void test_mb_res_pool_consistent(void) { mb_res_pool_cell_t *cell; mb_res_pool_t *pool; void *ptr[64]; int i; pool = mb_res_pool_make(64); mb_assert_res_pool_valid(pool); // populate data for(i = 0; i < 64; i++) { ptr[0] = (void *) cut_take_memory(malloc(16)); mb_res_pool_push(pool, ptr[0]); mb_assert_will_not_free(ptr[0]); } mb_assert_res_pool_valid(pool); ptr[0] = mb_res_pool_pop(pool); mb_res_pool_push(pool, ptr[0]); mb_assert_res_pool_valid(pool); ptr[0] = mb_res_pool_pop(pool); ptr[1] = mb_res_pool_pop(pool); mb_res_pool_push(pool, ptr[0]); mb_res_pool_push(pool, ptr[1]); mb_assert_res_pool_valid(pool); mb_res_pool_destroy(pool); }
void test_mb_res_pool_push_and_pop(void) { int i; struct iocb *iocb; cbpool = mb_res_pool_make(64); for(i = 0; i < 64; i++) { iocb = malloc(sizeof(struct iocb)); cut_assert_equal_int(i, cbpool->nr_avail); cut_assert_equal_int(0, mb_res_pool_push(cbpool, iocb)); } cut_assert_equal_int(64, cbpool->nr_avail); iocb = malloc(sizeof(struct iocb)); // pushing into full pool fails cut_take_memory(iocb); cut_assert_equal_int(-1, mb_res_pool_push(cbpool, iocb)); for(i = 0; i < 64; i++) { iocb = mb_res_pool_pop(cbpool); cut_assert_not_null(iocb); cut_assert_equal_int(64 - i - 1, cbpool->nr_avail, cut_message("poped %d iocbs", i+1)); } // now the pool is empty and pop fails iocb = mb_res_pool_pop(cbpool); cut_assert_null(iocb); }
void test_mb_res_pool_destroy(void) { mb_res_pool_cell_t *cell; mb_res_pool_t *pool; void *ptr; int i; pool = mb_res_pool_make(64); cell = pool->ring; // populate some data for(i = 0; i < 8; i++) { ptr = (void *) cut_take_memory(malloc(16)); mb_res_pool_push(pool, ptr); mb_assert_will_not_free(ptr); } mb_assert_will_free(pool); mb_assert_will_free(pool->ring); cell = pool->ring->next; for(; cell != pool->ring; cell = cell->next) { mb_assert_will_free(cell); } mb_res_pool_destroy(pool); }
void test_change_unix_socket_group (void) { const gchar *path; struct stat stat_buffer; gint i, n_groups, max_n_groups; gid_t *groups; struct group *group = NULL; GError *error = NULL; path = cut_take_printf("%s/milter.sock", tmp_dir); spec = cut_take_printf("unix:%s", path); max_n_groups = getgroups(0, NULL); if (max_n_groups < 0) max_n_groups = 5; groups = g_new0(gid_t, max_n_groups); cut_take_memory(groups); n_groups = getgroups(max_n_groups, groups); if (n_groups == -1) cut_assert_errno(); for (i = 0; i < n_groups; i++) { if (groups[i] == getegid()) continue; errno = 0; group = getgrgid(groups[i]); if (!group) { if (errno == 0) cut_omit("can't find supplementary group: %u", groups[i]); else cut_assert_errno(); } } if (!group) cut_omit("no supplementary group"); milter_client_set_default_unix_socket_group(client, group->gr_name); milter_client_set_default_remove_unix_socket_on_close(client, FALSE); cut_trace(setup_client()); milter_client_run(client, &error); gcut_assert_error(error); if (stat(path, &stat_buffer) == -1) cut_assert_errno(); cut_assert_equal_uint(group->gr_gid, stat_buffer.st_gid); }
static void __mb_assert_will_not_free(const char *fname, int lineno, const char *exp, void *ptr, ...) { will_free_cell_t *cell = malloc(sizeof(will_free_cell_t)); cut_take_memory(cell); cell->ptr = ptr; cell->exp = exp; cell->fname = fname; cell->lineno = lineno; will_not_free_list = g_list_append(will_not_free_list, cell); }
int io_setup(int nr_events, io_context_t *ctxp) { mb_mock_check("io_setup", nr_events, ctxp); int (*io_setup_org)(int, io_context_t *) = (int(*)(int, io_context_t *))dlsym(RTLD_NEXT, "io_setup"); pseudo_io_queue = malloc(sizeof(struct iocb *) * nr_events); cut_take_memory(pseudo_io_queue); pseudo_io_queue_len = 0; bzero(pseudo_io_queue, sizeof(struct iocb *) * nr_events); return io_setup_org(nr_events, ctxp); }
static grn_obj * construct_elements(gconstpointer data) { const int n_of_elements = 3; grn_obj *elements; const gchar *type_name; elements = g_new0(grn_obj, n_of_elements); type_name = gcut_data_get_string(data, "type_name"); #define SET_VALUE(index, name) \ if (g_str_equal(type_name, "Int32")) { \ GRN_INT32_INIT(&elements[index], 0); \ GRN_INT32_SET(context, &elements[index], \ gcut_data_get_int(data, name)); \ } if (g_str_equal(type_name, "Float")) { \ GRN_FLOAT_INIT(&elements[index], 0); \ GRN_FLOAT_SET(context, &elements[index], \ gcut_data_get_double(data, name)); \ } if (g_str_equal(type_name, "Bool")) { \ GRN_BOOL_INIT(&elements[index], 0); \ GRN_BOOL_SET(context, &elements[index], \ gcut_data_get_boolean(data, name)); \ } if (g_str_equal(type_name, "Text")) { \ GRN_TEXT_INIT(&elements[index], 0); \ GRN_TEXT_SETS(context, &elements[index], \ gcut_data_get_string(data, name)); \ } SET_VALUE(0, "first_element"); SET_VALUE(1, "second_element"); SET_VALUE(2, "third_element"); #undef SET_VALUE cut_take_memory(elements); return elements; }