diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ac43b3c84..9ff70958d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -57,6 +57,11 @@ jobs: - uses: arduino/setup-protoc@c65c819552d16ad3c9b72d9dfd5ba5237b9c906b # v3.0.0 with: repo-token: ${{ secrets.GITHUB_TOKEN }} + - name: Setup-perf-decode + if: ${{ matrix.os == 'ubuntu-latest' }} + run: | + chmod +x scripts/setup_perf_decoder.sh + sudo ./scripts/setup_perf_decoder.sh - name: Test (Windows) if: ${{ matrix.os == 'windows-latest'}} run: ./scripts/test.ps1 @@ -64,6 +69,9 @@ jobs: - name: Test (Unix) if: ${{ matrix.os != 'windows-latest'}} run: bash ./scripts/test.sh + - name: Test user_events + if: ${{ matrix.os == 'ubuntu-latest'}} + run: bash ./scripts/test_user_events.sh lint: strategy: matrix: diff --git a/opentelemetry-user-events-logs/src/lib.rs b/opentelemetry-user-events-logs/src/lib.rs index b0ee9136b..22e5dc8a0 100644 --- a/opentelemetry-user-events-logs/src/lib.rs +++ b/opentelemetry-user-events-logs/src/lib.rs @@ -106,7 +106,7 @@ mod tests { #[test] fn integration_test_basic() { // Run using the below command - // sudo -E ~/.cargo/bin/cargo test integration_test_basic -- --nocapture --ignored + // sudo ./scripts/setup_perf_decoder.sh && sudo -E ~/.cargo/bin/cargo test integration_test_basic -- --nocapture --ignored // Basic check if user_events are available check_user_events_available().expect("Kernel does not support user_events. Verify your distribution/kernel supports user_events: https://docs.kernel.org/trace/user_events.html."); @@ -135,7 +135,7 @@ mod tests { // Start perf recording in a separate thread and emit logs in parallel. let perf_thread = - std::thread::spawn(|| run_perf_and_decode(5, "user_events:myprovider_L2K1")); + std::thread::spawn(|| run_perf_and_decode(20, "user_events:myprovider_L2K1")); // Give a little time for perf to start recording std::thread::sleep(std::time::Duration::from_millis(1000)); @@ -180,6 +180,9 @@ mod tests { .as_array() .expect("Events for perf.data is not an array"); + // display the events for debugging + println!("Events: {:#?}", events); + // Find the specific event. Its named providername:eventname format. let event = events .iter() @@ -385,14 +388,15 @@ mod tests { // Run perf record for duration_secs seconds let perf_status = Command::new("sudo") .args([ - "timeout", - "-s", - "SIGINT", - &duration_secs.to_string(), "perf", "record", + "-o", + "/tmp/perf.data", "-e", event, + "--", + "sleep", + &duration_secs.to_string(), ]) .status()?; @@ -407,21 +411,10 @@ mod tests { } } - // Change permissions on perf.data (which is the default file perf records to) to allow reading - let chmod_status = Command::new("sudo") - .args(["chmod", "uog+r", "./perf.data"]) - .status()?; - - if !chmod_status.success() { - panic!("chmod failed with exit code: {:?}", chmod_status.code()); - } - // Decode the performance data and return it directly - // Note: This tool must be installed on the machine - // git clone https://github.com/microsoft/LinuxTracepoints && - // cd LinuxTracepoints && mkdir build && cd build && cmake .. && make && - // sudo cp bin/perf-decode /usr/local/bin && - let decode_output = Command::new("perf-decode").args(["./perf.data"]).output()?; + let decode_output = Command::new("sudo") + .args(["perf-decode", "/tmp/perf.data"]) + .output()?; if !decode_output.status.success() { panic!( diff --git a/scripts/setup_perf_decoder.sh b/scripts/setup_perf_decoder.sh new file mode 100644 index 000000000..fe36eeb70 --- /dev/null +++ b/scripts/setup_perf_decoder.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +set -e # Exit immediately if a command exits with a non-zero status +set -x # Print commands and their arguments as they are executed + +# Update package lists +sudo apt-get update + +# Install required dependencies +sudo apt-get install -y git build-essential cmake flex bison linux-tools-generic + +# Clone and build LinuxTracepoints +git clone https://github.com/microsoft/LinuxTracepoints +cd LinuxTracepoints +mkdir build && cd build +cmake .. && make + +# Install perf-decode +sudo cp bin/perf-decode /usr/local/bin + +# Cleanup +cd ../.. +rm -rf LinuxTracepoints + +# Verify installation +perf --version +test -x /usr/local/bin/perf-decode && echo "perf-decode is executable" +exit 0 diff --git a/scripts/test.sh b/scripts/test.sh index b35950945..0245f4184 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -7,3 +7,4 @@ cargo test --workspace --all-features --tests echo "Running doctests for all packages in workspace with --all-features" cargo test --workspace --all-features --doc + diff --git a/scripts/test_user_events.sh b/scripts/test_user_events.sh new file mode 100644 index 000000000..9bc1086b0 --- /dev/null +++ b/scripts/test_user_events.sh @@ -0,0 +1,4 @@ +set -eu + +echo "Running user_events tests" +sudo -E ~/.cargo/bin/cargo test --manifest-path=opentelemetry-user-events-logs/Cargo.toml -- --nocapture --ignored \ No newline at end of file