LCOV - code coverage report
Current view: top level - core/test - run-timer.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 27 27 100.0 %
Date: 2024-01-02 21:04:04 Functions: 7 7 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 2014-2018 IBM Corp
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <stdint.h>
       7                 :            : #include <stdlib.h>
       8                 :            : #include <stdio.h>
       9                 :            : 
      10                 :            : #define __TEST__
      11                 :            : #include <timer.h>
      12                 :            : #include <skiboot.h>
      13                 :            : 
      14                 :            : #define mftb()  (stamp)
      15                 :            : #define sync()
      16                 :            : #define smt_lowest()
      17                 :            : #define smt_medium()
      18                 :            : 
      19                 :            : enum proc_gen proc_gen = proc_gen_unknown;
      20                 :            : 
      21                 :            : static uint64_t stamp, last;
      22                 :            : struct lock;
      23                 :      65666 : static inline void lock_caller(struct lock *l, const char *caller)
      24                 :            : {
      25                 :            :         (void)caller;
      26                 :            :         (void)l;
      27                 :      65666 : }
      28                 :      65666 : static inline void unlock(struct lock *l) { (void)l; }
      29                 :            : 
      30                 :            : unsigned long tb_hz = 512000000;
      31                 :            : 
      32                 :            : #include "../timer.c"
      33                 :            : 
      34                 :            : #define NUM_TIMERS      100
      35                 :            : 
      36                 :            : static struct timer timers[NUM_TIMERS];
      37                 :            : static unsigned int rand_shift, count;
      38                 :            : 
      39                 :          1 : static void init_rand(void)
      40                 :            : {
      41                 :          1 :         unsigned long max = RAND_MAX;
      42                 :            : 
      43                 :            :         /* Get something reasonably small */
      44                 :         16 :         while(max > 0x10000) {
      45                 :         15 :                 rand_shift++;
      46                 :         15 :                 max >>= 1;
      47                 :            :         }
      48                 :          1 : }
      49                 :            : 
      50                 :        100 : static void expiry(struct timer *t, void *data, uint64_t now)
      51                 :            : {
      52                 :            :         (void)data;
      53                 :            :         (void)now;
      54                 :        100 :         assert(t->target >= last);
      55                 :        100 :         count--;
      56                 :        100 : }
      57                 :            : 
      58                 :        100 : void sbe_update_timer_expiry(uint64_t new_target)
      59                 :            : {
      60                 :            :         (void)new_target;
      61                 :            :         /* FIXME: do intersting SLW timer sim */
      62                 :        100 : }
      63                 :            : 
      64                 :        100 : bool sbe_timer_ok(void)
      65                 :            : {
      66                 :        100 :         return true;
      67                 :            : }
      68                 :            : 
      69                 :          1 : int main(void)
      70                 :            : {
      71                 :            :         unsigned int i;
      72                 :            : 
      73                 :          1 :         init_rand();
      74                 :        101 :         for (i = 0; i < NUM_TIMERS; i++) {
      75                 :        100 :                 init_timer(&timers[i], expiry, NULL);
      76                 :        100 :                 schedule_timer(&timers[i], random() >> rand_shift);
      77                 :            :         }
      78                 :          1 :         count = NUM_TIMERS;
      79                 :      65467 :         while(count) {
      80                 :      65466 :                 check_timers(false);
      81                 :      65466 :                 stamp++;
      82                 :            :         }
      83                 :          1 :         return 0;
      84                 :            : }

Generated by: LCOV version 1.14