|
@@ -585,6 +585,22 @@ test_config_parse_transport_options_line(void *arg)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+static int get_total_system_memory_mock(size_t *mem_out);
|
|
|
+
|
|
|
+static size_t total_system_memory_output = 0;
|
|
|
+static int total_system_memory_return = 0;
|
|
|
+
|
|
|
+static int
|
|
|
+get_total_system_memory_mock(size_t *mem_out)
|
|
|
+{
|
|
|
+ if (! mem_out)
|
|
|
+ return -1;
|
|
|
+
|
|
|
+ *mem_out = total_system_memory_output;
|
|
|
+ return total_system_memory_return;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
static void pt_kickstart_proxy_mock(const smartlist_t *transport_list,
|
|
@@ -5596,6 +5612,72 @@ test_config_include_opened_file_list(void *data)
|
|
|
tor_free(dir);
|
|
|
}
|
|
|
|
|
|
+static void
|
|
|
+test_config_compute_max_mem_in_queues(void *data)
|
|
|
+{
|
|
|
+#define GIGABYTE(x) (U64_LITERAL(x) << 30)
|
|
|
+#define MEGABYTE(x) (U64_LITERAL(x) << 20)
|
|
|
+ (void)data;
|
|
|
+ MOCK(get_total_system_memory, get_total_system_memory_mock);
|
|
|
+
|
|
|
+
|
|
|
+ * to use some sensible default values for 64-bit and 32-bit systems. */
|
|
|
+ total_system_memory_return = -1;
|
|
|
+
|
|
|
+#if SIZEOF_VOID_P >= 8
|
|
|
+
|
|
|
+ tt_int_op(compute_real_max_mem_in_queues(0, 0), OP_EQ, GIGABYTE(8));
|
|
|
+#else
|
|
|
+
|
|
|
+ tt_int_op(compute_real_max_mem_in_queues(0, 0), OP_EQ, GIGABYTE(1));
|
|
|
+#endif
|
|
|
+
|
|
|
+
|
|
|
+ total_system_memory_return = 0;
|
|
|
+
|
|
|
+
|
|
|
+ total_system_memory_output = GIGABYTE(1);
|
|
|
+
|
|
|
+
|
|
|
+ tt_int_op(compute_real_max_mem_in_queues(0, 0), OP_EQ,
|
|
|
+ 3 * (GIGABYTE(1) / 4));
|
|
|
+
|
|
|
+
|
|
|
+ total_system_memory_output = MEGABYTE(256);
|
|
|
+
|
|
|
+
|
|
|
+ * MaxMemInQueues here, even though we should only have had 0.75 * 256 = 192
|
|
|
+ * MB available. */
|
|
|
+ tt_int_op(compute_real_max_mem_in_queues(0, 0), OP_EQ, MEGABYTE(256));
|
|
|
+
|
|
|
+
|
|
|
+ total_system_memory_output = GIGABYTE(8);
|
|
|
+
|
|
|
+
|
|
|
+ tt_int_op(compute_real_max_mem_in_queues(0, 0), OP_EQ,
|
|
|
+ 2 * (GIGABYTE(8) / 5));
|
|
|
+
|
|
|
+
|
|
|
+ total_system_memory_output = GIGABYTE(16);
|
|
|
+
|
|
|
+
|
|
|
+ tt_int_op(compute_real_max_mem_in_queues(0, 0), OP_EQ,
|
|
|
+ 2 * (GIGABYTE(16) / 5));
|
|
|
+
|
|
|
+
|
|
|
+ total_system_memory_output = GIGABYTE(32);
|
|
|
+
|
|
|
+
|
|
|
+ tt_int_op(compute_real_max_mem_in_queues(0, 0), OP_EQ,
|
|
|
+ MAX_DEFAULT_MEMORY_QUEUE_SIZE);
|
|
|
+
|
|
|
+ done:
|
|
|
+ UNMOCK(get_total_system_memory);
|
|
|
+
|
|
|
+#undef GIGABYTE
|
|
|
+#undef MEGABYTE
|
|
|
+}
|
|
|
+
|
|
|
#define CONFIG_TEST(name, flags) \
|
|
|
{ #name, test_config_ ## name, flags, NULL, NULL }
|
|
|
|
|
@@ -5644,6 +5726,7 @@ struct testcase_t config_tests[] = {
|
|
|
CONFIG_TEST(check_bridge_distribution_setting_invalid, 0),
|
|
|
CONFIG_TEST(check_bridge_distribution_setting_unrecognised, 0),
|
|
|
CONFIG_TEST(include_opened_file_list, 0),
|
|
|
+ CONFIG_TEST(compute_max_mem_in_queues, 0),
|
|
|
END_OF_TESTCASES
|
|
|
};
|
|
|
|