-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathexecutor_test.py
146 lines (118 loc) · 4.56 KB
/
executor_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
import os
import re
import time
import json
from pathlib import Path
from executor import test_executor
# def scan_gen(json_folder, json_files, existing_files):
# new_gen_files = set()
# for json_file in json_files:
# json_file = os.path.join(json_folder, json_file)
# # print(json_file)
# if os.path.exists(json_file):
# with open(json_file, "r") as file:
# data = json.load(file)
# for k, v in data["target_lines_triggered"].items():
# if isinstance(v, list):
# for item in v:
# if item not in existing_files:
# new_gen_files.add(item)
# # print("len: ", len(new_gen_files))
# # print("existing file: ", len(existing_files))
# return new_gen_files
def scan_gen(gen_dirs, existing_gens: set):
new_gens = set()
for target_dir in gen_dirs.iterdir():
if not target_dir.is_dir():
continue
for gen_dir in target_dir.iterdir():
if not gen_dir.is_dir():
continue
for gen_file in gen_dir.iterdir():
if not gen_file.is_file():
continue
# if gen_file.suffix != ".py" and gen_file.suffix != ".ll": continue
if gen_file.suffix != ".ll":
continue
if gen_file in existing_gens:
continue
new_gens.add(gen_file)
return new_gens
def info_dump(Statistics: dict, path=None):
print(f"{len(Statistics.keys())} has been tested and saved")
if path is not None:
with open(path, "a") as f:
f.write(json.dumps(Statistics) + "\n")
def info_read(path=None):
alldata = {}
if path is not None:
with open(path, "r") as f:
lines = f.readlines()
for l in lines:
data = json.loads(l)
alldata.update(data)
return alldata
"""
python --json_folder
"""
if __name__ == "__main__":
import argparse
parser = argparse.ArgumentParser()
parser.add_argument(
"--json-folder",
type=str,
default="/JawTitan/whitefox-data/starcoder-1000/llvm-exe-result/trigger_test",
)
parser.add_argument(
"--jsons",
type=str,
default="no_source_with_specific_ir_prompt.json_AND_no_source_prompt.json",
)
parser.add_argument(
"--out_dir",
type=str,
default="/JawTitan/whitefox-data/llvm-exe-result/diff_test1",
)
parser.add_argument(
"--gen-dir",
type=str,
default="/JawTitan/whitefox-data/starcoder-1000/llvm-opt/",
)
args = parser.parse_args()
# python executor_test.py --jsons mixed_prompt_for_starcoder.json --out_dir /JawTitan/whitefox-data/starcoder/llvm-exe-result/diff_test_mixed_nl
# python executor_test.py --jsons starcoder_cpp_deadarg.json --out_dir /JawTitan/whitefox-data/starcoder/llvm-exe-result/diff_test_cpp_code
# python executor_test.py --jsons llvm-opt-run_2023_09_27.json --out_dir /JawTitan/whitefox-data/starcoder/llvm-exe-result/diff_test_llvm_opt_run
# python executor_test.py --jsons llvm-1000.json --out_dir /JawTitan/whitefox-data/starcoder-1000/llvm-exe-result/diff_test_llvm_opt_run
sleep_time = 30
json_files = list(args.jsons.split("_AND_"))
print(json_files)
json_folder = args.json_folder
out_dir = Path(args.out_dir)
out_dir.mkdir(parents=True, exist_ok=True)
os.chmod(out_dir, 0o777)
out_json_path = os.path.join(out_dir, "diff_result.jsonl")
if os.path.exists(out_json_path):
print("find json: ", out_json_path)
out_json_dict = info_read(out_json_path)
else:
print("don't find json, build one: ", out_json_path)
out_json_dict = {}
all_trigger_files = []
existing_files = set(out_json_dict.keys())
gen_dirs = Path(args.gen_dir)
while True:
new_gen_files = scan_gen(gen_dirs, existing_files)
if len(new_gen_files) == 0:
print(f"No new gen file, sleep {sleep_time}s...")
time.sleep(sleep_time)
continue
length = len(new_gen_files)
print(f"Found {length} new gen_files, start testing...")
for idx, gen_file in enumerate(new_gen_files):
existing_files.add(gen_file)
# llc -> compare -> exe -> compare
log = test_executor(gen_file, str(out_dir), timeout=30)
if log == None:
continue
info_dump(log, out_json_path)
out_json_dict.update(log)