#!/bin/bash
set -xeuo pipefail

# Make sure ftrace is configured in the kernel. Skip this test otherwise.
if [[ "$(mount | awk '/tracefs/{print $5}')" != "tracefs" ]]; then
    echo "skipping test - tracefs not mounted"
    exit 77
fi

# Make sure we have permissions to read /sys/kernel/tracing.
if ! ls /sys/kernel/tracing; then
    echo "skipping test - cannot read /sys/kernel/tracing"
    exit 77
fi

# Build trace-utest using the libraries installed on the system instead of in-tree ones.
cc -o utest/trace-utest utest/trace-utest.c utest/tracecmd-utest.c $(pkg-config --cflags --libs libtracecmd) -lcunit

./utest/trace-utest
