From e7429c8504c2f238fc37c864df441d8657b3ce42 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Mon, 27 Jul 2020 09:32:25 -0700 Subject: [PATCH 1/3] Added unit tests for wc_port.c --- tests/api.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/api.c b/tests/api.c index 454bd91e3..95688eba5 100644 --- a/tests/api.c +++ b/tests/api.c @@ -13662,6 +13662,65 @@ static int test_wc_SetKeyUsage (void) return ret; } /* END test_wc_SetKeyUsage */ +#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) +static void sample_mutex_cb (int flag, int type, const char* file, int line) +{ + (void)flag; + (void)type; + (void)file; + (void)line; +} +#endif +/* + * Testing wc_LockMutex_ex + */ +static int test_wc_LockMutex_ex (void) +{ + int ret = 0; +#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) + int flag = CRYPTO_LOCK; + int type = F_LOCK; + const char* file = "./test-LockMutex_ex.txt"; + int line = 0; + XFILE fp = XFOPEN("./test-LockMutex_ex.txt", "ar"); + + printf(testingFmt, "wc_LockMutex_ex()"); + + /*without SetMutexCb*/ + ret = wc_LockMutex_ex(flag, type, file, line); + if (ret == BAD_STATE_E) { + ret = 0; + } + /*with SetMutexCb*/ + if (ret == 0) { + ret = wc_SetMutexCb(sample_mutex_cb); + if (ret == 0) { + ret = wc_LockMutex_ex(flag, type, file, line); + } + } + + printf(resultFmt, ret == 0 ? passed : failed); + XFCLOSE(fp); + +#endif + return ret; +}/*End test_wc_LockMutex_ex*/ +/* + * Testing wc_SetMutexCb + */ +static int test_wc_SetMutexCb (void) +{ + int ret = 0; +#if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) + + printf(testingFmt, "wc_SetMutexCb()"); + + ret = wc_SetMutexCb(sample_mutex_cb); + + printf(resultFmt, ret == 0 ? passed : failed); +#endif + return ret; +}/*End test_wc_SetMutexCb*/ /* * Testing wc_RsaKeyToDer() @@ -35472,6 +35531,8 @@ void ApiTest(void) AssertIntEQ(test_wc_MakeRsaKey(), 0); AssertIntEQ(test_wc_SetKeyUsage (), 0); + AssertIntEQ(test_wc_SetMutexCb(), 0); + AssertIntEQ(test_wc_LockMutex_ex(), 0); AssertIntEQ(test_wc_RsaKeyToDer(), 0); AssertIntEQ(test_wc_RsaKeyToPublicDer(), 0); From 5af4872baba5e1f8ad63eea0ca3a689fbaefc82d Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Tue, 28 Jul 2020 09:16:43 -0700 Subject: [PATCH 2/3] Changed lock type to 0 --- tests/api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/api.c b/tests/api.c index 95688eba5..dfa770487 100644 --- a/tests/api.c +++ b/tests/api.c @@ -13679,7 +13679,7 @@ static int test_wc_LockMutex_ex (void) int ret = 0; #if defined(OPENSSL_EXTRA) || defined(HAVE_WEBSERVER) int flag = CRYPTO_LOCK; - int type = F_LOCK; + int type = 0; const char* file = "./test-LockMutex_ex.txt"; int line = 0; XFILE fp = XFOPEN("./test-LockMutex_ex.txt", "ar"); From b524926837c692fef5a447f7bf8e40229cd58de6 Mon Sep 17 00:00:00 2001 From: Ethan Looney Date: Wed, 29 Jul 2020 09:31:37 -0700 Subject: [PATCH 3/3] Deleted unneeded xfopen and xfclose --- tests/api.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/api.c b/tests/api.c index dfa770487..1cfc007c1 100644 --- a/tests/api.c +++ b/tests/api.c @@ -13682,7 +13682,6 @@ static int test_wc_LockMutex_ex (void) int type = 0; const char* file = "./test-LockMutex_ex.txt"; int line = 0; - XFILE fp = XFOPEN("./test-LockMutex_ex.txt", "ar"); printf(testingFmt, "wc_LockMutex_ex()"); @@ -13700,7 +13699,6 @@ static int test_wc_LockMutex_ex (void) } printf(resultFmt, ret == 0 ? passed : failed); - XFCLOSE(fp); #endif return ret;