Commit 8af0812b authored by Rusty Russell's avatar Rusty Russell

ccanlint: add coverage variant of files.

Rather than a separate cov_compiled member, we can add to the
compiled[] array, and we reduce duplication significantly.
parent b931f476
......@@ -20,6 +20,7 @@ extern int verbose;
enum compile_type {
COMPILE_NORMAL,
COMPILE_NOFEAT,
COMPILE_COVERAGE,
COMPILE_TYPES
};
......@@ -182,9 +183,6 @@ struct ccan_file {
/* If this file gets compiled (eg. .C file to .o file), result here. */
char *compiled[COMPILE_TYPES];
/* Compiled with coverage information. */
char *cov_compiled;
/* Filename containing output from valgrind. */
char *valgrind_log;
......
......@@ -10,6 +10,7 @@
#include <ccan/noerr/noerr.h>
#include <ccan/foreach/foreach.h>
#include <ccan/asort/asort.h>
#include <ccan/array_size/array_size.h>
#include "../tools.h"
#include <unistd.h>
#include <sys/types.h>
......@@ -74,6 +75,7 @@ struct list_head *get_ccan_file_docs(struct ccan_file *f)
struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name)
{
struct ccan_file *f;
unsigned int i;
assert(dir[0] == '/');
......@@ -81,11 +83,11 @@ struct ccan_file *new_ccan_file(const void *ctx, const char *dir, char *name)
f->lines = NULL;
f->line_info = NULL;
f->doc_sections = NULL;
f->compiled[COMPILE_NORMAL] = f->compiled[COMPILE_NOFEAT] = NULL;
for (i = 0; i < ARRAY_SIZE(f->compiled); i++)
f->compiled[i] = NULL;
f->name = talloc_steal(f, name);
f->fullname = talloc_asprintf(f, "%s/%s", dir, f->name);
f->contents = NULL;
f->cov_compiled = NULL;
f->simplified = NULL;
return f;
}
......
......@@ -15,6 +15,7 @@
#include <string.h>
#include <ctype.h>
#include "reduce_features.h"
#include "tests_compile.h"
static const char *can_build(struct manifest *m)
{
......@@ -23,8 +24,8 @@ static const char *can_build(struct manifest *m)
return NULL;
}
static char *obj_list(const struct manifest *m, bool link_with_module,
enum compile_type ctype)
char *test_obj_list(const struct manifest *m, bool link_with_module,
enum compile_type ctype, enum compile_type own_ctype)
{
char *list = talloc_strdup(m, "");
struct ccan_file *i;
......@@ -39,7 +40,7 @@ static char *obj_list(const struct manifest *m, bool link_with_module,
if (link_with_module)
list_for_each(&m->c_files, i, list)
list = talloc_asprintf_append(list, " %s",
i->compiled[ctype]);
i->compiled[own_ctype]);
/* Other ccan modules. */
list_for_each(&m->deps, subm, list) {
......@@ -51,7 +52,7 @@ static char *obj_list(const struct manifest *m, bool link_with_module,
return list;
}
static char *lib_list(const struct manifest *m, enum compile_type ctype)
char *lib_list(const struct manifest *m, enum compile_type ctype)
{
unsigned int i, num;
char **libs = get_libs(m, m->dir, &num,
......@@ -81,8 +82,10 @@ static bool compile(const void *ctx,
fname = maybe_temp_file(ctx, "", keep, file->fullname);
if (!compile_and_link(ctx, file->fullname, ccan_dir,
obj_list(m, link_with_module, ctype), compiler,
flags, lib_list(m, ctype), fname, output)) {
test_obj_list(m, link_with_module,
ctype, ctype),
compiler, flags, lib_list(m, ctype), fname,
output)) {
talloc_free(fname);
return false;
}
......
/* Objects to link with; ctype is variant for test helpers and other modules,
own_ctype is (if link_with_module) for this module's objects. */
char *test_obj_list(const struct manifest *m, bool link_with_module,
enum compile_type ctype, enum compile_type own_ctype);
/* Library list as specified by ctype variant of _info. */
char *lib_list(const struct manifest *m, enum compile_type ctype);
......@@ -14,6 +14,8 @@
#include <err.h>
#include <string.h>
#include <ctype.h>
#include "../compulsory_tests/build.h"
#include "tests_compile.h"
/* Note: we already test safe_mode in run_tests.c */
static const char *can_run_coverage(struct manifest *m)
......@@ -26,85 +28,26 @@ static const char *can_run_coverage(struct manifest *m)
return NULL;
}
static bool build_module_objs_with_coverage(struct manifest *m, bool keep,
struct score *score,
char **modobjs)
{
struct ccan_file *i;
*modobjs = talloc_strdup(m, "");
list_for_each(&m->c_files, i, list) {
char *err;
char *fullfile = talloc_asprintf(m, "%s/%s", m->dir, i->name);
i->cov_compiled = maybe_temp_file(m, "", keep, fullfile);
if (!compile_object(m, fullfile, ccan_dir, compiler, cflags,
i->cov_compiled, &err)) {
score_file_error(score, i, 0, "%s", err);
talloc_free(i->cov_compiled);
i->cov_compiled = NULL;
return false;
}
*modobjs = talloc_asprintf_append(*modobjs,
" %s", i->cov_compiled);
}
return true;
}
/* FIXME: Merge this into one place. */
static char *obj_list(const struct manifest *m, const char *modobjs)
{
char *list = talloc_strdup(m, "");
struct ccan_file *i;
struct manifest *subm;
/* Objects from any other C files. */
list_for_each(&m->other_test_c_files, i, list)
list = talloc_asprintf_append(list, " %s",
i->compiled[COMPILE_NORMAL]);
if (modobjs)
list = talloc_append_string(list, modobjs);
/* Other ccan modules (don't need coverage versions of those). */
list_for_each(&m->deps, subm, list) {
if (subm->compiled[COMPILE_NORMAL])
list = talloc_asprintf_append(list, " %s",
subm->compiled
[COMPILE_NORMAL]);
}
return list;
}
static char *lib_list(const struct manifest *m)
{
unsigned int i, num;
char **libs = get_libs(m, m->dir, &num,
&m->info_file->compiled[COMPILE_NORMAL]);
char *ret = talloc_strdup(m, "");
for (i = 0; i < num; i++)
ret = talloc_asprintf_append(ret, "-l%s ", libs[i]);
return ret;
}
static char *cov_compile(const void *ctx,
struct manifest *m,
struct ccan_file *file,
const char *modobjs,
bool link_with_module,
bool keep)
{
char *output;
char *f = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
char *flags = talloc_asprintf(ctx, "%s %s", cflags, COVERAGE_CFLAGS);
file->cov_compiled = maybe_temp_file(ctx, "", keep, file->fullname);
file->compiled[COMPILE_COVERAGE]
= maybe_temp_file(ctx, "", keep, file->fullname);
if (!compile_and_link(ctx, file->fullname, ccan_dir,
obj_list(m, modobjs),
compiler, f,
lib_list(m), file->cov_compiled, &output)) {
talloc_free(file->cov_compiled);
file->cov_compiled = NULL;
test_obj_list(m, link_with_module,
COMPILE_NORMAL,
COMPILE_COVERAGE),
compiler, flags,
lib_list(m, COMPILE_NORMAL),
file->compiled[COMPILE_COVERAGE], &output)) {
talloc_free(file->compiled[COMPILE_COVERAGE]);
file->compiled[COMPILE_COVERAGE] = NULL;
return output;
}
talloc_free(output);
......@@ -117,22 +60,25 @@ static void do_compile_coverage_tests(struct manifest *m,
unsigned int *timeleft,
struct score *score)
{
char *cmdout, *modobjs = NULL;
char *cmdout;
struct ccan_file *i;
struct list_head *h;
char *f = talloc_asprintf(score, "%s %s", cflags, COVERAGE_CFLAGS);
if (!list_empty(&m->api_tests)
&& !build_module_objs_with_coverage(m, keep, score, &modobjs)) {
/* For API tests, we need coverage version of module. */
if (!list_empty(&m->api_tests)) {
build_objects(m, keep, score, f, COMPILE_COVERAGE);
if (!score->pass) {
score->error = talloc_strdup(score,
"Failed to compile module objects with coverage");
return;
}
}
foreach_ptr(h, &m->run_tests, &m->api_tests) {
list_for_each(h, i, list) {
cmdout = cov_compile(m, m, i,
h == &m->api_tests
? modobjs : NULL,
h == &m->api_tests,
keep);
if (cmdout) {
score_file_error(score, i, 0,
......
......@@ -158,7 +158,7 @@ static void do_run_coverage_tests(struct manifest *m,
foreach_ptr(list, &m->run_tests, &m->api_tests) {
list_for_each(list, i, list) {
if (run_command(score, timeleft, &cmdout,
"%s", i->cov_compiled)) {
"%s", i->compiled[COMPILE_COVERAGE])) {
covcmd = talloc_asprintf_append(covcmd, " %s",
i->fullname);
} else {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment