aboutsummaryrefslogtreecommitdiff
path: root/gdb/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'gdb/unittests')
-rw-r--r--gdb/unittests/array-view-selftests.c4
-rw-r--r--gdb/unittests/child-path-selftests.c4
-rw-r--r--gdb/unittests/cli-utils-selftests.c4
-rw-r--r--gdb/unittests/command-def-selftests.c4
-rw-r--r--gdb/unittests/common-utils-selftests.c4
-rw-r--r--gdb/unittests/copy_bitwise-selftests.c4
-rw-r--r--gdb/unittests/enum-flags-selftests.c5
-rw-r--r--gdb/unittests/environ-selftests.c4
-rw-r--r--gdb/unittests/filtered_iterator-selftests.c4
-rw-r--r--gdb/unittests/format_pieces-selftests.c4
-rw-r--r--gdb/unittests/frame_info_ptr-selftests.c4
-rw-r--r--gdb/unittests/function-view-selftests.c4
-rw-r--r--gdb/unittests/gdb_tilde_expand-selftests.c4
-rw-r--r--gdb/unittests/gmp-utils-selftests.c5
-rw-r--r--gdb/unittests/intrusive_list-selftests.c5
-rw-r--r--gdb/unittests/lookup_name_info-selftests.c4
-rw-r--r--gdb/unittests/main-thread-selftests.c4
-rw-r--r--gdb/unittests/memory-map-selftests.c4
-rw-r--r--gdb/unittests/memrange-selftests.c4
-rw-r--r--gdb/unittests/mkdir-recursive-selftests.c4
-rw-r--r--gdb/unittests/observable-selftests.c4
-rw-r--r--gdb/unittests/offset-type-selftests.c4
-rw-r--r--gdb/unittests/packed-selftests.c4
-rw-r--r--gdb/unittests/parallel-for-selftests.c141
-rw-r--r--gdb/unittests/parse-connection-spec-selftests.c4
-rw-r--r--gdb/unittests/path-join-selftests.c4
-rw-r--r--gdb/unittests/remote-arg-selftests.c163
-rw-r--r--gdb/unittests/rsp-low-selftests.c4
-rw-r--r--gdb/unittests/scoped_fd-selftests.c4
-rw-r--r--gdb/unittests/scoped_ignore_signal-selftests.c4
-rw-r--r--gdb/unittests/scoped_mmap-selftests.c4
-rw-r--r--gdb/unittests/scoped_restore-selftests.c4
-rw-r--r--gdb/unittests/search-memory-selftests.c4
-rw-r--r--gdb/unittests/style-selftests.c4
-rw-r--r--gdb/unittests/tracepoint-selftests.c4
-rw-r--r--gdb/unittests/tui-selftests.c4
-rw-r--r--gdb/unittests/ui-file-selftests.c4
-rw-r--r--gdb/unittests/unique_xmalloc_ptr_char.c4
-rw-r--r--gdb/unittests/unpack-selftests.c4
-rw-r--r--gdb/unittests/utils-selftests.c59
-rw-r--r--gdb/unittests/vec-utils-selftests.c4
-rw-r--r--gdb/unittests/xml-utils-selftests.c4
42 files changed, 259 insertions, 263 deletions
diff --git a/gdb/unittests/array-view-selftests.c b/gdb/unittests/array-view-selftests.c
index fa96d3b..914800a 100644
--- a/gdb/unittests/array-view-selftests.c
+++ b/gdb/unittests/array-view-selftests.c
@@ -695,9 +695,7 @@ run_copy_tests ()
} /* namespace array_view_tests */
} /* namespace selftests */
-void _initialize_array_view_selftests ();
-void
-_initialize_array_view_selftests ()
+INIT_GDB_FILE (array_view_selftests)
{
selftests::register_test ("array_view",
selftests::array_view_tests::run_tests);
diff --git a/gdb/unittests/child-path-selftests.c b/gdb/unittests/child-path-selftests.c
index 0f29f7d..95b2c34 100644
--- a/gdb/unittests/child-path-selftests.c
+++ b/gdb/unittests/child-path-selftests.c
@@ -58,9 +58,7 @@ test ()
}
}
-void _initialize_child_path_selftests ();
-void
-_initialize_child_path_selftests ()
+INIT_GDB_FILE (child_path_selftests)
{
selftests::register_test ("child_path",
selftests::child_path::test);
diff --git a/gdb/unittests/cli-utils-selftests.c b/gdb/unittests/cli-utils-selftests.c
index e6c64a9..1382ca6 100644
--- a/gdb/unittests/cli-utils-selftests.c
+++ b/gdb/unittests/cli-utils-selftests.c
@@ -109,9 +109,7 @@ test_cli_utils ()
}
}
-void _initialize_cli_utils_selftests ();
-void
-_initialize_cli_utils_selftests ()
+INIT_GDB_FILE (cli_utils_selftests)
{
selftests::register_test ("cli_utils",
selftests::cli_utils::test_cli_utils);
diff --git a/gdb/unittests/command-def-selftests.c b/gdb/unittests/command-def-selftests.c
index 6f169f5..0a54d31 100644
--- a/gdb/unittests/command-def-selftests.c
+++ b/gdb/unittests/command-def-selftests.c
@@ -219,9 +219,7 @@ command_structure_invariants_tests ()
} /* namespace selftests */
-void _initialize_command_def_selftests ();
-void
-_initialize_command_def_selftests ()
+INIT_GDB_FILE (command_def_selftests)
{
selftests::register_test
("help_doc_invariants",
diff --git a/gdb/unittests/common-utils-selftests.c b/gdb/unittests/common-utils-selftests.c
index fab9cd1..ecc4769 100644
--- a/gdb/unittests/common-utils-selftests.c
+++ b/gdb/unittests/common-utils-selftests.c
@@ -127,9 +127,7 @@ string_vappendf_tests ()
} /* namespace selftests */
-void _initialize_common_utils_selftests ();
-void
-_initialize_common_utils_selftests ()
+INIT_GDB_FILE (common_utils_selftests)
{
selftests::register_test ("string_printf", selftests::string_printf_tests);
selftests::register_test ("string_vprintf", selftests::string_vprintf_tests);
diff --git a/gdb/unittests/copy_bitwise-selftests.c b/gdb/unittests/copy_bitwise-selftests.c
index 8798cbd..6fcdcd7 100644
--- a/gdb/unittests/copy_bitwise-selftests.c
+++ b/gdb/unittests/copy_bitwise-selftests.c
@@ -151,9 +151,7 @@ copy_bitwise_tests (void)
} /* namespace selftests */
-void _initialize_copy_bitwise_utils_selftests ();
-void
-_initialize_copy_bitwise_utils_selftests ()
+INIT_GDB_FILE (copy_bitwise_utils_selftests)
{
selftests::register_test ("copy_bitwise", selftests::copy_bitwise_tests);
}
diff --git a/gdb/unittests/enum-flags-selftests.c b/gdb/unittests/enum-flags-selftests.c
index bb55019..3eb0f52 100644
--- a/gdb/unittests/enum-flags-selftests.c
+++ b/gdb/unittests/enum-flags-selftests.c
@@ -607,10 +607,7 @@ self_test ()
} /* namespace enum_flags_tests */
} /* namespace selftests */
-void _initialize_enum_flags_selftests ();
-
-void
-_initialize_enum_flags_selftests ()
+INIT_GDB_FILE (enum_flags_selftests)
{
selftests::register_test ("enum-flags",
selftests::enum_flags_tests::self_test);
diff --git a/gdb/unittests/environ-selftests.c b/gdb/unittests/environ-selftests.c
index 79bffed..5ac3384 100644
--- a/gdb/unittests/environ-selftests.c
+++ b/gdb/unittests/environ-selftests.c
@@ -297,9 +297,7 @@ run_tests ()
} /* namespace gdb_environ */
} /* namespace selftests */
-void _initialize_environ_selftests ();
-void
-_initialize_environ_selftests ()
+INIT_GDB_FILE (environ_selftests)
{
selftests::register_test ("gdb_environ",
selftests::gdb_environ_tests::run_tests);
diff --git a/gdb/unittests/filtered_iterator-selftests.c b/gdb/unittests/filtered_iterator-selftests.c
index b3ec70b..49c95cb 100644
--- a/gdb/unittests/filtered_iterator-selftests.c
+++ b/gdb/unittests/filtered_iterator-selftests.c
@@ -154,9 +154,7 @@ test_filtered_iterator_eq ()
} /* namespace selftests */
-void _initialize_filtered_iterator_selftests ();
-void
-_initialize_filtered_iterator_selftests ()
+INIT_GDB_FILE (filtered_iterator_selftests)
{
selftests::register_test ("filtered_iterator",
selftests::test_filtered_iterator);
diff --git a/gdb/unittests/format_pieces-selftests.c b/gdb/unittests/format_pieces-selftests.c
index 473d690..c7d8ff0 100644
--- a/gdb/unittests/format_pieces-selftests.c
+++ b/gdb/unittests/format_pieces-selftests.c
@@ -147,9 +147,7 @@ run_tests ()
} /* namespace format_pieces */
} /* namespace selftests */
-void _initialize_format_pieces_selftests ();
-void
-_initialize_format_pieces_selftests ()
+INIT_GDB_FILE (format_pieces_selftests)
{
selftests::register_test ("format_pieces",
selftests::format_pieces::run_tests);
diff --git a/gdb/unittests/frame_info_ptr-selftests.c b/gdb/unittests/frame_info_ptr-selftests.c
index c9eb4f4..d518482 100644
--- a/gdb/unittests/frame_info_ptr-selftests.c
+++ b/gdb/unittests/frame_info_ptr-selftests.c
@@ -66,9 +66,7 @@ test_user_created_frame ()
} /* namespace selftests */
-void _initialize_frame_info_ptr_selftests ();
-void
-_initialize_frame_info_ptr_selftests ()
+INIT_GDB_FILE (frame_info_ptr_selftests)
{
selftests::register_test ("frame_info_ptr_user",
selftests::test_user_created_frame);
diff --git a/gdb/unittests/function-view-selftests.c b/gdb/unittests/function-view-selftests.c
index 036c7f9..21838f1 100644
--- a/gdb/unittests/function-view-selftests.c
+++ b/gdb/unittests/function-view-selftests.c
@@ -250,9 +250,7 @@ run_tests ()
} /* namespace function_view */
} /* namespace selftests */
-void _initialize_function_view_selftests ();
-void
-_initialize_function_view_selftests ()
+INIT_GDB_FILE (function_view_selftests)
{
selftests::register_test ("function_view",
selftests::function_view::run_tests);
diff --git a/gdb/unittests/gdb_tilde_expand-selftests.c b/gdb/unittests/gdb_tilde_expand-selftests.c
index b0b7027..28c759f 100644
--- a/gdb/unittests/gdb_tilde_expand-selftests.c
+++ b/gdb/unittests/gdb_tilde_expand-selftests.c
@@ -84,9 +84,7 @@ do_test ()
} /* namespace gdb_tilde_expand_tests */
} /* namespace selftests */
-void _initialize_gdb_tilde_expand_selftests ();
-void
-_initialize_gdb_tilde_expand_selftests ()
+INIT_GDB_FILE (gdb_tilde_expand_selftests)
{
selftests::register_test
("gdb_tilde_expand", selftests::gdb_tilde_expand_tests::do_test);
diff --git a/gdb/unittests/gmp-utils-selftests.c b/gdb/unittests/gmp-utils-selftests.c
index 495947af..9843fcb 100644
--- a/gdb/unittests/gmp-utils-selftests.c
+++ b/gdb/unittests/gmp-utils-selftests.c
@@ -498,10 +498,7 @@ gdb_mpq_write_fixed_point ()
}
-void _initialize_gmp_utils_selftests ();
-
-void
-_initialize_gmp_utils_selftests ()
+INIT_GDB_FILE (gmp_utils_selftests)
{
selftests::register_test ("gdb_mpz_as_integer",
selftests::gdb_mpz_as_integer);
diff --git a/gdb/unittests/intrusive_list-selftests.c b/gdb/unittests/intrusive_list-selftests.c
index eaffbba..2dd1298 100644
--- a/gdb/unittests/intrusive_list-selftests.c
+++ b/gdb/unittests/intrusive_list-selftests.c
@@ -1648,10 +1648,7 @@ test_intrusive_list ()
test_node_is_linked ();
}
-void _initialize_intrusive_list_selftests ();
-
-void
-_initialize_intrusive_list_selftests ()
+INIT_GDB_FILE (intrusive_list_selftests)
{
selftests::register_test ("intrusive_list", test_intrusive_list);
}
diff --git a/gdb/unittests/lookup_name_info-selftests.c b/gdb/unittests/lookup_name_info-selftests.c
index 3e8440b..dc0d307 100644
--- a/gdb/unittests/lookup_name_info-selftests.c
+++ b/gdb/unittests/lookup_name_info-selftests.c
@@ -105,9 +105,7 @@ run_tests ()
}} /* namespace selftests::lookup_name */
-void _initialize_lookup_name_info_selftests ();
-void
-_initialize_lookup_name_info_selftests ()
+INIT_GDB_FILE (lookup_name_info_selftests)
{
selftests::register_test ("lookup_name_info",
selftests::lookup_name::run_tests);
diff --git a/gdb/unittests/main-thread-selftests.c b/gdb/unittests/main-thread-selftests.c
index 5f3d790..77adf47 100644
--- a/gdb/unittests/main-thread-selftests.c
+++ b/gdb/unittests/main-thread-selftests.c
@@ -73,9 +73,7 @@ run_tests ()
}
}
-void _initialize_main_thread_selftests ();
-void
-_initialize_main_thread_selftests ()
+INIT_GDB_FILE (main_thread_selftests)
{
#if CXX_STD_THREAD
selftests::register_test ("run_on_main_thread",
diff --git a/gdb/unittests/memory-map-selftests.c b/gdb/unittests/memory-map-selftests.c
index 6872d5a..c014c4d 100644
--- a/gdb/unittests/memory-map-selftests.c
+++ b/gdb/unittests/memory-map-selftests.c
@@ -75,9 +75,7 @@ parse_memory_map_tests ()
#endif /* HAVE_LIBEXPAT */
-void _initialize_memory_map_selftests ();
-void
-_initialize_memory_map_selftests ()
+INIT_GDB_FILE (memory_map_selftests)
{
#if defined(HAVE_LIBEXPAT)
selftests::register_test
diff --git a/gdb/unittests/memrange-selftests.c b/gdb/unittests/memrange-selftests.c
index 1433105..17e08e8 100644
--- a/gdb/unittests/memrange-selftests.c
+++ b/gdb/unittests/memrange-selftests.c
@@ -105,9 +105,7 @@ normalize_mem_ranges_tests ()
} /* namespace memrange_tests */
} /* namespace selftests */
-void _initialize_memrange_selftests ();
-void
-_initialize_memrange_selftests ()
+INIT_GDB_FILE (memrange_selftests)
{
selftests::register_test
("normalize_mem_ranges",
diff --git a/gdb/unittests/mkdir-recursive-selftests.c b/gdb/unittests/mkdir-recursive-selftests.c
index 764fe1a..b2ae383 100644
--- a/gdb/unittests/mkdir-recursive-selftests.c
+++ b/gdb/unittests/mkdir-recursive-selftests.c
@@ -80,9 +80,7 @@ test ()
}
}
-void _initialize_mkdir_recursive_selftests ();
-void
-_initialize_mkdir_recursive_selftests ()
+INIT_GDB_FILE (mkdir_recursive_selftests)
{
selftests::register_test ("mkdir_recursive",
selftests::mkdir_recursive::test);
diff --git a/gdb/unittests/observable-selftests.c b/gdb/unittests/observable-selftests.c
index 90d7392..0934249 100644
--- a/gdb/unittests/observable-selftests.c
+++ b/gdb/unittests/observable-selftests.c
@@ -237,9 +237,7 @@ run_tests ()
} /* namespace observers */
} /* namespace selftests */
-void _initialize_observer_selftest ();
-void
-_initialize_observer_selftest ()
+INIT_GDB_FILE (observer_selftest)
{
selftests::register_test ("gdb::observers",
selftests::observers::run_tests);
diff --git a/gdb/unittests/offset-type-selftests.c b/gdb/unittests/offset-type-selftests.c
index 1623f0d..2cba4e1 100644
--- a/gdb/unittests/offset-type-selftests.c
+++ b/gdb/unittests/offset-type-selftests.c
@@ -170,9 +170,7 @@ run_tests ()
} /* namespace offset_type */
} /* namespace selftests */
-void _initialize_offset_type_selftests ();
-void
-_initialize_offset_type_selftests ()
+INIT_GDB_FILE (offset_type_selftests)
{
selftests::register_test ("offset_type", selftests::offset_type::run_tests);
}
diff --git a/gdb/unittests/packed-selftests.c b/gdb/unittests/packed-selftests.c
index daa8036..5a91b29 100644
--- a/gdb/unittests/packed-selftests.c
+++ b/gdb/unittests/packed-selftests.c
@@ -119,9 +119,7 @@ run_tests ()
} /* namespace packed_tests */
} /* namespace selftests */
-void _initialize_packed_selftests ();
-void
-_initialize_packed_selftests ()
+INIT_GDB_FILE (packed_selftests)
{
selftests::register_test ("packed", selftests::packed_tests::run_tests);
}
diff --git a/gdb/unittests/parallel-for-selftests.c b/gdb/unittests/parallel-for-selftests.c
index 841d914..f545614 100644
--- a/gdb/unittests/parallel-for-selftests.c
+++ b/gdb/unittests/parallel-for-selftests.c
@@ -17,13 +17,6 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
-/* This file is divided in two parts:
- - FOR_EACH-undefined, and
- - FOR_EACH-defined.
- The former includes the latter, more than once, with different values for
- FOR_EACH. The FOR_EACH-defined part reads like a regular function. */
-#ifndef FOR_EACH
-
#include "gdbsupport/selftest.h"
#include "gdbsupport/parallel-for.h"
@@ -49,97 +42,77 @@ struct save_restore_n_threads
int n_threads;
};
-/* Define test_par using TEST in the FOR_EACH-defined part. */
-#define TEST test_par
-#define FOR_EACH gdb::parallel_for_each
-#include "parallel-for-selftests.c"
-#undef FOR_EACH
-#undef TEST
-
-/* Define test_seq using TEST in the FOR_EACH-defined part. */
-#define TEST test_seq
-#define FOR_EACH gdb::sequential_for_each
-#include "parallel-for-selftests.c"
-#undef FOR_EACH
-#undef TEST
+using foreach_callback_t = gdb::function_view<void (int first, int last)>;
+using do_foreach_t = gdb::function_view<void (int first, int last,
+ foreach_callback_t)>;
static void
-test (int n_threads)
+test_one (int n_threads, do_foreach_t do_foreach)
{
- test_par (n_threads);
- test_seq (n_threads);
+ save_restore_n_threads saver;
+ gdb::thread_pool::g_thread_pool->set_thread_count (n_threads);
+
+ {
+ constexpr int upper_bound = 1000;
+ std::atomic<int> counter (0);
+ do_foreach (0, upper_bound,
+ [&] (int start, int end) { counter += end - start; });
+ SELF_CHECK (counter == upper_bound);
+ }
+
+ {
+ std::atomic<int> counter (0);
+ do_foreach (0, 0, [&] (int start, int end) { counter += end - start; });
+ SELF_CHECK (counter == 0);
+ }
+
+ {
+ /* Check that if there are fewer tasks than threads, then we won't
+ end up with a null result. */
+ std::vector<std::unique_ptr<int>> intresults;
+ std::atomic<bool> any_empty_tasks (false);
+
+ do_foreach (0, 1,
+ [&] (int start, int end)
+ {
+ if (start == end)
+ any_empty_tasks = true;
+
+ return std::make_unique<int> (end - start);
+ });
+
+ SELF_CHECK (!any_empty_tasks);
+ SELF_CHECK (std::all_of (intresults.begin (), intresults.end (),
+ [] (const std::unique_ptr<int> &entry)
+ { return entry != nullptr; }));
+ }
}
static void
-test_n_threads ()
+test_parallel_for_each ()
{
- test (0);
- test (1);
- test (3);
+ const std::vector<do_foreach_t> for_each_functions
+ {
+ [] (int start, int end, foreach_callback_t callback)
+ { gdb::parallel_for_each<1> (start, end, callback); },
+ [] (int start, int end, foreach_callback_t callback)
+ { gdb::sequential_for_each (start, end, callback);}
+ };
+
+ for (int n_threads : { 0, 1, 3 })
+ for (const auto &for_each_function : for_each_functions)
+ test_one (n_threads, for_each_function);
}
-}
-}
+} /* namespace parallel_for */
+} /* namespace selftests */
#endif /* CXX_STD_THREAD */
-void _initialize_parallel_for_selftests ();
-void
-_initialize_parallel_for_selftests ()
+INIT_GDB_FILE (parallel_for_selftests)
{
#ifdef CXX_STD_THREAD
selftests::register_test ("parallel_for",
- selftests::parallel_for::test_n_threads);
+ selftests::parallel_for::test_parallel_for_each);
#endif /* CXX_STD_THREAD */
}
-
-#else /* FOR_EACH */
-
-static void
-TEST (int n_threads)
-{
- save_restore_n_threads saver;
- gdb::thread_pool::g_thread_pool->set_thread_count (n_threads);
-
-#define NUMBER 10000
-
- std::atomic<int> counter (0);
- FOR_EACH (1, 0, NUMBER,
- [&] (int start, int end)
- {
- counter += end - start;
- });
- SELF_CHECK (counter == NUMBER);
-
- counter = 0;
- FOR_EACH (1, 0, 0,
- [&] (int start, int end)
- {
- counter += end - start;
- });
- SELF_CHECK (counter == 0);
-
-#undef NUMBER
-
- /* Check that if there are fewer tasks than threads, then we won't
- end up with a null result. */
- std::vector<std::unique_ptr<int>> intresults;
- std::atomic<bool> any_empty_tasks (false);
-
- FOR_EACH (1, 0, 1,
- [&] (int start, int end)
- {
- if (start == end)
- any_empty_tasks = true;
- return std::make_unique<int> (end - start);
- });
- SELF_CHECK (!any_empty_tasks);
- SELF_CHECK (std::all_of (intresults.begin (),
- intresults.end (),
- [] (const std::unique_ptr<int> &entry)
- {
- return entry != nullptr;
- }));
-}
-
-#endif /* FOR_EACH */
diff --git a/gdb/unittests/parse-connection-spec-selftests.c b/gdb/unittests/parse-connection-spec-selftests.c
index 7104272..ce2da35 100644
--- a/gdb/unittests/parse-connection-spec-selftests.c
+++ b/gdb/unittests/parse-connection-spec-selftests.c
@@ -238,9 +238,7 @@ run_tests ()
} /* namespace parse_connection_spec_tests */
} /* namespace selftests */
-void _initialize_parse_connection_spec_selftests ();
-void
-_initialize_parse_connection_spec_selftests ()
+INIT_GDB_FILE (parse_connection_spec_selftests)
{
selftests::register_test ("parse_connection_spec",
selftests::parse_connection_spec_tests::run_tests);
diff --git a/gdb/unittests/path-join-selftests.c b/gdb/unittests/path-join-selftests.c
index a4003f0..8bc5a91 100644
--- a/gdb/unittests/path-join-selftests.c
+++ b/gdb/unittests/path-join-selftests.c
@@ -63,9 +63,7 @@ test ()
}
}
-void _initialize_path_join_selftests ();
-void
-_initialize_path_join_selftests ()
+INIT_GDB_FILE (path_join_selftests)
{
selftests::register_test ("path_join",
selftests::path_join::test);
diff --git a/gdb/unittests/remote-arg-selftests.c b/gdb/unittests/remote-arg-selftests.c
new file mode 100644
index 0000000..17b8d1d
--- /dev/null
+++ b/gdb/unittests/remote-arg-selftests.c
@@ -0,0 +1,163 @@
+/* Self tests for GDB's argument splitting and merging.
+
+ Copyright (C) 2023-2025 Free Software Foundation, Inc.
+
+ This file is part of GDB.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "defs.h"
+#include "gdbsupport/selftest.h"
+#include "gdbsupport/buildargv.h"
+#include "gdbsupport/common-inferior.h"
+#include "gdbsupport/remote-args.h"
+#include "gdbsupport/gdb_argv_vec.h"
+
+namespace selftests {
+namespace remote_args_tests {
+
+/* The data needed to perform a single remote argument test. */
+struct arg_test_desc
+{
+ /* The original inferior argument string. */
+ std::string input;
+
+ /* The individual arguments once they have been split. */
+ std::vector<std::string> split;
+
+ /* The new inferior argument string, created by joining SPLIT. */
+ std::string joined;
+};
+
+/* The list of tests. */
+arg_test_desc desc[] = {
+ { "abc", { "abc" }, "abc" },
+ { "a b c", { "a", "b", "c" }, "a b c" },
+ { "\"a b\" 'c d'", { "a b", "c d" }, "a\\ b c\\ d" },
+ { "\\' \\\"", { "'", "\"" }, "\\' \\\"" },
+ { "'\\'", { "\\" }, "\\\\" },
+ { "\"\\\\\" \"\\\\\\\"\"", { "\\", "\\\"" }, "\\\\ \\\\\\\"" },
+ { "\\ \" \" ' '", { " ", " ", " "}, "\\ \\ \\ " },
+ { "\"'\"", { "'" }, "\\'" },
+ { "'\"' '\\\"'", { "\"", "\\\"" } , "\\\" \\\\\\\""},
+ { "\"first arg\" \"\" \"third-arg\" \"'\" \"\\\"\" \"\\\\\\\"\" \" \" \"\"",
+ { "first arg", "", "third-arg", "'", "\"", "\\\""," ", "" },
+ "first\\ arg '' third-arg \\' \\\" \\\\\\\" \\ ''"},
+ { "\"\\a\" \"\\&\" \"\\#\" \"\\<\" \"\\^\"",
+ { "\\a", "\\&", "\\#" , "\\<" , "\\^"},
+ "\\\\a \\\\\\& \\\\\\# \\\\\\< \\\\\\^" },
+ { "1 '\n' 3", { "1", "\n", "3" }, "1 '\n' 3" },
+};
+
+/* Run the remote argument passing self tests. */
+
+static void
+self_test ()
+{
+ int failure_count = 0;
+ for (const auto &d : desc)
+ {
+ if (run_verbose ())
+ {
+ if (&d != &desc[0])
+ debug_printf ("------------------------------\n");
+ debug_printf ("Input (%s)\n", d.input.c_str ());
+ }
+
+ /* Split argument string into individual arguments. */
+ std::vector<std::string> split_args = gdb::remote_args::split (d.input);
+
+ if (run_verbose ())
+ {
+ debug_printf ("Split:\n");
+
+ size_t len = std::max (split_args.size (), d.split.size ());
+ for (size_t i = 0; i < len; ++i)
+ {
+ const char *got = "N/A";
+ const char *expected = got;
+
+ if (i < split_args.size ())
+ got = split_args[i].c_str ();
+
+ if (i < d.split.size ())
+ expected = d.split[i].c_str ();
+
+ debug_printf (" got (%s), expected (%s)\n", got, expected);
+ }
+ }
+
+ if (split_args != d.split)
+ {
+ ++failure_count;
+ if (run_verbose ())
+ debug_printf ("FAIL\n");
+ continue;
+ }
+
+ /* Now join the arguments. */
+ gdb::argv_vec split_args_c_str;
+ for (const std::string &s : split_args)
+ split_args_c_str.push_back (xstrdup (s.c_str ()));
+ std::string joined_args
+ = gdb::remote_args::join (split_args_c_str.get ());
+
+ if (run_verbose ())
+ debug_printf ("Joined (%s), expected (%s)\n",
+ joined_args.c_str (), d.joined.c_str ());
+
+ if (joined_args != d.joined)
+ {
+ ++failure_count;
+ if (run_verbose ())
+ debug_printf ("FAIL\n");
+ continue;
+ }
+
+ /* The contents of JOINED_ARGS will not be identical to D.INPUT.
+ There are multiple ways that an argument can be escaped, and our
+ join function just picks one. However, if we split JOINED_ARGS
+ again then each individual argument should be the same as those in
+ SPLIT_ARGS. So test that next. */
+ std::vector<std::string> split_args_v2
+ = gdb::remote_args::split (joined_args);
+
+ if (split_args_v2 != split_args)
+ {
+ ++failure_count;
+ if (run_verbose ())
+ {
+ debug_printf ("Re-split:\n");
+ for (const auto &a : split_args_v2)
+ debug_printf (" got (%s)\n", a.c_str ());
+ debug_printf ("FAIL\n");
+ }
+ continue;
+ }
+
+ if (run_verbose ())
+ debug_printf ("PASS\n");
+ }
+
+ SELF_CHECK (failure_count == 0);
+}
+
+} /* namespace remote_args_tests */
+} /* namespace selftests */
+
+INIT_GDB_FILE (remote_arg_selftests)
+{
+ selftests::register_test ("remote-args",
+ selftests::remote_args_tests::self_test);
+}
diff --git a/gdb/unittests/rsp-low-selftests.c b/gdb/unittests/rsp-low-selftests.c
index 7a1b2de..d0002ae 100644
--- a/gdb/unittests/rsp-low-selftests.c
+++ b/gdb/unittests/rsp-low-selftests.c
@@ -60,9 +60,7 @@ static void test_hex2str ()
} /* namespace rsp_low */
} /* namespace selftests */
-void _initialize_rsp_low_selftests ();
-void
-_initialize_rsp_low_selftests ()
+INIT_GDB_FILE (rsp_low_selftests)
{
selftests::register_test ("hex2bin_byte_vector",
selftests::rsp_low::test_hex2bin_byte_vector);
diff --git a/gdb/unittests/scoped_fd-selftests.c b/gdb/unittests/scoped_fd-selftests.c
index 7abbbd8..da59a18 100644
--- a/gdb/unittests/scoped_fd-selftests.c
+++ b/gdb/unittests/scoped_fd-selftests.c
@@ -92,9 +92,7 @@ run_tests ()
} /* namespace scoped_fd */
} /* namespace selftests */
-void _initialize_scoped_fd_selftests ();
-void
-_initialize_scoped_fd_selftests ()
+INIT_GDB_FILE (scoped_fd_selftests)
{
selftests::register_test ("scoped_fd",
selftests::scoped_fd::run_tests);
diff --git a/gdb/unittests/scoped_ignore_signal-selftests.c b/gdb/unittests/scoped_ignore_signal-selftests.c
index fdfaca3..86c5031 100644
--- a/gdb/unittests/scoped_ignore_signal-selftests.c
+++ b/gdb/unittests/scoped_ignore_signal-selftests.c
@@ -114,9 +114,7 @@ test_sigpipe ()
} /* namespace scoped_ignore_sig */
} /* namespace selftests */
-void _initialize_scoped_ignore_signal_selftests ();
-void
-_initialize_scoped_ignore_signal_selftests ()
+INIT_GDB_FILE (scoped_ignore_signal_selftests)
{
#ifdef SIGPIPE
selftests::register_test ("scoped_ignore_sigpipe",
diff --git a/gdb/unittests/scoped_mmap-selftests.c b/gdb/unittests/scoped_mmap-selftests.c
index 695ed1e..72568fe 100644
--- a/gdb/unittests/scoped_mmap-selftests.c
+++ b/gdb/unittests/scoped_mmap-selftests.c
@@ -135,9 +135,7 @@ run_tests ()
#endif /* !defined(HAVE_SYS_MMAN_H) */
-void _initialize_scoped_mmap_selftests ();
-void
-_initialize_scoped_mmap_selftests ()
+INIT_GDB_FILE (scoped_mmap_selftests)
{
#if defined(HAVE_SYS_MMAN_H)
selftests::register_test ("scoped_mmap",
diff --git a/gdb/unittests/scoped_restore-selftests.c b/gdb/unittests/scoped_restore-selftests.c
index 18d898b..4396046 100644
--- a/gdb/unittests/scoped_restore-selftests.c
+++ b/gdb/unittests/scoped_restore-selftests.c
@@ -102,9 +102,7 @@ run_tests ()
} /* namespace scoped_restore_tests */
} /* namespace selftests */
-void _initialize_scoped_restore_selftests ();
-void
-_initialize_scoped_restore_selftests ()
+INIT_GDB_FILE (scoped_restore_selftests)
{
selftests::register_test ("scoped_restore",
selftests::scoped_restore_tests::run_tests);
diff --git a/gdb/unittests/search-memory-selftests.c b/gdb/unittests/search-memory-selftests.c
index 0e82d6c..c1942fc 100644
--- a/gdb/unittests/search-memory-selftests.c
+++ b/gdb/unittests/search-memory-selftests.c
@@ -89,9 +89,7 @@ run_tests ()
} /* namespace selftests */
-void _initialize_search_memory_selftests ();
-void
-_initialize_search_memory_selftests ()
+INIT_GDB_FILE (search_memory_selftests)
{
selftests::register_test ("search_memory",
selftests::search_memory_tests::run_tests);
diff --git a/gdb/unittests/style-selftests.c b/gdb/unittests/style-selftests.c
index 2cbe194..f2a37bb 100644
--- a/gdb/unittests/style-selftests.c
+++ b/gdb/unittests/style-selftests.c
@@ -100,9 +100,7 @@ run_tests ()
} /* namespace style */
} /* namespace selftests */
-void _initialize_style_selftest ();
-void
-_initialize_style_selftest ()
+INIT_GDB_FILE (style_selftest)
{
selftests::register_test ("style",
selftests::style::run_tests);
diff --git a/gdb/unittests/tracepoint-selftests.c b/gdb/unittests/tracepoint-selftests.c
index 235dd1e..bef51ae 100644
--- a/gdb/unittests/tracepoint-selftests.c
+++ b/gdb/unittests/tracepoint-selftests.c
@@ -60,9 +60,7 @@ test_parse_static_tracepoint_marker_definition ()
} /* namespace tracepoint_tests */
} /* namespace selftests */
-void _initialize_tracepoint_selftests ();
-void
-_initialize_tracepoint_selftests ()
+INIT_GDB_FILE (tracepoint_selftests)
{
selftests::register_test
("parse_static_tracepoint_marker_definition",
diff --git a/gdb/unittests/tui-selftests.c b/gdb/unittests/tui-selftests.c
index e61b0db..5235a07 100644
--- a/gdb/unittests/tui-selftests.c
+++ b/gdb/unittests/tui-selftests.c
@@ -45,9 +45,7 @@ run_tests ()
#endif /* TUI */
-void _initialize_tui_selftest ();
-void
-_initialize_tui_selftest ()
+INIT_GDB_FILE (tui_selftest)
{
#ifdef TUI
selftests::register_test ("tui", selftests::tui::run_tests);
diff --git a/gdb/unittests/ui-file-selftests.c b/gdb/unittests/ui-file-selftests.c
index b62fd4f..d78c6b0 100644
--- a/gdb/unittests/ui-file-selftests.c
+++ b/gdb/unittests/ui-file-selftests.c
@@ -53,9 +53,7 @@ run_tests ()
} /* namespace file*/
} /* namespace selftests */
-void _initialize_ui_file_selftest ();
-void
-_initialize_ui_file_selftest ()
+INIT_GDB_FILE (ui_file_selftest)
{
selftests::register_test ("ui-file",
selftests::file::run_tests);
diff --git a/gdb/unittests/unique_xmalloc_ptr_char.c b/gdb/unittests/unique_xmalloc_ptr_char.c
index 984f692..7f61c06 100644
--- a/gdb/unittests/unique_xmalloc_ptr_char.c
+++ b/gdb/unittests/unique_xmalloc_ptr_char.c
@@ -47,9 +47,7 @@ unique_xmalloc_ptr_char ()
}
}
-void _initialize_unique_xmalloc_ptr_char ();
-void
-_initialize_unique_xmalloc_ptr_char ()
+INIT_GDB_FILE (unique_xmalloc_ptr_char)
{
selftests::register_test ("unique_xmalloc_ptr_char",
selftests::unpack::unique_xmalloc_ptr_char);
diff --git a/gdb/unittests/unpack-selftests.c b/gdb/unittests/unpack-selftests.c
index 54af777..fccf7a2 100644
--- a/gdb/unittests/unpack-selftests.c
+++ b/gdb/unittests/unpack-selftests.c
@@ -52,9 +52,7 @@ unpack_field_as_long_tests (struct gdbarch *arch)
}
}
-void _initialize_unpack_selftests ();
-void
-_initialize_unpack_selftests ()
+INIT_GDB_FILE (unpack_selftests)
{
selftests::register_test_foreach_arch
("unpack_field_as_long", selftests::unpack::unpack_field_as_long_tests);
diff --git a/gdb/unittests/utils-selftests.c b/gdb/unittests/utils-selftests.c
deleted file mode 100644
index b1c457c..0000000
--- a/gdb/unittests/utils-selftests.c
+++ /dev/null
@@ -1,59 +0,0 @@
-/* Unit tests for the utils.c file.
-
- Copyright (C) 2018-2025 Free Software Foundation, Inc.
-
- This file is part of GDB.
-
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 3 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>. */
-
-#include "utils.h"
-#include "gdbsupport/selftest.h"
-
-namespace selftests {
-namespace utils {
-
-static void
-test_substitute_path_component ()
-{
- auto test = [] (std::string s, const char *from, const char *to,
- const char *expected)
- {
- char *temp = xstrdup (s.c_str ());
- substitute_path_component (&temp, from, to);
- SELF_CHECK (strcmp (temp, expected) == 0);
- xfree (temp);
- };
-
- test ("/abc/$def/g", "abc", "xyz", "/xyz/$def/g");
- test ("abc/$def/g", "abc", "xyz", "xyz/$def/g");
- test ("/abc/$def/g", "$def", "xyz", "/abc/xyz/g");
- test ("/abc/$def/g", "g", "xyz", "/abc/$def/xyz");
- test ("/abc/$def/g", "ab", "xyz", "/abc/$def/g");
- test ("/abc/$def/g", "def", "xyz", "/abc/$def/g");
- test ("/abc/$def/g", "abc", "abc", "/abc/$def/g");
- test ("/abc/$def/g", "abc", "", "//$def/g");
- test ("/abc/$def/g", "abc/$def", "xyz", "/xyz/g");
- test ("/abc/$def/abc", "abc", "xyz", "/xyz/$def/xyz");
-}
-
-}
-}
-
-void _initialize_utils_selftests ();
-void
-_initialize_utils_selftests ()
-{
- selftests::register_test ("substitute_path_component",
- selftests::utils::test_substitute_path_component);
-}
diff --git a/gdb/unittests/vec-utils-selftests.c b/gdb/unittests/vec-utils-selftests.c
index 4be0b86..11fad31 100644
--- a/gdb/unittests/vec-utils-selftests.c
+++ b/gdb/unittests/vec-utils-selftests.c
@@ -65,9 +65,7 @@ unordered_remove_tests ()
} /* namespace vector_utils_tests */
} /* namespace selftests */
-void _initialize_vec_utils_selftests ();
-void
-_initialize_vec_utils_selftests ()
+INIT_GDB_FILE (vec_utils_selftests)
{
selftests::register_test
("unordered_remove",
diff --git a/gdb/unittests/xml-utils-selftests.c b/gdb/unittests/xml-utils-selftests.c
index 5884faa..f4a637b 100644
--- a/gdb/unittests/xml-utils-selftests.c
+++ b/gdb/unittests/xml-utils-selftests.c
@@ -47,9 +47,7 @@ static void test_xml_escape_text_append ()
}
}
-void _initialize_xml_utils ();
-void
-_initialize_xml_utils ()
+INIT_GDB_FILE (xml_utils)
{
selftests::register_test ("xml_escape_text",
selftests::xml_utils::test_xml_escape_text);