Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3411407pxk; Mon, 5 Oct 2020 09:01:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw63vKnXQ/xwYP/1B1ei/GyEcK6gfnL6WTepXpeOIKYJQN7jZUAt+Oikt3qII+2flPZsJ2m X-Received: by 2002:adf:e6c7:: with SMTP id y7mr40806wrm.147.1601913717929; Mon, 05 Oct 2020 09:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601913717; cv=none; d=google.com; s=arc-20160816; b=xK+V3bdShvVAYPLDLOFcDEm9OG4fNt8FFTyiVuIkDjfhHvrqo6EfKbGYaxpBOXYRX5 kqOk/R7ztvqfLmKvGQsLNsE5Qe5sC5ctwishvrs390unL/K+sywp+dEaXXIoCw92+01l LXIwTJDbdCyzZ3X6o6Qp0a+/3WFXNB4XW2prvANEL5sskdgZbDzub9bD8Rr10iw4f3pz Mt+DFsLp9kBl6sIkq/1q79orW4sBMt7Ab/RHlo1zC6o2l5eE5E+F9pxjkfVWykx2xNu4 /bfLxYMNRQvxT6tkLr4yRIfqZndwpPJFf7PFDQQdUGfOy+Fq4ryxpDqiH3QiY/ADMrkH mdsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=dN5gsjMnqyqI5A2jup6ulYvntmGtep/DzBd0lOh8y1w=; b=xUUy5+6kDgSAqU5caZKA+pXDUgZFMXCTuhX7pmFG1rIwYXM89mO9H7N6pjgpWDaX4J A78eRyZvyD9pKNikbZyeAwK+9HcMCbkXp3mSNr7vRcIRtzuhh1kKuhxdzbiOowYuX/Ga mU1L0EXzhLqBm+1Oyu7slO80hX1vXIdw2EKYFjfW+vtGD/6au/y7OO1FPlNpoeFZE+fn M4JcbddwvcvL3FqrSxAAhOucpp1ObhGdejg209Eh8m6n3QeTiSUcy3OMpJY3PFe9kISc 6mvZ/0H98FrOORa+RD/VS4p+mVgCFrzXtsdKsm+JTkF0YjnzxmT4ng00k2Z29lTH81bB YmGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=KxLCYd3O; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id di23si296915edb.451.2020.10.05.09.01.18; Mon, 05 Oct 2020 09:01:57 -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=@redhat.com header.s=mimecast20190719 header.b=KxLCYd3O; 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=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728861AbgJEP63 (ORCPT + 99 others); Mon, 5 Oct 2020 11:58:29 -0400 Received: from us-smtp-delivery-124.mimecast.com ([63.128.21.124]:54219 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727309AbgJEP63 (ORCPT ); Mon, 5 Oct 2020 11:58:29 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601913507; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=dN5gsjMnqyqI5A2jup6ulYvntmGtep/DzBd0lOh8y1w=; b=KxLCYd3ODn1QSzzSW+dS/LnTpqOt+tKzNgPpuD5GoqP0HkTAt6Tf44WD2yxveZs9sDOaE3 z/4o+8vnjON7+/hrMTJ5Q88OnZ+VDtvUbtUOTovN1vft2lhQiMHkb7xyFGCItQrfXBOGhS HPVYsh5dYW3T8B9adP5CHA6vBfscdeg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-460-qgIJrjfmM7yoddD5iKTd2A-1; Mon, 05 Oct 2020 11:58:23 -0400 X-MC-Unique: qgIJrjfmM7yoddD5iKTd2A-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 04D7B107ACF5; Mon, 5 Oct 2020 15:58:22 +0000 (UTC) Received: from krava (unknown [10.40.195.156]) by smtp.corp.redhat.com (Postfix) with SMTP id 650DD75120; Mon, 5 Oct 2020 15:58:19 +0000 (UTC) Date: Mon, 5 Oct 2020 17:58:18 +0200 From: Jiri Olsa To: Arnaldo Carvalho de Melo Cc: Ian Rogers , Namhyung Kim , Jiri Olsa , lkml , Peter Zijlstra , Ingo Molnar , Mark Rutland , Alexander Shishkin , Michael Petlan , Stephane Eranian Subject: [PATCHv3 1/9] perf tools: Add build id shell test Message-ID: <20201005155818.GA249615@krava> References: <20200930171512.3986425-1-jolsa@kernel.org> <20200930171512.3986425-2-jolsa@kernel.org> <20201001190530.GD3999500@krava> <20201002205527.GA7581@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201002205527.GA7581@kernel.org> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Adding test for build id cache that adds binary with sha1 and md5 build ids and verifies it's added properly. The test updates build id cache with perf record and perf buildid-cache -a. Signed-off-by: Jiri Olsa --- v3 changes: - compile examples directly in the test - using 'command' instead of 'which' for detection tools/perf/tests/shell/buildid.sh | 101 ++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100755 tools/perf/tests/shell/buildid.sh diff --git a/tools/perf/tests/shell/buildid.sh b/tools/perf/tests/shell/buildid.sh new file mode 100755 index 000000000000..4861a20edee2 --- /dev/null +++ b/tools/perf/tests/shell/buildid.sh @@ -0,0 +1,101 @@ +#!/bin/sh +# build id cache operations +# SPDX-License-Identifier: GPL-2.0 + +# skip if there's no readelf +if ! [ -x "$(command -v readelf)" ]; then + echo "failed: no readelf, install binutils" + exit 2 +fi + +# skip if there's no compiler +if ! [ -x "$(command -v cc)" ]; then + echo "failed: no compiler, install gcc" + exit 2 +fi + +ex_md5=$(mktemp /tmp/perf.ex.MD5.XXX) +ex_sha1=$(mktemp /tmp/perf.ex.SHA1.XXX) + +echo 'int main(void) { return 0; }' | cc -Wl,--build-id=sha1 -o ${ex_sha1} -x c - +echo 'int main(void) { return 0; }' | cc -Wl,--build-id=md5 -o ${ex_md5} -x c - + +echo "test binaries: ${ex_sha1} ${ex_md5}" + +check() +{ + id=`readelf -n ${1} 2>/dev/null | grep 'Build ID' | awk '{print $3}'` + + echo "build id: ${id}" + + link=${build_id_dir}/.build-id/${id:0:2}/${id:2} + echo "link: ${link}" + + if [ ! -h $link ]; then + echo "failed: link ${link} does not exist" + exit 1 + fi + + file=${build_id_dir}/.build-id/${id:0:2}/`readlink ${link}`/elf + echo "file: ${file}" + + if [ ! -x $file ]; then + echo "failed: file ${file} does not exist" + exit 1 + fi + + diff ${file} ${1} + if [ $? -ne 0 ]; then + echo "failed: ${file} do not match" + exit 1 + fi + + echo "OK for ${1}" +} + +test_add() +{ + build_id_dir=$(mktemp -d /tmp/perf.debug.XXX) + perf="perf --buildid-dir ${build_id_dir}" + + ${perf} buildid-cache -v -a ${1} + if [ $? -ne 0 ]; then + echo "failed: add ${1} to build id cache" + exit 1 + fi + + check ${1} + + rm -rf ${build_id_dir} +} + +test_record() +{ + data=$(mktemp /tmp/perf.data.XXX) + build_id_dir=$(mktemp -d /tmp/perf.debug.XXX) + perf="perf --buildid-dir ${build_id_dir}" + + ${perf} record --buildid-all -o ${data} ${1} + if [ $? -ne 0 ]; then + echo "failed: record ${1}" + exit 1 + fi + + check ${1} + + rm -rf ${build_id_dir} + rm -rf ${data} +} + +# add binaries manual via perf buildid-cache -a +test_add ${ex_sha1} +test_add ${ex_md5} + +# add binaries via perf record post processing +test_record ${ex_sha1} +test_record ${ex_md5} + +# cleanup +rm ${ex_sha1} ${ex_md5} + +exit ${err} -- 2.26.2