summaryrefslogtreecommitdiff
path: root/hal/phy/maximus/test/src/test_phy_ctrl.c
diff options
context:
space:
mode:
Diffstat (limited to 'hal/phy/maximus/test/src/test_phy_ctrl.c')
-rw-r--r--hal/phy/maximus/test/src/test_phy_ctrl.c176
1 files changed, 154 insertions, 22 deletions
diff --git a/hal/phy/maximus/test/src/test_phy_ctrl.c b/hal/phy/maximus/test/src/test_phy_ctrl.c
index d17d7ef3a5..cf9ca6dc7b 100644
--- a/hal/phy/maximus/test/src/test_phy_ctrl.c
+++ b/hal/phy/maximus/test/src/test_phy_ctrl.c
@@ -18,6 +18,8 @@
#include "hal/phy/maximus/test/inc/test_phy_maximus.h"
#include "host/station.h"
#include "host/sci.h"
+#include "maximus/common/types/phy_types.h"
+#include "host/fwd.h" // for 'phy_msg_hdr_t'
#include <stdio.h> // for 'printf'
#include <string.h> // for 'memset'
#include <netinet/in.h> // for 'ntohl' and 'ntohs' functions
@@ -26,9 +28,129 @@
#include <errno.h>
uint32_t maximus_pending_isrs; // used in 'station.c'
-extern station_ctx_t my_station;
phy_t *ctx;
+void maximus_phy_fill_hdr_test_case(test_t t)
+{
+ test_case_begin(t, "fill hdr");
+
+ test_begin(t, "fill hdr")
+ {
+ sci_msg_t msg;
+ uint8_t type = PHY_TYPE_MPDU_PAYLOAD;
+ uint8_t mpdu_format = PHY_MPDU_FORMAT_SOF;
+ uint8_t pb_nb = 3;
+ uint8_t tonemap_index = 0;
+ uint8_t flags = 0x06;
+ uint32_t nek[4];
+ uint32_t pb_measurement[PHY_PB_MAX_NB];
+ uint32_t pb_header[PHY_PB_MAX_NB];
+
+ memset(nek, '\0', 4*sizeof(uint32_t));
+ memset(pb_measurement, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
+ memset(pb_header, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
+
+ test_fail_unless ((0 == maximus_phy_fill_hdr(ctx,
+ &msg,
+ type,
+ mpdu_format,
+ pb_nb,
+ tonemap_index,
+ flags,
+ nek,
+ pb_measurement,
+ pb_header))
+ && (PHY_VERSION == msg.hdr.phy->version)
+ && (PHY_VERSION == msg.hdr.phy->type)
+ && (PHY_VERSION == msg.hdr.phy->mpdu_format)
+ && (PHY_VERSION == msg.hdr.phy->pb_nb)
+ && (PHY_VERSION == msg.hdr.phy->tonemap_index)
+ && (PHY_VERSION == msg.hdr.phy->flags)
+ && (0 == memcmp (nek, msg.hdr.phy->nek, 4*sizeof(uint32_t)))
+ && (0 == memcmp (pb_measurement, msg.hdr.phy->pb_measurement, PHY_PB_MAX_NB*sizeof(uint32_t)))
+ && (0 == memcmp (pb_header, msg.hdr.phy->pb_header, PHY_PB_MAX_NB*sizeof(uint32_t)))
+ && (EINVAL != errno));
+ } test_end;
+}
+
+void maximus_phy_recv_test_case(test_t t)
+{
+ sci_msg_t msg;
+ unsigned char buffer[SCI_MSG_MAX_SIZE];
+ uint32_t nek[4];
+ uint32_t pb_measurement[PHY_PB_MAX_NB];
+ uint32_t pb_header[PHY_PB_MAX_NB];
+ //sci_msg_hdr_t hdr;
+ phy_msg_hdr_t phy_hdr;
+
+ 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));
+ } test_end;
+
+ test_begin(t, "NULL msg")
+ {
+ test_fail_unless ((0 > (maximus_phy_recv(NULL, ctx)))
+ && (EINVAL == errno));
+ } test_end;
+
+ test_begin(t, "NULL phy")
+ {
+ test_fail_unless ((0 > (maximus_phy_recv(&msg, NULL)))
+ && (EINVAL == errno));
+ } test_end;
+
+ test_begin(t, "recv")
+ {
+ memset(nek, '\0', 4*sizeof(uint32_t));
+ memset(pb_measurement, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
+ memset(pb_header, '\0', PHY_PB_MAX_NB*sizeof(uint32_t));
+
+ // fill the phy header
+ phy_hdr.version = PHY_VERSION;
+ phy_hdr.type = PHY_TYPE_MPDU_PAYLOAD;
+ phy_hdr.mpdu_format = PHY_MPDU_FORMAT_BEACON;
+ phy_hdr.pb_nb = 3;
+ phy_hdr.tonemap_index = 0;
+ phy_hdr.flags = 0x06;
+ phy_hdr.reserved = 0;
+ memcpy(phy_hdr.nek, nek, 4*sizeof(uint32_t));
+ memcpy(phy_hdr.pb_measurement, pb_measurement, PHY_PB_MAX_NB*sizeof(uint32_t));
+ memcpy(phy_hdr.pb_header, pb_header, PHY_PB_MAX_NB*sizeof(uint32_t));
+
+ // fill the sci header
+ test_fail_unless (0 == sci_fill_hdr(ctx->control.station->sci, &msg, SCI_MSG_TYPE_PHY, 0));
+
+ // fill the sci data
+ test_fail_unless ((sizeof(phy_msg_hdr_t) == sci_msg_push(&msg, sizeof(phy_msg_hdr_t)))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, &phy_hdr, sizeof(phy_msg_hdr_t));
+ test_fail_unless ((512*phy_hdr.pb_nb == sci_msg_push(&msg, 512*phy_hdr.pb_nb))
+ && (EINVAL != errno)
+ && (ENOSPC != errno));
+ memcpy(msg.data_begin, buffer, 512*phy_hdr.pb_nb);
+
+ test_fail_unless ((0 <= (maximus_phy_recv(&msg, ctx)))
+ && (EINVAL != errno));
+
+ test_fail_unless ((phy_hdr.version == msg.hdr.phy->version)
+ && (phy_hdr.type == msg.hdr.phy->type)
+ && (phy_hdr.mpdu_format == msg.hdr.phy->mpdu_format)
+ && (phy_hdr.pb_nb == msg.hdr.phy->pb_nb)
+ && (phy_hdr.tonemap_index == msg.hdr.phy->tonemap_index)
+ && (phy_hdr.flags == msg.hdr.phy->flags)
+ && (phy_hdr.reserved == msg.hdr.phy->reserved)
+ && (0 == memcmp (phy_hdr.nek, msg.hdr.phy->nek, 4*sizeof(uint32_t)))
+ && (0 == memcmp (phy_hdr.pb_measurement, msg.hdr.phy->pb_measurement, PHY_PB_MAX_NB*sizeof(uint32_t)))
+ && (0 == memcmp (phy_hdr.pb_header, msg.hdr.phy->pb_header, PHY_PB_MAX_NB*sizeof(uint32_t)))
+ && (EINVAL != errno));
+ } test_end;
+}
+
void phy_init_test_case(test_t t)
{
int user_data = 1234567890;
@@ -55,10 +177,15 @@ void phy_init_test_case(test_t t)
test_begin(t, "rx fc cb")
{
- test_fail_unless ((*ctx->control.rx_fc_cb)(ctx->control.user_data, ctx->control.current_date, ctx->control.fc_av));
+ test_fail_unless ((NULL != ctx->control.rx_fc_cb)
+ && ((*ctx->control.rx_fc_cb)(ctx->control.user_data, ctx->control.current_date, ctx->control.fc_av)));
} test_end;
- (*ctx->control.deferred_cb)(ctx->control.user_data);
+ test_begin(t, "deferred cb")
+ {
+ test_fail_unless (NULL != ctx->control.deferred_cb);
+ (*ctx->control.deferred_cb)(ctx->control.user_data);
+ } test_end;
return;
}
@@ -107,9 +234,9 @@ void phy_date_test_case(test_t t)
{
ctx->control.current_date = 5;
}
- test_fail_unless ((EINVAL != errno)
- && (NULL != ctx)
- && (ctx->control.current_date == phy_date(ctx)));
+ test_fail_unless ((NULL != ctx)
+ && (ctx->control.current_date == phy_date(ctx))
+ && (EINVAL != errno));
} test_end;
return;
@@ -166,14 +293,14 @@ void phy_tx_frame_test_case(test_t t)
int fd_in = -1;
// open pipe
- fd_in = open(my_station.pipe_out_name, O_RDONLY);
+ fd_in = open(ctx->control.station->pipe_out_name, O_RDONLY);
// read sci header
test_fail_unless ((-1 != fd_in)
&& ((int)sizeof(sci_msg_hdr_t) == read(fd_in, &sci_hdr, sizeof(sci_msg_hdr_t))));
// read netclock header
- test_fail_unless((int)sizeof(netclock_msg_hdr_t) == read(fd_in, &netclock_hdr, sizeof(netclock_msg_hdr_t)));
+ test_fail_unless ((int)sizeof(netclock_msg_hdr_t) == read(fd_in, &netclock_hdr, sizeof(netclock_msg_hdr_t)));
// check netclock tick value
test_fail_unless (date == ntohl(netclock_hdr.tick_low));
@@ -183,7 +310,7 @@ void phy_tx_frame_test_case(test_t t)
| (unsigned long long)(ntohl(sci_hdr.netclock_low));
// update current tick value
- my_station.current_tick_tck = msg_tick_tck;
+ ctx->control.station->current_tick_tck = msg_tick_tck;
// close pipe
close(fd_in);
@@ -204,7 +331,8 @@ void phy_tx_frame_test_case(test_t t)
test_begin(t, "access conf cb")
{
- test_fail_unless ((*ctx->control.access_conf_cb)(ctx->control.user_data));
+ test_fail_unless ((NULL != ctx->control.access_conf_cb)
+ && ((*ctx->control.access_conf_cb)(ctx->control.user_data)));
} test_end;
// check that the correct phy message has been sent to Maximus
@@ -216,7 +344,7 @@ void phy_tx_frame_test_case(test_t t)
int fd_in = -1;
// open pipe
- fd_in = open(my_station.pipe_out_name, O_RDONLY);
+ fd_in = open(ctx->control.station->pipe_out_name, O_RDONLY);
// read sci header
test_fail_unless ((-1 != fd_in)
@@ -241,7 +369,7 @@ void phy_tx_frame_test_case(test_t t)
| (unsigned long long)(ntohl(sci_hdr.netclock_low));
// update current tick value
- my_station.current_tick_tck = msg_tick_tck;
+ ctx->control.station->current_tick_tck = msg_tick_tck;
// close pipe
close(fd_in);
@@ -259,7 +387,7 @@ void phy_tx_frame_test_case(test_t t)
int fd_in = -1;
// open pipe
- fd_in = open(my_station.pipe_out_name, O_RDONLY);
+ fd_in = open(ctx->control.station->pipe_out_name, O_RDONLY);
// read sci header
test_fail_unless ((-1 != fd_in)
@@ -276,7 +404,7 @@ void phy_tx_frame_test_case(test_t t)
| (unsigned long long)(ntohl(sci_hdr.netclock_low));
// update current tick value
- my_station.current_tick_tck = msg_tick_tck;
+ ctx->control.station->current_tick_tck = msg_tick_tck;
// close pipe
close(fd_in);
@@ -304,7 +432,7 @@ void phy_tx_frame_test_case(test_t t)
int fd_in = -1;
// open pipe
- fd_in = open(my_station.pipe_out_name, O_RDONLY);
+ fd_in = open(ctx->control.station->pipe_out_name, O_RDONLY);
// read sci header
test_fail_unless ((-1 != fd_in)
@@ -329,7 +457,7 @@ void phy_tx_frame_test_case(test_t t)
| (unsigned long long)(ntohl(sci_hdr.netclock_low));
// update current tick value
- my_station.current_tick_tck = msg_tick_tck;
+ ctx->control.station->current_tick_tck = msg_tick_tck;
// close pipe
close(fd_in);
@@ -348,7 +476,7 @@ void phy_clock_set_test_case(test_t t)
phy_clock_set (phy_clock);
test_fail_unless ((EINVAL != errno)
- &&(phy_clock == my_station.current_tick_tck));
+ &&(phy_clock == ctx->control.station->current_tick_tck));
} test_end;
return;
@@ -371,7 +499,7 @@ void phy_rx_activate_test_case(test_t t)
int fd_in = -1;
// open pipe
- fd_in = open(my_station.pipe_out_name, O_RDONLY);
+ fd_in = open(ctx->control.station->pipe_out_name, O_RDONLY);
// read sci header and netclock header
memset(data, '\0', 256);
@@ -428,16 +556,20 @@ void phy_ctrl_test_suite(test_t t)
{
unsigned char buffer[1024];
int fd_out = -1;
+ station_ctx_t station;
- station_init(&my_station);
+ station_init (&station);
+ sci_init(station.sci, &station);
// TO REMOVE
memset(buffer, 'a', 1024);
- fd_out = open(my_station.pipe_out_name, O_WRONLY);
+ fd_out = open(station.pipe_out_name, O_WRONLY);
write(fd_out, buffer, 1024);
- close(fd_out);
+ close(fd_out);
test_suite_begin(t, "phy control");
+ maximus_phy_fill_hdr_test_case(t);
+ maximus_phy_recv_test_case(t);
phy_init_test_case(t);
phy_date_test_case(t);
phy_tx_fc10_test_case(t);
@@ -448,5 +580,5 @@ void phy_ctrl_test_suite(test_t t)
phy_reset_test_case(t);
phy_uninit_test_case(t);
- station_down (&my_station);
+ station_down (&station);
}