test: scan returned values in ci
This commit is contained in:
parent
5da0d33bf2
commit
cef1920251
|
@ -62,11 +62,8 @@ os.makedirs(log_file_path, exist_ok=True)
|
||||||
|
|
||||||
scan_log_file = f"{log_file_path}/scan.log"
|
scan_log_file = f"{log_file_path}/scan.log"
|
||||||
logger.add(scan_log_file, rotation="10MB", retention="7 days", level="DEBUG")
|
logger.add(scan_log_file, rotation="10MB", retention="7 days", level="DEBUG")
|
||||||
# logging.basicConfig(level=logging.INFO,
|
#if error happens, open this to debug
|
||||||
# format='%(asctime)s | %(levelname)s | %(name)s:%(lineno)d - %(message)s')
|
# print(self_path,work_path,TD_project_path,log_file_path,change_file_list)
|
||||||
# logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
print(self_path,work_path,TD_project_path,log_file_path,change_file_list)
|
|
||||||
|
|
||||||
# scan result base path
|
# scan result base path
|
||||||
scan_result_base_path = f"{log_file_path}/clang_scan_result/"
|
scan_result_base_path = f"{log_file_path}/clang_scan_result/"
|
||||||
|
@ -75,7 +72,9 @@ scan_result_base_path = f"{log_file_path}/clang_scan_result/"
|
||||||
# the compile commands json file path
|
# the compile commands json file path
|
||||||
# compile_commands_path = f"{work_path}/debugNoSan/compile_commands.json"
|
# compile_commands_path = f"{work_path}/debugNoSan/compile_commands.json"
|
||||||
compile_commands_path = f"{TD_project_path}/debug/compile_commands.json"
|
compile_commands_path = f"{TD_project_path}/debug/compile_commands.json"
|
||||||
print(f"compile_commands_path:{compile_commands_path}")
|
|
||||||
|
#if error happens, open this to debug
|
||||||
|
# print(f"compile_commands_path:{compile_commands_path}")
|
||||||
|
|
||||||
# # replace the docerk worf path with real work path in compile_commands.json
|
# # replace the docerk worf path with real work path in compile_commands.json
|
||||||
# docker_work_path = "home"
|
# docker_work_path = "home"
|
||||||
|
@ -140,17 +139,14 @@ def input_files(change_files):
|
||||||
tdc_file_path = os.path.join(TD_project_path, "community/")
|
tdc_file_path = os.path.join(TD_project_path, "community/")
|
||||||
file_name = os.path.join(tdc_file_path, file_name)
|
file_name = os.path.join(tdc_file_path, file_name)
|
||||||
all_file_path.append(file_name)
|
all_file_path.append(file_name)
|
||||||
print(f"all_file_path:{all_file_path}")
|
# print(f"all_file_path:{all_file_path}")
|
||||||
# for file_path in change_files:
|
|
||||||
# if (file_path.endswith(".c") or file_path.endswith(".h") or file_path.endswith(".cpp")) and all(item not in file_path for item in scan_skip_file_list):
|
|
||||||
# all_file_path.append(file_path)
|
|
||||||
logger.info("Found %s files" % len(all_file_path))
|
logger.info("Found %s files" % len(all_file_path))
|
||||||
file_res_path = ""
|
file_res_path = ""
|
||||||
|
|
||||||
def save_scan_res(res_base_path, file_path, out, err):
|
def save_scan_res(res_base_path, file_path, out, err):
|
||||||
global file_res_path
|
global file_res_path
|
||||||
file_res_path = os.path.join(res_base_path, file_path.replace(f"{work_path}", "").split(".")[0] + ".txt")
|
file_res_path = os.path.join(res_base_path, file_path.replace(f"{work_path}", "").split(".")[0] + ".txt")
|
||||||
print(f"file_res_path:{file_res_path},res_base_path:{res_base_path},file_path:{file_path}")
|
# print(f"file_res_path:{file_res_path},res_base_path:{res_base_path},file_path:{file_path}")
|
||||||
if not os.path.exists(os.path.dirname(file_res_path)):
|
if not os.path.exists(os.path.dirname(file_res_path)):
|
||||||
os.makedirs(os.path.dirname(file_res_path))
|
os.makedirs(os.path.dirname(file_res_path))
|
||||||
logger.info("Save scan result to: %s" % file_res_path)
|
logger.info("Save scan result to: %s" % file_res_path)
|
||||||
|
@ -174,7 +170,7 @@ if __name__ == "__main__":
|
||||||
# get all the c files path
|
# get all the c files path
|
||||||
# scan_files_path(TD_project_path)
|
# scan_files_path(TD_project_path)
|
||||||
input_files(change_file_list)
|
input_files(change_file_list)
|
||||||
print(f"all_file_path:{all_file_path}")
|
# print(f"all_file_path:{all_file_path}")
|
||||||
res = []
|
res = []
|
||||||
web_path = []
|
web_path = []
|
||||||
res.append(["scan_source_file", "scan_result_file", "match_num", "check_result"])
|
res.append(["scan_source_file", "scan_result_file", "match_num", "check_result"])
|
||||||
|
@ -189,7 +185,8 @@ if __name__ == "__main__":
|
||||||
print(f"cmd:{cmd}")
|
print(f"cmd:{cmd}")
|
||||||
try:
|
try:
|
||||||
stdout, stderr = command_executor.execute(cmd)
|
stdout, stderr = command_executor.execute(cmd)
|
||||||
print(stderr)
|
#if "error" in stderr:
|
||||||
|
# print(stderr)
|
||||||
lines = stdout.split("\n")
|
lines = stdout.split("\n")
|
||||||
if lines[-2].endswith("matches.") or lines[-2].endswith("match."):
|
if lines[-2].endswith("matches.") or lines[-2].endswith("match."):
|
||||||
match_num = int(lines[-2].split(" ")[0])
|
match_num = int(lines[-2].split(" ")[0])
|
||||||
|
|
Loading…
Reference in New Issue