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

[SR-1125] Make StdlibUnittest automatically run tests in process when run in the interpreter #43738

Closed
belkadan opened this issue Apr 1, 2016 · 22 comments
Assignees
Labels
improvement standard library Area: Standard library umbrella

Comments

@belkadan
Copy link
Contributor

belkadan commented Apr 1, 2016

Previous ID SR-1125
Radar None
Original Reporter @belkadan
Type Improvement
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Improvement, Test
Assignee @harlanhaskins
Priority Medium

md5: 891687c76bd6a27a72b51e7b499c7049

relates to:

  • SR-1126 Support more complicated execution tests under "lit.py --param interpret"

Issue Description:

By default StdlibUnittest runs tests out of process, so that it can detect expected and unexpected crashes. We should give it a mode where it

  • runs tests in process

  • skips crash tests (possibly with a new skip annotation)

and figure out how to automatically make it use this mode when run under the Swift interpreter, at least during lit tests. (An environment variable might be an easy way to do this.)

@harlanhaskins
Copy link
Collaborator

Is it reliable to check if Process.arguments[0].lowercased() == "swift"?

@belkadan
Copy link
Contributor Author

belkadan commented Apr 4, 2016

It isn't, unfortunately. Script mode sets Process.arguments[0] to the name of the script. Since this is for an internal tool, though, it doesn't have to be clean; maybe it's good enough to check if the string ends with ".swift"?

@belkadan
Copy link
Contributor Author

belkadan commented Apr 4, 2016

Note that "the interpreter" is different from "the integrated REPL" (and definitely different from "the real, LLDB-provided REPL"). The mode I'm referring to is swift foo.swift.

@harlanhaskins
Copy link
Collaborator

Wait, shouldn't --stdlib-unittest-in-process imply skipping crash tests? Or should there be an explicit, separate option?

@belkadan
Copy link
Contributor Author

belkadan commented Apr 4, 2016

That's a good @gribozavr question, but I think that's the flag that says "yes, please crash; the parent process will pick it up". But we also want to do this without extra options, so that we don't have to change the RUN lines between compile/run and interpret builds.

@harlanhaskins
Copy link
Collaborator

I think the argument you're thinking of is --stdlib-unittest-run-child but I definitely understand wanting it to Just Work™. I'll try some things out. Thanks!

@gribozavr
Copy link
Collaborator

The way I imagined we would run tests in the interpreter is by teaching StdlibUnittest to run the subprocess with the interpreter correctly. Then everything will just work.

> Wait, shouldn't --stdlib-unittest-in-process imply skipping crash tests?

I'd say no. This option is very useful for running individual tests under the debugger, so it shouldn't disable tests by itself.

@harlanhaskins
Copy link
Collaborator

I agree, that makes more sense. However, I can't seem to find any way of knowing the interpreter path at runtime. I've looked all over.

Would this be a case for an environment variable like SWIFT_INVOCATION so we could maybe use that inside spawnChild?

    var pid: pid_t = -1
    var childArgs = [Process.arguments[0]] + args
    if let invocation = String(cString: getenv("SWIFT_INVOCATION")) {
      childArgs.insert(invocation, at: 0)
    }
    let spawnResult = withArrayOfCStrings(childArgs) { //... }

@gribozavr
Copy link
Collaborator

I thought the interpreter path is visible through argv[0]. If it is not, I don't mind an environment variable. I'd call it SWIFT_INTERPRETER though.

@harlanhaskins
Copy link
Collaborator

Unfortunately, argv[0] is just the filename of the test.

Should that invocation variable come from lit? Or how should it be set?

@harlanhaskins
Copy link
Collaborator

How about a #interpreter directive? 😉

@belkadan
Copy link
Contributor Author

belkadan commented Apr 4, 2016

I'd rather not have to go through swift-evolution to enable more tests. ;-)

@gribozavr
Copy link
Collaborator

Yes, the variable should be set by lit.

Re: #interpreter – let's not do language design 🙂

@harlanhaskins
Copy link
Collaborator

Well, what if we set the variable in Immediate.cpp:swift::RunImmediately? It gets the command line as a parameter, and would allow running one-off tests outside of lit.

@gribozavr
Copy link
Collaborator

That would change the compiler's behavior.

StdlibUnittest could include the environment variable into the command line that it suggests for debugging.

@harlanhaskins
Copy link
Collaborator

Ah, right. Didn't realize that was necessarily off-limits. 👍

@belkadan
Copy link
Contributor Author

belkadan commented Jun 9, 2016

Done? Great! But when?

@harlanhaskins
Copy link
Collaborator

Actually months ago, haha

d307e31

@belkadan
Copy link
Contributor Author

belkadan commented Jun 9, 2016

Ah, I missed this. Cool!

@belkadan
Copy link
Contributor Author

belkadan commented Jun 9, 2016

It doesn't work.

../llvm/utils/lit/lit.py -sv ../build/ninja/swift-macosx-x86_64/test-macosx-x86_64/1_stdlib --param interpret

(lots of crashes)

@harlanhaskins
Copy link
Collaborator

Hmm...this worked when I tried it in April. It's supposed to invoke a sub-interpreter when crashes are expected.

I'll investigate again...

@harlanhaskins
Copy link
Collaborator

So this specific issue is working correctly, but there are many test failures when running in the interpreter because of invariants that the interpreter doesn't satisfy.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement standard library Area: Standard library umbrella
Projects
None yet
Development

No branches or pull requests

3 participants