-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.py
More file actions
90 lines (71 loc) · 2.2 KB
/
util.py
File metadata and controls
90 lines (71 loc) · 2.2 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
import typing
import os
from subprocess import run, TimeoutExpired
import clang.cindex
import lizard
import pandas as pd
def _is_c_or_cpp_file(filename: str):
# Extract the file extension
_, extension = os.path.splitext(filename)
return extension.lower() in [
".c",
".cpp",
".cxx",
".cc",
".c++",
".h",
".hpp",
".hxx",
".hh",
".inl",
".cu",
".cuh",
]
def get_selected_vcc_from_file_df(input_file_name: str) -> pd.DataFrame:
commit_df = pd.read_csv(f"../data-ref/{input_file_name}")
return commit_df
def get_output_filename(project: str, commit_sha: str) -> str:
project_name = project.replace("/", "-")
return f"{project_name}-{commit_sha}"
def _check_transaction_data(transaction_data: dict) -> bool:
try:
assert "trial_name" in transaction_data
assert "project" in transaction_data
assert "tool" in transaction_data
assert "tool_type" in transaction_data
assert "commit_sha" in transaction_data
assert "parent_commit_sha" in transaction_data
assert "is_parent_commit" in transaction_data
assert "result_location" in transaction_data
assert "result_count" in transaction_data
assert "execution_status" in transaction_data
assert "start_time" in transaction_data
assert "end_time" in transaction_data
return True
except Exception:
return False
def run_command(
command: typing.Union[str, list],
shell_execution: bool = False,
expected_return_code: int = 0,
) -> (bool, str):
result = "SUCCESS"
try:
# allow maximum 5hr to execute a command
# up to 5hr only for cppcheck
if (
run(command, timeout=60 * 60 * 5, shell=shell_execution).returncode
== expected_return_code
):
return (True, result)
result = "FAILED"
except TimeoutExpired:
print("subprocess timeout, execution failed")
result = "TIMEOUT"
pass
except Exception as ex:
# in any failures, return false
print(str(ex))
result = "EXCEPTION"
pass
return (False, result)