Unit tests for tracefs APIs, checking for ftrace file / directory existence: bool tracefs_file_exist(struct tracefs_instance *instance, char *name); bool tracefs_dir_exist(struct tracefs_instance *instance, char *name); Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@xxxxxxxxx> --- utest/tracefs-utest.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/utest/tracefs-utest.c b/utest/tracefs-utest.c index 2473e893..3f57ecad 100644 --- a/utest/tracefs-utest.c +++ b/utest/tracefs-utest.c @@ -175,6 +175,7 @@ static void test_instance_file_read(struct tracefs_instance *inst, char *fname) #define ALL_TRACERS "available_tracers" #define CUR_TRACER "current_tracer" +#define PER_CPU "per_cpu" static void test_instance_file(void) { struct tracefs_instance *instance = NULL; @@ -251,6 +252,21 @@ static void test_instance_file(void) tracefs_put_tracing_file(inst_file); free(fname); + CU_TEST(tracefs_file_exist(NULL, (char *)name) == false); + CU_TEST(tracefs_dir_exist(NULL, (char *)name) == false); + CU_TEST(tracefs_file_exist(instance, (char *)name) == false); + CU_TEST(tracefs_dir_exist(instance, (char *)name) == false); + + CU_TEST(tracefs_file_exist(NULL, CUR_TRACER) == true); + CU_TEST(tracefs_dir_exist(NULL, CUR_TRACER) == false); + CU_TEST(tracefs_file_exist(instance, CUR_TRACER) == true); + CU_TEST(tracefs_dir_exist(instance, CUR_TRACER) == false); + + CU_TEST(tracefs_file_exist(NULL, PER_CPU) == false); + CU_TEST(tracefs_dir_exist(NULL, PER_CPU) == true); + CU_TEST(tracefs_file_exist(instance, PER_CPU) == false); + CU_TEST(tracefs_dir_exist(instance, PER_CPU) == true); + CU_TEST(tracefs_instance_destroy(NULL) != 0); CU_TEST(tracefs_instance_destroy(instance) == 0); CU_TEST(tracefs_instance_destroy(instance) != 0); -- 2.24.1