mirror of
https://github.com/MaJerle/lwmem.git
synced 2025-01-26 06:02:54 +08:00
Merge branch 'develop'
This commit is contained in:
commit
17504781da
@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## Develop
|
## Develop
|
||||||
|
|
||||||
|
## v2.2.1
|
||||||
|
|
||||||
|
- Fix the wrong variable to reduce the size of the region in case of unaligned address or size
|
||||||
|
|
||||||
## v2.2.0
|
## v2.2.0
|
||||||
|
|
||||||
- Rework library CMake with removed INTERFACE type
|
- Rework library CMake with removed INTERFACE type
|
||||||
|
@ -11,6 +11,7 @@ else()
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp
|
${CMAKE_CURRENT_LIST_DIR}/dev/main.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c
|
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test.c
|
||||||
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test_simple.c
|
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test_simple.c
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/tests/lwmem_test_region.c
|
||||||
|
|
||||||
# win32 port
|
# win32 port
|
||||||
${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c
|
${CMAKE_CURRENT_LIST_DIR}/lwmem/src/system/lwmem_sys_win32.c
|
||||||
|
@ -45,6 +45,6 @@
|
|||||||
#define LWMEM_CFG_OS_MUTEX_HANDLE HANDLE
|
#define LWMEM_CFG_OS_MUTEX_HANDLE HANDLE
|
||||||
#define LWMEM_CFG_ENABLE_STATS 0
|
#define LWMEM_CFG_ENABLE_STATS 0
|
||||||
#define LWMEM_CFG_CLEAN_MEMORY 1
|
#define LWMEM_CFG_CLEAN_MEMORY 1
|
||||||
#define LWMEM_CFG_FULL 0
|
#define LWMEM_CFG_FULL 1
|
||||||
|
|
||||||
#endif /* LWMEM_HDR_OPTS_H */
|
#endif /* LWMEM_HDR_OPTS_H */
|
||||||
|
@ -7,12 +7,15 @@
|
|||||||
extern "C" void lwmem_test_run(void);
|
extern "C" void lwmem_test_run(void);
|
||||||
extern "C" void lwmem_test_simple_run(void);
|
extern "C" void lwmem_test_simple_run(void);
|
||||||
extern "C" void lwmem_test_memory_structure(void);
|
extern "C" void lwmem_test_memory_structure(void);
|
||||||
|
extern "C" void lwmem_test_region(void);
|
||||||
|
|
||||||
/* Setup manager */
|
/* Setup manager */
|
||||||
static Lwmem::LwmemLight<1024> manager;
|
static Lwmem::LwmemLight<1024> manager;
|
||||||
|
|
||||||
int
|
int
|
||||||
main(void) {
|
main(void) {
|
||||||
|
lwmem_test_region();
|
||||||
|
return 0;
|
||||||
#if LWMEM_CFG_FULL
|
#if LWMEM_CFG_FULL
|
||||||
lwmem_test_memory_structure();
|
lwmem_test_memory_structure();
|
||||||
//lwmem_test_run();
|
//lwmem_test_run();
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "LwMEM",
|
"name": "LwMEM",
|
||||||
"version": "2.2.0",
|
"version": "2.2.1",
|
||||||
"description": "Lightweight dynamic memory manager optimized for embedded systems",
|
"description": "Lightweight dynamic memory manager optimized for embedded systems",
|
||||||
"keywords": "lwmem, memory, dynamic, heap, malloc, calloc, realloc, free, lightweight, manager, embedded, stm32, win32",
|
"keywords": "lwmem, memory, dynamic, heap, malloc, calloc, realloc, free, lightweight, manager, embedded, stm32, win32",
|
||||||
"repository": {
|
"repository": {
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#ifndef LWMEM_HDR_H
|
#ifndef LWMEM_HDR_H
|
||||||
#define LWMEM_HDR_H
|
#define LWMEM_HDR_H
|
||||||
@ -144,8 +144,9 @@ size_t lwmem_get_size(void* ptr);
|
|||||||
unsigned char lwmem_debug_create_regions(lwmem_region_t** regs_out, size_t count, size_t size);
|
unsigned char lwmem_debug_create_regions(lwmem_region_t** regs_out, size_t count, size_t size);
|
||||||
void lwmem_debug_save_state(void);
|
void lwmem_debug_save_state(void);
|
||||||
void lwmem_debug_restore_to_saved(void);
|
void lwmem_debug_restore_to_saved(void);
|
||||||
|
|
||||||
void lwmem_debug_print(unsigned char print_alloc, unsigned char print_free);
|
void lwmem_debug_print(unsigned char print_alloc, unsigned char print_free);
|
||||||
|
void lwmem_debug_test_region(void* region_start, size_t region_size, uint8_t** region_start_calc,
|
||||||
|
size_t* region_size_calc);
|
||||||
#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */
|
#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#ifndef LWMEM_HDR_HPP
|
#ifndef LWMEM_HDR_HPP
|
||||||
#define LWMEM_HDR_HPP
|
#define LWMEM_HDR_HPP
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#ifndef LWMEM_OPT_HDR_H
|
#ifndef LWMEM_OPT_HDR_H
|
||||||
#define LWMEM_OPT_HDR_H
|
#define LWMEM_OPT_HDR_H
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#ifndef LWMEM_OPTS_HDR_H
|
#ifndef LWMEM_OPTS_HDR_H
|
||||||
#define LWMEM_OPTS_HDR_H
|
#define LWMEM_OPTS_HDR_H
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#ifndef LWMEM_SYS_HDR_H
|
#ifndef LWMEM_SYS_HDR_H
|
||||||
#define LWMEM_SYS_HDR_H
|
#define LWMEM_SYS_HDR_H
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#include "lwmem/lwmem.h"
|
#include "lwmem/lwmem.h"
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
@ -206,7 +206,7 @@ prv_get_region_addr_size(const lwmem_region_t* region, uint8_t** msa, size_t* ms
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Check region size and align it to config bits */
|
/* Check region size and align it to config bits */
|
||||||
mem_size = region->size & ~LWMEM_ALIGN_BITS; /* Size does not include lower bits */
|
mem_size &= ~LWMEM_ALIGN_BITS; /* Align the size to lower bits */
|
||||||
if (mem_size < (2 * LWMEM_BLOCK_MIN_SIZE)) {
|
if (mem_size < (2 * LWMEM_BLOCK_MIN_SIZE)) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -1427,4 +1427,13 @@ lwmem_debug_restore_to_saved(void) {
|
|||||||
printf(" -- > State restored to last saved!\r\n");
|
printf(" -- > State restored to last saved!\r\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
lwmem_debug_test_region(void* region_start, size_t region_size, uint8_t** region_start_calc, size_t* region_size_calc) {
|
||||||
|
lwmem_region_t region = {
|
||||||
|
.start_addr = region_start,
|
||||||
|
.size = region_size,
|
||||||
|
};
|
||||||
|
prv_get_region_addr_size(®ion, region_start_calc, region_size_calc);
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */
|
#endif /* defined(LWMEM_DEV) && !__DOXYGEN__ */
|
||||||
|
@ -29,5 +29,5 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#include "system/lwmem_sys.h"
|
#include "system/lwmem_sys.h"
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#include "system/lwmem_sys.h"
|
#include "system/lwmem_sys.h"
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
* This file is part of LwMEM - Lightweight dynamic memory manager library.
|
||||||
*
|
*
|
||||||
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
* Author: Tilen MAJERLE <tilen@majerle.eu>
|
||||||
* Version: v2.2.0
|
* Version: v2.2.1
|
||||||
*/
|
*/
|
||||||
#include "system/lwmem_sys.h"
|
#include "system/lwmem_sys.h"
|
||||||
|
|
||||||
|
82
tests/lwmem_test_region.c
Normal file
82
tests/lwmem_test_region.c
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
#include <stdio.h>
|
||||||
|
#include "lwmem/lwmem.h"
|
||||||
|
|
||||||
|
#if LWMEM_CFG_ALIGN_NUM != 4
|
||||||
|
#error "Test shall run with LWMEM_CFG_ALIGN_NUM == 4"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Test assert information */
|
||||||
|
#define TEST_ASSERT(condition) \
|
||||||
|
do { \
|
||||||
|
if (!(condition)) { \
|
||||||
|
printf("Assert failed on the line %d\r\n", __LINE__); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
uint8_t* region_start;
|
||||||
|
size_t region_size;
|
||||||
|
uint8_t* region_start_exp;
|
||||||
|
size_t region_size_exp;
|
||||||
|
} test_region_t;
|
||||||
|
|
||||||
|
#define TEST_ENTRY(_region_start_, _region_size_, _region_start_exp_, _region_size_exp_) \
|
||||||
|
{ \
|
||||||
|
.region_start = (void*)(_region_start_), \
|
||||||
|
.region_size = (_region_size_), \
|
||||||
|
.region_start_exp = (void*)(_region_start_exp_), \
|
||||||
|
.region_size_exp = (_region_size_exp_), \
|
||||||
|
}
|
||||||
|
|
||||||
|
/* List of test cases */
|
||||||
|
static const test_region_t test_cases[] = {
|
||||||
|
TEST_ENTRY(0x00000000, 0x00000000, 0x00000000, 0x00000000),
|
||||||
|
TEST_ENTRY(0x00000000, 0x00004000, 0x00000000, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000000, 0x00004001, 0x00000000, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000000, 0x00004002, 0x00000000, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000000, 0x00004003, 0x00000000, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000000, 0x00004004, 0x00000000, 0x00004004),
|
||||||
|
TEST_ENTRY(0x00000000, 0x00004005, 0x00000000, 0x00004004),
|
||||||
|
|
||||||
|
/* Start is not always aligned, but length input is aligned */
|
||||||
|
TEST_ENTRY(0x00000000, 0x00004000, 0x00000000, 0x00004000),
|
||||||
|
|
||||||
|
/* Start must advance to next aligned value, size reduced to next lower aligned value */
|
||||||
|
TEST_ENTRY(0x00000001, 0x00004000, 0x00000004, 0x00003FFC),
|
||||||
|
TEST_ENTRY(0x00000002, 0x00004000, 0x00000004, 0x00003FFC),
|
||||||
|
TEST_ENTRY(0x00000003, 0x00004000, 0x00000004, 0x00003FFC),
|
||||||
|
TEST_ENTRY(0x00000003, 0x00004003, 0x00000004, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000003, 0x00004004, 0x00000004, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000003, 0x00004005, 0x00000004, 0x00004004),
|
||||||
|
TEST_ENTRY(0x00000001, 0x00004003, 0x00000004, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000002, 0x00004005, 0x00000004, 0x00004000),
|
||||||
|
TEST_ENTRY(0x00000002, 0x00004006, 0x00000004, 0x00004004),
|
||||||
|
TEST_ENTRY(0x00000002, 0x00004007, 0x00000004, 0x00004004),
|
||||||
|
TEST_ENTRY(0x00000003, 0x00004006, 0x00000004, 0x00004004),
|
||||||
|
TEST_ENTRY(0x00000003, 0x00004005, 0x00000004, 0x00004004),
|
||||||
|
TEST_ENTRY(0x00000004, 0x00004006, 0x00000004, 0x00004004),
|
||||||
|
};
|
||||||
|
|
||||||
|
/* Start is aligned, length is not always aligned */
|
||||||
|
|
||||||
|
void
|
||||||
|
lwmem_test_region(void) {
|
||||||
|
uint8_t* region_start = NULL;
|
||||||
|
size_t region_size = 0;
|
||||||
|
|
||||||
|
for (size_t idx = 0; idx < sizeof(test_cases) / sizeof(test_cases[0]); ++idx) {
|
||||||
|
const test_region_t* test = &test_cases[idx];
|
||||||
|
lwmem_debug_test_region(test->region_start, test->region_size, ®ion_start, ®ion_size);
|
||||||
|
|
||||||
|
if (region_start != test->region_start_exp) {
|
||||||
|
printf("Region start test failed. Idx: %u, input: 0x%08p, expected: 0x%08p, output: 0x%08p\r\n",
|
||||||
|
(unsigned)idx, test->region_start, test->region_start_exp, region_start);
|
||||||
|
} else if (region_size != test->region_size_exp) {
|
||||||
|
printf("Region size test failed. Idx: %u, input: 0x%08X, expected: 0x%08X, output: 0x%08X\r\n",
|
||||||
|
(unsigned)idx, (unsigned)test->region_size, (unsigned)test->region_size_exp, (unsigned)region_size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Done\r\n");
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user