8 #define TEST(r, f, x, m) ( \
9 ((r) = (f)) == (x) || (error("%s failed (" m ")\n", #f, r, x), 0) )
13 (f) || (error("%s failed (errno = %d)\n", #f, errno), 0) )
15 #define TEST_S(s, x, m) ( \
17 (error("[%s] != [%s] (%s)\n", s, x, m), 0) )
19 static sig_atomic_t got_sig;
21 static void handler(int sig) {
25 void test_popen(void) {
31 TEST_E(f = popen("echo hello", "r"));
33 TEST_E(fgets(foo, sizeof foo, f));
34 TEST_S(foo, "hello", "child process did not say hello");
35 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"));
42 TEST_E(fputs("hello", f) >= 0);
43 TEST(i, pclose(f), 0, "exit status %04x != %04x");
44 TEST(i, got_sig, 1, "child process did not send signal");
46 signal(SIGUSR1, SIG_DFL);