LCOV - code coverage report
Current view: top level - core/test - run-timebase.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 20 20 100.0 %
Date: 2024-01-02 21:04:04 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /*
       3                 :            :  * Copyright 2015-2016 IBM Corp.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <stdint.h>
       7                 :            : #include <stdlib.h>
       8                 :            : #include <stdio.h>
       9                 :            : #include <assert.h>
      10                 :            : 
      11                 :            : #define __TEST__
      12                 :            : #include <timebase.h>
      13                 :            : 
      14                 :            : unsigned long tb_hz = 512000000;
      15                 :            : 
      16                 :          1 : int main(void)
      17                 :            : {
      18                 :            :         /* This is a fairly solid assumption that the math we're doing
      19                 :            :          * is based on tb_hz of exactly 512mhz.
      20                 :            :          * If we do start doing the math on different tb_hz, you probably
      21                 :            :          * want to go and audit every bit of code that touches tb to
      22                 :            :          * count/delay things.
      23                 :            :          */
      24                 :          1 :         assert(tb_hz == 512000000);
      25                 :          1 :         assert(secs_to_tb(1) == tb_hz);
      26                 :          1 :         assert(secs_to_tb(2) == 1024000000);
      27                 :          1 :         assert(secs_to_tb(10) == 5120000000);
      28                 :          1 :         assert(tb_to_secs(512000000) == 1);
      29                 :          1 :         assert(tb_to_secs(5120000000) == 10);
      30                 :          1 :         assert(tb_to_secs(1024000000) == 2);
      31                 :            : 
      32                 :          1 :         assert(msecs_to_tb(1) == 512000);
      33                 :          1 :         assert(msecs_to_tb(100) == 51200000);
      34                 :          1 :         assert(msecs_to_tb(5) == 2560000);
      35                 :          1 :         assert(tb_to_msecs(512000) == 1);
      36                 :            : 
      37                 :          1 :         assert(usecs_to_tb(5) == 2560);
      38                 :          1 :         assert(tb_to_usecs(2560) == 5);
      39                 :          1 :         assert(usecs_to_tb(5)*1000 == msecs_to_tb(5));
      40                 :          1 :         assert(tb_to_usecs(512000) == 1000);
      41                 :            : 
      42                 :          1 :         assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)) == TB_AAFTERB);
      43                 :          1 :         assert(tb_compare(msecs_to_tb(5), usecs_to_tb(50000)) == TB_ABEFOREB);
      44                 :          1 :         assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)*1000) == TB_AEQUALB);
      45                 :            : 
      46                 :          1 :         return 0;
      47                 :            : }

Generated by: LCOV version 1.14