From 91a8b5ffd46f12333a60e26a8a7e66b4380680e1 Mon Sep 17 00:00:00 2001 From: David Garske Date: Tue, 12 Dec 2023 11:06:34 -0800 Subject: [PATCH] Portability fixes. Added `NO_MAIN_DRIVER`. Support for `SINGLE_THREADED`. Add `static` to some globals. --- tests/pkcs11mtt.c | 18 +++++++++++++----- tests/pkcs11str.c | 10 +++++++--- tests/pkcs11test.c | 12 ++++++++---- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/tests/pkcs11mtt.c b/tests/pkcs11mtt.c index c9f1b3e..40bcd9e 100644 --- a/tests/pkcs11mtt.c +++ b/tests/pkcs11mtt.c @@ -32,7 +32,7 @@ #include -#ifdef _POSIX_THREADS +#if defined(_POSIX_THREADS) && !defined(SINGLE_THREADED) #include #include @@ -49,14 +49,14 @@ static void* dlib; #endif static CK_FUNCTION_LIST* funcList; static int slot; -const char* tokenName = "wolfpkcs11"; +static const char* tokenName = "wolfpkcs11"; /* FIPS requires pin to be at least 14 characters, since it is used for * the HMAC key */ static byte* soPin = (byte*)"password123456"; static int soPinLen = 14; -byte* userPin = (byte*)"wolfpkcs11-test"; -int userPinLen; +static byte* userPin = (byte*)"wolfpkcs11-test"; +static int userPinLen; #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DH) static CK_OBJECT_CLASS pubKeyClass = CKO_PUBLIC_KEY; @@ -6482,7 +6482,11 @@ static void Usage(void) printf(" Test case number to try\n"); } +#ifndef NO_MAIN_DRIVER int main(int argc, char* argv[]) +#else +int pkcs11test_mtt(int argc, char* argv[]) +#endif { int ret; CK_RV rv; @@ -6603,7 +6607,11 @@ int main(int argc, char* argv[]) #else +#ifndef NO_MAIN_DRIVER int main(int argc, char* argv[]) +#else +int pkcs11test_mtt(int argc, char* argv[]) +#endif { (void)argc; (void)argv; @@ -6611,4 +6619,4 @@ int main(int argc, char* argv[]) return 0; } -#endif /* _POSIX_THREADS */ +#endif /* _POSIX_THREADS && !SINGLE_THREADED */ diff --git a/tests/pkcs11str.c b/tests/pkcs11str.c index 610c587..25b25a2 100644 --- a/tests/pkcs11str.c +++ b/tests/pkcs11str.c @@ -132,14 +132,14 @@ static void* dlib; #endif static CK_FUNCTION_LIST* funcList; static int slot = 0; -const char* tokenName = "wolfpkcs11"; +static const char* tokenName = "wolfpkcs11"; /* FIPS requires pin to be at least 14 characters, since it is used for * the HMAC key */ static byte* soPin = (byte*)"password123456"; static int soPinLen = 14; -byte* userPin = (byte*)"wolfpkcs11-test"; -int userPinLen; +static byte* userPin = (byte*)"wolfpkcs11-test"; +static int userPinLen; #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DH) static CK_OBJECT_CLASS pubKeyClass = CKO_PUBLIC_KEY; @@ -909,7 +909,11 @@ static int string_matches(const char* arg, const char* str) return XSTRNCMP(arg, str, len) == 0; } +#ifndef NO_MAIN_DRIVER int main(int argc, char* argv[]) +#else +int pkcs11test_str(int argc, char* argv[]) +#endif { int ret; CK_RV rv; diff --git a/tests/pkcs11test.c b/tests/pkcs11test.c index 394a781..c34201b 100644 --- a/tests/pkcs11test.c +++ b/tests/pkcs11test.c @@ -59,14 +59,14 @@ static void* dlib; #endif static CK_FUNCTION_LIST* funcList; static int slot = 0; -const char* tokenName = "wolfpkcs11"; +static const char* tokenName = "wolfpkcs11"; /* FIPS requires pin to be at least 14 characters, since it is used for * the HMAC key */ static byte* soPin = (byte*)"password123456"; static int soPinLen = 14; -byte* userPin = (byte*)"wolfpkcs11-test"; -int userPinLen; +static byte* userPin = (byte*)"wolfpkcs11-test"; +static int userPinLen; #if !defined(NO_RSA) || defined(HAVE_ECC) || !defined(NO_DH) static CK_OBJECT_CLASS pubKeyClass = CKO_PUBLIC_KEY; @@ -7896,7 +7896,11 @@ static void Usage(void) printf(" Test case number to try\n"); } +#ifndef NO_MAIN_DRIVER int main(int argc, char* argv[]) +#else +int pkcs11test_test(int argc, char* argv[]) +#endif { int ret; CK_RV rv; @@ -7974,7 +7978,7 @@ int main(int argc, char* argv[]) fprintf(stderr, "%d: %s\n", i + 1, testFunc[i].name); return 0; } - else if (isdigit(argv[0][0])) { + else if (isdigit((int)argv[0][0])) { testCase = atoi(*argv); if (testCase <= 0 || testCase > testFuncCnt) { fprintf(stderr, "Test case out of range: %s\n", *argv);