linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] perf jit: move test functionality in to a test
@ 2019-11-26 23:59 Ian Rogers
  2019-11-27 15:23 ` Arnaldo Carvalho de Melo
  2019-12-04  7:53 ` [tip: perf/urgent] perf jit: Move " tip-bot2 for Ian Rogers
  0 siblings, 2 replies; 8+ messages in thread
From: Ian Rogers @ 2019-11-26 23:59 UTC (permalink / raw)
  To: Peter Zijlstra, Ingo Molnar, Arnaldo Carvalho de Melo,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Song Liu, Leo Yan, Michael Petlan,
	Florian Fainelli, Kate Stewart, Greg Kroah-Hartman,
	Allison Randal, Alexios Zavras, Thomas Gleixner, linux-kernel,
	Stephane Eranian
  Cc: Ian Rogers

Adds a test for minimal jit_write_elf functionality.

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf jit: move test functionality in to a test
  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
  2019-11-27 16:05   ` Arnaldo Carvalho de Melo
  2019-12-04  7:53 ` [tip: perf/urgent] perf jit: Move " tip-bot2 for Ian Rogers
  1 sibling, 1 reply; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-11-27 15:23 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Adrian Hunter, Song Liu, Leo Yan,
	Michael Petlan, Florian Fainelli, Kate Stewart,
	Greg Kroah-Hartman, Allison Randal, Alexios Zavras,
	Thomas Gleixner, linux-kernel, Stephane Eranian

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf jit: move test functionality in to a test
  2019-11-27 15:23 ` Arnaldo Carvalho de Melo
@ 2019-11-27 16:05   ` Arnaldo Carvalho de Melo
  2019-11-27 18:49     ` Ian Rogers
  0 siblings, 1 reply; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-11-27 16:05 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Adrian Hunter, Song Liu, Leo Yan,
	Michael Petlan, Florian Fainelli, Kate Stewart,
	Greg Kroah-Hartman, Allison Randal, Alexios Zavras,
	Thomas Gleixner, linux-kernel, Stephane Eranian

Em Wed, Nov 27, 2019 at 12:23:28PM -0300, Arnaldo Carvalho de Melo escreveu:
> 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.

Had to apply this to have it built in systems where HAVE_JITDUMP isn't
defined:

diff --git a/tools/perf/tests/genelf.c b/tools/perf/tests/genelf.c
index d392e9300881..28dfd17a6b9f 100644
--- a/tools/perf/tests/genelf.c
+++ b/tools/perf/tests/genelf.c
@@ -17,16 +17,15 @@
 
 #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
+	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;
 
@@ -48,6 +47,6 @@ int test__jit_write_elf(struct test *test __maybe_unused,
 
 	return ret ? TEST_FAIL : 0;
 #else
-	return TEST_SKIPPED;
+	return TEST_SKIP;
 #endif
 }



^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf jit: move test functionality in to a test
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Rogers @ 2019-11-27 18:49 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Adrian Hunter, Song Liu, Leo Yan,
	Michael Petlan, Florian Fainelli, Kate Stewart,
	Greg Kroah-Hartman, Allison Randal, Alexios Zavras,
	Thomas Gleixner, LKML, Stephane Eranian

On Wed, Nov 27, 2019 at 8:06 AM Arnaldo Carvalho de Melo
<arnaldo.melo@gmail.com> wrote:
>
> Em Wed, Nov 27, 2019 at 12:23:28PM -0300, Arnaldo Carvalho de Melo escreveu:
> > 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.
>
> Had to apply this to have it built in systems where HAVE_JITDUMP isn't
> defined:

Thanks for fixing this!
Ian

> diff --git a/tools/perf/tests/genelf.c b/tools/perf/tests/genelf.c
> index d392e9300881..28dfd17a6b9f 100644
> --- a/tools/perf/tests/genelf.c
> +++ b/tools/perf/tests/genelf.c
> @@ -17,16 +17,15 @@
>
>  #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
> +       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;
>
> @@ -48,6 +47,6 @@ int test__jit_write_elf(struct test *test __maybe_unused,
>
>         return ret ? TEST_FAIL : 0;
>  #else
> -       return TEST_SKIPPED;
> +       return TEST_SKIP;
>  #endif
>  }
>
>

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf jit: move test functionality in to a test
  2019-11-27 18:49     ` Ian Rogers
@ 2019-11-28 13:19       ` Arnaldo Carvalho de Melo
  2019-12-02 17:30         ` Ian Rogers
  0 siblings, 1 reply; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-11-28 13:19 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Song Liu, Leo Yan, Michael Petlan,
	Florian Fainelli, Kate Stewart, Greg Kroah-Hartman,
	Allison Randal, Alexios Zavras, Thomas Gleixner, LKML,
	Stephane Eranian

Em Wed, Nov 27, 2019 at 10:49:29AM -0800, Ian Rogers escreveu:
> On Wed, Nov 27, 2019 at 8:06 AM Arnaldo Carvalho de Melo
> <arnaldo.melo@gmail.com> wrote:
> >
> > Em Wed, Nov 27, 2019 at 12:23:28PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > 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.
> >
> > Had to apply this to have it built in systems where HAVE_JITDUMP isn't
> > defined:
> 
> Thanks for fixing this!
> Ian

This needs some more work, as it is failing in some of the cross build
containers, for arches not supported by that genelf.h header, where it
should just detect that this feature shouldn't be used, warn the user
and build what is possible to build, e.g.:

  CC       /tmp/build/perf/util/evswitch.o
In file included from tests/genelf.c:15:
tests/../util/genelf.h:42:2: error: #error "unsupported architecture"
   42 | #error "unsupported architecture"
      |  ^~~~~
tests/../util/genelf.h:51:5: error: "GEN_ELF_CLASS" is not defined, evaluates to 0 [-Werror=undef]
   51 | #if GEN_ELF_CLASS == ELFCLASS64
      |     ^~~~~~~~~~~~~
cc1: all warnings being treated as errors
mv: cannot stat '/tmp/build/perf/tests/.genelf.o.tmp': No such file or directory
make[4]: *** [/git/linux/tools/build/Makefile.build:96: /tmp/build/perf/tests/genelf.o] Error 1
make[4]: *** Waiting for unfinished jobs....
  CC       /tmp/build/perf/util/find_bit.o
  CC       /tmp/build/perf/util/get_current_dir_name.o


There is some wiring up to do here, related to:
[acme@quaco perf]$ vim tools/perf/Makefile.config
[acme@quaco perf]$ find . -type f| xargs grep PERF_HAVE_JITDUMP
grep: ./et: No such file or directory
grep: vi: No such file or directory
^Xgrep: ./perf.data: Permission denied
./tools/perf/arch/x86/Makefile:PERF_HAVE_JITDUMP := 1
./tools/perf/arch/sparc/Makefile:PERF_HAVE_JITDUMP := 1
./tools/perf/arch/arm/Makefile:PERF_HAVE_JITDUMP := 1
./tools/perf/arch/arm64/Makefile:PERF_HAVE_JITDUMP := 1
./tools/perf/arch/powerpc/Makefile:PERF_HAVE_JITDUMP := 1
./tools/perf/arch/s390/Makefile:PERF_HAVE_JITDUMP := 1
./tools/perf/Makefile.config:ifdef PERF_HAVE_JITDUMP
^C
[acme@quaco perf]$

But I'll defer this for later, not to hold what I have too much, after
my next pull req I'll revisit this, if you haven't found a fix by then
:-)

The current patch is below, with my fixes, and looking at it again it
seems its just to replace that HAVE_LIBELF_SUPPORT with HAVE_JITDUMP,
will confirm that later, after sending the pull req to Ingo.

- Arnaldo

commit d006842faa9a26feb51b818e02c681f064b83b0a
Author: Ian Rogers <irogers@google.com>
Date:   Tue Nov 26 15:59:13 2019 -0800

    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>

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index a3c595fba943..1692529639b0 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 += maps.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 7115aa32a51e..970e2ecfb39f 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -296,6 +296,10 @@ static struct test generic_tests[] = {
 		.desc = "time utils",
 		.func = test__time_utils,
 	},
+	{
+		.desc = "Test jit_write_elf",
+		.func = test__jit_write_elf,
+	},
 	{
 		.desc = "maps__merge_in",
 		.func = test__maps__merge_in,
diff --git a/tools/perf/tests/genelf.c b/tools/perf/tests/genelf.c
new file mode 100644
index 000000000000..28dfd17a6b9f
--- /dev/null
+++ b/tools/perf/tests/genelf.c
@@ -0,0 +1,52 @@
+// 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"
+
+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
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 25aea387e2bf..0e6d67910b0a 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__maps__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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf jit: move test functionality in to a test
  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
  0 siblings, 1 reply; 8+ messages in thread
From: Ian Rogers @ 2019-12-02 17:30 UTC (permalink / raw)
  To: Arnaldo Carvalho de Melo
  Cc: Peter Zijlstra, Ingo Molnar, Mark Rutland, Alexander Shishkin,
	Jiri Olsa, Namhyung Kim, Adrian Hunter, Song Liu, Leo Yan,
	Michael Petlan, Florian Fainelli, Kate Stewart,
	Greg Kroah-Hartman, Allison Randal, Alexios Zavras,
	Thomas Gleixner, LKML, Stephane Eranian

On Thu, Nov 28, 2019 at 5:19 AM Arnaldo Carvalho de Melo
<arnaldo.melo@gmail.com> wrote:
>
> Em Wed, Nov 27, 2019 at 10:49:29AM -0800, Ian Rogers escreveu:
> > On Wed, Nov 27, 2019 at 8:06 AM Arnaldo Carvalho de Melo
> > <arnaldo.melo@gmail.com> wrote:
> > >
> > > Em Wed, Nov 27, 2019 at 12:23:28PM -0300, Arnaldo Carvalho de Melo escreveu:
> > > > 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.
> > >
> > > Had to apply this to have it built in systems where HAVE_JITDUMP isn't
> > > defined:
> >
> > Thanks for fixing this!
> > Ian
>
> This needs some more work, as it is failing in some of the cross build
> containers, for arches not supported by that genelf.h header, where it
> should just detect that this feature shouldn't be used, warn the user
> and build what is possible to build, e.g.:
>
>   CC       /tmp/build/perf/util/evswitch.o
> In file included from tests/genelf.c:15:
> tests/../util/genelf.h:42:2: error: #error "unsupported architecture"
>    42 | #error "unsupported architecture"
>       |  ^~~~~
> tests/../util/genelf.h:51:5: error: "GEN_ELF_CLASS" is not defined, evaluates to 0 [-Werror=undef]
>    51 | #if GEN_ELF_CLASS == ELFCLASS64
>       |     ^~~~~~~~~~~~~
> cc1: all warnings being treated as errors
> mv: cannot stat '/tmp/build/perf/tests/.genelf.o.tmp': No such file or directory
> make[4]: *** [/git/linux/tools/build/Makefile.build:96: /tmp/build/perf/tests/genelf.o] Error 1
> make[4]: *** Waiting for unfinished jobs....
>   CC       /tmp/build/perf/util/find_bit.o
>   CC       /tmp/build/perf/util/get_current_dir_name.o
>
>
> There is some wiring up to do here, related to:
> [acme@quaco perf]$ vim tools/perf/Makefile.config
> [acme@quaco perf]$ find . -type f| xargs grep PERF_HAVE_JITDUMP
> grep: ./et: No such file or directory
> grep: vi: No such file or directory
> ^Xgrep: ./perf.data: Permission denied
> ./tools/perf/arch/x86/Makefile:PERF_HAVE_JITDUMP := 1
> ./tools/perf/arch/sparc/Makefile:PERF_HAVE_JITDUMP := 1
> ./tools/perf/arch/arm/Makefile:PERF_HAVE_JITDUMP := 1
> ./tools/perf/arch/arm64/Makefile:PERF_HAVE_JITDUMP := 1
> ./tools/perf/arch/powerpc/Makefile:PERF_HAVE_JITDUMP := 1
> ./tools/perf/arch/s390/Makefile:PERF_HAVE_JITDUMP := 1
> ./tools/perf/Makefile.config:ifdef PERF_HAVE_JITDUMP
> ^C
> [acme@quaco perf]$
>
> But I'll defer this for later, not to hold what I have too much, after
> my next pull req I'll revisit this, if you haven't found a fix by then
> :-)
>
> The current patch is below, with my fixes, and looking at it again it
> seems its just to replace that HAVE_LIBELF_SUPPORT with HAVE_JITDUMP,
> will confirm that later, after sending the pull req to Ingo.
>
> - Arnaldo

Your fix sounds correct, I should work on getting a build test setup.
It sounds like you have it covered but if you need me to do anything
let me know.

Thanks,
Ian

> commit d006842faa9a26feb51b818e02c681f064b83b0a
> Author: Ian Rogers <irogers@google.com>
> Date:   Tue Nov 26 15:59:13 2019 -0800
>
>     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>
>
> diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
> index a3c595fba943..1692529639b0 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 += maps.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 7115aa32a51e..970e2ecfb39f 100644
> --- a/tools/perf/tests/builtin-test.c
> +++ b/tools/perf/tests/builtin-test.c
> @@ -296,6 +296,10 @@ static struct test generic_tests[] = {
>                 .desc = "time utils",
>                 .func = test__time_utils,
>         },
> +       {
> +               .desc = "Test jit_write_elf",
> +               .func = test__jit_write_elf,
> +       },
>         {
>                 .desc = "maps__merge_in",
>                 .func = test__maps__merge_in,
> diff --git a/tools/perf/tests/genelf.c b/tools/perf/tests/genelf.c
> new file mode 100644
> index 000000000000..28dfd17a6b9f
> --- /dev/null
> +++ b/tools/perf/tests/genelf.c
> @@ -0,0 +1,52 @@
> +// 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"
> +
> +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
> +}
> diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
> index 25aea387e2bf..0e6d67910b0a 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__maps__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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] perf jit: move test functionality in to a test
  2019-12-02 17:30         ` Ian Rogers
@ 2019-12-02 18:20           ` Arnaldo Carvalho de Melo
  0 siblings, 0 replies; 8+ messages in thread
From: Arnaldo Carvalho de Melo @ 2019-12-02 18:20 UTC (permalink / raw)
  To: Ian Rogers
  Cc: Arnaldo Carvalho de Melo, Peter Zijlstra, Ingo Molnar,
	Mark Rutland, Alexander Shishkin, Jiri Olsa, Namhyung Kim,
	Adrian Hunter, Song Liu, Leo Yan, Michael Petlan,
	Florian Fainelli, Kate Stewart, Greg Kroah-Hartman,
	Allison Randal, Alexios Zavras, Thomas Gleixner, LKML,
	Stephane Eranian

Em Mon, Dec 02, 2019 at 09:30:19AM -0800, Ian Rogers escreveu:
> On Thu, Nov 28, 2019 at 5:19 AM Arnaldo Carvalho de Melo
> > But I'll defer this for later, not to hold what I have too much, after
> > my next pull req I'll revisit this, if you haven't found a fix by then
> > :-)

> > The current patch is below, with my fixes, and looking at it again it
> > seems its just to replace that HAVE_LIBELF_SUPPORT with HAVE_JITDUMP,
> > will confirm that later, after sending the pull req to Ingo.
 
> Your fix sounds correct, I should work on getting a build test setup.
> It sounds like you have it covered but if you need me to do anything
> let me know.

Right, everything seems to be in good shape now and should go Ingo's way
soon.

- Arnaldo

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [tip: perf/urgent] perf jit: Move test functionality in to a test
  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
@ 2019-12-04  7:53 ` tip-bot2 for Ian Rogers
  1 sibling, 0 replies; 8+ messages in thread
From: tip-bot2 for Ian Rogers @ 2019-12-04  7:53 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: Ian Rogers, Arnaldo Carvalho de Melo, Adrian Hunter,
	Alexander Shishkin, Alexios Zavras, Allison Randal,
	Florian Fainelli, Greg Kroah-Hartman, Jiri Olsa, Kate Stewart,
	Leo Yan, Mark Rutland, Michael Petlan, Namhyung Kim,
	Peter Zijlstra, Song Liu, Stephane Eranian, Thomas Gleixner, x86,
	LKML

The following commit has been merged into the perf/urgent branch of tip:

Commit-ID:     fa7f7e7354957422b43ea950b672d3e731f27e68
Gitweb:        https://git.kernel.org/tip/fa7f7e7354957422b43ea950b672d3e731f27e68
Author:        Ian Rogers <irogers@google.com>
AuthorDate:    Tue, 26 Nov 2019 15:59:13 -08:00
Committer:     Arnaldo Carvalho de Melo <acme@redhat.com>
CommitterDate: Fri, 29 Nov 2019 12:20:45 -03:00

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>
---
 tools/perf/tests/Build          |  1 +-
 tools/perf/tests/builtin-test.c |  4 +++-
 tools/perf/tests/genelf.c       | 51 ++++++++++++++++++++++++++++++++-
 tools/perf/tests/tests.h        |  1 +-
 tools/perf/util/genelf.c        | 46 +-----------------------------
 5 files changed, 57 insertions(+), 46 deletions(-)
 create mode 100644 tools/perf/tests/genelf.c

diff --git a/tools/perf/tests/Build b/tools/perf/tests/Build
index a3c595f..1692529 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 += maps.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 82d19a8..5f05db7 100644
--- a/tools/perf/tests/builtin-test.c
+++ b/tools/perf/tests/builtin-test.c
@@ -302,6 +302,10 @@ static struct test generic_tests[] = {
 		.func = test__time_utils,
 	},
 	{
+		.desc = "Test jit_write_elf",
+		.func = test__jit_write_elf,
+	},
+	{
 		.desc = "maps__merge_in",
 		.func = test__maps__merge_in,
 	},
diff --git a/tools/perf/tests/genelf.c b/tools/perf/tests/genelf.c
new file mode 100644
index 0000000..f797f98
--- /dev/null
+++ b/tools/perf/tests/genelf.c
@@ -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
+}
diff --git a/tools/perf/tests/tests.h b/tools/perf/tests/tests.h
index 4f9ae6a..9a160fe 100644
--- a/tools/perf/tests/tests.h
+++ b/tools/perf/tests/tests.h
@@ -110,6 +110,7 @@ int test__unit_number__scnprint(struct test *test, int subtest);
 int test__mem2node(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__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 f9f18b8..aed4980 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 @@ error:
 
 	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

^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-12-04  7:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).