5 #ifndef OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_UJSON_OTTF_H_
6 #define OPENTITAN_SW_DEVICE_LIB_TESTING_TEST_FRAMEWORK_UJSON_OTTF_H_
9 #include "sw/device/lib/base/status.h"
11 #include "sw/device/lib/ujson/ujson.h"
14 #if defined(UJSON_SERDE_IMPL) && UJSON_SERDE_IMPL == 1
15 #define OLD_UJSON_SERDE_IMPL
16 #undef UJSON_SERDE_IMPL
17 #define UJSON_SERDE_IMPL 0
19 #include "sw/device/lib/testing/json/ottf.h"
20 #ifdef OLD_UJSON_SERDE_IMPL
21 #undef UJSON_SERDE_IMPL
22 #define UJSON_SERDE_IMPL 1
34 ujson_t ujson_ottf_console(
void);
48 #define UJSON_WITH_CRC(deser_fn_, uj_ctx_, data_) \
50 ujson_crc32_reset(uj_ctx_); \
51 status_t err = deser_fn_(uj_ctx_, data_); \
52 uint32_t msg_crc = ujson_crc32_finish(uj_ctx_); \
54 if (status_ok(err)) { \
55 err = ujson_deserialize_ottf_crc_t(uj_ctx_, &crc); \
56 if (status_ok(err) && msg_crc != crc.crc) { \
70 #define RESP_CRC(uj_ctx_) \
72 uint32_t crc = ujson_crc32_finish(uj_ctx_); \
73 TRY(ujson_putbuf(uj_ctx_, " CRC:", 5)); \
74 TRY(ujson_serialize_uint32_t(uj_ctx_, &crc)); \
75 TRY(ujson_putbuf(uj_ctx_, "\n", 1)); \
86 #define RESP_OK(responder_, uj_ctx_, data_) \
88 TRY(ujson_putbuf(uj_ctx_, "RESP_OK:", 8)); \
89 ujson_crc32_reset(uj_ctx_); \
90 TRY(responder_(uj_ctx_, data_)); \
101 #define RESP_OK_STATUS(uj_ctx_, ...) \
103 status_t sts = OK_STATUS(__VA_ARGS__); \
104 RESP_OK(ujson_serialize_status_t, uj_ctx_, &sts); \
114 #define RESP_ERR(uj_ctx_, expr_) \
116 status_t sts = expr_; \
117 if (!status_ok(sts)) { \
118 TRY(ujson_putbuf(uj_ctx_, "RESP_ERR:", 9)); \
119 TRY(ujson_serialize_status_t(uj_ctx_, &sts)); \