about summary refs log tree commit homepage
path: root/t
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-02-27 02:14:23 +0000
committerEric Wong <e@80x24.org>2016-02-27 10:58:22 +0000
commitca885bd5905b7faa9ecb7b0eb02476de1d3a7f88 (patch)
treec4ae278dfb6825ae3e80eb4346c80fbab993c99e /t
parent2cc034627726da5c73c88d5ff7a8b136cc9ce759 (diff)
downloadpublic-inbox-ca885bd5905b7faa9ecb7b0eb02476de1d3a7f88.tar.gz
Under Linux, vfork maintains constant performance as
parent process size increases.  fork needs to prepare pages
for copy-on-write, requiring a linear scan of the address
space.
Diffstat (limited to 't')
-rw-r--r--t/spawn.t53
1 files changed, 53 insertions, 0 deletions
diff --git a/t/spawn.t b/t/spawn.t
new file mode 100644
index 00000000..ed9b5b08
--- /dev/null
+++ b/t/spawn.t
@@ -0,0 +1,53 @@
+# Copyright (C) 2015 all contributors <meta@public-inbox.org>
+# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
+use strict;
+use warnings;
+use Test::More;
+use PublicInbox::Spawn qw(which spawn);
+
+{
+        my $true = which('true');
+        ok($true, "'true' command found with which()");
+}
+
+{
+        my $pid = spawn(['true']);
+        ok($pid, 'spawned process');
+        is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
+        is($?, 0, 'true exited successfully');
+}
+
+{
+        my ($r, $w);
+        pipe $r, $w or die "pipe failed: $!";
+        my $pid = spawn(['echo', 'hello world'], undef, { 1 => fileno($w) });
+        close $w or die "close pipe[1] failed: $!";
+        is(<$r>, "hello world\n", 'read stdout of spawned from pipe');
+        is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
+        is($?, 0, 'true exited successfully');
+}
+
+{
+        my ($r, $w);
+        pipe $r, $w or die "pipe failed: $!";
+        my $pid = spawn(['sh', '-c', 'echo $HELLO'],
+                { 'HELLO' => 'world' }, { 1 => fileno($w) });
+        close $w or die "close pipe[1] failed: $!";
+        is(<$r>, "world\n", 'read stdout of spawned from pipe');
+        is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
+        is($?, 0, 'sh exited successfully');
+}
+
+{
+        my ($r, $w);
+        pipe $r, $w or die "pipe failed: $!";
+        my $pid = spawn(['env'], {}, { -env => 1, 1 => fileno($w) });
+        close $w or die "close pipe[1] failed: $!";
+        ok(!defined(<$r>), 'read stdout of spawned from pipe');
+        is(waitpid($pid, 0), $pid, 'waitpid succeeds on spawned process');
+        is($?, 0, 'env(1) exited successfully');
+}
+
+done_testing();
+
+1;