File tree 3 files changed +114
-0
lines changed
examples/tests/isolated_nonvolatile_storage/invs_no_permission
3 files changed +114
-0
lines changed Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 ` .
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments