Browse Source

build: arbitrary path for `make check`

To support builds in other directories, unit.test and wolfcrypt test
must be aware of the source and build directory.
Elms 3 years ago
parent
commit
c17597a4fb
9 changed files with 79 additions and 45 deletions
  1. 4 0
      .gitignore
  2. 0 2
      Makefile.am
  3. 9 1
      configure.ac
  4. 1 0
      scripts/include.am
  5. 0 15
      scripts/unit.test
  6. 8 0
      scripts/unit.test.in
  7. 1 2
      wolfcrypt/test/include.am
  8. 31 25
      wolfcrypt/test/test.c
  9. 25 0
      wolfcrypt/test/test_paths.h.in

+ 4 - 0
.gitignore

@@ -242,6 +242,10 @@ linuxkm/libwolfssl.mod.c
 linuxkm/module_exports.c
 linuxkm/linuxkm/get_thread_size
 
+# autotools generated
+scripts/unit.test
+wolfcrypt/test/test_paths.h
+
 # MPLAB Generated Files (OS X)
 mcapi/wolfcrypt_mcapi.X/nbproject/Makefile-*
 mcapi/wolfcrypt_mcapi.X/nbproject/Package-default.bash

+ 0 - 2
Makefile.am

@@ -23,8 +23,6 @@ noinst_DATA =
 SUBDIRS_OPT =
 DIST_SUBDIRS_OPT =
 
-DISTCHECK_CONFIGURE_FLAGS = CPPFLAGS=-DDISTCHECK_BUILD
-
 #includes additional rules from aminclude.am
 @INC_AMINCLUDE@
 DISTCLEANFILES+= aminclude.am

+ 9 - 1
configure.ac

@@ -6145,7 +6145,15 @@ AC_SUBST([LIB_STATIC_ADD])
 
 # FINAL
 AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h])
-AC_CONFIG_FILES([Makefile wolfssl/version.h wolfssl/options.h cyassl/options.h support/wolfssl.pc rpm/spec])
+AC_CONFIG_FILES([Makefile
+        wolfssl/version.h
+        wolfssl/options.h
+        cyassl/options.h
+        support/wolfssl.pc
+        rpm/spec
+        wolfcrypt/test/test_paths.h
+        ])
+AC_CONFIG_FILES([scripts/unit.test],[chmod +x scripts/unit.test])
 
 AX_CREATE_GENERIC_CONFIG
 AX_AM_JOBSERVER([yes])

+ 1 - 0
scripts/include.am

@@ -82,6 +82,7 @@ dist_noinst_SCRIPTS+= scripts/ocsp.test
 endif
 
 dist_noinst_SCRIPTS+= scripts/unit.test
+noinst_SCRIPTS+= scripts/unit.test.in
 
 endif
 endif

+ 0 - 15
scripts/unit.test

@@ -1,15 +0,0 @@
-#!/bin/sh
-
-# for makefile use PWD as it is safe to assume location of execution
-if [ "$MAKELEVEL" != "" ]; then
-    DIRNAME=$PWD;
-else
-    DIRNAME="$(dirname "$0")/..";
-fi
-
-bwrap_path="$(command -v bwrap)"
-if [ -n "$bwrap_path" ]; then
-    exec "$bwrap_path" --unshare-net --dev-bind / / "$DIRNAME/tests/unit.test" "$@"
-else
-    exec "$DIRNAME/tests/unit.test" "$@"
-fi

+ 8 - 0
scripts/unit.test.in

@@ -0,0 +1,8 @@
+#!/bin/sh
+
+bwrap_path="$(command -v bwrap)"
+if [ -n "$bwrap_path" ]; then
+    exec "$bwrap_path" --unshare-net --dev-bind / / "@builddir@/tests/unit.test" "$@"
+else
+    exec "@builddir@/tests/unit.test" "$@"
+fi

+ 1 - 2
wolfcrypt/test/include.am

@@ -12,8 +12,7 @@ noinst_PROGRAMS+= wolfcrypt/test/testwolfcrypt
 wolfcrypt_test_testwolfcrypt_SOURCES      = wolfcrypt/test/test.c
 wolfcrypt_test_testwolfcrypt_LDADD        = src/libwolfssl.la $(LIB_STATIC_ADD)
 wolfcrypt_test_testwolfcrypt_DEPENDENCIES = src/libwolfssl.la
-noinst_HEADERS += wolfcrypt/test/test.h
-
+noinst_HEADERS += wolfcrypt/test/test.h wolfcrypt/test/test_paths.h.in
 endif
 endif
 

+ 31 - 25
wolfcrypt/test/test.c

@@ -94,8 +94,14 @@ _Pragma("GCC diagnostic ignored \"-Wunused-function\"");
 #endif
 
 #ifdef USE_FLAT_TEST_H
+    #ifdef HAVE_CONFIG_H
+        #include "test_paths.h"
+    #endif
     #include "test.h"
 #else
+    #ifdef HAVE_CONFIG_H
+        #include "wolfcrypt/test/test_paths.h"
+    #endif
     #include "wolfcrypt/test/test.h"
 #endif
 
@@ -11641,20 +11647,20 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out)
 #elif defined(WOLFSSL_uTKERNEL2)
     #define CERT_PREFIX "/uda/"
     #define CERT_PATH_SEP "/"
-#else
+#endif
+
+#ifndef CERT_PREFIX
     #define CERT_PREFIX "./"
+#endif
+#ifndef CERT_PATH_SEP
     #define CERT_PATH_SEP "/"
 #endif
-#define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
-
-#ifdef DISTCHECK_BUILD
-/* This is the path used during distcheck by autotools.
- * Using a temp directory passed in would be more flexible */
-    #define CERT_TEMPDIR "./_build/sub/"
-#else
-    #define CERT_TEMPDIR CERT_PREFIX
+#ifndef CERT_WRITE_TEMP_DIR
+    #define CERT_WRITE_TEMP_DIR CERT_PREFIX
 #endif
 
+#define CERT_ROOT CERT_PREFIX "certs" CERT_PATH_SEP
+
 /* Generated Test Certs */
 #if !defined(USE_CERT_BUFFERS_1024) && !defined(USE_CERT_BUFFERS_2048) && \
     !defined(USE_CERT_BUFFERS_3072) && !defined(USE_CERT_BUFFERS_4096)
@@ -11746,44 +11752,44 @@ byte GetEntropy(ENTROPY_CMD cmd, byte* out)
 #ifndef NO_WRITE_TEMP_FILES
 #ifdef HAVE_ECC
     #ifdef WOLFSSL_CERT_GEN
-         static const char* certEccPemFile =   CERT_TEMPDIR "certecc.pem";
+         static const char* certEccPemFile =   CERT_WRITE_TEMP_DIR "certecc.pem";
     #endif
     #if defined(WOLFSSL_CERT_GEN) && !defined(NO_RSA)
-        static const char* certEccRsaPemFile = CERT_TEMPDIR "certeccrsa.pem";
-        static const char* certEccRsaDerFile = CERT_TEMPDIR "certeccrsa.der";
+        static const char* certEccRsaPemFile = CERT_WRITE_TEMP_DIR "certeccrsa.pem";
+        static const char* certEccRsaDerFile = CERT_WRITE_TEMP_DIR "certeccrsa.der";
     #endif
-        static const char* eccCaKeyPemFile  = CERT_TEMPDIR "ecc-key.pem";
-        static const char* eccPubKeyDerFile = CERT_TEMPDIR "ecc-public-key.der";
-        static const char* eccCaKeyTempFile = CERT_TEMPDIR "ecc-key.der";
+        static const char* eccCaKeyPemFile  = CERT_WRITE_TEMP_DIR "ecc-key.pem";
+        static const char* eccPubKeyDerFile = CERT_WRITE_TEMP_DIR "ecc-public-key.der";
+        static const char* eccCaKeyTempFile = CERT_WRITE_TEMP_DIR "ecc-key.der";
     #ifdef HAVE_PKCS8
-        static const char* eccPkcs8KeyDerFile = CERT_TEMPDIR "ecc-key-pkcs8.der";
+        static const char* eccPkcs8KeyDerFile = CERT_WRITE_TEMP_DIR "ecc-key-pkcs8.der";
     #endif
     #if defined(WOLFSSL_CERT_GEN) || \
             (defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT))
-        static const char* certEccDerFile = CERT_TEMPDIR "certecc.der";
+        static const char* certEccDerFile = CERT_WRITE_TEMP_DIR "certecc.der";
     #endif
 #endif /* HAVE_ECC */
 
 #ifndef NO_RSA
     #if defined(WOLFSSL_CERT_GEN) || \
         (defined(WOLFSSL_CERT_EXT) && defined(WOLFSSL_TEST_CERT))
-        static const char* otherCertDerFile = CERT_TEMPDIR "othercert.der";
-        static const char* certDerFile = CERT_TEMPDIR "cert.der";
+        static const char* otherCertDerFile = CERT_WRITE_TEMP_DIR "othercert.der";
+        static const char* certDerFile = CERT_WRITE_TEMP_DIR "cert.der";
     #endif
     #ifdef WOLFSSL_CERT_GEN
-        static const char* otherCertPemFile = CERT_TEMPDIR "othercert.pem";
-        static const char* certPemFile = CERT_TEMPDIR "cert.pem";
+        static const char* otherCertPemFile = CERT_WRITE_TEMP_DIR "othercert.pem";
+        static const char* certPemFile = CERT_WRITE_TEMP_DIR "cert.pem";
     #endif
     #ifdef WOLFSSL_CERT_REQ
-        static const char* certReqDerFile = CERT_TEMPDIR "certreq.der";
-        static const char* certReqPemFile = CERT_TEMPDIR "certreq.pem";
+        static const char* certReqDerFile = CERT_WRITE_TEMP_DIR "certreq.der";
+        static const char* certReqPemFile = CERT_WRITE_TEMP_DIR "certreq.pem";
     #endif
 #endif /* !NO_RSA */
 
 #if !defined(NO_RSA) || !defined(NO_DSA)
     #ifdef WOLFSSL_KEY_GEN
-        static const char* keyDerFile = CERT_TEMPDIR "key.der";
-        static const char* keyPemFile = CERT_TEMPDIR "key.pem";
+        static const char* keyDerFile = CERT_WRITE_TEMP_DIR "key.der";
+        static const char* keyPemFile = CERT_WRITE_TEMP_DIR "key.pem";
     #endif
 #endif
 

+ 25 - 0
wolfcrypt/test/test_paths.h.in

@@ -0,0 +1,25 @@
+/* wolfcrypt/test/test_paths.h
+ *
+ * Copyright (C) 2006-2020 wolfSSL Inc.
+ *
+ * This file is part of wolfSSL.
+ *
+ * wolfSSL is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * wolfSSL is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
+ */
+
+#ifndef NO_FILESYSTEM
+    #define CERT_PREFIX "@abs_top_srcdir@/"
+    #define CERT_WRITE_TEMP_DIR "@abs_top_builddir@/"
+#endif /* NO_FILESYSTEM */