Skip to content

Add comprehensive unit tests for nDPI public API#3146

Closed
Copilot wants to merge 2 commits intodevfrom
copilot/add-test-coverage-analysis
Closed

Add comprehensive unit tests for nDPI public API#3146
Copilot wants to merge 2 commits intodevfrom
copilot/add-test-coverage-analysis

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 26, 2026

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

  • stringUtilsUnitTestndpi_strnstr, ndpi_strncasestr, ndpi_strip_leading_trailing_spaces, ndpi_check_punycode_string with edge cases (empty needle, boundary lengths, encoding detection)
  • hashFunctionsUnitTest — determinism and collision properties for ndpi_hash_string, ndpi_quick_hash, ndpi_murmur_hash, ndpi_hash_string_len; correctness of ndpi_nearest_power_of_two
  • strHashMapUnitTest — full lifecycle: ndpi_hash_init/add_entry/find_entry/walk/free, including update-in-place semantics and non-existent key behaviour
  • dataAnalysisUnitTest — statistical correctness of ndpi_data_average/variance/stddev/min/max, sliding-window stats, ndpi_reset_data_analysis, ndpi_alloc_data_analysis_from_series, and ndpi_data_ratio/ndpi_data_ratio2str thresholds
  • bitmapUnitTest — roaring bitmap CRUD, cardinality, AND/OR/XOR, copy, iterator traversal, and serialize/deserialize round-trip
  • bitmap64FuseUnitTest — fuse bitmap set→compress→query lifecycle including values exceeding the 32-bit range (0x100000000ULL)
  • riskUtilsUnitTestndpi_risk2str for every ndpi_risk_enum value; ndpi_risk2score for zero-risk, single-risk, and combined-risk cases
  • cryptoUnitTestndpi_md5/ndpi_sha256 against known-good vectors, ndpi_crc32/ndpi_crc16_ccit determinism, ndpi_hex2bin/ndpi_bin2hex round-trip
  • protocolModuleUnitTest — module lifecycle and metadata: version, protocol count/name, breed/category lookups, ndpi_detection_get_sizeof_ndpi_flow_struct, and proper teardown via ndpi_exit_detection_module

Copilot AI and others added 2 commits March 26, 2026 22:15
…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>
@sonarqubecloud
Copy link
Copy Markdown

@lucaderi lucaderi marked this pull request as ready for review March 26, 2026 22:22
@lucaderi lucaderi requested a review from IvanNardi March 26, 2026 22:22
@lucaderi
Copy link
Copy Markdown
Member

We decided to keep the current test suite ad developed so far.

@lucaderi lucaderi closed this Mar 27, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants