Skip to content

Commit

Permalink
Revert "[tools][bfd] Add non-dynamic versions of symtab_upper_bounds …
Browse files Browse the repository at this point in the history
…& canonicalize"

This reverts commit 326c5a5.
  • Loading branch information
thoni56 committed Jun 28, 2022
1 parent 41b9077 commit d77d9d8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 71 deletions.
8 changes: 0 additions & 8 deletions tools/bfd_adapter.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ long bfd_adapter_get_dynamic_symtab_upper_bound(bfd *abfd) {
return bfd_get_dynamic_symtab_upper_bound(abfd);
}

long bfd_adapter_get_symtab_upper_bound(bfd *abfd) {
return bfd_get_symtab_upper_bound(abfd);
}

flagword bfd_adapter_get_file_flags(const bfd *abfd){
return bfd_get_file_flags(abfd);
}
Expand All @@ -35,10 +31,6 @@ long bfd_adapter_canonicalize_dynamic_symtab(bfd *abfd, asymbol **symbols) {
return bfd_canonicalize_dynamic_symtab(abfd, symbols);
}

long bfd_adapter_canonicalize_symtab(bfd *abfd, asymbol **symbols) {
return bfd_canonicalize_symtab(abfd, symbols);
}

bfd_boolean bfd_adapter_check_format(bfd *abfd, bfd_format format) {
return bfd_check_format(abfd, format);
}
Expand Down
4 changes: 0 additions & 4 deletions tools/bfd_adapter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,10 @@
#ifdef UNITTESTING
#define bfd_adapter_openr bfd_adapter_openr_unittesting
#define bfd_adapter_close bfd_adapter_close_unittesting
#define bfd_adapter_get_symtab_upper_bound bfd_adapter_get_symtab_upper_bound_unittesting
#define bfd_adapter_get_dynamic_symtab_upper_bound bfd_adapter_get_dynamic_symtab_upper_bound_unittesting
#define bfd_adapter_get_file_flags bfd_adapter_get_file_flags_unittesting
#define bfd_adapter_asymbol_bfd bfd_adapter_asymbol_bfd_unittesting
#define bfd_adapter_is_target_special_symbol bfd_adapter_is_target_special_symbol_unittesting
#define bfd_adapter_canonicalize_symtab bfd_adapter_canonicalize_symtab_unittesting
#define bfd_adapter_canonicalize_dynamic_symtab bfd_adapter_canonicalize_dynamic_symtab_unittesting
#define bfd_adapter_check_format bfd_adapter_check_format_unittesting
#define bfd_adapter_alloc bfd_adapter_alloc_unittesting
Expand All @@ -24,13 +22,11 @@
bfd *bfd_adapter_openr(const char *filename, const char *target);
bfd_boolean bfd_adapter_close(bfd *abfd);

long bfd_adapter_get_symtab_upper_bound(bfd *abfd);
long bfd_adapter_get_dynamic_symtab_upper_bound(bfd *abfd);
flagword bfd_adapter_get_file_flags(const bfd *abfd);

struct bfd *bfd_adapter_asymbol_bfd(const asymbol *sy);
bfd_boolean bfd_adapter_is_target_special_symbol(bfd *abfd, asymbol *symbols);
long bfd_adapter_canonicalize_symtab(bfd *abfd, asymbol **symbols);
long bfd_adapter_canonicalize_dynamic_symtab(bfd *abfd, asymbol **symbols);

bfd_boolean bfd_adapter_check_format(bfd *abfd, bfd_format format);
Expand Down
8 changes: 0 additions & 8 deletions tools/bfd_adapter.mocks
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ long bfd_adapter_get_dynamic_symtab_upper_bound(bfd *abfd) {
return (long) mock(abfd);
}

long bfd_adapter_get_symtab_upper_bound(bfd *abfd) {
return (long) mock(abfd);
}

flagword bfd_adapter_get_file_flags(const bfd *abfd){
return (flagword) mock(abfd);
}
Expand All @@ -33,10 +29,6 @@ long bfd_adapter_canonicalize_dynamic_symtab(bfd *abfd, asymbol **symbols) {
return (long) mock(abfd, symbols);
}

long bfd_adapter_canonicalize_symtab(bfd *abfd, asymbol **symbols) {
return (long) mock(abfd, symbols);
}

bfd_boolean bfd_adapter_check_format(bfd *abfd, bfd_format format) {
return (bfd_boolean) mock(abfd, format);
}
Expand Down
26 changes: 12 additions & 14 deletions tools/discoverer.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,21 @@ static void add_all_tests_from(asymbol **symbols, long symbol_count, CgreenVecto
}
}

/* Read in the symbols. */
/* Read in the dynamic symbols. */

static asymbol **get_symbols_table(bfd *abfd, long *symbol_count, bool verbose, const char *filename)
{
bool dynamic = (bfd_adapter_get_file_flags(abfd) & DYNAMIC) != 0;
long storage;
if ((bfd_adapter_get_file_flags(abfd) & DYNAMIC) == 0){
printf("%s: can only handle libraries with dynamic symbol tables for now\n");
*symbol_count = 0;
return NULL;
}

if (dynamic)
storage = bfd_adapter_get_dynamic_symtab_upper_bound(abfd);
else
storage = bfd_adapter_get_symtab_upper_bound(abfd);
long storage = bfd_adapter_get_dynamic_symtab_upper_bound(abfd);
if (storage <= 0) {
if (verbose) {
if (storage < 0)
printf("%s: bfd_get_symtab_upper_bounds returned %ld\n", filename, storage);
printf("%s: bfd_get_dynamic_symtab_upper_bounds returned %ld\n", filename, storage);
else
printf("%s: no symbols\n", filename);
}
Expand All @@ -71,18 +72,15 @@ static asymbol **get_symbols_table(bfd *abfd, long *symbol_count, bool verbose,
return NULL;
}

if (dynamic)
*symbol_count = bfd_adapter_canonicalize_dynamic_symtab(abfd, symbols);
else
*symbol_count = bfd_adapter_canonicalize_symtab(abfd, symbols);
*symbol_count = bfd_adapter_canonicalize_dynamic_symtab(abfd, symbols);
if (*symbol_count < 0) {
if (verbose)
printf("%s: failed to get symbols count\n", filename);
*symbol_count = 0;
return NULL;
}

return symbols;
return symbols;
}

CgreenVector *discover_tests_in(const char *filename, bool verbose) {
Expand All @@ -96,7 +94,7 @@ CgreenVector *discover_tests_in(const char *filename, bool verbose) {
bfd_adapter_check_format(abfd, bfd_object);
if ((bfd_adapter_get_file_flags(abfd) & HAS_SYMS) == 0) {
if (verbose)
printf("%s: file flags indicate no symbols\n", filename);
printf("%s: incorrect format\n", filename);
bfd_adapter_close(abfd);
return NULL;
}
Expand Down
46 changes: 9 additions & 37 deletions tools/tests/discoverer_unit_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ static void expect_open_file(const char *filename, void *result) {
will_return(result));
}

static void given_a_dynamic_file_with_symbols(const char *filename, bfd *expect_abfd) {
static void given_a_file_with_dynamic_symbols(const char *filename, bfd *expect_abfd) {
expect_open_file(filename, expect_abfd);
expect(bfd_adapter_check_format,
when(abfd, is_equal_to(expect_abfd)),
Expand All @@ -42,16 +42,6 @@ static void given_a_dynamic_file_with_symbols(const char *filename, bfd *expect_
will_return(HAS_SYMS|DYNAMIC));
}

static void given_a_non_dynamic_file_with_symbols(const char *filename, bfd *expect_abfd) {
expect_open_file(filename, expect_abfd);
expect(bfd_adapter_check_format,
when(abfd, is_equal_to(expect_abfd)),
when(format, is_equal_to(bfd_object)));
always_expect(bfd_adapter_get_file_flags,
when(abfd, is_equal_to(expect_abfd)),
will_return(HAS_SYMS));
}

static void given_a_file_with_two_lines(const char *filename, const char *line1, const char *line2) {
static bfd *expect_abfd = (bfd *) 1;
static long expect_storage = 1;
Expand All @@ -61,7 +51,7 @@ static void given_a_file_with_two_lines(const char *filename, const char *line1,
static asymbol *symbols_ptr[2] = { &symbols[0], &symbols[1] };
static asymbol **expect_symbols = (asymbol **) &symbols_ptr;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand Down Expand Up @@ -100,7 +90,7 @@ static void given_a_file_with_one_line(const char *filename, const char *line) {
static asymbol *symbols_ptr = symbols;
static asymbol **expect_symbols = (asymbol **) &symbols_ptr;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand Down Expand Up @@ -162,7 +152,7 @@ Ensure(Discoverer, should_find_no_tests_if_file_has_no_dynamic_symbol) {
const char *filename = "no-dynamic-symbol";
bfd *expect_abfd = (bfd *)1;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand All @@ -176,31 +166,13 @@ Ensure(Discoverer, should_find_no_tests_if_file_has_no_dynamic_symbol) {
assert_that(cgreen_vector_size(tests), is_equal_to(0));
}

Ensure(Discoverer, should_find_no_tests_if_non_dynamic_file_has_no_symbol) {
const char *filename = "no-dynamic-symbol";
bfd *expect_abfd = (bfd *)1;

given_a_non_dynamic_file_with_symbols(filename, expect_abfd);

expect(bfd_adapter_get_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
will_return(-1));
expect(printf_unittesting);
expect(bfd_adapter_close,
when(abfd, is_equal_to(expect_abfd)));

CgreenVector *tests = discover_tests_in(filename, verbose);

assert_that(cgreen_vector_size(tests), is_equal_to(0));
}

/*======================================================================*/
Ensure(Discoverer, should_find_no_tests_if_bdf_alloc_fail) {
const char *filename = "valid-file";
bfd *expect_abfd = (bfd *)1;
long expect_storage = 1;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand All @@ -225,7 +197,7 @@ Ensure(Discoverer, should_find_no_tests_if_bfd_canonicalize_dynamic_symtab_fails
long expect_storage = 1;
asymbol **expect_symbols = (asymbol **) 2;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand Down Expand Up @@ -254,7 +226,7 @@ Ensure(Discoverer, should_find_no_tests_if_get_symbols_table_return_zero_symbol)
long expect_storage = 1;
asymbol **expect_symbols = (asymbol **) 2;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand Down Expand Up @@ -285,7 +257,7 @@ Ensure(Discoverer, should_find_no_tests_if_bfd_asymbol_bfd_fails) {
asymbol *symbols_ptr = symbols;
asymbol **expect_symbols = (asymbol **) &symbols_ptr;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand Down Expand Up @@ -319,7 +291,7 @@ Ensure(Discoverer, should_find_no_tests_if_bfd_is_target_special_symbol_returns_
asymbol *symbols_ptr = symbols;
asymbol **expect_symbols = (asymbol **) &symbols_ptr;

given_a_dynamic_file_with_symbols(filename, expect_abfd);
given_a_file_with_dynamic_symbols(filename, expect_abfd);

expect(bfd_adapter_get_dynamic_symtab_upper_bound,
when(abfd, is_equal_to(expect_abfd)),
Expand Down

0 comments on commit d77d9d8

Please sign in to comment.