Skip to content

Commit 0bcf485

Browse files
authored
Add Unit Tests for LTTng, Perf, and LinuxLogParsers (#3)
* Add Unit Tests for LTTng, Perf, and LinuxLogParsers
1 parent 530e54e commit 0bcf485

File tree

24 files changed

+5036
-10
lines changed

24 files changed

+5036
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ StyleCopReport.xml
8585
*.tmp
8686
*.tmp_proj
8787
*_wpftmp.csproj
88-
*.log
88+
#*.log
8989
*.vspscc
9090
*.vssscc
9191
.builds

CtfUnitTest/CtfUnitTest.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.3.0" />
11-
<PackageReference Include="MSTest.TestAdapter" Version="1.4.0" />
12-
<PackageReference Include="MSTest.TestFramework" Version="1.4.0" />
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
11+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
12+
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
1313
</ItemGroup>
1414

1515
<ItemGroup>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
11+
<PackageReference Include="Microsoft.Performance.SDK" Version="0.108.2" />
12+
<PackageReference Include="Microsoft.Performance.SDK.Runtime" Version="0.108.2" />
13+
<PackageReference Include="Microsoft.Performance.Toolkit.Engine" Version="0.108.2" />
14+
<PackageReference Include="Moq" Version="4.15.2" />
15+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
16+
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
17+
<PackageReference Include="coverlet.collector" Version="1.3.0" />
18+
</ItemGroup>
19+
20+
<ItemGroup>
21+
<ProjectReference Include="..\LttngDataExtensions\LTTngDataExtensions.csproj" />
22+
<ProjectReference Include="..\UnitTestCommon\UnitTestCommon.csproj" />
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
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+
}
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using CloudInitMPTAddin;
5+
using DmesgIsoMPTAddin;
6+
using Microsoft.Performance.SDK.Extensibility;
7+
using Microsoft.Performance.Toolkit.Engine;
8+
using Microsoft.VisualStudio.TestTools.UnitTesting;
9+
using Moq;
10+
using System;
11+
using System.Collections;
12+
using System.Collections.Generic;
13+
using System.IO;
14+
using System.Linq;
15+
using System.Threading;
16+
using UnitTestCommon;
17+
using WaLinuxAgentMPTAddin;
18+
19+
namespace LinuxLogParsersUnitTest
20+
{
21+
[TestClass]
22+
public class LinuxLogParsersUnitTest
23+
{
24+
[TestMethod]
25+
public void Dmesg()
26+
{
27+
// Input data
28+
string[] dmesgData = { @"..\..\..\..\..\TestData\LinuxLogs\Dmesg\dmesg.iso.log" };
29+
var dmesgDataPath = new FileInfo(dmesgData[0]);
30+
Assert.IsTrue(dmesgDataPath.Exists);
31+
32+
var runtime = Engine.Create();
33+
runtime.AddFile(dmesgDataPath.FullName);
34+
35+
var cooker = new DmesgIsoDataCooker().Path;
36+
runtime.EnableCooker(cooker);
37+
38+
var runtimeExecutionResults = runtime.Process();
39+
40+
var eventData = runtimeExecutionResults.QueryOutput<DmesgIsoLogParsedResult>(
41+
new DataOutputPath(
42+
cooker,
43+
nameof(DmesgIsoDataCooker.ParsedResult)));
44+
45+
Assert.IsTrue(eventData.LogEntries.Count >= 0);
46+
}
47+
48+
[TestMethod]
49+
public void CloudInit()
50+
{
51+
// Input data
52+
string[] cloudInitData = { @"..\..\..\..\..\TestData\LinuxLogs\Cloud-Init\cloud-init.log" };
53+
var cloutInitDataPath = new FileInfo(cloudInitData[0]);
54+
Assert.IsTrue(cloutInitDataPath.Exists);
55+
56+
var runtime = Engine.Create();
57+
runtime.AddFile(cloutInitDataPath.FullName);
58+
59+
var cooker = new CloudInitDataCooker().Path;
60+
runtime.EnableCooker(cooker);
61+
62+
var runtimeExecutionResults = runtime.Process();
63+
64+
var eventData = runtimeExecutionResults.QueryOutput<CloudInitLogParsedResult>(
65+
new DataOutputPath(
66+
cooker,
67+
nameof(CloudInitDataCooker.ParsedResult)));
68+
69+
Assert.IsTrue(eventData.LogEntries.Count >= 0);
70+
}
71+
72+
[TestMethod]
73+
public void WaLinuxAgent()
74+
{
75+
// Input data
76+
string[] waLinuxAgentData = { @"..\..\..\..\..\TestData\LinuxLogs\WaLinuxAgent\waagent.log" };
77+
var waLinuxAgentDataPath = new FileInfo(waLinuxAgentData[0]);
78+
Assert.IsTrue(waLinuxAgentDataPath.Exists);
79+
80+
var runtime = Engine.Create();
81+
runtime.AddFile(waLinuxAgentDataPath.FullName);
82+
83+
var cooker = new WaLinuxAgentDataCooker().Path;
84+
runtime.EnableCooker(cooker);
85+
86+
var runtimeExecutionResults = runtime.Process();
87+
88+
var eventData = runtimeExecutionResults.QueryOutput<WaLinuxAgentLogParsedResult>(
89+
new DataOutputPath(
90+
cooker,
91+
nameof(WaLinuxAgentDataCooker.ParsedResult)));
92+
93+
Assert.IsTrue(eventData.LogEntries.Count >= 0);
94+
}
95+
}
96+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
6+
<IsPackable>false</IsPackable>
7+
</PropertyGroup>
8+
9+
<ItemGroup>
10+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.8.3" />
11+
<PackageReference Include="Microsoft.Performance.SDK" Version="0.108.2" />
12+
<PackageReference Include="Microsoft.Performance.Toolkit.Engine" Version="0.108.2" />
13+
<PackageReference Include="Moq" Version="4.15.2" />
14+
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
15+
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
16+
<PackageReference Include="coverlet.collector" Version="1.3.0" />
17+
</ItemGroup>
18+
19+
<ItemGroup>
20+
<ProjectReference Include="..\..\UnitTestCommon\UnitTestCommon.csproj" />
21+
<ProjectReference Include="..\LinuxPlugins-MicrosoftPerformanceToolkSDK\Cloud-init\Cloud-Init.csproj" />
22+
<ProjectReference Include="..\LinuxPlugins-MicrosoftPerformanceToolkSDK\DmesgIsoLog\Dmesg.csproj" />
23+
<ProjectReference Include="..\LinuxPlugins-MicrosoftPerformanceToolkSDK\WaLinuxAgent\WaLinuxAgent.csproj" />
24+
</ItemGroup>
25+
26+
</Project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"profiles": {
3+
"LTTngDataExtensions": {
4+
"commandName": "Executable",
5+
"executablePath": "C:\\Tools\\WPT\\latest\\wpa.exe",
6+
"commandLineArgs": "-addsearchdir C:\\src\\Microsoft-Performance-Tools-Linux\\LttngDataExtensions\\bin\\Debug\\netstandard2.1"
7+
}
8+
}
9+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"profiles": {
3+
"LttngDriver": {
4+
"commandName": "Project",
5+
"commandLineArgs": "-e C:\\src\\Microsoft-Performance-Tools-Linux\\LttngDataExtensions\\bin\\Debug\\netstandard2.1 C:\\src\\Microsoft-Performance-Tools-Linux\\TestData\\LTTng\\lttng-kernel-trace.ctf"
6+
}
7+
}
8+
}

0 commit comments

Comments
 (0)