1
1

tests: Migrate torture_sftp_read to a cwrap test

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Этот коммит содержится в:
Andreas Schneider 2015-09-16 08:41:19 +02:00
родитель af3de262b6
Коммит 571f547556
2 изменённых файлов: 46 добавлений и 31 удалений

Просмотреть файл

@ -4,7 +4,6 @@ find_package(socket_wrapper)
if (WITH_SFTP)
add_cmocka_test(torture_sftp_static torture_sftp_static.c ${TORTURE_LIBRARY})
add_cmocka_test(torture_sftp_read torture_sftp_read.c ${TORTURE_LIBRARY})
endif (WITH_SFTP)
set(LIBSSH_CLIENT_TESTS
@ -20,7 +19,8 @@ set(LIBSSH_CLIENT_TESTS
if (WITH_SFTP)
set(LIBSSH_CLIENT_TESTS
${LIBSSH_CLIENT_TESTS}
torture_sftp_dir)
torture_sftp_dir
torture_sftp_read)
endif (WITH_SFTP)
foreach(_CLI_TEST ${LIBSSH_CLIENT_TESTS})

Просмотреть файл

@ -3,48 +3,61 @@
#include "torture.h"
#include "sftp.c"
#include <sys/types.h>
#include <pwd.h>
#define MAX_XFER_BUF_SIZE 16384
static int setup(void **state)
static int sshd_setup(void **state)
{
ssh_session session;
struct torture_sftp *t;
const char *host;
const char *user;
const char *password;
host = getenv("TORTURE_HOST");
if (host == NULL) {
host = "localhost";
}
user = getenv("TORTURE_USER");
password = getenv("TORTURE_PASSWORD");
session = torture_ssh_session(host, NULL, user, password);
assert_false(session == NULL);
t = torture_sftp_session(session);
assert_false(t == NULL);
*state = t;
torture_setup_sshd_server(state);
return 0;
}
static int teardown(void **state)
static int sshd_teardown(void **state) {
torture_teardown_sshd_server(state);
return 0;
}
static int session_setup(void **state)
{
struct torture_sftp *t = (struct torture_sftp*) *state;
struct torture_state *s = *state;
struct passwd *pwd;
assert_false(t == NULL);
pwd = getpwnam("bob");
assert_non_null(pwd);
setuid(pwd->pw_uid);
torture_rmdirs(t->testdir);
torture_sftp_close(t);
s->ssh.session = torture_ssh_session(TORTURE_SSH_SERVER,
NULL,
TORTURE_SSH_USER_ALICE,
NULL);
assert_non_null(s->ssh.session);
s->ssh.tsftp = torture_sftp_session(s->ssh.session);
assert_non_null(s->ssh.tsftp);
return 0;
}
static int session_teardown(void **state)
{
struct torture_state *s = *state;
torture_rmdirs(s->ssh.tsftp->testdir);
torture_sftp_close(s->ssh.tsftp);
ssh_disconnect(s->ssh.session);
ssh_free(s->ssh.session);
return 0;
}
static void torture_sftp_read_blocking(void **state) {
struct torture_sftp *t = (struct torture_sftp*) *state;
struct torture_state *s = *state;
struct torture_sftp *t = s->ssh.tsftp;
char libssh_tmp_file[] = "/tmp/libssh_sftp_test_XXXXXX";
char buf[MAX_XFER_BUF_SIZE];
ssize_t bytesread;
@ -79,13 +92,15 @@ static void torture_sftp_read_blocking(void **state) {
int torture_run_tests(void) {
int rc;
struct CMUnitTest tests[] = {
cmocka_unit_test_setup_teardown(torture_sftp_read_blocking, setup, teardown)
cmocka_unit_test_setup_teardown(torture_sftp_read_blocking,
session_setup,
session_teardown)
};
ssh_init();
torture_filter_tests(tests);
rc = cmocka_run_group_tests(tests, NULL, NULL);
rc = cmocka_run_group_tests(tests, sshd_setup, sshd_teardown);
ssh_finalize();
return rc;