2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-09-15 08:06:19 +00:00
|
|
|
/*
|
2017-10-04 13:31:26 +00:00
|
|
|
* efi_selftest_exitbootservices
|
2017-09-15 08:06:19 +00:00
|
|
|
*
|
|
|
|
* Copyright (c) 2017 Heinrich Schuchardt <xypron.glpk@gmx.de>
|
|
|
|
*
|
|
|
|
* This unit test checks that the notification function of an
|
|
|
|
* EVT_SIGNAL_EXIT_BOOT_SERVICES event is called exactly once.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <efi_selftest.h>
|
|
|
|
|
2021-11-17 17:52:35 +00:00
|
|
|
static efi_guid_t guid_before_exit_boot_services =
|
|
|
|
EFI_GUID(0x8be0e274, 0x3970, 0x4b44, 0x80, 0xc5,
|
|
|
|
0x1a, 0xb9, 0x50, 0x2f, 0x3b, 0xfc);
|
|
|
|
#define CAPACITY 4
|
|
|
|
|
|
|
|
struct notification_record {
|
|
|
|
unsigned int count;
|
|
|
|
unsigned int type[CAPACITY];
|
|
|
|
};
|
|
|
|
|
|
|
|
struct notification_context {
|
|
|
|
struct notification_record *record;
|
|
|
|
unsigned int type;
|
|
|
|
};
|
|
|
|
|
2017-09-15 08:06:19 +00:00
|
|
|
static struct efi_boot_services *boottime;
|
|
|
|
static struct efi_event *event_notify;
|
2021-11-17 17:52:35 +00:00
|
|
|
struct notification_record record;
|
|
|
|
|
|
|
|
struct notification_context context_before = {
|
|
|
|
.record = &record,
|
|
|
|
.type = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct notification_context context = {
|
|
|
|
.record = &record,
|
|
|
|
.type = 2,
|
|
|
|
};
|
2017-09-15 08:06:19 +00:00
|
|
|
|
|
|
|
/*
|
2017-10-04 13:31:26 +00:00
|
|
|
* Notification function, increments the notification count.
|
2017-09-15 08:06:19 +00:00
|
|
|
*
|
|
|
|
* @event notified event
|
2017-10-04 13:31:26 +00:00
|
|
|
* @context pointer to the notification count
|
2017-09-15 08:06:19 +00:00
|
|
|
*/
|
2021-11-17 17:52:35 +00:00
|
|
|
static void EFIAPI ebs_notify(struct efi_event *event, void *context)
|
2017-09-15 08:06:19 +00:00
|
|
|
{
|
2021-11-17 17:52:35 +00:00
|
|
|
struct notification_context *ctx = context;
|
|
|
|
|
|
|
|
if (ctx->record->count >= CAPACITY)
|
|
|
|
return;
|
2017-10-04 13:31:26 +00:00
|
|
|
|
2021-11-17 17:52:35 +00:00
|
|
|
ctx->record->type[ctx->record->count] = ctx->type;
|
|
|
|
ctx->record->count++;
|
2017-09-15 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup unit test.
|
|
|
|
*
|
|
|
|
* Create an EVT_SIGNAL_EXIT_BOOT_SERVICES event.
|
|
|
|
*
|
|
|
|
* @handle: handle of the loaded image
|
|
|
|
* @systable: system table
|
2017-10-04 13:31:26 +00:00
|
|
|
* @return: EFI_ST_SUCCESS for success
|
2017-09-15 08:06:19 +00:00
|
|
|
*/
|
|
|
|
static int setup(const efi_handle_t handle,
|
|
|
|
const struct efi_system_table *systable)
|
|
|
|
{
|
|
|
|
efi_status_t ret;
|
|
|
|
|
|
|
|
boottime = systable->boottime;
|
|
|
|
|
|
|
|
ret = boottime->create_event(EVT_SIGNAL_EXIT_BOOT_SERVICES,
|
2021-11-17 17:52:35 +00:00
|
|
|
TPL_CALLBACK, ebs_notify,
|
|
|
|
&context,
|
2017-09-15 08:06:19 +00:00
|
|
|
&event_notify);
|
|
|
|
if (ret != EFI_SUCCESS) {
|
|
|
|
efi_st_error("could not create event\n");
|
2017-10-04 13:31:26 +00:00
|
|
|
return EFI_ST_FAILURE;
|
2017-09-15 08:06:19 +00:00
|
|
|
}
|
2021-11-17 17:52:35 +00:00
|
|
|
ret = boottime->create_event_ex(0, TPL_CALLBACK, ebs_notify,
|
|
|
|
&context_before,
|
|
|
|
&guid_before_exit_boot_services,
|
|
|
|
&event_notify);
|
|
|
|
if (ret != EFI_SUCCESS) {
|
|
|
|
efi_st_error("could not create event\n");
|
|
|
|
return EFI_ST_FAILURE;
|
|
|
|
}
|
|
|
|
|
2017-10-04 13:31:26 +00:00
|
|
|
return EFI_ST_SUCCESS;
|
2017-09-15 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Execute unit test.
|
|
|
|
*
|
|
|
|
* Check that the notification function of the EVT_SIGNAL_EXIT_BOOT_SERVICES
|
|
|
|
* event has been called.
|
|
|
|
*
|
|
|
|
* Call ExitBootServices again and check that the notification function is
|
|
|
|
* not called again.
|
2017-10-04 13:31:26 +00:00
|
|
|
*
|
|
|
|
* @return: EFI_ST_SUCCESS for success
|
2017-09-15 08:06:19 +00:00
|
|
|
*/
|
|
|
|
static int execute(void)
|
|
|
|
{
|
2021-11-17 17:52:35 +00:00
|
|
|
if (record.count != 2) {
|
|
|
|
efi_st_error("Incorrect event count %u\n", record.count);
|
|
|
|
return EFI_ST_FAILURE;
|
|
|
|
}
|
|
|
|
if (record.type[0] != 1) {
|
|
|
|
efi_st_error("EFI_GROUP_BEFORE_EXIT_BOOT_SERVICE not notified\n");
|
|
|
|
return EFI_ST_FAILURE;
|
|
|
|
}
|
|
|
|
if (record.type[1] != 2) {
|
|
|
|
efi_st_error("EVT_SIGNAL_EXIT_BOOT_SERVICES was not notified\n");
|
2017-10-04 13:31:26 +00:00
|
|
|
return EFI_ST_FAILURE;
|
2017-09-15 08:06:19 +00:00
|
|
|
}
|
|
|
|
efi_st_exit_boot_services();
|
2021-11-17 17:52:35 +00:00
|
|
|
if (record.count != 2) {
|
|
|
|
efi_st_error("Incorrect event count %u\n", record.count);
|
2017-10-04 13:31:26 +00:00
|
|
|
return EFI_ST_FAILURE;
|
2017-09-15 08:06:19 +00:00
|
|
|
}
|
2017-10-04 13:31:26 +00:00
|
|
|
return EFI_ST_SUCCESS;
|
2017-09-15 08:06:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EFI_UNIT_TEST(exitbootservices) = {
|
|
|
|
.name = "ExitBootServices",
|
|
|
|
.phase = EFI_SETUP_BEFORE_BOOTTIME_EXIT,
|
|
|
|
.setup = setup,
|
|
|
|
.execute = execute,
|
|
|
|
};
|