mirror of
https://github.com/portapack-mayhem/mayhem-firmware.git
synced 2025-08-13 14:43:18 +00:00
Move tests, add applicaiton tests. (#1031)
Co-authored-by: kallanreed <kallanreed@outlook.com>
This commit is contained in:
30
firmware/test/CMakeLists.txt
Normal file
30
firmware/test/CMakeLists.txt
Normal file
@@ -0,0 +1,30 @@
|
||||
# Copyright (C) 2023 Bernd Herzog, Kyle Reed
|
||||
#
|
||||
# This file is part of PortaPack.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
project(tests)
|
||||
|
||||
set(DOCTESTINC ${PROJECT_SOURCE_DIR}/include)
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(application)
|
||||
add_subdirectory(baseband)
|
||||
|
||||
add_custom_target(build_tests)
|
||||
add_dependencies(build_tests application_test baseband_test)
|
70
firmware/test/application/CMakeLists.txt
Normal file
70
firmware/test/application/CMakeLists.txt
Normal file
@@ -0,0 +1,70 @@
|
||||
# Copyright (C) 2023 Bernd Herzog, Kyle Reed
|
||||
#
|
||||
# This file is part of PortaPack.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
project(application_test)
|
||||
|
||||
enable_language(C CXX ASM)
|
||||
|
||||
include(${CHIBIOS_PORTAPACK}/boards/PORTAPACK_APPLICATION/board.cmake)
|
||||
include(${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx_M0/platform.cmake)
|
||||
include(${CHIBIOS}/os/hal/hal.cmake)
|
||||
include(${CHIBIOS_PORTAPACK}/os/ports/GCC/ARMCMx/LPC43xx_M0/port.cmake)
|
||||
include(${CHIBIOS}/os/kernel/kernel.cmake)
|
||||
include(${CHIBIOS_PORTAPACK}/os/various/fatfs_bindings/fatfs.cmake)
|
||||
include(${CHIBIOS}/test/test.cmake)
|
||||
|
||||
set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
add_executable(application_test EXCLUDE_FROM_ALL
|
||||
${PROJECT_SOURCE_DIR}/main.cpp
|
||||
${PROJECT_SOURCE_DIR}/test_basics.cpp
|
||||
${PROJECT_SOURCE_DIR}/test_optional.cpp
|
||||
)
|
||||
|
||||
target_include_directories(application_test PRIVATE
|
||||
${DOCTESTINC}
|
||||
${COMMON}
|
||||
${PORTINC}
|
||||
${KERNINC}
|
||||
${TESTINC}
|
||||
${HALINC}
|
||||
${PLATFORMINC}
|
||||
${BOARDINC}
|
||||
${CHIBIOS}/os/various
|
||||
${BASEBAND}
|
||||
)
|
||||
|
||||
target_compile_options(application_test PRIVATE
|
||||
-DLPC43XX
|
||||
-DLPC43XX_M0
|
||||
-D__NEWLIB__
|
||||
-DHACKRF_ONE
|
||||
-DTOOLCHAIN_GCC
|
||||
-DTOOLCHAIN_GCC_ARM
|
||||
-D_RANDOM_TCC=0
|
||||
-DVERSION_STRING=\"${VERSION}\"
|
||||
${USE_CPPOPT}
|
||||
${USE_OPT}
|
||||
${CPPWARN}
|
||||
)
|
||||
|
||||
add_test(NAME application_test
|
||||
COMMAND application_test
|
||||
)
|
23
firmware/test/application/main.cpp
Normal file
23
firmware/test/application/main.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
27
firmware/test/application/test_basics.cpp
Normal file
27
firmware/test/application/test_basics.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright (C) 2023
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "doctest.h"
|
||||
|
||||
TEST_CASE("Testing test framework") {
|
||||
REQUIRE(1 == 1);
|
||||
REQUIRE_FALSE(1 == 2);
|
||||
}
|
42
firmware/test/application/test_optional.cpp
Normal file
42
firmware/test/application/test_optional.cpp
Normal file
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) 2023
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "doctest.h"
|
||||
#include "optional.hpp"
|
||||
|
||||
TEST_SUITE_BEGIN("optional");
|
||||
|
||||
TEST_CASE("Default instance should not be valid.") {
|
||||
Optional<int> o;
|
||||
REQUIRE_FALSE(o.is_valid());
|
||||
}
|
||||
|
||||
TEST_CASE("Instance with value should be valid.") {
|
||||
Optional<int> o{1};
|
||||
REQUIRE(o.is_valid());
|
||||
}
|
||||
|
||||
TEST_CASE("value() should return value.") {
|
||||
Optional<int> o{1};
|
||||
REQUIRE(o.value() == 1);
|
||||
}
|
||||
|
||||
TEST_SUITE_END();
|
66
firmware/test/baseband/CMakeLists.txt
Normal file
66
firmware/test/baseband/CMakeLists.txt
Normal file
@@ -0,0 +1,66 @@
|
||||
# Copyright (C) 2023 Bernd Herzog, Kyle Reed
|
||||
#
|
||||
# This file is part of PortaPack.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; see the file COPYING. If not, write to
|
||||
# the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
# Boston, MA 02110-1301, USA.
|
||||
#
|
||||
|
||||
project(baseband_test)
|
||||
|
||||
enable_language(C CXX ASM)
|
||||
|
||||
include(${CHIBIOS_PORTAPACK}/boards/PORTAPACK_BASEBAND/board.cmake)
|
||||
include(${CHIBIOS_PORTAPACK}/os/hal/platforms/LPC43xx_M4/platform.cmake)
|
||||
include(${CHIBIOS}/os/hal/hal.cmake)
|
||||
include(${CHIBIOS_PORTAPACK}/os/ports/GCC/ARMCMx/LPC43xx_M4/port.cmake)
|
||||
include(${CHIBIOS}/os/kernel/kernel.cmake)
|
||||
include(${CHIBIOS}/test/test.cmake)
|
||||
|
||||
set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
add_executable(baseband_test EXCLUDE_FROM_ALL
|
||||
${PROJECT_SOURCE_DIR}/main.cpp
|
||||
${PROJECT_SOURCE_DIR}/dsp_fft_test.cpp
|
||||
${COMMON}/dsp_fft.cpp
|
||||
)
|
||||
|
||||
target_include_directories(baseband_test PRIVATE
|
||||
${DOCTESTINC}
|
||||
${COMMON}
|
||||
${PORTINC}
|
||||
${KERNINC}
|
||||
${TESTINC}
|
||||
${HALINC}
|
||||
${PLATFORMINC}
|
||||
${BOARDINC}
|
||||
${CHIBIOS}/os/various
|
||||
${BASEBAND}
|
||||
)
|
||||
|
||||
target_compile_options(baseband_test PRIVATE
|
||||
-DLPC43XX
|
||||
-DLPC43XX_M4
|
||||
-D__NEWLIB__
|
||||
-DHACKRF_ONE
|
||||
-DTOOLCHAIN_GCC
|
||||
-DTOOLCHAIN_GCC_ARM
|
||||
-D_RANDOM_TCC=0
|
||||
-DVERSION_STRING=\"${VERSION}\"
|
||||
)
|
||||
|
||||
add_test(NAME baseband_test
|
||||
COMMAND baseband_test
|
||||
)
|
87
firmware/test/baseband/dsp_fft_test.cpp
Normal file
87
firmware/test/baseband/dsp_fft_test.cpp
Normal file
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#include "dsp_fft.hpp"
|
||||
#include "doctest.h"
|
||||
|
||||
TEST_CASE("ifft successfully calculates dc on zero frequency") {
|
||||
uint32_t fft_width = 8;
|
||||
complex16_t* v = new complex16_t[fft_width];
|
||||
complex16_t* tmp = new complex16_t[fft_width];
|
||||
|
||||
v[0] = {1024, 0}; // DC bin
|
||||
v[1] = {0, 0};
|
||||
v[2] = {0, 0};
|
||||
v[3] = {0, 0};
|
||||
v[4] = {0, 0};
|
||||
v[5] = {0, 0};
|
||||
v[6] = {0, 0};
|
||||
v[7] = {0, 0};
|
||||
|
||||
ifft<complex16_t>(v, fft_width, tmp);
|
||||
|
||||
CHECK(v[0].real() == 1024);
|
||||
CHECK(v[1].real() == 1024);
|
||||
CHECK(v[2].real() == 1024);
|
||||
CHECK(v[3].real() == 1024);
|
||||
CHECK(v[4].real() == 1024);
|
||||
CHECK(v[5].real() == 1024);
|
||||
CHECK(v[6].real() == 1024);
|
||||
CHECK(v[7].real() == 1024);
|
||||
|
||||
for (uint32_t i = 0; i < fft_width; i++)
|
||||
CHECK(v[i].imag() == 0);
|
||||
|
||||
free(v);
|
||||
free(tmp);
|
||||
}
|
||||
|
||||
TEST_CASE("ifft successfully calculates pure sine of half the sample rate") {
|
||||
uint32_t fft_width = 8;
|
||||
complex16_t* v = new complex16_t[fft_width];
|
||||
complex16_t* tmp = new complex16_t[fft_width];
|
||||
|
||||
v[0] = {0, 0};
|
||||
v[1] = {0, 0};
|
||||
v[2] = {0, 0};
|
||||
v[3] = {0, 0};
|
||||
v[4] = {1024, 0}; // sample rate /2 bin
|
||||
v[5] = {0, 0};
|
||||
v[6] = {0, 0};
|
||||
v[7] = {0, 0};
|
||||
|
||||
ifft<complex16_t>(v, fft_width, tmp);
|
||||
|
||||
CHECK(v[0].real() == 1024);
|
||||
CHECK(v[1].real() == -1024);
|
||||
CHECK(v[2].real() == 1024);
|
||||
CHECK(v[3].real() == -1024);
|
||||
CHECK(v[4].real() == 1024);
|
||||
CHECK(v[5].real() == -1024);
|
||||
CHECK(v[6].real() == 1024);
|
||||
CHECK(v[7].real() == -1024);
|
||||
|
||||
for (uint32_t i = 0; i < fft_width; i++)
|
||||
CHECK(v[i].imag() == 0);
|
||||
|
||||
free(v);
|
||||
free(tmp);
|
||||
}
|
23
firmware/test/baseband/main.cpp
Normal file
23
firmware/test/baseband/main.cpp
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Bernd Herzog
|
||||
*
|
||||
* This file is part of PortaPack.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2, or (at your option)
|
||||
* any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; see the file COPYING. If not, write to
|
||||
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||
* Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN
|
||||
#include "doctest.h"
|
7223
firmware/test/include/doctest.h
Normal file
7223
firmware/test/include/doctest.h
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user