Rizin
unix-like reverse engineering framework and cli tools
rz_test.h File Reference
#include <rz_util.h>

Go to the source code of this file.

Classes

struct  rz_test_cmd_test_string_record
 
struct  rz_test_cmd_test_bool_record
 
struct  rz_test_cmd_test_num_record
 
struct  rz_test_cmd_test_t
 
struct  rz_test_asm_test_t
 
struct  rz_test_json_test_t
 
struct  rz_test_fuzz_test_t
 
struct  rz_test_test_t
 
struct  rz_test_test_database_t
 
struct  rz_test_run_config_t
 
struct  rz_test_asm_test_output_t
 
struct  rz_test_test_result_info_t
 

Macros

#define RZ_TEST_OS   "unknown"
 
#define RZ_TEST_ARCH   "unknown"
 
#define RZ_TEST_ARCH_OS   RZ_TEST_OS "-" RZ_TEST_ARCH
 
#define RZ_CMD_TEST_FOREACH_RECORD_NOP(name, field)
 
#define RZ_CMD_TEST_FOREACH_RECORD(macro_str, macro_bool, macro_int)
 

Typedefs

typedef struct rz_test_cmd_test_string_record RzCmdTestStringRecord
 
typedef struct rz_test_cmd_test_bool_record RzCmdTestBoolRecord
 
typedef struct rz_test_cmd_test_num_record RzCmdTestNumRecord
 
typedef struct rz_test_cmd_test_t RzCmdTest
 
typedef enum rz_test_asm_test_mode_t RzAsmTestMode
 
typedef struct rz_test_asm_test_t RzAsmTest
 
typedef struct rz_test_json_test_t RzJsonTest
 
typedef struct rz_test_fuzz_test_t RzFuzzTest
 
typedef enum rz_test_test_type_t RzTestType
 
typedef struct rz_test_test_t RzTest
 
typedef struct rz_test_test_database_t RzTestDatabase
 
typedef struct rz_test_run_config_t RzTestRunConfig
 
typedef struct rz_test_asm_test_output_t RzAsmTestOutput
 
typedef enum rz_test_test_result_t RzTestResult
 
typedef struct rz_test_test_result_info_t RzTestResultInfo
 
typedef 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)
 

Enumerations

enum  rz_test_asm_test_mode_t { RZ_ASM_TEST_MODE_ASSEMBLE = 1 , RZ_ASM_TEST_MODE_DISASSEMBLE = (1 << 1) , RZ_ASM_TEST_MODE_BIG_ENDIAN = (1 << 2) , RZ_ASM_TEST_MODE_BROKEN = (1 << 3) }
 
enum  rz_test_test_type_t { RZ_TEST_TYPE_CMD , RZ_TEST_TYPE_ASM , RZ_TEST_TYPE_JSON , RZ_TEST_TYPE_FUZZ }
 
enum  rz_test_test_result_t { RZ_TEST_RESULT_OK , RZ_TEST_RESULT_FAILED , RZ_TEST_RESULT_BROKEN , RZ_TEST_RESULT_FIXED }
 

Functions

RZ_API RzCmdTestrz_test_cmd_test_new (void)
 
RZ_API void rz_test_cmd_test_free (RzCmdTest *test)
 
RZ_API RzPVectorrz_test_load_cmd_test_file (const char *file)
 
RZ_API RzAsmTestrz_test_asm_test_new (void)
 
RZ_API void rz_test_asm_test_free (RzAsmTest *test)
 
RZ_API RzPVectorrz_test_load_asm_test_file (RzStrConstPool *strpool, const char *file)
 
RZ_API RzJsonTestrz_test_json_test_new (void)
 
RZ_API void rz_test_json_test_free (RzJsonTest *test)
 
RZ_API RzPVectorrz_test_load_json_test_file (const char *file)
 
RZ_API RzTestDatabaserz_test_test_database_new (void)
 
RZ_API void rz_test_test_database_free (RzTestDatabase *db)
 
RZ_API bool rz_test_test_database_load (RzTestDatabase *db, const char *path)
 
RZ_API bool rz_test_test_database_load_fuzz (RzTestDatabase *db, const char *path)
 
RZ_API RzSubprocessOutputrz_test_run_cmd_test (RzTestRunConfig *config, RzCmdTest *test, RzTestCmdRunner runner, void *user)
 
RZ_API bool rz_test_check_cmd_test (RzSubprocessOutput *out, RzCmdTest *test)
 
RZ_API bool rz_test_cmp_cmd_output (const char *output, const char *expect, const char *regexp)
 
RZ_API bool rz_test_check_jq_available (void)
 
RZ_API RzSubprocessOutputrz_test_run_json_test (RzTestRunConfig *config, RzJsonTest *test, RzTestCmdRunner runner, void *user)
 
RZ_API bool rz_test_check_json_test (RzSubprocessOutput *out, RzJsonTest *test)
 
RZ_API RzAsmTestOutputrz_test_run_asm_test (RzTestRunConfig *config, RzAsmTest *test)
 
RZ_API bool rz_test_check_asm_test (RzAsmTestOutput *out, RzAsmTest *test)
 
RZ_API void rz_test_asm_test_output_free (RzAsmTestOutput *out)
 
RZ_API RzSubprocessOutputrz_test_run_fuzz_test (RzTestRunConfig *config, RzFuzzTest *test, RzTestCmdRunner runner, void *user)
 
RZ_API bool rz_test_check_fuzz_test (RzSubprocessOutput *out)
 
RZ_API void rz_test_test_free (RzTest *test)
 
RZ_API char * rz_test_test_name (RzTest *test)
 
RZ_API bool rz_test_test_broken (RzTest *test)
 
RZ_API RzTestResultInforz_test_run_test (RzTestRunConfig *config, RzTest *test)
 
RZ_API void rz_test_test_result_info_free (RzTestResultInfo *result)
 

Macro Definition Documentation

◆ RZ_CMD_TEST_FOREACH_RECORD

#define RZ_CMD_TEST_FOREACH_RECORD (   macro_str,
  macro_bool,
  macro_int 
)
Value:
macro_str ("NAME", name) \
macro_str ("FILE", file) \
macro_str ("ARGS", args) \
macro_int ("TIMEOUT", timeout) \
macro_str ("SOURCE", source) \
macro_str ("CMDS", cmds) \
macro_str ("EXPECT", expect) \
macro_str ("EXPECT_ERR", expect_err) \
macro_str ("REGEXP_FILTER_OUT", regexp_out) \
macro_str ("REGEXP_FILTER_ERR", regexp_err) \
macro_bool ("BROKEN", broken)
#define expect(expr, value)
Definition: lz4.c:170
const char * source
Definition: lz4.h:699
int args
Definition: mipsasm.c:18
Definition: gzappend.c:170
Definition: z80asm.h:102
uv_timer_t timeout
Definition: main.c:9
#define macro_str(s)
Definition: te.c:21

Definition at line 74 of file rz_test.h.

◆ RZ_CMD_TEST_FOREACH_RECORD_NOP

#define RZ_CMD_TEST_FOREACH_RECORD_NOP (   name,
  field 
)

Definition at line 73 of file rz_test.h.

◆ RZ_TEST_ARCH

#define RZ_TEST_ARCH   "unknown"

Definition at line 30 of file rz_test.h.

◆ RZ_TEST_ARCH_OS

#define RZ_TEST_ARCH_OS   RZ_TEST_OS "-" RZ_TEST_ARCH

Definition at line 33 of file rz_test.h.

◆ RZ_TEST_OS

#define RZ_TEST_OS   "unknown"

Definition at line 18 of file rz_test.h.

Typedef Documentation

◆ RzAsmTest

typedef struct rz_test_asm_test_t RzAsmTest

◆ RzAsmTestMode

◆ RzAsmTestOutput

◆ RzCmdTest

typedef struct rz_test_cmd_test_t RzCmdTest

◆ RzCmdTestBoolRecord

◆ RzCmdTestNumRecord

◆ RzCmdTestStringRecord

◆ RzFuzzTest

◆ RzJsonTest

◆ RzTest

typedef struct rz_test_test_t RzTest

◆ RzTestCmdRunner

typedef 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 at line 197 of file rz_test.h.

◆ RzTestDatabase

◆ RzTestResult

◆ RzTestResultInfo

◆ RzTestRunConfig

◆ RzTestType

Enumeration Type Documentation

◆ rz_test_asm_test_mode_t

Enumerator
RZ_ASM_TEST_MODE_ASSEMBLE 
RZ_ASM_TEST_MODE_DISASSEMBLE 
RZ_ASM_TEST_MODE_BIG_ENDIAN 
RZ_ASM_TEST_MODE_BROKEN 

Definition at line 88 of file rz_test.h.

88  {
91  RZ_ASM_TEST_MODE_BIG_ENDIAN = (1 << 2),
92  RZ_ASM_TEST_MODE_BROKEN = (1 << 3)
enum rz_test_asm_test_mode_t RzAsmTestMode
@ 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_test_test_result_t

Enumerator
RZ_TEST_RESULT_OK 
RZ_TEST_RESULT_FAILED 
RZ_TEST_RESULT_BROKEN 
RZ_TEST_RESULT_FIXED 

Definition at line 161 of file rz_test.h.

161  {
166 } RzTestResult;
enum rz_test_test_result_t RzTestResult
@ 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

◆ rz_test_test_type_t

Enumerator
RZ_TEST_TYPE_CMD 
RZ_TEST_TYPE_ASM 
RZ_TEST_TYPE_JSON 
RZ_TEST_TYPE_FUZZ 

Definition at line 119 of file rz_test.h.

119  {
124 } RzTestType;
enum rz_test_test_type_t RzTestType
@ 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

Function Documentation

◆ rz_test_asm_test_free()

RZ_API void rz_test_asm_test_free ( RzAsmTest test)

Definition at line 263 of file load.c.

263  {
264  if (!test) {
265  return;
266  }
267  free(test->disasm);
268  free(test->bytes);
269  free(test->il);
270  free(test);
271 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
-lz4-versions

References free().

Referenced by rz_test_test_free().

◆ rz_test_asm_test_new()

RZ_API RzAsmTest* rz_test_asm_test_new ( void  )

Definition at line 259 of file load.c.

259  {
260  return RZ_NEW0(RzAsmTest);
261 }
#define RZ_NEW0(x)
Definition: rz_types.h:284

References RZ_NEW0.

Referenced by rz_test_load_asm_test_file().

◆ rz_test_asm_test_output_free()

RZ_API void rz_test_asm_test_output_free ( RzAsmTestOutput out)

Definition at line 422 of file run.c.

422  {
423  if (!out) {
424  return;
425  }
426  free(out->disasm);
427  free(out->bytes);
428  free(out->il);
429  free(out->il_report);
430  free(out);
431 }
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528

References free(), and out.

Referenced by rz_test_test_result_info_free().

◆ rz_test_check_asm_test()

RZ_API bool rz_test_check_asm_test ( RzAsmTestOutput out,
RzAsmTest test 
)

Definition at line 389 of file run.c.

389  {
390  if (!out) {
391  return false;
392  }
393  if (test->mode & RZ_ASM_TEST_MODE_ASSEMBLE) {
394  if (!out->bytes || !test->bytes || out->bytes_size != test->bytes_size || out->as_timeout) {
395  return false;
396  }
397  if (memcmp(out->bytes, test->bytes, test->bytes_size) != 0) {
398  return false;
399  }
400  }
401  if (test->mode & RZ_ASM_TEST_MODE_DISASSEMBLE) {
402  if (!out->disasm || !test->disasm || out->as_timeout) {
403  return false;
404  }
405  if (strcmp(out->disasm, test->disasm) != 0) {
406  return false;
407  }
408  }
409  if (test->il) {
410  // expect some IL, no failure, no report and no timeout
411  if (!out->il || out->il_failed || (out->il_report && *out->il_report) || out->il_timeout) {
412  return false;
413  }
414  // IL must also be correct
415  if (strcmp(out->il, test->il) != 0) {
416  return false;
417  }
418  }
419  return true;
420 }

References out, RZ_ASM_TEST_MODE_ASSEMBLE, and RZ_ASM_TEST_MODE_DISASSEMBLE.

Referenced by rz_test_run_test().

◆ rz_test_check_cmd_test()

RZ_API bool rz_test_check_cmd_test ( RzSubprocessOutput out,
RzCmdTest test 
)

Definition at line 204 of file run.c.

204  {
205  if (!out || out->ret != 0 || !out->out || !out->err || out->timeout) {
206  return false;
207  }
208  const char *expect_out = test->expect.value;
209  const char *regexp_out = test->regexp_out.value;
210  if (expect_out && !rz_test_cmp_cmd_output((char *)out->out, expect_out, regexp_out)) {
211  return false;
212  }
213  const char *expect_err = test->expect_err.value;
214  const char *regexp_err = test->regexp_err.value;
215  if (expect_err && !rz_test_cmp_cmd_output((char *)out->err, expect_err, regexp_err)) {
216  return false;
217  }
218  return true;
219 }
RZ_API bool rz_test_cmp_cmd_output(const char *output, const char *expect, const char *regexp)
Definition: run.c:192

References out, and rz_test_cmp_cmd_output().

Referenced by rz_test_run_test().

◆ rz_test_check_fuzz_test()

RZ_API bool rz_test_check_fuzz_test ( RzSubprocessOutput out)

Definition at line 447 of file run.c.

447  {
448  return out && out->ret == 0 && out->out && out->err && !out->timeout;
449 }

References out.

Referenced by rz_test_run_test().

◆ rz_test_check_jq_available()

RZ_API bool rz_test_check_jq_available ( void  )

Definition at line 223 of file run.c.

223  {
224  const char *args[] = { "." };
225  const char *invalid_json = "this is not json lol";
227  if (proc) {
228  rz_subprocess_stdin_write(proc, (const ut8 *)invalid_json, strlen(invalid_json));
230  }
231  bool invalid_detected = proc && rz_subprocess_ret(proc) != 0;
233 
234  const char *valid_json = "{\"this is\":\"valid json\",\"lol\":true}";
236  if (proc) {
237  rz_subprocess_stdin_write(proc, (const ut8 *)valid_json, strlen(valid_json));
239  }
240  bool valid_detected = proc && rz_subprocess_ret(proc) == 0;
242 
243  return invalid_detected && valid_detected;
244 }
#define JQ_CMD
Definition: run.c:221
#define NULL
Definition: cris-opc.c:27
uint8_t ut8
Definition: lh5801.h:11
RZ_API RzSubprocessWaitReason rz_subprocess_wait(RzSubprocess *proc, ut64 timeout_ms)
Definition: subprocess.c:1185
RZ_API void rz_subprocess_free(RzSubprocess *proc)
Definition: subprocess.c:1273
RZ_API RzSubprocess * rz_subprocess_start(const char *file, const char *args[], size_t args_size, const char *envvars[], const char *envvals[], size_t env_size)
Definition: subprocess.c:1345
RZ_API ssize_t rz_subprocess_stdin_write(RzSubprocess *proc, const ut8 *buf, size_t buf_size)
Definition: subprocess.c:1206
RZ_API int rz_subprocess_ret(RzSubprocess *proc)
Definition: subprocess.c:1297
#define UT64_MAX
Definition: rz_types_base.h:86
struct Proc * proc

References args, JQ_CMD, NULL, proc, rz_subprocess_free(), rz_subprocess_ret(), rz_subprocess_start(), rz_subprocess_stdin_write(), rz_subprocess_wait(), and UT64_MAX.

Referenced by rz_test_main().

◆ rz_test_check_json_test()

RZ_API bool rz_test_check_json_test ( RzSubprocessOutput out,
RzJsonTest test 
)

Definition at line 254 of file run.c.

254  {
255  if (!out || out->ret != 0 || !out->out || !out->err || out->timeout) {
256  return false;
257  }
258  const char *args[] = { "." };
260  rz_subprocess_stdin_write(proc, (const ut8 *)out->out, strlen((char *)out->out));
262  bool ret = rz_subprocess_ret(proc) == 0;
264  return ret;
265 }

References args, JQ_CMD, NULL, out, proc, rz_subprocess_free(), rz_subprocess_ret(), rz_subprocess_start(), rz_subprocess_stdin_write(), rz_subprocess_wait(), and UT64_MAX.

Referenced by rz_test_run_test().

◆ rz_test_cmd_test_free()

RZ_API void rz_test_cmd_test_free ( RzCmdTest test)

Definition at line 14 of file load.c.

14  {
15  if (!test) {
16  return;
17  }
18 #define DO_KEY_STR(key, field) free(test->field.value);
20 #undef DO_KEY_STR
21  free(test);
22 }
#define DO_KEY_STR(key, field)
#define RZ_CMD_TEST_FOREACH_RECORD_NOP(name, field)
Definition: rz_test.h:73
#define RZ_CMD_TEST_FOREACH_RECORD(macro_str, macro_bool, macro_int)
Definition: rz_test.h:74

References DO_KEY_STR, free(), RZ_CMD_TEST_FOREACH_RECORD, and RZ_CMD_TEST_FOREACH_RECORD_NOP.

Referenced by rz_test_load_cmd_test_file(), and rz_test_test_free().

◆ rz_test_cmd_test_new()

RZ_API RzCmdTest* rz_test_cmd_test_new ( void  )

Definition at line 10 of file load.c.

10  {
11  return RZ_NEW0(RzCmdTest);
12 }

References RZ_NEW0.

Referenced by rz_test_load_cmd_test_file().

◆ rz_test_cmp_cmd_output()

RZ_API bool rz_test_cmp_cmd_output ( const char *  output,
const char *  expect,
const char *  regexp 
)

Definition at line 192 of file run.c.

192  {
193  if (regexp) {
194  RzList *matches = rz_regex_get_match_list(regexp, "e", output);
195  const char *match = rz_list_to_str(matches, '\0');
196  bool equal = (0 == strcmp(expect, match));
197  rz_list_free(matches);
198  RZ_FREE(match);
199  return equal;
200  }
201  return (0 == strcmp(expect, output));
202 }
RZ_API RZ_OWN char * rz_list_to_str(RZ_NONNULL RzList *list, char ch)
Casts a RzList containg strings into a concatenated string.
Definition: list.c:785
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
RZ_API RzList * rz_regex_get_match_list(const char *pattern, const char *flags, const char *text)
Definition: regcomp.c:155
#define RZ_FREE(x)
Definition: rz_types.h:369
Definition: engine.c:71
diff_output_t output
Definition: zipcmp.c:237

References expect, output, RZ_FREE, rz_list_free(), rz_list_to_str(), and rz_regex_get_match_list().

Referenced by print_result_diff(), and rz_test_check_cmd_test().

◆ rz_test_json_test_free()

RZ_API void rz_test_json_test_free ( RzJsonTest test)

Definition at line 474 of file load.c.

474  {
475  if (!test) {
476  return;
477  }
478  free(test->cmd);
479  free(test);
480 }

References free().

Referenced by rz_test_load_json_test_file(), and rz_test_test_free().

◆ rz_test_json_test_new()

RZ_API RzJsonTest* rz_test_json_test_new ( void  )

Definition at line 470 of file load.c.

470  {
471  return RZ_NEW0(RzJsonTest);
472 }

References RZ_NEW0.

Referenced by rz_test_load_json_test_file().

◆ rz_test_load_asm_test_file()

RZ_API RzPVector* rz_test_load_asm_test_file ( RzStrConstPool strpool,
const char *  file 
)

Definition at line 313 of file load.c.

313  {
314  const char *arch;
315  const char *cpu;
316  int bits;
317  if (!parse_asm_path(file, strpool, &arch, &cpu, &bits)) {
318  eprintf("Failed to parse arch/cpu/bits from path %s\n", file);
319  return NULL;
320  }
321 
322  char *contents = rz_file_slurp(file, NULL);
323  if (!contents) {
324  eprintf("Failed to open file \"%s\"\n", file);
325  return NULL;
326  }
327 
328  RzPVector *ret = rz_pvector_new(NULL);
329  if (!ret) {
330  return NULL;
331  }
332 
333  ut64 linenum = 0;
334  char *line = contents;
335  size_t linesz;
336  char *nextline;
337  do {
338  nextline = readline(line, &linesz);
339  linenum++;
340  if (!linesz) {
341  continue;
342  }
343  if (*line == '#') {
344  continue;
345  }
346 
347  // mode flags
348  int mode = 0;
349  while (*line && *line != ' ') {
350  switch (*line) {
351  case 'a':
353  break;
354  case 'd':
356  break;
357  case 'E':
359  break;
360  case 'B':
362  break;
363  default:
364  eprintf(LINEFMT "Warning: Invalid mode char '%c'\n", file, linenum, *line);
365  goto fail;
366  }
367  line++;
368  }
370  eprintf(LINEFMT "Warning: Mode specifies neither assemble nor disassemble.\n", file, linenum);
371  continue;
372  }
373 
374  // disasm
375  char *disasm = strchr(line, '"');
376  if (!disasm) {
377  eprintf(LINEFMT "Error: Expected \" to begin disassembly.\n", file, linenum);
378  goto fail;
379  }
380  disasm++;
381  char *hex = strchr(disasm, '"');
382  if (!hex) {
383  eprintf(LINEFMT "Error: Expected \" to end disassembly.\n", file, linenum);
384  goto fail;
385  }
386  *hex = '\0';
387  hex++;
388  rz_str_trim(disasm);
389 
390  // hex
391  while (*hex && *hex == ' ') {
392  hex++;
393  }
394 
395  // remove comment at the end of the line
396  char *latecmt = strchr(hex, '#');
397  if (latecmt) {
398  *latecmt = '\0';
399  }
400 
401  // offset (optional)
402  char *offset = strchr(hex, ' ');
403  char *il = NULL;
404  if (offset) {
405  *offset = '\0';
406  offset++;
407 
408  // IL (optional, the entire rest)
409  il = strchr(offset, ' ');
410  if (il) {
411  *il = '\0';
412  il++;
413  }
414  }
415 
416  size_t hexlen = strlen(hex);
417  if (!hexlen) {
418  eprintf(LINEFMT "Error: Expected hex chars.\n", file, linenum);
419  goto fail;
420  }
421  ut8 *bytes = malloc(hexlen);
422  if (!bytes) {
423  break;
424  }
425  int bytesz = rz_hex_str2bin(hex, bytes);
426  if (bytesz == 0) {
427  eprintf(LINEFMT "Error: Expected hex chars.\n", file, linenum);
428  free(bytes);
429  goto fail;
430  }
431  if (bytesz < 0) {
432  eprintf(LINEFMT "Error: Odd number of hex chars: %s\n", file, linenum, hex);
433  free(bytes);
434  goto fail;
435  }
436 
438  if (!test) {
439  free(bytes);
440  goto fail;
441  }
442  test->line = linenum;
443  test->bits = bits;
444  test->arch = arch;
445  test->cpu = cpu;
446  test->mode = mode;
447  char *endptr = NULL;
448  test->offset = offset ? (ut64)strtoull(offset, &endptr, 0) : 0;
449  if (endptr && *endptr) {
450  eprintf(LINEFMT "Error: Invalid offset string: \"%s\"\n", file, linenum, offset);
451  free(bytes);
452  goto fail;
453  }
454  test->disasm = strdup(disasm);
455  test->bytes = bytes;
456  test->bytes_size = (size_t)bytesz;
457  test->il = il ? strdup(il) : NULL;
458  rz_pvector_push(ret, test);
459  } while ((line = nextline));
460 
461 beach:
462  free(contents);
463  return ret;
464 fail:
465  rz_pvector_free(ret);
466  ret = NULL;
467  goto beach;
468 }
static ut32 cpu[32]
Definition: analysis_or1k.c:21
static ut8 bytes[32]
Definition: asm_arc.c:23
int bits(struct state *s, int need)
Definition: blast.c:72
cs_arch arch
Definition: cstool.c:13
voidpf uLong offset
Definition: ioapi.h:144
const char int mode
Definition: ioapi.h:137
void * malloc(size_t size)
Definition: malloc.c:123
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static char * readline(char *buf, size_t *linesz)
Definition: load.c:24
#define LINEFMT
Definition: load.c:8
RZ_API RzAsmTest * rz_test_asm_test_new(void)
Definition: load.c:259
static bool parse_asm_path(const char *path, RzStrConstPool *strpool, const char **arch_out, const char **cpuout, int *bitsout)
Definition: load.c:273
line
Definition: setup.py:34
static const char hex[16]
Definition: print.c:21
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API RZ_OWN char * rz_file_slurp(const char *str, RZ_NULLABLE size_t *usz)
Definition: file.c:454
RZ_API int rz_hex_str2bin(const char *in, ut8 *out)
Convert an input string in into the binary form in out.
Definition: hex.c:444
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
RZ_API RzPVector * rz_pvector_new(RzPVectorFree free)
Definition: vector.c:302
static void ** rz_pvector_push(RzPVector *vec, void *x)
Definition: rz_vector.h:300
RZ_API void rz_pvector_free(RzPVector *vec)
Definition: vector.c:336
int size_t
Definition: sftypes.h:40
#define fail(test)
Definition: tests.h:29
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References arch, bits(), bytes, cpu, eprintf, fail, free(), hex, setup::line, LINEFMT, malloc(), NULL, parse_asm_path(), readline(), RZ_ASM_TEST_MODE_ASSEMBLE, RZ_ASM_TEST_MODE_BIG_ENDIAN, RZ_ASM_TEST_MODE_BROKEN, RZ_ASM_TEST_MODE_DISASSEMBLE, rz_file_slurp(), rz_hex_str2bin(), rz_pvector_free(), rz_pvector_new(), rz_pvector_push(), rz_str_trim(), rz_test_asm_test_new(), strdup(), and ut64().

Referenced by database_load().

◆ rz_test_load_cmd_test_file()

RZ_API RzPVector* rz_test_load_cmd_test_file ( const char *  file)

Definition at line 105 of file load.c.

105  {
106  char *contents = rz_file_slurp(file, NULL);
107  if (!contents) {
108  eprintf("Failed to open file \"%s\"\n", file);
109  return NULL;
110  }
111 
112  RzPVector *ret = rz_pvector_new(NULL);
113  if (!ret) {
114  free(contents);
115  return NULL;
116  }
118  if (!test) {
119  free(contents);
120  rz_pvector_free(ret);
121  return NULL;
122  }
123 
124  ut64 linenum = 0;
125  char *line = contents;
126  size_t linesz;
127  char *nextline;
128  do {
129  nextline = readline(line, &linesz);
130  linenum++;
131  if (!linesz) {
132  continue;
133  }
134  if (*line == '#') {
135  continue;
136  }
137 
138  char *val = strchr(line, '=');
139  if (val) {
140  *val = '\0';
141  val++;
142  } else if (!val && !(strcmp(line, "RUN") == 0)) {
143  eprintf("Error: No value for key \"%s\".\n", line);
144  goto fail;
145  }
146 
147  // RUN is the only cmd without value
148  if (strcmp(line, "RUN") == 0) {
149  test->run_line = linenum;
150  if (!test->cmds.value) {
151  eprintf(LINEFMT "Error: Test without CMDS key\n", file, linenum);
152  goto fail;
153  }
154  if (!(test->expect.value || test->expect_err.value)) {
155  eprintf(LINEFMT "Error: Test without EXPECT or EXPECT_ERR key"
156  " (did you forget an EOF?)\n",
157  file, linenum);
158  goto fail;
159  }
160  rz_pvector_push(ret, test);
162  if (!test) {
163  goto beach;
164  }
165  continue;
166  }
167 
168 #define DO_KEY_STR(key, field) \
169  if (strcmp(line, key) == 0) { \
170  if (test->field.value) { \
171  free(test->field.value); \
172  eprintf(LINEFMT "Warning: Duplicate key \"%s\"\n", file, linenum, key); \
173  } \
174  test->field.line_begin = linenum; \
175  test->field.value = read_string_val(&nextline, val, &linenum); \
176  test->field.line_end = linenum + 1; \
177  if (!test->field.value) { \
178  eprintf(LINEFMT "Error: Failed to read value for key \"%s\"\n", file, linenum, key); \
179  goto fail; \
180  } \
181  continue; \
182  }
183 
184 #define DO_KEY_BOOL(key, field) \
185  if (strcmp(line, key) == 0) { \
186  if (test->field.value) { \
187  eprintf(LINEFMT "Warning: Duplicate key \"%s\"\n", file, linenum, key); \
188  } \
189  test->field.set = true; \
190  /* Strip comment */ \
191  char *cmt = strchr(val, '#'); \
192  if (cmt) { \
193  *cmt = '\0'; \
194  cmt--; \
195  while (cmt > val && *cmt == ' ') { \
196  *cmt = '\0'; \
197  cmt--; \
198  } \
199  } \
200  if (!strcmp(val, "1")) { \
201  test->field.value = true; \
202  } else if (!strcmp(val, "0")) { \
203  test->field.value = false; \
204  } else { \
205  eprintf(LINEFMT "Error: Invalid value \"%s\" for boolean key \"%s\", only \"1\" or \"0\" allowed.\n", file, linenum, val, key); \
206  goto fail; \
207  } \
208  continue; \
209  }
210 
211 #define DO_KEY_NUM(key, field) \
212  if (strcmp(line, key) == 0) { \
213  if (test->field.value) { \
214  eprintf(LINEFMT "Warning: Duplicate key \"%s\"\n", file, linenum, key); \
215  } \
216  test->field.set = true; \
217  /* Strip comment */ \
218  char *cmt = strchr(val, '#'); \
219  if (cmt) { \
220  *cmt = '\0'; \
221  cmt--; \
222  while (cmt > val && *cmt == ' ') { \
223  *cmt = '\0'; \
224  cmt--; \
225  } \
226  } \
227  char *endval; \
228  test->field.value = strtol(val, &endval, 0); \
229  if (!endval || *endval) { \
230  eprintf(LINEFMT "Error: Invalid value \"%s\" for numeric key \"%s\", only numbers allowed.\n", file, linenum, val, key); \
231  goto fail; \
232  } \
233  continue; \
234  }
235 
237 #undef DO_KEY_STR
238 #undef DO_KEY_BOOL
239 #undef DO_KEY_NUM
240 
241  eprintf(LINEFMT "Unknown key \"%s\".\n", file, linenum, line);
242  } while ((line = nextline));
243 beach:
244  free(contents);
245 
246  if (test && (test->name.value || test->cmds.value || test->expect.value)) {
247  eprintf("Warning: found test tokens at the end of \"%s\" without RUN.\n", file);
248  }
250  return ret;
251 fail:
253  test = NULL;
254  rz_pvector_free(ret);
255  ret = NULL;
256  goto beach;
257 }
ut16 val
Definition: armass64_const.h:6
RZ_API RzCmdTest * rz_test_cmd_test_new(void)
Definition: load.c:10
#define DO_KEY_NUM(key, field)
RZ_API void rz_test_cmd_test_free(RzCmdTest *test)
Definition: load.c:14
#define DO_KEY_BOOL(key, field)

References DO_KEY_BOOL, DO_KEY_NUM, DO_KEY_STR, eprintf, fail, free(), setup::line, LINEFMT, NULL, readline(), RZ_CMD_TEST_FOREACH_RECORD, rz_file_slurp(), rz_pvector_free(), rz_pvector_new(), rz_pvector_push(), rz_test_cmd_test_free(), rz_test_cmd_test_new(), ut64(), and val.

Referenced by database_load().

◆ rz_test_load_json_test_file()

RZ_API RzPVector* rz_test_load_json_test_file ( const char *  file)

Definition at line 482 of file load.c.

482  {
483  char *contents = rz_file_slurp(file, NULL);
484  if (!contents) {
485  eprintf("Failed to open file \"%s\"\n", file);
486  return NULL;
487  }
488 
489  RzPVector *ret = rz_pvector_new(NULL);
490  if (!ret) {
491  free(contents);
492  return NULL;
493  }
494 
495  ut64 linenum = 0;
496  char *line = contents;
497  size_t linesz;
498  char *nextline;
499  do {
500  nextline = readline(line, &linesz);
501  linenum++;
502  if (!linesz) {
503  continue;
504  }
505  if (*line == '#') {
506  continue;
507  }
508 
509  char *broken_token = strstr(line, "BROKEN");
510  if (broken_token) {
511  *broken_token = '\0';
512  }
513 
514  rz_str_trim(line);
515  if (!*line) {
516  // empty line
517  continue;
518  }
519 
521  if (!test) {
522  break;
523  }
524  test->line = linenum;
525  test->cmd = strdup(line);
526  if (!test->cmd) {
528  break;
529  }
530  test->broken = broken_token ? true : false;
531  rz_pvector_push(ret, test);
532  } while ((line = nextline));
533 
534  free(contents);
535  return ret;
536 }
#define true
RZ_API RzJsonTest * rz_test_json_test_new(void)
Definition: load.c:470
RZ_API void rz_test_json_test_free(RzJsonTest *test)
Definition: load.c:474

References eprintf, free(), setup::line, NULL, readline(), rz_file_slurp(), rz_pvector_new(), rz_pvector_push(), rz_str_trim(), rz_test_json_test_free(), rz_test_json_test_new(), strdup(), true, and ut64().

Referenced by database_load().

◆ rz_test_run_asm_test()

RZ_API RzAsmTestOutput* rz_test_run_asm_test ( RzTestRunConfig config,
RzAsmTest test 
)

Definition at line 267 of file run.c.

267  {
269  if (!out) {
270  return NULL;
271  }
272 
273  RzPVector args;
275 
276  if (test->arch) {
277  rz_pvector_push(&args, "-a");
278  rz_pvector_push(&args, (void *)test->arch);
279  }
280 
281  if (test->cpu) {
282  rz_pvector_push(&args, "-c");
283  rz_pvector_push(&args, (void *)test->cpu);
284  }
285 
286  char bits[0x20];
287  if (test->bits) {
288  snprintf(bits, sizeof(bits), "%d", test->bits);
289  rz_pvector_push(&args, "-b");
291  }
292 
293  if (test->mode & RZ_ASM_TEST_MODE_BIG_ENDIAN) {
294  rz_pvector_push(&args, "-e");
295  }
296 
297  char offset[0x20];
298  if (test->offset) {
299  rz_snprintf(offset, sizeof(offset), "0x%" PFMT64x, test->offset);
300  rz_pvector_push(&args, "-o");
302  }
303 
304  if (test->mode & RZ_ASM_TEST_MODE_ASSEMBLE) {
305  rz_pvector_push(&args, test->disasm);
307  if (rz_subprocess_wait(proc, config->timeout_ms) == RZ_SUBPROCESS_TIMEDOUT) {
309  out->as_timeout = true;
310  goto rip;
311  }
312  if (rz_subprocess_ret(proc) != 0) {
313  goto rip;
314  }
315  char *hex = (char *)crlf2lf(rz_subprocess_out(proc, NULL));
316  size_t hexlen = strlen(hex);
317  if (!hexlen) {
318  goto rip;
319  }
320  ut8 *bytes = malloc(hexlen);
321  int byteslen = rz_hex_str2bin(hex, bytes);
322  free(hex);
323  if (byteslen <= 0) {
324  free(bytes);
325  goto rip;
326  }
327  out->bytes = bytes;
328  out->bytes_size = (size_t)byteslen;
329  rip:
332  }
333  if (test->mode & RZ_ASM_TEST_MODE_DISASSEMBLE) {
334  char *hex = rz_hex_bin2strdup(test->bytes, test->bytes_size);
335  if (!hex) {
336  goto beach;
337  }
338  rz_pvector_push(&args, "-d");
341  if (rz_subprocess_wait(proc, config->timeout_ms) == RZ_SUBPROCESS_TIMEDOUT) {
343  out->disas_timeout = true;
344  goto ship;
345  }
346  if (rz_subprocess_ret(proc) != 0) {
347  goto ship;
348  }
349  char *disasm = (char *)crlf2lf(rz_subprocess_out(proc, NULL));
350  rz_str_trim(disasm);
351  out->disasm = disasm;
352  ship:
353  free(hex);
357  }
358  if (test->il) {
359  char *hex = rz_hex_bin2strdup(test->bytes, test->bytes_size);
360  if (!hex) {
361  goto beach;
362  }
363  rz_pvector_push(&args, "-I");
366  if (rz_subprocess_wait(proc, config->timeout_ms) == RZ_SUBPROCESS_TIMEDOUT) {
368  out->il_timeout = true;
369  } else {
370  char *il = (char *)crlf2lf(rz_subprocess_out(proc, NULL));
371  rz_str_trim(il);
372  char *il_err = (char *)crlf2lf(rz_subprocess_err(proc, NULL));
373  rz_str_trim(il_err);
374  out->il = il;
375  out->il_report = il_err;
376  out->il_failed = rz_subprocess_ret(proc) != 0;
377  }
378  free(hex);
382  }
383 
384 beach:
386  return out;
387 }
#define crlf2lf(x)
Definition: run.c:24
void rip(char *fname, off_t offset, unsigned int length)
Definition: cabrip.c:18
snprintf
Definition: kernel.h:364
RZ_API char * rz_hex_bin2strdup(const ut8 *in, int len)
Definition: hex.c:415
RZ_API int rz_snprintf(char *string, int len, const char *fmt,...) RZ_PRINTF_CHECK(3
@ RZ_SUBPROCESS_TIMEDOUT
Definition: rz_subprocess.h:32
RZ_API ut8 * rz_subprocess_out(RzSubprocess *proc, int *length)
Definition: subprocess.c:1301
RZ_API ut8 * rz_subprocess_err(RzSubprocess *proc, int *length)
Definition: subprocess.c:1312
RZ_API void rz_subprocess_kill(RzSubprocess *proc)
Definition: subprocess.c:1256
#define PFMT64x
Definition: rz_types.h:393
RZ_API void * rz_pvector_pop(RzPVector *vec)
Definition: vector.c:372
RZ_API void rz_pvector_init(RzPVector *vec, RzPVectorFree free)
Definition: vector.c:298
static size_t rz_pvector_len(const RzPVector *vec)
Definition: rz_vector.h:231
RZ_API void rz_pvector_clear(RzPVector *vec)
Definition: vector.c:326

References args, bits(), bytes, crlf2lf, free(), hex, malloc(), NULL, out, PFMT64x, proc, rip(), RZ_ASM_TEST_MODE_ASSEMBLE, RZ_ASM_TEST_MODE_BIG_ENDIAN, RZ_ASM_TEST_MODE_DISASSEMBLE, rz_hex_bin2strdup(), rz_hex_str2bin(), RZ_NEW0, rz_pvector_clear(), rz_pvector_init(), rz_pvector_len(), rz_pvector_pop(), rz_pvector_push(), rz_snprintf(), rz_str_trim(), rz_subprocess_err(), rz_subprocess_free(), rz_subprocess_kill(), rz_subprocess_out(), rz_subprocess_ret(), rz_subprocess_start(), RZ_SUBPROCESS_TIMEDOUT, rz_subprocess_wait(), and snprintf.

Referenced by rz_test_run_test().

◆ rz_test_run_cmd_test()

RZ_API RzSubprocessOutput* rz_test_run_cmd_test ( RzTestRunConfig config,
RzCmdTest test,
RzTestCmdRunner  runner,
void *  user 
)

Definition at line 161 of file run.c.

161  {
162  RzList *extra_args = test->args.value ? rz_str_split_duplist(test->args.value, " ", true) : NULL;
163  RzList *files = test->file.value ? rz_str_split_duplist(test->file.value, "\n", true) : NULL;
164  RzListIter *it;
165  RzListIter *tmpit;
166  char *token;
167  rz_list_foreach_safe (extra_args, it, tmpit, token) {
168  if (!*token) {
169  rz_list_delete(extra_args, it);
170  }
171  }
172  rz_list_foreach_safe (files, it, tmpit, token) {
173  if (!*token) {
174  rz_list_delete(files, it);
175  }
176  }
177  if (rz_list_empty(files)) {
178  if (!files) {
179  files = rz_list_new();
180  } else {
181  files->free = NULL;
182  }
183  rz_list_push(files, "=");
184  }
185  ut64 timeout_ms = test->timeout.set ? test->timeout.value * 1000 : config->timeout_ms;
186  RzSubprocessOutput *out = run_rz_test(config, timeout_ms, test->cmds.value, files, extra_args, test->load_plugins, runner, user);
187  rz_list_free(extra_args);
189  return out;
190 }
static RzSubprocessOutput * run_rz_test(RzTestRunConfig *config, ut64 timeout_ms, const char *cmds, RzList *files, RzList *extra_args, bool load_plugins, RzTestCmdRunner runner, void *user)
Definition: run.c:113
checking print the parsed form of the magic use in n conjunction with m to debug a new magic file n before installing it n output MIME type special files
Definition: file_opts.h:46
RZ_API void rz_list_delete(RZ_NONNULL RzList *list, RZ_NONNULL RzListIter *iter)
Removes an entry in the list by using the RzListIter pointer.
Definition: list.c:162
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_push(RZ_NONNULL RzList *list, void *item)
Alias for rz_list_append.
Definition: list.c:60
RZ_API RzList * rz_str_split_duplist(const char *str, const char *c, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3464

References files, NULL, out, run_rz_test(), rz_list_delete(), rz_list_free(), rz_list_new(), rz_list_push(), rz_str_split_duplist(), and ut64().

Referenced by print_result_diff(), and rz_test_run_test().

◆ rz_test_run_fuzz_test()

RZ_API RzSubprocessOutput* rz_test_run_fuzz_test ( RzTestRunConfig config,
RzFuzzTest test,
RzTestCmdRunner  runner,
void *  user 
)

Definition at line 433 of file run.c.

433  {
434  const char *cmd = "aaa";
435  RzList *files = rz_list_new();
436  rz_list_push(files, test->file);
437 #if ASAN
438  if (rz_str_endswith(test->file, "/swift_read")) {
439  cmd = "?F";
440  }
441 #endif
442  RzSubprocessOutput *ret = run_rz_test(config, config->timeout_ms, cmd, files, NULL, false, runner, user);
444  return ret;
445 }
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
RZ_API bool rz_str_endswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string ends with a specifc sequence of characters (case sensitive)
Definition: str.c:3329

References cmd, files, NULL, run_rz_test(), rz_list_free(), rz_list_new(), rz_list_push(), and rz_str_endswith().

Referenced by print_result_diff(), and rz_test_run_test().

◆ rz_test_run_json_test()

RZ_API RzSubprocessOutput* rz_test_run_json_test ( RzTestRunConfig config,
RzJsonTest test,
RzTestCmdRunner  runner,
void *  user 
)

Definition at line 246 of file run.c.

246  {
247  RzList *files = rz_list_new();
248  rz_list_push(files, (void *)config->json_test_file);
249  RzSubprocessOutput *ret = run_rz_test(config, config->timeout_ms, test->cmd, files, NULL, test->load_plugins, runner, user);
251  return ret;
252 }

References files, NULL, run_rz_test(), rz_list_free(), rz_list_new(), and rz_list_push().

Referenced by rz_test_run_test().

◆ rz_test_run_test()

RZ_API RzTestResultInfo* rz_test_run_test ( RzTestRunConfig config,
RzTest test 
)

Definition at line 482 of file run.c.

482  {
484  if (!ret) {
485  return NULL;
486  }
487  ret->test = test;
488  bool success = false;
490  switch (test->type) {
491  case RZ_TEST_TYPE_CMD: {
492  RzCmdTest *cmd_test = test->cmd_test;
494  success = rz_test_check_cmd_test(out, cmd_test);
495  ret->proc_out = out;
496  ret->timeout = out && out->timeout;
497  ret->run_failed = !out;
498  break;
499  }
500  case RZ_TEST_TYPE_ASM: {
501  RzAsmTest *asm_test = test->asm_test;
503  success = rz_test_check_asm_test(out, asm_test);
504  ret->asm_out = out;
505  if (out) {
506  ret->timeout = out->as_timeout || out->disas_timeout || out->il_timeout;
507  }
508  ret->run_failed = !out;
509  break;
510  }
511  case RZ_TEST_TYPE_JSON: {
512  RzJsonTest *json_test = test->json_test;
514  success = rz_test_check_json_test(out, json_test);
515  ret->proc_out = out;
516  if (out) {
517  ret->timeout = out->timeout;
518  }
519  ret->run_failed = !out;
520  break;
521  }
522  case RZ_TEST_TYPE_FUZZ: {
523  RzFuzzTest *fuzz_test = test->fuzz_test;
525  success = rz_test_check_fuzz_test(out);
526  ret->proc_out = out;
527  if (out) {
528  ret->timeout = out->timeout;
529  }
530  ret->run_failed = !out;
531  }
532  }
534  bool broken = rz_test_broken(test);
535 #if ASAN
536 #if !RZ_ASSERT_STDOUT
537 #error RZ_ASSERT_STDOUT undefined or 0
538 #endif
540  if (!success && test->type == RZ_TEST_TYPE_CMD && strstr(test->path, "/dbg") && (!out->out || (!strstr((char *)out->out, "WARNING:") && !strstr((char *)out->out, "ERROR:") && !strstr((char *)out->out, "FATAL:"))) && (!out->err || (!strstr((char *)out->err, "Sanitizer") && !strstr((char *)out->err, "runtime error:")))) {
541  broken = true;
542  }
543 #endif
544  if (!success) {
546  } else {
548  }
549  return ret;
550 }
RZ_API bool rz_test_check_asm_test(RzAsmTestOutput *out, RzAsmTest *test)
Definition: run.c:389
RZ_API RzSubprocessOutput * rz_test_run_cmd_test(RzTestRunConfig *config, RzCmdTest *test, RzTestCmdRunner runner, void *user)
Definition: run.c:161
RZ_API bool rz_test_broken(RzTest *test)
Definition: run.c:468
RZ_API RzSubprocessOutput * rz_test_run_json_test(RzTestRunConfig *config, RzJsonTest *test, RzTestCmdRunner runner, void *user)
Definition: run.c:246
RZ_API RzAsmTestOutput * rz_test_run_asm_test(RzTestRunConfig *config, RzAsmTest *test)
Definition: run.c:267
RZ_API bool rz_test_check_json_test(RzSubprocessOutput *out, RzJsonTest *test)
Definition: run.c:254
static RzSubprocessOutput * subprocess_runner(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: run.c:27
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
RZ_API bool rz_test_check_fuzz_test(RzSubprocessOutput *out)
Definition: run.c:447
static uint64_t start_time
Definition: mytime.c:21
RZ_API ut64 rz_time_now_mono(void)
Returns the current time in microseconds, using the monotonic clock.
Definition: time.c:102
RzAsmTestOutput * asm_out
Definition: rz_test.h:176
RzSubprocessOutput * proc_out
Definition: rz_test.h:175

References rz_test_test_result_info_t::asm_out, NULL, out, rz_test_test_result_info_t::proc_out, rz_test_test_result_info_t::result, rz_test_test_result_info_t::run_failed, RZ_NEW0, rz_test_broken(), rz_test_check_asm_test(), rz_test_check_cmd_test(), rz_test_check_fuzz_test(), rz_test_check_json_test(), RZ_TEST_RESULT_BROKEN, RZ_TEST_RESULT_FAILED, RZ_TEST_RESULT_FIXED, RZ_TEST_RESULT_OK, rz_test_run_asm_test(), rz_test_run_cmd_test(), rz_test_run_fuzz_test(), rz_test_run_json_test(), RZ_TEST_TYPE_ASM, RZ_TEST_TYPE_CMD, RZ_TEST_TYPE_FUZZ, RZ_TEST_TYPE_JSON, rz_time_now_mono(), start_time, subprocess_runner(), rz_test_test_result_info_t::test, test_customized_mnem::test(), rz_test_test_result_info_t::time_elapsed, rz_test_test_result_info_t::timeout, and ut64().

Referenced by worker_th().

◆ rz_test_test_broken()

RZ_API bool rz_test_test_broken ( RzTest test)

◆ rz_test_test_database_free()

RZ_API void rz_test_test_database_free ( RzTestDatabase db)

Definition at line 577 of file load.c.

577  {
578  if (!db) {
579  return;
580  }
581  rz_pvector_clear(&db->tests);
583  free(db);
584 }
RZ_API void rz_str_constpool_fini(RzStrConstPool *pool)
Definition: str_constpool.c:15
RzStrConstPool strpool
Definition: rz_test.h:139

References free(), rz_pvector_clear(), rz_str_constpool_fini(), rz_test_test_database_t::strpool, and rz_test_test_database_t::tests.

Referenced by rz_test_main().

◆ rz_test_test_database_load()

RZ_API bool rz_test_test_database_load ( RzTestDatabase db,
const char *  path 
)

Definition at line 756 of file load.c.

756  {
757  return database_load(db, path, 4);
758 }
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
static bool database_load(RzTestDatabase *db, const char *path, int depth)
Definition: load.c:640

References database_load(), and path.

Referenced by rz_test_main().

◆ rz_test_test_database_load_fuzz()

RZ_API bool rz_test_test_database_load_fuzz ( RzTestDatabase db,
const char *  path 
)

Definition at line 782 of file load.c.

782  {
783  if (rz_file_is_directory(path)) {
784  RzList *dir = rz_sys_dir(path);
785  if (!dir) {
786  return false;
787  }
788  RzListIter *it;
789  const char *subname;
790  RzStrBuf subpath;
791  rz_strbuf_init(&subpath);
792  bool ret = true;
793  rz_list_foreach (dir, it, subname) {
794  if (*subname == '.') {
795  continue;
796  }
797  rz_strbuf_setf(&subpath, "%s%s%s", path, RZ_SYS_DIR, subname);
798  if (rz_file_is_directory(rz_strbuf_get(&subpath))) {
799  // only load 1 level deep
800  continue;
801  }
803  }
804  rz_strbuf_fini(&subpath);
805  rz_list_free(dir);
806  return ret;
807  }
808 
809  if (!rz_file_exists(path)) {
810  eprintf("Path \"%s\" does not exist\n", path);
811  return false;
812  }
813 
814  // Just a single file
816  return true;
817 }
static void database_load_fuzz_file(RzTestDatabase *db, const char *path, const char *file)
Definition: load.c:760
RZ_API bool rz_file_is_directory(const char *str)
Definition: file.c:167
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API void rz_strbuf_fini(RzStrBuf *sb)
Definition: strbuf.c:365
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
RZ_API RzList * rz_sys_dir(const char *path)
Definition: sys.c:216
#define RZ_SYS_DIR
Definition: rz_types.h:218

References database_load_fuzz_file(), eprintf, path, rz_file_exists(), rz_file_is_directory(), rz_list_free(), rz_strbuf_fini(), rz_strbuf_get(), rz_strbuf_init(), rz_strbuf_setf(), RZ_SYS_DIR, and rz_sys_dir().

Referenced by rz_test_main().

◆ rz_test_test_database_new()

RZ_API RzTestDatabase* rz_test_test_database_new ( void  )

Definition at line 567 of file load.c.

567  {
569  if (!db) {
570  return NULL;
571  }
574  return db;
575 }
RZ_API void rz_test_test_free(RzTest *test)
Definition: load.c:546
RZ_API bool rz_str_constpool_init(RzStrConstPool *pool)
Definition: str_constpool.c:10
#define RZ_NEW(x)
Definition: rz_types.h:285
void(* RzPVectorFree)(void *e)
Definition: rz_vector.h:43

References NULL, RZ_NEW, rz_pvector_init(), rz_str_constpool_init(), rz_test_test_free(), rz_test_test_database_t::strpool, and rz_test_test_database_t::tests.

Referenced by rz_test_main().

◆ rz_test_test_free()

RZ_API void rz_test_test_free ( RzTest test)

Definition at line 546 of file load.c.

546  {
547  if (!test) {
548  return;
549  }
550  switch (test->type) {
551  case RZ_TEST_TYPE_CMD:
552  rz_test_cmd_test_free(test->cmd_test);
553  break;
554  case RZ_TEST_TYPE_ASM:
555  rz_test_asm_test_free(test->asm_test);
556  break;
557  case RZ_TEST_TYPE_JSON:
558  rz_test_json_test_free(test->json_test);
559  break;
560  case RZ_TEST_TYPE_FUZZ:
561  rz_test_fuzz_test_free(test->fuzz_test);
562  break;
563  }
564  free(test);
565 }
RZ_API void rz_test_fuzz_test_free(RzFuzzTest *test)
Definition: load.c:538
RZ_API void rz_test_asm_test_free(RzAsmTest *test)
Definition: load.c:263

References free(), rz_test_asm_test_free(), rz_test_cmd_test_free(), rz_test_fuzz_test_free(), rz_test_json_test_free(), RZ_TEST_TYPE_ASM, RZ_TEST_TYPE_CMD, RZ_TEST_TYPE_FUZZ, and RZ_TEST_TYPE_JSON.

Referenced by rz_test_main(), and rz_test_test_database_new().

◆ rz_test_test_name()

RZ_API char* rz_test_test_name ( RzTest test)

Definition at line 451 of file run.c.

451  {
452  switch (test->type) {
453  case RZ_TEST_TYPE_CMD:
454  if (test->cmd_test->name.value) {
455  return strdup(test->cmd_test->name.value);
456  }
457  return strdup("<unnamed>");
458  case RZ_TEST_TYPE_ASM:
459  return rz_str_newf("<asm> %s", test->asm_test->disasm ? test->asm_test->disasm : "");
460  case RZ_TEST_TYPE_JSON:
461  return rz_str_newf("<json> %s", test->json_test->cmd ? test->json_test->cmd : "");
462  case RZ_TEST_TYPE_FUZZ:
463  return rz_str_newf("<fuzz> %s", test->fuzz_test->file);
464  }
465  return NULL;
466 }
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1

References NULL, rz_str_newf(), RZ_TEST_TYPE_ASM, RZ_TEST_TYPE_CMD, RZ_TEST_TYPE_FUZZ, RZ_TEST_TYPE_JSON, and strdup().

Referenced by print_new_results().

◆ rz_test_test_result_info_free()

RZ_API void rz_test_test_result_info_free ( RzTestResultInfo result)

Definition at line 552 of file run.c.

552  {
553  if (!result) {
554  return;
555  }
556  if (result->test) {
557  switch (result->test->type) {
558  case RZ_TEST_TYPE_CMD:
559  case RZ_TEST_TYPE_JSON:
560  case RZ_TEST_TYPE_FUZZ:
562  break;
563  case RZ_TEST_TYPE_ASM:
565  break;
566  }
567  }
568  free(result);
569 }
RZ_API void rz_test_asm_test_output_free(RzAsmTestOutput *out)
Definition: run.c:422
RZ_API void rz_subprocess_output_free(RzSubprocessOutput *out)
Definition: subprocess.c:1323
RzTestType type
Definition: rz_test.h:128

References rz_test_test_result_info_t::asm_out, free(), rz_test_test_result_info_t::proc_out, rz_subprocess_output_free(), rz_test_asm_test_output_free(), RZ_TEST_TYPE_ASM, RZ_TEST_TYPE_CMD, RZ_TEST_TYPE_FUZZ, RZ_TEST_TYPE_JSON, rz_test_test_result_info_t::test, and rz_test_test_t::type.

Referenced by rz_test_main().