diff options
author | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 23:21:40 +0000 |
---|---|---|
committer | deanm@chromium.org <deanm@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-11-21 23:21:40 +0000 |
commit | f727e41d25258a22143c04192b5d98afafae25d2 (patch) | |
tree | 0f5b30dbc519aa91e1f17a0b3ae98d4470670572 /net | |
parent | 156f2c0e187c0283f026fd356a4b682d4b4eaaa1 (diff) | |
download | chromium_src-f727e41d25258a22143c04192b5d98afafae25d2.zip chromium_src-f727e41d25258a22143c04192b5d98afafae25d2.tar.gz chromium_src-f727e41d25258a22143c04192b5d98afafae25d2.tar.bz2 |
Port stress_cache tool.
BUG=4491
Review URL: http://codereview.chromium.org/11202
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@5862 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/disk_cache/stress_cache.cc | 82 | ||||
-rw-r--r-- | net/net.scons | 1 | ||||
-rw-r--r-- | net/stress_cache.scons | 11 |
3 files changed, 67 insertions, 27 deletions
diff --git a/net/disk_cache/stress_cache.cc b/net/disk_cache/stress_cache.cc index dde20ff..610cdc3 100644 --- a/net/disk_cache/stress_cache.cc +++ b/net/disk_cache/stress_cache.cc @@ -10,13 +10,27 @@ // 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> #include "base/at_exit.h" +#include "base/command_line.h" +#include "base/debug_util.h" #include "base/logging.h" #include "base/message_loop.h" #include "base/path_service.h" +#include "base/platform_thread.h" +#include "base/process_util.h" #include "base/string_util.h" #include "base/thread.h" #include "net/disk_cache/disk_cache.h" @@ -25,43 +39,54 @@ using base::Time; const int kError = -1; -const int kExpectedCrash = 1000000; +const int kExpectedCrash = 100; // Starts a new process. int RunSlave(int iteration) { std::wstring exe; PathService::Get(base::FILE_EXE, &exe); - std::wstring command = StringPrintf(L"%ls %d", exe.c_str(), iteration); - - STARTUPINFO startup_info = {0}; - startup_info.cb = sizeof(startup_info); - PROCESS_INFORMATION process_info; - - // I really don't care about this call modifying the string. - if (!::CreateProcess(exe.c_str(), const_cast<wchar_t*>(command.c_str()), NULL, - NULL, FALSE, 0, NULL, NULL, &startup_info, - &process_info)) { +#if defined(OS_WIN) + CommandLine cmdline(StringPrintf(L"%ls %d", exe.c_str(), iteration)); +#elif defined(OS_POSIX) + std::vector<std::string> cmd_argv; + cmd_argv.push_back(WideToUTF8(exe)); + cmd_argv.push_back(IntToString(iteration)); + CommandLine cmdline(cmd_argv); +#endif + + base::ProcessHandle handle; + if (!base::LaunchApp(cmdline, false, false, &handle)) { printf("Unable to run test\n"); return kError; } - DWORD reason = ::WaitForSingleObject(process_info.hProcess, INFINITE); - + // 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(process_info.hProcess, - reinterpret_cast<PDWORD>(&code)) ? true : - false; - - ::CloseHandle(process_info.hProcess); - ::CloseHandle(process_info.hThread); - + bool ok = GetExitCodeProcess(handle, + reinterpret_cast<LPDWORD>(&code)) ? true : + false; + CloseHandle(handle); if (!ok) { 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 } // Main loop for the master process. @@ -121,7 +146,7 @@ void StressTheCache(int iteration) { if (!cache->OpenEntry(keys[key], &entries[slot])) CHECK(cache->CreateEntry(keys[key], &entries[slot])); - sprintf_s(data, "%d %d", iteration, i); + base::snprintf(data, kDataLen, "%d %d", iteration, i); CHECK(kDataLen == entries[slot]->WriteData(0, 0, data, kDataLen, NULL, false)); @@ -153,7 +178,14 @@ class CrashTask : public Task { if (rand() % 100 > 1) { printf("sweet death...\n"); - TerminateProcess(GetCurrentProcess(), kExpectedCrash); +#if defined(OS_WIN) + // Windows does more work on _exit() that we would like, so we use Kill. + base::KillProcess(base::GetCurrentProcId(), kExpectedCrash, false); +#elif defined(OS_POSIX) + // On POSIX, _exit() will terminate the process with minimal cleanup, + // and it is cleaner than killing. + _exit(kExpectedCrash); +#endif } } @@ -176,7 +208,7 @@ bool StartCrashThread() { void CrashHandler(const std::string& str) { g_crashing = true; - __debugbreak(); + DebugUtil::BreakDebugger(); } // ----------------------------------------------------------------------- @@ -191,7 +223,7 @@ int main(int argc, const char* argv[]) { logging::SetLogAssertHandler(CrashHandler); // Some time for the memory manager to flush stuff. - Sleep(3000); + PlatformThread::Sleep(3000); MessageLoop message_loop; char* end; diff --git a/net/net.scons b/net/net.scons index d70222fe..e5e74da 100644 --- a/net/net.scons +++ b/net/net.scons @@ -27,7 +27,6 @@ if env['PLATFORM'] in ('posix', 'darwin'): # TODO(port): delete files from this list as they get ported. to_be_ported = [ 'crash_cache.scons', - 'stress_cache.scons', ] for remove in to_be_ported: sconscript_files.remove(remove) diff --git a/net/stress_cache.scons b/net/stress_cache.scons index 09cd905..e7dfedf 100644 --- a/net/stress_cache.scons +++ b/net/stress_cache.scons @@ -17,6 +17,15 @@ env.ApplySConscript([ '$NET_DIR/using_net.scons', ]) +if env['PLATFORM'] in ('darwin', 'posix'): + env.ApplySConscript(['$THIRD_PARTY_DIR/libevent/using_libevent.scons']) + +env.Prepend( + CPPPATH = [ + '$CHROME_SRC_DIR', + ], +) + if env['PLATFORM'] == 'win32': env.Prepend( CCFLAGS = [ @@ -29,5 +38,5 @@ input_files = [ 'disk_cache/stress_cache.cc', ] -if env['PLATFORM'] == 'win32': +if env['PLATFORM'] in ('posix', 'win32'): env.ChromeTestProgram('stress_cache', input_files) |