Ejemplo n.º 1
0
int main(int argc, char *argv[])
{
  int n;
  int size;

  prog_name = argv[0];

  if (argc != 4) {
    printf("%s: %s num size dir\n", prog_name, prog_name);
    exit(1);
  }

  n = atoi(argv[1]);
  size = atoi(argv[2]);
  topdir = argv[3];

  printf("%s %d %d %s\n", prog_name, n, size, topdir);

  creat_dir();
  
  printstats(topdir, 1);
  
  creat_test(n, size);
  
  printstats(topdir, 0);

  read_test(n, size);
  delete_test(n);

  unlink("t");
  return 0;
}
Ejemplo n.º 2
0
void run_tests(int iter)
{
	testno = 1;
	snprintf(dirent_name, OCFS2_MAX_FILENAME_LEN,
                 "multi-indexed-dirs-test-%d", iter);
        snprintf(dir_name, OCFS2_MAX_FILENAME_LEN, "%s/%s", work_place,
                 dirent_name);

	if (test_flags & GROW_TEST)
		grow_test();
	
	if (test_flags & RENM_TEST)
		rw_test();

	if (test_flags & READ_TEST)
		read_test();

	if (test_flags & ULNK_TEST)
		unlink_test();

	if (test_flags & FLUP_TEST)
		fillup_test();

	if (test_flags & STRS_TEST)
		stress_test();
}
Ejemplo n.º 3
0
int main()
{
  /* write a PLY file */
  write_test();
  /* read a PLY file */
  read_test();
}
Ejemplo n.º 4
0
/*
 *	Test routines
 */
void
test_read(
	int	max)
{
	int i, ssk, usecs;
	struct timeval start, stop;

	if (max == 0)
		max = test_read_skew + 1;
	ssk = test_read_skew;
	for (i = test_read_skew_min; i < max; i++){
		test_read_skew = i;

		start = time;
		read_test();
		stop = time;

		usecs = stop.tv_usec - start.tv_usec;
		if (usecs < 0) {
			stop.tv_sec -= 1;
			usecs += 1000000;
		}
		printf("Skew %3d size %d count %d time %3d sec %d us\n",
			i, test_read_size, test_read_nreads,
			stop.tv_sec - start.tv_sec, usecs);
	}
	test_read_skew = ssk;
}
Ejemplo n.º 5
0
int
main(int argc, char *argv[])
{
    int ret = 0;

    if (argc != 2) {
        printf("Usage: %s [getattr|readdir|open|read]\n", argv[0]);
        ret = 1;
        goto out;
    }

    pagesize = getpagesize();

    if (strcmp(argv[1], "getattr") == 0) {
        ret = getattr_test();
    } else if (strcmp(argv[1], "readdir") == 0) {
        ret = readdir_test();
    } else if (strcmp(argv[1], "open") == 0) {
        ret = open_test();
    } else if (strcmp(argv[1], "read") == 0) {
        ret = read_test();
    } else if (strcmp(argv[1], "write") == 0) {
        ret = write_test();
    } else if (strcmp(argv[1], "remove") == 0) {
        ret = remove_test();
    }else if (strcmp(argv[1], "mkdir") == 0) {
        ret = mkdir_test();
    }else if (strcmp(argv[1], "rmdir") == 0) {
        ret = rmdir_test();
    }
out:
    exit(ret);
}
Ejemplo n.º 6
0
TEST_CASE PlotReaderTest()
{
    TEST(read_test("../DemoData/index", "fred", 10.0) > 0);

    epicsTime start;
    TEST(string2epicsTime("03/23/2004 10:50:00", start));
    TEST(read_test("../DemoData/index", "fred", 10.0, &start) > 0);

    epicsTime end(start);
    end += 15;
    TEST(read_test("../DemoData/index", "fred", 5.0, &start, &end) > 0);

    TEST(DataFile::clear_cache() == 0);

    TEST_OK;
}
Ejemplo n.º 7
0
int main(){
    FILE* f = fopen ("test_output6.txt", "w");
    int size;
    int sizeOfRegion = 1 << 20;// 1MB
    int a = psumeminit(1, sizeOfRegion);
    if (a == -1){
        fprintf(f, "Initialization failed!\n");
    }
    
    void* pointer_array[16][NUM];
    for (int i = 0; i < 16; i++){
        for (int j = 0; j < NUM; j++){
            pointer_array[i][j] = NULL;
        }
    }

    for (int i = 0; i < 16; i++){
        for (int j = 0; j < NUM; ++j)
        {
            size = rand()%248 + 8;
            test* a = (test*)psumalloc(size);
            write_test(a);
            read_test(a, f);
            if (a == NULL){
                fprintf(f, "No. %d: No extra space for allocation in memory!\n", j);
            }
            else{
                pointer_array[i][j] = a;
                fprintf(f, "NO.%d chunk has been allocated, the size is %d bytes\n", j, size);
            }
        }
    }
    
    int half = 16;
    while (half != 0){
        half /= 2;
        int bound;
        if (half){
            bound = half * 2;
        }
        else{
            bound = 1;
        }
        for (int i = half; i < bound ; i++){
            for (int j = 0; j < NUM; j++)
            {
                int a = psufree(pointer_array[i][j]);
                if (a == 0){
                    fprintf(f, "No.%d chunk has been freed. \n", j);
                }
                else{
                    fprintf(f, "Can not free No.%d chunk. \n", j);
                }
            }
        }
    }
    fclose(f);
    return 0;
}
Ejemplo n.º 8
0
int main(int argc, char *argv[])
{
  int n, fd;
  int size;

  prog_name = argv[0];

  if (argc != 4) {
    printf("%s: %s num size fsync\n", prog_name, prog_name);
    exit(1);
  }

  n = atoi(argv[1]);
  size = atoi(argv[2]);
  do_fsync = atoi (argv[3]);

  if (do_fsync != 0 && do_fsync != 1) {
    printf("%s: fsync 0 or 1!\n", prog_name);    
    exit (1);
  }

  printf("\n%s %d %d\n", prog_name, n, size);

  srandom(getpid());

  if((fd = creat(name, S_IRUSR | S_IWUSR)) < 0) {
    printf("%s: create %d failed %d\n", prog_name, fd, errno);
    exit(1);
  }
  close (fd);

  flush_cache ();
  write_test(n, size, 1);
  read_test(n, size, 1);
  write_test(n , size, 0);
  read_test(n, size, 0);
  read_test(n , size, 1);

  unlink(name);

  return 0;
}
Ejemplo n.º 9
0
void run_tests(void) {
  int i = 0;

  read_test(100, 8192);
  read_test(10000, 8192);
  read_test(10000, 137);
  read_test(10000, 1);
  large_read_test(8192);
  large_read_test(1);

  write_test(100, 8192);
  write_test(100, 1);
  write_test(100000, 8192);
  write_test(100000, 1);
  write_test(100000, 137);

  for (i = 1; i < 1000; i = GPR_MAX(i + 1, i * 5 / 4)) {
    write_test(40320, i);
  }
}
TEST_CASE RawDataReaderTest()
{
    TEST(read_test("../DemoData/index", "fred") == 87);

    epicsTime start;
    TEST(string2epicsTime("03/23/2004 10:50:42.400561000", start));
    TEST(read_test("../DemoData/index", "fred", &start) == 10);
#ifdef CHECK_AUTO_INDEX
    TEST(auto_read_test("../DemoData/index", "fred", &start) == 10);
    TEST(auto_read_test("list_index.xml", "fred", &start) == 10);
#endif
    epicsTime end(start);
    end += 5;
    TEST(read_test("../DemoData/index", "fred", &start, &end) == 3);
#ifdef CHECK_AUTO_INDEX
    TEST(auto_read_test("../DemoData/index", "fred", &start, &end) == 3);
    TEST(auto_read_test("list_index.xml", "fred", &start, &end) == 3);
#endif
    TEST(DataFile::clear_cache() == 0);
    TEST_OK;
}
Ejemplo n.º 11
0
main()
{

#if 1
  /* write a PLY file */
  write_test();
#endif

#if 1
  /* read a PLY file */
  read_test();
#endif

}
Ejemplo n.º 12
0
/*
 * Test whether writing to counter works.
 */
static void write_test(int fd)
{
    int ret;
    uint64_t val;

    val = 12;

    ret = set_counter(fd, val);
    if (ret == -1) {
        tst_resm(TBROK, "error setting counter value to %" PRIu64, val);
        return;
    }

    read_test(fd, val);
}
Ejemplo n.º 13
0
int main(int argc, char **argv)
{
    int lc;
    int fd;

    tst_parse_opts(argc, argv, NULL, NULL);

    setup();

    for (lc = 0; TEST_LOOPING(lc); lc++) {
        int ret;
        uint64_t einit = 10;

        tst_count = 0;

        fd = myeventfd(einit, 0);
        if (fd == -1)
            tst_brkm(TBROK | TERRNO, CLEANUP,
                     "error creating eventfd");

        ret = fcntl(fd, F_SETFL, O_NONBLOCK);
        if (ret == -1)
            tst_brkm(TBROK | TERRNO, CLEANUP,
                     "error setting non-block mode");

        read_test(fd, einit);
        read_eagain_test(fd);
        write_test(fd);
        write_eagain_test(fd);
        read_einval_test(fd);
        write_einval_test(fd);
        write_einval2_test(fd);
        readfd_set_test(fd);
        readfd_not_set_test(fd);
        writefd_set_test(fd);
        writefd_not_set_test(fd);
        child_inherit_test(fd);
        overflow_select_test(fd);
        overflow_poll_test(fd);
        overflow_read_test(fd);

        close(fd);
    }

    cleanup();

    tst_exit();
}
Ejemplo n.º 14
0
void main(int argc, char *argv[])
{
	int opt;
	unsigned char write_enable = 0;
	char *device = NULL;
	unsigned int blocks = 0;
	int blocksize = 1024;
	int repeats = 1;

	printf("RetroDisk Profiler\n");

	while((opt = getopt(argc,argv,"wd:b:s:r:"))!=-1)
	{
		switch(opt)
		{
			case 'w':
				printf("Write tests enabled!\n");
				write_enable=1;
				break;
			case 'd':
				device = optarg;
				break;
			case 'b':
				blocks = atoi(optarg);
				break;
			case 's':
				blocksize = atoi(optarg);
				break;
			case 'r':
				repeats = atoi(optarg);
				break;
		}
	}
	
	if(device==NULL)
	{
		usage();
	}

	read_test(device,blocks,blocksize,repeats);
	if(write_enable==1)
		write_test(device,blocks,blocksize,repeats);
}
Ejemplo n.º 15
0
int main(){
    FILE* f = fopen ("test_output8.txt", "w");
    int size;
    int sizeOfRegion = 1 << 20;// 1MB
    int a = psumeminit(1, sizeOfRegion);
    if (a == -1){
        fprintf(f, "Initialization failed!\n");
    }
    for (int i = 0; i < 10; i++){
        void* pointer_array[NUM];
        for (int i = 0; i < NUM; ++i){
            pointer_array[i] = NULL;
        }
        for (int i = 0; i < NUM; ++i)
        {
            size = rand()%248 + 8;
            test* a = (test*)psumalloc(size);
            write_test(a);
            read_test(a, f);
            if (a == NULL){
                fprintf(f, "No.%d : No extra space for allocation in memory!\n", i);
            }
            else{
                pointer_array[i] = a;
                fprintf(f, "NO.%d chunk has been allocated. the size is %d bytes \n", i, size);
            }
        }
        
        for (int i = 0; i < NUM; ++i)
        {
            int a = psufree(pointer_array[i]);
            if (a == 0){
                fprintf(f, "No.%d chunk has been freed. \n", i);
            }
            else{
                fprintf(f, "Can not free No.%d chunk. \n", i);
            }
        }
    }
    fclose(f);
    return 0;
}
Ejemplo n.º 16
0
int mymain()
{
	unsigned char c = 68;
	//clock_init();
	uart_init();
	// 初始化nandflash
	nand_init();
	
	while (1)
	{
		printf("\r\n********Nandflash R/W Test*******\r\n");
		printf("[i] Read ID\r\n");
		printf("[e] Erase Nandflash\r\n");
		printf("[w] Write Nandflash\r\n");
		printf("[r] Read  Nandflash\r\n");
		printf("[n] read sdram to nand\r\n");
		printf("Enter your choice: ");
		c = getc();
		printf("%c\r\n",c);
		
		switch(c)
		{
		case 'i':
			nand_read_id();
			break;
		case 'e':
			erase_test();
			break;
		case 'w':
			write_test();
			break;
		case 'r':
			read_test();
			break;
		case 'n':
			sdram_to_nand_test();
			break;
		}
	}
	return 0;
}
Ejemplo n.º 17
0
static int				/* O - Standard input of child */
run_read_test(void)
{
  int	ras_pipes[2];			/* Raster data pipes */
  int	pid;				/* Child process ID */


  if (pipe(ras_pipes))
    return (-1);

  if ((pid = fork()) < 0)
  {
   /*
    * Fork error - return -1 on error...
    */

    close(ras_pipes[0]);
    close(ras_pipes[1]);

    return (-1);
  }
  else if (pid == 0)
  {
   /*
    * Child comes here - read data from the input pipe...
    */

    close(ras_pipes[1]);
    read_test(ras_pipes[0]);
    exit(0);
  }
  else
  {
   /*
    * Parent comes here - return the output pipe...
    */

    close(ras_pipes[0]);
    return (ras_pipes[1]);
  }
}
Ejemplo n.º 18
0
XAttrManager::XAttrManager(const Glib::ustring& filename) throw (XAttrManagerException)
	: _filename(filename)
{
	// Check it is an ordinary file or a directory
	struct stat buffer;
	if (stat(_filename.c_str(), &buffer) == -1)
	{
		throw XAttrManagerException(Glib::locale_to_utf8(strerror(errno)));
	}

	if (!S_ISREG(buffer.st_mode) && !S_ISDIR(buffer.st_mode))
	{
		throw XAttrManagerException(_("Only regular files or directories supported")); 
	}

	this->_owner = buffer.st_uid;
	
	// FIXME Crappy way to detect if we can modify xattrs,
    // it will thrown a exception if they cannot be read
	read_test();
}
Ejemplo n.º 19
0
static int worker_run(struct worker *self)
{
	char buf[BUFFER_SIZE];
	struct sigaction term_sa = {
		.sa_handler = SIG_IGN,
		.sa_flags = 0,
	};
	struct queue *q = self->q;

	sigaction(SIGTTIN, &term_sa, NULL);

	while (1) {
		if (!queue_pop(q, buf))
			break;

		read_test(buf);
	}

	queue_destroy(q, 1);
	tst_flush();
	return 0;
}

static void spawn_workers(void)
{
	int i;
	struct worker *wa = workers;

	bzero(workers, worker_count * sizeof(*workers));

	for (i = 0; i < worker_count; i++) {
		wa[i].q = queue_init();
		wa[i].pid = SAFE_FORK();
		if (!wa[i].pid)
			exit(worker_run(wa + i));
	}
}
Ejemplo n.º 20
0
int main(int argc, char **argv)
{
/* 初期値設定  c getopt用変数 size サイズ(1048576byte)
		rcount 読み込み回数(0回) wcount 書き込み回数(0回)
		sizesw size option が設定されたかどうかのフラグ
		filename ファイルの名前("/tmp/io-bench.tmp")
		st statbuf stat用領域  */
	int c;
	int size = 1048576;
	int rcount = 0;
	int wcount = 0;
	int sizesw = 0;
	char filename[PATH_MAX];
	int st;
	struct stat statbuf;

/* ファイルサイズ処理関連の変数初期化 */
	int mem[4];       /* キロ、メガ、ギガ 用の基数保存用 */
	char *ans;        /* 文字検索用ポインタ保存域 */
	char mainbuff[PATH_MAX]="kKmMgG", findbuff[PATH_MAX]="", sizebuff[PATH_MAX]="";
	int x;            /* ポインタの場所記憶域 */
	strcpy(filename, "/tmp/io-bench.tmp");
	mem[1] = 1024;
	mem[2] = 1048576;
	mem[3] = 1073741824;

/* オプションの設定 	r: 読み込みオプション rcount
			w: 書き込みオプション wcount
			s: サイズオプション size
			オプション無し…ファイル名…filename	*/
	while   ((c = getopt(argc, argv, "r:w:s:")) > 0)  {
		switch  (c) {
		case  'r':
			rcount = atoi(optarg);
			break;

		case  'w':
			wcount = atoi(optarg);
			break;

		case  's':
			memmove(sizebuff, optarg, strlen(optarg) - 1);
			memmove(findbuff, optarg + strlen(optarg) - 1, 1);
			ans = strstr(mainbuff, findbuff);
			if (ans != NULL) {
				x = (int)(ans - mainbuff) + 2;
				x = x / 2;
				size = atoi(sizebuff) * mem[x];
			}
			else {
				size = atoi(optarg);
			}
			sizesw = 1;
			break;

		default:
			printf("io-bench [-r count][-w coount][-s size]");
			printf("[dirname | dirname/filename]");
			printf("\n\n	-r count   [count] times read.	default 0.");
			printf("\n\n	-w count   [count] times write.	default 0.");
			printf("\n\n	-s size   [size] file open.	");
			printf("default 1M or filesize\n\n");
			printf("	default filename '/tmp/io-bench.tmp'");
			printf("\n\n	for example './io-bench -r 10 -w 10 -s");
			printf(" 1024K /tmp/io-bench.tmp'\n\n");
			exit(1);
		}
	}

/* ファイル名の指定があった場合filenameにファイル名を代入 */
	if (optind < argc) {
		strcpy(filename, argv[optind++]);
	}

/* 指定されたファイルがファイルか、ディレクトリかを判別 */
	errno = 0;
	st = stat(filename, &statbuf);
	if (st == -1) {
		if (errno != ENOENT) {
			perror(filename);
			exit (1);
		}
	}
	else {	/* filemodeがディレクトリの場合 ディレクトリ+/io-bench.tmp */
		if (S_ISDIR(statbuf.st_mode)) {
			strcat(filename, "/io-bench.tmp");
		}
	}

/* filename のファイルサイズをサイズに代入(size指定が無い場合) */
	st = stat(filename, &statbuf);
	if (st == -1) {
	}
	else {
		if (sizesw == 0) {
			size = statbuf.st_size;
		}
	}


/* 書き込み処理、読み込み処理  回数が0の場合実行しない	*/
	if (wcount > 0) {
		write_test(wcount, size, filename);
	}
	if (rcount > 0) {
		read_test(rcount, size, filename);
	}
	return 0;
}
Ejemplo n.º 21
0
Archivo: t-data.c Proyecto: gpg/gpgme
int
main (int argc, char **argv)
{
  round_t round = TEST_INITIALIZER;
  char *text_filename = make_filename ("t-data-1.txt");
  char *longer_text_filename = make_filename ("t-data-2.txt");
  const char *missing_filename = "this-file-surely-does-not-exist";
  gpgme_error_t err = 0;
  gpgme_data_t data;

  while (++round)
    {
      switch (round)
	{
	case TEST_INVALID_ARGUMENT:
	  err = gpgme_data_new (NULL);
	  if (!err)
	    {
	      fprintf (stderr, "%s:%d: gpgme_data_new on NULL pointer succeeded "
		       "unexpectedly\n", __FILE__, __LINE__);
	      exit (1);
	    }
	  continue;
	case TEST_INOUT_NONE:
	  err = gpgme_data_new (&data);
	  break;
	case TEST_INOUT_MEM_NO_COPY:
	  err = gpgme_data_new_from_mem (&data, text, strlen (text), 0);
	  break;
	case TEST_INOUT_MEM_COPY:
	  err = gpgme_data_new_from_mem (&data, text, strlen (text), 1);
	  break;
	case TEST_INOUT_MEM_FROM_FILE_COPY:
	  err = gpgme_data_new_from_file (&data, text_filename, 1);
	  break;
	case TEST_INOUT_MEM_FROM_INEXISTANT_FILE:
	  err = gpgme_data_new_from_file (&data, missing_filename, 1);
	  if (!err)
	    {
	      fprintf (stderr, "%s:%d: gpgme_data_new_from_file on inexistant "
		       "file succeeded unexpectedly\n", __FILE__, __LINE__);
	      exit (1);
	    }
	  continue;
	case TEST_INOUT_MEM_FROM_FILE_NO_COPY:
	  err = gpgme_data_new_from_file (&data, text_filename, 0);
	  /* This is not implemented yet.  */
	  if (gpgme_err_code (err) == GPG_ERR_NOT_IMPLEMENTED
	      || gpgme_err_code (err) == GPG_ERR_INV_VALUE)
	    continue;
	  break;
	case TEST_INOUT_MEM_FROM_FILE_PART_BY_NAME:
	  err = gpgme_data_new_from_filepart (&data, longer_text_filename, 0,
					      strlen (text), strlen (text));
	  break;
	case TEST_INOUT_MEM_FROM_INEXISTANT_FILE_PART:
	  err = gpgme_data_new_from_filepart (&data, missing_filename, 0,
					      strlen (text), strlen (text));
	  if (!err)
	    {
	      fprintf (stderr, "%s:%d: gpgme_data_new_from_file on inexistant "
		       "file succeeded unexpectedly\n", __FILE__, __LINE__);
	      exit (1);
	    }
	  continue;
	case TEST_INOUT_MEM_FROM_FILE_PART_BY_FP:
	  {
	    FILE *fp = fopen (longer_text_filename, "rb");
	    if (! fp)
	      {
		fprintf (stderr, "%s:%d: fopen: %s\n", __FILE__, __LINE__,
			 strerror (errno));
		exit (1);
	      }
	    err = gpgme_data_new_from_filepart (&data, 0, fp,
						strlen (text), strlen (text));
	  }
	  break;
	case TEST_END:
	  goto out;
	case TEST_INITIALIZER:
	  /* Shouldn't happen.  */
	  fprintf (stderr, "%s:%d: impossible condition\n", __FILE__, __LINE__);
	  exit (1);
	}
      fail_if_err (err);

      read_test (round, data);
      write_test (round, data);
      gpgme_data_release (data);
    }
 out:
  free (text_filename);
  free (longer_text_filename);
  return 0;
}
Ejemplo n.º 22
0
int main(){
    
    
    printf("You entered: %d\n", a);

    // LSMT parameters from user inputs
    int Nc, size, ratio, value_size;
    printf("Define the number of components: ");
    scanf("%d", &Nc);
    printf("Define the size of C0: ");
    scanf("%d", &size);
    printf("Define the ratio: ");
    scanf("%d", &ratio);
    printf("Define the value size: ");
    scanf("%d", &value_size);
    char *name = (char *) malloc(FILENAME_SIZE * sizeof(char));
    printf("Define the name of the LSM tree: ");
    scanf("%s", name);

    // ------------------------ BUILDING THE LSM TREE
    int* Cs_size = (int *) malloc((Nc+2) * sizeof(int));
    Cs_size[0] = size;
    for (int i=1; i<(Nc+2); i++) Cs_size[i] = ratio * Cs_size[i-1];

    LSM_tree  *lsm =  (LSM_tree*) malloc(sizeof(LSM_tree));
    

    // Read test
    read_test(lsm, 100);
    read_test(lsm, 1000);
    read_test(lsm, 10000);
    read_test(lsm, 100000);
    read_test(lsm, 999999);
    read_test(lsm, 1000000);


    // ---------------- TEST READING LSM FROM DISK
    printf("%d\n",BLOOM_ON);
    printf("%d\n",BLOOM_ON);
    printf("Reading LSM from disk:\n");
    LSM_tree *lsm_backup = (LSM_tree *)malloc(sizeof(LSM_tree));
    read_lsm_from_disk(lsm_backup, name, FILENAME_SIZE);
    print_state(lsm_backup);

    // Read test
    read_test(lsm_backup, 100);
    read_test(lsm_backup, 1000);
    read_test(lsm_backup, 10000);
    read_test(lsm_backup, 100000);
    read_test(lsm_backup, 999999);
    read_test(lsm_backup, 1000000);

    // PARALLEL READING TEST
    printf("----------------------------------\n");
    printf("PARALLEL READS\n");
    printf("----------------------------------\n");
    read_parallel_test(lsm_backup, 999);
    printf("----------------------------------\n");
    read_parallel_test(lsm_backup, 9999);
    printf("----------------------------------\n");
    read_parallel_test(lsm_backup, 51215);
    printf("----------------------------------\n");
    read_parallel_test(lsm_backup, 215841);
    printf("----------------------------------\n");

    //update/delete tests
    // To store the value to update
    char* value = (char*) malloc(lsm_backup->value_size * sizeof(char));
    int key = 999;
    // Filling the updated value
    for (int i=0; i<lsm_backup->value_size - 7; i++) value[i] = 'b';
    sprintf(value + lsm_backup->value_size - 7, "_%d", key%10000);
    // update_lsm(lsm_backup, key, value);
    delete_lsm(lsm_backup, 999);
    read_test(lsm_backup, key);


    // Wrap up
    print_state(lsm_backup);
    write_lsm_to_disk(lsm_backup);
    free_lsm(lsm_backup);
}
int main () {
	
	// utility parameters
	int n, i;
	
	clean_array((int*)count_case_0, 2097152*5);
	clean_array((int*)count_case_1, 2097152*5);
	
	// read the train.csv data
	FILE *train;
	train = fopen ("train.csv", "r");
	while (fgetc(train) != '\n') ;  // skip the head line

	int id, delta, initial_grid[24][24], start_grid[24][24], stop_grid[24][24];
	clean_array((int*)initial_grid, 24*24);
	clean_array((int*)start_grid, 24*24);
	clean_array((int*)stop_grid, 24*24);
	
	// read all the train set and make statistical table for them
	for (n = 0; n < 50000; ++n) {
		read_train(train, &id, &delta, (int*)start_grid);
		for (i = 0; i < delta; ++i) {
			conway_step(start_grid, stop_grid);
			vote_step(start_grid, stop_grid, count_case_0[i], count_case_1[i]);
			copy_grid(start_grid, stop_grid);
		}
	}
	
	// vote for statistical table
	for (i = 0; i < 5; ++i) {
		for (n = 0; n < 2097152; ++n) 
			vote_case[i][n] = vote_pattern(n, count_case_0[i][n], count_case_1[i][n], i);
	}
	
	//------------------------------------------------------------------
	
	// check prediction accuracy
	///*
	train = fopen ("train.csv", "r");
	while (fgetc(train) != '\n') ;  // skip the head line
	
	FILE *pred;
	pred = fopen ("pred.csv", "w");
	fprintf(pred, "id,");
	for (n = 1; n < 401; ++n) fprintf(pred, "start.%d,", n);
	for (n = 1; n < 400; ++n) fprintf(pred, "diff.%d,", n);
	fprintf(pred, "diff.400\n");
	
	double difference_all = 0;
	for (n = 0; n < 50000; ++n) {
		read_train (train, &id, &delta, (int*)initial_grid);
		copy_grid(start_grid, initial_grid);

		for (i = 0; i < delta; ++i) {
			conway_step(start_grid, stop_grid);
			copy_grid(start_grid, stop_grid);
		}
		
		for (i = delta-1; i >= 0; --i) {
			reverse_step (start_grid, stop_grid, vote_case[i]);
			copy_grid(stop_grid, start_grid);
		}
		write_pred(pred, id, initial_grid, start_grid);
		difference_all += difference_grid(initial_grid, start_grid);
	}
	printf("training set score: %f\n", difference_all/50000);
	fclose(pred);
	//*/

	fclose(train);
	
	//------------------------------------------------------------------
	
	// make submission file
	///*
	FILE *test;
	test = fopen ("test.csv", "r");
	while (fgetc(train) != '\n') ;  // skip the head line
	
	FILE *submission;
	submission = fopen ("submission.csv", "w");
	fprintf(submission, "id,");
	for (n = 1; n < 400; ++n) fprintf(submission, "start.%d,", n);
	fprintf(submission, "start.400\n");
	
	for (n = 0; n < 50000; ++n) {
		read_test(test, &id, &delta, stop_grid);
		
		for (i = delta-1; i >= 0; --i) {
			reverse_step (start_grid, stop_grid, vote_case[i]);
			copy_grid(stop_grid, start_grid);
		}
		write_submission(submission, id, start_grid);
	}
	
	fclose(test);
	fclose(submission);
	//*/
	
	return 0;
	// training set score: 0.12549
	// real score: 0.12687 	

	// I also tried set up vote_case table cutoff based on different delta number.
	// it may helps (the entire table parameter need a long time to be fixed),
	// but a naive setup of the final step (5->6) to 0.5 makes everything goes worse.
}
int main(int argc, char **argv[])
{
	string name;
	vector<Mat>Images(100), TestImages(50);
	vector<Mat> Descriptor(100), TestDescriptor(50), TestPcafeature(50);
	vector<vector<KeyPoint>>Keypoints(100), TestKeypoint(50);
	Mat histogram = Mat::zeros(100, Cluster, CV_32F);
	Mat Testhistogram = Mat::zeros(50, Cluster, CV_32F);
	Mat Keyword = Mat::zeros(Cluster, 20, CV_32F);
	Mat full_Descriptor, Pcafeature, Pcaduplicate, clusteridx, trainlabels(100, 1, CV_32F);
	vector<vector<DMatch>> matches(50);
	Mat predicted(Testhistogram.rows, 1, CV_32F);

	// Read Training Images.
	read_train(Images, name);

	//Calculate SIFT features for the Training Images.
	calculate_SIFT(Images,Keypoints,Descriptor);
	merge_descriptor(full_Descriptor,Descriptor);

	//Compute PCA for all the features across all Images.
	PCA pca;
	perform_PCA(full_Descriptor, Pcafeature, pca);
	
	//Perform K-Means on all the PCA reduced features.
	Pcafeature.convertTo(Pcaduplicate, CV_32F);
	calculate_Kmeans(Pcaduplicate, clusteridx);

	//Calculate the Keywords in the Feature Space.
	make_dictionary(clusteridx, Pcaduplicate, Keyword);

	//Get the Histogram for each Training Image.
	hist(Descriptor, clusteridx, histogram);

	//Read Test Image
	read_test(TestImages, name);

	//Calculate the SIFT feature for all the test Images.
	calculate_SIFT(TestImages, TestKeypoint, TestDescriptor);

	//Project the SIFT feature of each feature on the lower dimensional PCA plane calculated above. 
	pca_testProject(TestDescriptor, TestPcafeature, pca);

	//Find the Label by searching for keywords closest to current feature.
	get_matches(TestPcafeature,Keyword,matches);

	//Calculate Histogram for each test Image.
	hist_test(TestDescriptor, matches, Testhistogram);
	
	//Perform classification through Knn Classifier. 
	train_labels(trainlabels);
	KNearest knn;
	train_classifier(histogram, trainlabels, knn);
	test_classify(Testhistogram,predicted,knn);

	//Calculate Accuracy for each class.
	calculate_accuracy(predicted);
	
	getchar();
	return 0;
}
Ejemplo n.º 25
0
int main(){
    struct timeval start;
    struct timeval finish;
	FILE* f = fopen ("test_output3.txt", "w");
	int size;
	int sizeOfRegion = 1 << 20;// 1MB
	int a = psumeminit(0, sizeOfRegion);
	if (a == -1){
		fprintf(f, "Initialization failed!\n");
	}
    void* sample_malloc[20];
    void* sample_free[20];
    for (int i = 0; i < 20; i++){
		void* pointer_array[NUM];
        for (int i = 0; i < NUM; i++){
            pointer_array[i] = NULL;
        }
        int duration_malloc = 0;
		for (int i = 0; i < NUM; ++i)
		{
			if (i % 2 == 0){
				size = 64;
			}
			else{
				size = 64 * 1024;
			}
            gettimeofday(&start,NULL);
			test* a = (test*)psumalloc(size);
            gettimeofday(&finish,NULL);
            
             duration_malloc += (finish.tv_sec*1000000 + finish.tv_usec)- (start.tv_sec*1000000 + start.tv_usec);
            
            write_test(a);
            read_test(a, f);
			if (a == NULL){
				fprintf(f, "No extra space for allocation in memory!\n");
			}
			else{
				pointer_array[i] = a;
				fprintf(f, "NO.%d chunk has been allocated. the size is %d bytes\n", i, size);
			}
        }sample_malloc[i] = duration_malloc;

        int duration_free = 0;
		for (int i = 0; i < NUM; ++i)
		{
			gettimeofday(&start,NULL);
            int a = psufree(pointer_array[i]);
            gettimeofday(&finish,NULL);
			if (a == 0){
				fprintf(f, "No.%d chunk has been freed. \n", i);
			}
			else{
				fprintf(f, "Can not free No.%d chunk. \n", i);
			}
		}sample_free[i] = duration_free;
    }
    qsort((void *)sample_malloc, 20, sizeof(sample_malloc[0]), (int (*)(const void*, const void*))strcmp );
    qsort((void *)sample_free, 20, sizeof(sample_free[0]), (int (*)(const void*, const void*))strcmp );
    printf("\n25th percentile psumalloc=%d",sample_malloc[4]);
    printf("\n75th percentile psumalloc=%d",sample_malloc[14]);
    printf("\nAverage psumalloc=%d\n",sample_malloc[9]);
    printf("\n25th percentile psufree=%d",sample_free[4]);
    printf("\n75th percentile psufree=%d",sample_free[14]);
    printf("\nAverage psufree=%d\n",sample_free[9]);
	fclose(f);
	return 0;
}
void reverse_step (int start_grid[][24], int stop_grid[][24], int vote_case[]) {
	int i, j, n, idx;
	FLIP_STACK fs = {.size = 0};
	for (i = 2; i < 22; ++i) {
		for (j = 2; j < 22; ++j) {	
			idx = get_pattern_idx(stop_grid, i, j);
			start_grid[i][j] = vote_case[idx]%2;
			if (vote_case[idx] >= 2) push_flip(&fs, i, j);		
		}
	}
	
	FLIP_POINT ijp;
	double score_start, score_flip;
	for (n = fs.size; n > 0; --n) {
		score_start = difference_forward(start_grid, stop_grid);
		ijp = pop_flip(&fs);
		flip_point(ijp.i, ijp.j, start_grid);
		score_flip = difference_forward(start_grid, stop_grid);
		if (score_start <= score_flip) flip_point(ijp.i, ijp.j, start_grid);
	}
}

////////////////////////////////////////////////////////////////////////

unsigned int count_case_0[5][2097152], count_case_1[5][2097152]; // 2097152 = pow(2, 21)
int vote_case[5][2097152];
//double probability_case[5][2097152];

int main () {
	
	// utility parameters
	int n, i;
	
	clean_array((int*)count_case_0, 2097152*5);
	clean_array((int*)count_case_1, 2097152*5);
	
	// read the train.csv data
	FILE *train;
	train = fopen ("train.csv", "r");
	while (fgetc(train) != '\n') ;  // skip the head line

	int id, delta, initial_grid[24][24], start_grid[24][24], stop_grid[24][24];
	clean_array((int*)initial_grid, 24*24);
	clean_array((int*)start_grid, 24*24);
	clean_array((int*)stop_grid, 24*24);
	
	// read all the train set and make statistical table for them
	for (n = 0; n < 50000; ++n) {
		read_train(train, &id, &delta, (int*)start_grid);
		for (i = 0; i < delta; ++i) {
			conway_step(start_grid, stop_grid);
			vote_step(start_grid, stop_grid, count_case_0[i], count_case_1[i]);
			copy_grid(start_grid, stop_grid);
		}
	}
	
	// vote for statistical table
	for (i = 0; i < 5; ++i) {
		for (n = 0; n < 2097152; ++n) {
			vote_case[i][n] = vote_pattern(n, count_case_0[i][n], count_case_1[i][n], i);
			
			//if (count_case_0[i][n]+count_case_1[i][n] == 0) probability_case[i][n] = 0;
			//else probability_case[i][n] = (double)count_case_1[i][n] / (double)(count_case_0[i][n]+count_case_1[i][n]);
		}
	}
	
	//------------------------------------------------------------------
	
	// check prediction accuracy
	/*
	train = fopen ("train.csv", "r");
	while (fgetc(train) != '\n') ;  // skip the head line
	
	FILE *pred;
	pred = fopen ("pred.csv", "w");
	fprintf(pred, "id,");
	for (n = 1; n < 401; ++n) fprintf(pred, "start.%d,", n);
	for (n = 1; n < 400; ++n) fprintf(pred, "diff.%d,", n);
	fprintf(pred, "diff.400\n");
	
	double difference_all = 0;
	for (n = 0; n < 50000; ++n) {
		read_train (train, &id, &delta, (int*)initial_grid);
		copy_grid(start_grid, initial_grid);

		for (i = 0; i < delta; ++i) {
			conway_step(start_grid, stop_grid);
			copy_grid(start_grid, stop_grid);
		}
		
		for (i = delta-1; i >= 0; --i) {
			reverse_step (start_grid, stop_grid, vote_case[i]);
			copy_grid(stop_grid, start_grid);
		}
		write_pred(pred, id, initial_grid, start_grid);
		difference_all += difference_grids(initial_grid, start_grid);
	}
	printf("training set score: %f\n", difference_all/50000);
	fclose(pred);
	*/

	fclose(train);
	
	//------------------------------------------------------------------
	
	// make submission file
	///*
	FILE *test;
	test = fopen ("test.csv", "r");
	while (fgetc(train) != '\n') ;  // skip the head line
	
	FILE *submission;
	submission = fopen ("submission.csv", "w");
	fprintf(submission, "id,");
	for (n = 1; n < 400; ++n) fprintf(submission, "start.%d,", n);
	fprintf(submission, "start.400\n");
	
	for (n = 0; n < 50000; ++n) {
		read_test(test, &id, &delta, stop_grid);
		
		for (i = delta-1; i >= 0; --i) {
			reverse_step (start_grid, stop_grid, vote_case[i]);
			copy_grid(stop_grid, start_grid);
		}
		write_submission(submission, id, start_grid);
	}
	
	fclose(test);
	fclose(submission);
	//*/
	
	return 0;
	// training set score: 0.124948 (-0.00054)
	// real score: 0.12685 (-0.00002)
	// actual improvement is really tiny compare to the training set one.
}
Ejemplo n.º 27
0
Archivo: read_all.c Proyecto: kraj/ltp
static int worker_run(struct worker *self)
{
	char buf[BUFFER_SIZE];
	struct sigaction term_sa = {
		.sa_handler = SIG_IGN,
		.sa_flags = 0,
	};
	struct queue *q = self->q;

	sigaction(SIGTTIN, &term_sa, NULL);

	while (1) {
		if (!queue_pop(q, buf))
			break;

		read_test(buf);
	}

	queue_destroy(q, 1);
	tst_flush();
	return 0;
}

static void maybe_drop_privs(void)
{
	struct passwd *nobody;

	if (!drop_privs)
		return;

	TEST(setgroups(0, NULL));
	if (TST_RET < 0 && TST_ERR != EPERM) {
		tst_brk(TBROK | TTERRNO,
			"Failed to clear suplementary group set");
	}

	nobody = SAFE_GETPWNAM("nobody");

	TEST(setgid(nobody->pw_gid));
	if (TST_RET < 0 && TST_ERR != EPERM)
		tst_brk(TBROK | TTERRNO, "Failed to use nobody gid");

	TEST(setuid(nobody->pw_uid));
	if (TST_RET < 0 && TST_ERR != EPERM)
		tst_brk(TBROK | TTERRNO, "Failed to use nobody uid");
}

static void spawn_workers(void)
{
	int i;
	struct worker *wa = workers;

	bzero(workers, worker_count * sizeof(*workers));

	for (i = 0; i < worker_count; i++) {
		wa[i].q = queue_init();
		wa[i].pid = SAFE_FORK();
		if (!wa[i].pid) {
			maybe_drop_privs();
			exit(worker_run(wa + i));
		}
	}
}
Ejemplo n.º 28
0
main()
	{
	double t,wps;
	int str;
	ui count,buflen;
	int i,pcount=0;
	char strbuf[10];

	/* Open our log file */
	for(i=1; i<32; ++i)
	   {
	   sprintf(strbuf,"cache.%d",i);
	   if (access(strbuf,0)) break;
	   }
	record=fopen(strbuf,"w");
	if (record==NULL) printf("Could not open record file %s. No record kept\n",strbuf);
	else printf("\t\tA copy of this run will be kept in %s\n\n",strbuf);

	printf("Memory tester v1.0\n");
	printf("Author: [email protected], January 1996\n\n");
	printf("On this machine, one word = %d bytes\n",sizeof(ui *));
	printf("Reported access times are in nS per word.\n\n");
	if (record!=NULL)
	   {
	   fprintf(record,"On this machine, one word = %d bytes\n",sizeof(ui *));
	   fprintf(record,"Reported access times are in nS per word.\n\n");
	   }

	/* Start with a block of 256 words, each word is of type (ui *) */
	build_buffer(256,1);
	count=8;
	do
	   {
	   count *= 2;
	   t = read_test(count);
	   }
	while(t < 2);

	fflush(stdout);

	print_header();
	count = (ui)((double)count * LOOPTIME / t);
	for(buflen=256; buflen<=MAXBSIZE; buflen*=2)
	   {
	   if (buflen<256*1024) sprintf(strbuf,"%uk",buflen/256);
	   else sprintf(strbuf,"%uM",buflen/(256*1024));

	   printf("%-5.5s|",strbuf); fflush(stdout);
	   if (record!=NULL) fprintf(record,"%-5.5s|",strbuf);

	   for(str=1; str<buflen; str*=2)
	   	{
	   	build_buffer(buflen,str);

	   	while(1)
	      	   {
	      	   t = read_test(count);
	      	   if (t<1.0) count*=3; else break;
	      	   }
	
	   	wps = (double)(count) / t;
	  	wps = 1.0e9 / wps;
		if (wps>=1000)
		   {
	    	   printf("1k+ ");
	    	   if (record!=NULL) fprintf(record,"1k+ ");
		   }
		else 
		   {
		   printf("%-3d ", (int)wps);
		   if (record!=NULL) fprintf(record,"%-3d ", (int)wps);
		   }

		fflush(stdout); if (record!=NULL) fflush(record);

	   	count = (ui)((double)count * LOOPTIME / t);
	   	}
	   putchar('\n');
	   if (record!=NULL) putc('\n',record);
	   }

	if (record!=NULL) fclose(record);
	}