Test fix: clean trace files left behind by test_ctf_ir_ref
[babeltrace.git] / tests / lib / test_ctf_writer.c
index 370de0f72512b43457d795312491bab69a423c27..321a4ac5fbe50a0d6ac899a2ee5ef7abaaa7b154 100644 (file)
@@ -44,7 +44,7 @@
 #include "tap/tap.h"
 #include <math.h>
 #include <float.h>
-#include <sys/stat.h>
+#include "common.h"
 
 #define METADATA_LINE_SIZE 512
 #define SEQUENCE_TEST_LENGTH 10
 
 static int64_t current_time = 42;
 
-static
-void delete_trace(const char *trace_path)
-{
-       /* Remove all trace files and delete temporary trace directory */
-       struct dirent *entry;
-       DIR *trace_dir = opendir(trace_path);
-
-       if (!trace_dir) {
-               perror("# opendir");
-               return;
-       }
-
-       while ((entry = readdir(trace_dir))) {
-               struct stat st;
-               char filename[PATH_MAX];
-
-               if (snprintf(filename, sizeof(filename), "%s/%s",
-                            trace_path, entry->d_name) <= 0) {
-                       continue;
-               }
-
-               if (stat(filename, &st)) {
-                       continue;
-               }
-
-               if (S_ISREG(st.st_mode)) {
-                       unlinkat(bt_dirfd(trace_dir), entry->d_name, 0);
-               }
-       }
-
-       rmdir(trace_path);
-       closedir(trace_dir);
-}
-
 /* Return 1 if uuids match, zero if different. */
 static
 int uuid_match(const unsigned char *uuid_a, const unsigned char *uuid_b)
@@ -2919,7 +2885,7 @@ void test_create_writer_vs_non_writer_mode(void)
        bt_put(non_writer_clock);
        bt_put(packet);
        bt_put(packet2);
-       delete_trace(trace_path);
+       recursive_rmdir(trace_path);
 }
 
 static
@@ -3637,6 +3603,6 @@ int main(int argc, char **argv)
        free(metadata_string);
        bt_put(stream_class);
 
-       delete_trace(trace_path);
+        recursive_rmdir(trace_path);
        return 0;
 }
This page took 0.026321 seconds and 4 git commands to generate.