diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 11 | ||||
| -rw-r--r-- | tests/dice/CMakeLists.txt | 19 | ||||
| -rw-r--r-- | tests/dice/Dice.pro | 25 | ||||
| -rw-r--r-- | tests/dice/testnode.cpp (renamed from tests/testnode.cpp) | 0 | ||||
| -rw-r--r-- | tests/dice/testnode.h (renamed from tests/testnode.h) | 0 | ||||
| -rw-r--r-- | tests/dice/tst_dice.cpp (renamed from tests/tst_dice.cpp) | 41 | ||||
| -rw-r--r-- | tests/fuzzer/CMakeLists.txt | 26 | ||||
| -rwxr-xr-x | tests/fuzzer/run_test.sh | 27 | ||||
| -rw-r--r-- | tests/fuzzer/testcase.cpp | 37 | ||||
| -rw-r--r-- | tests/fuzzer/testcase_dir/gooddata.txt | 45 |
10 files changed, 178 insertions, 53 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 4065cc5..6fb276b 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,9 +1,2 @@ -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra") -set(CMAKE_AUTOMOC ON) -find_package(Qt5Test REQUIRED) - -set(test_source testnode.cpp tst_dice.cpp) - -add_executable(test_dice ${test_source} ) -target_link_libraries(test_dice diceparser Qt5::Test) -add_test(tst_diceparser test_dice) +#add_subdirectory(fuzzer) +add_subdirectory(dice) diff --git a/tests/dice/CMakeLists.txt b/tests/dice/CMakeLists.txt index a0f27fd..d254624 100644 --- a/tests/dice/CMakeLists.txt +++ b/tests/dice/CMakeLists.txt @@ -1,17 +1,12 @@ -cmake_minimum_required(VERSION 3.5) -project(tst_diceParser) - -enable_testing(true) - -# Tell CMake to run moc when necessary: +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra") set(CMAKE_AUTOMOC ON) +find_package(Qt5Test REQUIRED) -# As moc files are generated in the binary dir, tell CMake -# to always look for includes there: -set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(test_source testnode.cpp tst_dice.cpp) -find_package(Qt5Test REQUIRED) +add_executable(test_dice ${test_source} ${dice_sources}) -add_test(tst_diceParser tst_dice.cpp) +target_include_directories(test_dice PRIVATE ../../include) -target_link_libraries(foo Qt5::Test) +target_link_libraries(test_dice Qt5::Test) +add_test(tst_diceparser test_dice) diff --git a/tests/dice/Dice.pro b/tests/dice/Dice.pro deleted file mode 100644 index 9d24f91..0000000 --- a/tests/dice/Dice.pro +++ /dev/null @@ -1,25 +0,0 @@ -include(../tests.pri) - -SOURCES += \ - tst_dice.cpp - -TEMPLATE = app -TARGET= tst_diceParser -MOC_DIR=trash -OBJECTS_DIR=trash - -CONFIG+=testcase - -QT += testlib quick qml widgets - -INCLUDEPATH += $$ROLISTEAMSRC/diceparser/ -INCLUDEPATH += $$ROLISTEAMSRC/diceparser/node -INCLUDEPATH += $$ROLISTEAMSRC/diceparser/result - - -include($$ROLISTEAMSRC/diceparser/diceparser.pri) - -HEADERS -= ../../../rolisteam/client/diceparser/qmltypesregister.h -SOURCES -= ../../../rolisteam/client/diceparser/qmltypesregister.cpp - - diff --git a/tests/testnode.cpp b/tests/dice/testnode.cpp index de9fc05..de9fc05 100644 --- a/tests/testnode.cpp +++ b/tests/dice/testnode.cpp diff --git a/tests/testnode.h b/tests/dice/testnode.h index 5c918ee..5c918ee 100644 --- a/tests/testnode.h +++ b/tests/dice/testnode.h diff --git a/tests/tst_dice.cpp b/tests/dice/tst_dice.cpp index 1fe2641..a35f918 100644 --- a/tests/tst_dice.cpp +++ b/tests/dice/tst_dice.cpp @@ -43,6 +43,7 @@ #include "node/splitnode.h" #include "node/stringnode.h" #include "node/uniquenode.h" +#include "operationcondition.h" #include "result/stringresult.h" #include "testnode.h" @@ -131,6 +132,8 @@ private slots: void occurenceTest(); void occurenceTest_data(); + void operatoionConditionValidatorTest(); + private: std::unique_ptr<Die> m_die; std::unique_ptr<DiceParser> m_diceParser; @@ -463,13 +466,13 @@ void TestDice::dangerousCommandsTest_data() // QTest::addRow("cmd5") << "10d10g10"; } -void makeResult(DiceResult& result, const QVector<int>& values) +void makeResult(DiceResult& result, const QVector<int>& values, int base= 1, int max= 10) { for(int val : values) { auto die= new Die(); - die->setBase(1); - die->setMaxValue(10); + die->setBase(base); + die->setMaxValue(max); die->insertRollValue(val); result.insertResult(die); } @@ -524,7 +527,7 @@ void TestDice::keepTest() if(error) return; - auto resultScore= keepN.getResult()->getResult(Result::SCALAR).toInt(); + auto resultScore= keepN.getResult()->getResult(Dice::RESULT_TYPE::SCALAR).toInt(); QCOMPARE(score, resultScore); } @@ -609,7 +612,7 @@ void TestDice::countTest() node.run(nullptr); - QCOMPARE(score, countN.getResult()->getResult(Result::SCALAR).toInt()); + QCOMPARE(score, countN.getResult()->getResult(Dice::RESULT_TYPE::SCALAR).toInt()); countN.setValidator(nullptr); } @@ -722,7 +725,7 @@ void TestDice::rerollUntilTest() RerollDiceNode reroll(false, false); DiceResult result; - makeResult(result, values); + makeResult(result, values, 0); node.setResult(&result); auto validator= makeValidator(condition, BooleanCondition::Equal); @@ -742,7 +745,6 @@ void TestDice::rerollUntilTest() resultDiff= true; ++i; } - QCOMPARE(different, resultDiff); } void TestDice::rerollUntilTest_data() @@ -1062,6 +1064,31 @@ void TestDice::ifCommandTest_data() << QStringList({"Complete Success:", "Success with Complications:", "Failure:"}); } +void TestDice::operatoionConditionValidatorTest() +{ + OperationCondition validator; + NumberNode number; + number.setNumber(2); + validator.setValueNode(&number); + + BooleanCondition subValidator; + subValidator.setOperator(BooleanCondition::Equal); + NumberNode subnumber; + subnumber.setNumber(0); + subValidator.setValueNode(&subnumber); + + validator.setBoolean(&subValidator); + + std::set<qint64> data= {2, 4, 6, 8, 10}; + auto value= validator.getPossibleValues(std::make_pair<qint64, qint64>(1, 10)); + + subValidator.setValueNode(nullptr); + validator.setValueNode(nullptr); + validator.setBoolean(nullptr); + + QCOMPARE(value, data); +} + void TestDice::cleanupTestCase() {} QTEST_MAIN(TestDice) diff --git a/tests/fuzzer/CMakeLists.txt b/tests/fuzzer/CMakeLists.txt new file mode 100644 index 0000000..c6d94ca --- /dev/null +++ b/tests/fuzzer/CMakeLists.txt @@ -0,0 +1,26 @@ +cmake_minimum_required(VERSION 3.10) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fno-permissive -pedantic -Wall -Wextra") +set(CMAKE_AUTOMOC ON) + +find_package(Qt5Core REQUIRED) +find_package(Qt5Gui REQUIRED) +find_package(Qt5Svg REQUIRED) +find_package(Qt5Concurrent REQUIRED) + +set(CMAKE_INCLUDE_CURRENT_DIR ON) +set(CMAKE_AUTOMOC ON) + +#SET (CMAKE_EXE_LINKER_FLAGS "-static") + +add_definitions(-DPAINTER_OP) +set(MODE "cli") + + + +set(fdsource testcase.cpp) + +add_executable(fuzzTestCase ${fdsource} ) + + +target_link_libraries(fuzzTestCase libdiceparser.a Qt5::Core Qt5::Gui Qt5::Svg Qt5::Concurrent) +#target_link_libraries(fuzzTestCase ) diff --git a/tests/fuzzer/run_test.sh b/tests/fuzzer/run_test.sh new file mode 100755 index 0000000..9ecdeef --- /dev/null +++ b/tests/fuzzer/run_test.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +rm -rf build +mkdir build +cd build +CC=afl-gcc CXX=afl-g++ cmake ../ -DSTATIC_BUILD=ON && make +#export LD_LIBRARY_PATH="/usr/local/lib:$LD_LIBRARY_PATH" + + +#./fuzzTestCase ../testcase_dir/gooddata.txt +# afl-fuzz -m 2G -i ../testcase_dir -o ../findings_dir ./fuzzTestCase @@ +afl-fuzz -m 2G -i ../testcase_dir -o ../sync_dir -M fuzzer01 ./fuzzTestCase @@ & +screen -S fuzz1 -d -m touch afl-fuzz -m 2G -i ../testcase_dir -o ../sync_dir -S fuzzer02 ./fuzzTestCase @@ & +screen -S fuzz2 -d -m touch afl-fuzz -m 2G -i ../testcase_dir -o ../sync_dir -S fuzzer03 ./fuzzTestCase @@ & +screen -S fuzz3 -d -m touch afl-fuzz -m 2G -i ../testcase_dir -o ../sync_dir -S fuzzer04 ./fuzzTestCase @@ & +screen -S fuzz4 -d -m touch afl-fuzz -m 2G -i ../testcase_dir -o ../sync_dir -S fuzzer05 ./fuzzTestCase @@ & +screen -S fuzz5 -d -m touch afl-fuzz -m 2G -i ../testcase_dir -o ../sync_dir -S fuzzer06 ./fuzzTestCase @@ + + + +# as root + +# echo core >/proc/sys/kernel/core_pattern + +# echo performance | tee cpu*/cpufreq/scaling_governor + +# echo ondemand | tee cpu*/cpufreq/scaling_governor diff --git a/tests/fuzzer/testcase.cpp b/tests/fuzzer/testcase.cpp new file mode 100644 index 0000000..87d1867 --- /dev/null +++ b/tests/fuzzer/testcase.cpp @@ -0,0 +1,37 @@ +#include <QCoreApplication> +#include <QDebug> +#include <QFile> +#include <diceparser.h> + +static DiceParser* parser= new DiceParser(); + +void runCommand(const QString& cmd) +{ + qDebug() << "cmd" << cmd; + if(parser->parseLine(cmd)) + { + parser->start(); + } +} + +int main(int argc, char** argv) +{ + // qDebug() << "first"; + QCoreApplication app(argc, argv); + + // qDebug() << "start"; + QFile file(app.arguments().at(1)); + // qDebug() << "file" << app.arguments().at(1); + if(!file.open(QIODevice::ReadOnly)) + return 1; + + auto line= file.readLine(); + while(!line.isEmpty()) + { + // qDebug() << line; + runCommand(QString::fromUtf8(line)); + line= file.readLine(); + } + + return 0; +} diff --git a/tests/fuzzer/testcase_dir/gooddata.txt b/tests/fuzzer/testcase_dir/gooddata.txt new file mode 100644 index 0000000..d62c87e --- /dev/null +++ b/tests/fuzzer/testcase_dir/gooddata.txt @@ -0,0 +1,45 @@ +1L[cheminée,chocolat,épée,arc,chute de pierre[40]] +10d10c[>=6]-@c[=1] +1+1D10 +1+(4*3)D10s +2+4/4 +2D10*2D20*8 +1D100a[>=95]a[>=96]a[>=97]a[>=98]a[>=99]e[>=100] +15D10e10c[8-10] +(4+4)^4 +(1d20+20)*7/10 +20*7/10 +2d6c[%2=0] +D25;D10 +8+8+8 +1D20-88 +100*1D20*2D6 +2D6 # comment +100/28*3 +help +la +10D10c[<2|>7] +10D6c[=2|=4|=6] +10D10e[=1|=10]k4 +1L[t,b,s,r,j,v,i,p[8-10]] +1d6e6;1d4e4mk1 +400D20/400000 +1d100e[>=95]i[<5]{-1d100e95} +1d100i[<70]{1d10i[=10]{1d100i[<70]{1d10e10}}} +5-5*5+5 +((3+4)*2)d6 +4d6i[=6]{+1d6} +10d[-8--1] +4d6e6i[=4]{-4} +4d6e6f[!=4] +5d10g10 +4d6p[4:blue] +10d[0-9] +1d8e8;1d6e6mk1+2 +3d100g5 +2d10k1+2d10k1+2d10k1 +(1)-1d6e6 +8d10o +[100,200,300]k2 +100;200;300;[$1,$2,$3]k2 +0-2;$1+$1;$2i:[<1]{1}{0} |