Skip to content

feat(test): Enhance NVS test - PERSONAL #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions tests/validation/nvs/nvs.ino
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <Arduino.h>
#include <Preferences.h>


struct TestData {
uint8_t id;
uint16_t value;
Expand Down Expand Up @@ -78,16 +77,15 @@ void setup() {
}

Serial.printf("Values from Preferences: ");
Serial.printf("char: %c | uchar: %u | short: %d | ushort: %u | int: %ld | uint: %lu | ",
val_char, val_uchar, val_short, val_ushort, val_int, val_uint);
Serial.printf("long: %lld | ulong: %lu | long64: %lld | ulong64: %llu | ",
val_long, val_ulong, val_long64, val_ulong64);
Serial.printf("float: %.2f | double: %.2f | bool: %s | str: %s | strLen: %s | struct: {id:%u,val:%u}\n",
val_float, val_double, val_bool ? "true" : "false", val_string.c_str(), val_string_buf, test_data.id, test_data.value);

Serial.printf("char: %c | uchar: %u | short: %d | ushort: %u | int: %ld | uint: %lu | ", val_char, val_uchar, val_short, val_ushort, val_int, val_uint);
Serial.printf("long: %lld | ulong: %lu | long64: %lld | ulong64: %llu | ", val_long, val_ulong, val_long64, val_ulong64);
Serial.printf(
"float: %.2f | double: %.2f | bool: %s | str: %s | strLen: %s | struct: {id:%u,val:%u}\n", val_float, val_double, val_bool ? "true" : "false",
val_string.c_str(), val_string_buf, test_data.id, test_data.value
);

// Increment the values
val_char += 1; // Increment char A -> B
val_char += 1; // Increment char A -> B
val_uchar += 1;
val_short += 1;
val_ushort += 1;
Expand All @@ -99,7 +97,7 @@ void setup() {
val_ulong64 += 1;
val_float += 1.1f;
val_double += 1.1;
val_bool = !val_bool; // Toggle boolean value
val_bool = !val_bool; // Toggle boolean value

// Increment string values using function
incrementStringValues(val_string, val_string_buf, sizeof(val_string_buf));
Expand Down
18 changes: 15 additions & 3 deletions tests/validation/nvs/test_nvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,22 @@ def test_nvs(dut):
LOGGER = logging.getLogger(__name__)

LOGGER.info("Expecting default values from Preferences")
dut.expect_exact("Values from Preferences: char: A | uchar: 0 | short: 0 | ushort: 0 | int: 0 | uint: 0 | long: 0 | ulong: 0 | long64: 0 | ulong64: 0 | float: 0.00 | double: 0.00 | bool: false | str: str0 | strLen: strLen0 | struct: {id:1,val:100}")
dut.expect_exact(
"Values from Preferences: char: A | uchar: 0 | short: 0 | ushort: 0 | int: 0 | uint: 0 | long: 0 | ulong: 0 | "
"long64: 0 | ulong64: 0 | float: 0.00 | double: 0.00 | bool: false | str: str0 | strLen: strLen0 | "
"struct: {id:1,val:100}"
)

LOGGER.info("Expecting updated preferences for the first time")
dut.expect_exact("Values from Preferences: char: B | uchar: 1 | short: 1 | ushort: 1 | int: 1 | uint: 1 | long: 1 | ulong: 1 | long64: 1 | ulong64: 1 | float: 1.10 | double: 1.10 | bool: true | str: str1 | strLen: strLen1 | struct: {id:2,val:110}")
dut.expect_exact(
"Values from Preferences: char: B | uchar: 1 | short: 1 | ushort: 1 | int: 1 | uint: 1 | long: 1 | ulong: 1 | "
"long64: 1 | ulong64: 1 | float: 1.10 | double: 1.10 | bool: true | str: str1 | strLen: strLen1 | "
"struct: {id:2,val:110}"
)

LOGGER.info("Expecting updated preferences for the second time")
dut.expect_exact("Values from Preferences: char: C | uchar: 2 | short: 2 | ushort: 2 | int: 2 | uint: 2 | long: 2 | ulong: 2 | long64: 2 | ulong64: 2 | float: 2.20 | double: 2.20 | bool: false | str: str2 | strLen: strLen2 | struct: {id:3,val:120}")
dut.expect_exact(
"Values from Preferences: char: C | uchar: 2 | short: 2 | ushort: 2 | int: 2 | uint: 2 | long: 2 | ulong: 2 | "
"long64: 2 | ulong64: 2 | float: 2.20 | double: 2.20 | bool: false | str: str2 | strLen: strLen2 | "
"struct: {id:3,val:120}"
)
Loading