diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-03-06 18:06:08 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-03-06 18:06:08 -0500 |
commit | 1365ff5b9a04a7da2acc2e52df18a61b6cb39fe6 (patch) | |
tree | 0ada1a483eab86cdda00ea3728394a5482376b60 /src/ext/tinytest_demo.c | |
parent | 065097b81bad3326a9bd536fbdf646f408638a94 (diff) | |
download | tor-1365ff5b9a04a7da2acc2e52df18a61b6cb39fe6.tar.gz tor-1365ff5b9a04a7da2acc2e52df18a61b6cb39fe6.zip |
Upgrade to the latest version of tinytest.
This brings us to tinytest commit 709a36ba63ff16d8.
The only big change tor-side is that we don't need our own test_mem_op
operation any longer.
Diffstat (limited to 'src/ext/tinytest_demo.c')
-rw-r--r-- | src/ext/tinytest_demo.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/ext/tinytest_demo.c b/src/ext/tinytest_demo.c index be95ce4c1d..bdd0e60089 100644 --- a/src/ext/tinytest_demo.c +++ b/src/ext/tinytest_demo.c @@ -35,6 +35,10 @@ #include <stdlib.h> #include <string.h> #include <errno.h> +#include <time.h> +#ifndef _WIN32 +#include <unistd.h> +#endif /* ============================================================ */ @@ -148,6 +152,9 @@ test_memcpy(void *ptr) memcpy(db->buffer2, db->buffer1, sizeof(db->buffer1)); tt_str_op(db->buffer1, ==, db->buffer2); + /* This one works if there's an internal NUL. */ + tt_mem_op(db->buffer1, <, db->buffer2, sizeof(db->buffer1)); + /* Now we've allocated memory that's referenced by a local variable. The end block of the function will clean it up. */ mem = strdup("Hello world."); @@ -162,6 +169,27 @@ test_memcpy(void *ptr) free(mem); } +void +test_timeout(void *ptr) +{ + time_t t1, t2; + (void)ptr; + t1 = time(NULL); +#ifdef _WIN32 + Sleep(5000); +#else + sleep(5); +#endif + t2 = time(NULL); + + tt_int_op(t2-t1, >=, 4); + + tt_int_op(t2-t1, <=, 6); + + end: + ; +} + /* ============================================================ */ /* Now we need to make sure that our tests get invoked. First, you take @@ -178,6 +206,10 @@ struct testcase_t demo_tests[] = { its environment. */ { "memcpy", test_memcpy, TT_FORK, &data_buffer_setup }, + /* This flag is off-by-default, since it takes a while to run. You + * can enable it manually by passing +demo/timeout at the command line.*/ + { "timeout", test_timeout, TT_OFF_BY_DEFAULT }, + /* The array has to end with END_OF_TESTCASES. */ END_OF_TESTCASES }; @@ -192,6 +224,18 @@ struct testgroup_t groups[] = { END_OF_GROUPS }; +/* We can also define test aliases. These can be used for types of tests that + * cut across groups. */ +const char *alltests[] = { "+..", NULL }; +const char *slowtests[] = { "+demo/timeout", NULL }; +struct testlist_alias_t aliases[] = { + + { "ALL", alltests }, + { "SLOW", slowtests }, + + END_OF_ALIASES +}; + int main(int c, const char **v) @@ -211,5 +255,6 @@ main(int c, const char **v) "tinytest-demo" and "tinytest-demo .." mean the same thing. */ + tinytest_set_aliases(aliases); return tinytest_main(c, v, groups); } |