Skip to content

util-cpu: add a mockup value for unittests v1#13645

Closed
lukashino wants to merge 1 commit into
OISF:masterfrom
lukashino:bug/7831-idempotent-threading-tests-v1
Closed

util-cpu: add a mockup value for unittests v1#13645
lukashino wants to merge 1 commit into
OISF:masterfrom
lukashino:bug/7831-idempotent-threading-tests-v1

Conversation

@lukashino

Copy link
Copy Markdown
Contributor

Tests were previously platform-dependent, as UtilCpuGetNumProcessorsOnline retrieved the real number of CPU cores, and on systems with fewer than 4 CPU cores, some threading unit tests failed.

Link to ticket: https://redmine.openinfosecfoundation.org/issues/7831

Describe changes:

  • added a mockup value of 40 cores

Tests were previously platform-dependent, as UtilCpuGetNumProcessorsOnline
retrieved the real number of CPU cores, and on systems with fewer than 4 CPU
cores, some threading unit tests failed.

Ticket: 7831
Comment thread src/util-cpu.c
Comment on lines +110 to +112
#ifdef UNITTESTS
return 40; // A mockup value for unittests
#endif

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How does this affect thing if I build with unittests, but then run live, on a box with 2 cores?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was afraid this case should be supported as well 😅 alternatively the tests can check real CPU core presence and skip tests based on the environment and requirements. This is implemented in the other PR#13644

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If it is a usual and still working case, then surely this would not be acceptable, and I would only propose skipping the tests on insufficient machine capabilities.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if rather ThreadingAffinityTest03 and such should be skipped if the requirements are not met

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I would be in favor of that approach as is implemented in #13644 in https://github.com/OISF/suricata/pull/13644/files#diff-1700c8224734e17b7f5fc2cb71b7c53c110438d178cf44ae0d35312c32b3e229R2060

Alternatively, we can add another switch to e.g. configure script that would enable unittest mockups and HW dependent tests would be otherwise skipped? configure --enable-unittests --enable-unittest-mockups

But I still prefer the real HW test as we can generally limit the tests to, e.g., 4 cores (or other limited HW resources).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So, should you close this PR in favor of #13644 and such ? (if you prefer the other PR as I do)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok, sounds good.

@satta satta Sep 25, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note that this actually breaks Debian package tests which run the unit tests on i386 platforms where the test machines have less than 4 CPUs: https://ci.debian.net/packages/s/suricata/testing/i386/64736439/

I also have a patch which determines at runtime whether UtilCpuGetNumProcessorsOnline() is called from a unit test or not, and which returns a hardcoded mock value in that case (See 994d01c) -- but would also be fine with skipping the tests.

For Debian I would just disable these tests so they don't hold up testing transitions.

@codecov

codecov Bot commented Jul 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 66.66667% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 83.69%. Comparing base (2e69e0d) to head (7357e42).
⚠️ Report is 31 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #13645   +/-   ##
=======================================
  Coverage   83.69%   83.69%           
=======================================
  Files        1011     1011           
  Lines      275071   275074    +3     
=======================================
+ Hits       230210   230226   +16     
+ Misses      44861    44848   -13     
Flag Coverage Δ
fuzzcorpus 62.83% <ø> (+0.08%) ⬆️
livemode 19.01% <ø> (-0.12%) ⬇️
pcap 44.72% <ø> (-0.02%) ⬇️
suricata-verify 65.06% <ø> (-0.04%) ⬇️
unittests 59.18% <66.66%> (-0.01%) ⬇️

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@suricata-qa

Copy link
Copy Markdown

Information: QA ran without warnings.

Pipeline = 27051

@lukashino

Copy link
Copy Markdown
Contributor Author

Closing as it breaks the use case of having unit tests compiled in with the runtime capture method.

@lukashino lukashino closed this Aug 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

5 participants