mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-11 05:52:19 +02:00
[Fuzz] Add Fuzz testing for FancyZones (#38165)
* Add FancyZones.FuzzTests Module for fuzzing grid from json element * remove unuse test cs * fix spell error * remove specific modify in job-fuzz.yml * add Testably.Abstractions.FileSystem.Interface.dll * fix spell error * add dependency dll * add annotations * fix pipeline error need to import 'Common.Dotnet.CsWinRT.props'
This commit is contained in:
@@ -706,6 +706,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RegistryPreview.FuzzTests",
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.System", "src\modules\cmdpal\ext\Microsoft.CmdPal.Ext.System\Microsoft.CmdPal.Ext.System.csproj", "{64B88F02-CD88-4ED8-9624-989A800230F9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.CmdPal.Ext.System", "src\modules\cmdpal\ext\Microsoft.CmdPal.Ext.System\Microsoft.CmdPal.Ext.System.csproj", "{64B88F02-CD88-4ED8-9624-989A800230F9}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FancyZones.FuzzTests", "src\modules\fancyzones\FancyZones.FuzzTests\FancyZones.FuzzTests.csproj", "{0217E86E-3476-9946-DE8E-9D200CEBD47A}"
|
||||||
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CmdPalKeyboardService", "src\modules\cmdpal\CmdPalKeyboardService\CmdPalKeyboardService.vcxproj", "{5F63C743-F6CE-4DBA-A200-2B3F8A14E8C2}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CmdPalKeyboardService", "src\modules\cmdpal\CmdPalKeyboardService\CmdPalKeyboardService.vcxproj", "{5F63C743-F6CE-4DBA-A200-2B3F8A14E8C2}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRename.FuzzingTest", "src\modules\powerrename\PowerRename.FuzzingTest\PowerRename.FuzzingTest.vcxproj", "{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}"
|
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PowerRename.FuzzingTest", "src\modules\powerrename\PowerRename.FuzzingTest\PowerRename.FuzzingTest.vcxproj", "{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}"
|
||||||
@@ -2596,6 +2598,14 @@ Global
|
|||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|ARM64.ActiveCfg = Release|ARM64
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.ActiveCfg = Release|x64
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.ActiveCfg = Release|x64
|
||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.Build.0 = Release|x64
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E}.Release|x64.Build.0 = Release|x64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|ARM64.ActiveCfg = Debug|ARM64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|ARM64.Build.0 = Debug|ARM64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|x64.ActiveCfg = Debug|x64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Debug|x64.Build.0 = Debug|x64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|ARM64.ActiveCfg = Release|ARM64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|ARM64.Build.0 = Release|ARM64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|x64.ActiveCfg = Release|x64
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A}.Release|x64.Build.0 = Release|x64
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
@@ -2866,6 +2876,7 @@ Global
|
|||||||
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}
|
{4E0AE3A4-2EE0-44D7-A2D0-8769977254A0} = {F05E590D-AD46-42BE-9C25-6A63ADD2E3EA}
|
||||||
{5702B3CC-8575-48D5-83D8-15BB42269CD3} = {929C1324-22E8-4412-A9A8-80E85F3985A5}
|
{5702B3CC-8575-48D5-83D8-15BB42269CD3} = {929C1324-22E8-4412-A9A8-80E85F3985A5}
|
||||||
{64B88F02-CD88-4ED8-9624-989A800230F9} = {ECB8E0D1-7603-4E5C-AB10-D1E545E6F8E2}
|
{64B88F02-CD88-4ED8-9624-989A800230F9} = {ECB8E0D1-7603-4E5C-AB10-D1E545E6F8E2}
|
||||||
|
{0217E86E-3476-9946-DE8E-9D200CEBD47A} = {D1D6BC88-09AE-4FB4-AD24-5DED46A791DD}
|
||||||
{5F63C743-F6CE-4DBA-A200-2B3F8A14E8C2} = {3846508C-77EB-4034-A702-F8BB263C4F79}
|
{5F63C743-F6CE-4DBA-A200-2B3F8A14E8C2} = {3846508C-77EB-4034-A702-F8BB263C4F79}
|
||||||
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
|
{2694E2FB-DCD5-4BFF-A418-B6C3C7CE3B8E} = {89E20BCE-EB9C-46C8-8B50-E01A82E6FDC3}
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
<!-- Look at Directory.Build.props in root for common stuff as well -->
|
||||||
|
<Import Project="..\..\..\Common.Dotnet.CsWinRT.props" />
|
||||||
|
<Import Project="..\..\..\Common.Dotnet.FuzzTest.props" />
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputPath>..\..\..\..\$(Platform)\$(Configuration)\tests\FancyZones.FuzzTests\</OutputPath>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Compile Include="..\editor\FancyZonesEditor\Utils\ParsingResult.cs" Link="ParsingResult.cs" />
|
||||||
|
<Compile Include="..\FancyZonesEditorCommon\Data\CustomLayouts.cs" Link="CustomLayouts.cs" />
|
||||||
|
<Compile Include="..\FancyZonesEditorCommon\Data\EditorData`1.cs" Link="EditorData`1.cs" />
|
||||||
|
<Compile Include="..\FancyZonesEditorCommon\Data\LayoutDefaultSettings.cs" Link="LayoutDefaultSettings.cs" />
|
||||||
|
<Compile Include="..\FancyZonesEditorCommon\Utils\DashCaseNamingPolicy.cs" Link="DashCaseNamingPolicy.cs" />
|
||||||
|
<Compile Include="..\FancyZonesEditorCommon\Utils\IOUtils.cs" Link="IOUtils.cs" />
|
||||||
|
<Compile Include="..\FancyZonesEditorCommon\Utils\StringUtils.cs" Link="StringUtils.cs" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="MSTest" />
|
||||||
|
<PackageReference Include="System.IO.Abstractions" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Using Include="Microsoft.VisualStudio.TestTools.UnitTesting" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="OneFuzzConfig.json">
|
||||||
|
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
86
src/modules/fancyzones/FancyZones.FuzzTests/FuzzTests.cs
Normal file
86
src/modules/fancyzones/FancyZones.FuzzTests/FuzzTests.cs
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text.Json;
|
||||||
|
using FancyZonesEditorCommon.Data;
|
||||||
|
using FancyZonesEditorCommon.Utils;
|
||||||
|
using static FancyZonesEditorCommon.Data.CustomLayouts;
|
||||||
|
|
||||||
|
namespace FancyZones.FuzzTests
|
||||||
|
{
|
||||||
|
public class FuzzTests
|
||||||
|
{
|
||||||
|
public static void FuzzGridFromJsonElement(ReadOnlySpan<byte> input)
|
||||||
|
{
|
||||||
|
if (input.Length < 4)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
int inputData = BitConverter.ToInt32(input.Slice(0, 4));
|
||||||
|
|
||||||
|
// mock user input for custom-layouts.json
|
||||||
|
string mockCustomLayouts = $@"{{""custom-layouts"": [{{
|
||||||
|
""uuid"": ""{{B8C275E-A7BC-485F-A35C-67B69164F51F}}"",
|
||||||
|
""name"": ""Custom layout 1"",
|
||||||
|
""type"": ""grid"",
|
||||||
|
""info"": {{
|
||||||
|
""rows"": {inputData},
|
||||||
|
""columns"": {inputData},
|
||||||
|
""rows-percentage"": [ {inputData} ],
|
||||||
|
""columns-percentage"": [ {inputData}, {inputData}, {inputData} ],
|
||||||
|
""cell-child-map"": [ [{inputData}, {inputData}, {inputData}] ],
|
||||||
|
""show-spacing"": true,
|
||||||
|
""spacing"": {inputData},
|
||||||
|
""sensitivity-radius"": {inputData}
|
||||||
|
}}
|
||||||
|
}}]}}";
|
||||||
|
|
||||||
|
CustomLayoutListWrapper wrapper;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
wrapper = JsonSerializer.Deserialize<CustomLayoutListWrapper>(mockCustomLayouts, JsonOptions);
|
||||||
|
}
|
||||||
|
catch (JsonException)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
List<CustomLayouts.CustomLayoutWrapper> customLayouts = wrapper.CustomLayouts;
|
||||||
|
|
||||||
|
if (customLayouts == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get Layout Info from mockCustomLayouts
|
||||||
|
foreach (var zoneSet in customLayouts)
|
||||||
|
{
|
||||||
|
if (zoneSet.Uuid == null || zoneSet.Uuid.Length == 0)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
CustomLayouts deserializer = new CustomLayouts();
|
||||||
|
|
||||||
|
// Fuzzing the deserializer
|
||||||
|
_ = deserializer.GridFromJsonElement(zoneSet.Info.GetRawText());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static JsonSerializerOptions JsonOptions
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return new JsonSerializerOptions
|
||||||
|
{
|
||||||
|
PropertyNamingPolicy = new DashCaseNamingPolicy(),
|
||||||
|
WriteIndented = true,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation
|
||||||
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
||||||
|
// See the LICENSE file in the project root for more information.
|
||||||
|
|
||||||
|
[assembly: Parallelize(Scope = ExecutionScope.MethodLevel)]
|
||||||
@@ -0,0 +1,51 @@
|
|||||||
|
{
|
||||||
|
"configVersion": 3,
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"fuzzer": {
|
||||||
|
"$type": "libfuzzerDotNet",
|
||||||
|
"dll": "FancyZones.FuzzTests.dll",
|
||||||
|
"class": "FancyZones.FuzzTests.FuzzTests",
|
||||||
|
"method": "FuzzGridFromJsonElement",
|
||||||
|
"FuzzingTargetBinaries": [
|
||||||
|
"PowerToys.FancyZones.dll"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"adoTemplate": {
|
||||||
|
// supply the values appropriate to your
|
||||||
|
// project, where bugs will be filed
|
||||||
|
"org": "microsoft",
|
||||||
|
"project": "OS",
|
||||||
|
"AssignedTo": "mengyuanchen@microsoft.com",
|
||||||
|
"AreaPath": "OS\\Windows Client and Services\\WinPD\\DEEP-Developer Experience, Ecosystem and Partnerships\\SHINE\\PowerToys",
|
||||||
|
"IterationPath": "OS\\Future"
|
||||||
|
},
|
||||||
|
"jobNotificationEmail": "mengyuanchen@microsoft.com",
|
||||||
|
"skip": false,
|
||||||
|
"rebootAfterSetup": false,
|
||||||
|
"oneFuzzJobs": [
|
||||||
|
// at least one job is required
|
||||||
|
{
|
||||||
|
"projectName": "FancyZones",
|
||||||
|
"targetName": "FancyZones-dotnet-fuzzer-FuzzGridFromJsonElement"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"jobDependencies": [
|
||||||
|
// this should contain, at minimum,
|
||||||
|
// the DLL and PDB files
|
||||||
|
// you will need to add any other files required
|
||||||
|
// (globs are supported)
|
||||||
|
"FancyZones.FuzzTests.dll",
|
||||||
|
"FancyZones.FuzzTests.pdb",
|
||||||
|
"Microsoft.Windows.SDK.NET.dll",
|
||||||
|
"Newtonsoft.Json.dll",
|
||||||
|
"System.IO.Abstractions.dll",
|
||||||
|
"Testably.Abstractions.FileSystem.Interface.dll",
|
||||||
|
"TestableIO.System.IO.Abstractions.dll",
|
||||||
|
"TestableIO.System.IO.Abstractions.Wrappers.dll",
|
||||||
|
"WinRT.Runtime.dll"
|
||||||
|
],
|
||||||
|
"SdlWorkItemId": 49911822
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user