From 48a891316490fd8bc8574aafbd390eb96011ee40 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Apr 2023 14:35:56 +0100 Subject: test-assetFactory depends on all resource files --- test/Jamfile.jam | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index bf1c408..390880d 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -54,7 +54,7 @@ run test-text.cpp ; run test-enumDetails.cpp ; run test-render.cpp : : : test ; run test-glContextBhvr.cpp ; -run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.xml *.png ] fixtures/rgb.txt ] : test ; +run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.* ] fixtures/rgb.txt ] : test ; run perf-assetFactory.cpp : : : benchmark test test-assetFactory ; run perf-persistence.cpp : : : benchmark test test-persistence ; compile test-static-enumDetails.cpp ; -- cgit v1.2.3 From b25bc3cc32c5a9057c66ad282fa1cdfe0ed6094a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 10 Apr 2023 18:45:13 +0100 Subject: First cut loading assets using assimp This is far from perfect, specifically the created texture atlas is not compatibile with wrapping texture UVs --- test/perf-assetFactory.cpp | 11 +++++++++++ test/test-assetFactory.cpp | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) (limited to 'test') diff --git a/test/perf-assetFactory.cpp b/test/perf-assetFactory.cpp index c90ac52..147e4ba 100644 --- a/test/perf-assetFactory.cpp +++ b/test/perf-assetFactory.cpp @@ -14,6 +14,17 @@ brush47xml_load(benchmark::State & state) } } +static void +foliagexml_load(benchmark::State & state) +{ + TestMainWindow window; + + for (auto _ : state) { + benchmark::DoNotOptimize(AssetFactory::loadXML(RESDIR "/foliage.xml")); + } +} + BENCHMARK(brush47xml_load); +BENCHMARK(foliagexml_load); BENCHMARK_MAIN(); diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 54168aa..dd458ca 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -8,6 +8,8 @@ #include "assetFactory/assetFactory.h" #include "assetFactory/object.h" #include "assetFactory/texturePacker.h" +#include "game/scenary/foliage.h" +#include "game/scenary/plant.h" #include "game/vehicles/railVehicle.h" #include "game/vehicles/railVehicleClass.h" #include "gfx/gl/sceneRenderer.h" @@ -96,6 +98,21 @@ BOOST_AUTO_TEST_CASE(brush47xml, *boost::unit_test::timeout(5)) render(); } + +BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) +{ + auto mf = AssetFactory::loadXML(RESDIR "/foliage.xml"); + BOOST_REQUIRE(mf); + auto tree_01_1 = mf->assets.at("Tree-01-1"); + BOOST_REQUIRE(tree_01_1); + auto tree_01_1_f = std::dynamic_pointer_cast(tree_01_1); + BOOST_REQUIRE(tree_01_1_f); + + auto plant = std::make_shared(tree_01_1_f, Location {}); + objects.objects.push_back(plant); + + render(); +} BOOST_AUTO_TEST_SUITE_END(); template using InOut = std::tuple; -- cgit v1.2.3 From 1efd1c0cabb19c0d305b64d6e8aa1df3ab2150da Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 01:40:28 +0100 Subject: Extend timeout... this can be a bit slow now --- test/test-assetFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index dd458ca..4fde5ed 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -174,7 +174,7 @@ BOOST_AUTO_TEST_CASE(texturePacker_many, *boost::unit_test::timeout(5)) BOOST_CHECK_EQUAL(totalSize, TexturePacker::area(result.second)); } -BOOST_AUTO_TEST_CASE(texturePacker_many_random, *boost::unit_test::timeout(5)) +BOOST_AUTO_TEST_CASE(texturePacker_many_random, *boost::unit_test::timeout(15)) { std::vector images(2048); std::mt19937 gen(std::random_device {}()); -- cgit v1.2.3 From 0638aaaf2a60efae95a1b404d7eee29e894047bc Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 01:54:19 +0100 Subject: No need to pass size around, we can get it back from the texture --- test/test-assetFactory.cpp | 2 +- test/test-render.cpp | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 4fde5ed..59dc40d 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -32,7 +32,7 @@ public: glDisable(GL_DEBUG_OUTPUT); auto outpath = (TMP / boost::unit_test::framework::current_test_case().full_name()).replace_extension(".tga"); std::filesystem::create_directories(outpath.parent_path()); - Texture::save(outImage, size, outpath.c_str()); + Texture::save(outImage, outpath.c_str()); } void content(const SceneShader & shader) const override diff --git a/test/test-render.cpp b/test/test-render.cpp index 7771760..8c6b31c 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -73,7 +73,7 @@ BOOST_AUTO_TEST_CASE(basic) const TestScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); - Texture::save(outImage, size, "/tmp/basic.tga"); + Texture::save(outImage, "/tmp/basic.tga"); } BOOST_AUTO_TEST_CASE(pointlight) @@ -101,7 +101,7 @@ BOOST_AUTO_TEST_CASE(pointlight) const PointLightScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); - Texture::save(outImage, size, "/tmp/pointlight.tga"); + Texture::save(outImage, "/tmp/pointlight.tga"); } BOOST_AUTO_TEST_CASE(spotlight) @@ -128,7 +128,7 @@ BOOST_AUTO_TEST_CASE(spotlight) const PointLightScene scene; ss.render(scene); glDisable(GL_DEBUG_OUTPUT); - Texture::save(outImage, size, "/tmp/spotlight.tga"); + Texture::save(outImage, "/tmp/spotlight.tga"); } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3 From 4bf94458d5d7abafb154e914620dc758d26719c2 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 10:24:10 +0100 Subject: Global worker instance --- test/Jamfile.jam | 1 + test/test-worker.cpp | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 test/test-worker.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 390880d..482b388 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -57,6 +57,7 @@ run test-glContextBhvr.cpp ; run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.* ] fixtures/rgb.txt ] : test ; run perf-assetFactory.cpp : : : benchmark test test-assetFactory ; run perf-persistence.cpp : : : benchmark test test-persistence ; +run test-worker.cpp ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; explicit perf-assetFactory ; diff --git a/test/test-worker.cpp b/test/test-worker.cpp new file mode 100644 index 0000000..3c5ed7e --- /dev/null +++ b/test/test-worker.cpp @@ -0,0 +1,7 @@ +#define BOOST_TEST_MODULE test_worker + +#include "testHelpers.h" +#include +#include + +BOOST_AUTO_TEST_CASE(exists) { } -- cgit v1.2.3 From aa77548bd637ffd1a7461136e6206906dc4c61c7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 11:54:45 +0100 Subject: New WorkItem/job/promise/future based interface --- test/test-worker.cpp | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/test-worker.cpp b/test/test-worker.cpp index 3c5ed7e..c542020 100644 --- a/test/test-worker.cpp +++ b/test/test-worker.cpp @@ -2,6 +2,43 @@ #include "testHelpers.h" #include +#include #include +#include -BOOST_AUTO_TEST_CASE(exists) { } +uint32_t +workCounter() +{ + static std::atomic_uint32_t n; + usleep(1000); + return n++; +} + +BOOST_AUTO_TEST_CASE(basic_slow_counter) +{ + std::vector> ps; + for (int i {}; i < 30; ++i) { + ps.push_back(Worker::addWork(workCounter)); + } + std::set out; + std::transform(ps.begin(), ps.end(), std::inserter(out, out.end()), [](auto && p) { + return p->get(); + }); + BOOST_REQUIRE_EQUAL(out.size(), ps.size()); + BOOST_CHECK_EQUAL(*out.begin(), 0); + BOOST_CHECK_EQUAL(*out.rbegin(), ps.size() - 1); +} + +BOOST_AUTO_TEST_CASE(basic_error_handler) +{ + auto workitem = Worker::addWork([]() { + throw std::runtime_error {"test"}; + }); + BOOST_CHECK_THROW(workitem->get(), std::runtime_error); +} + +BOOST_AUTO_TEST_CASE(basic_void_work) +{ + auto workitem = Worker::addWork([]() {}); + BOOST_CHECK_NO_THROW(workitem->get()); +} -- cgit v1.2.3 From e671adba5a57e1d4e848eb4d6de0f480e7b3709a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 12:29:24 +0100 Subject: Simplify doWork, add tests for various interface uses --- test/test-worker.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 4 deletions(-) (limited to 'test') diff --git a/test/test-worker.cpp b/test/test-worker.cpp index c542020..319261b 100644 --- a/test/test-worker.cpp +++ b/test/test-worker.cpp @@ -14,6 +14,19 @@ workCounter() return n++; } +void +workVoid() +{ + usleep(1000); +} + +void +workFail() +{ + usleep(1000); + throw std::runtime_error {"test"}; +} + BOOST_AUTO_TEST_CASE(basic_slow_counter) { std::vector> ps; @@ -31,14 +44,40 @@ BOOST_AUTO_TEST_CASE(basic_slow_counter) BOOST_AUTO_TEST_CASE(basic_error_handler) { - auto workitem = Worker::addWork([]() { - throw std::runtime_error {"test"}; - }); + auto workitem = Worker::addWork(workFail); BOOST_CHECK_THROW(workitem->get(), std::runtime_error); } BOOST_AUTO_TEST_CASE(basic_void_work) { - auto workitem = Worker::addWork([]() {}); + auto workitem = Worker::addWork(workVoid); BOOST_CHECK_NO_THROW(workitem->get()); } + +BOOST_AUTO_TEST_CASE(lambda_void) +{ + BOOST_CHECK_NO_THROW(Worker::addWork([]() {})->get()); + BOOST_CHECK_NO_THROW(Worker::addWork([](int) {}, 0)->get()); + BOOST_CHECK_NO_THROW(Worker::addWork([](int, int) {}, 0, 0)->get()); +} + +BOOST_AUTO_TEST_CASE(lambda_value) +{ + BOOST_CHECK_EQUAL(1, Worker::addWork([]() { + return 1; + })->get()); + BOOST_CHECK_EQUAL(2, + Worker::addWork( + [](int i) { + return i; + }, + 2) + ->get()); + BOOST_CHECK_EQUAL(3, + Worker::addWork( + [](int i, int j) { + return i + j; + }, + 1, 2) + ->get()); +} -- cgit v1.2.3 From f8ee56f6dc8cf7e92c4bfc5930d32b14f634141c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 13:13:47 +0100 Subject: Current thread partakes in work effort while waiting This will prevent deadlock if the work pool is otherwise busy by ensuring work is always being done --- test/test-worker.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test') diff --git a/test/test-worker.cpp b/test/test-worker.cpp index 319261b..76b7138 100644 --- a/test/test-worker.cpp +++ b/test/test-worker.cpp @@ -81,3 +81,24 @@ BOOST_AUTO_TEST_CASE(lambda_value) 1, 2) ->get()); } + +BOOST_AUTO_TEST_CASE(recursive, *boost::unit_test::timeout(5)) +{ + auto recurse = []() { + std::vector> ps; + for (int i {}; i < 30; ++i) { + ps.push_back(Worker::addWork(workCounter)); + } + return std::accumulate(ps.begin(), ps.end(), 0U, [](auto && out, auto && p) { + return out += p->get(); + }); + }; + std::vector> ps; + for (int i {}; i < 30; ++i) { + ps.push_back(Worker::addWork(recurse)); + } + std::set out; + std::transform(ps.begin(), ps.end(), std::inserter(out, out.end()), [](auto && p) { + return p->get(); + }); +} -- cgit v1.2.3 From 41b6cc54a739ef1776c4e827a0e82c33438f1c14 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 16:37:04 +0100 Subject: Adjust test render view to get a closer view of our tree --- test/test-assetFactory.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index 59dc40d..c425e71 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -108,10 +108,10 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) auto tree_01_1_f = std::dynamic_pointer_cast(tree_01_1); BOOST_REQUIRE(tree_01_1_f); - auto plant = std::make_shared(tree_01_1_f, Location {}); + auto plant = std::make_shared(tree_01_1_f, Location {{-2, 2, 0}, {}}); objects.objects.push_back(plant); - render(); + render(5); } BOOST_AUTO_TEST_SUITE_END(); -- cgit v1.2.3 From 7c2977ee4de2cfd967871a0927443f24361944b1 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 17:07:40 +0100 Subject: Use asset factory models in test-render --- test/Jamfile.jam | 6 +++--- test/test-render.cpp | 24 +++++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index 482b388..d91af1d 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -52,11 +52,11 @@ run test-network.cpp ; run test-persistence.cpp : -- : [ sequence.insertion-sort [ glob-tree fixtures : *.json ] ] : test ; run test-text.cpp ; run test-enumDetails.cpp ; -run test-render.cpp : : : test ; +run test-render.cpp : -- : test-assetFactory : test ; run test-glContextBhvr.cpp ; run test-assetFactory.cpp : -- : [ sequence.insertion-sort [ glob-tree $(res) : *.* ] fixtures/rgb.txt ] : test ; -run perf-assetFactory.cpp : : : benchmark test test-assetFactory ; -run perf-persistence.cpp : : : benchmark test test-persistence ; +run perf-assetFactory.cpp : -- : test-assetFactory : benchmark test ; +run perf-persistence.cpp : -- : test-persistence : benchmark test ; run test-worker.cpp ; compile test-static-enumDetails.cpp ; compile test-static-stream_support.cpp ; diff --git a/test/test-render.cpp b/test/test-render.cpp index 8c6b31c..45acab5 100644 --- a/test/test-render.cpp +++ b/test/test-render.cpp @@ -6,8 +6,10 @@ #include #include +#include #include #include +#include #include #include #include @@ -19,18 +21,30 @@ #include class TestScene : public SceneProvider { - RailVehicleClass train {"brush47"}; + std::shared_ptr train1, train2; + Terrain terrain {[]() { auto gd = std::make_shared(GeoData::Limits {{0, 0}, {100, 100}}); gd->generateRandom(); return gd; }()}; + +public: + TestScene() + { + const auto assetFactory = AssetFactory::loadXML(RESDIR "/brush47.xml"); + const auto brush47rvc = std::dynamic_pointer_cast(assetFactory->assets.at("brush-47")); + train1 = std::make_shared(brush47rvc); + train1->location.pos = {52, 50, 2}; + train2 = std::make_shared(brush47rvc); + train2->location.pos = {52, 30, 2}; + } void content(const SceneShader & shader) const override { terrain.render(shader); - train.render(shader, Location {{52, 50, 2}}, {Location {{52, 56, 2}}, Location {{52, 44, 2}}}); - train.render(shader, Location {{52, 30, 2}}, {Location {{52, 36, 2}}, Location {{52, 24, 2}}}); + train1->render(shader); + train2->render(shader); } void lights(const SceneShader &) const override @@ -40,8 +54,8 @@ class TestScene : public SceneProvider { shadows(const ShadowMapper & shadowMapper) const override { terrain.shadows(shadowMapper); - train.shadows(shadowMapper, Location {{52, 50, 2}}, {Location {{52, 56, 2}}, Location {{52, 44, 2}}}); - train.shadows(shadowMapper, Location {{52, 30, 2}}, {Location {{52, 36, 2}}, Location {{52, 24, 2}}}); + train1->shadows(shadowMapper); + train2->shadows(shadowMapper); } }; -- cgit v1.2.3 From 47cd9d863fb09acb82d2428f881d61242f8ab437 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 17:33:02 +0100 Subject: Load all assets in red dir with asset factory --- test/test-assetFactory.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'test') diff --git a/test/test-assetFactory.cpp b/test/test-assetFactory.cpp index c425e71..3d79213 100644 --- a/test/test-assetFactory.cpp +++ b/test/test-assetFactory.cpp @@ -115,6 +115,13 @@ BOOST_AUTO_TEST_CASE(foliage, *boost::unit_test::timeout(5)) } BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_CASE(loadall) +{ + const auto assets = AssetFactory::loadAll(RESDIR); + BOOST_CHECK(assets.at("brush-47")); + BOOST_CHECK(assets.at("Tree-01-1")); +} + template using InOut = std::tuple; BOOST_DATA_TEST_CASE(normalizeColourName, boost::unit_test::data::make>({ -- cgit v1.2.3 From 66da4f83c1b5bb6f3ceda880820e01c2f8e23e43 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 14 Apr 2023 17:45:31 +0100 Subject: Remove the old .obj load, assets and supporting stuff --- test/Jamfile.jam | 1 - test/test-obj.cpp | 39 --------------------------------------- 2 files changed, 40 deletions(-) delete mode 100644 test/test-obj.cpp (limited to 'test') diff --git a/test/Jamfile.jam b/test/Jamfile.jam index d91af1d..b0eed5e 100644 --- a/test/Jamfile.jam +++ b/test/Jamfile.jam @@ -44,7 +44,6 @@ project : requirements lib test : [ glob *.cpp : test-*.cpp perf-*.cpp ] ; run test-collection.cpp ; -run test-obj.cpp ; run test-maths.cpp ; run test-lib.cpp ; run test-geo.cpp ; diff --git a/test/test-obj.cpp b/test/test-obj.cpp deleted file mode 100644 index e6e725d..0000000 --- a/test/test-obj.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#define BOOST_TEST_MODULE test_obj - -#include - -#include -#include -#include -#include -#include -#include -#include - -BOOST_AUTO_TEST_CASE(objparse) -{ - const ObjParser op {RESDIR "/brush47.obj"}; - BOOST_CHECK_EQUAL(75, op.vertices.size()); - BOOST_CHECK_EQUAL(112, op.texCoords.size()); - BOOST_CHECK_EQUAL(31, op.normals.size()); - BOOST_CHECK_EQUAL(3, op.objects.size()); - const auto & object {op.objects.front()}; - BOOST_CHECK_EQUAL("Body", object.first); - BOOST_CHECK_EQUAL(21, object.second.size()); - BOOST_CHECK_EQUAL(8, object.second[0].size()); - BOOST_CHECK_EQUAL(8, object.second[1].size()); - BOOST_CHECK_EQUAL(4, object.second[12].size()); -} - -BOOST_AUTO_TEST_CASE(create_meshes) -{ - const ObjParser op {RESDIR "/brush47.obj"}; - const auto ms = op.createMeshData(); - BOOST_REQUIRE_EQUAL(3, ms.size()); - BOOST_REQUIRE_EQUAL("Body", ms.begin()->first); - const auto & o = ms.at("Body"); - BOOST_REQUIRE_EQUAL(88, o.first.size()); - const auto & v = o.first.front(); - BOOST_REQUIRE_CLOSE(-1.345, v.pos.x, 1); - BOOST_REQUIRE_EQUAL(138, o.second.size()); -} -- cgit v1.2.3