Skip to content

Commit

Permalink
Adds dynamic load test to nix
Browse files Browse the repository at this point in the history
  • Loading branch information
maddeleine committed Jun 1, 2023
1 parent 8cf3212 commit 288280b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
16 changes: 10 additions & 6 deletions codebuild/bin/test_dynamic_load.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,23 +19,27 @@

WORK_DIR=$1

source codebuild/bin/s2n_setup_env.sh
source codebuild/bin/jobs.sh
if [ ! -z "$NIX_STORE" ]; then
OPENSSL=$(which openssl)
LIBCRYPTO_ROOT=$(nix-store --query $OPENSSL)
else
source codebuild/bin/s2n_setup_env.sh
fi

S2N_BUILD_ARGS=(-H. -DCMAKE_PREFIX_PATH=$LIBCRYPTO_ROOT -DBUILD_TESTING=OFF)

# create installation dir with libs2n.so
if [ ! -d $WORK_DIR/s2n-install-shared ]; then
(set -x; cmake -B$WORK_DIR/s2n-build-shared -DCMAKE_INSTALL_PREFIX=$WORK_DIR/s2n-install-shared -DBUILD_SHARED_LIBS=ON ${S2N_BUILD_ARGS[@]})
(set -x; cmake --build $WORK_DIR/s2n-build-shared --target install -- -j $JOBS)
(set -x; cmake --build $WORK_DIR/s2n-build-shared --target install -- -j $(nproc))
fi

# Compile the dynamic load test without linking to libs2n.so
gcc -o s2n_dynamic_load_test codebuild/bin/s2n_dynamic_load_test.c -ldl -lpthread -L$WORK_DIR/s2n-install-shared/lib -ls2n
# Compile the test file
$CC -Wl,-rpath $LIBCRYPTO_ROOT -o s2n_dynamic_load_test codebuild/bin/s2n_dynamic_load_test.c -ldl -lpthread -L$WORK_DIR/s2n-install-shared/lib

LDD_OUTPUT=$(ldd s2n_dynamic_load_test)

# Confirm executable doesn't have libs2n linked
# Confirm executable doesn't have libs2n.so loaded
if echo "$LDD_OUTPUT" | grep -q libs2n; then
echo "test failure: libs2n should not appear in ldd output"
exit 1
Expand Down
6 changes: 3 additions & 3 deletions nix/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ In the context of s2n-tls, we're using it to ease the setup of development envir

- `sudo bash -c “mkdir /nix && chmod 755 /nix && chown -R $USERNAME /nix”`
- Run the single-user command from `https://nixos.org/download.html#nix-install-linux`
- Enable flakes: `mkdir ~/.config/nix; echo "experimental-features = nix-command flakes" > ~/.config/nix.conf`
- Enable flakes: `mkdir ~/.config/nix; echo "experimental-features = nix-command flakes" > ~/.config/nix/nix.conf`
- `cd s2n-tls`

#### What is this doing?
Expand Down Expand Up @@ -39,7 +39,7 @@ The first time this is run, it might take a while to build everything.
From inside the devShell after configuring and build finish, run `unit <test name>`, or with no test name for all of the tests.
For example, to run the stuffer_test use: `unit stuffer_test`, or `unit stuffer` to run all of tests with stuffer in the name.

The CI does this in one shot with: `nix develop --max-jobs auto --ignore-environnment --command bash -c "source ./nix/shell.sh; configure;build;unit" `.
The CI does this in one shot with: `nix develop --max-jobs auto --ignore-environment --command bash -c "source ./nix/shell.sh; configure;build;unit" `.

What is this doing?

Expand All @@ -66,7 +66,7 @@ In its simplest form, the `nix copy` command can be used to stash a specific pac

By using inputDerivation, we can create a meta-package that contains all the packages in our devShell.

As an exmample, this copy will stash the s2n-tls devShell:
As an example, this copy will stash the s2n-tls devShell:

```
nix copy --to 's3://my-nix-chache-bucket?region=us-west-2' .#devShell
Expand Down
4 changes: 4 additions & 0 deletions nix/shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,7 @@ function test_toolchain_counts {
echo -e "python nassl:\t $(pip freeze|grep -c 'nassl')"
}

function dynamic_load {
./codebuild/bin/test_dynamic_load.sh $(mktemp -d)
}

0 comments on commit 288280b

Please sign in to comment.