示例#1
0
// The loop function is called in an endless loop
void loop()
{
//Add your repeated code here

	float rpm = speed_test(SPEED_PIN_0);

}
static int test_alphaComp_speed(void)
{
	BYTE ALIGN(src1[SRC1_WIDTH * SRC1_HEIGHT]);
	BYTE ALIGN(src2[SRC2_WIDTH * SRC2_HEIGHT]);
	BYTE ALIGN(dst1[DST_WIDTH * DST_HEIGHT]);
	char testStr[256];
	UINT32* ptr;
	UINT32 i;
	testStr[0] = '\0';
	winpr_RAND((BYTE*)src1, sizeof(src1));
	/* Special-case the first two values */
	src1[0] &= 0x00FFFFFFU;
	src1[1] |= 0xFF000000U;
	winpr_RAND((BYTE*)src2, sizeof(src2));
	/* Set the second operand to fully-opaque. */
	ptr = (UINT32*)src2;

	for (i = 0; i < sizeof(src2) / 4; ++i) *ptr++ |= 0xFF000000U;

	memset(dst1, 0, sizeof(dst1));

	if (!speed_test("add16s", "aligned", g_Iterations,
	                (speed_test_fkt)generic->alphaComp_argb,
	                (speed_test_fkt)optimized->alphaComp_argb,
	                src1, 4 * SRC1_WIDTH,
	                src2, 4 * SRC2_WIDTH,
	                dst1, 4 * DST_WIDTH, TEST_WIDTH, TEST_HEIGHT))
		return FALSE;

	return TRUE;
}
示例#3
0
// batch
void all_simple_tests()
{
	basic_test();
	splitter_test();
	invalid_message_test();
	invalid_message_test2();
	test_binary_tag();
	speed_test();
}
示例#4
0
int main (void)
{
	// Initialize everything
	initAll();

	xprintf("Startup!");


#ifdef GENERATE_ASCII_RANDOM_BITS

	uint32_t i,j;
	uint32_t n;
	for (i=0; i<NUMBER_OF_RANDOM_WORDS; i++)
	{
		n = TM_RNG_Get();
		//while (n) {
		for (j=0; j<32; j++)
		{
		    if (n & 1)
		        xprintf("1");
		    else
		        xprintf("0");

		    n >>= 1;
		}
	}

#endif

#ifdef GENERATE_BINARY_RANDOM_BITS
	uint32_t i=0;
	uint32_t n;
	for (i=0; i<NUMBER_OF_RANDOM_WORDS; i++)
	{
		//xprintf(".");
		n = TM_RNG_Get();
		xprintf("%c%c%c%c",(n&0xff),((n>>8)&0xff),((n>>16)&0xff),((n>>24)&0xff));
	}
#endif

#ifdef PERFORM_UNIT_TESTS
	perform_unit_tests();
#endif

#ifdef PERFORM_SPEED_TESTS
	speed_test();
#endif

	xputs("[Done]\n\n");

	while (1)
	{
	}

	return 0;
}
示例#5
0
static void do_speed_test(void)
{
	int i, j;

	for (i = 1000 ; i <= 100000 ; i *= 10) {
		for (j = 100 ; j <= i / 10 ; j *= 10) {
			speed_test(i, j);
		}
	}
}
示例#6
0
/* ------------------------------------------------------------------------- */
static BOOL test_and_32u_speed(void)
{
	UINT32 ALIGN(src[MAX_TEST_SIZE + 3]), ALIGN(dst[MAX_TEST_SIZE + 3]);

	winpr_RAND((BYTE*)src, sizeof(src));

	if (!speed_test("andC_32u", "aligned", g_Iterations,
			(speed_test_fkt)generic->andC_32u,
			(speed_test_fkt)optimized->andC_32u,
			src + 1, VALUE, dst + 1, MAX_TEST_SIZE))
		return FALSE;
	if (!speed_test("andC_32u", "unaligned", g_Iterations,
			(speed_test_fkt)generic->andC_32u,
			(speed_test_fkt)optimized->andC_32u,
			src + 1, VALUE, dst + 2, MAX_TEST_SIZE))
		return FALSE;

	return TRUE;
}
示例#7
0
		MDPerformanceTest()
		{
			mdperf_log.info() << "Starting perf test..." << std::endl;
			setup();
			speed_test();
			cleanup();
			setup();
			speed_test_no_memcpy();
			cleanup();
		}
示例#8
0
/* ------------------------------------------------------------------------- */
static BOOL test_RGBToRGB_16s8u_P3AC4R_speed(void)
{
	const prim_size_t roi64x64 = { 64, 64 };
	INT16 ALIGN(r[4096+1]), ALIGN(g[4096+1]), ALIGN(b[4096+1]);
	UINT32 ALIGN(dst[4096+1]);
	int i;
	INT16* ptrs[3];

	winpr_RAND((BYTE*)r, sizeof(r));
	winpr_RAND((BYTE*)g, sizeof(g));
	winpr_RAND((BYTE*)b, sizeof(b));

	/* clear upper bytes */
	for (i = 0; i < 4096; ++i)
	{
		r[i] &= 0x00FFU;
		g[i] &= 0x00FFU;
		b[i] &= 0x00FFU;
	}

	ptrs[0] = r+1;
	ptrs[1] = g+1;
	ptrs[2] = b+1;

	if (!speed_test("RGBToRGB_16s8u_P3AC4R", "aligned", g_Iterations,
			(speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
			(speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R,
			(const INT16**) ptrs, 64 * 2, (BYTE*) dst, 64 * 4, &roi64x64))
		return FALSE;

	if (!speed_test("RGBToRGB_16s8u_P3AC4R", "unaligned", g_Iterations,
			(speed_test_fkt)generic->RGBToRGB_16s8u_P3AC4R,
			(speed_test_fkt)optimized->RGBToRGB_16s8u_P3AC4R,
			(const INT16**) ptrs, 64 * 2, ((BYTE*) dst)+1, 64 * 4, &roi64x64))
		return FALSE;

	return TRUE;
}
示例#9
0
/* ------------------------------------------------------------------------- */
static BOOL test_or_32u_speed(void)
{
	UINT32 ALIGN(src[FUNC_TEST_SIZE + 3]), ALIGN(dst[FUNC_TEST_SIZE + 3]);
	char testStr[256];
	testStr[0] = '\0';
	winpr_RAND((BYTE*)src, sizeof(src));

	if (!speed_test("add16s", "aligned", g_Iterations,
			(speed_test_fkt)generic->orC_32u,
			(speed_test_fkt)optimized->orC_32u,
			src + 1, VALUE, dst + 1, FUNC_TEST_SIZE))
		return FALSE;

	return TRUE;
}
示例#10
0
static int test_YCoCgRToRGB_8u_AC4R_speed(void)
{
	INT32 ALIGN(in[4096]);
	INT32 ALIGN(out[4096]);

	winpr_RAND((BYTE*)in, sizeof(in));

	if (!speed_test("YCoCgToRGB_8u_AC4R", "aligned", g_Iterations,
			(speed_test_fkt)generic->YCoCgToRGB_8u_AC4R,
			(speed_test_fkt)optimized->YCoCgToRGB_8u_AC4R,
			in, 64 * 4, out, 64 * 4, 64, 64, 2, FALSE, FALSE))
		return FALSE;

	return TRUE;
}
示例#11
0
/* ------------------------------------------------------------------------- */
static int test_yCbCrToRGB_16s16s_P3P3_speed(void)
{
	prim_size_t roi = { 64, 64 };
	INT16 ALIGN(y[4096]), ALIGN(cb[4096]), ALIGN(cr[4096]);
	INT16 ALIGN(r[4096]), ALIGN(g[4096]), ALIGN(b[4096]);
	int i;
	const INT16* input[3];
	INT16* output[3];

	winpr_RAND((BYTE*)y, sizeof(y));
	winpr_RAND((BYTE*)cb, sizeof(cb));
	winpr_RAND((BYTE*)cr, sizeof(cr));

	/* Normalize to 11.5 fixed radix */
	for (i = 0; i < 4096; ++i)
	{
		y[i]  &= 0x1FE0U;
		cb[i] &= 0x1FE0U;
		cr[i] &= 0x1FE0U;
	}

	input[0] = y;
	input[1] = cb;
	input[2] = cr;
	output[0] = r;
	output[1] = g;
	output[2] = b;

	if (!speed_test("yCbCrToRGB_16s16s_P3P3", "aligned", g_Iterations,
			(speed_test_fkt)generic->yCbCrToRGB_16s16s_P3P3,
			(speed_test_fkt)optimized->yCbCrToRGB_16s16s_P3P3,
			input, 64 * 2, output, 64 * 2, &roi))
		return FALSE;

	return TRUE;
}
示例#12
0
int
main(int argc, char **argv)
{
    AVFormatContext *afc;
    AVStream *st;
    AVPacket pk;
    struct frame_format frame_fmt = { 0 };
    const struct pixconv *pixconv = NULL;
    const struct memman *memman = NULL;
    const struct codec *codec = NULL;
    struct frame_format dp;
    int bufsize = BUFFER_SIZE;
    pthread_t dispt;
    unsigned flags = OFBP_DOUBLE_BUF;
    char *test_param = NULL;
    char *dispdrv = NULL;
    char *timer_drv = NULL;
    char *memman_drv = NULL;
    char *pixconv_drv = NULL;
    char *codec_drv = NULL;
    int opt;
    int ret = 0;

#define error(n) do { ret = n; goto out; } while (0)

    while ((opt = getopt(argc, argv, "b:d:fFM:P:st:T:v:")) != -1) {
        switch (opt) {
        case 'b':
            bufsize = strtol(optarg, NULL, 0) * 1048576;
            break;
        case 'd':
            dispdrv = optarg;
            break;
        case 'F':
            noaspect = 1;
        case 'f':
            flags |= OFBP_FULLSCREEN;
            break;
        case 'M':
            memman_drv = optarg;
            break;
        case 'P':
            pixconv_drv = optarg;
            break;
        case 's':
            flags &= ~OFBP_DOUBLE_BUF;
            break;
        case 't':
            test_param = optarg;
            break;
        case 'T':
            timer_drv = optarg;
            break;
        case 'v':
            codec_drv = optarg;
            break;
        }
    }

    argc -= optind;
    argv += optind;

    if (test_param)
        return speed_test(dispdrv, memman_drv, pixconv_drv, test_param, flags);

    if (argc < 1)
        return 1;

    av_register_all();
    avcodec_register_all();

    afc = open_file(argv[0]);

    st = find_stream(afc);
    if (!st) {
        fprintf(stderr, "No video streams found.\n");
        exit(1);
    }

    codec = find_driver(codec_drv, NULL, ofbp_codec_start);
    if (!codec) {
        fprintf(stderr, "Decoder '%s' not found\n", codec_drv);
        error(1);
    }

    if (codec->open(NULL, st->codec, &frame_fmt)) {
        fprintf(stderr, "Error opening decoder\n");
        error(1);
    }

    if (!frame_fmt.width) {
        fprintf(stderr, "Decoder error: frame size not specified\n");
        error(1);
    }

    dp.pixfmt = frame_fmt.pixfmt;
    display = display_open(dispdrv, &dp, &frame_fmt);
    if (!display)
        error(1);

    set_scale(&dp, &frame_fmt, flags);

    if (display->memman) {
        if (dp.pixfmt == frame_fmt.pixfmt) {
            memman = display->memman;
        } else if (display->flags & OFBP_PRIV_MEM) {
            fprintf(stderr, "Decoder/display pixel format mismatch\n");
            error(1);
        }
    }

    if (!memman)
        memman = find_driver(memman_drv, NULL, ofbp_memman_start);
    if (!memman)
        error(1);

    if ((codec->flags & OFBP_PHYS_MEM) && !(memman->flags & OFBP_PHYS_MEM)) {
        fprintf(stderr, "Incompatible decoder/memman\n");
        error(1);
    }

    if (memman->alloc_frames(&frame_fmt, bufsize, &frames, &num_frames))
        error(1);

    if (memman != display->memman) {
        pixconv = pixconv_open(pixconv_drv, &frame_fmt, &dp);
        if (!pixconv)
            error(1);
        if ((pixconv->flags & OFBP_PHYS_MEM) &&
            !(memman->flags & display->flags & OFBP_PHYS_MEM)) {
            fprintf(stderr, "Incompatible display/memman/pixconv\n");
            error(1);
        }
    }

    timer = timer_open(timer_drv);
    if (!timer)
        error(1);

    init_frames(&frame_fmt);

    if (display->enable(&frame_fmt, flags, pixconv, &dp))
        error(1);

    pthread_mutex_init(&disp_lock, NULL);
    sem_init(&disp_sem, 0, 0);

    signal(SIGINT, sigint);

    pthread_create(&dispt, NULL, disp_thread, st);

    while (!stop && !av_read_frame(afc, &pk)) {
        if (pk.stream_index == st->index)
            if (codec->decode(&pk))
                stop = 1;
        av_free_packet(&pk);
    }

    if (!stop) {
        sem_post(&disp_sem);
        while (disp_tail != -1)
            usleep(100000);
    }

    stop = 1;
    sem_post(&disp_sem);
    pthread_join(dispt, NULL);

out:
    if (afc) av_close_input_file(afc);

    if (codec)   codec->close();
    if (timer)   timer->close();
    if (memman)  memman->free_frames(frames, num_frames);
    if (display) display->close();
    if (pixconv) pixconv->close();

    return ret;
}
示例#13
0
int main(int argc, char *argv[]) {


    struct FRAME_HEADERS FRAME_HEADERS;
    struct TEST_INTERFACE TEST_INTERFACE;
    struct TEST_PARAMS TEST_PARAMS;
    struct MTU_TEST MTU_TEST;
    struct QM_TEST QM_TEST;
    struct APP_PARAMS APP_PARAMS;

    char TESTING = true;

    while(TESTING)
    {

        /*
         ******************************************************* DEFAULT VALUES
         */

        pFRAME_HEADERS                  = &FRAME_HEADERS;
        FRAME_HEADERS.SOURCE_MAC[0]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[1]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[2]     = 0x5E;
        FRAME_HEADERS.SOURCE_MAC[3]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[4]     = 0x00;
        FRAME_HEADERS.SOURCE_MAC[5]     = 0x01;
        FRAME_HEADERS.DEST_MAC[0]       = 0x00;
        FRAME_HEADERS.DEST_MAC[1]       = 0x00;
        FRAME_HEADERS.DEST_MAC[2]       = 0x5E;
        FRAME_HEADERS.DEST_MAC[3]       = 0x00;
        FRAME_HEADERS.DEST_MAC[4]       = 0x00;
        FRAME_HEADERS.DEST_MAC[5]       = 0x02;
        FRAME_HEADERS.LENGTH            = HEADERS_LEN_DEF;
        FRAME_HEADERS.ETHERTYPE         = ETHERTYPE_DEF;
        FRAME_HEADERS.PCP               = PCP_DEF;
        FRAME_HEADERS.VLAN_ID           = VLAN_ID_DEF;
        FRAME_HEADERS.QINQ_ID           = QINQ_ID_DEF;
        FRAME_HEADERS.QINQ_PCP          = QINQ_PCP_DEF;
        FRAME_HEADERS.LSP_SOURCE_MAC[0] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[1] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[2] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[3] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[4] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[5] = 0x00;
        FRAME_HEADERS.LSP_SOURCE_MAC[6] = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[0]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[1]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[2]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[3]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[4]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[5]   = 0x00;
        FRAME_HEADERS.LSP_DEST_MAC[6]   = 0x00;
        FRAME_HEADERS.MPLS_LABELS       = 0;
        for (int i = 0; i<MPLS_LABELS_MAX; i++) {
            FRAME_HEADERS.MPLS_LABEL[i] = 0;
            FRAME_HEADERS.MPLS_EXP[i]   = 0;
            FRAME_HEADERS.MPLS_TTL[i]   = 0;
        }
        FRAME_HEADERS.PWE_CONTROL_WORD  = 0;
        FRAME_HEADERS.MPLS_IGNORE       = 0;
        FRAME_HEADERS.TLV_SIZE          = sizeof(char) + sizeof(short) +
                                          sizeof(unsigned long);
        FRAME_HEADERS.SUB_TLV_SIZE      = FRAME_HEADERS.TLV_SIZE + 
                                          sizeof(char) + sizeof(short) + 
                                          sizeof(unsigned long long);

        pTEST_INTERFACE         = &TEST_INTERFACE;
        TEST_INTERFACE.IF_INDEX = IF_INDEX_DEF;
        for (int i = 0; i<IFNAMSIZ; i++) {
            TEST_INTERFACE.IF_NAME[i] = 0;
        }

        TEST_PARAMS.F_SIZE          = F_SIZE_DEF;
        TEST_PARAMS.F_SIZE_TOTAL    = F_SIZE_DEF + FRAME_HEADERS.LENGTH;
        TEST_PARAMS.F_DURATION      = F_DURATION_DEF;
        TEST_PARAMS.F_COUNT         = F_COUNT_DEF; 
        TEST_PARAMS.F_BYTES         = F_BYTES_DEF;
        TEST_PARAMS.S_ELAPSED       = 0;
        TEST_PARAMS.B_TX_SPEED_MAX  = B_TX_SPEED_MAX_DEF;
        TEST_PARAMS.B_TX_SPEED_PREV = 0;
        TEST_PARAMS.F_TX_COUNT      = 0;
        TEST_PARAMS.F_TX_COUNT_PREV = 0;
        TEST_PARAMS.F_TX_SPEED_MAX  = F_TX_SPEED_MAX_DEF;
        TEST_PARAMS.B_TX            = 0;
        TEST_PARAMS.B_TX_PREV       = 0;
        TEST_PARAMS.F_RX_COUNT      = 0;
        TEST_PARAMS.F_RX_COUNT_PREV = 0;
        TEST_PARAMS.B_RX            = 0;
        TEST_PARAMS.B_RX_PREV       = 0;
        TEST_PARAMS.F_INDEX_PREV    = 0;
        TEST_PARAMS.F_RX_ONTIME     = 0;
        TEST_PARAMS.F_RX_EARLY      = 0;
        TEST_PARAMS.F_RX_LATE       = 0;
        TEST_PARAMS.F_RX_OTHER      = 0;
        TEST_PARAMS.B_SPEED         = 0;
        TEST_PARAMS.B_SPEED_MAX     = 0;
        TEST_PARAMS.B_SPEED_AVG     = 0;
        TEST_PARAMS.F_ACK           = false;
        TEST_PARAMS.F_WAITING_ACK   = false;

        MTU_TEST.ENABLED    = false;
        MTU_TEST.MTU_TX_MIN = 1400;
        MTU_TEST.MTU_TX_MAX = 1500;

        pQM_TEST                 = &QM_TEST;
        QM_TEST.ENABLED          = false;
        QM_TEST.INTERVAL         = 1000;
        QM_TEST.INTERVAL_SEC     = 0;
        QM_TEST.INTERVAL_NSEC    = 0;
        QM_TEST.INTERVAL_MIN     = 99999.99999;
        QM_TEST.INTERVAL_MAX     = 0.0;
        QM_TEST.TIMEOUT          = 1000;
        QM_TEST.TIMEOUT_NSEC     = 0;
        QM_TEST.TIMEOUT_SEC      = 0;
        QM_TEST.TIMEOUT_COUNT    = 0;
        QM_TEST.DELAY_TEST_COUNT = 10000;
        QM_TEST.RTT_MIN          = 999999.999999;
        QM_TEST.RTT_MAX          = 0.0;
        QM_TEST.JITTER_MIN       = 999999.999999;
        QM_TEST.JITTER_MAX       = 0.0;
        QM_TEST.pDELAY_RESULTS   = (double*)calloc(QM_TEST.DELAY_TEST_COUNT,
                                                   sizeof(double));

        APP_PARAMS.TX_MODE     = true;
        APP_PARAMS.TX_SYNC     = true;
        APP_PARAMS.TX_DELAY    = TX_DELAY_DEF;
        


        /*
         ************************************************************* CLI ARGS
         */

        int CLI_RET_VAL = cli_args(argc, argv, &APP_PARAMS, &FRAME_HEADERS,
                                   &TEST_INTERFACE, &TEST_PARAMS, &MTU_TEST,
                                   &QM_TEST);

        if (CLI_RET_VAL == -2) {
            return EXIT_SUCCESS;
        } else if (CLI_RET_VAL == -1) {
            return EX_USAGE;
        }


        // Check for root privs because low level socket access is required
        if (getuid() != 0) {
            printf("Must be root to use this program!\n");
            return EX_NOPERM;
        }


        if (APP_PARAMS.TX_MODE) printf("Running in TX mode\n");
        else printf("Running in RX mode\n");


        /*
         ****************************************************** INTERFACE SETUP
         */

        TEST_INTERFACE.SOCKET_FD = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL));

///// Monitor sock1 for input
TEST_INTERFACE.fds[0].fd = TEST_INTERFACE.SOCKET_FD;
TEST_INTERFACE.fds[0].events = POLLIN;
TEST_INTERFACE.fds[0].revents = 0;

        if (TEST_INTERFACE.SOCKET_FD < 0 )
        {
          printf("Error defining socket!\n");
          perror("socket() ");
          close(TEST_INTERFACE.SOCKET_FD);
          return EX_SOFTWARE;
        }


        // If the user has supplied an interface index try to use that
        if (TEST_INTERFACE.IF_INDEX != IF_INDEX_DEF) {

            TEST_INTERFACE.IF_INDEX = set_sock_interface_index(&TEST_INTERFACE);
            if (TEST_INTERFACE.IF_INDEX == 0)
            {
                printf("Error: Couldn't set interface with index, "
                       "returned index was 0!\n");
                return EX_SOFTWARE;
            }

        // Or if the user has supplied an interface name try to use that        
        } else if (strcmp(TEST_INTERFACE.IF_NAME, "") != 0) {

            TEST_INTERFACE.IF_INDEX = set_sock_interface_name(&TEST_INTERFACE);
            if (TEST_INTERFACE.IF_INDEX == 0)
            {
                printf("Error: Couldn't set interface index from name, "
                       "returned index was 0!\n");
                return EX_SOFTWARE;
            }

        // Otherwise, try and best guess an interface
        } else if (TEST_INTERFACE.IF_INDEX == IF_INDEX_DEF) {

            TEST_INTERFACE.IF_INDEX = get_sock_interface(&TEST_INTERFACE);
            if (TEST_INTERFACE.IF_INDEX == 0)
            {
                printf("Error: Couldn't find appropriate interface ID, "
                      "returned ID was 0!\n Try supplying a source MAC address "
                      "with the -s option.\n");
                return EX_SOFTWARE;
            }

        }


        // Link layer socket setup
        TEST_INTERFACE.SOCKET_ADDRESS.sll_family   = PF_PACKET;	
        TEST_INTERFACE.SOCKET_ADDRESS.sll_protocol = htons(ETH_P_IP);
        TEST_INTERFACE.SOCKET_ADDRESS.sll_ifindex  = TEST_INTERFACE.IF_INDEX;    
        TEST_INTERFACE.SOCKET_ADDRESS.sll_hatype   = ARPHRD_ETHER;
        TEST_INTERFACE.SOCKET_ADDRESS.sll_pkttype  = PACKET_OTHERHOST;
        TEST_INTERFACE.SOCKET_ADDRESS.sll_halen    = ETH_ALEN;		
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[0]  = FRAME_HEADERS.DEST_MAC[0];		
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[1]  = FRAME_HEADERS.DEST_MAC[1];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[2]  = FRAME_HEADERS.DEST_MAC[2];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[3]  = FRAME_HEADERS.DEST_MAC[3];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[4]  = FRAME_HEADERS.DEST_MAC[4];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[5]  = FRAME_HEADERS.DEST_MAC[5];
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[6]  = 0x00;
        TEST_INTERFACE.SOCKET_ADDRESS.sll_addr[7]  = 0x00;

        // Send and receive buffers for incoming/outgoing ethernet frames
        FRAME_HEADERS.RX_BUFFER = (char*)calloc(1, F_SIZE_MAX);
        FRAME_HEADERS.TX_BUFFER = (char*)calloc(1, F_SIZE_MAX);

        build_headers(&FRAME_HEADERS);

        // Total size of the frame data (paylod size+headers), this excludes the
        // preamble & start frame delimiter, FCS and inter frame gap
        TEST_PARAMS.F_SIZE_TOTAL = TEST_PARAMS.F_SIZE + FRAME_HEADERS.LENGTH;


        int PHY_MTU = get_interface_mtu_by_name(&TEST_INTERFACE);
        
        if (PHY_MTU==-1) {

            printf("\nPhysical interface MTU unknown, "
                   "test might exceed physical MTU!\n\n");

        } else if (TEST_PARAMS.F_SIZE_TOTAL > PHY_MTU + 14) {
            
            printf("\nPhysical interface MTU (%u with headers) is less than\n"
                   "the test frame size (%u with headers). Test frames shall\n"
                   "bo limited to the interface MTU size\n\n",
                   PHY_MTU+14, TEST_PARAMS.F_SIZE_TOTAL);
            
            TEST_PARAMS.F_SIZE_TOTAL = PHY_MTU + 14;

        }

        // Fill the test frame with some random data
        for (unsigned int i = 0; i < (F_SIZE_MAX-FRAME_HEADERS.LENGTH); i++)
        {
            FRAME_HEADERS.TX_DATA[i] = (char)((255.0*rand()/(RAND_MAX+1.0)));
        }

        
        // Send and receive ret vals
        int TX_RET_VAL = 0;


        // Set the network interface to promiscuos mode
        printf("Entering promiscuous mode\n");
        strncpy(ethreq.ifr_name,TEST_INTERFACE.IF_NAME,IFNAMSIZ);

        if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCGIFFLAGS,&ethreq) == -1) 
        {

            printf("Error getting socket flags, entering promiscuous mode failed!\n");
            perror("ioctl() ");
            close(TEST_INTERFACE.SOCKET_FD);
            return EX_SOFTWARE;

        }

        ethreq.ifr_flags|=IFF_PROMISC;

        if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCSIFFLAGS,&ethreq) == -1)
        {

            printf("Error setting socket flags, entering promiscuous mode failed!\n");
            perror("ioctl() ");
            close(TEST_INTERFACE.SOCKET_FD);
            return EX_SOFTWARE;

        }


        // Declare sigint handler, TX will signal RX to reset when it quits
        signal (SIGINT,signal_handler);


        printf("Source MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
               FRAME_HEADERS.SOURCE_MAC[0],FRAME_HEADERS.SOURCE_MAC[1],
               FRAME_HEADERS.SOURCE_MAC[2],FRAME_HEADERS.SOURCE_MAC[3],
               FRAME_HEADERS.SOURCE_MAC[4],FRAME_HEADERS.SOURCE_MAC[5]);

        printf("Destination MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
               FRAME_HEADERS.DEST_MAC[0],FRAME_HEADERS.DEST_MAC[1],
               FRAME_HEADERS.DEST_MAC[2],FRAME_HEADERS.DEST_MAC[3],
               FRAME_HEADERS.DEST_MAC[4],FRAME_HEADERS.DEST_MAC[5]);


        // Broadcacst to populate any TCAM or MAC tables
        unsigned char TEMP_MAC[6] = {
            FRAME_HEADERS.DEST_MAC[0],
            FRAME_HEADERS.DEST_MAC[1],
            FRAME_HEADERS.DEST_MAC[2],
            FRAME_HEADERS.DEST_MAC[3],
            FRAME_HEADERS.DEST_MAC[4],
            FRAME_HEADERS.DEST_MAC[5],
        };

        FRAME_HEADERS.DEST_MAC[0] = 0xFF;
        FRAME_HEADERS.DEST_MAC[1] = 0xFF;
        FRAME_HEADERS.DEST_MAC[2] = 0xFF;
        FRAME_HEADERS.DEST_MAC[3] = 0xFF;
        FRAME_HEADERS.DEST_MAC[4] = 0xFF;
        FRAME_HEADERS.DEST_MAC[5] = 0xFF;

        // Rebuild frame headers with destination MAC
        build_headers(&FRAME_HEADERS);

        build_tlv(&FRAME_HEADERS, htons(TYPE_BROADCAST), htonl(VALUE_PRESENCE));
        // Build a dummy sub-TLV to align the buffers and pointers
        build_sub_tlv(&FRAME_HEADERS, htons(TYPE_APPLICATION_SUB_TLV),
                      htonll(VALUE_DUMMY));

        printf("Sending gratuitous broadcasts...\n");
        for (int i=1; i<=3; i++)
        {

            TX_RET_VAL = sendto(TEST_INTERFACE.SOCKET_FD, FRAME_HEADERS.TX_BUFFER,
                                FRAME_HEADERS.LENGTH+FRAME_HEADERS.TLV_SIZE, 0, 
                                (struct sockaddr*)&TEST_INTERFACE.SOCKET_ADDRESS,
                                sizeof(TEST_INTERFACE.SOCKET_ADDRESS));

            sleep(1);

        }


        FRAME_HEADERS.DEST_MAC[0] = TEMP_MAC[0];
        FRAME_HEADERS.DEST_MAC[1] = TEMP_MAC[1];
        FRAME_HEADERS.DEST_MAC[2] = TEMP_MAC[2];
        FRAME_HEADERS.DEST_MAC[3] = TEMP_MAC[3];
        FRAME_HEADERS.DEST_MAC[4] = TEMP_MAC[4];
        FRAME_HEADERS.DEST_MAC[5] = TEMP_MAC[5];

        build_headers(&FRAME_HEADERS);
        /////build_tlv(&FRAME_HEADERS, htons(TYPE_BROADCAST), htonl(VALUE_PRESENCE));
        /////build_sub_tlv(&FRAME_HEADERS, htons(TYPE_APPLICATION_SUB_TLV),
        /////htonll(VALUE_DUMMY));

        // Total size of the frame data (paylod size+headers), this excludes the
        // preamble & start frame delimiter, FCS and inter frame gap
/////        TEST_PARAMS.F_SIZE_TOTAL = TEST_PARAMS.F_SIZE + FRAME_HEADERS.LENGTH;



        /*
         ******************************************************** SETTINGS SYNC
         */

        sync_settings(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE, &TEST_PARAMS,
                      &MTU_TEST, &QM_TEST);

        // Pause to allow the RX host to process the sent settings
        sleep(1);

        // Rebuild the test frame headers in case any settings have been changed
        // by the TX host
        if (!APP_PARAMS.TX_MODE) build_headers(&FRAME_HEADERS);


        // Try to measure the TX to RX one way delay
        if (APP_PARAMS.TX_DELAY)
            delay_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE, &TEST_PARAMS,
                       &QM_TEST);


        /*
         ****************************************************** MAIN TEST PHASE
         */    

        if (MTU_TEST.ENABLED) {

            mtu_sweep_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE,
                           &TEST_PARAMS, &MTU_TEST);

        } else if (QM_TEST.ENABLED) {

            latency_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE,
                         &TEST_PARAMS, &QM_TEST);

        } else {

            speed_test(&APP_PARAMS, &FRAME_HEADERS, &TEST_INTERFACE,
                       &TEST_PARAMS);

        }
        

        // End the testing loop if TX host
        if (APP_PARAMS.TX_MODE) TESTING=false;

    }


    printf("Leaving promiscuous mode\n");

    strncpy(ethreq.ifr_name,TEST_INTERFACE.IF_NAME,IFNAMSIZ);

    if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCGIFFLAGS,&ethreq) == -1)
    {
        printf("Error getting socket flags, leaving promiscuous mode failed!\n");
        perror("ioctl() ");
        close(TEST_INTERFACE.SOCKET_FD);
        return EX_SOFTWARE;
    }

    ethreq.ifr_flags &= ~IFF_PROMISC;

    if (ioctl(TEST_INTERFACE.SOCKET_FD,SIOCSIFFLAGS,&ethreq) == -1)
    {
        printf("Error setting socket flags, leaving promiscuous mode failed\n");
        perror("ioctl() ");
        close(TEST_INTERFACE.SOCKET_FD);
        return EX_SOFTWARE;
    }

    close(TEST_INTERFACE.SOCKET_FD);

    free (QM_TEST.pDELAY_RESULTS);
    free (FRAME_HEADERS.RX_BUFFER);
    free (FRAME_HEADERS.TX_BUFFER);

    return EXIT_SUCCESS;

}
示例#14
0
void loop(char *input, render_callback render_board){
	
	/* case where it's the computer's turn to move: */
	if (!is_edit_mode && (comp_color == white_to_move || automode) 
		&& !force_mode && !must_sit && !result) {
		
		/* whatever happens, never allow pondering in normal search */
		is_pondering = FALSE_C;
		
		cpu_start = clock ();
		comp_move = think ();
		cpu_end = clock();
		
		ply = 0;
		
		/* must_sit can be changed by search */
		if (!must_sit || must_go != 0)
		{
			/* check for a game end: */
			if ((
				 ((Variant == Losers || Variant == Suicide)
				  && 
				  ((result != white_is_mated) && (result != black_is_mated)))
				 || 
				 ((Variant == Normal || Variant == Crazyhouse || Variant == Bughouse)
				  && ((comp_color == 1 && result != white_is_mated) 
					  ||
					  (comp_color == 0 && result != black_is_mated)
					  ))) 
				&& result != stalemate 
				&& result != draw_by_fifty 
				&& result != draw_by_rep) 
			{
				
				comp_to_coord (comp_move, output);
				
				hash_history[move_number] = hash;
				
				game_history[move_number] = comp_move;
				make (&comp_move, 0);
				
				/* saves state info */
				game_history_x[move_number++] = path_x[0];
				
				userealholdings = 0;
				must_go--;
				
				/* check to see if we draw by rep/fifty after our move: */
				if (is_draw ()) {
					result = draw_by_rep;
				}
				else if (fifty > 100) {
					result = draw_by_fifty;
				}
				
				root_to_move ^= 1;
				
				reset_piece_square ();
				
				if (book_ply < 40) {
					if (!book_ply) {
						strcpy(opening_history, output);
					}
					else {
						strcat(opening_history, output);
					}
				}
				
				book_ply++;
				
				printf ("\nNodes: %d (%0.2f%% qnodes)\n", nodes,
						(float) ((float) qnodes / (float) nodes * 100.0));
				
				elapsed = (cpu_end-cpu_start)/(double) CLOCKS_PER_SEC;
				nps = (float) nodes/(float) elapsed;
				
				if (!elapsed)
					printf ("NPS: N/A\n");
				else
					printf ("NPS: %d\n", (int32_t) nps);
				
				printf("ECacheProbes : %d   ECacheHits : %d   HitRate : %f%%\n", 
					   ECacheProbes, ECacheHits, 
					   ((float)ECacheHits/((float)ECacheProbes+1)) * 100);
				
				printf("TTStores : %d TTProbes : %d   TTHits : %d   HitRate : %f%%\n", 
					   TTStores, TTProbes, TTHits, 
					   ((float)TTHits/((float)TTProbes+1)) * 100);
				
				printf("NTries : %d  NCuts : %d  CutRate : %f%%  TExt: %d\n", 
					   NTries, NCuts, (((float)NCuts*100)/((float)NTries+1)), TExt);
				
				printf("Check extensions: %d  Razor drops : %d  Razor Material : %d\n", ext_check, razor_drop, razor_material);
				
				printf("EGTB Hits: %d  EGTB Probes: %d  Efficiency: %3.1f%%\n", EGTBHits, EGTBProbes,
					   (((float)EGTBHits*100)/(float)(EGTBProbes+1)));
				
				printf("Move ordering : %f%%\n", (((float)FHF*100)/(float)(FH+1)));
				
				printf("Material score: %d   Eval : %d  White hand: %d  Black hand : %d\n", 
					   Material, (int)eval(), white_hand_eval, black_hand_eval);
				
				printf("Hash : %X  HoldHash : %X\n", (unsigned)hash, (unsigned)hold_hash);
				
				/* check to see if we mate our opponent with our current move: */
				if (!result) {
					if (xb_mode) {
						
						/* safety in place here */
						if (comp_move.from != dummy.from || comp_move.target != dummy.target)
							printf ("move %s\n", output);
						
						if (Variant == Bughouse)
						{
							CheckBadFlow(FALSE_C);
						}	
					}
					else {
						if (comp_move.from != dummy.from || comp_move.target != dummy.target)
							printf ("\n%s\n", output);
					}
				}
				else {
					if (xb_mode) {
						if (comp_move.from != dummy.from || comp_move.target != dummy.target)
							printf ("move %s\n", output);
					}
					else {
						if (comp_move.from != dummy.from || comp_move.target != dummy.target)
							printf ("\n%s\n", output);
					}
					if (result == white_is_mated) {
						printf ("0-1 {Black Mates}\n");
					}
					else if (result == black_is_mated) {
						printf ("1-0 {White Mates}\n");
					}
					else if (result == draw_by_fifty) {
						printf ("1/2-1/2 {Fifty move rule}\n");
					}
					else if (result == draw_by_rep) {
						printf ("1/2-1/2 {3 fold repetition}\n");
					}
					else {
						printf ("1/2-1/2 {Draw}\n");
					}
					automode = 0;
				}
			}
			/* we have been mated or stalemated: */
			else {
				if (result == white_is_mated) {
					printf ("0-1 {Black Mates}\n");
				}
				else if (result == black_is_mated) {
					printf ("1-0 {White Mates}\n");
				}
				else if (result == draw_by_fifty) {
					printf ("1/2-1/2 {Fifty move rule}\n");
				}
				else if (result == draw_by_rep) {
					printf ("1/2-1/2 {3 fold repetition}\n");
				}
				else {
					printf ("1/2-1/2 {Draw}\n");
				}
				automode = 0;
			}
		}
	}
	
	/* get our input: */
	if (!xb_mode) {
		if (show_board) {
			printf ("\n");
			display_board (stdout, 1-comp_color);
			render_board(1-comp_color);
		}
		if (!automode)
		{
			printf ("Sjeng: ");
			//readStr(input, STR_BUFF);
			//			rinput (input, STR_BUFF, stdin);
		}
	}
	else {
		/* start pondering */
		
		if ((must_sit || (allow_pondering && !is_edit_mode && !force_mode &&
						  move_number != 0) || is_analyzing) && !result && !automode)
		{
			is_pondering = TRUE_C;
			think();
			is_pondering = FALSE_C;
			
			ply = 0;
		}
		if (!automode)
		{
			//rinput (input, STR_BUFF, stdin);
		}
	}
	
	/* check to see if we have a move.  If it's legal, play it. */
	if (!is_edit_mode && is_move (&input[0])) {
		if (verify_coord (input, &human_move)) {
			
			if (confirm_moves) printf ("Legal move: %s\n", input);
			
			game_history[move_number] = human_move;
			hash_history[move_number] = hash;
			
			make (&human_move, 0);
			game_history_x[move_number++] = path_x[0];
			
			reset_piece_square ();
			
			root_to_move ^= 1;
			
			if (book_ply < 40) {
				if (!book_ply) {
					strcpy(opening_history, input);
				}
				else {
					strcat(opening_history, input);
				}
			}
			
			book_ply++;
			
			if (show_board) {
				printf ("\n");
				display_board (stdout, 1-comp_color);
				render_board(1-comp_color);
			}
		}
		else {
			printf ("Illegal move: %s\n", input);
		}
	}
	else {
		
		/* make everything lower case for convenience: */
		/* GCP: except for setboard, which is case sensitive */
		if (!strstr(input, "setboard")){
			for (p = input; *p; p++) {
				*p = tolower (*p);
			}
		}
		
		/* command parsing: */
		if (!strcmp (input, "quit") || (!input[0] && feof(stdin))) {
			safe_fclose(lrn_standard);
			safe_fclose(lrn_zh);
			safe_fclose(lrn_suicide);
			safe_fclose(lrn_losers);
			free_hash();
			free_ecache();
			exit (EXIT_SUCCESS);
		}
		else if (!strcmp (input, "exit"))
		{
			if (is_analyzing)
			{
				is_analyzing = FALSE_C;
				is_pondering = FALSE_C;
				time_for_move = 0;
			}
			else
			{
				safe_fclose(lrn_standard);
				safe_fclose(lrn_zh);
				safe_fclose(lrn_suicide);
				safe_fclose(lrn_losers);
				free_hash();
				free_ecache();
				exit (EXIT_SUCCESS);
			}
		}
		else if (!strcmp (input, "diagram") || !strcmp (input, "d")) {
			toggle_bool_c (&show_board);
		}
		else if (!strncmp (input, "perft", 5)) {
			sscanf (input+6, "%d", &depth);
			raw_nodes = 0;
			xstart_time = rtime();
			perft (depth);
			printf ("Raw nodes for depth %d: %d\n", depth, raw_nodes);
			printf("Time : %.2f\n", (float)rdifftime(rtime(), xstart_time)/100.);
		}
		else if (!strcmp (input, "confirm_moves")) {
			confirm_moves = TRUE_C;
			printf("Will now confirm moves.\n");
		}
		else if (!strcmp (input, "new")) {
			
			if (xb_mode)
			{
				printf("tellics set 1 Sjeng " VERSION " (2001-9-28/%s)\n", setcode);
			}
			
			if (!is_analyzing)
			{	
				memcpy(material, std_material, sizeof(std_material));
				Variant = Normal;
				
				// memcpy(material, zh_material, sizeof(zh_material));
				//Variant = Crazyhouse;
				
				init_game ();
				initialize_hash();
				
				if (!braindeadinterface)
				{
					clear_tt();
					init_book();
					reset_ecache();
				}
				
				force_mode = FALSE_C;
				must_sit = FALSE_C;
				go_fast = FALSE_C;
				piecedead = FALSE_C;
				partnerdead = FALSE_C;
				kibitzed = FALSE_C;
				fixed_time = FALSE_C;
				
				root_to_move = WHITE;
				
				comp_color = 0;
				move_number = 0;
				hash_history[move_number] = 0;
				bookidx = 0;
				my_rating = opp_rating = 2000;
				must_go = 0;
				tradefreely = 1;
				automode = 0;
				
				CheckBadFlow(TRUE_C);
				ResetHandValue();
			}
			else
			{
				init_game ();
				move_number = 0;
			}
			
		}
		else if (!strcmp (input, "xboard")) {
			xb_mode = TRUE_C;
			toggle_bool_c (&show_board);
			signal (SIGINT, SIG_IGN);
			printf ("\n");
			
			/* Reset f5 in case we left with partner */
			printf("tellics set f5 1=1\n");
			
			BegForPartner();
		}
		else if (!strcmp (input, "nodes")) {
			printf ("Number of nodes: %d (%0.2f%% qnodes)\n", nodes,
					(float) ((float) qnodes / (float) nodes * 100.0));
		}
		else if (!strcmp (input, "nps")) {
			elapsed = (cpu_end-cpu_start)/(double) CLOCKS_PER_SEC;
			nps = (float) nodes/(float) elapsed;
			if (!elapsed)
				printf ("NPS: N/A\n");
			else
				printf ("NPS: %d\n", (int32_t) nps);
		}
		else if (!strcmp (input, "post")) {
			toggle_bool_c (&post);
			if (xb_mode)
				post = TRUE_C;
		}
		else if (!strcmp (input, "nopost")) {
			post = FALSE_C;
		}
		else if (!strcmp (input, "random")) {
			return;
		}
		else if (!strcmp (input, "hard")) {
			
			allow_pondering = TRUE_C;
			
			return;
		}
		else if (!strcmp (input, "easy")) {
			
			allow_pondering = FALSE_C;
			
			return;
		}
		else if (!strcmp (input, "?")) {
			return;
		}
		else if (!strcmp (input, "white")) {
			white_to_move = 1;
			root_to_move = WHITE;
			comp_color = 0;
		}
		else if (!strcmp (input, "black")) {
			white_to_move = 0;
			root_to_move = BLACK;
			comp_color = 1;
		}
		else if (!strcmp (input, "force")) {
			force_mode = TRUE_C;
		}
		else if (!strcmp (input, "eval")) {
			check_phase();
			printf("Eval: %d\n", (int)eval());
		}
		else if (!strcmp (input, "go")) {
			comp_color = white_to_move;
			force_mode = FALSE_C;
		}
		else if (!strncmp (input, "time", 4)) {
			sscanf (input+5, "%d", &time_left);
		}
		else if (!strncmp (input, "otim", 4)) {
			sscanf (input+5, "%d", &opp_time);
		}
		else if (!strncmp (input, "level", 5)) {
			if (strstr(input+6, ":"))
			{
				/* time command with seconds */
				sscanf (input+6, "%d %d:%d %d", &moves_to_tc, &min_per_game, 
						&sec_per_game, &inc);
				time_left = (min_per_game*6000) + (sec_per_game * 100);
				opp_time = time_left;
			}
			else
			{
				/* extract the time controls: */
				sscanf (input+6, "%d %d %d", &moves_to_tc, &min_per_game, &inc);
				time_left = min_per_game*6000;
				opp_time = time_left;
			}
			fixed_time = FALSE_C;
			time_cushion = 0; 
		}
		else if (!strncmp (input, "rating", 6)) {
			sscanf (input+7, "%d %d", &my_rating, &opp_rating);
			if (my_rating == 0) my_rating = 2000;
			if (opp_rating == 0) opp_rating = 2000;
		}
		else if (!strncmp (input, "holding", 7)) {
			ProcessHoldings(input);     
		}
		else if (!strncmp (input, "variant", 7)) {
			if (strstr(input, "normal"))
			{
				Variant = Normal;
				memcpy(material, std_material, sizeof(std_material));
				init_book();
			}
			else if (strstr(input, "crazyhouse"))
			{
				Variant = Crazyhouse;
				memcpy(material, zh_material, sizeof(zh_material));
				init_book();
			}
			else if (strstr(input, "bughouse"))
			{
				Variant = Bughouse;
				memcpy(material, zh_material, sizeof(zh_material));
				init_book();
			}
			else if (strstr(input, "suicide"))
			{
				Variant = Suicide;
				Giveaway = FALSE_C;
				memcpy(material, suicide_material, sizeof(suicide_material));
				init_book();
			}
			else if (strstr(input, "giveaway"))
			{
				Variant = Suicide;
				Giveaway = TRUE_C;
				memcpy(material, suicide_material, sizeof(suicide_material));
				init_book();
			}
			else if (strstr(input, "losers"))
			{
				Variant = Losers;
				memcpy(material, losers_material, sizeof(losers_material));
				init_book();
			}
			
			initialize_hash();
			clear_tt();
			reset_ecache();
			
		}
		else if (!strncmp (input, "analyze", 7)) {
			is_analyzing = TRUE_C;
			is_pondering = TRUE_C;
			think();
			ply = 0;
		}
		else if (!strncmp (input, "undo", 4)) {
			printf("Move number : %d\n", move_number);
			if (move_number > 0)
			{
				path_x[0] = game_history_x[--move_number];
				unmake(&game_history[move_number], 0);
				reset_piece_square();
				root_to_move ^= 1;
			}
			result = 0;
		}
		else if (!strncmp (input, "remove", 5)) {
			if (move_number > 1)
			{
				path_x[0] = game_history_x[--move_number];
				unmake(&game_history[move_number], 0);
				reset_piece_square();
				
				path_x[0] = game_history_x[--move_number];
				unmake(&game_history[move_number], 0);
				reset_piece_square();
			}
			result = 0;
		}
		else if (!strncmp (input, "edit", 4)) {
			is_edit_mode = TRUE_C;
			edit_color = WHITE;
		}
		else if (!strncmp (input, ".", 1) && is_edit_mode) {
			is_edit_mode = FALSE_C;
			if (wking_loc == 30) white_castled = no_castle;
			if (bking_loc == 114) black_castled = no_castle;
			book_ply = 50;
			ep_square = 0;
			move_number = 0;
			memset(opening_history, 0, sizeof(opening_history));
			clear_tt();
			initialize_hash();
			reset_piece_square();
		}
		else if (is_edit_mode && !strncmp (input, "c", 1)) {
			if (edit_color == WHITE) edit_color = BLACK; else edit_color = WHITE;
		}
		else if (is_edit_mode && !strncmp (input, "#", 1)) {
			reset_board();
			move_number = 0;
		}
		else if (is_edit_mode 
				 && isalpha(input[0]) 
				 && isalpha(input[1]) 
				 && isdigit(input[2])) {
			PutPiece(edit_color, input[0], input[1], input[2]);
		}
		else if (!strncmp (input, "partner", 7)) {
			HandlePartner(input+7);
		}
		else if (!strncmp (input, "$partner", 8)) {
			HandlePartner(input+8);
		}
		else if (!strncmp (input, "ptell", 5)) {
			HandlePtell(input);
		}
		else if (!strncmp (input, "test", 4)) {
			run_epd_testsuite();
		}
		else if (!strncmp (input, "st", 2)) {
			sscanf(input+3, "%d", &fixed_time);
			fixed_time = fixed_time * 100;
		}
		else if (!strncmp (input, "book", 4)) {
			build_book();
		}
		else if (!strncmp (input, "speed",  5)) {
			speed_test();
		}
		else if (!strncmp (input, "result", 6)) {
			if (cfg_booklearn)
			{
				if (strstr (input+7, "1-0"))
				{
					if (comp_color == 1)
						book_learning(WIN);
					else
						book_learning(LOSS);
				}
				else if (strstr(input+7, "0-1"))
				{
					if (comp_color == 1)
						book_learning(LOSS);
					else
						book_learning(WIN);
				}
				else if (strstr(input+7, "1/2-1/2"))
				{
					book_learning(DRAW);
				};
			}
		}
		else if (!strncmp (input, "prove", 5)) {
			printf("\nMax time to search (s): ");
			start_time = rtime();
			rinput(readbuff, STR_BUFF, stdin);
			pn_time = atoi(readbuff) * 100;
			printf("\n");
			proofnumbersearch();      
		}
		else if (!strncmp (input, "ping", 4)) {
			sscanf (input+5, "%d", &pingnum);
			printf("pong %d\n", pingnum);
		}
		else if (!strncmp (input, "fritz", 5)) {
			braindeadinterface = TRUE_C;
		}
		else if (!strncmp (input, "reset", 5)) {
			
			memcpy(material, std_material, sizeof(std_material));
			Variant = Normal;
			
			init_game ();
			initialize_hash();
			
			clear_tt();
			init_book();
			reset_ecache();       
			
			force_mode = FALSE_C;
			fixed_time = FALSE_C;
			
			root_to_move = WHITE;
			
			comp_color = 0;
			move_number = 0;
			bookidx = 0;
			my_rating = opp_rating = 2000;
		}
		else if (!strncmp (input, "setboard", 8)) {
			setup_epd_line(input+9);
		}
		else if (!strncmp (input, "buildegtb", 9)) {
			Variant = Suicide;
			gen_all_tables();
		}
		else if (!strncmp (input, "lookup", 6)) {
			Variant = Suicide;
			printf("Value : %d\n", egtb(white_to_move));
		}
		else if (!strncmp (input, ".", 1)) {
			/* periodic updating and were not searching */
			/* most likely due to proven mate */
			return;
		}
		else if (!strncmp (input, "sd", 2)) {
			sscanf(input+3, "%d", &maxdepth);
			printf("New max depth set to: %d\n", maxdepth);
			return;
		}
		else if (!strncmp (input, "auto", 4)) {
			automode = 1;
			return;
		}
		else if (!strncmp (input, "protover", 8)) {
			printf("feature ping=1 setboard=1 playother=0 san=0 usermove=0 time=1\n");
			printf("feature draw=0 sigint=0 sigterm=0 reuse=1 analyze=1\n");
			printf("feature myname=\"Sjeng " VERSION "\"\n");
			printf("feature variants=\"normal,bughouse,crazyhouse,suicide,giveaway,losers\"\n");
			printf("feature colors=1 ics=0 name=0 pause=0 done=1\n");
			xb_mode = 2;
		}
		else if (!strncmp (input, "accepted", 8)) {
			/* do nothing as of yet */
		}
		else if (!strncmp (input, "rejected", 8)) {
			printf("Interface does not support a required feature...expect trouble.\n");
		}
		else if (!strncmp (input, "warranty", 8)) {
			printf("\n  BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY\n"
				   "FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN\n"
				   "OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES\n"
				   "PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED\n"
				   "OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\n"
				   "MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS\n"
				   "TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE\n"
				   "PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,\n"
				   "REPAIR OR CORRECTION.\n"
				   "\n");
			printf("  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\n"
				   "WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR\n"
				   "REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,\n"
				   "INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING\n"
				   "OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED\n"
				   "TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY\n"
				   "YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER\n"
				   "PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE\n"
				   "POSSIBILITY OF SUCH DAMAGES.\n\n");
			
		}
		else if (!strncmp (input, "distribution", 12)) {
			printf("\n  You may copy and distribute verbatim copies of the Program's\n"
				   "source code as you receive it, in any medium, provided that you\n"
				   "conspicuously and appropriately publish on each copy an appropriate\n"
				   "copyright notice and disclaimer of warranty; keep intact all the\n"
				   "notices that refer to this License and to the absence of any warranty;\n"
				   "and give any other recipients of the Program a copy of this License\n"
				   "along with the Program.\n"
				   "\n"
				   "You may charge a fee for the physical act of transferring a copy, and\n"
				   "you may at your option offer warranty protection in exchange for a fee.\n\n");
			
		}
		else if (!strcmp (input, "help")) {
			printf ("\n%s\n\n", divider);
			printf ("diagram/d:       toggle diagram display\n");
			printf ("exit/quit:       terminate Sjeng\n");
			printf ("go:              make Sjeng play the side to move\n");
			printf ("new:             start a new game\n");
			printf ("level <x>:       the xboard style command to set time\n");
			printf ("  <x> should be in the form: <a> <b> <c> where:\n");
			printf ("  a -> moves to TC (0 if using an ICS style TC)\n");
			printf ("  b -> minutes per game\n");
			printf ("  c -> increment in seconds\n");
			printf ("nodes:           outputs the number of nodes searched\n");
			printf ("nps:             outputs Sjeng's NPS in search\n");
			printf ("perft <x>:       compute raw nodes to depth x\n");
			printf ("post:            toggles thinking output\n");
			printf ("xboard:          put Sjeng into xboard mode\n");
			printf ("test:            run an EPD testsuite\n");
			printf ("speed:           test movegen and evaluation speed\n");
			printf ("warranty:        show warranty details\n");
			printf ("distribution:    show distribution details\n");
			printf( "proof:           try to prove or disprove the current pos\n");
			printf( "sd <x>:          limit thinking to depth x\n");
			printf( "st <x>:          limit thinking to x centiseconds\n");
			printf( "setboard <FEN>:  set board to a specified FEN string\n");
			printf( "undo:            back up a half move\n");
			printf( "remove:          back up a full move\n");
			printf( "force:           disable computer moving\n");
			printf( "auto:            computer plays both sides\n");
			printf ("\n%s\n\n", divider);
			
			show_board = 0;
		}
		else if (!xb_mode) {
			printf ("Illegal move: %s\n", input);
		}
		
	}
	
}
示例#15
0
int
run_main (int argc, ACE_TCHAR *argv[])
{
  ACE_START_TEST (ACE_TEXT ("Cached_Allocator_Test"));

  size_t chunk_size = 0;
  size_t n_chunks   = 0;
  size_t requested_size = 0;
  size_t depth = 0;
  char *ptr1 = 0;
  char *ptr2 = 0;
  char *ptr3 = 0;
  char *ptr4 = 0;
  ACE_UINT32 loops = 0;

  const char *str1 = "12345678";
  const char *str3 = "ABCDEFGH";

  if (argc < 2)
    loops = 10000000;
  else
    loops = ACE_OS::atoi (argv[1]);

  chunk_size = 8;
  n_chunks = 2;

  ACE_DEBUG ((LM_INFO,
              ACE_TEXT (" (%t) Creating allocator: ")
              ACE_TEXT ("%B chunks, %B bytes each\n"),
              n_chunks,
              chunk_size));

  DYNAMIC_ALLOCATOR allocator (n_chunks, chunk_size);

  if ((depth = allocator.pool_depth ()) != n_chunks)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Expected pool depth %B but reported %B\n"),
                n_chunks, depth));
  requested_size = chunk_size;
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT (" (%t) Allocating chunk 1: %B bytes, should succeed...\n"),
              requested_size));

  ptr1 = (char *) allocator.malloc (requested_size);
  if (!ptr1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%t) Failed, exiting.\n")), -1);

  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) OK, succeeded.\n")));
  if ((depth = allocator.pool_depth ()) != (n_chunks - 1))
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Expected pool depth %B but reported %B\n"),
                n_chunks - 1, depth));

  requested_size = chunk_size + 1;
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT (" (%t) Allocating chunk 2: %B bytes, too big, should fail...\n"),
              requested_size));

  ptr2 = (char *) allocator.malloc (requested_size);
  if (!ptr2)
    ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) OK, failed.\n")));
  else
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%t) Something is wrong...\n")), -1);

  requested_size = chunk_size - 1;
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT (" (%t) Allocating chunk 3: %B bytes, ")
              ACE_TEXT ("should succeed...\n"),
              requested_size));
  ptr3 = (char *) allocator.malloc (requested_size);
  if (!ptr3)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%t) Failed, exiting.\n")), -1);

  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) OK, succeeded.\n")));

  // One chunk too far...
  if ((depth = allocator.pool_depth ()) != 0)
    ACE_ERROR ((LM_ERROR,
                ACE_TEXT ("Expected pool depth 0 but reported %B\n"),
                depth));
  requested_size = chunk_size;
  ACE_DEBUG ((LM_INFO,
              ACE_TEXT (" (%t) Allocating chunk 4: %B bytes, no free chunks,")
              ACE_TEXT (" should fail...\n"),
              requested_size));

  ptr4 = (char *) allocator.malloc (requested_size);
  if (!ptr4)
    ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) OK, failed.\n")));
  else
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%t) Something is wrong\n")), -1);

  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Writing to chunk 1:   %C\n"), str1));
  ACE_OS::memcpy (ptr1, str1, chunk_size);
  ptr1[chunk_size - 1] = '\0';
  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Reading from chunk 1: %C\n"), ptr1));

  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Writing to chunk 3:   %C\n"), str3));
  ACE_OS::memcpy (ptr3, str3, chunk_size);
  ptr3[chunk_size - 1] = '\0';
  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Reading from chunk 3: %C\n"), ptr3));

  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Deallocating chunk 1\n")));
  allocator.free (ptr1);

  requested_size = chunk_size;
  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Allocating chunk: %B bytes, ")
                       ACE_TEXT ("should succeed...\n"),
              requested_size));
  ptr1 = (char *) allocator.malloc (requested_size);
  if (!ptr1)
    ACE_ERROR_RETURN ((LM_ERROR, ACE_TEXT (" (%t) Failed, exiting.\n")), -1);

  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) OK, succeeded.\n")));

  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Deallocating chunk 1\n")));
  allocator.free (ptr1);
  ACE_DEBUG ((LM_INFO, ACE_TEXT (" (%t) Deallocating chunk 3\n")));
  allocator.free (ptr3);

  speed_test (loops);
  stdspeed_test (loops);

  ACE_END_TEST;
  return 0;
}