source: mainline/uspace/lib/c/test/perf.c@ d7f7a4a

Last change on this file since d7f7a4a was d7f7a4a, checked in by Jiří Zárevúcky <zarevucky.jiri@…>, 3 years ago

Replace some license headers with SPDX identifier

Headers are replaced using tools/transorm-copyright.sh only
when it can be matched verbatim with the license header used
throughout most of the codebase.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/*
2 * SPDX-FileCopyrightText: 2018 Vojtech Horky
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <pcut/pcut.h>
8#include <fibril.h>
9#include <perf.h>
10
11PCUT_INIT;
12
13PCUT_TEST_SUITE(perf);
14
15/* Checks that initialization zeroes out all entries. */
16PCUT_TEST(zero_diff)
17{
18 stopwatch_t sw;
19 stopwatch_init(&sw);
20 PCUT_ASSERT_INT_EQUALS(0, (int) stopwatch_get_nanos(&sw));
21}
22
23/* Checks that initialization zeroes out all entries. */
24PCUT_TEST(zero_diff_static)
25{
26 stopwatch_t sw = STOPWATCH_INITIALIZE_STATIC;
27 PCUT_ASSERT_INT_EQUALS(0, (int) stopwatch_get_nanos(&sw));
28}
29
30/* Checks that measuring 1s sleep does not give completely invalid results. */
31PCUT_TEST(stopwatch_smokes)
32{
33 stopwatch_t sw = STOPWATCH_INITIALIZE_STATIC;
34 stopwatch_start(&sw);
35 fibril_sleep(1);
36 stopwatch_stop(&sw);
37 nsec_t diff_nanos = stopwatch_get_nanos(&sw);
38 PCUT_ASSERT_TRUE(diff_nanos > MSEC2NSEC(500));
39 PCUT_ASSERT_TRUE(diff_nanos < SEC2NSEC(5));
40}
41
42/* Checks that setting time works for small values. */
43PCUT_TEST(stopwatch_emulation_works_small)
44{
45 stopwatch_t sw = STOPWATCH_INITIALIZE_STATIC;
46 stopwatch_set_nanos(&sw, 42);
47 PCUT_ASSERT_INT_EQUALS(42, (int) stopwatch_get_nanos(&sw));
48}
49
50/* Checks that setting time works for big values too. */
51PCUT_TEST(stopwatch_emulation_works_big)
52{
53 stopwatch_t sw = STOPWATCH_INITIALIZE_STATIC;
54 stopwatch_set_nanos(&sw, 4200000000021);
55 PCUT_ASSERT_EQUALS(4200000000021, (long long) stopwatch_get_nanos(&sw));
56}
57
58PCUT_EXPORT(perf);
Note: See TracBrowser for help on using the repository browser.