Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2690889iof; Wed, 8 Jun 2022 10:01:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxD2o4VkZW5+PvY1WdOwmGapK4vgRuLw3x9gDJm0lTAmfH1xMi+E45Od7YA4uVtNHxp3lFc X-Received: by 2002:a17:903:41d0:b0:167:68a7:c2f with SMTP id u16-20020a17090341d000b0016768a70c2fmr22091943ple.148.1654707680203; Wed, 08 Jun 2022 10:01:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654707680; cv=none; d=google.com; s=arc-20160816; b=TQyKNlHR6oclcyQy/QSpjin75gkUfbpzOK8QwL3OHc9Mc4bUqgfGwWg4Qd5Fhj+PdL 2oxG2UTwl/mckd3pnTjn5asLsU7UzRdhwfF2Qh+p7W3kmCPFTxM4w4k4SRFfwNxeAEkZ nVzPYiXEQaGwnQIXSpCZVV4hZcgTOBrAwae5Ta+e3dtMci/QrqYiOMxgd+5rdU1PFyrR VgOkru98dHOkCE5j9ZAknj+hJq7BC9rkNeNlqVZTs9GUoahiv5i7es3mDbxrYHhSx4kc pw8EyV1BmyRVW/GQ6Gj/PP2Z7XfrHnVAETqEKAdAzNXKhmpccVliZxIy3ydw8k/DXkT9 un/A== 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=9MWoWYpPNtKdOh5OWWChfWWdIEIaCiLObL+8E7CLiZg=; b=Rqp23Mv8pq/h9ROGNeRMc+ytaqyCHD83AvSxjqOhxwxvGqJp/svqT/cLlIOvnlDTSq N4xgMth+v9ishR28iSwkzyQY8tL+LLH9+haWloIgzSxHSkXifgj0rQNzGgSK30C/xSGf f10MVa3G3W3vhOnNdmKgIgUs6e/SSFJiKmdZfuovOSQqDtxoPt9rwsQ6jlfmCkQBhnut uWXXyeafwKVkGp3DdvphF1JAyzZC16uTNm2xzh6DGJscW5BoP/hg7gY+nnzPTSHhCR3Q pNbBDhTB7zMU3NjxQuKsLA4IkYZHI+CkwCypvM9Jf8Oza+K3hPDym4MYzhNClaE9/o+Q 2Wcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=nVO+jS7X; 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 t9-20020a634449000000b003daf6356570si28603887pgk.3.2022.06.08.10.01.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Jun 2022 10:01:20 -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=nVO+jS7X; 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 340E12B7E3D; Wed, 8 Jun 2022 09:31:28 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245186AbiFHQa6 (ORCPT + 99 others); Wed, 8 Jun 2022 12:30:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36500 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245523AbiFHQaA (ORCPT ); Wed, 8 Jun 2022 12:30:00 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 28EA62044DD for ; Wed, 8 Jun 2022 09:29:10 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id gl15so28647312ejb.4 for ; Wed, 08 Jun 2022 09:29:10 -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=9MWoWYpPNtKdOh5OWWChfWWdIEIaCiLObL+8E7CLiZg=; b=nVO+jS7X+cDzngzfvvGkk9s2t9t3POOcTDqdU6zsQtOzTa4PltRl65f+yPvBJroxTL frAUoYEL+fXaEOz4SN5e88mM1SjLzOmyxMKSoS8I1M8e9BMUtOGqi83lDh0U6Jo1oERF 3jUcqliIjCgZNK62NzKkWiF7ARfwsR16hg+AZl4qi/KiBagthHl98dWCysgUOEAjSBy+ DAgpqR/lao/s2sl+bp967HfPGvGjz4RouA/01UBevHT3zEGJVep78t2N2a6LLVUUQLPN nmVTT/M36WsunuU+IZ0PRHk8p0JQ9THlp9PXtGbOJhDmmdVOKp4FMvLHuLTZ+XrUcnUg WHzw== 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=9MWoWYpPNtKdOh5OWWChfWWdIEIaCiLObL+8E7CLiZg=; b=aJsyxapQO2vxSXSLD+C7OLvrjmaKr7dTpoK8CpyD7UZkN81JxhWEbS3vJkLGUYKbdI Ta3P9b9xFK1DErjLyfZT8EdDFiC4O+o2vHhRBKWkB5mtEB1YogZWUrXLwBDG+ylmih+b j0H6ij4+6XNP3raubtII7CWzStsUaHMGuyfgBm3GMI0/sOYWyenHil2kzL1HqzkHdQFQ mNqU6B4fJV8xaQbIS0TsoPzCm+DDwSVSf5zOHBvrsdn+/KKE/cm55lWLwZZYZH/8ptvK W42Qt6uUmwhlFgz2vYsTez7k6SWWT16GVCk57vKztjMfRzcuVTC3HtZr2CEdYAuyqony hxrg== X-Gm-Message-State: AOAM530fF3Wolx4Bng/gZUqnqpFlC4MHDDGprJfYAM3oTbLsUJZxrX/+ orz6aJe+0auezW+BnhT7VYmvFlIoBgntcLvthbuUNwsnfPOASICI X-Received: by 2002:a17:907:1ca8:b0:70c:68ce:dade with SMTP id nb40-20020a1709071ca800b0070c68cedademr29505192ejc.723.1654705741762; Wed, 08 Jun 2022 09:29:01 -0700 (PDT) MIME-Version: 1.0 References: <20220608110734.2928245-1-tzungbi@kernel.org> <20220608110734.2928245-20-tzungbi@kernel.org> In-Reply-To: <20220608110734.2928245-20-tzungbi@kernel.org> From: Guenter Roeck Date: Wed, 8 Jun 2022 09:28:49 -0700 Message-ID: Subject: Re: [PATCH v3 19/23] platform/chrome: cros_ec_proto: add Kunit tests for getting cmd mask 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_host_command_version_mask() expects to receive > sizeof(struct ec_response_get_cmd_versions) 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_host_command_version_mask(). > > Note that because the 2 cros_ec_get_host_command_version_mask() use the > same `ver_mask`. cros_ec_proto_test_query_all_no_host_sleep_return0() > polluates the `ver_mask` and returns 0 on the second send_command() to > make sure the second cros_ec_get_host_command_version_mask() doesn't > take the garbage from the previous call. > > 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 | 197 +++++++++++++++++++ > 1 file changed, 197 insertions(+) > > diff --git a/drivers/platform/chrome/cros_ec_proto_test.c b/drivers/platform/chrome/cros_ec_proto_test.c > index eb6d77b95c9f..c988ff1e2a5a 100644 > --- a/drivers/platform/chrome/cros_ec_proto_test.c > +++ b/drivers/platform/chrome/cros_ec_proto_test.c > @@ -980,6 +980,94 @@ static void cros_ec_proto_test_query_all_no_mkbp_return_error(struct kunit *test > } > } > > +static void cros_ec_proto_test_query_all_no_mkbp_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->mkbp_event_supported = 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_addx(test, 0, EC_RES_INVALID_COMMAND, 0); > + KUNIT_ASSERT_PTR_NE(test, mock, NULL); > + } > + > + /* For cros_ec_get_host_command_version_mask() for MKBP. */ > + { > + 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); > + } > + > + /* For cros_ec_get_host_command_version_mask() for MKBP. */ > + { > + struct ec_params_get_cmd_versions *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_GET_CMD_VERSIONS); > + KUNIT_EXPECT_EQ(test, mock->msg.insize, > + sizeof(struct ec_response_get_cmd_versions)); > + KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(*data)); > + > + data = (struct ec_params_get_cmd_versions *)mock->i_data; > + KUNIT_EXPECT_EQ(test, data->cmd, EC_CMD_GET_NEXT_EVENT); > + > + KUNIT_EXPECT_EQ(test, ec_dev->mkbp_event_supported, 0); > + } > +} > + > static void cros_ec_proto_test_query_all_no_host_sleep(struct kunit *test) > { > struct cros_ec_proto_test_priv *priv = test->priv; > @@ -1086,6 +1174,113 @@ static void cros_ec_proto_test_query_all_no_host_sleep(struct kunit *test) > } > } > > +static void cros_ec_proto_test_query_all_no_host_sleep_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->host_sleep_v1 = true; > + > + /* 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_addx(test, 0, EC_RES_INVALID_COMMAND, 0); > + KUNIT_ASSERT_PTR_NE(test, mock, NULL); > + } > + > + /* For cros_ec_get_host_command_version_mask() for MKBP. */ > + { > + struct ec_response_get_cmd_versions *data; > + > + mock = cros_kunit_ec_xfer_mock_add(test, sizeof(*data)); > + KUNIT_ASSERT_PTR_NE(test, mock, NULL); > + > + /* In order to pollute next cros_ec_get_host_command_version_mask(). */ > + data = (struct ec_response_get_cmd_versions *)mock->o_data; > + data->version_mask = 0xbeef; > + } > + > + /* For cros_ec_get_host_command_version_mask() for host sleep v1. */ > + { > + 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); > + } > + > + /* For cros_ec_get_host_command_version_mask() for MKBP. */ > + { > + 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_CMD_VERSIONS); > + KUNIT_EXPECT_EQ(test, mock->msg.insize, > + sizeof(struct ec_response_get_cmd_versions)); > + KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(struct ec_params_get_cmd_versions)); > + } > + > + /* For cros_ec_get_host_command_version_mask() for host sleep v1. */ > + { > + 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_CMD_VERSIONS); > + KUNIT_EXPECT_EQ(test, mock->msg.insize, > + sizeof(struct ec_response_get_cmd_versions)); > + KUNIT_EXPECT_EQ(test, mock->msg.outsize, sizeof(struct ec_params_get_cmd_versions)); > + > + KUNIT_EXPECT_FALSE(test, ec_dev->host_sleep_v1); > + } > +} > + > static void cros_ec_proto_test_query_all_default_wake_mask_return_error(struct kunit *test) > { > struct cros_ec_proto_test_priv *priv = test->priv; > @@ -1274,7 +1469,9 @@ static struct kunit_case cros_ec_proto_test_cases[] = { > KUNIT_CASE(cros_ec_proto_test_query_all_legacy_return0), > KUNIT_CASE(cros_ec_proto_test_query_all_no_mkbp), > KUNIT_CASE(cros_ec_proto_test_query_all_no_mkbp_return_error), > + KUNIT_CASE(cros_ec_proto_test_query_all_no_mkbp_return0), > KUNIT_CASE(cros_ec_proto_test_query_all_no_host_sleep), > + KUNIT_CASE(cros_ec_proto_test_query_all_no_host_sleep_return0), > KUNIT_CASE(cros_ec_proto_test_query_all_default_wake_mask_return_error), > {} > }; > -- > 2.36.1.255.ge46751e96f-goog >