diff options
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() | ||
