mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/xiang/erofs.git
synced 2026-11-08 18:43:21 +01:00
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 <[email protected]> Tested-by: Arnaldo Carvalho de Melo <[email protected]> Cc: Adrian Hunter <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Alexios Zavras <[email protected]> Cc: Allison Randal <[email protected]> Cc: Florian Fainelli <[email protected]> Cc: Greg Kroah-Hartman <[email protected]> Cc: Jiri Olsa <[email protected]> Cc: Kate Stewart <[email protected]> Cc: Leo Yan <[email protected]> Cc: Mark Rutland <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Song Liu <[email protected]> Cc: Stephane Eranian <[email protected]> Cc: Thomas Gleixner <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
52 lines
995 B
C
52 lines
995 B
C
// 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
|
|
}
|