Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp1403639pxj; Fri, 21 May 2021 13:24:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwHH5eNOvylhdcfd2zBorhf/7dPCw5idaysA4LayWOniDZP1d2yp38eO4YtzTMGnKe2lRX X-Received: by 2002:a92:700a:: with SMTP id l10mr687726ilc.44.1621628699184; Fri, 21 May 2021 13:24:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621628699; cv=none; d=google.com; s=arc-20160816; b=GKeF8xwO/QqtBC/acCeAvo4f2J8Vbr+sBLh083Qrpm05+FaxtUikYFnlX6RBNBT6Ix Ue5plmPaO2cjvWhRU5VtSXPnsZ4OVX/Tp5bsuYXCETiukD0+bJq/dgz5oteTchrtFs3z oSSIIBFmkhW/fBZt5ctJcr4d8GrBFcSdT9IrtFzB0vDidbsQIiM6L30DxdY/RPtYv+zX keaKhPMP7Z9LRl6y8BzfaKsBRvjr7NBe1GsbCu57dAEKBklnj9SUoTDiKliOomOlCxoU mSogTuor0r8ab1RyqfDPjFtwyn4o+AUtGEjnUhJxkr+1tRXAbOCsXx0wnhaIT3huH5Sr jmrA== 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=C05EVeiCGPy6rrIauyHkjFQKq227VJsF0DfNk738mFo=; b=BF4R+eTe6gnXMYaVGPP7kKIGnDbuS3KxRVUEj8tWz4ms8MrzSWdjH70x8tFIBZD+zD 8/qCQVwpRsVS5TW9dcpfoBPo8tv6iZ+/XPnjvBi5iuaaGevfX9nFwbrJKHg5DdAPhkwK EYdh8Wb0G4CM8FQVGcN72GGEpgScbNjsDYBeuoU3+j7gDVasoBPkdcLFApV9uMqs0R/B pSAgyQu/eCiX7JQrapoMhNdG3ARR3xXm12Lz/5xGIwfsfeRXVqjGwlbHl5s03pweNeAU 5lGeCpXyymcELZTb7955Zj0sbp4BVgZ+8LZMuw7Z3higfSB9QkGdqM2QCSRYxHD6VEEf cabQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cisco.com header.s=iport header.b=m+KouVuW; 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 l22si6938196jad.10.2021.05.21.13.24.46; Fri, 21 May 2021 13:24:59 -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=m+KouVuW; 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 S232144AbhEUR3T (ORCPT + 99 others); Fri, 21 May 2021 13:29:19 -0400 Received: from alln-iport-8.cisco.com ([173.37.142.95]:38076 "EHLO alln-iport-8.cisco.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232022AbhEUR3S (ORCPT ); Fri, 21 May 2021 13:29:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=cisco.com; i=@cisco.com; l=3248; q=dns/txt; s=iport; t=1621618075; x=1622827675; h=from:to:subject:date:message-id:in-reply-to:references: mime-version:content-transfer-encoding; bh=JvTqOTjUDtT8xKRvqRDFpCWK+apz7Wz1lqutJWoWXT0=; b=m+KouVuWrAFJ/Mc3o+GxaNAeEaIx0NTyVbS2+l2yl6wEpMg+7fJUGc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Zwj2AmlqugevUlAvhVY4SHaH+/flv6HWawmEDARsaWEH9uvm4kU69WtR3L 00S5zporK4u+UjtRd74NzW+qXuErwMaVPJTHvc85QXLzbDbiy6QDW0JZj1MctorsIkxXzNC/ keEg97zFxRutrOPQH6Q/7vSqim9UQAQJHUBIzUZUQ8M5dXLqZs2yBnIS75e/LWdh9nxH3T7x CqH6XV4jLQIhslN3KK+lbzav96yjpzvcl8YwhSGZTOCyQVAQ4qYYLa14keOuJ6sM72lokm9U GkswpbEtb1eU8nSyURhU81WR+n4vabt3Cn0xA8xQcV8q1xB7lb+JehtDCdCyFCF2yruURbtZ ELV0e+6zMAOZCPwBUObjn7YNijH5aHkEdKgXffOY58TCnSQSONl1Hw1DaJz9zmw+KTJrU3ZE cvDGSpLJS1HYZmLNBLsG48gPUYDn0jSP18/oKwXKTz5j9Jyg1bLEN843KemNYjVEYvd+lyOq oYDXyd040sBD4USnRU7AaZKfQxVchDX9Ljdqtdccaa4MxF6FWQ6Y8I9MptwJtM/wfU9qws8x VngCh4w4Aeu3hXvdFTVAk2PnZuyBP6TW1pgZndyVbtpslB+CbuSAFA3J8pvIeZ/rLQ9pRO2J tFcE/i97j10Ymyv01wggVPV9eSOqDzDadqyAheY IronPort-HdrOrdr: A9a23:6JmmyK6QPIZttu9PigPXwMnXdLJyesId70hD6qkXc20wTiX2ra 6TdZgguCMczQxhO03I+urwXZVoP0m8yXcd2+B4Vt2ftUvdyQmVxepZgrcKrQeNJ8SHzI5gPW MKSdkZNDU2ZmIK6vrH3A== X-IronPort-Anti-Spam-Filtered: true X-IronPort-AV: E=Sophos;i="5.82,319,1613433600"; d="scan'208";a="716112903" Received: from alln-core-5.cisco.com ([173.36.13.138]) by alln-iport-8.cisco.com with ESMTP/TLS/DHE-RSA-SEED-SHA; 21 May 2021 17:27:54 +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 14LHRsCN023275 (version=TLSv1.2 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Fri, 21 May 2021 17:27:54 GMT Received: by sjc-ads-9103.cisco.com (Postfix, from userid 487941) id 06425CC1253; Fri, 21 May 2021 10:27:54 -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 v6 2/3] perf tests: avoid storing an absolute path in perf binary Date: Fri, 21 May 2021 10:27:52 -0700 Message-Id: <20210521172753.55399-2-dzagorui@cisco.com> X-Mailer: git-send-email 2.26.2.Cisco In-Reply-To: <20210521172753.55399-1-dzagorui@cisco.com> References: <20210521172753.55399-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 | 21 +++++++++++++++++++-- tools/perf/util/util.c | 12 ++++++++++++ tools/perf/util/util.h | 1 + 4 files changed, 33 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..4a6ff7db2bf1 100644 --- a/tools/perf/tests/python-use.c +++ b/tools/perf/tests/python-use.c @@ -8,18 +8,35 @@ #include #include "tests.h" #include "util/debug.h" +#include "util/util.h" +#include int test__python_use(struct test *test __maybe_unused, int subtest __maybe_unused) { char *cmd; int ret; + char *exec_path; + char *pythonpath; + 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) + exec_path = perf_exe_path(); + + if (asprintf(&pythonpath, "%s/python", exec_path) < 0) return -1; + 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(pythonpath); return ret; } diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c index 3bba74e431ed..53f3dbf02f58 100644 --- a/tools/perf/util/util.c +++ b/tools/perf/util/util.c @@ -22,6 +22,7 @@ #include "cap.h" #include "strlist.h" #include "string2.h" +#include /* * XXX We need to find a better place for these things... @@ -388,3 +389,14 @@ char *perf_exe(char *buf, int len) } return strcpy(buf, "perf"); } + +char *perf_exe_path(void) +{ + char buf[PATH_MAX]; + char *dname; + + perf_exe(buf, PATH_MAX); + dname = dirname(buf); + + return dname; +} diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h index 80b194ee6c7d..4b506df4e8b9 100644 --- a/tools/perf/util/util.h +++ b/tools/perf/util/util.h @@ -49,6 +49,7 @@ void perf_set_singlethreaded(void); void perf_set_multithreaded(void); char *perf_exe(char *buf, int len); +char *perf_exe_path(void); #ifndef O_CLOEXEC #ifdef __sparc__ -- 2.26.2.Cisco