Skip to content
Snippets Groups Projects
Commit f8447b02 authored by Marty Faltesek's avatar Marty Faltesek Committed by CQ bot account: commit-bot@chromium.org
Browse files

[zircon][zxtest] Migrate ticks to zxtest and port to cpp

Test: time-test

Bug: ZX-3741 #done

Change-Id: I37b0a2e3947ba29b63fa4b1b1f066a9e88231497
parent 99311885
No related branches found
No related tags found
No related merge requests found
......@@ -8,9 +8,9 @@ source_set("time") {
"ticks.cpp",
]
deps = [
"$zx/system/ulib/fbl",
"$zx/system/ulib/fdio",
"$zx/system/ulib/runtime",
"$zx/system/ulib/unittest",
"$zx/system/ulib/zircon",
"$zx/system/ulib/zx",
"$zx/system/ulib/zxtest",
]
}
......@@ -3,28 +3,26 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <zircon/syscalls.h>
#include <unittest/unittest.h>
#include <inttypes.h>
// Calculation of elapsed time using ticks.
static bool elapsed_time_using_ticks(void) {
BEGIN_TEST;
#include <lib/zx/time.h>
#include <zircon/syscalls.h>
#include <zxtest/zxtest.h>
zx_ticks_t per_second = zx_ticks_per_second();
ASSERT_GT(per_second, 0u, "Invalid ticks per second");
unittest_printf("Ticks per second: %" PRIu64 "\n", per_second);
namespace {
zx_ticks_t x = zx_ticks_get();
zx_ticks_t y = zx_ticks_get();
ASSERT_GE(y, x, "Ticks went backwards");
// Calculation of elapsed time using ticks.
TEST(TicksTest, ElapsedTimeUsingTicks) {
zx::ticks ticks_per_second = zx::ticks::per_second();
ASSERT_GT(ticks_per_second, zx::ticks(0), "Invalid ticks per second");
double seconds = (double)(y - x) / (double)per_second;
ASSERT_GE(seconds, 0u, "Time went backwards");
zx::ticks start = zx::ticks::now();
zx::ticks end = zx::ticks::now();
ASSERT_GE(end, start, "Ticks went backwards");
END_TEST;
double seconds = static_cast<double>((end - start).get()) /
static_cast<double>(ticks_per_second.get());
ASSERT_GE(seconds, 0, "Time went backwards");
}
BEGIN_TEST_CASE(ticks_tests)
RUN_TEST(elapsed_time_using_ticks)
END_TEST_CASE(ticks_tests)
} // namespace
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment