From 394d165d6877afe6490bad49f8b957492c5ac3e4 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 2 Feb 2024 01:25:38 +0000 Subject: Fix warnings in test-glContainer Also updates static asserts to requirements --- test/test-glContainer.cpp | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) (limited to 'test') diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index ccf3b90..f19ca74 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -325,27 +325,33 @@ BOOST_FIXTURE_TEST_SUITE(c, glContainer) BOOST_AUTO_TEST_CASE(basic) { - BOOST_CHECK_NO_THROW(emplace_back(1, 2.f)); + BOOST_CHECK_NO_THROW(emplace_back(1, 2.F)); BOOST_CHECK_EQUAL(1, begin()->x); - BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_EQUAL(2.F, begin()->y); BOOST_CHECK_NO_THROW(begin()->x = 3); BOOST_CHECK_EQUAL(3, begin()->x); - BOOST_CHECK_NO_THROW(push_back(C {4, 5.f})); + BOOST_CHECK_NO_THROW(push_back(C {4, 5.F})); BOOST_CHECK_EQUAL(3, begin()->x); - BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_EQUAL(2.F, begin()->y); BOOST_CHECK_EQUAL(4, rbegin()->x); - BOOST_CHECK_EQUAL(5.f, rbegin()->y); + BOOST_CHECK_EQUAL(5.F, rbegin()->y); } BOOST_AUTO_TEST_SUITE_END(); struct CC { + CC() = default; + + CC(int a, float b) noexcept : x {a}, y {b} { } + ~CC() { ++x; } + DEFAULT_MOVE_COPY(CC); + int x; float y; }; @@ -356,17 +362,17 @@ BOOST_FIXTURE_TEST_SUITE(cc, glContainer) BOOST_AUTO_TEST_CASE(basic) { - BOOST_CHECK_NO_THROW(emplace_back(1, 2.f)); + BOOST_CHECK_NO_THROW(emplace_back(1, 2.F)); BOOST_CHECK_EQUAL(1, begin()->x); - BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_EQUAL(2.F, begin()->y); BOOST_CHECK_NO_THROW(begin()->x = 3); BOOST_CHECK_EQUAL(3, begin()->x); - BOOST_CHECK_NO_THROW(push_back(CC {4, 5.f})); + BOOST_CHECK_NO_THROW(push_back(CC {4, 5.F})); BOOST_CHECK_EQUAL(3, begin()->x); - BOOST_CHECK_EQUAL(2.f, begin()->y); + BOOST_CHECK_EQUAL(2.F, begin()->y); BOOST_CHECK_EQUAL(4, rbegin()->x); - BOOST_CHECK_EQUAL(5.f, rbegin()->y); + BOOST_CHECK_EQUAL(5.F, rbegin()->y); BOOST_CHECK_NO_THROW(pop_back()); BOOST_CHECK_EQUAL(size(), 1); BOOST_CHECK_EQUAL(capacity(), 2); @@ -380,11 +386,11 @@ BOOST_AUTO_TEST_CASE(basic) BOOST_AUTO_TEST_CASE(insert_remove_test) { - BOOST_CHECK_NO_THROW(emplace_back(1, 2.f)); - BOOST_CHECK_NO_THROW(emplace_back(3, 4.f)); - BOOST_CHECK_NO_THROW(emplace(begin(), 5, 6.f)); - BOOST_CHECK_NO_THROW(emplace(begin() + 1, 7, 8.f)); - BOOST_CHECK_NO_THROW(emplace(begin() + 2, 9, 10.f)); + BOOST_CHECK_NO_THROW(emplace_back(1, 2.F)); + BOOST_CHECK_NO_THROW(emplace_back(3, 4.F)); + BOOST_CHECK_NO_THROW(emplace(begin(), 5, 6.F)); + BOOST_CHECK_NO_THROW(emplace(begin() + 1, 7, 8.F)); + BOOST_CHECK_NO_THROW(emplace(begin() + 2, 9, 10.F)); BOOST_CHECK_EQUAL(capacity(), 8); BOOST_CHECK_EQUAL(size(), 5); BOOST_CHECK_NO_THROW(shrink_to_fit()); -- cgit v1.2.3 From 9a106a6906d6a9718541633525de540e667b7625 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 2 Feb 2024 02:02:19 +0000 Subject: Don't keep a span, create as needed Removes the error prone issue where data/size get out of sync. Fixes overflow issues leading to memory corruption of GPU data. --- test/test-glContainer.cpp | 19 +++++++++---------- test/test-instancing.cpp | 6 +++--- 2 files changed, 12 insertions(+), 13 deletions(-) (limited to 'test') diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index f19ca74..382bd7a 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -23,14 +23,14 @@ BOOST_FIXTURE_TEST_SUITE(i, glContainer) BOOST_AUTO_TEST_CASE(createDestroy, *boost::unit_test::timeout(1)) { - BOOST_CHECK(!data_.data()); + BOOST_CHECK(!data_); BOOST_CHECK_NO_THROW(map()); - BOOST_REQUIRE(!data_.data()); + BOOST_REQUIRE(!data_); BOOST_CHECK_NO_THROW(emplace_back(0)); BOOST_CHECK_NO_THROW(map()); - BOOST_REQUIRE(data_.data()); + BOOST_REQUIRE(data_); BOOST_CHECK_NO_THROW(unmap()); - BOOST_CHECK(!data_.data()); + BOOST_CHECK(!data_); } BOOST_AUTO_TEST_CASE(push_back_test, *boost::unit_test::timeout(1)) @@ -44,7 +44,6 @@ BOOST_AUTO_TEST_CASE(push_back_test, *boost::unit_test::timeout(1)) BOOST_CHECK_NO_THROW(push_back(5)); BOOST_CHECK_EQUAL(capacity_, 8); BOOST_CHECK_EQUAL(size_, 5); - BOOST_CHECK_EQUAL(data_.size(), 5); { std::array expected1 {1, 2, 3, 4, 5}; BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); @@ -166,7 +165,7 @@ BOOST_AUTO_TEST_CASE(getters) BOOST_CHECK_EQUAL(2, at(1)); BOOST_CHECK_EQUAL(1, (*this)[0]); BOOST_CHECK_EQUAL(2, (*this)[1]); - BOOST_CHECK_EQUAL(data_.data(), data()); + BOOST_CHECK_EQUAL(data_, data()); BOOST_CHECK_THROW(std::ignore = at(2), std::out_of_range); const auto & constCont {*this}; @@ -183,7 +182,7 @@ BOOST_AUTO_TEST_CASE(getters) BOOST_CHECK_EQUAL(2, constCont.at(1)); BOOST_CHECK_EQUAL(1, constCont[0]); BOOST_CHECK_EQUAL(2, constCont[1]); - BOOST_CHECK_EQUAL(data_.data(), constCont.data()); + BOOST_CHECK_EQUAL(data_, constCont.data()); BOOST_CHECK_THROW(std::ignore = constCont.at(2), std::out_of_range); } @@ -209,16 +208,16 @@ BOOST_AUTO_TEST_CASE(random_write) BOOST_CHECK_NO_THROW(resize(3)); BOOST_CHECK_EQUAL(size(), 3); BOOST_CHECK_NO_THROW(unmap()); - BOOST_REQUIRE(!data_.data()); + BOOST_REQUIRE(!data_); BOOST_CHECK_NO_THROW(at(0, 10)); BOOST_CHECK_NO_THROW(at(1, 20)); BOOST_CHECK_NO_THROW(at(2, 30)); - BOOST_CHECK(!data_.data()); + BOOST_CHECK(!data_); { std::array expected1 {10, 20, 30}; BOOST_CHECK_EQUAL_COLLECTIONS(begin(), end(), expected1.begin(), expected1.end()); } - BOOST_CHECK(data_.data()); + BOOST_CHECK(data_); BOOST_CHECK_NO_THROW(at(1, 40)); { std::array expected1 {10, 40, 30}; diff --git a/test/test-instancing.cpp b/test/test-instancing.cpp index 98133f3..c1860a4 100644 --- a/test/test-instancing.cpp +++ b/test/test-instancing.cpp @@ -56,11 +56,11 @@ BOOST_AUTO_TEST_CASE(autoMapUnmap) { { auto proxy = acquire(); - BOOST_CHECK(data_.data()); + BOOST_CHECK(data_); std::ignore = bufferName(); - BOOST_CHECK(data_.data()); + BOOST_CHECK(data_); BOOST_CHECK_EQUAL(1, size()); - BOOST_CHECK(!data_.data()); + BOOST_CHECK(!data_); } BOOST_CHECK_EQUAL(0, size()); } -- cgit v1.2.3 From b85297334ee3b59a738eec4dd8560979b0591c37 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 2 Feb 2024 20:49:09 +0000 Subject: Map buffers RO if const operations, upgrade to RW as required --- test/test-glContainer.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/test-glContainer.cpp b/test/test-glContainer.cpp index 382bd7a..ec1c0d1 100644 --- a/test/test-glContainer.cpp +++ b/test/test-glContainer.cpp @@ -1,6 +1,5 @@ #define BOOST_TEST_MODULE glContainer -#include "testHelpers.h" #include "testMainWindow.h" #include "ui/applicationBase.h" #include @@ -23,14 +22,69 @@ BOOST_FIXTURE_TEST_SUITE(i, glContainer) BOOST_AUTO_TEST_CASE(createDestroy, *boost::unit_test::timeout(1)) { + // Unmapped BOOST_CHECK(!data_); - BOOST_CHECK_NO_THROW(map()); + BOOST_CHECK(!access_); + // Request map, but empty + BOOST_CHECK_NO_THROW(map(GL_READ_ONLY)); BOOST_REQUIRE(!data_); + BOOST_REQUIRE(!access_); + BOOST_CHECK_NO_THROW(map(GL_READ_WRITE)); + BOOST_REQUIRE(!data_); + BOOST_REQUIRE(!access_); + // Add something BOOST_CHECK_NO_THROW(emplace_back(0)); - BOOST_CHECK_NO_THROW(map()); BOOST_REQUIRE(data_); + BOOST_REQUIRE_EQUAL(access_, GL_READ_WRITE); + // Unmap + BOOST_CHECK_NO_THROW(unmap()); + BOOST_REQUIRE(!data_); + BOOST_REQUIRE(!access_); + // Map RO + BOOST_CHECK_NO_THROW(map(GL_READ_ONLY)); + BOOST_REQUIRE(data_); + BOOST_REQUIRE_EQUAL(access_, GL_READ_ONLY); + // Map RW upgradde + BOOST_CHECK_NO_THROW(map(GL_READ_WRITE)); + BOOST_REQUIRE(data_); + BOOST_REQUIRE_EQUAL(access_, GL_READ_WRITE); + // Map RO downgradde, no change + BOOST_CHECK_NO_THROW(map(GL_READ_ONLY)); + BOOST_REQUIRE(data_); + BOOST_REQUIRE_EQUAL(access_, GL_READ_WRITE); + // Unmap BOOST_CHECK_NO_THROW(unmap()); BOOST_CHECK(!data_); + BOOST_CHECK(!access_); +} + +BOOST_AUTO_TEST_CASE(mapModes) +{ + BOOST_CHECK_EQUAL(std::accumulate(begin(), end(), 0), 0); + BOOST_CHECK(!data_); + BOOST_CHECK(!access_); + + BOOST_CHECK_NO_THROW(push_back(1)); + BOOST_CHECK_NO_THROW(push_back(2)); + BOOST_CHECK_NO_THROW(push_back(3)); + BOOST_CHECK_NO_THROW(push_back(4)); + BOOST_CHECK_NO_THROW(unmap()); + + BOOST_CHECK_EQUAL(std::accumulate(cbegin(), cend(), 0), 10); + BOOST_CHECK(data_); + BOOST_CHECK_EQUAL(access_, GL_READ_ONLY); + BOOST_CHECK_NO_THROW(unmap()); + + BOOST_CHECK_EQUAL(std::accumulate(begin(), end(), 0), 10); + BOOST_CHECK(data_); + BOOST_CHECK_EQUAL(access_, GL_READ_WRITE); + BOOST_CHECK_NO_THROW(unmap()); + + const auto & c = *this; + BOOST_CHECK_EQUAL(std::accumulate(c.begin(), c.end(), 0), 10); + BOOST_CHECK(data_); + BOOST_CHECK_EQUAL(access_, GL_READ_ONLY); + BOOST_CHECK_NO_THROW(unmap()); } BOOST_AUTO_TEST_CASE(push_back_test, *boost::unit_test::timeout(1)) -- cgit v1.2.3