All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mauro Carvalho Chehab <mauro.chehab@linux.intel.com>
To: igt-dev@lists.freedesktop.org
Subject: [igt-dev] [PATCH v3 04/10] scripts/code_cov_gather*/sh: add help scripts for code coverage
Date: Wed, 16 Mar 2022 15:59:57 +0100	[thread overview]
Message-ID: <20220316150003.1583681-5-mauro.chehab@linux.intel.com> (raw)
In-Reply-To: <20220316150003.1583681-1-mauro.chehab@linux.intel.com>

From: Mauro Carvalho Chehab <mchehab@kernel.org>

When a Linux Kernel is built with gcov support, the compiler creates
some other object files (*.gcno) that are dependent of the compiler
version, and contain references to the source files.

At Kernel runtime at the test machine, counter files will be visible at
sysfs (*.gcda files), which are also on a compiler specific format.

In order to be able to properly parse the contents of the counters, the
information from 3 different places should be merged altogether:

	- Runtime counters: /sys/.../*.gcda and hiperlinks to *.gcno
	- Compile-time cross-reference object files: *.gcno
	- Kernel source code.

If the build machine is different than the source machine, some special
scripts are needed in order to either copy the source files to the
runtime machine or vice versa.

This is described at:

	https://www.kernel.org/doc/html/latest/dev-tools/gcov.html

Copy the two scripts described there as-is.

Further patches will modify them as needed.

Acked-by: Petri Latvala <petri.latvala@intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
---
 scripts/code_cov_gather_on_build.sh | 23 +++++++++++++++++++++++
 scripts/code_cov_gather_on_test.sh  | 20 ++++++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100755 scripts/code_cov_gather_on_build.sh
 create mode 100755 scripts/code_cov_gather_on_test.sh

diff --git a/scripts/code_cov_gather_on_build.sh b/scripts/code_cov_gather_on_build.sh
new file mode 100755
index 000000000000..99c436f76fb8
--- /dev/null
+++ b/scripts/code_cov_gather_on_build.sh
@@ -0,0 +1,23 @@
+#!/bin/bash
+
+KSRC=$1
+KOBJ=$2
+DEST=$3
+
+if [ -z "$KSRC" ] || [ -z "$KOBJ" ] || [ -z "$DEST" ]; then
+  echo "Usage: $0 <ksrc directory> <kobj directory> <output.tar.gz>" >&2
+  exit 1
+fi
+
+KSRC=$(cd $KSRC; printf "all:\n\t@echo \${CURDIR}\n" | make -f -)
+KOBJ=$(cd $KOBJ; printf "all:\n\t@echo \${CURDIR}\n" | make -f -)
+
+find $KSRC $KOBJ \( -name '*.gcno' -o -name '*.[ch]' -o -type l \) -a \
+                 -perm /u+r,g+r | tar cfz $DEST -P -T -
+
+if [ $? -eq 0 ] ; then
+  echo "$DEST successfully created, copy to test system and unpack with:"
+  echo "  tar xfz $DEST -P"
+else
+  echo "Could not create file $DEST"
+fi
diff --git a/scripts/code_cov_gather_on_test.sh b/scripts/code_cov_gather_on_test.sh
new file mode 100755
index 000000000000..8834aa0d78af
--- /dev/null
+++ b/scripts/code_cov_gather_on_test.sh
@@ -0,0 +1,20 @@
+#!/bin/bash -e
+
+DEST=$1
+GCDA=/sys/kernel/debug/gcov
+
+if [ -z "$DEST" ] ; then
+  echo "Usage: $0 <output.tar.gz>" >&2
+  exit 1
+fi
+
+TEMPDIR=$(mktemp -d)
+echo Collecting data..
+find $GCDA -type d -exec mkdir -p $TEMPDIR/\{\} \;
+find $GCDA -name '*.gcda' -exec sh -c 'cat < $0 > '$TEMPDIR'/$0' {} \;
+find $GCDA -name '*.gcno' -exec sh -c 'cp -d $0 '$TEMPDIR'/$0' {} \;
+tar czf $DEST -C $TEMPDIR sys
+rm -rf $TEMPDIR
+
+echo "$DEST successfully created, copy to build system and unpack with:"
+echo "  tar xfz $DEST"
-- 
2.35.1

  parent reply	other threads:[~2022-03-16 15:03 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-16 14:59 [igt-dev] [PATCH v3 00/10] Add support to collect code coverage data Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 01/10] runner: check if it has root permissions Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 02/10] runner: Add support for code coverage Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 03/10] runner: cleanup code_cov directory, if any Mauro Carvalho Chehab
2022-03-16 14:59 ` Mauro Carvalho Chehab [this message]
2022-03-16 14:59 ` [igt-dev] [PATCH v3 05/10] scripts/code_cov_gather_on_build.sh: Improve the script Mauro Carvalho Chehab
2022-03-16 14:59 ` [igt-dev] [PATCH v3 06/10] scripts/code_cov_capture.sh: add a script to use lcov on build+test machine Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 07/10] scripts/code_cov_gen_report.sh: add a script to generate code coverage reports Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 08/10] scripts/run-tests.sh: add code coverage support Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 09/10] scripts:code_cov_gather_on_test: use a faster script Mauro Carvalho Chehab
2022-03-16 15:00 ` [igt-dev] [PATCH v3 10/10] docs: add documentation for code coverage Mauro Carvalho Chehab
2022-03-16 15:44 ` [igt-dev] ✓ Fi.CI.BAT: success for Add support to collect code coverage data Patchwork
2022-03-16 16:53 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220316150003.1583681-5-mauro.chehab@linux.intel.com \
    --to=mauro.chehab@linux.intel.com \
    --cc=igt-dev@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.