static void test_merge_split(CuTest *tc) { message_list *mlist = 0, *append = 0; struct mlist **split; /* TODO: why is this a double asterisk? */ message_type *mtype; message *msg; test_setup(); mtype = mt_create(mt_new("custom", NULL), NULL, 0); add_message(&mlist, msg = msg_message(mtype->name, "")); msg_release(msg); add_message(&append, msg = msg_message(mtype->name, "")); msg_release(msg); CuAssertPtrEquals(tc, NULL, mlist->begin->next); CuAssertPtrEquals(tc, &mlist->begin->next, mlist->end); split = merge_messages(mlist, append); CuAssertPtrNotNull(tc, split); CuAssertPtrEquals(tc, &mlist->begin->next, split); CuAssertPtrEquals(tc, append->end, mlist->end); CuAssertPtrNotNull(tc, mlist->begin->next); CuAssertPtrEquals(tc, append->begin, mlist->begin->next); split_messages(mlist, split); CuAssertPtrEquals(tc, NULL, mlist->begin->next); free_messagelist(*split); free_messagelist(mlist->begin); free(mlist); free_messagelist(append->begin); free(append); test_teardown(); }
SOS() { readyq = new_dllist(); mt_init(); writeok = mt_sem_create(0); writers = mt_sem_create(1); readers = mt_sem_create(1); nelem = mt_sem_create(0); consoleWait = mt_sem_create(0); wr_iobuf = make_io_buffer(1); cr_iobuf = make_io_buffer(256); crb_no_chars = 0; crb_end = 0; crb_begin = 0; curpid = -1; // pids = make_rb(); init_partitions(); DEBUG('e', "pagesize: %d\n", PageSize); jrbTree = make_jrb(); // Step 20 init = new_pcb(); // Step 22 init->pid = get_new_pid(); // Step 22 cread_vnode = new_vnode(); cread_vnode->iobuf =cr_iobuf; cr_iobuf->nwriters = 1; cwrite_vnode = new_vnode(); cwrite_vnode->iobuf = wr_iobuf; wr_iobuf->nreaders = 1; start_timer(10); bzero(main_memory, MemorySize); mt_create(read_console_io, (void *)cr_iobuf); mt_create(write_console_io, (void *)wr_iobuf); //mt_create(read_console, NULL); mt_create(initialize_user_process, (void *)Argv); schedule(); }
PROTOTYPES int main() { t_mt *mt = mt_create("ft_printf"); setbuf(stdout, NULL); setlocale(LC_ALL, "en_US.UTF-8"); ADD_TESTS mt_exec(mt); return(0); }
void test_message(CuTest *tc) { message *msg; message_type *mtype; test_setup(); mtype = mt_create(mt_new("custom", NULL), NULL, 0); CuAssertPtrEquals(tc, mtype, (void *)mt_find("custom")); CuAssertIntEquals(tc, 0, mtype->nparameters); CuAssertPtrEquals(tc, NULL, (void *)mtype->pnames); CuAssertPtrEquals(tc, NULL, (void *)mtype->types); msg = msg_message("custom", ""); CuAssertPtrNotNull(tc, msg); CuAssertIntEquals(tc, 1, msg->refcount); CuAssertPtrEquals(tc, NULL, msg->parameters); CuAssertPtrEquals(tc, mtype, (void *)msg->type); CuAssertPtrEquals(tc, msg, msg_addref(msg)); CuAssertIntEquals(tc, 2, msg->refcount); msg_release(msg); CuAssertIntEquals(tc, 1, msg->refcount); msg_release(msg); test_teardown(); }
module_t *module_open(const char *file, module_manager_t *manager, string_t **error) { char *function = NULL; if (!module_allow(file, &function)) { *error = string_construct(); string_catf(*error, "%s blacklisted", function); free(function); return NULL; } module_t *module = malloc(sizeof(*module)); if (!(module->handle = dlopen(file, RTLD_LAZY))) { free(module); *error = string_create(dlerror()); return NULL; } module->file = strdup(file); module->instance = manager->instance; if (!module_load(module)) { if (!module) return NULL; if (module->handle) dlclose(module->handle); free(module->file); free(module); return NULL; } module->random = mt_create(); list_push(manager->modules, module); return module; }
bool module_reload(module_t *module, module_manager_t *manager) { if (module->close) module->close(module->instance); dlclose(module->handle); /* Save old address for unloaded module */ list_push(manager->unloaded, module->handle); if (!(module->handle = dlopen(module->file, RTLD_LAZY))) goto module_reload_error; if (!module_load(module)) goto module_reload_error; /* Reload the PRNG as well */ mt_destroy(module->random); module->random = mt_create(); return true; module_reload_error: module_close(module, manager); return false; }