eBPF-based security platform
testing: follow the kernel coding style in the helpers
Daniel Borkmannb746fe27ba25
diff --git a/testing/fixtures/uprobe-multi.bpf.c b/testing/fixtures/uprobe-multi.bpf.cindex f3893938..abad86d2 100644--- a/testing/fixtures/uprobe-multi.bpf.c+++ b/testing/fixtures/uprobe-multi.bpf.c@@ -16,6 +16,7 @@ int probe(struct pt_regs *ctx){__u32 key = 0;__u64 *value = bpf_map_lookup_elem(&hits, &key);+if (value)__sync_fetch_and_add(value, 1);return 0;diff --git a/testing/helper/test-bpf-cmd.c b/testing/helper/test-bpf-cmd.cindex a1534a6b..ad0d5aad 100644--- a/testing/helper/test-bpf-cmd.c+++ b/testing/helper/test-bpf-cmd.c@@ -58,9 +58,10 @@ int main(int argc, char **argv)argv[0]);return 2;}- for (i = 0; i < ARRAY_SIZE(cmds); i++)+ for (i = 0; i < ARRAY_SIZE(cmds); i++) {if (strcmp(cmds[i].name, argv[1]) == 0)break;+ }if (i == ARRAY_SIZE(cmds)) {fprintf(stderr, "%s: unknown command %s\n", argv[0], argv[1]);return 2;diff --git a/testing/helper/test-bpm-source.c b/testing/helper/test-bpm-source.cindex bebdd346..b4a8eafe 100644--- a/testing/helper/test-bpm-source.c+++ b/testing/helper/test-bpm-source.c@@ -21,8 +21,8 @@ int main(void)sizeof(endpoint), key_file,sizeof(key_file)) ||shirudo_bpm_parse_source_line(key_file_line, endpoint,- sizeof(endpoint), key_file,- sizeof(key_file)))+ sizeof(endpoint), key_file,+ sizeof(key_file)))return 1;if (strcmp(endpoint, "oci://registry.test:5443") ||strcmp(key_file, "/etc/shirudo/bpm/keys/jbrust.pem"))diff --git a/testing/helper/test-exec-churn.c b/testing/helper/test-exec-churn.cindex b4f1bd57..8d5feedb 100644--- a/testing/helper/test-exec-churn.c+++ b/testing/helper/test-exec-churn.c@@ -1,5 +1,5 @@// SPDX-License-Identifier: BSD-2-Clause-// Copyright (c) 2026 Authors of shirudo+/* Copyright (c) 2026 Authors of shirudo */#include <errno.h>#include <inttypes.h>@@ -98,7 +98,7 @@ int main(int argc, char **argv)return 2;start = monotonic_ns();if (!start || duration_sec > UINT64_MAX / UINT64_C(1000000000) ||- start > UINT64_MAX - duration_sec * UINT64_C(1000000000))+ start > UINT64_MAX - duration_sec * UINT64_C(1000000000))return 1;deadline = start + duration_sec * UINT64_C(1000000000);if (pipe(result_fd) != 0)diff --git a/testing/helper/test-kernel-release.c b/testing/helper/test-kernel-release.cindex 61b511dc..624c25c8 100644--- a/testing/helper/test-kernel-release.c+++ b/testing/helper/test-kernel-release.c@@ -4,6 +4,7 @@#include <stdio.h>#include "util/kernel_release.h"+#include "util/macros.h"struct test_case {const char *release;@@ -24,9 +25,11 @@ int main(void){ "6.1.0", NULL, 0 },};- for (size_t i = 0; i < sizeof(cases) / sizeof(cases[0]); i++) {- int matches = shirudo_kernel_release_prefix_matches(- cases[i].release, cases[i].prefix);+ for (size_t i = 0; i < ARRAY_SIZE(cases); i++) {+ int matches;++ matches = shirudo_kernel_release_prefix_matches(cases[i].release,+ cases[i].prefix);if (matches != cases[i].matches) {fprintf(stderr, "case %zu: unexpected match result %d\n",diff --git a/testing/helper/test-otel-map.c b/testing/helper/test-otel-map.cindex 730996ae..1ccecac7 100644--- a/testing/helper/test-otel-map.c+++ b/testing/helper/test-otel-map.c@@ -156,7 +156,7 @@ static int fixture_init(struct fixture *f, uint32_t map_type, bool is_signed,snprintf(f->view.upatch, sizeof(f->view.upatch), "test-upatch");snprintf(f->view.name, sizeof(f->view.name), "hits_total");snprintf(f->view.location, sizeof(f->view.location),- "fentry/test_hook");+ "fentry/test_hook");f->view.type = map_type;f->view.type_name = map_type == BPF_MAP_TYPE_ARRAY ? "array" :"percpu_array";@@ -180,11 +180,11 @@ static int fixture_init(struct fixture *f, uint32_t map_type, bool is_signed,return -ENOMEM;key_int = btf__add_int(f->btf, "unsigned int", 4, 0);value_int = btf__add_int(f->btf,- is_signed ? "int" : "unsigned int", 4,- is_signed ? BTF_INT_SIGNED : 0);+ is_signed ? "int" : "unsigned int", 4,+ is_signed ? BTF_INT_SIGNED : 0);key_type = btf__add_typedef(f->btf, "__u32", key_int);value_type = btf__add_typedef(f->btf,- is_signed ? "__s32" : "__u32", value_int);+ is_signed ? "__s32" : "__u32", value_int);if (key_int < 0 || value_int < 0 || key_type < 0 || value_type < 0)return -EINVAL;f->view.btf = f->btf;@@ -192,7 +192,7 @@ static int fixture_init(struct fixture *f, uint32_t map_type, bool is_signed,f->view.value_type_id = (uint32_t)value_type;snprintf(f->view.btf_key_type, sizeof(f->view.btf_key_type), "__u32");snprintf(f->view.btf_value_type, sizeof(f->view.btf_value_type), "%s",- is_signed ? "__s32" : "__u32");+ is_signed ? "__s32" : "__u32");return 0;}@@ -241,12 +241,15 @@ static int print_payload(bool metric, bool counter, bool with_location)if (!with_location)f.view.location[0] = '\0';rc = make_decoder(metric, counter, false, decoder_path,- sizeof(decoder_path));- if (!rc)- rc = metric ? shirudo_upatch_maps_otel_build_metric_file(- decoder_path, &f.view, &opts, &buf, &len) :- shirudo_upatch_maps_otel_build_log_file(decoder_path, &f.view,+ sizeof(decoder_path));+ if (!rc && metric)+ rc = shirudo_upatch_maps_otel_build_metric_file(decoder_path,+ &f.view, &opts,&buf, &len);+ else if (!rc)+ rc = shirudo_upatch_maps_otel_build_log_file(decoder_path,+ &f.view, &buf,+ &len);if (!rc && buf)fwrite(buf, 1, len, stdout);if (buf)@@ -291,7 +294,7 @@ static int send_log(const char *url, unsigned int retries, bool insecure)if (rc)return 1;rc = make_decoder(false, false, false, decoder_path,- sizeof(decoder_path));+ sizeof(decoder_path));if (!rc)rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,SHIRUDO_OTEL_FORCE_LOG, &opts);@@ -311,7 +314,7 @@ static int send_auto(const char *base, bool is_signed)if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, is_signed, true))return 1;rc = make_decoder(!is_signed, !is_signed, false, decoder_path,- sizeof(decoder_path));+ sizeof(decoder_path));if (!rc)rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,SHIRUDO_OTEL_AUTO, &opts);@@ -336,7 +339,7 @@ static int send_metric(const char *url)if (fixture_init(&f, BPF_MAP_TYPE_PERCPU_ARRAY, false, true))return 1;rc = make_decoder(true, false, false, decoder_path,- sizeof(decoder_path));+ sizeof(decoder_path));if (!rc)rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,SHIRUDO_OTEL_FORCE_METRIC, &opts);@@ -416,7 +419,7 @@ static int send_s3(const char *endpoint, unsigned int retries, bool large)sizeof(decoder_path));if (!rc)rc = shirudo_upatch_maps_otel_send_file(decoder_path, &f.view,- SHIRUDO_OTEL_S3, &opts);+ SHIRUDO_OTEL_S3, &opts);if (decoder_path[0])unlink(decoder_path);large_serialized_destroy(&f);diff --git a/testing/helper/test-register.c b/testing/helper/test-register.cindex c23d8d57..a77a54ac 100644--- a/testing/helper/test-register.c+++ b/testing/helper/test-register.c@@ -140,7 +140,7 @@ int main(int argc, char **argv)if (shirudo_hex_decode(argv[3], payload, 32))return 2;shirudo_chain_upatch_event("shirudo-upatch", argv[2], payload,- event);+ event);rc = shirudo_chain_extend(event, chain);printf("rc=%d\n", rc);if (rc)diff --git a/testing/helper/test-upatch-decode.c b/testing/helper/test-upatch-decode.cindex b16ac7d8..8d8ac2b2 100644--- a/testing/helper/test-upatch-decode.c+++ b/testing/helper/test-upatch-decode.c@@ -39,10 +39,10 @@ int main(int argc, char **argv)view.serial_bytes_total = 999;if (strcmp(argv[1], "otel") == 0)rc = shirudo_upatch_decode_map_file_otel(argv[2], &view,- &out, &out_len);+ &out, &out_len);elserc = shirudo_upatch_decode_map_file_json(argv[2], &view,- &out, &out_len);+ &out, &out_len);if (rc) {fprintf(stderr, "decode: %d\n", rc);return 1;diff --git a/testing/helper/test-upatch-prog-metadata.c b/testing/helper/test-upatch-prog-metadata.cindex 339313a1..3af0c679 100644--- a/testing/helper/test-upatch-prog-metadata.c+++ b/testing/helper/test-upatch-prog-metadata.c@@ -166,27 +166,27 @@ int main(int argc, char **argv)if (rc)return fail("open upatch failed");- if (strcmp(mode, "serializer") == 0)+ if (strcmp(mode, "serializer") == 0) {rc = expect_serializer(&u);- else if (strcmp(mode, "cgroup-ingress") == 0)+ } else if (strcmp(mode, "cgroup-ingress") == 0) {rc = expect_attach(&u,- SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_INGRESS,- NULL, 0);- else if (strcmp(mode, "cgroup-egress") == 0)+ SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_INGRESS,+ NULL, 0);+ } else if (strcmp(mode, "cgroup-egress") == 0) {rc = expect_attach(&u,- SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_EGRESS,- NULL, 0);- else if (strcmp(mode, "kprobe-override") == 0)+ SHIRUDO_UPATCH_ATTACH_CGROUP_SKB_EGRESS,+ NULL, 0);+ } else if (strcmp(mode, "kprobe-override") == 0) {rc = expect_attach(&u, SHIRUDO_UPATCH_ATTACH_KPROBE,"bpf_modify_return_test", 0);- else if (strcmp(mode, "fmod-ret") == 0)+ } else if (strcmp(mode, "fmod-ret") == 0) {rc = expect_attach(&u, SHIRUDO_UPATCH_ATTACH_FMOD_RET,NULL, 0);- else if (strcmp(mode, "netfilter-ipv6-pre-routing") == 0)+ } else if (strcmp(mode, "netfilter-ipv6-pre-routing") == 0) {rc = expect_attach(&u,- SHIRUDO_UPATCH_ATTACH_NETFILTER_IPV6_PRE_ROUTING,- NULL, 0);- else if (strcmp(mode, "uprobe-multi") == 0 && argc == 6) {+ SHIRUDO_UPATCH_ATTACH_NETFILTER_IPV6_PRE_ROUTING,+ NULL, 0);+ } else if (strcmp(mode, "uprobe-multi") == 0 && argc == 6) {char *end = NULL;unsigned long count = strtoul(argv[5], &end, 10);@@ -195,9 +195,9 @@ int main(int argc, char **argv)elserc = expect_uprobe_multi(&u, argv[3], argv[4],(uint32_t)count);- }- else+ } else {rc = fail("unknown metadata check mode");+ }shirudo_upatch_close(&u);if (rc)