tests: adding test to test physical memory observe interface #4171

Merged
merged 7 commits into from Nov 22, 2017
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+dd if=/dev/mem of=/dev/null bs=1024 count=1
@@ -0,0 +1,9 @@
+name: test-snapd-physical-memory-observe
+summary: Basic snap to read the physical memory
+description: A basic snap used to read the head of the physical memory
+version: 1.0
+
+apps:
+ head:
+ command: bin/head-mem
+ plugs: [physical-memory-observe]
@@ -0,0 +1,52 @@
+summary: Ensure that the physical memory observe interface works.
+
+details: |
+ The physical-memory-observe interface allows to read the physical memory.
+
+ The test-snapd-physical-memory-observe snap checks that /dev/mem can be read
+ and the interface can be connected and disconnected.
+
+# As the ubuntu kernels are configured with CONFIG_STRICT_DEVMEM=y, this interface is
+# validated just in the other supported systems.
+systems: [-ubuntu-*]
@zyga

zyga Nov 14, 2017

Contributor

I wonder if we could do runtime detection and still let this run on core systems. There it will depend on the kernel and AFAIK will let us validate this for the purpose for which it was added (memory-mapped GPIO toggling via /dev/mem)

@zyga

zyga Nov 16, 2017

Contributor

Can we run on all systems now that you added runtime detection?

+
+prepare: |
+ echo "Given the physical-memory-observe snap is installed"
+ snap try $TESTSLIB/snaps/test-snapd-physical-memory-observe
@stolowski

stolowski Nov 17, 2017

Contributor

Should we snap remove it in restore?

@sergiocazzolato

sergiocazzolato Nov 21, 2017

Contributor

it is being done automatically in the prepare. The reset script is called and it is deleting all the installed snaps and cleaning up the env.

+
+restore: |
+ rm -f call.error
+
+execute: |
+ config="/boot/config-$(uname -r)"
+ if ([ -f $config ] && MATCH "CONFIG_STRICT_DEVMEM=y" < $config) || ([ -f /proc/config.gz ] && zcat /proc/config.gz | MATCH "CONFIG_STRICT_DEVMEM=y"); then
+ echo "Kernel option CONFIG_STRICT_DEVMEM=y, it is not possible to write in /dev/mem, exiting..."
+ exit 0
+ fi
+
+ CONNECTED_PATTERN=":physical-memory-observe +test-snapd-physical-memory-observe"
+ DISCONNECTED_PATTERN="\- +test-snapd-physical-memory-observe:physical-memory-observe"
+
+ echo "The interface is not connected by default"
+ snap interfaces | MATCH "$DISCONNECTED_PATTERN"
+
+ echo "When the interface is connected"
+ snap connect test-snapd-physical-memory-observe:physical-memory-observe
+
+ echo "Then the snap is able access to the physical memory"
+ test-snapd-physical-memory-observe.head
+
+ if [ "$(snap debug confinement)" = partial ] ; then
+ exit 0
+ fi
+
+ echo "When the plug is disconnected"
+ snap disconnect test-snapd-physical-memory-observe:physical-memory-observe
+ snap interfaces | MATCH "$DISCONNECTED_PATTERN"
+
+ echo "Then the snap is not able to access the physical memory"
+ if test-snapd-physical-memory-observe.head 2>${PWD}/call.error; then
+ echo "Expected permission error accessing to physical memory with disconnected plug"
+ exit 1
+ fi
+ MATCH "Permission denied" < call.error