LCOV - code coverage report
Current view: top level - core/test - run-mem_region_next.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 41 41 100.0 %
Date: 2024-01-02 21:04:04 Functions: 6 6 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-2018 IBM Corp.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <config.h>
       7                 :            : 
       8                 :            : #define BITS_PER_LONG (sizeof(long) * 8)
       9                 :            : 
      10                 :            : #include "dummy-cpu.h"
      11                 :            : 
      12                 :            : #include <stdlib.h>
      13                 :            : #include <string.h>
      14                 :            : 
      15                 :            : /* Use these before we override definitions below. */
      16                 :          1 : static void *real_malloc(size_t size)
      17                 :            : {
      18                 :          1 :         return malloc(size);
      19                 :            : }
      20                 :            : 
      21                 :          1 : static void real_free(void *p)
      22                 :            : {
      23                 :          1 :         return free(p);
      24                 :            : }
      25                 :            : 
      26                 :            : #undef malloc
      27                 :            : #undef free
      28                 :            : 
      29                 :            : #include <skiboot.h>
      30                 :            : 
      31                 :            : #define is_rodata(p) true
      32                 :            : 
      33                 :            : #include "../mem_region.c"
      34                 :            : #include "../malloc.c"
      35                 :            : #include "../device.c"
      36                 :            : 
      37                 :            : #include <assert.h>
      38                 :            : #include <stdio.h>
      39                 :            : 
      40                 :            : enum proc_chip_quirks proc_chip_quirks;
      41                 :            : 
      42                 :          3 : void lock_caller(struct lock *l, const char *caller)
      43                 :            : {
      44                 :            :         (void)caller;
      45                 :          3 :         assert(!l->lock_val);
      46                 :          3 :         l->lock_val++;
      47                 :          3 : }
      48                 :            : 
      49                 :          3 : void unlock(struct lock *l)
      50                 :            : {
      51                 :          3 :         assert(l->lock_val);
      52                 :          3 :         l->lock_val--;
      53                 :          3 : }
      54                 :            : 
      55                 :          6 : bool lock_held_by_me(struct lock *l)
      56                 :            : {
      57                 :          6 :         return l->lock_val;
      58                 :            : }
      59                 :            : 
      60                 :            : 
      61                 :            : #define TEST_HEAP_ORDER 16
      62                 :            : #define TEST_HEAP_SIZE (1ULL << TEST_HEAP_ORDER)
      63                 :            : 
      64                 :          1 : int main(void)
      65                 :            : {
      66                 :            :         struct mem_region *r;
      67                 :            :         char *test_heap;
      68                 :            : 
      69                 :            :         /* Use malloc for the heap, so valgrind can find issues. */
      70                 :          1 :         test_heap = real_malloc(TEST_HEAP_SIZE);
      71                 :          1 :         skiboot_heap.start = (unsigned long)test_heap;
      72                 :          1 :         skiboot_heap.len = TEST_HEAP_SIZE;
      73                 :            : 
      74                 :          1 :         lock(&mem_region_lock);
      75                 :            : 
      76                 :            :         /* empty regions */
      77                 :          1 :         r = mem_region_next(NULL);
      78                 :          1 :         assert(!r);
      79                 :            : 
      80                 :          1 :         r = new_region("test.1", 0x1000, 0x1000, NULL, REGION_RESERVED);
      81                 :          1 :         assert(add_region(r));
      82                 :          1 :         r = new_region("test.2", 0x2000, 0x1000, NULL, REGION_RESERVED);
      83                 :          1 :         assert(add_region(r));
      84                 :          1 :         mem_regions_finalised = true;
      85                 :            : 
      86                 :          1 :         r = mem_region_next(NULL);
      87                 :          1 :         assert(r);
      88                 :          1 :         assert(r->start == 0x1000);
      89                 :          1 :         assert(r->len == 0x1000);
      90                 :          1 :         assert(r->type == REGION_RESERVED);
      91                 :            : 
      92                 :          1 :         r = mem_region_next(r);
      93                 :          1 :         assert(r);
      94                 :          1 :         assert(r->start == 0x2000);
      95                 :          1 :         assert(r->len == 0x1000);
      96                 :          1 :         assert(r->type == REGION_RESERVED);
      97                 :            : 
      98                 :          1 :         r = mem_region_next(r);
      99                 :          1 :         assert(!r);
     100                 :            : 
     101                 :          1 :         unlock(&mem_region_lock);
     102                 :          1 :         real_free(test_heap);
     103                 :            : 
     104                 :          1 :         return 0;
     105                 :            : }

Generated by: LCOV version 1.14