Beispiel #1
0
static char *test_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make map");
    mu_assert(make_random(map), "Didn't make a random fake radix map");

    RadixMap_sort(map);
    mu_assert(check_order(map),
            "Failed to properly sort the RadixMap");

    mu_assert(test_search(map), "Failed the search test");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search");

    while (map->end > 0) {
        RMElement *el = RadixMap_find(map,
                map->contents[map->end/2].data.key);
        mu_assert(el != NULL, "Should get a result");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete");

        // test that the end is now the old value
        // but uint32 max so it trails off
        mu_assert(check_order(map),
                "RadixMap didn't stay sorted after delete");
    }
    RadixMap_destroy(map);

    return NULL;
}
Beispiel #2
0
// test for large number of elements
static char *test_operations() {
    size_t N = 200;
    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "failed to make the map");
    mu_assert(make_random(map), "did not make a random fake radix map");

    RadixMap_sort(map);
    mu_assert(check_order(map), "failed to properly sort the RadixMap");
    mu_assert(test_search(map), "failed the search test");
    mu_assert(check_order(map), "RadixMap not sorted after seach");

    while (map->end > 0) {
        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "should get a result");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "did not delete element");
        mu_assert(old_end - 1 == map->end, "wrong size after delete");
        mu_assert(check_order(map), "did not stay sorted after delete");
    }
    RadixMap_destroy(map);

    return NULL;
}
Beispiel #3
0
static char *test_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");

    mu_assert(make_random(map), "Didn't make a random fake radix map.");
    //In Zed's code was:
    //RadixMap_sort(map, 0);
    //I think we should sort it again because we do it every time we add a new value
    mu_assert(check_order(map), "Failed to properly sort the RadixMap.");

    mu_assert(test_search(map), "Failed to search test.");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search.");

    while(map->end > 0) {

        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "Should get a result.");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it.");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete.");

        //test taht the end is now the old value, but uint32 max so it trails off
        mu_assert(check_order(map), "RadixMap didn't stay sorted after delete.");
    }

    RadixMap_destroy(map);

    return NULL;
}
Beispiel #4
0
TEST_F(test_ivector, check_order)
{
  ivector v(1, 4);
  v(1) = 0;
  v(2) = 1;
  v(3) = 2;
  v(4) = -4;

  bool check_order(const ivector& v);
  ASSERT_FALSE(check_order(v));

  v = sort(v);

  ASSERT_TRUE(check_order(v));
}
Beispiel #5
0
int		check_redir(t_list *command)
{
  t_list	*tmp;
  int		i;
  char		**tab;
  int		k;

  i = count_command(command);
  if ((tab = malloc(sizeof(char *) * (i + 1))) == NULL)
    return (-2);
  i = 0;
  k = 0;
  tmp = command;
  while (tmp != NULL)
    {
      if (i == 0)
	{
	  tab[k++] = tmp->str;
	  i++;
	}
      k = fill_redir(tmp->str, tab, k);
      tmp = tmp->next;
    }
  if (check_order(tab) == -1)
    return (-1);
  return (0);
}
Beispiel #6
0
char *test_speed() {
    size_t N = 100000;
    int i = 0;
    clock_t fastest = LONG_MAX;

    RadixMap *source_map = RadixMap_create(N);
    mu_assert(source_map != NULL, "Failed to make the map.");
    mu_assert(make_random(source_map), "Didn't make a random fake radix map.");

    for(i = 0; i < 100; i++) {
        RadixMap *map = RadixMap_create(N);
        mu_assert(map != NULL, "Failed to make the map.");

        mu_assert(RadixMap_copy(source_map, map) == 0,
                "Copying unsorted RadixMap failed.");

        clock_t elapsed = -clock();
        RadixMap_sort(map, 0, map->end);
        elapsed += clock();

        if(elapsed < fastest) fastest = elapsed;
        mu_assert(check_order(map), "Failed to sort the RadixMap.");

        RadixMap_destroy(map);
    }

    RadixMap_destroy(source_map);
    debug("Fastest time for size %zu: %f", N, ((float)fastest)/CLOCKS_PER_SEC);

    return NULL;
}
Beispiel #7
0
// test for big number of elements
static char *test_RadixMap_operations()
{
    size_t N = 200;

    RadixMap *map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");
    mu_assert(make_random(map), "Didn't make a random fake radix map.");

    RadixMap_sort(map);
    mu_assert(check_order(map), "Failed to properly sort the RadixMap.");

    mu_assert(test_search(map), "Failed the search test.");
    mu_assert(check_order(map), "RadixMap didn't stay sorted after search.");

    RadixMap_destroy(map);

    map = RadixMap_create(N);
    mu_assert(map != NULL, "Failed to make the map.");

    debug("PUSHING VALUES");
    mu_assert(push_random_values(map), "Didn't push random values.");
    debug("VALUES PUSHED!");

    mu_assert(check_order(map), "Map wasn't sorted after pushes.");

    debug("DOING DELETES");
    while(map->end > 0) {
        RMElement *el = RadixMap_find(map, map->contents[map->end / 2].data.key);
        mu_assert(el != NULL, "Should get a result.");

        size_t old_end = map->end;

        mu_assert(RadixMap_delete(map, el) == 0, "Didn't delete it.");
        mu_assert(old_end - 1 == map->end, "Wrong size after delete.");

        // test that the end is now the old value, but uint32 max so it trails off
        mu_assert(check_order(map), "RadixMap didn't stay sorted after delete.");
    }

    RadixMap_destroy(map);

    return NULL;
}
Beispiel #8
0
// test for big number of elements
static void test_radix (ulong N)
{
        rec *data = (rec *) malloc (N * sizeof (rec));
        assert (data != NULL);

        make_random (data, N);
        radix_sort (data, N);
        check_order (data, N);

        free (data);
}
Beispiel #9
0
 Mm check_order(Mm n_in, i_o_t, Mm& n_out__o, Mm& w__o) {
   begin_scope
   double old_nargin=nargin_val; nargin_val=1.0; nargin_set=1;
   double old_nargout=nargout_val; nargout_val=2.0; nargout_set=1;
   dMm(trivalwin__o); 
   check_order(n_in, i_o, n_out__o, w__o, trivalwin__o);
   nargout_val=old_nargout;
   nargin_val=old_nargin;
   return x_M;
   end_scope
 }
Beispiel #10
0
TEST_F(test_ivector, common_one)
{
  ivector v(1, 4);
  v(1) = 3;
  v(2) = 1;
  v(3) = 2;
  v(4) = -4;

  ivector w(1, 4);
  w(1) = -3;
  w(2) = 1;
  w(3) = -2;
  w(4) = 4;

  int common(ivector& v,ivector& w);
  EXPECT_TRUE(common(v, w) == 1);

  bool check_order(const ivector& v);
  ASSERT_TRUE(check_order(v));
  ASSERT_TRUE(check_order(w));
}
Beispiel #11
0
TEST_F(test_ivector, common_same)
{
  ivector v(1, 4);
  v(1) = 0;
  v(2) = 1;
  v(3) = 2;
  v(4) = -4;

  int common(ivector& v,ivector& w);
  EXPECT_TRUE(common(v, v) == 1);

  bool check_order(const ivector& v);
  ASSERT_TRUE(check_order(v));
}
Beispiel #12
0
/** main program to verify all traces passed */
int
main(int argc, char* argv[])
{
	rbtree_t* all_locks;
	int i;
	time_t starttime = time(NULL);
#ifdef USE_THREAD_DEBUG
	/* do not overwrite the ublocktrace files with the ones generated
	 * by this program (i.e. when the log code creates a lock) */
	check_locking_order = 0;
#endif
	if(argc <= 1) {
		usage();
		return 1;
	}
	log_init(NULL, 0, NULL);
	log_ident_set("lock-verify");
	/* init */
	all_locks = rbtree_create(order_lock_cmp);
	errors_detected = 0;

	/* read the input files */
	for(i=1; i<argc; i++) {
		readinput(all_locks, argv[i]);
	}

	/* check ordering */
	check_order(all_locks);

	/* do not free a thing, OS will do it */
	printf("checked %d locks in %d seconds with %d errors.\n", 
		(int)all_locks->count, (int)(time(NULL)-starttime),
		errors_detected);
	if(errors_detected) return 1;
	return 0;
}
/*
 *  stress_remap
 *	stress page remapping
 */
static int stress_remap(const args_t *args)
{
	mapdata_t *data;
	const size_t page_size = args->page_size;
	const size_t data_size = N_PAGES * page_size;
	const size_t stride = page_size / sizeof(*data);
	size_t i;

	data = mmap(NULL, data_size, PROT_READ | PROT_WRITE,
			MAP_SHARED | MAP_ANONYMOUS, -1, 0);
	if (data == MAP_FAILED) {
		pr_err("%s: mmap failed: errno=%d (%s)\n",
			args->name, errno, strerror(errno));
		return EXIT_NO_RESOURCE;
	}

	for (i = 0; i < N_PAGES; i++)
		data[i * stride] = i;

	do {
		size_t order[N_PAGES];

		/* Reverse pages */
		for (i = 0; i < N_PAGES; i++)
			order[i] = N_PAGES - 1 - i;

		if (remap_order(args, stride, data, order, page_size) < 0)
			break;
		check_order(args, stride, data, order, "reverse");

		/* random order pages */
		for (i = 0; i < N_PAGES; i++)
			order[i] = i;
		for (i = 0; i < N_PAGES; i++) {
			size_t tmp, j = mwc32() % N_PAGES;

			tmp = order[i];
			order[i] = order[j];
			order[j] = tmp;
		}

		if (remap_order(args, stride, data, order, page_size) < 0)
			break;
		check_order(args, stride, data, order, "random");

		/* all mapped to 1 page */
		for (i = 0; i < N_PAGES; i++)
			order[i] = 0;
		if (remap_order(args, stride, data, order, page_size) < 0)
			break;
		check_order(args, stride, data, order, "all-to-1");

		/* reorder pages back again */
		for (i = 0; i < N_PAGES; i++)
			order[i] = i;
		if (remap_order(args, stride, data, order, page_size) < 0)
			break;
		check_order(args, stride, data, order, "forward");

		inc_counter(args);
	} while (keep_stressing());

	(void)munmap(data, data_size);

	return EXIT_SUCCESS;
}
Beispiel #14
0
gboolean check_parse (ihm_trick_t *ihm_setup ,char *transbuf) {
  position_t position;
  color_t couleur=club;
  int tabref[est+1][cA+1];
  char *buf;
  char *pos="SONE";
  char *coul="TKCP";
  memset(tabref,0,(cA+1)*(est+1)*sizeof(int));


  for (position = sud; position < est + 1; position++) {
    if(NULL!=(buf=strchr(transbuf,'\n'))) {
      buf[0]='\0';
      if((strlen(transbuf)!=1) || transbuf[0]!=pos[position]) {
        fprintf(stderr,"Error in file parsing, strlen(buffer)=%d, %c!=%c\n",(int)strlen(transbuf),transbuf[0],(char)pos[position]);
        return FALSE;
      }
      transbuf=buf+1;
    }

    else {
      fprintf(stderr,"Error in file parsing, No \\n at the end of a line probably\n");
      return FALSE;
    }
        if(ihm_setup->debug|TRUE)
      fprintf(stdout,"Load of pos=%c\n",pos[position]);

    for (couleur = club; couleur < spade + 1; couleur++) {
      if(NULL!=(buf=strchr(transbuf,'\n'))) {
        buf[0]='\0';
        if(transbuf[0]!=coul[couleur]) {
          fprintf(stderr,"Error in file parsing,  %c!=%c\n",transbuf[0],coul[couleur]);
          free(transbuf);
          return FALSE;
        }

        if(!check_value(transbuf,couleur,tabref)){
          return FALSE;
        }
        if(!check_order(ihm_setup,transbuf)){
          return FALSE;
        }
        
        

        if(ihm_setup->debug)
          fprintf(stdout,"Load of col=%c\n",coul[couleur]);
        transbuf=buf+1;
      }
      else {
        fprintf(stderr,"Error in file parsing, buf=NULL\n");
        return FALSE;

      }


    }
  }
  return TRUE;

}
Beispiel #15
0
int main(void)
{
	check_order();
	check_attach();
	return 0;
}