ソースを参照

Make get_total_system_memory mockable.

This patch makes get_total_system_memory mockable, which allows us to
alter the return value of the function in tests.

See: https://bugs.torproject.org/24782
Alexander Færøy 6 年 前
コミット
bd42367a1e
2 ファイル変更3 行追加3 行削除
  1. 2 2
      src/common/compat.c
  2. 1 1
      src/common/compat.h

+ 2 - 2
src/common/compat.c

@@ -3409,8 +3409,8 @@ get_total_system_memory_impl(void)
  * Try to find out how much physical memory the system has. On success,
  * return 0 and set *<b>mem_out</b> to that value. On failure, return -1.
  */
-int
-get_total_system_memory(size_t *mem_out)
+MOCK_IMPL(int,
+get_total_system_memory, (size_t *mem_out))
 {
   static size_t mem_cached=0;
   uint64_t m = get_total_system_memory_impl();

+ 1 - 1
src/common/compat.h

@@ -699,7 +699,7 @@ char *make_path_absolute(char *fname);
 
 char **get_environment(void);
 
-int get_total_system_memory(size_t *mem_out);
+MOCK_DECL(int, get_total_system_memory, (size_t *mem_out));
 
 int compute_num_cpus(void);