static void check_tree (TREENODE t, int size) { if (size==1) { Assert(t->children[0]==NULL); Assert(t->children[1]==NULL); } else { check_tree(t->children[0], size/2); check_tree(t->children[1], size/2); } }
int test_ptrace1(int idx, struct bproc_test_info_t *info) { int i; long val; static volatile long magicflag = 0x32124312; if (idx == 0) { setvbuf(stdout, 0, _IONBF, 0); /* fflush every time is ugly */ /* Parent process */ for (i=1; i < info->nprocs; i++) { if (ptrace(PTRACE_ATTACH, info->pid[i])) { perror("ptrace"); exit(1); } printf(" A"); info->scratch |= (1 << i); wait_on_child1(info, i, 0); /* wait for the stop */ printf(" S"); val = ptrace(PTRACE_PEEKDATA, info->pid[i], &magicflag); if (val != magicflag) { fprintf(stderr, "PE: expected 0x%lx; got 0x%lx\n", magicflag, val); } printf(" PE"); if (ptrace(PTRACE_POKEDATA, info->pid[i], &magicflag, 0)) { perror("ptrace(pokedata)"); } printf(" PO"); wait_data_check(info, -1); if (ptrace(PTRACE_DETACH, info->pid[i], 0, 0)) { perror("ptrace(detach)"); } printf(" D"); info->scratch &= ~(1 << i); if (proc_isattach(proc_arr(info->arr,i))) { wait_on_child1(info, i, WAIT_WANTEXIT); printf(" W"); } } return 0; } else { /* child process */ check_tree(); while (magicflag) { usleep(100000); } check_tree(); exit(WAIT_EXITSTATUS); } }
static int check_tree(struct memtree *tree) { if (tree == NULL) return (0); int i; i = check_list(tree->allocated); i += check_list(tree->freed); i += check_tree(tree->lesser); i += check_tree(tree->greater); return (i); }
int main(int argc, char *argv[]) { int do_insert = 0; int from = -1, to = -1; expensive_checking = True; // we always want this here const char *file = NULL; for (int i=1; argv[i]; ++i) { if (strcmp(argv[i], "-v") == 0) { verbose = 1; } else if (strcmp(argv[i], "-n") == 0) { // no post processing nopost = 1; } else if (strcmp(argv[i], "--no-post") == 0) { // no post processing nopost = 1; } else if (strcmp(argv[i], "--no-rot") == 0) { // no rotate norotate = 1; } else if (strcmp(argv[i], "-i") == 0) { ++i; assert(argv[i]); do_insert = 1; int n = sscanf(argv[i], "%d:%d", &from, &to); assert(n == 2); } else { assert(file == NULL); file = argv[i]; } } assert(file); NSegment *tree = read_file(file); check_tree(tree); // Write out the tree prior to inserting something // write_dot(tree, NULL, NULL, file); /* insert a segment */ if (do_insert) { NSegment *subtree = locate_subtree_containing(root_segment(), from, to); NSegment *inserted = insert_node(from, to); check_tree(root_segment()); char buf[strlen(file) + 40]; // large enough sprintf(buf, "%s-i%d:%d", file, from, to); write_dot(root_segment(), subtree, inserted, buf); } return 0; }
/* * Test node removal: p = power_product to remove */ static void test_remove(rba_buffer_t *b, pprod_t *p) { uint32_t i, j; bool new_node; if (p == empty_pp) { printf("test remove: empty product\n"); } else { printf("test remove: x%"PRId32"\n", var_of_pp(p)); } i = rba_find_node(b, p); if (i != 0) { q_clear(&b->mono[i].coeff); // get_node must be called first to setup b->stack j = rba_get_node(b, p, &new_node); if (j != i && new_node) { printf("Error in test_removed: get_node failed\n"); fflush(stdout); exit(1); } rba_delete_node(b, i); j = rba_find_node(b, p); if (j != 0) { printf("Error in test_remove: removal failed\n"); fflush(stdout); exit(1); } check_tree(b); } }
void check_tree( struct seg_tree_2d_t *tr, int depth, int lower, int upper ) { if( tr->left == NULL ) { printf("Tree Empty\n"); return; } if( tr->key < lower || tr->key >= upper ) printf("Wrong Key Order \n"); if( tr->right == NULL ) { if( *( (int *) tr->left) == 42 ) printf("%d(%d) ", tr->key, depth ); else printf("Wrong Object \n"); } else { check_tree(tr->left, depth+1, lower, tr->key ); check_tree(tr->right, depth+1, tr->key, upper ); } }
static void check_tree (ipa_reference_local_vars_info_t local, tree t, bool checking_write) { if ((TREE_CODE (t) == EXC_PTR_EXPR) || (TREE_CODE (t) == FILTER_EXPR)) return; while (TREE_CODE (t) == REALPART_EXPR || TREE_CODE (t) == IMAGPART_EXPR || handled_component_p (t)) { if (TREE_CODE (t) == ARRAY_REF) check_operand (local, TREE_OPERAND (t, 1), false); t = TREE_OPERAND (t, 0); } /* The bottom of an indirect reference can only be read, not written. So just recurse and whatever we find, check it against the read bitmaps. */ /* if (INDIRECT_REF_P (t) || TREE_CODE (t) == MEM_REF) */ /* FIXME when we have array_ref's of pointers. */ if (INDIRECT_REF_P (t)) check_tree (local, TREE_OPERAND (t, 0), false); if (SSA_VAR_P (t)) check_operand (local, t, checking_write); }
int main() //@ : main //@ requires true; //@ ensures true; { struct tree *t; bool b; struct list *l = create_list(); list_push(l, 2); list_push(l, 3); list_push(l, 3); list_push(l, 1); //@ note(nat_of_int(3) == succ(succ(succ(zero)))); b = build(l, &t); assert(b); char *result = check_tree(t, "NLNNLLL"); assert(result != 0); list_dispose(l); l = create_list(); list_push(l, 2); list_push(l, 2); list_push(l, 3); list_push(l, 1); b = build(l, &t); assert(!b); list_dispose(l); return 0; }
void check_memory_state(void) { t_sysfree sysfree = free; /* (t_sysfree)dlsym(RTLD_NEXT, "free"); */ if (memory_check == 0) { sysfree(memory_head()); return ; } struct memhead *head; int i; head = memory_head(); fprintf(stderr, "Call to malloc: %lu\n", head->alloc_count); fprintf(stderr, "Sum of all byte requested: %lu\n", head->total_count); fprintf(stderr, "Allocated chunks at the end of the program: %lu\n", head->alloc); fprintf(stderr, "Allocated bytes at the end of the program: %lu\n", head->total); i = check_tree(head->first); fprintf(stderr, "Altered chunks: %d\n", i); sysfree(memory_head()); if (i) { kill(getpid(), SIGSEGV); sleep(2); exit(EXIT_FAILURE); } }
int test_ptrace3(int idx, struct bproc_test_info_t *info) { int i; if (idx == 0) { /* Parent process */ setvbuf(stdout, 0, _IONBF, 0); /* fflush every time is ugly */ for (i=1; i < info->nprocs; i++) { info->scratch |= (1 << i); /* Due to traceme below... ?? */ wait_on_child1(info, i, 0); printf(" S"); if (ptrace(PTRACE_DETACH, info->pid[i], 0, 0)) { perror("ptrace(detach)"); } printf(" D"); info->scratch &= ~(1 << i); wait_on_child1(info, i, WAIT_WANTEXIT|WAIT_EXITZERO); printf(" W"); } return 0; } else { if (ptrace(PTRACE_TRACEME)) { perror("ptrace"); exit(1); } check_tree(); execl("/tmp/pt3", "/tmp/pt3", 0); perror("/tmp/pt3"); exit(1); /* wake up and exit */ } }
// Peform the AST passes on the given AST up to the speficied last pass static bool ast_passes(ast_t** astp, pass_opt_t* options, pass_id last) { assert(astp != NULL); bool r; if(!visit_pass(astp, options, last, &r, PASS_SUGAR, pass_sugar, NULL)) return r; if(options->check_tree) check_tree(*astp, options->check.errors); if(!visit_pass(astp, options, last, &r, PASS_SCOPE, pass_scope, NULL)) return r; if(!visit_pass(astp, options, last, &r, PASS_IMPORT, pass_import, NULL)) return r; if(!visit_pass(astp, options, last, &r, PASS_NAME_RESOLUTION, NULL, pass_names)) return r; if(!visit_pass(astp, options, last, &r, PASS_FLATTEN, NULL, pass_flatten)) return r; if(!visit_pass(astp, options, last, &r, PASS_TRAITS, pass_traits, NULL)) return r; if(!check_limit(astp, options, PASS_DOCS, last)) return true; if(options->docs && ast_id(*astp) == TK_PROGRAM) generate_docs(*astp, options); if(!visit_pass(astp, options, last, &r, PASS_EXPR, pass_pre_expr, pass_expr)) return r; if(!check_limit(astp, options, PASS_FINALISER, last)) return true; if(!pass_finalisers(*astp, options)) return false; if(options->check_tree) check_tree(*astp, options->check.errors); return true; }
static void check_lhs_var (ipa_reference_local_vars_info_t local, tree t) { if (local == NULL) return; check_tree(local, t, true); }
static void aobf_link_free_block(Allctr_t *allctr, Block_t *block) { BFAllctr_t *bfallctr = (BFAllctr_t *) allctr; RBTree_t **root = &bfallctr->mbc_root; RBTree_t *blk = (RBTree_t *) block; Uint blk_sz = BF_BLK_SZ(blk); blk->flags = 0; blk->left = NULL; blk->right = NULL; if (!*root) { blk->parent = NULL; SET_BLACK(blk); *root = blk; } else { RBTree_t *x = *root; while (1) { Uint size; size = BF_BLK_SZ(x); if (blk_sz < size || (blk_sz == size && blk < x)) { if (!x->left) { blk->parent = x; x->left = blk; break; } x = x->left; } else { if (!x->right) { blk->parent = x; x->right = blk; break; } x = x->right; } } /* Insert block into size tree */ RBT_ASSERT(blk->parent); SET_RED(blk); if (IS_RED(blk->parent)) tree_insert_fixup(root, blk); } #ifdef HARD_DEBUG check_tree(root, 1, 0); #endif }
void check_tree(text_t *tr, int depth, int lower, int upper) { if (tr->left == NULL) { printf("Tree Empty\n"); return; } if (tr->key < lower || tr->key >= upper) printf("Wrong Key Order \n"); if (tr->right == NULL) { char *ptr = ((char *) tr->left); while (*ptr) printf("%c", *(ptr)++); printf("%d(%d) ", tr->key, depth); } else { check_tree(tr->left, depth + 1, lower, tr->key); check_tree(tr->right, depth + 1, tr->key, upper); } }
static void check_rhs_var (ipa_reference_local_vars_info_t local, tree t) { look_for_address_of (t); if (local == NULL) return; check_tree(local, t, false); }
static void check_lhs_var (funct_state local, tree t) { /* Memcmp and strlen can both trap and they are declared pure. Which seems to imply that we can apply the same rule here. */ if (tree_could_trap_p (t) && local->pure_const_state == IPA_CONST) local->pure_const_state = IPA_PURE; check_tree(local, t, true); }
int test_btree(string **values, int n){ int i; btree *tree = make_btree(); uint64_t *hashes = xmalloc(n*sizeof(uint64_t)); uint64_t *indices = xmalloc(n*sizeof(uint64_t)); //nfor now I'm just using sequential ints for keys DEBUG_PRINTF("Testing btree insertion\n"); for(i=0;i<n;i++){ assert(check_tree(tree) >= 0); indices[i] = i; hashes[i] = fnv_hash(values[i]->mem, values[i]->len); btree_insert(tree, hashes[indices[i]], values[i]); } assert(check_tree(tree) >= 0); shuffle_array((void**)indices, n); DEBUG_PRINTF("Testing btree lookup\n"); for(i=0;i<n;i++){ string *str = btree_lookup(tree, hashes[indices[i]]); WARN_ON_ONCE(!string_ptr_eq(str, values[indices[i]])); } DEBUG_PRINTF("Testing btree deletion\n"); for(i=0;i<n;i++){ uint64_t num_keys = count_num_keys(tree->root); if(num_keys != (n-i)){ DEBUG_PRINTF("Tree has %lu keys, expected %lu\n", num_keys, n-i); exit(1); } assert(check_tree(tree) >= 0); if(btree_lookup(tree, hashes[indices[i]])){ if(!btree_delete(tree, hashes[indices[i]])){ exit(1); } } else { DEBUG_PRINTF("Couldn't find key %lu\n",indices[i]); } } WARN_ON(check_tree(tree) < 0); WARN_ON(tree->root->n_keys != 0); return 0; }
void check_tree( tree_node_t *tr, int depth, int lower, int upper ) { if ( tr->left == NULL ) { printf("Tree Empty\n"); return; } if ( tr->key < lower || tr->key >= upper ) printf("Wrong Key Order \n"); if ( tr->right == NULL ) { if( *((int *) tr->left) == 10*tr->key + 2 ) printf("%d (%d) (%d,%d) ", tr->key, depth,tr->left_leaves,tr->right_leaves ); else printf("Wrong Object \n"); } else { check_tree(tr->left, depth+1, lower, tr->key ); check_tree(tr->right, depth+1, tr->key, upper ); } }
void kd_tree::check_tree(int where){ int i; if(where<0)where=masterparent; //printf("checking %d %d %d %d\n",where,tree[where][1],tree[where][2],tree[where][0]); if(tree[where][1]>-1)confirm(tree[where][0],where,1,tree[where][1]); //printf("confirmed 1\n"); if(tree[where][2]>-1)confirm(tree[where][0],where,2,tree[where][2]); //printf("confirmed 2\n"); if(tree[where][1]>-1)check_tree(tree[where][1]); if(tree[where][2]>-1)check_tree(tree[where][2]); }
static void check_rhs_var (funct_state local, tree t) { look_for_address_of (local, t); /* Memcmp and strlen can both trap and they are declared pure. */ if (tree_could_trap_p (t) && local->pure_const_state == IPA_CONST) local->pure_const_state = IPA_PURE; check_tree(local, t, false); }
int test_wait2(int idx, struct bproc_test_info_t *info) { if (idx == 0) { /* Parent process */ int i; for (i=1; i < info->nprocs; i++) wait_on_child1(info, -1, WAIT_WANTEXIT); return 0; } else { /* One of the children */ check_tree(); exit(WAIT_EXITSTATUS); } }
static void add_to_heap(sel_timer_t **top, sel_timer_t **last, sel_timer_t *elem) { sel_timer_t **next; sel_timer_t *parent; #ifdef MASSIVE_DEBUG fprintf(*debug_out, "add_to_heap entry\n"); print_tree(*top, *last); check_tree(*top, *last); #endif elem->left = NULL; elem->right = NULL; elem->up = NULL; if (*top == NULL) { *top = elem; *last = elem; goto out; } find_next_pos(*last, &next, &parent); *next = elem; elem->up = parent; *last = elem; if (cmp_timeval(&elem->timeout, &parent->timeout) < 0) { send_up(elem, top, last); } out: #ifdef MASSIVE_DEBUG fprintf(*debug_out, "add_to_heap exit\n"); print_tree(*top, *last); check_tree(*top, *last); #endif return; }
static ERTS_INLINE void bf_unlink_free_block(Allctr_t *allctr, Block_t *block) { BFAllctr_t *bfallctr = (BFAllctr_t *) allctr; RBTree_t **root = &bfallctr->mbc_root; RBTree_t *x = (RBTree_t *) block; if (IS_LIST_ELEM(x)) { /* Remove from list */ ASSERT(LIST_PREV(x)); LIST_NEXT(LIST_PREV(x)) = LIST_NEXT(x); if (LIST_NEXT(x)) LIST_PREV(LIST_NEXT(x)) = LIST_PREV(x); } else if (LIST_NEXT(x)) { /* Replace tree node by next element in list... */ ASSERT(BF_BLK_SZ(LIST_NEXT(x)) == BF_BLK_SZ(x)); ASSERT(IS_TREE_NODE(x)); ASSERT(IS_LIST_ELEM(LIST_NEXT(x))); #ifdef HARD_DEBUG check_tree(root, 0, 0); #endif replace(root, x, LIST_NEXT(x)); #ifdef HARD_DEBUG check_tree(bfallctr, 0); #endif } else { /* Remove from tree */ tree_delete(allctr, block); } DESTROY_LIST_ELEM(x); }
int check_tree(IndexTreeNode *root_node) { char buffer[256]; if (!root_node) return 1; if (root_node->left_node) { if (root_node->left_node->parent_node != root_node) { SLPDLog("Invalid parent link in %p - parent is %p - should be %p\n", root_node->left_node, root_node->left_node->parent_node, root_node); return 0; } } if (!check_tree(root_node->left_node)) return 0; if (root_node->right_node) { if (root_node->right_node->parent_node != root_node) { SLPDLog("Invalid parent link in %p - parent is %p - should be %p\n", root_node->right_node, root_node->right_node->parent_node, root_node); return 0; } } if (!check_tree(root_node->right_node)) return 0; return 1; }
int test_wait3(int idx, struct bproc_test_info_t *info) { if (idx == 0) { /* Parent process */ int i; /* look for stops */ for (i=1; i < info->nprocs; i++) { wait_on_child1(info, i, 0); printf(" W"); kill(info->pid[i], SIGCONT); printf(" K"); } /* look for exits */ for (i=1; i < info->nprocs; i++) { wait_on_child1(info, i, WAIT_WANTEXIT); printf(" W"); } return 0; } else { check_tree(); kill(getpid(), SIGSTOP); /* stop self */ check_tree(); exit(WAIT_EXITSTATUS); } }
static Block_t * bf_get_free_block(Allctr_t *allctr, Uint size, Block_t *cand_blk, Uint cand_size) { BFAllctr_t *bfallctr = (BFAllctr_t *) allctr; RBTree_t **root = &bfallctr->mbc_root; RBTree_t *x = *root; RBTree_t *blk = NULL; Uint blk_sz; ASSERT(!cand_blk || cand_size >= size); while (x) { blk_sz = BF_BLK_SZ(x); if (blk_sz < size) { x = x->right; } else { blk = x; if (blk_sz == size) break; x = x->left; } } if (!blk) return NULL; ASSERT(IS_TREE_NODE(blk)); #ifdef HARD_DEBUG { RBTree_t *ct_blk = check_tree(root, 0, size); ASSERT(BF_BLK_SZ(ct_blk) == BF_BLK_SZ(blk)); } #endif if (cand_blk && cand_size <= BF_BLK_SZ(blk)) return NULL; /* cand_blk was better */ /* Use next block if it exist in order to avoid replacing the tree node */ blk = LIST_NEXT(blk) ? LIST_NEXT(blk) : blk; bf_unlink_free_block(allctr, (Block_t *) blk); return (Block_t *) blk; }
bool module_passes(ast_t* package, pass_opt_t* options, source_t* source) { if(!pass_parse(package, source)) return false; if(options->limit < PASS_SYNTAX) return true; ast_t* module = ast_child(package); if(ast_visit(&module, pass_syntax, NULL, options, PASS_SYNTAX) != AST_OK) return false; check_tree(module); return true; }
main(int argc, char * argv[]){ int file_addr, file_size; char c; int nbyte; struct iso_primary_descriptor ipd; struct iso_directory_record * idr; int typel_extent, typem_extent; int path_table_size; int i,j; if(argc < 2) return 0; infile = fopen(argv[1],"rb"); file_addr = 32768; lseek(fileno(infile), file_addr, 0); read(fileno(infile), &ipd, sizeof(ipd)); idr = (struct iso_directory_record *) &ipd.root_directory_record; blocksize = isonum_723((char *)ipd.logical_block_size); if( blocksize != 512 && blocksize != 1024 && blocksize != 2048 ) { blocksize = 2048; } file_addr = isonum_733(idr->extent) + isonum_711((char *)idr->ext_attr_length); file_size = isonum_733(idr->size); printf("Root at extent %x, %d bytes\n", file_addr, file_size); file_addr = file_addr * blocksize; check_tree(file_addr, file_size, file_addr); typel_extent = isonum_731((char *)ipd.type_l_path_table); typem_extent = isonum_732((char *)ipd.type_m_path_table); path_table_size = isonum_733(ipd.path_table_size); /* Enable this to get the dump of the path tables */ #if 0 check_path_tables(typel_extent, typem_extent, path_table_size); #endif fclose(infile); if(!ngoof) printf("No errors found\n"); }
static void check_tree (funct_state local, tree t, bool checking_write) { if ((TREE_CODE (t) == EXC_PTR_EXPR) || (TREE_CODE (t) == FILTER_EXPR)) return; /* Any tree which is volatile disqualifies thie function from being const or pure. */ if (TREE_THIS_VOLATILE (t)) { local->pure_const_state = IPA_NEITHER; return; } while (TREE_CODE (t) == REALPART_EXPR || TREE_CODE (t) == IMAGPART_EXPR || handled_component_p (t)) { if (TREE_CODE (t) == ARRAY_REF) check_operand (local, TREE_OPERAND (t, 1), false); t = TREE_OPERAND (t, 0); } /* The bottom of an indirect reference can only be read, not written. */ if (INDIRECT_REF_P (t)) { check_tree (local, TREE_OPERAND (t, 0), false); /* Any indirect reference that occurs on the lhs disqualifies the function from being pure or const. Any indirect reference that occurs on the rhs disqualifies the function from being const. */ if (checking_write) { local->pure_const_state = IPA_NEITHER; return; } else if (local->pure_const_state == IPA_CONST) local->pure_const_state = IPA_PURE; } if (SSA_VAR_P (t)) check_operand (local, t, checking_write); }
/* * Test node addition: p = power_product to add */ static void test_add(rba_buffer_t *b, pprod_t *p) { uint32_t i, j, k; bool new_node; if (p == empty_pp) { printf("test add: empty product\n"); } else { printf("test add: x%"PRId32"\n", var_of_pp(p)); } i = rba_find_node(b, p); j = rba_get_node(b, p, &new_node); k = rba_find_node(b, p); if (j != k) { printf("Error in test_add: find after get failed\n"); fflush(stdout); exit(1); } if (i == 0 && !new_node) { printf("Error in test_add: expected a new node\n"); fflush(stdout); exit(1); } if (i != 0) { if (new_node) { printf("Error in test_add: not expecting a new node\n"); fflush(stdout); exit(1); } if (j != i) { printf("Error in test_add: get returned an unexpected node\n"); fflush(stdout); exit(1); } } check_tree(b); }