|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.IO; |
| 7 | +using LttngCds; |
| 8 | +using LttngDataExtensions.SourceDataCookers; |
| 9 | +using LttngDataExtensions.DataOutputTypes; |
| 10 | +using LttngDataExtensions.SourceDataCookers.Syscall; |
| 11 | +using LttngDataExtensions.SourceDataCookers.Thread; |
| 12 | +using Microsoft.Performance.SDK.Extensibility; |
| 13 | +using Microsoft.Performance.SDK.Processing; |
| 14 | +using Microsoft.Performance.Toolkit.Engine; |
| 15 | +using Microsoft.VisualStudio.TestTools.UnitTesting; |
| 16 | +using Moq; |
| 17 | +using UnitTestCommon; |
| 18 | +using LttngDataExtensions.SourceDataCookers.Diagnostic_Messages; |
| 19 | +using Microsoft.Performance.SDK; |
| 20 | +using LttngDataExtensions.SourceDataCookers.Module; |
| 21 | +using LttngDataExtensions.SourceDataCookers.Disk; |
| 22 | + |
| 23 | +namespace LTTngDataExtUnitTest |
| 24 | +{ |
| 25 | + [TestClass] |
| 26 | + public class LTTngUnitTest |
| 27 | + { |
| 28 | + public static bool IsTraceProcessed = false; |
| 29 | + public static object IsTraceProcessedLock = new object(); |
| 30 | + |
| 31 | + private static RuntimeExecutionResults RuntimeExecutionResults; |
| 32 | + |
| 33 | + private static DataCookerPath LTTngGenericEventDataCookerPath; |
| 34 | + private static DataCookerPath LTTngSyscallDataCookerPath; |
| 35 | + private static DataCookerPath LTTngThreadDataCookerPath; |
| 36 | + private static DataCookerPath LttngDmesgDataCookerPath; |
| 37 | + private static DataCookerPath LttngModuleDataCookerPath; |
| 38 | + private static DataCookerPath LttngDiskDataCookerPath; |
| 39 | + |
| 40 | + public static void ProcessTrace() |
| 41 | + { |
| 42 | + lock (IsTraceProcessedLock) |
| 43 | + { |
| 44 | + if (!IsTraceProcessed) |
| 45 | + { |
| 46 | + // Input data |
| 47 | + string[] lttngData = { @"..\..\..\..\TestData\LTTng\lttng-kernel-trace.ctf" }; |
| 48 | + var lttngDataPath = new FileInfo(lttngData[0]); |
| 49 | + Assert.IsTrue(lttngDataPath.Exists); |
| 50 | + |
| 51 | + // Approach #1 - Engine - Doesn't test tables UI but tests processing |
| 52 | + var runtime = Engine.Create(); |
| 53 | + |
| 54 | + runtime.AddFile(lttngDataPath.FullName); |
| 55 | + |
| 56 | + // Enable our various types of data |
| 57 | + var lttngGenericEventDataCooker = new LttngGenericEventDataCooker(); |
| 58 | + LTTngGenericEventDataCookerPath = lttngGenericEventDataCooker.Path; |
| 59 | + runtime.EnableCooker(LTTngGenericEventDataCookerPath); |
| 60 | + |
| 61 | + var lttngSyscallDataCooker = new LttngSyscallDataCooker(); |
| 62 | + LTTngSyscallDataCookerPath = lttngSyscallDataCooker.Path; |
| 63 | + runtime.EnableCooker(LTTngSyscallDataCookerPath); |
| 64 | + |
| 65 | + var lttngThreadDataCooker = new LttngThreadDataCooker(); |
| 66 | + LTTngThreadDataCookerPath = lttngThreadDataCooker.Path; |
| 67 | + runtime.EnableCooker(LTTngThreadDataCookerPath); |
| 68 | + |
| 69 | + var lttngDmesgDataCooker = new LttngDmesgDataCooker(); |
| 70 | + LttngDmesgDataCookerPath = lttngDmesgDataCooker.Path; |
| 71 | + runtime.EnableCooker(LttngDmesgDataCookerPath); |
| 72 | + |
| 73 | + var lttngModuleDataCooker = new LttngModuleDataCooker(); |
| 74 | + LttngModuleDataCookerPath = lttngModuleDataCooker.Path; |
| 75 | + runtime.EnableCooker(LttngModuleDataCookerPath); |
| 76 | + |
| 77 | + var lttngDiskDataCooker = new LttngDiskDataCooker(); |
| 78 | + LttngDiskDataCookerPath = lttngDiskDataCooker.Path; |
| 79 | + runtime.EnableCooker(LttngDiskDataCookerPath); |
| 80 | + |
| 81 | + // |
| 82 | + // Process our data. |
| 83 | + // |
| 84 | + |
| 85 | + RuntimeExecutionResults = runtime.Process(); |
| 86 | + |
| 87 | + IsTraceProcessed = true; |
| 88 | + } |
| 89 | + } |
| 90 | + } |
| 91 | + |
| 92 | + [TestMethod] |
| 93 | + public void DiagnosticMessageTable() |
| 94 | + { |
| 95 | + ProcessTrace(); |
| 96 | + |
| 97 | + var eventData = RuntimeExecutionResults.QueryOutput<IReadOnlyList<IDiagnosticMessage>>( |
| 98 | + new DataOutputPath( |
| 99 | + LttngDmesgDataCookerPath, |
| 100 | + nameof(LttngDmesgDataCooker.DiagnosticMessages))); |
| 101 | + |
| 102 | + Assert.IsTrue(eventData.Count == 0); // TODO - UT - Trace has no DiagMessages |
| 103 | + } |
| 104 | + |
| 105 | + [TestMethod] |
| 106 | + public void DiskTable() |
| 107 | + { |
| 108 | + ProcessTrace(); |
| 109 | + |
| 110 | + var eventData = RuntimeExecutionResults.QueryOutput<IReadOnlyList<DiskActivity>>( |
| 111 | + new DataOutputPath( |
| 112 | + LttngDiskDataCookerPath, |
| 113 | + nameof(LttngDiskDataCooker.DiskActivity))); |
| 114 | + |
| 115 | + Assert.IsTrue(eventData.Count > 0); |
| 116 | + } |
| 117 | + |
| 118 | + [TestMethod] |
| 119 | + public void ExecutionEventTable() |
| 120 | + { |
| 121 | + ProcessTrace(); |
| 122 | + |
| 123 | + var eventData = RuntimeExecutionResults.QueryOutput<IReadOnlyList<IExecutionEvent>>( |
| 124 | + new DataOutputPath( |
| 125 | + LTTngThreadDataCookerPath, |
| 126 | + nameof(LttngThreadDataCooker.ExecutionEvents))); |
| 127 | + |
| 128 | + Assert.IsTrue(eventData.Count > 0); |
| 129 | + } |
| 130 | + |
| 131 | + [TestMethod] |
| 132 | + public void FileEventsTable() |
| 133 | + { |
| 134 | + ProcessTrace(); |
| 135 | + |
| 136 | + var eventData = RuntimeExecutionResults.QueryOutput<IReadOnlyList<FileEvent>>( |
| 137 | + new DataOutputPath( |
| 138 | + LttngDiskDataCookerPath, |
| 139 | + nameof(LttngDiskDataCooker.FileEvents))); |
| 140 | + |
| 141 | + Assert.IsTrue(eventData.Count > 0); |
| 142 | + } |
| 143 | + |
| 144 | + [TestMethod] |
| 145 | + public void GenericEventsTable() |
| 146 | + { |
| 147 | + ProcessTrace(); |
| 148 | + |
| 149 | + var eventData = RuntimeExecutionResults.QueryOutput<ProcessedEventData<LttngGenericEvent>>( |
| 150 | + new DataOutputPath( |
| 151 | + LTTngGenericEventDataCookerPath, |
| 152 | + nameof(LttngGenericEventDataCooker.Events))); |
| 153 | + |
| 154 | + Assert.IsTrue(eventData.Count > 0); |
| 155 | + } |
| 156 | + |
| 157 | + [TestMethod] |
| 158 | + public void ModuleEventsTable() |
| 159 | + { |
| 160 | + ProcessTrace(); |
| 161 | + |
| 162 | + var eventData = RuntimeExecutionResults.QueryOutput<IReadOnlyList<ModuleEvent>>( |
| 163 | + new DataOutputPath( |
| 164 | + LttngModuleDataCookerPath, |
| 165 | + nameof(LttngModuleDataCooker.ModuleEvents))); |
| 166 | + |
| 167 | + Assert.IsTrue(eventData.Count == 0); // TODO - UT - Trace has no ModuleEvents |
| 168 | + } |
| 169 | + |
| 170 | + [TestMethod] |
| 171 | + public void SyscallTable() |
| 172 | + { |
| 173 | + ProcessTrace(); |
| 174 | + |
| 175 | + var eventData = RuntimeExecutionResults.QueryOutput<List<ISyscall>>( |
| 176 | + new DataOutputPath( |
| 177 | + LTTngSyscallDataCookerPath, |
| 178 | + nameof(LttngSyscallDataCooker.Syscalls))); |
| 179 | + |
| 180 | + Assert.IsTrue(eventData.Count > 0); |
| 181 | + } |
| 182 | + |
| 183 | + [TestMethod] |
| 184 | + public void ThreadTable() |
| 185 | + { |
| 186 | + ProcessTrace(); |
| 187 | + |
| 188 | + var threads = RuntimeExecutionResults.QueryOutput<IReadOnlyList<IThread>>( |
| 189 | + new DataOutputPath( |
| 190 | + LTTngThreadDataCookerPath, |
| 191 | + nameof(LttngThreadDataCooker.Threads))); |
| 192 | + |
| 193 | + Assert.IsTrue(threads.Count > 0); |
| 194 | + } |
| 195 | + } |
| 196 | +} |
0 commit comments