Skip to content

Commit 14d66e1

Browse files
committed
Squashed 'src/note-c/' content from commit bfe8cca
git-subtree-dir: src/note-c git-subtree-split: bfe8cca967702e615c7e59a11b8aec2c598d74a0
0 parents  commit 14d66e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+20526
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Container with dependencies necessary to run note-c unit tests.
2+
3+
# Build development environment
4+
# $ docker build . --tag note_c_run_unit_tests
5+
6+
# Launch development environment (mount source root as /note-c/)
7+
# $ docker run --rm --volume $(pwd)/../../../:/note-c/ --workdir /note-c/ note_c_run_unit_tests
8+
9+
# POSIX compatible (Linux/Unix) base image.
10+
FROM debian:stable-slim
11+
12+
# Install whatever dependencies we can via apt-get.
13+
RUN ["dash", "-c", "\
14+
apt-get update --quiet \
15+
&& apt-get install --assume-yes --no-install-recommends --quiet \
16+
build-essential \
17+
ca-certificates \
18+
curl \
19+
lcov \
20+
&& apt-get clean \
21+
&& apt-get purge \
22+
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
23+
"]
24+
25+
# Download and install CMake v3.25.1. We need CMake v3.20+ in order to get the
26+
# ctest --test-dir option used by run_unit_tests.sh.
27+
RUN ["dash", "-c", "\
28+
curl -LO https://github.com/Kitware/CMake/releases/download/v3.25.1/cmake-3.25.1-linux-x86_64.tar.gz \
29+
&& tar xf cmake-3.25.1-linux-x86_64.tar.gz --strip-components=1 -C /usr \
30+
&& rm cmake-3.25.1-linux-x86_64.tar.gz \
31+
"]
32+
33+
# Download and install Catch2 v3.2.1.
34+
RUN ["dash", "-c", "\
35+
curl -LO https://github.com/catchorg/Catch2/archive/refs/tags/v3.2.1.tar.gz \
36+
&& tar xf v3.2.1.tar.gz \
37+
&& cd Catch2-3.2.1 \
38+
&& cmake -DCATCH_INSTALL_DOCS=0 -B build/ \
39+
&& cmake --build build/ --target install \
40+
&& rm -rf Catch2-3.2.1 v3.2.1.tar.gz \
41+
"]
42+
43+
ENTRYPOINT ["./scripts/run_unit_tests.sh", "--coverage"]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
name: 'Run Unit Tests'
2+
author: 'Hayden Roche'
3+
description: 'Run unit tests inside Docker container.'
4+
runs:
5+
using: 'docker'
6+
image: 'Dockerfile'

.github/workflows/ci.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: note-c CI Pipeline
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
9+
jobs:
10+
run_unit_tests:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v3
15+
- name: Run unit tests
16+
uses: ./.github/actions/run_unit_tests
17+
run_astyle:
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Checkout Code
21+
uses: actions/checkout@v3
22+
- name: Install astyle
23+
run: sudo apt-get install -y astyle
24+
- name: Check formatting
25+
run: ./scripts/run_astyle.sh --check

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
.DS_Store
2+
Doxyfile.bak
3+
latex/
4+
html/
5+
6+
# VS Code workspace files
7+
*.code-workspace
8+
*.orig

CMakeLists.txt

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
cmake_minimum_required(VERSION 3.13)
2+
3+
if ("${CMAKE_BINARY_DIR}" STREQUAL "${CMAKE_SOURCE_DIR}")
4+
message(FATAL_ERROR "In-source builds are not allowed.
5+
Please create a build directory and use `cmake ..` inside it.
6+
NOTE: cmake will now create CMakeCache.txt and CMakeFiles/*.
7+
You must delete them, or cmake will refuse to work.")
8+
endif()
9+
10+
project(note_c)
11+
12+
# Automatically ignore CMake build directory.
13+
if(NOT EXISTS ${PROJECT_BINARY_DIR}/.gitignore)
14+
file(WRITE ${PROJECT_BINARY_DIR}/.gitignore "*")
15+
endif()
16+
17+
option(BUILD_TESTS "Build tests." ON)
18+
option(BUILD_SHARED_LIBS "Build note-c as a shared library." ON)
19+
option(COVERAGE "Compile for test coverage reporting." OFF)
20+
21+
add_compile_options(
22+
-Wall
23+
-Wextra
24+
-Wpedantic
25+
-Werror
26+
)
27+
28+
set(NOTE_C_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR})
29+
add_library(
30+
note_c
31+
${NOTE_C_SRC_DIR}/n_atof.c
32+
${NOTE_C_SRC_DIR}/n_cjson.c
33+
${NOTE_C_SRC_DIR}/n_const.c
34+
${NOTE_C_SRC_DIR}/n_helpers.c
35+
${NOTE_C_SRC_DIR}/n_i2c.c
36+
${NOTE_C_SRC_DIR}/n_printf.c
37+
${NOTE_C_SRC_DIR}/n_serial.c
38+
${NOTE_C_SRC_DIR}/n_ua.c
39+
${NOTE_C_SRC_DIR}/n_b64.c
40+
${NOTE_C_SRC_DIR}/n_cjson_helpers.c
41+
${NOTE_C_SRC_DIR}/n_ftoa.c
42+
${NOTE_C_SRC_DIR}/n_hooks.c
43+
${NOTE_C_SRC_DIR}/n_md5.c
44+
${NOTE_C_SRC_DIR}/n_request.c
45+
${NOTE_C_SRC_DIR}/n_str.c
46+
)
47+
48+
if(BUILD_TESTS)
49+
add_compile_definitions(
50+
TEST
51+
)
52+
53+
# Including this here rather than in test/CMakeLists.txt allows us to run
54+
# ctest from the root build directory (e.g. build/ instead of build/test/).
55+
include(CTest)
56+
57+
# If we don't weaken the functions we're mocking in the tests, the linker
58+
# will complain about multiple function definitions: the mocked one and the
59+
# "real" one from note-c. Weakening the real function causes the mock
60+
# function, if defined, to override the real one. If no mock is defined, the
61+
# real one will be used. So, every time a developer needs to mock a function
62+
# in a test, they need to make sure it's included in the MOCKED_FNS list
63+
# below.
64+
set(
65+
MOCKED_FNS
66+
"NoteReset;
67+
NoteJSONTransaction;
68+
NoteTransaction;
69+
NoteGetMs;
70+
NoteRequestResponse;
71+
NoteMalloc;
72+
NoteI2CTransmit;
73+
NoteI2CReceive;
74+
NoteLockI2C;
75+
NoteUnlockI2C;
76+
NoteI2CReset"
77+
)
78+
foreach(MOCKED_FN ${MOCKED_FNS})
79+
string(APPEND OBJCOPY_WEAKEN "-W ${MOCKED_FN} ")
80+
endforeach()
81+
separate_arguments(OBJCOPY_WEAKEN_LIST NATIVE_COMMAND "${OBJCOPY_WEAKEN}")
82+
add_custom_command(TARGET note_c POST_BUILD
83+
COMMAND ${CMAKE_OBJCOPY} ${OBJCOPY_WEAKEN_LIST}
84+
$<TARGET_FILE:note_c>
85+
COMMENT "Weakening mocked functions."
86+
)
87+
88+
add_subdirectory(test)
89+
endif(BUILD_TESTS)

CODE_OF_CONDUCT.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Code of conduct
2+
3+
By participating in this project, you agree to abide by the
4+
[Blues Inc code of conduct][1].
5+
6+
[1]: https://blues.github.io/opensource/code-of-conduct
7+

CONTRIBUTING.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Contributing to blues/note-c
2+
3+
We love pull requests from everyone. By participating in this project, you
4+
agree to abide by the Blues Inc [code of conduct].
5+
6+
[code of conduct]: https://blues.github.io/opensource/code-of-conduct
7+
8+
Here are some ways *you* can contribute:
9+
10+
* by using alpha, beta, and prerelease versions
11+
* by reporting bugs
12+
* by suggesting new features
13+
* by writing or editing documentation
14+
* by writing specifications
15+
* by writing code ( **no patch is too small** : fix typos, add comments,
16+
clean up inconsistent whitespace )
17+
* by refactoring code
18+
* by closing [issues][]
19+
* by reviewing patches
20+
21+
[issues]: https://github.com/blues/note-c/issues
22+
23+
## Submitting an Issue
24+
25+
* We use the [GitHub issue tracker][issues] to track bugs and features.
26+
* Before submitting a bug report or feature request, check to make sure it
27+
hasn't
28+
already been submitted.
29+
* When submitting a bug report, please include a [Gist][] that includes a stack
30+
trace and any details that may be necessary to reproduce the bug, including
31+
your gem version, Ruby version, and operating system. Ideally, a bug report
32+
should include a pull request with failing specs.
33+
34+
[gist]: https://gist.github.com/
35+
36+
## Cleaning up issues
37+
38+
* Issues that have no response from the submitter will be closed after 30 days.
39+
* Issues will be closed once they're assumed to be fixed or answered. If the
40+
maintainer is wrong, it can be opened again.
41+
* If your issue is closed by mistake, please understand and explain the issue.
42+
We will happily reopen the issue.
43+
44+
## Submitting a Pull Request
45+
1. [Fork][fork] the [official repository][repo].
46+
2. [Create a topic branch.][branch]
47+
3. Implement your feature or bug fix.
48+
4. Add, commit, and push your changes.
49+
5. [Submit a pull request.][pr]
50+
51+
## Notes
52+
* Please add tests if you changed code. Contributions without tests won't be
53+
* accepted. If you don't know how to add tests, please put in a PR and leave a
54+
* comment asking for help. We love helping!
55+
56+
[repo]: https://github.com/blues/note-c/tree/master
57+
[fork]: https://help.github.com/articles/fork-a-repo/
58+
[branch]:
59+
https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
60+
[pr]: https://help.github.com/articles/creating-a-pull-request-from-a-fork/
61+
62+
Inspired by
63+
https://github.com/thoughtbot/factory_bot/blob/master/CONTRIBUTING.md
64+

0 commit comments

Comments
 (0)