From 87950eb3127e175f0f2b0bb42440f5350c679369 Mon Sep 17 00:00:00 2001 From: Adeeb Shihadeh Date: Tue, 5 Jan 2021 12:50:23 -0800 Subject: [PATCH] setup clang tidy (#19533) * setup clang tidy * config * some cleanup * little more * remove that * fix qcom build --- .clang-tidy | 19 +++++++++++++++++++ .gitignore | 1 + SConstruct | 6 +++++- selfdrive/boardd/boardd.cc | 4 ++-- selfdrive/boardd/pigeon.cc | 4 ++-- selfdrive/camerad/cameras/camera_common.cc | 8 ++++---- selfdrive/camerad/cameras/camera_qcom.cc | 10 +++------- selfdrive/camerad/main.cc | 20 ++++++++++---------- selfdrive/common/params.cc | 2 +- 9 files changed, 47 insertions(+), 27 deletions(-) create mode 100644 .clang-tidy diff --git a/.clang-tidy b/.clang-tidy new file mode 100644 index 000000000..cc55fefd2 --- /dev/null +++ b/.clang-tidy @@ -0,0 +1,19 @@ +--- +Checks: ' +bugprone-*, +-bugprone-integer-division, +-bugprone-narrowing-conversions, +performance-*, +clang-analyzer-*, +misc-*, +-misc-unused-parameters, +modernize-*, +-modernize-avoid-c-arrays, +-modernize-deprecated-headers, +-modernize-use-auto, +-modernize-use-using, +-modernize-use-nullptr, +-modernize-use-trailing-return-type, +' +CheckOptions: +... diff --git a/.gitignore b/.gitignore index 915a798c7..75b9d5511 100644 --- a/.gitignore +++ b/.gitignore @@ -31,6 +31,7 @@ a.out *.vcd config.json clcache +compile_commands.json persist board/obj/ diff --git a/SConstruct b/SConstruct index f9b7a0aae..0b4135de8 100644 --- a/SConstruct +++ b/SConstruct @@ -21,6 +21,10 @@ AddOption('--clazy', action='store_true', help='build with clazy') +AddOption('--compile_db', + action='store_true', + help='build clang compilation database') + real_arch = arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip() if platform.system() == "Darwin": arch = "Darwin" @@ -186,7 +190,7 @@ env = Environment( tools=["default", "cython", "compilation_db"], ) -if GetOption('test'): +if GetOption('compile_db'): env.CompilationDatabase('compile_commands.json') if os.environ.get('SCONS_CACHE'): diff --git a/selfdrive/boardd/boardd.cc b/selfdrive/boardd/boardd.cc index d8da30be4..b59ea876e 100644 --- a/selfdrive/boardd/boardd.cc +++ b/selfdrive/boardd/boardd.cc @@ -72,7 +72,7 @@ void safety_setter_thread() { panda->set_safety_model(cereal::CarParams::SafetyModel::ELM327); // switch to SILENT when CarVin param is read - while (1) { + while (true) { if (do_exit || !panda->connected){ safety_setter_thread_running = false; return; @@ -94,7 +94,7 @@ void safety_setter_thread() { std::vector params; LOGW("waiting for params to set safety model"); - while (1) { + while (true) { if (do_exit || !panda->connected){ safety_setter_thread_running = false; return; diff --git a/selfdrive/boardd/pigeon.cc b/selfdrive/boardd/pigeon.cc index 5d2a9379e..5446840ff 100644 --- a/selfdrive/boardd/pigeon.cc +++ b/selfdrive/boardd/pigeon.cc @@ -37,14 +37,14 @@ void Pigeon::init() { LOGW("panda GPS start"); // power off pigeon - set_power(0); + set_power(false); util::sleep_for(100); // 9600 baud at init set_baud(9600); // power on pigeon - set_power(1); + set_power(true); util::sleep_for(500); // baud rate upping diff --git a/selfdrive/camerad/cameras/camera_common.cc b/selfdrive/camerad/cameras/camera_common.cc index 43e5ac287..48038d0f3 100644 --- a/selfdrive/camerad/cameras/camera_common.cc +++ b/selfdrive/camerad/cameras/camera_common.cc @@ -123,11 +123,11 @@ CameraBuf::~CameraBuf() { for (int i = 0; i < frame_buf_count; i++) { visionbuf_free(&camera_bufs[i]); } - for (int i = 0; i < UI_BUF_COUNT; i++) { - visionbuf_free(&rgb_bufs[i]); + for (auto &buf : rgb_bufs) { + visionbuf_free(&buf); } - for (int i = 0; i < YUV_COUNT; i++) { - visionbuf_free(&yuv_ion[i]); + for (auto &buf : yuv_ion) { + visionbuf_free(&buf); } rgb_to_yuv_destroy(&rgb_to_yuv_state); diff --git a/selfdrive/camerad/cameras/camera_qcom.cc b/selfdrive/camerad/cameras/camera_qcom.cc index 899139aea..3da23250b 100644 --- a/selfdrive/camerad/cameras/camera_qcom.cc +++ b/selfdrive/camerad/cameras/camera_qcom.cc @@ -427,7 +427,6 @@ static void do_autoexposure(CameraState *s, float grey_frac) { pthread_mutex_unlock(&s->frame_info_lock); set_exposure(s, s->cur_exposure_frac, cur_gain_frac); - } else { // keep the old for others float new_exposure = s->cur_exposure_frac; new_exposure *= pow(1.05, (target_grey - grey_frac) / 0.05 ); @@ -534,8 +533,6 @@ static void imx298_ois_calibration(int ois_fd, uint8_t* eeprom) { } - - static void sensors_init(MultiCameraState *s) { int err; @@ -782,7 +779,6 @@ static void sensors_init(MultiCameraState *s) { LOG("sensor init cfg (rear): %d", err); assert(err >= 0); - struct msm_camera_sensor_slave_info slave_info2 = {0}; if (s->device == DEVICE_LP3) { slave_info2 = (struct msm_camera_sensor_slave_info){ @@ -1987,10 +1983,10 @@ const char* get_isp_event_name(unsigned int type) { static FrameMetadata get_frame_metadata(CameraState *s, uint32_t frame_id) { pthread_mutex_lock(&s->frame_info_lock); - for (int i=0; iframe_metadata[i].frame_id == frame_id) { + for (auto &i : s->frame_metadata) { + if (i.frame_id == frame_id) { pthread_mutex_unlock(&s->frame_info_lock); - return s->frame_metadata[i]; + return i; } } pthread_mutex_unlock(&s->frame_info_lock); diff --git a/selfdrive/camerad/main.cc b/selfdrive/camerad/main.cc index b6b948fe0..a1e362e8e 100644 --- a/selfdrive/camerad/main.cc +++ b/selfdrive/camerad/main.cc @@ -72,13 +72,13 @@ static CameraBuf *get_camerabuf_by_type(VisionState *s, VisionStreamType type) { // visionserver void* visionserver_client_thread(void* arg) { int err; - VisionClientState *client = (VisionClientState*)arg; + auto *client = (VisionClientState*)arg; VisionState *s = client->s; int fd = client->fd; set_thread_name("clientthread"); - VisionClientStreamState streams[VISION_STREAM_MAX] = {{0}}; + VisionClientStreamState streams[VISION_STREAM_MAX] = {{false}}; LOGW("client start fd %d", fd); @@ -215,12 +215,12 @@ void* visionserver_client_thread(void* arg) { LOGW("client end fd %d", fd); - for (int i=0; iclients_lock); } - for (int i=0; iclients) { pthread_mutex_lock(&s->clients_lock); - bool running = s->clients[i].running; + bool running = client.running; pthread_mutex_unlock(&s->clients_lock); if (running) { - err = pthread_join(s->clients[i].thread_handle, NULL); + err = pthread_join(client.thread_handle, NULL); assert(err == 0); } } diff --git a/selfdrive/common/params.cc b/selfdrive/common/params.cc index ffae79fa6..9f4c2009b 100644 --- a/selfdrive/common/params.cc +++ b/selfdrive/common/params.cc @@ -257,7 +257,7 @@ std::string Params::get(std::string key, bool block){ size_t size; int r; - if (block){ + if (block) { r = read_db_value_blocking((const char*)key.c_str(), &value, &size); } else { r = read_db_value((const char*)key.c_str(), &value, &size);