LCOV - code coverage report
Current view: top level - core/test - run-malloc-speed.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 28 28 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 2013-2018 IBM Corp.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <config.h>
       7                 :            : 
       8                 :            : #define BITS_PER_LONG (sizeof(long) * 8)
       9                 :            : #include "dummy-cpu.h"
      10                 :            : 
      11                 :            : #include <stdlib.h>
      12                 :            : 
      13                 :            : /* Use these before we undefine them below. */
      14                 :          2 : static inline void *real_malloc(size_t size)
      15                 :            : {
      16                 :          2 :         return malloc(size);
      17                 :            : }
      18                 :            : 
      19                 :          1 : static inline void real_free(void *p)
      20                 :            : {
      21                 :          1 :         return free(p);
      22                 :            : }
      23                 :            : 
      24                 :            : #include <skiboot.h>
      25                 :            : 
      26                 :            : /* We need mem_region to accept __location__ */
      27                 :            : #define is_rodata(p) true
      28                 :            : #include "../malloc.c"
      29                 :            : #include "../mem_region.c"
      30                 :            : #include "../device.c"
      31                 :            : 
      32                 :            : #undef malloc
      33                 :            : #undef free
      34                 :            : #undef realloc
      35                 :            : 
      36                 :            : #include <assert.h>
      37                 :            : #include <stdio.h>
      38                 :            : 
      39                 :            : char __rodata_start[1], __rodata_end[1];
      40                 :            : struct dt_node *dt_root;
      41                 :            : enum proc_chip_quirks proc_chip_quirks;
      42                 :            : 
      43                 :       4096 : void lock_caller(struct lock *l, const char *caller)
      44                 :            : {
      45                 :            :         (void)caller;
      46                 :       4096 :         assert(!l->lock_val);
      47                 :       4096 :         l->lock_val = 1;
      48                 :       4096 : }
      49                 :            : 
      50                 :       4096 : void unlock(struct lock *l)
      51                 :            : {
      52                 :       4096 :         assert(l->lock_val);
      53                 :       4096 :         l->lock_val = 0;
      54                 :       4096 : }
      55                 :            : 
      56                 :       4096 : bool lock_held_by_me(struct lock *l)
      57                 :            : {
      58                 :       4096 :         return l->lock_val;
      59                 :            : }
      60                 :            : 
      61                 :            : #define TEST_HEAP_ORDER 27
      62                 :            : #define TEST_HEAP_SIZE (1ULL << TEST_HEAP_ORDER)
      63                 :            : 
      64                 :            : #define NUM_ALLOCS 4096
      65                 :            : 
      66                 :          1 : int main(void)
      67                 :            : {
      68                 :            :         uint64_t i, len;
      69                 :          1 :         void **p = real_malloc(sizeof(void*)*NUM_ALLOCS);
      70                 :            : 
      71                 :          1 :         assert(p);
      72                 :            : 
      73                 :            :         /* Use malloc for the heap, so valgrind can find issues. */
      74                 :          1 :         skiboot_heap.start = (unsigned long)real_malloc(skiboot_heap.len);
      75                 :            : 
      76                 :          1 :         len = skiboot_heap.len / NUM_ALLOCS - sizeof(struct alloc_hdr);
      77                 :       4097 :         for (i = 0; i < NUM_ALLOCS; i++) {
      78                 :       4096 :                 p[i] = __malloc(len, __location__);
      79                 :       4096 :                 assert(p[i] > region_start(&skiboot_heap));
      80                 :       4096 :                 assert(p[i] + len <= region_start(&skiboot_heap)
      81                 :            :                        + skiboot_heap.len);
      82                 :            :         }
      83                 :          1 :         assert(mem_check(&skiboot_heap));
      84                 :          1 :         assert(skiboot_heap.free_list_lock.lock_val == 0);
      85                 :          1 :         free(region_start(&skiboot_heap));
      86                 :          1 :         real_free(p);
      87                 :          1 :         return 0;
      88                 :            : }

Generated by: LCOV version 1.14