Skip to content

Commit

Permalink
fix(tests): use GCOVR_EXCL_BR_LINE on HASH_ macros
Browse files Browse the repository at this point in the history
  • Loading branch information
dfranusic committed Oct 13, 2023
1 parent 6b86d6f commit 88c7a1a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
22 changes: 13 additions & 9 deletions src/services/sysagent/plugins/mqtt/plg_sysagent_mqtt.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ mqtt_bin_upl_add(const char *path, size_t fsz)
char uuid_str[37];
uuid_unparse_lower(uuid, uuid_str);
// check for uuid
HASH_FIND_STR(bin_uploads, uuid_str, f);
HASH_FIND_STR(bin_uploads, uuid_str, f); // GCOVR_EXCL_BR_LINE
if (f != NULL) {
pthread_mutex_unlock(&bin_upl_mtx);
return NULL;
Expand All @@ -231,7 +231,7 @@ mqtt_bin_upl_add(const char *path, size_t fsz)
memcpy(f->uuid, uuid_str, sizeof(uuid_str));
f->ts = time(NULL);
f->size = fsz;
HASH_ADD_STR(bin_uploads, uuid, f);
HASH_ADD_STR(bin_uploads, uuid, f); // GCOVR_EXCL_BR_LINE

pthread_mutex_unlock(&bin_upl_mtx);
return f;
Expand All @@ -247,13 +247,13 @@ mqtt_bin_upl_del(const char *uuid)
pthread_mutex_lock(&bin_upl_mtx);

// check for uuid
HASH_FIND_STR(bin_uploads, uuid, f);
HASH_FIND_STR(bin_uploads, uuid, f); // GCOVR_EXCL_BR_LINE
if (f == NULL) {
pthread_mutex_unlock(&bin_upl_mtx);
return 1;
}
// remove
HASH_DEL(bin_uploads, f);
HASH_DEL(bin_uploads, f); // GCOVR_EXCL_BR_LINE
free(f);

pthread_mutex_unlock(&bin_upl_mtx);
Expand Down Expand Up @@ -320,7 +320,7 @@ mqtt_handle_bin(const char *tpc, const MQTTAsync_message *msg)
}

mqtt_file_d_t *f = NULL;
HASH_FIND_STR(bin_uploads, file_uuid, f);
HASH_FIND_STR(bin_uploads, file_uuid, f); // GCOVR_EXCL_BR_LINE
if (f == NULL) {
umd_log(UMD,
UMD_LLT_ERROR,
Expand Down Expand Up @@ -416,7 +416,7 @@ mqtt_bin_cleanup()
HASH_ITER(hh, bin_uploads, f, f_tmp)
{
if (now - f->ts > SIG_SEM_TIMEOUT) {
HASH_DEL(bin_uploads, f);
HASH_DEL(bin_uploads, f); // GCOVR_EXCL_BR_LINE
// create file path str
char fp[strlen(f->path) + strlen(f->uuid) + 6];
gen_temp_fname(f, fp);
Expand Down Expand Up @@ -659,7 +659,9 @@ mqtt_mngr_add_conn(struct mqtt_conn_mngr *m,
}
// label should not be present
struct mqtt_conn_d *tmp_conn = NULL;
// GCOVR_EXCL_BR_START
HASH_FIND_STR(m->conns, json_object_get_string(j_name), tmp_conn);
// GCOVR_EXCL_BR_STOP
if (tmp_conn != NULL) {
return NULL;
}
Expand Down Expand Up @@ -694,7 +696,9 @@ mqtt_mngr_add_conn(struct mqtt_conn_mngr *m,
// lock
pthread_mutex_lock(&m->mtx);
// add to conn list
// GCOVR_EXCL_BR_START
HASH_ADD_KEYPTR(hh, m->conns, c->name, strlen(c->name), c);
// GCOVR_EXCL_BR_STOP
// unlock
pthread_mutex_unlock(&m->mtx);
// return new conn
Expand Down Expand Up @@ -724,12 +728,12 @@ mqtt_mngr_del_conn(struct mqtt_conn_mngr *m, const char *name, bool th_safe)
if (th_safe) {
pthread_mutex_lock(&m->mtx);
}
HASH_FIND_STR(m->conns, name, tmp_conn);
HASH_FIND_STR(m->conns, name, tmp_conn); // GCOVR_EXCL_BR_LINE
if (tmp_conn != NULL) {
pthread_join(tmp_conn->sig_th, NULL);
sem_destroy(&tmp_conn->sig_sem);
spscq_free(tmp_conn->sig_q);
HASH_DEL(m->conns, tmp_conn);
HASH_DEL(m->conns, tmp_conn); // GCOVR_EXCL_BR_LINE
MQTTAsync_destroy(&tmp_conn->client);
free(tmp_conn->name);
utarray_free(tmp_conn->topics);
Expand Down Expand Up @@ -782,7 +786,7 @@ mqtt_mngr_get_conn(struct mqtt_conn_mngr *m, const char *name)
struct mqtt_conn_d *tmp_conn = NULL;
// lock
pthread_mutex_lock(&m->mtx);
HASH_FIND_STR(m->conns, name, tmp_conn);
HASH_FIND_STR(m->conns, name, tmp_conn); // GCOVR_EXCL_BR_LINE
// unlock
pthread_mutex_unlock(&m->mtx);
return tmp_conn;
Expand Down
12 changes: 7 additions & 5 deletions src/services/sysagent/umlua.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ lenvm_get_envd(struct lua_env_mngr *lem, const char *n)
pthread_mutex_lock(&lem->mtx);
// find env
struct lua_env_d *env = NULL;
HASH_FIND_STR(lem->envs, n, env);
HASH_FIND_STR(lem->envs, n, env); // GCOVR_EXCL_BR_LINE
// unlock
pthread_mutex_unlock(&lem->mtx);
// return env
Expand All @@ -142,9 +142,9 @@ lenvm_del_envd(struct lua_env_mngr *lem, const char *n, bool th_safe)
}
// find env
struct lua_env_d *env = NULL;
HASH_FIND_STR(lem->envs, n, env);
HASH_FIND_STR(lem->envs, n, env); // GCOVR_EXCL_BR_LINE
if (env != NULL) {
HASH_DEL(lem->envs, env);
HASH_DEL(lem->envs, env); // GCOVR_EXCL_BR_LINE
}
// unlock
if (th_safe) {
Expand All @@ -161,9 +161,11 @@ lenvm_new_envd(struct lua_env_mngr *lem, struct lua_env_d *env)
pthread_mutex_lock(&lem->mtx);
// find env
struct lua_env_d *tmp_env = NULL;
HASH_FIND_STR(lem->envs, env->name, tmp_env);
HASH_FIND_STR(lem->envs, env->name, tmp_env); // GCOVR_EXCL_BR_LINE
if (tmp_env == NULL) {
// GCOVR_EXCL_BR_START
HASH_ADD_KEYPTR(hh, lem->envs, env->name, strlen(env->name), env);
// GCOVR_EXCL_BR_STOP
tmp_env = env;
}
// unlock
Expand All @@ -179,7 +181,7 @@ lenvm_envd_exists(struct lua_env_mngr *lem, const char *n)
pthread_mutex_lock(&lem->mtx);
// find env
struct lua_env_d *tmp_env = NULL;
HASH_FIND_STR(lem->envs, n, tmp_env);
HASH_FIND_STR(lem->envs, n, tmp_env); // GCOVR_EXCL_BR_LINE
// unlock
pthread_mutex_unlock(&lem->mtx);
return (tmp_env != NULL);
Expand Down
8 changes: 4 additions & 4 deletions src/utils/umcounters.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ umc_free_ctx(umc_ctx_t *ctx)
pthread_mutex_lock(&ctx->mtx);
HASH_ITER(hh, ctx->counters, c, tmp)
{
HASH_DEL(ctx->counters, c);
HASH_DEL(ctx->counters, c); // GCOVR_EXCL_BR_BR_LINE
pthread_mutex_destroy(&c->mtx);
free(c);
}
Expand All @@ -60,7 +60,7 @@ umc_new_counter(umc_ctx_t *ctx, const char *id, enum umc_type type)

pthread_mutex_lock(&ctx->mtx);

HASH_FIND_STR(ctx->counters, id, c);
HASH_FIND_STR(ctx->counters, id, c); // GCOVR_EXCL_BR_LINE
if (c != NULL) {
pthread_mutex_unlock(&ctx->mtx);
return c;
Expand All @@ -72,7 +72,7 @@ umc_new_counter(umc_ctx_t *ctx, const char *id, enum umc_type type)
c->idp = c->id;
c->type = type;
pthread_mutex_init(&c->mtx, NULL);
HASH_ADD_STR(ctx->counters, id, c);
HASH_ADD_STR(ctx->counters, id, c); // GCOVR_EXCL_BR_LINE

pthread_mutex_unlock(&ctx->mtx);

Expand All @@ -91,7 +91,7 @@ umc_get(umc_ctx_t *ctx, const char *id, bool lock)
pthread_mutex_lock(&ctx->mtx);
}

HASH_FIND_STR(ctx->counters, id, c);
HASH_FIND_STR(ctx->counters, id, c); // GCOVR_EXCL_BR_LINE

if (lock) {
pthread_mutex_unlock(&ctx->mtx);
Expand Down

0 comments on commit 88c7a1a

Please sign in to comment.