Skip to content

Commit

Permalink
invs: add no permissions test app
Browse files Browse the repository at this point in the history
  • Loading branch information
bradjc committed Feb 25, 2025
1 parent ba6eb1f commit 201d42b
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Makefile for user application

# Specify this directory relative to the current application.
TOCK_USERLAND_BASE_DIR = ../../../..

# Which files to compile.
C_SRCS := $(wildcard *.c)

# Set the SHA256 hash for the credential checker on the `nrf52840dk-test-invs`
# board. Also set the write_id to 0 meaning no storage permissions.
ELF2TAB_ARGS += --sha256 --write_id 0

# Include userland master makefile. Contains rules and flags for actually
# building the application.
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Isolated Nonvolatile Storage Test App With No Permissions
=========================================================

This app tries to use the isolated nonvolatile storage capsule but is granted no
storage access permissions (its `write_id` in the TBF header is 0). This
verifies that the read and write calls return `ENOSUPPORT`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>

#include <libtock-sync/storage/isolated_nonvolatile_storage.h>


static bool test_exists(void) {
bool exists = libtock_isolated_nonvolatile_storage_exists();

if (exists) {
return true;
}
return false;
}

static bool test_size(void) {
uint64_t num_bytes;
returncode_t ret;

ret = libtocksync_isolated_nonvolatile_storage_get_number_bytes(&num_bytes);

if (ret == RETURNCODE_ENOSUPPORT) {
return true;
}
return false;
}

static bool test_read(void) {
returncode_t ret;

uint8_t readbuf[512];

uint32_t offset = 0;
uint32_t length = 10;

ret = libtocksync_isolated_nonvolatile_storage_read(offset, readbuf, length);
if (ret == RETURNCODE_ENOSUPPORT) {
return true;
}
return false;
}


static bool test_write(void) {
returncode_t ret;

uint8_t writebuf[512] = {0x3f};

uint32_t offset = 0;
uint32_t length = 10;

ret = libtocksync_isolated_nonvolatile_storage_write(offset, writebuf, length);
if (ret == RETURNCODE_ENOSUPPORT) {
return true;
}
return false;
}


int main(void) {
printf("[TEST] Isolated Nonvolatile Storage - No Permissions\n");

printf("[INVS TEST] Exists: ");
if (test_exists()) {
printf("Success\n");
} else {
printf("Fail\n");
}

printf("[INVS TEST] Size: ");
if (test_size()) {
printf("Success\n");
} else {
printf("Fail\n");
}

printf("[INVS TEST] Read: ");
if (test_read()) {
printf("Success\n");
} else {
printf("Fail\n");
}

printf("[INVS TEST] Write: ");
if (test_write()) {
printf("Success\n");
} else {
printf("Fail\n");
}

return 0;
}

0 comments on commit 201d42b

Please sign in to comment.