From 5780570880cbde14cdc93e3e21392bc932afacfd Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Fri, 29 Sep 2023 16:12:21 -0700 Subject: [PATCH] limit additional nonblocking test --- examples/client/client.c | 5 ++++ scripts/external.test | 11 +++++++- scripts/get-put.test | 10 ++++++- scripts/scp.test | 9 ++++++ scripts/sftp.test | 61 ++++++++++++++++++++++++---------------- src/io.c | 2 +- tests/api.c | 13 +++++++-- tests/testsuite.c | 2 +- 8 files changed, 82 insertions(+), 31 deletions(-) diff --git a/examples/client/client.c b/examples/client/client.c index 925456fe..5d4439f0 100644 --- a/examples/client/client.c +++ b/examples/client/client.c @@ -91,7 +91,12 @@ static void ShowUsage(void) printf(" -j 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 diff --git a/scripts/external.test b/scripts/external.test index 7e3c6e99..d7c50752 100755 --- a/scripts/external.test +++ b/scripts/external.test @@ -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() { diff --git a/scripts/get-put.test b/scripts/get-put.test index a48691c8..9fedb6a7 100755 --- a/scripts/get-put.test +++ b/scripts/get-put.test @@ -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." diff --git a/scripts/scp.test b/scripts/scp.test index 3cfabfbb..093db684 100755 --- a/scripts/scp.test +++ b/scripts/scp.test @@ -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..." diff --git a/scripts/sftp.test b/scripts/sftp.test index 83249867..69927e97 100755 --- a/scripts/sftp.test +++ b/scripts/sftp.test @@ -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 @@ -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" @@ -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 @@ -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" diff --git a/src/io.c b/src/io.c index 686c02f1..6f157436 100644 --- a/src/io.c +++ b/src/io.c @@ -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 diff --git a/tests/api.c b/tests/api.c index 9ab032f7..840a0d4f 100644 --- a/tests/api.c +++ b/tests/api.c @@ -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 #include "tests/api.h" @@ -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, @@ -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) @@ -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 } diff --git a/tests/testsuite.c b/tests/testsuite.c index 32748306..0b64266a 100644 --- a/tests/testsuite.c +++ b/tests/testsuite.c @@ -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) {