From 40164e4a44036023e9f71ac7c88d7c67c28ca6c1 Mon Sep 17 00:00:00 2001 From: Jeremy Gunawan Date: Fri, 25 Oct 2024 15:54:12 -0700 Subject: [PATCH 1/5] Add job to run the sample and check for memory leak --- .github/workflows/ci.yml | 99 +++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 12 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4061ca5e73..7d75d88f1e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -45,7 +45,7 @@ jobs: cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE make - name: Run tests - run: | + run: | cd build ./tst/webrtc_client_test mac-os-build-gcc: @@ -71,7 +71,7 @@ jobs: cmake .. -DBUILD_TEST=TRUE -DCOMPILER_WARNINGS=TRUE make - name: Run tests - run: | + run: | cd build ./tst/webrtc_client_test mac-os-m1-build-clang: @@ -100,7 +100,7 @@ jobs: sh -c 'cmake .. -DBUILD_TEST=TRUE -DCMAKE_C_COMPILER=$(brew --prefix llvm@15)/bin/clang -DCMAKE_CXX_COMPILER=$(brew --prefix llvm@15)/bin/clang++' make - name: Run tests - run: | + run: | cd build ./tst/webrtc_client_test static-build-mac: @@ -124,7 +124,7 @@ jobs: cmake .. -DBUILD_STATIC_LIBS=TRUE -DBUILD_TEST=TRUE make - name: Run tests - run: | + run: | cd build ./tst/webrtc_client_test address-sanitizer: @@ -160,7 +160,7 @@ jobs: make ulimit -c unlimited -S - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test undefined-behavior-sanitizer: @@ -195,7 +195,7 @@ jobs: make ulimit -c unlimited -S - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test # memory-sanitizer: @@ -250,7 +250,7 @@ jobs: make ulimit -c unlimited -S - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test linux-gcc-4_4: @@ -288,7 +288,7 @@ jobs: make ulimit -c unlimited -S - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test static-build-linux: @@ -348,7 +348,7 @@ jobs: make ulimit -c unlimited -S - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test mbedtls-ubuntu-gcc-11: @@ -382,7 +382,7 @@ jobs: make ulimit -c unlimited -S - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test @@ -448,7 +448,7 @@ jobs: make ulimit -c unlimited -S - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test sample-check: @@ -530,7 +530,7 @@ jobs: cmake .. -DBUILD_TEST=TRUE make - name: Run tests - run: | + run: | cd build timeout --signal=SIGABRT 60m ./tst/webrtc_client_test windows-msvc-openssl: @@ -668,3 +668,78 @@ jobs: mkdir build && cd build cmake .. -DBUILD_OPENSSL=TRUE -DBUILD_OPENSSL_PLATFORM=linux-generic32 -DBUILD_LIBSRTP_HOST_PLATFORM=x86_64-unknown-linux-gnu -DBUILD_LIBSRTP_DESTINATION_PLATFORM=arm-unknown-linux-uclibcgnueabi make + + valgrind-check: + runs-on: ubuntu-latest + env: + AWS_KVS_LOG_LEVEL: 7 + permissions: + id-token: write + contents: read + steps: + - name: Clone repository + uses: actions/checkout@v3 + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v2 + with: + role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} + aws-region: ${{ secrets.AWS_REGION }} + - name: Install deps + run: | + sudo apt clean && sudo apt update + sudo sh -c 'echo 0 > /proc/sys/net/ipv6/conf/all/disable_ipv6' + sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu/ jammy main' + sudo add-apt-repository 'deb http://archive.ubuntu.com/ubuntu/ jammy universe' + sudo apt-get -q update + sudo apt-get -y install libcurl4-openssl-dev valgrind + - name: Build repository + run: | + mkdir build && cd build + cmake .. -DUSE_OPENSSL=OFF -DUSE_MBEDTLS=ON + make + ulimit -c unlimited -S + - name: Run tests + run: | + cd build + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-master.txt ./samples/kvsWebrtcClientMaster demo-channel-gh-actions & + PID_MASTER=$! + valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes --verbose --log-file=valgrind-viewer.txt ./samples/kvsWebrtcClientViewer demo-channel-gh-actions & + PID_VIEWER=$! + + # Wait for processes to run initially + sleep 30 # Wait 30s + + # Send SIGINT (2) to both processes + kill -2 $PID_VIEWER + sleep 30 + + kill -2 $PID_MASTER + + # Start a background task to enforce a timeout for graceful shutdown + ( + sleep 10 + kill -9 $PID_MASTER 2>/dev/null + kill -9 $PID_VIEWER 2>/dev/null + ) & + + wait $PID_MASTER + EXIT_STATUS_MASTER=$? + wait $PID_VIEWER + EXIT_STATUS_VIEWER=$? + + # Check exit statuses to determine if the interrupt was successful + if [ $EXIT_STATUS_MASTER -ne 0 ] || [ $EXIT_STATUS_VIEWER -ne 0 ]; then + echo "Process did not exit gracefully." + exit 1 + else + echo "Processes exited successfully." + fi + + # Check for memory leaks in Valgrind output files + if grep "All heap blocks were freed -- no leaks are possible" valgrind-master.txt && grep "All heap blocks were freed -- no leaks are possible" valgrind-viewer.txt; then + echo "No memory leaks detected." + else + echo "Memory leaks detected." + exit 1 + fi From de95a69d3b9f744a70540535055f3b7df67479b8 Mon Sep 17 00:00:00 2001 From: sirknightj Date: Fri, 25 Oct 2024 18:25:23 -0700 Subject: [PATCH 2/5] Simulate a memory leak --- samples/Common.c | 1 + 1 file changed, 1 insertion(+) diff --git a/samples/Common.c b/samples/Common.c index 35bc2c3b80..561b01d12f 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -781,6 +781,7 @@ STATUS lookForSslCert(PSampleConfiguration* ppSampleConfiguration) STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE roleType, BOOL trickleIce, BOOL useTurn, UINT32 logLevel, PSampleConfiguration* ppSampleConfiguration) { + PVOID test = MALLOC(10000); // Test memory leak STATUS retStatus = STATUS_SUCCESS; PCHAR pAccessKey, pSecretKey, pSessionToken; PSampleConfiguration pSampleConfiguration = NULL; From 03e6977c5bf8cae5b8b043a47f2ec001e8c9feef Mon Sep 17 00:00:00 2001 From: sirknightj Date: Fri, 25 Oct 2024 18:32:22 -0700 Subject: [PATCH 3/5] MEMALLOC instead of MALLOC --- samples/Common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/samples/Common.c b/samples/Common.c index 561b01d12f..6d0af837c5 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -781,7 +781,7 @@ STATUS lookForSslCert(PSampleConfiguration* ppSampleConfiguration) STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE roleType, BOOL trickleIce, BOOL useTurn, UINT32 logLevel, PSampleConfiguration* ppSampleConfiguration) { - PVOID test = MALLOC(10000); // Test memory leak + PVOID test = MEMALLOC(10000); // Test memory leak STATUS retStatus = STATUS_SUCCESS; PCHAR pAccessKey, pSecretKey, pSessionToken; PSampleConfiguration pSampleConfiguration = NULL; From 433a730131bcc01f27afa6310db713511b95b8f8 Mon Sep 17 00:00:00 2001 From: sirknightj Date: Fri, 25 Oct 2024 18:45:49 -0700 Subject: [PATCH 4/5] Remove simulated memory leak --- samples/Common.c | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/Common.c b/samples/Common.c index 6d0af837c5..35bc2c3b80 100644 --- a/samples/Common.c +++ b/samples/Common.c @@ -781,7 +781,6 @@ STATUS lookForSslCert(PSampleConfiguration* ppSampleConfiguration) STATUS createSampleConfiguration(PCHAR channelName, SIGNALING_CHANNEL_ROLE_TYPE roleType, BOOL trickleIce, BOOL useTurn, UINT32 logLevel, PSampleConfiguration* ppSampleConfiguration) { - PVOID test = MEMALLOC(10000); // Test memory leak STATUS retStatus = STATUS_SUCCESS; PCHAR pAccessKey, pSecretKey, pSessionToken; PSampleConfiguration pSampleConfiguration = NULL; From 6cd219849984575ca4c60a0d171bdeb3ec405b52 Mon Sep 17 00:00:00 2001 From: sirknightj Date: Thu, 31 Oct 2024 18:09:02 -0700 Subject: [PATCH 5/5] Print the exit statuses in case of failure --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 7d75d88f1e..b55c8228b2 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -731,6 +731,8 @@ jobs: # Check exit statuses to determine if the interrupt was successful if [ $EXIT_STATUS_MASTER -ne 0 ] || [ $EXIT_STATUS_VIEWER -ne 0 ]; then echo "Process did not exit gracefully." + echo "Master exit code: $EXIT_STATUS_MASTER" + echo "Viewer exit code: $EXIT_STATUS_VIEWER" exit 1 else echo "Processes exited successfully."