Skip to content

Commit 70f621e

Browse files
aamCommit Queue
authored andcommitted
[vm/win] Add test for ctrl-c handling on Windows.
Follow-up to 010b696 TEST=ctrlc_handling_test Change-Id: I35ef48037419b7f73aa36008be1f81b40fff3241 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448240 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Ryan Macnak <[email protected]>
1 parent 7e76412 commit 70f621e

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
//
5+
// Tests that on Windows ctrl-c SIGINT is handled by spawned dartvm.exe, parent
6+
// dart.exe does not get in a way.
7+
//
8+
9+
import 'dart:ffi';
10+
import 'dart:io';
11+
12+
import 'package:expect/expect.dart';
13+
14+
final DynamicLibrary kernel32 = DynamicLibrary.open("kernel32.dll");
15+
16+
typedef GenerateConsoleCtrlEventFT = bool Function(int, int);
17+
typedef GenerateConsoleCtrlEventNFT = Bool Function(IntPtr, IntPtr);
18+
19+
const int CTRL_C_EVENT = 0;
20+
21+
final generateConsoleCtrlEvent = kernel32
22+
.lookupFunction<GenerateConsoleCtrlEventNFT, GenerateConsoleCtrlEventFT>(
23+
'GenerateConsoleCtrlEvent',
24+
);
25+
26+
typedef SetConsoleCtrlHandlerFT = bool Function(int, bool);
27+
typedef SetConsoleCtrlHandlerNFT = Bool Function(IntPtr, Bool);
28+
29+
final setConsoleCtrlHandler = kernel32
30+
.lookupFunction<SetConsoleCtrlHandlerNFT, SetConsoleCtrlHandlerFT>(
31+
'SetConsoleCtrlHandler',
32+
);
33+
34+
main(List<String> args) async {
35+
if (!Platform.isWindows) {
36+
return;
37+
}
38+
39+
// Restore ctrl-c handler
40+
setConsoleCtrlHandler(0, false);
41+
42+
if (args.contains("--testee")) {
43+
ProcessSignal.sigint.watch().listen((_) {
44+
print('SIGINT RECEIVED');
45+
exit(0);
46+
});
47+
48+
while (true) {
49+
await Future.delayed(const Duration(seconds: 1));
50+
print('Waiting...');
51+
52+
// Send Ctrl-C to ourselves after 1 second.
53+
generateConsoleCtrlEvent(CTRL_C_EVENT, /*dwProcessGroupId=*/ 0);
54+
}
55+
} else {
56+
var result = await Process.run(Platform.executable, [
57+
...Platform.executableArguments,
58+
Platform.script.toFilePath(),
59+
"--testee",
60+
]);
61+
print("stdout:");
62+
print(result.stdout);
63+
Expect.isTrue(result.stdout.contains("Waiting..."));
64+
Expect.isTrue(result.stdout.contains("SIGINT RECEIVED"));
65+
print("stderr:");
66+
print(result.stderr);
67+
}
68+
}

runtime/tests/vm/vm.status

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ dart/transferable_throws_oom_test: SkipByDesign # Allocating too much memory to
188188
cc/CorelibCompilerStats: Skip
189189
dart/disassemble_determinism_test: Slow, Pass # Times out on slower bots.
190190

191+
[ $system != windows ]
192+
dart/ctrlc_handling_test: SkipByDesign
193+
191194
[ $qemu ]
192195
cc/ManyClasses: Slow, Pass # Generates 100k classes, slow on emulated architectures.
193196
cc/StressMallocDirectly: Skip # Queries RSS

0 commit comments

Comments
 (0)