rust.py 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. # SPDX-License-Identifier: MIT
  2. import subprocess
  3. import time
  4. from oeqa.core.decorator import OETestTag
  5. from oeqa.core.decorator.data import skipIfArch
  6. from oeqa.core.case import OEPTestResultTestCase
  7. from oeqa.selftest.case import OESelftestTestCase
  8. from oeqa.utils.commands import runCmd, bitbake, get_bb_var, runqemu
  9. from oeqa.utils.sshcontrol import SSHControl
  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. 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. # Total time taken for testing is of about 2hr 20min, with PARALLEL_MAKE set to 40 number of jobs.
  35. @OETestTag("toolchain-system")
  36. @OETestTag("toolchain-user")
  37. @OETestTag("runqemu")
  38. class RustSelfTestSystemEmulated(OESelftestTestCase, OEPTestResultTestCase):
  39. @skipIfArch(['mips', 'mips64'])
  40. def test_rust(self, *args, **kwargs):
  41. # build remote-test-server before image build
  42. recipe = "rust"
  43. start_time = time.time()
  44. bitbake("{} -c test_compile".format(recipe))
  45. builddir = get_bb_var("RUSTSRC", "rust")
  46. # build core-image-minimal with required packages
  47. default_installed_packages = ["libgcc", "libstdc++", "libatomic", "libgomp"]
  48. features = []
  49. features.append('IMAGE_FEATURES += "ssh-server-dropbear"')
  50. features.append('CORE_IMAGE_EXTRA_INSTALL += "{0}"'.format(" ".join(default_installed_packages)))
  51. self.write_config("\n".join(features))
  52. bitbake("core-image-minimal")
  53. # Exclude the test folders that error out while building
  54. # TODO: Fix the errors and include them for testing
  55. # no-fail-fast: Run all tests regardless of failure.
  56. # bless: First runs rustfmt to format the codebase,
  57. # then runs tidy checks.
  58. exclude_list = [
  59. 'src/bootstrap',
  60. 'src/doc/rustc',
  61. 'src/doc/rustdoc',
  62. 'src/doc/unstable-book',
  63. 'src/etc/test-float-parse',
  64. 'src/librustdoc',
  65. 'src/rustdoc-json-types',
  66. 'src/tools/coverage-dump',
  67. 'src/tools/jsondoclint',
  68. 'src/tools/lint-docs',
  69. 'src/tools/replace-version-placeholder',
  70. 'src/tools/rust-analyzer',
  71. 'src/tools/rustdoc-themes',
  72. 'src/tools/rust-installer',
  73. 'src/tools/test-float-parse',
  74. 'src/tools/suggest-tests',
  75. 'src/tools/tidy',
  76. 'tests/assembly-llvm/asm/aarch64-outline-atomics.rs',
  77. 'tests/codegen-llvm/issues/issue-122805.rs',
  78. 'tests/codegen-llvm/thread-local.rs',
  79. 'tests/mir-opt/',
  80. 'tests/run-make',
  81. 'tests/run-make-fulldeps',
  82. 'tests/rustdoc',
  83. 'tests/rustdoc-json',
  84. 'tests/rustdoc-js-std',
  85. 'tests/ui/abi/stack-probes-lto.rs',
  86. 'tests/ui/abi/stack-probes.rs',
  87. 'tests/ui/codegen/mismatched-data-layouts.rs',
  88. 'tests/codegen-llvm/rust-abi-arch-specific-adjustment.rs',
  89. 'tests/ui/debuginfo/debuginfo-emit-llvm-ir-and-split-debuginfo.rs',
  90. 'tests/ui/feature-gates/version_check.rs',
  91. 'tests/ui-fulldeps/',
  92. 'tests/ui/process/nofile-limit.rs',
  93. 'tidyselftest'
  94. ]
  95. exclude_fail_tests = " ".join([" --exclude " + item for item in exclude_list])
  96. # Add exclude_fail_tests with other test arguments
  97. testargs = exclude_fail_tests + " --no-doc --no-fail-fast --bless"
  98. # wrap the execution with a qemu instance.
  99. # Set QEMU RAM to 1024MB to support running unit tests for the compiler crate, including larger
  100. # test cases and parallel execution in the test environment.
  101. with runqemu("core-image-minimal", runqemuparams = "nographic", qemuparams = "-m 1024") as qemu:
  102. # Copy remote-test-server to image through scp
  103. host_sys = get_bb_var("RUST_BUILD_SYS", "rust")
  104. ssh = SSHControl(ip=qemu.ip, logfile=qemu.sshlog, user="root")
  105. ssh.copy_to(builddir + "/build/" + host_sys + "/stage1-tools-bin/remote-test-server","~/")
  106. # Execute remote-test-server on image through background ssh
  107. command = '~/remote-test-server --bind 0.0.0.0:12345 -v'
  108. 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)
  109. # Get the values of variables.
  110. tcpath = get_bb_var("TARGET_SYS", "rust")
  111. targetsys = get_bb_var("RUST_TARGET_SYS", "rust")
  112. rustlibpath = get_bb_var("WORKDIR", "rust")
  113. tmpdir = get_bb_var("TMPDIR", "rust")
  114. # Set path for target-poky-linux-gcc, RUST_TARGET_PATH and hosttools.
  115. cmd = "export TARGET_VENDOR=\"-poky\";"
  116. cmd = cmd + " export PATH=%s/recipe-sysroot-native/usr/bin/python3-native:%s/recipe-sysroot-native/usr/bin:%s/recipe-sysroot-native/usr/bin/%s:%s/hosttools:$PATH;" % (rustlibpath, rustlibpath, rustlibpath, tcpath, tmpdir)
  117. cmd = cmd + " export RUST_TARGET_PATH=%s/rust-targets;" % rustlibpath
  118. # Trigger testing.
  119. cmd = cmd + " export TEST_DEVICE_ADDR=\"%s:12345\";" % qemu.ip
  120. cmd = cmd + " cd %s; python3 src/bootstrap/bootstrap.py test %s --target %s" % (builddir, testargs, targetsys)
  121. retval = runCmd(cmd)
  122. end_time = time.time()
  123. resultlog = rustlibpath + "/results-log.txt"
  124. with open(resultlog, "w") as f:
  125. f.write(retval.output)
  126. ptestsuite = "rust"
  127. self.ptest_section(ptestsuite, duration = int(end_time - start_time), logfile=resultlog)
  128. test_results = parse_results(resultlog)
  129. for test in test_results:
  130. self.ptest_result(ptestsuite, test, test_results[test])