END_TEST START_TEST (check_tbchain_iterate) { int i; double begin = test_time(); fs_tbchain *bc = fs_tbchain_open_filename("./tmp/check_test.tbchain",O_RDWR | O_CREAT | O_TRUNC); fail_if(bc == NULL); fs_index_node b = fs_tbchain_new_chain(bc); fail_if(fs_tbchain_length(bc, b) != 0); fs_rid search[3] = {FS_RID_NULL, FS_RID_NULL, FS_RID_NULL}; fs_tbchain_it *it = fs_tbchain_new_iterator(bc, FS_RID_NULL, b); int count = 0; while (fs_tbchain_it_next(it, search) > 0) { fail_if(b == 1); fail_if(1 == 1); count ++; } fail_if(count !=0 ); fs_tbchain_it_free(it); fs_rid triple[3]; triple[0] = 0xABC; triple[1] = 0xABC; triple[2] = 0xABC; b = fs_tbchain_add_triple(bc, b, triple); fail_if(fs_tbchain_length(bc, b) != 1); it = fs_tbchain_new_iterator(bc, FS_RID_NULL, b); count = 0; while (fs_tbchain_it_next(it, search) > 0) { fail_if(b == 1); fail_if(search[0] != 0xABC && search[1] != 0xABC && search[2] != 0xABC); count ++; } fail_if(count != 1); fs_tbchain_it_free(it); fs_index_node c = fs_tbchain_new_chain(bc); fs_index_node d = fs_tbchain_new_chain(bc); int dcount=0, ccount =0, bcount =1; for(i=1; i < 10000; i++) { triple[0] = i; triple[1] = i;triple[2] = i + 777; b = fs_tbchain_add_triple(bc, b, triple); bcount += 1; if (c<2) fail_if(1==1); if ((i % 7 == 0) && (i % 5 ==0)) { c = fs_tbchain_add_triple(bc, c, triple); ccount += 1; } if ((i % 7 == 0) || (i % 5 ==0)) { d = fs_tbchain_add_triple(bc, d, triple); dcount += 1; } } it = fs_tbchain_new_iterator(bc, FS_RID_NULL, c); count = 0; while (i>0) { i = fs_tbchain_it_next(it, search); if (i != 1) { fail_if(search[0] != FS_RID_NULL || search[1] != FS_RID_NULL || search[2] != FS_RID_NULL); break; } ccount -= 1; int j=0; int test = 0; for (j=0;j<2 && !test;j++) test = (search[j] % 7 == 0) && (search[j] % 5 == 0); fail_if(test != 1); fail_if(search[2] - 777 != search[1]); } fail_if(ccount != 0); fs_tbchain_it_free(it); it = fs_tbchain_new_iterator(bc, FS_RID_NULL, d); count = 0; i = 1; while (i>0) { i = fs_tbchain_it_next(it, search); if (i != 1) { fail_if(search[0] != FS_RID_NULL || search[1] != FS_RID_NULL || search[2] != FS_RID_NULL); break; } dcount -= 1; int j=0; int test = 0; for (j=0;j<2 && !test;j++) test = (search[j] % 7 == 0) || (search[j] % 5 == 0); fail_if(test != 1); fail_if(search[2] - 777 != search[1]); } fail_if(dcount != 0); fs_tbchain_it_free(it); it = fs_tbchain_new_iterator(bc, FS_RID_NULL, b); count = 0; i = 1; while (i>0) { i = fs_tbchain_it_next(it, search); if (i != 1) { fail_if(search[0] != FS_RID_NULL || search[1] != FS_RID_NULL || search[2] != FS_RID_NULL); break; } bcount -= 1; if (search[0] != 0xABC && bcount > 0) fail_if(search[2] - 777 != search[1]); } fail_if(bcount != 0); fs_tbchain_it_free(it); fs_tbchain_close(bc); TIME(ts_timing_report); double end = test_time(); printf("TIMES: check_tbchain_create %.4f\n", (end - begin)); }
int main(int argc, char **argv) { pipeline_t *pl; char line[1024]; int n; int i; int stages; pipeline_stage_process_pf *stages_proc; int max_random; struct timeval start; struct timeval end; int start_num = 0; stages = atoi(argv[1]); max_random = atoi(argv[2]); if (argc == 4) { start_num = atoi(argv[3]); if (start_num <= 0) { printf(" usage: test_pipeline <stage_num> <max_random> [start_num]\n"); return 1; } } if (stages<1 || max_random<1) { printf(" usage: test_pipeline <stage_num> <max_random> [start_num]\n"); return 1; } stages_proc = malloc(stages * sizeof(pipeline_stage_process_pf)); for (i = 0; i < stages-1; ++i) stages_proc[i] = _stage; stages_proc[stages-1] = _stage_tail; pl = pipeline_create(stages, stages_proc); free(stages_proc); if (start_num == 0) printf("input an integer, and end with a command named 'q'\n"); while (1) { if (start_num == 0) { printf("data> "); if (fgets(line, sizeof(line), stdin) == NULL) break; line[strlen(line)-1] = 0; if (strcmp(line, "q") == 0) break; if (sscanf(line, "%d", &n) != 1) { printf("please input valid integer\n"); continue; } } // int num = random() % max_random; g_random_count += max_random; gettimeofday(&start, NULL); for (i = max_random; i > 0; --i) pipeline_start(pl, (void *) (long) (n + i)); pipeline_wait(pl, 0); gettimeofday(&end, NULL); test_time("pipeline", &start, &end); if (start_num != 0) break; } printf("\n\n---------------count is: %d[%d]\n\n", g_count, g_random_count); assert(g_count == g_random_count); pipeline_wait(pl, 1); pipeline_destroy(pl); return EXIT_SUCCESS; }