Skip to content

Commit

Permalink
Add test environment and init CI
Browse files Browse the repository at this point in the history
  • Loading branch information
NValsted committed Apr 1, 2024
1 parent 9cf1b96 commit 728be4e
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 3 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Tests

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Install clang-format
run: sudo apt-get install -y clang-format

- name: Check code formatting
run: |
find . -name '*.cpp' -or -name '*.hpp' -or -name '*.c' -or -name '*.h' | xargs clang-format -style=file -i
git diff --exit-code
- name: Build and run tests
run: |
docker build -t csp_proc .
docker run -t csp_proc
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
git \
python3 \
python3-pip \
ninja-build \
gcc \
g++ \
meson \
libcriterion-dev

WORKDIR /csp_proc/
RUN git clone https://github.com/spaceinventor/libcsp.git lib/csp
RUN git clone https://github.com/spaceinventor/libparam.git lib/param
RUN git clone https://github.com/spaceinventor/slash.git lib/slash
RUN git clone https://github.com/FreeRTOS/FreeRTOS-Kernel.git lib/freertos

COPY . /csp_proc/

CMD meson setup builddir \
&& meson compile -C builddir \
&& meson test -C builddir
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
# csp_proc
Lightweight, programmable procedures with a libcsp- and libparam-native runtime. This library has a relatively small footprint suitable for microcontrollers, requiring no external libraries other than libcsp and libparam themselves.
![Tests](https://github.com/discosat/csp_proc/actions/workflows/run-tests.yml/badge.svg)

This provides remote control over coordination between nodes in a CSP network, essentially exposing the network as single programmable unit.
Lightweight, programmable procedures with a libcsp- and libparam-native runtime. This provides remote control over coordination between nodes in a CSP network, essentially exposing the network as single programmable unit.

The library has a relatively small footprint suitable for microcontrollers, requiring no external libraries other than libcsp and libparam themselves for the core of the library. However, currently, the only runtime implementation relies on FreeRTOS.

# Build environment
Refer to the Dockerfile for a reference build environment. It can be brought up like so:

```bash
docker build -t csp_proc .
docker run -t csp_proc
```
20 changes: 19 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
project('csp_proc', 'c')
project('csp_proc', 'c', subproject_dir: 'lib', default_options: [
'c_std=gnu11',
'b_lto=false',
'default_library=static',
])

csp_dep = dependency('csp', fallback : ['csp', 'csp_dep'])
param_dep = dependency('param', fallback : ['param', 'param_dep'])
Expand Down Expand Up @@ -76,3 +80,17 @@ csp_proc_lib = static_library('csp_proc',
)

csp_proc_dep = declare_dependency(include_directories : csp_proc_inc, link_with : csp_proc_lib)


# Tests
criterion_dep = dependency('criterion', required : false)
if not criterion_dep.found()
error('Criterion not found (required for tests)')
endif

test_src = files([
'tests/test_proc_pack.c',
])

run_tests_executable = executable('run_tests', test_src, dependencies : [criterion_dep, csp_proc_dep, csp_dep, param_dep, slash_dep, freertos_dep])
test('run_tests', run_tests_executable)
31 changes: 31 additions & 0 deletions tests/test_proc_pack.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#include <criterion/criterion.h>

#include <csp/csp_types.h>
#include <csp_proc/proc_types.h>
#include <csp_proc/proc_pack.h>

Test(proc_pack_unpack, test_pack_unpack) {
proc_t original_proc;
csp_packet_t packet;

original_proc.instruction_count = 1;
original_proc.instructions[0].node = 1;
original_proc.instructions[0].type = PROC_BLOCK;
original_proc.instructions[0].instruction.block.param_a = "param_a";
original_proc.instructions[0].instruction.block.op = OP_EQ;
original_proc.instructions[0].instruction.block.param_b = "param_b";

int pack_result = pack_proc_into_csp_packet(&original_proc, &packet);
cr_assert(pack_result == 0, "Packing failed");

proc_t new_proc;
int unpack_result = unpack_proc_from_csp_packet(&new_proc, &packet);
cr_assert(unpack_result == 0, "Unpacking failed");

cr_assert(original_proc.instruction_count == new_proc.instruction_count, "Instruction counts do not match");
cr_assert(original_proc.instructions[0].node == new_proc.instructions[0].node, "Nodes do not match");
cr_assert(original_proc.instructions[0].type == new_proc.instructions[0].type, "Types do not match");
cr_assert(strcmp(original_proc.instructions[0].instruction.block.param_a, new_proc.instructions[0].instruction.block.param_a) == 0, "param_a does not match");
cr_assert(original_proc.instructions[0].instruction.block.op == new_proc.instructions[0].instruction.block.op, "op does not match");
cr_assert(strcmp(original_proc.instructions[0].instruction.block.param_b, new_proc.instructions[0].instruction.block.param_b) == 0, "param_b does not match");
}

0 comments on commit 728be4e

Please sign in to comment.