mirror of
https://git.libssh.org/projects/libssh.git
synced 2025-08-05 20:55:46 +03:00
tests: Migrated torture_rand to cmockery.
This commit is contained in:
@@ -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_list torture_list.c ${TORTURE_LIBRARY})
|
||||||
add_cmockery_test(torture_misc torture_misc.c ${TORTURE_LIBRARY})
|
add_cmockery_test(torture_misc torture_misc.c ${TORTURE_LIBRARY})
|
||||||
add_cmockery_test(torture_options torture_options.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})
|
||||||
|
@@ -13,12 +13,16 @@
|
|||||||
#endif
|
#endif
|
||||||
#define NUM_THREADS 100
|
#define NUM_THREADS 100
|
||||||
|
|
||||||
static void setup(){
|
static void setup(void **state) {
|
||||||
|
(void) state;
|
||||||
|
|
||||||
ssh_threads_set_callbacks(ssh_threads_get_pthread());
|
ssh_threads_set_callbacks(ssh_threads_get_pthread());
|
||||||
ssh_init();
|
ssh_init();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void teardown(){
|
static void teardown(void **state) {
|
||||||
|
(void) state;
|
||||||
|
|
||||||
ssh_finalize();
|
ssh_finalize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,36 +30,38 @@ static void *torture_rand_thread(void *threadid){
|
|||||||
char buffer[12];
|
char buffer[12];
|
||||||
int i;
|
int i;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
(void) threadid;
|
(void) threadid;
|
||||||
|
|
||||||
buffer[0] = buffer[1] = buffer[10] = buffer[11] = 'X';
|
buffer[0] = buffer[1] = buffer[10] = buffer[11] = 'X';
|
||||||
for(i = 0; i < NUM_LOOPS; ++i) {
|
for(i = 0; i < NUM_LOOPS; ++i) {
|
||||||
r = ssh_get_random(&buffer[2], i % 8 + 1, 0);
|
r = ssh_get_random(&buffer[2], i % 8 + 1, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
pthread_exit(NULL);
|
pthread_exit(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
START_TEST(torture_rand_threading)
|
static void torture_rand_threading(void **state) {
|
||||||
{
|
|
||||||
pthread_t threads[NUM_THREADS];
|
pthread_t threads[NUM_THREADS];
|
||||||
int i;
|
int i;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
(void) state;
|
||||||
|
|
||||||
for(i = 0; i < NUM_THREADS; ++i) {
|
for(i = 0; i < NUM_THREADS; ++i) {
|
||||||
err = pthread_create(&threads[i], NULL, torture_rand_thread, NULL);
|
err = pthread_create(&threads[i], NULL, torture_rand_thread, NULL);
|
||||||
ck_assert_int_eq(err,0);
|
assert_int_equal(err, 0);
|
||||||
}
|
}
|
||||||
for(i = 0; i < NUM_THREADS; ++i) {
|
for(i = 0; i < NUM_THREADS; ++i) {
|
||||||
err=pthread_join(threads[i], NULL);
|
err=pthread_join(threads[i], NULL);
|
||||||
ck_assert_int_eq(err,0);
|
assert_int_equal(err, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_TEST
|
|
||||||
|
|
||||||
|
int torture_run_tests(void) {
|
||||||
|
const UnitTest tests[] = {
|
||||||
|
unit_test_setup_teardown(torture_rand_threading, setup, teardown),
|
||||||
|
};
|
||||||
|
|
||||||
|
return run_tests(tests);
|
||||||
Suite *torture_make_suite(void) {
|
|
||||||
Suite *s = suite_create("torture_rand");
|
|
||||||
|
|
||||||
torture_create_case_fixture(s, "torture_rand_threading", torture_rand_threading,setup,teardown);
|
|
||||||
|
|
||||||
return s;
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user