diff options
| author | Simon Glass <[email protected]> | 2022-03-04 08:43:01 -0700 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2022-03-10 08:28:36 -0500 |
| commit | 7d02645fe4c07efe253f68d2d6134922e7c5323e (patch) | |
| tree | fc3a8a8a4af25118b174deafd2d1ce25887ab9c8 /test/common | |
| parent | 87a5d1b5d012b0663517bfa36f5e01c8028f121a (diff) | |
event: Add a simple test
Add a test for event registration and activation.
Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'test/common')
| -rw-r--r-- | test/common/Makefile | 1 | ||||
| -rw-r--r-- | test/common/event.c | 47 |
2 files changed, 48 insertions, 0 deletions
diff --git a/test/common/Makefile b/test/common/Makefile index 24c9145dccc..9087788ba6a 100644 --- a/test/common/Makefile +++ b/test/common/Makefile @@ -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 diff --git a/test/common/event.c b/test/common/event.c new file mode 100644 index 00000000000..dfaa66ea492 --- /dev/null +++ b/test/common/event.c @@ -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); |
