1
1
libssh/tests/unittests/torture_rand.c
Aris Adamantiadis 2cca490076 Moved pthread specific code in src/threads/pthread.c
pthread example doesn't compile du to the lack of
libssh_threads_native.so library
2010-09-06 14:51:01 +02:00

59 строки
1.1 KiB
C

#define LIBSSH_STATIC
#include <libssh/priv.h>
#include <libssh/callbacks.h>
#include <pthread.h>
#include <errno.h>
#include "torture.h"
#ifdef HAVE_LIBGCRYPT
#define NUM_LOOPS 1000
#else
/* openssl is much faster */
#define NUM_LOOPS 20000
#endif
#define NUM_THREADS 100
static void setup(){
printf("setup\n");
ssh_threads_set_callbacks(&ssh_pthread_callbacks);
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);
}
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);
}
}
END_TEST
Suite *torture_make_suite(void) {
Suite *s = suite_create("torture_rand");
torture_create_case_fixture(s, "torture_rand_threading", torture_rand_threading,setup,NULL);
return s;
}