chromium/net/tools/stress_cache/stress_cache.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifdef UNSAFE_BUFFERS_BUILD
// TODO(crbug.com/40284755): Remove this and spanify to fix the errors.
#pragma allow_unsafe_buffers
#endif

// This is a simple application that stress-tests the crash recovery of the disk
// cache. The main application starts a copy of itself on a loop, checking the
// exit code of the child process. When the child dies in an unexpected way,
// the main application quits.

// The child application has two threads: one to exercise the cache in an
// infinite loop, and another one to asynchronously kill the process.

// A regular build should never crash.
// To test that the disk cache doesn't generate critical errors with regular
// application level crashes, edit stress_support.h.

#include <string>
#include <string_view>
#include <vector>

#include "base/at_exit.h"
#include "base/command_line.h"
#include "base/debug/debugger.h"
#include "base/files/file_path.h"
#include "base/functional/bind.h"
#include "base/functional/callback_helpers.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/message_loop/message_pump_type.h"
#include "base/path_service.h"
#include "base/process/launch.h"
#include "base/process/process.h"
#include "base/run_loop.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/utf_string_conversions.h"
#include "base/task/single_thread_task_executor.h"
#include "base/task/single_thread_task_runner.h"
#include "base/threading/platform_thread.h"
#include "base/threading/thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "net/base/io_buffer.h"
#include "net/base/net_errors.h"
#include "net/base/test_completion_callback.h"
#include "net/disk_cache/blockfile/backend_impl.h"
#include "net/disk_cache/blockfile/stress_support.h"
#include "net/disk_cache/disk_cache.h"
#include "net/disk_cache/disk_cache_test_util.h"

#if BUILDFLAG(IS_WIN)
#include "base/logging_win.h"
#endif

Time;

const int kError =;
const int kExpectedCrash =;

// Starts a new process.
int RunSlave(int iteration) {}

// Main loop for the master process.
int MasterCode() {}

// -----------------------------------------------------------------------

std::string GenerateStressKey() {}

// kNumKeys is meant to be enough to have about 3x or 4x iterations before
// the process crashes.
#ifdef NDEBUG
const int kNumKeys = 4000;
#else
const int kNumKeys =;
#endif
const int kNumEntries =;
const int kBufferSize =;
const int kReadSize =;

// Things that an entry can be doing.
enum Operation {};

// This class encapsulates a cache entry and the operations performed on that
// entry. An entry is opened or created as needed, the current content is then
// verified and then something is written to the entry. At that point, the
// |state_| becomes NONE again, waiting for another write, unless the entry is
// closed or deleted.
class EntryWrapper {};

// The data that the main thread is working on.
struct Data {};

Data* g_data =;

void EntryWrapper::DoOpen(int key) {}

void EntryWrapper::OnOpenDone(int key, disk_cache::EntryResult result) {}

void EntryWrapper::DoRead() {}

void EntryWrapper::OnReadDone(int result) {}

void EntryWrapper::DoWrite() {}

void EntryWrapper::OnWriteDone(int size, int result) {}

void EntryWrapper::DoDelete(const std::string& key) {}

void EntryWrapper::OnDeleteDone(int result) {}

void LoopTask();

void EntryWrapper::DoIdle() {}

// The task that keeps the main thread busy. Whenever an entry becomes idle this
// task is executed again.
void LoopTask() {}

// This thread will loop forever, adding and removing entries from the cache.
// iteration is the current crash cycle, so the entries on the cache are marked
// to know which instance of the application wrote them.
void StressTheCache(int iteration) {}

// We want to prevent the timer thread from killing the process while we are
// waiting for the debugger to attach.
bool g_crashing =;

// RunSoon() and CrashCallback() reference each other, unfortunately.
void RunSoon(scoped_refptr<base::SingleThreadTaskRunner> task_runner);

void CrashCallback() {}

void RunSoon(scoped_refptr<base::SingleThreadTaskRunner> task_runner) {}

// We leak everything here :)
bool StartCrashThread() {}

void CrashHandler(const char* file,
                  int line,
                  const std::string_view str,
                  const std::string_view stack_trace) {}

// -----------------------------------------------------------------------

#if BUILDFLAG(IS_WIN)
// {B9A153D4-31C3-48e4-9ABF-D54383F14A0D}
const GUID kStressCacheTraceProviderName = {
    0xb9a153d4, 0x31c3, 0x48e4,
        { 0x9a, 0xbf, 0xd5, 0x43, 0x83, 0xf1, 0x4a, 0xd } };
#endif

int main(int argc, const char* argv[]) {}