Skip to content

ci: upgrade cppcheck from 2.3 to 2.13 via apt#5943

Open
fabit0v wants to merge 1 commit into
aws:mainfrom
fabit0v:cpp-check
Open

ci: upgrade cppcheck from 2.3 to 2.13 via apt#5943
fabit0v wants to merge 1 commit into
aws:mainfrom
fabit0v:cpp-check

Conversation

@fabit0v

@fabit0v fabit0v commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Goal

Update the cppcheck CI to use Ubuntu's pre-built package with incremental caching and targeted configuration checking.

Why

The build-from-source setup (pinned to cppcheck 2.3 from 2020) requires source patches and keeps breaking. Every upgrade attempt (#3630, #3646, #5186) failed due to compilation issues on newer Ubuntu.

How

  • Replace install_cppcheck.sh with apt-get install cppcheck=2.13*
  • Remove --force and replace with explicit customer configuration checks using -D/-U flags and --max-configs=1
  • Run cppcheck three times targeting real customer configurations: Linux+AWS-LC, Linux+OpenSSL, Windows
  • Add --cppcheck-build-dir with GitHub Actions cache for incremental analysis
  • Suppress noisy style findings and documented false positives
  • Use -j "$(nproc)" to adapt to available cores

Callouts

  • Cold run takes ~1h 43min on first CI execution. Subsequent cached runs will complete must faster.
  • --force removed. It caused 6+ hour timeouts on the CI runner. Instead it is replaced with explicit -D/-U flags which run once per customer configuration. Three runs cover Linux+AWS-LC, Linux+OpenSSL, and Windows, which represent the primary customer code paths. Running with and without --force locally produces identical findings.
  • --max-configs=1 ensures cppcheck only checks the specified configuration per run.
  • -j "$(nproc)" disables unusedFunction check (unchanged behavior from before).
  • Some suppressions were identified using cppcheck 2.19 (Ubuntu 26.04) locally. They're forward-compatible, so suppressions that don't match in 2.13 are handled via the unmatchedSuppression entry.

Testing

Passed locally with cppcheck 2.19 (all three configs, identical results with/without --force)
Draft PR passed on CI with cppcheck 2.13

Resolves #5239

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

@github-actions github-actions Bot added the s2n-core team label Jun 18, 2026
@fabit0v fabit0v force-pushed the cpp-check branch 4 times, most recently from 8d45387 to 301252a Compare June 29, 2026 19:37
@fabit0v fabit0v changed the title ci: update cpp check ci: upgrade cppcheck from 2.3 to 2.13 via apt Jun 30, 2026
@fabit0v fabit0v marked this pull request as ready for review June 30, 2026 20:59

@boquan-fang boquan-fang left a comment

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.

Seems like cppcheck will take 1 hour 43 minutes to finish running: https://github.com/aws/s2n-tls/actions/runs/28401044354/job/84152043651?pr=5943. Will this becomes faster in the future? If so, how much time or how many PRs do we need to do to get it down to a reasonable runtime.

$CPPCHECK_EXECUTABLE --std=c99 --error-exitcode=-1 --quiet -j "$(nproc)" \
--cppcheck-build-dir="$CPPCHECK_BUILD_DIR" \
--max-configs=1 \
--enable=warning,performance,portability \

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.

The original check has --enable=all and the code that you change to only has warning, performance, and portability check. Does that drop test coverage?

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.

It primarily drops the style suggestions which aren't actionable and informational messages like "ConfigurationNotChecked" and "unusedFunction", which don't work with -j.

if [ $FAILED == 1 ];
then

# Config 1: Linux + AWS-LC (primary customer configuration)

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.

All these three configs seem very similar to each other. Can we just use --force flag and make it one command?

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.

--force causes the job to time out at 6 hours because it tells cppcheck to explore every possible #ifdef combination.

sudo apt-get install -y cppcheck=2.13*

- name: Cache cppcheck build dir
uses: actions/cache@v4

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.

Is there a reason that we downgrade actions/cache from version 5 to 4?

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.

I was testing version 4 at the time. will revert to version 5.

constParameterCallback

// Reason: Conditions always true/false due to compile-time constants or platform-dependent macros.
knownConditionTrueFalse

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.

At line 17 of this file: https://github.com/aws/s2n-tls/pull/5943/changes#diff-bc7696cee1ea27205e3e145964ee35b2c7e79d5184b450e2dd1d5218aaee01f1R17, knownConditionTrueFalse has already been scoped to crypto/s2n_libcrypto.c. Why do we enable it globally here? Do we want this suppression to be globally available or just scoped to crypto/s2n_libcrypto.c?

nullPointerRedundantCheck:tls/s2n_tls13_secrets.c

// Reason: Const correctness suggestions are low-priority style noise. Suppressed globally.
constParameterPointer

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.

How many errors are these suppressing? All previous suppressions have a scope. Global suppressions might hide problems from us and general not a good idea.

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.

Most of these suppressions are from using cpp-check 2.19 locally which introduced new findings. I can scope it down to what the current CI runners use (version 2.13)

checkersReport

// Reason: Suppressions from old cppcheck version that no longer match.
unmatchedSuppression

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.

This unmatchedSuppression seems to suppress warnings if a suppression in this file doesn't match anything. I don't think we should suppress this error. We should fix the warnings that was generated by this suppression.

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.

Most of these findings are results from running it locally (Ubuntu 26 uses cpp-check 2.19). I will refactor to focus on the version that the CI runners use (2.13).

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Update cppcheck

2 participants