summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAina Niemetz <aina.niemetz@gmail.com>2020-12-08 15:10:50 -0800
committerGitHub <noreply@github.com>2020-12-08 17:10:50 -0600
commit66cfa09ecbd7d6eac2778745c9837dc20b8a23e7 (patch)
tree4c7432d9985d99237656bde4930f47cc3987f13c
parent55bebd57afd3a5f56b58d67a0a68b209ebd7e3ac (diff)
google test: context: Migrate context_mm_black. (#5592)
-rw-r--r--test/unit/context/CMakeLists.txt4
-rw-r--r--test/unit/context/context_mm_black.cpp107
-rw-r--r--test/unit/context/context_mm_black.h106
3 files changed, 109 insertions, 108 deletions
diff --git a/test/unit/context/CMakeLists.txt b/test/unit/context/CMakeLists.txt
index 1f623ea21..7d99fcbb2 100644
--- a/test/unit/context/CMakeLists.txt
+++ b/test/unit/context/CMakeLists.txt
@@ -16,5 +16,5 @@ cvc4_add_unit_test_black(cdmap_black context)
cvc4_add_unit_test_white(cdmap_white context)
cvc4_add_unit_test_black(cdo_black context)
cvc4_add_unit_test_black(context_black context)
-cvc4_add_cxx_unit_test_black(context_mm_black context)
-cvc4_add_cxx_unit_test_white(context_white context)
+cvc4_add_unit_test_black(context_mm_black context)
+cvc4_add_cxx_unit_test_white(context_white context) \ No newline at end of file
diff --git a/test/unit/context/context_mm_black.cpp b/test/unit/context/context_mm_black.cpp
new file mode 100644
index 000000000..ac97a9995
--- /dev/null
+++ b/test/unit/context/context_mm_black.cpp
@@ -0,0 +1,107 @@
+/********************* */
+/*! \file context_mm_black.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Dejan Jovanovic, Aina Niemetz, Andres Noetzli
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
+ ** in the top-level source directory and their institutional affiliations.
+ ** All rights reserved. See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Black box testing of CVC4::context::ContextMemoryManager.
+ **
+ ** Black box testing of CVC4::context::ContextMemoryManager.
+ **/
+
+#include <cstring>
+#include <iostream>
+#include <vector>
+
+#include "context/context_mm.h"
+#include "test.h"
+
+namespace CVC4 {
+
+using namespace context;
+
+namespace test {
+
+class TestContextMMBlack : public TestInternal
+{
+ protected:
+ void SetUp() override { d_cmm.reset(new ContextMemoryManager()); }
+ std::unique_ptr<ContextMemoryManager> d_cmm;
+};
+
+TEST_F(TestContextMMBlack, push_pop)
+{
+#ifdef CVC4_DEBUG_CONTEXT_MEMORY_MANAGER
+#warning "Using the debug context memory manager, omitting unit tests"
+#else
+ // Push, then allocate, then pop
+ // We make sure that we don't allocate too much so that all the regions
+ // should be reclaimed
+ uint32_t chunk_size_bytes = 16384;
+ uint32_t max_free_chunks = 100;
+ uint32_t pieces_per_chunk = 13;
+ uint32_t len;
+ uint32_t n;
+
+ len = chunk_size_bytes / pieces_per_chunk; // Length of the individual block
+ n = max_free_chunks * pieces_per_chunk;
+ for (uint32_t p = 0; p < 5; ++p)
+ {
+ d_cmm->push();
+ for (uint32_t i = 0; i < n; ++i)
+ {
+ char* newMem = (char*)d_cmm->newData(len);
+ // We only setup the memory in the first run, the others should
+ // reclaim the same memory
+ if (p == 0)
+ {
+ for (uint32_t k = 0; k < len - 1; k++)
+ {
+ newMem[k] = 'a';
+ }
+ newMem[len - 1] = 0;
+ }
+ if (strlen(newMem) != len - 1)
+ {
+ std::cout << strlen(newMem) << " : " << len - 1 << std::endl;
+ }
+ ASSERT_EQ(strlen(newMem), len - 1);
+ }
+ d_cmm->pop();
+ }
+
+ uint32_t factor = 3;
+ n = 16384 / factor;
+ // Push, then allocate, then pop all at once
+ for (uint32_t p = 0; p < 5; ++p)
+ {
+ d_cmm->push();
+ for (uint32_t i = 1; i < n; ++i)
+ {
+ len = i * factor;
+ char* newMem = (char*)d_cmm->newData(len);
+ for (uint32_t k = 0; k < len - 1; k++)
+ {
+ newMem[k] = 'a';
+ }
+ newMem[len - 1] = 0;
+ ASSERT_EQ(strlen(newMem), len - 1);
+ }
+ }
+ for (uint32_t p = 0; p < 5; ++p)
+ {
+ d_cmm->pop();
+ }
+
+ // Try popping out of scope
+ ASSERT_DEATH(d_cmm->pop(), "d_nextFreeStack.size\\(\\) > 0");
+#endif
+}
+
+} // namespace test
+} // namespace CVC4
diff --git a/test/unit/context/context_mm_black.h b/test/unit/context/context_mm_black.h
deleted file mode 100644
index 8167edeed..000000000
--- a/test/unit/context/context_mm_black.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/********************* */
-/*! \file context_mm_black.h
- ** \verbatim
- ** Top contributors (to current version):
- ** Dejan Jovanovic, Aina Niemetz, Andres Noetzli
- ** This file is part of the CVC4 project.
- ** Copyright (c) 2009-2020 by the authors listed in the file AUTHORS
- ** in the top-level source directory and their institutional affiliations.
- ** All rights reserved. See the file COPYING in the top-level source
- ** directory for licensing information.\endverbatim
- **
- ** \brief Black box testing of CVC4::context::ContextMemoryManager.
- **
- ** Black box testing of CVC4::context::ContextMemoryManager.
- **/
-
-#include <cxxtest/TestSuite.h>
-#include <cstring>
-
-//Used in some of the tests
-#include <vector>
-#include <iostream>
-
-#include "context/context_mm.h"
-#include "test_utils.h"
-
-using namespace std;
-using namespace CVC4::context;
-
-class ContextBlack : public CxxTest::TestSuite {
-private:
-
- ContextMemoryManager* d_cmm;
-
- public:
- void setUp() override { d_cmm = new ContextMemoryManager(); }
-
- void testPushPop()
- {
-#ifdef CVC4_DEBUG_CONTEXT_MEMORY_MANAGER
-#warning "Using the debug context memory manager, omitting unit tests"
-#else
- // Push, then allocate, then pop
- // We make sure that we don't allocate too much so that all the regions
- // should be reclaimed
- uint32_t chunkSizeBytes = 16384;
- uint32_t maxFreeChunks = 100;
- uint32_t piecesPerChunk = 13;
- uint32_t len;
- uint32_t N;
-
- len = chunkSizeBytes / piecesPerChunk; // Length of the individual block
- N = maxFreeChunks * piecesPerChunk;
- for (uint32_t p = 0; p < 5; ++p)
- {
- d_cmm->push();
- for (uint32_t i = 0; i < N; ++i)
- {
- char* newMem = (char*)d_cmm->newData(len);
- // We only setup the memory in the first run, the others should
- // reclaim the same memory
- if(p == 0) {
- for (uint32_t k = 0; k < len - 1; k++)
- {
- newMem[k] = 'a';
- }
- newMem[len-1] = 0;
- }
- if(strlen(newMem) != len - 1) {
- cout << strlen(newMem) << " : " << len - 1 << endl;
- }
- TS_ASSERT(strlen(newMem) == len - 1);
- }
- d_cmm->pop();
- }
-
- uint32_t factor = 3;
- N = 16384 / factor;
- // Push, then allocate, then pop all at once
- for (uint32_t p = 0; p < 5; ++p)
- {
- d_cmm->push();
- for (uint32_t i = 1; i < N; ++i)
- {
- len = i * factor;
- char* newMem = (char*)d_cmm->newData(len);
- for (uint32_t k = 0; k < len - 1; k++)
- {
- newMem[k] = 'a';
- }
- newMem[len - 1] = 0;
- TS_ASSERT(strlen(newMem) == len - 1);
- }
- }
- for (uint32_t p = 0; p < 5; ++p)
- {
- d_cmm->pop();
- }
-
- // Try popping out of scope
- TS_UTILS_EXPECT_ABORT(d_cmm->pop());
-#endif /* __CVC4__CONTEXT__CONTEXT_MM_H */
- }
-
- void tearDown() override { delete d_cmm; }
-};
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback