From c4ca9f54301c0367891be6330f59fdd5dcdd51d1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 31 Aug 2011 15:39:16 +0930 Subject: [PATCH 1/1] tdb2: test: convert (non-invasive) run tests to api tests. This reduces compilation time, since these are merely linked with the pre-built module, rather than recompiling it into the test (which allows for fancy things like failtest). This reduces the test compile time down from about 62 seconds to 45 seconds. Since ccanlint compiles tests three times (once normally, once with coverage, and once with reduced config.h) this makes a difference: we go from 780 seconds to 729 seconds. --- ccan/tdb2/test/{run-12-store.c => api-12-store.c} | 9 ++++++--- ccan/tdb2/test/{run-13-delete.c => api-13-delete.c} | 7 ++++++- ccan/tdb2/test/{run-14-exists.c => api-14-exists.c} | 5 ++++- .../test/{run-16-wipe_all.c => api-16-wipe_all.c} | 5 ++++- .../{run-21-parse_record.c => api-21-parse_record.c} | 5 ++++- .../{run-55-transaction.c => api-55-transaction.c} | 7 ++++++- ccan/tdb2/test/{run-80-tdb_fd.c => api-80-tdb_fd.c} | 7 +++++-- ccan/tdb2/test/{run-81-seqnum.c => api-81-seqnum.c} | 8 ++++++-- .../test/{run-82-lockattr.c => api-82-lockattr.c} | 7 ++++++- .../test/{run-83-openhook.c => api-83-openhook.c} | 7 +++++-- .../test/{run-91-get-stats.c => api-91-get-stats.c} | 7 ++++++- ...-get-set-readonly.c => api-92-get-set-readonly.c} | 5 ++++- ccan/tdb2/test/{run-93-repack.c => api-93-repack.c} | 5 ++++- ...run-add-remove-flags.c => api-add-remove-flags.c} | 8 ++++++-- .../{run-check-callback.c => api-check-callback.c} | 7 +++++-- ...run-firstkey-nextkey.c => api-firstkey-nextkey.c} | 8 ++++++-- ccan/tdb2/test/{run-fork-test.c => api-fork-test.c} | 7 ++++++- .../test/{run-locktimeout.c => api-locktimeout.c} | 12 +++++++++--- .../{run-missing-entries.c => api-missing-entries.c} | 6 +++++- ...en-multiple-times.c => api-open-multiple-times.c} | 6 +++++- .../{run-record-expand.c => api-record-expand.c} | 8 ++++++-- .../{run-simple-delete.c => api-simple-delete.c} | 7 +++++-- ccan/tdb2/test/{run-summary.c => api-summary.c} | 8 +++++--- 23 files changed, 124 insertions(+), 37 deletions(-) rename ccan/tdb2/test/{run-12-store.c => api-12-store.c} (92%) rename ccan/tdb2/test/{run-13-delete.c => api-13-delete.c} (96%) rename ccan/tdb2/test/{run-14-exists.c => api-14-exists.c} (93%) rename ccan/tdb2/test/{run-16-wipe_all.c => api-16-wipe_all.c} (92%) rename ccan/tdb2/test/{run-21-parse_record.c => api-21-parse_record.c} (94%) rename ccan/tdb2/test/{run-55-transaction.c => api-55-transaction.c} (92%) rename ccan/tdb2/test/{run-80-tdb_fd.c => api-80-tdb_fd.c} (85%) rename ccan/tdb2/test/{run-81-seqnum.c => api-81-seqnum.c} (95%) rename ccan/tdb2/test/{run-82-lockattr.c => api-82-lockattr.c} (97%) rename ccan/tdb2/test/{run-83-openhook.c => api-83-openhook.c} (95%) rename ccan/tdb2/test/{run-91-get-stats.c => api-91-get-stats.c} (91%) rename ccan/tdb2/test/{run-92-get-set-readonly.c => api-92-get-set-readonly.c} (97%) rename ccan/tdb2/test/{run-93-repack.c => api-93-repack.c} (94%) rename ccan/tdb2/test/{run-add-remove-flags.c => api-add-remove-flags.c} (91%) rename ccan/tdb2/test/{run-check-callback.c => api-check-callback.c} (93%) rename ccan/tdb2/test/{run-firstkey-nextkey.c => api-firstkey-nextkey.c} (96%) rename ccan/tdb2/test/{run-fork-test.c => api-fork-test.c} (97%) rename ccan/tdb2/test/{run-locktimeout.c => api-locktimeout.c} (94%) rename ccan/tdb2/test/{run-missing-entries.c => api-missing-entries.c} (90%) rename ccan/tdb2/test/{run-open-multiple-times.c => api-open-multiple-times.c} (95%) rename ccan/tdb2/test/{run-record-expand.c => api-record-expand.c} (89%) rename ccan/tdb2/test/{run-simple-delete.c => api-simple-delete.c} (89%) rename ccan/tdb2/test/{run-summary.c => api-summary.c} (93%) diff --git a/ccan/tdb2/test/run-12-store.c b/ccan/tdb2/test/api-12-store.c similarity index 92% rename from ccan/tdb2/test/run-12-store.c rename to ccan/tdb2/test/api-12-store.c index 73ffd554..ccec53e0 100644 --- a/ccan/tdb2/test/run-12-store.c +++ b/ccan/tdb2/test/api-12-store.c @@ -1,5 +1,10 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include + #include "logging.h" /* We use the same seed which we saw a failure on. */ @@ -49,5 +54,3 @@ int main(int argc, char *argv[]) ok1(tap_log_messages == 0); return exit_status(); } - - diff --git a/ccan/tdb2/test/run-13-delete.c b/ccan/tdb2/test/api-13-delete.c similarity index 96% rename from ccan/tdb2/test/run-13-delete.c rename to ccan/tdb2/test/api-13-delete.c index fdbc9db7..0287a6ab 100644 --- a/ccan/tdb2/test/run-13-delete.c +++ b/ccan/tdb2/test/api-13-delete.c @@ -1,4 +1,9 @@ -#include "tdb2-source.h" +#include // For TDB_TOPLEVEL_HASH_BITS +#include +#include +#include +#include +#include #include #include "logging.h" diff --git a/ccan/tdb2/test/run-14-exists.c b/ccan/tdb2/test/api-14-exists.c similarity index 93% rename from ccan/tdb2/test/run-14-exists.c rename to ccan/tdb2/test/api-14-exists.c index 7ff45142..698006fa 100644 --- a/ccan/tdb2/test/run-14-exists.c +++ b/ccan/tdb2/test/api-14-exists.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" static bool test_records(struct tdb_context *tdb) diff --git a/ccan/tdb2/test/run-16-wipe_all.c b/ccan/tdb2/test/api-16-wipe_all.c similarity index 92% rename from ccan/tdb2/test/run-16-wipe_all.c rename to ccan/tdb2/test/api-16-wipe_all.c index 27d6f438..d17eff8e 100644 --- a/ccan/tdb2/test/run-16-wipe_all.c +++ b/ccan/tdb2/test/api-16-wipe_all.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" static bool add_records(struct tdb_context *tdb) diff --git a/ccan/tdb2/test/run-21-parse_record.c b/ccan/tdb2/test/api-21-parse_record.c similarity index 94% rename from ccan/tdb2/test/run-21-parse_record.c rename to ccan/tdb2/test/api-21-parse_record.c index c7414a4d..4a9cf05c 100644 --- a/ccan/tdb2/test/run-21-parse_record.c +++ b/ccan/tdb2/test/api-21-parse_record.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" static enum TDB_ERROR parse(TDB_DATA key, TDB_DATA data, TDB_DATA *expected) diff --git a/ccan/tdb2/test/run-55-transaction.c b/ccan/tdb2/test/api-55-transaction.c similarity index 92% rename from ccan/tdb2/test/run-55-transaction.c rename to ccan/tdb2/test/api-55-transaction.c index 95545b7e..9c1044b4 100644 --- a/ccan/tdb2/test/run-55-transaction.c +++ b/ccan/tdb2/test/api-55-transaction.c @@ -1,5 +1,10 @@ -#include "tdb2-source.h" +#include // struct tdb_context +#include #include +#include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) diff --git a/ccan/tdb2/test/run-80-tdb_fd.c b/ccan/tdb2/test/api-80-tdb_fd.c similarity index 85% rename from ccan/tdb2/test/run-80-tdb_fd.c rename to ccan/tdb2/test/api-80-tdb_fd.c index 7faed41c..b321f597 100644 --- a/ccan/tdb2/test/run-80-tdb_fd.c +++ b/ccan/tdb2/test/api-80-tdb_fd.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) @@ -7,7 +10,7 @@ int main(int argc, char *argv[]) unsigned int i; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, - TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, + TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, diff --git a/ccan/tdb2/test/run-81-seqnum.c b/ccan/tdb2/test/api-81-seqnum.c similarity index 95% rename from ccan/tdb2/test/run-81-seqnum.c rename to ccan/tdb2/test/api-81-seqnum.c index b33d0a21..c41b9ce3 100644 --- a/ccan/tdb2/test/run-81-seqnum.c +++ b/ccan/tdb2/test/api-81-seqnum.c @@ -1,5 +1,9 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) @@ -24,7 +28,7 @@ int main(int argc, char *argv[]) O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr); if (!ok1(tdb)) continue; - + seq = 0; ok1(tdb_get_seqnum(tdb) == seq); ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0); diff --git a/ccan/tdb2/test/run-82-lockattr.c b/ccan/tdb2/test/api-82-lockattr.c similarity index 97% rename from ccan/tdb2/test/run-82-lockattr.c rename to ccan/tdb2/test/api-82-lockattr.c index acad4399..048feacf 100644 --- a/ccan/tdb2/test/run-82-lockattr.c +++ b/ccan/tdb2/test/api-82-lockattr.c @@ -1,5 +1,10 @@ -#include "tdb2-source.h" +#include // for tdb_fcntl_unlock +#include #include +#include +#include +#include +#include #include "logging.h" static int mylock(int fd, int rw, off_t off, off_t len, bool waitflag, diff --git a/ccan/tdb2/test/run-83-openhook.c b/ccan/tdb2/test/api-83-openhook.c similarity index 95% rename from ccan/tdb2/test/run-83-openhook.c rename to ccan/tdb2/test/api-83-openhook.c index 59b1e652..e7e94738 100644 --- a/ccan/tdb2/test/run-83-openhook.c +++ b/ccan/tdb2/test/api-83-openhook.c @@ -1,9 +1,13 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include #include #include #include +#include #include "external-agent.h" #include "logging.h" @@ -93,4 +97,3 @@ int main(int argc, char *argv[]) free_external_agent(agent); return exit_status(); } - diff --git a/ccan/tdb2/test/run-91-get-stats.c b/ccan/tdb2/test/api-91-get-stats.c similarity index 91% rename from ccan/tdb2/test/run-91-get-stats.c rename to ccan/tdb2/test/api-91-get-stats.c index f00abb3c..d9a22ca4 100644 --- a/ccan/tdb2/test/run-91-get-stats.c +++ b/ccan/tdb2/test/api-91-get-stats.c @@ -1,5 +1,10 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) diff --git a/ccan/tdb2/test/run-92-get-set-readonly.c b/ccan/tdb2/test/api-92-get-set-readonly.c similarity index 97% rename from ccan/tdb2/test/run-92-get-set-readonly.c rename to ccan/tdb2/test/api-92-get-set-readonly.c index c8bbe627..483b50d7 100644 --- a/ccan/tdb2/test/run-92-get-set-readonly.c +++ b/ccan/tdb2/test/api-92-get-set-readonly.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) diff --git a/ccan/tdb2/test/run-93-repack.c b/ccan/tdb2/test/api-93-repack.c similarity index 94% rename from ccan/tdb2/test/run-93-repack.c rename to ccan/tdb2/test/api-93-repack.c index 906a17b4..0a2e6d5b 100644 --- a/ccan/tdb2/test/run-93-repack.c +++ b/ccan/tdb2/test/api-93-repack.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" #define NUM_TESTS 50000 diff --git a/ccan/tdb2/test/run-add-remove-flags.c b/ccan/tdb2/test/api-add-remove-flags.c similarity index 91% rename from ccan/tdb2/test/run-add-remove-flags.c rename to ccan/tdb2/test/api-add-remove-flags.c index 54c48817..231b9f6c 100644 --- a/ccan/tdb2/test/run-add-remove-flags.c +++ b/ccan/tdb2/test/api-add-remove-flags.c @@ -1,5 +1,9 @@ -#include "tdb2-source.h" +#include // for tdb_context +#include #include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) @@ -7,7 +11,7 @@ int main(int argc, char *argv[]) unsigned int i; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, - TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, + TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, diff --git a/ccan/tdb2/test/run-check-callback.c b/ccan/tdb2/test/api-check-callback.c similarity index 93% rename from ccan/tdb2/test/run-check-callback.c rename to ccan/tdb2/test/api-check-callback.c index 91a4d287..fb980f22 100644 --- a/ccan/tdb2/test/run-check-callback.c +++ b/ccan/tdb2/test/api-check-callback.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" #define NUM_RECORDS 1000 @@ -53,7 +56,7 @@ int main(int argc, char *argv[]) unsigned int i, j; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, - TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, + TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, diff --git a/ccan/tdb2/test/run-firstkey-nextkey.c b/ccan/tdb2/test/api-firstkey-nextkey.c similarity index 96% rename from ccan/tdb2/test/run-firstkey-nextkey.c rename to ccan/tdb2/test/api-firstkey-nextkey.c index 1eb265ef..0c095141 100644 --- a/ccan/tdb2/test/run-firstkey-nextkey.c +++ b/ccan/tdb2/test/api-firstkey-nextkey.c @@ -1,5 +1,9 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include #include "logging.h" #define NUM_RECORDS 1000 @@ -50,7 +54,7 @@ int main(int argc, char *argv[]) union tdb_attribute seed_attr; enum TDB_ERROR ecode; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, - TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, + TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, diff --git a/ccan/tdb2/test/run-fork-test.c b/ccan/tdb2/test/api-fork-test.c similarity index 97% rename from ccan/tdb2/test/run-fork-test.c rename to ccan/tdb2/test/api-fork-test.c index 7ff71366..6feb618c 100644 --- a/ccan/tdb2/test/run-fork-test.c +++ b/ccan/tdb2/test/api-fork-test.c @@ -10,10 +10,15 @@ * Note that we don't hold a lock across tdb_traverse callbacks, so * that doesn't matter. */ -#include "tdb2-source.h" +#include #include #include +#include +#include +#include #include +#include +#include #include "logging.h" static enum TDB_ERROR fork_in_parse(TDB_DATA key, TDB_DATA data, diff --git a/ccan/tdb2/test/run-locktimeout.c b/ccan/tdb2/test/api-locktimeout.c similarity index 94% rename from ccan/tdb2/test/run-locktimeout.c rename to ccan/tdb2/test/api-locktimeout.c index 18b6e1a9..21a26c46 100644 --- a/ccan/tdb2/test/run-locktimeout.c +++ b/ccan/tdb2/test/api-locktimeout.c @@ -1,5 +1,11 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include +#include +#include #include "logging.h" #include "external-agent.h" @@ -142,7 +148,7 @@ int main(int argc, char *argv[]) if (!ok1(tdb)) break; - /* Simple cases: should succeed. */ + /* Simple cases: should succeed. */ ecode = tdb_chainlock_with_timeout_internal(tdb, key, 20, F_RDLCK); ok1(ecode == TDB_SUCCESS); @@ -162,7 +168,7 @@ int main(int argc, char *argv[]) /* OK, get agent to start transaction, then we should time out. */ ok1(external_agent_operation(agent, OPEN, "run-locktimeout.tdb") == SUCCESS); - ok1(external_agent_operation(agent, TRANSACTION_START, "") + ok1(external_agent_operation(agent, TRANSACTION_START, "") == SUCCESS); ecode = tdb_chainlock_with_timeout_internal(tdb, key, 20, F_WRLCK); diff --git a/ccan/tdb2/test/run-missing-entries.c b/ccan/tdb2/test/api-missing-entries.c similarity index 90% rename from ccan/tdb2/test/run-missing-entries.c rename to ccan/tdb2/test/api-missing-entries.c index 22d6ba42..1932947a 100644 --- a/ccan/tdb2/test/run-missing-entries.c +++ b/ccan/tdb2/test/api-missing-entries.c @@ -1,6 +1,10 @@ -#include "tdb2-source.h" /* Another test revealed that we lost an entry. This reproduces it. */ +#include +#include #include +#include +#include +#include #include "logging.h" #define NUM_RECORDS 1189 diff --git a/ccan/tdb2/test/run-open-multiple-times.c b/ccan/tdb2/test/api-open-multiple-times.c similarity index 95% rename from ccan/tdb2/test/run-open-multiple-times.c rename to ccan/tdb2/test/api-open-multiple-times.c index 4d60b202..16562069 100644 --- a/ccan/tdb2/test/run-open-multiple-times.c +++ b/ccan/tdb2/test/api-open-multiple-times.c @@ -1,5 +1,9 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) diff --git a/ccan/tdb2/test/run-record-expand.c b/ccan/tdb2/test/api-record-expand.c similarity index 89% rename from ccan/tdb2/test/run-record-expand.c rename to ccan/tdb2/test/api-record-expand.c index 2cde8739..48ad1cdf 100644 --- a/ccan/tdb2/test/run-record-expand.c +++ b/ccan/tdb2/test/api-record-expand.c @@ -1,5 +1,9 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include #include "logging.h" #define MAX_SIZE 10000 @@ -10,7 +14,7 @@ int main(int argc, char *argv[]) unsigned int i; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, - TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, + TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, diff --git a/ccan/tdb2/test/run-simple-delete.c b/ccan/tdb2/test/api-simple-delete.c similarity index 89% rename from ccan/tdb2/test/run-simple-delete.c rename to ccan/tdb2/test/api-simple-delete.c index 84acd194..a5b65d60 100644 --- a/ccan/tdb2/test/run-simple-delete.c +++ b/ccan/tdb2/test/api-simple-delete.c @@ -1,5 +1,8 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) @@ -7,7 +10,7 @@ int main(int argc, char *argv[]) unsigned int i; struct tdb_context *tdb; int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, - TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, + TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT, TDB_INTERNAL|TDB_VERSION1, TDB_VERSION1, TDB_NOMMAP|TDB_VERSION1, diff --git a/ccan/tdb2/test/run-summary.c b/ccan/tdb2/test/api-summary.c similarity index 93% rename from ccan/tdb2/test/run-summary.c rename to ccan/tdb2/test/api-summary.c index 73e180df..e0e292ea 100644 --- a/ccan/tdb2/test/run-summary.c +++ b/ccan/tdb2/test/api-summary.c @@ -1,5 +1,9 @@ -#include "tdb2-source.h" +#include #include +#include +#include +#include +#include #include "logging.h" int main(int argc, char *argv[]) @@ -57,5 +61,3 @@ int main(int argc, char *argv[]) ok1(tap_log_messages == 0); return exit_status(); } - - -- 2.39.2