Skip to content

Commit 7d9cd5b

Browse files
committed
Supply of SMBIOS parsing code for SMBIOS types 0, 1, and 3 (the useful ones).
1 parent 31694f3 commit 7d9cd5b

48 files changed

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

0 commit comments

Comments
 (0)