MCPcopy Create free account
hub / github.com/ElementsProject/lightning / main

Function main

ccan/ccan/err/test/run.c:13–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11#define BUFFER_MAX 1024
12
13int main(int argc, char *argv[])
14{
15 int pfd[2];
16 const char *base;
17
18 (void)argc;
19 plan_tests(24);
20
21 err_set_progname(argv[0]);
22
23 /* In case it only prints out the basename of argv[0]. */
24 base = strrchr(argv[0], '/');
25 if (base)
26 base++;
27 else
28 base = argv[0];
29
30 /* Test err() in child */
31 if (pipe(pfd))
32 abort();
33 fflush(stdout);
34 if (fork()) {
35 char buffer[BUFFER_MAX+1];
36 unsigned int i;
37 int status;
38
39 /* We are parent. */
40 close(pfd[1]);
41 for (i = 0; i < BUFFER_MAX; i++) {
42 if (read(pfd[0], buffer + i, 1) == 0) {
43 buffer[i] = '\0';
44 ok1(strstr(buffer, "running err:"));
45 ok1(strstr(buffer, strerror(ENOENT)));
46 ok1(strstr(buffer, base));
47 ok1(buffer[i-1] == '\n');
48 break;
49 }
50 }
51 close(pfd[0]);
52 ok1(wait(&status) != -1);
53 ok1(WIFEXITED(status));
54 ok1(WEXITSTATUS(status) == 17);
55 } else {
56 close(pfd[0]);
57 dup2(pfd[1], STDERR_FILENO);
58 errno = ENOENT;
59 err(17, "running %s", "err");
60 abort();
61 }
62
63 /* Test errx() in child */
64 if (pipe(pfd))
65 abort();
66 fflush(stdout);
67 if (fork()) {
68 char buffer[BUFFER_MAX+1];
69 unsigned int i;
70 int status;

Callers

nothing calls this directly

Calls 6

err_set_prognameFunction · 0.85
abortFunction · 0.85
errFunction · 0.85
errxFunction · 0.85
warnFunction · 0.85
warnxFunction · 0.85

Tested by

no test coverage detected