diff options
author | comex | 2015-01-29 01:48:09 -0500 |
---|---|---|
committer | comex | 2015-01-29 01:48:17 -0500 |
commit | 5d7d4cdf531234390055540dc4ccc478268b0588 (patch) | |
tree | 4bda0d50e2284986d730efe7ce9db77a28f51b3f /test | |
parent | port some old code (diff) | |
download | substitute-5d7d4cdf531234390055540dc4ccc478268b0588.tar.gz |
get rid of the unnecessary CoreFoundation dependency
Diffstat (limited to 'test')
-rw-r--r-- | test/test-htab.c | 17 | ||||
-rw-r--r-- | test/test-stop-threads.c | 15 |
2 files changed, 26 insertions, 6 deletions
diff --git a/test/test-htab.c b/test/test-htab.c index 2986de8..ad23cdb 100644 --- a/test/test-htab.c +++ b/test/test-htab.c @@ -1,6 +1,7 @@ #include "cbit/htab.h" #include <string.h> #include <stdio.h> +#include <assert.h> struct teststr { bool valid; const char *what; @@ -19,15 +20,23 @@ int main() { for(int i = 0; i < 100; i++) { const char *k; asprintf((char **) &k, "foo%d", i); - *htab_setp_teststr_int(hp, &k) = i; + bool new; + *htab_setp_teststr_int(hp, &k, &new) = i; + assert(new); + } + { + const char *k = "foo31"; + bool new; + htab_setp_teststr_int(hp, &k, NULL); + htab_setp_teststr_int(hp, &k, &new); + assert(!new); + htab_remove_teststr_int(hp, &k); } - const char *to_remove = "foo31"; - htab_remove_teststr_int(hp, &to_remove); HTAB_FOREACH(hp, const char **k, int *v, teststr_int) { if(*v % 10 == 1) printf("%s -> %d\n", *k, *v); } - htab_free_teststr_int(hp); + htab_free_storage_teststr_int(hp); } /* diff --git a/test/test-stop-threads.c b/test/test-stop-threads.c index 829e73e..d53d8cd 100644 --- a/test/test-stop-threads.c +++ b/test/test-stop-threads.c @@ -4,15 +4,22 @@ #include <unistd.h> #include <pthread.h> #include <assert.h> +/* printf without taking any locks - because they might be taken at stop time */ +#define ulprintf(...) do { \ + char buf[256]; \ + int len = sprintf(buf, __VA_ARGS__); \ + write(1, buf, len); \ +} while(0) + static void *some_thread(void *ip) { long i = (long) ip; while (1) { - printf("Hello from %ld\n", i); + ulprintf("Hello from %ld\n", i); sleep(1); } } static void replacement() { - printf("Bye\n"); + ulprintf("Bye\n"); pthread_exit(NULL); } static uintptr_t patch_callback(void *ctx, UNUSED uintptr_t pc) { @@ -26,9 +33,13 @@ int main() { pthread_create(&pts[i], NULL, some_thread, (void *) i); sleep(1); void *stop_token; + ulprintf("stopping\n"); assert(!stop_other_threads(&stop_token)); + ulprintf("stopped\n"); assert(!apply_pc_patch_callback(stop_token, patch_callback, NULL)); + ulprintf("resuming\n"); assert(!resume_other_threads(stop_token)); + ulprintf("resumed\n"); void *out; for (long i = 0; i < 10; i++) assert(!pthread_join(pts[i], &out)); |