Solved PHY unit test memory leaks

master
Xavier Arteaga 6 years ago
parent 794325fa29
commit c18a59730c

@ -38,6 +38,8 @@ SRSLTE_API int srslte_random_uniform_int_dist(srslte_random_t q, int min, int ma
SRSLTE_API float srslte_random_uniform_real_dist(srslte_random_t q, float min, float max);
SRSLTE_API cf_t srslte_random_uniform_complex_dist(srslte_random_t q, float min, float max);
SRSLTE_API float srslte_random_gauss_dist(srslte_random_t q, float std_dev);
SRSLTE_API void srslte_random_free(srslte_random_t q);

@ -30,6 +30,7 @@
#include <sys/time.h>
#include <unistd.h>
#undef ENABLE_GUI /* Disable GUI by default */
#ifdef ENABLE_GUI
#include "srsgui/srsgui.h"
static bool enable_gui = false;

@ -98,7 +98,7 @@ int srslte_layermap_type(cf_t* d[SRSLTE_MAX_CODEWORDS],
switch(type) {
case SRSLTE_TXSCHEME_PORT0:
if (nof_cw == 1 && nof_layers == 1) {
return srslte_layermap_single(x[0], d[0], nof_symbols[0]);
return srslte_layermap_single(d[0], x[0], nof_symbols[0]);
} else {
ERROR("Number of codewords and layers must be 1 for transmission on single antenna ports\n");
return -1;

@ -19,14 +19,15 @@
*
*/
#include <math.h>
#include <srslte/phy/utils/random.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>
#include <math.h>
#include <time.h>
#include <stdbool.h>
#include <unistd.h>
#include "srslte/srslte.h"
@ -72,6 +73,7 @@ void parse_args(int argc, char **argv) {
}
int main(int argc, char **argv) {
srslte_random_t random = srslte_random_init(0);
int i, j, num_errors, symbols_layer;
cf_t *d[SRSLTE_MAX_CODEWORDS], *x[SRSLTE_MAX_LAYERS], *dp[SRSLTE_MAX_CODEWORDS];
srslte_tx_scheme_t type;
@ -118,7 +120,7 @@ int main(int argc, char **argv) {
/* generate random data */
for (i=0;i<nof_cw;i++) {
for (j=0;j<nof_symb_cw[i];j++) {
d[i][j] = 100 * (rand()/RAND_MAX + I*rand()/RAND_MAX);
d[i][j] = srslte_random_uniform_complex_dist(random, -10, 10);
}
}
@ -152,6 +154,8 @@ int main(int argc, char **argv) {
free(x[i]);
}
srslte_random_free(random);
if (num_errors) {
printf("%d Errors\n", num_errors);
exit(-1);

@ -19,11 +19,12 @@
*
*/
#include <srslte/phy/utils/random.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <unistd.h>
#include "srslte/srslte.h"
@ -128,12 +129,13 @@ int main(int argc, char **argv) {
static uint8_t* data_rx[SRSLTE_MAX_CODEWORDS] = {NULL};
srslte_softbuffer_rx_t* softbuffers_rx[SRSLTE_MAX_CODEWORDS];
srslte_softbuffer_tx_t* softbuffers_tx[SRSLTE_MAX_CODEWORDS];
srslte_random_t random = srslte_random_init(0);
#ifdef DO_OFDM
cf_t* tx_sf_symbols[SRSLTE_MAX_PORTS];
cf_t* rx_sf_symbols[SRSLTE_MAX_PORTS];
cf_t* tx_sf_symbols[SRSLTE_MAX_PORTS] = {};
cf_t* rx_sf_symbols[SRSLTE_MAX_PORTS] = {};
#endif /* DO_OFDM */
cf_t* tx_slot_symbols[SRSLTE_MAX_PORTS];
cf_t* rx_slot_symbols[SRSLTE_MAX_PORTS];
cf_t* tx_slot_symbols[SRSLTE_MAX_PORTS] = {};
cf_t* rx_slot_symbols[SRSLTE_MAX_PORTS] = {};
srslte_chest_dl_res_t chest_dl_res;
srslte_pmch_t pmch;
@ -290,7 +292,7 @@ int main(int argc, char **argv) {
for (int tb = 0; tb < SRSLTE_MAX_CODEWORDS; tb++) {
if (pmch_cfg.pdsch_cfg.grant.tb[tb].enabled) {
for (int byte = 0; byte < pmch_cfg.pdsch_cfg.grant.tb[tb].tbs / 8; byte++) {
data_tx[tb][byte] = (uint8_t)(rand() % 256);
data_tx[tb][byte] = (uint8_t)srslte_random_uniform_int_dist(random, 0, 255);
}
}
}
@ -430,6 +432,7 @@ quit:
free(rx_slot_symbols[i]);
}
}
srslte_random_free(random);
if (ret) {
printf("Error\n");
} else {

@ -21,6 +21,7 @@
#include "srslte/srslte.h"
#include <srslte/phy/phch/pusch_cfg.h>
#include <srslte/phy/utils/random.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -44,7 +45,7 @@ static srslte_uci_offset_cfg_t uci_cfg = {
.I_offset_ack = 9,
};
static srslte_uci_data_t uci_data_tx;
static srslte_uci_data_t uci_data_tx = {};
uint32_t L_rb = 2;
uint32_t tbs = 0;
@ -147,7 +148,7 @@ void parse_args(int argc, char **argv) {
riv = (int) strtol(argv[optind], NULL, 10);
break;
case 'L':
L_rb = (int)strtol(argv[optind], NULL, 10);
L_rb = (uint32_t)strtol(argv[optind], NULL, 10);
break;
case 'F':
freq_hop = (int) strtol(argv[optind], NULL, 10);
@ -177,6 +178,7 @@ void parse_args(int argc, char **argv) {
int main(int argc, char** argv)
{
srslte_random_t random_h = srslte_random_init(0);
srslte_chest_ul_res_t chest_res;
srslte_pusch_t pusch_tx;
srslte_pusch_t pusch_rx;
@ -198,7 +200,6 @@ int main(int argc, char** argv)
srslte_dci_ul_t dci;
ZERO_OBJECT(dci);
srand(time(NULL));
parse_args(argc, argv);
dci.freq_hop_fl = freq_hop;
@ -213,10 +214,7 @@ int main(int argc, char** argv)
ZERO_OBJECT(ul_sf);
ul_sf.tti = 0;
srslte_pusch_hopping_cfg_t ul_hopping;
ul_hopping.n_sb = 1;
ul_hopping.hopping_offset = 0;
ul_hopping.hop_mode = 1;
srslte_pusch_hopping_cfg_t ul_hopping = {.n_sb = 1, .hopping_offset = 0, .hop_mode = 1};
if (srslte_ra_ul_dci_to_grant(&cell, &ul_sf, &ul_hopping, &dci, &cfg.grant)) {
ERROR("Error computing resource allocation\n");
@ -287,18 +285,18 @@ int main(int argc, char** argv)
ret = SRSLTE_SUCCESS;
/* Configure PUSCH */
ul_sf.tti = n;
ul_sf.tti = (uint32_t)n;
cfg.uci_offset = uci_cfg;
srslte_softbuffer_tx_reset(&softbuffer_tx);
srslte_softbuffer_rx_reset(&softbuffer_rx);
for (uint32_t i = 0; i < cfg.grant.tb.tbs / 8; i++) {
data[i] = (uint8_t) (random() & 0xff);
data[i] = (uint8_t)srslte_random_uniform_int_dist(random_h, 0, 255);
}
for (uint32_t a = 0; a < uci_data_tx.cfg.ack.nof_acks; a++) {
uci_data_tx.value.ack.ack_value[a] = (uint8_t)(random() & 0x1);
uci_data_tx.value.ack.ack_value[a] = (uint8_t)srslte_random_uniform_int_dist(random_h, 0, 1);
}
srslte_pusch_data_t pdata;
@ -320,9 +318,9 @@ int main(int argc, char** argv)
}
}
srslte_pusch_res_t pusch_res;
pusch_res.data = data_rx;
cfg.softbuffers.rx = &softbuffer_rx;
srslte_pusch_res_t pusch_res = {};
pusch_res.data = data_rx;
cfg.softbuffers.rx = &softbuffer_rx;
memcpy(&cfg.uci_cfg, &uci_data_tx.cfg, sizeof(srslte_uci_cfg_t));
gettimeofday(&t[1], NULL);
@ -394,7 +392,7 @@ int main(int argc, char** argv)
srslte_pusch_free(&pusch_rx);
srslte_softbuffer_tx_free(&softbuffer_tx);
srslte_softbuffer_rx_free(&softbuffer_rx);
srslte_random_free(random_h);
if (sf_symbols) {
free(sf_symbols);
}

@ -20,19 +20,7 @@
*/
#include "srslte/srslte.h"
#include <complex.h>
#include <math.h>
#include <memory.h>
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include "srslte/phy/utils/mat.h"
#include "srslte/phy/utils/simd.h"
#include "srslte/phy/utils/vector.h"
#include <srslte/phy/utils/random.h>
bool zf_solver = false;
bool mmse_solver = false;
@ -43,29 +31,36 @@ bool verbose = false;
#define MAX_FUNCTIONS (64)
#define MAX_BLOCKS (16)
#define RANDOM_F() (((float) rand()) / ((float) RAND_MAX) * 2.0f - 1.0f)
#define RANDOM_S() ((int16_t)(rand() & 0x800F))
#define RANDOM_B() ((int8_t)(rand() & 0x8008))
#define RANDOM_CF() (RANDOM_F() + _Complex_I*RANDOM_F())
static srslte_random_t random_h = NULL;
#define RANDOM_F() srslte_random_uniform_real_dist(random_h, -1.0f, +1.0f)
#define RANDOM_S() ((int16_t)srslte_random_uniform_int_dist(random_h, -255, +255))
#define RANDOM_B() ((int8_t)srslte_random_uniform_int_dist(random_h, -127, +127))
#define RANDOM_CF() srslte_random_uniform_complex_dist(random_h, -1.0f, +1.0f)
#define TEST_CALL(TEST_CODE) gettimeofday(&start, NULL);\
for (int i = 0; i < NOF_REPETITIONS; i++){TEST_CODE;}\
gettimeofday(&end, NULL); \
*timing = elapsed_us(&start, &end);
#define TEST(X, CODE) static bool test_##X (char *func_name, double *timing, uint32_t block_size) {\
struct timeval start, end;\
bzero(&start, sizeof(start));\
bzero(&end, sizeof(end));\
float mse = 0.0f;\
bool passed;\
strncpy(func_name, #X, 32);\
CODE;\
passed = (mse < MAX_MSE);\
printf("%32s (%5d) ... %7.1f MSamp/s ... %3s Passed (%.6f)\n", func_name, block_size, \
(double) block_size*NOF_REPETITIONS/ *timing, passed?"":"Not", mse);\
return passed;\
}
#define TEST(X, CODE) \
static bool test_##X(char* func_name, double* timing, uint32_t block_size) \
{ \
struct timeval start, end; \
bzero(&start, sizeof(start)); \
bzero(&end, sizeof(end)); \
float mse = 0.0f; \
bool passed = false; \
strncpy(func_name, #X, 32); \
CODE; \
passed = (mse < MAX_MSE); \
printf("%32s (%5d) ... %7.1f MSamp/s ... %3s Passed (%.6f)\n", \
func_name, \
block_size, \
(double)block_size* NOF_REPETITIONS / *timing, \
passed ? "" : "Not", \
mse); \
return passed; \
}
#define MALLOC(TYPE, NAME) TYPE *NAME = srslte_vec_malloc(sizeof(TYPE)*block_size)
@ -504,28 +499,31 @@ TEST(srslte_vec_convert_if,
free(z);
)
TEST(srslte_vec_prod_fff,
MALLOC(float, x);
MALLOC(float, y);
MALLOC(float, z);
cf_t gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_CF();
y[i] = RANDOM_CF();
}
TEST_CALL(srslte_vec_prod_fff(x, y, z, block_size))
TEST(
srslte_vec_prod_fff, MALLOC(float, x); MALLOC(float, y); MALLOC(float, z);
float gold;
for (int i = 0; i < block_size; i++) {
x[i] = RANDOM_F();
y[i] = RANDOM_F();
if (isnan(x[i])) {
printf("RANDOM_F!! x=%f; y=%f\n", x[i], y[i]);
}
}
for (int i = 0; i < block_size; i++) {
gold = x[i] * y[i];
mse += cabsf(gold - z[i]);
}
TEST_CALL(srslte_vec_prod_fff(x, y, z, block_size))
free(x);
free(y);
free(z);
)
for (int i = 0; i < block_size; i++) {
gold = x[i] * y[i];
if (isnan(gold)) {
printf("x=%f; y=%f\n", x[i], y[i]);
}
mse += fabsf(gold - z[i]);
}
free(x);
free(y);
free(z);)
TEST(srslte_vec_prod_cfc,
MALLOC(cf_t, x);
@ -820,9 +818,9 @@ TEST(srslte_vec_estimate_frequency, MALLOC(cf_t, x); float freq_gold = 0.1f; flo
for (int i = 0; i < block_size; i++) { x[i] = cexpf(-I * 2.0f * M_PI * (float)i * freq_gold); }
if (block_size > 6) {
TEST_CALL(freq = srslte_vec_estimate_frequency(x, block_size);)
} mse = cabsf(freq - freq_gold);
TEST_CALL(freq = srslte_vec_estimate_frequency(x, block_size);) if (block_size < 6) { mse = 0.0f; } else {
mse = fabsf(freq - freq_gold);
}
free(x);)
@ -888,6 +886,7 @@ int main(int argc, char **argv) {
uint32_t func_count = 0;
bool passed[MAX_FUNCTIONS][MAX_BLOCKS];
bool all_passed = true;
random_h = srslte_random_init(0x1234);
for (uint32_t block_size = 1; block_size <= 1024*32; block_size *= 2) {
func_count = 0;
@ -1053,6 +1052,7 @@ int main(int argc, char **argv) {
}
if (f) fclose(f);
srslte_random_free(random_h);
return (all_passed)?SRSLTE_SUCCESS:SRSLTE_ERROR;
}

@ -19,6 +19,7 @@
*
*/
#include <srslte/phy/utils/random.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@ -67,7 +68,7 @@ void parse_extensive_param(char* param, char* arg)
{
int ext_code = SRSLTE_SUCCESS;
if (!strcmp(param, "carrier-indicator")) {
cross_carrier_indicator = atoi(arg);
cross_carrier_indicator = (uint32_t)strtol(arg, NULL, 10);
} else {
ext_code = SRSLTE_ERROR;
}
@ -83,7 +84,7 @@ void parse_args(int argc, char **argv) {
while ((opt = getopt(argc, argv, "cfapndvstm")) != -1) {
switch (opt) {
case 't':
transmission_mode = strtol(argv[optind], NULL, 10) - 1;
transmission_mode = (uint32_t)strtol(argv[optind], NULL, 10) - 1;
if (transmission_mode == 0) {
cell.nof_ports = 1;
nof_rx_ant = 1;
@ -93,19 +94,19 @@ void parse_args(int argc, char **argv) {
}
break;
case 'f':
cfi = (uint32_t) atoi(argv[optind]);
cfi = (uint32_t)(uint32_t)strtol(argv[optind], NULL, 10);
break;
case 'm':
mcs = (uint32_t) atoi(argv[optind]);
mcs = (uint32_t)(uint32_t)strtol(argv[optind], NULL, 10);
break;
case 'p':
cell.nof_prb = (uint32_t) atoi(argv[optind]);
cell.nof_prb = (uint32_t)strtol(argv[optind], NULL, 10);
break;
case 'c':
cell.id = (uint32_t) atoi(argv[optind]);
cell.id = (uint32_t)strtol(argv[optind], NULL, 10);
break;
case 's':
nof_subframes = (uint32_t) atoi(argv[optind]);
nof_subframes = (uint32_t)strtol(argv[optind], NULL, 10);
break;
case 'd':
print_dci_table = true;
@ -306,6 +307,7 @@ static int check_evm(srslte_ue_dl_cfg_t* ue_dl_cfg, int tb)
}
int main(int argc, char **argv) {
srslte_random_t random = srslte_random_init(0);
struct timeval t[3] = {};
size_t tx_nof_bits = 0, rx_nof_bits = 0;
srslte_softbuffer_tx_t *softbuffer_tx[SRSLTE_MAX_TB] = {};
@ -474,7 +476,7 @@ int main(int argc, char **argv) {
dci.tb[1].rv = 1;
} else if (transmission_mode == SRSLTE_TM3) {
dci.format = SRSLTE_DCI_FORMAT2A;
for (int i = 0; i < SRSLTE_MAX_TB; i++) {
for (uint32_t i = 0; i < SRSLTE_MAX_TB; i++) {
dci.tb[i].mcs_idx = mcs;
dci.tb[i].rv = 0;
dci.tb[i].ndi = 0;
@ -483,7 +485,7 @@ int main(int argc, char **argv) {
} else if (transmission_mode == SRSLTE_TM4) {
dci.format = SRSLTE_DCI_FORMAT2;
dci.pinfo = 0;
for (int i = 0; i < SRSLTE_MAX_TB; i++) {
for (uint32_t i = 0; i < SRSLTE_MAX_TB; i++) {
dci.tb[i].mcs_idx = mcs;
dci.tb[i].rv = 0;
dci.tb[i].ndi = 0;
@ -499,9 +501,9 @@ int main(int argc, char **argv) {
INFO("--- Starting test ---\n");
for (uint32_t sf_idx = 0; sf_idx < nof_subframes; sf_idx++) {
/* Generate random data */
for (int t = 0; t < SRSLTE_MAX_TB; t++) {
for (int j = 0; j < SRSLTE_MAX_TB; j++) {
for (int i = 0; i < MAX_DATABUFFER_SIZE; i++) {
data_tx[t][i] = (uint8_t)(rand() & 0xff);
data_tx[j][i] = (uint8_t)srslte_random_uniform_int_dist(random, 0, 255);
}
}
@ -532,7 +534,7 @@ int main(int argc, char **argv) {
}
gettimeofday(&t[2], NULL);
get_time_interval(t);
pdsch_encode_us += t[0].tv_sec * 1e6 + t[0].tv_usec;
pdsch_encode_us += (size_t)(t[0].tv_sec * 1e6 + t[0].tv_usec);
// MIMO perfect crossed channel
if (transmission_mode > 1) {
@ -572,6 +574,7 @@ int main(int argc, char **argv) {
ue_dl_cfg.chest_cfg.interpolate_subframe = false;
ue_dl_cfg.chest_cfg.cfo_estimate_enable = false;
ue_dl_cfg.chest_cfg.cfo_estimate_sf_mask = false;
ue_dl_cfg.chest_cfg.sync_error_enable = false;
ue_dl_cfg.dci_cfg = dci_cfg;
srslte_pdsch_res_t pdsch_res[SRSLTE_MAX_CODEWORDS];
@ -587,7 +590,7 @@ int main(int argc, char **argv) {
gettimeofday(&t[2], NULL);
get_time_interval(t);
pdsch_decode_us += t[0].tv_sec * 1e6 + t[0].tv_usec;
pdsch_decode_us += (size_t)(t[0].tv_sec * 1e6 + t[0].tv_usec);
for (int i = 0; i < SRSLTE_MAX_TB; i++) {
if (ue_dl_cfg.cfg.pdsch.grant.tb[i].enabled) {
@ -601,10 +604,11 @@ int main(int argc, char **argv) {
srslte_vec_fprint_byte(stdout, (uint8_t*)enb_dl.pdsch.e[i], ue_dl_cfg.cfg.pdsch.grant.tb[i].nof_bits / 8);
srslte_vec_fprint_byte(stdout, (uint8_t*)ue_dl.pdsch.e[i], ue_dl_cfg.cfg.pdsch.grant.tb[i].nof_bits / 8);
count_failures++;
} else if (!pdsch_res[i].crc || memcmp(data_tx[i], data_rx[i], ue_dl_cfg.cfg.pdsch.grant.tb[i].tbs / 8) != 0) {
} else if (!pdsch_res[i].crc ||
memcmp(data_tx[i], data_rx[i], (uint32_t)ue_dl_cfg.cfg.pdsch.grant.tb[i].tbs / 8) != 0) {
printf("UE Failed decoding tb %d in subframe %d. crc=%d; Bytes:\n", i, sf_idx, pdsch_res[i].crc);
srslte_vec_fprint_byte(stdout, data_tx[i], ue_dl_cfg.cfg.pdsch.grant.tb[i].tbs / 8);
srslte_vec_fprint_byte(stdout, data_rx[i], ue_dl_cfg.cfg.pdsch.grant.tb[i].tbs / 8);
srslte_vec_fprint_byte(stdout, data_tx[i], (uint32_t)ue_dl_cfg.cfg.pdsch.grant.tb[i].tbs / 8);
srslte_vec_fprint_byte(stdout, data_rx[i], (uint32_t)ue_dl_cfg.cfg.pdsch.grant.tb[i].tbs / 8);
count_failures++;
} else {
// Decoded Ok
@ -635,6 +639,7 @@ int main(int argc, char **argv) {
quit:
srslte_enb_dl_free(&enb_dl);
srslte_ue_dl_free(&ue_dl);
srslte_random_free(random);
for (
int i = 0;

Loading…
Cancel
Save