failtest: failtest_has_failed()
authorRusty Russell <rusty@rustcorp.com.au>
Fri, 20 May 2011 06:21:33 +0000 (15:51 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Fri, 20 May 2011 06:21:33 +0000 (15:51 +0930)
Allows tests to explicitly avoid continuing when a failure has been
injected.

ccan/failtest/failtest.c
ccan/failtest/failtest.h

index e9f837364a84b55ed9853a287ab69884b5f92c0a..2471510614a070c6c404e04d51789bbc28a8536e 100644 (file)
@@ -1053,6 +1053,11 @@ void failtest_init(int argc, char *argv[])
        gettimeofday(&start, NULL);
 }
 
+bool failtest_has_failed(void)
+{
+       return control_fd != -1;
+}
+
 void failtest_exit(int status)
 {
        if (failtest_exit_check) {
index 4df286241d0ef35f8a271251861ae7d0f2c11ac7..d4d9987b5e38e545244eebc18e0103a053149c8f 100644 (file)
@@ -196,6 +196,16 @@ extern enum failtest_result
 extern bool (*failtest_exit_check)(struct failtest_call *history,
                                   unsigned num);
 
+/**
+ * failtest_has_failed - determine if a failure has occurred.
+ *
+ * Sometimes you want to exit immediately if you've experienced a failure.
+ * This is useful when you have four separate tests in your test suite,
+ * and you don't want to do the next one if you've had a failure in a
+ * previous one.
+ */
+extern bool failtest_has_failed(void);
+
 /**
  * failtest_timeout_ms - how long to wait before killing child.
  *