Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for sm.c #695

Merged
merged 5 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ CC_CHECK_FLAGS_APPEND([AM_CFLAGS],[CFLAGS],[ \
-Wdate-time \
-Wnested-externs \
-Wconversion \
-Wno-format-nonliteral \
-Werror \
])
# To enable:
Expand Down
19 changes: 16 additions & 3 deletions src/lib/sm.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,27 @@

static inline void sm_obs(const struct sm *m)
{
tracef("%s pid: %d sm_id: %" PRIu64 " %s |\n",
tracef("%s pid: %d sm_id: %" PRIu64 " %s |",
m->name, m->pid, m->id, m->conf[sm_state(m)].name);
}

void sm_relate(const struct sm *from, const struct sm *to)
{
tracef("%s-to-%s opid: %d dpid: %d id: %" PRIu64 " id: %" PRIu64 " |\n",
tracef("%s-to-%s opid: %d dpid: %d id: %" PRIu64 " id: %" PRIu64 " |",
from->name, to->name, from->pid, to->pid, from->id, to->id);
}

void sm_attr(const struct sm *m, const char *k, const char *fmt, ...)

Check warning on line 35 in src/lib/sm.c

View check run for this annotation

Codecov / codecov/patch

src/lib/sm.c#L35

Added line #L35 was not covered by tests
{
char v[SM_MAX_ATTR_LENGTH];
va_list ap;
va_start(ap, fmt);
vsnprintf(v, sizeof(v), fmt, ap);
va_end(ap);

Check warning on line 41 in src/lib/sm.c

View check run for this annotation

Codecov / codecov/patch

src/lib/sm.c#L37-L41

Added lines #L37 - L41 were not covered by tests
tracef("%s-attr pid: %d sm_id: %" PRIu64 " %s %s |",
m->name, m->pid, m->id, k, v);
}

void sm_init(struct sm *m,
bool (*invariant)(const struct sm *, int),
bool (*is_locked)(const struct sm *),
Expand All @@ -49,6 +60,7 @@
m->is_locked = is_locked;
m->id = ++id;
m->pid = getpid();
m->rc = 0;
snprintf(m->name, SM_MAX_NAME_LENGTH, "%s", name);
sm_obs(m);

Expand Down Expand Up @@ -82,12 +94,13 @@

m->rc = rc;
m->state = fail_state;
sm_obs(m);
POST(m->invariant != NULL && m->invariant(m, prev));
}

static __attribute__((noinline)) bool check_failed(const char *f, int n, const char *s)
{
tracef("%s:%d check failed: %s\n", f, n, s);
tracef("%s:%d check failed: %s", f, n, s);
return false;
}

Expand Down
5 changes: 5 additions & 0 deletions src/lib/sm.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define CHECK(cond) sm_check((cond), __FILE__, __LINE__, #cond)

#define SM_MAX_NAME_LENGTH 50
#define SM_MAX_ATTR_LENGTH 100

enum {
SM_PREV_NONE = -1,
Expand Down Expand Up @@ -54,5 +55,9 @@ int sm_state(const struct sm *m);
bool sm_check(bool b, const char *f, int n, const char *s);
/* Relates one state machine to another for observability. */
void sm_relate(const struct sm *from, const struct sm *to);
/**
* Records an attribute of a state machine for observability.
*/
void sm_attr(const struct sm *m, const char *k, const char *fmt, ...);

#endif /* __LIB_SM__ */
3 changes: 0 additions & 3 deletions src/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ void loggerDefaultEmit(void *data, int level, const char *fmt, va_list args)

/* Then render the message, possibly truncating it. */
n = EMIT_BUF_LEN - strlen(buf) - 1;
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
vsnprintf(cursor, n, fmt, args);
#pragma GCC diagnostic pop

fprintf(stderr, "%s\n", buf);
}
3 changes: 0 additions & 3 deletions test/lib/logger.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,7 @@ void test_logger_emit(void *data, int level, const char *format, va_list args)

sprintf(buf + strlen(buf), "%2d -> [%s] ", t->id, level_name);

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wformat-nonliteral"
vsnprintf(buf + strlen(buf), 1024 - strlen(buf), format, args);
#pragma GCC diagnostic pop
munit_log(MUNIT_LOG_INFO, buf);
return;

Expand Down
Loading