blob: dfaa66ea492e519282d757bf2fd16498ca6f1547 [file] [log] [blame]
Simon Glassa128b1b2022-03-04 08:43:01 -07001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Unit tests for event handling
4 *
5 * Copyright 2021 Google LLC
6 * Written by Simon Glass <sjg@chromium.org>
7 */
8
9#include <common.h>
10#include <dm.h>
11#include <event.h>
12#include <test/common.h>
13#include <test/test.h>
14#include <test/ut.h>
15
16struct test_state {
17 struct udevice *dev;
18 int val;
19};
20
21static int h_adder(void *ctx, struct event *event)
22{
23 struct event_data_test *data = &event->data.test;
24 struct test_state *test_state = ctx;
25
26 test_state->val += data->signal;
27
28 return 0;
29}
30
31static int test_event_base(struct unit_test_state *uts)
32{
33 struct test_state state;
34 int signal;
35
36 state.val = 12;
37 ut_assertok(event_register("wibble", EVT_TEST, h_adder, &state));
38
39 signal = 17;
40
41 /* Check that the handler is called */
42 ut_assertok(event_notify(EVT_TEST, &signal, sizeof(signal)));
43 ut_asserteq(12 + 17, state.val);
44
45 return 0;
46}
47COMMON_TEST(test_event_base, 0);