LCOV - code coverage report
Current view: top level - spdk/test/unit/lib/blob/blob.c - ext_dev.c (source / functions) Hit Total Coverage
Test: Combined Lines: 33 33 100.0 %
Date: 2024-07-11 16:06:21 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 8 16 50.0 %

           Branch data     Line data    Source code
       1                 :            : /*   SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  *   Copyright (C) 2023 SUSE LLC.
       3                 :            :  *   All rights reserved.
       4                 :            :  */
       5                 :            : 
       6                 :            : #include "thread/thread_internal.h"
       7                 :            : #include "spdk/blob.h"
       8                 :            : 
       9                 :            : 
      10                 :            : #define EXT_DEV_BUFFER_SIZE (4 * 1024 * 1024)
      11                 :            : uint8_t g_ext_dev_buffer[EXT_DEV_BUFFER_SIZE];
      12                 :            : struct spdk_io_channel g_ext_io_channel;
      13                 :            : 
      14                 :            : static struct spdk_io_channel *
      15                 :        120 : ext_dev_create_channel(struct spdk_bs_dev *dev)
      16                 :            : {
      17                 :        120 :         return &g_ext_io_channel;
      18                 :            : }
      19                 :            : 
      20                 :            : static void
      21                 :        120 : ext_dev_destroy_channel(struct spdk_bs_dev *dev, struct spdk_io_channel *channel)
      22                 :            : {
      23                 :        120 : }
      24                 :            : 
      25                 :            : static void
      26                 :         96 : ext_dev_destroy(struct spdk_bs_dev *dev)
      27                 :            : {
      28                 :         96 :         free(dev);
      29                 :         96 : }
      30                 :            : 
      31                 :            : static void
      32                 :      24576 : ext_dev_read(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
      33                 :            :              uint64_t lba, uint32_t lba_count,
      34                 :            :              struct spdk_bs_dev_cb_args *cb_args)
      35                 :            : {
      36                 :            :         uint64_t offset, length;
      37                 :            : 
      38                 :      24576 :         offset = lba * dev->blocklen;
      39                 :      24576 :         length = lba_count * dev->blocklen;
      40         [ -  + ]:      24576 :         SPDK_CU_ASSERT_FATAL(offset + length <= EXT_DEV_BUFFER_SIZE);
      41                 :            : 
      42         [ +  - ]:      24576 :         if (length > 0) {
      43   [ -  +  -  + ]:      24576 :                 memcpy(payload, &g_ext_dev_buffer[offset], length);
      44                 :            :         }
      45                 :            : 
      46                 :      24576 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
      47                 :      24576 : }
      48                 :            : 
      49                 :            : static void
      50                 :      24624 : ext_dev_write(struct spdk_bs_dev *dev, struct spdk_io_channel *channel, void *payload,
      51                 :            :               uint64_t lba, uint32_t lba_count,
      52                 :            :               struct spdk_bs_dev_cb_args *cb_args)
      53                 :            : {
      54                 :            :         uint64_t offset, length;
      55                 :            : 
      56                 :      24624 :         offset = lba * dev->blocklen;
      57                 :      24624 :         length = lba_count * dev->blocklen;
      58         [ -  + ]:      24624 :         SPDK_CU_ASSERT_FATAL(offset + length <= EXT_DEV_BUFFER_SIZE);
      59                 :            : 
      60   [ -  +  -  + ]:      24624 :         memcpy(&g_ext_dev_buffer[offset], payload, length);
      61                 :            : 
      62                 :      24624 :         cb_args->cb_fn(cb_args->channel, cb_args->cb_arg, 0);
      63                 :      24624 : }
      64                 :            : 
      65                 :            : static struct spdk_bs_dev *
      66                 :         96 : init_ext_dev(uint64_t blockcnt, uint32_t blocklen)
      67                 :            : {
      68                 :         96 :         struct spdk_bs_dev *dev = calloc(1, sizeof(*dev));
      69                 :            : 
      70         [ -  + ]:         96 :         SPDK_CU_ASSERT_FATAL(dev != NULL);
      71                 :            : 
      72                 :         96 :         dev->create_channel = ext_dev_create_channel;
      73                 :         96 :         dev->destroy_channel = ext_dev_destroy_channel;
      74                 :         96 :         dev->destroy = ext_dev_destroy;
      75                 :         96 :         dev->read = ext_dev_read;
      76                 :         96 :         dev->write = ext_dev_write;
      77                 :         96 :         dev->blockcnt = blockcnt;
      78                 :         96 :         dev->blocklen = blocklen;
      79                 :            : 
      80                 :         96 :         return dev;
      81                 :            : }

Generated by: LCOV version 1.14