]> ocean-lang.org Git - ocean/commitdiff
oceani-tests: add valgrind testing for 'special' tests
authorNeilBrown <neil@brown.name>
Sat, 13 Nov 2021 00:40:33 +0000 (11:40 +1100)
committerNeilBrown <neil@brown.name>
Sat, 13 Nov 2021 22:50:58 +0000 (09:50 +1100)
Make sure we clean up properly, even after a fatal error - just because.

Signed-off-by: NeilBrown <neil@brown.name>
csrc/oceani-tests.mdc
csrc/oceani.mdc

index fbc5a2f085e3af5f9ad2b2eaa4a928f24579e9fe..4dceab407eee8c163f4a3e69fedca3b8ccf3afe6 100644 (file)
@@ -94,6 +94,7 @@ arguments separated from the name by commas.  For each test, there is a section
                       echo "valgrind found memory in use at exit"; cat .tmp.valg ; exit 1 ; fi; \
                    echo " passed"; \
                done
+               ## valgrind test code
                @[ -n "$$SKIP_COVERAGE_CHECK" ] || awk '/NOTEST/ { next } /^ *[1-9]/ {ran+=1} /^ *###/ {skip+=1} \
                    END {printf "coverage: %6.2f%%\n", ran * 100 / (ran + skip); \
                         if (ran < (ran + skip) *0.968) exit(1) }' \
@@ -1057,6 +1058,19 @@ command list possible.
            echo  "passed"; \
            ./coverage_oceani $${1+"$$@"} > /dev/null 2>&1 ;\
        done || true
+###### valgrind test code
+       @[ -n "$$SKIP_VALGRIND" ] || for t in $(oceani_special_tests); do\
+           echo -n "Valgrind $$t.. "; \
+           i="$$IFS"; IFS=,; set $$t; IFS="$$i"; shift ;\
+           if valgrind --error-exitcode=42 --log-file=.tmp.valg ./oceani $${1+"$$@"} > .tmp.have 2>&1 ;\
+              [ $$? -eq 42 ]; then \
+                      echo "FAILED"; cat .tmp.valg; exit 1; fi ; \
+           if grep 'LEAK SUMMARY' .tmp.valg > /dev/null; then \
+              echo "valgrind found LEAKS"; cat .tmp.valg ; exit 1 ; fi; \
+           if grep 'in use at exit [1-9]' .tmp.valg > /dev/null; then \
+              echo "valgrind found memory in use at exit"; cat .tmp.valg ; exit 1 ; fi; \
+           echo " passed"; \
+       done
 
 ###### test list
        oceani_special_tests += "cmd"
index 0334af198c9656e7f261beb6e773c838aeda2a8a..96fe6c6d6922d82c89de66d37ce0375667a02f04 100644 (file)
@@ -176,7 +176,7 @@ structures can be used.
                int fd;
                int len;
                char *file;
-               struct section *s, *ss;
+               struct section *s = NULL, *ss;
                char *section = NULL;
                struct parse_context context = {
                        .config = {
@@ -231,13 +231,13 @@ structures can be used.
                        if (!ss) {
                                fprintf(stderr, "oceani: cannot find section %s\n",
                                        section);
-                               exit(1);
+                               goto cleanup;
                        }
                } else
                        ss = s;                         // NOTEST
                if (!ss->code) {
                        fprintf(stderr, "oceani: no code found in requested section\n");        // NOTEST
-                       exit(1);                        // NOTEST
+                       goto cleanup;                   // NOTEST
                }
 
                parse_oceani(ss->code, &context.config, dotrace ? stderr : NULL);
@@ -254,7 +254,7 @@ structures can be used.
                }
                if (doexec && !context.parse_error)
                        interp_main(&context, argc - optind, argv + optind);
-
+       cleanup:
                while (s) {
                        struct section *t = s->next;
                        code_free(s->code);