示例#1
0
void WaitForTestTransfer(struct BENCHMARK_TRANSFER_PARAM* transferParam)
{
    DWORD exitCode;
    while (transferParam)
    {
        if (!transferParam->IsRunning)
        {
            if (GetExitCodeThread(transferParam->ThreadHandle, &exitCode))
            {
                if (exitCode == 0)
                {
                    CONMSG("stopped Ep%02Xh thread.\tExitCode=%d\n",
                              transferParam->Ep.bEndpointAddress, exitCode);
                    break;
                }
            }
            else
            {
                CONERR("failed getting Ep%02Xh thread exit code!\n",transferParam->Ep.bEndpointAddress);
                break;
            }
        }
        Sleep(100);
        CONMSG("waiting for Ep%02Xh thread..\n", transferParam->Ep.bEndpointAddress);
    }
}
示例#2
0
void ShowRunningStatus(struct BENCHMARK_TRANSFER_PARAM* transferParam)
{
	struct BENCHMARK_TRANSFER_PARAM temp;
	DOUBLE bpsOverall;
	DOUBLE bpsLastTransfer;
    
	// LOCK the display critical section
    EnterCriticalSection(&DisplayCriticalSection);
	
	memcpy(&temp, transferParam, sizeof(struct BENCHMARK_TRANSFER_PARAM));
	
	// UNLOCK the display critical section
    LeaveCriticalSection(&DisplayCriticalSection);

    if ((!temp.StartTick) || (temp.StartTick >= temp.LastTick))
    {
        CONMSG("Synchronizing %d..\n", abs(transferParam->Packets));
    }
    else
    {
        GetAverageBytesSec(&temp,&bpsOverall);
        GetCurrentBytesSec(&temp,&bpsLastTransfer);
		transferParam->LastStartTick = 0;
		CONMSG("Avg. Bytes/s: %.2f Transfers: %d Bytes/s: %.2f\n",
			bpsOverall, temp.Packets, bpsLastTransfer);
    }

}
示例#3
0
CommandHook *SourceLuaConsole::HookOrAddConCommand(const char* name, CommandCallback callback, const char *help, int flags) {
  ConCommand *current = g_iCVar->FindCommand(name);
  if(!current) {
    CONMSG("Registering %s\n", name);
    return RegConCommand(name, callback, help, flags);
  } else {
    CONMSG("Command %s already exists, hooking\n", name);
    return new CommandHook(current, callback);
  }
}
示例#4
0
void sourcelua_concmd(const CCommand &command) {
  int args = command.ArgC();
  if(args >= 2) {
    const char *cmd = command.Arg(1);
    if(strcmp(cmd, "version") == 0) {
      CONMSG("SourceLua v%s\n", SOURCELUA_VERSION);
      CONMSG("  - %s\n", LUAJIT_VERSION);
      CONMSG("  - %s\n", LUA_VERSION);
    }
  }
}
示例#5
0
void ShowTestInfo(struct BENCHMARK_TEST_PARAM* testParam)
{
    if (!testParam) return;

    CONMSG("%s Test Information\n",TestDisplayString[testParam->TestType & 3]);
    CONMSG("\tVid / Pid       : %04Xh / %04Xh\n", testParam->Vid,  testParam->Pid);
    CONMSG("\tInterface #     : %02Xh\n", testParam->Intf);
    CONMSG("\tPriority        : %d\n", testParam->Priority);
    CONMSG("\tBuffer Size     : %d\n", testParam->BufferSize);
    CONMSG("\tBuffer Count    : %d\n", testParam->BufferCount);
    CONMSG("\tDisplay Refresh : %d (ms)\n", testParam->Refresh);
    CONMSG("\tTransfer Timeout: %d (ms)\n", testParam->Timeout);
    CONMSG("\tRetry Count     : %d\n", testParam->Retry);
    CONMSG("\tVerify Data     : %s%s\n",
		testParam->Verify ? "On" : "Off",
		(testParam->Verify && testParam->VerifyDetails) ? " (Detailed)" : "");

    CONMSG0("\n");
}
示例#6
0
void ShowTransferInfo(struct BENCHMARK_TRANSFER_PARAM* transferParam)
{
    DOUBLE bpsAverage;
    DOUBLE bpsCurrent;
    DOUBLE elapsedSeconds;

	if (!transferParam) return;

	CONMSG("%s %s (Ep%02Xh) max packet size: %d\n",
		EndpointTypeDisplayString[ENDPOINT_TYPE(transferParam)],
		TRANSFER_DISPLAY(transferParam,"Read","Write"),
		transferParam->Ep.bEndpointAddress,
		transferParam->Ep.wMaxPacketSize);

	if (transferParam->StartTick)
    {
        GetAverageBytesSec(transferParam,&bpsAverage);
        GetCurrentBytesSec(transferParam,&bpsCurrent);
        CONMSG("\tTotal Bytes     : %I64d\n", transferParam->TotalTransferred);
        CONMSG("\tTotal Transfers : %d\n", transferParam->Packets);

		if (transferParam->ShortTransferCount)
		{
			CONMSG("\tShort Transfers : %d\n", transferParam->ShortTransferCount);
		}
		if (transferParam->TotalTimeoutCount)
		{
			CONMSG("\tTimeout Errors  : %d\n", transferParam->TotalTimeoutCount);
		}
		if (transferParam->TotalErrorCount)
		{
			CONMSG("\tOther Errors    : %d\n", transferParam->TotalErrorCount);
		}

        CONMSG("\tAvg. Bytes/sec  : %.2f\n", bpsAverage);

		if (transferParam->StartTick && transferParam->StartTick < transferParam->LastTick)
		{
			elapsedSeconds = (transferParam->LastTick - transferParam->StartTick) / 1000.0;

			CONMSG("\tElapsed Time    : %.2f seconds\n", elapsedSeconds);
		}

	    CONMSG0("\n");
    }

}
示例#7
0
int main(int argc, char** argv)
{
    struct BENCHMARK_TEST_PARAM Test;
    struct BENCHMARK_TRANSFER_PARAM* ReadTest	= NULL;
    struct BENCHMARK_TRANSFER_PARAM* WriteTest	= NULL;
    int key;


    if (argc == 1)
    {
        ShowHelp();
        return -1;
    }

	ShowCopyright();

    // NOTE: This is the log level for the benchmark application.
    //
#if defined __ERROR_H__
    usb_log_set_level(255);
#endif

    SetTestDefaults(&Test);

    // Load the command line arguments.
    if (ParseBenchmarkArgs(&Test, argc, argv) < 0)
        return -1;

    // Initialize the critical section used for locking
    // the volatile members of the transfer params in order
    // to update/modify the running statistics.
    //
    InitializeCriticalSection(&DisplayCriticalSection);

    // Initialize the library.
    usb_init();

    // Find all busses.
    usb_find_busses();

    // Find all connected devices.
    usb_find_devices();

    if (Test.UseList)
    {
        if (GetTestDeviceFromList(&Test) < 0)
            goto Done;
    }
    else
    {
        // Open a benchmark device. see Bench_Open().
        Test.DeviceHandle = Bench_Open(Test.Vid, Test.Pid, Test.Intf, Test.Altf, &Test.Device);
    }
    if (!Test.DeviceHandle || !Test.Device)
    {
        CONERR("device %04X:%04X not found!\n",Test.Vid, Test.Pid);
        goto Done;
    }

    // If "NoTestSelect" appears in the command line then don't send the control
    // messages for selecting the test type.
    //
    if (!Test.NoTestSelect)
    {
        if (Bench_SetTestType(Test.DeviceHandle, Test.TestType, Test.Intf) != 1)
        {
            CONERR("setting bechmark test type #%d!\n%s\n", Test.TestType, usb_strerror());
            goto Done;
        }
    }

    CONMSG("Benchmark device %04X:%04X opened..\n",Test.Vid, Test.Pid);

    // If reading from the device create the read transfer param. This will also create
    // a thread in a suspended state.
    //
    if (Test.TestType & TestTypeRead)
    {
        ReadTest = CreateTransferParam(&Test, Test.Ep | USB_ENDPOINT_DIR_MASK);
        if (!ReadTest) goto Done;
    }

    // If writing to the device create the write transfer param. This will also create
    // a thread in a suspended state.
    //
    if (Test.TestType & TestTypeWrite)
    {
        WriteTest = CreateTransferParam(&Test, Test.Ep);
        if (!WriteTest) goto Done;
    }

    // Set configuration #1.
    if (usb_set_configuration(Test.DeviceHandle, 1) < 0)
    {
        CONERR("setting configuration #%d!\n%s\n",1,usb_strerror());
        goto Done;
    }

    // Claim_interface Test.Intf (Default is #0)
    if (usb_claim_interface(Test.DeviceHandle, Test.Intf) < 0)
    {
        CONERR("claiming interface #%d!\n%s\n", Test.Intf, usb_strerror());
        goto Done;
    }

    // Set the alternate setting (Default is #0)
	if (usb_set_altinterface(Test.DeviceHandle, Test.Altf) < 0)
	{
		CONERR("selecting alternate setting #%d on interface #%d!\n%s\n", Test.Altf,  Test.Intf, usb_strerror());
        goto Done;
	}
	else
	{
		if (Test.Altf > 0)
		{
			CONDBG("selected alternate setting #%d on interface #%d\n",Test.Altf,  Test.Intf);
		}
	}

	if (Test.Verify)
	{
		if (ReadTest && WriteTest)
		{
			if (CreateVerifyBuffer(&Test, WriteTest->Ep.wMaxPacketSize) < 0)
				goto Done;
		}
		else if (ReadTest)
		{
			if (CreateVerifyBuffer(&Test, ReadTest->Ep.wMaxPacketSize) < 0)
				goto Done;
		}
	}

	ShowTestInfo(&Test);
	ShowTransferInfo(ReadTest);
	ShowTransferInfo(WriteTest);

	CONMSG0("\nWhile the test is running:\n");
	CONMSG0("Press 'Q' to quit\n");
	CONMSG0("Press 'T' for test details\n");
	CONMSG0("Press 'I' for status information\n");
	CONMSG0("Press 'R' to reset averages\n");
    CONMSG0("\nPress 'Q' to exit, any other key to begin..");
    key = _getch();
    CONMSG0("\n");

    if (key=='Q' || key=='q') goto Done;

    // Set the thread priority and start it.
    if (ReadTest)
    {
        SetThreadPriority(ReadTest->ThreadHandle, Test.Priority);
        ResumeThread(ReadTest->ThreadHandle);
    }

    // Set the thread priority and start it.
    if (WriteTest)
    {
        SetThreadPriority(WriteTest->ThreadHandle, Test.Priority);
        ResumeThread(WriteTest->ThreadHandle);
    }

    while (!Test.IsCancelled)
    {
        Sleep(Test.Refresh);

        if (_kbhit())
        {
            // A key was pressed.
            key = _getch();
            switch (key)
            {
            case 'Q':
            case 'q':
                Test.IsUserAborted = TRUE;
                Test.IsCancelled = TRUE;
                break;
			case 'T':
			case 't':
				ShowTestInfo(&Test);
				break;
            case 'I':
            case 'i':
                // LOCK the display critical section
                EnterCriticalSection(&DisplayCriticalSection);

                // Print benchmark test details.
				ShowTransferInfo(ReadTest);
				ShowTransferInfo(WriteTest);


                // UNLOCK the display critical section
                LeaveCriticalSection(&DisplayCriticalSection);
                break;

            case 'R':
            case 'r':
                // LOCK the display critical section
                EnterCriticalSection(&DisplayCriticalSection);

                // Reset the running status.
                ResetRunningStatus(ReadTest);
                ResetRunningStatus(WriteTest);

                // UNLOCK the display critical section
                LeaveCriticalSection(&DisplayCriticalSection);
                break;
            }

            // Only one key at a time.
            while (_kbhit()) _getch();
        }

        // If the read test should be running and it isn't, cancel the test.
        if ((ReadTest) && !ReadTest->IsRunning)
        {
            Test.IsCancelled = TRUE;
            break;
        }

        // If the write test should be running and it isn't, cancel the test.
        if ((WriteTest) && !WriteTest->IsRunning)
        {
            Test.IsCancelled = TRUE;
            break;
        }

        // Print benchmark stats
        if (ReadTest)
            ShowRunningStatus(ReadTest);
        else
            ShowRunningStatus(WriteTest);

    }

	// Wait for the transfer threads to complete gracefully if it
	// can be done in 10ms. All of the code from this point to
	// WaitForTestTransfer() is not required.  It is here only to
	// improve response time when the test is cancelled.
	//
    Sleep(10);

	// If the thread is still running, abort and reset the endpoint.
    if ((ReadTest) && ReadTest->IsRunning)
        usb_resetep(Test.DeviceHandle, ReadTest->Ep.bEndpointAddress);

    // If the thread is still running, abort and reset the endpoint.
    if ((WriteTest) && WriteTest->IsRunning)
        usb_resetep(Test.DeviceHandle, WriteTest->Ep.bEndpointAddress);

    // Small delay incase usb_resetep() was called.
    Sleep(10);

    // WaitForTestTransfer will not return until the thread
	// has exited.
    WaitForTestTransfer(ReadTest);
    WaitForTestTransfer(WriteTest);

    // Print benchmark detailed stats
	ShowTestInfo(&Test);
	if (ReadTest) ShowTransferInfo(ReadTest);
	if (WriteTest) ShowTransferInfo(WriteTest);


Done:
    if (Test.DeviceHandle)
    {
        usb_close(Test.DeviceHandle);
        Test.DeviceHandle = NULL;
    }
	if (Test.VerifyBuffer)
	{
		free(Test.VerifyBuffer);
		Test.VerifyBuffer = NULL;

	}
    FreeTransferParam(&ReadTest);
    FreeTransferParam(&WriteTest);

    DeleteCriticalSection(&DisplayCriticalSection);

    CONMSG0("Press any key to exit..");
    _getch();
    CONMSG0("\n");

    return 0;
}
示例#8
0
int GetTestDeviceFromList(struct BENCHMARK_TEST_PARAM* testParam)
{
    const int LINE_MAX_SIZE   = 1024;
    const int STRING_MAX_SIZE = 256;
    const int NUM_STRINGS = 3;
    const int ALLOC_SIZE = LINE_MAX_SIZE + (STRING_MAX_SIZE * NUM_STRINGS);

    int userInput;

    char* buffer;
    char* line;
    char* product;
    char* manufacturer;
    char* serial;

    struct usb_bus* bus;
    struct usb_device* dev;
    usb_dev_handle* udev;
    struct usb_device* validDevices[256];

    int deviceIndex=0;
	struct usb_interface_descriptor* firstInterface;

    int ret = -1;

    buffer = malloc(ALLOC_SIZE);
    if (!buffer)
    {
        CONERR0("failed allocating memory!\n");
        return ret;
    }

    line = buffer;
    product = buffer + LINE_MAX_SIZE;
    manufacturer = product + STRING_MAX_SIZE;
    serial = manufacturer + STRING_MAX_SIZE;

    for (bus = usb_get_busses(); bus; bus = bus->next)
    {
        for (dev = bus->devices; dev; dev = dev->next)
        {

            udev = usb_open(dev);
            if (udev)
            {
                memset(buffer, 0, ALLOC_SIZE);
                line = buffer;
                if (dev->descriptor.iManufacturer)
                {
                    if (usb_get_string_simple(udev, dev->descriptor.iManufacturer, manufacturer, STRING_MAX_SIZE - 1) > 0)
                    {
                        strcat(line,"(");
                        strcat(line,manufacturer);
                        strcat(line,") ");
                    }
                }

                if (dev->descriptor.iProduct)
                {
                    if (usb_get_string_simple(udev, dev->descriptor.iProduct, product, STRING_MAX_SIZE - 1) > 0)
                    {
                        strcat(line,product);
                        strcat(line," ");
                    }
                }

                if (dev->descriptor.iSerialNumber)
                {
                    if (usb_get_string_simple(udev, dev->descriptor.iSerialNumber, serial, STRING_MAX_SIZE - 1) > 0)
                    {
                        strcat(line,"[");
                        strcat(line,serial);
                        strcat(line,"] ");
                    }
                }

                if (!deviceIndex)
                    CONMSG0("\n");

                validDevices[deviceIndex++] = dev;

                CONMSG("%d. %04X:%04X %s\n",
                          deviceIndex, dev->descriptor.idVendor, dev->descriptor.idProduct, line);

                usb_close(udev);
            }
        }
    }
    
	if (!deviceIndex) 
	{
		CONERR0("No devices where found!\n");
		ret = -1;
		goto Done;
	}

    CONMSG("\nSelect device (1-%d) :",deviceIndex);
	ret = _cscanf("%i",&userInput);
    if (ret != 1 || userInput < 1)
	{
        CONMSG0("\n");
        CONMSG0("Aborting..\n");
		ret = -1;
		goto Done;
	}
    CONMSG0("\n");
    userInput--;
    if (userInput >= 0 && userInput < deviceIndex)
    {
        testParam->DeviceHandle = usb_open(validDevices[userInput]);
        if (testParam->DeviceHandle)
        {
			testParam->Device = validDevices[userInput];
            testParam->Vid = testParam->Device->descriptor.idVendor;
            testParam->Pid = testParam->Device->descriptor.idProduct;
			if (usb_find_interface(&validDevices[userInput]->config[0],testParam->Intf, testParam->Altf, &firstInterface) == NULL)
			{
				// the specified (or default) interface didn't exist, use the first one.
				if (firstInterface != NULL)
				{
					testParam->Intf = firstInterface->bInterfaceNumber;
				}
				else
				{
					CONERR("device %04X:%04X does not have any interfaces!\n",
						testParam->Vid, testParam->Pid);
					ret = -1;
					goto Done;
				}
			}
            ret = 0;
        }
	}

Done:
	if (buffer)
        free(buffer);

    return ret;
}