1#include "loopback/LoopbackIP.h"
18 {
AppID(
"loopback_inst", 0),
AppID(
"loopback_tohw")}, lastLookup);
20 throw std::runtime_error(
"No loopback_tohw port found");
22 {
AppID(
"loopback_inst", 0),
AppID(
"loopback_fromhw")}, lastLookup);
24 throw std::runtime_error(
"No loopback_fromhw port found");
32 uint8_t sendVal = 0x5a;
35 uint8_t got = fromHw.
read();
37 throw std::runtime_error(
"Loopback byte mismatch");
39 std::cout <<
"loopback i8 ok: 0x" << std::hex << (int)got << std::dec <<
"\n";
46 throw std::runtime_error(
"No structFunc port found");
53 esi_system::ArgStruct arg{};
55 arg.b =
static_cast<int8_t
>(-7);
57 esi_system::ResultStruct res = func.
call(arg).get();
59 int8_t expectedX =
static_cast<int8_t
>(arg.b + 1);
60 if (res.x != expectedX || res.y != arg.b)
61 throw std::runtime_error(
"Struct func result mismatch");
63 std::cout <<
"struct func ok: b=" << (int)arg.b <<
" x=" << (
int)res.x
64 <<
" y=" << (int)res.y <<
"\n";
71 throw std::runtime_error(
"No oddStructFunc port found");
78 esi_system::OddStruct arg{};
80 arg.b =
static_cast<int8_t
>(-17);
82 arg.inner.q =
static_cast<int8_t
>(-7);
86 esi_system::OddStruct res = func.
call(arg).get();
88 uint16_t expectA =
static_cast<uint16_t
>(arg.a + 1);
89 int8_t expectB =
static_cast<int8_t
>(arg.b - 3);
90 uint8_t expectP =
static_cast<uint8_t
>(arg.inner.p + 5);
91 int8_t expectQ =
static_cast<int8_t
>(arg.inner.q + 2);
92 uint8_t expectR0 =
static_cast<uint8_t
>(arg.inner.r[0] + 1);
93 uint8_t expectR1 =
static_cast<uint8_t
>(arg.inner.r[1] + 2);
94 if (res.a != expectA || res.b != expectB || res.inner.p != expectP ||
95 res.inner.q != expectQ || res.inner.r[0] != expectR0 ||
96 res.inner.r[1] != expectR1)
97 throw std::runtime_error(
"Odd struct func result mismatch");
99 std::cout <<
"odd struct func ok: a=" << res.a <<
" b=" << (int)res.b
100 <<
" p=" << (
int)res.inner.p <<
" q=" << (int)res.inner.q
101 <<
" r0=" << (
int)res.inner.r[0] <<
" r1=" << (int)res.inner.r[1]
109 throw std::runtime_error(
"No arrayFunc port found");
113 throw std::runtime_error(
"arrayFunc not a FuncService::Function");
116 int8_t argArray[1] = {
static_cast<int8_t
>(-3)};
118 func->call(
MessageData(
reinterpret_cast<const uint8_t *
>(argArray),
122 const auto *res = resMsg.
as<esi_system::ResultArray>();
123 int8_t a = (*res)[0];
124 int8_t b = (*res)[1];
125 int8_t expect0 = argArray[0];
126 int8_t expect1 =
static_cast<int8_t
>(argArray[0] + 1);
128 bool ok = (a == expect0 && b == expect1) || (a == expect1 && b == expect0);
130 throw std::runtime_error(
"Array func result mismatch");
139 std::cout <<
"array func ok: " << (int)low <<
" " << (
int)high <<
"\n";
146 throw std::runtime_error(
"No sint4Func port found");
156 int8_t posResult = func.
call(posArg).get();
157 if (posResult != posArg)
158 throw std::runtime_error(
"sint4 loopback positive mismatch: got " +
159 std::to_string(posResult));
163 int8_t negResult = func.
call(negArg).get();
164 if (negResult != negArg)
165 throw std::runtime_error(
"sint4 loopback negative mismatch: got " +
166 std::to_string(negResult));
168 std::cout <<
"sint4 loopback ok: pos=" << (int)posResult
169 <<
" neg=" << (
int)negResult <<
"\n";
172int main(
int argc,
const char *argv[]) {
175 "Loopback cosim test using generated ESI headers and typed ports.");
176 if (
int rc = cli.
esiParse(argc, argv))
178 if (!cli.get_help_ptr()->empty())
185 Manifest manifest(ctxt, info.getJsonManifest());
186 Accelerator *accel = manifest.buildAccelerator(*conn);
187 conn->getServiceThread()->addPoll(*accel);
189 std::cout <<
"depth: 0x" << std::hex << esi_system::LoopbackIP::depth
199 }
catch (std::exception &e) {
Abstract class representing a connection to an accelerator.
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.
Common options and code for ESI runtime tools.
Context & getContext()
Get the context.
AcceleratorConnection * connect()
Connect to the accelerator using the specified backend and connection.
int esiParse(int argc, const char **argv)
Run the parser.
AcceleratorConnections, Accelerators, and Manifests must all share a context.
BundlePort * resolvePort(const AppIDPath &path, AppIDPath &lastLookup) const
Attempt to resolve a path to a port.
virtual void error(const std::string &subsystem, const std::string &msg, const std::map< std::string, std::any > *details=nullptr)
Report an error.
Class to parse a manifest.
A logical chunk of data representing serialized data.
const T * as() const
Cast to a type.
std::future< ResultT > call(const ArgT &arg)
void connect(const ChannelPort::ConnectOptions &opts={})
void connect(const ChannelPort::ConnectOptions &opts={})
void write(const T &data)
A function call which gets attached to a service port.
Information about the Accelerator system.
static void runOddStructFunc(Accelerator *accel)
int main(int argc, const char *argv[])
static void runLoopbackI8(Accelerator *accel)
static void runStructFunc(Accelerator *accel)
static void runArrayFunc(Accelerator *accel)
static void runSInt4Loopback(Accelerator *accel)