Make dwarf unit tests portable

This commit is contained in:
pancake 2022-09-20 17:05:34 +02:00
parent 51b08ba7f0
commit 78c0d8bd8f
2 changed files with 10 additions and 11 deletions

View File

@ -417,6 +417,7 @@ typedef struct r_bin_ldr_plugin_t {
bool (*load)(RBin *bin);
} RBinLdrPlugin;
// R2_580 - deprecate this struct which looks dupe from RArchConfig
typedef struct r_bin_arch_options_t {
const char *arch;
int bits;

View File

@ -22,8 +22,7 @@ static bool test_parse_dwarf_types(void) {
RBinFileOptions opt = {0};
bool res = r_bin_open (bin, "bins/pe/vista-glass.exe", &opt);
// TODO fix, how to correctly promote binary info to the RAnal in unit tests?
free (anal->config->cpu);
anal->config->cpu = strdup ("x86");
anal->config->arch = strdup ("x86");
anal->config->bits = 32;
mu_assert ("pe/vista-glass.exe binary could not be opened", res);
mu_assert_notnull (anal->sdb_types, "Couldn't create new RAnal.sdb_types");
@ -84,15 +83,14 @@ static bool test_dwarf_function_parsing_cpp(void) {
RIO *io = r_io_new ();
mu_assert_notnull (io, "Couldn't create new RIO");
RAnal *anal = r_anal_new ();
anal->config->arch = strdup ("x86");
anal->config->bits = 64;
mu_assert_notnull (anal, "Couldn't create new RAnal");
r_io_bind (io, &bin->iob);
anal->binb.demangle = r_bin_demangle;
RBinFileOptions opt = {0};
bool res = r_bin_open (bin, "bins/elf/dwarf4_many_comp_units.elf", &opt);
// TODO fix, how to correctly promote binary info to the RAnal in unit tests?
anal->config->cpu = strdup ("x86");
anal->config->bits = 64;
mu_assert ("elf/dwarf4_many_comp_units.elf binary could not be opened", res);
mu_assert_notnull (anal->sdb_types, "Couldn't create new RAnal.sdb_types");
RBinDwarfDebugAbbrev *abbrevs = r_bin_dwarf_parse_abbrev (bin, MODE);
@ -140,15 +138,15 @@ static bool test_dwarf_function_parsing_go(void) {
RIO *io = r_io_new ();
mu_assert_notnull (io, "Couldn't create new RIO");
RAnal *anal = r_anal_new ();
// TODO fix, how to correctly promote binary info to the RAnal in unit tests?
anal->config->arch = strdup ("x86");
anal->config->bits = 64;
mu_assert_notnull (anal, "Couldn't create new RAnal");
r_io_bind (io, &bin->iob);
anal->binb.demangle = r_bin_demangle;
RBinFileOptions opt = {0};
bool res = r_bin_open (bin, "bins/elf/dwarf_go_tree", &opt);
// TODO fix, how to correctly promote binary info to the RAnal in unit tests?
anal->config->cpu = strdup ("x86");
anal->config->bits = 64;
mu_assert ("bins/elf/dwarf_go_tree", res);
mu_assert_notnull (anal->sdb_types, "Couldn't create new RAnal.sdb_types");
RBinDwarfDebugAbbrev *abbrevs = r_bin_dwarf_parse_abbrev (bin, MODE);
@ -194,6 +192,8 @@ static bool test_dwarf_function_parsing_rust(void) {
RIO *io = r_io_new ();
mu_assert_notnull (io, "Couldn't create new RIO");
RAnal *anal = r_anal_new ();
anal->config->arch = strdup ("x86");
anal->config->bits = 64;
mu_assert_notnull (anal, "Couldn't create new RAnal");
r_io_bind (io, &bin->iob);
anal->binb.demangle = r_bin_demangle;
@ -202,8 +202,6 @@ static bool test_dwarf_function_parsing_rust(void) {
bool res = r_bin_open (bin, "bins/elf/dwarf_rust_bubble", &opt);
// TODO fix, how to correctly promote binary info to the RAnal in unit tests?
free (anal->config->cpu);
anal->config->cpu = strdup ("x86");
anal->config->bits = 64;
mu_assert ("bins/elf/dwarf_rust_bubble", res);
mu_assert_notnull (anal->sdb_types, "Couldn't create new RAnal.sdb_types");
RBinDwarfDebugAbbrev *abbrevs = r_bin_dwarf_parse_abbrev (bin, MODE);
@ -249,8 +247,8 @@ static bool test_dwarf_function_parsing_rust(void) {
int all_tests(void) {
mu_run_test (test_parse_dwarf_types);
mu_run_test (test_dwarf_function_parsing_cpp);
mu_run_test (test_dwarf_function_parsing_go);
mu_run_test (test_dwarf_function_parsing_rust);
mu_run_test (test_dwarf_function_parsing_go);
return tests_passed != tests_run;
}