diff options
| author | Frédéric Desbiens <[email protected]> | 2026-06-08 10:01:32 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2026-06-08 10:01:32 +0200 |
| commit | 87ab09cce305eb9cd4aacac4e8c62af72f665bff (patch) | |
| tree | dd062ebbea5235d1921c64b396bf7e4ce79e9e15 /test/tx/regression/threadx_byte_memory_basic_test.c | |
| parent | 9ab0cf9683f832cdb48e2099533a5b06a3afcd64 (diff) | |
| parent | 730b61874bc5cf40768987605ae5187fde0fa1e2 (diff) | |
Merge pull request #544 from eclipse-threadx/devv6.5.1.202602_rel
Merging changes for the v.6.5.1.202602 release
Diffstat (limited to 'test/tx/regression/threadx_byte_memory_basic_test.c')
| -rw-r--r-- | test/tx/regression/threadx_byte_memory_basic_test.c | 56 |
1 files changed, 38 insertions, 18 deletions
diff --git a/test/tx/regression/threadx_byte_memory_basic_test.c b/test/tx/regression/threadx_byte_memory_basic_test.c index 36f41331..45f92e12 100644 --- a/test/tx/regression/threadx_byte_memory_basic_test.c +++ b/test/tx/regression/threadx_byte_memory_basic_test.c @@ -1,8 +1,29 @@ +/***************************************************************************/ +/* Copyright (c) 2024 Microsoft Corporation */ +/* Copyright (c) 2026 Eclipse ThreadX contributors */ +/* */ +/* This program and the accompanying materials are made available under */ +/* the terms of the MIT License which is available at */ +/* https://opensource.org/licenses/MIT. */ +/* */ +/* SPDX-License-Identifier: MIT */ +/***************************************************************************/ + /* This test is designed to test simple memory byte pool creation, deletion, and allocates and releases. */ #include <stdio.h> #include "tx_api.h" +#include "threadx_test_port.h" + +/* Per-allocation overhead in byte pools: next pointer + ALIGN_TYPE alignment marker. */ +#define BYTE_POOL_OVERHEAD (sizeof(UCHAR *) + sizeof(ALIGN_TYPE)) + +/* Pool size for pool_0: exactly fits 3 allocations of 24 bytes with no room for a 4th. */ +#define POOL_0_SIZE (ULONG)(3u * (24u + BYTE_POOL_OVERHEAD) + BYTE_POOL_OVERHEAD) + +/* Pool size for pool_4: must accommodate 3 allocations of 84 bytes (tightest pattern). */ +#define POOL_4_SIZE (ULONG)(3u * (84u + BYTE_POOL_OVERHEAD) + BYTE_POOL_OVERHEAD + 16u) typedef struct BYTE_MEMORY_TEST_STRUCT { @@ -91,7 +112,7 @@ CHAR *pointer; /* Attempt to create a byte pool from a timer. */ pointer = (CHAR *) 0x30000; - status = tx_byte_pool_create(&pool_2, "pool 2", pointer, 108); + status = tx_byte_pool_create(&pool_2, "pool 2", pointer, TX_TEST_BYTE_POOL_BYTES(108)); /* Check status. */ if (status != TX_CALLER_ERROR) @@ -103,7 +124,7 @@ CHAR *pointer; /* Attempt to create a byte pool with an invalid size. */ status = _txe_byte_pool_create(&pool_3, "pool 3", pointer, - 108, (sizeof(TX_BYTE_POOL)+1)); + TX_TEST_BYTE_POOL_BYTES(108), (sizeof(TX_BYTE_POOL)+1)); /* Check status. */ if (status != TX_POOL_ERROR) @@ -186,7 +207,7 @@ UINT status; /* Attempt to create a byte pool from an ISR. */ - status = tx_byte_pool_create(&pool_2, "pool 0", (void *) 0x100000, 108); + status = tx_byte_pool_create(&pool_2, "pool 0", (void *) 0x100000, TX_TEST_BYTE_POOL_BYTES(108)); /* Check status. */ if (status != TX_CALLER_ERROR) @@ -256,8 +277,8 @@ CHAR *pointer; } /* Create byte pools 0 and 1. */ - status = tx_byte_pool_create(&pool_0, "pool 0", pointer, 108); - pointer = pointer + 108; + status = tx_byte_pool_create(&pool_0, "pool 0", pointer, TX_TEST_BYTE_POOL_CAPACITY_BYTES(24, 3)); + pointer = pointer + TX_TEST_BYTE_POOL_CAPACITY_BYTES(24, 3); /* Check status. */ if (status != TX_SUCCESS) @@ -267,8 +288,8 @@ CHAR *pointer; test_control_return(1); } - status = tx_byte_pool_create(&pool_1, "pool 1", pointer, 200); - pointer = pointer + 200; + status = tx_byte_pool_create(&pool_1, "pool 1", pointer, TX_TEST_BYTE_POOL_BYTES(200)); + pointer = pointer + TX_TEST_BYTE_POOL_BYTES(200); /* Check status. */ if (status != TX_SUCCESS) @@ -279,9 +300,9 @@ CHAR *pointer; } /* Test for search pointer issue on wrapped seach with prior block to search pointer merged. */ - status = tx_byte_pool_create(&pool_4, "pool 4", pointer, 300); + status = tx_byte_pool_create(&pool_4, "pool 4", pointer, TX_TEST_BYTE_POOL_CAPACITY_BYTES(84, 3)); pool_4_memory = pointer; - pointer = pointer + 300; + pointer = pointer + TX_TEST_BYTE_POOL_CAPACITY_BYTES(84, 3); /* Check status. */ if (status != TX_SUCCESS) @@ -353,7 +374,7 @@ CHAR *pointer_2; CHAR *pointer_3; CHAR *pointer_4; INT i; -ULONG array[20]; +TX_TEST_POINTER_WORD array[20]; UCHAR *save_search; @@ -394,7 +415,7 @@ UCHAR *save_search; /* Try to create a NULL pool. */ pointer_1 = (CHAR *) 0x30000; - status = tx_byte_pool_create(TX_NULL, "pool 0", pointer_1, 108); + status = tx_byte_pool_create(TX_NULL, "pool 0", pointer_1, TX_TEST_BYTE_POOL_BYTES(108)); /* Check status. */ if (status != TX_POOL_ERROR) @@ -406,7 +427,7 @@ UCHAR *save_search; } /* Try to create the same pool. */ - status = tx_byte_pool_create(&pool_0, "pool 0", pointer_1, 108); + status = tx_byte_pool_create(&pool_0, "pool 0", pointer_1, TX_TEST_BYTE_POOL_BYTES(108)); /* Check status. */ if (status != TX_POOL_ERROR) @@ -418,7 +439,7 @@ UCHAR *save_search; } /* Try to create a pool with a NULL start address. */ - status = tx_byte_pool_create(&pool_2, "pool 2", TX_NULL, 108); + status = tx_byte_pool_create(&pool_2, "pool 2", TX_NULL, TX_TEST_BYTE_POOL_BYTES(108)); /* Check status. */ if (status != TX_PTR_ERROR) @@ -626,7 +647,7 @@ UCHAR *save_search; /* Test another bad block release.... pool pointer is not a valid pool! */ array[0] = 0; - array[1] = (ULONG) &array[3]; + TX_TEST_STORE_POINTER(array[1], &array[3]); array[2] = 0; array[3] = 0; status = _tx_byte_release(&array[2]); @@ -865,7 +886,7 @@ UCHAR *save_search; } /* Move the search pointer to the third block to exercise that code in the byte search algorithm. */ - pool_0.tx_byte_pool_search = (UCHAR *) pointer_3-8; + pool_0.tx_byte_pool_search = (UCHAR *) pointer_3 - TX_TEST_BYTE_POOL_SEARCH_OFFSET; /* Now allocate the block again. */ status = tx_byte_allocate(&pool_0, (VOID **) &pointer_2, 24, TX_NO_WAIT); @@ -885,7 +906,7 @@ UCHAR *save_search; status += tx_byte_release(pointer_1); /* Move the search pointer to the third block to exercise that code in the byte search algorithm. */ - pool_0.tx_byte_pool_search = (UCHAR *) pointer_3-8; + pool_0.tx_byte_pool_search = (UCHAR *) pointer_3 - TX_TEST_BYTE_POOL_SEARCH_OFFSET; /* Allocate a large block to force the search pointer update. */ status = tx_byte_allocate(&pool_0, (VOID **) &pointer_3, 88, TX_NO_WAIT); @@ -961,7 +982,7 @@ UCHAR *save_search; } /* Create pool 4. */ - status = tx_byte_pool_create(&pool_4, "pool 4", pool_4_memory, 300); + status = tx_byte_pool_create(&pool_4, "pool 4", pool_4_memory, TX_TEST_BYTE_POOL_CAPACITY_BYTES(84, 3)); /* Check status. */ if (status != TX_SUCCESS) @@ -1061,4 +1082,3 @@ UCHAR *save_search; printf("SUCCESS!\n"); test_control_return(0); } - |
