summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2015-11-23 18:15:39 +0100
committerThomas Haller <thaller@redhat.com>2015-11-24 11:14:48 +0100
commit243d0facb89203647c24bca2fe06e2c917e6a8fb (patch)
tree58f4663b4f8d9f26e3dc393448aa9342f69c8deb
parent7eed71d860b5e91c2da1c66396f8c3135eb37eb7 (diff)
downloadNetworkManager-243d0facb89203647c24bca2fe06e2c917e6a8fb.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. (cherry picked from commit 73cb57910835ef46d43bb92309def186e38534cf)
-rw-r--r--include/nm-test-utils.h50
1 files changed, 49 insertions, 1 deletions
diff --git a/include/nm-test-utils.h b/include/nm-test-utils.h
index 3630d78bcd..0067fa7446 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>
@@ -257,6 +261,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;
@@ -315,6 +321,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;
@@ -353,7 +367,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. */
@@ -364,6 +384,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++)
@@ -374,6 +395,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;
@@ -399,6 +435,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)