Use distinguished exit status for unittests.
* Enabled a parametric exit status in Terminator::Exit().
* The unittest binary sets this exit status to 2, to distinguish it from
other exit(1) calls in the code base.
BUG=chromium-os:29841
TEST=Build, passes unit tests.
Change-Id: I2bf6a834743e513a647ed7bb2266ef095064d6bc
Reviewed-on: https://gerrit.chromium.org/gerrit/21479
Reviewed-by: Don Garrett <dgarrett@chromium.org>
Commit-Ready: Gilad Arnold <garnold@chromium.org>
Reviewed-by: Gilad Arnold <garnold@chromium.org>
Tested-by: Gilad Arnold <garnold@chromium.org>
diff --git a/terminator.cc b/terminator.cc
index abf57c8..6d00ddb 100644
--- a/terminator.cc
+++ b/terminator.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -8,6 +8,7 @@
namespace chromeos_update_engine {
+volatile sig_atomic_t Terminator::exit_status_ = 1; // default exit status
volatile sig_atomic_t Terminator::exit_blocked_ = 0;
volatile sig_atomic_t Terminator::exit_requested_ = 0;
@@ -17,8 +18,13 @@
signal(SIGTERM, HandleSignal);
}
+void Terminator::Init(int exit_status) {
+ exit_status_ = exit_status;
+ Init();
+}
+
void Terminator::Exit() {
- exit(1);
+ exit(exit_status_);
}
void Terminator::HandleSignal(int signum) {
diff --git a/terminator.h b/terminator.h
index b3fdba6..97c9d7f 100644
--- a/terminator.h
+++ b/terminator.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -16,6 +16,7 @@
public:
// Initializes the terminator and sets up signal handlers.
static void Init();
+ static void Init(int exit_status);
// Terminates the current process.
static void Exit();
@@ -37,6 +38,7 @@
// The signal handler.
static void HandleSignal(int signum);
+ static volatile sig_atomic_t exit_status_;
static volatile sig_atomic_t exit_blocked_;
static volatile sig_atomic_t exit_requested_;
};
diff --git a/terminator_unittest.cc b/terminator_unittest.cc
index b0f4191..68d4d13 100644
--- a/terminator_unittest.cc
+++ b/terminator_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -34,7 +34,7 @@
}
void RaiseSIGTERM() {
- ASSERT_EXIT(raise(SIGTERM), ExitedWithCode(1), "");
+ ASSERT_EXIT(raise(SIGTERM), ExitedWithCode(2), "");
}
} // namespace {}
@@ -54,9 +54,9 @@
}
TEST_F(TerminatorDeathTest, ExitTest) {
- ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(1), "");
+ ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(2), "");
Terminator::set_exit_blocked(true);
- ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(1), "");
+ ASSERT_EXIT(Terminator::Exit(), ExitedWithCode(2), "");
}
TEST_F(TerminatorDeathTest, RaiseSignalTest) {
@@ -68,7 +68,7 @@
TEST_F(TerminatorDeathTest, ScopedTerminatorExitUnblockerExitTest) {
Terminator::set_exit_blocked(true);
Terminator::exit_requested_ = 1;
- ASSERT_EXIT(UnblockExitThroughUnblocker(), ExitedWithCode(1), "");
+ ASSERT_EXIT(UnblockExitThroughUnblocker(), ExitedWithCode(2), "");
}
} // namespace chromeos_update_engine
diff --git a/testrunner.cc b/testrunner.cc
index 725b5b5..59b1b4b 100644
--- a/testrunner.cc
+++ b/testrunner.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
+// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -21,7 +21,12 @@
g_thread_init(NULL);
dbus_g_thread_init();
base::AtExitManager exit_manager;
- chromeos_update_engine::Terminator::Init();
+ // TODO(garnold) temporarily cause the unittest binary to exit with status
+ // code 2 upon catching a SIGTERM. This will help diagnose why the unittest
+ // binary is perceived as failing by the buildbot. We should revert it to use
+ // the default exit status of 1. Corresponding reverts are necessary in
+ // terminator_unittest.cc.
+ chromeos_update_engine::Terminator::Init(2);
chromeos_update_engine::Subprocess::Init();
CommandLine::Init(argc, argv);
::testing::InitGoogleTest(&argc, argv);