u3: adds jam/cue roundtrip tests of new implementations

This commit is contained in:
Joe Bryan 2020-08-27 15:12:57 -07:00
parent 9addb545c0
commit 5b9c48c3fd
2 changed files with 234 additions and 4 deletions

View File

@ -965,10 +965,10 @@ _cs_cue_xeno_next(_cue_stack_t* tac_u,
}
}
/* _cs_cue_xeno_unsafe(): cue onto the loom, all bookkeeping off-loom.
/* u3s_cue_xeno_unsafe(): cue onto the loom, all bookkeeping off-loom.
*/
static ur_cue_res_e
_cs_cue_xeno_unsafe(ur_dict32_t* dic_u,
ur_cue_res_e
u3s_cue_xeno_unsafe(ur_dict32_t* dic_u,
c3_d len_d,
const c3_y* byt_y,
u3_noun* out)
@ -1046,7 +1046,7 @@ u3s_cue_xeno(c3_d len_d, const c3_y* byt_y)
// errors are fatal
//
if ( ur_cue_good !=
(res_e = _cs_cue_xeno_unsafe(&dic_u, len_d, byt_y, &pro)) )
(res_e = u3s_cue_xeno_unsafe(&dic_u, len_d, byt_y, &pro)) )
{
fprintf(stderr, "cue xeno: failed\r\n");
exit(1);

View File

@ -1,4 +1,13 @@
#include "all.h"
#include "ur/ur.h"
// XX not declared in serial.h due to presence of ur_* types
//
ur_cue_res_e
u3s_cue_xeno_unsafe(ur_dict32_t* dic_u,
c3_d len_d,
const c3_y* byt_y,
u3_noun* out);
/* _setup(): prepare for tests.
*/
@ -294,6 +303,222 @@ _test_jam_spot_b()
return 1;
}
static void
_byte_print(c3_d out_d,
c3_y* out_y,
c3_w len_w,
const c3_y* byt_y)
{
c3_d i_d;
fprintf(stderr, " actual: { ");
for ( i_d = 0; i_d < out_d; i_d++ ) {
fprintf(stderr, "0x%x, ", out_y[i_d]);
}
fprintf(stderr, "}\r\n");
fprintf(stderr, " expect: { ");
for ( i_d = 0; i_d < len_w; i_d++ ) {
fprintf(stderr, "0x%x, ", byt_y[i_d]);
}
fprintf(stderr, "}\r\n");
}
static c3_i
_test_jam_spec(const c3_c* cap_c,
u3_noun ref,
c3_w len_w,
const c3_y* byt_y)
{
c3_i ret_i = 1;
c3_d out_d;
c3_y* out_y;
{
u3s_jam_xeno(ref, &out_d, &out_y);
if ( 0 != memcmp(out_y, byt_y, len_w) ) {
fprintf(stderr, "\033[31mjam xeno %s fail\033[0m\r\n", cap_c);
_byte_print(out_d, out_y, len_w, byt_y);
ret_i = 0;
}
free(out_y);
}
{
c3_w bit_w;
c3_w* wor_w = u3s_jam_fib(ref, &bit_w);
out_d = (bit_w >> 3) + !!ur_mask_3(bit_w);
// XX assumes little-endian
//
out_y = (c3_y*)wor_w;
if ( 0 != memcmp(out_y, byt_y, len_w) ) {
fprintf(stderr, "\033[31mjam fib %s fail\033[0m\r\n", cap_c);
_byte_print(out_d, out_y, len_w, byt_y);
ret_i = 0;
}
u3a_wfree(wor_w);
}
return ret_i;
}
static c3_i
_test_cue_spec(const c3_c* cap_c,
u3_noun ref,
c3_w len_w,
const c3_y* byt_y)
{
c3_i ret_i = 1;
{
ur_dict32_t dic_u = {0};
u3_noun out;
ur_dict32_grow((ur_root_t*)0, &dic_u, ur_fib10, ur_fib11);
if ( ur_cue_good != u3s_cue_xeno_unsafe(&dic_u, len_w, byt_y, &out) ) {
fprintf(stderr, "\033[31mcue %s fail 1\033[0m\r\n", cap_c);
ret_i = 0;
}
else if ( c3n == u3r_sing(ref, out) ) {
fprintf(stderr, "\033[31mcue %s fail 2\033[0m\r\n", cap_c);
u3m_p("ref", ref);
u3m_p("out", out);
ret_i = 0;
}
u3z(out);
ur_dict_free((ur_dict_t*)&dic_u);
}
{
u3_noun pro = u3m_soft(0, u3s_cue_atom, u3i_bytes(len_w, byt_y));
u3_noun tag, out;
u3x_cell(pro, &tag, &out);
if ( u3_blip != tag ) {
fprintf(stderr, "\033[31mcue %s fail 3\033[0m\r\n", cap_c);
ret_i = 0;
}
else if ( c3n == u3r_sing(ref, out) ) {
fprintf(stderr, "\033[31mcue %s fail 4\033[0m\r\n", cap_c);
u3m_p("ref", ref);
u3m_p("out", out);
ret_i = 0;
}
u3z(pro);
}
// if we haven't failed yet, run u3s_cue_full w/out virtualization
//
if ( ret_i ) {
u3_noun out = u3s_cue_full(len_w, byt_y);
if ( c3n == u3r_sing(ref, out) ) {
fprintf(stderr, "\033[31mcue %s fail 5\033[0m\r\n", cap_c);
u3m_p("ref", ref);
u3m_p("out", out);
ret_i = 0;
}
u3z(out);
}
return ret_i;
}
static c3_i
_test_jam_roundtrip(void)
{
c3_i ret_i = 1;
# define TEST_CASE(a, b) \
const c3_c* cap_c = a; \
u3_noun ref = b; \
ret_i &= _test_jam_spec(cap_c, ref, sizeof(res_y), res_y); \
ret_i &= _test_cue_spec(cap_c, ref, sizeof(res_y), res_y); \
u3z(ref);
{
c3_y res_y[1] = { 0x2 };
TEST_CASE("0", 0);
}
{
c3_y res_y[1] = { 0xc };
TEST_CASE("1", 1);
}
{
c3_y res_y[1] = { 0x48 };
TEST_CASE("2", 2);
}
{
c3_y res_y[6] = { 0xc0, 0x37, 0xb, 0x9b, 0xa3, 0x3 };
TEST_CASE("%fast", c3__fast);
}
{
c3_y res_y[6] = { 0xc0, 0x37, 0xab, 0x63, 0x63, 0x3 };
TEST_CASE("%full", c3__full);
}
{
c3_y res_y[1] = { 0x29 };
TEST_CASE("[0 0]", u3nc(0, 0));
}
{
c3_y res_y[2] = { 0x31, 0x3 };
TEST_CASE("[1 1]", u3nc(1, 1));
}
{
c3_y res_y[2] = { 0x21, 0xd1 };
TEST_CASE("[2 3]", u3nc(2, 3));
}
{
c3_y res_y[11] = { 0x1, 0xdf, 0x2c, 0x6c, 0x8e, 0xe, 0x7c, 0xb3, 0x3a, 0x36, 0x36 };
TEST_CASE("[%fast %full]", u3nc(c3__fast, c3__full));
}
{
c3_y res_y[2] = { 0x71, 0xcc };
TEST_CASE("[1 1 1]", u3nc(1, u3nc(1, 1)));
}
{
c3_y res_y[12] = { 0x1, 0xdf, 0x2c, 0x6c, 0x8e, 0x1e, 0xf0, 0xcd, 0xea, 0xd8, 0xd8, 0x93 };
TEST_CASE("[%fast %full %fast]", u3nc(c3__fast, u3nc(c3__full, c3__fast)));
}
{
c3_y res_y[6] = { 0xa5, 0x35, 0x19, 0xf3, 0x18, 0x5 };
TEST_CASE("[[0 0] [[0 0] 1 1] 1 1]", u3nc(u3nc(0, 0), u3nc(u3nc(u3nc(0, 0), u3nc(1, 1)), u3nc(1, 1))));
}
{
c3_y res_y[14] = { 0x15, 0x17, 0xb2, 0xd0, 0x85, 0x59, 0xb8, 0x61, 0x87, 0x5f, 0x10, 0x54, 0x55, 0x5 };
TEST_CASE("deep", u3nc(u3nc(u3nc(1, u3nc(u3nc(2, u3nc(u3nc(3, u3nc(u3nc(4, u3nc(u3nt(5, 6, u3nc(7, u3nc(u3nc(8, 0), 0))), 0)), 0)), 0)), 0)), 0), 0));
}
{
c3_y inp_y[33] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
c3_y res_y[35] = { 0, 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8 };
TEST_CASE("wide", u3i_bytes(sizeof(inp_y), inp_y));
}
return ret_i;
}
static c3_i
_test_jam(void)
{
@ -309,6 +534,11 @@ _test_jam(void)
ret_i = 0;
}
if ( !_test_jam_roundtrip() ) {
fprintf(stderr, "test jam: roundtrip: failed\r\n");
ret_i = 0;
}
return ret_i;
}