Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 2 | /* |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 3 | * efi_selftest_exitbootservices |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 4 | * |
| 5 | * Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de> |
| 6 | * |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 7 | * This unit test checks that the notification function of an |
| 8 | * EVT_SIGNAL_EXIT_BOOT_SERVICES event is called exactly once. |
| 9 | */ |
| 10 | |
| 11 | #include <efi_selftest.h> |
| 12 | |
| 13 | static struct efi_boot_services *boottime; |
| 14 | static struct efi_event *event_notify; |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 15 | static unsigned int notification_count; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 16 | |
| 17 | /* |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 18 | * Notification function, increments the notification count. |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 19 | * |
| 20 | * @event notified event |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 21 | * @context pointer to the notification count |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 22 | */ |
| 23 | static void EFIAPI notify(struct efi_event *event, void *context) |
| 24 | { |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 25 | unsigned int *count = context; |
| 26 | |
| 27 | ++*count; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | /* |
| 31 | * Setup unit test. |
| 32 | * |
| 33 | * Create an EVT_SIGNAL_EXIT_BOOT_SERVICES event. |
| 34 | * |
| 35 | * @handle: handle of the loaded image |
| 36 | * @systable: system table |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 37 | * @return: EFI_ST_SUCCESS for success |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 38 | */ |
| 39 | static int setup(const efi_handle_t handle, |
| 40 | const struct efi_system_table *systable) |
| 41 | { |
| 42 | efi_status_t ret; |
| 43 | |
| 44 | boottime = systable->boottime; |
| 45 | |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 46 | notification_count = 0; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 47 | ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES, |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 48 | TPL_CALLBACK, notify, |
| 49 | (void *)¬ification_count, |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 50 | &event_notify); |
| 51 | if (ret != EFI_SUCCESS) { |
| 52 | efi_st_error("could not create event\n"); |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 53 | return EFI_ST_FAILURE; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 54 | } |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 55 | return EFI_ST_SUCCESS; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | /* |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 59 | * Execute unit test. |
| 60 | * |
| 61 | * Check that the notification function of the EVT_SIGNAL_EXIT_BOOT_SERVICES |
| 62 | * event has been called. |
| 63 | * |
| 64 | * Call ExitBootServices again and check that the notification function is |
| 65 | * not called again. |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 66 | * |
| 67 | * @return: EFI_ST_SUCCESS for success |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 68 | */ |
| 69 | static int execute(void) |
| 70 | { |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 71 | if (notification_count != 1) { |
| 72 | efi_st_error("ExitBootServices was not notified\n"); |
| 73 | return EFI_ST_FAILURE; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 74 | } |
| 75 | efi_st_exit_boot_services(); |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 76 | if (notification_count != 1) { |
| 77 | efi_st_error("ExitBootServices was notified twice\n"); |
| 78 | return EFI_ST_FAILURE; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 79 | } |
Heinrich Schuchardt | e67e724 | 2017-10-04 15:31:26 +0200 | [diff] [blame] | 80 | return EFI_ST_SUCCESS; |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 81 | } |
| 82 | |
| 83 | EFI_UNIT_TEST(exitbootservices) = { |
| 84 | .name = "ExitBootServices", |
| 85 | .phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT, |
| 86 | .setup = setup, |
| 87 | .execute = execute, |
Heinrich Schuchardt | 0923876 | 2017-09-15 10:06:19 +0200 | [diff] [blame] | 88 | }; |