diff --git a/iocore/cache/Makefile.am b/iocore/cache/Makefile.am index 9363ccbca5c..c38c201718b 100644 --- a/iocore/cache/Makefile.am +++ b/iocore/cache/Makefile.am @@ -117,7 +117,6 @@ test_LDADD = \ @YAMLCPP_LIBS@ \ -lm -if EXPENSIVE_TESTS check_PROGRAMS = \ test_Cache \ test_RWW \ @@ -130,7 +129,6 @@ check_PROGRAMS = \ test_Update_L_to_S \ test_Update_S_to_L \ test_Update_header -endif test_main_SOURCES = \ ./test/main.cc \ diff --git a/iocore/cache/test/main.cc b/iocore/cache/test/main.cc index 3585ab68bea..0e2379d3bde 100644 --- a/iocore/cache/test/main.cc +++ b/iocore/cache/test/main.cc @@ -23,10 +23,34 @@ #define CATCH_CONFIG_MAIN #include "main.h" +#include "tscore/ts_file.h" + +#include #define THREADS 1 #define DIAGS_LOG_FILE "diags.log" +// Create a new temp directory and return it +std::string +temp_prefix() +{ + char buffer[PATH_MAX]; + std::error_code err; + const char *tmpdir = getenv("TMPDIR"); + if (tmpdir == nullptr) { + tmpdir = "/tmp"; + } + snprintf(buffer, sizeof(buffer), "%s/cachetest.XXXXXX", tmpdir); + auto prefix = ts::file::path(mkdtemp(buffer)); + bool result = ts::file::create_directories(prefix / "var" / "trafficserver", err, 0755); + if (!result) { + Debug("cache test", "Failed to create directories for test: %s(%s)", prefix.c_str(), err.message().c_str()); + } + ink_assert(result); + + return prefix.string(); +} + void test_done() { @@ -48,7 +72,7 @@ struct EventProcessorListener : Catch::TestEventListenerBase { diags->show_location = SHOW_LOCATION_DEBUG; mime_init(); - Layout::create(); + Layout::create(temp_prefix()); RecProcessInit(RECM_STAND_ALONE); LibRecordsConfigInit(); ink_net_init(ts::ModuleVersion(1, 0, ts::ModuleVersion::PRIVATE)); @@ -66,8 +90,6 @@ struct EventProcessorListener : Catch::TestEventListenerBase { std::string src_dir = std::string(TS_ABS_TOP_SRCDIR) + "/iocore/cache/test"; Layout::get()->sysconfdir = src_dir; - Layout::get()->prefix = src_dir; - ::remove("./test/var/trafficserver/cache.db"); } }; CATCH_REGISTER_LISTENER(EventProcessorListener); diff --git a/iocore/cache/test/test_RWW.cc b/iocore/cache/test/test_RWW.cc index ee86681d58b..dab2f607195 100644 --- a/iocore/cache/test/test_RWW.cc +++ b/iocore/cache/test/test_RWW.cc @@ -275,7 +275,7 @@ class CacheRWWErrorTest : public CacheRWWTest case VC_EVENT_ERROR: case VC_EVENT_EOS: if (this->_size == LARGE_FILE) { - REQUIRE(base->vio->ndone >= 1 * 1024 * 1024 - sizeof(Doc)); + REQUIRE(base->vio->ndone >= int64_t(1 * 1024 * 1024 - sizeof(Doc))); } else { REQUIRE(base->vio->ndone == 0); }