4 #include <ccan/tap/tap.h>
5 /* Include the C files directly. */
6 #include <ccan/failtest/failtest.c>
10 struct failtest_call *call;
11 struct calloc_call calloc_call;
12 struct malloc_call malloc_call;
13 struct realloc_call realloc_call;
14 struct open_call open_call;
15 struct pipe_call pipe_call;
16 struct read_call read_call;
17 struct write_call write_call;
22 /* This is how many tests you plan to run */
25 calloc_call.ret = calloc(1, 2);
26 calloc_call.nmemb = 1;
28 call = add_history(FAILTEST_CALLOC, "run-history.c", 1, &calloc_call);
29 ok1(call->type == FAILTEST_CALLOC);
30 ok1(strcmp(call->file, "run-history.c") == 0);
32 ok1(call->u.calloc.ret == calloc_call.ret);
33 ok1(call->u.calloc.nmemb == calloc_call.nmemb);
34 ok1(call->u.calloc.size == calloc_call.size);
36 malloc_call.ret = malloc(2);
38 call = add_history(FAILTEST_MALLOC, "run-history.c", 2, &malloc_call);
39 ok1(call->type == FAILTEST_MALLOC);
40 ok1(strcmp(call->file, "run-history.c") == 0);
42 ok1(call->u.malloc.ret == malloc_call.ret);
43 ok1(call->u.malloc.size == malloc_call.size);
45 realloc_call.ret = realloc(malloc_call.ret, 3);
46 realloc_call.ptr = malloc_call.ret;
47 realloc_call.size = 3;
48 call = add_history(FAILTEST_REALLOC, "run-history.c", 3,
50 ok1(call->type == FAILTEST_REALLOC);
51 ok1(strcmp(call->file, "run-history.c") == 0);
53 ok1(call->u.realloc.ret == realloc_call.ret);
54 ok1(call->u.realloc.ptr == realloc_call.ptr);
55 ok1(call->u.realloc.size == realloc_call.size);
57 open_call.ret = open("test/run_history.c", O_RDONLY);
58 open_call.pathname = "test/run_history.c";
59 open_call.flags = O_RDONLY;
61 call = add_history(FAILTEST_OPEN, "run-history.c", 4, &open_call);
62 ok1(call->type == FAILTEST_OPEN);
63 ok1(strcmp(call->file, "run-history.c") == 0);
65 ok1(call->u.open.ret == open_call.ret);
66 ok1(strcmp(call->u.open.pathname, open_call.pathname) == 0);
67 ok1(call->u.open.flags == open_call.flags);
68 ok1(call->u.open.mode == open_call.mode);
70 pipe_call.ret = pipe(pipe_call.fds);
71 call = add_history(FAILTEST_PIPE, "run-history.c", 5, &pipe_call);
72 ok1(call->type == FAILTEST_PIPE);
73 ok1(strcmp(call->file, "run-history.c") == 0);
75 ok1(call->u.pipe.ret == pipe_call.ret);
76 ok1(call->u.pipe.fds[0] == pipe_call.fds[0]);
77 ok1(call->u.pipe.fds[1] == pipe_call.fds[1]);
79 read_call.ret = read(open_call.ret, buf, 20);
81 read_call.fd = open_call.ret;
83 call = add_history(FAILTEST_READ, "run-history.c", 6, &read_call);
84 ok1(call->type == FAILTEST_READ);
85 ok1(strcmp(call->file, "run-history.c") == 0);
87 ok1(call->u.read.ret == read_call.ret);
88 ok1(call->u.read.buf == read_call.buf);
89 ok1(call->u.read.fd == read_call.fd);
90 ok1(call->u.read.count == read_call.count);
94 write_call.fd = open_call.ret;
95 write_call.count = 20;
96 call = add_history(FAILTEST_WRITE, "run-history.c", 7, &write_call);
97 ok1(call->type == FAILTEST_WRITE);
98 ok1(strcmp(call->file, "run-history.c") == 0);
100 ok1(call->u.write.ret == write_call.ret);
101 ok1(call->u.write.buf == write_call.buf);
102 ok1(call->u.write.fd == write_call.fd);
103 ok1(call->u.write.count == write_call.count);
105 ok1(history_num == 7);
107 for (i = 0; i < history_num; i++)
108 history[i].fail = false;
110 path = failpath_string();
111 ok1(strcmp(path, "cmeoprw") == 0);
114 for (i = 0; i < history_num; i++)
115 history[i].fail = true;
117 path = failpath_string();
118 ok1(strcmp(path, "CMEOPRW") == 0);
121 return exit_status();