blob: c9c60e16fd2bc282986c6c883988de06f7ff5499 [file] [log] [blame]
Andrew Geissler595f6302022-01-24 19:11:47 +00001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Andrew Geissler595f6302022-01-24 19:11:47 +00004# SPDX-License-Identifier: MIT
5#
6
7from oeqa.runtime.case import OERuntimeTestCase
8from oeqa.core.decorator.depends import OETestDepends
9from oeqa.runtime.decorator.package import OEHasPackage
10
Andrew Geissler517393d2023-01-13 08:55:19 -060011class RustCompileTest(OERuntimeTestCase):
12
13 @classmethod
14 def setUp(cls):
15 dst = '/tmp/'
16 src = os.path.join(cls.tc.files_dir, 'test.rs')
17 cls.tc.target.copyTo(src, dst)
18
19 @classmethod
20 def tearDown(cls):
21 files = '/tmp/test.rs /tmp/test'
22 cls.tc.target.run('rm %s' % files)
23 dirs = '/tmp/hello'
24 cls.tc.target.run('rm -r %s' % dirs)
25
26 @OETestDepends(['ssh.SSHTest.test_ssh'])
27 @OEHasPackage(['rust'])
28 def test_rust_compile(self):
29 status, output = self.target.run('rustc /tmp/test.rs -o /tmp/test')
30 msg = 'rust compile failed, output: %s' % output
31 self.assertEqual(status, 0, msg=msg)
32
33 status, output = self.target.run('/tmp/test')
34 msg = 'running compiled file failed, output: %s' % output
35 self.assertEqual(status, 0, msg=msg)
36
37 @OETestDepends(['ssh.SSHTest.test_ssh'])
38 @OEHasPackage(['cargo'])
39 def test_cargo_compile(self):
40 status, output = self.target.run('cargo new /tmp/hello')
41 msg = 'cargo new failed, output: %s' % output
42 self.assertEqual(status, 0, msg=msg)
43
44 status, output = self.target.run('cargo build --manifest-path=/tmp/hello/Cargo.toml')
45 msg = 'cargo build failed, output: %s' % output
46 self.assertEqual(status, 0, msg=msg)
47
48 status, output = self.target.run('cargo run --manifest-path=/tmp/hello/Cargo.toml')
49 msg = 'running compiled file failed, output: %s' % output
50 self.assertEqual(status, 0, msg=msg)
51
Andrew Geissler595f6302022-01-24 19:11:47 +000052class RustHelloworldTest(OERuntimeTestCase):
53 @OETestDepends(['ssh.SSHTest.test_ssh'])
54 @OEHasPackage(['rust-hello-world'])
55 def test_rusthelloworld(self):
56 cmd = "rust-hello-world"
57 status, output = self.target.run(cmd)
58 msg = 'Exit status was not 0. Output: %s' % output
59 self.assertEqual(status, 0, msg=msg)
60
61 msg = 'Incorrect output: %s' % output
62 self.assertEqual(output, "Hello, world!", msg=msg)