Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3712481pxb; Mon, 24 Jan 2022 16:05:08 -0800 (PST) X-Google-Smtp-Source: ABdhPJwPg0cgL/umbdR/e8qaOufCpOSgEnqKLbzLyIc22QrTsWBvVH63bFtN8eA0xq+TiKwXJwLa X-Received: by 2002:aa7:9217:0:b0:4c2:5a97:31e9 with SMTP id 23-20020aa79217000000b004c25a9731e9mr15995212pfo.16.1643069108047; Mon, 24 Jan 2022 16:05:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643069108; cv=none; d=google.com; s=arc-20160816; b=Ee+p70K3GXZxc9j1urCTaQf0Lgtp2V+UduJlV+T+QViNBCqM5xDpnPk+l+aC225CnT WzsKy9Pqz2laCbgPPovQsvoiy2Cyq5nhnYj5AnVKfa7bdL/IQ+ld5YQlnWz+Z84i5utD 1niKl+j0SxuajPiJpQdbafNOU2i9yxoFkxxKRyGUjhpF6p9xPWVf9/Zl6GV0ludThGQE 07J/DCa9fVQd66g3eaaTFjfS5RG2Va3ARyTTTDX2dKh3mPAhAt02nqBk5jlvdOHyKNCw 66zVJFBHm9grUauDGoTOvPD8+qX/K4bh9Cq9Hsd7H+/kmFYMRHJb3/HOB93IaS+c70gB mDpQ== 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=4n10zjwuvDrf7xskVRIPakZ+aBskVjHYZo/WyAqviYo=; b=u7OxacrCh9ouWczQvRJq4fey5fPtP2c1twWJgyhg7Tetgg2qWSu3jMd+32vX6Pd9f+ +FrR3EgvvJbaIlAeBr33lSPtH6nctgbbbffWV0ANx6TZ2ATaEd1scwsiCNRqJGEhoMXs 9hLDD+D9/3QekPFD6/AVLP7E9GH6pYRzgOvLLNUqC5gl2jBH5+R2edioHoQ4TdRF3xOC d9yADL7IrVh9/VVfVL5j50wQUhjp4KI+GIHjlIzkOXW118pcil1yXVL8zSjUqJlDmLSi 3yjEeTxMNo2Rx1ynOeyxaolwpwEk9kGqH1jbV9/MHFBtdfESBSQwC60k143t265sFp4c ssiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=AXEjFp9v; 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 pc9si706178pjb.67.2022.01.24.16.04.55; Mon, 24 Jan 2022 16:05:08 -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=AXEjFp9v; 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 S2367373AbiAXXzP (ORCPT + 99 others); Mon, 24 Jan 2022 18:55:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1846529AbiAXXQP (ORCPT ); Mon, 24 Jan 2022 18:16:15 -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 3BB79C0617BB; Mon, 24 Jan 2022 13:25:33 -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 027AEB811A2; Mon, 24 Jan 2022 21:25:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1FEF8C340E5; Mon, 24 Jan 2022 21:25:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643059530; bh=l5m0JNrwApBjUgpOL2jCcyrk+wjkCLYERdR8P9Cx/Vw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AXEjFp9vPfYuvNSqweUSV5h6LJlR8Vx35kMrME0Ep3SnDqDTcvBxC8m9f4FCnJJhO Jn/lLoCmDErfWipqRlN6QoILlsGMVegnSbwN4gG4y/TDnQ8P7Nir65fOsP43uCRcLu /Jb9l9xXNMfA0NN18dG2P5S402XFh9M5z3ioR32U= 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.16 0646/1039] kunit: Dont crash if no parameters are generated Date: Mon, 24 Jan 2022 19:40:35 +0100 Message-Id: <20220124184147.064749898@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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 3bd741e50a2d3..f96498ede2cc5 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