Skip to content

Commit 39e4b3f

Browse files
committed
invs: add no permissions test app
1 parent 45a442a commit 39e4b3f

File tree

3 files changed

+114
-0
lines changed

3 files changed

+114
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Makefile for user application
2+
3+
# Specify this directory relative to the current application.
4+
TOCK_USERLAND_BASE_DIR = ../../../..
5+
6+
# Which files to compile.
7+
C_SRCS := $(wildcard *.c)
8+
9+
# Set the SHA256 hash for the credential checker on the `nrf52840dk-test-invs`
10+
# board. Also set the write_id to 0 meaning no storage permissions.
11+
ELF2TAB_ARGS += --sha256 --write_id 0
12+
13+
# Include userland master makefile. Contains rules and flags for actually
14+
# building the application.
15+
include $(TOCK_USERLAND_BASE_DIR)/AppMakefile.mk
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Isolated Nonvolatile Storage Test App With No Permissions
2+
=========================================================
3+
4+
This app tries to use the isolated nonvolatile storage capsule but is granted no
5+
storage access permissions (its `write_id` in the TBF header is 0). This
6+
verifies that the read and write calls return `ENOSUPPORT`.
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
#include <stdint.h>
2+
#include <stdio.h>
3+
#include <stdlib.h>
4+
5+
#include <libtock-sync/storage/isolated_nonvolatile_storage.h>
6+
7+
8+
static bool test_exists(void) {
9+
bool exists = libtock_isolated_nonvolatile_storage_exists();
10+
11+
if (exists) {
12+
return true;
13+
}
14+
return false;
15+
}
16+
17+
static bool test_size(void) {
18+
uint64_t num_bytes;
19+
returncode_t ret;
20+
21+
ret = libtocksync_isolated_nonvolatile_storage_get_number_bytes(&num_bytes);
22+
23+
if (ret == RETURNCODE_ENOSUPPORT) {
24+
return true;
25+
}
26+
return false;
27+
}
28+
29+
static bool test_read(void) {
30+
returncode_t ret;
31+
32+
uint8_t readbuf[512];
33+
34+
uint32_t offset = 0;
35+
uint32_t length = 10;
36+
37+
ret = libtocksync_isolated_nonvolatile_storage_read(offset, readbuf, length);
38+
if (ret == RETURNCODE_ENOSUPPORT) {
39+
return true;
40+
}
41+
return false;
42+
}
43+
44+
45+
static bool test_write(void) {
46+
returncode_t ret;
47+
48+
uint8_t writebuf[512] = {0x3f};
49+
50+
uint32_t offset = 0;
51+
uint32_t length = 10;
52+
53+
ret = libtocksync_isolated_nonvolatile_storage_write(offset, writebuf, length);
54+
if (ret == RETURNCODE_ENOSUPPORT) {
55+
return true;
56+
}
57+
return false;
58+
}
59+
60+
61+
int main(void) {
62+
printf("[TEST] Isolated Nonvolatile Storage - No Permissions\n");
63+
64+
printf("[INVS TEST] Exists: ");
65+
if (test_exists()) {
66+
printf("Success\n");
67+
} else {
68+
printf("Fail\n");
69+
}
70+
71+
printf("[INVS TEST] Size: ");
72+
if (test_size()) {
73+
printf("Success\n");
74+
} else {
75+
printf("Fail\n");
76+
}
77+
78+
printf("[INVS TEST] Read: ");
79+
if (test_read()) {
80+
printf("Success\n");
81+
} else {
82+
printf("Fail\n");
83+
}
84+
85+
printf("[INVS TEST] Write: ");
86+
if (test_write()) {
87+
printf("Success\n");
88+
} else {
89+
printf("Fail\n");
90+
}
91+
92+
return 0;
93+
}

0 commit comments

Comments
 (0)