-
Notifications
You must be signed in to change notification settings - Fork 34
/
LinuxLogParsersUnitTest.cs
181 lines (148 loc) · 9.47 KB
/
LinuxLogParsersUnitTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
using System;
using System.IO;
using System.Linq;
using AndroidLogcatMPTAddin;
using CloudInitMPTAddin;
using DmesgIsoMPTAddin;
using Microsoft.Performance.SDK;
using Microsoft.Performance.SDK.Extensibility;
using Microsoft.Performance.SDK.Processing;
using Microsoft.Performance.Toolkit.Engine;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using WaLinuxAgentMPTAddin;
namespace LinuxLogParsersUnitTest
{
[TestClass]
public class LinuxLogParsersUnitTest
{
[TestMethod]
public void Dmesg()
{
// Input data
string[] dmesgData = { @"..\..\..\..\..\TestData\LinuxLogs\Dmesg\dmesg.iso.log" };
var dmesgDataPath = new FileInfo(dmesgData[0]);
Assert.IsTrue(dmesgDataPath.Exists);
using var runtime = Engine.Create(new FileDataSource(dmesgDataPath.FullName));
var cooker = new DmesgIsoDataCooker().Path;
runtime.EnableCooker(cooker);
var runtimeExecutionResults = runtime.Process();
var eventData = runtimeExecutionResults.QueryOutput<DmesgIsoLogParsedResult>(
new DataOutputPath(
cooker,
nameof(DmesgIsoDataCooker.ParsedResult)));
Assert.IsTrue(eventData.LogEntries.Count == 1867);
}
[TestMethod]
public void AndroidLogcat()
{
// Some other examples focusing on RegEx
var trickySamples = new string[]
{
"12-13 10:32:21.278 0 0 I : Linux version 5.10.43-2-windows-subsystem-for-android (oe-user@oe-host) (clang version 10.0.1 (https://github.com/llvm/llvm-project ef32c611aa214dea855364efd7ba451ec5ec3f74), GNU ld (GNU Binutils) 2.34.0.20200220) #1 SMP PREEMPT Tue Sep 14 09:09:25 UTC 2021",
@"12-13 10:32:21.278 0 0 I Command line: initrd=\initrd.img panic=-1 nr_cpus=8 earlycon=uart8250,io,0x3f8,115200 console=hvc0 debug pty.legacy_count=0 androidboot.hardware=windows_x86_64 panic=-1 pty.legacy_count=0 androidboot.veritymode=enforcing androidboot.verifiedbootstate=green loglevel=6 transparent_hugepage=never swiotlb=noforce androidboot.hardware.egl=emulation androidboot.hardware.gralloc=emulation",
"12-13 10:32:21.278 0 0 I x86/fpu : Supporting XSAVE feature 0x001: 'x87 floating point registers'",
"12-13 10:32:25.709 86 86 E APM::AudioPolicyEngine/Config: parseLegacyVolumeFile: Could not parse document /odm/etc/audio_policy_configuration.xml",
"12-13 10:32:21.278 0 0 I BIOS-e820: [mem 0x0000000000000000-0x000000000009ffff] usable",
"12-13 10:32:21.317 0 0 I IOAPIC[0]: apic_id 8, version 17, address 0xfec00000, GSI 0-23",
"12-13 10:32:21.328 0 0 I : Built 1 zonelists, mobility grouping on. Total pages: 1547406"
};
foreach (var s in trickySamples)
{
var m = LinuxLogParser.AndroidLogcat.AndroidLogcatLogParser.AndroidLogCatRegex.Match(s);
if (!m.Success)
{
Console.WriteLine(s);
}
Assert.IsTrue(m.Success);
}
// Input data from log
string[] androidlogcatData = { @"..\..\..\..\..\TestData\AndroidLogs\Logcat\AndroidLogcatWSA.log" };
var androidlogcatDataPath = new FileInfo(androidlogcatData[0]);
Assert.IsTrue(androidlogcatDataPath.Exists);
using var runtime = Engine.Create(new FileDataSource(androidlogcatDataPath.FullName));
var cooker = new AndroidLogcatDataCooker().Path;
runtime.EnableCooker(cooker);
var runtimeExecutionResults = runtime.Process();
var eventData = runtimeExecutionResults.QueryOutput<AndroidLogcatParsedResult>(
new DataOutputPath(
cooker,
nameof(AndroidLogcatDataCooker.ParsedResult)));
Assert.IsTrue(eventData.LogEntries.Count > 0);
Assert.IsTrue(eventData.LogEntries.Count == 6061);
var noTimestampOrNotParsed = eventData.LogEntries.Where(f => f.Timestamp.ToNanoseconds < 0);
Assert.IsTrue(noTimestampOrNotParsed.Count() == 5); // There is 5 entries with no timestamp e.g "--------- beginning of "
//eventData.LogEntries[1].Timestamp == // Check abs time if/when SDK supports it
Assert.IsTrue(eventData.LogEntries[1].LineNumber == 3);
Assert.IsTrue(eventData.LogEntries[1].Timestamp == Timestamp.Zero);
Assert.IsTrue(eventData.LogEntries[1].PID == 20);
Assert.IsTrue(eventData.LogEntries[1].TID == 20);
Assert.IsTrue(eventData.LogEntries[1].Priority == "I");
Assert.IsTrue(eventData.LogEntries[1].Tag == "auditd");
Assert.IsTrue(eventData.LogEntries[1].Message == "type=2000 audit(0.0:1): state=initialized audit_enabled=0 res=1");
//eventData.LogEntries[6].Timestamp == // Check abs time if/when SDK supports it
Assert.IsTrue(eventData.LogEntries[6].LineNumber == 13);
Assert.IsTrue(eventData.LogEntries[6].Timestamp == new Timestamp(1248000000)); // 1,248,000,000 ns past 1st event
Assert.IsTrue(eventData.LogEntries[6].PID == 0);
Assert.IsTrue(eventData.LogEntries[6].TID == 0);
Assert.IsTrue(eventData.LogEntries[6].Priority == "I");
Assert.IsTrue(eventData.LogEntries[6].Tag == "Command line");
Assert.IsTrue(!String.IsNullOrWhiteSpace(eventData.LogEntries[6].Message));
Assert.IsTrue(eventData.DurationLogEntries.Count > 0);
// Service 'exec 1 (/system/bin/linkerconfig --target /linkerconfig/bootstrap)' (pid 4) exited with status 0 waiting took 0.015000 seconds
Assert.IsTrue(eventData.DurationLogEntries[0].Name == "exec 1 (/system/bin/linkerconfig --target /linkerconfig/bootstrap)");
Assert.IsTrue(eventData.DurationLogEntries[0].Duration.ToMilliseconds == 15);
// Service 'apexd-bootstrap' (pid 6) exited with status 0 waiting took 0.053000 seconds
Assert.IsTrue(eventData.DurationLogEntries[1].Name == "apexd-bootstrap");
Assert.IsTrue(eventData.DurationLogEntries[1].Duration.ToMilliseconds == 53);
Assert.IsTrue((eventData.DurationLogEntries[1].EndTimestamp - eventData.DurationLogEntries[1].StartTimestamp).ToMilliseconds == 53);
Assert.IsTrue(eventData.DurationLogEntries.Count == 1039);
// MakeWindowManagerServiceReady took to complete: 3ms
// eventData.DurationLogEntries.IndexOf(eventData.DurationLogEntries.Single(f => f.Name == "MakeWindowManagerServiceReady"))
Assert.IsTrue(eventData.DurationLogEntries[468].Name == "MakeWindowManagerServiceReady");
Assert.IsTrue(eventData.DurationLogEntries[468].Duration.ToMilliseconds == 3);
Assert.IsTrue((eventData.DurationLogEntries[468].EndTimestamp - eventData.DurationLogEntries[468].StartTimestamp).ToMilliseconds == 3);
// Looper : Slow delivery took 2033ms main h=android.app.ActivityThread$H c=null m=156
Assert.IsTrue(eventData.DurationLogEntries[934].Name == "main h=android.app.ActivityThread$H");
Assert.IsTrue(eventData.DurationLogEntries[934].Duration.ToMilliseconds == 2033);
// Kernel Boot
Assert.IsTrue(eventData.DurationLogEntries[^1].Name == "Kernel Boot");
Assert.IsTrue(eventData.DurationLogEntries[^1].Duration.ToMilliseconds == 1906);
}
[TestMethod]
public void CloudInit()
{
// Input data
string[] cloudInitData = { @"..\..\..\..\..\TestData\LinuxLogs\Cloud-Init\cloud-init.log" };
var cloutInitDataPath = new FileInfo(cloudInitData[0]);
Assert.IsTrue(cloutInitDataPath.Exists);
using var runtime = Engine.Create(new FileDataSource(cloutInitDataPath.FullName));
var cooker = new CloudInitDataCooker().Path;
runtime.EnableCooker(cooker);
var runtimeExecutionResults = runtime.Process();
var eventData = runtimeExecutionResults.QueryOutput<CloudInitLogParsedResult>(
new DataOutputPath(
cooker,
nameof(CloudInitDataCooker.ParsedResult)));
Assert.IsTrue(eventData.LogEntries.Count == 937);
}
[TestMethod]
public void WaLinuxAgent()
{
// Input data
string[] waLinuxAgentData = { @"..\..\..\..\..\TestData\LinuxLogs\WaLinuxAgent\waagent.log" };
var waLinuxAgentDataPath = new FileInfo(waLinuxAgentData[0]);
Assert.IsTrue(waLinuxAgentDataPath.Exists);
using var runtime = Engine.Create(new FileDataSource(waLinuxAgentDataPath.FullName));
var cooker = new WaLinuxAgentDataCooker().Path;
runtime.EnableCooker(cooker);
var runtimeExecutionResults = runtime.Process();
var eventData = runtimeExecutionResults.QueryOutput<WaLinuxAgentLogParsedResult>(
new DataOutputPath(
cooker,
nameof(WaLinuxAgentDataCooker.ParsedResult)));
Assert.IsTrue(eventData.LogEntries.Count == 773); // Should be 795 - bug?
}
}
}