|
4 | 4 | * under the terms of the license (GNU LGPL) which comes with this package. */ |
5 | 5 |
|
6 | 6 | #include <cmath> |
| 7 | +#include <fstream> |
7 | 8 | #include <gtest/gtest.h> |
8 | 9 | #include <simgrid/host.h> |
9 | 10 | #include <simgrid/s4u/Actor.hpp> |
@@ -46,6 +47,48 @@ class DTLReductionTest : public ::testing::Test { |
46 | 47 | } |
47 | 48 | }; |
48 | 49 |
|
| 50 | +TEST_F(DTLReductionTest, BogusDecimationSetting) |
| 51 | +{ |
| 52 | + DO_TEST_WITH_FORK([this]() { |
| 53 | + this->setup_platform(); |
| 54 | + host_->add_actor("TestActor", [this]() { |
| 55 | + std::shared_ptr<dtlmod::ReductionMethod> decimator; |
| 56 | + XBT_INFO("Connect to the DTL"); |
| 57 | + auto dtl = dtlmod::DTL::connect(); |
| 58 | + XBT_INFO("Create a stream"); |
| 59 | + auto stream = dtl->add_stream("my-output"); |
| 60 | + stream->set_transport_method(dtlmod::Transport::Method::File); |
| 61 | + stream->set_engine_type(dtlmod::Engine::Type::File); |
| 62 | + stream->set_metadata_export(); |
| 63 | + XBT_INFO("Create a 3D variable"); |
| 64 | + auto var = stream->define_variable("var3D", {640, 640, 640}, {0, 0, 0}, {640, 640, 640}, sizeof(double)); |
| 65 | + XBT_INFO("Define a Decimation Reduction Method"); |
| 66 | + ASSERT_NO_THROW(decimator = stream->define_reduction_method("decimation")); |
| 67 | + XBT_INFO("Assign the decimation method to 'var3D' with a bogus option, should fail."); |
| 68 | + ASSERT_THROW(var->set_reduction_operation(decimator, {{"bogus", "-1"}}), |
| 69 | + dtlmod::UnknownDecimationOptionException); |
| 70 | + XBT_INFO("Assign the decimation method to 'var3D' with only a 2D stride, should fail"); |
| 71 | + ASSERT_THROW(var->set_reduction_operation(decimator, {{"stride", "1,2"}}), |
| 72 | + dtlmod::InconsistentDecimationStrideException); |
| 73 | + XBT_INFO("Assign the decimation method to 'var3D' with a negative stride value, should fail"); |
| 74 | + ASSERT_THROW(var->set_reduction_operation(decimator, {{"stride", "1,2,-1"}}), |
| 75 | + dtlmod::InconsistentDecimationStrideException); |
| 76 | + XBT_INFO("Assign the decimation method to 'var3D' with a stride value of 0, should fail"); |
| 77 | + ASSERT_THROW(var->set_reduction_operation(decimator, {{"stride", "1,0,1"}}), |
| 78 | + dtlmod::InconsistentDecimationStrideException); |
| 79 | + XBT_INFO("Assign the decimation method to 'var3D' with an unknown interpolation method, should fail"); |
| 80 | + ASSERT_THROW(var->set_reduction_operation(decimator, {{"stride", "1,2,4"}, {"interpolation", "bogus"}}), |
| 81 | + dtlmod::UnknownDecimationInterpolationException); |
| 82 | + |
| 83 | + XBT_INFO("Disconnect the actor from the DTL"); |
| 84 | + dtlmod::DTL::disconnect(); |
| 85 | + }); |
| 86 | + |
| 87 | + // Run the simulation |
| 88 | + ASSERT_NO_THROW(sg4::Engine::get_instance()->run()); |
| 89 | + }); |
| 90 | +} |
| 91 | + |
49 | 92 | TEST_F(DTLReductionTest, SimpleDecimationFileEngine) |
50 | 93 | { |
51 | 94 | DO_TEST_WITH_FORK([this]() { |
@@ -86,9 +129,54 @@ TEST_F(DTLReductionTest, SimpleDecimationFileEngine) |
86 | 129 | ASSERT_NO_THROW(engine->put(var)); |
87 | 130 | XBT_INFO("End a Transaction"); |
88 | 131 | engine->end_transaction(); |
| 132 | + XBT_INFO("Sleep until t = 8s"); |
| 133 | + sg4::this_actor::sleep_until(8); |
| 134 | + XBT_INFO("Triple the cost per element of the decimation method assigned to 'var3D'"); |
| 135 | + ASSERT_NO_THROW(var->set_reduction_operation(decimator, {{"cost_per_element", "3"}})); |
| 136 | + XBT_INFO("Start a Transaction"); |
| 137 | + engine->begin_transaction(); |
| 138 | + XBT_INFO("Put reduced Variable 'var' into the DTL"); |
| 139 | + ASSERT_NO_THROW(engine->put(var)); |
| 140 | + XBT_INFO("End a Transaction"); |
| 141 | + engine->end_transaction(); |
| 142 | + XBT_INFO("Sleep until t = 10s"); |
| 143 | + sg4::this_actor::sleep_until(10); |
| 144 | + XBT_INFO("Create a second 3D variable"); |
| 145 | + auto var2 = stream->define_variable("var3D_2", {640, 640, 640}, {0, 0, 0}, {640, 640, 640}, sizeof(double)); |
| 146 | + XBT_INFO("Assign the decimation method to 'var3D_2'"); |
| 147 | + ASSERT_NO_THROW(var2->set_reduction_operation(decimator, {{"stride", "2,2,2"}, {"interpolation", "quadratic"}})); |
| 148 | + XBT_INFO("Start a Transaction"); |
| 149 | + engine->begin_transaction(); |
| 150 | + XBT_INFO("Put reduced Variable 'var2' into the DTL"); |
| 151 | + ASSERT_NO_THROW(engine->put(var2)); |
| 152 | + XBT_INFO("End a Transaction"); |
| 153 | + engine->end_transaction(); |
89 | 154 | XBT_INFO("Close the engine"); |
90 | 155 | engine->close(); |
91 | | - |
| 156 | + |
| 157 | + XBT_INFO("Get the name of the metadata file"); |
| 158 | + auto metadata_file_name = engine->get_metadata_file_name(); |
| 159 | + XBT_INFO("Check the contents of '%s'", metadata_file_name.c_str()); |
| 160 | + std::ifstream file(metadata_file_name); |
| 161 | + ASSERT_TRUE(file.is_open()); |
| 162 | + std::string file_contents((std::istreambuf_iterator<char>(file)), std::istreambuf_iterator<char>()); |
| 163 | + |
| 164 | + file.close(); |
| 165 | + const std::string& expected_contents = |
| 166 | + "8\tvar3D_2\t1*{640,640,640}\n" |
| 167 | + " Transaction 4:\n" |
| 168 | + " /host/scratch/my-working-dir/my-output/data.0: [0:320, 0:320, 0:320]\n" |
| 169 | + "8\tvar3D\t3*{640,640,640}\n" |
| 170 | + " Transaction 1:\n" |
| 171 | + " /host/scratch/my-working-dir/my-output/data.0: [0:640, 0:640, 0:640]\n" |
| 172 | + " Transaction 2:\n" |
| 173 | + " /host/scratch/my-working-dir/my-output/data.0: [0:640, 0:320, 0:160]\n" |
| 174 | + " Transaction 3:\n" |
| 175 | + " /host/scratch/my-working-dir/my-output/data.0: [0:640, 0:320, 0:160]\n"; |
| 176 | + |
| 177 | + ASSERT_EQ(file_contents, expected_contents); |
| 178 | + std::remove(metadata_file_name.c_str()); |
| 179 | + |
92 | 180 | XBT_INFO("Disconnect the actor from the DTL"); |
93 | 181 | dtlmod::DTL::disconnect(); |
94 | 182 | }); |
|
0 commit comments