[v2] dts: fix pass rate edge case in results json

Message ID 20250115154345.23790-1-dmarx@iol.unh.edu (mailing list archive)
State Accepted
Delegated to: Paul Szczepanek
Headers
Series [v2] dts: fix pass rate edge case in results json |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Dean Marx Jan. 15, 2025, 3:43 p.m. UTC
Add condition to results.json pass rate generation
method which returns 0 as the pass rate when the suite
is skipped, rather than causing a divide by 0 error.

Fixes: 9f8a257235ac ("dts: improve test run result statistics")

Signed-off-by: Dean Marx <dmarx@iol.unh.edu>
---
 dts/framework/test_result.py | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
  

Comments

Luca Vizzarro Jan. 15, 2025, 4:30 p.m. UTC | #1
lgtm. thanks!

Reviewed-by: Luca Vizzarro <luca.vizzarro@arm.com>
  

Patch

diff --git a/dts/framework/test_result.py b/dts/framework/test_result.py
index ba7c1c9804..45fc2e8241 100644
--- a/dts/framework/test_result.py
+++ b/dts/framework/test_result.py
@@ -324,13 +324,10 @@  def generate_pass_rate_dict(self, test_run_summary) -> dict[str, float]:
         Returns:
             A dictionary with the PASS/FAIL ratio of all test cases.
         """
-        return {
-            "PASS_RATE": (
-                float(test_run_summary[Result.PASS.name])
-                * 100
-                / sum(test_run_summary[result.name] for result in Result if result != Result.SKIP)
-            )
-        }
+        cases_not_skipped = sum(
+            test_run_summary[result.name] for result in Result if result != Result.SKIP
+        )
+        return {"PASS_RATE": test_run_summary[Result.PASS.name] * 100.0 / max(cases_not_skipped, 1)}
 
 
 class DTSResult(BaseResult):