Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1707640pxj; Fri, 21 May 2021 23:21:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyt15MR2s3nAi4Tx7oEM6C5UvaDVKPQMJnTlWIuz9J26FIrJ8XeA3TTznO2Lq3q74xtZr2x X-Received: by 2002:a92:d7c3:: with SMTP id g3mr2945213ilq.114.1621664474224; Fri, 21 May 2021 23:21:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621664474; cv=none; d=google.com; s=arc-20160816; b=abFYSdg4l3NF21P3QIZwB6rK9bjnZVEzAs86Yg7MOuQlYQ91hIJJ9ziIjfqhR+RH/Z LxqR35cCoaJWaiLMvg1u1MWHRkK8ClPNTXVcMZJGIh/P7wtXNit7ozw4xPrjySTs9RL1 FdRG/J6KoAs+tbVQv3T8W9NiANxY7U0/Sp5HikOyYbK5zwkk1uI8OWVjg/SsRJ2Q56TC z6OU1chJz2zgdC4IRThUyVnWipYLmQSamnFO/6VYhYzl1lIAN9Zru3+PL7RmEbDg4yEC UtDxfqs3C1X/glgUzRUhgxPBm7KT8nQuQ/j4TBWXt+eVirOvthvBMpaAYjhgxv77MHlY kbzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :ironport-hdrordr:ironport-data:dkim-signature; bh=+uh7ctZ7RLTpIrBJIT4JroZdd8kQGQGgZKfi1xXeKGg=; b=q3Ct+Kl7buOvo4ClLDBjxp72s2VgiB5SSVEKuCjVQN+lZRkEXgvO4fSzm/g2V1My9r ZYNtcDit1WCrLM6anrE81SNjz/3V8k/Y4b8tT5nSbshwtGFdzHBFO51iPOzlC6HxxH7X 86f+F3G21Ggk1iV7OstiW7pCC4/lfm9hDzdpU1VLTBukjH2h+MwCN9Eggqfsm/MqNeoV JGZfThj4ZTJ+XImqhVtMVOM4qxa6ile2ZCjstJc4Uvi43DYkZLVc/IQBkzK9r84RJ8MM oQXrloypLMeYOEPpZj9Vxx5xh8W78V/yfXKMgdNHp8HyYJEQ8K66eugaZ6l/LNWaYtah 0gPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=hfgMfnzv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l11si8375903jak.61.2021.05.21.23.21.00; Fri, 21 May 2021 23:21:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=hfgMfnzv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=cisco.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbhEVGVp (ORCPT + 99 others); Sat, 22 May 2021 02:21:45 -0400 Received: from alln-iport-2.cisco.com ([173.37.142.89]:56353 "EHLO alln-iport-2.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229639AbhEVGVp (ORCPT ); Sat, 22 May 2021 02:21:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=2404; q=dns/txt; s=iport; t=1621664421; x=1622874021; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=jA6VOyUz8HqvmDa574sYJssvKl47NA09np1hsczVkwQ=; b=hfgMfnzvk++mK9z3qvXLSn6mEDMnOLkZ1VGQbNcomX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ajkfNdqQzhKf/36sj/OJliT+MKoQE7mj/9ZwjVGTz3BVAxoTPXOypfSpg0iyVsgZM EwV4SotrK4a8E2tU8m7XhukrXrCtRkZM/JWGug6+RyLxYLX7hyfC2xCSSROAPQvv8o7bT8nz FmEm5XuHzMHmKWYVX+H5J+Vqz2oMCQYJGNEYjULJSMA6sPg5psukhbGSNpLGbSwyNbyHFnNL yuipSw6gfAYitQGkvj99lHciDXqrZ/MJuIo2unJdmX74ihpQrGFW7OX4lTC9dEacZalQ2DU6 RDohPOiAPAy4YClzXLXGbhdQun2up5pIxWH2gY+RclJGyCFvi/9I9wNvFmSMW80aq45lSnVj Fg/UO+7zLZXOHasBUOcS93sU5xwpUQM+CiMaxw5RtNKZp40fwid8WQzDaJx44wPuBV3+U3cE c7GGSpJMZr8Ifg/pNZRb7xAuYLHPghkmQvuqWnTlnxLK4ZygUJ5r59bbjNiichntcu5TPn9q L6zyuPTkUwECb2iCsUp2dBNcjjm0kTX9biv+5AIKYZv0yJNGXoqDLfq0Kg9dol+95m5Zc+Zo y7nBB4w9bYLvlWaeVTiQi0yM9vHAMcgxU/XyARxZD5ELVB4Ot3xhEreHrNqFYQaGBtLna8sE 6ZdI53eahmNIxyekwkggVDGhNQKXHyWacimZkJJvBBXk0ZcejH0 IronPort-HdrOrdr: A9a23:odP8LKPi63cZj8BcTsCjsMiBIKoaSvp037BN7TEUdfU7SKKlfq yV8cjzkCWE6wr5O0tQ/OxoRpPgfZq0z/cciuMs1PWZLWvbUQCTQ72Kg7GP/9SZIU3DHio379 YHT0C4Y+eAamRHsQ== X-IronPort-Anti-Spam-Filtered: true X-IronPort-AV: E=Sophos;i="5.82,319,1613433600"; d="scan'208";a="723110272" Received: from alln-core-5.cisco.com ([173.36.13.138]) by alln-iport-2.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 22 May 2021 06:20:17 +0000 Received: from sjc-ads-9103.cisco.com (sjc-ads-9103.cisco.com [10.30.208.113]) by alln-core-5.cisco.com (8.15.2/8.15.2) with ESMTPS id 14M6KHFP013759 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Sat, 22 May 2021 06:20:17 GMT Received: by sjc-ads-9103.cisco.com (Postfix, from userid 487941) id D6A80CC1253; Fri, 21 May 2021 23:20:16 -0700 (PDT) From: Denys Zagorui To: jolsa@redhat.com, linux-kernel@vger.kernel.org, peterz@infradead.org, mingo@redhat.com, acme@kernel.org, mark.rutland@arm.com, alexander.shishkin@linux.intel.com, namhyung@kernel.org Subject: [PATCH v7 2/3] perf tests: avoid storing an absolute path in perf binary Date: Fri, 21 May 2021 23:20:15 -0700 Message-Id: <20210522062016.84677-2-dzagorui@cisco.com> X-Mailer: git-send-email 2.26.2.Cisco In-Reply-To: <20210522062016.84677-1-dzagorui@cisco.com> References: <20210522062016.84677-1-dzagorui@cisco.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Outbound-SMTP-Client: 10.30.208.113, sjc-ads-9103.cisco.com X-Outbound-Node: alln-core-5.cisco.com Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org python binding test uses PYTHONPATH definition to find python/perf.so library. This definition is an absolute path that makes perf binary unreproducible. This path can be found during runtime execution. Signed-off-by: Denys Zagorui --- tools/perf/tests/Build | 2 +- tools/perf/tests/python-use.c | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build index 650aec19d490..a20098dcdbc4 100644 --- a/tools/perf/tests/Build +++ b/tools/perf/tests/Build @@ -98,5 +98,5 @@ perf-$(CONFIG_DWARF_UNWIND) += dwarf-unwind.o endif CFLAGS_attr.o += -DBINDIR="BUILD_STR($(bindir_SQ))" -DPYTHON="BUILD_STR($(PYTHON_WORD))" -CFLAGS_python-use.o += -DPYTHONPATH="BUILD_STR($(OUTPUT)python)" -DPYTHON="BUILD_STR($(PYTHON_WORD))" +CFLAGS_python-use.o += -DPYTHON="BUILD_STR($(PYTHON_WORD))" CFLAGS_dwarf-unwind.o += -fno-optimize-sibling-calls diff --git a/tools/perf/tests/python-use.c b/tools/perf/tests/python-use.c index 98c6d474aa6f..e196faf1140d 100644 --- a/tools/perf/tests/python-use.c +++ b/tools/perf/tests/python-use.c @@ -8,18 +8,46 @@ #include #include "tests.h" #include "util/debug.h" +#include "util/util.h" +#include +#include +#include int test__python_use(struct test *test __maybe_unused, int subtest __maybe_unused) { char *cmd; int ret; + char *exec_path; + char *buf; + char *pythonpath = NULL; + struct stat sb; - if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s", - PYTHONPATH, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0) + buf = malloc(PATH_MAX); + if (buf == NULL) return -1; + perf_exe(buf, PATH_MAX); + exec_path = dirname(buf); + + if (asprintf(&pythonpath, "%s/python", exec_path) < 0) { + ret = -1; + goto out; + } + + if (stat(pythonpath, &sb) || !S_ISDIR(sb.st_mode)) + pythonpath[0] = 0; + + if (asprintf(&cmd, "echo \"import sys ; sys.path.append('%s'); import perf\" | %s %s", + pythonpath, PYTHON, verbose > 0 ? "" : "2> /dev/null") < 0) { + ret = -1; + goto out; + } + pr_debug("python usage test: \"%s\"\n", cmd); ret = system(cmd) ? -1 : 0; free(cmd); +out: + free(buf); + free(pythonpath); return ret; } -- 2.26.2.Cisco