Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions benchmark/.clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CompileFlags:
CompilationDatabase: .
BuiltinHeaders: QueryDriver
103 changes: 103 additions & 0 deletions benchmark/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# Copyright 2024 - 2025 Khalil Estell and the libhal contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

cmake_minimum_required(VERSION 3.25)

project(benchmark-error-handling LANGUAGES CXX)

# Always check that the $ENV{LIBHAL_PLATFORM_LIBRARY} & $ENV{LIBHAL_PLATFORM}
# environment variables are set by the profile.
if("$ENV{LIBHAL_PLATFORM_LIBRARY}" STREQUAL "")
message(FATAL_ERROR
"Build environment variable LIBHAL_PLATFORM_LIBRARY is required for " "this project.")
endif()
if("$ENV{LIBHAL_PLATFORM}" STREQUAL "")
message(FATAL_ERROR
"Build environment variable LIBHAL_PLATFORM is required for "
"this project.")
endif()

find_package(libhal-$ENV{LIBHAL_PLATFORM_LIBRARY} REQUIRED)
find_package(prebuilt-picolibc QUIET)

if(${CMAKE_CROSSCOMPILING})
find_package(${PACKAGE} REQUIRED)
endif()

set(startup_source_files main.cpp filler.cpp)

# Makes the platform/<platform_name>.cpp file optional
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/platforms/$ENV{LIBHAL_PLATFORM}.cpp")
list(APPEND startup_source_files platforms/$ENV{LIBHAL_PLATFORM}.cpp)
endif()

add_library(startup_code ${startup_source_files})

target_include_directories(startup_code PUBLIC .)
target_compile_options(startup_code PRIVATE
-g
-Werror
-Wall
-Wextra
-Wshadow
-fno-threadsafe-statics
$<$<COMPILE_LANGUAGE:CXX>:-fexceptions -fno-rtti>
)

target_link_libraries(startup_code PRIVATE
libhal::$ENV{LIBHAL_PLATFORM_LIBRARY}
)

if(prebuilt-picolibc_FOUND)
target_link_libraries(startup_code PRIVATE picolibc)
message(STATUS "Found picolibc, linking it in!")
endif()

# Glob all the files in the directory 'generated_tests'
file(GLOB GENERATED_TEST "${CMAKE_CURRENT_SOURCE_DIR}/generated_tests/*.cpp")

foreach(test_path ${GENERATED_TEST})
get_filename_component(test_file_name ${test_path} NAME)
set(elf ${test_file_name}.elf)
message(STATUS "Generating Demo for \"${elf}\"")
add_executable(${elf} ${test_path})

target_compile_options(${elf} PRIVATE
-g
-Werror
-Wall
-Wextra
-Wshadow
-fno-threadsafe-statics
$<$<COMPILE_LANGUAGE:CXX>:-fexceptions -fno-rtti>
)

target_link_libraries(${elf} PRIVATE
startup_code
libhal::$ENV{LIBHAL_PLATFORM_LIBRARY}
)

target_link_options(${elf} PRIVATE -fno-threadsafe-statics)

if(prebuilt-picolibc_FOUND)
target_link_libraries(${elf} PRIVATE picolibc)
endif()

if(${CMAKE_CROSSCOMPILING})
# Convert elf into .bin, .hex and other formats needed for programming
# devices.
libhal_post_build(${elf})
libhal_disassemble(${elf})
endif()
endforeach()
26 changes: 26 additions & 0 deletions benchmark/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Copyright 2024 - 2025 Khalil Estell and the libhal contributors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from conan import ConanFile


class demos(ConanFile):
python_requires = "libhal-bootstrap/[>=4.3.0 <5]"
python_requires_extend = "libhal-bootstrap.demo"

def requirements(self):
bootstrap = self.python_requires["libhal-bootstrap"]
bootstrap.module.add_demo_requirements(self)
if self.options.platform != "mac":
self.requires("libhal-exceptions/[1.2.0 || latest]")
17 changes: 17 additions & 0 deletions benchmark/filler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @file filler.cpp
*
* This file includes filler functions which are added to both result and
* exceptions. The hypothesis and expectation is that the additional functions
* will have no effect on the result experiment and will have an effect on the
* exceptions experiment. Exceptions are effected because exceptions perform a
* binary search through the exception index to find the handling info for each
* function.
*
*/

/**
* @brief Performs some set of actions that forces the compiler to link in all
* of the filler functions.
*/
void activate_filler();
Loading
Loading