Skip to content

[tests] Add DotNetRunCtrlC integration test#11293

Draft
jonathanpeppers wants to merge 1 commit intomainfrom
jonathanpeppers/ctrl-c-device-test
Draft

[tests] Add DotNetRunCtrlC integration test#11293
jonathanpeppers wants to merge 1 commit intomainfrom
jonathanpeppers/ctrl-c-device-test

Conversation

@jonathanpeppers
Copy link
Copy Markdown
Member

Adds a device integration test that verifies Ctrl+C (SIGINT) sent to dotnet run properly stops the Android app on the device/emulator.

Test flow:

  1. Build and launch an Android app via dotnet run with WaitForExit=true
  2. Wait for app logcat output confirming launch
  3. Verify the app PID exists on the device via adb shell pidof
  4. Send SIGINT via process.SendCtrlC() extension method
  5. Assert the process exits gracefully
  6. Verify Microsoft.Android.Run's Ctrl+C handler ran ("Stopping application...")
  7. Confirm the app is no longer running on the device

Also adds a SendCtrlC() extension method on Process in ProcessExtensions.cs, using libc kill(pid, SIGINT) P/Invoke (Unix/macOS only; throws PlatformNotSupportedException on Windows).

Fixes #11264

@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/ctrl-c-device-test branch 5 times, most recently from c4c574d to f65d066 Compare May 6, 2026 21:58
Add a device integration test that verifies Ctrl+C (SIGINT) sent to
`dotnet run` properly stops the Android app on the device/emulator.

The test:
1. Builds and launches an Android app via `dotnet run` with WaitForExit
2. Waits for app logcat output confirming launch
3. Verifies the app PID exists on the device
4. Sends SIGINT via Process.SendCtrlC() extension method
5. Asserts the process exits gracefully
6. Verifies Microsoft.Android.Run's Ctrl+C handler ran ("Stopping application...")
7. Confirms the app is no longer running on the device

Also adds a `SendCtrlC()` extension method on `Process` in
`ProcessExtensions.cs`. On Unix/macOS, it uses `pgrep` to find all
descendant processes and sends SIGINT to the entire process tree,
simulating what a real terminal Ctrl+C does (SIGINT to the whole
foreground process group). Without this, child processes like
`Microsoft.Android.Run` (launched by `dotnet run` via MSBuild) would
not receive the signal.

Fixes a bug in `Microsoft.Android.Run` where `OperationCanceledException`
from `GetAppPidAsync()` would escape through the top-level catch block
when Ctrl+C was pressed, printing "Error: The operation was canceled."
instead of exiting cleanly.

Fixes: #11264

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jonathanpeppers jonathanpeppers force-pushed the jonathanpeppers/ctrl-c-device-test branch from f65d066 to 996bb8f Compare May 6, 2026 21:59
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.

dotnet run Ctrl+C does not stop the app on the device

1 participant