Changes the check script to detect segfaults

This commit is contained in:
Felipe Zimmerle
2017-01-19 21:41:47 -03:00
committed by Felipe Zimmerle
parent ff65d618e4
commit a88dc8efa9
12 changed files with 76 additions and 90 deletions

View File

@@ -141,7 +141,10 @@ void ModSecurityTest<T>::cmd_options(int argc, char **argv) {
i++;
m_automake_output = true;
}
if (argc > i && strcmp(argv[i], "countall") == 0) {
i++;
m_count_all = true;
}
if (const char* env_p = std::getenv("AUTOMAKE_TESTS")) {
m_automake_output = true;
}

View File

@@ -33,7 +33,8 @@ template <class T> class ModSecurityTest :
public:
ModSecurityTest()
: m_test_number(0),
m_automake_output(false) { }
m_automake_output(false),
m_count_all(false) { }
std::string header();
void cmd_options(int, char **);
@@ -45,6 +46,7 @@ template <class T> class ModSecurityTest :
bool verbose = false;
bool color = false;
int m_test_number;
bool m_count_all;
bool m_automake_output;
};

View File

@@ -397,13 +397,13 @@ int main(int argc, char **argv) {
<< std::endl;
#else
test.cmd_options(argc, argv);
if (!test.m_automake_output) {
if (!test.m_automake_output && !test.m_count_all) {
std::cout << test.header();
}
test.load_tests();
if (!test.m_automake_output) {
if (!test.m_automake_output && !test.m_count_all) {
std::cout << std::setw(4) << std::right << "# ";
std::cout << std::setw(50) << std::left << "File Name";
std::cout << std::setw(70) << std::left << "Test Name";
@@ -423,6 +423,11 @@ int main(int argc, char **argv) {
}
keyList.sort();
if (test.m_count_all) {
std::cout << std::to_string(keyList.size()) << std::endl;
exit(0);
}
ModSecurityTestResults<RegressionTestResult> res;
for (std::string &a : keyList) {
test_number++;

View File

@@ -10,8 +10,14 @@ FILE=${@: -1}
if [[ $FILE == *"test-cases/regression/"* ]]
then
$VALGRIND $PARAM ./regression_tests ../$FILE
echo $VALGRIND $PARAM ./regression_tests ../$FILE
AMOUNT=$(./regression_tests countall ../$FILE)
for i in `seq 1 $AMOUNT`; do
$VALGRIND $PARAM ./regression_tests ../$FILE:$i
if [ $? -eq 139 ]; then
echo ":test-result: FAIL segfault: ../$FILE:$i"
fi
echo $VALGRIND $PARAM ./regression_tests ../$FILE:$i
done;
else
$VALGRIND $PARAM ./unit_tests ../$FILE
fi

View File

@@ -144,10 +144,9 @@ void perform_unit_test(ModSecurityTest<UnitTest> *test, UnitTest *t,
}
if (t->type == "op") {
Operator *op = Operator::instantiate("\"@" + t->name + \
" " + t->param + "\"");
Operator *op = Operator::instantiate(t->name, t->param);
op->init(t->filename, &error);
int ret = op->evaluate(NULL, t->input);
int ret = op->evaluate(NULL, NULL, t->input, NULL);
t->obtained = ret;
if (ret != t->ret) {
res->push_back(t);