summaryrefslogtreecommitdiff
path: root/cleopatre/devkit/tests/libspid/utests/src
diff options
context:
space:
mode:
Diffstat (limited to 'cleopatre/devkit/tests/libspid/utests/src')
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/analog_alarm_eoc_utests.c268
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/autoconf_eoc_utests.c189
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/community_eoc_utests.c472
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/config_backup_eoc_utests.c516
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c155
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/current_alarm_eoc_utests.c210
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/discrete_alarm_eoc_utests.c234
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/ethctl_eoc_utests.c454
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/ethernet_port_eoc_utests.c542
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/hardware_utests.c162
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/igmp_snooping_eoc_utests.c300
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/image_utests.c2
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/maclimit_eoc_utests.c367
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/master_config_eoc_utests.c321
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/misc_eoc_utests.c323
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/misc_utests.c220
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/network_utests.c168
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/port_eoc_stub.c78
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/port_eoc_utests.c495
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/service_eoc_stub.c107
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/service_eoc_utests.c682
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/storm_eoc_utests.c445
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/system_utests.c895
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/trap_eoc_utests.c373
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/upgrade_eoc_utests.c218
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/utest_launcher.c30
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc.c223
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc_cap.c304
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/util_utests.c266
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/vlan_port_utests.c362
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/vlan_utests.c346
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/wl_eoc_stub.c108
-rw-r--r--cleopatre/devkit/tests/libspid/utests/src/wl_eoc_utests.c1138
33 files changed, 10623 insertions, 350 deletions
diff --git a/cleopatre/devkit/tests/libspid/utests/src/analog_alarm_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/analog_alarm_eoc_utests.c
new file mode 100644
index 0000000000..3ca1e8bc83
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/analog_alarm_eoc_utests.c
@@ -0,0 +1,268 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file analog_alarm_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains all the unitary tests for EoC analog alarms in LibSPiD.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define ANALOG_ALARM_CONF "testfiles/alarm_analog.conf"
+#define ANALOG_ALARM_ENTRY_NUM 2
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char oid;
+ libspid_eoc_analog_alarm_entry_t analog_alarm_entry;
+
+ /* oid = NULL */
+ ret = libspid_eoc_analog_alarm_set (NULL, &analog_alarm_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "oid = NULL");
+
+ /* analog_alarm_entry = NULL */
+ ret = libspid_eoc_analog_alarm_set (&oid, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "analog_alarm_entry = NULL");
+
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+START_TEST (test_libspid_eoc_analog_alarm_set)
+{
+ int ret;
+ char oid[LIBSPID_OID_MAX_LEN];
+ libspid_eoc_analog_alarm_entry_t entry;
+
+
+ memset (&entry, 0, sizeof (entry));
+
+ strcpy (oid, ".1.3.6.1.4.1.22764.3.1.5.2.4.1.10");
+
+ entry.enable.LOLO_alarm_enable = 1;
+ entry.enable.LO_alarm_enable = 0;
+ entry.enable.HI_alarm_enable = 1;
+ entry.enable.HIHI_alarm_enable = 0;
+ entry.state = 3;
+ entry.hihi = 110;
+ entry.hi = 60;
+ entry.lo = 15;
+ entry.lolo = 5;
+ entry.deadband = 6;
+
+ system ("cp " ANALOG_ALARM_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_analog_alarm_set (oid, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_analog_alarm_set fail");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_analog_alarm_get)
+{
+ int ret;
+ char oid[LIBSPID_OID_MAX_LEN];
+ libspid_eoc_analog_alarm_entry_t entry;
+
+
+ memset (&entry, 0, sizeof (entry));
+
+ strcpy (oid, ".1.3.6.1.4.1.22764.3.1.5.2.4.1.10");
+
+ system ("cp " ANALOG_ALARM_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_analog_alarm_get (oid, &entry);
+
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_analog_alarm_get return unsuccessful");
+ fail_if (strcmp (entry.oid, ".1.3.6.1.4.1.22764.3.1.5.2.4.1.10") != 0,
+ "libspid_eoc_analog_alarm_get corrupts alarm OID");
+ fail_if (entry.enable.LOLO_alarm_enable != 1,
+ "libspid_eoc_analog_alarm_get gets wrong alarm enable");
+ fail_if (entry.state != 1,
+ "libspid_eoc_analog_alarm_get gets wrong alarm state");
+ fail_if (entry.hihi != 127,
+ "libspid_eoc_analog_alarm_get gets wrong alarm HIHI threshold");
+ fail_if (entry.hi != 50,
+ "libspid_eoc_analog_alarm_get gets wrong alarm HI threshold");
+ fail_if (entry.lo != 10,
+ "libspid_eoc_analog_alarm_get gets wrong alarm LO threshold");
+ fail_if (entry.lolo != 0,
+ "libspid_eoc_analog_alarm_get gets wrong alarm LOLO threshold");
+ fail_if (entry.deadband != 7,
+ "libspid_eoc_analog_alarm_get gets wrong alarm deadband");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_analog_alarm_get_list)
+{
+ int ret;
+ libspid_eoc_analog_alarm_entry_t entries[ANALOG_ALARM_ENTRY_NUM];
+ int i;
+ int count;
+
+ /* Expected results */
+ char oid[ANALOG_ALARM_ENTRY_NUM][LIBSPID_OID_MAX_LEN]
+ = {".1.3.6.1.4.1.22764.3.1.5.2.4.1.10",
+ ".1.3.6.1.4.1.22764.3.1.5.2.4.1.11"};
+ char enable[ANALOG_ALARM_ENTRY_NUM][2] = {"1", "1"};
+ char state[ANALOG_ALARM_ENTRY_NUM][2] = {"1", "2"};
+ char hihi[ANALOG_ALARM_ENTRY_NUM][4] = {"127", "100"};
+ char hi[ANALOG_ALARM_ENTRY_NUM][4] = {"50", "70"};
+ char lo[ANALOG_ALARM_ENTRY_NUM][4] = {"10", "20"};
+ char lolo[ANALOG_ALARM_ENTRY_NUM][4] = {"0", "10"};
+ char deadband[ANALOG_ALARM_ENTRY_NUM][4] = {"7", "5"};
+
+ memset (entries, 0, ANALOG_ALARM_ENTRY_NUM
+ * sizeof (libspid_eoc_analog_alarm_entry_t));
+
+ system ("cp " ANALOG_ALARM_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_analog_alarm_get_list (entries, &count);
+
+ fail_if (count != ANALOG_ALARM_ENTRY_NUM,
+ "libspid_eoc_analog_alarm_get_list returns wrong count");
+
+ for (i=0; i<ANALOG_ALARM_ENTRY_NUM; i++)
+ {
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_analog_alarm_get_list return is unsuccessful");
+
+ fail_if (strcmp (entries[i].oid, oid[i]) != 0,
+ "libspid_eoc_analog_alarm_get_list corrupts alarm OID");
+ fail_if (entries[i].enable.LOLO_alarm_enable != atoi (enable[i]),
+ "libspid_eoc_analog_alarm_get_list corrupts alarm enable");
+ fail_if ((int) entries[i].state != atoi (state[i]),
+ "libspid_eoc_analog_alarm_get_list corrupts alarm state");
+ fail_if (entries[i].hihi != atoi (hihi[i]),
+ "libspid_eoc_analog_alarm_get_list corrupts alarm "
+ "HIHI threshold");
+ fail_if (entries[i].hi != atoi (hi[i]),
+ "libspid_eoc_analog_alarm_get_list corrupts alarm "
+ "HI threshold");
+ fail_if (entries[i].lo != atoi (lo[i]),
+ "libspid_eoc_analog_alarm_get_list corrupts alarm "
+ "LO threshold");
+ fail_if (entries[i].lolo != atoi (lolo[i]),
+ "libspid_eoc_analog_alarm_get_list corrupts alarm "
+ "LOLO threshold");
+ fail_if (entries[i].deadband != atoi (deadband[i]),
+ "libspid_eoc_analog_alarm_get_list corrupts alarm deadband");
+ }
+}
+END_TEST
+
+extern Suite*
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_analog_alarm_set);
+ tcase_add_test (tc_core, test_libspid_eoc_analog_alarm_get);
+ tcase_add_test (tc_core, test_libspid_eoc_analog_alarm_get_list);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/autoconf_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/autoconf_eoc_utests.c
new file mode 100644
index 0000000000..5ce1db5d8f
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/autoconf_eoc_utests.c
@@ -0,0 +1,189 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file autoconf_eoc_utests.c
+ * \brief Unitary tests for auto-configure libspid function
+ * \ingroup Cleopatre - libspid
+ *
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define LOCAL_CONFIG_TAR_FILE "testfiles/config.tar"
+#define CONFIG_TAR_FILE "config.tar"
+#define CONFIG_GZIP_FILE "config.tar.gz"
+
+/* fixtures - run before and after each unit test */
+void
+setup(void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ( (stat (UTESTS_TMP_DIR, &st) == 0) )
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char mac_address;
+ char file [20];
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_configure (NULL, file);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* mac_address_count = NULL */
+ ret = libspid_eoc_configure (&mac_address, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "file = NULL");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_configure)
+{
+ int ret, i;
+ char tar_file[] = UTESTS_TMP_DIR "/" CONFIG_TAR_FILE;
+ char gzip_file[] = UTESTS_TMP_DIR "/" CONFIG_GZIP_FILE;
+ int exp_ret[8] = {
+ LIBSPID_SUCCESS, LIBSPID_ERROR_SYSTEM, LIBSPID_ERROR_SYSTEM,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_ERROR_SYSTEM, LIBSPID_ERROR_SYSTEM,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_ERROR_AUTOCONF_EXIST
+ };
+ char mac_addr[8][LIBSPID_MAC_STR_LEN] = {
+ "00:11:22:33:44:55", "00:11:22:33:44:66", "00:11:22:33:44:77",
+ "00:11:22:33:44:88", "00:11:22:33:44:99", "00:11:22:33:44:aa",
+ "00:11:22:33:44:bb", "00:11:22:33:44:cc"
+ };
+
+ system ("cp " LOCAL_CONFIG_TAR_FILE " " UTESTS_TMP_DIR);
+
+ /* Check for NULL parameters */
+ ret = libspid_eoc_configure (NULL, tar_file);
+ fail_if (ret != LIBSPID_ERROR_PARAM,
+ "libspid_eoc_configure operates with NULL MAC parameter");
+ ret = libspid_eoc_configure ("00:11:22:33:44:55", NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM,
+ "libspid_eoc_configure operates with NULL file parameter");
+
+ /* Check various responses from slave */
+ for (i=0; i<8; i++) {
+ ret = libspid_eoc_configure (mac_addr[i], tar_file);
+ fail_if (ret != exp_ret[i],
+ "[MAC %s] libspid_eoc_configure return is incorrect",
+ mac_addr[i]);
+ }
+
+ system ("mv " UTESTS_TMP_DIR "/" CONFIG_TAR_FILE " "
+ UTESTS_TMP_DIR "/" CONFIG_GZIP_FILE);
+
+ /* Check wrong archive */
+ ret = libspid_eoc_configure ("00:11:22:33:44:55", tar_file);
+ fail_if (ret != LIBSPID_ERROR_PARAM,
+ "libspid_eoc_configure operates with non-existing "
+ "configuration");
+ ret = libspid_eoc_configure ("00:11:22:33:44:55", gzip_file);
+ fail_if (ret != LIBSPID_ERROR_PARAM,
+ "libspid_eoc_configure should operates only with .tar files");
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+extern Suite* libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_configure);
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param());
+ return s;
+}
+
+int main(void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
+
diff --git a/cleopatre/devkit/tests/libspid/utests/src/community_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/community_eoc_utests.c
new file mode 100644
index 0000000000..85ac7e3384
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/community_eoc_utests.c
@@ -0,0 +1,472 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file community_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+# define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+# define TRACE(...)
+#endif
+
+/* local constants */
+#define SNMPD_CONF "testfiles/snmpd.conf"
+
+int curr_comm_num = 4;
+#define COMM_NUM 4
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* go on create other subdirs */
+ sprintf (buf, "%s/etc/snmp", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc/snmp, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+
+START_TEST (test_libspid_eoc_write_community_line)
+{
+ int ret;
+ int line_num;
+ char old_comm_name[16], old_sec_name[16], new_comm_name[16];
+ libspid_snmp_comm_t entries[6];
+
+ memset (entries, 0, (COMM_NUM + 1) * sizeof (libspid_snmp_comm_t));
+
+ /*old_comm_name = NULL */
+ ret =
+ libspid_eoc_write_community_line (0, old_sec_name,
+ new_comm_name, curr_comm_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_community_line old_comm_name = NULL");
+
+ /*old_sec_name = NULL */
+ ret =
+ libspid_eoc_write_community_line (old_comm_name, 0,
+ new_comm_name, curr_comm_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_community_line old_comm_name = NULL");
+
+ /*new_comm_name = NULL */
+ ret =
+ libspid_eoc_write_community_line (old_comm_name, old_sec_name,
+ 0, curr_comm_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_community_line new_comm_name = NULL");
+
+ /* curr_comm_num = 0 or curr_comm_num without inited */
+
+ /* the uninited value will take a big value, like follows */
+ int noinit_curr_num = 97893;
+
+ ret =
+ libspid_eoc_write_community_line (old_comm_name, old_sec_name,
+ new_comm_name, 0);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_community_line curr_comm_num is 0");
+ ret =
+ libspid_eoc_write_community_line (old_comm_name, old_sec_name,
+ new_comm_name, &noinit_curr_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_community_line curr_comm_num have been not inited");
+
+
+ system ("cp " SNMPD_CONF " " UTESTS_TMP_DIR "/etc/snmp");
+
+ strcpy (old_comm_name, "");
+ strcpy (new_comm_name, "aaa");
+ line_num = curr_comm_num;
+
+ ret =
+ libspid_eoc_write_community_line (old_comm_name, old_sec_name,
+ new_comm_name, line_num);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_write_community_line for new line failed");
+
+
+ line_num++;
+ libspid_eoc_read_community_list (entries, &line_num);
+ fail_if (strcmp (entries[line_num - 1].comm_name, "aaa") != 0,
+ "test libspid_eoc_write_commumity_line sets wrong "
+ "comm_name");
+
+ strcpy (old_comm_name, "aaa");
+ strcpy (new_comm_name, "bbb");
+
+ ret =
+ libspid_eoc_write_community_line (old_comm_name, old_sec_name,
+ new_comm_name, line_num);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_write_community_line for update failed");
+
+ libspid_eoc_read_community_list (entries, &line_num);
+ fail_if (strcmp (entries[line_num - 1].comm_name, "bbb") != 0,
+ "test libspid_eoc_write_commumity_line updates wrong "
+ "comm_name");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_write_security_line)
+{
+ int ret;
+ int line_num;
+ char old_sec_name[16], new_comm_name[16];
+ libspid_snmp_comm_t entries[6];
+
+ memset (entries, 0, (COMM_NUM + 1) * sizeof (libspid_snmp_comm_t));
+
+ /*old_sec_name = NULL */
+ ret =
+ libspid_eoc_write_security_line (0, new_comm_name, 1, curr_comm_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_security_line old_sec_name = NULL");
+
+ /*new_comm_name = NULL */
+ ret =
+ libspid_eoc_write_security_line (old_sec_name, 0, 1, curr_comm_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_security_line new_comm_name = NULL");
+
+ /*new_access < 0 */
+ ret =
+ libspid_eoc_write_security_line (old_sec_name, new_comm_name, -2,
+ curr_comm_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_security_line new_access < 0");
+
+ /* curr_comm_num is 0 or without inited */
+ int noinit_curr_num = 88978;
+ ret =
+ libspid_eoc_write_security_line (old_sec_name, new_comm_name, 1, 0);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_security_line curr_comm_num is 0");
+ ret =
+ libspid_eoc_write_security_line (old_sec_name, new_comm_name, 1,
+ noinit_curr_num);
+ fail_unless (ret == LIBSPID_ERROR_PARAM,
+ "write_security_line curr_comm_num have been not inited");
+
+ system ("cp " SNMPD_CONF " " UTESTS_TMP_DIR "/etc/snmp");
+ strcpy (old_sec_name, "ccc");
+ strcpy (new_comm_name, "ccc");
+ ret =
+ libspid_eoc_write_security_line (old_sec_name, new_comm_name, 1,
+ curr_comm_num);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_write_security_line for new line failed");
+
+ line_num = curr_comm_num + 1;
+
+ libspid_eoc_read_security_list (entries, &line_num);
+ fail_if (strcmp (entries[line_num - 1].sec_name, "ccc") != 0,
+ "test libspid_eoc_write_security_line sets wrong " "sec_name");
+
+ strcpy (old_sec_name, "ccc");
+ strcpy (new_comm_name, "ddd");
+
+ ret =
+ libspid_eoc_write_security_line (old_sec_name, new_comm_name,
+ 1, line_num);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_write_security_line for update line failed");
+
+ libspid_eoc_read_security_list (entries, &line_num);
+ fail_if (strcmp (entries[line_num - 1].sec_name, "ddd") != 0,
+ "test libspid_eoc_write_security_line updates wrong "
+ "sec_name");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_read_list)
+{
+ int ret_comm, ret_sec;
+ libspid_snmp_comm_t entries[COMM_NUM];
+ int idx;
+ int line_num = COMM_NUM;
+
+ /* Expected results */
+ char comm_names[COMM_NUM][16] =
+ { "spidcom", "mstar", "public", "private" };
+
+ char sec_names[COMM_NUM][16] = { "local", "mstar",
+ "public", "private"};
+
+ int comm_permissions[COMM_NUM] = { 1, 1, 2, 3 };
+
+
+ memset (entries, 0, COMM_NUM * sizeof (libspid_snmp_comm_t));
+
+ /*entries = NULL */
+ ret_comm = libspid_eoc_read_community_list (0, &line_num);
+ ret_sec = libspid_eoc_read_security_list (0, &line_num);
+ fail_unless (ret_comm == LIBSPID_ERROR_PARAM,
+ "read_community_list entries = NULL");
+ fail_unless (ret_sec == LIBSPID_ERROR_PARAM,
+ "read_security_list entries = NULL");
+
+ /*line_num = NULL */
+ ret_comm = libspid_eoc_read_community_list (entries, 0);
+ ret_sec = libspid_eoc_read_security_list (entries, 0);
+ fail_unless (ret_comm == LIBSPID_ERROR_PARAM,
+ "read_community_list line_num = NULL");
+ fail_unless (ret_sec == LIBSPID_ERROR_PARAM,
+ "read_security_list line_num = NULL");
+
+ /* line_num is not init */
+ int noinit_line_num = 88483;
+
+ ret_comm = libspid_eoc_read_community_list (entries, &noinit_line_num);
+ ret_sec = libspid_eoc_read_security_list (entries, &noinit_line_num);
+ fail_unless (ret_comm == LIBSPID_ERROR_PARAM,
+ "read_community_list line_num have been not inited");
+ fail_unless (ret_sec == LIBSPID_ERROR_PARAM,
+ "read_security_list line_num have been not inited");
+
+ system ("cp " SNMPD_CONF " " UTESTS_TMP_DIR "/etc/snmp");
+ ret_comm = libspid_eoc_read_community_list (entries, &line_num);
+ ret_sec = libspid_eoc_read_security_list (entries, &line_num);
+
+ fail_if (line_num != COMM_NUM,
+ "test_libspid_eoc_read_community_list returns wrong count");
+
+ for (idx = 0; idx < COMM_NUM; idx++)
+ {
+ fail_if (ret_comm != LIBSPID_SUCCESS,
+ "libspid_eoc_read_community_list return is "
+ "unsuccessful");
+ fail_if (ret_sec != LIBSPID_SUCCESS,
+ "libspid_eoc_read_security_list return is "
+ "unsuccessful");
+ fail_if (strcmp (entries[idx].comm_name, comm_names[idx]) != 0,
+ "test_libspid_eoc_read_community_list corrupts ip "
+ "comm_name");
+ fail_if (strcmp (entries[idx].sec_name, sec_names[idx]) != 0,
+ "test_libspid_eoc_read_community_list gets wrong "
+ "sec_name");
+ fail_if (entries[idx].comm_permission != comm_permissions[idx],
+ "test_libspid_eoc_read_community_list gets wrong "
+ "comm_permission");
+ }
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_remove_line)
+{
+ int ret_comm, ret_sec;
+ char old_comm_name[16], old_sec_name[16];
+ libspid_snmp_comm_t entries[COMM_NUM];
+ int idx;
+ int line_num = COMM_NUM;
+
+ /* Expected read results */
+ char comm_names[][16] = { "spidcom", "mstar", "private" };
+
+ char sec_names[][16] = { "local", "mstar", "private"};
+
+ int comm_permissions[] = { 1, 1, 3 };
+
+ /*old_comm_name = NULL */
+ ret_comm =
+ libspid_eoc_remove_community_line (0, old_sec_name, curr_comm_num);
+ fail_unless (ret_comm == LIBSPID_ERROR_PARAM,
+ "remove_community_line old_comm_name = NULL");
+
+ /*old_sec_name = NULL */
+ ret_comm =
+ libspid_eoc_remove_community_line (old_comm_name, 0, curr_comm_num);
+ ret_sec = libspid_eoc_remove_security_line (0, curr_comm_num);
+ fail_unless (ret_comm == LIBSPID_ERROR_PARAM,
+ "remove_community_line old_sec_name = NULL");
+ fail_unless (ret_sec == LIBSPID_ERROR_PARAM,
+ "remove_security_line old_sec_name = NULL");
+
+ /*curr_comm_num < 0 */
+ ret_comm =
+ libspid_eoc_remove_community_line (old_comm_name, old_sec_name, -1);
+ ret_sec = libspid_eoc_remove_security_line (old_sec_name, -1);
+ fail_unless (ret_comm == LIBSPID_ERROR_PARAM,
+ "remove_community_line curr_comm_num < 0");
+ fail_unless (ret_sec == LIBSPID_ERROR_PARAM,
+ "remove_security_line curr_comm_num < 0");
+
+ system ("cp " SNMPD_CONF " " UTESTS_TMP_DIR "/etc/snmp");
+ curr_comm_num = 4;
+
+ strcpy (old_comm_name, "public");
+
+ /* remove entry public */
+ ret_comm =
+ libspid_eoc_remove_community_line (old_comm_name, old_sec_name,
+ curr_comm_num);
+ ret_sec = libspid_eoc_remove_security_line (old_sec_name, curr_comm_num);
+
+ fail_if (ret_comm != LIBSPID_SUCCESS,
+ "libspid_eoc_remove_community_line return is unsuccessful");
+ fail_if (ret_sec != LIBSPID_SUCCESS,
+ "libspid_eoc_remove_security_line return is not found");
+
+ /* remove no existing entry public */
+
+ line_num = curr_comm_num - 1;
+ ret_comm =
+ libspid_eoc_remove_community_line (old_comm_name, old_sec_name,
+ line_num);
+
+ ret_sec = libspid_eoc_remove_security_line (old_sec_name, line_num);
+
+
+ fail_if (ret_comm != LIBSPID_ERROR_NOT_FOUND,
+ "no existing entry but return is not NOT_FOUND");
+ fail_if (ret_sec != LIBSPID_ERROR_NOT_FOUND,
+ "no existing entry but return is not NOT_FOUND");
+
+ /* read and check list */
+ memset (entries, 0, (COMM_NUM - 1) * sizeof (libspid_snmp_comm_t));
+
+ ret_comm = libspid_eoc_read_community_list (entries, &line_num);
+ ret_sec = libspid_eoc_read_security_list (entries, &line_num);
+
+ fail_if (line_num != COMM_NUM - 1,
+ "test_libspid_eoc_read_community_list returns wrong count");
+
+ for (idx = 0; idx < COMM_NUM - 1; idx++)
+ {
+ fail_if (ret_comm != LIBSPID_SUCCESS,
+ "libspid_eoc_read_community_list return is "
+ "unsuccessful");
+ fail_if (ret_sec != LIBSPID_SUCCESS,
+ "libspid_eoc_read_security_list return is "
+ "unsuccessful");
+ fail_if (strcmp (entries[idx].comm_name, comm_names[idx]) != 0,
+ "test_libspid_eoc_read_community_list corrupts ip "
+ "comm_name");
+ fail_if (strcmp (entries[idx].sec_name, sec_names[idx]) != 0,
+ "test_libspid_eoc_read_community_list gets wrong "
+ "sec_name");
+ fail_if (entries[idx].comm_permission != comm_permissions[idx],
+ "test_libspid_eoc_read_community_list gets wrong "
+ "comm_permission");
+ }
+
+}
+
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ return tc_param;
+}
+
+extern Suite *
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_read_list);
+ tcase_add_test (tc_core, test_libspid_eoc_write_community_line);
+ tcase_add_test (tc_core, test_libspid_eoc_write_security_line);
+ tcase_add_test (tc_core, test_libspid_eoc_remove_line);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/config_backup_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/config_backup_eoc_utests.c
new file mode 100644
index 0000000000..6b99762311
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/config_backup_eoc_utests.c
@@ -0,0 +1,516 @@
+/*
+*Cleopatre project {{{
+* Copyright (C) 2012 MStar
+* <<<Licence>>>
+* }}}
+*/
+
+/**
+* \file config_backup_eoc_utests.c
+* \brief Unitary tests for libspid
+* \ingroup Cleopatre - libspid
+*
+* This file content all the unitary tests for EoC SPiDLib.
+*/
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h>
+#include <string.h>
+#include "eoc_utests.h"
+#include "libspid.h"
+
+#define BACKUP_CONF "testfiles/confbak.conf"
+#define BACKUP_DUINDEX_CONF "testfiles/confbak_duindex.conf"
+
+
+static void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+
+}
+
+static void entry_cmp_equ (
+ libspid_eoc_config_backup_entry_t *entry1,
+ libspid_eoc_config_backup_entry_t *entry2)
+{
+ int ret;
+ ret = strcmp (entry1->index, entry2->index);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->protocol, entry2->protocol);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->ip_address, entry2->ip_address);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->server_port, entry2->server_port);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->login, entry2->login);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->password, entry2->password);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->type, entry2->type);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->fileName, entry2->fileName);
+ fail_if (0 != ret, "must equ");
+
+ ret = strcmp (entry1->result, entry2->result);
+ fail_if (0 != ret, "must equ");
+
+}
+
+START_TEST (test_libspid_eoc_config_backup_get)
+{
+ int ret;
+ char index[16];
+ libspid_eoc_config_backup_entry_t entry, entry2;
+
+ ret = libspid_eoc_config_backup_get (0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ strcpy (index, "10");
+ ret = libspid_eoc_config_backup_get (index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ strcpy (index, "10");
+ ret = libspid_eoc_config_backup_get (index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of no config file");
+
+ ret = system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ strcpy (index, "10");
+ ret = libspid_eoc_config_backup_get (index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, not have this index");
+
+ strcpy (entry.index, "10");
+ strcpy (entry.protocol, "1");
+ strcpy (entry.ip_address, "192.168.0.1");
+ strcpy (entry.server_port, "1111");
+ strcpy (entry.login, "mstar");
+ strcpy (entry.password, "mstar");
+ strcpy (entry.type, "1");
+ strcpy (entry.fileName, "aaaa");
+ strcpy (entry.result, "1");
+
+ ret = libspid_eoc_config_backup_set (index, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_get (index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entry2);
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_config_backup_get_list)
+{
+ int ret = 0;
+ unsigned int cnt = 0 ;
+ unsigned int i = 0;
+ libspid_eoc_config_backup_entry_t entry;
+ libspid_eoc_config_backup_entry_t entries[LIBSPID_CONFIG_BACKUP_ITEM_MAX];
+
+ ret = libspid_eoc_config_backup_get_list (0, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ ret = libspid_eoc_config_backup_get_list (entries, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ ret = libspid_eoc_config_backup_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of none config file");
+
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+ ret = libspid_eoc_config_backup_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (3 != cnt, "Get List Items error");
+
+ for (i = 0 ; i < cnt ; i ++)
+ {
+ ret = libspid_eoc_config_backup_get (entries[i].index, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entries[i]);
+ }
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_config_backup_set)
+{
+ int ret = 0;
+ char index[16];
+ libspid_eoc_config_backup_entry_t entry, entry2;
+
+ ret = libspid_eoc_config_backup_set (0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ strcpy (index, "10");
+ ret = libspid_eoc_config_backup_set (index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ ret = system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ strcpy (index, "10");
+ strcpy (entry.index, "10");
+ strcpy (entry.protocol, "1");
+ strcpy (entry.ip_address, "192.168.0.1");
+ strcpy (entry.server_port, "1111");
+ strcpy (entry.login, "mstar");
+ strcpy (entry.password, "mstar");
+ strcpy (entry.type, "1");
+ strcpy (entry.fileName, "aaaa");
+ strcpy (entry.result, "1");
+
+ ret = libspid_eoc_config_backup_set (index, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_get (index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entry2);
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_config_backup_remove)
+{
+ int ret = 0;
+ unsigned int cnt = 0 ;
+ unsigned int i = 0;
+ char index[16];
+ libspid_eoc_config_backup_entry_t entry, entry2;
+ libspid_eoc_config_backup_entry_t entries[LIBSPID_CONFIG_BACKUP_ITEM_MAX];
+
+ ret = libspid_eoc_config_backup_remove (0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ strcpy (index, "5");
+ ret = libspid_eoc_config_backup_remove (index);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of none config file");
+
+ ret = system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+ strcpy (index, "5");
+ ret = libspid_eoc_config_backup_remove (index);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of none this item");
+
+ strcpy (index, "5");
+ strcpy (entry.index, "5");
+ strcpy (entry.protocol, "1");
+ strcpy (entry.ip_address, "192.168.0.1");
+ strcpy (entry.server_port, "1111");
+ strcpy (entry.login, "mstar");
+ strcpy (entry.password, "mstar");
+ strcpy (entry.type, "1");
+ strcpy (entry.fileName, "aaaa");
+ strcpy (entry.result, "1");
+
+ ret = libspid_eoc_config_backup_set (index, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_get (index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entry2);
+
+ ret = libspid_eoc_config_backup_remove (entry.index);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+
+ ret = libspid_eoc_config_backup_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ for (i = 0 ; i < cnt ; i ++)
+ {
+ ret = libspid_eoc_config_backup_remove (entries[i].index);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ }
+
+ ret = libspid_eoc_config_backup_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (0 != cnt, "must equ zero, because have delete all");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_config_backup_flush)
+{
+ int ret = 0;
+ unsigned int cnt = 0 ;
+ libspid_eoc_config_backup_entry_t entries[LIBSPID_CONFIG_BACKUP_ITEM_MAX];
+
+ ret = libspid_eoc_config_backup_flush ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of none config file");
+
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ ret = libspid_eoc_config_backup_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (cnt == 0, "must not equ zero");
+
+ ret = libspid_eoc_config_backup_flush ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (cnt != 0, "must equ zero");
+
+ ret = libspid_eoc_config_backup_flush ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_config_backup_check)
+{
+ int ret = 0;
+ char index[16];
+ libspid_eoc_config_backup_entry_t entry, entry2;
+
+ strcpy (index, "11");
+ strcpy (entry.index, "11");
+ strcpy (entry.protocol, "1");
+ strcpy (entry.ip_address, "192.168.0.1");
+ strcpy (entry.server_port, "1111");
+ strcpy (entry.login, "mstar");
+ strcpy (entry.password, "mstar");
+ strcpy (entry.type, "1");
+ strcpy (entry.fileName, "aaaa");
+ strcpy (entry.result, "1");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of none config file");
+
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_set (entry.index, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ /* check index*/
+ setup ();
+ ret = system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.index, "16");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of index error");
+
+ /* check index is not unique */
+ setup ();
+ system ("cp " BACKUP_DUINDEX_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of index is not unique");
+
+ /* check protocol*/
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.protocol, "5");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of protocol error");
+
+ /* check ip*/
+ setup ();
+ ret = system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.ip_address, "139.88.888.1");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of ip format error");
+
+ /* check server_port*/
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.server_port, "cd");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of server_port error");
+
+ /* check login*/
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.login, "01234567890123456789012345678901234");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of login too long");
+
+ /* check password*/
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.password, "01234567890123456789012345678901234");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of password too long");
+
+ /* check type*/
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.type, "9");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of type error");
+
+ /* check filename*/
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.fileName, "abcdefghigklmnopqrstuvwxyz123456789.bin");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of type error");
+
+ /* check result*/
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.result, "3");
+
+ ret = libspid_eoc_config_backup_set (entry2.index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of result error");
+
+}
+END_TEST
+
+Suite *
+libspid_eoc_suite ()
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_config_backup_get);
+ tcase_add_test (tc_core, test_libspid_eoc_config_backup_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_config_backup_set);
+ tcase_add_test (tc_core, test_libspid_eoc_config_backup_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_config_backup_flush);
+ tcase_add_test (tc_core, test_libspid_eoc_config_backup_check);
+
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_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;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c b/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c
index aac0d92b3b..d7742b8512 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/config_line_utests.c
@@ -324,63 +324,65 @@ START_TEST (test_libspid_config_read_line)
unsigned int elt_nb;
char key[LIBSPID_CONFIG_KEY_MAX_LEN + 1];
- system("cp " LINE_CNF " " UTESTS_TMP_DIR);
- sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(LINE_CNF));
+ system ("cp " LINE_CNF " " UTESTS_TMP_DIR);
+ sprintf (filename, "%s/%s", UTESTS_TMP_DIR, basename (LINE_CNF));
elt_nb = 8;
- strcpy(key, "eth");
- ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
- fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
+ strcpy (key, "eth");
+ ret = libspid_config_read_line (filename, delimiters, key,
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
- fail_if(elt_nb != 6);
- fail_if( strcmp(elt[3], "bb") != 0, "libspid_config_read_line gets wrong data");
+ fail_if (elt_nb != 6);
+ fail_if (strcmp (elt[3], "bb") != 0, "libspid_config_read_line gets wrong data");
/* check the same, but for DOS format cfg file */
- system("cp " LINE_DOS_CNF " " UTESTS_TMP_DIR);
- sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(LINE_DOS_CNF));
+ system ("cp " LINE_DOS_CNF " " UTESTS_TMP_DIR);
+ sprintf (filename, "%s/%s", UTESTS_TMP_DIR, basename (LINE_DOS_CNF));
elt_nb = 8;
- strcpy(key, "eth");
- ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
- fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
+ strcpy (key, "eth");
+ ret = libspid_config_read_line (filename, delimiters, key,
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
- fail_if(elt_nb != 6);
- fail_if( strcmp(elt[3], "bb") != 0, "libspid_config_read_line gets wrong data");
+ fail_if (elt_nb != 6);
+ fail_if (strcmp (elt[3], "bb") != 0, "libspid_config_read_line gets wrong data");
- system("cp " LINE_CNF " " UTESTS_TMP_DIR);
- sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(LINE_CNF));
- strcpy(delimiters, "*");
- strcpy(key, "spidcom");
+
+ system ("cp " LINE_CNF " " UTESTS_TMP_DIR);
+ sprintf (filename, "%s/%s", UTESTS_TMP_DIR, basename (LINE_CNF));
+ strcpy (delimiters, "*");
+ strcpy (key, "spidcom");
elt_nb = 8;
- ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
- fail_if(ret != LIBSPID_ERROR_NOT_FOUND, "libspid_config_read_line fail");
+ ret = libspid_config_read_line (filename, delimiters, key,
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_ERROR_NOT_FOUND, "libspid_config_read_line fail");
- strcpy(delimiters, ", ");
- strcpy(key, "mode");
+ strcpy (delimiters, ", ");
+ strcpy (key, "mode");
elt_nb = 8;
- ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
- fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
- fail_if(elt_nb != 4, "libspid_config_read_line gets wrong data");
- fail_if( strcmp(elt[2], "something") != 0, "libspid_config_read_line gets wrong data");
+ ret = libspid_config_read_line (filename, delimiters, key,
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
+ fail_if (elt_nb != 4, "libspid_config_read_line gets wrong data");
+ fail_if (strcmp (elt[2], "something") != 0, "libspid_config_read_line gets wrong data");
/* find the first key */
key[0] = '\0';
- strcpy(delimiters, ", ");
+ strcpy (delimiters, ", ");
elt_nb = 8;
- ret = libspid_config_read_line( filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
- fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
- fail_if( strcmp(key, "mode") != 0, "libspid_config_read_line gets wrong first key");
-
- /* check key max length */
- strcpy (key, "key5");
- elt_nb = 5;
ret = libspid_config_read_line (filename, delimiters, key,
- &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN );
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
fail_if (ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
- fail_unless (strlen (key) == 0, "libspid_config_read_line exceeds key max length");
+ fail_if (strcmp (key, "mode") != 0, "libspid_config_read_line gets wrong first key");
+
+ strcpy (key, "00:13:D7:d0:a0:b2");
+ elt_nb = 3;
+ ret = libspid_config_read_line (filename, delimiters, key,
+ &elt_nb, elt, buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_config_read_line failed");
+ fail_if (elt_nb != 3, "libspid_config_read_line gets wrong data");
+ fail_if (strcmp (buffer, "00:13:d7:d0:a0:b2") != 0, "libspid_config_read_line gets wrong key");
+
}
END_TEST
@@ -388,7 +390,7 @@ START_TEST (test_libspid_config_write_line)
{
int ret;
char filename[128];
- char delimiter = ':';
+ char delimiter = ' ';
char *elt[2];
unsigned int elt_nb;
char key[LIBSPID_CONFIG_KEY_MAX_LEN + 1];
@@ -398,44 +400,45 @@ START_TEST (test_libspid_config_write_line)
char el1[32] = {0};
char *p;
- system("cp " LINE_CNF " " UTESTS_TMP_DIR);
- sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(LINE_CNF));
+ system ("cp " LINE_CNF " " UTESTS_TMP_DIR);
+ sprintf (filename, "%s/%s", UTESTS_TMP_DIR, basename (LINE_CNF));
elt_nb = 2;
- elt[0] = strdup("el_0");
- elt[1] = strdup("el_1");
- strcpy(key, "tst_key");
- ret = libspid_config_write_line( filename, delimiter, key, elt_nb, elt);
- fail_if(ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
+ elt[0] = strdup ("el_0");
+ elt[1] = strdup ("el_1");
+ strcpy (key, "00:13:d7:D0:a0:B5");
+ ret = libspid_config_write_line (filename, delimiter, key, elt_nb, elt);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_config_read_line fail");
- fp = fopen(filename, "r");
+ strcpy (key, "00:13:d7:d0:a0:b5");
+ fp = fopen (filename, "r");
if (fp == NULL)
{
- perror("fopen())");
- exit(EXIT_FAILURE);
+ perror ("fopen())");
+ exit (EXIT_FAILURE);
}
- while ( fgets(line, LIBSPID_CONFIG_LINE_MAX_LEN, fp) != NULL )
+ while (fgets (line, LIBSPID_CONFIG_LINE_MAX_LEN, fp) != NULL)
{
- p = strtok(line, ":");
- if ( !strcmp(p, key) )
+ p = strtok (line, " ");
+ if ( !strcmp (p, key) )
{
- p = strtok(NULL, ":");
- strcpy(el0, p);
- if ( el0[ strlen(el0) - 1 ] == '\n' )
+ p = strtok (NULL, " ");
+ strcpy (el0, p);
+ if (el0[strlen (el0) - 1] == '\n')
{
- el0[ strlen(el0) - 1 ] = '\0';
+ el0[strlen (el0) - 1] = '\0';
}
- p = strtok(NULL, ":");
- strcpy(el1, p);
- if ( el1[ strlen(el1) - 1 ] == '\n' )
+ p = strtok (NULL, " ");
+ strcpy (el1, p);
+ if (el1[strlen (el1) - 1] == '\n')
{
- el1[ strlen(el1) - 1 ] = '\0';
+ el1[strlen (el1) - 1] = '\0';
}
}
}
- fclose(fp);
+ fclose (fp);
- fail_if( strcmp(el0, "el_0") != 0, "libspid_config_write_line writes wrong data" );
- fail_if( strcmp(el1, "el_1") != 0, "libspid_config_write_line writes wrong data" );
+ fail_if ( strcmp (el0, "el_0") != 0, "libspid_config_write_line writes wrong data");
+ fail_if ( strcmp (el1, "el_1") != 0, "libspid_config_write_line writes wrong data");
}
END_TEST
@@ -443,22 +446,22 @@ START_TEST (test_libspid_config_remove_line)
{
int ret;
char filename[128];
- char delimiters[32] = " :";
+ char delimiters[32] = " ";
char key[LIBSPID_CONFIG_KEY_MAX_LEN + 1];
char cmd[256];
struct stat file_stat;
- system("cp " LINE_CNF " " UTESTS_TMP_DIR);
- sprintf(filename, "%s/%s", UTESTS_TMP_DIR, basename(LINE_CNF));
- strcpy(key, "eth");
- ret = libspid_config_remove_line( filename, delimiters, key );
- fail_if(ret != LIBSPID_SUCCESS, "libspid_config_remove_line fail");
- sprintf( cmd, "diff %s %s > result.tmp", filename, LINE_REMOVE_CNF );
+ system ("cp " LINE_CNF " " UTESTS_TMP_DIR);
+ sprintf (filename, "%s/%s", UTESTS_TMP_DIR, basename (LINE_CNF));
+ strcpy (key, "00:13:D7:d0:a0:b2");
+ ret = libspid_config_remove_line (filename, delimiters, key);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_config_remove_line fail");
+ sprintf (cmd, "diff %s %s > result.tmp", filename, LINE_REMOVE_CNF);
- fail_unless( (system(cmd) == 0)
- && (stat("result.tmp", &file_stat) >= 0)
+ fail_unless ((system (cmd) == 0)
+ && (stat ("result.tmp", &file_stat) >= 0)
&& (file_stat.st_size == 0),
- "remove existing line eth" );
+ "remove existing line eth" );
}
END_TEST
diff --git a/cleopatre/devkit/tests/libspid/utests/src/current_alarm_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/current_alarm_eoc_utests.c
new file mode 100644
index 0000000000..02106c3370
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/current_alarm_eoc_utests.c
@@ -0,0 +1,210 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file current_alarm_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains all the unitary tests for EoC current alarms in LibSPiD.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define ALARM_INFO "testfiles/alarm.info"
+#define CURRENT_ALARM_ENTRY_NUM 4
+
+/* fixtures - run before and after each unit test */
+void
+setup(void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ( (stat (UTESTS_TMP_DIR, &st) == 0) )
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char oid;
+ libspid_eoc_current_alarm_entry_t current_alarm_entry;
+
+ /* oid = NULL */
+ ret = libspid_eoc_current_alarm_get (NULL, &current_alarm_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "oid = NULL");
+
+ /* current_alarm_entry = NULL */
+ ret = libspid_eoc_current_alarm_get (&oid, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "current_alarm_entry = NULL");
+
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+START_TEST (test_libspid_eoc_current_alarm_get)
+{
+ int ret;
+ char oid[LIBSPID_OID_MAX_LEN];
+ libspid_eoc_current_alarm_entry_t entry;
+
+ memset (&entry, 0, sizeof (entry));
+
+ strcpy (oid, ".1.3.6.1.4.1.22764.3.1.5.1.6.1.6");
+
+ system ("cp " ALARM_INFO " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_current_alarm_get (oid, &entry);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_current_alarm_get return unsuccessful");
+ fail_if (strcmp (entry.oid, ".1.3.6.1.4.1.22764.3.1.5.1.6.1.6") != 0,
+ "libspid_eoc_current_alarm_get corrupts alarm OID");
+ fail_if (entry.state != 6,
+ "libspid_eoc_current_alarm_get gets wrong alarm state");
+ fail_if (entry.value != 1,
+ "libspid_eoc_current_alarm_get gets wrong alarm value");
+}
+END_TEST
+
+/* TODO */
+START_TEST (test_libspid_eoc_current_alarm_get_list)
+{
+ int ret;
+ libspid_eoc_current_alarm_entry_t entries[CURRENT_ALARM_ENTRY_NUM];
+ int i;
+ int count;
+
+ /* Expected results */
+ char oid[CURRENT_ALARM_ENTRY_NUM][LIBSPID_OID_MAX_LEN]
+ = {".1.3.6.1.4.1.22764.3.1.5.1.6.1.6",
+ ".1.3.6.1.4.1.22764.3.1.5.1.6.1.7",
+ ".1.3.6.1.4.1.22764.3.1.5.1.6.1.8",
+ ".1.3.6.1.4.1.22764.3.1.5.1.6.1.9" };
+ char state[CURRENT_ALARM_ENTRY_NUM][2] = {"6", "7", "2", "5"};
+ char value[CURRENT_ALARM_ENTRY_NUM][2] = {"1", "0", "9", "1"};
+
+ memset (entries, 0, CURRENT_ALARM_ENTRY_NUM
+ * sizeof (libspid_eoc_current_alarm_entry_t));
+
+ system ("cp " ALARM_INFO " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_current_alarm_get_list (entries, &count);
+
+ fail_if (count != CURRENT_ALARM_ENTRY_NUM,
+ "libspid_eoc_current_alarm_get returns wrong count");
+
+ for (i=0; i < CURRENT_ALARM_ENTRY_NUM; i++)
+ {
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_current_alarm_get_list return is unsuccessful");
+
+ fail_if (strcmp (entries[i].oid, oid[i]) != 0,
+ "libspid_eoc_current_alarm_get_list corrupts alarm OID");
+ fail_if ((int) entries[i].state != atoi (state[i]),
+ "libspid_eoc_current_alarm_get_list corrupts alarm state");
+ fail_if (entries[i].value != atoi (value[i]),
+ "libspid_eoc_current_alarm_get_list corrupts alarm value");
+ }
+}
+END_TEST
+
+extern Suite*
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_current_alarm_get);
+ tcase_add_test (tc_core, test_libspid_eoc_current_alarm_get_list);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/discrete_alarm_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/discrete_alarm_eoc_utests.c
new file mode 100644
index 0000000000..616a6d347a
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/discrete_alarm_eoc_utests.c
@@ -0,0 +1,234 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file discrete_alarm_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains all the unitary tests for EoC discrete alarms in LibSPiD.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define DISCRETE_ALARM_CONF "testfiles/alarm_discrete.conf"
+#define DISCRETE_ALARM_ENTRY_NUM 2
+
+/* fixtures - run before and after each unit test */
+void
+setup(void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ( (stat (UTESTS_TMP_DIR, &st) == 0) )
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char oid;
+ libspid_eoc_discrete_alarm_entry_t discrete_alarm_entry;
+
+ /* oid = NULL */
+ ret = libspid_eoc_discrete_alarm_set (NULL, &discrete_alarm_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "oid = NULL");
+
+ /* discrete_alarm_entry = NULL */
+ ret = libspid_eoc_discrete_alarm_set (&oid, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "discrete_alarm_entry = NULL");
+
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+START_TEST (test_libspid_eoc_discrete_alarm_set)
+{
+ int ret;
+ char oid[LIBSPID_OID_MAX_LEN];
+ libspid_eoc_discrete_alarm_entry_t entry;
+
+ memset (&entry, 0, sizeof (entry));
+
+ strcpy (oid, ".1.3.6.1.4.1.22764.3.1.5.1.6.1.6");
+
+ entry.trigger = 1;
+ entry.enable = 2;
+ entry.state = 1;
+
+ system ("cp " DISCRETE_ALARM_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_discrete_alarm_set (oid, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_discrete_alarm_set fail");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_discrete_alarm_get)
+{
+ int ret;
+ char oid[LIBSPID_OID_MAX_LEN];
+ libspid_eoc_discrete_alarm_entry_t entry;
+
+ memset (&entry, 0, sizeof (entry));
+
+ strcpy (oid, ".1.3.6.1.4.1.22764.3.1.5.1.6.1.6");
+
+ system ("cp " DISCRETE_ALARM_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_discrete_alarm_get (oid, &entry);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_discrete_alarm_get return unsuccessful");
+ fail_if (strcmp (entry.oid, ".1.3.6.1.4.1.22764.3.1.5.1.6.1.6") != 0,
+ "libspid_eoc_discrete_alarm_get corrupts alarm OID");
+ fail_if (entry.trigger != 1,
+ "libspid_eoc_discrete_alarm_get gets wrong alarm trigger");
+ fail_if (entry.enable != 1,
+ "libspid_eoc_discrete_alarm_get gets wrong alarm enable");
+ fail_if (entry.state != 1,
+ "libspid_eoc_discrete_alarm_get gets wrong alarm state");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_discrete_alarm_get_list)
+{
+ int ret;
+ libspid_eoc_discrete_alarm_entry_t entries[DISCRETE_ALARM_ENTRY_NUM];
+ int i;
+ int count;
+
+ /* Expected results */
+ char oid[DISCRETE_ALARM_ENTRY_NUM][LIBSPID_OID_MAX_LEN]
+ = {".1.3.6.1.4.1.22764.3.1.5.1.6.1.6",
+ ".1.3.6.1.4.1.22764.3.1.5.1.6.1.7"};
+ char trigger[DISCRETE_ALARM_ENTRY_NUM][2] = {"1", "1"};
+ char enable[DISCRETE_ALARM_ENTRY_NUM][2] = {"1", "2"};
+ char state[DISCRETE_ALARM_ENTRY_NUM][2] = {"1", "6"};
+
+ memset (entries, 0, DISCRETE_ALARM_ENTRY_NUM
+ * sizeof (libspid_eoc_discrete_alarm_entry_t));
+
+ system ("cp " DISCRETE_ALARM_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_discrete_alarm_get_list (entries, &count);
+
+ fail_if (count != DISCRETE_ALARM_ENTRY_NUM,
+ "libspid_eoc_discrete_alarm_get returns wrong count");
+
+ for (i=0; i<DISCRETE_ALARM_ENTRY_NUM; i++)
+ {
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_discrete_alarm_get_list return is unsuccessful");
+
+ fail_if (strcmp (entries[i].oid, oid[i]) != 0,
+ "libspid_eoc_discrete_alarm_get_list corrupts alarm OID");
+ fail_if (entries[i].trigger != atoi (trigger[i]),
+ "libspid_eoc_discrete_alarm_get_list corrupts alarm "
+ "trigger");
+ fail_if ((int) entries[i].enable != atoi (enable[i]),
+ "libspid_eoc_discrete_alarm_get_list corrupts alarm enable");
+ fail_if ((int) entries[i].state != atoi (state[i]),
+ "libspid_eoc_discrete_alarm_get_list corrupts alarm state");
+ }
+}
+END_TEST
+
+extern Suite*
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_discrete_alarm_set);
+ tcase_add_test (tc_core, test_libspid_eoc_discrete_alarm_get);
+ tcase_add_test (tc_core, test_libspid_eoc_discrete_alarm_get_list);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/ethctl_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/ethctl_eoc_utests.c
new file mode 100644
index 0000000000..a3dfe6e504
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/ethctl_eoc_utests.c
@@ -0,0 +1,454 @@
+/*
+*Cleopatre project {{{
+* Copyright (C) 2012 MStar
+* <<<Licence>>>
+* }}}
+*/
+
+/**
+* \file ethctl_eoc_utests.c
+* \brief Unitary tests for libspid
+* \ingroup Cleopatre - libspid
+*
+* This file content all the unitary tests for EoC SPiDLib.
+*/
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h>
+#include <string.h>
+#include "eoc_utests.h"
+#include "libspid.h"
+
+#define ETHCTL_CONF "testfiles/ethctl.conf"
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define ETHCT_IGMP_CONF "testfiles/ethctl_check.conf"
+#define ETHCT_DUMAC_CONF "testfiles/ethctl_dumac.conf"
+
+
+
+static void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+
+}
+
+static void
+entry_cmp_equ (libspid_eoc_ethctl_entry_t *entry1,
+ libspid_eoc_ethctl_entry_t *entry2)
+{
+ int ret;
+ ret = strcmp (entry1->mac_address, entry2->mac_address);
+ fail_if (0 != ret, "mac_address must equ");
+
+ ret = strcmp (entry1->mirror_type, entry2->mirror_type);
+ fail_if (0 != ret, "mirror_type must equ");
+
+ ret = strcmp (entry1->mirror_en, entry2->mirror_en);
+ fail_if (0 != ret, "mirror_en must equ");
+
+ ret = strcmp (entry1->mirror_source_port, entry2->mirror_source_port);
+ fail_if (0 != ret, "mirror_source_port must equ");
+
+ ret = strcmp (entry1->mirror_dest_port, entry2->mirror_dest_port);
+ fail_if (0 != ret, "mirror_dest_port must equ");
+
+ ret = strcmp (entry1->loopback_en, entry2->loopback_en);
+ fail_if (0 != ret, "loopback_en must equ");
+
+ ret = strcmp (entry1->loopback_port_index, entry2->loopback_port_index);
+ fail_if (0 != ret, "loopback_port_index must equ");
+
+ ret = strcmp (entry1->flow_ctl_en, entry2->flow_ctl_en);
+ fail_if (0 != ret, "flow_ctl_en must equ");
+
+ ret = strcmp (entry1->aging_time, entry2->aging_time);
+ fail_if (0 != ret, "aging_time must equ");
+
+}
+
+START_TEST (test_libspid_eoc_ethctl_get)
+{
+ int ret;
+ char mac_address[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_ethctl_entry_t entry, entry2;
+
+ ret = libspid_eoc_ethctl_get (0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ strcpy (mac_address, "00:13:d7:00:00:00");
+ ret = libspid_eoc_ethctl_get (mac_address, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ strcpy (mac_address, "00:13:d7:00:00:00");
+ ret = libspid_eoc_ethctl_get (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of no config file");
+
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ strcpy (mac_address, "00:13:d7:00:00:00");
+ ret = libspid_eoc_ethctl_get (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, not have this mac_address");
+
+ strcpy (mac_address, "00:13:d7:00:00:01");
+ ret = libspid_eoc_ethctl_get (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must success");
+
+ strcpy (entry.mac_address, "00:13:d7:00:00:01");
+ strcpy (entry.mirror_type, "1");
+ strcpy (entry.mirror_en, "1");
+ strcpy (entry.mirror_source_port, "3");
+ strcpy (entry.mirror_dest_port, "4");
+ strcpy (entry.loopback_en, "1");
+ strcpy (entry.loopback_port_index, "255");
+ strcpy (entry.flow_ctl_en, "111");
+ strcpy (entry.aging_time, "110");
+
+ ret = libspid_eoc_ethctl_set (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_get (mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entry2);
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ethctl_get_list)
+{
+ int ret = 0;
+ int cnt = 0 ;
+ int i = 0;
+ libspid_eoc_ethctl_entry_t entry;
+ libspid_eoc_ethctl_entry_t entries[LIBSPID_ETHCTL_MAX_CONF_NUM];
+
+ ret = libspid_eoc_ethctl_get_list (0, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ ret = libspid_eoc_ethctl_get_list (entries, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ ret = libspid_eoc_ethctl_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of none config file");
+
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_ethctl_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (4 != cnt, "Get List Items error");
+
+ for (i = 0 ; i < cnt ; i ++)
+ {
+ ret = libspid_eoc_ethctl_get (entries[i].mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entries[i]);
+ }
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ethctl_set)
+{
+ int ret = 0;
+ char mac_address[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_ethctl_entry_t entry, entry2;
+
+ ret = libspid_eoc_ethctl_set (0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ strcpy (mac_address, "00:13:d7:00:00:01");
+ ret = libspid_eoc_ethctl_set (mac_address, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ strcpy (entry.mac_address, "00:13:d7:00:00:01");
+ strcpy (entry.mirror_type, "1");
+ strcpy (entry.mirror_en, "1");
+ strcpy (entry.mirror_source_port, "3");
+ strcpy (entry.mirror_dest_port, "4");
+ strcpy (entry.loopback_en, "1");
+ strcpy (entry.loopback_port_index, "255");
+ strcpy (entry.flow_ctl_en, "111");
+ strcpy (entry.aging_time, "110");
+
+ ret = libspid_eoc_ethctl_set (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_get (mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entry2);
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ethctl_check)
+{
+ int ret = 0;
+ libspid_eoc_ethctl_entry_t entry, entry2;
+
+ strcpy (entry.mac_address, "00:13:D7:00:00:01");
+ strcpy (entry.mirror_type, "1");
+ strcpy (entry.mirror_en, "1");
+ strcpy (entry.mirror_source_port, "3");
+ strcpy (entry.mirror_dest_port, "4");
+ strcpy (entry.loopback_en, "1");
+ strcpy (entry.loopback_port_index, "16");
+ strcpy (entry.flow_ctl_en, "65");
+ strcpy (entry.aging_time, "110");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of none config file");
+
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_set (entry.mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ /* check mac_address*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.mac_address, "00:13:D7:00:00:00");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of mac not defined");
+
+ /* check mac_address is in whitelist but not in ethctl config*/
+ setup ();
+ system ("cp " ETHCT_IGMP_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of mac in whitelist"
+ " but not in config file");
+
+ /* check mac_address is unique*/
+ setup ();
+ system ("cp " ETHCT_DUMAC_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of mac is not unique");
+
+ /* check mirror_type*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.mirror_type, "4");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of mirror_type error");
+
+ /* check mirror_en*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.mirror_en, "2");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of mirror_en error");
+
+ /* check mirror_source_port*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.mirror_source_port, "5");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of mirror_source_port error");
+
+ /* check mirror_dest_port*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.mirror_dest_port, "0");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of mirror_dest_port error");
+
+ /* check loopback_en*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.loopback_en, "2");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of loopback_en error");
+
+ /* check loopback_port_index*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.loopback_port_index, "256");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of loopback_port_index error");
+
+ /* check flow_ctl_en*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.flow_ctl_en, "257");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of flow_ctl_en error");
+
+ /* check aging_time*/
+ setup ();
+ system ("cp " ETHCTL_CONF" " LIBSPID_ETHCTL_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.aging_time, "1861");
+
+ ret = libspid_eoc_ethctl_set (entry2.mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_ethctl_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of aging_time error");
+
+}
+END_TEST
+
+Suite *
+libspid_eoc_suite ()
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_ethctl_get);
+ tcase_add_test (tc_core, test_libspid_eoc_ethctl_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_ethctl_set);
+ tcase_add_test (tc_core, test_libspid_eoc_ethctl_check);
+
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_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;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/ethernet_port_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/ethernet_port_eoc_utests.c
new file mode 100644
index 0000000000..d7d15d4161
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/ethernet_port_eoc_utests.c
@@ -0,0 +1,542 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file ethernet_port_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+# define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+# define TRACE(...)
+#endif
+
+/* local constants */
+#define ETH_PORT_CONF "testfiles/ethport.conf"
+#define ETH_PORT_MAC_CONF_1 "testfiles/eth_port_mac_1.conf"
+#define ETH_PORT_MAC_CONF_2 "testfiles/eth_port_mac_2.conf"
+#define ETH_PORT_ENTRY_NUM 20
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define PORT_V2 "testfiles/port_v2.conf"
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+
+ char mac_addr[LIBSPID_MAC_STR_LEN];
+ char index[2];
+ libspid_eoc_ethernet_port_entry_t eth_port_entry;
+ libspid_eoc_ethernet_port_entry_t eth_port_entries[LIBSPID_PORT_TOTAL_MAX];
+ int count;
+
+ /* check input parameters for libspid_eoc_ethernet_port_set */
+ /* check if mac_addr is NULL */
+ ret = libspid_eoc_ethernet_port_set (NULL, index, &eth_port_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac address is NULL");
+
+ /* check if index is NULL */
+ ret = libspid_eoc_ethernet_port_set (mac_addr, NULL, &eth_port_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "index is NULL");
+
+ /* check if eth_port_entry is NULL */
+ ret = libspid_eoc_ethernet_port_set (mac_addr, index, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eth_port_entry is NULL");
+
+ /* check input parameters for libspid_eoc_ethernet_port_get */
+ /* check if mac_addr is NULL */
+ ret = libspid_eoc_ethernet_port_get (NULL, index, &eth_port_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac address is NULL");
+
+ /* check if index is NULL */
+ ret = libspid_eoc_ethernet_port_get (mac_addr, NULL, &eth_port_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "index is NULL");
+
+ /* check if eth_port_entry is NULL */
+ ret = libspid_eoc_ethernet_port_get (mac_addr, index, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eth_port_entry is NULL");
+
+ /* check input parameters for libspid_eoc_ethernet_port_get_list */
+ /* check if eth_port_entry is NULL */
+ ret = libspid_eoc_ethernet_port_get_list (NULL, &count);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac address is NULL");
+
+ /* check if count is NULL */
+ ret = libspid_eoc_ethernet_port_get_list (eth_port_entries, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "count is NULL");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_ethernet_port_set)
+{
+ int ret;
+
+ libspid_eoc_ethernet_port_entry_t eth_port_entry;
+ libspid_eoc_ethernet_port_entry_t eth_port_entry_received;
+
+ memset (&eth_port_entry, 0, sizeof (eth_port_entry));
+ strcpy (eth_port_entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (eth_port_entry.port_index, "1");
+ strcpy (eth_port_entry.auto_neg, "0");
+ strcpy (eth_port_entry.speed, "1");
+ strcpy (eth_port_entry.duplex, "1");
+
+
+ system ("cp " ETH_PORT_CONF " " LIBSPID_EOC_PORT_V2_FILE);
+ ret = libspid_eoc_ethernet_port_set (eth_port_entry.mac_addr,
+ eth_port_entry.port_index,
+ &eth_port_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_ethernet_port_set failed");
+
+ ret = libspid_eoc_ethernet_port_get (eth_port_entry.mac_addr,
+ eth_port_entry.port_index,
+ &eth_port_entry_received);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_ethernet_port_get failed");
+ fail_if (strcmp (eth_port_entry.mac_addr,
+ eth_port_entry_received.mac_addr) != 0,
+ "mac addres is wrong");
+ fail_if (strcmp (eth_port_entry.port_index,
+ eth_port_entry_received.port_index) != 0,
+ "port index is wrong");
+ fail_if (strcmp (eth_port_entry.auto_neg,
+ eth_port_entry_received.auto_neg) != 0,
+ "auto neg is wrong");
+ fail_if (strcmp (eth_port_entry.speed,
+ eth_port_entry_received.speed) != 0,
+ "speed is wrong");
+ fail_if (strcmp (eth_port_entry.duplex,
+ eth_port_entry_received.duplex) != 0,
+ "duplex is wrong");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_ethernet_port_get)
+{
+ int ret;
+ char mac_addr[LIBSPID_MAC_STR_LEN];
+ char port_index[2];
+ libspid_eoc_ethernet_port_entry_t eth_port_entry;
+
+ memset (&eth_port_entry, 0, sizeof (eth_port_entry));
+ strcpy (mac_addr, "00:13:d7:00:00:01");
+ strcpy (port_index, "1");
+
+
+ system ("cp " ETH_PORT_CONF " " LIBSPID_EOC_PORT_V2_FILE);
+ ret = libspid_eoc_ethernet_port_get (mac_addr, port_index,
+ &eth_port_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_get return unsuccessful");
+ fail_if (strcmp (eth_port_entry.mac_addr, "00:13:d7:00:00:01") != 0,
+ "libspid_eoc_ethernet_port_get gets wrong mac addr");
+ fail_if (strcmp (eth_port_entry.port_index, "1") != 0,
+ "libspid_eoc_ethernet_port_get gets wrong port_index");
+ fail_if (strcmp (eth_port_entry.auto_neg, "0") != 0,
+ "libspid_eoc_ethernet_port_get gets wrong auto_neg");
+ fail_if (strcmp (eth_port_entry.speed, "1") != 0,
+ "libspid_eoc_ethernet_port_get gets wrong speed");
+ fail_if (strcmp (eth_port_entry.duplex, "1") != 0,
+ "libspid_eoc_ethernet_port_get gets wrong duplex");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_port_v2_set)
+{
+ int ret;
+
+ libspid_eoc_port_v2_entry_t eth_port_v2_entry;
+ libspid_eoc_port_v2_entry_t eth_port_v2_entry_received;
+
+ memset (&eth_port_v2_entry, 0, sizeof (eth_port_v2_entry));
+ strcpy (eth_port_v2_entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (eth_port_v2_entry.port_index, "1");
+ strcpy (eth_port_v2_entry.auto_neg, "0");
+ strcpy (eth_port_v2_entry.speed, "1");
+ strcpy (eth_port_v2_entry.duplex, "1");
+ strcpy (eth_port_v2_entry.vlan_port_pvid, "0");
+ strcpy (eth_port_v2_entry.vlan_port_tpid, "1");
+ strcpy (eth_port_v2_entry.vlan_port_prio, "2");
+ strcpy (eth_port_v2_entry.vlan_port_mode, "3");
+ strcpy (eth_port_v2_entry.bcast_protect_en, "4");
+ strcpy (eth_port_v2_entry.bcast_thres_hold, "5");
+ strcpy (eth_port_v2_entry.multi_protect_en, "6");
+ strcpy (eth_port_v2_entry.multi_thres_hold, "7");
+ strcpy (eth_port_v2_entry.unknow_protect_en, "8");
+ strcpy (eth_port_v2_entry.unknow_thres_hold, "9");
+
+ system ("cp " PORT_V2 " " LIBSPID_EOC_PORT_V2_FILE);
+ ret = libspid_eoc_port_v2_set (eth_port_v2_entry.mac_addr,
+ eth_port_v2_entry.port_index,
+ &eth_port_v2_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_ethernet_port_set failed");
+
+ ret = libspid_eoc_port_v2_get (eth_port_v2_entry.mac_addr,
+ eth_port_v2_entry.port_index,
+ &eth_port_v2_entry_received);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_ethernet_port_get failed");
+ fail_if (strcmp (eth_port_v2_entry.mac_addr,
+ eth_port_v2_entry_received.mac_addr) != 0,
+ "mac addres is wrong");
+ fail_if (strcmp (eth_port_v2_entry.port_index,
+ eth_port_v2_entry_received.port_index) != 0,
+ "port index is wrong");
+ fail_if (strcmp (eth_port_v2_entry.auto_neg,
+ eth_port_v2_entry_received.auto_neg) != 0,
+ "auto neg is wrong");
+ fail_if (strcmp (eth_port_v2_entry.speed,
+ eth_port_v2_entry_received.speed) != 0,
+ "speed is wrong");
+ fail_if (strcmp (eth_port_v2_entry.duplex,
+ eth_port_v2_entry_received.duplex) != 0,
+ "duplex is wrong");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_pvid,
+ eth_port_v2_entry_received.vlan_port_pvid) != 0,
+ "vlan_port_pvid is wrong");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_tpid,
+ eth_port_v2_entry_received.vlan_port_tpid) != 0,
+ "vlan_port_tpid is wrong");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_prio,
+ eth_port_v2_entry_received.vlan_port_prio) != 0,
+ "vlan_port_prio is wrong");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_mode,
+ eth_port_v2_entry_received.vlan_port_mode) != 0,
+ "vlan_port_mode is wrong");
+ fail_if (strcmp (eth_port_v2_entry.bcast_protect_en,
+ eth_port_v2_entry_received.bcast_protect_en) != 0,
+ "bcast_protect_en is wrong");
+ fail_if (strcmp (eth_port_v2_entry.bcast_thres_hold,
+ eth_port_v2_entry_received.bcast_thres_hold) != 0,
+ "bcast_thres_hold is wrong");
+ fail_if (strcmp (eth_port_v2_entry.multi_protect_en,
+ eth_port_v2_entry_received.multi_protect_en) != 0,
+ "multi_protect_en is wrong");
+ fail_if (strcmp (eth_port_v2_entry.multi_thres_hold,
+ eth_port_v2_entry_received.multi_thres_hold) != 0,
+ "multi_thres_hold is wrong");
+ fail_if (strcmp (eth_port_v2_entry.unknow_protect_en,
+ eth_port_v2_entry_received.unknow_protect_en) != 0,
+ "unknow_protect_en is wrong");
+ fail_if (strcmp (eth_port_v2_entry.unknow_thres_hold,
+ eth_port_v2_entry_received.unknow_thres_hold) != 0,
+ "unknow_thres_hold is wrong");
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_port_v2_get)
+{
+ int ret;
+ char mac_addr[LIBSPID_MAC_STR_LEN];
+ char port_index[2];
+ libspid_eoc_port_v2_entry_t eth_port_v2_entry;
+
+ memset (&eth_port_v2_entry, 0, sizeof (eth_port_v2_entry));
+ strcpy (mac_addr, "00:13:d7:00:00:02");
+ strcpy (port_index, "2");
+
+
+ system ("cp " PORT_V2 " " LIBSPID_EOC_PORT_V2_FILE);
+ ret = libspid_eoc_port_v2_get (mac_addr, port_index,
+ &eth_port_v2_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_port_v2_get return unsuccessful");
+ fail_if (strcmp (eth_port_v2_entry.mac_addr, "00:13:d7:00:00:02") != 0,
+ "libspid_eoc_port_v2_get gets wrong mac addr");
+ fail_if (strcmp (eth_port_v2_entry.port_index, "2") != 0,
+ "libspid_eoc_port_v2_get gets wrong port_index");
+ fail_if (strcmp (eth_port_v2_entry.auto_neg, "1") != 0,
+ "libspid_eoc_port_v2_get gets wrong auto_neg");
+ fail_if (strcmp (eth_port_v2_entry.speed, "2") != 0,
+ "libspid_eoc_port_v2_get gets wrong speed");
+ fail_if (strcmp (eth_port_v2_entry.duplex, "2") != 0,
+ "libspid_eoc_port_v2_get gets wrong duplex");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_pvid, "0") != 0,
+ "libspid_eoc_port_v2_get gets wrong vlan_port_pvid");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_tpid, "33024") != 0,
+ "libspid_eoc_port_v2_get gets wrong vlan_port_tpid");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_prio, "0") != 0,
+ "libspid_eoc_port_v2_get gets wrong vlan_port_prio");
+ fail_if (strcmp (eth_port_v2_entry.vlan_port_mode, "0") != 0,
+ "libspid_eoc_port_v2_get gets wrong vlan_port_mode");
+ fail_if (strcmp (eth_port_v2_entry.bcast_protect_en, "0") != 0,
+ "libspid_eoc_port_v2_get gets wrong bcast_protect_en");
+ fail_if (strcmp (eth_port_v2_entry.bcast_thres_hold, "107") != 0,
+ "libspid_eoc_port_v2_get gets wrong bcast_thres_hold");
+ fail_if (strcmp (eth_port_v2_entry.multi_protect_en, "0") != 0,
+ "libspid_eoc_port_v2_get gets wrong multi_protect_en");
+ fail_if (strcmp (eth_port_v2_entry.multi_thres_hold, "207") != 0,
+ "libspid_eoc_port_v2_get gets wrong multi_thres_hold");
+ fail_if (strcmp (eth_port_v2_entry.unknow_protect_en, "0") != 0,
+ "libspid_eoc_port_v2_get gets wrong unknow_protect_en");
+ fail_if (strcmp (eth_port_v2_entry.unknow_thres_hold, "8") != 0,
+ "libspid_eoc_port_v2_get gets wrong unknow_thres_hold");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_ethernet_port_get_list)
+{
+ int ret;
+ libspid_eoc_ethernet_port_entry_t entries[ETH_PORT_ENTRY_NUM];
+ int idx;
+ int line_count = ETH_PORT_ENTRY_NUM;
+
+ /* Expected results */
+ char mac_addr[ETH_PORT_ENTRY_NUM][LIBSPID_MAC_STR_LEN] =
+ { "00:13:d7:00:00:01", "00:13:d7:00:00:01", "00:13:d7:00:00:01",
+ "00:13:d7:00:00:01", "00:13:d7:00:00:01", "00:13:d7:00:00:02",
+ "00:13:d7:00:00:02", "00:13:d7:00:00:02", "00:13:d7:00:00:02",
+ "00:13:d7:00:00:02", "00:13:d7:00:00:65", "00:13:d7:00:00:65",
+ "00:13:d7:00:00:65", "00:13:d7:00:00:65", "00:13:d7:00:00:65",
+ "00:13:d7:00:00:66", "00:13:d7:00:00:66", "00:13:d7:00:00:66",
+ "00:13:d7:00:00:66", "00:13:d7:00:00:66"
+ };
+ char port_index[ETH_PORT_ENTRY_NUM][2] =
+ { "0", "1", "2", "3", "4", "0", "1", "2", "3", "4",
+ "0", "1", "2", "3", "4", "0", "1", "2", "3", "4"};
+ char auto_neg[ETH_PORT_ENTRY_NUM][2] =
+ { "0", "0", "0", "0", "0", "0", "0", "0", "0", "0",
+ "0", "0", "0", "0", "0", "0", "0", "0", "0", "0"};
+ char speed[ETH_PORT_ENTRY_NUM][4] =
+ { "2", "1", "2", "2", "2", "2", "2", "2", "2", "2",
+ "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"};
+ char duplex[ETH_PORT_ENTRY_NUM][2] =
+ { "2", "1", "2", "2", "2", "2", "2", "2", "2", "2",
+ "2", "2", "2", "2", "2", "2", "2", "2", "2", "2"};
+
+ memset (entries, 0, ETH_PORT_ENTRY_NUM *
+ sizeof (libspid_eoc_ethernet_port_entry_t));
+
+ system ("cp " ETH_PORT_CONF " " LIBSPID_EOC_PORT_V2_FILE);
+
+ ret = libspid_eoc_ethernet_port_get_list (entries, &line_count);
+
+ fail_if (line_count != ETH_PORT_ENTRY_NUM,
+ "libspid_eoc_ethernet_port_get_list returns wrong count");
+
+ for (idx = 0; idx < ETH_PORT_ENTRY_NUM; idx++)
+ {
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_get_list return is"
+ " unsuccessful");
+ fail_if (strcmp (entries[idx].mac_addr, mac_addr[idx]) != 0,
+ "libspid_eoc_ethernet_port_get_list gets wrong mac addr");
+ fail_if (strcmp (entries[idx].port_index, port_index[idx]) != 0,
+ "libspid_eoc_ethernet_port_get_list gets wrong"
+ " port_index");
+ fail_if (strcmp (entries[idx].auto_neg, auto_neg[idx]) != 0,
+ "libspid_eoc_ethernet_port_get_list gets wrong auto_neg");
+ fail_if (strcmp (entries[idx].speed, speed[idx]) != 0,
+ "libspid_eoc_ethernet_port_get_list gets wrong speed");
+ fail_if (strcmp (entries[idx].duplex, duplex[idx]) != 0,
+ "libspid_eoc_ethernet_port_get_list gets wrong duplex");
+ }
+
+}
+
+
+END_TEST
+
+START_TEST (test_libspid_eoc_ethernet_port_check)
+{
+ int ret;
+ libspid_eoc_ethernet_port_entry_t eth_port_entry;
+
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " ETH_PORT_CONF " " LIBSPID_EOC_PORT_V2_FILE);
+
+ ret = libspid_eoc_ethernet_port_check ();
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_check return is unsuccessful");
+
+ /* add wrong duplex parameter */
+ memset (&eth_port_entry, 0, sizeof (eth_port_entry));
+ strcpy (eth_port_entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (eth_port_entry.port_index, "1");
+ strcpy (eth_port_entry.auto_neg, "0");
+ strcpy (eth_port_entry.speed, "2");
+ strcpy (eth_port_entry.duplex, "a");
+
+ ret = libspid_eoc_ethernet_port_set (eth_port_entry.mac_addr,
+ eth_port_entry.port_index,
+ &eth_port_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_ethernet_port_set failed");
+
+ ret = libspid_eoc_ethernet_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_check must return unsuccessful");
+
+ /* add wrong speed parameter */
+ memset (&eth_port_entry, 0, sizeof (eth_port_entry));
+ strcpy (eth_port_entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (eth_port_entry.port_index, "1");
+ strcpy (eth_port_entry.auto_neg, "0");
+ strcpy (eth_port_entry.speed, "a");
+ strcpy (eth_port_entry.duplex, "2");
+
+ ret = libspid_eoc_ethernet_port_set (eth_port_entry.mac_addr,
+ eth_port_entry.port_index,
+ &eth_port_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_ethernet_port_set failed");
+
+ ret = libspid_eoc_ethernet_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_check must return unsuccessful");
+
+ /* add wrong auto_neg parameter */
+ memset (&eth_port_entry, 0, sizeof (eth_port_entry));
+ strcpy (eth_port_entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (eth_port_entry.port_index, "1");
+ strcpy (eth_port_entry.auto_neg, "a");
+ strcpy (eth_port_entry.speed, "2");
+ strcpy (eth_port_entry.duplex, "2");
+
+ ret = libspid_eoc_ethernet_port_set (eth_port_entry.mac_addr,
+ eth_port_entry.port_index,
+ &eth_port_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_ethernet_port_set failed");
+
+ ret = libspid_eoc_ethernet_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_check must return unsuccessful");
+
+
+ system ("cp " ETH_PORT_MAC_CONF_1 " "
+ LIBSPID_EOC_PORT_V2_FILE);
+
+ ret = libspid_eoc_ethernet_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_check must return unsuccessful");
+
+ system ("cp " ETH_PORT_MAC_CONF_2 " "
+ LIBSPID_EOC_PORT_V2_FILE);
+
+ ret = libspid_eoc_ethernet_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_ethernet_port_check must return unsuccessful");
+
+
+}
+END_TEST
+
+TCase * tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+extern Suite *
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_ethernet_port_set);
+ tcase_add_test (tc_core, test_libspid_eoc_ethernet_port_get);
+ tcase_add_test (tc_core, test_libspid_eoc_ethernet_port_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_ethernet_port_check);
+ tcase_add_test (tc_core, test_libspid_eoc_port_v2_set);
+ tcase_add_test (tc_core, test_libspid_eoc_port_v2_get);
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/hardware_utests.c b/cleopatre/devkit/tests/libspid/utests/src/hardware_utests.c
new file mode 100644
index 0000000000..f9b7d9932a
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/hardware_utests.c
@@ -0,0 +1,162 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2008 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file hardware_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for libspid hardware.c
+ */
+
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include "../../linux/gpio.h"
+
+#include "inc/network_utests.h"
+
+/* Local gpio value. */
+#define TEST_SCR300_OPEN_CLOSE_IND_GPIO_NUM 6
+
+/* local variables */
+static int test_gpio_value;
+
+/* Ioctl stub for gpio. */
+int
+ioctl (int d, unsigned long int request, void *argp)
+{
+ if (!argp)
+ {
+ printf ("%s: invalid arguments\n", __FUNCTION__);
+ return -1;
+ }
+
+ union gpio_info *tamper_gpio = (union gpio_info *)argp;
+ if (GPIOIOC_SETDIRECTION == request)
+ {
+ if (tamper_gpio->gpiodir.dir != SPC300_GPIO_DIRECTION_INPUT)
+ return -2;
+ if (tamper_gpio->gpiodir.num != TEST_SCR300_OPEN_CLOSE_IND_GPIO_NUM)
+ return -3;
+ }
+ else if (GPIOIOC_GETVALUE == request)
+ {
+ if (tamper_gpio->gpiodir.num != TEST_SCR300_OPEN_CLOSE_IND_GPIO_NUM)
+ return -4;
+ tamper_gpio->gpioval.val = test_gpio_value;
+ }
+ else
+ {
+ printf ("%s: invalid request\n", __FUNCTION__);
+ return -5;
+ }
+
+ return 0;
+}
+
+/* Fixtures - run before and after each unit test. */
+void setup(void)
+{
+ int ret;
+ char buf[256];
+ struct dirent *d;
+ DIR *dir;
+
+ ret = mkdir(UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit(EXIT_FAILURE);
+ }
+
+ /* Initialize - delete all files which have left from previous testing. */
+ dir = opendir(UTESTS_TMP_DIR);
+
+ while ( (d = readdir(dir)) != NULL )
+ {
+ sprintf(buf, "%s/%s", "/tmp/utests", d->d_name);
+ remove(buf);
+ }
+ /* Fake gpio. Ordinary file. */
+ int fd = open (LIBSPID_GPIO_DEVICE_NAME, O_CREAT, S_IRUSR | S_IWUSR);
+ if (fd < 0)
+ {
+ perror("file could not be created\n");
+ exit(EXIT_FAILURE);
+ }
+ close (fd);
+}
+
+void teardown(void)
+{
+ /* Clean tmp. */
+ system("rm -rf "UTESTS_TMP_DIR);
+}
+
+START_TEST (test_tamper)
+{
+ int ret;
+ libspid_eoc_tamper_status_t tamper_status;
+
+ ret = libspid_hardware_get_tamper (&tamper_status);
+ fail_if (ret != LIBSPID_SUCCESS, "Error reading gpio");
+ /* Test intact. */
+ test_gpio_value = 0;
+ ret = libspid_hardware_get_tamper (&tamper_status);
+ fail_if (ret != LIBSPID_SUCCESS, "Error reading gpio");
+ fail_if (tamper_status != LIBSPID_TAMPER_STATUS_INTACT, "grio read error");
+ /* Test compromized. */
+ test_gpio_value = 1;
+ ret = libspid_hardware_get_tamper (&tamper_status);
+ fail_if (ret != LIBSPID_SUCCESS, "Error reading gpio");
+ fail_if (tamper_status != LIBSPID_TAMPER_STATUS_COMPROMISED,
+ "grio read error");
+}
+END_TEST
+
+extern Suite* libspid_hw_suite(void)
+{
+ Suite *s = suite_create("LIBSPID_HARDWARE");
+ TCase *tc_core = tcase_create("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ tcase_add_test(tc_core, test_tamper);
+ suite_add_tcase(s, tc_core);
+ return s;
+}
+
+int main(void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ /* Run network tests. */
+ s = libspid_hw_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;
+}
+
diff --git a/cleopatre/devkit/tests/libspid/utests/src/igmp_snooping_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/igmp_snooping_eoc_utests.c
new file mode 100644
index 0000000000..ee12ce108e
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/igmp_snooping_eoc_utests.c
@@ -0,0 +1,300 @@
+/*
+*Cleopatre project {{{
+* Copyright (C) 2012 MStar
+* <<<Licence>>>
+* }}}
+*/
+
+/**
+* \file igmp_snooping_eoc_utests.c
+* \brief Unitary tests for libspid
+* \ingroup Cleopatre - libspid
+*
+* This file content all the unitary tests for EoC SPiDLib.
+*/
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h>
+#include <string.h>
+#include "eoc_utests.h"
+#include "libspid.h"
+
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define IGMP_CONF "testfiles/igmp.conf"
+#define TMP_IGMP_CONF "testfiles/igmp_check.conf"
+#define IGMP_DUMAC_CONF "testfiles/igmp_dumac.conf"
+
+
+
+static void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+
+
+void
+teardown (void)
+{
+
+}
+
+static void entry_cmp_equ (
+ libspid_eoc_igmp_snooping_entry_t *entry1,
+ libspid_eoc_igmp_snooping_entry_t *entry2)
+{
+ int ret;
+ ret = strcmp (entry1->mac_addr, entry2->mac_addr);
+ fail_if (0 != ret, "mac_address must equ");
+
+ ret = strcmp (entry1->igmp_snooping_en, entry2->igmp_snooping_en);
+ fail_if (0 != ret, "igmp_snooping_en must equ");
+
+}
+
+START_TEST (test_libspid_eoc_igmp_snooping_get)
+{
+ int ret;
+ char mac_address[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_igmp_snooping_entry_t entry, entry2;
+
+ ret = libspid_eoc_igmp_snooping_get (0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ strcpy (mac_address, "00:13:d7:00:00:00");
+ ret = libspid_eoc_igmp_snooping_get (mac_address, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ strcpy (mac_address, "00:13:d7:00:00:00");
+ ret = libspid_eoc_igmp_snooping_get (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of no config file");
+
+ system ("cp " IGMP_CONF" " LIBSPID_IGMP_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ strcpy (mac_address, "00:13:d7:00:00:00");
+ ret = libspid_eoc_igmp_snooping_get (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, not have this mac_address");
+
+ strcpy (mac_address, "00:13:d7:00:00:01");
+ ret = libspid_eoc_igmp_snooping_get (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must success");
+
+ strcpy (entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (entry.igmp_snooping_en, "1");
+
+ ret = libspid_eoc_igmp_snooping_set (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_igmp_snooping_get (mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entry2);
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_igmp_snooping_get_list)
+{
+ int ret = 0;
+ int cnt = 0 ;
+ int i = 0;
+ libspid_eoc_igmp_snooping_entry_t entry;
+ libspid_eoc_igmp_snooping_entry_t
+ entries[LIBSPID_EOC_IGMP_SNOOPING_ITMES_MAX];
+
+ ret = libspid_eoc_igmp_snooping_get_list (0, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ ret = libspid_eoc_igmp_snooping_get_list (entries, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ ret = libspid_eoc_igmp_snooping_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of none config file");
+
+ system ("cp " IGMP_CONF" " LIBSPID_IGMP_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_igmp_snooping_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (4 != cnt, "Get List Items error");
+
+ for (i = 0 ; i < cnt ; i ++)
+ {
+ ret = libspid_eoc_igmp_snooping_get (entries[i].mac_addr, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entries[i]);
+ }
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_igmp_snooping_set)
+{
+ int ret = 0;
+ char mac_address[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_igmp_snooping_entry_t entry, entry2;
+
+ ret = libspid_eoc_igmp_snooping_set (0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ strcpy (mac_address, "00:13:d7:00:00:01");
+ ret = libspid_eoc_igmp_snooping_set (mac_address, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 2 error");
+
+ system ("cp " IGMP_CONF" " LIBSPID_IGMP_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ strcpy (entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (entry.igmp_snooping_en, "1");
+
+ ret = libspid_eoc_igmp_snooping_set (mac_address, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_igmp_snooping_get (mac_address, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ entry_cmp_equ (&entry, &entry2);
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_igmp_snooping_check)
+{
+ int ret = 0;
+ libspid_eoc_igmp_snooping_entry_t entry, entry2;
+
+ strcpy (entry.mac_addr, "00:13:d7:00:00:01");
+ strcpy (entry.igmp_snooping_en, "1");
+
+ ret = libspid_eoc_igmp_snooping_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of none config file");
+
+ setup ();
+ system ("cp " IGMP_CONF" " LIBSPID_IGMP_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_igmp_snooping_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_igmp_snooping_set (entry.mac_addr, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_igmp_snooping_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ /* check mac_address int whitelist but not in igmp*/
+ setup ();
+ system ("cp " TMP_IGMP_CONF" " LIBSPID_IGMP_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_igmp_snooping_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of whitelist mac is"
+ " not in igmp config file");
+
+
+ /* check mac_address is unique*/
+ setup ();
+ system ("cp " IGMP_DUMAC_CONF" " LIBSPID_IGMP_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_igmp_snooping_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of MAC is not unique");
+
+
+ /* check igmp_snooping_en*/
+ setup ();
+ system ("cp " IGMP_CONF" " LIBSPID_IGMP_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memcpy (&entry2, &entry, sizeof (entry));
+ strcpy (entry2.igmp_snooping_en, "2");
+
+ ret = libspid_eoc_igmp_snooping_set (entry2.mac_addr, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_igmp_snooping_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of igmp_snooping_en error");
+
+}
+END_TEST
+
+Suite *
+libspid_eoc_suite ()
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_igmp_snooping_get);
+ tcase_add_test (tc_core, test_libspid_eoc_igmp_snooping_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_igmp_snooping_set);
+ tcase_add_test (tc_core, test_libspid_eoc_igmp_snooping_check);
+
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_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;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/image_utests.c b/cleopatre/devkit/tests/libspid/utests/src/image_utests.c
index dca2ea55b2..bd271b3611 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/image_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/image_utests.c
@@ -435,7 +435,7 @@ extern Suite* libspid_image_suite(void)
//Test system_init
tcase_add_test(tc_core, test_libspid_image_get_desc);
- tcase_add_test(tc_core, test_libspid_image_get_index);
+ tcase_add_test (tc_core, test_libspid_image_get_index);
tcase_add_test(tc_core, test_libspid_image_select);
suite_add_tcase(s, tc_core);
diff --git a/cleopatre/devkit/tests/libspid/utests/src/maclimit_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/maclimit_eoc_utests.c
new file mode 100644
index 0000000000..5d0ce6c8be
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/maclimit_eoc_utests.c
@@ -0,0 +1,367 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2012 MStar
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file maclimit_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+# define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+# define TRACE(...)
+#endif
+
+/* local constants */
+#define MACLIMIT_CONF "testfiles/maclimit.conf"
+#define SLAVE_CONF "testfiles/slave.conf"
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define TMP_MACLIMIT_CONF "testfiles/maclimit_check.conf"
+#define MACLIMIT_DUMAC_CONF "testfiles/maclimitation_dumac.conf"
+
+
+#define MACLIMIT_ENTRY_NUM 4
+#define LIMIT_DEFAULT_NUM 4
+
+
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+
+ char mac_addr[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_maclimit_entry_t eoc_maclimit_entry;
+ int count;
+
+
+ memset (mac_addr, 0x0, LIBSPID_MAC_STR_LEN);
+ memset (&eoc_maclimit_entry, 0x0,
+ sizeof (libspid_eoc_maclimit_entry_t));
+ count = 1;
+
+ /* check input parameters for libspid_eoc_maclimit_set */
+ /* eoc_maclimit_entry = NULL */
+ ret = libspid_eoc_maclimit_set (mac_addr, NULL);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "eoc_maclimit_set eoc_maclimit_entry = NULL");
+
+ /* mac_addr = NULL */
+ ret = libspid_eoc_maclimit_set (NULL, &eoc_maclimit_entry);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "eoc_maclimit_set mac_addr = NULL");
+
+
+ /* check input parameters for libspid_eoc_maclimit_get */
+ /* mac_addr = NULL */
+ ret = libspid_eoc_maclimit_get (NULL, &eoc_maclimit_entry);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "eoc_maclimit_get mac_addr = NULL");
+
+ /* eoc_maclimit_entry = NULL */
+ ret = libspid_eoc_maclimit_get (mac_addr, NULL);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "eoc_maclimit_get eoc_maclimit_entry = NULL");
+
+
+ /* check input parameters for libspid_eoc_maclimit_get_list */
+ /* entries = NULL */
+ libspid_eoc_maclimit_get_list (NULL, &count);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "eoc_maclimit_get_list entries = NULL");
+
+ /* count = NULL */
+ libspid_eoc_maclimit_get_list (&eoc_maclimit_entry, NULL);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "eoc_maclimit_get_list entries = NULL");
+
+
+ /* check input parameters for libspid_eoc_maclimit_get_defaultnum */
+ /* num = NULL */
+ libspid_eoc_maclimit_get_defaultnum (NULL);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "eoc_maclimit_get_defaultnum num = NULL");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_maclimit_check)
+{
+ int ret;
+ libspid_eoc_maclimit_entry_t eoc_maclimit_entry;
+
+ memset (&eoc_maclimit_entry, 0, sizeof (eoc_maclimit_entry));
+
+ system ("cp " MACLIMIT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+
+ /* a right data to be checked */
+ ret = libspid_eoc_maclimit_check ();
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_maclimit_check fail");
+
+
+ /* bad mac_limitation_num to be checked */
+ memset (&eoc_maclimit_entry, 0, sizeof (eoc_maclimit_entry));
+ strcpy (eoc_maclimit_entry.mac_addr, "00:13:d7:00:00:02");
+ strcpy (eoc_maclimit_entry.mac_limitation_num, "513");
+
+ libspid_eoc_maclimit_set (eoc_maclimit_entry.mac_addr,
+ &eoc_maclimit_entry);
+
+ ret = libspid_eoc_maclimit_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_maclimit_check fail wrong limition num(>512)");
+
+
+ /* bad depends with white list */
+ system ("cp " TMP_MACLIMIT_CONF " " UTESTS_TMP_DIR "/etc/"
+ "maclimitation.conf");
+
+ ret = libspid_eoc_maclimit_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_maclimit_check fail wrong mac in wl but not in "
+ " maclimit");
+
+ ret = system ("cp " MACLIMIT_DUMAC_CONF " " UTESTS_TMP_DIR "/etc/"
+ "maclimitation.conf");
+
+ ret = libspid_eoc_maclimit_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_maclimit_check fail wrong because of double mac"
+ "in maclimitation.conf");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_maclimit_set)
+{
+ int ret;
+ char mac_addr[LIBSPID_MAC_STR_LEN];
+
+ libspid_eoc_maclimit_entry_t eoc_maclimit_entry;
+
+ memset (&eoc_maclimit_entry, 0, sizeof (eoc_maclimit_entry));
+ strcpy (eoc_maclimit_entry.mac_addr, "00:13:d7:00:00:02");
+ strcpy (eoc_maclimit_entry.mac_limitation_num, "45");
+
+ system ("cp " MACLIMIT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_maclimit_set (eoc_maclimit_entry.mac_addr,
+ &eoc_maclimit_entry);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_maclimit_set fail");
+
+
+ /* To check if it saved success */
+ strcpy (mac_addr, "00:13:D7:00:00:02");
+ memset (&eoc_maclimit_entry, 0, sizeof (eoc_maclimit_entry));
+
+ ret = libspid_eoc_maclimit_get (mac_addr, &eoc_maclimit_entry);
+
+ fail_if (ret == LIBSPID_ERROR_NOT_FOUND,
+ "libspid_eoc_maclimit_set not write or save success");
+ fail_if (strcmp (eoc_maclimit_entry.mac_addr, "00:13:d7:00:00:02") != 0,
+ "libspid_eoc_maclimit_set set wrong mac addr");
+ fail_if (strcmp (eoc_maclimit_entry.mac_limitation_num, "45") != 0,
+ "libspid_eoc_maclimit_set set wrong mac_limitation_num");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_maclimit_get)
+{
+ int ret;
+ char mac_addr[LIBSPID_MAC_STR_LEN];
+ char mac_limit_nm[4];
+ libspid_eoc_maclimit_entry_t eoc_maclimit_entry;
+
+
+ memset (&eoc_maclimit_entry, 0, sizeof (eoc_maclimit_entry));
+ strcpy (mac_addr, "00:13:d7:00:00:01");
+ strcpy (mac_limit_nm, "45");
+
+ system ("cp " MACLIMIT_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_maclimit_get (mac_addr, &eoc_maclimit_entry);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_maclimit_get return unsuccessful");
+ fail_if (strcmp (eoc_maclimit_entry.mac_addr, mac_addr) != 0,
+ "libspid_eoc_maclimit_get gets wrong mac addr");
+ fail_if (strcmp (eoc_maclimit_entry.mac_limitation_num, mac_limit_nm) !=
+ 0, "libspid_eoc_maclimit_get gets wrong mac_limitation_num");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_maclimit_get_list)
+{
+ int ret;
+ libspid_eoc_maclimit_entry_t entries[MACLIMIT_ENTRY_NUM];
+ int idx;
+ int mac_count = MACLIMIT_ENTRY_NUM;
+
+ /* Expected results */
+ char mac_addr[MACLIMIT_ENTRY_NUM][LIBSPID_MAC_STR_LEN] =
+ { "00:13:d7:00:00:01",
+ "00:13:d7:00:00:02",
+ "00:13:d7:00:00:65",
+ "00:13:d7:00:00:66"
+ };
+ char mac_limit_nm[MACLIMIT_ENTRY_NUM][4] = { "45", "46", "47", "48" };
+
+ memset (entries, 0,
+ MACLIMIT_ENTRY_NUM * sizeof (libspid_eoc_maclimit_entry_t));
+
+ system ("cp " MACLIMIT_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_maclimit_get_list (entries, &mac_count);
+
+ fail_if (mac_count != MACLIMIT_ENTRY_NUM,
+ "libspid_eoc_maclimit_get_list returns wrong count");
+
+ for (idx = 0; idx < MACLIMIT_ENTRY_NUM; idx++)
+ {
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_maclimit_get_list return is unsuccessful");
+ fail_if (strcmp (entries[idx].mac_addr, mac_addr[idx]) != 0,
+ "libspid_eoc_maclimit_get_list corrupts mac address");
+ fail_if (strcmp (entries[idx].mac_limitation_num, mac_limit_nm[idx])
+ != 0,
+ "libspid_eoc_maclimit_get_list gets wrong mac_limit_nm");
+ }
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_maclimit_get_defaultnum)
+{
+ int ret;
+ int num = 0;
+
+ system ("cp " SLAVE_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_maclimit_get_defaultnum (NULL);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "libspid_eoc_maclimit_get_defaultnum param is NULL");
+
+ ret = libspid_eoc_maclimit_get_defaultnum (&num);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_maclimit_get_defaultnum return unsuccessful");
+ fail_if (num != LIMIT_DEFAULT_NUM,
+ "libspid_eoc_maclimit_get_defaultnum gets wrong default"
+ " value");
+}
+
+END_TEST TCase * tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+extern Suite *
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_maclimit_check);
+ tcase_add_test (tc_core, test_libspid_eoc_maclimit_set);
+ tcase_add_test (tc_core, test_libspid_eoc_maclimit_get);
+ tcase_add_test (tc_core, test_libspid_eoc_maclimit_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_maclimit_get_defaultnum);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/master_config_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/master_config_eoc_utests.c
new file mode 100644
index 0000000000..d89bd26e55
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/master_config_eoc_utests.c
@@ -0,0 +1,321 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define NETWORK_BR_TST "testfiles/network_br.tst"
+#define MASTER_CONF "testfiles/master.conf"
+#define SYSTEM_CONF "testfiles/system.conf"
+#define SNMPD_CONF "testfiles/snmpd.conf"
+#define MASTER_TAR "testfiles/master.tar"
+#define UPDATE_INFO "testfiles/update.info"
+#define HOSTNAME "testfiles/hostname"
+#define SAVE_FILE "testfiles/save.lst"
+#define BACKUP_CONF "testfiles/confbak.conf"
+
+/** local variables */
+
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ struct dirent *d;
+ DIR *dir;
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* initialize - delete all files which have left from previous testing */
+ dir = opendir (UTESTS_TMP_DIR);
+
+ while ((d = readdir (dir)) != NULL)
+ {
+ sprintf (buf, "%s/%s", "/tmp/utests", d->d_name);
+ remove (buf);
+ }
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ sprintf (buf, "%s/etc/network", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc/network, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ sprintf (buf, "%s/etc/snmp", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc/snmp, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ sprintf (buf, "%s/local", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/local, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+START_TEST (test_libspid_eoc_master_vlan_action)
+{
+ int ret;
+
+ /* prepare configuration files */
+ system ("cp " NETWORK_BR_TST " " LIBSPID_NETWORK_CONF_PATH );
+ system ("cp " MASTER_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_master_vlan_action ();
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_master_vlan_action fail");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_master_disable_vlan_action)
+{
+ int ret;
+
+ /* prepare configuration files */
+ system ("cp " NETWORK_BR_TST " " LIBSPID_NETWORK_CONF_PATH );
+ system ("cp " MASTER_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_master_disable_vlan_action ();
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_master_disable_vlan_action fail");
+}
+END_TEST
+
+/* --- TEST PROCEDURES --- */
+START_TEST (test_libspid_eoc_upload_master_config)
+{
+ int rc, ret;
+ char filename[] = "master.tar";
+ char buf[256];
+ char *ext;
+
+ /* prepare configuration files */
+ rc = system ("cp " SYSTEM_CONF " " UTESTS_TMP_DIR "/etc");
+ rc = system ("cp " NETWORK_BR_TST " " LIBSPID_NETWORK_CONF_PATH);
+ rc = system ("cp " SNMPD_CONF " " LIBSPID_SNMPD_CONF_PATH);
+ rc = system ("cp " UPDATE_INFO " " LIBSPID_UPDATE_INFO_PATH);
+ rc = system ("cp " HOSTNAME " " LIBSPID_EOC_HOSTNAME);
+ rc = system ("cp " SAVE_FILE " " LIBSPID_SAVE_LIST_PATH);
+
+ ret = libspid_eoc_upload_master_config (filename);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_upload_master_config");
+
+ sprintf (buf, "%s%s", LIBSPID_EOC_TMP_PATH, filename);
+
+ /* Check if configuration archive really exists */
+ rc = access (buf, F_OK);
+ fail_if (rc != 0, "Configuration archive doesn't exist");
+
+ /* Check if given archive is a .tar file */
+ ext = strchr (buf, '.');
+ fail_if (strcmp (ext, ".tar") != 0, "Given file is not a .tar archive");
+
+}
+END_TEST
+
+/* --- TEST PROCEDURES --- */
+START_TEST (test_libspid_eoc_download_master_config)
+{
+ int rc, ret;
+ char file[] = "master.tar";
+ char buf[256];
+
+ /* prepare configuration files */
+ rc = system ("cp " SYSTEM_CONF " " UTESTS_TMP_DIR "/etc");
+ rc = system ("cp " MASTER_TAR " " LIBSPID_EOC_TMP_PATH);
+
+ ret = libspid_eoc_download_master_config (file);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_download_master_config");
+
+ sprintf (buf, "%s/master.conf", LIBSPID_CONF_SAVE_PATH);
+
+ /* Check if configuration file really exists */
+ rc = access (buf, F_OK);
+ fail_if (rc != 0, "Configuration file doesn't exist");
+
+ sprintf (buf, "%s/network/interfaces", LIBSPID_CONF_SAVE_PATH);
+
+ /* Check if configuration file really exists */
+ rc = access (buf, F_OK);
+ fail_if (rc != 0, "Configuration file doesn't exist");
+
+ sprintf (buf, "%s/snmp/snmpd.conf", LIBSPID_CONF_SAVE_PATH);
+
+ /* Check if configuration file really exists */
+ rc = access (buf, F_OK);
+ fail_if (rc != 0, "Configuration file doesn't exist");
+
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_backup_recover_master_config)
+{
+ int ret;
+ unsigned int i = 0;
+ unsigned int count;
+ libspid_eoc_config_backup_entry_t entries[LIBSPID_CONFIG_BACKUP_ITEM_MAX];
+
+ ret = libspid_eoc_backup_recover_master_config (1);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail,"
+ " because of none config file");
+
+ setup ();
+ system ("cp " BACKUP_CONF" " LIBSPID_CONFIG_BACKUP_PATH);
+ system ("cp " SYSTEM_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " NETWORK_BR_TST " " LIBSPID_NETWORK_CONF_PATH);
+ system ("cp " SNMPD_CONF " " LIBSPID_SNMPD_CONF_PATH);
+ system ("cp " UPDATE_INFO " " LIBSPID_UPDATE_INFO_PATH);
+ system ("cp " HOSTNAME " " LIBSPID_EOC_HOSTNAME);
+ system ("cp " SAVE_FILE " " LIBSPID_SAVE_LIST_PATH);
+
+ ret = libspid_eoc_backup_recover_master_config (0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ ret = libspid_eoc_backup_recover_master_config (3);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of param 1 error");
+
+ ret = libspid_eoc_backup_recover_master_config (LIBSPID_CONFIG_BACKUP);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_get_list (entries, &count);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ for (i = 0; i < count ; i ++)
+ {
+ ret = strcmp (entries[i].result, LIBSPID_CONFIG_BACKUP_RESULT_SUC);
+ fail_if (0 != ret, "must equ suc");
+ }
+
+ ret = libspid_eoc_backup_recover_master_config (LIBSPID_CONFIG_RECOVER);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_config_backup_get_list (entries, &count);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ for (i = 0; i < count ; i ++)
+ {
+ ret = strcmp (entries[i].result, LIBSPID_CONFIG_BACKUP_RESULT_SUC);
+ fail_if (0 != ret, "must equ suc");
+ }
+}
+END_TEST
+
+extern Suite* libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_master_vlan_action);
+ tcase_add_test (tc_core, test_libspid_eoc_master_disable_vlan_action);
+ tcase_add_test (tc_core, test_libspid_eoc_upload_master_config);
+ tcase_add_test (tc_core, test_libspid_eoc_download_master_config);
+ tcase_add_test (tc_core, test_libspid_eoc_backup_recover_master_config);
+ suite_add_tcase (s, tc_core);
+
+ return s;
+}
+
+int main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/misc_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/misc_eoc_utests.c
new file mode 100644
index 0000000000..f6c6a27573
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/misc_eoc_utests.c
@@ -0,0 +1,323 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define ONLINE_INFO "testfiles/online.info"
+
+/** local variables */
+typedef char mac_t[6];
+typedef char mac_string_t[18];
+
+/* fixtures - run before and after each unit test */
+void
+setup(void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown(void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char mac_address_list, mac_address;
+ int mac_address_count = 0;
+ libspid_eoc_dev_info_t eoc_dev_info;
+ libspid_eoc_link_quality_t eoc_link_quality;
+ libspid_eoc_rt_stat_t eoc_rt_stat;
+
+ /* mac_address_list = NULL */
+ ret = libspid_eoc_get_topo (NULL, &mac_address_count);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address_list = NULL");
+
+ /* mac_address_count = NULL */
+ ret = libspid_eoc_get_topo (&mac_address_list, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address_count = NULL");
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_get_device_info (NULL, &eoc_dev_info);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* eoc_dev_info = NULL */
+ ret = libspid_eoc_get_device_info (&mac_address, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eoc_dev_info = NULL");
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_get_link (NULL, &eoc_link_quality);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* eoc_link_quality = NULL */
+ ret = libspid_eoc_get_link (&mac_address, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eoc_link_quality = NULL");
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_reset_stat (NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+ ret = libspid_eoc_get_stat (NULL, &eoc_rt_stat);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* eoc_rt_stat = NULL */
+ ret = libspid_eoc_get_stat (&mac_address, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eoc_rt_stat = NULL");
+}
+END_TEST
+
+/* Tests that should pass */
+START_TEST (test_libspid_eoc_reboot)
+{
+ int ret;
+ mac_t mac_address;
+
+ ret = libspid_eoc_reboot (mac_address);
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_reboot fails");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_factory)
+{
+ int ret;
+ mac_t mac_address = {0x0, 0x11, 0x22, 0x33, 0x44, 0x55};
+
+ ret = libspid_eoc_factory (0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of param 1 error");
+
+ ret = libspid_eoc_factory (mac_address);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_get_topo)
+{
+ int ret;
+ mac_t mac_address_list[5];
+ int mac_address_count = 0;
+
+ system ("cp " ONLINE_INFO " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_get_topo (mac_address_list[0], &mac_address_count);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_get_topo fail");
+ fail_if (strcmp (mac_address_list[0], "\x00\xd7\x20\x00\x00\x01") != 0,
+ "libspid_eoc_get_topo gets wrong mac address 1");
+ fail_if (strcmp (mac_address_list[1], "\x00\xd7\x20\x00\x00\x02") != 0,
+ "libspid_eoc_get_topo gets wrong mac address 2");
+ fail_if (strcmp (mac_address_list[2], "\x00\xd7\x20\x00\x00\x03") != 0,
+ "libspid_eoc_get_topo gets wrong mac address 3");
+ fail_if (strcmp (mac_address_list[3], "\x00\xd7\x20\x00\x00\x04") != 0,
+ "libspid_eoc_get_topo gets wrong mac address 4");
+ fail_if (strcmp (mac_address_list[4], "\x00\xd7\x20\x00\x00\x05") != 0,
+ "libspid_eoc_get_topo gets wrong mac address 5");
+ fail_if (mac_address_count != 5,
+ "libspid_eoc_get_topo gets wrong mac address count");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_get_device_info)
+{
+ mac_string_t mac_address;
+ libspid_eoc_dev_info_t eoc_dev_info;
+ libspid_error_t ret;
+
+ system ("cp " ONLINE_INFO " " UTESTS_TMP_DIR "/etc");
+ strcpy (mac_address, "00:d7:20:00:00:03");
+
+ ret = libspid_eoc_get_device_info (mac_address, &eoc_dev_info);
+
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_get_device_info fail");
+ fail_if (strcmp (eoc_dev_info.sw_version, "software3") != 0,
+ "libspid_eoc_get_device_info gets wrong software version");
+ fail_if (eoc_dev_info.eth_port_nb != 1,
+ "libspid_eoc_get_device_info gets wrong ethernet port number");
+ fail_if (strcmp (eoc_dev_info.model_no, "model3") != 0,
+ "libspid_eoc_get_device_info gets wrong model string");
+ fail_if (eoc_dev_info.downstream_attenuation != 30,
+ "libspid_eoc_get_device_info gets wrong downstream attenuation "
+ "value");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_get_link)
+{
+ mac_string_t mac_address;
+ libspid_eoc_link_quality_t eoc_link_quality;
+ libspid_error_t ret;
+
+ system("cp " ONLINE_INFO " " UTESTS_TMP_DIR "/etc");
+ strcpy(mac_address, "00:d7:20:00:00:03");
+
+ ret = libspid_eoc_get_link(mac_address, &eoc_link_quality);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_get_link fail");
+ fail_if (eoc_link_quality.down_att != 30,
+ "libspid_eoc_get_link gets wrong downstream attenuation");
+ fail_if (eoc_link_quality.up_att != 103,
+ "libspid_eoc_get_link gets wrong upstream attenuation ");
+ fail_if (eoc_link_quality.down_quality != 100,
+ "libspid_eoc_get_link gets wrong downstream quality");
+ fail_if (eoc_link_quality.up_quality != 100,
+ "libspid_eoc_get_link gets wrong upstream quality");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_get_stat)
+{
+ char mac_addr[4][LIBSPID_MAC_STR_LEN] = {
+ "00:11:22:33:44:aa", "00:11:22:33:44:bb",
+ "00:11:22:33:44:cc", "00:11:22:33:44:dd"
+ };
+ int exp_ret[3] = {LIBSPID_SUCCESS, LIBSPID_ERROR_GEN, LIBSPID_ERROR_MME};
+ unsigned int data_exp = 0x17550300;
+ libspid_eoc_rt_stat_t eoc_rt_stat;
+ int ret = 0;
+
+ ret = libspid_eoc_get_stat (mac_addr[0], &eoc_rt_stat);
+ fail_if (ret != exp_ret[0], "libspid_eoc_get_stat 1 failed");
+
+ ret = libspid_eoc_get_stat (mac_addr[1], &eoc_rt_stat);
+ fail_if (ret != exp_ret[1], "libspid_eoc_get_stat 2 failed");
+
+ ret = libspid_eoc_get_stat (mac_addr[2], &eoc_rt_stat);
+ fail_if (ret != exp_ret[2], "libspid_eoc_get_stat 3 failed");
+
+ ret = libspid_eoc_get_stat (mac_addr[3], &eoc_rt_stat);
+ fail_if (eoc_rt_stat.rx_pkt != data_exp,
+ "libspid_eoc_get_stat data error");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_reset_stat)
+{
+ char mac_addr[4][LIBSPID_MAC_STR_LEN] = {
+ "00:11:22:33:44:aa", "00:11:22:33:44:bb",
+ "00:11:22:33:44:cc", "00:11:22:33:44:dd"
+ };
+ int exp_ret[3] = {LIBSPID_SUCCESS, LIBSPID_ERROR_GEN, LIBSPID_ERROR_MME};
+ int ret = 0;
+
+ ret = libspid_eoc_reset_stat (mac_addr[0]);
+ fail_if (ret != exp_ret[0], "libspid_eoc_reset_stat failed");
+
+ ret = libspid_eoc_reset_stat (mac_addr[1]);
+ fail_if (ret != exp_ret[1], "libspid_eoc_reset_stat failed");
+
+ ret = libspid_eoc_reset_stat (mac_addr[2]);
+ fail_if (ret != exp_ret[2], "libspid_eoc_reset_stat failed");
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+extern Suite* libspid_eoc_suite(void)
+{
+ Suite *s = suite_create("LIBSPID_EOC");
+ TCase *tc_core = tcase_create("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test(tc_core, test_libspid_eoc_reboot);
+ tcase_add_test(tc_core, test_libspid_eoc_factory);
+ tcase_add_test(tc_core, test_libspid_eoc_get_topo);
+ tcase_add_test(tc_core, test_libspid_eoc_get_device_info);
+ tcase_add_test(tc_core, test_libspid_eoc_get_link);
+ tcase_add_test(tc_core, test_libspid_eoc_get_stat);
+ tcase_add_test(tc_core, test_libspid_eoc_reset_stat);
+ suite_add_tcase(s, tc_core);
+ suite_add_tcase(s, tc_param());
+ return s;
+}
+
+int main(void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite();
+
+ SRunner *sr = srunner_create(s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all(sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/misc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/misc_utests.c
new file mode 100644
index 0000000000..394072d787
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/misc_utests.c
@@ -0,0 +1,220 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file misc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for misc.c
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "misc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_MISC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+
+/* fixtures - run before and after each unit test */
+void setup(void)
+{
+}
+
+void teardown(void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+/* TESTING FALSE PARAMS */
+START_TEST (test_ip_str_to_bin_param)
+{
+ int ret;
+ char str[LIBSPID_IP_MAX_LEN]="192.168.3.1";
+ unsigned char bin[4];
+
+ /* str = NULL */
+ ret = libspid_ip_str_to_bin(NULL, bin);
+ fail_unless( ret == LIBSPID_ERROR_PARAM, "str = NULL");
+
+ /* bin = NULL */
+ ret = libspid_ip_str_to_bin(str, NULL );
+ fail_unless( ret == LIBSPID_ERROR_PARAM, "bin = NULL");
+
+ /* str doesn't contain IP address */
+ strcpy(str, "abcd");
+ ret = libspid_ip_str_to_bin(str, bin);
+ fail_unless( ret == LIBSPID_ERROR_PARAM, "string IP address invalid");
+
+ /* str contains IP address out of range */
+ strcpy(str, "999.999.999.999");
+ ret = libspid_ip_str_to_bin(str, bin);
+ fail_unless( ret == LIBSPID_ERROR_PARAM, "string IP address out of range");
+
+
+}
+END_TEST
+
+START_TEST (test_ip_bin_to_str_param)
+{
+ int ret;
+ char str[LIBSPID_IP_MAX_LEN];
+ unsigned char bin[4] = {192, 168, 3, 1};
+
+ /* str = NULL */
+ ret = libspid_ip_bin_to_str(bin, NULL);
+ fail_unless( ret == LIBSPID_ERROR_PARAM, "str = NULL");
+
+ /* bin = NULL */
+ ret = libspid_ip_bin_to_str(NULL, str);
+ fail_unless( ret == LIBSPID_ERROR_PARAM, "bin = NULL");
+
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("param");
+ tcase_add_test (tc_param, test_ip_str_to_bin_param);
+ tcase_add_test (tc_param, test_ip_bin_to_str_param);
+ return tc_param;
+}
+
+/* TEST THAT SHOULD PASS */
+/** test procedures */
+START_TEST (test_ip_str_to_bin)
+{
+ int ret;
+ char str[LIBSPID_IP_MAX_LEN];
+ unsigned char bin[4];
+ unsigned char test_bin[4]={192, 168, 3, 1};
+
+ strcpy(str, "192.168.3.1");
+ ret = libspid_ip_str_to_bin(str, bin);
+ fail_if(ret != LIBSPID_SUCCESS, "libspid_ip_str_to_bin fail");
+
+ ret = memcmp (bin, test_bin, 4);
+ fail_if(ret != LIBSPID_SUCCESS, "libspid_ip_str_to_bin fail");
+
+ strcpy(str, "192.168.003.001");
+ ret = libspid_ip_str_to_bin(str, bin);
+ fail_if(ret != LIBSPID_SUCCESS, "libspid_ip_str_to_bin fail");
+
+ ret = memcmp (bin, test_bin, 4);
+ fail_if(ret != LIBSPID_SUCCESS, "libspid_ip_str_to_bin fail");
+}
+END_TEST
+
+START_TEST (test_ip_bin_to_str)
+{
+ int ret;
+ unsigned char bin[4] = {192, 168, 3, 1};
+
+ char str[LIBSPID_IP_MAX_LEN];
+ char test_str[LIBSPID_IP_MAX_LEN] = "192.168.3.1";
+
+ ret = libspid_ip_bin_to_str(bin, str);
+ fail_if(ret != LIBSPID_SUCCESS, "libspid_ip_bin_to_str fail");
+
+ ret = strcmp (str, test_str);
+ fail_if(ret != 0, "libspid_ip_bin_to_str fail");
+
+}
+END_TEST
+
+START_TEST (test_libspid_check_key_mac_format)
+{
+ int ret = 0;
+ char mac_address[5][LIBSPID_MAC_STR_LEN] = {"A0:13:D7:a0:b0:01", "00:13:d7:a0:c0:01",
+ "A0:13:D7:00:A0:0B", "0R:13:D7:00:00:01",
+ "00*13:D7:00:00:01" };
+ char fake_mac_address[] = "fake_mak_add";
+ char port_key[] = "A0:13:D7:c0:b0:D1.3";
+
+ ret = libspid_check_key_mac_format (NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "libspid_check_mac_format failed");
+
+ ret = libspid_check_key_mac_format (mac_address[0]);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_check_mac_format failed");
+
+ ret = libspid_check_key_mac_format (mac_address[1]);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_check_mac_format failed");
+
+ ret = libspid_check_key_mac_format (mac_address[2]);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_check_mac_format failed");
+
+ ret = libspid_check_key_mac_format (mac_address[3]);
+ fail_if (ret != LIBSPID_ERROR_MAC, "libspid_check_mac_format failed");
+
+ ret = libspid_check_key_mac_format (mac_address[4]);
+ fail_if (ret != LIBSPID_ERROR_MAC, "libspid_check_mac_format failed");
+
+ ret = libspid_check_key_mac_format (fake_mac_address);
+ fail_if (ret != LIBSPID_ERROR_MAC, "libspid_check_mac_format failed");
+
+ ret = libspid_check_key_mac_format (port_key);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_check_mac_format failed");
+}
+END_TEST
+
+extern Suite* libspid_misc_suite(void)
+{
+ Suite *s = suite_create("LIBSPID_MISC");
+ TCase *tc_core = tcase_create("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ tcase_add_test (tc_core, test_ip_str_to_bin);
+ tcase_add_test (tc_core, test_ip_bin_to_str);
+ tcase_add_test (tc_core, test_libspid_check_key_mac_format);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param());
+ return s;
+}
+
+int main(void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run misc tests
+ s = libspid_misc_suite();
+
+ SRunner *sr = srunner_create(s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all(sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed(sr);
+ srunner_free(sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/network_utests.c b/cleopatre/devkit/tests/libspid/utests/src/network_utests.c
index 450b7391a3..7d0fef0b8b 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/network_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/network_utests.c
@@ -74,12 +74,19 @@ void setup(void)
}
/* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
- sprintf(buf, "%s/network", UTESTS_TMP_DIR);
+ sprintf(buf, "%s/etc/network", UTESTS_TMP_DIR);
ret = mkdir(buf, 0770);
if (ret < 0 && errno != EEXIST)
{
- perror("mkdir(UTESTS_TMP_DIR/network, 0770)");
+ perror("mkdir(UTESTS_TMP_DIR/etc/network, 0770)");
exit(EXIT_FAILURE);
}
@@ -132,6 +139,38 @@ START_TEST (test_get_ip)
}
END_TEST
+START_TEST (test_get_realip)
+{
+ int ret;
+ libspid_ip_t ip;
+
+ /* initerface is NULL */
+ ret = libspid_network_get_realip (NULL, &ip);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "interface is NULL");
+
+ /* ip is NULL */
+ ret = libspid_network_get_realip ("eth0", NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "ip is NULL");
+
+}
+END_TEST
+
+START_TEST (test_set_realip)
+{
+ int ret;
+ libspid_ip_t ip;
+
+ /* initerface is NULL */
+ ret = libspid_network_set_realip (NULL, &ip);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "interface is NULL");
+
+ /* ip is NULL */
+ ret = libspid_network_set_realip ("eth0", NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "ip is NULL");
+
+}
+END_TEST
+
START_TEST (test_set_ip)
{
int ret;
@@ -153,7 +192,9 @@ tc_param (void)
{
TCase *tc_param = tcase_create ("param");
tcase_add_test (tc_param, test_get_ip);
+ tcase_add_test (tc_param, test_get_realip);
tcase_add_test (tc_param, test_set_ip);
+ tcase_add_test (tc_param, test_set_realip);
tcase_add_test (tc_param, test_get_mac_param);
return tc_param;
}
@@ -179,6 +220,125 @@ START_TEST (test_libspid_network_get_ip)
}
END_TEST
+START_TEST (test_libspid_network_get_realip)
+{
+ int ret;
+ int fd;
+ struct ifreq ifr;
+ char default_name[] = "tap0";
+ int error;
+ libspid_ip_t ip;
+ libspid_ip_t get_ip;
+ char cmd[128] = {0};
+
+ strcpy ((char *)ip.address, "192.168.3.1");
+ strcpy ((char *)ip.netmask, "255.255.255.0");
+ strcpy ((char *)ip.broadcast, "192.168.3.254");
+
+ //Open TUN device
+ if ((fd = open ("/dev/net/tun", O_RDWR)) < 0)
+ {
+ printf ("open /dev/net/tun failed, make sure test is run as root\n");
+ exit (EXIT_FAILURE);
+ }
+
+ //Prepare TUN/TAP name
+ memset (&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+ strncpy (ifr.ifr_name, default_name, IFNAMSIZ);
+
+ //Create a TUN/TAP interface
+ if ((error = ioctl (fd, TUNSETIFF, (void *)&ifr)) < 0)
+ {
+ close (fd);
+ if (error == -EPERM)
+ printf ("TUN/TAP creation error.\n"
+ "You need to be root to create an network interface.\n");
+ else
+ printf ("TUN/TAP creation error(%d).\n",error);
+ exit (EXIT_FAILURE);
+ }
+
+ sprintf (cmd, "/sbin/ifconfig tap0 %s broadcast %s netmask %s",
+ ip.address, ip.broadcast, ip.netmask);
+ system (cmd);
+
+ ret = libspid_network_get_realip ("tap0", &get_ip);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_network_get_realip fail");
+
+ fail_if (strcmp((char *)get_ip.address, (char *)ip.address) != 0,
+ "ip address is error");
+
+ fail_if (strcmp((char *)get_ip.netmask, (char *)ip.netmask) != 0,
+ "ip netmask is error");
+
+ fail_if (strcmp((char *)get_ip.broadcast, (char *)ip.broadcast) != 0,
+ "ip broadcast is error");
+
+ /* close TAP */
+ close (fd);
+}
+END_TEST
+
+START_TEST (test_libspid_network_set_realip)
+{
+ int ret;
+ int fd;
+ struct ifreq ifr;
+ char default_name[] = "tap0";
+ int error;
+ libspid_ip_t ip;
+ libspid_ip_t get_ip;
+
+ strcpy ((char *)ip.address, "192.168.3.1");
+ strcpy ((char *)ip.netmask, "255.255.255.0");
+ strcpy ((char *)ip.broadcast, "192.168.3.254");
+
+ //Open TUN device
+ if ((fd = open ("/dev/net/tun", O_RDWR)) < 0)
+ {
+ printf ("open /dev/net/tun failed, make sure test is run as root\n");
+ exit (EXIT_FAILURE);
+ }
+
+ //Prepare TUN/TAP name
+ memset (&ifr, 0, sizeof(ifr));
+ ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
+ strncpy (ifr.ifr_name, default_name, IFNAMSIZ);
+
+ //Create a TUN/TAP interface
+ if ((error = ioctl (fd, TUNSETIFF, (void *)&ifr)) < 0)
+ {
+ close (fd);
+ if (error == -EPERM)
+ printf ("TUN/TAP creation error.\n"
+ "You need to be root to create an network interface.\n");
+ else
+ printf ("TUN/TAP creation error(%d).\n",error);
+ exit (EXIT_FAILURE);
+ }
+
+ ret = libspid_network_set_realip ("tap0", &ip);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_network_set_realip fail");
+
+ ret = libspid_network_get_realip ("tap0", &get_ip);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_network_get_realip fail");
+
+ fail_if (strcmp((char *)get_ip.address, (char *)ip.address) != 0,
+ "ip address is error");
+
+ fail_if (strcmp((char *)get_ip.netmask, (char *)ip.netmask) != 0,
+ "ip netmask is error");
+
+ fail_if (strcmp((char *)get_ip.broadcast, (char *)ip.broadcast) != 0,
+ "ip broadcast is error");
+
+ /* close TAP */
+ close (fd);
+}
+END_TEST
+
+
START_TEST (test_libspid_network_set_ip)
{
int ret;
@@ -219,7 +379,7 @@ START_TEST (test_libspid_network_get_mac)
//Open TUN device
if((fd = open("/dev/net/tun", O_RDWR)) < 0)
{
- printf("open /dev/net/tun failed");
+ printf("open /dev/net/tun failed, make sure test is run as root\n");
exit(EXIT_FAILURE);
}
@@ -263,7 +423,9 @@ extern Suite* libspid_network_suite(void)
//Test network_init
tcase_add_test(tc_core, test_libspid_network_get_ip);
+ tcase_add_test(tc_core, test_libspid_network_get_realip);
tcase_add_test(tc_core, test_libspid_network_set_ip);
+ tcase_add_test(tc_core, test_libspid_network_set_realip);
tcase_add_test(tc_core, test_libspid_network_get_mac);
suite_add_tcase(s, tc_core);
diff --git a/cleopatre/devkit/tests/libspid/utests/src/port_eoc_stub.c b/cleopatre/devkit/tests/libspid/utests/src/port_eoc_stub.c
new file mode 100644
index 0000000000..9c01c8fc38
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/port_eoc_stub.c
@@ -0,0 +1,78 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file port_eoc_stubs.c
+ * \brief Stubs for port related unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains stub functions used in unitary tests
+ * for ports in EoC libspid.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+
+libspid_error_t
+port_send_single_value (unsigned int mmtype,
+ const void *value, unsigned int length)
+{
+ unsigned char sta_num = 0x01;
+ unsigned char mac_addr[ETH_ALEN] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55};
+ unsigned char port_en[LIBSPID_PORT_PER_SLAVE_MAX]
+ = {0x01, 0x01, 0x00, 0x01, 0x00};
+ unsigned char service_index[LIBSPID_PORT_PER_SLAVE_MAX]
+ = {0x01, 0x01, 0x02, 0x01, 0x02};
+
+ fail_if (memcmp (value, &sta_num, 1) != 0,
+ "fail: wrong number of stations" );
+ fail_if (memcmp (value + 1, mac_addr, ETH_ALEN) != 0,
+ "fail: wrong MAC address for station #1" );
+ fail_if (memcmp (value + 7, &port_en[0], 1) != 0,
+ "fail: wrong port enable for station #1 port #0" );
+ fail_if (memcmp (value + 8, &service_index[0], 1) != 0,
+ "fail: wrong service index for station #1 port #0" );
+ fail_if (memcmp (value + 9, &port_en[1], 1) != 0,
+ "fail: wrong port enable for station #1 port #1" );
+ fail_if (memcmp (value + 10, &service_index[1], 1) != 0,
+ "fail: wrong service index for station #1 port #1" );
+ fail_if (memcmp (value + 11, &port_en[2], 1) != 0,
+ "fail: wrong port enable for station #1 port #2" );
+ fail_if (memcmp (value + 12, &service_index[2], 1) != 0,
+ "fail: wrong service index for station #1 port #2" );
+ fail_if (memcmp (value + 13, &port_en[3], 1) != 0,
+ "fail: wrong port enable for station #1 port #3" );
+ fail_if (memcmp (value + 14, &service_index[3], 1) != 0,
+ "fail: wrong service index for station #1 port #3" );
+ fail_if (memcmp (value + 15, &port_en[4], 1) != 0,
+ "fail: wrong port enable for station #1 port #4" );
+ fail_if (memcmp (value + 16, &service_index[4], 1) != 0,
+ "fail: wrong service index for station #1 port #4" );
+
+
+ return 0;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/port_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/port_eoc_utests.c
new file mode 100644
index 0000000000..bbb97943b4
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/port_eoc_utests.c
@@ -0,0 +1,495 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2012 MStar
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file port_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains all the unitary tests for EoC ports in LibSPiD.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf ("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define PORT_CONF "testfiles/port.conf"
+#define PORT_NO_SERVICE_INDEX "testfiles/port_no_service_index.conf"
+#define PORT_ERROR_MAC "testfiles/port_error_mac.conf"
+#define PORT_SYNC_CONF "testfiles/port_sync.conf"
+
+#define PORT_ENTRY_NUM 20
+#define PORT_CONF_SYSTEM "/etc/port.conf"
+#define ETC_PORT_CONF "/etc/port.conf"
+#define ETC_SYSTEM_CONF "/etc/system.conf"
+#define ETC_SERVICE_CONF "/etc/service.conf"
+#define ETC_VLAN_PORTTABLE_CONF "/etc/vlan_porttable.conf"
+
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define SYSTEM_CONF "testfiles/system.conf"
+#define SYSTEM_CONF_EOC "testfiles/system_v2.conf"
+#define SYSTEM_CONF_MOD "testfiles/system.conf"
+#define SERVICE_CONF "testfiles/service.conf"
+
+
+/** local variables */
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ( (stat (UTESTS_TMP_DIR, &st) == 0) )
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+
+
+START_TEST (test_libspid_eoc_port_set)
+{
+ int ret;
+ char mac_address[LIBSPID_MAC_STR_LEN];
+ char index[2];
+ libspid_eoc_port_entry_t entry,entry2;
+
+ memset (&entry, 0, sizeof (entry));
+
+ ret = libspid_eoc_port_set (NULL, index, &entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* index = NULL */
+ ret = libspid_eoc_port_set (mac_address, NULL, &entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "index = NULL");
+
+ /* eoc_port_entry = NULL */
+ ret = libspid_eoc_port_set (mac_address, index, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eoc_port_entry = NULL");
+
+ /*creat temp test_files*/
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ strcpy (mac_address, "00:13:D7:00:00:02");
+ strcpy (index, "3");
+ strcpy (entry.port_en, "1");
+ strcpy (entry.service_index, "2");
+ strcpy (entry.vlan_tag_en, "1");
+ strcpy (entry.vlan_mark_id, "5");
+
+ ret = libspid_eoc_port_set (mac_address, index, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "[mod]libspid_eoc_port_set fail");
+
+ ret = libspid_eoc_port_get (mac_address,index,&entry2);
+ fail_if (ret != LIBSPID_SUCCESS, "[mod]libspid_eoc_port_get fail");
+
+ ret = strcmp (entry2.port_en, entry.port_en);
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ ret = strcmp (entry2.service_index, entry.service_index);
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ ret = strcmp (entry2.vlan_tag_en, entry.vlan_tag_en);
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ ret = strcmp (entry2.vlan_mark_id, entry.vlan_mark_id);
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ setup ();
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ strcpy (mac_address, "00:13:D7:00:00:02");
+ strcpy (index, "3");
+ strcpy (entry.port_en, "1");
+ strcpy (entry.service_index, "2");
+ strcpy (entry.vlan_tag_en, "1");
+ strcpy (entry.vlan_mark_id, "5");
+
+ ret = libspid_eoc_port_set (mac_address, index, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "[eoc]libspid_eoc_port_set fail");
+
+ ret = libspid_eoc_port_get (mac_address,index,&entry2);
+ fail_if (ret != LIBSPID_SUCCESS, "[eoc]libspid_eoc_port_get fail");
+
+ ret = strcmp (entry2.port_en, entry.port_en);
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+ ret = strcmp (entry2.service_index, entry.service_index);
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+ ret = strcmp (entry2.vlan_tag_en, "0");
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+ ret = strcmp (entry2.vlan_mark_id, "0");
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_port_get)
+{
+ int ret;
+ char mac_address[LIBSPID_MAC_STR_LEN];
+ char index[2];
+ libspid_eoc_port_entry_t entry;
+
+ strcpy (mac_address, "00:13:D7:00:00:01");
+ strcpy (index, "4");
+
+ ret = libspid_eoc_port_get (0, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "Param 1 is error");
+
+ ret = libspid_eoc_port_get (mac_address, 0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "Param 2 is error");
+
+ ret = libspid_eoc_port_get (mac_address, index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "Param 3 is error");
+
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ strcpy (mac_address, "00:13:D7:00:00:01");
+ strcpy (index, "4");
+
+ ret = libspid_eoc_port_get (mac_address,index,&entry);
+ fail_if (ret != LIBSPID_SUCCESS, "[mod]libspid_eoc_port_get fail");
+
+ ret = strcmp (entry.port_en, "1");
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ ret = strcmp (entry.service_index, "7");
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ ret = strcmp (entry.vlan_tag_en, "1");
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ ret = strcmp (entry.vlan_mark_id, "2");
+ fail_if (ret != 0, "[mod]get data is not equ set");
+
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ strcpy (mac_address, "00:13:D7:00:00:01");
+ strcpy (index, "4");
+
+ ret = libspid_eoc_port_get (mac_address,index,&entry);
+ fail_if (ret != LIBSPID_SUCCESS, "[eoc]libspid_eoc_port_get fail");
+
+ ret = strcmp (entry.port_en, "1");
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+ ret = strcmp (entry.service_index, "7");
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+ ret = strcmp (entry.vlan_tag_en, "0");
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+ ret = strcmp (entry.vlan_mark_id, "0");
+ fail_if (ret != 0, "[eoc]get data is not equ set");
+
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_port_get_list)
+{
+ int ret;
+ libspid_eoc_port_entry_t entries[PORT_ENTRY_NUM];
+ libspid_eoc_port_entry_t entry;
+ int i;
+ int count = PORT_ENTRY_NUM;
+
+ ret = libspid_eoc_port_get_list (0, &count);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of err param 1");
+
+ ret = libspid_eoc_port_get_list (entries, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of err param 2");
+
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ ret = libspid_eoc_port_get_list (entries, &count);
+
+ fail_if (LIBSPID_SUCCESS != ret, "[mod]must get suc");
+ fail_if (count != PORT_ENTRY_NUM,
+ "[mod]libspid_eoc_port_get returns wrong count");
+ for (i = 0 ; i < count ; i ++)
+ {
+ libspid_eoc_port_get (entries[i].mac_addr,
+ entries[i].port_index,
+ &entry);
+ ret = strcmp (entries[i].port_en,entry.port_en);
+ fail_if (0 != ret, "[mod]Get Data not correct");
+
+ ret = strcmp (entries[i].service_index,entry.service_index);
+ fail_if (0 != ret, "[mod]Get Data not correct");
+
+ ret = strcmp (entries[i].vlan_tag_en,entry.vlan_tag_en);
+ fail_if (0 != ret, "[mod]Get Data not correct");
+
+ ret = strcmp (entries[i].vlan_mark_id,entry.vlan_mark_id);
+ fail_if (0 != ret, "[mod]Get Data not correct");
+ }
+
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ ret = libspid_eoc_port_get_list (entries, &count);
+ fail_if (LIBSPID_SUCCESS != ret, "[eoc]must get suc");
+ fail_if (count != PORT_ENTRY_NUM,
+ "[eoc]libspid_eoc_port_get returns wrong count");
+ for (i = 0 ; i < count ; i ++)
+ {
+ libspid_eoc_port_get (entries[i].mac_addr,
+ entries[i].port_index,
+ &entry);
+ ret = strcmp (entries[i].port_en,entry.port_en);
+ fail_if (0 != ret, "[eoc]Get Data not correct");
+
+ ret = strcmp (entries[i].service_index,entry.service_index);
+ fail_if (0 != ret, "[eoc]Get Data not correct");
+
+ ret = strcmp (entries[i].vlan_tag_en,"0");
+ fail_if (0 != ret, "[eoc]Get Data not correct");
+
+ ret = strcmp (entries[i].vlan_mark_id,"0");
+ fail_if (0 != ret, "[eoc]Get Data not correct");
+ }
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_port_retrieve)
+{
+ int ret;
+ int port_count = LIBSPID_PORT_TOTAL_MAX;
+ libspid_eoc_port_entry_t entries[LIBSPID_PORT_TOTAL_MAX];
+ libspid_eoc_port_entry_t entry;
+ int i;
+
+ /* Expected results */
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_SYNC_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ memset (entries, 0,
+ LIBSPID_PORT_PER_SLAVE_MAX * sizeof (libspid_eoc_port_entry_t));
+
+ libspid_eoc_port_get_list (entries, &port_count);
+
+ ret = libspid_eoc_port_retrieve (entries, &port_count);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_port_retrieve return is unsuccessful");
+ fail_if (port_count != LIBSPID_PORT_PER_SLAVE_MAX,
+ "port_count is not equal to maximum number of ports");
+ for (i = 0; i < port_count; i++)
+ {
+ libspid_eoc_port_get (entries[i].mac_addr,
+ entries[i].port_index,
+ &entry);
+ ret = strcmp (entries[i].port_en,entry.port_en);
+ fail_if (0 != ret, "[mod]Get Data not correct");
+
+ ret = strcmp (entries[i].service_index,entry.service_index);
+ fail_if (0 != ret, "[mod]Get Data not correct");
+ }
+
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_SYNC_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ memset (entries, 0,
+ LIBSPID_PORT_PER_SLAVE_MAX * sizeof (libspid_eoc_port_entry_t));
+
+ libspid_eoc_port_get_list (entries, &port_count);
+
+ ret = libspid_eoc_port_retrieve (entries, &port_count);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_port_retrieve return is unsuccessful");
+ fail_if (port_count != LIBSPID_PORT_PER_SLAVE_MAX,
+ "port_count is not equal to maximum number of ports");
+ for (i = 0; i < port_count; i++)
+ {
+ libspid_eoc_port_get (entries[i].mac_addr,
+ entries[i].port_index,
+ &entry);
+ ret = strcmp (entries[i].port_en,entry.port_en);
+ fail_if (0 != ret, "[eoc]Get Data not correct");
+
+ ret = strcmp (entries[i].service_index,entry.service_index);
+ fail_if (0 != ret, "[eoc]Get Data not correct");
+ }
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_port_sync)
+{
+ int ret;
+
+ /*creat temp test_files*/
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_SYNC_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ ret = libspid_eoc_port_sync ();
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "[mod]libspid_eoc_port_sync return is unsuccessful");
+
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_SYNC_CONF " " LIBSPID_PORT_CONF_PATH);
+
+ ret = libspid_eoc_port_sync ();
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "[eoc]libspid_eoc_port_sync return is unsuccessful");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_port_check)
+{
+ int ret;
+
+ /*creat temp test_files*/
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " LIBSPID_WHITE_LIST_CONF_PATH);
+ system ("cp " SERVICE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+
+ ret = libspid_eoc_port_check ();
+ fail_if (ret != LIBSPID_SUCCESS,
+ "[mod]must success, becase of correct port.conf");
+
+ system ("cp -f " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+
+ ret = libspid_eoc_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "[mod]must fail, becase of service index not exist");
+
+ system ("cp -f " PORT_ERROR_MAC " " LIBSPID_PORT_CONF_PATH);
+ ret = libspid_eoc_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "[mod]must fail, becase of mac is not exist");
+
+ setup ();
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " WHITE_LIST_CONF " " LIBSPID_WHITE_LIST_CONF_PATH);
+ system ("cp " SERVICE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+
+ ret = libspid_eoc_port_check ();
+ fail_if (ret != LIBSPID_SUCCESS,
+ "[eoc]must success, becase of correct port.conf");
+
+ setup ();
+ system ("cp -f " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+
+ ret = libspid_eoc_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "[eoc]must fail, becase of service index not exist");
+
+ system ("cp -f " PORT_ERROR_MAC " " LIBSPID_PORT_CONF_PATH);
+
+ ret = libspid_eoc_port_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "[mod]must fail, becase of mac is not exist");
+
+
+}
+END_TEST
+
+
+extern Suite*
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_port_set);
+ tcase_add_test (tc_core, test_libspid_eoc_port_get);
+ tcase_add_test (tc_core, test_libspid_eoc_port_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_port_retrieve);
+ tcase_add_test (tc_core, test_libspid_eoc_port_sync);
+ tcase_add_test (tc_core, test_libspid_eoc_port_check);
+
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/service_eoc_stub.c b/cleopatre/devkit/tests/libspid/utests/src/service_eoc_stub.c
new file mode 100644
index 0000000000..b009274337
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/service_eoc_stub.c
@@ -0,0 +1,107 @@
+
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file service_eoc_stubs.c
+ * \brief Stubs for service related unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains stub functions used in unitary tests
+ * for services in EoC libspid.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+
+libspid_error_t
+service_send_single_value (unsigned int mmtype, const void *value,
+ unsigned int length)
+{
+ unsigned char action1 = 0x00;
+ unsigned char service_num = 0x01;
+ unsigned char index1 = 0x02;
+ unsigned char index2 = 0x01;
+ /* using service type as classifier rule ID */
+ unsigned char cl_rule1 = 0x01;
+ /* using matching value as classifier rule value */
+ unsigned char cl_value1[2] = {0x01, 0x00};
+ unsigned char acs_en1 = 0x01;
+ /* parameter number is always 7 */
+ unsigned char param_nb1 = 0x07;
+ /* latency */
+ unsigned char param_value1[2] = {0x32, 0x00};
+ /* jitter */
+ unsigned char param_value2[2] = {0x14, 0x00};
+ /* down PIR */
+ unsigned char param_value3[2] = {0x64, 0x00};
+ /* up PIR */
+ unsigned char param_value4[2] = {0xC8, 0x00};
+ /* down CIR */
+ unsigned char param_value5[2] = {0x64, 0x00};
+ /* up CIR */
+ unsigned char param_value6[2] = {0xC8, 0x00};
+ /* QOS prio */
+ unsigned char param_value7[2] = {0x05, 0x00};
+
+ if (memcmp (value, &action1, 1) != 0)
+ {
+ fail_if (memcmp (value + 2, &index2, 1) != 0,
+ "fail: wrong service index for remove" );
+ return 0;
+ }
+ fail_if (memcmp (value, &action1, 1) != 0,
+ "fail: wrong action" );
+ fail_if (memcmp (value + 1, &service_num, 1) != 0,
+ "fail: wrong number of services" );
+ fail_if (memcmp (value + 2, &index1, 1) != 0,
+ "fail: wrong service index1" );
+ fail_if (memcmp (value + 3, &cl_rule1, 1) != 0,
+ "fail: wrong cl_rule1 (service type)" );
+ fail_if (memcmp (value + 4, cl_value1, 2) != 0,
+ "fail: wrong cl_value1 (matching value)" );
+ fail_if (memcmp (value + 6, &acs_en1, 1) != 0,
+ "fail: wrong acs_en1" );
+ fail_if (memcmp (value + 7, &param_nb1, 1) != 0,
+ "fail: wrong number of parameters (param_nb1)" );
+ fail_if (memcmp (value + 8, param_value1, 2) != 0,
+ "fail: wrong parameter value1 (latency)" );
+ fail_if (memcmp (value + 10, param_value2, 2) != 0,
+ "fail: wrong parameter value2 (jitter)" );
+ fail_if (memcmp (value + 12, param_value3, 2) != 0,
+ "fail: wrong parameter value3 (down PIR)" );
+ fail_if (memcmp (value + 14, param_value4, 2) != 0,
+ "fail: wrong parameter value4 (up PIR)" );
+ fail_if (memcmp (value + 16, param_value5, 2) != 0,
+ "fail: wrong parameter value5 (down CIR)" );
+ fail_if (memcmp (value + 18, param_value6, 2) != 0,
+ "fail: wrong parameter value6 (up CIR)" );
+ fail_if (memcmp (value + 20, param_value7, 2) != 0,
+ "fail: wrong parameter value7 (QOS prio)" );
+
+ return 0;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/service_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/service_eoc_utests.c
new file mode 100644
index 0000000000..849adceb9d
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/service_eoc_utests.c
@@ -0,0 +1,682 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2012 MStar
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file service_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains all the unitary tests for EoC services in SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf ("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define SERVICE_CONF "testfiles/service.conf"
+#define SERVICE_DUP_INDEX_CONF "testfiles/service_dup_index.conf"
+#define SERVICE_ERROR_TYPE_CONF "testfiles/service_error_type.conf"
+#define SERVICE_ERROR_NAME_CONF "testfiles/service_error_name.conf"
+#define SERVICE_ERROR_QOS_CONF "testfiles/service_error_qos.conf"
+#define SERVICE_ERROR_ACS_CONF "testfiles/service_error_acs.conf"
+#define SERVICE_PIR_CIR_CONF "testfiles/service_pir_cir.conf"
+#define SERVICE_SYNC_CONF "testfiles/service_sync.conf"
+
+#define EOC_CONF "testfiles/eoc.conf"
+#define SERVICE_ENTRY_NUM 2
+#define SERVICE_CONF_SYSTEM "/etc/service.conf"
+#define ETC_SERVICE_SYNC_CONF "/etc/service_sync.conf"
+#define TEST_DIR "testfiles"
+#define ETC_SYSTEM_CONF "/etc/system.conf"
+#define SYSTEM_CONF_EOC "testfiles/system_v2.conf"
+#define SYSTEM_CONF_MOD "testfiles/system.conf"
+#define PORT_CONF "testfiles/port.conf"
+#define PORT_NO_SERVICE_INDEX "testfiles/port_no_service_index.conf"
+
+
+/** local variables */
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char index;
+ libspid_eoc_service_entry_t eoc_service_entry;
+
+ /* index = NULL */
+ ret = libspid_eoc_service_set (NULL, &eoc_service_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "index = NULL");
+
+ /* eoc_service_entry = NULL */
+ ret = libspid_eoc_service_set (&index, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eoc_service_entry = NULL");
+
+ /* index = NULL */
+ ret = libspid_eoc_service_remove (NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "index = NULL");
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+START_TEST (test_libspid_eoc_service_set)
+{
+ int ret;
+ char index[4];
+ libspid_eoc_service_entry_t entry;
+
+ memset (&entry, 0, sizeof (entry));
+
+ strcpy (index, "6");
+
+ strcpy (entry.service_name, "basic");
+ strcpy (entry.matching_value, "100");
+ strcpy (entry.qos_prio, "4");
+ strcpy (entry.dba_dl_pir, "200");
+ strcpy (entry.dba_ul_pir, "300");
+ strcpy (entry.dba_dl_cir, "400");
+ strcpy (entry.dba_ul_cir, "500");
+ strcpy (entry.max_latency, "10");
+ strcpy (entry.max_jitter, "0");
+ strcpy (entry.acs_en, "0");
+
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_service_set (index, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_service_set fail");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_get)
+{
+ int ret;
+ char index[4];
+ libspid_eoc_service_entry_t entry;
+
+ memset (&entry, 0, sizeof (entry));
+ strcpy (index, "8");
+
+
+ ret = libspid_eoc_service_get (0, &entry);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of error param 1");
+
+ strcpy (index, "1");
+ ret = libspid_eoc_service_get (index, 0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of error param 2");
+
+ strcpy (index, "222");
+ ret = libspid_eoc_service_get (index, &entry);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of not have index:222");
+
+
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " EOC_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+
+ strcpy (index, "8");
+ ret = libspid_eoc_service_get (index, &entry);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_get return unsuccessful");
+ fail_if (strcmp (entry.service_index, "8") != 0,
+ "libspid_eoc_service_get corrupts service index");
+ fail_if (strcmp (entry.service_name, "video") != 0,
+ "libspid_eoc_service_get gets wrong service name");
+ fail_if (strcmp (entry.matching_value, "5") != 0,
+ "libspid_eoc_service_get gets wrong matching value");
+ fail_if (strcmp (entry.qos_prio, "1") != 0,
+ "libspid_eoc_service_get gets wrong QOS priority");
+ fail_if (strcmp (entry.dba_dl_pir, "450") != 0,
+ "libspid_eoc_service_get gets wrong DBA download PIR");
+ fail_if (strcmp (entry.dba_ul_pir, "550") != 0,
+ "libspid_eoc_service_get gets wrong DBA upload PIR");
+ fail_if (strcmp (entry.dba_dl_cir, "250") != 0,
+ "libspid_eoc_service_get gets wrong DBA download CIR");
+ fail_if (strcmp (entry.dba_ul_cir, "350") != 0,
+ "libspid_eoc_service_get gets wrong DBA upload CIR");
+ fail_if (strcmp (entry.max_latency, "50") != 0,
+ "libspid_eoc_service_get gets wrong maximal latency");
+ fail_if (strcmp (entry.max_jitter, "10") != 0,
+ "libspid_eoc_service_get gets wrong maximal jitter");
+ fail_if (strcmp (entry.acs_en, "1") != 0,
+ "libspid_eoc_service_get gets wrong ACS enable value");
+ fail_if (strcmp (entry.service_type, "1") != 0,
+ "libspid_eoc_service_get gets wrong service_type");
+
+ setup ();
+
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+
+ strcpy (index, "8");
+ ret = libspid_eoc_service_get (index, &entry);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_get return unsuccessful");
+ fail_if (strcmp (entry.service_index, "8") != 0,
+ "libspid_eoc_service_get corrupts service index");
+ fail_if (strcmp (entry.service_name, "video") != 0,
+ "libspid_eoc_service_get gets wrong service name");
+ fail_if (strcmp (entry.matching_value, "5") != 0,
+ "libspid_eoc_service_get gets wrong matching value");
+ fail_if (strcmp (entry.qos_prio, "1") != 0,
+ "libspid_eoc_service_get gets wrong QOS priority");
+ fail_if (strcmp (entry.dba_dl_pir, "450") != 0,
+ "libspid_eoc_service_get gets wrong DBA download PIR");
+ fail_if (strcmp (entry.dba_ul_pir, "550") != 0,
+ "libspid_eoc_service_get gets wrong DBA upload PIR");
+ fail_if (strcmp (entry.dba_dl_cir, "250") != 0,
+ "libspid_eoc_service_get gets wrong DBA download CIR");
+ fail_if (strcmp (entry.dba_ul_cir, "350") != 0,
+ "libspid_eoc_service_get gets wrong DBA upload CIR");
+ fail_if (strcmp (entry.max_latency, "50") != 0,
+ "libspid_eoc_service_get gets wrong maximal latency");
+ fail_if (strcmp (entry.max_jitter, "10") != 0,
+ "libspid_eoc_service_get gets wrong maximal jitter");
+ fail_if (strcmp (entry.acs_en, "1") != 0,
+ "libspid_eoc_service_get gets wrong ACS enable value");
+ fail_if (strcmp (entry.service_type, "1") != 0,
+ "libspid_eoc_service_get gets wrong service_type");
+
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_get_list)
+{
+ int ret;
+ libspid_eoc_service_entry_t entries[SERVICE_ENTRY_NUM], entry;
+ int i;
+ int count;
+
+ /* Expected results */
+ memset (entries, 0,
+ SERVICE_ENTRY_NUM * sizeof (libspid_eoc_service_entry_t));
+
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " EOC_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+
+ ret = libspid_eoc_service_get_list (entries, &count);
+
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+ fail_if (count != SERVICE_ENTRY_NUM,
+ "libspid_eoc_service_get returns wrong count");
+
+ for (i = 0; i < SERVICE_ENTRY_NUM; i++)
+ {
+ ret = libspid_eoc_service_get (entries[i].service_index, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_get return is unsuccessful");
+ fail_if (strcmp (entries[i].service_index, entry.service_index) != 0,
+ "libspid_eoc_service_get_list corrupts service index");
+
+ fail_if (strcmp (entries[i].service_name, entry.service_name) != 0,
+ "libspid_eoc_service_get_list gets wrong service name");
+
+ fail_if (strcmp (entries[i].matching_value, entry.matching_value) != 0,
+ "libspid_eoc_service_get_list gets wrong matching value");
+
+ fail_if (strcmp (entries[i].qos_prio, entry.qos_prio) != 0,
+ "libspid_eoc_service_get_list gets wrong QOS priority");
+
+ fail_if (strcmp (entries[i].dba_dl_pir, entry.dba_dl_pir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA download PIR");
+
+ fail_if (strcmp (entries[i].dba_ul_pir, entry.dba_ul_pir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA upload PIR");
+
+ fail_if (strcmp (entries[i].dba_dl_cir, entry.dba_dl_cir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA download CIR");
+
+ fail_if (strcmp (entries[i].dba_ul_cir, entry.dba_ul_cir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA upload CIR");
+
+ fail_if (strcmp (entries[i].max_latency, entry.max_latency) != 0,
+ "libspid_eoc_service_get_list gets wrong maximal latency");
+
+ fail_if (strcmp (entries[i].max_jitter, entry.max_jitter) != 0,
+ "libspid_eoc_service_get_list gets wrong maximal jitter");
+
+ fail_if (strcmp (entries[i].acs_en, entry.acs_en) != 0,
+ "libspid_eoc_service_get_list gets wrong ACS Enable value");
+
+ fail_if (strcmp (entries[i].service_type, entry.service_type) != 0,
+ "libspid_eoc_service_get_list gets wrong service type");
+ }
+
+ setup ();
+
+
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " EOC_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+
+ ret = libspid_eoc_service_get_list (entries, &count);
+
+ fail_if (count != SERVICE_ENTRY_NUM,
+ "libspid_eoc_service_get returns wrong count");
+
+ for (i = 0; i < SERVICE_ENTRY_NUM; i++)
+ {
+ ret = libspid_eoc_service_get (entries[i].service_index, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ fail_if (strcmp (entries[i].service_index, entry.service_index) != 0,
+ "libspid_eoc_service_get_list corrupts service index");
+
+ fail_if (strcmp (entries[i].service_name, entry.service_name) != 0,
+ "libspid_eoc_service_get_list gets wrong service name");
+
+ fail_if (strcmp (entries[i].matching_value, entry.matching_value) != 0,
+ "libspid_eoc_service_get_list gets wrong matching value");
+
+ fail_if (strcmp (entries[i].qos_prio, entry.qos_prio) != 0,
+ "libspid_eoc_service_get_list gets wrong QOS priority");
+
+ fail_if (strcmp (entries[i].dba_dl_pir, entry.dba_dl_pir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA download PIR");
+
+ fail_if (strcmp (entries[i].dba_ul_pir, entry.dba_ul_pir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA upload PIR");
+
+ fail_if (strcmp (entries[i].dba_dl_cir, entry.dba_dl_cir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA download CIR");
+
+ fail_if (strcmp (entries[i].dba_ul_cir, entry.dba_ul_cir) != 0,
+ "libspid_eoc_service_get_list gets wrong DBA upload CIR");
+
+ fail_if (strcmp (entries[i].max_latency, entry.max_latency) != 0,
+ "libspid_eoc_service_get_list gets wrong maximal latency");
+
+ fail_if (strcmp (entries[i].max_jitter, entry.max_jitter) != 0,
+ "libspid_eoc_service_get_list gets wrong maximal jitter");
+
+ fail_if (strcmp (entries[i].acs_en, entry.acs_en) != 0,
+ "libspid_eoc_service_get_list gets wrong ACS Enable value");
+
+ fail_if (strcmp (entries[i].service_type, entry.service_type) != 0,
+ "libspid_eoc_service_get_list gets wrong service type");
+ }
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_remove)
+{
+ char index[4];
+ int ret;
+
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc");
+
+ strcpy (index, "7");
+
+ ret = libspid_eoc_service_remove (index);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_remove return is unsuccessful");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_flush)
+{
+ int ret;
+
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_service_flush ();
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_flush return is unsuccessful");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_retrieve)
+{
+ int ret;
+ int service_count;
+ libspid_eoc_service_entry_t eoc_service_entry;
+
+ /* Expected results */
+ char index[] = "1";
+ /* using service type as classifier rule ID */
+ char cl_rule[] = "1";
+ /* using matching value as classifier rule value */
+ char cl_value[] = "1";
+ char acs_en[] = "0";
+ /* latency */
+ char param_value1[] = "50";
+ /* jitter */
+ char param_value2[] = "20";
+ /* down PIR */
+ char param_value3[] = "100";
+ /* up PIR */
+ char param_value4[] = "200";
+ /* down CIR */
+ char param_value5[] = "100";
+ /* up CIR */
+ char param_value6[] = "200";
+ /* QOS prio */
+ char param_value7[] = "5";
+
+
+ ret = libspid_eoc_service_retrieve (&eoc_service_entry, &service_count);
+
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_retrieve return is unsuccessful");
+ fail_if (service_count != 1, "service_count is not 1");
+ fail_if (strcmp (eoc_service_entry.service_index, index) != 0,
+ "libspid_eoc_service_retrieve corrupts index");
+ fail_if (strcmp (eoc_service_entry.service_type, cl_rule) != 0,
+ "libspid_eoc_service_retrieve gets wrong classifier rule ID "
+ "(service type)");
+ fail_if (strcmp (eoc_service_entry.matching_value, cl_value) != 0,
+ "libspid_eoc_service_retrieve gets wrong classifier rule value "
+ "(matching value)");
+ fail_if (strcmp (eoc_service_entry.acs_en, acs_en) != 0,
+ "libspid_eoc_service_retrieve gets wrong ACS enable");
+ fail_if (strcmp (eoc_service_entry.max_latency, param_value1) != 0,
+ "libspid_eoc_service_retrieve gets wrong param_value1 "
+ "(max latency)");
+ fail_if (strcmp (eoc_service_entry.max_jitter, param_value2) != 0,
+ "libspid_eoc_service_retrieve gets wrong param_value2 "
+ "(max jitter)");
+ fail_if (strcmp (eoc_service_entry.dba_dl_pir, param_value3) != 0,
+ "libspid_eoc_service_retrieve gets wrong param_value3 "
+ "(down PIR)");
+ fail_if (strcmp (eoc_service_entry.dba_ul_pir, param_value4) != 0,
+ "libspid_eoc_service_retrieve gets wrong param_value4 (up PIR)");
+ fail_if (strcmp (eoc_service_entry.dba_dl_cir, param_value5) != 0,
+ "libspid_eoc_service_retrieve gets wrong param_value5 "
+ "(down CIR)");
+ fail_if (strcmp (eoc_service_entry.dba_ul_cir, param_value6) != 0,
+ "libspid_eoc_service_retrieve gets wrong param_value6 (up CIR)");
+ fail_if (strcmp (eoc_service_entry.qos_prio, param_value7) != 0,
+ "libspid_eoc_service_retrieve gets wrong param_value7 "
+ "(QOS prio)");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_sync)
+{
+ int ret;
+
+ system ("cp " SERVICE_SYNC_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+
+ ret = libspid_eoc_service_sync ();
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_sync return is unsuccessful");
+
+ setup ();
+
+ system ("cp " SERVICE_SYNC_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+
+ ret = libspid_eoc_service_sync ();
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_service_sync return is unsuccessful");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_type_get)
+{
+ /* CASE1 : VLAN_ID mapping rules */
+ system ("cp " TEST_DIR "/eoc_1.conf" " " LIBSPID_EOC_CONF_PATH);
+ fail_if (libspid_eoc_service_type_get () != LIBSPID_SERVICE_TYPE_VID,
+ "libspid_eoc_service_type_get VID fails");
+
+ /* CASE2 : VLAN_PRIO mapping rules */
+ system ("cp " TEST_DIR "/eoc_2.conf" " " LIBSPID_EOC_CONF_PATH);
+ fail_if (libspid_eoc_service_type_get () != LIBSPID_SERVICE_TYPE_PRIO,
+ "libspid_eoc_service_type_get PRIO fails");
+
+ /* CASE3 : TOS mapping rules */
+ system ("cp " TEST_DIR "/eoc_3.conf" " " LIBSPID_EOC_CONF_PATH);
+ fail_if (libspid_eoc_service_type_get () != LIBSPID_SERVICE_TYPE_TOS,
+ "libspid_eoc_service_type_get TOS fails");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_qos_rules_get)
+{
+ plcdrv_qos_rules_t qos_rules;
+ system ("cp " SERVICE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+
+ fail_if (libspid_eoc_service_type_get () != LIBSPID_SERVICE_TYPE_VID,
+ "libspid_eoc_service_type_get: wrong type of service");
+
+ fail_if (libspid_eoc_qos_rules_get (&qos_rules) != LIBSPID_SUCCESS,
+ "libspid_eoc_qos_rules_get returns unsuccessful");
+ fail_if (qos_rules.rules_nb != SERVICE_ENTRY_NUM,
+ "libspid_eoc_qos_rules_get: wrong number of rules");
+ fail_if (qos_rules.rules[0].matching_value != 4,
+ "libspid_eoc_qos_rules_get rule #1: wrong vlan id");
+ fail_if (qos_rules.rules[0].packet_prio > 1,
+ "libspid_eoc_qos_rules_get rule #1: wrong packet prio");
+ fail_if (qos_rules.rules[1].matching_value != 5,
+ "libspid_eoc_qos_rules_get rule #2: wrong vlan id");
+ fail_if (qos_rules.rules[1].packet_prio > 1,
+ "libspid_eoc_qos_rules_get rule #2: wrong packet prio");
+
+ setup ();
+ system ("cp " SERVICE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+
+ fail_if (libspid_eoc_service_type_get () != LIBSPID_SERVICE_TYPE_VID,
+ "libspid_eoc_service_type_get: wrong type of service");
+
+ fail_if (libspid_eoc_qos_rules_get (&qos_rules) != LIBSPID_SUCCESS,
+ "libspid_eoc_qos_rules_get returns unsuccessful");
+ fail_if (qos_rules.rules_nb != SERVICE_ENTRY_NUM,
+ "libspid_eoc_qos_rules_get: wrong number of rules");
+ fail_if (qos_rules.rules[0].matching_value != 4,
+ "libspid_eoc_qos_rules_get rule #1: wrong vlan id");
+ fail_if (qos_rules.rules[0].packet_prio > 1,
+ "libspid_eoc_qos_rules_get rule #1: wrong packet prio");
+ fail_if (qos_rules.rules[1].matching_value != 5,
+ "libspid_eoc_qos_rules_get rule #2: wrong vlan id");
+ fail_if (qos_rules.rules[1].packet_prio > 1,
+ "libspid_eoc_qos_rules_get rule #2: wrong packet prio");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_service_check)
+{
+ int ret;
+ system ("cp " SERVICE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret != LIBSPID_SUCCESS, "must success");
+
+ setup ();
+ system ("cp " SERVICE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because miss a index that exist in port.conf");
+
+
+ setup ();
+ system ("cp " SERVICE_DUP_INDEX_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of same index in server.conf");
+
+ setup ();
+ system ("cp " SERVICE_ERROR_TYPE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of type error");
+
+ setup ();
+ system ("cp " SERVICE_ERROR_NAME_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of name formate error");
+
+ setup ();
+ system ("cp " SERVICE_ERROR_QOS_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of qos error");
+
+ setup ();
+ system ("cp " SERVICE_ERROR_ACS_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of acs error");
+
+ setup ();
+ system ("cp " SERVICE_PIR_CIR_CONF " " LIBSPID_SERVICE_CONF_PATH);
+ system ("cp " EOC_CONF " " LIBSPID_EOC_CONF_PATH);
+ system ("cp " PORT_NO_SERVICE_INDEX " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+ ret = libspid_eoc_service_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of qos error");
+
+}
+END_TEST
+
+extern Suite*
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_service_set);
+ tcase_add_test (tc_core, test_libspid_eoc_service_get);
+ tcase_add_test (tc_core, test_libspid_eoc_service_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_service_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_service_flush);
+ tcase_add_test (tc_core, test_libspid_eoc_service_retrieve);
+ tcase_add_test (tc_core, test_libspid_eoc_service_sync);
+ tcase_add_test (tc_core, test_libspid_eoc_service_type_get);
+ tcase_add_test (tc_core, test_libspid_eoc_qos_rules_get);
+ tcase_add_test (tc_core, test_libspid_eoc_service_check);
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/storm_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/storm_eoc_utests.c
new file mode 100644
index 0000000000..3b17ee4fe5
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/storm_eoc_utests.c
@@ -0,0 +1,445 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file storm_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+#include "libspid.h"
+
+
+/* fixtures - run before and after each unit test */
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define STORM_PROTECTION_CONF "testfiles/storm.conf"
+
+#define SP_CONF_MAC_FORMAT "testfiles/storm_protection_mac_format.conf"
+#define SP_CONF_DUP_KEY "testfiles/storm_protection_dup_key.conf"
+#define SP_CONF_INDEX_ERR "testfiles/storm_protection_index_err.conf"
+#define SP_CONF_STORM_EN_ERR "testfiles/storm_protection_storm_en_err.conf"
+#define SP_CONF_STORM_THR_ERR "testfiles/storm_protection_storm_thr_err.conf"
+#define SP_CONF_MULT_EN_ERR "testfiles/storm_protection_mult_en_err.conf"
+#define SP_CONF_MULT_THR_ERR "testfiles/storm_protection_mult_thr_err.conf"
+#define SP_CONF_UNKNOW_EN_ERR "testfiles/storm_protection_unknow_en_err.conf"
+#define SP_CONF_UNKNOW_THR_ERR "testfiles/storm_protection_unknow_thr_err.conf"
+#define SP_CONF_MAC_NOT_IN_WL "testfiles/storm_protection_mac_not_in_wl.conf"
+
+static void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+// test_create_test_file ();
+}
+
+void
+teardown (void)
+{
+}
+
+START_TEST (test_libspid_eoc_storm_get)
+{
+ int ret;
+ char index[2];
+ char mac[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_storm_entry_t entry;
+ static libspid_eoc_storm_entry_t entries[LIBSPID_PORT_TOTAL_MAX];
+ unsigned int count;
+ unsigned int i = 0;
+
+ system ("cp " STORM_PROTECTION_CONF
+ " "LIBSPID_EOC_PORT_V2_FILE );
+
+ strcpy (index, "0");
+ strcpy (mac, "00:11:22:33:44:55");
+
+ ret = libspid_eoc_storm_get (0, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must false, for param 1 error");
+
+ ret = libspid_eoc_storm_get (mac, 0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must false, for param 2 error");
+
+ ret = libspid_eoc_storm_get (mac, index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must false, for param 3 error");
+
+ strcpy (index, "0");
+ strcpy (mac, "00:11:22:33:44:55");
+ ret = libspid_eoc_storm_get (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must false, mac no found");
+
+ strcpy (index, "9");
+ strcpy (mac, "00:13:D7:00:00:01");
+ ret = libspid_eoc_storm_get (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must false, port index error");
+
+ ret = libspid_eoc_storm_get_list (entries, (int *)&count);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (20 != count, "must count equ to 20");
+
+ for (i = 0 ; i < count; i ++)
+ {
+ ret = libspid_eoc_storm_get (entries[i].mac_addr,
+ entries[i].port_index,
+ &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = strcasecmp (entries[i].mac_addr, entry.mac_addr);
+ fail_if (0 != ret, "must equ, get error");
+
+ ret = strcmp (entries[i].port_index, entry.port_index);
+ fail_if (0 != ret, "must equ, get error");
+
+ ret = strcmp (entries[i].bcast_protect_en, entry.bcast_protect_en);
+ fail_if (0 != ret, "must equ, get error");
+
+ ret = strcmp (entries[i].bcast_thres_hold, entry.bcast_thres_hold);
+ fail_if (0 != ret, "must equ, get error");
+
+ ret = strcmp (entries[i].multi_protect_en, entry.multi_protect_en);
+ fail_if (0 != ret, "must equ, get error");
+
+ ret = strcmp (entries[i].multi_thres_hold, entry.multi_thres_hold);
+ fail_if (0 != ret, "must equ, get error");
+
+ ret = strcmp (entries[i].unknow_protect_en, entry.unknow_protect_en);
+ fail_if (0 != ret, "must equ, get error");
+
+ ret = strcmp (entries[i].unknow_thres_hold, entry.unknow_thres_hold);
+ fail_if (0 != ret, "must equ, get error");
+ }
+
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_storm_set)
+{
+ int ret;
+ char index[2];
+ char mac[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_storm_entry_t entry, entry2;
+
+ system ("cp " STORM_PROTECTION_CONF
+ " "LIBSPID_EOC_PORT_V2_FILE );
+
+ strcpy (index, "0");
+ strcpy (mac, "00:11:22:33:44:55");
+
+ ret = libspid_eoc_storm_set (0, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for param 1 error");
+
+ ret = libspid_eoc_storm_set (mac, 0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for param 2 error");
+
+ ret = libspid_eoc_storm_set (mac, index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for param 3 error");
+
+ ret = libspid_eoc_storm_get (mac, index, &entry2);
+ fail_if (LIBSPID_SUCCESS == ret, "must false, the mac.index not found");
+
+ strcpy (index, "0");
+ strcpy (mac, "00:11:22:33:44:55");
+ strcpy (entry.mac_addr, mac);
+ strcpy (entry.port_index, index);
+ strcpy (entry.bcast_protect_en, "1");
+ strcpy (entry.bcast_thres_hold, "555");
+ strcpy (entry.multi_protect_en, "0");
+ strcpy (entry.multi_thres_hold, "666");
+ strcpy (entry.unknow_protect_en, "1");
+ strcpy (entry.unknow_thres_hold, "777");
+ ret = libspid_eoc_storm_set (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, mac and port not exist");
+
+ strcpy (index, "0");
+ strcpy (mac, "00:13:D7:00:00:01");
+ strcpy (entry.mac_addr, mac);
+ strcpy (entry.port_index, index);
+ strcpy (entry.bcast_protect_en, "1");
+ strcpy (entry.bcast_thres_hold, "222");
+ strcpy (entry.multi_protect_en, "0");
+ strcpy (entry.multi_thres_hold, "333");
+ strcpy (entry.unknow_protect_en, "1");
+ strcpy (entry.unknow_thres_hold, "444");
+ ret = libspid_eoc_storm_set (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_eoc_storm_get (mac, index, &entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = strcasecmp (entry.mac_addr, entry2.mac_addr);
+ fail_if (0 != ret, "must equ, get is not equ set");
+
+ ret = strcmp (entry.port_index, entry2.port_index);
+ fail_if (0 != ret, "must equ, get is not equ set");
+
+ ret = strcmp (entry.bcast_protect_en, entry2.bcast_protect_en);
+ fail_if (0 != ret, "must equ, get is not equ set");
+
+ ret = strcmp (entry.bcast_thres_hold, entry2.bcast_thres_hold);
+ fail_if (0 != ret, "must equ, get is not equ set");
+
+ ret = strcmp (entry.multi_protect_en, entry2.multi_protect_en);
+ fail_if (0 != ret, "must equ, get is not equ set");
+
+ ret = strcmp (entry.multi_thres_hold, entry2.multi_thres_hold);
+ fail_if (0 != ret, "must equ, get is not equ set");
+
+ ret = strcmp (entry.unknow_protect_en, entry2.unknow_protect_en);
+ fail_if (0 != ret, "must equ, get is not equ set");
+
+ ret = strcmp (entry.unknow_thres_hold, entry2.unknow_thres_hold);
+ fail_if (0 != ret, "must equ, get is not equ set");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_storm_get_list)
+{
+ int ret;
+ char mac[4][LIBSPID_MAC_STR_LEN] = {
+ "00:13:D7:00:00:01", "00:13:D7:00:00:02",
+ "00:13:D7:00:00:65", "00:13:D7:00:00:66" };
+ char *index[5] = {"0", "1", "2", "3", "4"};
+
+ int i = 0, y = 0;
+ int cnt = LIBSPID_PORT_TOTAL_MAX;
+ static libspid_eoc_storm_entry_t entries[LIBSPID_PORT_TOTAL_MAX];
+ static libspid_eoc_storm_entry_t entry;
+
+ system ("cp " STORM_PROTECTION_CONF
+ " "LIBSPID_EOC_PORT_V2_FILE );
+
+ ret = libspid_eoc_storm_get_list (0, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for param 1 error");
+
+ ret = libspid_eoc_storm_get_list (entries, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for param 2 error");
+
+ ret = libspid_eoc_storm_get_list (entries, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (cnt != 20, "get list cnt error");
+
+ for (i = 0; i < 4; i ++)
+ {
+ for (y = 0; y < 5; y ++)
+ {
+ ret = strcasecmp (entries[i*5 + y].mac_addr, mac[i]);
+ fail_if (0 != ret, "must equ, get mac addr error");
+
+ ret = libspid_eoc_storm_get (mac[i], index[y], &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = strcmp (entries[i*5 + y].port_index, entry.port_index);
+ fail_if (0 != ret, "must equ, get port index err");
+
+ ret = strcmp (entries[i*5 + y].bcast_protect_en,
+ entry.bcast_protect_en);
+ fail_if (0 != ret, "must equ, get bcast_protect_en error");
+
+ ret = strcmp (entries[i*5 + y].bcast_thres_hold,
+ entry.bcast_thres_hold);
+ fail_if (0 != ret, "must equ, get bcast_thres_hold error");
+
+ ret = strcmp (entries[i*5 + y].multi_protect_en,
+ entry.multi_protect_en);
+ fail_if (0 != ret, "must equ, get multi_protect_en error");
+
+ ret = strcmp (entries[i*5 + y].multi_thres_hold,
+ entry.multi_thres_hold);
+ fail_if (0 != ret, "must equ, get multi_thres_hold error");
+
+ ret = strcmp (entries[i*5 + y].unknow_protect_en,
+ entry.unknow_protect_en);
+ fail_if (0 != ret, "must equ, get unknow_protect_en error");
+
+ ret = strcmp (entries[i*5 + y].unknow_thres_hold,
+ entry.unknow_thres_hold);
+ fail_if (0 != ret, "must equ, get unknow_thres_hold error");
+ }
+ }
+}
+END_TEST
+
+
+START_TEST (test_libspid_eoc_storm_check)
+{
+ int ret;
+
+ setup ();
+ system ("cp " STORM_PROTECTION_CONF
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ setup ();
+ system ("cp " SP_CONF_MAC_FORMAT
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for mac format error");
+
+ setup ();
+ system ("cp " SP_CONF_DUP_KEY
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for mac double same key");
+
+ setup ();
+ system ("cp " SP_CONF_INDEX_ERR
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for port index invalid");
+
+
+ setup ();
+ system ("cp " SP_CONF_STORM_EN_ERR
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for storm en error");
+
+ setup ();
+ system ("cp " SP_CONF_STORM_THR_ERR
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for storm thr error");
+
+ setup ();
+ system ("cp " SP_CONF_MULT_EN_ERR
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for multi en err");
+
+ setup ();
+ system ("cp " SP_CONF_MULT_THR_ERR
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for multi thr err");
+
+ setup ();
+ system ("cp " SP_CONF_UNKNOW_EN_ERR
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for unknow en err");
+
+ setup ();
+ system ("cp " SP_CONF_UNKNOW_THR_ERR
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for unknow thr err");
+
+ setup ();
+ system ("cp " SP_CONF_MAC_NOT_IN_WL
+ " "LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF
+ " "LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_storm_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, for mac not in wl");
+
+}
+END_TEST
+
+Suite *
+libspid_eoc_suite ()
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_storm_get);
+ tcase_add_test (tc_core, test_libspid_eoc_storm_set);
+ tcase_add_test (tc_core, test_libspid_eoc_storm_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_storm_check);
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/system_utests.c b/cleopatre/devkit/tests/libspid/utests/src/system_utests.c
index 17b72ecd77..86ebb968bd 100644
--- a/cleopatre/devkit/tests/libspid/utests/src/system_utests.c
+++ b/cleopatre/devkit/tests/libspid/utests/src/system_utests.c
@@ -1,6 +1,6 @@
/* Cleopatre project {{{
*
- * Copyright (C) 2008 Spidcom
+ * Copyright (C) 2012 MStar
*
* <<<Licence>>>
*
@@ -27,6 +27,8 @@
#include <sys/wait.h>
#include <dirent.h>
#include <sys/stat.h>
+#include <time.h>
+#include <utime.h>
#include "inc/system_utests.h"
#include "path.h"
@@ -40,88 +42,91 @@
#define TRACE(...)
#endif
+#define TEST_DIR "testfiles"
#define VERSION_TST "testfiles/version.tst"
#define UPTIME_TST "testfiles/uptime.tst"
#define MEMINFO_TST "testfiles/meminfo.tst"
#define MTD_TST "testfiles/mtd.tst"
+#define SYSTEM_RESET_CAUSE_TST "testfiles/reset_cause.tst"
+#define SYSTEM_CONF_EOC "testfiles/system_v2.conf"
+#define SYSTEM_CONF_MOD "testfiles/system.conf"
#define PLC_ADDR "\x00\x13\xd7\x11\x10\x20"
/** local variables */
volatile sig_atomic_t handler_called = 0;
/* fixtures - run before and after each unit test */
-void setup(void)
+void setup (void)
{
int ret;
char buf[256];
struct dirent *d;
DIR *dir;
- ret = mkdir(UTESTS_TMP_DIR, 0770);
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
if (ret < 0 && errno != EEXIST)
{
- perror("mkdir(UTESTS_TMP_DIR, 0770)");
- exit(EXIT_FAILURE);
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
}
/* initialize - delete all files which have left from previous testing */
- dir = opendir(UTESTS_TMP_DIR);
+ dir = opendir (UTESTS_TMP_DIR);
- while ( (d = readdir(dir)) != NULL )
+ while ((d = readdir (dir)) != NULL)
{
- //printf("%s\n",d->d_name);
- sprintf(buf, "%s/%s", "/tmp/utests", d->d_name);
- remove(buf);
+ sprintf (buf, "%s/%s", "/tmp/utests", d->d_name);
+ remove (buf);
}
/* create other subdirs */
- sprintf(buf, "%s/etc", UTESTS_TMP_DIR);
- ret = mkdir(buf, 0770);
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
if (ret < 0 && errno != EEXIST)
{
- perror("mkdir(UTESTS_TMP_DIR/etc, 0770)");
- exit(EXIT_FAILURE);
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
}
- sprintf(buf, "%s/proc", UTESTS_TMP_DIR);
- ret = mkdir(buf, 0770);
+ sprintf (buf, "%s/proc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
if (ret < 0 && errno != EEXIST)
{
- perror("mkdir(UTESTS_TMP_DIR/proc, 0770)");
- exit(EXIT_FAILURE);
+ perror ("mkdir (UTESTS_TMP_DIR/proc, 0770)");
+ exit (EXIT_FAILURE);
}
- sprintf(buf, "%s/local", UTESTS_TMP_DIR);
- ret = mkdir(buf, 0770);
+ sprintf (buf, "%s/local", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
if (ret < 0 && errno != EEXIST)
{
- perror("mkdir(UTESTS_TMP_DIR, 0770)");
- exit(EXIT_FAILURE);
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
}
- sprintf(buf, "%s/factory", UTESTS_TMP_DIR);
- ret = mkdir(buf, 0770);
+ sprintf (buf, "%s/factory", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
if (ret < 0 && errno != EEXIST)
{
- perror("mkdir(UTESTS_TMP_DIR, 0770)");
- exit(EXIT_FAILURE);
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
}
- sprintf(buf, "%s/dev", UTESTS_TMP_DIR);
- ret = mkdir(buf, 0770);
+ sprintf (buf, "%s/dev", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
if (ret < 0 && errno != EEXIST)
{
- perror("mkdir(UTESTS_TMP_DIR, 0770)");
- exit(EXIT_FAILURE);
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
}
}
-void teardown(void)
+void teardown (void)
{
- char command[512];
- sprintf (command, "rm -f %s", LIBSPID_SIGNAL_INFO_PATH);
- system (command);
+ char command[512];
+ sprintf (command, "rm -f %s", LIBSPID_SIGNAL_INFO_PATH);
+ system (command);
}
@@ -134,12 +139,14 @@ START_TEST (param_get_kernel_version)
char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
/* buffer is NULL */
- ret = libspid_system_get_kernel_version(NULL, LIBSPID_CONFIG_LINE_MAX_LEN);
- fail_if(ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
+ ret = libspid_system_get_kernel_version (NULL,
+ LIBSPID_CONFIG_LINE_MAX_LEN);
+
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
/* buffer_len is zero */
- ret = libspid_system_get_kernel_version(buffer, 0);
- fail_if(ret != LIBSPID_ERROR_PARAM, "buffer_len is 0");
+ ret = libspid_system_get_kernel_version (buffer, 0);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer_len is 0");
}
END_TEST
@@ -151,12 +158,12 @@ START_TEST (param_get_uptime)
unsigned int idle_s;
/* total_s is NULL */
- ret = libspid_system_get_uptime(NULL, &idle_s);
- fail_if(ret != LIBSPID_ERROR_PARAM, "total_s is NULL");
+ ret = libspid_system_get_uptime (NULL, &idle_s);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "total_s is NULL");
/* idle_s is NULL */
- ret = libspid_system_get_uptime(&total_s, NULL);
- fail_if(ret != LIBSPID_ERROR_PARAM, "idle_s is NULL");
+ ret = libspid_system_get_uptime (&total_s, NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "idle_s is NULL");
}
END_TEST
@@ -167,13 +174,36 @@ START_TEST (param_get_meminfo)
char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
/* buffer is NULL */
- ret = libspid_system_get_meminfo(NULL, LIBSPID_CONFIG_LINE_MAX_LEN);
- fail_if(ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
+ ret = libspid_system_get_meminfo (NULL, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
/* buffer_len is zero */
- ret = libspid_system_get_meminfo(buffer, 0);
- fail_if(ret != LIBSPID_ERROR_PARAM, "buffer_len is 0");
+ ret = libspid_system_get_meminfo (buffer, 0);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer_len is 0");
+}
+END_TEST
+
+START_TEST (param_get_memusage_percent)
+{
+ int ret;
+
+ /* buffer is NULL */
+ ret = libspid_system_get_memusage_percent (NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
+
+}
+
+END_TEST
+START_TEST (param_get_cpuload_percent)
+{
+ int ret;
+
+ /* buffer is NULL */
+ ret = libspid_system_get_cpuload_percent (NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
+
}
+
END_TEST
START_TEST (param_get_nvram)
@@ -181,8 +211,56 @@ START_TEST (param_get_nvram)
int ret;
/* nvram is NULL */
- ret = libspid_system_get_nvram(NULL);
- fail_if(ret != LIBSPID_ERROR_PARAM, "nvram is NULL");
+ ret = libspid_system_get_nvram (NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "nvram is NULL");
+}
+END_TEST
+
+START_TEST (param_get_date)
+{
+ int ret;
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
+
+ /* buffer is NULL */
+ ret = libspid_system_get_date (NULL, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
+
+ /* buffer_len is zero */
+ ret = libspid_system_get_date (buffer, 0);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer_len is 0");
+
+}
+END_TEST
+
+START_TEST (param_set_date)
+{
+ int ret;
+
+ /* buffer is NULL */
+ ret = libspid_system_set_date (NULL);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
+
+}
+END_TEST
+
+START_TEST (param_get_reset_cause)
+{
+ int ret;
+ char buffer[SPC300_RESET_CAUSE_STR_MAX_LEN];
+
+ /* buffer is NULL */
+ ret = libspid_system_get_reset_cause (NULL, sizeof (buffer));
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer is NULL");
+
+ /* buffer_len is zero */
+ ret = libspid_system_get_reset_cause (buffer, 0);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "buffer_len is 0");
+
+ /* buffer is too small */
+ ret =
+ libspid_system_get_reset_cause (buffer,
+ SPC300_RESET_CAUSE_STR_MAX_LEN - 1);
+ fail_if (ret != LIBSPID_ERROR_NO_SPACE, "buffer is too small");
}
END_TEST
@@ -206,8 +284,14 @@ tc_param (void)
tcase_add_test (tc_param, param_get_kernel_version);
tcase_add_test (tc_param, param_get_uptime);
tcase_add_test (tc_param, param_get_meminfo);
+ tcase_add_test (tc_param, param_get_memusage_percent);
+ tcase_add_test (tc_param, param_get_cpuload_percent);
tcase_add_test (tc_param, param_get_nvram);
tcase_add_test (tc_param, param_get_plc_addr);
+ tcase_add_test (tc_param, param_get_date);
+ tcase_add_test (tc_param, param_set_date);
+ tcase_add_test (tc_param, param_get_reset_cause);
+
return tc_param;
}
@@ -219,20 +303,23 @@ START_TEST (test_libspid_system_get_kernel_version)
char test_string[LIBSPID_CONFIG_LINE_MAX_LEN];
FILE *fp;
- system("cp " VERSION_TST " " LIBSPID_SYSTEM_VERSION_PATH);
+ system ("cp " VERSION_TST " " LIBSPID_SYSTEM_VERSION_PATH);
- ret = libspid_system_get_kernel_version(buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
- fail_if(ret != LIBSPID_SUCCESS, "libspid_system_get_kernel_version fail");
+ ret = libspid_system_get_kernel_version (buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_system_get_kernel_version fail");
- fp = fopen(LIBSPID_SYSTEM_VERSION_PATH, "r");
+ fp = fopen (LIBSPID_SYSTEM_VERSION_PATH, "r");
if (fp == NULL)
{
- perror("fopen(VERSION_TST, \"r\")");
- exit(EXIT_FAILURE);
+ perror ("fopen (VERSION_TST, \"r\")");
+ exit (EXIT_FAILURE);
}
fail_if (NULL == fgets (test_string, LIBSPID_CONFIG_LINE_MAX_LEN, fp));
- fail_if( strcmp(buffer, test_string) != 0, "libspid_system_get_kernel_version gets wrong data");
- fclose(fp);
+ fail_if (strcmp (buffer, test_string) != 0,
+ "libspid_system_get_kernel_version gets wrong data");
+ fclose (fp);
}
END_TEST
@@ -254,21 +341,21 @@ START_TEST (test_libspid_system_get_uptime)
unsigned int total_s;
unsigned int idle_s;
- system("cp " UPTIME_TST " " LIBSPID_SYSTEM_UPTIME_PATH);
- ret = libspid_system_get_uptime(&total_s, &idle_s);
- fail_if(ret != LIBSPID_SUCCESS, "libspid_system_get_uptime");
+ system ("cp " UPTIME_TST " " LIBSPID_SYSTEM_UPTIME_PATH);
+ ret = libspid_system_get_uptime (&total_s, &idle_s);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_system_get_uptime");
- fp = fopen(UPTIME_TST, "r");
+ fp = fopen (UPTIME_TST, "r");
if (fp == NULL)
{
- perror("fopen(UPTIME_TST, \"r\")");
- exit(EXIT_FAILURE);
+ perror ("fopen (UPTIME_TST, \"r\")");
+ exit (EXIT_FAILURE);
}
fail_if (NULL== fgets (test_string, LIBSPID_CONFIG_LINE_MAX_LEN, fp));
- fclose(fp); /* flushes I/O buffer into the file */
- fail_if(total_s != 11, "libspid_system_get_uptime gets wrong total_s");
- fail_if(idle_s != 333, "libspid_system_get_uptime gets wrong idle_s");
+ fclose (fp); /* flushes I/O buffer into the file */
+ fail_if (total_s != 11, "libspid_system_get_uptime gets wrong total_s");
+ fail_if (idle_s != 333, "libspid_system_get_uptime gets wrong idle_s");
}
END_TEST
@@ -280,82 +367,131 @@ START_TEST (test_libspid_system_get_meminfo)
char line[LIBSPID_CONFIG_LINE_MAX_LEN];
FILE *fp;
- system("cp " MEMINFO_TST " " LIBSPID_SYSTEM_MEMINFO_PATH);
+ system ("cp " MEMINFO_TST " " LIBSPID_SYSTEM_MEMINFO_PATH);
- ret = libspid_system_get_meminfo(buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
+ ret = libspid_system_get_meminfo (buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
- fail_if(ret != LIBSPID_SUCCESS, "libspid_system_get_meminfo fail");
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_system_get_meminfo fail");
- fp = fopen(MEMINFO_TST, "r");
+ fp = fopen (MEMINFO_TST, "r");
if (fp == NULL)
{
- perror("fopen(MEMINFO_TST, \"r\")");
- exit(EXIT_FAILURE);
+ perror ("fopen (MEMINFO_TST, \"r\")");
+ exit (EXIT_FAILURE);
}
memset (test_string, 0, sizeof (test_string));
- while ( fgets(line, LIBSPID_CONFIG_LINE_MAX_LEN, fp) != NULL )
+ while (fgets (line, LIBSPID_CONFIG_LINE_MAX_LEN, fp) != NULL)
{
- strcat(test_string, line);
+ strcat (test_string, line);
}
- fclose(fp);
- fail_if( strcmp(buffer, test_string) != 0, "libspid_system_get_meminfo gets wrong data");
+ fclose (fp);
+ fail_if (strcmp (buffer, test_string) != 0,
+ "libspid_system_get_meminfo gets wrong data");
}
END_TEST
-START_TEST (test_libspid_system_save)
+START_TEST (test_libspid_system_get_memusage_percent)
{
int ret;
- char test_string[LIBSPID_CONFIG_LINE_MAX_LEN] = "test1\ntest2\n"; /* do not forget last '\n' */
+ int percent;
+
+ system ("cp " MEMINFO_TST " " LIBSPID_SYSTEM_MEMINFO_PATH);
+
+ ret = libspid_system_get_memusage_percent (&percent);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_system_get_memusage_percent fail");
+
+ fail_if ((2010216 - 104224) * 100 / 2010216 != percent,
+ "libspid_system_get_memusage_percent gets wrong data");
+}
+END_TEST
+
+START_TEST (test_libspid_system_save)
+{
+ int ret, cnt = 0;
+
+ /* do not forget last '\n' */
+ char test_string[LIBSPID_CONFIG_LINE_MAX_LEN] = "test1\ntest2\n";
FILE *fp;
char tst_file[128] = {0};
struct stat st;
-#ifdef DEBUG
struct dirent *d;
DIR *dir;
-#endif /* DEBUG */
- sprintf(tst_file, "%s/test1", LIBSPID_CONF_ROOT_PATH);
- mknod(tst_file, 0770, S_IFREG);
- sprintf(tst_file, "%s/test2", LIBSPID_CONF_ROOT_PATH);
- mknod(tst_file, 0770, S_IFREG);
- sprintf(tst_file, "%s/test3.conf", LIBSPID_CONF_ROOT_PATH);
- mknod(tst_file, 0770, S_IFREG);
+ sprintf (tst_file, "%s/test1", LIBSPID_CONF_ROOT_PATH);
+ mknod (tst_file, 0770, S_IFREG);
+ sprintf (tst_file, "%s/test2", LIBSPID_CONF_ROOT_PATH);
+ mknod (tst_file, 0770, S_IFREG);
+ sprintf (tst_file, "%s/test3.conf", LIBSPID_CONF_ROOT_PATH);
+ mknod (tst_file, 0770, S_IFREG);
+
+ ret = libspid_system_save ();
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_system_get_save failed if save.lst is not created");
+
+ // test if save directory contains only .conf files
+ dir = opendir (LIBSPID_CONF_SAVE_PATH);
+ if (dir == NULL)
+ {
+ perror ("opendir ()");
+ exit (1);
+ }
+ while ((d = readdir (dir)) != NULL) cnt++;
+
+ closedir (dir);
+
+ fail_if (cnt < 3,
+ "libspid_system_get_save stores less files that expected");
+
+ sprintf (tst_file, "%s/test3.conf", LIBSPID_CONF_SAVE_PATH);
- fp = fopen(LIBSPID_SAVE_LIST_PATH, "w");
+ fail_if (stat (tst_file,&st) != 0,
+ "libspid_system_save does not backup .conf files properly" );
+
+ fp = fopen (LIBSPID_SAVE_LIST_PATH, "w");
if (fp == NULL)
{
- perror("fopen(LIBSPID_SAVE_LIST_PATH, \"w\")");
- exit(EXIT_FAILURE);
+ perror ("fopen (LIBSPID_SAVE_LIST_PATH, \"w\")");
+ exit (EXIT_FAILURE);
}
- fputs(test_string, fp);
- fclose(fp); /* flushes I/O buffer into the file */
+ fputs (test_string, fp);
+ fclose (fp); /* flushes I/O buffer into the file */
- ret = libspid_system_save();
- fail_if(ret != LIBSPID_SUCCESS, "libspid_system_save fail");
+ ret = libspid_system_save ();
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_system_save fail");
/* test if files have been well copied */
- sprintf(tst_file, "%s/test1", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) != 0, "libspid_system_save does not backup files well" );
- sprintf(tst_file, "%s/test2", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) != 0, "libspid_system_save does not backup files well" );
- sprintf(tst_file, "%s/test3.conf", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) != 0, "libspid_system_save does not backup files well" );
+ sprintf (tst_file, "%s/test1", LIBSPID_CONF_SAVE_PATH);
+
+ fail_if (stat (tst_file,&st) != 0,
+ "libspid_system_save does not backup files well" );
+
+ sprintf (tst_file, "%s/test2", LIBSPID_CONF_SAVE_PATH);
+
+ fail_if (stat (tst_file,&st) != 0,
+ "libspid_system_save does not backup files well" );
+
+ sprintf (tst_file, "%s/test3.conf", LIBSPID_CONF_SAVE_PATH);
+
+ fail_if (stat (tst_file,&st) != 0,
+ "libspid_system_save does not backup files well" );
#ifdef DEBUG
/* print contents for debug */
- dir = opendir(LIBSPID_SAVE_DIR_PATH);
+ dir = opendir (LIBSPID_CONF_SAVE_PATH);
if (dir == NULL)
{
- perror("opendir()");
- exit(1);
+ perror ("opendir ()");
+ exit (1);
}
- TRACE("Listing LIBSPID_SAVE_DIR_PATH, %s:\n", LIBSPID_SAVE_DIR_PATH);
- while( (d = readdir(dir)) != NULL )
+ TRACE ("Listing LIBSPID_CONF_SAVE_PATH, %s:\n", LIBSPID_CONF_SAVE_PATH);
+ while ((d = readdir (dir)) != NULL)
{
- TRACE("%s\n",d->d_name);
+ TRACE ("%s\n", d->d_name);
}
#endif
}
@@ -367,23 +503,33 @@ START_TEST (test_libspid_system_factory)
char tst_file[128] = {0};
struct stat st;
+ DIR *dir;
- sprintf(tst_file, "%s/test1", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) != 0, "missing file before test" );
- sprintf(tst_file, "%s/test2", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) != 0, "missing file before test" );
- sprintf(tst_file, "%s/test3.conf", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) != 0, "missing file before test" );
-
- ret = libspid_system_factory();
- fail_if(ret != LIBSPID_SUCCESS, "libspid_system_factory fail");
-
- sprintf(tst_file, "%s/test1", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) == 0, "file not removed" );
- sprintf(tst_file, "%s/test2", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) == 0, "file not removed" );
- sprintf(tst_file, "%s/test3.conf", LIBSPID_SAVE_DIR_PATH);
- fail_if ( stat(tst_file,&st) == 0, "file not removed" );
+ sprintf (tst_file, "%s/test1", LIBSPID_CONF_SAVE_PATH);
+ fail_if (stat (tst_file,&st) != 0, "missing file before test" );
+ sprintf (tst_file, "%s/test2", LIBSPID_CONF_SAVE_PATH);
+ fail_if (stat (tst_file,&st) != 0, "missing file before test" );
+ sprintf (tst_file, "%s/test3.conf", LIBSPID_CONF_SAVE_PATH);
+ fail_if (stat (tst_file,&st) != 0, "missing file before test" );
+
+ sprintf (tst_file, "mkdir %s", LIBSPID_CONF_TRACE_PATH);
+ system (tst_file);
+ dir = opendir (LIBSPID_CONF_TRACE_PATH);
+ fail_if (dir == NULL, "missing trace dir before test");
+
+ ret = libspid_system_factory ();
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_system_factory fail");
+
+ /* test if files have been deleted */
+ sprintf (tst_file, "%s/test1", LIBSPID_CONF_SAVE_PATH);
+ fail_if (stat (tst_file,&st) == 0, "file not removed" );
+ sprintf (tst_file, "%s/test2", LIBSPID_CONF_SAVE_PATH);
+ fail_if (stat (tst_file,&st) == 0, "file not removed" );
+ sprintf (tst_file, "%s/test3.conf", LIBSPID_CONF_SAVE_PATH);
+ fail_if (stat (tst_file,&st) == 0, "file not removed" );
+
+ dir = opendir (LIBSPID_CONF_TRACE_PATH);
+ fail_if (dir != NULL, "trace dir not removed");
}
END_TEST
@@ -417,24 +563,24 @@ START_TEST (test_libspid_system_get_nvram)
system("cp " MTD_TST " " LIBSPID_SYSTEM_MTD_PATH);
/* prepare /dev/mtd1 */
- sprintf(nvram_path, "%s/mtd1", LIBSPID_DEV_PATH);
- fp = fopen(nvram_path, "w");
+ sprintf (nvram_path, "%s/mtd1", LIBSPID_DEV_PATH);
+ fp = fopen (nvram_path, "w");
if (fp == NULL)
{
- perror("fopen(nvram_path, \"w\")");
- exit(EXIT_FAILURE);
+ perror ("fopen (nvram_path, \"w\")");
+ exit (EXIT_FAILURE);
}
- fwrite( &nvram, sizeof(spidcom_nvram_t), 1, fp );
- fclose(fp); /* flushes I/O buffer into the file */
+ fwrite (&nvram, sizeof (spidcom_nvram_t), 1, fp );
+ fclose (fp); /* flushes I/O buffer into the file */
- memset( &ret_nvram, 0x0, sizeof(spidcom_nvram_t) );
- ret = libspid_system_get_nvram(&ret_nvram);
- fail_if(ret != LIBSPID_SUCCESS, "libspid_system_get_nvram fail");
+ memset (&ret_nvram, 0x0, sizeof (spidcom_nvram_t) );
+ ret = libspid_system_get_nvram (&ret_nvram);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_system_get_nvram fail");
- ret = memcmp ( &ret_nvram, &nvram, sizeof(spidcom_nvram_t) );
- fail_if(ret != 0, "libspid_system_get_nvram gets wrong nvram");
+ ret = memcmp (&ret_nvram, &nvram, sizeof (spidcom_nvram_t) );
+ fail_if (ret != 0, "libspid_system_get_nvram gets wrong nvram");
#ifdef DEBUG
printf("ret_nvram.pkg_cfg = %#x\n", ret_nvram.pkg_cfg);
@@ -444,8 +590,65 @@ START_TEST (test_libspid_system_get_nvram)
}
END_TEST
+START_TEST (test_libspid_system_set_nvram)
+{
+ static spidcom_nvram_t nvram;
+ static spidcom_nvram_t ret_nvram;
+ int ret;
+ FILE *fp;
+ char nvram_path[128] = {0};
+
+ system ("cp " MTD_TST " " LIBSPID_SYSTEM_MTD_PATH);
+
+ /* prepare initial /dev/mtd1 contents */
+ memset(&nvram, 0x0, sizeof(spidcom_nvram_t));
+ strcpy(nvram.magic, SPC300_NVRAM_MAGIC); /* magic number "NVRAM\0\0\0" */
+ nvram.pkg_cfg = 0x123; /* SPC300 package configuration register */
+ nvram.io.spcpio.gpio_0_7_cfg = 0x45; /* SPC300 GPIO 0 to 7 configuration register */
+ nvram.io.spcpio.gpio_8_15_cfg = 0x6789; /* SPC300 GPIO 8 to 15 configuration register */
+ nvram.dram.sdram.config = 0xABC; /* SPC300 SDRAM configuration register */
+ nvram.dram.sdram.timing0 = 0x11; /* SPC300 SDRAM timing register 0 */
+ nvram.dram.sdram.timing1 = 0x222; /* SPC300 SDRAM timing register 1 */
+ nvram.dram.sdram.refresh = 0xdef; /* SPC300 SDRAM refresh register */
+ nvram.img_0_offset = 0x140000; /* offset of first image address */
+ nvram.nb_images = 2; /* Max Number of Images present in flash */
+ memcpy(nvram.plc_address, PLC_ADDR, 6);
+
+ ret = libspid_system_set_nvram(&nvram);
+ fail_if(ret != LIBSPID_SUCCESS, "libspid_system_set_nvram failed");
+
+ /* collect new /dev/mtd1 contents */
+ memset (&ret_nvram, 0x0, sizeof (spidcom_nvram_t));
+ sprintf (nvram_path, "%s/mtd1", LIBSPID_DEV_PATH);
+ fp = fopen (nvram_path, "r");
+ if (fp == NULL)
+ {
+ perror ("Cannot open NVRAM path for reading");
+ exit (EXIT_FAILURE);
+ }
+ fail_if (fread (&ret_nvram, sizeof (spidcom_nvram_t), 1, fp) != 1);
+ fclose (fp);
+
+ ret = memcmp (&ret_nvram, &nvram, sizeof (spidcom_nvram_t));
+ fail_if (ret != 0,
+ "libspid_system_set_nvram stores wrong NVRAM contents");
+
+#ifdef DEBUG
+ printf ("ret_nvram.pkg_cfg = %#x\n", ret_nvram.pkg_cfg);
+ printf ("ret_nvram.sdram_config = %#x\n", ret_nvram.sdram_config);
+ printf ("ret_nvram.nb_images = %#x\n", ret_nvram.nb_images);
+#endif
+}
+END_TEST
+
START_TEST (test_libspid_system_get_date)
{
+ int ret;
+ char buffer[LIBSPID_CONFIG_LINE_MAX_LEN];
+
+ ret = libspid_system_get_date (buffer, LIBSPID_CONFIG_LINE_MAX_LEN);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_system_get_date fail");
+
}
END_TEST
@@ -474,56 +677,68 @@ START_TEST (test_libspid_system_file_update_register)
strcpy (key, filename);
/* Test wrong input parameters. */
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (0, filename,
- callback));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (rx_pid, NULL,
- callback));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (rx_pid,
- filename_too_long, callback));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_register (rx_pid,
- filename, NULL));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_register (0, filename, callback));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_register (rx_pid, NULL, callback));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_register (rx_pid,
+ filename_too_long,
+ callback));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_register (rx_pid, filename, NULL));
/* Test to register filename/rx_pid. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid, filename,
- callback));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (rx_pid, filename, callback));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
/* Check "signal.info" file contents.*/
- fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
- LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
- LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (LIBSPID_SUCCESS ==
+ libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key,
+ &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
fail_unless (1 == elt_number);
fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "1"));
/* Test to register another rx_pid. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid + 1,
- filename, callback));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid + 1,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (rx_pid + 1, filename,
+ callback));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid + 1, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
/* Check "signal.info" file contents.*/
strcpy (key, filename);
elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
- fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
- LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
- LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (LIBSPID_SUCCESS ==
+ libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key,
+ &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
fail_unless (2 == elt_number);
fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "1"));
fail_unless ((NULL != elt[1]) && !strcmp (elt[1], "2"));
- /* Test when the given process has already registered to the given file update. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid, filename,
- callback));
+ /* Test when the given process has already
+ * registered to the given file update. */
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (rx_pid, filename, callback));
/* Check "signal.info" file contents.*/
strcpy (key, filename);
elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
- fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
- LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
- LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (LIBSPID_SUCCESS ==
+ libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key,
+ &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
fail_unless (2 == elt_number);
fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "1"));
fail_unless ((NULL != elt[1]) && !strcmp (elt[1], "2"));
@@ -547,70 +762,86 @@ START_TEST (test_libspid_system_file_update_unregister)
strcpy (key, filename);
/* Test wrong input parameters. */
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_unregister (0,
- filename));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_unregister (rx_pid1,
- NULL));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_unregister (rx_pid1,
- filename_too_long));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_unregister (0, filename));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_unregister (rx_pid1, NULL));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_unregister (rx_pid1,
+ filename_too_long));
/* Test when no process is registered to the given file update. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid1, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_unregister (rx_pid1, filename));
/* Test when the process is not registered to the given file update. */
/** rx_pid1 registration */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid1,
- filename, callback));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid1,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (rx_pid1, filename, callback));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid1, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
/** end rx_pid1 registration */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid2, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_unregister (rx_pid2, filename));
/* Check "signal.info" file contents.*/
- fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
- LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
- LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (LIBSPID_SUCCESS ==
+ libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key,
+ &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
fail_unless (1 == elt_number);
fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "10"));
/* Test when several processes are registered to the given file update. */
/** rx_pid2 registration */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid2, filename,
- callback));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid2,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (rx_pid2, filename, callback));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid2, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
/** end rx_pid2 registration */
/** rx_pid3 registration */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (rx_pid3, filename,
- callback));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid3,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (rx_pid3, filename, callback));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid3, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
/** end rx_pid3 registration */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid1, filename));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid1,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_unregister (rx_pid1, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid1, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid3, filename));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid3,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_unregister (rx_pid3, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid3, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
/* Check "signal.info" file contents.*/
strcpy (key, filename);
elt_number = LIBSPID_CONFIG_ELT_MAX_NB;
- fail_unless (LIBSPID_SUCCESS == libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
- LIBSPID_SIGNAL_INFO_DELIMITER, key, &elt_number, elt, buffer,
- LIBSPID_CONFIG_LINE_MAX_LEN));
+ fail_unless (LIBSPID_SUCCESS ==
+ libspid_config_read_line (LIBSPID_SIGNAL_INFO_PATH,
+ LIBSPID_SIGNAL_INFO_DELIMITER, key,
+ &elt_number, elt, buffer,
+ LIBSPID_CONFIG_LINE_MAX_LEN));
fail_unless (1 == elt_number);
fail_unless ((NULL != elt[0]) && !strcmp (elt[0], "20"));
/* Test when only one process is registered to the given file update. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (rx_pid2, filename));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid2,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_unregister (rx_pid2, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid2, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
}
END_TEST
@@ -627,63 +858,86 @@ START_TEST (test_libspid_system_file_update_is_registered)
filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = '\0';
/* Test wrong input parameters. */
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (0,
- filename, &is_registered));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (rx_pid,
- NULL, &is_registered));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (rx_pid,
- filename_too_long, &is_registered));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_is_registered (rx_pid,
- filename, NULL));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_is_registered (0, filename,
+ &is_registered));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_is_registered (rx_pid, NULL,
+ &is_registered));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_is_registered (rx_pid, filename_too_long,
+ &is_registered));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_is_registered (rx_pid, filename, NULL));
/* Test when "signal.info" file does not exist. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
- /* Test when "signal.info" file exists but filename/rx_pid is not registered. */
+ /* Test when "signal.info" file exists
+ * but filename/rx_pid is not registered. */
sprintf (command, "touch %s", LIBSPID_SIGNAL_INFO_PATH);
system (command);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
sprintf (command, "echo %s%s%d > %s", wrong_filename,
- LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 1, LIBSPID_SIGNAL_INFO_PATH);
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 1,
+ LIBSPID_SIGNAL_INFO_PATH);
+
system (command);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
sprintf (command, "echo %s%s%d > %s", wrong_filename,
- LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid, LIBSPID_SIGNAL_INFO_PATH);
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid,
+ LIBSPID_SIGNAL_INFO_PATH);
+
system (command);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
sprintf (command, "echo %s%s%d > %s", filename,
- LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 1, LIBSPID_SIGNAL_INFO_PATH);
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 1,
+ LIBSPID_SIGNAL_INFO_PATH);
+
system (command);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid, filename,
+ &is_registered));
fail_if (LIBSPID_FALSE != is_registered);
/* Test when "signal.info" file exists and filename/rx_pid is registered. */
sprintf (command, "echo %s%s%d > %s", filename,
- LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid, LIBSPID_SIGNAL_INFO_PATH);
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid,
+ LIBSPID_SIGNAL_INFO_PATH);
+
system (command);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
- /* Test when "signal.info" file exists and several rx_pid are registered on filename. */
+ /* Test when "signal.info" file exists and several
+ * rx_pid are registered on filename. */
sprintf (command, "echo %s%s%d%s%d > %s", filename,
- LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 2, LIBSPID_SIGNAL_INFO_DELIMITER,
- rx_pid + 3, LIBSPID_SIGNAL_INFO_PATH);
+ LIBSPID_SIGNAL_INFO_DELIMITER, rx_pid + 2,
+ LIBSPID_SIGNAL_INFO_DELIMITER,
+ rx_pid + 3, LIBSPID_SIGNAL_INFO_PATH);
+
system (command);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid + 3,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid + 3, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (rx_pid + 2,
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (rx_pid + 2, filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
}
END_TEST
@@ -698,26 +952,42 @@ START_TEST (test_libspid_system_file_update_warn)
filename_too_long[LIBSPID_CONFIG_KEY_MAX_LEN + 1] = '\0';
/* Test wrong input parameters. */
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_warn (-1, filename));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_warn (tx_pid, NULL));
- fail_if (LIBSPID_ERROR_PARAM != libspid_system_file_update_warn (tx_pid,
- filename_too_long));
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_warn (-1, filename));
+
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_warn (tx_pid, NULL));
+
+ fail_if (LIBSPID_ERROR_PARAM !=
+ libspid_system_file_update_warn (tx_pid, filename_too_long));
/* Test when no process is registered. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_warn (tx_pid, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_warn (tx_pid, filename));
+
fail_if (0 != handler_called);
/* Test when my PID is registered. */
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (getpid(), filename,
- callback));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_is_registered (getpid(),
- filename, &is_registered));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (getpid (), filename,
+ callback));
+
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_is_registered (getpid (), filename,
+ &is_registered));
fail_if (LIBSPID_TRUE != is_registered);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_warn (getpid(), filename));
+
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_warn (getpid (), filename));
+
fail_if (handler_called);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_warn (tx_pid, filename));
+
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_warn (tx_pid, filename));
fail_if (!handler_called);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (getpid(), filename));
+
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_unregister (getpid (), filename));
handler_called = 0;
/* Test with a registered process that no longer exists. */
@@ -726,11 +996,14 @@ START_TEST (test_libspid_system_file_update_warn)
if (child_pid)
{
fail_if (waitpid (child_pid, NULL, 0) != child_pid);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_register (child_pid, filename,
- callback));
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_warn (tx_pid, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_register (child_pid, filename,
+ callback));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_warn (tx_pid, filename));
fail_if (handler_called);
- fail_if (LIBSPID_SUCCESS != libspid_system_file_update_unregister (child_pid, filename));
+ fail_if (LIBSPID_SUCCESS !=
+ libspid_system_file_update_unregister (child_pid, filename));
}
else
{
@@ -739,49 +1012,131 @@ START_TEST (test_libspid_system_file_update_warn)
}
END_TEST
-extern Suite* libspid_system_suite(void)
+START_TEST (test_libspid_system_file_is_updated)
+{
+ struct timespec last_check;
+ memset (&last_check, 0, sizeof (struct timespec));
+
+ system ("cp " TEST_DIR "/eoc.conf" " " LIBSPID_EOC_CONF_PATH);
+ clock_gettime (CLOCK_REALTIME, &last_check);
+ fail_if (LIBSPID_FALSE !=
+ libspid_system_file_is_updated (last_check,
+ LIBSPID_EOC_CONF_PATH));
+ /* Sleep 1s. */
+ sleep (1);
+ /* Touch file. */
+ utime (LIBSPID_EOC_CONF_PATH, NULL);
+ fail_if (LIBSPID_TRUE !=
+ libspid_system_file_is_updated (last_check,
+ LIBSPID_EOC_CONF_PATH));
+ clock_gettime (CLOCK_REALTIME, &last_check);
+
+ fail_if (LIBSPID_FALSE !=
+ libspid_system_file_is_updated (last_check,
+ LIBSPID_EOC_CONF_PATH));
+ /* Sleep 1s. */
+ sleep (1);
+ /* Touch file. */
+ utime (LIBSPID_EOC_CONF_PATH, NULL);
+ fail_if (LIBSPID_TRUE !=
+ libspid_system_file_is_updated (last_check,
+ LIBSPID_EOC_CONF_PATH));
+}
+END_TEST
+
+START_TEST (test_libspid_system_nscrtv_eponeoc_mod_eoc)
+{
+ int ret;
+ int value;
+
+ ret = libspid_system_nscrtv_eponeoc_mod_eoc (0);
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of param 1 error");
+
+ ret = libspid_system_nscrtv_eponeoc_mod_eoc (&value);
+ fail_if (LIBSPID_SUCCESS != ret,
+ "must suc, even if system conf not exist");
+ fail_if (LIBSPID_FALSE != value,
+ "must is false, even if system conf not exist");
+
+ system ("cp -f " SYSTEM_CONF_MOD " " LIBSPID_SYSTEM_CONF_PATH);
+
+ ret = libspid_system_nscrtv_eponeoc_mod_eoc (&value);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (LIBSPID_FALSE != value, "value must be false");
+
+ system ("cp -f " SYSTEM_CONF_EOC " " LIBSPID_SYSTEM_CONF_PATH);
+
+ ret = libspid_system_nscrtv_eponeoc_mod_eoc (&value);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+ fail_if (LIBSPID_TRUE != value, "value must be true");
+
+}
+END_TEST
+
+START_TEST (test_libspid_system_get_reset_cause)
+{
+ int ret;
+ char buffer[SPC300_RESET_CAUSE_STR_MAX_LEN];
+
+ ret = system ("cp " SYSTEM_RESET_CAUSE_TST " "
+ LIBSPID_SYSTEM_RESET_CAUSE_PATH);
+ fail_if (ret != 0, "system () fail");
+
+ ret = libspid_system_get_reset_cause (buffer, sizeof (buffer));
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_system_get_reset_cause fail");
+ fail_if (strcmp (buffer, "watchdog"));
+}
+END_TEST
+
+extern Suite* libspid_system_suite (void)
{
- Suite *s = suite_create("LIBSPID_SYSTEM");
- TCase *tc_core = tcase_create("Core");
+ Suite *s = suite_create ("LIBSPID_SYSTEM");
+ TCase *tc_core = tcase_create ("Core");
tcase_add_checked_fixture (tc_core, setup, teardown);
//Test system_init
- tcase_add_test(tc_core, test_libspid_system_get_kernel_version);
- tcase_add_test(tc_core, test_libspid_system_get_plc_version);
- tcase_add_test(tc_core, test_libspid_system_get_av_version);
- tcase_add_test(tc_core, test_libspid_system_get_uptime);
- tcase_add_test(tc_core, test_libspid_system_get_meminfo);
- tcase_add_test(tc_core, test_libspid_system_save);
- tcase_add_test(tc_core, test_libspid_system_factory);
- tcase_add_test(tc_core, test_libspid_system_get_nvram);
- tcase_add_test(tc_core, test_libspid_system_get_date);
- tcase_add_test(tc_core, test_libspid_system_file_update_is_registered);
- tcase_add_test(tc_core, test_libspid_system_file_update_register);
- tcase_add_test(tc_core, test_libspid_system_file_update_unregister);
- tcase_add_test(tc_core, test_libspid_system_file_update_warn);
-
- suite_add_tcase(s, tc_core);
- suite_add_tcase(s, tc_param());
+ tcase_add_test (tc_core, test_libspid_system_get_kernel_version);
+ tcase_add_test (tc_core, test_libspid_system_get_plc_version);
+ tcase_add_test (tc_core, test_libspid_system_get_av_version);
+ tcase_add_test (tc_core, test_libspid_system_get_uptime);
+ tcase_add_test (tc_core, test_libspid_system_get_meminfo);
+ tcase_add_test (tc_core, test_libspid_system_get_reset_cause);
+ tcase_add_test (tc_core, test_libspid_system_get_memusage_percent);
+ tcase_add_test (tc_core, test_libspid_system_save);
+ tcase_add_test (tc_core, test_libspid_system_factory);
+ tcase_add_test (tc_core, test_libspid_system_get_nvram);
+ tcase_add_test (tc_core, test_libspid_system_set_nvram);
+ tcase_add_test (tc_core, test_libspid_system_get_date);
+ tcase_add_test (tc_core, test_libspid_system_file_update_is_registered);
+ tcase_add_test (tc_core, test_libspid_system_file_update_register);
+ tcase_add_test (tc_core, test_libspid_system_file_update_unregister);
+ tcase_add_test (tc_core, test_libspid_system_file_update_warn);
+ tcase_add_test (tc_core, test_libspid_system_file_is_updated);
+ tcase_add_test (tc_core, test_libspid_system_nscrtv_eponeoc_mod_eoc);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
return s;
}
-int main(void)
+int main (void)
{
int number_failed = 0;
Suite *s;
//Run system tests
- s = libspid_system_suite();
+ s = libspid_system_suite ();
- SRunner *sr = srunner_create(s);
- //srunner_set_fork_status (sr, CK_NOFORK);
- srunner_set_fork_status (sr, CK_FORK);
- srunner_run_all(sr, CK_NORMAL);
- number_failed = srunner_ntests_failed(sr);
- srunner_free(sr);
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
/* clean behind */
- system("rm -r "UTESTS_TMP_DIR);
+ system ("rm -r "UTESTS_TMP_DIR);
return (number_failed == 0) ? 0 : -1;
}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/trap_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/trap_eoc_utests.c
new file mode 100644
index 0000000000..420f0fa90c
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/trap_eoc_utests.c
@@ -0,0 +1,373 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file trap_eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+# define TRACE(...) printf ("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+# define TRACE(...)
+#endif
+
+/* local constants */
+#define TRAP_CONF "testfiles/trap.conf"
+#define TRAP_ENTRY_NUM 4
+#define TRAP_DU_IP_CONF "testfiles/trap_du_ip.conf"
+#define TRAP_EN_ERROR_CONF "testfiles/trap_en_error.conf"
+#define TRAP_IP_ERROR_CONF "testfiles/trap_ip_error.conf"
+#define TRAP_NULL_COMMUNITY_CONF "testfiles/trap_null_community.conf"
+#define TRAP_COMMUNITY_LONG_CONF "testfiles/trap_community_long.conf"
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+START_TEST (test_libspid_eoc_trap_set)
+{
+ int ret;
+
+ libspid_eoc_trap_entry_t eoc_trap_entry, eoc_trap_entry2;
+
+ system ("cp " TRAP_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_trap_set (0);
+ fail_unless (ret != LIBSPID_SUCCESS,
+ "must false, because of param 1 error");
+
+ memset (&eoc_trap_entry, 0, sizeof (eoc_trap_entry));
+
+ strcpy (eoc_trap_entry.ip_address, "aabbcc");
+ strcpy (eoc_trap_entry.status, LIBSPID_EOC_TRAP_STATUS_IDLE);
+ strcpy (eoc_trap_entry.community, "public");
+ ret = libspid_eoc_trap_set (&eoc_trap_entry);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, because of param ip error");
+
+ strcpy (eoc_trap_entry.ip_address, "172.21.16.8");
+ strcpy (eoc_trap_entry.status, "");
+ strcpy (eoc_trap_entry.community, "public");
+ ret = libspid_eoc_trap_set (&eoc_trap_entry);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, because of param status error");
+
+ strcpy (eoc_trap_entry.ip_address, "172.21.16.8");
+ strcpy (eoc_trap_entry.status, "3");
+ strcpy (eoc_trap_entry.community, "public");
+ ret = libspid_eoc_trap_set (&eoc_trap_entry);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, because of param status error");
+
+ strcpy (eoc_trap_entry.ip_address, "172.21.16.8");
+ strcpy (eoc_trap_entry.status, LIBSPID_EOC_TRAP_STATUS_IDLE);
+ strcpy (eoc_trap_entry.community, "");
+ ret = libspid_eoc_trap_set (&eoc_trap_entry);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must fail, because of param community error");
+
+ strcpy (eoc_trap_entry.ip_address, "172.21.16.8");
+ strcpy (eoc_trap_entry.status, LIBSPID_EOC_TRAP_STATUS_IDLE);
+ strcpy (eoc_trap_entry.community, "public");
+ ret = libspid_eoc_trap_set (&eoc_trap_entry);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = libspid_eoc_trap_get ("172.21.16.8", &eoc_trap_entry2);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (eoc_trap_entry.ip_address, eoc_trap_entry2.ip_address);
+ fail_if (ret != 0, "must equ, buf get not equ set");
+
+ ret = strcmp (eoc_trap_entry.status, eoc_trap_entry2.status);
+ fail_if (ret != 0, "must equ, buf get not equ set");
+
+ ret = strcmp (eoc_trap_entry.community, eoc_trap_entry2.community);
+ fail_if (ret != 0, "must equ, buf get not equ set");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_trap_get)
+{
+ int ret;
+ char ip_addr[16];
+ libspid_eoc_trap_entry_t eoc_trap_entry, eoc_trap_entry2;
+
+ ret = system ("cp " TRAP_CONF " " UTESTS_TMP_DIR "/etc");
+
+ memset (&eoc_trap_entry, 0, sizeof (eoc_trap_entry));
+ strcpy (ip_addr, "172.21.16.22");
+
+ ret = libspid_eoc_trap_get (0, &eoc_trap_entry);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, for param 1 error");
+
+ ret = libspid_eoc_trap_get (ip_addr, 0);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, for param 2 error");
+
+ strcpy (ip_addr, "192.168.1.100");
+ ret = libspid_eoc_trap_get (ip_addr, &eoc_trap_entry);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, no this ip found");
+
+ strcpy (eoc_trap_entry.ip_address, ip_addr);
+ strcpy (eoc_trap_entry.status, LIBSPID_EOC_TRAP_STATUS_BUSY);
+ strcpy (eoc_trap_entry.community, "public");
+ ret = libspid_eoc_trap_set (&eoc_trap_entry);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = libspid_eoc_trap_get (ip_addr, &eoc_trap_entry2);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (eoc_trap_entry2.ip_address, eoc_trap_entry.ip_address);
+ fail_if (ret != 0, "must equ, get not equ set");
+
+ ret = strcmp (eoc_trap_entry2.status, eoc_trap_entry.status);
+ fail_if (ret != 0, "must equ, get not equ set");
+
+ ret = strcmp (eoc_trap_entry2.community, eoc_trap_entry.community);
+ fail_if (ret != 0, "must equ, get not equ set");
+;
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_trap_get_list)
+{
+ int ret;
+ libspid_eoc_trap_entry_t entries[18];
+ int idx;
+ unsigned int ip_count = 18;
+
+ /* Expected results */
+ char ip_addr[TRAP_ENTRY_NUM][LIBSPID_IP_STR_MAX_LEN] =
+ { "172.21.16.22", "172.21.16.121",
+ "192.168.121.121", "172.21.6.1"
+ };
+
+ char status[TRAP_ENTRY_NUM][2] = { "0", "1", "0", "1" };
+
+ char communities[TRAP_ENTRY_NUM][16] =
+ { "public", "mstar", "public", "public" };
+
+ memset (entries, 0,
+ TRAP_ENTRY_NUM * sizeof (libspid_eoc_trap_entry_t));
+
+ system ("cp " TRAP_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_trap_get_list (0, &ip_count);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, for param 1 error");
+
+ ret = libspid_eoc_trap_get_list (entries, 0);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, for param 2 error");
+
+ ip_count = LIBSPID_EOC_TRAP_SERVER_MAX + 1;
+ ret = libspid_eoc_trap_get_list (entries, &ip_count);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, for param 2 error");
+
+ ip_count = 0;
+ ret = libspid_eoc_trap_get_list (entries, &ip_count);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, for param 2 error");
+
+ ip_count = 18;
+ ret = libspid_eoc_trap_get_list (entries, &ip_count);
+ fail_if (ip_count != TRAP_ENTRY_NUM,
+ "libspid_eoc_trap_get_list returns wrong count");
+
+ for (idx = 0; idx < TRAP_ENTRY_NUM; idx++)
+ {
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_trap_get_list return is unsuccessful");
+ fail_if (strcmp (entries[idx].ip_address, ip_addr[idx]) != 0,
+ "libspid_eoc_trap_get_list corrupts ip address");
+ fail_if (strcmp (entries[idx].status, status[idx]) != 0,
+ "libspid_eoc_trap_get_list gets wrong status");
+ fail_if (strcmp (entries[idx].community, communities[idx]) != 0,
+ "libspid_eoc_trap_get_list gets wrong community");
+ }
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_trap_remove)
+{
+ char ip_addr[16];
+ libspid_eoc_trap_entry_t entriy;
+ int ret;
+
+ system ("cp " TRAP_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_trap_remove (0);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, for param 1 error");
+
+ strcpy (ip_addr, "192.167.43.32");
+ ret = libspid_eoc_trap_remove (ip_addr);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, the ip not found");
+
+ strcpy (ip_addr, "172.21.16.22");
+
+ ret = libspid_eoc_trap_get (ip_addr, &entriy);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = libspid_eoc_trap_remove (ip_addr);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = libspid_eoc_trap_get (ip_addr, &entriy);
+ fail_if (ret == LIBSPID_SUCCESS, "must fail, the ip not found");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_trap_flush)
+{
+ int ret;
+ libspid_eoc_trap_entry_t entries[18];
+ unsigned int ip_count = 18;
+
+ system ("cp " TRAP_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_trap_get_list (entries, &ip_count);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+ fail_if (4 != ip_count, "must fount ip count is 4");
+
+ ret = libspid_eoc_trap_flush ();
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = libspid_eoc_trap_get_list (entries, &ip_count);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+ fail_if (0 != ip_count, "must get list num is zero after flush");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_trap_check)
+{
+ int ret;
+ system ("cp -rf " TRAP_CONF " " LIBSPID_TRAP_CONF_PATH);
+ ret = libspid_eoc_trap_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ system ("cp -rf " TRAP_DU_IP_CONF " " LIBSPID_TRAP_CONF_PATH);
+ ret = libspid_eoc_trap_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of double ip");
+
+ system ("cp -rf " TRAP_EN_ERROR_CONF " " LIBSPID_TRAP_CONF_PATH);
+ ret = libspid_eoc_trap_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of en error");
+
+ system ("cp -rf " TRAP_IP_ERROR_CONF " " LIBSPID_TRAP_CONF_PATH);
+ ret = libspid_eoc_trap_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of ip error");
+
+ system ("cp -rf " TRAP_NULL_COMMUNITY_CONF " "
+ LIBSPID_TRAP_CONF_PATH);
+ ret = libspid_eoc_trap_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of null community");
+
+ system ("cp -rf " TRAP_COMMUNITY_LONG_CONF " "
+ LIBSPID_TRAP_CONF_PATH);
+ ret = libspid_eoc_trap_check ();
+ fail_if (LIBSPID_SUCCESS == ret,
+ "must fail, because of community too long");
+
+}
+END_TEST
+
+TCase * tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ return tc_param;
+}
+
+extern Suite *
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_trap_set);
+ tcase_add_test (tc_core, test_libspid_eoc_trap_get);
+ tcase_add_test (tc_core, test_libspid_eoc_trap_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_trap_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_trap_flush);
+ tcase_add_test (tc_core, test_libspid_eoc_trap_check);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/upgrade_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/upgrade_eoc_utests.c
new file mode 100644
index 0000000000..2cef19dc1b
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/upgrade_eoc_utests.c
@@ -0,0 +1,218 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define LOCAL_IMAGE_FILE "testfiles/firmware.img"
+#define IMAGE_FILE "firmware.img"
+
+/** local variables */
+typedef char mac_t[6];
+typedef char mac_string_t[18];
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char mac_address;
+ char file [20];
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_upgrade_remote_image (NULL, file);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* mac_address_count = NULL */
+ ret = libspid_eoc_upgrade_remote_image (&mac_address, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "file = NULL");
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_tftp_upgrade_remote_image (NULL, file);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* mac_address_count = NULL */
+ ret = libspid_eoc_tftp_upgrade_remote_image (&mac_address, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "file = NULL");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_upgrade_remote_image)
+{
+ int exp_ret[10] = { LIBSPID_SUCCESS, LIBSPID_ERROR_SYSTEM,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_ERROR_SYSTEM,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_SUCCESS,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_SUCCESS,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_ERROR_SYSTEM };
+ int ret, i;
+ char mac_addr[10][LIBSPID_MAC_STR_LEN] = {
+ "00:11:22:33:44:55", "00:11:22:33:44:66", "00:11:22:33:44:77",
+ "00:11:22:33:44:88", "00:11:22:33:44:99", "00:11:22:33:44:aa",
+ "00:11:22:33:44:bb", "00:11:22:33:44:cc", "00:11:22:33:44:dd",
+ "00:11:22:33:44:ee"
+ };
+ char file[] = UTESTS_TMP_DIR "/" IMAGE_FILE;
+
+ system ("cp " LOCAL_IMAGE_FILE " " UTESTS_TMP_DIR);
+
+ for (i = 0; i < 10; i++) {
+ ret = libspid_eoc_upgrade_remote_image (mac_addr[i], file);
+ fail_if (ret != exp_ret[i], "libspid_eoc_upgrade_image return "
+ "is unsuccessful");
+ }
+
+ strcpy (file, "/tmp/false.img");
+ ret = libspid_eoc_upgrade_remote_image (mac_addr[9], file);
+ fail_if (ret != LIBSPID_ERROR_PARAM, "libspid_eoc_upgrade_image "
+ "operates with false image");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_tftp_upgrade_remote_image)
+{
+ int ret, i;
+ int exp_ret[10] = { LIBSPID_SUCCESS, LIBSPID_ERROR_SYSTEM,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_ERROR_SYSTEM,
+ LIBSPID_ERROR_SYSTEM, LIBSPID_SUCCESS,
+ LIBSPID_SUCCESS, LIBSPID_SUCCESS,
+ LIBSPID_SUCCESS, LIBSPID_ERROR_PARAM
+ };
+ char mac_addr[10][LIBSPID_MAC_STR_LEN] = {
+ "00:11:22:33:44:55", "00:11:22:33:44:66", "00:11:22:33:44:77",
+ "00:11:22:33:44:88", "00:11:22:33:44:99", "00:11:22:33:44:aa",
+ "00:11:22:33:44:bb", "00:11:22:33:44:cc", "00:11:22:33:44:dd",
+ "00:11:22:33:44:ee"
+ };
+
+ char file[] = UTESTS_TMP_DIR "/" IMAGE_FILE;
+ system ("cp " LOCAL_IMAGE_FILE " " UTESTS_TMP_DIR);
+
+ for (i = 0; i < 9; i++) {
+ ret = libspid_eoc_tftp_upgrade_remote_image (mac_addr[i], file);
+ fail_if (ret != exp_ret[i], "libspid_eoc_tftp_upgrade_remote_image "
+ "return is unsuccessful");
+ }
+
+ strcpy (file, "/tmp/false.img");
+ ret = libspid_eoc_tftp_upgrade_remote_image (mac_addr[9], file);
+ fail_if (ret != exp_ret[9], "libspid_eoc_tftp_upgrade_remote_image "
+ "operates with false image");
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+extern Suite*
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_upgrade_remote_image);
+ tcase_add_test (tc_core, test_libspid_eoc_tftp_upgrade_remote_image);
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/utest_launcher.c b/cleopatre/devkit/tests/libspid/utests/src/utest_launcher.c
new file mode 100644
index 0000000000..2c6f8c2bfc
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/utest_launcher.c
@@ -0,0 +1,30 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/libspid/utests/src/utest_launcher.c
+ * \ingroup devkit_tests_libspid_utests
+ */
+#include "inc/utest_launcher.h"
+#include <check.h>
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ s = utest_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_run_all (sr, CK_NORMAL);
+ srunner_set_fork_status (sr, CK_FORK);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc.c b/cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc.c
new file mode 100644
index 0000000000..5be9405bb7
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc.c
@@ -0,0 +1,223 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc.c
+ * \ingroup devkit_tests_libspid_utests
+ *
+ *
+ * A = utest_tonemap_snr_eoc.c
+ * B = tonemap_snr_eoc.c (target)
+ * C = utest_tonemap_snr_eoc_cap.c
+ *
+ * ----- ----- -----
+ * | A | <-> | B | <-> | C |
+ * ----- ----- -----
+ *
+ * Data checked are the output of B,
+ * And so, It's done in A and C files.
+ *
+ * Inputs of B are defined by 'utest_sequence_t'
+ */
+
+#include <check.h>
+#include "libspid.h"
+#include "inc/utest_tonemap_snr_eoc.h"
+
+static const utest_sequence_t snr_basic[] = {
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0x00, 0x00, 0x05},
+ .sizeof_req = 9,
+ .cnf.snr = {
+ .result = 0,
+ .int_id = 0,
+ .int_length = 1,
+ .int_et = 537,
+ .tm_ber = 789,
+ .carrier_group = 5,
+ .snr_list = 198 }},
+};
+
+static const utest_sequence_t snr_interval[] = {
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0x00, 0x00, 0x05},
+ .sizeof_req = 9,
+ .cnf.snr = {
+ .result = 2,
+ .int_id = 3 }},
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0x00, 0x03, 0x05},
+ .sizeof_req = 9,
+ .cnf.snr = {
+ .result = 0,
+ .int_id = 3,
+ .int_length = 1,
+ .int_et = 537,
+ .tm_ber = 789,
+ .carrier_group = 5,
+ .snr_list = 198 }},
+};
+
+static const utest_sequence_t tonemap_basic[] = {
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0xff, 0x00, 0x00},
+ .sizeof_req = 9,
+ .cnf.tonemap = {
+ .result = 0,
+ .int_id = 0x23 }},
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0x04, 0x23, 0x00},
+ .sizeof_req = 9,
+ .cnf.tonemap = {
+ .result = 0,
+ .int_id = 0x23,
+ .tmi_default = 3,
+ .tmi_length = 1,
+ .tmi_data = 67,
+ .int_length = 1,
+ .int_et = 633,
+ .int_tmi = 56,
+ .tmi = 3,
+ .tm_fec = 7,
+ .tm_gi = 5,
+ .modulation_list = 31 }},
+};
+
+static const utest_sequence_t snr_error[] = {
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0x00, 0x00, 0x05},
+ .sizeof_req = 9,
+ .cnf.snr = {
+ .result = 1,
+ .int_id = 0 }},
+};
+
+static const utest_sequence_t snr_transition[] = {
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0x00, 0x00, 0x05},
+ .sizeof_req = 9,
+ .cnf.snr = {
+ .result = 2,
+ .int_id = 4 }},
+ {
+ .req = {FAKE_MAC_ADDR2_BIN, 0x00, 0x04, 0x05},
+ .sizeof_req = 9,
+ .cnf.snr = {
+ .result = 2,
+ .int_id = 5 }},
+};
+
+static const utest_list_t utest_snr_list[] = {
+ ADD_TEST (snr_basic, LIBSPID_SUCCESS),
+ ADD_TEST (snr_interval, LIBSPID_SUCCESS),
+ ADD_TEST (snr_error, LIBSPID_ERROR_GEN),
+ ADD_TEST (snr_transition, LIBSPID_ERROR_GEN),
+};
+
+static const utest_list_t utest_tonemap_list[] = {
+ ADD_TEST (tonemap_basic, LIBSPID_SUCCESS),
+};
+
+START_TEST (utest_libspid_eoc_get_tonemap)
+{
+ libspid_error_t r;
+ libspid_eoc_tonemap_entry_t tonemap;
+ unsigned char direction = 0;
+ char mac_address[LIBSPID_MAC_STR_LEN] = FAKE_MAC_ADDR2;
+
+ utest_set_values_expected (
+ utest_tonemap_list[_i].seq,
+ utest_tonemap_list[_i].nb_sequence);
+
+ r = libspid_eoc_get_tonemap (
+ mac_address, direction, &tonemap);
+
+ fail_if (r != utest_tonemap_list[_i].libspid);
+ if (utest_tonemap_list[_i].libspid == LIBSPID_SUCCESS)
+ {
+ const pattern_tonemap_t *tm;
+ int i, last;
+
+ /* Check output build with the pattern. */
+ last = utest_tonemap_list[_i].nb_sequence - 1;
+ tm = &utest_tonemap_list[_i].seq[last].cnf.tonemap;
+
+ fail_if (tonemap.int_id != tm->int_id);
+ fail_if (tonemap.tmi_default != tm->tmi_default);
+ fail_if (tonemap.tmi_length != tm->tmi_length);
+ for (i = 0; i < tm->tmi_length; i++)
+ fail_if (tonemap.tmi_data[i] != tm->tmi_data);
+ fail_if (tonemap.int_length != tm->int_length);
+ for (i = 0; i < tm->int_length; i++)
+ {
+ fail_if (tonemap.int_et[i] != tm->int_et);
+ fail_if (tonemap.int_tmi[i] != tm->int_tmi);
+ }
+ fail_if (tonemap.tmi != tm->tmi);
+ fail_if (tonemap.tm_fec != tm->tm_fec);
+ fail_if (tonemap.tm_gi != tm->tm_gi);
+ for (i = 0; i < LIBSPID_EOC_MODULATION_LIST_MAX_SIZE; i++)
+ fail_if (tonemap.modulation_list[i]
+ != tm->modulation_list);
+ }
+}
+END_TEST
+
+START_TEST (utest_libspid_eoc_get_snr)
+{
+ char mac_address[LIBSPID_MAC_STR_LEN] = FAKE_MAC_ADDR2;
+ libspid_eoc_snr_entry_t output_snr;
+ libspid_error_t r;
+
+ utest_set_values_expected (
+ utest_snr_list[_i].seq,
+ utest_snr_list[_i].nb_sequence);
+
+ r = libspid_eoc_get_snr (
+ mac_address, 5, &output_snr);
+
+ fail_if (r != utest_snr_list[_i].libspid);
+ if (utest_snr_list[_i].libspid == LIBSPID_SUCCESS)
+ {
+ const pattern_snr_t *snr;
+ int i, last;
+
+ /* Check output build with the pattern. */
+ last = utest_snr_list[_i].nb_sequence - 1;
+ snr = &utest_snr_list[_i].seq[last].cnf.snr;
+
+ fail_if (output_snr.int_id != snr->int_id);
+ fail_if (output_snr.int_length != snr->int_length);
+ for (i = 0; i < snr->int_length; i++)
+ fail_if (output_snr.int_et[i] != snr->int_et);
+ fail_if (output_snr.tm_ber != snr->tm_ber);
+ fail_if (output_snr.carrier_group != snr->carrier_group);
+ for (i = 0; i < LIBSPID_EOC_SNR_LIST_MAX_SIZE; i++)
+ {
+ unsigned char val = snr->snr_list + i;
+ fail_if (output_snr.snr_list[i] != val);
+ }
+ }
+}
+END_TEST
+
+Suite *
+utest_suite (void)
+{
+ Suite *s = suite_create ("utest - tonemap_snr_eoc.c");
+ TCase *tcase = tcase_create ("Core");
+
+ tcase_add_loop_test (
+ tcase, utest_libspid_eoc_get_snr,
+ 0, ARRAY_LENGTH (utest_snr_list));
+ tcase_add_loop_test (
+ tcase, utest_libspid_eoc_get_tonemap,
+ 0, ARRAY_LENGTH (utest_tonemap_list));
+
+ suite_add_tcase (s, tcase);
+ return s;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc_cap.c b/cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc_cap.c
new file mode 100644
index 0000000000..cc33c66ebf
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc_cap.c
@@ -0,0 +1,304 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2013 MStar Semiconductor
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file devkit/tests/libspid/utests/src/utest_tonemap_snr_eoc_cap.c
+ * \ingroup devkit_tests_libspid_utests
+ */
+
+#include <assert.h>
+#include <check.h>
+#include "libspid.h"
+#include "libmme.h"
+#include "inc/utest_tonemap_snr_eoc.h"
+
+static const utest_sequence_t *cur_utest;
+static int max_sequence;
+static int cur_sequence;
+
+typedef union {
+ char byte;
+ short word;
+ long dword;
+} auto_cast;
+
+void
+utest_set_values_expected (
+ const utest_sequence_t *utest,
+ const int max)
+{
+ assert (utest);
+
+ cur_utest = utest;
+ max_sequence = max;
+ cur_sequence = 0;
+}
+
+static void
+utest_common_stub (
+ auto_cast *in, auto_cast *out, unsigned int length)
+{
+ unsigned int i;
+
+ if (length == 1)
+ out->byte = in->byte;
+ else if (length == 2)
+ out->word = in->word;
+ else if (length == 4)
+ out->dword = in->dword;
+ else if (length > 4)
+ for (i=0; i<length; i++)
+ (&out->byte)[i] = (&in->byte)[i];
+}
+
+static void
+utest_check_mme_req (mme_ctx_t *req)
+{
+ assert (req);
+ const char *bin = cur_utest[cur_sequence].req;
+ int size = cur_utest[cur_sequence].sizeof_req;
+
+ fail_if (memcmp (req->buffer, bin, size));
+}
+
+static void
+utest_build_mme_cnf (
+ mme_ctx_t *req, mme_ctx_t *cnf)
+{
+ int i, index = 0;
+ auto_cast *ptr;
+
+ assert (req);
+ assert (cnf);
+ assert (cnf->buffer);
+
+ /* Build the CNF buffer. */
+ cnf->oui = MME_OUI_SPIDCOM;
+ const pattern_snr_t *snr =
+ &cur_utest[cur_sequence].cnf.snr;
+ const pattern_tonemap_t *tonemap =
+ &cur_utest[cur_sequence].cnf.tonemap;
+ switch (req->mmtype)
+ {
+ case VS_GET_SNR_REQ:
+ assert (snr);
+ cnf->mmtype = VS_GET_SNR_CNF;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = snr->result;
+ index ++;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = snr->int_id;
+ index ++;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = snr->int_length;
+ index ++;
+
+ for (i=0; i < snr->int_length; i++)
+ {
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->word = snr->int_et;
+ index += 2;
+ }
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->word = snr->tm_ber;
+ index += 2;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = snr->carrier_group;
+ index ++;
+
+ for (i = 0; i < LIBSPID_EOC_SNR_LIST_MAX_SIZE; i++)
+ {
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = snr->snr_list + i;
+ index ++;
+ }
+ break;
+
+ case VS_GET_TONEMAP_REQ:
+ assert (tonemap);
+ cnf->mmtype = VS_GET_TONEMAP_CNF;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->result;
+ index ++;
+
+ /* Current tonemap interval list identifier */
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->dword = 0xDEADDEAD;
+ index += 4;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->int_id;
+ index ++;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->tmi_default;
+ index ++;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->tmi_length;
+ index ++;
+
+ for (i = 0; i < tonemap->tmi_length; i++)
+ {
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->tmi_data;
+ index ++;
+ }
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->int_length;
+ index ++;
+
+ for (i = 0; i < tonemap->int_length; i++)
+ {
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->word = tonemap->int_et;
+ index += 2;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->int_tmi;
+ index ++;
+ }
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->tmi;
+ index ++;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->tm_fec;
+ index ++;
+
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->tm_gi;
+ index ++;
+
+ for (i = 0; i < LIBSPID_EOC_MODULATION_LIST_MAX_SIZE; i++)
+ {
+ ptr = (auto_cast *)(cnf->buffer + index);
+ ptr->byte = tonemap->modulation_list;
+ index ++;
+ }
+ break;
+ };
+
+ cnf->tail = index;
+}
+
+mme_error_t
+mme_pull (
+ mme_ctx_t *ctx, void *data, unsigned int length,
+ unsigned int *result_length)
+{
+ assert (ctx);
+ assert (ctx->buffer);
+ assert (data);
+ assert (result_length);
+ assert (ctx->head + length < ctx->length);
+ assert (ctx->head + length <= ctx->tail);
+
+ auto_cast *out = data;
+ auto_cast *in = (auto_cast *)(ctx->buffer + ctx->head);
+
+ utest_common_stub (in, out, length);
+ ctx->head += length;
+
+ return MME_SUCCESS;
+}
+
+mme_error_t
+mme_send (
+ mme_ctx_t *ctx, mme_send_type_t type, char *iface,
+ unsigned char *dest, mme_ctx_t *confirm_ctx)
+{
+ assert (iface == NULL);
+ assert (dest);
+ assert (cur_sequence < max_sequence);
+
+ utest_check_mme_req (ctx);
+ utest_build_mme_cnf (ctx, confirm_ctx);
+ cur_sequence ++;
+ return MME_SUCCESS;
+}
+
+mme_error_t
+mme_put (
+ mme_ctx_t *ctx, const void *data, unsigned int length,
+ unsigned int *result_length)
+{
+ assert (ctx);
+ assert (data);
+ assert (result_length);
+
+ auto_cast *in = (auto_cast *)data;
+ auto_cast *out = (auto_cast *)(ctx->buffer + ctx->head);
+
+ utest_common_stub (in, out, length);
+ ctx->head += length;
+
+ return MME_SUCCESS;
+}
+
+mme_error_t
+mme_init (
+ mme_ctx_t *ctx, const mmtype_t mmtype,
+ unsigned char *buffer, const unsigned int length)
+{
+ assert (ctx);
+ assert (buffer);
+ assert (length);
+
+ memset (ctx, 0, sizeof (mme_ctx_t));
+ ctx->mmtype = mmtype;
+ ctx->length = length;
+ ctx->buffer = buffer;
+ /* Initialize all the buffer to check memory corruption
+ * with Valgrind. */
+ memset (buffer, 0xFF, length);
+
+ return MME_SUCCESS;
+}
+
+libspid_error_t
+libspid_mac_str_to_bin (
+ const char *str, unsigned char *bin)
+{
+ assert (str);
+ assert (bin);
+
+ const char mac1[LIBSPID_MAC_BIN_LEN] = {
+ FAKE_MAC_ADDR1_BIN };
+ const char mac2[LIBSPID_MAC_BIN_LEN] = {
+ FAKE_MAC_ADDR2_BIN };
+
+ if (!strcmp (str, FAKE_MAC_ADDR1))
+ memcpy (bin, mac1, LIBSPID_MAC_BIN_LEN);
+ else if (!strcmp (str, FAKE_MAC_ADDR2))
+ memcpy (bin, mac2, LIBSPID_MAC_BIN_LEN);
+ else
+ return LIBSPID_ERROR_GEN;
+
+ return LIBSPID_SUCCESS;
+}
+
+libspid_error_t
+libspid_network_get_mac (
+ const char *interface, unsigned char *mac)
+{
+ assert (interface);
+ assert (mac);
+
+ fail_if (strcmp (interface, LIBSPID_EOC_PLC_IFACE));
+ strcpy ((char *)mac, FAKE_MAC_ADDR1);
+
+ return LIBSPID_SUCCESS;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/util_utests.c b/cleopatre/devkit/tests/libspid/utests/src/util_utests.c
new file mode 100644
index 0000000000..6c648a350d
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/util_utests.c
@@ -0,0 +1,266 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2012 MStar
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file util_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+#include "libspid.h"
+
+char buffer[1024];
+
+static void
+setup (void)
+{
+ memset (buffer, 0 , sizeof (buffer));
+}
+void
+
+teardown (void)
+{
+}
+
+void test_show (char *str)
+{
+ if (NULL == str)return;
+
+ strcat (buffer, str);
+ return;
+}
+
+
+START_TEST (test_libspid_ptable_init_uninit)
+{
+ int ret;
+ print_table_t table;
+ ret = libspid_ptable_init (0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, param is zero");
+
+ table.col = 0;
+ table.row = 2;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, col is 0");
+
+ table.col = LIBSPID_PTABLE_COL_MAX + 1;
+ table.row = 2;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, col is bigger than max");
+
+ table.col = 2;
+ table.row = 0;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, row is 0");
+
+ table.col = 2;
+ table.row = LIBSPID_PTABLE_ROW_MAX + 1;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, row is bigger than max");
+
+ table.col = 2;
+ table.row = 5;
+ table.print_callback = 0;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, print callback is 0");
+
+ table.col = LIBSPID_PTABLE_COL_MIN;
+ table.row = LIBSPID_PTABLE_ROW_MIN;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+
+ ret = libspid_ptable_uninit (0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because prarm error");
+
+ ret = libspid_ptable_uninit (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ table.col = LIBSPID_PTABLE_COL_MAX;
+ table.row = LIBSPID_PTABLE_ROW_MAX;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_uninit (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_uninit (&table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, the table hase been uninit");
+
+}
+END_TEST
+
+START_TEST (test_libspid_ptable_init_add)
+{
+ int ret;
+ print_table_t table;
+
+ ret = libspid_ptable_add (table, 2, 3, "menu");
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, table not init");
+
+ table.col = 5;
+ table.row = 5;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 6, 4, "menu");
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, row is error");
+
+ ret = libspid_ptable_add (table, 4, 6, "menu");
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, col is error");
+
+ ret = libspid_ptable_add (table, 4, 6, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, string is null");
+
+ ret = libspid_ptable_add (table, 4, 4, "menu");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_uninit (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+}
+END_TEST
+
+
+START_TEST (test_libspid_ptable_init_show)
+{
+ int ret;
+ print_table_t table;
+ char *tmp="menu1 menu2 menu3 menu4 menu4 \n"
+ "0 - 2 3 4 \n"
+ "abcdefg hijk lmn opq rst \n";
+
+ ret = libspid_ptable_show (table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, table not init");
+
+ table.col = 5;
+ table.row = 5;
+ table.print_callback = test_show;
+ ret = libspid_ptable_init (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ memset (buffer, 0, sizeof (buffer));
+
+ ret = libspid_ptable_add (table, 0, 0, "menu1");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 0, 1, "menu2");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 0, 2, "menu3");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 0, 3, "menu4");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 0, 4, "menu4");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 1, 0, "0");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 1, 2, "2");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 1, 3, "3");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 1, 4, "4");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 2, 0, "abcdefg");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 2, 1, "hijk");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 2, 2, "lmn");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 2, 3, "opq");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_add (table, 2, 4, "rst");
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_show (table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = strcmp (buffer, tmp);
+ fail_if (0 != ret, "must equ");
+
+ ret = libspid_ptable_uninit (&table);
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+ ret = libspid_ptable_show (table);
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of table uninit");
+
+}
+END_TEST
+
+
+Suite * libspid_eoc_suite ()
+{
+ Suite * s = suite_create ("LIBSPID_EOC");
+ TCase * tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_ptable_init_uninit);
+ tcase_add_test (tc_core, test_libspid_ptable_init_add);
+ tcase_add_test (tc_core, test_libspid_ptable_init_show);
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite * s;
+
+ //Run EoC tests
+ s = libspid_eoc_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;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/vlan_port_utests.c b/cleopatre/devkit/tests/libspid/utests/src/vlan_port_utests.c
new file mode 100644
index 0000000000..ad5d2d78df
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/vlan_port_utests.c
@@ -0,0 +1,362 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2012 MStar
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file vlan_port_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+
+#include "eoc_utests.h"
+#include "libspid.h"
+
+/* local constants */
+#define TEST_VLAN_PORT_CONF "testfiles/vlanport.conf"
+#define ETC_VLAN_PORT_CONF "/etc/vlanport.conf"
+#define VLAN_PORT_NO_VLANID "testfiles/vlanport_no_vlanid.conf"
+#define VLAN_PORT_LINE2 "testfiles/vlan_port_line2.conf"
+#define VLAN_PORT_LINE7 "testfiles/vlan_port_line7.conf"
+#define VLAN_PORT_ERROR1 "testfiles/vlan_port_error1.conf"
+#define VLAN_PORT_ERROR2 "testfiles/vlan_port_error2.conf"
+#define VLAN_PORT_ERROR3 "testfiles/vlan_port_error3.conf"
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define VLAN_CONF "testfiles/vlan_table.conf"
+
+
+
+void
+test_create_test_file_2 ()
+{
+ system ("cp " VLAN_PORT_LINE2 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+}
+
+void
+test_create_test_file_7 ()
+{
+ system ("cp " VLAN_PORT_LINE7 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+}
+
+void
+table_print (libspid_eoc_vlan_port_table_entry_t * entry)
+{
+ fprintf (stderr, "%s %s %s %s %s %s\r\n",
+ entry->vlan_port_mac,
+ entry->vlan_port_index,
+ entry->vlan_port_pvid,
+ entry->vlan_port_tpid,
+ entry->vlan_port_prio, entry->vlan_port_mode);
+}
+
+static void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+START_TEST (test_libspid_eoc_vlan_port_get)
+{
+ int ret;
+ char index[2];
+ char mac[LIBSPID_MAC_STR_LEN];
+ libspid_eoc_vlan_port_table_entry_t entry;
+
+ strcpy (index, "1");
+
+ ret = libspid_eoc_vlan_port_get (0, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "param 1 is 0,but return suc");
+
+ strcpy (mac, "00:13:d7:00:00:01");
+ ret = libspid_eoc_vlan_port_get (mac, 0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "param 2 is 0,but return suc");
+
+ ret = libspid_eoc_vlan_port_get (mac, index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "param 3 is 0,but return suc");
+ test_create_test_file_7 ();
+ strcpy (mac, "00:13:d7:00:00:01");
+
+ strcpy (index, "3");
+ ret = libspid_eoc_vlan_port_get (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must get it,but not");
+ fail_if (3 != atoi (entry.vlan_port_index), "Get the port index error");
+ fail_if (2 != atoi (entry.vlan_port_pvid), "Get the port pvid error");
+ fail_if (1 != atoi (entry.vlan_port_tpid), "Get the port tvid error");
+ fail_if (2 != atoi (entry.vlan_port_prio), "Get the port prio error");
+ fail_if (1 != atoi (entry.vlan_port_mode), "Get the port mode error");
+
+ strcpy (mac, "00:13:d7:44:00:10");
+ strcpy (index, "3");
+ ret = libspid_eoc_vlan_port_get (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "vaild mac ,but return suc");
+
+ strcpy (mac, "00:13:d7:00:00:02");
+ strcpy (index, "4");
+ ret = libspid_eoc_vlan_port_get (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "vaild index ,but return suc");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_vlan_port_get_list)
+{
+ int ret;
+ int cnt = LIBSPID_PORT_TOTAL_MAX;
+ static libspid_eoc_vlan_port_table_entry_t entry[LIBSPID_PORT_TOTAL_MAX];
+ ret = libspid_eoc_vlan_port_get_list (0, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "param 1 is 0,but return suc");
+
+ ret = libspid_eoc_vlan_port_get_list (entry, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "param 2 is 0,but return suc");
+
+ test_create_test_file_2 ();
+ ret = libspid_eoc_vlan_port_get_list (entry, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "Get List must suc,but fail");
+ fail_if (2 != cnt, "There are two entries in file,but return cnt is "
+ "error");
+
+ test_create_test_file_7 ();
+ ret = libspid_eoc_vlan_port_get_list (entry, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "Get List must suc,but fail");
+ fail_if (7 != cnt, "There are seven entries in file,but return cnt is"
+ " error");
+ ret = strcasecmp (entry[5].vlan_port_mac, "00:13:d7:00:00:02");
+ fail_if (0 != ret, "Get the mac error");
+ fail_if (0 != atoi (entry[5].vlan_port_index),
+ "Get the port index error");
+ fail_if (2 != atoi (entry[5].vlan_port_pvid),
+ "Get the port pvid error");
+ fail_if (3 != atoi (entry[5].vlan_port_tpid),
+ "Get the port tvid error");
+ fail_if (2 != atoi (entry[5].vlan_port_prio),
+ "Get the port prio error");
+ fail_if (1 != atoi (entry[5].vlan_port_mode),
+ "Get the port mode error");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_vlan_port_set)
+{
+ int ret;
+ char mac[LIBSPID_MAC_STR_LEN];
+ char index[2];
+
+ strcpy (index, "2");
+ strcpy (mac, "00:13:D7:00:00:20");
+
+ libspid_eoc_vlan_port_table_entry_t entry, temp_entry;
+
+ memset (&entry , 0x0, sizeof (libspid_eoc_vlan_port_table_entry_t));
+ memset (&temp_entry , 0x0, sizeof (libspid_eoc_vlan_port_table_entry_t));
+
+ ret = libspid_eoc_vlan_port_set (0, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "param 1 is zero,but return suc");
+
+ ret = libspid_eoc_vlan_port_set (mac, 0, &entry);
+ fail_if (LIBSPID_SUCCESS == ret, "param 2 is zero,but return suc");
+
+ ret = libspid_eoc_vlan_port_set (mac, index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "param 3 is zero,but return suc");
+
+ test_create_test_file_7 ();
+
+ strcpy (mac, "00:13:D7:00:00:02");
+ strcpy (index, "1");
+
+ strcpy (entry.vlan_port_pvid, "10");
+ strcpy (entry.vlan_port_tpid, "11");
+ strcpy (entry.vlan_port_prio, "2");
+ strcpy (entry.vlan_port_mode, "99");
+
+ ret = libspid_eoc_vlan_port_set (mac, index, &entry);
+
+ fail_if (LIBSPID_SUCCESS != ret, "must set suc");
+
+ ret = libspid_eoc_vlan_port_get (mac, index, &temp_entry);
+ fail_if (LIBSPID_SUCCESS != ret, "must get suc");
+
+ ret = strcasecmp (mac, temp_entry.vlan_port_mac);
+ fail_if (0 != ret, "mac not right");
+
+ ret = strcasecmp (index, temp_entry.vlan_port_index);
+ fail_if (0 != ret, "index not right");
+
+ ret = strcasecmp (entry.vlan_port_pvid, temp_entry.vlan_port_pvid);
+ fail_if (0 != ret, "vlan_port_pvid not right");
+
+ ret = strcasecmp (entry.vlan_port_tpid, temp_entry.vlan_port_tpid);
+ fail_if (0 != ret, "vlan_port_tpid not right");
+
+ ret = strcasecmp (entry.vlan_port_prio, temp_entry.vlan_port_prio);
+ fail_if (0 != ret, "vlan_port_prio not right");
+
+ ret = strcasecmp (entry.vlan_port_mode, temp_entry.vlan_port_mode);
+ fail_if (0 != ret, "vlan_port_mode not right");
+ strcpy(mac, "00:13:D7:00:00:20");
+ strcpy (index, "1");
+
+ strcpy (entry.vlan_port_pvid, "10");
+ strcpy (entry.vlan_port_tpid, "11");
+ strcpy (entry.vlan_port_prio, "2");
+ strcpy (entry.vlan_port_mode, "99");
+ ret = libspid_eoc_vlan_port_set (mac, index, &entry);
+ fail_if (LIBSPID_SUCCESS == ret,
+ "mac doesn't exist but function return successfu");
+}
+END_TEST
+
+void
+test_create_port_check_test_file_ok_1 ()
+{
+ system ("cp " TEST_VLAN_PORT_CONF " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+
+}
+
+void
+test_create_port_check_test_file_no_vlanid ()
+{
+ system ("cp " VLAN_PORT_NO_VLANID " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+
+}
+
+void
+test_create_port_check_test_file_error_1 ()
+{
+ system ("cp " VLAN_PORT_ERROR1 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+}
+
+void
+test_create_port_check_test_file_error_2 ()
+{
+ system ("cp " VLAN_PORT_ERROR2 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+}
+
+void
+test_create_port_check_test_file_error_3 ()
+{
+ system ("cp " VLAN_PORT_ERROR3 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+}
+
+START_TEST (test_libspid_eoc_vlan_port_check)
+{
+ int ret;
+ test_create_port_check_test_file_ok_1 ();
+ ret = libspid_eoc_vlan_port_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must right");
+
+ test_create_port_check_test_file_no_vlanid ();
+ ret = libspid_eoc_vlan_port_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must error,no vlanid");
+
+ test_create_port_check_test_file_error_1 ();
+ ret = libspid_eoc_vlan_port_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must error");
+
+ test_create_port_check_test_file_error_2 ();
+ ret = libspid_eoc_vlan_port_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must error");
+
+ test_create_port_check_test_file_error_3 ();
+ ret = libspid_eoc_vlan_port_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must error");
+}
+END_TEST
+
+Suite * libspid_eoc_suite ()
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_port_get);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_port_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_port_set);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_port_check);
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+ return (number_failed == 0) ? 0 : -1;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/vlan_utests.c b/cleopatre/devkit/tests/libspid/utests/src/vlan_utests.c
new file mode 100644
index 0000000000..b7ff033773
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/vlan_utests.c
@@ -0,0 +1,346 @@
+/*
+*Cleopatre project {{{
+* Copyright (C) 2012 MStar
+* <<<Licence>>>
+* }}}
+*/
+
+/**
+* \file vlan_utests.c
+* \brief Unitary tests for libspid
+* \ingroup Cleopatre - libspid
+*
+* This file content all the unitary tests for EoC SPiDLib.
+*/
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename() */
+#include <string.h>
+#include "eoc_utests.h"
+#include "libspid.h"
+
+#define SYSTEM_CONF "testfiles/system.conf"
+#define SYSTEM_NO_VLAN_NUM_CONF "testfiles/system_no_vlan_num.conf"
+#define VLAN_CONF "testfiles/vlan_table.conf"
+#define VLAN_DU_ID_CONF "testfiles/vlan_table_du_id.conf"
+#define VLAN_ID_0_CONF "testfiles/vlan_table_id_0.conf"
+#define VLAN_ID_4096_CONF "testfiles/vlan_table_id_4096.conf"
+#define VLAN_VALUE_ERROR_CONF "testfiles/vlan_table_value_error.conf"
+
+
+void
+test_create_test_file ()
+{
+ system ("rm -f " LIBSPID_VLAN_TABLE_CONF_PATH );
+ system ("cp " VLAN_CONF " " LIBSPID_VLAN_TABLE_CONF_PATH);
+}
+
+void
+test_create_sys_cfg ()
+{
+ system ("rm -f " LIBSPID_SYSTEM_CONF_PATH);
+ system ("cp " SYSTEM_CONF " " UTESTS_TMP_DIR "/etc");
+}
+
+static void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+/* initialize - delete testing dir if it exists */
+ if ((stat (UTESTS_TMP_DIR, &st) == 0))
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir(UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ test_create_test_file ();
+ test_create_sys_cfg ();
+
+}
+
+
+
+void
+teardown (void)
+{
+
+}
+
+START_TEST (test_libspid_eoc_vlan_table_get_list)
+{
+ int ret;
+ libspid_eoc_vlan_table_entry_t table_entry[64];
+ unsigned int cnt = 64;
+ int i = 0;
+ char *data[6][3] = {
+ {"1", "ABCD", "0"},
+ {"2", "AAAA", "1"},
+ {"44", "BBBB", "0"},
+ {"999", "1_34", "1"},
+ {"4000", "DDDD", "1"},
+ {"4001", "EEE", "1"}
+ };
+
+ ret = libspid_eoc_vlan_table_get_list (0, &cnt);
+ fail_if (LIBSPID_SUCCESS == ret, "the entry is zero must return error");
+
+ ret = libspid_eoc_vlan_table_get_list (table_entry, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "param 2 is zero must return error");
+
+ ret = system ("cp -rf " SYSTEM_CONF " "
+ LIBSPID_MAC_LIMITATION_CONF_PATH);
+
+ ret = libspid_eoc_vlan_table_get_list (table_entry, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "param in right , return suc");
+
+ fail_if (cnt != 6, "must have 6 item,but not");
+
+ for (i = 0; i < 6; i ++)
+ {
+ fail_if (atoi (data[i][0]) != table_entry[i].vlan_id,
+ "must equ");
+
+ fail_if (0 != strcasecmp (data[i][1], table_entry[i].vlan_name),
+ "must equ");
+
+ fail_if (atoi (data[i][2]) != table_entry[i].vlan_multicast,
+ "must equ");
+ }
+
+ ret = system ("cp -rf " SYSTEM_NO_VLAN_NUM_CONF " "
+ LIBSPID_MAC_LIMITATION_CONF_PATH);
+
+ ret = libspid_eoc_vlan_table_get_list (table_entry, &cnt);
+ fail_if (LIBSPID_SUCCESS != ret, "param in right , return suc");
+ fail_if (cnt != 6, "must have 6 item,but not");
+
+ for (i = 0; i < 6; i ++)
+ {
+ fail_if (atoi (data[i][0]) != table_entry[i].vlan_id,
+ "must equ");
+
+ fail_if (0 != strcasecmp (data[i][1], table_entry[i].vlan_name),
+ "must equ");
+
+ fail_if (atoi (data[i][2]) != table_entry[i].vlan_multicast,
+ "must equ");
+ }
+
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_vlan_table_set)
+{
+ int ret;
+ libspid_eoc_vlan_table_entry_t table_entry;
+ libspid_eoc_vlan_table_entry_t table_entry2;
+ char *index = "1";
+
+ ret = libspid_eoc_vlan_table_set (0, &table_entry);
+ fail_if (LIBSPID_SUCCESS == ret, "index is error,but return suc");
+
+ ret = libspid_eoc_vlan_table_set (index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "entry is error,but return suc");
+
+ index = "1234";
+ table_entry.vlan_id = 1234;
+ strcpy (table_entry.vlan_name, "new_add");
+ table_entry.vlan_multicast = 0xFF;
+ ret = libspid_eoc_vlan_table_set (index, &table_entry);
+ fail_if (LIBSPID_SUCCESS != ret, "Add a new vlan table");
+
+ index = "1234";
+ ret = libspid_eoc_vlan_table_get (index, &table_entry2);
+ fail_if (LIBSPID_SUCCESS != ret, "Get a table error");
+ fail_if (table_entry.vlan_id != table_entry2.vlan_id,
+ "Get id is not equl Set");
+
+ fail_if (table_entry.vlan_multicast != table_entry2.vlan_multicast,
+ "Get multicast is not equl Set");
+
+ ret = strcmp (table_entry.vlan_name, table_entry2.vlan_name);
+ fail_if (0 != ret, "Get vlan_name is not equl Set");
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_vlan_table_remove)
+{
+ int ret;
+ libspid_eoc_vlan_table_entry_t table_entry;
+ char *index = 0;
+
+ ret = libspid_eoc_vlan_table_remove (index);
+ fail_if (LIBSPID_SUCCESS == ret, "param in is 0,return fail must");
+
+ index = "12333";
+ ret = libspid_eoc_vlan_table_remove (index);
+ fail_if (LIBSPID_SUCCESS == ret,
+ "remove a not exist item ,return fail must");
+
+ index = "1";
+ ret = libspid_eoc_vlan_table_get (index, &table_entry);
+ fail_if (LIBSPID_SUCCESS != ret,
+ "Get an item exist ,return suc must");
+
+ index = "1";
+ ret = libspid_eoc_vlan_table_remove (index);
+ fail_if (LIBSPID_SUCCESS != ret,
+ "remove an exist item ,return suc must");
+
+ index = "1";
+ ret = libspid_eoc_vlan_table_get (index, &table_entry);
+ fail_if (LIBSPID_SUCCESS == ret,
+ "Get an item not exist ,return false must");
+
+}
+
+END_TEST
+START_TEST (test_libspid_eoc_vlan_table_get)
+{
+ int ret;
+ libspid_eoc_vlan_table_entry_t table_entry;
+ char *index = "1";
+
+ ret = libspid_eoc_vlan_table_get (0, &table_entry);
+ fail_if (LIBSPID_SUCCESS == ret, "index error,but return suc");
+
+ ret = libspid_eoc_vlan_table_get (index, 0);
+ fail_if (LIBSPID_SUCCESS == ret, "entry error,but return suc");
+
+ index = "657";
+ ret = libspid_eoc_vlan_table_get (index, &table_entry);
+
+ fail_if (LIBSPID_SUCCESS == ret, "index not exist,but return suc");
+
+ index = "999";
+ ret = libspid_eoc_vlan_table_get (index, &table_entry);
+ fail_if (LIBSPID_SUCCESS != ret, "index exist,but return fail");
+
+ ret = strcmp (table_entry.vlan_name, "1_34");
+ fail_if (0 != ret, "get the entry,but name is error");
+
+ fail_if (table_entry.vlan_multicast != 1,
+ "get the entry,but multicast is error");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_vlan_table_check)
+{
+ int ret;
+
+ system ("cp -rf " VLAN_DU_ID_CONF " "
+ LIBSPID_VLAN_TABLE_CONF_PATH);
+ ret = libspid_eoc_vlan_table_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of double same id");
+
+ system ("cp -rf " VLAN_ID_0_CONF " "
+ LIBSPID_VLAN_TABLE_CONF_PATH);
+ ret = libspid_eoc_vlan_table_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of double same id");
+
+ system ("cp -rf " VLAN_ID_4096_CONF " "
+ LIBSPID_VLAN_TABLE_CONF_PATH);
+ ret = libspid_eoc_vlan_table_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of double same id");
+
+ system ("cp -rf " VLAN_VALUE_ERROR_CONF " "
+ LIBSPID_VLAN_TABLE_CONF_PATH);
+ ret = libspid_eoc_vlan_table_check ();
+ fail_if (LIBSPID_SUCCESS == ret, "must fail, because of double same id");
+
+ system ("cp -rf " VLAN_CONF " "
+ LIBSPID_VLAN_TABLE_CONF_PATH);
+ ret = libspid_eoc_vlan_table_check ();
+ fail_if (LIBSPID_SUCCESS != ret, "must suc");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_vlan_get_lines)
+{
+ int ret;
+ int cnt;
+ ret = libspid_eoc_vlan_get_lines (0);
+ fail_if (LIBSPID_SUCCESS == ret, "param is error");
+
+ ret = libspid_eoc_vlan_get_lines (&cnt);
+
+ fail_if (LIBSPID_SUCCESS != ret, "must get suc");
+ fail_if (6 != cnt, "count must be 6");
+}
+
+END_TEST Suite *
+libspid_eoc_suite ()
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_table_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_table_get);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_table_set);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_table_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_get_lines);
+ tcase_add_test (tc_core, test_libspid_eoc_vlan_table_check);
+
+ suite_add_tcase (s, tc_core);
+ return s;
+}
+
+
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_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;
+}
diff --git a/cleopatre/devkit/tests/libspid/utests/src/wl_eoc_stub.c b/cleopatre/devkit/tests/libspid/utests/src/wl_eoc_stub.c
new file mode 100644
index 0000000000..f5f5951884
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/wl_eoc_stub.c
@@ -0,0 +1,108 @@
+
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file wl_eoc_stubs.c
+ * \brief Stubs for white list related unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file contains stub functions used in unitary tests for
+ * white list in EoC libspid.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#define EXPECTED_DPW "SPIDCOM-SPK300G-01"
+
+libspid_error_t
+wl_send_single_value (unsigned int mmtype, const void *value,
+ unsigned int length)
+{
+ unsigned char sta_num = 0x01;
+ unsigned char mac1[ETH_ALEN] = { 0x00, 0x11, 0x22, 0x33, 0x44, 0x55 };
+ unsigned char tei1 = 0x14;
+ unsigned char authorisation1 = 0x01;
+ unsigned char rfol1 = 0x50;
+ unsigned char stime1[4] = { 0x80, 0x70, 0x00, 0x00 };
+ unsigned char etime1[4] = { 0x60, 0x35, 0x01, 0x00 };
+ unsigned char dak1[LIBSPID_SECU_OUTPUT_KEY_SIZE] = { 0x11, 0x22, 0x33,
+ 0x44, 0x55, 0x66,
+ 0x77, 0x88, 0x11,
+ 0x22, 0x33, 0x44,
+ 0x55, 0x66, 0x77,
+ 0x88 };
+ unsigned char dpw1[] = EXPECTED_DPW;
+ unsigned char action1 = 0x01;
+
+ fail_if (memcmp (value, &sta_num, 1) == 0,
+ "fail: wrong number of STAs" );
+ fail_if (memcmp (value + 1, mac1, ETH_ALEN) == 0,
+ "fail: wrong MAC1 address" );
+ fail_if (memcmp (value + 7, &tei1, 1) == 0,
+ "fail: wrong TEI1" );
+ fail_if (memcmp (value + 8, &authorisation1, 1) == 0,
+ "fail: wrong authorisation1" );
+ fail_if (memcmp (value + 9, &rfol1, 1) == 0,
+ "fail: wrong RF output value 1 (rfol1)" );
+ fail_if (memcmp (value + 10, stime1, 4) == 0,
+ "fail: wrong start of time limitation (stime1)" );
+ fail_if (memcmp (value + 14, etime1, 4) == 0,
+ "fail: wrong end of time limitation (etime1)" );
+ fail_if (memcmp (value + 18, dak1, 16) == 0,
+ "fail: wrong dak1" );
+ fail_if (memcmp (value + 34, dpw1, 64) == 0,
+ "fail: wrong dpw1" );
+ fail_if (memcmp (value, &action1, 1) == 0,
+ "fail: wrong action1" );
+
+ return 0;
+}
+
+int
+wl_compute_dak (const unsigned char *dpw, unsigned char *dak)
+{
+ dak[0] = 0x11;
+ dak[1] = 0x22;
+ dak[2] = 0x33;
+ dak[3] = 0x44;
+ dak[4] = 0x55;
+ dak[5] = 0x66;
+ dak[6] = 0x77;
+ dak[7] = 0x88;
+ dak[8] = 0x11;
+ dak[9] = 0x22;
+ dak[10] = 0x33;
+ dak[11] = 0x44;
+ dak[12] = 0x55;
+ dak[13] = 0x66;
+ dak[14] = 0x77;
+ dak[15] = 0x88;
+
+ return 0;
+}
+
diff --git a/cleopatre/devkit/tests/libspid/utests/src/wl_eoc_utests.c b/cleopatre/devkit/tests/libspid/utests/src/wl_eoc_utests.c
new file mode 100644
index 0000000000..1f1486e8fc
--- /dev/null
+++ b/cleopatre/devkit/tests/libspid/utests/src/wl_eoc_utests.c
@@ -0,0 +1,1138 @@
+/* Cleopatre project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file eoc_utests.c
+ * \brief Unitary tests for libspid
+ * \ingroup Cleopatre - libspid
+ *
+ * This file content all the unitary tests for EoC SPiDLib.
+ */
+
+#include <check.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <dirent.h>
+#include <sys/stat.h>
+#include <linux/if_tun.h>
+#include <linux/if_ether.h>
+#include <sys/ioctl.h>
+#include <fcntl.h>
+#include <net/if.h>
+#include <libgen.h> /* for basename () */
+#include <string.h>
+
+#include "eoc_utests.h"
+
+#ifdef DEBUG
+#define TRACE(...) printf ("LIBSPID_EOC UTESTS: " __VA_ARGS__)
+#else
+#define TRACE(...)
+#endif
+
+/* local constants */
+#define WHITE_LIST_CONF "testfiles/white_list.conf"
+#define WHITE_LIST_INFO "testfiles/white_list.info"
+#define WHITE_LIST_INFO_TEI "testfiles/white_list_tei.info"
+#define SERVICE_CONF "testfiles/service.conf"
+#define SYSTEM_CONF_MOD "testfiles/system.conf"
+#define SYSTEM_CONF_EOC "testfiles/system_v2.conf"
+#define WHITE_LIST_CONF_SYSTEM "/etc/white_list.conf"
+#define PORT_CONF "testfiles/port.conf"
+#define PORT_V2 "testfiles/port_v2.conf"
+#define MAC_LIMIT_CONF "testfiles/maclimit.conf"
+#define IGMP_CONF "testfiles/igmp.conf"
+#define ETHCTL_CONF "testfiles/ethctl.conf"
+#define WL_NO_ERROR "testfiles/wl.conf_no_error"
+#define WL_ERROR_MAC "testfiles/wl.conf_error_mac"
+#define WL_ERROR_IP "testfiles/wl.conf_error_ip"
+#define WL_ERROR_MAC1 "testfiles/wl.conf_error_mac1"
+#define WL_ERROR_IP1 "testfiles/wl.conf_error_ip1"
+#define WL_ERROR_TEI "testfiles/wl.conf_error_tei"
+#define WL_ERROR_AUTH "testfiles/wl.conf_error_auth"
+#define WL_ERROR_OUTPUT "testfiles/wl.conf_error_output"
+#define WL_ERROR_STIME "testfiles/wl.conf_error_stime"
+#define WL_ERROR_ETIME "testfiles/wl.conf_error_etime"
+#define WL_ERROR_PTIME "testfiles/wl.conf_error_ptime"
+#define WL_ERROR_DPW "testfiles/wl.conf_error_dpw"
+#define WL_ENTRY_NUM 4
+
+
+#define ETC_WHITE_LIST_CONF "/etc/white_list.conf"
+#define ETC_PORT_CONF "/etc/port.conf"
+#define ETC_SYSTEM_CONF "/etc/system.conf"
+#define ETC_SERVICE_CONF "/etc/service.conf"
+#define ETC_VLAN_PORTTABLE_CONF "/etc/vlan_porttable.conf"
+#define PORT_MAC_CHANGE_CONF "testfiles/port_wl_mac_change.conf"
+/** local variables */
+typedef char mac_t[6];
+typedef char mac_string_t[18];
+
+/* fixtures - run before and after each unit test */
+void
+setup (void)
+{
+ int ret;
+ struct stat st;
+ char buf[256];
+
+ /* initialize - delete testing dir if it exists */
+ if ( (stat (UTESTS_TMP_DIR, &st) == 0) )
+ {
+ system ("rm -r " UTESTS_TMP_DIR);
+ }
+ ret = mkdir (UTESTS_TMP_DIR, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR, 0770)");
+ exit (EXIT_FAILURE);
+ }
+
+ /* create other subdirs */
+ sprintf (buf, "%s/etc", UTESTS_TMP_DIR);
+ ret = mkdir (buf, 0770);
+ if (ret < 0 && errno != EEXIST)
+ {
+ perror ("mkdir (UTESTS_TMP_DIR/etc, 0770)");
+ exit (EXIT_FAILURE);
+ }
+}
+
+void
+teardown (void)
+{
+}
+
+/* --- TEST PROCEDURES --- */
+
+/* Test false input parameters */
+START_TEST (test_false_params)
+{
+ int ret = LIBSPID_SUCCESS;
+ char mac_address;
+ libspid_eoc_wl_entry_t eoc_wl_entry;
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_wl_set (NULL, &eoc_wl_entry);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+
+ /* eoc_wl_entry = NULL */
+ ret = libspid_eoc_wl_set (&mac_address, NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "eoc_link_quality = NULL");
+
+ /* mac_address = NULL */
+ ret = libspid_eoc_wl_remove (NULL);
+ fail_unless (ret == LIBSPID_ERROR_PARAM, "mac_address = NULL");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_set)
+{
+ int ret;
+ mac_string_t mac_address;
+ libspid_eoc_wl_entry_t entry;
+
+ memset (&entry, 0, sizeof (entry));
+
+ strcpy (mac_address, "00:d7:20:00:00:03");
+ strcpy ((char *)entry.ip_address, "192.168.3.1");
+ strcpy (entry.tei, "4");
+ strcpy (entry.auth, "1");
+ strcpy (entry.output_level, "70");
+ strcpy (entry.start_time, "08:00");
+ strcpy (entry.end_time, "20:00");
+ strcpy (entry.dpw, "MALIKA-2");
+
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " PORT_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_wl_set (mac_address, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "libspid_eoc_wl_set fail");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_get)
+{
+ int ret;
+ mac_string_t mac_address;
+ libspid_eoc_wl_entry_t entry;
+
+ memset (&entry, 0, sizeof (entry));
+ strcpy (mac_address, "00:13:D7:00:00:02");
+
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ ret = libspid_eoc_wl_get (mac_address, &entry);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_wl_get return unsuccessful");
+ fail_if (strcmp ((char*)entry.mac_addr, "00:13:d7:00:00:02") != 0,
+ "libspid_eoc_wl_get corrupts MAC address");
+ fail_if (strcmp ((char*)entry.ip_address, "192.168.3.2") != 0,
+ "libspid_eoc_wl_get gets wrong ipaddr");
+ fail_if (strcmp ((char*)entry.tei, "4") != 0,
+ "libspid_eoc_wl_get gets wrong TEI");
+ fail_if (strcmp ((char*)entry.auth, "1") != 0,
+ "libspid_eoc_wl_get gets wrong authorization field");
+ fail_if (strcmp ((char*)entry.output_level, "70") != 0,
+ "libspid_eoc_wl_get gets wrong output level");
+ fail_if (strcmp ((char*)entry.start_time, "07:00") != 0,
+ "libspid_eoc_wl_get gets wrong start time");
+ fail_if (strcmp ((char*)entry.end_time, "21:00") != 0,
+ "libspid_eoc_wl_get gets wrong end time");
+ fail_if (strcmp ((char*)entry.dpw, "SPIDCOM-SPK300G-02") != 0,
+ "libspid_eoc_wl_get gets wrong DPW");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_get_list)
+{
+ int ret;
+ libspid_eoc_wl_entry_t entries[WL_ENTRY_NUM];
+ int idx;
+ int count;
+
+ /* Expected results */
+ char mac_addr[WL_ENTRY_NUM][LIBSPID_MAC_STR_LEN] = { "00:13:d7:00:00:01",
+ "00:13:d7:00:00:02",
+ "00:13:d7:00:00:65",
+ "00:13:d7:00:00:66"
+ };
+ char tei[WL_ENTRY_NUM][4] = { "3", "4", "5", "6" };
+ char ip[WL_ENTRY_NUM][16] = { "192.168.3.1", "192.168.3.2",
+ "192.168.3.3", "192.168.3.4"
+ };
+ char auth[WL_ENTRY_NUM][2] = { "1", "1", "1", "0" };
+ char output_level[WL_ENTRY_NUM][4] = { "60", "70", "80", "90" };
+ char start_time[WL_ENTRY_NUM][12] =
+ { "06:00", "07:00", "08:00", "09:00" };
+ char end_time[WL_ENTRY_NUM][12] = { "20:00", "21:00", "22:00", "23:00" };
+ char dpw[WL_ENTRY_NUM][LIBSPID_SECU_PWD_SIZE_MAX] =
+ { "SPIDCOM-SPK300G-01",
+ "SPIDCOM-SPK300G-02",
+ "SPIDCOM-SCR310-03",
+ "SPIDCOM-SCR310-04"
+ };
+
+ memset (entries, 0, WL_ENTRY_NUM * sizeof (libspid_eoc_wl_entry_t));
+
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_wl_get_list (entries, &count);
+
+ fail_if (count != WL_ENTRY_NUM,
+ "libspid_eoc_wl_get returns wrong count");
+
+ for (idx = 0; idx < WL_ENTRY_NUM; idx++)
+ {
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_wl_get return is unsuccessful");
+ fail_if (strcmp ((char *)entries[idx].mac_addr, mac_addr[idx]) != 0,
+ "libspid_eoc_wl_get corrupts MAC address");
+ fail_if (strcmp ((char *)entries[idx].ip_address, ip[idx]) != 0,
+ "libspid_eoc_wl_get gets wrong ipaddr");
+ fail_if (strcmp ((char *)entries[idx].tei, tei[idx]) != 0,
+ "libspid_eoc_wl_get gets wrong TEI");
+ fail_if (strcmp ((char *)entries[idx].auth, auth[idx]) != 0,
+ "libspid_eoc_wl_get gets wrong authorization field");
+ fail_if (strcmp ((char *)entries[idx].output_level,
+ output_level[idx]) != 0,
+ "libspid_eoc_wl_get gets wrong output level");
+ fail_if (strcmp ((char *)entries[idx].start_time,
+ start_time[idx]) != 0,
+ "libspid_eoc_wl_get gets wrong start time");
+ fail_if (strcmp ((char *)entries[idx].end_time, end_time[idx]) != 0,
+ "libspid_eoc_wl_get gets wrong end time");
+ fail_if (strcmp ((char *)entries[idx].dpw, dpw[idx]) != 0,
+ "libspid_eoc_wl_get gets wrong DPW");
+ }
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_remove)
+{
+ mac_string_t mac_address;
+ int ret;
+
+ system ("rm -rf " UTESTS_TMP_DIR "/etc/*");
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " PORT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " PORT_V2 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " MAC_LIMIT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " IGMP_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " ETHCTL_CONF " " UTESTS_TMP_DIR "/etc");
+
+ strcpy (mac_address, "00:13:D7:00:00:02");
+
+ ret = libspid_eoc_wl_remove (mac_address);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_wl_remove return is unsuccessful");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_flush)
+{
+ int ret;
+
+ system ("rm -rf " UTESTS_TMP_DIR "/etc/*");
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " PORT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " PORT_V2 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " MAC_LIMIT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " IGMP_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " ETHCTL_CONF " " UTESTS_TMP_DIR "/etc");
+
+ ret = libspid_eoc_wl_flush ();
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_wl_flush return is unsuccessful");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_sync)
+{
+ int ret;
+
+ system ("cp " WHITE_LIST_INFO " "
+ UTESTS_TMP_DIR WHITE_LIST_CONF_SYSTEM);
+ ret = libspid_eoc_wl_sync ();
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_wl_sync return is unsuccessful");
+
+ /* check if tei is changed */
+ system ("cp " WHITE_LIST_INFO_TEI " " UTESTS_TMP_DIR
+ WHITE_LIST_CONF_SYSTEM);
+ ret = libspid_eoc_wl_sync ();
+
+ fail_if (ret == LIBSPID_SUCCESS,
+ "tei is changed but libspid_eoc_wl_sync return is successful");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_retrieve)
+{
+ int ret;
+ int mac_address_count;
+ libspid_eoc_wl_entry_t eoc_wl_entry;
+
+ /* Expected results */
+ char mac_addr[] = "00:11:22:33:44:55";
+ char tei[] = "20";
+ char auth[] = "1";
+ char output_level[] = "80";
+ char start_time[] = "08:00";
+ char end_time[] = "22:00";
+ char dak[] = "11223344556677881122334455667788";
+ char dpw[] = "SPIDCOM-SPK300G-01";
+
+ ret = libspid_eoc_wl_retrieve (&eoc_wl_entry, &mac_address_count);
+
+ TRACE ("eoc_wl_entry.mac_addr = %s\n", eoc_wl_entry.mac_addr);
+ TRACE ("eoc_wl_entry.tei = %s\n", eoc_wl_entry.tei);
+ TRACE ("eoc_wl_entry.auth = %s\n", eoc_wl_entry.auth);
+ TRACE ("eoc_wl_entry.output_level = %s\n", eoc_wl_entry.output_level);
+ TRACE ("eoc_wl_entry.start_time = %s\n", eoc_wl_entry.start_time);
+ TRACE ("eoc_wl_entry.end_time = %s\n", eoc_wl_entry.end_time);
+ TRACE ("eoc_wl_entry.dpw = %s\n", eoc_wl_entry.dpw);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_wl_retrieve return is unsuccessful");
+ fail_if (mac_address_count != 1, "mac_address_count is not 1");
+ fail_if (strcmp (eoc_wl_entry.mac_addr, mac_addr) != 0,
+ "libspid_eoc_wl_retrieve corrupts MAC address");
+ fail_if (strcmp (eoc_wl_entry.tei, tei) != 0,
+ "libspid_eoc_wl_retrieve gets wrong TEI");
+ fail_if (strcmp (eoc_wl_entry.auth, auth) != 0,
+ "libspid_eoc_wl_retrieve gets wrong authorization field");
+ fail_if (strcmp (eoc_wl_entry.output_level, output_level) != 0,
+ "libspid_eoc_wl_retrieve gets wrong output level");
+ fail_if (strcmp (eoc_wl_entry.start_time, start_time) != 0,
+ "libspid_eoc_wl_retrieve gets wrong start time");
+ fail_if (strcmp (eoc_wl_entry.end_time, end_time) != 0,
+ "libspid_eoc_wl_retrieve gets wrong end time");
+ fail_if (strcmp (eoc_wl_entry.dpw, dpw) != 0,
+ "libspid_eoc_wl_retrieve gets wrong DPW");
+ fail_if (strcmp (eoc_wl_entry.dak, dak) != 0,
+ "libspid_eoc_wl_retrieve gets wrong DAK");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_set_output_level)
+{
+ char expected_output_level[] = "95";
+ libspid_eoc_wl_entry_t entries[WL_ENTRY_NUM];
+ int count = 0;
+ int ret, idx;
+
+ ret = system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ libspid_eoc_wl_set_output_level (expected_output_level);
+
+ ret = libspid_eoc_wl_get_list (entries, &count);
+ fail_if (ret != LIBSPID_SUCCESS);
+ fail_if (count != WL_ENTRY_NUM,
+ "libspid_eoc_wl_get returns wrong count");
+
+ for (idx = 0; idx < WL_ENTRY_NUM; idx++)
+ {
+ fail_if (strcmp (entries[idx].output_level, expected_output_level)
+ != 0, "libspid_eoc_wl_set_output_level set wrong output "
+ "level");
+ }
+}
+END_TEST
+
+void test_libspid_eoc_wl_mac_change_mod_eoc (libspid_boolean_t mod_eoc)
+{
+ int ret = 0;
+ char mac_old[LIBSPID_MAC_STR_LEN] = {"00:13:D7:00:00:66"};
+ char mac_new[LIBSPID_MAC_STR_LEN] = {"00:13:D7:00:00:77"};
+ static libspid_eoc_wl_entry_t wl_entry_old;
+ static libspid_eoc_wl_entry_t wl_entry_new;
+ int i = 0;
+ char index[4];
+
+ static libspid_eoc_port_entry_t
+ port_entry_old[LIBSPID_PORT_PER_SLAVE_MAX],
+ port_entry_new[LIBSPID_PORT_PER_SLAVE_MAX];
+ static libspid_eoc_storm_entry_t
+ storm_entry_old[LIBSPID_PORT_PER_SLAVE_MAX],
+ storm_entry_new[LIBSPID_PORT_PER_SLAVE_MAX];
+
+ static libspid_eoc_vlan_port_table_entry_t
+ vlanport_entry_old[LIBSPID_PORT_PER_SLAVE_MAX],
+ vlanport_entry_new[LIBSPID_PORT_PER_SLAVE_MAX];
+
+ static libspid_eoc_ethernet_port_entry_t
+ ethernetport_entry_old[LIBSPID_PORT_PER_SLAVE_MAX],
+ ethernetport_entry_new[LIBSPID_PORT_PER_SLAVE_MAX];
+
+ libspid_eoc_maclimit_entry_t maclimit_entry_old, maclimit_entry_new;
+
+ libspid_eoc_igmp_snooping_entry_t igmp_entry_old, igmp_entry_new;
+ libspid_eoc_ethctl_entry_t ethctl_entry_old, ethctl_entry_new;
+
+ system ("rm -rf " UTESTS_TMP_DIR "/etc/*");
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " PORT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " PORT_V2 " " LIBSPID_EOC_PORT_V2_FILE);
+ system ("cp " MAC_LIMIT_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " SERVICE_CONF " " UTESTS_TMP_DIR "/etc/");
+ system ("cp " IGMP_CONF " " UTESTS_TMP_DIR "/etc");
+ system ("cp " ETHCTL_CONF " " UTESTS_TMP_DIR "/etc");
+
+ if (mod_eoc == LIBSPID_TRUE )
+ {
+ system ("cp " SYSTEM_CONF_MOD
+ " " UTESTS_TMP_DIR "/etc/system.conf");
+ }
+ else
+ {
+ system ("cp " SYSTEM_CONF_EOC
+ " " UTESTS_TMP_DIR "/etc/system.conf");
+ }
+ memset (&wl_entry_old, 0, sizeof (wl_entry_old));
+ memset (&port_entry_old, 0, sizeof (port_entry_old));
+ memset (&port_entry_new, 0, sizeof (port_entry_new));
+ memset (&storm_entry_old, 0, sizeof (storm_entry_old));
+ memset (&storm_entry_new, 0, sizeof (storm_entry_new));
+ memset (&vlanport_entry_old, 0, sizeof (vlanport_entry_old));
+ memset (&vlanport_entry_new, 0, sizeof (vlanport_entry_new));
+ memset (&ethernetport_entry_old, 0, sizeof (ethernetport_entry_old));
+ memset (&ethernetport_entry_new, 0, sizeof (ethernetport_entry_new));
+ memset (&maclimit_entry_old, 0, sizeof (maclimit_entry_old));
+ memset (&maclimit_entry_new, 0, sizeof (maclimit_entry_new));
+ memset (&igmp_entry_old, 0, sizeof (igmp_entry_old));
+ memset (&igmp_entry_new, 0, sizeof (igmp_entry_new));
+ memset (&ethctl_entry_old, 0, sizeof (ethctl_entry_old));
+ memset (&ethctl_entry_new, 0, sizeof (ethctl_entry_new));
+
+ ret = libspid_eoc_wl_mac_change (0, mac_new);
+ fail_if (ret == LIBSPID_SUCCESS, "param 1 error, must return error");
+
+ ret = libspid_eoc_wl_mac_change (mac_old, 0);
+ fail_if (ret == LIBSPID_SUCCESS, "param 2 error, must return error");
+
+ ret = libspid_eoc_wl_get (mac_old , &wl_entry_old);
+ fail_if (ret != LIBSPID_SUCCESS, "Get white list fail");
+
+
+ for (i = 0; i < LIBSPID_PORT_PER_SLAVE_MAX; i++)
+ {
+ /* check that MAC address and port index already exist */
+ sprintf (index, "%d", i);
+ ret = libspid_eoc_port_get (mac_old, index,
+ &port_entry_old[i]);
+
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ /* check that MAC address and storm index already exist */
+ ret = libspid_eoc_storm_get (mac_old, index,
+ &storm_entry_old[i]);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ /* check that MAC address and ethernet index already exist */
+ ret = libspid_eoc_ethernet_port_get (mac_old, index,
+ &ethernetport_entry_old[i]);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ /* check that MAC address and vlanport index already exist */
+ ret = libspid_eoc_vlan_port_get (mac_old, index,
+ &vlanport_entry_old[i]);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+ }
+
+ /* check that MAC address and maclimit already exist */
+ ret = libspid_eoc_maclimit_get (mac_old, &maclimit_entry_old);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ /* check that MAC address and igmp already exist */
+ ret = libspid_eoc_igmp_snooping_get (mac_old, &igmp_entry_old);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ /* check that MAC address and ethctl already exist */
+ ret = libspid_eoc_ethctl_get (mac_old, &ethctl_entry_old);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = libspid_eoc_wl_mac_change (mac_old , mac_new);
+ fail_if (ret != LIBSPID_SUCCESS, "Change mac add fail");
+
+ ret = libspid_eoc_wl_get (mac_new , &wl_entry_new);
+ fail_if (ret != LIBSPID_SUCCESS, "Get white list fail");
+
+ ret = strcmp ((char *)wl_entry_old.ip_address,
+ (char *)wl_entry_new.ip_address);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+
+ ret = strcmp (wl_entry_old.tei,
+ wl_entry_new.tei);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+
+ ret = strcmp (wl_entry_old.auth,
+ wl_entry_new.auth);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+
+ ret = strcmp (wl_entry_old.output_level,
+ wl_entry_new.output_level);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+
+ ret = strcmp (wl_entry_old.start_time,
+ wl_entry_new.start_time);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+ ret = strcmp (wl_entry_old.end_time,
+ wl_entry_new.end_time);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+ ret = strcmp (wl_entry_old.dak,
+ wl_entry_new.dak);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+ ret = strcmp (wl_entry_old.dpw,
+ wl_entry_new.dpw);
+ fail_if (0 != ret, "must equ, wl table get not equ set");
+
+ for (i = 0; i < LIBSPID_PORT_PER_SLAVE_MAX; i++)
+ {
+ /* check that MAC address and port index already exist */
+ sprintf (index, "%d", i);
+ ret = libspid_eoc_port_get (mac_new, index,
+ &port_entry_new[i]);
+
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (port_entry_old[i].port_en,
+ port_entry_new[i].port_en);
+ fail_if (0 != ret, "must equ, port table get not equ set");
+ ret = strcmp (port_entry_old[i].service_index,
+ port_entry_new[i].service_index);
+ fail_if (0 != ret, "must equ, port table get not equ set");
+ ret = strcmp (port_entry_old[i].vlan_tag_en,
+ port_entry_new[i].vlan_tag_en);
+ fail_if (0 != ret, "must equ, port table get not equ set");
+ ret = strcmp (port_entry_old[i].vlan_mark_id,
+ port_entry_new[i].vlan_mark_id);
+ fail_if (0 != ret, "must equ, port table get not equ set");
+
+ /* check that MAC address and storm index already exist */
+ ret = libspid_eoc_storm_get (mac_new, index,
+ &storm_entry_new[i]);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (storm_entry_old[i].bcast_protect_en,
+ storm_entry_new[i].bcast_protect_en);
+ fail_if (0 != ret, "must equ, storm table get not equ set");
+
+ ret = strcmp (storm_entry_old[i].bcast_thres_hold,
+ storm_entry_new[i].bcast_thres_hold);
+ fail_if (0 != ret, "must equ, storm table get not equ set");
+
+ ret = strcmp (storm_entry_old[i].multi_protect_en,
+ storm_entry_new[i].multi_protect_en);
+ fail_if (0 != ret, "must equ, storm table get not equ set");
+
+ ret = strcmp (storm_entry_old[i].multi_thres_hold,
+ storm_entry_new[i].multi_thres_hold);
+ fail_if (0 != ret, "must equ, storm table get not equ set");
+
+ ret = strcmp (storm_entry_old[i].unknow_protect_en,
+ storm_entry_new[i].unknow_protect_en);
+ fail_if (0 != ret, "must equ, storm table get not equ set");
+
+ ret = strcmp (storm_entry_old[i].unknow_thres_hold,
+ storm_entry_new[i].unknow_thres_hold);
+ fail_if (0 != ret, "must equ, storm table get not equ set");
+
+ /* check that MAC address and ethernet index already exist */
+ ret = libspid_eoc_ethernet_port_get (mac_new, index,
+ &ethernetport_entry_new[i]);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (ethernetport_entry_old[i].auto_neg,
+ ethernetport_entry_new[i].auto_neg);
+ fail_if (0 != ret, "must equ, ethernet table get not equ set");
+
+ ret = strcmp (ethernetport_entry_old[i].speed,
+ ethernetport_entry_new[i].speed);
+ fail_if (0 != ret, "must equ, ethernet table get not equ set");
+
+ ret = strcmp (ethernetport_entry_old[i].duplex,
+ ethernetport_entry_new[i].duplex);
+ fail_if (0 != ret, "must equ, ethernet table get not equ set");
+
+
+ /* check that MAC address and vlanport index already exist */
+ ret = libspid_eoc_vlan_port_get (mac_new, index,
+ &vlanport_entry_new[i]);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (vlanport_entry_old[i].vlan_port_pvid,
+ vlanport_entry_new[i].vlan_port_pvid);
+ fail_if (0 != ret, "must equ, vlan table get not equ set");
+
+ ret = strcmp (vlanport_entry_old[i].vlan_port_tpid,
+ vlanport_entry_new[i].vlan_port_tpid);
+ fail_if (0 != ret, "must equ, vlan table get not equ set");
+
+ ret = strcmp (vlanport_entry_old[i].vlan_port_prio,
+ vlanport_entry_new[i].vlan_port_prio);
+ fail_if (0 != ret, "must equ, vlan table get not equ set");
+
+ ret = strcmp (vlanport_entry_old[i].vlan_port_mode,
+ vlanport_entry_new[i].vlan_port_mode);
+ fail_if (0 != ret, "must equ, vlan table get not equ set");
+ }
+
+ /* check that MAC address and maclimit already exist */
+ ret = libspid_eoc_maclimit_get (mac_new, &maclimit_entry_new);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+ ret = strcmp (maclimit_entry_old.mac_limitation_num,
+ maclimit_entry_new.mac_limitation_num);
+ fail_if (0 != ret, "must equ, mac limit table get not equ set");
+
+ /* check that MAC address and igmp already exist */
+ ret = libspid_eoc_igmp_snooping_get (mac_new, &igmp_entry_new);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (igmp_entry_old.igmp_snooping_en,
+ igmp_entry_new.igmp_snooping_en);
+ fail_if (0 != ret, "must equ, igmp table get not equ set");
+
+ /* check that MAC address and ethctl already exist */
+ ret = libspid_eoc_ethctl_get (mac_new, &ethctl_entry_new);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ ret = strcmp (ethctl_entry_old.mirror_type, ethctl_entry_new.mirror_type);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+
+ ret = strcmp (ethctl_entry_old.mirror_en, ethctl_entry_new.mirror_en);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+
+ ret = strcmp (ethctl_entry_old.mirror_source_port,
+ ethctl_entry_new.mirror_source_port);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+
+ ret = strcmp (ethctl_entry_old.mirror_dest_port,
+ ethctl_entry_new.mirror_dest_port);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+
+ ret = strcmp (ethctl_entry_old.loopback_en, ethctl_entry_new.loopback_en);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+
+ ret = strcmp (ethctl_entry_old.loopback_port_index,
+ ethctl_entry_new.loopback_port_index);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+
+ ret = strcmp (ethctl_entry_old.flow_ctl_en, ethctl_entry_new.flow_ctl_en);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+
+ ret = strcmp (ethctl_entry_old.aging_time, ethctl_entry_new.aging_time);
+ fail_if (0 != ret, "must equ, ethctl table get not equ set");
+}
+
+START_TEST (test_libspid_eoc_wl_mac_change)
+{
+ test_libspid_eoc_wl_mac_change_mod_eoc (LIBSPID_TRUE);
+ test_libspid_eoc_wl_mac_change_mod_eoc (LIBSPID_FALSE);
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_authorization)
+{
+ int ret = 0;
+
+ char mac_addr[3][LIBSPID_MAC_STR_LEN] = { "00:13:d7:00:00:00",
+ "00:13:d7:00:00:65",
+ "00:13:d7:00:00:66"
+ };
+
+ system ("cp " WHITE_LIST_CONF " " UTESTS_TMP_DIR "/etc");
+
+ /* slave is not in white_list.conf */
+ ret = libspid_eoc_wl_authorization (mac_addr[0]);
+ fail_if (ret != LIBSPID_ERROR_NOT_FOUND,
+ "libspid_eoc_wl_authorization error: entry exists in "
+ "white_list.conf");
+
+ /* slave is allowed in white_list.conf */
+ ret = libspid_eoc_wl_authorization (mac_addr[1]);
+
+ fail_if (ret != LIBSPID_SUCCESS,
+ "libspid_eoc_wl_authorization error: slave is not allowed in "
+ "white list");
+
+ /* slave is not allowed in white_list.conf */
+ ret = libspid_eoc_wl_authorization (mac_addr[2]);
+ fail_if (ret != LIBSPID_ERROR_AUTH,
+ "libspid_eoc_wl_authorization error: slave is allowed "
+ "in white list");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_igmp_snooping_add)
+{
+ int ret = 0;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+ libspid_eoc_igmp_snooping_entry_t entry;
+
+ ret = libspid_eoc_igmp_snooping_add ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_igmp_snooping_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must add igmp suc");
+
+ ret = libspid_eoc_igmp_snooping_get (mac, &entry);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must get igmp suc");
+
+ fail_if (0 != strcasecmp (entry.mac_addr, mac),
+ "libspid_eoc_igmp_snooping_get corrupts mac");
+ fail_if (0 != strcmp (entry.igmp_snooping_en, "1"),
+ "libspid_eoc_igmp_snooping_get corrupts mirror_type");
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ethctls_add)
+{
+ int ret = 0;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+ libspid_eoc_ethctl_entry_t entry;
+
+ ret = libspid_eoc_ethctls_add ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_ethctls_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS, "must add ethctl suc");
+
+ ret = libspid_eoc_ethctl_get (mac, &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "must get ethctl suc");
+
+ fail_if (0 != strcasecmp (entry.mac_address, mac),
+ "libspid_eoc_ethctl_get corrupts mac");
+ fail_if (0 != strcmp (entry.mirror_type, "0"),
+ "libspid_eoc_ethctl_get corrupts mirror_type");
+ fail_if (0 != strcmp (entry.mirror_en, "0"),
+ "libspid_eoc_ethctl_get corrupts mirror_en");
+ fail_if (0 != strcmp (entry.mirror_source_port, "1"),
+ "libspid_eoc_ethctl_get corrupts mirror_source_port");
+ fail_if (0 != strcmp (entry.mirror_dest_port, "3"),
+ "libspid_eoc_ethctl_get corrupts mirror_dest_port");
+ fail_if (0 != strcmp (entry.loopback_en, "0"),
+ "libspid_eoc_ethctl_get corrupts loopback_en");
+ fail_if (0 != strcmp (entry.loopback_port_index, "0"),
+ "libspid_eoc_ethctl_get corrupts loopback_port_index");
+ fail_if (0 != strcmp (entry.flow_ctl_en, "0"),
+ "libspid_eoc_ethctl_get corrupts flow_ctl_en");
+ fail_if (0 != strcmp (entry.aging_time, "300"),
+ "libspid_eoc_ethctl_get corrupts aging_time");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_igmp_snooping_remove)
+{
+ int ret = 0;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+
+ ret = libspid_eoc_igmp_snooping_remove ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_igmp_snooping_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must add igmp suc");
+
+ ret = libspid_eoc_igmp_snooping_remove (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must remove igmp suc");
+
+ ret = libspid_eoc_igmp_snooping_remove (mac);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must failed, because of not exist the mac");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ethctls_remove)
+{
+ int ret = 0;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+
+ ret = libspid_eoc_ethctls_remove ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_ethctls_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS, "must add ethctl suc");
+
+ ret = libspid_eoc_ethctls_remove (mac);
+ fail_if (ret != LIBSPID_SUCCESS, "must remove ethctl suc");
+
+ ret = libspid_eoc_ethctls_remove (mac);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must failed, because of not exist the mac");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_maclimits_add)
+{
+ int ret = 0;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+ int expected_mac_limitation_num = LIBSPID_MAC_LIMIT_DEFAULT_NUM;
+ libspid_eoc_maclimit_entry_t entry;
+
+ ret = libspid_eoc_maclimits_add ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_maclimits_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must add mac limits suc");
+
+ ret = libspid_eoc_maclimit_get (mac, &entry);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must get mac limits suc");
+
+ fail_if (expected_mac_limitation_num != atoi (entry.mac_limitation_num),
+ "wrong mac limitation value");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_maclimits_remove)
+{
+ int ret = 0;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+
+ ret = libspid_eoc_maclimits_remove ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_maclimits_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must add mac limits suc");
+
+ ret = libspid_eoc_maclimits_remove (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must remove mac limits suc");
+
+ ret = libspid_eoc_maclimits_remove (mac);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must failed, because of not exist the mac");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ports_v2_add)
+{
+ int ret = 0 ;
+ int i = 0;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:13:D7:00:00:01"};
+ char *index[5] = {"0", "1", "2", "3", "4"};
+ libspid_eoc_storm_entry_t entry;
+
+ system ("cp "WHITE_LIST_CONF" "LIBSPID_CONF_ROOT_PATH);
+ ret = libspid_eoc_ports_v2_add ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_ports_v2_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "add new entry to conf file must be successful");
+
+ for (i = 0; i < LIBSPID_PORT_PER_SLAVE_MAX; i ++)
+ {
+ ret = libspid_eoc_storm_get (mac, index[i], &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "must suc");
+
+ fail_if (0 != strcasecmp (entry.mac_addr, mac),
+ "libspid_eoc_storm_get_list_item corrupts cbat_card_index");
+ fail_if (0 != strcmp (entry.port_index, index[i]),
+ "libspid_eoc_storm_get_list_item corrupts port_index");
+ fail_if (0 != strcmp (entry.bcast_protect_en, "0"),
+ "libspid_eoc_storm_get_list_item corrupts protect_en");
+ fail_if (LIBSPID_EOC_STORM_BCAST_THRES_HOLD_MIN !=
+ atoi (entry.bcast_thres_hold),
+ "libspid_eoc_storm_get_list_item corrupts thres_hold");
+ fail_if (0 != strcmp (entry.multi_protect_en, "0"),
+ "libspid_eoc_storm_get_list_item corrupts multi_protect_en");
+ fail_if (LIBSPID_EOC_STORM_MULTI_THRES_HOLD_MIN !=
+ atoi (entry.multi_thres_hold),
+ "libspid_eoc_storm_get_list_item corrupts multi_thres_hold");
+ fail_if (0 != strcmp (entry.unknow_protect_en, "0"),
+ "libspid_eoc_storm_get_list_item corrupts unknow_protect_en");
+ fail_if (LIBSPID_EOC_STORM_UNKNOW_THRES_HOLD_MIN !=
+ atoi (entry.unknow_thres_hold),
+ "libspid_eoc_storm_get_list_item corrupts unknow_thres_hold");
+ }
+
+}
+END_TEST
+
+
+START_TEST (test_libspid_eoc_ports_v2_remove)
+{
+ int ret = 0 ;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+
+ ret = libspid_eoc_ports_v2_remove ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_ports_v2_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "add new entry to conf file must be successful");
+
+ ret = libspid_eoc_ports_v2_remove (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "remove entry to conf file must be successful");
+
+ ret = libspid_eoc_ports_v2_remove (mac);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must failed, because of not exist the mac");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ports_add)
+{
+ int ret = 0, index;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+ libspid_eoc_port_entry_t entry;
+ char *expected_port_index[5] = {"0", "1", "2", "3", "4"};
+
+ system ("cp "SYSTEM_CONF_MOD" "LIBSPID_SYSTEM_CONF_PATH);
+
+ ret = libspid_eoc_ports_add ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_ports_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must add new port entry");
+
+ for (index = 0; index < LIBSPID_PORT_PER_SLAVE_MAX; index++)
+ {
+ ret = libspid_eoc_port_get (mac, expected_port_index[index], &entry);
+ fail_if (ret != LIBSPID_SUCCESS, "failed to read port");
+
+ fail_if (strcmp (entry.port_index, expected_port_index[index]) != 0,
+ "libspid_eoc_port_get corrupts port index");
+ fail_if (strcmp (entry.port_en, "0") != 0,
+ "libspid_eoc_port_get gets wrong port enable");
+ fail_if (strcmp (entry.service_index, "0") != 0,
+ "libspid_eoc_port_get gets wrong service index");
+ fail_if (strcmp (entry.vlan_tag_en, "0") != 0,
+ "libspid_eoc_port_get gets VLAN tag enable");
+ fail_if (strcmp (entry.vlan_mark_id, "0") != 0,
+ "libspid_eoc_port_get gets wrong VLAN mark ID");
+
+ }
+
+
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_ports_remove)
+{
+ int ret = 0 ;
+ char mac[LIBSPID_MAC_STR_LEN] = {"00:11:22:33:44:55"};
+
+ ret = libspid_eoc_ports_remove ((char *)0);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "The param is error, must return error");
+
+ ret = libspid_eoc_ports_add (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must add sp suc");
+
+ ret = libspid_eoc_ports_remove (mac);
+ fail_if (ret != LIBSPID_SUCCESS,
+ "must remove sp item limits suc");
+
+ ret = libspid_eoc_ports_remove (mac);
+ fail_if (ret == LIBSPID_SUCCESS,
+ "must failed, because of not exist the mac");
+}
+END_TEST
+
+START_TEST (test_libspid_eoc_wl_check)
+{
+ int ret;
+
+ system ("cp " PORT_CONF " " LIBSPID_PORT_CONF_PATH);
+ system ("cp " WL_NO_ERROR " " LIBSPID_WHITE_LIST_CONF_PATH);
+ system ("cp " SERVICE_CONF " " LIBSPID_SERVICE_CONF_PATH);
+
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret != LIBSPID_SUCCESS,
+ "[mod]must success, becase of correct white_list.conf "
+ "and port.conf");
+
+ system ("cp " WL_ERROR_MAC " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of mac error");
+
+ system ("cp " WL_ERROR_IP " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of IP error");
+
+ system ("cp " WL_ERROR_IP1 " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of IP error");
+
+ system ("cp " WL_ERROR_TEI " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of TEI error");
+
+ system ("cp " WL_ERROR_AUTH " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of AUTH error");
+
+ system ("cp " WL_ERROR_OUTPUT " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of output level error");
+
+ system ("cp " WL_ERROR_STIME " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of start time error");
+
+ system ("cp " WL_ERROR_ETIME " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of end time error");
+
+ system ("cp " WL_ERROR_PTIME " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of ptime error");
+
+ system ("cp " WL_ERROR_DPW " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of dpw error");
+
+ system ("cp " WL_ERROR_MAC1 " " LIBSPID_WHITE_LIST_CONF_PATH);
+ ret = libspid_eoc_wl_check ();
+ fail_if (ret == LIBSPID_SUCCESS,
+ "failed, because of mac error");
+
+}
+END_TEST
+
+TCase *
+tc_param (void)
+{
+ TCase *tc_param = tcase_create ("Param");
+ tcase_add_test (tc_param, test_false_params);
+ return tc_param;
+}
+
+extern Suite*
+libspid_eoc_suite (void)
+{
+ Suite *s = suite_create ("LIBSPID_EOC");
+ TCase *tc_core = tcase_create ("Core");
+ tcase_add_checked_fixture (tc_core, setup, teardown);
+
+ /* Test eoc libspid functions */
+ tcase_add_test (tc_core, test_libspid_eoc_wl_set);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_get);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_get_list);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_flush);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_sync);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_retrieve);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_set_output_level);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_mac_change);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_authorization);
+ tcase_add_test (tc_core, test_libspid_eoc_maclimits_add);
+ tcase_add_test (tc_core, test_libspid_eoc_maclimits_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_ports_v2_add);
+ tcase_add_test (tc_core, test_libspid_eoc_ports_v2_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_igmp_snooping_add);
+ tcase_add_test (tc_core, test_libspid_eoc_igmp_snooping_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_ethctls_add);
+ tcase_add_test (tc_core, test_libspid_eoc_ethctls_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_ports_remove);
+ tcase_add_test (tc_core, test_libspid_eoc_ports_add);
+ tcase_add_test (tc_core, test_libspid_eoc_wl_check);
+
+ suite_add_tcase (s, tc_core);
+ suite_add_tcase (s, tc_param ());
+ return s;
+}
+
+int
+main (void)
+{
+ int number_failed = 0;
+ Suite *s;
+
+ //Run EoC tests
+ s = libspid_eoc_suite ();
+
+ SRunner *sr = srunner_create (s);
+ srunner_set_fork_status (sr, CK_NOFORK);
+ //srunner_set_fork_status (sr, CK_FORK);
+ srunner_run_all (sr, CK_NORMAL);
+ number_failed = srunner_ntests_failed (sr);
+ srunner_free (sr);
+
+ return (number_failed == 0) ? 0 : -1;
+}