diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-12-05 16:42:48 +1030 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-12-05 16:42:48 +1030 |
commit | 5917d979911b024714d2d3a7b64255bffa37ec60 (patch) | |
tree | e010d41c30e9fd777032110c63d6f4bbdcd9a229 /lib/ccan/likely/test | |
parent | e1374049678842f5086f174d97ae916345686f87 (diff) | |
download | samba-5917d979911b024714d2d3a7b64255bffa37ec60.tar.gz samba-5917d979911b024714d2d3a7b64255bffa37ec60.tar.bz2 samba-5917d979911b024714d2d3a7b64255bffa37ec60.zip |
lib/ccan/likely: use htable_type
Also general cleanups:
(1) Don't assume that strings are folded by the compiler.
(2) Implement likely_stats_reset().
(3) Return non-const string from likely_stats(), as caller must free it.
(4) Don't use struct info indirection (that was from when we used callbacks?)
(5) Close memory leak in run-debug.c
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
(Imported from CCAN commit 0e5d0e30b30bb07b6605843e5ff224210d8083d8)
Diffstat (limited to 'lib/ccan/likely/test')
-rw-r--r-- | lib/ccan/likely/test/run-debug.c | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/ccan/likely/test/run-debug.c b/lib/ccan/likely/test/run-debug.c index df78619271..afb21e2be2 100644 --- a/lib/ccan/likely/test/run-debug.c +++ b/lib/ccan/likely/test/run-debug.c @@ -28,9 +28,9 @@ static bool likely_one_unlikely_two(unsigned int val1, unsigned int val2) int main(int argc, char *argv[]) { - 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,9 +80,19 @@ 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)); |