From b66a108e9783f9e9364eb00b935e6fad12456c11 Mon Sep 17 00:00:00 2001 From: John Safranek Date: Wed, 17 Jan 2024 21:38:26 -0800 Subject: [PATCH] CRL Monitor Test Fix 1. For Mach and FreeBsd builds, add the function link_file() which makes a hard link for a file. 2. Add a macro STAGE_FILE that either calls copy_file or link_file depending on doing a Mach or FreeBSD build or not. This is to work around how the CRL Monitor is detecting file changes made by the CRL monitor test in the testsuite. Linux and Windows are detecting the file copies and deletes, and how macOS detects them. kevent sees the link as a single change to the parent directory and reads it. When you copy the file, kevent sees the new file getting opened and triggering the file update. --- tests/utils.h | 7 +++++++ testsuite/testsuite.c | 4 ++-- wolfssl/test.h | 7 +++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/tests/utils.h b/tests/utils.h index 46b16e2c8..dbc816051 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -111,6 +111,13 @@ cleanup: XFCLOSE(outFile); return ret; } + +#if defined(__MACH__) || defined(__FreeBSD__) +int link_file(const char* in, const char* out) +{ + return link(in, out); +} +#endif #endif /* !NO_FILESYSTEM */ #if !defined(NO_FILESYSTEM) && !defined(NO_CERTS) && !defined(NO_RSA) && \ diff --git a/testsuite/testsuite.c b/testsuite/testsuite.c index 753077aad..70aecb887 100644 --- a/testsuite/testsuite.c +++ b/testsuite/testsuite.c @@ -327,7 +327,7 @@ static int test_crl_monitor(void) if (i % 2 == 0) { /* succeed on even rounds */ sprintf(buf, "%s/%s", tmpDir, "crl.pem"); - if (copy_file("certs/crl/crl.pem", buf) != 0) { + if (STAGE_FILE("certs/crl/crl.pem", buf) != 0) { fprintf(stderr, "[%d] Failed to copy file to %s\n", i, buf); goto cleanup; } @@ -350,7 +350,7 @@ static int test_crl_monitor(void) else { /* fail on odd rounds */ sprintf(buf, "%s/%s", tmpDir, "crl.revoked"); - if (copy_file("certs/crl/crl.revoked", buf) != 0) { + if (STAGE_FILE("certs/crl/crl.revoked", buf) != 0) { fprintf(stderr, "[%d] Failed to copy file to %s\n", i, buf); goto cleanup; } diff --git a/wolfssl/test.h b/wolfssl/test.h index cc366575f..e9c7e6f63 100644 --- a/wolfssl/test.h +++ b/wolfssl/test.h @@ -656,6 +656,13 @@ int rem_dir(const char* dirName); int rem_file(const char* fileName); int copy_file(const char* in, const char* out); +#if defined(__MACH__) || defined(__FreeBSD__) + int link_file(const char* in, const char* out); + #define STAGE_FILE(x,y) link_file((x),(y)) +#else + #define STAGE_FILE(x,y) copy_file((x),(y)) +#endif + void signal_ready(tcp_ready* ready); /* wolfSSL */