Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(326)

Side by Side Diff: tests/standalone/io/signals_test.dart

Issue 108003009: Signal handling. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up impl and add test. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2013, 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 import "dart:io";
6
7 import "package:expect/expect.dart";
8 import "package:async_helper/async_helper.dart";
9
10 void testSignals(int usr1Expect,
11 int usr2Expect,
12 [int usr1Send,
13 int usr2Send,
14 bool shouldFail = false]) {
15 if (usr1Send == null) usr1Send = usr1Expect;
16 if (usr2Send == null) usr2Send = usr2Expect;
17 asyncStart();
18 Process.start(Platform.executable,
19 [Platform.script.resolve('signals_test_script.dart').toFilePath(),
20 usr1Expect.toString(),
21 usr2Expect.toString()])
22 .then((process) {
23 process.stdin.close();
24 process.stderr.drain();
25 int v = 0;
26 process.stdout.listen((out) {
27 int count = out.where((c) => c == 10).length;
Søren Gjesse 2013/12/19 08:51:24 Please change 10 to '\n'.charCodeAt(0) (or make a
Anders Johnsen 2013/12/19 10:54:17 Done.
28 for (int i = 0; i < count; i++) {
29 if (v < usr1Send) {
30 process.kill(ProcessSignal.SIGUSR1);
31 } else if (v < usr1Send + usr2Send) {
32 process.kill(ProcessSignal.SIGUSR2);
33 }
34 v++;
35 }
36 });
37 process.exitCode.then((exitCode) {
38 Expect.equals(shouldFail, exitCode != 0);
39 asyncEnd();
40 });
41 });
42 }
43
44
45 void testListenCancel() {
46 for (int i = 0; i < 10; i++) {
47 ProcessSignal.watch(ProcessSignal.SIGUSR1).listen(null).cancel();
48 }
49 }
50
51 void main() {
52 testListenCancel();
53 if (Platform.isWindows) return;
54 testSignals(0, 0);
55 testSignals(1, 0);
56 testSignals(0, 1);
57 testSignals(1, 1);
58 testSignals(10, 10);
59 testSignals(10, 1);
60 testSignals(1, 10);
61 testSignals(1, 0, 0, 1, true);
62 testSignals(0, 1, 1, 0, true);
63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698