/* DISKSPD Copyright(c) Microsoft Corporation All rights reserved. MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ #include "StdAfx.h" #include "XmlResultParser.UnitTests.h" #include "Common.h" #include "xmlresultparser.h" #include #include using namespace WEX::TestExecution; using namespace WEX::Logging; using namespace std; namespace UnitTests { void XmlResultParserUnitTests::Test_ParseResults() { Profile profile; TimeSpan timeSpan; Target target; XmlResultParser parser; Results results; results.fUseETW = false; double fTime = 120.0; results.ullTimeCount = PerfTimer::SecondsToPerfTime(fTime); // First group has 1 active cpu // 30% user, 45% idle, 25% non-idle kernel (45% + 25% = 70%) SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION systemProcessorInfo = { 0 }; systemProcessorInfo.UserTime.QuadPart = static_cast(fTime * 30 * 100000); systemProcessorInfo.IdleTime.QuadPart = static_cast(fTime * 45 * 100000); systemProcessorInfo.KernelTime.QuadPart = static_cast(fTime * 70 * 100000); results.vSystemProcessorPerfInfo.push_back(systemProcessorInfo); // Second group has 2 active // 100% idle systemProcessorInfo.UserTime.QuadPart = static_cast(fTime * 0 * 100000); systemProcessorInfo.IdleTime.QuadPart = static_cast(fTime * 100 * 100000); systemProcessorInfo.KernelTime.QuadPart = static_cast(fTime * 100 * 100000); results.vSystemProcessorPerfInfo.push_back(systemProcessorInfo); results.vSystemProcessorPerfInfo.push_back(systemProcessorInfo); // TODO: multiple target cases, full profile/result variations target.SetPath("testfile1.dat"); target.SetCacheMode(TargetCacheMode::DisableOSCache); target.SetWriteThroughMode(WriteThroughMode::On); target.SetThroughputIOPS(1000); timeSpan.AddTarget(target); timeSpan.SetCalculateIopsStdDev(true); TargetResults targetResults; targetResults.sPath = "testfile1.dat"; targetResults.ullFileSize = 10 * 1024 * 1024; targetResults.ullReadBytesCount = 4 * 1024 * 1024; targetResults.ullReadIOCount = 6; targetResults.ullWriteBytesCount = 2 * 1024 * 1024; targetResults.ullWriteIOCount = 10; targetResults.ullBytesCount = targetResults.ullReadBytesCount + targetResults.ullWriteBytesCount; targetResults.ullIOCount = targetResults.ullReadIOCount + targetResults.ullWriteIOCount; // TODO: Histogram readLatencyHistogram; // TODO: Histogram writeLatencyHistogram; // TODO: IoBucketizer writeBucketizer; targetResults.readBucketizer.Initialize(1000, timeSpan.GetDuration()); for (size_t i = 0; i < timeSpan.GetDuration(); i++) { // add an io halfway through the bucket's time interval targetResults.readBucketizer.Add(i*1000 + 500, 0); } ThreadResults threadResults; threadResults.vTargetResults.push_back(targetResults); results.vThreadResults.push_back(threadResults); vector vResults; vResults.push_back(results); // Just throw away the computername, pp and reset the timestamp - for the ut, it's // as useful (and simpler) to verify statics as anything else. Reconstruct the // processor topo to a fixed example as well. Note that the performance // efficiency class must be placed since it is calculated on the fly during // the actual GLPIEx enumeration. If we could shim GLPIEx ... SystemInformation system; system.ResetTime(); system.sComputerName.clear(); system.sActivePolicyName.clear(); system.sActivePolicyGuid.clear(); system.processorTopology._ulProcessorCount = 3; system.processorTopology._ubPerformanceEfficiencyClass = 1; system.processorTopology._fSMT = true; system.processorTopology._vProcessorGroupInformation.clear(); system.processorTopology._vProcessorGroupInformation.emplace_back((WORD)0, (BYTE)1, (BYTE)1, (KAFFINITY)0x1); system.processorTopology._vProcessorGroupInformation.emplace_back((WORD)1, (BYTE)4, (BYTE)2, (KAFFINITY)0x3); ProcessorNumaInformation node; node._nodeNumber = 0; node._vProcessorMasks.emplace_back((WORD)0, (KAFFINITY)0x1); node._vProcessorMasks.emplace_back((WORD)1, (KAFFINITY)0x3); system.processorTopology._vProcessorNumaInformation.clear(); system.processorTopology._vProcessorNumaInformation.push_back(node); ProcessorSocketInformation socket; socket._vProcessorMasks.emplace_back((WORD)0, (KAFFINITY)0x1); socket._vProcessorMasks.emplace_back((WORD)1, (KAFFINITY)0x3); system.processorTopology._vProcessorSocketInformation.clear(); system.processorTopology._vProcessorSocketInformation.push_back(socket); system.processorTopology._vProcessorCoreInformation.clear(); system.processorTopology._vProcessorCoreInformation.emplace_back((WORD)0, (KAFFINITY)0x1, (BYTE)0); system.processorTopology._vProcessorCoreInformation.emplace_back((WORD)1, (KAFFINITY)0x3, (BYTE)1); // finally, add the timespan to the profile and dump. profile.AddTimeSpan(timeSpan); string sResults = parser.ParseResults(profile, system, vResults); // stringify random text, quoting "'s and adding newline/preserving tabs // gc some.txt |% { write-host $("`"{0}\n`"" -f $($_ -replace "`"","\`"" -replace "`t","\t")) } const char *pcszExpectedOutput = \ "\n" " \n" " \n" " \n" " " DISKSPD_NUMERIC_VERSION_STRING "\n" " " DISKSPD_DATE_VERSION_STRING "\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " 0\n" " text\n" " false\n" " \n" " \n" " false\n" " false\n" " true\n" " false\n" " 10\n" " 5\n" " 0\n" " 0\n" " 0\n" " 1000\n" " 0\n" " \n" " \n" " testfile1.dat\n" " 65536\n" " 0\n" " false\n" " false\n" " false\n" " false\n" " true\n" " true\n" " \n" " sequential\n" " \n" " false\n" " 65536\n" " false\n" " 0\n" " 0\n" " 2\n" " 0\n" " 1000\n" " 1\n" " 3\n" " 1\n" " \n" " \n" " \n" " \n" " \n" " \n" " 120.00\n" " 1\n" " 0\n" " 3\n" " \n" " \n" " 0\n" " 0\n" " 0\n" " 0\n" " 0\n" " 0\n" " 55.00\n" " 30.00\n" " 25.00\n" " 45.00\n" " \n" " \n" " 0\n" " 0\n" " 1\n" " 0\n" " 1\n" " 0\n" " 0.00\n" " 0.00\n" " 0.00\n" " 100.00\n" " \n" " \n" " 0\n" " 0\n" " 1\n" " 0\n" " 1\n" " 1\n" " 0.00\n" " 0.00\n" " 0.00\n" " 100.00\n" " \n" " \n" " 18.33\n" " 10.00\n" " 8.33\n" " 81.67\n" " \n" " \n" " \n" " 0.000\n" " 0.000\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " 0\n" " \n" " testfile1.dat\n" " 6291456\n" " 10485760\n" " 16\n" " 4194304\n" " 6\n" " 2097152\n" " 10\n" " \n" " 0.000\n" " 0.000\n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" " \n" ""; #if 0 HANDLE h; DWORD written; h = CreateFileW(L"g:\\xmlresult-received.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(h, sResults.c_str(), (DWORD)sResults.length(), &written, NULL); VERIFY_ARE_EQUAL(sResults.length(), written); CloseHandle(h); h = CreateFileW(L"g:\\xmlresult-expected.txt", GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); WriteFile(h, pcszExpectedOutput, (DWORD)strlen(pcszExpectedOutput), &written, NULL); VERIFY_ARE_EQUAL((DWORD)strlen(pcszExpectedOutput), written); CloseHandle(h); printf("--\n%s\n", sResults.c_str()); printf("-------------------------------------------------\n"); printf("--\n%s\n", pcszExpectedOutput); #endif VERIFY_ARE_EQUAL(0, strcmp(sResults.c_str(), pcszExpectedOutput)); } void XmlResultParserUnitTests::Test_ParseProfile() { Profile profile; XmlResultParser parser; TimeSpan timeSpan; Target target; timeSpan.AddTarget(target); profile.AddTimeSpan(timeSpan); string s = parser.ParseProfile(profile); const char *pcszExpectedOutput = "\n" " 0\n" " text\n" " false\n" " \n" " \n" " false\n" " false\n" " false\n" " false\n" " 10\n" " 5\n" " 0\n" " 0\n" " 0\n" " 1000\n" " 0\n" " \n" " \n" " \n" " 65536\n" " 0\n" " false\n" " false\n" " false\n" " false\n" " \n" " sequential\n" " \n" " false\n" " 65536\n" " false\n" " 0\n" " 0\n" " 2\n" " 0\n" " 0\n" " 1\n" " 3\n" " 1\n" " \n" " \n" " \n" " \n" "\n"; //VERIFY_ARE_EQUAL(pcszExpectedOutput, s.c_str()); VERIFY_ARE_EQUAL(strlen(pcszExpectedOutput), s.length()); VERIFY_IS_TRUE(!strcmp(pcszExpectedOutput, s.c_str())); } void XmlResultParserUnitTests::Test_ParseTargetProfile() { Target target; string sResults; char pszExpectedOutput[4096]; int nWritten; const char *pcszOutputTemplate = \ "\n" " testfile1.dat\n" " 65536\n" " 0\n" " false\n" " false\n" " false\n" " false\n" " true\n" " true\n" " \n" " sequential\n" " \n" " false\n" " 65536\n" " false\n" " 0\n" " 0\n" " 2\n" " 0\n" " %s\n" // 2 param " 1\n" " 3\n" " 1\n" "\n"; target.SetPath("testfile1.dat"); target.SetCacheMode(TargetCacheMode::DisableOSCache); target.SetWriteThroughMode(WriteThroughMode::On); // Base case - no limit nWritten = sprintf_s(pszExpectedOutput, sizeof(pszExpectedOutput), pcszOutputTemplate, "", "0"); VERIFY_IS_GREATER_THAN(nWritten, 0); sResults = target.GetXml(0); VERIFY_ARE_EQUAL(sResults, pszExpectedOutput); // IOPS - with units target.SetThroughputIOPS(1000); nWritten = sprintf_s(pszExpectedOutput, sizeof(pszExpectedOutput), pcszOutputTemplate, " unit=\"IOPS\"", "1000"); VERIFY_IS_GREATER_THAN(nWritten, 0); sResults = target.GetXml(0); VERIFY_ARE_EQUAL(sResults, pszExpectedOutput); // BPMS - not specified with units in output target.SetThroughput(1000); nWritten = sprintf_s(pszExpectedOutput, sizeof(pszExpectedOutput), pcszOutputTemplate, "", "1000"); VERIFY_IS_GREATER_THAN(nWritten, 0); sResults = target.GetXml(0); VERIFY_ARE_EQUAL(sResults, pszExpectedOutput); } }