Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add action to build and test using more Ubuntu releases #15

Merged
merged 6 commits into from
Dec 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,10 @@ jobs:
ubuntu:
strategy:
matrix:
release: ["22.04"]
compiler: ["gcc", "clang"]
release: ["16.04", "18.04", "20.04", "22.04"]
runs-on: ubuntu-latest
container:
image: ubuntu:${{ matrix.release }}
env:
CC: ${{ matrix.compiler }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
Expand All @@ -36,14 +33,26 @@ jobs:
apt-get install -y --no-install-recommends clang build-essential \
cmake libyaml-dev libcmocka-dev

- name: Run CMake
- name: Run CMake (GCC)
run: |
mkdir build && cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DSCONF_BUILD_EXAMPLES=on \
-DSCONF_ENABLE_TESTS=on -DSCONF_ENABLE_ASAN=on ..
mkdir build-gcc && cd build-gcc
CC=gcc cmake -DCMAKE_BUILD_TYPE=Debug -DSCONF_BUILD_EXAMPLES=on \
-DSCONF_ENABLE_TESTS=on ..

- name: Build code
run: cmake --build build
- name: Run CMake (Clang)
run: |
mkdir build-clang && cd build-clang
CC=clang cmake -DCMAKE_BUILD_TYPE=Debug -DSCONF_BUILD_EXAMPLES=on \
-DSCONF_ENABLE_TESTS=on ..

- name: Build code (GCC)
run: cmake --build build-gcc

- name: Build code (clang)
run: cmake --build build-clang

- name: Run tests (GCC)
run: cmake --build build-gcc --target test

- name: Run tests
run: cmake --build build --target test
- name: Run tests (clang)
run: cmake --build build-clang --target test
3 changes: 1 addition & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ cmake_minimum_required(VERSION 3.1)

project(
simpleconfig
DESCRIPTION "A simpler approach to configuration handling in projects"
VERSION 1.0.1
LANGUAGES C
)

set(CMAKE_C_STANDARD 17)
set(CMAKE_C_STANDARD 11)

list(APPEND CMAKE_MODULE_PATH "${simpleconfig_SOURCE_DIR}/cmake")

Expand Down
6 changes: 3 additions & 3 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ set(simpleconfig_source
yaml.c
)

set(simpleconfig_compile_options -Wall -Wextra -Wno-missing-field-initializers -Wno-missing-braces)

if(CMAKE_BUILD_TYPE STREQUAL "Debug")
set(simpleconfig_compile_options -Wall -Wextra -Werror)
else()
set(simpleconfig_compile_options -Wall -Wextra)
set(simpleconfig_compile_options ${simpleconfig_compile_options} -Werror)
endif()

find_package(yaml REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ set(SCONF_TESTS

foreach(X IN LISTS SCONF_TESTS)
add_executable(${X} ${X}.c)
target_compile_options(${X} PRIVATE -Wall)
target_compile_options(${X} PRIVATE -Wall -Wno-missing-field-initializers -Wno-missing-braces)
target_link_libraries(${X} sconf ${CMOCKA_LIB})
add_test(NAME ${X} COMMAND ${CMAKE_CURRENT_BINARY_DIR}/${X}
WORKING_DIRECTORY ${simpleconfig_SOURCE_DIR}/tests
Expand Down
54 changes: 54 additions & 0 deletions tests/sconf_tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* Older versions of cmocka does not have this function defined, so
lets define it so we can run some tests on older OS releases! */
#ifndef assert_float_equal
#include <float.h>

#include <cmocka.h>

/* Function copied from cmocka 1.1.7
(https://gitlab.com/cmocka/cmocka/-/blob/cmocka-1.1.7/src/cmocka.c#L1120) */
/* Returns 1 if the specified float values are equal, else returns 0. */
static int float_compare(const float left,
const float right,
const float epsilon) {
float absLeft;
float absRight;
float largest;
float relDiff;

float diff = left - right;
diff = (diff >= 0.f) ? diff : -diff;

// Check if the numbers are really close -- needed
// when comparing numbers near zero.
if (diff <= epsilon) {
return 1;
}

absLeft = (left >= 0.f) ? left : -left;
absRight = (right >= 0.f) ? right : -right;

largest = (absRight > absLeft) ? absRight : absLeft;
relDiff = largest * FLT_EPSILON;

if (diff > relDiff) {
return 0;
}
return 1;
}

void _assert_float_equal(const float a, const float b, const float epsilon)
{
const int equal = float_compare(a, b, epsilon);
if (!equal) {
fail_msg("%f != %f\n", a, b);
}
}

#define assert_float_equal(a, b, epsilon) \
_assert_float_equal((float)a, \
(float)b, \
(float)epsilon)

#endif /* assert_float_equal */

1 change: 1 addition & 0 deletions tests/test_sconf_defaults.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cmocka.h>

#include "sconf_tests.h"
#include "sconf.h"

static struct SConfMap default_map[] = {
Expand Down
1 change: 1 addition & 0 deletions tests/test_sconf_env_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <cmocka.h>

#include "sconf_tests.h"
#include "sconf.h"

static void test_sconf_env_read_string(void **unused)
Expand Down
1 change: 1 addition & 0 deletions tests/test_sconf_opts_parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cmocka.h>

#include "sconf_tests.h"
#include "sconf.h"

void my_usage_callback(const char *usage, void *user)
Expand Down
1 change: 1 addition & 0 deletions tests/test_sconf_set_and_get_float.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cmocka.h>

#include "sconf_tests.h"
#include "sconf.h"

static void test_sconf_set_and_get_float(void **unused)
Expand Down
1 change: 1 addition & 0 deletions tests/test_sconf_yaml_read.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#include <cmocka.h>

#include "sconf_tests.h"
#include "sconf.h"

static void test_valid_yaml_string(void **unused)
Expand Down