Skip to content

Commit

Permalink
Test cases compile again
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanwbrei committed Oct 28, 2023
1 parent 326b09e commit d1f9517
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 76 deletions.
3 changes: 3 additions & 0 deletions src/libraries/JANA/Engine/JArrowProcessingController.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class JArrowProcessingController : public JProcessingController {
void print_report() override;
void print_final_report() override;

// This is so we can test
inline JScheduler* get_scheduler() { return m_scheduler; }


private:

Expand Down
74 changes: 37 additions & 37 deletions src/programs/tests/ArrowActivationTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,9 @@


JArrowMetrics::Status steppe(JArrow* arrow) {
if (arrow->get_type() != JArrow::NodeType::Source &&
arrow->get_status() == JArrow::Status::Running &&
arrow->get_pending() == 0 &&
arrow->get_running_upstreams() == 0) {

arrow->finish();
return JArrowMetrics::Status::Finished;
}

JArrowMetrics metrics;
arrow->execute(metrics, 0);
return metrics.get_last_status();
arrow->execute(metrics, 0);
return metrics.get_last_status();
}

TEST_CASE("ArrowActivationTests") {
Expand All @@ -33,7 +24,6 @@ TEST_CASE("ArrowActivationTests") {
SumSink<double> sink;

auto topology = std::make_shared<JArrowTopology>();
JScheduler scheduler(topology);

auto q1 = new JMailbox<int>();
auto q2 = new JMailbox<double>();
Expand All @@ -57,6 +47,7 @@ TEST_CASE("ArrowActivationTests") {
topology->sinks.push_back(sum_everything);

emit_rand_ints->set_chunksize(1);
JScheduler scheduler(topology);

auto logger = JLogger(JLogger::Level::OFF);
topology->m_logger = logger;
Expand All @@ -69,10 +60,12 @@ TEST_CASE("ArrowActivationTests") {
REQUIRE(q2->size() == 0);
REQUIRE(q3->size() == 0);

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Unopened);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Unopened);
REQUIRE(subtract_one->get_status() == JArrow::Status::Unopened);
REQUIRE(sum_everything->get_status() == JArrow::Status::Unopened);
JScheduler::TopologyState state = scheduler.get_topology_state();

REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[1].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[2].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[3].status == JScheduler::ArrowStatus::Uninitialized);

REQUIRE(emit_rand_ints->get_pending() == 0);
REQUIRE(multiply_by_two->get_pending() == 0);
Expand All @@ -82,18 +75,21 @@ TEST_CASE("ArrowActivationTests") {

SECTION("As a message propagates, arrows and queues downstream automatically activate") {

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Unopened);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Unopened);
REQUIRE(subtract_one->get_status() == JArrow::Status::Unopened);
REQUIRE(sum_everything->get_status() == JArrow::Status::Unopened);
JScheduler::TopologyState state = scheduler.get_topology_state();

REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[1].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[2].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[3].status == JScheduler::ArrowStatus::Uninitialized);

scheduler.run_topology(1);
state = scheduler.get_topology_state();
// TODO: Check that initialize has been called, but not finalize

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Running);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Running);
REQUIRE(subtract_one->get_status() == JArrow::Status::Running);
REQUIRE(sum_everything->get_status() == JArrow::Status::Running);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[1].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[2].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[3].status == JScheduler::ArrowStatus::Active);
}

} // TEST_CASE
Expand All @@ -109,7 +105,6 @@ TEST_CASE("ActivableDeactivationTests") {
SumSink<double> sink;

auto topology = std::make_shared<JArrowTopology>();
JScheduler scheduler(topology);

auto q1 = new JMailbox<int>();
auto q2 = new JMailbox<double>();
Expand All @@ -135,24 +130,29 @@ TEST_CASE("ActivableDeactivationTests") {
topology->m_logger = logger;
source.logger = logger;

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Unopened);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Unopened);
REQUIRE(subtract_one->get_status() == JArrow::Status::Unopened);
REQUIRE(sum_everything->get_status() == JArrow::Status::Unopened);
JScheduler scheduler(topology);
JScheduler::TopologyState state = scheduler.get_topology_state();

REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Uninitialized);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Uninitialized);

scheduler.run_topology(1);
state = scheduler.get_topology_state();

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Running);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Running);
REQUIRE(subtract_one->get_status() == JArrow::Status::Running);
REQUIRE(sum_everything->get_status() == JArrow::Status::Running);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);

steppe(emit_rand_ints);
state = scheduler.get_topology_state();

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Finished);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Running);
REQUIRE(subtract_one->get_status() == JArrow::Status::Running);
REQUIRE(sum_everything->get_status() == JArrow::Status::Running);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Active);

// TODO: Test that finalize was called exactly once
} // TEST_CASE
Expand Down
12 changes: 7 additions & 5 deletions src/programs/tests/SchedulerTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ TEST_CASE("SchedulerTests") {
SumSink<double> sink;

auto topology = std::make_shared<JArrowTopology>();
JScheduler scheduler(topology);

auto q1 = new JMailbox<int>();
auto q2 = new JMailbox<double>();
Expand All @@ -40,6 +39,8 @@ TEST_CASE("SchedulerTests") {
topology->sinks.push_back(sum_everything);

emit_rand_ints->set_chunksize(1);

JScheduler scheduler(topology);
scheduler.run_topology(1);

JArrow* assignment;
Expand All @@ -62,10 +63,11 @@ TEST_CASE("SchedulerTests") {
}
} while (assignment != nullptr);

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Finished);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Paused);
REQUIRE(subtract_one->get_status() == JArrow::Status::Paused);
REQUIRE(sum_everything->get_status() == JArrow::Status::Paused);
JScheduler::TopologyState state = scheduler.get_topology_state();
REQUIRE(state.arrow_states[0].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(state.arrow_states[1].status == JScheduler::ArrowStatus::Inactive);
REQUIRE(state.arrow_states[2].status == JScheduler::ArrowStatus::Inactive);
REQUIRE(state.arrow_states[3].status == JScheduler::ArrowStatus::Inactive);
}

SECTION("When run sequentially, topology finished => RRS returns nullptr") {
Expand Down
67 changes: 33 additions & 34 deletions src/programs/tests/TopologyTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "catch.hpp"
#include "JANA/Engine/JTopologyBuilder.h"
#include <JANA/Engine/JArrowProcessingController.h>

#include <TestTopologyComponents.h>
#include <JANA/Utils/JPerfUtils.h>
Expand All @@ -13,15 +14,6 @@

JArrowMetrics::Status step(JArrow* arrow) {

if (arrow->get_type() != JArrow::NodeType::Source &&
arrow->get_status() == JArrow::Status::Running &&
arrow->get_pending() == 0 &&
arrow->get_running_upstreams() == 0) {

arrow->finish();
return JArrowMetrics::Status::Finished;
}

JArrowMetrics metrics;
arrow->execute(metrics, 0);
auto status = metrics.get_last_status();
Expand All @@ -42,7 +34,6 @@ TEST_CASE("JTopology: Basic functionality") {
SumSink<double> sink;

auto topology = std::make_shared<JArrowTopology>();
JScheduler scheduler(topology);

auto q1 = new JMailbox<int>();
auto q2 = new JMailbox<double>();
Expand All @@ -69,14 +60,15 @@ TEST_CASE("JTopology: Basic functionality") {
auto logger = JLogger(JLogger::Level::TRACE);
topology->m_logger = logger;
source.logger = logger;
JScheduler scheduler(topology);


SECTION("Before anything runs...") {

// All queues are empty, none are finished
REQUIRE(multiply_by_two->get_pending() == 0);
REQUIRE(subtract_one->get_pending() == 0);
REQUIRE(sum_everything->get_pending() == 0);
REQUIRE(subtract_one->get_pending() == 0);
}

SECTION("When nothing is in the input queue...") {
Expand Down Expand Up @@ -201,47 +193,52 @@ TEST_CASE("JTopology: Basic functionality") {
source.logger = logger;

scheduler.run_topology(1);
auto ts = scheduler.get_topology_state();

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Running);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Running);
REQUIRE(subtract_one->get_status() == JArrow::Status::Running);
REQUIRE(sum_everything->get_status() == JArrow::Status::Running);
REQUIRE(ts.arrow_states[0].status == JScheduler::ArrowStatus::Active);
REQUIRE(ts.arrow_states[1].status == JScheduler::ArrowStatus::Active);
REQUIRE(ts.arrow_states[2].status == JScheduler::ArrowStatus::Active);
REQUIRE(ts.arrow_states[3].status == JScheduler::ArrowStatus::Active);

for (int i = 0; i < 20; ++i) {
step(emit_rand_ints);
}
ts = scheduler.get_topology_state();

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Finished);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Running);
REQUIRE(subtract_one->get_status() == JArrow::Status::Running);
REQUIRE(sum_everything->get_status() == JArrow::Status::Running);
REQUIRE(ts.arrow_states[0].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[1].status == JScheduler::ArrowStatus::Active);
REQUIRE(ts.arrow_states[2].status == JScheduler::ArrowStatus::Active);
REQUIRE(ts.arrow_states[3].status == JScheduler::ArrowStatus::Active);

for (int i = 0; i < 20; ++i) {
step(multiply_by_two);
}
ts = scheduler.get_topology_state();

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Finished);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Finished);
REQUIRE(subtract_one->get_status() == JArrow::Status::Running);
REQUIRE(sum_everything->get_status() == JArrow::Status::Running);
REQUIRE(ts.arrow_states[0].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[1].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[2].status == JScheduler::ArrowStatus::Active);
REQUIRE(ts.arrow_states[3].status == JScheduler::ArrowStatus::Active);

for (int i = 0; i < 20; ++i) {
step(subtract_one);
}
ts = scheduler.get_topology_state();

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Finished);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Finished);
REQUIRE(subtract_one->get_status() == JArrow::Status::Finished);
REQUIRE(sum_everything->get_status() == JArrow::Status::Running);
REQUIRE(ts.arrow_states[0].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[1].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[2].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[3].status == JScheduler::ArrowStatus::Active);

for (int i = 0; i < 20; ++i) {
step(sum_everything);
}
ts = scheduler.get_topology_state();

REQUIRE(emit_rand_ints->get_status() == JArrow::Status::Finished);
REQUIRE(multiply_by_two->get_status() == JArrow::Status::Finished);
REQUIRE(subtract_one->get_status() == JArrow::Status::Finished);
REQUIRE(sum_everything->get_status() == JArrow::Status::Finished);
REQUIRE(ts.arrow_states[0].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[1].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[2].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(ts.arrow_states[3].status == JScheduler::ArrowStatus::Finalized);

log_status(*topology);

Expand All @@ -255,10 +252,12 @@ TEST_CASE("JTopology: Basic functionality") {
REQUIRE(sink.sum == 0);

app.Run(true);
auto scheduler = app.GetService<JArrowProcessingController>()->get_scheduler();


// TODO: Access the JScheduler managed by JApplication
// REQUIRE(scheduler.get_topology_status() == JScheduler::TopologyStatus::Finalized);
REQUIRE(sum_everything->get_status() == JArrow::Status::Finished);
auto ts = scheduler->get_topology_state();
REQUIRE(ts.current_topology_status == JScheduler::TopologyStatus::Finalized);
REQUIRE(ts.arrow_states[0].status == JScheduler::ArrowStatus::Finalized);
REQUIRE(sink.sum == 20 * 13);

}
Expand Down

0 comments on commit d1f9517

Please sign in to comment.