Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Adds print statements to help debug s2n_dynamic_load_test #4836

Merged
merged 4 commits into from
Oct 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions codebuild/bin/s2n_dynamic_load_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,53 @@ static void *s2n_load_dynamic_lib(void *ctx)

void *s2n_so = dlopen(s2n_so_path, RTLD_NOW);
if (!s2n_so) {
printf("Error dynamically loading libs2n\n");
printf("%s\n", dlerror());
exit(1);
}

int (*s2n_init_dl)(void) = NULL;
*(void **) (&s2n_init_dl) = dlsym(s2n_so, "s2n_init");
if (dlerror()) {
printf("Error dynamically loading s2n_init\n");
exit(1);
}

int (*s2n_cleanup_dl)(void) = NULL;
*(void **) (&s2n_cleanup_dl) = dlsym(s2n_so, "s2n_cleanup");
if (dlerror()) {
printf("Error dynamically loading s2n_cleanup\n");
exit(1);
}

int (*s2n_errno_location_dl)(void) = NULL;
*(void **) (&s2n_errno_location_dl) = dlsym(s2n_so, "s2n_errno_location");
if (dlerror()) {
printf("Error dynamically loading s2n_errno_location\n");
exit(1);
}

const char *(*s2n_strerror_debug_dl)(int error, const char *lang) = NULL;
*(void **) (&s2n_strerror_debug_dl) = dlsym(s2n_so, "s2n_strerror_debug");
if (dlerror()) {
printf("Error dynamically loading s2n_strerror_debug\n");
exit(1);
}

if ((*s2n_init_dl)()) {
int s2n_errno = (*s2n_errno_location_dl)();
fprintf(stderr, "Error calling s2n_init: '%s'\n", (*s2n_strerror_debug_dl)(s2n_errno, "EN"));
exit(1);
}
if ((*s2n_cleanup_dl)()) {
int s2n_errno = (*s2n_errno_location_dl)();
fprintf(stderr, "Error calling s2n_cleanup: '%s'\n", (*s2n_strerror_debug_dl)(s2n_errno, "EN"));
exit(1);
}

if (dlclose(s2n_so)) {
printf("Error closing libs2n\n");
printf("%s\n", dlerror());
exit(1);
}

Expand All @@ -70,9 +94,11 @@ int main(int argc, char *argv[])
for (size_t i = 0; i <= PTHREAD_KEYS_MAX + 1; i++) {
pthread_t thread_id = { 0 };
if (pthread_create(&thread_id, NULL, &s2n_load_dynamic_lib, argv[1])) {
printf("Error creating thread at loop index: %li\n", i);
exit(1);
}
if (pthread_join(thread_id, NULL)) {
printf("Error joining thread at loop index: %li\n", i);
exit(1);
}
}
Expand Down
Loading