Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace CppUnit with GoogleTest in AX tests #1919

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
74a14be
Add GoogleTest to AX test; run cppunit and gtest in tandem for gradua…
tstraubinger Sep 27, 2024
7aa409a
Revert deliberate test failure used for testing
tstraubinger Oct 3, 2024
1c51ba5
Convert TestScanners.cc from cppunit to gtest
tstraubinger Oct 3, 2024
8c8fbda
Convert TestAttributeBindings.cc from cppunit to gtest
tstraubinger Oct 3, 2024
3194d38
Convert TestCodecs.cc from cppunit to gtest
tstraubinger Oct 3, 2024
ce3ffd4
Convert TestComputeGeneratorFailures.cc from cppunit to gtest
tstraubinger Oct 3, 2024
3a6781d
Convert TestFunctionGroup.cc from cppunit to gtest
tstraubinger Oct 3, 2024
c0e66ce
Convert TestFunctionRegistry.cc from cppunit to gtest
tstraubinger Oct 3, 2024
323dc5c
Convert TestFunctionTypes.cc from cppunit to gtest
tstraubinger Oct 4, 2024
b90ea23
Convert TestLogger.cc from cppunit to gtest; add gtest friend declara…
tstraubinger Oct 5, 2024
e7d8515
Convert TestStringIR.cc from cppunit to gtest
tstraubinger Oct 5, 2024
f27fcf9
Convert TestSymbolTable.cc from cppunit to gtest
tstraubinger Oct 5, 2024
883727a
Convert TestTypes.cc from cppunit to gtest
tstraubinger Oct 5, 2024
f668ee2
Convert TestAXRun.cc from cppunit to gtest
tstraubinger Oct 5, 2024
892cfa5
Convert TestPointExecutable.cc from cppunit to gtest; add gtest frien…
tstraubinger Oct 5, 2024
a7bb428
Convert TestVolumeExecutable.cc from cppunit to gtest; add gtest frie…
tstraubinger Oct 5, 2024
4ca8cc0
Convert TestArrayPack.cc to use gtest; add temporary support for both…
tstraubinger Oct 18, 2024
c032483
Convert all of AX frontend test suite to use gtest; remove temporary …
tstraubinger Oct 18, 2024
81ce1ac
Convert all of AX integration test suite to use gtest
tstraubinger Oct 28, 2024
f5276db
Remove cppunit utilities from main AX test runner
tstraubinger Oct 29, 2024
1de8690
Remove CppUnit from AX test CMake requirements
tstraubinger Oct 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion openvdb_ax/openvdb_ax/compiler/Logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <openvdb/version.h>

#include <gtest/gtest.h> // FRIEND_TEST, see TestLogger.cc

#include <functional>
#include <string>
#include <unordered_map>
Expand Down Expand Up @@ -197,7 +199,9 @@ class OPENVDB_AX_API Logger

private:

friend class ::TestLogger;
FRIEND_TEST(TestLogger, testParseSetsTree);
FRIEND_TEST(TestLogger, testAddError);
FRIEND_TEST(TestLogger, testAddWarning);
Comment on lines -200 to +204
Copy link
Author

@tstraubinger tstraubinger Oct 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might have been possible to avoid these changes to a header file in order to test private members, but this is the GTest-recommended approach. See https://google.github.io/googletest/advanced.html#testing-private-code


OutputFunction mErrorOutput;
OutputFunction mWarningOutput;
Expand Down
6 changes: 5 additions & 1 deletion openvdb_ax/openvdb_ax/compiler/PointExecutable.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include <openvdb/version.h>
#include <openvdb/points/PointDataGrid.h>

#include <gtest/gtest.h> // FRIEND_TEST, see TestPointExecutable.cc

#include <unordered_map>

class TestPointExecutable;
Expand Down Expand Up @@ -167,7 +169,9 @@ class OPENVDB_AX_API PointExecutable

private:
friend class Compiler;
friend class ::TestPointExecutable;

FRIEND_TEST(TestPointExecutable, testConstructionDestruction);
FRIEND_TEST(TestPointExecutable, testAttributeCodecs);

/// @brief Private method used in the unit tests
bool usesAcceleratedKernel(const points::PointDataTree& tree) const;
Expand Down
5 changes: 4 additions & 1 deletion openvdb_ax/openvdb_ax/compiler/VolumeExecutable.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include <openvdb/version.h>
#include <openvdb/Grid.h>

#include <gtest/gtest.h> // FRIEND_TEST, see TestVolumeExecutable.cc

#include <unordered_map>

class TestVolumeExecutable;
Expand Down Expand Up @@ -293,7 +295,8 @@ class OPENVDB_AX_API VolumeExecutable

private:
friend class Compiler;
friend class ::TestVolumeExecutable;

FRIEND_TEST(TestVolumeExecutable, testConstructionDestruction);

/// @brief Constructor, expected to be invoked by the compiler. Should not
/// be invoked directly.
Expand Down
13 changes: 11 additions & 2 deletions openvdb_ax/openvdb_ax/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,17 @@ elseif(CONCURRENT_MALLOC STREQUAL "Tbbmalloc")
list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS TBB::tbbmalloc)
endif()

find_package(CppUnit ${MINIMUM_CPPUNIT_VERSION} REQUIRED)
list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS CppUnit::cppunit)
find_package(GTest ${MINIMUM_GOOGLETEST_VERSION} REQUIRED)

if(TARGET GTest::gtest_main)
# New gtest targets as of CMake 3.20. Defined by both the Config and Module
# find modes
list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS GTest::gtest GTest::gtest_main)
else()
# Older targets, only defined by the Module find_package calls
list(APPEND OPENVDB_AX_TEST_DEPENDENT_LIBS GTest::GTest GTest::Main)
endif()


set(TEST_SOURCE_FILES
ast/TestScanners.cc
Expand Down
56 changes: 23 additions & 33 deletions openvdb_ax/openvdb_ax/test/ast/TestPrinters.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,38 @@
#include <openvdb_ax/ast/Parse.h>
#include <openvdb_ax/ast/PrintTree.h>

#include <cppunit/extensions/HelperMacros.h>
#include <gtest/gtest.h>

#include <string>
#include <ostream>

using namespace openvdb::ax::ast;
using namespace openvdb::ax::ast::tokens;

class TestPrinters : public CppUnit::TestCase
class TestPrinters : public ::testing::Test
{
public:

CPPUNIT_TEST_SUITE(TestPrinters);
CPPUNIT_TEST(testReprint);
CPPUNIT_TEST_SUITE_END();

void testReprint();
};

CPPUNIT_TEST_SUITE_REGISTRATION(TestPrinters);

void TestPrinters::testReprint()
TEST_F(TestPrinters, testReprint)
{
// Small function providing more verbose output on failures
auto check = [](const std::string& in, const std::string& expected) {
const size_t min = std::min(in.size(), expected.size());
for (size_t i = 0; i < min; ++i) {
if (in[i] != expected[i]) {
std::ostringstream msg;
msg << "TestReprint failed at character " << i << '.'
std::cout << "TestReprint failed at character " << i << '.'
<< '[' << in[i] << "] vs [" << expected[i] << "]\n"
<< "Got:\n" << in
<< "Expected:\n" << expected;
CPPUNIT_FAIL(msg.str());
ADD_FAILURE();
return;
}
}
if (in.size() != expected.size()) {
std::ostringstream msg;
msg << "TestReprint failed at end character.\n"
std::cout << "TestReprint failed at end character.\n"
<< "Got:\n" << in
<< "Expected:\n" << expected ;
CPPUNIT_FAIL(msg.str());
ADD_FAILURE();
}
};

Expand All @@ -56,7 +46,7 @@ void TestPrinters::testReprint()
std::string in = "a + b * c / d % e << f >> g = h & i | j ^ k && l || m;";
std::string expected = "(((a + (((b * c) / d) % e)) << f) >> g = ((((h & i) | (j ^ k)) && l) || m));\n";
Tree::ConstPtr tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -65,7 +55,7 @@ void TestPrinters::testReprint()
in = "(a + b) * (c / d) % e << (f) >> g = (((h & i) | j) ^ k) && l || m;";
expected = "(((((a + b) * (c / d)) % e) << f) >> g = (((((h & i) | j) ^ k) && l) || m));\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -74,7 +64,7 @@ void TestPrinters::testReprint()
in = "a <= b; c >= d; e == f; g != h; i < j; k > l;";
expected = "(a <= b);\n(c >= d);\n(e == f);\n(g != h);\n(i < j);\n(k > l);\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -83,7 +73,7 @@ void TestPrinters::testReprint()
in = "a = b; b += c; c -= d; d /= e; e *= f; f %= 1; g &= 2; h |= 3; i ^= 4; j <<= 5; k >>= 6;";
expected = "a = b;\nb += c;\nc -= d;\nd /= e;\ne *= f;\nf %= 1;\ng &= 2;\nh |= 3;\ni ^= 4;\nj <<= 5;\nk >>= 6;\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -92,7 +82,7 @@ void TestPrinters::testReprint()
in = "++++a; ----b; a++; b--;";
expected = "++++a;\n----b;\na++;\nb--;\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -101,7 +91,7 @@ void TestPrinters::testReprint()
in = "a,b,(c,d),(e,(f,(g,h,i)));";
expected = "(a, b, (c, d), (e, (f, (g, h, i))));\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -110,7 +100,7 @@ void TestPrinters::testReprint()
in = "a.x; b.y; c.z; d[0]; d[1,2]; e[(a.r, c.b), b.g];";
expected = "a[0];\nb[1];\nc[2];\nd[0];\nd[1, 2];\ne[(a[0], c[2]), b[1]];\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -119,7 +109,7 @@ void TestPrinters::testReprint()
in = "a = {0,1}; b = {2,3,4}; c = {a,(b,c), d};";
expected = "a = {0, 1};\nb = {2, 3, 4};\nc = {a, (b, c), d};\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -128,7 +118,7 @@ void TestPrinters::testReprint()
in = "bool a; int b,c; int32 d=0, e; int64 f; float g; double h, i=0;";
expected = "bool a;\nint32 b, c;\nint32 d = 0, e;\nint64 f;\nfloat g;\ndouble h, i = 0;\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -137,7 +127,7 @@ void TestPrinters::testReprint()
in = "if (a) b; else if (c) d; else e; if (a) if (b) { c,d; } else { e,f; }";
expected = "if (a)\n{\nb;\n}\nelse\n{\nif (c)\n{\nd;\n}\nelse\n{\ne;\n}\n}\nif (a)\n{\nif (b)\n{\n(c, d);\n}\nelse\n{\n(e, f);\n}\n}\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -146,7 +136,7 @@ void TestPrinters::testReprint()
in = "return; break; continue; true; false;";
expected = "return;\nbreak;\ncontinue;\ntrue;\nfalse;\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -155,7 +145,7 @@ void TestPrinters::testReprint()
in = "@a; $a; v@b; v$b; f@a; f$a; i@c; i$c; s@d; s$d;";
expected = "float@a;\nfloat$a;\nvec3f@b;\nvec3f$b;\nfloat@a;\nfloat$a;\nint32@c;\nint32$c;\nstring@d;\nstring$d;\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -164,7 +154,7 @@ void TestPrinters::testReprint()
in = "a ? b : c; a ? b ? c ? : d : e : f;";
expected = "a ? b : c;\na ? b ? c ?: d : e : f;\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -173,7 +163,7 @@ void TestPrinters::testReprint()
in = "while (a) for (int32 b, c;;) do { d; } while (e)";
expected = "while (a)\n{\nfor (int32 b, c; true; )\n{\ndo\n{\nd;\n}\nwhile (e)\n}\n}\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, "");
check(os.str(), ("{\n" + expected + "}\n"));

Expand All @@ -182,7 +172,7 @@ void TestPrinters::testReprint()
in = "while (a) for (int32 b, c;;) do { d; } while (e)";
expected = " while (a)\n {\n for (int32 b, c; true; )\n {\n do\n {\n d;\n }\n while (e)\n }\n }\n";
tree = parse(in.c_str());
CPPUNIT_ASSERT(tree.get());
ASSERT_TRUE(tree.get());
reprint(*tree, os, " ");
check(os.str(), ("{\n" + expected + "}\n"));
}
Expand Down
Loading
Loading