|
| 1 | +import json |
| 2 | +import sys |
| 3 | +import os |
| 4 | +from datetime import datetime |
| 5 | + |
| 6 | +SUCCESS_SYMBOL = ":white_check_mark:" |
| 7 | +FAILURE_SYMBOL = ":x:" |
| 8 | +ERROR_SYMBOL = ":fire:" |
| 9 | + |
| 10 | +# Load the JSON file passed as argument to the script |
| 11 | +with open(sys.argv[1], "r") as f: |
| 12 | + data = json.load(f) |
| 13 | + tests = sorted(data["stats"]["suite_details"], key=lambda x: x["name"]) |
| 14 | + |
| 15 | +# Get commit SHA from command line argument or environment variable |
| 16 | +commit_sha = None |
| 17 | +if len(sys.argv) < 2 or len(sys.argv) > 3: |
| 18 | + print(f"Usage: python {sys.argv[0]} <test_results.json> [commit_sha]", file=sys.stderr) |
| 19 | + sys.exit(1) |
| 20 | +elif len(sys.argv) == 3: # Commit SHA is provided as argument |
| 21 | + commit_sha = sys.argv[2] |
| 22 | +elif "GITHUB_SHA" in os.environ: # Commit SHA is provided as environment variable |
| 23 | + commit_sha = os.environ["GITHUB_SHA"] |
| 24 | +else: # Commit SHA is not provided |
| 25 | + print("Commit SHA is not provided. Please provide it as an argument or set the GITHUB_SHA environment variable.", file=sys.stderr) |
| 26 | + sys.exit(1) |
| 27 | + |
| 28 | +# Generate the table |
| 29 | + |
| 30 | +print("## Runtime Test Results") |
| 31 | +print("") |
| 32 | + |
| 33 | +try: |
| 34 | + if os.environ["IS_FAILING"] == "true": |
| 35 | + print(f"{FAILURE_SYMBOL} **The test workflows are failing. Please check the run logs.** {FAILURE_SYMBOL}") |
| 36 | + print("") |
| 37 | + else: |
| 38 | + print(f"{SUCCESS_SYMBOL} **The test workflows are passing.** {SUCCESS_SYMBOL}") |
| 39 | + print("") |
| 40 | +except KeyError: |
| 41 | + pass |
| 42 | + |
| 43 | +print("### Validation Tests") |
| 44 | + |
| 45 | +proc_test_data = {} |
| 46 | +target_list = [] |
| 47 | + |
| 48 | +for test in tests: |
| 49 | + if test["name"].startswith("performance_"): |
| 50 | + continue |
| 51 | + |
| 52 | + _, platform, target, test_name = test["name"].split("_", 3) |
| 53 | + test_name = test_name[:-1] |
| 54 | + |
| 55 | + if target not in target_list: |
| 56 | + target_list.append(target) |
| 57 | + |
| 58 | + if platform not in proc_test_data: |
| 59 | + proc_test_data[platform] = {} |
| 60 | + |
| 61 | + if test_name not in proc_test_data[platform]: |
| 62 | + proc_test_data[platform][test_name] = {} |
| 63 | + |
| 64 | + if target not in proc_test_data[platform][test_name]: |
| 65 | + proc_test_data[platform][test_name][target] = { |
| 66 | + "failures": 0, |
| 67 | + "total": 0, |
| 68 | + "errors": 0 |
| 69 | + } |
| 70 | + |
| 71 | + proc_test_data[platform][test_name][target]["total"] += test["tests"] |
| 72 | + proc_test_data[platform][test_name][target]["failures"] += test["failures"] |
| 73 | + proc_test_data[platform][test_name][target]["errors"] += test["errors"] |
| 74 | + |
| 75 | +target_list = sorted(target_list) |
| 76 | + |
| 77 | +for platform in proc_test_data: |
| 78 | + print("") |
| 79 | + print(f"#### {platform.capitalize()}") |
| 80 | + print("") |
| 81 | + print("Test", end="") |
| 82 | + |
| 83 | + for target in target_list: |
| 84 | + # Make target name uppercase and add hyfen if not esp32 |
| 85 | + if target != "esp32": |
| 86 | + target = target.replace("esp32", "esp32-") |
| 87 | + |
| 88 | + print(f"|{target.upper()}", end="") |
| 89 | + |
| 90 | + print("") |
| 91 | + print("-" + "|:-:" * len(target_list)) |
| 92 | + |
| 93 | + for test_name, targets in proc_test_data[platform].items(): |
| 94 | + print(f"{test_name}", end="") |
| 95 | + for target in target_list: |
| 96 | + if target in targets: |
| 97 | + test_data = targets[target] |
| 98 | + if test_data["errors"] > 0: |
| 99 | + print(f"|Error {ERROR_SYMBOL}", end="") |
| 100 | + else: |
| 101 | + print(f"|{test_data['total']-test_data['failures']}/{test_data['total']}", end="") |
| 102 | + if test_data["failures"] > 0: |
| 103 | + print(f" {FAILURE_SYMBOL}", end="") |
| 104 | + else: |
| 105 | + print(f" {SUCCESS_SYMBOL}", end="") |
| 106 | + else: |
| 107 | + print("|-", end="") |
| 108 | + print("") |
| 109 | + |
| 110 | +print("\n") |
| 111 | +print(f"Generated on: {datetime.now().strftime('%Y/%m/%d %H:%M:%S')}") |
| 112 | +print("") |
| 113 | + |
| 114 | +try: |
| 115 | + print(f"[Commit](https://github.com/{os.environ['GITHUB_REPOSITORY']}/commit/{commit_sha}) / [Build and QEMU run](https://github.com/{os.environ['GITHUB_REPOSITORY']}/actions/runs/{os.environ['BUILD_RUN_ID']}) / [Hardware and Wokwi run](https://github.com/{os.environ['GITHUB_REPOSITORY']}/actions/runs/{os.environ['WOKWI_RUN_ID']})") |
| 116 | +except KeyError: |
| 117 | + pass |
| 118 | + |
| 119 | +# Save test results to JSON file |
| 120 | +results_data = { |
| 121 | + "commit_sha": commit_sha, |
| 122 | + "tests_failed": os.environ["IS_FAILING"] == "true", |
| 123 | + "test_data": proc_test_data, |
| 124 | + "generated_at": datetime.now().isoformat() |
| 125 | +} |
| 126 | + |
| 127 | +with open("test_results.json", "w") as f: |
| 128 | + json.dump(results_data, f, indent=2) |
| 129 | + |
| 130 | +print(f"\nTest results saved to test_results.json", file=sys.stderr) |
| 131 | +print(f"Commit SHA: {commit_sha}", file=sys.stderr) |
| 132 | +print(f"Tests failed: {results_data['tests_failed']}", file=sys.stderr) |
0 commit comments