8 #define TEST(r, f, x, m) ( \
9 ((r) = (f)) == (x) || (t_error("%s failed (" m ")\n", #f, r, x), 0) )
13 (f) || (t_error("%s failed (errno = %d)\n", #f, errno), 0) )
15 #define TEST_S(s, x, m) ( \
17 (t_error("[%s] != [%s] (%s)\n", s, x, m), 0) )
19 static sig_atomic_t got_sig
;
21 static void handler(int sig
) {
32 TEST_E(f
= popen("echo hello", "r"));
34 TEST_E(fgets(foo
, sizeof foo
, f
));
35 TEST_S(foo
, "hello", "child process did not say hello");
36 TEST(i
, pclose(f
), 0, "exit status %04x != %04x");
39 signal(SIGUSR1
, handler
);
40 snprintf(cmd
, sizeof cmd
, "read a ; test \"x$a\" = xhello && kill -USR1 %d", getpid());
41 TEST_E(f
= popen(cmd
, "w"));
43 TEST_E(fputs("hello", f
) >= 0);
44 TEST(i
, pclose(f
), 0, "exit status %04x != %04x");
45 TEST(i
, got_sig
, 1, "child process did not send signal");
47 signal(SIGUSR1
, SIG_DFL
);