Skip to content

Commit 1e7ae47

Browse files
committed
support running single ctest
1 parent c59b3cd commit 1e7ae47

File tree

5 files changed

+68
-24
lines changed

5 files changed

+68
-24
lines changed

core/run_ctest/main.py

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
project = p_input["project"]
1515

1616

17-
def main(argv):
17+
def main():
1818
print(">>>>[ctest_core] running project {}".format(project))
1919
s = time.time()
2020
os.makedirs(os.path.join(RUNCTEST_TR_DIR, project), exist_ok=True)
@@ -23,27 +23,17 @@ def main(argv):
2323
print(">>>>[ctest_core] input conf file: {}".format(conf_file_path))
2424
test_input = extract_conf_diff(conf_file_path)
2525
test_conf_file(conf_file_path, test_input)
26-
elif run_mode == "run_single_ctest":
27-
for conf_file_path in sorted(glob.glob(os.path.join(p_input["conf_file_dir"], "*"))):
28-
print(">>>>[ctest_core] input conf file: {}".format(conf_file_path))
29-
test_input = extract_conf_diff(conf_file_path)
30-
test_conf_file(conf_file_path, test_input, argv[1])
3126
else:
3227
sys.exit(">>>>[ctest_core] invalid run_mode")
3328
print(">>>>[ctest_core] total time: {} seconds".format(time.time() - s))
3429

35-
def test_conf_file(conf_file_path, test_input, ctestname = "notuse"):
30+
def test_conf_file(conf_file_path, test_input):
3631
fbase = os.path.splitext(os.path.basename(conf_file_path))[0]
3732
params = test_input.keys()
3833
if run_mode == "run_ctest":
3934
associated_test_map, associated_tests = extract_mapping(mapping, params)
4035
print(">>>>[ctest_core] # parameters associated with the run: {}".format(len(params)))
4136
print(">>>>[ctest_core] # ctests to run in total: {}".format(len(associated_tests)))
42-
elif run_mode == "run_single_ctest":
43-
associated_test_map = dict([[i, list((ctestname, ))] for i in params if ctestname in mapping[i]])
44-
associated_tests = set((ctestname, ))
45-
print(">>>>[ctest_core] # parameters associated with the run: {}".format(len(params)))
46-
print(">>>>[ctest_core] # single ctest to run")
4737
tr_file = open(os.path.join(RUNCTEST_TR_DIR, project, TR_FILE.format(id=fbase)), "w")
4838
mt_file = open(os.path.join(RUNCTEST_TR_DIR, project, MT_FILE.format(id=fbase)), "w")
4939
if len(associated_tests) != 0:
@@ -69,4 +59,4 @@ def test_conf_file(conf_file_path, test_input, ctestname = "notuse"):
6959

7060

7161
if __name__ == '__main__':
72-
main(sys.argv)
62+
main()

core/run_ctest/parse_input.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,15 @@ def extract_conf_diff(path):
105105
print(">>>>[ctest_core] config diff: {} (param, value) pairs".format(len(conf_diff)))
106106
return conf_diff
107107

108+
def extract_conf_diff_from_pair(param_value_dict):
109+
default_conf_map = load_default_conf(DEFAULT_CONF_FILE[project])
110+
conf_diff = {}
111+
for param, value in param_value_dict.items():
112+
if param not in default_conf_map:
113+
print(">>>>[ctest_core] parameter {} in input config file is not in default config file".format(param))
114+
if param not in default_conf_map or value != default_conf_map[param]:
115+
conf_diff[param] = value
116+
return conf_diff
108117

109118
def parse_mapping(path):
110119
print(">>>>[ctest_core] loading mapping {}".format(path))

core/run_ctest/run_ctest.sh

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,4 @@
22

33
# please specify data input in program_input.py before running this script
44

5-
ctestname=$1
6-
function main() {
7-
if [ -z $ctestname ]
8-
then
9-
python3 main.py
10-
else
11-
python3 main.py $ctestname
12-
fi
13-
}
14-
15-
main
5+
python3 main.py

core/run_ctest/run_single_ctest.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import sys, time
2+
3+
from program_input import p_input
4+
from main import test_conf_file
5+
from parse_input import *
6+
7+
run_mode = p_input["run_mode"]
8+
project = p_input["project"]
9+
mapping = parse_mapping(p_input["mapping_path"])
10+
from run_test import run_test_batch
11+
12+
def main(argv):
13+
print(">>>>[ctest_core] running project {}".format(project))
14+
s = time.time()
15+
ctestname = argv[1]
16+
if run_mode == "run_ctest":
17+
print("Please use the run_single_ctest mode")
18+
return
19+
elif run_mode == "run_single_ctest":
20+
param_value_dict = {}
21+
for i in range(2, len(argv)):
22+
param, value = argv[i].split('=')
23+
param_value_dict[param] = value
24+
test_input = extract_conf_diff_from_pair(param_value_dict)
25+
test_conf_file(test_input, ctestname)
26+
print(">>>>[ctest_core] total time: {} seconds".format(time.time() - s))
27+
28+
def test_conf_file(test_input, ctestname):
29+
params = test_input.keys()
30+
associated_test_map = dict([[i, list((ctestname, ))] for i in params if ctestname in mapping[i]])
31+
associated_tests = set((ctestname, ))
32+
print(">>>>[ctest_core] # parameters associated with the run: {}".format(len(params)))
33+
tr = run_test_batch(test_input, associated_test_map)
34+
tup = tr.ran_tests_and_time.pop()
35+
test, mvntime = tup.split("\t")
36+
if test in tr.failed_tests:
37+
print(">>>>[ctest_core] The single ctest FAIL")
38+
else:
39+
print(">>>>[ctest_core] The single ctest PASS")
40+
41+
if __name__ == "__main__":
42+
main(sys.argv)

core/run_ctest/show_pset.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sys, json
2+
3+
def main(argv):
4+
mapping = json.load(open("../../data/ctest_mapping/opensource-zookeeper-server.json"))
5+
count = 0
6+
for key, value in mapping.items():
7+
if argv[1] in value:
8+
count += 1
9+
print("p", count," ", key, sep='')
10+
print("Number of parameter is", count)
11+
12+
if __name__ == "__main__":
13+
main(sys.argv)

0 commit comments

Comments
 (0)