From 92841ca55e6c24f189a9e26d001a5164325fee80 Mon Sep 17 00:00:00 2001 From: sirknightj Date: Wed, 13 Aug 2025 01:10:27 -0700 Subject: [PATCH 1/3] Add sanitizer runs to the workflows --- .github/workflows/ci.yml | 1 - .github/workflows/multiple-instances-test.yml | 1 - .github/workflows/sanitizers.yml | 92 +++++++++++++++++++ 3 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/sanitizers.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1b26c4db5..32edd9a6c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,7 +12,6 @@ on: concurrency: group: ${{ github.workflow }} - cancel-in-progress: true jobs: load-matrix: diff --git a/.github/workflows/multiple-instances-test.yml b/.github/workflows/multiple-instances-test.yml index 8c5025aaf..d8f854023 100644 --- a/.github/workflows/multiple-instances-test.yml +++ b/.github/workflows/multiple-instances-test.yml @@ -12,7 +12,6 @@ on: concurrency: group: ${{ github.workflow }} - cancel-in-progress: true jobs: spawn-multiple-instances: diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml new file mode 100644 index 000000000..83f606616 --- /dev/null +++ b/.github/workflows/sanitizers.yml @@ -0,0 +1,92 @@ +name: Sanitizer Tests + +on: + push: + branches: + - develop + - master + pull_request: + branches: + - develop + - master + +concurrency: + group: ${{ github.workflow }} + +jobs: + sanitizer-tests: + strategy: + matrix: + sanitizer: [ADDRESS_SANITIZER, MEMORY_SANITIZER, THREAD_SANITIZER, UNDEFINED_BEHAVIOR_SANITIZER] + fail-fast: false + + env: + STREAM_NAME: producer-java-ubuntu-22-${{ matrix.sanitizer }}-ci + TEST_STREAMS_PREFIX: producer-java-ubuntu-22-${{ matrix.sanitizer }}-ci + + runs-on: ubuntu-22.04 + permissions: + id-token: write + contents: read + + steps: + - name: Checkout the repository + uses: actions/checkout@v4 + + - name: Set up JDK + uses: actions/setup-java@v4 + with: + java-version: 17 + distribution: 'adopt' + cache: maven + + - name: Build JNI with ${{ matrix.sanitizer }} + run: | + mkdir build + cd build + cmake .. -D${{ matrix.sanitizer }}=ON + make -j + + - name: Build with Maven + run: mvn clean compile assembly:single + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} + aws-region: ${{ secrets.AWS_REGION }} + + + - name: Create the stream (DemoAppMain) + working-directory: scripts + run: | + ./prepareStream.sh "$STREAM_NAME" + + shell: bash + + - name: Run DemoAppMain with ${{ matrix.sanitizer }} + run: | + JAR_FILE=$(find target -name '*jar-with-dependencies.jar' | head -n 1) + + if [ -z "$JAR_FILE" ]; then + echo "Error: JAR file not found!" + exit 1 + fi + + echo "Using JAR file: $JAR_FILE" + java -classpath "$JAR_FILE" \ + -Daws.accessKeyId=${AWS_ACCESS_KEY_ID} \ + -Daws.secretKey=${AWS_SECRET_ACCESS_KEY} \ + -Daws.sessionToken=${AWS_SESSION_TOKEN} \ + -Djava.library.path=${JNI_FOLDER} \ + -Dkvs-stream=$STREAM_NAME \ + -Dlog4j.configurationFile=.github/log4j2.xml \ + com.amazonaws.kinesisvideo.demoapp.DemoAppMain + + shell: bash + + - name: Run tests with ${{ matrix.sanitizer }} + env: + JNI_FOLDER: ${{ github.workspace }}/build + run: | + mvn clean test -DargLine="-Daws.accessKeyId=${AWS_ACCESS_KEY_ID} -Daws.secretKey=${AWS_SECRET_ACCESS_KEY} -Daws.sessionToken=${AWS_SESSION_TOKEN} -Djava.library.path=${JNI_FOLDER} -Dlog4j.configurationFile=.github/log4j2.xml" From b00efc2dc0e51e7934dfc8a3ca9f2f5ef73f6298 Mon Sep 17 00:00:00 2001 From: sirknightj Date: Thu, 30 Oct 2025 00:39:11 -0700 Subject: [PATCH 2/3] Add TSAN to the CI/CD --- .github/workflows/sanitizers.yml | 66 +++++++++++++++---- .../kinesisvideo/demoapp/DemoAppMain.java | 2 + 2 files changed, 55 insertions(+), 13 deletions(-) diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 83f606616..140b631b1 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -1,4 +1,4 @@ -name: Sanitizer Tests +name: Sanitizers on: push: @@ -14,17 +14,30 @@ concurrency: group: ${{ github.workflow }} jobs: - sanitizer-tests: + sanitizes: strategy: matrix: - sanitizer: [ADDRESS_SANITIZER, MEMORY_SANITIZER, THREAD_SANITIZER, UNDEFINED_BEHAVIOR_SANITIZER] + include: +# TODO: re-enable later. Not currently passing +# - sanitizer: ADDRESS_SANITIZER +# lib_name: libasan.so + - sanitizer: THREAD_SANITIZER + lib_name: libtsan.so +# - sanitizer: UNDEFINED_BEHAVIOR_SANITIZER +# lib_name: libubsan.so fail-fast: false env: + DEBIAN_FRONTEND: noninteractive STREAM_NAME: producer-java-ubuntu-22-${{ matrix.sanitizer }}-ci TEST_STREAMS_PREFIX: producer-java-ubuntu-22-${{ matrix.sanitizer }}-ci + JNI_FOLDER: ${{ github.workspace }}/build + + name: ${{ matrix.sanitizer }} + runs-on: ubuntu-latest + container: + image: public.ecr.aws/ubuntu/ubuntu:22.04 - runs-on: ubuntu-22.04 permissions: id-token: write contents: read @@ -33,6 +46,11 @@ jobs: - name: Checkout the repository uses: actions/checkout@v4 + - name: Setup cmake + uses: jwlawson/actions-setup-cmake@v2 + with: + cmake-version: '3.x' + - name: Set up JDK uses: actions/setup-java@v4 with: @@ -40,11 +58,29 @@ jobs: distribution: 'adopt' cache: maven + - name: Install dependencies + run: | + apt-get update + apt-get install -y git build-essential pkg-config clang maven jq unzip curl + clang --version + echo "CC=clang" >> $GITHUB_ENV + echo "CXX=clang++" >> $GITHUB_ENV + + - name: Install AWS CLI v2 + run: | + # https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html + curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip" + unzip awscliv2.zip + ./aws/install + - name: Build JNI with ${{ matrix.sanitizer }} run: | + # Note: GCC does not support memory sanitizer, using Clang instead + export CC=clang + export CXX=clang++ mkdir build cd build - cmake .. -D${{ matrix.sanitizer }}=ON + cmake .. -D${{ matrix.sanitizer }}=ON -DCMAKE_BUILD_TYPE=RelWithDebInfo make -j - name: Build with Maven @@ -56,7 +92,6 @@ jobs: role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} aws-region: ${{ secrets.AWS_REGION }} - - name: Create the stream (DemoAppMain) working-directory: scripts run: | @@ -68,25 +103,30 @@ jobs: run: | JAR_FILE=$(find target -name '*jar-with-dependencies.jar' | head -n 1) + # Dynamically find sanitizer library + SANITIZER_LIB=$(find /usr/lib/x86_64-linux-gnu /usr/lib/clang/*/lib/linux -name "${{ matrix.lib_name }}*" 2>/dev/null | head -n 1) + if [ -z "$JAR_FILE" ]; then echo "Error: JAR file not found!" exit 1 fi echo "Using JAR file: $JAR_FILE" + + if [ -n "$SANITIZER_LIB" ]; then + echo "Found sanitizer library: $SANITIZER_LIB" + export LD_PRELOAD="$SANITIZER_LIB" + else + echo "Warning: Sanitizer library not found for ${{ matrix.lib_name }}" + fi + java -classpath "$JAR_FILE" \ -Daws.accessKeyId=${AWS_ACCESS_KEY_ID} \ -Daws.secretKey=${AWS_SECRET_ACCESS_KEY} \ -Daws.sessionToken=${AWS_SESSION_TOKEN} \ -Djava.library.path=${JNI_FOLDER} \ - -Dkvs-stream=$STREAM_NAME \ + -Dkvs-stream=${STREAM_NAME} \ -Dlog4j.configurationFile=.github/log4j2.xml \ com.amazonaws.kinesisvideo.demoapp.DemoAppMain shell: bash - - - name: Run tests with ${{ matrix.sanitizer }} - env: - JNI_FOLDER: ${{ github.workspace }}/build - run: | - mvn clean test -DargLine="-Daws.accessKeyId=${AWS_ACCESS_KEY_ID} -Daws.secretKey=${AWS_SECRET_ACCESS_KEY} -Daws.sessionToken=${AWS_SESSION_TOKEN} -Djava.library.path=${JNI_FOLDER} -Dlog4j.configurationFile=.github/log4j2.xml" diff --git a/src/main/demo/com/amazonaws/kinesisvideo/demoapp/DemoAppMain.java b/src/main/demo/com/amazonaws/kinesisvideo/demoapp/DemoAppMain.java index c146223a6..d0d1c9aa3 100644 --- a/src/main/demo/com/amazonaws/kinesisvideo/demoapp/DemoAppMain.java +++ b/src/main/demo/com/amazonaws/kinesisvideo/demoapp/DemoAppMain.java @@ -94,6 +94,8 @@ public static void main(final String[] args) { } catch (final KinesisVideoException | InterruptedException e) { throw new RuntimeException(e); } + + System.exit(0); } /** From 7792d64c0d1fd201893dc1acc7ad1ca540fef2cd Mon Sep 17 00:00:00 2001 From: sirknightj Date: Thu, 30 Oct 2025 00:48:32 -0700 Subject: [PATCH 3/3] Disable TSAN, enable UBSAN --- .github/workflows/sanitizers.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sanitizers.yml b/.github/workflows/sanitizers.yml index 140b631b1..6e8903448 100644 --- a/.github/workflows/sanitizers.yml +++ b/.github/workflows/sanitizers.yml @@ -21,10 +21,10 @@ jobs: # TODO: re-enable later. Not currently passing # - sanitizer: ADDRESS_SANITIZER # lib_name: libasan.so - - sanitizer: THREAD_SANITIZER - lib_name: libtsan.so -# - sanitizer: UNDEFINED_BEHAVIOR_SANITIZER -# lib_name: libubsan.so +# - sanitizer: THREAD_SANITIZER +# lib_name: libtsan.so + - sanitizer: UNDEFINED_BEHAVIOR_SANITIZER + lib_name: libubsan.so fail-fast: false env: