From b205794d6ad7b50e140f615f367366e607571341 Mon Sep 17 00:00:00 2001 From: "Mengyuan Chen (from Dev Box)" Date: Tue, 28 Jan 2025 22:00:17 +0800 Subject: [PATCH] Add fuzz test cases --- .../RegistryPreview.FuzzTests/FuzzTests.cs | 26 ++++++++++ .../MSTestSettings.cs | 5 ++ .../OneFuzzConfig.json | 50 +++++++++++++++++++ .../RegistryPreview.FuzzTests.csproj | 28 +++++++++++ 4 files changed, 109 insertions(+) create mode 100644 src/modules/registrypreview/RegistryPreview.FuzzTests/FuzzTests.cs create mode 100644 src/modules/registrypreview/RegistryPreview.FuzzTests/MSTestSettings.cs create mode 100644 src/modules/registrypreview/RegistryPreview.FuzzTests/OneFuzzConfig.json create mode 100644 src/modules/registrypreview/RegistryPreview.FuzzTests/RegistryPreview.FuzzTests.csproj diff --git a/src/modules/registrypreview/RegistryPreview.FuzzTests/FuzzTests.cs b/src/modules/registrypreview/RegistryPreview.FuzzTests/FuzzTests.cs new file mode 100644 index 000000000000..f81bb1cc33e0 --- /dev/null +++ b/src/modules/registrypreview/RegistryPreview.FuzzTests/FuzzTests.cs @@ -0,0 +1,26 @@ +// 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. +namespace RegistryPreview.FuzzTests +{ + public class FuzzTests + { + public static void FuzzTargetMethod(ReadOnlySpan input) + { + try + { + // … use input parameter in code under test … + // + // TargetMethod(…); + } + catch (Exception ex) when (ex is ArgumentException) + { + // This is an example. It's important to filter out any *expected* exceptions from our code here. + // However, catching all exceptions is considered an anti-pattern because it may suppress legitimate + // issues, such as a NullReferenceException thrown by our code. In this case, we still re-throw + // the exception, as the ToJsonFromXmlOrCsvAsync method is not expected to throw any exceptions. + throw; + } + } + } +} diff --git a/src/modules/registrypreview/RegistryPreview.FuzzTests/MSTestSettings.cs b/src/modules/registrypreview/RegistryPreview.FuzzTests/MSTestSettings.cs new file mode 100644 index 000000000000..5b05c0b86e3f --- /dev/null +++ b/src/modules/registrypreview/RegistryPreview.FuzzTests/MSTestSettings.cs @@ -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)] diff --git a/src/modules/registrypreview/RegistryPreview.FuzzTests/OneFuzzConfig.json b/src/modules/registrypreview/RegistryPreview.FuzzTests/OneFuzzConfig.json new file mode 100644 index 000000000000..d86b7bf773c6 --- /dev/null +++ b/src/modules/registrypreview/RegistryPreview.FuzzTests/OneFuzzConfig.json @@ -0,0 +1,50 @@ +// 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. +{ + "configVersion": 3, + "entries": [ + { + "fuzzer": { + "$type": "libfuzzerDotNet", + "dll": "RegistryPreview.FuzzTests.dll", + "class": "RegistryPreview.FuzzTests.FuzzTests", + "method": "FuzzTargetMethod", + "FuzzingTargetBinaries": [ + "PowerToys.RegistryPreview.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": "RegistryPreview", + "targetName": "RegistryPreview-dotnet-fuzzer" + } + ], + "jobDependencies": [ + // this should contain, at minimum, + // the DLL and PDB files + // you will need to add any other files required + // (globs are supported) + "RegistryPreview.FuzzTests.dll", + "RegistryPreview.FuzzTests.pdb", + "Microsoft.Windows.SDK.NET.dll", + "Newtonsoft.Json.dll", + "WinRT.Runtime.dll" + ], + "SdlWorkItemId": 49911822 + } + ] +} \ No newline at end of file diff --git a/src/modules/registrypreview/RegistryPreview.FuzzTests/RegistryPreview.FuzzTests.csproj b/src/modules/registrypreview/RegistryPreview.FuzzTests/RegistryPreview.FuzzTests.csproj new file mode 100644 index 000000000000..a196ccb1b120 --- /dev/null +++ b/src/modules/registrypreview/RegistryPreview.FuzzTests/RegistryPreview.FuzzTests.csproj @@ -0,0 +1,28 @@ + + + + net8.0 + latest + enable + enable + + + + ..\..\..\..\$(Platform)\$(Configuration)\tests\RegistryPreview.FuzzTests\ + + + + + PreserveNewest + + + + + + + + + + + +