diff options
author | Andreas Schneider <asn@cynapses.org> | 2010-12-28 15:10:34 +0100 |
---|---|---|
committer | Andreas Schneider <asn@cynapses.org> | 2010-12-28 22:14:47 +0100 |
commit | b0446ad55d8949ffdb34f487ee0028bb1b5622e0 (patch) | |
tree | 7523830dd2e72d18d8cfdb89a3ff7fe2be7deaf5 | |
parent | d04ce30b037edf59caafb486921c9af114a22d04 (diff) | |
download | libssh-b0446ad55d8949ffdb34f487ee0028bb1b5622e0.tar.gz libssh-b0446ad55d8949ffdb34f487ee0028bb1b5622e0.tar.xz libssh-b0446ad55d8949ffdb34f487ee0028bb1b5622e0.zip |
tests: Migrated torture_rand to cmockery.
-rw-r--r-- | tests/unittests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/unittests/torture_rand.c | 74 |
2 files changed, 41 insertions, 35 deletions
diff --git a/tests/unittests/CMakeLists.txt b/tests/unittests/CMakeLists.txt index f3375c90..1049805b 100644 --- a/tests/unittests/CMakeLists.txt +++ b/tests/unittests/CMakeLists.txt @@ -7,4 +7,4 @@ add_cmockery_test(torture_keyfiles torture_keyfiles.c ${TORTURE_LIBRARY}) add_cmockery_test(torture_list torture_list.c ${TORTURE_LIBRARY}) add_cmockery_test(torture_misc torture_misc.c ${TORTURE_LIBRARY}) add_cmockery_test(torture_options torture_options.c ${TORTURE_LIBRARY}) -#add_check_test(torture_rand torture_rand.c ${TORTURE_LIBRARY}) +add_cmockery_test(torture_rand torture_rand.c ${TORTURE_LIBRARY}) diff --git a/tests/unittests/torture_rand.c b/tests/unittests/torture_rand.c index 847fe407..71e8bf18 100644 --- a/tests/unittests/torture_rand.c +++ b/tests/unittests/torture_rand.c @@ -13,49 +13,55 @@ #endif #define NUM_THREADS 100 -static void setup(){ - ssh_threads_set_callbacks(ssh_threads_get_pthread()); - ssh_init(); -} +static void setup(void **state) { + (void) state; -static void teardown(){ - ssh_finalize(); + ssh_threads_set_callbacks(ssh_threads_get_pthread()); + ssh_init(); } -static void *torture_rand_thread(void *threadid){ - char buffer[12]; - int i; - int r; - (void)threadid; - buffer[0]=buffer[1]=buffer[10]=buffer[11]='X'; - for(i=0;i<NUM_LOOPS;++i){ - r=ssh_get_random(&buffer[2], i%8+1 ,0); - } - pthread_exit(NULL); +static void teardown(void **state) { + (void) state; + + ssh_finalize(); } -START_TEST(torture_rand_threading) -{ - pthread_t threads[NUM_THREADS]; - int i; - int err; - for(i=0;i<NUM_THREADS;++i){ - err=pthread_create(&threads[i],NULL,torture_rand_thread,NULL); - ck_assert_int_eq(err,0); - } - for(i=0;i<NUM_THREADS;++i){ - err=pthread_join(threads[i], NULL); - ck_assert_int_eq(err,0); - } +static void *torture_rand_thread(void *threadid) { + char buffer[12]; + int i; + int r; + + (void) threadid; + + buffer[0] = buffer[1] = buffer[10] = buffer[11] = 'X'; + for(i = 0; i < NUM_LOOPS; ++i) { + r = ssh_get_random(&buffer[2], i % 8 + 1, 0); + } + + pthread_exit(NULL); } -END_TEST +static void torture_rand_threading(void **state) { + pthread_t threads[NUM_THREADS]; + int i; + int err; + (void) state; -Suite *torture_make_suite(void) { - Suite *s = suite_create("torture_rand"); + for(i = 0; i < NUM_THREADS; ++i) { + err = pthread_create(&threads[i], NULL, torture_rand_thread, NULL); + assert_int_equal(err, 0); + } + for(i = 0; i < NUM_THREADS; ++i) { + err=pthread_join(threads[i], NULL); + assert_int_equal(err, 0); + } +} - torture_create_case_fixture(s, "torture_rand_threading", torture_rand_threading,setup,teardown); +int torture_run_tests(void) { + const UnitTest tests[] = { + unit_test_setup_teardown(torture_rand_threading, setup, teardown), + }; - return s; + return run_tests(tests); } |