Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp297120iob; Wed, 18 May 2022 02:23:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxWXWudM1De038H+GLXhEN1r2tP+7bTD5euzTSccdu5ukvrWkL6jshAPrtmdZotNTysTreK X-Received: by 2002:a17:90a:6a45:b0:1dd:11e4:b8e8 with SMTP id d5-20020a17090a6a4500b001dd11e4b8e8mr40427823pjm.89.1652865799962; Wed, 18 May 2022 02:23:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652865799; cv=none; d=google.com; s=arc-20160816; b=UIadgvmHO7qDf8cBLqE5df+BHWPrrlJAOPcVrRkTHllpzc09sHg7ZOBCOCKvWITRf2 efp7HlpCPtueuU4iAxET5cEww0ynF13E5d5/OdGNAea7hIsOmNPtQuQG/eL+FikyRtgC PEMAgPY5P3qkVRU2uRUtjfp/dZ+NDkt6j3rwRpEdO6zVR5WjczB6vtFMp451+gQIy9lS InonUfNjs4CUrzR/zi2Qgjj+x6mTGnbMkEvKD+t5rVi8GMahOrkV4l0raziANyVN0hzJ ANx8EIC0hQyH9lclnDhJc/QuL03ne9zwqBPUrONJGbzPDEFKx/qzZrF15oTcE65iTBGF 18mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+oUN4996w2+Op+KniZ2+pLrEyRrNTvr2tBTIIwyxSts=; b=ch4khCBEIjnvgsTlsPSVn+sA2RKzT5NznP0ZyP6Sw4dmXiRN/TYUY2i3Vjj9K/LLuS pZ3UkJAjTqh8TuHKmfWhUh8eqMuPpr2iOXomyowZIev70bIE6nRXg1XdVJlpu6szAxjv dUy2FhWgsgShH56DHkOXosse1ZDA3t9pMRrTYE0eRpWMTZg0jGwScxWzpwthXCxDMk/Z VM8GTKCiT86IMZumba/CGgnJhTK+ZKjspwNdPGjG8oq0TNNjfbFxaSaU15nNWzxHnMsH k32FpSm9BUm/9N9/h9etZVnIh3PARQy8W+wzm6w8kgsQd//F1PuAtOC5ZBunR3/KG603 A91g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jJ8nNnOF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v5-20020a655c45000000b003c22771658dsi1932523pgr.482.2022.05.18.02.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 May 2022 02:23:19 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=jJ8nNnOF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id BF93C275D9; Wed, 18 May 2022 02:19:04 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234026AbiERJS4 (ORCPT + 99 others); Wed, 18 May 2022 05:18:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233989AbiERJSm (ORCPT ); Wed, 18 May 2022 05:18:42 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83E1B20F6C for ; Wed, 18 May 2022 02:18:40 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F2CBAB81EEF for ; Wed, 18 May 2022 09:18:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7F234C34113; Wed, 18 May 2022 09:18:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652865517; bh=QyFJZzEsnEsrlWMWXjof8oPuhELGLvpS5gdy1Ruuuug=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jJ8nNnOFTHP2OIXelVrkUf4+jpbb7chiaCx1Q4napWwuqZvsjfqmWHKWUxGn5DUfQ Vc7f86+sIjT4dU9NfbnD5E2Yvza44XD5oRkL0kGJ5t+3HIQHGVWnduIe1tOAr3NipU uRxu2QhM91rXfQo6IFqX8mzHsv87j8tYcSAldamFcZ/8RXPnWogpVQiYxxrMX6nvqd gESqERjl/smC4+yvcfjI6GUQmuXhmQixKSVKyxHrkTWZtNrzimUjmQ3RyOUs8i9xln wwuzfPwYCZOcNo7kgtzCwBLhJgrUy/n/g1BMfLUG/Odd1l3Puy9+Ucu5kFDV3sETYI molyAKtOjNWvg== From: Tzung-Bi Shih To: bleung@chromium.org, groeck@chromium.org Cc: chrome-platform@lists.linux.dev, linux-kernel@vger.kernel.org, tzungbi@kernel.org, dianders@chromium.org Subject: [PATCH 4/4] platform/chrome: cros_ec_proto: add Kunit tests for cros_ec_check_result() Date: Wed, 18 May 2022 17:18:14 +0800 Message-Id: <20220518091814.2028579-5-tzungbi@kernel.org> X-Mailer: git-send-email 2.36.0.550.gb090851708-goog In-Reply-To: <20220518091814.2028579-1-tzungbi@kernel.org> References: <20220518091814.2028579-1-tzungbi@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org cros_ec_check_result() is used to check if the EC communication success but EC responded EC_RES_IN_PROGRESS. It should return 0 even if EC wasn't happy about the host command. Add Kunit tests for cros_ec_check_result(). Signed-off-by: Tzung-Bi Shih --- drivers/platform/chrome/cros_ec_proto_test.c | 41 ++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c index 61abb18ac00b..25c4fca5c165 100644 --- a/drivers/platform/chrome/cros_ec_proto_test.c +++ b/drivers/platform/chrome/cros_ec_proto_test.c @@ -132,6 +132,46 @@ static void cros_ec_proto_test_prepare_tx_bad_msg_outsize(struct kunit *test) KUNIT_EXPECT_EQ(test, ret, -EINVAL); } +static void cros_ec_proto_test_check_result(struct kunit *test) +{ + struct cros_ec_proto_test_priv *priv = test->priv; + struct cros_ec_device *ec_dev = &priv->ec_dev; + struct cros_ec_command *msg = priv->msg; + int ret, i; + static enum ec_status status[] = { + EC_RES_SUCCESS, + EC_RES_INVALID_COMMAND, + EC_RES_ERROR, + EC_RES_INVALID_PARAM, + EC_RES_ACCESS_DENIED, + EC_RES_INVALID_RESPONSE, + EC_RES_INVALID_VERSION, + EC_RES_INVALID_CHECKSUM, + EC_RES_UNAVAILABLE, + EC_RES_TIMEOUT, + EC_RES_OVERFLOW, + EC_RES_INVALID_HEADER, + EC_RES_REQUEST_TRUNCATED, + EC_RES_RESPONSE_TOO_BIG, + EC_RES_BUS_ERROR, + EC_RES_BUSY, + EC_RES_INVALID_HEADER_VERSION, + EC_RES_INVALID_HEADER_CRC, + EC_RES_INVALID_DATA_CRC, + EC_RES_DUP_UNAVAILABLE, + }; + + for (i = 0; i < ARRAY_SIZE(status); ++i) { + msg->result = status[i]; + ret = cros_ec_check_result(ec_dev, msg); + KUNIT_EXPECT_EQ(test, ret, 0); + } + + msg->result = EC_RES_IN_PROGRESS; + ret = cros_ec_check_result(ec_dev, msg); + KUNIT_EXPECT_EQ(test, ret, -EAGAIN); +} + static int cros_ec_proto_test_init(struct kunit *test) { struct cros_ec_proto_test_priv *priv; @@ -159,6 +199,7 @@ static struct kunit_case cros_ec_proto_test_cases[] = { KUNIT_CASE(cros_ec_proto_test_prepare_tx_legacy_bad_msg_outsize), KUNIT_CASE(cros_ec_proto_test_prepare_tx_normal), KUNIT_CASE(cros_ec_proto_test_prepare_tx_bad_msg_outsize), + KUNIT_CASE(cros_ec_proto_test_check_result), {} }; -- 2.36.0.550.gb090851708-goog