/*++ Copyright (c) 1999 Microsoft Corporation Module Name: PSTRESS.C Abstract: This application is a console app for performing the parser stress functionality that was originally included with hidview.exe. It takes a path to some report descriptor binary files and continually passes them to the kernel mode driver USBTEST.SYS for parsing by HIDPARSE.SYS. It requires both USBTEST.SYS and USBTEST.DLL to run correctly. Environment: user mode Revision History: 09-21-99 : created --*/ //***************************************************************************** // I N C L U D E S //***************************************************************************** #include #include #include #include #include #include #include "usbtest.h" //***************************************************************************** // D E F I N E S //***************************************************************************** #define VER_PRODUCTVERSION_STR "0.90" #define DEFAULT_DESC_PATH "." #define FILE_WILDCARD_STRING "*.bin" #define REPORT_DESC_HEADER "REPORT" #define DESCRIPTOR_HEADER_SIZE 11 //***************************************************************************** // G L O B A L S //***************************************************************************** // // PSTRESS command line parameters // ULONG TestIterations; CHAR DescPath[MAX_PATH+1]; BOOL Verbose; // // Global boolean that is set by ctrl-c handled to indicate test thread should // terminate. // BOOL Abort; // // Name of the current file that is being parsed // CHAR CurrentParserFile[MAX_PATH+1]; //***************************************************************************** // L O C A L F U N C T I O N D E C L A R A T I O N S //***************************************************************************** BOOL ParseArgs ( int argc, char *argv[] ); VOID Usage( VOID ); VOID Version( VOID ); BOOL DoParserStress( VOID ); BOOL WINAPI CtrlHandlerRoutine ( DWORD dwCtrlType ); //***************************************************************************** // F U N C T I O N D E F I N I T I O N S //***************************************************************************** int __cdecl main( int argc, char *argv[] ) { ULONG index; BOOL success; TestIterations = 1; if (!ParseArgs(argc, argv)) { return 1; } // // Set a CTRL-C / CTRL-BREAK handler // Abort = FALSE; SetConsoleCtrlHandler(CtrlHandlerRoutine, TRUE); success = DoParserStress(); if (!success) { printf("Error %d occurred running parser stress\n", GetLastError()); } // // Return an errorlevel code of 1 if the test failed and some point // return (success ? 0 : 1); } //***************************************************************************** // // ParseArgs() // //***************************************************************************** BOOL ParseArgs ( int argc, char *argv[] ) { int i, j; ULONG pathLength; PCHAR path; if (argc < 2) { Usage(); return FALSE; } for (i=1; i MAX_PATH) { iteration++; continue; } strcat(CurrentParserFile, fileData.cFileName); printf("Going to parse file %s\n", CurrentParserFile); // // Open handle to the file we want to send to parse // fileHandle = CreateFile(CurrentParserFile, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL); if (INVALID_HANDLE_VALUE == fileHandle) { success = FALSE; continue; } // // Get the number of bytes to read in // if (0 != fileData.nFileSizeHigh) { // // Report descriptor file is bigger than 4GB...Hmm...probably an // error...just skip it // iteration++; continue; } descSize = fileData.nFileSizeLow; dataBuffer = ALLOC(descSize); if (NULL == dataBuffer) { SetLastError(ERROR_OUTOFMEMORY); success = FALSE; continue; } // // Read in the file // success = ReadFile(fileHandle, dataBuffer, descSize, &nBytes, NULL); CloseHandle(fileHandle); if (!success) { continue; } // // Attempt to parse the report descriptor // repDesc = dataBuffer; if (0 == memcmp(repDesc, REPORT_DESC_HEADER, strlen(REPORT_DESC_HEADER))) { repDesc += DESCRIPTOR_HEADER_SIZE; descSize -= DESCRIPTOR_HEADER_SIZE; } success = ParseReportDescriptor(repDesc, descSize, &hidDeviceDesc); printf("hidDeviceDesc: %08x\n", hidDeviceDesc); FREE(hidDeviceDesc); errorCode = GetLastError(); FREE(dataBuffer); if (!success) { SetLastError(errorCode); continue; } // // Get the next file to process // success = FindNextFile(fileSearchHandle, &fileData); if (!success) { errorCode = GetLastError(); if (ERROR_NO_MORE_FILES == errorCode) { FindClose(fileSearchHandle); fileSearchHandle = FindFirstFile(DescPath, &fileData); success = (INVALID_HANDLE_VALUE != fileSearchHandle); } } iteration++; } return (success); } //***************************************************************************** // // CtrlHandlerRoutine() // //***************************************************************************** BOOL WINAPI CtrlHandlerRoutine ( DWORD dwCtrlType ) { BOOL handled; switch (dwCtrlType) { case CTRL_C_EVENT: case CTRL_BREAK_EVENT: Abort = TRUE; handled = TRUE; break; default: handled = FALSE; break; } return handled; }