SST 16.0.0
Structural Simulation Toolkit
coreTest_PortModule.h
1// Copyright 2009-2026 NTESS. Under the terms
2// of Contract DE-NA0003525 with NTESS, the U.S.
3// Government retains certain rights in this software.
4//
5// Copyright (c) 2009-2026, NTESS
6// All rights reserved.
7//
8// This file is part of the SST software package. For license
9// information, see the LICENSE file in the top level directory of the
10// distribution.
11
12#ifndef SST_CORE_CORETEST_PORTMODULE_H
13#define SST_CORE_CORETEST_PORTMODULE_H
14
15#include "sst/core/component.h"
16#include "sst/core/event.h"
17#include "sst/core/subcomponent.h"
18
19#include <cstdint>
20
21namespace SST::CoreTestPortModule {
22
24
25// Event passed between test components. The variable modified can
26// be set to true as a test of modifying events in PortModules.
27class PortModuleEvent : public Event
28{
29public:
30 bool modified = false;
31 bool last = false;
32
33 void serialize_order(SST::Core::Serialization::serializer& ser) override
34 {
35 Event::serialize_order(ser);
36 SST_SER(modified);
37 SST_SER(last);
38 }
39
40 ImplementSerializable(SST::CoreTestPortModule::PortModuleEvent);
41};
42
43// Event that is created by a PortModule to notify the receiving
44// component that the event was dropped
45class PortModuleAckEvent : public Event
46{
47public:
48 void serialize_order(SST::Core::Serialization::serializer& ser) override { Event::serialize_order(ser); }
49
51};
52
53
54class TestPortModule : public SST::PortModule
55{
56public:
57 SST_ELI_REGISTER_PORTMODULE(
58 TestPortModule,
59 "coreTestElement",
60 "portmodules.test",
61 SST_ELI_ELEMENT_VERSION(0, 1, 0),
62 "PortModule used for testing port module functionality")
63
64 SST_ELI_DOCUMENT_PARAMS(
65 { "modify", "Set to true to have PortModule mark event as modfied. NOTE: only 1 of modify, drop or replace can be set to true.", "false" },
66 { "drop", "Set to true to have PortModule drop events. NOTE: only 1 of modify, drop, or replace can be set to true.", "false" },
67 { "replace", "Set to true to have PortModule drop events and deliver an Ack event instead. NOTE: only 1 of modify, drop or replace can be set to true.", "false" },
68 { "install_on_send", "Controls whether the PortModule is installed on the send or receive side. Set to true to register on send and false to register on recieve.", "false" },
69 )
70
71 SST_ELI_DOCUMENT_STATISTICS(
72 { "events_intercepted", "How many events were intercepted by the module", "count", 4 },
73 { "not_enabled", "A statistic that isn't enabled in tests to ensure that stat level is respected", "none", 7 }
74 )
75
76 SST_ELI_IS_CHECKPOINTABLE()
77
78 explicit TestPortModule(Params& params);
79
80 // For serialization only
81 TestPortModule() = default;
82 ~TestPortModule() {}
83
84 void eventSent(uintptr_t key, Event*& ev) override;
85 void interceptHandler(uintptr_t key, Event*& data, bool& cancel) override;
86
87 bool installOnReceive() override { return !install_on_send_; }
88 bool installOnSend() override { return install_on_send_; }
89
90private:
91 bool install_on_send_ = false;
92 bool modify_ = false;
93 bool drop_ = false;
94 bool replace_ = false;
95
96 Statistic<uint64_t>* count_ = nullptr;
97 Statistic<uint64_t>* no_stat_ = nullptr;
98
99 void serialize_order(SST::Core::Serialization::serializer& ser) override
100 {
101 SST::PortModule::serialize_order(ser);
102 SST_SER(install_on_send_);
103 SST_SER(modify_);
104 SST_SER(drop_);
105 SST_SER(replace_);
106 SST_SER(count_);
107 SST_SER(no_stat_);
108 }
109 ImplementSerializable(SST::CoreTestPortModule::TestPortModule)
110};
111
112class coreTestPortModuleComponent : public SST::Component
113{
114public:
115 // REGISTER THIS COMPONENT INTO THE ELEMENT LIBRARY
116 SST_ELI_REGISTER_COMPONENT(
117 coreTestPortModuleComponent,
118 "coreTestElement",
119 "coreTestPortModuleComponent",
120 SST_ELI_ELEMENT_VERSION(1,0,0),
121 "Component to test PortModule functionality",
122 COMPONENT_CATEGORY_UNCATEGORIZED
123 )
124
125 SST_ELI_DOCUMENT_PORTS(
126 {"left", "Link to the left. Will only receive on left port. If nothing is attached to the left port, the component will send sendcount events.", { "" } },
127 {"right", "Link to the right. Will only send on right port. If nothing is connect to the right port, the component will check the types of the events recieved.", { "" } }
128 )
129
130 SST_ELI_DOCUMENT_PARAMS(
131 { "sendcount", "Events to send if send is set to true", "20"},
132 { "use_subcomponent", "Set to true to use a subcomponent to hook up the ports", "false"},
133 { "repeat_last", "When set to true, will keep sending \"last\" events until the simulation terminates. This is to support test of the RandomDropPortModule which doesn't check event types or values so will not automatically pass through the event marked last.", "false" },
134 )
135
136 SST_ELI_DOCUMENT_STATISTICS(
137 { "handle_modified_event", "How many modified events were handled", "events", 1 },
138 { "handle_ack_event", "How many ack events were handled", "events", 1 },
139 { "handle_unmodified_event", "How many unmodified events were handled", "events", 1 },
140 )
141
142 // Optional since there is nothing to document
143 SST_ELI_DOCUMENT_SUBCOMPONENT_SLOTS(
144 {"port_slot", "Slot for loading subcomponent to test shared ports", "" }
145 )
146
147 SST_ELI_IS_CHECKPOINTABLE()
148
149 coreTestPortModuleComponent(SST::ComponentId_t id, SST::Params& params);
150
151 void serialize_order(SST::Core::Serialization::serializer& ser) override
152 {
153 SST::Component::serialize_order(ser);
154 SST_SER(sendcount_);
155 SST_SER(sub_);
156 SST_SER(repeat_last_);
157 SST_SER(left_);
158 SST_SER(right_);
159 SST_SER(stat_mod_event_);
160 SST_SER(stat_unmod_event_);
161 SST_SER(stat_ack_event_);
162 }
164
165private:
166 int sendcount_ = 20;
167 bool repeat_last_ = false;
168
169 Statistic<uint32_t>* stat_mod_event_;
170 Statistic<uint32_t>* stat_ack_event_;
171 Statistic<uint32_t>* stat_unmod_event_;
172
173 Link* left_;
174 Link* right_;
175
176 PortSubComponent* sub_ = nullptr;
177
178 coreTestPortModuleComponent() = default; // for serialization only
179 coreTestPortModuleComponent(const coreTestPortModuleComponent&) = delete; // do not implement
180 coreTestPortModuleComponent& operator=(const coreTestPortModuleComponent&) = delete; // do not implement
181
182 bool tick(SST::Cycle_t);
183 void handleEvent(SST::Event* ev);
184 void handleEventLast(SST::Event* ev);
185};
186
187class PortSubComponent : public SST::SubComponent
188{
189public:
190 SST_ELI_REGISTER_SUBCOMPONENT_API(SST::CoreTestPortModule::PortSubComponent)
191
192 SST_ELI_REGISTER_SUBCOMPONENT(
193 PortSubComponent,
194 "coreTestElement",
195 "PortSubComponent",
196 SST_ELI_ELEMENT_VERSION(1,0,0),
197 "Subcomponent used to test putting PortModules on shared ports",
199 )
200
201 SST_ELI_IS_CHECKPOINTABLE()
202
203 PortSubComponent(ComponentId_t id, Params& params);
204 PortSubComponent() = default; // For serialization
205 ~PortSubComponent() {}
206
207 Link* getLeft() { return left_; }
208 Link* getRight() { return right_; }
209
210private:
211 Link* left_;
212 Link* right_;
213
214 void dummy_handler(SST::Event* UNUSED(ev)) {}
215
216 void serialize_order(SST::Core::Serialization::serializer& ser) override
217 {
218 SST::SubComponent::serialize_order(ser);
219 SST_SER(left_);
220 SST_SER(right_);
221 }
222 ImplementSerializable(SST::CoreTestPortModule::PortSubComponent)
223};
224
225} // namespace SST::CoreTestPortModule
226
227#endif // SST_CORE_CORETEST_PORTMODULE_H
Main component object for the simulation.
Definition component.h:32
Definition coreTest_PortModule.h:46
Definition coreTest_PortModule.h:28
Definition coreTest_PortModule.h:188
Definition coreTest_PortModule.h:55
void eventSent(uintptr_t key, Event *&ev) override
Function that will be called when an event is sent on a link with registered PortModules.
Definition coreTest_PortModule.cc:48
bool installOnSend() override
Called to determine if the PortModule should be installed on sends.
Definition coreTest_PortModule.h:88
void interceptHandler(uintptr_t key, Event *&data, bool &cancel) override
Function that will be called before the event handler to let the attach point intercept the data.
Definition coreTest_PortModule.cc:82
bool installOnReceive() override
Called to determine if the PortModule should be installed on receives.
Definition coreTest_PortModule.h:87
Definition coreTest_PortModule.h:113
This class is basically a wrapper for objects to declare the order in which their members should be s...
Definition serializer.h:43
Base class for Events - Items sent across links to communicate between components.
Definition event.h:41
Parameter store.
Definition params.h:65
PortModules are modules that can be attached to the send and/or receive side of ports.
Definition portModule.h:54
Forms the template defined base class for statistics gathering within SST.
Definition statbase.h:369
SubComponent is a class loadable through the factory which allows dynamic functionality to be added t...
Definition subcomponent.h:29