setup clang tidy (#19533)

* setup clang tidy

* config

* some cleanup

* little more

* remove that

* fix qcom build
pull/19670/head
Adeeb Shihadeh 2021-01-05 12:50:23 -08:00 committed by GitHub
parent bd8fbe15bf
commit 87950eb312
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 47 additions and 27 deletions

19
.clang-tidy 100644
View File

@ -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:
...

1
.gitignore vendored
View File

@ -31,6 +31,7 @@ a.out
*.vcd *.vcd
config.json config.json
clcache clcache
compile_commands.json
persist persist
board/obj/ board/obj/

View File

@ -21,6 +21,10 @@ AddOption('--clazy',
action='store_true', action='store_true',
help='build with clazy') 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() real_arch = arch = subprocess.check_output(["uname", "-m"], encoding='utf8').rstrip()
if platform.system() == "Darwin": if platform.system() == "Darwin":
arch = "Darwin" arch = "Darwin"
@ -186,7 +190,7 @@ env = Environment(
tools=["default", "cython", "compilation_db"], tools=["default", "cython", "compilation_db"],
) )
if GetOption('test'): if GetOption('compile_db'):
env.CompilationDatabase('compile_commands.json') env.CompilationDatabase('compile_commands.json')
if os.environ.get('SCONS_CACHE'): if os.environ.get('SCONS_CACHE'):

View File

@ -72,7 +72,7 @@ void safety_setter_thread() {
panda->set_safety_model(cereal::CarParams::SafetyModel::ELM327); panda->set_safety_model(cereal::CarParams::SafetyModel::ELM327);
// switch to SILENT when CarVin param is read // switch to SILENT when CarVin param is read
while (1) { while (true) {
if (do_exit || !panda->connected){ if (do_exit || !panda->connected){
safety_setter_thread_running = false; safety_setter_thread_running = false;
return; return;
@ -94,7 +94,7 @@ void safety_setter_thread() {
std::vector<char> params; std::vector<char> params;
LOGW("waiting for params to set safety model"); LOGW("waiting for params to set safety model");
while (1) { while (true) {
if (do_exit || !panda->connected){ if (do_exit || !panda->connected){
safety_setter_thread_running = false; safety_setter_thread_running = false;
return; return;

View File

@ -37,14 +37,14 @@ void Pigeon::init() {
LOGW("panda GPS start"); LOGW("panda GPS start");
// power off pigeon // power off pigeon
set_power(0); set_power(false);
util::sleep_for(100); util::sleep_for(100);
// 9600 baud at init // 9600 baud at init
set_baud(9600); set_baud(9600);
// power on pigeon // power on pigeon
set_power(1); set_power(true);
util::sleep_for(500); util::sleep_for(500);
// baud rate upping // baud rate upping

View File

@ -123,11 +123,11 @@ CameraBuf::~CameraBuf() {
for (int i = 0; i < frame_buf_count; i++) { for (int i = 0; i < frame_buf_count; i++) {
visionbuf_free(&camera_bufs[i]); visionbuf_free(&camera_bufs[i]);
} }
for (int i = 0; i < UI_BUF_COUNT; i++) { for (auto &buf : rgb_bufs) {
visionbuf_free(&rgb_bufs[i]); visionbuf_free(&buf);
} }
for (int i = 0; i < YUV_COUNT; i++) { for (auto &buf : yuv_ion) {
visionbuf_free(&yuv_ion[i]); visionbuf_free(&buf);
} }
rgb_to_yuv_destroy(&rgb_to_yuv_state); rgb_to_yuv_destroy(&rgb_to_yuv_state);

View File

@ -427,7 +427,6 @@ static void do_autoexposure(CameraState *s, float grey_frac) {
pthread_mutex_unlock(&s->frame_info_lock); pthread_mutex_unlock(&s->frame_info_lock);
set_exposure(s, s->cur_exposure_frac, cur_gain_frac); set_exposure(s, s->cur_exposure_frac, cur_gain_frac);
} else { // keep the old for others } else { // keep the old for others
float new_exposure = s->cur_exposure_frac; float new_exposure = s->cur_exposure_frac;
new_exposure *= pow(1.05, (target_grey - grey_frac) / 0.05 ); 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) { static void sensors_init(MultiCameraState *s) {
int err; int err;
@ -782,7 +779,6 @@ static void sensors_init(MultiCameraState *s) {
LOG("sensor init cfg (rear): %d", err); LOG("sensor init cfg (rear): %d", err);
assert(err >= 0); assert(err >= 0);
struct msm_camera_sensor_slave_info slave_info2 = {0}; struct msm_camera_sensor_slave_info slave_info2 = {0};
if (s->device == DEVICE_LP3) { if (s->device == DEVICE_LP3) {
slave_info2 = (struct msm_camera_sensor_slave_info){ 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) { static FrameMetadata get_frame_metadata(CameraState *s, uint32_t frame_id) {
pthread_mutex_lock(&s->frame_info_lock); pthread_mutex_lock(&s->frame_info_lock);
for (int i=0; i<METADATA_BUF_COUNT; i++) { for (auto &i : s->frame_metadata) {
if (s->frame_metadata[i].frame_id == frame_id) { if (i.frame_id == frame_id) {
pthread_mutex_unlock(&s->frame_info_lock); pthread_mutex_unlock(&s->frame_info_lock);
return s->frame_metadata[i]; return i;
} }
} }
pthread_mutex_unlock(&s->frame_info_lock); pthread_mutex_unlock(&s->frame_info_lock);

View File

@ -72,13 +72,13 @@ static CameraBuf *get_camerabuf_by_type(VisionState *s, VisionStreamType type) {
// visionserver // visionserver
void* visionserver_client_thread(void* arg) { void* visionserver_client_thread(void* arg) {
int err; int err;
VisionClientState *client = (VisionClientState*)arg; auto *client = (VisionClientState*)arg;
VisionState *s = client->s; VisionState *s = client->s;
int fd = client->fd; int fd = client->fd;
set_thread_name("clientthread"); set_thread_name("clientthread");
VisionClientStreamState streams[VISION_STREAM_MAX] = {{0}}; VisionClientStreamState streams[VISION_STREAM_MAX] = {{false}};
LOGW("client start fd %d", fd); LOGW("client start fd %d", fd);
@ -215,12 +215,12 @@ void* visionserver_client_thread(void* arg) {
LOGW("client end fd %d", fd); LOGW("client end fd %d", fd);
for (int i=0; i<VISION_STREAM_MAX; i++) { for (auto &stream : streams) {
if (!streams[i].subscribed) continue; if (!stream.subscribed) continue;
if (streams[i].tb) { if (stream.tb) {
tbuffer_release_all(streams[i].tbuffer); tbuffer_release_all(stream.tbuffer);
} else { } else {
pool_release_queue(streams[i].queue); pool_release_queue(stream.queue);
} }
} }
@ -286,12 +286,12 @@ void* visionserver_thread(void* arg) {
pthread_mutex_unlock(&s->clients_lock); pthread_mutex_unlock(&s->clients_lock);
} }
for (int i=0; i<MAX_CLIENTS; i++) { for (auto &client : s->clients) {
pthread_mutex_lock(&s->clients_lock); pthread_mutex_lock(&s->clients_lock);
bool running = s->clients[i].running; bool running = client.running;
pthread_mutex_unlock(&s->clients_lock); pthread_mutex_unlock(&s->clients_lock);
if (running) { if (running) {
err = pthread_join(s->clients[i].thread_handle, NULL); err = pthread_join(client.thread_handle, NULL);
assert(err == 0); assert(err == 0);
} }
} }

View File

@ -257,7 +257,7 @@ std::string Params::get(std::string key, bool block){
size_t size; size_t size;
int r; int r;
if (block){ if (block) {
r = read_db_value_blocking((const char*)key.c_str(), &value, &size); r = read_db_value_blocking((const char*)key.c_str(), &value, &size);
} else { } else {
r = read_db_value((const char*)key.c_str(), &value, &size); r = read_db_value((const char*)key.c_str(), &value, &size);