From: Rusty Russell Date: Fri, 21 Jan 2011 03:37:27 +0000 (+1030) Subject: lca2011: test X-Git-Url: http://git.ozlabs.org/?a=commitdiff_plain;h=b3458dbe49ae218f183affcb239433d66839e2c9;p=ccan-lca-2011.git lca2011: test --- diff --git a/ccan/oserver/_info b/ccan/oserver/_info index 087b043..e73e855 100644 --- a/ccan/oserver/_info +++ b/ccan/oserver/_info @@ -37,6 +37,7 @@ int main(int argc, char *argv[]) if (strcmp(argv[1], "depends") == 0) { printf("ccan/compiler\n"); printf("ccan/read_write_all\n"); + printf("ccan/str\n"); return 0; } diff --git a/ccan/oserver/test/run.c b/ccan/oserver/test/run.c new file mode 100644 index 0000000..3a93be8 --- /dev/null +++ b/ccan/oserver/test/run.c @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +int main(void) +{ + int fd; + int status; + char buf[200]; + + /* This is how many tests you plan to run */ + plan_tests(3); + + fd = open("run-fd", O_RDWR|O_CREAT|O_TRUNC, 0600); + write(fd, "This is a test\n", sizeof("This is a test\n")); + lseek(fd, 0, SEEK_SET); + + if (fork() == 0) + oserver_serve(fd); + + wait(&status); + + ok1(WIFEXITED(status)); + ok1(WEXITSTATUS(status) == 0); + + lseek(fd, 0, SEEK_SET); + buf[read(fd, buf, sizeof(buf)-1)] = '\0'; + + ok1(streq(buf, "This is a test\n" + "Louder, like this: 'THIS IS A TEST'\r\n")); + + /* This exits depending on whether all tests passed */ + return exit_status(); +}