Feature #1758
closed
Added by Jason Ish over 8 years ago.
Updated about 7 years ago.
Description
Based on discussion with Victor. Here are some of the ideas out of it.
- Tests should just return 1 for success, 0 for failure, eliminating the need to specify a success return value during registration.
-- Requires cleaning up tests that return a value other than 1 or 0 to return 1 for success, 0 for failure.
-- Convert functions that return 0 for success to 1 for success.
-- Rewrite all calls to UtRegisterTest (spatch).
- Provide macros to test failure conditions:
-- ie: FAIL_IF(expression)
- Move unit tests to a different file with a clear correlation against the file it is testing.
Couple of more things:
- tests should clean up their memory in their success case only. Currently for many tests it's done for complicated error cases as well. All that complexity can be removed.
- FAIL_IF should be a 'return 0' in the normal case, but a wrapper to BUG_ON() in the --fatal-unittests case so we can jump right into the code line that is broken
- all conditional things in tests should go. A test should be clearly defined.
Next to this, many tests should move to a higher level. E.g. all the rule matching tests would ideally be tested for each MPM algo we support. Same for the MPM tests themselves. They are pretty much copy/pasted between the different algo implementations.
Lots of things, so probably a good idea to make this a root ticket and connect more specific ones to this. This will be a multi-step undertaking :)
- Status changed from New to Assigned
I'd like to also add 'PASS' and 'PASS_IF(expr)' macro's.
Victor Julien wrote:
I'd like to also add 'PASS' and 'PASS_IF(expr)' macro's.
Its not clear to me what these would actually do?
I've tried a few things:
1) Moving tests into tests/ as source files and setting up autoconf in tests. Got complicated quick, couldn't test private functions.
2) Like above, but include the source being tested at the top of the test file. Would require redoing the test framework with a separate program (or multiple programs) to avoid duplicate definitions of functions.
3) Put tests in tests, and including them into the source file under test. This requires the least amount of changes. Example can be seen here: https://github.com/inliniac/suricata/compare/master...jasonish:ish-move-tests
Yeah the (3) is what I did in my stream branch work as well. I did include the header in the tests file as well though, otherwise my code highlighting thingy in vim would flag code as bad wrt unknown types and all. Perhaps there is a way around that.
- Status changed from Assigned to Closed
- Target version deleted (
70)
Work is ongoing but closing this ticket. Moving tests into C files in src/tests/ and then including the c files directly in the original file.
Also available in: Atom
PDF