Add comprehensive unit tests for nDPI public API#3146
Closed
Conversation
…ps, bitmaps, risks, crypto, and protocol module APIs Agent-Logs-Url: https://github.com/ntop/nDPI/sessions/ff18deab-42fa-4a6c-8f86-e7756d8b89ee Co-authored-by: lucaderi <4493366+lucaderi@users.noreply.github.com>
… 64-bit bitmap test value Agent-Logs-Url: https://github.com/ntop/nDPI/sessions/ff18deab-42fa-4a6c-8f86-e7756d8b89ee Co-authored-by: lucaderi <4493366+lucaderi@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
lucaderi
March 26, 2026 22:21
View session
|
Member
|
We decided to keep the current test suite ad developed so far. |
IvanNardi
added a commit
to IvanNardi/nDPI
that referenced
this pull request
Mar 28, 2026
Put all the internal unit tests in a separate file. The tests suite run (via `ndpiReader`): * if the option `--run-tests` is used, * always if the library is compiled with `-DNDPI_EXTENDED_SANITY_CHECKS` (useful in CI) Extend tests using part of ntop#3146. We keep `tests/unit/unit.c` for serialization tests, like now, because that is the only code that depends on the external library libjson-c
IvanNardi
added a commit
to IvanNardi/nDPI
that referenced
this pull request
Mar 28, 2026
Put all the internal unit tests in a separate file. The tests suite run (via `ndpiReader`): * if the option `--run-tests` is used, * always if the library is compiled with `-DNDPI_EXTENDED_SANITY_CHECKS` (useful in CI) Extend tests using part of ntop#3146. We keep `tests/unit/unit.c` for serialization tests, like now, because that is the only code that depends on the external library libjson-c
IvanNardi
added a commit
to IvanNardi/nDPI
that referenced
this pull request
Mar 28, 2026
Put all the internal unit tests in a separate file. The tests suite run (via `ndpiReader`): * if the option `--run-tests` is used, * always if the library is compiled with `-DNDPI_EXTENDED_SANITY_CHECKS` (useful in CI) Extend tests using part of ntop#3146. We keep `tests/unit/unit.c` for serialization tests, like now, because that is the only code that depends on the external library libjson-c
IvanNardi
added a commit
to IvanNardi/nDPI
that referenced
this pull request
Mar 28, 2026
Put all the internal unit tests in a separate file. The tests suite run (via `ndpiReader`): * if the option `--run-tests` is used, * always if the library is compiled with `-DNDPI_EXTENDED_SANITY_CHECKS` (useful in CI) Extend tests using part of ntop#3146. We keep `tests/unit/unit.c` for serialization tests, like now, because that is the only code that depends on the external library libjson-c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Unit test coverage was essentially limited to serializer output (TLV/JSON/CSV) — 2 test functions across ~422 lines against a ~60,000-line library. Nine new test functions cover previously untested public API surface.
New test functions
stringUtilsUnitTest—ndpi_strnstr,ndpi_strncasestr,ndpi_strip_leading_trailing_spaces,ndpi_check_punycode_stringwith edge cases (empty needle, boundary lengths, encoding detection)hashFunctionsUnitTest— determinism and collision properties forndpi_hash_string,ndpi_quick_hash,ndpi_murmur_hash,ndpi_hash_string_len; correctness ofndpi_nearest_power_of_twostrHashMapUnitTest— full lifecycle:ndpi_hash_init/add_entry/find_entry/walk/free, including update-in-place semantics and non-existent key behaviourdataAnalysisUnitTest— statistical correctness ofndpi_data_average/variance/stddev/min/max, sliding-window stats,ndpi_reset_data_analysis,ndpi_alloc_data_analysis_from_series, andndpi_data_ratio/ndpi_data_ratio2strthresholdsbitmapUnitTest— roaring bitmap CRUD, cardinality,AND/OR/XOR, copy, iterator traversal, and serialize/deserialize round-tripbitmap64FuseUnitTest— fuse bitmap set→compress→query lifecycle including values exceeding the 32-bit range (0x100000000ULL)riskUtilsUnitTest—ndpi_risk2strfor everyndpi_risk_enumvalue;ndpi_risk2scorefor zero-risk, single-risk, and combined-risk casescryptoUnitTest—ndpi_md5/ndpi_sha256against known-good vectors,ndpi_crc32/ndpi_crc16_ccitdeterminism,ndpi_hex2bin/ndpi_bin2hexround-tripprotocolModuleUnitTest— module lifecycle and metadata: version, protocol count/name, breed/category lookups,ndpi_detection_get_sizeof_ndpi_flow_struct, and proper teardown viandpi_exit_detection_module