Skip to content

Commit

Permalink
setup clang tidy (#19533)
Browse files Browse the repository at this point in the history
* setup clang tidy

* config

* some cleanup

* little more

* remove that

* fix qcom build
  • Loading branch information
adeebshihadeh authored Jan 5, 2021
1 parent bd8fbe1 commit 87950eb
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 27 deletions.
19 changes: 19 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ a.out
*.vcd
config.json
clcache
compile_commands.json

persist
board/obj/
Expand Down
6 changes: 5 additions & 1 deletion SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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'):
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/boardd/boardd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -94,7 +94,7 @@ void safety_setter_thread() {

std::vector<char> params;
LOGW("waiting for params to set safety model");
while (1) {
while (true) {
if (do_exit || !panda->connected){
safety_setter_thread_running = false;
return;
Expand Down
4 changes: 2 additions & 2 deletions selfdrive/boardd/pigeon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions selfdrive/camerad/cameras/camera_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
10 changes: 3 additions & 7 deletions selfdrive/camerad/cameras/camera_qcom.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -534,8 +533,6 @@ static void imx298_ois_calibration(int ois_fd, uint8_t* eeprom) {
}




static void sensors_init(MultiCameraState *s) {
int err;

Expand Down Expand Up @@ -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){
Expand Down Expand Up @@ -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; i<METADATA_BUF_COUNT; i++) {
if (s->frame_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);
Expand Down
20 changes: 10 additions & 10 deletions selfdrive/camerad/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -215,12 +215,12 @@ void* visionserver_client_thread(void* arg) {

LOGW("client end fd %d", fd);

for (int i=0; i<VISION_STREAM_MAX; i++) {
if (!streams[i].subscribed) continue;
if (streams[i].tb) {
tbuffer_release_all(streams[i].tbuffer);
for (auto &stream : streams) {
if (!stream.subscribed) continue;
if (stream.tb) {
tbuffer_release_all(stream.tbuffer);
} else {
pool_release_queue(streams[i].queue);
pool_release_queue(stream.queue);
}
}

Expand Down Expand Up @@ -286,12 +286,12 @@ void* visionserver_thread(void* arg) {
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);
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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion selfdrive/common/params.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 87950eb

Please sign in to comment.