Skip to content

Commit

Permalink
limit additional nonblocking test
Browse files Browse the repository at this point in the history
  • Loading branch information
JacobBarthelmeh committed Sep 29, 2023
1 parent cb6088e commit 5780570
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 31 deletions.
5 changes: 5 additions & 0 deletions examples/client/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ static void ShowUsage(void)
printf(" -j <filename> filename for the user's public key\n");
printf(" -x exit after successful connection without doing\n"
" read/write\n");
#ifdef WOLFSSH_TEST_BLOCK
printf("-N non-blocking sockets required when compiled with "
"WOLFSSH_TEST_BLOCK\n");
#else
printf(" -N use non-blocking sockets\n");
#endif
#ifdef WOLFSSH_TERM
printf(" -t use psuedo terminal\n");
#endif
Expand Down
11 changes: 10 additions & 1 deletion scripts/external.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ if test -n "$WOLFSSH_EXTERNAL_TEST"; then
echo "WOLFSSH_EXTERNAL_TEST set, running test..."
else
echo "WOLFSSH_EXTERNAL_TEST NOT set, won't run"
exit 0
exit 77
fi

# test for nonblocking only
./examples/client/client -h | grep WOLFSSH_TEST_BLOCK
if [ $? -eq 0 ]
then
echo "macro NO_WOLFSSH_CLIENT was used"
echo "skipping for now"
exit 77
fi

do_cleanup() {
Expand Down
10 changes: 9 additions & 1 deletion scripts/get-put.test
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,21 @@ then
then
echo "macro NO_WOLFSSH_CLIENT was used"
echo "skipping test"
exit 0
exit 77
else
echo "wolfSFTP client not compiled in or not working"
exit 1
fi
fi

# test for nonblocking only
./examples/client/client -h | grep WOLFSSH_TEST_BLOCK
if [ $? -eq 0 ]
then
echo "macro WOLFSSH_TEST_BLOCK was used"
exit 77
fi

if test ! -x ./examples/echoserver/echoserver
then
echo "This test requires the wolfSSH echoserver."
Expand Down
9 changes: 9 additions & 0 deletions scripts/scp.test
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ counter=0

[ ! -x ./examples/scpclient/wolfscp ] && echo -e "\n\nwolfscp client doesn't exist" && exit 1

# test for nonblocking only
./examples/client/client -h | grep WOLFSSH_TEST_BLOCK
if [ $? -eq 0 ]
then
echo "macro NO_WOLFSSH_CLIENT was used"
echo "skipping for now"
exit 77
fi

create_port() {
while [ ! -s "$ready_file" ] && [ "$counter" -lt 20 ]; do
echo -e "waiting for ready file..."
Expand Down
61 changes: 37 additions & 24 deletions scripts/sftp.test
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ no_pid=-1
server_pid=$no_pid
ready_file=`pwd`/wolfssh_sftp_ready$$
counter=0
nonblockingOnly=0

[ ! -x ./examples/sftpclient/wolfsftp ] && echo -e "\n\nwolfSFTP client doesn't exist" && exit 1

Expand All @@ -15,7 +16,15 @@ if [ $? -eq 0 ]
then
echo "macro NO_WOLFSSH_CLIENT was used"
echo "skipping test"
exit 0
exit 77
fi

# test for nonblocking only
./examples/client/client -h | grep WOLFSSH_TEST_BLOCK
if [ $? -eq 0 ]
then
echo "macro NO_WOLFSSH_CLIENT was used"
nonblockingOnly=1
fi

#echo "ready file $ready_file"
Expand Down Expand Up @@ -67,17 +76,19 @@ trap do_trap INT TERM

[ ! -x ./examples/sftpclient/wolfsftp ] && echo -e "\n\nClient doesn't exist" && exit 1

echo "Test basic connection"
./examples/echoserver/echoserver -1 -R $ready_file &
server_pid=$!
create_port
echo "exit" | ./examples/sftpclient/wolfsftp -u jill -P upthehill -p $port
RESULT=$?
remove_ready_file
if [ $RESULT -ne 0 ]; then
echo -e "\n\nfailed to connect"
do_cleanup
exit 1
if [ $nonblockingOnly = 0 ]; then
echo "Test basic connection"
./examples/echoserver/echoserver -1 -R $ready_file &
server_pid=$!
create_port
echo "exit" | ./examples/sftpclient/wolfsftp -u jill -P upthehill -p $port
RESULT=$?
remove_ready_file
if [ $RESULT -ne 0 ]; then
echo -e "\n\nfailed to connect"
do_cleanup
exit 1
fi
fi

# Test non blocking connection
Expand All @@ -95,18 +106,20 @@ if [ $RESULT -ne 0 ]; then
fi

# Test of setting directory
echo "Test of setting directory"
PWD=`pwd`
./examples/echoserver/echoserver -d $PWD/examples -1 -R $ready_file &
server_pid=$!
create_port
echo "exit" | ./examples/sftpclient/wolfsftp -N -u jill -P upthehill -p $port
RESULT=$?
remove_ready_file
if [ $RESULT -ne 0 ]; then
echo -e "\n\nfailed to connect"
do_cleanup
exit 1
if [ $nonblockingOnly = 0 ]; then
echo "Test of setting directory"
PWD=`pwd`
./examples/echoserver/echoserver -d $PWD/examples -1 -R $ready_file &
server_pid=$!
create_port
echo "exit" | ./examples/sftpclient/wolfsftp -N -u jill -P upthehill -p $port
RESULT=$?
remove_ready_file
if [ $RESULT -ne 0 ]; then
echo -e "\n\nfailed to connect"
do_cleanup
exit 1
fi
fi

echo -e "\nALL Tests Passed"
Expand Down
2 changes: 1 addition & 1 deletion src/io.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

/* percent of time that forced want read/write is done */
#ifndef WOLFSSH_BLOCK_PROB
#define WOLFSSH_BLOCK_PROB 75
#define WOLFSSH_BLOCK_PROB 50
#endif
#endif

Expand Down
13 changes: 10 additions & 3 deletions tests/api.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
#define WOLFSSH_TEST_SERVER
#define WOLFSSH_TEST_ECHOSERVER
#endif
#define WOLFSSH_TEST_HEX2BIN
#ifndef WOLFSSH_TEST_BLOCK
#define WOLFSSH_TEST_HEX2BIN
#endif
#include <wolfssh/test.h>
#include "tests/api.h"

Expand Down Expand Up @@ -127,6 +129,8 @@ char* myoptarg = NULL;
#define AssertPtrLE(x, y) AssertPtr(x, y, <=, >)


#ifndef WOLFSSH_TEST_BLOCK

enum WS_TestEndpointTypes {
TEST_GOOD_ENDPOINT_SERVER = WOLFSSH_ENDPOINT_SERVER,
TEST_GOOD_ENDPOINT_CLIENT = WOLFSSH_ENDPOINT_CLIENT,
Expand Down Expand Up @@ -1074,13 +1078,16 @@ static void test_wolfSSH_RealPath(void)
#else
static void test_wolfSSH_RealPath(void) { ; }
#endif

#endif /* WOLFSSH_TEST_BLOCK */

int wolfSSH_ApiTest(int argc, char** argv)
{
(void)argc;
(void)argv;

#ifdef WOLFSSH_TEST_BLOCK
return 77;
#else
AssertIntEQ(wolfSSH_Init(), WS_SUCCESS);

#if defined(FIPS_VERSION_GE) && FIPS_VERSION_GE(5,2)
Expand Down Expand Up @@ -1111,10 +1118,10 @@ int wolfSSH_ApiTest(int argc, char** argv)

/* Either SCP or SFTP */
test_wolfSSH_RealPath();

AssertIntEQ(wolfSSH_Cleanup(), WS_SUCCESS);

return 0;
#endif
}


Expand Down
2 changes: 1 addition & 1 deletion tests/testsuite.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ char* myoptarg = NULL;


#if !defined(NO_WOLFSSH_SERVER) && !defined(NO_WOLFSSH_CLIENT) && \
!defined(SINGLE_THREADED)
!defined(SINGLE_THREADED) && !defined(WOLFSSH_TEST_BLOCK)

static int tsClientUserAuth(byte authType, WS_UserAuthData* authData, void* ctx)
{
Expand Down

0 comments on commit 5780570

Please sign in to comment.