* [PATCH bpf-next 1/4] selftests: bpf: tests.h should depend on .c files, not the output
2019-04-02 17:08 [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings Stanislav Fomichev
@ 2019-04-02 17:08 ` Stanislav Fomichev
2019-04-02 17:08 ` [PATCH bpf-next 2/4] selftests: bpf: fix -Wformat-security warning for flow_dissector_load.c Stanislav Fomichev
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2019-04-02 17:08 UTC (permalink / raw)
To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev
This makes sure we don't put headers as input files when doing
compilation, because clang complains about the following:
clang-9: error: cannot specify -o when generating multiple output files
../lib.mk:152: recipe for target 'xxx/tools/testing/selftests/bpf/test_verifier' failed
make: *** [xxx/tools/testing/selftests/bpf/test_verifier] Error 1
make: *** Waiting for unfinished jobs....
clang-9: error: cannot specify -o when generating multiple output files
../lib.mk:152: recipe for target 'xxx/tools/testing/selftests/bpf/test_progs' failed
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/Makefile | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/tools/testing/selftests/bpf/Makefile b/tools/testing/selftests/bpf/Makefile
index 2aed37ea61a4..e7ee6a242146 100644
--- a/tools/testing/selftests/bpf/Makefile
+++ b/tools/testing/selftests/bpf/Makefile
@@ -206,7 +206,7 @@ ifeq ($(DWARF2BTF),y)
endif
PROG_TESTS_H := $(OUTPUT)/prog_tests/tests.h
-$(OUTPUT)/test_progs: $(PROG_TESTS_H)
+test_progs.c: $(PROG_TESTS_H)
$(OUTPUT)/test_progs: CFLAGS += $(TEST_PROGS_CFLAGS)
$(OUTPUT)/test_progs: prog_tests/*.c
@@ -229,7 +229,7 @@ $(PROG_TESTS_H): $(PROG_TESTS_DIR) $(PROG_TESTS_FILES)
) > $(PROG_TESTS_H))
VERIFIER_TESTS_H := $(OUTPUT)/verifier/tests.h
-$(OUTPUT)/test_verifier: $(VERIFIER_TESTS_H)
+test_verifier.c: $(VERIFIER_TESTS_H)
$(OUTPUT)/test_verifier: CFLAGS += $(TEST_VERIFIER_CFLAGS)
VERIFIER_TESTS_DIR = $(OUTPUT)/verifier
--
2.21.0.392.gf8f6787159e-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH bpf-next 2/4] selftests: bpf: fix -Wformat-security warning for flow_dissector_load.c
2019-04-02 17:08 [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings Stanislav Fomichev
2019-04-02 17:08 ` [PATCH bpf-next 1/4] selftests: bpf: tests.h should depend on .c files, not the output Stanislav Fomichev
@ 2019-04-02 17:08 ` Stanislav Fomichev
2019-04-02 17:08 ` [PATCH bpf-next 3/4] selftests: bpf: fix -Wformat-invalid-specifier for bpf_obj_id.c Stanislav Fomichev
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2019-04-02 17:08 UTC (permalink / raw)
To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev
flow_dissector_load.c:55:19: warning: format string is not a string literal (potentially insecure)
[-Wformat-security]
error(1, errno, command);
^~~~~~~
flow_dissector_load.c:55:19: note: treat the string as an argument to avoid this
error(1, errno, command);
^
"%s",
1 warning generated.
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/flow_dissector_load.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/flow_dissector_load.c b/tools/testing/selftests/bpf/flow_dissector_load.c
index 77cafa66d048..7136ab9ffa73 100644
--- a/tools/testing/selftests/bpf/flow_dissector_load.c
+++ b/tools/testing/selftests/bpf/flow_dissector_load.c
@@ -52,7 +52,7 @@ static void detach_program(void)
sprintf(command, "rm -r %s", cfg_pin_path);
ret = system(command);
if (ret)
- error(1, errno, command);
+ error(1, errno, "%s", command);
}
static void parse_opts(int argc, char **argv)
--
2.21.0.392.gf8f6787159e-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* [PATCH bpf-next 3/4] selftests: bpf: fix -Wformat-invalid-specifier for bpf_obj_id.c
2019-04-02 17:08 [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings Stanislav Fomichev
2019-04-02 17:08 ` [PATCH bpf-next 1/4] selftests: bpf: tests.h should depend on .c files, not the output Stanislav Fomichev
2019-04-02 17:08 ` [PATCH bpf-next 2/4] selftests: bpf: fix -Wformat-security warning for flow_dissector_load.c Stanislav Fomichev
@ 2019-04-02 17:08 ` Stanislav Fomichev
2019-04-02 17:08 ` [PATCH bpf-next 4/4] selftests: bpf: remove duplicate .flags initialization in ctx_skb.c Stanislav Fomichev
2019-04-02 21:19 ` [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings Daniel Borkmann
4 siblings, 0 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2019-04-02 17:08 UTC (permalink / raw)
To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev
Use standard C99 %zu for sizeof, not GCC's custom %Zu:
bpf_obj_id.c:76:48: warning: invalid conversion specifier 'Z'
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c b/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c
index a64f7a02139c..cb827383db4d 100644
--- a/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c
+++ b/tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c
@@ -73,7 +73,7 @@ void test_bpf_obj_id(void)
info_len != sizeof(struct bpf_map_info) ||
strcmp((char *)map_infos[i].name, expected_map_name),
"get-map-info(fd)",
- "err %d errno %d type %d(%d) info_len %u(%Zu) key_size %u value_size %u max_entries %u map_flags %X name %s(%s)\n",
+ "err %d errno %d type %d(%d) info_len %u(%zu) key_size %u value_size %u max_entries %u map_flags %X name %s(%s)\n",
err, errno,
map_infos[i].type, BPF_MAP_TYPE_ARRAY,
info_len, sizeof(struct bpf_map_info),
@@ -117,7 +117,7 @@ void test_bpf_obj_id(void)
*(int *)(long)prog_infos[i].map_ids != map_infos[i].id ||
strcmp((char *)prog_infos[i].name, expected_prog_name),
"get-prog-info(fd)",
- "err %d errno %d i %d type %d(%d) info_len %u(%Zu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d load_time %lu(%lu) uid %u(%u) nr_map_ids %u(%u) map_id %u(%u) name %s(%s)\n",
+ "err %d errno %d i %d type %d(%d) info_len %u(%zu) jit_enabled %d jited_prog_len %u xlated_prog_len %u jited_prog %d xlated_prog %d load_time %lu(%lu) uid %u(%u) nr_map_ids %u(%u) map_id %u(%u) name %s(%s)\n",
err, errno, i,
prog_infos[i].type, BPF_PROG_TYPE_SOCKET_FILTER,
info_len, sizeof(struct bpf_prog_info),
@@ -185,7 +185,7 @@ void test_bpf_obj_id(void)
memcmp(&prog_info, &prog_infos[i], info_len) ||
*(int *)(long)prog_info.map_ids != saved_map_id,
"get-prog-info(next_id->fd)",
- "err %d errno %d info_len %u(%Zu) memcmp %d map_id %u(%u)\n",
+ "err %d errno %d info_len %u(%zu) memcmp %d map_id %u(%u)\n",
err, errno, info_len, sizeof(struct bpf_prog_info),
memcmp(&prog_info, &prog_infos[i], info_len),
*(int *)(long)prog_info.map_ids, saved_map_id);
@@ -231,7 +231,7 @@ void test_bpf_obj_id(void)
memcmp(&map_info, &map_infos[i], info_len) ||
array_value != array_magic_value,
"check get-map-info(next_id->fd)",
- "err %d errno %d info_len %u(%Zu) memcmp %d array_value %llu(%llu)\n",
+ "err %d errno %d info_len %u(%zu) memcmp %d array_value %llu(%llu)\n",
err, errno, info_len, sizeof(struct bpf_map_info),
memcmp(&map_info, &map_infos[i], info_len),
array_value, array_magic_value);
--
2.21.0.392.gf8f6787159e-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH bpf-next 4/4] selftests: bpf: remove duplicate .flags initialization in ctx_skb.c
2019-04-02 17:08 [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings Stanislav Fomichev
` (2 preceding siblings ...)
2019-04-02 17:08 ` [PATCH bpf-next 3/4] selftests: bpf: fix -Wformat-invalid-specifier for bpf_obj_id.c Stanislav Fomichev
@ 2019-04-02 17:08 ` Stanislav Fomichev
2019-04-02 21:19 ` [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings Daniel Borkmann
4 siblings, 0 replies; 6+ messages in thread
From: Stanislav Fomichev @ 2019-04-02 17:08 UTC (permalink / raw)
To: netdev, bpf; +Cc: davem, ast, daniel, Stanislav Fomichev
verifier/ctx_skb.c:708:11: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
tools/testing/selftests/bpf/verifier/ctx_skb.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/tools/testing/selftests/bpf/verifier/ctx_skb.c b/tools/testing/selftests/bpf/verifier/ctx_skb.c
index c660deb582f1..b0fda2877119 100644
--- a/tools/testing/selftests/bpf/verifier/ctx_skb.c
+++ b/tools/testing/selftests/bpf/verifier/ctx_skb.c
@@ -705,7 +705,6 @@
.errstr = "invalid bpf_context access",
.result = REJECT,
.flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
- .flags = F_NEEDS_EFFICIENT_UNALIGNED_ACCESS,
},
{
"check cb access: half, wrong type",
--
2.21.0.392.gf8f6787159e-goog
^ permalink raw reply related [flat|nested] 6+ messages in thread* Re: [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings
2019-04-02 17:08 [PATCH bpf-next 0/4] selftests: bpf: support building selftests with clang and fix warnings Stanislav Fomichev
` (3 preceding siblings ...)
2019-04-02 17:08 ` [PATCH bpf-next 4/4] selftests: bpf: remove duplicate .flags initialization in ctx_skb.c Stanislav Fomichev
@ 2019-04-02 21:19 ` Daniel Borkmann
4 siblings, 0 replies; 6+ messages in thread
From: Daniel Borkmann @ 2019-04-02 21:19 UTC (permalink / raw)
To: Stanislav Fomichev, netdev, bpf; +Cc: davem, ast
On 04/02/2019 07:08 PM, Stanislav Fomichev wrote:
> This series contains small fixes to make bpf selftests compile cleanly
> with clangs. All of them are not real problems, but it's nice to have
> an option to use clang for the tests themselves.
>
> Stanislav Fomichev (4):
> selftests: bpf: tests.h should depend on .c files, not the output
> selftests: bpf: fix -Wformat-security warning for
> flow_dissector_load.c
> selftests: bpf: fix -Wformat-invalid-specifier for bpf_obj_id.c
> selftests: bpf: remove duplicate .flags initialization in ctx_skb.c
>
> tools/testing/selftests/bpf/Makefile | 4 ++--
> tools/testing/selftests/bpf/flow_dissector_load.c | 2 +-
> tools/testing/selftests/bpf/prog_tests/bpf_obj_id.c | 8 ++++----
> tools/testing/selftests/bpf/verifier/ctx_skb.c | 1 -
> 4 files changed, 7 insertions(+), 8 deletions(-)
>
Applied, thanks!
^ permalink raw reply [flat|nested] 6+ messages in thread