Rizin
unix-like reverse engineering framework and cli tools
rz_test.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2020 thestr4ng3r <info@florianmaerkl.de>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef RIZIN_RZTEST_H
5 #define RIZIN_RZTEST_H
6 
7 #include <rz_util.h>
8 
9 #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__)
10 #define RZ_TEST_OS "freebsd"
11 #elif defined(__linux__)
12 #define RZ_TEST_OS "linux"
13 #elif defined(__APPLE__)
14 #define RZ_TEST_OS "darwin"
15 #elif __WINDOWS__
16 #define RZ_TEST_OS "windows"
17 #else
18 #define RZ_TEST_OS "unknown"
19 #endif
20 
21 #if __i386__
22 #define RZ_TEST_ARCH "x86"
23 #elif __x86_64__
24 #define RZ_TEST_ARCH "x64"
25 #elif __arm__
26 #define RZ_TEST_ARCH "arm"
27 #elif __arm64__
28 #define RZ_TEST_ARCH "arm64"
29 #else
30 #define RZ_TEST_ARCH "unknown"
31 #endif
32 
33 #define RZ_TEST_ARCH_OS RZ_TEST_OS "-" RZ_TEST_ARCH
34 
36  char *value;
37  ut64 line_begin; // inclusive
38  ut64 line_end; // exclusive
40 
42  bool value;
43  ut64 line; // bools are always oneliners (e.g. BROKEN=1)
44  bool set;
46 
49  ut64 line; // nums are always oneliners (e.g. TIMEOUT=10)
50  bool set;
52 
53 typedef struct rz_test_cmd_test_t {
68 
69 // A temporary workaround while clang-format bug is not fixed:
70 // https://bugs.llvm.org/show_bug.cgi?id=46240
71 
72 // clang-format off
73 #define RZ_CMD_TEST_FOREACH_RECORD_NOP(name, field)
74 #define RZ_CMD_TEST_FOREACH_RECORD(macro_str, macro_bool, macro_int) \
75  macro_str ("NAME", name) \
76  macro_str ("FILE", file) \
77  macro_str ("ARGS", args) \
78  macro_int ("TIMEOUT", timeout) \
79  macro_str ("SOURCE", source) \
80  macro_str ("CMDS", cmds) \
81  macro_str ("EXPECT", expect) \
82  macro_str ("EXPECT_ERR", expect_err) \
83  macro_str ("REGEXP_FILTER_OUT", regexp_out) \
84  macro_str ("REGEXP_FILTER_ERR", regexp_err) \
85  macro_bool ("BROKEN", broken)
86 // clang-format on
87 
92  RZ_ASM_TEST_MODE_BROKEN = (1 << 3)
94 
95 typedef struct rz_test_asm_test_t {
97  const char *arch;
98  const char *cpu;
99  int bits;
100  int mode;
104  size_t bytes_size;
107 
108 typedef struct rz_test_json_test_t {
110  char *cmd;
111  bool broken;
114 
115 typedef struct rz_test_fuzz_test_t {
116  char *file;
118 
119 typedef enum rz_test_test_type_t {
125 
126 typedef struct rz_test_test_t {
127  const char *path;
129  union {
134  };
136 
137 typedef struct rz_test_test_database_t {
141 
142 typedef struct rz_test_run_config_t {
143  const char *rz_cmd;
144  const char *rz_asm_cmd;
145  const char *json_test_file;
148 
150  char *disasm;
152  size_t bytes_size;
153  char *il;
154  char *il_report;
155  bool il_failed;
160 
161 typedef enum rz_test_test_result_t {
167 
171  bool timeout;
172  bool run_failed; // something went seriously wrong (e.g. rizin not found)
174  union {
175  RzSubprocessOutput *proc_out; // for test->type == RZ_TEST_TYPE_CMD, RZ_TEST_TYPE_JSON or RZ_TEST_TYPE_FUZZ
176  RzAsmTestOutput *asm_out; // for test->type == RZ_TEST_TYPE_ASM
177  };
179 
183 
187 
191 
196 
197 typedef RzSubprocessOutput *(*RzTestCmdRunner)(const char *file, const char *args[], size_t args_size,
198  const char *envvars[], const char *envvals[], size_t env_size, ut64 timeout_ms, void *user);
199 
202 RZ_API bool rz_test_cmp_cmd_output(const char *output, const char *expect, const char *regexp);
211 
217 
218 #endif // RIZIN_RZTEST_H
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define RZ_API
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
uint8_t ut8
Definition: lh5801.h:11
#define expect(expr, value)
Definition: lz4.c:170
int args
Definition: mipsasm.c:18
-lz4-versions
enum rz_test_test_result_t RzTestResult
RZ_API bool rz_test_check_asm_test(RzAsmTestOutput *out, RzAsmTest *test)
Definition: run.c:389
struct rz_test_cmd_test_num_record RzCmdTestNumRecord
RZ_API RzJsonTest * rz_test_json_test_new(void)
Definition: load.c:470
RZ_API RzTestResultInfo * rz_test_run_test(RzTestRunConfig *config, RzTest *test)
Definition: run.c:482
enum rz_test_test_type_t RzTestType
RZ_API RzSubprocessOutput * rz_test_run_cmd_test(RzTestRunConfig *config, RzCmdTest *test, RzTestCmdRunner runner, void *user)
Definition: run.c:161
RZ_API RzPVector * rz_test_load_cmd_test_file(const char *file)
Definition: load.c:105
RZ_API bool rz_test_test_database_load(RzTestDatabase *db, const char *path)
Definition: load.c:756
RZ_API bool rz_test_check_jq_available(void)
Definition: run.c:223
RZ_API RzSubprocessOutput * rz_test_run_json_test(RzTestRunConfig *config, RzJsonTest *test, RzTestCmdRunner runner, void *user)
Definition: run.c:246
RZ_API RzTestDatabase * rz_test_test_database_new(void)
Definition: load.c:567
struct rz_test_json_test_t RzJsonTest
RZ_API RzAsmTestOutput * rz_test_run_asm_test(RzTestRunConfig *config, RzAsmTest *test)
Definition: run.c:267
struct rz_test_test_database_t RzTestDatabase
struct rz_test_test_result_info_t RzTestResultInfo
rz_test_test_result_t
Definition: rz_test.h:161
@ RZ_TEST_RESULT_OK
Definition: rz_test.h:162
@ RZ_TEST_RESULT_FAILED
Definition: rz_test.h:163
@ RZ_TEST_RESULT_FIXED
Definition: rz_test.h:165
@ RZ_TEST_RESULT_BROKEN
Definition: rz_test.h:164
RzSubprocessOutput *(* RzTestCmdRunner)(const char *file, const char *args[], size_t args_size, const char *envvars[], const char *envvals[], size_t env_size, ut64 timeout_ms, void *user)
Definition: rz_test.h:197
RZ_API void rz_test_test_database_free(RzTestDatabase *db)
Definition: load.c:577
RZ_API RzCmdTest * rz_test_cmd_test_new(void)
Definition: load.c:10
struct rz_test_test_t RzTest
RZ_API RzPVector * rz_test_load_json_test_file(const char *file)
Definition: load.c:482
RZ_API bool rz_test_check_json_test(RzSubprocessOutput *out, RzJsonTest *test)
Definition: run.c:254
RZ_API void rz_test_test_free(RzTest *test)
Definition: load.c:546
RZ_API bool rz_test_test_database_load_fuzz(RzTestDatabase *db, const char *path)
Definition: load.c:782
RZ_API RzAsmTest * rz_test_asm_test_new(void)
Definition: load.c:259
RZ_API void rz_test_json_test_free(RzJsonTest *test)
Definition: load.c:474
RZ_API bool rz_test_cmp_cmd_output(const char *output, const char *expect, const char *regexp)
Definition: run.c:192
struct rz_test_run_config_t RzTestRunConfig
RZ_API void rz_test_cmd_test_free(RzCmdTest *test)
Definition: load.c:14
RZ_API RzPVector * rz_test_load_asm_test_file(RzStrConstPool *strpool, const char *file)
Definition: load.c:313
struct rz_test_cmd_test_string_record RzCmdTestStringRecord
RZ_API RzSubprocessOutput * rz_test_run_fuzz_test(RzTestRunConfig *config, RzFuzzTest *test, RzTestCmdRunner runner, void *user)
Definition: run.c:433
RZ_API bool rz_test_check_cmd_test(RzSubprocessOutput *out, RzCmdTest *test)
Definition: run.c:204
struct rz_test_asm_test_t RzAsmTest
RZ_API void rz_test_test_result_info_free(RzTestResultInfo *result)
Definition: run.c:552
struct rz_test_asm_test_output_t RzAsmTestOutput
struct rz_test_cmd_test_t RzCmdTest
enum rz_test_asm_test_mode_t RzAsmTestMode
RZ_API void rz_test_asm_test_output_free(RzAsmTestOutput *out)
Definition: run.c:422
RZ_API bool rz_test_check_fuzz_test(RzSubprocessOutput *out)
Definition: run.c:447
struct rz_test_fuzz_test_t RzFuzzTest
rz_test_test_type_t
Definition: rz_test.h:119
@ RZ_TEST_TYPE_JSON
Definition: rz_test.h:122
@ RZ_TEST_TYPE_ASM
Definition: rz_test.h:121
@ RZ_TEST_TYPE_FUZZ
Definition: rz_test.h:123
@ RZ_TEST_TYPE_CMD
Definition: rz_test.h:120
RZ_API bool rz_test_test_broken(RzTest *test)
struct rz_test_cmd_test_bool_record RzCmdTestBoolRecord
rz_test_asm_test_mode_t
Definition: rz_test.h:88
@ RZ_ASM_TEST_MODE_BIG_ENDIAN
Definition: rz_test.h:91
@ RZ_ASM_TEST_MODE_BROKEN
Definition: rz_test.h:92
@ RZ_ASM_TEST_MODE_ASSEMBLE
Definition: rz_test.h:89
@ RZ_ASM_TEST_MODE_DISASSEMBLE
Definition: rz_test.h:90
RZ_API char * rz_test_test_name(RzTest *test)
Definition: run.c:451
RZ_API void rz_test_asm_test_free(RzAsmTest *test)
Definition: load.c:263
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_NONNULL
Definition: rz_types.h:64
Definition: gzappend.c:170
RZ_NONNULL ut8 * bytes
Definition: rz_test.h:103
const char * arch
Definition: rz_test.h:97
RZ_NONNULL char * disasm
Definition: rz_test.h:102
size_t bytes_size
Definition: rz_test.h:104
RZ_NULLABLE char * il
Definition: rz_test.h:105
const char * cpu
Definition: rz_test.h:98
RzCmdTestStringRecord expect
Definition: rz_test.h:59
RzCmdTestNumRecord timeout
Definition: rz_test.h:64
RzCmdTestStringRecord regexp_out
Definition: rz_test.h:61
RzCmdTestStringRecord regexp_err
Definition: rz_test.h:62
RzCmdTestStringRecord file
Definition: rz_test.h:55
RzCmdTestStringRecord source
Definition: rz_test.h:57
RzCmdTestStringRecord expect_err
Definition: rz_test.h:60
RzCmdTestStringRecord args
Definition: rz_test.h:56
RzCmdTestBoolRecord broken
Definition: rz_test.h:63
RzCmdTestStringRecord cmds
Definition: rz_test.h:58
RzCmdTestStringRecord name
Definition: rz_test.h:54
const char * rz_asm_cmd
Definition: rz_test.h:144
const char * rz_cmd
Definition: rz_test.h:143
const char * json_test_file
Definition: rz_test.h:145
RzStrConstPool strpool
Definition: rz_test.h:139
RzAsmTestOutput * asm_out
Definition: rz_test.h:176
RzSubprocessOutput * proc_out
Definition: rz_test.h:175
RzCmdTest * cmd_test
Definition: rz_test.h:130
const char * path
Definition: rz_test.h:127
RzFuzzTest * fuzz_test
Definition: rz_test.h:133
RzJsonTest * json_test
Definition: rz_test.h:132
RzAsmTest * asm_test
Definition: rz_test.h:131
RzTestType type
Definition: rz_test.h:128
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int file
Definition: z80asm.c:58
diff_output_t output
Definition: zipcmp.c:237