Skip to content

Commit

Permalink
Version 2 with API enhancements (#7)
Browse files Browse the repository at this point in the history
* Actualize the tooling
* Add spelling dictionary
* Remove critical section hooks; fix #4
* Clean up redundant declarations
* Add support for O1HEAP_CONFIG_HEADER, fix #5
  • Loading branch information
pavel-kirienko committed Oct 9, 2021
1 parent d1c19dd commit 9daa66d
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 252 deletions.
57 changes: 41 additions & 16 deletions .github/workflows/main.yml
Expand Up @@ -5,7 +5,6 @@ on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest

strategy:
matrix:
toolchain: ['clang', 'gcc']
Expand All @@ -15,17 +14,22 @@ jobs:
c-compiler: gcc
cxx-compiler: g++
- toolchain: clang
c-compiler: clang-11
cxx-compiler: clang++-11

c-compiler: clang
cxx-compiler: clang++
steps:
- uses: actions/checkout@v2

- name: Install Dependencies
run: sudo apt install gcc-multilib g++-multilib clang-tidy-9 clang-format-9
run: sudo apt install gcc-multilib g++-multilib clang-tidy-12

- name: Configure CMake
run: cmake -B ${{ github.workspace }}/build -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DCMAKE_C_COMPILER=${{ matrix.c-compiler }} -DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }} tests
run: >
cmake
-B ${{ github.workspace }}/build
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-DCMAKE_C_COMPILER=${{ matrix.c-compiler }}
-DCMAKE_CXX_COMPILER=${{ matrix.cxx-compiler }}
tests
- name: Build
working-directory: ${{github.workspace}}/build
Expand All @@ -36,24 +40,23 @@ jobs:
run: make test

sonarcloud:
if: endsWith(github.base_ref, 'master') || endsWith(github.ref, 'master')
runs-on: ubuntu-latest
env:
SONAR_SCANNER_VERSION: 4.6.1.2450
SONAR_SERVER_URL: "https://sonarcloud.io"
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
CC: gcc-9
CXX: g++-9

runs-on: ubuntu-latest

CC: gcc
CXX: g++
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Install Dependencies
run: sudo apt install g++-9 g++-9-multilib gcc-9-multilib
run: sudo apt install g++ g++-multilib gcc-multilib

- name: Set up JDK 11
uses: actions/setup-java@v1
Expand All @@ -72,7 +75,7 @@ jobs:
SONAR_SCANNER_DOWNLOAD_URL: https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-${{ env.SONAR_SCANNER_VERSION }}-linux.zip
run: |
mkdir -p $HOME/.sonar
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
curl -sSLo $HOME/.sonar/sonar-scanner.zip ${{ env.SONAR_SCANNER_DOWNLOAD_URL }}
unzip -o $HOME/.sonar/sonar-scanner.zip -d $HOME/.sonar/
echo "$HOME/.sonar/sonar-scanner-${{ env.SONAR_SCANNER_VERSION }}-linux/bin" >> $GITHUB_PATH
Expand All @@ -89,8 +92,30 @@ jobs:
cmake tests -DCMAKE_BUILD_TYPE=Debug -DNO_STATIC_ANALYSIS=1
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} make all
make test
gcov-10 --preserve-paths --long-file-names $(find CMakeFiles/test_private_cov.dir -name '*.gcno')
gcov --preserve-paths --long-file-names $(find CMakeFiles/test_general_cov.dir -name '*.gcno')
gcov --preserve-paths --long-file-names $(find CMakeFiles/test_private_cov.dir -name '*.gcno')
- name: Run sonar-scanner
run: |
sonar-scanner --define sonar.host.url="${{ env.SONAR_SERVER_URL }}" --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}" --define sonar.login=${{ secrets.SONAR_TOKEN }}
run: >
sonar-scanner
--define sonar.projectKey="pavel-kirienko_o1heap"
--define sonar.organization="pavel-kirienko"
--define sonar.sources="o1heap/"
--define sonar.sourceEncoding="UTF-8"
--define sonar.cfamily.gcov.reportsPath="."
--define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
--define sonar.cfamily.cache.enabled="false"
--define sonar.cfamily.threads=1
--define sonar.host.url="${{ env.SONAR_SERVER_URL }}"
--define sonar.login=${{ secrets.SONAR_TOKEN }}
style_check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: DoozyX/clang-format-lint-action@v0.12
with:
source: './o1heap ./tests'
exclude: './tests/catch'
extensions: 'c,h,cpp,hpp'
clangFormatVersion: 12
4 changes: 3 additions & 1 deletion .gitignore
Expand Up @@ -52,6 +52,8 @@ Mkfile.old
dkms.conf

# IDE & outputs
.idea/
**/.idea/*
!**/.idea/dictionaries
!**/.idea/dictionaries/*
cmake-build-*/
build/
38 changes: 27 additions & 11 deletions README.md
Expand Up @@ -16,7 +16,7 @@ which makes it suitable for use in high-integrity embedded systems.

The codebase is implemented in C99/C11 following MISRA C:2012, with several intended deviations which are unavoidable
due to the fact that a memory allocator has to rely on inherently unsafe operations to fulfill its purpose.
The codebase is extremely compact (<500 SLoC) and is therefore trivial to validate.
The codebase is extremely compact (<500 LoC) and is therefore trivial to validate.

The allocator is designed to be portable across all conventional architectures, from 8-bit to 64-bit systems.
Multi-threaded environments are supported with the help of external synchronization hooks provided by the application.
Expand Down Expand Up @@ -77,9 +77,9 @@ a memory allocation request even if there is enough free memory due to its subop
By definition, if the amount of memory available to the allocator is not less than *H*, then the state of
catastrophic fragmentation cannot occur.

Memory allocators used in general-purpose (non real-time) applications often leverage a different class of algorithms
Memory allocators used in general-purpose (non-real-time) applications often leverage a different class of algorithms
which may feature poorer worst-case performance metrics but perform (much) better on average.
For a hard real-time system, the average case performance is generally less relevant
For a hard real-time system, the average case performance is generally less relevant,
so it can be excluded from analysis.

The above-defined theoretical worst-case upper bound H may be prohibitively high for some
Expand All @@ -90,7 +90,7 @@ the probability of a (de-)allocation sequence that results in catastrophic fragm
When combined with an acceptable failure probability and a set of adequate assumptions about the behaviors of
the application, this property may allow the designer to drastically reduce the amount of memory dedicated to
the heap while ensuring a sufficient degree of predictability and reliability.
The methods of such optimization are outside of the scope of this document;
The methods of such optimization are outside the scope of this document;
interested readers are advised to consult with the referred publications.

Following some of the ideas expressed in the discussion about memory caching in real-time systems in [Herter 2014],
Expand Down Expand Up @@ -173,15 +173,18 @@ and its internal data structures are not damaged.

### Build configuration options

The preprocessor options given below can be overridden (e.g., using the `-D` compiler flag, depending on the compiler)
to fine-tune the implementation.
The preprocessor options given below can be overridden to fine-tune the implementation.
None of them are mandatory to use.

#### O1HEAP_CONFIG_HEADER

Define this optional macro like `O1HEAP_CONFIG_HEADER="path/to/my_o1heap_config.h"` to pass build configuration macros.
This is useful because some build systems do not allow passing function-like macros via command line flags.

#### O1HEAP_ASSERT(x)

The macro `O1HEAP_ASSERT(x)` can be defined to customize the assertion handling or to disable it.
To disable assertion checks, the macro should expand into `(void)(x)`.

If not specified, the macro expands into the standard assertion check macro `assert(x)` as defined in `<assert.h>`.

#### O1HEAP_LIKELY(x)
Expand All @@ -195,7 +198,7 @@ or into the original expression `(x)` if no such hinting is desired.
If not specified, the macro expands as follows:

- For some well-known compilers the macro automatically expands into appropriate branch weighting intrinsics.
For example, for GCC, Clang, and ARM Compiler, it expands into `__builtin_expect((x), 1)`.
For example, for GCC, Clang, and ARM Compiler, it expands into `__builtin_expect((x), 1)`.
- For other (unknown) compilers it expands into the original expression with no modifications: `(x)`.

## Development
Expand All @@ -204,9 +207,7 @@ For example, for GCC, Clang, and ARM Compiler, it expands into `__builtin_expect

The following tools should be available locally to conduct library development:

- GCC v9 or newer.
- Clang and Clang-Tools v9 or newer.
- CMake v3.12 or newer.
- Modern versions of CMake, GCC, Clang, and Clang-Tools.
- An AMD64 machine.
- (optional) Valgrind.

Expand All @@ -223,6 +224,10 @@ Compliance is enforced through the following means:

Please refer to the continuous integration configuration to see how to invoke the tests.

### Releasing

Update the version number macro in the header file and create a new git tag like `1.0`.

### MISRA compliance

MISRA compliance is enforced with the help of the following tools:
Expand Down Expand Up @@ -252,6 +257,17 @@ An exception applies for the case of false-positive (invalid) warnings -- those
- [Dynamic Memory Allocation In SQLite](https://sqlite.org/malloc.html) -- on Robson proof and deterministic fragmentation.
- *[Russian]* [Динамическая память в системах жёсткого реального времени](https://habr.com/ru/post/486650/) -- issues with dynamic memory allocation in modern embedded RTOS and related popular misconceptions.

## Changelog

### v2.0

- Remove critical section hooks to enhance MISRA conformance [#4](https://github.com/pavel-kirienko/o1heap/issues/4)
- Add support for config header via `O1HEAP_CONFIG_HEADER` [#5](https://github.com/pavel-kirienko/o1heap/issues/5)

### v1.0

The first release.

## License

The library is available under the terms of the MIT License.
Expand Down
3 changes: 3 additions & 0 deletions o1heap/.clang-tidy
Expand Up @@ -16,6 +16,9 @@ Checks: >-
-google-readability-todo,
-readability-avoid-const-params-in-decls,
-llvm-header-guard,
CheckOptions:
- key: readability-function-cognitive-complexity.Threshold
value: '199'
WarningsAsErrors: '*'
HeaderFilterRegex: '.*'
AnalyzeTemporaryDtors: false
Expand Down

0 comments on commit 9daa66d

Please sign in to comment.