LCOV - code coverage report
Current view: top level - core/test - run-pool.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 2014 IBM Corp
       4                 :            :  */
       5                 :            : 
       6                 :            : #include <pool.h>
       7                 :            : 
       8                 :            : #include "../pool.c"
       9                 :            : 
      10                 :            : #define POOL_OBJ_COUNT 10
      11                 :            : #define POOL_RESERVED_COUNT 2
      12                 :            : #define POOL_NORMAL_COUNT (POOL_OBJ_COUNT - POOL_RESERVED_COUNT)
      13                 :            : 
      14                 :            : struct test_object
      15                 :            : {
      16                 :            :         int a;
      17                 :            :         int b;
      18                 :            :         int c;
      19                 :            : };
      20                 :            : 
      21                 :          1 : int main(void)
      22                 :            : {
      23                 :          1 :         int i, count = 0;
      24                 :            :         struct pool pool;
      25                 :            :         struct test_object *a[POOL_OBJ_COUNT];
      26                 :            : 
      27                 :          1 :         assert(!pool_init(&pool, sizeof(struct test_object), POOL_OBJ_COUNT,
      28                 :            :                       POOL_RESERVED_COUNT));
      29                 :            : 
      30                 :          1 :         a[0] = pool_get(&pool, POOL_NORMAL);
      31                 :          1 :         assert(a[0]);
      32                 :          1 :         pool_free_object(&pool, a[0]);
      33                 :            : 
      34                 :          9 :         for(i = 0; i < POOL_NORMAL_COUNT; i++)
      35                 :            :         {
      36                 :          8 :                 a[i] = pool_get(&pool, POOL_NORMAL);
      37                 :          8 :                 if (a[i])
      38                 :          8 :                         count++;
      39                 :            :         }
      40                 :          1 :         assert(count == POOL_NORMAL_COUNT);
      41                 :            : 
      42                 :            :         /* Normal pool should be exhausted */
      43                 :          1 :         assert(!pool_get(&pool, POOL_NORMAL));
      44                 :            : 
      45                 :            :         /* Reserved pool should still be available */
      46                 :          1 :         a[POOL_NORMAL_COUNT] = pool_get(&pool, POOL_HIGH);
      47                 :          1 :         assert(a[POOL_NORMAL_COUNT]);
      48                 :          1 :         a[POOL_NORMAL_COUNT + 1] = pool_get(&pool, POOL_HIGH);
      49                 :          1 :         assert(a[POOL_NORMAL_COUNT + 1]);
      50                 :            : 
      51                 :          1 :         pool_free_object(&pool, a[3]);
      52                 :            : 
      53                 :            :         /* Should be a free object to get now */
      54                 :          1 :         a[3] = pool_get(&pool, POOL_HIGH);
      55                 :          1 :         assert(a[3]);
      56                 :            : 
      57                 :            :         /* This exits depending on whether all tests passed */
      58                 :          1 :         return 0;
      59                 :            : }

Generated by: LCOV version 1.14