summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests
diff options
context:
space:
mode:
authorlefranc2010-02-01 13:10:25 +0000
committerlefranc2010-02-01 13:10:25 +0000
commit88a4da8c6b759fcf55f44c82d188abfa2b3b5fd9 (patch)
tree7c30a1b225b925253a6253f68ed7ebdb763d7e3e /cleopatre/devkit/tests
parent4f401c4dffa12d517cdd8e9d1e4e60dc09a87954 (diff)
cleo/appli/managerd: add VS_ETH_STATS MME
- unit tests included git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6682 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cleopatre/devkit/tests')
-rw-r--r--cleopatre/devkit/tests/managerd/utests/src/vs_mme_utests.c139
-rw-r--r--cleopatre/devkit/tests/managerd/utests/testfiles/net_dev7
2 files changed, 145 insertions, 1 deletions
diff --git a/cleopatre/devkit/tests/managerd/utests/src/vs_mme_utests.c b/cleopatre/devkit/tests/managerd/utests/src/vs_mme_utests.c
index ad585ceea1..eb555d4765 100644
--- a/cleopatre/devkit/tests/managerd/utests/src/vs_mme_utests.c
+++ b/cleopatre/devkit/tests/managerd/utests/src/vs_mme_utests.c
@@ -42,6 +42,7 @@
#define PLC_FIRMWARE_VERSION "0.1-rc3-1-unit_test"
#define PLC_VERSION_FILE "testfiles/plc_version"
+#define NET_DEV_FILE "testfiles/net_dev"
#define BR_MAC_ADDR "\x00\x13\xd7\x00\x00\x10"
@@ -56,6 +57,14 @@ static struct check_ctx {
} check_ctx;
+enum test_id {
+ TEST_GET_VERSION = 0,
+ TEST_ETH_STATS,
+ TEST_NB
+};
+
+enum test_id test_id;
+
/** local variables */
static struct managerd_ctx managerd_ctx;
static struct managerd_ctx *ctx = &managerd_ctx;
@@ -85,7 +94,17 @@ void __assert_fail (__const char *__assertion, __const char *__file,
FILE *fopen (const char *path, const char *mode)
{
- test_fd = open (PLC_VERSION_FILE, O_RDONLY);
+ switch(test_id)
+ {
+ case TEST_GET_VERSION:
+ test_fd = open (PLC_VERSION_FILE, O_RDONLY);
+ break;
+ case TEST_ETH_STATS:
+ test_fd = open (NET_DEV_FILE, O_RDONLY);
+ break;
+ default:
+ return NULL;
+ }
return fdopen (test_fd, "r");
}
@@ -254,6 +273,9 @@ START_TEST (test_get_version_success)
{
int result;
vs_get_version_cnf_t *get_version_cnf;
+
+ test_id = TEST_GET_VERSION;
+
get_version_cnf = (vs_get_version_cnf_t *)((unsigned char*)confirm + sizeof(MME_t));
/* fill request */
memset (request, '\0', 1024);
@@ -292,10 +314,125 @@ TCase *vs_get_version_tcase (void)
return tc;
}
+/* check param input error */
+START_TEST (test_eth_stats_param_1)
+{
+ check_ctx.test_id = 1;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eth_stats (NULL, request, confirm, 1024);
+ fail ("vs_eth_stats ctx = NULL (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_eth_stats ctx = NULL (2)");
+}
+END_TEST
+
+START_TEST (test_eth_stats_param_2)
+{
+ check_ctx.test_id = 2;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eth_stats (ctx, NULL, confirm, 1024);
+ fail ("vs_eth_stats request = NULL (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_eth_stats request = NULL (2)");
+}
+END_TEST
+
+START_TEST (test_eth_stats_param_3)
+{
+ check_ctx.test_id = 3;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eth_stats (ctx, request, NULL, 1024);
+ fail ("vs_eth_stats confirm = NULL (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_eth_stats confirm = NULL (2)");
+}
+END_TEST
+
+START_TEST (test_eth_stats_param_4)
+{
+ check_ctx.test_id = 4;
+ if(0 == setjmp (check_ctx.jmp_env))
+ {
+ vs_mme_eth_stats (ctx, request, confirm, sizeof(vs_eth_stats_cnf_t) + sizeof(MME_t) - 1);
+ fail ("vs_eth_stats len too small (1)");
+ }
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
+ "vs_eth_stats len too small (2)");
+}
+END_TEST
+
+START_TEST (test_eth_stats_get_success)
+{
+ int result;
+ vs_eth_stats_req_t *eth_stats_req;
+ vs_eth_stats_cnf_t *eth_stats_cnf;
+
+ test_id = TEST_ETH_STATS;
+
+ eth_stats_req = (vs_eth_stats_req_t *)((unsigned char*)request + sizeof(MME_t));
+ eth_stats_cnf = (vs_eth_stats_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 = MME_TYPE_VS_ETH_STATS | MME_TYPE_REQ;
+ memcpy (eth_stats_req->oui, OUI_SPIDCOM, 3);
+ eth_stats_req->command = 0; /* get command */
+
+ fail_unless ((vs_mme_eth_stats (ctx, request, confirm, 1024) == TO_DROP)
+ && !memcmp (confirm->mme_dest, request->mme_src, ETH_ALEN)
+ && !memcmp (confirm->mme_src, ctx->br_mac_addr, ETH_ALEN)
+ && (confirm->mtype == request->mtype)
+ && (confirm->mmtype == (MME_TYPE_VS_ETH_STATS | MME_TYPE_CNF))
+ && !memcmp (eth_stats_cnf->oui, OUI_SPIDCOM, 3)
+ && (eth_stats_cnf->result == MME_RESULT_SUCCESS)
+ && (eth_stats_cnf->rx_bytes_low == (111111111111LL & 0xffffffff))
+ && (eth_stats_cnf->rx_bytes_high == ((111111111111LL & 0xffffffff00000000LL) >> 32))
+ && (eth_stats_cnf->rx_packets_low == (2222222222LL & 0xffffffff))
+ && (eth_stats_cnf->rx_packets_high == ((2222222222LL & 0xffffffff00000000LL) >> 32))
+ && (eth_stats_cnf->rx_errors == 303)
+ && (eth_stats_cnf->rx_dropped == 404)
+ && (eth_stats_cnf->rx_overruns == 505)
+ && (eth_stats_cnf->rx_frames == 606)
+ && (eth_stats_cnf->tx_bytes_low == (333333333333LL & 0xffffffff))
+ && (eth_stats_cnf->tx_bytes_high == ((333333333333LL & 0xffffffff00000000LL) >> 32))
+ && (eth_stats_cnf->tx_packets_low == (4444444444LL & 0xffffffff))
+ && (eth_stats_cnf->tx_packets_high == ((4444444444LL & 0xffffffff00000000LL) >> 32))
+ && (eth_stats_cnf->tx_errors == 909)
+ && (eth_stats_cnf->tx_dropped == 1010)
+ && (eth_stats_cnf->tx_fifo == 1111)
+ && (eth_stats_cnf->tx_collisions == 1212)
+ && (eth_stats_cnf->tx_carrier == 1313)
+ ,
+ "vs_eth_stats_get success");
+}
+END_TEST
+
+TCase *vs_eth_stats_tcase (void)
+{
+ TCase *tc = tcase_create ("vs_eth_stats");
+ tcase_add_checked_fixture (tc, setup, teardown);
+ // check input param
+ tcase_add_test (tc, test_eth_stats_param_1);
+ tcase_add_test (tc, test_eth_stats_param_2);
+ tcase_add_test (tc, test_eth_stats_param_3);
+ tcase_add_test (tc, test_eth_stats_param_4);
+ tcase_add_test (tc, test_eth_stats_get_success);
+ return tc;
+}
+
Suite* vs_mme_suite(void)
{
Suite *s = suite_create ("vs_mme");
suite_add_tcase (s, vs_get_version_tcase ());
+ suite_add_tcase (s, vs_eth_stats_tcase ());
return s;
}
diff --git a/cleopatre/devkit/tests/managerd/utests/testfiles/net_dev b/cleopatre/devkit/tests/managerd/utests/testfiles/net_dev
new file mode 100644
index 0000000000..9d0f24c990
--- /dev/null
+++ b/cleopatre/devkit/tests/managerd/utests/testfiles/net_dev
@@ -0,0 +1,7 @@
+Inter-| Receive | Transmit
+ face |bytes packets errs drop fifo frame compressed multicast|bytes packets errs drop fifo colls carrier compressed
+ lo: 1074523 36505 0 0 0 0 0 0 1074523 36505 0 0 0 0 0 0
+ eth0:111111111111 2222222222 303 404 505 606 707 808 333333333333 4444444444 909 1010 1111 1212 1313 1414
+ br0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
+ plc0: 5914 66 0 0 0 0 0 0 118734 142 0 0 0 0 0 0
+