aboutsummaryrefslogtreecommitdiff
path: root/tests/simple_mem
diff options
context:
space:
mode:
Diffstat (limited to 'tests/simple_mem')
-rw-r--r--tests/simple_mem/bus.c29
-rw-r--r--tests/simple_mem/many.c28
-rw-r--r--tests/simple_mem/no_bus.c24
-rw-r--r--tests/simple_mem/source.mk17
-rw-r--r--tests/simple_mem/traffic_gen.c61
-rw-r--r--tests/simple_mem/traffic_gen.h9
6 files changed, 168 insertions, 0 deletions
diff --git a/tests/simple_mem/bus.c b/tests/simple_mem/bus.c
new file mode 100644
index 0000000..fa2ffad
--- /dev/null
+++ b/tests/simple_mem/bus.c
@@ -0,0 +1,29 @@
+#include <assert.h>
+
+#include <gran/root.h>
+#include <gran/clock_domain.h>
+#include <gran/components/mem/simple_mem.h>
+#include <gran/components/bus/simple_bus.h>
+
+#include "traffic_gen.h"
+
+int main()
+{
+ const size_t size = 100000;
+ const uintptr_t addr = 100000;
+ struct component *simple_mem = create_simple_mem(size);
+ struct component *simple_bus = create_simple_bus();
+ simple_bus_add(simple_bus, simple_mem, addr, size);
+
+ struct component *traffic_gen = create_traffic_gen(simple_mem, addr, size);
+
+ struct clock_domain *clk = create_clock_domain(NS(1));
+ clock_domain_add(clk, traffic_gen);
+
+ struct gran_root *root = create_root();
+ root_add_clock(root, clk);
+
+ assert(root_run(root) == OK);
+
+ destroy_root(root);
+}
diff --git a/tests/simple_mem/many.c b/tests/simple_mem/many.c
new file mode 100644
index 0000000..6754ebb
--- /dev/null
+++ b/tests/simple_mem/many.c
@@ -0,0 +1,28 @@
+#include <assert.h>
+
+#include <gran/root.h>
+#include <gran/clock_domain.h>
+#include <gran/components/mem/simple_mem.h>
+
+#include "traffic_gen.h"
+
+int main()
+{
+ const size_t size = 100000;
+ struct component *simple_mem1 = create_simple_mem(size);
+ struct component *simple_mem2 = create_simple_mem(size);
+
+ struct component *traffic_gen1 = create_traffic_gen(simple_mem1, 0, size);
+ struct component *traffic_gen2 = create_traffic_gen(simple_mem2, 0, size);
+
+ struct clock_domain *clk = create_clock_domain(NS(1));
+ clock_domain_add(clk, traffic_gen1);
+ clock_domain_add(clk, traffic_gen2);
+
+ struct gran_root *root = create_root();
+ root_add_clock(root, clk);
+
+ assert(root_run(root) == OK);
+
+ destroy_root(root);
+}
diff --git a/tests/simple_mem/no_bus.c b/tests/simple_mem/no_bus.c
new file mode 100644
index 0000000..df7888e
--- /dev/null
+++ b/tests/simple_mem/no_bus.c
@@ -0,0 +1,24 @@
+#include <assert.h>
+
+#include <gran/root.h>
+#include <gran/clock_domain.h>
+#include <gran/components/mem/simple_mem.h>
+
+#include "traffic_gen.h"
+
+int main()
+{
+ const size_t size = 100000;
+ struct component *simple_mem = create_simple_mem(size);
+ struct component *traffic_gen = create_traffic_gen(simple_mem, 0, size);
+
+ struct clock_domain *clk = create_clock_domain(NS(1));
+ clock_domain_add(clk, traffic_gen);
+
+ struct gran_root *root = create_root();
+ root_add_clock(root, clk);
+
+ assert(root_run(root) == OK);
+
+ destroy_root(root);
+}
diff --git a/tests/simple_mem/source.mk b/tests/simple_mem/source.mk
new file mode 100644
index 0000000..1c19967
--- /dev/null
+++ b/tests/simple_mem/source.mk
@@ -0,0 +1,17 @@
+TEST_OBJS != ./scripts/gen-deps --sources "tests/simple_mem/traffic_gen.c"
+NO_BUS_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_mem/no_bus.c"
+BUS_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_mem/bus.c"
+MANY_TEST_OBJ != ./scripts/gen-deps --sources "tests/simple_mem/many.c"
+
+TEST_PROGS += build/tests/simple_mem/no_bus \
+ build/tests/simple_mem/bus \
+ build/tests/simple_mem/many
+
+build/tests/simple_mem/no_bus: $(NO_BUS_TEST_OBJ) $(TEST_OBJS) $(OBJS)
+ $(COMPILE) $(NO_BUS_TEST_OBJ) $(TEST_OBJS) $(OBJS) -o $@
+
+build/tests/simple_mem/bus: $(BUS_TEST_OBJ) $(TEST_OBJS) $(OBJS)
+ $(COMPILE) $(BUS_TEST_OBJ) $(TEST_OBJS) $(OBJS) -o $@
+
+build/tests/simple_mem/many: $(MANY_TEST_OBJ) $(TEST_OBJS) $(OBJS)
+ $(COMPILE) $(MANY_TEST_OBJ) $(TEST_OBJS) $(OBJS) -o $@
diff --git a/tests/simple_mem/traffic_gen.c b/tests/simple_mem/traffic_gen.c
new file mode 100644
index 0000000..4d14d12
--- /dev/null
+++ b/tests/simple_mem/traffic_gen.c
@@ -0,0 +1,61 @@
+#include <stdlib.h>
+#include <assert.h>
+
+#include <gran/component.h>
+
+#include "traffic_gen.h"
+
+struct traffic_gen {
+ struct component component;
+ struct component *stress;
+ uintptr_t addr;
+ uintptr_t end;
+
+ size_t counter;
+};
+
+static stat traffic_gen_clock(struct traffic_gen *tg)
+{
+ if (tg->addr == tg->end)
+ return DONE;
+
+ uint8_t c = 0;
+ switch (tg->counter) {
+ case 0:
+ assert(write_u8(tg->stress, tg->addr, 13) == OK);
+ tg->counter = 1;
+ break;
+
+ case 1:
+ c = 0;
+ assert(read_u8(tg->stress, tg->addr, &c) == OK);
+ assert(c == 13);
+ tg->counter = 0;
+ tg->addr++;
+ break;
+ }
+
+ return OK;
+}
+
+void traffic_gen_destroy(struct traffic_gen *tg)
+{
+ destroy(tg->stress);
+ free(tg);
+}
+
+struct component *create_traffic_gen(struct component *stress, uintptr_t start, size_t size)
+{
+ struct traffic_gen *new = calloc(1, sizeof(struct traffic_gen));
+ if (!new)
+ return NULL;
+
+ new->stress = stress;
+ new->addr = start;
+ new->end = start + size;
+ new->counter = 0;
+
+ new->component.clock = (clock_callback)traffic_gen_clock;
+ new->component.destroy = (destroy_callback)traffic_gen_destroy;
+ return (struct component *)new;
+}
diff --git a/tests/simple_mem/traffic_gen.h b/tests/simple_mem/traffic_gen.h
new file mode 100644
index 0000000..9875bae
--- /dev/null
+++ b/tests/simple_mem/traffic_gen.h
@@ -0,0 +1,9 @@
+#ifndef EXSIM_TRAFFIC_GEN_H
+#define EXSIM_TRAFFIC_GEN_H
+
+#include <stdint.h>
+#include <stddef.h>
+
+struct component *create_traffic_gen(struct component *, uintptr_t, size_t);
+
+#endif /* EXSIM_TRAFFIC_GEN_H */