Skip to content

Commit 49a80df

Browse files
committed
Fix tests
1 parent ad42344 commit 49a80df

File tree

4 files changed

+272
-36
lines changed

4 files changed

+272
-36
lines changed

LTTngDataExtUnitTest/LTTngUnitTest.cs

Lines changed: 46 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,40 @@ public static void ProcessTrace()
4747
Assert.IsTrue(lttngDataPath.Exists);
4848

4949
// Approach #1 - Engine - Doesn't test tables UI but tests processing
50-
using (var runtime = Engine.Create(new FileDataSource(lttngDataPath.FullName)))
51-
{
50+
var runtime = Engine.Create(new FileDataSource(lttngDataPath.FullName));
5251

53-
// Enable our various types of data
54-
var lttngGenericEventDataCooker = new LTTngGenericEventDataCooker();
55-
LTTngGenericEventDataCookerPath = lttngGenericEventDataCooker.Path;
56-
runtime.EnableCooker(LTTngGenericEventDataCookerPath);
52+
// Enable our various types of data
53+
var lttngGenericEventDataCooker = new LTTngGenericEventDataCooker();
54+
LTTngGenericEventDataCookerPath = lttngGenericEventDataCooker.Path;
55+
runtime.EnableCooker(LTTngGenericEventDataCookerPath);
5756

58-
var lttngSyscallDataCooker = new LTTngSyscallDataCooker();
59-
LTTngSyscallDataCookerPath = lttngSyscallDataCooker.Path;
60-
runtime.EnableCooker(LTTngSyscallDataCookerPath);
57+
var lttngSyscallDataCooker = new LTTngSyscallDataCooker();
58+
LTTngSyscallDataCookerPath = lttngSyscallDataCooker.Path;
59+
runtime.EnableCooker(LTTngSyscallDataCookerPath);
6160

62-
var lttngThreadDataCooker = new LTTngThreadDataCooker();
63-
LTTngThreadDataCookerPath = lttngThreadDataCooker.Path;
64-
runtime.EnableCooker(LTTngThreadDataCookerPath);
61+
var lttngThreadDataCooker = new LTTngThreadDataCooker();
62+
LTTngThreadDataCookerPath = lttngThreadDataCooker.Path;
63+
runtime.EnableCooker(LTTngThreadDataCookerPath);
6564

66-
var lttngDmesgDataCooker = new LTTngDmesgDataCooker();
67-
LTTngDmesgDataCookerPath = lttngDmesgDataCooker.Path;
68-
runtime.EnableCooker(LTTngDmesgDataCookerPath);
65+
var lttngDmesgDataCooker = new LTTngDmesgDataCooker();
66+
LTTngDmesgDataCookerPath = lttngDmesgDataCooker.Path;
67+
runtime.EnableCooker(LTTngDmesgDataCookerPath);
6968

70-
var lttngModuleDataCooker = new LTTngModuleDataCooker();
71-
LTTngModuleDataCookerPath = lttngModuleDataCooker.Path;
72-
runtime.EnableCooker(LTTngModuleDataCookerPath);
69+
var lttngModuleDataCooker = new LTTngModuleDataCooker();
70+
LTTngModuleDataCookerPath = lttngModuleDataCooker.Path;
71+
runtime.EnableCooker(LTTngModuleDataCookerPath);
7372

74-
var lttngDiskDataCooker = new LTTngDiskDataCooker();
75-
LTTngDiskDataCookerPath = lttngDiskDataCooker.Path;
76-
runtime.EnableCooker(LTTngDiskDataCookerPath);
73+
var lttngDiskDataCooker = new LTTngDiskDataCooker();
74+
LTTngDiskDataCookerPath = lttngDiskDataCooker.Path;
75+
runtime.EnableCooker(LTTngDiskDataCookerPath);
7776

78-
//
79-
// Process our data.
80-
//
77+
//
78+
// Process our data.
79+
//
8180

82-
RuntimeExecutionResults = runtime.Process();
81+
RuntimeExecutionResults = runtime.Process();
8382

84-
IsTraceProcessed = true;
85-
}
83+
IsTraceProcessed = true;
8684
}
8785
}
8886
}
@@ -95,17 +93,29 @@ public void ProcessTraceAsFolder()
9593

9694
string tempDirectory = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
9795

98-
ZipFile.ExtractToDirectory(lttngData[0], tempDirectory);
99-
100-
var ds = new DirectoryDataSource(tempDirectory);
101-
// Approach #1 - Engine - Doesn't test tables UI but tests processing
102-
using (var runtime = Engine.Create(ds))
96+
using (var zipFile = ZipFile.OpenRead(lttngData[0]))
10397
{
104-
Assert.IsTrue(ds.IsDirectory());
105-
Assert.IsTrue(runtime.EnabledCookers.Where(cooker => cooker.DataCookerType == DataCookerType.SourceDataCooker).Count() >= 1);
106-
Assert.IsTrue(runtime.AvailableTables.Count() >= 1);
98+
zipFile.ExtractToDirectory(tempDirectory);
10799
}
108-
100+
101+
using (var dataSourceSet = DataSourceSet.Create())
102+
{
103+
var ds = new DirectoryDataSource(tempDirectory);
104+
dataSourceSet.AddDataSource(ds);
105+
106+
// Approach #1 - Engine - Doesn't test tables UI but tests processing
107+
using (var runtime = Engine.Create(new EngineCreateInfo(dataSourceSet.AsReadOnly())))
108+
{
109+
//
110+
// We do not assert that any cookers are enabled since we did not explicitly enable cookers here
111+
//
112+
113+
Assert.IsTrue(ds.IsDirectory());
114+
Assert.IsTrue(runtime.AvailableTables.Count() >= 1);
115+
}
116+
}
117+
118+
109119
Directory.Delete(tempDirectory, true);
110120
}
111121

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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 System.Linq;
8+
using LinuxLogParser.CloudInitLog;
9+
using Microsoft.Performance.SDK.Processing;
10+
11+
namespace CloudInitMPTAddin
12+
{
13+
//
14+
// This is a sample Custom Data Source (CDS) that understands files with the .txt extension
15+
//
16+
17+
// In order for a CDS to be recognized, it MUST satisfy the following:
18+
// a) Be a public type
19+
// b) Have a public parameterless constructor
20+
// c) Implement the IProcessingSource interface
21+
// d) Be decorated with the ProcessingSourceAttribute attribute
22+
// e) Be decorated with at least one of the derivatives of the DataSourceAttribute attribute
23+
//
24+
25+
[ProcessingSource(
26+
"{a7752cda-d80f-49f6-8022-2129ab041cd2}", // The GUID must be unique for your Custom Data Source. You can use Visual Studio's Tools -> Create Guid… tool to create a new GUID
27+
"Cloud-Init", // The Custom Data Source MUST have a name
28+
@"Linux Cloud-Init log parser")] // The Custom Data Source MUST have a description
29+
[FileDataSource(
30+
".log", // A file extension is REQUIRED
31+
"Linux Cloud-Init Cloud Provisioning Log")] // A description is OPTIONAL. The description is what appears in the file open menu to help users understand what the file type actually is.
32+
33+
//
34+
// There are two methods to creating a Custom Data Source that is recognized by the SDK:
35+
// 1. Using the helper abstract base classes
36+
// 2. Implementing the raw interfaces
37+
// This sample demonstrates method 1 where the ProcessingSource abstract class
38+
// helps provide a public parameterless constructor and implement the IProcessingSource interface
39+
//
40+
41+
public class CloudInitProcessingSource
42+
: ProcessingSource
43+
{
44+
private IApplicationEnvironment applicationEnvironment;
45+
46+
protected override void SetApplicationEnvironmentCore(IApplicationEnvironment applicationEnvironment)
47+
{
48+
//
49+
// Saves the given application environment into this instance
50+
//
51+
52+
this.applicationEnvironment = applicationEnvironment;
53+
}
54+
55+
protected override bool IsDataSourceSupportedCore(IDataSource dataSource)
56+
{
57+
return dataSource.IsFile() && StringComparer.OrdinalIgnoreCase.Equals(
58+
"cloud-init.log",
59+
Path.GetFileName(dataSource.Uri.LocalPath));
60+
}
61+
62+
protected override ICustomDataProcessor CreateProcessorCore(
63+
IEnumerable<IDataSource> dataSources,
64+
IProcessorEnvironment processorEnvironment,
65+
ProcessorOptions options)
66+
{
67+
string[] filePaths = dataSources.Select(x => x.Uri.LocalPath).ToArray();
68+
var sourceParser = new CloudInitLogParser(filePaths);
69+
70+
return new CloudInitCustomDataProcessor(
71+
sourceParser,
72+
options,
73+
this.applicationEnvironment,
74+
processorEnvironment);
75+
}
76+
}
77+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
4+
using LinuxLogParser.WaLinuxAgentLog;
5+
using Microsoft.Performance.SDK.Processing;
6+
using System;
7+
using System.Collections.Generic;
8+
using System.IO;
9+
using System.Linq;
10+
11+
namespace WaLinuxAgentMPTAddin
12+
{
13+
//
14+
// This is a sample Custom Data Source (CDS) that understands files with the .txt extension
15+
//
16+
17+
// In order for a CDS to be recognized, it MUST satisfy the following:
18+
// a) Be a public type
19+
// b) Have a public parameterless constructor
20+
// c) Implement the IProcessingSource interface
21+
// d) Be decorated with the ProcessingSourceAttribute attribute
22+
// e) Be decorated with at least one of the derivatives of the DataSourceAttribute attribute
23+
//
24+
25+
[ProcessingSource(
26+
"{a9ac39bc-2d07-4a01-b9b5-13a02611f5f2}", // The GUID must be unique for your Custom Data Source. You can use Visual Studio's Tools -> Create Guid… tool to create a new GUID
27+
"WaLinuxAgent", // The Custom Data Source MUST have a name
28+
@"WaLinuxAgent log parser")] // The Custom Data Source MUST have a description
29+
[FileDataSource(
30+
".log", // A file extension is REQUIRED
31+
"Linux WaLinuxAgent Cloud Provisioning Log")] // A description is OPTIONAL. The description is what appears in the file open menu to help users understand what the file type actually is.
32+
33+
//
34+
// There are two methods to creating a Custom Data Source that is recognized by the SDK:
35+
// 1. Using the helper abstract base classes
36+
// 2. Implementing the raw interfaces
37+
// This sample demonstrates method 1 where the ProcessingSource abstract class
38+
// helps provide a public parameterless constructor and implement the IProcessingSource interface
39+
//
40+
41+
public class WaLinuxAgentProcessingSource
42+
: ProcessingSource
43+
{
44+
protected override bool IsDataSourceSupportedCore(IDataSource dataSource)
45+
{
46+
return dataSource.IsFile() && StringComparer.OrdinalIgnoreCase.Equals("waagent.log", Path.GetFileName(dataSource.Uri.LocalPath));
47+
}
48+
49+
protected override ICustomDataProcessor CreateProcessorCore(
50+
IEnumerable<IDataSource> dataSources,
51+
IProcessorEnvironment processorEnvironment,
52+
ProcessorOptions options)
53+
{
54+
string[] filePaths = dataSources.Select(x => x.Uri.LocalPath).ToArray();
55+
var sourceParser = new WaLinuxAgentLogParser(filePaths);
56+
57+
return new WaLinuxAgentCustomDataProcessor(
58+
sourceParser,
59+
options,
60+
this.ApplicationEnvironment,
61+
processorEnvironment);
62+
}
63+
}
64+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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 System.Linq;
8+
using Microsoft.Performance.SDK.Processing;
9+
10+
namespace PerfDataProcessingSource
11+
{
12+
//
13+
// This is a sample Custom Data Source (CDS) that understands files with the .txt extension
14+
//
15+
16+
// In order for a CDS to be recognized, it MUST satisfy the following:
17+
// a) Be a public type
18+
// b) Have a public parameterless constructor
19+
// c) Implement the IProcessingSource interface
20+
// d) Be decorated with the ProcessingSourceAttribute attribute
21+
// e) Be decorated with at least one of the derivatives of the DataSourceAttribute attribute
22+
//
23+
24+
[ProcessingSource(
25+
"{EA48A279-2B4E-43A0-AC86-030113A23064}", // The GUID must be unique for your Custom Data Source. You can use Visual Studio's Tools -> Create Guid… tool to create a new GUID
26+
"Linux Perf Txt Data", // The Custom Data Source MUST have a name
27+
@"Linux perf.data.txt parser")] // The Custom Data Source MUST have a description
28+
[FileDataSource(
29+
".txt", // A file extension is REQUIRED
30+
"Linux perf.data.txt parser")] // A description is OPTIONAL. The description is what appears in the file open menu to help users understand what the file type actually is.
31+
32+
//
33+
// There are two methods to creating a Custom Data Source that is recognized by UI:
34+
// 1. Using the helper abstract base classes
35+
// 2. Implementing the raw interfaces
36+
// This sample demonstrates method 1 where the ProcessingSource abstract class
37+
// helps provide a public parameterless constructor and implement the IProcessingSource interface
38+
//
39+
40+
public class PerfDataProcessingSource
41+
: ProcessingSource
42+
{
43+
private IApplicationEnvironment applicationEnvironment;
44+
45+
public override ProcessingSourceInfo GetAboutInfo()
46+
{
47+
return new ProcessingSourceInfo()
48+
{
49+
ProjectInfo = new ProjectInfo() { Uri = "https://aka.ms/linuxperftools" },
50+
};
51+
}
52+
53+
protected override void SetApplicationEnvironmentCore(IApplicationEnvironment applicationEnvironment)
54+
{
55+
//
56+
// Saves the given application environment into this instance
57+
//
58+
59+
this.applicationEnvironment = applicationEnvironment;
60+
}
61+
62+
protected override bool IsDataSourceSupportedCore(IDataSource dataSource)
63+
{
64+
return dataSource.IsFile() && StringComparer.OrdinalIgnoreCase.Equals("perf.data.txt", Path.GetFileName(dataSource.Uri.LocalPath));
65+
}
66+
67+
protected override ICustomDataProcessor CreateProcessorCore(
68+
IEnumerable<IDataSource> dataSources,
69+
IProcessorEnvironment processorEnvironment,
70+
ProcessorOptions options)
71+
{
72+
//
73+
// Create a new instance implementing ICustomDataProcessor here to process the specified data sources.
74+
// Note that you can have more advanced logic here to create different processors if you would like based on the file, or any other criteria.
75+
// You are not restricted to always returning the same type from this method.
76+
//
77+
78+
return new PerfDataCustomDataProcessor(
79+
dataSources.Select(x => x.Uri.LocalPath).ToArray(),
80+
options,
81+
this.applicationEnvironment,
82+
processorEnvironment);
83+
}
84+
}
85+
}

0 commit comments

Comments
 (0)