dpdk: add initial unittests for DPDK codebase v13.2#15366
Conversation
The threads field is uint16_t, so the <= 0 comparison is misleading as the value can never be negative. Change to == 0. Ticket: 6927
Rename affinity public API functions to use a consistent naming convention (e.g. GetAffinityTypeForNameAndIface to AffinityTypeGetByIfaceOrCpuset, UtilAffinityGetAffinedCPUNum to AffinityGetAffinedCPUNum, AffinitySetupLoadFromConfig to AffinityLoadFromConfig, etc.). Also change the return type of AffinityCpusOverlap from uint16_t to bool, remove dead code in that function, and make ResetAffinityForTest public as AffinityReset for unit test use. Ticket: 6927
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 be accessed only by functions. This allows reinitialization of the variable value - needed for unit tests. Ticket: 6927
Needed by unit tests to properly reset the device list. Ticket: 6927
Add SKIP() macro and update the test runner to track and report skipped tests separately from passes and failures. Ticket: 6927
Some unit tests work with multiple CPUs. Suricata, in some code paths, depends on the environment on which it runs. As a result, tests requiring e.g. 4 cores failed on 2-core machines. This commit introduces a skip directive for these tests. Change AffinityLoadFromConfig from void to int, returning negative errno on failure. Callers now treat affinity configuration errors as fatal at startup with descriptive error messages. Move the CPU range bounds check (b > max) from an early parse-time error to a post-load validation that returns -ERANGE, allowing the skip directive to handle incompatible environments. Add explicit bounds checks for single CPU values exceeding the available range. Ticket: 6927
Reduce affinity unit test CPU indices to a maximum of 4 cores for broader CI compatibility on machines with fewer CPUs. Also fix assertions in ThreadingAffinityTest12 that were incorrectly checking hiprio_cpu instead of cpu_set. Ticket: 6927
Add unit tests for mempool cache size auto-calculation and for automatic thread distribution across interfaces, including management thread overlap scenarios. Ticket: 6927
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds initial unit tests for DPDK runmode logic and improves CPU affinity parsing/error propagation, including a mechanism to skip tests on hosts that don’t meet minimum CPU requirements.
Changes:
- Introduce
SKIP()support in the unit test framework and surface skipped counts in test results. - Refactor/rename affinity APIs and propagate parse errors upwards (now fatal at runtime when affinity config is invalid).
- Add DPDK runmode unit tests (thread auto-assignment + mempool cache size auto-calculation) and enable DPDK in a CI job.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/util-unittest.h | Adds SKIP(reason) unittest helper returning a distinct skip code. |
| src/util-unittest.c | Tracks/pass/fail/skip results; prints skipped count. |
| src/util-ebpf.c | Updates to renamed affinity cpuset builder API. |
| src/util-device.c | Re-initializes TAILQ heads after list cleanup/finalize. |
| src/util-affinity.h | Renames/reshapes affinity API, adds reset + new return types. |
| src/util-affinity.c | Refactors affinity parsing to return errno-style errors; adds/updates unit tests. |
| src/tm-threads.c | Updates callsites to renamed affinity APIs. |
| src/runmodes.c | Makes invalid affinity config fatal with strerror diagnostics. |
| src/runmode-unittests.c | Registers affinity tests under new name; registers DPDK tests under HAVE_DPDK. |
| src/runmode-dpdk.h | Adds unit test registration prototype guarded by HAVE_DPDK && UNITTESTS. |
| src/runmode-dpdk.c | Adds DPDK unit tests; refactors auto-thread remainder logic; updates affinity API usage. |
| .github/workflows/builds.yml | Installs DPDK deps and enables --enable-dpdk for a unittest build job. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| for (i = 0; i < MAX_CPU_SET; i++) { | ||
| if (strcmp(thread_affinity[i].name, name) == 0) { | ||
| if (strcmp(thread_affinity[i].name, affinity_set_name) == 0) { |
There was a problem hiding this comment.
This thread_affinity[i].name != NULL signals bug in the code, irrelevant.
| SCConfInit(); | ||
| ResetAffinityForTest(); | ||
| AffinityReset(); | ||
| SCConfYamlLoadString(config, strlen(config)); |
There was a problem hiding this comment.
unit tests only. this pattern is elsewhere as well.. Irrelevant
| SKIP("not enough cpus in the system"); | ||
| FAIL_IF(ret < 0); | ||
|
|
||
| DPDKIfaceConfig iconf = { 0 }; |
There was a problem hiding this comment.
name is not needed, irrelevant
| for (int i = UtilCpuGetNumProcessorsOnline() - 1; i >= 0; i--) | ||
| if (CPU_ISSET(i, &tmpcset)) { | ||
| return 1; | ||
| } |
There was a problem hiding this comment.
potentially relevant but very minor, not addressing.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #15366 +/- ##
==========================================
- Coverage 82.64% 82.61% -0.04%
==========================================
Files 996 996
Lines 271107 271116 +9
==========================================
- Hits 224063 223989 -74
- Misses 47044 47127 +83
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
|
WARNING:
Pipeline = 31395 |
|
Will need a rebase |
catenacyber
left a comment
There was a problem hiding this comment.
Requesting changes as it needs a rebase
Follow-up of #15347
Link to ticket: https://redmine.openinfosecfoundation.org/issues/6927
The PR is adding unit tests tailored to verify CPU threading logic and the automatic calculation of the mempool cache of the interface. Tests are skipped if the minimal CPU requirements (CPU count) on the executing machine are not met.
Describe changes:
v13.2:
threadingformat (switching from a list to nodes)v12.7:
v12.1 (Victor-greened in v11.4):
v11.4:
v11.3:
v11.2:
v10.1:
v2 (v10):
v1 - PR splitted to sub-PRs: