2010-08-30 16:08:07 +04:00
|
|
|
#define LIBSSH_STATIC
|
|
|
|
#include <libssh/priv.h>
|
2010-09-03 14:03:04 +04:00
|
|
|
#include <libssh/callbacks.h>
|
2010-08-30 16:08:07 +04:00
|
|
|
#include <pthread.h>
|
2010-09-03 14:03:04 +04:00
|
|
|
#include <errno.h>
|
2010-08-30 16:08:07 +04:00
|
|
|
#include "torture.h"
|
|
|
|
|
2010-09-01 16:07:45 +04:00
|
|
|
#ifdef HAVE_LIBGCRYPT
|
2010-08-31 18:49:55 +04:00
|
|
|
#define NUM_LOOPS 1000
|
2010-09-01 16:07:45 +04:00
|
|
|
#else
|
|
|
|
/* openssl is much faster */
|
|
|
|
#define NUM_LOOPS 20000
|
|
|
|
#endif
|
2010-08-31 18:49:55 +04:00
|
|
|
#define NUM_THREADS 100
|
2010-08-30 16:08:07 +04:00
|
|
|
|
2015-09-07 11:39:51 +03:00
|
|
|
static int setup(void **state) {
|
2010-12-28 17:10:34 +03:00
|
|
|
(void) state;
|
2010-08-30 16:08:07 +04:00
|
|
|
|
2010-12-28 17:10:34 +03:00
|
|
|
ssh_threads_set_callbacks(ssh_threads_get_pthread());
|
|
|
|
ssh_init();
|
2015-09-07 11:39:51 +03:00
|
|
|
|
|
|
|
return 0;
|
2010-12-19 14:37:21 +03:00
|
|
|
}
|
|
|
|
|
2015-09-07 11:39:51 +03:00
|
|
|
static int teardown(void **state) {
|
2010-12-28 17:10:34 +03:00
|
|
|
(void) state;
|
|
|
|
|
|
|
|
ssh_finalize();
|
2015-09-07 11:39:51 +03:00
|
|
|
|
|
|
|
return 0;
|
2010-08-30 16:08:07 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 17:10:34 +03:00
|
|
|
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);
|
2011-01-06 12:13:06 +03:00
|
|
|
assert_true(r == 1);
|
2010-12-28 17:10:34 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
pthread_exit(NULL);
|
2010-08-30 16:08:07 +04:00
|
|
|
}
|
|
|
|
|
2010-12-28 17:10:34 +03:00
|
|
|
static void torture_rand_threading(void **state) {
|
|
|
|
pthread_t threads[NUM_THREADS];
|
|
|
|
int i;
|
|
|
|
int err;
|
2010-08-30 16:08:07 +04:00
|
|
|
|
2010-12-28 17:10:34 +03:00
|
|
|
(void) state;
|
2010-08-30 16:08:07 +04:00
|
|
|
|
2010-12-28 17:10:34 +03:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2010-08-30 16:08:07 +04:00
|
|
|
|
2010-12-28 17:10:34 +03:00
|
|
|
int torture_run_tests(void) {
|
2015-09-07 11:39:51 +03:00
|
|
|
int rc;
|
|
|
|
struct CMUnitTest tests[] = {
|
|
|
|
cmocka_unit_test_setup_teardown(torture_rand_threading, setup, teardown),
|
2010-12-28 17:10:34 +03:00
|
|
|
};
|
2010-08-30 16:08:07 +04:00
|
|
|
|
2014-09-02 11:07:17 +04:00
|
|
|
torture_filter_tests(tests);
|
2015-09-07 11:39:51 +03:00
|
|
|
rc = cmocka_run_group_tests(tests, NULL, NULL);
|
|
|
|
|
|
|
|
return rc;
|
2010-08-30 16:08:07 +04:00
|
|
|
}
|