forked from openSUSE/u-boot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a test for event registration and activation. Signed-off-by: Simon Glass <[email protected]>
- Loading branch information
Showing
4 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -814,6 +814,7 @@ M: Simon Glass <[email protected]> | |
S: Maintained | ||
F: common/event.c | ||
F: include/event.h | ||
F: test/common/event.c | ||
|
||
FASTBOOT | ||
S: Orphaned | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# SPDX-License-Identifier: GPL-2.0+ | ||
obj-y += cmd_ut_common.o | ||
obj-$(CONFIG_AUTOBOOT) += test_autoboot.o | ||
obj-$(CONFIG_EVENT) += event.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// SPDX-License-Identifier: GPL-2.0+ | ||
/* | ||
* Unit tests for event handling | ||
* | ||
* Copyright 2021 Google LLC | ||
* Written by Simon Glass <[email protected]> | ||
*/ | ||
|
||
#include <common.h> | ||
#include <dm.h> | ||
#include <event.h> | ||
#include <test/common.h> | ||
#include <test/test.h> | ||
#include <test/ut.h> | ||
|
||
struct test_state { | ||
struct udevice *dev; | ||
int val; | ||
}; | ||
|
||
static int h_adder(void *ctx, struct event *event) | ||
{ | ||
struct event_data_test *data = &event->data.test; | ||
struct test_state *test_state = ctx; | ||
|
||
test_state->val += data->signal; | ||
|
||
return 0; | ||
} | ||
|
||
static int test_event_base(struct unit_test_state *uts) | ||
{ | ||
struct test_state state; | ||
int signal; | ||
|
||
state.val = 12; | ||
ut_assertok(event_register("wibble", EVT_TEST, h_adder, &state)); | ||
|
||
signal = 17; | ||
|
||
/* Check that the handler is called */ | ||
ut_assertok(event_notify(EVT_TEST, &signal, sizeof(signal))); | ||
ut_asserteq(12 + 17, state.val); | ||
|
||
return 0; | ||
} | ||
COMMON_TEST(test_event_base, 0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters