summaryrefslogtreecommitdiff
diff options
authorsergio-j-cazzolato <sergio.cazzolato@canonical.com>2018-02-14 01:04:48 -0300
committersergio-j-cazzolato <sergio.cazzolato@canonical.com>2018-02-14 01:04:48 -0300
commitfd43bda0857894b02ee265ce1166066c622a7bd2 (patch)
treebc5e2b18eb0719ea7ea0fc25c128d532323352bf
parent3e3b4c915589c14bcbca411ea44a77a34f78eb60 (diff)
Memory address and write data are fixed now
Also minor chages in gpiomem.c based on PR review.
-rw-r--r--tests/lib/snaps/test-snapd-gpio-memory-control/gpiomem.c56
-rw-r--r--tests/main/interfaces-gpio-memory-control/task.yaml15
2 files changed, 27 insertions, 44 deletions
diff --git a/tests/lib/snaps/test-snapd-gpio-memory-control/gpiomem.c b/tests/lib/snaps/test-snapd-gpio-memory-control/gpiomem.c
index a39733fb31..1a5bbe6406 100644
--- a/tests/lib/snaps/test-snapd-gpio-memory-control/gpiomem.c
+++ b/tests/lib/snaps/test-snapd-gpio-memory-control/gpiomem.c
@@ -1,14 +1,10 @@
-#include <ctype.h>
-#include <errno.h>
#include <fcntl.h>
-#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
-#include <termios.h>
#include <unistd.h>
#define MAP_SIZE 4096UL
@@ -18,49 +14,45 @@ int main(int argc, char** argv)
{
int fd;
void *map_base, *virt_addr;
- uint32_t read_result, writeval;
- off_t target;
+ uint32_t read_result, write_result;
- if (argc < 2) {
- printf("Usage: gpiomem ADDRESS [DATA]\n"
- "\tADDRESS : memory address to act upon\n"
- "\tDATA : data to be written\n\n");
- exit(1);
- }
- target = strtoul(argv[1], 0, 0);
+ uint32_t writeval = 't';
+ off_t address = 0x00000001;
+ int retval = -1;
- if ((fd = open("/dev/gpiomem", O_RDWR | O_SYNC)) == -1) {
- fprintf(stderr, "Error: File /dev/gpiomem could not be opened\n");
- exit(1);
+ /* Open character device */
+ if ((fd = open("/dev/gpiomem", O_RDWR)) == -1) {
+ perror("cannot open /dev/gpiomem");
+ goto close;
}
/* Map one page */
- map_base = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
+ map_base = mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, address & ~MAP_MASK);
if (map_base == MAP_FAILED) {
- fprintf(stderr, "Error: Page could not be mapped\n");
- exit(1);
+ perror("cannot map gpio memory");
+ goto unmap;
}
-
printf("Memory mapped at address %p.\n", map_base);
- virt_addr = map_base + (target & MAP_MASK);
+ /* Read memory map */
+ virt_addr = (char*)map_base + (address & MAP_MASK);
read_result = *((uint32_t*)virt_addr);
+ printf("Read value: %#010x\n", read_result);
- printf("Read value: 0x%ui\n", read_result);
+ /* Write memory map */
+ *((uint32_t*)virt_addr) = writeval;
+ write_result = *((uint32_t*)virt_addr);
+ printf("Written %#010x; readback %#010x\n", writeval, write_result);
- if (argc > 2) {
- writeval = strtoul(argv[2], 0, 0);
- *((uint32_t*)virt_addr) = writeval;
- read_result = *((uint32_t*)virt_addr);
-
- printf("Written 0x%ui; readback 0x%ui\n", writeval, read_result);
- }
+ retval = 0;
+unmap:
+ /* Unmap the page */
if (munmap(map_base, MAP_SIZE) == -1) {
- fprintf(stderr, "Error: Data could not be written\n");
- exit(1);
+ perror("cannot unmap gpio memory");
}
+close:
close(fd);
- return 0;
+ return retval;
}
diff --git a/tests/main/interfaces-gpio-memory-control/task.yaml b/tests/main/interfaces-gpio-memory-control/task.yaml
index adc7e4b964..94400c4f0b 100644
--- a/tests/main/interfaces-gpio-memory-control/task.yaml
+++ b/tests/main/interfaces-gpio-memory-control/task.yaml
@@ -29,17 +29,8 @@ execute: |
snap connect test-snapd-gpio-memory-control:gpio-memory-control
snap interfaces | MATCH "$CONNECTED_PATTERN"
- mem_address=$(cat /var/log/syslog | grep -m1 'gpiomem.*Registers at' | sed 's/^.*at //')
- if [ -n $mem_address ]; then
- echo "Memory address not registered"
- exit 1
- fi
-
- echo "Then the snap is able read the physical memory"
- test-snapd-gpio-memory-control.gpiomem $mem_address
-
- echo "Then the snap is able to write the physical memory"
- test-snapd-gpio-memory-control.gpiomem $mem_address test
+ echo "Then the snap is able read and write the physical memory"
+ test-snapd-gpio-memory-control.gpiomem
if [ "$(snap debug confinement)" = partial ] ; then
exit 0
@@ -50,7 +41,7 @@ execute: |
snap interfaces | MATCH "$DISCONNECTED_PATTERN"
echo "Then the snap is not able to access the gpio physical memory"
- if test-snapd-gpio-memory-control.gpiomem $mem_address 2>${PWD}/call.error; then
+ if test-snapd-gpio-memory-control.gpiomem 2>${PWD}/call.error; then
echo "Expected permission error reading the gpio physical memory with disconnected plug"
exit 1
fi