From 5139b6713f4412ada512485e91599cf8a228496c Mon Sep 17 00:00:00 2001
From: Simon McVittie <simon.mcvittie@collabora.co.uk>
Date: Mon, 26 Sep 2016 18:30:43 +0100
Subject: [PATCH] apparmor-pulseaudio: run as much as possible from cwd

Auto-discovering ${top directory}/resources instead of
/usr/share/chaiwala-tests/resources means we don't have to depend
on the legacy chaiwala-tests package.

We still need to hard-code /usr/lib/apertis-tests to load the
LD_PRELOAD hack that we use to simulate a compromised pulseaudio
process, but we can reduce the test/fix cycle for the rest by
running it directly from a git checkout.

Reviewed-by: Philip Withnall <philip.withnall@collabora.co.uk>
Signed-off-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
Differential Revision: https://phabricator.apertis.org/D4382
---
 apparmor/apparmor-pulseaudio.yaml   | 2 +-
 apparmor/pulseaudio/pulseaudio      | 5 ++---
 apparmor/pulseaudio/test-pulseaudio | 2 +-
 debian/control                      | 1 -
 4 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/apparmor/apparmor-pulseaudio.yaml b/apparmor/apparmor-pulseaudio.yaml
index 51bdc76..31b4afa 100644
--- a/apparmor/apparmor-pulseaudio.yaml
+++ b/apparmor/apparmor-pulseaudio.yaml
@@ -20,7 +20,7 @@ install:
 run:
   steps:
   - echo -n | sudo tee /var/log/audit/audit.log
-  - common/run-test-in-systemd --name run-test-pulseaudio --timeout 90 /usr/lib/apertis-tests/apparmor/pulseaudio/test-pulseaudio
+  - common/run-test-in-systemd --name run-test-pulseaudio --timeout 90 apparmor/pulseaudio/test-pulseaudio
   - sudo cat /var/log/audit/audit.log | aa_log_extract_tokens.pl PERMITTING REJECTING
 
 parse:
diff --git a/apparmor/pulseaudio/pulseaudio b/apparmor/pulseaudio/pulseaudio
index 956635d..01319f4 100755
--- a/apparmor/pulseaudio/pulseaudio
+++ b/apparmor/pulseaudio/pulseaudio
@@ -1,8 +1,7 @@
 #!/bin/bash
 # vim: set sts=4 sw=4 et tw=0 :
 
-# Default value. Can be overriden by setting it in the env.
-: ${RESOURCE_DIR:="/usr/share/chaiwala-tests/resources/media"}
+pkglibdir="$(cd "$(dirname "$0")/../.." && pwd)"
 
 if [[ ${#@} -eq 1 ]] && [[ $1 =~ (normal|malicious) ]]; then
     :
@@ -19,7 +18,7 @@ test_pulseaudio() {
     echo ">> 2"
     pactl set-sink-volume 0 0
     echo ">> 3"
-    paplay "${RESOURCE_DIR}/audio/generic.wav"
+    paplay "$pkglibdir/resources/media/audio/generic.wav"
     echo ">> 4"
     pactl set-sink-volume 0 50%
     echo ">> 5"
diff --git a/apparmor/pulseaudio/test-pulseaudio b/apparmor/pulseaudio/test-pulseaudio
index 0ea0ed9..c9a3f7d 100755
--- a/apparmor/pulseaudio/test-pulseaudio
+++ b/apparmor/pulseaudio/test-pulseaudio
@@ -1,7 +1,7 @@
 #!/bin/bash
 # vim: tw=0
 
-TEST_DIR="${TEST_DIR:-/usr/lib/apertis-tests/apparmor/pulseaudio}"
+TEST_DIR="$(cd "$(dirname "$0")" && pwd)"
 # We want to use the pre-existing session bus.
 export LAUNCH_DBUS="no"
 
diff --git a/debian/control b/debian/control
index 5a8b2e7..7461b2c 100644
--- a/debian/control
+++ b/debian/control
@@ -273,7 +273,6 @@ Depends:
  apparmor (>= 2.8.0-0ubuntu5co4),
  apparmor-profiles,
  chaiwala-apparmor-profiles,
- chaiwala-tests,
  pulseaudio-utils,
 Description: Functional tests for PulseAudio AppArmor profiles/abstractions
  This package tests Apertis AppArmor profiles for PulseAudio.
-- 
GitLab