From nobody Sat Feb 7 21:05:41 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D0F1C83F12 for ; Wed, 30 Aug 2023 00:22:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238679AbjH3AWD (ORCPT ); Tue, 29 Aug 2023 20:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236383AbjH3AVi (ORCPT ); Tue, 29 Aug 2023 20:21:38 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B8432CC2 for ; Tue, 29 Aug 2023 17:21:35 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id 3f1490d57ef6-d74829dd58fso5869971276.1 for ; Tue, 29 Aug 2023 17:21:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1693354895; x=1693959695; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=WME0Ze+ifFaCbrf4pzxhX55YR+juKZdsW7/o/oy5q0k=; b=y8quO5lllfzlZGcKwGqxOV5I9stXyiKbJPccMoAVHDYj03EobaTUcG1Vb4xRDLCxMO OIgoYB9ktpZowlKqI4Wvtsk0eBoSgrnJvqPRWkbg6FClX7uFwta9nk8q7iVJ1OJTJRJx Zm39mufGuQ9gyaXJryN8ONYpv9eBX6TNfQQoGytQWjmig++yA260T5QzzKeMHEUP4lt+ fCbdfO6KLuERtCYzDsSzqf+CDj867+mZcZhxAKx3d3v56JAxwHf3Q/oNSpci0JSOgGN4 3Fdh3RRO0YmgWuMEmOARKNCNj7SIwmNKj8UnfgCDY1d0GiREMGMD8j2whRkQGpofMORP k7SQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693354895; x=1693959695; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=WME0Ze+ifFaCbrf4pzxhX55YR+juKZdsW7/o/oy5q0k=; b=RIlTzkZwoLr+5Kh3CsLL+gnYZIiCJ22nChPUf9ka0R9vrJjJZYpxo1hmoIMDgGWcCQ wAg+d12ImLHj1K13EajU/UrzlbYbimB+VOJnXZ72UKoVeBBBSD36mc8jUTTKqrADL38m m7xSx+u2p1dyJD5eLVLyfQIw8j6mplQowikOIr4chRe01IkOCB74gNJLluSyy6B2h6M/ eCIseh3TqUmn8CHuEqXxTOrVKOH5r1Zwkp6TjfbydaULsd9iuDUTdOQojacDRY2PL5k2 w7S5nFDHN3mhT8sHBl9sT2EVdUDf77NxOCEU8asIKfRd++TSoNYp5Nu/uBWwBxWGjJom C0OA== X-Gm-Message-State: AOJu0YzbYGnhnZ1c3CHikkDFZ3lcX7cZ/2JYxLyFOqJyIvWpJ/RxOqO5 dqV8u3CaXgitgN9Po0Fa6W0bGmp1QJ6QOQ== X-Google-Smtp-Source: AGHT+IGJmzX2TfHubw3EZ/rAHp1W6ncpiGu7wRHuL61OO2aYXO8SzIQTL3UsdLsq+Un71/uvbyPbZqGaonDW0w== X-Received: from slicestar.c.googlers.com ([fda3:e722:ac3:cc00:4f:4b78:c0a8:20a1]) (user=davidgow job=sendgmr) by 2002:a25:dbce:0:b0:c15:cbd1:60da with SMTP id g197-20020a25dbce000000b00c15cbd160damr18870ybf.6.1693354895079; Tue, 29 Aug 2023 17:21:35 -0700 (PDT) Date: Wed, 30 Aug 2023 08:21:15 +0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.42.0.283.g2d96d420d3-goog Message-ID: <20230830002116.3768675-1-davidgow@google.com> Subject: [PATCH] kunit: test: Make filter strings in executor_test writable From: David Gow To: Shuah Khan , Rae Moar , Guenter Roeck Cc: Brendan Higgins , kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, David Gow Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" KUnit's attribute filtering feature needs the filter strings passed in to be writable, as it modifies them in-place during parsing. This works for the filters passed on the kernel command line, but the string literals used in the executor tests are at least theoretically read-only (though they work on x86_64 for some reason). s390 wasn't fooled, and crashed when these tests were run. Use a 'char[]' instead, (and make an explicit variable for the current filter in parse_filter_attr_test), which will store the string in a writable segment. Fixes: 76066f93f1df ("kunit: add tests for filtering attributes") Closes: https://lore.kernel.org/linux-kselftest/55950256-c00a-4d21-a2c0-cf9= f0e5b8a9a@roeck-us.net/ Signed-off-by: David Gow Reviewed-by: Rae Moar Tested-by: Guenter Roeck --- lib/kunit/executor_test.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/kunit/executor_test.c b/lib/kunit/executor_test.c index 4084071d0eb5..b4f6f96b2844 100644 --- a/lib/kunit/executor_test.c +++ b/lib/kunit/executor_test.c @@ -119,7 +119,7 @@ static void parse_filter_attr_test(struct kunit *test) { int j, filter_count; struct kunit_attr_filter *parsed_filters; - char *filters =3D "speed>slow, module!=3Dexample"; + char filters[] =3D "speed>slow, module!=3Dexample", *filter =3D filters; int err =3D 0; =20 filter_count =3D kunit_get_filter_count(filters); @@ -128,7 +128,7 @@ static void parse_filter_attr_test(struct kunit *test) parsed_filters =3D kunit_kcalloc(test, filter_count, sizeof(*parsed_filte= rs), GFP_KERNEL); for (j =3D 0; j < filter_count; j++) { - parsed_filters[j] =3D kunit_next_attr_filter(&filters, &err); + parsed_filters[j] =3D kunit_next_attr_filter(&filter, &err); KUNIT_ASSERT_EQ_MSG(test, err, 0, "failed to parse filter '%s'", filters= [j]); } =20 @@ -154,6 +154,7 @@ static void filter_attr_test(struct kunit *test) .start =3D subsuite, .end =3D &subsuite[2], }; struct kunit_suite_set got; + char filter[] =3D "speed>slow"; int err =3D 0; =20 subsuite[0] =3D alloc_fake_suite(test, "normal_suite", dummy_attr_test_ca= ses); @@ -168,7 +169,7 @@ static void filter_attr_test(struct kunit *test) * attribute is unset and thus, the filtering is based on the parent attr= ibute * of slow. */ - got =3D kunit_filter_suites(&suite_set, NULL, "speed>slow", NULL, &err); + got =3D kunit_filter_suites(&suite_set, NULL, filter, NULL, &err); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start); KUNIT_ASSERT_EQ(test, err, 0); kfree_at_end(test, got.start); @@ -191,12 +192,13 @@ static void filter_attr_empty_test(struct kunit *test) .start =3D subsuite, .end =3D &subsuite[2], }; struct kunit_suite_set got; + char filter[] =3D "module!=3Ddummy"; int err =3D 0; =20 subsuite[0] =3D alloc_fake_suite(test, "suite1", dummy_attr_test_cases); subsuite[1] =3D alloc_fake_suite(test, "suite2", dummy_attr_test_cases); =20 - got =3D kunit_filter_suites(&suite_set, NULL, "module!=3Ddummy", NULL, &e= rr); + got =3D kunit_filter_suites(&suite_set, NULL, filter, NULL, &err); KUNIT_ASSERT_EQ(test, err, 0); kfree_at_end(test, got.start); /* just in case */ =20 @@ -211,12 +213,13 @@ static void filter_attr_skip_test(struct kunit *test) .start =3D subsuite, .end =3D &subsuite[1], }; struct kunit_suite_set got; + char filter[] =3D "speed>slow"; int err =3D 0; =20 subsuite[0] =3D alloc_fake_suite(test, "suite", dummy_attr_test_cases); =20 /* Want: suite(slow, normal), NULL -> suite(slow with SKIP, normal), NULL= */ - got =3D kunit_filter_suites(&suite_set, NULL, "speed>slow", "skip", &err); + got =3D kunit_filter_suites(&suite_set, NULL, filter, "skip", &err); KUNIT_ASSERT_NOT_ERR_OR_NULL(test, got.start); KUNIT_ASSERT_EQ(test, err, 0); kfree_at_end(test, got.start); --=20 2.42.0.283.g2d96d420d3-goog