xref: /aosp_15_r20/external/executorch/runtime/platform/test/clock_test.cpp (revision 523fa7a60841cd1ecfb9cc4201f1ca8b03ed023a)
1 /*
2  * Copyright (c) Meta Platforms, Inc. and affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #include <executorch/runtime/platform/clock.h>
10 
11 #include <executorch/runtime/platform/test/stub_platform.h>
12 
13 #include <gtest/gtest.h>
14 
15 using namespace ::testing;
16 
17 class PalSpy : public PlatformIntercept {
18  public:
ticks_to_ns_multiplier()19   et_tick_ratio_t ticks_to_ns_multiplier() override {
20     return tick_ns_multiplier;
21   }
22 
23   et_tick_ratio_t tick_ns_multiplier = {1, 1};
24 };
25 
TEST(ClockTest,ConvertTicksToNsSanity)26 TEST(ClockTest, ConvertTicksToNsSanity) {
27   PalSpy spy;
28   InterceptWith iw(spy);
29 
30   spy.tick_ns_multiplier = {3, 2};
31   auto ns = executorch::runtime::ticks_to_ns(10);
32   ASSERT_EQ(15, ns); // 10 ticks * 3/2 = 15 ns
33 
34   spy.tick_ns_multiplier = {2, 7};
35   ns = executorch::runtime::ticks_to_ns(14);
36   ASSERT_EQ(4, ns); // 14 ticks * 2/7 = 4 ns
37 }
38