Skip to content

Conversation

@thulasiramk-2310
Copy link

Goal

Enable -Werror for all unit test builds and fix the warnings that appear when compiling tests with this flag enabled.

Why

Unit tests previously did not compile with -Werror, which allowed several warnings to accumulate unnoticed.
Applying warnings-as-errors improves build hygiene, enforces consistency with the main library build, and prevents future regressions.

How

Build System

  • Updated CMakeLists.txt to apply -Werror to all unit test targets when UNSAFE_TREAT_WARNINGS_AS_ERRORS=ON is set.

Warning Fixes

  • tests/unit/s2n_safety_test.c

    • Initialized a local buffer to resolve a maybe-uninitialized warning.
  • tests/unit/s2n_tls12_handshake_test.c

    • Replaced invalid array-to-array comparisons with memcmp().
  • tests/unit/s2n_tls13_handshake_state_machine_test.c

    • Replaced array comparisons with proper memcmp() checks.

Verification

  • Rebuilt the entire project with strict warning settings to ensure no further warnings remain.

Callouts

  • This enforcement uses the existing UNSAFE_TREAT_WARNINGS_AS_ERRORS mechanism to keep the change opt-in, as requested in the issue discussion.
  • If maintainers prefer applying this unconditionally, I can update the PR accordingly.

Testing

Built and tested with:

cmake -DUNSAFE_TREAT_WARNINGS_AS_ERRORS=ON ..
make -j

Verified:

  • 100% of unit tests pass (280 tests, 0 failures)
  • All warnings resolved
  • No behavioral regressions introduced

Related

Resolves #5650

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

@maddeleine
Copy link
Contributor

Looks like there's also a failure on mac builds. I think you probably just need to add an if-def S2N_CLONE_SUPPORTED around the s2n_unit_test_clone_child_process function to get those builds to pass.

}

#if S2N_CLONE_SUPPORTED
static int s2n_unit_test_clone_child_process(struct s2n_unit_test_clone *data)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not the correct place for this change. The fork_generation_number_test is the testfile that is causing the issue.

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for pointing that out — I’ll move the guard to fork_generation_number_test and update the PR accordingly.

Copy link
Author

Choose a reason for hiding this comment

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

@maddeleine I’ve moved the S2N_CLONE_SUPPORTED guard and s2n_unit_test_clone_child_process into s2n_fork_generation_number_test, and reverted s2n_safety_test to only include the initialization fix. Please let me know if this looks correct now.

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

2 participants