X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Flikely%2Ftest%2Frun-debug.c;h=72015ee42858301bd343572fead21ae9cce81a2b;hp=198ac5b79e6424099a37f3fc87604f5273f93507;hb=61f58ff94e35c9b8ac5488554e2554bc5c9888b3;hpb=9f8c65b28acba8e5eabea5d7abd98b19e62d06fe diff --git a/ccan/likely/test/run-debug.c b/ccan/likely/test/run-debug.c index 198ac5b7..72015ee4 100644 --- a/ccan/likely/test/run-debug.c +++ b/ccan/likely/test/run-debug.c @@ -1,4 +1,4 @@ -#define DEBUG 1 +#define CCAN_LIKELY_DEBUG 1 #include #include #include @@ -26,11 +26,11 @@ static bool likely_one_unlikely_two(unsigned int val1, unsigned int val2) return false; } -int main(int argc, char *argv[]) +int main(void) { - const char *bad; + char *bad; - plan_tests(13); + plan_tests(14); /* Correct guesses. */ one_seems_likely(1); @@ -46,6 +46,7 @@ int main(int argc, char *argv[]) bad = likely_stats(3, 90); ok(strends(bad, "run-debug.c:9:likely(val == 1) correct 33% (1/3)"), "likely_stats returned %s", bad); + free(bad); /* Nothing else above 90% */ ok1(!likely_stats(0, 90)); @@ -54,6 +55,7 @@ int main(int argc, char *argv[]) bad = likely_stats(0, 100); ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 100% (1/1)"), "likely_stats returned %s", bad); + free(bad); /* Nothing left (table is actually cleared) */ ok1(!likely_stats(0, 100)); @@ -66,6 +68,7 @@ int main(int argc, char *argv[]) bad = likely_stats(0, 90); ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 66% (2/3)"), "likely_stats returned %s", bad); + free(bad); ok1(!likely_stats(0, 100)); likely_one_unlikely_two(1, 1); @@ -77,11 +80,26 @@ int main(int argc, char *argv[]) bad = likely_stats(0, 90); ok(strends(bad, "run-debug.c:24:unlikely(val2 == 2) correct 75% (3/4)"), "likely_stats returned %s", bad); + free(bad); bad = likely_stats(0, 100); ok(strends(bad, "run-debug.c:24:likely(val1 == 1) correct 100% (4/4)"), "likely_stats returned %s", bad); + free(bad); + + ok1(!likely_stats(0, 100)); + + /* Check that reset works! */ + one_seems_unlikely(0); + one_seems_unlikely(2); + one_seems_unlikely(1); + likely_stats_reset(); ok1(!likely_stats(0, 100)); exit(exit_status()); } + +/* Fools ccanlint: it doesn't think we use str, htable or hash. */ +#include +#include +#include