a28a8b5982
Each Substrate now retains an append-only history of state transitions (both location and processing axes), the triggering event captured as a std::variant<SubstrateEvent, SubstrateProcessingEvent>, the location label at the time, and a steady_clock timestamp. E90 §6.6 requires the equipment to be able to report a wafer's processing history — typically queried via S6F11 batched reports or SVID reads. This commit lays the runtime substrate; wire query plumbing is the natural follow-up. set_history_limit(n) caps per-substrate retention (default 256, 0 = unbounded). Oldest entries are dropped when the cap is reached; vector-erase is fine at this scale (typical wafer lifecycle is a few dozen transitions). Two new test cases cover the recording invariants (every fire results in one history entry on the right axis) and history_limit eviction. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
133 lines
5.4 KiB
C++
133 lines
5.4 KiB
C++
#include <doctest/doctest.h>
|
|
|
|
#include <vector>
|
|
|
|
#include "secsgem/gem/store/substrates.hpp"
|
|
#include "secsgem/gem/substrate_state.hpp"
|
|
|
|
using namespace secsgem::gem;
|
|
|
|
TEST_CASE("SubstrateStateMachine: initial AtSource / NeedsProcessing") {
|
|
SubstrateStateMachine s;
|
|
CHECK(s.location_state() == SubstrateState::AtSource);
|
|
CHECK(s.processing_state() == SubstrateProcessingState::NeedsProcessing);
|
|
}
|
|
|
|
TEST_CASE("Substrate location: AtSource -> AtWork -> AtDestination") {
|
|
SubstrateStateMachine s;
|
|
CHECK(s.on_location_event(SubstrateEvent::Acquire));
|
|
CHECK(s.location_state() == SubstrateState::AtWork);
|
|
CHECK(s.on_location_event(SubstrateEvent::Release));
|
|
CHECK(s.location_state() == SubstrateState::AtDestination);
|
|
}
|
|
|
|
TEST_CASE("Substrate location: Return from AtWork sends back to AtSource") {
|
|
SubstrateStateMachine s;
|
|
s.on_location_event(SubstrateEvent::Acquire);
|
|
CHECK(s.on_location_event(SubstrateEvent::Return));
|
|
CHECK(s.location_state() == SubstrateState::AtSource);
|
|
}
|
|
|
|
TEST_CASE("Substrate processing: happy path Start -> End -> Processed") {
|
|
SubstrateStateMachine s;
|
|
CHECK(s.on_processing_event(SubstrateProcessingEvent::StartProcessing));
|
|
CHECK(s.processing_state() == SubstrateProcessingState::InProcess);
|
|
CHECK(s.on_processing_event(SubstrateProcessingEvent::EndProcessing));
|
|
CHECK(s.processing_state() == SubstrateProcessingState::Processed);
|
|
}
|
|
|
|
TEST_CASE("Substrate processing: Abort/Stop/Reject/Lost are terminal") {
|
|
for (auto ev : {SubstrateProcessingEvent::Abort,
|
|
SubstrateProcessingEvent::Stop,
|
|
SubstrateProcessingEvent::Reject,
|
|
SubstrateProcessingEvent::ReportLost}) {
|
|
SubstrateStateMachine s;
|
|
s.on_processing_event(SubstrateProcessingEvent::StartProcessing);
|
|
CHECK(s.on_processing_event(ev));
|
|
// Terminal: no further transitions accepted.
|
|
CHECK_FALSE(s.on_processing_event(SubstrateProcessingEvent::EndProcessing));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("Substrate processing: Skip from NeedsProcessing") {
|
|
SubstrateStateMachine s;
|
|
CHECK(s.on_processing_event(SubstrateProcessingEvent::Skip));
|
|
CHECK(s.processing_state() == SubstrateProcessingState::Skipped);
|
|
}
|
|
|
|
// ---- SubstrateStore -----------------------------------------------------
|
|
|
|
TEST_CASE("SubstrateStore: create + dedup + location update") {
|
|
SubstrateStore s;
|
|
CHECK(s.create("W-001", "CAR-A", /*slot=*/1) ==
|
|
SubstrateStore::CreateResult::Created);
|
|
CHECK(s.create("W-001") == SubstrateStore::CreateResult::Denied_AlreadyExists);
|
|
REQUIRE(s.has("W-001"));
|
|
CHECK(s.get("W-001")->carrierid == "CAR-A");
|
|
CHECK(s.get("W-001")->slot == 1);
|
|
|
|
CHECK(s.fire_location_event("W-001", SubstrateEvent::Acquire, "MOD-A"));
|
|
CHECK(s.get("W-001")->location == "MOD-A");
|
|
CHECK(s.get("W-001")->fsm->location_state() == SubstrateState::AtWork);
|
|
}
|
|
|
|
TEST_CASE("SubstrateStore: history records every transition") {
|
|
SubstrateStore s;
|
|
s.create("W-H", "CAR-X", 3);
|
|
s.fire_location_event("W-H", SubstrateEvent::Acquire, "MOD-A");
|
|
s.fire_processing_event("W-H", SubstrateProcessingEvent::StartProcessing);
|
|
s.fire_processing_event("W-H", SubstrateProcessingEvent::EndProcessing);
|
|
s.fire_location_event("W-H", SubstrateEvent::Release, "DEST");
|
|
const auto* hist = s.history("W-H");
|
|
REQUIRE(hist != nullptr);
|
|
CHECK(hist->size() == 4);
|
|
// First entry is a location transition to AtWork.
|
|
CHECK((*hist)[0].location_to == SubstrateState::AtWork);
|
|
CHECK((*hist)[0].processing_to == SubstrateProcessingState::NoState);
|
|
CHECK((*hist)[0].location_label == "MOD-A");
|
|
// Third entry is a processing transition to Processed.
|
|
CHECK((*hist)[2].processing_to == SubstrateProcessingState::Processed);
|
|
CHECK((*hist)[2].location_to == SubstrateState::NoState);
|
|
}
|
|
|
|
TEST_CASE("SubstrateStore: history_limit caps retention") {
|
|
SubstrateStore s;
|
|
s.set_history_limit(3);
|
|
s.create("W-CAP");
|
|
// Generate more transitions than the cap.
|
|
s.fire_location_event("W-CAP", SubstrateEvent::Acquire);
|
|
s.fire_location_event("W-CAP", SubstrateEvent::Return);
|
|
s.fire_location_event("W-CAP", SubstrateEvent::Acquire);
|
|
s.fire_location_event("W-CAP", SubstrateEvent::Release);
|
|
const auto* hist = s.history("W-CAP");
|
|
REQUIRE(hist != nullptr);
|
|
CHECK(hist->size() == 3);
|
|
// Oldest entry (Acquire to AtWork) should be evicted; first remaining
|
|
// entry is the Return.
|
|
CHECK((*hist)[0].location_to == SubstrateState::AtSource);
|
|
}
|
|
|
|
TEST_CASE("SubstrateStore: change handlers observe both axes independently") {
|
|
SubstrateStore s;
|
|
std::vector<std::pair<std::string, SubstrateState>> loc_log;
|
|
std::vector<std::pair<std::string, SubstrateProcessingState>> proc_log;
|
|
s.set_location_handler([&](const std::string& id, SubstrateState,
|
|
SubstrateState to, SubstrateEvent) {
|
|
loc_log.emplace_back(id, to);
|
|
});
|
|
s.set_processing_handler([&](const std::string& id, SubstrateProcessingState,
|
|
SubstrateProcessingState to,
|
|
SubstrateProcessingEvent) {
|
|
proc_log.emplace_back(id, to);
|
|
});
|
|
s.create("W-X");
|
|
s.fire_location_event("W-X", SubstrateEvent::Acquire);
|
|
s.fire_processing_event("W-X", SubstrateProcessingEvent::StartProcessing);
|
|
s.fire_processing_event("W-X", SubstrateProcessingEvent::EndProcessing);
|
|
s.fire_location_event("W-X", SubstrateEvent::Release);
|
|
CHECK(loc_log.size() == 2);
|
|
CHECK(proc_log.size() == 2);
|
|
CHECK(loc_log.back().second == SubstrateState::AtDestination);
|
|
CHECK(proc_log.back().second == SubstrateProcessingState::Processed);
|
|
}
|