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 arg.b =
static_cast<int8_t
>(-17);
90 arg.inner.q =
static_cast<int8_t
>(-7);
95 const auto *res = resMsg.
as<esi_system::OddStruct>();
97 uint16_t expectA =
static_cast<uint16_t
>(arg.a + 1);
98 int8_t expectB =
static_cast<int8_t
>(arg.b - 3);
99 uint8_t expectP =
static_cast<uint8_t
>(arg.inner.p + 5);
100 int8_t expectQ =
static_cast<int8_t
>(arg.inner.q + 2);
101 uint8_t expectR0 =
static_cast<uint8_t
>(arg.inner.r[0] + 1);
102 uint8_t expectR1 =
static_cast<uint8_t
>(arg.inner.r[1] + 2);
103 if (res->a != expectA || res->b != expectB || res->inner.p != expectP ||
104 res->inner.q != expectQ || res->inner.r[0] != expectR0 ||
105 res->inner.r[1] != expectR1)
106 throw std::runtime_error(
"Odd struct func result mismatch");
108 std::cout <<
"odd_struct_func ok: a=" << res->a <<
" b=" << (int)res->b
109 <<
" p=" << (
int)res->inner.p <<
" q=" << (int)res->inner.q
110 <<
" r0=" << (
int)res->inner.r[0] <<
" r1=" << (int)res->inner.r[1]
119 throw std::runtime_error(
"No arrayFunc port found");
123 throw std::runtime_error(
"arrayFunc not a FuncService::Function");
126 int8_t argArray[1] = {
static_cast<int8_t
>(-3)};
128 func->call(
MessageData(
reinterpret_cast<const uint8_t *
>(argArray),
132 const auto *res = resMsg.
as<esi_system::ResultArray>();
133 int8_t a = (*res)[0];
134 int8_t b = (*res)[1];
135 int8_t expect0 = argArray[0];
136 int8_t expect1 =
static_cast<int8_t
>(argArray[0] + 1);
138 bool ok = (a == expect0 && b == expect1) || (a == expect1 && b == expect0);
140 throw std::runtime_error(
"Array func result mismatch");
149 std::cout <<
"array_func ok: " << (int)low <<
" " << (
int)high <<
"\n";
184 std::vector<SerialCoordData>
coords;
189 std::vector<SerialCoordData> &
coords)
200 return {
reinterpret_cast<const uint8_t *
>(&
header),
sizeof(
header)};
202 return {
reinterpret_cast<const uint8_t *
>(
coords.data()),
205 return {
reinterpret_cast<const uint8_t *
>(&
footer),
sizeof(
footer)};
207 throw std::out_of_range(
"SerialCoordInput: invalid segment index");
228 size_t numCoords = 100;
229 uint32_t xTrans = 10, yTrans = 20;
232 std::mt19937 rng(0xDEADBEEF);
233 std::uniform_int_distribution<uint32_t> dist(0, 1000000);
234 std::vector<Coord> inputCoords;
235 inputCoords.reserve(numCoords);
236 for (uint32_t i = 0; i < numCoords; ++i)
237 inputCoords.push_back({dist(rng), dist(rng)});
241 throw std::runtime_error(
"Serial coord translate test: no "
242 "'coord_translator_serial' child found");
244 auto &ports = child->second->getPorts();
245 auto portIter = ports.find(
AppID(
"translate_coords_serial"));
246 if (portIter == ports.end())
247 throw std::runtime_error(
248 "Serial coord translate test: no 'translate_coords_serial' port found");
252 throw std::runtime_error(
253 "Serial coord translate test: port is not a FuncService::Function");
261 func->getRawWrite(
"arg"));
273 std::vector<SerialCoordData> coords;
274 for (
auto &c : inputCoords)
275 coords.emplace_back(c.x, c.y);
277 argPort.
write(batch);
283 for (
size_t i = 0; i < numCoords + 2; ++i)
284 rawResult.
read(drained);
285 std::cout <<
"serial_coord_translate ok\n";
290 std::cout <<
"depth: 0x" << std::hex << esi_system::LoopbackIP::depth
292 std::cout <<
"depth_constant ok\n";
297 "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