Skip to content

C++: Turn header variant tests that use PCH files into integration tests #19410

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 3 commits into from
Apr 30, 2025

Conversation

jketema
Copy link
Contributor

@jketema jketema commented Apr 29, 2025

These tests currently test a code path in the extractor that only exists for these tests. By turning them into integration tests, we actually use the code path that normal database creation uses.

Moreover, the tests only work by virtue of a hack, where we know magically that the empty file _.c will be extracted first by qltest.

These tests currently test a code path in the extractor that only exists for
these tests. By turning them into integration tests, we actually use the
code path that normal database creation uses.
@jketema jketema marked this pull request as ready for review April 29, 2025 13:22
@Copilot Copilot AI review requested due to automatic review settings April 29, 2025 13:22
@jketema jketema requested a review from a team as a code owner April 29, 2025 13:22
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 converts header variant tests using precompiled headers (PCH) into integration tests to exercise the normal database creation code path. Key changes include:

  • Updating Microsoft PCH tests by adding simple C source files with appropriate header inclusion directives.
  • Modifying Clang PCH tests to run as integration tests via a Python test script and multiple minimal C source files.
  • Removing hacky test setups by ensuring that PCH creation and inclusion follow realistic code extraction flows.

Reviewed Changes

Copilot reviewed 36 out of 36 changed files in this pull request and generated 2 comments.

File Description
cpp/ql/integration-tests/header-variant-tests/microsoft-pch/b.c Adds a simple C source using PCH with a pragma and header inclusion.
cpp/ql/integration-tests/header-variant-tests/microsoft-pch/a.c Includes the corresponding header for testing purposes.
cpp/ql/integration-tests/header-variant-tests/clang-pch/test.py Introduces a Python script to invoke database creation with PCH commands.
cpp/ql/integration-tests/header-variant-tests/clang-pch/*.c Provides minimal C source files exercising different PCH inclusion scenarios.
Comments suppressed due to low confidence (1)

cpp/ql/integration-tests/header-variant-tests/clang-pch/c.c:2

  • The macro ONE is used but its definition isn't shown in the diff; ensure that it is defined or included appropriately in the test environment.
  return ONE + FOUR;

redsun82
redsun82 previously approved these changes Apr 30, 2025
Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

Minor comment from me, LGTM

def test(codeql, cpp):
os.mkdir("pch")
codeql.database.create(command=[
f'"{cpp.get_tool("extractor")}" --mimic-clang -emit-pch -o pch/a.pch a.c',
Copy link
Contributor

Choose a reason for hiding this comment

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

minor cosmetic nit: here you could define once extractor = f"{cpp.get_tool("extractor")} --mimic-clang" and then reuse that for all commands.

This also avoids an extremely minor FS churn with calling get_tool repeatedly (that tries tools/extractor first with a couple of file extensions, and then goes into tools/{CODEQL_PLAT}/extractor, again potentially with multiple file extensions)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in edd18dc. I left the duplication of --mimic-clang/--mimic-cl, as I feel that slightly better signals what is going on.

redsun82
redsun82 previously approved these changes Apr 30, 2025
Copy link
Contributor

@redsun82 redsun82 left a comment

Choose a reason for hiding this comment

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

Thanks!

@jketema jketema merged commit 359aa02 into github:main Apr 30, 2025
12 checks passed
@jketema jketema deleted the header-variant branch April 30, 2025 18:10
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.

2 participants