[augeas-devel] augeas: master - * src/fatest.c: make testable with failmalloc

David Lutterkort lutter at fedoraproject.org
Thu Oct 1 00:23:24 UTC 2009


Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=96c72991e324a87d11428e639ed868d4cb5c0b7d
Commit:        96c72991e324a87d11428e639ed868d4cb5c0b7d
Parent:        d3ff2a7ad602e1bc11dcfd88a5618f4d3b7ffa33
Author:        David Lutterkort <lutter at redhat.com>
AuthorDate:    Tue Sep 29 17:07:56 2009 -0700
Committer:     David Lutterkort <lutter at redhat.com>
CommitterDate: Wed Sep 30 17:07:54 2009 -0700

* src/fatest.c: make testable with failmalloc

  - when FAILMALLOC_INTERVAL is set, report success, no matter
    how many tests failed (presumably because of memory starvation)
  - abort with die_oom() if crucial internal checks can't be performed
    because of allocation failures
---
 tests/fatest.c |   16 ++++++++++++----
 1 files changed, 12 insertions(+), 4 deletions(-)

diff --git a/tests/fatest.c b/tests/fatest.c
index fe2dfa7..34c8f2f 100644
--- a/tests/fatest.c
+++ b/tests/fatest.c
@@ -25,6 +25,7 @@
 #include "fa.h"
 #include "cutest.h"
 #include "internal.h"
+#include "memory.h"
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -62,7 +63,8 @@ static struct fa *mark(struct fa *fa) {
     struct fa_list *fl;
 
     if (fa != NULL) {
-        CALLOC(fl, 1);
+        if (ALLOC(fl) < 0)
+            die_oom();
         fl->fa = fa;
         list_cons(fa_list, fl);
     }
@@ -80,7 +82,9 @@ static void assertAsRegexp(CuTest *tc, struct fa *fa) {
     fa1 = mark(fa_concat(fa, empty));
     /* Minimize FA1, otherwise the regexp returned is enormous for the */
     /* monster (~ 2MB) and fa_compile becomes incredibly slow          */
-    fa_minimize(fa1);
+    r = fa_minimize(fa1);
+    if (r < 0)
+        die_oom();
 
     r = fa_as_regexp(fa1, &re, &re_len);
     CuAssertIntEquals(tc, 0, r);
@@ -90,7 +94,6 @@ static void assertAsRegexp(CuTest *tc, struct fa *fa) {
         print_regerror(r, re);
     }
     CuAssertIntEquals(tc, REG_NOERROR, r);
-
     CuAssertTrue(tc, fa_equals(fa, fa2));
 
     fa_free(fa2);
@@ -104,6 +107,8 @@ static struct fa *make_fa(CuTest *tc,
     int r;
 
     r = fa_compile(regexp, reglen, &fa);
+    if (r == REG_ESPACE)
+        die_oom();
     if (exp_err == REG_NOERROR) {
         if (r != REG_NOERROR)
             print_regerror(r, regexp);
@@ -515,7 +520,10 @@ int main(int argc, char **argv) {
         CuSuiteDetails(suite, &output);
         printf("%s\n", output);
         free(output);
-        return suite->failCount;
+        if (getenv("FAILMALLOC_INTERVAL") != NULL)
+            return EXIT_SUCCESS;
+        else
+            return suite->failCount;
     }
 
     for (int i=1; i<argc; i++) {




More information about the augeas-devel mailing list