From nobody Mon Jun 8 04:19:59 2026 Received: from mail-dl1-f74.google.com (mail-dl1-f74.google.com [74.125.82.74]) (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 6D6143A9626 for ; Tue, 2 Jun 2026 07:32:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.82.74 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780385530; cv=none; b=DLOWtqVaxATkBfsrRpbaZM7ehwBQouYpgeTzTFgwNuQsxQNBdLUssyef7aR7klQQgry6UZB9VZPuiXGuIbLcAoT7Yqb9Po94qYgwmH9ceCoVyLgtjJoa81UG2LzcIL0mmYUc9NwufPPi1yrDjLIYYje7uE6dNWSs4Iv3odo1v5I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1780385530; c=relaxed/simple; bh=TEcBlkRXP0aLRqSO1xUVAlBdPZbo0AOnZi+UeYmfL3c=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=CUA4DNR98S5bezPFBiCzly3dnKOek6iOpPxS0zoMD5yRtK0fyJK+CvXEkloJSggbXA7364d3u9nI0oWtQf62rzzAuMFA70yFS2p5cUMUh9CdbP9h9wcK7hpIcm6XctiZu7NqJByBQ55qo2/jKbuxXOX2GVlCsI0fubw/1j6K8U8= 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=iaiDsoMU; arc=none smtp.client-ip=74.125.82.74 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="iaiDsoMU" Received: by mail-dl1-f74.google.com with SMTP id a92af1059eb24-137d003cf09so7202143c88.1 for ; Tue, 02 Jun 2026 00:32:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1780385524; x=1780990324; 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=vlKCGIeoP9gFnsy1L4NY9TgahXlL3xTJGu0ES0JouDQ=; b=iaiDsoMUnEVsis6OxBngpoLY7e2r03QcEskjwg9Hpdv2VqW2I4SeZBseU5vboCssjQ qFZ8huhJdzDv1IZ9mXKRP8q4GZYrOScizmnslX2+M0t6XvzlKDx4/nxBe3HU8S/zyIO+ hFkBtfYPBYqJK7skhQvicOTb8tnQiRlbNe7l36VaUqWgvK7WoeJk+tGp0//er7W9zifq EWY3PINAFqfCud5n7G5HgF+aFZJzkKJvjxIyQTrhOJUhLTWPWvv3ZlkoIhdIbwmlQoDt CwwWXmYBzWnhAIobOYIR5H9Ghn4paJTTj4mR3xxb/h+DKjd94TRaUr6f51zW9hd5u+ju kR6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1780385524; x=1780990324; 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=vlKCGIeoP9gFnsy1L4NY9TgahXlL3xTJGu0ES0JouDQ=; b=l87efi8KPn7PCpi3KwfR7RpSvNCsf3wl5BLcsX5sbhBxZWUclOAMkDP3fclvQ6h6YQ VR1KQJvx1XkGr20/mdSJa1TOBSa1tuJ0Y5j8DgnBln6xlnfFVUzWLcabnHpO4OeeFv8x nKq0rYe9vXjx/S9e9v0Xe5WFF4DFSmz7BFc+EpluXIMfNok81afQlhp1yEm0vGjM2yWg 9BLntkK9F1GJXQjzbHYovSnqy4e/1q9ZEQ8dBZchvddEl7CQZt+31RgvB2n92T50WMtJ vItiBLONBXa3olfWRVSlwA/JzoCvXu+sWSNSLyjfe67tTt6FV76ZGbVWz2IE43GQSH+R HPWw== X-Forwarded-Encrypted: i=1; AFNElJ9m2bDtcAWofO3Mpj2/xFqnGHXjNBVA24Qnxz3vG4SoBAsvuxr++BKPMZwzs7Z3shA4bmzRhN1dONNvXl4=@vger.kernel.org X-Gm-Message-State: AOJu0Yxo5NFKe3XqcgQEgpFpJoilkaxAFP8ETiWcts13xJPyZC8YS8g6 Nuc9ND0/L6aMXmtoMsho8Xsxcp5GyWTEdknqfq/+pvIuFhOLbyjvBltZERmIhFmZ7S4lyHN/gNz b5n0KnffoTA== X-Received: from dly11-n2.prod.google.com ([2002:a05:701b:204b:20b0:137:ee1d:b1c2]) (user=irogers job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7022:671e:b0:12f:c7c3:f5ab with SMTP id a92af1059eb24-137d3f18decmr7234119c88.2.1780385524021; Tue, 02 Jun 2026 00:32:04 -0700 (PDT) Date: Tue, 2 Jun 2026 00:31:27 -0700 In-Reply-To: <20260602073132.2653307-1-irogers@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260601061401.1541457-1-irogers@google.com> <20260602073132.2653307-1-irogers@google.com> X-Mailer: git-send-email 2.54.0.929.g9b7fa37559-goog Message-ID: <20260602073132.2653307-13-irogers@google.com> Subject: [PATCH v7] perf test: Skip shebang and SPDX comments in shell test descriptions 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 extracting shell test descriptions in tests-scripts.c, the parser skipped the first line assuming it was the shebang (#!/bin/sh) and then read the first comment line on line 2 as the test description. However, checkpatch.pl expects shell scripts to declare their SPDX license identifier on line 2 (# SPDX-License-Identifier: ...). This caused the test harness to extract the SPDX license string as the test description. Refactor shell_test__description to use io__getline, skipping both shebang and SPDX comment lines. This allows shell tests to include standard SPDX headers without breaking test suite description extraction. Assisted-by: Gemini-CLI:Google Gemini 3 Signed-off-by: Ian Rogers --- tools/perf/tests/tests-scripts.c | 82 ++++++++++++++++++-------------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/tools/perf/tests/tests-scripts.c b/tools/perf/tests/tests-scri= pts.c index f18c4cd337c8..ec24a1d974ae 100644 --- a/tools/perf/tests/tests-scripts.c +++ b/tools/perf/tests/tests-scripts.c @@ -31,6 +31,7 @@ static int shell_tests__dir_fd(void) { struct stat st; char path[PATH_MAX], path2[PATH_MAX], *exec_path; + ssize_t len; static const char * const devel_dirs[] =3D { "./tools/perf/tests/shell", "./tests/shell", @@ -47,13 +48,17 @@ static int shell_tests__dir_fd(void) } =20 /* Use directory of executable */ - if (readlink("/proc/self/exe", path2, sizeof path2) < 0) + len =3D readlink("/proc/self/exe", path2, sizeof(path2) - 1); + if (len < 0) return -1; + path2[len] =3D '\0'; /* Follow another level of symlink if there */ if (lstat(path2, &st) =3D=3D 0 && (st.st_mode & S_IFMT) =3D=3D S_IFLNK) { - scnprintf(path, sizeof(path), path2); - if (readlink(path, path2, sizeof path2) < 0) + scnprintf(path, sizeof(path), "%s", path2); + len =3D readlink(path, path2, sizeof(path2) - 1); + if (len < 0) return -1; + path2[len] =3D '\0'; } /* Get directory */ p =3D strrchr(path2, '/'); @@ -78,43 +83,50 @@ static int shell_tests__dir_fd(void) static char *shell_test__description(int dir_fd, const char *name) { struct io io; - char buf[128], desc[256]; - int ch, pos =3D 0; + char buf[128], *line =3D NULL; + size_t line_len =3D 0; + ssize_t len; + char *desc =3D NULL; + const char *spdx =3D "SPDX-License"; =20 io__init(&io, openat(dir_fd, name, O_RDONLY), buf, sizeof(buf)); if (io.fd < 0) return NULL; =20 - /* Skip first line - should be #!/bin/bash Shebang */ - if (io__get_char(&io) !=3D '#') - goto err_out; - if (io__get_char(&io) !=3D '!') - goto err_out; - do { - ch =3D io__get_char(&io); - if (ch < 0) - goto err_out; - } while (ch !=3D '\n'); - - do { - ch =3D io__get_char(&io); - if (ch < 0) - goto err_out; - } while (ch =3D=3D '#' || isspace(ch)); - while (ch > 0 && ch !=3D '\n') { - desc[pos++] =3D ch; - if (pos >=3D (int)sizeof(desc) - 1) + while ((len =3D io__getline(&io, &line, &line_len)) > 0) { + char *p =3D line; + + /* Skip leading whitespace */ + while (*p && isspace(*p)) + p++; + + /* Must be a comment */ + if (*p !=3D '#') + continue; + p++; + + /* Skip shebang or SPDX lines */ + if (*p =3D=3D '!' || (strstr(p, spdx) && strstr(p, "-Identifier:"))) + continue; + + /* Skip whitespace after # */ + while (*p && isspace(*p)) + p++; + + /* If we found non-empty text, this is the description! */ + if (*p && *p !=3D '\n') { + char *end =3D p + strlen(p); + + while (end > p && isspace(end[-1])) + end--; + *end =3D '\0'; + desc =3D strdup(p); break; - ch =3D io__get_char(&io); + } } - while (pos > 0 && isspace(desc[--pos])) - ; - desc[++pos] =3D '\0'; - close(io.fd); - return strdup(desc); -err_out: + free(line); close(io.fd); - return NULL; + return desc; } =20 /* Is this full file path a shell script */ @@ -178,9 +190,9 @@ static void append_script(int dir_fd, const char *name,= char *desc, char *exclusive; =20 snprintf(link, sizeof(link), "/proc/%d/fd/%d", getpid(), dir_fd); - len =3D readlink(link, filename, sizeof(filename)); - if (len < 0) { - pr_err("Failed to readlink %s", link); + len =3D readlink(link, filename, sizeof(filename) - 1); + if (len < 0 || (size_t)len >=3D sizeof(filename) - strlen(name) - 2) { + pr_err("Failed to readlink %s or path too long", link); return; } filename[len++] =3D '/'; --=20 2.54.0.929.g9b7fa37559-goog