!474 sync from openEuler
From: @jingwoo Reviewed-by: @duguhaotian Signed-off-by: @duguhaotian
This commit is contained in:
commit
6adb935185
@ -1,7 +1,7 @@
|
|||||||
From f9cb1b86511fac1c3a7f11fdaa4c9c20dc889068 Mon Sep 17 00:00:00 2001
|
From f9cb1b86511fac1c3a7f11fdaa4c9c20dc889068 Mon Sep 17 00:00:00 2001
|
||||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
Date: Sun, 9 Oct 2022 19:00:38 +0800
|
Date: Sun, 9 Oct 2022 19:00:38 +0800
|
||||||
Subject: [PATCH] use epoll instead of select for wait_exit_fifo
|
Subject: [PATCH 01/35] use epoll instead of select for wait_exit_fifo
|
||||||
|
|
||||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
---
|
---
|
||||||
@ -154,5 +154,5 @@ index b9099a74..5124b33a 100644
|
|||||||
|
|
||||||
#define EPOLL_LOOP_HANDLE_CONTINUE 0
|
#define EPOLL_LOOP_HANDLE_CONTINUE 0
|
||||||
--
|
--
|
||||||
2.25.1
|
2.37.3
|
||||||
|
|
||||||
|
|||||||
155
0002-add-namespace-util-UT.patch
Normal file
155
0002-add-namespace-util-UT.patch
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
From 864a500f18d56aebeaa71960f10791386212b18b Mon Sep 17 00:00:00 2001
|
||||||
|
From: haozi007 <liuhao27@huawei.com>
|
||||||
|
Date: Thu, 13 Oct 2022 15:55:08 +0800
|
||||||
|
Subject: [PATCH 02/35] add namespace util UT
|
||||||
|
|
||||||
|
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||||
|
---
|
||||||
|
test/cutils/CMakeLists.txt | 15 ++++
|
||||||
|
test/cutils/utils_namespace/CMakeLists.txt | 16 ++++
|
||||||
|
.../utils_namespace/utils_namespace_ut.cc | 82 +++++++++++++++++++
|
||||||
|
3 files changed, 113 insertions(+)
|
||||||
|
create mode 100644 test/cutils/utils_namespace/CMakeLists.txt
|
||||||
|
create mode 100644 test/cutils/utils_namespace/utils_namespace_ut.cc
|
||||||
|
|
||||||
|
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||||
|
index b549f844..31408f18 100644
|
||||||
|
--- a/test/cutils/CMakeLists.txt
|
||||||
|
+++ b/test/cutils/CMakeLists.txt
|
||||||
|
@@ -1,7 +1,22 @@
|
||||||
|
project(iSulad_UT)
|
||||||
|
|
||||||
|
+aux_source_directory(${CMAKE_SOURCE_DIR}/src/utils/cutils local_cutils_srcs)
|
||||||
|
+aux_source_directory(${CMAKE_SOURCE_DIR}/src/utils/cutils/map local_cutils_map_srcs)
|
||||||
|
+
|
||||||
|
+add_library(libutils_ut STATIC
|
||||||
|
+ ${local_cutils_srcs}
|
||||||
|
+ ${local_cutils_map_srcs}
|
||||||
|
+ )
|
||||||
|
+set_target_properties(libutils_ut PROPERTIES PREFIX "")
|
||||||
|
+target_include_directories(libutils_ut
|
||||||
|
+ PUBLIC ${CMAKE_SOURCE_DIR}/src/common
|
||||||
|
+ PUBLIC ${CMAKE_SOURCE_DIR}/src/utils/cutils
|
||||||
|
+ PUBLIC ${CMAKE_SOURCE_DIR}/src/utils/cutils/map
|
||||||
|
+)
|
||||||
|
+
|
||||||
|
add_subdirectory(utils_string)
|
||||||
|
add_subdirectory(utils_convert)
|
||||||
|
add_subdirectory(utils_array)
|
||||||
|
add_subdirectory(utils_base64)
|
||||||
|
add_subdirectory(utils_pwgr)
|
||||||
|
+add_subdirectory(utils_namespace)
|
||||||
|
diff --git a/test/cutils/utils_namespace/CMakeLists.txt b/test/cutils/utils_namespace/CMakeLists.txt
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..8add4a71
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/cutils/utils_namespace/CMakeLists.txt
|
||||||
|
@@ -0,0 +1,16 @@
|
||||||
|
+project(iSulad_UT)
|
||||||
|
+
|
||||||
|
+SET(EXE utils_namespace_ut)
|
||||||
|
+
|
||||||
|
+add_executable(${EXE}
|
||||||
|
+ utils_namespace_ut.cc)
|
||||||
|
+
|
||||||
|
+target_include_directories(${EXE} PUBLIC
|
||||||
|
+ ${GTEST_INCLUDE_DIR}
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
+ )
|
||||||
|
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
diff --git a/test/cutils/utils_namespace/utils_namespace_ut.cc b/test/cutils/utils_namespace/utils_namespace_ut.cc
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..da50d503
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/cutils/utils_namespace/utils_namespace_ut.cc
|
||||||
|
@@ -0,0 +1,82 @@
|
||||||
|
+/******************************************************************************
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
|
||||||
|
+ * iSulad licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Author: hejunjie
|
||||||
|
+ * Create: 2022-04-08
|
||||||
|
+ * Description: utils_pwgr unit test
|
||||||
|
+ *******************************************************************************/
|
||||||
|
+
|
||||||
|
+#include <gtest/gtest.h>
|
||||||
|
+#include "namespace.h"
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_is_host)
|
||||||
|
+{
|
||||||
|
+ ASSERT_EQ(namespace_is_host(SHARE_NAMESPACE_HOST), true);
|
||||||
|
+ ASSERT_EQ(namespace_is_host(SHARE_NAMESPACE_NONE), false);
|
||||||
|
+ ASSERT_EQ(namespace_is_host(nullptr), false);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_is_none)
|
||||||
|
+{
|
||||||
|
+ ASSERT_EQ(namespace_is_none(SHARE_NAMESPACE_HOST), false);
|
||||||
|
+ ASSERT_EQ(namespace_is_none(SHARE_NAMESPACE_NONE), true);
|
||||||
|
+ ASSERT_EQ(namespace_is_none(nullptr), false);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_is_container)
|
||||||
|
+{
|
||||||
|
+ std::string con = "container:test";
|
||||||
|
+ ASSERT_EQ(namespace_is_container(SHARE_NAMESPACE_HOST), false);
|
||||||
|
+ ASSERT_EQ(namespace_is_container(con.c_str()), true);
|
||||||
|
+ ASSERT_EQ(namespace_is_container(nullptr), false);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_is_bridge)
|
||||||
|
+{
|
||||||
|
+ ASSERT_EQ(namespace_is_bridge(SHARE_NAMESPACE_HOST), false);
|
||||||
|
+ ASSERT_EQ(namespace_is_bridge(SHARE_NAMESPACE_BRIDGE), true);
|
||||||
|
+ ASSERT_EQ(namespace_is_bridge(nullptr), false);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_is_file)
|
||||||
|
+{
|
||||||
|
+ ASSERT_EQ(namespace_is_file(SHARE_NAMESPACE_HOST), false);
|
||||||
|
+ ASSERT_EQ(namespace_is_file(SHARE_NAMESPACE_FILE), true);
|
||||||
|
+ ASSERT_EQ(namespace_is_file(nullptr), false);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_is_shareable)
|
||||||
|
+{
|
||||||
|
+ ASSERT_EQ(namespace_is_shareable(SHARE_NAMESPACE_HOST), false);
|
||||||
|
+ ASSERT_EQ(namespace_is_shareable(SHARE_NAMESPACE_SHAREABLE), true);
|
||||||
|
+ ASSERT_EQ(namespace_is_shareable(nullptr), false);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_get_connected_container)
|
||||||
|
+{
|
||||||
|
+ std::string con = "container:test";
|
||||||
|
+ char *ret = nullptr;
|
||||||
|
+ ret = namespace_get_connected_container(con.c_str());
|
||||||
|
+ ASSERT_STREQ(ret, "test");
|
||||||
|
+ ASSERT_EQ(namespace_get_connected_container(SHARE_NAMESPACE_SHAREABLE), nullptr);
|
||||||
|
+ ASSERT_EQ(namespace_get_connected_container(nullptr), nullptr);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+TEST(utils_namespace, test_namespace_get_host_namespace_path)
|
||||||
|
+{
|
||||||
|
+ ASSERT_EQ(namespace_get_host_namespace_path(nullptr), nullptr);
|
||||||
|
+ ASSERT_STREQ(namespace_get_host_namespace_path(TYPE_NAMESPACE_PID), SHARE_NAMESPACE_PID_HOST_PATH);
|
||||||
|
+ ASSERT_STREQ(namespace_get_host_namespace_path(TYPE_NAMESPACE_NETWORK), SHARE_NAMESPACE_NET_HOST_PATH);
|
||||||
|
+ ASSERT_STREQ(namespace_get_host_namespace_path(TYPE_NAMESPACE_IPC), SHARE_NAMESPACE_IPC_HOST_PATH);
|
||||||
|
+ ASSERT_STREQ(namespace_get_host_namespace_path(TYPE_NAMESPACE_UTS), SHARE_NAMESPACE_UTS_HOST_PATH);
|
||||||
|
+ ASSERT_STREQ(namespace_get_host_namespace_path(TYPE_NAMESPACE_MOUNT), SHARE_NAMESPACE_MNT_HOST_PATH);
|
||||||
|
+ ASSERT_STREQ(namespace_get_host_namespace_path(TYPE_NAMESPACE_USER), SHARE_NAMESPACE_USER_HOST_PATH);
|
||||||
|
+ ASSERT_STREQ(namespace_get_host_namespace_path(TYPE_NAMESPACE_CGROUP), SHARE_NAMESPACE_CGROUP_HOST_PATH);
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
|
--
|
||||||
|
2.37.3
|
||||||
|
|
||||||
182
0003-refactor-build-system-of-cutils-ut.patch
Normal file
182
0003-refactor-build-system-of-cutils-ut.patch
Normal file
@ -0,0 +1,182 @@
|
|||||||
|
From d1061efc9a83df659f5aeab57352b9247380217a Mon Sep 17 00:00:00 2001
|
||||||
|
From: haozi007 <liuhao27@huawei.com>
|
||||||
|
Date: Thu, 13 Oct 2022 16:56:10 +0800
|
||||||
|
Subject: [PATCH 03/35] refactor build system of cutils ut
|
||||||
|
|
||||||
|
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||||
|
---
|
||||||
|
test/cutils/utils_array/CMakeLists.txt | 13 +------------
|
||||||
|
test/cutils/utils_base64/CMakeLists.txt | 14 +-------------
|
||||||
|
test/cutils/utils_convert/CMakeLists.txt | 13 +------------
|
||||||
|
test/cutils/utils_namespace/utils_namespace_ut.cc | 6 +++---
|
||||||
|
test/cutils/utils_pwgr/CMakeLists.txt | 14 +-------------
|
||||||
|
test/cutils/utils_string/CMakeLists.txt | 13 +------------
|
||||||
|
6 files changed, 8 insertions(+), 65 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/test/cutils/utils_array/CMakeLists.txt b/test/cutils/utils_array/CMakeLists.txt
|
||||||
|
index 427e588d..71733e31 100644
|
||||||
|
--- a/test/cutils/utils_array/CMakeLists.txt
|
||||||
|
+++ b/test/cutils/utils_array/CMakeLists.txt
|
||||||
|
@@ -3,17 +3,6 @@ project(iSulad_UT)
|
||||||
|
SET(EXE utils_array_ut)
|
||||||
|
|
||||||
|
add_executable(${EXE}
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_string.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_array.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_convert.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_verify.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_regex.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/rb_tree.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
|
||||||
|
utils_array_ut.cc)
|
||||||
|
|
||||||
|
target_include_directories(${EXE} PUBLIC
|
||||||
|
@@ -25,5 +14,5 @@ target_include_directories(${EXE} PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
)
|
||||||
|
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,calloc")
|
||||||
|
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
|
||||||
|
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
diff --git a/test/cutils/utils_base64/CMakeLists.txt b/test/cutils/utils_base64/CMakeLists.txt
|
||||||
|
index 3c7b72dc..d5b99361 100644
|
||||||
|
--- a/test/cutils/utils_base64/CMakeLists.txt
|
||||||
|
+++ b/test/cutils/utils_base64/CMakeLists.txt
|
||||||
|
@@ -3,18 +3,6 @@ project(iSulad_UT)
|
||||||
|
SET(EXE utils_base64_ut)
|
||||||
|
|
||||||
|
add_executable(${EXE}
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_base64.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_array.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_string.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_convert.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_verify.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_regex.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/rb_tree.c
|
||||||
|
utils_base64_ut.cc)
|
||||||
|
|
||||||
|
target_include_directories(${EXE} PUBLIC
|
||||||
|
@@ -25,5 +13,5 @@ target_include_directories(${EXE} PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
)
|
||||||
|
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
|
||||||
|
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
diff --git a/test/cutils/utils_convert/CMakeLists.txt b/test/cutils/utils_convert/CMakeLists.txt
|
||||||
|
index 809a798e..30068208 100644
|
||||||
|
--- a/test/cutils/utils_convert/CMakeLists.txt
|
||||||
|
+++ b/test/cutils/utils_convert/CMakeLists.txt
|
||||||
|
@@ -3,17 +3,6 @@ project(iSulad_UT)
|
||||||
|
SET(EXE utils_convert_ut)
|
||||||
|
|
||||||
|
add_executable(${EXE}
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_string.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_array.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_convert.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_verify.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_regex.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/rb_tree.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
|
||||||
|
utils_convert_ut.cc)
|
||||||
|
|
||||||
|
target_include_directories(${EXE} PUBLIC
|
||||||
|
@@ -24,5 +13,5 @@ target_include_directories(${EXE} PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
)
|
||||||
|
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
|
||||||
|
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
diff --git a/test/cutils/utils_namespace/utils_namespace_ut.cc b/test/cutils/utils_namespace/utils_namespace_ut.cc
|
||||||
|
index da50d503..1c652e9f 100644
|
||||||
|
--- a/test/cutils/utils_namespace/utils_namespace_ut.cc
|
||||||
|
+++ b/test/cutils/utils_namespace/utils_namespace_ut.cc
|
||||||
|
@@ -8,9 +8,9 @@
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
* PURPOSE.
|
||||||
|
* See the Mulan PSL v2 for more details.
|
||||||
|
- * Author: hejunjie
|
||||||
|
- * Create: 2022-04-08
|
||||||
|
- * Description: utils_pwgr unit test
|
||||||
|
+ * Author: haozi007
|
||||||
|
+ * Create: 2022-10-13
|
||||||
|
+ * Description: utils namespace unit test
|
||||||
|
*******************************************************************************/
|
||||||
|
|
||||||
|
#include <gtest/gtest.h>
|
||||||
|
diff --git a/test/cutils/utils_pwgr/CMakeLists.txt b/test/cutils/utils_pwgr/CMakeLists.txt
|
||||||
|
index 548718da..5938991e 100644
|
||||||
|
--- a/test/cutils/utils_pwgr/CMakeLists.txt
|
||||||
|
+++ b/test/cutils/utils_pwgr/CMakeLists.txt
|
||||||
|
@@ -3,18 +3,6 @@ project(iSulad_UT)
|
||||||
|
SET(EXE utils_pwgr_ut)
|
||||||
|
|
||||||
|
add_executable(${EXE}
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_string.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_array.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_convert.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_verify.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_regex.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_pwgr.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/rb_tree.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
|
||||||
|
utils_pwgr_ut.cc)
|
||||||
|
|
||||||
|
target_include_directories(${EXE} PUBLIC
|
||||||
|
@@ -25,5 +13,5 @@ target_include_directories(${EXE} PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
)
|
||||||
|
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
|
||||||
|
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
diff --git a/test/cutils/utils_string/CMakeLists.txt b/test/cutils/utils_string/CMakeLists.txt
|
||||||
|
index c86141ef..1343f4e6 100644
|
||||||
|
--- a/test/cutils/utils_string/CMakeLists.txt
|
||||||
|
+++ b/test/cutils/utils_string/CMakeLists.txt
|
||||||
|
@@ -3,17 +3,6 @@ project(iSulad_UT)
|
||||||
|
SET(EXE utils_string_ut)
|
||||||
|
|
||||||
|
add_executable(${EXE}
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_string.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_array.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_file.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_convert.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_verify.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/utils_regex.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256/sha256.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/path.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/map.c
|
||||||
|
- ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map/rb_tree.c
|
||||||
|
utils_string_ut.cc)
|
||||||
|
|
||||||
|
target_include_directories(${EXE} PUBLIC
|
||||||
|
@@ -25,5 +14,5 @@ target_include_directories(${EXE} PUBLIC
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
)
|
||||||
|
set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,util_strdup_s -Wl,--wrap,calloc -Wl,--wrap,strcat_s")
|
||||||
|
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
|
||||||
|
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
--
|
||||||
|
2.37.3
|
||||||
|
|
||||||
68
0004-run-storage-layers-ut-with-non-root.patch
Normal file
68
0004-run-storage-layers-ut-with-non-root.patch
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
From 8c33633d26ec5d5eb9b5ad415afc114cf6c232f3 Mon Sep 17 00:00:00 2001
|
||||||
|
From: haozi007 <liuhao27@huawei.com>
|
||||||
|
Date: Tue, 11 Oct 2022 20:34:18 +0800
|
||||||
|
Subject: [PATCH 04/35] run storage layers ut with non-root
|
||||||
|
|
||||||
|
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||||
|
---
|
||||||
|
test/CMakeLists.txt | 2 ++
|
||||||
|
test/image/oci/storage/layers/storage_layers_ut.cc | 10 ++++++++--
|
||||||
|
2 files changed, 10 insertions(+), 2 deletions(-)
|
||||||
|
|
||||||
|
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
|
||||||
|
index 940de5ce..a36f68c5 100644
|
||||||
|
--- a/test/CMakeLists.txt
|
||||||
|
+++ b/test/CMakeLists.txt
|
||||||
|
@@ -1,5 +1,7 @@
|
||||||
|
project(iSulad_UT)
|
||||||
|
|
||||||
|
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-maybe-uninitialized")
|
||||||
|
+
|
||||||
|
function(gmock_find_library _name)
|
||||||
|
find_library(${_name}
|
||||||
|
NAMES ${ARGN}
|
||||||
|
diff --git a/test/image/oci/storage/layers/storage_layers_ut.cc b/test/image/oci/storage/layers/storage_layers_ut.cc
|
||||||
|
index 0b481a95..87dfb4a1 100644
|
||||||
|
--- a/test/image/oci/storage/layers/storage_layers_ut.cc
|
||||||
|
+++ b/test/image/oci/storage/layers/storage_layers_ut.cc
|
||||||
|
@@ -153,7 +153,8 @@ protected:
|
||||||
|
MockDriverQuota_SetMock(&m_driver_quota_mock);
|
||||||
|
struct storage_module_init_options opts = {0};
|
||||||
|
|
||||||
|
- std::string isulad_dir = "/var/lib/isulad/";
|
||||||
|
+ std::string isulad_dir = "/tmp/isulad/";
|
||||||
|
+ mkdir(isulad_dir.c_str(), 0755);
|
||||||
|
std::string root_dir = isulad_dir + "data";
|
||||||
|
std::string run_dir = isulad_dir + "data/run";
|
||||||
|
std::string data_dir = GetDirectory() + "/data";
|
||||||
|
@@ -167,6 +168,9 @@ protected:
|
||||||
|
ASSERT_STRNE(util_clean_path(run_dir.c_str(), real_run_path, sizeof(real_run_path)), nullptr);
|
||||||
|
opts.storage_run_root = strdup(real_run_path);
|
||||||
|
opts.driver_name = strdup("overlay");
|
||||||
|
+ opts.driver_opts = static_cast<char **>(util_smart_calloc_s(sizeof(char *), 1));
|
||||||
|
+ opts.driver_opts[0] = strdup("overlay2.skip_mount_home=true");
|
||||||
|
+ opts.driver_opts_len = 1;
|
||||||
|
|
||||||
|
EXPECT_CALL(m_driver_quota_mock, QuotaCtl(_, _, _, _)).WillRepeatedly(Invoke(invokeQuotaCtl));
|
||||||
|
ASSERT_EQ(layer_store_init(&opts), 0);
|
||||||
|
@@ -174,6 +178,8 @@ protected:
|
||||||
|
free(opts.storage_root);
|
||||||
|
free(opts.storage_run_root);
|
||||||
|
free(opts.driver_name);
|
||||||
|
+ free(opts.driver_opts[0]);
|
||||||
|
+ free(opts.driver_opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TearDown() override
|
||||||
|
@@ -183,7 +189,7 @@ protected:
|
||||||
|
layer_store_exit();
|
||||||
|
layer_store_cleanup();
|
||||||
|
|
||||||
|
- std::string rm_command = "rm -rf /var/lib/isulad/data";
|
||||||
|
+ std::string rm_command = "rm -rf /tmp/isulad/";
|
||||||
|
ASSERT_EQ(system(rm_command.c_str()), 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
--
|
||||||
|
2.37.3
|
||||||
|
|
||||||
37
0005-add-extern-C-for-mainloop-header.patch
Normal file
37
0005-add-extern-C-for-mainloop-header.patch
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
From 0ddc58b78b0ca7d6c1cb52b10e3fa03f0da69326 Mon Sep 17 00:00:00 2001
|
||||||
|
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
Date: Sat, 15 Oct 2022 16:51:38 +0800
|
||||||
|
Subject: [PATCH 05/35] add extern C for mainloop header
|
||||||
|
|
||||||
|
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
---
|
||||||
|
src/utils/cutils/mainloop.h | 8 ++++++++
|
||||||
|
1 file changed, 8 insertions(+)
|
||||||
|
|
||||||
|
diff --git a/src/utils/cutils/mainloop.h b/src/utils/cutils/mainloop.h
|
||||||
|
index 5124b33a..7a4f1cfd 100644
|
||||||
|
--- a/src/utils/cutils/mainloop.h
|
||||||
|
+++ b/src/utils/cutils/mainloop.h
|
||||||
|
@@ -18,6 +18,10 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "linked_list.h"
|
||||||
|
|
||||||
|
+#ifdef __cplusplus
|
||||||
|
+extern "C" {
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
typedef void (*epoll_timeout_callback_t)(void *data);
|
||||||
|
|
||||||
|
struct epoll_descr {
|
||||||
|
@@ -42,4 +46,8 @@ extern int epoll_loop_open(struct epoll_descr *descr);
|
||||||
|
|
||||||
|
extern int epoll_loop_close(struct epoll_descr *descr);
|
||||||
|
|
||||||
|
+#ifdef __cplusplus
|
||||||
|
+}
|
||||||
|
+#endif
|
||||||
|
+
|
||||||
|
#endif
|
||||||
|
--
|
||||||
|
2.37.3
|
||||||
|
|
||||||
517
0006-add-UT-for-mainloop-and-network.patch
Normal file
517
0006-add-UT-for-mainloop-and-network.patch
Normal file
@ -0,0 +1,517 @@
|
|||||||
|
From f7089859d339cfe2b33ab701c02e1f424e4bd248 Mon Sep 17 00:00:00 2001
|
||||||
|
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
Date: Sat, 15 Oct 2022 16:52:32 +0800
|
||||||
|
Subject: [PATCH 06/35] add UT for mainloop and network
|
||||||
|
|
||||||
|
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||||
|
---
|
||||||
|
test/cutils/CMakeLists.txt | 3 +
|
||||||
|
test/cutils/mainloop/CMakeLists.txt | 27 ++++++
|
||||||
|
test/cutils/mainloop/mainloop_ut.cc | 55 ++++++++++++
|
||||||
|
test/cutils/utils_network/CMakeLists.txt | 27 ++++++
|
||||||
|
test/cutils/utils_network/utils_network_ut.cc | 89 +++++++++++++++++++
|
||||||
|
test/cutils/utils_string/utils_string_ut.cc | 24 +++++
|
||||||
|
test/mocks/mainloop_mock.cc | 58 ++++++++++++
|
||||||
|
test/mocks/mainloop_mock.h | 33 +++++++
|
||||||
|
test/mocks/utils_network_mock.cc | 60 +++++++++++++
|
||||||
|
test/mocks/utils_network_mock.h | 34 +++++++
|
||||||
|
10 files changed, 410 insertions(+)
|
||||||
|
create mode 100644 test/cutils/mainloop/CMakeLists.txt
|
||||||
|
create mode 100644 test/cutils/mainloop/mainloop_ut.cc
|
||||||
|
create mode 100644 test/cutils/utils_network/CMakeLists.txt
|
||||||
|
create mode 100644 test/cutils/utils_network/utils_network_ut.cc
|
||||||
|
create mode 100644 test/mocks/mainloop_mock.cc
|
||||||
|
create mode 100644 test/mocks/mainloop_mock.h
|
||||||
|
create mode 100644 test/mocks/utils_network_mock.cc
|
||||||
|
create mode 100644 test/mocks/utils_network_mock.h
|
||||||
|
|
||||||
|
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||||
|
index 31408f18..724f2188 100644
|
||||||
|
--- a/test/cutils/CMakeLists.txt
|
||||||
|
+++ b/test/cutils/CMakeLists.txt
|
||||||
|
@@ -8,15 +8,18 @@ add_library(libutils_ut STATIC
|
||||||
|
${local_cutils_map_srcs}
|
||||||
|
)
|
||||||
|
set_target_properties(libutils_ut PROPERTIES PREFIX "")
|
||||||
|
+target_link_libraries(libutils_ut ${ISULA_LIBUTILS_LIBRARY})
|
||||||
|
target_include_directories(libutils_ut
|
||||||
|
PUBLIC ${CMAKE_SOURCE_DIR}/src/common
|
||||||
|
PUBLIC ${CMAKE_SOURCE_DIR}/src/utils/cutils
|
||||||
|
PUBLIC ${CMAKE_SOURCE_DIR}/src/utils/cutils/map
|
||||||
|
)
|
||||||
|
|
||||||
|
+add_subdirectory(mainloop)
|
||||||
|
add_subdirectory(utils_string)
|
||||||
|
add_subdirectory(utils_convert)
|
||||||
|
add_subdirectory(utils_array)
|
||||||
|
add_subdirectory(utils_base64)
|
||||||
|
add_subdirectory(utils_pwgr)
|
||||||
|
add_subdirectory(utils_namespace)
|
||||||
|
+add_subdirectory(utils_network)
|
||||||
|
diff --git a/test/cutils/mainloop/CMakeLists.txt b/test/cutils/mainloop/CMakeLists.txt
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..78e3f18d
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/cutils/mainloop/CMakeLists.txt
|
||||||
|
@@ -0,0 +1,27 @@
|
||||||
|
+project(iSulad_UT)
|
||||||
|
+
|
||||||
|
+SET(EXE mainloop_ut)
|
||||||
|
+
|
||||||
|
+add_executable(${EXE}
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/mainloop_mock.cc
|
||||||
|
+ mainloop_ut.cc)
|
||||||
|
+
|
||||||
|
+target_include_directories(${EXE} PUBLIC
|
||||||
|
+ ${GTEST_INCLUDE_DIR}
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks
|
||||||
|
+ )
|
||||||
|
+
|
||||||
|
+target_link_libraries(${EXE}
|
||||||
|
+ ${GTEST_BOTH_LIBRARIES}
|
||||||
|
+ ${GMOCK_LIBRARY}
|
||||||
|
+ ${GMOCK_MAIN_LIBRARY}
|
||||||
|
+ ${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
+ ${ISULA_LIBUTILS_LIBRARY}
|
||||||
|
+ libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
+
|
||||||
|
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
diff --git a/test/cutils/mainloop/mainloop_ut.cc b/test/cutils/mainloop/mainloop_ut.cc
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..adba9ea1
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/cutils/mainloop/mainloop_ut.cc
|
||||||
|
@@ -0,0 +1,55 @@
|
||||||
|
+/*
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
|
||||||
|
+ * iSulad licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Description: mainloop unit test
|
||||||
|
+ * Author: zhangxiaoyu
|
||||||
|
+ * Create: 2022-10-11
|
||||||
|
+ */
|
||||||
|
+
|
||||||
|
+#include <stdlib.h>
|
||||||
|
+#include <stdio.h>
|
||||||
|
+#include <gtest/gtest.h>
|
||||||
|
+#include "mainloop.h"
|
||||||
|
+#include "mainloop_mock.h"
|
||||||
|
+
|
||||||
|
+using ::testing::NiceMock;
|
||||||
|
+using ::testing::Invoke;
|
||||||
|
+using ::testing::Return;
|
||||||
|
+using ::testing::_;
|
||||||
|
+
|
||||||
|
+class MainloopUnitTest : public testing::Test {
|
||||||
|
+protected:
|
||||||
|
+ void SetUp() override
|
||||||
|
+ {
|
||||||
|
+ Mainloop_SetMock(&m_mainloop_mock);
|
||||||
|
+ EXPECT_CALL(m_mainloop_mock, Close(_)).WillRepeatedly(Return(0));
|
||||||
|
+ EXPECT_CALL(m_mainloop_mock, EpollCreate1(_)).WillRepeatedly(Return(0));
|
||||||
|
+ EXPECT_CALL(m_mainloop_mock, EpollCtl(_, _, _, _)).WillRepeatedly(Return(0));
|
||||||
|
+ EXPECT_CALL(m_mainloop_mock, EpollWait(_, _, _, _)).WillRepeatedly(Return(0));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void TearDown() override
|
||||||
|
+ {
|
||||||
|
+ Mainloop_SetMock(nullptr);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ NiceMock<MockMainloop> m_mainloop_mock;
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+TEST_F(MainloopUnitTest, test_mainloop)
|
||||||
|
+{
|
||||||
|
+ struct epoll_descr descr = { 0 };
|
||||||
|
+
|
||||||
|
+ ASSERT_EQ(epoll_loop_open(&descr), 0);
|
||||||
|
+ ASSERT_EQ(epoll_loop_add_handler(&descr, 111, nullptr, nullptr), 0);
|
||||||
|
+ ASSERT_EQ(epoll_loop(&descr, -1), 0);
|
||||||
|
+ ASSERT_EQ(epoll_loop_del_handler(&descr, 111), 0);
|
||||||
|
+ ASSERT_EQ(epoll_loop_close(&descr), 0);
|
||||||
|
+}
|
||||||
|
diff --git a/test/cutils/utils_network/CMakeLists.txt b/test/cutils/utils_network/CMakeLists.txt
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..7e2c84e7
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/cutils/utils_network/CMakeLists.txt
|
||||||
|
@@ -0,0 +1,27 @@
|
||||||
|
+project(iSulad_UT)
|
||||||
|
+
|
||||||
|
+SET(EXE utils_network_ut)
|
||||||
|
+
|
||||||
|
+add_executable(${EXE}
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks/utils_network_mock.cc
|
||||||
|
+ utils_network_ut.cc)
|
||||||
|
+
|
||||||
|
+target_include_directories(${EXE} PUBLIC
|
||||||
|
+ ${GTEST_INCLUDE_DIR}
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../include
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/common
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils/map
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/cutils
|
||||||
|
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../test/mocks
|
||||||
|
+ )
|
||||||
|
+
|
||||||
|
+target_link_libraries(${EXE}
|
||||||
|
+ ${GTEST_BOTH_LIBRARIES}
|
||||||
|
+ ${GMOCK_LIBRARY}
|
||||||
|
+ ${GMOCK_MAIN_LIBRARY}
|
||||||
|
+ ${CMAKE_THREAD_LIBS_INIT}
|
||||||
|
+ ${ISULA_LIBUTILS_LIBRARY}
|
||||||
|
+ libutils_ut -lcrypto -lyajl -lz)
|
||||||
|
+
|
||||||
|
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||||
|
diff --git a/test/cutils/utils_network/utils_network_ut.cc b/test/cutils/utils_network/utils_network_ut.cc
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..532fd780
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/cutils/utils_network/utils_network_ut.cc
|
||||||
|
@@ -0,0 +1,89 @@
|
||||||
|
+/*
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.
|
||||||
|
+ * iSulad licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Description: utils_network unit test
|
||||||
|
+ * Author: zhangxiaoyu
|
||||||
|
+ * Create: 2022-10-11
|
||||||
|
+ */
|
||||||
|
+
|
||||||
|
+#include <stdlib.h>
|
||||||
|
+#include <stdio.h>
|
||||||
|
+#include <gtest/gtest.h>
|
||||||
|
+#include "utils.h"
|
||||||
|
+#include "utils_network.h"
|
||||||
|
+#include "utils_network_mock.h"
|
||||||
|
+
|
||||||
|
+using ::testing::NiceMock;
|
||||||
|
+using ::testing::Invoke;
|
||||||
|
+using ::testing::Return;
|
||||||
|
+using ::testing::_;
|
||||||
|
+
|
||||||
|
+std::string GetLocalPath()
|
||||||
|
+{
|
||||||
|
+ char abs_path[PATH_MAX] { 0x00 };
|
||||||
|
+ int ret = readlink("/proc/self/exe", abs_path, sizeof(abs_path));
|
||||||
|
+ if (ret < 0 || static_cast<size_t>(ret) >= sizeof(abs_path)) {
|
||||||
|
+ return "";
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ for (int i { ret }; i >= 0; --i) {
|
||||||
|
+ if (abs_path[i] == '/') {
|
||||||
|
+ abs_path[i + 1] = '\0';
|
||||||
|
+ break;
|
||||||
|
+ }
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ return static_cast<std::string>(abs_path);
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+class UtilsNetworkUnitTest : public testing::Test {
|
||||||
|
+protected:
|
||||||
|
+ void SetUp() override
|
||||||
|
+ {
|
||||||
|
+ UtilsNetwork_SetMock(&m_utils_network_mock);
|
||||||
|
+ EXPECT_CALL(m_utils_network_mock, Mount(_, _, _, _, _)).WillRepeatedly(Return(0));
|
||||||
|
+ EXPECT_CALL(m_utils_network_mock, Umount2(_, _)).WillRepeatedly(Invoke(invokeUmont2));
|
||||||
|
+
|
||||||
|
+ EXPECT_CALL(m_utils_network_mock, PthreadCreate(_, _, _, _)).WillRepeatedly(Return(0));
|
||||||
|
+ EXPECT_CALL(m_utils_network_mock, PthreadJoin(_, _)).WillRepeatedly(Invoke(invokePthreadJoin));
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ void TearDown() override
|
||||||
|
+ {
|
||||||
|
+ UtilsNetwork_SetMock(nullptr);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ NiceMock<MockUtilsNetwork> m_utils_network_mock;
|
||||||
|
+
|
||||||
|
+ static int invokeUmont2(const char *target, int flags)
|
||||||
|
+ {
|
||||||
|
+ errno = EINVAL;
|
||||||
|
+ return -1;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ static int invokePthreadJoin(pthread_t thread, void **retval)
|
||||||
|
+ {
|
||||||
|
+ void *status = (void *)calloc(1, sizeof(int));
|
||||||
|
+ *retval = status;
|
||||||
|
+
|
||||||
|
+ return 0;
|
||||||
|
+ }
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+TEST_F(UtilsNetworkUnitTest, test_network_namespace)
|
||||||
|
+{
|
||||||
|
+ int err = 0;
|
||||||
|
+ std::string netNS = GetLocalPath() + "test_namespace";
|
||||||
|
+
|
||||||
|
+ ASSERT_EQ(util_create_netns_file(netNS.c_str()), 0);
|
||||||
|
+ ASSERT_EQ(util_mount_namespace(netNS.c_str()), 0);
|
||||||
|
+ ASSERT_EQ(util_umount_namespace(netNS.c_str()), 0);
|
||||||
|
+ ASSERT_EQ(util_force_remove_file(netNS.c_str(), &err), true);
|
||||||
|
+}
|
||||||
|
diff --git a/test/cutils/utils_string/utils_string_ut.cc b/test/cutils/utils_string/utils_string_ut.cc
|
||||||
|
index 0cac212f..b488a09f 100644
|
||||||
|
--- a/test/cutils/utils_string/utils_string_ut.cc
|
||||||
|
+++ b/test/cutils/utils_string/utils_string_ut.cc
|
||||||
|
@@ -807,3 +807,27 @@ TEST(utils_string_ut, test_parse_percent_string)
|
||||||
|
ret = util_parse_percent_string(wrong6, &converted);
|
||||||
|
ASSERT_NE(ret, 0);
|
||||||
|
}
|
||||||
|
+
|
||||||
|
+TEST(utils_string_ut, test_str_token)
|
||||||
|
+{
|
||||||
|
+ char *token = nullptr;
|
||||||
|
+ char *string = (char *)"abc:def:gh";
|
||||||
|
+ char *tmp = string;
|
||||||
|
+
|
||||||
|
+ token = util_str_token(&tmp, nullptr);
|
||||||
|
+ ASSERT_STREQ(token, nullptr);
|
||||||
|
+ token = util_str_token(nullptr, ":");
|
||||||
|
+ ASSERT_STREQ(token, nullptr);
|
||||||
|
+
|
||||||
|
+ token = util_str_token(&tmp, ",");
|
||||||
|
+ ASSERT_STREQ(tmp, nullptr);
|
||||||
|
+ ASSERT_STREQ(token, string);
|
||||||
|
+ tmp = string;
|
||||||
|
+ free(token);
|
||||||
|
+ token = nullptr;
|
||||||
|
+
|
||||||
|
+ token = util_str_token(&tmp, ":");
|
||||||
|
+ ASSERT_STREQ(tmp, "def:gh");
|
||||||
|
+ ASSERT_STREQ(token, "abc");
|
||||||
|
+ free(token);
|
||||||
|
+}
|
||||||
|
diff --git a/test/mocks/mainloop_mock.cc b/test/mocks/mainloop_mock.cc
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..508c957b
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/mocks/mainloop_mock.cc
|
||||||
|
@@ -0,0 +1,58 @@
|
||||||
|
+/******************************************************************************
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
|
||||||
|
+ * iSulad licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Author: zhangxiaoyu
|
||||||
|
+ * Create: 2022-10-13
|
||||||
|
+ * Description: provide mainloop mock
|
||||||
|
+ ******************************************************************************/
|
||||||
|
+
|
||||||
|
+#include "mainloop_mock.h"
|
||||||
|
+
|
||||||
|
+namespace {
|
||||||
|
+MockMainloop *g_mainloop_mock = nullptr;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void Mainloop_SetMock(MockMainloop* mock)
|
||||||
|
+{
|
||||||
|
+ g_mainloop_mock = mock;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int close(int fd)
|
||||||
|
+{
|
||||||
|
+ if (g_mainloop_mock != nullptr) {
|
||||||
|
+ return g_mainloop_mock->Close(fd);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int epoll_create1(int flags)
|
||||||
|
+{
|
||||||
|
+ std::cout << "epoll_create1" << std::endl;
|
||||||
|
+ if (g_mainloop_mock != nullptr) {
|
||||||
|
+ return g_mainloop_mock->EpollCreate1(flags);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int epoll_ctl(int epfd, int op, int fd, struct epoll_event *event)
|
||||||
|
+{
|
||||||
|
+ if (g_mainloop_mock != nullptr) {
|
||||||
|
+ return g_mainloop_mock->EpollCtl(epfd, op, fd, event);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int epoll_wait(int epfd, struct epoll_event *events, int maxevents, int timeout)
|
||||||
|
+{
|
||||||
|
+ if (g_mainloop_mock != nullptr) {
|
||||||
|
+ return g_mainloop_mock->EpollWait(epfd, events, maxevents, timeout);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
diff --git a/test/mocks/mainloop_mock.h b/test/mocks/mainloop_mock.h
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..aab16d12
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/mocks/mainloop_mock.h
|
||||||
|
@@ -0,0 +1,33 @@
|
||||||
|
+/******************************************************************************
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
|
||||||
|
+ * iSulad licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Author: zhangxiaoyu
|
||||||
|
+ * Create: 2022-10-13
|
||||||
|
+ * Description: mainloop mock
|
||||||
|
+ ******************************************************************************/
|
||||||
|
+
|
||||||
|
+#ifndef _ISULAD_TEST_MOCKS_MAINLOOP_MOCK_H
|
||||||
|
+#define _ISULAD_TEST_MOCKS_MAINLOOP_MOCK_H
|
||||||
|
+
|
||||||
|
+#include <gmock/gmock.h>
|
||||||
|
+#include <sys/epoll.h>
|
||||||
|
+
|
||||||
|
+class MockMainloop {
|
||||||
|
+public:
|
||||||
|
+ virtual ~MockMainloop() = default;
|
||||||
|
+ MOCK_METHOD1(Close, int(int));
|
||||||
|
+ MOCK_METHOD1(EpollCreate1, int(int));
|
||||||
|
+ MOCK_METHOD4(EpollCtl, int(int, int, int, struct epoll_event *));
|
||||||
|
+ MOCK_METHOD4(EpollWait, int(int, struct epoll_event *, int, int));
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+void Mainloop_SetMock(MockMainloop* mock);
|
||||||
|
+
|
||||||
|
+#endif // _ISULAD_TEST_MOCKS_MAINLOOP_MOCK_H
|
||||||
|
diff --git a/test/mocks/utils_network_mock.cc b/test/mocks/utils_network_mock.cc
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..afa346b5
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/mocks/utils_network_mock.cc
|
||||||
|
@@ -0,0 +1,60 @@
|
||||||
|
+/******************************************************************************
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
|
||||||
|
+ * iSulad licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Author: zhangxiaoyu
|
||||||
|
+ * Create: 2022-10-15
|
||||||
|
+ * Description: provide utils_network mock
|
||||||
|
+ ******************************************************************************/
|
||||||
|
+
|
||||||
|
+#include "utils_network_mock.h"
|
||||||
|
+
|
||||||
|
+namespace {
|
||||||
|
+MockUtilsNetwork *g_utils_network_mock = nullptr;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+void UtilsNetwork_SetMock(MockUtilsNetwork* mock)
|
||||||
|
+{
|
||||||
|
+ g_utils_network_mock = mock;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int mount(const char *source, const char *target, const char *filesystemtype,
|
||||||
|
+ unsigned long mountflags, const void *data)
|
||||||
|
+{
|
||||||
|
+ if (g_utils_network_mock != nullptr) {
|
||||||
|
+ return g_utils_network_mock->Mount(source, target, filesystemtype, mountflags, data);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int umount2(const char *target, int flags)
|
||||||
|
+{
|
||||||
|
+ if (g_utils_network_mock != nullptr) {
|
||||||
|
+ return g_utils_network_mock->Umount2(target, flags);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void *),
|
||||||
|
+ void *arg)
|
||||||
|
+{
|
||||||
|
+ if (g_utils_network_mock != nullptr) {
|
||||||
|
+ return g_utils_network_mock->PthreadCreate(thread, attr, start_routine, arg);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
+
|
||||||
|
+
|
||||||
|
+int pthread_join(pthread_t thread, void **retval)
|
||||||
|
+{
|
||||||
|
+ if (g_utils_network_mock != nullptr) {
|
||||||
|
+ return g_utils_network_mock->PthreadJoin(thread, retval);
|
||||||
|
+ }
|
||||||
|
+ return 0;
|
||||||
|
+}
|
||||||
|
\ No newline at end of file
|
||||||
|
diff --git a/test/mocks/utils_network_mock.h b/test/mocks/utils_network_mock.h
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..fcae5664
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/test/mocks/utils_network_mock.h
|
||||||
|
@@ -0,0 +1,34 @@
|
||||||
|
+/******************************************************************************
|
||||||
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2020-2022. All rights reserved.
|
||||||
|
+ * iSulad licensed under the Mulan PSL v2.
|
||||||
|
+ * You can use this software according to the terms and conditions of the Mulan PSL v2.
|
||||||
|
+ * You may obtain a copy of Mulan PSL v2 at:
|
||||||
|
+ * http://license.coscl.org.cn/MulanPSL2
|
||||||
|
+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
|
||||||
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
|
||||||
|
+ * PURPOSE.
|
||||||
|
+ * See the Mulan PSL v2 for more details.
|
||||||
|
+ * Author: zhangxiaoyu
|
||||||
|
+ * Create: 2022-10-15
|
||||||
|
+ * Description: utils_network mock
|
||||||
|
+ ******************************************************************************/
|
||||||
|
+
|
||||||
|
+#ifndef _ISULAD_TEST_MOCKS_UTILS_NETWORK_MOCK_H
|
||||||
|
+#define _ISULAD_TEST_MOCKS_UTILS_NETWORK_MOCK_H
|
||||||
|
+
|
||||||
|
+#include <gmock/gmock.h>
|
||||||
|
+#include <sys/mount.h>
|
||||||
|
+#include <pthread.h>
|
||||||
|
+
|
||||||
|
+class MockUtilsNetwork {
|
||||||
|
+public:
|
||||||
|
+ virtual ~MockUtilsNetwork() = default;
|
||||||
|
+ MOCK_METHOD5(Mount, int(const char *, const char *, const char *, unsigned long, const void *));
|
||||||
|
+ MOCK_METHOD2(Umount2, int(const char *, int));
|
||||||
|
+ MOCK_METHOD4(PthreadCreate, int(pthread_t *, const pthread_attr_t *, void *(*start_routine)(void *), void *));
|
||||||
|
+ MOCK_METHOD2(PthreadJoin, int(pthread_t, void **));
|
||||||
|
+};
|
||||||
|
+
|
||||||
|
+void UtilsNetwork_SetMock(MockUtilsNetwork* mock);
|
||||||
|
+
|
||||||
|
+#endif // _ISULAD_TEST_MOCKS_UTILS_NETWORK_MOCK_H
|
||||||
|
--
|
||||||
|
2.37.3
|
||||||
|
|
||||||
13
iSulad.spec
13
iSulad.spec
@ -1,5 +1,5 @@
|
|||||||
%global _version 2.0.17
|
%global _version 2.0.17
|
||||||
%global _release 3
|
%global _release 4
|
||||||
%global is_systemd 1
|
%global is_systemd 1
|
||||||
%global enable_shimv2 1
|
%global enable_shimv2 1
|
||||||
%global is_embedded 1
|
%global is_embedded 1
|
||||||
@ -14,6 +14,11 @@ Source: https://gitee.com/openeuler/iSulad/repository/archive/v%{version}.tar
|
|||||||
BuildRoot: {_tmppath}/iSulad-%{version}
|
BuildRoot: {_tmppath}/iSulad-%{version}
|
||||||
|
|
||||||
Patch0001: 0001-use-epoll-instead-of-select-for-wait_exit_fifo.patch
|
Patch0001: 0001-use-epoll-instead-of-select-for-wait_exit_fifo.patch
|
||||||
|
Patch0002: 0002-add-namespace-util-UT.patch
|
||||||
|
Patch0003: 0003-refactor-build-system-of-cutils-ut.patch
|
||||||
|
Patch0004: 0004-run-storage-layers-ut-with-non-root.patch
|
||||||
|
Patch0005: 0005-add-extern-C-for-mainloop-header.patch
|
||||||
|
Patch0006: 0006-add-UT-for-mainloop-and-network.patch
|
||||||
|
|
||||||
%ifarch x86_64 aarch64
|
%ifarch x86_64 aarch64
|
||||||
Provides: libhttpclient.so()(64bit)
|
Provides: libhttpclient.so()(64bit)
|
||||||
@ -240,6 +245,12 @@ fi
|
|||||||
%endif
|
%endif
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Oct 31 2022 wujing <wujing50@huawei.com> - 2.0.17-4
|
||||||
|
- Type: enhancement
|
||||||
|
- ID: NA
|
||||||
|
- SUG: NA
|
||||||
|
- DESC: sync from openEuler
|
||||||
|
|
||||||
* Wed Oct 19 2022 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.0.17-3
|
* Wed Oct 19 2022 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.0.17-3
|
||||||
- Type: enhancement
|
- Type: enhancement
|
||||||
- ID: NA
|
- ID: NA
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user