mirror of
https://github.com/espressif/esp-idf.git
synced 2025-10-04 11:00: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
|
||||
#
|
||||
# SPDX-FileCopyrightText: 2020-2024 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-FileCopyrightText: 2020-2025 Espressif Systems (Shanghai) CO LTD
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Check placements in this test app for main
|
||||
@@ -8,13 +8,13 @@
|
||||
import argparse
|
||||
import subprocess
|
||||
|
||||
from pyparsing import alphanums
|
||||
from pyparsing import hexnums
|
||||
from pyparsing import LineEnd
|
||||
from pyparsing import LineStart
|
||||
from pyparsing import Literal
|
||||
from pyparsing import Optional
|
||||
from pyparsing import Word
|
||||
from pyparsing import alphanums
|
||||
from pyparsing import hexnums
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
|
||||
@@ -29,13 +29,16 @@ contents = subprocess.check_output([args.objdump, '-t', args.elf]).decode()
|
||||
|
||||
|
||||
def check_location(symbol, expected):
|
||||
pattern = (LineStart() + Word(hexnums).setResultsName('address')
|
||||
pattern = (
|
||||
LineStart()
|
||||
+ Word(hexnums).setResultsName('address')
|
||||
+ Optional(Word(alphanums, exact=1))
|
||||
+ Optional(Word(alphanums, exact=1))
|
||||
+ Word(alphanums + '._*').setResultsName('actual')
|
||||
+ Word(hexnums)
|
||||
+ Literal(symbol)
|
||||
+ LineEnd())
|
||||
+ LineEnd()
|
||||
)
|
||||
|
||||
try:
|
||||
results = pattern.searchString(contents)[0]
|
||||
@@ -43,7 +46,9 @@ def check_location(symbol, expected):
|
||||
raise Exception("check placement fail: '%s' was not found" % (symbol))
|
||||
|
||||
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))
|
||||
return int(results.address, 16)
|
||||
@@ -82,3 +87,5 @@ check_location('func3', '.flash.text')
|
||||
check_location('func4', '.iram0.text')
|
||||
|
||||
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"
|
||||
INCLUDE_DIRS "."
|
||||
PRIV_REQUIRES prebuilt
|
||||
LDFRAGMENTS "linker.lf")
|
||||
|
@@ -10,3 +10,8 @@ entries:
|
||||
if SOC_RTC_MEM_SUPPORTED = y:
|
||||
src1:func2 (rtc)
|
||||
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 const int const_array[];
|
||||
extern int prebuilt_func(void);
|
||||
|
||||
void app_main(void)
|
||||
{
|
||||
func2();
|
||||
func3();
|
||||
func4();
|
||||
prebuilt_func();
|
||||
if (esp_ptr_in_dram(const_array)) {
|
||||
printf("const_array placed in dram\n");
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user