90c177b7ce
GEM300 layer: SEMI E40-0705 Process Job and E94-0705 Control Job state machines, plus the E30 §6.1 communication-state machine that sits between HSMS SELECT and full GEM communication. Data-driven via data/process_job_state.yaml and data/control_job_state.yaml, mirroring the existing control_state.yaml pattern. Wire coverage: S14F9/F10 CreateObject (CJ) host -> equipment S14F11/F12 DeleteObject (CJ) host -> equipment S16F5/F6 PRJobCommand host -> equipment S16F9 PRJobAlert equipment -> host S16F11/F12 PRJobCreate (simplified body) host -> equipment S16F13/F14 PRJobDequeue host -> equipment S16F27/F28 CJobCommand host -> equipment Process Job FSM exposes 8 states matching PRJOBSTATE bytes (E40 §10.3.2); HOQ is reorder-aware (move-to-head against an insertion-order vector); Stop/Abort on a Queued PJ routes through ABORTING so the host observes PRJOBSTATE=7 on the wire (§6.3); alert_enabled is settable per-PJ for PRALERT control; FSM dispatches through ProcessJobStore::on_change_ dynamically so a late set_state_change_handler() reaches existing PJs. Hardening: loader rejects NoState (sentinel) as initial/from/to and rejects `on: created` rows; static_asserts pin enum values to wire bytes; ProcessJobStore is non-movable to keep the per-PJ this-capture safe. Server simulator cascades the full CJ -> PJ lifecycle on CJSTART so the wire trace exercises every legal state. CEIDs 400/401 fire on CJ state changes via the existing event-report pipeline. Tests: 60+ new assertions across test_process_jobs, test_control_jobs, test_communication_state, test_hsms_connection, plus loader and messages round-trip coverage. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
224 lines
8.3 KiB
C++
224 lines
8.3 KiB
C++
#include <doctest/doctest.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "secsgem/gem/process_job_state.hpp"
|
|
#include "secsgem/gem/store/process_jobs.hpp"
|
|
|
|
using namespace secsgem::gem;
|
|
|
|
namespace {
|
|
|
|
struct Recorder {
|
|
std::vector<std::tuple<ProcessJobState, ProcessJobState, ProcessJobEvent>> changes;
|
|
ProcessJobStateMachine::StateChangeHandler handler() {
|
|
return [this](ProcessJobState from, ProcessJobState to, ProcessJobEvent ev) {
|
|
changes.emplace_back(from, to, ev);
|
|
};
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
TEST_CASE("PJ default initial state is Queued") {
|
|
ProcessJobStateMachine pj;
|
|
CHECK(pj.state() == ProcessJobState::Queued);
|
|
}
|
|
|
|
TEST_CASE("PJ Queued -> SettingUp on Select (internal)") {
|
|
ProcessJobStateMachine pj;
|
|
Recorder rec;
|
|
pj.set_state_change_handler(rec.handler());
|
|
CHECK(pj.on_internal(ProcessJobEvent::Select));
|
|
CHECK(pj.state() == ProcessJobState::SettingUp);
|
|
REQUIRE(rec.changes.size() == 1);
|
|
CHECK(std::get<1>(rec.changes[0]) == ProcessJobState::SettingUp);
|
|
}
|
|
|
|
TEST_CASE("PJ full happy-path cascade") {
|
|
ProcessJobStateMachine pj;
|
|
CHECK(pj.on_internal(ProcessJobEvent::Select)); // -> SettingUp
|
|
CHECK(pj.on_internal(ProcessJobEvent::SetupComplete)); // -> WaitingForStart
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Start) == HostCmdAck::Accept);
|
|
CHECK(pj.state() == ProcessJobState::Processing);
|
|
CHECK(pj.on_internal(ProcessJobEvent::ProcessComplete));
|
|
CHECK(pj.state() == ProcessJobState::ProcessComplete);
|
|
}
|
|
|
|
TEST_CASE("PJ Start while Queued rejected (CannotDoNow)") {
|
|
ProcessJobStateMachine pj;
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Start) == HostCmdAck::CannotDoNow);
|
|
CHECK(pj.state() == ProcessJobState::Queued);
|
|
}
|
|
|
|
TEST_CASE("PJ Pause/Resume preserves Processing context") {
|
|
ProcessJobStateMachine pj;
|
|
pj.on_internal(ProcessJobEvent::Select);
|
|
pj.on_internal(ProcessJobEvent::SetupComplete);
|
|
pj.on_host_command(ProcessJobEvent::Start);
|
|
REQUIRE(pj.state() == ProcessJobState::Processing);
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Pause) == HostCmdAck::Accept);
|
|
CHECK(pj.state() == ProcessJobState::Paused);
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Resume) == HostCmdAck::Accept);
|
|
CHECK(pj.state() == ProcessJobState::Processing);
|
|
}
|
|
|
|
TEST_CASE("PJ Abort from any non-terminal state -> Aborting") {
|
|
// Includes Queued: per E40-0705 §6.3 a Queued PJ stops/aborts via the
|
|
// Aborting state (not direct-to-ProcessComplete), so the host sees a
|
|
// PRJOBSTATE=7 alert on the wire.
|
|
for (auto initial : {ProcessJobState::Queued, ProcessJobState::SettingUp,
|
|
ProcessJobState::WaitingForStart,
|
|
ProcessJobState::Processing, ProcessJobState::Paused,
|
|
ProcessJobState::Stopping}) {
|
|
ProcessJobStateMachine pj(ProcessJobTransitionTable::default_table(), initial);
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Abort) == HostCmdAck::Accept);
|
|
CHECK(pj.state() == ProcessJobState::Aborting);
|
|
CHECK(pj.on_internal(ProcessJobEvent::AbortComplete));
|
|
CHECK(pj.state() == ProcessJobState::ProcessComplete);
|
|
}
|
|
}
|
|
|
|
TEST_CASE("PJ Stop on Queued routes through Aborting") {
|
|
ProcessJobStateMachine pj;
|
|
REQUIRE(pj.state() == ProcessJobState::Queued);
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Stop) == HostCmdAck::Accept);
|
|
CHECK(pj.state() == ProcessJobState::Aborting);
|
|
CHECK(pj.on_internal(ProcessJobEvent::AbortComplete));
|
|
CHECK(pj.state() == ProcessJobState::ProcessComplete);
|
|
}
|
|
|
|
TEST_CASE("PJ HeadOfQueue is reorder-only — same state, ack Accept") {
|
|
ProcessJobStateMachine pj;
|
|
CHECK(pj.on_host_command(ProcessJobEvent::HeadOfQueue) == HostCmdAck::Accept);
|
|
CHECK(pj.state() == ProcessJobState::Queued);
|
|
}
|
|
|
|
TEST_CASE("PJ ProcessComplete is terminal — further commands rejected") {
|
|
ProcessJobStateMachine pj(ProcessJobTransitionTable::default_table(),
|
|
ProcessJobState::ProcessComplete);
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Start) == HostCmdAck::CannotDoNow);
|
|
CHECK(pj.on_host_command(ProcessJobEvent::Abort) == HostCmdAck::CannotDoNow);
|
|
CHECK(pj.state() == ProcessJobState::ProcessComplete);
|
|
}
|
|
|
|
TEST_CASE("PRCMD wire-name mapping") {
|
|
CHECK(pr_cmd_to_event("PJSTART").value() == ProcessJobEvent::Start);
|
|
CHECK(pr_cmd_to_event("PJSTOP").value() == ProcessJobEvent::Stop);
|
|
CHECK(pr_cmd_to_event("PAUSE").value() == ProcessJobEvent::Pause);
|
|
CHECK(pr_cmd_to_event("PJABORT").value() == ProcessJobEvent::Abort);
|
|
CHECK(pr_cmd_to_event("PJHOQ").value() == ProcessJobEvent::HeadOfQueue);
|
|
CHECK_FALSE(pr_cmd_to_event("DELETE").has_value());
|
|
}
|
|
|
|
TEST_CASE("Store: create rejects duplicate PRJOBID") {
|
|
ProcessJobStore store;
|
|
CHECK(store.create("PJ-1", "RECIPE", {"W1"}) ==
|
|
ProcessJobStore::CreateResult::Created);
|
|
CHECK(store.create("PJ-1", "RECIPE", {"W1"}) ==
|
|
ProcessJobStore::CreateResult::Denied_AlreadyExists);
|
|
}
|
|
|
|
TEST_CASE("Store: create rejects unknown PPID via validator") {
|
|
ProcessJobStore store;
|
|
auto known = [](const std::string& ppid) { return ppid == "RECIPE-A"; };
|
|
CHECK(store.create("PJ-1", "BAD", {}, known) ==
|
|
ProcessJobStore::CreateResult::Denied_InvalidPpid);
|
|
CHECK(store.create("PJ-1", "RECIPE-A", {}, known) ==
|
|
ProcessJobStore::CreateResult::Created);
|
|
}
|
|
|
|
TEST_CASE("Store: dequeue only legal while Queued") {
|
|
ProcessJobStore store;
|
|
store.create("PJ-1", "R", {});
|
|
CHECK(store.dequeue("PJ-1") == HostCmdAck::Accept);
|
|
CHECK(store.has("PJ-1") == false);
|
|
|
|
store.create("PJ-2", "R", {});
|
|
store.fire_internal("PJ-2", ProcessJobEvent::Select); // -> SettingUp
|
|
CHECK(store.dequeue("PJ-2") == HostCmdAck::CannotDoNow);
|
|
CHECK(store.has("PJ-2") == true);
|
|
}
|
|
|
|
TEST_CASE("Store: state-change handler observes synthetic create event") {
|
|
ProcessJobStore store;
|
|
std::vector<std::tuple<std::string, ProcessJobState, ProcessJobState>> log;
|
|
store.set_state_change_handler(
|
|
[&log](const std::string& id, ProcessJobState f, ProcessJobState t,
|
|
ProcessJobEvent) { log.emplace_back(id, f, t); });
|
|
store.create("PJ-1", "R", {});
|
|
REQUIRE(log.size() == 1);
|
|
CHECK(std::get<0>(log[0]) == "PJ-1");
|
|
CHECK(std::get<1>(log[0]) == ProcessJobState::NoState);
|
|
CHECK(std::get<2>(log[0]) == ProcessJobState::Queued);
|
|
}
|
|
|
|
TEST_CASE("Store: host command on unknown PJ returns InvalidObject") {
|
|
ProcessJobStore store;
|
|
CHECK(store.on_host_command("ghost", ProcessJobEvent::Start) ==
|
|
HostCmdAck::InvalidObject);
|
|
}
|
|
|
|
TEST_CASE("Store: ids() preserves insertion order") {
|
|
ProcessJobStore store;
|
|
store.create("PJ-B", "R", {});
|
|
store.create("PJ-A", "R", {});
|
|
store.create("PJ-C", "R", {});
|
|
REQUIRE(store.ids().size() == 3);
|
|
CHECK(store.ids()[0] == "PJ-B");
|
|
CHECK(store.ids()[1] == "PJ-A");
|
|
CHECK(store.ids()[2] == "PJ-C");
|
|
}
|
|
|
|
TEST_CASE("Store: HOQ moves Queued PJ to head of queue") {
|
|
ProcessJobStore store;
|
|
store.create("PJ-1", "R", {});
|
|
store.create("PJ-2", "R", {});
|
|
store.create("PJ-3", "R", {});
|
|
REQUIRE(store.position("PJ-3") == 2);
|
|
|
|
CHECK(store.on_host_command("PJ-3", ProcessJobEvent::HeadOfQueue) ==
|
|
HostCmdAck::Accept);
|
|
CHECK(store.position("PJ-3") == 0);
|
|
CHECK(store.position("PJ-1") == 1);
|
|
CHECK(store.position("PJ-2") == 2);
|
|
}
|
|
|
|
TEST_CASE("Store: HOQ on the head is a no-op Accept") {
|
|
ProcessJobStore store;
|
|
store.create("PJ-1", "R", {});
|
|
store.create("PJ-2", "R", {});
|
|
CHECK(store.on_host_command("PJ-1", ProcessJobEvent::HeadOfQueue) ==
|
|
HostCmdAck::Accept);
|
|
CHECK(store.position("PJ-1") == 0);
|
|
}
|
|
|
|
TEST_CASE("Store: HOQ rejected for non-Queued PJ") {
|
|
ProcessJobStore store;
|
|
store.create("PJ-1", "R", {});
|
|
store.create("PJ-2", "R", {});
|
|
store.fire_internal("PJ-2", ProcessJobEvent::Select); // -> SettingUp
|
|
CHECK(store.on_host_command("PJ-2", ProcessJobEvent::HeadOfQueue) ==
|
|
HostCmdAck::CannotDoNow);
|
|
CHECK(store.position("PJ-2") == 1); // order unchanged
|
|
}
|
|
|
|
TEST_CASE("Store: dequeue removes PJ from order vector") {
|
|
ProcessJobStore store;
|
|
store.create("PJ-1", "R", {});
|
|
store.create("PJ-2", "R", {});
|
|
CHECK(store.dequeue("PJ-1") == HostCmdAck::Accept);
|
|
REQUIRE(store.ids().size() == 1);
|
|
CHECK(store.ids()[0] == "PJ-2");
|
|
CHECK(store.position("PJ-1") == -1);
|
|
}
|
|
|
|
TEST_CASE("Store: set_alert toggles per-PJ alert flag") {
|
|
ProcessJobStore store;
|
|
store.create("PJ-1", "R", {});
|
|
REQUIRE(store.get("PJ-1")->alert_enabled);
|
|
CHECK(store.set_alert("PJ-1", false));
|
|
CHECK(store.get("PJ-1")->alert_enabled == false);
|
|
CHECK_FALSE(store.set_alert("ghost", false));
|
|
}
|