From cc797456f44e6efd9f76f7f08e54d345fc8b64d7 Mon Sep 17 00:00:00 2001 From: Shuhei Matsumoto Date: Wed, 26 Jan 2022 10:29:39 +0900 Subject: [PATCH] ut: Use unit/lib/json_mock.c for stubs Signed-off-by: Shuhei Matsumoto Change-Id: I2cd488c17dbc92c381cd956ae0d6f5ca709a24dc Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/11263 Tested-by: SPDK CI Jenkins Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Reviewed-by: Aleksey Marchuk Reviewed-by: Tomasz Zawadzki --- test/unit/lib/accel/accel.c/accel_engine_ut.c | 5 ++-- test/unit/lib/iscsi/conn.c/conn_ut.c | 9 ++---- test/unit/lib/rpc/rpc.c/rpc_ut.c | 14 ++------- test/unit/lib/sock/sock.c/sock_ut.c | 30 ++----------------- 4 files changed, 11 insertions(+), 47 deletions(-) diff --git a/test/unit/lib/accel/accel.c/accel_engine_ut.c b/test/unit/lib/accel/accel.c/accel_engine_ut.c index 043693dd5..5cabba712 100644 --- a/test/unit/lib/accel/accel.c/accel_engine_ut.c +++ b/test/unit/lib/accel/accel.c/accel_engine_ut.c @@ -3,6 +3,7 @@ * * Copyright (c) Intel Corporation. * All rights reserved. + * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -36,9 +37,7 @@ #include "thread/thread_internal.h" #include "common/lib/test_env.c" #include "accel/accel_engine.c" - -DEFINE_STUB(spdk_json_write_array_begin, int, (struct spdk_json_write_ctx *w), 0); -DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0); +#include "unit/lib/json_mock.c" /* global vars and setup/cleanup functions used for all test functions */ struct spdk_accel_engine g_accel_engine = {}; diff --git a/test/unit/lib/iscsi/conn.c/conn_ut.c b/test/unit/lib/iscsi/conn.c/conn_ut.c index ade9a2533..e1846a8f7 100644 --- a/test/unit/lib/iscsi/conn.c/conn_ut.c +++ b/test/unit/lib/iscsi/conn.c/conn_ut.c @@ -3,6 +3,7 @@ * * Copyright (c) Intel Corporation. * All rights reserved. + * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,6 +41,8 @@ #include "spdk_internal/mock.h" +#include "unit/lib/json_mock.c" + SPDK_LOG_REGISTER_COMPONENT(iscsi) DEFINE_STUB(iscsi_get_pdu, struct spdk_iscsi_pdu *, @@ -47,12 +50,6 @@ DEFINE_STUB(iscsi_get_pdu, struct spdk_iscsi_pdu *, DEFINE_STUB(iscsi_param_eq_val, int, (struct iscsi_param *params, const char *key, const char *val), 0); DEFINE_STUB(iscsi_pdu_calc_data_digest, uint32_t, (struct spdk_iscsi_pdu *pdu), 0); -DEFINE_STUB(spdk_json_write_object_begin, int, (struct spdk_json_write_ctx *w), 0); -DEFINE_STUB(spdk_json_write_named_int32, int, (struct spdk_json_write_ctx *w, - const char *name, int32_t val), 0); -DEFINE_STUB(spdk_json_write_named_string, int, (struct spdk_json_write_ctx *w, - const char *name, const char *val), 0); -DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0); DEFINE_STUB_V(spdk_sock_writev_async, (struct spdk_sock *sock, struct spdk_sock_request *req)); diff --git a/test/unit/lib/rpc/rpc.c/rpc_ut.c b/test/unit/lib/rpc/rpc.c/rpc_ut.c index 70fab84b2..c31f51a2d 100644 --- a/test/unit/lib/rpc/rpc.c/rpc_ut.c +++ b/test/unit/lib/rpc/rpc.c/rpc_ut.c @@ -3,6 +3,7 @@ * * Copyright (c) Intel Corporation. * All rights reserved. + * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -40,23 +41,14 @@ #include "rpc/rpc.c" +#include "unit/lib/json_mock.c" + static int g_rpc_err; void fn_rpc_method_handler(struct spdk_jsonrpc_request *request, const struct spdk_json_val *params); DEFINE_STUB_V(spdk_jsonrpc_end_result, (struct spdk_jsonrpc_request *request, struct spdk_json_write_ctx *w)); -DEFINE_STUB(spdk_json_write_array_begin, int, (struct spdk_json_write_ctx *w), 0); -DEFINE_STUB(spdk_json_write_string, int, (struct spdk_json_write_ctx *w, const char *val), 0); -DEFINE_STUB(spdk_json_write_object_begin, int, (struct spdk_json_write_ctx *w), 0); -DEFINE_STUB(spdk_json_write_named_string_fmt, int, (struct spdk_json_write_ctx *w, const char *name, - const char *fmt, ...), 0); -DEFINE_STUB(spdk_json_write_named_object_begin, int, (struct spdk_json_write_ctx *w, - const char *name), 0); -DEFINE_STUB(spdk_json_write_named_uint32, int, (struct spdk_json_write_ctx *w, const char *name, - uint32_t val), 0); -DEFINE_STUB(spdk_json_write_object_end, int, (struct spdk_json_write_ctx *w), 0); -DEFINE_STUB(spdk_json_write_array_end, int, (struct spdk_json_write_ctx *w), 0); DEFINE_STUB(spdk_jsonrpc_begin_result, struct spdk_json_write_ctx *, (struct spdk_jsonrpc_request *request), (void *)1); DEFINE_STUB(spdk_json_decode_bool, int, (const struct spdk_json_val *val, void *out), 0); diff --git a/test/unit/lib/sock/sock.c/sock_ut.c b/test/unit/lib/sock/sock.c/sock_ut.c index b023f6379..3b913388a 100644 --- a/test/unit/lib/sock/sock.c/sock_ut.c +++ b/test/unit/lib/sock/sock.c/sock_ut.c @@ -3,6 +3,7 @@ * * Copyright (c) Intel Corporation. All rights reserved. * Copyright (c) 2020 Mellanox Technologies LTD. All rights reserved. + * Copyright (c) 2022 NVIDIA CORPORATION & AFFILIATES. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -44,6 +45,8 @@ #include "spdk_internal/mock.h" #include "common/lib/test_env.c" +#include "unit/lib/json_mock.c" + #define UT_IP "test_ip" #define UT_PORT 1234 @@ -70,33 +73,6 @@ struct spdk_ut_sock_group_impl { #define __ut_sock(sock) (struct spdk_ut_sock *)sock #define __ut_group(group) (struct spdk_ut_sock_group_impl *)group -DEFINE_STUB(spdk_json_write_array_begin, int, - (struct spdk_json_write_ctx *w), 0); - -DEFINE_STUB(spdk_json_write_object_begin, int, - (struct spdk_json_write_ctx *w), 0); - -DEFINE_STUB(spdk_json_write_named_string, int, - (struct spdk_json_write_ctx *w, const char *name, - const char *val), 0); - -DEFINE_STUB(spdk_json_write_named_object_begin, int, - (struct spdk_json_write_ctx *w, const char *name), 0); - -DEFINE_STUB(spdk_json_write_named_uint32, int, - (struct spdk_json_write_ctx *w, const char *name, uint32_t val), - 0); - -DEFINE_STUB(spdk_json_write_named_bool, int, - (struct spdk_json_write_ctx *w, const char *name, bool val), - 0); - -DEFINE_STUB(spdk_json_write_object_end, int, - (struct spdk_json_write_ctx *w), 0); - -DEFINE_STUB(spdk_json_write_array_end, int, - (struct spdk_json_write_ctx *w), 0); - static int spdk_ut_sock_getaddr(struct spdk_sock *_sock, char *saddr, int slen, uint16_t *sport, char *caddr, int clen, uint16_t *cport)