-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/heap_pytest' into 'master'
heap: move unit tests to pytest Closes IDF-5591 See merge request espressif/esp-idf!20229
- Loading branch information
Showing
50 changed files
with
248 additions
and
63 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# The following lines of boilerplate have to be in your project's | ||
# CMakeLists in this exact order for cmake to work correctly | ||
cmake_minimum_required(VERSION 3.16) | ||
|
||
include($ENV{IDF_PATH}/tools/cmake/project.cmake) | ||
project(test_heap) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
| Supported Targets | ESP32 | ESP32-C2 | ESP32-C3 | ESP32-S2 | ESP32-S3 | | ||
| ----------------- | ----- | -------- | -------- | -------- | -------- | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
set(src_test "test_app_main.c" | ||
"test_aligned_alloc_caps.c" | ||
"test_allocator_timings.c" | ||
"test_corruption_check.c" | ||
"test_diram.c" | ||
"test_heap_trace.c" | ||
"test_malloc_caps.c" | ||
"test_malloc.c" | ||
"test_realloc.c" | ||
"test_runtime_heap_reg.c") | ||
|
||
idf_component_register(SRCS ${src_test} | ||
INCLUDE_DIRS "." | ||
WHOLE_ARCHIVE) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
#include "unity.h" | ||
#include "unity_test_runner.h" | ||
#include "esp_heap_caps.h" | ||
|
||
#define TEST_MEMORY_LEAK_THRESHOLD (-1024) | ||
|
||
static size_t before_free_8bit; | ||
static size_t before_free_32bit; | ||
|
||
static void check_leak(size_t before_free, size_t after_free, const char *type) | ||
{ | ||
ssize_t delta = after_free - before_free; | ||
printf("MALLOC_CAP_%s: Before %u bytes free, After %u bytes free (delta %d)\n", type, before_free, after_free, delta); | ||
TEST_ASSERT_MESSAGE(delta >= TEST_MEMORY_LEAK_THRESHOLD, "memory leak"); | ||
} | ||
|
||
void setUp(void) | ||
{ | ||
before_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); | ||
before_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); | ||
} | ||
|
||
void tearDown(void) | ||
{ | ||
size_t after_free_8bit = heap_caps_get_free_size(MALLOC_CAP_8BIT); | ||
size_t after_free_32bit = heap_caps_get_free_size(MALLOC_CAP_32BIT); | ||
check_leak(before_free_8bit, after_free_8bit, "8BIT"); | ||
check_leak(before_free_32bit, after_free_32bit, "32BIT"); | ||
} | ||
|
||
void app_main(void) | ||
{ | ||
printf("Running heap component tests\n"); | ||
unity_run_menu(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
components/heap/test/test_heap_trace.c → ...nts/heap/test_apps/main/test_heap_trace.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
components/heap/test/test_malloc.c → components/heap/test_apps/main/test_malloc.c
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# SPDX-FileCopyrightText: 2022 Espressif Systems (Shanghai) CO LTD | ||
# SPDX-License-Identifier: CC0-1.0 | ||
|
||
import pytest | ||
from pytest_embedded import Dut | ||
|
||
|
||
@pytest.mark.generic | ||
@pytest.mark.supported_targets | ||
@pytest.mark.parametrize( | ||
'config', | ||
[ | ||
'no_poisoning', | ||
'light_poisoning', | ||
'comprehensive_poisoning' | ||
] | ||
) | ||
def test_heap_poisoning(dut: Dut) -> None: | ||
dut.expect_exact('Press ENTER to see the list of tests') | ||
dut.write('![ignore]') | ||
dut.expect_unity_test_output(timeout=300) | ||
|
||
|
||
@pytest.mark.generic | ||
@pytest.mark.esp32 | ||
@pytest.mark.esp32s2 | ||
@pytest.mark.esp32s3 | ||
@pytest.mark.parametrize( | ||
'config', | ||
[ | ||
'psram', | ||
'psram_all_ext' | ||
] | ||
) | ||
def test_heap(dut: Dut) -> None: | ||
dut.expect_exact('Press ENTER to see the list of tests') | ||
dut.write('![ignore]') | ||
dut.expect_unity_test_output(timeout=300) | ||
|
||
|
||
@pytest.mark.generic | ||
@pytest.mark.esp32 | ||
@pytest.mark.parametrize( | ||
'config', | ||
[ | ||
'abort_alloc_fail' | ||
] | ||
) | ||
def test_heap_abort_on_alloc_failure(dut: Dut) -> None: | ||
dut.expect_exact('Press ENTER to see the list of tests') | ||
dut.write('"When enabled, allocation operation failure generates an abort"') | ||
dut.expect('Backtrace: ') | ||
|
||
|
||
@pytest.mark.generic | ||
@pytest.mark.esp32 | ||
@pytest.mark.parametrize( | ||
'config', | ||
[ | ||
'8bit_access' | ||
] | ||
) | ||
def test_heap_8bit_access(dut: Dut) -> None: | ||
dut.expect_exact('Press ENTER to see the list of tests') | ||
dut.write('"IRAM_8BIT capability test"') | ||
dut.expect_unity_test_output(timeout=300) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
CONFIG_FREERTOS_UNICORE=y | ||
CONFIG_ESP32_IRAM_AS_8BIT_ACCESSIBLE_MEMORY=y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
CONFIG_HEAP_ABORT_WHEN_ALLOCATION_FAILS=y |
Oops, something went wrong.