RCU_API int rcu_add_test_func(rcu_module *mod, rcu_generic_function entry, rcu_generic_function init, rcu_generic_function destroy, const char *name) { rcu_test *func = NULL; rcu_registry *which_reg = NULL; rcu_test_machine *machine = NULL; int name_len = 0; rcu_init(); machine = &the_test_machine; if (entry == NULL) { RCU_SET_ERCD(RCU_E_INVFUNCENTRY); RCU_LOG_WARN("%s (null)", RCU_GET_ERR_MSG()); return RCU_E_NG; } mod = (mod == NULL) ? rcu_get_default_mod() : mod; func = rcu_srch_test_func_entry(mod, entry); if (func != NULL) { RCU_LOG_WARN("Similar test %s exists in %s", func->name, mod->name); } if ((func = rcu_alloc_test_func(1)) == NULL) { RCU_SET_ERCD(RCU_E_NOMEM); RCU_LOG_WARN("%s", RCU_GET_ERR_MSG()); return RCU_E_NG; } rcu_init_list(&func->link); char test_name[RCU_TEST_FUNCTION_NAME_LENGTH]; if (name == NULL) { memset(test_name, 0, RCU_TEST_FUNCTION_NAME_LENGTH); sprintf(test_name, "%p", entry); strncpy(func->name, test_name, strlen(test_name)); } else { name_len = strlen(name) > RCU_TEST_FUNCTION_NAME_LENGTH ? RCU_TEST_FUNCTION_NAME_LENGTH : strlen(name); strncpy(func->name, name, name_len); } func->entry = entry; func->init = init; func->destroy = destroy; rcu_init_list(&func->fail_rec_list); rcu_insert_list(&mod->func_list, &func->link); RCU_SET_RUN_STAT(func, RCU_RUN_STAT_NOTTESTED); RCU_INCR(mod->nr_test); RCU_LOG_DEBUG("Test %s added to %s", func->name, mod->name); return RCU_E_OK; }
RCU_API int rcu_add_test_func_tbl(rcu_module *mod, rcu_test_function_entry *func_tbl) { rcu_test_function_entry *cursor = NULL; int index; rcu_test_machine *machine = &the_test_machine; rcu_init(); if (!rcu_is_mach_initialized(machine)) { RCU_SET_ERCD(RCU_E_MACHNOINIT); return RCU_E_NG; } if (func_tbl == NULL) { RCU_SET_ERCD(RCU_E_INVFUNCTABLE); RCU_LOG_WARN("%s (null)", RCU_GET_ERR_MSG()); return RCU_E_NG; } mod = (mod == NULL) ? rcu_get_default_mod() : mod; RCU_FOR_EACH_FUNC_ENTRY(func_tbl, cursor, index) { if (cursor->entry != NULL) { rcu_add_test_func(mod, cursor->entry, cursor->init, cursor->destroy, cursor->name); } else { RCU_LOG_WARN("Invalid test function entry. (index = %d)", index); } } return RCU_E_OK; }
RCU_HASHTABLE *rcu_cre_hash_tbl(RCU_U4 nr_bucket){ RCU_HASHTABLE *tbl; RCU_U4 tbl_size; RCU_LOG_INFO_P1("Creating hash table with %lu buckets\n",nr_bucket); if (nr_bucket == 0){ return(RCU_NULL); } tbl_size = RCU_SIZEOF_HASHTABLE(nr_bucket); tbl = (RCU_HASHTABLE*)rcu_alloc_mem_cell(tbl_size); if (tbl == RCU_NULL){ RCU_SET_ERCD(RCU_E_NOMEM); RCU_LOG_WARN_P1("%s",RCU_GET_ERR_MSG()); return(RCU_NULL); } return(RCU_NULL); }