Files
allwpilib/wpilibc/src/test/native/cpp/ScopedTracerTest.cpp

30 lines
799 B
C++
Raw Normal View History

// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
#include "wpi/system/ScopedTracer.hpp"
#include <string_view>
#include <gtest/gtest.h>
2025-11-07 19:57:55 -05:00
#include "wpi/simulation/SimHooks.hpp"
2025-11-07 19:56:21 -05:00
#include "wpi/util/SmallString.hpp"
#include "wpi/util/StringExtras.hpp"
#include "wpi/util/raw_ostream.hpp"
TEST(ScopedTracerTest, Timing) {
2025-11-07 20:00:05 -05:00
wpi::util::SmallString<128> buf;
wpi::util::raw_svector_ostream os(buf);
2025-11-07 20:00:05 -05:00
wpi::sim::PauseTiming();
{
2025-11-07 20:00:05 -05:00
wpi::ScopedTracer tracer("timing_test", os);
wpi::sim::StepTiming(1.5_s);
}
2025-11-07 20:00:05 -05:00
wpi::sim::ResumeTiming();
std::string_view out = os.str();
2025-11-07 20:00:05 -05:00
EXPECT_TRUE(wpi::util::starts_with(out, "\ttiming_test: 1.5"));
}