📄 testpdma.c
字号:
{
UCHAR errorBuffer[MAX_ERROR_BUFFER];
ULONG outputCount = 0;
outputCount = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
ErrorCode,
0,
errorBuffer,
sizeof(errorBuffer),
NULL
);
if (outputCount) {
printf("%s\n", errorBuffer);
} else {
printf("Format message failed. Error: %d\n", GetLastError());
}
} // PrintError
DWORD
ReadTest(
IN HANDLE FileHandle,
IN LPVOID DataBuffer,
IN DWORD BufferSize
)
{
DWORD bytesReturned;
DWORD errorCode = NO_ERROR;
FillMemory(DataBuffer, MAX_DATA_BUFFER, FILL_MEMORY_BYTE);
if (!ReadFile(FileHandle,
DataBuffer,
BufferSize,
&bytesReturned,
NULL
)) {
errorCode = GetLastError();
printf("ReadFile failed %d \n", errorCode);
PrintError(errorCode);
//
// Fall through...
//
} else {
printf("ReadFile succeeded. Bytes returned %d \n", bytesReturned);
}
return errorCode;
} // ReadTest
VOID
ReleaseBuffers(
IN PBUFFER_INFO BufferInfo,
IN USHORT NumberOfBuffers
)
{
USHORT i;
printf("Releasing concurrent data buffers \n");
for (i = 0; i < NumberOfBuffers; i++) {
if (BufferInfo->DataBuffer) {
VirtualFree(BufferInfo->DataBuffer,
BufferInfo->Length,
MEM_DECOMMIT
);
}
BufferInfo++;
}
} // ReleaseBuffers
BOOLEAN
VerifyInputParameters(
IN SHORT ArgC,
IN PCHAR ArgV[],
IN PUSER_PARMS UserParms
)
{
PCHAR programName;
PCHAR loopCount;
USHORT i;
USHORT flags = 0;
BOOLEAN parmError = FALSE;
BOOLEAN verifyStatus = FALSE;
BOOLEAN done = FALSE;
//
// Get the program name for displaying error messages.
//
programName = ArgV[0];
printf("\n");
//
// Verify that the number of parameters looks correct.
//
if (ArgC < 2) {
printf("Option required. \n");
DisplayUsage(programName);
return FALSE;
}
//
// Set the default device number.
//
strcpy(UserParms->DeviceNumber, "0");
//
// Check each argument.
//
while (--ArgC > 0 && !done) {
++ArgV;
if (((*ArgV)[0] != '-') &&
((*ArgV)[0] != '/')) {
printf("Invalid option indicator \n");
parmError = TRUE;
break;
}
//
// Each argument is a string. Check each character in the string.
//
for (i = 0; !done && (*ArgV)[i] != 0; i++) {
switch ((*ArgV)[i]) {
case '?':
//
// Not really an error, but we don't want to continue
// the program.
//
parmError = TRUE;
done = TRUE;
break;
case 'a':
//
// Enable async test.
//
flags |= FLAG_TEST_ASYNC;
break;
case 'd':
//
// Currently, we are pointing at the 'd'. Move to
// the next character and save the device number string.
//
if (0 == (*ArgV)[++i]) {
printf("No device number specified. \n");
//
// Now we're pointing at the end of the string. Have to
// backup one char because the for loop will increment the
// pointer before the next check. So backup one...
//
i--;
} else {
//
// Copy the device number to the user parms sting.
//
strcpy(UserParms->DeviceNumber, &((*ArgV)[i]));
//
// Skip to the end of the string to parse the next
// parameter.
//
while ((*ArgV)[i] != 0) {
//
// Explicitly increment the counter inside the while
// loop, or we will be two places beyond where we want
// to be.
//
// Originally used:
// while ((*ArgV)[i++] != 0)
// NOTHING;
//
// But in this case the check was made and then the
// counter incremented even if the value was zero.
//
i++;
}
//
// Now we're pointing at the end of the string. Have to
// backup one char because the for loop will increment the
// pointer before the next check. So backup one...
//
i--;
}
break;
case 's':
//
// Enable sync test.
//
flags |= FLAG_TEST_SYNC;
break;
case 't':
//
// Get the total I/O loop count.
//
loopCount = &((*ArgV)[i+1]);
//
// Skip past the actual number.
//
while ((*ArgV)[i] != 0) {
//
// Explicitly increment the counter inside the while
// loop, or we will be two places beyond where we want
// to be.
//
// Originally used:
// while ((*ArgV)[i++] != 0)
// NOTHING;
//
// But in this case the check was made and then the
// counter incremented even if the value was zero.
//
i++;
}
//
// Now we're pointing at the end of the string. Have to
// backup one char because the for loop will increment the
// pointer before the next check. So backup one...
//
i--;
sscanf(loopCount, "%d", &UserParms->LoopCount);
printf("Total loop count = %d \n", UserParms->LoopCount);
if (UserParms->LoopCount <= 0) {
parmError = TRUE;
printf("Invalid loop count specified \n");
} else if (UserParms->LoopCount < MAX_CONCURRENT_IO) {
printf("Requested loop count < concurrent I/O count (%d) \n",
MAX_CONCURRENT_IO
);
parmError = TRUE;
}
break;
case 'v':
flags |= FLAG_VERBOSE_MODE;
break;
case '-':
case '/':
//
// Skip past normal option indicators.
//
break;
default:
printf("Unknown option: %s \n", (*ArgV));
parmError = TRUE;
//
// Skip past the argument.
//
while ((*ArgV)[i] != 0) {
//
// Explicitly increment the counter inside the while
// loop, or we will be two places beyond where we want
// to be.
//
// Originally used:
// while ((*ArgV)[i++] != 0)
// NOTHING;
//
// But in this case the check was made and then the
// counter incremented even if the value was zero.
//
i++;
}
//
// Now we're pointing at the end of the string. Have to
// backup one char because the for loop will increment the
// pointer before the next check. So backup one...
//
i--;
break;
} // switch
} // for
}
//
// If no test enabled, there is nothing to do. Display
// message and return error.
//
if (!(flags & FLAG_TESTS_ENABLED)) {
printf("All tests disabled! \n");
parmError = TRUE;
}
//
// If any kind of error, display usage and exit program.
//
if (parmError) {
DisplayUsage(programName);
return FALSE;
}
UserParms->Flags = flags;
return TRUE;
} // VerifyInputParameters
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -