public void BVT_CopyOffload() { BaseTestSite.Log.Add(LogEntryKind.TestStep, "1. Create a file with specified length {0} as the source of offload copy.", TestConfig.WriteBufferLengthInKb * 1024); string content = Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb); string fileName = Guid.NewGuid().ToString(); uint treeId; FILEID fileIdSrc; PrepareTestFile(fileName, content, out treeId, out fileIdSrc); BaseTestSite.Log.Add(LogEntryKind.TestStep, "2. Client sends IOCTL request with FSCTL_OFFLOAD_READ to ask server to generate the token of the content for offload copy."); STORAGE_OFFLOAD_TOKEN token; ulong fileOffsetToRead = 0; //FileOffset should be aligned to logical sector boundary on the volume, e.g. 512 bytes ulong copyLengthToRead = (ulong)TestConfig.WriteBufferLengthInKb * 1024; //CopyLength should be aligned to logical sector boundary on the volume, e.g. 512 bytes ulong transferLength; // Request hardware to generate a token that represents a range of file to be copied client.OffloadRead( treeId, fileIdSrc, fileOffsetToRead, copyLengthToRead, out transferLength, out token); BaseTestSite.Log.Add(LogEntryKind.Debug, "Transfer length during OFFLOAD_READ is {0}", transferLength); BaseTestSite.Assert.AreEqual(copyLengthToRead, transferLength, "Transfer length {0} should be equal to copy length {1}", transferLength, copyLengthToRead); BaseTestSite.Log.Add(LogEntryKind.TestStep, "3. Create another file as the destination of offload copy."); FILEID fileIdDest; Smb2CreateContextResponse[] serverCreateContexts; client.Create( treeId, Guid.NewGuid().ToString(), CreateOptions_Values.FILE_NON_DIRECTORY_FILE, out fileIdDest, out serverCreateContexts); // The destination file of CopyOffload Write should be equal to or larger than the size of original file client.Write(treeId, fileIdDest, Smb2Utility.CreateRandomString(TestConfig.WriteBufferLengthInKb)); client.Flush(treeId, fileIdDest); BaseTestSite.Log.Add(LogEntryKind.TestStep, "4. Client sends IOCTL request with FSCTL_OFFLOAD_WRITE to ask server to copy the content from source to destination."); ulong fileOffsetToWrite = 0; //FileOffset should be aligned to logical sector boundary on the volume, e.g. 512 bytes ulong copyLengthToWrite = transferLength; //CopyLength should be aligned to logical sector boundary on the volume, e.g. 512 bytes ulong transferOffset = 0; //TransferOffset should be aligned to logical sector boundary on the volume, e.g. 512 bytes // Request hardware to write a range of file which is represented by the generated token // and length/offset to another place (a different file or different offset of the same file) client.OffloadWrite( treeId, fileIdDest, fileOffsetToWrite, copyLengthToWrite, transferOffset, token); BaseTestSite.Log.Add(LogEntryKind.TestStep, "5. Compare the content of section 1 with the content of section 2."); string readContent; // Read the content that was just offload copied client.Read( treeId, fileIdDest, fileOffsetToWrite, (uint)copyLengthToWrite, out readContent); BaseTestSite.Assert.IsTrue( readContent.Equals(content), "File content read should equal to original"); BaseTestSite.Log.Add(LogEntryKind.TestStep, "6. Tear down the client by sending the following requests: CLOSE; TREE_DISCONNECT; LOG_OFF."); client.Close(treeId, fileIdSrc); client.Close(treeId, fileIdDest); client.TreeDisconnect(treeId); client.LogOff(); }