Skip to content

Commit

Permalink
Testing++
Browse files Browse the repository at this point in the history
  • Loading branch information
henricasanova committed Aug 12, 2019
1 parent a50935d commit a9bcf17
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/wrench/simgrid_S4U_util/S4U_Daemon.cpp
Expand Up @@ -165,7 +165,7 @@ namespace wrench {
this->s4u_actor = simgrid::s4u::Actor::create(this->process_name.c_str(),
simgrid::s4u::Host::by_name(hostname),
S4U_DaemonActor(this));
} catch (std::exception &e) {
} catch (simgrid::Exception &e) {
throw std::runtime_error("S4U_Daemon::startDaemon(): SimGrid actor creation failed... shouldn't happen.");
}

Expand Down
84 changes: 80 additions & 4 deletions test/simulation/S4U_DaemonTest.cpp
Expand Up @@ -20,6 +20,7 @@ class S4U_DaemonTest : public ::testing::Test {
public:

void do_basic_Test();
void do_noCleanup_Test();

protected:
S4U_DaemonTest() {
Expand Down Expand Up @@ -68,10 +69,6 @@ class S4U_DaemonTest : public ::testing::Test {

};

/**********************************************************************/
/** BASIC TEST **/
/**********************************************************************/

class Sleep100Daemon : public wrench::S4U_Daemon {

public:
Expand All @@ -85,6 +82,11 @@ class Sleep100Daemon : public wrench::S4U_Daemon {

};

/**********************************************************************/
/** BASIC TEST **/
/**********************************************************************/


class S4U_DaemonTestWMS : public wrench::WMS {

public:
Expand Down Expand Up @@ -197,3 +199,77 @@ void S4U_DaemonTest::do_basic_Test() {
}


/**********************************************************************/
/** NO CLEANUP TEST **/
/**********************************************************************/



class S4U_DaemonNoCleanupTestWMS : public wrench::WMS {

public:
S4U_DaemonNoCleanupTestWMS(S4U_DaemonTest *test,
std::string hostname) :
wrench::WMS(nullptr, nullptr, {}, {}, {}, nullptr, hostname, "test") {
this->test = test;
}

private:

S4U_DaemonTest *test;

int main() {

std::shared_ptr<Sleep100Daemon> daemon =
std::shared_ptr<Sleep100Daemon>(new Sleep100Daemon("Host2"));

daemon->createLifeSaver(std::shared_ptr<Sleep100Daemon>(daemon));
daemon->simulation = this->simulation;
daemon->startDaemon(false, false);

// sleep 10 seconds
wrench::Simulation::sleep(10);

// Turn off Host2
wrench::Simulation::turnOffHost("Host2");

return 0;
}
};

TEST_F(S4U_DaemonTest, NoCleanup) {
DO_TEST_WITH_FORK_EXPECT_FATAL_FAILURE(do_noCleanup_Test, true);
}

void S4U_DaemonTest::do_noCleanup_Test() {

// Create and initialize a simulation
auto simulation = new wrench::Simulation();
int argc = 1;
char **argv = (char **) calloc(1, sizeof(char *));
argv[0] = strdup("file_registry_test");

simulation->init(&argc, argv);

// Setting up the platform
ASSERT_NO_THROW(simulation->instantiatePlatform(platform_file_path));

// Get a hostname
std::string hostname = "Host1";

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

ASSERT_NO_THROW(wms->addWorkflow(workflow));

// Running a "run a single task" simulation
ASSERT_NO_THROW(simulation->launch());

delete simulation;

free(argv[0]);
free(argv);
}

2 changes: 1 addition & 1 deletion test/workflow/WorkflowTaskTest.cpp
Expand Up @@ -206,7 +206,7 @@ TEST_F(WorkflowTaskTest, InputOutputFile) {

ASSERT_THROW(t1->addInputFile(f2), std::invalid_argument);
ASSERT_THROW(t1->addOutputFile(f1), std::invalid_argument);

ASSERT_THROW(workflow->removeFile(f1), std::invalid_argument);
ASSERT_THROW(workflow->removeFile(f2), std::invalid_argument);

Expand Down

0 comments on commit a9bcf17

Please sign in to comment.