LCOV - code coverage report
Current view: top level - spdk/module/accel/error - accel_error_rpc.c (source / functions) Hit Total Coverage
Test: Combined Lines: 34 40 85.0 %
Date: 2024-07-15 09:31:40 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 14 24 58.3 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright (C) 2023 Intel Corporation. All rights reserved.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "accel_error.h"
       6                 :            : #include "spdk/accel.h"
       7                 :            : #include "spdk/rpc.h"
       8                 :            : #include "spdk/string.h"
       9                 :            : #include "spdk/util.h"
      10                 :            : 
      11                 :            : static int
      12                 :         24 : rpc_accel_error_decode_opcode(const struct spdk_json_val *val, void *out)
      13                 :            : {
      14                 :         24 :         enum spdk_accel_opcode *opcode = out;
      15                 :         24 :         char *opstr = NULL;
      16                 :            :         int i, rc;
      17                 :            : 
      18                 :         24 :         rc = spdk_json_decode_string(val, &opstr);
      19         [ -  + ]:         24 :         if (rc != 0) {
      20                 :          0 :                 return rc;
      21                 :            :         }
      22                 :            : 
      23                 :         24 :         rc = -EINVAL;
      24         [ +  - ]:        120 :         for (i = 0; i < SPDK_ACCEL_OPC_LAST; ++i) {
      25   [ -  +  -  +  :        120 :                 if (strcmp(spdk_accel_get_opcode_name((enum spdk_accel_opcode)i), opstr) == 0) {
                   +  + ]
      26                 :         24 :                         *opcode = (enum spdk_accel_opcode)i;
      27                 :         24 :                         rc = 0;
      28                 :         24 :                         break;
      29                 :            :                 }
      30                 :            :         }
      31                 :            : 
      32                 :         24 :         free(opstr);
      33                 :            : 
      34                 :         24 :         return rc;
      35                 :            : }
      36                 :            : 
      37                 :            : static int
      38                 :         24 : rpc_accel_error_decode_type(const struct spdk_json_val *val, void *out)
      39                 :            : {
      40                 :         24 :         enum accel_error_inject_type *type = out;
      41                 :         24 :         char *typestr = NULL;
      42                 :            :         int i, rc;
      43                 :            : 
      44                 :         24 :         rc = spdk_json_decode_string(val, &typestr);
      45         [ -  + ]:         24 :         if (rc != 0) {
      46                 :          0 :                 return rc;
      47                 :            :         }
      48                 :            : 
      49                 :         24 :         rc = -EINVAL;
      50         [ +  - ]:         36 :         for (i = 0; i < ACCEL_ERROR_INJECT_MAX; ++i) {
      51   [ -  +  -  +  :         36 :                 if (strcmp(accel_error_get_type_name(i), typestr) == 0) {
                   +  + ]
      52                 :         24 :                         *type = (enum accel_error_inject_type)i;
      53                 :         24 :                         rc = 0;
      54                 :         24 :                         break;
      55                 :            :                 }
      56                 :            :         }
      57                 :            : 
      58                 :         24 :         free(typestr);
      59                 :            : 
      60                 :         24 :         return rc;
      61                 :            : }
      62                 :            : 
      63                 :            : static const struct spdk_json_object_decoder rpc_accel_error_inject_error_decoders[] = {
      64                 :            :         {"opcode", offsetof(struct accel_error_inject_opts, opcode), rpc_accel_error_decode_opcode},
      65                 :            :         {"type", offsetof(struct accel_error_inject_opts, type), rpc_accel_error_decode_type},
      66                 :            :         {"count", offsetof(struct accel_error_inject_opts, count), spdk_json_decode_uint64, true},
      67                 :            :         {"interval", offsetof(struct accel_error_inject_opts, interval), spdk_json_decode_uint64, true},
      68                 :            :         {"errcode", offsetof(struct accel_error_inject_opts, errcode), spdk_json_decode_int32, true},
      69                 :            : };
      70                 :            : 
      71                 :            : static void
      72                 :         24 : rpc_accel_error_inject_error(struct spdk_jsonrpc_request *request,
      73                 :            :                              const struct spdk_json_val *params)
      74                 :            : {
      75                 :         24 :         struct accel_error_inject_opts opts = {.count = UINT64_MAX};
      76                 :            :         int rc;
      77                 :            : 
      78                 :         24 :         rc = spdk_json_decode_object(params, rpc_accel_error_inject_error_decoders,
      79                 :            :                                      SPDK_COUNTOF(rpc_accel_error_inject_error_decoders), &opts);
      80         [ -  + ]:         24 :         if (rc != 0) {
      81                 :          0 :                 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
      82                 :          0 :                 return;
      83                 :            :         }
      84                 :            : 
      85                 :         24 :         rc = accel_error_inject_error(&opts);
      86         [ -  + ]:         24 :         if (rc != 0) {
      87                 :          0 :                 spdk_jsonrpc_send_error_response(request, rc, spdk_strerror(-rc));
      88                 :          0 :                 return;
      89                 :            :         }
      90                 :            : 
      91                 :         24 :         spdk_jsonrpc_send_bool_response(request, true);
      92                 :            : }
      93                 :            : 
      94                 :       3022 : SPDK_RPC_REGISTER("accel_error_inject_error", rpc_accel_error_inject_error, SPDK_RPC_RUNTIME)

Generated by: LCOV version 1.14