blob: 123c942012e1c10e64af6e479b1baf9ae4adde40 [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'])
Andrew Geissler5082cc72023-09-11 08:41:39 -040027 @OEHasPackage('rust')
28 @OEHasPackage('openssh-scp')
Andrew Geissler517393d2023-01-13 08:55:19 -060029 def test_rust_compile(self):
30 status, output = self.target.run('rustc /tmp/test.rs -o /tmp/test')
31 msg = 'rust compile failed, output: %s' % output
32 self.assertEqual(status, 0, msg=msg)
33
34 status, output = self.target.run('/tmp/test')
35 msg = 'running compiled file failed, output: %s' % output
36 self.assertEqual(status, 0, msg=msg)
37
38 @OETestDepends(['ssh.SSHTest.test_ssh'])
Andrew Geissler5082cc72023-09-11 08:41:39 -040039 @OEHasPackage('cargo')
40 @OEHasPackage('openssh-scp')
Andrew Geissler517393d2023-01-13 08:55:19 -060041 def test_cargo_compile(self):
42 status, output = self.target.run('cargo new /tmp/hello')
43 msg = 'cargo new failed, output: %s' % output
44 self.assertEqual(status, 0, msg=msg)
45
46 status, output = self.target.run('cargo build --manifest-path=/tmp/hello/Cargo.toml')
47 msg = 'cargo build failed, output: %s' % output
48 self.assertEqual(status, 0, msg=msg)
49
50 status, output = self.target.run('cargo run --manifest-path=/tmp/hello/Cargo.toml')
51 msg = 'running compiled file failed, output: %s' % output
52 self.assertEqual(status, 0, msg=msg)
Andrew Geissler5082cc72023-09-11 08:41:39 -040053
54class RustCLibExampleTest(OERuntimeTestCase):
55 @OETestDepends(['ssh.SSHTest.test_ssh'])
56 @OEHasPackage('rust-c-lib-example-bin')
57 def test_rust_c_lib_example(self):
58 cmd = "rust-c-lib-example-bin test"
59 status, output = self.target.run(cmd)
60 msg = 'Exit status was not 0. Output: %s' % output
61 self.assertEqual(status, 0, msg=msg)
62
63 msg = 'Incorrect output: %s' % output
64 self.assertEqual(output, "Hello world in rust from C!", msg=msg)