-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathtest.py
More file actions
executable file
·156 lines (125 loc) · 5.41 KB
/
Copy pathtest.py
File metadata and controls
executable file
·156 lines (125 loc) · 5.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#!/usr/bin/env python3
import argparse
import csv
import os
import sys
from types import SimpleNamespace
from benchmark import run_benchmarks
from benchmarks.benchmark import benchmarks
from compare import load_expected, compare_input
from util import schemajson
from util.log import log
workdir = os.getcwd()
csv.field_size_limit(sys.maxsize)
def main():
parser = argparse.ArgumentParser(description="Test OLAPBench.")
parser.add_argument("filenames", nargs="*", default=[], help="Optional list of configuration files")
args = parser.parse_args()
requested = {os.path.basename(f).split('.')[0] for f in args.filenames}
yaml_files = [
f for f in os.listdir(os.path.join(workdir, "test"))
if f.endswith('.yaml') and (not requested or f.split('.')[0] in requested)
]
if args.filenames and not yaml_files:
log.error(f"No test files matched: {', '.join(args.filenames)}")
return False
succeeded = []
failed = []
for file in yaml_files:
log.header(file)
try:
run_test(file)
succeeded.append(file)
except Exception as e:
log.error(f"Test '{file}' failed: {e}")
failed.append((file, e))
log.header("Test summary")
log.info(f"{len(succeeded)}/{len(yaml_files)} tests succeeded")
for file in succeeded:
log.info(f" PASS {file}")
for file, e in failed:
log.error(f" FAIL {file}: {e}")
return len(failed) == 0
def run_test(file):
args = SimpleNamespace(
json=os.path.join(workdir, "test", file),
verbose=False,
very_verbose=False,
db="db",
data="data",
env=None,
clear=True,
launch=False,
benchmark="default",
)
run_benchmarks(args)
definition = schemajson.load(os.path.join(workdir, args.json), "benchmark.schema.json")
output_dir = os.path.join(workdir, definition["output"])
results = {}
versions = []
expected_dbms = None
for system in definition["systems"]:
if expected_dbms is None:
expected_dbms = system["dbms"]
elif expected_dbms != system["dbms"]:
raise Exception(f"System name '{system['dbms']}' in definition does not match the first system.")
if isinstance(system["parameter"]["version"], list):
versions.extend(system["parameter"]["version"])
else:
versions.append(system["parameter"]["version"])
benchmark_descriptions = benchmarks()
total_valid = {}
total_invalid = {}
all_mismatches = []
for b in definition["benchmarks"]:
benchmark = benchmark_descriptions[b["name"]].instantiate("data", b)
result_csv = os.path.join(output_dir, benchmark.result_name + ".csv")
with open(result_csv, "r") as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
dbms = row["dbms"]
version = row["version"]
state = row["state"]
query = row["query"]
if dbms != expected_dbms:
raise Exception(f"System name '{dbms}' in output does not match the definition.")
if version not in versions:
raise Exception(f"Version '{version}' in output does not match the definition.")
if state not in ["success", "timeout", "global_timeout"]:
raise Exception(f"Unexpected state '{state}' in output.")
if version not in results:
results[version] = []
results[row["version"]].append(query)
# Compare the results against the pre-computed expected results
expected_dir = os.path.join(workdir, "test", "expected", benchmark.result_name)
if not os.path.isdir(expected_dir):
raise Exception(f"No expected results found for '{benchmark.result_name}' (expected at {expected_dir}).")
expected, queries = load_expected(expected_dir)
_, _, per_system_valid, per_system_invalid, mismatches = compare_input(result_csv, expected, queries)
for title, count in per_system_valid.items():
total_valid[title] = total_valid.get(title, 0) + count
for title, count in per_system_invalid.items():
total_invalid[title] = total_invalid.get(title, 0) + count
all_mismatches.extend(mismatches)
# Report, per version, how many queries match and mismatch the expectation.
# Use the `log` console (which owns the comparison progress bar) so the
# transient progress display is cleared correctly before the header is drawn.
log.header("Result comparison")
for title in sorted(total_valid.keys() | total_invalid.keys()):
match = total_valid.get(title, 0)
mismatch = total_invalid.get(title, 0)
log.info(f"{title}: {match} match, {mismatch} mismatch")
if all_mismatches:
details = ", ".join(f"{title}: {query}" for title, query in all_mismatches)
raise Exception(f"{len(all_mismatches)} queries with results differing from the expectation: {details}")
query_names = benchmark.query_names()
for version in results:
if set(query_names) != set(results[version]):
raise Exception(f"Mismatch between expected queries and results for version '{version}'.")
if __name__ == "__main__":
try:
all_passed = main()
except Exception as e:
log.error(e)
raise e
sys.exit(0 if all_passed else 1)