1#include "loopback/LoopbackIP.h"
20 {
AppID(
"loopback_inst", 0),
AppID(
"loopback_tohw")}, lastLookup);
22 throw std::runtime_error(
"No loopback_tohw port found");
24 {
AppID(
"loopback_inst", 0),
AppID(
"loopback_fromhw")}, lastLookup);
26 throw std::runtime_error(
"No loopback_fromhw port found");
33 uint8_t sendVal = 0x5a;
38 if (recvMsg.
getSize() !=
sizeof(uint8_t))
39 throw std::runtime_error(
"Unexpected loopback recv size");
40 uint8_t got = *recvMsg.
as<uint8_t>();
42 throw std::runtime_error(
"Loopback byte mismatch");
44 std::cout <<
"loopback_i8 ok: 0x" << std::hex << (int)got << std::dec <<
"\n";
52 throw std::runtime_error(
"No structFunc port found");
56 throw std::runtime_error(
"structFunc not a FuncService::Function");
59 esi_system::ArgStruct arg{};
61 arg.b(
static_cast<int8_t
>(-7));
64 const auto *res = resMsg.
as<esi_system::ResultStruct>();
66 int8_t expectedX =
static_cast<int8_t
>(arg.b() + 1);
67 if (res->x() != expectedX || res->y() != arg.b())
68 throw std::runtime_error(
"Struct func result mismatch");
70 std::cout <<
"struct_func ok: b=" << (int)arg.b() <<
" x=" << (int)res->x()
71 <<
" y=" << (int)res->y() <<
"\n";
79 throw std::runtime_error(
"No oddStructFunc port found");
83 throw std::runtime_error(
"oddStructFunc not a FuncService::Function");
86 esi_system::OddStruct arg{
88 static_cast<int8_t
>(-17),
89 {5,
static_cast<int8_t
>(-7), {3, 4}},
93 const auto *res = resMsg.
as<esi_system::OddStruct>();
95 uint16_t expectA =
static_cast<uint16_t
>(arg.a() + 1);
96 int8_t expectB =
static_cast<int8_t
>(arg.b() - 3);
97 uint8_t expectP =
static_cast<uint8_t
>(arg.inner().p() + 5);
98 int8_t expectQ =
static_cast<int8_t
>(arg.inner().q() + 2);
99 uint8_t expectR0 =
static_cast<uint8_t
>(arg.inner().r()[0] + 1);
100 uint8_t expectR1 =
static_cast<uint8_t
>(arg.inner().r()[1] + 2);
101 if (res->a() != expectA || res->b() != expectB ||
102 res->inner().p() != expectP || res->inner().q() != expectQ ||
103 res->inner().r()[0] != expectR0 || res->inner().r()[1] != expectR1)
104 throw std::runtime_error(
"Odd struct func result mismatch");
106 std::cout <<
"odd_struct_func ok: a=" << res->a() <<
" b=" << (int)res->b()
107 <<
" p=" << (int)res->inner().p() <<
" q=" << (int)res->inner().q()
108 <<
" r0=" << (int)res->inner().r()[0]
109 <<
" r1=" << (int)res->inner().r()[1] <<
"\n";
117 throw std::runtime_error(
"No arrayFunc port found");
121 throw std::runtime_error(
"arrayFunc not a FuncService::Function");
124 int8_t argArray[1] = {
static_cast<int8_t
>(-3)};
126 func->call(
MessageData(
reinterpret_cast<const uint8_t *
>(argArray),
130 const auto *res = resMsg.
as<esi_system::ResultArray>();
131 int8_t a = (*res)[0];
132 int8_t b = (*res)[1];
133 int8_t expect0 = argArray[0];
134 int8_t expect1 =
static_cast<int8_t
>(argArray[0] + 1);
136 bool ok = (a == expect0 && b == expect1) || (a == expect1 && b == expect0);
138 throw std::runtime_error(
"Array func result mismatch");
147 std::cout <<
"array_func ok: " << (int)low <<
" " << (
int)high <<
"\n";
182 std::vector<SerialCoordData>
coords;
187 std::vector<SerialCoordData> &
coords)
198 return {
reinterpret_cast<const uint8_t *
>(&
header),
sizeof(
header)};
200 return {
reinterpret_cast<const uint8_t *
>(
coords.data()),
203 return {
reinterpret_cast<const uint8_t *
>(&
footer),
sizeof(
footer)};
205 throw std::out_of_range(
"SerialCoordInput: invalid segment index");
226 size_t numCoords = 100;
227 uint32_t xTrans = 10, yTrans = 20;
230 std::mt19937 rng(0xDEADBEEF);
231 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
232 std::vector<Coord> inputCoords;
233 inputCoords.reserve(numCoords);
234 for (uint32_t i = 0; i < numCoords; ++i)
235 inputCoords.push_back({dist(rng), dist(rng)});
239 throw std::runtime_error(
"Serial coord translate test: no "
240 "'coord_translator_serial' child found");
242 auto &ports = child->second->getPorts();
243 auto portIter = ports.find(
AppID(
"translate_coords_serial"));
244 if (portIter == ports.end())
245 throw std::runtime_error(
246 "Serial coord translate test: no 'translate_coords_serial' port found");
250 throw std::runtime_error(
251 "Serial coord translate test: port is not a FuncService::Function");
259 func->getRawWrite(
"arg"));
271 std::vector<SerialCoordData> coords;
272 for (
auto &c : inputCoords)
273 coords.emplace_back(c.x, c.y);
275 argPort.
write(batch);
281 for (
size_t i = 0; i < numCoords + 2; ++i)
282 rawResult.
read(drained);
283 std::cout <<
"serial_coord_translate ok\n";
288 std::cout <<
"depth: 0x" << std::hex << esi_system::LoopbackIP::depth
290 std::cout <<
"depth_constant ok\n";
295 "Loopback cosim test using generated ESI headers.",
Top level accelerator class.
Services provide connections to 'bundles' – collections of named, unidirectional communication channe...
T * getAs() const
Cast this Bundle port to a subclass which is actually useful.
ReadChannelPort & getRawRead(const std::string &name) const
WriteChannelPort & getRawWrite(const std::string &name) const
Get access to the raw byte streams of a channel.
BundlePort * resolvePort(const AppIDPath &path, AppIDPath &lastLookup) const
Attempt to resolve a path to a port.
const std::map< AppID, Instance * > & getChildren() const
Access the module's children by ID.
A concrete flat message backed by a single vector of bytes.
const T * as() const
Cast to a type.
size_t getSize() const
Get the size of the data in bytes.
static MessageData from(T &t)
Cast from a type to its raw bytes.
A ChannelPort which reads data from the accelerator.
virtual void connect(ReadCallback callback, const ConnectOptions &options={})
virtual void read(MessageData &outData)
Specify a buffer to read into.
Abstract multi-segment message.
void connect(const ChannelPort::ConnectOptions &opts={std::nullopt, false})
void write(const T &data)
A ChannelPort which sends data to the accelerator.
void write(const MessageData &data)
A very basic blocking write API.
virtual void connect(const ConnectOptions &options={}) override
Set up a connection to the accelerator.
A function call which gets attached to a service port.
static int serialCoordTranslateTest(Accelerator *accel)
static int runDepthConstant(Accelerator *)
static int runArrayFunc(Accelerator *accel)
static int runOddStructFunc(Accelerator *accel)
static int runStructFunc(Accelerator *accel)
static int runLoopbackI8(Accelerator *accel)
#define ESI_PROBE_REGISTRY(name, description,...)
Convenience macro: defines main() with a probe registry.
Test the CoordTranslator module using message translation.
SerialCoordData(uint32_t x, uint32_t y)
A contiguous, non-owning view of bytes within a SegmentedMessageData.
SerialCoordOutputData data
SerialCoordOutputHeader header