00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "vfer_api.h"
00018 #include "vsl_util.h"
00019 #include "vsl_api.h"
00020 #include "vfer_tests.h"
00021
00022
00023 enum status {
00024 READ,
00025 WROTE
00026 };
00027
00028
00029 #define TESTSIZE 63*1024
00030
00031
00032
00033
00034 int main (int argc, char** argv) {
00035 TEST_INIT("VSL_TEST_SSH", "vsl_test_ssh.c", stdout, stdout);
00036 vsl_sock sock1, sock2, sock3;
00037 vfer_fd vfd;
00038 char errmsg[512];
00039
00040 ASSERT(vsl_init() == 0);
00041
00042
00043 int sargc=0;
00044 char **sargv1, **sargv2, **sargv3;
00045 if ( argc == 3 ) {
00046 vsl_debug(stdout, NULL);
00047 sargc = 1;
00048 sargv1 = (char*[]) { "vsl_test_ssh_1.log" };
00049 sargv2 = (char*[]) { "vsl_test_ssh_2.log" };
00050 sargv3 = (char*[]) { "vsl_test_ssh_3.log" };
00051 }
00052
00053
00054 char buf[TESTSIZE];
00055 const size_t buflen = sizeof(buf);
00056 char buf2[buflen];
00057 int fd;
00058 ASSERT( (fd = open(RANDDEV, 0)) >= 0);
00059 ASSERT( read(fd, (void*)buf, TESTSIZE) == TESTSIZE );
00060 ASSERT( close(fd) == 0 );
00061
00062
00063 ASSERT((vfd = vfer_socket(SOCK_DGRAM)) >= 0);
00064 ASSERT( vsl_socket(&sock1, vfd) == 0);
00065 vsl_test_mode(&sock1);
00066 set_blocking(&sock1, true);
00067 ASSERT( vsl_connect_ssh(&sock1, "localhost", NULL,
00068 argv[1], sargc, (const char* const*) sargv1, errmsg) == 0);
00069 ASSERT( vsl_send(&sock1, buf, buflen) == buflen );
00070 ASSERT( vsl_recv(&sock1, buf2, buflen) == buflen );
00071 ASSERT( memcmp(buf, buf2, buflen) == 0 );
00072 set_blocking(&sock1, false);
00073
00074
00075
00076 ASSERT((vfd = vfer_socket(SOCK_DGRAM)) >= 0);
00077 ASSERT( vsl_socket(&sock2, vfd) == 0);
00078 ASSERT( vsl_connect_ssh(&sock2, "localhost", NULL,
00079 argv[1], sargc, (const char* const*) sargv2, errmsg) == 0);
00080 vsl_test_mode(&sock2);
00081 ASSERT( vsl_send(&sock1, buf, buflen) == buflen );
00082 set_blocking(&sock2, false);
00083
00084
00085 ASSERT((vfd = vfer_socket(SOCK_DGRAM)) >= 0);
00086 ASSERT( vsl_socket(&sock3, vfd) == 0);
00087 vsl_test_mode(&sock3);
00088 set_blocking(&sock3, false);
00089
00090
00091 bool s3_connected = false;
00092 enum status s1_stat = READ;
00093 enum status s2_stat = WROTE;
00094 int vsl_connect_ssh_ret;
00095 int maxtries = 20;
00096 int num_read = 0;
00097 int num_written = 0;
00098 do {
00099 ASSERT( vsl_selectmark(&sock3, VSL_AUTHABLE | VSL_EXCEPTION) == 0 );
00100 #define SETMARK(SOCK) do { \
00101 if ( s ## SOCK ## _stat == WROTE ) \
00102 ASSERT( vsl_selectmark(&sock ## SOCK, VSL_READABLE | VSL_EXCEPTION) == 0 ); \
00103 else \
00104 ASSERT( vsl_selectmark(&sock ## SOCK, VSL_WRITABLE | VSL_EXCEPTION) == 0 ); \
00105 } while(0)
00106 SETMARK(2);
00107 SETMARK(1);
00108 ASSERT( vsl_selectpoll(3, (vsl_sock*[]) { &sock1, &sock2, &sock3 }, NULL, 1000000) > 0 );
00109
00110
00111 ASSERT( vsl_selecttest(&sock3) == VSL_AUTHABLE ||
00112 vsl_selecttest(&sock3) == 0);
00113 if ( vsl_selecttest(&sock3) == VSL_AUTHABLE ) {
00114 vsl_connect_ssh_ret =
00115 vsl_connect_ssh(&sock3, "localhost", NULL,
00116 argv[1], sargc, (const char* const*) sargv3, errmsg);
00117 ASSERT(vsl_connect_ssh_ret == VFER_INPROGRESS ||
00118 vsl_connect_ssh_ret == 0);
00119 if ( vsl_connect_ssh_ret == 0 )
00120 s3_connected = true;
00121 }
00122
00123 #define READWRITE(NR) do { \
00124 \
00125 if ( s ## NR ## _stat == WROTE ) { \
00126 ASSERT( vsl_selecttest(&sock ## NR) == VSL_READABLE || \
00127 vsl_selecttest(&sock ## NR) == 0); \
00128 if ( vsl_selecttest(&sock ## NR) == VSL_READABLE ) { \
00129 ASSERT( vsl_recv(&sock ## NR, buf2, buflen) == buflen ); \
00130 ASSERT( memcmp(buf, buf2, buflen) == 0 ); \
00131 } \
00132 s ## NR ## _stat = READ; \
00133 num_read++; \
00134 } \
00135 \
00136 else if ( s ## NR ## _stat == READ ) { \
00137 ASSERT( vsl_selecttest(&sock ## NR) == VSL_WRITABLE || \
00138 vsl_selecttest(&sock ## NR) == 0); \
00139 if ( vsl_selecttest(&sock ## NR) == VSL_WRITABLE ) { \
00140 ASSERT( vsl_send(&sock ## NR, buf, buflen) == buflen ); \
00141 } \
00142 s ## NR ## _stat = WROTE; \
00143 num_written++; \
00144 } \
00145 } while(0)
00146 READWRITE(1);
00147 READWRITE(2);
00148 ASSERT(maxtries-- > 0);
00149 usleep(500000);
00150 } while (!s3_connected);
00151 ASSERT(num_written > 0);
00152 ASSERT(num_read > 0);
00153
00154 vsl_close(&sock1);
00155 vsl_close(&sock2);
00156 vsl_close(&sock3);
00157
00158 TEST_SUMMARY();
00159 exit(0);
00160 }
00161
00162
00163
00164
00165
00166
00167
00168