Use OK() and ERR() in unit tests
Also remove prefixes and trailing new lines in err() and die()
This commit is contained in:
parent
648411c686
commit
c0afc79d4e
@ -104,7 +104,7 @@ instr_start(int rank, int nranks)
|
||||
|
||||
int curcpu = rank;
|
||||
|
||||
dbg("thread %d has cpu %d (ncpus=%d)\n",
|
||||
dbg("thread %d has cpu %d (ncpus=%d)",
|
||||
gettid(), curcpu, nranks);
|
||||
|
||||
instr_thread_execute(curcpu, -1, 0);
|
||||
|
@ -53,7 +53,7 @@ start_delayed(int rank, int nranks)
|
||||
|
||||
int curcpu = rank;
|
||||
|
||||
dbg("thread %d has cpu %d (ncpus=%d)\n",
|
||||
dbg("thread %d has cpu %d (ncpus=%d)",
|
||||
gettid(), curcpu, nranks);
|
||||
|
||||
delta = ((int64_t) rank) * 2LL * 3600LL * 1000LL * 1000LL * 1000LL;
|
||||
|
@ -58,7 +58,7 @@ main(void)
|
||||
/* Fill the ring buffer */
|
||||
long n = 1000000 + 10;
|
||||
|
||||
err("using n=%ld events\n", n);
|
||||
err("using n=%ld events", n);
|
||||
|
||||
/* Go back 100 ns for each event (with some space) */
|
||||
int64_t delta = 10000;
|
||||
@ -66,7 +66,7 @@ main(void)
|
||||
|
||||
for (long i = 0; i < n; i++) {
|
||||
if (t <= t0 || t >= t1)
|
||||
die("bad time\n");
|
||||
die("bad time");
|
||||
emit("OB.", t);
|
||||
t += 33;
|
||||
}
|
||||
|
@ -17,22 +17,22 @@ main(void)
|
||||
if (nosv_type_init(&type, NULL, NULL, NULL, "adopted", NULL,
|
||||
NULL, NOSV_TYPE_INIT_EXTERNAL)
|
||||
!= 0)
|
||||
die("nosv_type_init failed\n");
|
||||
die("nosv_type_init failed");
|
||||
|
||||
nosv_task_t task;
|
||||
if (nosv_attach(&task, type, 0, NULL, 0) != 0)
|
||||
die("nosv_attach failed\n");
|
||||
die("nosv_attach failed");
|
||||
|
||||
usleep(100);
|
||||
|
||||
if (nosv_detach(0) != 0)
|
||||
die("nosv_detach failed\n");
|
||||
die("nosv_detach failed");
|
||||
|
||||
if (nosv_type_destroy(type, 0) != 0)
|
||||
die("nosv_type_destroy failed\n");
|
||||
die("nosv_type_destroy failed");
|
||||
|
||||
if (nosv_shutdown() != 0)
|
||||
die("nosv_shutdown failed\n");
|
||||
die("nosv_shutdown failed");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "emu/bay.h"
|
||||
#include "common.h"
|
||||
#include "unittest.h"
|
||||
#include <time.h>
|
||||
|
||||
#define N 10000
|
||||
@ -28,23 +29,20 @@ populate(struct bay *bay)
|
||||
|
||||
channels = calloc(N, sizeof(struct chan));
|
||||
if (channels == NULL)
|
||||
die("calloc failed\n");
|
||||
die("calloc failed");
|
||||
|
||||
for (long i = 0; i < N; i++) {
|
||||
sprintf(name, "%s.%ld", BASE, i);
|
||||
chan_init(&channels[i], CHAN_SINGLE, name);
|
||||
if (bay_register(bay, &channels[i]) != 0)
|
||||
die("bay_register failed\n");
|
||||
OK(bay_register(bay, &channels[i]));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
dummy_work(struct chan *c)
|
||||
{
|
||||
if (chan_set(c, value_int64(dummy_value++)) != 0)
|
||||
die("chan_set failed\n");
|
||||
if (chan_flush(c) != 0)
|
||||
die("chan_flush failed\n");
|
||||
OK(chan_set(c, value_int64(dummy_value++)));
|
||||
OK(chan_flush(c));
|
||||
}
|
||||
|
||||
static double
|
||||
@ -62,14 +60,14 @@ measure_hash(struct bay *bay, double T)
|
||||
sprintf(name, "%s.%ld", BASE, i);
|
||||
struct chan *c = bay_find(bay, name);
|
||||
if (c == NULL)
|
||||
die("bay_find failed\n");
|
||||
die("bay_find failed");
|
||||
dummy_work(c);
|
||||
nlookups++;
|
||||
}
|
||||
|
||||
double speed = (double) nlookups / T;
|
||||
|
||||
err("bay_find: %e lookups/s\n", speed);
|
||||
err("%e lookups/s", speed);
|
||||
return speed;
|
||||
}
|
||||
|
||||
@ -90,7 +88,7 @@ measure_direct(double T)
|
||||
|
||||
double speed = (double) nlookups / T;
|
||||
|
||||
err("direct: %e lookups/s\n", speed);
|
||||
err("%e lookups/s", speed);
|
||||
return speed;
|
||||
}
|
||||
|
||||
@ -101,10 +99,10 @@ test_speed(struct bay *bay)
|
||||
double hash = measure_hash(bay, T);
|
||||
double direct = measure_direct(T);
|
||||
double slowdown = hash / direct;
|
||||
err("slowdown speed_hash/speed_direct = %f\n", slowdown);
|
||||
err("slowdown speed_hash/speed_direct = %f", slowdown);
|
||||
|
||||
if (slowdown < 0.2)
|
||||
die("hash speed is too slow\n");
|
||||
die("hash speed is too slow");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include "emu/bay.h"
|
||||
#include "common.h"
|
||||
#include "unittest.h"
|
||||
|
||||
static void
|
||||
test_duplicate(struct bay *bay)
|
||||
@ -10,22 +11,18 @@ test_duplicate(struct bay *bay)
|
||||
struct chan chan;
|
||||
chan_init(&chan, CHAN_SINGLE, "dup");
|
||||
|
||||
if (bay_register(bay, &chan) != 0)
|
||||
die("bay_register failed\n");
|
||||
|
||||
if (bay_register(bay, &chan) == 0)
|
||||
die("bay_register didn't fail\n");
|
||||
OK(bay_register(bay, &chan));
|
||||
ERR(bay_register(bay, &chan));
|
||||
}
|
||||
|
||||
static int
|
||||
callback(struct chan *chan, void *ptr)
|
||||
{
|
||||
struct value value;
|
||||
if (chan_read(chan, &value) != 0)
|
||||
die("callback: chan_read failed\n");
|
||||
OK(chan_read(chan, &value));
|
||||
|
||||
if (value.type != VALUE_INT64)
|
||||
die("callback: unexpected value type\n");
|
||||
die("unexpected value type");
|
||||
|
||||
int64_t *ival = ptr;
|
||||
*ival = value.i;
|
||||
@ -39,28 +36,25 @@ test_callback(struct bay *bay)
|
||||
struct chan chan;
|
||||
chan_init(&chan, CHAN_SINGLE, "testchan");
|
||||
|
||||
if (bay_register(bay, &chan) != 0)
|
||||
die("bay_register failed\n");
|
||||
OK(bay_register(bay, &chan));
|
||||
|
||||
int64_t data = 0;
|
||||
if (bay_add_cb(bay, BAY_CB_DIRTY, &chan, callback, &data, 1) == NULL)
|
||||
die("bay_add_cb failed\n");
|
||||
die("bay_add_cb failed");
|
||||
|
||||
if (data != 0)
|
||||
die("data changed after bay_chan_append_cb\n");
|
||||
die("data changed after bay_chan_append_cb");
|
||||
|
||||
if (chan_set(&chan, value_int64(1)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, value_int64(1)));
|
||||
|
||||
if (data != 0)
|
||||
die("data changed after chan_set\n");
|
||||
die("data changed after chan_set");
|
||||
|
||||
/* Now the callback should modify 'data' */
|
||||
if (bay_propagate(bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_propagate(bay));
|
||||
|
||||
if (data != 1)
|
||||
die("data didn't change after bay_propagate\n");
|
||||
die("data didn't change after bay_propagate");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
|
120
test/unit/chan.c
120
test/unit/chan.c
@ -3,6 +3,7 @@
|
||||
|
||||
#include "emu/chan.h"
|
||||
#include "common.h"
|
||||
#include "unittest.h"
|
||||
|
||||
static void
|
||||
test_dirty(void)
|
||||
@ -10,37 +11,30 @@ test_dirty(void)
|
||||
struct chan chan;
|
||||
chan_init(&chan, CHAN_SINGLE, "testchan");
|
||||
|
||||
if (chan_set(&chan, value_int64(1)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, value_int64(1)));
|
||||
|
||||
/* Now channel is dirty */
|
||||
|
||||
if (chan_set(&chan, value_int64(2)) == 0)
|
||||
die("chan_set didn't fail\n");
|
||||
ERR(chan_set(&chan, value_int64(2)));
|
||||
|
||||
if (chan_flush(&chan) != 0)
|
||||
die("chan_flush failed\n");
|
||||
OK(chan_flush(&chan));
|
||||
|
||||
chan_prop_set(&chan, CHAN_DIRTY_WRITE, 1);
|
||||
|
||||
if (chan_set(&chan, value_int64(3)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, value_int64(3)));
|
||||
|
||||
/* Now is dirty, but it should allow multiple writes */
|
||||
if (chan_set(&chan, value_int64(4)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, value_int64(4)));
|
||||
|
||||
struct value value;
|
||||
struct value four = value_int64(4);
|
||||
|
||||
if (chan_read(&chan, &value) != 0)
|
||||
die("chan_read failed\n");
|
||||
OK(chan_read(&chan, &value));
|
||||
|
||||
if (!value_is_equal(&value, &four))
|
||||
die("chan_read returned unexpected value\n");
|
||||
die("chan_read returned unexpected value");
|
||||
|
||||
if (chan_flush(&chan) != 0)
|
||||
die("chan_flush failed\n");
|
||||
OK(chan_flush(&chan));
|
||||
|
||||
err("OK");
|
||||
}
|
||||
@ -51,29 +45,24 @@ test_single(void)
|
||||
struct chan chan;
|
||||
struct value one = { .type = VALUE_INT64, .i = 1 };
|
||||
struct value two = { .type = VALUE_INT64, .i = 2 };
|
||||
//struct value nil = { .type = VALUE_NULL, .i = 0 };
|
||||
|
||||
chan_init(&chan, CHAN_SINGLE, "testchan");
|
||||
|
||||
/* Ensure we cannot push as stack */
|
||||
if (chan_push(&chan, one) == 0)
|
||||
die("chan_push didn't fail\n");
|
||||
ERR(chan_push(&chan, one));
|
||||
|
||||
/* Now we should be able to write with set */
|
||||
if (chan_set(&chan, one) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, one));
|
||||
|
||||
/* Now is dirty, it shouldn't allow another set */
|
||||
if (chan_set(&chan, two) == 0)
|
||||
die("chan_set didn't fail\n");
|
||||
ERR(chan_set(&chan, two));
|
||||
|
||||
struct value value;
|
||||
|
||||
if (chan_read(&chan, &value) != 0)
|
||||
die("chan_read failed\n");
|
||||
OK(chan_read(&chan, &value));
|
||||
|
||||
if (!value_is_equal(&value, &one))
|
||||
die("chan_read returned unexpected value\n");
|
||||
die("chan_read returned unexpected value");
|
||||
|
||||
err("OK");
|
||||
}
|
||||
@ -86,22 +75,17 @@ test_allow_dup(void)
|
||||
struct chan chan;
|
||||
chan_init(&chan, CHAN_SINGLE, "testchan");
|
||||
|
||||
if (chan_set(&chan, value_int64(1)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (chan_flush(&chan) != 0)
|
||||
die("chan_flush failed\n");
|
||||
OK(chan_set(&chan, value_int64(1)));
|
||||
OK(chan_flush(&chan));
|
||||
|
||||
/* Attempt to write the same value again */
|
||||
if (chan_set(&chan, value_int64(1)) == 0)
|
||||
die("chan_set didn't fail\n");
|
||||
ERR(chan_set(&chan, value_int64(1)));
|
||||
|
||||
/* Allow duplicates */
|
||||
chan_prop_set(&chan, CHAN_ALLOW_DUP, 1);
|
||||
|
||||
/* Then it should allow writting the same value */
|
||||
if (chan_set(&chan, value_int64(1)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, value_int64(1)));
|
||||
|
||||
/* Also ensure the channel is dirty */
|
||||
if (!chan.is_dirty)
|
||||
@ -119,15 +103,12 @@ test_ignore_dup(void)
|
||||
chan_init(&chan, CHAN_SINGLE, "testchan");
|
||||
chan_prop_set(&chan, CHAN_IGNORE_DUP, 1);
|
||||
|
||||
if (chan_set(&chan, value_int64(1)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, value_int64(1)));
|
||||
|
||||
if (chan_flush(&chan) != 0)
|
||||
die("chan_flush failed\n");
|
||||
OK(chan_flush(&chan));
|
||||
|
||||
/* Write the same value */
|
||||
if (chan_set(&chan, value_int64(1)) != 0)
|
||||
die("chan_set failed");
|
||||
OK(chan_set(&chan, value_int64(1)));
|
||||
|
||||
/* And ensure the channel is not dirty */
|
||||
if (chan.is_dirty)
|
||||
@ -136,69 +117,12 @@ test_ignore_dup(void)
|
||||
err("OK");
|
||||
}
|
||||
|
||||
//static void
|
||||
//test_stack(void)
|
||||
//{
|
||||
// struct chan chan;
|
||||
//
|
||||
// chan_init(&chan, CHAN_STACK);
|
||||
//
|
||||
// /* Ensure we cannot set as single */
|
||||
// if (chan_set(&chan, 1) == 0)
|
||||
// die("chan_set didn't fail\n");
|
||||
//
|
||||
// /* Channels are closed after init */
|
||||
// if (chan_push(&chan, 1) != 0)
|
||||
// die("chan_push failed\n");
|
||||
//
|
||||
// /* Now is closed, it shouldn't allow another value */
|
||||
// if (chan_push(&chan, 2) == 0)
|
||||
// die("chan_push didn't fail\n");
|
||||
//
|
||||
// struct chan_value value = { 0 };
|
||||
//
|
||||
// if (chan_flush(&chan, &value) != 0)
|
||||
// die("chan_flush failed\n");
|
||||
//
|
||||
// if (!value.ok || value.i != 1)
|
||||
// die("chan_flush returned unexpected value\n");
|
||||
//
|
||||
// /* Now it should allow to push another value */
|
||||
// if (chan_push(&chan, 2) != 0)
|
||||
// die("chan_push failed\n");
|
||||
//
|
||||
// if (chan_flush(&chan, &value) != 0)
|
||||
// die("chan_flush failed\n");
|
||||
//
|
||||
// if (!value.ok || value.i != 2)
|
||||
// die("chan_flush returned unexpected value\n");
|
||||
//
|
||||
// /* Now pop the values */
|
||||
// if (chan_pop(&chan, 2) != 0)
|
||||
// die("chan_pop failed\n");
|
||||
//
|
||||
// if (chan_flush(&chan, &value) != 0)
|
||||
// die("chan_flush failed\n");
|
||||
//
|
||||
// if (!value.ok || value.i != 1)
|
||||
// die("chan_flush returned unexpected value\n");
|
||||
//
|
||||
// if (chan_pop(&chan, 1) != 0)
|
||||
// die("chan_pop failed\n");
|
||||
//
|
||||
// /* Now the stack should be empty */
|
||||
//
|
||||
// if (chan_pop(&chan, 1) == 0)
|
||||
// die("chan_pop didn't fail\n");
|
||||
//
|
||||
//}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_single();
|
||||
test_dirty();
|
||||
test_allow_dup();
|
||||
test_ignore_dup();
|
||||
//test_stack();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "emu/clkoff.h"
|
||||
#include "common.h"
|
||||
#include "unittest.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static int
|
||||
@ -20,22 +21,21 @@ test_ok(void)
|
||||
FILE *f = fmemopen(table_str, ARRAYLEN(table_str), "r");
|
||||
|
||||
if (f == NULL)
|
||||
die("fmemopen failed\n");
|
||||
die("fmemopen failed:");
|
||||
|
||||
struct clkoff table;
|
||||
clkoff_init(&table);
|
||||
if (clkoff_load(&table, f) != 0)
|
||||
die("clkoff_load failed\n");
|
||||
OK(clkoff_load(&table, f));
|
||||
|
||||
if (clkoff_count(&table) != 4)
|
||||
die("clkoff_count failed\n");
|
||||
die("clkoff_count failed");
|
||||
|
||||
struct clkoff_entry *entry = clkoff_get(&table, 3);
|
||||
if (entry == NULL)
|
||||
die("clkoff_get returned NULL\n");
|
||||
die("clkoff_get returned NULL");
|
||||
|
||||
if (entry->index != 3)
|
||||
die("clkoff_get returned wrong index\n");
|
||||
die("clkoff_get returned wrong index");
|
||||
|
||||
fclose(f);
|
||||
|
||||
@ -55,13 +55,12 @@ test_dup(void)
|
||||
FILE *f = fmemopen(table_str, ARRAYLEN(table_str), "r");
|
||||
|
||||
if (f == NULL)
|
||||
die("fmemopen failed\n");
|
||||
die("fmemopen failed:");
|
||||
|
||||
struct clkoff table;
|
||||
|
||||
clkoff_init(&table);
|
||||
if (clkoff_load(&table, f) == 0)
|
||||
die("clkoff_load didn't fail\n");
|
||||
ERR(clkoff_load(&table, f));
|
||||
|
||||
fclose(f);
|
||||
|
||||
|
164
test/unit/mux.c
164
test/unit/mux.c
@ -3,6 +3,7 @@
|
||||
|
||||
#include "emu/mux.h"
|
||||
#include "common.h"
|
||||
#include "unittest.h"
|
||||
|
||||
#define N 10
|
||||
|
||||
@ -10,28 +11,22 @@ static void
|
||||
check_output(struct mux *mux, struct value expected)
|
||||
{
|
||||
struct value out_value = value_null();
|
||||
if (chan_read(mux->output, &out_value) != 0)
|
||||
die("chan_read() failed for output channel\n");
|
||||
OK(chan_read(mux->output, &out_value));
|
||||
|
||||
if (!value_is_equal(&out_value, &expected)) {
|
||||
die("unexpected value found %s in output (expected %s)\n",
|
||||
die("unexpected value found %s in output (expected %s)",
|
||||
value_str(out_value),
|
||||
value_str(expected));
|
||||
}
|
||||
|
||||
err("----- output ok -----\n");
|
||||
}
|
||||
|
||||
static void
|
||||
test_select(struct mux *mux, int key)
|
||||
{
|
||||
if (chan_set(mux->select, value_int64(key)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
|
||||
OK(chan_set(mux->select, value_int64(key)));
|
||||
OK(bay_propagate(mux->bay));
|
||||
check_output(mux, value_int64(1000 + key));
|
||||
err("OK");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -45,15 +40,12 @@ test_input(struct mux *mux, int key)
|
||||
/* Then change that channel */
|
||||
struct mux_input *mi = mux_get_input(mux, key);
|
||||
if (mi == NULL)
|
||||
die("mux_get_input failed to locate input %d\n", key);
|
||||
|
||||
if (chan_set(mi->chan, value_int64(new_value)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
die("mux_get_input failed to locate input %d", key);
|
||||
|
||||
OK(chan_set(mi->chan, value_int64(new_value)));
|
||||
OK(bay_propagate(mux->bay));
|
||||
check_output(mux, value_int64(new_value));
|
||||
err("OK");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -61,24 +53,22 @@ test_select_and_input(struct mux *mux, int key)
|
||||
{
|
||||
/* Set the select channel to the selected key, but don't
|
||||
* propagate the changes yet */
|
||||
if (chan_set(mux->select, value_int64(key)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(mux->select, value_int64(key)));
|
||||
|
||||
int new_value = 2000 + key;
|
||||
|
||||
/* Also change that channel */
|
||||
struct mux_input *mi = mux_get_input(mux, key);
|
||||
if (mi == NULL)
|
||||
die("mux_get_input failed to locate input %d\n", key);
|
||||
die("mux_get_input failed to locate input %d", key);
|
||||
|
||||
if (chan_set(mi->chan, value_int64(new_value)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(mi->chan, value_int64(new_value)));
|
||||
|
||||
/* Write twice to the output */
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_propagate(mux->bay));
|
||||
|
||||
check_output(mux, value_int64(new_value));
|
||||
err("OK");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -89,20 +79,18 @@ test_input_and_select(struct mux *mux, int key)
|
||||
/* First change the input */
|
||||
struct mux_input *mi = mux_get_input(mux, key);
|
||||
if (mi == NULL)
|
||||
die("mux_get_input failed to locate input %d\n", key);
|
||||
die("mux_get_input failed to locate input %d", key);
|
||||
|
||||
if (chan_set(mi->chan, value_int64(new_value)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(mi->chan, value_int64(new_value)));
|
||||
|
||||
/* Then change select */
|
||||
if (chan_set(mux->select, value_int64(key)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(mux->select, value_int64(key)));
|
||||
|
||||
/* Write twice to the output */
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_propagate(mux->bay));
|
||||
|
||||
check_output(mux, value_int64(new_value));
|
||||
err("OK");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -112,21 +100,15 @@ test_mid_propagate(struct mux *mux, int key)
|
||||
|
||||
struct mux_input *mi = mux_get_input(mux, key);
|
||||
if (mi == NULL)
|
||||
die("mux_get_input failed to locate input %d\n", key);
|
||||
die("mux_get_input failed to locate input %d", key);
|
||||
|
||||
if (chan_set(mi->chan, value_int64(new_value)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
|
||||
if (chan_set(mux->select, value_int64(key)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(chan_set(mi->chan, value_int64(new_value)));
|
||||
OK(bay_propagate(mux->bay));
|
||||
OK(chan_set(mux->select, value_int64(key)));
|
||||
OK(bay_propagate(mux->bay));
|
||||
|
||||
check_output(mux, value_int64(new_value));
|
||||
err("OK");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -136,35 +118,27 @@ test_duplicate_output(struct mux *mux, int key1, int key2)
|
||||
|
||||
struct mux_input *in1 = mux_get_input(mux, key1);
|
||||
if (in1 == NULL)
|
||||
die("mux_get_input failed to locate input1 %d\n", key1);
|
||||
die("mux_get_input failed to locate input1 %d", key1);
|
||||
|
||||
struct mux_input *in2 = mux_get_input(mux, key2);
|
||||
if (in2 == NULL)
|
||||
die("mux_get_input failed to locate input2 %d\n", key2);
|
||||
die("mux_get_input failed to locate input2 %d", key2);
|
||||
|
||||
if (chan_set(in1->chan, value_int64(new_value)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (chan_set(in2->chan, value_int64(new_value)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(in1->chan, value_int64(new_value)));
|
||||
OK(chan_set(in2->chan, value_int64(new_value)));
|
||||
|
||||
/* Select input 1 */
|
||||
if (chan_set(mux->select, value_int64(key1)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(chan_set(mux->select, value_int64(key1)));
|
||||
OK(bay_propagate(mux->bay));
|
||||
|
||||
check_output(mux, value_int64(new_value));
|
||||
|
||||
/* Now switch to input 2, which has the same value */
|
||||
if (chan_set(mux->select, value_int64(key2)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (bay_propagate(mux->bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(chan_set(mux->select, value_int64(key2)));
|
||||
OK(bay_propagate(mux->bay));
|
||||
|
||||
check_output(mux, value_int64(new_value));
|
||||
err("OK");
|
||||
}
|
||||
|
||||
/* Ensure that the output of a mux is correct while the mux is connected
|
||||
@ -183,42 +157,31 @@ test_delayed_connect(void)
|
||||
chan_init(&input, CHAN_SINGLE, "input.0");
|
||||
|
||||
/* Register all channels in the bay */
|
||||
if (bay_register(&bay, &select) != 0)
|
||||
die("bay_register failed\n");
|
||||
|
||||
if (bay_register(&bay, &output) != 0)
|
||||
die("bay_register failed\n");
|
||||
|
||||
if (bay_register(&bay, &input) != 0)
|
||||
die("bay_register failed\n");
|
||||
OK(bay_register(&bay, &select));
|
||||
OK(bay_register(&bay, &output));
|
||||
OK(bay_register(&bay, &input));
|
||||
|
||||
/* Setup channel values */
|
||||
if (chan_set(&select, value_int64(0)) != 0)
|
||||
die("chan_set failed\n");
|
||||
if (chan_set(&input, value_int64(1000)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&select, value_int64(0)));
|
||||
OK(chan_set(&input, value_int64(1000)));
|
||||
|
||||
/* Propagate now so they are clean */
|
||||
if (bay_propagate(&bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_propagate(&bay));
|
||||
|
||||
/* ----- delayed connect ----- */
|
||||
|
||||
struct mux mux;
|
||||
if (mux_init(&mux, &bay, &select, &output, NULL, 1) != 0)
|
||||
die("mux_init failed\n");
|
||||
|
||||
if (mux_set_input(&mux, 0, &input) != 0)
|
||||
die("mux_add_input failed\n");
|
||||
OK(mux_init(&mux, &bay, &select, &output, NULL, 1));
|
||||
OK(mux_set_input(&mux, 0, &input));
|
||||
|
||||
/* Don't modify the input of the select until propagation, the
|
||||
* mux_init must have marked the select as dirty. */
|
||||
|
||||
if (bay_propagate(&bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_propagate(&bay));
|
||||
|
||||
/* The mux must have selected the first input */
|
||||
check_output(&mux, value_int64(1000));
|
||||
err("OK");
|
||||
}
|
||||
|
||||
int
|
||||
@ -241,39 +204,26 @@ main(void)
|
||||
}
|
||||
|
||||
/* Register all channels in the bay */
|
||||
if (bay_register(&bay, &select) != 0)
|
||||
die("bay_register failed\n");
|
||||
OK(bay_register(&bay, &select));
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (bay_register(&bay, &inputs[i]) != 0)
|
||||
die("bay_register failed\n");
|
||||
}
|
||||
for (int i = 0; i < N; i++)
|
||||
OK(bay_register(&bay, &inputs[i]));
|
||||
|
||||
struct mux mux;
|
||||
/* Attempt to init the mux without registering the output */
|
||||
if (mux_init(&mux, &bay, &select, &output, NULL, N) == 0)
|
||||
die("mux_init didn't fail\n");
|
||||
ERR(mux_init(&mux, &bay, &select, &output, NULL, N));
|
||||
OK(bay_register(&bay, &output));
|
||||
OK(mux_init(&mux, &bay, &select, &output, NULL, N));
|
||||
|
||||
if (bay_register(&bay, &output) != 0)
|
||||
die("bay_register failed\n");
|
||||
|
||||
if (mux_init(&mux, &bay, &select, &output, NULL, N) != 0)
|
||||
die("mux_init failed\n");
|
||||
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (mux_set_input(&mux, i, &inputs[i]) != 0)
|
||||
die("mux_add_input failed\n");
|
||||
}
|
||||
for (int i = 0; i < N; i++)
|
||||
OK(mux_set_input(&mux, i, &inputs[i]));
|
||||
|
||||
/* Write something to the input channels */
|
||||
for (int i = 0; i < N; i++) {
|
||||
if (chan_set(&inputs[i], value_int64(1000 + i)) != 0)
|
||||
die("chan_set failed\n");
|
||||
}
|
||||
for (int i = 0; i < N; i++)
|
||||
OK(chan_set(&inputs[i], value_int64(1000 + i)));
|
||||
|
||||
/* Propagate values and call the callbacks */
|
||||
if (bay_propagate(&bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_propagate(&bay));
|
||||
|
||||
test_select(&mux, 1);
|
||||
test_input(&mux, 2);
|
||||
@ -283,7 +233,7 @@ main(void)
|
||||
test_duplicate_output(&mux, 6, 7);
|
||||
test_delayed_connect();
|
||||
|
||||
err("OK\n");
|
||||
err("OK");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -16,14 +16,14 @@ test_underflow_trailing(void)
|
||||
|
||||
if (memcmp(in, out, sizeof(in)) != 0) {
|
||||
for (size_t i = 0; i < sizeof(in); i++) {
|
||||
err("i=%3d, in[i]=%02x out[i]=%02x\n", i,
|
||||
err("i=%3d, in[i]=%02x out[i]=%02x", i,
|
||||
(unsigned char) in[i],
|
||||
(unsigned char) out[i]);
|
||||
}
|
||||
die("path mismatch");
|
||||
}
|
||||
|
||||
err("OK\n");
|
||||
err("OK");
|
||||
}
|
||||
|
||||
int
|
||||
|
@ -31,22 +31,18 @@ test_emit(const char *path)
|
||||
sprintf(buf, "testchan.%d", i);
|
||||
chan_init(&chan[i], CHAN_SINGLE, buf);
|
||||
|
||||
if (bay_register(&bay, &chan[i]) != 0)
|
||||
die("bay_register failed\n");
|
||||
OK(bay_register(&bay, &chan[i]));
|
||||
}
|
||||
|
||||
for (int i = 0; i < NROWS; i++)
|
||||
if (prv_register(&prv, i, type, &bay, &chan[i], 0) != 0)
|
||||
die("prv_register failed\n");
|
||||
OK(prv_register(&prv, i, type, &bay, &chan[i], 0));
|
||||
|
||||
for (int i = 0; i < NROWS; i++)
|
||||
if (chan_set(&chan[i], value_int64(value_base + i)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan[i], value_int64(value_base + i)));
|
||||
|
||||
OK(prv_advance(&prv, 10000));
|
||||
|
||||
if (bay_propagate(&bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_propagate(&bay));
|
||||
|
||||
/* Ensure all writes are flushed to the buffer and
|
||||
* the header has been fixed */
|
||||
@ -59,7 +55,7 @@ test_emit(const char *path)
|
||||
}
|
||||
fclose(f);
|
||||
|
||||
err("test emit OK\n");
|
||||
err("OK");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -82,29 +78,18 @@ test_duplicate(const char *path)
|
||||
/* Allow setting the same value in the channel */
|
||||
chan_prop_set(&chan, CHAN_ALLOW_DUP, 1);
|
||||
|
||||
if (bay_register(&bay, &chan) != 0)
|
||||
die("bay_register failed\n");
|
||||
|
||||
if (prv_register(&prv, 0, type, &bay, &chan, 0) != 0)
|
||||
die("prv_register failed\n");
|
||||
|
||||
if (chan_set(&chan, value_int64(1000)) != 0)
|
||||
die("chan_set failed\n");
|
||||
|
||||
if (prv_advance(&prv, 10000) != 0)
|
||||
die("prv_advance failed\n");
|
||||
|
||||
if (bay_propagate(&bay) != 0)
|
||||
die("bay_propagate failed\n");
|
||||
OK(bay_register(&bay, &chan));
|
||||
OK(prv_register(&prv, 0, type, &bay, &chan, 0));
|
||||
OK(chan_set(&chan, value_int64(1000)));
|
||||
OK(prv_advance(&prv, 10000));
|
||||
OK(bay_propagate(&bay));
|
||||
|
||||
/* Set the same value again, which shouldn't fail */
|
||||
if (chan_set(&chan, value_int64(1000)) != 0)
|
||||
die("chan_set failed\n");
|
||||
OK(chan_set(&chan, value_int64(1000)));
|
||||
|
||||
/* Now the propagation phase must fail, as we cannot write the same
|
||||
* value in the prv trace */
|
||||
if (bay_propagate(&bay) == 0)
|
||||
die("bay_propagate didn't fail\n");
|
||||
ERR(bay_propagate(&bay));
|
||||
|
||||
/* Ensure all writes are flushed to the buffer and
|
||||
* the header has been fixed */
|
||||
@ -136,7 +121,7 @@ test_same_type(const char *path)
|
||||
OK(prv_register(&prv, row, type, &bay, &chan, 0));
|
||||
ERR(prv_register(&prv, row, type, &bay, &chan, 0));
|
||||
|
||||
err("ok");
|
||||
err("OK");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -145,7 +130,7 @@ int main(void)
|
||||
char fname[] = "/tmp/ovni.prv.XXXXXX";
|
||||
int fd = mkstemp(fname);
|
||||
if (fd < 0)
|
||||
die("mkstemp failed\n");
|
||||
die("mkstemp failed:");
|
||||
|
||||
test_emit(fname);
|
||||
test_duplicate(fname);
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "emu/emu.h"
|
||||
#include "common.h"
|
||||
#include "unittest.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
@ -15,7 +16,7 @@ test_ok(char *fname)
|
||||
FILE *f = fopen(fname, "w");
|
||||
|
||||
if (f == NULL)
|
||||
die("fopen failed\n");
|
||||
die("fopen failed:");
|
||||
|
||||
/* Write bogus header */
|
||||
struct ovni_stream_header header;
|
||||
@ -23,17 +24,18 @@ test_ok(char *fname)
|
||||
header.version = OVNI_STREAM_VERSION;
|
||||
|
||||
if (fwrite(&header, sizeof(header), 1, f) != 1)
|
||||
die("fwrite failed\n");
|
||||
die("fwrite failed:");
|
||||
|
||||
fclose(f);
|
||||
|
||||
struct stream stream;
|
||||
const char *relpath = &fname[5];
|
||||
if (stream_load(&stream, "/tmp", relpath) != 0)
|
||||
die("stream_load failed");
|
||||
OK(stream_load(&stream, "/tmp", relpath));
|
||||
|
||||
if (stream.active)
|
||||
die("stream is active\n");
|
||||
die("stream is active");
|
||||
|
||||
err("OK");
|
||||
}
|
||||
|
||||
static void
|
||||
@ -42,7 +44,7 @@ test_bad(char *fname)
|
||||
FILE *f = fopen(fname, "w");
|
||||
|
||||
if (f == NULL)
|
||||
die("fopen failed\n");
|
||||
die("fopen failed:");
|
||||
|
||||
/* Write bogus header */
|
||||
struct ovni_stream_header header;
|
||||
@ -50,14 +52,15 @@ test_bad(char *fname)
|
||||
header.version = 1234; /* Wrong version */
|
||||
|
||||
if (fwrite(&header, sizeof(header), 1, f) != 1)
|
||||
die("fwrite failed\n");
|
||||
die("fwrite failed:");
|
||||
|
||||
fclose(f);
|
||||
|
||||
struct stream stream;
|
||||
const char *relpath = &fname[5];
|
||||
if (stream_load(&stream, "/tmp", relpath) == 0)
|
||||
die("stream_load didn't fail");
|
||||
ERR(stream_load(&stream, "/tmp", relpath));
|
||||
|
||||
err("OK");
|
||||
}
|
||||
|
||||
int main(void)
|
||||
@ -66,11 +69,12 @@ int main(void)
|
||||
char fname[] = "/tmp/ovni.stream.XXXXXX";
|
||||
int fd = mkstemp(fname);
|
||||
if (fd < 0)
|
||||
die("mkstemp failed\n");
|
||||
die("mkstemp failed:");
|
||||
|
||||
test_ok(fname);
|
||||
test_bad(fname);
|
||||
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ test_holes(void)
|
||||
* compare two values, so we don't have problems with
|
||||
* unitialized holes due to alignment */
|
||||
if (memcmp(&a, &b, sizeof(struct value)) != 0)
|
||||
die("values are not the same\n");
|
||||
die("values are not the same");
|
||||
|
||||
err("OK\n");
|
||||
err("OK");
|
||||
}
|
||||
|
||||
/* Ensure value_null results in values being equal */
|
||||
@ -39,7 +39,7 @@ test_null_init(void)
|
||||
if (!value_is_equal(&a, &b))
|
||||
die("null not equal");
|
||||
|
||||
err("OK\n");
|
||||
err("OK");
|
||||
}
|
||||
|
||||
/* Test that we can printf at least 8 values without overwritting the
|
||||
|
@ -34,14 +34,14 @@ int main(void)
|
||||
int tuple[3] = { 0 };
|
||||
|
||||
if (version_parse(c->version, tuple) != c->rc)
|
||||
die("wrong return value\n");
|
||||
die("wrong return value");
|
||||
|
||||
if (c->rc != 0)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < 3; j++) {
|
||||
if (tuple[j] != c->tuple[j])
|
||||
die("wrong parsed version\n");
|
||||
die("wrong parsed version");
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user