libtracefs: Unit test for the tracing filter API
PATCH 1/1 libtracefs: Unit test for the tracing filter API
tracefs_function_filter();
utest/tracefs-utest.c +77 -0
@@ -11,6 +11,7 @@#include <time.h> #include <dirent.h> #include <ftw.h> +#include <errno.h> #include <CUnit/CUnit.h> #include <CUnit/Basic.h>
@@ -1020,6 +1021,80 @@ static void test_custom_trace_dir(void)free (dname); } +static int test_instance_filter (struct tracefs_instance *instance, +const char **filters,const char *module, +int flags) +{ +int ret; +int i; + +if (filters) { +for (i =0 ; filters[i]; i++) { + ret =tracefs_function_filter (instance, filters[i], + module, flags); +if (ret) { +if (errno ==EINVAL ) +printf ("Filter %s did not match\n" , + filters[i]); +else +printf ("Failed writing %s\n" , + filters[i]); + } + } + }else { + ret =tracefs_function_filter (instance,NULL , module, flags); + } +return ret; +} + +static void test_tracefs_function_filter (void ) +{ +const char *filter[] = {"run_init_process" ,"ufs*" ,"^ext4.*$" ,NULL }; +const char *future_filter[] = {"write_dummy" ,"read_dummy" ,NULL }; +const char *future_module ="dummy" ; +struct tracefs_instance *instance; +const char *module ="btrtl" ; +int ret; + + instance =tracefs_instance_create (TEST_INSTANCE_NAME ); +CU_TEST (instance !=NULL ); + + ret =tracefs_function_filter (instance,NULL ,NULL , +TRACEFS_FL_RESET |TRACEFS_FL_CONTINUE ); +if (ret) { +printf ("Failed to reset the filter\n" ); +if (ret <0 ) +tracefs_function_filter (instance,NULL ,NULL ,0 ); + } +/* Test string, kernel glob and regex for specific_instance*/ + ret =test_instance_filter (instance, filter,NULL ,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); +/* Test Module only with no filters*/ + ret =test_instance_filter (instance,NULL , module,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); + ret =test_instance_filter (instance, future_filter, future_module, +TRACEFS_FL_CONTINUE |TRACEFS_FL_FUTURE ); +CU_ASSERT (ret ==0 ); +tracefs_function_filter (instance,NULL ,NULL ,0 ); + + ret =tracefs_function_filter (NULL ,NULL ,NULL , +TRACEFS_FL_RESET |TRACEFS_FL_CONTINUE ); +if (ret) { +printf ("Failed to reset the filter\n" ); +if (ret <0 ) +tracefs_function_filter (instance,NULL ,NULL ,0 ); + } +/* Test top instance*/ + ret =test_instance_filter (NULL , filter,NULL ,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); + ret =test_instance_filter (NULL ,NULL , module,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); + ret =test_instance_filter (NULL , future_filter, future_module, +TRACEFS_FL_CONTINUE |TRACEFS_FL_FUTURE ); +CU_ASSERT (ret ==0 ); +tracefs_function_filter (NULL ,NULL ,NULL ,0 ); +} +static int test_suite_destroy (void ) {tracefs_instance_destroy (test_instance);
@@ -1075,4 +1150,6 @@ void test_tracefs_lib(void) test_tracing_options);CU_add_test (suite,"custom system directory" , test_custom_trace_dir); +CU_add_test (suite,"Set Filter API" , + test_tracefs_function_filter); }
Signature · 1 line
2.7.4
Quoted 1 line · On Sat, 3 Apr 2021 07:31:00 +0530 Sameeruddin shaik…
tracefs_function_filter();
Need some more information in the change log. What is this testing?
Quoted 38 lines
Signed-off-by Sameeruddin shaik <[email protected]>utest/tracefs-utest.c +20
-0@@ -11,6 +11,7 @@#include <time.h> #include <dirent.h> #include <ftw.h> +#include <errno.h> #include <CUnit/CUnit.h> #include <CUnit/Basic.h> @@ -1020,6 +1021,80 @@ static void test_custom_trace_dir(void)free (dname); } +static int test_instance_filter (struct tracefs_instance *instance, +const char **filters,const char *module, +int flags) +{ +int ret; +int i; + +if (filters) { +for (i =0 ; filters[i]; i++) { + ret =tracefs_function_filter (instance, filters[i], + module, flags); +if (ret) { +if (errno ==EINVAL ) +printf ("Filter %s did not match\n" , + filters[i]); +else +printf ("Failed writing %s\n" , + filters[i]); + }
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1052
Quoted 10 lines
utest/tracefs-utest.c +10
-0+ } + }else { + ret =tracefs_function_filter (instance,NULL , module, flags); + } +return ret; +} + +static void test_tracefs_function_filter (void ) +{ +const char *filter[] = {"run_init_process" ,"ufs*" ,"^ext4.*$" ,NULL };
I ran this and it failed, because my box has no functions that start with "ufs" nor "ext4" (I use an xfs file system).
You need to use core function names like "sched*" or "irq*", because ufs and ext4 are modules that do not exist in all machines that this may be executed on.
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1056
Quoted 4 lines
utest/tracefs-utest.c +4
-0+const char *future_filter[] = {"write_dummy" ,"read_dummy" ,NULL }; +const char *future_module ="dummy" ; +struct tracefs_instance *instance; +const char *module ="btrtl" ;
I also do not have the btrtl module. You may need to see what modules are loaded (reading /proc/modules will help you there).
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1065
Quoted 9 lines
utest/tracefs-utest.c +9
-0+int ret; + + instance =tracefs_instance_create (TEST_INSTANCE_NAME ); +CU_TEST (instance !=NULL ); + + ret =tracefs_function_filter (instance,NULL ,NULL , +TRACEFS_FL_RESET |TRACEFS_FL_CONTINUE ); +if (ret) { +printf ("Failed to reset the filter\n" );
Should the above be a CU_TEST failure?
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1078
Quoted 13 lines
utest/tracefs-utest.c +13
-0+if (ret <0 ) +tracefs_function_filter (instance,NULL ,NULL ,0 ); + } +/* Test string, kernel glob and regex for specific_instance*/ + ret =test_instance_filter (instance, filter,NULL ,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); +/* Test Module only with no filters*/ + ret =test_instance_filter (instance,NULL , module,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); + ret =test_instance_filter (instance, future_filter, future_module, +TRACEFS_FL_CONTINUE |TRACEFS_FL_FUTURE ); +CU_ASSERT (ret ==0 ); +tracefs_function_filter (instance,NULL ,NULL ,0 );
Should the above result also be tested?
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1082
Quoted 4 lines
utest/tracefs-utest.c +4
-0+ + ret =tracefs_function_filter (NULL ,NULL ,NULL , +TRACEFS_FL_RESET |TRACEFS_FL_CONTINUE ); +if (ret) {
And here too.
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1090
Quoted 8 lines
utest/tracefs-utest.c +8
-0+printf ("Failed to reset the filter\n" ); +if (ret <0 ) +tracefs_function_filter (instance,NULL ,NULL ,0 ); + } +/* Test top instance*/ + ret =test_instance_filter (NULL , filter,NULL ,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); + ret =test_instance_filter (NULL ,NULL , module,TRACEFS_FL_CONTINUE );
As I stated above, I don't have the module you picked, and will most definitely fail this test as FUTURE is not set.
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1096
Quoted 6 lines
utest/tracefs-utest.c +6
-0+CU_ASSERT (ret ==0 ); + ret =test_instance_filter (NULL , future_filter, future_module, +TRACEFS_FL_CONTINUE |TRACEFS_FL_FUTURE ); +CU_ASSERT (ret ==0 ); +tracefs_function_filter (NULL ,NULL ,NULL ,0 ); +}
Anyway, this is a good start.
Thanks!
-- Steve
Quoted 11 lines
utest/tracefs-utest.c +3
-0+static int test_suite_destroy (void ) {tracefs_instance_destroy (test_instance);@@ -1075,4 +1150,6 @@ void test_tracefs_lib(void) test_tracing_options);CU_add_test (suite,"custom system directory" , test_custom_trace_dir); +CU_add_test (suite,"Set Filter API" , + test_tracefs_function_filter); }
Quoted 90 lines · Steven Rostedt
Quoted 1 line · On Sat, 3 Apr 2021 07:31:00 +0530 Sameeruddin shaik…
tracefs_function_filter();Need some more information in the change log. What is this testing?
Quoted 37 lines
Signed-off-by Sameeruddin shaik <[email protected]>utest/tracefs-utest.c +20
-0@@ -11,6 +11,7 @@#include <time.h> #include <dirent.h> #include <ftw.h> +#include <errno.h> #include <CUnit/CUnit.h> #include <CUnit/Basic.h> @@ -1020,6 +1021,80 @@ static void test_custom_trace_dir(void)free (dname); } +static int test_instance_filter (struct tracefs_instance *instance, +const char **filters,const char *module, +int flags) +{ +int ret; +int i; + +if (filters) { +for (i =0 ; filters[i]; i++) { + ret =tracefs_function_filter (instance, filters[i], + module, flags); +if (ret) { +if (errno ==EINVAL ) +printf ("Filter %s did not match\n" , + filters[i]); +else +printf ("Failed writing %s\n" , + filters[i]); + }utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1052
Quoted 10 lines
utest/tracefs-utest.c +10
-0+ } + }else { + ret =tracefs_function_filter (instance,NULL , module, flags); + } +return ret; +} + +static void test_tracefs_function_filter (void ) +{ +const char *filter[] = {"run_init_process" ,"ufs*" ,"^ext4.*$" ,NULL };I ran this and it failed, because my box has no functions that start with "ufs" nor "ext4" (I use an xfs file system).
You need to use core function names like "sched*" or "irq*", because ufs and ext4 are modules that do not exist in all machines that this may be executed on.
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1056
Quoted 4 lines
utest/tracefs-utest.c +4
-0+const char *future_filter[] = {"write_dummy" ,"read_dummy" ,NULL }; +const char *future_module ="dummy" ; +struct tracefs_instance *instance; +const char *module ="btrtl" ;I also do not have the btrtl module. You may need to see what modules are loaded (reading
/proc/moduleswill help you there).utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1065
Quoted 9 lines
utest/tracefs-utest.c +9
-0+int ret; + + instance =tracefs_instance_create (TEST_INSTANCE_NAME ); +CU_TEST (instance !=NULL ); + + ret =tracefs_function_filter (instance,NULL ,NULL , +TRACEFS_FL_RESET |TRACEFS_FL_CONTINUE ); +if (ret) { +printf ("Failed to reset the filter\n" );Should the above be a
CU_TESTfailure?utest/tracefs-utest.c +13
-0+if (ret <0 ) +tracefs_function_filter (instance,NULL ,NULL ,0 ); + } +/* Test string, kernel glob and regex for specific_instance*/ + ret =test_instance_filter (instance, filter,NULL ,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); +/* Test Module only with no filters*/ + ret =test_instance_filter (instance,NULL , module,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); + ret =test_instance_filter (instance, future_filter, future_module, +TRACEFS_FL_CONTINUE |TRACEFS_FL_FUTURE ); +CU_ASSERT (ret ==0 ); +tracefs_function_filter (instance,NULL ,NULL ,0 );
Quoted 1 line
Should the above result also be tested?
Is it really needs to be tested?, because anyhow if we have any error, it will be thrown at the above lines
But anyhow, i will test the result here, since we are commiting the changes in the file.
Quoted 5 lines
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1082
Quoted 4 lines
utest/tracefs-utest.c +4
-0+ + ret =tracefs_function_filter (NULL ,NULL ,NULL , +TRACEFS_FL_RESET |TRACEFS_FL_CONTINUE ); +if (ret) {And here too.
okay.
Quoted 10 lines
utest/tracefs-utest.c static void test_custom_trace_dir(void) · line 1090
Quoted 8 lines
utest/tracefs-utest.c +8
-0+printf ("Failed to reset the filter\n" ); +if (ret <0 ) +tracefs_function_filter (instance,NULL ,NULL ,0 ); + } +/* Test top instance*/ + ret =test_instance_filter (NULL , filter,NULL ,TRACEFS_FL_CONTINUE ); +CU_ASSERT (ret ==0 ); + ret =test_instance_filter (NULL ,NULL , module,TRACEFS_FL_CONTINUE );As I stated above, I don't have the module you picked, and will most definitely fail this test as FUTURE is not set.
Yeah will try to add some standard modules.
Thanks,
sameer.