Skip to content

Commit 97ae78e

Browse files
committed
test(heap): fixed align_alloc issues in host test
1 parent b3f5251 commit 97ae78e

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

components/heap/test_apps/host_test_linux/main/test_heap_linux.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2022-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -50,7 +50,7 @@ TEST_CASE("Alloc APIs", "[heap]")
5050

5151
TEST_CASE("Size APIs", "[heap]")
5252
{
53-
/* These functions doesnt provide any useful information on linux
53+
/* These functions doesn't provide any useful information on linux
5454
These "tests" are simply included to check that all the functions in the header
5555
are actually mocked
5656
*/
@@ -71,21 +71,22 @@ TEST_CASE("Size APIs", "[heap]")
7171
TEST_ASSERT_TRUE(heap_caps_get_allocated_size(&info) == 0);
7272
}
7373

74-
#define TEST_ALIGNMENT 0x1F
74+
#define TEST_ALIGNMENT 0x20
7575

7676
TEST_CASE("Aligned alloc APIs", "[heap]")
7777
{
78-
uint8_t * p = heap_caps_aligned_alloc(TEST_ALIGNMENT, MALLOC_LEN, MALLOC_CAP_DEFAULT);
78+
const int aligned_len = MALLOC_LEN - (MALLOC_LEN % TEST_ALIGNMENT);
79+
uint8_t * p = heap_caps_aligned_alloc(TEST_ALIGNMENT, aligned_len, MALLOC_CAP_DEFAULT);
7980
TEST_ASSERT_NOT_NULL(p);
8081
TEST_ASSERT_TRUE(((intptr_t)p & (0x1F -1)) == 0);
81-
memset(p, TEST_VAL, MALLOC_LEN);
82-
TEST_ASSERT_EACH_EQUAL_HEX8(TEST_VAL, p, MALLOC_LEN);
82+
memset(p, TEST_VAL, aligned_len);
83+
TEST_ASSERT_EACH_EQUAL_HEX8(TEST_VAL, p, aligned_len);
8384
heap_caps_free(p);
8485

85-
p = heap_caps_aligned_calloc(TEST_ALIGNMENT, MALLOC_LEN, sizeof(uint8_t), MALLOC_CAP_DEFAULT);
86+
p = heap_caps_aligned_calloc(TEST_ALIGNMENT, aligned_len, sizeof(uint8_t), MALLOC_CAP_DEFAULT);
8687
TEST_ASSERT_NOT_NULL(p);
8788
TEST_ASSERT_TRUE(((intptr_t)p & (0x1F -1)) == 0);
88-
TEST_ASSERT_EACH_EQUAL_HEX8(0, p, MALLOC_LEN);
89+
TEST_ASSERT_EACH_EQUAL_HEX8(0, p, aligned_len);
8990
heap_caps_free(p);
9091
}
9192

0 commit comments

Comments
 (0)