From mboxrd@z Thu Jan 1 00:00:00 1970 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 7B03EC433EF for ; Sun, 10 Apr 2022 01:24:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234188AbiDJB03 (ORCPT ); Sat, 9 Apr 2022 21:26:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234251AbiDJB01 (ORCPT ); Sat, 9 Apr 2022 21:26:27 -0400 Received: from mail-ej1-x632.google.com (mail-ej1-x632.google.com [IPv6:2a00:1450:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59628DF3F for ; Sat, 9 Apr 2022 18:24:17 -0700 (PDT) Received: by mail-ej1-x632.google.com with SMTP id bq8so24202653ejb.10 for ; Sat, 09 Apr 2022 18:24:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=EYyl3H7DZOdvVyjoBwIeVjzarKMqTNEfyGOsHkNP3bQ=; b=XXQv+s3FHjWgeL4YghCdeqSJ9IFqyjYH2qzZaPl2d/Af4wxT03hbRm3uhpM+rcHfO+ 4S8wcLwagyH2wjdmYL+QYCIDHktjTaxkz89+3/tkAF0dOUtXplgEyUKyZPR3COKFFGhS ovZq4Sydovf/j2+PIEd3qEM/z9sUmOcjby2QFxnZb2nk3g8PbSABKT7n0MegwU0W3WMO LqqedaiKS0/4auz0LKI2BBCZz/VXbAu51BIQaFfMkB+be3zMWTxI0um/lMV4q+bpQZgB iHqCiS/dPv8hXmtP+onNlRQTZ46GO6RJZfZpWcmbRMchXzgTPItrfC8MmHDyKLij7uQU YLaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=EYyl3H7DZOdvVyjoBwIeVjzarKMqTNEfyGOsHkNP3bQ=; b=5Eqi6/8mYDO5RlO3/1lXNFK2Z5udk8ka7nRGv/qf879kYTutb9MgeLeBthYFX1Osuw Gv4jvYRe5fxbTS4sukUVPM5FvJtKDHAZsDXme7HVvB2cFkOehZaHDIJoG0DGuZrcJwUd jhKDNp6Vbz0SgA80zbL6OefsInZVuvlu5mdoIbNvwnpZfwTi4otYJsu19mTxPnwP0d9T yEjE4luSMUYpvpnYNkFaokZc+oOry5T62RGzKKxYc9gzRdxDZ7ZKXDP2S/I1ENE9JFmY bIo5Mo26YgbMoOZnvJGoH7qhIcxutPNNH69HjkqvMecjkIf+Wr8zOwshTN3jbPqftTiD 2FzA== X-Gm-Message-State: AOAM533UfVlA6p2MXubYHm9NOKxKyoGM10HeDFBpSFPgFPiNWBLR6NA3 Eec4NFIep42fzKLgMuqNL/Ey1Q== X-Google-Smtp-Source: ABdhPJzKIw6527Dw7iJvBaylX1uYDP/tK55dKKO2c3xESsWPQba6+f0lfjtYcWfJAjGwCXjGbia3WQ== X-Received: by 2002:a17:907:2cc3:b0:6e6:45fb:39fa with SMTP id hg3-20020a1709072cc300b006e645fb39famr23724307ejc.545.1649553855848; Sat, 09 Apr 2022 18:24:15 -0700 (PDT) Received: from leoy-ThinkPad-X240s ([104.245.96.34]) by smtp.gmail.com with ESMTPSA id z25-20020a1709067e5900b006e7fe2a1308sm6297770ejr.48.2022.04.09.18.24.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 09 Apr 2022 18:24:15 -0700 (PDT) Date: Sun, 10 Apr 2022 09:24:10 +0800 From: Leo Yan To: carsten.haitzler@foss.arm.com Cc: linux-kernel@vger.kernel.org, coresight@lists.linaro.org, suzuki.poulose@arm.com, mathieu.poirier@linaro.org, mike.leach@linaro.org, linux-perf-users@vger.kernel.org, acme@kernel.org Subject: Re: [PATCH 1/3] perf test: Shell - Limit to only run executable scripts in tests Message-ID: <20220410012410.GA14326@leoy-ThinkPad-X240s> References: <20220309122859.31487-1-carsten.haitzler@foss.arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220309122859.31487-1-carsten.haitzler@foss.arm.com> Precedence: bulk List-ID: X-Mailing-List: linux-perf-users@vger.kernel.org On Wed, Mar 09, 2022 at 12:28:57PM +0000, carsten.haitzler@foss.arm.com wrote: > From: Carsten Haitzler > > Perf test's shell runner will just run everything in the tests > directory (as long as it's not another directory or does not begin > with a dot), but sometimes you find files in there that are not shell > scripts - perf.data output for example if you do some testing and then > the next time you run perf test it tries to run these. Check the files > are executable so they are actually intended to be test scripts and > not just some "random junk" files there. > > Signed-off-by: Carsten Haitzler Reviewed-by: Leo Yan > --- > tools/perf/tests/builtin-test.c | 4 +++- > tools/perf/util/path.c | 14 +++++++++++++- > tools/perf/util/path.h | 1 + > 3 files changed, 17 insertions(+), 2 deletions(-) > > diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c > index fac3717d9ba1..3c34cb766724 100644 > --- a/tools/perf/tests/builtin-test.c > +++ b/tools/perf/tests/builtin-test.c > @@ -296,7 +296,9 @@ static const char *shell_test__description(char *description, size_t size, > > #define for_each_shell_test(entlist, nr, base, ent) \ > for (int __i = 0; __i < nr && (ent = entlist[__i]); __i++) \ > - if (!is_directory(base, ent) && ent->d_name[0] != '.') > + if (!is_directory(base, ent) && \ > + is_executable_file(base, ent) && \ > + ent->d_name[0] != '.') > > static const char *shell_tests__dir(char *path, size_t size) > { > diff --git a/tools/perf/util/path.c b/tools/perf/util/path.c > index caed0336429f..ce80b79be103 100644 > --- a/tools/perf/util/path.c > +++ b/tools/perf/util/path.c > @@ -86,9 +86,21 @@ bool is_directory(const char *base_path, const struct dirent *dent) > char path[PATH_MAX]; > struct stat st; > > - sprintf(path, "%s/%s", base_path, dent->d_name); > + snprintf(path, sizeof(path), "%s/%s", base_path, dent->d_name); > if (stat(path, &st)) > return false; > > return S_ISDIR(st.st_mode); > } > + > +bool is_executable_file(const char *base_path, const struct dirent *dent) > +{ > + char path[PATH_MAX]; > + struct stat st; > + > + snprintf(path, sizeof(path), "%s/%s", base_path, dent->d_name); > + if (stat(path, &st)) > + return false; > + > + return !S_ISDIR(st.st_mode) && (st.st_mode & S_IXUSR); > +} > diff --git a/tools/perf/util/path.h b/tools/perf/util/path.h > index 083429b7efa3..d94902c22222 100644 > --- a/tools/perf/util/path.h > +++ b/tools/perf/util/path.h > @@ -12,5 +12,6 @@ int path__join3(char *bf, size_t size, const char *path1, const char *path2, con > > bool is_regular_file(const char *file); > bool is_directory(const char *base_path, const struct dirent *dent); > +bool is_executable_file(const char *base_path, const struct dirent *dent); > > #endif /* _PERF_PATH_H */ > -- > 2.32.0 >