bpftool: Make probes which emit dmesg warnings optional
Subsystems (6)
v2 cover bpftool: Make probes which emit dmesg warnings optional
Feature probes in bpftool related to bpf_probe_write_user and bpf_trace_printk helpers emit dmesg warnings which might be confusing for people running bpftool on production environments. This patch series addresses that by filtering them out by default and introducing the new positional argument "full" which enables all available probes.
The main motivation behind those changes is ability the fact that some probes (for example those related to "trace" or "write_user" helpers) emit dmesg messages which might be confusing for people who are running on production environments. For details see the Cilium issue[0].
v1: https://lore.kernel.org/bpf/[email protected]/T/
v1 -> v2:
- Do not expose regex filters to users, keep filtering logic internal, expose only the "full" option for including probes which emit dmesg warnings.
[0] https://github.com/cilium/cilium/issues/10048
Michal Rostecki (5):
bpftool: Move out sections to separate functions
bpftool: Make probes which emit dmesg warnings optional
bpftool: Update documentation of "bpftool feature" command
bpftool: Update bash completion for "bpftool feature" command selftests/bpf: Add test for "bpftool feature" command
.../bpftool/Documentation/bpftool-feature.rst | 15 +- tools/bpf/bpftool/bash-completion/bpftool | 27 +- tools/bpf/bpftool/feature.c | 291 ++++++++++++------ tools/testing/selftests/.gitignore | 5 +- tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/test_bpftool.py | 228 ++++++++++++++ tools/testing/selftests/bpf/test_bpftool.sh | 5 + 7 files changed, 463 insertions(+), 111 deletions(-) create mode 100644 tools/testing/selftests/bpf/test_bpftool.py create mode 100755 tools/testing/selftests/bpf/test_bpftool.sh
Signature · 1 line
2.25.0
PATCH v2 1/5 bpftool: Move out sections to separate functions
Remove all calls of print_end_then_start_section function and for loops out from the do_probe function. Instead, provide separate functions for each section (like i.e. section_helpers) which are called in do_probe. This change is motivated by better readability.
--- tools/bpf/bpftool/feature.c | 219 +++++++++++++++++++++--------------- 1 file changed, 126 insertions(+), 93 deletions(-)
tools/bpf/bpftool/feature.c +126 -93
@@ -112,18 +112,12 @@ print_start_section(const char *json_title, const char *plain_title, } } -static void -print_end_then_start_section (const char *json_title,const char *plain_title, -const char *define_comment, -const char *define_prefix) +static void print_end_section (void ) {if (json_output)jsonw_end_object (json_wtr);else printf ("\n" ); - -print_start_section (json_title, plain_title, define_comment, - define_prefix); }/* Probing functions */
@@ -584,13 +578,130 @@ probe_large_insn_limit(const char *define_prefix, __u32 ifindex) res, define_prefix); } +static void +section_system_config (enum probe_component target,const char *define_prefix) +{ +switch (target) { +case COMPONENT_KERNEL : +case COMPONENT_UNSPEC : +if (define_prefix) +break ; + +print_start_section ("system_config" , +"Scanning system configuration..." , +NULL ,/* define_comment never used here */ +NULL );/* define_prefix always NULL here */ +if (check_procfs ()) { +probe_unprivileged_disabled (); +probe_jit_enable (); +probe_jit_harden (); +probe_jit_kallsyms (); +probe_jit_limit (); + }else { +p_info ("/* procfs not mounted, skipping related probes */" ); + } +probe_kernel_image_config (); +print_end_section (); +break ; +default : +break ; + } +} + +static bool section_syscall_config (const char *define_prefix) +{ +bool res; + +print_start_section ("syscall_config" , +"Scanning system call availability..." , +"/*** System call availability ***/" , + define_prefix); + res =probe_bpf_syscall (define_prefix); +print_end_section (); + +return res; +} + +static void +section_program_types (bool *supported_types,const char *define_prefix, +__u32 ifindex) +{ +unsigned int i; + +print_start_section ("program_types" , +"Scanning eBPF program types..." , +"/*** eBPF program types ***/" , + define_prefix); + +for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++) +probe_prog_type (i, supported_types, define_prefix, ifindex); + +print_end_section (); +} + +static void section_map_types (const char *define_prefix,__u32 ifindex) +{ +unsigned int i; + +print_start_section ("map_types" , +"Scanning eBPF map types..." , +"/*** eBPF map types ***/" , + define_prefix); + +for (i =BPF_MAP_TYPE_UNSPEC +1 ; i < map_type_name_size; i++) +probe_map_type (i, define_prefix, ifindex); + +print_end_section (); +} + +static void +section_helpers (bool *supported_types,const char *define_prefix,__u32 ifindex) +{ +unsigned int i; + +print_start_section ("helpers" , +"Scanning eBPF helper functions..." , +"/*** eBPF helper functions ***/" , + define_prefix); + +if (define_prefix) +printf ("/*\n" +" * Use %sHAVE_PROG_TYPE_HELPER(prog_type_name, helper_name)\n" +" * to determine if <helper_name> is available for <prog_type_name>,\n" +" * e.g.\n" +" * #if %sHAVE_PROG_TYPE_HELPER(xdp, bpf_redirect)\n" +" * // do stuff with this helper\n" +" * #elif\n" +" * // use a workaround\n" +" * #endif\n" +" */\n" +"#define %sHAVE_PROG_TYPE_HELPER(prog_type, helper) \\\n" +" %sBPF__PROG_TYPE_ ## prog_type ## __HELPER_ ## helper\n" , + define_prefix, define_prefix, define_prefix, + define_prefix); +for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++) +probe_helpers_for_progtype (i, supported_types[i], + define_prefix, ifindex); + +print_end_section (); +} + +static void section_misc (const char *define_prefix,__u32 ifindex) +{ +print_start_section ("misc" , +"Scanning miscellaneous eBPF features..." , +"/*** eBPF misc features ***/" , + define_prefix); +probe_large_insn_limit (define_prefix, ifindex); +print_end_section (); +} +static int do_probe (int argc,char **argv) {enum probe_component target =COMPONENT_UNSPEC ;const char *define_prefix =NULL ;bool supported_types[128 ] = {};__u32 ifindex =0 ; -unsigned int i;char *ifname;/* Detection assumes user has sufficient privileges (CAP_SYS_ADMIN).
@@ -658,97 +769,19 @@ static int do_probe(int argc, char **argv)jsonw_start_object (json_wtr); } -switch (target) { -case COMPONENT_KERNEL : -case COMPONENT_UNSPEC : -if (define_prefix) -break ; - -print_start_section ("system_config" , -"Scanning system configuration..." , -NULL ,/* define_comment never used here */ -NULL );/* define_prefix always NULL here */ -if (check_procfs ()) { -probe_unprivileged_disabled (); -probe_jit_enable (); -probe_jit_harden (); -probe_jit_kallsyms (); -probe_jit_limit (); - }else { -p_info ("/* procfs not mounted, skipping related probes */" ); - } -probe_kernel_image_config (); -if (json_output) -jsonw_end_object (json_wtr); -else -printf ("\n" ); -break ; -default : -break ; - } - -print_start_section ("syscall_config" , -"Scanning system call availability..." , -"/*** System call availability ***/" , - define_prefix); - -if (!probe_bpf_syscall (define_prefix)) +section_system_config (target, define_prefix); +if (!section_syscall_config (define_prefix))/* bpf() syscall unavailable, don't probe other BPF features */ goto exit_close_json; - -print_end_then_start_section ("program_types" , -"Scanning eBPF program types..." , -"/*** eBPF program types ***/" , - define_prefix); - -for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++) -probe_prog_type (i, supported_types, define_prefix, ifindex); - -print_end_then_start_section ("map_types" , -"Scanning eBPF map types..." , -"/*** eBPF map types ***/" , - define_prefix); - -for (i =BPF_MAP_TYPE_UNSPEC +1 ; i < map_type_name_size; i++) -probe_map_type (i, define_prefix, ifindex); - -print_end_then_start_section ("helpers" , -"Scanning eBPF helper functions..." , -"/*** eBPF helper functions ***/" , - define_prefix); - -if (define_prefix) -printf ("/*\n" -" * Use %sHAVE_PROG_TYPE_HELPER(prog_type_name, helper_name)\n" -" * to determine if <helper_name> is available for <prog_type_name>,\n" -" * e.g.\n" -" * #if %sHAVE_PROG_TYPE_HELPER(xdp, bpf_redirect)\n" -" * // do stuff with this helper\n" -" * #elif\n" -" * // use a workaround\n" -" * #endif\n" -" */\n" -"#define %sHAVE_PROG_TYPE_HELPER(prog_type, helper) \\\n" -" %sBPF__PROG_TYPE_ ## prog_type ## __HELPER_ ## helper\n" , - define_prefix, define_prefix, define_prefix, - define_prefix); -for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++) -probe_helpers_for_progtype (i, supported_types[i], - define_prefix, ifindex); - -print_end_then_start_section ("misc" , -"Scanning miscellaneous eBPF features..." , -"/*** eBPF misc features ***/" , - define_prefix); -probe_large_insn_limit (define_prefix, ifindex); +section_program_types (supported_types, define_prefix, ifindex); +section_map_types (define_prefix, ifindex); +section_helpers (supported_types, define_prefix, ifindex); +section_misc (define_prefix, ifindex); exit_close_json: -if (json_output) { -/* End current "section" of probes */ -jsonw_end_object (json_wtr); +if (json_output)/* End root object */ jsonw_end_object (json_wtr); - }return 0 ; }
Signature · 1 line
2.25.0
Re: [PATCH bpf-next v2 1/5] bpftool: Move out sections to separate functions
2020-02-21 04:16 UTC+0100 ~ Michal Rostecki <[email protected]>
Quoted 6 lines
Remove all calls of
print_end_then_start_sectionfunction and for loops out from thedo_probefunction. Instead, provide separate functions for each section (like i.e.section_helpers) which are called indo_probe. This change is motivated by better readability.Signed-off-by Michal Rostecki <[email protected]>
Thanks!
PATCH v2 2/5 bpftool: Make probes which emit dmesg warnings optional
In reply to Michal RosteckiProbes related to bpf_probe_write_user and bpf_trace_printk helpers emit dmesg warnings which might be confusing for people running bpftool on production environments. This change filters them out by default and introduces the new positional argument "full" which enables all available probes.
--- tools/bpf/bpftool/feature.c | 80 +++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 7 deletions(-)
tools/bpf/bpftool/feature.c +73 -7
@@ -3,6 +3,7 @@#include <ctype.h> #include <errno.h> +#include <regex.h> #include <string.h> #include <unistd.h> #include <net/if.h>
@@ -22,6 +23,9 @@# define PROC_SUPER_MAGIC 0x9fa0#endif +/* Regex pattern for filtering out probes which emit dmesg warnings */ +#define FILTER_OUT_PATTERN "(trace|write_user)" +enum probe_component {COMPONENT_UNSPEC ,COMPONENT_KERNEL ,
@@ -57,6 +61,35 @@ static void uppercase(char *str, size_t len) str[i] =toupper (str[i]); } +/* Filtering utility functions */ + +static bool +check_filters (const char *name,regex_t *filter_out) +{ +char err_buf[100 ]; +int ret; + +/* Do not probe if filter_out was defined and string matches against the +* pattern. +*/ +if (filter_out) { + ret =regexec (filter_out, name,0 ,NULL ,0 ); +switch (ret) { +case 0 : +return false; +case REG_NOMATCH : +break ; +default : +regerror (ret, filter_out, err_buf,ARRAY_SIZE (err_buf)); +p_err ("could not match regex: %s" , err_buf); +free (filter_out); +exit (1 ); + } + } + +return true; +} +/* Printing utility functions */ static void
@@ -515,7 +548,8 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix,static void probe_helpers_for_progtype (enum bpf_prog_type prog_type,bool supported_type, -const char *define_prefix,__u32 ifindex) +const char *define_prefix,regex_t *filter_out, +__u32 ifindex) {const char *ptype_name = prog_type_name[prog_type];char feat_name[128 ];
@@ -542,6 +576,9 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type, }for (id =1 ; id <ARRAY_SIZE (helper_name); id++) { +if (!check_filters (helper_name[id], filter_out)) +continue ; +if (!supported_type) res = false;else
@@ -634,7 +671,8 @@ section_program_types(bool *supported_types, const char *define_prefix, define_prefix);for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++) -probe_prog_type (i, supported_types, define_prefix, ifindex); +probe_prog_type (i, supported_types, define_prefix, + ifindex);print_end_section (); }
@@ -655,7 +693,8 @@ static void section_map_types(const char *define_prefix, __u32 ifindex) }static void -section_helpers (bool *supported_types,const char *define_prefix,__u32 ifindex) +section_helpers (bool *supported_types,const char *define_prefix, +regex_t *filter_out,__u32 ifindex) {unsigned int i;
@@ -681,7 +720,7 @@ section_helpers(bool *supported_types, const char *define_prefix, __u32 ifindex) define_prefix);for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++)probe_helpers_for_progtype (i, supported_types[i], - define_prefix, ifindex); + define_prefix, filter_out, ifindex);print_end_section (); }
@@ -701,8 +740,13 @@ static int do_probe(int argc, char **argv)enum probe_component target =COMPONENT_UNSPEC ;const char *define_prefix =NULL ;bool supported_types[128 ] = {}; +regex_t *filter_out =NULL ; +bool full_mode = false; +char regerror_buf[100 ];__u32 ifindex =0 ;char *ifname; +int reg_ret; +int ret =0 ;/* Detection assumes user has sufficient privileges (CAP_SYS_ADMIN). * Let's approximate, and restrict usage to root user only.
@@ -740,6 +784,9 @@ static int do_probe(int argc, char **argv) strerror(errno));return -1 ; } + }else if (is_prefix (*argv,"full" )) { + full_mode = true; +NEXT_ARG (); }else if (is_prefix (*argv,"macros" ) && !define_prefix) { define_prefix ="" ;NEXT_ARG ();
@@ -764,6 +811,22 @@ static int do_probe(int argc, char **argv) } } +/* If full mode is not acivated, filter out probes which emit dmesg +* messages. +*/ +if (!full_mode) { + filter_out =malloc (sizeof (regex_t)); + reg_ret =regcomp (filter_out,FILTER_OUT_PATTERN ,REG_EXTENDED ); +if (reg_ret) { +regerror (reg_ret, filter_out, regerror_buf, +ARRAY_SIZE (regerror_buf)); +p_err ("could not compile regex: %s" , + regerror_buf); + ret =-1 ; + goto cleanup; + } + } +if (json_output) { define_prefix =NULL ;jsonw_start_object (json_wtr);
@@ -775,7 +838,7 @@ static int do_probe(int argc, char **argv) goto exit_close_json;section_program_types (supported_types, define_prefix, ifindex);section_map_types (define_prefix, ifindex); -section_helpers (supported_types, define_prefix, ifindex); +section_helpers (supported_types, define_prefix, filter_out, ifindex);section_misc (define_prefix, ifindex); exit_close_json:
@@ -783,7 +846,10 @@ static int do_probe(int argc, char **argv)/* End root object */ jsonw_end_object (json_wtr); -return 0 ; +cleanup: +free (filter_out); + +return ret; }static int do_help (int argc,char **argv)
@@ -794,7 +860,7 @@ static int do_help(int argc, char **argv) }fprintf (stderr, -"Usage: %s %s probe [COMPONENT] [macros [prefix PREFIX]]\n" +"Usage: %s %s probe [COMPONENT] [full] [macros [prefix PREFIX]]\n" " %s %s help\n" "\n" " COMPONENT := { kernel | dev NAME }\n"
Signature · 1 line
2.25.0
2020-02-21 04:16 UTC+0100 ~ Michal Rostecki <[email protected]>
Quoted 24 lines
Probes related to
bpf_probe_write_userandbpf_trace_printkhelpers emit dmesg warnings which might be confusing for people running bpftool on production environments. This change filters them out by default and introduces the new positional argument "full" which enables all available probes.Signed-off-by Michal Rostecki <[email protected]>--- tools/bpf/bpftool/feature.c | 80 +++++++++++++++++++++++++++++++++---- 1 file changed, 73 insertions(+), 7 deletions(-)tools/bpf/bpftool/feature.c +1
-0@@ -3,6 +3,7 @@#include <ctype.h> #include <errno.h> +#include <regex.h> #include <string.h> #include <unistd.h> #include <net/if.h>
tools/bpf/bpftool/feature.c line 27
Quoted 5 lines
tools/bpf/bpftool/feature.c +2
-0@@ -22,6 +23,9 @@# define PROC_SUPER_MAGIC 0x9fa0#endif +/* Regex pattern for filtering out probes which emit dmesg warnings */ +#define FILTER_OUT_PATTERN "(trace|write_user)"
"trace" sounds too generic. If filters are applied again to prog and map types in the future (as you had in v1), this would catch tracepoint and raw_tracepoint program types and stack_trace map type. Or if new helpers with "trace" in their name are added, we skip them too. Can we use something more specific, probably "trace_printk"?
Quoted 61 lines
tools/bpf/bpftool/feature.c +35
-1+enum probe_component {COMPONENT_UNSPEC ,COMPONENT_KERNEL ,@@ -57,6 +61,35 @@ static void uppercase(char *str, size_t len) str[i] =toupper (str[i]); } +/* Filtering utility functions */ + +static bool +check_filters (const char *name,regex_t *filter_out) +{ +char err_buf[100 ]; +int ret; + +/* Do not probe if filter_out was defined and string matches against the +* pattern. +*/ +if (filter_out) { + ret =regexec (filter_out, name,0 ,NULL ,0 ); +switch (ret) { +case 0 : +return false; +case REG_NOMATCH : +break ; +default : +regerror (ret, filter_out, err_buf,ARRAY_SIZE (err_buf)); +p_err ("could not match regex: %s" , err_buf); +free (filter_out); +exit (1 ); + } + } + +return true; +} +/* Printing utility functions */ static void@@ -515,7 +548,8 @@ probe_map_type(enum bpf_map_type map_type, const char *define_prefix,static void probe_helpers_for_progtype (enum bpf_prog_type prog_type,bool supported_type, -const char *define_prefix,__u32 ifindex) +const char *define_prefix,regex_t *filter_out, +__u32 ifindex) {const char *ptype_name = prog_type_name[prog_type];char feat_name[128 ];@@ -542,6 +576,9 @@ probe_helpers_for_progtype(enum bpf_prog_type prog_type, bool supported_type, }for (id =1 ; id <ARRAY_SIZE (helper_name); id++) { +if (!check_filters (helper_name[id], filter_out)) +continue ; +if (!supported_type) res = false;else
tools/bpf/bpftool/feature.c section_program_types(bool *supported_types, const char *define_prefix, · line 675
Quoted 6 lines
tools/bpf/bpftool/feature.c +2
-1@@ -634,7 +671,8 @@ section_program_types(bool *supported_types, const char *define_prefix, define_prefix);for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++) -probe_prog_type (i, supported_types, define_prefix, ifindex); +probe_prog_type (i, supported_types, define_prefix, + ifindex);
Splitting the line here is not desirable, probably some leftover after rolling back on changes?
Quoted 47 lines
tools/bpf/bpftool/feature.c +11
-2print_end_section (); }@@ -655,7 +693,8 @@ static void section_map_types(const char *define_prefix, __u32 ifindex) }static void -section_helpers (bool *supported_types,const char *define_prefix,__u32 ifindex) +section_helpers (bool *supported_types,const char *define_prefix, +regex_t *filter_out,__u32 ifindex) {unsigned int i;@@ -681,7 +720,7 @@ section_helpers(bool *supported_types, const char *define_prefix, __u32 ifindex) define_prefix);for (i =BPF_PROG_TYPE_UNSPEC +1 ; i <ARRAY_SIZE (prog_type_name); i++)probe_helpers_for_progtype (i, supported_types[i], - define_prefix, ifindex); + define_prefix, filter_out, ifindex);print_end_section (); }@@ -701,8 +740,13 @@ static int do_probe(int argc, char **argv)enum probe_component target =COMPONENT_UNSPEC ;const char *define_prefix =NULL ;bool supported_types[128 ] = {}; +regex_t *filter_out =NULL ; +bool full_mode = false; +char regerror_buf[100 ];__u32 ifindex =0 ;char *ifname; +int reg_ret; +int ret =0 ;/* Detection assumes user has sufficient privileges (CAP_SYS_ADMIN). * Let's approximate, and restrict usage to root user only. @@ -740,6 +784,9 @@ static int do_probe(int argc, char **argv) strerror(errno));return -1 ; } + }else if (is_prefix (*argv,"full" )) { + full_mode = true; +NEXT_ARG (); }else if (is_prefix (*argv,"macros" ) && !define_prefix) { define_prefix ="" ;NEXT_ARG ();
tools/bpf/bpftool/feature.c static int do_probe(int argc, char **argv) · line 814
Quoted 4 lines
tools/bpf/bpftool/feature.c +1
-0@@ -764,6 +811,22 @@ static int do_probe(int argc, char **argv) } } +/* If full mode is not acivated, filter out probes which emit dmesg
Typo: acivated
tools/bpf/bpftool/feature.c static int do_probe(int argc, char **argv) · line 818
Quoted 4 lines
tools/bpf/bpftool/feature.c +4
-0+* messages. +*/ +if (!full_mode) { + filter_out =malloc (sizeof (regex_t));
filter_out is not free()-d on the different error paths in the function. You would probably have to goto cleanup from several other locations.
Quoted 37 lines
tools/bpf/bpftool/feature.c +16
-2+ reg_ret =regcomp (filter_out,FILTER_OUT_PATTERN ,REG_EXTENDED ); +if (reg_ret) { +regerror (reg_ret, filter_out, regerror_buf, +ARRAY_SIZE (regerror_buf)); +p_err ("could not compile regex: %s" , + regerror_buf); + ret =-1 ; + goto cleanup; + } + } +if (json_output) { define_prefix =NULL ;jsonw_start_object (json_wtr);@@ -775,7 +838,7 @@ static int do_probe(int argc, char **argv) goto exit_close_json;section_program_types (supported_types, define_prefix, ifindex);section_map_types (define_prefix, ifindex); -section_helpers (supported_types, define_prefix, ifindex); +section_helpers (supported_types, define_prefix, filter_out, ifindex);section_misc (define_prefix, ifindex); exit_close_json:@@ -783,7 +846,10 @@ static int do_probe(int argc, char **argv)/* End root object */ jsonw_end_object (json_wtr); -return 0 ; +cleanup: +free (filter_out); + +return ret; }static int do_help (int argc,char **argv)
tools/bpf/bpftool/feature.c static int do_help(int argc, char **argv) · line 866
Quoted 8 lines
tools/bpf/bpftool/feature.c +1
-1@@ -794,7 +860,7 @@ static int do_help(int argc, char **argv) }fprintf (stderr, -"Usage: %s %s probe [COMPONENT] [macros [prefix PREFIX]]\n" +"Usage: %s %s probe [COMPONENT] [full] [macros [prefix PREFIX]]\n" " %s %s help\n" "\n" " COMPONENT := { kernel | dev NAME }\n"
Thanks for the patch! While I understand you want to keep the changes you have done to use regex, I do not really think they bring much in this version of the patch. As we only want to filter out two specific helpers, it seems to me that it would be much simpler to just compare helper names instead of introducing regular expressions that are not used otherwise. What do you think?
Quentin
Quoted 6 lines · Quentin Monnet
"trace" sounds too generic. If filters are applied again to prog and map types in the future (as you had in v1), this would catch tracepoint and
raw_tracepointprogram types andstack_tracemap type. Or if new helpers with "trace" in their name are added, we skip them too. Can we use something more specific, probably "trace_printk"?
+1
Quoted 6 lines
Thanks for the patch! While I understand you want to keep the changes you have done to use regex, I do not really think they bring much in this version of the patch. As we only want to filter out two specific helpers, it seems to me that it would be much simpler to just compare helper names instead of introducing regular expressions that are not used otherwise. What do you think?
+1
I was thinking the same.
Or filter by specific integer id of the helper.
Quoted 17 lines · Alexei Starovoitov
Quoted 6 lines · Quentin Monnet
"trace" sounds too generic. If filters are applied again to prog and map types in the future (as you had in v1), this would catch tracepoint and
raw_tracepointprogram types andstack_tracemap type. Or if new helpers with "trace" in their name are added, we skip them too. Can we use something more specific, probably "trace_printk"?+1
Quoted 6 lines
Thanks for the patch! While I understand you want to keep the changes you have done to use regex, I do not really think they bring much in this version of the patch. As we only want to filter out two specific helpers, it seems to me that it would be much simpler to just compare helper names instead of introducing regular expressions that are not used otherwise. What do you think?
Quoted 4 lines
+1
I was thinking the same.
Or filter by specific integer id of the helper.
I like the idea of filtering by id. I will do that in v3. Thanks for review!
PATCH v2 3/5 bpftool: Update documentation of "bpftool feature" command
In reply to Michal RosteckiUpdate documentation of "bpftool feature" command with information about new arguments: "full".
--- .../bpf/bpftool/Documentation/bpftool-feature.rst | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
tools/bpf/bpftool/Documentation/bpftool-feature.rst +10 -5
@@ -19,19 +19,24 @@ SYNOPSIS FEATURE COMMANDS ================ -| **bpftool** **feature probe** [*COMPONENT*] [**macros** [**prefix** *PREFIX*]] +| **bpftool** **feature probe** [*COMPONENT*] [**full**] [**macros** [**prefix** *PREFIX*]] | **bpftool** **feature help** | | *COMPONENT* := { **kernel** | **dev** *NAME* } DESCRIPTION =========== - **bpftool feature probe** [**kernel**] [**macros** [**prefix** *PREFIX*]] + **bpftool feature probe** [**kernel**] [**full**] [**macros** [**prefix** *PREFIX*]] Probe the running kernel and dump a number of eBPF-related parameters, such as availability of the **bpf()** system call, JIT status, eBPF program types availability, eBPF helper functions availability, and more. + By default, bpftool does not run probes for + bpf_probe_write_user and bpf_trace_printk helpers which emit + dmesg warnings. To enable them and run all probes, the + **full** keyword should be used. + If the **macros** keyword (but not the **-j** option) is passed, a subset of the output is dumped as a list of **#define** macros that are ready to be included in a C
@@ -48,12 +53,12 @@ DESCRIPTION **bpf_trace_printk**\ () or **bpf_probe_write_user**\ ()) may print warnings to kernel logs. - **bpftool feature probe dev** *NAME* [**macros** [**prefix** *PREFIX*]] + **bpftool feature probe dev** *NAME* [**full**] [**macros** [**prefix** *PREFIX*]] Probe network device for supported eBPF features and dump results to the console. - The two keywords **macros** and **prefix** have the same - role as when probing the kernel. + The keywords **full**, **macros** and **prefix** have the + same role as when probing the kernel. **bpftool feature help** Print short help message.
Signature · 1 line
2.25.0
Re: [PATCH bpf-next v2 3/5] bpftool: Update documentation of "bpftool feature" command
2020-02-21 04:16 UTC+0100 ~ Michal Rostecki <[email protected]>
Quoted 23 lines
Update documentation of "bpftool feature" command with information about new arguments: "full".
Signed-off-by Michal Rostecki <[email protected]>--- .../bpf/bpftool/Documentation/bpftool-feature.rst | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)tools/bpf/bpftool/Documentation/bpftool-feature.rst +1
-1@@ -19,19 +19,24 @@ SYNOPSIS FEATURE COMMANDS ================ -| **bpftool** **feature probe** [*COMPONENT*] [**macros** [**prefix** *PREFIX*]] +| **bpftool** **feature probe** [*COMPONENT*] [**full**] [**macros** [**prefix** *PREFIX*]] | **bpftool** **feature help** | | *COMPONENT* := { **kernel** | **dev** *NAME* } DESCRIPTION
tools/bpf/bpftool/Documentation/bpftool-feature.rst SYNOPSIS · line 36
Quoted 10 lines
tools/bpf/bpftool/Documentation/bpftool-feature.rst +3
-1=========== - **bpftool feature probe** [**kernel**] [**macros** [**prefix** *PREFIX*]] + **bpftool feature probe** [**kernel**] [**full**] [**macros** [**prefix** *PREFIX*]] Probe the running kernel and dump a number of eBPF-related parameters, such as availability of the **bpf()** system call, JIT status, eBPF program types availability, eBPF helper functions availability, and more. + By default, bpftool does not run probes for + bpf_probe_write_user and bpf_trace_printk helpers which emit
Please use formatting on helper function names, for readability and consistency.
I would even be tempted to highlight part or all of the sentence, with caps or bold, as some users may be surprised not to see those helpers in the list of available helpers on their system.
tools/bpf/bpftool/Documentation/bpftool-feature.rst DESCRIPTION · line 54
Quoted 9 lines
tools/bpf/bpftool/Documentation/bpftool-feature.rst +3
-0+ dmesg warnings. To enable them and run all probes, the + **full** keyword should be used. + If the **macros** keyword (but not the **-j** option) is passed, a subset of the output is dumped as a list of **#define** macros that are ready to be included in a C@@ -48,12 +53,12 @@ DESCRIPTION **bpf_trace_printk**\ () or **bpf_probe_write_user**\ ()) may print warnings to kernel logs.
This should maybe be moved upwards and combined with your new paragraph?
Quoted 14 lines
tools/bpf/bpftool/Documentation/bpftool-feature.rst +3
-3- **bpftool feature probe dev** *NAME* [**macros** [**prefix** *PREFIX*]] + **bpftool feature probe dev** *NAME* [**full**] [**macros** [**prefix** *PREFIX*]] Probe network device for supported eBPF features and dump results to the console. - The two keywords **macros** and **prefix** have the same - role as when probing the kernel. + The keywords **full**, **macros** and **prefix** have the + same role as when probing the kernel. **bpftool feature help** Print short help message.
PATCH v2 4/5 bpftool: Update bash completion for "bpftool feature" command
In reply to Michal RosteckiUpdate bash completion for "bpftool feature" command with the new
argument: "full".
--- tools/bpf/bpftool/bash-completion/bpftool | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-)
tools/bpf/bpftool/bash-completion/bpftool +19 -8
@@ -981,14 +981,25 @@ _bpftool() feature) case $command in probe) - [[ $prev == "prefix" ]] && return 0 - if _bpftool_search_list 'macros'; then - COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) ) - else - COMPREPLY+=( $( compgen -W 'macros' -- "$cur" ) ) - fi - _bpftool_one_of_list 'kernel dev' - return 0 + case $prev in + $command) + COMPREPLY+=( $( compgen -W 'kernel dev full macros' -- \ + "$cur" ) ) + return 0 + ;; + prefix) + return 0 + ;; + macros) + COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) ) + return 0 + ;; + *) + _bpftool_one_of_list 'kernel dev' + _bpftool_once_attr 'full macros' + return 0 + ;; + esac ;; *) [[ $prev == $object ]] && \
Signature · 1 line
2.25.0
Re: [PATCH bpf-next v2 4/5] bpftool: Update bash completion for "bpftool feature" command
2020-02-21 04:16 UTC+0100 ~ Michal Rostecki <[email protected]>
Quoted 26 lines
Update bash completion for "bpftool feature" command with the new
argument: "full".Signed-off-by Michal Rostecki <[email protected]>--- tools/bpf/bpftool/bash-completion/bpftool | 27 ++++++++++++++++------- 1 file changed, 19 insertions(+), 8 deletions(-)tools/bpf/bpftool/bash-completion/bpftool +2
-8@@ -981,14 +981,25 @@ _bpftool() feature) case $command in probe) - [[ $prev == "prefix" ]] && return 0 - if _bpftool_search_list 'macros'; then - COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) ) - else - COMPREPLY+=( $( compgen -W 'macros' -- "$cur" ) ) - fi - _bpftool_one_of_list 'kernel dev' - return 0 + case $prev in + $command)
tools/bpf/bpftool/bash-completion/bpftool _bpftool() · line 995
Quoted 10 lines
tools/bpf/bpftool/bash-completion/bpftool +10
-0+ COMPREPLY+=( $( compgen -W 'kernel dev full macros' -- \ + "$cur" ) ) + return 0 + ;; + prefix) + return 0 + ;; + macros) + COMPREPLY+=( $( compgen -W 'prefix' -- "$cur" ) ) + return 0
I have not tested, but I think because of the "return 0" this will propose only "prefix" after "macros". But "kernel" or "dev" should also be in the list.
Maybe just add "_bpftool_once_attr 'full'" under the "_bpftool_one_of_list 'kernel dev'" instead of changing to the "case $prev in" structure?
Quoted 11 lines
tools/bpf/bpftool/bash-completion/bpftool +7
-0+ ;; + *) + _bpftool_one_of_list 'kernel dev' + _bpftool_once_attr 'full macros' + return 0 + ;; + esac ;; *) [[ $prev == $object ]] && \
PATCH v2 5/5 selftests/bpf: Add test for "bpftool feature" command
In reply to Michal RosteckiAdd Python module with tests for "bpftool feature" command, which mainly wheck whether the "full" option is working properly.
--- tools/testing/selftests/.gitignore | 5 +- tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/test_bpftool.py | 228 ++++++++++++++++++++ tools/testing/selftests/bpf/test_bpftool.sh | 5 + 4 files changed, 239 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/bpf/test_bpftool.py create mode 100755 tools/testing/selftests/bpf/test_bpftool.sh
tools/testing/selftests/.gitignore +4 -1
@@ -3,4 +3,7 @@ gpiogpio-hammer gpioinclude/ gpiolsgpio tpm2/SpaceTest.log -tpm2/*.pyc + +# Python bytecode and cache +__pycache__/ +*.py[cod]
tools/testing/selftests/bpf/Makefile +2 -1
@@ -62,7 +62,8 @@ TEST_PROGS := test_kmod.sh \ test_tc_tunnel.sh \ test_tc_edt.sh \ test_xdping.sh \ - test_bpftool_build.sh + test_bpftool_build.sh \ + test_bpftool.sh TEST_PROGS_EXTENDED := with_addr.sh \ with_tunnels.sh \
tools/testing/selftests/bpf/test_bpftool.py new file +228 -0
228 lines not on this page · raw message
tools/testing/selftests/bpf/test_bpftool.sh new file +5 -0
@@ -0,0 +1,5 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2020 SUSE LLC. + +python3 -m unittest -v test_bpftool.TestBpftool
Signature · 1 line
2.25.0
Re: [PATCH bpf-next v2 5/5] selftests/bpf: Add test for "bpftool feature" command
2020-02-21 04:17 UTC+0100 ~ Michal Rostecki <[email protected]>
Quoted 48 lines
Add Python module with tests for "bpftool feature" command, which mainly wheck whether the "full" option is working properly.
Signed-off-by Michal Rostecki <[email protected]>--- tools/testing/selftests/.gitignore | 5 +- tools/testing/selftests/bpf/Makefile | 3 +- tools/testing/selftests/bpf/test_bpftool.py | 228 ++++++++++++++++++++ tools/testing/selftests/bpf/test_bpftool.sh | 5 + 4 files changed, 239 insertions(+), 2 deletions(-)create mode 100644
tools/testing/selftests/bpf/test_bpftool.pycreate mode 100755tools/testing/selftests/bpf/test_bpftool.shtools/testing/selftests/.gitignore +4
-1@@ -3,4 +3,7 @@ gpiogpio-hammer gpioinclude/ gpiolsgpio tpm2/SpaceTest.log -tpm2/*.pyc + +# Python bytecode and cache +__pycache__/ +*.py[cod]tools/testing/selftests/bpf/Makefile +2
-1@@ -62,7 +62,8 @@ TEST_PROGS := test_kmod.sh \ test_tc_tunnel.sh \ test_tc_edt.sh \ test_xdping.sh \ - test_bpftool_build.sh + test_bpftool_build.sh \ + test_bpftool.sh TEST_PROGS_EXTENDED := with_addr.sh \ with_tunnels.sh \tools/testing/selftests/bpf/test_bpftool.py new file +2
-0@@ -0,0 +1,228 @@ +# Copyright (c) 2020 SUSE LLC. +#
tools/testing/selftests/bpf/test_bpftool.py line 12
Quoted 10 lines
tools/testing/selftests/bpf/test_bpftool.py new file +10
-0+# This software is licensed under the GNU General License Version 2, +# June 1991 as shown in the file COPYING in the top-level directory of this +# source tree. +# +# THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" +# WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, +# BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +# FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE +# OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME +# THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
SPDX tag instead of boilerplate?
Quoted 62 lines
tools/testing/selftests/bpf/test_bpftool.py new file +62
-0+ +import collections +import functools +import json +import os +import socket +import subprocess +import unittest + + +# Add the source tree of bpftool and /usr/local/sbin to PATH +cur_dir = os.path.dirname(os.path.realpath(__file__)) +bpftool_dir = os.path.abspath(os.path.join(cur_dir, "..", "..", "..", "..", + "tools", "bpf", "bpftool")) +os.environ["PATH"] = bpftool_dir + ":/usr/local/sbin:" + os.environ["PATH"] + +# Probe sections +SECTION_SYSTEM_CONFIG_PATTERN = b"Scanning system configuration..." +SECTION_SYSCALL_CONFIG_PATTERN = b"Scanning system call availability..." +SECTION_PROGRAM_TYPES_PATTERN = b"Scanning eBPF program types..." +SECTION_MAP_TYPES_PATTERN = b"Scanning eBPF map types..." +SECTION_HELPERS_PATTERN = b"Scanning eBPF helper functions..." +SECTION_MISC_PATTERN = b"Scanning miscellaneous eBPF features..." + + +class IfaceNotFoundError(Exception): + pass + + +class UnprivilegedUserError(Exception): + pass + + +def _bpftool(args, json=True): + _args = ["bpftool"] + if json: + _args.append("-j") + _args.extend(args) + + res = subprocess.run(_args, capture_output=True) + return res.stdout + + +def bpftool(args): + return _bpftool(args, json=False) + + +def bpftool_json(args): + res = _bpftool(args) + return json.loads(res) + + +def get_default_iface(): + for iface in socket.if_nameindex(): + if iface[1] != "lo": + return iface[1] + raise IfaceNotFoundError("Could not find any network interface to probe") + + +def default_iface(f): + @functools.wraps(f) + def wrapper(*args, **kwargs):
tools/testing/selftests/bpf/test_bpftool.py line 84
Quoted 10 lines
tools/testing/selftests/bpf/test_bpftool.py new file +10
-0+ iface = get_default_iface() + return f(*args, iface, **kwargs) + return wrapper + + +class TestBpftool(unittest.TestCase): + @classmethod + def setUpClass(cls): + if os.getuid() != 0: + raise UnprivilegedUserError("This test suite eeeds root privileges")
Typo: eeeds
tools/testing/selftests/bpf/test_bpftool.py line 87
Quoted 3 lines
tools/testing/selftests/bpf/test_bpftool.py new file +3
-0+ + def _assert_pattern_not_in_dict(self, dct, pattern, check_keys=False): + """Check if all string values inside dictionary do not containe the
Typo: containe
Quoted 10 lines
tools/testing/selftests/bpf/test_bpftool.py new file +10
-0+ given pattern. + """ + for key, value in dct.items(): + if check_keys: + self.assertNotIn(pattern, key) + if isinstance(value, dict): + self._assert_pattern_not_in_dict(value, pattern, + check_keys=True) + elif isinstance(value, str): + self.assertNotIn(pattern, value)
tools/testing/selftests/bpf/test_bpftool.py line 107
Quoted 10 lines
tools/testing/selftests/bpf/test_bpftool.py new file +10
-0+ + @default_iface + def test_feature_dev(self, iface): + expected_patterns = [ + SECTION_SYSCALL_CONFIG_PATTERN, + SECTION_PROGRAM_TYPES_PATTERN, + SECTION_MAP_TYPES_PATTERN, + SECTION_HELPERS_PATTERN, + SECTION_MISC_PATTERN, + ]
Mixed feeling on the tests with plain output, as we keep telling people that plain output should not be parsed (not reliable, may change). But if you want to run one or two tests with it, why not, I guess.
Quoted 58 lines
tools/testing/selftests/bpf/test_bpftool.py new file +58
-0+ unexpected_patterns = [ + b"bpf_trace_printk", + b"bpf_probe_write_user", + ] + + res = bpftool(["feature", "probe", "dev", iface]) + for pattern in expected_patterns: + self.assertIn(pattern, res) + for pattern in unexpected_patterns: + self.assertNotIn(pattern, res) + + @default_iface + def test_feature_dev_json(self, iface): + expected_keys = [ + "syscall_config", + "program_types", + "map_types", + "helpers", + "misc", + ] + unexpected_values = [ + "bpf_trace_printk", + "bpf_probe_write_user", + ] + + res = bpftool_json(["feature", "probe", "dev", iface]) + self.assertCountEqual(res.keys(), expected_keys) + for value in unexpected_values: + self._assert_pattern_not_in_dict(res, value) + + def test_feature_kernel(self): + expected_patterns = [ + SECTION_SYSTEM_CONFIG_PATTERN, + SECTION_SYSCALL_CONFIG_PATTERN, + SECTION_PROGRAM_TYPES_PATTERN, + SECTION_MAP_TYPES_PATTERN, + SECTION_HELPERS_PATTERN, + SECTION_MISC_PATTERN, + ] + unexpected_patterns = [ + b"bpf_trace_printk", + b"bpf_probe_write_user", + ] + + res_default1 = bpftool(["feature"]) + res_default2 = bpftool(["feature", "probe"]) + res = bpftool(["feature", "probe", "kernel"]) + + for pattern in expected_patterns: + self.assertIn(pattern, res_default1) + self.assertIn(pattern, res_default2) + self.assertIn(pattern, res) + for pattern in unexpected_patterns: + self.assertNotIn(pattern, res_default1) + self.assertNotIn(pattern, res_default2) + self.assertNotIn(pattern, res) + + def test_feature_kernel_full(self):
tools/testing/selftests/bpf/test_bpftool.py line 175
Quoted 10 lines
tools/testing/selftests/bpf/test_bpftool.py new file +10
-0+ expected_patterns = [ + SECTION_SYSTEM_CONFIG_PATTERN, + SECTION_SYSCALL_CONFIG_PATTERN, + SECTION_PROGRAM_TYPES_PATTERN, + SECTION_MAP_TYPES_PATTERN, + SECTION_HELPERS_PATTERN, + SECTION_MISC_PATTERN, + b"bpf_trace_printk", + b"bpf_probe_write_user", + ]
However, if you do just one test for "kernel full", please favour JSON over plain output.
Quoted 43 lines
tools/testing/selftests/bpf/test_bpftool.py new file +43
-0+ + res_default = bpftool(["feature", "probe", "full"]) + res = bpftool(["feature", "probe", "kernel", "full"]) + + for pattern in expected_patterns: + self.assertIn(pattern, res_default) + self.assertIn(pattern, res) + + def test_feature_kernel_json(self): + expected_keys = [ + "system_config", + "syscall_config", + "program_types", + "map_types", + "helpers", + "misc", + ] + unexpected_values = [ + "bpf_trace_printk", + "bpf_probe_write_user", + ] + + res_default1 = bpftool_json(["feature"]) + self.assertCountEqual(res_default1.keys(), expected_keys) + for value in unexpected_values: + self._assert_pattern_not_in_dict(res_default1, value) + + res_default2 = bpftool_json(["feature", "probe"]) + self.assertCountEqual(res_default2.keys(), expected_keys) + for value in unexpected_values: + self._assert_pattern_not_in_dict(res_default2, value) + + res = bpftool_json(["feature", "probe", "kernel"]) + self.assertCountEqual(res.keys(), expected_keys) + for value in unexpected_values: + self._assert_pattern_not_in_dict(res, value) + + def test_feature_macros(self): + expected_patterns = [ + b"/\*\*\* System call availability \*\*\*/", + b"#define HAVE_BPF_SYSCALL", + b"/\*\*\* eBPF program types \*\*\*/", + b"#define HAVE.*PROG_TYPE",
tools/testing/selftests/bpf/test_bpftool.py line 228
Quoted 10 lines
tools/testing/selftests/bpf/test_bpftool.py new file +10
-0+ b"/\*\*\* eBPF map types \*\*\*/", + b"#define HAVE.*MAP_TYPE", + b"/\*\*\* eBPF helper functions \*\*\*/", + b"#define HAVE.*HELPER", + b"/\*\*\* eBPF misc features \*\*\*/", + ] + + res = bpftool(["feature", "probe", "macros"]) + for pattern in expected_patterns: + self.assertRegex(res, pattern)
Could we have (or did I miss it?) a test that compares the output of probes _with_ "full" and _without_ it, to make sure that the only lines that differ are about "bpf_trace_prink" or "bpf_probe_write_user"? Could help determine if we filter out too many elements by mistake.
Thanks,
Quentin
Quoted 12 lines
tools/testing/selftests/bpf/test_bpftool.sh new file +5
-0@@ -0,0 +1,5 @@ +#!/bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2020 SUSE LLC. + +python3 -m unittest -v test_bpftool.TestBpftool
Re: [PATCH bpf-next v2 5/5] selftests/bpf: Add test for "bpftool feature" command
On 2/21/20 12:28 PM, Quentin Monnet wrote:>> + def test_feature_macros(self):
Quoted 16 lines
Quoted 7 lines
+
expected_patterns= [
+ b"/\*\*\* System call availability \*\*\*/", + b"#defineHAVE_BPF_SYSCALL",
+ b"/\*\*\* eBPF program types \*\*\*/", + b"#define HAVE.*PROG_TYPE",
+ b"/\*\*\* eBPF map types \*\*\*/", + b"#define HAVE.*MAP_TYPE",Quoted 8 lines
+ b"/\*\*\* eBPF helper functions \*\*\*/", + b"#define HAVE.*HELPER",
+ b"/\*\*\* eBPF misc features \*\*\*/", + ]
+
+ res =bpftool(["feature", "probe", "macros"])+ for pattern inexpected_patterns:
+self.assertRegex(res, pattern)
Quoted 7 lines
Could we have (or did I miss it?) a test that compares the output of probes _with_ "full" and _without_ it, to make sure that the only lines that differ are about "
bpf_trace_prink" or "bpf_probe_write_user"? Could help determine if we filter out too many elements by mistake.Thanks,
Quentin
Good idea, I will add that test in v3.
Re: [PATCH bpf-next v2 5/5] selftests/bpf: Add test for "bpftool feature" command
In reply to Quentin MonnetQuoted 10 lines · Quentin Monnet
Quoted 9 lines
+ @default_iface
+ deftest_feature_dev(self, iface):
+expected_patterns= [
+SECTION_SYSCALL_CONFIG_PATTERN,
+SECTION_PROGRAM_TYPES_PATTERN,
+SECTION_MAP_TYPES_PATTERN,
+SECTION_HELPERS_PATTERN,
+SECTION_MISC_PATTERN,
+ ]
Quoted 3 lines
Mixed feeling on the tests with plain output, as we keep telling people that plain output should not be parsed (not reliable, may change). But if you want to run one or two tests with it, why not, I guess.
I thought about that and yes, testing the plain output is probably redundant and makes those tests less readable. However, the only plain output test which I would like to keep there is test_feature_macros - because I guess that we are not planning to change names or patterns of generated macros (or if so, we should test that change).
Re: [PATCH bpf-next v2 5/5] selftests/bpf: Add test for "bpftool feature" command
2020-02-25 14:55 UTC+0100 ~ Michal Rostecki <[email protected]>
Quoted 15 lines · Quentin Monnet
Quoted 10 lines
Quoted 9 lines
+ @default_iface
+ deftest_feature_dev(self, iface):
+expected_patterns= [
+SECTION_SYSCALL_CONFIG_PATTERN,
+SECTION_PROGRAM_TYPES_PATTERN,
+SECTION_MAP_TYPES_PATTERN,
+SECTION_HELPERS_PATTERN,
+SECTION_MISC_PATTERN,
+ ]Quoted 3 lines
Mixed feeling on the tests with plain output, as we keep telling people that plain output should not be parsed (not reliable, may change). But if you want to run one or two tests with it, why not, I guess.
Quoted 6 lines
I thought about that and yes, testing the plain output is probably redundant and makes those tests less readable. However, the only plain output test which I would like to keep there is
test_feature_macros- because I guess that we are not planning to change names or patterns of generated macros (or if so, we should test that change).
I did not mentally include the header/macros output in “plain output”, but yeah I guess I was not explicit on this one. So: Agreed, with “macros” it should not change and it is welcome in the tests, feel free to keep it :)
Quentin