mirror of
https://github.com/espressif/esp-idf.git
synced 2025-09-23 01:05:14 +00:00
add unit tests to esp-idf
rename nvs host test folder, modify .gitlab-ci.yml remove unit-test-app build re-format unit test files remove extra newlines in project.mk some refactoring for unit test part in project.mk add build files of unit-test-app in gitignore add README.md for unit test app correct headings in README.md remove files and make minor tweaks in unit test app update .gitlab-ci.yml to use unit test app delete unused lines in component_wrapper.mk delete periph_i2s.h and lcd test add text floating point in components/esp32/test/Kconfig correct idf test build paths in .gitlab-ci.yml
This commit is contained in:
77
components/esp32/test/test_miniz.c
Normal file
77
components/esp32/test/test_miniz.c
Normal file
@@ -0,0 +1,77 @@
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include "rom/miniz.h"
|
||||
#include "unity.h"
|
||||
|
||||
|
||||
#define DATASIZE (1024*64)
|
||||
|
||||
TEST_CASE("Test miniz compression/decompression", "[miniz]")
|
||||
{
|
||||
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);
|
||||
}
|
Reference in New Issue
Block a user