Skip to content

Commit d3d7a61

Browse files
committed
Merge branch 'test-cleanup-fix':
Clean up debugging globals between test runs - fixes segfault when calling ./bin/runTests
2 parents 61f453b + 31359fd commit d3d7a61

22 files changed

+121
-4
lines changed

src/debugging.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ extern EncryptedArray* dbgEa;
3636
extern NTL::ZZX dbg_ptxt;
3737
extern NTL::Vec<NTL::ZZ> ptxt_pwr; // powerful basis
3838

39+
// Cleanup method for using the above debug variables several times in one process
40+
inline void cleanupGlobals()
41+
{
42+
dbgKey = nullptr;
43+
dbgEa = nullptr;
44+
dbg_ptxt = NTL::ZZX{};
45+
ptxt_pwr = NTL::Vec<NTL::ZZ>{};
46+
}
47+
3948
void decryptAndPrint(std::ostream& s, const Ctxt& ctxt, const FHESecKey& sk,
4049
const EncryptedArray& ea, long flags=0);
4150

src/tests/GTest_Bin_IO.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "FHE.h"
2121
#include "timing.h"
2222
#include "EncryptedArray.h"
23+
#include "debugging.h"
2324

2425
#include "gtest/gtest.h"
2526
#include "test_common.h"
@@ -171,6 +172,11 @@ class GTest_Bin_IO : public ::testing::TestWithParam<Parameters> {
171172
// Nothing clear to do here for now the way the test is written
172173
};
173174

175+
virtual void TearDown() override
176+
{
177+
cleanupGlobals();
178+
}
179+
174180
public:
175181
static void SetUpTestCase() {
176182
testResourcePath = getTestResourcePath();

src/tests/GTest_EaCx.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ class GTest_EaCx : public ::testing::TestWithParam<Parameters> {
8787
#endif
8888
}
8989
}
90+
91+
virtual void TearDown() override
92+
{
93+
#ifdef DEBUG_PRINTOUT
94+
cleanupGlobals();
95+
#endif
96+
}
9097
};
9198

9299
TEST_P(GTest_EaCx, encoding_works_correctly)

src/tests/GTest_EvalMap.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "EvalMap.h"
1616
#include "hypercube.h"
1717
#include "powerful.h"
18+
#include "debugging.h"
1819

1920
#include "gtest/gtest.h"
2021
#include "test_common.h"
@@ -180,6 +181,11 @@ class GTest_EvalMap : public ::testing::TestWithParam<Parameters> {
180181
addSome1DMatrices(secretKey); // compute key-switching matrices that we need
181182
addFrbMatrices(secretKey); // compute key-switching matrices that we need
182183
};
184+
185+
virtual void TearDown() override
186+
{
187+
cleanupGlobals();
188+
}
183189
};
184190

185191

src/tests/GTest_General.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ class GTest_General : public ::testing::TestWithParam<Parameters> {
161161

162162
virtual void TearDown() override
163163
{
164-
};
164+
cleanupGlobals();
165+
}
165166
};
166167

167168
TEST_P(GTest_General, correctly_implements_mix_of_operations_over_four_ciphertexts)

src/tests/GTest_IO.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "FHE.h"
2020
#include "timing.h"
2121
#include "EncryptedArray.h"
22+
#include "debugging.h"
2223

2324
#include "gtest/gtest.h"
2425
#include "test_common.h"
@@ -110,6 +111,11 @@ class GTest_IO : public ::testing::TestWithParam<Parameters> {
110111
std::vector<std::unique_ptr<EncryptedArray>> eas;
111112
std::vector<std::vector<NTL::ZZX>> ptxts;
112113

114+
virtual void TearDown() override
115+
{
116+
cleanupGlobals();
117+
}
118+
113119
public:
114120
static void SetUpTestCase() {
115121
keyFilePath = getTestResourcePath() + "/iotest.txt";

src/tests/GTest_PAlgebra.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <NTL/ZZ.h>
1616
#include "NumbTh.h"
1717
#include "FHEContext.h"
18+
#include "debugging.h"
1819

1920
#include "gtest/gtest.h"
2021
#include "test_common.h"
@@ -86,7 +87,10 @@ class GTest_PAlgebra : public ::testing::TestWithParam<Parameters> {
8687
}
8788
};
8889

89-
90+
virtual void TearDown() override
91+
{
92+
cleanupGlobals();
93+
}
9094
};
9195

9296
TEST_P(GTest_PAlgebra, reads_and_writes_contexts_as_strings)

src/tests/GTest_Permutations.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "timing.h"
1717
#include "permutations.h"
1818
#include "EncryptedArray.h"
19+
#include "debugging.h"
1920

2021
#include "gtest/gtest.h"
2122
#include "test_common.h"
@@ -113,6 +114,11 @@ class GTest_Permutations : public ::testing::TestWithParam<Parameters> {
113114
virtual void SetUp() override {
114115
setDryRun(helib_test::dry);
115116
};
117+
118+
virtual void TearDown() override
119+
{
120+
cleanupGlobals();
121+
}
116122
};
117123

118124
void testCube(NTL::Vec<GenDescriptor>& vec, long widthBound)

src/tests/GTest_PolyEval.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <NTL/ZZ.h>
1414
#include "polyEval.h"
1515
#include "EncryptedArray.h"
16+
#include "debugging.h"
1617

1718
#include "gtest/gtest.h"
1819
#include "test_common.h"
@@ -101,6 +102,11 @@ class GTest_PolyEval : public ::testing::TestWithParam<Parameters>
101102
if (!helib_test::noPrint) std::cout << (isDryRun()? "* dry run, " : "* ")
102103
<< "degree-"<<d<<", m="<<m<<", L="<<L<<", p^r="<<p2r<<std::endl;
103104
};
105+
106+
virtual void TearDown() override
107+
{
108+
cleanupGlobals();
109+
}
104110
};
105111

106112

src/tests/GTest_Powerful.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "hypercube.h"
1313
#include "powerful.h"
1414
#include "FHEContext.h"
15+
#include "debugging.h"
1516

1617
#include "gtest/gtest.h"
1718
#include "test_common.h"
@@ -78,6 +79,11 @@ class GTest_Powerful : public ::testing::TestWithParam<Parameters>
7879
{
7980
buildModChain(context, /*L=*/9, /*c=*/3);
8081
};
82+
83+
virtual void TearDown() override
84+
{
85+
cleanupGlobals();
86+
}
8187
};
8288

8389
TEST_P(GTest_Powerful, simple_conversion_works)

0 commit comments

Comments
 (0)