https://git.reactos.org/?p=reactos.git;a=commitdiff;h=b922b6d7fc9cd8988d62a…
commit b922b6d7fc9cd8988d62a32e2c62decdde8ec901
Author: George Bișoc <george.bisoc(a)reactos.org>
AuthorDate: Tue Jan 25 13:20:05 2022 +0100
Commit: George Bișoc <george.bisoc(a)reactos.org>
CommitDate: Tue May 24 18:39:46 2022 +0200
[NTOS:KE] Write a basic kernel mode test for FPU Save/Restore mechanism
---
modules/rostests/kmtests/CMakeLists.txt | 1 +
modules/rostests/kmtests/kmtest_drv/testlist.c | 2 +
.../rostests/kmtests/ntos_ke/KeFloatPointState.c | 47 ++++++++++++++++++++++
3 files changed, 50 insertions(+)
diff --git a/modules/rostests/kmtests/CMakeLists.txt
b/modules/rostests/kmtests/CMakeLists.txt
index 588dd3d74c9..3561248f6eb 100644
--- a/modules/rostests/kmtests/CMakeLists.txt
+++ b/modules/rostests/kmtests/CMakeLists.txt
@@ -74,6 +74,7 @@ list(APPEND KMTEST_DRV_SOURCE
ntos_ke/KeDevQueue.c
ntos_ke/KeDpc.c
ntos_ke/KeEvent.c
+ ntos_ke/KeFloatPointState.c
ntos_ke/KeGuardedMutex.c
ntos_ke/KeIrql.c
ntos_ke/KeMutex.c
diff --git a/modules/rostests/kmtests/kmtest_drv/testlist.c
b/modules/rostests/kmtests/kmtest_drv/testlist.c
index c9c37818ac5..60352b26a83 100644
--- a/modules/rostests/kmtests/kmtest_drv/testlist.c
+++ b/modules/rostests/kmtests/kmtest_drv/testlist.c
@@ -39,6 +39,7 @@ KMT_TESTFUNC Test_KeApc;
KMT_TESTFUNC Test_KeDeviceQueue;
KMT_TESTFUNC Test_KeDpc;
KMT_TESTFUNC Test_KeEvent;
+KMT_TESTFUNC Test_KeFloatPointState;
KMT_TESTFUNC Test_KeGuardedMutex;
KMT_TESTFUNC Test_KeIrql;
KMT_TESTFUNC Test_KeMutex;
@@ -119,6 +120,7 @@ const KMT_TEST TestList[] =
{ "KeDeviceQueue", Test_KeDeviceQueue },
{ "KeDpc", Test_KeDpc },
{ "KeEvent", Test_KeEvent },
+ { "KeFloatPointState", Test_KeFloatPointState },
{ "KeGuardedMutex", Test_KeGuardedMutex },
{ "KeIrql", Test_KeIrql },
{ "KeMutex", Test_KeMutex },
diff --git a/modules/rostests/kmtests/ntos_ke/KeFloatPointState.c
b/modules/rostests/kmtests/ntos_ke/KeFloatPointState.c
new file mode 100644
index 00000000000..9f229f52f54
--- /dev/null
+++ b/modules/rostests/kmtests/ntos_ke/KeFloatPointState.c
@@ -0,0 +1,47 @@
+/*
+ * PROJECT: ReactOS kernel-mode tests
+ * LICENSE: GPL-2.0-or-later (
https://spdx.org/licenses/GPL-2.0-or-later)
+ * PURPOSE: Kernel mode tests for Save/Restore FPU state API kernel support
+ * COPYRIGHT: Copyright 2022 George Bișoc <george.bisoc(a)reactos.org>
+ */
+
+#include <kmt_test.h>
+
+START_TEST(KeFloatPointState)
+{
+ NTSTATUS Status;
+ KFLOATING_SAVE FloatSave;
+ KIRQL Irql;
+
+ /* Save the state under normal conditions */
+ Status = KeSaveFloatingPointState(&FloatSave);
+ ok_irql(PASSIVE_LEVEL);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+
+ /* Restore the FPU state back */
+ KeRestoreFloatingPointState(&FloatSave);
+
+ /* Try to raise the IRQL to APC and do some operations again */
+ KeRaiseIrql(APC_LEVEL, &Irql);
+
+ /* Save the state under APC_LEVEL interrupt */
+ Status = KeSaveFloatingPointState(&FloatSave);
+ ok_irql(APC_LEVEL);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+
+ /* Restore the FPU state back */
+ KeRestoreFloatingPointState(&FloatSave);
+
+ /* Try to raise the IRQL to dispatch this time */
+ KeLowerIrql(Irql);
+ KeRaiseIrql(DISPATCH_LEVEL, &Irql);
+
+ /* Save the state under DISPATCH_LEVEL interrupt */
+ Status = KeSaveFloatingPointState(&FloatSave);
+ ok_irql(DISPATCH_LEVEL);
+ ok_eq_hex(Status, STATUS_SUCCESS);
+
+ /* We're done */
+ KeRestoreFloatingPointState(&FloatSave);
+ KeLowerIrql(Irql);
+}