Example #1
0
static void
test_unset_display (void)
{
  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
    {
      GdkDisplayManager *manager;

      g_unsetenv ("DISPLAY");

      g_assert (!gdk_init_check (NULL, NULL));
      manager = gdk_display_manager_get ();
      g_assert (manager != NULL);
      g_assert (gdk_display_manager_get_default_display (manager) == NULL);

      exit (0);
    }
  g_test_trap_assert_passed ();

  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
    {
      g_unsetenv ("DISPLAY");

      gdk_init (NULL, NULL);

      exit (0);
    }
  g_test_trap_assert_failed ();
  g_test_trap_assert_stderr ("*cannot open display*");
}
Example #2
0
static void test_static_prop(void)
{
    g_test_trap_subprocess("/qdev/properties/static/default/subprocess", 0, 0);
    g_test_trap_assert_passed();
    g_test_trap_assert_stderr("");
    g_test_trap_assert_stdout("");
}
Example #3
0
static void
test_schema (gpointer data)
{
  SchemaTest *test = (SchemaTest *) data;

  if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDERR))
    {
      gchar *filename = g_strconcat (test->name, ".gschema.xml", NULL);
      gchar *path = g_build_filename (SRCDIR, "schema-tests", filename, NULL);
      gchar *argv[] = {
        "../glib-compile-schemas",
        "--dry-run",
        "--schema-file", path,
        (gchar *)test->opt,
        NULL
      };
      gchar *envp[] = { NULL };
      execve (argv[0], argv, envp);
      g_free (filename);
      g_free (path);
    }
  if (test->err)
    {
      g_test_trap_assert_failed ();
      g_test_trap_assert_stderr (test->err);
    }
  else
    g_test_trap_assert_passed();
}
Example #4
0
File: slice.c Project: Babelz/SaNi
/* 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);
}
Example #5
0
static void test_sc_is_ns_group_dir_private()
{
	if (geteuid() != 0) {
		g_test_skip("this test needs to run as root");
		return;
	}
	const char *ns_dir = sc_test_use_fake_ns_dir();
	g_test_queue_destroy(unmount_dir, (char *)ns_dir);

	if (g_test_subprocess()) {
		// The temporary directory should not be private initially
		g_assert_false(sc_is_ns_group_dir_private());

		/// do what "mount --bind /foo /foo; mount --make-private /foo" does.
		int err;
		err = mount(ns_dir, ns_dir, NULL, MS_BIND, NULL);
		g_assert_cmpint(err, ==, 0);
		err = mount(NULL, ns_dir, NULL, MS_PRIVATE, NULL);
		g_assert_cmpint(err, ==, 0);

		// The temporary directory should now be private
		g_assert_true(sc_is_ns_group_dir_private());
		return;
	}
	g_test_trap_subprocess(NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDERR);
	g_test_trap_assert_passed();
}
Example #6
0
static void test_sc_initialize_ns_groups()
{
	if (geteuid() != 0) {
		g_test_skip("this test needs to run as root");
		return;
	}
	// NOTE: this is g_test_subprocess aware!
	const char *ns_dir = sc_test_use_fake_ns_dir();
	g_test_queue_destroy(unmount_dir, (char *)ns_dir);
	if (g_test_subprocess()) {
		// Initialize namespace groups using a fake directory.
		sc_initialize_ns_groups();

		// Check that the fake directory is now a private mount.
		g_assert_true(sc_is_ns_group_dir_private());

		// Check that the lock file did not leak unclosed.

		// Construct the name of the lock file
		char *lock_file __attribute__ ((cleanup(sc_cleanup_string))) =
		    NULL;
		lock_file =
		    g_strdup_printf("%s/%s", sc_ns_dir, SC_NS_LOCK_FILE);
		// Attempt to open and lock the lock file.
		int lock_fd __attribute__ ((cleanup(sc_cleanup_close))) = -1;
		lock_fd = open(lock_file, O_RDWR | O_CLOEXEC | O_NOFOLLOW);
		g_assert_cmpint(lock_fd, !=, -1);
		// The non-blocking lock operation should not fail
		int err = flock(lock_fd, LOCK_EX | LOCK_NB);
		g_assert_cmpint(err, ==, 0);
		return;
	}
	g_test_trap_subprocess(NULL, 0, G_TEST_SUBPROCESS_INHERIT_STDERR);
	g_test_trap_assert_passed();
}
Example #7
0
static void test_dynamic_globalprop_nouser(void)
{
    g_test_trap_subprocess("/qdev/properties/dynamic/global/nouser/subprocess", 0, 0);
    g_test_trap_assert_passed();
    g_test_trap_assert_stderr("");
    g_test_trap_assert_stdout("");
}
Example #8
0
File: slice.c Project: Babelz/SaNi
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");
}
Example #9
0
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*");
}
Example #10
0
void test_signal(int signal) {
    if (g_test_subprocess()) {
        raise(signal);
    }

    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_passed();
}
Example #11
0
static void test_chnlat(void)
{
	if (g_test_trap_fork(60 * 1000 * 1000, 0) == TRUE) {
		test_connect(FALSE);
		exit(0);
	}

	g_test_trap_assert_passed();
	//g_test_trap_assert_stderr("failed");
}
Example #12
0
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(""));
}
Example #13
0
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);
}
Example #14
0
static void test_dynamic_globalprop(void)
{
    g_test_trap_subprocess("/qdev/properties/dynamic/global/subprocess", 0, 0);
    g_test_trap_assert_passed();
    g_test_trap_assert_stderr_unmatched("*prop1*");
    g_test_trap_assert_stderr_unmatched("*prop2*");
    g_test_trap_assert_stderr("*Warning: global dynamic-prop-type-bad.prop3 has invalid class name\n*");
    g_test_trap_assert_stderr_unmatched("*prop4*");
    g_test_trap_assert_stderr("*Warning: global nohotplug-type.prop5=105 not used\n*");
    g_test_trap_assert_stderr("*Warning: global nondevice-type.prop6 has invalid class name\n*");
    g_test_trap_assert_stdout("");
}
Example #15
0
static void
_test_new_good_good(gpointer fixture, gconstpointer user_data)
{
    if ( ! g_test_undefined() )
            return;
    if ( g_test_subprocess() )
    {
        eventd_event_new_for_uuid_string(EVENTD_EVENT_TEST_UUID, EVENTD_EVENT_TEST_CATEGORY, EVENTD_EVENT_TEST_NAME);
        exit(0);
    }
    g_test_trap_subprocess(NULL, 0, 0);
    g_test_trap_assert_passed();
}
Example #16
0
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();
}
Example #17
0
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();
}
Example #18
0
/* void ClockPrint() */
static void
test_ClockPrint(void)
{
    /* ClockPrint uses internally ClockPrintTime() so we'll stress test that one
       and check here only the print procedure. */
    /* Fork this test to capture stdout. */
    if (g_test_trap_fork(1000000, G_TEST_TRAP_SILENCE_STDERR))
    {
        ClockPrint();
        exit(0);
    }
    g_test_trap_assert_passed();
    /* Consider regular expression to check for more specific "%lds.%ldms". */
    g_test_trap_assert_stderr("*s.*ms*");
}
Example #19
0
static void
test_fallback_calloc (void)
{
  if (g_test_subprocess ())
    {
      GMemVTable vtable = { malloc, realloc, free, NULL, NULL, NULL };
      gpointer p;

      g_mem_set_vtable (&vtable);
      p = g_malloc0 (1000);
      g_free (p);
      exit (0);
    }
  g_test_trap_subprocess (NULL, 0, 0);
  g_test_trap_assert_passed ();
}
Example #20
0
static void
crank_test_meta_timeout (gconstpointer userdata)
{
  CrankTestMetaTimeout *meta = (CrankTestMetaTimeout*) userdata;

  if (g_test_subprocess ())
    {
      meta->func ();
    }
  else
    {
      g_test_trap_subprocess (NULL, meta->time,
                              G_TEST_SUBPROCESS_INHERIT_STDOUT |
                              G_TEST_SUBPROCESS_INHERIT_STDERR);

      g_test_trap_assert_passed ();
    }
}
Example #21
0
File: syslog.c Project: smcv/dbus
static void
test_syslog_normal (Fixture *f,
    gconstpointer data)
{
  if (g_test_subprocess ())
    {
      _dbus_init_system_log ("test-syslog",
          DBUS_LOG_FLAGS_SYSTEM_LOG | DBUS_LOG_FLAGS_STDERR);
      _dbus_log (DBUS_SYSTEM_LOG_INFO, MESSAGE "%d", 42);
      _dbus_log (DBUS_SYSTEM_LOG_WARNING, MESSAGE "%d", 45);
      _dbus_log (DBUS_SYSTEM_LOG_SECURITY, MESSAGE "%d", 666);
      _dbus_log (DBUS_SYSTEM_LOG_ERROR, MESSAGE "%d", 23);

      _dbus_init_system_log ("test-syslog-stderr", DBUS_LOG_FLAGS_STDERR);
      _dbus_log (DBUS_SYSTEM_LOG_INFO,
          MESSAGE "this should not appear in the syslog");
      _dbus_init_system_log ("test-syslog-both",
          DBUS_LOG_FLAGS_SYSTEM_LOG | DBUS_LOG_FLAGS_STDERR);
      _dbus_log (DBUS_SYSTEM_LOG_INFO,
          MESSAGE "this should appear in the syslog and on stderr");
      _dbus_init_system_log ("test-syslog-only", DBUS_LOG_FLAGS_SYSTEM_LOG);
      _dbus_log (DBUS_SYSTEM_LOG_INFO,
          MESSAGE "this should appear in the syslog only");

      exit (0);
    }

  g_test_trap_subprocess (NULL, 0, 0);
  g_test_trap_assert_passed ();
  g_test_trap_assert_stderr ("*" MESSAGE "42\n"
                             "*" MESSAGE "45\n"
                             "*" MESSAGE "666\n"
                             "*" MESSAGE "23\n"
                             "*test-syslog-stderr*" MESSAGE
                               "this should not appear in the syslog\n"
                             "*test-syslog-both*" MESSAGE
                               "this should appear in the syslog and "
                               "on stderr\n");
  g_test_trap_assert_stderr_unmatched ("*this should appear in the syslog "
                                       "only*");
  g_test_trap_assert_stderr_unmatched ("*test-syslog-only*");
}
Example #22
0
static void
test_schema (gpointer data)
{
  SchemaTest *test = (SchemaTest *) data;
  gchar *child_name;

  child_name = g_strdup_printf ("/gschema/%s%s/subprocess/do_compile", test->name, test->opt ? "/opt" : "");
  g_test_trap_subprocess (child_name, 0, 0);
  g_free (child_name);

  if (test->err)
    {
      g_test_trap_assert_failed ();
      g_test_trap_assert_stderr_unmatched ("*CRITICAL*");
      g_test_trap_assert_stderr_unmatched ("*WARNING*");
      g_test_trap_assert_stderr (test->err);
    }
  else
    g_test_trap_assert_passed();
}
Example #23
0
static void
test_x11_autolaunch (void)
{
  if (g_test_subprocess ())
    {
      g_unsetenv ("DISPLAY");
      g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
      g_unsetenv ("XDG_RUNTIME_DIR");
      set_up_mock_dbus_launch ();

      print_address ();

      tear_down_mock_dbus_launch ();
      return;
    }

  g_test_trap_subprocess (NULL, 0, 0);
  g_test_trap_assert_stderr_unmatched ("?*");
  g_test_trap_assert_stdout ("hello:this=address-is-from-the,mock=dbus-launch\n");
  g_test_trap_assert_passed ();
}
Example #24
0
static void
test_ClockPrintTime_validate(long sec, long nsec)
{
    struct timespec ts;
    ts.tv_sec = sec;
    ts.tv_nsec = nsec;

    GString *reference = g_string_new("");
    g_string_printf(reference, "*%lds.%ldms*", sec, nsec / NSEC_PER_MSEC);

    if (g_test_trap_fork(1000000, G_TEST_TRAP_SILENCE_STDERR))
    {
        /* Should print "[seconds]s.[milliseconds]ms ". */
        ClockPrintTime(&ts);
        exit(0);
    }
    g_test_trap_assert_passed();
    g_test_trap_assert_stderr(reference->str);

    g_string_free(reference, TRUE);
}
Example #25
0
static void
test_xdg_runtime (void)
{
  if (g_test_subprocess ())
    {
      g_unsetenv ("DISPLAY");
      g_unsetenv ("DBUS_SESSION_BUS_ADDRESS");
      set_up_mock_xdg_runtime_dir ();
      set_up_mock_dbus_launch ();

      print_address ();

      tear_down_mock_dbus_launch ();
      tear_down_mock_xdg_runtime_dir ();
      return;
    }

  g_test_trap_subprocess (NULL, 0, 0);
  g_test_trap_assert_stderr_unmatched ("?*");
  g_test_trap_assert_stdout ("unix:path=/tmp/gdbus%2Cunix%2Ctest.*/bus\n");
  g_test_trap_assert_passed ();
}
Example #26
0
static void char_console_test(void)
{
    g_test_trap_subprocess("/char/console/subprocess", 0, 0);
    g_test_trap_assert_passed();
    g_test_trap_assert_stdout("CONSOLE");
}
Example #27
0
static void char_stdio_test(void)
{
    g_test_trap_subprocess("/char/stdio/subprocess", 0, 0);
    g_test_trap_assert_passed();
    g_test_trap_assert_stdout("buf");
}