[PATCH 7/8] tests: allow running 'make check' with ASAN

Jussi Kivilinna jussi.kivilinna at iki.fi
Sun Jan 31 17:01:39 CET 2021


* tests/t-secmem.c (main): Skip test if environment variable
GCRYPT_IN_ASAN_TEST is defined.
* tests/t-sexp.c (main): Do not initialize secmem if environment
variable GCRYPT_IN_ASAN_TEST is defined.
--

ASAN and mlock are incompatible, so add GCRYPT_IN_ASAN_TEST
environment variant for skipping tests failing as result.
This allows easier automation of ASAN checks.

Signed-off-by: Jussi Kivilinna <jussi.kivilinna at iki.fi>
---
 tests/t-secmem.c | 8 ++++++++
 tests/t-sexp.c   | 9 ++++++++-
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/tests/t-secmem.c b/tests/t-secmem.c
index c4d8c66d..2b769134 100644
--- a/tests/t-secmem.c
+++ b/tests/t-secmem.c
@@ -120,6 +120,14 @@ main (int argc, char **argv)
   long int pgsize_val = -1;
   size_t pgsize;
 
+  if (getenv ("GCRYPT_IN_ASAN_TEST"))
+    {
+      /* 'mlock' is not available when build with address sanitizer,
+       * so skip test. */
+      fputs ("Note: " PGM " skipped because running with ASAN.\n", stdout);
+      return 0;
+    }
+
 #if HAVE_MMAP
 # if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE)
   pgsize_val = sysconf (_SC_PAGESIZE);
diff --git a/tests/t-sexp.c b/tests/t-sexp.c
index 4285ffd8..96d5f97e 100644
--- a/tests/t-sexp.c
+++ b/tests/t-sexp.c
@@ -1312,7 +1312,14 @@ main (int argc, char **argv)
   if (debug)
     xgcry_control ((GCRYCTL_SET_DEBUG_FLAGS, 1u, 0));
   xgcry_control ((GCRYCTL_DISABLE_SECMEM_WARN));
-  xgcry_control ((GCRYCTL_INIT_SECMEM, 16384, 0));
+  if (getenv ("GCRYPT_IN_ASAN_TEST"))
+    {
+      fputs ("Note: " PGM " not using secmem as running with ASAN.\n", stdout);
+    }
+  else
+    {
+      xgcry_control ((GCRYCTL_INIT_SECMEM, 16384, 0));
+    }
   if (!gcry_check_version (GCRYPT_VERSION))
     die ("version mismatch");
   /* #include "../src/gcrypt-int.h" indicates that internal interfaces
-- 
2.27.0




More information about the Gcrypt-devel mailing list