/* * Parse the logmask configuration option. Verifies the listed argument * numbers, stores them in the configuration rule struct, and returns * CONFIG_SUCCESS on success and CONFIG_ERROR on error. */ static enum config_status option_logmask(struct rule *rule, char *value, const char *name, size_t lineno) { struct cvector *logmask; size_t i; long mask; logmask = cvector_split(value, ',', NULL); free(rule->logmask); rule->logmask = xcalloc(logmask->count + 1, sizeof(unsigned int)); for (i = 0; i < logmask->count; i++) { if (!convert_number(logmask->strings[i], &mask) || mask < 0) { warn("%s:%lu: invalid logmask parameter %s", name, (unsigned long) lineno, logmask->strings[i]); cvector_free(logmask); free(rule->logmask); rule->logmask = NULL; return CONFIG_ERROR; } rule->logmask[i] = (unsigned int) mask; } rule->logmask[i] = 0; cvector_free(logmask); return CONFIG_SUCCESS; }
EC_BOOL __test_ict_data_consumer_1() { UINT32 super_md_id; UINT32 obj_zone_num; UINT32 obj_zone_size; UINT32 obj_num; UINT32 obj_id; void * obj_vec; super_md_id = 0; obj_zone_size = __ICT_OBJ_ZONE_SIZE; obj_zone_num = __ICT_OBJ_ZONE_NUM; obj_num = obj_zone_num * obj_zone_size; super_set_zone_size(super_md_id, obj_zone_size); //super_print_data_all(super_md_id, obj_zone_num, LOGSTDOUT); ASSERT(obj_vec = cvector_new(super_md_id, MM_UINT32, 0)); for(obj_id = 0; obj_id < obj_num; obj_id ++) { ASSERT(EC_TRUE == super_get_data(super_md_id, obj_id, obj_vec)); sys_log(LOGCONSOLE, "__test_ict_data_consumer_1: get data from zone %lx: obj_id = %lx ==> ", __GET_ZONE_ID_FROM_OBJ_ID(obj_id, __ICT_OBJ_ZONE_SIZE), obj_id); super_print_obj_vec(super_md_id, obj_vec, LOGCONSOLE); cvector_clean(obj_vec, NULL_PTR, 0); } cvector_free(obj_vec, 0); sys_log(LOGCONSOLE, "__test_ict_data_consumer_1: done\n"); return (EC_TRUE); }
void cpool_release(cpool_t *p) { if (!p) { return; } cvector_free(&p->freelist); cpool_init(p, 0, 0); }
void coat_release(coat_t *t) { assert(t); size_t count = cvector_count(&t->table); for (int i = 0; i < count; i++) { cvector_item_t obj = cvector_get(&t->table, i); if (!obj) continue; if (t->oat_delete) { t->oat_delete(t, obj); } } cvector_free(&t->table); cpool_release(&t->pool); }
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 __test_cdfs_check_content_consumer_2() { UINT32 cdfs_md_id; void * cdfsdn_tcid_vec; cdfs_md_id = cdfs_start(CDFS_NP_MIN_NUM); ASSERT(ERR_MODULE_ID != cdfs_md_id); ASSERT(EC_TRUE == cdfs_add_npp_vec(cdfs_md_id)); cdfsdn_tcid_vec = cvector_new(0, MM_UINT32, 0); ASSERT(NULL_PTR != cdfsdn_tcid_vec); cdfs_collect_dn_tcid_vec(cdfs_md_id, cdfsdn_tcid_vec); test_case_88_cdfs_file_content_checker(cdfs_md_id, g_cdfs_cbytes_used_num, (char *)"/hansoul02"); cvector_free(cdfsdn_tcid_vec, 0); cdfs_end(cdfs_md_id); return (EC_TRUE); }
EC_BOOL __test_cdfs_read_consumer_1() { UINT32 cdfs_md_id; void * cdfsdn_tcid_vec; cdfs_md_id = cdfs_start(CDFS_NP_MIN_NUM); ASSERT(ERR_MODULE_ID != cdfs_md_id); ASSERT(EC_TRUE == cdfs_add_npp_vec(cdfs_md_id)); ASSERT(EC_TRUE == cdfs_add_dn_vec(cdfs_md_id)); cdfsdn_tcid_vec = cvector_new(0, MM_UINT32, 0); ASSERT(NULL_PTR != cdfsdn_tcid_vec); cdfs_collect_dn_tcid_vec(cdfs_md_id, cdfsdn_tcid_vec); test_case_87_cdfs_reader(cdfs_md_id, CMPI_LOCAL_TCID, g_cdfs_cbytes_used_num, (char *)"/hansoul01", cdfsdn_tcid_vec); cvector_free(cdfsdn_tcid_vec, 0); cdfs_end(cdfs_md_id); return (EC_TRUE); }
void test_case_cbgt_create_table_on_root(const UINT32 cbgt_md_id, const char *user_table_name, const int colf_num, ...) { CBYTES table_name_bytes; void *colf_vec; int pos; va_list ap; cbytes_mount(&table_name_bytes, strlen(user_table_name), (UINT8 *)user_table_name); colf_vec = cvector_new(0, MM_CBYTES, 0); va_start(ap, colf_num); for(pos = 0; pos < colf_num; pos ++) { CBYTES *colf_bytes; char *colf; colf = va_arg(ap, char *); colf_bytes = cbytes_new(0); ASSERT(NULL_PTR != colf_bytes); cbytes_mount(colf_bytes, strlen(colf), (UINT8 *)colf); cvector_push(colf_vec, colf_bytes); } va_end(ap); ASSERT(EC_TRUE == cbgt_create_table_on_root(cbgt_md_id, &table_name_bytes, colf_vec)); cvector_loop_front(colf_vec, (CVECTOR_DATA_HANDLER)cbytes_umount); cvector_clean_with_location(colf_vec, (CVECTOR_DATA_LOCATION_CLEANER)cbytes_free, 0); cvector_free(colf_vec, 0); return; }
void test_case_cbgt_delete_group_p(const UINT32 cbgt_md_id, const char *table_name, const UINT32 row_tag) { UINT32 row_idx; UINT32 colf_idx; UINT32 colq_idx; CBYTES table_name_bytes; void *mod_mgr; EC_BOOL continue_flag; ASSERT(mod_mgr = mod_mgr_new(cbgt_md_id, LOAD_BALANCING_OBJ)); mod_mgr_incl(CMPI_LOCAL_TCID, CMPI_LOCAL_COMM, CMPI_LOCAL_RANK, cbgt_md_id, mod_mgr); mod_mgr_print(LOGCONSOLE, mod_mgr); cbytes_mount(&table_name_bytes, strlen(table_name), (UINT8 *)table_name); continue_flag = EC_TRUE; for(row_idx = 0; row_idx < CBGT_TEST_ROW_NUM && EC_TRUE == continue_flag; row_idx ++) { char *row; CBYTES *row_bytes; ASSERT(row = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(row, CBGT_STR_MAX_LEN, "row-%08ld-%08ld", row_tag, row_idx); ASSERT(row_bytes = cbytes_new(0)); cbytes_mount(row_bytes , strlen(row) , (UINT8 *)row ); //cvector_push(bytes_vec, (void *)row_bytes); for(colf_idx = 0; colf_idx < CBGT_TEST_COLF_NUM && EC_TRUE == continue_flag; colf_idx ++) { char *colf; CBYTES *colf_bytes; void *task_mgr; void *bytes_vec; EC_BOOL ret[CBGT_TEST_COLQ_NUM]; ASSERT(bytes_vec = cvector_new(0, MM_CBYTES, 0)); ASSERT(colf = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colf, CBGT_STR_MAX_LEN, "colf-%ld", colf_idx); ASSERT(colf_bytes = cbytes_new(0)); cbytes_mount(colf_bytes , strlen(colf) , (UINT8 *)colf ); task_mgr = task_new(mod_mgr, TASK_PRIO_NORMAL, TASK_NEED_RSP_FLAG, TASK_NEED_ALL_RSP); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM && EC_TRUE == continue_flag; colq_idx ++) { char *colq; CBYTES *colq_bytes; ASSERT(colq = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colq, CBGT_STR_MAX_LEN, "colq-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); ASSERT(colq_bytes = cbytes_new(0)); cbytes_mount(colq_bytes , strlen(colq) , (UINT8 *)colq ); cvector_push(bytes_vec, (void *)colq_bytes); ret[ colq_idx ] = EC_FALSE; task_inc(task_mgr, &(ret[ colq_idx ]), FI_cbgt_delete, ERR_MODULE_ID, &table_name_bytes, row_bytes, colf_bytes, colq_bytes); } task_wait(task_mgr, TASK_DEFAULT_LIVE, TASK_NEED_RESCHEDULE_FLAG, NULL_PTR); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM; colq_idx ++) { if(EC_TRUE == ret[ colq_idx ]) { sys_log(LOGSTDNULL, "[DEBUG] test_case_cbgt_delete_group_p: [SUCC] delete %s %s:%s:colq-%08ld-%08ld-%08ld\n", table_name, row, colf, row_idx, colf_idx, colq_idx); } else { //continue_flag = EC_FALSE; sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [FAIL] delete %s %s:%s:colq-%08ld-%08ld-%08ld\n", table_name, row, colf, row_idx, colf_idx, colq_idx); } } cbytes_free(colf_bytes, 0); cvector_clean_with_location(bytes_vec, (CVECTOR_DATA_LOCATION_CLEANER)cbytes_free, 0); cvector_free(bytes_vec, 0); } cbytes_free(row_bytes, 0); if(EC_TRUE == continue_flag) { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [SUCC] row tag %ld, row no. %ld\n", row_tag, row_idx); } else { sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: [FAIL] row tag %ld, row no. %ld\n", row_tag, row_idx); } } sys_log(LOGCONSOLE, "[DEBUG] test_case_cbgt_delete_group_p: row tag %ld end\n", row_tag); return; }
void test_case_cbgt_insert_group(const UINT32 cbgt_md_id, const char *table_name) { UINT32 row_idx; UINT32 colf_idx; UINT32 colq_idx; CBYTES table_name_bytes; void *bytes_vec; cbytes_mount(&table_name_bytes, strlen(table_name), (UINT8 *)table_name); ASSERT(bytes_vec = cvector_new(0, MM_CBYTES, 0)); for(row_idx = 0; row_idx < CBGT_TEST_ROW_NUM; row_idx ++) { char *row; CBYTES *row_bytes; ASSERT(row = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(row, CBGT_STR_MAX_LEN, "row-%08ld", row_idx); ASSERT(row_bytes = cbytes_new(0)); cbytes_mount(row_bytes , strlen(row) , (UINT8 *)row ); cvector_push(bytes_vec, (void *)row_bytes); for(colf_idx = 0; colf_idx < CBGT_TEST_COLF_NUM; colf_idx ++) { char *colf; CBYTES *colf_bytes; ASSERT(colf = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colf, CBGT_STR_MAX_LEN, "colf-%ld", colf_idx); ASSERT(colf_bytes = cbytes_new(0)); cbytes_mount(colf_bytes , strlen(colf) , (UINT8 *)colf ); cvector_push(bytes_vec, (void *)colf_bytes); for(colq_idx = 0; colq_idx < CBGT_TEST_COLQ_NUM; colq_idx ++) { char *colq; CBYTES *colq_bytes; char *val; CBYTES *val_bytes; ASSERT(colq = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(colq, CBGT_STR_MAX_LEN, "colq-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); ASSERT(val = (char *)safe_malloc(CBGT_STR_MAX_LEN, 0)); snprintf(val, CBGT_STR_MAX_LEN, "val-%08ld-%08ld-%08ld", row_idx, colf_idx, colq_idx); ASSERT(colq_bytes = cbytes_new(0)); ASSERT(val_bytes = cbytes_new(0)); cbytes_mount(colq_bytes , strlen(colq) , (UINT8 *)colq ); cbytes_mount(val_bytes , strlen(val) , (UINT8 *)val ); cvector_push(bytes_vec, (void *)colq_bytes); cvector_push(bytes_vec, (void *)val_bytes); //sys_log(LOGCONSOLE, "test_case_cbgt_insert_group: [TRY ] insert %s %s:%s:%s %s\n", table_name, row, colf, colq, val); ASSERT(EC_TRUE == cbgt_insert(cbgt_md_id, &table_name_bytes, row_bytes, colf_bytes, colq_bytes, val_bytes)); sys_log(LOGCONSOLE, "test_case_cbgt_insert_group: [SUCC] insert %s %s:%s:%s %s\n", table_name, row, colf, colq, val); } } } cvector_clean_with_location(bytes_vec, (CVECTOR_DATA_LOCATION_CLEANER)cbytes_free, 0); cvector_free(bytes_vec, 0); sys_log(LOGCONSOLE, "test_case_cbgt_insert_group: end\n"); return; }