mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
added first unit test (#1027)
* added first unit test * improved unit test names
This commit is contained in:
parent
cac3a7cf1e
commit
34d46a9d5d
@ -18,7 +18,7 @@
|
|||||||
# Boston, MA 02110-1301, USA.
|
# Boston, MA 02110-1301, USA.
|
||||||
#
|
#
|
||||||
|
|
||||||
cmake_minimum_required(VERSION 2.8.9)
|
cmake_minimum_required(VERSION 3.0)
|
||||||
cmake_policy(SET CMP0005 NEW)
|
cmake_policy(SET CMP0005 NEW)
|
||||||
|
|
||||||
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/firmware/toolchain-arm-cortex-m.cmake)
|
set(CMAKE_TOOLCHAIN_FILE ${CMAKE_CURRENT_LIST_DIR}/firmware/toolchain-arm-cortex-m.cmake)
|
||||||
@ -58,4 +58,5 @@ set(HACKRF_CPLD_XSVF_PATH ${HACKRF_PATH}/firmware/cpld/sgpio_if/${HACKRF_CPLD_XS
|
|||||||
set(HACKRF_FIRMWARE_DFU_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_DFU_FILENAME})
|
set(HACKRF_FIRMWARE_DFU_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_DFU_FILENAME})
|
||||||
set(HACKRF_FIRMWARE_BIN_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_BIN_FILENAME})
|
set(HACKRF_FIRMWARE_BIN_IMAGE ${hackrf_usb_BINARY_DIR}/${HACKRF_FIRMWARE_BIN_FILENAME})
|
||||||
|
|
||||||
|
enable_testing()
|
||||||
add_subdirectory(firmware)
|
add_subdirectory(firmware)
|
||||||
|
@ -35,6 +35,7 @@ set(FIRMWARE_FILENAME ${FIRMWARE_NAME}.bin)
|
|||||||
|
|
||||||
add_subdirectory(application)
|
add_subdirectory(application)
|
||||||
add_subdirectory(baseband)
|
add_subdirectory(baseband)
|
||||||
|
add_subdirectory(baseband-test)
|
||||||
|
|
||||||
# NOTE: Dependencies break if the .bin files aren't included in DEPENDS. WTF, CMake?
|
# NOTE: Dependencies break if the .bin files aren't included in DEPENDS. WTF, CMake?
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
|
64
firmware/baseband-test/CMakeLists.txt
Normal file
64
firmware/baseband-test/CMakeLists.txt
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
# 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.
|
||||||
|
#
|
||||||
|
|
||||||
|
enable_language(C CXX ASM)
|
||||||
|
|
||||||
|
project(baseband_test)
|
||||||
|
|
||||||
|
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(TEST_FILENAME testrunner)
|
||||||
|
set(HOST_TOOLCHAIN g++)
|
||||||
|
set(DDEFS -DLPC43XX -DLPC43XX_M4 -D__NEWLIB__ -DHACKRF_ONE -DTOOLCHAIN_GCC -DTOOLCHAIN_GCC_ARM -D_RANDOM_TCC=0 -D'VERSION_STRING=\"${VERSION}\"')
|
||||||
|
|
||||||
|
set(CPP_FILES
|
||||||
|
${PROJECT_SOURCE_DIR}/main.cpp
|
||||||
|
${PROJECT_SOURCE_DIR}/dsp_fft_test.cpp
|
||||||
|
${COMMON}/dsp_fft.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(CPP_INCLUDES
|
||||||
|
${PROJECT_SOURCE_DIR}/include
|
||||||
|
${COMMON}
|
||||||
|
${PORTINC}
|
||||||
|
${KERNINC}
|
||||||
|
${TESTINC}
|
||||||
|
${HALINC}
|
||||||
|
${PLATFORMINC}
|
||||||
|
${BOARDINC}
|
||||||
|
${CHIBIOS}/os/various
|
||||||
|
${BASEBAND}
|
||||||
|
)
|
||||||
|
|
||||||
|
add_custom_target(
|
||||||
|
baseband_test ALL
|
||||||
|
COMMAND echo ${CPP_INCLUDES} | sed "s/[^[:space:]]*/-I \\\\0/g" > include_files
|
||||||
|
COMMAND ${HOST_TOOLCHAIN} ${DDEFS} -o ${TEST_FILENAME} -g ${CPP_FILES} `cat include_files`
|
||||||
|
)
|
||||||
|
|
||||||
|
add_test(NAME /home/j39f3fs/dev/portapack-mayhem
|
||||||
|
COMMAND ${TEST_FILENAME}
|
||||||
|
)
|
87
firmware/baseband-test/dsp_fft_test.cpp
Normal file
87
firmware/baseband-test/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);
|
||||||
|
}
|
7106
firmware/baseband-test/include/doctest.h
Normal file
7106
firmware/baseband-test/include/doctest.h
Normal file
File diff suppressed because it is too large
Load Diff
23
firmware/baseband-test/main.cpp
Normal file
23
firmware/baseband-test/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"
|
Loading…
Reference in New Issue
Block a user