Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFTP Test Maintenance #646

Merged
merged 2 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions examples/echoserver/echoserver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2159,21 +2159,18 @@ static void ShowUsage(void)
}


static INLINE void SignalTcpReady(func_args* serverArgs, word16 port)
static INLINE void SignalTcpReady(tcp_ready* ready, word16 port)
{
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
!defined(__MINGW32__) && !defined(SINGLE_THREADED)
tcp_ready* ready = serverArgs->signal;
if (ready != NULL) {
pthread_mutex_lock(&ready->mutex);
ready->ready = 1;
ready->port = port;
pthread_cond_signal(&ready->cond);
pthread_mutex_unlock(&ready->mutex);
}
pthread_mutex_lock(&ready->mutex);
ready->ready = 1;
ready->port = port;
pthread_cond_signal(&ready->cond);
pthread_mutex_unlock(&ready->mutex);
#else
(void)serverArgs;
(void)port;
WOLFSSH_UNUSED(ready);
WOLFSSH_UNUSED(port);
#endif
}

Expand Down Expand Up @@ -2543,6 +2540,8 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
#endif
}

SignalTcpReady(serverArgs->signal, port);

do {
WS_SOCKET_T clientFd = WOLFSSH_SOCKET_INVALID;
#ifdef WOLFSSL_NUCLEUS
Expand Down Expand Up @@ -2600,8 +2599,6 @@ THREAD_RETURN WOLFSSH_THREAD echoserver_test(void* args)
}
#endif

SignalTcpReady(serverArgs, port);

#ifdef WOLFSSL_NUCLEUS
clientFd = NU_Accept(listenFd, &clientAddr, 0);
#else
Expand Down
2 changes: 1 addition & 1 deletion tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,7 @@ static void test_wolfSSH_SFTP_SendReadPacket(void)
ser.signal = &ready;
InitTcpReady(ser.signal);
ThreadStart(echoserver_test, (void*)&ser, &serThread);
WaitTcpReady(&ser);
WaitTcpReady(&ready);

sftp_client_connect(&ctx, &ssh, ready.port);
AssertNotNull(ctx);
Expand Down
5 changes: 3 additions & 2 deletions tests/sftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,18 +208,18 @@ int wolfSSH_SftpTest(int flag)
ser.signal = &ready;
InitTcpReady(ser.signal);
ThreadStart(echoserver_test, (void*)&ser, &serThread);
WaitTcpReady(&ser);
WaitTcpReady(&ready);

argsCount = 0;
args[argsCount++] = ".";
args[argsCount++] = "-u";
args[argsCount++] = "jill";
args[argsCount++] = "-P";
args[argsCount++] = "upthehill";
args[argsCount++] = "-p";

#ifndef USE_WINDOWS_API
/* use port that server has found */
args[argsCount++] = "-p";
snprintf(portNumber, sizeof(portNumber), "%d", ready.port);
args[argsCount++] = portNumber;
#endif
Expand All @@ -240,6 +240,7 @@ int wolfSSH_SftpTest(int flag)

ThreadJoin(serThread);
wolfSSH_Cleanup();
FreeTcpReady(&ready);

return ret;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int wolfSSH_TestsuiteTest(int argc, char** argv)
serverArgs.signal = &ready;
serverArgs.user_auth = NULL;
ThreadStart(echoserver_test, &serverArgs, &serverThread);
WaitTcpReady(&serverArgs);
WaitTcpReady(&ready);

WSTRNCPY(cA[clientArgc++], "client", ARGLEN);
WSTRNCPY(cA[clientArgc++], "-u", ARGLEN);
Expand Down
26 changes: 16 additions & 10 deletions wolfssh/test.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,8 +850,8 @@ static INLINE void InitTcpReady(tcp_ready* ready)
ready->srfName = NULL;
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
!defined(__MINGW32__) && !defined(SINGLE_THREADED)
pthread_mutex_init(&ready->mutex, 0);
pthread_cond_init(&ready->cond, 0);
pthread_mutex_init(&ready->mutex, NULL);
pthread_cond_init(&ready->cond, NULL);
#endif
}

Expand All @@ -863,24 +863,30 @@ static INLINE void FreeTcpReady(tcp_ready* ready)
pthread_mutex_destroy(&ready->mutex);
pthread_cond_destroy(&ready->cond);
#else
(void)ready;
WOLFSSH_UNUSED(ready);
#endif
}


static INLINE void WaitTcpReady(func_args* args)
static INLINE void WaitTcpReady(tcp_ready* ready)
{
#if defined(_POSIX_THREADS) && defined(NO_MAIN_DRIVER) && \
!defined(__MINGW32__) && !defined(SINGLE_THREADED)
pthread_mutex_lock(&args->signal->mutex);
pthread_mutex_lock(&ready->mutex);

if (!args->signal->ready)
pthread_cond_wait(&args->signal->cond, &args->signal->mutex);
args->signal->ready = 0; /* reset */
while (!ready->ready) {
pthread_cond_wait(&ready->cond, &ready->mutex);
}

pthread_mutex_unlock(&args->signal->mutex);
pthread_mutex_unlock(&ready->mutex);
#ifdef WOLFSSH_ZEPHYR
/* It's like the server isn't ready to accept connections it is
* listening for despite this conditional variable. A 300ms wait
* seems to help. This is not ideal. (XXX) */
k_sleep(Z_TIMEOUT_TICKS(300));
#endif /* WOLFSSH_ZEPHYR */
#else
(void)args;
WOLFSSH_UNUSED(ready);
#endif
}

Expand Down
Loading