Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3677753pxb; Mon, 24 Jan 2022 15:07:41 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/9aNkje9078Cgt4fNBMEFQz0jGGaWVyKK3wDGxjVHo6kCyxVTkq/HhHz7od1IC6nTZjMO X-Received: by 2002:a17:902:be15:b0:149:a608:7098 with SMTP id r21-20020a170902be1500b00149a6087098mr16058402pls.63.1643065661041; Mon, 24 Jan 2022 15:07:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643065661; cv=none; d=google.com; s=arc-20160816; b=FGXzgMTt/ZhakES7pGjH3s+sKpMjWOj8LklzB9avpLLDDcACtMEWm6FVDuElNXdJB4 f1um2IkVUXqq94+d9knh0pnvYZNdg5DQzovzq0Z/QhsfGeq19kZbcmmjUQCFNM7SsaaW OfX5UEIIppk+ajUz6O5OHstLNQ5t7D/d9ArcpGM/h/BojJwiKjgeIPr0JkRpELZTkFAN fKMwVVp4sn6nR7wrwhQ3FW5EVr/ou/28wzEUuF4tssDCb0IK/PsUJiDiCUYeWvevI46j VUkoOCfW6YNa4y2kzTCwQ4IVJ1fgOFBumoIbcM8R8H6Bv/QBVZxxY5NkJupVdwKGnc75 7dKQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JOqlMDGD9vUOyVGiEIGHVsthjkotPeg/upIjaJmtj6Q=; b=zKOs03biglET6jANQn1gKz+Z17eehFtM2jJeihrhBTIfn5Wr8vnjpZ/2n9r2wXsmF4 c9xkg4zoJEBi3whC7OHqYjFWIFfmcFxEynTaM88moxnoGTH8WjYlaFpQOV4S76F9Evn5 2/MkWq1lZiG6Tpt0/e5u2tKVghQoHDP3rG2kRtW3s/E2YjAo624wWnhyKK+a3F4gV65r nWFAHy7W/SGjKWI21dO/QZqMOMq7yWvgjE0OQ4/t9xR9tFqF9m7ZGcOV/2mx9hkgUWY2 XKCPpFFunSZHChzkgpYlbVeKZfSep6+hRu5SvO2weg7FKQcYZfHzRLSlYzqFr2CNX+AR DWVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VlnZ9FEF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q4si17137549plh.423.2022.01.24.15.07.29; Mon, 24 Jan 2022 15:07:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=VlnZ9FEF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1843029AbiAXXDM (ORCPT + 99 others); Mon, 24 Jan 2022 18:03:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60068 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1577048AbiAXV5L (ORCPT ); Mon, 24 Jan 2022 16:57:11 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 407C6C02C307; Mon, 24 Jan 2022 12:38:50 -0800 (PST) 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 AB910B811FB; Mon, 24 Jan 2022 20:38:48 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D935BC340E5; Mon, 24 Jan 2022 20:38:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643056727; bh=uSOMnpLBoWbmn1u3zPszgvPwiLRvJiLR/eIsGJPtN6k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=VlnZ9FEFV8Z/vlL5DcAMmrV91gnMG2/FH1b8mLNbpap387C2v+lxDVR2ytt8xSx8r DSco0Tv/RHCnJJoTw5AhxhJ/r8Od0AbdGJfcPT0gYKX9WsaJjW0T2SDnzmQ/5ydIbF WtZPMkC8yCBC5R3qiIWfz6U1JR4zFwj8zAoOuH5o= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Daniel Latypov , David Gow , Brendan Higgins , Shuah Khan , Sasha Levin Subject: [PATCH 5.15 547/846] kunit: Dont crash if no parameters are generated Date: Mon, 24 Jan 2022 19:41:04 +0100 Message-Id: <20220124184119.893371050@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: David Gow [ Upstream commit 37dbb4c7c7442dbfc9b651e4ddd4afe30b26afc9 ] It's possible that a parameterised test could end up with zero parameters. At the moment, the test function will nevertheless be called with NULL as the parameter. Instead, don't try to run the test code, and just mark the test as SKIPped. Reported-by: Daniel Latypov Signed-off-by: David Gow Reviewed-by: Daniel Latypov Reviewed-by: Brendan Higgins Signed-off-by: Shuah Khan Signed-off-by: Sasha Levin --- lib/kunit/test.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/kunit/test.c b/lib/kunit/test.c index f246b847024e3..9aef816e573c1 100644 --- a/lib/kunit/test.c +++ b/lib/kunit/test.c @@ -504,16 +504,18 @@ int kunit_run_tests(struct kunit_suite *suite) struct kunit_result_stats param_stats = { 0 }; test_case->status = KUNIT_SKIPPED; - if (test_case->generate_params) { + if (!test_case->generate_params) { + /* Non-parameterised test. */ + kunit_run_case_catch_errors(suite, test_case, &test); + kunit_update_stats(¶m_stats, test.status); + } else { /* Get initial param. */ param_desc[0] = '\0'; test.param_value = test_case->generate_params(NULL, param_desc); - } - do { - kunit_run_case_catch_errors(suite, test_case, &test); + while (test.param_value) { + kunit_run_case_catch_errors(suite, test_case, &test); - if (test_case->generate_params) { if (param_desc[0] == '\0') { snprintf(param_desc, sizeof(param_desc), "param-%d", test.param_index); @@ -530,11 +532,11 @@ int kunit_run_tests(struct kunit_suite *suite) param_desc[0] = '\0'; test.param_value = test_case->generate_params(test.param_value, param_desc); test.param_index++; - } - kunit_update_stats(¶m_stats, test.status); + kunit_update_stats(¶m_stats, test.status); + } + } - } while (test.param_value); kunit_print_test_stats(&test, param_stats); -- 2.34.1