From cf4b568e644c354bb3cb24a39ef71c5dfd83f221 Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Tue, 21 Feb 2023 07:17:39 -0800 Subject: [PATCH] testPlan(): select isolated network configuration for QSRV --- ioc/iochooks.cpp | 4 +++- src/pvxs/unittest.h | 2 ++ src/unittest.cpp | 10 ++++++++++ src/utilpvt.h | 3 +++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/ioc/iochooks.cpp b/ioc/iochooks.cpp index 05dad70..cfd6c01 100644 --- a/ioc/iochooks.cpp +++ b/ioc/iochooks.cpp @@ -27,6 +27,7 @@ #include "iocserver.h" #include "iocshcommand.h" +#include "utilpvt.h" // must include after log.h has been included to avoid clash with printf macro #include @@ -210,7 +211,8 @@ void initialisePvxsServer() { using namespace pvxs::server; auto serv = pvxsServer.load(); if (!serv) { - std::unique_ptr temp(new IOCServer(Config::from_env())); + Config conf = ::pvxs::impl::inUnitTest() ? Config::isolated() : Config::from_env(); + std::unique_ptr temp(new IOCServer(conf)); if (pvxsServer.compare_exchange_strong(serv, temp.get())) { log_debug_printf(_logname, "Installing Server %p\n", temp.get()); diff --git a/src/pvxs/unittest.h b/src/pvxs/unittest.h index 1af7f35..2191cbe 100644 --- a/src/pvxs/unittest.h +++ b/src/pvxs/unittest.h @@ -23,6 +23,8 @@ namespace pvxs { /** Prepare for testing. Call after testPlan() + * @since UNRELEASED If linked with pvxsIoc library, PVA server started + * by ``iocInit()`` will use "isolated" configuration. */ PVXS_API void testSetup(); diff --git a/src/unittest.cpp b/src/unittest.cpp index dba7b77..05c3194 100644 --- a/src/unittest.cpp +++ b/src/unittest.cpp @@ -4,6 +4,8 @@ * in file LICENSE that is included with this distribution. */ +#include + #include "pvxs/version.h" #if !defined(GCC_VERSION) || GCC_VERSION>VERSION_INT(4,9,0,0) @@ -29,6 +31,8 @@ namespace pvxs { +static std::atomic thisIsATest{false}; + void testSetup() { #ifdef _WIN32 @@ -39,9 +43,15 @@ void testSetup() if(prev) testDiag("SetErrorMode() disables 0x%x\n", (unsigned)prev); #endif + thisIsATest = true; } namespace impl { +bool inUnitTest() +{ + return thisIsATest; +} + loc_bad_alloc::loc_bad_alloc(const char *file, int line) { if(auto sep = strrchr(file, '/')) { diff --git a/src/utilpvt.h b/src/utilpvt.h index b2bb4ec..da379ec 100644 --- a/src/utilpvt.h +++ b/src/utilpvt.h @@ -56,6 +56,9 @@ struct promote_print { static int op(const char& v) { return v; }}; template<> struct promote_print { static unsigned op(const char& v) { return v; }}; +PVXS_API +bool inUnitTest(); + /* specialization of bad_alloc which notes the location from which * the exception originates. */