From: Rusty Russell Date: Wed, 17 Nov 2010 09:53:30 +0000 (+1030) Subject: ccanlint: run tests in alphabetical order X-Git-Url: https://git.ozlabs.org/?p=ccan-lca-2011.git;a=commitdiff_plain;h=ed776b635be5cde9bcda9569789fba487f4e7cca ccanlint: run tests in alphabetical order This allows tests (like in tdb2) to run the simpler tests first and build up, making it easier to spot the root cause of errors. --- diff --git a/tools/ccanlint/Makefile b/tools/ccanlint/Makefile index 974e738..7a19055 100644 --- a/tools/ccanlint/Makefile +++ b/tools/ccanlint/Makefile @@ -9,6 +9,7 @@ CORE_OBJS := tools/ccanlint/ccanlint.o \ tools/tools.o \ tools/compile.o \ ccan/str_talloc/str_talloc.o ccan/grab_file/grab_file.o \ + ccan/asort/asort.o \ ccan/btree/btree.o \ ccan/talloc/talloc.o ccan/noerr/noerr.o \ ccan/foreach/foreach.o \ diff --git a/tools/ccanlint/file_analysis.c b/tools/ccanlint/file_analysis.c index 6ee74de..d17940a 100644 --- a/tools/ccanlint/file_analysis.c +++ b/tools/ccanlint/file_analysis.c @@ -4,6 +4,8 @@ #include #include #include +#include +#include #include "../tools.h" #include #include @@ -139,11 +141,36 @@ static void add_files(struct manifest *m, const char *dir) closedir(d); } +static int cmp_names(struct ccan_file *const *a, struct ccan_file *const *b, + void *unused) +{ + return strcmp((*a)->name, (*b)->name); +} + +static void sort_files(struct list_head *list) +{ + struct ccan_file **files = NULL, *f; + unsigned int i, num; + + num = 0; + while ((f = list_top(list, struct ccan_file, list)) != NULL) { + files = talloc_realloc(NULL, files, struct ccan_file *, num+1); + files[num++] = f; + list_del(&f->list); + } + asort(files, num, cmp_names, NULL); + + for (i = 0; i < num; i++) + list_add_tail(list, &files[i]->list); + talloc_free(files); +} + struct manifest *get_manifest(const void *ctx, const char *dir) { struct manifest *m = talloc(ctx, struct manifest); char *olddir; unsigned int len; + struct list_head *list; m->info_file = NULL; list_head_init(&m->c_files); @@ -191,6 +218,11 @@ struct manifest *get_manifest(const void *ctx, const char *dir) add_files(m, ""); + /* Nicer to run tests in a predictable order. */ + foreach_ptr(list, &m->api_tests, &m->run_tests, &m->compile_ok_tests, + &m->compile_fail_tests) + sort_files(list); + if (chdir(olddir) != 0) err(1, "Returning to original directory '%s'", olddir); talloc_free(olddir);