Exemple #1
0
Fichier : buf.c Projet : taysom/tau
void buf_put (Buf_s **bp)
{
	Buf_s *b = *bp;

	*bp = NULL;
	aver(b->blknum == ((Node_s *)b->d)->blknum);
	aver(0 < b->inuse);
	++Cache.stat.puts;
	--b->inuse;
	if (!b->inuse) {
		u64 crc = crc64(b->d, BLOCK_SIZE);
		if (b->dirty) {
			if (crc == b->crc) {
				printf("Didn't change %lld\n", b->blknum);
			}
			//XXX: this can be true. aver(crc != b->crc);
			b->crc = crc;
			dev_flush(b);
			b->dirty = FALSE;
		} else {
			if (crc != b->crc) {
				PRd(b->blknum);
			}
			aver(crc == b->crc);
		}
	}
}
Exemple #2
0
void
BzTest5(void)
{
	enum { NUM_RECS = 20 };
	VAR_LUMP(v, MAX_DATA);
	Key key = {{0}};
	Lump a, b;
	Bz t;
	bool found;

	printf("%s\n", __FUNCTION__);
	init_twister(17);
	BzInit(&t, KEY_LEN);
	for (u64 i = 0; i < NUM_RECS; i++) {
		IntLump(v, i);
		BzPut(&t, RandKey().s, v);
	}
	BzDump(__FUNCTION__, &t);
	for (;;) {
		bool done;

		a = BzNext(&t, key.s, key.s, &done);
		if (done) {
			break;
		}
		b = BzGet(&t, key.s, &found);
		if (!found) {
			fatal("didn't find %llu", key);
		}
		aver(a.len == b.len);
		aver(strcmp(a.p, b.p) == 0);
	}
	BzDump(__FUNCTION__, &t);
}
Exemple #3
0
static buf_s *victim (void)
{
	buf_s	*buf;
	unint	wrap = 0;

	for (;;) {
		++Clock;
		if (Clock == &Buf[Num_bufs]) {
			Clock = Buf;
			if (++wrap > 2) {
				bdump();
				fatal("All buffers in use");
				return NULL;
			}
		}
		buf = Clock;
		if (buf->b_use < 0) {
			if (buf->b_ant.a_state == ANT_FLUSHING) continue;
			bflush(buf);
			aver(buf->b_ant.a_state != ANT_FLUSHING);
			aver(buf->b_ant.a_state != ANT_DIRTY);
			buf->b_use = 1;
			rmv(buf);
			return buf;
		}
		if (buf->b_use == 0) {
			buf->b_use = -1;
		}
	}
}
Exemple #4
0
Fichier : buf.c Projet : taysom/tau
static void add (Buf_s *b)
{
	Buf_s	*prev = hash(b->inode, b->blknum);

	aver(b->blknum);
	aver(b->next == NULL);
	b->next = prev->next;
	prev->next = b;
}
Exemple #5
0
void *bdata (ant_s *ant)
{
	buf_s	*buf = container(ant, buf_s, b_ant);

	aver(buf >= Buf);
	aver(buf < &Buf[Num_bufs]);

	return buf->b_data;
}
Exemple #6
0
void
BcTest6(void)
{
	enum { NUM_RECS = 2000, NUM_TRIALS = ONE_MILLION };
	Bc t;
	VAR_LUMP(v, MAX_DATA);
	Key a[NUM_RECS];
	u64 n = 0;
	u64 puts = 0;
	u64 deletes = 0;

	printf("%s\n", __FUNCTION__);
	init_twister(37);
	BcInit(&t, KEY_LEN);
	for (u64 j = 0; j < NUM_TRIALS; j++) {
		Key key;
		bool found;
		if (Prob(((NUM_RECS - n) * 100) / NUM_RECS)) {
			aver(n < NUM_RECS);
			key = IntKey(twister_urand(10000));
			BcGet(&t, key.s, &found);
			if (!found) {
				a[n++] = key;
				RandLump(v);
				BcPut(&t, key.s, v);
				++puts;
			}
			if (0 || Prob(2)) Audit("Put", &t, a, n, j);
		} else {
			aver(0 < n);
			u64 i = twister_urand(n);
			key = a[i];
			BcGet(&t, key.s, &found);
			if (!found) {
				BcDump("not found", &t);
				fatal("didn't find %s %llu %llu", key.s, puts, deletes);
			}
			BcDelete(&t, key.s);
			BcGet(&t, key.s, &found);
			if (found) {
				BcDump("found", &t);
				fatal("found %llu", key);
			}
			a[i] = a[--n];
			++deletes;
			if (0 || Prob(2)) Audit("Delete", &t, a, n, j);
		}
	}
	BcDoAudit(&t);
	printf("\tputs=%llu deletes=%llu\n", puts, deletes);
	BcReport(__FUNCTION__, BcDoAudit(&t));
	BcDump(__FUNCTION__, &t);
	BcFree(&t);
}
Exemple #7
0
Fichier : ht.c Projet : taysom/tau
STATIC void store_key(Node_s *node, Key_t key)
{
	u8	*start;

	aver(sizeof(Key_t) <= node->free);
	aver(sizeof(Key_t) <= node->end);

	node->end -= sizeof(Key_t);
	node->free -= sizeof(Key_t);
	start = &((u8 *)node)[node->end];
	PACK(start, key);
}
Exemple #8
0
int main(int argc, char *argv[]) {
	for (Test *t = test; t->string; t++) {
		const char *suffix = Suffix(t->string);
		if (t->suffix == NULL) {
			aver(suffix == NULL);
		} else {
			aver(suffix != NULL);
			aver(strcmp(suffix, t->suffix) == 0);
		}
	}
	return 0;
}
Exemple #9
0
void bput (void *data)
{
	buf_s	*buf;

	buf = addr2buf(data);
	aver(buf->b_use > 0);
	if (!Lazy) {
		bflush(buf);
	}
	aver(buf->b_use > 0);
	--buf->b_use;
}
Exemple #10
0
void
BaTest6(void)
{
    enum { NUM_RECS = 2000, NUM_TRIALS = ONE_MILLION };
    Ba t;
    u64 a[NUM_RECS];
    u64 n = 0;
    u64 puts = 0;
    u64 deletes = 0;

    printf("%s\n", __FUNCTION__);
    init_twister(17);
    BaInit(&t);
    for (u64 j = 0; j < NUM_TRIALS; j++) {
        u64 key;
        bool found;

        if (Prob(((NUM_RECS - n) * 100) / NUM_RECS)) {
            aver(n < NUM_RECS);
            key = twister_urand(10000);
            BaGet(&t, key, &found);
            if (!found) {
                a[n++] = key;
                BaPut(&t, key);
                ++puts;
            }
            if (0 || twister_urand(100) < 2) Audit("Put", &t, a, n, j);
        } else {
            aver(0 < n);
            u64 i = twister_urand(n);
            key = a[i];
            BaGet(&t, key, &found);
            if (!found) {
                BaDump("not found", &t);
                fatal("didn't find %llu %llu %llu", key, puts, deletes);
            }
            BaDelete(&t, key);
            BaGet(&t, key, &found);
            if (found) {
                BaDump("found", &t);
                fatal("found %llu", key);
            }
            a[i] = a[--n];
            ++deletes;
            if (0 || twister_urand(100) < 2) Audit("Delete", &t, a, n, j);
        }
    }
    BaDoAudit(&t);
    printf("\tputs=%llu deletes=%llu\n", puts, deletes);
    BaReportAudit(__FUNCTION__, BaDoAudit(&t));
    BaDump(__FUNCTION__, &t);
}
Exemple #11
0
Fichier : ht.c Projet : taysom/tau
STATIC Key_t get_key(Node_s *node, unint i)
{
	Key_t	key;
	unint	x;
	u8	*start;

	aver(i < node->numrecs);
	x = node->rec[i];
	aver(x < BLOCK_SIZE);
	start = &((u8 *)node)[x];
	UNPACK(start, key);
	return key;
}
Exemple #12
0
Fichier : buf.c Projet : taysom/tau
void buf_free (Buf_s **bp)
{
	Buf_s *b = *bp;

	*bp = NULL;
	aver(b->blknum == ((Node_s *)b->d)->blknum);
	aver(0 < b->inuse);
	++Cache.stat.puts;
	--b->inuse;
	if (!b->inuse) {
		if (b->blknum) rmv(b->inode, b->blknum);
	}
	//XXX: Don't know what to do yet with freed block
}
Exemple #13
0
symbol_list *
symbol_list_n_get (symbol_list *l, int n)
{
  int i;
  aver (0 <= n);
  for (i = 0; i < n; ++i)
    {
      l = l->next;
      aver (l);
    }
  aver (l->content_type == SYMLIST_SYMBOL);
  aver (l->content.sym);
  return l;
}
Exemple #14
0
void
BcTest8(void)
{
	/*
	 * Extensive test of all functions. Want to cover most code paths.
	 * 1. Dynamically adjust number of records by a factor of 100.
	 * 2. Randomly pick operations.
	 * 3. Test iteration intermixed with other operations.
	 */
	enum { MAX_RECS = 100 * ONE_THOUSAND };

	Bc t;
	u64 key;
	u64 keys[MAX_RECS];
	u64 numKeys = 0;
	u64 numPuts = 0;
	u64 numDeletes = 0;
	VAR_LUMP(v, MAX_DATA);

	init_twister(37);
	BcInit(&t, KEY_LEN);
	RandLump(v);
	for (u64 i = 0; i < 10; i++) {
		u64 maxKeys = twister_urand(MAX_RECS);
		PRu(maxKeys);
		while (numKeys != maxKeys) {
			aver(numKeys <= MAX_RECS);
			if (numKeys < maxKeys && Prob(75)) {
				key = twister_random();
				keys[numKeys++] = key;
				BcPut(&t, IntKey(key).s, v);
				++numPuts;
			} else {
				if (numKeys) {
					u64 j = twister_urand(numKeys);
					key = keys[j];
					keys[j] = keys[--numKeys];
					BcDelete(&t, IntKey(key).s);
					++numDeletes;
				}
			}
		}
	}
	aver(numPuts - numDeletes == numKeys);
	PRu(numPuts);
	PRu(numDeletes);
	PRu(numKeys);
	BcReport(__FUNCTION__, BcDoAudit(&t));
}
Exemple #15
0
void
boundary_set_from_string (boundary *bound, char *loc_str)
{
  /* Must search in reverse since the file name field may
   * contain `.' or `:'.  */
  char *delim = _mbsrchr (loc_str, '.');
  aver (delim);
  *delim = '\0';
  bound->column = atoi (delim+1);
  delim = _mbsrchr (loc_str, ':');
  aver (delim);
  *delim = '\0';
  bound->line = atoi (delim+1);
  bound->file = uniqstr_new (loc_str);
}
Exemple #16
0
static inline buf_s *addr2buf (void *data)
{
	addr	x;
	addr	y;

	aver(data);

	x = (addr)data - (addr)Base;
	y = x >> BLK_SHIFT;

	aver(y < Num_bufs);
	aver((y << BLK_SHIFT) == x);

	return &Buf[y];
}
Exemple #17
0
static u64 GetRing(void) {
	aver(Tail != Head);
	if (Tail == RING) {
		Tail = 0;
	}
	return Ring[Tail++];
}
Exemple #18
0
void
BzTest7(void)
{
	enum { NUM_RECS = 20 };
	VAR_LUMP(v, MAX_DATA);
	Key key = {{0}};
	Bz t;

	printf("%s\n", __FUNCTION__);
	init_twister(17);
	BzInit(&t, KEY_LEN);
	for (u64 i = 0; i < NUM_RECS; i++) {
		RandLump(v);
		BzPut(&t, RandKey().s, v);
	}
	BzDump(__FUNCTION__, &t);
	for (;;) {
		bool done;

		BzNext(&t, key.s, key.s, &done);
		if (done) {
			break;
		}
		BzDelete(&t, key.s);
	}
	BzDelete(&t, key.s);
	BzDump("Should be empty", &t);
	BzReportAudit(__FUNCTION__, BzDoAudit(&t));
	if (1) aver(t.root == NULL);
}
Exemple #19
0
void
BzTest4(void)
{
	enum { NUM_RECS = 20 };
	VAR_LUMP(v, MAX_DATA);
	Lump a;
	Bz t;
	bool found;

	printf("%s\n", __FUNCTION__);
	init_twister(17);
	BzInit(&t, KEY_LEN);
	for (u64 i = 0; i < NUM_RECS; i++) {
		IntLump(v, i);
		BzPut(&t, RandKey().s, v);
	}
	init_twister(17);
	for (u64 i = 0; i < NUM_RECS; i++) {
		IntLump(v, i);
		a = BzGet(&t, RandKey().s, &found);
		if (!found) {
			fatal("didn't find %llu", i);
		}
		aver(memcmp(a.p, v.p, v.len) == 0);
	}
	BzDump(__FUNCTION__, &t);
}
Exemple #20
0
static void
save_reductions (state *s)
{
  int count = 0;
  size_t i;

  /* Find and count the active items that represent ends of rules. */
  for (i = 0; i < nitemset; ++i)
    {
      item_number item = ritem[itemset[i]];
      if (item_number_is_rule_number (item))
	{
	  rule_number r = item_number_as_rule_number (item);
	  redset[count++] = &rules[r];
	  if (r == 0)
	    {
	      /* This is "reduce 0", i.e., accept. */
	      aver (!final_state);
	      final_state = s;
	    }
	}
    }

  /* Make a reductions structure and copy the data into it.  */
  state_reductions_set (s, count, redset);
}
int AirqualityGp2y10::APIair(int Time)
{
   int DensityAPI;
   float Density;
   
   Density = aver(Time*10);//////
//Serial.println(Density);//test
   if(Density<0.05)//1
     {
         DensityAPI=Density/0.001;
     } 
     else if(Density>0.05 && Density<0.15) //2
            {
               DensityAPI=50+(Density-0.05)/0.002;
            }
             else if(Density>0.15 && Density<0.35) //3
                    {
                       DensityAPI=98+(Density-0.15)/0.002;
                    }
                   else if(Density>0.35 && Density<0.4) //4
                        {
                             DensityAPI=200+(Density-0.35)/0.0007;
                        }
                         else if(Density>0.42 && Density<0.5) //5
                              {
                                   DensityAPI=300+(Density-0.42)/0.008;
                               }
                               else if(Density>0.5 && Density<0.6) //6
                                      {
                                           DensityAPI=400+(Density-0.5)/0.001;
                                      }
      return(DensityAPI);
}
Exemple #22
0
void
BaTest7(void)
{
    enum { NUM_RECS = 200 };
    Ba t;

    printf("%s\n", __FUNCTION__);
    init_twister(17);
    BaInit(&t);
    for (u64 i = 0; i < NUM_RECS; i++) {
        BaPut(&t, twister_random());
    }
    BaDump(__FUNCTION__, &t);
    for (u64 key = 0, i = 0;; i++) {
        bool done;

        BaNext(&t, key, &key, &done);
        if (done) {
            if (i != NUM_RECS) fatal("Didn't find all the keys %llu %u", i, NUM_RECS);
            break;
        }
        BaDelete(&t, key);
    }
    BaDelete(&t, 0);
    BaDump(__FUNCTION__, &t);
    BaReportAudit(__FUNCTION__, BaDoAudit(&t));
    if (0) aver(t.root == NULL);
}
Exemple #23
0
static int insert_search (
	void	*data,
	u64	rec_key,
	void	*rec,
	unint	len)
{
	insert_search_s	*s = data;
	char		*name = rec;

	if ((s->key & HASH_MASK) < (rec_key & HASH_MASK)) {
		return qERR_NOT_FOUND;
	}
	aver((s->key & HASH_MASK) == (rec_key & HASH_MASK));
	if (strcmp(s->name, name) == 0) {
		return qERR_DUP;
	}
	if (!s->set_new_key) {
		if (s->key != rec_key) {
			s->set_new_key = TRUE;
		} else {
			s->key = rec_key + 1;
			if ((s->key & UNIQUE_MASK) == 0) {
printf("OVERFLOW: %s\n", s->name);
				return qERR_HASH_OVERFLOW;
			}
		}
	}
	return qERR_TRY_NEXT;
}
Exemple #24
0
Fichier : ht.c Projet : taysom/tau
STATIC void lf_move_recs(Node_s *node, Node_s *sibling)
{
	int	i;
	int	j;
	int	size;
	int	total;

	node_compact(node);

	j = node->numrecs;
	for (i = 0; i < sibling->numrecs; i++, j++) {
		unint	x = sibling->rec[i];
		u8	*start = &((u8 *)sibling)[x];

		size = start[sizeof(Key_t)];
		size |= start[sizeof(Key_t) + 1] << 8;
		size += sizeof(u16) + sizeof(Key_t);
		total = size + sizeof(u16);
		aver(total <= node->free);
		node->end -= size;
		node->rec[j] = node->end;
		node->free -= total;
		memmove(&((u8 *)node)[node->end], start, size);
		++node->numrecs;
	}
	sibling->numrecs = 0;
	sibling->free = BLOCK_SIZE - SZ_HEAD;
}
Exemple #25
0
Fichier : ht.c Projet : taysom/tau
STATIC void store_lump(Node_s *node, Lump_s lump)
{
	int total = lump.size + SZ_U16;
	u8 *start;

	aver(total <= node->free);
	aver(total <= node->end);
	aver(lump.size < MAX_U16);

	node->end -= total;
	node->free -= total;
	start = &((u8 *)node)[node->end];
	*start++ = lump.size & MASK_U8;
	*start++ = (lump.size >> BITS_U8) & MASK_U8;
	memmove(start, lump.d, lump.size);
}
Exemple #26
0
Sbitset
Sbitset__new (Sbitset__Index nbits)
{
  /* Some functions, like Sbitset__last_byte_mask, will fail if nbits = 0.  */
  aver (nbits);
  return xcalloc (1, Sbitset__nbytes (nbits));
}
Exemple #27
0
Fichier : ht.c Projet : taysom/tau
STATIC Lump_s get_val(Node_s *node, unint i)
{
	Lump_s	val;
	unint	x;
	u8	*start;

	aver(i < node->numrecs);
	x = node->rec[i];
	aver(x < BLOCK_SIZE);
	start = &((u8 *)node)[x];
	start += sizeof(Key_t);
	val.size = *start++;
	val.size |= (*start++) << 8;
	val.d = start;
	return val;
}
Exemple #28
0
static Tree_s *object (void)
{
FN;
	Tree_s	*tree = NULL;
	Tree_s	*obj;
	Tree_s	*p;
	Token_s	t;

	t = get_token();
	if (t.type != '{') return NULL;
	for (;;) {
		p = pair();
		if (!p) break;
		if (tree) {
			tree->right = p;
		} else {
			tree = p;
		}
		t = get_token();
		if (t.type == ',') continue;
	}
	t = get_token();
	aver(t.type == '}');
	obj = new_tree();
	obj->token.type = T_OBJECT;
	obj->left = tree;
	return obj;
}
Exemple #29
0
Fichier : blk.c Projet : taysom/tau
void bput (buf_s *buf)
{
	aver(buf->b_use > 0);
	if (!buf->b_dev->d_lazy) {
		bflush(buf);
	}
	--buf->b_use;
}
Exemple #30
0
void put_info (info_s *info)
{
    FN;
    aver(info->in_use);
    if (!info) return;
    if (--info->in_use) return;
    rmv_info(info);
}