Skip to content

Commit

Permalink
test: test pass on esp32s3
Browse files Browse the repository at this point in the history
  • Loading branch information
leeebo committed Jun 20, 2023
1 parent 640851e commit ff2dcc8
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 11 deletions.
3 changes: 2 additions & 1 deletion tests/main/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
idf_component_register(SRCS "../unittest.c"
INCLUDE_DIRS "../")
INCLUDE_DIRS "../")
spiffs_create_partition_image(storage ../spiffs_image FLASH_IN_PROJECT)
6 changes: 6 additions & 0 deletions tests/partitions.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Name, Type, SubType, Offset, Size, Flags
# Note: if you have increased the bootloader size, make sure to update the offsets to avoid overlap
nvs, data, nvs, 0x9000, 0x6000,
phy_init, data, phy, 0xf000, 0x1000,
factory, app, factory, 0x10000, 1M,
storage, data, spiffs, , 100K,
3 changes: 3 additions & 0 deletions tests/sdkconfig.defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_PARTITION_TABLE_CUSTOM=y
CONFIG_PARTITION_TABLE_CUSTOM_FILENAME="partitions.csv"
CONFIG_PARTITION_TABLE_FILENAME="partitions.csv"
1 change: 1 addition & 0 deletions tests/spiffs_image/bad_comment.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an error
1 change: 1 addition & 0 deletions tests/spiffs_image/bad_multi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
indented
5 changes: 5 additions & 0 deletions tests/spiffs_image/bad_section.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[section1]
name1=value1
[section2
[section3 ; comment ]
name2=value2
3 changes: 3 additions & 0 deletions tests/spiffs_image/bom.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[bom_section]
bom_name=bom_value
key“ = value“
6 changes: 6 additions & 0 deletions tests/spiffs_image/duplicate_sections.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[section1]
single1 = abc
single2 = xyz
[section1]
single1 = def
single2 = qrs
17 changes: 17 additions & 0 deletions tests/spiffs_image/multi_line.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[section1]
single1 = abc
multi = this is a
multi-line value
single2 = xyz
[section2]
multi = a
b
c
[section3]
single: ghi
multi: the quick
brown fox
name = bob smith ; comment line 1
; comment line 2
foo = bar ;c1
Hi World ;c2
9 changes: 9 additions & 0 deletions tests/spiffs_image/no_value.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[section_list]
section0
section1

[section0]
key0=val0

[section1]
key1=val1
31 changes: 31 additions & 0 deletions tests/spiffs_image/normal.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
; This is an INI file
[section1] ; section comment
one=This is a test ; name=value comment
two = 1234
; x=y

[ section 2 ]
happy = 4
sad =

[empty]
; do nothing

[comment_test]
test1 = 1;2;3 ; only this will be a comment
test2 = 2;3;4;this won't be a comment, needs whitespace before ';'
test;3 = 345 ; key should be "test;3"
test4 = 4#5#6 ; '#' only starts a comment at start of line
#test5 = 567 ; entire line commented
# test6 = 678 ; entire line commented, except in MULTILINE mode
test7 = ; blank value, except if inline comments disabled
test8 =; not a comment, needs whitespace before ';'

[colon_tests]
Content-Type: text/html
foo:bar
adams : 42
funny1 : with = equals
funny2 = with : colons
funny3 = two = equals
funny4 : two : colons
4 changes: 4 additions & 0 deletions tests/spiffs_image/user_error.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[section]
a = b
user = parse_error
c = d
62 changes: 52 additions & 10 deletions tests/unittest.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,63 @@ void parse(const char* fname) {
}

#ifdef CONFIG_IDF_TARGET
#include "esp_err.h"
#include "esp_log.h"
#include "esp_spiffs.h"
#define BASE_PATH "/spiffs"
#define TAG "inih"

void spiffs_init(void) {
esp_vfs_spiffs_conf_t conf = {
.base_path = BASE_PATH,
.partition_label = NULL,
.max_files = 5,
.format_if_mount_failed = false
};

// Use settings defined above to initialize and mount SPIFFS filesystem.
// Note: esp_vfs_spiffs_register is an all-in-one convenience function.
esp_err_t ret = esp_vfs_spiffs_register(&conf);

if (ret != ESP_OK) {
if (ret == ESP_FAIL) {
ESP_LOGE(TAG, "Failed to mount or format filesystem");
} else if (ret == ESP_ERR_NOT_FOUND) {
ESP_LOGE(TAG, "Failed to find SPIFFS partition");
} else {
ESP_LOGE(TAG, "Failed to initialize SPIFFS (%s)", esp_err_to_name(ret));
}
return;
}

size_t total = 0, used = 0;
ret = esp_spiffs_info(NULL, &total, &used);
if (ret != ESP_OK) {
ESP_LOGE(TAG, "Failed to get SPIFFS partition information (%s)", esp_err_to_name(ret));
} else {
ESP_LOGI(TAG, "Partition size: total: %d, used: %d", total, used);
}
}

void app_main(void)
#else
#define BASE_PATH
int main(void)
#endif
{
parse("no_file.ini");
parse("normal.ini");
parse("bad_section.ini");
parse("bad_comment.ini");
parse("user_error.ini");
parse("multi_line.ini");
parse("bad_multi.ini");
parse("bom.ini");
parse("duplicate_sections.ini");
parse("no_value.ini");
#ifdef CONFIG_IDF_TARGET
spiffs_init();
#endif
parse(BASE_PATH "/" "no_file.ini");
parse(BASE_PATH "/" "normal.ini");
parse(BASE_PATH "/" "bad_section.ini");
parse(BASE_PATH "/" "bad_comment.ini");
parse(BASE_PATH "/" "user_error.ini");
parse(BASE_PATH "/" "multi_line.ini");
parse(BASE_PATH "/" "bad_multi.ini");
parse(BASE_PATH "/" "bom.ini");
parse(BASE_PATH "/" "duplicate_sections.ini");
parse(BASE_PATH "/" "no_value.ini");
#ifndef CONFIG_IDF_TARGET
return 0;
#endif
Expand Down

0 comments on commit ff2dcc8

Please sign in to comment.