/*------------------------------------------------------------------
* ipv6_discovery_test.c -- Neighbor Discovery unit tests.
*
* August 2003, Ole Troan
*
* Copyright (c) 2003-2004 by cisco Systems, Inc.
* All rights reserved.
*------------------------------------------------------------------
*/
#include "interface.h"
#include "interface_private.h"
#include "../ipv6.h"
#include "../ipv6_discovery.h"
#include "sys_registry.h"
#include "subsys.h"
#include COMP_INC(cutest, cu_test.h)
idbtype lidb;
hwidbtype hwidb;
ipv6_idbtype ipv6_sb;
in6_addr_t target;
/*
* setup_subsys_init
*/
extern list_header subsyslist[SUBSYS_CLASS_MAX];
static void
setup_subsys_init (subsys_class category, char *name)
{
list_element *element;
subsystype *subsys;
FOR_ALL_DATA_IN_LIST(&subsyslist[category], element, subsys) {
if (!strcmp(name, subsys->namestring)) {
if (subsys->entry) {
(*subsys->entry)(subsys);
break;
}
}
}
}
static void
setup (void) {
setup_subsys_init(SUBSYS_CLASS_PROTOCOL, "ipv6_nd");
reg_add_printf((long)'P', ipv6_printf, "ipv6_printf");
/*
* Create an IDB and Enable IPv6 on it
*/
lidb.hwptr = &hwidb;
hwidb.firstsw = &lidb;
hwidb.status = IDB_ETHER;
lidb.ipv6_data = &ipv6_sb;
target.s6_addr32[0] = 0x2001000;
target.s6_addr32[3] = 0x0000001;
}
/*
* nd_test_create
*/
CU_TEST_START (nd_test_create, tc)
{
ipv6_nd_entry *e;
printf("\nAdding %P to ND cache", &target);
e = ipv6_nd_table_create(&target, &lidb);
cu_ok(tc, (e != NULL), "%s", "create ND entry");
cu_ok(tc, (e->idb == &lidb) &&
IN6_ARE_ADDR_EQUAL(&e->address, &target), "%s",
"verify ND entry");
}
CU_TEST_END
/*
* nd_test_lookup
*/
CU_TEST_START (nd_test_lookup, tc)
{
ipv6_nd_entry *e;
e = ipv6_nd_table_lookup(&target, &lidb);
cu_ok(tc, (e != NULL), "%s", "ND lookup");
}
CU_TEST_END
/*
* nd_test_delete
*/
CU_TEST_START (nd_test_delete, tc)
{
ipv6_nd_entry *e;
ipv6_nd_table_delete(&target, &lidb);
e = ipv6_nd_table_lookup(&target, &lidb);
cu_ok(tc, (e == NULL), "ND delete");
}
CU_TEST_END
/*
* nd_test_suite
*/
cu_suite_t *
nd_test_suite (void)
{
cu_suite_t *s = cu_suite_new();
CU_SUITE_ADD_TEST(s, nd_test_create);
CU_SUITE_ADD_TEST(s, nd_test_lookup);
CU_SUITE_ADD_TEST(s, nd_test_delete);
return (s);
}
CU_TEST_MAIN()
{
int res;
cu_suite_t *suite = cu_suite_new();
cu_init();
cu_suite_add_suite(suite, nd_test_suite());
setup();
res = cu_suite_run(suite);
cu_suite_summary(suite);
CU_TEST_MAIN_RETURN(res);
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment