diff options
| author | MDBijman <matthijs@bijman.org> | 2017-01-24 12:15:26 +0100 |
|---|---|---|
| committer | MDBijman <matthijs@bijman.org> | 2017-01-24 12:15:26 +0100 |
| commit | 070ce923574dcc57435cb3fb2dfe86b6a38cd249 (patch) | |
| tree | ffd69a842ac4ad22aaf7161f923b9f0b47c7147a /Testing/include/simulation/workloads/SimpleSchedulerTest.h | |
Initial code commit with organized dependencies
Diffstat (limited to 'Testing/include/simulation/workloads/SimpleSchedulerTest.h')
| -rw-r--r-- | Testing/include/simulation/workloads/SimpleSchedulerTest.h | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/Testing/include/simulation/workloads/SimpleSchedulerTest.h b/Testing/include/simulation/workloads/SimpleSchedulerTest.h new file mode 100644 index 00000000..07b4416f --- /dev/null +++ b/Testing/include/simulation/workloads/SimpleSchedulerTest.h @@ -0,0 +1,106 @@ +#pragma once +#include "simulation\workloads\SimpleScheduler.h" +#include "simulation\workloads\Workload.h" +#include "modeling\Machine.h" + +#include <vector> +#include <gtest\gtest.h> + +TEST(SimpleSchedulerTest, ScheduleSingleMachine) +{ + // Initialization + Simulation::SimpleScheduler scheduler; + Simulation::Workload workload1(100, 0, 1, 1, 0); + Simulation::Workload workload2(150, 0, 1, 1, 0); + Modeling::Machine machine(10); + + std::vector<std::reference_wrapper<Modeling::Machine>> machines; + machines.push_back(std::reference_wrapper<Modeling::Machine>(machine)); + scheduler.addWorkload(workload1); + scheduler.addWorkload(workload2); + + // Distribute tasks across machines + scheduler.schedule(machines); + + // Do work + for (auto machine : machines) + machine.get().tick(); + + // Assert work done + auto workloads = scheduler.getWorkloads(); + auto workload1Remaining = workloads.at(0).lock()->getRemainingOperations(); + auto workload2Remaining = workloads.at(1).lock()->getRemainingOperations(); + ASSERT_EQ(workload1Remaining, 90); + ASSERT_EQ(workload2Remaining, 150); +} + +TEST(SimpleSchedulerTest, ScheduleMultipleMachine) +{ + // Initialization + Simulation::SimpleScheduler scheduler; + Simulation::Workload workload1(100, 0, 1, 1, 0); + Simulation::Workload workload2(150, 0, 1, 1, 0); + Modeling::Machine machine1(10); + Modeling::Machine machine2(30); + + std::vector<std::reference_wrapper<Modeling::Machine>> machines; + machines.push_back(std::reference_wrapper<Modeling::Machine>(machine1)); + machines.push_back(std::reference_wrapper<Modeling::Machine>(machine2)); + scheduler.addWorkload(workload1); + scheduler.addWorkload(workload2); + + // Distribute tasks across machines + scheduler.schedule(machines); + + // Do work + for (auto machine : machines) + machine.get().tick(); + + // Assert work done + auto workloads = scheduler.getWorkloads(); + auto workload1Remaining = workloads.at(0).lock()->getRemainingOperations(); + auto workload2Remaining = workloads.at(1).lock()->getRemainingOperations(); + ASSERT_EQ(workload1Remaining, 60); + ASSERT_EQ(workload2Remaining, 150); +} + +TEST(SimpleSchedulerTest, ScheduleFinishTask) +{ + // Initialization + Simulation::SimpleScheduler scheduler; + Simulation::Workload workload1(100, 0, 1, 1, 0); + Modeling::Machine machine1(100); + + std::vector<std::reference_wrapper<Modeling::Machine>> machines; + machines.push_back(std::reference_wrapper<Modeling::Machine>(machine1)); + scheduler.addWorkload(workload1); + ASSERT_TRUE(scheduler.hasWorkloads()); + + // Distribute tasks across machines + scheduler.schedule(machines); + + // Do work + for (auto machine : machines) + machine.get().tick(); + + // Distribute tasks across machines again, this is when finished workloads get cleared + scheduler.schedule(machines); + + // Assert work done + auto workloads = scheduler.getWorkloads(); + ASSERT_EQ(workloads.size(), 0); + ASSERT_FALSE(scheduler.hasWorkloads()); +} + +TEST(SimpleSchedulerTest, AddMultipleWorkloads) +{ + Simulation::SimpleScheduler ss; + std::vector<Simulation::Workload> workloads{ + Simulation::Workload(100, 0, 1, 1, 0), + Simulation::Workload(100, 0, 1, 1, 0) + }; + ss.addWorkloads(workloads); + + ASSERT_TRUE(ss.hasWorkloads()); + ASSERT_EQ(ss.getWorkloads().size(), 2); +}
\ No newline at end of file |
