X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ffailtest%2Ffailtest.c;h=a0c825399d03881ab0338075a0a46fb2c4ec1898;hp=ec41e92b46e4cc514bdecb54598686b0a5e9b716;hb=2006aa032d6f72599165e50242d06df35428d43a;hpb=57cc9494b0daacd23372cdbdefcd31fe9320c836 diff --git a/ccan/failtest/failtest.c b/ccan/failtest/failtest.c index ec41e92b..a0c82539 100644 --- a/ccan/failtest/failtest.c +++ b/ccan/failtest/failtest.c @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,7 @@ static unsigned int lock_num = 0; static pid_t orig_pid; -static const char info_to_arg[] = "mceoxprwf"; +static const char info_to_arg[] = "mceoxprwfa"; /* Dummy call used for failtest_undo wrappers. */ static struct failtest_call unrecorded_call; @@ -487,7 +488,10 @@ static NORETURN void failtest_cleanup(bool forced_cleanup, int status) } free_everything(); - tell_parent(SUCCESS); + if (status == 0) + tell_parent(SUCCESS); + else + tell_parent(FAILURE); exit(status); } @@ -514,8 +518,8 @@ static bool should_fail(struct failtest_call *call) } else { if (tolower((unsigned char)*failpath) != info_to_arg[call->type]) - errx(1, "Failpath expected '%c' got '%c'\n", - info_to_arg[call->type], *failpath); + errx(1, "Failpath expected '%s' got '%c'\n", + failpath, info_to_arg[call->type]); call->fail = cisupper(*(failpath++)); return call->fail; } @@ -523,7 +527,12 @@ static bool should_fail(struct failtest_call *call) /* Attach debugger if they asked for it. */ if (debugpath) { - char *path = failpath_string(); + char *path; + + /* Pretend this last call matches whatever path wanted: + * keeps valgrind happy. */ + call->fail = cisupper(debugpath[strlen(debugpath)-1]); + path = failpath_string(); if (streq(path, debugpath)) { char str[80]; @@ -534,9 +543,14 @@ static bool should_fail(struct failtest_call *call) getpid(), getpid()); if (system(str) == 0) sleep(5); - } else if (!strstarts(path, debugpath)) { - fprintf(stderr, "--debugpath not followed: %s\n", path); - debugpath = NULL; + } else { + /* Ignore last character: could be upper or lower. */ + path[strlen(path)-1] = '\0'; + if (!strstarts(debugpath, path)) { + fprintf(stderr, + "--debugpath not followed: %s\n", path); + debugpath = NULL; + } } free(path); } @@ -850,6 +864,30 @@ int failtest_open(const char *pathname, return p->u.open.ret; } +void *failtest_mmap(void *addr, size_t length, int prot, int flags, + int fd, off_t offset, const char *file, unsigned line) +{ + struct failtest_call *p; + struct mmap_call call; + + call.addr = addr; + call.length = length; + call.prot = prot; + call.flags = flags; + call.offset = offset; + call.fd = fd; + + p = add_history(FAILTEST_MMAP, file, line, &call); + if (should_fail(p)) { + p->u.mmap.ret = MAP_FAILED; + p->error = ENOMEM; + } else { + p->u.mmap.ret = mmap(addr, length, prot, flags, fd, offset); + } + errno = p->error; + return p->u.mmap.ret; +} + static void cleanup_pipe(struct pipe_call *call) { if (!call->closed[0])