Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2675774iof; Wed, 8 Jun 2022 09:41:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv55Mj4DvWwGaYziRFab4sdbWAPud1v6QUXWmYYviUilZ8xMN+xF4ymHFCkLtJE5SWB2aH X-Received: by 2002:a63:81c3:0:b0:3fc:c510:1a3 with SMTP id t186-20020a6381c3000000b003fcc51001a3mr30757647pgd.581.1654706462501; Wed, 08 Jun 2022 09:41:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654706462; cv=none; d=google.com; s=arc-20160816; b=F7oPLuwWBQnocAYlEbnPKSXxo41R1xPL6BSSwAZRjM4QD2Z/ol+5lhbxuaY6KCJKOO e+rvHX8T/WkIrblCZ/Oe0zOZdbnNYQqbsLUQhETMF1dGqfS+GLKedX+y2xet3ijjk01J blcqkmxzh6ZmZCH80djmVbI46i7mw6DNLfHky2LDmCW7e/myLgj2wFnRIxxSHYvkXdRl 18iZnh0Q50/EmdNlZ9RsdZqDvlH/z7E/akX/nxJrfDPa7botGlSVHtixTmC7XeHGbtN0 23aiGkgr1Mq3/Ykb+tjjIA5krJTQE6LpMqF3x0DCYge/GNqRhIsDXqmdcY9LIqGNpJhc tvFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=UJW5PXvVdEwE0T70Irkxa5WekVJL3N0yIkXVXlVvJX4=; b=FsjLBhEALHvwqtwtsbLZaLwO9c9yvAUws6PfXOXDuymsEjW2VHd6riYqhJ/pJYzccn RE1DCuPRk922uS5AkFwAJBc9s8UeRRYuHsA2/O5ZjWYNG20ObbsSXTiqyF5XGffZbEeh vwXD8dwkrh5D+e9J/2Cp6wiCV7xD+t3wzzFgL/wc51pASCMB4Y8dj+whLgBD1AR69Vgn GKkZebi3Nq4VPwnOGlmuw9/kQvMYoODCTFSJ4PzKkQWV82BbMjZLcIyWLk0f3t7vbChp On1Nf/wDx2v6d4T89o4mHzcVpsMCguJrDqQiJojGIs6x4QtKENFU3tnGx9ZZC7jckzIb WNvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IKdRSGMY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id x24-20020a63db58000000b003fce456b2e4si28322846pgi.502.2022.06.08.09.41.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 09:41:02 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=IKdRSGMY; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5375041FAC; Wed, 8 Jun 2022 09:14:10 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244768AbiFHQNr (ORCPT + 99 others); Wed, 8 Jun 2022 12:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245187AbiFHQNk (ORCPT ); Wed, 8 Jun 2022 12:13:40 -0400 Received: from mail-ej1-x633.google.com (mail-ej1-x633.google.com [IPv6:2a00:1450:4864:20::633]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F2D8D8D36 for ; Wed, 8 Jun 2022 09:13:38 -0700 (PDT) Received: by mail-ej1-x633.google.com with SMTP id fu3so40931382ejc.7 for ; Wed, 08 Jun 2022 09:13:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=UJW5PXvVdEwE0T70Irkxa5WekVJL3N0yIkXVXlVvJX4=; b=IKdRSGMYjDtk/Ff+Y3vj8CHRQ7xdW1cnj+jYmjGhlEzhCu7xbQWVYCFSKe5ukhgx4o 1ohsrzszgk5aGZH6fOksVjbiWBnV1PLQ/MyGUtwyNoNO3EkyhbyxT9bHXthQd3odk1dP cKZyJDBKrwtY3ePIu5rzEjT0yaF5oYSPS6U1z0Ygdlb/mcpm6SoMGtAGKq0F4n3habhg cSE3eFG7EqSPW13DItMzTYonzo91GaXTrTlUV1wKlRxxbBto1Re7J4C6vMr0xuUkYmpE eytRz3c1rpRVqZByIfYY3qFekhjYNHh4Pfv0yZ3hSykrJ7tnSIxaQxOWh5+zpaArGU/V FLaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=UJW5PXvVdEwE0T70Irkxa5WekVJL3N0yIkXVXlVvJX4=; b=8OoZkqkBQgn35qy4QiZlpghJ096/DWHuPak6dUh7rOet6G9bvnt8922S++0Ih/xybo Fxwk6RWikPRpyJdRKEMpSFbUQuPB06MItHjPGAXKlD9zb0iqud+NHvwSMJ/GEzQHRtvt +R9l+vAvFKhS+2L9B+MCWDN4WOfvAOtRsm7VeJ2WgFPU4WlGXS9I1+71LVcXOzR1ZnbU b8pQk/0NjCjD8vETNtSYtuoF7Qp3lK9BUcdff0E9ACqUgvRZFNlk4vPrLIjtP4/y0hFh mTLu9r0s/Ee67avqqdb78b4xML953dx5VTt0e7iEwa8yK7i34wSRG/KkEo0nl3BB+1d5 WGNw== X-Gm-Message-State: AOAM531D6OFkoJiR5QywZhStBXkRzbzPcsO/WTu/FVwrKcEKyP0HJ6gP HQ6E5GoXT+rayc0D3Zi66gZNb+6s/wZ6mq3J6xJRpA== X-Received: by 2002:a17:906:4d50:b0:70d:afd4:1e63 with SMTP id b16-20020a1709064d5000b0070dafd41e63mr28190727ejv.618.1654704816852; Wed, 08 Jun 2022 09:13:36 -0700 (PDT) MIME-Version: 1.0 References: <20220608110734.2928245-1-tzungbi@kernel.org> <20220608110734.2928245-9-tzungbi@kernel.org> In-Reply-To: <20220608110734.2928245-9-tzungbi@kernel.org> From: Guenter Roeck Date: Wed, 8 Jun 2022 09:13:25 -0700 Message-ID: Subject: Re: [PATCH v3 08/23] platform/chrome: cros_ec_proto: add Kunit tests for getting proto info To: Tzung-Bi Shih Cc: Benson Leung , Guenter Roeck , "open list:CHROME HARDWARE PLATFORM SUPPORT" , linux-kernel Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.5 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL autolearn=no 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 On Wed, Jun 8, 2022 at 4:08 AM Tzung-Bi Shih wrote: > > cros_ec_get_proto_info() expects to receive > sizeof(struct ec_response_get_protocol_info) from send_command(). The > payload is valid only if the return value is positive. > > Add Kunit tests for returning 0 from send_command() in > cros_ec_get_proto_info(). > > Signed-off-by: Tzung-Bi Shih Reviewed-by: Guenter Roeck > --- > No v2. New and separated from the original series. > > drivers/platform/chrome/cros_ec_proto_test.c | 132 +++++++++++++++++++ > 1 file changed, 132 insertions(+) > > diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c > index 8b16666c1657..1378ac90e1cb 100644 > --- a/drivers/platform/chrome/cros_ec_proto_test.c > +++ b/drivers/platform/chrome/cros_ec_proto_test.c > @@ -407,6 +407,71 @@ static void cros_ec_proto_test_query_all_no_pd_return_error(struct kunit *test) > } > } > > +static void cros_ec_proto_test_query_all_no_pd_return0(struct kunit *test) > +{ > + struct cros_ec_proto_test_priv *priv = test->priv; > + struct cros_ec_device *ec_dev = &priv->ec_dev; > + struct ec_xfer_mock *mock; > + int ret; > + > + /* Set some garbage bytes. */ > + ec_dev->max_passthru = 0xbf; > + > + /* For cros_ec_get_proto_info() without passthru. */ > + { > + struct ec_response_get_protocol_info *data; > + > + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data)); > + KUNIT_ASSERT_PTR_NE(test, mock, NULL); > + > + /* > + * Although it doesn't check the value, provides valid sizes so that > + * cros_ec_query_all() allocates din and dout correctly. > + */ > + data = (struct ec_response_get_protocol_info *)mock->o_data; > + data->max_request_packet_size = 0xbe; > + data->max_response_packet_size = 0xef; > + } > + > + /* For cros_ec_get_proto_info() with passthru. */ > + { > + mock = cros_kunit_ec_xfer_mock_add(test, 0); > + KUNIT_ASSERT_PTR_NE(test, mock, NULL); > + } > + > + cros_ec_proto_test_query_all_pretest(test); > + ret = cros_ec_query_all(ec_dev); > + KUNIT_EXPECT_EQ(test, ret, 0); > + > + /* For cros_ec_get_proto_info() without passthru. */ > + { > + mock = cros_kunit_ec_xfer_mock_next(); > + KUNIT_EXPECT_PTR_NE(test, mock, NULL); > + > + KUNIT_EXPECT_EQ(test, mock->msg.version, 0); > + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_PROTOCOL_INFO); > + KUNIT_EXPECT_EQ(test, mock->msg.insize, > + sizeof(struct ec_response_get_protocol_info)); > + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0); > + } > + > + /* For cros_ec_get_proto_info() with passthru. */ > + { > + mock = cros_kunit_ec_xfer_mock_next(); > + KUNIT_EXPECT_PTR_NE(test, mock, NULL); > + > + KUNIT_EXPECT_EQ(test, mock->msg.version, 0); > + KUNIT_EXPECT_EQ(test, mock->msg.command, > + EC_CMD_PASSTHRU_OFFSET(CROS_EC_DEV_PD_INDEX) | > + EC_CMD_GET_PROTOCOL_INFO); > + KUNIT_EXPECT_EQ(test, mock->msg.insize, > + sizeof(struct ec_response_get_protocol_info)); > + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0); > + > + KUNIT_EXPECT_EQ(test, ec_dev->max_passthru, 0); > + } > +} > + > static void cros_ec_proto_test_query_all_legacy_normal_v3_return_error(struct kunit *test) > { > struct cros_ec_proto_test_priv *priv = test->priv; > @@ -472,6 +537,71 @@ static void cros_ec_proto_test_query_all_legacy_normal_v3_return_error(struct ku > } > } > > +static void cros_ec_proto_test_query_all_legacy_normal_v3_return0(struct kunit *test) > +{ > + struct cros_ec_proto_test_priv *priv = test->priv; > + struct cros_ec_device *ec_dev = &priv->ec_dev; > + struct ec_xfer_mock *mock; > + int ret; > + > + /* For cros_ec_get_proto_info() without passthru. */ > + { > + mock = cros_kunit_ec_xfer_mock_add(test, 0); > + KUNIT_ASSERT_PTR_NE(test, mock, NULL); > + } > + > + /* For cros_ec_host_command_proto_query_v2(). */ > + { > + struct ec_response_hello *data; > + > + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data)); > + KUNIT_ASSERT_PTR_NE(test, mock, NULL); > + > + data = (struct ec_response_hello *)mock->o_data; > + data->out_data = 0xa1b2c3d4; > + } > + > + cros_ec_proto_test_query_all_pretest(test); > + ret = cros_ec_query_all(ec_dev); > + KUNIT_EXPECT_EQ(test, ret, 0); > + > + /* For cros_ec_get_proto_info() without passthru. */ > + { > + mock = cros_kunit_ec_xfer_mock_next(); > + KUNIT_EXPECT_PTR_NE(test, mock, NULL); > + > + KUNIT_EXPECT_EQ(test, mock->msg.version, 0); > + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_GET_PROTOCOL_INFO); > + KUNIT_EXPECT_EQ(test, mock->msg.insize, > + sizeof(struct ec_response_get_protocol_info)); > + KUNIT_EXPECT_EQ(test, mock->msg.outsize, 0); > + } > + > + /* For cros_ec_host_command_proto_query_v2(). */ > + { > + struct ec_params_hello *data; > + > + mock = cros_kunit_ec_xfer_mock_next(); > + KUNIT_EXPECT_PTR_NE(test, mock, NULL); > + > + KUNIT_EXPECT_EQ(test, mock->msg.version, 0); > + KUNIT_EXPECT_EQ(test, mock->msg.command, EC_CMD_HELLO); > + KUNIT_EXPECT_EQ(test, mock->msg.insize, sizeof(struct ec_response_hello)); > + KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data)); > + > + data = (struct ec_params_hello *)mock->i_data; > + KUNIT_EXPECT_EQ(test, data->in_data, 0xa0b0c0d0); > + > + KUNIT_EXPECT_EQ(test, ec_dev->proto_version, 2); > + KUNIT_EXPECT_EQ(test, ec_dev->max_request, EC_PROTO2_MAX_PARAM_SIZE); > + KUNIT_EXPECT_EQ(test, ec_dev->max_response, EC_PROTO2_MAX_PARAM_SIZE); > + KUNIT_EXPECT_EQ(test, ec_dev->max_passthru, 0); > + KUNIT_EXPECT_PTR_EQ(test, ec_dev->pkt_xfer, NULL); > + KUNIT_EXPECT_EQ(test, ec_dev->din_size, EC_PROTO2_MSG_BYTES); > + KUNIT_EXPECT_EQ(test, ec_dev->dout_size, EC_PROTO2_MSG_BYTES); > + } > +} > + > static void cros_ec_proto_test_query_all_legacy_xfer_error(struct kunit *test) > { > struct cros_ec_proto_test_priv *priv = test->priv; > @@ -999,7 +1129,9 @@ static struct kunit_case cros_ec_proto_test_cases[] = { > KUNIT_CASE(cros_ec_proto_test_check_result), > KUNIT_CASE(cros_ec_proto_test_query_all_normal), > KUNIT_CASE(cros_ec_proto_test_query_all_no_pd_return_error), > + KUNIT_CASE(cros_ec_proto_test_query_all_no_pd_return0), > KUNIT_CASE(cros_ec_proto_test_query_all_legacy_normal_v3_return_error), > + KUNIT_CASE(cros_ec_proto_test_query_all_legacy_normal_v3_return0), > KUNIT_CASE(cros_ec_proto_test_query_all_legacy_xfer_error), > KUNIT_CASE(cros_ec_proto_test_query_all_legacy_return_error), > KUNIT_CASE(cros_ec_proto_test_query_all_legacy_data_error), > -- > 2.36.1.255.ge46751e96f-goog >