Initial vere test passes on ames lane codec

This commit is contained in:
Ted Blackman 2019-07-09 17:48:07 -07:00
parent 3a1a3e30cc
commit ed4d477ba0
4 changed files with 87 additions and 4 deletions

View File

@ -15,7 +15,7 @@ worker_objs = $(shell echo $(worker) | sed 's/\.c/.o/g')
all_objs = $(common_objs) $(daemon_objs) $(worker_objs)
all_srcs = $(common) $(daemon) $(worker)
all_exes = ./mug_tests jam_tests ./hashtable_tests ./urbit ./urbit-worker
all_exes = ./ames_tests ./mug_tests jam_tests ./hashtable_tests ./urbit ./urbit-worker
# -Werror promotes all warnings that are enabled into errors (this is on)
@ -29,9 +29,10 @@ CFLAGS := $(CFLAGS)
################################################################################
all: urbit urbit-worker hashtable_tests jam_tests mug_tests
all: urbit urbit-worker ames_tests hashtable_tests jam_tests mug_tests
test: hashtable_tests jam_tests mug_tests
test: ames_tests hashtable_tests jam_tests mug_tests
./ames_tests
./hashtable_tests
./jam_tests
./mug_tests
@ -44,6 +45,10 @@ mrproper: clean
################################################################################
ames_tests: $(common_objs) tests/ames_tests.o
@echo CC -o $@
@$(CC) $^ $(LDFLAGS) -o $@
hashtable_tests: $(common_objs) tests/hashtable_tests.o
@echo CC -o $@
@$(CC) $^ $(LDFLAGS) -o $@

View File

@ -248,6 +248,13 @@
c3_c* dns_c; // galaxy fqdn (optional)
} u3_pact;
/* u3_lane: ames lane (IP address and port)
*/
typedef struct _u3_lane {
c3_w pip_w; // target IPv4 address
c3_s por_s; // target port
} u3_lane;
/* u3_poke: poke callback function.
*/
typedef void (*u3_poke)(void*, u3_noun);
@ -983,6 +990,15 @@
void
u3_ames_io_exit(u3_pier* pir_u);
/* u3_ames_decode_lane(): destructure lane from noun
*/
u3_lane
u3_ames_decode_lane(u3_noun);
/* u3_ames_encode_lane(): encode lane as noun
*/
u3_noun
u3_ames_encode_lane(u3_lane);
/** Autosave.
**/

View File

@ -0,0 +1,42 @@
#include "all.h"
#include "vere/vere.h"
/* _setup(): prepare for tests.
*/
static void
_setup(void)
{
u3m_init();
u3m_pave(c3y, c3n);
}
/* _test_ames(): spot check ames helpers
*/
static void
_test_ames(void)
{
u3_lane lan_u;
lan_u.pip_w = 0x7f000001;
lan_u.por_s = 12345;
u3_lane nal_u = u3_ames_decode_lane(u3_ames_encode_lane(lan_u));
if ( !(lan_u.pip_w == nal_u.pip_w && lan_u.por_s == nal_u.por_s) ) {
fprintf(stderr, "ames: lane fail (a)\r\n");
fprintf(stderr, "pip: %d, por: %d\r\n", nal_u.pip_w, nal_u.por_s);
exit(1);
}
}
/* main(): run all test cases.
*/
int
main(int argc, char* argv[])
{
_setup();
_test_ames();
fprintf(stderr, "ames ok");
return 0;
}

View File

@ -185,6 +185,26 @@ _ames_czar_cb(uv_getaddrinfo_t* adr_u,
uv_freeaddrinfo(aif_u);
}
u3_lane
u3_ames_decode_lane(u3_noun lan) {
u3_noun cud, pip, por;
cud = u3ke_cue(lan);
u3x_cell(cud, &pip, &por);
u3_lane lan_u;
lan_u.pip_w = u3r_word(0, pip);
lan_u.por_s = por;
u3z(pip); u3z(por);
return lan_u;
}
u3_noun
u3_ames_encode_lane(u3_lane lan) {
return u3ke_jam(u3nc(u3i_words(1, &lan.pip_w), lan.por_s));
}
/* _ames_czar(): galaxy address resolution.
*/
@ -259,7 +279,7 @@ _ames_czar(u3_pact* pac_u, c3_c* bos_c)
}
}
/* _ames_lane_ipv4(): IPv4 address/ from lane.
/* _ames_lane_ipv4(): IPv4 address from noun.
*/
u3_noun
_ames_lane_ip(u3_noun lan, c3_s* por_s, c3_w* pip_w)