-
Notifications
You must be signed in to change notification settings - Fork 33
Launch emulator in signal-isolated process on Unix to survive Ctrl+C #361
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
Open
Copilot
wants to merge
4
commits into
main
Choose a base branch
from
copilot/fix-ctrl-c-emulator-closure
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+82
−6
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,8 +97,6 @@ public void LaunchEmulator_ThrowsOnWhitespaceAvdName () | |
| Assert.Throws<ArgumentException> (() => runner.LaunchEmulator (" ")); | ||
| } | ||
|
|
||
| // --- BootEmulatorAsync tests (ported from dotnet/android BootAndroidEmulatorTests) --- | ||
|
|
||
| [Test] | ||
| public async Task AlreadyOnlineDevice_PassesThrough () | ||
| { | ||
|
|
@@ -205,7 +203,7 @@ public async Task LaunchFailure_ReturnsError () | |
| var result = await runner.BootEmulatorAsync ("Pixel_7_API_35", mockAdb, options); | ||
|
|
||
| Assert.IsFalse (result.Success); | ||
| Assert.That (result.ErrorMessage, Does.Contain ("Failed to launch")); | ||
| Assert.AreEqual (EmulatorBootErrorKind.LaunchFailed, result.ErrorKind); | ||
| } | ||
|
|
||
| [Test] | ||
|
|
@@ -295,8 +293,6 @@ public async Task MultipleEmulators_FindsCorrectAvd () | |
| Assert.AreEqual ("emulator-5556", result.Serial, "Should find the correct AVD among multiple emulators"); | ||
| } | ||
|
|
||
| // --- Tests ported from dotnet/android BootAndroidEmulatorTests --- | ||
|
|
||
| [Test] | ||
| public async Task AlreadyOnlinePhysicalDevice_PassesThrough () | ||
| { | ||
|
|
@@ -480,6 +476,36 @@ public void BootEmulatorAsync_EmptyDeviceName_Throws () | |
| runner.BootEmulatorAsync ("", mockAdb)); | ||
| } | ||
|
|
||
| [Test] | ||
| [Platform ("Linux,MacOsX")] | ||
| public void LaunchEmulator_SurvivesSigint () | ||
|
jonathanpeppers marked this conversation as resolved.
Comment on lines
+479
to
+481
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| { | ||
| var (tempDir, emuPath) = CreateFakeEmulatorSdk (); | ||
| Process? process = null; | ||
| try { | ||
| var runner = new EmulatorRunner (emuPath); | ||
| process = runner.LaunchEmulator ("TestAVD"); | ||
|
|
||
| Assert.IsFalse (process.HasExited, "Process should be running after launch"); | ||
|
|
||
| // Send SIGINT to the emulator process | ||
| var killPsi = ProcessUtils.CreateProcessStartInfo ("kill", "-INT", process.Id.ToString ()); | ||
| using var kill = new Process { StartInfo = killPsi }; | ||
| kill.Start (); | ||
| Assert.IsTrue (kill.WaitForExit (5000), "kill command should exit promptly"); | ||
| Assert.AreEqual (0, kill.ExitCode, "kill -INT should succeed"); | ||
|
|
||
| // Give the signal a moment to be delivered | ||
| Thread.Sleep (500); | ||
|
|
||
| Assert.IsFalse (process.HasExited, "Emulator process should survive SIGINT"); | ||
| } finally { | ||
| try { process?.Kill (); process?.WaitForExit (5000); } catch { } | ||
| process?.Dispose (); | ||
| Directory.Delete (tempDir, true); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task InvalidEmulatorBinary_ReturnsLaunchFailed () | ||
| { | ||
|
|
@@ -512,6 +538,35 @@ public async Task InvalidEmulatorBinary_ReturnsLaunchFailed () | |
| } | ||
| } | ||
|
|
||
| [Test] | ||
| [Platform ("Linux,MacOsX")] | ||
| public void ShellQuote_EscapesSingleQuotes () | ||
| { | ||
| var tempDir = Path.Combine (Path.GetTempPath (), $"emu-quote-test-{Path.GetRandomFileName ()}"); | ||
| var emulatorDir = Path.Combine (tempDir, "emu'dir"); | ||
| Directory.CreateDirectory (emulatorDir); | ||
|
|
||
| var emuPath = Path.Combine (emulatorDir, "emulator"); | ||
| File.WriteAllText (emuPath, "#!/bin/sh\nsleep 60\n"); | ||
| var psi = ProcessUtils.CreateProcessStartInfo ("chmod", "+x", emuPath); | ||
| using (var chmod = new Process { StartInfo = psi }) { | ||
| chmod.Start (); | ||
| Assert.IsTrue (chmod.WaitForExit (5000), "chmod should exit promptly"); | ||
| } | ||
|
|
||
| Process? process = null; | ||
| try { | ||
| var runner = new EmulatorRunner (emuPath); | ||
| process = runner.LaunchEmulator ("TestAVD"); | ||
|
|
||
| Assert.IsFalse (process.HasExited, "Process should start even with single-quote in path"); | ||
| } finally { | ||
| try { process?.Kill (); process?.WaitForExit (5000); } catch { } | ||
| process?.Dispose (); | ||
| Directory.Delete (tempDir, true); | ||
| } | ||
| } | ||
|
|
||
| // --- Helpers --- | ||
|
|
||
| static (string tempDir, string emulatorPath) CreateFakeEmulatorSdk () | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.

Uh oh!
There was an error while loading. Please reload this page.