summaryrefslogtreecommitdiff
path: root/hal/hle/maximus/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'hal/hle/maximus/test/src')
-rw-r--r--hal/hle/maximus/test/src/test_maximus_ether.c479
-rw-r--r--hal/hle/maximus/test/src/test_maximus_hle.c18
-rw-r--r--hal/hle/maximus/test/src/test_maximus_ipmbox.c240
3 files changed, 702 insertions, 35 deletions
diff --git a/hal/hle/maximus/test/src/test_maximus_ether.c b/hal/hle/maximus/test/src/test_maximus_ether.c
index 66be14ef8e..0fff2cf669 100644
--- a/hal/hle/maximus/test/src/test_maximus_ether.c
+++ b/hal/hle/maximus/test/src/test_maximus_ether.c
@@ -16,42 +16,489 @@
#include "hal/hle/maximus/test/inc/test_maximus_hle.h"
#include "hal/hle/maximus/inc/maximus_ether.h"
#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h"
+#include "hal/hle/maximus/inc/maximus_interrupts.h" // for 'HAL_HLE_INTERRUPT_IPMBOX'
#include "hal/hle/ipmbox.h"
#include "hal/hle/forward.h" // for 'ipmbox_t'
+#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...'
#include "host/station.h" // for 'station_ctx_t'
+#include "maximus/common/types/ethernet_types.h" // for 'ETHERNET_TYPE_...'
#include <stdio.h> // for 'printf'
#include <string.h> // for 'memset'
#include <unistd.h> // for 'read'
#include <fcntl.h> // for 'read'
+#include <stdlib.h> // for 'free'
#include <errno.h>
extern uint32_t maximus_pending_isrs; // used in 'station.c'
extern station_ctx_t my_station;
ipmbox_t *ctx;
-/** User data for Maximus. */
-struct maximus_user_data_t
-{
- /** RX data. */
- int rx_data;
- /** TX data. */
- int tx_data;
-};
-typedef struct maximus_user_data_t maximus_user_data_t;
-
void maximus_ether_fill_hdr_test_case(test_t t)
{
-
+ printf("fill hdr\n");
+ test_case_begin(t, "fill hdr");
+
+ sci_msg_t msg;
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+ uint8_t type = ETHERNET_TYPE_DATA;
+
+ test_begin(t, "sci init")
+ {
+ memset(buffer, '\0', SCI_MSG_MAX_SIZE);
+ test_fail_unless ((0 == sci_msg_init(&msg, buffer, SCI_MSG_MAX_SIZE))
+ && (EINVAL != errno));
+ msg.length = 0;
+ } test_end;
+
+ test_begin(t, "fill hdr")
+ {
+ test_fail_unless ((0 == maximus_ether_fill_hdr(ctx, &msg, type))
+ && (EINVAL != errno)
+ && (ETHERNET_VERSION == msg.hdr.ether->version)
+ && (type == msg.hdr.ether->type)
+ && (0 == msg.hdr.ether->flags)
+ && (0 == msg.hdr.ether->reserved));
+ } test_end;
+
+ test_begin(t, "fill hdr with incorrect type")
+ {
+ type = ETHERNET_TYPE_NONE;
+
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((-1 == maximus_ether_fill_hdr(ctx, &msg, type))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("fill hdr with incorrect type\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
}
void maximus_ether_recv_test_case(test_t t)
{
-
+ sci_msg_t msg;
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+
+ printf("recv\n");
+ test_case_begin(t, "recv");
+
+ test_begin(t, "sci init")
+ {
+ memset(buffer, '\0', SCI_MSG_MAX_SIZE);
+ test_fail_unless ((0 == sci_msg_init(&msg, buffer, SCI_MSG_MAX_SIZE))
+ && (EINVAL != errno));
+ msg.length = 0;
+ } test_end;
+
+ test_begin(t, "NULL msg")
+ {
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_ether_recv(NULL, ctx)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("NULL msg\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+
+ test_begin(t, "NULL ipmbox")
+ {
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_ether_recv(&msg, NULL)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("NULL ipmbox\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+
+ test_begin(t, "recv")
+ {
+ // ether header
+ ether_msg_hdr_t ether_hdr;
+
+ // sci header
+ sci_msg_hdr_t sci_hdr;
+
+ // sci data
+ uint data_length = 1500;
+ u8 data[data_length];
+
+ // initialize sci data
+ memset(data, '\0', data_length);
+
+ // set ether header values
+ ether_hdr.version = ETHERNET_VERSION;
+ ether_hdr.type = ETHERNET_TYPE_NONE;
+ ether_hdr.flags = 0;
+ ether_hdr.reserved = 0;
+
+ // test ether type none
+ test_begin(t, "ether type none")
+ {
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_ether_recv(&msg, ctx)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("ether type none\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+
+ for (ether_hdr.type = ETHERNET_TYPE_DATA; ether_hdr.type < ETHERNET_TYPE_BUFFER_RELEASED; ether_hdr.type++)
+ {
+ /* Fill sci data. */
+
+ // ether type data or mme
+ if ((ETHERNET_TYPE_DATA == ether_hdr.type) || (ETHERNET_TYPE_MME == ether_hdr.type))
+ {
+ uint i;
+ for (i=0; i<data_length; i++)
+ {
+ data[i] = (u8)i;
+ }
+ test_fail_unless ((data_length == (uint)sci_msg_push(&msg, data_length))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, data, data_length);
+ }
+
+ // ether type data buffer add
+ else if (ETHERNET_TYPE_DATA_BUFFER_ADD == ether_hdr.type)
+ {
+ u32 buffer_nb = 1;
+ u32 buffer_id = 1;
+ test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &buffer_nb, sizeof(u32));
+ test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &buffer_id, sizeof(u32));
+ }
+
+ // ether type mme buffer add
+ else // ETHERNET_TYPE_MME_BUFFER_ADD
+ {
+ u32 buffer_nb = 10;
+ u32 buffer_id;
+ for (buffer_id = buffer_nb + 1; buffer_id > 1; buffer_id--)
+ {
+ test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &buffer_id, sizeof(u32));
+ }
+ test_fail_unless ((sizeof(u32) == (uint)sci_msg_push(&msg, sizeof(u32)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &buffer_nb, sizeof(u32));
+ }
+
+ // fill ether header
+ test_fail_unless ((sizeof(ether_msg_hdr_t) == sci_msg_push(&msg, sizeof(ether_msg_hdr_t)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &ether_hdr, sizeof(ether_msg_hdr_t));
+
+ // fill sci header
+ memcpy((u8 *)&sci_hdr.magic_id, SCI_MSG_MAGIC, 4);
+ sci_hdr.version = SCI_MSG_VERSION;
+ sci_hdr.type = SCI_MSG_TYPE_ETHERNET;
+ sci_hdr.flags = 0;
+ sci_hdr.station_id = my_station.id;
+ sci_hdr.length = msg.length - sizeof(sci_msg_hdr_t);
+ sci_hdr.msg_id = my_station.sci->current_msg_id | SCI_MSG_ID_STATION;
+ sci_hdr.netclock_high = my_station.current_tick_tck >> 32;
+ sci_hdr.netclock_low = my_station.current_tick_tck & 0xffffffff;
+ msg.sci_hdr = &sci_hdr;
+
+ test_fail_unless ((0 <= (maximus_ether_recv(&msg, ctx)))
+ && (EINVAL != errno)
+ && (EPROTO != errno));
+
+ test_fail_unless ((ether_hdr.version == msg.hdr.ether->version)
+ && (ether_hdr.type == msg.hdr.ether->type)
+ && (ether_hdr.flags == msg.hdr.ether->flags)
+ && (ether_hdr.reserved == msg.hdr.ether->reserved));
+
+ /* Check results. */
+
+ // test ether type data or mme
+ if ((ETHERNET_TYPE_DATA == ether_hdr.type) || (ETHERNET_TYPE_MME == ether_hdr.type))
+ {
+ u32 hdr = (HLE_MSG_TYPE_DATA << 24) | (1 << 20) | data_length; // ipmbox msg hdr
+ if (ETHERNET_TYPE_MME == ether_hdr.type)
+ {
+ hdr |= (1 << 11);
+ }
+
+ test_begin(t, "ether type data or mme")
+ {
+ test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
+ && (2 == ctx->rx.length)
+ && (ctx->rx.mailbox[0] == hdr)
+ && (0 == memcmp((u8 *)ctx->rx.mailbox[1], data, data_length)));
+ (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
+ maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+ } test_end;
+ }
+
+ // test ether type data buffer add
+ else if (ETHERNET_TYPE_DATA_BUFFER_ADD == ether_hdr.type)
+ {
+ test_begin(t, "ether type data buffer add")
+ {
+ u32 mailbox[2];
+ mailbox[0] = (HLE_MSG_TYPE_BUFFER_ADD << 24) | (1 << 20); // ipmbox msg hdr
+ mailbox[1] = (u32)ctx->last_buffer->data; // ipmbox msg data
+
+ test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
+ && (2 == ctx->rx.length)
+ && (0 == memcmp(ctx->rx.mailbox, mailbox, 2 * sizeof(u32)))
+ && (NULL == ctx->last_buffer->next)
+ && (1 == ctx->last_buffer->id)
+ && (NULL != ctx->last_buffer->data));
+ (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
+ maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+ } test_end;
+ }
+
+ // test ether type mme buffer add
+ else // ETHERNET_TYPE_MME_BUFFER_ADD
+ {
+ test_begin(t, "ether type mme buffer add")
+ {
+ uint i;
+ u32 mailbox[20];
+ u32 hdr = (HLE_MSG_TYPE_BUFFER_ADD << 24) | (1 << 20) | 1; // ipmbox msg hdr
+ maximus_hle_buffer_t *current_buffer = ctx->first_buffer->next->next;
+ for (i=0; i<20; i+=2)
+ {
+ mailbox[i] = hdr;
+ mailbox[i+1] = (u32)current_buffer->data; // ipmbox msg data
+ current_buffer = current_buffer->next;
+ }
+
+ // check mailbox contents
+ test_fail_unless ((maximus_pending_isrs & (1 << HAL_HLE_INTERRUPT_IPMBOX))
+ && (20 == ctx->rx.length)
+ && (0 == memcmp(ctx->rx.mailbox, mailbox, 20 * sizeof(u32))));
+
+ // check list of the 10 allocated buffers
+ current_buffer = ctx->first_buffer->next->next;
+ for (i=1; i<10; i++)
+ {
+ test_fail_unless ((NULL != current_buffer->next)
+ && (i+1 == current_buffer->id)
+ && (NULL != current_buffer->data));
+ current_buffer = current_buffer->next;
+ }
+ test_fail_unless ((NULL == current_buffer->next)
+ && (11 == current_buffer->id)
+ && (NULL != current_buffer->data));
+
+ // call rx_cb
+ (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
+ maximus_pending_isrs &= (0 << HAL_HLE_INTERRUPT_IPMBOX);
+ } test_end;
+
+ test_begin(t, "release allocated buffers")
+ {
+ maximus_hle_buffer_t *current_buffer = ctx->first_buffer->next;
+ maximus_hle_buffer_t *next_buffer = NULL;
+ uint buffer_nb = 0;
+ while (NULL != current_buffer)
+ {
+ next_buffer = current_buffer->next;
+ free(current_buffer->data);
+ free(current_buffer);
+ current_buffer = next_buffer;
+ buffer_nb++;
+ }
+ test_fail_unless (11 == buffer_nb);
+ } test_end;
+ }
+ }
+ } test_end;
+
+ // test ether type buffer released
+ test_begin(t, "ether type buffer released")
+ {
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_ether_recv(&msg, ctx)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("ether type buffer released\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+}
+
+void maximus_ether_send_test_case(test_t t)
+{
+ // ether type
+ u8 type = ETHERNET_TYPE_NONE;
+
+ // data
+ int data_length = 1500;
+ u8 data[1500];
+
+ // initialize data
+ memset(data, '\0', data_length);
+
+ printf("send\n");
+ test_case_begin(t, "send");
+
+ test_begin(t, "send null")
+ {
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_ether_send(ctx, type, 0, NULL)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("send null\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+
+ for (type = ETHERNET_TYPE_NONE; type < ETHERNET_TYPE_NB; type++)
+ {
+ // ether type none, data buffer add, or mme buffer add
+ if ((ETHERNET_TYPE_NONE == type)
+ || (ETHERNET_TYPE_DATA_BUFFER_ADD == type)
+ || (ETHERNET_TYPE_MME_BUFFER_ADD == type))
+ {
+ test_begin(t, "send invalid")
+ {
+ dbg_fatal_try_begin
+ {
+ test_fail_unless ((0 > (maximus_ether_send(ctx, type, data_length, (u32 *)data)))
+ && (EINVAL == errno));
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("send invalid\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+ }
+
+ // ether type data, mme, or buffer released
+ else if ((ETHERNET_TYPE_DATA == type)
+ || (ETHERNET_TYPE_MME == type)
+ || (ETHERNET_TYPE_BUFFER_RELEASED == type))
+ {
+ // ether type data or mme
+ if ((ETHERNET_TYPE_DATA == type) || (ETHERNET_TYPE_MME == type))
+ {
+ // set data
+ int i;
+ for (i=0; i<data_length; i++)
+ {
+ data[i] = (u8)i;
+ }
+ }
+
+ // ether type buffer release
+ else // ETHERNET_TYPE_BUFFER_RELEASE
+ {
+ // set data length and data
+ int i;
+ data_length = 4;
+ for (i=0; i<data_length; i++)
+ {
+ data[i] = i;
+ }
+ }
+
+ test_begin(t, "send ether")
+ {
+ test_fail_unless ((0 == maximus_ether_send(ctx, type, data_length, (u32 *)data))
+ && (EINVAL != errno));
+ } test_end;
+
+ /* Check results. */
+
+ // check that the correct ether message has been sent to Maximus
+ test_begin(t, "ether message")
+ {
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+ sci_msg_hdr_t *sci_hdr;
+ ether_msg_hdr_t *ether_hdr;
+ int fd_in = -1;
+
+ // open pipe
+ fd_in = open(my_station.pipe_out_name, O_RDONLY);
+
+ // read sci and ether headers
+ memset(buffer, '\0', SCI_MSG_MAX_SIZE);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, buffer, sizeof(sci_msg_hdr_t)))
+ && (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
+
+ // set sci and ether headers pointers
+ sci_hdr = (sci_msg_hdr_t *)buffer;
+ ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
+
+ // check ether header
+ test_fail_unless (type == ether_hdr->type);
+
+ // read the remaining part of message
+ test_fail_unless (data_length == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), data_length));
+
+ // check ether data
+ test_fail_unless (0 == memcmp(data, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), data_length));
+
+ // close pipe
+ close(fd_in);
+ } test_end;
+ }
+ }
}
void ether_test_suite(test_t t)
{
- maximus_user_data_t user_data = { 123456789, 987654321 };
+ int user_data = 1234567890;
// reset errno
errno = 0;
@@ -59,17 +506,15 @@ void ether_test_suite(test_t t)
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;
ctx = ipmbox_init ((void*)&user_data,
- &ipmbox_rx_cb,
- &ipmbox_tx_cb,
- &ipmbox_deferred_cb);
+ &ipmbox_rx_cb);
ctx->warning_assert = true;
test_suite_begin(t, "ether");
maximus_ether_fill_hdr_test_case(t);
maximus_ether_recv_test_case(t);
+ maximus_ether_send_test_case(t);
station_down (&my_station);
}
diff --git a/hal/hle/maximus/test/src/test_maximus_hle.c b/hal/hle/maximus/test/src/test_maximus_hle.c
index 8ef27812c0..2dc7e226fa 100644
--- a/hal/hle/maximus/test/src/test_maximus_hle.c
+++ b/hal/hle/maximus/test/src/test_maximus_hle.c
@@ -21,21 +21,11 @@ void ether_test_suite (test_t t);
uint32_t maximus_pending_isrs;
station_ctx_t my_station;
-bool
-ipmbox_rx_cb (u32 *first_msg, uint length, void *user_data)
-{
- return true;
-}
-
-bool
-ipmbox_tx_cb (void *user_data)
-{
- return true;
-}
-
void
-ipmbox_deferred_cb (void *user_data)
+ipmbox_rx_cb (void *user_data, u32 *first_msg, uint length)
{
+ int *my_data = (int *)user_data;
+ *my_data = 987654321;
return;
}
@@ -45,8 +35,8 @@ main (int argc, char **argv)
test_t t;
test_init(t, argc, argv);
- ipmbox_test_suite(t);
ether_test_suite(t);
+ ipmbox_test_suite(t);
test_result(t);
return test_nb_failed(t) == 0 ? 0 : 1;
diff --git a/hal/hle/maximus/test/src/test_maximus_ipmbox.c b/hal/hle/maximus/test/src/test_maximus_ipmbox.c
index 165438b7d6..f6d28485ff 100644
--- a/hal/hle/maximus/test/src/test_maximus_ipmbox.c
+++ b/hal/hle/maximus/test/src/test_maximus_ipmbox.c
@@ -14,13 +14,17 @@
#include "common/std.h"
#include "lib/test.h"
#include "hal/hle/maximus/test/inc/test_maximus_hle.h"
+#include "hal/hle/maximus/inc/maximus_ipmbox_ctx.h" // for 'ipmbox_t'
#include "hal/hle/ipmbox.h"
-#include "hal/hle/forward.h" // for 'ipmbox_t'
+#include "hal/hle/defs.h" // for 'HLE_MSG_TYPE_...'
#include "host/station.h" // for 'station_ctx_t'
+#include "host/fwd.h" // for 'sci_msg_t'
+#include "maximus/common/types/ethernet_types.h" // for 'ether_msg_hdr_t'
#include <stdio.h> // for 'printf'
#include <string.h> // for 'memset'
#include <unistd.h> // for 'read'
#include <fcntl.h> // for 'read'
+#include <stdlib.h> // for 'malloc'
#include <errno.h>
extern uint32_t maximus_pending_isrs; // used in 'station.c'
@@ -29,12 +33,241 @@ ipmbox_t *ctx;
void ipmbox_init_test_case(test_t t)
{
-
+ int user_data = 123456789;
+
+ printf("init\n");
+ test_case_begin(t, "init");
+
+ test_begin(t, "init")
+ {
+ ctx = ipmbox_init ((void *)&user_data, &ipmbox_rx_cb);
+ test_fail_unless ((EINVAL != errno)
+ && (NULL != ctx)
+ && (user_data == *((int *)ctx->user_data))
+ && (&ipmbox_rx_cb == ctx->rx_cb)
+ && (NULL != ctx->first_buffer)
+ && (NULL == ctx->first_buffer->next)
+ && (0 == ctx->first_buffer->id)
+ && (NULL == ctx->first_buffer->data)
+ && (ctx->last_buffer == ctx->first_buffer));
+ ctx->warning_assert = true;
+ } test_end;
+
+ test_begin(t, "rx cb")
+ {
+ (*ctx->rx_cb)(ctx->user_data, ctx->rx.mailbox, ctx->rx.length);
+ test_fail_unless (987654321 == *((int *)ctx->user_data));
+ } test_end;
+
+ maximus_pending_isrs = 0;
+
+ return;
}
void ipmbox_tx_test_case(test_t t)
{
-
+ // ethernet frame data
+ int frame_length = 1200;
+ u8 frame[1200];
+ memset(frame, '\0', frame_length); // init frame
+
+ // mailbox msg
+ ipmbox_msg_hdr_t hdr;
+ u32 mailbox[2];
+ uint length = 2; // init length
+ hdr.type = HLE_MSG_TYPE_NONE; // init hdr type
+ hdr.length = 1; // init hdr length
+ hdr.param = 0; // init hdr param
+ memset(mailbox, '\0', length * sizeof(u32)); // init mailbox
+
+ printf("tx\n");
+ test_case_begin(t, "tx");
+
+ test_begin(t, "tx none")
+ {
+ dbg_fatal_try_begin
+ {
+ // set mailbox
+ memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
+
+ ipmbox_tx(ctx, mailbox, length);
+ test_fail_unless (EINVAL == errno);
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("tx none\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+
+ for (hdr.type = HLE_MSG_TYPE_DATA; hdr.type < HLE_MSG_TYPE_NB; hdr.type++)
+ {
+ /* Fill sci data. */
+
+ // hle type data
+ if (HLE_MSG_TYPE_DATA == hdr.type)
+ {
+ // set hdr param
+ hdr.param = frame_length;
+
+ // set mailbox
+ memcpy(&mailbox[0], &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
+ mailbox[1] = (u32)frame; // set data
+
+ test_begin(t, "tx data")
+ {
+ ipmbox_tx(ctx, mailbox, length);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+ }
+
+ // hle type buffer add
+ else if (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
+ {
+ // set mailbox
+ memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
+
+ test_begin(t, "tx buffer add")
+ {
+ dbg_fatal_try_begin
+ {
+ // set mailbox
+ memcpy(mailbox, &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
+
+ ipmbox_tx(ctx, mailbox, length);
+ test_fail_unless (EINVAL == errno);
+ }
+ dbg_fatal_try_catch (const char *fatal_message)
+ {
+ printf("tx buffer add\n%s\n", fatal_message);
+ }
+ dbg_fatal_try_end;
+
+ // reset errno
+ errno = 0;
+ } test_end;
+ }
+
+ // hle type send done
+ else // HLE_TYPE_SEND_DONE
+ {
+ maximus_hle_buffer_t *second_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
+ maximus_hle_buffer_t *last_buffer = (maximus_hle_buffer_t *)malloc(sizeof(maximus_hle_buffer_t));
+ last_buffer->next = NULL;
+ last_buffer->id = 100;
+ last_buffer->data = (u32 *)malloc(frame_length);
+ second_buffer->next = last_buffer;
+ second_buffer->id = 32;
+ second_buffer->data = (u32 *)malloc(frame_length);
+ ctx->first_buffer->next = second_buffer;
+
+ // set hdr param
+ hdr.param = 0;
+
+ // set mailbox
+ memcpy(&mailbox[0], &hdr, sizeof(ipmbox_msg_hdr_t)); // set first msg
+ mailbox[1] = (u32)second_buffer->data; // set data
+
+ test_begin(t, "tx send done")
+ {
+ ipmbox_tx(ctx, mailbox, length);
+ test_fail_unless (EINVAL != errno);
+ } test_end;
+
+ test_begin(t, "release allocated buffers")
+ {
+ maximus_hle_buffer_t *current_buffer = ctx->first_buffer->next;
+ maximus_hle_buffer_t *next_buffer = NULL;
+ uint buffer_nb = 0;
+ while (NULL != current_buffer)
+ {
+ next_buffer = current_buffer->next;
+ free(current_buffer->data);
+ free(current_buffer);
+ current_buffer = next_buffer;
+ buffer_nb++;
+ }
+ test_fail_unless (1 == buffer_nb);
+ } test_end;
+ }
+
+ /* Check results. */
+
+ // hle type data
+ if ((HLE_MSG_TYPE_DATA == hdr.type) || (HLE_MSG_TYPE_SEND_DONE == hdr.type))
+ {
+ // check that the correct ether message has been sent to Maximus
+ test_begin(t, "ether message")
+ {
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+ sci_msg_hdr_t *sci_hdr;
+ ether_msg_hdr_t *ether_hdr;
+ int fd_in = -1;
+
+ // open pipe
+ fd_in = open(my_station.pipe_out_name, O_RDONLY);
+
+ // read sci and ether headers
+ memset(buffer, '\0', SCI_MSG_MAX_SIZE);
+ test_fail_unless ((-1 != fd_in)
+ && (sizeof(sci_msg_hdr_t) == read(fd_in, buffer, sizeof(sci_msg_hdr_t)))
+ && (sizeof(ether_msg_hdr_t) == read(fd_in, buffer + sizeof(sci_msg_hdr_t), sizeof(ether_msg_hdr_t))));
+
+ // set sci and ether headers pointers
+ sci_hdr = (sci_msg_hdr_t *)buffer;
+ ether_hdr = (ether_msg_hdr_t *)(buffer + sizeof(sci_msg_hdr_t));
+
+ // test hle type data
+ if (HLE_MSG_TYPE_DATA == hdr.type)
+ {
+ // check ether header
+ test_fail_unless (ETHERNET_TYPE_DATA == ether_hdr->type);
+
+ // read the remaining part of message
+ test_fail_unless (frame_length == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
+
+ // check ether data
+ test_fail_unless (0 == memcmp(frame, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), frame_length));
+ }
+
+ // test hle type send done
+ else // HLE_MSG_TYPE_SEND_DONE
+ {
+ // check ether header
+ test_fail_unless (ETHERNET_TYPE_BUFFER_RELEASED == ether_hdr->type);
+
+ // read the remaining part of message
+ test_fail_unless (sizeof(u32) == read(fd_in, buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t), sizeof(u32)));
+
+ // check ether data
+ test_fail_unless (32 == *(buffer + sizeof(sci_msg_hdr_t) + sizeof(ether_msg_hdr_t)));
+ }
+ // close pipe
+ close(fd_in);
+ } test_end;
+ }
+
+ // hle type buffer add
+ else if (HLE_MSG_TYPE_BUFFER_ADD == hdr.type)
+ {
+ test_begin(t, "tx buffer add")
+ {
+
+ } test_end;
+ }
+
+ // hle type send done
+ else // HLE_MSG_TYPE_SEND_DONE
+ {
+ test_begin(t, "tx send done")
+ {
+
+ } test_end;
+ }
+ }
}
void ipmbox_test_suite(test_t t)
@@ -45,7 +278,6 @@ void ipmbox_test_suite(test_t t)
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, "ipmbox");
ipmbox_init_test_case(t);