From 5116f2b2cf3d00fc2c9f41f8ce3661ed7bb4975e Mon Sep 17 00:00:00 2001 From: Frederic Martinsons Date: Thu, 17 Aug 2023 07:04:15 +0200 Subject: rust: provide examples for C library generation in rust rust-c-lib-example is a little rust code which provide a single function to print a formatted date (via the chrono crate) from an input timestamp in millisecond. It has the necessary FFI annotation and inherit cargo_c class for the C ABI compatible library generation. rust-c-lib-example is meson project for the C code which will call the print_date function from rust-c-lib-example if no argument is provided, if any argument is provided it will print "Hello world in rust from C!" add a runtime test case to check if all went well. (From OE-Core rev: bb177c7764b1bc47157d57d7a34930e59a7acef3) Signed-off-by: Frederic Martinsons Signed-off-by: Richard Purdie --- meta/lib/oeqa/runtime/cases/rust.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'meta/lib/oeqa/runtime') diff --git a/meta/lib/oeqa/runtime/cases/rust.py b/meta/lib/oeqa/runtime/cases/rust.py index 9bf0312669..39707cf5cf 100644 --- a/meta/lib/oeqa/runtime/cases/rust.py +++ b/meta/lib/oeqa/runtime/cases/rust.py @@ -48,3 +48,15 @@ class RustCompileTest(OERuntimeTestCase): status, output = self.target.run('cargo run --manifest-path=/tmp/hello/Cargo.toml') msg = 'running compiled file failed, output: %s' % output self.assertEqual(status, 0, msg=msg) + +class RustCLibExampleTest(OERuntimeTestCase): + @OETestDepends(['ssh.SSHTest.test_ssh']) + @OEHasPackage('rust-c-lib-example-bin') + def test_rust_c_lib_example(self): + cmd = "rust-c-lib-example-bin test" + status, output = self.target.run(cmd) + msg = 'Exit status was not 0. Output: %s' % output + self.assertEqual(status, 0, msg=msg) + + msg = 'Incorrect output: %s' % output + self.assertEqual(output, "Hello world in rust from C!", msg=msg) -- cgit v1.2.3-54-g00ecf