summaryrefslogtreecommitdiff
path: root/cesar/hal/leon/maximus/test
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/hal/leon/maximus/test')
-rw-r--r--cesar/hal/leon/maximus/test/Config3
-rw-r--r--cesar/hal/leon/maximus/test/Makefile8
-rw-r--r--cesar/hal/leon/maximus/test/inc/test_maximus_timer.h40
-rw-r--r--cesar/hal/leon/maximus/test/src/test_maximus_timer.c306
4 files changed, 357 insertions, 0 deletions
diff --git a/cesar/hal/leon/maximus/test/Config b/cesar/hal/leon/maximus/test/Config
new file mode 100644
index 0000000000..cba3c8284a
--- /dev/null
+++ b/cesar/hal/leon/maximus/test/Config
@@ -0,0 +1,3 @@
+CONFIG_DEBUG = y
+CONFIG_DEBUG_FATAL_CATCH = y
+CONFIG_TRACE = y \ No newline at end of file
diff --git a/cesar/hal/leon/maximus/test/Makefile b/cesar/hal/leon/maximus/test/Makefile
new file mode 100644
index 0000000000..305256daea
--- /dev/null
+++ b/cesar/hal/leon/maximus/test/Makefile
@@ -0,0 +1,8 @@
+BASE = ../../../..
+EXTRA_HOST_CFLAGS+= -DUNIT_TEST
+HOST_PROGRAMS = test_maximus_timer
+test_maximus_timer_SOURCES = test_maximus_timer.c
+test_maximus_timer_MODULES = lib host hal/leon/maximus
+INCLUDES = hal/leon/maximus/test/inc
+
+include $(BASE)/common/make/top.mk \ No newline at end of file
diff --git a/cesar/hal/leon/maximus/test/inc/test_maximus_timer.h b/cesar/hal/leon/maximus/test/inc/test_maximus_timer.h
new file mode 100644
index 0000000000..ff8a323380
--- /dev/null
+++ b/cesar/hal/leon/maximus/test/inc/test_maximus_timer.h
@@ -0,0 +1,40 @@
+#ifndef hal_leon_maximus_test_inc_test_maximus_timer_h
+#define hal_leon_maximus_test_inc_test_maximus_timer_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/leon/maximus/test/inc/test_maximus_timer.h
+ * \brief test header for Maximus.
+ * \ingroup hal_leon_maximus
+ */
+
+#include "host/fwd.h" // for 'station_ctx_t'
+
+/**
+ * DSR callback function.
+ * \param user_data user data
+ */
+void
+leon_timer_cb (void *user_data);
+
+/**
+ * Open pipe or socket.
+ * \param station pointer to the station context
+ * \return file descriptor for pipe or socket
+ */
+int
+maximus_timer_open (station_ctx_t *station);
+
+/**
+ * Close pipe.
+ * \param fd file descriptor for pipe or socket
+ */
+void
+maximus_timer_close (int fd);
+
+#endif /* hal_leon_maximus_test_inc_test_maximus_timer_h */
diff --git a/cesar/hal/leon/maximus/test/src/test_maximus_timer.c b/cesar/hal/leon/maximus/test/src/test_maximus_timer.c
new file mode 100644
index 0000000000..2702717174
--- /dev/null
+++ b/cesar/hal/leon/maximus/test/src/test_maximus_timer.c
@@ -0,0 +1,306 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2007 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hal/leon/maximus/test/src/test_maximus_timer.c
+ * \brief HAL leon timer test functions for Maximus.
+ * \ingroup hal_leon_maximus
+ */
+
+#include "common/std.h"
+#include "lib/test.h"
+#include "lib/trace.h"
+#include "hal/leon/maximus/inc/maximus_timer_ctx.h"
+#include "hal/leon/maximus/inc/maximus_timer.h"
+#include "hal/leon/maximus/inc/maximus_interrupts.h"
+#include "hal/leon/maximus/test/inc/test_maximus_timer.h"
+#include <stdio.h> // for 'printf'
+#include <string.h> // for 'memset'
+#include <netinet/in.h> // for 'ntohl' and 'ntohs' functions
+#include <unistd.h> // for 'read', 'open()' and 'close()'
+#include <fcntl.h> // for 'read', 'open()' and 'close()'
+#include <errno.h>
+
+#include "hal/phy/phy.h"
+
+void leon_timer_test_suite (test_t t);
+
+uint32_t maximus_pending_isrs;
+station_ctx_t my_station;
+leon_timer_t *ctx;
+phy_t *phy;
+
+void
+leon_timer_cb (void *user_data)
+{
+ int *my_data = (int *)user_data;
+ *my_data = 987654321;
+ return;
+}
+
+int
+maximus_timer_open (station_ctx_t *station)
+{
+ int fd;
+
+ #ifdef STATION_SOCK
+ fd = station->sock_pair_fd;
+ #else /* STATION_SOCK */
+ fd = open(station->pipe_out_name, O_RDONLY);
+ #endif /* STATION_SOCK */
+
+ return fd;
+}
+
+void
+maximus_timer_close (int fd)
+{
+ #ifndef STATION_SOCK
+ close(fd);
+ #endif /* !STATION_SOCK */
+}
+
+void
+leon_timer_init_test_case(test_t t)
+{
+ int user_data = 123456789;
+
+ printf("init\n");
+ phy = blk_alloc ();
+ test_case_begin(t, "init");
+
+ test_begin(t, "init")
+ {
+ ctx = leon_timer_init ((void *)&user_data, &leon_timer_cb, phy);
+ test_fail_unless ((EINVAL != errno)
+ && (NULL != ctx)
+ && (user_data == *((int *)ctx->user_data))
+ && (&leon_timer_cb == ctx->cb));
+ ctx->warning_assert = true;
+ } test_end;
+
+ test_begin(t, "cb")
+ {
+ (*ctx->cb)(ctx->user_data);
+ test_fail_unless (987654321 == *((int *)ctx->user_data));
+ } test_end;
+
+ maximus_pending_isrs = 0;
+
+ return;
+}
+
+void leon_timer_program_test_case(test_t t)
+{
+ u32 date = 0xDEADBEEE;
+ netclock_id_t id = 0;
+
+ printf("leon timer program\n");
+ test_case_begin(t, "leon timer program");
+
+ leon_timer_program (ctx, date);
+
+ // check that the correct netclock message has been sent to Maximus
+ test_begin(t, "netclock message")
+ {
+ unsigned char data[256];
+ netclock_msg_hdr_t *netclock_hdr;
+ int fd_in = -1;
+
+ // open pipe or socket
+ fd_in = maximus_timer_open(&my_station);
+
+ // read sci and netclock headers
+ memset(data, '\0', 256);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
+ && (sizeof(netclock_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(netclock_msg_hdr_t))));
+
+ // set netclock header pointer
+ netclock_hdr = (netclock_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
+
+ // check netclock tick value
+ test_fail_unless (date == ntohl(netclock_hdr->tick_low));
+
+ // check netclock id for 'leon_timer_cancel()'
+ test_fail_unless (ntohs(netclock_hdr->id) == ctx->netclock_id);
+
+ // close pipe
+ maximus_timer_close(fd_in);
+ } test_end;
+
+ // test the callback
+ test_begin(t, "maximus leon timer cb")
+ {
+ maximus_leon_timer_cb ((void*)ctx);
+ test_fail_unless ((EINVAL != errno)
+ && (maximus_pending_isrs & (1 << HAL_LEON_TIMER_INTERRUPT)));
+ } test_end;
+
+ test_begin(t, "leon timer cb")
+ {
+ test_fail_unless (NULL != ctx->cb);
+ (*ctx->cb)(ctx->user_data);
+ maximus_pending_isrs &= (0 << HAL_LEON_TIMER_INTERRUPT);
+ } test_end;
+
+ id = ctx->netclock_id;
+ leon_timer_program (ctx, date+1);
+
+ // check that the correct netclock message has been sent to Maximus
+ test_begin(t, "cancel netclock message")
+ {
+ unsigned char data[256];
+ netclock_msg_hdr_t *netclock_hdr;
+ int fd_in = -1;
+
+ // open pipe or socket
+ fd_in = maximus_timer_open(&my_station);
+
+ // read sci and netclock headers
+ memset(data, '\0', 256);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
+ && (sizeof(netclock_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(netclock_msg_hdr_t))));
+
+ // set netclock header pointer
+ netclock_hdr = (netclock_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
+
+ // check netclock id
+ test_fail_unless (ntohs(netclock_hdr->id) == id);
+
+ // close pipe
+ maximus_timer_close(fd_in);
+ } test_end;
+
+ // check that the correct netclock message has been sent to Maximus
+ test_begin(t, "program netclock message")
+ {
+ unsigned char data[256];
+ netclock_msg_hdr_t *netclock_hdr;
+ int fd_in = -1;
+
+ // open pipe or socket
+ fd_in = maximus_timer_open(&my_station);
+
+ // read sci and netclock headers
+ memset(data, '\0', 256);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
+ && (sizeof(netclock_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(netclock_msg_hdr_t))));
+
+ // set netclock header pointer
+ netclock_hdr = (netclock_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
+
+ // check netclock tick value
+ test_fail_unless (date+1 == ntohl(netclock_hdr->tick_low));
+
+ // check netclock id for 'phy_access_timer_cancel'
+ test_fail_unless (ntohs(netclock_hdr->id) == ctx->netclock_id);
+
+ // close pipe
+ maximus_timer_close(fd_in);
+ } test_end;
+
+ return;
+}
+
+void leon_timer_cancel_test_case(test_t t)
+{
+ netclock_id_t id = 0;
+
+ printf("leon timer cancel\n");
+ test_case_begin(t, "leon timer cancel");
+
+ test_begin(t, "leon timer cancel")
+ {
+ id = ctx->netclock_id;
+ leon_timer_cancel (ctx);
+ test_fail_unless ((EINVAL != errno)
+ && (0 == ctx->netclock_id));
+ } test_end;
+
+ // check that the correct netclock message has been sent to Maximus
+ test_begin(t, "netclock message")
+ {
+ unsigned char data[256];
+ netclock_msg_hdr_t *netclock_hdr;
+ int fd_in = -1;
+
+ // open pipe or socket
+ fd_in = maximus_timer_open(&my_station);
+
+ // read sci and netclock headers
+ memset(data, '\0', 256);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, data, sizeof(sci_msg_hdr_t)))
+ && (sizeof(netclock_msg_hdr_t) == read(fd_in, data+sizeof(sci_msg_hdr_t), sizeof(netclock_msg_hdr_t))));
+
+ // set netclock header pointer
+ netclock_hdr = (netclock_msg_hdr_t *)(data+sizeof(sci_msg_hdr_t));
+
+ // check netclock id
+ test_fail_unless (ntohs(netclock_hdr->id) == id);
+
+ // close pipe
+ maximus_timer_close(fd_in);
+ } test_end;
+
+ return;
+}
+
+void leon_timer_uninit_test_case(test_t t)
+{
+ printf("uninit\n");
+ test_case_begin(t, "uninit");
+
+ test_begin(t, "uninit")
+ {
+ leon_timer_uninit(ctx);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+
+ blk_release (phy);
+
+ return;
+}
+
+void leon_timer_test_suite(test_t t)
+{
+ // reset errno
+ errno = 0;
+
+ station_init (&my_station);
+ station_log_set_level(&my_station, STATION_LOG_DEBUG);
+ station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
+ //my_station.pipe_log_fd = 1;
+
+ test_suite_begin(t, "leon timer");
+ leon_timer_init_test_case(t);
+ leon_timer_program_test_case(t);
+ leon_timer_cancel_test_case(t);
+ printf("BEGIN_TRACE\n");
+ trace_buffer_dbg_dump(&ctx->trace);
+ printf("END_TRACE\n");
+ leon_timer_uninit_test_case(t);
+
+ station_down (&my_station);
+}
+
+int
+main (int argc, char **argv)
+{
+ test_t t;
+ test_init(t, argc, argv);
+
+ trace_init();
+ leon_timer_test_suite(t);
+ trace_uninit();
+
+ test_result(t);
+ return test_nb_failed(t) == 0 ? 0 : 1;
+}