tests: code_relocation: Add additional test cases for library and genex
Add test cases for generator expressions and library relocation to the code_relocation test, in order to verify functionality for these new API features. Signed-off-by: Daniel DeGrasse <daniel.degrasse@nxp.com>
This commit is contained in:
parent
de8478b7f3
commit
bd593bf93e
9 changed files with 158 additions and 3 deletions
|
@ -1,4 +1,5 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright 2022 NXP
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
|
||||
|
@ -18,15 +19,29 @@ zephyr_code_relocate(FILES src/test_file1.c ${SRAM2_PHDR} LOCATION SRAM2)
|
|||
|
||||
zephyr_code_relocate(FILES src/test_file2.c ${RAM_PHDR} LOCATION RAM)
|
||||
|
||||
# Add custom library that we can relocate code for
|
||||
add_subdirectory(test_lib)
|
||||
target_link_libraries(app PUBLIC test_lib)
|
||||
target_include_directories(app PUBLIC ${CMAKE_CURRENT_LIST_DIR}/test_lib)
|
||||
# Relocate library code
|
||||
zephyr_code_relocate(LIBRARY test_lib LOCATION SRAM2)
|
||||
|
||||
# Test support for a simple generator expression to relocate two files
|
||||
set(reloc_files src/test_file4.c src/test_file5.c)
|
||||
set(genex_expr
|
||||
${CMAKE_CURRENT_LIST_DIR}/$<JOIN:${reloc_files},$<SEMICOLON>${CMAKE_CURRENT_LIST_DIR}/>)
|
||||
zephyr_code_relocate(FILES ${genex_expr} LOCATION SRAM2)
|
||||
|
||||
zephyr_code_relocate(FILES src/test_file3.c LOCATION SRAM2_LITERAL)
|
||||
zephyr_code_relocate(FILES src/test_file3.c LOCATION SRAM2_TEXT)
|
||||
zephyr_code_relocate(FILES src/test_file3.c LOCATION RAM_DATA)
|
||||
zephyr_code_relocate(FILES src/test_file3.c LOCATION SRAM2_BSS)
|
||||
|
||||
zephyr_code_relocate(FILES ../../../kernel/sem.c ${RAM_PHDR} LOCATION RAM)
|
||||
|
||||
zephyr_code_relocate(FILES ${ZEPHYR_BASE}/kernel/sem.c ${RAM_PHDR} LOCATION RAM)
|
||||
|
||||
if (CONFIG_RELOCATE_TO_ITCM)
|
||||
zephyr_code_relocate(FILES ../../../lib/libc/minimal/source/string/string.c
|
||||
zephyr_code_relocate(FILES ${ZEPHYR_BASE}/lib/libc/minimal/source/string/string.c
|
||||
LOCATION ITCM_TEXT)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -8,6 +8,8 @@
|
|||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
#include "test_lib.h"
|
||||
|
||||
/*
|
||||
* These values will typically be placed in the appropriate sections, but may be moved around
|
||||
* by the compiler; for instance var_sram2_data might end up in .rodata if the compiler can prove
|
||||
|
@ -63,6 +65,8 @@ ZTEST(code_relocation, test_function_in_sram2)
|
|||
|
||||
/* Print values from sram */
|
||||
function_in_sram(var_sram2_data);
|
||||
/* Call library function */
|
||||
relocated_library();
|
||||
|
||||
/* Print values which were placed using attributes */
|
||||
printk("Address of custom_section, func placed using attributes %p\n",
|
||||
|
|
|
@ -16,6 +16,6 @@ void function_in_sram(int32_t value)
|
|||
|
||||
printk("Hello World! %s\n", CONFIG_BOARD);
|
||||
memcpy(dst, src, 8);
|
||||
printk("Address of memcpy %p\n", &memcpy);
|
||||
printk("Address of memcpy %p\n\n", &memcpy);
|
||||
zassert_mem_equal(src, dst, 8, "memcpy compare error");
|
||||
}
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2022, NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
__in_section(data, sram2, var) uint32_t var_file4_sram2_data = 10U;
|
||||
__in_section(bss, sram2, var) uint32_t var_file4_sram2_bss;
|
||||
|
||||
ZTEST(code_relocation, test_function_genex_relocate_1)
|
||||
{
|
||||
extern uintptr_t __sram2_data_start;
|
||||
extern uintptr_t __sram2_data_end;
|
||||
extern uintptr_t __sram2_bss_start;
|
||||
extern uintptr_t __sram2_bss_end;
|
||||
|
||||
printk("Address of var_file4_sram2_data %p\n", &var_file4_sram2_data);
|
||||
printk("Address of var_file4_sram2_bss %p\n\n", &var_file4_sram2_bss);
|
||||
|
||||
zassert_between_inclusive((uintptr_t)&var_file4_sram2_data,
|
||||
(uintptr_t)&__sram2_data_start,
|
||||
(uintptr_t)&__sram2_data_end,
|
||||
"var_file4_sram2_data not in sram2_data region");
|
||||
zassert_between_inclusive((uintptr_t)&var_file4_sram2_bss,
|
||||
(uintptr_t)&__sram2_bss_start,
|
||||
(uintptr_t)&__sram2_bss_end,
|
||||
"var_file4_sram2_bss not in sram2_bss region");
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* Copyright (c) 2022, NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
__in_section(data, sram2, var) uint32_t var_file5_sram2_data = 10U;
|
||||
__in_section(bss, sram2, var) uint32_t var_file5_sram2_bss;
|
||||
|
||||
ZTEST(code_relocation, test_function_genex_relocate_2)
|
||||
{
|
||||
extern uintptr_t __sram2_data_start;
|
||||
extern uintptr_t __sram2_data_end;
|
||||
extern uintptr_t __sram2_bss_start;
|
||||
extern uintptr_t __sram2_bss_end;
|
||||
|
||||
printk("Address of var_file5_sram2_data %p\n", &var_file5_sram2_data);
|
||||
printk("Address of var_file5_sram2_bss %p\n\n", &var_file5_sram2_bss);
|
||||
|
||||
zassert_between_inclusive((uintptr_t)&var_file5_sram2_data,
|
||||
(uintptr_t)&__sram2_data_start,
|
||||
(uintptr_t)&__sram2_data_end,
|
||||
"var_file5_sram2_data not in sram2_data region");
|
||||
zassert_between_inclusive((uintptr_t)&var_file5_sram2_bss,
|
||||
(uintptr_t)&__sram2_bss_start,
|
||||
(uintptr_t)&__sram2_bss_end,
|
||||
"var_file5_sram2_bss not in sram2_bss region");
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
# SPDX-License-Identifier: Apache-2.0
|
||||
# Copyright 2022 NXP
|
||||
|
||||
add_library(test_lib STATIC "")
|
||||
target_sources(test_lib PRIVATE test_lib1.c test_lib2.c)
|
||||
get_target_property(include_dirs app INCLUDE_DIRECTORIES)
|
||||
target_link_libraries(test_lib PUBLIC zephyr_interface)
|
||||
add_dependencies(test_lib zephyr_generated_headers)
|
|
@ -0,0 +1,8 @@
|
|||
/*
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/* External library function, called from test_file1.c */
|
||||
void relocated_library(void);
|
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
#include <zephyr/ztest.h>
|
||||
|
||||
__in_section(data, sram2, var) uint32_t var_lib1_sram2_data = 10U;
|
||||
__in_section(bss, sram2, var) uint32_t var_lib1_sram2_bss;
|
||||
|
||||
/* Helper function, declared in test_lib2.c */
|
||||
extern void relocated_helper(void);
|
||||
|
||||
void relocated_library(void)
|
||||
{
|
||||
extern uintptr_t __sram2_text_start;
|
||||
extern uintptr_t __sram2_text_end;
|
||||
extern uintptr_t __sram2_data_start;
|
||||
extern uintptr_t __sram2_data_end;
|
||||
extern uintptr_t __sram2_bss_start;
|
||||
extern uintptr_t __sram2_bss_end;
|
||||
|
||||
printk("Address of var_lib1_sram2_data %p\n", &var_lib1_sram2_data);
|
||||
printk("Address of var_lib1_sram2_bss %p\n", &var_lib1_sram2_bss);
|
||||
printk("Address of relocated_lib_helper %p\n\n", &relocated_helper);
|
||||
|
||||
zassert_between_inclusive((uintptr_t)&var_lib1_sram2_data,
|
||||
(uintptr_t)&__sram2_data_start,
|
||||
(uintptr_t)&__sram2_data_end,
|
||||
"var_lib1_sram2_data not in sram2_data region");
|
||||
zassert_between_inclusive((uintptr_t)&var_lib1_sram2_bss,
|
||||
(uintptr_t)&__sram2_bss_start,
|
||||
(uintptr_t)&__sram2_bss_end,
|
||||
"var_lib1_sram2_bss not in sram2_bss region");
|
||||
zassert_between_inclusive((uintptr_t)&relocated_helper,
|
||||
(uintptr_t)&__sram2_text_start,
|
||||
(uintptr_t)&__sram2_text_end,
|
||||
"relocated_helper not in sram2_text region");
|
||||
relocated_helper();
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
/*
|
||||
* Copyright 2022 NXP
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/kernel.h>
|
||||
#include <zephyr/sys/printk.h>
|
||||
|
||||
void relocated_helper(void)
|
||||
{
|
||||
printk("Relocated helper function running on %s\n\n", CONFIG_BOARD);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue