Skip to content

Commit

Permalink
fix failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lmbsog0 committed Nov 10, 2021
1 parent cac66b2 commit b8cdc25
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 69 deletions.
20 changes: 11 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@ RUN apt-get update -y && apt-get install -y --no-install-recommends \
python3-pip \
wget

RUN wget -O gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2 https://github.com/paoloteti/armeb-none-eabi-gcc-buildpatch/releases/download/v8-2019-q3-update/gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2 && \
mkdir /usr/local/bin/armbe-none-eabi-gcc && \
tar -xf gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2 -C /usr/local/bin/armbig-none-eabi-gcc && \
rm gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2

RUN wget -O gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2019q3/RC1.1/gcc-arm-none-eabi-8-2019-q3-update-linux.tar.bz2?revision=c34d758a-be0c-476e-a2de-af8c6e16a8a2?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,8-2019-q3-update && \
mkdir /usr/local/bin/armle-none-eabi-gcc && \
tar -xf gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2 -C /usr/local/bin/armlittle-none-eabi-gcc && \
rm gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2
# install arm-none-eabi toolchain for big endian targets.
RUN wget -O gcc-arm-none-eabi.tar.bz2 https://github.com/paoloteti/armeb-none-eabi-gcc-buildpatch/releases/download/v8-2019-q3-update/gcc-armeb-none-eabi-8-2019-q3-update-linux.tar.bz2 && \
mkdir /usr/local/bin/armeb-none-eabi-gcc && \
tar xf gcc-arm-none-eabi.tar.bz2 --strip-components=1 -C /usr/local/bin/armeb-none-eabi-gcc && \
rm gcc-arm-none-eabi.tar.bz2

# install arm-none-eabi toolchain for little endian targets.
RUN wget -O gcc-arm-none-eabi.tar.bz2 https://developer.arm.com/-/media/Files/downloads/gnu-rm/8-2019q3/RC1.1/gcc-arm-none-eabi-8-2019-q3-update-linux.tar.bz2?revision=c34d758a-be0c-476e-a2de-af8c6e16a8a2?product=GNU%20Arm%20Embedded%20Toolchain,64-bit,,Linux,8-2019-q3-update && \
mkdir /usr/local/bin/armel-none-eabi-gcc && \
tar xf gcc-arm-none-eabi.tar.bz2 --strip-components=1 -C /usr/local/bin/armel-none-eabi-gcc && \
rm gcc-arm-none-eabi.tar.bz2

COPY requirements.txt requirements.txt

Expand Down
12 changes: 6 additions & 6 deletions pyelf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ def test_get_endianness(elf_file, expected_endianness):

@pytest.mark.parametrize('elf_file', elf_files)
@pytest.mark.parametrize('symbol, size, address', ((
('dummy_var_no_init_uint8', 1, 0x08400014),
('dummy_var_no_init_uint16', 2, 0x0840000e),
('dummy_var_no_init_uint32', 4, 0x08400010),
('dummy_var_no_init_uint8', 1, 0x08400000),
('dummy_var_no_init_uint16', 2, 0x08400004),
('dummy_var_no_init_uint32', 4, 0x08400008),
('dummy_var_no_init_sint8', 1, 0x0840000c),
('dummy_var_no_init_sint16', 2, 0x08400004),
('dummy_var_no_init_sint32', 4, 0x08400008))))
('dummy_var_no_init_sint16', 2, 0x08400010),
('dummy_var_no_init_sint32', 4, 0x08400014))))
def test_get_symbol(elf_file, symbol, size, address):
elf_file = ElfFile(elf_file)
assert elf_file.get_symbol(symbol).size == size
Expand All @@ -100,7 +100,7 @@ def test_get_binary(elf_file, bin_file):

@pytest.mark.parametrize('elf_file', elf_files)
@pytest.mark.parametrize('address, expected_source_file, expected_line, expected_func_name', (
(0x30, '/usr/project/pyelf/tests/main.c', 12, 'main'),))
(0x00000030, os.path.abspath(os.path.join(os.path.dirname(__file__), 'tests', 'main.c')), 21, 'main'),))
def test_get_source_info(elf_file, address, expected_source_file, expected_line, expected_func_name):
elf_file = ElfFile(elf_file)
source_file, line, func_name = elf_file.get_source_info(address)
Expand Down
50 changes: 24 additions & 26 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,36 @@ set(CMAKE_TRY_COMPILE_TARGET_TYPE "STATIC_LIBRARY")

project(pyelf ASM C)

find_program(SREC_CAT NAMES srec_cat)

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})

add_library(dummy_0_${CMAKE_ENDIANNESS}_endian dummy_0.c)
target_include_directories(dummy_0_${CMAKE_ENDIANNESS}_endian
add_compile_options(-g3 -gdwarf -m${ENDIANNESS}-endian -march=armv7-r)

add_library(dummy_0_${ENDIANNESS}_endian dummy_0.c)

target_include_directories(dummy_0_${ENDIANNESS}_endian
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_options(dummy_0_${CMAKE_ENDIANNESS}_endian
PRIVATE -m${CMAKE_ENDIANNESS}-endian
PRIVATE -march=armv7-r
)

add_executable(${CMAKE_ENDIANNESS}_endian.elf crt0.S main.c)
target_compile_options(${CMAKE_ENDIANNESS}_endian.elf
PRIVATE -m${CMAKE_ENDIANNESS}-endian
PRIVATE -march=armv7-r
)
target_link_options(${CMAKE_ENDIANNESS}_endian.elf

add_executable(${ENDIANNESS}_endian.elf crt0.S main.c)

target_link_options(${ENDIANNESS}_endian.elf
PRIVATE -nostartfiles
PRIVATE -nodefaultlibs
PRIVATE -march=armv7-r
)
target_link_libraries(${CMAKE_ENDIANNESS}_endian.elf
PUBLIC dummy_0_${CMAKE_ENDIANNESS}_endian)
set_target_properties(${CMAKE_ENDIANNESS}_endian.elf PROPERTIES
LINK_FLAGS "-T${CMAKE_CURRENT_SOURCE_DIR}/linker.ld -Wl,-Map,${CMAKE_CURRENT_SOURCE_DIR}/${CMAKE_ENDIANNESS}_endian.map"
PRIVATE -nodefaultlibs)

target_link_libraries(${ENDIANNESS}_endian.elf
PUBLIC dummy_0_${ENDIANNESS}_endian)

set_target_properties(${ENDIANNESS}_endian.elf PROPERTIES
LINK_FLAGS "-T${CMAKE_CURRENT_SOURCE_DIR}/linker.ld -Wl,-Map,${CMAKE_CURRENT_SOURCE_DIR}/${ENDIANNESS}_endian.map"
LINK_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/linker.ld)

add_custom_target(${CMAKE_ENDIANNESS}_endian.bin ALL
DEPENDS ${CMAKE_ENDIANNESS}_endian.elf
COMMAND ${CMAKE_OBJCOPY} -O binary ${CMAKE_ENDIANNESS}_endian.elf ${CMAKE_ENDIANNESS}_endian.bin
add_custom_target(${ENDIANNESS}_endian.bin ALL
DEPENDS ${ENDIANNESS}_endian.elf
COMMAND ${CMAKE_OBJCOPY} -O binary ${ENDIANNESS}_endian.elf ${ENDIANNESS}_endian.bin
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})

add_custom_target(${CMAKE_ENDIANNESS}_endian.asm ALL
DEPENDS ${CMAKE_ENDIANNESS}_endian.elf
COMMAND ${CMAKE_OBJDUMP} -D -z ${CMAKE_ENDIANNESS}_endian.elf > ${CMAKE_ENDIANNESS}_endian.asm
add_custom_target(${ENDIANNESS}_endian.asm ALL
DEPENDS ${ENDIANNESS}_endian.elf
COMMAND ${CMAKE_OBJDUMP} -D -z ${ENDIANNESS}_endian.elf > ${ENDIANNESS}_endian.asm
WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
38 changes: 23 additions & 15 deletions tests/build.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
#!/usr/bin/env bash

for endinnaness in big little; do
# export path to the compiler.
export PATH=$PATH:/usr/local/opt/arm${endinnaness}-none-eabi-gcc
rm -rf build

# delete the build directory if it exists.
rm -rf build
# build the project using either the big endian toolchain.
cmake -H. -Bbuild -DCMAKE_C_COMPILER=/usr/local/bin/armeb-none-eabi-gcc/bin/armeb-none-eabi-gcc \
-DCMAKE_AR=/usr/local/bin/armeb-none-eabi-gcc/bin/armeb-none-eabi-ar \
-DCMAKE_OBJCOPY=/usr/local/bin/armeb-none-eabi-gcc/bin/armeb-none-eabi-objcopy \
-DCMAKE_OBJDUMP=/usr/local/bin/armeb-none-eabi-gcc/bin/armeb-none-eabi-objdump \
-DENDIANNESS=big
pushd build
make all
popd

# build the project using either the big or the little endian toolchain.
cmake -H. -Bbuild -DCMAKE_C_COMPILER=$(which arm-none-eabi-gcc) \
-DCMAKE_AR=$(which arm-none-eabi-ar) \
-DCMAKE_OBJCOPY=$(which arm-none-eabi-objcopy) \
-DCMAKE_OBJDUMP=$(which arm-none-eabi-objdump) \
-DCMAKE_ENDIANNESS=$CMAKE_ENDIANNESS
pushd build
make all
popd
done
rm -rf build

# build the project using either the big endian toolchain.
cmake -H. -Bbuild -DCMAKE_C_COMPILER=/usr/local/bin/armel-none-eabi-gcc/bin/arm-none-eabi-gcc \
-DCMAKE_AR=/usr/local/bin/armel-none-eabi-gcc/bin/arm-none-eabi-ar \
-DCMAKE_OBJCOPY=/usr/local/bin/armel-none-eabi-gcc/bin/arm-none-eabi-objcopy \
-DCMAKE_OBJDUMP=/usr/local/bin/armel-none-eabi-gcc/bin/arm-none-eabi-objdump \
-DENDIANNESS=little
pushd build
make all
popd

rm -rf build
45 changes: 34 additions & 11 deletions tests/linker.ld
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MEMORY
{
FLASH_ECC_BANK_0_SECTOR_0 (x) : ORIGIN = 0x00000000, LENGTH = 16K
RAM_ECC (rwx) : ORIGIN = 0x08400000, LENGTH = 512K
FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 16K
RAM (rwx) : ORIGIN = 0x08400000, LENGTH = 512K
}


Expand All @@ -16,29 +16,52 @@ SECTIONS
*(.code.boot);
. = ALIGN(0x04);
*(.code);
. = ALIGN(0x04);
} > FLASH_ECC_BANK_0_SECTOR_0
} > FLASH
.rodata :
{
*(.rodata)
. = ALIGN(0x04);
} > FLASH_ECC_BANK_0_SECTOR_0
*(.rodata)
} > FLASH
.text :
{
*(.text)
. = ALIGN(0x04);
} > FLASH_ECC_BANK_0_SECTOR_0
*(.text)
} > FLASH
.data :
{
. = ALIGN(0x04);
*(.data)
} > FLASH
.init_lma :
{
. = ALIGN(0x04);
} > FLASH_ECC_BANK_0_SECTOR_0
.bss :
} > FLASH = 0xFF
.init_vma : AT(ADDR(.init_lma))
{
*(.unsigned.8)
. = ALIGN(0x04);
*(.unsigned.16)
. = ALIGN(0x04);
*(.unsigned.32)
. = ALIGN(0x04);
*(.signed.8)
. = ALIGN(0x04);
*(.signed.16)
. = ALIGN(0x04);
*(.signed.32)
. = ALIGN(0x04);
} > RAM
.bss (NOLOAD) :
{
*(.bss)
*(COMMON)
. = ALIGN(0x04);
} > RAM_ECC
} > RAM
.free_flash_lma ADDR(.init_lma) + SIZEOF(.init_vma) :
{
BYTE(0xFF);
. = ABSOLUTE(LENGTH(FLASH));
} > FLASH = 0xFF
/DISCARD/ :
{
*(.comment)
Expand Down
13 changes: 11 additions & 2 deletions tests/main.c
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
#include "dummy_0.h"

const int arch_paths_first;

__attribute__((section(".unsigned.8")))
unsigned char dummy_var_no_init_uint8;

__attribute__((section(".unsigned.16")))
unsigned short dummy_var_no_init_uint16;

__attribute__((section(".unsigned.32")))
unsigned int dummy_var_no_init_uint32;

__attribute__((section(".signed.8")))
signed char dummy_var_no_init_sint8;

__attribute__((section(".signed.16")))
signed short dummy_var_no_init_sint16;

__attribute__((section(".signed.32")))
signed int dummy_var_no_init_sint32;

int main(int argc, char *argv[])
Expand Down

0 comments on commit b8cdc25

Please sign in to comment.