Test fix: clean trace files left behind by test_ctf_ir_ref
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 May 2016 03:57:34 +0000 (23:57 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 3 May 2016 03:57:34 +0000 (23:57 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/lib/Makefile.am
tests/lib/common.c
tests/lib/common.h
tests/lib/test_ctf_ir_ref.c
tests/lib/test_ctf_writer.c

index c9c27d0718906118ef5b5603a3e642c86fa41589..a8c94488b4a583869571fc8a16d9ff050a670fc0 100644 (file)
@@ -18,14 +18,16 @@ test_bitfield_LDADD = $(LIBTAP) libtestcommon.a
 
 test_ctf_writer_LDADD = $(LIBTAP) \
        $(top_builddir)/lib/libbabeltrace.la \
-       $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
+       $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \
+       libtestcommon.a
 
 test_bt_values_LDADD = $(LIBTAP) \
        $(top_builddir)/lib/libbabeltrace.la
 
 test_ctf_ir_ref_LDADD = $(LIBTAP) \
        $(top_builddir)/lib/libbabeltrace.la \
-       $(top_builddir)/formats/ctf/libbabeltrace-ctf.la
+       $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \
+       libtestcommon.a
 
 test_bt_ctf_field_type_validation_LDADD = $(LIBTAP) \
        $(top_builddir)/lib/libbabeltrace.la \
index 60e2be04244a34b821d5e93bb14a57d85530e42d..d137cb304a764f3a3680af7284fbb1c60aad6054 100644 (file)
@@ -21,6 +21,8 @@
 
 #include <babeltrace/context.h>
 #include <babeltrace/iterator.h>
+#include <babeltrace/compat/dirent.h>
+#include <sys/stat.h>
 
 struct bt_context *create_context_with_path(const char *path)
 {
@@ -39,3 +41,35 @@ struct bt_context *create_context_with_path(const char *path)
        }
        return ctx;
 }
+
+void recursive_rmdir(const char *path)
+{
+       struct dirent *entry;
+       DIR *dir = opendir(path);
+
+       if (!dir) {
+               perror("# opendir");
+               return;
+       }
+
+       while ((entry = readdir(dir))) {
+               struct stat st;
+               char filename[PATH_MAX];
+
+               if (snprintf(filename, sizeof(filename), "%s/%s",
+                               path, entry->d_name) <= 0) {
+                       continue;
+               }
+
+               if (stat(filename, &st)) {
+                       continue;
+               }
+
+               if (S_ISREG(st.st_mode)) {
+                       unlinkat(bt_dirfd(dir), entry->d_name, 0);
+               }
+       }
+
+       rmdir(path);
+       closedir(dir);
+}
index 25a02ffadc81ecb559cdc596cf4cd0bccf2a8763..06ea63b56047a05fae93e8ed9c74bf27d42f3d7a 100644 (file)
@@ -4,6 +4,7 @@
  * Lib BabelTrace - Common function to all tests
  *
  * Copyright 2012 - Yannick Brosseau <yannick.brosseau@gmail.com>
+ * Copyright 2016 - Jérémie Galarneau <jeremie.galarneau@efficios.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -23,6 +24,7 @@
 
 struct bt_context;
 
+void recursive_rmdir(const char *path);
 struct bt_context *create_context_with_path(const char *path);
 
 #endif /* _TESTS_COMMON_H */
index d30195c8eb2017dfb2d15a6f83127ffa827d7ca0..5d0816b136675592efb6888a7cdd45d5e9123258 100644 (file)
@@ -32,6 +32,7 @@
 #include <babeltrace/object-internal.h>
 #include <babeltrace/compat/stdlib.h>
 #include <assert.h>
+#include "common.h"
 
 #define NR_TESTS 41
 
@@ -551,6 +552,7 @@ static void create_user_full(struct user *user)
        BT_PUT(field);
        ret = bt_ctf_stream_append_event(user->stream, user->event);
        assert(!ret);
+       recursive_rmdir(trace_path);
 }
 
 static void test_put_order_swap(size_t *array, size_t a, size_t b)
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.028892 seconds and 4 git commands to generate.