-
Notifications
You must be signed in to change notification settings - Fork 1
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
Use __maybe_unused
compiler attribute to fix flakey code-coverage in test_edgesec
#432
Conversation
Add the `__maybe_unused` attribute, which prevents warnings when a variable is unused (e.g. if we use the variable only if a given `#ifdef X` is set). In the edgesec project, we normally use a cast to `(void)` to do the same thing, e.g. `(void)my_var;`, but code taken from hostap uses `__maybe_unused`. This is equivalent to the C23 attribute [`[[maybe_unused]]`][1]. [1]: https://en.cppreference.com/w/c/language/attributes/maybe_unused
Add a CMake INTERFACE/header-only library for `src/radius/common.h`
Add `./src/utils/attributes.h` header file for compiler attributes. For example, `__attribute__((unused))` is supported on GCC and Clang, but on other compilers, this is not supported. Most of these are already in `src/radius/common.h`, so we just need to move them into a new file to use them in the rest of the edgesec code.
Move `__maybe_unused` from the `src/radius/common.h` file into `src/utils/attributes.h`, so that we can use it in the rest of the edgesec project.
Use the `__maybe_unused` compiler attribute to mark unused function parameters in `tests/test_edgesec.c` as unused, instead of `(void)`. For some reason, code coverage sometimes thinks that `(void)` lines are not covered by tests. Using `__maybe_unused` instead should fix this issue.
Codecov Report
@@ Coverage Diff @@
## main #432 +/- ##
==========================================
+ Coverage 53.09% 53.14% +0.04%
==========================================
Files 144 144
Lines 19876 19897 +21
==========================================
+ Hits 10553 10574 +21
Misses 9323 9323
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great.
We should also add https://github.com/nqminds/edgesec/blob/main/src/utils/os.h#L36 i.e.,
__attribute__((packed))
to the attributes.h
file.
Move the `#define STRUCT_PACKED __attribute__((packed))` from `src/utils/os.h` into `src/utils/attributes.h`. Co-authored-by: Alexandru Mereacre <mereacre@gmail.com>
Good idea, I've done it in f770f44 |
For some reason, these lines are sometimes not run by tests, and because of that, we get a code-coverage warning:
edgesec/tests/test_edgesec.c
Lines 44 to 45 in 9b53dea
I would have thought that these no-op statements are optimized out, even when compiling in debug mode, but I guess sometimes they are kept in?
To fix this, I've taken the
__maybe_unused
macro from PR #380 and stuck it in a new file calledsrc/utils/attributes.h
, which we can use for compiler attributes.(C23 has built-in support for attributes like
[[maybe_unused]]
, but since we're not using that, we're stuck with doing complicated compiler-specific checks in massive header files)