8#include "serialization_probes/BitPackProbe.h"
9#include "serialization_probes/ByteRotate1.h"
10#include "serialization_probes/PackProbe.h"
11#include "serialization_probes/SignProbe.h"
12#include "serialization_probes/SignProbe13.h"
37 throw std::runtime_error(std::string(
"probe instance '") + appidName +
38 "' not found in accelerator hierarchy");
45static constexpr std::array<uint8_t, 8>
kBytePattern = {0x12, 0x34, 0x56, 0x78,
46 0x9A, 0xBC, 0xDE, 0xF0};
49 esi_system::ByteRotate1 mod(
findProbe(accel,
"byte_rotate1_inst"));
50 auto connected = mod.connect();
52 uint64_t arg = 0x0102030405060708ULL;
53 uint64_t expect = 0x0203040506070801ULL;
54 uint64_t got = connected->byte_rotate1(arg).get();
56 throw std::runtime_error(
"byte_rotate1 mismatch: got 0x" +
toHex(got) +
57 " expected 0x" +
toHex(expect));
58 std::cout <<
"byte_rotate1 ok: 0x" << std::hex << got << std::dec <<
"\n";
66 const char *portName) {
69 throw std::runtime_error(std::string(
"port '") + portName +
70 "' not found on probe instance");
73 throw std::runtime_error(std::string(
"port '") + portName +
74 "' is not a FuncService::Function");
82 "byte_pattern_const");
89 throw std::runtime_error(
"byte_pattern_const: wrong response size (got " +
90 std::to_string(resMsg.
getSize()) +
", expected " +
92 const uint8_t *got = resMsg.
getBytes();
96 ss <<
"byte_pattern_const: wire byte " << i <<
" mismatch (got 0x"
97 << std::hex << static_cast<unsigned>(got[i]) <<
" expected 0x"
99 throw std::runtime_error(ss.str());
102 std::cout <<
"byte_pattern_const ok\n";
110 "byte_pattern_echo_eq");
116 throw std::runtime_error(
"byte_pattern_echo_eq: wrong response size (got " +
117 std::to_string(resMsg.
getSize()) +
121 throw std::runtime_error(
122 "byte_pattern_echo_eq: hardware reported byte mismatch (got " +
123 std::to_string(got) +
")");
124 std::cout <<
"byte_pattern_echo_eq ok\n";
129 esi_system::SignProbe mod(
findProbe(accel,
"sign_probe_inst"));
130 auto connected = mod.connect();
144 {INT16_MAX,
static_cast<int16_t
>(INT16_MIN), -INT16_MAX, 0},
147 {INT16_MIN,
static_cast<int16_t
>(INT16_MIN + 1),
148 static_cast<int16_t
>(INT16_MIN), 1},
150 for (
const Case &c : cases) {
151 esi_system::SignResult r = connected->sign_probe(c.arg).get();
152 if (r.plus_one != c.plus_one || r.neg != c.neg || r.sign_bit != c.sign_bit)
153 throw std::runtime_error(
"sign_probe mismatch for arg=" +
154 std::to_string(c.arg));
156 std::cout <<
"sign_probe ok\n";
161 esi_system::SignProbe13 mod(
findProbe(accel,
"sign_probe13_inst"));
162 auto connected = mod.connect();
169 static constexpr int16_t kMin = -4096;
170 static constexpr int16_t kMax = 4095;
181 {kMax, kMin,
static_cast<int16_t
>(-kMax), 0},
184 {kMin,
static_cast<int16_t
>(kMin + 1), kMin, 1},
186 for (
const Case &c : cases) {
187 esi_system::SignResult13 r = connected->sign_probe13(c.arg).get();
188 if (r.plus_one != c.plus_one || r.neg != c.neg || r.sign_bit != c.sign_bit)
189 throw std::runtime_error(
190 "sign_probe13 mismatch for arg=" + std::to_string(c.arg) +
191 " got plus_one=" + std::to_string(r.plus_one) +
" neg=" +
192 std::to_string(r.neg) +
" sign_bit=" + std::to_string(r.sign_bit));
216 std::cout <<
"sign_probe13 ok\n";
221 esi_system::PackProbe mod(
findProbe(accel,
"pack_probe_inst"));
222 auto connected = mod.connect();
224 esi_system::PackStruct arg{};
230 esi_system::PackStruct r = connected->pack_probe(arg).get();
231 if (r.a != 0xA1 || r.b != 0xB002 || r.c != 0xC3 || r.d != 0xD0000004)
232 throw std::runtime_error(
"pack_probe field mismatch");
233 std::cout <<
"pack_probe ok: a=0x" << std::hex << (unsigned)r.a <<
" b=0x"
234 << r.b <<
" c=0x" << (
unsigned)r.c <<
" d=0x" << r.d << std::dec
240 esi_system::BitPackProbe mod(
findProbe(accel,
"bit_pack_probe_inst"));
241 auto connected = mod.connect();
243 esi_system::BitPackArg arg{};
252 esi_system::BitPackResult r = connected->bit_pack_probe(arg).get();
253 if (r.w_field != arg.x || r.z_field != arg.y || r.y_field != arg.z ||
255 throw std::runtime_error(
"bit_pack_probe field rotation mismatch");
256 std::cout <<
"bit_pack_probe ok\n";
288 static constexpr std::array<uint8_t, 4> kRequest = {0x01, 0x02, 0x03, 0x04};
290 func->call(
MessageData(kRequest.data(), kRequest.size())).get();
291 if (resMsg.
getSize() != kRequest.size())
292 throw std::runtime_error(
"array_probe: wrong response size (got " +
293 std::to_string(resMsg.
getSize()) +
", expected " +
294 std::to_string(kRequest.size()) +
")");
296 static constexpr std::array<uint8_t, 4> kExpect = {11, 22, 33, 44};
297 const uint8_t *got = resMsg.
getBytes();
298 for (
size_t i = 0; i < kExpect.size(); ++i) {
299 if (got[i] != kExpect[i]) {
300 std::stringstream ss;
301 ss <<
"array_probe: wire byte " << i <<
" mismatch (got 0x" << std::hex
302 <<
static_cast<unsigned>(got[i]) <<
" expected 0x"
303 <<
static_cast<unsigned>(kExpect[i]) <<
")";
304 throw std::runtime_error(ss.str());
307 std::cout <<
"array_probe ok (wire order: natural element-index)\n";
312 "Hardware-vs-host serialization correctness probes for ESI.",
Top level accelerator class.
Represents either the top level or an instance of a hardware module.
const std::map< AppID, BundlePort & > & getPorts() const
Access the module's ports by ID.
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 uint8_t * getBytes() const
size_t getSize() const
Get the size of the data in bytes.
A function call which gets attached to a service port.
std::string toHex(void *val)
#define ESI_PROBE_REGISTRY(name, description,...)
Convenience macro: defines main() with a probe registry.
static int runPackProbe(Accelerator *accel)
static services::FuncService::Function * findRawFunc(esi::HWModule *probe, const char *portName)
static esi::HWModule * findProbe(Accelerator *accel, const char *appidName)
static int runBytePatternConst(Accelerator *accel)
static int runSignProbe13(Accelerator *accel)
static int runArrayProbe(Accelerator *accel)
static constexpr std::array< uint8_t, 8 > kBytePattern
static int runBytePatternEchoEq(Accelerator *accel)
static int runSignProbe(Accelerator *accel)
static int runByteRotate1(Accelerator *accel)
static int runBitPackProbe(Accelerator *accel)