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

[or-cvs] Make unit tests (and others) run without launching listener...



Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv15355/src/or

Modified Files:
	config.c or.h test.c 
Log Message:
Make unit tests (and others) run without launching listeners, creating subdirectories, and so on.

Index: config.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/config.c,v
retrieving revision 1.401
retrieving revision 1.402
diff -u -d -r1.401 -r1.402
--- config.c	26 Aug 2005 22:03:57 -0000	1.401
+++ config.c	26 Aug 2005 23:22:27 -0000	1.402
@@ -411,9 +411,10 @@
   char *fn;
   size_t len;
   or_options_t *options = get_options();
+  int running_tor = options->command == CMD_RUN_TOR;
   static int libevent_initialized = 0;
 
-  if (options->RunAsDaemon) {
+  if (running_tor && options->RunAsDaemon) {
     start_daemon();
   }
 
@@ -426,7 +427,7 @@
     }
   }
 
-  if (rend_config_services(options, 0)<0) {
+  if (running_tor && rend_config_services(options, 0)<0) {
     log_fn(LOG_ERR,
            "Bug: Previously validated hidden services line could not be added!");
     return -1;
@@ -448,15 +449,18 @@
            options->DataDirectory);
     return -1;
   }
-  len = strlen(options->DataDirectory)+32;
-  fn = tor_malloc(len);
-  tor_snprintf(fn, len, "%s/cached-status", options->DataDirectory);
-  if (check_private_dir(fn, CPD_CREATE) != 0) {
-    log_fn(LOG_ERR, "Couldn't access/create private data directory \"%s\"",fn);
+  if (running_tor) {
+    len = strlen(options->DataDirectory)+32;
+    fn = tor_malloc(len);
+    tor_snprintf(fn, len, "%s/cached-status", options->DataDirectory);
+    if (check_private_dir(fn, CPD_CREATE) != 0) {
+      log_fn(LOG_ERR, "Couldn't access/create private data directory \"%s\"",
+             fn);
+      tor_free(fn);
+      return -1;
+    }
     tor_free(fn);
-    return -1;
   }
-  tor_free(fn);
 
   /* Bail out at this point if we're not going to be a client or server:
    * we want to not fork, and to log stuff to stderr. */
@@ -474,7 +478,7 @@
   control_adjust_event_log_severity();
 
   /* Set up libevent. */
-  if (!libevent_initialized) {
+  if (running_tor && !libevent_initialized) {
     if (init_libevent())
       return -1;
     libevent_initialized = 1;
@@ -500,14 +504,14 @@
   }
 
   /* Finish backgrounding the process */
-  if (options->RunAsDaemon) {
+  if (running_tor && options->RunAsDaemon) {
     /* We may be calling this for the n'th time (on SIGHUP), but it's safe. */
     finish_daemon(options->DataDirectory);
   }
 
   /* Write our pid to the pid file. If we do not have write permissions we
    * will log a warning */
-  if (options->PidFile)
+  if (running_tor && options->PidFile)
     write_pidfile(options->PidFile);
 
   /* Register addressmap directives */
@@ -534,6 +538,9 @@
   if (accounting_is_enabled(options))
     configure_accounting(time(NULL));
 
+  if (!running_tor)
+    return 0;
+
   if (!we_are_hibernating() && retry_all_listeners(0) < 0) {
     log_fn(LOG_ERR,"Failed to bind one of the listener ports.");
     return -1;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.658
retrieving revision 1.659
diff -u -d -r1.658 -r1.659
--- or.h	26 Aug 2005 21:28:16 -0000	1.658
+++ or.h	26 Aug 2005 23:22:27 -0000	1.659
@@ -1034,7 +1034,7 @@
   /** What should the tor process actually do? */
   enum {
     CMD_RUN_TOR=0, CMD_LIST_FINGERPRINT, CMD_HASH_PASSWORD,
-    CMD_VERIFY_CONFIG,
+    CMD_VERIFY_CONFIG, CMD_RUN_UNITTESTS
   } command;
   const char *command_arg; /**< Argument for command-line option. */
 

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/test.c,v
retrieving revision 1.195
retrieving revision 1.196
diff -u -d -r1.195 -r1.196
--- test.c	26 Aug 2005 21:28:16 -0000	1.195
+++ test.c	26 Aug 2005 23:22:27 -0000	1.196
@@ -114,7 +114,8 @@
     /* Only "." and ".." start with ., since we don't create any dotfiles. */
     if (de->d_name[0] == '.') continue;
     if (unlink(get_fname(de->d_name))) {
-      perror("Error removing file");
+      printf("Couldn't remove temprorary file \"%s/%s\"",temp_dir,de->d_name);
+      perror("");
     }
 #if 0
     printf("==%s\n", de->d_name);
@@ -1522,6 +1523,7 @@
 main(int c, char**v)
 {
   or_options_t *options = options_new();
+  options->command = CMD_RUN_UNITTESTS;
   network_init();
   setup_directory();
   options_init(options);