7 #define TEST(r, f, x, m) ( \
8 ((r) = (f)) == (x) || \
9 (printf(__FILE__ ":%d: %s failed (" m ")\n", __LINE__, #f, r, x), err++, 0) )
11 #define TEST_E(f) ( (errno = 0), (f) || \
12 (printf(__FILE__ ":%d: %s failed (errno = %d)\n", __LINE__, #f, errno), err++, 0) )
14 #define TEST_S(s, x, m) ( \
16 (printf(__FILE__ ":%d: [%s] != [%s] (%s)\n", __LINE__, s, x, m), err++, 0) )
18 static sig_atomic_t got_sig
;
20 static void handler(int sig
)
33 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");
38 signal(SIGUSR1
, handler
);
39 snprintf(cmd
, sizeof cmd
, "read a ; test \"x$a\" = xhello && kill -USR1 %d", getpid());
40 TEST_E(f
= popen(cmd
, "w"));
41 TEST_E(fputs("hello", f
) >= 0);
42 TEST(i
, pclose(f
), 0, "exit status %04x != %04x");
43 signal(SIGUSR1
, SIG_DFL
);
44 TEST(i
, got_sig
, 1, "child process did not send signal (%i!=%i)");