Skip to content

Use CTest to simplify test configuration#2001

Merged
Dead2 merged 1 commit intodevelopfrom
cmake-tests
Nov 16, 2025
Merged

Use CTest to simplify test configuration#2001
Dead2 merged 1 commit intodevelopfrom
cmake-tests

Conversation

@Dead2
Copy link
Copy Markdown
Member

@Dead2 Dead2 commented Nov 11, 2025

Start using CTest and the BUILD_TESTING option provided by it, this increases minimum CMake version to 3.14, same as what we had as minimum on the wiki since 2.1.0 but never enforced.

Also improve and make more clear the partial support for running our tests on the stock zlib, it now uses requires CMake variable TEST_STOCK_ZLIB to be manually set. Improved some of the tests in that relation.

In total, this simplifies the testing options and makes them follow the CTest standard more closely.

@Dead2 Dead2 added cleanup Improving maintainability or removing code. Documentation labels Nov 11, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Nov 11, 2025

Walkthrough

Replaces legacy ZLIB_ENABLE_TESTS/ZLIBNG_ENABLE_TESTS gating with CMake's BUILD_TESTING (adds include(CTest)), deprecates and maps ZLIB_ENABLE_TESTS to BUILD_TESTING, regates testing options on BUILD_TESTING, and updates test-source guards to use TEST_STOCK_ZLIB.

Changes

Cohort / File(s) Summary
Top-level CMake & feature plumbing
CMakeLists.txt
Raise minimum CMake version; add include(CTest); introduce BUILD_TESTING feature (default ON), deprecate/map ZLIB_ENABLE_TESTSBUILD_TESTING; remove ZLIB_ENABLE_TESTS/ZLIBNG_ENABLE_TESTS feature entries; re-gate WITH_GTEST, WITH_FUZZERS, WITH_BENCHMARKS, WITH_BENCHMARK_APPS on BUILD_TESTING; update messaging/shared-library gating.
Documentation
README.md
Remove ZLIB_ENABLE_TESTS / ZLIBNG_ENABLE_TESTS build-option rows; add BUILD_TESTING build-option row ("Build test binaries", default ON).
Test CMake plumbing
test/CMakeLists.txt, test/add-subdirectory-project/CMakeLists.txt, test/fuzz/CMakeLists.txt
Replace checks of ZLIB_ENABLE_TESTS/ZLIBNG_ENABLE_TESTS with BUILD_TESTING or TEST_STOCK_ZLIB as appropriate; test/add-subdirectory-project sets the cache entry using BUILD_TESTING; fuzz CMake removes guard and now always discovers/registers fuzzers.
Test sources & headers
test/example.c, test/infcover.c, test/test_shared_ng.h
Flip/add preprocessor guards to TEST_STOCK_ZLIB (#ifndef TEST_STOCK_ZLIB / #ifdef TEST_STOCK_ZLIB) to include/exclude zlib-ng–specific tests and adjust conditional compilation paths (e.g., inflate-table/coverage and deflatePrime call paths).

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant User as User / CMake cache
    participant CMake as Top-level CMakeLists.txt
    participant CTest as CTest / BUILD_TESTING
    participant Tests as test CMake & sources

    Note over User,CMake: option resolution
    User->>CMake: may set `ZLIB_ENABLE_TESTS` or `BUILD_TESTING`
    CMake->>CMake: if(DEFINED ZLIB_ENABLE_TESTS) map to `BUILD_TESTING` and emit deprecation
    CMake->>CMake: include(CTest)

    Note over CMake,CTest: test gating decision
    alt BUILD_TESTING = ON
        CMake->>Tests: enable `WITH_GTEST` / `WITH_FUZZERS` / `WITH_BENCHMARKS` / `WITH_BENCHMARK_APPS`
        Tests-->>CMake: configure and register test targets (including fuzzers)
    else
        CMake-->>Tests: test-related options disabled
    end

    Note over Tests: source-level selection
    CMake->>Tests: may define `TEST_STOCK_ZLIB`
    alt TEST_STOCK_ZLIB defined
        Tests-->>Tests: exclude zlib-ng-only coverage/inflate-table tests
    else
        Tests-->>Tests: include zlib-ng test paths
    end
Loading

Possibly related PRs

Suggested labels

Testing Framework, Build Env

Suggested reviewers

  • nmoinvaz

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the main change: transitioning to CTest and simplifying test configuration from multiple convoluted options to BUILD_TESTING.
Docstring Coverage ✅ Passed Docstring coverage is 85.71% which is sufficient. The required threshold is 80.00%.
Description check ✅ Passed The PR description clearly explains the changes: adopting CTest and BUILD_TESTING standard, increasing CMake minimum version to 3.14, and adding TEST_STOCK_ZLIB for better stock zlib test support.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cmake-tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20083c8 and e115f9c.

📒 Files selected for processing (2)
  • CMakeLists.txt (5 hunks)
  • README.md (3 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.
📚 Learning: 2025-02-21T01:41:50.358Z
Learnt from: KungFuJesus
Repo: zlib-ng/zlib-ng PR: 1872
File: arch/x86/chorba_sse2.c:14-24
Timestamp: 2025-02-21T01:41:50.358Z
Learning: In zlib-ng's SSE2 vectorized Chorba CRC implementation, the code that calls READ_NEXT macro ensures 16-byte alignment, making explicit alignment checks unnecessary within the macro.

Applied to files:

  • README.md
📚 Learning: 2025-07-04T16:59:44.725Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.

Applied to files:

  • README.md
  • CMakeLists.txt
📚 Learning: 2025-10-12T17:01:13.630Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.

Applied to files:

  • README.md
  • CMakeLists.txt
📚 Learning: 2025-04-15T09:20:52.333Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1904
File: arch/riscv/Makefile.in:12-14
Timestamp: 2025-04-15T09:20:52.333Z
Learning: Optional feature flags in Makefile.in templates should default to empty strings. The configure script should detect feature support and update these variables accordingly during the configuration process.

Applied to files:

  • CMakeLists.txt
📚 Learning: 2025-04-15T09:30:10.081Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1904
File: arch/riscv/Makefile.in:12-14
Timestamp: 2025-04-15T09:30:10.081Z
Learning: Feature detection modules like riscv_features.c should not be compiled with feature-specific flags (like RVVFLAG) because they need to be compilable on all systems regardless of feature support. These modules perform runtime detection and must initialize feature availability flags to zero on unsupported systems.

Applied to files:

  • CMakeLists.txt
🪛 LanguageTool
README.md

[uncategorized] ~103-~103: Do not mix variants of the same word (‘optimisation’ and ‘optimization’) within a single text.
Context: ...| --without-optimizations | Build with optimisations ...

(EN_WORD_COHERENCY)


[uncategorized] ~211-~211: Do not mix variants of the same word (‘optimisation’ and ‘optimization’) within a single text.
Context: ...ut-power8 | ppc: Build with POWER8 optimisations ...

(EN_WORD_COHERENCY)


[uncategorized] ~212-~212: Do not mix variants of the same word (‘optimisation’ and ‘optimization’) within a single text.
Context: ...ut-power9 | ppc: Build with POWER9 optimisations ...

(EN_WORD_COHERENCY)


[uncategorized] ~218-~218: Do not mix variants of the same word (‘optimisation’ and ‘optimization’) within a single text.
Context: ... | loongarch: Build with LSX optimisations ...

(EN_WORD_COHERENCY)

🔇 Additional comments (6)
CMakeLists.txt (3)

51-57: Backward compatibility logic is clean.

The introduction of ZLIBNG_ENABLE_TESTS as the canonical option with propagation from ZLIB_ENABLE_TESTS correctly implements the consolidation intent. The dependent options (WITH_GTEST, WITH_FUZZERS, WITH_BENCHMARKS) are properly updated to gate on the new option.


1577-1594: Test gating correctly switches to ZLIBNG_ENABLE_TESTS.

The conditional logic properly gates test and benchmark builds on the unified option while enforcing the constraint that tests are incompatible with shared libraries.


1617-1617: Architecture-specific feature info entries correctly added.

The new feature info entries for WITH_ARMV6 and WITH_CRC32_VX follow the established pattern and properly expose these architecture-specific options in the feature summary.

Also applies to: 1628-1628

README.md (3)

22-26: Feature bullets accurately document expanded SIMD coverage.

The updated SIMD target lists align with the architecture-specific options and expanded feature support reflected in the CMakeLists.txt changes. Documentation is comprehensive and clear.


100-109: Build Options table correctly documents new/refactored options.

The additions of ZLIB_ALIASES and ZLIBNG_ENABLE_TESTS, along with the reformatted existing options, accurately reflect the CMakeLists.txt configuration surface. Table layout and descriptions are clear.


194-227: Advanced Build Options table comprehensively documents architecture-specific intrinsics.

The restructured table correctly maps CMakeLists.txt architecture-specific options with clear target architecture prefixes. Content accuracy and organization are strong.

Minor note: Static analysis flags mixed British/American English spelling (e.g., "optimisations" on lines 211, 212, 218 vs. "Build with optimisations" on line 103). This mixes with the configure option's American spelling --without-optimizations. Consider standardizing to one variant codebase-wide in a follow-up cleanup if desired, though this is a pre-existing inconsistency not critical to this PR.

@Dead2 Dead2 force-pushed the cmake-tests branch 2 times, most recently from ca62f21 to afa18d3 Compare November 11, 2025 16:58
@codecov
Copy link
Copy Markdown

codecov bot commented Nov 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 82.20%. Comparing base (780838b) to head (38d5130).
⚠️ Report is 5 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2001      +/-   ##
===========================================
- Coverage    83.31%   82.20%   -1.12%     
===========================================
  Files          161      161              
  Lines        12960    13612     +652     
  Branches      3149     3276     +127     
===========================================
+ Hits         10798    11190     +392     
- Misses        1134     1378     +244     
- Partials      1028     1044      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Nov 13, 2025

When ZLIB_COMPAT is set, some tests don't make sense, thus should not be unconditionally enabled. I don't see however reason to have two separate options just to enable basic functionality tests.

I'm not sure how many tests there is that only make sense when ZLIB_COMPAT is set.

@Dead2
Copy link
Copy Markdown
Member Author

Dead2 commented Nov 13, 2025

When ZLIB_COMPAT is set, some tests don't make sense, thus should not be unconditionally enabled. I don't see however reason to have two separate options just to enable basic functionality tests.

I'm not sure how many tests there is that only make sense when ZLIB_COMPAT is set.

Those tests should be enabled/disabled according to ZLIB_COMPAT then.
None of it worked that way before, ZLIB_ENABLE_TESTS enabled the tests options only but did not itself enable any tests, while ZLIBNG_ENABLE_TESTS enabled tests only if ZLIB_ENABLE_TESTS was also enabled.
ZLIBNG_ENABLE_TESTS enabled tests for both zlib-ng and compat apis.
No specific tests for compat api were disabled based on ZLIB_ENABLE_TESTS, all testing would get disabled.

That logic is pretty convoluted and not necessary for us.
Better to have ZLIBNG_ENABLE_TESTS enable testing and some basic tests, then WITH_GTEST, WITH_FUZZERS and WITH_BENCHMARKS enabling the more in-depth tests.

@nmoinvaz
Copy link
Copy Markdown
Member

@Dead2:

CMake provides a BUILD_TESTING option through its CTest module, which is set to ON by default when the module creates it. This option controls whether include(CTest) calls enable_testing() to build tests in a project.

I'm not sure if it makes sense to start using this BUILD_TESTING instead of a *_ENABLE_TESTS option.

# Backwards compatibility?
if (DEFINED ZLIB_ENABLE_TESTS AND NOT ZLIB_ENABLE_TESTS)
   set(BUILD_TESTING OFF)
endif()

@Dead2
Copy link
Copy Markdown
Member Author

Dead2 commented Nov 13, 2025

I'm not sure if it makes sense to start using this BUILD_TESTING instead of a *_ENABLE_TESTS option.

That is a good idea, I wonder how well this change works. It builds fine locally at least :)

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e2b6a4f and 7633397.

📒 Files selected for processing (8)
  • CMakeLists.txt (2 hunks)
  • README.md (1 hunks)
  • test/CMakeLists.txt (3 hunks)
  • test/add-subdirectory-project/CMakeLists.txt (1 hunks)
  • test/example.c (2 hunks)
  • test/fuzz/CMakeLists.txt (1 hunks)
  • test/infcover.c (3 hunks)
  • test/test_shared_ng.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • CMakeLists.txt
🧰 Additional context used
🧠 Learnings (7)
📚 Learning: 2024-09-25T16:25:56.686Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1797
File: inflate.c:81-83
Timestamp: 2024-09-25T16:25:56.686Z
Learning: When `INFLATE_STRICT` is not defined, the variable `state->dmax` is completely removed from the code.

Applied to files:

  • test/infcover.c
📚 Learning: 2025-08-20T14:34:15.867Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1928
File: gzwrite.c:0-0
Timestamp: 2025-08-20T14:34:15.867Z
Learning: Z_VERSION_ERROR is used by zlib but not by zlib-ng, so it should not be included in error handling for zlib-ng deflateInit2() calls.

Applied to files:

  • test/infcover.c
  • test/example.c
  • test/test_shared_ng.h
📚 Learning: 2024-09-25T16:26:23.643Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1797
File: inflate.c:84-86
Timestamp: 2024-09-25T16:26:23.643Z
Learning: When `INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR` is not defined, `state->sane` is completely removed from the codebase and does not need to be initialized.

Applied to files:

  • test/infcover.c
📚 Learning: 2025-07-04T16:59:44.725Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.

Applied to files:

  • README.md
  • test/test_shared_ng.h
📚 Learning: 2025-10-12T17:01:13.630Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.

Applied to files:

  • README.md
  • test/example.c
  • test/test_shared_ng.h
📚 Learning: 2025-02-21T01:41:50.358Z
Learnt from: KungFuJesus
Repo: zlib-ng/zlib-ng PR: 1872
File: arch/x86/chorba_sse2.c:14-24
Timestamp: 2025-02-21T01:41:50.358Z
Learning: In zlib-ng's SSE2 vectorized Chorba CRC implementation, the code that calls READ_NEXT macro ensures 16-byte alignment, making explicit alignment checks unnecessary within the macro.

Applied to files:

  • test/example.c
  • test/test_shared_ng.h
📚 Learning: 2025-05-13T06:56:12.407Z
Learnt from: samrussell
Repo: zlib-ng/zlib-ng PR: 1914
File: arch/generic/crc32_chorba_c.c:30-32
Timestamp: 2025-05-13T06:56:12.407Z
Learning: In zlib-ng, pointer casts between z_word_t* and uint64_t* are safe because: 1) On 64-bit platforms, z_word_t is defined as uint64_t, making the cast a no-op; 2) On 32-bit platforms where z_word_t is uint32_t, the code paths using uint64_t* are skipped in favor of 32-bit specific implementations.

Applied to files:

  • test/test_shared_ng.h
🔇 Additional comments (10)
test/fuzz/CMakeLists.txt (1)

42-44: LGTM - Unconditional test registration is appropriate.

The fuzzer tests are now registered unconditionally within this file, which is correct since the parent CMakeLists.txt conditionally includes this directory based on WITH_FUZZERS and the new BUILD_TESTING flow.

test/test_shared_ng.h (1)

11-18: LGTM - Semantic shift from "enable tests" to "test stock zlib" is appropriate.

The change from #ifdef ZLIBNG_ENABLE_TESTS to #ifndef TEST_STOCK_ZLIB correctly reflects the new approach: when not testing against stock zlib, use zlib-ng's native 32-bit deflatePrime(). When testing stock zlib compatibility, fall back to the 16-bit implementation required by the original zlib API.

test/example.c (2)

423-462: LGTM - Correctly excludes zlib-ng specific test.

The test_sync() function is appropriately guarded with #ifndef TEST_STOCK_ZLIB as it expects a specific compressed block layout unique to zlib-ng. The comment on line 426 clarifies this intent.


982-984: LGTM - Consistent guarding of test_sync call.

The call to test_sync() is correctly guarded with the same #ifndef TEST_STOCK_ZLIB condition as its definition, ensuring consistency.

test/infcover.c (2)

621-645: LGTM - Correctly excludes zlib-ng internal test.

The cover_trees() function directly calls zng_inflate_table() (line 636, 640), which is internal to zlib-ng. Guarding this with #ifndef TEST_STOCK_ZLIB is appropriate since these internals are not available when testing against stock zlib.


677-679: LGTM - Consistent guarding of cover_trees call.

The call to cover_trees() is correctly guarded with the same #ifndef TEST_STOCK_ZLIB condition as its definition, ensuring consistency.

test/add-subdirectory-project/CMakeLists.txt (1)

8-8: Verify consistency with the main CMakeLists.txt option.

This sets BUILD_TESTS to control test builds, matching the README documentation. However, ensure this aligns with the actual option name used in the parent CMakeLists.txt (verify whether it should be BUILD_TESTS or BUILD_TESTING).

test/CMakeLists.txt (3)

57-57: Unconditional infcover test registration - verify this is intentional.

The infcover test is now always registered without any conditional guard. Previously (per the AI summary), it was conditionally registered. Ensure this aligns with the intended behavior where the test directory itself is only included when BUILD_TESTING is ON in the parent CMakeLists.txt.


178-188: LGTM - Correctly excludes zlib-ng specific tests.

The additional test sources (test_adler32.cc, test_crc32.cc, test_inflate_sync.cc, etc.) are appropriately included only when NOT TEST_STOCK_ZLIB, as these tests exercise zlib-ng specific functionality like CPU intrinsics and internal APIs that are not available in stock zlib.


10-12: TEST_STOCK_ZLIB is checked but not defined in CMakeLists.txt.

Verification confirms the concern: TEST_STOCK_ZLIB at test/CMakeLists.txt:10 is referenced without any definition in the root or test CMakeLists.txt files. The variable is either intended to be passed via cmake command-line (-DTEST_STOCK_ZLIB=ON) or is missing its intended definition. If this is intentional, consider documenting it; otherwise, add an option() declaration in test/CMakeLists.txt.

@Dead2 Dead2 force-pushed the cmake-tests branch 2 times, most recently from 382bd9b to f07d474 Compare November 13, 2025 23:39
@Dead2
Copy link
Copy Markdown
Member Author

Dead2 commented Nov 13, 2025

I have not tested the functionality of running our tests on stock zlib, don't even know how to do that really, but I added the CMake variable TEST_STOCK_ZLIB that can be used to make tests behave better with stock zlib. Whether that works? IDK

@Dead2
Copy link
Copy Markdown
Member Author

Dead2 commented Nov 14, 2025

It passes CI at least.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
CMakeLists.txt (1)

1597-1597: Feature info references undefined variable.

Line 1597 uses ZLIBNG_ENABLE_TESTS as the status variable for add_feature_info(), but ZLIBNG_ENABLE_TESTS is never defined in the code. This will cause the feature summary to report incorrect status. The actual control variable is BUILD_TESTING.

Apply this diff:

-add_feature_info(ZLIBNG_ENABLE_TESTS ZLIBNG_ENABLE_TESTS "Build test binaries")
+add_feature_info(ZLIBNG_ENABLE_TESTS BUILD_TESTING "Build test binaries")
🧹 Nitpick comments (1)
CMakeLists.txt (1)

52-54: Consider adding a deprecation message for ZLIB_ENABLE_TESTS.

The backward compatibility logic correctly handles ZLIB_ENABLE_TESTS=OFF, but users who have ZLIB_ENABLE_TESTS=ON might be surprised that it has no effect (since BUILD_TESTING defaults to OFF in subdirectory builds). Consider adding a deprecation message to guide users toward BUILD_TESTING:

 if (DEFINED ZLIB_ENABLE_TESTS AND NOT ZLIB_ENABLE_TESTS)
    set(BUILD_TESTING OFF)
 endif()
+if (DEFINED ZLIB_ENABLE_TESTS)
+   message(DEPRECATION "ZLIB_ENABLE_TESTS is deprecated. Please use BUILD_TESTING instead.")
+endif()
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 382bd9b and 6f9af3e.

📒 Files selected for processing (8)
  • CMakeLists.txt (2 hunks)
  • README.md (1 hunks)
  • test/CMakeLists.txt (3 hunks)
  • test/add-subdirectory-project/CMakeLists.txt (1 hunks)
  • test/example.c (2 hunks)
  • test/fuzz/CMakeLists.txt (1 hunks)
  • test/infcover.c (3 hunks)
  • test/test_shared_ng.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • README.md
  • test/fuzz/CMakeLists.txt
  • test/test_shared_ng.h
  • test/CMakeLists.txt
🧰 Additional context used
🧠 Learnings (7)
📚 Learning: 2024-09-25T16:25:56.686Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1797
File: inflate.c:81-83
Timestamp: 2024-09-25T16:25:56.686Z
Learning: When `INFLATE_STRICT` is not defined, the variable `state->dmax` is completely removed from the code.

Applied to files:

  • test/infcover.c
📚 Learning: 2025-08-20T14:34:15.867Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1928
File: gzwrite.c:0-0
Timestamp: 2025-08-20T14:34:15.867Z
Learning: Z_VERSION_ERROR is used by zlib but not by zlib-ng, so it should not be included in error handling for zlib-ng deflateInit2() calls.

Applied to files:

  • test/infcover.c
  • test/example.c
📚 Learning: 2024-09-25T16:26:23.643Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1797
File: inflate.c:84-86
Timestamp: 2024-09-25T16:26:23.643Z
Learning: When `INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR` is not defined, `state->sane` is completely removed from the codebase and does not need to be initialized.

Applied to files:

  • test/infcover.c
📚 Learning: 2025-10-12T17:01:13.630Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.

Applied to files:

  • test/example.c
📚 Learning: 2025-02-21T01:41:50.358Z
Learnt from: KungFuJesus
Repo: zlib-ng/zlib-ng PR: 1872
File: arch/x86/chorba_sse2.c:14-24
Timestamp: 2025-02-21T01:41:50.358Z
Learning: In zlib-ng's SSE2 vectorized Chorba CRC implementation, the code that calls READ_NEXT macro ensures 16-byte alignment, making explicit alignment checks unnecessary within the macro.

Applied to files:

  • test/example.c
📚 Learning: 2025-04-15T09:20:52.333Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1904
File: arch/riscv/Makefile.in:12-14
Timestamp: 2025-04-15T09:20:52.333Z
Learning: Optional feature flags in Makefile.in templates should default to empty strings. The configure script should detect feature support and update these variables accordingly during the configuration process.

Applied to files:

  • CMakeLists.txt
📚 Learning: 2025-07-04T16:59:44.725Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.

Applied to files:

  • CMakeLists.txt
🔇 Additional comments (4)
test/example.c (2)

423-462: LGTM! Guard change aligns with test semantics.

The guard change from #ifdef ZLIBNG_ENABLE_TESTS to #ifndef TEST_STOCK_ZLIB correctly implements the intent stated in the comment at line 426—this test expects zlib-ng-specific compressed block layout and should be skipped when testing against stock zlib.


982-984: LGTM! Consistent guard at call site.

The guard at the call site correctly matches the function definition guard, ensuring test_sync is only called when it's compiled.

test/infcover.c (1)

621-645: LGTM! Appropriate guards for zlib-ng specific tests.

The #ifndef TEST_STOCK_ZLIB guards correctly exclude the cover_trees() function and its invocation when testing against stock zlib, since zng_inflate_table() is not available in stock zlib.

Also applies to: 677-679

CMakeLists.txt (1)

1577-1592: LGTM! Test gating logic is correct.

The migration to BUILD_TESTING is properly implemented, and the shared library constraints for gtest and benchmarks are appropriately handled.

@Dead2 Dead2 changed the title Simplify enabling tests in CMake Use CTest to simplify test configuration Nov 14, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
CMakeLists.txt (1)

52-55: Enhance backward compatibility to handle both ON and OFF cases.

The current logic only maps ZLIB_ENABLE_TESTS=OFF to BUILD_TESTING=OFF, but doesn't handle the case where users explicitly set ZLIB_ENABLE_TESTS=ON. For complete backward compatibility, consider mapping both states.

Apply this diff to handle both cases:

-if (DEFINED ZLIB_ENABLE_TESTS AND NOT ZLIB_ENABLE_TESTS)
+if (DEFINED ZLIB_ENABLE_TESTS)
     message(DEPRECATION "ZLIB_ENABLE_TESTS is deprecated. Please use BUILD_TESTING instead.")
-    set(BUILD_TESTING OFF)
+    if(NOT ZLIB_ENABLE_TESTS)
+        set(BUILD_TESTING OFF)
+    else()
+        set(BUILD_TESTING ON)
+    endif()
 endif()
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6f9af3e and c6db8eb.

📒 Files selected for processing (8)
  • CMakeLists.txt (3 hunks)
  • README.md (1 hunks)
  • test/CMakeLists.txt (3 hunks)
  • test/add-subdirectory-project/CMakeLists.txt (1 hunks)
  • test/example.c (2 hunks)
  • test/fuzz/CMakeLists.txt (1 hunks)
  • test/infcover.c (3 hunks)
  • test/test_shared_ng.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • README.md
  • test/add-subdirectory-project/CMakeLists.txt
  • test/example.c
  • test/fuzz/CMakeLists.txt
  • test/CMakeLists.txt
🧰 Additional context used
🧠 Learnings (8)
📚 Learning: 2024-09-25T16:25:56.686Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1797
File: inflate.c:81-83
Timestamp: 2024-09-25T16:25:56.686Z
Learning: When `INFLATE_STRICT` is not defined, the variable `state->dmax` is completely removed from the code.

Applied to files:

  • test/infcover.c
📚 Learning: 2025-08-20T14:34:15.867Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1928
File: gzwrite.c:0-0
Timestamp: 2025-08-20T14:34:15.867Z
Learning: Z_VERSION_ERROR is used by zlib but not by zlib-ng, so it should not be included in error handling for zlib-ng deflateInit2() calls.

Applied to files:

  • test/infcover.c
  • test/test_shared_ng.h
📚 Learning: 2024-09-25T16:26:23.643Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1797
File: inflate.c:84-86
Timestamp: 2024-09-25T16:26:23.643Z
Learning: When `INFLATE_ALLOW_INVALID_DISTANCE_TOOFAR_ARRR` is not defined, `state->sane` is completely removed from the codebase and does not need to be initialized.

Applied to files:

  • test/infcover.c
📚 Learning: 2025-10-12T17:01:13.630Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-05-13T06:56:12.407Z
Learnt from: samrussell
Repo: zlib-ng/zlib-ng PR: 1914
File: arch/generic/crc32_chorba_c.c:30-32
Timestamp: 2025-05-13T06:56:12.407Z
Learning: In zlib-ng, pointer casts between z_word_t* and uint64_t* are safe because: 1) On 64-bit platforms, z_word_t is defined as uint64_t, making the cast a no-op; 2) On 32-bit platforms where z_word_t is uint32_t, the code paths using uint64_t* are skipped in favor of 32-bit specific implementations.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-02-21T01:41:50.358Z
Learnt from: KungFuJesus
Repo: zlib-ng/zlib-ng PR: 1872
File: arch/x86/chorba_sse2.c:14-24
Timestamp: 2025-02-21T01:41:50.358Z
Learning: In zlib-ng's SSE2 vectorized Chorba CRC implementation, the code that calls READ_NEXT macro ensures 16-byte alignment, making explicit alignment checks unnecessary within the macro.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-07-04T16:59:44.725Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-04-15T09:20:52.333Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1904
File: arch/riscv/Makefile.in:12-14
Timestamp: 2025-04-15T09:20:52.333Z
Learning: Optional feature flags in Makefile.in templates should default to empty strings. The configure script should detect feature support and update these variables accordingly during the configuration process.

Applied to files:

  • CMakeLists.txt
🔇 Additional comments (8)
test/infcover.c (2)

621-645: LGTM! Correct guard for zlib-ng internal API.

The guard correctly excludes cover_trees() when testing with stock zlib, since it calls zng_inflate_table() which is a zlib-ng internal function not available in stock zlib.


677-679: LGTM! Consistent guard for function call.

The guard correctly excludes the cover_trees() call when the function itself is not compiled (stock zlib mode), maintaining consistency with the function definition guard.

test/test_shared_ng.h (1)

11-18: LGTM! Correct guard for zlib-ng extended API.

The guard correctly uses the 32-bit deflatePrime() path when NOT using stock zlib (zlib-ng native mode), and falls back to two 16-bit calls for stock zlib compatibility, which only supports up to 16 bits per call.

CMakeLists.txt (5)

48-48: LGTM! Using standard CMake testing infrastructure.

Adding include(CTest) is the standard CMake way to enable testing support. This provides the BUILD_TESTING option (ON by default) and calls enable_testing() automatically.


56-59: LGTM! Correctly updated test dependencies.

The dependent options now properly gate on BUILD_TESTING instead of the deprecated ZLIB_ENABLE_TESTS, using the standard CMake testing infrastructure.


1578-1593: LGTM! Testing block correctly updated to use BUILD_TESTING.

The test subdirectory and related options are now properly gated on BUILD_TESTING, consistent with standard CMake testing practices. The updated messages correctly reflect the new gating mechanism.


1598-1598: LGTM! Feature info correctly reports BUILD_TESTING status.

The feature summary now correctly reports the status of BUILD_TESTING, which is the actual control variable for test builds.


1599-1599: LGTM! Clarified sanitizer feature description.

Adding "testing" to the description clarifies that sanitizer support is for testing purposes, improving the feature summary readability.

mtl1979

This comment was marked as resolved.

cmake_dependent_option(WITH_BENCHMARKS "Build test/benchmarks" OFF "ZLIB_ENABLE_TESTS" OFF)
cmake_dependent_option(WITH_BENCHMARK_APPS "Build application benchmarks" OFF "WITH_BENCHMARKS" OFF)
if (DEFINED ZLIB_ENABLE_TESTS AND NOT ZLIB_ENABLE_TESTS)
message(DEPRECATION "ZLIB_ENABLE_TESTS is deprecated. Please use BUILD_TESTING instead.")
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Indeed. Fixed.

@Dead2
Copy link
Copy Markdown
Member Author

Dead2 commented Nov 15, 2025

Added workaround for BUILD_TESTING not being set until some unclear version (it was used before it actually got documented, and no mention of when it was introduced).
The workaround adds an option that does not override an existing option/variable (but depends on CMake 3.13).

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (2)
README.md (1)

109-109: Correctly documents BUILD_TESTING.

The CMake option name now matches the actual variable provided by include(CTest) in CMakeLists.txt.

test/add-subdirectory-project/CMakeLists.txt (1)

8-8: Correctly uses BUILD_TESTING.

The cache variable now matches CTest's BUILD_TESTING option (included on line 5).

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a06ce5f and 1b85b57.

📒 Files selected for processing (8)
  • CMakeLists.txt (4 hunks)
  • README.md (1 hunks)
  • test/CMakeLists.txt (3 hunks)
  • test/add-subdirectory-project/CMakeLists.txt (1 hunks)
  • test/example.c (2 hunks)
  • test/fuzz/CMakeLists.txt (1 hunks)
  • test/infcover.c (3 hunks)
  • test/test_shared_ng.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • test/fuzz/CMakeLists.txt
  • test/CMakeLists.txt
  • test/infcover.c
  • test/example.c
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.
📚 Learning: 2025-10-12T17:01:13.630Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.

Applied to files:

  • test/test_shared_ng.h
  • README.md
📚 Learning: 2025-08-20T14:34:15.867Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1928
File: gzwrite.c:0-0
Timestamp: 2025-08-20T14:34:15.867Z
Learning: Z_VERSION_ERROR is used by zlib but not by zlib-ng, so it should not be included in error handling for zlib-ng deflateInit2() calls.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-05-13T06:56:12.407Z
Learnt from: samrussell
Repo: zlib-ng/zlib-ng PR: 1914
File: arch/generic/crc32_chorba_c.c:30-32
Timestamp: 2025-05-13T06:56:12.407Z
Learning: In zlib-ng, pointer casts between z_word_t* and uint64_t* are safe because: 1) On 64-bit platforms, z_word_t is defined as uint64_t, making the cast a no-op; 2) On 32-bit platforms where z_word_t is uint32_t, the code paths using uint64_t* are skipped in favor of 32-bit specific implementations.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-02-21T01:41:50.358Z
Learnt from: KungFuJesus
Repo: zlib-ng/zlib-ng PR: 1872
File: arch/x86/chorba_sse2.c:14-24
Timestamp: 2025-02-21T01:41:50.358Z
Learning: In zlib-ng's SSE2 vectorized Chorba CRC implementation, the code that calls READ_NEXT macro ensures 16-byte alignment, making explicit alignment checks unnecessary within the macro.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-07-04T16:59:44.725Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.

Applied to files:

  • CMakeLists.txt
  • README.md
📚 Learning: 2025-04-15T09:20:52.333Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1904
File: arch/riscv/Makefile.in:12-14
Timestamp: 2025-04-15T09:20:52.333Z
Learning: Optional feature flags in Makefile.in templates should default to empty strings. The configure script should detect feature support and update these variables accordingly during the configuration process.

Applied to files:

  • CMakeLists.txt
🔇 Additional comments (6)
test/test_shared_ng.h (1)

11-11: LGTM! Guard correctly switched to TEST_STOCK_ZLIB.

The preprocessor guard correctly selects the appropriate deflatePrime implementation: the native 32-bit path for zlib-ng, and the split 16-bit workaround for stock zlib (which only accepts 16 bits per call).

CMakeLists.txt (5)

1-1: Minimum CMake version bump justified by CMP0077 requirement.

The bump to 3.13 is necessary for CMP0077 support (see line 52), which allows option() to honor normal variables—needed for the BUILD_TESTING integration with CTest.


48-48: LGTM! CTest included at appropriate location.

Placed correctly before the BUILD_TESTING option declaration (line 52) and among other CMake module includes.


59-62: LGTM! Test-related options correctly depend on BUILD_TESTING.

The cmake_dependent_option declarations properly gate WITH_GTEST, WITH_FUZZERS, WITH_BENCHMARKS, and WITH_BENCHMARK_APPS on BUILD_TESTING.


1581-1598: LGTM! Test gating correctly migrated to BUILD_TESTING.

The test enablement logic properly uses BUILD_TESTING and retains the shared library constraints for gtest and benchmarks.


1603-1603: LGTM! Feature info correctly reports BUILD_TESTING.

The feature summary now tracks BUILD_TESTING instead of the legacy test flags.

Add CMake variable TEST_STOCK_ZLIB to disable some tests if attempting
to run our testsuite on stock zlib.
PR depends on CMP0077, introduced by CMake 3.13.
Upped minimum compatible CMake version to 3.13, same as we have
actually been telling people was the minumum for years on the wiki.
Upped upper compatible CMake version to 3.31, my current version.
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

♻️ Duplicate comments (3)
README.md (1)

109-109: LGTM! Documentation correctly reflects the CMake option.

The BUILD_TESTING option name matches the actual CMake option defined in CMakeLists.txt line 52, and the past review concern about the BUILD_TESTS typo has been addressed.

test/add-subdirectory-project/CMakeLists.txt (1)

8-8: LGTM! Variable name corrected.

The BUILD_TESTING variable now correctly matches the CTest-provided option (line 5 includes CTest), and the past critical issue about using BUILD_TESTS has been resolved.

CMakeLists.txt (1)

53-58: Consider handling both ON and OFF cases in deprecation logic.

The deprecation mapping only sets BUILD_TESTING OFF when ZLIB_ENABLE_TESTS is OFF, but doesn't set BUILD_TESTING ON when ZLIB_ENABLE_TESTS is ON. While the default BUILD_TESTING ON (line 52) handles clean builds, users upgrading with a cached BUILD_TESTING=OFF who set ZLIB_ENABLE_TESTS=ON won't see tests enabled.

For smoother migration, consider handling both cases:

if (DEFINED ZLIB_ENABLE_TESTS)
    message(DEPRECATION "ZLIB_ENABLE_TESTS is deprecated. Please use BUILD_TESTING instead.")
    if (ZLIB_ENABLE_TESTS)
        set(BUILD_TESTING ON)
    else()
        set(BUILD_TESTING OFF)
    endif()
endif()
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1b85b57 and 38d5130.

📒 Files selected for processing (8)
  • CMakeLists.txt (4 hunks)
  • README.md (1 hunks)
  • test/CMakeLists.txt (3 hunks)
  • test/add-subdirectory-project/CMakeLists.txt (1 hunks)
  • test/example.c (2 hunks)
  • test/fuzz/CMakeLists.txt (1 hunks)
  • test/infcover.c (3 hunks)
  • test/test_shared_ng.h (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • test/infcover.c
  • test/example.c
🧰 Additional context used
🧠 Learnings (7)
📓 Common learnings
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.
📚 Learning: 2025-07-04T16:59:44.725Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1925
File: arch/loongarch/lasxintrin_ext.h:38-65
Timestamp: 2025-07-04T16:59:44.725Z
Learning: In zlib-ng, the policy for supporting old compilers is to maintain compatibility for up to two years after GitHub removes support for them in CI, or when there is no long-time contributor left testing for the architecture if the architecture was not supported by GitHub Actions at all.

Applied to files:

  • test/CMakeLists.txt
  • CMakeLists.txt
  • README.md
📚 Learning: 2025-04-15T09:20:52.333Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1904
File: arch/riscv/Makefile.in:12-14
Timestamp: 2025-04-15T09:20:52.333Z
Learning: Optional feature flags in Makefile.in templates should default to empty strings. The configure script should detect feature support and update these variables accordingly during the configuration process.

Applied to files:

  • CMakeLists.txt
📚 Learning: 2025-10-12T17:01:13.630Z
Learnt from: mtl1979
Repo: zlib-ng/zlib-ng PR: 1980
File: compress.c:31-33
Timestamp: 2025-10-12T17:01:13.630Z
Learning: In zlib-ng, when ZLIB_COMPAT is defined, z_int32_t is typedef'd as `int` (not int32_t), and zlib.h is included (which uses `int` in function signatures). This allows the implementation to use z_int32_t while maintaining backwards compatibility with the original zlib API that uses `int`. When ZLIB_COMPAT is not defined, z_int32_t is typedef'd as int32_t and zlib-ng.h is used instead.

Applied to files:

  • README.md
  • test/test_shared_ng.h
📚 Learning: 2025-08-20T14:34:15.867Z
Learnt from: Dead2
Repo: zlib-ng/zlib-ng PR: 1928
File: gzwrite.c:0-0
Timestamp: 2025-08-20T14:34:15.867Z
Learning: Z_VERSION_ERROR is used by zlib but not by zlib-ng, so it should not be included in error handling for zlib-ng deflateInit2() calls.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-05-13T06:56:12.407Z
Learnt from: samrussell
Repo: zlib-ng/zlib-ng PR: 1914
File: arch/generic/crc32_chorba_c.c:30-32
Timestamp: 2025-05-13T06:56:12.407Z
Learning: In zlib-ng, pointer casts between z_word_t* and uint64_t* are safe because: 1) On 64-bit platforms, z_word_t is defined as uint64_t, making the cast a no-op; 2) On 32-bit platforms where z_word_t is uint32_t, the code paths using uint64_t* are skipped in favor of 32-bit specific implementations.

Applied to files:

  • test/test_shared_ng.h
📚 Learning: 2025-02-21T01:41:50.358Z
Learnt from: KungFuJesus
Repo: zlib-ng/zlib-ng PR: 1872
File: arch/x86/chorba_sse2.c:14-24
Timestamp: 2025-02-21T01:41:50.358Z
Learning: In zlib-ng's SSE2 vectorized Chorba CRC implementation, the code that calls READ_NEXT macro ensures 16-byte alignment, making explicit alignment checks unnecessary within the macro.

Applied to files:

  • test/test_shared_ng.h
🧬 Code graph analysis (1)
README.md (1)
test/pkgcheck.sh (1)
  • usage (3-46)
🔇 Additional comments (8)
test/CMakeLists.txt (2)

56-56: LGTM! Test registration simplified.

The infcover test is now unconditionally registered, which is appropriate since the entire test/ directory is only processed when BUILD_TESTING is enabled (CMakeLists.txt line 1581). This simplification removes redundant conditional logic.


177-187: LGTM! Conditional test inclusion correctly inverted.

The logic correctly excludes zlib-ng-specific tests (adler32_neon, cpu_check_features, etc.) when TEST_STOCK_ZLIB is defined, as these tests rely on zlib-ng internals and would fail against stock zlib.

test/test_shared_ng.h (1)

11-18: LGTM! Guard condition correctly transformed.

The preprocessor guard change from #ifdef ZLIBNG_ENABLE_TESTS to #ifndef TEST_STOCK_ZLIB correctly maintains the semantic intent:

  • When TEST_STOCK_ZLIB is NOT defined: use zlib-ng's native 32-bit deflatePrime
  • When TEST_STOCK_ZLIB IS defined: use the stock zlib-compatible 16-bit two-step approach

This transformation aligns with the new testing flag semantics while preserving the original behavior.

CMakeLists.txt (4)

59-62: LGTM! Dependent options correctly structured.

The test-related options (WITH_GTEST, WITH_FUZZERS, WITH_BENCHMARKS, WITH_BENCHMARK_APPS) now properly depend on BUILD_TESTING using cmake_dependent_option, ensuring they're automatically disabled when BUILD_TESTING is OFF while remaining independently configurable when BUILD_TESTING is ON.


1581-1598: LGTM! Test gating migrated to BUILD_TESTING.

The test directory inclusion and related warning messages have been correctly updated to use BUILD_TESTING instead of ZLIB_ENABLE_TESTS, maintaining the same logic while adopting the standard CMake convention.


1603-1604: LGTM! Feature summary updated.

The feature info declarations correctly reflect the migration from ZLIB_ENABLE_TESTS/ZLIBNG_ENABLE_TESTS to BUILD_TESTING, ensuring the feature summary displays accurate information.


1-1: No action required—code is correct.

The code safely handles version compatibility. Line 4-5 uses if(POLICY CMP0169) to conditionally set the policy only when CMake 3.30+ recognizes it, preventing errors on older versions. The minimum version 3.14 satisfies the CMP0077 (3.13) dependency mentioned at line 52 and likely other requirements. The discrepancy noted in the original review is not an issue—this is correct defensive programming.

test/fuzz/CMakeLists.txt (1)

42-44: LGTM! Unconditional test registration appropriate.

The fuzz tests are now unconditionally registered within this file, which is correct because:

  1. The test/ directory is only processed when BUILD_TESTING is ON (CMakeLists.txt line 1581)
  2. This fuzz/ subdirectory is only included when WITH_FUZZERS is ON (test/CMakeLists.txt line 86)
  3. WITH_FUZZERS depends on BUILD_TESTING (CMakeLists.txt line 60)

This multi-level gating eliminates the need for redundant conditionals in this file.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Nov 15, 2025

I have not tested the functionality of running our tests on stock zlib, don't even know how to do that really, but I added the CMake variable TEST_STOCK_ZLIB that can be used to make tests behave better with stock zlib. Whether that works? IDK

You need headers and libz.a from stock zlib, then link the test sources against libz.a from stock zlib. This isn't much different from comparing ABIs between stock zlib and zlib-ng in compat mode as both require pulling stock zlib sources from its Git repository and building within "fetched" zlib-ng repository.

@nmoinvaz
Copy link
Copy Markdown
Member

LGTM!

Copy link
Copy Markdown
Collaborator

@mtl1979 mtl1979 left a comment

Choose a reason for hiding this comment

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

LGTM

@Dead2 Dead2 merged commit 8d4bd56 into develop Nov 16, 2025
301 of 304 checks passed
@Dead2
Copy link
Copy Markdown
Member Author

Dead2 commented Nov 16, 2025

I have not tested the functionality of running our tests on stock zlib, don't even know how to do that really, but I added the CMake variable TEST_STOCK_ZLIB that can be used to make tests behave better with stock zlib. Whether that works? IDK

You need headers and libz.a from stock zlib, then link the test sources against libz.a from stock zlib. This isn't much different from comparing ABIs between stock zlib and zlib-ng in compat mode as both require pulling stock zlib sources from its Git repository and building within "fetched" zlib-ng repository.

@mtl1979 Would you mind making a step-by-step of that on the wiki for future reference? New page called "Advanced Testing" or something perhaps, a page that could be used to describe several special testing features like stock zlib, libpng, abi, etc..

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Nov 16, 2025

@mtl1979 Would you mind making a step-by-step of that on the wiki for future reference? New page called "Advanced Testing" or something perhaps, a page that could be used to describe several special testing features like stock zlib, libpng, abi, etc..

I'm still figuring out how much changes it requires in the test sources itself... We could short circuit by passing ZLIB_COMPAT to the test sources so stock zlib testing would share a lot of code with zlib-ng in compat mode, but it would still need to avoid some zlib-ng specific additions.

As most of the long-time people know, I'm not very good at making CMake build scripts, so I might need some help with isolating the test sources from rest of the zlib-ng source tree...

@Dead2
Copy link
Copy Markdown
Member Author

Dead2 commented Nov 16, 2025

@mtl1979 Would you mind making a step-by-step of that on the wiki for future reference? New page called "Advanced Testing" or something perhaps, a page that could be used to describe several special testing features like stock zlib, libpng, abi, etc..

I'm still figuring out how much changes it requires in the test sources itself... We could short circuit by passing ZLIB_COMPAT to the test sources so stock zlib testing would share a lot of code with zlib-ng in compat mode, but it would still need to avoid some zlib-ng specific additions.

As most of the long-time people know, I'm not very good at making CMake build scripts, so I might need some help with isolating the test sources from rest of the zlib-ng source tree...

Oh, I thought you were using it this way already. It's more of a nice-to-have than a must-have. Not a big priority IMO.

@mtl1979
Copy link
Copy Markdown
Collaborator

mtl1979 commented Nov 16, 2025

Oh, I thought you were using it this way already. It's more of a nice-to-have than a must-have. Not a big priority IMO.

Build system of stock zlib has had quite big bugs for years, so using it for anything complex has just failed... I know there is workarounds for a lot of the bugs in stock zlib, but it's matter of knowing which commit in the develop branch fix each issue and if there is breaking changes between two commits.

I know how to do a lot of weird things in principle, but doing some of them will need some edits to more than one source tree. There is always a "hack" way of things and then there is cleaner way of doing things...

"Hack" way in this case is just replacing libz.a from zlib-ng with the one from stock zlib, but there is no guarantee that linker is able to combine the two successfully due to version checks and changes in the internal function signatures.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Improving maintainability or removing code. Documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants