-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeroMemoryTests.cs
More file actions
47 lines (42 loc) · 1.65 KB
/
ZeroMemoryTests.cs
File metadata and controls
47 lines (42 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using Xunit;
namespace Platform.Unsafe.Tests
{
public static unsafe class ZeroMemoryTests
{
[Fact]
public static void ZeroMemoryTest()
{
var bytes = new byte[1024];
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = unchecked((byte)i);
}
fixed (byte* pointer = bytes)
{
MemoryBlock.Zero(pointer, bytes.Length);
}
for (int i = 0; i < bytes.Length; i++)
{
Assert.Equal(0, bytes[i]);
}
}
[Fact]
public static void PhysicalCoreCountTest()
{
// Test that physical core count is reasonable
var physicalCores = MemoryBlock.PhysicalCoreCount;
var logicalProcessors = Environment.ProcessorCount;
// Physical cores should be at least 1
Assert.True(physicalCores >= 1, $"Physical cores should be at least 1, got {physicalCores}");
// Physical cores should not exceed logical processors
Assert.True(physicalCores <= logicalProcessors,
$"Physical cores ({physicalCores}) should not exceed logical processors ({logicalProcessors})");
// On most systems, physical cores should be at least half of logical processors
// (allowing for hyper-threading)
var expectedMinimum = Math.Max(1, logicalProcessors / 2);
Assert.True(physicalCores >= expectedMinimum,
$"Physical cores ({physicalCores}) should be at least {expectedMinimum}");
}
}
}