From: Arnaldo Carvalho de Melo <arnaldo.melo@gmail.com>
To: Ian Rogers <irogers@google.com>
Cc: Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@redhat.com>,
Mark Rutland <mark.rutland@arm.com>,
Alexander Shishkin <alexander.shishkin@linux.intel.com>,
Jiri Olsa <jolsa@redhat.com>, Namhyung Kim <namhyung@kernel.org>,
Adrian Hunter <adrian.hunter@intel.com>,
Song Liu <songliubraving@fb.com>, Leo Yan <leo.yan@linaro.org>,
Michael Petlan <mpetlan@redhat.com>,
Florian Fainelli <f.fainelli@gmail.com>,
Kate Stewart <kstewart@linuxfoundation.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Allison Randal <allison@lohutok.net>,
Alexios Zavras <alexios.zavras@intel.com>,
Thomas Gleixner <tglx@linutronix.de>,
linux-kernel@vger.kernel.org,
Stephane Eranian <eranian@google.com>
Subject: Re: [PATCH] perf jit: move test functionality in to a test
Date: Wed, 27 Nov 2019 12:23:28 -0300 [thread overview]
Message-ID: <20191127152328.GI22719@kernel.org> (raw)
In-Reply-To: <20191126235913.41855-1-irogers@google.com>
Em Tue, Nov 26, 2019 at 03:59:13PM -0800, Ian Rogers escreveu:
> Adds a test for minimal jit_write_elf functionality.
Thanks, tested and applied.
- Arnaldo
> Signed-off-by: Ian Rogers <irogers@google.com>
> ---
> tools/perf/tests/Build | 1 +
> tools/perf/tests/builtin-test.c | 4 +++
> tools/perf/tests/genelf.c | 53 +++++++++++++++++++++++++++++++++
> tools/perf/tests/tests.h | 1 +
> tools/perf/util/genelf.c | 46 ----------------------------
> 5 files changed, 59 insertions(+), 46 deletions(-)
> create mode 100644 tools/perf/tests/genelf.c
>
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index e72accefd669..a738e4a5b301 100644
> --- a/tools/perf/tests/Build
> +++ b/tools/perf/tests/Build
> @@ -54,6 +54,7 @@ perf-y += unit_number__scnprintf.o
> perf-y += mem2node.o
> perf-y += map_groups.o
> perf-y += time-utils-test.o
> +perf-y += genelf.o
>
> $(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
> $(call rule_mkdir)
> diff --git a/tools/perf/tests/builtin-test.c b/tools/perf/tests/builtin-test.c
> index 8b286e9b7549..6ab2e2346aab 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -300,6 +300,10 @@ static struct test generic_tests[] = {
> .desc = "map_groups__merge_in",
> .func = test__map_groups__merge_in,
> },
> + {
> + .desc = "Test jit_write_elf",
> + .func = test__jit_write_elf,
> + },
> {
> .func = NULL,
> },
> diff --git a/tools/perf/tests/genelf.c b/tools/perf/tests/genelf.c
> new file mode 100644
> index 000000000000..d392e9300881
> --- /dev/null
> +++ b/tools/perf/tests/genelf.c
> @@ -0,0 +1,53 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +#include <limits.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <linux/compiler.h>
> +
> +#include "debug.h"
> +#include "tests.h"
> +
> +
> +#ifdef HAVE_LIBELF_SUPPORT
> +#include <libelf.h>
> +#include "../util/genelf.h"
> +#endif
> +
> +#define TEMPL "/tmp/perf-test-XXXXXX"
> +
> +static unsigned char x86_code[] = {
> + 0xBB, 0x2A, 0x00, 0x00, 0x00, /* movl $42, %ebx */
> + 0xB8, 0x01, 0x00, 0x00, 0x00, /* movl $1, %eax */
> + 0xCD, 0x80 /* int $0x80 */
> +};
> +
> +int test__jit_write_elf(struct test *test __maybe_unused,
> + int subtest __maybe_unused)
> +{
> +#ifdef HAVE_JITDUMP
> + char path[PATH_MAX];
> + int fd, ret;
> +
> + strcpy(path, TEMPL);
> +
> + fd = mkstemp(path);
> + if (fd < 0) {
> + perror("mkstemp failed");
> + return TEST_FAIL;
> + }
> +
> + pr_info("Writing jit code to: %s\n", path);
> +
> + ret = jit_write_elf(fd, 0, "main", x86_code, sizeof(x86_code),
> + NULL, 0, NULL, 0, 0);
> + close(fd);
> +
> + unlink(path);
> +
> + return ret ? TEST_FAIL : 0;
> +#else
> + return TEST_SKIPPED;
> +#endif
> +}
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index 9837b6e93023..5a53ab7294e9 100644
> --- a/tools/perf/tests/tests.h
> +++ b/tools/perf/tests/tests.h
> @@ -109,6 +109,7 @@ int test__unit_number__scnprint(struct test *test, int subtest);
> int test__mem2node(struct test *t, int subtest);
> int test__map_groups__merge_in(struct test *t, int subtest);
> int test__time_utils(struct test *t, int subtest);
> +int test__jit_write_elf(struct test *test, int subtest);
>
> bool test__bp_signal_is_supported(void);
> bool test__bp_account_is_supported(void);
> diff --git a/tools/perf/util/genelf.c b/tools/perf/util/genelf.c
> index f9f18b8b1df9..aed49806a09b 100644
> --- a/tools/perf/util/genelf.c
> +++ b/tools/perf/util/genelf.c
> @@ -8,15 +8,12 @@
> */
>
> #include <sys/types.h>
> -#include <stdio.h>
> -#include <getopt.h>
> #include <stddef.h>
> #include <libelf.h>
> #include <string.h>
> #include <stdlib.h>
> #include <unistd.h>
> #include <inttypes.h>
> -#include <limits.h>
> #include <fcntl.h>
> #include <err.h>
> #ifdef HAVE_DWARF_SUPPORT
> @@ -31,8 +28,6 @@
> #define NT_GNU_BUILD_ID 3
> #endif
>
> -#define JVMTI
> -
> #define BUILD_ID_URANDOM /* different uuid for each run */
>
> #ifdef HAVE_LIBCRYPTO
> @@ -511,44 +506,3 @@ jit_write_elf(int fd, uint64_t load_addr, const char *sym,
>
> return retval;
> }
> -
> -#ifndef JVMTI
> -
> -static unsigned char x86_code[] = {
> - 0xBB, 0x2A, 0x00, 0x00, 0x00, /* movl $42, %ebx */
> - 0xB8, 0x01, 0x00, 0x00, 0x00, /* movl $1, %eax */
> - 0xCD, 0x80 /* int $0x80 */
> -};
> -
> -static struct options options;
> -
> -int main(int argc, char **argv)
> -{
> - int c, fd, ret;
> -
> - while ((c = getopt(argc, argv, "o:h")) != -1) {
> - switch (c) {
> - case 'o':
> - options.output = optarg;
> - break;
> - case 'h':
> - printf("Usage: genelf -o output_file [-h]\n");
> - return 0;
> - default:
> - errx(1, "unknown option");
> - }
> - }
> -
> - fd = open(options.output, O_CREAT|O_TRUNC|O_RDWR, 0666);
> - if (fd == -1)
> - err(1, "cannot create file %s", options.output);
> -
> - ret = jit_write_elf(fd, "main", x86_code, sizeof(x86_code));
> - close(fd);
> -
> - if (ret != 0)
> - unlink(options.output);
> -
> - return ret;
> -}
> -#endif
> --
> 2.24.0.432.g9d3f5f5b63-goog
--
- Arnaldo
next prev parent reply other threads:[~2019-11-27 15:23 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-26 23:59 [PATCH] perf jit: move test functionality in to a test Ian Rogers
2019-11-27 15:23 ` Arnaldo Carvalho de Melo [this message]
2019-11-27 16:05 ` Arnaldo Carvalho de Melo
2019-11-27 18:49 ` Ian Rogers
2019-11-28 13:19 ` Arnaldo Carvalho de Melo
2019-12-02 17:30 ` Ian Rogers
2019-12-02 18:20 ` Arnaldo Carvalho de Melo
2019-12-04 7:53 ` [tip: perf/urgent] perf jit: Move " tip-bot2 for Ian Rogers
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=20191127152328.GI22719@kernel.org \
--to=arnaldo.melo@gmail.com \
--cc=adrian.hunter@intel.com \
--cc=alexander.shishkin@linux.intel.com \
--cc=alexios.zavras@intel.com \
--cc=allison@lohutok.net \
--cc=eranian@google.com \
--cc=f.fainelli@gmail.com \
--cc=gregkh@linuxfoundation.org \
--cc=irogers@google.com \
--cc=jolsa@redhat.com \
--cc=kstewart@linuxfoundation.org \
--cc=leo.yan@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mingo@redhat.com \
--cc=mpetlan@redhat.com \
--cc=namhyung@kernel.org \
--cc=peterz@infradead.org \
--cc=songliubraving@fb.com \
--cc=tglx@linutronix.de \
/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.