Skip to content

Commit

Permalink
tools/compare: add failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
LebedevRI committed Jan 7, 2024
1 parent a01ec6c commit 9282814
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tools/gbench/Inputs/test5_run0.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"context": {
"date": "2016-08-02 17:44:46",
"num_cpus": 4,
"mhz_per_cpu": 4228,
"cpu_scaling_enabled": false,
"library_build_type": "release"
},
"benchmarks": [
{
"name": "BM_ManyRepetitions",
"iterations": 1000,
"real_time": 1,
"cpu_time": 1000,
"time_unit": "s"
}
]
}
18 changes: 18 additions & 0 deletions tools/gbench/Inputs/test5_run1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"context": {
"date": "2016-08-02 17:44:46",
"num_cpus": 4,
"mhz_per_cpu": 4228,
"cpu_scaling_enabled": false,
"library_build_type": "release"
},
"benchmarks": [
{
"name": "BM_ManyRepetitions",
"iterations": 1000,
"real_time": 1000,
"cpu_time": 1,
"time_unit": "s"
}
]
}
96 changes: 96 additions & 0 deletions tools/gbench/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -1490,6 +1490,102 @@ def test_json_diff_report_pretty_printing(self):
self.assertEqual(out["name"], expected)


class TestReportDifferenceWithUTestWhileDisplayingAggregatesOnly2(
unittest.TestCase
):
@classmethod
def setUpClass(cls):
def load_results():
import json

testInputs = os.path.join(
os.path.dirname(os.path.realpath(__file__)), "Inputs"
)
testOutput1 = os.path.join(testInputs, "test5_run0.json")
testOutput2 = os.path.join(testInputs, "test5_run1.json")
with open(testOutput1, "r") as f:
json1 = json.load(f)
json1["benchmarks"] = [
json1["benchmarks"][0] for i in range(1000)
]
with open(testOutput2, "r") as f:
json2 = json.load(f)
json2["benchmarks"] = [
json2["benchmarks"][0] for i in range(1000)
]
return json1, json2

json1, json2 = load_results()
cls.json_diff_report = get_difference_report(json1, json2, utest=True)

@unittest.expectedFailure
def test_json_diff_report_pretty_printing(self):
expect_line = [
"BM_ManyRepetitions_pvalue",
"0.0000",
"0.0000",
"U",
"Test,",
"Repetitions:",
"1000",
"vs",
"1000",
]
output_lines_with_header = print_difference_report(
self.json_diff_report, utest=True, utest_alpha=0.05, use_color=False
)
output_lines = output_lines_with_header[2:]
found = False
for i in range(0, len(output_lines)):
parts = [x for x in output_lines[i].split(" ") if x]
found = expect_line == parts
if found:
break
self.assertTrue(found)

@unittest.expectedFailure
def test_json_diff_report(self):
expected_output = [
{
"name": "BM_ManyRepetitions",
"label": "",
"time_unit": "s",
"run_type": "",
"aggregate_name": "",
"utest": {
"have_optimal_repetitions": True,
"cpu_pvalue": 0.0,
"time_pvalue": 0.0,
"nr_of_repetitions": 1000,
"nr_of_repetitions_other": 1000,
},
},
{
"name": "OVERALL_GEOMEAN",
"label": "",
"measurements": [
{
"real_time": 1.0,
"cpu_time": 1000.000000000069,
"real_time_other": 1000.000000000069,
"cpu_time_other": 1.0,
"time": 999.000000000069,
"cpu": -0.9990000000000001,
}
],
"time_unit": "s",
"run_type": "aggregate",
"aggregate_name": "geomean",
"utest": {},
},
]
self.assertEqual(len(self.json_diff_report), len(expected_output))
for out, expected in zip(self.json_diff_report, expected_output):
self.assertEqual(out["name"], expected["name"])
self.assertEqual(out["time_unit"], expected["time_unit"])
assert_utest(self, out, expected)


def assert_utest(unittest_instance, lhs, rhs):
if lhs["utest"]:
unittest_instance.assertAlmostEqual(
Expand Down

0 comments on commit 9282814

Please sign in to comment.