Skip to content

Commit

Permalink
Test code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Nov 2, 2024
1 parent 67a653a commit 4eb3f33
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 73 deletions.
7 changes: 3 additions & 4 deletions test/energy_consumption/EnergyConsumptionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include <wrench/simgrid_S4U_util/S4U_CommPort.h>
#include <wrench/simulation/SimulationMessage.h>
#include <gtest/gtest.h>
#include <wrench/services/compute/batch/BatchComputeService.h>
#include <wrench/services/compute/batch/BatchComputeServiceMessage.h>
#include <algorithm>
#include <simgrid/plugins/energy.h>
Expand Down Expand Up @@ -780,7 +779,7 @@ class EnergyConsumptionPStateChangeTestWMS : public wrench::ExecutionController

double after_current_energy_consumed_by_host1 = this->getSimulation()->getEnergyConsumed(simulation_hosts[1]);
double energy_consumed_while_running_with_higher_speed = after_current_energy_consumed_by_host1 - before_current_energy_consumed_by_host1;
double higher_speed_compuation_time = wrench::S4U_Simulation::getClock();
double higher_speed_computation_time = wrench::S4U_Simulation::getClock();


if (energy_consumed_while_running_with_higher_speed <= 0) {
Expand All @@ -804,7 +803,7 @@ class EnergyConsumptionPStateChangeTestWMS : public wrench::ExecutionController

double after_current_energy_consumed_by_host2 = this->getSimulation()->getEnergyConsumed(simulation_hosts[1]);
double energy_consumed_while_running_with_lower_speed = after_current_energy_consumed_by_host2 - before_current_energy_consumed_by_host2;
double lower_speed_computation_time = wrench::S4U_Simulation::getClock() - higher_speed_compuation_time;
double lower_speed_computation_time = wrench::S4U_Simulation::getClock() - higher_speed_computation_time;

if (energy_consumed_while_running_with_lower_speed <= 0) {
throw std::runtime_error("Unexpectedly the energy consumed is less than 0 for a lower speed ??");
Expand All @@ -820,7 +819,7 @@ class EnergyConsumptionPStateChangeTestWMS : public wrench::ExecutionController
double exact_max_wattage_power_1 = wrench::Simulation::getMaxPowerConsumption(simulation_hosts[1]);
double exact_max_wattage_power_2 = wrench::Simulation::getMaxPowerConsumption(simulation_hosts[1]);
double EPSILON = 1.0;
double computed_wattage_power_1 = energy_consumed_while_running_with_higher_speed / higher_speed_compuation_time;
double computed_wattage_power_1 = energy_consumed_while_running_with_higher_speed / higher_speed_computation_time;
double computed_wattage_power_2 = energy_consumed_while_running_with_lower_speed / lower_speed_computation_time;

if (std::abs(exact_max_wattage_power_1 - computed_wattage_power_1) > EPSILON && std::abs(exact_max_wattage_power_2 - computed_wattage_power_2) > EPSILON) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* (at your option) any later version.
*/

#include <math.h>
#include <gtest/gtest.h>
#include <wrench-dev.h>

Expand Down Expand Up @@ -62,7 +61,7 @@ class BareMetalComputeServiceOneTaskTest : public ::testing::Test {


protected:
~BareMetalComputeServiceOneTaskTest() {
~BareMetalComputeServiceOneTaskTest() override {
workflow->clear();
wrench::Simulation::removeAllFiles();
}
Expand Down Expand Up @@ -654,14 +653,14 @@ void BareMetalComputeServiceOneTaskTest::do_StandardJobConstructor_test() {

class HostMemoryTestWMS : public wrench::ExecutionController {
public:
HostMemoryTestWMS(BareMetalComputeServiceOneTaskTest *test, std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
HostMemoryTestWMS(BareMetalComputeServiceOneTaskTest *test, const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
BareMetalComputeServiceOneTaskTest *test;

int main() override {
double ram_capacity;
sg_size_t ram_capacity;

ram_capacity = wrench::Simulation::getHostMemoryCapacity("TwoCoreHost");
if (ram_capacity != wrench::S4U_Simulation::DEFAULT_RAM) {
Expand All @@ -677,7 +676,7 @@ class HostMemoryTestWMS : public wrench::ExecutionController {
if (ram_capacity == wrench::S4U_Simulation::DEFAULT_RAM) {
throw std::runtime_error("RAM Capacity of RAMHost should not be the default");
}
if (std::abs(ram_capacity - 1024) > 0.01) {
if (ram_capacity != 1024) {
throw std::runtime_error("RAM Capacity of RAMHost should be 1024");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* (at your option) any later version.
*/

#include <math.h>

#include <gtest/gtest.h>
#include <wrench-dev.h>

Expand All @@ -32,7 +30,7 @@ class BareMetalComputeServiceTestResourceInformation : public ::testing::Test {
void do_ResourceInformation_test();

protected:
~BareMetalComputeServiceTestResourceInformation() {
~BareMetalComputeServiceTestResourceInformation() override {
workflow->clear();
wrench::Simulation::removeAllFiles();
}
Expand Down Expand Up @@ -81,7 +79,7 @@ class ResourceInformationTestWMS : public wrench::ExecutionController {

public:
ResourceInformationTestWMS(BareMetalComputeServiceTestResourceInformation *test,
std::string hostname) : wrench::ExecutionController(hostname, "test") {
const std::string& hostname) : wrench::ExecutionController(hostname, "test") {
this->test = test;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
* (at your option) any later version.
*/

#include <math.h>

#include <gtest/gtest.h>
#include <wrench-dev.h>

Expand Down Expand Up @@ -36,7 +34,7 @@ class BareMetalComputeServiceTestPilotJobs : public ::testing::Test {
void do_UnsupportedPilotJobs_test();

protected:
~BareMetalComputeServiceTestPilotJobs() {
~BareMetalComputeServiceTestPilotJobs() override {
workflow->clear();
wrench::Simulation::removeAllFiles();
}
Expand Down Expand Up @@ -90,7 +88,7 @@ class BareMetalComputeServiceUnsupportedPilotJobsTestWMS : public wrench::Execut

public:
BareMetalComputeServiceUnsupportedPilotJobsTestWMS(BareMetalComputeServiceTestPilotJobs *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,23 @@ class SimpleStorageServiceFunctionalTest : public ::testing::Test {

std::shared_ptr<wrench::ComputeService> compute_service = nullptr;

void do_BasicFunctionality_test(double buffer_size);
void do_BasicFunctionality_test(sg_size_t buffer_size);

void do_WrongService_test(double buffer_size);
void do_SynchronousFileCopy_test(sg_size_t buffer_size);

void do_SynchronousFileCopy_test(double buffer_size);
void do_AsynchronousFileCopy_test(sg_size_t buffer_size);

void do_AsynchronousFileCopy_test(double buffer_size);
void do_SynchronousFileCopyFailures_test(sg_size_t buffer_size);

void do_SynchronousFileCopyFailures_test(double buffer_size);
void do_AsynchronousFileCopyFailures_test(sg_size_t buffer_size);

void do_AsynchronousFileCopyFailures_test(double buffer_size);
void do_Partitions_test(sg_size_t buffer_size);

void do_Partitions_test(double buffer_size);

void do_FileWrite_test(double buffer_size);
void do_FileWrite_test(sg_size_t buffer_size);


protected:
~SimpleStorageServiceFunctionalTest() {
~SimpleStorageServiceFunctionalTest() override {
workflow->clear();
wrench::Simulation::removeAllFiles();
}
Expand Down Expand Up @@ -115,7 +113,7 @@ class SimpleStorageServiceBasicFunctionalityTestWMS : public wrench::ExecutionCo

public:
SimpleStorageServiceBasicFunctionalityTestWMS(SimpleStorageServiceFunctionalTest *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down Expand Up @@ -239,14 +237,14 @@ class SimpleStorageServiceBasicFunctionalityTestWMS : public wrench::ExecutionCo


// Send a free space request
double free_space;
sg_size_t free_space;
try {
free_space = this->test->storage_service_100->getTotalFreeSpace();
} catch (wrench::ExecutionException &e) {
throw std::runtime_error("Should be able to get a storage's service free space");
}

if (free_space != 90.0) {
if (free_space != 90) {
throw std::runtime_error(
"Free space on storage service is wrong (" + std::to_string(free_space) + ") instead of 90.0");
}
Expand All @@ -257,7 +255,7 @@ class SimpleStorageServiceBasicFunctionalityTestWMS : public wrench::ExecutionCo
} catch (wrench::ExecutionException &e) {
throw std::runtime_error("Should be able to get a storage's service free space at a path");
}
if (free_space != 90.0) {
if (free_space != 90) {
throw std::runtime_error(
"Free space on storage service is wrong (" + std::to_string(free_space) + ") instead of 90.0");
}
Expand All @@ -268,7 +266,7 @@ class SimpleStorageServiceBasicFunctionalityTestWMS : public wrench::ExecutionCo
} catch (wrench::ExecutionException &e) {
throw std::runtime_error("Should be able to get a storage's service free space at a path");
}
if (free_space != 90.0) {
if (free_space != 90) {
throw std::runtime_error(
"Free space on storage service is wrong (" + std::to_string(free_space) + ") instead of 90.0");
}
Expand All @@ -279,7 +277,7 @@ class SimpleStorageServiceBasicFunctionalityTestWMS : public wrench::ExecutionCo
} catch (wrench::ExecutionException &ignore) {
throw std::runtime_error("Should be able to get a storage's service free space, even at a bogus path");
}
if (free_space != 0.0) {
if (free_space != 0) {
throw std::runtime_error(
"Free space on storage service at a bogus path should be 0.0 (" + std::to_string(free_space) + ")");
}
Expand Down Expand Up @@ -404,7 +402,7 @@ class SimpleStorageServiceBasicFunctionalityTestWMS : public wrench::ExecutionCo
throw std::runtime_error("Should be able to get a storage's service free space");
}

if (free_space != 100.0) {
if (free_space != 100) {
throw std::runtime_error(
"Free space on storage service is wrong (" + std::to_string(free_space) + ") instead of 100.0");
}
Expand Down Expand Up @@ -470,7 +468,7 @@ class SimpleStorageServiceBasicFunctionalityTestWMS : public wrench::ExecutionCo
} catch (wrench::ExecutionException &e) {
throw std::runtime_error("Should be able to get a storage's service free space");
}
if (free_space != 99.0) {
if (free_space != 99) {
throw std::runtime_error(
"Free space on storage service is wrong (" + std::to_string(free_space) + ") instead of 99.0");
}
Expand Down Expand Up @@ -646,7 +644,7 @@ TEST_F(SimpleStorageServiceFunctionalTest, BasicFunctionality) {
DO_TEST_WITH_FORK_ONE_ARG(do_BasicFunctionality_test, 0);
}

void SimpleStorageServiceFunctionalTest::do_BasicFunctionality_test(double buffer_size) {
void SimpleStorageServiceFunctionalTest::do_BasicFunctionality_test(sg_size_t buffer_size) {

// Create and initialize a simulation
auto simulation = wrench::Simulation::createSimulation();
Expand Down Expand Up @@ -785,13 +783,13 @@ class SimpleStorageServiceSynchronousFileCopyTestWMS : public wrench::ExecutionC
throw std::runtime_error("Should not be able to do a file copy with a bogus path");
} catch (wrench::ExecutionException &e) {
auto cause = e.getCause();
if (auto real_cause = std::dynamic_pointer_cast<wrench::InvalidDirectoryPath>(e.getCause())) {
real_cause->toString(); // Coverage
real_cause->getLocation();// Coverage
} else if (auto real_cause = std::dynamic_pointer_cast<wrench::FileNotFound>(e.getCause())) {
real_cause->toString(); // Coverage
real_cause->getFile(); // Coverage
real_cause->getLocation();// Coverage
if (auto real_cause_1 = std::dynamic_pointer_cast<wrench::InvalidDirectoryPath>(e.getCause())) {
real_cause_1->toString(); // Coverage
real_cause_1->getLocation();// Coverage
} else if (auto real_cause_2 = std::dynamic_pointer_cast<wrench::FileNotFound>(e.getCause())) {
real_cause_2->toString(); // Coverage
real_cause_2->getFile(); // Coverage
real_cause_2->getLocation();// Coverage
} else {
throw std::runtime_error("Got the expected exception, but the failure cause is not InvalidDirectoryPath or FileNotFound (it's " + cause->toString() + ")");
}
Expand Down Expand Up @@ -833,7 +831,7 @@ TEST_F(SimpleStorageServiceFunctionalTest, SynchronousFileCopy) {
DO_TEST_WITH_FORK_ONE_ARG(do_SynchronousFileCopy_test, 0);
}

void SimpleStorageServiceFunctionalTest::do_SynchronousFileCopy_test(double buffer_size) {
void SimpleStorageServiceFunctionalTest::do_SynchronousFileCopy_test(sg_size_t buffer_size) {

// Create and initialize a simulation
auto simulation = wrench::Simulation::createSimulation();
Expand Down Expand Up @@ -899,7 +897,7 @@ class SimpleStorageServiceAsynchronousFileCopyTestWMS : public wrench::Execution

public:
SimpleStorageServiceAsynchronousFileCopyTestWMS(SimpleStorageServiceFunctionalTest *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down Expand Up @@ -979,7 +977,7 @@ TEST_F(SimpleStorageServiceFunctionalTest, AsynchronousFileCopy) {
DO_TEST_WITH_FORK_ONE_ARG(do_AsynchronousFileCopy_test, 0);
}

void SimpleStorageServiceFunctionalTest::do_AsynchronousFileCopy_test(double buffer_size) {
void SimpleStorageServiceFunctionalTest::do_AsynchronousFileCopy_test(sg_size_t buffer_size) {

// Create and initialize a simulation
auto simulation = wrench::Simulation::createSimulation();
Expand Down Expand Up @@ -1044,7 +1042,7 @@ class SimpleStorageServiceSynchronousFileCopyFailuresTestWMS : public wrench::Ex

public:
SimpleStorageServiceSynchronousFileCopyFailuresTestWMS(SimpleStorageServiceFunctionalTest *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down Expand Up @@ -1176,7 +1174,7 @@ TEST_F(SimpleStorageServiceFunctionalTest, SynchronousFileCopyFailures) {
DO_TEST_WITH_FORK_ONE_ARG(do_SynchronousFileCopyFailures_test, 0);
}

void SimpleStorageServiceFunctionalTest::do_SynchronousFileCopyFailures_test(double buffer_size) {
void SimpleStorageServiceFunctionalTest::do_SynchronousFileCopyFailures_test(sg_size_t buffer_size) {

// Create and initialize a simulation
auto simulation = wrench::Simulation::createSimulation();
Expand Down Expand Up @@ -1247,7 +1245,7 @@ class SimpleStorageServiceAsynchronousFileCopyFailuresTestWMS : public wrench::E

public:
SimpleStorageServiceAsynchronousFileCopyFailuresTestWMS(SimpleStorageServiceFunctionalTest *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down Expand Up @@ -1383,7 +1381,7 @@ TEST_F(SimpleStorageServiceFunctionalTest, AsynchronousFileCopyFailures) {
DO_TEST_WITH_FORK_ONE_ARG(do_AsynchronousFileCopyFailures_test, 0);
}

void SimpleStorageServiceFunctionalTest::do_AsynchronousFileCopyFailures_test(double buffer_size) {
void SimpleStorageServiceFunctionalTest::do_AsynchronousFileCopyFailures_test(sg_size_t buffer_size) {

// Create and initialize a simulation
auto simulation = wrench::Simulation::createSimulation();
Expand Down Expand Up @@ -1450,7 +1448,7 @@ class PartitionsTestWMS : public wrench::ExecutionController {

public:
PartitionsTestWMS(SimpleStorageServiceFunctionalTest *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down Expand Up @@ -1643,7 +1641,7 @@ TEST_F(SimpleStorageServiceFunctionalTest, Partitions) {
DO_TEST_WITH_FORK_ONE_ARG(do_Partitions_test, 0);
}

void SimpleStorageServiceFunctionalTest::do_Partitions_test(double buffer_size) {
void SimpleStorageServiceFunctionalTest::do_Partitions_test(sg_size_t buffer_size) {

// Create and initialize a simulation
auto simulation = wrench::Simulation::createSimulation();
Expand Down Expand Up @@ -1701,7 +1699,7 @@ class FileWriteTestWMS : public wrench::ExecutionController {

public:
FileWriteTestWMS(SimpleStorageServiceFunctionalTest *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down Expand Up @@ -1748,7 +1746,7 @@ TEST_F(SimpleStorageServiceFunctionalTest, FileWrite) {
DO_TEST_WITH_FORK_ONE_ARG(do_FileWrite_test, 0);
}

void SimpleStorageServiceFunctionalTest::do_FileWrite_test(double buffer_size) {
void SimpleStorageServiceFunctionalTest::do_FileWrite_test(sg_size_t buffer_size) {

// Create and initialize a simulation
auto simulation = wrench::Simulation::createSimulation();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class SimpleStorageServiceWrongServiceTest : public ::testing::Test {


protected:
~SimpleStorageServiceWrongServiceTest() {
~SimpleStorageServiceWrongServiceTest() override {
workflow->clear();
wrench::Simulation::removeAllFiles();
}
Expand Down Expand Up @@ -83,7 +83,7 @@ class SimpleStorageServiceWrongServiceTestWMS : public wrench::ExecutionControll

public:
SimpleStorageServiceWrongServiceTestWMS(SimpleStorageServiceWrongServiceTest *test,
std::string hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
const std::string& hostname) : wrench::ExecutionController(hostname, "test"), test(test) {
}

private:
Expand Down Expand Up @@ -147,9 +147,7 @@ void SimpleStorageServiceWrongServiceTest::do_WrongService_test(double buffer_si
{{wrench::SimpleStorageServiceProperty::BUFFER_SIZE, std::to_string(buffer_size)}}, {})));

// Create a WMS
std::shared_ptr<wrench::ExecutionController> wms = nullptr;
ASSERT_NO_THROW(wms = simulation->add(
new SimpleStorageServiceWrongServiceTestWMS(this, hostname)));
ASSERT_NO_THROW(simulation->add(new SimpleStorageServiceWrongServiceTestWMS(this, hostname)));

// Staging all files on the 1000 storage service
ASSERT_NO_THROW(storage_service_1->createFile(file_1));
Expand Down
Loading

0 comments on commit 4eb3f33

Please sign in to comment.