summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlefranc2009-10-29 20:02:25 +0000
committerlefranc2009-10-29 20:02:25 +0000
commit4a0b13a569e71094462655aa766b7a2d458d0c69 (patch)
treeaab80152cf486896ad1886aec7057032002a3bb3
parentc1641e2e4793af49081c4ad89219dd908d909aa1 (diff)
cleo/devkit/plcd: change on unit tests
- do not use libspid/libppe anymore (all funtions are stubbed) - check_status() test implementation (not completed yet) git-svn-id: svn+ssh://pessac/svn/cesar/trunk@6264 017c9cb6-072f-447c-8318-d5b54f68fe89
-rw-r--r--cleopatre/devkit/tests/plcd/Makefile4
-rw-r--r--cleopatre/devkit/tests/plcd/src/event_utests.c261
2 files changed, 173 insertions, 92 deletions
diff --git a/cleopatre/devkit/tests/plcd/Makefile b/cleopatre/devkit/tests/plcd/Makefile
index 52b2036ab9..6290698ce9 100644
--- a/cleopatre/devkit/tests/plcd/Makefile
+++ b/cleopatre/devkit/tests/plcd/Makefile
@@ -9,9 +9,9 @@ LIBMME_TEST_OBJ = $(wildcard $(LIBMME_TEST_DIR)/obj/prj/*.o)
LIBSPID_TEST_OBJ = $(wildcard $(LIBSPID_TEST_DIR)/obj/prj/*.o)
EXTRA_CFLAGS = -I$(LIBMME_DIR)/inc -I$(LIBSPID_DIR)/inc -I../../../include
-EXTRA_LIBS = $(LIBMME_TEST_OBJ) $(LIBSPID_TEST_OBJ)
+EXTRA_LIBS =
-PREBINS = make_libs
+PREBINS =
include ../../tests/utests_makerules
diff --git a/cleopatre/devkit/tests/plcd/src/event_utests.c b/cleopatre/devkit/tests/plcd/src/event_utests.c
index 56fbfad7f6..ccf402e913 100644
--- a/cleopatre/devkit/tests/plcd/src/event_utests.c
+++ b/cleopatre/devkit/tests/plcd/src/event_utests.c
@@ -48,15 +48,20 @@
#define HPAV_INFO_FILE_1 "../testfiles/hpav_1.info"
static struct check_ctx {
- int assert;
+ int assert_id;
+ int test_id;
jmp_buf jmp_env;
} check_ctx;
+#define CHECK_ASSERT(result, id, jmpbuf) if(0 == (result = setjmp (jmpbuf)))
/** local defines */
#define MAC_ADDR "AA:BB:CC:12:34:56" /* mac addr that will be used for testing */
#define PLC_ADDR "FF:EE:DD:98:76:54" /* mac addr that will be used for testing */
+#define MAX_ITEM_NB 8
+#define CONF_TABLE_INDEX 0
+#define INFO_TABLE_INDEX 1
/** local variables */
static plcd_ctx_t plcd_ctx;
@@ -64,48 +69,21 @@ static plcd_ctx_t *ctx = &plcd_ctx;
static int is_info_manager_needed, is_save_conf_needed;
static mme_ctx_t mme_ctx;
static char mme_buffer[1024];
-
+unsigned char label_table[2][MAX_ITEM_NB][64];
+unsigned char value_table[2][MAX_ITEM_NB][64];
unsigned char msg_buf[ETH_FRAME_LEN]; /* local buffer to store netlink messages */
-/****************************************
- * internal accomodation functions
- * **************************************/
-int check_assert (struct check_ctx *ctx, int test_id)
-{
- ctx->assert = 0;
- if (setjmp (ctx->jmp_env) != 0)
- {
- return test_id;
- }
- else
- {
- return 0;
- }
-}
-
-int build_file (const char *filename, const char *content)
-{
- FILE *fp;
- fp = fopen (filename, "w+");
- fprintf (fp, "%s", content);
- fclose (fp);
- return 0;
-}
-
/*
######################################
# FUNCTION STUB
# (redefinition of libc functions)
######################################
*/
-#undef assert
-void assert (int /*scalar*/ expr)
+void __assert_fail (__const char *__assertion, __const char *__file,
+ unsigned int __line, __const char *__function)
{
- if (!expr)
- {
- check_ctx.assert = 1;
- longjmp (check_ctx.jmp_env, check_ctx.assert);
- }
+ check_ctx.assert_id = check_ctx.test_id;
+ longjmp (check_ctx.jmp_env, check_ctx.assert_id);
}
ssize_t sendmsg (int socket, const struct msghdr *message, int flags)
@@ -148,6 +126,86 @@ int hpav_send_single_value (const plcd_ctx_t *plcd_ctx, unsigned int mmtype, con
return 0;
}
+mme_error_t mme_init (mme_ctx_t *ctx, const mme_type_t mmtype, unsigned char *buffer, const unsigned int length)
+{
+ ctx->buffer = buffer;
+ ctx->mmtype = mmtype;
+ ctx->length = length;
+ ctx->head = 0;
+ ctx->tail = 0;
+ return MME_SUCCESS;
+}
+
+mme_error_t mme_push (mme_ctx_t *ctx, const void *data, unsigned int length, unsigned int *result_length)
+{
+ return MME_SUCCESS;
+}
+
+mme_error_t mme_pull (mme_ctx_t *ctx, void *data, unsigned int length, unsigned int *result_length)
+{
+ *result_length = length;
+ memcpy(data, (unsigned char *)(ctx->buffer + ctx->head), length);
+ ctx->head += length;
+ //printf ("head=%d, data=%02x\n", ctx->head, *((unsigned char *)data));
+ return MME_SUCCESS;
+}
+
+mme_error_t mme_put (mme_ctx_t *ctx, const void *data, unsigned int length, unsigned int *result_length)
+{
+ *result_length = length;
+ memcpy( (unsigned char *)(ctx->buffer + ctx->tail), (unsigned char *)data, length );
+ ctx->tail += length;
+ return MME_SUCCESS;
+}
+
+void dump_table (unsigned char table[MAX_ITEM_NB][64])
+{
+ int i;
+ for (i = 0; i < MAX_ITEM_NB; i++)
+ printf ("%s-", table[i]);
+ printf ("\n");
+}
+
+libspid_error_t libspid_config_read_item (const char *filename, const char *label, char *value, int buffer_len)
+{
+ int i, conf;
+ conf = (!strcmp (filename, "conf") ? CONF_TABLE_INDEX : INFO_TABLE_INDEX);
+ for(i = 0; i < MAX_ITEM_NB; i++)
+ {
+ if(!strcmp (label, label_table[conf][i]))
+ {
+ strcpy (value, value_table[conf][i]);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ return LIBSPID_ERROR_NOT_FOUND;
+}
+
+libspid_error_t libspid_config_write_item(const char *filename, const char *label, const char *value)
+{
+ int i, conf;
+ conf = (!strcmp (filename, "conf") ? CONF_TABLE_INDEX : INFO_TABLE_INDEX);
+ for (i = 0; i < MAX_ITEM_NB; i++)
+ {
+ if(label_table[conf][i][0] == '\0')
+ break;
+ if(!strcmp (label_table[conf][i], label))
+ {
+ strcpy (value_table[conf][i], value);
+ return LIBSPID_SUCCESS;
+ }
+ }
+ if(i >= MAX_ITEM_NB)
+ return LIBSPID_ERROR_NO_SPACE;
+ strcpy (label_table[conf][i], label);
+ strcpy (value_table[conf][i], value);
+ return LIBSPID_SUCCESS;
+}
+
+extern libspid_error_t libspid_system_save_file(const char *filename)
+{
+ return LIBSPID_SUCCESS;
+}
/* fixtures - run before and after each unit test */
void setup(void)
@@ -157,29 +215,16 @@ void setup(void)
mme_init (&mme_ctx, MME_TYPE_DRV_STA_STATUS | MME_TYPE_IND, mme_buffer, sizeof(mme_buffer));
is_info_manager_needed = LIBSPID_FALSE;
is_save_conf_needed = LIBSPID_FALSE;
-#if 0
- int i;
- char pa[] = PLC_ADDR;
- char *s, *e;
-
- ctx->hardware_info_path = (char *)malloc(64);
- ctx->hpav_info_path = (char *)malloc(64);
- ctx->hpav_conf_path = (char *)malloc(64);
-
- /* initialize plcd context */
- strcpy(ctx->hardware_info_path, LIBSPID_HARDWARE_INFO_PATH);
- strcpy(ctx->hpav_info_path, LIBSPID_HPAV_INFO_PATH);
- strcpy(ctx->hpav_conf_path, LIBSPID_HPAV_CONF_PATH);
- ctx->plc_sock = 0;
- ctx->nvram = (spc300_nvram_t *) malloc(sizeof(spc300_nvram_t));
- s = pa;
- for (i = 0; i < 6; ++i)
- {
- ctx->nvram->plc_address[i] = s ? strtoul (s, &e, 16) : 0;
- if (s)
- s = (*e) ? e + 1 : e;
- }
-#endif
+ check_ctx.test_id = 0;
+ check_ctx.assert_id = 0;
+ memset (label_table, '\0', sizeof(label_table));
+ memset (value_table, '\0', sizeof(value_table));
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, "unassociated");
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_CCO, "station");
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_BACKUP_CCO, "no");
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_SC, "no");
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_SC_BUTTON, "no");
+
}
void teardown(void)
@@ -193,13 +238,13 @@ START_TEST (test_refresh_status_param_1)
{
int result;
- if(0 == (result = check_assert (&check_ctx, 1)))
+ check_ctx.test_id = 1;
+ if(0 == setjmp (check_ctx.jmp_env))
{
refresh_status (NULL, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
fail ("refresh_status plcd_ctx = NULL (1)");
}
- fail_unless ((1 == result)
- && (check_ctx.assert != 0),
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
"refresh status plcd_ctx = NULL (2)");
}
END_TEST
@@ -209,13 +254,13 @@ START_TEST (test_refresh_status_param_2)
{
int result;
- if(0 == (result = check_assert (&check_ctx, 2)))
+ check_ctx.test_id = 2;
+ if(0 == setjmp (check_ctx.jmp_env))
{
refresh_status (&plcd_ctx, NULL, &is_save_conf_needed, &is_info_manager_needed);
fail ("refresh_status mme_ctx = NULL (1)");
}
- fail_unless ((2 == result)
- && (check_ctx.assert != 0),
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
"refresh status mme_ctx = NULL (2)");
}
END_TEST
@@ -226,13 +271,13 @@ START_TEST (test_refresh_status_param_3)
int result;
mme_ctx.mmtype = MME_TYPE_DRV_STA_STATUS | MME_TYPE_CNF;
- if(0 == (result = check_assert (&check_ctx, 3)))
+ check_ctx.test_id = 3;
+ if(0 == setjmp (check_ctx.jmp_env))
{
refresh_status (&plcd_ctx, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
fail ("refresh_status mme_ctx.mmtype (1)");
}
- fail_unless ((3 == result)
- && (check_ctx.assert != 0),
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
"refresh status mme_ctx.mmtype (2)");
}
END_TEST
@@ -242,13 +287,13 @@ START_TEST (test_refresh_status_param_4)
{
int result;
- if(0 == (result = check_assert (&check_ctx, 4)))
+ check_ctx.test_id = 4;
+ if(0 == setjmp (check_ctx.jmp_env))
{
refresh_status (&plcd_ctx, &mme_ctx, NULL, &is_info_manager_needed);
fail ("refresh_status is_save_conf_needed (1)");
}
- fail_unless ((4 == result)
- && (check_ctx.assert != 0),
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
"refresh status is_save_conf_needed (2)");
}
END_TEST
@@ -258,20 +303,21 @@ START_TEST (test_refresh_status_param_5)
{
int result;
- if(0 == (result = check_assert (&check_ctx, 5)))
+ check_ctx.test_id = 5;
+ if(0 == setjmp (check_ctx.jmp_env))
{
refresh_status (&plcd_ctx, &mme_ctx, &is_save_conf_needed, NULL);
fail ("refresh_status is_info_manager_needed (1)");
}
- fail_unless ((5 == result)
- && (check_ctx.assert != 0),
+ fail_unless ((check_ctx.test_id == check_ctx.assert_id),
"refresh status is_info_manager_needed (2)");
}
END_TEST
TCase *event_refresh_status_param_tcase (void)
{
- TCase *tc = tcase_create ("refresh_status param");
+ TCase *tc = tcase_create ("refresh_status_param");
+ tcase_add_checked_fixture (tc, setup, teardown);
// check params plcd_ctx = NULL
tcase_add_test (tc, test_refresh_status_param_1);
// check param mme_ctx = NULL
@@ -291,8 +337,8 @@ START_TEST (test_refresh_status_assoc_1)
int result, length;
char buffer[1024];
- mme_push (&mme_ctx, "\x00\x00\x00\x00\x00", 5, &length);
- build_file (HPAV_INFO_TMP_PATH, "STATUS = associated\n");
+ mme_put (&mme_ctx, "\x00\x00\x00\x00\x00", 5, &length);
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, "unassociated");
refresh_status (&plcd_ctx, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
libspid_config_read_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, buffer, sizeof(buffer));
@@ -309,14 +355,20 @@ START_TEST (test_refresh_status_assoc_2)
int result, length;
char buffer[1024];
- mme_push (&mme_ctx, "\x01\x00\x00\x00\x00", 5, &length);
- build_file (HPAV_INFO_TMP_PATH, "STATUS = unassociated\n");
+ mme_put (&mme_ctx, "\x01\x00\x00\x00\x00", 5, &length);
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, "unassociated");
+
+// dump_table (label_table[INFO_TABLE_INDEX]);
+// dump_table (value_table[INFO_TABLE_INDEX]);
refresh_status (&plcd_ctx, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
libspid_config_read_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, buffer, sizeof(buffer));
+// dump_table (label_table[INFO_TABLE_INDEX]);
+// dump_table (value_table[INFO_TABLE_INDEX]);
+
fail_unless (!strcmp (buffer, "associated")
- && (LIBSPID_FALSE == is_info_manager_needed),
+ && (LIBSPID_TRUE == is_info_manager_needed),
"STATUS = associated");
}
END_TEST
@@ -327,14 +379,14 @@ START_TEST (test_refresh_status_assoc_3)
int result, length;
char buffer[1024];
- mme_push (&mme_ctx, "\x02\x00\x00\x00\x00", 5, &length);
- build_file (HPAV_INFO_TMP_PATH, "STATUS = unassociated\n");
+ mme_put (&mme_ctx, "\x02\x00\x00\x00\x00", 5, &length);
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, "unassociated");
refresh_status (&plcd_ctx, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
libspid_config_read_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, buffer, sizeof(buffer));
fail_unless (!strcmp (buffer, "authenticated")
- && (LIBSPID_FALSE == is_info_manager_needed),
+ && (LIBSPID_TRUE == is_info_manager_needed),
"STATUS = authenticated");
}
END_TEST
@@ -345,8 +397,8 @@ START_TEST (test_refresh_status_assoc_4)
int result, length;
char buffer[1024];
- mme_push (&mme_ctx, "\x03\x00\x00\x00\x00", 5, &length);
- build_file (HPAV_INFO_TMP_PATH, "STATUS = associated\n");
+ mme_put (&mme_ctx, "\x03\x00\x00\x00\x00", 5, &length);
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, "associated");
refresh_status (&plcd_ctx, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
libspid_config_read_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_STATUS, buffer, sizeof(buffer));
@@ -359,7 +411,8 @@ END_TEST
TCase *event_refresh_status_assoc_tcase (void)
{
- TCase *tc = tcase_create ("refresh_status assoc");
+ TCase *tc = tcase_create ("refresh_status_assoc");
+ tcase_add_checked_fixture (tc, setup, teardown);
// check STATUS field
tcase_add_test (tc, test_refresh_status_assoc_1);
tcase_add_test (tc, test_refresh_status_assoc_2);
@@ -369,20 +422,48 @@ TCase *event_refresh_status_assoc_tcase (void)
return tc;
}
-extern Suite* event_suite(void)
+/* check cco switch to proxy */
+START_TEST (test_refresh_status_cco_1)
+{
+ int result, length;
+ char buffer[1024];
+
+ mme_put (&mme_ctx, "\x00\x01\x00\x00\x00", 5, &length);
+ libspid_config_write_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_CCO, "station");
+
+ refresh_status (&plcd_ctx, &mme_ctx, &is_save_conf_needed, &is_info_manager_needed);
+ libspid_config_read_item (plcd_ctx.hpav_info_path, LIBSPID_HPAV_INFO_LABEL_CCO, buffer, sizeof(buffer));
+
+ fail_unless (!strcmp (buffer, "proxy")
+ && (LIBSPID_TRUE == is_info_manager_needed),
+ "CCO = proxy");
+}
+END_TEST
+
+TCase *event_refresh_status_cco_tcase (void)
+{
+ TCase *tc = tcase_create ("refresh_status_cco");
+ tcase_add_checked_fixture (tc, setup, teardown);
+ // check STATUS field
+ tcase_add_test (tc, test_refresh_status_cco_1);
+ return tc;
+}
+
+Suite* event_suite(void)
{
- Suite *s = suite_create("event");
- suite_add_tcase (s, event_refresh_status_param_tcase);
- suite_add_tcase (s, event_refresh_status_assoc_tcase);
+ Suite *s = suite_create ("event");
+ suite_add_tcase (s, event_refresh_status_param_tcase ());
+ suite_add_tcase (s, event_refresh_status_assoc_tcase());
+ suite_add_tcase (s, event_refresh_status_cco_tcase());
return s;
}
int main(void)
{
- Suite *s = event_suite;
+ Suite *s = suite_create ("event");
int number_failed = 0;
SRunner *sr = srunner_create(s);
- srunner_add_suite (sr, event_suite);
+ srunner_add_suite (sr, event_suite ());
//srunner_set_fork_status (sr, CK_NOFORK);
srunner_set_fork_status (sr, CK_FORK);
srunner_run_all(sr, CK_NORMAL);