Skip to content

Commit

Permalink
Merge pull request #64 from antoniovazquezblanco/dev/tests
Browse files Browse the repository at this point in the history
Add a sample testing structure
  • Loading branch information
BatchDrake committed Jun 18, 2023
2 parents d610516 + dcd70ae commit a100653
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 11 deletions.
7 changes: 0 additions & 7 deletions .github/actions/package/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ runs:
name: linux-deb.zip
path: build/dist/*.deb

- name: Upload RPM artifact
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
with:
name: linux-rpm.zip
path: build/dist/*.rpm

- name: Upload TGZ artifact
if: runner.os == 'Linux'
uses: actions/upload-artifact@v3
Expand Down
14 changes: 14 additions & 0 deletions .github/actions/test/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Test
description: 'Test a CMake project with CTest support'

inputs:
shell:
required: false
default: bash

runs:
using: "composite"
steps:
- name: Test
shell: ${{inputs.shell}}
run: ctest --test-dir build -VV --rerun-failed --output-on-failure
3 changes: 3 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ sigutils:

documentation:
- doc/**/*

tests:
- tests/**/*
33 changes: 30 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Install dependencies
run: sudo apt-get install libsndfile1-dev libvolk2-dev libfftw3-dev
run: sudo apt-get install libsndfile1-dev libvolk2-dev libfftw3-dev catch2

- name: Checkout
uses: actions/checkout@v3
Expand All @@ -21,6 +21,14 @@ jobs:
target: sigutils
cmake_configuration_parameters: -DCMAKE_INSTALL_PREFIX=/usr

- name: Build tests
uses: "./.github/actions/build"
with:
target: sigutils_test

- name: Test
uses: "./.github/actions/test"

- name: Package
uses: "./.github/actions/package"
with:
Expand All @@ -30,7 +38,7 @@ jobs:
runs-on: macos-latest
steps:
- name: Install dependencies
run: brew install libsndfile volk fftw
run: brew install libsndfile volk fftw catch2

- name: Checkout
uses: actions/checkout@v3
Expand All @@ -43,6 +51,14 @@ jobs:
with:
target: sigutils

- name: Build tests
uses: "./.github/actions/build"
with:
target: sigutils_test

- name: Test
uses: "./.github/actions/test"

- name: Package
uses: "./.github/actions/package"
with:
Expand All @@ -59,7 +75,7 @@ jobs:
with:
msystem: MINGW64
update: true
install: git mingw-w64-x86_64-cc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-libsndfile mingw-w64-x86_64-fftw mingw-w64-x86_64-volk
install: git mingw-w64-x86_64-gcc mingw-w64-x86_64-make mingw-w64-x86_64-cmake mingw-w64-x86_64-libsndfile mingw-w64-x86_64-fftw mingw-w64-x86_64-volk mingw-w64-x86_64-catch

- name: Checkout
uses: actions/checkout@v3
Expand All @@ -73,6 +89,17 @@ jobs:
shell: msys2 {0}
target: sigutils

- name: Build tests
uses: "./.github/actions/build"
with:
shell: msys2 {0}
target: sigutils_test

- name: Test
uses: "./.github/actions/test"
with:
shell: msys2 {0}

- name: Package
uses: "./.github/actions/package"
with:
Expand Down
10 changes: 9 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,18 @@ project(
VERSION ${SIGUTILS_VERSION}
DESCRIPTION "Small signal processing utility library"
HOMEPAGE_URL "http://github.org/BatchDrake/sigutils"
LANGUAGES C)
LANGUAGES C CXX)

# Always use top level dir for generated targets to avoid linker problems
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

# The library code is in src
add_subdirectory(src)

# The documentation is in doc
add_subdirectory(doc)

# Tests are in the tests dir
include(CTest)
add_subdirectory(tests)
24 changes: 24 additions & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
find_package(Catch2)

if(Catch2_FOUND)
# General options
file(GLOB_RECURSE TEST_SRCS LIST_DIRECTORIES false *.cpp)
add_executable(sigutils_test ${TEST_SRCS})
target_include_directories(sigutils_test PUBLIC $<TARGET_PROPERTY:sigutils,INCLUDE_DIRECTORIES>)
target_compile_definitions(sigutils_test PUBLIC $<TARGET_PROPERTY:sigutils,COMPILE_DEFINITIONS>)
target_link_libraries(sigutils_test $<TARGET_LINKER_FILE:sigutils>)
include(Catch)
catch_discover_tests(sigutils_test)

if(Catch2_VERSION_MAJOR EQUAL 2)
target_compile_definitions(sigutils_test PUBLIC CATCH2_V2)
target_link_libraries(sigutils_test Catch2::Catch2)
elseif(Catch2_VERSION_MAJOR EQUAL 3)
target_compile_definitions(sigutils_test PUBLIC CATCH2_V3)
target_link_libraries(sigutils_test Catch2::Catch2WithMain)
else()
message("Unsuported Catch2 version")
endif()
else()
message("Catch2 needs to be installed to perform unit testing")
endif()
21 changes: 21 additions & 0 deletions tests/catch.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* Copyright (C) 2023 Antonio Vázquez Blanco <antoniovazquezblanco@gmail.com>
* SPDX-License-Identifier: GPL-3.0-only
*/

#ifndef _CATCH_TEST_H
#define _CATCH_TEST_H

#ifdef CATCH2_V2
#define CATCH_CONFIG_MAIN
#include <catch2/catch.hpp>
#endif

#ifdef CATCH2_V3
#include <catch2/catch_all.hpp>
#endif

#if !defined(CATCH2_V2) && !defined(CATCH2_V3)
#error "No Catch2 version specified!"
#endif

#endif
17 changes: 17 additions & 0 deletions tests/test_ncqo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Copyright (C) 2023 Antonio Vázquez Blanco <antoniovazquezblanco@gmail.com>
* SPDX-License-Identifier: GPL-3.0-only
*/

#include "catch.hpp"

#include <sigutils/ncqo.h>

TEST_CASE("Test normalized frecuency scale", "[NCQO]")
{
su_ncqo_t ncqo;
su_ncqo_init(&ncqo, 1.0);
REQUIRE(SUFLOAT_EQUAL(su_ncqo_read_i(&ncqo), 1.0));
REQUIRE(SUFLOAT_EQUAL(su_ncqo_read_i(&ncqo), -1.0));
REQUIRE(SUFLOAT_EQUAL(su_ncqo_read_i(&ncqo), 1.0));
REQUIRE(SUFLOAT_EQUAL(su_ncqo_read_i(&ncqo), -1.0));
}

0 comments on commit a100653

Please sign in to comment.