diff --git a/src/support/src/Logger.cpp b/src/support/src/Logger.cpp index d82eef6..99f87c1 100644 --- a/src/support/src/Logger.cpp +++ b/src/support/src/Logger.cpp @@ -9,8 +9,6 @@ #include "Options.h" Logger &Logger::get() { - // Ensure proper destruction order for tests - Options::get(); static Logger logger; return logger; } diff --git a/src/vm/src/MemoryContext.cpp b/src/vm/src/MemoryContext.cpp index fe79c8d..376ec8a 100644 --- a/src/vm/src/MemoryContext.cpp +++ b/src/vm/src/MemoryContext.cpp @@ -197,9 +197,6 @@ void MemoryContext::gc_thread_entry() { } } MemoryContext &MemoryContext::get() { - // Ensure proper destruction order for tests - Options::get(); - Logger::get(); static MemoryContext mc; return mc; } diff --git a/test/vm/GCTest.cpp b/test/vm/GCTest.cpp index fd50551..cf8d2c6 100644 --- a/test/vm/GCTest.cpp +++ b/test/vm/GCTest.cpp @@ -5,6 +5,22 @@ #include #include "MemoryContext.h" +class Environment : public ::testing::Environment { +public: + ~Environment() override {} + + void SetUp() override { + Options::set_int("cell_limit", 60000); + Logger::set_level("MemoryContext", Logger::INFO); + } + + void TearDown() override { + Options::reset(); + Logger::reset(); + } +}; + +testing::Environment *const env = testing::AddGlobalTestEnvironment(new Environment); TEST(GCTest, GCTest) { @@ -19,6 +35,7 @@ TEST(GCTest, GCTest) { } MemoryContext::get().request_gc_and_wait(); MemoryContext::get().request_gc_and_wait(); + MemoryContext::get().request_gc_and_wait(); EXPECT_EQ(MemoryContext::get().cell_count(), 0); { Handle c = Handle::cons(nullptr, nullptr); @@ -31,6 +48,7 @@ TEST(GCTest, GCTest) { } MemoryContext::get().request_gc_and_wait(); MemoryContext::get().request_gc_and_wait(); + MemoryContext::get().request_gc_and_wait(); EXPECT_EQ(MemoryContext::get().cell_count(), 0); } @@ -45,6 +63,7 @@ TEST(GCTest, GCTestAppend) { } MemoryContext::get().request_gc_and_wait(); MemoryContext::get().request_gc_and_wait(); + MemoryContext::get().request_gc_and_wait(); EXPECT_EQ(MemoryContext::get().cell_count(), 0); } TEST(GCTest, GCTestPop) { @@ -63,6 +82,7 @@ TEST(GCTest, GCTestPop) { } MemoryContext::get().request_gc_and_wait(); MemoryContext::get().request_gc_and_wait(); + MemoryContext::get().request_gc_and_wait(); EXPECT_EQ(MemoryContext::get().cell_count(), 0); } @@ -80,6 +100,7 @@ TEST(GCTest, GCTestAppend2) { } MemoryContext::get().request_gc_and_wait(); MemoryContext::get().request_gc_and_wait(); + MemoryContext::get().request_gc_and_wait(); EXPECT_EQ(MemoryContext::get().cell_count(), 0); } @@ -98,5 +119,6 @@ TEST(GCTest, GCTestAppend3) { } MemoryContext::get().request_gc_and_wait(); MemoryContext::get().request_gc_and_wait(); + MemoryContext::get().request_gc_and_wait(); EXPECT_EQ(MemoryContext::get().cell_count(), 0); } diff --git a/test/vm/VMTest.cpp b/test/vm/VMTest.cpp index 769b994..18e2be8 100644 --- a/test/vm/VMTest.cpp +++ b/test/vm/VMTest.cpp @@ -2,6 +2,22 @@ #include "Command.h" #include "VM.h" +class Environment : public ::testing::Environment { +public: + ~Environment() override {} + + void SetUp() override { + Options::set_int("cell_limit", 1000); + Logger::set_level("MemoryContext", Logger::INFO); + } + + void TearDown() override { + Options::reset(); + Logger::reset(); + } +}; + +testing::Environment *const env = testing::AddGlobalTestEnvironment(new Environment); using namespace Command; TEST(VMTest, BasicHello) { diff --git a/test/vm/VMWithParserTest.cpp b/test/vm/VMWithParserTest.cpp index f834ffb..b125306 100644 --- a/test/vm/VMWithParserTest.cpp +++ b/test/vm/VMWithParserTest.cpp @@ -3,6 +3,24 @@ #include "Parser.h" #include "VM.h" +class Environment : public ::testing::Environment { +public: + ~Environment() override {} + + void SetUp() override { + Options::set_int("cell_limit", 2000); + Logger::set_level("MemoryContext", Logger::INFO); + } + + void TearDown() override { + Options::reset(); + Logger::reset(); + } +}; + +testing::Environment *const env = testing::AddGlobalTestEnvironment(new Environment); + + TEST(VMWithParserTest, BasicHello) { std::stringstream ssin; std::stringstream ssout; @@ -63,6 +81,7 @@ TEST(VMWithParserTest, RecFunction) { } MemoryContext::get().request_gc_and_wait(); MemoryContext::get().request_gc_and_wait(); + MemoryContext::get().request_gc_and_wait(); EXPECT_EQ(MemoryContext::get().cell_count(), 0); ssout.flush(); EXPECT_EQ(ssout.str(), "6765");