Skip to content
Closed
Show file tree
Hide file tree
Changes from 48 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
af9ace6
test(cmux-next): a stop of the main run loop no longer ends the swift…
teamleaderleo Oct 28, 2026
672f097
ci(cmux-next): the WebKit video page tests run in their own Swift tes…
teamleaderleo Oct 28, 2026
5b2efa0
ci: register the Swift test main-thread isolation guard in the test e…
teamleaderleo Oct 28, 2026
99a3b99
ci(cmux-next): frame benchmarks join the WebKit video tests in their …
teamleaderleo Oct 28, 2026
aebba32
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 28, 2026
96abf30
test(cmux-next): the main-run-loop stop test waits on a run-loop bloc…
teamleaderleo Oct 28, 2026
14ae572
cmux-next swift test: derive the main-thread-heavy suites from the te…
teamleaderleo Oct 28, 2026
e3333b4
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 28, 2026
acc2f5a
cmux-next swift test: one process per main-thread-heavy suite, and a …
teamleaderleo Oct 28, 2026
2ebfb48
Window census: read needsLayout from the content view (NSWindow has n…
teamleaderleo Oct 28, 2026
096d894
main-thread-heavy suites: a nested helper type is never read as a suite
teamleaderleo Oct 28, 2026
5c71899
cmux-next swift test: the broad pass runs as several test processes; …
teamleaderleo Oct 28, 2026
584734e
cmux-next swift test: commit the shard wiring, heavy-suite routing an…
teamleaderleo Oct 28, 2026
351e9b3
Run-loop guard without blocks; register script modules before loading…
teamleaderleo Oct 28, 2026
3186630
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 28, 2026
2c051d4
Swift test shards: the CmuxNextAppTests Cloud suites run in a shard o…
teamleaderleo Oct 28, 2026
1195376
Swift test shards: one SwiftPM start at a time, and a shard that lost…
teamleaderleo Oct 28, 2026
e847f94
cmux-next swift test: leave the run-loop guard to #25861
teamleaderleo Oct 28, 2026
4400dfa
cmux-next tests: the test process catches SIGPIPE as the app does
teamleaderleo Oct 28, 2026
08aab38
cmux-next tests: shorter signal-policy note
teamleaderleo Oct 28, 2026
80b0037
cmux-next tests: export the signal-policy header through the umbrella…
teamleaderleo Oct 28, 2026
6f2f6c9
cmux-next swift test: count nonisolated suites, split long shared pre…
teamleaderleo Oct 28, 2026
1a80ae3
cmux-next swift test: no new CI guard steps; the SIGPIPE test proves …
teamleaderleo Oct 28, 2026
aa84002
cmux-next tests: the SIGPIPE tests read no live process-wide disposition
teamleaderleo Oct 29, 2026
7554914
ci guards: the two manual swift-test guards are listed as unwired on …
teamleaderleo Oct 29, 2026
f12d543
Merge branch 'feat-cmux-next' into swift-cutshort-root
teamleaderleo Oct 29, 2026
1a5ed0e
Merge branch 'feat-cmux-next' into swift-cutshort-root
teamleaderleo Oct 29, 2026
183e0d1
test: read errno into a local before asserting in TestProcessSignalTests
teamleaderleo Oct 29, 2026
42e11c2
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 29, 2026
a71d470
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 29, 2026
456390c
Merge origin/feat-cmux-next into swift-cutshort-root
teamleaderleo Oct 29, 2026
825cea7
Merge origin/feat-cmux-next into swift-cutshort-root (takes #27385's …
teamleaderleo Oct 29, 2026
3727a9c
cmux-next swift test: layout and huge-upgrade suites in the heavy ste…
teamleaderleo Oct 29, 2026
e3c31bf
Merge origin/feat-cmux-next into swift-cutshort-root (takes #27436's …
teamleaderleo Oct 29, 2026
88a4d83
EXPERIMENT cmux-next swift test: broad-pass shards one test at a time…
teamleaderleo Oct 29, 2026
3e086d5
cmux-next swift test: one test at a time inside each broad-pass shard
teamleaderleo Oct 29, 2026
fc2799c
Merge origin/feat-cmux-next into swift-cutshort-root
teamleaderleo Oct 29, 2026
aaa0aaf
cmux-next swift test: three suites that fail only in a shared process…
teamleaderleo Oct 29, 2026
b4eff05
cmux-next swift test: no mid-job same-tree fetch; WindowScreenshotTes…
teamleaderleo Oct 29, 2026
13a759a
cmux-next swift test: resolve the same-tree cmux-tui once for the bro…
teamleaderleo Oct 29, 2026
b6dc762
WindowScreenshotTests: wait for the whole frame before reading pixels
teamleaderleo Oct 29, 2026
ca7a9d3
WindowScreenshotTests: the crop test checks its full image too
teamleaderleo Oct 30, 2026
bf641d4
checks workflow test: the swift test job may read the tree's path, ne…
teamleaderleo Oct 30, 2026
dc7c331
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 30, 2026
c6e3f76
swift-test-shards: count a free @Test function under its own name
teamleaderleo Oct 30, 2026
cbe64e8
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 30, 2026
764e79d
Merge branch 'feat-cmux-next' into swift-cutshort-root
teamleaderleo Oct 30, 2026
a897616
Merge branch 'feat-cmux-next' into swift-cutshort-root
teamleaderleo Oct 30, 2026
84121af
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 30, 2026
4d5237b
cmux-next swift test: wall-clock suites get their own process; masked…
teamleaderleo Oct 30, 2026
5a39be4
Merge branch 'feat-cmux-next' into swift-cutshort-root
teamleaderleo Oct 30, 2026
b42d88b
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 31, 2026
b777afc
Merge remote-tracking branch 'origin/feat-cmux-next' into swift-cutsh…
teamleaderleo Oct 31, 2026
88f39a8
Merge branch 'feat-cmux-next' into swift-cutshort-root
cmux-bot[bot] Oct 31, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 103 additions & 18 deletions .github/workflows/cmux-next.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3036,8 +3036,10 @@ jobs:
# A cold build of the package graph (CmuxNext plus its Shared and iOS test
# dependencies) and the selected suites. Admission (up to 20 min), cache
# restore (~7 min) and the build (~6 min) used most of 60 before a full
# broad pass (~860 s on a slow mini) ran, so 90.
timeout-minutes: 90
# broad pass (~860 s on a slow mini) ran, so 90; the main-thread-heavy
# suites' serial step (up to 60 min, out of the broad pass since #26809)
# makes it 135.
timeout-minutes: 135
outputs:
# The folded generated files verdict (generated-verdict reads it): fresh, stale or empty. A
# reused pass of a folded run was recorded only with the generated files fresh.
Expand Down Expand Up @@ -3318,6 +3320,20 @@ jobs:
working-directory: Packages/macOS/CmuxNext
run: ../../../scripts/cmux-next/compile-string-catalogs.sh

# The suites of the selected targets that drive the main thread for long
# stretches (Core Animation frame commits, real WebKit downloads), read
# from the test sources: the changed-suites pass and the broad pass skip
# them and a step of their own runs them, each in a fresh process.
- name: Find the main-thread-heavy suites
if: ${{ (env.SWIFT_TARGETS != '') && steps.reuse.outputs.hit != 'true' }}
run: |
set -euo pipefail
heavy="$(python3 scripts/cmux-next/main-thread-heavy-suites.py Packages/macOS/CmuxNext/Tests --targets "$SWIFT_TARGETS")"
echo "CMUX_NEXT_MAIN_THREAD_HEAVY=$heavy" >> "$GITHUB_ENV"
suites="$(python3 scripts/cmux-next/main-thread-heavy-suites.py Packages/macOS/CmuxNext/Tests --targets "$SWIFT_TARGETS" --list)"
echo "CMUX_NEXT_MAIN_THREAD_HEAVY_SUITES=${suites//$'\n'/ }" >> "$GITHUB_ENV"
while read -r suite; do [[ -z "$suite" ]] || echo "main-thread heavy: $suite"; done <<< "$suites"

# Samples and fails a run still going after 15 minutes, so a hang shows
# its stacks; each test step timeout stops it holding the runner regardless.
# Control tests use tight request deadlines and run in their own process so
Expand All @@ -3332,40 +3348,70 @@ jobs:
# hang ends in ~5 min; this only caps a slow healthy pass (~860 s).
# Both passes share one deadline below the step's 30 minutes.
CMUX_NEXT_TEST_HANG_SECONDS: "1500"
# At most 6 Swift Testing tests run at once. A test's time limit
# counts from its start, and Swift Testing otherwise starts all
# ~5,900 at once: on a mini shared with Xcode compiles, tests used
# their 60 s waiting for the main actor (18 to 73 time-limit
# failures per push run; 0 on an idle worker, where width 6 costs
# 117 s -> 141 s). Xcode 26.6's Swift Testing reads this variable.
SWT_EXPERIMENTAL_MAXIMUM_PARALLELIZATION_WIDTH: "6"
# One Swift Testing test at a time inside each shard process; the
# shards themselves run side by side (swift-test-shards.py). A test's
# time limit counts from its start, and Swift Testing otherwise starts
# all ~5,900 at once (width 6 here before #26809). With 6 at once in
# each of 3 shards, suites that pass alone at the base went red only
# in shards: WorkspaceGroupPinLive, ClickedLinkFocus,
# BrowserEngineStateRestore, RapidWorkspaceCreate,
# WorkspaceHoverCardScroll, MarkdownTableWidthMemory (run
# 40896449485); at 1 at once all six passed (run 40906115871), and
# the pass took 9.5 min against 8.1.
SWT_EXPERIMENTAL_MAXIMUM_PARALLELIZATION_WIDTH: "1"
run: |
set -euo pipefail
echo "Test targets: $SWIFT_TARGETS"
# One deadline for both passes, 2 min inside the step timeout, so a pass
# hung before any test starts is still sampled and reported.
deadline=$(( $(date +%s) + 1680 ))
filter=()
[[ -z "$SWIFT_FILTER" ]] || filter=(--filter "$SWIFT_FILTER")
# The heavy suites only ever run in their own step: never --skip "" (an
# empty pattern matches, and so skips, every test).
heavy_skip=()
[[ -z "$CMUX_NEXT_MAIN_THREAD_HEAVY" ]] || heavy_skip=(--skip "$CMUX_NEXT_MAIN_THREAD_HEAVY")
priority_skip=()
priority_status=0
if [[ -n "$SWIFT_PRIORITY_FILTER" ]]; then
echo "Changed Swift suites first: $SWIFT_PRIORITY_FILTER"
if ../../../scripts/cmux-next/swift-test-with-hang-sampler.sh --skip-build --no-parallel --filter "$SWIFT_PRIORITY_FILTER"; then
if ../../../scripts/cmux-next/swift-test-with-hang-sampler.sh --skip-build --no-parallel --filter "$SWIFT_PRIORITY_FILTER" \
${heavy_skip[@]+"${heavy_skip[@]}"}; then
:
else
priority_status=$?
echo "Changed Swift suite shard failed with status $priority_status; continuing with the selected target pass" >&2
fi
priority_skip=(--skip "$SWIFT_PRIORITY_FILTER")
fi
# The selected targets as several test processes at once, split by
# target and suite prefix (scripts/cmux-next/swift-test-shards.py), as
# many at a time as the runner's cores and memory hold. One process ran
# them all before: ~6,300 tests queued on its one main thread and the
# windows they left open piled up (3 -> 428), so throughput fell from
# ~2,000 to ~100 tests a minute and the pass hit its limit with 466
# tests unfinished (#26809, run 40705037968).
# The same-tree cmux-tui as it is when the broad pass starts, the same
# for every shard. In the one shared process the base runs, the
# live-daemon suites read the tree once, early, before any
# CmuxNextDaemonTests suite could fetch it (RealBinary.sameTree), so
# they ran only when the tree was already here (after the
# changed-suites pass fetched it, say) and skipped otherwise. As
# shards, those that started after a fetch ran them and the rest
# skipped (run 40932106119: 87 skipped, 315 on the base). Resolved
# once here, a missing tree is a path that is never a file: no shard
# fetches it, and every live-daemon suite skips as on the base. The
# daemon tests job fetches the tree and runs the daemon suites.
tree_path="$(../../../scripts/cmux-next/pin-cmux-tui.sh path 2>/dev/null)" || tree_path=""
if [[ -n "$tree_path" && -x "$tree_path" ]]; then
echo "Broad pass same-tree cmux-tui: $tree_path"
else
echo "Broad pass same-tree cmux-tui: not here yet; the live-daemon suites skip"
tree_path=/dev/null/no-same-tree-here
fi
broad_status=0
left=$(( deadline - $(date +%s) ))
(( left >= 60 )) || left=60
(( left <= CMUX_NEXT_TEST_HANG_SECONDS )) || left=$CMUX_NEXT_TEST_HANG_SECONDS
if CMUX_NEXT_TEST_HANG_SECONDS="$left" ../../../scripts/cmux-next/swift-test-with-hang-sampler.sh --skip-build ${filter[@]+"${filter[@]}"} \
${priority_skip[@]+"${priority_skip[@]}"} --skip CmuxNextControlTests --skip BranchStateResourcesTests --skip CloudBringBackTests \
--skip CommitBoundaryAppKitTests; then
if CMUX_NEXT_TUI_TREE_PATH="$tree_path" python3 ../../../scripts/cmux-next/swift-test-shards.py run --targets "$SWIFT_TARGETS" \
--exclude CmuxNextControlTests --wrapper ../../../scripts/cmux-next/swift-test-with-hang-sampler.sh \
--deadline "$deadline" -- ${priority_skip[@]+"${priority_skip[@]}"} --skip BranchStateResourcesTests \
--skip CloudBringBackTests --skip CommitBoundaryAppKitTests ${heavy_skip[@]+"${heavy_skip[@]}"}; then
:
else
broad_status=$?
Expand Down Expand Up @@ -3421,6 +3467,45 @@ jobs:
CMUX_NEXT_TEST_HANG_SECONDS: "300"
run: ../../../scripts/cmux-next/swift-test-with-hang-sampler.sh --skip-build --no-parallel --filter CommitBoundaryAppKitTests

# Suites that hold the test process's main thread for minutes when they
# share it (scripts/cmux-next/main-thread-heavy-suites.py says which),
# run in their own process, one test at a time. Each Core Animation
# commit lays out every window the process holds: in the shared pass
# SidebarHugeGroupTests' oneGroup10k (about 1 s alone) and
# SidebarLagTests held the main thread for 5 to 11+ minutes, and
# RemoteVideoPageTests' WebKit downloads held it in a kernel call
# (SandboxExtension::createHandle -> __mac_syscall) for 300+ s. Every
# main-actor test beside them stalled or failed on timing, and the stuck
# watchdog killed the run with hundreds of tests unfinished (#26809's
# runs 40660100939, 40677563234 and 40683540650). Each suite gets a fresh
# process: in one shared serial process the windows earlier gallery
# suites left open made SidebarScrollCostTests' 500-row scroll take 300+
# s and the stuck watchdog ended the step (run 40693598261). A hang or a
# red here is this step's red, and every suite still runs. Each suite's
# watchdog limits come from main-thread-heavy-suites.py --runs: 600 s for
# the run and 300 s with no test finished, or above the suite's own
# `.timeLimit` (ClassicUpgradeHugeSimulationTests: 15 min, so 1200 s and
# 1020 s; it took 412 s alone and one test was open 572 s in a shard).
- name: Run main-thread-heavy suites in their own process
if: ${{ (!cancelled() && steps.build-tests.outcome == 'success' && env.CMUX_NEXT_MAIN_THREAD_HEAVY != '') && steps.reuse.outputs.hit != 'true' }}
timeout-minutes: 60
working-directory: Packages/macOS/CmuxNext
run: |
set -uo pipefail
status=0
runs="$(python3 ../../../scripts/cmux-next/main-thread-heavy-suites.py Tests --targets "$SWIFT_TARGETS" --runs)" || exit 1
while read -r suite hang stuck; do
[[ -n "$suite" ]] || continue
echo "::group::$suite (run limit ${hang} s, stuck limit ${stuck} s)"
if ! CMUX_NEXT_TEST_HANG_SECONDS="$hang" CMUX_NEXT_TEST_STUCK_SECONDS="$stuck" \
../../../scripts/cmux-next/swift-test-with-hang-sampler.sh --skip-build --no-parallel --filter "${suite//./\\.}\\b" < /dev/null; then
status=1
echo "::error title=main-thread-heavy suite red::$suite"
fi
echo "::endgroup::"
done <<< "$runs"
exit "$status"

# Each isolated step below runs when its suites' target is selected and
# the build succeeded, even after a failed test step, so one red step
# does not hide the others.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import Testing
/// (`scripts/cmux-next/pin-cmux-tui.sh fetch`; `path` names it).
nonisolated enum SameTreeDaemonBinary {
static let url: URL? = {
// A CI lane that resolved (and fetched) the tree once names it here.
if let path = ProcessInfo.processInfo.environment["CMUX_NEXT_TUI_TREE_PATH"], !path.isEmpty,
FileManager.default.isExecutableFile(atPath: path) {
return URL(fileURLWithPath: path)
// A CI lane that resolved (and fetched) the tree once names it here. A path that is no
// binary means the lane looked and has none (run-swift-testing-suites.sh exports the path
// even after a failed fetch; the swift test job's broad pass sets one that is never a file):
// the suites skip and nothing looks again, as RealBinary.sameTree and LiveBinary do.
if let path = ProcessInfo.processInfo.environment["CMUX_NEXT_TUI_TREE_PATH"], !path.isEmpty {
return FileManager.default.isExecutableFile(atPath: path) ? URL(fileURLWithPath: path) : nil
}
var root = URL(fileURLWithPath: #filePath)
for _ in 0..<6 { root.deleteLastPathComponent() }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import CmuxNextTestExitTrace
import Darwin
import Testing

/// The test process takes the app's SIGPIPE policy (ChildSignalDefaults.installAppSignalPolicy):
/// a write to a pipe whose reader is gone fails with EPIPE instead of ending every test in the
/// process (an AgentPane shard died on signal 13 with 19 tests never finished, 2026-10-28).
///
/// SIGPIPE's disposition is process-wide and other suites change it while they run
/// (ChiefAdoptionLiveWriterTests sets SIG_IGN), so these tests never read or send it live: the
/// install is checked when the bundle loads, before any test, and the handler is called directly.
struct TestProcessSignalTests {
@Test func theBundleCatchesSIGPIPEFromTheMomentItLoads() {
#expect(cmux_next_test_signal_policy_installed_at_load() == 1)
}

@Test func theInstalledDispositionIsTheBundlesHandlerNotIgnoreOrDefault() {
var action = sigaction()
cmux_next_test_signal_policy_action(&action)
#expect(cmux_next_test_signal_policy_is_handler(&action) == 1)
// SIG_DFL is the handler value 0 and SIG_IGN is 1 (<sys/signal.h>).
let handler = unsafeBitCast(action.__sigaction_u, to: Int.self)
#expect(handler != 0 && handler != 1)
#expect(action.sa_flags & SA_RESTART != 0)
var ignore = sigaction()
ignore.__sigaction_u.__sa_handler = SIG_IGN
#expect(cmux_next_test_signal_policy_is_handler(&ignore) == 0)
}

@Test func aCaughtSIGPIPEIsCountedAndLeavesErrnoAsItWas() {
let before = cmux_next_test_sigpipes()
errno = EPIPE
cmux_next_test_sigpipe_handle()
let after = errno
#expect(after == EPIPE)
#expect(cmux_next_test_sigpipes() >= before + 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,17 +121,28 @@ import CmuxNextDesignTokens
pixel.green > 180 && pixel.red < 90 && pixel.blue < 90 && pixel.alpha > 200
}

/// Captures with `capture` until the Metal frame shows (the window
/// server composites a presented drawable on its next frame), bounded.
/// Captures with `capture` until the window's whole frame shows (the
/// window server composites a new window, and a presented drawable, on
/// a later frame), bounded. Until then a capture can be all transparent,
/// which `screenshotImage` throws as `.blank`, or show only part of the
/// Metal layer: on a CI mini, in a test process with no window before
/// this one, the first capture threw `.blank` (0.37 s into the test) and
/// a crop's corner came out transparent while its center was red (#26809).
/// The last capture runs outside the loop and is returned unchecked: a
/// window that never shows still fails, with that capture's own error or
/// in the caller's `expectWindowPixels`, which every test runs on it.
private func settledImage(_ fixture: Fixture, _ capture: () async throws -> CGImage?) async throws -> CGImage? {
let deadline = ContinuousClock.now + .seconds(5)
var last: CGImage?
let size = fixture.window.frame.size
let corner = fixture.metal.convert(CGPoint(x: 2, y: 2), to: nil)
repeat {
last = try await capture()
if let last, isRed(pixel(last, at: CGPoint(x: 180, y: 60), size: fixture.window.frame.size)) { return last }
if let image = try? await capture(), isRed(pixel(image, at: CGPoint(x: 180, y: 60), size: size)),
isRed(pixel(image, at: corner, size: size)), isGreen(pixel(image, at: CGPoint(x: 60, y: 60), size: size)) {
return image
}
try await Task.sleep(for: .milliseconds(50))
} while ContinuousClock.now < deadline
return last
return try await capture()
}

/// `exactSize`: the image is frame x backing scale pixels (the
Expand Down Expand Up @@ -190,6 +201,8 @@ import CmuxNextDesignTokens
defer { fixture.close() }
let window = fixture.window
let full = try #require(try await settledImage(fixture) { try await window.screenshotImage() })
// The whole image first, as the other paths check theirs: a crop of a wrong image proves nothing.
try expectWindowPixels(full, fixture, path: "screenshotImage")
let rect = fixture.metal.convert(fixture.metal.bounds, to: nil)
let crop = try #require(full.cropped(toWindowRect: rect, windowSize: window.frame.size))
#expect(crop.width == Int((rect.width * window.backingScaleFactor).rounded()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// A shard's test process died on signal 13 with 19 tests never finished (2026-10-28): a write to
// a pipe whose reader was gone. The app catches SIGPIPE at launch
// (ChildSignalDefaults.installAppSignalPolicy), so there the write fails with EPIPE; the test
// process never ran that step. The bundle takes the same policy when it loads (exec resets it in
// children). The handler calls only async-signal-safe functions (write(2) and a lock-free atomic):
// a stack print (backtrace, backtrace_symbols_fd) can take locks the interrupted thread holds and
// deadlock. The note lands beside the writing test's own "started" line in the log.
#include "CmuxNextTestSignalPolicy.h"

#include <errno.h>
#include <signal.h>
#include <stdatomic.h>
#include <string.h>
#include <unistd.h>

static _Atomic long sigpipes;

static void sigpipe_caught(int signal) {
(void)signal;
int saved = errno;
if (atomic_fetch_add(&sigpipes, 1) < 3) {
static const char note[] =
"cmux-next test process: SIGPIPE caught (a write to a closed pipe or socket; it fails with EPIPE, as in the app)\n";
(void)write(STDERR_FILENO, note, sizeof note - 1);
}
errno = saved;
}

void cmux_next_test_signal_policy_action(struct sigaction *action) {
memset(action, 0, sizeof *action);
action->sa_handler = sigpipe_caught;
action->sa_flags = SA_RESTART;
sigemptyset(&action->sa_mask);
}

int cmux_next_test_signal_policy_is_handler(const struct sigaction *action) {
return action->sa_handler == sigpipe_caught;
}

void cmux_next_test_sigpipe_handle(void) {
sigpipe_caught(SIGPIPE);
}

static int installed_at_load;

// Runs when the bundle loads, before any test: no test can change SIGPIPE between the install and the check.
__attribute__((constructor)) static void cmux_next_test_signal_policy_load(void) {
struct sigaction action, current;
cmux_next_test_signal_policy_action(&action);
sigaction(SIGPIPE, &action, NULL);
installed_at_load = sigaction(SIGPIPE, NULL, &current) == 0 && cmux_next_test_signal_policy_is_handler(&current);
}

int cmux_next_test_signal_policy_installed_at_load(void) {
return installed_at_load;
}

long cmux_next_test_sigpipes(void) {
return atomic_load(&sigpipes);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef CMUX_NEXT_TEST_EXIT_TRACE_H
#define CMUX_NEXT_TEST_EXIT_TRACE_H
#include "CmuxNextTestSignalPolicy.h" // SwiftPM exports only this umbrella header

/// 1 once the test process's exit() prints its stack (installed when the test bundle loads).
int cmux_next_test_exit_trace_installed(void);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef CMUX_NEXT_TEST_SIGNAL_POLICY_H
#define CMUX_NEXT_TEST_SIGNAL_POLICY_H

#include <signal.h>

/// SIGPIPEs the bundle's handler caught (each one a write to a closed pipe or socket that failed with
/// EPIPE instead of ending the run).
long cmux_next_test_sigpipes(void);

/// Fills `action` with the disposition the bundle installs for SIGPIPE when it loads.
void cmux_next_test_signal_policy_action(struct sigaction *action);

/// 1 when `action`'s handler is the bundle's own (not SIG_DFL, SIG_IGN or another handler).
int cmux_next_test_signal_policy_is_handler(const struct sigaction *action);

/// Runs the bundle's handler as a delivered SIGPIPE would, with no signal sent.
void cmux_next_test_sigpipe_handle(void);

/// 1 when SIGPIPE's handler was the bundle's own right after the bundle loaded, before any test ran.
int cmux_next_test_signal_policy_installed_at_load(void);

#endif
Loading
Loading