Skip to content

Commit 3a55917

Browse files
mjr4077auDanGough
authored andcommitted
Supply of SMBIOS parsing code for SMBIOS types 0, 1, and 3 (the useful ones).
1 parent f09cf22 commit 3a55917

48 files changed

Lines changed: 5599 additions & 63 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (C) 2025 Devicie Pty Ltd. All rights reserved.
3+
*
4+
* This file is part of PSAppDeployToolkit.
5+
*
6+
* PSAppDeployToolkit is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation, either version 3
9+
* of the License, or (at your option) any later version.
10+
*
11+
* PSAppDeployToolkit is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
*
15+
* See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PSAppDeployToolkit. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
using PSADT.SMBIOS;
22+
using Xunit;
23+
24+
namespace PSADT.Tests.SMBIOS
25+
{
26+
/// <summary>
27+
/// Contains unit tests that verify the values of the BaseboardType enumeration against their expected byte
28+
/// representations.
29+
/// </summary>
30+
/// <remarks>Use this test class to ensure that changes to the BaseboardType enumeration do not introduce
31+
/// breaking changes to its underlying values. Failing tests may indicate that the enumeration no longer conforms to
32+
/// its intended specification.</remarks>
33+
public sealed class BaseboardTypeTests
34+
{
35+
/// <summary>
36+
/// Verifies that each value of the BaseboardType enumeration matches its expected byte representation.
37+
/// </summary>
38+
/// <remarks>This test ensures that the underlying byte values assigned to each BaseboardType
39+
/// enumeration member conform to the specification. Changes to the enumeration values may cause this test to
40+
/// fail, indicating a breaking change in the enum's definition.</remarks>
41+
[Fact]
42+
public void EnumValues_MatchSpecification()
43+
{
44+
Assert.Equal<byte>(0x01, (byte)BaseboardType.Unknown);
45+
Assert.Equal<byte>(0x02, (byte)BaseboardType.Other);
46+
Assert.Equal<byte>(0x03, (byte)BaseboardType.ServerBlade);
47+
Assert.Equal<byte>(0x04, (byte)BaseboardType.ConnectivitySwitch);
48+
Assert.Equal<byte>(0x05, (byte)BaseboardType.SystemManagementModule);
49+
Assert.Equal<byte>(0x06, (byte)BaseboardType.ProcessorModule);
50+
Assert.Equal<byte>(0x07, (byte)BaseboardType.IoModule);
51+
Assert.Equal<byte>(0x08, (byte)BaseboardType.MemoryModule);
52+
Assert.Equal<byte>(0x09, (byte)BaseboardType.DaughterBoard);
53+
Assert.Equal<byte>(0x0A, (byte)BaseboardType.Motherboard);
54+
Assert.Equal<byte>(0x0B, (byte)BaseboardType.ProcessorMemoryModule);
55+
Assert.Equal<byte>(0x0C, (byte)BaseboardType.ProcessorIoModule);
56+
Assert.Equal<byte>(0x0D, (byte)BaseboardType.InterconnectBoard);
57+
}
58+
}
59+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
/*
2+
* Copyright (C) 2025 Devicie Pty Ltd. All rights reserved.
3+
*
4+
* This file is part of PSAppDeployToolkit.
5+
*
6+
* PSAppDeployToolkit is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation, either version 3
9+
* of the License, or (at your option) any later version.
10+
*
11+
* PSAppDeployToolkit is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
*
15+
* See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PSAppDeployToolkit. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
using PSADT.SMBIOS;
22+
using Xunit;
23+
24+
namespace PSADT.Tests.SMBIOS
25+
{
26+
/// <summary>
27+
/// Contains unit tests for the BiosExtendedRomSize struct, verifying the correctness of its properties and
28+
/// behavior.
29+
/// </summary>
30+
/// <remarks>This class includes both individual and parameterized tests to ensure that the
31+
/// BiosExtendedRomSize struct correctly interprets raw BIOS ROM size values and exposes accurate property values.
32+
/// The tests use representative sample data to validate expected outcomes for various BIOS ROM
33+
/// configurations.</remarks>
34+
public sealed class BiosExtendedRomSizeTests
35+
{
36+
/// <summary>
37+
/// Verifies that the Size property of the BiosExtendedRomSize struct returns the value of the lower fourteen
38+
/// bits of the underlying ushort.
39+
/// </summary>
40+
/// <remarks>This test ensures that only the least significant fourteen bits are considered when
41+
/// retrieving the Size value, regardless of the higher bits in the input.</remarks>
42+
[Fact]
43+
public void Size_ReturnsLowerFourteenBits()
44+
{
45+
BiosExtendedRomSize size = new(unchecked((ushort)0b01_0011001100110011));
46+
Assert.Equal(0b0011001100110011 & 0x3FFF, size.Size);
47+
}
48+
49+
/// <summary>
50+
/// Verifies that the properties of a BiosExtendedRomSize instance return the expected values for the given
51+
/// input parameters.
52+
/// </summary>
53+
/// <remarks>This is a parameterized unit test that uses data from SampleData to validate the
54+
/// behavior of the BiosExtendedRomSize properties.</remarks>
55+
/// <param name="raw">The raw ushort value used to construct the BiosExtendedRomSize instance.</param>
56+
/// <param name="expectedUnitValue">The expected unit value, as a byte, to compare against the Unit property of the instance.</param>
57+
/// <param name="expectedRecognized">The expected value indicating whether the unit is recognized, to compare against the IsUnitRecognized
58+
/// property.</param>
59+
/// <param name="expectedBytes">The expected number of bytes, or null if not applicable, to compare against the Bytes property.</param>
60+
[Theory]
61+
[MemberData(nameof(SampleData))]
62+
public void Properties_ReturnExpectedValues(ushort raw, byte expectedUnitValue, bool expectedRecognized, ulong? expectedBytes)
63+
{
64+
BiosExtendedRomSize value = new(raw);
65+
BiosRomUnit expectedUnit = (BiosRomUnit)expectedUnitValue;
66+
Assert.Equal(raw, value.Raw);
67+
Assert.Equal(expectedUnit, value.Unit);
68+
Assert.Equal(expectedRecognized, value.IsUnitRecognized);
69+
Assert.Equal(expectedBytes, value.Bytes);
70+
}
71+
72+
/// <summary>
73+
/// Gets a collection of sample BIOS ROM data sets for use in parameterized unit tests.
74+
/// </summary>
75+
/// <remarks>Each data set consists of a 16-bit identifier, a unit value as a byte, a flag
76+
/// indicating validity, and an optional ROM size in bytes. This property is intended to support test scenarios
77+
/// that require representative BIOS ROM configurations.</remarks>
78+
public static TheoryData<ushort, byte, bool, ulong?> SampleData { get; } = new()
79+
{
80+
{ 0x0002, (byte)BiosRomUnit.MB, true, 2UL * 1024 * 1024 },
81+
{ 0x4003, (byte)BiosRomUnit.GB, true, 3UL * 1024 * 1024 * 1024 },
82+
};
83+
}
84+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright (C) 2025 Devicie Pty Ltd. All rights reserved.
3+
*
4+
* This file is part of PSAppDeployToolkit.
5+
*
6+
* PSAppDeployToolkit is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation, either version 3
9+
* of the License, or (at your option) any later version.
10+
*
11+
* PSAppDeployToolkit is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
*
15+
* See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PSAppDeployToolkit. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
using PSADT.SMBIOS;
22+
using Xunit;
23+
24+
namespace PSADT.Tests.SMBIOS
25+
{
26+
/// <summary>
27+
/// Contains unit tests for verifying the correctness and stability of the BiosRomUnit enumeration values.
28+
/// </summary>
29+
/// <remarks>Use this test class to ensure that changes to the BiosRomUnit enumeration do not
30+
/// inadvertently alter the assigned byte values, which may impact serialization, interoperability, or dependent
31+
/// components.</remarks>
32+
public sealed class BiosRomUnitTests
33+
{
34+
/// <summary>
35+
/// Verifies that the underlying byte values of the BiosRomUnit enumeration members match the expected
36+
/// specification.
37+
/// </summary>
38+
/// <remarks>This test ensures that the values assigned to BiosRomUnit.MB and BiosRomUnit.GB
39+
/// remain consistent with their intended specification. Changes to these values may affect serialization,
40+
/// interoperability, or other components that depend on the exact numeric values of the enumeration.</remarks>
41+
[Fact]
42+
public void EnumValues_MatchSpecification()
43+
{
44+
Assert.Equal(0, (byte)BiosRomUnit.MB);
45+
Assert.Equal(1, (byte)BiosRomUnit.GB);
46+
}
47+
}
48+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (C) 2025 Devicie Pty Ltd. All rights reserved.
3+
*
4+
* This file is part of PSAppDeployToolkit.
5+
*
6+
* PSAppDeployToolkit is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation, either version 3
9+
* of the License, or (at your option) any later version.
10+
*
11+
* PSAppDeployToolkit is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
*
15+
* See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PSAppDeployToolkit. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
using PSADT.SMBIOS;
22+
using Xunit;
23+
24+
namespace PSADT.Tests.SMBIOS
25+
{
26+
/// <summary>
27+
/// Contains unit tests for verifying the values and behavior of the ChassisSecurityStatus enumeration.
28+
/// </summary>
29+
/// <remarks>This class is intended to ensure that the ChassisSecurityStatus enum remains consistent with
30+
/// protocol specifications. It is typically used in automated test suites to detect unintended changes to the
31+
/// enum's assigned values.</remarks>
32+
public sealed class ChassisSecurityStatusTests
33+
{
34+
/// <summary>
35+
/// Verifies that the byte values of the ChassisSecurityStatus enumeration members match the expected
36+
/// specification.
37+
/// </summary>
38+
/// <remarks>This test ensures that changes to the ChassisSecurityStatus enum do not alter the
39+
/// assigned byte values, which may be required for protocol compatibility or serialization.</remarks>
40+
[Fact]
41+
public void EnumValues_MatchSpecification()
42+
{
43+
Assert.Equal<byte>(0x01, (byte)ChassisSecurityStatus.Other);
44+
Assert.Equal<byte>(0x02, (byte)ChassisSecurityStatus.Unknown);
45+
Assert.Equal<byte>(0x03, (byte)ChassisSecurityStatus.None);
46+
Assert.Equal<byte>(0x04, (byte)ChassisSecurityStatus.ExternalInterfaceLockedOut);
47+
Assert.Equal<byte>(0x05, (byte)ChassisSecurityStatus.ExternalInterfaceEnabled);
48+
}
49+
}
50+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (C) 2025 Devicie Pty Ltd. All rights reserved.
3+
*
4+
* This file is part of PSAppDeployToolkit.
5+
*
6+
* PSAppDeployToolkit is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation, either version 3
9+
* of the License, or (at your option) any later version.
10+
*
11+
* PSAppDeployToolkit is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
*
15+
* See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PSAppDeployToolkit. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
using PSADT.SMBIOS;
22+
using Xunit;
23+
24+
namespace PSADT.Tests.SMBIOS
25+
{
26+
/// <summary>
27+
/// Contains unit tests for verifying the values and behavior of the ChassisState enumeration.
28+
/// </summary>
29+
/// <remarks>Use this test class to ensure that changes to the ChassisState enumeration do not break
30+
/// protocol compatibility or serialization requirements by altering the defined byte values. Update the tests if
31+
/// the specification for ChassisState values changes.</remarks>
32+
public sealed class ChassisStateTests
33+
{
34+
/// <summary>
35+
/// Verifies that the underlying byte values of the ChassisState enumeration members match the expected
36+
/// specification.
37+
/// </summary>
38+
/// <remarks>This test ensures that changes to the ChassisState enumeration do not alter the
39+
/// defined byte values, which may be required for protocol compatibility or serialization. Update this test if
40+
/// the specification for ChassisState values changes.</remarks>
41+
[Fact]
42+
public void EnumValues_MatchSpecification()
43+
{
44+
Assert.Equal<byte>(0x01, (byte)ChassisState.Other);
45+
Assert.Equal<byte>(0x02, (byte)ChassisState.Unknown);
46+
Assert.Equal<byte>(0x03, (byte)ChassisState.Safe);
47+
Assert.Equal<byte>(0x04, (byte)ChassisState.Warning);
48+
Assert.Equal<byte>(0x05, (byte)ChassisState.Critical);
49+
Assert.Equal<byte>(0x06, (byte)ChassisState.NonRecoverable);
50+
}
51+
}
52+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (C) 2025 Devicie Pty Ltd. All rights reserved.
3+
*
4+
* This file is part of PSAppDeployToolkit.
5+
*
6+
* PSAppDeployToolkit is free software: you can redistribute it and/or
7+
* modify it under the terms of the GNU Lesser General Public License
8+
* as published by the Free Software Foundation, either version 3
9+
* of the License, or (at your option) any later version.
10+
*
11+
* PSAppDeployToolkit is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14+
*
15+
* See the GNU Lesser General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU Lesser General Public License
18+
* along with PSAppDeployToolkit. If not, see <https://www.gnu.org/licenses/>.
19+
*/
20+
21+
using PSADT.SMBIOS;
22+
using Xunit;
23+
24+
namespace PSADT.Tests.SMBIOS
25+
{
26+
/// <summary>
27+
/// Contains unit tests that verify the values of the ChassisType enumeration conform to the expected specification.
28+
/// </summary>
29+
/// <remarks>Use this test class to ensure that any changes to the ChassisType enum do not inadvertently
30+
/// alter the assigned byte values. This helps maintain compatibility with external systems or standards that rely
31+
/// on specific enumeration values.</remarks>
32+
public sealed class ChassisTypeTests
33+
{
34+
/// <summary>
35+
/// Verifies that each value of the ChassisType enumeration matches its expected byte value as specified by the
36+
/// standard.
37+
/// </summary>
38+
/// <remarks>This test ensures that the underlying byte values of all ChassisType enum members
39+
/// conform to the documented specification. If the enum definitions are modified or regenerated, this test will
40+
/// detect any unintended changes to their assigned values.</remarks>
41+
[Fact]
42+
public void EnumValues_MatchSpecification()
43+
{
44+
Assert.Equal<byte>(0x01, (byte)ChassisType.Other);
45+
Assert.Equal<byte>(0x02, (byte)ChassisType.Unknown);
46+
Assert.Equal<byte>(0x03, (byte)ChassisType.Desktop);
47+
Assert.Equal<byte>(0x04, (byte)ChassisType.LowProfileDesktop);
48+
Assert.Equal<byte>(0x05, (byte)ChassisType.PizzaBox);
49+
Assert.Equal<byte>(0x06, (byte)ChassisType.MiniTower);
50+
Assert.Equal<byte>(0x07, (byte)ChassisType.Tower);
51+
Assert.Equal<byte>(0x08, (byte)ChassisType.Portable);
52+
Assert.Equal<byte>(0x09, (byte)ChassisType.Laptop);
53+
Assert.Equal<byte>(0x0A, (byte)ChassisType.Notebook);
54+
Assert.Equal<byte>(0x0B, (byte)ChassisType.HandHeld);
55+
Assert.Equal<byte>(0x0C, (byte)ChassisType.DockingStation);
56+
Assert.Equal<byte>(0x0D, (byte)ChassisType.AllInOne);
57+
Assert.Equal<byte>(0x0E, (byte)ChassisType.SubNotebook);
58+
Assert.Equal<byte>(0x0F, (byte)ChassisType.SpaceSaving);
59+
Assert.Equal<byte>(0x10, (byte)ChassisType.LunchBox);
60+
Assert.Equal<byte>(0x11, (byte)ChassisType.MainServerChassis);
61+
Assert.Equal<byte>(0x12, (byte)ChassisType.ExpansionChassis);
62+
Assert.Equal<byte>(0x13, (byte)ChassisType.SubChassis);
63+
Assert.Equal<byte>(0x14, (byte)ChassisType.BusExpansionChassis);
64+
Assert.Equal<byte>(0x15, (byte)ChassisType.PeripheralChassis);
65+
Assert.Equal<byte>(0x16, (byte)ChassisType.RaidChassis);
66+
Assert.Equal<byte>(0x17, (byte)ChassisType.RackMountChassis);
67+
Assert.Equal<byte>(0x18, (byte)ChassisType.SealedCasePc);
68+
Assert.Equal<byte>(0x19, (byte)ChassisType.MultiSystemChassis);
69+
Assert.Equal<byte>(0x1A, (byte)ChassisType.CompactPci);
70+
Assert.Equal<byte>(0x1B, (byte)ChassisType.AdvancedTca);
71+
Assert.Equal<byte>(0x1C, (byte)ChassisType.Blade);
72+
Assert.Equal<byte>(0x1D, (byte)ChassisType.BladeEnclosure);
73+
Assert.Equal<byte>(0x1E, (byte)ChassisType.Tablet);
74+
Assert.Equal<byte>(0x1F, (byte)ChassisType.Convertible);
75+
Assert.Equal<byte>(0x20, (byte)ChassisType.Detachable);
76+
Assert.Equal<byte>(0x21, (byte)ChassisType.IoTGateway);
77+
Assert.Equal<byte>(0x22, (byte)ChassisType.EmbeddedPc);
78+
Assert.Equal<byte>(0x23, (byte)ChassisType.MiniPc);
79+
Assert.Equal<byte>(0x24, (byte)ChassisType.StickPc);
80+
}
81+
}
82+
}

0 commit comments

Comments
 (0)