aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar vnugent <public@vaughnnugent.com>2024-09-14 15:43:45 -0400
committerLibravatar vnugent <public@vaughnnugent.com>2024-09-14 15:43:45 -0400
commit322bbe00f77772ba6b0e25759de95dd517b6014c (patch)
tree12abc5835dc6df87c3aaf7d39dfd541fa26b6529
parentabcd0e0d6cb5532c8a19a8cd8c7dd83e7f143442 (diff)
build: Testing updates and easier dev-testing
-rw-r--r--Module.Taskfile.yaml54
-rw-r--r--lib/Plugins.Essentials/src/EventProcessor.cs4
-rw-r--r--lib/Utils/src/ERRNO.cs25
-rw-r--r--lib/Utils/src/Memory/MemoryUtil.cs3
-rw-r--r--lib/Utils/tests/.runsettings3
-rw-r--r--lib/Utils/tests/IO/VnMemoryStreamTests.cs15
-rw-r--r--lib/Utils/tests/Memory/NativeHeapTests.cs10
7 files changed, 75 insertions, 39 deletions
diff --git a/Module.Taskfile.yaml b/Module.Taskfile.yaml
index 6ec8fc6..99ea9b2 100644
--- a/Module.Taskfile.yaml
+++ b/Module.Taskfile.yaml
@@ -10,42 +10,68 @@
version: '3'
-vars:
- INT_DIR: '{{ .SCRATCH_DIR }}/obj/{{ .MODULE_NAME }}/'
- MS_ARGS: '/p:RunAnalyzersDuringBuild=false /p:IntermediateOutputPath="{{.INT_DIR}}" /p:UseCommonOutputDirectory=true /p:BuildInParallel=true /p:MultiProcessorCompilation=true /p:ErrorOnDuplicatePublishOutputFiles=false'
+vars:
+ MS_ARGS: '/p:RunAnalyzersDuringBuild=false /p:UseCommonOutputDirectory=true /p:BuildInParallel=true /p:MultiProcessorCompilation=true /p:ErrorOnDuplicatePublishOutputFiles=false'
PACK_OUT: '{{ .OUTPUT_DIR }}/{{ .HEAD_SHA }}/pkg'
tasks:
+ default:
+ desc: 'Builds the managed libraries in this module for development'
+ cmds:
+ - dotnet build -c debug {{ .MS_ARGS }}
+
+
#called by build pipeline to sync repo
update:
cmds:
- git reset --hard #clean up any local changes
- - git remote update
+ - git remote update
- git pull origin {{ .BRANCH_NAME }} --verify-signatures
#re-write semver after hard reset
- dotnet-gitversion.exe /updateprojectfiles
#called by build pipeline to build module
build:
+ desc: "Used by vnbuild to build the entire module at CI time"
+ vars:
+ INT_DIR: '{{ .SCRATCH_DIR }}/obj/{{ .MODULE_NAME }}/'
+ MS_ARGS: '{{ .MS_ARGS }} /p:IntermediateOutputPath="{{ .INT_DIR }}"'
cmds:
- - echo "building module {{.MODULE_NAME}}"
-
+ - cmd: echo "building module {{ .MODULE_NAME }}"
+ silent: true
+
#build debug mode first
- task: build_debug
+ vars: { MS_ARGS: '{{ .MS_ARGS }}'}
- task: build_release
+ vars: { MS_ARGS: '{{ .MS_ARGS }}'}
publish:
+ desc: "Used by vnbuild to prepare the packages for build servers"
cmds:
#git archive in the module directory
- - git archive --format {{.ARCHIVE_FILE_FORMAT}} --output {{.ARCHIVE_FILE_NAME}} HEAD
+ - git archive --format {{ .ARCHIVE_FILE_FORMAT }} --output {{ .ARCHIVE_FILE_NAME }} HEAD
#push packages to the sleet feed (feed path is vnbuild global)
- - sleet push "{{.PACK_OUT}}/debug/" --source debug --config "{{.SLEET_CONFIG_PATH}}" --force
- - sleet push "{{.PACK_OUT}}/release/" --source release --config "{{.SLEET_CONFIG_PATH}}" --force
+ - sleet push "{{ .PACK_OUT }}/debug/" --source debug --config "{{ .SLEET_CONFIG_PATH }}" --force
+ - sleet push "{{ .PACK_OUT }}/release/" --source release --config "{{ .SLEET_CONFIG_PATH }}" --force
test:
+ desc: "Runs managed tests against the entire solution and all loaded test projects"
+ vars:
+ RPMALLOC_LIB_PATH: '{{ .USER_WORKING_DIR }}/lib/Utils.Memory/vnlib_rpmalloc/build/Debug/vnlib_rpmalloc'
+ MIMALLOC_LIB_PATH: '{{ .USER_WORKING_DIR }}/lib/Utils.Memory/vnlib_mimalloc/build/Debug/vnlib_mimalloc'
cmds:
- - cmd: dotnet test --verbosity normal
+ - cmd: echo "Ensure you have run 'task dev-init' before running tests to build native libraries"
+ silent: true
+ - cmd: dotnet test
+ {{ .CLI_ARGS }}
+ --verbosity normal
+ --framework {{ .FRAMEWORK | default "net8.0" }}
+ --environment VNLIB_SHARED_HEAP_DIAGNOSTICS="1"
+ --environment TEST_RPMALLOC_LIB_PATH="{{ .RPMALLOC_LIB_PATH }}"
+ --environment TEST_MIMALLOC_LIB_PATH="{{ .MIMALLOC_LIB_PATH }}"
+
#called by build pipeline to clean module
clean:
@@ -72,12 +98,12 @@ tasks:
build_debug:
internal: true
cmds:
- - dotnet publish -c debug {{.MS_ARGS}}
- - dotnet pack -c debug {{.MS_ARGS}} -o "{{.PACK_OUT}}/debug/" -p:PackageVersion={{.BUILD_VERSION}}
+ - dotnet publish -c debug {{ .MS_ARGS }}
+ - dotnet pack -c debug {{ .MS_ARGS }} -o "{{ .PACK_OUT }}/debug/" -p:PackageVersion={{ .BUILD_VERSION }}
build_release:
internal: true
cmds:
- - dotnet publish -c release {{.MS_ARGS}}
- - dotnet pack -c release {{.MS_ARGS}} -o "{{.PACK_OUT}}/release/" -p:PackageVersion={{.BUILD_VERSION}}
+ - dotnet publish -c release {{ .MS_ARGS }}
+ - dotnet pack -c release {{ .MS_ARGS }} -o "{{ .PACK_OUT }}/release/" -p:PackageVersion={{ .BUILD_VERSION }}
\ No newline at end of file
diff --git a/lib/Plugins.Essentials/src/EventProcessor.cs b/lib/Plugins.Essentials/src/EventProcessor.cs
index 908ad07..c3082a1 100644
--- a/lib/Plugins.Essentials/src/EventProcessor.cs
+++ b/lib/Plugins.Essentials/src/EventProcessor.cs
@@ -416,8 +416,12 @@ namespace VNLib.Plugins.Essentials
//set last modified time as the files last write time
entity.Server.LastModified(fileLastModified);
+
//Open the file handle directly, reading will always be sequentially read and async
+
+#pragma warning disable CA2000 // Dispose objects before losing scope
DirectFileStream dfs = DirectFileStream.Open(filename);
+#pragma warning restore CA2000 // Dispose objects before losing scope
long endOffset = checked((long)entity.Server.Range.End);
long startOffset = checked((long)entity.Server.Range.Start);
diff --git a/lib/Utils/src/ERRNO.cs b/lib/Utils/src/ERRNO.cs
index 684a3c7..0a95780 100644
--- a/lib/Utils/src/ERRNO.cs
+++ b/lib/Utils/src/ERRNO.cs
@@ -30,8 +30,12 @@ namespace VNLib.Utils
/// <summary>
/// Implements a C style integer error code type. Size is platform dependent
/// </summary>
+ /// <remarks>
+ /// Creates a new <see cref="ERRNO"/> from the specified error value
+ /// </remarks>
+ /// <param name="errno">The value of the error to represent</param>
[StructLayout(LayoutKind.Sequential)]
- public readonly struct ERRNO : IEquatable<ERRNO>, ISpanFormattable, IFormattable
+ public readonly struct ERRNO(nint errno) : IEquatable<ERRNO>, ISpanFormattable, IFormattable
{
/// <summary>
/// Represents a successfull error code (true)
@@ -43,13 +47,7 @@ namespace VNLib.Utils
/// </summary>
public static readonly ERRNO E_FAIL = false;
- private readonly nint ErrorCode;
-
- /// <summary>
- /// Creates a new <see cref="ERRNO"/> from the specified error value
- /// </summary>
- /// <param name="errno">The value of the error to represent</param>
- public ERRNO(nint errno) => ErrorCode = errno;
+ private readonly nint ErrorCode = errno;
/// <summary>
/// Creates a new <see cref="ERRNO"/> from an <see cref="int"/> error code. null = 0 = false
@@ -130,13 +128,14 @@ namespace VNLib.Utils
}
return false;
}
+#pragma warning disable CA1305 // Specify IFormatProvider
/// <summary>
/// The integer error value of the current instance in radix 10
/// </summary>
/// <returns>The radix 10 formatted error code</returns>
- public readonly override string ToString() => ErrorCode.ToString();
+ public override readonly string ToString() => ErrorCode.ToString();
/// <summary>
/// Formats the internal nint error code as a string in specified format
/// </summary>
@@ -144,11 +143,15 @@ namespace VNLib.Utils
/// <returns>The formatted error code</returns>
public readonly string ToString(string format) => ErrorCode.ToString(format);
+#pragma warning restore CA1305 // Specify IFormatProvider
+
///<inheritdoc/>
- public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider) => ErrorCode.TryFormat(destination, out charsWritten, format, provider);
+ public readonly bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan<char> format, IFormatProvider? provider)
+ => ErrorCode.TryFormat(destination, out charsWritten, format, provider);
///<inheritdoc/>
- public readonly string ToString(string? format, IFormatProvider? formatProvider) => ErrorCode.ToString(format, formatProvider);
+ public readonly string ToString(string? format, IFormatProvider? formatProvider)
+ => ErrorCode.ToString(format, formatProvider);
public static ERRNO operator +(ERRNO err, int add) => new(err.ErrorCode + add);
public static ERRNO operator +(ERRNO err, nint add) => new(err.ErrorCode + add);
diff --git a/lib/Utils/src/Memory/MemoryUtil.cs b/lib/Utils/src/Memory/MemoryUtil.cs
index 2ef9c24..cbaaa2f 100644
--- a/lib/Utils/src/Memory/MemoryUtil.cs
+++ b/lib/Utils/src/Memory/MemoryUtil.cs
@@ -604,7 +604,8 @@ namespace VNLib.Utils.Memory
/// <param name="target">A reference to the first byte of the memory location to copy the struct data to</param>
/// <exception cref="ArgumentNullException"></exception>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
- public static void CopyStruct<T>(void* source, ref byte target) where T : unmanaged => CopyStruct((T*)source, ref target);
+ public static void CopyStruct<T>(void* source, ref byte target) where T : unmanaged
+ => CopyStruct((T*)source, ref target);
/// <summary>
/// Copies the memory of the structure pointed to by the source pointer to the target
diff --git a/lib/Utils/tests/.runsettings b/lib/Utils/tests/.runsettings
index 0e7a703..b13ddb7 100644
--- a/lib/Utils/tests/.runsettings
+++ b/lib/Utils/tests/.runsettings
@@ -3,6 +3,9 @@
<RunConfiguration>
<EnvironmentVariables>
<VNLIB_SHARED_HEAP_DIAGNOSTICS>1</VNLIB_SHARED_HEAP_DIAGNOSTICS>
+ <TEST_RPMALLOC_LIB_PATH>../../../../../Utils.Memory/vnlib_rpmalloc/build/Debug/vnlib_rpmalloc.dll</TEST_RPMALLOC_LIB_PATH>
+ <TEST_MIMALLOC_LIB_PATH>../../../../../Utils.Memory/vnlib_mimalloc/build/Debug/vnlib_mimalloc.dll</TEST_MIMALLOC_LIB_PATH>
+
</EnvironmentVariables>
</RunConfiguration>
</RunSettings> \ No newline at end of file
diff --git a/lib/Utils/tests/IO/VnMemoryStreamTests.cs b/lib/Utils/tests/IO/VnMemoryStreamTests.cs
index 9bcb823..6bbf328 100644
--- a/lib/Utils/tests/IO/VnMemoryStreamTests.cs
+++ b/lib/Utils/tests/IO/VnMemoryStreamTests.cs
@@ -47,8 +47,11 @@ namespace VNLib.Utils.IO.Tests
Assert.IsTrue(vms.CanWrite == true);
}
+ //Handle should throw since the stream owns the handle and it gets dispoed
+ Assert.ThrowsException<ObjectDisposedException>(handle.ThrowIfClosed);
+
//From existing data
- ReadOnlySpan<byte> testSpan = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
+ ReadOnlySpan<byte> testSpan = [1, 2, 3, 4, 5, 6, 7, 8];
using (VnMemoryStream vms = new (privateHeap, testSpan))
{
Assert.IsTrue(vms.Length == testSpan.Length);
@@ -125,19 +128,13 @@ namespace VNLib.Utils.IO.Tests
ReadOnlyMemory<byte> memory = vms.AsMemory();
Assert.AreEqual(memory.Length, testData.Length);
- for (int i = 0; i < memory.Length; i++)
- {
- Assert.AreEqual(memory.Span[i], testData[i]);
- }
+ Assert.IsTrue(memory.Span.SequenceEqual(testData));
//Get the data as a byte array
byte[] array = vms.ToArray();
Assert.AreEqual(array.Length, testData.Length);
- for (int i = 0; i < array.Length; i++)
- {
- Assert.AreEqual(array[i], testData[i]);
- }
+ Assert.IsTrue(array.AsSpan().SequenceEqual(testData));
}
}
} \ No newline at end of file
diff --git a/lib/Utils/tests/Memory/NativeHeapTests.cs b/lib/Utils/tests/Memory/NativeHeapTests.cs
index 8653bd0..a7072ed 100644
--- a/lib/Utils/tests/Memory/NativeHeapTests.cs
+++ b/lib/Utils/tests/Memory/NativeHeapTests.cs
@@ -1,20 +1,22 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
+using System.Runtime.InteropServices;
namespace VNLib.Utils.Memory.Tests
{
[TestClass()]
public class NativeHeapTests
{
- const string RpMallocLibPath = "../../../../../Utils.Memory/vnlib_rpmalloc/build/Debug/vnlib_rpmalloc.dll";
- const string MimallocLibPath = "../../../../../Utils.Memory/vnlib_mimalloc/build/Debug/vnlib_mimalloc.dll";
+ private static string? RpMallocLibPath => Environment.GetEnvironmentVariable("TEST_RPMALLOC_LIB_PATH");
+
+ private static string? MimallocLibPath => Environment.GetEnvironmentVariable("TEST_MIMALLOC_LIB_PATH");
[TestMethod()]
public void LoadInTreeRpmallocTest()
{
//Try to load the shared heap
- using NativeHeap heap = NativeHeap.LoadHeap(RpMallocLibPath, System.Runtime.InteropServices.DllImportSearchPath.SafeDirectories, HeapCreation.Shared, 0);
+ using NativeHeap heap = NativeHeap.LoadHeap(RpMallocLibPath, DllImportSearchPath.SafeDirectories, HeapCreation.Shared, flags: 0);
Assert.IsFalse(heap.IsInvalid);
@@ -36,7 +38,7 @@ namespace VNLib.Utils.Memory.Tests
public void LoadInTreeMimallocTest()
{
//Try to load the shared heap
- using NativeHeap heap = NativeHeap.LoadHeap(MimallocLibPath, System.Runtime.InteropServices.DllImportSearchPath.SafeDirectories, HeapCreation.Shared, 0);
+ using NativeHeap heap = NativeHeap.LoadHeap(MimallocLibPath, DllImportSearchPath.SafeDirectories, HeapCreation.Shared, flags: 0);
Assert.IsFalse(heap.IsInvalid);