void dev_irq_init(dev_irq_state_t *irqState, dev_irq_config_t config) { assert(irqState); memset(irqState, 0, sizeof(dev_irq_state_t)); dprintf("Initialising IRQ handler state...\n"); if (config.numIRQChannels <= 0 || config.numIRQChannels >= DEVICE_IRQ_BADGE_MAX_CHANNELS) { ROS_ERROR("config.numIRQChannels is invalid.\n"); ROS_ERROR("IRQ handler init failed.\n"); return; } if (!config.getIRQHandlerEndpoint) { ROS_ERROR("Please provide a callback function for minting a IRQ handler cap.\n"); ROS_ERROR("IRQ handler init failed.\n"); return; } if (!config.notifyAsyncEP) { ROS_ERROR("Please provide an async endpoint to mint IRQ badges from.\n"); ROS_ERROR("IRQ handler init failed.\n"); return; } /* Initialise IRQ channel table. */ for (int i = 0; i < config.numIRQChannels; i++) { cvector_init(&irqState->channel[i]); } irqState->cfg = config; irqState->magic = DEVICE_IRQ_MAGIC; }
EC_BOOL chfsnp_mgr_init(CHFSNP_MGR *chfsnp_mgr) { CHFSNP_MGR_CRWLOCK_INIT(chfsnp_mgr, LOC_CHFSNPMGR_0002); CHFSNP_MGR_CMUTEX_INIT(chfsnp_mgr, LOC_CHFSNPMGR_0003); cstring_init(CHFSNP_MGR_DB_ROOT_DIR(chfsnp_mgr), NULL_PTR); CHFSNP_MGR_NP_MODEL(chfsnp_mgr) = CHFSNP_ERR_MODEL; CHFSNP_MGR_NP_1ST_CHASH_ALGO_ID(chfsnp_mgr) = (uint8_t)CHASH_ERR_ALGO_ID; CHFSNP_MGR_NP_2ND_CHASH_ALGO_ID(chfsnp_mgr) = (uint8_t)CHASH_ERR_ALGO_ID; CHFSNP_MGR_NP_ITEM_MAX_NUM(chfsnp_mgr) = 0; CHFSNP_MGR_NP_MAX_NUM(chfsnp_mgr) = 0; cvector_init(CHFSNP_MGR_NP_HOME_DIR_VEC(chfsnp_mgr), 0, MM_CSTRING, CVECTOR_LOCK_ENABLE, LOC_CHFSNPMGR_0004); cvector_init(CHFSNP_MGR_NP_VEC(chfsnp_mgr), 0, MM_CHFSNP, CVECTOR_LOCK_ENABLE, LOC_CHFSNPMGR_0005); return (EC_TRUE); }
void cpool_init(cpool_t *p, uint32_t start, uint32_t end) { assert(p); p->start = start; p->end = end; p->mx = start; cvector_init(&p->freelist); }
void test_cvector_remove_error() { cvector vec; int tester = 1; /* start the test */ /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); /* test the results */; cvector_destroy(vec); }
void test_cvector_init() { cvector vec; /* start the test */ /* start the tests */ cvector_init(&vec, NULL); FO_ASSERT_EQUAL(vec->size, 0); FO_ASSERT_EQUAL(vec->capacity, 1); FO_ASSERT_PTR_NULL(vec->memory); FO_ASSERT_PTR_NOT_NULL(vec->data); cvector_destroy(vec); }
void test_cvector_end() { cvector vec; int tester = 1; /* start the test */ /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); /* test the results */; FO_ASSERT_PTR_EQUAL(cvector_end(vec), vec->data+vec->size); cvector_destroy(vec); }
void test_cvector_at() { cvector vec; int tester = 1; /* start the test */ /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); /* test the results */; FO_ASSERT_EQUAL(*(int*)cvector_at(vec, 0), tester); cvector_destroy(vec); }
void test_cvector_init() { cvector vec; /* start the test */ printf("Test cvector_init: "); /* start the tests */ cvector_init(&vec, NULL); CU_ASSERT_EQUAL(vec->size, 0); CU_ASSERT_EQUAL(vec->capacity, 1); CU_ASSERT_EQUAL(vec->memory, NULL); CU_ASSERT_NOT_EQUAL(vec->data, NULL); cvector_destroy(vec); test_failure(); printf("\n"); }
void test_cvector_remove() { cvector vec; int tester = 1; /* start the test */ /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); cvector_remove(vec, vec->data); /* test the results */ FO_ASSERT_EQUAL(vec->size, 0); FO_ASSERT_PTR_EQUAL(vec->data[0], NULL); cvector_destroy(vec); }
void test_cvector_remove_error() { cvector vec; int tester = 1; /* start the test */ printf("Test cvector_remove_error: NOT IMPLEMENTED"); /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); /* test the results */; cvector_destroy(vec); test_failure(); printf("\n"); }
void test_cvector_end() { cvector vec; int tester = 1; /* start the test */ printf("Test cvector_end:"); /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); /* test the results */; CU_ASSERT_EQUAL(cvector_end(vec), vec->data+vec->size); cvector_destroy(vec); test_failure(); printf("\n"); }
void test_cvector_at() { cvector vec; int tester = 1; /* start the test */ printf("Test cvector_at:"); /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); /* test the results */; CU_ASSERT_EQUAL(*(int*)cvector_at(vec, 0), tester); cvector_destroy(vec); test_failure(); printf("\n"); }
void test_cvector_insert() { cvector vec; int tester = 1; /* start the test */ /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_insert(vec, vec->data, &tester); cvector_insert(vec, vec->data, &tester); cvector_insert(vec, vec->data, &tester); /* test the results */ FO_ASSERT_EQUAL(*(int*)vec->data[0], tester); tester = 2; FO_ASSERT_NOT_EQUAL(*(int*)vec->data[0], tester); cvector_destroy(vec); }
void test_cvector_remove() { cvector vec; int tester = 1; /* start the test */ printf("Test cvector_remove:"); /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_push_back(vec, &tester); cvector_remove(vec, vec->data); /* test the results */ CU_ASSERT_EQUAL(vec->size, 0); CU_ASSERT_EQUAL(vec->data[0], NULL); cvector_destroy(vec); test_failure(); printf("\n"); }
void test_cvector_capacity() { cvector vec; int tester = 1; /* start the test */ /* run the functions */ cvector_init(&vec, int_function_registry()); /* test the results */; FO_ASSERT_EQUAL(cvector_capacity(vec), 1); cvector_push_back(vec, &tester); FO_ASSERT_EQUAL(cvector_capacity(vec), 1); cvector_push_back(vec, &tester); FO_ASSERT_EQUAL(cvector_capacity(vec), 2); cvector_push_back(vec, &tester); FO_ASSERT_EQUAL(cvector_capacity(vec), 4); cvector_destroy(vec); }
void test_cvector_insert() { cvector vec; int tester = 1; /* start the test */ printf("Test cvector_insert:"); /* run the functions */ cvector_init(&vec, int_function_registry()); cvector_insert(vec, vec->data, &tester); cvector_insert(vec, vec->data, &tester); cvector_insert(vec, vec->data, &tester); /* test the results */ CU_ASSERT_EQUAL(*(int*)vec->data[0], tester); tester = 2; CU_ASSERT_NOT_EQUAL(*(int*)vec->data[0], tester); cvector_destroy(vec); test_failure(); printf("\n"); }
static int test_cvector(void) { test_start("cvector"); // Src: https://gist.github.com/EmilHernvall/953968 cvector_t v; cvector_init(&v); cvector_add(&v, (cvector_item_t)1); cvector_add(&v, (cvector_item_t)2); cvector_add(&v, (cvector_item_t)3); cvector_add(&v, (cvector_item_t)4); cvector_add(&v, (cvector_item_t)5); test_assert(cvector_count(&v) == (int)5); test_assert(cvector_get(&v, 0) == (cvector_item_t)1); test_assert(cvector_get(&v, 1) == (cvector_item_t)2); test_assert(cvector_get(&v, 2) == (cvector_item_t)3); test_assert(cvector_get(&v, 3) == (cvector_item_t)4); test_assert(cvector_get(&v, 4) == (cvector_item_t)5); cvector_delete(&v, 1); cvector_delete(&v, 3); test_assert(cvector_count(&v) == (int)3); test_assert(cvector_get(&v, 0) == (cvector_item_t)1); test_assert(cvector_get(&v, 1) == (cvector_item_t)3); test_assert(cvector_get(&v, 2) == (cvector_item_t)4); cvector_free(&v); int vcStress = 10000; for (int i = 0; i < vcStress; i++) { int data = ((i << 2) * 0xcafebabe) ^ 0xdeadbeef; cvector_add(&v, (cvector_item_t)data); test_assert(cvector_count(&v) == (int)(i + 1)); test_assert(cvector_get(&v, i) == (cvector_item_t)data); data = (data << 7) ^ 0xbaabaabb; cvector_set(&v, i, (cvector_item_t)data); test_assert(cvector_count(&v) == (int)(i + 1)); test_assert(cvector_get(&v, i) == (cvector_item_t)data); } cvector_free(&v); return test_success(); }
EC_BOOL crouter_node_vec_init(CROUTER_NODE_VEC *crouter_node_vec) { cvector_init(CROUTER_NODE_VEC_NODES(crouter_node_vec), 0, MM_CROUTER_NODE, CVECTOR_LOCK_ENABLE, LOC_CROUTER_0018); return (EC_TRUE); }
/* ======================================================================================================================= ======================================================================================================================= */ void rumble_modules_load(masterHandle *master) { /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ rumbleKeyValuePair *el; dvector_element *line; uint32_t ver; int x; #ifdef _WIN32 HINSTANCE handle; #else void *handle; #endif rumbleModInit init; rumbleVerCheck mcheck; rumble_module_info *modinfo; rumbleService *svc; char *error = 0; const char *services[] = { "mailman", "smtp", "pop3", "imap4", 0 }; /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/ rumble_debug(NULL, "core", "Preparing to load modules"); for (x = 0; services[x]; x++) { svc = comm_serviceHandle(services[x]); if (svc) { rumble_debug(NULL, "core", "Flushing hook structs for %s", services[x]); svc->cue_hooks = cvector_init(); svc->init_hooks = cvector_init(); svc->exit_hooks = cvector_init(); } } rumble_debug(NULL, "core", "Loading modules"); for (line = master->_core.conf->first; line != NULL; line = line->next) { el = (rumbleKeyValuePair *) line->object; if (!strcmp(el->key, "loadmodule")) { #if R_WINDOWS handle = LoadLibraryA(el->value); #else handle = dlopen(el->value, RTLD_LAZY | RTLD_NODELETE); error = dlerror(); #endif if (!handle) { error = error ? error : "(no such file?)"; fprintf(stderr, "\nError loading %s: %s\n", el->value, error); rumble_debug(NULL, "core", "Error loading %s: %s", el->value, error); exit(1); } if (error) { rumble_debug(NULL, "core", "Warning: %s\n", error); } modinfo = (rumble_module_info *) calloc(1, sizeof(rumble_module_info)); if (!modinfo) merror(); modinfo->author = 0; modinfo->description = 0; modinfo->title = 0; init = (rumbleModInit) dlsym(handle, "rumble_module_init"); mcheck = (rumbleVerCheck) dlsym(handle, "rumble_module_check"); modinfo->config = (rumbleModConfig) dlsym(handle, "rumble_module_config"); error = (init == 0 || mcheck == 0) ? "no errors" : 0; if (error != NULL) { rumble_debug(NULL, "core", "Warning: %s does not contain required module functions.\n", el->value); } if (init && mcheck) { master->_core.currentSO = el->value; dvector_add(master->_core.modules, modinfo); ver = (*mcheck) (); ver = (ver & 0xFFFFFF00) + (RUMBLE_VERSION & 0x000000FF); x = EXIT_SUCCESS; if (ver > RUMBLE_VERSION || ver < RUMBLE_VERSION_REQUIRED) { if (ver > RUMBLE_VERSION) { rumble_debug(NULL, "module", "Error: %s was compiled with a newer version of librumble (v%#X) than this server executable (v%#X).\nPlease recompile the module using the latest sources to avoid crashes or bugs.\n", el->value, ver, RUMBLE_VERSION); } else { rumble_debug(NULL, "module", "Error: %s was compiled with an older version of librumble (v%#X).\nPlease recompile the module using the latest sources (v%#X) to avoid crashes or bugs.\n", el->value, ver, RUMBLE_VERSION); } } else { modinfo->file = el->value; x = init(master, modinfo); } if (x != EXIT_SUCCESS) { rumble_debug(NULL, "module", "Error: %s failed to load!", el->value); dlclose(handle); } if (x == EXIT_SUCCESS) { if (modinfo->title) rumble_debug(NULL, "module", "Loaded extension: %-30s", modinfo->title); else rumble_debug(NULL, "module", "Loaded %48s", el->value); } else rumble_debug(NULL, "module", "%s exited prematurely!", el->value); } /* * dlclose(handle); */ } #ifdef RUMBLE_LUA else if (!strcmp(el->key, "loadscript")) { /*~~~~~~~~~~~*/ int x; lua_State *L; /*~~~~~~~~~~~*/ for (x = 0; x < RUMBLE_LSTATES; x++) { if (!master->lua.states[x].state) { master->lua.states[x].state = luaL_newstate(); L = (lua_State *) master->lua.states[x].state; lua_pushinteger(L, x); luaL_ref(L, LUA_REGISTRYINDEX); luaL_openlibs(L); luaopen_debug(L); Foo_register(L); } } printf("Loading script <%s>\n", el->value); /* Load the file into all states */ for (x = 0; x < RUMBLE_LSTATES; x++) { L = (lua_State *) master->lua.states[x].state; if (luaL_loadfile(L, el->value)) { rumble_debug(NULL, "lua", "Couldn't load script: %s", lua_tostring(L, -1)); break; } else if (lua_pcall(L, 0, LUA_MULTRET, 0)) { rumble_debug(NULL, "lua", "Failed to run <%s>: %s\n", el->value, lua_tostring(L, -1)); break; } } } #endif } }
void coat_init(coat_t *t, int start, int end) { assert(t); assert(start != 0); /* zero idx is reserved. */ cpool_init(&t->pool, start, end); cvector_init(&t->table); }
/** * @brief runs the labeled test files to determine accuracy * * This function will open each pair of files in the testdata directory to * analyze how accurate the copyright agent is. This function will respond with * the number of false negatives, false positives, and correct answers for each * file and total tally of these numbers. This will also produce 3 files, one * containing all matches that the copyright agent found, all the things that it * didn't find, and all of the false positives. */ void run_test_files(copyright copy) { /* locals */ cvector compare; copyright_iterator iter; cvector_iterator curr; FILE* istr, * m_out, * n_out, * p_out; char buffer[READMAX + 1]; char file_name[FILENAME_MAX]; char copy_buf[FILENAME_MAX]; char name_buf[FILENAME_MAX]; char* first, * last, * loc, tmp; int i, matches, correct = 0, falsep = 0, falsen = 0; /* grab the copyright files */ memset(copy_buf, '\0', sizeof(copy_buf)); memset(name_buf, '\0', sizeof(copy_buf)); snprintf(copy_buf, sizeof(copy_buf), "%s/mods-enabled/copyright/agent/copyright.dic", sysconfigdir); snprintf(name_buf, sizeof(name_buf), "%s/mods-enabled/copyright/agent/names.dic", sysconfigdir); /* create data structures */ copyright_init(©, copy_buf, name_buf); cvector_init(&compare, string_function_registry()); /* open the logging files */ m_out = fopen("Matches", "w"); n_out = fopen("False_Negatives", "w"); p_out = fopen("False_Positives", "w"); /* big problem if any of the log files didn't open correctly */ if(!m_out || !n_out || !p_out) { fprintf(cerr, "ERROR did not successfully open one of the log files\n"); fprintf(cerr, "ERROR the files that needed to be opened were:\n"); fprintf(cerr, "ERROR Matches, False_Positives, False_Negatives\n"); exit(-1); } /* loop over every file in the test directory */ for(i = 0; i < TESTFILE_NUMBER; i++) { sprintf(file_name, "%s%d_raw", test_dir, i); /* attempt to open the labeled test file */ istr = fopen(file_name, "r"); if(!istr) { fprintf(cerr, "ERROR Must run testing from correct directory. The\n"); fprintf(cerr, "ERROR correct directory is installation dependent but\n"); fprintf(cerr, "ERROR the working directory should include the folder:\n"); fprintf(cerr, "ERROR %s\n", test_dir); exit(-1); } /* initialize the buffer and read in any information */ memset(buffer, '\0', sizeof(buffer)); buffer[fread(buffer, sizeof(char), READMAX, istr)] = '\0'; matches = 0; /* set everything in the buffer to lower case */ for(first = buffer; *first; first++) { *first = tolower(*first); } /* loop through and find all <s>...</s> tags */ loc = buffer; while((first = strstr(loc, "<s>")) != NULL) { last = strstr(loc, "</s>"); if(last == NULL) { fprintf(cerr, "ERROR unmatched \"<s>\"\n"); fprintf(cerr, "ERROR in file: \"%s\"\n", file_name); exit(-1); } if(last <= first) { fprintf(cerr, "ERROR unmatched \"</s>\"\n"); fprintf(cerr, "ERROR in file: \"%s\"\n", file_name); exit(-1); } tmp = *last; *last = 0; cvector_push_back(compare, first + 3); *last = tmp; loc = last + 4; } /* close the previous file and open the corresponding raw data */ fclose(istr); file_name[strlen(file_name) - 4] = '\0'; istr = fopen(file_name, "r"); if(!istr) { fprintf(cerr, "ERROR Unmatched file in the test directory"); fprintf(cerr, "ERROR File with no match: \"%s\"_raw\n", file_name); fprintf(cerr, "ERROR File that caused error: \"%s\"\n", file_name); } /* perform the analysis on the current file */ copyright_analyze(copy, istr, REPORTALL); fclose(istr); /* loop over every match that the copyright object found */ for(iter = copyright_begin(copy); iter != copyright_end(copy); iter++) { cvector_iterator best = cvector_begin(compare); char score[2048]; char dst[2048]; memset(dst, '\0', sizeof(dst)); memset(score, '\0', sizeof(score)); /* log the coyright entry */ fprintf(m_out, "====%s================================\n", file_name); fprintf(m_out, "DICT: %s\tNAME: %s\n",copy_entry_dict(*iter), copy_entry_name(*iter)); fprintf(m_out, "TEXT[%s]\n",copy_entry_text(*iter)); /* loop over the vector looking for matches */ for(curr = cvector_begin(compare); curr != cvector_end(compare); curr++) { if(longest_common(dst, copy_entry_text(*iter), (char*)*curr) > strlen(score)) { strcpy(score, dst); best = curr; } } /* log the entry as found if it matched something in compare */ if(cvector_size(compare) != 0 && (strcmp(copy_entry_dict(*iter), "by") || strlen(score) > THRESHOLD)) { cvector_remove(compare, best); matches++; } else if(!strcmp(copy_entry_dict(*iter), "email") || !strcmp(copy_entry_dict(*iter), "url")) { matches++; } else { fprintf(p_out, "====%s================================\n", file_name); fprintf(p_out, "DICT: %s\tNAME: %s\n",copy_entry_dict(*iter), copy_entry_name(*iter)); fprintf(p_out, "TEXT[%s]\n",copy_entry_text(*iter)); } } /* log all the false negatives */ for(curr = cvector_begin(compare); curr != cvector_end(compare); curr++) { fprintf(n_out, "====%s================================\n", file_name); fprintf(n_out, "%s\n", (char*)*curr); } fprintf(cout, "====%s================================\n", file_name); fprintf(cout, "Correct: %d\n", matches); fprintf(cout, "False Positives: %d\n", copyright_size(copy) - matches); fprintf(cout, "False Negatives: %d\n", cvector_size(compare)); /* clean up for the next file */ correct += matches; falsep += copyright_size(copy) - matches; falsen += cvector_size(compare); cvector_clear(compare); } fprintf(cout, "==== Totals ================================\n"); fprintf(cout, "Total Found: %d\n", correct + falsep); fprintf(cout, "Correct: %d\n", correct); fprintf(cout, "False Positives: %d\n", falsep); fprintf(cout, "False Negatives: %d\n", falsen); fclose(m_out); fclose(n_out); fclose(p_out); copyright_destroy(copy); cvector_destroy(compare); }
EC_BOOL crouter_node_init(CROUTER_NODE *crouter_node, const UINT32 des_tcid) { CROUTER_NODE_DES_TCID(crouter_node) = des_tcid; cvector_init(CROUTER_NODE_NEXT_HOPS(crouter_node), 0, MM_TASKS_NODE, CVECTOR_LOCK_ENABLE, LOC_CROUTER_0002); return (EC_TRUE); }