chromium/net/third_party/quiche/src/quiche/quic/core/quic_trace_visitor_test.cc

// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "quiche/quic/core/quic_trace_visitor.h"

#include <string>
#include <vector>

#include "quiche/quic/core/quic_constants.h"
#include "quiche/quic/platform/api/quic_test.h"
#include "quiche/quic/test_tools/quic_test_utils.h"
#include "quiche/quic/test_tools/simulator/quic_endpoint.h"
#include "quiche/quic/test_tools/simulator/simulator.h"
#include "quiche/quic/test_tools/simulator/switch.h"

namespace quic::test {
namespace {

const QuicByteCount kTransferSize =;
const QuicByteCount kTestStreamNumber =;
const QuicTime::Delta kDelay =;

// The trace for this test is generated using a simulator transfer.
class QuicTraceVisitorTest : public QuicTest {};

TEST_F() {
  char expected_cid[] = {0, 0, 0, 0, 0, 0, 0, 42};
  EXPECT_EQ();
}

TEST_F() {
  std::string version = trace_.protocol_version();
  ASSERT_EQ();
  // Ensure version isn't all-zeroes.
  EXPECT_TRUE();
}

// Check that basic metadata about sent packets is recorded.
TEST_F() {
  auto sent_packets = AllEventsWithType(quic_trace::PACKET_SENT);
  EXPECT_EQ();
  ASSERT_GT();

  EXPECT_EQ();
  EXPECT_EQ();
}

// Ensure that every stream frame that was sent is recorded.
TEST_F() {
  auto sent_packets = AllEventsWithType(quic_trace::PACKET_SENT);

  QuicIntervalSet<QuicStreamOffset> offsets;
  for (const quic_trace::Event& packet : sent_packets) {
    for (const quic_trace::Frame& frame : packet.frames()) {
      if (frame.frame_type() != quic_trace::STREAM) {
        continue;
      }

      const quic_trace::StreamFrameInfo& info = frame.stream_frame_info();
      if (info.stream_id() != kTestStreamNumber) {
        continue;
      }

      ASSERT_GT();
      offsets.Add(info.offset(), info.offset() + info.length());
    }
  }

  ASSERT_EQ();
  EXPECT_EQ();
  EXPECT_EQ();
}

// Ensure that all packets are either acknowledged or lost.
TEST_F() {
  QuicIntervalSet<QuicPacketNumber> packets;
  for (const quic_trace::Event& packet : trace_.events()) {
    if (packet.event_type() == quic_trace::PACKET_RECEIVED) {
      for (const quic_trace::Frame& frame : packet.frames()) {
        if (frame.frame_type() != quic_trace::ACK) {
          continue;
        }

        const quic_trace::AckInfo& info = frame.ack_info();
        for (const auto& block : info.acked_packets()) {
          packets.Add(QuicPacketNumber(block.first_packet()),
                      QuicPacketNumber(block.last_packet()) + 1);
        }
      }
    }
    if (packet.event_type() == quic_trace::PACKET_LOST) {
      packets.Add(QuicPacketNumber(packet.packet_number()),
                  QuicPacketNumber(packet.packet_number()) + 1);
    }
  }

  ASSERT_EQ();
  EXPECT_EQ();
  // We leave some room (20 packets) for the packets which did not receive
  // conclusive status at the end of simulation.
  EXPECT_GT();
}

TEST_F() {
  auto acks = AllEventsWithType(quic_trace::PACKET_RECEIVED);
  ASSERT_EQ();
  ASSERT_EQ();

  // Check that min-RTT at the end is a reasonable approximation.
  EXPECT_LE();
  EXPECT_GE();
}

TEST_F() {
  for (const auto& event : trace_.events()) {
    switch (event.event_type()) {
      case quic_trace::PACKET_SENT:
      case quic_trace::PACKET_RECEIVED:
      case quic_trace::PACKET_LOST:
        ASSERT_TRUE();
        ASSERT_NE();
        break;

      default:
        break;
    }
  }
}

}  // namespace
}  // namespace quic::test