diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index a266986..3d3dd2f 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 @@ -103,12 +103,41 @@ 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 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 with: submodules: false - name: Fail on all warnings 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); 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); 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); 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; } 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; } 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); 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++) { 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);