LCOV - code coverage report
Current view: top level - core/test - run-cpufeatures.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 91 91 100.0 %
Date: 2024-09-10 18:37:41 Functions: 3 3 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 2019 IBM Corp.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <skiboot.h>
       7                 :            : #include <stdio.h>
       8                 :            : #include <stdlib.h>
       9                 :            : #include <stdbool.h>
      10                 :            : 
      11                 :            : /* Override this for testing. */
      12                 :            : #define is_rodata(p) fake_is_rodata(p)
      13                 :            : 
      14                 :            : char __rodata_start[16];
      15                 :            : #define __rodata_end (__rodata_start + sizeof(__rodata_start))
      16                 :            : 
      17                 :       4484 : static inline bool fake_is_rodata(const void *p)
      18                 :            : {
      19                 :       4484 :         return ((char *)p >= __rodata_start && (char *)p < __rodata_end);
      20                 :            : }
      21                 :            : 
      22                 :            : #define zalloc(bytes) calloc((bytes), 1)
      23                 :            : 
      24                 :            : #include "../device.c"
      25                 :            : #include <assert.h>
      26                 :            : #include "../../test/dt_common.c"
      27                 :            : 
      28                 :            : #define __TEST__
      29                 :            : 
      30                 :            : static inline unsigned long mfspr(unsigned int spr);
      31                 :            : 
      32                 :            : #include <ccan/str/str.c>
      33                 :            : 
      34                 :            : #include "../cpufeatures.c"
      35                 :            : 
      36                 :            : static unsigned long fake_pvr = PVR_TYPE_P8;
      37                 :            : 
      38                 :         11 : static inline unsigned long mfspr(unsigned int spr)
      39                 :            : {
      40                 :         11 :         assert(spr == SPR_PVR);
      41                 :         11 :         return fake_pvr;
      42                 :            : }
      43                 :            : 
      44                 :          1 : int main(void)
      45                 :            : {
      46                 :            :         struct dt_node *dt_root;
      47                 :            : 
      48                 :          1 :         dt_root = dt_new_root("");
      49                 :          1 :         dt_add_cpufeatures(dt_root);
      50                 :          1 :         dump_dt(dt_root, 0, true);
      51                 :          1 :         dt_free(dt_root);
      52                 :            : 
      53                 :          1 :         fake_pvr = (PVR_TYPE_P8E << 16) | 0x100; // P8E DD1.0
      54                 :          1 :         dt_root = dt_new_root("");
      55                 :          1 :         dt_add_cpufeatures(dt_root);
      56                 :          1 :         dump_dt(dt_root, 0, false);
      57                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
      58                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
      59                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
      60                 :          1 :         dt_free(dt_root);
      61                 :            : 
      62                 :          1 :         fake_pvr = (PVR_TYPE_P8E << 16) | 0x200; // P8E DD2.0
      63                 :          1 :         dt_root = dt_new_root("");
      64                 :          1 :         dt_add_cpufeatures(dt_root);
      65                 :          1 :         dump_dt(dt_root, 0, false);
      66                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
      67                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
      68                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
      69                 :          1 :         dt_free(dt_root);
      70                 :            : 
      71                 :          1 :         fake_pvr = (PVR_TYPE_P8 << 16) | 0x100; // P8 DD1.0
      72                 :          1 :         dt_root = dt_new_root("");
      73                 :          1 :         dt_add_cpufeatures(dt_root);
      74                 :          1 :         dump_dt(dt_root, 0, false);
      75                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
      76                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
      77                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
      78                 :          1 :         dt_free(dt_root);
      79                 :            : 
      80                 :          1 :         fake_pvr = (PVR_TYPE_P8 << 16) | 0x200; // P8 DD2.0
      81                 :          1 :         dt_root = dt_new_root("");
      82                 :          1 :         dt_add_cpufeatures(dt_root);
      83                 :          1 :         dump_dt(dt_root, 0, false);
      84                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
      85                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
      86                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
      87                 :          1 :         dt_free(dt_root);
      88                 :            : 
      89                 :          1 :         fake_pvr = (PVR_TYPE_P8NVL << 16) | 0x100; // P8NVL DD1.0
      90                 :          1 :         dt_root = dt_new_root("");
      91                 :          1 :         dt_add_cpufeatures(dt_root);
      92                 :          1 :         dump_dt(dt_root, 0, false);
      93                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix") == 0);
      94                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
      95                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
      96                 :          1 :         dt_free(dt_root);
      97                 :            : 
      98                 :          1 :         fake_pvr = (PVR_TYPE_P9 << 16) | 0x200; // P9 DD2.0
      99                 :          1 :         dt_root = dt_new_root("");
     100                 :          1 :         dt_add_cpufeatures(dt_root);
     101                 :          1 :         dump_dt(dt_root, 0, false);
     102                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
     103                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
     104                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
     105                 :          1 :         dt_free(dt_root);
     106                 :            : 
     107                 :          1 :         fake_pvr = (PVR_TYPE_P9 << 16) | 0x201; // P9 DD2.1
     108                 :          1 :         dt_root = dt_new_root("");
     109                 :          1 :         dt_add_cpufeatures(dt_root);
     110                 :          1 :         dump_dt(dt_root, 0, false);
     111                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
     112                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") == 0);
     113                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
     114                 :          1 :         dt_free(dt_root);
     115                 :            : 
     116                 :          1 :         fake_pvr = (PVR_TYPE_P9 << 16) | 0x202; // P9 DD2.2
     117                 :          1 :         dt_root = dt_new_root("");
     118                 :          1 :         dt_add_cpufeatures(dt_root);
     119                 :          1 :         dump_dt(dt_root, 0, false);
     120                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
     121                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") != 0);
     122                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") != 0);
     123                 :          1 :         dt_free(dt_root);
     124                 :            : 
     125                 :          1 :         fake_pvr = (PVR_TYPE_P9 << 16) | 0x203; // P9 DD2.3
     126                 :          1 :         dt_root = dt_new_root("");
     127                 :          1 :         dt_add_cpufeatures(dt_root);
     128                 :          1 :         dump_dt(dt_root, 0, false);
     129                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
     130                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") != 0);
     131                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
     132                 :          1 :         dt_free(dt_root);
     133                 :            : 
     134                 :          1 :         fake_pvr = (PVR_TYPE_P9P << 16) | 0x100; // P9P DD1.0
     135                 :          1 :         dt_root = dt_new_root("");
     136                 :          1 :         dt_add_cpufeatures(dt_root);
     137                 :          1 :         dump_dt(dt_root, 0, false);
     138                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/mmu-radix"));
     139                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-hypervisor-assist") != 0);
     140                 :          1 :         assert(dt_find_by_path(dt_root, "cpus/ibm,powerpc-cpu-features/tm-suspend-xer-so-bug") == 0);
     141                 :          1 :         dt_free(dt_root);
     142                 :            : 
     143                 :          1 :         exit(EXIT_SUCCESS);
     144                 :            : }

Generated by: LCOV version 1.14