Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/6927 add unit tests v2 #10838

Closed
wants to merge 7 commits into from

Conversation

lukashino
Copy link
Contributor

Redmine ticket: https://redmine.openinfosecfoundation.org/issues/6927
Follow-up of: #10786

Describe changes:
v2

  • added a FatalError check on the number of LiveDevices
  • changed #if HAVE_DPDK to #if defined(HAVE_DPDK) && defined(UNITTESTS)
  • enabled unit tests in the Github workflow runs on Ubuntu and Fedora tasks

v1

  • function-guarded variable
  • fix the CPU exclude logic
  • add DPDK unit tests

Lukas Sismis added 7 commits April 14, 2024 12:39
To better control the values within the variables and to
prepare for the follow-up unit tests, the variable was moved
into global scope and should accessed only by functions.
This allows reinstantination of the variable value - needed for
unit tests.
The function would incorrectly perform XOR operation. While it
worked when the worker cores were occupying all cores, it is
still not correct operation. The example might be when a core
would be affined to only management and not worker threads.
With the XOR operation it would set affinity to also worker set.
(1 XOR 0 -> 1 where in fact the desired outcome is 0)
For the upcoming changes, skipping a unit test might be beneficial
when testing a function that retrieves hardware data. This can e.g. depend
on the number of CPU cores and systems that does not meet the required
test criteria will need to omit the tests.
The tests should always target minimal system requirements
Copy link

codecov bot commented Apr 14, 2024

Codecov Report

Attention: Patch coverage is 92.88136% with 21 lines in your changes are missing coverage. Please review.

Project coverage is 82.41%. Comparing base (784ce30) to head (0c7ea10).
Report is 127 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #10838      +/-   ##
==========================================
- Coverage   82.83%   82.41%   -0.42%     
==========================================
  Files         913      919       +6     
  Lines      246847   248831    +1984     
==========================================
+ Hits       204474   205083     +609     
- Misses      42373    43748    +1375     
Flag Coverage Δ
fuzzcorpus 64.35% <14.28%> (+0.05%) ⬆️
suricata-verify 62.08% <28.57%> (-0.02%) ⬇️
unittests 62.07% <92.88%> (-0.26%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 20058

@@ -451,6 +452,8 @@ void LiveDeviceFinalize(void)
}
SCFree(ld);
}

TAILQ_INIT(&pre_live_devices); // reset the list
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should it not be done in a separate "reset" function ?

Looks strange to see SomeFuncFinalize end with INIT

@@ -88,10 +88,12 @@ ThreadsAffinityType * GetAffinityTypeFromName(const char *name);

uint16_t AffinityGetNextCPU(ThreadsAffinityType *taf);
uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf);
#ifdef HAVE_DPDK
int UnitTestsUtilAffinityVerifyCPURequirement(void);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this function used outside of tests ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is not. What do you imply? Ah, should it be guarded by #if defined UNIT_TEST?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you imply? Ah, should it be guarded by #if defined UNIT_TEST?

Indeed, but trying to ask the question in a way that you found it yourself ;-)

@@ -326,7 +326,7 @@ uint16_t UtilAffinityGetAffinedCPUNum(ThreadsAffinityType *taf)
*/
int UnitTestsUtilAffinityVerifyCPURequirement(void)
{
#if UNITTESTS && !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && \
#if defined(UNITTESTS) && !defined __CYGWIN__ && !defined OS_WIN32 && !defined __OpenBSD__ && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this line should have only been changed in one commit

@catenacyber catenacyber added the needs rebase Needs rebase to master label Apr 30, 2024
Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs at least a rebase

@victorjulien
Copy link
Member

On the next PR, please set a descriptive title.

@lukashino
Copy link
Contributor Author

Follow up in #11494

@lukashino lukashino closed this Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs rebase Needs rebase to master
Development

Successfully merging this pull request may close these issues.

4 participants