Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #include <limits.h>
0003 #include <stdio.h>
0004 #include <stdlib.h>
0005 #include <string.h>
0006 #include <unistd.h>
0007 #include <linux/compiler.h>
0008 
0009 #include "debug.h"
0010 #include "tests.h"
0011 
0012 #ifdef HAVE_JITDUMP
0013 #include <libelf.h>
0014 #include "../util/genelf.h"
0015 #endif
0016 
0017 #define TEMPL "/tmp/perf-test-XXXXXX"
0018 
0019 static int test__jit_write_elf(struct test_suite *test __maybe_unused,
0020                    int subtest __maybe_unused)
0021 {
0022 #ifdef HAVE_JITDUMP
0023     static unsigned char x86_code[] = {
0024         0xBB, 0x2A, 0x00, 0x00, 0x00, /* movl $42, %ebx */
0025         0xB8, 0x01, 0x00, 0x00, 0x00, /* movl $1, %eax */
0026         0xCD, 0x80            /* int $0x80 */
0027     };
0028     char path[PATH_MAX];
0029     int fd, ret;
0030 
0031     strcpy(path, TEMPL);
0032 
0033     fd = mkstemp(path);
0034     if (fd < 0) {
0035         perror("mkstemp failed");
0036         return TEST_FAIL;
0037     }
0038 
0039     pr_info("Writing jit code to: %s\n", path);
0040 
0041     ret = jit_write_elf(fd, 0, "main", x86_code, sizeof(x86_code),
0042             NULL, 0, NULL, 0, 0);
0043     close(fd);
0044 
0045     unlink(path);
0046 
0047     return ret ? TEST_FAIL : 0;
0048 #else
0049     return TEST_SKIP;
0050 #endif
0051 }
0052 
0053 DEFINE_SUITE("Test jit_write_elf", jit_write_elf);