From 1ef03a1c7043d617885d319b0803d69907c3c9cc Mon Sep 17 00:00:00 2001 From: Klaus Aehlig Date: Mon, 28 Feb 2022 13:24:26 +0100 Subject: Pass actions and trees in analysis result as shared pointer ... to avoid unnecessary copying and moving of larger objects. --- .../build_engine/target_map/result_map.test.cpp | 53 +++++++++++++--------- .../build_engine/target_map/target_map.test.cpp | 25 +++++----- test/buildtool/common/action_description.test.cpp | 2 +- 3 files changed, 45 insertions(+), 35 deletions(-) (limited to 'test') diff --git a/test/buildtool/build_engine/target_map/result_map.test.cpp b/test/buildtool/build_engine/target_map/result_map.test.cpp index 14bf0638..a0b8f0bc 100644 --- a/test/buildtool/build_engine/target_map/result_map.test.cpp +++ b/test/buildtool/build_engine/target_map/result_map.test.cpp @@ -21,12 +21,12 @@ namespace { [[nodiscard]] auto CreateAnalysedTarget( TargetResult const& result, - std::vector const& descs, + std::vector const& descs, std::vector const& blobs) -> AnalysedTargetPtr { return std::make_shared(result, descs, blobs, - std::vector(), + std::vector(), std::unordered_set{}, std::set{}); } @@ -54,34 +54,43 @@ TEST_CASE("origins creation", "[result_map]") { using BuildMaps::Base::EntityName; using BuildMaps::Target::ResultTargetMap; - auto foo = - ActionDescription{{}, {}, Action{"run_foo", {"touch", "foo"}, {}}, {}}; - auto bar = - ActionDescription{{}, {}, Action{"run_bar", {"touch", "bar"}, {}}, {}}; - auto baz = - ActionDescription{{}, {}, Action{"run_baz", {"touch", "baz"}, {}}, {}}; + auto foo = std::make_shared( + ActionDescription::outputs_t{}, + ActionDescription::outputs_t{}, + Action{"run_foo", {"touch", "foo"}, {}}, + ActionDescription::inputs_t{}); + auto bar = std::make_shared( + ActionDescription::outputs_t{}, + ActionDescription::outputs_t{}, + Action{"run_bar", {"touch", "bar"}, {}}, + ActionDescription::inputs_t{}); + auto baz = std::make_shared( + ActionDescription::outputs_t{}, + ActionDescription::outputs_t{}, + Action{"run_baz", {"touch", "baz"}, {}}, + ActionDescription::inputs_t{}); ResultTargetMap map{0}; CHECK(map.Add(EntityName{"", ".", "foobar"}, {}, CreateAnalysedTarget( - {}, std::vector{foo, bar}, {}))); - CHECK(map.Add( - EntityName{"", ".", "baz"}, - {}, - CreateAnalysedTarget({}, std::vector{baz}, {}))); + {}, std::vector{foo, bar}, {}))); + CHECK(map.Add(EntityName{"", ".", "baz"}, + {}, + CreateAnalysedTarget( + {}, std::vector{baz}, {}))); auto result = map.ToResult(); REQUIRE(result.actions.size() == 3); CHECK(result.blobs.empty()); - auto expect_foo = foo.ToJson(); - auto expect_bar = bar.ToJson(); - auto expect_baz = baz.ToJson(); + auto expect_foo = foo->ToJson(); + auto expect_bar = bar->ToJson(); + auto expect_baz = baz->ToJson(); CHECK(map.ToJson() == nlohmann::json{{"actions", - {{foo.Id(), expect_foo}, - {bar.Id(), expect_bar}, - {baz.Id(), expect_baz}}}, + {{foo->Id(), expect_foo}, + {bar->Id(), expect_bar}, + {baz->Id(), expect_baz}}}, {"blobs", nlohmann::json::array()}, {"trees", nlohmann::json::object()}}); @@ -101,9 +110,9 @@ TEST_CASE("origins creation", "[result_map]") { nlohmann::json from_file{}; file >> from_file; CHECK(from_file == nlohmann::json{{"actions", - {{foo.Id(), expect_foo}, - {bar.Id(), expect_bar}, - {baz.Id(), expect_baz}}}, + {{foo->Id(), expect_foo}, + {bar->Id(), expect_bar}, + {baz->Id(), expect_baz}}}, {"blobs", nlohmann::json::array()}, {"trees", nlohmann::json::object()}}); } diff --git a/test/buildtool/build_engine/target_map/target_map.test.cpp b/test/buildtool/build_engine/target_map/target_map.test.cpp index a711eef3..3bfdfccd 100644 --- a/test/buildtool/build_engine/target_map/target_map.test.cpp +++ b/test/buildtool/build_engine/target_map/target_map.test.cpp @@ -315,9 +315,9 @@ TEST_CASE("simple targets") { // in the vector is guaranteed. The test rule generates the action by // iterating over the "srcs" field, so we get the actions in the order // of that field, not in alphabetical order. - CHECK(result->Actions()[0].ToJson()["input"]["in"]["data"]["path"] == + CHECK(result->Actions()[0]->ToJson()["input"]["in"]["data"]["path"] == "simple_targets/foo.txt"); - CHECK(result->Actions()[1].ToJson()["input"]["in"]["data"]["path"] == + CHECK(result->Actions()[1]->ToJson()["input"]["in"]["data"]["path"] == "simple_targets/bar.txt"); } } @@ -594,9 +594,9 @@ TEST_CASE("target reference") { CHECK(result->Actions().size() == 1); CHECK(result->Actions()[0] - .ToJson()["input"]["raw_data/hello.txt"]["type"] == "LOCAL"); + ->ToJson()["input"]["raw_data/hello.txt"]["type"] == "LOCAL"); CHECK(result->Actions()[0] - .ToJson()["input"]["raw_data/hello.txt"]["data"]["path"] == + ->ToJson()["input"]["raw_data/hello.txt"]["data"]["path"] == "file_reference/hello.txt"); } @@ -665,16 +665,17 @@ TEST_CASE("trees") { CHECK(!error); CHECK(error_msg == "NONE"); CHECK(result->Actions().size() == 1); - CHECK(result->Actions()[0].ToJson()["input"]["tree"]["type"] == "TREE"); - CHECK(result->Actions()[0].ToJson()["input"]["foo.txt"]["type"] == + CHECK(result->Actions()[0]->ToJson()["input"]["tree"]["type"] == + "TREE"); + CHECK(result->Actions()[0]->ToJson()["input"]["foo.txt"]["type"] == "LOCAL"); - CHECK( - result->Actions()[0].ToJson()["input"]["foo.txt"]["data"]["path"] == - "tree/foo.txt"); + CHECK(result->Actions()[0]->ToJson()["input"]["foo.txt"]["data"]["pat" + "h"] == + "tree/foo.txt"); CHECK(result->Trees().size() == 1); - CHECK(result->Trees()[0].ToJson()["foo.txt"]["type"] == "LOCAL"); - CHECK(result->Trees()[0].ToJson()["bar.txt"]["type"] == "LOCAL"); - CHECK(result->Trees()[0].ToJson()["baz.txt"]["type"] == "LOCAL"); + CHECK(result->Trees()[0]->ToJson()["foo.txt"]["type"] == "LOCAL"); + CHECK(result->Trees()[0]->ToJson()["bar.txt"]["type"] == "LOCAL"); + CHECK(result->Trees()[0]->ToJson()["baz.txt"]["type"] == "LOCAL"); } SECTION("stage into tree") { diff --git a/test/buildtool/common/action_description.test.cpp b/test/buildtool/common/action_description.test.cpp index ac7367e1..ee5c00da 100644 --- a/test/buildtool/common/action_description.test.cpp +++ b/test/buildtool/common/action_description.test.cpp @@ -20,7 +20,7 @@ TEST_CASE("From JSON", "[action_description]") { SECTION("Parse full action") { auto description = ActionDescription::FromJson("id", json); REQUIRE(description); - CHECK(description->ToJson() == json); + CHECK((*description)->ToJson() == json); } SECTION("Parse action without optional input") { -- cgit v1.2.3