diff options
author | Yash Shinde <Yash.Shinde@windriver.com> | 2023-07-11 14:33:46 +0400 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-07-19 18:00:32 +0100 |
commit | a1096d4a57942e1b57bdd0884b363a028ac479d5 (patch) | |
tree | 224254e6bd4b3dda5b63f6ff09ad504d8201975e /meta/lib | |
parent | d101e64b1c2be0e16769e7d3b856e4a85cbaaf68 (diff) | |
download | poky-a1096d4a57942e1b57bdd0884b363a028ac479d5.tar.gz |
oeqa/selftest: Add rust selftests
The patch implements Rust testing framework similar to other selftest,
specifically the gcc selftest in OE. It uses the client and server
based method to test the binaries for cross-target on the image.
The test framework is a wrapper around the Rust build system as ./x.py
test. It tests many functionalities of Rust distribution like tools,
documentation, libraries, packages, tools, Cargo, Crater etc.
Please refer the following link for detailed description of Rust
testing:-
https://rustc-dev-guide.rust-lang.org/tests/intro.html#tool-tests
To support the rust tests in oe-core, the following functions were
added:-
setup_cargo_environment(): Build bootstrap and some early stage tools.
do_rust_setup_snapshot(): Install the snapshot version of rust binaries.
do_configure(): To generate config.toml
do_compile(): To build "remote-test-server" for qemu target image.
Approximate Number of Tests Run in the Rust Testsuite :- 18000
Approximate Number of Tests that FAIL in bitbake environment :- 100-150
Normally majority of the testcases are present in major folder "test/"
It contributes to more than 80% of the testcases present in Rust test
framework. These tests pass as expected on any Rust versions without
much fuss. The tests that fail are of less important and contribute to
less than 2% of the total testcases. These minor tests are observed to
work on some versions and fail on others. They have to be added, ignored
or excluded for different versions as per the behavior.
These tests have been ignored or excluded in the Rust selftest
environment to generate success of completing the testsuite.
These tests work in parallel mode even in the skipped test mode as
expected. Although the patch to disable tests is large, it is very simple
in that it only disables tests. When updating to a newer version of Rust,
the patch can usually be ported in a day.
Tested for X86, X86-64, ARM, ARM64 and MIPS64 on Ubuntu 22.04.
(From OE-Core rev: 7c3346d8fbe85302b605bb3f772b029ea7bfaa6c)
Signed-off-by: pgowda <pgowda.cve@gmail.com>
Signed-off-by: Vinay Kumar <vinay.m.engg@gmail.com>
Signed-off-by: Yash Shinde <yashinde145@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib')
-rw-r--r-- | meta/lib/oeqa/selftest/cases/rust.py | 85 |
1 files changed, 85 insertions, 0 deletions
diff --git a/meta/lib/oeqa/selftest/cases/rust.py b/meta/lib/oeqa/selftest/cases/rust.py new file mode 100644 index 0000000000..4fbe8f08fa --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/rust.py | |||
@@ -0,0 +1,85 @@ | |||
1 | # SPDX-License-Identifier: MIT | ||
2 | import os | ||
3 | import subprocess | ||
4 | from oeqa.core.decorator import OETestTag | ||
5 | from oeqa.core.case import OEPTestResultTestCase | ||
6 | from oeqa.selftest.case import OESelftestTestCase | ||
7 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu, Command | ||
8 | from oeqa.utils.sshcontrol import SSHControl | ||
9 | |||
10 | def parse_results(filename): | ||
11 | tests = [] | ||
12 | with open(filename, "r") as f: | ||
13 | lines = f.readlines() | ||
14 | for line in lines: | ||
15 | if "..." in line and "test [" in line: | ||
16 | test = line.split("test ")[1].split(" ... ")[0] | ||
17 | result = line.split(" ... ")[1].strip() | ||
18 | if result == "ok": | ||
19 | result = "PASS" | ||
20 | elif result == "failed": | ||
21 | result = "FAIL" | ||
22 | elif "ignored" in result: | ||
23 | result = "SKIP" | ||
24 | tests.append((test, result)) | ||
25 | return tests | ||
26 | |||
27 | # Total time taken for testing is of about 2hr 20min, with PARALLEL_MAKE set to 40 number of jobs. | ||
28 | class RustSelfTestSystemEmulated(OESelftestTestCase, OEPTestResultTestCase): | ||
29 | def test_rust(self, *args, **kwargs): | ||
30 | # build remote-test-server before image build | ||
31 | recipe = "rust" | ||
32 | bitbake("{} -c test_compile".format(recipe)) | ||
33 | builddir = get_bb_var("RUSTSRC", "rust") | ||
34 | # build core-image-minimal with required packages | ||
35 | default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp"] | ||
36 | features = [] | ||
37 | features.append('IMAGE_FEATURES += "ssh-server-dropbear"') | ||
38 | features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages))) | ||
39 | self.write_config("\n".join(features)) | ||
40 | bitbake("core-image-minimal") | ||
41 | # wrap the execution with a qemu instance. | ||
42 | # Tests are run with 512 tasks in parallel to execute all tests very quickly | ||
43 | with runqemu("core-image-minimal", runqemuparams = "nographic", qemuparams = "-m 512") as qemu: | ||
44 | # Copy remote-test-server to image through scp | ||
45 | host_sys = get_bb_var("RUST_BUILD_SYS", "rust") | ||
46 | ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user="root") | ||
47 | ssh.copy_to(builddir + "/build/" + host_sys + "/stage1-tools-bin/remote-test-server","~/") | ||
48 | # Execute remote-test-server on image through background ssh | ||
49 | command = '~/remote-test-server --bind 0.0.0.0:12345 -v' | ||
50 | sshrun=subprocess.Popen(("ssh", '-o', 'UserKnownHostsFile=/dev/null', '-o', 'StrictHostKeyChecking=no', '-f', "root@%s" % qemu.ip, command), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
51 | # Get the values of variables. | ||
52 | tcpath = get_bb_var("TARGET_SYS", "rust") | ||
53 | targetsys = get_bb_var("RUST_TARGET_SYS", "rust") | ||
54 | rustlibpath = get_bb_var("WORKDIR", "rust") | ||
55 | tmpdir = get_bb_var("TMPDIR", "rust") | ||
56 | |||
57 | # Exclude the test folders that error out while building | ||
58 | # TODO: Fix the errors and include them for testing | ||
59 | # no-fail-fast: Run all tests regardless of failure. | ||
60 | # bless: First runs rustfmt to format the codebase, | ||
61 | # then runs tidy checks. | ||
62 | testargs = "--exclude tests/rustdoc --exclude src/tools/rust-analyzer --exclude tests/rustdoc-json --exclude tests/run-make-fulldeps --exclude src/tools/tidy --exclude src/tools/rustdoc-themes --exclude src/rustdoc-json-types --exclude src/librustdoc --exclude src/doc/unstable-book --exclude src/doc/rustdoc --exclude src/doc/rustc --exclude compiler/rustc --exclude library/panic_abort --exclude library/panic_unwind --exclude src/tools/lint-docs --exclude tests/rustdoc-js-std --doc --no-fail-fast --bless" | ||
63 | |||
64 | # Set path for target-poky-linux-gcc, RUST_TARGET_PATH and hosttools. | ||
65 | cmd = " export PATH=%s/recipe-sysroot-native/usr/bin:$PATH;" % rustlibpath | ||
66 | cmd = cmd + " export TARGET_VENDOR=\"-poky\";" | ||
67 | cmd = cmd + " export PATH=%s/recipe-sysroot-native/usr/bin/%s:%s/hosttools:$PATH;" % (rustlibpath, tcpath, tmpdir) | ||
68 | cmd = cmd + " export RUST_TARGET_PATH=%s/rust-targets;" % rustlibpath | ||
69 | # Trigger testing. | ||
70 | cmd = cmd + " export TEST_DEVICE_ADDR=\"%s:12345\";" % qemu.ip | ||
71 | cmd = cmd + " cd %s; python3 src/bootstrap/bootstrap.py test %s --target %s > summary.txt 2>&1;" % (builddir, testargs, targetsys) | ||
72 | runCmd(cmd) | ||
73 | |||
74 | ptestsuite = "rust" | ||
75 | self.ptest_section(ptestsuite, logfile = builddir + "/summary.txt") | ||
76 | filename = builddir + "/summary.txt" | ||
77 | test_results = parse_results(filename) | ||
78 | for test, result in test_results: | ||
79 | self.ptest_result(ptestsuite, test, result) | ||
80 | |||
81 | @OETestTag("toolchain-system") | ||
82 | @OETestTag("runqemu") | ||
83 | class RustSelfTestBase(RustSelfTestSystemEmulated): | ||
84 | def test_check(self): | ||
85 | self.test_rust() | ||