Skip to content

Commit

Permalink
Added script
Browse files Browse the repository at this point in the history
  • Loading branch information
maddeleine committed May 26, 2023
1 parent e1c7287 commit 9f7c718
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
10 changes: 8 additions & 2 deletions codebuild/bin/test_dynamic_load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# This script compiles s2n-tls as a shared library and compiles a test
# without linking to the library. This enables us to test behavior when
# s2n-tls is dynamically loaded.
set -e

WORK_DIR=$1

Expand All @@ -43,4 +42,11 @@ if echo "$LDD_OUTPUT" | grep -q libs2n; then
fi

# Run the test with the path to libs2n
./s2n_dynamic_load_test $WORK_DIR/s2n-install-shared/lib/libs2n.so
echo "Running s2n_dynamic_load_test"
./s2n_dynamic_load_test $WORK_DIR/s2n-install-shared/lib/libs2n.so
returncode=$?
if [ $returncode -ne 0 ]; then
echo "test failure: s2n_dynamic_load_test did not succeed"
exit 1
fi
echo "Passed s2n_dynamic_load_test"
22 changes: 11 additions & 11 deletions codebuild/spec/buildspec_omnibus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,17 @@ batch:
TESTS: sharedandstatic
# must use the libcrypto that's actually installed on the system
S2N_LIBCRYPTO: openssl-1.1.1
- identifier: s2nInstallSharedAndStatic

buildspec: codebuild/spec/buildspec_ubuntu.yml
env:
compute-type: BUILD_GENERAL1_SMALL
image: 024603541914.dkr.ecr.us-west-2.amazonaws.com/docker:ubuntu18codebuild
privileged-mode: true
variables:
TESTS: dynamicload
# must use the libcrypto that's actually installed on the system
S2N_LIBCRYPTO: openssl-1.1.1

- identifier: s2nDynamicLoad
buildspec: codebuild/spec/buildspec_ubuntu.yml
env:
compute-type: BUILD_GENERAL1_SMALL
image: 024603541914.dkr.ecr.us-west-2.amazonaws.com/docker:ubuntu18codebuild
privileged-mode: true
variables:
TESTS: dynamicload
# must use the libcrypto that's actually installed on the system
S2N_LIBCRYPTO: openssl-1.1.1

- buildspec: codebuild/spec/buildspec_ubuntu.yml
env:
Expand Down
18 changes: 13 additions & 5 deletions tests/unit/s2n_dynamic_load_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

static void * s2n_load_dynamic_lib(void *ctx)
{
void *s2n_so = dlopen("../../lib/libs2n.so", RTLD_NOW);
const char *s2n_so_path = ctx;

void *s2n_so = dlopen(s2n_so_path, RTLD_NOW);
if (!s2n_so) {
exit(1);
}
Expand Down Expand Up @@ -51,16 +53,22 @@ static void * s2n_load_dynamic_lib(void *ctx)
return NULL;
}

int main(int argc, char **argv)
int main(int argc, char *argv[])
{
/* We don't want this test to run with all the other unit tests, so we fail quietly
* if the shared library wasn't specified. */
if (argc != 2) {
return 0;
}

/* s2n-tls library can be dynamically loaded and cleaned up safely
*
* We can't use any s2n test macros because those would need to be linked from
* the s2n library, and we can't link to the library for this test.
* We can't use any s2n test macros because then the compiler gets
* confused about whether or not to link the s2n functions.
*/
{
pthread_t thread_id = { 0 };
if(pthread_create(&thread_id, NULL, &s2n_load_dynamic_lib, NULL)) {
if(pthread_create(&thread_id, NULL, &s2n_load_dynamic_lib, argv[1])) {
exit(1);
}
if(pthread_join(thread_id, NULL)) {
Expand Down

0 comments on commit 9f7c718

Please sign in to comment.