From 4868094fbfdfa5e149a2884560a957973e4c1115 Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Sat, 19 Dec 2020 00:26:56 +0100 Subject: [PATCH] tests/memarray: add extend/reduce tests --- tests/memarray/Makefile.ci | 4 +++ tests/memarray/main.c | 47 ++++++++++++++++++++++++++++++++-- tests/memarray/tests/01-run.py | 14 ++++++++++ 3 files changed, 63 insertions(+), 2 deletions(-) diff --git a/tests/memarray/Makefile.ci b/tests/memarray/Makefile.ci index b9ff275375..ff454e3604 100644 --- a/tests/memarray/Makefile.ci +++ b/tests/memarray/Makefile.ci @@ -1,3 +1,7 @@ BOARD_INSUFFICIENT_MEMORY := \ + arduino-duemilanove \ + arduino-nano \ + arduino-uno \ + atmega328p \ nucleo-l011k4 \ # diff --git a/tests/memarray/main.c b/tests/memarray/main.c index b2d9140d88..a9507552bd 100644 --- a/tests/memarray/main.c +++ b/tests/memarray/main.c @@ -32,11 +32,11 @@ #endif #ifndef NUMBER_OF_TESTS -#define NUMBER_OF_TESTS (12) +#define NUMBER_OF_TESTS (1) #endif #ifndef NUMBER_OF_LOOPS -#define NUMBER_OF_LOOPS (2) +#define NUMBER_OF_LOOPS (1) #endif @@ -50,6 +50,7 @@ struct block_t { }; struct block_t block_storage_data[MAX_NUMBER_BLOCKS]; +struct block_t block_storage_data_extend[MAX_NUMBER_BLOCKS]; memarray_t block_storage; int total = 0; @@ -141,6 +142,48 @@ int main(void) count++; } + puts("Extend and reduce tests"); + + printf("Memarray available: %u\n", + (unsigned)memarray_available(&block_storage)); + + /* Extend with second block */ + memarray_extend(&block_storage, block_storage_data_extend, + MAX_NUMBER_BLOCKS); + printf("Memarray available: %u\n", + (unsigned)memarray_available(&block_storage)); + + /* remove the original block */ + int res = memarray_reduce(&block_storage, block_storage_data, + MAX_NUMBER_BLOCKS); + printf("Memarray reduction: %d available: %u\n", + res, (unsigned)memarray_available(&block_storage)); + + /* try to remove original block a second time */ + res = memarray_reduce(&block_storage, block_storage_data, + MAX_NUMBER_BLOCKS); + printf("Memarray reduction: %d available: %u\n", + res, (unsigned)memarray_available(&block_storage)); + + /* remove the extension block */ + res = memarray_reduce(&block_storage, block_storage_data_extend, + MAX_NUMBER_BLOCKS); + printf("Memarray reduction: %d available: %u\n", + res, (unsigned)memarray_available(&block_storage)); + + /* extend again with the original block */ + memarray_extend(&block_storage, block_storage_data, MAX_NUMBER_BLOCKS); + + /* remove one element */ + memarray_alloc(&block_storage); + printf("Memarray available: %u\n", + (unsigned)memarray_available(&block_storage)); + + /* try to reduce with a missing element */ + res = memarray_reduce(&block_storage, block_storage_data, MAX_NUMBER_BLOCKS); + printf("Memarray reduction: %d available: %u\n", + res, (unsigned)memarray_available(&block_storage)); + printf("Finishing\n"); _ps_handler(0, NULL); diff --git a/tests/memarray/tests/01-run.py b/tests/memarray/tests/01-run.py index 7ab78eccb6..68de6a6848 100755 --- a/tests/memarray/tests/01-run.py +++ b/tests/memarray/tests/01-run.py @@ -27,6 +27,20 @@ def testfunc(child): for i in range(max_number_blocks): child.expect(r'Free \({}\) \d+ Bytes at 0x[a-z0-9]+,' ' total [0-9]+\r\n'.format(i)) + + child.expect_exact("Extend and reduce tests") + + child.expect_exact("Memarray available: {}".format(max_number_blocks)) + child.expect_exact("Memarray available: {}".format(2 * max_number_blocks)) + child.expect_exact("Memarray reduction: 0 available: {}" + "".format(max_number_blocks)) + child.expect_exact("Memarray reduction: -1 available: {}" + "".format(max_number_blocks)) + child.expect_exact("Memarray reduction: 0 available: 0") + child.expect_exact("Memarray available: {}".format(max_number_blocks - 1)) + child.expect_exact("Memarray reduction: -1 available: {}" + "".format(max_number_blocks - 1)) + child.expect_exact("Finishing")