commit 17ed2fed68ed18480976748e3f407bf6952ab72c Author: Andrea Shepard andrea@torproject.org Date: Sat Jun 25 06:26:44 2016 +0000
Expose dump_desc() to the test suite and make things it calls mockable --- src/common/util.c | 14 ++++++++++++-- src/common/util.h | 5 ++++- src/or/routerparse.c | 4 ++-- src/or/routerparse.h | 1 + 4 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/common/util.c b/src/common/util.c index 4b6df81..d4553c3 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -2013,6 +2013,16 @@ clean_name_for_stat(char *name) #endif }
+/** Wrapper for unlink() to make it mockable for the test suite; returns 0 + * if unlinking the file succeeded, -1 and sets errno if unlinking fails. + */ + +MOCK_IMPL(int, +tor_unlink,(const char *pathname)) +{ + return unlink(pathname); +} + /** Return: * FN_ERROR if filename can't be read, is NULL, or is zero-length, * FN_NOENT if it doesn't exist, @@ -2306,8 +2316,8 @@ check_private_dir(const char *dirname, cpd_check_t check, * function, and all other functions in util.c that create files, create them * with mode 0600. */ -int -write_str_to_file(const char *fname, const char *str, int bin) +MOCK_IMPL(int, +write_str_to_file,(const char *fname, const char *str, int bin)) { #ifdef _WIN32 if (!bin && strchr(str, '\r')) { diff --git a/src/common/util.h b/src/common/util.h index 7cb33dc..fd9b983 100644 --- a/src/common/util.h +++ b/src/common/util.h @@ -309,6 +309,8 @@ const char *stream_status_to_string(enum stream_status stream_status);
enum stream_status get_string_from_pipe(FILE *stream, char *buf, size_t count);
+MOCK_DECL(int,tor_unlink,(const char *pathname)); + /** Return values from file_status(); see that function's documentation * for details. */ typedef enum { FN_ERROR, FN_NOENT, FN_FILE, FN_DIR, FN_EMPTY } file_status_t; @@ -338,7 +340,8 @@ FILE *start_writing_to_stdio_file(const char *fname, int open_flags, int mode, FILE *fdopen_file(open_file_t *file_data); int finish_writing_to_file(open_file_t *file_data); int abort_writing_to_file(open_file_t *file_data); -int write_str_to_file(const char *fname, const char *str, int bin); +MOCK_DECL(int, +write_str_to_file,(const char *fname, const char *str, int bin)); MOCK_DECL(int, write_bytes_to_file,(const char *fname, const char *str, size_t len, int bin)); diff --git a/src/or/routerparse.c b/src/or/routerparse.c index 1d227fd..eacf9aa 100644 --- a/src/or/routerparse.c +++ b/src/or/routerparse.c @@ -646,7 +646,7 @@ dump_desc_fifo_add_and_clean(char *filename, const uint8_t *digest_sha256, */ if (strcmp(tmp->filename, filename) != 0) { /* Delete it and adjust the length counter */ - unlink(tmp->filename); + tor_unlink(tmp->filename); tor_assert(len_descs_dumped >= tmp->len); len_descs_dumped -= tmp->len; log_info(LD_DIR, @@ -736,7 +736,7 @@ dump_desc_fifo_cleanup(void) * type *<b>type</b> to file $DATADIR/unparseable-desc. Do not write more * than one descriptor to disk per minute. If there is already such a * file in the data directory, overwrite it. */ -static void +STATIC void dump_desc(const char *desc, const char *type) { tor_assert(desc); diff --git a/src/or/routerparse.h b/src/or/routerparse.h index 69160d1..fe32fb7 100644 --- a/src/or/routerparse.h +++ b/src/or/routerparse.h @@ -92,6 +92,7 @@ STATIC int routerstatus_parse_guardfraction(const char *guardfraction_str, networkstatus_t *vote, vote_routerstatus_t *vote_rs, routerstatus_t *rs); +STATIC void dump_desc(const char *desc, const char *type); #endif
#define ED_DESC_SIGNATURE_PREFIX "Tor router descriptor signature v1"