summaryrefslogtreecommitdiff
diff options
-rw-r--r--tests/lib/files.sh44
-rw-r--r--tests/lib/snaps/test-snapd-broadcom-asic-control/meta/snap.yaml9
-rw-r--r--tests/main/interfaces-broadcom-asic-control/task.yaml75
3 files changed, 128 insertions, 0 deletions
diff --git a/tests/lib/files.sh b/tests/lib/files.sh
index e795780066..4c935e828a 100644
--- a/tests/lib/files.sh
+++ b/tests/lib/files.sh
@@ -13,3 +13,47 @@ wait_for_file() {
done
return 1
}
+
+ensure_dir_exists() {
+ dir="$1"
+ if ! [ -d "$dir" ]; then
+ mkdir -p "$dir"
+ touch "$dir.fake"
+ fi
+}
+
+clean_dir() {
+ dir="$1"
+ if [ -f "$dir.fake" ]; then
+ rm -rf "$dir"
+ rm -f "$dir.fake"
+ fi
+}
+
+ensure_file_exists() {
+ file="$1"
+ if ! [ -f "$file" ]; then
+ touch "$file"
+ touch "$file.fake"
+ fi
+}
+
+ensure_file_exists_backup_real() {
+ file="$1"
+ if [ -f "$file" ]; then
+ mv "$file" "$file.back"
+ fi
+ touch "$file"
+ touch "$file.fake"
+}
+
+clean_file() {
+ file="$1"
+ if [ -f "$file.fake" ]; then
+ rm -f "$file"
+ rm -f "$file.fake"
+ fi
+ if [ -f "$file.back" ]; then
+ mv "$file.back" "$file"
+ fi
+}
diff --git a/tests/lib/snaps/test-snapd-broadcom-asic-control/meta/snap.yaml b/tests/lib/snaps/test-snapd-broadcom-asic-control/meta/snap.yaml
new file mode 100644
index 0000000000..c53fc06ea4
--- /dev/null
+++ b/tests/lib/snaps/test-snapd-broadcom-asic-control/meta/snap.yaml
@@ -0,0 +1,9 @@
+name: test-snapd-broadcom-asic-control
+version: 1.0
+summary: Basic broadcom-asic-control snap
+description: A basic snap which allow access to broadcom asic kernel module
+
+apps:
+ sh:
+ command: ../../../bin/sh
+ plugs: [broadcom-asic-control]
diff --git a/tests/main/interfaces-broadcom-asic-control/task.yaml b/tests/main/interfaces-broadcom-asic-control/task.yaml
new file mode 100644
index 0000000000..cc82b688d6
--- /dev/null
+++ b/tests/main/interfaces-broadcom-asic-control/task.yaml
@@ -0,0 +1,75 @@
+summary: Ensure that the broadcom-asic-control interface works.
+
+details: |
+ The broadcom-asic-control interface allow access to broadcom asic kernel module.
+
+prepare: |
+ . $TESTSLIB/snaps.sh
+ install_local test-snapd-broadcom-asic-control
+
+ . $TESTSLIB/files.sh
+ ensure_file_exists_backup_real /dev/linux-user-bde
+ ensure_file_exists_backup_real /dev/linux-kernel-bde
+ ensure_file_exists_backup_real /dev/linux-bcm-knet
+
+ ensure_file_exists /run/udev/data/+pci:0test
+
+restore: |
+ rm -f call.error
+
+ . $TESTSLIB/files.sh
+ clean_file /dev/linux-user-bde
+ clean_file /dev/linux-kernel-bde
+ clean_file /dev/linux-bcm-knet
+
+ clean_dir /sys/devices/pci00test/
+ clean_file "/run/udev/data/+pci:0test"
+
+execute: |
+ echo "When the interface is connected"
+ snap connect test-snapd-broadcom-asic-control:broadcom-asic-control
+
+ echo "Then the snap is able to read the system modules directories"
+ for module in "linux_bcm_knet" "linux_kernel_bde" "linux_user_bde"; do
+ if [ -d /sys/module/$module ]; then
+ test-snapd-broadcom-asic-control.sh -c "ls /sys/module/$module"
+ fi
+ done
+
+ echo "Then the snap is able to read/write the system modules devices"
+ for device in "linux-bcm-knet" "linux-kernel-bde" "linux-user-bde"; do
+ test-snapd-broadcom-asic-control.sh -c "cat /dev/$device"
+ test-snapd-broadcom-asic-control.sh -c "echo test >> /dev/$device"
+ done
+
+ echo "Then the snap is able to read pci devices info"
+ if [ -d "/sys/devices/pci0000:00/" ]; then
+ config="$(find /sys/devices/pci0000:00/ -name config | head -n1)"
+ vendor="$(find /sys/devices/pci0000:00/ -name vendor | head -n1)"
+ device="$(find /sys/devices/pci0000:00/ -name device | head -n1)"
+ subsystem_vendor="$(find /sys/devices/pci0000:00/ -name subsystem_vendor | head -n1)"
+ subsystem_device="$(find /sys/devices/pci0000:00/ -name subsystem_device | head -n1)"
+
+ for file in "$config" "$vendor" "$device" "$subsystem_vendor" "$subsystem_device"; do
+ if ! [ -z $file ]; then
+ test-snapd-broadcom-asic-control.sh -c "cat $file"
+ fi
+ done
+ fi
+
+ test-snapd-broadcom-asic-control.sh -c "ls /sys/bus/pci/devices/"
+ test-snapd-broadcom-asic-control.sh -c "cat /run/udev/data/+pci:0test"
+
+ if [ "$(snap debug confinement)" = partial ] ; then
+ exit 0
+ fi
+
+ echo "When the plug is disconnected"
+ snap disconnect test-snapd-broadcom-asic-control:broadcom-asic-control
+
+ echo "Then the snap is not able to read the device"
+ if test-snapd-broadcom-asic-control.sh -c "cat /dev/linux-bcm-knet" 2>${PWD}/call.error; then
+ echo "Expected permission error accessing to device"
+ exit 1
+ fi
+ MATCH "Permission denied" < call.error