blob: 76bba3d4289ebddefc2d19707d34d3f7e56c13d6 [file] [edit]
// Copyright 2026 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef SRC_DEVELOPER_DEBUG_DEBUG_AGENT_FAILING_WRITE_STREAM_H_
#define SRC_DEVELOPER_DEBUG_DEBUG_AGENT_FAILING_WRITE_STREAM_H_
#include <zircon/types.h>
#include <cstddef>
#include <memory>
#include "src/developer/debug/debug_agent/debug_agent.h"
#include "src/developer/debug/shared/buffered_stream.h"
namespace debug {
class MessageLoop;
} // namespace debug
namespace debug_agent {
class MockProcess;
// BufferedStream test double that fails every write by invoking its error callback and returning 0.
class FailingWriteStream final : public debug::BufferedStream {
public:
bool Start() override;
bool Stop() override;
bool IsValid() override;
size_t write_calls() const { return write_calls_; }
size_t ConsumeStreamBufferData(const char* data, size_t len) override;
protected:
void ResetInternal() override;
private:
bool valid_ = false;
size_t write_calls_ = 0;
};
struct FailingWriteAgentSetup {
// Creates a connected DebugAgent wired to a FailingWriteStream and completes the Hello handshake.
FailingWriteAgentSetup();
~FailingWriteAgentSetup();
FailingWriteAgentSetup(const FailingWriteAgentSetup&) = delete;
FailingWriteAgentSetup& operator=(const FailingWriteAgentSetup&) = delete;
FailingWriteAgentSetup(FailingWriteAgentSetup&&) = delete;
FailingWriteAgentSetup& operator=(FailingWriteAgentSetup&&) = delete;
std::unique_ptr<DebugAgent> agent;
FailingWriteStream* stream = nullptr;
// Injects a MockProcess for |process_koid| into |agent| and returns a borrowed pointer.
MockProcess* AddProcess(zx_koid_t process_koid) const;
};
// Runs |loop| with a trailing sentinel task and asserts the deferred error handler calls QuitNow()
// before the sentinel executes.
void ExpectDeferredQuitNow(debug::MessageLoop& loop);
} // namespace debug_agent
#endif // SRC_DEVELOPER_DEBUG_DEBUG_AGENT_FAILING_WRITE_STREAM_H_