示例#1
0
int main(void)
{
    int len, range, i, ret, *list = NULL;
    clock_t start, end;
    float latency;

    printf("please input list size:");
    if (scanf("%d", &len) != 1) return -1;

    printf("please input max random number or -1 for no range:");
    if (scanf("%d", &range) != 1) return -1;

    printf("generating random data\n");
    if (rand_data(&list, len, range) != 0) {
        printf("failed to generate random data\n");
        ret = -1;
        goto exit;
    }
    if (len < 500) dump(list, len);

    printf("start merge sorting\n");
    start = clock();
    mergeSort(list, len);
    end = clock();

    latency = (((float)end - (float)start)/1000000.0F) * 1000;
    printf("merge sort execution time %f ms\n", latency);
    if (len < 500) dump(list, len);
    ret = 0;

exit:
    if (list) free(list);
    return ret;
}
示例#2
0
int main()
{

	int a[MAXN];
	int cnt;
	rand_data(a, MAXN);
	printf("befor:\n");
	print(a, MAXN);
	cnt = shell_sort(a, MAXN);
	printf("after shell sort, %d times\n", cnt);
	print(a, MAXN);
	return 0;
}
示例#3
0
文件: shell.c 项目: Igeneous/os
void shell_cmd(const char* cmd) {
    if (!strcmp(cmd, "help")) {
        printf("check the source ;)\n");
    } else if (!strcmp(cmd, "reboot")) {
        printf("rebooting...\n");
        _triple_fault();
    } else if (!strcmp(cmd, "heap")) {
        dump_heap();
    } else if (!strcmp(cmd, "rand")) {
        uint8_t buf[16];
        if (!rand_data(buf, 16)) {
            putbytes(buf, 16);
            putc('\n');
        } else {
            printf("not enough entropy\n");
        }
    } else if (!strcmp(cmd, "alloc")) {
        malloc(0x10000);
    } else if (!strcmp(cmd, "page")) {
        printf("trying to map single 4 MiB page...\n");
        test_enable_paging();
        printf("done\n");
    } else if (!strcmp(cmd, "info")) {
        printf("pit ticks: %u\n", pit_ticks);
        printf("rtc ticks: %lu\n", rtc_ticks);
        printf("spurious irq count: %lu\n", spurious_irq_count);
        printf("rdtsc: 0x%lx\n", __builtin_ia32_rdtsc());
    } else if (!strcmp(cmd, "test")) {
        thread_create(test, (void*) 42);
    } else if (!strcmp(cmd, "yield")) {
        thread_yield();
    } else if (strcmp(cmd, "")) {
        // not empty
        printf("unknown cmd \"%s\"\n", cmd);
    }
}
示例#4
0
文件: ics_test.c 项目: belesova/haven
/**
 * \brief Program main function.
 *
 * \param argc          number of arguments
 * \param *argv[]       array with the arguments
 *
 * \return      0       OK <BR>
 *              -1      error
 */
int
main(int argc, char *argv[]) {

        cs_device_t     *dev;
        char            *file = CS_PATH_DEV(0);
	cs_space_t	*lb_ep[NUM_LB_EP];
	cs_space_t	*mi32tobm;
	uint32_t	*lb_ep_mem[NUM_LB_EP];
	uint32_t	offset = 0;
	uint32_t	value[MAX_DATA_SIZE/4];
	bool		randomize_offset = true, randomize_data = true, randomize_index = true;
	int		c, index, mem_size, size;
	int		cmd = -1;
	char 		buffer[MAX_DATA_SIZE];
	uint32_t	phy_addr;
	uint32_t	lb_ep_base_addr[10];
	uint32_t	data;
        char            *command = NULL;

	long 		ltemp; /*!< getopt */
	uint32_t 	loops = 1, cycle;
	uint32_t 	data_size = 4;
	char 		*data_file = NULL;
	int		ret = 0;
	bool 		test_local, test_global;
	uint32_t	i;

	debug = -1;

	size = LB_ENDPOINT_WIDTH/4;
	for(i=0; i < NUM_LB_EP; i++){
		if(i >= BRAM_FROM_INDEX) {
			size = LB_ENDPOINT_BRAM_WIDTH/4;
		}

		lb_ep_mem[i] = (uint32_t *) malloc(sizeof(uint32_t) * size);
		if(lb_ep_mem[i] == 0){
			errx(1, "cannot allocate memory");
		}
		memset(lb_ep_mem[i], 0, sizeof(uint32_t) * size);
	}

        while ((c = getopt(argc, argv, ARGUMENTS)) != -1) {
                switch (c) {
                case 'd':       /* Set device file path */
                        file = optarg;
                        break;

                case 'c':       /* Decode command */
                        command = optarg;
                        break;
#ifdef DEBUG
		case 'D':	/* debug level */
                        if( (cl_strtol(optarg, &ltemp)) || (ltemp > 2) || (ltemp < 0) ) {
				errx(1, "wrong value of -D attribute");
                        }
			debug = ltemp;
			break;
#endif
                case 'f':       
			randomize_data = false;
                        data_file = optarg;
                        break;
               	case 'h':	/* program usage */
                        usage(c_commands);
                        return 0;

               	case 'l':
                        if( (cl_strtol(optarg,  &ltemp)) || (ltemp > LOOPS_MAX) || (ltemp < 1) ) {
				errx(1, "wrong value of -l attribute. Minimum is 1, maximum %d", LOOPS_MAX);
                        }
			loops = ltemp;
			break;
               	case 's':
                        if( (cl_strtol(optarg,  &ltemp)) || (ltemp > MAX_DATA_SIZE) || (ltemp < 1)) {
				errx(1, "wrong value of -s attribute. Minimum is 1, maximum %d", MAX_DATA_SIZE);
                        }
			data_size = ltemp;
			if(data_size % 4)
				errx(1, "Size not aligned to 4");
			break;
               	case 'o':
                        if( (cl_strtol(optarg,  &ltemp)) || (ltemp > MAX_OFFSET)) {
				errx(1, "wrong value of -o attribute. Minimum is 0, maximum %d", MAX_OFFSET);
                        }
			randomize_offset = false;
			offset = ltemp;
			if(offset % 4)
				warnx("offset not aligned to 4");
			break;
                default:
                        errx(1, "unknown argument -%c", optopt);
                }
        }
        argc -= optind;
        argv += optind;

        if (argc != 0) {
                errx(1, "stray arguments");
	}

	/* load data pattern */
	if(!cl_file_read_hex((char *)value, data_file, data_size))
		errx(1, "Can't load data from file");

	/* attach device */
	if (cs_attach_noex(&dev, file) != 0){
       		cs_detach(&dev);
             	errx(1, "cs_attach_noex failed");
	}

        /* ------------ Component space mapping ------------ */

                                /* LB_ENDPOINT */
	MSG(CL_VERBOSE_BASIC, "Mapping memory 0 at %08x", LB_ENDPOINT_0_BASE);
	if (cs_space_map(dev, &lb_ep[0], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \
                        LB_ENDPOINT_0_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_0");
	}
	lb_ep_base_addr[0] = LB_ENDPOINT_0_BASE;

#ifndef GICS
                                /* LB_ENDPOINT */
        if (cs_space_map(dev, &lb_ep[1], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \
                        LB_ENDPOINT_1_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_1");
        }
 	lb_ep_base_addr[1] = LB_ENDPOINT_1_BASE;

                                /* LB_ENDPOINT */
        if (cs_space_map(dev, &lb_ep[2], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \
                        LB_ENDPOINT_2_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_2");
        }
 	lb_ep_base_addr[2] = LB_ENDPOINT_2_BASE;

                                /* LB_ENDPOINT */
        if (cs_space_map(dev, &lb_ep[3], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \
                        LB_ENDPOINT_3_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_3");
        }
	lb_ep_base_addr[3] = LB_ENDPOINT_3_BASE;

                                /* LB_ENDPOINT */
        if (cs_space_map(dev, &lb_ep[4], CS_SPACE_FPGA, LB_ENDPOINT_WIDTH, \
                        LB_ENDPOINT_4_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_4");
        }
	lb_ep_base_addr[4] = LB_ENDPOINT_4_BASE;

#endif

				/* MI32 TO BM */
	MSG(CL_VERBOSE_BASIC, "Mapping MI32 TO BM at %08x", LB_EP_MI32TOBM_BASE);
        if (cs_space_map(dev, &mi32tobm, CS_SPACE_FPGA, LB_EP_MI32TOBM_WIDTH, \
                        LB_EP_MI32TOBM_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map MI32TOBM");
        }


#ifndef GICS
                                /* LB_ENDPOINT */
        if (cs_space_map(dev, &lb_ep[5], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\
                        LB_ENDPOINT_5_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_5");
        }
        lb_ep_base_addr[5] = LB_ENDPOINT_5_BASE;

                                /* LB_ENDPOINT */
        if (cs_space_map(dev, &lb_ep[6], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\
                        LB_ENDPOINT_6_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_6");
        }
 	lb_ep_base_addr[6] = LB_ENDPOINT_6_BASE;

                                /* LB_ENDPOINT */
        if (cs_space_map(dev, &lb_ep[7], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\
                        LB_ENDPOINT_7_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_7");
        }
	lb_ep_base_addr[7] = LB_ENDPOINT_7_BASE;

                                /* LB_ENDPOINT_BM */
	if (cs_space_map(dev, &lb_ep[8], CS_SPACE_FPGA, LB_ENDPOINT_BRAM_WIDTH,\
                        LB_ENDPOINT_BM_BASE, 0) != 0) {
                errx(1, "cs_space_map failed to map LB_ENDPOINT_BM");
        }
 	lb_ep_base_addr[8] = LB_ENDPOINT_BM_BASE;

#endif


        /* Clear all memory of all LB_EPs - zeros like in SW buffers */
        for(i=0; i<NUM_LB_EP; i++) {
		mem_size = get_lb_ep_mem_size(i);

		ics_clear_mem(dev,lb_ep[i], mem_size);
        }

	srand((unsigned int) clock());


        if (command != NULL){
                if( (cmd = decode_choice(c_commands, command, NUM_CMD)) == -1){
			MSG(CL_VERBOSE_BASIC, "Unknown command %s", command);
                        return -1;
                }
        }

	if(cmd == -1){
		usage(c_commands);
		return 0;	
	}

	for(cycle=0; cycle<loops; cycle++) {
		test_local = false;
		test_global = false;

		/* get needed data for operations */
		if(randomize_index)
			index = rand_index();

		if(randomize_offset)
			offset = rand_offset(index);

		if(randomize_data)
			rand_data((u_char *)value, data_size);

		MSG(CL_VERBOSE_BASIC, "index     %d", index);
		MSG(CL_VERBOSE_BASIC, "offset    0x%08x", offset);
		MSG(CL_VERBOSE_BASIC, "data_size 0x%08x", data_size);
		MSG(CL_VERBOSE_BASIC, "loops     %d", loops);
		MSG(CL_VERBOSE_BASIC, "data");

		for(i = 0; i < data_size; i++) {
			MSG_NONL(CL_VERBOSE_BASIC, "%02x ", *((u_char *)value + i));
		}
		MSG_NONL(CL_VERBOSE_BASIC, "\n");

		switch(cmd){
		case CMD_WRITE_IN:
			/* test write-in to LB_EPs */
			MSG(CL_VERBOSE_BASIC, "WRITE_IN");

			ics_write(dev, lb_ep[index], offset, value, \
					lb_ep_mem[index], data_size);

			test_local = true;
			break;
		case CMD_G2LR:
			/*************************************************************/
			/* BM - G2L READ - TEST */

			write_to_phy_addr((char *)value, data_size);

			/* written data to physical address - verification */
			read_from_phy_addr(buffer, data_size);

			/* store data from phy. mem to SW copy of LB_EP mems */
			memcpy(lb_ep_mem[index], buffer, data_size);

			/* get physical address - here was just written */
			if( (phy_addr = get_phy_addr()) == 0) {
				printf("Unable to get physical address to memory\n");
				exit(-1);
			}

		       /* BM operation - from physical address to unit */
			ics_bm_g2lread(dev, mi32tobm, phy_addr, \
						lb_ep_base_addr[index]+(offset), data_size);

			/* wait for operation to finish */
			usleep(1000);

			test_local = true;
			break;

		case CMD_L2GW:
			/************************************************************/
			/* BM - L2G WRITE - TEST*/
			if( (phy_addr = get_phy_addr()) == 0) {
				printf("Unable to get physical address to memory\n");
				exit(-1);
			}

			ics_write(dev, lb_ep[index], offset, value, \
					lb_ep_mem[index], data_size);

			ics_bm_l2gwrite(dev, mi32tobm, phy_addr, offset, data_size);

			/* wait till BM operation end */
			usleep(100);

			read_from_phy_addr(buffer, data_size);

			test_global = true;
			break;
		}

		if(test_local) { /* diff FPGA and lb_ep_mem */
			ret = ics_test_lb_ep_mem(dev, lb_ep[index], data_size, (u_char *)lb_ep_mem[index], offset);
		} else if(test_global) { /* global stored in buffer - diff buffer and lb_ep_mem */
			ret = ics_test_lb_ep_mem_global(buffer, data_size, (u_char *)lb_ep_mem[index], offset);
		}

		/* print results */
		if(!ret) {
			printf("memory verification for lb_ep %d was " \
				"successfull\n", index);
		} else {
			printf("memory verification for lb_ep %d failed!!\n", \
				index);
		}

	} /* FOR */

	cs_detach(&dev);

	return 0;
}