Example #1
0
void test_private() {

	new_group("Private data tests");

	PointerStack stack = pointer_stack_create();

	write_test("PointerStack Set Private", "[[ %i == 1 ]]", pointer_stack_set_private(stack, buffer));
	write_test("PointerStack Get Private", "[[ '%p' == '%p' ]]", pointer_stack_get_private(stack), buffer);

	pointer_stack_dispose(stack);

	end_group();

}
Example #2
0
void test_optimization() {

	new_group("Optimization tests");

	PointerStack stack = pointer_stack_create();

	write_test("PointerStack Set Buffering", "[[ %i == 1 ]]", pointer_stack_set_buffering(stack, 16));
	write_test("PointerStack Get Buffering", "[[ %li == %li ]]", pointer_stack_get_buffering(stack), 16);

	pointer_stack_dispose(stack);

	end_group();

}
Example #3
0
void test_limitation() {

	new_group("Limitation tests");

	PointerStack stack = pointer_stack_create();

	write_test("PointerStack Set Limit", "[[ %i == 1 ]]", pointer_stack_set_limit(stack, 2));
	write_test("PointerStack Get Limit", "[[ %li == %li ]]", pointer_stack_get_limit(stack), 2);

	pointer_stack_dispose(stack);

	end_group();

}
Example #4
0
void test_create_pointer_stack() {

	new_group("Life cycle operation tests");

	PointerStack stack = pointer_stack_create();

	fatal_errors(true);
	write_test("Create PointerStack....", "[[ %li != 0 ]]", (long int) stack);
	write_test("Dispose PointerStack...", "[[ %i  != 0 ]]", pointer_stack_dispose(stack));
	fatal_errors(false);

	end_group();

}
Example #5
0
void test_protection() {

	new_group("Protection tests");

	PointerStack stack = pointer_stack_create();

	write_test("PointerStack Lock.......", "[[ %i  == 1 ]]", pointer_stack_lock(stack));
	write_test("PointerStack Get Lock...", "[[ %li == 1 ]]", pointer_stack_get_lock(stack));
	write_test("PointerStack Unlock.....", "[[ %i  == 1 ]]", pointer_stack_lock(stack));

	pointer_stack_dispose(stack);

	end_group();

}
Example #6
0
int main()
{
  /* write a PLY file */
  write_test();
  /* read a PLY file */
  read_test();
}
Example #7
0
File: debug.c Project: taphier/lk
static int bio_test_device(bdev_t* device)
{
    ssize_t num_errors = erase_test(device);
    if (num_errors < 0) {
        printf("error %ld performing erase test\n", num_errors);
        return -1;
    }
    printf("discovered %ld error(s) while testing erase.\n", num_errors);
    if (num_errors) {
        // No point in continuing the tests if we couldn't erase the device.
        printf("not continuing to test writes.\n");
        return -1;
    }

    num_errors = write_test(device);
    printf("Discovered %ld error(s) while testing write.\n", num_errors);
    if (num_errors) {
        return -1;
    }

    printf ("Testing sub-erase...\n");
    bool success = sub_erase_test(device, SUB_ERASE_TEST_SAMPLES);
    if (!success) {
        printf("Discovered errors while testing sub-erase.\n");
        return -1;
    } else {
        printf("No errors while testing sub-erase.\n");
    }

    return 0;
}
Example #8
0
static void
write_cond(tree *cond)
{
  char *end_label = NULL;

  /* else doesn't have a condition */
  if (cond->value.cond.cond != NULL) {
    end_label = next_label();
    fprintf(state.output.f, ";#CSRC %s %d\n", 
            state.srcfilename,
            cond->value.cond.cond->line_number);
    temp_number = 0;
    write_test(cond->value.cond.cond, end_label);
    if (temp_number > max_temp_number)
      max_temp_number = temp_number;
  }
  
  /* write the body of the code */
  write_statements(cond->value.cond.body);
  
  /* if there is a condition generate a label at the end of the body */
  if (cond->value.cond.cond != NULL) {
    write_label(end_label);
    if (end_label)
      free(end_label);
  }
  
  /* generate next conditional block, if there is one */
  if (cond->value.cond.next != NULL)
    write_cond(cond->value.cond.next);
}
Example #9
0
int main (int argc, char *argv[])
{
	char	*directory = "";
	char	name[256];
	unint	i, j;
	unint	n = 1000;
	u64	size = (1<<20);

	punyopt(argc, argv, NULL, NULL);
	directory = Option.dir;
	size = Option.file_size;
	n = Option.iterations;
	for (i = 0; i < BUF_SIZE; i++)
	{
		Buf[i] = random();
	}
	mkdir(directory, 0777);
	chdirq(directory);
	for (j = 0; j < Option.loops; j++) {
		sprintf(name, "dir_%ld", j);
		mkdirq(name);
		chdirq(name);
		startTimer();
		for (i = 0; i < n; i++) {
			sprintf(name, "file_%ld", i);
			write_test(name, size);
		}
		stopTimer();
		prTimer();
		printf(" size=%lld n=%ld\n", size, n);
		if (chdir("..")) perror("chdir ..");
	}
	return 0;
}
Example #10
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);
}
Example #11
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;
}
Example #12
0
File: wire.c Project: dnstap/knot
int main(int argc, char *argv[])
{
	plan(8);

	const uint8_t rdata[] = { 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff };

	is_hex(            0x8899, knot_wire_read_u16(rdata), "16-bit read");
	is_hex(        0x8899aabb, knot_wire_read_u32(rdata), "32-bit read");
	is_hex(    0x8899aabbccdd, knot_wire_read_u48(rdata), "48-bit read");
	is_hex(0x8899aabbccddeeff, knot_wire_read_u64(rdata), "64-bit read");

	write_test(16, 0x1122,             0x11, 0x22);
	write_test(32, 0x66778899,         0x66, 0x77, 0x88, 0x99);
	write_test(48, 0xbbccdd778899,     0xbb, 0xcc, 0xdd, 0x77, 0x88, 0x99);
	write_test(64, 0xbbccddee66778899, 0xbb, 0xcc, 0xdd, 0xee,
	                                   0x66, 0x77, 0x88, 0x99);

	return 0;
}
Example #13
0
int main(int argc, char **argv)
{
  hid_t file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
  for (int i = 0; i < 5; i++)
  {
    write_test(file, i);
  }
  H5Fclose(file);
  return 0;
}
Example #14
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;
}
Example #15
0
void test_extended() {

	new_group("Extended operation tests");

	PointerStack stack = pointer_stack_create();
	pointer_stack_push(stack, buffer);
	pointer_stack_push(stack, pointer_stack_license());

	bool status = pointer_stack_reverse(stack);

	write_test("PointerStack Reverse...", "[[ %i == 1 && '%p' == '%p' ]]", status, pointer_stack_peek(stack, 1), buffer);
	status = pointer_stack_invert(stack, true);
	write_test("PointerStack Invert....", "[[ %i == 1 && '%p' == '%p' ]]", status, pointer_stack_peek(stack, 0), buffer);
	status = pointer_stack_void(stack, 1);
	write_test("PointerStack Void......", "[[ %i == 1 && %i == 1 ]]", status, pointer_stack_get_count(stack));

	pointer_stack_dispose(stack);

	end_group();

}
Example #16
0
int					/* O - Exit status */
main(void)
{
  int		i;			/* Looping var */
  int		ras_fd,			/* File descriptor for read process */
		status;			/* Exit status of read process */
  double	start_secs,		/* Start time */
		write_secs,		/* Write time */
		read_secs,		/* Read time */
		pass_secs[TEST_PASSES];	/* Total test times */


 /*
  * Ignore SIGPIPE...
  */

  signal(SIGPIPE, SIG_IGN);

 /*
  * Run the tests several times to get a good average...
  */

  printf("Test read/write speed of %d pages, %dx%d pixels...\n\n",
         TEST_PAGES, TEST_WIDTH, TEST_HEIGHT);
  for (i = 0; i < TEST_PASSES; i ++)
  {
    printf("PASS %2d: ", i + 1);
    fflush(stdout);

    ras_fd     = run_read_test();
    start_secs = get_time();

    write_test(ras_fd);

    write_secs = get_time();
    printf(" %.3f write,", write_secs - start_secs);
    fflush(stdout);

    close(ras_fd);
    wait(&status);

    read_secs    = get_time();
    pass_secs[i] = read_secs - start_secs;
    printf(" %.3f read, %.3f total\n", read_secs - write_secs, pass_secs[i]);
  }

  printf("\nMedian Total Time: %.3f seconds per document\n",
         compute_median(pass_secs));

  return (0);
}
main()
{

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

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

}
Example #18
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();
}
Example #19
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);
}
Example #20
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;
}
Example #21
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;
}
Example #22
0
time_test()
{
        time_t tt,ptt;
        struct tm *stm;
        int sec,min,hour,rtn;
        char string[40];
        tt=time(&ptt);
        stm=localtime(&ptt);
        rtn=stm->tm_wday;
        hour=stm->tm_hour;
        min=stm->tm_min;
        printf ("Time %d:%d\n",hour,min);
        printf ("Seconds since start of Unix %ld\n",tt);
        stm = localtime(&tt);
        rtn=stm->tm_wday;
        hour=stm->tm_hour;
        min=stm->tm_min;
        ptt = tt;
        stm=localtime(&ptt);
        rtn=stm->tm_wday;
        hour=stm->tm_hour;
        min=stm->tm_min;
        strcpy(string,ctime(&ptt));
        printf ("this is a percent sign: %%\n");
        printf ("Time now is  %s",string);
        printf ("Unix start Time %d:%d\n",hour,min);
        printf("ctime is %s\n",ctime(&ptt));
        tt = tt - 30;
        printf("30 seconds ago was %s",ctime(&tt));
/*
        rtn = sizeof(tt);
        printf ("Sizeof tt = %d\n",rtn);
        rtn = sizeof(rtn);
        printf ("Sizeof rtn = %d\n",rtn);
*/
        exit(22);
        shared_memory_attach();
        write_test();
}
Example #23
0
File: debug.c Project: 0xBADCA7/lk
static int bio_test_device(bdev_t *device)
{
    ssize_t num_errors = erase_test(device);
    if (num_errors < 0) {
        printf("error %ld performing erase test\n", num_errors);
        return -1;
    }
    printf("discovered %ld error(s) while testing erase.\n", num_errors);
    if (num_errors) {
        // No point in continuing the tests if we couldn't erase the device.
        printf("not continuing to test writes.\n");
        return -1;
    }

    num_errors = write_test(device);
    printf("Discovered %ld error(s) while testing write.\n", num_errors);
    if (num_errors) {
        return -1;
    }

    printf ("Testing sub-erase...\n");
    bool success = sub_erase_test(device, SUB_ERASE_TEST_SAMPLES);
    if (!success) {
        printf("Discovered errors while testing sub-erase.\n");
        return -1;
    } else {
        printf("No errors while testing sub-erase.\n");
    }

    printf("Testing memory mapped mode...\n");
    status_t test_result = memory_mapped_test(device);
    if (test_result != NO_ERROR) {
        printf("Memory mapped test returned error %d\n", test_result);
    } else {
        printf("Memory mapped mode tests returned successfully\n");
    }

    return 0;
}
Example #24
0
static void
write_loop(tree *loop)
{
  char *start_label = NULL;

  /* write out initalization code */
  if (loop->value.loop.init != NULL) {
    write_statements(loop->value.loop.init);
  }
 
  start_label = next_label();
  write_label(start_label);

  /* write the body of the loop */
  if (loop->value.loop.body != NULL)
    write_statements(loop->value.loop.body);

  /* write the increment statements */
  if (loop->value.loop.incr != NULL)
    write_statements(loop->value.loop.incr);

  /* write the exit statements */
  if (loop->value.loop.exit != NULL) {
    fprintf(state.output.f, ";#CSRC %s %d\n", 
            state.srcfilename,
            loop->value.loop.exit->line_number);
    temp_number = 0;
    write_test(loop->value.loop.exit, start_label);
    if (temp_number > max_temp_number)
      max_temp_number = temp_number;
  } else {
    write_asm_line("goto %s", start_label);
  }

  if (start_label)
    free(start_label);
}
Example #25
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);
  }
}
Example #26
0
void test_main() {

	bool test = false;

	new_group("General operation tests");

	PointerStack stack = pointer_stack_create();

	test = pointer_stack_pack(stack); // need to cache this, dual procedure parameter calls dependent on each other might not work out!

	write_test("PointerStack Pack......", "[[ %i == 1 && %li == %li ]]", test, pointer_stack_get_units(stack), 8);
	write_test("PointerStack Push......", "[[ %i == 1 ]]", pointer_stack_push(stack, buffer));
	write_test("PointerStack Pointer...", "[[ '%p' == '%p' ]]", * pointer_stack_pointer(stack, 0), buffer);
	write_test("PointerStack Peek......", "[[ '%p' == '%p' ]]",   pointer_stack_peek(stack, 0), buffer);
	write_test("PointerStack Poke......", "[[ '%p' == '%p' ]]",   pointer_stack_poke(stack, 0, NULL), buffer);
	write_test("PointerStack Pop.......", "[[ '%p' == '%p' ]]",   pointer_stack_pop(stack), NULL);

	pointer_stack_dispose(stack);

	end_group();

}
Example #27
0
void test_io() {

	new_group("I/O operation tests");

	PointerStack stack = pointer_stack_create();
	pointer_stack_push(stack, buffer); // "initialize" the stack so we can test it.

	write_test("PointerStack Get Count", "[[ %li == 1 ]]", pointer_stack_get_count(stack));
	write_test("PointerStack Get Slots", "[[ %li == %li ]]", pointer_stack_get_slots(stack), 7);
	write_test("PointerStack Get Units", "[[ %li == %li ]]", pointer_stack_get_units(stack), 8);
	PointerStackExport parray = pointer_stack_export(stack, 0, 0);
	write_test("PointerStack Export...", "[[ '%p' != '(nil)' && '%p' == '%p' && '%p' == '(nil)' ]]", parray, parray[0], buffer, parray[1]); 
	write_test("PointerStack Free.....", "[[ %i == 1 ]]", pointer_stack_free(parray));

	void * array[] = { buffer, buffer, NULL };
	bool test = pointer_stack_import(stack, array, 0, 1);
	void * result[] = { pointer_stack_peek(stack, 1), pointer_stack_peek(stack, 2), NULL };
	result[2] = pointer_stack_peek(stack, 3);
	write_test("PointerStack Import...", "[[ %i == 1 && '%p' == '%p' && '%p' == '%p' && '%p' == '(nil)' && %li == %li ]]", test, result[0], buffer, result[1], buffer, result[2], pointer_stack_error(stack), PSE_OVERFLOW);
	pointer_stack_dispose(stack);

	end_group();

}
Example #28
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;
}
Example #29
0
void fatal_errors(bool active) {
	if (active) write_test("shell", "error.fatal");
	else write_test("shell", "error.normal");
}
Example #30
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;
}