summaryrefslogtreecommitdiffstats
path: root/net/disk_cache
diff options
context:
space:
mode:
authorphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-13 17:38:49 +0000
committerphajdan.jr@chromium.org <phajdan.jr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-01-13 17:38:49 +0000
commitc78566309f95a11cd5253e1cac681038d9885f21 (patch)
tree74bac802565ea385f1585d5d7d8ca15891b1979c /net/disk_cache
parent2ccbdbe2508fdf17fde95a96ee197d45faabe467 (diff)
downloadchromium_src-c78566309f95a11cd5253e1cac681038d9885f21.zip
chromium_src-c78566309f95a11cd5253e1cac681038d9885f21.tar.gz
chromium_src-c78566309f95a11cd5253e1cac681038d9885f21.tar.bz2
Port crash_cache tool to Linux.
Review URL: http://codereview.chromium.org/17353 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7939 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/disk_cache')
-rw-r--r--net/disk_cache/rankings.cc49
-rw-r--r--net/disk_cache/stress_cache.cc36
2 files changed, 38 insertions, 47 deletions
diff --git a/net/disk_cache/rankings.cc b/net/disk_cache/rankings.cc
index e3ff489..d786077 100644
--- a/net/disk_cache/rankings.cc
+++ b/net/disk_cache/rankings.cc
@@ -63,10 +63,20 @@ enum CrashLocation {
ON_REMOVE_3, ON_REMOVE_4, ON_REMOVE_5, ON_REMOVE_6, ON_REMOVE_7, ON_REMOVE_8
};
+void TerminateSelf() {
+#if defined(OS_WIN)
+ // Windows does more work on _exit() than we would like, so we force exit.
+ TerminateProcess(GetCurrentProcess(), 0);
+#elif defined(OS_POSIX)
+ // On POSIX, _exit() will terminate the process with minimal cleanup,
+ // and it is cleaner than killing.
+ _exit(0);
+#endif
+}
+
// Generates a crash on debug builds, acording to the value of g_rankings_crash.
// This used by crash_cache.exe to generate unit-test files.
void GenerateCrash(CrashLocation location) {
-#if defined(OS_WIN)
#ifndef NDEBUG
if (disk_cache::NO_CRASH == g_rankings_crash)
return;
@@ -75,26 +85,32 @@ void GenerateCrash(CrashLocation location) {
switch (g_rankings_crash) {
case disk_cache::INSERT_ONE_1:
case disk_cache::INSERT_LOAD_1:
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
+ default:
+ break;
}
break;
case ON_INSERT_2:
if (disk_cache::INSERT_EMPTY_1 == g_rankings_crash)
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
break;
case ON_INSERT_3:
switch (g_rankings_crash) {
case disk_cache::INSERT_EMPTY_2:
case disk_cache::INSERT_ONE_2:
case disk_cache::INSERT_LOAD_2:
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
+ default:
+ break;
}
break;
case ON_INSERT_4:
switch (g_rankings_crash) {
case disk_cache::INSERT_EMPTY_3:
case disk_cache::INSERT_ONE_3:
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
+ default:
+ break;
}
break;
case ON_REMOVE_1:
@@ -103,42 +119,48 @@ void GenerateCrash(CrashLocation location) {
case disk_cache::REMOVE_HEAD_1:
case disk_cache::REMOVE_TAIL_1:
case disk_cache::REMOVE_LOAD_1:
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
+ default:
+ break;
}
break;
case ON_REMOVE_2:
if (disk_cache::REMOVE_ONE_2 == g_rankings_crash)
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
break;
case ON_REMOVE_3:
if (disk_cache::REMOVE_ONE_3 == g_rankings_crash)
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
break;
case ON_REMOVE_4:
if (disk_cache::REMOVE_HEAD_2 == g_rankings_crash)
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
break;
case ON_REMOVE_5:
if (disk_cache::REMOVE_TAIL_2 == g_rankings_crash)
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
break;
case ON_REMOVE_6:
if (disk_cache::REMOVE_TAIL_3 == g_rankings_crash)
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
break;
case ON_REMOVE_7:
switch (g_rankings_crash) {
case disk_cache::REMOVE_ONE_4:
case disk_cache::REMOVE_LOAD_2:
case disk_cache::REMOVE_HEAD_3:
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
+ default:
+ break;
}
break;
case ON_REMOVE_8:
switch (g_rankings_crash) {
case disk_cache::REMOVE_HEAD_4:
case disk_cache::REMOVE_LOAD_3:
- TerminateProcess(GetCurrentProcess(), 0);
+ TerminateSelf();
+ default:
+ break;
}
break;
default:
@@ -146,7 +168,6 @@ void GenerateCrash(CrashLocation location) {
return;
}
#endif // NDEBUG
-#endif // OS_WIN
}
} // namespace
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc
index 610cdc3..03fb4c1 100644
--- a/net/disk_cache/stress_cache.cc
+++ b/net/disk_cache/stress_cache.cc
@@ -10,16 +10,6 @@
// The child application has two threads: one to exercise the cache in an
// infinite loop, and another one to asynchronously kill the process.
-#include "build/build_config.h"
-
-#if defined(OS_WIN)
-#include <windows.h>
-#elif defined(OS_POSIX)
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#endif
-
#include <string>
#include <vector>
@@ -61,32 +51,12 @@ int RunSlave(int iteration) {
return kError;
}
- // TODO: Find a good place for this kind of code in process_util.
-#if defined(OS_WIN)
- WaitForSingleObject(handle, INFINITE);
- int code;
- bool ok = GetExitCodeProcess(handle,
- reinterpret_cast<LPDWORD>(&code)) ? true :
- false;
- CloseHandle(handle);
- if (!ok) {
+ int exit_code;
+ if (!base::WaitForExitCode(handle, &exit_code)) {
printf("Unable to get return code\n");
return kError;
}
- return code;
-#elif defined(OS_POSIX)
- int status;
- wait(&status);
-
- if (WIFSIGNALED(status))
- return kError;
-
- if (WIFEXITED(status))
- return WEXITSTATUS(status);
-
- NOTREACHED();
- return kError;
-#endif
+ return exit_code;
}
// Main loop for the master process.