diff options
author | Thomas Haller <thaller@redhat.com> | 2015-11-23 18:15:39 +0100 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2015-11-24 09:46:06 +0100 |
commit | 73cb57910835ef46d43bb92309def186e38534cf (patch) | |
tree | 83a7a1b85ee4c2d0c35d92834acf95ca3378e3ce | |
parent | a6a2fd7eef5a1aefcc7ab6d35b84a8d4c0039cd1 (diff) | |
download | NetworkManager-73cb57910835ef46d43bb92309def186e38534cf.tar.gz |
nmtst: support -p and -s arguments from gtestutils via $NMTST_DEBUG
For tests based on glib's test framework, you can select which tests to
run by passing -p/-s on the command line.
Usually, we want to invoke our tests via `make check` which conveniently
calls valgrind (run-test-valgrind.sh) or spawns a private D-Bus server
(libnm-test-launch.sh, libnm-glib-test-launch.sh). At that point, it is
not directly possible to specify command line arguments for the tests,
which is why it is convenient to specify arguments via $NMTST_DEBUG
environment variable.
Parse "p" and "s" arguments from $NMTST_DEBUG and pass them to g_test_init()
to select which tests to run.
NMTST_DEBUG=p=/core/general/test_setting_ip4_changed_signal ./libnm-core/tests/test-general
However, there is a problem here: in gtestutils, -p/-s conflicts with --tap,
which is how our Makefile invokes the tests. Thus the new options explicitly
don't work when being called during `make check`. Which makes this much
less useful. I only noticed that afterwards, so still keep the patch
because it might still be convenient during developing tests to set the
environment variable once, and then repeatedly spawn the tests, without
specifying -p/-s.
-rw-r--r-- | include/nm-test-utils.h | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h index f896253a38..9fc6fad618 100644 --- a/include/nm-test-utils.h +++ b/include/nm-test-utils.h @@ -80,6 +80,10 @@ * - respect g_test_quick(), if the command line contains '-mslow', '-mquick', '-mthorough'. * - use compile time default * + * "p=PATH"|"s=PATH": passes the path to g_test_init() as "-p" and "-s", respectively. + * Unfortunately, these options conflict with "--tap" which our makefile passes to the + * tests, thus it's only useful outside of `make check`. + * *******************************************************************************/ #include <arpa/inet.h> @@ -268,6 +272,8 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ gboolean test_quick = FALSE; gboolean test_quick_set = FALSE; gboolean test_quick_argv = FALSE; + gs_unref_ptrarray GPtrArray *p_tests = NULL; + gs_unref_ptrarray GPtrArray *s_tests = NULL; if (!out_set_logging) out_set_logging = &_out_set_logging; @@ -324,6 +330,14 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ sudo_cmd = g_strdup (&debug[strlen ("sudo-cmd=")]); } else if (!g_ascii_strcasecmp (debug, "no-expect-message")) { no_expect_message = TRUE; + } else if (!g_ascii_strncasecmp (debug, "p=", strlen ("p="))) { + if (!p_tests) + p_tests = g_ptr_array_new_with_free_func (g_free); + g_ptr_array_add (p_tests, g_strdup (&debug[strlen ("p=")])); + } else if (!g_ascii_strncasecmp (debug, "s=", strlen ("s="))) { + if (!s_tests) + s_tests = g_ptr_array_new_with_free_func (g_free); + g_ptr_array_add (s_tests, g_strdup (&debug[strlen ("s=")])); } else if (!g_ascii_strcasecmp (debug, "slow") || !g_ascii_strcasecmp (debug, "thorough")) { test_quick = FALSE; test_quick_set = TRUE; @@ -362,7 +376,13 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ } } - if (argc && !g_test_initialized ()) { + if (!argc || g_test_initialized ()) { + if (p_tests || s_tests) { + char *msg = g_strdup_printf (">>> nmtst: ignore -p and -s options for test which calls g_test_init() itself"); + + g_array_append_val (debug_messages, msg); + } + } else { /* g_test_init() is a variadic function, so we cannot pass it * (variadic) arguments. If you need to pass additional parameters, * call nmtst_init() with argc==NULL and call g_test_init() yourself. */ @@ -373,6 +393,7 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ GPtrArray *arg_array = g_ptr_array_new (); gs_free char **arg_array_c = NULL; int arg_array_n, j; + static char **s_tests_x, **p_tests_x; if (*argc) { for (i = 0; i < *argc; i++) @@ -383,6 +404,21 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ if (test_quick_set && !test_quick_argv) g_ptr_array_add (arg_array, "-m=quick"); + if (!__nmtst_internal.test_tap_log) { + for (i = 0; p_tests && i < p_tests->len; i++) { + g_ptr_array_add (arg_array, "-p"); + g_ptr_array_add (arg_array, p_tests->pdata[i]); + } + for (i = 0; s_tests && i < s_tests->len; i++) { + g_ptr_array_add (arg_array, "-s"); + g_ptr_array_add (arg_array, s_tests->pdata[i]); + } + } else if (p_tests || s_tests) { + char *msg = g_strdup_printf (">>> nmtst: ignore -p and -s options for tap-tests"); + + g_array_append_val (debug_messages, msg); + } + g_ptr_array_add (arg_array, NULL); arg_array_n = arg_array->len - 1; @@ -408,6 +444,18 @@ __nmtst_init (int *argc, char ***argv, gboolean assert_logging, const char *log_ } *argc = j; } + + /* we must "leak" the test paths because they are not cloned by g_test_init(). */ + if (!__nmtst_internal.test_tap_log) { + if (p_tests) { + p_tests_x = (char **) g_ptr_array_free (p_tests, FALSE); + p_tests = NULL; + } + if (s_tests) { + s_tests_x = (char **) g_ptr_array_free (s_tests, FALSE); + s_tests = NULL; + } + } } if (test_quick_set) |