summaryrefslogtreecommitdiff
path: root/lib/ccan/failtest/test/run-failpath.c
blob: 9795ee9d054f9810b4aecd2c1a1f73bf2689efbb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <ccan/failtest/failtest.c>
#include <stdlib.h>
#include <setjmp.h>
#include <stdio.h>
#include <stdarg.h>
#include <ccan/tap/tap.h>

int main(void)
{
	int fds[2], fd;
	void *p;

	plan_tests(14);
	failtest_init(0, NULL);

	failpath = "mceopwrMCEOPWR";

	ok1((p = failtest_malloc(10, "run-failpath.c", 1)) != NULL);
	ok1(failtest_calloc(10, 5, "run-failpath.c", 1) != NULL);
	ok1((p = failtest_realloc(p, 100, "run-failpath.c", 1)) != NULL);
	ok1((fd = failtest_open("failpath-scratch", "run-failpath.c", 1,
				O_RDWR|O_CREAT, 0600)) >= 0);
	ok1(failtest_pipe(fds, "run-failpath.c", 1) == 0);
	ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == 4);
	lseek(fd, 0, SEEK_SET);
	ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == 4);

	/* Now we're into the failures. */
	ok1(failtest_malloc(10, "run-failpath.c", 1) == NULL);
	ok1(failtest_calloc(10, 5, "run-failpath.c", 1) == NULL);
	ok1(failtest_realloc(p, 100, "run-failpath.c", 1) == NULL);
	ok1(failtest_open("failpath-scratch", "run-failpath.c", 1,
			  O_RDWR|O_CREAT, 0600) == -1);
	ok1(failtest_pipe(fds, "run-failpath.c", 1) == -1);
	ok1(failtest_write(fd, "xxxx", 4, "run-failpath.c", 1) == -1);
	lseek(fd, 0, SEEK_SET);
	ok1(failtest_read(fd, p, 5, "run-failpath.c", 1) == -1);
	return exit_status();
}