TEST: Adapt test/errtest for the 'no-err' configuration
authorRichard Levitte <levitte@openssl.org>
Wed, 25 Nov 2020 11:05:35 +0000 (12:05 +0100)
committerRichard Levitte <levitte@openssl.org>
Fri, 27 Nov 2020 11:02:56 +0000 (12:02 +0100)
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/13510)

test/errtest.c

index 247bc546a054f34e36f5e16405d5f23ce7314d71..a5e35d6320ccc99b6eb4972b01b4bc91d20f9c25 100644 (file)
 static int test_print_error_format(void)
 {
     /* Variables used to construct an error line */
+    char *lib;
     const char *func = OPENSSL_FUNC;
+    char *reason;
+# ifdef OPENSSL_NO_ERR
+    char reasonbuf[255];
+# endif
 # ifndef OPENSSL_NO_FILENAMES
     const char *file = OPENSSL_FILE;
     const int line = OPENSSL_LINE;
@@ -35,13 +40,14 @@ static int test_print_error_format(void)
     const int line = 0;
 # endif
     /* The format for OpenSSL error lines */
-    const char *expected_format = ":error::system library:%s:%s:%s:%d";
+    const char *expected_format = ":error:%08lX:%s:%s:%s:%s:%d";
     /*-
-     *                                                    ^^ ^^ ^^ ^^
-     * function name -------------------------------------++ || || ||
-     * reason string (system error string) ------------------++ || ||
-     * file name -----------------------------------------------++ ||
-     * line number ------------------------------------------------++
+     *                                          ^^ ^^ ^^ ^^ ^^
+     * "library" name --------------------------++ || || || ||
+     * function name ------------------------------++ || || ||
+     * reason string (system error string) -----------++ || ||
+     * file name ----------------------------------------++ ||
+     * line number -----------------------------------------++
      */
     char expected[512];
 
@@ -49,7 +55,8 @@ static int test_print_error_format(void)
     int ret = 0, len;
     BIO *bio = NULL;
     const int syserr = EPERM;
-    int reasoncode;
+    unsigned long errorcode;
+    unsigned long reasoncode;
 
     /*
      * We set a mark here so we can clear the system error that we generate
@@ -59,15 +66,25 @@ static int test_print_error_format(void)
     ERR_set_mark();
 
     ERR_PUT_error(ERR_LIB_SYS, 0, syserr, file, line);
-    reasoncode = ERR_GET_REASON(ERR_peek_error());
+    errorcode = ERR_peek_error();
+    reasoncode = ERR_GET_REASON(errorcode);
 
     if (!TEST_int_eq(reasoncode, syserr)) {
         ERR_pop_to_mark();
         goto err;
     }
 
+# ifndef OPENSSL_NO_ERR
+    lib = "system library";
+    reason = strerror(syserr);
+# else
+    lib = "lib(2)";
+    BIO_snprintf(reasonbuf, sizeof(reasonbuf), "reason(%lu)", reasoncode);
+    reason = reasonbuf;
+# endif
+
     BIO_snprintf(expected, sizeof(expected), expected_format,
-                 func, strerror(syserr), file, line);
+                 errorcode, lib, func, reason, file, line);
 
     if (!TEST_ptr(bio = BIO_new(BIO_s_mem())))
         goto err;