2020-12-26 14:12:05 -08:00
|
|
|
// 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.
|
2020-09-27 03:10:11 -04:00
|
|
|
|
2025-11-11 18:05:12 -08:00
|
|
|
#include "wpi/system/ScopedTracer.hpp"
|
|
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
#include <string_view>
|
|
|
|
|
|
2023-08-28 15:13:34 -07:00
|
|
|
#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"
|
2020-09-27 03:10:11 -04:00
|
|
|
|
|
|
|
|
TEST(ScopedTracerTest, Timing) {
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::util::SmallString<128> buf;
|
|
|
|
|
wpi::util::raw_svector_ostream os(buf);
|
2021-06-06 16:13:58 -07:00
|
|
|
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::sim::PauseTiming();
|
2020-09-27 03:10:11 -04:00
|
|
|
{
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::ScopedTracer tracer("timing_test", os);
|
|
|
|
|
wpi::sim::StepTiming(1.5_s);
|
2020-09-27 03:10:11 -04:00
|
|
|
}
|
2025-11-07 20:00:05 -05:00
|
|
|
wpi::sim::ResumeTiming();
|
2020-09-27 03:10:11 -04:00
|
|
|
|
2021-06-06 16:13:58 -07:00
|
|
|
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"));
|
2020-09-27 03:10:11 -04:00
|
|
|
}
|