2015-09-07 22:05:55 +03:00
|
|
|
#ifndef UNICORN_TEST_H
|
|
|
|
#define UNICORN_TEST_H
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
#include <cmocka.h>
|
|
|
|
#include <unicorn/unicorn.h>
|
2017-06-25 05:14:22 +03:00
|
|
|
#include <sys/stat.h>
|
2015-09-07 22:05:55 +03:00
|
|
|
|
2015-09-14 04:32:31 +03:00
|
|
|
/**
|
|
|
|
* Assert that err matches expect
|
|
|
|
*/
|
|
|
|
#define uc_assert_err(expect, err) \
|
|
|
|
do { \
|
|
|
|
uc_err __err = err; \
|
2015-09-21 14:56:02 +03:00
|
|
|
if (__err != expect) { \
|
2015-09-14 04:32:31 +03:00
|
|
|
fail_msg("%s", uc_strerror(__err)); \
|
|
|
|
} \
|
2015-09-07 23:07:48 +03:00
|
|
|
} while (0)
|
|
|
|
|
2015-09-14 04:32:31 +03:00
|
|
|
/**
|
|
|
|
* Assert that err is UC_ERR_OK
|
|
|
|
*/
|
|
|
|
#define uc_assert_success(err) uc_assert_err(UC_ERR_OK, err)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assert that err is anything but UC_ERR_OK
|
|
|
|
*
|
|
|
|
* Note: Better to use uc_assert_err(<specific error>, err),
|
|
|
|
* as this serves to document which errors a function will return
|
|
|
|
* in various scenarios.
|
|
|
|
*/
|
2015-09-21 14:56:02 +03:00
|
|
|
#define uc_assert_fail(err) \
|
|
|
|
do { \
|
|
|
|
uc_err __err = err; \
|
|
|
|
if (__err == UC_ERR_OK) { \
|
|
|
|
fail_msg("%s", uc_strerror(__err)); \
|
|
|
|
} \
|
|
|
|
} while (0)
|
2015-09-07 23:07:48 +03:00
|
|
|
|
2017-06-25 05:14:22 +03:00
|
|
|
char * read_file(const char *filename, struct stat *info) {
|
|
|
|
stat(filename, info);
|
|
|
|
char *code = malloc(info->st_size);
|
2020-05-18 14:57:44 +03:00
|
|
|
if (code == NULL) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-06-25 05:14:22 +03:00
|
|
|
FILE *fp = fopen(filename, "r");
|
2020-05-18 14:57:44 +03:00
|
|
|
if (fp == NULL) {
|
|
|
|
free(code);
|
|
|
|
return NULL;
|
|
|
|
}
|
2017-06-25 05:14:22 +03:00
|
|
|
fread(code, info->st_size, 1, fp);
|
|
|
|
return code;
|
|
|
|
}
|
2015-09-07 22:05:55 +03:00
|
|
|
|
|
|
|
#endif /* UNICORN_TEST_H */
|