diff options
author | Simon Glass <sjg@chromium.org> | 2022-03-04 08:43:03 -0700 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-03-10 08:28:36 -0500 |
commit | 5b896ed5856f768cdd55cdeb44c5f8f6b6a7a18a (patch) | |
tree | 427918a7828619a8620cd9b95d547539c9eb6733 /test | |
parent | 5a4219043d659514316e41d3d09866030c773e78 (diff) | |
download | u-boot-5b896ed5856f768cdd55cdeb44c5f8f6b6a7a18a.zip u-boot-5b896ed5856f768cdd55cdeb44c5f8f6b6a7a18a.tar.gz u-boot-5b896ed5856f768cdd55cdeb44c5f8f6b6a7a18a.tar.bz2 |
event: Add events for device probe/remove
Generate events when devices are probed or removed, allowing hooks
to be added for these situations.
This is controlled by the DM_EVENT config option.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/common/event.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test/common/event.c b/test/common/event.c index dfaa66e..6037ae2 100644 --- a/test/common/event.c +++ b/test/common/event.c @@ -45,3 +45,41 @@ static int test_event_base(struct unit_test_state *uts) return 0; } COMMON_TEST(test_event_base, 0); + +static int h_probe(void *ctx, struct event *event) +{ + struct test_state *test_state = ctx; + + test_state->dev = event->data.dm.dev; + switch (event->type) { + case EVT_DM_PRE_PROBE: + test_state->val |= 1; + break; + case EVT_DM_POST_PROBE: + test_state->val |= 2; + break; + default: + break; + } + + return 0; +} + +static int test_event_probe(struct unit_test_state *uts) +{ + struct test_state state; + struct udevice *dev; + + state.val = 0; + ut_assertok(event_register("pre", EVT_DM_PRE_PROBE, h_probe, &state)); + ut_assertok(event_register("post", EVT_DM_POST_PROBE, h_probe, &state)); + + /* Probe a device */ + ut_assertok(uclass_first_device_err(UCLASS_TEST_FDT, &dev)); + + /* Check that the handler is called */ + ut_asserteq(3, state.val); + + return 0; +} +COMMON_TEST(test_event_probe, UT_TESTF_DM | UT_TESTF_SCAN_FDT); |