Skip to content

Commit

Permalink
end-to-end tests: updated test structure to reuse loaded result
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasrothenberger committed Jul 2, 2024
1 parent 84fe07b commit 12dd298
Show file tree
Hide file tree
Showing 40 changed files with 335 additions and 336 deletions.
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/backwards_array_access/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 1)
else:
Expand Down
18 changes: 9 additions & 9 deletions test/end_to_end/do_all/calls/LULESH_proxy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,24 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that main loop do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

found_main_loop = False

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
do_all_patterns = test_output.patterns.__dict__[pattern_type]
do_all_patterns = self.test_output.patterns.__dict__[pattern_type]

for pattern in do_all_patterns:
if cast(DoAllInfo, pattern).start_line == "1:271":
Expand Down
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/above_nesting_level_3/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,21 +49,21 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)


def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 5)
else:
Expand Down
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/allowing/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 1)
else:
Expand Down
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/allowing_2/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 2)
else:
Expand Down
20 changes: 10 additions & 10 deletions test/end_to_end/do_all/calls/complex/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
expected = ["1:22", "1:27"]
for pattern in test_output.patterns.__dict__[pattern_type]:
for pattern in self.test_output.patterns.__dict__[pattern_type]:
self.assertTrue(pattern.start_line in expected, "False positive: Pattern at " + pattern.start_line + " not in expected result: " + str(expected))
self.assertTrue(len(test_output.patterns.__dict__[pattern_type]) == 2, "False negative: Missed pattern. \nFound: " + " ".join([p.start_line for p in test_output.patterns.__dict__[pattern_type]])+"\nExpected: " + " ".join(expected))
self.assertTrue(len(self.test_output.patterns.__dict__[pattern_type]) == 2, "False negative: Missed pattern. \nFound: " + " ".join([p.start_line for p in self.test_output.patterns.__dict__[pattern_type]])+"\nExpected: " + " ".join(expected))
else:
self.assertEqual(amount_of_identified_patterns, 0)
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/preventing/simple/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 0)
else:
Expand Down
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/second_order/allowing/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def validate_results(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 1)
else:
Expand Down
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/second_order/allowing_2/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 1)
else:
Expand Down
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/second_order/preventing/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 0)
else:
Expand Down
16 changes: 8 additions & 8 deletions test/end_to_end/do_all/calls/second_order/preventing_2/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,20 +52,20 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""Check that exactly one do-all is suggested"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
self.assertEqual(amount_of_identified_patterns, 0)
else:
Expand Down
24 changes: 12 additions & 12 deletions test/end_to_end/do_all/daxpy/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,35 +51,35 @@ def setUpClass(self):
self.src_dir = src_dir
self.env_vars = env_vars

test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
self.test_output: DetectionResult = jsonpickle.decode(tmp_str)

@classmethod
def tearDownClass(self):
run_cmd("make veryclean", self.src_dir, self.env_vars)

def test(self):
"""compare results to gold standard"""
test_output_file = os.path.join(self.src_dir, ".discopop", "explorer", "detection_result_dump.json")
# load detection results
with open(test_output_file, "r") as f:
tmp_str = f.read()
test_output: DetectionResult = jsonpickle.decode(tmp_str)

for pattern_type in test_output.patterns.__dict__:
amount_of_identified_patterns = len(test_output.patterns.__dict__[pattern_type])
for pattern_type in self.test_output.patterns.__dict__:
amount_of_identified_patterns = len(self.test_output.patterns.__dict__[pattern_type])
if pattern_type == "do_all":
expected_lines = ["10","21"]
for pattern in test_output.patterns.__dict__[pattern_type]:
for pattern in self.test_output.patterns.__dict__[pattern_type]:
if pattern.start_line.split(":")[1] in expected_lines:
expected_lines.remove(pattern.start_line.split(":")[1])
self.assertTrue(len(expected_lines) == 0,
"Missing expected do-all patterns at line " + str(expected_lines) + ". Found: " + str(
[p.start_line for p in test_output.patterns.__dict__[pattern_type]]))
[p.start_line for p in self.test_output.patterns.__dict__[pattern_type]]))
elif pattern_type == "reduction":
expected_lines = ["29"]
for pattern in test_output.patterns.__dict__[pattern_type]:
for pattern in self.test_output.patterns.__dict__[pattern_type]:
if pattern.start_line.split(":")[1] in expected_lines:
expected_lines.remove(pattern.start_line.split(":")[1])
self.assertTrue(len(expected_lines) == 0,
"Missing expected reduction patterns at line " + str(expected_lines) + ". Found: " + str(
[p.start_line for p in test_output.patterns.__dict__[pattern_type]]))
[p.start_line for p in self.test_output.patterns.__dict__[pattern_type]]))
else:
self.assertEqual(amount_of_identified_patterns, 0)
Loading

0 comments on commit 12dd298

Please sign in to comment.