summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/plcdrv/utests/src/processing_utests.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/tests/plcdrv/utests/src/processing_utests.c')
-rw-r--r--cleopatre/devkit/tests/plcdrv/utests/src/processing_utests.c230
1 files changed, 230 insertions, 0 deletions
diff --git a/cleopatre/devkit/tests/plcdrv/utests/src/processing_utests.c b/cleopatre/devkit/tests/plcdrv/utests/src/processing_utests.c
new file mode 100644
index 0000000000..9035df1969
--- /dev/null
+++ b/cleopatre/devkit/tests/plcdrv/utests/src/processing_utests.c
@@ -0,0 +1,230 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file processing_utests.c
+ * \brief Unitary tests for Porcessing layer
+ * \ingroup Cleopatre - PlcDrv
+ *
+ * This file content all the unitary tests for the processing layer,
+ * this layer will analyse all frames(TX ans RX) and decided to pass and drop it.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include "processing.h"
+
+/** local defines */
+#define ETH_P_HPAV 0x88E1
+#define HPAV_MME_VERSION 0x01
+#define HPAV_MME_TYPE_FCALL 0xABCD
+#define HPAV_MME_FMI 0x2664
+
+/** local variables */
+static uint8_t eth_std[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, //src addr
+ 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, //dst addr
+ 0x34, 0x12, //eth type
+ 0x01, //eth raw
+ 0x88, 0x99,
+ 0x55, 0x66,
+ 0x99
+};
+static uint8_t eth_hpav[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, //src addr
+ 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, //dst addr
+ 0x88, 0xE1, //eth type=HPAV
+ 0x01, //mme version
+ 0x88, 0x99, //mme type=unknown
+ 0x55, 0x66, //mme fmi
+ 0x99
+};
+static uint8_t eth_hpav_fcall[] = {
+ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, //src addr
+ 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, //dst addr
+ 0x88, 0xE1, //eth type=HPAV
+ 0x01, //mme version
+ 0xAB, 0xCD, //mme type=fcall
+ 0x26, 0x64, //mme fmi
+ 0x99
+};
+
+/** Test init */
+START_TEST (test_processing_init)
+{
+ struct init_info info;
+ fail_if(processing_init(NULL) == 0, "Error checking arguments");
+ fail_if(processing_init((struct init_info*)0x55555555) == 0, "Error with mailbox layer error");
+ fail_if(processing_init(&info) != 0, "Error checking normal case");
+}
+END_TEST
+
+/** Test uninit */
+START_TEST (test_processing_uninit)
+{
+}
+END_TEST
+
+/** Test get_eth_src_addr */
+START_TEST (test_processing_get_eth_src_addr)
+{
+ uint8_t source[6];
+ int i;
+ get_eth_src_addr(eth_std, source);
+ for(i=0; i<6; i++)
+ {
+ fail_if(source[i] != eth_std[i+6], "Error with Eth src addr copy");
+ }
+}
+END_TEST
+
+/** Test get_eth_dst_addr */
+START_TEST (test_processing_get_eth_dst_addr)
+{
+ uint8_t dst[6];
+ int i;
+ get_eth_dst_addr(eth_std, dst);
+ for(i=0; i<6; i++)
+ {
+ fail_if(dst[i] != eth_std[i], "Error with Eth dst addr copy");
+ }
+}
+END_TEST
+
+/** Test get_eth_type */
+START_TEST (test_processing_get_eth_type)
+{
+ fail_if(get_eth_type(eth_hpav) != ETH_P_HPAV, "Error with Eth type search");
+}
+END_TEST
+
+/** Test get_eth_mme_version */
+START_TEST (test_processing_get_eth_mme_version)
+{
+ fail_if(get_eth_mme_version(eth_hpav) != HPAV_MME_VERSION, "Error with HPAV MME version search");
+}
+END_TEST
+
+/** Test get_eth_mme_type */
+START_TEST (test_processing_get_eth_mme_type)
+{
+ fail_if(get_eth_mme_type(eth_hpav_fcall) != HPAV_MME_TYPE_FCALL, "Error with HPAV MME type search");
+}
+END_TEST
+
+/** Test get_eth_mme_fmi */
+START_TEST (test_processing_get_eth_mme_fmi)
+{
+ fail_if(get_eth_mme_fmi(eth_hpav_fcall) != HPAV_MME_FMI, "Error with HPAV MME fmi search");
+}
+END_TEST
+
+/** Test processing_buffer_add */
+START_TEST (test_processing_buffer_add)
+{
+ fail_if(processing_buffer_add((void*)NULL, DATA) != -1, "Error with prepare_hw procedure");
+
+ fail_if(processing_buffer_add(eth_hpav_fcall, MME) != 0, "Error with sending a known frame");
+ fail_if(processing_buffer_add(eth_std, (enum buffer_type)10) != -1, "Error with sending an unknown type frame");
+}
+END_TEST
+
+/** Test processing_buffer_free */
+START_TEST (test_processing_buffer_free)
+{
+ fail_if(processing_buffer_free((void*)NULL) != -1, "Error with prepare_hw procedure");
+
+ fail_if(processing_buffer_free((void*)0x12345678) != 0, "Error with freeing a known frame");
+ fail_if(processing_buffer_free((void*)0x55555555) != -1, "Error with freeing an unknown type frame");
+}
+END_TEST
+
+/** Test processing_send */
+START_TEST (test_processing_send)
+{
+ fail_if(processing_send(NULL, 124) != -1, "Error with arguments checking");
+ fail_if(processing_send((void*)0x12345678, 0) != -1, "Error with arguments checking");
+ fail_if(processing_send((void*)0x12345678, 2000) != -1, "Error with arguments checking");
+
+ fail_if(processing_send((void*)eth_std, 100) != -1, "Error with prepare_hw procedure");
+
+ fail_if(processing_send(eth_hpav_fcall, 70) != 3, "Error with sending an Interface frame");
+ fail_if(processing_send(eth_hpav, 70) != 2, "Error with sending a Mme frame");
+ fail_if(processing_send(eth_std, 70) != 1, "Error with sending a Data frame");
+}
+END_TEST
+
+/** Test processing_receive */
+START_TEST (test_processing_receive)
+{
+ fail_if(processing_receive(NULL, 124, DATA) != -1, "Error with arguments checking");
+ fail_if(processing_receive((void*)0x12345678, 0, DATA) != -1, "Error with arguments checking");
+ fail_if(processing_receive((void*)0x12345678, 2000, DATA) != -1, "Error with arguments checking");
+
+ fail_if(processing_receive((void*)0x12345678, 100, DATA) != -1, "Error with prepare_hw procedure");
+
+ fail_if(processing_receive(eth_hpav_fcall, 70, INTERFACE) != 0, "Error with receiving an Interface frame");
+ fail_if(processing_receive(eth_hpav, 70, MME) != 0, "Error with receiving a Mme frame");
+ fail_if(processing_receive(eth_hpav, 70, DATA) != 0, "Error with receiving a Data frame");
+ fail_if(processing_receive(eth_hpav, 70, (enum buffer_type)10) != -1, "Error with receiving a unknown frame");
+
+ fail_if(processing_receive((void*)0x55555555, 70, DATA) != -1, "Error with plcdrv_rx procedure");
+}
+END_TEST
+
+
+extern Suite* processing_suite(void)
+{
+ Suite *s = suite_create("PROCESSING");
+ TCase *tc_core = tcase_create("Core");
+
+ //Test init
+ tcase_add_test(tc_core, test_processing_init);
+ //Test uninit
+ tcase_add_test(tc_core, test_processing_uninit);
+ //Test get_eth_src_addr
+ tcase_add_test(tc_core, test_processing_get_eth_src_addr);
+ //Test get_eth_dst_addr
+ tcase_add_test(tc_core, test_processing_get_eth_dst_addr);
+ //Test get_eth_type
+ tcase_add_test(tc_core, test_processing_get_eth_type);
+ //Test get_eth_mme_version
+ tcase_add_test(tc_core, test_processing_get_eth_mme_version);
+ //Test get_eth_mme_type
+ tcase_add_test(tc_core, test_processing_get_eth_mme_type);
+ //Test get_eth_mme_fmi
+ tcase_add_test(tc_core, test_processing_get_eth_mme_fmi);
+ //Test processing_buffer_add
+ tcase_add_test(tc_core, test_processing_buffer_add);
+ //Test processing_buffer_add
+ tcase_add_test(tc_core, test_processing_buffer_free);
+ //Test processing_send
+ tcase_add_test(tc_core, test_processing_send);
+ //Test processing_receive
+ tcase_add_test(tc_core, test_processing_receive);
+
+ suite_add_tcase(s, tc_core);
+ return s;
+}
+
+int main(void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run Processing tests
+ s = processing_suite();
+
+ SRunner *sr = srunner_create(s);
+ srunner_run_all(sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
+