[or-cvs] Re-enable unit tests for directory generation.

Nick Mathewson nickm at seul.org
Mon Mar 29 19:51:01 UTC 2004


Update of /home/or/cvsroot/src/or
In directory moria.mit.edu:/tmp/cvs-serv15791/src/or

Modified Files:
	dirserv.c routerlist.c test.c 
Log Message:
Re-enable unit tests for directory generation.

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/src/or/dirserv.c,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -d -r1.30 -r1.31
--- dirserv.c	29 Mar 2004 19:28:15 -0000	1.30
+++ dirserv.c	29 Mar 2004 19:50:59 -0000	1.31
@@ -26,7 +26,7 @@
 static fingerprint_entry_t fingerprint_list[MAX_ROUTERS_IN_DIR];
 static int n_fingerprints = 0;
 
-static void
+void /* Should be static; exposed for testing */
 add_fingerprint_to_dir(const char *nickname, const char *fp)
 {
   int i;

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- routerlist.c	28 Mar 2004 04:54:36 -0000	1.41
+++ routerlist.c	29 Mar 2004 19:50:59 -0000	1.42
@@ -111,7 +111,7 @@
 router_get_list_from_string_impl(const char **s, routerlist_t **dest,
                                  int n_good_nicknames,
                                  const char **good_nickname_lst);
-static int
+int /* Exposed for unit tests */
 router_get_routerlist_from_directory_impl(const char *s, routerlist_t **dest,
                                           crypto_pk_env_t *pkey);
 static int
@@ -119,8 +119,6 @@
 static int
 router_resolve_routerlist(routerlist_t *dir);
 
-
-
 static int router_get_hash_impl(const char *s, char *digest,
                                 const char *start_str, const char *end_str);
 static void token_free(directory_token_t *tok);
@@ -575,7 +573,7 @@
  * resulting routerlist in *dest, freeing the old value if necessary.
  * If pkey is provided, we check the directory signature with pkey.
  */
-static int
+int /* Should be static; exposed for unit tests */
 router_get_routerlist_from_directory_impl(const char *str, 
                                           routerlist_t **dest,
                                           crypto_pk_env_t *pkey)

Index: test.c
===================================================================
RCS file: /home/or/cvsroot/src/or/test.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -u -d -r1.66 -r1.67
--- test.c	28 Mar 2004 04:54:36 -0000	1.66
+++ test.c	29 Mar 2004 19:50:59 -0000	1.67
@@ -17,6 +17,11 @@
 
 int have_failed = 0;
 
+/* These functions are file-local, but are exposed so we can test. */
+int router_get_routerlist_from_directory_impl(
+        const char *s, routerlist_t **dest, crypto_pk_env_t *pkey);
+void add_fingerprint_to_dir(const char *nickname, const char *fp);
+
 void
 dump_hex(char *s, int len)
 {
@@ -667,6 +672,7 @@
   r2.link_pkey = pk2;
   r2.bandwidthrate = r2.bandwidthburst = 3000;
   r2.exit_policy = &ex1;
+  r2.nickname = "Fred";
 
   test_assert(!crypto_pk_write_public_key_to_string(pk1, &pk1_str,
                                                     &pk1_str_len));
@@ -740,22 +746,27 @@
   test_assert(rp2->exit_policy->next->next == NULL);
 #endif
 
-#if 0
-  /* XXX To re-enable this test, we need to separate directory generation
-   * XXX from the directory backend again.  Do this the next time we have
-   * XXX directory trouble. */
   /* Okay, now for the directories. */
-  dir1 = (directory_t*) tor_malloc(sizeof(directory_t));
-  dir1->n_routers = 2;
-  dir1->routers = (routerinfo_t**) tor_malloc(sizeof(routerinfo_t*)*2);
-  dir1->routers[0] = &r1;
-  dir1->routers[1] = &r2;
-  test_assert(! dump_signed_directory_to_string_impl(buf, 4096, dir1, pk1));
-  /* puts(buf); */
-
-  test_assert(! router_get_dir_from_string_impl(buf, &dir2, pk1));
-  test_eq(2, dir2->n_routers);
-#endif
+  crypto_pk_get_fingerprint(pk2, buf);
+  add_fingerprint_to_dir("Magri", buf);
+  crypto_pk_get_fingerprint(pk1, buf);
+  add_fingerprint_to_dir("Fred", buf);
+  /* Make sure routers aren't too far in the past any more. */
+  r1.published_on = time(NULL);
+  r2.published_on = time(NULL)-3*60*60;
+  test_assert(router_dump_router_to_string(buf, 2048, &r1, pk2)>0);
+  cp = buf;
+  test_eq(dirserv_add_descriptor((const char**)&cp), 1);
+  test_assert(router_dump_router_to_string(buf, 2048, &r2, pk1)>0);
+  cp = buf;
+  test_eq(dirserv_add_descriptor((const char**)&cp), 1);
+  extern or_options_t options;
+  options.Nickname = "DirServer";
+  test_assert(!dirserv_dump_directory_to_string(buf,8192,pk3));
+  cp = buf;
+  test_assert(!router_get_routerlist_from_directory_impl(buf, &dir1, pk3));
+  test_eq(2, dir1->n_routers);
+  dirserv_free_fingerprint_list();
 
   tor_free(pk1_str);
   tor_free(pk2_str);
@@ -763,7 +774,7 @@
   if (pk2) crypto_free_pk_env(pk2);
   if (rp1) routerinfo_free(rp1);
   if (rp2) routerinfo_free(rp2);
-  tor_free(dir1); /* And more !*/
+  tor_free(dir1); /* XXXX And more !*/
   tor_free(dir2); /* And more !*/
 
   /* make sure is_recommended_version() works */



More information about the tor-commits mailing list