diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2011-06-20 16:54:15 +0930 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2011-06-20 11:18:34 +0200 |
commit | 754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e (patch) | |
tree | 54d99c9f66d5a57bf7f70d53e744a31df18f9e0e /lib/ccan/likely/test | |
parent | a8c3d38bc806c6972d10b6a371de8941da25a9ae (diff) | |
download | samba-754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e.tar.gz samba-754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e.tar.bz2 samba-754c677b0bbf3ea6c7d2a73c93848f1b0d68c91e.zip |
lib: import ccan modules for tdb2
Imported from git://git.ozlabs.org/~ccan/ccan init-1161-g661d41f
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Diffstat (limited to 'lib/ccan/likely/test')
-rw-r--r-- | lib/ccan/likely/test/run-debug.c | 87 | ||||
-rw-r--r-- | lib/ccan/likely/test/run.c | 30 |
2 files changed, 117 insertions, 0 deletions
diff --git a/lib/ccan/likely/test/run-debug.c b/lib/ccan/likely/test/run-debug.c new file mode 100644 index 0000000000..df78619271 --- /dev/null +++ b/lib/ccan/likely/test/run-debug.c @@ -0,0 +1,87 @@ +#define CCAN_LIKELY_DEBUG 1 +#include <ccan/likely/likely.c> +#include <ccan/likely/likely.h> +#include <ccan/tap/tap.h> +#include <stdlib.h> + +static bool one_seems_likely(unsigned int val) +{ + if (likely(val == 1)) + return true; + return false; +} + +static bool one_seems_unlikely(unsigned int val) +{ + if (unlikely(val == 1)) + return true; + return false; +} + +static bool likely_one_unlikely_two(unsigned int val1, unsigned int val2) +{ + /* Same line, check we don't get confused! */ + if (likely(val1 == 1) && unlikely(val2 == 2)) + return true; + return false; +} + +int main(int argc, char *argv[]) +{ + const char *bad; + + plan_tests(13); + + /* Correct guesses. */ + one_seems_likely(1); + ok1(likely_stats(0, 90) == NULL); + one_seems_unlikely(2); + ok1(likely_stats(0, 90) == NULL); + + /* Incorrect guesses. */ + one_seems_likely(0); + one_seems_likely(2); + /* Hasn't been hit 4 times, so this fails */ + ok1(!likely_stats(4, 90)); + bad = likely_stats(3, 90); + ok(strends(bad, "run-debug.c:9:likely(val == 1) correct 33% (1/3)"), + "likely_stats returned %s", bad); + + /* Nothing else above 90% */ + ok1(!likely_stats(0, 90)); + + /* This should get everything. */ + bad = likely_stats(0, 100); + ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 100% (1/1)"), + "likely_stats returned %s", bad); + + /* Nothing left (table is actually cleared) */ + ok1(!likely_stats(0, 100)); + + /* Make sure unlikely works */ + one_seems_unlikely(0); + one_seems_unlikely(2); + one_seems_unlikely(1); + + bad = likely_stats(0, 90); + ok(strends(bad, "run-debug.c:16:unlikely(val == 1) correct 66% (2/3)"), + "likely_stats returned %s", bad); + ok1(!likely_stats(0, 100)); + + likely_one_unlikely_two(1, 1); + likely_one_unlikely_two(1, 1); + likely_one_unlikely_two(1, 1); + ok1(!likely_stats(0, 90)); + likely_one_unlikely_two(1, 2); + + bad = likely_stats(0, 90); + ok(strends(bad, "run-debug.c:24:unlikely(val2 == 2) correct 75% (3/4)"), + "likely_stats returned %s", 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); + + ok1(!likely_stats(0, 100)); + + exit(exit_status()); +} diff --git a/lib/ccan/likely/test/run.c b/lib/ccan/likely/test/run.c new file mode 100644 index 0000000000..fa1dc9f6ea --- /dev/null +++ b/lib/ccan/likely/test/run.c @@ -0,0 +1,30 @@ +#include <ccan/likely/likely.c> +#include <ccan/likely/likely.h> +#include <ccan/tap/tap.h> +#include <stdlib.h> + +static bool one_seems_likely(unsigned int val) +{ + if (likely(val == 1)) + return true; + return false; +} + +static bool one_seems_unlikely(unsigned int val) +{ + if (unlikely(val == 1)) + return true; + return false; +} + +int main(int argc, char *argv[]) +{ + plan_tests(4); + + /* Without debug, we can only check that it doesn't effect functions. */ + ok1(one_seems_likely(1)); + ok1(!one_seems_likely(2)); + ok1(one_seems_unlikely(1)); + ok1(!one_seems_unlikely(2)); + exit(exit_status()); +} |