[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor/master] Tweak 4282 unit tests for style, safety, correctness.



commit 58721ac24c684236c52c062a255c38f2f019fda5
Author: Nick Mathewson <nickm@xxxxxxxxxxxxxx>
Date:   Fri May 24 13:31:10 2013 -0400

    Tweak 4282 unit tests for style, safety, correctness.
    
    We do our filesystem wrangling relative to get_fname() results, so
    that if we fail or crash, we can always clean up.
---
 src/test/test_config.c |   35 ++++++++++++++++++++---------------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/src/test/test_config.c b/src/test/test_config.c
index 78def70..8316d0e 100644
--- a/src/test/test_config.c
+++ b/src/test/test_config.c
@@ -170,7 +170,7 @@ test_config_addressmap(void *arg)
  done:
   ;
 }
- 
+
 static int
 is_private_dir(const char* path)
 {
@@ -180,7 +180,7 @@ is_private_dir(const char* path)
     return 0;
   }
 #if !defined (_WIN32) || defined (WINCE)
-  if (st.st_mode != (S_IFDIR | 0700)) {
+  if ((st.st_mode & (S_IFDIR | 0777)) != (S_IFDIR | 0700)) {
     return 0;
   }
 #endif
@@ -190,11 +190,14 @@ is_private_dir(const char* path)
 static void
 test_config_check_or_create_data_subdir(void *arg)
 {
-  or_options_t* options = get_options_mutable();
-  options->DataDirectory = "test_data";
-  const char* subdir = "test_stats";
-  const char* subpath = get_datadir_fname(subdir);
+  or_options_t *options = get_options_mutable();
+  char *datadir = options->DataDirectory = tor_strdup(get_fname("datadir-0"));
+  const char *subdir = "test_stats";
+  const char *subpath = get_datadir_fname(subdir);
   struct stat st;
+  int r;
+  unsigned group_permission;
+  (void)arg;
 
 #if defined (_WIN32) && !defined (WINCE)
   mkdir(options->DataDirectory);
@@ -202,7 +205,7 @@ test_config_check_or_create_data_subdir(void *arg)
   mkdir(options->DataDirectory, 0700);
 #endif
 
-  int r = stat(subpath, &st);
+  r = stat(subpath, &st);
 
   // The subdirectory shouldn't exist yet,
   // but should be created by the call to check_or_create_data_subdir.
@@ -215,7 +218,7 @@ test_config_check_or_create_data_subdir(void *arg)
   test_assert(!check_or_create_data_subdir(subdir));
 
 #if !defined (_WIN32) || defined (WINCE)
-  unsigned group_permission = st.st_mode | 0070;
+  group_permission = st.st_mode | 0070;
   r = chmod(subpath, group_permission);
 
   if (r) {
@@ -229,16 +232,16 @@ test_config_check_or_create_data_subdir(void *arg)
   test_assert(is_private_dir(subpath));
 #endif
 
-  done:
-    rmdir(subpath);
-    rmdir(options->DataDirectory);
+ done:
+  rmdir(subpath);
+  tor_free(datadir);
 }
 
 static void
-test_config_write_to_data_subdir(void* arg)
+test_config_write_to_data_subdir(void *arg)
 {
   or_options_t* options = get_options_mutable();
-  options->DataDirectory = "test_data";
+  char *datadir = options->DataDirectory = tor_strdup(get_fname("datadir-1"));
   const char* subdir = "test_stats";
   const char* fname = "test_file";
   const char* str =
@@ -258,6 +261,7 @@ test_config_write_to_data_subdir(void* arg)
       "sanctus est Lorem ipsum dolor sit amet.";
   const char* subpath = get_datadir_fname(subdir);
   const char* filepath = get_datadir_fname2(subdir, fname);
+  (void)arg;
 
 #if defined (_WIN32) && !defined (WINCE)
   mkdir(options->DataDirectory);
@@ -282,6 +286,7 @@ test_config_write_to_data_subdir(void* arg)
   remove(filepath);
   rmdir(subpath);
   rmdir(options->DataDirectory);
+  tor_free(datadir);
 }
 
 /* Test helper function: Make sure that a bridge line gets parsed
@@ -437,8 +442,8 @@ test_config_parse_bridge_line(void *arg)
 struct testcase_t config_tests[] = {
   CONFIG_TEST(addressmap, 0),
   CONFIG_TEST(parse_bridge_line, 0),
-  CONFIG_TEST(check_or_create_data_subdir, 0),
-  CONFIG_TEST(write_to_data_subdir, 0),
+  CONFIG_TEST(check_or_create_data_subdir, TT_FORK),
+  CONFIG_TEST(write_to_data_subdir, TT_FORK),
   END_OF_TESTCASES
 };
 



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits