From 54be1ea4e878b6e2942868e32d2dd8f671acc31d Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 15:52:54 -0600 Subject: [PATCH 01/10] github: Use the latest version of the checkout action Update the Github Actions to use the latest version, @v4, of the checkout action. Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- .github/workflows/continuous-integration.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a266986..8c0052e 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -40,7 +40,7 @@ jobs: pull-requests: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: Differential ShellCheck @@ -54,7 +54,7 @@ jobs: runs-on: ubuntu-latest steps: - name: Check out source repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Set up Python environment uses: actions/setup-python@v4 with: @@ -76,7 +76,7 @@ jobs: steps: - name: 'Calculate PR commits + 1' run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> $GITHUB_ENV - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: ref: ${{ github.event.pull_request.head.sha }} fetch-depth: ${{ env.PR_FETCH_DEPTH }} @@ -90,7 +90,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: false - name: Initialize the directory @@ -108,7 +108,7 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: false - name: Fail on all warnings From 1e9e188637adff95b1a012dd99e629ccfcf98eee Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:04:52 -0600 Subject: [PATCH 02/10] adaptived: shared_data: Fix clang warning Fix the following clang warning by declaring this variable at the start of the function: shared_data.c:218:4: warning: label followed by a declaration is a C23 extension [-Wc23-extensions] 218 | struct adaptived_name_and_value *name_value; | ^ Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/src/shared_data.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/adaptived/src/shared_data.c b/adaptived/src/shared_data.c index c20bc09..ac25378 100644 --- a/adaptived/src/shared_data.c +++ b/adaptived/src/shared_data.c @@ -177,6 +177,7 @@ API int adaptived_get_shared_data(const struct adaptived_cause * const cse, int API void free_shared_data(struct adaptived_cause * const cse, bool force_delete) { struct shared_data *cur, *next, *prev_valid = NULL, *first_valid = NULL; + struct adaptived_name_and_value *name_value; bool do_free, persist; if (cse == NULL) @@ -215,8 +216,6 @@ API void free_shared_data(struct adaptived_cause * const cse, bool force_delete) free(cur->data); break; case ADAPTIVED_SDATA_NAME_VALUE: - struct adaptived_name_and_value *name_value; - name_value = (struct adaptived_name_and_value *)cur->data; free(name_value->name); From ef5ca9ef2b9b87d46e25dc129f4c3bade72cb7e6 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:07:00 -0600 Subject: [PATCH 03/10] adaptived: utils: Fix clang warnings Fix the following clang warnings by moving the trailing ")" to the correct location: utils/cgroup_utils.c:238:61: warning: size argument in 'strncmp' call is a comparison [-Wmemsize-comparison] 238 | strncmp(validate_value, value, strlen(validate_value) != 0)) { | ~~~~~~~~~~~~~~~~~~~~~~~^~~~ utils/cgroup_utils.c:238:7: note: did you mean to compare the result of 'strncmp' instead? 238 | strncmp(validate_value, value, strlen(validate_value) != 0)) { | ^ ~ | ) utils/cgroup_utils.c:238:38: note: explicitly cast the argument to size_t to silence this warning 238 | strncmp(validate_value, value, strlen(validate_value) != 0)) { | ^ | (size_t)( ) Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/src/utils/cgroup_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adaptived/src/utils/cgroup_utils.c b/adaptived/src/utils/cgroup_utils.c index b6583dc..5eb5c2c 100644 --- a/adaptived/src/utils/cgroup_utils.c +++ b/adaptived/src/utils/cgroup_utils.c @@ -235,7 +235,7 @@ API int adaptived_cgroup_set_str(const char * const setting, const char * const return ret; if (strlen(validate_value) != strlen(value) || - strncmp(validate_value, value, strlen(validate_value) != 0)) { + strncmp(validate_value, value, strlen(validate_value)) != 0) { adaptived_err("Failed to validate %s. Expected %s, read %s\n", setting, value, validate_value); free(validate_value); From 8f9fb64eb751d98da0553464e8e354941f1354dc Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:08:41 -0600 Subject: [PATCH 04/10] adaptived: utils: Fix clang warnings Fix the following clang warnings by moving the trailing ")" to the correct location: utils/sd_bus_utils.c:448:62: warning: size argument in 'strncmp' call is a comparison [-Wmemsize-comparison] 448 | strncmp(validate_value, value, strlen(validate_value) != 0)) { | ~~~~~~~~~~~~~~~~~~~~~~~^~~~ utils/sd_bus_utils.c:448:8: note: did you mean to compare the result of 'strncmp' instead? 448 | strncmp(validate_value, value, strlen(validate_value) != 0)) { | ^ ~ | ) utils/sd_bus_utils.c:448:39: note: explicitly cast the argument to size_t to silence this warning 448 | strncmp(validate_value, value, strlen(validate_value) != 0)) { | ^ | (size_t)( ) Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/src/utils/sd_bus_utils.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adaptived/src/utils/sd_bus_utils.c b/adaptived/src/utils/sd_bus_utils.c index f2a6405..3dd8bf6 100644 --- a/adaptived/src/utils/sd_bus_utils.c +++ b/adaptived/src/utils/sd_bus_utils.c @@ -445,7 +445,7 @@ API int adaptived_sd_bus_set_str(const char * const target, const char * const p return -EFAULT; } if (strlen(validate_value) != strlen(value) || - strncmp(validate_value, value, strlen(validate_value) != 0)) { + strncmp(validate_value, value, strlen(validate_value)) != 0) { adaptived_err("Failed to validate %s. Expected %s, read %s\n", property, value, validate_value); free(validate_value); From 13959fa4fe0144f1e7af4982783bc44d75b1b1c9 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:27:31 -0600 Subject: [PATCH 05/10] adaptived: ftests: Fix clang warning Fix uninitialized usage warning for the ctx variable: 015-load_rule_at_runtime.c:116:6: warning: variable 'ctx' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] 116 | if (ret) | ^~~ 015-load_rule_at_runtime.c:180:24: note: uninitialized use occurs here 180 | adaptived_unload_rule(ctx, rule_name); | ^~~ Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/tests/ftests/015-load_rule_at_runtime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/adaptived/tests/ftests/015-load_rule_at_runtime.c b/adaptived/tests/ftests/015-load_rule_at_runtime.c index 7aebb51..3c03e6e 100644 --- a/adaptived/tests/ftests/015-load_rule_at_runtime.c +++ b/adaptived/tests/ftests/015-load_rule_at_runtime.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) struct adaptived_cause *cse; struct adaptived_rule *rule; pthread_t adaptived_thread; - struct adaptived_ctx *ctx; + struct adaptived_ctx *ctx = NULL; char *time_str = NULL; void *tret; int ret; @@ -177,8 +177,10 @@ int main(int argc, char *argv[]) adaptived_release_effect(&eff); adaptived_release_rule(&rule); - adaptived_unload_rule(ctx, rule_name); - adaptived_release(&ctx); + if (ctx) { + adaptived_unload_rule(ctx, rule_name); + adaptived_release(&ctx); + } return AUTOMAKE_HARD_ERROR; } From 071bc881ad577a0732feaac30a88af41c12a6b14 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:29:08 -0600 Subject: [PATCH 06/10] adaptived: ftests: Fix clang warning Fix uninitialized usage for the ctx variable: 016-unload_rule_at_runtime.c:119:6: warning: variable 'ctx' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] 119 | if (ret) | ^~~ 016-unload_rule_at_runtime.c:190:24: note: uninitialized use occurs here 190 | adaptived_unload_rule(ctx, rule_name); | ^~~ Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/tests/ftests/016-unload_rule_at_runtime.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/adaptived/tests/ftests/016-unload_rule_at_runtime.c b/adaptived/tests/ftests/016-unload_rule_at_runtime.c index 186cf2f..7d586df 100644 --- a/adaptived/tests/ftests/016-unload_rule_at_runtime.c +++ b/adaptived/tests/ftests/016-unload_rule_at_runtime.c @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) struct adaptived_cause *cse; struct adaptived_rule *rule; pthread_t adaptived_thread; - struct adaptived_ctx *ctx; + struct adaptived_ctx *ctx = NULL; char *time_str = NULL; void *tret; int ret; @@ -187,8 +187,10 @@ int main(int argc, char *argv[]) adaptived_release_effect(&eff); adaptived_release_rule(&rule); - adaptived_unload_rule(ctx, rule_name); - adaptived_release(&ctx); + if (ctx) { + adaptived_unload_rule(ctx, rule_name); + adaptived_release(&ctx); + } return AUTOMAKE_HARD_ERROR; } From 0a0f19edd529830b0f6f247f3fc28bfcd087997b Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:36:43 -0600 Subject: [PATCH 07/10] adaptived: ftests: Fix clang warning Fix the following clang warning by initializing cse to NULL: 018-effect-cgroup_setting_set_str.c:95:6: warning: variable 'cse' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized] 95 | if (!rule) | ^~~~~ 018-effect-cgroup_setting_set_str.c:154:6: note: uninitialized use occurs here 154 | if (cse) | ^~~ Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/tests/ftests/018-effect-cgroup_setting_set_str.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adaptived/tests/ftests/018-effect-cgroup_setting_set_str.c b/adaptived/tests/ftests/018-effect-cgroup_setting_set_str.c index 56e7259..9c70b30 100644 --- a/adaptived/tests/ftests/018-effect-cgroup_setting_set_str.c +++ b/adaptived/tests/ftests/018-effect-cgroup_setting_set_str.c @@ -66,7 +66,7 @@ int main(int argc, char *argv[]) struct adaptived_effect *eff = NULL; struct adaptived_rule *rule = NULL; struct adaptived_ctx *ctx = NULL; - struct adaptived_cause *cse; + struct adaptived_cause *cse = NULL; int ret; ctx = adaptived_init(NULL); From bdb187463ab59c85d99c5be9ac62893fba58e0f7 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:39:29 -0600 Subject: [PATCH 08/10] adaptived: gtests: Fix clang warning Fix clang warning in test 011 where the initialization to NULL of an array of structs was ambiguous. 011-kill_processes_sort.cpp:66:39: warning: suggest braces around initialization of subobject [-Wmissing-braces] 66 | struct pid_info pida[array_size] = { 0 }; | ^ | {} Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/tests/gunit/011-kill_processes_sort.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/adaptived/tests/gunit/011-kill_processes_sort.cpp b/adaptived/tests/gunit/011-kill_processes_sort.cpp index b500508..5e23b44 100644 --- a/adaptived/tests/gunit/011-kill_processes_sort.cpp +++ b/adaptived/tests/gunit/011-kill_processes_sort.cpp @@ -63,7 +63,7 @@ class SortPidListTest : public ::testing::Test { TEST_F(SortPidListTest, Sort) { - struct pid_info pida[array_size] = { 0 }; + struct pid_info pida[array_size] = { { 0 } }; int i; for (i = 0; i < array_size; i++) { From ff6a3bf2872e7eac2d10d82acf63a055e961e899 Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 16:43:50 -0600 Subject: [PATCH 09/10] adaptived: gunit: Fix clang warning Fix the following clang warning by explicitly initializing the type variable: 012-shared_data.cpp:133:46: warning: variable 'type' is uninitialized when used here [-Wuninitialized] 133 | ret = adaptived_update_shared_data(&cse, 0, type, &read_data, 0); | ^~~~ 012-shared_data.cpp:125:2: note: variable 'type' is declared here 125 | enum adaptived_sdata_type type; | ^ Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- adaptived/tests/gunit/012-shared_data.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/adaptived/tests/gunit/012-shared_data.cpp b/adaptived/tests/gunit/012-shared_data.cpp index 7e29f95..f788684 100644 --- a/adaptived/tests/gunit/012-shared_data.cpp +++ b/adaptived/tests/gunit/012-shared_data.cpp @@ -130,6 +130,7 @@ TEST_F(SharedDataTest, CustomDataShare) populate_cause(&cse, 0); + type = ADAPTIVED_SDATA_STR; ret = adaptived_update_shared_data(&cse, 0, type, &read_data, 0); ASSERT_EQ(ret, -ERANGE); From 6e083653ffc8c788a15e17276d732a6a70d6828e Mon Sep 17 00:00:00 2001 From: Tom Hromatka Date: Wed, 30 Jul 2025 15:55:23 -0600 Subject: [PATCH 10/10] github: Add job to build adaptived with clang Add a Github Actions job to build adaptived using clang. Signed-off-by: Tom Hromatka Reviewed-by: Sidhartha Kumar --- .github/workflows/continuous-integration.yml | 29 ++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index 8c0052e..3d3dd2f 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -103,6 +103,35 @@ jobs: cat adaptived/adaptived-*/_build/sub/tests/ftests/ftests-wrapper.sh.log cat adaptived/adaptived-*/_build/sub/tests/ftests/ftests-c-wrapper.sh.log + build-with-clang: + name: Build with Clang + runs-on: ubuntu-latest + env: + CC: clang + CXX: clang++ + steps: + - uses: actions/checkout@v4 + with: + submodules: false + - name: Fail on all warnings + run: | + CFLAGS=-Werror + export CFLAGS + - name: Install Dependencies + run: | + while sudo fuser /var/{lib/{dpkg,apt/lists},cache/apt/archives}/lock >/dev/null 2>&1; do sleep 3; done + sudo apt-get update + sudo apt-get install libjson-c-dev lcov cmake bison flex autoconf automake libtool libsystemd-dev clang -y + - name: Build adaptived + run: cd adaptived && ./autogen.sh && ./configure && make check-build + - name: Run functional tests + run: cd adaptived && make check + - name: Display test logs + if: ${{ always() }} + run: | + cat adaptived/tests/ftests/ftests-wrapper.sh.log + cat adaptived/tests/ftests/ftests-c-wrapper.sh.log + functional_tests_cgv2: name: Adaptived Functional Tests v2 runs-on: ubuntu-latest