-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add end-to-end test for complex calls
- Loading branch information
1 parent
d3439ca
commit 8378e94
Showing
5 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
all: clean prog | ||
|
||
prog: code.o | ||
$(CXX) -o prog code.o $(CXXFLAGS) | ||
|
||
code.o: | ||
$(CXX) -c -S -emit-llvm -o code.ll code.cpp $(CXXFLAGS) | ||
rm -rf .discopop | ||
$(CXX) -c -o code.o code.cpp $(CXXFLAGS) | ||
|
||
clean: | ||
rm -rf .discopop | ||
rm -rf src/.discopop | ||
find . -not -name code.cpp -not -name Makefile -not -path **/FileMapping.txt -delete | ||
|
||
veryclean: clean | ||
rm -f FileMapping.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include <stdlib.h> | ||
#include <stdio.h> | ||
|
||
void perform_calculation(double* base, int offset_1, int offset_2){ | ||
base[offset_1] = 42 + base[offset_2]; | ||
} | ||
|
||
void doall_possible(double* base, int index){ | ||
perform_calculation(base, index, index); | ||
} | ||
|
||
void doall_not_possible(double* base, int index, int n){ | ||
perform_calculation(base, index, (index + 1 % n)); | ||
} | ||
|
||
int main(int argc, const char* argv[]) { | ||
static int n = 5000; static double a = 2.0; //n = 100000000; | ||
double *x = (double *) malloc(n * sizeof(double)); | ||
// Initialize x | ||
|
||
// DOALL | ||
for(int i = 0; i < n; ++i){ | ||
x[i] = 1.0; | ||
} | ||
|
||
// DOALL | ||
for(int i = 0; i < n; i++){ | ||
doall_possible(x, i); | ||
} | ||
|
||
// NOT DOALL | ||
for(int i = 0; i < n; i++){ | ||
doall_not_possible(x, i, n); | ||
} | ||
|
||
|
||
free(x);; | ||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
import pathlib | ||
import subprocess | ||
import unittest | ||
|
||
import jsonpickle | ||
|
||
from discopop_library.result_classes.DetectionResult import DetectionResult | ||
from test.utils.subprocess_wrapper.command_execution_wrapper import run_cmd | ||
from test.utils.validator_classes.DoAllInfoForValidation import DoAllInfoForValidation | ||
from subprocess import DEVNULL | ||
from discopop_library.ConfigProvider.config_provider import run as run_config_provider | ||
from discopop_library.ConfigProvider.ConfigProviderArguments import ConfigProviderArguments | ||
|
||
|
||
class TestMethods(unittest.TestCase): | ||
def test(self): | ||
current_dir = pathlib.Path(__file__).parent.resolve() | ||
dp_build_dir = run_config_provider( | ||
ConfigProviderArguments( | ||
return_dp_build_dir=True, | ||
return_dp_source_dir=False, | ||
return_llvm_bin_dir=False, | ||
return_full_config=False, | ||
return_version_string=False, | ||
) | ||
) | ||
|
||
env_vars = dict(os.environ) | ||
|
||
src_dir = os.path.join(current_dir, "src") | ||
# create FileMapping | ||
cmd = os.path.join(dp_build_dir, "scripts", "dp-fmap") | ||
run_cmd(cmd, src_dir, env_vars) | ||
|
||
# build | ||
env_vars["CC"] = os.path.join(dp_build_dir, "scripts", "CC_wrapper.sh") | ||
env_vars["CXX"] = os.path.join(dp_build_dir, "scripts", "CXX_wrapper.sh") | ||
cmd = "make" | ||
run_cmd(cmd, src_dir, env_vars) | ||
|
||
# execute instrumented program | ||
run_cmd("./prog", src_dir, env_vars) | ||
|
||
# execute DiscoPoP analysis | ||
cmd = "discopop_explorer --enable-patterns doall,reduction" | ||
run_cmd(cmd, os.path.join(src_dir, ".discopop"), env_vars) | ||
# validate results | ||
try: | ||
self.validate_results(current_dir, src_dir) | ||
# clean environment | ||
run_cmd("make veryclean", src_dir, env_vars) | ||
except Exception as ex: | ||
# clean environment | ||
run_cmd("make veryclean", src_dir, env_vars) | ||
raise ex | ||
|
||
def validate_results(self, test_dir, src_dir): | ||
"""Check that exactly one do-all is suggested""" | ||
test_output_file = os.path.join(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]) | ||
if pattern_type == "do_all": | ||
expected = ["1:22", "1:27"] | ||
for pattern in 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)) | ||
else: | ||
self.assertEqual(amount_of_identified_patterns, 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters