Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ci test for false positive reduction #627

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions test/end_to_end/reduction_pattern/negative/case_1/src/Makefile
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
29 changes: 29 additions & 0 deletions test/end_to_end/reduction_pattern/negative/case_1/src/code.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <stdio.h>

int f(int i) {
if (i < 100000 / 2) {
return i + 100000 / 2;
} else {
return i;
}
}

int g(int i) { return i; }

int main() {
int N = 100000;
int Arr[N];

// DOALL
for (int i = 0; i < N; i++) {
Arr[i] = 0;
}

long w = 0;

// NO REDUCTION, NO DOALL
for (int i = 0; i < N; i++) {
w += Arr[g(i)];
Arr[f(i)] = 1;
}
}
85 changes: 85 additions & 0 deletions test/end_to_end/reduction_pattern/negative/case_1/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import copy
import os
import pathlib
import unittest

import jsonpickle

from discopop_library.result_classes.DetectionResult import DetectionResult
from test.utils.existence.existence_utils import check_patterns_for_FN, check_patterns_for_FP
from test.utils.subprocess_wrapper.command_execution_wrapper import run_cmd
from test.utils.validator_classes.DoAllInfoForValidation import DoAllInfoForValidation
from discopop_library.ConfigProvider.config_provider import run as run_config_provider
from discopop_library.ConfigProvider.ConfigProviderArguments import ConfigProviderArguments


class TestMethods(unittest.TestCase):
@classmethod
def setUpClass(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")
env_vars["DP_PROJECT_ROOT_DIR"] = src_dir
cmd = "make"
run_cmd(cmd, src_dir, env_vars)
# execute instrumented program
cmd = "./prog"
run_cmd(cmd, src_dir, env_vars)
# execute DiscoPoP analysis
cwd = os.path.join(src_dir, ".discopop")
cmd = "discopop_explorer --enable-patterns doall,reduction"
run_cmd(cmd, cwd, env_vars)

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):
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 = ["1:18"]
with self.subTest("check for FP"):
res, msg = check_patterns_for_FP(self, pattern_type, copy.deepcopy(expected_lines), self.test_output.patterns.__dict__[pattern_type])
self.assertTrue(res, msg)
with self.subTest("check for FN"):
res, msg = check_patterns_for_FN(self, pattern_type, copy.deepcopy(expected_lines), self.test_output.patterns.__dict__[pattern_type])
self.assertTrue(res, msg)
elif pattern_type == "reduction":
expected_lines = []
with self.subTest("check for FP"):
res, msg = check_patterns_for_FP(self, pattern_type, copy.deepcopy(expected_lines), self.test_output.patterns.__dict__[pattern_type])
self.assertTrue(res, msg)
with self.subTest("check for FN"):
res, msg = check_patterns_for_FN(self, pattern_type, copy.deepcopy(expected_lines), self.test_output.patterns.__dict__[pattern_type])
self.assertTrue(res, msg)
else:
self.assertEqual(amount_of_identified_patterns, 0)
Loading