Task #2975
openconvert unittests to new FAIL/PASS API
Description
If you are interested in working on this task, please check the available subtasks. Community contributors are welcome to work on them.¶
Convert existing tests to use the FAIL/PASS API. The idea is that every step in a test is checked and that the test should not leak memory on its success path.
There are many tests, some of which have lots of duplication. Consider per test whether the test can be improved (cleaned up) further.
This is not something meant to be done in one step. A commit per source file is ok. PRs can include multiple commits.
More explanations and context:
Initially, a lot of tests were written just like any other method: there were multiple conditionals for failure (return 0) and one pass condition (return 1), e.g.:
/**
* \test MarkTestParse01 is a test for a valid mark value
*
* \retval 1 on succces
* \retval 0 on failure
*/
static int MarkTestParse01 (void)
{
DetectMarkData *data;
data = DetectMarkParse("1/1");
if (data == NULL) {
return 0;
}
DetectMarkDataFree(NULL, data);
return 1;
}
While there was nothing wrong with this approach, we found it would be much cleaner if we used conditional macros that clearly say whether the test "fails" or "passes" on a certain condition. So, we introduced a lot of well-defined macros (see https://github.com/OISF/suricata/blob/master/src/util-unittest.h) to make the tests more legible and clear.
There are macros for almost all failing conditionals e.g., fail if something is null (FAIL_IF_NULL), fail if something
exists (>0) (FAIL_IF), etc. There are also macros PASS and PASS_IF which mean all the conditionals were met properly and the test has passed.
Your job as a part of this task is to remove the old style of tests, i.e. returning values on failure/passing
conditionals, and use this FAIL/PASS API instead. One good example could be
https://github.com/OISF/suricata/commit/3cf8b4629f2cf523c3f82604d93b8fd4a0888109:
There, all the conditionals were converted to the FAIL/PASS API in a manner that there is NO memory leak on the success path (PASS). It is OK to have memleaks on failure paths.
VJ Updated by Victor Julien over 6 years ago
- Related to Feature #1025: seperate #ifdef UNITTEST code into their own files added
VJ Updated by Victor Julien over 5 years ago
- Assignee changed from Shivani Bhardwaj to Community Ticket
JF Updated by Juliana Fajardini Reichow over 4 years ago
- Description updated (diff)
JF Updated by Juliana Fajardini Reichow over 4 years ago
- Description updated (diff)
updated description with a code snippet, as the example code has been updated to the new API and therefore the suggested example didn't work
LH Updated by lipeng hao about 3 years ago
I can pick it up,please assign this tick to me,thks
AH Updated by Andreas Herz almost 3 years ago
- Assignee changed from Community Ticket to lipeng hao
AH Updated by Andreas Herz almost 3 years ago
- Assignee changed from lipeng hao to Community Ticket
AH Updated by Andreas Herz almost 3 years ago
lipeng hao wrote in #note-5:
I can pick it up,please assign this tick to me,thks
this is the meta ticket, but feel free to work on the remaining subtickets, one is already assigned to you.
JF Updated by Juliana Fajardini Reichow almost 3 years ago
- Subtask #6107 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6314 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6315 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6316 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6317 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6318 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6319 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6320 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6321 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6322 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6323 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6324 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6325 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6326 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6327 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6328 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6329 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6330 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6331 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6332 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6333 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6334 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6335 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6336 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6337 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6338 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6339 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6340 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6341 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6343 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6344 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6345 added
JF Updated by Juliana Fajardini Reichow over 2 years ago
- Subtask #6346 added
JF Updated by Juliana Fajardini Reichow almost 2 years ago
- Subtask #6935 added
EA Updated by Ezra Adeyinka 6 months ago
- Assignee changed from Community Ticket to Ezra Adeyinka
- Effort set to low
JF Updated by Juliana Fajardini Reichow 6 months ago
- Assignee changed from Ezra Adeyinka to Community Ticket
JF Updated by Juliana Fajardini Reichow 5 months ago
- Status changed from Assigned to In Progress
JF Updated by Juliana Fajardini Reichow 5 months ago
- Description updated (diff)
- Status changed from In Progress to Assigned
- Assignee changed from Community Ticket to OISF Dev
JF Updated by Juliana Fajardini Reichow 5 months ago
- Description updated (diff)
JF Updated by Juliana Fajardini Reichow 5 months ago ยท Edited
- Assignee changed from OISF Dev to Juliana Fajardini Reichow