https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b851d7e1d3775e7c080d2…
commit b851d7e1d3775e7c080d2e7c9e2d3f9d71142605
Author: Stanislav Motylkov <x86corez(a)gmail.com>
AuthorDate: Sun Aug 5 11:38:20 2018 +0300
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Sun Aug 19 20:27:59 2018 +0200
[KERNEL32_APITEST] Add SystemFirmwareTableInformation tests
Thanks goes to Mark Jansen for help!
---
.../rostests/apitests/kernel32/SystemFirmware.c | 123 +++++++++++++++++----
modules/rostests/apitests/kernel32/precomp.h | 3 +
2 files changed, 103 insertions(+), 23 deletions(-)
diff --git a/modules/rostests/apitests/kernel32/SystemFirmware.c
b/modules/rostests/apitests/kernel32/SystemFirmware.c
index 5ba946d815..c052761b45 100644
--- a/modules/rostests/apitests/kernel32/SystemFirmware.c
+++ b/modules/rostests/apitests/kernel32/SystemFirmware.c
@@ -3,6 +3,7 @@
* LICENSE: GPL-2.0+ (
https://spdx.org/licenses/GPL-2.0+)
* PURPOSE: Tests for System Firmware functions
* COPYRIGHT: Copyright 2018 Stanislav Motylkov
+ * Copyright 2018 Mark Jansen
*/
#include "precomp.h"
@@ -17,6 +18,70 @@ typedef struct ENTRY
DWORD ErrSuccess;
} ENTRY;
+static UINT
+CallNt(IN DWORD FirmwareTableProviderSignature,
+ IN DWORD FirmwareTableID,
+ OUT PVOID pFirmwareTableBuffer,
+ IN DWORD BufferSize,
+ IN SYSTEM_FIRMWARE_TABLE_ACTION Action)
+{
+ SYSTEM_FIRMWARE_TABLE_INFORMATION* SysFirmwareInfo;
+ ULONG Result = 0, ReturnedSize;
+ ULONG TotalSize = BufferSize + sizeof(SYSTEM_FIRMWARE_TABLE_INFORMATION);
+ NTSTATUS Status;
+
+ SysFirmwareInfo = RtlAllocateHeap(RtlGetProcessHeap(), HEAP_ZERO_MEMORY, TotalSize);
+ if (!SysFirmwareInfo)
+ {
+ SetLastError(ERROR_INVALID_PARAMETER);
+ return 0;
+ }
+ _SEH2_TRY
+ {
+ SysFirmwareInfo->ProviderSignature = FirmwareTableProviderSignature;
+ SysFirmwareInfo->TableID = FirmwareTableID;
+ SysFirmwareInfo->Action = Action;
+ SysFirmwareInfo->TableBufferLength = BufferSize;
+
+ Status = NtQuerySystemInformation(SystemFirmwareTableInformation,
SysFirmwareInfo, TotalSize, &ReturnedSize);
+
+ if (NT_SUCCESS(Status) || Status == STATUS_BUFFER_TOO_SMALL)
+ Result = SysFirmwareInfo->TableBufferLength;
+
+ if (NT_SUCCESS(Status) && pFirmwareTableBuffer)
+ {
+ memcpy(pFirmwareTableBuffer, SysFirmwareInfo->TableBuffer,
SysFirmwareInfo->TableBufferLength);
+ }
+ }
+ _SEH2_FINALLY
+ {
+ RtlFreeHeap(RtlGetProcessHeap(), 0, SysFirmwareInfo);
+ }
+ _SEH2_END;
+
+ SetLastError(RtlNtStatusToDosError(Status));
+ return Result;
+}
+
+UINT
+WINAPI
+fEnumSystemFirmwareTables(IN DWORD FirmwareTableProviderSignature,
+ OUT PVOID pFirmwareTableBuffer,
+ IN DWORD BufferSize)
+{
+ return CallNt(FirmwareTableProviderSignature, 0, pFirmwareTableBuffer, BufferSize,
SystemFirmwareTable_Enumerate);
+}
+
+UINT
+WINAPI
+fGetSystemFirmwareTable(IN DWORD FirmwareTableProviderSignature,
+ IN DWORD FirmwareTableID,
+ OUT PVOID pFirmwareTableBuffer,
+ IN DWORD BufferSize)
+{
+ return CallNt(FirmwareTableProviderSignature, FirmwareTableID, pFirmwareTableBuffer,
BufferSize, SystemFirmwareTable_Get);
+}
+
static
VOID
test_EnumBuffer(
@@ -378,7 +443,9 @@ test_GetBuffer(
}
}
-START_TEST(SystemFirmware)
+static
+VOID
+test_Functions()
{
static const ENTRY Entries[] =
{
@@ -388,34 +455,12 @@ START_TEST(SystemFirmware)
/* This entry should be last */
{ 0xDEAD, ERROR_INVALID_FUNCTION, ERROR_INVALID_FUNCTION },
};
- HANDLE hKernel;
CHAR Buffer[262144]; // 256 KiB should be enough
CHAR Sign[sizeof(DWORD) + 1];
UINT TableCount[_countof(Entries)];
DWORD FirstTableID[_countof(Entries)];
int i;
- hKernel = GetModuleHandleW(L"kernel32.dll");
- if (!hKernel)
- {
- skip("kernel32.dll module not found. Can't proceed\n");
- return;
- }
-
- pEnumSystemFirmwareTables = (void *)GetProcAddress(hKernel,
"EnumSystemFirmwareTables");
- pGetSystemFirmwareTable = (void *)GetProcAddress(hKernel,
"GetSystemFirmwareTable");
-
- if (!pEnumSystemFirmwareTables)
- {
- skip("EnumSystemFirmwareTables not found. Can't proceed\n");
- return;
- }
- if (!pGetSystemFirmwareTable)
- {
- skip("GetSystemFirmwareTable not found. Can't proceed\n");
- return;
- }
-
// Test EnumSystemFirmwareTables
for (i = 0; i < _countof(Entries); i++)
{
@@ -464,3 +509,35 @@ START_TEST(SystemFirmware)
FALSE, Entries[i].ErrInsuff, Entries[i].ErrSuccess);
}
}
+
+START_TEST(SystemFirmware)
+{
+ HANDLE hKernel;
+
+ hKernel = GetModuleHandleW(L"kernel32.dll");
+ if (!hKernel)
+ {
+ skip("kernel32.dll module not found. Can't proceed\n");
+ return;
+ }
+
+ pEnumSystemFirmwareTables = (void *)fEnumSystemFirmwareTables;
+ pGetSystemFirmwareTable = (void *)fGetSystemFirmwareTable;
+
+ test_Functions();
+
+ pEnumSystemFirmwareTables = (void *)GetProcAddress(hKernel,
"EnumSystemFirmwareTables");
+ pGetSystemFirmwareTable = (void *)GetProcAddress(hKernel,
"GetSystemFirmwareTable");
+
+ if (!pEnumSystemFirmwareTables)
+ {
+ skip("EnumSystemFirmwareTables not found. Can't proceed\n");
+ return;
+ }
+ if (!pGetSystemFirmwareTable)
+ {
+ skip("GetSystemFirmwareTable not found. Can't proceed\n");
+ return;
+ }
+ test_Functions();
+}
diff --git a/modules/rostests/apitests/kernel32/precomp.h
b/modules/rostests/apitests/kernel32/precomp.h
index ffbf218a93..b356a2d117 100644
--- a/modules/rostests/apitests/kernel32/precomp.h
+++ b/modules/rostests/apitests/kernel32/precomp.h
@@ -11,5 +11,8 @@
#include <winreg.h>
#include <strsafe.h>
#include <ndk/umtypes.h>
+#include <ndk/extypes.h>
+#include <ndk/exfuncs.h>
+#include <ndk/rtlfuncs.h>
#endif /* _KERNEL32_APITEST_PRECOMP_H_ */