mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-04 19:10:58 +02:00
test(ldgen): add test for placements of symbols in prebuilt libraries
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
#
|
#
|
||||||
# SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
# SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
|
||||||
# SPDX-License-Identifier: Apache-2.0
|
# SPDX-License-Identifier: Apache-2.0
|
||||||
#
|
#
|
||||||
# Check placements in this test app for main
|
# Check placements in this test app for main
|
||||||
@@ -8,13 +8,13 @@
|
|||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from pyparsing import alphanums
|
|
||||||
from pyparsing import hexnums
|
|
||||||
from pyparsing import LineEnd
|
from pyparsing import LineEnd
|
||||||
from pyparsing import LineStart
|
from pyparsing import LineStart
|
||||||
from pyparsing import Literal
|
from pyparsing import Literal
|
||||||
from pyparsing import Optional
|
from pyparsing import Optional
|
||||||
from pyparsing import Word
|
from pyparsing import Word
|
||||||
|
from pyparsing import alphanums
|
||||||
|
from pyparsing import hexnums
|
||||||
|
|
||||||
argparser = argparse.ArgumentParser()
|
argparser = argparse.ArgumentParser()
|
||||||
|
|
||||||
@@ -29,13 +29,16 @@ contents = subprocess.check_output([args.objdump, '-t', args.elf]).decode()
|
|||||||
|
|
||||||
|
|
||||||
def check_location(symbol, expected):
|
def check_location(symbol, expected):
|
||||||
pattern = (LineStart() + Word(hexnums).setResultsName('address')
|
pattern = (
|
||||||
+ Optional(Word(alphanums, exact=1))
|
LineStart()
|
||||||
+ Optional(Word(alphanums,exact=1))
|
+ Word(hexnums).setResultsName('address')
|
||||||
+ Word(alphanums + '._*').setResultsName('actual')
|
+ Optional(Word(alphanums, exact=1))
|
||||||
+ Word(hexnums)
|
+ Optional(Word(alphanums, exact=1))
|
||||||
+ Literal(symbol)
|
+ Word(alphanums + '._*').setResultsName('actual')
|
||||||
+ LineEnd())
|
+ Word(hexnums)
|
||||||
|
+ Literal(symbol)
|
||||||
|
+ LineEnd()
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
results = pattern.searchString(contents)[0]
|
results = pattern.searchString(contents)[0]
|
||||||
@@ -43,7 +46,9 @@ def check_location(symbol, expected):
|
|||||||
raise Exception("check placement fail: '%s' was not found" % (symbol))
|
raise Exception("check placement fail: '%s' was not found" % (symbol))
|
||||||
|
|
||||||
if results.actual != expected:
|
if results.actual != expected:
|
||||||
raise Exception("check placement fail: '%s' was placed in '%s', not in '%s'" % (symbol, results.actual, expected))
|
raise Exception(
|
||||||
|
"check placement fail: '%s' was placed in '%s', not in '%s'" % (symbol, results.actual, expected)
|
||||||
|
)
|
||||||
|
|
||||||
print("check placement pass: '%s' was successfully placed in '%s'" % (symbol, results.actual))
|
print("check placement pass: '%s' was successfully placed in '%s'" % (symbol, results.actual))
|
||||||
return int(results.address, 16)
|
return int(results.address, 16)
|
||||||
@@ -82,3 +87,5 @@ check_location('func3', '.flash.text')
|
|||||||
check_location('func4', '.iram0.text')
|
check_location('func4', '.iram0.text')
|
||||||
|
|
||||||
check_location('const_array', '.dram0.data')
|
check_location('const_array', '.dram0.data')
|
||||||
|
|
||||||
|
check_location('prebuilt_func', '.iram0.text')
|
||||||
|
@@ -0,0 +1,14 @@
|
|||||||
|
idf_component_register()
|
||||||
|
|
||||||
|
include(ExternalProject)
|
||||||
|
externalproject_add(subproject
|
||||||
|
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/subproject
|
||||||
|
CMAKE_ARGS -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TOOLCHAIN_FILE}
|
||||||
|
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/subproject"
|
||||||
|
INSTALL_COMMAND ""
|
||||||
|
BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/subproject/libprebuilt.a"
|
||||||
|
)
|
||||||
|
|
||||||
|
add_prebuilt_library(prebuilt "${CMAKE_CURRENT_BINARY_DIR}/subproject/libprebuilt.a")
|
||||||
|
|
||||||
|
target_link_libraries(${COMPONENT_LIB} INTERFACE prebuilt)
|
@@ -0,0 +1,5 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.12)
|
||||||
|
|
||||||
|
project(prebuilt)
|
||||||
|
add_library(prebuilt STATIC prebuilt.c)
|
||||||
|
target_compile_options(prebuilt PRIVATE "-ffunction-sections" "-fdata-sections")
|
@@ -0,0 +1,9 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||||
|
*/
|
||||||
|
int prebuilt_func(void)
|
||||||
|
{
|
||||||
|
return 42;
|
||||||
|
}
|
@@ -1,3 +1,4 @@
|
|||||||
idf_component_register(SRCS "src1.c" "src2.c" "test_main.c" "consts.c"
|
idf_component_register(SRCS "src1.c" "src2.c" "test_main.c" "consts.c"
|
||||||
INCLUDE_DIRS "."
|
INCLUDE_DIRS "."
|
||||||
|
PRIV_REQUIRES prebuilt
|
||||||
LDFRAGMENTS "linker.lf")
|
LDFRAGMENTS "linker.lf")
|
||||||
|
@@ -10,3 +10,8 @@ entries:
|
|||||||
if SOC_RTC_MEM_SUPPORTED = y:
|
if SOC_RTC_MEM_SUPPORTED = y:
|
||||||
src1:func2 (rtc)
|
src1:func2 (rtc)
|
||||||
consts : const_array (noflash)
|
consts : const_array (noflash)
|
||||||
|
|
||||||
|
[mapping:prebuilt]
|
||||||
|
archive: libprebuilt.a
|
||||||
|
entries:
|
||||||
|
prebuilt:prebuilt_func (noflash)
|
||||||
|
@@ -11,12 +11,14 @@ extern void func3(void);
|
|||||||
extern void func4(void);
|
extern void func4(void);
|
||||||
|
|
||||||
extern const int const_array[];
|
extern const int const_array[];
|
||||||
|
extern int prebuilt_func(void);
|
||||||
|
|
||||||
void app_main(void)
|
void app_main(void)
|
||||||
{
|
{
|
||||||
func2();
|
func2();
|
||||||
func3();
|
func3();
|
||||||
func4();
|
func4();
|
||||||
|
prebuilt_func();
|
||||||
if (esp_ptr_in_dram(const_array)) {
|
if (esp_ptr_in_dram(const_array)) {
|
||||||
printf("const_array placed in dram\n");
|
printf("const_array placed in dram\n");
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user