bugfix - fix memcheck warnings. move instructions with side effects outside of asserts

master
Francisco 4 years ago committed by Francisco Paisana
parent a064e85c54
commit 3b78bf3730

@ -144,9 +144,10 @@ private:
// used to unlock select // used to unlock select
struct ctrl_cmd_t { struct ctrl_cmd_t {
enum class cmd_id_t { EXIT, NEW_FD, RM_FD }; enum class cmd_id_t { EXIT, NEW_FD, RM_FD };
cmd_id_t cmd = cmd_id_t::EXIT; cmd_id_t cmd;
int new_fd = -1; int new_fd;
bool signal_rm_complete = false; bool signal_rm_complete;
ctrl_cmd_t() { bzero(this, sizeof(ctrl_cmd_t)); }
}; };
std::map<int, recv_callback_t>::iterator remove_socket_unprotected(int fd, fd_set* total_fd_set, int* max_fd); std::map<int, recv_callback_t>::iterator remove_socket_unprotected(int fd, fd_set* total_fd_set, int* max_fd);

@ -329,7 +329,8 @@ bool sctp_init_server(unique_socket* socket, net_utils::socket_type socktype, co
socket_manager::socket_manager() : thread("RXsockets"), socket_manager_itf(srslog::fetch_basic_logger("COMN")) socket_manager::socket_manager() : thread("RXsockets"), socket_manager_itf(srslog::fetch_basic_logger("COMN"))
{ {
// register control pipe fd // register control pipe fd
srsran_assert(pipe(pipefd) != -1, "Failed to open control pipe"); int fd = pipe(pipefd);
srsran_assert(fd != -1, "Failed to open control pipe");
start(thread_prio); start(thread_prio);
} }
@ -344,7 +345,7 @@ void socket_manager::stop()
// close thread // close thread
{ {
std::lock_guard<std::mutex> lock(socket_mutex); std::lock_guard<std::mutex> lock(socket_mutex);
ctrl_cmd_t msg{}; ctrl_cmd_t msg;
msg.cmd = ctrl_cmd_t::cmd_id_t::EXIT; msg.cmd = ctrl_cmd_t::cmd_id_t::EXIT;
if (write(pipefd[1], &msg, sizeof(msg)) != sizeof(msg)) { if (write(pipefd[1], &msg, sizeof(msg)) != sizeof(msg)) {
rxSockError("while writing to control pipe"); rxSockError("while writing to control pipe");

@ -22,53 +22,56 @@ typedef struct {
byte_buffer_queue* q; byte_buffer_queue* q;
} args_t; } args_t;
void* write_thread(void* a) void write_thread(byte_buffer_queue* q)
{ {
args_t* args = (args_t*)a; unique_byte_buffer_t b;
for (uint32_t i = 0; i < NMSGS; i++) { for (uint32_t i = 0; i < NMSGS; i++) {
unique_byte_buffer_t b = srsran::make_byte_buffer(); do {
if (b == nullptr) { b = srsran::make_byte_buffer();
return nullptr; if (b == nullptr) {
} // wait until pool is not depleted
std::this_thread::yield();
}
} while (b == nullptr);
memcpy(b->msg, &i, 4); memcpy(b->msg, &i, 4);
b->N_bytes = 4; b->N_bytes = 4;
args->q->write(std::move(b)); q->write(std::move(b));
} }
return NULL;
} }
int main(int argc, char** argv) int test_concurrent_writeread()
{ {
bool result;
byte_buffer_queue q; byte_buffer_queue q;
unique_byte_buffer_t b; unique_byte_buffer_t b;
pthread_t thread; int result = 0;
args_t args;
u_int32_t r;
result = true; std::thread t([&q]() { write_thread(&q); });
args.q = &q;
pthread_create(&thread, NULL, &write_thread, &args);
for (uint32_t i = 0; i < NMSGS; i++) { for (uint32_t i = 0; i < NMSGS; i++) {
b = q.read(); b = q.read();
uint32_t r = 0;
memcpy(&r, b->msg, 4); memcpy(&r, b->msg, 4);
if (r != i) if (r != i) {
result = false; result = -1;
break;
}
} }
pthread_join(thread, NULL); t.join();
if (q.size() != 0 || q.size_bytes() != 0) { if (q.size() != 0 || q.size_bytes() != 0) {
result = false; result = -1;
} }
if (result) { if (result == 0) {
printf("Passed\n"); printf("Passed\n");
exit(0);
} else { } else {
printf("Failed\n;"); printf("Failed\n;");
exit(1);
} }
return result;
}
int main()
{
return test_concurrent_writeread();
} }

@ -28,7 +28,8 @@ struct mme_dummy {
TESTASSERT(bind_addr(fd, mme_sockaddr)); TESTASSERT(bind_addr(fd, mme_sockaddr));
} }
srsran_assert(listen(fd, SOMAXCONN) == 0, "Failed to listen to incoming SCTP connections"); int success = listen(fd, SOMAXCONN);
srsran_assert(success == 0, "Failed to listen to incoming SCTP connections");
} }
~mme_dummy() ~mme_dummy()

Loading…
Cancel
Save