arm-systemready-acs.bbclass 7.0 KB

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