diff options
author | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-09-12 04:01:37 +0000 |
---|---|---|
committer | shiqian <shiqian@861a406c-534a-0410-8894-cb66d6ee9925> | 2008-09-12 04:01:37 +0000 |
commit | c3b4de35a18a1f011e8009d4d794f787f7e4e0c1 (patch) | |
tree | 8522f2db6e168ee4e829c2e7f2cf6dfbaaab30c7 /include/gtest/gtest-death-test.h | |
parent | acc68fa2ae88d0ab46bff0afdccd2554350f1b5f (diff) | |
download | googletest-c3b4de35a18a1f011e8009d4d794f787f7e4e0c1.tar.gz |
Improves thread-safe death tests by changing to the original working directory before they are executed; also fixes out-dated comments about death tests.
git-svn-id: http://googletest.googlecode.com/svn/trunk@88 861a406c-534a-0410-8894-cb66d6ee9925
Diffstat (limited to 'include/gtest/gtest-death-test.h')
-rw-r--r-- | include/gtest/gtest-death-test.h | 36 |
1 files changed, 20 insertions, 16 deletions
diff --git a/include/gtest/gtest-death-test.h b/include/gtest/gtest-death-test.h index cbd41fe..6fae47f 100644 --- a/include/gtest/gtest-death-test.h +++ b/include/gtest/gtest-death-test.h @@ -56,29 +56,19 @@ GTEST_DECLARE_string(death_test_style); // Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is // executed: // -// 1. The assertion fails immediately if there are more than one -// active threads. This is because it's safe to fork() only when -// there is a single thread. +// 1. It generates a warning if there is more than one active +// thread. This is because it's safe to fork() or clone() only +// when there is a single thread. // -// 2. The parent process forks a sub-process and runs the death test -// in it; the sub-process exits with code 0 at the end of the death -// test, if it hasn't exited already. +// 2. The parent process clone()s a sub-process and runs the death +// test in it; the sub-process exits with code 0 at the end of the +// death test, if it hasn't exited already. // // 3. The parent process waits for the sub-process to terminate. // // 4. The parent process checks the exit code and error message of // the sub-process. // -// Note: -// -// It's not safe to call exit() if the current process is forked from -// a multi-threaded process, so people usually call _exit() instead in -// such a case. However, we are not concerned with this as we run -// death tests only when there is a single thread. Since exit() has a -// cleaner semantics (it also calls functions registered with atexit() -// and on_exit()), this macro calls exit() instead of _exit() to -// terminate the child process. -// // Examples: // // ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number"); @@ -95,6 +85,20 @@ GTEST_DECLARE_string(death_test_style); // } // // ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!"); +// +// Known caveats: +// +// A "threadsafe" style death test obtains the path to the test +// program from argv[0] and re-executes it in the sub-process. For +// simplicity, the current implementation doesn't search the PATH +// when launching the sub-process. This means that the user must +// invoke the test program via a path that contains at least one +// path separator (e.g. path/to/foo_test and +// /absolute/path/to/bar_test are fine, but foo_test is not). This +// is rarely a problem as people usually don't put the test binary +// directory in PATH. +// +// TODO(wan@google.com): make thread-safe death tests search the PATH. // Asserts that a given statement causes the program to exit, with an // integer exit status that satisfies predicate, and emitting error output |