Skip to content

Commit 7557b78

Browse files
authored
Use separate key instances for span/array/array+offset test classes (#34199)
Because the key object generation was done in the algorithm-specific base class, the triplet of interface types was using the key instances in parallel. By moving the static variable (and initialization thereof) to each of the derived classes, the key objects are unique per class, which matches the test parallelism. Making the classes be part of the same test collection would also solve this problem, which would save on a few random keygens, but would likely overall take more time due to the number of tests that would be moved to sequential execution.
1 parent e85e352 commit 7557b78

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/DSA/DSASignatureFormatTests.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ namespace System.Security.Cryptography.Dsa.Tests
1111
{
1212
public abstract class DSASignatureFormatTests : DsaFamilySignatureFormatTests
1313
{
14-
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
15-
16-
protected override KeyDescription[] GenerateTestKeys() => s_keys;
1714
protected override bool SupportsSha2 => DSAFactory.SupportsFips186_3;
1815
protected override string HashParameterName => "rgbHash";
1916
protected override string SignatureParameterName => "rgbSignature";
@@ -50,7 +47,7 @@ private static KeyDescription OpenKey(in DSAParameters dsaParameters)
5047
dsaParameters.Q.Length * 8);
5148
}
5249

53-
private static IEnumerable<KeyDescription> LocalGenerateTestKeys()
50+
protected static IEnumerable<KeyDescription> LocalGenerateTestKeys()
5451
{
5552
if (DSAFactory.SupportsKeyGeneration)
5653
{
@@ -73,6 +70,9 @@ private static IEnumerable<KeyDescription> LocalGenerateTestKeys()
7370

7471
public sealed class DsaArraySignatureFormatTests : DSASignatureFormatTests
7572
{
73+
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
74+
75+
protected override KeyDescription[] GenerateTestKeys() => s_keys;
7676
protected override bool IsArrayBased => true;
7777

7878
protected override byte[] SignHash(
@@ -114,6 +114,9 @@ protected override bool VerifyData(
114114

115115
public sealed class DsaArrayOffsetSignatureFormatTests : DSASignatureFormatTests
116116
{
117+
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
118+
119+
protected override KeyDescription[] GenerateTestKeys() => s_keys;
117120
protected override bool IsArrayBased => true;
118121

119122
protected override byte[] SignHash(
@@ -232,6 +235,9 @@ public void OffsetAndCountOutOfRange()
232235

233236
public sealed class DsaSpanSignatureFormatTests : DSASignatureFormatTests
234237
{
238+
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
239+
240+
protected override KeyDescription[] GenerateTestKeys() => s_keys;
235241
protected override bool IsArrayBased => false;
236242

237243
protected override byte[] SignHash(

src/libraries/Common/tests/System/Security/Cryptography/AlgorithmImplementations/ECDsa/ECDsaSignatureFormatTests.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@ namespace System.Security.Cryptography.EcDsa.Tests
1212
{
1313
public abstract class ECDsaSignatureFormatTests : DsaFamilySignatureFormatTests
1414
{
15-
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
16-
17-
protected override KeyDescription[] GenerateTestKeys() => s_keys;
1815
protected override bool SupportsSha2 => true;
1916

2017
private static KeyDescription CreateKey(ECCurve curve)
@@ -38,7 +35,7 @@ private static KeyDescription OpenKey(in ECParameters ecParameters)
3835
dsa.KeySize);
3936
}
4037

41-
private static IEnumerable<KeyDescription> LocalGenerateTestKeys()
38+
protected static IEnumerable<KeyDescription> LocalGenerateTestKeys()
4239
{
4340
if (ECDsaFactory.IsCurveValid(EccTestData.BrainpoolP160r1Key1.Curve.Oid))
4441
{
@@ -58,8 +55,11 @@ private static IEnumerable<KeyDescription> LocalGenerateTestKeys()
5855

5956
public sealed class ECDsaArraySignatureFormatTests : ECDsaSignatureFormatTests
6057
{
61-
protected override bool IsArrayBased => true;
58+
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
6259

60+
protected override KeyDescription[] GenerateTestKeys() => s_keys;
61+
protected override bool IsArrayBased => true;
62+
6363
protected override byte[] SignHash(
6464
KeyDescription key,
6565
byte[] hash,
@@ -99,6 +99,9 @@ protected override bool VerifyData(
9999

100100
public sealed class ECDsaArrayOffsetSignatureFormatTests : ECDsaSignatureFormatTests
101101
{
102+
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
103+
104+
protected override KeyDescription[] GenerateTestKeys() => s_keys;
102105
protected override bool IsArrayBased => true;
103106

104107
protected override byte[] SignHash(
@@ -217,6 +220,9 @@ public void OffsetAndCountOutOfRange()
217220

218221
public sealed class ECDsaSpanSignatureFormatTests : ECDsaSignatureFormatTests
219222
{
223+
private static readonly KeyDescription[] s_keys = LocalGenerateTestKeys().ToArray();
224+
225+
protected override KeyDescription[] GenerateTestKeys() => s_keys;
220226
protected override bool IsArrayBased => false;
221227

222228
protected override byte[] SignHash(

0 commit comments

Comments
 (0)