mirror of
https://github.com/OpenRTX/OpenRTX
synced 2026-08-08 12:29:06 -04:00
test: format all unit tests
Signed-off-by: Ryan Turner <ryan@turnrye.com
This commit is contained in:
parent
778e5b6d4b
commit
b0493aedae
12 changed files with 237 additions and 241 deletions
|
|
@ -86,7 +86,18 @@ platform/targets/linux/emulator/sdl_engine.h
|
|||
platform/targets/ttwrplus/pmu.h
|
||||
tests/platform/mic_test.c
|
||||
tests/platform/codec2_encode_test.c
|
||||
tests/unit/convert_minmea_coord.c
|
||||
tests/unit/cps.c
|
||||
tests/unit/dummy.c
|
||||
tests/unit/linux_inputStream_test.cpp
|
||||
tests/unit/M17_callsign.cpp
|
||||
tests/unit/M17_demodulator.cpp
|
||||
tests/unit/M17_golay.cpp
|
||||
tests/unit/M17_rrc.cpp
|
||||
tests/unit/M17_viterbi.cpp
|
||||
tests/unit/play_sine.c
|
||||
tests/unit/ui_check_standby.c
|
||||
tests/unit/voice_prompts.c
|
||||
EOF
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ using namespace std;
|
|||
int main()
|
||||
{
|
||||
// Open file
|
||||
FILE *baseband_file = fopen("../tests/unit/assets/M17_test_baseband_dc.raw", "rb");
|
||||
FILE *baseband_file = fopen("../tests/unit/assets/M17_test_baseband_dc.raw",
|
||||
"rb");
|
||||
FILE *baseband_out = fopen("M17_test_baseband_rrc.raw", "wb");
|
||||
if (!baseband_file)
|
||||
{
|
||||
if (!baseband_file) {
|
||||
perror("Error in reading test baseband");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -41,26 +41,24 @@ int main()
|
|||
printf("Baseband is %ld bytes!\n", baseband_size);
|
||||
|
||||
// Read data from input file
|
||||
int16_t *baseband_buffer = (int16_t *) malloc(baseband_size);
|
||||
if (!baseband_buffer)
|
||||
{
|
||||
int16_t *baseband_buffer = (int16_t *)malloc(baseband_size);
|
||||
if (!baseband_buffer) {
|
||||
perror("Error in memory allocation");
|
||||
return -1;
|
||||
}
|
||||
size_t read_items = fread(baseband_buffer, 2, baseband_samples, baseband_file);
|
||||
if (read_items != baseband_samples)
|
||||
{
|
||||
size_t read_items = fread(baseband_buffer, 2, baseband_samples,
|
||||
baseband_file);
|
||||
if (read_items != baseband_samples) {
|
||||
perror("Error in reading input file");
|
||||
return -1;
|
||||
}
|
||||
fclose(baseband_file);
|
||||
|
||||
// Apply RRC on the baseband buffer
|
||||
int16_t *filtered_buffer = (int16_t *) malloc(baseband_size);
|
||||
for(size_t i = 0; i < baseband_samples; i++)
|
||||
{
|
||||
float elem = static_cast< float >(baseband_buffer[i]);
|
||||
filtered_buffer[i] = static_cast< int16_t >(M17::rrc(elem));
|
||||
int16_t *filtered_buffer = (int16_t *)malloc(baseband_size);
|
||||
for (size_t i = 0; i < baseband_samples; i++) {
|
||||
float elem = static_cast<float>(baseband_buffer[i]);
|
||||
filtered_buffer[i] = static_cast<int16_t>(M17::rrc(elem));
|
||||
}
|
||||
fwrite(filtered_buffer, baseband_samples, 2, baseband_out);
|
||||
fclose(baseband_out);
|
||||
|
|
@ -74,51 +72,50 @@ int main()
|
|||
m17Demodulator.baseband = baseband;
|
||||
|
||||
FILE *output_csv_1 = fopen("M17_demodulator_output_1.csv", "w");
|
||||
fprintf(output_csv_1, "Input,RRCSignal,LSFConvolution,FrameConvolution,Stddev\n");
|
||||
fprintf(output_csv_1,
|
||||
"Input,RRCSignal,LSFConvolution,FrameConvolution,Stddev\n");
|
||||
// Test convolution
|
||||
m17Demodulator.resetCorrelationStats();
|
||||
for(unsigned i = 0; i < baseband_samples - m17Demodulator.M17_SYNCWORD_SYMBOLS * m17Demodulator.M17_SAMPLES_PER_SYMBOL; i++)
|
||||
{
|
||||
for (unsigned i = 0; i < baseband_samples
|
||||
- m17Demodulator.M17_SYNCWORD_SYMBOLS
|
||||
* m17Demodulator.M17_SAMPLES_PER_SYMBOL;
|
||||
i++) {
|
||||
int32_t lsf_conv =
|
||||
m17Demodulator.convolution(i,
|
||||
m17Demodulator.lsf_syncword,
|
||||
m17Demodulator.convolution(i, m17Demodulator.lsf_syncword,
|
||||
m17Demodulator.M17_SYNCWORD_SYMBOLS);
|
||||
int32_t stream_conv =
|
||||
m17Demodulator.convolution(i,
|
||||
m17Demodulator.stream_syncword,
|
||||
m17Demodulator.convolution(i, m17Demodulator.stream_syncword,
|
||||
m17Demodulator.M17_SYNCWORD_SYMBOLS);
|
||||
m17Demodulator.updateCorrelationStats(stream_conv);
|
||||
fprintf(output_csv_1, "%" PRId16 ",%" PRId16 ",%d,%d,%f\n",
|
||||
baseband_buffer[i],
|
||||
baseband.data[i],
|
||||
lsf_conv + (int32_t) m17Demodulator.getCorrelationEma(),
|
||||
stream_conv - (int32_t) m17Demodulator.getCorrelationEma(),
|
||||
m17Demodulator.conv_threshold_factor *
|
||||
m17Demodulator.getCorrelationStddev());
|
||||
baseband_buffer[i], baseband.data[i],
|
||||
lsf_conv + (int32_t)m17Demodulator.getCorrelationEma(),
|
||||
stream_conv - (int32_t)m17Demodulator.getCorrelationEma(),
|
||||
m17Demodulator.conv_threshold_factor
|
||||
* m17Demodulator.getCorrelationStddev());
|
||||
}
|
||||
fclose(output_csv_1);
|
||||
|
||||
// Test syncword detection
|
||||
printf("Testing syncword detection!\n");
|
||||
FILE *syncword_ref = fopen("../tests/unit/assets/M17_test_baseband_dc_syncwords.txt", "r");
|
||||
FILE *syncword_ref =
|
||||
fopen("../tests/unit/assets/M17_test_baseband_dc_syncwords.txt", "r");
|
||||
int32_t offset = 0;
|
||||
M17::sync_t syncword = { -1, false };
|
||||
m17Demodulator.resetCorrelationStats();
|
||||
int i = 0;
|
||||
do
|
||||
{
|
||||
do {
|
||||
int expected_syncword = 0;
|
||||
fscanf(syncword_ref, "%d\n", &expected_syncword);
|
||||
syncword = m17Demodulator.nextFrameSync(offset);
|
||||
offset = syncword.index + m17Demodulator.M17_SYNCWORD_SYMBOLS * m17Demodulator.M17_SAMPLES_PER_SYMBOL;
|
||||
offset = syncword.index
|
||||
+ m17Demodulator.M17_SYNCWORD_SYMBOLS
|
||||
* m17Demodulator.M17_SAMPLES_PER_SYMBOL;
|
||||
printf("%d\n", syncword.index);
|
||||
if (syncword.index != expected_syncword)
|
||||
{
|
||||
if (syncword.index != expected_syncword) {
|
||||
fprintf(stderr, "Error in syncwords detection #%d!\n", i);
|
||||
return -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
} else {
|
||||
printf("SYNC: %d...OK!\n", syncword.index);
|
||||
}
|
||||
i++;
|
||||
|
|
@ -132,66 +129,70 @@ int main()
|
|||
syncword = { -1, false };
|
||||
m17Demodulator.resetCorrelationStats();
|
||||
syncword = m17Demodulator.nextFrameSync(offset);
|
||||
for(unsigned i = 0; i < baseband_samples - m17Demodulator.M17_SYNCWORD_SYMBOLS * m17Demodulator.M17_SAMPLES_PER_SYMBOL; i++)
|
||||
{
|
||||
if ((int) i == (syncword.index + 1)) {
|
||||
for (unsigned i = 0; i < baseband_samples
|
||||
- m17Demodulator.M17_SYNCWORD_SYMBOLS
|
||||
* m17Demodulator.M17_SAMPLES_PER_SYMBOL;
|
||||
i++) {
|
||||
if ((int)i == (syncword.index + 1)) {
|
||||
if (syncword.lsf)
|
||||
detect = -4000;
|
||||
else
|
||||
detect = 4000;
|
||||
syncword = m17Demodulator.nextFrameSync(syncword.index + m17Demodulator.M17_SYNCWORD_SYMBOLS * m17Demodulator.M17_SAMPLES_PER_SYMBOL);
|
||||
} else if (((int) i % 10) == ((syncword.index + 1) % 10)) {
|
||||
syncword = m17Demodulator.nextFrameSync(
|
||||
syncword.index
|
||||
+ m17Demodulator.M17_SYNCWORD_SYMBOLS
|
||||
* m17Demodulator.M17_SAMPLES_PER_SYMBOL);
|
||||
} else if (((int)i % 10) == ((syncword.index + 1) % 10)) {
|
||||
m17Demodulator.updateQuantizationStats(i);
|
||||
symbol = m17Demodulator.quantize(i) * 1000;
|
||||
detect = 3000;
|
||||
} else
|
||||
{
|
||||
} else {
|
||||
detect = 0;
|
||||
symbol = 0;
|
||||
}
|
||||
fprintf(output_csv_2, "%" PRId16 ",%d,%f,%f,%d\n",
|
||||
m17Demodulator.baseband.data[i] - (int16_t) m17Demodulator.getQuantizationEma(),
|
||||
detect,
|
||||
m17Demodulator.getQuantizationMax() / 2,
|
||||
m17Demodulator.getQuantizationMin() / 2,
|
||||
symbol);
|
||||
m17Demodulator.baseband.data[i]
|
||||
- (int16_t)m17Demodulator.getQuantizationEma(),
|
||||
detect, m17Demodulator.getQuantizationMax() / 2,
|
||||
m17Demodulator.getQuantizationMin() / 2, symbol);
|
||||
}
|
||||
fclose(output_csv_2);
|
||||
|
||||
// TODO: Test symbol quantization
|
||||
FILE *symbols_ref = fopen("../tests/unit/assets/M17_test_baseband.bin", "rb");
|
||||
FILE *symbols_ref = fopen("../tests/unit/assets/M17_test_baseband.bin",
|
||||
"rb");
|
||||
// Skip preamble
|
||||
fseek(symbols_ref, 0x30, SEEK_SET);
|
||||
uint32_t failed_bytes = 0, total_bytes = 0;
|
||||
syncword = { -1, false };
|
||||
offset = 0;
|
||||
syncword = m17Demodulator.nextFrameSync(offset);
|
||||
std::array< uint8_t, m17Demodulator.M17_FRAME_BYTES > frame;
|
||||
std::array<uint8_t, m17Demodulator.M17_FRAME_BYTES> frame;
|
||||
// Preheat quantizer
|
||||
for(int i = 0; i < 10; i++)
|
||||
for (int i = 0; i < 10; i++)
|
||||
m17Demodulator.updateQuantizationStats(i);
|
||||
if (syncword.index != -1)
|
||||
{
|
||||
if (syncword.index != -1) {
|
||||
// Next syncword does not overlap with current syncword
|
||||
offset = syncword.index + m17Demodulator.M17_SAMPLES_PER_SYMBOL;
|
||||
// Slice the input buffer to extract a frame and quantize
|
||||
for(uint32_t j = 0;
|
||||
syncword.index + 2 + m17Demodulator.M17_SAMPLES_PER_SYMBOL * (j + i) < m17Demodulator.baseband.len;
|
||||
j+= m17Demodulator.M17_FRAME_SYMBOLS)
|
||||
{
|
||||
for(uint16_t i = 0; i < m17Demodulator.M17_FRAME_SYMBOLS; i++)
|
||||
{
|
||||
for (uint32_t j = 0;
|
||||
syncword.index + 2
|
||||
+ m17Demodulator.M17_SAMPLES_PER_SYMBOL * (j + i)
|
||||
< m17Demodulator.baseband.len;
|
||||
j += m17Demodulator.M17_FRAME_SYMBOLS) {
|
||||
for (uint16_t i = 0; i < m17Demodulator.M17_FRAME_SYMBOLS; i++) {
|
||||
// Quantize
|
||||
uint32_t symbol_index = syncword.index + 2 +
|
||||
m17Demodulator.M17_SAMPLES_PER_SYMBOL * (j + i);
|
||||
uint32_t symbol_index = syncword.index + 2
|
||||
+ m17Demodulator.M17_SAMPLES_PER_SYMBOL
|
||||
* (j + i);
|
||||
m17Demodulator.updateQuantizationStats(symbol_index);
|
||||
int8_t symbol = m17Demodulator.quantize(symbol_index);
|
||||
setSymbol<m17Demodulator.M17_FRAME_BYTES>(frame, i, symbol);
|
||||
}
|
||||
for(uint16_t i = 0; i < m17Demodulator.M17_FRAME_BYTES; i+=2) {
|
||||
for (uint16_t i = 0; i < m17Demodulator.M17_FRAME_BYTES; i += 2) {
|
||||
if (i % 16 == 0)
|
||||
printf("\n");
|
||||
printf(" %02X%02X", frame[i], frame[i+1]);
|
||||
printf(" %02X%02X", frame[i], frame[i + 1]);
|
||||
// Check with reference bitstream
|
||||
//uint8_t ref_byte = 0x00;
|
||||
//fread(&ref_byte, 1, 1, symbols_ref);
|
||||
|
|
|
|||
|
|
@ -19,11 +19,10 @@ default_random_engine rng;
|
|||
uint32_t generateErrorMask()
|
||||
{
|
||||
uint32_t errorMask = 0;
|
||||
uniform_int_distribution< uint8_t > numErrs(0, 5);
|
||||
uniform_int_distribution< uint8_t > errPos(0, 23);
|
||||
uniform_int_distribution<uint8_t> numErrs(0, 5);
|
||||
uniform_int_distribution<uint8_t> errPos(0, 23);
|
||||
|
||||
for(uint8_t i = 0; i < numErrs(rng); i++)
|
||||
{
|
||||
for (uint8_t i = 0; i < numErrs(rng); i++) {
|
||||
errorMask |= 1 << errPos(rng);
|
||||
}
|
||||
|
||||
|
|
@ -32,10 +31,9 @@ uint32_t generateErrorMask()
|
|||
|
||||
int main()
|
||||
{
|
||||
uniform_int_distribution< uint16_t > rndValue(0, 2047);
|
||||
uniform_int_distribution<uint16_t> rndValue(0, 2047);
|
||||
|
||||
for(uint32_t i = 0; i < 10000; i++)
|
||||
{
|
||||
for (uint32_t i = 0; i < 10000; i++) {
|
||||
uint16_t value = rndValue(rng);
|
||||
uint32_t cword = M17::golay24_encode(value);
|
||||
uint32_t emask = generateErrorMask();
|
||||
|
|
@ -48,24 +46,21 @@ int main()
|
|||
bool correcting_ok = false;
|
||||
|
||||
// For four or more bit errors, decode should return 0xFFFF (uncorrectable error)
|
||||
if((__builtin_popcount(emask) >= 4) && (decoded == 0xFFFF))
|
||||
{
|
||||
if ((__builtin_popcount(emask) >= 4) && (decoded == 0xFFFF)) {
|
||||
correcting_ok = true;
|
||||
}
|
||||
|
||||
// Less than four errors should be corrected.
|
||||
if(decoded == value) correcting_ok = true;
|
||||
if (decoded == value)
|
||||
correcting_ok = true;
|
||||
|
||||
int input_error_count = __builtin_popcount(emask);
|
||||
|
||||
printf("Value %04x, emask %08x errs %d -> d %s, c %s\n",
|
||||
value,
|
||||
emask,
|
||||
input_error_count,
|
||||
decoding_ok ? "OK" : "FAIL",
|
||||
printf("Value %04x, emask %08x errs %d -> d %s, c %s\n", value, emask,
|
||||
input_error_count, decoding_ok ? "OK" : "FAIL",
|
||||
correcting_ok ? "OK" : "FAIL");
|
||||
|
||||
if(input_error_count <= 4 && (!decoding_ok || !correcting_ok))
|
||||
if (input_error_count <= 4 && (!decoding_ok || !correcting_ok))
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,8 +21,7 @@ int main()
|
|||
{
|
||||
// Open file
|
||||
FILE *baseband_out = fopen("M17_rrc_impulse_response.raw", "wb");
|
||||
if (!baseband_out)
|
||||
{
|
||||
if (!baseband_out) {
|
||||
perror("Error in opening output file");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -33,10 +32,9 @@ int main()
|
|||
|
||||
// Apply RRC on impulse signal
|
||||
int16_t filtered_impulse[IMPULSE_SIZE] = { 0 };
|
||||
for(size_t i = 0; i < IMPULSE_SIZE; i++)
|
||||
{
|
||||
float elem = static_cast< float >(impulse[i]);
|
||||
filtered_impulse[i] = static_cast< int16_t >(M17::rrc_48k(0.10 * elem));
|
||||
for (size_t i = 0; i < IMPULSE_SIZE; i++) {
|
||||
float elem = static_cast<float>(impulse[i]);
|
||||
filtered_impulse[i] = static_cast<int16_t>(M17::rrc_48k(0.10 * elem));
|
||||
}
|
||||
fwrite(filtered_impulse, IMPULSE_SIZE, 1, baseband_out);
|
||||
fclose(baseband_out);
|
||||
|
|
|
|||
|
|
@ -20,28 +20,25 @@ default_random_engine rng;
|
|||
/**
|
||||
* Insert radom bit flips in input data.
|
||||
*/
|
||||
template < size_t N >
|
||||
void generateErrors(array< uint8_t, N >& data)
|
||||
template <size_t N> void generateErrors(array<uint8_t, N> &data)
|
||||
{
|
||||
uniform_int_distribution< uint8_t > numErrs(0, 4);
|
||||
uniform_int_distribution< uint8_t > errPos(0, N);
|
||||
uniform_int_distribution<uint8_t> numErrs(0, 4);
|
||||
uniform_int_distribution<uint8_t> errPos(0, N);
|
||||
|
||||
for(uint8_t i = 0; i < numErrs(rng); i++)
|
||||
{
|
||||
for (uint8_t i = 0; i < numErrs(rng); i++) {
|
||||
uint8_t pos = errPos(rng);
|
||||
bool bit = M17::getBit(data, pos);
|
||||
bool bit = M17::getBit(data, pos);
|
||||
M17::setBit(data, pos, !bit);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
uniform_int_distribution< uint8_t > rndValue(0, 255);
|
||||
uniform_int_distribution<uint8_t> rndValue(0, 255);
|
||||
|
||||
array< uint8_t, 18 > source;
|
||||
array<uint8_t, 18> source;
|
||||
|
||||
for(auto& byte : source)
|
||||
{
|
||||
for (auto &byte : source) {
|
||||
byte = rndValue(rng);
|
||||
}
|
||||
|
||||
|
|
@ -56,16 +53,14 @@ int main()
|
|||
|
||||
generateErrors(punctured);
|
||||
|
||||
array< uint8_t, 18 > result;
|
||||
array<uint8_t, 18> result;
|
||||
M17::M17HardViterbi decoder;
|
||||
decoder.decodePunctured(punctured, result, M17::DATA_PUNCTURE);
|
||||
|
||||
for(size_t i = 0; i < result.size(); i++)
|
||||
{
|
||||
if(source[i] != result[i])
|
||||
{
|
||||
for (size_t i = 0; i < result.size(); i++) {
|
||||
if (source[i] != result[i]) {
|
||||
printf("Error at pos %ld: got %02x, expected %02x\n", i, result[i],
|
||||
source[i]);
|
||||
source[i]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,17 +12,16 @@
|
|||
static void assert_conversion(struct minmea_float *f, int32_t expected)
|
||||
{
|
||||
int32_t result = minmea_tofixedpoint(f);
|
||||
if (result != expected)
|
||||
{
|
||||
printf("FAILED! result value %d - expected %d\n",
|
||||
result, expected);
|
||||
if (result != expected) {
|
||||
printf("FAILED! result value %d - expected %d\n", result, expected);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
printf("minmea coordinate conversion test\n");
|
||||
struct minmea_float test = {5333735, 1000};
|
||||
struct minmea_float test = { 5333735, 1000 };
|
||||
assert_conversion(&test, 53562250);
|
||||
test.scale = 1;
|
||||
test.value = 0;
|
||||
|
|
|
|||
119
tests/unit/cps.c
119
tests/unit/cps.c
|
|
@ -8,7 +8,8 @@
|
|||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int test_initCPS() {
|
||||
int test_initCPS()
|
||||
{
|
||||
// Initialize a new cps
|
||||
int err = cps_create("/tmp/test1.rtxc");
|
||||
if (err)
|
||||
|
|
@ -20,93 +21,107 @@ int test_initCPS() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int test_insertContact() {
|
||||
int test_insertContact()
|
||||
{
|
||||
cps_create("/tmp/test2.rtxc");
|
||||
|
||||
cps_open("/tmp/test2.rtxc");
|
||||
contact_t c1 = { "Test contact 1", 0, {{0}} };
|
||||
contact_t c2 = { "Test contact 2", 0, {{0}} };
|
||||
contact_t c3 = { "Test contact 3", 0, {{0}} };
|
||||
contact_t c4 = { "Test contact 4", 0, {{0}} };
|
||||
contact_t c1 = { "Test contact 1", 0, { { 0 } } };
|
||||
contact_t c2 = { "Test contact 2", 0, { { 0 } } };
|
||||
contact_t c3 = { "Test contact 3", 0, { { 0 } } };
|
||||
contact_t c4 = { "Test contact 4", 0, { { 0 } } };
|
||||
cps_insertContact(c1, 0);
|
||||
cps_insertContact(c2, 0);
|
||||
cps_insertContact(c3, 0);
|
||||
cps_insertContact(c4, 1);
|
||||
contact_t c = { 0 };
|
||||
cps_readContact(&c, 0);
|
||||
if(strncmp(c3.name, c.name, 32L))
|
||||
if (strncmp(c3.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_readContact(&c, 1);
|
||||
if(strncmp(c4.name, c.name, 32L))
|
||||
if (strncmp(c4.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_readContact(&c, 2);
|
||||
if(strncmp(c2.name, c.name, 32L))
|
||||
if (strncmp(c2.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_readContact(&c, 3);
|
||||
if(strncmp(c1.name, c.name, 32L))
|
||||
if (strncmp(c1.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_insertChannel() {
|
||||
int test_insertChannel()
|
||||
{
|
||||
cps_create("/tmp/test3.rtxc");
|
||||
|
||||
cps_open("/tmp/test3.rtxc");
|
||||
channel_t c1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1", "", {0}, {{0}} };
|
||||
channel_t c2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 2", "", {0}, {{0}} };
|
||||
channel_t c3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 3", "", {0}, {{0}} };
|
||||
channel_t c4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 4", "", {0}, {{0}} };
|
||||
channel_t c1 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t c2 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 2",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t c3 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 3",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t c4 = { 0, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 4",
|
||||
"", { 0 }, { { 0 } } };
|
||||
cps_insertChannel(c1, 0);
|
||||
cps_insertChannel(c2, 0);
|
||||
cps_insertChannel(c3, 0);
|
||||
cps_insertChannel(c4, 1);
|
||||
channel_t c = { 0 };
|
||||
cps_readChannel(&c, 0);
|
||||
if(strncmp(c3.name, c.name, 32L))
|
||||
if (strncmp(c3.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_readChannel(&c, 1);
|
||||
if(strncmp(c4.name, c.name, 32L))
|
||||
if (strncmp(c4.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_readChannel(&c, 2);
|
||||
if(strncmp(c2.name, c.name, 32L))
|
||||
if (strncmp(c2.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_readChannel(&c, 3);
|
||||
if(strncmp(c1.name, c.name, 32L))
|
||||
if (strncmp(c1.name, c.name, 32L))
|
||||
return -1;
|
||||
cps_close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_contactIndexFix() {
|
||||
int test_contactIndexFix()
|
||||
{
|
||||
cps_create("/tmp/test4.rtxc");
|
||||
|
||||
cps_open("/tmp/test4.rtxc");
|
||||
contact_t ct1 = { "Test contact 1", 0, {{0}} };
|
||||
contact_t ct2 = { "Test contact 2", 0, {{0}} };
|
||||
channel_t ch1 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1", "", {0}, {{0}} };
|
||||
contact_t ct1 = { "Test contact 1", 0, { { 0 } } };
|
||||
contact_t ct2 = { "Test contact 2", 0, { { 0 } } };
|
||||
channel_t ch1 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1",
|
||||
"", { 0 }, { { 0 } } };
|
||||
cps_insertContact(ct1, 0);
|
||||
cps_insertChannel(ch1, 0);
|
||||
cps_insertContact(ct2, 0);
|
||||
channel_t c = { 0 };
|
||||
cps_readChannel(&c, 0);
|
||||
if(c.m17.contact_index != 1)
|
||||
if (c.m17.contact_index != 1)
|
||||
return -1;
|
||||
cps_close();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int test_createComplexCPS() {
|
||||
int test_createComplexCPS()
|
||||
{
|
||||
cps_create("/tmp/test5.rtxc");
|
||||
|
||||
cps_open("/tmp/test5.rtxc");
|
||||
contact_t ct1 = { "Test contact 1", 0, {{0}} };
|
||||
contact_t ct2 = { "Test contact 2", 0, {{0}} };
|
||||
channel_t ch1 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1", "", {0}, {{0}} };
|
||||
channel_t ch2 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 2", "", {0}, {{0}} };
|
||||
channel_t ch3 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 3", "", {0}, {{0}} };
|
||||
channel_t ch4 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 4", "", {0}, {{0}} };
|
||||
channel_t ch5 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 5", "", {0}, {{0}} };
|
||||
contact_t ct1 = { "Test contact 1", 0, { { 0 } } };
|
||||
contact_t ct2 = { "Test contact 2", 0, { { 0 } } };
|
||||
channel_t ch1 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch2 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 2",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch3 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 3",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch4 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 4",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch5 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 5",
|
||||
"", { 0 }, { { 0 } } };
|
||||
bankHdr_t b1 = { "Test Bank 1", 0 };
|
||||
bankHdr_t b2 = { "Test Bank 2", 0 };
|
||||
cps_insertContact(ct2, 0);
|
||||
|
|
@ -127,17 +142,23 @@ int test_createComplexCPS() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int test_createOOOCPS() {
|
||||
int test_createOOOCPS()
|
||||
{
|
||||
cps_create("/tmp/test6.rtxc");
|
||||
|
||||
cps_open("/tmp/test6.rtxc");
|
||||
contact_t ct1 = { "Test contact 1", 0, {{0}} };
|
||||
contact_t ct2 = { "Test contact 2", 0, {{0}} };
|
||||
channel_t ch1 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1", "", {0}, {{0}} };
|
||||
channel_t ch2 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 2", "", {0}, {{0}} };
|
||||
channel_t ch3 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 3", "", {0}, {{0}} };
|
||||
channel_t ch4 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 4", "", {0}, {{0}} };
|
||||
channel_t ch5 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 5", "", {0}, {{0}} };
|
||||
contact_t ct1 = { "Test contact 1", 0, { { 0 } } };
|
||||
contact_t ct2 = { "Test contact 2", 0, { { 0 } } };
|
||||
channel_t ch1 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 1",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch2 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 2",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch3 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 3",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch4 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 4",
|
||||
"", { 0 }, { { 0 } } };
|
||||
channel_t ch5 = { 2, 0, 0, 0, 0, 0, 0, 0, 0, "Test channel 5",
|
||||
"", { 0 }, { { 0 } } };
|
||||
bankHdr_t b1 = { "Test Bank 1", 0 };
|
||||
bankHdr_t b2 = { "Test Bank 2", 0 };
|
||||
cps_insertContact(ct1, 0);
|
||||
|
|
@ -158,19 +179,17 @@ int test_createOOOCPS() {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int main() {
|
||||
if (test_initCPS())
|
||||
{
|
||||
int main()
|
||||
{
|
||||
if (test_initCPS()) {
|
||||
printf("Error in codeplug initialization and read back!\n");
|
||||
return -1;
|
||||
}
|
||||
if (test_insertContact())
|
||||
{
|
||||
if (test_insertContact()) {
|
||||
printf("Error in contact insertion!\n");
|
||||
return -1;
|
||||
}
|
||||
if (test_insertChannel())
|
||||
{
|
||||
if (test_insertChannel()) {
|
||||
printf("Error in channel insertion!\n");
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -179,13 +198,11 @@ int main() {
|
|||
// printf("Error in contact index fix!\n");
|
||||
// return -1;
|
||||
// }
|
||||
if (test_createComplexCPS())
|
||||
{
|
||||
if (test_createComplexCPS()) {
|
||||
printf("Error in creation of complex CPS!\n");
|
||||
return -1;
|
||||
}
|
||||
if (test_createOOOCPS())
|
||||
{
|
||||
if (test_createOOOCPS()) {
|
||||
printf("Error in creation of Out-Of-Order CPS!\n");
|
||||
return -1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,8 @@
|
|||
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
if (1) {
|
||||
printf("PASS!\n");
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -14,13 +14,11 @@
|
|||
|
||||
#include "core/audio_stream.h"
|
||||
|
||||
static const char* files[] = {"MIC.raw", "RTX.raw", "MCU.raw"};
|
||||
static const char *files[] = { "MIC.raw", "RTX.raw", "MCU.raw" };
|
||||
|
||||
#define CHECK(x) \
|
||||
do \
|
||||
{ \
|
||||
if (!(x)) \
|
||||
{ \
|
||||
do { \
|
||||
if (!(x)) { \
|
||||
puts("Failed assertion: " #x "\n"); \
|
||||
abort(); \
|
||||
} \
|
||||
|
|
@ -28,13 +26,11 @@ static const char* files[] = {"MIC.raw", "RTX.raw", "MCU.raw"};
|
|||
|
||||
void test_linear()
|
||||
{
|
||||
for (int fn = 0; fn < 3; fn++)
|
||||
{
|
||||
for (int fn = 0; fn < 3; fn++) {
|
||||
// Write a mock audio file
|
||||
FILE* fp = fopen(files[fn], "wb");
|
||||
FILE *fp = fopen(files[fn], "wb");
|
||||
CHECK(fp);
|
||||
for (int i = 0; i < 13; i++)
|
||||
{
|
||||
for (int i = 0; i < 13; i++) {
|
||||
CHECK(fputc(i, fp) == i);
|
||||
CHECK(fputc(0, fp) == 0);
|
||||
}
|
||||
|
|
@ -42,26 +38,30 @@ void test_linear()
|
|||
|
||||
// Start inputStream using that file as source
|
||||
stream_sample_t tmp[128];
|
||||
auto id = inputStream_start(
|
||||
static_cast<AudioSource>(fn), AudioPriority::PRIO_PROMPT, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]), BufMode::BUF_LINEAR, 44100);
|
||||
auto id = inputStream_start(static_cast<AudioSource>(fn),
|
||||
AudioPriority::PRIO_PROMPT, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]),
|
||||
BufMode::BUF_LINEAR, 44100);
|
||||
CHECK(id != -1);
|
||||
|
||||
// Should fail
|
||||
auto id_2 = inputStream_start(
|
||||
static_cast<AudioSource>(fn), AudioPriority::PRIO_BEEP, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]), BufMode::BUF_LINEAR, 44100);
|
||||
auto id_2 = inputStream_start(static_cast<AudioSource>(fn),
|
||||
AudioPriority::PRIO_BEEP, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]),
|
||||
BufMode::BUF_LINEAR, 44100);
|
||||
CHECK(id_2 == -1);
|
||||
|
||||
auto id_3 = inputStream_start(
|
||||
static_cast<AudioSource>(fn), AudioPriority::PRIO_RX, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]), BufMode::BUF_LINEAR, 44100);
|
||||
auto id_3 = inputStream_start(static_cast<AudioSource>(fn),
|
||||
AudioPriority::PRIO_RX, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]),
|
||||
BufMode::BUF_LINEAR, 44100);
|
||||
CHECK(id_3 == -1);
|
||||
|
||||
// This should work, as it has higher priority
|
||||
auto id_4 = inputStream_start(
|
||||
static_cast<AudioSource>(fn), AudioPriority::PRIO_TX, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]), BufMode::BUF_LINEAR, 44100);
|
||||
auto id_4 = inputStream_start(static_cast<AudioSource>(fn),
|
||||
AudioPriority::PRIO_TX, tmp,
|
||||
sizeof(tmp) / sizeof(tmp[0]),
|
||||
BufMode::BUF_LINEAR, 44100);
|
||||
CHECK(id_4 != -1);
|
||||
|
||||
{
|
||||
|
|
@ -76,12 +76,11 @@ void test_linear()
|
|||
|
||||
int c_ptr = 0;
|
||||
// getData multiple times
|
||||
for (int i = 0; i < 20; i++)
|
||||
{
|
||||
for (int i = 0; i < 20; i++) {
|
||||
using namespace std::chrono;
|
||||
auto t1 = steady_clock::now();
|
||||
auto db = inputStream_getData(id);
|
||||
auto t2 = steady_clock::now();
|
||||
auto t1 = steady_clock::now();
|
||||
auto db = inputStream_getData(id);
|
||||
auto t2 = steady_clock::now();
|
||||
const uint64_t delta = duration_cast<microseconds>(t2 - t1).count();
|
||||
const uint64_t expected = (128 * 1000000 / 44100);
|
||||
|
||||
|
|
@ -90,8 +89,7 @@ void test_linear()
|
|||
|
||||
// Check the contents
|
||||
CHECK(db.len == 128);
|
||||
for (int i = 0; i < 128; i++)
|
||||
{
|
||||
for (int i = 0; i < 128; i++) {
|
||||
CHECK(tmp[i] == (c_ptr % 13));
|
||||
CHECK(db.data[i] == (c_ptr % 13));
|
||||
c_ptr++;
|
||||
|
|
@ -104,28 +102,26 @@ void test_linear()
|
|||
}
|
||||
}
|
||||
|
||||
void test_ring_buffer(uint64_t n_bytes,
|
||||
uint64_t n_iter,
|
||||
void test_ring_buffer(uint64_t n_bytes, uint64_t n_iter,
|
||||
const uint64_t buf_size)
|
||||
{
|
||||
for (int fn = 0; fn < 3; fn++)
|
||||
{
|
||||
FILE* fp = fopen(files[fn], "wb");
|
||||
for (int fn = 0; fn < 3; fn++) {
|
||||
FILE *fp = fopen(files[fn], "wb");
|
||||
CHECK(fp);
|
||||
|
||||
for (uint64_t i = 0; i < n_bytes; i++)
|
||||
{
|
||||
uint16_t j = i;
|
||||
uint8_t* buf = (uint8_t*)&j;
|
||||
for (uint64_t i = 0; i < n_bytes; i++) {
|
||||
uint16_t j = i;
|
||||
uint8_t *buf = (uint8_t *)&j;
|
||||
CHECK(fputc(buf[0], fp) == buf[0]);
|
||||
CHECK(fputc(buf[1], fp) == buf[1]);
|
||||
}
|
||||
fclose(fp);
|
||||
|
||||
std::vector<stream_sample_t> tmp(buf_size);
|
||||
auto id = inputStream_start(
|
||||
static_cast<AudioSource>(fn), AudioPriority::PRIO_BEEP, tmp.data(),
|
||||
tmp.size(), BufMode::BUF_CIRC_DOUBLE, 44100);
|
||||
auto id = inputStream_start(static_cast<AudioSource>(fn),
|
||||
AudioPriority::PRIO_BEEP, tmp.data(),
|
||||
tmp.size(), BufMode::BUF_CIRC_DOUBLE,
|
||||
44100);
|
||||
CHECK(id != -1);
|
||||
|
||||
using namespace std::chrono;
|
||||
|
|
@ -133,16 +129,14 @@ void test_ring_buffer(uint64_t n_bytes,
|
|||
|
||||
uint64_t ctr = 0;
|
||||
std::vector<stream_sample_t> tmp2(buf_size / 2);
|
||||
for (uint64_t i = 0; i < n_iter; i++)
|
||||
{
|
||||
for (uint64_t i = 0; i < n_iter; i++) {
|
||||
{
|
||||
auto db = inputStream_getData(id);
|
||||
|
||||
CHECK(db.len > 0);
|
||||
CHECK(db.data == &tmp[0]);
|
||||
memcpy(tmp2.data(), db.data, db.len * sizeof(stream_sample_t));
|
||||
for (uint64_t i = 0; i < db.len; i++)
|
||||
{
|
||||
for (uint64_t i = 0; i < db.len; i++) {
|
||||
CHECK(uint16_t(tmp2[i]) == uint16_t(ctr % n_bytes));
|
||||
ctr++;
|
||||
}
|
||||
|
|
@ -154,16 +148,15 @@ void test_ring_buffer(uint64_t n_bytes,
|
|||
CHECK(db.len > 0);
|
||||
CHECK(db.data == &tmp[buf_size / 2]);
|
||||
memcpy(tmp2.data(), db.data, db.len * sizeof(stream_sample_t));
|
||||
for (uint64_t i = 0; i < db.len; i++)
|
||||
{
|
||||
for (uint64_t i = 0; i < db.len; i++) {
|
||||
CHECK(uint16_t(tmp2[i]) == uint16_t(ctr % n_bytes));
|
||||
ctr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
auto t2 = steady_clock::now();
|
||||
const uint64_t delta = duration_cast<microseconds>(t2 - t0).count();
|
||||
auto t2 = steady_clock::now();
|
||||
const uint64_t delta = duration_cast<microseconds>(t2 - t0).count();
|
||||
const uint64_t expected = (buf_size * n_iter * 1000000lu / 44100);
|
||||
CHECK(delta > expected && delta < expected * 2);
|
||||
|
||||
|
|
|
|||
|
|
@ -25,10 +25,9 @@ int16_t buffer[BUF_LEN] = { 0 };
|
|||
|
||||
void fill_buffer_sine(int16_t *buffer, size_t len)
|
||||
{
|
||||
for(size_t i = 0; i < len; i++)
|
||||
{
|
||||
buffer[i] = AMPLITUDE * sin(2 * PI * i *
|
||||
((float) FREQUENCY / SAMPLE_RATE));
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
buffer[i] = AMPLITUDE
|
||||
* sin(2 * PI * i * ((float)FREQUENCY / SAMPLE_RATE));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -40,14 +39,9 @@ void play_sine_linear()
|
|||
fill_buffer_sine(buffer, BUF_LEN);
|
||||
|
||||
// Play back sine wave
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
id = outputStream_start(SINK_SPK,
|
||||
PRIO_PROMPT,
|
||||
buffer,
|
||||
BUF_LEN,
|
||||
BUF_LINEAR,
|
||||
SAMPLE_RATE);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
id = outputStream_start(SINK_SPK, PRIO_PROMPT, buffer, BUF_LEN,
|
||||
BUF_LINEAR, SAMPLE_RATE);
|
||||
};
|
||||
outputStream_sync(id, false);
|
||||
|
||||
|
|
@ -65,15 +59,10 @@ void play_sine_circular()
|
|||
fill_buffer_sine(buffer, BUF_LEN / 2);
|
||||
|
||||
// Play back sine wave
|
||||
id = outputStream_start(SINK_SPK,
|
||||
PRIO_PROMPT,
|
||||
buffer,
|
||||
BUF_LEN,
|
||||
BUF_CIRC_DOUBLE,
|
||||
SAMPLE_RATE);
|
||||
id = outputStream_start(SINK_SPK, PRIO_PROMPT, buffer, BUF_LEN,
|
||||
BUF_CIRC_DOUBLE, SAMPLE_RATE);
|
||||
|
||||
for(int i = 0; i < 10; i++)
|
||||
{
|
||||
for (int i = 0; i < 10; i++) {
|
||||
buf = outputStream_getIdleBuffer(id);
|
||||
fill_buffer_sine(buf, BUF_LEN / 2);
|
||||
outputStream_sync(id, true);
|
||||
|
|
|
|||
|
|
@ -13,29 +13,28 @@
|
|||
extern bool _ui_checkStandby(long long);
|
||||
extern state_t state;
|
||||
|
||||
void assert_display_timer(display_timer_t conf,
|
||||
long long time_sec,
|
||||
void assert_display_timer(display_timer_t conf, long long time_sec,
|
||||
bool expected)
|
||||
{
|
||||
state.settings.brightness_timer = conf;
|
||||
|
||||
long long ticks = time_sec * 1000;
|
||||
|
||||
if (_ui_checkStandby(ticks) != expected)
|
||||
{
|
||||
printf("FAILED! enum value %d - time %lld sec - expected %d\n",
|
||||
conf, time_sec, expected);
|
||||
if (_ui_checkStandby(ticks) != expected) {
|
||||
printf("FAILED! enum value %d - time %lld sec - expected %d\n", conf,
|
||||
time_sec, expected);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
void test_timer_threshold(display_timer_t conf, long long time_sec)
|
||||
{
|
||||
assert_display_timer(conf, time_sec -1, false);
|
||||
assert_display_timer(conf, time_sec - 1, false);
|
||||
assert_display_timer(conf, time_sec, true);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int main()
|
||||
{
|
||||
printf("Backlight timer test\n");
|
||||
|
||||
test_timer_threshold(TIMER_5S, 5);
|
||||
|
|
@ -51,7 +50,6 @@ int main() {
|
|||
test_timer_threshold(TIMER_4M, 4 * 60);
|
||||
test_timer_threshold(TIMER_5M, 5 * 60);
|
||||
|
||||
|
||||
test_timer_threshold(TIMER_15M, 15 * 60);
|
||||
test_timer_threshold(TIMER_30M, 30 * 60);
|
||||
test_timer_threshold(TIMER_45M, 45 * 60);
|
||||
|
|
|
|||
|
|
@ -17,14 +17,13 @@
|
|||
int main()
|
||||
{
|
||||
state.settings.vpLevel = 3;
|
||||
vpQueueFlags_t flags = vp_getVoiceLevelQueueFlags();
|
||||
vpQueueFlags_t flags = vp_getVoiceLevelQueueFlags();
|
||||
|
||||
vp_init();
|
||||
vp_flush();
|
||||
vp_queueStringTableEntry(¤tLanguage->allChannels);
|
||||
vp_play();
|
||||
while(true)
|
||||
{
|
||||
while (true) {
|
||||
vp_tick();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue