From 783779c870bd02a8eaf7d5bf5f694906b7454d67 Mon Sep 17 00:00:00 2001 From: morris Date: Fri, 3 Apr 2020 16:53:11 +0800 Subject: [PATCH 1/3] esp_rom: move rom api test into esp_rom component --- components/esp32/test/CMakeLists.txt | 12 +- components/esp32/test/component.mk | 8 - components/esp32/test/test_miniz.c | 77 -------- components/esp32s2/test/CMakeLists.txt | 13 +- components/esp32s2/test/logo.jpg | Bin 7561 -> 0 bytes components/esp32s2/test/test_libgcc.c | 185 ------------------ components/esp_rom/test/CMakeLists.txt | 12 ++ components/esp_rom/test/component.mk | 15 ++ components/{esp32 => esp_rom}/test/logo.jpg | Bin .../{esp32 => esp_rom}/test/test_libgcc.c | 9 +- components/esp_rom/test/test_miniz.c | 105 ++++++++++ .../{esp32 => esp_rom}/test/test_tjpgd.c | 16 +- 12 files changed, 147 insertions(+), 305 deletions(-) delete mode 100644 components/esp32/test/test_miniz.c delete mode 100644 components/esp32s2/test/logo.jpg delete mode 100644 components/esp32s2/test/test_libgcc.c create mode 100644 components/esp_rom/test/CMakeLists.txt create mode 100644 components/esp_rom/test/component.mk rename components/{esp32 => esp_rom}/test/logo.jpg (100%) rename components/{esp32 => esp_rom}/test/test_libgcc.c (97%) create mode 100644 components/esp_rom/test/test_miniz.c rename components/{esp32 => esp_rom}/test/test_tjpgd.c (90%) diff --git a/components/esp32/test/CMakeLists.txt b/components/esp32/test/CMakeLists.txt index a0940e0477..297fa6370f 100644 --- a/components/esp32/test/CMakeLists.txt +++ b/components/esp32/test/CMakeLists.txt @@ -1,18 +1,8 @@ if(IDF_TARGET STREQUAL "esp32") idf_component_register(SRC_DIRS . - PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR} + PRIV_INCLUDE_DIRS . PRIV_REQUIRES unity test_utils nvs_flash ulp esp_common ) - - add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" - COMMAND xxd -i "logo.jpg" "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" - WORKING_DIRECTORY ${COMPONENT_DIR} - DEPENDS "${CMAKE_CURRENT_LIST_DIR}/logo.jpg") - - add_custom_target(esp32_test_logo DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h") - - add_dependencies(${COMPONENT_LIB} esp32_test_logo) - target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_test_dport_xt_highint5") endif() diff --git a/components/esp32/test/component.mk b/components/esp32/test/component.mk index d4b5a9012f..b68857397e 100644 --- a/components/esp32/test/component.mk +++ b/components/esp32/test/component.mk @@ -2,15 +2,7 @@ #Component Makefile # -COMPONENT_EXTRA_CLEAN := test_tjpgd_logo.h - COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive \ -u ld_include_test_dport_xt_highint5 \ COMPONENT_SRCDIRS := . - -test_tjpgd.o: test_tjpgd_logo.h - -test_tjpgd_logo.h: $(COMPONENT_PATH)/logo.jpg - $(summary) XXD logo.jpg - cd $(COMPONENT_PATH); xxd -i logo.jpg $(COMPONENT_BUILD_DIR)/test_tjpgd_logo.h diff --git a/components/esp32/test/test_miniz.c b/components/esp32/test/test_miniz.c deleted file mode 100644 index e4a6c99445..0000000000 --- a/components/esp32/test/test_miniz.c +++ /dev/null @@ -1,77 +0,0 @@ - - -#include -#include "esp32/rom/miniz.h" -#include "unity.h" - - -#define DATASIZE (1024*64) - -TEST_CASE("Test miniz compression/decompression", "[miniz][ignore]") -{ - int x; - char b; - char *inbuf, *outbuf; - tdefl_compressor *comp; - tinfl_decompressor *decomp; - tdefl_status status; - size_t inbytes = 0, outbytes = 0, inpos = 0, outpos = 0, compsz; - printf("Allocating data buffer and filling it with semi-random data\n"); - inbuf = malloc(DATASIZE); - TEST_ASSERT(inbuf != NULL); - srand(0); - for (x = 0; x < DATASIZE; x++) { - inbuf[x] = (x & 1) ? rand() & 0xff : 0; - } - printf("Allocating compressor & outbuf (%d bytes)\n", sizeof(tdefl_compressor)); - comp = malloc(sizeof(tdefl_compressor)); - TEST_ASSERT(comp != NULL); - outbuf = malloc(DATASIZE); - TEST_ASSERT(outbuf != NULL); - printf("Compressing...\n"); - status = tdefl_init(comp, NULL, NULL, TDEFL_WRITE_ZLIB_HEADER | 1500); - TEST_ASSERT(status == TDEFL_STATUS_OKAY); - while (inbytes != DATASIZE) { - outbytes = DATASIZE - outpos; - inbytes = DATASIZE - inpos; - tdefl_compress(comp, &inbuf[inpos], &inbytes, &outbuf[outpos], &outbytes, TDEFL_FINISH); - printf("...Compressed %d into %d bytes\n", inbytes, outbytes); - inpos += inbytes; outpos += outbytes; - } - compsz = outpos; - free(comp); - //Kill inbuffer - for (x = 0; x < DATASIZE; x++) { - inbuf[x] = 0; - } - free(inbuf); - - inbuf = outbuf; - outbuf = malloc(DATASIZE); - TEST_ASSERT(outbuf != NULL); - printf("Reinflating...\n"); - decomp = malloc(sizeof(tinfl_decompressor)); - TEST_ASSERT(decomp != NULL); - tinfl_init(decomp); - inpos = 0; outpos = 0; - while (inbytes != compsz) { - outbytes = DATASIZE - outpos; - inbytes = compsz - inpos; - tinfl_decompress(decomp, (const mz_uint8 *)&inbuf[inpos], &inbytes, (uint8_t *)outbuf, (mz_uint8 *)&outbuf[outpos], &outbytes, TINFL_FLAG_PARSE_ZLIB_HEADER); - printf("...Decompressed %d into %d bytes\n", inbytes, outbytes); - inpos += inbytes; outpos += outbytes; - } - printf("Checking if same...\n"); - srand(0); - for (x = 0; x < DATASIZE; x++) { - b = (x & 1) ? rand() & 0xff : 0; - if (outbuf[x] != b) { - printf("Pos %x: %hhx!=%hhx\n", x, outbuf[x], b); - TEST_ASSERT(0); - } - } - printf("Great Success!\n"); - free(inbuf); - free(outbuf); - free(decomp); -} diff --git a/components/esp32s2/test/CMakeLists.txt b/components/esp32s2/test/CMakeLists.txt index 155d8969f0..7d5e8e3953 100644 --- a/components/esp32s2/test/CMakeLists.txt +++ b/components/esp32s2/test/CMakeLists.txt @@ -1,18 +1,7 @@ if(IDF_TARGET STREQUAL "esp32s2") idf_component_register(SRC_DIRS . - PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR} + PRIV_INCLUDE_DIRS . PRIV_REQUIRES unity test_utils nvs_flash ulp esp_common ) - - add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" - COMMAND xxd -i "logo.jpg" "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" - WORKING_DIRECTORY ${COMPONENT_DIR} - DEPENDS "${CMAKE_CURRENT_LIST_DIR}/logo.jpg") - - add_custom_target(esp32s2_test_logo DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h") - - add_dependencies(${COMPONENT_LIB} esp32s2_test_logo) - - target_link_libraries(${COMPONENT_LIB} INTERFACE "-u ld_include_test_dport_xt_highint5") endif() diff --git a/components/esp32s2/test/logo.jpg b/components/esp32s2/test/logo.jpg deleted file mode 100644 index 2bd9e775eac4d4195d9d7465239fa007715ff428..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 7561 zcmex=_85ksPA;eS`Ffj19FfeR8kK`XQPP5`i&FEFQx(E8Q_C~+(iNQZ^HMTPGV}8kGV^f7Fqztr z+yG)i(lrAEgYc4n3?lJ*3!K{R|8YOvRb$;Pm4h6rzw^T2uy+2W3kJRt7Exeg+W+Nd`FvWd;ofT?Qit za|UY$2L@LLF9v^x5Qa#GIEG|~42E2WB8GB?8iq!OHimA72@F#iW--iXSi-Q9VI9LJ zhV2Y{7!EQVV>r!lf#E8{ZH5O7PZ?e_d|>#-@SBm5k)4s3QJ7JZQJztiQJc|-(Sp&A z(UsAMF^DmeF@Z6iF^{p7v4*jkv72!c<1EI7j4K&8GVWwN$as?RBI8ZQhm0>7KQaDd zVrJrD5@C{MQe)C*vS4y#@@5KQie*Y?DrBl+YGLYQn!&V)X${jhrh`nUnXWQDV0z8; zm6?H=n^}xmky)47g4vnbpE-&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g-mX zoYM91l$c?rEqVA#=v;$|r`tLvL{D#fl#u$#Ha+J8Z{C&b_J@O}vCW$}vG(MYok`Id zLQ0xCr&3SoEY5nO+}rW;`kSz&UyUQzTH7yoz4lJ3bXWYMxo3Iz&XS#YoY^CaYt_jq zDtcQIOaiUVchs9OevJOlAQ=2l@IS*B?*(i1f9*f zYG&T|L;o3yBCpJ=z518$=I-dLjp;MRHM3V&{qvh-=={@mW=rJs9R{D2lor_+3jXf+ zQxEuib$+GA<-$X1wdw zRpQ@L5T@#Oz=n7I4@UyO&otFsCeByl6rSr$R&ZZ2vRnC*N6|?^&%W=dQeJzHgP% z$0_g97VgioFxT#?o_opJeW#yWrlzY+j`2yJ2zlO##{-&;Ahoze!TGLp;Zq{S7qIv@>XX}QDkS5|DDMv zEtn^tJaFDebQQO1+g1O>4S~nK9T{$m2)Ipjmijx%W$LgnrDqmmQ%k@Wv|0TEc z?3?o^1Qsugv$^!Ak^S#}*^ -#include "unity.h" - -TEST_CASE("libgcc math functions", "[rom]") -{ - extern int64_t __absvdi2(int64_t x); - TEST_ASSERT(__absvdi2(-1L) == 1); - extern int __absvsi2(int x); - TEST_ASSERT(__absvsi2(-1) == 1); - extern double __adddf3(double x, double y); - TEST_ASSERT(__adddf3(1.0, 4.0) == 5.0); - extern float __addsf3(float x, float y); - TEST_ASSERT(__addsf3(1.0f, 4.0f) == 5.0f); - extern int64_t __addvdi3(int64_t x, int64_t y); - TEST_ASSERT(__addvdi3(1L, 4L) == 5L); - extern int __addvsi3(int x, int y); - TEST_ASSERT(__addvsi3(1, 4) == 5); - extern int64_t __ashldi3(int64_t x, int y); - TEST_ASSERT(__ashldi3(1, 4) == 16); - extern int64_t __ashrdi3(int64_t x, int y); - TEST_ASSERT(__ashrdi3(4, 1) == 2); - extern int64_t __bswapdi2(int64_t x); - TEST_ASSERT(__bswapdi2(0xaabbccddeeff0011ULL) == 0x1100ffeeddccbbaaULL); - extern int32_t __bswapsi2(int32_t x); - TEST_ASSERT(__bswapsi2(0xaabbccdd) == 0xddccbbaa); - extern int64_t __clrsbdi2(int64_t x); - TEST_ASSERT(__clrsbdi2(-1) == 63); - extern int __clrsbsi2(int x); - TEST_ASSERT(__clrsbsi2(-1) == 31); - extern int __clzdi2(int64_t x); - TEST_ASSERT(__clzdi2(1) == 63); - extern int __clzsi2(int x); - TEST_ASSERT(__clzsi2(1) == 31); - extern int __cmpdi2(int64_t x, int64_t y); - TEST_ASSERT(__cmpdi2(10, 10) == 1); - extern int __ctzdi2(uint64_t x); - TEST_ASSERT(__ctzdi2(0x8000000000000000ULL) == 63); - extern int __ctzsi2(unsigned x); - TEST_ASSERT(__ctzsi2(0x80000000U) == 31); - extern complex double __divdc3(double a, double b, double c, double d); - TEST_ASSERT(__divdc3(0, 1, 1, 0) == I); - extern double __divdf3(double x, double y); - TEST_ASSERT(__divdf3(16.0, 2.0) == 8.0); - extern int64_t __divdi3(int64_t x, int64_t y); - TEST_ASSERT(__divdi3(16, 2) == 8); - extern complex float __divsc3(float a, float b, float c, float d); - TEST_ASSERT(__divsc3(0, 1, 1, 0) == I); - extern float __divsf3(float x, float y); - TEST_ASSERT(__divsf3(16.0f, 2.0f) == 8.0f); - extern int __divsi3(int x, int y); - TEST_ASSERT(__divsi3(16, 2) == 8); - extern int __eqdf2(double x, double y); - TEST_ASSERT(__eqdf2(4.0, 4.0) == 0); - extern int __eqsf2(float x, float y); - TEST_ASSERT(__eqsf2(4.0f, 4.0f) == 0); - extern double __extendsfdf2(float x); - TEST_ASSERT(__extendsfdf2(4.0f) == 4.0); - extern int __ffsdi2(uint64_t x); - TEST_ASSERT(__ffsdi2(0x8000000000000000ULL) == 64); - extern int __ffssi2(unsigned x); - TEST_ASSERT(__ffssi2(0x80000000) == 32); - extern int64_t __fixdfdi(double x); - TEST_ASSERT(__fixdfdi(4.0) == 4LL); - extern int __fixdfsi(double x); - TEST_ASSERT(__fixdfsi(4.0) == 4); - extern int64_t __fixsfdi(float x); - TEST_ASSERT(__fixsfdi(4.0f) == 4LL); - extern int __fixsfsi(float x); - TEST_ASSERT(__fixsfsi(4.0f) == 4); - extern unsigned __fixunsdfsi(double x); - TEST_ASSERT(__fixunsdfsi(16.0) == 16); - extern uint64_t __fixunssfdi(float x); - TEST_ASSERT(__fixunssfdi(16.0f) == 16); - extern unsigned __fixunssfsi(float x); - TEST_ASSERT(__fixunssfsi(16.0f) == 16); - extern double __floatdidf(int64_t); - TEST_ASSERT(__floatdidf(-1LL) == -1.0f); - extern float __floatdisf(int64_t); - TEST_ASSERT(__floatdisf(-1LL) == -1.0f); - extern double __floatsidf(int x); - TEST_ASSERT(__floatsidf(-1) == -1.0); - extern float __floatsisf(int x); - TEST_ASSERT(__floatsisf(-1) == -1.0f); - extern double __floatundidf(uint64_t x); - TEST_ASSERT(__floatundidf(16) == 16.0); - extern float __floatundisf(uint64_t x); - TEST_ASSERT(__floatundisf(16) == 16.0f); - extern double __floatunsidf(unsigned x); - TEST_ASSERT(__floatunsidf(16) == 16.0); - extern float __floatunsisf(unsigned x); - TEST_ASSERT(__floatunsisf(16) == 16.0f); - extern int __gedf2(double x, double y); - TEST_ASSERT(__gedf2(2.0, 0.0) >= 0); - extern int __gesf2(float x, float y); - TEST_ASSERT(__gesf2(2.0f, 0.0f) >= 0); - extern int __gtdf2(double x, double y); - TEST_ASSERT(__gtdf2(2.0, 0.0) >= 0); - extern int __gtsf2(float x, float y); - TEST_ASSERT(__gtsf2(2.0f, 0.0f) >= 0); - extern int __ledf2(double x, double y); - TEST_ASSERT(__ledf2(0.0, 2.0) <= 0); - extern int __lesf2(float x, float y); - TEST_ASSERT(__lesf2(0.0f, 2.0f) <= 0); - extern int64_t __lshrdi3(int64_t x, int y); - TEST_ASSERT(__lshrdi3(0x8000000000000000LL, 1) == 0x4000000000000000LL); - extern int __ltdf2(double x, double y); - TEST_ASSERT(__ltdf2(0.0, 2.0) < 0); - extern int __ltsf2(float x, float y); - TEST_ASSERT(__ltsf2(0.0f, 2.0f) < 0); - extern int64_t __moddi3(int64_t x, int64_t y); - TEST_ASSERT(__moddi3(15, 2) == 1); - extern int __modsi3(int x, int y); - TEST_ASSERT(__modsi3(15, 2) == 1); - extern complex double __muldc3(double a, double b, double c, double d); - TEST_ASSERT(__muldc3(1.0, 0.0, 0.0, 1.0) == I); - extern double __muldf3(double x, double y); - TEST_ASSERT(__muldf3(2.0, 8.0) == 16.0); - extern int64_t __muldi3(int64_t x, int64_t y); - TEST_ASSERT(__muldi3(2, 8) == 16); - extern complex float __mulsc3 (float a, float b, float c, float d); - TEST_ASSERT(__mulsc3(1.0f, 0.0f, 0.0f, -1.0f) == -I); - extern float __mulsf3 (float a, float b); - TEST_ASSERT(__mulsf3(2.0f, 8.0f) == 16.0f); - extern int __mulsi3(int x, int y); - TEST_ASSERT(__mulsi3(2, 8) == 16); - extern int __mulvdi3(int64_t x, int64_t y); - TEST_ASSERT(__mulvdi3(2, 8) == 16); - extern int __mulvsi3(int x, int y); - TEST_ASSERT(__mulvsi3(2, 8) == 16); - extern int __nedf2(double x, double y); - TEST_ASSERT(__nedf2(2.0, 2.0) == 0); - extern double __negdf2(double x); - TEST_ASSERT(__negdf2(1.0) == -1.0); - extern int64_t __negdi2(int64_t x); - TEST_ASSERT(__negdi2(-1LL) == 1); - extern float __negsf2(float x); - TEST_ASSERT(__negsf2(-1.0f) == 1.0f); - extern int64_t __negvdi2(int64_t x); - TEST_ASSERT(__negvdi2(-1LL) == 1); - extern int __negvsi2(int x); - TEST_ASSERT(__negvsi2(-1) == 1); - extern int __nesf2(float x, float y); - TEST_ASSERT(__nesf2(2.0, 0.0) != 0); - extern int __paritysi2(unsigned x); - TEST_ASSERT(__paritysi2(0x10101010) == 0); - extern int __popcountdi2(uint64_t); - TEST_ASSERT(__popcountdi2(0xaaaaaaaa11111111ULL) == 24); - extern int __popcountsi2(unsigned x); - TEST_ASSERT(__popcountsi2(0x11111111) == 8); - extern double __powidf2(double x, int y); - TEST_ASSERT(__powidf2(2.0, -1) == 0.5); - extern float __powisf2(float x, int y); - TEST_ASSERT(__powisf2(2.0f, 2) == 4.0f); - extern double __subdf3(double x, double y); - TEST_ASSERT(__subdf3(2.0, 1.0) == 1.0); - extern float __subsf3(float x, float y); - TEST_ASSERT(__subsf3(5.0f, 4.0f) == 1.0f); - extern int64_t __subvdi3(int64_t x, int64_t y); - TEST_ASSERT(__subvdi3(-1LL, -1LL) == 0); - extern int __subvsi3(int x, int y); - TEST_ASSERT(__subvsi3(-1, -1) == 0); - extern float __truncdfsf2(double x); - TEST_ASSERT(__truncdfsf2(4.0) == 4.0f); - extern int __ucmpdi2(uint64_t x, uint64_t y); - TEST_ASSERT(__ucmpdi2(0x100000000ULL, 0x100000000ULL) == 1); - extern uint64_t __udivdi3(uint64_t x, uint64_t y); - TEST_ASSERT(__udivdi3(15, 2) == 7); - extern uint64_t __udivmoddi4(uint64_t x, uint64_t y, uint64_t* z); - uint64_t z; - TEST_ASSERT(__udivmoddi4(15, 2, &z) == 7); - TEST_ASSERT(z == 1); - extern unsigned __udivsi3(unsigned x, unsigned y); - TEST_ASSERT(__udivsi3(15, 2) == 7); - extern uint64_t __umoddi3(uint64_t x, uint64_t y); - TEST_ASSERT(__umoddi3(15, 2) == 1); - extern unsigned __umodsi3(unsigned x, unsigned y); - TEST_ASSERT(__umodsi3(15, 2) == 1); - extern uint64_t __umulsidi3(unsigned x, unsigned y); - TEST_ASSERT(__umulsidi3(0x10000000, 0x10000000) == 0x100000000000000ULL); - extern int __unorddf2(double x, double y); - TEST_ASSERT(__unorddf2(1.0, 2.0) == 0); - extern int __unordsf2(float x, float y); - TEST_ASSERT(__unordsf2(2.0f, 1.0f) == 0); - -} diff --git a/components/esp_rom/test/CMakeLists.txt b/components/esp_rom/test/CMakeLists.txt new file mode 100644 index 0000000000..c28ddcca46 --- /dev/null +++ b/components/esp_rom/test/CMakeLists.txt @@ -0,0 +1,12 @@ +idf_component_register(SRC_DIRS . + PRIV_INCLUDE_DIRS . ${CMAKE_CURRENT_BINARY_DIR} + PRIV_REQUIRES unity test_utils) + +if(IDF_TARGET STREQUAL "esp32") + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" + COMMAND xxd -i "logo.jpg" "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h" + WORKING_DIRECTORY ${COMPONENT_DIR} + DEPENDS "${CMAKE_CURRENT_LIST_DIR}/logo.jpg") + add_custom_target(test_logo DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/test_tjpgd_logo.h") + add_dependencies(${COMPONENT_LIB} test_logo) +endif() diff --git a/components/esp_rom/test/component.mk b/components/esp_rom/test/component.mk new file mode 100644 index 0000000000..07ea1205a5 --- /dev/null +++ b/components/esp_rom/test/component.mk @@ -0,0 +1,15 @@ +# +#Component Makefile +# + +COMPONENT_SRCDIRS := . + +COMPONENT_ADD_LDFLAGS = -Wl,--whole-archive -l$(COMPONENT_NAME) -Wl,--no-whole-archive + +COMPONENT_EXTRA_CLEAN := test_tjpgd_logo.h + +test_tjpgd.o: test_tjpgd_logo.h + +test_tjpgd_logo.h: $(COMPONENT_PATH)/logo.jpg + $(summary) XXD logo.jpg + cd $(COMPONENT_PATH); xxd -i logo.jpg $(COMPONENT_BUILD_DIR)/test_tjpgd_logo.h diff --git a/components/esp32/test/logo.jpg b/components/esp_rom/test/logo.jpg similarity index 100% rename from components/esp32/test/logo.jpg rename to components/esp_rom/test/logo.jpg diff --git a/components/esp32/test/test_libgcc.c b/components/esp_rom/test/test_libgcc.c similarity index 97% rename from components/esp32/test/test_libgcc.c rename to components/esp_rom/test/test_libgcc.c index 7fca990d48..25c5ae7f17 100644 --- a/components/esp32/test/test_libgcc.c +++ b/components/esp_rom/test/test_libgcc.c @@ -1,7 +1,7 @@ #include #include "unity.h" -TEST_CASE("libgcc math functions", "[rom]") +TEST_CASE("libgcc math functions", "[rom][libgcc]") { extern int64_t __absvdi2(int64_t x); TEST_ASSERT(__absvdi2(-1L) == 1); @@ -117,9 +117,9 @@ TEST_CASE("libgcc math functions", "[rom]") TEST_ASSERT(__muldf3(2.0, 8.0) == 16.0); extern int64_t __muldi3(int64_t x, int64_t y); TEST_ASSERT(__muldi3(2, 8) == 16); - extern complex float __mulsc3 (float a, float b, float c, float d); + extern complex float __mulsc3(float a, float b, float c, float d); TEST_ASSERT(__mulsc3(1.0f, 0.0f, 0.0f, -1.0f) == -I); - extern float __mulsf3 (float a, float b); + extern float __mulsf3(float a, float b); TEST_ASSERT(__mulsf3(2.0f, 8.0f) == 16.0f); extern int __mulsi3(int x, int y); TEST_ASSERT(__mulsi3(2, 8) == 16); @@ -165,7 +165,7 @@ TEST_CASE("libgcc math functions", "[rom]") TEST_ASSERT(__ucmpdi2(0x100000000ULL, 0x100000000ULL) == 1); extern uint64_t __udivdi3(uint64_t x, uint64_t y); TEST_ASSERT(__udivdi3(15, 2) == 7); - extern uint64_t __udivmoddi4(uint64_t x, uint64_t y, uint64_t* z); + extern uint64_t __udivmoddi4(uint64_t x, uint64_t y, uint64_t *z); uint64_t z; TEST_ASSERT(__udivmoddi4(15, 2, &z) == 7); TEST_ASSERT(z == 1); @@ -181,5 +181,4 @@ TEST_CASE("libgcc math functions", "[rom]") TEST_ASSERT(__unorddf2(1.0, 2.0) == 0); extern int __unordsf2(float x, float y); TEST_ASSERT(__unordsf2(2.0f, 1.0f) == 0); - } diff --git a/components/esp_rom/test/test_miniz.c b/components/esp_rom/test/test_miniz.c new file mode 100644 index 0000000000..1ba742b331 --- /dev/null +++ b/components/esp_rom/test/test_miniz.c @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include "sdkconfig.h" +#include "unity.h" + +// compression/decompression will take off a bunch of memory +// test it only with PSRAM enabled +#ifdef CONFIG_SPIRAM + +#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32) + +#if CONFIG_IDF_TARGET_ESP32 +#include "esp32/rom/miniz.h" +#elif CONFIG_IDF_TARGET_ESP32S2 +#include "esp32s2/rom/miniz.h" +#else +#error "unsupported target" +#endif + + +#define DATASIZE (1024 * 64) + +TEST_CASE("Test miniz compression/decompression", "[rom][miniz]") +{ + size_t inbytes = 0, outbytes = 0, inpos = 0, outpos = 0, compsz; + printf("Allocating data buffer and filling it with semi-random data\r\n"); + uint8_t *inbuf = calloc(1, DATASIZE); + TEST_ASSERT_NOT_NULL_MESSAGE(inbuf, "allocate input buffer failed"); + + srand(0); // semi random data + for (int i = 0; i < DATASIZE; i++) { + inbuf[i] = (i & 0x01) ? rand() & 0xff : 0; + } + + printf("Allocating compressor\r\n"); + tdefl_compressor *comp = calloc(1, sizeof(tdefl_compressor)); + TEST_ASSERT_NOT_NULL_MESSAGE(comp, "allocate tdefl_compressor failed"); + + uint8_t *outbuf = calloc(1, DATASIZE); + TEST_ASSERT_NOT_NULL_MESSAGE(outbuf, "allocate output buffer failed"); + + printf("Compressing...\r\n"); + tdefl_status comp_status = tdefl_init(comp, NULL, NULL, TDEFL_WRITE_ZLIB_HEADER | 1500); + TEST_ASSERT_EQUAL_MESSAGE(TDEFL_STATUS_OKAY, comp_status, "tdefl_init failed"); + + while (1) { + outbytes = DATASIZE - outpos; + inbytes = DATASIZE - inpos; + comp_status = tdefl_compress(comp, &inbuf[inpos], &inbytes, &outbuf[outpos], &outbytes, TDEFL_FINISH); + inpos += inbytes; + outpos += outbytes; + printf("...Compressed %d into %d bytes\r\n", inpos, outpos); + if (comp_status == TDEFL_STATUS_DONE) { + break; + } else if (comp_status != TDEFL_STATUS_OKAY) { + TEST_ASSERT_MESSAGE(0, "tdefl_compress failed"); + } + } + + compsz = outpos; + free(comp); + free(inbuf); + + inbuf = outbuf; + outbuf = calloc(1, DATASIZE); + TEST_ASSERT_NOT_NULL_MESSAGE(outbuf, "allocate output buffer failed"); + + printf("Decompressing...\r\n"); + tinfl_decompressor *decomp = calloc(1, sizeof(tinfl_decompressor)); + TEST_ASSERT_NOT_NULL_MESSAGE(decomp, "allocate tinfl_decompressor failed"); + tinfl_init(decomp); + + inpos = 0; + outpos = 0; + while (1) { + outbytes = DATASIZE - outpos; + inbytes = compsz - inpos; + tinfl_status decomp_status = tinfl_decompress(decomp, &inbuf[inpos], &inbytes, outbuf, &outbuf[outpos], &outbytes, TINFL_FLAG_PARSE_ZLIB_HEADER); + inpos += inbytes; + outpos += outbytes; + printf("...Decompressed %d into %d bytes\r\n", inpos, outpos); + if (decomp_status == TINFL_STATUS_DONE) { + break; + } else if (decomp_status < TINFL_STATUS_DONE) { + printf("decomp status=%d\r\n", decomp_status); + TEST_ASSERT_MESSAGE(0, "tinfl_decompress failed"); + } + } + + printf("Verifying data between compression and decompression...\r\n"); + srand(0); // semi random data + for (int i = 0; i < DATASIZE; i++) { + uint8_t original = (i & 1) ? rand() & 0xff : 0; + TEST_ASSERT_EQUAL_MESSAGE(original, outbuf[i], "data after decompression doesn't match the original one"); + } + printf("Great Success!\n"); + free(inbuf); + free(outbuf); + free(decomp); +} + +#endif //#if !TEMPORARY_DISABLED_FOR_TARGETS(ESP32) +#endif // CONFIG_SPIRAM \ No newline at end of file diff --git a/components/esp32/test/test_tjpgd.c b/components/esp_rom/test/test_tjpgd.c similarity index 90% rename from components/esp32/test/test_tjpgd.c rename to components/esp_rom/test/test_tjpgd.c index 82c147b11e..7a0439c0d0 100644 --- a/components/esp32/test/test_tjpgd.c +++ b/components/esp_rom/test/test_tjpgd.c @@ -1,12 +1,13 @@ - - #include -#include "esp32/rom/tjpgd.h" #include #include #include +#include "sdkconfig.h" #include "unity.h" +#if CONFIG_IDF_TARGET_ESP32 + +#include "esp32/rom/tjpgd.h" #include "test_tjpgd_logo.h" typedef struct { @@ -17,7 +18,6 @@ typedef struct { int outH; } JpegDev; - static UINT infunc(JDEC *decoder, BYTE *buf, UINT len) { JpegDev *jd = (JpegDev *)decoder->device; @@ -29,7 +29,6 @@ static UINT infunc(JDEC *decoder, BYTE *buf, UINT len) return len; } - static UINT outfunc(JDEC *decoder, void *bitmap, JRECT *rect) { unsigned char *in = (unsigned char *)bitmap; @@ -49,7 +48,7 @@ static UINT outfunc(JDEC *decoder, void *bitmap, JRECT *rect) #define TESTH 48 #define WORKSZ 3100 -TEST_CASE("Test JPEG decompression library", "[tjpgd]") +TEST_CASE("Test JPEG decompression library", "[rom][tjpgd]") { char aapix[] = " .:;+=xX$$"; unsigned char *decoded, *p; @@ -60,7 +59,8 @@ TEST_CASE("Test JPEG decompression library", "[tjpgd]") JpegDev jd; decoded = malloc(48 * 48 * 3); for (x = 0; x < 48 * 48 * 3; x += 2) { - decoded[x] = 0; decoded[x + 1] = 0xff; + decoded[x] = 0; + decoded[x + 1] = 0xff; } work = malloc(WORKSZ); memset(work, 0, WORKSZ); @@ -89,3 +89,5 @@ TEST_CASE("Test JPEG decompression library", "[tjpgd]") free(work); free(decoded); } + +#endif // #if CONFIG_IDF_TARGET_ESP32 From d70961ad58375260b5eea5c622167d5f00f88cb1 Mon Sep 17 00:00:00 2001 From: morris Date: Fri, 3 Apr 2020 17:11:39 +0800 Subject: [PATCH 2/3] esp32s2: add more unit test for esp32s2 Most of the test cases are copied from esp32 add int_alloc test add delay test add random test --- components/esp32/test/test_intr_alloc.c | 16 +- components/esp32s2/test/test_delay.c | 73 ++++++ components/esp32s2/test/test_intr_alloc.c | 291 ++++++++++++++++++++++ components/esp32s2/test/test_random.c | 66 +++++ tools/ci/config/target-test.yml | 2 +- 5 files changed, 437 insertions(+), 11 deletions(-) create mode 100644 components/esp32s2/test/test_delay.c create mode 100644 components/esp32s2/test/test_intr_alloc.c create mode 100644 components/esp32s2/test/test_random.c diff --git a/components/esp32/test/test_intr_alloc.c b/components/esp32/test/test_intr_alloc.c index a477c543c1..07442c33fc 100644 --- a/components/esp32/test/test_intr_alloc.c +++ b/components/esp32/test/test_intr_alloc.c @@ -4,11 +4,7 @@ #include #include -#if CONFIG_IDF_TARGET_ESP32 #include "esp32/rom/ets_sys.h" -#elif CONFIG_IDF_TARGET_ESP32S2 -#include "esp32s2/rom/ets_sys.h" -#endif #include "freertos/FreeRTOS.h" #include "freertos/task.h" #include "freertos/semphr.h" @@ -187,22 +183,22 @@ void local_timer_test(void) } -TEST_CASE("Intr_alloc test, CPU-local int source", "[esp32]") +TEST_CASE("Intr_alloc test, CPU-local int source", "[intr_alloc]") { local_timer_test(); } -TEST_CASE("Intr_alloc test, private ints", "[esp32]") +TEST_CASE("Intr_alloc test, private ints", "[intr_alloc]") { timer_test(0); } -TEST_CASE("Intr_alloc test, shared ints", "[esp32]") +TEST_CASE("Intr_alloc test, shared ints", "[intr_alloc]") { timer_test(ESP_INTR_FLAG_SHARED); } -TEST_CASE("Can allocate IRAM int only with an IRAM handler", "[esp32]") +TEST_CASE("Can allocate IRAM int only with an IRAM handler", "[intr_alloc]") { void dummy(void* arg) { @@ -261,7 +257,7 @@ void IRAM_ATTR int_handler2(void* arg) } } -TEST_CASE("allocate 2 handlers for a same source and remove the later one","[esp32]") +TEST_CASE("allocate 2 handlers for a same source and remove the later one","[intr_alloc]") { intr_alloc_test_ctx_t ctx = {false, false, false, false }; intr_handle_t handle1, handle2; @@ -328,7 +324,7 @@ void isr_alloc_free_test(void) printf("test passed\n"); } -TEST_CASE("alloc and free isr handle on different core", "[esp32]") +TEST_CASE("alloc and free isr handle on different core", "[intr_alloc]") { isr_alloc_free_test(); } diff --git a/components/esp32s2/test/test_delay.c b/components/esp32s2/test/test_delay.c new file mode 100644 index 0000000000..d04642c83b --- /dev/null +++ b/components/esp32s2/test/test_delay.c @@ -0,0 +1,73 @@ +#include +#include +#include +#include +#include "esp32s2/rom/ets_sys.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "unity.h" +#include "test_utils.h" + +typedef struct { + int delay_us; + int method; + int result; + SemaphoreHandle_t done; +} delay_test_arg_t; + +static void test_delay_task(void *p) +{ + delay_test_arg_t *arg = (delay_test_arg_t *)p; + vTaskDelay(1); + uint64_t start = ref_clock_get(); + switch (arg->method) { + case 0: + ets_delay_us(arg->delay_us); + break; + case 1: + vTaskDelay(arg->delay_us / portTICK_PERIOD_MS / 1000); + break; + default: + TEST_FAIL(); + } + uint64_t stop = ref_clock_get(); + + arg->result = (int)(stop - start); + xSemaphoreGive(arg->done); + vTaskDelete(NULL); +} + +TEST_CASE("ets_delay produces correct delay", "[delay]") +{ + int delay_ms = 50; + const delay_test_arg_t args = { + .delay_us = delay_ms * 1000, + .method = 0, + .done = xSemaphoreCreateBinary() + }; + ref_clock_init(); + xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void *)&args, 3, NULL, 0); + TEST_ASSERT(xSemaphoreTake(args.done, delay_ms * 2 / portTICK_PERIOD_MS)); + TEST_ASSERT_INT32_WITHIN(1000, args.delay_us, args.result); + + ref_clock_deinit(); + vSemaphoreDelete(args.done); +} + +TEST_CASE("vTaskDelay produces correct delay", "[delay]") +{ + int delay_ms = 50; + const delay_test_arg_t args = { + .delay_us = delay_ms * 1000, + .method = 1, + .done = xSemaphoreCreateBinary() + }; + ref_clock_init(); + xTaskCreatePinnedToCore(test_delay_task, "", 2048, (void *)&args, 3, NULL, 0); + TEST_ASSERT(xSemaphoreTake(args.done, delay_ms * 2 / portTICK_PERIOD_MS)); + TEST_ASSERT_INT32_WITHIN(1000, args.delay_us, args.result); + + ref_clock_deinit(); + vSemaphoreDelete(args.done); +} diff --git a/components/esp32s2/test/test_intr_alloc.c b/components/esp32s2/test/test_intr_alloc.c new file mode 100644 index 0000000000..b136a4720e --- /dev/null +++ b/components/esp32s2/test/test_intr_alloc.c @@ -0,0 +1,291 @@ +/* + Tests for the interrupt allocator. +*/ + +#include +#include "unity.h" +#include "esp_types.h" +#include "esp32s2/rom/ets_sys.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "freertos/semphr.h" +#include "freertos/queue.h" +#include "freertos/xtensa_api.h" +#include "soc/uart_periph.h" +#include "soc/dport_reg.h" +#include "soc/gpio_periph.h" +#include "esp_intr_alloc.h" +#include "driver/periph_ctrl.h" +#include "driver/timer.h" + +#define TIMER_DIVIDER 16 /*!< Hardware timer clock divider */ +#define TIMER_SCALE (TIMER_BASE_CLK / TIMER_DIVIDER) /*!< used to calculate counter value */ +#define TIMER_INTERVAL0_SEC (3.4179) /*!< test interval for timer 0 */ +#define TIMER_INTERVAL1_SEC (5.78) /*!< test interval for timer 1 */ + +static void my_timer_init(int timer_group, int timer_idx, int ival) +{ + timer_config_t config; + config.alarm_en = 1; + config.auto_reload = 1; + config.counter_dir = TIMER_COUNT_UP; + config.divider = TIMER_DIVIDER; + config.intr_type = TIMER_INTR_LEVEL; + config.counter_en = TIMER_PAUSE; + /*Configure timer*/ + timer_init(timer_group, timer_idx, &config); + /*Stop timer counter*/ + timer_pause(timer_group, timer_idx); + /*Load counter value */ + timer_set_counter_value(timer_group, timer_idx, 0x00000000ULL); + /*Set alarm value*/ + timer_set_alarm_value(timer_group, timer_idx, ival); + /*Enable timer interrupt*/ + timer_enable_intr(timer_group, timer_idx); +} + +static volatile int count[4] = {0, 0, 0, 0}; + +static void timer_isr(void *arg) +{ + int timer_idx = (int)arg; + count[timer_idx]++; + if (timer_idx == 0) { + timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_0); + timer_group_enable_alarm_in_isr(TIMER_GROUP_0, TIMER_0); + } + if (timer_idx == 1) { + timer_group_clr_intr_status_in_isr(TIMER_GROUP_0, TIMER_1); + timer_group_enable_alarm_in_isr(TIMER_GROUP_0, TIMER_1); + } + if (timer_idx == 2) { + timer_group_clr_intr_status_in_isr(TIMER_GROUP_1, TIMER_0); + timer_group_enable_alarm_in_isr(TIMER_GROUP_1, TIMER_0); + } + if (timer_idx == 3) { + timer_group_clr_intr_status_in_isr(TIMER_GROUP_1, TIMER_1); + timer_group_enable_alarm_in_isr(TIMER_GROUP_1, TIMER_1); + } +} + +static void timer_test(int flags) +{ + int x; + timer_isr_handle_t inth[4]; + my_timer_init(TIMER_GROUP_0, TIMER_0, 110000); + my_timer_init(TIMER_GROUP_0, TIMER_1, 120000); + my_timer_init(TIMER_GROUP_1, TIMER_0, 130000); + my_timer_init(TIMER_GROUP_1, TIMER_1, 140000); + timer_isr_register(TIMER_GROUP_0, TIMER_0, timer_isr, (void *)0, flags | ESP_INTR_FLAG_INTRDISABLED, &inth[0]); + timer_isr_register(TIMER_GROUP_0, TIMER_1, timer_isr, (void *)1, flags, &inth[1]); + timer_isr_register(TIMER_GROUP_1, TIMER_0, timer_isr, (void *)2, flags, &inth[2]); + timer_isr_register(TIMER_GROUP_1, TIMER_1, timer_isr, (void *)3, flags, &inth[3]); + timer_start(TIMER_GROUP_0, TIMER_0); + timer_start(TIMER_GROUP_0, TIMER_1); + timer_start(TIMER_GROUP_1, TIMER_0); + timer_start(TIMER_GROUP_1, TIMER_1); + + for (x = 0; x < 4; x++) { + count[x] = 0; + } + printf("Interrupts allocated: %d (dis) %d %d %d\n", + esp_intr_get_intno(inth[0]), esp_intr_get_intno(inth[1]), + esp_intr_get_intno(inth[2]), esp_intr_get_intno(inth[3])); + printf("Timer values on start: %d %d %d %d\n", count[0], count[1], count[2], count[3]); + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer values after 1 sec: %d %d %d %d\n", count[0], count[1], count[2], count[3]); + TEST_ASSERT(count[0] == 0); + TEST_ASSERT(count[1] != 0); + TEST_ASSERT(count[2] != 0); + TEST_ASSERT(count[3] != 0); + + printf("Disabling timers 1 and 2...\n"); + esp_intr_enable(inth[0]); + esp_intr_disable(inth[1]); + esp_intr_disable(inth[2]); + for (x = 0; x < 4; x++) { + count[x] = 0; + } + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer values after 1 sec: %d %d %d %d\n", count[0], count[1], count[2], count[3]); + TEST_ASSERT(count[0] != 0); + TEST_ASSERT(count[1] == 0); + TEST_ASSERT(count[2] == 0); + TEST_ASSERT(count[3] != 0); + printf("Disabling other half...\n"); + esp_intr_enable(inth[1]); + esp_intr_enable(inth[2]); + esp_intr_disable(inth[0]); + esp_intr_disable(inth[3]); + for (x = 0; x < 4; x++) { + count[x] = 0; + } + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer values after 1 sec: %d %d %d %d\n", count[0], count[1], count[2], count[3]); + TEST_ASSERT(count[0] == 0); + TEST_ASSERT(count[1] != 0); + TEST_ASSERT(count[2] != 0); + TEST_ASSERT(count[3] == 0); + printf("Done.\n"); + esp_intr_free(inth[0]); + esp_intr_free(inth[1]); + esp_intr_free(inth[2]); + esp_intr_free(inth[3]); +} + +static volatile int int_timer_ctr; + +void int_timer_handler(void *arg) +{ + xthal_set_ccompare(1, xthal_get_ccount() + 8000000); + int_timer_ctr++; +} + +void local_timer_test(void) +{ + intr_handle_t ih; + esp_err_t r; + r = esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, 0, int_timer_handler, NULL, &ih); + TEST_ASSERT(r == ESP_OK); + printf("Int timer 1 intno %d\n", esp_intr_get_intno(ih)); + xthal_set_ccompare(1, xthal_get_ccount() + 8000000); + int_timer_ctr = 0; + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer val after 1 sec: %d\n", int_timer_ctr); + TEST_ASSERT(int_timer_ctr != 0); + printf("Disabling int\n"); + esp_intr_disable(ih); + int_timer_ctr = 0; + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer val after 1 sec: %d\n", int_timer_ctr); + TEST_ASSERT(int_timer_ctr == 0); + printf("Re-enabling\n"); + esp_intr_enable(ih); + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer val after 1 sec: %d\n", int_timer_ctr); + TEST_ASSERT(int_timer_ctr != 0); + + printf("Free int, re-alloc disabled\n"); + r = esp_intr_free(ih); + TEST_ASSERT(r == ESP_OK); + r = esp_intr_alloc(ETS_INTERNAL_TIMER1_INTR_SOURCE, ESP_INTR_FLAG_INTRDISABLED, int_timer_handler, NULL, &ih); + TEST_ASSERT(r == ESP_OK); + int_timer_ctr = 0; + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer val after 1 sec: %d\n", int_timer_ctr); + TEST_ASSERT(int_timer_ctr == 0); + printf("Re-enabling\n"); + esp_intr_enable(ih); + vTaskDelay(1000 / portTICK_PERIOD_MS); + printf("Timer val after 1 sec: %d\n", int_timer_ctr); + TEST_ASSERT(int_timer_ctr != 0); + r = esp_intr_free(ih); + TEST_ASSERT(r == ESP_OK); + printf("Done.\n"); +} + +TEST_CASE("Intr_alloc test, CPU-local int source", "[intr_alloc]") +{ + local_timer_test(); +} + +TEST_CASE("Intr_alloc test, private ints", "[intr_alloc]") +{ + timer_test(0); +} + +TEST_CASE("Intr_alloc test, shared ints", "[intr_alloc]") +{ + timer_test(ESP_INTR_FLAG_SHARED); +} + +TEST_CASE("Can allocate IRAM int only with an IRAM handler", "[intr_alloc]") +{ + void dummy(void *arg) { + } + IRAM_ATTR void dummy_iram(void *arg) { + } + RTC_IRAM_ATTR void dummy_rtc(void *arg) { + } + intr_handle_t ih; + esp_err_t err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, + ESP_INTR_FLAG_IRAM, &dummy, NULL, &ih); + TEST_ASSERT_EQUAL_INT(ESP_ERR_INVALID_ARG, err); + err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, + ESP_INTR_FLAG_IRAM, &dummy_iram, NULL, &ih); + TEST_ESP_OK(err); + err = esp_intr_free(ih); + TEST_ESP_OK(err); + err = esp_intr_alloc(ETS_INTERNAL_SW0_INTR_SOURCE, + ESP_INTR_FLAG_IRAM, &dummy_rtc, NULL, &ih); + TEST_ESP_OK(err); + err = esp_intr_free(ih); + TEST_ESP_OK(err); +} + +#include "soc/spi_periph.h" +typedef struct { + bool flag1; + bool flag2; + bool flag3; + bool flag4; +} intr_alloc_test_ctx_t; + +void IRAM_ATTR int_handler1(void *arg) +{ + intr_alloc_test_ctx_t *ctx = (intr_alloc_test_ctx_t *)arg; + ets_printf("handler 1 called.\n"); + if (ctx->flag1) { + ctx->flag3 = true; + } else { + ctx->flag1 = true; + } + GPSPI2.slave.trans_done = 0; +} + +void IRAM_ATTR int_handler2(void *arg) +{ + intr_alloc_test_ctx_t *ctx = (intr_alloc_test_ctx_t *)arg; + ets_printf("handler 2 called.\n"); + if (ctx->flag2) { + ctx->flag4 = true; + } else { + ctx->flag2 = true; + } +} + +TEST_CASE("allocate 2 handlers for a same source and remove the later one", "[intr_alloc]") +{ + intr_alloc_test_ctx_t ctx = {false, false, false, false}; + intr_handle_t handle1, handle2; + + //enable SPI2 + periph_module_enable(PERIPH_FSPI_MODULE); + + esp_err_t r; + r = esp_intr_alloc(ETS_SPI2_INTR_SOURCE, ESP_INTR_FLAG_SHARED, int_handler1, &ctx, &handle1); + TEST_ESP_OK(r); + //try an invalid assign first + r = esp_intr_alloc(ETS_SPI2_INTR_SOURCE, 0, int_handler2, NULL, &handle2); + TEST_ASSERT_EQUAL_INT(r, ESP_ERR_NOT_FOUND); + //assign shared then + r = esp_intr_alloc(ETS_SPI2_INTR_SOURCE, ESP_INTR_FLAG_SHARED, int_handler2, &ctx, &handle2); + TEST_ESP_OK(r); + GPSPI2.slave.int_trans_done_en = 1; + + printf("trigger first time.\n"); + GPSPI2.slave.trans_done = 1; + + vTaskDelay(100); + TEST_ASSERT(ctx.flag1 && ctx.flag2); + + printf("remove intr 1.\n"); + r = esp_intr_free(handle2); + + printf("trigger second time.\n"); + GPSPI2.slave.trans_done = 1; + + vTaskDelay(500); + TEST_ASSERT(ctx.flag3 && !ctx.flag4); + printf("test passed.\n"); +} diff --git a/components/esp32s2/test/test_random.c b/components/esp32s2/test/test_random.c new file mode 100644 index 0000000000..083c791246 --- /dev/null +++ b/components/esp32s2/test/test_random.c @@ -0,0 +1,66 @@ +#include +#include +#include "unity.h" +#include "esp_system.h" + +/* Note: these are just sanity tests, not the same as + entropy tests +*/ + +TEST_CASE("call esp_random()", "[random]") +{ + const size_t NUM_RANDOM = 128; /* in most cases this is massive overkill */ + + uint32_t zeroes = UINT32_MAX; + uint32_t ones = 0; + for (int i = 0; i < NUM_RANDOM - 1; i++) { + uint32_t r = esp_random(); + ones |= r; + zeroes &= ~r; + } + + /* assuming a 'white' random distribution, we can expect + usually at least one time each bit will be zero and at + least one time each will be one. Statistically this + can still fail, just *very* unlikely to. */ + TEST_ASSERT_EQUAL_HEX32(0, zeroes); + TEST_ASSERT_EQUAL_HEX32(UINT32_MAX, ones); +} + +TEST_CASE("call esp_fill_random()", "[random]") +{ + const size_t NUM_BUF = 200; + const size_t BUF_SZ = 16; + uint8_t buf[NUM_BUF][BUF_SZ]; + uint8_t zero_buf[BUF_SZ]; + uint8_t one_buf[BUF_SZ]; + + bzero(buf, sizeof(buf)); + bzero(one_buf, sizeof(zero_buf)); + memset(zero_buf, 0xFF, sizeof(one_buf)); + + for (int i = 0; i < NUM_BUF; i++) { + esp_fill_random(buf[i], BUF_SZ); + } + /* No two 128-bit buffers should be the same + (again, statistically this could happen but it's very unlikely) */ + for (int i = 0; i < NUM_BUF; i++) { + for (int j = 0; j < NUM_BUF; j++) { + if (i != j) { + TEST_ASSERT_NOT_EQUAL(0, memcmp(buf[i], buf[j], BUF_SZ)); + } + } + } + + /* Do the same all bits are zero and one at least once test across the buffers */ + for (int i = 0; i < NUM_BUF; i++) { + for (int x = 0; x < BUF_SZ; x++) { + zero_buf[x] &= ~buf[i][x]; + one_buf[x] |= buf[i][x]; + } + } + for (int x = 0; x < BUF_SZ; x++) { + TEST_ASSERT_EQUAL_HEX8(0, zero_buf[x]); + TEST_ASSERT_EQUAL_HEX8(0xFF, one_buf[x]); + } +} diff --git a/tools/ci/config/target-test.yml b/tools/ci/config/target-test.yml index ba088a3979..1ec77eac65 100644 --- a/tools/ci/config/target-test.yml +++ b/tools/ci/config/target-test.yml @@ -539,7 +539,7 @@ UT_034: UT_035: extends: .unit_test_s2_template - parallel: 36 + parallel: 38 tags: - ESP32S2_IDF - UT_T1_1 From 2ccdd7eb101ec80310ac1a8727195bc6eaf09809 Mon Sep 17 00:00:00 2001 From: morris Date: Wed, 3 Jun 2020 13:15:37 +0800 Subject: [PATCH 3/3] intr_alloc: using isr version of critical section --- components/esp32s2/intr_alloc.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/components/esp32s2/intr_alloc.c b/components/esp32s2/intr_alloc.c index ce13d7b9b4..066472744e 100644 --- a/components/esp32s2/intr_alloc.c +++ b/components/esp32s2/intr_alloc.c @@ -116,7 +116,7 @@ const static int_desc_t int_desc[32]={ { 3, INTTP_LEVEL, {INTDESC_NORMAL, INTDESC_NORMAL} }, //23 { 4, INTTP_LEVEL, {INTDESC_RESVD, INTDESC_NORMAL} }, //24 { 4, INTTP_LEVEL, {INTDESC_RESVD, INTDESC_RESVD } }, //25 - { 5, INTTP_LEVEL, {INTDESC_RESVD, INTDESC_RESVD } }, //26 + { 5, INTTP_LEVEL, {INTDESC_NORMAL, INTDESC_RESVD } }, //26 { 3, INTTP_LEVEL, {INTDESC_RESVD, INTDESC_RESVD } }, //27 { 4, INTTP_EDGE, {INTDESC_NORMAL, INTDESC_NORMAL} }, //28 { 3, INTTP_NA, {INTDESC_SPECIAL,INTDESC_SPECIAL}}, //29 @@ -487,7 +487,7 @@ static void IRAM_ATTR shared_intr_isr(void *arg) { vector_desc_t *vd=(vector_desc_t*)arg; shared_vector_desc_t *sh_vec=vd->shared_vec_info; - portENTER_CRITICAL(&spinlock); + portENTER_CRITICAL_ISR(&spinlock); while(sh_vec) { if (!sh_vec->disabled) { if ((sh_vec->statusreg == NULL) || (*sh_vec->statusreg & sh_vec->statusmask)) { @@ -505,7 +505,7 @@ static void IRAM_ATTR shared_intr_isr(void *arg) } sh_vec=sh_vec->next; } - portEXIT_CRITICAL(&spinlock); + portEXIT_CRITICAL_ISR(&spinlock); } #if CONFIG_SYSVIEW_ENABLE @@ -513,7 +513,7 @@ static void IRAM_ATTR shared_intr_isr(void *arg) static void IRAM_ATTR non_shared_intr_isr(void *arg) { non_shared_isr_arg_t *ns_isr_arg=(non_shared_isr_arg_t*)arg; - portENTER_CRITICAL(&spinlock); + portENTER_CRITICAL_ISR(&spinlock); traceISR_ENTER(ns_isr_arg->source+ETS_INTERNAL_INTR_SOURCE_OFF); // FIXME: can we call ISR and check port_switch_flag after releasing spinlock? // when CONFIG_SYSVIEW_ENABLE = 0 ISRs for non-shared IRQs are called without spinlock @@ -522,7 +522,7 @@ static void IRAM_ATTR non_shared_intr_isr(void *arg) if (!port_switch_flag[xPortGetCoreID()]) { traceISR_EXIT(); } - portEXIT_CRITICAL(&spinlock); + portEXIT_CRITICAL_ISR(&spinlock); } #endif @@ -729,11 +729,11 @@ esp_err_t esp_intr_free(intr_handle_t handle) } //If nothing left, disable interrupt. if (handle->vector_desc->shared_vec_info==NULL) free_shared_vector=true; - ESP_LOGV(TAG, "esp_intr_free: Deleting shared int: %s. Shared int is %s", svd?"not found or last one":"deleted", free_shared_vector?"empty now.":"still in use"); + ESP_EARLY_LOGV(TAG, "esp_intr_free: Deleting shared int: %s. Shared int is %s", svd?"not found or last one":"deleted", free_shared_vector?"empty now.":"still in use"); } if ((handle->vector_desc->flags&VECDESC_FL_NONSHARED) || free_shared_vector) { - ESP_LOGV(TAG, "esp_intr_free: Disabling int, killing handler"); + ESP_EARLY_LOGV(TAG, "esp_intr_free: Disabling int, killing handler"); #if CONFIG_SYSVIEW_ENABLE if (!free_shared_vector) { void *isr_arg = xt_get_interrupt_handler_arg(handle->vector_desc->intno);