[tor-commits] [tor/master] core/or: Make some functions mockable

nickm at torproject.org nickm at torproject.org
Thu Apr 9 15:56:22 UTC 2020


commit 2b66429fcfe3dbbaa559b0b2de910e0266f27698
Author: teor <teor at torproject.org>
Date:   Mon Apr 6 19:14:27 2020 +1000

    core/or: Make some functions mockable
    
    Preparation for testing circuit_extend().
    
    Part of 33633.
---
 src/core/or/channel.c      | 16 ++++++++--------
 src/core/or/channel.h      |  7 ++++---
 src/core/or/circuitbuild.c |  8 ++++----
 src/core/or/circuitbuild.h |  8 ++++----
 src/core/or/onion.c        |  8 +++++---
 src/core/or/onion.h        |  6 ++++--
 6 files changed, 29 insertions(+), 24 deletions(-)

diff --git a/src/core/or/channel.c b/src/core/or/channel.c
index 542b4d88b..9c1e8368e 100644
--- a/src/core/or/channel.c
+++ b/src/core/or/channel.c
@@ -2370,12 +2370,12 @@ channel_is_better(channel_t *a, channel_t *b)
  * and set *launch_out to a boolean indicated whether the caller should try to
  * launch a new channel with channel_connect().
  */
-channel_t *
-channel_get_for_extend(const char *rsa_id_digest,
-                       const ed25519_public_key_t *ed_id,
-                       const tor_addr_t *target_addr,
-                       const char **msg_out,
-                       int *launch_out)
+MOCK_IMPL(channel_t *,
+channel_get_for_extend,(const char *rsa_id_digest,
+                        const ed25519_public_key_t *ed_id,
+                        const tor_addr_t *target_addr,
+                        const char **msg_out,
+                        int *launch_out))
 {
   channel_t *chan, *best = NULL;
   int n_inprogress_goodaddr = 0, n_old = 0;
@@ -2821,8 +2821,8 @@ channel_get_actual_remote_address(channel_t *chan)
  * Subsequent calls to channel_get_{actual,canonical}_remote_{address,descr}
  * may invalidate the return value from this function.
  */
-const char *
-channel_get_canonical_remote_descr(channel_t *chan)
+MOCK_IMPL(const char *,
+channel_get_canonical_remote_descr,(channel_t *chan))
 {
   tor_assert(chan);
   tor_assert(chan->get_remote_descr);
diff --git a/src/core/or/channel.h b/src/core/or/channel.h
index 2e2936a69..49331d5d5 100644
--- a/src/core/or/channel.h
+++ b/src/core/or/channel.h
@@ -658,11 +658,12 @@ channel_t * channel_connect(const tor_addr_t *addr, uint16_t port,
                             const char *rsa_id_digest,
                             const struct ed25519_public_key_t *ed_id);
 
-channel_t * channel_get_for_extend(const char *rsa_id_digest,
+MOCK_DECL(channel_t *, channel_get_for_extend,(
+                                   const char *rsa_id_digest,
                                    const struct ed25519_public_key_t *ed_id,
                                    const tor_addr_t *target_addr,
                                    const char **msg_out,
-                                   int *launch_out);
+                                   int *launch_out));
 
 /* Ask which of two channels is better for circuit-extension purposes */
 int channel_is_better(channel_t *a, channel_t *b);
@@ -723,7 +724,7 @@ const char * channel_get_actual_remote_descr(channel_t *chan);
 const char * channel_get_actual_remote_address(channel_t *chan);
 MOCK_DECL(int, channel_get_addr_if_possible, (channel_t *chan,
                                               tor_addr_t *addr_out));
-const char * channel_get_canonical_remote_descr(channel_t *chan);
+MOCK_DECL(const char *, channel_get_canonical_remote_descr,(channel_t *chan));
 int channel_has_queued_writes(channel_t *chan);
 int channel_is_bad_for_new_circs(channel_t *chan);
 void channel_mark_bad_for_new_circs(channel_t *chan);
diff --git a/src/core/or/circuitbuild.c b/src/core/or/circuitbuild.c
index 71a51e61a..ce0f9618f 100644
--- a/src/core/or/circuitbuild.c
+++ b/src/core/or/circuitbuild.c
@@ -698,10 +698,10 @@ circuit_n_chan_done(channel_t *chan, int status, int close_origin_circuits)
  * gave us via an EXTEND cell, so we shouldn't worry if we don't understand
  * it. Return -1 if we failed to find a suitable circid, else return 0.
  */
-int
-circuit_deliver_create_cell(circuit_t *circ,
-                            const struct create_cell_t *create_cell,
-                            int relayed)
+MOCK_IMPL(int,
+circuit_deliver_create_cell,(circuit_t *circ,
+                             const struct create_cell_t *create_cell,
+                             int relayed))
 {
   cell_t cell;
   circid_t id;
diff --git a/src/core/or/circuitbuild.h b/src/core/or/circuitbuild.h
index cf9999092..e62bb41de 100644
--- a/src/core/or/circuitbuild.h
+++ b/src/core/or/circuitbuild.h
@@ -80,10 +80,10 @@ channel_connect_for_circuit,(const tor_addr_t *addr,
                              const struct ed25519_public_key_t *ed_id));
 
 struct create_cell_t;
-int
-circuit_deliver_create_cell(circuit_t *circ,
-                            const struct create_cell_t *create_cell,
-                            int relayed);
+MOCK_DECL(int,
+circuit_deliver_create_cell,(circuit_t *circ,
+                             const struct create_cell_t *create_cell,
+                             int relayed));
 
 #ifdef CIRCUITBUILD_PRIVATE
 STATIC circid_t get_unique_circ_id_by_chan(channel_t *chan);
diff --git a/src/core/or/onion.c b/src/core/or/onion.c
index 4a5b296b9..45144b5e6 100644
--- a/src/core/or/onion.c
+++ b/src/core/or/onion.c
@@ -374,9 +374,11 @@ extend_cell_from_extend2_cell_body(extend_cell_t *cell_out,
 /** Parse an EXTEND or EXTEND2 cell (according to <b>command</b>) from the
  * <b>payload_length</b> bytes of <b>payload</b> into <b>cell_out</b>. Return
  * 0 on success, -1 on failure. */
-int
-extend_cell_parse(extend_cell_t *cell_out, const uint8_t command,
-                  const uint8_t *payload, size_t payload_length)
+MOCK_IMPL(int,
+extend_cell_parse,(extend_cell_t *cell_out,
+                   const uint8_t command,
+                   const uint8_t *payload,
+                   size_t payload_length))
 {
 
   tor_assert(cell_out);
diff --git a/src/core/or/onion.h b/src/core/or/onion.h
index ff3083f37..72470d1cb 100644
--- a/src/core/or/onion.h
+++ b/src/core/or/onion.h
@@ -74,8 +74,10 @@ void create_cell_init(create_cell_t *cell_out, uint8_t cell_type,
                       const uint8_t *onionskin);
 int create_cell_parse(create_cell_t *cell_out, const cell_t *cell_in);
 int created_cell_parse(created_cell_t *cell_out, const cell_t *cell_in);
-int extend_cell_parse(extend_cell_t *cell_out, const uint8_t command,
-                      const uint8_t *payload_in, size_t payload_len);
+MOCK_DECL(int,extend_cell_parse,(extend_cell_t *cell_out,
+                                 const uint8_t command,
+                                 const uint8_t *payload_in,
+                                 size_t payload_len));
 int extended_cell_parse(extended_cell_t *cell_out, const uint8_t command,
                         const uint8_t *payload_in, size_t payload_len);
 





More information about the tor-commits mailing list