summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/managerd/utests/src/vs_eoc_mme_utests.c
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/tests/managerd/utests/src/vs_eoc_mme_utests.c')
-rw-r--r--cleopatre/devkit/tests/managerd/utests/src/vs_eoc_mme_utests.c201
1 files changed, 201 insertions, 0 deletions
diff --git a/cleopatre/devkit/tests/managerd/utests/src/vs_eoc_mme_utests.c b/cleopatre/devkit/tests/managerd/utests/src/vs_eoc_mme_utests.c
new file mode 100644
index 0000000000..1d5497ad84
--- /dev/null
+++ b/cleopatre/devkit/tests/managerd/utests/src/vs_eoc_mme_utests.c
@@ -0,0 +1,201 @@
+/* SPC300-eoc bundle {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/managerd/utests/src/vs_eoc_mme_utests.c
+ * \brief Unitary tests for bridge
+ * \ingroup managerd
+ *
+ * Unitary tests for bridge
+ */
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h> /* for select() */
+#include <linux/if_ether.h> /* for ETH_ALEN */
+#include <unistd.h>
+#include <errno.h>
+#include "../../../../application/libspid/inc/path.h"
+#include "libmme.h"
+#include <setjmp.h>
+
+#include "vs_eoc_mme.h"
+#include "vs_mme.h"
+
+#include "stub.h"
+
+#define BR_MAC_ADDR "\x00\x13\xd7\x00\x00\x10"
+#define LOCAL_SLAVE_CONF_FILE "testfiles/slave.conf"
+
+struct check_ctx_st check_ctx;
+
+enum test_id_en test_id;
+
+struct managerd_ctx ctx;
+struct managerd_ctx *pctx = &ctx;
+int assert_id;
+
+/** local variables */
+static char request_buffer[1518];
+static char confirm_buffer[1518];
+static MME_t *request = (MME_t *)request_buffer;
+static MME_t *confirm = (MME_t *)confirm_buffer;
+
+/* fixtures - run before and after each unit test */
+void setup(void)
+{
+ check_ctx.test_id = 0;
+ check_ctx.assert_id = 0;
+ memcpy (pctx->br_mac_addr, BR_MAC_ADDR, ETH_ALEN);
+}
+
+void teardown(void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* check param input error */
+START_TEST (test_get_device_info_param_1)
+{
+ check_ctx.test_id = 1;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eoc_get_device_info (NULL, request, confirm, 1024);
+ fail ("vs_mme_eoc_get_device_info ctx = NULL (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_mme_eoc_get_device_info ctx = NULL (2)");
+}
+END_TEST
+
+START_TEST (test_get_device_info_param_2)
+{
+ check_ctx.test_id = 2;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eoc_get_device_info (pctx, NULL, confirm, 1024);
+ fail ("vs_mme_eoc_get_device_info request = NULL (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_mme_eoc_get_device_info request = NULL (2)");
+}
+END_TEST
+
+START_TEST (test_get_device_info_param_3)
+{
+ check_ctx.test_id = 3;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eoc_get_device_info (pctx, request, NULL, 1024);
+ fail ("vs_mme_eoc_get_device_info confirm = NULL (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_mme_eoc_get_device_info confirm = NULL (2)");
+}
+END_TEST
+
+START_TEST (test_get_device_info_param_4)
+{
+ check_ctx.test_id = 4;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eoc_get_device_info (pctx, request, confirm,
+ sizeof(vs_eoc_get_device_info_cnf_t)
+ + sizeof(MME_t) - 1);
+ fail ("vs_mme_eoc_get_device_info len too small (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_mme_eoc_get_device_info len too small (2)");
+}
+END_TEST
+
+START_TEST (test_get_device_info_success)
+{
+ vs_eoc_get_device_info_cnf_t *get_device_info_cnf;
+ char model_no[64] = "SPiDCOMmodem1Test";
+ unsigned int eth_port_nb = 4;
+ char downstream_attenuation = 0;
+
+ test_id = TEST_GET_DEVICE_INFO;
+
+ system ("mkdir -p /tmp/utests/etc");
+ system ("cp " LOCAL_SLAVE_CONF_FILE " " LIBSPID_CONF_ROOT_PATH);
+
+ get_device_info_cnf = (vs_eoc_get_device_info_cnf_t *)
+ ((unsigned char*)confirm + sizeof(MME_t));
+ /* fill request */
+ memset (request, '\0', 1024);
+ memcpy (request->mme_src, "\x00\x13\xd7\x00\x00\x20", ETH_ALEN);
+ memcpy (request->mme_dest, BROADCAST_ADDR, ETH_ALEN);
+ request->mtype = htons (MME_TYPE);
+ request->mmtype = VS_EOC_GET_DEVICE_INFO | MME_REQ;
+ memcpy ((char *)request + sizeof(MME_t), OUI_SPIDCOM, 3);
+
+ fail_unless ((vs_mme_eoc_get_device_info (pctx, request, confirm, 1024)
+ == TO_DROP), "vs_mme_eoc_get_device_info success (1)");
+ fail_if (memcmp (confirm->mme_dest, request->mme_src, ETH_ALEN),
+ "vs_mme_eoc_get_device_info success (2)");
+ fail_if (memcmp (confirm->mme_src, pctx->br_mac_addr, ETH_ALEN),
+ "vs_mme_eoc_get_device_info success (3)");
+ fail_if ((confirm->mtype != request->mtype),
+ "vs_mme_eoc_get_device_info success (4)");
+ fail_if ((confirm->mmtype
+ != (VS_EOC_GET_DEVICE_INFO | MME_CNF)),
+ "vs_mme_eoc_get_device_info success (5)");
+ fail_if (memcmp (get_device_info_cnf->oui, OUI_SPIDCOM, 3),
+ "vs_mme_eoc_get_device_info success (6)");
+ fail_if ((get_device_info_cnf->result != 0),
+ "vs_mme_eoc_get_device_info success (7)");
+ fail_if (memcmp (get_device_info_cnf->model_no, model_no,
+ sizeof(model_no)), "vs_mme_eoc_get_device_info success (8)");
+ fail_if ((get_device_info_cnf->eth_port_nb != eth_port_nb),
+ "vs_mme_eoc_get_device_info success (9)");
+ fail_if (memcmp (get_device_info_cnf->sw_version, IMAGE_DESC_VERSION,
+ strlen (IMAGE_DESC_VERSION)),
+ "vs_mme_eoc_get_device_info success (10)");
+ fail_if ((get_device_info_cnf->downstream_attenuation
+ != downstream_attenuation),
+ "vs_mme_eoc_get_device_info success (11)");
+
+}
+END_TEST
+
+extern Suite* managerd_eoc_mme_suite(void)
+{
+ Suite *s = suite_create("MANAGERD_EOC_MME");
+ TCase *tc_core = tcase_create("Core");
+
+ // check input param
+ tcase_add_test (tc_core, test_get_device_info_param_1);
+ tcase_add_test (tc_core, test_get_device_info_param_2);
+ tcase_add_test (tc_core, test_get_device_info_param_3);
+ tcase_add_test (tc_core, test_get_device_info_param_4);
+ tcase_add_test (tc_core, test_get_device_info_success);
+
+ suite_add_tcase(s, tc_core);
+ return s;
+}
+
+int main(void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ /* run bridge unitary tests */
+ s = managerd_eoc_mme_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
+