]> git.ozlabs.org Git - ccan/blobdiff - tools/ccanlint/tests/run-coverage.c
ccanlint: rename structures to match keys
[ccan] / tools / ccanlint / tests / run-coverage.c
index 8e756c7db732faed28d89028c6c9d0b7a2afb48b..af8d6f21c845948fbbae3cd1413cbfc6ac8e2938 100644 (file)
@@ -32,12 +32,16 @@ static bool find_source_file(const struct manifest *m, const char *filename)
        return false;
 }
 
-/* 1 point for 50%, 2 points for 75%, 3 points for 87.5%... */
+/* 1 point for 50%, 2 points for 75%, 3 points for 87.5%...  Bonus for 100%. */
 static unsigned int score_coverage(float covered, unsigned total)
 {
        float thresh, uncovered = 1.0 - covered;
        unsigned int i;
 
+       if (covered == 1.0)
+               return total;
+
+       total--;
        for (i = 0, thresh = 0.5; i < total; i++, thresh /= 2) {
                if (uncovered > thresh)
                        break;
@@ -112,7 +116,7 @@ static void analyze_coverage(struct manifest *m, bool full_gcov,
        if (total_lines == 0)
                score->total = score->score = 0;
        else {
-               score->total = 5;
+               score->total = 6;
                score->score = score_coverage(covered_lines / total_lines,
                                              score->total);
        }
@@ -125,7 +129,6 @@ static void do_run_coverage_tests(struct manifest *m,
        struct ccan_file *i;
        char *cmdout;
        char *covcmd;
-       bool ok;
        bool full_gcov = (verbose > 1);
        struct list_head *list;
 
@@ -137,20 +140,20 @@ static void do_run_coverage_tests(struct manifest *m,
        /* Run them all. */
        foreach_ptr(list, &m->run_tests, &m->api_tests) {
                list_for_each(list, i, list) {
-                       cmdout = run_command(m, timeleft, i->cov_compiled);
-                       if (cmdout) {
+                       if (run_command(score, timeleft, &cmdout,
+                                       "%s", i->cov_compiled)) {
+                               covcmd = talloc_asprintf_append(covcmd, " %s",
+                                                               i->fullname);
+                       } else {
                                score->error = "Running test with coverage";
                                score_file_error(score, i, 0, cmdout);
                                return;
                        }
-                       covcmd = talloc_asprintf_append(covcmd, " %s",
-                                                       i->fullname);
                }
        }
 
        /* Now run gcov: we want output even if it succeeds. */
-       cmdout = run_with_timeout(m, covcmd, &ok, timeleft);
-       if (!ok) {
+       if (!run_command(score, timeleft, &cmdout, "%s", covcmd)) {
                score->error = talloc_asprintf(score, "Running gcov: %s",
                                               cmdout);
                return;
@@ -159,10 +162,11 @@ static void do_run_coverage_tests(struct manifest *m,
        analyze_coverage(m, full_gcov, cmdout, score);
 }
 
-struct ccanlint run_coverage_tests = {
-       .key = "test-coverage",
-       .name = "Code coverage of module tests",
+struct ccanlint tests_coverage = {
+       .key = "tests_coverage",
+       .name = "Module's tests cover all the code",
        .check = do_run_coverage_tests,
+       .needs = "tests_compile_coverage tests_pass"
 };
 
-REGISTER_TEST(run_coverage_tests, &compile_coverage_tests, &run_tests, NULL);
+REGISTER_TEST(tests_coverage);