Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
| 7 | from oeqa.runtime.case import OERuntimeTestCase |
| 8 | from oeqa.core.decorator.depends import OETestDepends |
| 9 | from oeqa.runtime.decorator.package import OEHasPackage |
| 10 | |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 11 | class 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 Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 27 | @OEHasPackage('rust') |
| 28 | @OEHasPackage('openssh-scp') |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 29 | 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 Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 39 | @OEHasPackage('cargo') |
| 40 | @OEHasPackage('openssh-scp') |
Andrew Geissler | 517393d | 2023-01-13 08:55:19 -0600 | [diff] [blame] | 41 | 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 Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 53 | |
| 54 | class 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) |