Skip to content

Fix unit test build errors under -Werror#5686

Merged
CarolYeh910 merged 8 commits intoaws:mainfrom
thulasiramk-2310:fix-werror-unit-tests-v2
Jan 2, 2026
Merged

Fix unit test build errors under -Werror#5686
CarolYeh910 merged 8 commits intoaws:mainfrom
thulasiramk-2310:fix-werror-unit-tests-v2

Conversation

@thulasiramk-2310
Copy link
Copy Markdown
Contributor

Goal

Enable -Werror for unit test builds and fix all warnings that appear when compiling unit tests under strict warning settings.

Why

Unit tests were previously built without -Werror, allowing compiler warnings to accumulate over time.
This caused build failures on stricter platforms such as macOS, FreeBSD, and OpenBSD once warnings were treated as errors.
Aligning unit test builds with the main library’s warning strictness improves build hygiene and prevents regressions.

How

  • Updated CMakeLists.txt to:
    • Add -Wno-missing-braces
    • Apply -Werror to unit test targets when UNSAFE_TREAT_WARNINGS_AS_ERRORS=ON
  • Fixed platform-specific warnings in unit tests:
    • Guarded clone-based tests with S2N_CLONE_SUPPORTED
    • Moved OCSP-related helpers under S2N_OCSP_STAPLING_SUPPORTED
    • Corrected format specifier usage for ssize_t
    • Fixed enum comparison warnings in handshake-related tests
  • Ensured all changes compile cleanly across Linux, macOS, and BSD platforms

Callouts

  • Warning enforcement is opt-in via UNSAFE_TREAT_WARNINGS_AS_ERRORS, consistent with existing build behavior
  • Changes are limited to test code and build configuration; no production logic is affected

Testing

Built and tested with:

cmake -DUNSAFE_TREAT_WARNINGS_AS_ERRORS=ON ..
make -j
ctest

Related

Resolves #5650

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@thulasiramk-2310
Copy link
Copy Markdown
Contributor Author

@maddeleine
This is a clean follow-up to the earlier PR (#5668). I reapplied the discussed fixes on a fresh branch and resolved the remaining platform-specific warnings with -Werror enabled.

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.

Add a note for the CI failure. The range of time_t is platform-specific:

tests/unit/s2n_x509_validator_test.c:130:24: error: implicit conversion from 'long long' to 'time_t' (aka 'long') changes value from 2524608000 to -1770359296 [-Werror,-Wconstant-conversion]

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.

Thanks — understood. Just to confirm: should I add a comment explaining the platform-specific time_t behavior, or guard/skip this test on platforms where time_t is 32-bit?

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 think we need both :) just adding a comment can't fix the CI

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.

Added a note and guarded the 2050 check so it only runs on platforms where time_t can represent it safely. Also added a null-check for the ASN1 time allocation.

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 changed return false to return true to fix the CI. Seems like there are two different things going on here: whether the year 2050 can be represented by time_t depends on the OS system; the result of X509_cmp_time() depends on the libcrypto.

32BitBuildAndUnit runs on a 32-bit system using linux-gnu as libcrypto. We do have another job testing Openssl102 on a 64-bit system. Now all the CI checks passed. Let's see if Madeleine has other feedback 😆

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.

Thanks for the explanation — that makes sense now.
I hadn’t fully separated the time_t range issue from the libcrypto behavior before, so thanks for clarifying that and adjusting the return value accordingly.
Glad to see all the CI checks are green now 😄 — will wait to see if Madeleine has any other feedback.

Copy link
Copy Markdown
Contributor

@maddeleine maddeleine left a comment

Choose a reason for hiding this comment

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

Thanks for tackling this, there were a bit more build errors in our tests than I expected, but that means that we really needed this turned on! Great!

@CarolYeh910 CarolYeh910 added this pull request to the merge queue Jan 2, 2026
Merged via the queue into aws:main with commit 3276a08 Jan 2, 2026
54 checks passed
@thulasiramk-2310
Copy link
Copy Markdown
Contributor Author

Thanks @maddeleine and @CarolYeh910 for the guidance and reviews - really helpful!

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.

Turn on -Werror flag for unit tests

3 participants