blob: 6dbc517006891bf8467da8323701110a4f78a64f [file] [log] [blame]
Andrew Geissler8f840682023-07-21 09:09:43 -05001# SPDX-License-Identifier: MIT
2import os
3import subprocess
Patrick Williams2a254922023-08-11 09:48:11 -05004import time
Andrew Geissler8f840682023-07-21 09:09:43 -05005from oeqa.core.decorator import OETestTag
6from oeqa.core.case import OEPTestResultTestCase
7from oeqa.selftest.case import OESelftestTestCase
8from oeqa.utils.commands import runCmd, bitbake, get_bb_var, get_bb_vars, runqemu, Command
9from oeqa.utils.sshcontrol import SSHControl
10
11def parse_results(filename):
12 tests = {}
13 with open(filename, "r") as f:
14 lines = f.readlines()
15 for line in lines:
16 if "..." in line and "test [" in line:
17 test = line.split("test ")[1].split(" ... ")[0]
18 if "] " in test:
19 test = test.split("] ", 1)[1]
20 result = line.split(" ... ")[1].strip()
21 if result == "ok":
22 result = "PASS"
23 elif result == "failed":
24 result = "FAIL"
25 elif "ignored" in result:
26 result = "SKIPPED"
27 if test in tests:
28 if tests[test] != result:
29 print("Duplicate and mismatching result %s for %s" % (result, test))
30 else:
31 print("Duplicate result %s for %s" % (result, test))
32 else:
33 tests[test] = result
34 return tests
35
36# Total time taken for testing is of about 2hr 20min, with PARALLEL_MAKE set to 40 number of jobs.
37@OETestTag("toolchain-system")
38@OETestTag("toolchain-user")
39@OETestTag("runqemu")
40class RustSelfTestSystemEmulated(OESelftestTestCase, OEPTestResultTestCase):
41 def test_rust(self, *args, **kwargs):
Patrick Williams169d7bc2024-01-05 11:33:25 -060042 # Disable Rust Oe-selftest
43 self.skipTest("The Rust Oe-selftest is disabled.")
44
Andrew Geissler8f840682023-07-21 09:09:43 -050045 # build remote-test-server before image build
46 recipe = "rust"
Patrick Williams2a254922023-08-11 09:48:11 -050047 start_time = time.time()
Andrew Geissler8f840682023-07-21 09:09:43 -050048 bitbake("{} -c test_compile".format(recipe))
49 builddir = get_bb_var("RUSTSRC", "rust")
50 # build core-image-minimal with required packages
51 default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp"]
52 features = []
53 features.append('IMAGE_FEATURES += "ssh-server-dropbear"')
54 features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages)))
55 self.write_config("\n".join(features))
56 bitbake("core-image-minimal")
Patrick Williams2a254922023-08-11 09:48:11 -050057
58 # Exclude the test folders that error out while building
59 # TODO: Fix the errors and include them for testing
60 # no-fail-fast: Run all tests regardless of failure.
61 # bless: First runs rustfmt to format the codebase,
62 # then runs tidy checks.
63 exclude_list = [
64 'compiler/rustc',
65 'compiler/rustc_interface/src/tests.rs',
66 'library/panic_abort',
67 'library/panic_unwind',
68 'library/test/src/stats/tests.rs',
69 'src/bootstrap/builder/tests.rs',
70 'src/doc/rustc',
71 'src/doc/rustdoc',
72 'src/doc/unstable-book',
73 'src/librustdoc',
74 'src/rustdoc-json-types',
75 'src/tools/compiletest/src/common.rs',
76 'src/tools/lint-docs',
77 'src/tools/rust-analyzer',
78 'src/tools/rustdoc-themes',
79 'src/tools/tidy',
80 'tests/assembly/asm/aarch64-outline-atomics.rs',
81 'tests/codegen/abi-main-signature-32bit-c-int.rs',
82 'tests/codegen/abi-repr-ext.rs',
83 'tests/codegen/abi-x86-interrupt.rs',
84 'tests/codegen/branch-protection.rs',
85 'tests/codegen/catch-unwind.rs',
86 'tests/codegen/cf-protection.rs',
87 'tests/codegen/enum-bounds-check-derived-idx.rs',
88 'tests/codegen/force-unwind-tables.rs',
89 'tests/codegen/intrinsic-no-unnamed-attr.rs',
90 'tests/codegen/issues/issue-103840.rs',
91 'tests/codegen/issues/issue-47278.rs',
92 'tests/codegen/issues/issue-73827-bounds-check-index-in-subexpr.rs',
93 'tests/codegen/lifetime_start_end.rs',
94 'tests/codegen/local-generics-in-exe-internalized.rs',
95 'tests/codegen/match-unoptimized.rs',
96 'tests/codegen/noalias-rwlockreadguard.rs',
97 'tests/codegen/non-terminate/nonempty-infinite-loop.rs',
98 'tests/codegen/noreturn-uninhabited.rs',
99 'tests/codegen/repr-transparent-aggregates-3.rs',
100 'tests/codegen/sse42-implies-crc32.rs',
101 'tests/codegen/thread-local.rs',
102 'tests/codegen/uninit-consts.rs',
103 'tests/pretty/raw-str-nonexpr.rs',
104 'tests/run-make',
105 'tests/run-make/cdylib-fewer-symbols/foo.rs',
106 'tests/run-make/doctests-keep-binaries/t.rs',
107 'tests/run-make-fulldeps',
108 'tests/run-make/issue-22131/foo.rs',
109 'tests/run-make/issue-36710/Makefile',
110 'tests/run-make/issue-47551',
111 'tests/run-make/pgo-branch-weights',
112 'tests/run-make/pgo-gen',
113 'tests/run-make/pgo-gen-lto',
114 'tests/run-make/pgo-indirect-call-promotion',
115 'tests/run-make/pgo-use',
116 'tests/run-make/pointer-auth-link-with-c/Makefile',
117 'tests/run-make/profile',
118 'tests/run-make/static-pie',
119 'tests/run-make/sysroot-crates-are-unstable',
120 'tests/run-make/target-specs',
121 'tests/rustdoc',
122 'tests/rustdoc/async-move-doctest.rs',
123 'tests/rustdoc/async-trait.rs',
124 'tests/rustdoc/auto-traits.rs',
125 'tests/rustdoc/check-source-code-urls-to-def.rs',
126 'tests/rustdoc/comment-in-doctest.rs',
127 'tests/rustdoc/const-generics/const-generics-docs.rs',
128 'tests/rustdoc/cross-crate-hidden-assoc-trait-items.rs',
129 'tests/rustdoc/cross-crate-hidden-impl-parameter.rs',
130 'tests/rustdoc/cross-crate-links.rs',
131 'tests/rustdoc/cross-crate-primitive-doc.rs',
132 'tests/rustdoc/doctest-manual-crate-name.rs',
133 'tests/rustdoc/edition-doctest.rs',
134 'tests/rustdoc/edition-flag.rs',
135 'tests/rustdoc/elided-lifetime.rs',
136 'tests/rustdoc/external-macro-src.rs',
137 'tests/rustdoc/extern-html-root-url.rs',
138 'tests/rustdoc/extern-impl-trait.rs',
139 'tests/rustdoc/hide-unstable-trait.rs',
140 'tests/rustdoc/inline_cross/add-docs.rs',
141 'tests/rustdoc/inline_cross/default-trait-method.rs',
142 'tests/rustdoc/inline_cross/dyn_trait.rs',
143 'tests/rustdoc/inline_cross/impl_trait.rs',
144 'tests/rustdoc/inline_cross/issue-24183.rs',
145 'tests/rustdoc/inline_cross/macros.rs',
146 'tests/rustdoc/inline_cross/trait-vis.rs',
147 'tests/rustdoc/inline_cross/use_crate.rs',
148 'tests/rustdoc/intra-doc-crate/self.rs',
149 'tests/rustdoc/intra-doc/cross-crate/additional_doc.rs',
150 'tests/rustdoc/intra-doc/cross-crate/basic.rs',
151 'tests/rustdoc/intra-doc/cross-crate/crate.rs',
152 'tests/rustdoc/intra-doc/cross-crate/hidden.rs',
153 'tests/rustdoc/intra-doc/cross-crate/macro.rs',
154 'tests/rustdoc/intra-doc/cross-crate/module.rs',
155 'tests/rustdoc/intra-doc/cross-crate/submodule-inner.rs',
156 'tests/rustdoc/intra-doc/cross-crate/submodule-outer.rs',
157 'tests/rustdoc/intra-doc/cross-crate/traits.rs',
158 'tests/rustdoc/intra-doc/extern-builtin-type-impl.rs',
159 'tests/rustdoc/intra-doc/extern-crate-only-used-in-link.rs',
160 'tests/rustdoc/intra-doc/extern-crate.rs',
161 'tests/rustdoc/intra-doc/extern-inherent-impl.rs',
162 'tests/rustdoc/intra-doc/extern-reference-link.rs',
163 'tests/rustdoc/intra-doc/issue-103463.rs',
164 'tests/rustdoc/intra-doc/issue-104145.rs',
165 'tests/rustdoc/intra-doc/issue-66159.rs',
166 'tests/rustdoc/intra-doc/pub-use.rs',
167 'tests/rustdoc/intra-doc/reexport-additional-docs.rs',
168 'tests/rustdoc/issue-18199.rs',
169 'tests/rustdoc/issue-23106.rs',
170 'tests/rustdoc/issue-23744.rs',
171 'tests/rustdoc/issue-25944.rs',
172 'tests/rustdoc/issue-30252.rs',
173 'tests/rustdoc/issue-38129.rs',
174 'tests/rustdoc/issue-40936.rs',
175 'tests/rustdoc/issue-43153.rs',
176 'tests/rustdoc/issue-46727.rs',
177 'tests/rustdoc/issue-48377.rs',
178 'tests/rustdoc/issue-48414.rs',
179 'tests/rustdoc/issue-53689.rs',
180 'tests/rustdoc/issue-54478-demo-allocator.rs',
181 'tests/rustdoc/issue-57180.rs',
182 'tests/rustdoc/issue-61592.rs',
183 'tests/rustdoc/issue-73061-cross-crate-opaque-assoc-type.rs',
184 'tests/rustdoc/issue-75588.rs',
185 'tests/rustdoc/issue-85454.rs',
186 'tests/rustdoc/issue-86620.rs',
187 'tests/rustdoc-json',
188 'tests/rustdoc-js-std',
189 'tests/rustdoc/macro_pub_in_module.rs',
190 'tests/rustdoc/masked.rs',
191 'tests/rustdoc/normalize-assoc-item.rs',
192 'tests/rustdoc/no-stack-overflow-25295.rs',
193 'tests/rustdoc/primitive-reexport.rs',
194 'tests/rustdoc/process-termination.rs',
195 'tests/rustdoc/pub-extern-crate.rs',
196 'tests/rustdoc/pub-use-extern-macros.rs',
197 'tests/rustdoc/reexport-check.rs',
198 'tests/rustdoc/reexport-dep-foreign-fn.rs',
199 'tests/rustdoc/reexport-doc.rs',
200 'tests/rustdoc/reexports-priv.rs',
201 'tests/rustdoc/reexports.rs',
202 'tests/rustdoc/rustc,-incoherent-impls.rs',
203 'tests/rustdoc/test_option_check/bar.rs',
204 'tests/rustdoc/test_option_check/test.rs',
205 'tests/rustdoc/trait-alias-mention.rs',
206 'tests/rustdoc/trait-visibility.rs',
207 'tests/rustdoc-ui/cfg-test.rs',
208 'tests/rustdoc-ui/check-cfg-test.rs',
209 'tests/rustdoc-ui/display-output.rs',
210 'tests/rustdoc-ui/doc-comment-multi-line-attr.rs',
211 'tests/rustdoc-ui/doc-comment-multi-line-cfg-attr.rs',
212 'tests/rustdoc-ui/doc-test-doctest-feature.rs',
213 'tests/rustdoc-ui/doctest-multiline-crate-attribute.rs',
214 'tests/rustdoc-ui/doctest-output.rs',
215 'tests/rustdoc-ui/doc-test-rustdoc-feature.rs',
216 'tests/rustdoc-ui/failed-doctest-compile-fail.rs',
217 'tests/rustdoc-ui/issue-80992.rs',
218 'tests/rustdoc-ui/issue-91134.rs',
219 'tests/rustdoc-ui/nocapture-fail.rs',
220 'tests/rustdoc-ui/nocapture.rs',
221 'tests/rustdoc-ui/no-run-flag.rs',
222 'tests/rustdoc-ui/run-directory.rs',
223 'tests/rustdoc-ui/test-no_std.rs',
224 'tests/rustdoc-ui/test-type.rs',
225 'tests/rustdoc/unit-return.rs',
226 'tests/ui/abi/stack-probes-lto.rs',
227 'tests/ui/abi/stack-probes.rs',
228 'tests/ui/array-slice-vec/subslice-patterns-const-eval-match.rs',
229 'tests/ui/asm/x86_64/sym.rs',
230 'tests/ui/associated-type-bounds/fn-apit.rs',
231 'tests/ui/associated-type-bounds/fn-dyn-apit.rs',
232 'tests/ui/associated-type-bounds/fn-wrap-apit.rs',
233 'tests/ui/debuginfo/debuginfo-emit-llvm-ir-and-split-debuginfo.rs',
234 'tests/ui/drop/dynamic-drop.rs',
235 'tests/ui/empty_global_asm.rs',
236 'tests/ui-fulldeps/deriving-encodable-decodable-box.rs',
237 'tests/ui-fulldeps/deriving-encodable-decodable-cell-refcell.rs',
238 'tests/ui-fulldeps/deriving-global.rs',
239 'tests/ui-fulldeps/deriving-hygiene.rs',
240 'tests/ui-fulldeps/dropck_tarena_sound_drop.rs',
241 'tests/ui-fulldeps/empty-struct-braces-derive.rs',
242 'tests/ui-fulldeps/internal-lints/bad_opt_access.rs',
243 'tests/ui-fulldeps/internal-lints/bad_opt_access.stderr',
244 'tests/ui-fulldeps/internal-lints/default_hash_types.rs',
245 'tests/ui-fulldeps/internal-lints/diagnostics.rs',
246 'tests/ui-fulldeps/internal-lints/lint_pass_impl_without_macro.rs',
247 'tests/ui-fulldeps/internal-lints/qualified_ty_ty_ctxt.rs',
248 'tests/ui-fulldeps/internal-lints/query_stability.rs',
249 'tests/ui-fulldeps/internal-lints/rustc_pass_by_value.rs',
250 'tests/ui-fulldeps/internal-lints/ty_tykind_usage.rs',
251 'tests/ui-fulldeps/issue-14021.rs',
252 'tests/ui-fulldeps/lint-group-denied-lint-allowed.rs',
253 'tests/ui-fulldeps/lint-group-forbid-always-trumps-cli.rs',
254 'tests/ui-fulldeps/lint-pass-macros.rs',
255 'tests/ui-fulldeps/regions-mock-tcx.rs',
256 'tests/ui-fulldeps/rustc_encodable_hygiene.rs',
257 'tests/ui-fulldeps/session-diagnostic/enforce_slug_naming.rs',
258 'tests/ui/functions-closures/fn-help-with-err.rs',
259 'tests/ui/linkage-attr/issue-10755.rs',
260 'tests/ui/macros/restricted-shadowing-legacy.rs',
261 'tests/ui/process/nofile-limit.rs',
262 'tests/ui/process/process-panic-after-fork.rs',
263 'tests/ui/process/process-sigpipe.rs',
264 'tests/ui/simd/target-feature-mixup.rs',
265 'tests/ui/structs-enums/multiple-reprs.rs'
266 ]
267
268 exclude_fail_tests = " ".join([" --exclude " + item for item in exclude_list])
269 # Add exclude_fail_tests with other test arguments
270 testargs = exclude_fail_tests + " --doc --no-fail-fast --bless"
271
Andrew Geissler8f840682023-07-21 09:09:43 -0500272 # wrap the execution with a qemu instance.
273 # Tests are run with 512 tasks in parallel to execute all tests very quickly
274 with runqemu("core-image-minimal", runqemuparams = "nographic", qemuparams = "-m 512") as qemu:
275 # Copy remote-test-server to image through scp
276 host_sys = get_bb_var("RUST_BUILD_SYS", "rust")
277 ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user="root")
278 ssh.copy_to(builddir + "/build/" + host_sys + "/stage1-tools-bin/remote-test-server","~/")
279 # Execute remote-test-server on image through background ssh
280 command = '~/remote-test-server --bind 0.0.0.0:12345 -v'
281 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)
282 # Get the values of variables.
283 tcpath = get_bb_var("TARGET_SYS", "rust")
284 targetsys = get_bb_var("RUST_TARGET_SYS", "rust")
285 rustlibpath = get_bb_var("WORKDIR", "rust")
286 tmpdir = get_bb_var("TMPDIR", "rust")
287
Andrew Geissler8f840682023-07-21 09:09:43 -0500288 # Set path for target-poky-linux-gcc, RUST_TARGET_PATH and hosttools.
289 cmd = " export PATH=%s/recipe-sysroot-native/usr/bin:$PATH;" % rustlibpath
290 cmd = cmd + " export TARGET_VENDOR=\"-poky\";"
291 cmd = cmd + " export PATH=%s/recipe-sysroot-native/usr/bin/%s:%s/hosttools:$PATH;" % (rustlibpath, tcpath, tmpdir)
292 cmd = cmd + " export RUST_TARGET_PATH=%s/rust-targets;" % rustlibpath
293 # Trigger testing.
294 cmd = cmd + " export TEST_DEVICE_ADDR=\"%s:12345\";" % qemu.ip
295 cmd = cmd + " cd %s; python3 src/bootstrap/bootstrap.py test %s --target %s > summary.txt 2>&1;" % (builddir, testargs, targetsys)
296 runCmd(cmd)
Patrick Williams2a254922023-08-11 09:48:11 -0500297 end_time = time.time()
Andrew Geissler8f840682023-07-21 09:09:43 -0500298
299 ptestsuite = "rust"
Patrick Williams2a254922023-08-11 09:48:11 -0500300 self.ptest_section(ptestsuite, duration = int(end_time - start_time), logfile = builddir + "/summary.txt")
Andrew Geissler8f840682023-07-21 09:09:43 -0500301 filename = builddir + "/summary.txt"
302 test_results = parse_results(filename)
303 for test in test_results:
304 self.ptest_result(ptestsuite, test, test_results[test])