Skip to content

Commit

Permalink
testing
Browse files Browse the repository at this point in the history
  • Loading branch information
YukiYang31 committed Mar 3, 2024
1 parent a8244f9 commit bd08145
Show file tree
Hide file tree
Showing 10 changed files with 225 additions and 111 deletions.
13 changes: 8 additions & 5 deletions src/chooseFile.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
/app/code/tests/cFiles/C-master/CmasterFiles.txt // ISSTA benchmark
/app/code/experiments/testFiles.txt


we are only testing in the above file, below is a list of file path for easy copy paste:
/app/code/tests/cFiles/SV_benchmark/busybox-1.22.0/files.txt
/app/code/tests/cFiles/SV_benchmark/eca-rers2018/files.txt
/app/code/experiments/testFiles.txt // this is for random quick testing
/app/code/experiments/function_calls/benchmark/benchmarkFiles.txt //this is ICSE paper benchmark

/app/code/tests/cFiles/SV_benchmark/files.txt // this has 1720 files
/app/code/experiments/testFiles.txt // this is for random quick testing
/app/code/tests/cFiles/C-master/CmasterFiles.txt // ISSTA2024 benchmark
/app/code/experiments/function_calls/benchmark/benchmarkFiles.txt // ICSE2024 poster benchmark
/app/code/experiments/icse_experiment/files/files.txt // ICSE2021 paper benchmark
/app/code/experiments/recursion/files/files.txt // this should be example_apc_functions.c, the benchmark for formalize2023
5 changes: 3 additions & 2 deletions src/experiments/function_calls/summer2023_tests/test_apc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def collect(self) -> None:
"""Compute the metrics for all files and store the data."""
data = pd.DataFrame({"file_name": [], "graph_name": [], "apc": [], "apc_time": [],"exception": [],"exception_type": []})
with open("/app/code/chooseFile.txt") as filess:
filePath = [line.rstrip() for line in filess]
filePathwithComments = [line.rstrip() for line in filess]
filePath = filePathwithComments[0].split()[0]
print(filePath)
with open(filePath[0]) as funcs:
with open(filePath) as funcs:
# files = ['/app/code/experiments/recursion/files/catalan-numbers-1.c' ]
files = [line.rstrip() for line in funcs]

Expand Down
5 changes: 3 additions & 2 deletions src/experiments/function_calls/summer2023_tests/test_fcapc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def collect(self) -> None:
"""Compute the metrics for all files and store the data."""
data = pd.DataFrame({"file_name": [], "graph_name": [], "fcapc": [], "fcapc_time": [], 'naiveMathTime':[], 'firstHalfTime':[], "exception": [],"exception_type": []})
with open("/app/code/chooseFile.txt") as filess:
filePath = [line.rstrip() for line in filess]
filePathwithComments = [line.rstrip() for line in filess]
filePath = filePathwithComments[0].split()[0]
print(filePath)
with open(filePath[0]) as funcs:
with open(filePath) as funcs:
# files = ['/app/code/experiments/recursion/files/catalan-numbers-1.c' ]
files = [line.rstrip() for line in funcs]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ def collect(self) -> None:
"exception": [],"exception_type": [],"case":[],'gamma':[]})

with open("/app/code/chooseFile.txt") as filess:
filePath = [line.rstrip() for line in filess]
print(filePath[0])
with open(filePath[0]) as funcs: # open the first filePath in chooseFile
filePathwithComments = [line.rstrip() for line in filess]
filePath = filePathwithComments[0].split()[0]
print(f"benchmark that we are testing {filePath}")
with open(filePath) as funcs: # open the first filePath in chooseFile
# files = ['/app/code/experiments/recursion/files/catalan-numbers-1.c' ]
files = [line.rstrip() for line in funcs]

for i in files:
if i[0:1] == "*":
continue
print(f"IIIIII: {i}")
file = i.split()[0]
funcs = i.split()[1:]
print(f"Now analyzing {file}")
Expand Down
5 changes: 3 additions & 2 deletions src/experiments/function_calls/summer2023_tests/test_rapc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ def collect(self) -> None:
"""Compute the metrics for all files and store the data."""
data = pd.DataFrame({"file_name": [], "graph_name": [], "rapc": [], "rapc_time": [],"exception": [],"exception_type": []})
with open("/app/code/chooseFile.txt") as filess:
filePath = [line.rstrip() for line in filess]
filePathwithComments = [line.rstrip() for line in filess]
filePath = filePathwithComments[0].split()[0]
print(filePath)
with open(filePath[0]) as funcs:
with open(filePath) as funcs:
# files = ['/app/code/experiments/recursion/files/catalan-numbers-1.c' ]
files = [line.rstrip() for line in funcs]

Expand Down
14 changes: 13 additions & 1 deletion src/experiments/recursion/data_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def collect(self) -> None:
runtime = 0.0
rruntime = 0.0
bruntime = 0.0

# correct rapc
try:
with Timeout(300):
rapc = self.recursive_apc_computer.evaluate(graph)
Expand All @@ -63,6 +65,9 @@ def collect(self) -> None:
print(f"Exception: {exc}")
exception_type = "Timeout" if isinstance(exc, TimeoutError) else "Other"
start_time = time.time()


# Naive rapc
try:
with Timeout(300):
recurlist = []
Expand All @@ -81,24 +86,31 @@ def collect(self) -> None:
print(f"Exception: {exc}")
exception_type = "Timeout" if isinstance(exc, TimeoutError) else "Other"
start_time = time.time()

# original APC (cannot handle recursive)
try:
with Timeout(300):
apc = self.apc_computer.evaluate(graph)
runtime = time.time() - start_time
except Exception as exc:
exception_type = "Timeout" if isinstance(exc, TimeoutError) else "Other"

# cyclo
try:
with Timeout(200):
cyclo = self.cyclo_computer.evaluate(graph)
except Exception as exc:
exception_type = "Timeout" if isinstance(exc, TimeoutError) else "Other"


#npath
try:
with Timeout(200):
npath = self.npath_computer.evaluate(graph)
except Exception as exc:
exception_type = "Timeout" if isinstance(exc, TimeoutError) else "Other"



new_row = {"file_name": file, "graph_name": graph.name, "apc": apc,
"rapc": rapc, "brapc": brapc, "cyclo": cyclo, "npath": npath,
"apc_time": runtime, "rapc_time": rruntime, "brapc_time": bruntime,
Expand Down
15 changes: 1 addition & 14 deletions src/experiments/testFiles.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
/app/code/tests/cFiles/C-master/sorting/bead_sort.c bead_sort
/app/code/tests/cFiles/C-master/sorting/comb_sort.c sort
/app/code/tests/cFiles/C-master/sorting/gnome_sort.c sort
/app/code/tests/cFiles/C-master/sorting/partition_sort.c partitionSort
/app/code/tests/cFiles/C-master/sorting/patience_sort.c patienceSort
/app/code/tests/cFiles/C-master/searching/modified_binary_search.c modifiedBinarySearch
/app/code/tests/cFiles/C-master/greedy_approach/dijkstra.c dijkstra
/app/code/tests/cFiles/C-master/dynamic_programming/matrix_chain_order.c matrixChainOrder
/app/code/tests/cFiles/C-master/math/cantor_set.c main
/app/code/tests/cFiles/C-master/dynamic_programming/lcs.c lcsbuild
/app/code/tests/cFiles/C-master/math/lerp.c main
/app/code/experiments/function_calls/benchmark/even_odd_f2f.c is_even
/app/code/experiments/function_calls/benchmark/palindrome_recursive.c palindrome_r
/app/code/experiments/function_calls/benchmark/partition_f2f.c partition
/app/code/tests/cFiles/SV_benchmark/eca-rers2012/Problem03_label00.c
107 changes: 107 additions & 0 deletions src/graphVisulizer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# %%
from collections import defaultdict
import graphviz

calldict = defaultdict(list)

def convert_dict_to_string_keys(graph):
converted_graph = defaultdict(list)
for key, values in graph.items():
new_key = '0_' + str(key)
new_values = ['0_' + str(value) for value in values]
converted_graph[new_key] = new_values
return converted_graph

def remove_prefix(graph_with_prefix):
converted_graph = defaultdict(list)
for key, values in graph_with_prefix.items():
new_key = int(key.split('_')[1])
new_values = [int(value.split('_')[1]) for value in values]
converted_graph[new_key] = new_values
return converted_graph

def simplify_graphs(dictgraphs, calldict):
'''
Convert edge APC to branch APC
Basic Rules:
1. A -> B -> C gets simplified to A -> C
'''
simplified_graphs = []
for graph in dictgraphs:
incoming = defaultdict(list) # graph but all the arrows are flipped
for node, neighbors in graph.items():
for neighbor in neighbors:
incoming[neighbor].append(node)

for node in list(graph.keys()):
if node.split('_')[1] == '0': # keep first node
continue # remove this node, fix connection
if node not in calldict and len(incoming[node]) == 1 and len(graph[node]) == 1:
prev_node = incoming[node][0]
next_node = graph[node][0]
# remove prev node's connection to node
graph[prev_node].remove(node)
graph[prev_node].append(next_node) # connect prev to next node
# update incoming graph (same thing as above)
incoming[next_node].remove(node)
incoming[next_node].append(prev_node)
del graph[node]
del incoming[node]
simplified_graphs.append(graph)
return (simplified_graphs, calldict)

def viz_graph(graph, calldict):
dot = graphviz.Digraph(format='png')
# Add nodes to the graph
for node in graph:
dot.node(node)
# Add edges to the graph
for node, neighbors in graph.items():
for neighbor in neighbors:
dot.edge(node, neighbor)
# Add call edges to the graph
for node, neighbors in calldict.items():
for neighbor in neighbors:
dot.edge(node, f'{neighbor}_0', style='dashed')
# render file
dot.render('b')

if __name__ == '__main__':
calldict = defaultdict(list, {'0_6': [1], '0_8': [1]})
dictgraphs = [
defaultdict(list, {
'0_0': ['0_1'],
'0_1': ['0_2', '0_4'],
'0_2': ['0_3'],
'0_3': ['0_1'],
'0_4': ['0_5'],
'0_5': ['0_6', '0_17'],
'0_6': ['0_7'],
'0_7': ['0_8', '0_9'],
'0_8': ['0_7'],
'0_9': ['0_10'],
'0_10': ['0_11', '0_16'],
'0_11': ['0_12', '0_14'],
'0_12': ['0_13', '0_14'],
'0_13': ['0_14'],
'0_14': ['0_15'],
'0_15': ['0_10'],
'0_16': ['0_5']
}),
defaultdict(list, {
'1_0': ['1_1'],
'1_1': ['1_2', '1_6'],
'1_2': ['1_3', '1_4'],
'1_3': ['1_4'],
'1_4': ['1_5'],
'1_5': ['1_1']
})
]
# calldict= defaultdict(list, {})

# connect graphs:
combined_graph = defaultdict(list)
for graph in dictgraphs:
combined_graph.update(graph)
print(dictgraphs)
viz_graph(combined_graph, calldict)
8 changes: 4 additions & 4 deletions src/metric/fcn_call_path_complexity.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from sympy.utilities import lambdify
import math
import cmath
# from experiments.branch_apc.graph_simplification import simplify_graphs
from experiments.branch_apc.graph_simplification import simplify_graphs

PathComplexityRes = tuple[Union[float, str], Union[float, str]]
PRECISION = 11
Expand Down Expand Up @@ -53,9 +53,9 @@ def evaluate(self, cfg: ControlFlowGraph, all_cfgs: List[ControlFlowGraph]) -> U

# GRAPH SIMPLIFICATION ================================================
# for testing branch apc code, all other teams comment these 3 lines out
# dictgraphs, calldict = simplify_graphs(dictgraphs, calldict)
# self.logger.d_msg(f"simplified calldict: {calldict}")
# self.logger.d_msg(f"simplified dictgraphs: {dictgraphs}")
dictgraphs, calldict = simplify_graphs(dictgraphs, calldict)
self.logger.d_msg(f"simplified calldict: {calldict}")
self.logger.d_msg(f"simplified dictgraphs: {dictgraphs}")
# GRAPH SIMPLIFICATION ================================================

graphProcessTime = time.time() - start_time
Expand Down
Loading

0 comments on commit bd08145

Please sign in to comment.