├── third-party ├── cmocka │ ├── NEWS │ ├── .clang_complete │ ├── include │ │ ├── cmockery │ │ │ ├── cmockery.h │ │ │ └── pbc.h │ │ ├── CMakeLists.txt │ │ └── cmocka_pbc.h │ ├── cmocka-build-tree-settings.cmake.in │ ├── example │ │ ├── mock │ │ │ ├── chef_wrap │ │ │ │ ├── waiter_test_wrap.h │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── chef.h │ │ │ │ └── chef.c │ │ │ ├── CMakeLists.txt │ │ │ └── uptime │ │ │ │ ├── CMakeLists.txt │ │ │ │ ├── proc_uptime.h │ │ │ │ ├── proc_uptime.c │ │ │ │ └── README.md │ │ ├── assert_macro.h │ │ ├── simple_test.c │ │ ├── assert_module.h │ │ ├── assert_module.c │ │ ├── assert_macro.c │ │ ├── database.h │ │ ├── assert_macro_test.c │ │ ├── allocate_module_test.c │ │ ├── assert_module_test.c │ │ ├── allocate_module.c │ │ └── CMakeLists.txt │ ├── AUTHORS │ ├── doc │ │ ├── that_style │ │ │ ├── img │ │ │ │ ├── sync_on.png │ │ │ │ └── sync_off.png │ │ │ ├── js │ │ │ │ └── striped_bg.js │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ └── header.html │ │ └── CMakeLists.txt │ ├── coverity │ │ ├── coverity_internal_model.c │ │ └── README │ ├── cmocka.pc.cmake │ ├── CTestConfig.cmake │ ├── DefineOptions.cmake │ ├── cmocka-config.cmake.in │ ├── cmake │ │ ├── Modules │ │ │ ├── DefinePlatformDefaults.cmake │ │ │ ├── MacroEnsureOutOfSourceBuild.cmake │ │ │ ├── DefineCMakeDefaults.cmake │ │ │ ├── AddCCompilerFlag.cmake │ │ │ ├── COPYING-CMAKE-SCRIPTS │ │ │ ├── FindNSIS.cmake │ │ │ └── CheckCCompilerFlagSSP.cmake │ │ ├── Toolchain-Debian-mips.cmake │ │ └── Toolchain-cross-m32.cmake │ ├── README.md │ ├── tests │ │ ├── test_group_setup_fail.c │ │ ├── test_group_setup_assert.c │ │ ├── test_assert_macros.c │ │ ├── test_assert_macros_fail.c │ │ ├── test_exception_handler.c │ │ ├── test_cmockery.c │ │ ├── test_skip.c │ │ ├── test_group_fixtures.c │ │ ├── test_setup_fail.c │ │ ├── test_float_macros.c │ │ ├── test_wildcard.c │ │ ├── test_skip_filter.c │ │ ├── test_basics.c │ │ ├── test_returns.c │ │ ├── test_returns_fail.c │ │ ├── test_groups.c │ │ ├── test_fixtures.c │ │ ├── test_alloc.c │ │ ├── test_strmatch.c │ │ ├── test_ordering_fail.c │ │ ├── ctest-default.cmake │ │ └── test_ordering.c │ ├── 5.patch │ ├── src │ │ └── cmocka.def │ └── CPackConfig.cmake ├── uthash │ ├── README.md │ ├── package.json │ └── LICENSE ├── README.md ├── CMakeLists.txt └── tinyprintf │ └── tinyprintf_LICENSE.BSD-new ├── pyfitterbap ├── comm │ ├── __init__.py │ ├── test │ │ └── __init__.py │ └── ui │ │ ├── __init__.py │ │ └── vertical_scroll_area.py ├── test │ └── __init__.py ├── __init__.py ├── entry_points │ ├── comm_ui.py │ ├── __init__.py │ └── crc.py ├── version.py ├── time.py ├── c_crc.pxd ├── include │ └── fitterbap │ │ ├── platform.h │ │ └── config.h ├── crc.pyx ├── __main__.py └── module.pxi ├── doc ├── host_comm_ui.png ├── footer.html ├── developer.md └── header.html ├── MANIFEST.in ├── .gitignore ├── test ├── collections │ └── CMakeLists.txt ├── memory │ └── CMakeLists.txt ├── cdef_static_assert_test.c ├── comm │ ├── count_table_u8.py │ └── waveform_sink_test.c ├── platform_test.c ├── hal.c ├── ec_test.c ├── version_test.c ├── dbc_test.c ├── CMakeLists.txt └── topic_test.c ├── src ├── host │ ├── platform_alloc.c │ ├── freertos │ │ ├── os_task.c │ │ └── os_mutex.c │ ├── linux │ │ └── platform.c │ └── win │ │ └── error.c ├── version.c ├── comm │ └── port.c ├── log.c ├── collections │ └── list.c ├── ec.c ├── time.c ├── CMakeLists.txt ├── topic.c └── lfsr.c ├── include ├── fitterbap │ ├── host │ │ ├── linux │ │ │ └── config.h │ │ ├── win │ │ │ ├── config.h │ │ │ └── error.h │ │ └── arm.h │ ├── common_header.h │ ├── comm │ │ ├── wave_sink_port.h │ │ └── wave_port.h │ ├── inttypes.h │ ├── assert.h │ ├── os │ │ ├── task.h │ │ └── mutex.h │ ├── config_defaults.h │ ├── pubsub_meta.h │ ├── crc.h │ └── cmacro_inc.h └── fitterbap.h ├── port └── include │ └── fitterbap │ ├── platform.h │ └── config.h ├── requirements.txt ├── .gitattributes ├── .github └── workflows │ └── windows.yml └── version_update.py /third-party/cmocka/NEWS: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyfitterbap/comm/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyfitterbap/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /pyfitterbap/comm/test/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /third-party/cmocka/.clang_complete: -------------------------------------------------------------------------------- 1 | -Iinclude 2 | -Iobj 3 | -------------------------------------------------------------------------------- /third-party/cmocka/include/cmockery/cmockery.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /third-party/cmocka/include/cmockery/pbc.h: -------------------------------------------------------------------------------- 1 | #include 2 | -------------------------------------------------------------------------------- /doc/host_comm_ui.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetperch/fitterbap/HEAD/doc/host_comm_ui.png -------------------------------------------------------------------------------- /third-party/cmocka/cmocka-build-tree-settings.cmake.in: -------------------------------------------------------------------------------- 1 | set(CMOCKA_INLUDE_DIR @PROJECT_SOURCE_DIR@/include) 2 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/chef_wrap/waiter_test_wrap.h: -------------------------------------------------------------------------------- 1 | 2 | int __wrap_chef_cook(const char *order, char **dish_out); 3 | -------------------------------------------------------------------------------- /third-party/cmocka/AUTHORS: -------------------------------------------------------------------------------- 1 | opensource@google.com 2 | Andreas Schneider 3 | Jakub Hrozek 4 | -------------------------------------------------------------------------------- /third-party/uthash/README.md: -------------------------------------------------------------------------------- 1 | 2 | Documentation for uthash is available at: 3 | 4 | http://troydhanson.github.com/uthash/ 5 | 6 | 7 | -------------------------------------------------------------------------------- /third-party/cmocka/doc/that_style/img/sync_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetperch/fitterbap/HEAD/third-party/cmocka/doc/that_style/img/sync_on.png -------------------------------------------------------------------------------- /third-party/cmocka/doc/that_style/img/sync_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/jetperch/fitterbap/HEAD/third-party/cmocka/doc/that_style/img/sync_off.png -------------------------------------------------------------------------------- /third-party/cmocka/example/assert_macro.h: -------------------------------------------------------------------------------- 1 | const char* get_status_code_string(const unsigned int status_code); 2 | unsigned int string_to_status_code(const char* const status_code_string); 3 | -------------------------------------------------------------------------------- /third-party/cmocka/coverity/coverity_internal_model.c: -------------------------------------------------------------------------------- 1 | /* Functions to help coverity do static analysis on cmocka */ 2 | void exit_test(const int quit_application) 3 | { 4 | __coverity_panic__(); 5 | } 6 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | include CHANGELOG.md 2 | include LICENSE 3 | include README.md 4 | recursive-include include * 5 | recursive-include port * 6 | recursive-include src * 7 | include pyfitterbap/include/fitterbap/config.h 8 | -------------------------------------------------------------------------------- /third-party/cmocka/cmocka.pc.cmake: -------------------------------------------------------------------------------- 1 | Name: ${PROJECT_NAME} 2 | Description: The cmocka unit testing library 3 | Version: ${PROJECT_VERSION} 4 | Libs: -L${CMAKE_INSTALL_FULL_LIBDIR} -lcmocka 5 | Cflags: -I${CMAKE_INSTALL_FULL_INCLUDEDIR} 6 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # TODO Execute "$CMAKE_LINKER --help" and check for --wrap 2 | if (${CMAKE_C_COMPILER_ID} MATCHES "(GNU|Clang)" AND NOT APPLE) 3 | add_subdirectory(chef_wrap) 4 | add_subdirectory(uptime) 5 | endif() 6 | -------------------------------------------------------------------------------- /pyfitterbap/__init__.py: -------------------------------------------------------------------------------- 1 | 2 | from .version import __version__, __title__, __description__, __url__, \ 3 | __author__, __author_email__, __license__, __copyright__ 4 | 5 | 6 | #from . import lib 7 | #from . import collections, ec, memory, stream 8 | #from .pattern_32a import allocate_pattern_buffer, PatternTx, PatternRx 9 | -------------------------------------------------------------------------------- /third-party/cmocka/CTestConfig.cmake: -------------------------------------------------------------------------------- 1 | set(UPDATE_TYPE "true") 2 | 3 | set(CTEST_PROJECT_NAME "cmocka") 4 | set(CTEST_NIGHTLY_START_TIME "01:00:00 UTC") 5 | 6 | set(CTEST_DROP_METHOD "https") 7 | set(CTEST_DROP_SITE "test.cmocka.org") 8 | set(CTEST_DROP_LOCATION "/submit.php?project=${CTEST_PROJECT_NAME}") 9 | set(CTEST_DROP_SITE_CDASH TRUE) 10 | -------------------------------------------------------------------------------- /third-party/cmocka/coverity/README: -------------------------------------------------------------------------------- 1 | coverity_assert_model.c: 2 | 3 | This file is a Coverity Modeling file for projects using CMocka for unit 4 | testing. The assert functiions could create false positives, to avoid that you 5 | can load this modeling file in the Coverity web interface. 6 | 7 | coverity_internal_model.c: 8 | 9 | This file is for the CMocka source code itself. 10 | -------------------------------------------------------------------------------- /third-party/cmocka/DefineOptions.cmake: -------------------------------------------------------------------------------- 1 | option(WITH_STATIC_LIB "Build with a static library" OFF) 2 | option(WITH_CMOCKERY_SUPPORT "Install a cmockery header" OFF) 3 | option(WITH_EXAMPLES "Build examples" ON) 4 | option(UNIT_TESTING "Build with unit testing" OFF) 5 | option(PICKY_DEVELOPER "Build with picky developer flags" OFF) 6 | 7 | if (WITH_STATIC_LIB) 8 | set(BUILD_STATIC_LIB ON) 9 | endif (WITH_STATIC_LIB) 10 | 11 | if (UNIT_TESTING) 12 | set(BUILD_STATIC_LIB ON) 13 | endif (UNIT_TESTING) 14 | -------------------------------------------------------------------------------- /third-party/cmocka/example/simple_test.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | /* A test case that does nothing and succeeds. */ 8 | static void null_test_success(void **state) { 9 | (void) state; /* unused */ 10 | } 11 | 12 | int main(void) { 13 | const struct CMUnitTest tests[] = { 14 | cmocka_unit_test(null_test_success), 15 | }; 16 | 17 | return cmocka_run_group_tests(tests, NULL, NULL); 18 | } 19 | -------------------------------------------------------------------------------- /doc/footer.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 9 | 10 | 11 | 14 | 15 | 16 | 17 | -------------------------------------------------------------------------------- /third-party/uthash/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "description": "C macros for hash tables and more", 3 | 4 | "keywords": [ 5 | "array", 6 | "data", 7 | "hash", 8 | "list", 9 | "macro", 10 | "string", 11 | "structure", 12 | "uthash" 13 | ], 14 | 15 | "name": "uthash", 16 | "repo": "troydhanson/uthash", 17 | 18 | "src": [ 19 | "src/utarray.h", 20 | "src/uthash.h", 21 | "src/utlist.h", 22 | "src/utringbuffer.h", 23 | "src/utstring.h" 24 | ], 25 | 26 | "version": "2.0.1" 27 | } 28 | -------------------------------------------------------------------------------- /third-party/cmocka/include/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(cmocka-header C) 2 | 3 | install(FILES 4 | cmocka.h 5 | cmocka_pbc.h 6 | DESTINATION 7 | ${CMAKE_INSTALL_INCLUDEDIR} 8 | COMPONENT 9 | ${PROJECT_NAME}) 10 | 11 | if (WITH_CMOCKERY_SUPPORT) 12 | install(FILES 13 | cmockery/cmockery.h 14 | cmockery/pbc.h 15 | DESTINATION 16 | ${CMAKE_INSTALL_INCLUDEDIR}/cmockery 17 | COMPONENT 18 | ${PROJECT_NAME}) 19 | endif() 20 | -------------------------------------------------------------------------------- /third-party/cmocka/cmocka-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | get_filename_component(CMOCKA_CMAKE_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 4 | 5 | if (EXISTS "${CMOCKA_CMAKE_DIR}/CMakeCache.txt") 6 | # In build tree 7 | include(${CMOCKA_CMAKE_DIR}/cmocka-build-tree-settings.cmake) 8 | else() 9 | set(CMOCKA_INCLUDE_DIR @PACKAGE_INCLUDE_INSTALL_DIR@) 10 | endif() 11 | 12 | set(CMOCKA_LIBRARY @PACKAGE_LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) 13 | set(CMOCKA_LIBRARIES @PACKAGE_LIB_INSTALL_DIR@/@CMOCKA_LIBRARY_NAME@) 14 | 15 | mark_as_advanced(CMOCKA_LIBRARY CMOCKA_INCLUDE_DIR) 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Debug 2 | Release 3 | cmake-build* 4 | build 5 | __pycache__ 6 | *.pyo 7 | *.pyc 8 | *.atsuo 9 | *.pyd 10 | .eggs/ 11 | *.egg-info/ 12 | dist/* 13 | .DS_Store 14 | 15 | pyfitterbap/crc.c 16 | pyfitterbap/comm/comm.c 17 | 18 | # Compiled Object files 19 | *.slo 20 | *.lo 21 | *.o 22 | 23 | # Compiled Dynamic libraries 24 | *.so 25 | *.dylib 26 | *.elf 27 | *.objdump 28 | *.flash 29 | *.map 30 | 31 | # Compiled Static libraries 32 | *.lai 33 | *.la 34 | 35 | # Editor swap/backup file garbage 36 | .*.swp 37 | .*.swo 38 | 39 | .force_relink 40 | .force_rebuild 41 | 42 | .idea 43 | 44 | -------------------------------------------------------------------------------- /third-party/README.md: -------------------------------------------------------------------------------- 1 | # Third-party libraries 2 | 3 | The Fitterbap library is distributed alongside several very useful third-party 4 | libraries. Each of these libraries are provided under their respective 5 | licenses. 6 | 7 | * [cmocka](cmocka/LICENSE.txt) Apache 2.0 : 1.1.0+ (git commit: 26717f4909039803b231434740ef3ce005258dae) 8 | * [tinyprintf](tinyprintf/tinyprintf_LICENSE.BSD-new) BSD 9 | * [uthash](uthash/LICENSE) BSD 10 | 11 | ## Other libraries 12 | 13 | Although not included with Fitterbap, the following libraries may be of interest: 14 | 15 | * [xprintf](http://elm-chan.org/fsw/strf/xprintf.html) 16 | -------------------------------------------------------------------------------- /pyfitterbap/comm/ui/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from .main import run 16 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Modules/DefinePlatformDefaults.cmake: -------------------------------------------------------------------------------- 1 | # Set system vars 2 | 3 | if (CMAKE_SYSTEM_NAME MATCHES "Linux") 4 | set(LINUX TRUE) 5 | endif(CMAKE_SYSTEM_NAME MATCHES "Linux") 6 | 7 | if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") 8 | set(FREEBSD TRUE) 9 | endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD") 10 | 11 | if (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") 12 | set(OPENBSD TRUE) 13 | endif (CMAKE_SYSTEM_NAME MATCHES "OpenBSD") 14 | 15 | if (CMAKE_SYSTEM_NAME MATCHES "NetBSD") 16 | set(NETBSD TRUE) 17 | endif (CMAKE_SYSTEM_NAME MATCHES "NetBSD") 18 | 19 | if (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") 20 | set(SOLARIS TRUE) 21 | endif (CMAKE_SYSTEM_NAME MATCHES "(Solaris|SunOS)") 22 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/chef_wrap/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(cmocka-wrap-examples C) 2 | 3 | include_directories( 4 | ${CMAKE_BINARY_DIR} 5 | ${CMAKE_CURRENT_SOURCE_DIR} 6 | ${CMOCKA_PUBLIC_INCLUDE_DIRS} 7 | ) 8 | 9 | add_executable(waiter_test_wrap waiter_test_wrap.c chef.c) 10 | target_link_libraries(waiter_test_wrap ${CMOCKA_SHARED_LIBRARY}) 11 | 12 | add_test(waiter_test_wrap ${CMAKE_CURRENT_BINARY_DIR}/waiter_test_wrap) 13 | 14 | set_target_properties(waiter_test_wrap 15 | PROPERTIES 16 | LINK_FLAGS "-Wl,--wrap=chef_cook" 17 | ) 18 | if (WIN32 OR MINGW OR CYGWIN) 19 | set_tests_properties(waiter_test_wrap PROPERTIES ENVIRONMENT "PATH=${DLL_PATH_ENV}") 20 | endif (WIN32 OR MINGW OR CYGWIN) 21 | -------------------------------------------------------------------------------- /third-party/cmocka/README.md: -------------------------------------------------------------------------------- 1 | cmocka 2 | ====== 3 | 4 | cmocka is an elegant unit testing framework for C with support for mock 5 | objects. It only requires the standard C library, works on a range of computing 6 | platforms (including embedded) and with different compilers. 7 | 8 | For information about how to use the cmocka unit testing framework see 9 | doc/index.html or https://api.cmocka.org/. 10 | 11 | Compiling 12 | --------- 13 | 14 | To compile the cmocka library and example applications run, create a build dir, 15 | and in the build dir call 'cmake /path/to/cmocka' followed by 'make'. On 16 | Windows you can use the cmake gui. More details can be found in the INSTALL file. 17 | 18 | Website 19 | ------- 20 | 21 | https://cmocka.org 22 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Toolchain-Debian-mips.cmake: -------------------------------------------------------------------------------- 1 | include(CMakeForceCompiler) 2 | 3 | set(TOOLCHAIN_PREFIX mips-linux-gnu) 4 | 5 | set(CMAKE_SYSTEM_NAME Linux) 6 | set(CMAKE_SYSTEM_VERSION 1) 7 | set(CMAKE_SYSTEM_PROCESSOR mips) 8 | 9 | # This is the location of the mips toolchain 10 | set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}-gcc) 11 | set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}-g++) 12 | 13 | # This is the file system root of the target 14 | set(CMAKE_FIND_ROOT_PATH /usr/${TOOLCHAIN_PREFIX}) 15 | 16 | # Search for programs in the build host directories 17 | set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) 18 | 19 | # For libraries and headers in the target directories 20 | set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) 21 | set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) 22 | -------------------------------------------------------------------------------- /test/collections/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | ADD_CMOCKA_TEST(list_test) 16 | ADD_CMOCKA_TEST(msg_ring_buffer_test) 17 | ADD_CMOCKA_TEST(ring_buffer_u64_test) 18 | -------------------------------------------------------------------------------- /third-party/cmocka/example/assert_module.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | void increment_value(int * const value); 18 | void decrement_value(int * const value); 19 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Modules/MacroEnsureOutOfSourceBuild.cmake: -------------------------------------------------------------------------------- 1 | # - MACRO_ENSURE_OUT_OF_SOURCE_BUILD() 2 | # MACRO_ENSURE_OUT_OF_SOURCE_BUILD() 3 | 4 | # Copyright (c) 2006, Alexander Neundorf, 5 | # 6 | # Redistribution and use is allowed according to the terms of the BSD license. 7 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 8 | 9 | macro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD _errorMessage) 10 | 11 | string(COMPARE EQUAL "${CMAKE_SOURCE_DIR}" "${CMAKE_BINARY_DIR}" _insource) 12 | if (_insource) 13 | message(SEND_ERROR "${_errorMessage}") 14 | message(FATAL_ERROR "Remove the file CMakeCache.txt in ${CMAKE_SOURCE_DIR} first.") 15 | endif (_insource) 16 | 17 | endmacro (MACRO_ENSURE_OUT_OF_SOURCE_BUILD) 18 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/uptime/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | add_library(proc_uptime proc_uptime.c) 2 | 3 | add_executable(uptime uptime.c) 4 | target_compile_options(uptime PRIVATE ${DEFAULT_C_COMPILE_FLAGS}) 5 | target_link_libraries(uptime proc_uptime) 6 | set_property(TARGET 7 | uptime 8 | PROPERTY 9 | LINK_FLAGS 10 | "${DEFAULT_LINK_FLAGS}") 11 | 12 | add_cmocka_test(test_uptime 13 | SOURCES test_uptime.c 14 | COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} 15 | LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) 16 | set_property(TARGET 17 | test_uptime 18 | PROPERTY 19 | LINK_FLAGS 20 | "${DEFAULT_LINK_FLAGS} -Wl,--wrap=uptime") 21 | -------------------------------------------------------------------------------- /test/memory/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | ADD_CMOCKA_TEST(bbuf_test) 16 | ADD_CMOCKA_TEST(block_test) 17 | ADD_CMOCKA_TEST(buffer_test) 18 | ADD_CMOCKA_TEST(object_pool_test) 19 | ADD_CMOCKA_TEST(pool_test) 20 | -------------------------------------------------------------------------------- /test/cdef_static_assert_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/cdef.h" 18 | 19 | 20 | FBP_STATIC_ASSERT(0 == 1, identity_false); 21 | 22 | int main(void) { 23 | return 0; 24 | } 25 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_group_setup_fail.c: -------------------------------------------------------------------------------- 1 | /* Use the unit test allocators */ 2 | #define UNIT_TESTING 1 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static int group_setup_failing(void **state) 10 | { 11 | (void) state; /* unused */ 12 | return 1; /* To indicate the failure */ 13 | } 14 | 15 | static void test_true(void **state) 16 | { 17 | (void) state; /* unused */ 18 | assert_true(1); 19 | } 20 | 21 | static void test_false(void **state) 22 | { 23 | (void) state; /* unused */ 24 | assert_false(0); 25 | } 26 | 27 | int main(void) { 28 | const struct CMUnitTest tests[] = { 29 | cmocka_unit_test(test_true), 30 | cmocka_unit_test(test_false), 31 | }; 32 | 33 | return cmocka_run_group_tests(tests, group_setup_failing, NULL); 34 | } 35 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_group_setup_assert.c: -------------------------------------------------------------------------------- 1 | /* Use the unit test allocators */ 2 | #define UNIT_TESTING 1 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static int group_setup_failing(void **state) 10 | { 11 | (void) state; /* unused */ 12 | 13 | assert_int_equal(0, 1); 14 | 15 | return 0; 16 | } 17 | 18 | static void test_true(void **state) 19 | { 20 | (void) state; /* unused */ 21 | assert_true(1); 22 | } 23 | 24 | static void test_false(void **state) 25 | { 26 | (void) state; /* unused */ 27 | assert_false(0); 28 | } 29 | 30 | int main(void) { 31 | const struct CMUnitTest tests[] = { 32 | cmocka_unit_test(test_true), 33 | cmocka_unit_test(test_false), 34 | }; 35 | 36 | return cmocka_run_group_tests(tests, group_setup_failing, NULL); 37 | } 38 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/chef_wrap/chef.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 (c) Andreas Schneider 3 | * Jakub Hrozek 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | int chef_cook(const char *order, char **dish_out); 19 | const char *chef_strerror(int error); 20 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/uptime/proc_uptime.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Andreas Scheider 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _PROC_UPTIME_H 18 | #define _PROC_UPTIME_H 19 | 20 | int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs); 21 | 22 | #endif /* _PROC_UPTIME_H */ 23 | -------------------------------------------------------------------------------- /pyfitterbap/entry_points/comm_ui.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from pyfitterbap.comm.ui import run 16 | import logging 17 | 18 | log = logging.getLogger(__name__) 19 | 20 | 21 | def parser_config(p): 22 | """Run the data link user interface.""" 23 | return on_cmd 24 | 25 | 26 | def on_cmd(args): 27 | return run() 28 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Modules/DefineCMakeDefaults.cmake: -------------------------------------------------------------------------------- 1 | # Always include srcdir and builddir in include path 2 | # This saves typing ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY} in 3 | # about every subdir 4 | # since cmake 2.4.0 5 | set(CMAKE_INCLUDE_CURRENT_DIR ON) 6 | 7 | # Put the include dirs which are in the source or build tree 8 | # before all other include dirs, so the headers in the sources 9 | # are prefered over the already installed ones 10 | # since cmake 2.4.1 11 | set(CMAKE_INCLUDE_DIRECTORIES_PROJECT_BEFORE ON) 12 | 13 | # Use colored output 14 | # since cmake 2.4.0 15 | set(CMAKE_COLOR_MAKEFILE ON) 16 | 17 | # Create the compile command database for clang by default 18 | set(CMAKE_EXPORT_COMPILE_COMMANDS ON) 19 | 20 | # Always build with -fPIC 21 | set(CMAKE_POSITION_INDEPENDENT_CODE ON) 22 | 23 | # Avoid source tree pollution 24 | set(CMAKE_DISABLE_SOURCE_CHANGES ON) 25 | set(CMAKE_DISABLE_IN_SOURCE_BUILD ON) 26 | -------------------------------------------------------------------------------- /pyfitterbap/entry_points/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2018-2021 Jetperch LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | from . import crc, comm_ui 17 | 18 | __all__ = [crc, comm_ui] 19 | """This list of available command modules. Each module must contain a 20 | parser_config(subparser) function. The function must return the callable(args) 21 | that will be executed for the command.""" 22 | -------------------------------------------------------------------------------- /src/host/platform_alloc.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/common_header.h" 18 | #include 19 | 20 | void * fbp_alloc_(fbp_size_t size_bytes) { 21 | void * ptr = malloc(size_bytes); 22 | FBP_ASSERT_ALLOC(ptr); 23 | return ptr; 24 | } 25 | 26 | void fbp_free_(void * ptr) { 27 | free(ptr); 28 | } 29 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Modules/AddCCompilerFlag.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # add_c_compiler_flag("-Werror" SUPPORTED_CFLAGS) 3 | # 4 | # Copyright (c) 2018 Andreas Schneider 5 | # 6 | # Redistribution and use is allowed according to the terms of the BSD license. 7 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 8 | 9 | include(CheckCCompilerFlag) 10 | 11 | macro(add_c_compiler_flag _COMPILER_FLAG _OUTPUT_VARIABLE) 12 | string(TOUPPER ${_COMPILER_FLAG} _COMPILER_FLAG_NAME) 13 | string(REGEX REPLACE "^-" "" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}") 14 | string(REGEX REPLACE "(-|=|\ )" "_" _COMPILER_FLAG_NAME "${_COMPILER_FLAG_NAME}") 15 | 16 | check_c_compiler_flag("${_COMPILER_FLAG}" WITH_${_COMPILER_FLAG_NAME}_FLAG) 17 | if (WITH_${_COMPILER_FLAG_NAME}_FLAG) 18 | #string(APPEND ${_OUTPUT_VARIABLE} "${_COMPILER_FLAG} ") 19 | list(APPEND ${_OUTPUT_VARIABLE} ${_COMPILER_FLAG}) 20 | endif() 21 | endmacro() 22 | -------------------------------------------------------------------------------- /pyfitterbap/version.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | __version__ = "0.5.2" 17 | 18 | __title__ = 'pyfitterbap' 19 | __description__ = 'Fitterbap python bindings' 20 | __url__ = 'https://github.com/jetperch/fitterbap' 21 | __author__ = 'Jetperch LLC' 22 | __author_email__ = 'dev@jetperch.com' 23 | __license__ = 'Apache 2.0' 24 | __copyright__ = 'Copyright 2017-2021 Jetperch LLC' 25 | -------------------------------------------------------------------------------- /pyfitterbap/time.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import dateutil.parser 16 | import datetime 17 | 18 | 19 | FBP_TIME_EPOCH_UNIX_OFFSET_SECONDS = dateutil.parser.parse('2018-01-01T00:00:00Z').timestamp() 20 | Q_GAIN = 2 ** 30 21 | 22 | 23 | def now(): 24 | k = datetime.datetime.utcnow().timestamp() 25 | rel_s = k - FBP_TIME_EPOCH_UNIX_OFFSET_SECONDS 26 | return int(rel_s * Q_GAIN) 27 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_assert_macros.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #ifdef HAVE_UNISTD_H 13 | #include 14 | #endif 15 | #include 16 | 17 | /************************************** 18 | *** assert_return_code 19 | **************************************/ 20 | static void test_assert_return_code(void **state) 21 | { 22 | struct stat sb; 23 | int rc; 24 | 25 | (void)state; /* unused */ 26 | 27 | rc = stat(".", &sb); 28 | assert_return_code(rc, 0); 29 | 30 | #ifndef _MSC_VER 31 | assert_true(S_ISDIR(sb.st_mode)); 32 | #endif 33 | } 34 | 35 | int main(void) { 36 | const struct CMUnitTest tests[] = { 37 | cmocka_unit_test(test_assert_return_code), 38 | }; 39 | 40 | return cmocka_run_group_tests(tests, NULL, NULL); 41 | } 42 | -------------------------------------------------------------------------------- /pyfitterbap/c_crc.pxd: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | from libc.stdint cimport uint8_t, uint16_t, uint32_t 16 | 17 | cdef extern from "fitterbap/crc.h": 18 | 19 | uint8_t fbp_crc_ccitt_8(uint8_t crc, const uint8_t *data, uint32_t length) 20 | uint16_t fbp_crc_ccitt_16(uint16_t crc, const uint8_t *data, uint32_t length) 21 | uint32_t fbp_crc32(uint32_t crc, const uint8_t *data, uint32_t length) 22 | -------------------------------------------------------------------------------- /include/fitterbap/host/linux/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Default linux host configuration. 21 | */ 22 | 23 | #ifndef FBP_HOST_LINUX_CONFIG_H__ 24 | #define FBP_HOST_LINUX_CONFIG_H__ 25 | 26 | #include 27 | 28 | typedef void * fbp_os_mutex_t; 29 | typedef intptr_t fbp_size_t; 30 | 31 | #endif /* FBP_HOST_LINUX_CONFIG_H__ */ 32 | -------------------------------------------------------------------------------- /include/fitterbap/host/win/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Default windows host configuration. 21 | */ 22 | 23 | #ifndef FBP_HOST_WIN_CONFIG_H__ 24 | #define FBP_HOST_WIN_CONFIG_H__ 25 | 26 | #include 27 | 28 | typedef void * fbp_os_mutex_t; 29 | typedef intptr_t fbp_size_t; 30 | 31 | #endif /* FBP_HOST_WIN_CONFIG_H__ */ 32 | 33 | -------------------------------------------------------------------------------- /pyfitterbap/include/fitterbap/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief FBP platform. 21 | */ 22 | 23 | #ifndef FBP_PY_PLATFORM_H_ 24 | #define FBP_PY_PLATFORM_H_ 25 | 26 | // todo linux & mac support 27 | #if defined(WIN32) || defined(_WIN32) 28 | #include "fitterbap/host/win/platform.h" 29 | #else 30 | #endif 31 | 32 | /** @} */ 33 | 34 | #endif /* FBP_PY_PLATFORM_H_ */ 35 | 36 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_assert_macros_fail.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | #ifdef HAVE_UNISTD_H 13 | #include 14 | #endif 15 | #ifdef HAVE_IO_H 16 | #include 17 | #endif 18 | #include 19 | 20 | /************************************** 21 | *** assert_return_code 22 | **************************************/ 23 | static void test_assert_return_code_fail(void **state) 24 | { 25 | int fd; 26 | 27 | (void)state; /* unused */ 28 | 29 | fd = open("this_file_doesnt_exist.cmocka", 0); 30 | assert_return_code(fd, errno); 31 | 32 | if (fd >= 0) { 33 | close(fd); 34 | } 35 | } 36 | 37 | int main(void) { 38 | const struct CMUnitTest tests[] = { 39 | cmocka_unit_test(test_assert_return_code_fail), 40 | }; 41 | 42 | return cmocka_run_group_tests(tests, NULL, NULL); 43 | } 44 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_exception_handler.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | struct test_segv { 9 | int x; 10 | int y; 11 | }; 12 | 13 | static void test_segfault_recovery(void **state) 14 | { 15 | struct test_segv *s = NULL; 16 | 17 | (void) state; /* unused */ 18 | 19 | s->x = 1; 20 | } 21 | 22 | static void test_segfault_recovery1(void **state) 23 | { 24 | test_segfault_recovery(state); 25 | } 26 | 27 | static void test_segfault_recovery2(void **state) 28 | { 29 | test_segfault_recovery(state); 30 | } 31 | 32 | static void test_segfault_recovery3(void **state) 33 | { 34 | test_segfault_recovery(state); 35 | } 36 | 37 | int main(void) { 38 | const struct CMUnitTest tests[] = { 39 | cmocka_unit_test(test_segfault_recovery1), 40 | cmocka_unit_test(test_segfault_recovery2), 41 | cmocka_unit_test(test_segfault_recovery3), 42 | }; 43 | 44 | return cmocka_run_group_tests(tests, NULL, NULL); 45 | } 46 | -------------------------------------------------------------------------------- /src/host/freertos/os_task.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #include "fitterbap/os/task.h" 19 | #include "FreeRTOS.h" 20 | #include "task.h" 21 | 22 | FBP_API intptr_t fbp_os_current_task_id() { 23 | return ((intptr_t) xTaskGetCurrentTaskHandle()); 24 | } 25 | 26 | void fbp_os_sleep(int64_t duration) { 27 | if (duration < 0) { 28 | return; 29 | } 30 | vTaskDelay(FBP_TIME_TO_COUNTER(duration, configTICK_RATE_HZ)); 31 | } 32 | -------------------------------------------------------------------------------- /src/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/version.h" 18 | #include "tinyprintf.h" 19 | 20 | 21 | void fbp_version_u32_to_str(uint32_t u32, char * str, size_t size) { 22 | uint8_t major = FBP_VERSION_DECODE_U32_MAJOR(u32); 23 | uint8_t minor = FBP_VERSION_DECODE_U32_MINOR(u32); 24 | uint16_t patch = FBP_VERSION_DECODE_U32_PATCH(u32); 25 | tfp_snprintf(str, size, "%d.%d.%d", (int) major, (int) minor, (int) patch); 26 | } 27 | -------------------------------------------------------------------------------- /port/include/fitterbap/platform.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Host platform common definition file. 21 | */ 22 | 23 | #ifndef FBP_PORT_PLATFORM_H_ 24 | #define FBP_PORT_PLATFORM_H_ 25 | 26 | // todo linux & mac support 27 | #if defined(WIN32) || defined(_WIN32) 28 | #include "fitterbap/host/win/platform.h" 29 | #else 30 | #error "unsupported platform" 31 | #endif 32 | 33 | 34 | #endif /* FBP_PORT_PLATFORM_H_ */ 35 | -------------------------------------------------------------------------------- /include/fitterbap/common_header.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Common header includes. 21 | */ 22 | 23 | #ifndef FBP_COMMON_HEADER_H__ 24 | #define FBP_COMMON_HEADER_H__ 25 | 26 | #include "fitterbap/cmacro_inc.h" 27 | #include "fitterbap/config.h" 28 | #include "fitterbap/config_defaults.h" 29 | #include "fitterbap/platform_dependencies.h" 30 | #include "fitterbap/platform.h" 31 | 32 | #endif /* FBP_COMMON_HEADER_H__ */ 33 | -------------------------------------------------------------------------------- /src/comm/port.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/comm/port.h" 18 | 19 | int32_t fbp_port_register(struct fbp_port_api_s * self, const struct fbp_port_config_s * config) { 20 | int32_t rc = self->initialize(self, config); 21 | if (rc) { 22 | return rc; 23 | } 24 | return fbp_transport_port_register(config->transport, config->port_id, self->meta, 25 | self->on_event, self->on_recv, self); 26 | } 27 | -------------------------------------------------------------------------------- /test/comm/count_table_u8.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | import numpy as np 17 | 18 | 19 | def run(): 20 | counts = np.zeros(256, dtype=np.uint8) 21 | for i in range(256): 22 | k = i 23 | while k: 24 | if k & 1: 25 | counts[i] += 1 26 | k = k >> 1 27 | counts_str = [str(x) for x in counts] 28 | for i in range(0, 256, 16): 29 | print(', '.join(counts_str[i:i+16]) + ',') 30 | 31 | 32 | if __name__ == '__main__': 33 | run() 34 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_cmockery.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | /* A test case that does nothing and succeeds. */ 23 | static void null_test_success(void **state) { 24 | (void) state; /* unused */ 25 | } 26 | 27 | int main(void) { 28 | const UnitTest tests[] = { 29 | unit_test(null_test_success), 30 | }; 31 | return run_tests(tests); 32 | } 33 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2018-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | check-manifest>=0.37 16 | coverage>=4.5.2 17 | Cython>=0.29.3 18 | m2r 19 | # https://developercommunity.visualstudio.com/content/problem/1207405/fmod-after-an-update-to-windows-2004-is-causing-a.html 20 | numpy>=1.20 21 | psutil 22 | pypiwin32>=223; sys_platform == 'win32' 23 | # python {path_to_python}\scripts\pywin32_postinstall.py -install 24 | pyqtgraph>=0.12 25 | pyserial 26 | PySide6>=6.1.0 27 | python-dateutil>=2.7.3 28 | recommonmark 29 | sphinx>=3.1.0 30 | wheel 31 | -------------------------------------------------------------------------------- /third-party/cmocka/doc/that_style/js/striped_bg.js: -------------------------------------------------------------------------------- 1 | // Adds extra CSS classes "even" and "odd" to .memberdecls to allow 2 | // striped backgrounds. 3 | function MemberDeclsStriper () { 4 | var counter = 0; 5 | 6 | this.stripe = function() { 7 | $(".memberdecls tbody").children().each(function(i) { 8 | 9 | // reset counter at every heading -> always start with even 10 | if ($(this).is(".heading")) { 11 | counter = 0; 12 | } 13 | 14 | // add extra classes 15 | if (counter % 2 == 1) { 16 | $(this).addClass("odd"); 17 | } 18 | else { 19 | $(this).addClass("even"); 20 | } 21 | 22 | // advance counter at every separator 23 | // this is the only way to reliably detect which table rows belong together 24 | if ($(this).is('[class^="separator"]')) { 25 | counter++; 26 | } 27 | }); 28 | } 29 | } 30 | 31 | // execute the function 32 | $(document).ready(new MemberDeclsStriper().stripe); 33 | -------------------------------------------------------------------------------- /pyfitterbap/entry_points/crc.py: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | import numpy as np 16 | from pyfitterbap import crc 17 | 18 | 19 | def parser_config(p): 20 | """compute CRC.""" 21 | p.add_argument('--data', 22 | help='The CRC data.') 23 | return on_cmd 24 | 25 | 26 | def on_cmd(args): 27 | if args.data is not None: 28 | x = np.array([int(x, 0) for x in args.data.split(',')], dtype=np.uint8) 29 | y = crc.crc32(0, x) 30 | print(f'0x{y:08x}') 31 | return 0 32 | return 1 33 | 34 | -------------------------------------------------------------------------------- /third-party/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | set(INCLUDES 4 | ${CMAKE_CURRENT_SOURCE_DIR}/uthash/src 5 | ${CMAKE_CURRENT_SOURCE_DIR}/tinyprintf 6 | ) 7 | 8 | if (NOT CMAKE_CROSSCOMPILING) 9 | SET(cmocka_dir ${CMAKE_CURRENT_SOURCE_DIR}/../third-party/cmocka) 10 | include(CheckCCompilerFlag) 11 | include(${cmocka_dir}/ConfigureChecks.cmake) 12 | configure_file(${cmocka_dir}/config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config.h) 13 | include_directories(${CMAKE_CURRENT_BINARY_DIR}) 14 | include_directories(${cmocka_dir}/include) 15 | include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../third-party/uthash/src) 16 | if (CMAKE_COMPILER_IS_GNUCC) 17 | add_definitions(-Wno-format) 18 | endif() 19 | add_library(cmocka STATIC 20 | ${cmocka_dir}/src/cmocka.c) 21 | target_compile_definitions(cmocka PRIVATE -DHAVE_CONFIG_H=1) 22 | set(CMOCKA_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/cmocka/include CACHE INTERNAL "cmocka include" FORCE) 23 | set(CMOCKA_LIBS cmocka CACHE INTERNAL "cmocka lib" FORCE) 24 | endif() 25 | 26 | set(THIRD_PARTY_INCLUDES ${INCLUDES} PARENT_SCOPE) 27 | set(THIRD_PARTY_LIBS "" PARENT_SCOPE) 28 | -------------------------------------------------------------------------------- /third-party/cmocka/doc/that_style/LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Jan-Lukas Wynen 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /src/log.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/log.h" 18 | #include 19 | 20 | 21 | char const * const fbp_log_level_str[FBP_LOG_LEVEL_ALL + 1] = { 22 | "EMERGENCY", 23 | "ALERT", 24 | "CRITICAL", 25 | "ERROR", 26 | "WARN", 27 | "NOTICE" 28 | "INFO", 29 | "DEBUG", 30 | "DEBUG2" 31 | "DEBUG3", 32 | "ALL" 33 | }; 34 | 35 | char const fbp_log_level_char[FBP_LOG_LEVEL_ALL + 1] = { 36 | '!', 'A', 'C', 'E', 'W', 'N', 'I', 'D', 'D', 'D', '.' 37 | }; 38 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_skip.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | /* A test case that does check if an int is equal. */ 23 | static void test_check_skip(void **state) { 24 | (void)state; /* unused */ 25 | 26 | skip(); 27 | 28 | assert_true(0); 29 | } 30 | 31 | 32 | int main(void) { 33 | const struct CMUnitTest tests[] = { 34 | cmocka_unit_test(test_check_skip), 35 | }; 36 | 37 | return cmocka_run_group_tests(tests, NULL, NULL); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_group_fixtures.c: -------------------------------------------------------------------------------- 1 | /* Use the unit test allocators */ 2 | #define UNIT_TESTING 1 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static int group_setup(void **state) 10 | { 11 | int *answer = malloc(sizeof(int)); 12 | assert_non_null(answer); 13 | *answer = 42; 14 | 15 | *state = answer; 16 | return 0; 17 | } 18 | 19 | static int group_teardown(void **state) 20 | { 21 | int *answer = (int *)*state; 22 | 23 | free(answer); 24 | return 0; 25 | } 26 | 27 | static void test_value_equal(void **state) 28 | { 29 | int a = *((int *)*state); 30 | 31 | assert_int_equal(a, 42); 32 | } 33 | 34 | static void test_value_range(void **state) 35 | { 36 | int a = *((int *)*state); 37 | 38 | assert_in_range(a, 0, 100); 39 | } 40 | 41 | int main(void) { 42 | int prestate = 1337; 43 | const struct CMUnitTest tests[] = { 44 | cmocka_unit_test(test_value_equal), 45 | cmocka_unit_test(test_value_range), 46 | cmocka_unit_test_prestate(test_value_equal, &prestate), 47 | }; 48 | 49 | return cmocka_run_group_tests(tests, group_setup, group_teardown); 50 | } 51 | -------------------------------------------------------------------------------- /third-party/uthash/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2005-2014, Troy D. Hanson http://troydhanson.github.com/uthash/ 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 10 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 11 | IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 12 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 13 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 14 | OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 15 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 16 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 17 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 18 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 19 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 20 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 21 | 22 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Toolchain-cross-m32.cmake: -------------------------------------------------------------------------------- 1 | set(CMAKE_C_FLAGS "-m32" CACHE STRING "C compiler flags" FORCE) 2 | set(CMAKE_CXX_FLAGS "-m32" CACHE STRING "C++ compiler flags" FORCE) 3 | 4 | set(LIB32 /usr/lib) # Fedora 5 | 6 | if(EXISTS /usr/lib32) 7 | set(LIB32 /usr/lib32) # Arch, Solus 8 | endif() 9 | 10 | set(CMAKE_SYSTEM_LIBRARY_PATH ${LIB32} CACHE STRING "system library search path" FORCE) 11 | set(CMAKE_LIBRARY_PATH ${LIB32} CACHE STRING "library search path" FORCE) 12 | 13 | # this is probably unlikely to be needed, but just in case 14 | set(CMAKE_EXE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "executable linker flags" FORCE) 15 | set(CMAKE_SHARED_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "shared library linker flags" FORCE) 16 | set(CMAKE_MODULE_LINKER_FLAGS "-m32 -L${LIB32}" CACHE STRING "module linker flags" FORCE) 17 | 18 | # on Fedora and Arch and similar, point pkgconfig at 32 bit .pc files. We have 19 | # to include the regular system .pc files as well (at the end), because some 20 | # are not always present in the 32 bit directory 21 | if(EXISTS ${LIB32}/pkgconfig) 22 | set(ENV{PKG_CONFIG_LIBDIR} ${LIB32}/pkgconfig:/usr/share/pkgconfig:/usr/lib/pkgconfig:/usr/lib64/pkgconfig) 23 | endiF() 24 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_setup_fail.c: -------------------------------------------------------------------------------- 1 | #define UNIT_TESTING 1 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | static int setup_fail(void **state) { 9 | *state = NULL; 10 | 11 | /* We need to fail in setup */ 12 | return -1; 13 | } 14 | 15 | static void int_test_ignored(void **state) { 16 | /* should not be called */ 17 | assert_non_null(*state); 18 | } 19 | 20 | static int setup_ok(void **state) { 21 | int *answer; 22 | 23 | answer = malloc(sizeof(int)); 24 | if (answer == NULL) { 25 | return -1; 26 | } 27 | *answer = 42; 28 | 29 | *state = answer; 30 | 31 | return 0; 32 | } 33 | 34 | /* A test case that does check if an int is equal. */ 35 | static void int_test_success(void **state) { 36 | int *answer = *state; 37 | 38 | assert_int_equal(*answer, 42); 39 | } 40 | 41 | static int teardown(void **state) { 42 | free(*state); 43 | 44 | return 0; 45 | } 46 | 47 | int main(void) { 48 | const struct CMUnitTest tests[] = { 49 | cmocka_unit_test_setup_teardown(int_test_ignored, setup_fail, teardown), 50 | cmocka_unit_test_setup_teardown(int_test_success, setup_ok, teardown), 51 | }; 52 | 53 | return cmocka_run_group_tests(tests, NULL, NULL); 54 | } 55 | -------------------------------------------------------------------------------- /third-party/cmocka/5.patch: -------------------------------------------------------------------------------- 1 | From addb1927eb979310a01abc65f29a5408a970da11 Mon Sep 17 00:00:00 2001 2 | From: Richard Bayerle 3 | Date: Sun, 24 Feb 2019 16:38:05 +0000 4 | Subject: [PATCH] XML output is JUnit XML, not xUnit XML. 5 | 6 | --- 7 | doc/mainpage.dox | 4 ++-- 8 | 1 file changed, 2 insertions(+), 2 deletions(-) 9 | 10 | diff --git a/doc/mainpage.dox b/doc/mainpage.dox 11 | index 4c26d96..c378bb1 100644 12 | --- a/doc/mainpage.dox 13 | +++ b/doc/mainpage.dox 14 | @@ -33,7 +33,7 @@ The CMocka library provides: 15 | - Very well tested 16 | - Testing of memory leaks, buffer overflows and underflows. 17 | - A set of assert macros. 18 | - - Several supported output formats (stdout, TAP, xUnit XML, Subunit) 19 | + - Several supported output formats (stdout, TAP, JUnit XML, Subunit) 20 | - License: Apache License 2.0 21 | 22 | @section main-test A cmocka test 23 | @@ -119,7 +119,7 @@ supported values are: 24 | - STDOUT for the default standard output printer 25 | - SUBUNIT for subunit output 26 | - TAP for Test Anything Protocol (TAP) output 27 | - - XML for xUnit XML format 28 | + - XML for JUnit XML format 29 | The case doesn't matter. 30 | 31 | The XML output goes to stderr by default. If the environment variable 32 | -- 33 | 2.18.1 34 | 35 | -------------------------------------------------------------------------------- /third-party/cmocka/example/assert_module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | 18 | #include "assert_module.h" 19 | 20 | /* If unit testing is enabled override assert with mock_assert(). */ 21 | #ifdef UNIT_TESTING 22 | extern void mock_assert(const int result, const char* const expression, 23 | const char * const file, const int line); 24 | #undef assert 25 | #define assert(expression) \ 26 | mock_assert(((expression) ? 1 : 0), #expression, __FILE__, __LINE__); 27 | #endif /* UNIT_TESTING */ 28 | 29 | void increment_value(int * const value) { 30 | assert(value); 31 | (*value) ++; 32 | } 33 | 34 | void decrement_value(int * const value) { 35 | if (value) { 36 | (*value) --; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_float_macros.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Arnaud Gelas 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Use the unit test allocators */ 18 | #define UNIT_TESTING 1 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | /* A test case that does check if float is equal. */ 26 | static void float_test_success(void **state) 27 | { 28 | (void)state; /* unused */ 29 | 30 | assert_float_equal(0.5f, 1.f / 2.f, 0.000001f); 31 | assert_float_not_equal(0.5, 0.499f, 0.000001f); 32 | } 33 | 34 | int main(void) { 35 | const struct CMUnitTest tests[] = { 36 | cmocka_unit_test(float_test_success), 37 | }; 38 | 39 | return cmocka_run_group_tests(tests, NULL, NULL); 40 | } 41 | -------------------------------------------------------------------------------- /third-party/cmocka/src/cmocka.def: -------------------------------------------------------------------------------- 1 | LIBRARY cmocka 2 | EXPORTS 3 | _assert_float_equal 4 | _assert_float_not_equal 5 | _assert_in_range 6 | _assert_in_set 7 | _assert_int_equal 8 | _assert_int_not_equal 9 | _assert_memory_equal 10 | _assert_memory_not_equal 11 | _assert_not_in_range 12 | _assert_not_in_set 13 | _assert_return_code 14 | _assert_string_equal 15 | _assert_string_not_equal 16 | _assert_true 17 | _check_expected 18 | _cmocka_run_group_tests 19 | _expect_any 20 | _expect_check 21 | _expect_function_call 22 | _expect_in_range 23 | _expect_in_set 24 | _expect_memory 25 | _expect_not_in_range 26 | _expect_not_in_set 27 | _expect_not_memory 28 | _expect_not_string 29 | _expect_not_value 30 | _expect_string 31 | _expect_value 32 | _fail 33 | _function_called 34 | _mock 35 | _run_test 36 | _run_tests 37 | _skip 38 | _test_calloc 39 | _test_free 40 | _test_malloc 41 | _test_realloc 42 | _will_return 43 | cm_print_error 44 | cmocka_set_message_output 45 | cmocka_set_test_filter 46 | cmocka_set_skip_filter 47 | global_expect_assert_env 48 | global_expecting_assert 49 | global_last_failed_assert 50 | mock_assert 51 | print_error 52 | print_message 53 | vprint_error 54 | vprint_message 55 | -------------------------------------------------------------------------------- /include/fitterbap/host/win/error.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Windows error handling support. 21 | */ 22 | 23 | #ifndef FBP_HOST_WIN_ERROR_H__ 24 | #define FBP_HOST_WIN_ERROR_H__ 25 | 26 | #include 27 | #include "fitterbap/cmacro_inc.h" 28 | 29 | FBP_CPP_GUARD_START 30 | 31 | BOOL GetErrorMessage(DWORD dwErrorCode, char * pBuffer, DWORD cchBufferLength); 32 | 33 | #define WINDOWS_LOGE(format, ...) { \ 34 | char error_msg_[64]; \ 35 | DWORD error_ = GetLastError(); \ 36 | GetErrorMessage(error_, error_msg_, sizeof(error_msg_)); \ 37 | FBP_LOGE(format ": %d: %s", __VA_ARGS__, (int) error_, error_msg_); \ 38 | } 39 | 40 | FBP_CPP_GUARD_END 41 | 42 | #endif /* FBP_HOST_WIN_ERROR_H__ */ 43 | 44 | -------------------------------------------------------------------------------- /third-party/cmocka/doc/that_style/README.md: -------------------------------------------------------------------------------- 1 | # that style 2 | A plain, more modern HTML style for Doxygen 3 | 4 | ## Requirements 5 | - Doxygen (tested with version 1.8.13) 6 | - *optional*: a sass/scss compiler if you want to modify the style 7 | 8 | ## Simple usage 9 | Tell Doxygen about the files for that style as shown in [doxyfile.conf](doxyfile.conf). You might need to adjust the 10 | paths depending on where you installed that style. 11 | When you run Doxygen, all files are copied into to generated HTML folder. So you don't need to keep the originals around 12 | unless you want to re-generate the documentation. 13 | 14 | ## Advanced 15 | that style uses a custom javascript to hack some nice stripes into some tables. It has to be loaded from HTML. Hence you need 16 | to use the provided custom header. Since its default content may change when Doxygen is updated, there might be syntax error in 17 | the generated HTML. If this is the case, you can remove the custom header (adjust your doxyfile.conf). This has no 18 | disadvantages other than removing the stripes. 19 | 20 | [that_style.css](that_style.css) was generated from the scss files in the folder [sass](sass). If you want to change the style, 21 | use those files in order to have better control. For instance, you can easily change most colors by modifying the variables 22 | in the beginning of [that_style.scss](sass/that_style.scss). 23 | -------------------------------------------------------------------------------- /third-party/cmocka/example/assert_macro.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include "assert_macro.h" 19 | 20 | static const char* status_code_strings[] = { 21 | "Address not found", 22 | "Connection dropped", 23 | "Connection timed out", 24 | }; 25 | 26 | const char* get_status_code_string(const unsigned int status_code) { 27 | return status_code_strings[status_code]; 28 | } 29 | 30 | unsigned int string_to_status_code(const char* const status_code_string) { 31 | unsigned int i; 32 | for (i = 0; i < sizeof(status_code_strings) / 33 | sizeof(status_code_strings[0]); i++) { 34 | if (strcmp(status_code_strings[i], status_code_string) == 0) { 35 | return i; 36 | } 37 | } 38 | return ~0U; 39 | } 40 | -------------------------------------------------------------------------------- /src/collections/list.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/collections/list.h" 18 | 19 | struct fbp_list_s * fbp_list_index(struct fbp_list_s * list, fbp_size_t index) { 20 | struct fbp_list_s * item = list->next; 21 | fbp_size_t idx = 0; 22 | while (item != list) { 23 | if (idx == index) { 24 | return item; 25 | } 26 | item = item->next; 27 | ++idx; 28 | } 29 | return 0; 30 | } 31 | 32 | fbp_size_t fbp_list_index_of(struct fbp_list_s * list, struct fbp_list_s * item) { 33 | struct fbp_list_s * i = list->next; 34 | fbp_size_t idx = 0; 35 | while (i != list) { 36 | if (i == item) { 37 | return idx; 38 | } 39 | i = i->next; 40 | ++idx; 41 | } 42 | return -1; 43 | } 44 | -------------------------------------------------------------------------------- /pyfitterbap/crc.pyx: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from .c_crc cimport * 17 | from libc.stdint cimport uint8_t, uint16_t, uint32_t 18 | cimport numpy as np 19 | import numpy as np 20 | 21 | 22 | def crc_ccitt_8(crc, data): 23 | cdef np.uint8_t [::1] d_c 24 | data = np.ascontiguousarray(data, dtype=np.uint8) 25 | d_c = data 26 | return fbp_crc_ccitt_8( crc, &d_c[0], len(data)) 27 | 28 | 29 | def crc_ccitt_16(crc, data): 30 | cdef np.uint8_t [::1] d_c 31 | data = np.ascontiguousarray(data, dtype=np.uint8) 32 | d_c = data 33 | return fbp_crc_ccitt_16( crc, &d_c[0], len(data)) 34 | 35 | def crc32(crc, data): 36 | cdef np.uint8_t [::1] d_c 37 | data = np.ascontiguousarray(data, dtype=np.uint8) 38 | d_c = data 39 | return fbp_crc32( crc, &d_c[0], len(data)) 40 | -------------------------------------------------------------------------------- /include/fitterbap/comm/wave_sink_port.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Waveform sink port. 21 | */ 22 | 23 | #ifndef FBP_COMM_WAVEFORM_SINK_PORT_H_ 24 | #define FBP_COMM_WAVEFORM_SINK_PORT_H_ 25 | 26 | #include "fitterbap/comm/port.h" 27 | #include "fitterbap/comm/wave_port.h" 28 | 29 | /** 30 | * @ingroup fbp_comm 31 | * @defgroup fbp_comm_waveform_sink_port Waveform Sink Port 32 | * 33 | * @brief Waveform sink port. 34 | * 35 | * @{ 36 | */ 37 | 38 | FBP_CPP_GUARD_START 39 | 40 | /** 41 | * @brief Allocate an waveform port instance. 42 | * 43 | * @return The new instance or NULL on error. 44 | */ 45 | FBP_API struct fbp_port_api_s * fbp_wave_sink_factory(); 46 | 47 | FBP_CPP_GUARD_END 48 | 49 | /** @} */ 50 | 51 | #endif /* FBP_COMM_WAVEFORM_SINK_PORT_H_ */ 52 | -------------------------------------------------------------------------------- /include/fitterbap/inttypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Define "missing" inttypes. 21 | */ 22 | 23 | #ifndef FBP_INTTYPES_H_ 24 | #define FBP_INTTYPES_H_ 25 | 26 | #include 27 | 28 | /** 29 | * @ingroup fbp_core 30 | * @defgroup fbp_inttypes inttypes 31 | * 32 | * @brief Define "missing" inttypes 33 | * 34 | * This c99 omission makes me sad. 35 | * 36 | * @{ 37 | */ 38 | 39 | #if defined(__LP64__) || defined(_LP64) 40 | #define __PRIS_PREFIX "z" 41 | #else 42 | #define __PRIS_PREFIX 43 | #endif 44 | 45 | #define PRIdS __PRIS_PREFIX "d" 46 | #define PRIxS __PRIS_PREFIX "x" 47 | #define PRIuS __PRIS_PREFIX "u" 48 | #define PRIXS __PRIS_PREFIX "X" 49 | #define PRIoS __PRIS_PREFIX "o" 50 | 51 | /** @} */ 52 | 53 | #endif /* FBP_INTTYPES_H_ */ 54 | -------------------------------------------------------------------------------- /src/ec.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/ec.h" 18 | #include "fitterbap/argchk.h" 19 | #include "fitterbap/cdef.h" 20 | 21 | 22 | FBP_STATIC_ASSERT(FBP_ARGCHK_FAIL_RETURN_CODE_DEFAULT == FBP_ERROR_PARAMETER_INVALID, 23 | argchk_return_code_mismatch); 24 | 25 | #define SWITCH_NAME(NAME, TEXT) case FBP_ERROR_ ## NAME: return #NAME; 26 | #define SWITCH_DESCRIPTION(NAME, TEXT) case FBP_ERROR_ ## NAME: return TEXT; 27 | 28 | 29 | const char * fbp_error_code_name(int ec) { 30 | switch (ec) { 31 | FBP_ERROR_CODES(SWITCH_NAME); 32 | default: return "UNKNOWN"; 33 | } 34 | } 35 | 36 | const char * fbp_error_code_description(int ec) { 37 | switch (ec) { 38 | FBP_ERROR_CODES(SWITCH_DESCRIPTION); 39 | default: return "Unknown error"; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Modules/COPYING-CMAKE-SCRIPTS: -------------------------------------------------------------------------------- 1 | Redistribution and use in source and binary forms, with or without 2 | modification, are permitted provided that the following conditions 3 | are met: 4 | 5 | 1. Redistributions of source code must retain the copyright 6 | notice, this list of conditions and the following disclaimer. 7 | 2. Redistributions in binary form must reproduce the copyright 8 | notice, this list of conditions and the following disclaimer in the 9 | documentation and/or other materials provided with the distribution. 10 | 3. The name of the author may not be used to endorse or promote products 11 | derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 15 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 16 | IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 17 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 18 | NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 19 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 20 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 22 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_wildcard.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Andreas Schneider 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | 22 | static void test_ok1(void **state) 23 | { 24 | (void)state; 25 | 26 | assert_true(1); 27 | } 28 | 29 | static void test_ok2(void **state) 30 | { 31 | (void)state; 32 | 33 | assert_true(1); 34 | } 35 | 36 | static void test_fail(void **state) 37 | { 38 | (void)state; 39 | 40 | assert_false(1); 41 | } 42 | 43 | int main(void) { 44 | const struct CMUnitTest tests[] = { 45 | cmocka_unit_test(test_ok1), 46 | cmocka_unit_test(test_ok2), 47 | cmocka_unit_test(test_fail), 48 | }; 49 | 50 | cmocka_set_test_filter("test_ok*"); 51 | 52 | return cmocka_run_group_tests(tests, NULL, NULL); 53 | } 54 | -------------------------------------------------------------------------------- /include/fitterbap/host/arm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Platform for ARM. 21 | */ 22 | 23 | #ifndef FBP_HOST_PLATFORM_ARM_H_ 24 | #define FBP_HOST_PLATFORM_ARM_H_ 25 | 26 | #include "fitterbap/cmacro_inc.h" 27 | #include "fitterbap/config.h" 28 | #include "fitterbap/config_defaults.h" 29 | #include "fitterbap/platform_dependencies.h" 30 | 31 | 32 | FBP_CPP_GUARD_START 33 | 34 | FBP_INLINE_FN uint32_t fbp_clz(uint32_t x) { 35 | uint32_t leading_zeros; 36 | __asm volatile ( "clz %0, %1" : "=r" ( leading_zeros ) : "r" ( x ) ); 37 | return leading_zeros; 38 | } 39 | 40 | FBP_INLINE_FN uint32_t fbp_upper_power_of_two(uint32_t x) { 41 | if (x == 0) { 42 | return 0; 43 | } 44 | return 32 - fbp_clz(x - 1); 45 | } 46 | 47 | FBP_CPP_GUARD_END 48 | 49 | #endif /* FBP_HOST_PLATFORM_ARM_H_ */ 50 | -------------------------------------------------------------------------------- /test/platform_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "fitterbap/platform.h" 22 | #include "fitterbap/cdef.h" 23 | 24 | 25 | static void test_clz_extremes(void **state) { 26 | (void) state; 27 | assert_int_equal(32, fbp_clz(0)); 28 | assert_int_equal(0, fbp_clz(0x80000000)); 29 | } 30 | 31 | static void test_clz_individual_bits(void **state) { 32 | (void) state; 33 | for (uint32_t bit = 0; bit < 32; ++bit) { 34 | uint32_t x = 1 << bit; 35 | assert_int_equal(31 - bit, fbp_clz(x)); 36 | } 37 | } 38 | 39 | int main(void) { 40 | const struct CMUnitTest tests[] = { 41 | cmocka_unit_test(test_clz_extremes), 42 | cmocka_unit_test(test_clz_individual_bits), 43 | }; 44 | 45 | return cmocka_run_group_tests(tests, NULL, NULL); 46 | } 47 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # https://help.github.com/articles/dealing-with-line-endings/ 2 | # https://gist.github.com/eevee/6721177 3 | # http://stackoverflow.com/questions/2316677/can-git-automatically-switch-between-spaces-and-tabs/2316728 4 | # 5 | # find -type f -iregex '.*\.\(c\|h\|cpp\|hpp\|html\|txt\|cmake\|py\)$' -exec bash -c 'expand --initial -t 4 "$0" > /tmp/e && mv /tmp/e "$0"' {} \; 6 | # 7 | # Run the following commands: 8 | # git config --global filter.tabspace.smudge 'expand --tabs=4 --initial' 9 | # git config --global filter.tabspace.clean 'expand --tabs=4 --initial' 10 | # Or if you prefer tabs in your directory 11 | # git config --global filter.tabspace.smudge 'unexpand --tabs=4 --first-only' 12 | # Then 13 | # git checkout HEAD -- ** 14 | 15 | 16 | # Set the default behavior, in case people don't have core.autocrlf set. 17 | * text=auto 18 | 19 | # Explicitly declare text files you want to always be normalized and converted 20 | # to native line endings on checkout. 21 | *.c text diff=cpp filter=tabspace 22 | *.h text diff=cpp filter=tabspace 23 | *.cpp text diff=cpp filter=tabspace 24 | *.hpp text diff=cpp filter=tabspace 25 | *.html text diff=html filter=tabspace 26 | *.in text 27 | *.md text 28 | *.txt text filter=tabspace 29 | *.cmake text filter=tabspace 30 | *.py text diff=cpp filter=tabspace 31 | 32 | # Declare files that will always have CRLF line endings on checkout. 33 | *.sln text eol=crlf 34 | 35 | # Denote all files that are truly binary and should not be modified. 36 | *.png binary 37 | *.jpg binary 38 | *.zip binary 39 | *.gz binary 40 | 41 | -------------------------------------------------------------------------------- /third-party/cmocka/example/database.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | typedef struct DatabaseConnection DatabaseConnection; 17 | 18 | /* Function that takes an SQL query string and sets results to an array of 19 | * pointers with the result of the query. The value returned specifies the 20 | * number of items in the returned array of results. The returned array of 21 | * results are statically allocated and should not be deallocated using free() 22 | */ 23 | typedef unsigned int (*QueryDatabase)( 24 | DatabaseConnection* const connection, const char * const query_string, 25 | void *** const results); 26 | 27 | /* Connection to a database. */ 28 | struct DatabaseConnection { 29 | const char *url; 30 | unsigned int port; 31 | QueryDatabase query_database; 32 | }; 33 | 34 | /* Connect to a database. */ 35 | DatabaseConnection* connect_to_database(const char * const url, 36 | const unsigned int port); 37 | 38 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_skip_filter.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 by Red Hat, Inc. 3 | * 4 | * Author: Anderson Toshiyuki Sasaki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | static void test_skip1(void **state) 25 | { 26 | (void)state; 27 | 28 | assert_true(1); 29 | } 30 | 31 | static void test_skip2(void **state) 32 | { 33 | (void)state; 34 | 35 | assert_false(1); 36 | } 37 | 38 | static void test_fail(void **state) 39 | { 40 | (void)state; 41 | 42 | assert_false(1); 43 | } 44 | 45 | int main(void) { 46 | const struct CMUnitTest tests[] = { 47 | cmocka_unit_test(test_skip1), 48 | cmocka_unit_test(test_skip2), 49 | cmocka_unit_test(test_fail), 50 | }; 51 | 52 | cmocka_set_test_filter("test_skip*"); 53 | 54 | cmocka_set_skip_filter("test_skip2"); 55 | 56 | return cmocka_run_group_tests(tests, NULL, NULL); 57 | } 58 | -------------------------------------------------------------------------------- /src/host/freertos/os_mutex.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #include "fitterbap/os/mutex.h" 19 | #include "fitterbap/assert.h" 20 | #include "FreeRTOS.h" 21 | #include "semphr.h" 22 | 23 | 24 | #define MUTEX_LOCK_TIMEOUT_TICKS ((TickType_t) 500) 25 | 26 | fbp_os_mutex_t fbp_os_mutex_alloc() { 27 | SemaphoreHandle_t mutex = xSemaphoreCreateRecursiveMutex(); 28 | FBP_ASSERT_ALLOC(mutex); 29 | return mutex; 30 | } 31 | 32 | void fbp_os_mutex_free(fbp_os_mutex_t mutex) { 33 | if (mutex) { 34 | vSemaphoreDelete(mutex); 35 | } 36 | } 37 | 38 | void fbp_os_mutex_lock(fbp_os_mutex_t mutex) { 39 | if (mutex && (pdFALSE == xSemaphoreTakeRecursive(mutex, MUTEX_LOCK_TIMEOUT_TICKS))) { 40 | FBP_FATAL("mutex lock failed"); 41 | } 42 | } 43 | 44 | void fbp_os_mutex_unlock(fbp_os_mutex_t mutex) { 45 | if (mutex && (pdFALSE == xSemaphoreGiveRecursive(mutex))) { 46 | FBP_FATAL("mutex unlock failed"); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /test/hal.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "fitterbap/common_header.h" 22 | #include "fitterbap/log.h" 23 | #include "fitterbap/assert.h" 24 | #include 25 | #include // memset 26 | #include 27 | #include 28 | 29 | void * fbp_alloc_(fbp_size_t size_bytes) { 30 | void * ptr = test_malloc((size_t) size_bytes); 31 | // printf("hal_alloc %p\n", ptr); 32 | return ptr; 33 | } 34 | 35 | void fbp_free_(void * ptr) { 36 | // printf("hal_free %p\n", ptr); 37 | test_free(ptr); 38 | } 39 | 40 | void fbp_log_printf_(const char *format, ...) { 41 | va_list arg; 42 | va_start(arg, format); 43 | vprintf(format, arg); 44 | va_end(arg); 45 | } 46 | 47 | void fbp_fatal(char const * file, int line, char const * msg) { 48 | (void) file; 49 | (void) line; 50 | (void) msg; 51 | mock_assert(0, msg, file, line); 52 | } 53 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/chef_wrap/chef.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2013 (c) Andreas Schneider 3 | * Jakub Hrozek 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "chef.h" 28 | 29 | 30 | /* This is the real chef, just not implemented yet, currently it always 31 | * returns ENOSYS 32 | */ 33 | int chef_cook(const char *order, char **dish_out) 34 | { 35 | if (order == NULL || dish_out == NULL) return EINVAL; 36 | 37 | return -ENOSYS; 38 | } 39 | 40 | /* Print chef return codes as string */ 41 | const char *chef_strerror(int error) 42 | { 43 | switch (error) { 44 | case 0: 45 | return "Success"; 46 | case -1: 47 | return "Unknown dish"; 48 | case -2: 49 | return "Not enough ingredients for the dish"; 50 | } 51 | 52 | return "Unknown error!"; 53 | } 54 | 55 | -------------------------------------------------------------------------------- /third-party/tinyprintf/tinyprintf_LICENSE.BSD-new: -------------------------------------------------------------------------------- 1 | Copyright (c) 2004,2012 Kustaa Nyholm / SpareTimeLabs 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | * Redistributions of source code must retain the above copyright 7 | notice, this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of Kustaa Nyholm or SpareTimeLabs nor the 12 | names of its contributors may be used to endorse or promote products 13 | derived from this software without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 16 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 17 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER BE LIABLE FOR ANY 19 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 20 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 21 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 22 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 24 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /pyfitterbap/include/fitterbap/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief FBP configuration. 21 | */ 22 | 23 | #ifndef FBP_PY_CONFIG_H_ 24 | #define FBP_PY_CONFIG_H_ 25 | 26 | 27 | /* Set global log level */ 28 | #define FBP_LOG_GLOBAL_LEVEL FBP_LOG_LEVEL_ALL 29 | 30 | /* Set the initial comm log port level for forwarding/receiving log messages. */ 31 | #define FBP_LOGP_LEVEL FBP_LOG_LEVEL_ALL 32 | 33 | /* Override the log format */ 34 | void fbp_log_printf_(const char *fmt, ...); 35 | #define FBP_LOG_PRINTF(level, format, ...) \ 36 | fbp_log_printf_("%c %s:%d: " format "\n", fbp_log_level_char[level], __FILENAME__, __LINE__, __VA_ARGS__); 37 | 38 | // todo linux & mac support 39 | #if defined(WIN32) || defined(_WIN32) 40 | #include "fitterbap/host/win/config.h" 41 | #else 42 | #error "unsupported platform" 43 | #endif 44 | 45 | #define FBP_CONFIG_USE_FLOAT32 1 46 | #define FBP_CONFIG_USE_FLOAT64 1 47 | #define FBP_CONFIG_USE_CSTR_FLOAT 1 48 | 49 | #endif /* FBP_PY_CONFIG_H_ */ 50 | 51 | -------------------------------------------------------------------------------- /test/comm/waveform_sink_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "fitterbap/platform.h" 23 | #include "fitterbap/comm/wave_sink_port.h" 24 | 25 | #include "port_hal.inc" 26 | 27 | static void test_factory(void ** state) { 28 | (void) state; 29 | struct fbp_port_api_s * p = fbp_wave_sink_factory(); 30 | assert_non_null(p); 31 | assert_non_null(p->meta); 32 | assert_non_null(p->initialize); 33 | assert_non_null(p->finalize); 34 | assert_non_null(p->on_event); 35 | assert_non_null(p->on_recv); 36 | p->finalize(p); 37 | } 38 | 39 | int main(void) { 40 | const struct CMUnitTest tests[] = { 41 | cmocka_unit_test(test_factory), 42 | //cmocka_unit_test(), 43 | //cmocka_unit_test(), 44 | //cmocka_unit_test(), 45 | //cmocka_unit_test(), 46 | }; 47 | 48 | return cmocka_run_group_tests(tests, NULL, NULL); 49 | } 50 | -------------------------------------------------------------------------------- /doc/developer.md: -------------------------------------------------------------------------------- 1 | 16 | 17 | # Developer 18 | 19 | ## Code cleanup 20 | 21 | To remove trailing blanks:: 22 | 23 | find . -iname "*.c" -o -iname "*.h" -o -iname "*.txt" -type f -exec sed -i 's/[[:space:]]*$//' {} \; 24 | 25 | ## References 26 | 27 | Operating systems 28 | 29 | * [POSIX](http://pubs.opengroup.org/onlinepubs/9699919799/) 30 | * [NuttX](http://www.nuttx.org/) 31 | * [polymcu](https://github.com/labapart/polymcu) : CMSIS OS wrappers 32 | * [FreeRTOS](http://www.freertos.org/) 33 | 34 | C standard library implementations 35 | 36 | * [newlib](https://sourceware.org/newlib/) 37 | * [PDClib](http://pdclib.e43.eu/) 38 | * [uclibc](http://www.uclibc.org/) 39 | 40 | Using clib: 41 | 42 | * printf to [ITM](http://blog.atollic.com/cortex-m-debugging-printf-redirection-to-a-debugger-console-using-swv/itm-part-1) 43 | * printf to [uart](http://www.openstm32.org/forumthread1055) 44 | 45 | 46 | Linux 47 | 48 | * [EmbToolkit](https://www.embtoolkit.org/) 49 | * BuildRoot 50 | 51 | Switch debouncing 52 | 53 | * http://www.ganssle.com/debouncing.htm 54 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Modules/FindNSIS.cmake: -------------------------------------------------------------------------------- 1 | # - Try to find NSIS 2 | # Once done this will define 3 | # 4 | # NSIS_ROOT_PATH - Set this variable to the root installation of NSIS 5 | # 6 | # Read-Only variables: 7 | # 8 | # NSIS_FOUND - system has NSIS 9 | # NSIS_MAKE - NSIS creator executable 10 | # 11 | #============================================================================= 12 | # Copyright (c) 2010-2013 Andreas Schneider 13 | # 14 | # Distributed under the OSI-approved BSD License (the "License"); 15 | # see accompanying file Copyright.txt for details. 16 | # 17 | # This software is distributed WITHOUT ANY WARRANTY; without even the 18 | # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 19 | # See the License for more information. 20 | #============================================================================= 21 | # 22 | 23 | if (WIN32) 24 | set(_x86 "(x86)") 25 | 26 | set(_NSIS_ROOT_PATHS 27 | "$ENV{ProgramFiles}/NSIS" 28 | "$ENV{ProgramFiles${_x86}}/NSIS" 29 | "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\NSIS;Default]") 30 | 31 | find_path(NSIS_ROOT_PATH 32 | NAMES 33 | Include/Library.nsh 34 | PATHS 35 | ${_NSIS_ROOT_PATHS} 36 | ) 37 | mark_as_advanced(NSIS_ROOT_PATH) 38 | endif (WIN32) 39 | 40 | find_program(NSIS_MAKE 41 | NAMES 42 | makensis 43 | PATHS 44 | ${NSIS_ROOT_PATH} 45 | ) 46 | 47 | include(FindPackageHandleStandardArgs) 48 | find_package_handle_standard_args(NSIS DEFAULT_MSG NSIS_MAKE) 49 | 50 | if (NSIS_MAKE) 51 | set(NSIS_FOUND TRUE) 52 | endif (NSIS_MAKE) 53 | 54 | mark_as_advanced(NSIS_MAKE) 55 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_basics.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Use the unit test allocators */ 18 | #define UNIT_TESTING 1 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static int setup(void **state) { 26 | int *answer = malloc(sizeof(int)); 27 | 28 | assert_non_null(answer); 29 | *answer = 42; 30 | 31 | *state = answer; 32 | 33 | return 0; 34 | } 35 | 36 | static int teardown(void **state) { 37 | free(*state); 38 | 39 | return 0; 40 | } 41 | 42 | /* A test case that does nothing and succeeds. */ 43 | static void null_test_success(void **state) { 44 | (void) state; 45 | } 46 | 47 | /* A test case that does check if an int is equal. */ 48 | static void int_test_success(void **state) { 49 | int *answer = *state; 50 | 51 | assert_int_equal(*answer, 42); 52 | } 53 | 54 | 55 | int main(void) { 56 | const struct CMUnitTest tests[] = { 57 | cmocka_unit_test(null_test_success), 58 | cmocka_unit_test_setup_teardown(int_test_success, setup, teardown), 59 | }; 60 | 61 | return cmocka_run_group_tests(tests, NULL, NULL); 62 | } 63 | -------------------------------------------------------------------------------- /third-party/cmocka/example/assert_macro_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "assert_macro.h" 22 | 23 | /* This test will fail since the string returned by get_status_code_string(0) 24 | * doesn't match "Connection timed out". */ 25 | static void get_status_code_string_test(void **state) { 26 | (void) state; /* unused */ 27 | 28 | assert_string_equal(get_status_code_string(0), "Address not found"); 29 | assert_string_equal(get_status_code_string(1), "Connection timed out"); 30 | } 31 | 32 | /* This test will fail since the status code of "Connection timed out" isn't 1 */ 33 | static void string_to_status_code_test(void **state) { 34 | (void) state; /* unused */ 35 | 36 | assert_int_equal(string_to_status_code("Address not found"), 0); 37 | assert_int_equal(string_to_status_code("Connection timed out"), 1); 38 | } 39 | 40 | int main(void) { 41 | const struct CMUnitTest tests[] = { 42 | cmocka_unit_test(get_status_code_string_test), 43 | cmocka_unit_test(string_to_status_code_test), 44 | }; 45 | return cmocka_run_group_tests(tests, NULL, NULL); 46 | } 47 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_returns.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | int mock_function(void); 12 | void mock_function_call_times(size_t times, int expectedValue); 13 | 14 | int mock_function(void) 15 | { 16 | return (int) mock(); 17 | } 18 | 19 | void mock_function_call_times(size_t times, int expectedValue) 20 | { 21 | size_t i; 22 | for (i = 0u; i < times; ++i) 23 | { 24 | assert_int_equal(expectedValue, mock_function()); 25 | } 26 | } 27 | 28 | static void test_will_return_maybe_for_no_calls(void **state) 29 | { 30 | (void) state; 31 | 32 | will_return_maybe(mock_function, 32); 33 | } 34 | 35 | static void test_will_return_maybe_for_one_mock_call(void **state) 36 | { 37 | int value; 38 | 39 | (void) state; 40 | 41 | value = rand(); 42 | will_return_maybe(mock_function, value); 43 | mock_function_call_times(1u, value); 44 | } 45 | 46 | static void test_will_return_maybe_for_more_than_one_call(void **state) 47 | { 48 | int value; 49 | size_t numberOfCalls; 50 | (void)state; 51 | 52 | value = rand(); 53 | numberOfCalls = (size_t) ((rand()) % 20 + 2); 54 | will_return_maybe(mock_function, value); 55 | mock_function_call_times(numberOfCalls, value); 56 | } 57 | 58 | int main(int argc, char **argv) { 59 | const struct CMUnitTest alloc_tests[] = { 60 | cmocka_unit_test(test_will_return_maybe_for_no_calls) 61 | ,cmocka_unit_test(test_will_return_maybe_for_one_mock_call) 62 | ,cmocka_unit_test(test_will_return_maybe_for_more_than_one_call) 63 | }; 64 | 65 | (void)argc; 66 | (void)argv; 67 | 68 | return cmocka_run_group_tests(alloc_tests, NULL, NULL); 69 | } 70 | -------------------------------------------------------------------------------- /third-party/cmocka/example/allocate_module_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | extern void leak_memory(void); 22 | extern void buffer_overflow(void); 23 | extern void buffer_underflow(void); 24 | 25 | /* Test case that fails as leak_memory() leaks a dynamically allocated block. */ 26 | static void leak_memory_test(void **state) { 27 | (void) state; /* unused */ 28 | 29 | leak_memory(); 30 | } 31 | 32 | /* Test case that fails as buffer_overflow() corrupts an allocated block. */ 33 | static void buffer_overflow_test(void **state) { 34 | (void) state; /* unused */ 35 | 36 | buffer_overflow(); 37 | } 38 | 39 | /* Test case that fails as buffer_underflow() corrupts an allocated block. */ 40 | static void buffer_underflow_test(void **state) { 41 | (void) state; /* unused */ 42 | 43 | buffer_underflow(); 44 | } 45 | 46 | int main(void) { 47 | const struct CMUnitTest tests[] = { 48 | cmocka_unit_test(leak_memory_test), 49 | cmocka_unit_test(buffer_overflow_test), 50 | cmocka_unit_test(buffer_underflow_test), 51 | }; 52 | return cmocka_run_group_tests(tests, NULL, NULL); 53 | } 54 | -------------------------------------------------------------------------------- /src/host/linux/platform.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/platform.h" 18 | #include "fitterbap/time.h" 19 | #include 20 | 21 | static int64_t counter_base_seconds_ = 0; 22 | static uint64_t counter_frequency_ = 0; 23 | 24 | 25 | struct fbp_time_counter_s fbp_time_counter() { 26 | struct fbp_time_counter_s counter; 27 | struct timespec ts; 28 | struct timespec ts_res; 29 | clock_gettime(CLOCK_MONOTONIC, &ts); 30 | if (counter_frequency_ == 0) { 31 | clock_getres(CLOCK_MONOTONIC, &ts_res); 32 | if (ts_res.tv_sec > 0) { 33 | // really! too slow. 34 | } 35 | counter_frequency_ = 1000000000 / ts_res.tv_nsec; 36 | counter_base_seconds_ = (int64_t) ts.tv_sec; 37 | } 38 | counter.frequency = counter_frequency_; 39 | counter.value = FBP_TIME_SECOND * ((int64_t) ts.tv_sec - counter_base_seconds_); 40 | counter.value += FBP_NANOSECONDS_TO_TIME(ts.tv_nsec); 41 | return counter; 42 | } 43 | 44 | FBP_API int64_t fbp_time_utc() { 45 | struct timespec ts; 46 | clock_gettime(CLOCK_REALTIME, &ts); 47 | int64_t t = FBP_TIME_SECOND * (int64_t) ts.tv_sec; 48 | t += FBP_NANOSECONDS_TO_TIME(ts.tv_nsec); 49 | return t; 50 | } 51 | -------------------------------------------------------------------------------- /third-party/cmocka/example/assert_module_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include 19 | #include 20 | 21 | #include "assert_module.h" 22 | 23 | extern void increment_value(int * const value); 24 | 25 | /* This test case will fail but the assert is caught by run_tests() and the 26 | * next test is executed. */ 27 | static void increment_value_fail(void **state) { 28 | (void) state; 29 | 30 | increment_value(NULL); 31 | } 32 | 33 | /* This test case succeeds since increment_value() asserts on the NULL 34 | * pointer. */ 35 | static void increment_value_assert(void **state) { 36 | (void) state; 37 | 38 | expect_assert_failure(increment_value(NULL)); 39 | } 40 | 41 | /* This test case fails since decrement_value() doesn't assert on a NULL 42 | * pointer. */ 43 | static void decrement_value_fail(void **state) { 44 | (void) state; 45 | 46 | expect_assert_failure(decrement_value(NULL)); 47 | } 48 | 49 | int main(void) { 50 | const struct CMUnitTest tests[] = { 51 | cmocka_unit_test(increment_value_fail), 52 | cmocka_unit_test(increment_value_assert), 53 | cmocka_unit_test(decrement_value_fail), 54 | }; 55 | return cmocka_run_group_tests(tests, NULL, NULL); 56 | } 57 | -------------------------------------------------------------------------------- /pyfitterbap/comm/ui/vertical_scroll_area.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | from PySide6 import QtCore, QtGui, QtWidgets 17 | import logging 18 | 19 | 20 | class VerticalScrollArea(QtWidgets.QScrollArea): 21 | 22 | def __init__(self, parent=None): 23 | super(VerticalScrollArea, self).__init__(parent) 24 | self.setWidgetResizable(True) 25 | self.setHorizontalScrollBarPolicy(QtGui.Qt.ScrollBarAlwaysOff) 26 | self.setVerticalScrollBarPolicy(QtGui.Qt.ScrollBarAsNeeded) 27 | self.setSizePolicy(QtWidgets.QSizePolicy.Preferred, 28 | QtWidgets.QSizePolicy.Preferred) 29 | self._log = logging.getLogger(__name__) 30 | 31 | def setWidget(self, widget): 32 | widget.installEventFilter(self) 33 | return super(VerticalScrollArea, self).setWidget(widget) 34 | 35 | def eventFilter(self, obj, event): 36 | widget = self.widget() 37 | if obj == widget and event.type() == QtCore.QEvent.Resize: 38 | width = widget.minimumSizeHint().width() + self.verticalScrollBar().width() 39 | self.setMinimumWidth(width) 40 | self._log.debug('scroll: sizeHint=%s, minimumSizeHint=%s, minimumSize=%s', 41 | self.sizeHint(), self.minimumSizeHint(), self.minimumSize()) 42 | return False 43 | -------------------------------------------------------------------------------- /test/ec_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "fitterbap/ec.h" 22 | 23 | 24 | static void enum_check(void **state) { 25 | (void) state; 26 | assert_int_equal(0, FBP_ERROR_SUCCESS); 27 | assert_int_equal(0, FBP_SUCCESS); 28 | assert_int_equal(1, FBP_ERROR_UNSPECIFIED); 29 | } 30 | 31 | static void names(void **state) { 32 | (void) state; 33 | assert_string_equal("SUCCESS", fbp_error_code_name(0)); 34 | assert_string_equal("UNSPECIFIED", fbp_error_code_name(FBP_ERROR_UNSPECIFIED)); 35 | assert_string_equal("UNKNOWN", fbp_error_code_name(-1)); 36 | } 37 | 38 | static void descriptions(void **state) { 39 | (void) state; 40 | assert_string_equal("Success (no error)", fbp_error_code_description(0)); 41 | assert_string_equal("Unspecified error", fbp_error_code_description(FBP_ERROR_UNSPECIFIED)); 42 | assert_string_equal("Unknown error", fbp_error_code_description(-1)); 43 | } 44 | 45 | int main(void) { 46 | const struct CMUnitTest tests[] = { 47 | cmocka_unit_test(enum_check), 48 | cmocka_unit_test(names), 49 | cmocka_unit_test(descriptions), 50 | }; 51 | 52 | return cmocka_run_group_tests(tests, NULL, NULL); 53 | } 54 | -------------------------------------------------------------------------------- /third-party/cmocka/example/allocate_module.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2008 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifdef HAVE_CONFIG_H 17 | #include "config.h" 18 | #endif 19 | #ifdef HAVE_MALLOC_H 20 | #include 21 | #endif 22 | #include 23 | #include 24 | 25 | #ifdef UNIT_TESTING 26 | extern void* _test_malloc(const size_t size, const char* file, const int line); 27 | extern void* _test_calloc(const size_t number_of_elements, const size_t size, 28 | const char* file, const int line); 29 | extern void _test_free(void* const ptr, const char* file, const int line); 30 | 31 | #define malloc(size) _test_malloc(size, __FILE__, __LINE__) 32 | #define calloc(num, size) _test_calloc(num, size, __FILE__, __LINE__) 33 | #define free(ptr) _test_free(ptr, __FILE__, __LINE__) 34 | #endif // UNIT_TESTING 35 | 36 | void leak_memory(void); 37 | void buffer_overflow(void); 38 | void buffer_underflow(void); 39 | 40 | void leak_memory(void) { 41 | int * const temporary = (int*)malloc(sizeof(int)); 42 | *temporary = 0; 43 | } 44 | 45 | void buffer_overflow(void) { 46 | char * const memory = (char*)malloc(sizeof(int)); 47 | memory[sizeof(int)] = '!'; 48 | free(memory); 49 | } 50 | 51 | void buffer_underflow(void) { 52 | char * const memory = (char*)malloc(sizeof(int)); 53 | memory[-1] = '!'; 54 | free(memory); 55 | } 56 | -------------------------------------------------------------------------------- /include/fitterbap/assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Assert 21 | */ 22 | 23 | #ifndef FBP_ASSERT_H_ 24 | #define FBP_ASSERT_H_ 25 | 26 | #include "fitterbap/cmacro_inc.h" 27 | #include "fitterbap/config.h" 28 | #include "fitterbap/config_defaults.h" 29 | #include "fitterbap/platform_dependencies.h" 30 | 31 | /** 32 | * @ingroup fbp_core 33 | * @defgroup fbp_assert Assert 34 | * 35 | * @brief Assert and halt execution. 36 | * 37 | * This module provides assertion checking. When an assertion fails, 38 | * program execution halts. On an embedded system, the recommended behavior 39 | * is to log the fault and then reboot. 40 | * 41 | * @{ 42 | */ 43 | 44 | /** 45 | * @brief Check a condition that is normally true. 46 | * 47 | * @param[in] condition The condition which is normally true. 48 | * when false, invoke fault(). 49 | */ 50 | #define FBP_ASSERT(condition) \ 51 | if (! (condition) ) { FBP_FATAL("assert"); } 52 | 53 | /** 54 | * @brief Check that a memory allocation succeeded (not NULL). 55 | * 56 | * @param[in] pointer The pointer, usually returned from malloc/calloc, 57 | * which must not be NULL. 58 | */ 59 | #define FBP_ASSERT_ALLOC(pointer) \ 60 | if (0 == (pointer)) { FBP_FATAL("memory allocation"); } 61 | 62 | 63 | /** @} */ 64 | 65 | #endif /* FBP_ASSERT_H_ */ 66 | -------------------------------------------------------------------------------- /include/fitterbap/os/task.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief OS Task abstraction. 21 | */ 22 | 23 | #ifndef FBP_OS_TASK_H__ 24 | #define FBP_OS_TASK_H__ 25 | 26 | #include "fitterbap/cmacro_inc.h" 27 | #include "fitterbap/config.h" 28 | #include "fitterbap/config_defaults.h" 29 | #include "fitterbap/time.h" 30 | 31 | /** 32 | * @ingroup fbp_os 33 | * @defgroup fbp_os_task OS task abstraction 34 | * 35 | * @brief Provide a simple OS task abstraction. 36 | * 37 | * @{ 38 | */ 39 | 40 | FBP_CPP_GUARD_START 41 | 42 | /** 43 | * @brief Get the identifier for the currently running task. 44 | * 45 | * @return The task ID. If running single-threaded, return 0. 46 | */ 47 | FBP_INLINE_FN intptr_t fbp_os_current_task_id(); 48 | 49 | /** 50 | * @brief Sleep (pause thread execution) for a specified duration. 51 | * 52 | * @param duration The duration (see "fitterbap/time.h") 53 | */ 54 | FBP_INLINE_FN void fbp_os_sleep(int64_t duration); 55 | 56 | /** 57 | * @brief Sleep (pause thread execution) for a specified duration. 58 | * 59 | * @param duration The duration in milliseconds. 60 | */ 61 | FBP_INLINE_FN void fbp_os_sleep_ms(int64_t duration_ms) { 62 | fbp_os_sleep(FBP_COUNTER_TO_TIME(duration_ms, 1000)); 63 | } 64 | 65 | FBP_CPP_GUARD_END 66 | 67 | /** @} */ 68 | 69 | #endif /* FBP_OS_TASK_H__ */ 70 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_returns_fail.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | 11 | int mock_function(void); 12 | void mock_function_call_times(size_t times, int expectedValue); 13 | 14 | int mock_function(void) 15 | { 16 | return (int) mock(); 17 | } 18 | 19 | void mock_function_call_times(size_t times, int expectedValue) 20 | { 21 | size_t i; 22 | for (i = 0u; i < times; ++i) 23 | { 24 | assert_int_equal(expectedValue, mock_function()); 25 | } 26 | } 27 | 28 | static void test_will_return_fails_for_no_calls(void **state) 29 | { 30 | (void) state; 31 | 32 | will_return(mock_function, 32); 33 | } 34 | 35 | static void test_will_return_count_fails_for_unreturned_items(void **state) 36 | { 37 | int value; 38 | size_t numberOfCalls; 39 | 40 | (void) state; 41 | 42 | value = rand(); 43 | numberOfCalls = (size_t) ((rand()) % 20 + 2); 44 | 45 | will_return_count(mock_function, value, numberOfCalls); 46 | mock_function_call_times(numberOfCalls - 1u, value); 47 | } 48 | 49 | static void test_will_return_always_fails_for_no_calls(void **state) 50 | { 51 | int value; 52 | 53 | (void) state; 54 | 55 | value = rand(); 56 | 57 | will_return_always(mock_function, value); 58 | } 59 | 60 | static int teardown(void **state) { 61 | free(*state); 62 | 63 | return 0; 64 | } 65 | 66 | int main(int argc, char **argv) { 67 | const struct CMUnitTest alloc_tests[] = { 68 | cmocka_unit_test_teardown(test_will_return_fails_for_no_calls, teardown) 69 | ,cmocka_unit_test_teardown(test_will_return_count_fails_for_unreturned_items, teardown) 70 | ,cmocka_unit_test_teardown(test_will_return_always_fails_for_no_calls, teardown) 71 | }; 72 | 73 | (void)argc; 74 | (void)argv; 75 | 76 | return cmocka_run_group_tests(alloc_tests, NULL, NULL); 77 | } 78 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_groups.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016 David Schneider 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* Use the unit test allocators */ 18 | #define UNIT_TESTING 1 19 | 20 | #include 21 | #include 22 | #include 23 | #include 24 | 25 | static int setup(void **state) { 26 | int *answer = malloc(sizeof(int)); 27 | 28 | assert_non_null(answer); 29 | *answer = 42; 30 | 31 | *state = answer; 32 | 33 | return 0; 34 | } 35 | 36 | static int teardown(void **state) { 37 | free(*state); 38 | 39 | return 0; 40 | } 41 | 42 | /* A test case that does nothing and succeeds. */ 43 | static void null_test_success(void **state) { 44 | (void) state; 45 | } 46 | 47 | /* A test case that does check if an int is equal. */ 48 | static void int_test_success(void **state) { 49 | int *answer = *state; 50 | 51 | assert_int_equal(*answer, 42); 52 | } 53 | 54 | 55 | int main(void) { 56 | const struct CMUnitTest test_group1[] = { 57 | cmocka_unit_test(null_test_success), 58 | }; 59 | 60 | const struct CMUnitTest test_group2[] = { 61 | cmocka_unit_test_setup_teardown(int_test_success, setup, teardown), 62 | }; 63 | 64 | int result = 0; 65 | result += cmocka_run_group_tests(test_group1, NULL, NULL); 66 | result += cmocka_run_group_tests(test_group2, NULL, NULL); 67 | 68 | return result; 69 | } 70 | -------------------------------------------------------------------------------- /third-party/cmocka/CPackConfig.cmake: -------------------------------------------------------------------------------- 1 | # For help take a look at: 2 | # http://www.cmake.org/Wiki/CMake:CPackConfiguration 3 | 4 | ### general settings 5 | set(CPACK_PACKAGE_NAME ${PROJECT_NAME}) 6 | set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Unit testing framework for C with mock objects") 7 | set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README.md") 8 | set(CPACK_PACKAGE_VENDOR "Andreas Schneider") 9 | set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME}) 10 | set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/COPYING") 11 | 12 | 13 | ### versions 14 | set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION}) 15 | 16 | 17 | ### source generator 18 | set(CPACK_SOURCE_GENERATOR "TXZ") 19 | set(CPACK_SOURCE_IGNORE_FILES "~$;[.]swp$;/[.]svn/;/[.]git/;.gitignore;/obj*;tags;cscope.*;.ycm_extra_conf.pyc") 20 | set(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}") 21 | 22 | if (WIN32) 23 | set(CPACK_GENERATOR "ZIP") 24 | 25 | ### nsis generator 26 | find_package(NSIS) 27 | if (NSIS_MAKE) 28 | set(CPACK_GENERATOR "${CPACK_GENERATOR};NSIS") 29 | set(CPACK_NSIS_DISPLAY_NAME "CMocka") 30 | set(CPACK_NSIS_COMPRESSOR "/SOLID zlib") 31 | set(CPACK_NSIS_MENU_LINKS "http://cmocka.org/" "cmocka homepage") 32 | endif (NSIS_MAKE) 33 | endif (WIN32) 34 | 35 | set(CPACK_PACKAGE_INSTALL_DIRECTORY "cmocka") 36 | 37 | set(CPACK_PACKAGE_FILE_NAME ${PROJECT_NAME}-${CPACK_PACKAGE_VERSION}) 38 | 39 | set(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "Libraries") 40 | set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "C/C++ Headers") 41 | set(CPACK_COMPONENT_LIBRARIES_DESCRIPTION 42 | "Libraries used to build programs which use cmocka") 43 | set(CPACK_COMPONENT_HEADERS_DESCRIPTION 44 | "C/C++ header files for use with cmocka") 45 | set(CPACK_COMPONENT_HEADERS_DEPENDS libraries) 46 | #set(CPACK_COMPONENT_APPLICATIONS_GROUP "Runtime") 47 | set(CPACK_COMPONENT_LIBRARIES_GROUP "Development") 48 | set(CPACK_COMPONENT_HEADERS_GROUP "Development") 49 | 50 | include(CPack) 51 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_fixtures.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | static int setup_only(void **state) 9 | { 10 | *state = malloc(1); 11 | 12 | return 0; 13 | } 14 | 15 | static int teardown_only(void **state) 16 | { 17 | free(*state); 18 | 19 | return 0; 20 | } 21 | 22 | static void malloc_setup_test(void **state) 23 | { 24 | assert_non_null(*state); 25 | free(*state); 26 | } 27 | 28 | static void malloc_teardown_test(void **state) 29 | { 30 | *state = malloc(1); 31 | assert_non_null(*state); 32 | } 33 | 34 | static int prestate_setup(void **state) 35 | { 36 | int *val = (int *)*state, *a; 37 | 38 | a = malloc(sizeof(int)); 39 | *a = *val + 1; 40 | *state = a; 41 | 42 | return 0; 43 | } 44 | 45 | static int prestate_teardown(void **state) 46 | { 47 | free(*state); 48 | 49 | return 0; 50 | } 51 | 52 | static void prestate_setup_test(void **state) 53 | { 54 | int *a = (int *)*state; 55 | 56 | assert_non_null(a); 57 | assert_int_equal(*a, 43); 58 | } 59 | 60 | static void prestate_test(void **state) 61 | { 62 | int *a = (int *)*state; 63 | 64 | assert_non_null(a); 65 | assert_int_equal(*a, 42); 66 | } 67 | 68 | int main(void) { 69 | int prestate = 42; 70 | const struct CMUnitTest tests[] = { 71 | cmocka_unit_test_setup(malloc_setup_test, setup_only), 72 | cmocka_unit_test_setup(malloc_setup_test, setup_only), 73 | cmocka_unit_test_teardown(malloc_teardown_test, teardown_only), 74 | cmocka_unit_test_teardown(malloc_teardown_test, teardown_only), 75 | cmocka_unit_test_teardown(malloc_teardown_test, teardown_only), 76 | cmocka_unit_test_teardown(malloc_teardown_test, teardown_only), 77 | cmocka_unit_test_prestate(prestate_test, &prestate), 78 | cmocka_unit_test_prestate_setup_teardown(prestate_setup_test, prestate_setup, prestate_teardown, &prestate), 79 | }; 80 | 81 | return cmocka_run_group_tests(tests, NULL, NULL); 82 | } 83 | -------------------------------------------------------------------------------- /doc/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | $projectname: $title 7 | $title 8 | 9 | 10 | 11 | $treeview 12 | $search 13 | $mathjax 14 | 15 | $extrastylesheet 16 | 17 | 18 |
19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 35 | 36 | 37 | 38 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
30 |
$projectname 31 |  $projectnumber 32 |
33 |
$projectbrief
34 |
39 |
$projectbrief
40 |
$searchbox
51 |
52 | 53 | 54 | -------------------------------------------------------------------------------- /include/fitterbap/comm/wave_port.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Waveform port definitions. 21 | */ 22 | 23 | #ifndef FBP_COMM_WAVEFORM_PORT_H_ 24 | #define FBP_COMM_WAVEFORM_PORT_H_ 25 | 26 | #include "fitterbap/comm/port.h" 27 | 28 | /** 29 | * @ingroup fbp_comm 30 | * @defgroup fbp_comm_waveform_port Waveform Port Def 31 | * 32 | * @brief Waveform port definitions. 33 | * 34 | * @{ 35 | */ 36 | 37 | FBP_CPP_GUARD_START 38 | 39 | /* 40 | * FEATURES to implement 41 | * 42 | * - Send & receive waveform data for float32 43 | * - Send & receive waveform data for signed & unsigned integers of various widths 44 | * - Send & receive timing data: sample_id & UTC pairs 45 | * - Compression 46 | * 47 | * port_data[7:4] == 0: unsupported 48 | * port_data[7:4] == 1: start 49 | * - 64-bit starting sample_id, ignoring div 50 | * - 32-bit data type 51 | * port_data[7:4] == 2: stop 52 | * - 64-bit ending sample_id, ignoring div 53 | * port_data[7:4] == 3: skip (explicit indicator) 54 | * - 64-bit sample_id of first missing sample 55 | * - 64-bit sample_id of last missing sample 56 | * port_data[7] == 1: data packet 57 | * - port_data[6:0], compression type, 0=no compression 58 | * - 32-bit sample_id[31:0] 59 | * - waveform data, packed 60 | */ 61 | 62 | #define FBP_WAVEP_DTYPE_F32 (0x0033) 63 | 64 | FBP_CPP_GUARD_END 65 | 66 | /** @} */ 67 | 68 | #endif /* FBP_COMM_WAVEFORM_PORT_H_ */ 69 | -------------------------------------------------------------------------------- /src/host/win/error.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2022 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/host/win/error.h" 18 | 19 | // https://stackoverflow.com/questions/1387064/how-to-get-the-error-message-from-the-error-code-returned-by-getlasterror 20 | // This functions fills a caller-defined character buffer (pBuffer) 21 | // of max length (cchBufferLength) with the human-readable error message 22 | // for a Win32 error code (dwErrorCode). 23 | // 24 | // Returns TRUE if successful, or FALSE otherwise. 25 | // If successful, pBuffer is guaranteed to be NUL-terminated. 26 | // On failure, the contents of pBuffer are undefined. 27 | BOOL GetErrorMessage(DWORD dwErrorCode, char * pBuffer, DWORD cchBufferLength) { 28 | char* p = pBuffer; 29 | if (cchBufferLength == 0) { 30 | return FALSE; 31 | } 32 | pBuffer[0] = 0; 33 | 34 | DWORD cchMsg = FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, 35 | NULL, /* (not used with FORMAT_MESSAGE_FROM_SYSTEM) */ 36 | dwErrorCode, 37 | MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), 38 | pBuffer, 39 | cchBufferLength, 40 | NULL); 41 | 42 | while (*p) { 43 | if ((*p == '\n') || (*p == '\r')) { 44 | *p = 0; 45 | break; 46 | } 47 | ++p; 48 | } 49 | return (cchMsg > 0); 50 | } 51 | -------------------------------------------------------------------------------- /third-party/cmocka/include/cmocka_pbc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014 Luis Pabon, Jr. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /* 18 | * Programming by Contract is a programming methodology 19 | * which binds the caller and the function called to a 20 | * contract. The contract is represented using Hoare Triple: 21 | * {P} C {Q} 22 | * where {P} is the precondition before executing command C, 23 | * and {Q} is the postcondition. 24 | * 25 | * See also: 26 | * http://en.wikipedia.org/wiki/Design_by_contract 27 | * http://en.wikipedia.org/wiki/Hoare_logic 28 | * http://dlang.org/dbc.html 29 | */ 30 | #ifndef CMOCKA_PBC_H_ 31 | #define CMOCKA_PBC_H_ 32 | 33 | #if defined(UNIT_TESTING) || defined (DEBUG) 34 | 35 | #include 36 | 37 | /* 38 | * Checks caller responsibility against contract 39 | */ 40 | #define REQUIRE(cond) assert(cond) 41 | 42 | /* 43 | * Checks function reponsability against contract. 44 | */ 45 | #define ENSURE(cond) assert(cond) 46 | 47 | /* 48 | * While REQUIRE and ENSURE apply to functions, INVARIANT 49 | * applies to classes/structs. It ensures that intances 50 | * of the class/struct are consistent. In other words, 51 | * that the instance has not been corrupted. 52 | */ 53 | #define INVARIANT(invariant_fnc) do{ (invariant_fnc) } while (0); 54 | 55 | #else 56 | #define REQUIRE(cond) do { } while (0); 57 | #define ENSURE(cond) do { } while (0); 58 | #define INVARIANT(invariant_fnc) do{ } while (0); 59 | 60 | #endif /* defined(UNIT_TESTING) || defined (DEBUG) */ 61 | #endif /* CMOCKA_PBC_H_ */ 62 | 63 | -------------------------------------------------------------------------------- /third-party/cmocka/cmake/Modules/CheckCCompilerFlagSSP.cmake: -------------------------------------------------------------------------------- 1 | # - Check whether the C compiler supports a given flag in the 2 | # context of a stack checking compiler option. 3 | 4 | # CHECK_C_COMPILER_FLAG_SSP(FLAG VARIABLE) 5 | # 6 | # FLAG - the compiler flag 7 | # VARIABLE - variable to store the result 8 | # 9 | # This actually calls check_c_source_compiles. 10 | # See help for CheckCSourceCompiles for a listing of variables 11 | # that can modify the build. 12 | 13 | # Copyright (c) 2006, Alexander Neundorf, 14 | # 15 | # Redistribution and use is allowed according to the terms of the BSD license. 16 | # For details see the accompanying COPYING-CMAKE-SCRIPTS file. 17 | 18 | # Requires cmake 3.10 19 | #include_guard(GLOBAL) 20 | include(CheckCSourceCompiles) 21 | include(CMakeCheckCompilerFlagCommonPatterns) 22 | 23 | macro(CHECK_C_COMPILER_FLAG_SSP _FLAG _RESULT) 24 | set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") 25 | set(CMAKE_REQUIRED_FLAGS "${_FLAG}") 26 | 27 | # Normalize locale during test compilation. 28 | set(_CheckCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) 29 | foreach(v ${_CheckCCompilerFlag_LOCALE_VARS}) 30 | set(_CheckCCompilerFlag_SAVED_${v} "$ENV{${v}}") 31 | set(ENV{${v}} C) 32 | endforeach() 33 | 34 | CHECK_COMPILER_FLAG_COMMON_PATTERNS(_CheckCCompilerFlag_COMMON_PATTERNS) 35 | check_c_source_compiles("int main(int argc, char **argv) { char buffer[256]; return buffer[argc]=0;}" 36 | ${_RESULT} 37 | # Some compilers do not fail with a bad flag 38 | FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU 39 | ${_CheckCCompilerFlag_COMMON_PATTERNS}) 40 | foreach(v ${_CheckCCompilerFlag_LOCALE_VARS}) 41 | set(ENV{${v}} ${_CheckCCompilerFlag_SAVED_${v}}) 42 | unset(_CheckCCompilerFlag_SAVED_${v}) 43 | endforeach() 44 | unset(_CheckCCompilerFlag_LOCALE_VARS) 45 | unset(_CheckCCompilerFlag_COMMON_PATTERNS) 46 | 47 | set(CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") 48 | endmacro(CHECK_C_COMPILER_FLAG_SSP) 49 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/uptime/proc_uptime.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Andreas Scheider 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #include "proc_uptime.h" 28 | 29 | #define UPTIME_FILE "/proc/uptime" 30 | 31 | int uptime(const char *uptime_path, double *uptime_secs, double *idle_secs) 32 | { 33 | double up = 0; 34 | double idle = 0; 35 | char *savelocale = NULL; 36 | char buf[1024] = {0}; 37 | ssize_t nread; 38 | int fd = -1; 39 | int rc; 40 | 41 | if (uptime_path == NULL) { 42 | uptime_path = UPTIME_FILE; 43 | } 44 | 45 | fd = open(uptime_path, O_RDONLY); 46 | if (fd < 0) { 47 | return 0; 48 | } 49 | 50 | nread = read(fd, buf, sizeof(buf)); 51 | close(fd); 52 | if (nread < 0) { 53 | return 0; 54 | } 55 | 56 | savelocale = strdup(setlocale(LC_NUMERIC, NULL)); 57 | if (savelocale == NULL) { 58 | return 0; 59 | } 60 | 61 | setlocale(LC_NUMERIC, "C"); 62 | rc = sscanf(buf, "%lf %lf", &up, &idle); 63 | setlocale(LC_NUMERIC, savelocale); 64 | free(savelocale); 65 | if (rc < 2) { 66 | errno = EFAULT; 67 | return 0; 68 | } 69 | 70 | if (uptime_secs != NULL) { 71 | *uptime_secs = up; 72 | } 73 | if (idle_secs != NULL) { 74 | *idle_secs = idle; 75 | } 76 | 77 | return (int)up; 78 | } 79 | -------------------------------------------------------------------------------- /include/fitterbap.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Embedded systems library for C (FBP) 21 | * 22 | * The top-level FBP header file automatically includes select core components 23 | * of the FBP library. 24 | */ 25 | 26 | #ifndef FBP_H__ 27 | #define FBP_H__ 28 | 29 | #include "fitterbap/common_header.h" 30 | #include "fitterbap/argchk.h" 31 | #include "fitterbap/assert.h" 32 | #include "fitterbap/cdef.h" 33 | #include "fitterbap/dbc.h" 34 | #include "fitterbap/ec.h" 35 | #include "fitterbap/log.h" 36 | #include "fitterbap/time.h" 37 | #include "fitterbap/version.h" 38 | 39 | /** 40 | * @defgroup fbp Fitterbap 41 | * 42 | * @brief Firmware toolkit to enable reliable best architecture practices (FBP). 43 | */ 44 | 45 | /** 46 | * @defgroup fbp_core Core 47 | * @ingroup fbp 48 | * 49 | * @brief FBP Core. 50 | */ 51 | 52 | /** 53 | * @defgroup fbp_collections Collections 54 | * @ingroup fbp 55 | * 56 | * @brief FBP Collections. 57 | */ 58 | 59 | /** 60 | * @defgroup fbp_comm Comm 61 | * @ingroup fbp 62 | * 63 | * @brief FBP Comm. 64 | */ 65 | 66 | /** 67 | * @defgroup fbp_host Host 68 | * @ingroup fbp 69 | * 70 | * @brief FBP Host. 71 | */ 72 | 73 | /** 74 | * @defgroup fbp_memory Memory 75 | * @ingroup fbp 76 | * 77 | * @brief FBP Memory. 78 | */ 79 | 80 | /** 81 | * @defgroup fbp_os OS 82 | * @ingroup fbp 83 | * 84 | * @brief FBP Operating System. 85 | */ 86 | 87 | /** 88 | * @defgroup fbp_platform Platform 89 | * @ingroup fbp 90 | * 91 | * @brief FBP Platform. 92 | */ 93 | 94 | #endif /* FBP_H__ */ 95 | -------------------------------------------------------------------------------- /third-party/cmocka/example/mock/uptime/README.md: -------------------------------------------------------------------------------- 1 | The uptime mock example 2 | ======================= 3 | 4 | This is a very simple example to explain the mocking feature of cmocka. It 5 | implement the 'uptime' unix command in a very simple way to demonstrate how to 6 | test the time calculation. 7 | 8 | The problem with testing the uptime command is that /proc/uptime constantly 9 | ticks. The result is random whenever you call the test. To actually test it 10 | we need to make sure that we work with fixed values. The mocking features 11 | of cmocka allows us to test it anyway! 12 | 13 | Source files 14 | ------------ 15 | 16 | * *proc_uptime.c*: This implements the `uptime()` function reading and parsing 17 | the /proc/uptime file. 18 | * *uptime.c*: This is the actual uptime implementation, it calls 19 | `calc_uptime()` to get a human readable string representation of the uptime. 20 | This function calls `uptime()` from proc_uptime.c. 21 | * *test_uptime.c*: This is the test with the mocking function for uptime(). 22 | 23 | Linking magic 24 | ------------- 25 | 26 | The test is linked using: 27 | 28 | ld --wrap=uptime 29 | 30 | This replaces the orginal `uptime()` function which reads from `/proc/uptime` 31 | with the mock function we implemented for testing `calc_uptime()`. 32 | 33 | The mock function we implemented has a special name. It is called 34 | `__wrap_uptime()`. All the symbols you want to mock (or replace) need to start 35 | with the prefix `__wrap_`. So `ld --wrap=uptime` will rename the orignal 36 | `uptime()` function to `__real_uptime()`. This means you can still reach the 37 | original function using that name and call it e.g. from the wrap function. 38 | The symbol `uptime` will be bound to `__wrap_uptime`. 39 | 40 | You can find more details in the manpage: `man ld` 41 | 42 | The uptime test 43 | --------------- 44 | 45 | The code should be easy to understand. If you have a hard time following, there 46 | are two ways to understand how things work. 47 | 48 | You can find out details about symbol binding using: 49 | 50 | LD_DEBUG=symbols ./example/uptime/uptime 51 | LD_DEBUG=symbols ./example/uptime/test_uptime 52 | 53 | You can also use a debugger to step through the code! 54 | 55 | 56 | Have fun! 57 | -------------------------------------------------------------------------------- /include/fitterbap/config_defaults.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief The FBP shared library support functions. 21 | */ 22 | 23 | #ifndef FBP_CONFIG_DEFAULTS_H_ 24 | #define FBP_CONFIG_DEFAULTS_H_ 25 | 26 | #include "fitterbap/cmacro_inc.h" 27 | 28 | /** 29 | * @ingroup fbp_core 30 | * @defgroup fbp_config config 31 | * 32 | * @brief The FBP configuration defaults. 33 | * 34 | * @{ 35 | */ 36 | 37 | FBP_CPP_GUARD_START 38 | 39 | #ifndef FBP_CONFIG_OS_MUTEX_LOCK_TIMEOUT_MS 40 | #define FBP_CONFIG_OS_MUTEX_LOCK_TIMEOUT_MS (500) 41 | #endif 42 | 43 | #ifndef FBP_CONFIG_COMM_FRAMER_CRC32 44 | #define FBP_CONFIG_COMM_FRAMER_CRC32(data, length) fbp_crc32(0, (data), (length)) 45 | #endif 46 | 47 | #ifndef FBP_CONFIG_USE_CRC32 48 | #define FBP_CONFIG_USE_CRC32 1 49 | #endif 50 | 51 | #ifndef FBP_CONFIG_USE_FLOAT32 52 | #define FBP_CONFIG_USE_FLOAT32 0 53 | #endif 54 | 55 | #ifndef FBP_CONFIG_USE_FLOAT64 56 | #define FBP_CONFIG_USE_FLOAT64 0 57 | #endif 58 | 59 | #ifndef FBP_CONFIG_USE_CSTR_FLOAT 60 | #define FBP_CONFIG_USE_CSTR_FLOAT 0 61 | #endif 62 | 63 | // optional logging defines 64 | // #define FBP_LOG_GLOBAL_LEVEL FBP_LOG_LEVEL_ALL 65 | // #define FBP_LOG_PRINTF(level, format, ...) my_printf("%c %s:%d: " format "\n", fbp_log_level_char[level], __FILENAME__, __LINE__, __VA_ARGS__); 66 | 67 | // required typedefs 68 | // typedef void * fbp_os_mutex_t; 69 | // typedef intptr_t fbp_size_t; 70 | 71 | #ifndef FBP_FATAL 72 | #define FBP_FATAL(msg) fbp_fatal(__FILE__, __LINE__, msg) 73 | #endif 74 | 75 | FBP_CPP_GUARD_END 76 | 77 | /** @} */ 78 | 79 | #endif /* FBP_CONFIG_DEFAULTS_H_ */ 80 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_alloc.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #include 10 | #include 11 | #include 12 | 13 | static void torture_test_malloc(void **state) 14 | { 15 | char *str; 16 | size_t str_len; 17 | size_t len; 18 | 19 | (void)state; /* unsused */ 20 | 21 | str_len = 12; 22 | str = (char *)test_malloc(str_len); 23 | assert_non_null(str); 24 | 25 | len = snprintf(str, str_len, "test string"); 26 | assert_int_equal(len, 11); 27 | 28 | len = strlen(str); 29 | assert_int_equal(len, 11); 30 | 31 | test_free(str); 32 | } 33 | 34 | static void torture_test_realloc(void **state) 35 | { 36 | char *str; 37 | char *tmp; 38 | size_t str_len; 39 | size_t len; 40 | 41 | (void)state; /* unsused */ 42 | 43 | str_len = 16; 44 | str = (char *)test_malloc(str_len); 45 | assert_non_null(str); 46 | 47 | len = snprintf(str, str_len, "test string 123"); 48 | assert_int_equal(len, 15); 49 | 50 | len = strlen(str); 51 | assert_int_equal(len, 15); 52 | 53 | str_len = 20; 54 | tmp = test_realloc(str, str_len); 55 | assert_non_null(tmp); 56 | 57 | str = tmp; 58 | len = strlen(str); 59 | assert_string_equal(tmp, "test string 123"); 60 | 61 | snprintf(str + len, str_len - len, "4567"); 62 | assert_string_equal(tmp, "test string 1234567"); 63 | 64 | test_free(str); 65 | } 66 | 67 | static void torture_test_realloc_set0(void **state) 68 | { 69 | char *str; 70 | size_t str_len; 71 | 72 | (void)state; /* unsused */ 73 | 74 | str_len = 16; 75 | str = (char *)test_malloc(str_len); 76 | assert_non_null(str); 77 | 78 | /* realloc(ptr, 0) is like a free() */ 79 | str = (char *)test_realloc(str, 0); 80 | assert_null(str); 81 | } 82 | 83 | int main(void) { 84 | const struct CMUnitTest alloc_tests[] = { 85 | cmocka_unit_test(torture_test_malloc), 86 | cmocka_unit_test(torture_test_realloc), 87 | cmocka_unit_test(torture_test_realloc_set0), 88 | }; 89 | 90 | return cmocka_run_group_tests(alloc_tests, NULL, NULL); 91 | } 92 | -------------------------------------------------------------------------------- /third-party/cmocka/doc/that_style/header.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | $projectname: $title 9 | $title 10 | 11 | 12 | 13 | $treeview 14 | $search 15 | $mathjax 16 | 17 | 18 | $extrastylesheet 19 | 20 | 21 |
22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 38 | 39 | 40 | 41 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
33 |
$projectname 34 |  $projectnumber 35 |
36 |
$projectbrief
37 |
42 |
$projectbrief
43 |
$searchbox
54 |
55 | 56 | 57 | -------------------------------------------------------------------------------- /src/time.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* 4 | * Copyright 2021 Jetperch LLC 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | #include "fitterbap/common_header.h" 20 | #include "fitterbap/time.h" 21 | #include "tinyprintf.h" 22 | #include 23 | 24 | 25 | int32_t fbp_time_to_str(int64_t t, char * str, size_t size) { 26 | if (!size) { 27 | return 0; 28 | } 29 | int64_t microseconds = FBP_TIME_TO_MICROSECONDS(t); 30 | int64_t seconds = microseconds / 1000000; 31 | uint32_t days = (uint32_t) (seconds / (60 * 60 * 24)); 32 | days += 719468 + 17532; 33 | uint32_t era = days / 146097; 34 | uint32_t doe = days - era * 146097; 35 | uint32_t yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; // [0, 399] 36 | uint32_t y = yoe + era * 400; 37 | uint32_t doy = doe - (365*yoe + yoe/4 - yoe/100); // [0, 365] 38 | uint32_t mp = (5*doy + 2)/153; // [0, 11] 39 | uint32_t d = doy - (153 * mp + 2) / 5 + 1; // [1, 31] 40 | uint32_t m = mp + (mp < 10 ? 3 : -9); // [1, 12] 41 | y += (m <= 2) ? 1 : 0; 42 | 43 | uint32_t us = (uint32_t) (microseconds - (seconds * 1000000)); 44 | uint32_t ss = (uint32_t) (seconds % (60 * 60 * 24)); 45 | uint32_t hh = ss / (60 * 60); 46 | ss -= hh * (60 * 60); 47 | uint32_t mm = ss / 60; 48 | ss -= mm * 60; 49 | tfp_snprintf(str, size, "%04" PRIu32 "-%02" PRIu32"-%02" PRIu32 "T" 50 | "%02" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%06" PRIu32, 51 | y, m, d, hh, mm, ss, us); 52 | if (size >= FBP_TIME_STRING_LENGTH) { 53 | return (FBP_TIME_STRING_LENGTH - 1); 54 | } else { 55 | return ((int32_t) size - 1); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /include/fitterbap/pubsub_meta.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | /** 19 | * @file 20 | * 21 | * @brief PubSub metadata handling. 22 | */ 23 | 24 | #ifndef FBP_PUBSUB_META_H__ 25 | #define FBP_PUBSUB_META_H__ 26 | 27 | #include "fitterbap/common_header.h" 28 | #include "fitterbap/union.h" 29 | #include 30 | #include 31 | 32 | /** 33 | * @ingroup fbp_core 34 | * @defgroup fbp_pubsub_meta PubSub topic metadata 35 | * 36 | * @brief Handle JSON-formatted PubSub metadata. 37 | * 38 | * @{ 39 | */ 40 | 41 | FBP_CPP_GUARD_START 42 | 43 | /** 44 | * @brief Check the JSON metadata syntax. 45 | * 46 | * @param meta The JSON metadata. 47 | * @return 0 or error code. 48 | */ 49 | FBP_API int32_t fbp_pubsub_meta_syntax_check(const char * meta); 50 | 51 | /** 52 | * @brief Get the data type. 53 | * 54 | * @param meta The JSON metadata. 55 | * @param dtype[out] The fbp_union_e data type. 56 | * @return 0 or error code. 57 | */ 58 | FBP_API int32_t fbp_pubsub_meta_dtype(const char * meta, uint8_t * dtype); 59 | 60 | /** 61 | * @brief Get the default value. 62 | * 63 | * @param meta The JSON metadata. 64 | * @param value[out] The parsed default value. 65 | * @return 0 or error code. 66 | */ 67 | FBP_API int32_t fbp_pubsub_meta_default(const char * meta, struct fbp_union_s * value); 68 | 69 | /** 70 | * @brief Validate a parameter value using the metadata. 71 | * 72 | * @param meta The JSON metadata. 73 | * @param value[inout] The value, which is modified in place. 74 | * @return 0 or error code. 75 | */ 76 | FBP_API int32_t fbp_pubsub_meta_value(const char * meta, struct fbp_union_s * value); 77 | 78 | FBP_CPP_GUARD_END 79 | 80 | /** @} */ 81 | 82 | #endif /* FBP_PUBSUB_META_H__ */ 83 | -------------------------------------------------------------------------------- /third-party/cmocka/doc/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Build the documentation 3 | # 4 | if (${CMAKE_VERSION} VERSION_GREATER "3.8.99") 5 | 6 | find_package(Doxygen) 7 | 8 | if (DOXYGEN_FOUND) 9 | set(DOXYGEN_PROJECT_NAME ${PROJECT_NAME}) 10 | set(DOXYGEN_PROJECT_NUMBER ${PROJECT_VERSION}) 11 | set(DOXYGEN_PROJECT_BRIEF "Unit testing library with mock support") 12 | 13 | set(DOXYGEN_TAB_SIZE 4) 14 | set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C YES) 15 | set(DOXYGEN_MARKDOWN_SUPPORT YES) 16 | 17 | set(DOXYGEN_PREDEFINED DOXYGEN 18 | CMOCKA_PRINTF_ATTRIBUTE(x,y)) 19 | 20 | set(DOXYGEN_EXCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/that_style) 21 | set(DOXYGEN_HTML_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/that_style/header.html) 22 | set(DOXYGEN_HTML_EXTRA_STYLESHEET ${CMAKE_CURRENT_SOURCE_DIR}/that_style/that_style.css) 23 | set(DOXYGEN_HTML_EXTRA_FILES ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/nav_edge_left.svg 24 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/nav_edge_right.svg 25 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/nav_edge_inter.svg 26 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/sync_off.png 27 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/sync_on.png 28 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/splitbar_handle.svg 29 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/doc.svg 30 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/mag_glass.svg 31 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/folderclosed.svg 32 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/img/folderopen.svg 33 | ${CMAKE_CURRENT_SOURCE_DIR}/that_style/js/striped_bg.js) 34 | 35 | set(_doxyfile_template "${CMAKE_BINARY_DIR}/CMakeDoxyfile.in") 36 | set(_target_doxyfile "${CMAKE_CURRENT_BINARY_DIR}/Doxyfile.docs") 37 | configure_file("${_doxyfile_template}" "${_target_doxyfile}") 38 | 39 | doxygen_add_docs(docs 40 | ${cmocka-library_SOURCE_DIR} 41 | ${cmocka-header_SOURCE_DIR} 42 | ${CMAKE_CURRENT_SOURCE_DIR}) 43 | endif(DOXYGEN_FOUND) 44 | 45 | endif() # CMAKE_VERSION 46 | -------------------------------------------------------------------------------- /src/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set(SOURCES 16 | collections/list.c 17 | cli.c 18 | crc.c 19 | cstr.c 20 | ec.c 21 | event_manager.c 22 | fsm.c 23 | json.c 24 | lfsr.c 25 | log.c 26 | logh.c 27 | pattern_32a.c 28 | pubsub.c 29 | pubsub_meta.c 30 | time.c 31 | topic.c 32 | topic_list.c 33 | union.c 34 | version.c 35 | collections/ring_buffer_msg.c 36 | comm/data_link.c 37 | comm/framer.c 38 | comm/log_port.c 39 | comm/port.c 40 | comm/port0.c 41 | comm/pubsub_port.c 42 | comm/stack.c 43 | comm/timesync.c 44 | comm/transport.c 45 | memory/block.c 46 | memory/buffer.c 47 | memory/object_pool.c 48 | memory/pool.c 49 | ${PLATFORM_SRC} 50 | ) 51 | 52 | # Respect if TINYPRINTF has already been included, such as with RTOS build 53 | get_property(tinyprintf_property GLOBAL PROPERTY TINYPRINTF) 54 | if (NOT tinyprintf_property) 55 | message(STATUS "Fitterbap add tinyprintf") 56 | set(SOURCES ${SOURCES} ../third-party/tinyprintf/tinyprintf.c) 57 | endif() 58 | set_property(GLOBAL PROPERTY TINYPRINTF 1) 59 | 60 | if ("${FITTERBAP_OS}" STREQUAL "FREERTOS") 61 | set(SOURCES_HOST 62 | host/freertos/os_mutex.c 63 | host/freertos/os_task.c) 64 | 65 | elseif ("${FITTERBAP_OS}" STREQUAL "WIN32") 66 | set(SOURCES_HOST 67 | host/win/error.c 68 | host/win/uart.c 69 | host/win/platform.c 70 | host/win/comm.c) 71 | else() 72 | set(SOURCES_HOST "") 73 | endif() 74 | 75 | message(STATUS "SOURCES_HOST = ${SOURCES_HOST}") 76 | 77 | set(SOURCES ${SOURCES} ${SOURCES_HOST}) 78 | 79 | foreach(f IN LISTS SOURCES) 80 | SET_FILENAME("${f}") 81 | endforeach() 82 | 83 | add_library(fitterbap_objlib OBJECT ${SOURCES}) 84 | -------------------------------------------------------------------------------- /src/topic.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/topic.h" 18 | #include "fitterbap/ec.h" 19 | #include "fitterbap/platform.h" 20 | 21 | 22 | void fbp_topic_append(struct fbp_topic_s * topic, const char * subtopic) { 23 | char * topic_end = &topic->topic[FBP_PUBSUB_TOPIC_LENGTH_MAX]; 24 | if (topic->length && ('/' != topic->topic[topic->length -1])) { 25 | topic->topic[topic->length++] = '/'; 26 | } 27 | 28 | char * t = &topic->topic[topic->length]; 29 | while (*subtopic && (t < topic_end)) { 30 | char c = *subtopic++; 31 | *t++ = c; 32 | } 33 | FBP_ASSERT(t < topic_end); 34 | *t = 0; 35 | topic->length = (uint8_t) (t - topic->topic); 36 | } 37 | 38 | void fbp_topic_set(struct fbp_topic_s * topic, const char * str) { 39 | fbp_topic_clear(topic); 40 | while (*str && (topic->length < FBP_PUBSUB_TOPIC_LENGTH_MAX)) { 41 | topic->topic[topic->length++] = *str++; 42 | } 43 | FBP_ASSERT(topic->length < FBP_PUBSUB_TOPIC_LENGTH_MAX); 44 | topic->topic[topic->length] = 0; 45 | } 46 | 47 | void fbp_topic_append_char(struct fbp_topic_s * topic, char ch) { 48 | FBP_ASSERT(topic->length < (FBP_PUBSUB_TOPIC_LENGTH_MAX - 1)); 49 | topic->topic[topic->length++] = ch; 50 | topic->topic[topic->length] = 0; 51 | } 52 | 53 | char fbp_topic_remove_char(struct fbp_topic_s * topic) { 54 | char ch = 0; 55 | if (!topic->length) { 56 | return ch; 57 | } 58 | switch (topic->topic[topic->length - 1]) { 59 | case FBP_PUBSUB_CHAR_METADATA: /** intentional fall-through */ 60 | case FBP_PUBSUB_CHAR_QUERY: /** intentional fall-through */ 61 | case FBP_PUBSUB_CHAR_RETURN_CODE: 62 | ch = topic->topic[topic->length - 1]; 63 | topic->topic[topic->length - 1] = 0; 64 | topic->length--; 65 | break; 66 | default: 67 | break; 68 | } 69 | return ch; 70 | } 71 | -------------------------------------------------------------------------------- /include/fitterbap/os/mutex.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief OS Mutex abstraction. 21 | */ 22 | 23 | #ifndef FBP_OS_MUTEX_H__ 24 | #define FBP_OS_MUTEX_H__ 25 | 26 | #include "fitterbap/cmacro_inc.h" 27 | #include "fitterbap/config.h" 28 | #include "fitterbap/config_defaults.h" 29 | 30 | /** 31 | * @ingroup fbp_os 32 | * @defgroup fbp_os_mutex OS Mutex abstraction 33 | * 34 | * @brief Provide a simple OS mutex abstraction. 35 | * 36 | * Although FBP attempts to avoid OS calls, mutexes occur 37 | * frequently enough that the FBP library standardizes 38 | * on a convention. 39 | * 40 | * @{ 41 | */ 42 | 43 | FBP_CPP_GUARD_START 44 | 45 | /** 46 | * @brief Free an existing mutex (not recommended). 47 | * 48 | * @param mutex The mutex to free, previous produced using fbp_os_mutex_alloc(). 49 | */ 50 | FBP_INLINE_FN void fbp_os_mutex_free(fbp_os_mutex_t mutex) ; 51 | 52 | /** 53 | * @brief Allocate a new mutex. 54 | * 55 | * @param name The mutex name for platforms that support debug info. 56 | * @return The mutex or 0. 57 | */ 58 | FBP_COMPILER_ALLOC(fbp_os_mutex_free) FBP_INLINE_FN fbp_os_mutex_t fbp_os_mutex_alloc(const char * name); 59 | 60 | /** 61 | * @brief Lock a mutex. 62 | * 63 | * @param mutex The mutex to lock. If NULL, then skip the lock. 64 | * 65 | * Be sure to call fbp_os_mutex_unlock() when done. 66 | * 67 | * This function will use the default platform timeout. 68 | * An lock that takes longer than the timeout indicates 69 | * a system failure. In deployed embedded systems, this 70 | * should trip the watchdog timer. 71 | */ 72 | FBP_INLINE_FN void fbp_os_mutex_lock(fbp_os_mutex_t mutex); 73 | 74 | /** 75 | * @brief Unlock a mutex. 76 | * 77 | * @param mutex The mutex to unlock, which was previously locked 78 | * with fbp_os_mutex_lock(). If NULL, then skip the unlock. 79 | */ 80 | FBP_INLINE_FN void fbp_os_mutex_unlock(fbp_os_mutex_t mutex); 81 | 82 | FBP_CPP_GUARD_END 83 | 84 | /** @} */ 85 | 86 | #endif /* FBP_OS_MUTEX_H__ */ 87 | -------------------------------------------------------------------------------- /.github/workflows/windows.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # GitHub actions 16 | # See documentation: https://docs.github.com/en/actions 17 | # CMake example: https://github.com/Mizux/cmake-cpp/blob/main/.github/workflows/windows.yml 18 | 19 | name: Windows 20 | on: [push, pull_request, release] 21 | 22 | concurrency: 23 | group: dut 24 | cancel-in-progress: false 25 | 26 | jobs: 27 | build-windows: 28 | runs-on: windows-latest 29 | strategy: 30 | matrix: 31 | python-version: [3.9] 32 | 33 | steps: 34 | - name: Checkout the code 35 | uses: actions/checkout@v2 36 | 37 | - name: Configure python 38 | uses: actions/setup-python@v2 39 | with: 40 | python-version: ${{ matrix.python-version }} 41 | 42 | - name: Install Windows dependencies 43 | if: runner.os == 'Windows' 44 | shell: cmd 45 | run: | 46 | echo Path = %Path% 47 | cmake --version 48 | python3 -VV 49 | 50 | - name: Configure native build using CMake 51 | run: cmake -S . -B cmake_build -G "Visual Studio 17 2022" -DCMAKE_CONFIGURATION_TYPES=Release 52 | 53 | - name: Build native 54 | run: cmake --build cmake_build --config Release --target ALL_BUILD 55 | 56 | - name: Run native tests 57 | run: cmake --build cmake_build --config Release --target RUN_TESTS 58 | 59 | - name: Install python dependencies 60 | run: | 61 | pip3 install -U wheel 62 | pip3 install -U -r requirements.txt 63 | 64 | - name: Build python native 65 | run: python3 setup.py build_ext --inplace 66 | 67 | - name: Run python unit tests 68 | run: python3 -m unittest 69 | 70 | - name: Build python source package 71 | run: python3 setup.py sdist 72 | 73 | - name: Build python binary wheel package 74 | run: python3 setup.py bdist_wheel 75 | 76 | - name: Upload python packages 77 | uses: actions/upload-artifact@v2 78 | with: 79 | name: packages 80 | path: dist/* 81 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_strmatch.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Andreas Schneider 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "config.h" 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include "../src/cmocka.c" 25 | 26 | static void test_strmatch_null(void **state) 27 | { 28 | int rc; 29 | 30 | (void)state; 31 | 32 | rc = c_strmatch(NULL, NULL); 33 | assert_int_equal(rc, 0); 34 | 35 | rc = c_strmatch("", NULL); 36 | assert_int_equal(rc, 0); 37 | 38 | rc = c_strmatch(NULL, ""); 39 | assert_int_equal(rc, 0); 40 | } 41 | 42 | static void test_strmatch_empty(void **state) 43 | { 44 | int rc; 45 | 46 | (void)state; 47 | 48 | rc = c_strmatch("", ""); 49 | assert_int_equal(rc, 1); 50 | 51 | rc = c_strmatch("wurst", ""); 52 | assert_int_equal(rc, 0); 53 | 54 | rc = c_strmatch("", "wurst"); 55 | assert_int_equal(rc, 0); 56 | } 57 | 58 | static void test_strmatch_single(void **state) 59 | { 60 | int rc; 61 | 62 | (void)state; 63 | 64 | rc = c_strmatch("wurst", "wurs?"); 65 | assert_int_equal(rc, 1); 66 | 67 | rc = c_strmatch("wurst", "w?rs?"); 68 | assert_int_equal(rc, 1); 69 | 70 | rc = c_strmatch("wurst", "wur?"); 71 | assert_int_equal(rc, 0); 72 | } 73 | 74 | static void test_strmatch_wildcard(void **state) 75 | { 76 | int rc; 77 | 78 | (void)state; 79 | 80 | rc = c_strmatch("wurst", "wurst*"); 81 | assert_int_equal(rc, 1); 82 | 83 | rc = c_strmatch("wurstbrot", "wurst*"); 84 | assert_int_equal(rc, 1); 85 | 86 | rc = c_strmatch("wurstbrot", "w*t"); 87 | assert_int_equal(rc, 1); 88 | } 89 | 90 | int main(void) { 91 | const struct CMUnitTest tests[] = { 92 | cmocka_unit_test(test_strmatch_null), 93 | cmocka_unit_test(test_strmatch_empty), 94 | cmocka_unit_test(test_strmatch_single), 95 | cmocka_unit_test(test_strmatch_wildcard), 96 | }; 97 | 98 | return cmocka_run_group_tests(tests, NULL, NULL); 99 | } 100 | -------------------------------------------------------------------------------- /test/version_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include "fitterbap/version.h" 23 | 24 | static void test_encode_u32(void ** state) { 25 | (void) state; 26 | assert_int_equal(0x01000000, FBP_VERSION_ENCODE_U32(1, 0, 0)); 27 | assert_int_equal(0x00010000, FBP_VERSION_ENCODE_U32(0, 1, 0)); 28 | assert_int_equal(0x00000001, FBP_VERSION_ENCODE_U32(0, 0, 1)); 29 | assert_int_equal(0xff000000, FBP_VERSION_ENCODE_U32(0xff, 0, 0)); 30 | assert_int_equal(0x00ff0000, FBP_VERSION_ENCODE_U32(0, 0xff, 0)); 31 | assert_int_equal(0x0000ffff, FBP_VERSION_ENCODE_U32(0, 0, 0xffff)); 32 | 33 | assert_int_equal(0x00ff0000, FBP_VERSION_ENCODE_U32(0, 0xffffffff, 0)); 34 | assert_int_equal(0x0000ffff, FBP_VERSION_ENCODE_U32(0, 0, 0xffffffff)); 35 | } 36 | 37 | static void test_decode_u32(void ** state) { 38 | (void) state; 39 | assert_int_equal(1, FBP_VERSION_DECODE_U32_MAJOR(0x01000000)); 40 | assert_int_equal(1, FBP_VERSION_DECODE_U32_MINOR(0x00010000)); 41 | assert_int_equal(1, FBP_VERSION_DECODE_U32_PATCH(0x00000001)); 42 | } 43 | 44 | static void test_encode_str(void ** state) { 45 | (void) state; 46 | assert_string_equal("1.2.3", FBP_VERSION_ENCODE_STR(1, 2, 3)); 47 | assert_string_equal("255.255.65535", FBP_VERSION_ENCODE_STR(255, 255, 65535)); 48 | } 49 | 50 | static void test_convert_u32_to_str(void ** state) { 51 | (void) state; 52 | char s[FBP_VERSION_STR_LENGTH_MAX]; 53 | fbp_version_u32_to_str(0x01020003, s, sizeof(s)); 54 | assert_string_equal("1.2.3", s); 55 | fbp_version_u32_to_str(0xffffffff, s, sizeof(s)); 56 | assert_string_equal("255.255.65535", s); 57 | } 58 | 59 | int main(void) { 60 | const struct CMUnitTest tests[] = { 61 | cmocka_unit_test(test_encode_u32), 62 | cmocka_unit_test(test_decode_u32), 63 | cmocka_unit_test(test_encode_str), 64 | cmocka_unit_test(test_convert_u32_to_str), 65 | }; 66 | 67 | return cmocka_run_group_tests(tests, NULL, NULL); 68 | } 69 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_ordering_fail.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void mock_test_a_called(void) 10 | { 11 | function_called(); 12 | } 13 | 14 | static void mock_test_b_called(void) 15 | { 16 | function_called(); 17 | } 18 | 19 | static void mock_test_c_called(void) 20 | { 21 | function_called(); 22 | } 23 | 24 | static void test_does_fail_for_unexpected_call(void **state) 25 | { 26 | (void)state; 27 | expect_function_call(mock_test_a_called); 28 | expect_function_call(mock_test_a_called); 29 | 30 | mock_test_a_called(); 31 | mock_test_a_called(); 32 | mock_test_a_called(); 33 | } 34 | 35 | static void test_does_fail_for_unmade_expected_call(void **state) 36 | { 37 | (void)state; 38 | expect_function_call(mock_test_a_called); 39 | expect_function_call(mock_test_a_called); 40 | 41 | mock_test_a_called(); 42 | } 43 | 44 | static void test_ordering_fails_out_of_order(void **state) 45 | { 46 | (void)state; 47 | expect_function_call(mock_test_a_called); 48 | expect_function_call(mock_test_b_called); 49 | expect_function_call(mock_test_a_called); 50 | 51 | mock_test_b_called(); 52 | } 53 | 54 | static void test_ordering_fails_out_of_order_for_at_least_once_calls(void **state) 55 | { 56 | (void)state; 57 | expect_function_call_any(mock_test_a_called); 58 | ignore_function_calls(mock_test_b_called); 59 | 60 | mock_test_b_called(); 61 | mock_test_c_called(); 62 | } 63 | 64 | /* Primarily used to test error message */ 65 | static void test_fails_out_of_order_if_no_calls_found_on_any(void **state) 66 | { 67 | (void)state; 68 | expect_function_call_any(mock_test_a_called); 69 | ignore_function_calls(mock_test_b_called); 70 | 71 | mock_test_a_called(); 72 | mock_test_c_called(); 73 | } 74 | 75 | static void test_fails_if_zero_count_used(void **state) 76 | { 77 | (void)state; 78 | expect_function_calls(mock_test_a_called, 0); 79 | 80 | mock_test_a_called(); 81 | } 82 | 83 | int main(void) { 84 | const struct CMUnitTest tests[] = { 85 | cmocka_unit_test(test_does_fail_for_unexpected_call) 86 | ,cmocka_unit_test(test_does_fail_for_unmade_expected_call) 87 | ,cmocka_unit_test(test_does_fail_for_unmade_expected_call) 88 | ,cmocka_unit_test(test_ordering_fails_out_of_order) 89 | ,cmocka_unit_test(test_ordering_fails_out_of_order_for_at_least_once_calls) 90 | ,cmocka_unit_test(test_fails_out_of_order_if_no_calls_found_on_any) 91 | ,cmocka_unit_test(test_fails_if_zero_count_used) 92 | }; 93 | 94 | return cmocka_run_group_tests(tests, NULL, NULL); 95 | } 96 | -------------------------------------------------------------------------------- /third-party/cmocka/example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | project(cmocka-examples C) 2 | 3 | function(ADD_CMOCKA_TEST_ENVIRONMENT _TARGET_NAME) 4 | if (WIN32 OR CYGWIN OR MINGW) 5 | file(TO_NATIVE_PATH "${cmocka-library_BINARY_DIR}" CMOCKA_DLL_PATH) 6 | 7 | if (TARGET_SYSTEM_EMULATOR) 8 | set(DLL_PATH_ENV "WINEPATH=${CMOCKA_DLL_PATH};$ENV{WINEPATH}") 9 | else() 10 | set(DLL_PATH_ENV "PATH=${CMOCKA_DLL_PATH};$ENV{PATH}") 11 | endif() 12 | # 13 | # IMPORTANT NOTE: The set_tests_properties(), below, internally 14 | # stores its name/value pairs with a semicolon delimiter. 15 | # because of this we must protect the semicolons in the path 16 | # 17 | string(REPLACE ";" "\\;" DLL_PATH_ENV "${DLL_PATH_ENV}") 18 | 19 | set_tests_properties(${_TARGET_NAME} 20 | PROPERTIES 21 | ENVIRONMENT 22 | "${DLL_PATH_ENV}") 23 | endif() 24 | endfunction() 25 | 26 | set_source_files_properties(calculator.c 27 | allocate_module.c 28 | assert_module.c 29 | PROPERTIES 30 | COMPILE_DEFINITIONS 31 | UNIT_TESTING=1) 32 | 33 | 34 | ### The most simple test 35 | add_cmocka_test(simple_test 36 | SOURCES simple_test.c 37 | COMPILE_OPTIONS ${DEFAULT_C_COMPILE_FLAGS} 38 | LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) 39 | add_cmocka_test_environment(simple_test) 40 | 41 | ### Allocate module test 42 | add_cmocka_test(allocate_module_test 43 | SOURCES allocate_module.c allocate_module_test.c 44 | LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) 45 | add_cmocka_test_environment(allocate_module_test) 46 | 47 | set_tests_properties(allocate_module_test 48 | PROPERTIES 49 | WILL_FAIL 1) 50 | 51 | ### Assert macro test 52 | add_cmocka_test(assert_macro_test 53 | SOURCES assert_macro.c assert_macro_test.c 54 | LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) 55 | add_cmocka_test_environment(assert_macro_test) 56 | 57 | set_tests_properties(assert_macro_test 58 | PROPERTIES 59 | WILL_FAIL 1) 60 | 61 | ### Assert module test 62 | add_cmocka_test(assert_module_test 63 | SOURCES assert_module.c assert_module_test.c 64 | LINK_LIBRARIES ${CMOCKA_SHARED_LIBRARY}) 65 | add_cmocka_test_environment(assert_module_test) 66 | 67 | set_tests_properties(assert_module_test 68 | PROPERTIES 69 | WILL_FAIL 1) 70 | 71 | if (NOT WIN32) 72 | add_subdirectory(mock) 73 | endif() 74 | -------------------------------------------------------------------------------- /pyfitterbap/__main__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2018-2021 Jetperch LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """fbp command-line utility.""" 17 | 18 | 19 | import os 20 | import sys 21 | import argparse 22 | import logging 23 | import traceback 24 | from . import entry_points 25 | 26 | 27 | _LOG_LEVELS = { 28 | 'OFF': 100, 29 | 'CRITICAL': logging.CRITICAL, 30 | 'ERROR': logging.ERROR, 31 | 'WARNING': logging.WARNING, 32 | 'INFO': logging.INFO, 33 | 'DEBUG': logging.DEBUG, 34 | 'ALL': 0, 35 | } 36 | 37 | _EPILOG = f"""\ 38 | Set the PYFBP_LOG_LEVEL environment variable to change the logging level. 39 | Options are [{', '.join(_LOG_LEVELS.keys())}]. 40 | The default is WARNING. 41 | """ 42 | 43 | 44 | def get_parser(): 45 | parser = argparse.ArgumentParser( 46 | description='pyfbp command line tools.', 47 | epilog=_EPILOG, 48 | ) 49 | subparsers = parser.add_subparsers( 50 | dest='subparser_name', 51 | help='The command to execute') 52 | 53 | for entry_point in entry_points.__all__: 54 | default_name = entry_point.__name__.split('.')[-1] 55 | name = getattr(entry_point, 'NAME', default_name) 56 | cfg_fn = entry_point.parser_config 57 | p = subparsers.add_parser(name, help=cfg_fn.__doc__) 58 | cmd_fn = cfg_fn(p) 59 | if not callable(cmd_fn): 60 | raise ValueError(f'Invalid command function for {name}') 61 | p.set_defaults(func=cmd_fn) 62 | 63 | subparsers.add_parser('help', help='Display the command help. Use [command] --help to display help for a specific command.') 64 | 65 | return parser 66 | 67 | 68 | def run(): 69 | log_level = os.environ.get('PYFBP_LOG_LEVEL', 'WARNING').upper() 70 | log_level = _LOG_LEVELS.get(log_level, logging.WARNING) 71 | logging.basicConfig(level=log_level, 72 | format="%(levelname)s:%(asctime)s:%(filename)s:%(lineno)d:%(name)s:%(message)s") 73 | parser = get_parser() 74 | args = parser.parse_args() 75 | if args.subparser_name is None or args.subparser_name.lower() in ['help']: 76 | parser.print_help() 77 | parser.exit() 78 | return args.func(args) 79 | 80 | 81 | if __name__ == "__main__": 82 | sys.exit(run()) 83 | -------------------------------------------------------------------------------- /include/fitterbap/crc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Cyclic Redundancy Codes (CRC) 21 | */ 22 | 23 | #ifndef FBP_CRC_H__ 24 | #define FBP_CRC_H__ 25 | 26 | #include "fitterbap/cmacro_inc.h" 27 | #include 28 | 29 | /** 30 | * @ingroup fbp_core 31 | * @defgroup fbp_crc CRC 32 | * 33 | * @brief Cyclic Redundancy Codes (CRC). 34 | * 35 | * @{ 36 | */ 37 | 38 | FBP_CPP_GUARD_START 39 | 40 | /** 41 | * @brief Compute the CRC-CCITT-8 42 | * 43 | * @param crc The existing value for the crc which is used for continued block 44 | * computations. Pass 0 for the first block. 45 | * @param data The data for the CRC computation. 46 | * @param length The number of total_bytes in data. 47 | * @return The computed CRC-8. 48 | * 49 | * This function uses the 0x83 polynomial 50 | */ 51 | FBP_API uint8_t fbp_crc_ccitt_8(uint8_t crc, uint8_t const *data, uint32_t length); 52 | 53 | /** 54 | * @brief Compute the CRC-CCITT-16 in one's compliment form. 55 | * 56 | * @param crc The existing value for the crc which is used for continued block 57 | * computations. Pass 0 for the first block. 58 | * @param data The data for the CRC computation. 59 | * @param length The number of total_bytes in data. 60 | * @return The computed CRC-16. 61 | * 62 | * Although this implementation uses the CCITT 0x1021 polynomial, the 63 | * output is XOR'ed with 0xffff so that calls to this function may be 64 | * chained. 65 | * 66 | * @see http://srecord.sourceforge.net/crc16-ccitt.html 67 | * @see https://www.lammertbies.nl/comm/info/crc-calculation.html 68 | */ 69 | FBP_API uint16_t fbp_crc_ccitt_16(uint16_t crc, uint8_t const *data, uint32_t length); 70 | 71 | /** 72 | * @brief Compute the CRC-32 73 | * 74 | * @param crc The existing value for the crc which is used for continued block 75 | * computations. Pass 0 for the first block. 76 | * @param data The data for the CRC computation. 77 | * @param length The number of total_bytes in data. 78 | * @return The computed CRC-32. 79 | * 80 | * @see http://create.stephan-brumme.com/crc32/ 81 | * @see https://pycrc.org 82 | */ 83 | FBP_API uint32_t fbp_crc32(uint32_t crc, uint8_t const *data, uint32_t length); 84 | 85 | FBP_CPP_GUARD_END 86 | 87 | /** @} */ 88 | 89 | #endif /* FBP_CRC_H__ */ 90 | -------------------------------------------------------------------------------- /port/include/fitterbap/config.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief FBP configuration. 21 | */ 22 | 23 | #ifndef FBP_CONFIG_H_ 24 | #define FBP_CONFIG_H_ 25 | 26 | /** 27 | * @ingroup fbp 28 | * @defgroup fbp_config Configuration 29 | * 30 | * @brief FBP configuration. 31 | * 32 | * @{ 33 | */ 34 | 35 | /* Set global log level */ 36 | #define FBP_LOG_GLOBAL_LEVEL FBP_LOG_LEVEL_ALL 37 | 38 | /* Set the initial comm log port level for forwarding/receiving log messages. */ 39 | // #define FBP_LOGP_LEVEL FBP_LOG_LEVEL_WARNING 40 | 41 | /* Optionally Override the log format */ 42 | #if 0 // use the included Fitterbap log handler 43 | #ifndef FBP_LOG_PRINTF // allow unit tests to overwrite 44 | struct fbp_logh_s; 45 | int32_t fbp_logh_publish(struct fbp_logh_s * self, uint8_t level, const char * filename, uint32_t line, const char * format, ...); 46 | #define FBP_LOG_PRINTF(level, format, ...) \ 47 | fbp_logh_publish(NULL, level, __FILENAME__, __LINE__, format, __VA_ARGS__) 48 | #endif 49 | #elif 1 // redefine the printf format 50 | #ifndef FBP_LOG_PRINTF // allow unit tests to overwrite 51 | void fbp_log_printf_(const char * format, ...) FBP_PRINTF_FORMAT; 52 | #define FBP_LOG_PRINTF(level, format, ...) \ 53 | fbp_log_printf_("%c %s:%d: " format "\n", fbp_log_level_char[level], __FILENAME__, __LINE__, __VA_ARGS__); 54 | #endif 55 | #endif 56 | 57 | /** 58 | * @brief The 32-bit CRC function to use for the comm framer. 59 | * 60 | * The signature must be: 61 | * uint32_t (*fn)(uint8_t const *data, uint32_t length) 62 | */ 63 | //#define FBP_CONFIG_COMM_FRAMER_CRC32 fbp_crc32 64 | //#define FBP_CRC_CRC32 1 65 | 66 | // Uncomment for your platform 67 | //#define FBP_CONFIG_USE_PLATFORM_STDLIB 1 68 | //#define FBP_PLATFORM_ARM 1 69 | 70 | // remove the following for custom platforms 71 | #ifdef __linux__ 72 | #include "fitterbap/host/linux/config.h" 73 | #elif _WIN32 74 | #include "fitterbap/host/win/config.h" 75 | #else 76 | #error "unsupported platform" 77 | #endif 78 | 79 | // 1 to enable floating point 80 | #define FBP_CONFIG_USE_FLOAT32 1 81 | #define FBP_CONFIG_USE_FLOAT64 1 82 | #define FBP_CONFIG_USE_CSTR_FLOAT 1 83 | 84 | // typedef void * fbp_os_mutex_t; 85 | // typedef intptr_t fbp_size_t; 86 | 87 | /** @} */ 88 | 89 | #endif /* FBP_CONFIG_H_ */ 90 | -------------------------------------------------------------------------------- /include/fitterbap/cmacro_inc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | /** 18 | * @file 19 | * 20 | * @brief Commonly used C macros for FBP. 21 | */ 22 | 23 | #ifndef FBP_CMACRO_INC_H__ 24 | #define FBP_CMACRO_INC_H__ 25 | 26 | /** 27 | * @ingroup fbp_core 28 | * @defgroup fbp_cmacro_inc C Macros 29 | * 30 | * @brief Commonly used C macros for FBP. 31 | * 32 | * @{ 33 | */ 34 | 35 | /** 36 | * @def FBP_CPP_GUARD_START 37 | * @brief Make a C header file safe for a C++ compiler. 38 | * 39 | * This guard should be placed at near the top of the header file after 40 | * the \#if and imports. 41 | */ 42 | 43 | /** 44 | * @def FBP_CPP_GUARD_END 45 | * @brief Make a C header file safe for a C++ compiler. 46 | * 47 | * This guard should be placed at the bottom of the header file just before 48 | * the \#endif. 49 | */ 50 | 51 | #if defined(__cplusplus) && !defined(__CDT_PARSER__) 52 | #define FBP_CPP_GUARD_START extern "C" { 53 | #define FBP_CPP_GUARD_END }; 54 | #else 55 | #define FBP_CPP_GUARD_START 56 | #define FBP_CPP_GUARD_END 57 | #endif 58 | 59 | /** 60 | * @def FBP_API 61 | * @brief All functions that are available from the library are marked with 62 | * FBP_API. This platform-specific definition allows DLLs to ber 63 | * created properly on Windows. 64 | */ 65 | #if defined(WIN32) && defined(FBP_EXPORT) 66 | #define FBP_API __declspec(dllexport) 67 | #elif defined(WIN32) && defined(FBP_IMPORT) 68 | #define FBP_API __declspec(dllimport) 69 | #else 70 | #define FBP_API 71 | #endif 72 | 73 | /** 74 | * @brief Declare a packed structure. 75 | */ 76 | 77 | #ifdef __GNUC__ 78 | #define FBP_STRUCT_PACKED __attribute__((packed)) 79 | #define FBP_USED __attribute__((used)) 80 | #define FBP_FORMAT __attribute__((format)) 81 | #define FBP_INLINE_FN __attribute__((always_inline)) static inline 82 | #define FBP_PRINTF_FORMAT __attribute__((format (printf, 1, 2))) 83 | #define FBP_COMPILER_ALLOC(free_fn) __attribute__((malloc)) 84 | //#define FBP_COMPILER_ALLOC(free_fn) __attribute__((malloc, malloc(free_fn, 1))) // gcc 11 85 | #else 86 | #define FBP_STRUCT_PACKED 87 | #define FBP_USED 88 | #define FBP_FORMAT 89 | #define FBP_INLINE_FN static inline 90 | #define FBP_PRINTF_FORMAT 91 | #define FBP_COMPILER_ALLOC(free_fn) 92 | #endif 93 | 94 | 95 | /** @} */ 96 | 97 | #endif /* FBP_CMACRO_INC_H__ */ 98 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/ctest-default.cmake: -------------------------------------------------------------------------------- 1 | ## The directory to run ctest in. 2 | set(CTEST_DIRECTORY "$ENV{HOME}/workspace/tmp/dashboards/cmocka") 3 | 4 | ## The hostname of the machine 5 | set(CTEST_SITE "host.cmocka.org") 6 | ## The buildname 7 | set(CTEST_BUILD_NAME "Linux_GCC_x86_64_default") 8 | 9 | ## The Makefile generator to use 10 | set(CTEST_CMAKE_GENERATOR "Unix Makefiles") 11 | 12 | ## The Build configuration to use. 13 | set(CTEST_BUILD_CONFIGURATION "Debug") 14 | 15 | ## The build options for the project 16 | set(CTEST_BUILD_OPTIONS "-DUNIT_TESTING=ON -DWITH_CMOCKERY_SUPPORT=ON") 17 | 18 | #set(CTEST_CUSTOM_MEMCHECK_IGNORE torture_rand) 19 | 20 | ## The Model to set: Nightly, Continous, Experimental 21 | set(CTEST_MODEL "Experimental") 22 | 23 | ## The URL to the git repository 24 | set(CTEST_GIT_REPOSITORY "git://git.cryptomilk.org/projects/cmocka.git") 25 | 26 | ## The branch 27 | #set(CTEST_GIT_BRANCH "--branch v0-5") 28 | 29 | ## Wether to enable memory checking. 30 | set(WITH_MEMCHECK FALSE) 31 | 32 | ## Wether to enable code coverage. 33 | set(WITH_COVERAGE FALSE) 34 | 35 | ####################################################################### 36 | 37 | if (WITH_COVERAGE AND NOT WIN32) 38 | set(CTEST_BUILD_CONFIGURATION "Profiling") 39 | endif (WITH_COVERAGE AND NOT WIN32) 40 | 41 | set(CTEST_SOURCE_DIRECTORY "${CTEST_DIRECTORY}/${CTEST_BUILD_NAME}/source") 42 | set(CTEST_BINARY_DIRECTORY "${CTEST_DIRECTORY}/${CTEST_BUILD_NAME}/build") 43 | 44 | set(CTEST_MEMORYCHECK_SUPPRESSIONS_FILE ${CMAKE_SOURCE_DIR}/tests/valgrind.supp) 45 | 46 | find_program(CTEST_GIT_COMMAND NAMES git) 47 | find_program(CTEST_COVERAGE_COMMAND NAMES gcov) 48 | find_program(CTEST_MEMORYCHECK_COMMAND NAMES valgrind) 49 | 50 | if(NOT EXISTS "${CTEST_SOURCE_DIRECTORY}") 51 | set(CTEST_CHECKOUT_COMMAND "${CTEST_GIT_COMMAND} clone ${CTEST_GIT_BRANCH} ${CTEST_GIT_REPOSITORY} ${CTEST_SOURCE_DIRECTORY}") 52 | endif() 53 | 54 | set(CTEST_UPDATE_COMMAND "${CTEST_GIT_COMMAND}") 55 | 56 | set(CTEST_CONFIGURE_COMMAND "${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE:STRING=${CTEST_BUILD_CONFIGURATION}") 57 | set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} ${CTEST_BUILD_OPTIONS}") 58 | set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"-G${CTEST_CMAKE_GENERATOR}\"") 59 | set(CTEST_CONFIGURE_COMMAND "${CTEST_CONFIGURE_COMMAND} \"${CTEST_SOURCE_DIRECTORY}\"") 60 | 61 | ctest_empty_binary_directory(${CTEST_BINARY_DIRECTORY}) 62 | 63 | ctest_start(${CTEST_MODEL} TRACK ${CTEST_MODEL}) 64 | ctest_update(SOURCE ${CTEST_SOURCE_DIRECTORY}) 65 | ctest_configure(BUILD ${CTEST_BINARY_DIRECTORY}) 66 | ctest_build(BUILD ${CTEST_BINARY_DIRECTORY}) 67 | ctest_test(BUILD ${CTEST_BINARY_DIRECTORY}) 68 | if (WITH_MEMCHECK AND CTEST_COVERAGE_COMMAND) 69 | ctest_coverage(BUILD ${CTEST_BINARY_DIRECTORY}) 70 | endif (WITH_MEMCHECK AND CTEST_COVERAGE_COMMAND) 71 | if (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND) 72 | ctest_memcheck(BUILD ${CTEST_BINARY_DIRECTORY}) 73 | endif (WITH_MEMCHECK AND CTEST_MEMORYCHECK_COMMAND) 74 | ctest_submit() 75 | -------------------------------------------------------------------------------- /test/dbc_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "fitterbap/dbc.h" 22 | #include "fitterbap.h" 23 | 24 | 25 | static void test_true(void **state) { 26 | (void) state; 27 | FBP_DBC_TRUE(1); 28 | expect_assert_failure(FBP_DBC_TRUE(0)); 29 | } 30 | 31 | static void test_false(void **state) { 32 | (void) state; 33 | FBP_DBC_FALSE(0); 34 | expect_assert_failure(FBP_DBC_FALSE(1)); 35 | } 36 | 37 | static void test_not_null(void **state) { 38 | (void) state; 39 | int x = 0; 40 | int * p = &x; 41 | FBP_DBC_NOT_NULL(p); 42 | expect_assert_failure(FBP_DBC_NOT_NULL(0)); 43 | } 44 | 45 | static void test_equal(void **state) { 46 | (void) state; 47 | FBP_DBC_EQUAL(42, 42); 48 | expect_assert_failure(FBP_DBC_EQUAL(1, 2)); 49 | } 50 | 51 | static void test_gte_zero(void **state) { 52 | (void) state; 53 | FBP_DBC_GTE_ZERO(0); 54 | FBP_DBC_GTE_ZERO(100); 55 | expect_assert_failure(FBP_DBC_GTE_ZERO(-1)); 56 | } 57 | 58 | static void test_gt_zero(void **state) { 59 | (void) state; 60 | FBP_DBC_GT_ZERO(1); 61 | FBP_DBC_GT_ZERO(100); 62 | expect_assert_failure(FBP_DBC_GT_ZERO(0)); 63 | } 64 | 65 | static void test_lte_zero(void **state) { 66 | (void) state; 67 | FBP_DBC_LTE_ZERO(0); 68 | FBP_DBC_LTE_ZERO(-100); 69 | expect_assert_failure(FBP_DBC_LTE_ZERO(1)); 70 | } 71 | 72 | static void test_lt_zero(void **state) { 73 | (void) state; 74 | FBP_DBC_LT_ZERO(-1); 75 | FBP_DBC_LT_ZERO(-100); 76 | expect_assert_failure(FBP_DBC_LT_ZERO(0)); 77 | } 78 | 79 | static void test_range_int(void **state) { 80 | (void) state; 81 | FBP_DBC_RANGE_INT(-10, -10, 20); 82 | FBP_DBC_RANGE_INT(20, -10, 20); 83 | expect_assert_failure(FBP_DBC_RANGE_INT(-11, -10, 20)); 84 | expect_assert_failure(FBP_DBC_RANGE_INT(21, -10, 20)); 85 | } 86 | 87 | int main(void) { 88 | const struct CMUnitTest tests[] = { 89 | cmocka_unit_test(test_true), 90 | cmocka_unit_test(test_false), 91 | cmocka_unit_test(test_not_null), 92 | cmocka_unit_test(test_equal), 93 | cmocka_unit_test(test_gte_zero), 94 | cmocka_unit_test(test_gt_zero), 95 | cmocka_unit_test(test_lte_zero), 96 | cmocka_unit_test(test_lt_zero), 97 | cmocka_unit_test(test_range_int), 98 | }; 99 | 100 | return cmocka_run_group_tests(tests, NULL, NULL); 101 | } 102 | -------------------------------------------------------------------------------- /version_update.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright 2021 Jetperch LLC 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | """ 17 | Update the project version. 18 | 19 | Use the most recently CHANGELOG as the definitive version for: 20 | - CHANGELOG.md 21 | - CMakeLists.txt 22 | - include/fitterbap/version.h 23 | - pyfitterbap/version.py 24 | """ 25 | 26 | import os 27 | import re 28 | 29 | MYPATH = os.path.dirname(os.path.abspath(__file__)) 30 | 31 | 32 | def _str(version): 33 | return '.'.join([str(x) for x in version]) 34 | 35 | 36 | def _changelog_version(): 37 | path = os.path.join(MYPATH, 'CHANGELOG.md') 38 | with open(path, 'rt') as f: 39 | for line in f: 40 | if line.startswith('## '): 41 | version = line.split(' ')[1] 42 | return [int(x) for x in version.split('.')] 43 | 44 | 45 | def _cmakelists_update(version): 46 | regex = re.compile(r'(^\s*VERSION\s)') 47 | path = os.path.join(MYPATH, 'CMakeLists.txt') 48 | path_tmp = path + '.tmp' 49 | with open(path, 'rt') as rd: 50 | with open(path_tmp, 'wt') as wr: 51 | for line in rd: 52 | m = regex.match(line) 53 | if m is not None: 54 | line = m[1] + _str(version) + '\n' 55 | wr.write(line) 56 | os.replace(path_tmp, path) 57 | 58 | 59 | def _include_h_version(version): 60 | k = {'MAJOR': 0, 'MINOR': 1, 'PATCH': 2} 61 | regex = re.compile(r'#define FBP_VERSION_(MAJOR|MINOR|PATCH)\s') 62 | path = os.path.join(MYPATH, 'include', 'fitterbap', 'version.h') 63 | path_tmp = path + '.tmp' 64 | with open(path, 'rt') as rd: 65 | with open(path_tmp, 'wt') as wr: 66 | for line in rd: 67 | m = regex.match(line) 68 | if m is not None: 69 | v = version[k[m[1]]] 70 | line = f'#define FBP_VERSION_{m[1]} {v}\n' 71 | wr.write(line) 72 | os.replace(path_tmp, path) 73 | 74 | 75 | def _py_version(version): 76 | path = os.path.join(MYPATH, 'pyfitterbap', 'version.py') 77 | path_tmp = path + '.tmp' 78 | with open(path, 'rt') as rd: 79 | with open(path_tmp, 'wt') as wr: 80 | for line in rd: 81 | if line.startswith('__version__'): 82 | line = f'__version__ = "{_str(version)}"\n' 83 | wr.write(line) 84 | os.replace(path_tmp, path) 85 | 86 | 87 | def run(): 88 | version = _changelog_version() 89 | print(f'Version = {_str(version)}') 90 | _cmakelists_update(version) 91 | _include_h_version(version) 92 | _py_version(version) 93 | return 0 94 | 95 | 96 | if __name__ == '__main__': 97 | run() 98 | -------------------------------------------------------------------------------- /third-party/cmocka/tests/test_ordering.c: -------------------------------------------------------------------------------- 1 | #include "config.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | static void mock_test_a_called(void) 10 | { 11 | function_called(); 12 | } 13 | 14 | static void mock_test_b_called(void) 15 | { 16 | function_called(); 17 | } 18 | 19 | static void mock_test_c_called(void) 20 | { 21 | function_called(); 22 | } 23 | 24 | 25 | static void test_does_succeed_for_expected(void **state) 26 | { 27 | (void)state; 28 | expect_function_call(mock_test_a_called); 29 | expect_function_call(mock_test_a_called); 30 | 31 | mock_test_a_called(); 32 | mock_test_a_called(); 33 | } 34 | 35 | static void test_does_succeed_for_multiple_calls(void **state) 36 | { 37 | (void)state; 38 | expect_function_call(mock_test_a_called); 39 | expect_function_calls(mock_test_a_called, 2); 40 | expect_function_call(mock_test_a_called); 41 | 42 | mock_test_a_called(); 43 | mock_test_a_called(); 44 | mock_test_a_called(); 45 | mock_test_a_called(); 46 | } 47 | 48 | static void test_ordering_does_ignore_calls(void **state) 49 | { 50 | (void)state; 51 | 52 | ignore_function_calls(mock_test_a_called); 53 | 54 | mock_test_a_called(); 55 | mock_test_a_called(); 56 | mock_test_a_called(); 57 | } 58 | 59 | static void test_ordering_does_ignore_no_calls(void **state) 60 | { 61 | (void)state; 62 | ignore_function_calls(mock_test_a_called); 63 | } 64 | 65 | static void test_ordering_does_expect_at_least_one_call(void **state) 66 | { 67 | (void)state; 68 | expect_function_call_any(mock_test_a_called); 69 | 70 | mock_test_a_called(); 71 | mock_test_a_called(); 72 | mock_test_a_called(); 73 | } 74 | 75 | static void test_ordering_does_work_across_different_functions(void **state) 76 | { 77 | (void)state; 78 | expect_function_call(mock_test_a_called); 79 | expect_function_call(mock_test_b_called); 80 | expect_function_call(mock_test_a_called); 81 | 82 | mock_test_a_called(); 83 | mock_test_b_called(); 84 | mock_test_a_called(); 85 | } 86 | 87 | static void test_ordering_ignores_out_of_order_properly(void **state) 88 | { 89 | (void)state; 90 | ignore_function_calls(mock_test_a_called); 91 | ignore_function_calls(mock_test_b_called); 92 | expect_function_calls(mock_test_c_called, 2); 93 | 94 | 95 | mock_test_c_called(); 96 | mock_test_b_called(); 97 | mock_test_c_called(); 98 | } 99 | 100 | int main(void) { 101 | const struct CMUnitTest tests[] = { 102 | cmocka_unit_test(test_does_succeed_for_expected) 103 | ,cmocka_unit_test(test_does_succeed_for_multiple_calls) 104 | ,cmocka_unit_test(test_ordering_does_ignore_no_calls) 105 | ,cmocka_unit_test(test_ordering_does_ignore_calls) 106 | ,cmocka_unit_test(test_ordering_does_expect_at_least_one_call) 107 | ,cmocka_unit_test(test_ordering_does_work_across_different_functions) 108 | ,cmocka_unit_test(test_ordering_ignores_out_of_order_properly) 109 | }; 110 | 111 | return cmocka_run_group_tests(tests, NULL, NULL); 112 | } 113 | -------------------------------------------------------------------------------- /test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2014-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | #add_definitions(-Wno-format) 16 | 17 | set(TEST_FILES hal.c) 18 | add_library(test_objlib OBJECT ${TEST_FILES}) 19 | 20 | set(objects 21 | $ 22 | $) 23 | 24 | set(dependencies 25 | fitterbap_objlib 26 | test_objlib 27 | cmocka) 28 | include_directories(${CMOCKA_INCLUDE}) 29 | #include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include) 30 | 31 | function (ADD_CMOCKA_TEST _testName) 32 | set(TARGET ${_testName}) 33 | SET_FILENAME("${_testName}.c") 34 | add_executable(${_testName} "${_testName}.c" ${objects}) 35 | add_dependencies(${TARGET} fitterbap_objlib test_objlib cmocka) 36 | target_link_libraries(${_testName} cmocka) 37 | add_test(${_testName} ${CMAKE_CURRENT_BINARY_DIR}/${_testName}) 38 | endfunction (ADD_CMOCKA_TEST) 39 | 40 | add_subdirectory(collections) 41 | add_subdirectory(memory) 42 | add_subdirectory(comm) 43 | ADD_CMOCKA_TEST(argchk_test) 44 | ADD_CMOCKA_TEST(cdef_test) 45 | ADD_CMOCKA_TEST(cli_test) 46 | ADD_CMOCKA_TEST(crc_test) 47 | ADD_CMOCKA_TEST(cstr_test) 48 | ADD_CMOCKA_TEST(dbc_test) 49 | ADD_CMOCKA_TEST(ec_test) 50 | 51 | add_executable(event_manager_test event_manager_test.c ../src/event_manager.c hal.c) 52 | add_dependencies(event_manager_test cmocka) 53 | target_link_libraries(event_manager_test cmocka) 54 | add_test(event_manager_test ${CMAKE_CURRENT_BINARY_DIR}/event_manager_test) 55 | 56 | ADD_CMOCKA_TEST(fsm_test) 57 | ADD_CMOCKA_TEST(json_test) 58 | ADD_CMOCKA_TEST(lfsr_test) 59 | 60 | add_executable(log_test log_test.c) 61 | add_dependencies(log_test cmocka) 62 | target_link_libraries(log_test cmocka) 63 | add_test(log_test ${CMAKE_CURRENT_BINARY_DIR}/log_test) 64 | 65 | ADD_CMOCKA_TEST(logh_test) 66 | ADD_CMOCKA_TEST(pattern_32a_test) 67 | ADD_CMOCKA_TEST(platform_test) 68 | ADD_CMOCKA_TEST(pubsub_test) 69 | ADD_CMOCKA_TEST(pubsub_meta_test) 70 | ADD_CMOCKA_TEST(time_test) 71 | ADD_CMOCKA_TEST(topic_test) 72 | ADD_CMOCKA_TEST(topic_list_test) 73 | ADD_CMOCKA_TEST(union_test) 74 | ADD_CMOCKA_TEST(version_test) 75 | 76 | # test static assert compile failures 77 | # http://stackoverflow.com/questions/30155619/expected-build-failure-tests-in-cmake 78 | add_executable(cdef_static_assert_test cdef_static_assert_test.c) 79 | set_target_properties(cdef_static_assert_test PROPERTIES 80 | EXCLUDE_FROM_ALL TRUE 81 | EXCLUDE_FROM_DEFAULT_BUILD TRUE) 82 | add_test(NAME cdef_static_assert_test 83 | COMMAND ${CMAKE_COMMAND} --build . --target cdef_static_assert_test 84 | WORKING_DIRECTORY ${CMAKE_BINARY_DIR}) 85 | set_tests_properties(cdef_static_assert_test PROPERTIES WILL_FAIL TRUE) 86 | -------------------------------------------------------------------------------- /src/lfsr.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2014-2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "fitterbap/lfsr.h" 18 | #include "fitterbap/dbc.h" 19 | #include "fitterbap.h" 20 | 21 | void fbp_lfsr_initialize(struct fbp_lfsr_s * self) { 22 | FBP_DBC_NOT_NULL(self); 23 | self->value = LFSR16_INITIAL_VALUE; 24 | self->error_count = 0; 25 | self->resync_bit_count = 16; 26 | } 27 | 28 | void fbp_lfsr_seed_u16(struct fbp_lfsr_s * self, uint16_t seed) { 29 | FBP_DBC_NOT_NULL(self); 30 | if (seed == 0) { 31 | seed = 1; 32 | } 33 | self->value = seed; 34 | } 35 | 36 | static inline void value_guard(struct fbp_lfsr_s * self) { 37 | FBP_DBC_NOT_NULL(self); 38 | if (self->value == 0) { 39 | FBP_LOG_WARNING("Invalid lfsr value"); 40 | self->value = 1; 41 | } 42 | } 43 | 44 | static inline int fbp_lfsr_next_u1_inner(struct fbp_lfsr_s * self) { 45 | int bit = 0; 46 | uint16_t lfsr = self->value; 47 | bit = ((lfsr >> 0) ^ (lfsr >> 2) ^ (lfsr >> 3) ^ (lfsr >> 5) ) & 1; 48 | self->value = (lfsr >> 1) | (bit << 15); 49 | return bit; 50 | } 51 | 52 | int fbp_lfsr_next_u1(struct fbp_lfsr_s * self) { 53 | value_guard(self); 54 | return fbp_lfsr_next_u1_inner(self); 55 | } 56 | 57 | uint8_t fbp_lfsr_next_u8(struct fbp_lfsr_s * self) { 58 | int i = 0; 59 | value_guard(self); 60 | for (i = 0; i < 8; ++i) { 61 | fbp_lfsr_next_u1(self); 62 | } 63 | return (uint8_t) ((self->value & 0xff00) >> 8); 64 | } 65 | 66 | uint16_t fbp_lfsr_next_u16(struct fbp_lfsr_s * self) { 67 | int i = 0; 68 | value_guard(self); 69 | for (i = 0; i < 16; ++i) { 70 | fbp_lfsr_next_u1(self); 71 | } 72 | 73 | return self->value; 74 | } 75 | 76 | uint32_t fbp_lfsr_next_u32(struct fbp_lfsr_s * self) { 77 | uint32_t value = 0; 78 | value = ((uint32_t) fbp_lfsr_next_u16(self)) << 16; 79 | value |= (uint32_t) fbp_lfsr_next_u16(self); 80 | return value; 81 | } 82 | 83 | int fbp_lfsr_follow_u8(struct fbp_lfsr_s * self, uint8_t data) { 84 | uint8_t expected; 85 | FBP_DBC_NOT_NULL(self); 86 | if (self->resync_bit_count) { 87 | self->value = (self->value >> 8) | (((uint16_t) data) << 8); 88 | self->resync_bit_count -= 8; 89 | if (self->resync_bit_count < 0) { 90 | self->resync_bit_count = 0; 91 | } 92 | return 0; 93 | } 94 | expected = fbp_lfsr_next_u8(self); 95 | if (data == expected) { 96 | return 0; 97 | } else { 98 | self->value = ((uint16_t) data) << 8; 99 | self->resync_bit_count = 8; 100 | ++self->error_count; 101 | return -1; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /pyfitterbap/module.pxi: -------------------------------------------------------------------------------- 1 | # Copyright 2020-2021 Jetperch LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | """ 17 | Fitterbap initialization for a python module. 18 | """ 19 | 20 | from libc.stdint cimport intptr_t 21 | from libc.stdlib cimport malloc, free 22 | import sys 23 | import logging 24 | log = logging.getLogger(__name__) 25 | 26 | 27 | LOG_LEVEL_MAP = { 28 | '!': logging.CRITICAL, 29 | 'A': logging.CRITICAL, 30 | 'C': logging.CRITICAL, 31 | 'E': logging.ERROR, 32 | 'W': logging.WARNING, 33 | 'N': logging.INFO, 34 | 'I': logging.INFO, 35 | 'D': logging.DEBUG, 36 | '.': 0, 37 | } 38 | 39 | cdef extern from "stdarg.h": 40 | ctypedef struct va_list: 41 | pass 42 | ctypedef struct fake_type: 43 | pass 44 | void va_start(va_list, void* arg) nogil 45 | void* va_arg(va_list, fake_type) nogil 46 | void va_end(va_list) nogil 47 | fake_type int_type "int" 48 | 49 | cdef extern from "stdio.h": 50 | int vsnprintf (char * s, size_t n, const char * format, va_list arg ) nogil 51 | 52 | cdef extern from "fitterbap/platform_dependencies.h": 53 | void fbp_fatal(const char * file, int line, const char * msg) nogil 54 | 55 | # https://cython.readthedocs.io/en/latest/src/userguide/external_C_code.html#acquiring-and-releasing-the-gil 56 | cdef void _log_print(const char * s) noexcept with gil: 57 | try: 58 | msg = s.decode('utf-8') 59 | except Exception: 60 | log.warning("_log_print but not utf-8") 61 | return 62 | 63 | try: 64 | lvl = LOG_LEVEL_MAP[msg[0]] 65 | msg = msg[2:] 66 | if log.isEnabledFor(lvl): 67 | src_file, src_line, msg = msg.split(':', 2) 68 | msg = msg.strip() 69 | if src_file.startswith('src/'): 70 | src_file = src_file[4:] 71 | record = log.makeRecord(src_file, lvl, src_file, int(src_line), msg, [], None, None, None, None) 72 | log.handle(record) 73 | except Exception: 74 | log.exception(f'_log_print(msg)') 75 | 76 | cdef extern void fbp_log_printf_(const char *fmt, ...) nogil: 77 | cdef va_list args 78 | cdef char[256] s 79 | va_start(args, fmt) 80 | vsnprintf(&s[0], 256, fmt, args) # http://www.cplusplus.com/reference/cstdio/vsnprintf/ 81 | va_end(args) 82 | _log_print(s) 83 | 84 | 85 | cdef void _fbp_fatal(const char * file, int line, const char * msg) noexcept with gil: 86 | # since called from within C code, this exception will be ignored. 87 | # Consider a better error handler method. 88 | try: 89 | sys.stderr.write(f'fbp_fatal({file}, {line}, {msg}\n') 90 | sys.exit(-1) 91 | except Exception: 92 | print('_fbp_fatal failed') 93 | 94 | 95 | cdef void fbp_fatal(const char * file, int line, const char * msg) noexcept nogil: 96 | _fbp_fatal(file, line, msg) 97 | -------------------------------------------------------------------------------- /test/topic_test.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2021 Jetperch LLC 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include "fitterbap/topic.h" 22 | #include "fitterbap/ec.h" 23 | #include 24 | 25 | 26 | #define SETUP() \ 27 | (void) state; \ 28 | struct fbp_topic_s t = FBP_TOPIC_INIT 29 | 30 | 31 | #define assert_topic(str, t) \ 32 | assert_string_equal((str), (t)->topic); \ 33 | assert_int_equal(strlen(str), (t)->length) 34 | 35 | 36 | static void test_append(void **state) { 37 | SETUP(); 38 | assert_int_equal(0, t.length); 39 | fbp_topic_append(&t, "hello"); 40 | assert_topic("hello", &t); 41 | fbp_topic_append(&t, "there/"); 42 | assert_topic("hello/there/", &t); 43 | fbp_topic_append(&t, "world"); 44 | assert_topic("hello/there/world", &t); 45 | 46 | fbp_topic_append(&t, "message"); 47 | expect_assert_failure(fbp_topic_append(&t, "too_much")); 48 | } 49 | 50 | static void test_clear(void **state) { 51 | SETUP(); 52 | fbp_topic_append(&t, "hello"); 53 | fbp_topic_clear(&t); 54 | assert_topic("", &t); 55 | } 56 | 57 | static void test_truncate(void **state) { 58 | SETUP(); 59 | fbp_topic_append(&t, "hello"); 60 | uint8_t length = t.length; 61 | fbp_topic_append(&t, "world"); 62 | fbp_topic_truncate(&t, length); 63 | assert_topic("hello", &t); 64 | } 65 | 66 | static void test_set(void **state) { 67 | SETUP(); 68 | fbp_topic_set(&t, "hello"); 69 | assert_topic("hello", &t); 70 | expect_assert_failure(fbp_topic_set(&t, "hello/this/message/is/far/too/long/for/us")); 71 | } 72 | 73 | static void test_append_char(void **state) { 74 | SETUP(); 75 | fbp_topic_append_char(&t, '#'); 76 | assert_topic("#", &t); 77 | 78 | fbp_topic_set(&t, "hello"); 79 | fbp_topic_append_char(&t, '#'); 80 | assert_topic("hello#", &t); 81 | 82 | fbp_topic_set(&t, "hello/"); 83 | fbp_topic_append_char(&t, '#'); 84 | assert_topic("hello/#", &t); 85 | 86 | fbp_topic_set(&t, "01234567/01234567/01234567/012"); 87 | fbp_topic_append_char(&t, '#'); 88 | assert_topic("01234567/01234567/01234567/012#", &t); 89 | 90 | fbp_topic_set(&t, "01234567/01234567/01234567/0123"); 91 | expect_assert_failure(fbp_topic_append_char(&t, '#')); 92 | } 93 | 94 | int main(void) { 95 | const struct CMUnitTest tests[] = { 96 | cmocka_unit_test(test_append), 97 | cmocka_unit_test(test_clear), 98 | cmocka_unit_test(test_truncate), 99 | cmocka_unit_test(test_set), 100 | cmocka_unit_test(test_append_char), 101 | }; 102 | 103 | return cmocka_run_group_tests(tests, NULL, NULL); 104 | } 105 | --------------------------------------------------------------------------------