Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3337)

Unified Diff: chromecast/app/linux/cast_crash_reporter_client_unittest.cc

Issue 1240843003: Reland of place system IO calls in chromecast/crash with Chrome utilities. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Fix: Guard thread-restricted test with #define Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | chromecast/crash/linux/crash_util.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chromecast/app/linux/cast_crash_reporter_client_unittest.cc
diff --git a/chromecast/app/linux/cast_crash_reporter_client_unittest.cc b/chromecast/app/linux/cast_crash_reporter_client_unittest.cc
index 88cbad9c50c328317bc5d28f6c29ff812afa3b06..47b7ad3683bd85604e6d510b0f6095a735de8cb6 100644
--- a/chromecast/app/linux/cast_crash_reporter_client_unittest.cc
+++ b/chromecast/app/linux/cast_crash_reporter_client_unittest.cc
@@ -10,6 +10,7 @@
#include "base/files/file_util.h"
#include "base/memory/scoped_vector.h"
#include "base/test/scoped_path_override.h"
+#include "base/threading/thread_restrictions.h"
#include "chromecast/app/linux/cast_crash_reporter_client.h"
#include "chromecast/crash/app_state_tracker.h"
#include "chromecast/crash/linux/crash_util.h"
@@ -46,71 +47,115 @@ ScopedVector<DumpInfo> GetCurrentDumps(const std::string& logfile_path) {
} // namespace
-TEST(CastCrashReporterClientTest, EndToEnd) {
- // Set up a temporary directory which will be used as our fake home dir.
- base::FilePath fake_home_dir;
- ASSERT_TRUE(base::CreateNewTempDirectory("", &fake_home_dir));
- base::ScopedPathOverride home(base::DIR_HOME, fake_home_dir);
+class CastCrashReporterClientTest : public testing::Test {
+ protected:
+ CastCrashReporterClientTest() {}
+ ~CastCrashReporterClientTest() override {}
- // Set a callback to be used in place of the |dumpstate| executable.
- CrashUtil::SetDumpStateCbForTest(base::Bind(&WriteFakeDumpStateFile));
+ static void SetUpTestCase() {
+ // Set a callback to be used in place of the |dumpstate| executable.
+ CrashUtil::SetDumpStateCbForTest(base::Bind(&WriteFakeDumpStateFile));
+ }
- // "Launch" YouTube.
- AppStateTracker::SetLastLaunchedApp("youtube");
- AppStateTracker::SetCurrentApp("youtube");
+ // testing::Test implementation:
+ void SetUp() override {
+ // Set up a temporary directory which will be used as our fake home dir.
+ ASSERT_TRUE(base::CreateNewTempDirectory("", &fake_home_dir_));
+ home_override_.reset(
+ new base::ScopedPathOverride(base::DIR_HOME, fake_home_dir_));
+
+ // "Launch" YouTube.
+ AppStateTracker::SetLastLaunchedApp("youtube");
+ AppStateTracker::SetCurrentApp("youtube");
+
+ // "Launch" and switch to Pandora.
+ AppStateTracker::SetLastLaunchedApp("pandora");
+ AppStateTracker::SetCurrentApp("pandora");
+
+ // "Launch" Netflix.
+ AppStateTracker::SetLastLaunchedApp("netflix");
+ // Netflix crashed.
+
+ // A minidump file is created.
+ base::CreateTemporaryFile(&minidump_path_);
+ base::File minidump(minidump_path_,
+ base::File::FLAG_OPEN | base::File::FLAG_APPEND);
+ minidump.Write(0, kFakeMinidumpContents, sizeof(kFakeMinidumpContents) - 1);
+ minidump.Close();
+ }
- // "Launch" and switch to Pandora.
- AppStateTracker::SetLastLaunchedApp("pandora");
- AppStateTracker::SetCurrentApp("pandora");
+ void TearDown() override {
+ // Remove IO restrictions in order to examine the state of the filesystem.
+ base::ThreadRestrictions::SetIOAllowed(true);
+
+ // Assert that the original file has been moved.
+ ASSERT_FALSE(base::PathExists(minidump_path_));
+
+ // Assert that the file has been moved to "minidumps", with the expected
+ // contents.
+ std::string contents;
+ base::FilePath new_minidump =
+ fake_home_dir_.Append("minidumps").Append(minidump_path_.BaseName());
+ ASSERT_TRUE(base::PathExists(new_minidump));
+ ASSERT_TRUE(base::ReadFileToString(new_minidump, &contents));
+ ASSERT_EQ(kFakeMinidumpContents, contents);
+
+ // Assert that the dumpstate file has been written with the expected
+ // contents.
+ base::FilePath dumpstate = new_minidump.AddExtension(".txt.gz");
+ ASSERT_TRUE(base::PathExists(dumpstate));
+ ASSERT_TRUE(base::ReadFileToString(dumpstate, &contents));
+ ASSERT_EQ(kFakeDumpstateContents, contents);
+
+ // Assert that the lockfile has logged the correct information.
+ base::FilePath lockfile =
+ fake_home_dir_.Append("minidumps").Append("lockfile");
+ ASSERT_TRUE(base::PathExists(lockfile));
+ ScopedVector<DumpInfo> dumps = GetCurrentDumps(lockfile.value());
+ ASSERT_EQ(1u, dumps.size());
+
+ const DumpInfo& dump_info = *(dumps[0]);
+ ASSERT_TRUE(dump_info.valid());
+ EXPECT_EQ(new_minidump.value(), dump_info.crashed_process_dump());
+ EXPECT_EQ(dumpstate.value(), dump_info.logfile());
+ EXPECT_EQ("youtube", dump_info.params().previous_app_name);
+ EXPECT_EQ("pandora", dump_info.params().current_app_name);
+ EXPECT_EQ("netflix", dump_info.params().last_app_name);
+ }
- // "Launch" Netflix.
- AppStateTracker::SetLastLaunchedApp("netflix");
- // Netflix crashed.
+ const base::FilePath& minidump_path() { return minidump_path_; }
+
+ private:
+ base::FilePath fake_home_dir_;
+ base::FilePath minidump_path_;
+ scoped_ptr<base::ScopedPathOverride> home_override_;
+};
+
+#if ENABLE_THREAD_RESTRICTIONS
+// This test shall only be run when thread restricitons are enabled. Otherwise,
+// the thread will not actually be IO-restricted, and the final ASSERT will
+// fail.
+TEST_F(CastCrashReporterClientTest, EndToEndTestOnIORestrictedThread) {
+ // Handle a "crash" on an IO restricted thread.
+ base::ThreadRestrictions::SetIOAllowed(false);
+ CastCrashReporterClient client;
+ ASSERT_TRUE(client.HandleCrashDump(minidump_path().value().c_str()));
- // A minidump file is created.
- base::FilePath minidump_path;
- base::CreateTemporaryFile(&minidump_path);
- base::File minidump(minidump_path,
- base::File::FLAG_OPEN | base::File::FLAG_APPEND);
- minidump.Write(0, kFakeMinidumpContents, sizeof(kFakeMinidumpContents) - 1);
- minidump.Close();
+ // Assert that the thread is IO restricted when the function exits.
+ // Note that SetIOAllowed returns the previous value.
+ ASSERT_FALSE(base::ThreadRestrictions::SetIOAllowed(true));
+}
+#endif // ENABLE_THREAD_RESTRICTIONS
- // Handle the crash.
+TEST_F(CastCrashReporterClientTest, EndToEndTestOnNonIORestrictedThread) {
+ // Handle a crash on a non-IO restricted thread.
+ base::ThreadRestrictions::SetIOAllowed(true);
CastCrashReporterClient client;
- ASSERT_TRUE(client.HandleCrashDump(minidump_path.value().c_str()));
-
- // Assert that the original file has been moved.
- ASSERT_FALSE(base::PathExists(minidump_path));
-
- // Assert that the file has been moved to "minidumps", with the expected
- // contents.
- std::string contents;
- base::FilePath new_minidump =
- fake_home_dir.Append("minidumps").Append(minidump_path.BaseName());
- ASSERT_TRUE(base::PathExists(new_minidump));
- ASSERT_TRUE(base::ReadFileToString(new_minidump, &contents));
- ASSERT_EQ(kFakeMinidumpContents, contents);
-
- // Assert that the dumpstate file has been written with the expected contents.
- base::FilePath dumpstate = new_minidump.AddExtension(".txt.gz");
- ASSERT_TRUE(base::PathExists(dumpstate));
- ASSERT_TRUE(base::ReadFileToString(dumpstate, &contents));
- ASSERT_EQ(kFakeDumpstateContents, contents);
-
- // Assert that the lockfile has logged the correct information.
- base::FilePath lockfile =
- fake_home_dir.Append("minidumps").Append("lockfile");
- ASSERT_TRUE(base::PathExists(lockfile));
- ScopedVector<DumpInfo> dumps = GetCurrentDumps(lockfile.value());
- ASSERT_EQ(1u, dumps.size());
-
- const DumpInfo& dump_info = *(dumps[0]);
- ASSERT_TRUE(dump_info.valid());
- EXPECT_EQ(new_minidump.value(), dump_info.crashed_process_dump());
- EXPECT_EQ(dumpstate.value(), dump_info.logfile());
- EXPECT_EQ("youtube", dump_info.params().previous_app_name);
- EXPECT_EQ("pandora", dump_info.params().current_app_name);
- EXPECT_EQ("netflix", dump_info.params().last_app_name);
+ ASSERT_TRUE(client.HandleCrashDump(minidump_path().value().c_str()));
+
+ // Assert that the thread is not IO restricted when the function exits.
+ // Note that SetIOAllowed returns the previous value.
+ ASSERT_TRUE(base::ThreadRestrictions::SetIOAllowed(true));
}
-} // namespace chromecast
+} // namespace chromecast
« no previous file with comments | « no previous file | chromecast/crash/linux/crash_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698