Skip to content
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

Tests: make FileCheck a substitution that sanitizes the input #4187

Merged
merged 4 commits into from
Aug 11, 2016

Conversation

gribozavr
Copy link
Contributor

@gribozavr gribozavr commented Aug 10, 2016

In the Swift testsuite, FileCheck is used to check for (or for absence of) fixed strings in the input. It is not an issue when the string is long and complex (e.g., a full SIL instruction). But sometimes the string is a common word (e.g., 'sdk' or 'branch'). Tests that use such patterns are known break when the path to the build directory contains these words.

This change makes %FileCheck a lit substitution that replaces paths to source and build directories with fixed strings.


Before merging this pull request to apple/swift repository:

  • Test pull request on Swift continuous integration.

Triggering Swift CI

The swift-ci is triggered by writing a comment on this PR addressed to the GitHub user @swift-ci. Different tests will run depending on the specific comment that you use. The currently available comments are:

Smoke Testing

Platform Comment
All supported platforms @swift-ci Please smoke test
All supported platforms @swift-ci Please smoke test and merge
OS X platform @swift-ci Please smoke test OS X platform
Linux platform @swift-ci Please smoke test Linux platform

A smoke test on macOS does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library only for macOS. Simulator standard libraries and
    device standard libraries are not built.
  3. lldb is not built.
  4. The test and validation-test targets are run only for macOS. The optimized
    version of these tests are not run.

A smoke test on Linux does the following:

  1. Builds the compiler incrementally.
  2. Builds the standard library incrementally.
  3. lldb is built incrementally.
  4. The swift test and validation-test targets are run. The optimized version of these
    tests are not run.
  5. lldb is tested.

Validation Testing

Platform Comment
All supported platforms @swift-ci Please test
All supported platforms @swift-ci Please test and merge
OS X platform @swift-ci Please test OS X platform
OS X platform @swift-ci Please benchmark
Linux platform @swift-ci Please test Linux platform

Lint Testing

Language Comment
Python @swift-ci Please Python lint

Note: Only members of the Apple organization can trigger swift-ci.

@gribozavr
Copy link
Contributor Author

@tkremenek Would you mind reviewing?

@gribozavr
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor

If FileCheck is going to be a substitution, it really should have %. That can be a separate commit, but I don't think it should be a separate PR.

@jrose-apple
Copy link
Contributor

Also, what if the path to the source dir contains regex metacharacters, or @ signs?

@gribozavr
Copy link
Contributor Author

If FileCheck is going to be a substitution, it really should have %. That can be a separate commit, but I don't think it should be a separate PR.

This is a massive change to all tests, is it actually worth it? I tried making it, but then ended up reverting it because the resulting patch was huge and the percent sign didn't seem provide enough benefit for the reader of the RUN line. Seeing %FileCheck, you would know that it is not the real FileCheck, but is that important? Especially since we want this substitution to be used in all tests by default, and only skipping the sanitization step when the test has a certain unusual structure.

I don't have a strong preference here, just wanted to hear your thoughts about it.

@gribozavr
Copy link
Contributor Author

Also, what if the path to the source dir contains regex metacharacters, or @ signs?

Good point. I'll escape them.

@jrose-apple
Copy link
Contributor

I feel very strongly that anything without a % should work when you write the equivalent thing on the command line. The way we get around the "raw" bit is to have another substitution for " FileCheck " that produces an error; you can see that in action in lit.cfg. If someone really wants the raw one, they can then quote it.

@rjmccall
Copy link
Contributor

lit already does some pretty serious command-line parsing, I think; I don't think it's too weird for it to substitute "plaintext" commands, especially since that will be reflected in its logged command lines. Although maybe we should ask @ddunbar.

If we create a subtle difference between FileCheck and %FileCheck, we're just going to end up with this bug duplicated incrementally.

@jrose-apple
Copy link
Contributor

I don't think that's true. lit's command-line parsing has only gotten more shell-like over the years. And nobody complains about a subtle difference between clang and %clang, because the first one produces an error.

@rjmccall
Copy link
Contributor

That's not a subtle difference, then.

@jrose-apple
Copy link
Contributor

Right, as I said above we should do the same for FileCheck.

@ddunbar
Copy link
Contributor

ddunbar commented Aug 10, 2016

My $0.02:

  1. I am ok with something like FileCheck not being a substitution, if it is simply phrased as how lit does the executable search for the first argument. I agree with Jordan the command lines should replay... it would be nice for lit to resolve the first argument to a complete path, and then show that in the output.

    I already wanted such a mechanism in place to solve the hacks that LLVM does for finding its tools in a more principled manner. It should just be possible for the lit config to define a function which maps executable names to arguments.

  2. For this particular problem, it feels like it should be fixed at the LLVM level not just worked around via a shim script. Maybe one option would be to add FileCheck options for the sanitization, and then use the mapping mechanism from Redundant Load Elimination Patches #1 to automatically provide them?

@jrose-apple
Copy link
Contributor

Ah, I'm actually against expanding FileCheck just for path purposes (@gottesmm and I have had this argument several times). If we're already using some other substitution, though, then doing that as well doesn't make it any worse.

@ddunbar
Copy link
Contributor

ddunbar commented Aug 10, 2016

What is your objection to expanding FileCheck for path purposes (I assume that equals meaning using a custom PATH search for it)? LLVM already does that all over the place for llc, etc.?

@jrose-apple
Copy link
Contributor

I like being able to read both the initial RUN lines and what lit spits out. But maybe I lost that battle already.

@atrick
Copy link
Contributor

atrick commented Aug 10, 2016

FWIW I very frequently need to read and understand the RUN line's full expansion. I'm constantly manually breaking tests just to find out what the actual run line is. I don't want that process to get any worse.

@jrose-apple
Copy link
Contributor

For that last, I'd actually like to add a mode to lit where it just dumps run lines and doesn't run tests. checks --help output Oh, -a outputs command lines on success, but you can't combine it with --no-execute.

@atrick
Copy link
Contributor

atrick commented Aug 10, 2016

Debugging a failure for me usually starts with understanding exactly how the test was invoked. I often want to reduce it to a smaller command line, smaller test case, and run lldb.

@ddunbar
Copy link
Contributor

ddunbar commented Aug 10, 2016

That would be a great idea, and shouldn't actually be very hard.

The existing --no-execute isn't very useful (I used it for perf timing, but that doesn't deserve that command line arg spelling).

stdin = sys.stdin.read()
for s in args.sanitize_strings:
replacement, pattern = s.split('=', 1)
stdin = stdin.replace(pattern, replacement)
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems expensive to do this in-memory rather than via pipe, but we can add that later.

@gribozavr
Copy link
Contributor Author

@jrose-apple I have addressed your comments:

  • We use pipes instead of temporary files now.
  • I switched test/Interpreter/SDK/Foundation_NSLog.swift to %FileCheck (instead of the raw one).

@gribozavr
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor

The substitution is still in-memory, but that's probably fine for now. Thanks, Dmitri!

@tkremenek
Copy link
Member

Just caught up on this. I think this is a great addition.

@gribozavr
Copy link
Contributor Author

OS X failed with a SwiftPM failure in PackageLoadingTests.ManifestTests testManifestLoading. Retrying.

@swift-ci Please smoke test OS X platform

@gribozavr
Copy link
Contributor Author

@swift-ci Please smoke test OS X platform

@gribozavr
Copy link
Contributor Author

@swift-ci Please test OS X platform

@gribozavr
Copy link
Contributor Author

SceneKit_test.swift failures look unrelated. Will retry tomorrow, maybe the CI will be in a better state.

'%FileCheck' removes absolute paths of the source and build directory
from the input.  Overwhelming majority of tests don't intend to match
these paths.

Also add a substitution '%raw-FileCheck' that does not sanitize the
input.
This reverts commit 02039a1.

With the new `%FileCheck` substitution that removess full paths to the
build directory from FileCheck inputs, this workaround is no longer
needed.
@gribozavr
Copy link
Contributor Author

gribozavr commented Aug 11, 2016

Resolved conflicts and rebased. Retrying.

@gribozavr
Copy link
Contributor Author

@swift-ci Please smoke test OS X platform

@gribozavr
Copy link
Contributor Author

@swift-ci Please test OS X platform

@gribozavr
Copy link
Contributor Author

Tested locally on Linux, tests pass.

@gribozavr
Copy link
Contributor Author

macOS passed on CI, merging!

@gribozavr gribozavr merged commit a33203f into master Aug 11, 2016
@gribozavr gribozavr deleted the FileCheck-substitution branch August 11, 2016 15:32
kateinoigakukun pushed a commit that referenced this pull request Aug 31, 2022
Resolve conflicts with upstream `main`
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.

6 participants