1 /*
2  * PROJECT:     ReactOS kernel-mode tests
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Kernel mode tests for Save/Restore FPU state API kernel support
5  * COPYRIGHT:   Copyright 2022 George Bișoc <george.bisoc@reactos.org>
6  */
7 
8 #include <kmt_test.h>
9 
10 START_TEST(KeFloatPointState)
11 {
12     NTSTATUS Status;
13     KFLOATING_SAVE FloatSave;
14     KIRQL Irql;
15 
16     /* Save the state under normal conditions */
17     Status = KeSaveFloatingPointState(&FloatSave);
18     ok_irql(PASSIVE_LEVEL);
19     ok_eq_hex(Status, STATUS_SUCCESS);
20 
21     /* Restore the FPU state back */
22     KeRestoreFloatingPointState(&FloatSave);
23 
24     /* Try to raise the IRQL to APC and do some operations again */
25     KeRaiseIrql(APC_LEVEL, &Irql);
26 
27     /* Save the state under APC_LEVEL interrupt */
28     Status = KeSaveFloatingPointState(&FloatSave);
29     ok_irql(APC_LEVEL);
30     ok_eq_hex(Status, STATUS_SUCCESS);
31 
32     /* Restore the FPU state back */
33     KeRestoreFloatingPointState(&FloatSave);
34 
35     /* Try to raise the IRQL to dispatch this time */
36     KeLowerIrql(Irql);
37     KeRaiseIrql(DISPATCH_LEVEL, &Irql);
38 
39     /* Save the state under DISPATCH_LEVEL interrupt */
40     Status = KeSaveFloatingPointState(&FloatSave);
41     ok_irql(DISPATCH_LEVEL);
42     ok_eq_hex(Status, STATUS_SUCCESS);
43 
44     /* We're done */
45     KeRestoreFloatingPointState(&FloatSave);
46     KeLowerIrql(Irql);
47 }
48