Skip to content

Commit

Permalink
Plug the test reources build into gradle scripts (#105)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbachorik authored Jun 4, 2024
1 parent 98032a2 commit 706b40b
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 8 deletions.
20 changes: 20 additions & 0 deletions ddprof-lib/gtest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ tasks.withType(StripSymbols).configureEach { task ->
}
}

def buildResourcesTask = tasks.register("buildResources", Exec) {
group = 'build'
description = "Build the resources for the Google Tests"

onlyIf {
hasGtest && !project.hasProperty('skip-native') && os().isLinux()
}

def targetDir = project(':ddprof-lib').file('build/test/resources/unresolved-functions')

commandLine "sh", "-c", "cd ${project(':ddprof-lib').projectDir}/src/test/resources/unresolved-functions && make TARGET_DIR=${targetDir}"

inputs.files project(':ddprof-lib').files('src/test/resources/unresolved-functions')
outputs.file "${targetDir}/main"
}

def gtestAll = tasks.register("gtest") {
onlyIf {
hasGtest && !project.hasProperty('skip-native')
Expand Down Expand Up @@ -156,6 +172,10 @@ tasks.whenTaskAdded { task ->
gtestLinkTask.dependsOn compileTask
}
gtestTask.get().dependsOn gtestExecuteTask.get()
if (os().isLinux()) {
// custom binaries for tests are built only on linux
gtestExecuteTask.get().dependsOn buildResourcesTask
}
gtestAll.get().dependsOn gtestExecuteTask.get()
}
}
Expand Down
2 changes: 1 addition & 1 deletion ddprof-lib/src/main/cpp/symbols_linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ bool ElfParser::loadSymbolsUsingDebugLink() {
}

void ElfParser::loadSymbolTable(const char* symbols, size_t total_size, size_t ent_size, const char* strings) {
fprintf(stdout, "===> Loading symbol table at %p, base=%p, size=%lu, entry_size=%lu\n", symbols, _base, total_size, ent_size);
for (const char* symbols_end = symbols + total_size; symbols < symbols_end; symbols += ent_size) {
ElfSymbol* sym = (ElfSymbol*)symbols;
if (sym->st_name != 0 && sym->st_value != 0) {
// sanity check the offsets not to exceed the file size
if (_length == 0 || (sym->st_name < _length && sym->st_value < _length)) {
// Skip special AArch64 mapping symbols: $x and $d
if (sym->st_size != 0 || sym->st_info != 0 || strings[sym->st_name] != '$') {
Expand Down
3 changes: 1 addition & 2 deletions ddprof-lib/src/test/cpp/elfparser_ut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@ TEST(Elf, readSymTable) {
if (getcwd(cwd, sizeof(cwd)) == nullptr) {
exit(1);
}
fprintf(stdout, "Current working directory: %s\n", cwd);
char path[PATH_MAX];
snprintf(path, sizeof(path) - 1, "%s/../src/test/resources/libj9jit.so", cwd);
snprintf(path, sizeof(path) - 1, "%s/../build/test/resources/unresolved-functions/main", cwd);
if (access(path, R_OK) != 0) {
fprintf(stdout, "Missing test resource %s. Skipping the test\n", path);
exit(0);
Expand Down
5 changes: 3 additions & 2 deletions ddprof-lib/src/test/resources/unresolved-functions/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
TARGET_DIR = ../build/test/resources/unresolved-functions
all:
gcc -c main.c -o main.o
gcc -o main main.o -T linker.ld
gcc -c main.c -o $(TARGET_DIR)/main.o
gcc -o $(TARGET_DIR)/main $(TARGET_DIR)/main.o -T linker.ld
36 changes: 33 additions & 3 deletions ddprof-lib/src/test/resources/unresolved-functions/linker.ld
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
PHDRS
{
headers PT_PHDR PHDRS ;
interp PT_INTERP ;
text PT_LOAD FILEHDR PHDRS ;
data PT_LOAD ;
}

SECTIONS
{
. = 0x10000;
.text : { *(.text) }
.text : {
*(.text)
} :text

. = 0x20000;
.data : { *(.data) }
.bss : { *(.bss) }
.data : {
*(.data)
} :data

.bss : {
*(.bss)
}

. = 0x30000;
unresolved_symbol = .;
. = 0xffffffffffffffff;
unresolved_function = .;

/* Add the .init_array section */
.init_array : {
__init_array_start = .;
KEEP(*(.init_array))
__init_array_end = .;
}

/* Add the .fini_array section */
.fini_array : {
__fini_array_start = .;
KEEP(*(.fini_array))
__fini_array_end = .;
}
}

0 comments on commit 706b40b

Please sign in to comment.