Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create stryker.yml #311

Merged
merged 39 commits into from
Jan 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
069c6b8
Create stryker.yml
jamescourtney Oct 3, 2022
cb8a5a9
Update stryker.yml
jamescourtney Oct 3, 2022
9348a89
Add configs
jamescourtney Oct 3, 2022
c13c7d4
Merge branch 'stryker' of https://github.com/jamescourtney/FlatSharp …
jamescourtney Oct 3, 2022
8707737
Update stryker.yml
jamescourtney Oct 3, 2022
6dd1441
Update stryker config
jamescourtney Oct 3, 2022
14e1aad
Merge branch 'stryker' of https://github.com/jamescourtney/FlatSharp …
jamescourtney Oct 3, 2022
82202ae
Merge remote-tracking branch 'origin/main' into stryker
jamescourtney Jan 25, 2023
8a95955
ehh
jamescourtney Jan 25, 2023
2df9320
Merge remote-tracking branch 'origin/main' into stryker
jamescourtney Jan 26, 2023
ea7cb78
dedicated projects
jamescourtney Jan 26, 2023
f446bf8
Update stryker.yml
jamescourtney Jan 26, 2023
2f684b4
fix csproj
jamescourtney Jan 26, 2023
25158f8
Remove dead project
jamescourtney Jan 26, 2023
56f6be1
Add config file
jamescourtney Jan 26, 2023
663ebdd
Update stryker.yml
jamescourtney Jan 26, 2023
cbb53fc
Tests
jamescourtney Jan 27, 2023
4b84e6a
Merge branch 'stryker' of https://github.com/jamescourtney/FlatSharp …
jamescourtney Jan 27, 2023
8ed16a7
Merge branch 'stryker' of https://github.com/jamescourtney/FlatSharp …
jamescourtney Jan 27, 2023
14117a3
Merge branch 'stryker' of https://github.com/jamescourtney/FlatSharp …
jamescourtney Jan 27, 2023
e1516d3
Update stryker.yml
jamescourtney Jan 27, 2023
83f75ff
Rename
jamescourtney Jan 27, 2023
72978eb
Merge branch 'stryker' of https://github.com/jamescourtney/FlatSharp …
jamescourtney Jan 27, 2023
10584a7
Update stryker.yml
jamescourtney Jan 27, 2023
26e1b57
More coverage
jamescourtney Jan 27, 2023
1813027
start on vectors
jamescourtney Jan 27, 2023
e9ca624
More
jamescourtney Jan 27, 2023
a9bb3a8
80%!
jamescourtney Jan 28, 2023
a3788e8
comment
jamescourtney Jan 28, 2023
5868c73
Fix tests
jamescourtney Jan 28, 2023
ce3c4cf
Update codecov.yml
jamescourtney Jan 28, 2023
627ecef
Add coverlet to stryker
jamescourtney Jan 28, 2023
2227ee9
Fix build error
jamescourtney Jan 28, 2023
8cb14bb
Update codecov.yml
jamescourtney Jan 28, 2023
3151125
Remove coverlet
jamescourtney Jan 28, 2023
c7c9f83
Update codecov.yml
jamescourtney Jan 28, 2023
c1d3a58
Update README.md
jamescourtney Jan 28, 2023
25600c6
Delete stryker-config.json
jamescourtney Jan 28, 2023
5193f69
Add 80% threshold
jamescourtney Jan 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,23 @@ jobs:
--output pooling.coverage.xml `
--targetargs "src\FlatSharp.Compiler\bin\Debug\net7.0\FlatSharp.Compiler.dll --nullable-warnings false --normalize-field-names true --gen-poolable true --input `"$fbs`" -o src/tests/FlatSharpPoolableEndToEndTests"

- name: Run FlatSharp.Compiler (Stryker Tests)
# You may pin to the exact commit or the version.
# uses: Amadevus/pwsh-script@97a8b211a5922816aa8a69ced41fa32f23477186
uses: Amadevus/pwsh-script@v2.0.3
with:
# PowerShell script to execute in Actions-hydrated context
script: |
$fbs = (gci -r src/tests/Stryker/*.fbs) -join ";"
coverlet `
.\src\FlatSharp.Compiler\bin\Debug\net7.0 `
--skipautoprops `
--use-source-link `
--format opencover `
--target "dotnet" `
--output stryker.coverage.xml `
--targetargs "src/FlatSharp.Compiler/bin/Debug/net7.0/FlatSharp.Compiler.dll --nullable-warnings false --normalize-field-names true --input `"$fbs`" -o src/tests/Stryker/CodeGen --mutation-testing-mode"

- name: Test
working-directory: src
run: dotnet test -c Debug -p:SignAssembly=false --collect:"XPlat Code Coverage" --settings Tests/coverlet.runsettings -f net7.0
Expand Down
56 changes: 56 additions & 0 deletions .github/workflows/stryker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Mutation Testing

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
build:
runs-on: windows-2019
env:
AppVeyorBuild: true
steps:
- uses: actions/checkout@v2

- name: Setup .NET 7
uses: actions/setup-dotnet@v1
with:
dotnet-version: 7.0.x

- name: Install Stryker
run: dotnet tool install -g dotnet-stryker

- name: Build FlatSharp.Compiler
working-directory: src/FlatSharp.Compiler
run: dotnet build -c Release

- name: Run FlatSharp.Compiler (Mutation Tests)
# You may pin to the exact commit or the version.
# uses: Amadevus/pwsh-script@97a8b211a5922816aa8a69ced41fa32f23477186
uses: Amadevus/pwsh-script@v2.0.3
with:
# PowerShell script to execute in Actions-hydrated context
script: |
$fbs = (gci -r src/tests/Stryker/*.fbs) -join ";"
dotnet src/FlatSharp.Compiler/bin/Release/net7.0/FlatSharp.Compiler.dll --nullable-warnings false --normalize-field-names true --input "$fbs" -o src/tests/Stryker/CodeGen --mutation-testing-mode

- name: Build
working-directory: src/Tests/Stryker/Tests
run: dotnet build -c Release

- name: Test
working-directory: src/Tests/Stryker/Tests
run: dotnet test -c Release

- name: Mutate
working-directory: src/Tests/Stryker/Tests
run: dotnet-stryker

- name: Upload Results
uses: actions/upload-artifact@v2
with:
name: Stryker Results
path: ./**/StrykerOutput/**/*.*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@
/src/Tests/FlatSharpEndToEndTests/FlatSharpEndToEndTests.xml
/src/Tests/FlatSharpEndToEndTests/FlatSharp.generated.cs
/src/Benchmarks/ExperimentalBenchmark/FlatSharp.generated.cs
/src/Tests/FlatSharpEndToEndTests_Generated/FlatSharpEndToEndTestsGenerated.xml
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ All FlatSharp packages are published on nuget.org:
- **FlatSharp.Runtime**: The runtime library. You always need this.
- **FlatSharp.Compiler**: Build time compiler for generating C# from an FBS schema.

FlatSharp is a mature library and has been shipped to production at Microsoft, Unity3D, and others. Full status can be found at [ProjectStatus.md](ProjectStatus.md).
FlatSharp is a mature library and has been shipped to production at Microsoft, Unity3D, and others. Full status can be found at [ProjectStatus.md](ProjectStatus.md). FlatSharp is [extensively tested](https://github.com/jamescourtney/FlatSharp/wiki/Testing), using Mutation Testing, Code Coverage, Oracle Testing, and other techniques to ensure the library doesn't regress.

### Getting Started
If you're completely new to FlatBuffers, take a minute to look over [the FlatBuffer overview](https://google.github.io/flatbuffers/index.html#flatbuffers_overview). Additionally, it's worth the time to understand the different elements of [FlatBuffer schemas](https://google.github.io/flatbuffers/flatbuffers_guide_writing_schema.html).
Expand Down
4 changes: 4 additions & 0 deletions src/FlatSharp.Compiler/CompilerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,8 @@ public record CompilerOptions

[Option("instrument", Hidden = true, Default = false)]
public bool Instrument { get; set; }

// Suppress auto generated markers for mutation testing.
[Option("mutation-testing-mode", Hidden = true, Default = false)]
public bool MutationTestingMode { get; set; }
}
15 changes: 14 additions & 1 deletion src/FlatSharp.Compiler/FlatSharpCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class FlatSharpCompiler
{
public const string FailureMessage = "// !! FLATSHARP CODE GENERATION FAILED. THIS FILE MAY CONTAIN INCOMPLETE OR INACCURATE DATA !!";

internal static CompilerOptions? CommandLineOptions { get; private set; }

private static string AssemblyVersion => typeof(ISchemaMutator).Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>()?.Version ?? "unknown";

[ExcludeFromCodeCoverage]
Expand All @@ -44,6 +46,7 @@ static int Main(string[] args)
CommandLine.Parser.Default.ParseArguments<CompilerOptions>(args)
.WithParsed(x =>
{
CommandLineOptions = x;
exitCode = RunCompiler(x);
});
}
Expand Down Expand Up @@ -83,7 +86,12 @@ private static int RunCompiler(CompilerOptions options)
}

// Read existing file to see if we even need to do any work.
const string outputFileName = "FlatSharp.generated.cs";
string outputFileName = options.MutationTestingMode switch
{
true => "FlatSharp.cs",
false => "FlatSharp.generated.cs",
};

string outputFullPath = Path.Combine(options.OutputDirectory, outputFileName);

try
Expand All @@ -107,6 +115,11 @@ private static int RunCompiler(CompilerOptions options)
try
{
cSharp = CreateCSharp(bfbs, inputHash, options);

if (options.MutationTestingMode)
{
cSharp = cSharp.Replace("BitConverter", "MockBitConverter");
}
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ private void EmitDefaultConstrutor(CodeWriter writer, CompileContext context)
}

writer.AppendLine("#pragma warning disable CS8618"); // nullable

if (context.Options.MutationTestingMode)
{
writer.AppendLine($"[{typeof(ExcludeFromCodeCoverageAttribute).GetCompilableTypeName()}]");
}

writer.AppendLine($"public {this.Name}()");
using (writer.WithBlock())
{
Expand Down
23 changes: 13 additions & 10 deletions src/FlatSharp.Compiler/SchemaModel/RootModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ public void AddElement(BaseSchemaModel model)

internal void WriteCode(CodeWriter writer, CompileContext context)
{
writer.AppendLine($@"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the FlatSharp FBS to C# compiler (source hash: {context.InputHash})
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
");
if (!context.Options.MutationTestingMode)
{
writer.AppendLine($$"""
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the FlatSharp FBS to C# compiler (source hash: {{context.InputHash}})
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
""");
}

writer.AppendLine("using System;");
writer.AppendLine("using System.Collections.Generic;");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public StructVectorPropertyFieldModel(
$"{field.Name}[{i}]",
modifiedAttributes)
{
ProtectedGetter = true,
ProtectedGetter = FlatSharpCompiler.CommandLineOptions?.MutationTestingMode != true,
};

propertyModels.Add(model);
Expand Down
6 changes: 4 additions & 2 deletions src/FlatSharp.Compiler/SchemaModel/TableSchemaModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ protected override void EmitClassDefinition(CodeWriter writer, CompileContext co
string fileId = string.Empty;
if (this.Schema.RootTable?.Name == this.FullName && !string.IsNullOrEmpty(this.Schema.FileIdentifier))
{
fileId = $"{nameof(FlatBufferTableAttribute.FileIdentifier)} = \"{this.Schema.FileIdentifier}\"";
fileId = $", {nameof(FlatBufferTableAttribute.FileIdentifier)} = \"{this.Schema.FileIdentifier}\"";
}

string attribute = $"[FlatBufferTable({fileId})]";
string emitSerializer = $"{nameof(FlatBufferTableAttribute.BuildSerializer)} = {(this.Attributes.DeserializationOption is not null ? "true" : "false")}";

string attribute = $"[FlatBufferTable({emitSerializer}{fileId})]";

writer.AppendSummaryComment(this.Documentation);
writer.AppendLine(attribute);
Expand Down
5 changes: 5 additions & 0 deletions src/FlatSharp.Runtime/Attributes/FlatBufferTableAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public class FlatBufferTableAttribute : Attribute
/// Specifies the file identifier for serialized tables. Must be precisely 4 ASCII characters.
/// </summary>
public string? FileIdentifier { get; set; }

/// <summary>
/// Indicates that a serializer should be built for the given table.
/// </summary>
public bool BuildSerializer { get; set; } = true;
}
2 changes: 2 additions & 0 deletions src/FlatSharp.Runtime/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
[assembly: InternalsVisibleTo("FlatSharp, PublicKey=0024000004800000940000000602000000240000525341310004000001000100898185ce69dca04430ab296e094cd7eb6c66f5a3cfb0631ef64586fa183f0cb5ca64c47539a3a3c6351a9cf8d976a8d94350af430d5adc10536b3904cc1d6ecaaf3d0cb708aa318c559625f05d3b2d89da1c2bb323bb40e36dcf9245f21c3a4b6793c56ffface5e6e18290afb13c7eac1ea9c7a0c22f289c622bfa7b247d81a2")]
[assembly: InternalsVisibleTo("FlatSharpTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100898185ce69dca04430ab296e094cd7eb6c66f5a3cfb0631ef64586fa183f0cb5ca64c47539a3a3c6351a9cf8d976a8d94350af430d5adc10536b3904cc1d6ecaaf3d0cb708aa318c559625f05d3b2d89da1c2bb323bb40e36dcf9245f21c3a4b6793c56ffface5e6e18290afb13c7eac1ea9c7a0c22f289c622bfa7b247d81a2")]
[assembly: InternalsVisibleTo("FlatSharpEndToEndTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100898185ce69dca04430ab296e094cd7eb6c66f5a3cfb0631ef64586fa183f0cb5ca64c47539a3a3c6351a9cf8d976a8d94350af430d5adc10536b3904cc1d6ecaaf3d0cb708aa318c559625f05d3b2d89da1c2bb323bb40e36dcf9245f21c3a4b6793c56ffface5e6e18290afb13c7eac1ea9c7a0c22f289c622bfa7b247d81a2")]
[assembly: InternalsVisibleTo("FlatSharpEndToEndTestsGenerated, PublicKey=0024000004800000940000000602000000240000525341310004000001000100898185ce69dca04430ab296e094cd7eb6c66f5a3cfb0631ef64586fa183f0cb5ca64c47539a3a3c6351a9cf8d976a8d94350af430d5adc10536b3904cc1d6ecaaf3d0cb708aa318c559625f05d3b2d89da1c2bb323bb40e36dcf9245f21c3a4b6793c56ffface5e6e18290afb13c7eac1ea9c7a0c22f289c622bfa7b247d81a2")]
[assembly: InternalsVisibleTo("PoolingTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100898185ce69dca04430ab296e094cd7eb6c66f5a3cfb0631ef64586fa183f0cb5ca64c47539a3a3c6351a9cf8d976a8d94350af430d5adc10536b3904cc1d6ecaaf3d0cb708aa318c559625f05d3b2d89da1c2bb323bb40e36dcf9245f21c3a4b6793c56ffface5e6e18290afb13c7eac1ea9c7a0c22f289c622bfa7b247d81a2")]
[assembly: InternalsVisibleTo("FlatSharpCompilerTests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100898185ce69dca04430ab296e094cd7eb6c66f5a3cfb0631ef64586fa183f0cb5ca64c47539a3a3c6351a9cf8d976a8d94350af430d5adc10536b3904cc1d6ecaaf3d0cb708aa318c559625f05d3b2d89da1c2bb323bb40e36dcf9245f21c3a4b6793c56ffface5e6e18290afb13c7eac1ea9c7a0c22f289c622bfa7b247d81a2")]
[assembly: InternalsVisibleTo("FlatSharp.Compiler, PublicKey=0024000004800000940000000602000000240000525341310004000001000100898185ce69dca04430ab296e094cd7eb6c66f5a3cfb0631ef64586fa183f0cb5ca64c47539a3a3c6351a9cf8d976a8d94350af430d5adc10536b3904cc1d6ecaaf3d0cb708aa318c559625f05d3b2d89da1c2bb323bb40e36dcf9245f21c3a4b6793c56ffface5e6e18290afb13c7eac1ea9c7a0c22f289c622bfa7b247d81a2")]
Expand All @@ -33,6 +34,7 @@
[assembly: InternalsVisibleTo("FlatSharpTests")]
[assembly: InternalsVisibleTo("FlatSharpCompilerTests")]
[assembly: InternalsVisibleTo("FlatSharpEndToEndTests")]
[assembly: InternalsVisibleTo("FlatSharpEndToEndTestsGenerated")]
[assembly: InternalsVisibleTo("PoolingTests")]
[assembly: InternalsVisibleTo("FlatSharp.Compiler")]
[assembly: InternalsVisibleTo("ExperimentalBenchmark")]
Expand Down
11 changes: 11 additions & 0 deletions src/FlatSharp.Runtime/stryker-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"stryker-config":
{
"project": "FlatSharp.Runtime.csproj",
"test-projects": [
"../Tests/FlatSharpTests/FlatSharpTests.csproj",
"../Tests/FlatSharpCompilerTests/FlatSharpCompilerTests.csproj"
],
"target-framework": "net6.0"
}
}
2 changes: 1 addition & 1 deletion src/FlatSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microbench.6.3.3", "Benchma
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlatSharpPoolableEndToEndTests", "Tests\FlatSharpPoolableEndToEndTests\FlatSharpPoolableEndToEndTests.csproj", "{7E55A248-4BBD-48AD-B27D-A7E0E705DC89}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FlatSharp.UnityPolyfills", "FlatSharp.UnityPolyfills\FlatSharp.UnityPolyfills.csproj", "{E439E4AF-B948-4E6C-8791-1830619EB35B}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FlatSharp.UnityPolyfills", "FlatSharp.UnityPolyfills\FlatSharp.UnityPolyfills.csproj", "{E439E4AF-B948-4E6C-8791-1830619EB35B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
3 changes: 0 additions & 3 deletions src/FlatSharp/FlatBufferSerializerOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,6 @@ public FlatBufferSerializerOptions(
/// <summary>
/// Indicates if the object is immutable OR changes to the object are guaranteed to be written back to the buffer.
/// </summary>
/// <remarks>
/// VectorCacheMutable is not eligible here, since only some changes are written back.
/// </remarks>
public bool CanSerializeWithMemoryCopy => this.DeserializationOption == FlatBufferDeserializationOption.Lazy ||
this.DeserializationOption == FlatBufferDeserializationOption.Progressive;

Expand Down
4 changes: 2 additions & 2 deletions src/FlatSharp/FlatBufferVectorHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ internal struct {className}<{context.InputBufferTypeName}> : IVectorItemAccessor
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public {className}(int offset, TInputBuffer buffer)
{{
this.count = checked((int)buffer.ReadUInt(offset));
this.count = (int)buffer.ReadUInt(offset);

// Advance to the start of the element at index 0. Easiest to do this once
// in the .ctor than repeatedly for each index.
this.offset = checked(offset + sizeof(uint));
this.offset = offset + sizeof(uint);
}}

public int ItemSize => {inlineSize};
Expand Down
7 changes: 2 additions & 5 deletions src/FlatSharp/Serialization/DeserializeClassDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public override string ToString()
}

string interfaceGlobalName = typeof(IFlatBufferDeserializedObject).GetGlobalCompilableTypeName();
bool isProgressive = this.options.DeserializationOption == FlatBufferDeserializationOption.Progressive;

return
$@"
Expand All @@ -292,7 +293,6 @@ private sealed class {this.ClassName}<TInputBuffer>
, {interfaceGlobalName}
, {typeof(IPoolableObject).GetGlobalCompilableTypeName()}
, {typeof(IPoolableObjectDebug).GetGlobalCompilableTypeName()}

where TInputBuffer : IInputBuffer
{{
private static readonly {typeof(FlatBufferDeserializationContext).GetGlobalCompilableTypeName()} {CtorContextVariableName}
Expand Down Expand Up @@ -329,7 +329,6 @@ private sealed class {this.ClassName}<TInputBuffer>
}}
";
}

protected virtual string GetSetterBody(ItemMemberModel itemModel)
{
List<string> setterLines = new List<string>();
Expand Down Expand Up @@ -538,9 +537,7 @@ public override void ReturnToPool(bool unsafeForce = false)

protected static string GetFieldName(ItemMemberModel itemModel) => $"__index{itemModel.Index}Value";

protected static string GetHasValueFieldName(int index) => $"__mask{index}";

protected static string GetHasValueFieldName(ItemMemberModel itemModel) => GetHasValueFieldName(itemModel.Index / 8);
protected static string GetHasValueFieldName(ItemMemberModel itemModel) => $"__mask{itemModel.Index / 8}";

protected static string GetHasValueFieldMask(ItemMemberModel itemModel) => $"(byte){1 << (itemModel.Index % 8)}";

Expand Down
Loading