trap_fork


Description:

[ Deprecated ( since = "2.38" , replacement = "trap_subprocess" ) ]
public bool trap_fork (uint64 usec_timeout, TestTrapFlags test_trap_flags)

Warning: trap_fork is deprecated. Use GLib.Test.trap_subprocess.

Fork the current test program to execute a test case that might not return or that might abort.

Note:

This function is implemented only on Unix platforms, and is not always reliable due to problems inherent in fork-without-exec. Use trap_subprocess instead.

If usec_timeout is non-0, the forked test case is aborted and considered failing if its run time exceeds it.

The forking behavior can be configured with the TestTrapFlags flags.

In the following example, the test code forks, the forked child process produces some sample output and exits successfully. The forking parent process then asserts successful child program termination and validates child program outputs.

  static void
test_fork_patterns (void)
{
if (g_test_trap_fork (0, G_TEST_TRAP_SILENCE_STDOUT | G_TEST_TRAP_SILENCE_STDERR))
{
g_print ("some stdout text: somagic17\n");
g_printerr ("some stderr text: semagic43\n");
exit (0); // successful test run
}
g_test_trap_assert_passed ();
g_test_trap_assert_stdout ("*somagic17*");
g_test_trap_assert_stderr ("*semagic43*");
}

Parameters:

usec_timeout

Timeout for the forked test in micro seconds.

test_trap_flags

Flags to modify forking behaviour.

Returns:

true for the forked child and false for the executing parent process.


Namespace: GLib.Test
Package: glib-2.0