arm-systemready-acs.bbclass 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. # This class contains the common logic to deploy the SystemReady ACS pre-built
  2. # image and set up the testimage environment. It is to be inherited by recipes
  3. # which contains the URI to download the SystemReady ACS image.
  4. # This class also contains a testimage "postfunc" called acs_logs_handle which
  5. # performs the following functions after the tests have completed:
  6. # * Extract the acs_results directory from the Wic image to
  7. # ${WORKDIR}/testimage
  8. # * Create a symlink to the acs_results in ${TMPDIR}/log/oeqa for ease of
  9. # access
  10. # * Run the test parser, format results, and check results routines
  11. INHIBIT_DEFAULT_DEPS = "1"
  12. COMPATIBLE_HOST = "aarch64-*"
  13. PACKAGE_ARCH = "${MACHINE_ARCH}"
  14. inherit nopackages deploy rootfs-postcommands ${IMAGE_CLASSES} python3native testimage
  15. do_configure[noexec] = "1"
  16. do_compile[noexec] = "1"
  17. do_install[noexec] = "1"
  18. # Deploy with this suffix so it is picked up in the machine configuration
  19. IMAGE_DEPLOY_SUFFIX ?= ".wic"
  20. # Post-process commands may write to IMGDEPLOYDIR
  21. IMGDEPLOYDIR = "${DEPLOYDIR}"
  22. # Write the test data in IMAGE_POSTPROCESS_COMMAND
  23. IMAGE_POSTPROCESS_COMMAND += "write_image_test_data; "
  24. python do_deploy() {
  25. deploydir = d.getVar('DEPLOYDIR')
  26. suffix = d.getVar('IMAGE_DEPLOY_SUFFIX')
  27. imgfile = os.path.join(d.getVar('UNPACKDIR'), d.getVar('IMAGE_FILENAME'))
  28. deployfile = os.path.join(deploydir, d.getVar('IMAGE_NAME') + suffix)
  29. linkfile = os.path.join(deploydir, d.getVar('IMAGE_LINK_NAME') + suffix)
  30. # Install the image file in the deploy directory
  31. import shutil
  32. shutil.copyfile(imgfile, deployfile)
  33. if os.path.lexists(linkfile):
  34. os.remove(manifest_link)
  35. os.symlink(os.path.basename(deployfile), linkfile)
  36. # Run the image post-process commands
  37. from oe.utils import execute_pre_post_process
  38. post_process_cmds = d.getVar("IMAGE_POSTPROCESS_COMMAND")
  39. execute_pre_post_process(d, post_process_cmds)
  40. # Copy the report.txt to DEPLOYDIR
  41. # The machine-specific implementation can optionally put the report file in
  42. # ${UNPACKDIR}/report.txt. If there is no such file present, use the template.
  43. unpackdir = d.getVar('UNPACKDIR')
  44. report_file = os.path.join(unpackdir, "report.txt")
  45. report_file_dest = os.path.join(deploydir, "report.txt")
  46. if os.path.exists(report_file):
  47. report_file_to_copy = report_file
  48. else:
  49. report_file_to_copy = os.path.join(unpackdir, "systemready-ir-template",
  50. "report.txt")
  51. shutil.copyfile(report_file_to_copy, report_file_dest)
  52. # Ensure an empty rootfs manifest exists (required by testimage)
  53. fname = os.path.join(deploydir, d.getVar('IMAGE_LINK_NAME') + ".manifest")
  54. open(fname, 'w').close()
  55. }
  56. addtask deploy after do_install before do_image_complete
  57. do_image_complete() {
  58. true
  59. }
  60. addtask image_complete after do_deploy before do_build
  61. do_image_complete[depends] += "arm-systemready-firmware:do_image_complete"
  62. ACS_LOG_NAME = "acs_results_${DATETIME}"
  63. ACS_LOG_NAME[vardepsexclude] += "DATETIME"
  64. ACS_LOG_DIR = "${TEST_LOG_DIR}/${ACS_LOG_NAME}"
  65. ACS_LOG_LINK = "${TEST_LOG_DIR}/acs_results"
  66. TEST_LOG_DIR = "${WORKDIR}/testimage"
  67. RM_WORK_EXCLUDE_ITEMS += "${@ os.path.basename(d.getVar('TEST_LOG_DIR')) }"
  68. do_testimage[postfuncs] += "acs_logs_handle"
  69. do_testimage[depends] += "edk2-test-parser-native:do_populate_sysroot \
  70. arm-systemready-scripts-native:do_populate_sysroot \
  71. mtools-native:do_populate_sysroot \
  72. parted-native:do_populate_sysroot"
  73. # Process the logs
  74. python acs_logs_handle() {
  75. import logging
  76. from oeqa.utils import make_logger_bitbake_compatible, get_json_result_dir
  77. import shutil
  78. deploy_dir_image = d.getVar('DEPLOY_DIR_IMAGE')
  79. systemready_scripts_dir = os.path.join(d.getVar('STAGING_LIBDIR_NATIVE'),
  80. "systemready_scripts")
  81. edk2_test_parser_dir = os.path.join(d.getVar('STAGING_LIBDIR_NATIVE'),
  82. "edk2_test_parser")
  83. deployfile = os.path.join(deploy_dir_image, d.getVar('IMAGE_LINK_NAME')
  84. + d.getVar('IMAGE_DEPLOY_SUFFIX'))
  85. testimage_dir = d.getVar('TEST_LOG_DIR')
  86. logdir = d.getVar('ACS_LOG_DIR')
  87. loglink = d.getVar('ACS_LOG_LINK')
  88. # Copy the report.txt file from DEPLOY_DIR_IMAGE
  89. report_file = os.path.join(deploy_dir_image, "report.txt")
  90. report_file_dest = os.path.join(testimage_dir, "report.txt")
  91. shutil.copyfile(report_file, report_file_dest)
  92. # Extract the log files from the Wic image to the testimage logs directory
  93. resultspath = deployfile + ':3/acs_results'
  94. import subprocess
  95. subprocess.run(['wic', 'cp', resultspath, logdir], check=True)
  96. # Create a symlink to the acs_results directory
  97. if os.path.lexists(loglink):
  98. os.remove(loglink)
  99. os.symlink(os.path.basename(logdir), loglink)
  100. # Create a top-level symlink to the acs_results directory
  101. top_logdir = os.path.join(get_json_result_dir(d), d.getVar("PN"))
  102. log_name = d.getVar('ACS_LOG_NAME')
  103. top_link = os.path.join(top_logdir, log_name)
  104. log_target = os.path.relpath(logdir, top_logdir)
  105. os.symlink(log_target, top_link)
  106. # Parse the logs and generate results file
  107. logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
  108. sct_log = os.path.join(logdir, 'sct_results', 'Overall', 'Summary.ekl')
  109. sct_seq = os.path.join(logdir, 'sct_results', 'Sequence', 'EBBR.seq')
  110. parser_path = os.path.join(edk2_test_parser_dir, "parser.py")
  111. # format-sr-results.py needs the output file to be called "result.md"
  112. subprocess.run([parser_path, sct_log, sct_seq, "--md",
  113. os.path.join(logdir, "result.md")], check=True)
  114. scripts_path = os.path.join(systemready_scripts_dir,
  115. "format-sr-results.py")
  116. summary_path = os.path.join(testimage_dir, "summary.md")
  117. subprocess.run([scripts_path, "--dir", testimage_dir, "--md", summary_path],
  118. check=True)
  119. # Symlink acs-console.log to default_log
  120. subprocess.run(["ln", "-sf", os.path.join(testimage_dir, "default_log"),
  121. os.path.join(testimage_dir, "acs-console.log")], check=True)
  122. # Run the check-sr-results.py systemready script to check the results
  123. check_sr_results_log_path = os.path.join(testimage_dir,
  124. "check_sr_results.log")
  125. with open(check_sr_results_log_path, "w") as f:
  126. check_sr_results_path = os.path.join(systemready_scripts_dir,
  127. "check-sr-results.py")
  128. try:
  129. subprocess.run([check_sr_results_path, "--dir", testimage_dir,
  130. "--print-meta", "--debug"],
  131. stdout=f, stderr=f, text=True, check=True)
  132. except subprocess.CalledProcessError:
  133. logger.error(f"ACS run failed the check SystemReady results. See "
  134. f"{summary_path} and {check_sr_results_log_path} for "
  135. f"details of the error.")
  136. raise bb.BBHandledException()
  137. }