Project

General

Profile

Actions

Task #2975

open
VJ JF

convert unittests to new FAIL/PASS API

Task #2975: convert unittests to new FAIL/PASS API

Added by Victor Julien almost 7 years ago. Updated 4 months ago.

Status:
Assigned
Priority:
Normal
Target version:
Effort:
low
Difficulty:
Label:

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.


Subtasks 74 (8 open66 closed)

Task #4019: Convert unittests to new FAIL/PASS API - detect-detection-filter.cClosedHaleema KhanActions
Task #4020: Convert unittests to new FAIL/PASS API - detect-distance.cClosedHaleema KhanActions
Task #4021: Convert unittests to new FAIL/PASS API - detect-dsize.cClosedJuliana Fajardini ReichowActions
Task #4022: Convert unittests to new FAIL/PASS API - detect-engine-address-ipv4.cRejectedActions
Task #4023: Convert unittests to new FAIL/PASS API: detect-engine-address-ipv6.cClosedEzra AdeyinkaActions
Task #4024: Convert unittests to new FAIL/PASS API: detect-engine.cClosedSam MohammadActions
Task #4025: Convert unittests to new FAIL/PASS API: detect-engine-event.cClosedSam MohammadActions
Task #4026: Convert unittests to new FAIL/PASS API: detect-engine-payload.cClosedSam MohammadActions
Task #4027: Convert unittests to new FAIL/PASS API: detect-engine-proto.cClosedSam MohammadActions
Task #4028: Convert unittests to new FAIL/PASS API: detect-engine-siggroup.cClosedSam MohammadActions
Task #4029: Convert unittests to new FAIL/PASS API: detect-engine-sigorder.cClosedHaleema KhanActions
Task #4030: Convert unittests to new FAIL/PASS API: detect-engine-tag.cClosedBazzan DonActions
Task #4031: Convert unittests to new FAIL/PASS API: detect-fast-pattern.cClosedVictor JulienActions
Task #4032: Convert unittests to new FAIL/PASS API: detect-file-data.cClosedVictor JulienActions
Task #4033: Convert unittests to new FAIL/PASS API: detect-fileext.cClosedHaleema KhanActions
Task #4034: Convert unittests to new FAIL/PASS API: detect-filemagic.cClosedAlice da Silva AkakiActions
Task #4035: Convert unittests to new FAIL/PASS API: detect-filemd5.cClosedAlice da Silva AkakiActions
Task #4036: Convert unittests to new FAIL/PASS API: detect-filename.cClosedAlice da Silva AkakiActions
Task #4037: Convert unittests to new FAIL/PASS API: detect-filesha1.cClosedSumera PriyadarsiniActions
Task #4038: Convert unittests to new FAIL/PASS API: detect-filesha256.cClosedAlice da Silva AkakiActions
Task #4039: Convert unittests to new FAIL/PASS API: detect-filesize.cClosedHaleema KhanActions
Task #4040: Convert unittests to new FAIL/PASS API: detect-fragoffset.cClosedModupe FalodunActions
Task #4041: Convert unittests to new FAIL/PASS API: detect-gid.cClosedModupe FalodunActions
Task #4042: Convert unittests to new FAIL/PASS API: detect-icmp-id.cClosedAlice da Silva AkakiActions
Task #4043: Convert unittests to new FAIL/PASS API: detect-icmp-seq.cClosedAlice da Silva AkakiActions
Task #4044: Convert unittests to new FAIL/PASS API: detect-icmp-seq.cRejectedCommunity TicketActions
Task #4045: Convert unittests to new FAIL/PASS API: detect-icode.cClosedModupe FalodunActions
Task #4046: Convert unittests to new FAIL/PASS API: detect-id.cClosedModupe FalodunActions
Task #4047: Convert unittests to new FAIL/PASS API: detect-ipopts.cClosedModupe FalodunActions
Task #4048: Convert unittests to new FAIL/PASS API: detect-iprep.cClosedJuliana Fajardini ReichowActions
Task #4049: Convert unittests to new FAIL/PASS API: detect-itype.cClosedHaleema KhanActions
Task #4050: Convert unittests to new FAIL/PASS API: detect-l3proto.cClosedHaleema KhanActions
Task #4051: Convert unittests to new FAIL/PASS API: detect-lua.cClosedGabriel Lima LuzActions
Task #4052: Convert unittests to new FAIL/PASS API: detect-mark.cClosedJanani RamjeeActions
Task #4053: Convert unittests to new FAIL/PASS API: detect-msg.cClosedJuliana Fajardini ReichowActions
Task #4054: Convert unittests to new FAIL/PASS API: detect-replace.cClosedGabriel Lima LuzActions
Task #4055: Convert unittests to new FAIL/PASS API: detect-rfb-secresult.cClosedModupe FalodunActions
Task #4056: Convert unittests to new FAIL/PASS API: detect-rpc.cClosedJuliana Fajardini ReichowActions
Task #4057: Convert unittests to new FAIL/PASS API: detect-sameip.cClosedModupe FalodunActions
Task #4058: Convert unittests to new FAIL/PASS API: detect-sid.cClosedJuliana Fajardini ReichowActions
Task #6107: unittests: convert tests to new FAIL/PASS API - util-memcmp.cClosedComfort AmaechiActions
Task #6314: Convert unittests to new FAIL/PASS API - tests/detect-http-client-body.cNewCommunity TicketActions
Task #6315: Convert unittests to new FAIL/PASS API - ippair-storage.cClosedOlusegun FajobiActions
Task #6316: Convert unittests to new FAIL/PASS API - app-layer-detect-proto.cNewCommunity TicketActions
Task #6317: Convert unittests to new FAIL/PASS API - detect-filestore.cClosedJhonny SousaActions
Task #6318: unittests: convert tests to new FAIL/PASS API - detect-engine-address-ipv4.cClosedAlice da Silva AkakiActions
Task #6319: Convert unittests to new FAIL/PASS API - util-bloomfilter.cNewCommunity TicketActions
Task #6320: Convert unittests to new FAIL/PASS API - detect-base64-data.cClosedJhonny SousaActions
Task #6321: Convert unittests to new FAIL/PASS API - decode-raw.cClosedVictor JulienActions
Task #6322: Convert unittests to new FAIL/PASS API - util-pool.cClosedJhonny SousaActions
Task #6323: Convert unittests to new FAIL/PASS API - ippair-bit.cClosedOlusegun FajobiActions
Task #6324: Convert unittests to new FAIL/PASS API - stream-tcp-reassemble.cClosedJames KadduActions
Task #6325: Convert unittests to new FAIL/PASS API - detect-urilen.cClosedOlusegun FajobiActions
Task #6326: Convert unittests to new FAIL/PASS API - detect-ssh-software-version.cRejectedCommunity TicketActions
Task #6327: Convert unittests to new FAIL/PASS API - threads.cClosedOlusegun FajobiActions
Task #6328: Convert unittests to new FAIL/PASS API - detect-bytejump.cClosedDaniel OlatunjiActions
Task #6329: Convert unittests to new FAIL/PASS API - flow-bit.cClosedHadiqa Alamdar BukhariActions
Task #6330: Convert unittests to new FAIL/PASS API - tests/stream-tcp-list.cNewCommunity TicketActions
Task #6331: Convert unittests to new FAIL/PASS API - util-bloomfilter-counting.cNewCommunity TicketActions
Task #6332: Convert unittests to new FAIL/PASS API - detect-bytetest.cClosedDaniel OlatunjiActions
Task #6333: Convert unittests to new FAIL/PASS API - util-rule-vars.cClosedJhonny SousaActions
Task #6334: Convert unittests to new FAIL/PASS API - util-spm.cNewCommunity TicketActions
Task #6335: Convert unittests to new FAIL/PASS API - decode-tcp.cClosedVictor JulienActions
Task #6336: Convert unittests to new FAIL/PASS API - tests/detect-http-stat-code.cClosedVictor JulienActions
Task #6337: Convert unittests to new FAIL/PASS API - detect-ssh-proto-version.cClosedBruno FrancaActions
Task #6338: Convert unittests to new FAIL/PASS API - tests/detect-http-stat-msg.cClosedVictor JulienActions
Task #6339: Convert unittests to new FAIL/PASS API - detect-tcp-window.cClosedHadiqa Alamdar BukhariActions
Task #6340: Convert unittests to new FAIL/PASS API - tests/detect-http-method.cClosedVictor JulienActions
Task #6341: Convert unittests to new FAIL/PASS API - decode-ethernet.cNewCommunity TicketActions
Task #6343: Convert unittests to new FAIL/PASS API - tests/stream-tcp.cNewCommunity TicketActions
Task #6344: Convert unittests to new FAIL/PASS API - detect-pcre.cClosedCheryl OwalaActions
Task #6345: Convert unittests to new FAIL/PASS API - util-misc.cClosedHadiqa Alamdar BukhariActions
Task #6346: Convert unittests to new FAIL/PASS API - detect-engine-dcepayload.cClosedVictor JulienActions
Task #6935: unittests: convert tests to new FAIL/PASS API - src/app-layer-htp.cClosedNancy EnosActions

Related issues 1 (1 open0 closed)

Related to Suricata - Feature #1025: seperate #ifdef UNITTEST code into their own filesNewOISF DevActions

VJ Updated by Victor Julien over 6 years ago Actions #1

  • Related to Feature #1025: seperate #ifdef UNITTEST code into their own files added

VJ Updated by Victor Julien over 5 years ago Actions #2

  • Assignee changed from Shivani Bhardwaj to Community Ticket

JF Updated by Juliana Fajardini Reichow over 4 years ago Actions #3

  • Description updated (diff)

JF Updated by Juliana Fajardini Reichow over 4 years ago Actions #4

  • 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 Actions #5

I can pick it up,please assign this tick to me,thks

AH Updated by Andreas Herz almost 3 years ago Actions #6

  • Assignee changed from Community Ticket to lipeng hao

AH Updated by Andreas Herz almost 3 years ago Actions #7

  • Assignee changed from lipeng hao to Community Ticket

AH Updated by Andreas Herz almost 3 years ago Actions #8

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 Actions #9

  • Subtask #6107 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #10

  • Subtask #6314 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #11

  • Subtask #6315 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #12

  • Subtask #6316 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #13

  • Subtask #6317 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #14

  • Subtask #6318 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #15

  • Subtask #6319 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #16

  • Subtask #6320 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #17

  • Subtask #6321 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #18

  • Subtask #6322 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #19

  • Subtask #6323 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #20

  • Subtask #6324 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #21

  • Subtask #6325 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #22

  • Subtask #6326 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #23

  • Subtask #6327 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #24

  • Subtask #6328 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #25

  • Subtask #6329 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #26

  • Subtask #6330 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #27

  • Subtask #6331 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #28

  • Subtask #6332 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #29

  • Subtask #6333 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #30

  • Subtask #6334 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #31

  • Subtask #6335 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #32

  • Subtask #6336 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #33

  • Subtask #6337 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #34

  • Subtask #6338 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #35

  • Subtask #6339 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #36

  • Subtask #6340 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #37

  • Subtask #6341 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #38

  • Subtask #6343 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #39

  • Subtask #6344 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #40

  • Subtask #6345 added

JF Updated by Juliana Fajardini Reichow over 2 years ago Actions #41

  • Subtask #6346 added

JF Updated by Juliana Fajardini Reichow almost 2 years ago Actions #42

  • Subtask #6935 added

EA Updated by Ezra Adeyinka 6 months ago Actions #43

  • Assignee changed from Community Ticket to Ezra Adeyinka
  • Effort set to low

JF Updated by Juliana Fajardini Reichow 6 months ago Actions #44

  • Assignee changed from Ezra Adeyinka to Community Ticket

JF Updated by Juliana Fajardini Reichow 5 months ago Actions #45

  • Status changed from Assigned to In Progress

JF Updated by Juliana Fajardini Reichow 5 months ago Actions #46

  • 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 Actions #47

  • Description updated (diff)

JF Updated by Juliana Fajardini Reichow 5 months ago ยท Edited Actions #48

  • Assignee changed from OISF Dev to Juliana Fajardini Reichow
Actions

Also available in: PDF Atom