This repository has been archived by the owner on Mar 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 32
/
test.py
316 lines (284 loc) · 9.07 KB
/
test.py
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#!/usr/bin/env python3
#
# SPDX-License-Identifier: Apache-2.0
# Copyright 2021, Intel Corporation
import os, sys
import pytest
import json
import tempfile
import jsonschema
DEFAULT_TEST_FILE = "/dev/shm/pmemkv_test_db"
tests_path = os.path.dirname(os.path.realpath(__file__))
project_path = os.path.dirname(tests_path)
sys.path.append(project_path)
import run_benchmark as rb
build_configuration = {
"db_bench": {
"repo_url": project_path,
"commit": "HEAD",
"env": {},
},
"pmemkv": {
"repo_url": "https://github.com/pmem/pmemkv.git",
"commit": "HEAD",
"cmake_params": [
"-DCMAKE_BUILD_TYPE=Release",
"-DENGINE_CMAP=1",
"-DENGINE_CSMAP=1",
"-DENGINE_RADIX=1",
"-DENGINE_STREE=1",
"-DENGINE_ROBINHOOD=1",
"-DENGINE_VCMAP=1",
"-DBUILD_JSON_CONFIG=1",
"-DCXX_STANDARD=20",
"-DBUILD_TESTS=OFF",
"-DBUILD_DOC=OFF",
"-DBUILD_EXAMPLES=OFF",
],
"env": {"CC": "gcc", "CXX": "g++"},
},
"libpmemobjcpp": {
"repo_url": "https://github.com/pmem/libpmemobj-cpp.git",
"commit": "HEAD",
"cmake_params": [
"-DBUILD_EXAMPLES=OFF",
"-DBUILD_TESTS=OFF",
"-DBUILD_DOC=OFF",
"-DBUILD_BENCHMARKS=OFF",
"-DCMAKE_BUILD_TYPE=Release",
],
"env": {"CC": "gcc", "CXX": "g++"},
},
}
def create_config_file(configuration):
tf = tempfile.NamedTemporaryFile(suffix=".json", mode="w", delete=False)
json.dump(configuration, tf)
tf.close()
return tf
def execute_run_benchmark(build_configuration, benchmark_configuration):
build_config_file = create_config_file(build_configuration)
test_config_file = create_config_file(benchmark_configuration)
sys.argv = ["dummy.py", build_config_file.name, test_config_file.name]
try:
result = rb.main()
except Exception as e:
assert False, f"run-bench raised exception: {e}"
return result
def test_help():
"""Simple sanity check for -h option of run_benchmark.py."""
sys.argv = ["dummy.py", "-h"]
with pytest.raises(SystemExit) as e:
result = rb.main()
assert e.type == SystemExit
assert e.value.code == 0
@pytest.mark.parametrize(
"engine,test_path,benchmarks",
[
(
"cmap",
os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE),
"fillrandom,readrandom",
),
(
"csmap",
os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE),
"fillrandom,readrandom",
),
(
"blackhole",
os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE),
"fillrandom,readrandom",
),
],
)
def test_numactl(engine, test_path, benchmarks):
"""Basic integration test for run_benchmark.py. It runs full
benchmarking process for arbitrarily chosen parameters.
"""
benchmark_configuration = [
{
"env": {"PMEM_IS_PMEM_FORCE": "1", "KV_BENCH_TEST_PATH": test_path},
"pmemkv_bench": {
"--db": test_path,
"--db_size_in_gb": "1",
"--benchmarks": benchmarks,
"--engine": engine,
"--num": "100",
"--value_size": "8",
"--key_size": "16",
"--threads": "2",
},
"numactl": {
"--physcpubind": "1",
},
"cleanup": 1,
},
]
res = execute_run_benchmark(build_configuration, benchmark_configuration)
assert len(res) == 1
@pytest.mark.parametrize(
"engine,test_path,benchmarks",
[
(
"cmap",
os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE),
"fillrandom,readrandom",
),
(
"cmap",
os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE),
"readrandom,fillrandom,readrandom",
),
(
"csmap",
os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE),
"fillrandom,readrandom",
),
(
"vcmap",
os.path.dirname(os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE)),
"fillrandom,readrandom",
),
(
"vsmap",
os.path.dirname(os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE)),
"fillrandom,readrandom",
),
],
)
def test_json(engine, test_path, benchmarks):
"""Basic integration test for run_benchmark.py. It runs full
benchmarking process for arbitrarily chosen parameters.
"""
test_path_radix = os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE)
benchmark_configuration = [
{
"env": {"PMEM_IS_PMEM_FORCE": "1", "KV_BENCH_TEST_PATH": test_path},
"pmemkv_bench": {
"--db": test_path,
"--db_size_in_gb": "1",
"--benchmarks": benchmarks,
"--engine": engine,
"--num": "100",
"--value_size": "8",
"--key_size": "8",
"--threads": "2",
},
"cleanup": 1,
},
{
"env": {"KV_BENCH_TEST_PATH": test_path_radix},
"pmemkv_bench": {
"--db": test_path_radix,
"--db_size_in_gb": "2",
"--benchmarks": "fillseq",
"--engine": "radix",
"--num": "100",
"--value_size": "1024",
"--key_size": "128",
"--threads": "1",
},
"cleanup": 1,
},
]
res = execute_run_benchmark(build_configuration, benchmark_configuration)
assert len(res) == 2
@pytest.mark.parametrize(
"bench1,cleanup1,bench2,expected",
[
("fillseq", 0, "readseq", 100),
("fillrandom", 1, "readrandom", 0),
("readrandom", 1, "readrandom", 0),
],
)
def test_benchmarks_separate_processes(bench1, cleanup1, bench2, expected):
"""Test two runs of run_benchmark.py. Each in separate process,
some of them separated by a pool cleanup.
"""
test_path = os.getenv("KV_BENCH_TEST_PATH", DEFAULT_TEST_FILE)
benchmark_configuration = [
{
"env": {"KV_BENCH_TEST_PATH": test_path},
"pmemkv_bench": {
"--db": test_path,
"--db_size_in_gb": "1",
"--benchmarks": bench1,
"--engine": "cmap",
"--num": "100",
"--value_size": "8",
"--key_size": "8",
"--threads": "2",
},
"cleanup": cleanup1,
}
]
execute_run_benchmark(build_configuration, benchmark_configuration)
benchmark_configuration[0]["cleanup"] = 1
benchmark_configuration[0]["pmemkv_bench"]["--benchmarks"] = bench2
res = execute_run_benchmark(build_configuration, benchmark_configuration)
# parse x from: "extra_data" : "(x of 100 found by one thread)"
extra_data = res[0]["results"][0]["extra_data"]
found = int(extra_data.split()[0][1:])
assert found == expected
@pytest.mark.parametrize(
"scenario",
[
"generate_obj_based_scope.py",
"generate_dram_scope.py",
"generate_memkind_based_scope.py",
],
)
def test_scenario(scenario):
"""Test if schema validation works as expected."""
scenario_path = os.path.join(project_path, "bench_scenarios", scenario)
schema_path = os.path.join(project_path, "bench_scenarios", "bench.schema.json")
output = rb.load_scenarios(scenario_path)
schema = None
with open(schema_path, "r") as schema_file:
schema = json.loads(schema_file.read())
jsonschema.validate(instance=output, schema=schema)
@pytest.mark.parametrize(
"test_description,input_json,schema",
[
(
"missing required projects to build",
{
"db_bench": {
"repo_url": "project_path",
"commit": "HEAD",
"env": {},
},
"env": {"CC": "gcc", "CXX": "g++"},
},
"build.schema.json",
),
(
"missing params",
[
{
"env": {"PMEM_IS_PMEM_FORCE": "1"},
},
],
"bench.schema.json",
),
(
"missing params fields",
[
{
"env": {"PMEM_IS_PMEM_FORCE": "1"},
"pmemkv_bench": {
"--num": "100",
},
},
],
"bench.schema.json",
),
],
)
def test_wrong_input(input_json, schema, test_description):
"""Unit test for json schema validation"""
print(f"Test: {test_description}")
schema_path = os.path.join(project_path, "bench_scenarios", schema)
json_test_path = create_config_file(input_json)
with pytest.raises(jsonschema.exceptions.ValidationError):
result = rb.load_scenarios(json_test_path.name, schema_path)