-
-
Notifications
You must be signed in to change notification settings - Fork 0
feat(test): Enhance NVS test DEMO #2
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
Conversation
👋 Hello JakubAndrysek, we appreciate your contribution to this project! 📘 Please review the project's Contributions Guide for key guidelines on code, documentation, testing, and more. 🖊️ Please also make sure you have read and signed the Contributor License Agreement for this project. Click to see more instructions ...
Review and merge process you can expect ...
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the simple counter demo with a full Preferences test covering all supported types, adds type validation, and updates the Python test to match the expanded output.
- Expanded
nvs.ino
to read, validate, print, and update all Preferences data types (including structs, floats, doubles, and strings). - Added a
validate_types()
helper to assert that each key’s stored type matches the expectedPT_*
enum. - Updated
test_nvs.py
to check the new, verbose “Values from Preferences” output for default and successive runs.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
tests/validation/nvs/test_nvs.py | Updated expected serial output lines to match the new preferences demo output |
tests/validation/nvs/nvs.ino | Refactored the NVS demo to exercise get/put for all types, validate types, and print full state |
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 counter value 1") | ||
dut.expect_exact("Current counter value: 1") | ||
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}") | ||
|
||
LOGGER.info("Expecting counter value 2") | ||
dut.expect_exact("Current counter value: 2") | ||
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}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] This exact-match string is very long and makes the test fragile. Consider using a regex or splitting the check into multiple smaller expect
calls so that a minor formatting change won’t break the entire test.
Copilot uses AI. Check for mistakes.
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 | ", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using %lld
for val_long
(which comes from getLong
, typically a 32-bit value) can lead to mismatched output. Either switch to %ld
for 32-bit long
values or consistently use 64-bit APIs/types (e.g., getLong64
) if you intend 64-bit storage.
Serial.printf("long: %lld | ulong: %lu | long64: %lld | ulong64: %llu | ", | |
Serial.printf("long: %ld | ulong: %lu | long64: %lld | ulong64: %llu | ", |
Copilot uses AI. Check for mistakes.
// Print the counter to Serial Monitor | ||
Serial.printf("Current counter value: %u\n", counter); | ||
// Strings | ||
String val_string = preferences.getString("str", "str0"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Using the Arduino String
class on constrained devices can fragment heap memory over time. For a stability-focused demo, consider using a fixed-size char
buffer and preferences.getString(key, buf, bufSize)
instead.
String val_string = preferences.getString("str", "str0"); | |
char val_string[20] = "str0"; // Fixed-size buffer for stability | |
preferences.getString("str", val_string, sizeof(val_string)); |
Copilot uses AI. Check for mistakes.
Test Results 76 files 76 suites 20m 30s ⏱️ For more details on these failures, see this check. Results for commit 834e85c. |
By completing this PR sufficiently, you help us to review this Pull Request quicker and also help improve the quality of Release Notes
Checklist
This entire section above can be deleted if all items are checked.
Description of Change
Please describe your proposed Pull Request and it's impact.
Tests scenarios
Please describe on what Hardware and Software combinations you have tested this Pull Request and how.
(eg. I have tested my Pull Request on Arduino-esp32 core v2.0.2 with ESP32 and ESP32-S2 Board with this scenario)
Related links
Please provide links to related issue, PRs etc.
(eg. Closes #number of issue)