swiftlang / swift-corelibs-xctest

The XCTest Project, A Swift core library for providing unit test support
swift.org
Apache License 2.0
1.15k stars 267 forks source link

Add support for WASI platform #478

Closed kateinoigakukun closed 8 months ago

kateinoigakukun commented 8 months ago

WASI does not have thread spawning method yet, but the existing implementation blocks threads to wait async test cases synchronously. This commit introduced a new waiter method for running async test cases in single-threaded WASI environments, enabled by USE_SWIFT_CONCURRENCY_WAITER flag.

With the new waiter, XCTMain is async runs the given test suites without blocking the thread by bypassing some synchronous public APIs like XCTest.perform and XCTest.run. This ignores those APIs even if they are overridden by user-defined subclasses, so it's not 100% compatible with the existing XCTest APIs. This is a trade-off to support async test execution in single-threaded environments, but it should be fine because the APIs are seldom overridden by user code.

kateinoigakukun commented 8 months ago

@swift-ci test

MaxDesiatov commented 8 months ago

@swift-ci test macos

kateinoigakukun commented 8 months ago

@MaxDesiatov macOS build for corelibs-xctest has been broken for a while unfortunately...

kateinoigakukun commented 8 months ago

@stmontgomery If we can get this merged before the next branch cut, it would be appreciated because this patch is the last difference from the fork. Most of the changes are guarded by a macro and should not affect other platforms. :bow:

kateinoigakukun commented 8 months ago

I wish there were a way to achieve this with less branching, but without reasync support in the compiler, I doubt we can do much better.

Yeah, that's a very unfortunate situation to have many branching here due to function-colors. I agree that we can improve it with reasync support in the future.

Besides the details of the code changes in the PR, I'm interested in learning more about the plans for ongoing support and maintenance of this compilation mode and platform. In particular, what kind of CI and testing is in place, or expected to come in the near future?

Yes, at least I'm going to include XCTest and Foundation build in the WebAssembly build CI after this will get merged: https://ci.swift.org/job/oss-swift-pr-test-crosscompile-wasm-ubuntu-20_04/

Also, as you mentioned, we can build and run tests with this mode on other platforms.

kateinoigakukun commented 8 months ago

@swift-ci test

kateinoigakukun commented 8 months ago

@swift-ci test

briancroom commented 8 months ago

Let’s take a good look at CI results, but the diff looks ok to me now! Thanks for discussing and the quick turnaround on the revisions.

MaxDesiatov commented 8 months ago

@swift-ci test windows

kateinoigakukun commented 8 months ago
kateinoigakukun commented 8 months ago

Thanks a lot for your review @briancroom! I assume we need @shahmishal's help to get this merged by temporarily bypassing PR status check, right?

kkebo commented 8 months ago

This change might have broken some tests especially if there are many test cases. (I'm sorry if I was wrong.)

kateinoigakukun commented 8 months ago

@kkk669 Yes, the implementation is changed from the version used in the downstream, so some of large async test cases might not work. It will be mitigated after tail-call support.