Fix coverity warnings under lib/src/phy/utils

This commit is contained in:
Xavier Arteaga 2021-04-28 10:50:27 +02:00 committed by Andre Puschmann
parent 87cf3cf2e5
commit 892aea8219
5 changed files with 52 additions and 16 deletions

View File

@ -183,6 +183,10 @@ void srsran_psss_put_sf_buffer(cf_t* psss_signal, cf_t* sf_buffer, uint32_t nof_
*/
int srsran_psss_find(srsran_psss_t* q, cf_t* input, uint32_t nof_prb, srsran_cp_t cp)
{
if (q == NULL || input == NULL) {
return SRSRAN_ERROR_INVALID_INPUTS;
}
// One array for each N_id_2
float corr_peak_value[2] = {};
uint32_t corr_peak_pos[2] = {};

View File

@ -125,7 +125,8 @@ int fdd_tests(uint32_t max_cc)
for (uint32_t i = 0; i < nof_cc; i++) {
TESTASSERT(uci_data.cfg.ack[i].ncce[0] == i + 1);
for (uint32_t j = 0; j < uci_data.cfg.ack[i].nof_acks; j++) {
TESTASSERT(uci_data.value.ack.ack_value[k++]);
TESTASSERT(uci_data.value.ack.ack_value[k]);
k++;
}
}
TESTASSERT(k == srsran_uci_cfg_total_ack(&uci_data.cfg));
@ -143,7 +144,6 @@ int fdd_tests(uint32_t max_cc)
int main(int argc, char** argv)
{
// Test only until Format1B - CS
TESTASSERT(fdd_tests(2) == 0);

View File

@ -10,6 +10,7 @@
*
*/
#include "srsran/phy/utils/debug.h"
#include "srsran/phy/utils/random.h"
#include <complex.h>
#include <math.h>
@ -79,30 +80,42 @@ int test_dft(cf_t* in)
{
int res = 0;
srsran_dft_plan_t plan;
if (forward) {
srsran_dft_plan(&plan, N, SRSRAN_DFT_FORWARD, SRSRAN_DFT_COMPLEX);
} else {
srsran_dft_plan(&plan, N, SRSRAN_DFT_BACKWARD, SRSRAN_DFT_COMPLEX);
}
srsran_dft_plan_set_mirror(&plan, mirror);
srsran_dft_plan_set_norm(&plan, norm);
srsran_dft_plan_set_dc(&plan, dc);
cf_t* out1 = srsran_vec_cf_malloc(N);
cf_t* out2 = srsran_vec_cf_malloc(N);
srsran_vec_cf_zero(out1, N);
srsran_vec_cf_zero(out2, N);
srsran_dft_plan_t plan = {};
if (forward) {
if (srsran_dft_plan(&plan, N, SRSRAN_DFT_FORWARD, SRSRAN_DFT_COMPLEX) != SRSRAN_SUCCESS) {
ERROR("Error in DFT plan");
goto clean_exit;
}
} else {
if (srsran_dft_plan(&plan, N, SRSRAN_DFT_BACKWARD, SRSRAN_DFT_COMPLEX) != SRSRAN_SUCCESS) {
ERROR("Error in DFT plan");
goto clean_exit;
}
}
srsran_dft_plan_set_mirror(&plan, mirror);
srsran_dft_plan_set_norm(&plan, norm);
srsran_dft_plan_set_dc(&plan, dc);
print(in, N);
srsran_dft_run(&plan, in, out1);
print(out1, N);
srsran_dft_plan_t plan_rev;
if (!forward) {
srsran_dft_plan(&plan_rev, N, SRSRAN_DFT_FORWARD, SRSRAN_DFT_COMPLEX);
if (srsran_dft_plan(&plan_rev, N, SRSRAN_DFT_FORWARD, SRSRAN_DFT_COMPLEX) != SRSRAN_SUCCESS) {
ERROR("Error in DFT plan");
goto clean_exit;
}
} else {
srsran_dft_plan(&plan_rev, N, SRSRAN_DFT_BACKWARD, SRSRAN_DFT_COMPLEX);
if (srsran_dft_plan(&plan_rev, N, SRSRAN_DFT_BACKWARD, SRSRAN_DFT_COMPLEX) != SRSRAN_SUCCESS) {
ERROR("Error in DFT plan");
goto clean_exit;
}
}
srsran_dft_plan_set_mirror(&plan_rev, mirror);
srsran_dft_plan_set_norm(&plan_rev, norm);
@ -123,6 +136,7 @@ int test_dft(cf_t* in)
res = -1;
}
clean_exit:
srsran_dft_plan_free(&plan);
srsran_dft_plan_free(&plan_rev);
free(out1);

View File

@ -124,7 +124,15 @@ TEST(
for (int i = 0; i < block_size; i++) { gold += x[i] * y[i]; }
mse = (gold - z) / abs(gold);
// Check...
float abs_gold = abs(gold);
if (isnormal(abs_gold)) {
// Protected zero division
mse = (gold - z) / abs_gold;
} else {
// Flag error
mse = MAX_MSE;
}
free(x);
free(y);)

View File

@ -421,12 +421,22 @@ void srsran_vec_save_file(char* filename, const void* buffer, const uint32_t len
}
}
#define SAFE_READ(PTR, SIZE, N, FILE) \
do { \
size_t nbytes = SIZE * N; \
if (nbytes != fread(PTR, SIZE, N, FILE)) { \
perror("read"); \
fclose(FILE); \
exit(1); \
} \
} while (false)
void srsran_vec_load_file(char* filename, void* buffer, const uint32_t len)
{
FILE* f;
f = fopen(filename, "r");
if (f) {
fread(buffer, len, 1, f);
SAFE_READ(buffer, len, 1, f);
fclose(f);
} else {
perror("fopen");