From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F21C9345EB4 for ; Fri, 14 Aug 2026 13:55:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786715757; cv=none; b=CVnK7RgGfhO3CVe3+GqYNxIhGpASk/vBWa/9QVx7mjqb5oOQpZfgG+7tLh3bPG7cJgc5WNUdSRpuI6+KC0qB6x9uxcx9jlZEEylXnkVl+tsgBk9M/n0i7QKqxWa7SvItbB1nCq/jOaOkc70C7uRk0uht4iDJ+yqWg1NP3ak74nw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786715757; c=relaxed/simple; bh=Kq5E/r9tg+1yGMrhP87SYXj2ZfJSQrGUexdSTHbexAU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=p5j/FTOF+2604Pz80QUDtkma9bwwapC9PRiFO+5I2XbAQSA10cAZXn+GBUCAfisZoSVkg7/YDIv+5OHTkYaQzPy5AT5y51f39s1DmV4bfduslDoUr3iLTZdzdzbE2BPz9QiqOA18ToexactbnWAip6DRidCt5VuiZvjRzP/KgcM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Pict9MUe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Pict9MUe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1786715751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XjtevNBfIqkJxOx4BwwiGXQRrfIgcwR4eI1yjAuHNrU=; b=Pict9MUe+Oaz6XmU64mltIWRldgUvGcSHfuvUjTqoaWcP5hZpqqyXs4KA2wJsVE5zxuhzY a0gGu9WrdgK9r2PkJt+DCsFuq2ciIz/kEbib7A+miRemmQGX0MpoXBjeiwxZGp8QjH9LJ8 4ZO9UhfUqqzArxgZdcWwfYKNYC0hnHs= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-513-arhCGr2KOriDueH4imAo1w-1; Fri, 14 Aug 2026 09:55:48 -0400 X-MC-Unique: arhCGr2KOriDueH4imAo1w-1 X-Mimecast-MFC-AGG-ID: arhCGr2KOriDueH4imAo1w_1786715747 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8AD601800115; Fri, 14 Aug 2026 13:55:47 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.44.33.92]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 74629180049F; Fri, 14 Aug 2026 13:55:44 +0000 (UTC) From: Tomas Glozar To: Steven Rostedt , Tomas Glozar Cc: John Kacur , Luis Goncalves , Crystal Wood , Costa Shulyupin , Wander Lairson Costa , LKML , linux-trace-kernel Subject: [PATCH 4/5] rtla/tests: Add unit test for cpu_list_iterate() Date: Fri, 14 Aug 2026 15:55:10 +0200 Message-ID: <20260814135511.2207190-5-tglozar@redhat.com> In-Reply-To: <20260814135511.2207190-1-tglozar@redhat.com> References: <20260814135511.2207190-1-tglozar@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 cpu_list_iterate() was split out of parse_cpu_set() to hold shared code between it and the newly added function get_possible_cpus(). As its semantics are more complex than parse_cpu_set() - it calls a callback on each element of the list, with possible abort on failure, while parse_cpu_set() cares only about the set defined by the list - it deserves its own test. Test the callback being called correctly as well as the return value and early break on different combinations of comma-separated numbers and ranges. Signed-off-by: Tomas Glozar --- tools/tracing/rtla/tests/unit/utils.c | 62 +++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/tools/tracing/rtla/tests/unit/utils.c b/tools/tracing/rtla/tests/unit/utils.c index ce53cab494575..0cb5e217c56eb 100644 --- a/tools/tracing/rtla/tests/unit/utils.c +++ b/tools/tracing/rtla/tests/unit/utils.c @@ -34,6 +34,67 @@ START_TEST(test_strtoi) } END_TEST +struct cpu_list_iterate_cb_data { + int index; + int *values; +}; + +static int cpu_list_iterate_callback(int cpu, void *data) +{ + struct cpu_list_iterate_cb_data *cb_data = data; + + ck_assert_int_eq(cpu, cb_data->values[cb_data->index++]); + + return 0; +} + +static int cpu_list_iterate_callback_error(int cpu, void *data) +{ + struct cpu_list_iterate_cb_data *cb_data = data; + + if (cpu > 10) + return -42; + + ck_assert_int_eq(cpu, cb_data->values[cb_data->index++]); + + return 0; +} + +START_TEST(test_cpu_list_iterate) +{ + struct cpu_list_iterate_cb_data cb_data; + int test_data_1[] = {1, 2, 3, 4}; + int test_data_2[] = {1, 2, 10, 11, 12}; + + cb_data.index = 0; + + cb_data.values = test_data_1; + ck_assert_int_eq(cpu_list_iterate("1,2,3,4", cpu_list_iterate_callback, &cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index = 0; + ck_assert_int_eq(cpu_list_iterate("1-4", cpu_list_iterate_callback, &cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index = 0; + ck_assert_int_eq(cpu_list_iterate("1,2-3,4", cpu_list_iterate_callback, &cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index = 0; + ck_assert_int_eq(cpu_list_iterate("1-3,4", cpu_list_iterate_callback, &cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index = 0; + ck_assert_int_eq(cpu_list_iterate("1,2-4", cpu_list_iterate_callback, &cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + + cb_data.index = 0; + ck_assert_int_eq(cpu_list_iterate("1,2-4", cpu_list_iterate_callback_error, &cb_data), 4); + ck_assert_int_eq(cb_data.index, 4); + cb_data.index = 0; + cb_data.values = test_data_2; + ck_assert_int_eq(cpu_list_iterate("1,2,10-12", cpu_list_iterate_callback_error, &cb_data), + -42); + ck_assert_int_eq(cb_data.index, 3); +} +END_TEST + START_TEST(test_parse_cpu_set) { cpu_set_t set; @@ -98,6 +159,7 @@ Suite *utils_suite(void) TCase *tc = tcase_create("core"); tcase_add_test(tc, test_strtoi); + tcase_add_test(tc, test_cpu_list_iterate); tcase_add_test(tc, test_parse_cpu_set); tcase_add_test(tc, test_parse_prio); -- 2.55.0