summaryrefslogtreecommitdiff
path: root/cesar/cp2/msg/test/src/test-msg.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cp2/msg/test/src/test-msg.c')
-rw-r--r--cesar/cp2/msg/test/src/test-msg.c229
1 files changed, 229 insertions, 0 deletions
diff --git a/cesar/cp2/msg/test/src/test-msg.c b/cesar/cp2/msg/test/src/test-msg.c
new file mode 100644
index 0000000000..2a591b25f7
--- /dev/null
+++ b/cesar/cp2/msg/test/src/test-msg.c
@@ -0,0 +1,229 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file src/test-msg.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+
+#include "common/defs/homeplugAV.h"
+
+#include "lib/test.h"
+#include "lib/swap.h"
+#include "lib/bitstream.h"
+
+#include "cp2/cp.h"
+#include "cp2/msg/msg.h"
+
+#include "cp2/inc/context.h"
+#include "cp2/msg/inc/msg.h"
+
+void
+test_case_msg_messages_init (test_t test)
+{
+ cp_t cp;
+ cp_mme_rx_t *mme_rx;
+ cp_mme_tx_t *mme_tx;
+ u8 buffer[10];
+
+ cp_msg_init (&cp);
+
+ test_case_begin (test, "MSG Message");
+
+ mme_rx = cp_msg_mme_rx_init (&cp, buffer, 70, 0xA);
+ test_begin (test, "MME rx init")
+ {
+ test_fail_if (mme_rx == NULL, "MSG message shall not be null");
+ test_fail_if (mme_rx->p_mme != buffer, "Wrong buffer address");
+ test_fail_if (mme_rx->length != 70, "Wrong length");
+ test_fail_if (mme_rx->peer.tei != 0xA, "Wrong TEI");
+ test_fail_if (mme_rx->cp != &cp, "Wrong CP context");
+ }
+ test_end;
+ slab_release (mme_rx);
+
+ mme_tx = cp_msg_mme_tx_init (&cp);
+ test_begin (test, "MME rx init")
+ {
+ test_fail_if (mme_tx == NULL, "MSG message shall not be null");
+ test_fail_if (mme_tx->cp != &cp, "Wrong CP context");
+ }
+ test_end;
+ slab_release (mme_tx);
+
+ cp_msg_uninit (&cp);
+}
+
+void
+test_case_msg_mme_tx_init (test_t test)
+{
+ cp_t cp;
+ cp_mme_tx_t *mme;
+ cp_mme_peer_t peer;
+ bitstream_t bitstream;
+ u64 data;
+
+ cp_msg_init (&cp);
+
+ test_case_begin (test, "Get a MME TX context");
+
+ peer.mac = 0x123456789ABCull;
+ peer.vlan_tag = 0xAB;
+ peer.tei = 0xA;
+ peer.all_sta = false;
+ mme = cp_msg_mme_init (&cp, &peer, 0xb0);
+ // Close the MME bitstream.
+ bitstream_finalise (&mme->bitstream);
+
+ bitstream_init (&bitstream, mme->p_mme, HPAV_MME_HEADER_LEN_WITH_VLAN,
+ BITSTREAM_READ);
+ test_begin (test, "Verify")
+ {
+ test_fail_if (mme->p_mme == NULL, "buffer shall not be NULL");
+ test_fail_if (mme->peer.mac != peer.mac, "Wrong MAC @");
+ test_fail_if (mme->peer.vlan_tag != peer.vlan_tag, "Wrong VLAN tag");
+ test_fail_if (mme->peer.all_sta != peer.all_sta, "Wrong STA Flag");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != peer.mac, "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != 0x123456789ABCull,
+ "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 32);
+ test_fail_if (data != peer.vlan_tag, "Wrong VLAN TAG");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (swap16(data) != HPAV_MTYPE_MME, "Wrong Mtype");
+
+ bitstream_access (&bitstream, &data, 8);
+ test_fail_if (data != HPAV_MMV, "Wrong MMV");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != 0xb0, "Wrong MMTYPE");
+ }
+ test_end;
+
+ bitstream_finalise (&bitstream);
+ slab_release (mme);
+
+ cp_msg_uninit (&cp);
+}
+
+void
+test_case_msg_mme_tx_init_enc (test_t test)
+{
+ cp_t cp;
+ cp_mme_tx_t *mme;
+ cp_mme_peer_t peer;
+ cp_secu_protocol_run_t prun;
+ bitstream_t bitstream;
+ u64 data;
+
+ cp_msg_init (&cp);
+
+ test_case_begin (test, "Get a MME TX enc context");
+
+ peer.mac = 0x123456789ABCull;
+ peer.vlan_tag = 0xAB;
+ peer.tei = 0xA;
+ peer.all_sta = false;
+
+ prun.pid = 2;
+ prun.pmn = 2;
+ prun.my_nonce = 0x3;
+ prun.your_nonce = 0x4;
+
+ mme = cp_msg_mme_init_encrypted (&cp, &peer, 0xb0, 2, &prun);
+ // Close the MME bitstream.
+ bitstream_finalise (&mme->bitstream);
+
+ bitstream_init (&bitstream, mme->p_mme, 2*HPAV_MME_HEADER_LEN_WITH_VLAN,
+ BITSTREAM_READ);
+ test_begin (test, "Verify")
+ {
+ test_fail_if (mme->p_mme == NULL, "buffer shall not be NULL");
+ test_fail_if (mme->peer.mac != peer.mac, "Wrong MAC @");
+ test_fail_if (mme->peer.vlan_tag != peer.vlan_tag, "Wrong VLAN tag");
+ test_fail_if (mme->peer.all_sta != peer.all_sta, "Wrong STA Flag");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != peer.mac, "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != 0x123456789ABCull,
+ "Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 32);
+ test_fail_if (data != peer.vlan_tag, "Wrong VLAN TAG");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (swap16(data) != HPAV_MTYPE_MME, "Wrong Mtype");
+
+ bitstream_access (&bitstream, &data, 8);
+ test_fail_if (data != HPAV_MMV, "Wrong MMV");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != CM_ENCRYPTED_PAYLOAD_IND, "Wrong MMTYPE");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != 0, "Wrong FMI");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != peer.mac, "enc: Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 48);
+ test_fail_if (data != 0x123456789ABCull,
+ "enc: Wrong destination mac address");
+
+ bitstream_access (&bitstream, &data, 32);
+ test_fail_if (data != peer.vlan_tag, "enc: Wrong VLAN TAG");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (swap16(data) != HPAV_MTYPE_MME, "enc: Wrong Mtype");
+
+ bitstream_access (&bitstream, &data, 8);
+ test_fail_if (data != HPAV_MMV, "enc: Wrong MMV");
+
+ bitstream_access (&bitstream, &data, 16);
+ test_fail_if (data != 0xb0, "enc: Wrong MMTYPE");
+
+ }
+ test_end;
+
+ bitstream_finalise (&bitstream);
+ slab_release (mme);
+
+ cp_msg_uninit (&cp);
+}
+
+
+int
+main (void)
+{
+ test_t test;
+ test_init (test, 0, NULL);
+
+ test_case_msg_messages_init (test);
+ test_case_msg_mme_tx_init (test);
+ test_case_msg_mme_tx_init_enc (test);
+
+ test_case_begin (test, "Memory allocation");
+ test_begin (test, "memory leaks")
+ {
+ test_fail_if (blk_check_memory () != true, "Memory leaks");
+ }
+ test_end;
+
+ test_result (test);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}