Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 8 additions & 2 deletions fuzzing/Opc.Ua.Encoders.Fuzz.Tests/EncoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,15 @@ public class EncoderTests : FuzzTargetTestsBase

protected override Type FuzzableCodeType => typeof(FuzzableCode);

protected override void OnFuzzTargetSetup(ITelemetryContext telemetry)
[Test]
public void MessageContextIsInitializedWithoutTestSetup()
{
FuzzableCode.MessageContext = ServiceMessageContext.Create(telemetry);
ServiceMessageContext firstContext = FuzzableCode.MessageContext;
ServiceMessageContext secondContext = FuzzableCode.MessageContext;

Assert.That(firstContext, Is.Not.Null);
Assert.That(firstContext, Is.SameAs(secondContext));
Assert.That(firstContext.Factory, Is.Not.Null);
}
Comment thread
marcschier marked this conversation as resolved.
}
}
8 changes: 0 additions & 8 deletions fuzzing/Opc.Ua.Encoders.Fuzz.Tests/Issue3546RoundTripTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

using System.IO;
using NUnit.Framework;
using Opc.Ua.Tests;

namespace Opc.Ua.Fuzzing
{
Expand Down Expand Up @@ -58,13 +57,6 @@ public class Issue3546RoundTripTests
{
private static readonly uint[] s_arrayDimensions = [1u, 2u];

[SetUp]
public void Setup()
{
ITelemetryContext telemetry = NUnitTelemetryContext.Create();
FuzzableCode.MessageContext = ServiceMessageContext.Create(telemetry);
}

[Test]
public void DataTypeNodeWithReferencesRoundTripsCleanly()
{
Expand Down
5 changes: 2 additions & 3 deletions fuzzing/Opc.Ua.Encoders.Fuzz.Tools/Encoders.Testcases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,10 @@ public enum TestCaseEncoders
/// Run the encoder test cases
/// </summary>
/// <param name="workPath"></param>
/// <param name="telemetry">The telemetry context to use to create obvservability instruments</param>
/// <param name="telemetry">Unused; retained for the common fuzz-tool signature.</param>
public static void Run(string workPath, ITelemetryContext telemetry)
{
// Create the Testcases for the binary decoder.
FuzzableCode.MessageContext = ServiceMessageContext.Create(telemetry);
_ = telemetry;
string pathSuffix = GetTestcaseEncoderSuffix(TestCaseEncoders.Binary);
string pathTarget = workPath + pathSuffix + Path.DirectorySeparatorChar;
Directory.CreateDirectory(pathTarget);
Expand Down
12 changes: 11 additions & 1 deletion fuzzing/Opc.Ua.Encoders.Fuzz/FuzzableCode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,15 @@

using System;
using System.IO;
using Microsoft.Extensions.Logging.Abstractions;
using Opc.Ua.Bindings;

namespace Opc.Ua.Fuzzing
{
public static partial class FuzzableCode
{
public static ServiceMessageContext MessageContext { get; set; }
public static ServiceMessageContext MessageContext { get; } =
ServiceMessageContext.Create(new FuzzTelemetryContext());

/// <summary>
/// Print information about the fuzzer target.
Expand Down Expand Up @@ -70,5 +72,13 @@ private static MemoryStream PrepareArraySegmentStream(Stream stream)

return memoryStream;
}

private sealed class FuzzTelemetryContext : TelemetryContextBase
{
public FuzzTelemetryContext()
: base(NullLoggerFactory.Instance)
{
}
}
}
}
Loading