summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorCeline Buret2012-01-13 16:27:58 +0100
committerCeline Buret2012-04-12 14:26:53 +0200
commite50c8cfc7de9e375c8d0ce4a1820860a52cb1e8f (patch)
tree5d1e21c3b5a63e0d8a43cd7dacfb726ad0355c2b /cesar
parentea8a5d730db3d1e20b35d20e7163f1427831e564 (diff)
cesar/{host,maximus}: warn user if log is truncated, refs #43
Until now, log was truncated silently if its length reached the max log length. With this commit, user is informed when the station log is too big and truncated.
Diffstat (limited to 'cesar')
-rw-r--r--cesar/host/station/src/station.c12
-rw-r--r--cesar/host/station/station.h1
-rw-r--r--cesar/maximus/python/py/test_log.py45
-rw-r--r--cesar/maximus/stationtest/Makefile10
-rw-r--r--cesar/maximus/stationtest/src/test_log.c193
-rwxr-xr-xcesar/maximus/test/test_python.sh1
6 files changed, 255 insertions, 7 deletions
diff --git a/cesar/host/station/src/station.c b/cesar/host/station/src/station.c
index dab17adb1a..f645eab1fe 100644
--- a/cesar/host/station/src/station.c
+++ b/cesar/host/station/src/station.c
@@ -36,6 +36,8 @@
#include <sys/un.h>
#endif
+#define STATION_BUFFER_SIZE (STATION_MAX_LOG_SIZE + 2)
+
/* awfull, but needed */
static sci_ctx_t _my_sci;
static netclock_ctx_t _my_netclock;
@@ -454,8 +456,8 @@ int station_log_set_level(station_ctx_t *station, station_log_level_t level)
...)
{
va_list va_args;
- int hdr_len;
- static char buffer[STATION_MAX_LOG_SIZE];
+ int hdr_len, ret = 0;
+ static char buffer[STATION_BUFFER_SIZE];
if((station == NULL)
|| (station->status == STATION_STATUS_INIT)
@@ -500,13 +502,15 @@ int station_log_set_level(station_ctx_t *station, station_log_level_t level)
write(station->pipe_log_fd, buffer, hdr_len);
/* build body and send it */
- buffer[STATION_MAX_LOG_SIZE - 1] = '\0';
+ buffer[STATION_BUFFER_SIZE - 1] = '\0';
va_start(va_args, format);
- vsnprintf(buffer, STATION_MAX_LOG_SIZE - 1, format, va_args);
+ ret = vsnprintf (buffer, STATION_BUFFER_SIZE - 1, format, va_args);
va_end (va_args);
write(station->pipe_log_fd, buffer, strlen(buffer));
/* send CR */
+ if (ret == STATION_MAX_LOG_SIZE)
+ write (station->pipe_log_fd, STATION_MAX_LOG_MSG, strlen (STATION_MAX_LOG_MSG));
write(station->pipe_log_fd, "\n", 1);
return;
diff --git a/cesar/host/station/station.h b/cesar/host/station/station.h
index 8f5c54999c..774caf8c2e 100644
--- a/cesar/host/station/station.h
+++ b/cesar/host/station/station.h
@@ -33,6 +33,7 @@
#define STATION_SOCK_PATH STATION_PIPE_PATH
#define STATION_SOCK_PREFIX STATION_PIPE_PREFIX
#define STATION_MAX_LOG_SIZE 4096
+#define STATION_MAX_LOG_MSG " [...] <WARNING> Log exceeds max size"
#define STATION_MAX_SOCK_BUFFER_SIZE (256*1024)
#define STATION_MAX_FD 16
diff --git a/cesar/maximus/python/py/test_log.py b/cesar/maximus/python/py/test_log.py
new file mode 100644
index 0000000000..4848256600
--- /dev/null
+++ b/cesar/maximus/python/py/test_log.py
@@ -0,0 +1,45 @@
+#! usr/bin/env python
+
+import sys, unittest
+
+# for maximus package
+sys.path.append('../python')
+sys.path.append('../../python')
+
+# for interface module
+sys.path.append('./obj')
+sys.path.append('../obj')
+
+from maximus.station import *
+from interface import *
+
+
+# Create a Maximus instance
+m = Maximus ()
+
+# Initialize Maximus with command line arguments
+m.init (sys.argv)
+
+class TestSTAFunctions (unittest.TestCase):
+
+ def setUp (self):
+ # Create station
+ self.station = STA (m, debug=False, config=Config (default_config=False))
+
+ def tearDown (self):
+ # Remove station
+ m.create_fcall ("uninit_ether").send (self.station.get ())
+ self.station.remove ()
+
+ def testLog (self):
+ m.wait (1000000)
+ m.create_fcall ("test_log").send (self.station.get ())
+
+suite = unittest.TestLoader ().loadTestsFromTestCase (TestSTAFunctions)
+
+if __name__ == '__main__':
+ testResult = unittest.TextTestRunner (verbosity=2).run (suite)
+ # Stop Maximus
+ m.uninit ()
+ # For nightly build errors
+ sys.exit ((1, 0)[testResult.wasSuccessful ()])
diff --git a/cesar/maximus/stationtest/Makefile b/cesar/maximus/stationtest/Makefile
index acc4d499f4..40f2f39c5f 100644
--- a/cesar/maximus/stationtest/Makefile
+++ b/cesar/maximus/stationtest/Makefile
@@ -2,9 +2,9 @@ BASE = ../..
ECOS = y
-TARGET_PROGRAMS = exception hello_world one_thread threaddelay \
- stationtest \
- test_cb test_ether test_false_alarm test_lib_cesar test_send test_station test_tx_rx
+TARGET_PROGRAMS = exception hello_world one_thread threaddelay stationtest \
+ test_cb test_ether test_false_alarm test_lib_cesar test_send test_station \
+ test_tx_rx test_log
exception_SOURCES = exception.c
exception_MODULES = lib host
@@ -45,4 +45,8 @@ test_station_MODULES = lib host hal/ipmbox/maximus hal/phy/maximus/dur/maximus
test_tx_rx_SOURCES = test_tx_rx.c
test_tx_rx_MODULES = lib host hal/phy/maximus
+cp_beacon_MODULE_SOURCES = beacons.c bentry.c
+test_log_SOURCES = test_log.c
+test_log_MODULES = lib host hal/ipmbox/maximus hal/phy/maximus/dur/maximus
+
include $(BASE)/common/make/top.mk
diff --git a/cesar/maximus/stationtest/src/test_log.c b/cesar/maximus/stationtest/src/test_log.c
new file mode 100644
index 0000000000..1329144d9f
--- /dev/null
+++ b/cesar/maximus/stationtest/src/test_log.c
@@ -0,0 +1,193 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file test_station.c
+ * \brief station executable used for the test station program
+ * \ingroup
+ */
+
+#include "common/std.h"
+#include "common/defs/homeplugAV.h"
+#include "host/station/station.h" /* for 'station_ctx_t' */
+#include "hal/ipmbox/ipmbox.h"
+#include "hal/ipmbox/maximus/inc/maximus_ipmbox_ctx.h" /* for 'ipmbox_t' */
+#include "hal/ipmbox/maximus/inc/maximus_interrupts.h" /* for
+ 'HAL_IPMBOX_..._INTERRUPT' */
+#include "maximus/common/types/ethernet_types.h" /* for 'ETHERNET_TYPE_...' */
+#include "common/ipmbox/msg.h"
+#include <cyg/infra/diag.h>
+#include <stdio.h>
+
+#define RESULT_SUCCESS 0x00
+#define CM_SET_KEY_REQ_MMTYPE 0x6008
+
+/* DRV_STA_....CNF MMENTRY only contains 1 byte: Result */
+#define DRV_STA_CNF_LEN (HPAV_MME_HEADER + 1)
+
+/* CM_SET_KEY.CNF MMENTRY contains:
+ - 1 byte: Result
+ - 4 bytes: My Nonce
+ - 4 bytes: Your Nonce
+ - 1 byte: PID
+ - 2 bytes: PRN
+ - 1 byte: PMN
+ - 1 byte: CCo Capability
+ => 14 bytes in total */
+#define CM_SET_KEY_CNF_LEN (HPAV_MME_HEADER + 14)
+
+extern station_ctx_t my_station;
+ipmbox_t *ctx;
+int user_data = 123;
+
+void
+rx_cb_mbx (void *user_data, u32 *first_msg, uint length)
+{
+ /* Reset IT. */
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ ipmbox_msg_mbx_t *msg_mbx = (ipmbox_msg_mbx_t *) ctx->rx_mbx.mailbox;
+
+ /* When receiving an Ether SCI message of type MME REQ from Maximus,
+ * send the answer (an Ether SCI message of type MME CNF)
+ * with an Ether SCI message of type BUFFER_RELEASED. */
+
+ /* REQ data length. */
+ uint data_length = ipmbox_msg_get_mme_priv_length (msg_mbx->header);
+
+ /* REQ data. */
+ u32 buffer_addr;
+ if (1 != ipmbox_empty_buf_get (ctx, &buffer_addr, 1))
+ {
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: cannot get empty buf", __FUNCTION__);
+ }
+ memcpy ((u32 *) buffer_addr, (u32 *) msg_mbx->buffer_addr, data_length);
+
+ /* CNF data. */
+ char *cnf_data = (char *) buffer_addr;
+ /* REQ => CNF */
+ *(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME)) =
+ *(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME)) + 1;
+ *(cnf_data + HPAV_MME_HEADER) = RESULT_SUCCESS;
+
+ /* CNF data length. */
+ uint cnf_data_length = 0;
+ u16 mmtype = (
+ (u16) (*(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME) + 1) << 8)
+ | (u16) (*(cnf_data + HPAV_GET_MMTYPE_OFFSET (HPAV_MTYPE_MME))));
+ if (CM_SET_KEY_REQ_MMTYPE == mmtype)
+ {
+ cnf_data_length = CM_SET_KEY_CNF_LEN;
+ }
+ else /* mmtype = DRV_STA_....REQ */
+ {
+ cnf_data_length = DRV_STA_CNF_LEN;
+ }
+
+ /* Tx. */
+ msg_mbx->header = ipmbox_msg_create_header_mme_priv (cnf_data_length);
+ msg_mbx->buffer_addr = buffer_addr;
+ ipmbox_tx_mbx (ctx, (u32 *) msg_mbx, 2);
+
+ return;
+}
+
+void
+rx_cb_data (void *user_data, u32 *first_msg, uint length)
+{
+ /* Reset IT. */
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_RX_INTERRUPT);
+
+ /* In this test, we should not receive an Ether SCI message of type DATA
+ * from Maximus. */
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_ETHER,
+ "%s: rx cb data should not be called", __FUNCTION__);
+
+ return;
+}
+
+void
+empty_buf_cb (void *user_data)
+{
+ /* Reset IT. */
+ maximus_pending_isrs &= ~(1 << HAL_IPMBOX_BUF_INTERRUPT);
+
+ /* When receiving an Ether SCI message of type BUFFER_ADD from Maximus,
+ * do nothing: just keep the allocated buffer for future Tx DATA / MME. */
+}
+
+int
+uninit_ether (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg,
+ void *data)
+{
+ /* Uninitialize the HAL ipmbox. */
+ ipmbox_uninit (ctx);
+
+ /* Now make the return parameter list. */
+ fcall_param_reset (*param);
+
+ return 0;
+}
+
+#define MIN_LEN 2
+#define MAX_LEN STATION_MAX_LOG_SIZE
+#define BIG_LEN (STATION_MAX_LOG_SIZE + 1)
+
+int test_log (fcall_ctx_t *fcall, fcall_param_t **param, sci_msg_t **msg,
+ void *data)
+{
+ char min[MIN_LEN];
+ memset (min, 'm', MIN_LEN - 1);
+ min[MIN_LEN - 1]='\0';
+
+ char max[MAX_LEN];
+ memset (max, 'm', MAX_LEN - 1);
+ min[MAX_LEN - 1]='\0';
+
+ char big[BIG_LEN];
+ memset (big, 'b', BIG_LEN - 1);
+ big[BIG_LEN - 1]='\0';
+
+ station_log_set_level(&my_station, STATION_LOG_WARNING);
+ station_log_set_mask(&my_station, STATION_LOGTYPE_ALL);
+ my_station.pipe_log_fd = 1;
+
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_STATION,
+ "%s", min);
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_STATION,
+ "%s", max);
+ station_log (&my_station, STATION_LOG_ERROR, STATION_LOGTYPE_STATION,
+ "%s", big);
+
+ /* now make the return parameter list */
+ fcall_param_reset(*param);
+
+ return 0;
+}
+
+int main (void)
+{
+ /* Initialize the HAL ipmbox. */
+ ctx = ipmbox_init ();
+ ipmbox_register_rx_data_cb (ctx, (void *) &user_data, &rx_cb_data);
+ ipmbox_register_rx_mbx_cb (ctx, (void *) &user_data, &rx_cb_mbx);
+ ipmbox_register_empty_buf_cb (ctx, (void *) &user_data,
+ &empty_buf_cb);
+
+ /* Enable assertions on warnings. */
+ ctx->warning_assert = true;
+
+ /* Activate ipmbox interruptions. */
+ ipmbox_activate (ctx, true);
+
+ fcall_register (my_station.fcall, "uninit_ether", (void*) &uninit_ether,
+ NULL);
+ fcall_register(my_station.fcall, "test_log", (void*) &test_log, NULL);
+
+ return 0;
+}
diff --git a/cesar/maximus/test/test_python.sh b/cesar/maximus/test/test_python.sh
index 256bee84af..cab314c83f 100755
--- a/cesar/maximus/test/test_python.sh
+++ b/cesar/maximus/test/test_python.sh
@@ -34,3 +34,4 @@ python py/test_false_alarm.py -e ../stationtest/obj/test_false_alarm.elf -d fals
python py/test_send_mpdu.py -e ../stationtest/obj/test_send.elf -d false -t 2500000000 > /dev/null
python py/test_send_noise.py -e ../stationtest/obj/test_send.elf -d false -t 2500000000 > /dev/null
python py/test_tx_rx.py -e ../stationtest/obj/test_tx_rx.elf -d false -t 2500000000 > /dev/null
+python py/test_log.py -e ../stationtest/obj/test_log.elf -d false -t 2500000000 > /dev/null