[NTOS:KE] Write a basic kernel mode test for FPU Save/Restore mechanism

This commit is contained in:
George Bișoc 2022-01-25 13:20:05 +01:00
parent 064a35dc67
commit b922b6d7fc
No known key found for this signature in database
GPG key ID: 688C4FBE25D7DEF6
3 changed files with 50 additions and 0 deletions

View file

@ -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

View file

@ -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 },

View file

@ -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@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);
}