1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
% -*- mode: slang; mode: fold -*-
() = evalfile ("./test.sl");
require ("fork");
private define test_fork ()
{
variable _ppid = getpid ();
variable pid = fork ();
if (pid == 0)
{
% child
if (_ppid == getpid ())
{
() = fprintf (stderr, "fork did not change pid\n");
_exit (1);
}
#ifexists getppid
if (_ppid != getppid ())
{
() = fprintf (stderr, "getppid failed in child\n");
_exit (1);
}
#endif
_exit(123);
}
variable w = waitpid (pid, 0);
if (w.exited)
{
if (w.exit_status != 123)
failed ("child exited with unexpected status of %d", w.exit_status);
}
}
private define test_pipe ()
{
variable fdr, fdw, buf, n;
(fdr, fdw) = pipe ();
while (-1 == write (fdw, "hello"))
{
if (errno == EINTR)
continue;
failed ("write to pipe failed: %S", errno_string);
}
n = read (fdr, &buf, 10);
if ((buf != "hello") || (n != 5))
{
failed ("pipe failed");
}
}
define slsh_main ()
{
testing_module ("fork");
test_fork ();
test_pipe ();
%test_exec ();
end_test ();
}
|