Stress Test is a tool for comparing the output of two executable files given the same random input multiple times. This can be useful for testing the correctness of code or finding the case that cause code to fail. *The above Gif shows stress test tool testing code that hardly fails (faild at first time but not in the second time).
Stress test can check correctness of the code and find a case causes the code to fail if exist but how ? I would tell to you.
First, I would suppose you have the following:
- Code you want to test. build it and let us call its executable file
test
. - Refrence code or answer. It is a code do the same task as
test
but you are sure it makes it correctly. build it and let us call its executable fileanswer
. - Generator code, every time this code is run it will output a valid random input for
test
andanswer
. build it and let us call its executable filegenerator
.
stress test program is doing the process shown in the figure above. Additionally, you can specify number of test cases
(maximum number the cycle in the figure will repeat in case no conflict happened in outputs)
- The
generator
output is the input oftest
andanswer
and it must be compatible with the waytest
andanswer
reading input. - The tool works for windows and linux.
- Stress test program is a executable
C++
code.
- It doesn't matter the programming languages only the executable files are needed.
- You can use the tool with the last used executablel files without entering their paths again.
- You are the one who implement
generator
, you can implement anything. - Tool is handling most common errors.
- Check if the given path is exist.
- Check if the file is executalbe.
- Check valid integer or {0, 1} while reading input.
- Here's a library will help you implementing generator if you a
C++
coder.
- Need executable files and some programming languages doesn't generate executable files. (maybe there's tool generates executable files somewhere on Google such as pyinstaller for python)
- Output comparsion is string comparsion in current version. (whitespaces may lead to conflict)
- Probability of catching case causes code to fail if exist
-
$$= {{F \over A} {\sum_{i=0}^{N-1} \left(1 - {F \over A} \right)^i}}$$ - Suppose:
- Code
generator
generates fully randomized cases. -
N
is number of test cases run. -
A
is number of all possible valid input. -
F
is number of all possible failed cases. - So
F - A
is number of all possible passed cases.
- Code
- Suppose:
-
- Impelement the
generator
file then build it and remember its executable file path.- If you use
C++
this library will help you a lot to generate random stuff.
- If you use
- Build
test
andanswer
and remember their executable files' paths. - Run the Stress Test program, specifying the paths to
test
,answer
, andgenerator
andnumber of test cases
.- You can get stress test program from releases or by run
src\main.cpp
from the source code.
- You can get stress test program from releases or by run
- The Stress Test program will then handle the rest, running all executable files and comparing outputs.
- See Example for more clarification.
In case you are interesting, here's life cycle of the tool from start to terminate.
- If it's not your first time to use the tool.
- It will show you the last used paths and ask you if you want to use it now.
- If you want to use it, the tool will proceed to test.
- If not, the tool will ask you to enter the paths.
- It will show you the last used paths and ask you if you want to use it now.
- Entering data.
- For path, you can enter path or either make the tool use the last used path.
- Then entering number of test cases.
- The tool will create directory
stress_test_env
in the same tool directory and it will contains:input.txt
.- saves output of
generator
code here. test
andanswer
will read from it.
- saves output of
answer.txt
.- saves output of
answer
code here.
- saves output of
output.txt
.- saves output of
test
code here.
- saves output of
data.txt
.- saves used data here (paths and number of test cases).
- Start testing.
- run
generator
.- no input.
- output:
stress_test_env\intput.txt
.
- run
test
.- input:
stress_test_env\intput.txt
. - output:
stress_test_env\output.txt
.
- input:
- run
answer
.- input:
stress_test_env\intput.txt
. - output:
stress_test_env\answer.txt
.
- input:
- compare
stress_test_env\output.txt
andstress_test_env\answer.txt
. (string comparsion in this version)- If no conflict.
- If number of test cases is done, terminate the program.
- otherwise go to
4. Start testing.
- otherwise terminate.
- input causes
test
to fail could be found instress_test_env\intput.txt
. - output of
test
is instress_test_env\output.txt
. - refrence answer is in
stress_test_env\answer.txt
.
- input causes
- If no conflict.
- run
Add fetures such as:
- Add more comparators such as:
- single or more int64, ignore whitespaces.
- single or more doubles with EPS.
- compare lines, ignore whitespaces.
- Calculate average code time.
- Test interactive problems.