Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
Already on GitHub? Sign in to your account
tests: adding test to test physical memory observe interface #4171
Merged
zyga
merged 7 commits into
snapcore:master
from
sergiocazzolato:tests-interface-physical-memory-observe
Nov 22, 2017
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
3243428
Adding test to test physical memory observe interface
sergiocazzolato bba619d
Adding restore for the test
sergiocazzolato beea7ea
Removing ubuntu systems as they are configured with CONFIG_STRICT_DEV…
sergiocazzolato 75fd1db
Merge branch 'master' into tests-interface-physical-memory-observe
sergiocazzolato fba8ce7
Detecting dinamically if CONFIG_STRICT_DEVMEM option is set to y
sergiocazzolato 1f4a970
Change how /dev/mem is accessed
sergiocazzolato a49f39f
Change on how kernel configuration is detected
sergiocazzolato
Jump to file or symbol
Failed to load files and symbols.
| @@ -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-*] | ||
|
|
||
| + | ||
| +prepare: | | ||
| + echo "Given the physical-memory-observe snap is installed" | ||
| + snap try $TESTSLIB/snaps/test-snapd-physical-memory-observe | ||
sergiocazzolato
Contributor
|
||
| + | ||
| +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 | ||
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)