X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Ftdb2%2Ftest%2Frun-11-simple-fetch.c;h=ed3dcad64f28a82725912ea711523ea31cf27eb2;hp=8cd281e24fe31fc9feb78b406adc209a00ab4a9f;hb=c8c3b3568677e8b0105f84e4ab068c580faf4591;hpb=b21004624683be5bf1d8f75e3b5be4e9618049ee diff --git a/ccan/tdb2/test/run-11-simple-fetch.c b/ccan/tdb2/test/run-11-simple-fetch.c index 8cd281e2..ed3dcad6 100644 --- a/ccan/tdb2/test/run-11-simple-fetch.c +++ b/ccan/tdb2/test/run-11-simple-fetch.c @@ -1,12 +1,20 @@ -#include -#include -#include -#include -#include -#include -#include +#include +#include "tdb2-source.h" #include +#include #include "logging.h" +#include "failtest_helper.h" + +static bool failtest_suppress = false; + +/* Don't need to test everything here, just want fetch testing. */ +static enum failtest_result +suppress_failure(struct failtest_call *history, unsigned num) +{ + if (failtest_suppress) + return FAIL_DONT_FAIL; + return block_repeat_failures(history, num); +} int main(int argc, char *argv[]) { @@ -15,26 +23,37 @@ int main(int argc, char *argv[]) int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP, TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT, TDB_NOMMAP|TDB_CONVERT }; - struct tdb_data key = { (unsigned char *)"key", 3 }; - struct tdb_data data = { (unsigned char *)"data", 4 }; + struct tdb_data key = tdb_mkdata("key", 3); + struct tdb_data data = tdb_mkdata("data", 4); + + failtest_init(argc, argv); + failtest_hook = suppress_failure; + failtest_exit_check = exit_check_log; + failtest_suppress = true; plan_tests(sizeof(flags) / sizeof(flags[0]) * 8 + 1); for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { tdb = tdb_open("run-11-simple-fetch.tdb", flags[i], O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr); ok1(tdb); if (tdb) { - struct tdb_data d; + struct tdb_data d = { NULL, 0 }; /* Bogus GCC warning */ /* fetch should fail. */ - ok1(tdb_fetch(tdb, key, &d) == TDB_ERR_NOEXIST); + failtest_suppress = false; + if (!ok1(tdb_fetch(tdb, key, &d) == TDB_ERR_NOEXIST)) + goto fail; + failtest_suppress = true; ok1(tdb_check(tdb, NULL, NULL) == 0); /* Insert should succeed. */ ok1(tdb_store(tdb, key, data, TDB_INSERT) == 0); ok1(tdb_check(tdb, NULL, NULL) == 0); /* Fetch should now work. */ - ok1(tdb_fetch(tdb, key, &d) == TDB_SUCCESS); - ok1(data_equal(d, data)); + failtest_suppress = false; + if (!ok1(tdb_fetch(tdb, key, &d) == TDB_SUCCESS)) + goto fail; + failtest_suppress = true; + ok1(tdb_deq(d, data)); free(d.dptr); ok1(tdb_check(tdb, NULL, NULL) == 0); tdb_close(tdb); @@ -42,4 +61,9 @@ int main(int argc, char *argv[]) } ok1(tap_log_messages == 0); return exit_status(); + +fail: + failtest_suppress = true; + tdb_close(tdb); + failtest_exit(exit_status()); }