📄 perform.c
字号:
TestResult_t Result = TEST_PASSED; STAVFS_Handle_t DiskHandle; STAVFS_FileHandle_t FileHandle; int Partition; U64 FileSize; U32 FileBytes = 10 * M_BYTES; /* 100 MB takes too long (~36 mins writing 100 byte chunks 1 sect/clust) */ I64_SetValue (FileBytes, 0, FileSize); for (Partition = 1; Partition <= 3; Partition += 2) { if (TEST_PASSED != OpenPartition (0, Partition, DEV_NAME, &DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } else { /* Create the file */ if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, STAVFS_WRITE_MODE | STAVFS_READ_MODE, FileSize, &FileHandle)) { EXTRA_Print (("Couldn't create %u MB file on partition %i\n", FileBytes / M_BYTES, Partition)); Result = TEST_FAILED; } else { WriteReadInner (FileHandle, Partition, FileBytes, &Result); /* Close and delete the file */ if (ST_NO_ERROR != STAVFS_CloseFile(FileHandle)) { EXTRA_Print (("Couldn't close file on partition %i\n", Partition)); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME)) { EXTRA_Print (("Couldn't delete file on partition %i\n", Partition)); Result = TEST_FAILED; } } if (TEST_PASSED != ClosePartition (DEV_NAME, DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } /* In all cases of failure, still try the other partition */ } } return (Result);}/******************************************************************************Function Name : WriteReadInner Description : Inner part of WriteRead test comprising all the write/read subtests run on a particular file Parameters : file handle, partition number (for messages), place to record test failure******************************************************************************/static void WriteReadInner(STAVFS_FileHandle_t FileHandle, int Partition, U32 BytesLimit, TestResult_t * Result_p){ ST_ErrorCode_t Error; static U32 const BlockSizes[] = { 512, 1024, 4*K_BYTES, 64*K_BYTES, /* aligned */ 500, 1000, 4000, 64000, /* non-aligned */ }; int DoReads, SizeIdx; U64 ZeroPos; U32 BytesThisPass; /* bytes transfered so far in this pass over the file */ U32 BytesThisOp; /* bytes that will be transfered in next read/write */ U32 DataCnt; /* for STAVFS_Write/ReadFile */ /* absolute time values */ clock_t StartTime, EndTime; /* time value differences */ clock_t DeltaTime; /* errors are not expected; in the two cases where they can occur, returns are used to avoid overhead managing the state. Cleanup is handled by the calling function */ I64_SetValue (0, 0, ZeroPos); for (DoReads = 0; DoReads <= 1; ++DoReads) { STTBX_Print (("\n\t%s %u MB file on %i sector(s) per cluster:\n", (DoReads ? "Reading" : "Writing"), BytesLimit / M_BYTES, TestPartitionDefs[Partition].SizeOfCluster)); for (SizeIdx = 0; SizeIdx < TABLE_LEN(BlockSizes); ++SizeIdx) { assert (BlockSizes[SizeIdx] <= sizeof(Buffer)); if (ST_NO_ERROR != STAVFS_SeekFile (FileHandle, ZeroPos, STAVFS_START, DoReads ? FALSE : TRUE)) { EXTRA_Print (("Couldn't %s-seek to start of file\n", (DoReads ? "read" : "write") )); *Result_p = TEST_FAILED; return; } StartTime = time_now (); /* write in chunks of the specified size, except potentially the last, which we shrink to give the exact total bytes requested */ BytesThisOp = BlockSizes[SizeIdx]; for (BytesThisPass = 0; (BytesThisPass < BytesLimit); BytesThisPass += BytesThisOp) { if (BytesThisPass + BytesThisOp > BytesLimit) { BytesThisOp = BytesLimit - BytesThisPass; } if (DoReads) { Error = STAVFS_ReadFile (FileHandle, Buffer, BytesThisOp, &DataCnt); } else { Error = STAVFS_WriteFile (FileHandle, Buffer, BytesThisOp, &DataCnt); } if (Error != ST_NO_ERROR) { EXTRA_Print (("Couldn't %s file\n", (DoReads ? "read" : "write") )); *Result_p = TEST_FAILED; return; } if (BytesThisPass % (BytesLimit/10) < BlockSizes[SizeIdx]) { /* Breakpoint here will fire every 1/10th of total size */ BytesThisOp = BytesThisOp; } } EndTime = time_now (); DeltaTime = time_minus (EndTime, StartTime); /* display results */ STTBX_Print (("\t\t%5u byte chunks: %6u ms\n", BlockSizes[SizeIdx], DeltaTime / TicksPerMS)); } }}/******************************************************************************Function Name : WriteExpand Description : Performance tests for write-extend operations Parameters :******************************************************************************/static TestResult_t WriteExpand(int TestNo, TestVariant_t Variant){ TestResult_t Result = TEST_PASSED; STAVFS_Handle_t DiskHandle; STAVFS_OpenMode_t OpenMode; STAVFS_FileHandle_t FileHandle; static U32 const BlockSizes[] = { 500, 1000, 4000, 64000 }; int Partition, Streaming, SizeIdx; U64 FileSize; /* The following will still try other permutations if one fails - to back out more quickly, append " && (Result == TEST_PASSED)" to the loop conditions */ I64_SetValue (0, 0, FileSize); /* make it expand as we write */ for (Partition = 1; (Partition <= 3); Partition += 2) { if (TEST_PASSED != OpenPartition (0, Partition, DEV_NAME, &DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } else { for (Streaming = 0; (Streaming <= 1); ++Streaming) { OpenMode = (Streaming ? STAVFS_STREAM_FILE : 0); OpenMode |= STAVFS_WRITE_MODE; STTBX_Print (("\n\tWrite-expanding %s file" " on %i sector(s) per cluster:\n", (Streaming ? "stream" : "regular"), TestPartitionDefs[Partition].SizeOfCluster)); for (SizeIdx = 0; (SizeIdx < TABLE_LEN(BlockSizes)); ++SizeIdx) { /* Create the file */ if (ST_NO_ERROR != STAVFS_OpenFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME, OpenMode, FileSize, &FileHandle)) { EXTRA_Print (("Couldn't create %s file on partition %i\n", (Streaming ? "stream" : "regular"), Partition)); Result = TEST_FAILED; } else { WriteExpandInner (FileHandle, BlockSizes[SizeIdx], &Result); /* Close and delete the file */ if (ST_NO_ERROR != STAVFS_CloseFile(FileHandle)) { EXTRA_Print (("Couldn't close file on partition %i\n", Partition)); Result = TEST_FAILED; } if (ST_NO_ERROR != STAVFS_DeleteFile (DiskHandle, STAVFS_NULL_FILE_HANDLE, FILE_NAME)) { EXTRA_Print (("Couldn't delete file on partition %i\n", Partition)); Result = TEST_FAILED; } } /* STAVFS_FileOpen succeeds */ } /* loop over BlockSizes */ } /* loop over Streaming */ if (TEST_PASSED != ClosePartition (DEV_NAME, DiskHandle)) { Result = TEST_FAILED; /* message already displayed */ } } /* OpenPartition succeeds */ } /* loop over Partition */ return (Result);}/******************************************************************************Function Name : WriteExpandInner Description : Inner part of WriteExpand test comprising all the write/read subtests run on a particular file Parameters : file handle, standard block size to write in, place to record test failure******************************************************************************/static void WriteExpandInner(STAVFS_FileHandle_t FileHandle, U32 BlockSize, TestResult_t * Result_p){ /* standard total number of bytes we will write */ static U32 const BytesLimit = 10 * M_BYTES; U32 BytesThisPass; /* total bytes written so far */ U32 BytesThisOp; /* bytes that will be transfered in next write */ U32 DataCnt; /* for STAVFS_Write/ReadFile */ /* absolute time values */ clock_t StartTime, OpStartTime, EndTime; /* time value differences */ clock_t DeltaTime, LongestTime = 0; assert (BlockSize <= sizeof(Buffer)); /* start the output line so user has an idea of how long it might take */ STTBX_Print (("\t %u MB in %5u byte chunks: ", BytesLimit / M_BYTES, BlockSize)); OpStartTime = StartTime = time_now (); /* write in chunks of the specified size, except potentially the last, which we shrink to give the exact total bytes requested */ BytesThisOp = BlockSize; for (BytesThisPass = 0; (BytesThisPass < BytesLimit); BytesThisPass += BytesThisOp) { if (BytesThisPass + BytesThisOp > BytesLimit) { BytesThisOp = BytesLimit - BytesThisPass; } if (ST_NO_ERROR != STAVFS_WriteFile (FileHandle, Buffer, BytesThisOp, &DataCnt)) { EXTRA_Print (("Couldn't write file\n")); /* caller standard message has given Streaming and Partition info */ *Result_p = TEST_FAILED; return; /* caller handles all clean-up */ } EndTime = time_now (); DeltaTime = time_minus (EndTime, OpStartTime); if (DeltaTime > LongestTime) { LongestTime = DeltaTime; } if (BytesThisPass % (BytesLimit/10) < BlockSize) { /* Breakpoint here will fire every 1/10th of total size */ BytesThisOp = BytesThisOp; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -