private void VerifyProcessedFiles(int pass) { for (int i = 0; i < (int)TraceFileType.Count; i++) { IEnumerable <TraceFileInfo> traceFiles = this.traceFileInfo[(TraceFileType)i] .Where(t => (t.ProcessedInPass == pass)); QueryLocalTable tableQuery = null; if (traceFiles.Count() > 0) { string dirName = Path.Combine( testDataDirectory, String.Concat( traceSubFolderNames[(TraceFileType)i], this.testStartTime.Ticks.ToString())); string tableName = String.Concat( TableName, MdsEtwEventUploader.TableSchemaVersion, DefaultTableNonce); tableQuery = new QueryLocalTable(tableName, dirName); } foreach (TraceFileInfo traceFile in traceFiles) { VerifyEventsFromFile(traceFile, tableQuery, (-1 != pass)); } } }
private void VerifyTableRecordCount() { for (int i = 0; i < (int)TraceFileType.Count; i++) { IEnumerable <TraceFileInfo> traceFiles = this.traceFileInfo[(TraceFileType)i] .Where(t => (t.ProcessedInPass != -1)); int expectedEventCount = 0; foreach (TraceFileInfo traceFile in traceFiles) { expectedEventCount += traceFile.EventCount; } QueryLocalTable tableQuery = null; string dirName = Path.Combine( testDataDirectory, String.Concat( traceSubFolderNames[(TraceFileType)i], this.testStartTime.Ticks.ToString())); string tableName = String.Concat( TableName, MdsEtwEventUploader.TableSchemaVersion, DefaultTableNonce); tableQuery = new QueryLocalTable(tableName, dirName); IEnumerable <TableRecord> tableRecords = tableQuery.ReadRecords(DateTime.MinValue, DateTime.MaxValue); int eventCountInTable = tableRecords.Count(); if (eventCountInTable != expectedEventCount) { Utility.TraceSource.WriteError( TraceType, "Unexpected event count in table. Expected count: {0}, actual count: {1}", expectedEventCount, eventCountInTable); Verify.Fail("Unexpected event count in table"); } } }
private static void VerifyEvents(string logDirectory) { // Get merged lines from expected output var allLines = TestUtility.GetMergedDtrLines("fabric", expectedOutputDataFolderPath); // Calculate number of records from output dtr file List <string> allEventRecords = new List <string>(); StringBuilder strb = new StringBuilder(); foreach (var line in allLines) { var lineParts = line.Split(','); if (lineParts.Length > 0) { var dateString = lineParts[0]; DateTime result = DateTime.MinValue; if (DateTime.TryParse(dateString, out result)) { if (strb.Length > 0) { allEventRecords.Add(strb.ToString()); strb.Clear(); } strb.Append(line); } else { strb.Append(line); } } } // Write out the last record if (strb.Length > 0) { allEventRecords.Add(strb.ToString()); strb.Clear(); } // Get records from MDS table string tablePath = Path.Combine(logDirectory, "Fabric"); string tableName = String.Concat( TableName, MdsFileProducer.TableSchemaVersion, DefaultTableNonce); QueryLocalTable tableQuery = new QueryLocalTable(tableName, tablePath); var allTableRecords = tableQuery.ReadRecords(DateTime.MinValue, DateTime.MaxValue).ToArray(); Assert.AreEqual(allEventRecords.Count, allTableRecords.Count(), "Total number of records in the dtr files should be the same as in the MDS files"); // Compare records for (int i = 0; i < allEventRecords.Count; i++) { string[] eventParts = allEventRecords[i].Split(new char[] { ',' }, (int)MdsFileProducer.EtwEventParts.Count); object[] expectedTableFields = new object[(int)MdsFileProducer.MdsTableFields.Count]; expectedTableFields[(int)MdsFileProducer.MdsTableFields.Timestamp] = DateTime.Parse(eventParts[(int)MdsFileProducer.EtwEventParts.Timestamp]); expectedTableFields[(int)MdsFileProducer.MdsTableFields.Level] = eventParts[(int)MdsFileProducer.EtwEventParts.Level]; expectedTableFields[(int)MdsFileProducer.MdsTableFields.ThreadId] = Int32.Parse(eventParts[(int)MdsFileProducer.EtwEventParts.ThreadId]); expectedTableFields[(int)MdsFileProducer.MdsTableFields.ProcessId] = Int32.Parse(eventParts[(int)MdsFileProducer.EtwEventParts.ProcessId]); var winFabId = eventParts[(int)MdsFileProducer.EtwEventParts.WinFabId]; string[] winFabIdParts = winFabId.Split(new[] { '.', '@' }, (int)MdsFileProducer.WinFabIdParts.MaxCount); if (winFabIdParts.Length >= (int)MdsFileProducer.WinFabIdParts.MinCount) { expectedTableFields[(int)MdsFileProducer.MdsTableFields.TaskName] = winFabIdParts[(int)MdsFileProducer.WinFabIdParts.TaskName]; var eventType = winFabIdParts[(int)MdsFileProducer.WinFabIdParts.EventType]; string eventGroupName = EventDefinition.GetEventGroupName(eventType); if (!string.IsNullOrEmpty(eventGroupName)) { eventType = eventGroupName; } expectedTableFields[(int)MdsFileProducer.MdsTableFields.EventType] = eventType; expectedTableFields[(int)MdsFileProducer.MdsTableFields.Id] = (winFabIdParts.Length == (int)MdsFileProducer.WinFabIdParts.MinCount) ? (string.Empty) : (winFabIdParts[(int)MdsFileProducer.WinFabIdParts.Id]); } expectedTableFields[(int)MdsFileProducer.MdsTableFields.Text] = eventParts[(int)MdsFileProducer.EtwEventParts.Text]; Assert.AreEqual(1 + expectedTableFields.Length, allTableRecords[i].FieldData.Length, "Schema mismatch between dtr file and mds table record"); bool match = true; for (int j = 0; j < expectedTableFields.Length; j++) { // for text fields compare after stripping CR and tabs if (j == (int)MdsFileProducer.MdsTableFields.Text) { var expectedText = ((string)expectedTableFields[(int)MdsFileProducer.MdsTableFields.Text]).Replace("\r", "").Replace("\t", ""); var mdsText = ((string)allTableRecords[i].FieldData[j + 1]).Replace("\r", "").Replace("\t", ""); if (expectedText.Equals(mdsText) == false) { match = false; break; } } else { if (expectedTableFields[j].Equals(allTableRecords[i].FieldData[j + 1]) == false) { match = false; break; } } } Assert.IsTrue(match, "Event record values differ between the dtr file and mds table record"); } }
private void VerifyEventsFromFile(TraceFileInfo traceFile, QueryLocalTable tableQuery, bool expectProcessed) { if (traceFile.EmptyFile) { // We created a file with no events. Nothing to verify here. return; } object[] expectedTableFields = new object[(int)MdsEtwEventUploader.MdsTableFields.Count]; // Read the events from the table TableRecord[] tableRecords = tableQuery.ReadRecords(DateTime.MinValue, DateTime.MaxValue).ToArray(); // Figure out the full path to the trace file string traceFileFullPath; if (false == FabricFile.Exists(traceFile.FullName)) { // Maybe the trace file was deleted, i.e. moved to the deleted items folder string fileName = Path.GetFileName(traceFile.FullName); traceFileFullPath = Path.Combine(this.deletedItemsFolder, fileName); } else { traceFileFullPath = traceFile.FullName; } using (StreamReader reader = new StreamReader(traceFileFullPath)) { // Read event from file string eventLine = reader.ReadLine(); // For this event, get the fields that we expect to see in the table string[] eventParts = eventLine.Split(new char[] { ',', '.' }); expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Timestamp] = DateTime.Parse(eventParts[0]); expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Level] = eventParts[1]; expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.ThreadId] = Int32.Parse(eventParts[2]); expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.ProcessId] = Int32.Parse(eventParts[3]); expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.TaskName] = eventParts[4]; string eventTypeWithId = eventParts[5]; string[] eventTypeWithIdParts = eventTypeWithId.Split('@'); expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.EventType] = eventTypeWithIdParts[0]; expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Id] = (eventTypeWithIdParts.Length > 1) ? eventTypeWithIdParts[1] : String.Empty; // ReadLine method removes the '\r' at the end. Add it back. expectedTableFields[(int)MdsEtwEventUploader.MdsTableFields.Text] = String.Concat(eventParts[6], "\r"); // Search the table to see if we have a match bool matchFound = false; foreach (TableRecord tableRecord in tableRecords) { // The timestamp when the event was written to the table (NOT to be confused with // timestamp when the event occurred) also shows up as a field in the record that // we read. However, it is not a field in the record that we write. Looks like MDS // automatically adds the extra field. if ((1 + expectedTableFields.Length) != tableRecord.FieldData.Length) { Utility.TraceSource.WriteError( TraceType, "Found a record in the table whose schema does not match the expected schema. Record field tags are: {0}", String.Join(",", tableRecord.FieldTags)); Verify.Fail("Unexpected schema for table record"); } bool currentRecordMatchesEvent = true; for (int i = 0; i < expectedTableFields.Length; i++) { if (false == expectedTableFields[i].Equals(tableRecord.FieldData[i + 1])) { currentRecordMatchesEvent = false; break; } } if (currentRecordMatchesEvent) { matchFound = true; break; } } if (expectProcessed != matchFound) { Utility.TraceSource.WriteError( TraceType, "{0} Event info: {1}", expectProcessed ? "An event that we expected to find in the table was not found." : "Event unexpectedly found in table.", eventLine); Verify.Fail("Unexpected event processing status"); } } }