perf jit: Move test functionality in to a test
Adds a test for minimal jit_write_elf functionality. Committer testing: # perf test jit 61: Test jit_write_elf : Ok # # perf test -v jit 61: Test jit_write_elf : --- start --- test child forked, pid 10460 Writing jit code to: /tmp/perf-test-KqxURR test child finished with 0 ---- end ---- Test jit_write_elf: Ok # Committer notes: Fix up the case where HAVE_JITDUMP is no defined. Signed-off-by: Ian Rogers <irogers@google.com> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Alexios Zavras <alexios.zavras@intel.com> Cc: Allison Randal <allison@lohutok.net> Cc: Florian Fainelli <f.fainelli@gmail.com> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Kate Stewart <kstewart@linuxfoundation.org> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Michael Petlan <mpetlan@redhat.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Song Liu <songliubraving@fb.com> Cc: Stephane Eranian <eranian@google.com> Cc: Thomas Gleixner <tglx@linutronix.de> Link: http://lore.kernel.org/lkml/20191126235913.41855-1-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
704e2f5b70
commit
fa7f7e7354
|
@ -54,6 +54,7 @@ perf-y += unit_number__scnprintf.o
|
||||||
perf-y += mem2node.o
|
perf-y += mem2node.o
|
||||||
perf-y += maps.o
|
perf-y += maps.o
|
||||||
perf-y += time-utils-test.o
|
perf-y += time-utils-test.o
|
||||||
|
perf-y += genelf.o
|
||||||
|
|
||||||
$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
|
$(OUTPUT)tests/llvm-src-base.c: tests/bpf-script-example.c tests/Build
|
||||||
$(call rule_mkdir)
|
$(call rule_mkdir)
|
||||||
|
|
|
@ -301,6 +301,10 @@ static struct test generic_tests[] = {
|
||||||
.desc = "time utils",
|
.desc = "time utils",
|
||||||
.func = test__time_utils,
|
.func = test__time_utils,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.desc = "Test jit_write_elf",
|
||||||
|
.func = test__jit_write_elf,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
.desc = "maps__merge_in",
|
.desc = "maps__merge_in",
|
||||||
.func = test__maps__merge_in,
|
.func = test__maps__merge_in,
|
||||||
|
|
51
tools/perf/tests/genelf.c
Normal file
51
tools/perf/tests/genelf.c
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
// 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_JITDUMP
|
||||||
|
#include <libelf.h>
|
||||||
|
#include "../util/genelf.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define TEMPL "/tmp/perf-test-XXXXXX"
|
||||||
|
|
||||||
|
int test__jit_write_elf(struct test *test __maybe_unused,
|
||||||
|
int subtest __maybe_unused)
|
||||||
|
{
|
||||||
|
#ifdef HAVE_JITDUMP
|
||||||
|
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 */
|
||||||
|
};
|
||||||
|
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_SKIP;
|
||||||
|
#endif
|
||||||
|
}
|
|
@ -110,6 +110,7 @@ int test__unit_number__scnprint(struct test *test, int subtest);
|
||||||
int test__mem2node(struct test *t, int subtest);
|
int test__mem2node(struct test *t, int subtest);
|
||||||
int test__maps__merge_in(struct test *t, int subtest);
|
int test__maps__merge_in(struct test *t, int subtest);
|
||||||
int test__time_utils(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_signal_is_supported(void);
|
||||||
bool test__bp_account_is_supported(void);
|
bool test__bp_account_is_supported(void);
|
||||||
|
|
|
@ -8,15 +8,12 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <stdio.h>
|
|
||||||
#include <getopt.h>
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <libelf.h>
|
#include <libelf.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <limits.h>
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#ifdef HAVE_DWARF_SUPPORT
|
#ifdef HAVE_DWARF_SUPPORT
|
||||||
|
@ -31,8 +28,6 @@
|
||||||
#define NT_GNU_BUILD_ID 3
|
#define NT_GNU_BUILD_ID 3
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define JVMTI
|
|
||||||
|
|
||||||
#define BUILD_ID_URANDOM /* different uuid for each run */
|
#define BUILD_ID_URANDOM /* different uuid for each run */
|
||||||
|
|
||||||
#ifdef HAVE_LIBCRYPTO
|
#ifdef HAVE_LIBCRYPTO
|
||||||
|
@ -511,44 +506,3 @@ error:
|
||||||
|
|
||||||
return retval;
|
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
|
|
||||||
|
|
Loading…
Reference in a new issue