-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
114 additions
and
0 deletions.
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
examples/tests/isolated_nonvolatile_storage/invs_no_permission/Makefile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
6 changes: 6 additions & 0 deletions
6
examples/tests/isolated_nonvolatile_storage/invs_no_permission/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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`. |
93 changes: 93 additions & 0 deletions
93
examples/tests/isolated_nonvolatile_storage/invs_no_permission/main.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |