From 04adbaf8e1f410cd360a0487d6a51feeee7aa418 Mon Sep 17 00:00:00 2001 From: Dean Lee Date: Tue, 2 Feb 2021 20:18:11 +0800 Subject: [PATCH] Don't call function in assert (#19997) old-commit-hash: 91504176e403ca1bb6bd9491ce9e2075b7f4bae0 --- installer/installer.c | 3 ++- selfdrive/boardd/pigeon.cc | 22 +++++++++++------ selfdrive/logcatd/logcatd_systemd.cc | 24 ++++++++++--------- selfdrive/modeld/runners/onnxmodel.cc | 6 +++-- selfdrive/modeld/runners/snpemodel.cc | 6 +++-- .../modeld/test/snpe_benchmark/benchmark.cc | 3 ++- 6 files changed, 40 insertions(+), 24 deletions(-) diff --git a/installer/installer.c b/installer/installer.c index 137e4d6234..7ed667d5fa 100644 --- a/installer/installer.c +++ b/installer/installer.c @@ -156,7 +156,8 @@ void * run_spinner(void * args) { int main() { pthread_t spinner_thread; - assert(pthread_create(&spinner_thread, NULL, run_spinner, NULL) == 0); + int err = pthread_create(&spinner_thread, NULL, run_spinner, NULL); + assert(err == 0); int status = do_install(); diff --git a/selfdrive/boardd/pigeon.cc b/selfdrive/boardd/pigeon.cc index d5b577b5f8..da04430f17 100644 --- a/selfdrive/boardd/pigeon.cc +++ b/selfdrive/boardd/pigeon.cc @@ -132,8 +132,10 @@ void TTYPigeon::connect(const char * tty) { if (pigeon_tty_fd < 0){ handle_tty_issue(errno, __func__); assert(pigeon_tty_fd >= 0); + } - assert(tcgetattr(pigeon_tty_fd, &pigeon_tty) == 0); + int err = tcgetattr(pigeon_tty_fd, &pigeon_tty); + assert(err == 0); // configure tty pigeon_tty.c_cflag &= ~PARENB; // disable parity @@ -152,7 +154,8 @@ void TTYPigeon::connect(const char * tty) { pigeon_tty.c_cc[VMIN] = 0; // min amount of characters returned pigeon_tty.c_cc[VTIME] = 0; // max blocking time in s/10 (0=inf) - assert(tcsetattr(pigeon_tty_fd, TCSANOW, &pigeon_tty) == 0); + err = tcsetattr(pigeon_tty_fd, TCSANOW, &pigeon_tty); + assert(err == 0); } void TTYPigeon::set_baud(int baud){ @@ -169,15 +172,20 @@ void TTYPigeon::set_baud(int baud){ } // make sure everything is tx'ed before changing baud - assert(tcdrain(pigeon_tty_fd) == 0); + int err = tcdrain(pigeon_tty_fd); + assert(err == 0); // change baud - assert(tcgetattr(pigeon_tty_fd, &pigeon_tty) == 0); - assert(cfsetspeed(&pigeon_tty, baud_const) == 0); - assert(tcsetattr(pigeon_tty_fd, TCSANOW, &pigeon_tty) == 0); + err = tcgetattr(pigeon_tty_fd, &pigeon_tty); + assert(err == 0); + err = cfsetspeed(&pigeon_tty, baud_const); + assert(err == 0); + err = tcsetattr(pigeon_tty_fd, TCSANOW, &pigeon_tty); + assert(err == 0); // flush - assert(tcflush(pigeon_tty_fd, TCIOFLUSH) == 0); + err = tcflush(pigeon_tty_fd, TCIOFLUSH); + assert(err == 0); } void TTYPigeon::send(const std::string &s) { diff --git a/selfdrive/logcatd/logcatd_systemd.cc b/selfdrive/logcatd/logcatd_systemd.cc index abe3121a25..da9b3bb889 100644 --- a/selfdrive/logcatd/logcatd_systemd.cc +++ b/selfdrive/logcatd/logcatd_systemd.cc @@ -17,25 +17,27 @@ int main(int argc, char *argv[]) { PubMaster pm({"androidLog"}); sd_journal *journal; - assert(sd_journal_open(&journal, 0) >= 0); - assert(sd_journal_get_fd(journal) >= 0); // needed so sd_journal_wait() works properly if files rotate - assert(sd_journal_seek_tail(journal) >= 0); + int err = sd_journal_open(&journal, 0); + assert(err >= 0); + err = sd_journal_get_fd(journal); // needed so sd_journal_wait() works properly if files rotate + assert(err >= 0); + err = sd_journal_seek_tail(journal); + assert(err >= 0); - int r; while (!do_exit) { - r = sd_journal_next(journal); - assert(r >= 0); + err = sd_journal_next(journal); + assert(err >= 0); // Wait for new message if we didn't receive anything - if (r == 0){ - r = sd_journal_wait(journal, 1000 * 1000); - assert (r >= 0); + if (err == 0){ + err = sd_journal_wait(journal, 1000 * 1000); + assert (err >= 0); continue; // Try again } uint64_t timestamp = 0; - r = sd_journal_get_realtime_usec(journal, ×tamp); - assert(r >= 0); + err = sd_journal_get_realtime_usec(journal, ×tamp); + assert(err >= 0); const void *data; size_t length; diff --git a/selfdrive/modeld/runners/onnxmodel.cc b/selfdrive/modeld/runners/onnxmodel.cc index 4b89be4df8..ceefd85c32 100644 --- a/selfdrive/modeld/runners/onnxmodel.cc +++ b/selfdrive/modeld/runners/onnxmodel.cc @@ -22,8 +22,10 @@ ONNXModel::ONNXModel(const char *path, float *_output, size_t _output_size, int strcat(tmp, ".onnx"); LOGD("loading model %s", tmp); - assert(pipe(pipein) == 0); - assert(pipe(pipeout) == 0); + int err = pipe(pipein); + assert(err == 0); + err = pipe(pipeout); + assert(err == 0); std::string exe_dir = util::dir_name(util::readlink("/proc/self/exe")); std::string onnx_runner = exe_dir + "/runners/onnx_runner.py"; diff --git a/selfdrive/modeld/runners/snpemodel.cc b/selfdrive/modeld/runners/snpemodel.cc index 2197c24cd4..538c246562 100644 --- a/selfdrive/modeld/runners/snpemodel.cc +++ b/selfdrive/modeld/runners/snpemodel.cc @@ -140,7 +140,8 @@ void SNPEModel::execute(float *net_input_buf, int buf_size) { if (Runtime == zdl::DlSystem::Runtime_t::GPU) { float *inputs[4] = {recurrent, trafficConvention, desire, net_input_buf}; if (thneed == NULL) { - assert(inputBuffer->setBufferAddress(net_input_buf)); + bool ret = inputBuffer->setBufferAddress(net_input_buf); + assert(ret == true); if (!snpe->execute(inputMap, outputMap)) { PrintErrorStringAndExit(); } @@ -173,7 +174,8 @@ void SNPEModel::execute(float *net_input_buf, int buf_size) { } } else { #endif - assert(inputBuffer->setBufferAddress(net_input_buf)); + bool ret = inputBuffer->setBufferAddress(net_input_buf); + assert(ret == true); if (!snpe->execute(inputMap, outputMap)) { PrintErrorStringAndExit(); } diff --git a/selfdrive/modeld/test/snpe_benchmark/benchmark.cc b/selfdrive/modeld/test/snpe_benchmark/benchmark.cc index 0e8f4faf49..8209508629 100644 --- a/selfdrive/modeld/test/snpe_benchmark/benchmark.cc +++ b/selfdrive/modeld/test/snpe_benchmark/benchmark.cc @@ -85,7 +85,8 @@ void test(char *filename) { cout << "**** starting benchmark ****" << endl; for (int i = 0; i < 50; i++) { clock_gettime(CLOCK_MONOTONIC, &start); - assert(snpe->execute(inputTensorMap, outputTensorMap)); + int err = snpe->execute(inputTensorMap, outputTensorMap); + assert(err == true); clock_gettime(CLOCK_MONOTONIC, &end); uint64_t timeElapsed = timespecDiff(&end, &start); printf("time: %f ms\n", timeElapsed*1.0/1e6);