From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CB382C433F5 for ; Fri, 4 Mar 2022 15:45:16 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 74A3083BB0; Fri, 4 Mar 2022 16:44:14 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="IJ/0EXOB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3747683D10; Fri, 4 Mar 2022 16:43:59 +0100 (CET) Received: from mail-io1-xd2b.google.com (mail-io1-xd2b.google.com [IPv6:2607:f8b0:4864:20::d2b]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AB10B83CFE for ; Fri, 4 Mar 2022 16:43:27 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-io1-xd2b.google.com with SMTP id f14so9987395ioz.1 for ; Fri, 04 Mar 2022 07:43:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=EG2B0Z3b7bFEVhsVnlCnJiHp7ClQO1ZWqczvAnaz4Rk=; b=IJ/0EXOBiSH8CFBYgov3paVx5nhyBxBSY+HhdvOlhVUxO6s0BoQZhOcaueQmvMeOiV cOBUDgyNRGDT4Zob8aK4E335ZOqEViAHdBWaw2w8yAs7xXysWcDKHNKZZYkJEOieNUWo +HQuMgKHW8pqHuQrZpGFaaGZqWas1Vf+d2Qpo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=EG2B0Z3b7bFEVhsVnlCnJiHp7ClQO1ZWqczvAnaz4Rk=; b=ZbkUmaPA5GGhv/GL2jPD0BmWvYlQ0j8n+/HDILYscnW5U5y3Az+2FMqZbY1b+DK5yP rJ8paWT8L7u6zCLp9O8iGRf/5yj0ieIByMXL44gqITMEngYQLR//6JByvSovVFD5+jtB /lZ3JfBE1gSkgZE1O3Ju+cjBdXOT/ixmjD4AEvCMN1i95vouarj01se2XjDQhb6FOFFE rdij7TZsFlOhcuqvkSs4rdApeQaOYmT+nT31fI6WzbN/1Qs21saVcOs36gc6uxtjVkOM yRWFw+YFJuB0d53hLnELqKWdeNLMRk1T8NWhpOSJfEF+VgrGBPqmL3LuP7oSOovLIiyE cZnA== X-Gm-Message-State: AOAM5337oJBCZIwSHB4eb9SOJzdb1Zfn5rbEPSTvuaWYkvAAnHEL9L8T ns/QtQxOSqsd9IJnv2dEDB2v1AT0o7k3GQ== X-Google-Smtp-Source: ABdhPJxunlsKG85GQzIk+AHvxH1TKfHklCDLgY9QCd+ZMc/Qy1RNlZpRyZKb8tyKzm02gCSwvX6w4Q== X-Received: by 2002:a02:7158:0:b0:317:2da9:4c20 with SMTP id n24-20020a027158000000b003172da94c20mr21138884jaf.201.1646408606190; Fri, 04 Mar 2022 07:43:26 -0800 (PST) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id h13-20020a5ecb4d000000b006410cd7bf4asm4758814iok.9.2022.03.04.07.43.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 07:43:25 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Marek Vasut , Masahiro Yamada , Tom Rini , AKASHI Takahiro , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Heinrich Schuchardt , Simon Glass Subject: [PATCH v2 06/13] event: Add a simple test Date: Fri, 4 Mar 2022 08:43:01 -0700 Message-Id: <20220304154308.2547711-7-sjg@chromium.org> X-Mailer: git-send-email 2.35.1.616.g0bdcbb4464-goog In-Reply-To: <20220304154308.2547711-1-sjg@chromium.org> References: <20220304154308.2547711-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean Add a test for event registration and activation. Signed-off-by: Simon Glass --- (no changes since v1) MAINTAINERS | 1 + test/common/Makefile | 1 + test/common/event.c | 47 ++++++++++++++++++++++++++++++++++++++++++++ test/test-main.c | 4 ++++ 4 files changed, 53 insertions(+) create mode 100644 test/common/event.c diff --git a/MAINTAINERS b/MAINTAINERS index b534ad66b9..2786adad4b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -814,6 +814,7 @@ M: Simon Glass S: Maintained F: common/event.c F: include/event.h +F: test/common/event.c FASTBOOT S: Orphaned diff --git a/test/common/Makefile b/test/common/Makefile index 24c9145dcc..9087788ba6 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 0000000000..dfaa66ea49 --- /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 + */ + +#include +#include +#include +#include +#include +#include + +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); diff --git a/test/test-main.c b/test/test-main.c index 8fcb02ecea..ee38d1faea 100644 --- a/test/test-main.c +++ b/test/test-main.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -218,6 +219,8 @@ static int dm_test_restore(struct device_node *of_root) */ static int test_pre_run(struct unit_test_state *uts, struct unit_test *test) { + ut_assertok(event_init()); + if (test->flags & UT_TESTF_DM) ut_assertok(dm_test_pre_run(uts)); @@ -260,6 +263,7 @@ static int test_post_run(struct unit_test_state *uts, struct unit_test *test) ut_unsilence_console(uts); if (test->flags & UT_TESTF_DM) ut_assertok(dm_test_post_run(uts)); + ut_assertok(event_uninit()); return 0; } -- 2.35.1.616.g0bdcbb4464-goog