Skip to content

C++: Exclude tests in model generation #19498

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2025

Conversation

MathiasVP
Copy link
Contributor

@jketema noticed that there are a few summaries (for OpenSSL specifically) in #19492 that are from test functions. This PR excludes model generation for functions inside folders that match %test%.

Care is needed to not exclude our own tests, though, as the summary tests are located in cpp/ql/test/library-tests/dataflow/modelgenerator/dataflow. So we explicitly allow that directory.

I tried to regenerate the OpenSSL models with these changes on top of #19492 and compare the changes: https://www.diffchecker.com/z6iyKLAU/ (this isn't super readable, but I've manually checked most of the excludes functions and they do indeed belong to tests)

@Copilot Copilot AI review requested due to automatic review settings May 15, 2025 13:09
@MathiasVP MathiasVP requested a review from a team as a code owner May 15, 2025 13:09
@github-actions github-actions bot added the C++ label May 15, 2025
@MathiasVP MathiasVP added the no-change-note-required This PR does not need a change note label May 15, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates model generation to skip functions located in test directories while still including the CodeQL summary tests under test/library-tests/dataflow/modelgenerator/dataflow.

  • Adds a new predicate clause in isUninterestingForModels to exclude files whose paths contain test
  • Introduces an exception to retain the CodeQL summary tests directory
  • Adjusts path-matching logic in CaptureModels.qll
Comments suppressed due to low confidence (1)

cpp/ql/src/utils/modelgenerator/internal/CaptureModels.qll:49

  • Add unit tests or QL tests to validate this exclusion rule, ensuring functions in general test folders are skipped and those under test/library-tests/dataflow/modelgenerator/dataflow remain included.
// Exclude functions in test directories (but not the ones in the CodeQL test directory)

// Exclude functions in test directories (but not the ones in the CodeQL test directory)
exists(Cpp::File f |
f = api.getFile() and
f.getAbsolutePath().matches("%test%") and
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

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

The pattern "%test%" may match any substring (e.g., "contest" or user paths containing "test"). Consider anchoring to directory separators (e.g., "%/test/%") or using a path-matching utility to target only "test" directories.

Suggested change
f.getAbsolutePath().matches("%test%") and
f.getAbsolutePath().matches("%/test/%") and

Copilot uses AI. Check for mistakes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a bad suggestion! I do like simply using test though so that we also match stuff like tests, though. I could go either way on this 🤷

Comment on lines +52 to +53
f.getAbsolutePath().matches("%test%") and
not f.getAbsolutePath().matches("%test/library-tests/dataflow/modelgenerator/dataflow/%")
Copy link
Preview

Copilot AI May 15, 2025

Choose a reason for hiding this comment

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

Relying on absolute paths with OS-specific separators can reduce portability. Consider using getRelativePath() or normalizing paths with forward slashes to ensure this exception works across platforms.

Suggested change
f.getAbsolutePath().matches("%test%") and
not f.getAbsolutePath().matches("%test/library-tests/dataflow/modelgenerator/dataflow/%")
f.getRelativePath().matches("%test%") and
not f.getRelativePath().matches("%test/library-tests/dataflow/modelgenerator/dataflow/%")

Copilot uses AI. Check for mistakes.

Copy link
Contributor

@jketema jketema left a comment

Choose a reason for hiding this comment

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

LGTM

@MathiasVP MathiasVP merged commit ffc1c62 into github:main May 16, 2025
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C++ no-change-note-required This PR does not need a change note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants