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 ||
153 r.sign_bit() != c.sign_bit)
154 throw std::runtime_error(
"sign_probe mismatch for arg=" +
155 std::to_string(c.arg));
157 std::cout <<
"sign_probe ok\n";
162 esi_system::SignProbe13 mod(
findProbe(accel,
"sign_probe13_inst"));
163 auto connected = mod.connect();
170 static constexpr int16_t kMin = -4096;
171 static constexpr int16_t kMax = 4095;
182 {kMax, kMin,
static_cast<int16_t
>(-kMax), 0},
185 {kMin,
static_cast<int16_t
>(kMin + 1), kMin, 1},
187 for (
const Case &c : cases) {
188 esi_system::SignResult13 r = connected->sign_probe13(c.arg).get();
189 if (r.plus_one() != c.plus_one || r.neg() != c.neg ||
190 r.sign_bit() != c.sign_bit)
191 throw std::runtime_error(
192 "sign_probe13 mismatch for arg=" + std::to_string(c.arg) +
193 " got plus_one=" + std::to_string(r.plus_one()) +
194 " neg=" + std::to_string(r.neg()) +
195 " sign_bit=" + std::to_string(r.sign_bit()));
219 std::cout <<
"sign_probe13 ok\n";
224 esi_system::PackProbe mod(
findProbe(accel,
"pack_probe_inst"));
225 auto connected = mod.connect();
227 esi_system::PackStruct arg{};
233 esi_system::PackStruct r = connected->pack_probe(arg).get();
234 if (r.a() != 0xA1 || r.b() != 0xB002 || r.c() != 0xC3 || r.d() != 0xD0000004)
235 throw std::runtime_error(
"pack_probe field mismatch");
236 std::cout <<
"pack_probe ok: a=0x" << std::hex << (unsigned)r.a() <<
" b=0x"
237 << r.b() <<
" c=0x" << (unsigned)r.c() <<
" d=0x" << r.d()
243 esi_system::BitPackProbe mod(
findProbe(accel,
"bit_pack_probe_inst"));
244 auto connected = mod.connect();
246 esi_system::BitPackArg arg{};
255 esi_system::BitPackResult r = connected->bit_pack_probe(arg).get();
256 if (r.w_field() != arg.x() || r.z_field() != arg.y() ||
257 r.y_field() != arg.z() || r.x_field() != arg.w())
258 throw std::runtime_error(
"bit_pack_probe field rotation mismatch");
259 std::cout <<
"bit_pack_probe ok\n";
291 static constexpr std::array<uint8_t, 4> kRequest = {0x01, 0x02, 0x03, 0x04};
293 func->call(
MessageData(kRequest.data(), kRequest.size())).get();
294 if (resMsg.
getSize() != kRequest.size())
295 throw std::runtime_error(
"array_probe: wrong response size (got " +
296 std::to_string(resMsg.
getSize()) +
", expected " +
297 std::to_string(kRequest.size()) +
")");
299 static constexpr std::array<uint8_t, 4> kExpect = {11, 22, 33, 44};
300 const uint8_t *got = resMsg.
getBytes();
301 for (
size_t i = 0; i < kExpect.size(); ++i) {
302 if (got[i] != kExpect[i]) {
303 std::stringstream ss;
304 ss <<
"array_probe: wire byte " << i <<
" mismatch (got 0x" << std::hex
305 <<
static_cast<unsigned>(got[i]) <<
" expected 0x"
306 <<
static_cast<unsigned>(kExpect[i]) <<
")";
307 throw std::runtime_error(ss.str());
310 std::cout <<
"array_probe ok (wire order: natural element-index)\n";
315 "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)