blob: 7a0fd7033d8c7d147d0de01b257ca67c62930d36 [file] [log] [blame]
Andrew Geissler8f840682023-07-21 09:09:43 -05001# SPDX-License-Identifier: MIT
2import os
3import subprocess
4from oeqa.core.decorator import OETestTag
5from oeqa.core.case import OEPTestResultTestCase
6from oeqa.selftest.case import OESelftestTestCase
7from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu, Command
8from oeqa.utils.sshcontrol import SSHControl
9
10def 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 if "] " in test:
18 test = test.split("] ", 1)[1]
19 result = line.split(" ... ")[1].strip()
20 if result == "ok":
21 result = "PASS"
22 elif result == "failed":
23 result = "FAIL"
24 elif "ignored" in result:
25 result = "SKIPPED"
26 if test in tests:
27 if tests[test] != result:
28 print("Duplicate and mismatching result %s for %s" % (result, test))
29 else:
30 print("Duplicate result %s for %s" % (result, test))
31 else:
32 tests[test] = result
33 return tests
34
35# Total time taken for testing is of about 2hr 20min, with PARALLEL_MAKE set to 40 number of jobs.
36@OETestTag("toolchain-system")
37@OETestTag("toolchain-user")
38@OETestTag("runqemu")
39class RustSelfTestSystemEmulated(OESelftestTestCase, OEPTestResultTestCase):
40 def test_rust(self, *args, **kwargs):
41 # build remote-test-server before image build
42 recipe = "rust"
43 bitbake("{} -c test_compile".format(recipe))
44 builddir = get_bb_var("RUSTSRC", "rust")
45 # build core-image-minimal with required packages
46 default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp"]
47 features = []
48 features.append('IMAGE_FEATURES += "ssh-server-dropbear"')
49 features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages)))
50 self.write_config("\n".join(features))
51 bitbake("core-image-minimal")
52 # wrap the execution with a qemu instance.
53 # Tests are run with 512 tasks in parallel to execute all tests very quickly
54 with runqemu("core-image-minimal", runqemuparams = "nographic", qemuparams = "-m 512") as qemu:
55 # Copy remote-test-server to image through scp
56 host_sys = get_bb_var("RUST_BUILD_SYS", "rust")
57 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user="root")
58 ssh.copy_to(builddir + "/build/" + host_sys + "/stage1-tools-bin/remote-test-server","~/")
59 # Execute remote-test-server on image through background ssh
60 command = '~/remote-test-server --bind 0.0.0.0:12345 -v'
61 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)
62 # Get the values of variables.
63 tcpath = get_bb_var("TARGET_SYS", "rust")
64 targetsys = get_bb_var("RUST_TARGET_SYS", "rust")
65 rustlibpath = get_bb_var("WORKDIR", "rust")
66 tmpdir = get_bb_var("TMPDIR", "rust")
67
68 # Exclude the test folders that error out while building
69 # TODO: Fix the errors and include them for testing
70 # no-fail-fast: Run all tests regardless of failure.
71 # bless: First runs rustfmt to format the codebase,
72 # then runs tidy checks.
73 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"
74
75 # Set path for target-poky-linux-gcc, RUST_TARGET_PATH and hosttools.
76 cmd = " export PATH=%s/recipe-sysroot-native/usr/bin:$PATH;" % rustlibpath
77 cmd = cmd + " export TARGET_VENDOR=\"-poky\";"
78 cmd = cmd + " export PATH=%s/recipe-sysroot-native/usr/bin/%s:%s/hosttools:$PATH;" % (rustlibpath, tcpath, tmpdir)
79 cmd = cmd + " export RUST_TARGET_PATH=%s/rust-targets;" % rustlibpath
80 # Trigger testing.
81 cmd = cmd + " export TEST_DEVICE_ADDR=\"%s:12345\";" % qemu.ip
82 cmd = cmd + " cd %s; python3 src/bootstrap/bootstrap.py test %s --target %s > summary.txt 2>&1;" % (builddir, testargs, targetsys)
83 runCmd(cmd)
84
85 ptestsuite = "rust"
86 self.ptest_section(ptestsuite, logfile = builddir + "/summary.txt")
87 filename = builddir + "/summary.txt"
88 test_results = parse_results(filename)
89 for test in test_results:
90 self.ptest_result(ptestsuite, test, test_results[test])