static void test_sc_do_optional_mount_failure(gconstpointer snap_debug) { if (g_test_subprocess()) { sc_break("mount", broken_mount); if (GPOINTER_TO_INT(snap_debug) == 1) { g_setenv("SNAP_CONFINE_DEBUG", "1", true); } (void)sc_do_optional_mount("/foo", "/bar", "ext4", MS_RDONLY, NULL); g_test_message("expected sc_do_mount not to return"); sc_reset_faults(); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); if (GPOINTER_TO_INT(snap_debug) == 0) { g_test_trap_assert_stderr ("cannot perform operation: mount -t ext4 -o ro /foo /bar: Permission denied\n"); } else { /* with snap_debug the debug output hides the actual mount commands *but* * they are still shown if there was an error */ g_test_trap_assert_stderr ("DEBUG: performing operation: (disabled) use debug build to see details\n" "cannot perform operation: mount -t ext4 -o ro /foo /bar: Permission denied\n"); } }
static void test_slice_debug (void) { const gchar *oldval; oldval = g_getenv ("G_SLICE"); g_setenv ("G_SLICE", "debug-blocks:always-malloc", TRUE); if (g_test_subprocess ()) { gpointer p, q; p = g_slice_alloc (237); q = g_slice_alloc (259); g_slice_free1 (237, p); g_slice_free1 (259, q); g_slice_debug_tree_statistics (); return; } g_test_trap_subprocess (NULL, 1000000, 0); g_test_trap_assert_passed (); g_test_trap_assert_stderr ("*GSlice: MemChecker: * trunks, * branches, * old branches*"); if (oldval) g_setenv ("G_SLICE", oldval, TRUE); else g_unsetenv ("G_SLICE"); }
static void test_profiler (void) { if (g_test_subprocess ()) { gpointer p; g_mem_set_vtable (glib_mem_profiler_table); p = g_malloc (100); p = g_realloc (p, 200); g_free (p); p = g_malloc0 (1000); g_free (p); p = g_try_malloc (2000); p = g_try_realloc (p, 3000); g_free (p); p = g_malloc (0); p = g_malloc0 (0); p = g_realloc (NULL, 0); p = g_try_malloc (0); p = g_try_realloc (NULL, 0); g_mem_profile (); exit (0); } g_test_trap_subprocess (NULL, 0, 0); g_test_trap_assert_passed (); g_test_trap_assert_stdout ("*GLib Memory statistics*"); }
/* We test deprecated functionality here */ G_GNUC_BEGIN_IGNORE_DEPRECATIONS #ifdef G_ENABLE_DEBUG static void test_slice_nodebug (void) { const gchar *oldval; oldval = g_getenv ("G_SLICE"); g_unsetenv ("G_SLICE"); if (g_test_subprocess ()) { gpointer p, q; p = g_slice_alloc (237); q = g_slice_alloc (259); g_slice_free1 (237, p); g_slice_free1 (259, q); g_slice_debug_tree_statistics (); return; } g_test_trap_subprocess (NULL, 1000000, 0); g_test_trap_assert_passed (); g_test_trap_assert_stderr ("*GSlice: MemChecker: root=NULL*"); if (oldval) g_setenv ("G_SLICE", oldval, TRUE); }
void test_signal(int signal) { if (g_test_subprocess()) { raise(signal); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_passed(); }
void test_help(void) { if (g_test_subprocess()) { char *test_argv[] = { "", "-h" }; evaluate_options(2, test_argv); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stdout(usage_text("")); }
void test_wrong_option(void) { if (g_test_subprocess()) { char *test_argv[] = { "", "--nonex-option" }; evaluate_options(2, test_argv); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("*Unrecognised option*"); }
void test_bind_nonexisting(bool use_ipv6) { warnx("If this test fails check if host %s accidentally exists\n", host1); if (g_test_subprocess()) { test_bind(host1, 6, use_ipv6); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }
void test_bind_local_root(bool use_ipv6) { warnx("If this test fails check that you are not root\n"); if (g_test_subprocess()) { test_bind("localhost", 6, use_ipv6); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }
void test_no_options(void) { if (g_test_subprocess()) { char *test_argv[] = { "" }; evaluate_options(1, test_argv); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr( "*Both ports are required for forwarding.\n\nUsage*"); }
void error_vprintf(const char *fmt, va_list ap) { if (g_test_initialized() && !g_test_subprocess() && getenv("QTEST_SILENT_ERRORS")) { char *msg = g_strdup_vprintf(fmt, ap); g_test_message("%s", msg); g_free(msg); } else { vfprintf(stderr, fmt, ap); } }
static void test_handler_run_failed(void) { if (g_test_subprocess()) { handler_add("http", "unknown-program %s"); handle_uri(TEST_URI); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("*Can't run *unknown-program*"); }
static void test_handler_run_success(void) { if (g_test_subprocess()) { handler_add("http", "echo -n 'handled uri %s'"); handle_uri(TEST_URI); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_passed(); g_test_trap_assert_stdout("handled uri " TEST_URI); }
static void test_sc_string_init__NULL_buf() { if (g_test_subprocess()) { sc_string_init(NULL, 1); g_test_message("expected sc_string_init not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot initialize string, buffer is NULL\n"); }
void test_bind_local(bool use_ipv6) { uint16_t const test_port = 29407; warnx("If this test fails check that TCP port %d is unoccupied\n", test_port); if (g_test_subprocess()) { test_bind("localhost", test_port, use_ipv6); exit(0); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_passed(); }
static void test_sc_must_snprintf__fail() { if (g_test_subprocess()) { char buf[5]; sc_must_snprintf(buf, sizeof buf, "12345"); g_test_message("expected sc_must_snprintf not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot format string: 1234\n"); }
static void test_sc_snap_name_validate__respects_error_protocol() { if (g_test_subprocess()) { sc_snap_name_validate("hello world", NULL); g_test_message("expected sc_snap_name_validate to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("snap name must use lower case letters, digits or dashes\n"); }
static void _test_new_good_null(gpointer fixture, gconstpointer user_data) { if ( ! g_test_undefined() ) return; if ( g_test_subprocess() ) { eventd_event_new_for_uuid_string(EVENTD_EVENT_TEST_UUID, NULL, NULL); exit(0); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }
static void _test_add_data_notnull_good_good(gpointer fixture, gconstpointer user_data) { SettersData *data = fixture; if ( g_test_subprocess() ) { eventd_event_add_data_string(data->event, EVENTD_EVENT_TEST_DATA_NAME, EVENTD_EVENT_TEST_DATA_CONTENT); exit(0); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_passed(); }
static void test_sc_string_append_char__NULL_buf() { if (g_test_subprocess()) { sc_string_append_char(NULL, 2, 'a'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot append character: buffer is NULL\n"); }
static void _test_add_data_null_good_good(gpointer fixture, gconstpointer user_data) { if ( ! g_test_undefined() ) return; if ( g_test_subprocess() ) { eventd_event_add_data_string(NULL, EVENTD_EVENT_TEST_DATA_NAME, EVENTD_EVENT_TEST_DATA_CONTENT); exit(0); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }
static void test_sc_string_quote_NULL_str() { if (g_test_subprocess()) { char buf[16] = { 0 }; sc_string_quote(buf, sizeof buf, NULL); g_test_message("expected sc_string_quote not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr("cannot quote string: string is NULL\n"); }
static void test_sc_enable_sanity_timeout() { if (g_test_subprocess()) { sc_enable_sanity_timeout(); debug("waiting..."); usleep(4 * G_USEC_PER_SEC); debug("woke up"); sc_disable_sanity_timeout(); return; } g_test_trap_subprocess(NULL, 5 * G_USEC_PER_SEC, G_TEST_SUBPROCESS_INHERIT_STDERR); g_test_trap_assert_failed(); }
static void test_sc_unlock_ns_mutex_precondition() { sc_test_use_fake_ns_dir(); if (g_test_subprocess()) { struct sc_ns_group *group = sc_alloc_ns_group(); g_test_queue_free(group); // Try to unlock the mutex, this should abort because we never opened the // lock file and don't have a valid file descriptor. sc_unlock_ns_mutex(group); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }
static void test_double_vtable (void) { if (g_test_subprocess ()) { GMemVTable vtable = { malloc, realloc, free, NULL, NULL, NULL }; g_mem_set_vtable (&vtable); g_mem_set_vtable (&vtable); exit (0); } g_test_trap_subprocess (NULL, 0, 0); g_test_trap_assert_failed (); g_test_trap_assert_stderr ("*can only be set once*"); }
static void test_sc_string_append_char__uninitialized_buf() { if (g_test_subprocess()) { char buf[2] = { 0xFF, 0xFF }; sc_string_append_char(buf, sizeof buf, 'a'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("cannot append character: dst is unterminated\n"); }
// Check that rm_rf_tmp doesn't remove things outside of /tmp static void test_rm_rf_tmp() { if (access("/nonexistent", F_OK) == 0) { g_test_message ("/nonexistent exists but this test doesn't want it to"); g_test_fail(); return; } if (g_test_subprocess()) { rm_rf_tmp("/nonexistent"); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }
static void test_sc_string_append_char__overflow() { if (g_test_subprocess()) { char buf[1] = { 0 }; sc_string_append_char(buf, sizeof buf, 'a'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("cannot append character: not enough space\n"); }
static void test_sc_string_append_char__invalid_zero() { if (g_test_subprocess()) { char buf[2] = { 0 }; sc_string_append_char(buf, sizeof buf, '\0'); g_test_message("expected sc_string_append_char not to return"); g_test_fail(); return; } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); g_test_trap_assert_stderr ("cannot append character: cannot append string terminator\n"); }
static void _test_add_data_notnull_good_bad(gpointer fixture, gconstpointer user_data) { SettersData *data = fixture; if ( ! g_test_undefined() ) return; if ( g_test_subprocess() ) { eventd_event_add_data_string(data->event, EVENTD_EVENT_TEST_DATA_NAME, NULL); exit(0); } g_test_trap_subprocess(NULL, 0, 0); g_test_trap_assert_failed(); }