From nobody Mon Jun 8 07:23:01 2026 Received: from mail-dy1-f201.google.com (mail-dy1-f201.google.com [74.125.82.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7CD8230B525 for ; Thu, 4 Jun 2026 22:06:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780610794; cv=none; b=kzTnBiIrRG/9gWF20MHODV8Q6jgNETL6lE7ObZvMTZ1Yr3ntj69vkoB5yod3p6TFnRDSa+j6oM4gcDH26OOLuCq8RZb8kZYnXuYnHNNgWHlIZXgDz4hppIgkmGdmLvIntlaUPTOwlQ0GmddQTY5l64+Dwskurus+5mzdEncUiwk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780610794; c=relaxed/simple; bh=l/iGF1eiicn0gyOFHtPdUcmiqCfkLzEyUFFsiLKcBJc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=uenyspMDvcDkUIaf3PZZQpii2gEUC+EZTajY3CPSGGoK9pd/XYqr7TLYJo5hCd9Pmud6pPsJhoC7DORHAX5FQwXBB485/gHssL2+3/i7GGgSvEoc2w6hWKf/PPPCSiYpZNyj1/do+48bOXfqnRJmLM60OXSD6uHIUz2+pi8e7rY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=BNH7Vw2K; arc=none smtp.client-ip=74.125.82.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--irogers.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="BNH7Vw2K" Received: by mail-dy1-f201.google.com with SMTP id 5a478bee46e88-304dd917645so1128102eec.1 for ; Thu, 04 Jun 2026 15:06:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780610792; x=1781215592; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=IwUobqll5CG8S8DaYyJ6P1PbcVuywzyfMBEqRscWVk0=; b=BNH7Vw2Kgf+cwS4DTSn5aWItpWBUuEIWEeI15OQw2djg3LkrkWzjmpapU90vVMNzlO ShifD/WOU3zMXpgRBP3LXt9rciUbXzweMyf6wJP27ljZZAcTFxjapb9XW4S/OQVtJCi1 wQcr3CPrMdPPYc3T/5SPxZ/scX+SGISNmZ0AyWzGeGQWgi3EUHm/IKXjhjra5zWeud39 bGHcEqR5PlEvHQ33YoFd3yI1B3W+RrdEtzEWNRrh+lb23UI6M1bAY5HTq9MWMTP1Wbti l498INFnX6d61Ik9w0oyZBulH8mWkEbLCUuv8VyJ089e9ET3/4/Piy4CHHdWJtaXqMoa TyiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780610792; x=1781215592; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IwUobqll5CG8S8DaYyJ6P1PbcVuywzyfMBEqRscWVk0=; b=FgwbM5PX1W+BlADhdjcXTS6joGVQAVKETaZLwQOfV/q/rwk2BEvpQ3TEkMygGIjSiF P2c2JHsVQ50xsWdewbT3gxs0MhxBLTtqPJUGi8/xAMlk+iofqTmHXU7zs2GqeTSOPvsv ziGLjn3umTxt3ELwzGvK9BBZWM71wyFsXgInCQJBSLln4Y8yGE8L90gf9ZwpJwYkiJvK Wa68iFe2f+8VI0MXnYTJrOfBoSd5Fyj5J5HBiq1vrH+ioxxq3PVMx9LATuD+DynVn31l IGx0Urbv9ofFt1WniVWjvQ3BKZmQQXt9ovysWLW9O4grRodaX+jVKmO/RW7LM1Kvapvf 3z9Q== X-Forwarded-Encrypted: i=1; AFNElJ9H/iVIJpwP6Y7uBbanJPtueIJHGB3b8/FYcFRRyUmqGLDozbrNYzXpoIJDKR/KcfRAVXmHGAcYeVgpEf4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz8TBvMaHhaUiESZqR1dGjmo7m3zPPgnDyS8JYZ6tO7E4Nue0iz 7Frytt2AWIgysHLCJURWt6Rsjw+WrHvQ7WRflk6mCAmqOPi/2o14BUFIrqbfmHSmb2EsTOJMlLa 36EL1ZQl+YA== X-Received: from dlbqq4.prod.google.com ([2002:a05:7022:ed04:b0:137:fec5:89b1]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:f81:b0:137:4062:4c1b with SMTP id a92af1059eb24-138066d1951mr393721c88.11.1780610792212; Thu, 04 Jun 2026 15:06:32 -0700 (PDT) Date: Thu, 4 Jun 2026 15:06:27 -0700 In-Reply-To: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: X-Mailer: git-send-email 2.54.0.1032.g2f8565e1d1-goog Message-ID: <20260604220627.902635-1-irogers@google.com> Subject: [PATCH v10] perf test: Truncate printed test descriptions dynamically to avoid terminal wrapping From: Ian Rogers To: irogers@google.com, acme@kernel.org, namhyung@kernel.org Cc: adrian.hunter@intel.com, alexander.shishkin@linux.intel.com, james.clark@linaro.org, jolsa@kernel.org, linux-kernel@vger.kernel.org, linux-perf-users@vger.kernel.org, mingo@redhat.com, peterz@infradead.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" When test descriptions are extremely long (e.g., the truncated perf.data graceful handling test is 103 characters long), they wrap across terminal boundaries. Because the ANSI escape code to delete the line (PERF_COLOR_DELETE_LINE) only clears a single terminal line, visual wrapping leaves orphan wrapped lines on the screen, which results in the test description being printed multiple times. Resolve this by checking the terminal width (get_term_dimensions) and dynamically truncating the printed test description to fit within the available columns, leaving safety space for the prefix index and status suffix. Also, remove the width padding from the test suite headers which do not display inline status messages. This prevents their trailing colons from wrapping onto new lines on standard width terminals. Finally, avoid GCC 16's -Wformat-truncation warnings by delegating the description padding to pr_info's %-*s format specifier instead of padding within a temporary buffer, and clamp the truncation limit to the temporary buffer's size. JUnit XML output and the failure summary report still print the full, untruncated test descriptions. Assisted-by: Gemini-CLI:Google Gemini 3.1 Pro Signed-off-by: Ian Rogers --- tools/perf/tests/builtin-test.c | 66 +++++++++++++++++++++++++++++---- 1 file changed, 59 insertions(+), 7 deletions(-) diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-tes= t.c index b64fc2204f22..fd83ca2bda12 100644 --- a/tools/perf/tests/builtin-test.c +++ b/tools/perf/tests/builtin-test.c @@ -20,6 +20,8 @@ #include #include #include +#include +#include "util/term.h" #include "builtin.h" #include "config.h" #include "hist.h" @@ -404,19 +406,69 @@ static char *xml_escape(const char *str) return res ? res : strdup(""); } =20 +static const char *format_test_description(const char *desc, int max_desc_= width, + char *buf, size_t buf_sz) +{ + int len =3D strlen(desc); + + /* + * Clamp to buf_sz to prevent GCC format-truncation warnings + * when terminal width is very large. + */ + if (max_desc_width >=3D (int)buf_sz) + max_desc_width =3D buf_sz - 1; + + if (len > max_desc_width) { + snprintf(buf, buf_sz, "%.*s...", max_desc_width - 3, desc); + return buf; + } + return desc; +} + static int print_test_result(struct test_suite *t, int curr_suite, int cur= r_test_case, int result, int width, int running, const char *err_output, double elapsed) { + char desc_buf[256]; + const char *desc =3D test_description(t, curr_test_case); + struct winsize ws; + int max_desc_area_width; + int target_desc_area_width; + int desc_padding; + + get_term_dimensions(&ws); + /* + * Total terminal columns minus space for status e.g. " Running (12 activ= e)" + * which is 20 chars, plus a margin of 3 chars =3D 23 chars. + */ + max_desc_area_width =3D ws.ws_col - 23; + if (max_desc_area_width < 40) + max_desc_area_width =3D 40; + + /* Standard test has prefix "%3d: " which is 5 chars */ + target_desc_area_width =3D width + 5; + if (target_desc_area_width > max_desc_area_width) + target_desc_area_width =3D max_desc_area_width; + if (test_suite__num_test_cases(t) > 1) { char prefix[32]; int len =3D snprintf(prefix, sizeof(prefix), "%3d.%1d:", curr_suite + 1, curr_test_case + 1); - int subw =3D len >=3D 4 ? width + 4 - len : width; =20 - pr_info("%s %-*s:", prefix, subw, test_description(t, curr_test_case)); - } else - pr_info("%3d: %-*s:", curr_suite + 1, width, test_description(t, curr_te= st_case)); + desc_padding =3D target_desc_area_width - (len + 1); + if (desc_padding < 20) + desc_padding =3D 20; + + desc =3D format_test_description(desc, desc_padding, desc_buf, sizeof(de= sc_buf)); + pr_info("%s %-*s:", prefix, desc_padding, desc); + } else { + desc_padding =3D target_desc_area_width - 5; + if (desc_padding < 20) + desc_padding =3D 20; + + desc =3D format_test_description(desc, desc_padding, desc_buf, sizeof(de= sc_buf)); + pr_info("%3d: %-*s:", curr_suite + 1, desc_padding, desc); + } =20 switch (result) { case TEST_RUNNING: @@ -700,7 +752,7 @@ static void finish_test(struct child_test **child_tests= , int running_test, int c * sub test names. */ if (test_suite__num_test_cases(t) > 1 && curr_test_case =3D=3D 0) - pr_info("%3d: %-*s:\n", curr_suite + 1, width, test_description(t, -1)); + pr_info("%3d: %s:\n", curr_suite + 1, test_description(t, -1)); =20 /* * Busy loop reading from the child's stdout/stderr that are set to be @@ -976,7 +1028,7 @@ static int finish_tests_parallel(struct child_test **c= hild_tests, size_t num_tes if (next_child) { if (test_suite__num_test_cases(next_child->test) > 1 && last_suite_printed !=3D next_child->suite_num) { - pr_info("%3d: %-*s:\n", next_child->suite_num + 1, width, + pr_info("%3d: %s:\n", next_child->suite_num + 1, test_description(next_child->test, -1)); last_suite_printed =3D next_child->suite_num; } @@ -1040,7 +1092,7 @@ static int finish_tests_parallel(struct child_test **= child_tests, size_t num_tes =20 if (test_suite__num_test_cases(child->test) > 1 && last_suite_printed !=3D child->suite_num) { - pr_info("%3d: %-*s:\n", child->suite_num + 1, width, + pr_info("%3d: %s:\n", child->suite_num + 1, test_description(child->test, -1)); last_suite_printed =3D child->suite_num; } --=20 2.54.0.1032.g2f8565e1d1-goog