Merge branch 'noun-tests' (#1718)

* noun-tests:
  cleans up tests from previous commit, backporting to 32-bit
  64-bit noun tests

Signed-off-by: Jared Tobin <jared@tlon.io>
This commit is contained in:
Jared Tobin 2019-09-11 10:52:35 -02:30
commit 8a4fdc5843
No known key found for this signature in database
GPG Key ID: 0E4647D58F8A69E4
4 changed files with 1889 additions and 27 deletions

View File

@ -15,9 +15,9 @@ 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 = ./build/mug_tests ./build/jam_tests ./build/hashtable_tests \
./build/urbit ./build/urbit-worker
all_exes = ./build/mug_tests ./build/jam_tests \
./build/noun_tests ./build/hashtable_tests \
./build/urbit ./build/urbit-worker
# -Werror promotes all warnings that are enabled into errors (this is on)
# -Wall issues all types of errors. This is off (for now)
@ -31,10 +31,11 @@ CFLAGS := $(CFLAGS)
all: $(all_exes)
test: build/hashtable_tests build/jam_tests build/mug_tests
test: build/hashtable_tests build/jam_tests build/mug_tests build/noun_tests
./build/hashtable_tests
./build/jam_tests
./build/mug_tests
./build/noun_tests
clean:
rm -f ./tags $(all_objs) $(all_exes)
@ -59,6 +60,11 @@ build/mug_tests: $(common_objs) tests/mug_tests.o
@mkdir -p ./build
@$(CC) $^ $(LDFLAGS) -o $@
build/noun_tests: $(common_objs) tests/noun_tests.o
@echo CC -o $@
@mkdir -p ./build
@$(CC) $^ $(LDFLAGS) -o $@
build/urbit: $(common_objs) $(daemon_objs)
@echo CC -o $@
@mkdir -p ./build

View File

@ -1,30 +1,8 @@
#include "all.h"
static void _setup(void);
static void _test_cache_replace_value(void);
static void _test_cache_trimming(void);
static void _test_no_cache(void);
static void _test_skip_slot(void);
// defined in noun/hashtable.c
c3_w _ch_skip_slot(c3_w mug_w, c3_w lef_w);
/* main(): run all test cases.
*/
int
main(int argc, char* argv[])
{
_setup();
_test_no_cache();
_test_skip_slot();
_test_cache_trimming();
_test_cache_replace_value();
return 0;
}
/* _setup(): prepare for tests.
*/
static void
@ -34,6 +12,36 @@ _setup(void)
u3m_pave(c3y, c3n);
}
/* _test_bit_manipulation():
*/
static void
_test_bit_manipulation()
{
if ( sizeof(u3_noun) != sizeof(u3h_slot) ){
c3_assert(!"wrong size\n");
}
u3h_slot a = 0;
if (u3h_slot_is_null(a) != c3y){
c3_assert(!"nullity\n");
}
a = u3h_noun_be_warm(a);
if (u3h_slot_is_warm(a) != c3y){
c3_assert(!"warmth\n");
}
if (u3h_slot_is_null(a) != c3n){
c3_assert(!"nullity 2\n");
}
a = u3h_noun_be_cold(a);
if (u3h_slot_is_warm(a) != c3n){
c3_assert(!"coldness\n");
}
}
/* _test_no_cache(): test a hashtable without caching.
*/
static void
@ -115,6 +123,8 @@ _test_cache_trimming(void)
fprintf(stderr, "test_cache_trimming: ok\n");
}
/* _test_cache_replace_value():
*/
static void
_test_cache_replace_value(void)
{
@ -142,3 +152,21 @@ _test_cache_replace_value(void)
}
fprintf(stderr, "test_cache_replace_value: ok\r\n");
}
/* main(): run all test cases.
*/
int
main(int argc, char* argv[])
{
_setup();
_test_bit_manipulation();
_test_no_cache();
_test_skip_slot();
_test_cache_trimming();
_test_cache_replace_value();
fprintf(stderr, "test_hashtable: ok\r\n");
return 0;
}

View File

@ -96,8 +96,181 @@ _test_jam(void)
exit(1);
}
}
}
fprintf(stderr, "test_jam: ok\n");
/* _test_cue_jam(): more jam/cue spot-checking, ported from the 64-bit effort
*/
static void
_test_cue_jam()
{
// the boot msg from the worker
{
u3_noun dat = u3_nul;
u3_noun in_1 = u3nc(c3__play, dat);
u3_atom jam_1 = u3ke_jam(in_1);
u3_noun out_1 = u3ke_cue(jam_1);
u3_noun head_out = u3h(out_1);
u3_noun tail_out = u3t(out_1);
if (c3__play != head_out){
printf("*** cue_jam 0 out head \n");
}
if (u3_nul != tail_out){
printf("*** cue_jam 0 out tail \n");
}
}
// the boot msg from the worker, again,
// but this time torn apart into bytes and rebuilt
{
u3_noun dat = u3_nul;
u3_noun in_1 = u3nc(c3__play, dat);
u3_atom jam_1 = u3ke_jam(in_1);
c3_y buf_y[1024];
memset(buf_y, 0, 1024);
c3_w len_w = u3r_met(3, jam_1);
u3r_bytes(0, // start byte
len_w, // len
buf_y, // buffer
jam_1 ); // input noun
/// zip ....zap ... communicate between serf and king
u3_noun jam_2 = u3i_bytes(len_w, buf_y);
if ( c3n == u3r_sing(jam_1, jam_2) ) {
printf("*** error in 6 byte message\n");
}
u3_noun out_1 = u3ke_cue(jam_2);
u3_noun head_out = u3h(out_1);
u3_noun tail_out = u3t(out_1);
if (c3__play != head_out){
printf("*** cue_jam 0 out head \n");
}
if (u3_nul != tail_out){
printf("*** cue_jam 0 out tail \n");
}
}
// 1
{
u3_atom in_1 = 1;
u3_atom jam_1 = u3ke_jam(in_1);
if (12 != jam_1){
printf("*** cue_jam 1a \n");
}
u3_noun out_1 = u3ke_cue(jam_1);
if (1 != out_1){
printf("*** cue_jam 1b \n");
}
}
// [ 1 1 ]
{
u3_noun in_1 = u3i_cell(1, 1);
u3_atom jam_1 = u3ke_jam(in_1);
if (817 != jam_1){
printf("*** cue_jam 2 in \n");
}
u3_noun out_1 = u3ke_cue(jam_1);
u3_noun head_out = u3h(out_1);
u3_noun tail_out = u3t(out_1);
if (1 != head_out){
printf("*** cue_jam 2 out head \n");
}
if (1 != tail_out){
printf("*** cue_jam 2 out tail \n");
}
}
// [ 1 2 ]
{
u3_noun in_1 = u3i_cell(1, 2);
u3_atom jam_1 = u3ke_jam(in_1);
if (4657 != jam_1){
printf("*** cue_jam 2 in \n");
}
u3_noun out_1 = u3ke_cue(jam_1);
u3_noun head_out = u3h(out_1);
u3_noun tail_out = u3t(out_1);
if (1 != head_out){
printf("*** cue_jam 2 out head \n");
}
if (2 != tail_out){
printf("*** cue_jam 2 out tail \n");
}
}
// medium complicated cell
// q
// / \
// a1 r
// / \
// b2 s
// / \
// c3 d4
{
u3_noun a = (u3_noun) 0x1;
u3_noun b = (u3_noun) 0x2;
u3_noun c = (u3_noun) 0x3;
u3_noun d = (u3_noun) 0x4;
u3_noun s = u3i_cell(c, d);
u3_noun r = u3i_cell(b, s);
u3_noun q = u3i_cell(a, r);
u3_atom jam_1 = u3ke_jam(q);
u3_noun out_1 = u3ke_cue(jam_1);
u3_noun a2 = u3h(out_1);
u3_noun r2 = u3t(out_1);
if (a2 != a){
printf("*** _cue_jam: complicated a\n");
}
u3_noun b2 = u3h(r2);
u3_noun s2 = u3t(r2);
if (b2 != b){
printf("*** _cue_jam: complicated b\n");
}
u3_noun c2 = u3h(s2);
u3_noun d2 = u3t(s2);
if (c2 != c){
printf("*** _cue_jam: complicated c\n");
}
if (d2 != d){
printf("*** _cue_jam: complicated d\n");
}
}
}
/* main(): run all test cases.
@ -108,6 +281,9 @@ main(int argc, char* argv[])
_setup();
_test_jam();
_test_cue_jam();
fprintf(stderr, "test_jam: ok\n");
return 0;
}

1652
pkg/urbit/tests/noun_tests.c Normal file

File diff suppressed because it is too large Load Diff