Ejemplo n.º 1
0
void test_ack(void)
{
    quicly_acks_t acks;
    uint64_t at;
    size_t i, j;

    quicly_acks_init(&acks);

    /* save 150 acks, packet number from 1 to 50 */
    for (at = 0; at < 10; ++at)
        for (i = 1; i <= 5; ++i)
            for (j = 0; j < 3; ++j)
                quicly_acks_allocate(&acks, at * 5 + i, at, on_acked);

    /* check all acks */
    quicly_acks_iter_t iter;
    quicly_acks_init_iter(&acks, &iter);
    for (at = 0; at < 10; ++at) {
        for (i = 1; i <= 5; ++i) {
            for (j = 0; j < 3; ++j) {
                quicly_ack_t *ack = quicly_acks_get(&iter);
                ok(ack != NULL);
                ok(ack->packet_number == at * 5 + i);
                ok(ack->sent_at == at);
                ok(ack->acked == on_acked);
                quicly_acks_next(&iter);
            }
        }
    }
    ok(quicly_acks_get(&iter) == NULL);
    ok(num_blocks(&acks) == 150 / 16 + 1);

    /* pop acks between 11 <= packet_number <= 40 */
    quicly_acks_init_iter(&acks, &iter);
    while (quicly_acks_get(&iter)->packet_number <= 10) {
        quicly_acks_next(&iter);
        ok(quicly_acks_get(&iter) != NULL);
    }
    while (quicly_acks_get(&iter)->packet_number <= 40) {
        quicly_acks_release(&acks, &iter);
        quicly_acks_next(&iter);
        ok(quicly_acks_get(&iter) != NULL);
    }

    quicly_acks_init_iter(&acks, &iter);
    size_t cnt = 0;
    for (; quicly_acks_get(&iter) != NULL; quicly_acks_next(&iter)) {
        quicly_ack_t *ack = quicly_acks_get(&iter);
        ok(ack->acked != NULL);
        ok(ack->packet_number <= 10 || 40 < ack->packet_number);
        ++cnt;
    }
    ok(cnt == 60);
    ok(num_blocks(&acks) == 30 / 16 + 1 + 1 + 30 / 16 + 1);

    quicly_acks_dispose(&acks);
}
Ejemplo n.º 2
0
cov::status_t
cov_function_t::calc_stats(cov_stats_t *stats) const
{
    unsigned int bidx;
    cov_stats_t mine;
    cov::status_t st;

    assert(file_->finalised_);

    if (suppression_)
	st = cov::SUPPRESSED;
    else
    {
	/* skip the psuedo-blocks which don't correspond to code */
	assert(num_blocks() >= 2);
	for (bidx = first_real_block() ; bidx <= last_real_block() ; bidx++)
	{
	    cov_block_t *b = nth_block(bidx);
	    if (!b->locations().head())
		continue;
	    b->calc_stats(&mine);
	}
	stats->accumulate(&mine);
	st = mine.status_by_lines();
    }

    stats->add_function(st);

    return st;
}
Ejemplo n.º 3
0
 UInt64 virtual_size() const {
   return sizeof(Header)
       + (sizeof(Entry) * num_keys())
       + (sizeof(Block) * num_blocks())
       + (sizeof(Node) * num_nodes())
       + total_key_length();
 }
Ejemplo n.º 4
0
            std::vector<block_data> get_blocks()
            {
                std::vector<block_data> blocks;

                uint8_t const* ptr = m_blocks_data;
                static const uint64_t block_size = BlockCodec::block_size;
                std::vector<uint32_t> buf(block_size);
                for (size_t b = 0; b < m_blocks; ++b) {
                    blocks.emplace_back();
                    uint32_t cur_block_size =
                        ((b + 1) * block_size <= size())
                        ? block_size : (size() % block_size);

                    uint32_t cur_base = (b ? block_max(b - 1) : uint32_t(-1)) + 1;
                    uint32_t gaps_universe = block_max(b) - cur_base - (cur_block_size - 1);

                    blocks.back().index = b;
                    blocks.back().size = cur_block_size;
                    blocks.back().docs_begin = ptr;
                    blocks.back().doc_gaps_universe = gaps_universe;
                    blocks.back().max = block_max(b);

                    uint8_t const* freq_ptr =
                        BlockCodec::decode(ptr, buf.data(),
                                           gaps_universe, cur_block_size);
                    blocks.back().freqs_begin = freq_ptr;
                    ptr = BlockCodec::decode(freq_ptr, buf.data(),
                                             uint32_t(-1), cur_block_size);
                    blocks.back().end = ptr;
                }

                assert(blocks.size() == num_blocks());
                return blocks;
            }
Ejemplo n.º 5
0
 const aligned_vector<complex_type>& process(aligned_vector<complex_type>::const_iterator i0,
                                             aligned_vector<complex_type>::const_iterator i1) {
   assert(std::distance(i0,i1) == q()*num_blocks());
   for (int output_offset=0; i0!=i1; i0+=q(), output_offset+=p()) {
     process(i0, i0+q(), output_offset);
   }
   return out_;
 }
Ejemplo n.º 6
0
gboolean
cov_function_t::reconcile_calls()
{
    unsigned int bidx;
    gboolean ret = TRUE;

    if (suppression_)
	return TRUE;    /* ignored */

    /*
     * Last two blocks in a function appear to be the function
     * epilogue with one fake arc out representing returns *from*
     * the function, and a block inserted as the target of all
     * function call arcs, with one fake arc back to block 0
     * representing returns *to* the function.  So don't attempt
     * to reconcile those.
     */
    if (num_blocks() <= 2)
	return TRUE;

    for (bidx = first_real_block() ; bidx <= last_real_block() ; bidx++)
    {
	cov_block_t *b = nth_block(bidx);

	if (b->out_ncalls_ != (b->call_ == 0 ? 0U : 1U))
	{
	    /* TODO */
	    if (b->locations().head() != 0)
	    {
		/*
		 * Don't complain about not being to reconcile weird
		 * calls inserted by g++, like _Unwind_Resume() or
		 * __cxa_throw(), or any other call with no direct
		 * relationship to the source code.
		 */
		cgraph_log.debug("Failed to reconcile calls for block %s, %d call arcs, %d recorded calls\n",
				 b->describe(), b->out_ncalls_, (b->call_ == 0 ? 0 : 1));
	    }
	    b->call_ = (const char *)0;   /* free and null out */
	    ret = FALSE;
	    continue;
	}

	for (list_iterator_t<cov_arc_t> aiter = b->first_arc() ; *aiter ; ++aiter)
	{
	    cov_arc_t *a = *aiter;
	    char *name;

	    if (a->is_call() && (name = b->pop_call()))
	    {
		cgraph_log.debug2("    block %s calls %s\n", b->describe(), name);
		a->take_name(name);
	    }
	}
	cgraph_log.debug("Reconciled %d calls for block %s\n", b->out_ncalls_, b->describe());
    }
    return ret;
}
Ejemplo n.º 7
0
/* Start with buffer1 and sync to buffer2. */
static void test_sync(const char *buffer1, size_t len1,
		      const char *buffer2, size_t len2,
		      size_t block_size,
		      const struct result results[], size_t num_results)
{
	struct crc_context *ctx;
	size_t used, ret, i, curr_literal, tailsize;
	long result;
	uint64_t crcs[num_blocks(len1, block_size)];

	crc_of_blocks(buffer1, len1, block_size, 64, crcs);

	tailsize = len1 % block_size;

	/* Normal method. */
	ctx = crc_context_new(block_size, 64, crcs, ARRAY_SIZE(crcs),
			      tailsize);

	curr_literal = 0;
	for (used = 0, i = 0; used < len2; used += ret) {
		ret = crc_read_block(ctx, &result, buffer2+used, len2-used);
		check_result(result, &curr_literal, results, num_results, &i);
	}

	while ((result = crc_read_flush(ctx)) != 0)
		check_result(result, &curr_literal, results, num_results, &i);

	check_finalized_result(curr_literal, results, num_results, &i);
	
	/* We must have achieved everything we expected. */
	ok1(i == num_results);
	crc_context_free(ctx);

	/* Byte-at-a-time method. */
	ctx = crc_context_new(block_size, 64, crcs, ARRAY_SIZE(crcs),
			      tailsize);

	curr_literal = 0;
	for (used = 0, i = 0; used < len2; used += ret) {
		ret = crc_read_block(ctx, &result, buffer2+used, 1);

		check_result(result, &curr_literal, results, num_results, &i);
	}

	while ((result = crc_read_flush(ctx)) != 0)
		check_result(result, &curr_literal, results, num_results, &i);

	check_finalized_result(curr_literal, results, num_results, &i);
	
	/* We must have achieved everything we expected. */
	ok1(i == num_results);
	crc_context_free(ctx);
}
void CCorrelationFilters::compute_inverse_psd_matrix(struct CDataStruct *img, struct CParamStruct *params)
{
    img->S = params->beta*img->D;
	for (int i=0; i<img->num_channels*img->num_channels; i=i+img->num_channels+1) {
		img->S.block(0,i,img->num_elements_freq,1) += Eigen::ArrayXXcd::Constant(img->num_elements_freq,1,params->alpha);
	}
	
    img->Sinv = img->S;
	Eigen::MatrixXi num_blocks = Eigen::MatrixXi::Zero(img->num_channels,img->num_channels);

    int index=0;
    for (int i=0; i<img->num_channels; i++){
        for (int j=0; j<img->num_channels; j++){
            num_blocks(i,j) = index;
            index++;
        }
    }
    
	fusion_matrix_inverse(img->Sinv, num_blocks);
    img->inv_psd_flag = true;
}
Ejemplo n.º 9
0
gboolean
cov_function_t::solve()
{
    int passes, changes;
    cov_arc_t *a;
    cov_block_t *b;

    /* For every block in the file,
       - if every exit/entrance arc has a known count, then set the block count
       - if the block count is known, and every exit/entrance arc but one has
	 a known execution count, then set the count of the remaining arc

       As arc counts are set, decrement the succ/pred count, but don't delete
       the arc, that way we can easily tell when all arcs are known, or only
       one arc is unknown.  */

    /* The order that the basic blocks are iterated through is important.
       Since the code that finds spanning trees starts with block 0, low numbered
       arcs are put on the spanning tree in preference to high numbered arcs.
       Hence, most instrumented arcs are at the end.  Graph solving works much
       faster if we propagate numbers from the end to the start.

       This takes an average of slightly more than 3 passes.  */

    solve_log.debug(" ---> %s\n", name_.data());

    /*
     * In the new gcc 3.3 file format we cannot expect to get arcs into
     * the entry block and out of the exit block.  So if we don't get any,
     * tweak the {in,out}_ninvalid_ count up to effective infinity to
     * ensure the solve algorithm doesn't accidentally use the lack of
     * counts.
     */
    assert(num_blocks() >= 2);
    if ((b = blocks_->nth(entry_block()))->in_arcs_.head() == 0)
    {
	assert(file_->format_version_ > 0);
	b->in_ninvalid_ = ~0U;
	solve_log.debug("entry block tweaked\n");
    }
    if ((b = blocks_->nth(exit_block()))->out_arcs_.head() == 0)
    {
	assert(file_->format_version_ > 0);
	b->out_ninvalid_ = ~0U;
	solve_log.debug("exit block tweaked\n");
    }

    changes = 1;
    passes = 0;
    while (changes)
    {
	passes++;
	changes = 0;

	solve_log.debug("pass %d\n", passes);

	for (ptrarray_iterator_t<cov_block_t> bitr = blocks_->last() ; *bitr ; --bitr)
	{
	    b = *bitr;
	    solve_log.debug("[%d]\n", b->bindex());

	    if (!b->count_valid_)
	    {
		solve_log.debug("[%d] out_ninvalid_=%u in_ninvalid_=%u\n",
			    b->bindex(), b->out_ninvalid_, b->in_ninvalid_);

		/*
		 * For blocks with calls we have to ignore the outbound total
		 * when calculating the block count, because of the possibility
		 * of calls to fork(), exit() or other functions which can
		 * return more or less frequently than they're called.  Given
		 * the existance of longjmp() all calls are potentially like
		 * that.
		 */
		if (b->out_ncalls_ == 0 && b->out_ninvalid_ == 0)
		{
		    b->set_count(cov_arc_t::total(b->out_arcs_));
		    changes++;
		    solve_log.debug("[%d] count=%llu\n", b->bindex(), (unsigned long long)b->count());
		}
		else if (b->in_ninvalid_ == 0)
		{
		    b->set_count(cov_arc_t::total(b->in_arcs_));
		    changes++;
		    solve_log.debug("[%d] count=%llu\n", b->bindex(), (unsigned long long)b->count());
		}
	    }

	    if (b->count_valid_)
	    {
		if (b->out_ninvalid_ == 1)
		{
		    /* Search for the invalid arc, and set its count.  */
		    if ((a = cov_arc_t::find_invalid(b->out_arcs_, FALSE)) == 0)
			return FALSE;   /* ERROR */
		    /* Calculate count for remaining arc by conservation.  */
		    /* One of the counts will be invalid, but it is zero,
		       so adding it in also doesn't hurt.  */
		    count_t out_total = cov_arc_t::total(b->out_arcs_);
		    if (b->count_ < out_total)
		    {
			solve_log.warning("Function %s cannot be solved because "
					  "the arc counts are inconsistent, suppressing\n",
					  name_.data());
			suppress(cov_suppressions.find(0, cov_suppression_t::UNSOLVABLE));
			return TRUE;
		    }
		    assert(b->count_ >= out_total);
		    a->set_count(b->count_ - out_total);
		    changes++;
		    solve_log.debug("[%d->%d] count=%llu\n",
			    a->from()->bindex(), a->to()->bindex(),
			    (unsigned long long)a->count());
		}
		if (b->in_ninvalid_ == 1)
		{
		    /* Search for the invalid arc, and set its count.  */
		    if ((a = cov_arc_t::find_invalid(b->in_arcs_, FALSE)) == 0)
			return FALSE;   /* ERROR */
		    /* Calculate count for remaining arc by conservation.  */
		    /* One of the counts will be invalid, but it is zero,
		       so adding it in also doesn't hurt.  */
		    count_t in_total = cov_arc_t::total(b->in_arcs_);
		    if (b->count_ < in_total)
		    {
			solve_log.warning("Function %s cannot be solved because "
					  "the arc counts are inconsistent, suppressing\n",
					  name_.data());
			suppress(cov_suppressions.find(0, cov_suppression_t::UNSOLVABLE));
			return TRUE;
		    }
		    assert(b->count_ >= in_total);
		    a->set_count(b->count_ - in_total);
		    changes++;
		    solve_log.debug("[%d->%d] count=%llu\n",
			    a->from()->bindex(), a->to()->bindex(),
			    (unsigned long long)a->count());
		}
	    }
	}
    }

    /*
     * If the graph has been correctly solved, every block will
     * have a valid count and all its inbound and outbounds arcs
     * will also have valid counts.
     */
    for (ptrarray_iterator_t<cov_block_t> bitr = blocks_->first() ; *bitr ; ++bitr)
    {
	b = *bitr;
	if (!b->count_valid_)
	    return FALSE;
	if (b->out_ninvalid_ > 0 && b->out_ninvalid_ < ~0U)
	    return FALSE;
	if (b->in_ninvalid_ > 0 && b->in_ninvalid_ < ~0U)
	    return FALSE;
	if (cov_arc_t::find_invalid(b->in_arcs_, TRUE) != 0)
	    return FALSE;
	if (cov_arc_t::find_invalid(b->out_arcs_, TRUE) != 0)
	    return FALSE;
    }

    solve_log.debug("Solved flow graph for %s in %d passes\n", name(), passes);

    return TRUE;
}
Ejemplo n.º 10
0
 elem_cache_t() : arr(num_blocks()) {}
Ejemplo n.º 11
0
void xmodem_progress(void* unused, unsigned block_num, ulong offset, ulong fsize, time_t start)
{
	unsigned	cps;
	unsigned	total_blocks;
	long		l;
	long		t;
	time_t		now;
	static time_t last_progress;

	now=time(NULL);
	if(now-last_progress>=progress_interval || offset >= fsize || newline) {
		t=now-start;
		if(t<=0)
			t=1;
		if((cps=offset/t)==0)
			cps=1;			/* cps so far */
		l=fsize/cps;		/* total transfer est time */
		l-=t;				/* now, it's est time left */
		if(l<0) l=0;
		if(mode&SEND) {
			total_blocks=num_blocks(fsize,xm.block_size);
			fprintf(statfp,"\rBlock (%lu%s): %lu/%lu  Byte: %lu  "
				"Time: %lu:%02lu/%lu:%02lu  %u cps  %lu%% "
				,xm.block_size%1024L ? xm.block_size: xm.block_size/1024L
				,xm.block_size%1024L ? "" : "K"
				,block_num
				,total_blocks
				,offset
				,t/60L
				,t%60L
				,l/60L
				,l%60L
				,cps
				,(long)(((float)offset/(float)fsize)*100.0)
				);
		} else if(mode&YMODEM) {
			fprintf(statfp,"\rBlock (%lu%s): %lu  Byte: %lu  "
				"Time: %lu:%02lu/%lu:%02lu  %u cps  %lu%% "
				,xm.block_size%1024L ? xm.block_size: xm.block_size/1024L
				,xm.block_size%1024L ? "" : "K"
				,block_num
				,offset
				,t/60L
				,t%60L
				,l/60L
				,l%60L
				,cps
				,(long)(((float)offset/(float)fsize)*100.0)
				);
		} else { /* XModem receive */
			fprintf(statfp,"\rBlock (%lu%s): %lu  Byte: %lu  "
				"Time: %lu:%02lu  %u cps "
				,xm.block_size%1024L ? xm.block_size: xm.block_size/1024L
				,xm.block_size%1024L ? "" : "K"
				,block_num
				,offset
				,t/60L
				,t%60L
				,cps
				);
		}
		newline=FALSE;
		last_progress=now;
	}
}
Ejemplo n.º 12
0
 UInt32 num_nodes() const {
   return num_blocks() * BLOCK_SIZE;
 }
Ejemplo n.º 13
0
 void set_ith_leader(UInt32 i, UInt32 x) {
   GRN_DAT_DEBUG_THROW_IF(i > MAX_BLOCK_LEVEL);
   GRN_DAT_DEBUG_THROW_IF((x != INVALID_LEADER) && (x >= num_blocks()));
   leaders_[i] = x;
 }
Ejemplo n.º 14
0
/* Simple test for malloc and free. We will want a proper test driver */
int main(int argc, char **argv) {

	int opt;
	int pr = 0;

    struct sigaction newact;

    /* fill in newact */
	newact.sa_handler = handle_seg;
    newact.sa_flags = 0;
	sigaction(SIGSEGV, &newact, NULL);

	while ((opt = getopt(argc, argv, "p")) != -1) {
		switch (opt) {
		case 'p':
			pr = 1;
		break;
		default: /* '?' */
			fprintf(stderr, "Usage: %s [-p ] tracefile\n", argv[0]);
			exit(EXIT_FAILURE);
		}
	}
	if(optind >= argc) {
		fprintf(stderr, "Usage: %s [-p ] tracefile\n", argv[0]);
		exit(EXIT_FAILURE);
	}
	char *tracefile = argv[optind];

    mem_init(SIZE);
    
    char *ptrs[MAXOPS];
    int i;


    /* Call my malloc 4 times */
    
        //ptrs[i] = smalloc(num_bytes);
        //write_to_mem(num_bytes, ptrs[i], i);
	FILE *fp = fopen(tracefile, "r");
	if(!fp) {
		fprintf(stderr, "Usage: driver [-p] <tracefile>\n");
		exit(1);
	}
	load_trace(fp);
	fclose(fp);

	for(i = 0; i < num_ops; i++) {
		switch(trace[i].type) {
	    case 'm':
			ptrs[trace[i].index] = smalloc(trace[i].size);

			if(pr) {
		    	printf("smalloc block %d addr %p size %d\n", 
					trace[i].index, ptrs[trace[i].index], trace[i].size);
			}

			if(!ptrs[trace[i].index]) {
			    fprintf(stderr, "Error: smalloc returned NULL index=%d, size=%d\n", 
					trace[i].index, trace[i].size);
		    }
			// check for valid pointer
			if((ptrs[trace[i].index] < (char *)mem) || 
				(ptrs[trace[i].index] + trace[i].size) > ((char *)mem + SIZE)) {
			   fprintf(stderr, "Error: malloc block %d addr %p size %d heap overflow\n", 
					trace[i].index, ptrs[trace[i].index], trace[i].size);
		    } else {
               write_to_mem(trace[i].size, ptrs[trace[i].index],trace[i].index);
			}
	        break;
	    case 'f':
			if(pr) {
				printf("sfree block %d addr %p\n", 
					 trace[i].index, ptrs[trace[i].index]);
			}
			if(sfree(ptrs[trace[i].index])) {
				fprintf(stderr, "Error: free block %d addr %p\n", 
					trace[i].index, ptrs[trace[i].index]);
			}
				
	        break;
		default :
			fprintf(stderr, "ERROR: bad type of instruction %c for block %d\n",
					trace[i].type, trace[i].index);
	    }
	}

	if(pr) {
		printf("Total free mem: %d\n", total_space(freelist));
		printf("Total allocated mem: %d\n", total_space(allocated_list));
   	 	printf("List of allocated blocks:\n");
		print_allocated();
    	printf("List of free blocks:\n");
    	print_free();
    	printf("Contents of allocated memory:\n");
    	print_mem();
	} else {
		printf("Total free mem: %d\n", total_space(freelist));
		printf("Total allocated mem: %d\n", total_space(allocated_list));
		printf("Number of allocated blocks: %d\n", num_blocks(allocated_list));
	}


    mem_clean();
    return 0;
}
Ejemplo n.º 15
0
 const Block &ith_block(UInt32 i) const {
   GRN_DAT_DEBUG_THROW_IF(i >= num_blocks());
   return blocks_[i];
 }
Ejemplo n.º 16
0
 void set_ith_entry(UInt32 i, UInt32 x) {
   GRN_DAT_DEBUG_THROW_IF(i > MAX_BLOCK_LEVEL);
   GRN_DAT_DEBUG_THROW_IF((x != INVALID_ENTRY) && (x >= num_blocks()));
   entries_[i] = x;
 }