From 82d7226c8ec0d71b1a13dd8ede4baa91c0647b88 Mon Sep 17 00:00:00 2001 From: paul luse Date: Mon, 8 Feb 2021 17:56:19 -0500 Subject: [PATCH] test/accel: add first UT for accel framework Implementation is pretty solid now, add first test with many more to follow. Signed-off-by: paul luse Change-Id: I4b80f3108fcd07919949bcd14dadfdfeb10c45fd Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/6332 Community-CI: Broadcom CI Community-CI: Mellanox Build Bot Tested-by: SPDK CI Jenkins Reviewed-by: Jim Harris Reviewed-by: Shuhei Matsumoto --- test/unit/lib/Makefile | 2 +- test/unit/lib/accel/Makefile | 44 +++++++++++ test/unit/lib/accel/accel.c/.gitignore | 1 + test/unit/lib/accel/accel.c/Makefile | 38 ++++++++++ test/unit/lib/accel/accel.c/accel_engine_ut.c | 76 +++++++++++++++++++ test/unit/unittest.sh | 1 + 6 files changed, 161 insertions(+), 1 deletion(-) create mode 100644 test/unit/lib/accel/Makefile create mode 100644 test/unit/lib/accel/accel.c/.gitignore create mode 100644 test/unit/lib/accel/accel.c/Makefile create mode 100644 test/unit/lib/accel/accel.c/accel_engine_ut.c diff --git a/test/unit/lib/Makefile b/test/unit/lib/Makefile index aa2d707ab..8af7e4cc8 100644 --- a/test/unit/lib/Makefile +++ b/test/unit/lib/Makefile @@ -34,7 +34,7 @@ SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../..) include $(SPDK_ROOT_DIR)/mk/spdk.common.mk -DIRS-y = bdev blob blobfs event ioat iscsi json jsonrpc log lvol +DIRS-y = accel bdev blob blobfs event ioat iscsi json jsonrpc log lvol DIRS-y += notify nvme nvmf scsi sock thread util DIRS-$(CONFIG_IDXD) += idxd DIRS-$(CONFIG_REDUCE) += reduce diff --git a/test/unit/lib/accel/Makefile b/test/unit/lib/accel/Makefile new file mode 100644 index 000000000..acbb6dc61 --- /dev/null +++ b/test/unit/lib/accel/Makefile @@ -0,0 +1,44 @@ +# +# BSD LICENSE +# +# Copyright (c) Intel Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../..) +include $(SPDK_ROOT_DIR)/mk/spdk.common.mk + +DIRS-y = accel.c + +.PHONY: all clean $(DIRS-y) + +all: $(DIRS-y) +clean: $(DIRS-y) + +include $(SPDK_ROOT_DIR)/mk/spdk.subdirs.mk diff --git a/test/unit/lib/accel/accel.c/.gitignore b/test/unit/lib/accel/accel.c/.gitignore new file mode 100644 index 000000000..170ea0f4e --- /dev/null +++ b/test/unit/lib/accel/accel.c/.gitignore @@ -0,0 +1 @@ +accel_engine_ut diff --git a/test/unit/lib/accel/accel.c/Makefile b/test/unit/lib/accel/accel.c/Makefile new file mode 100644 index 000000000..183eccb82 --- /dev/null +++ b/test/unit/lib/accel/accel.c/Makefile @@ -0,0 +1,38 @@ +# +# BSD LICENSE +# +# Copyright (c) Intel Corporation. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in +# the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Intel Corporation nor the names of its +# contributors may be used to endorse or promote products derived +# from this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +SPDK_ROOT_DIR := $(abspath $(CURDIR)/../../../../..) + +TEST_FILE = accel_engine_ut.c + +include $(SPDK_ROOT_DIR)/mk/spdk.unittest.mk diff --git a/test/unit/lib/accel/accel.c/accel_engine_ut.c b/test/unit/lib/accel/accel.c/accel_engine_ut.c new file mode 100644 index 000000000..a441480b0 --- /dev/null +++ b/test/unit/lib/accel/accel.c/accel_engine_ut.c @@ -0,0 +1,76 @@ +/*- + * BSD LICENSE + * + * Copyright (c) Intel Corporation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "spdk_cunit.h" +#include "spdk_internal/mock.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); + +static void +test_spdk_accel_hw_engine_register(void) +{ + struct spdk_accel_engine accel_engine; + + /* Run once with no engine assigned, assign it. */ + g_hw_accel_engine = NULL; + spdk_accel_hw_engine_register(&accel_engine); + CU_ASSERT(g_hw_accel_engine == &accel_engine); + + /* Run with one assigned, should not change. */ + spdk_accel_hw_engine_register(&accel_engine); + CU_ASSERT(g_hw_accel_engine == &accel_engine); +} + +int main(int argc, char **argv) +{ + CU_pSuite suite = NULL; + unsigned int num_failures; + + CU_set_error_action(CUEA_ABORT); + CU_initialize_registry(); + + suite = CU_add_suite("accel", NULL, NULL); + + CU_ADD_TEST(suite, test_spdk_accel_hw_engine_register); + + CU_basic_set_mode(CU_BRM_VERBOSE); + CU_basic_run_tests(); + num_failures = CU_get_number_of_failures(); + CU_cleanup_registry(); + + return num_failures; +} diff --git a/test/unit/unittest.sh b/test/unit/unittest.sh index 04cb09f16..46bc4db1a 100755 --- a/test/unit/unittest.sh +++ b/test/unit/unittest.sh @@ -193,6 +193,7 @@ if [ $(uname -s) = Linux ]; then run_test "unittest_ftl" unittest_ftl fi +run_test "unittest_accel" $valgrind $testdir/lib/accel/accel.c/accel_engine_ut run_test "unittest_ioat" $valgrind $testdir/lib/ioat/ioat.c/ioat_ut if grep -q '#define SPDK_CONFIG_IDXD 1' $rootdir/include/spdk/config.h; then run_test "unittest_idxd" $valgrind $testdir/lib/idxd/idxd.c/idxd_ut