!478 add ut and bugfix for device mapper and websocket
From: @zh_xiaoyu Reviewed-by: @duguhaotian Signed-off-by: @duguhaotian
This commit is contained in:
commit
7bd62dac76
@ -1,7 +1,7 @@
|
||||
From f9cb1b86511fac1c3a7f11fdaa4c9c20dc889068 Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Sun, 9 Oct 2022 19:00:38 +0800
|
||||
Subject: [PATCH 01/35] use epoll instead of select for wait_exit_fifo
|
||||
Subject: [PATCH 01/39] use epoll instead of select for wait_exit_fifo
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
@ -154,5 +154,5 @@ index b9099a74..5124b33a 100644
|
||||
|
||||
#define EPOLL_LOOP_HANDLE_CONTINUE 0
|
||||
--
|
||||
2.37.3
|
||||
2.25.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
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
|
||||
Subject: [PATCH 02/39] add namespace util UT
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
@ -151,5 +151,5 @@ index 00000000..da50d503
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.37.3
|
||||
2.25.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
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
|
||||
Subject: [PATCH 03/39] refactor build system of cutils ut
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
@ -178,5 +178,5 @@ index c86141ef..1343f4e6 100644
|
||||
+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
|
||||
2.25.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
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
|
||||
Subject: [PATCH 04/39] run storage layers ut with non-root
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
@ -64,5 +64,5 @@ index 0b481a95..87dfb4a1 100644
|
||||
}
|
||||
|
||||
--
|
||||
2.37.3
|
||||
2.25.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
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
|
||||
Subject: [PATCH 05/39] add extern C for mainloop header
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
@ -33,5 +33,5 @@ index 5124b33a..7a4f1cfd 100644
|
||||
+
|
||||
#endif
|
||||
--
|
||||
2.37.3
|
||||
2.25.1
|
||||
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
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
|
||||
Subject: [PATCH 06/39] add UT for mainloop and network
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
@ -513,5 +513,5 @@ index 00000000..fcae5664
|
||||
+
|
||||
+#endif // _ISULAD_TEST_MOCKS_UTILS_NETWORK_MOCK_H
|
||||
--
|
||||
2.37.3
|
||||
2.25.1
|
||||
|
||||
|
||||
159
0007-add-check-for-aes-apis.patch
Normal file
159
0007-add-check-for-aes-apis.patch
Normal file
@ -0,0 +1,159 @@
|
||||
From 59b3f0832626fecebef66326b5316dbd10e482e0 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Sat, 15 Oct 2022 14:53:50 +0800
|
||||
Subject: [PATCH 07/39] add check for aes apis
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
src/utils/cutils/namespace.c | 3 +--
|
||||
src/utils/cutils/utils_aes.c | 48 ++++++++++++++++++++++++++++++------
|
||||
src/utils/cutils/utils_aes.h | 2 +-
|
||||
3 files changed, 43 insertions(+), 10 deletions(-)
|
||||
|
||||
diff --git a/src/utils/cutils/namespace.c b/src/utils/cutils/namespace.c
|
||||
index 2916c8bb..dc2fe810 100644
|
||||
--- a/src/utils/cutils/namespace.c
|
||||
+++ b/src/utils/cutils/namespace.c
|
||||
@@ -20,9 +20,8 @@
|
||||
|
||||
char *namespace_get_connected_container(const char *mode)
|
||||
{
|
||||
- const char *p = mode != NULL ? (mode + strlen(SHARE_NAMESPACE_PREFIX)) : NULL;
|
||||
-
|
||||
if (namespace_is_container(mode)) {
|
||||
+ const char *p = mode + strlen(SHARE_NAMESPACE_PREFIX);
|
||||
return util_strdup_s(p);
|
||||
}
|
||||
|
||||
diff --git a/src/utils/cutils/utils_aes.c b/src/utils/cutils/utils_aes.c
|
||||
index 9e318b5b..1e25ecd3 100644
|
||||
--- a/src/utils/cutils/utils_aes.c
|
||||
+++ b/src/utils/cutils/utils_aes.c
|
||||
@@ -28,12 +28,17 @@
|
||||
#include "utils.h"
|
||||
#include "utils_file.h"
|
||||
|
||||
-int util_aes_key(char *key_file, bool create, unsigned char *aeskey)
|
||||
+int util_aes_key(const char *key_file, bool create, unsigned char *aeskey)
|
||||
{
|
||||
char *key_dir = NULL;
|
||||
int fd = 0;
|
||||
int ret = 0;
|
||||
|
||||
+ if (key_file == NULL || aeskey == NULL) {
|
||||
+ ERROR("Invalid arguments");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
if (!util_file_exists(key_file)) {
|
||||
if (!create) {
|
||||
ERROR("init aes failed, file %s not exist", key_file);
|
||||
@@ -102,6 +107,11 @@ size_t util_aes_encode_buf_len(size_t len)
|
||||
return AES_256_CFB_IV_LEN + util_aes_decode_buf_len(len);
|
||||
}
|
||||
|
||||
+static bool invalid_ase_args(unsigned char *aeskey, unsigned char *bytes, size_t len, unsigned char **out)
|
||||
+{
|
||||
+ return aeskey == NULL || out == NULL || bytes == NULL || len == 0;
|
||||
+}
|
||||
+
|
||||
int util_aes_encode(unsigned char *aeskey, unsigned char *bytes, size_t len, unsigned char **out)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -110,22 +120,34 @@ int util_aes_encode(unsigned char *aeskey, unsigned char *bytes, size_t len, uns
|
||||
int size = 0;
|
||||
int expected_size = len;
|
||||
unsigned char *iv = NULL;
|
||||
+ EVP_CIPHER_CTX *ctx = NULL;
|
||||
#ifdef OPENSSL_IS_BORINGSSL
|
||||
const EVP_CIPHER *cipher = EVP_aes_256_ofb();
|
||||
#else
|
||||
const EVP_CIPHER *cipher = EVP_aes_256_cfb();
|
||||
#endif
|
||||
- EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
|
||||
- if (ctx == NULL || cipher == NULL) {
|
||||
+ if (cipher == NULL) {
|
||||
ERROR("EVP init failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
+ if (invalid_ase_args(aeskey, bytes, len, out)) {
|
||||
+ ERROR("Invalid arguments");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ ctx = EVP_CIPHER_CTX_new();
|
||||
+ if (ctx == NULL) {
|
||||
+ ERROR("Ctx create failed");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
*out = util_common_calloc_s(util_aes_encode_buf_len(len) + 1);
|
||||
if (*out == NULL) {
|
||||
ERROR("out of memory");
|
||||
- return -1;
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
}
|
||||
iv = *out;
|
||||
|
||||
@@ -192,27 +214,39 @@ int util_aes_decode(unsigned char *aeskey, unsigned char *bytes, size_t len, uns
|
||||
int size = 0;
|
||||
int expected_size = 0;
|
||||
unsigned char *iv = NULL;
|
||||
+ EVP_CIPHER_CTX *ctx = NULL;
|
||||
#ifdef OPENSSL_IS_BORINGSSL
|
||||
const EVP_CIPHER *cipher = EVP_aes_256_ofb();
|
||||
#else
|
||||
const EVP_CIPHER *cipher = EVP_aes_256_cfb();
|
||||
#endif
|
||||
- EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new();
|
||||
|
||||
- if (ctx == NULL || cipher == NULL) {
|
||||
+ if (cipher == NULL) {
|
||||
ERROR("EVP init failed");
|
||||
return -1;
|
||||
}
|
||||
|
||||
+ if (invalid_ase_args(aeskey, bytes, len, out)) {
|
||||
+ ERROR("Invalid arguments");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
if (len <= AES_256_CFB_IV_LEN) {
|
||||
ERROR("Invalid aes length, it must be larger than %d", AES_256_CFB_IV_LEN);
|
||||
return -1;
|
||||
}
|
||||
|
||||
+ ctx = EVP_CIPHER_CTX_new();
|
||||
+ if (ctx == NULL) {
|
||||
+ ERROR("Ctx create failed");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
*out = util_common_calloc_s(util_aes_decode_buf_len(len) + 1);
|
||||
if (*out == NULL) {
|
||||
ERROR("out of memory");
|
||||
- return -1;
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
}
|
||||
|
||||
iv = bytes;
|
||||
diff --git a/src/utils/cutils/utils_aes.h b/src/utils/cutils/utils_aes.h
|
||||
index d429c9e0..476fea65 100644
|
||||
--- a/src/utils/cutils/utils_aes.h
|
||||
+++ b/src/utils/cutils/utils_aes.h
|
||||
@@ -27,7 +27,7 @@ extern "C" {
|
||||
#define AES_256_CFB_KEY_LEN 32
|
||||
#define AES_256_CFB_IV_LEN 16
|
||||
|
||||
-int util_aes_key(char *key_path, bool create, unsigned char *aeskey);
|
||||
+int util_aes_key(const char *key_path, bool create, unsigned char *aeskey);
|
||||
|
||||
// note: Input bytes is "IV+data", "bytes+AES_256_CFB_IV_LEN" is the real data to be encoded.
|
||||
// The output length is the input "len" and add the '\0' after end of the length.
|
||||
--
|
||||
2.25.1
|
||||
|
||||
142
0008-add-ut-for-cutils-aes.patch
Normal file
142
0008-add-ut-for-cutils-aes.patch
Normal file
@ -0,0 +1,142 @@
|
||||
From 3909ddbc369c69202308e77beda6553b7d95d79b Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Sat, 15 Oct 2022 15:04:56 +0800
|
||||
Subject: [PATCH 08/39] add ut for cutils aes
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
test/CMakeLists.txt | 1 +
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_aes/CMakeLists.txt | 16 ++++++
|
||||
test/cutils/utils_aes/utils_aes_ut.cc | 74 +++++++++++++++++++++++++++
|
||||
4 files changed, 92 insertions(+)
|
||||
create mode 100644 test/cutils/utils_aes/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_aes/utils_aes_ut.cc
|
||||
|
||||
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
|
||||
index a36f68c5..034aaf97 100644
|
||||
--- a/test/CMakeLists.txt
|
||||
+++ b/test/CMakeLists.txt
|
||||
@@ -62,6 +62,7 @@ IF(ENABLE_COVERAGE)
|
||||
|
||||
COMMAND lcov --directory . --capture --output-file coverage.info
|
||||
COMMAND lcov -a coverage.base -a coverage.info --output-file coverage.total
|
||||
+ COMMAND lcov --remove coverage.total '/usr/include/*' --output-file coverage.total
|
||||
COMMAND lcov --remove coverage.total ${COVERAGE_EXCLUDES} --output-file ${PROJECT_BINARY_DIR}/coverage.info.cleaned
|
||||
COMMAND genhtml -o coverage ${PROJECT_BINARY_DIR}/coverage.info.cleaned
|
||||
COMMAND ${CMAKE_COMMAND} -E remove coverage.base coverage.total ${PROJECT_BINARY_DIR}/coverage.info.cleaned
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 724f2188..93c73fb8 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -23,3 +23,4 @@ add_subdirectory(utils_base64)
|
||||
add_subdirectory(utils_pwgr)
|
||||
add_subdirectory(utils_namespace)
|
||||
add_subdirectory(utils_network)
|
||||
+add_subdirectory(utils_aes)
|
||||
diff --git a/test/cutils/utils_aes/CMakeLists.txt b/test/cutils/utils_aes/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..f7535bb3
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_aes/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_aes_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_aes_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_aes/utils_aes_ut.cc b/test/cutils/utils_aes/utils_aes_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..e564428d
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_aes/utils_aes_ut.cc
|
||||
@@ -0,0 +1,74 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: haozi007
|
||||
+ * Create: 2022-10-13
|
||||
+ * Description: utils namespace unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils_aes.h"
|
||||
+
|
||||
+TEST(utils_aes, test_util_aes_key)
|
||||
+{
|
||||
+ std::string key_file = "./aes_key";
|
||||
+ unsigned char key_val[AES_256_CFB_KEY_LEN] = { 0 };
|
||||
+
|
||||
+ unlink(key_file.c_str());
|
||||
+ ASSERT_NE(util_aes_key(key_file.c_str(), false, key_val), 0);
|
||||
+ ASSERT_NE(util_aes_key(nullptr, true, key_val), 0);
|
||||
+ ASSERT_NE(util_aes_key(nullptr, false, key_val), 0);
|
||||
+ ASSERT_NE(util_aes_key(key_file.c_str(), true, nullptr), 0);
|
||||
+ ASSERT_NE(util_aes_key(key_file.c_str(), false, nullptr), 0);
|
||||
+ ASSERT_NE(util_aes_key(nullptr, true, nullptr), 0);
|
||||
+ ASSERT_NE(util_aes_key(nullptr, false, nullptr), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_aes, test_util_aes_encode)
|
||||
+{
|
||||
+ std::string key_file = "./aes_key";
|
||||
+ unsigned char key_val[AES_256_CFB_KEY_LEN] = { 0 };
|
||||
+ std::string test_data = "hello world";
|
||||
+ unsigned char *out = nullptr;
|
||||
+
|
||||
+ ASSERT_EQ(util_aes_key(key_file.c_str(), true, key_val), 0);
|
||||
+ ASSERT_EQ(util_aes_encode(key_val, (unsigned char *)test_data.c_str(), test_data.size(), &out), 0);
|
||||
+
|
||||
+ ASSERT_NE(util_aes_encode(nullptr, (unsigned char *)test_data.c_str(), test_data.size(), &out), 0);
|
||||
+ ASSERT_NE(util_aes_encode(key_val, nullptr, 0, &out), 0);
|
||||
+ ASSERT_NE(util_aes_encode(key_val, (unsigned char *)test_data.c_str(), 0, &out), 0);
|
||||
+ ASSERT_NE(util_aes_encode(key_val, (unsigned char *)test_data.c_str(), test_data.size(), nullptr), 0);
|
||||
+
|
||||
+ unlink(key_file.c_str());
|
||||
+}
|
||||
+
|
||||
+TEST(utils_aes, test_util_aes_decode)
|
||||
+{
|
||||
+ std::string key_file = "./aes_key";
|
||||
+ unsigned char key_val[AES_256_CFB_KEY_LEN] = { 0 };
|
||||
+ std::string test_data = "hello world";
|
||||
+ unsigned char *encode_data = nullptr;
|
||||
+ unsigned char *decode_data = nullptr;
|
||||
+ size_t aes_len = AES_256_CFB_IV_LEN;
|
||||
+
|
||||
+ ASSERT_EQ(util_aes_key(key_file.c_str(), true, key_val), 0);
|
||||
+ ASSERT_EQ(util_aes_encode(key_val, (unsigned char *)test_data.c_str(), test_data.size(), &encode_data), 0);
|
||||
+ aes_len += test_data.size();
|
||||
+ ASSERT_EQ(util_aes_decode(key_val, encode_data, aes_len, &decode_data), 0);
|
||||
+ printf("get decode value = %s\n", (const char *)decode_data);
|
||||
+ ASSERT_EQ(strcmp(test_data.c_str(), (const char *)decode_data), 0);
|
||||
+
|
||||
+ ASSERT_NE(util_aes_decode(nullptr, encode_data, aes_len, &decode_data), 0);
|
||||
+ ASSERT_NE(util_aes_decode(key_val, nullptr, 0, &decode_data), 0);
|
||||
+ ASSERT_NE(util_aes_decode(key_val, encode_data, 0, &decode_data), 0);
|
||||
+ ASSERT_NE(util_aes_decode(key_val, encode_data, aes_len, nullptr), 0);
|
||||
+
|
||||
+ unlink(key_file.c_str());
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
100
0009-add-ut-for-cutils-error.patch
Normal file
100
0009-add-ut-for-cutils-error.patch
Normal file
@ -0,0 +1,100 @@
|
||||
From b2f293d1777ba3846ea4bcab5754b66ebfe4094c Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Sat, 15 Oct 2022 17:01:02 +0800
|
||||
Subject: [PATCH 09/39] add ut for cutils error
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_error/CMakeLists.txt | 16 ++++++++
|
||||
test/cutils/utils_error/utils_error_ut.cc | 45 +++++++++++++++++++++++
|
||||
3 files changed, 62 insertions(+)
|
||||
create mode 100644 test/cutils/utils_error/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_error/utils_error_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 93c73fb8..d3e1038a 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -24,3 +24,4 @@ add_subdirectory(utils_pwgr)
|
||||
add_subdirectory(utils_namespace)
|
||||
add_subdirectory(utils_network)
|
||||
add_subdirectory(utils_aes)
|
||||
+add_subdirectory(utils_error)
|
||||
diff --git a/test/cutils/utils_error/CMakeLists.txt b/test/cutils/utils_error/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..28016605
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_error/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_error_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_error_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_error/utils_error_ut.cc b/test/cutils/utils_error/utils_error_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..d4585d70
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_error/utils_error_ut.cc
|
||||
@@ -0,0 +1,45 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: haozi007
|
||||
+ * Create: 2022-10-13
|
||||
+ * Description: utils namespace unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "error.h"
|
||||
+
|
||||
+TEST(utils_error, test_errno_to_error_message)
|
||||
+{
|
||||
+ const char *ret = nullptr;
|
||||
+ std::string internal_err = "Server internal error";
|
||||
+ std::string unknow_err = "Unknown error";
|
||||
+
|
||||
+ ret = errno_to_error_message(ISULAD_SUCCESS);
|
||||
+ ASSERT_EQ(strcmp(ret, DEF_SUCCESS_STR), 0);
|
||||
+
|
||||
+ ret = errno_to_error_message(ISULAD_ERR_INTERNAL);
|
||||
+ ASSERT_EQ(strcmp(ret, internal_err.c_str()), 0);
|
||||
+
|
||||
+ ret = errno_to_error_message(ISULAD_ERR_UNKNOWN);
|
||||
+ ASSERT_EQ(strcmp(ret, unknow_err.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_error, test_format_errorf)
|
||||
+{
|
||||
+ char *out = nullptr;
|
||||
+ std::string target = "hello world";
|
||||
+
|
||||
+ format_errorf(&out, "hello %s", "world");
|
||||
+ ASSERT_EQ(strcmp(out, target.c_str()), 0);
|
||||
+
|
||||
+ format_errorf(nullptr, "hello %s", "world");
|
||||
+ format_errorf(&out, nullptr);
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
28
0010-ensure-argument-is-not-null.patch
Normal file
28
0010-ensure-argument-is-not-null.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 99caa82b9406ef344707401c0b8c548296924466 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Sat, 15 Oct 2022 17:18:28 +0800
|
||||
Subject: [PATCH 10/39] ensure argument is not null
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
src/utils/cutils/error.h | 4 ++++
|
||||
1 file changed, 4 insertions(+)
|
||||
|
||||
diff --git a/src/utils/cutils/error.h b/src/utils/cutils/error.h
|
||||
index 5a8dca99..e3946cf2 100644
|
||||
--- a/src/utils/cutils/error.h
|
||||
+++ b/src/utils/cutils/error.h
|
||||
@@ -62,6 +62,10 @@ static inline void format_errorf(char **err, const char *format, ...)
|
||||
va_list argp;
|
||||
va_start(argp, format);
|
||||
|
||||
+ if (err == NULL) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
ret = vsnprintf(errbuf, BUFSIZ, format, argp);
|
||||
va_end(argp);
|
||||
if (ret < 0) {
|
||||
--
|
||||
2.25.1
|
||||
|
||||
96
0011-add-ut-for-utils_fs.patch
Normal file
96
0011-add-ut-for-utils_fs.patch
Normal file
@ -0,0 +1,96 @@
|
||||
From 8020e1e076e597a82962fe03990f89314f5419fa Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Mon, 17 Oct 2022 11:10:05 +0800
|
||||
Subject: [PATCH 11/39] add ut for utils_fs
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_fs/CMakeLists.txt | 16 +++++++++++
|
||||
test/cutils/utils_fs/utils_fs_ut.cc | 42 +++++++++++++++++++++++++++++
|
||||
3 files changed, 59 insertions(+)
|
||||
create mode 100644 test/cutils/utils_fs/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_fs/utils_fs_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index d3e1038a..9073a68d 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -25,3 +25,4 @@ add_subdirectory(utils_namespace)
|
||||
add_subdirectory(utils_network)
|
||||
add_subdirectory(utils_aes)
|
||||
add_subdirectory(utils_error)
|
||||
+add_subdirectory(utils_fs)
|
||||
diff --git a/test/cutils/utils_fs/CMakeLists.txt b/test/cutils/utils_fs/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..7ff3176a
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_fs/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_fs_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_fs_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_fs/utils_fs_ut.cc b/test/cutils/utils_fs/utils_fs_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..e1c4fd4b
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_fs/utils_fs_ut.cc
|
||||
@@ -0,0 +1,42 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: haozi007
|
||||
+ * Create: 2022-10-13
|
||||
+ * Description: utils namespace unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils_fs.h"
|
||||
+
|
||||
+int good_cb(const char *mp, const char *pattern)
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+int good_check_cb(const char *mp, const char *pattern)
|
||||
+{
|
||||
+ return pattern != nullptr ? 0 : -1;
|
||||
+}
|
||||
+
|
||||
+int bad_cb(const char *mp, const char *pattern)
|
||||
+{
|
||||
+ return -1;
|
||||
+}
|
||||
+
|
||||
+TEST(utils_fs, test_util_deal_with_mount_info)
|
||||
+{
|
||||
+ std::string spattern = "[0-9]*";
|
||||
+
|
||||
+ ASSERT_EQ(util_deal_with_mount_info(good_cb, spattern.c_str()), true);
|
||||
+ ASSERT_EQ(util_deal_with_mount_info(bad_cb, spattern.c_str()), false);
|
||||
+ ASSERT_EQ(util_deal_with_mount_info(good_check_cb, spattern.c_str()), true);
|
||||
+ ASSERT_EQ(util_deal_with_mount_info(good_check_cb, nullptr), false);
|
||||
+}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
55
0012-Add-adaptation-code-for-filters.patch
Normal file
55
0012-Add-adaptation-code-for-filters.patch
Normal file
@ -0,0 +1,55 @@
|
||||
From f1313b04f60672a1aae1a3d36df5f0b8abcdd06f Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Mon, 17 Oct 2022 15:04:01 +0800
|
||||
Subject: [PATCH 12/39] Add adaptation code for filters
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
src/utils/cutils/filters.c | 3 ++-
|
||||
src/utils/cutils/filters.h | 8 ++++++++
|
||||
2 files changed, 10 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/utils/cutils/filters.c b/src/utils/cutils/filters.c
|
||||
index 1885e9cc..21f5db7c 100644
|
||||
--- a/src/utils/cutils/filters.c
|
||||
+++ b/src/utils/cutils/filters.c
|
||||
@@ -315,9 +315,10 @@ bool filters_args_valid_key(const char **accepted, size_t len, const char *field
|
||||
{
|
||||
size_t i;
|
||||
|
||||
- if (field == NULL) {
|
||||
+ if (accepted == NULL || field == NULL) {
|
||||
return false;
|
||||
}
|
||||
+
|
||||
for (i = 0; i < len; i++) {
|
||||
if (accepted[i] != NULL && strcmp(accepted[i], field) == 0) {
|
||||
return true;
|
||||
diff --git a/src/utils/cutils/filters.h b/src/utils/cutils/filters.h
|
||||
index 021704d1..c6e5a618 100644
|
||||
--- a/src/utils/cutils/filters.h
|
||||
+++ b/src/utils/cutils/filters.h
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
#include "map.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct filters_args {
|
||||
// A map of map[string][map[string][bool]]
|
||||
map_t *fields;
|
||||
@@ -48,5 +52,9 @@ bool filters_args_exact_match(const struct filters_args *filters, const char *fi
|
||||
|
||||
bool filters_args_match(const struct filters_args *filters, const char *field, const char *source);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
30
0013-Add-parameter-check-to-path.patch
Normal file
30
0013-Add-parameter-check-to-path.patch
Normal file
@ -0,0 +1,30 @@
|
||||
From 45824723bf3968a1106089fb0572ad6a593ac62e Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Mon, 17 Oct 2022 15:15:49 +0800
|
||||
Subject: [PATCH 13/39] Add parameter check to path
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
src/utils/cutils/path.c | 6 ++++++
|
||||
1 file changed, 6 insertions(+)
|
||||
|
||||
diff --git a/src/utils/cutils/path.c b/src/utils/cutils/path.c
|
||||
index 79cd7af6..5a743632 100644
|
||||
--- a/src/utils/cutils/path.c
|
||||
+++ b/src/utils/cutils/path.c
|
||||
@@ -733,6 +733,12 @@ int util_realpath_in_scope(const char *rootfs, const char *path, char **real_pat
|
||||
char cleaned[PATH_MAX] = { 0 };
|
||||
char *tmp = NULL;
|
||||
|
||||
+ if (rootfs == NULL || path == NULL || real_path == NULL) {
|
||||
+ ERROR("Null parameter");
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
int nret = snprintf(full_path, sizeof(full_path), "%s%s", rootfs, path);
|
||||
if (nret < 0 || (size_t)nret >= sizeof(full_path)) {
|
||||
ERROR("sprintf error: %s", strerror(errno));
|
||||
--
|
||||
2.25.1
|
||||
|
||||
134
0014-Add-ut-for-utils_convert.patch
Normal file
134
0014-Add-ut-for-utils_convert.patch
Normal file
@ -0,0 +1,134 @@
|
||||
From 8cd75df646c836745b5a1325e68be67046a84f1a Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Mon, 17 Oct 2022 18:23:19 +0800
|
||||
Subject: [PATCH 14/39] Add ut for utils_convert
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
test/cutils/utils_convert/utils_convert_ut.cc | 112 ++++++++++++++++++
|
||||
1 file changed, 112 insertions(+)
|
||||
|
||||
diff --git a/test/cutils/utils_convert/utils_convert_ut.cc b/test/cutils/utils_convert/utils_convert_ut.cc
|
||||
index 7e46fd84..bee9c3c4 100644
|
||||
--- a/test/cutils/utils_convert/utils_convert_ut.cc
|
||||
+++ b/test/cutils/utils_convert/utils_convert_ut.cc
|
||||
@@ -239,3 +239,115 @@ TEST(utils_convert, test_util_str_to_bool)
|
||||
ret = util_str_to_bool("nullptr", &converted);
|
||||
ASSERT_NE(ret, 0);
|
||||
}
|
||||
+
|
||||
+TEST(utils_convert, test_util_safe_uint64)
|
||||
+{
|
||||
+ int ret;
|
||||
+ uint64_t converted;
|
||||
+ ret = util_safe_uint64("255", &converted);
|
||||
+ ASSERT_EQ(ret, 0);
|
||||
+ ASSERT_EQ(converted, 255);
|
||||
+
|
||||
+ ret = util_safe_uint64("255", nullptr);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_safe_uint64("-1", &converted);
|
||||
+ ASSERT_EQ(ret, 0);
|
||||
+ ASSERT_EQ(converted, UINT64_MAX);
|
||||
+
|
||||
+ ret = util_safe_uint64("0", &converted);
|
||||
+ ASSERT_EQ(ret, 0);
|
||||
+ ASSERT_EQ(converted, 0);
|
||||
+
|
||||
+ ret = util_safe_uint64("1.23", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_safe_uint64("1x", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_safe_uint64("18446744073709551616", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_safe_uint64("nullptr", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_convert, test_util_parse_octal_uint32)
|
||||
+{
|
||||
+ int ret;
|
||||
+ uint32_t converted;
|
||||
+ ret = util_parse_octal_uint32("50", &converted);
|
||||
+ ASSERT_EQ(ret, 0);
|
||||
+ ASSERT_EQ(converted, 40);
|
||||
+
|
||||
+ ret = util_parse_octal_uint32("50", nullptr);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_parse_octal_uint32("-1", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_parse_octal_uint32("0", &converted);
|
||||
+ ASSERT_EQ(ret, 0);
|
||||
+ ASSERT_EQ(converted, 0);
|
||||
+
|
||||
+ ret = util_parse_octal_uint32("1.23", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_parse_octal_uint32("1x", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_parse_octal_uint32("40000000000", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+
|
||||
+ ret = util_parse_octal_uint32("nullptr", &converted);
|
||||
+ ASSERT_NE(ret, 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_convert, test_util_uint_to_string)
|
||||
+{
|
||||
+ char *converted;
|
||||
+ long long unsigned int ret;
|
||||
+
|
||||
+ ret = 123456;
|
||||
+ converted = util_uint_to_string(ret);
|
||||
+ ASSERT_STREQ(converted, "123456");
|
||||
+
|
||||
+ ret = 0;
|
||||
+ converted = util_uint_to_string(ret);
|
||||
+ ASSERT_STREQ(converted, "0");
|
||||
+
|
||||
+ ret = ULLONG_MAX;
|
||||
+ converted = util_uint_to_string(ret);
|
||||
+ ASSERT_NE(converted, nullptr);
|
||||
+ ASSERT_STREQ(converted, std::to_string((long long unsigned int)ULLONG_MAX).c_str());
|
||||
+
|
||||
+ ret = -1;
|
||||
+ converted = util_uint_to_string(ret);
|
||||
+ ASSERT_NE(converted, nullptr);
|
||||
+ ASSERT_STREQ(converted, std::to_string((long long unsigned int)ULLONG_MAX).c_str());
|
||||
+}
|
||||
+
|
||||
+TEST(utils_convert, test_util_int_to_string)
|
||||
+{
|
||||
+ char *converted;
|
||||
+ long long int ret;
|
||||
+
|
||||
+ ret = 123456;
|
||||
+ converted = util_int_to_string(ret);
|
||||
+ ASSERT_STREQ(converted, "123456");
|
||||
+
|
||||
+ ret = 0;
|
||||
+ converted = util_int_to_string(ret);
|
||||
+ ASSERT_STREQ(converted, "0");
|
||||
+
|
||||
+ ret = LLONG_MAX;
|
||||
+ converted = util_int_to_string(ret);
|
||||
+ ASSERT_NE(converted, nullptr);
|
||||
+ ASSERT_STREQ(converted, std::to_string((long long)LLONG_MAX).c_str());
|
||||
+
|
||||
+ ret = LLONG_MIN;
|
||||
+ converted = util_int_to_string(ret);
|
||||
+ ASSERT_NE(converted, nullptr);
|
||||
+ ASSERT_STREQ(converted, std::to_string((long long)LLONG_MIN).c_str());
|
||||
+
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
187
0015-Add-ut-for-path.patch
Normal file
187
0015-Add-ut-for-path.patch
Normal file
@ -0,0 +1,187 @@
|
||||
From eb122520ccdcd71dee4e93d3bf9e6c296e3af315 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Mon, 17 Oct 2022 11:43:18 +0800
|
||||
Subject: [PATCH 15/39] Add ut for path
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
test/CMakeLists.txt | 1 -
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/path/CMakeLists.txt | 17 ++++++++
|
||||
test/{ => cutils}/path/path_ut.cc | 70 ++++++++++++++++++++++++++++++-
|
||||
test/path/CMakeLists.txt | 28 -------------
|
||||
5 files changed, 87 insertions(+), 30 deletions(-)
|
||||
create mode 100644 test/cutils/path/CMakeLists.txt
|
||||
rename test/{ => cutils}/path/path_ut.cc (82%)
|
||||
delete mode 100644 test/path/CMakeLists.txt
|
||||
|
||||
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
|
||||
index 034aaf97..92a4e969 100644
|
||||
--- a/test/CMakeLists.txt
|
||||
+++ b/test/CMakeLists.txt
|
||||
@@ -42,7 +42,6 @@ include_directories(${GMOCK_INCLUDE_DIRS})
|
||||
IF(ENABLE_UT)
|
||||
add_subdirectory(cutils)
|
||||
add_subdirectory(image)
|
||||
- add_subdirectory(path)
|
||||
add_subdirectory(cmd)
|
||||
add_subdirectory(runtime)
|
||||
add_subdirectory(specs)
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 9073a68d..00753e64 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -16,6 +16,7 @@ target_include_directories(libutils_ut
|
||||
)
|
||||
|
||||
add_subdirectory(mainloop)
|
||||
+add_subdirectory(path)
|
||||
add_subdirectory(utils_string)
|
||||
add_subdirectory(utils_convert)
|
||||
add_subdirectory(utils_array)
|
||||
diff --git a/test/cutils/path/CMakeLists.txt b/test/cutils/path/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..745258a1
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/path/CMakeLists.txt
|
||||
@@ -0,0 +1,17 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE path_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ path_ut.cc)
|
||||
+
|
||||
+target_include_directories(${EXE} PUBLIC
|
||||
+ ${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
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/../../../src/utils/sha256
|
||||
+ )
|
||||
+set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,getcwd -Wl,--wrap,readlink")
|
||||
+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/path/path_ut.cc b/test/cutils/path/path_ut.cc
|
||||
similarity index 82%
|
||||
rename from test/path/path_ut.cc
|
||||
rename to test/cutils/path/path_ut.cc
|
||||
index 0068ecb4..8601fa07 100644
|
||||
--- a/test/path/path_ut.cc
|
||||
+++ b/test/cutils/path/path_ut.cc
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
- * Copyright (c) Huawei Technologies Co., Ltd. 2019. All rights reserved.
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2019-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:
|
||||
@@ -376,3 +376,71 @@ TEST(path_ut, test_preserve_trailing_dot_or_separator)
|
||||
free(res);
|
||||
res = nullptr;
|
||||
}
|
||||
+
|
||||
+TEST(path_ut, test_split_path_dir_entry)
|
||||
+{
|
||||
+ std::string str;
|
||||
+ char *dir = nullptr;
|
||||
+ char *base = nullptr;
|
||||
+ char **null_dir = nullptr;
|
||||
+
|
||||
+ str = "/home/dir/file";
|
||||
+ ASSERT_EQ(util_split_path_dir_entry(nullptr, &dir, &base), -1);
|
||||
+ ASSERT_EQ(util_split_path_dir_entry(str.c_str(), null_dir, &base), 0);
|
||||
+ ASSERT_EQ(null_dir, nullptr);
|
||||
+
|
||||
+ str = "/home/dir/../file";
|
||||
+ ASSERT_EQ(util_split_path_dir_entry(str.c_str(), &dir, &base), 0);
|
||||
+ ASSERT_NE(dir, nullptr);
|
||||
+ ASSERT_STREQ(dir, "/home");
|
||||
+ ASSERT_NE(base, nullptr);
|
||||
+ ASSERT_STREQ(base, "file");
|
||||
+
|
||||
+ str = "/home/dir/./file";
|
||||
+ ASSERT_EQ(util_split_path_dir_entry(str.c_str(), &dir, &base), 0);
|
||||
+ ASSERT_NE(dir, nullptr);
|
||||
+ ASSERT_STREQ(dir, "/home/dir");
|
||||
+ ASSERT_NE(base, nullptr);
|
||||
+ ASSERT_STREQ(base, "file");
|
||||
+
|
||||
+ str = "./dir/file";
|
||||
+ MOCK_SET_V(getcwd, getcwd_specify);
|
||||
+ ASSERT_EQ(util_split_path_dir_entry(str.c_str(), &dir, &base), 0);
|
||||
+ ASSERT_NE(dir, nullptr);
|
||||
+ ASSERT_STREQ(dir, "/home/dir");
|
||||
+ ASSERT_NE(base, nullptr);
|
||||
+ ASSERT_STREQ(base, "file");
|
||||
+}
|
||||
+
|
||||
+TEST(path_ut, test_realpath_in_scope)
|
||||
+{
|
||||
+ std::string rootfs;
|
||||
+ std::string path;
|
||||
+ char *realpath = nullptr;
|
||||
+ char *null_roofs = nullptr;
|
||||
+
|
||||
+ ASSERT_EQ(util_realpath_in_scope(null_roofs, path.c_str(), &realpath), -1);
|
||||
+
|
||||
+ rootfs = "/home/dir";
|
||||
+ path = "/file";
|
||||
+ ASSERT_EQ(util_realpath_in_scope(rootfs.c_str(), path.c_str(), &realpath), 0);
|
||||
+ ASSERT_NE(realpath, nullptr);
|
||||
+ ASSERT_STREQ(realpath, "/home/dir/file");
|
||||
+
|
||||
+ rootfs = "/home/dir";
|
||||
+ path = "/../file";
|
||||
+ ASSERT_EQ(util_realpath_in_scope(rootfs.c_str(), path.c_str(), &realpath), -1);
|
||||
+
|
||||
+ rootfs = "/home/dir";
|
||||
+ path = "/./file";
|
||||
+ ASSERT_EQ(util_realpath_in_scope(rootfs.c_str(), path.c_str(), &realpath), 0);
|
||||
+ ASSERT_NE(realpath, nullptr);
|
||||
+ ASSERT_STREQ(realpath, "/home/dir/file");
|
||||
+
|
||||
+ rootfs = "";
|
||||
+ path = "./dir/file";
|
||||
+ MOCK_SET_V(getcwd, getcwd_specify);
|
||||
+ ASSERT_EQ(util_realpath_in_scope(rootfs.c_str(), path.c_str(), &realpath), 0);
|
||||
+ ASSERT_NE(realpath, nullptr);
|
||||
+ ASSERT_STREQ(realpath, "/home/dir/file");
|
||||
+}
|
||||
diff --git a/test/path/CMakeLists.txt b/test/path/CMakeLists.txt
|
||||
deleted file mode 100644
|
||||
index dcb69130..00000000
|
||||
--- a/test/path/CMakeLists.txt
|
||||
+++ /dev/null
|
||||
@@ -1,28 +0,0 @@
|
||||
-project(iSulad_UT)
|
||||
-
|
||||
-SET(EXE path_ut)
|
||||
-
|
||||
-add_executable(${EXE}
|
||||
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/utils/cutils/utils.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
|
||||
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/utils/cutils/utils_string.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_regex.c
|
||||
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/utils/cutils/utils_verify.c
|
||||
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/utils/sha256/sha256.c
|
||||
- path_ut.cc)
|
||||
-
|
||||
-target_include_directories(${EXE} PUBLIC
|
||||
- ${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
|
||||
- ${CMAKE_CURRENT_SOURCE_DIR}/../../src/utils/sha256
|
||||
- )
|
||||
-set_target_properties(${EXE} PROPERTIES LINK_FLAGS "-Wl,--wrap,getcwd -Wl,--wrap,readlink")
|
||||
-target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} ${ISULA_LIBUTILS_LIBRARY} -lcrypto -lyajl -lz)
|
||||
-add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
160
0016-Add-ut-for-filters.patch
Normal file
160
0016-Add-ut-for-filters.patch
Normal file
@ -0,0 +1,160 @@
|
||||
From e8b1afc8241200a51b1eab8884fca4bfda286126 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Mon, 17 Oct 2022 11:25:58 +0800
|
||||
Subject: [PATCH 16/39] Add ut for filters
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_filters/CMakeLists.txt | 18 +++
|
||||
test/cutils/utils_filters/utils_filters_ut.cc | 103 ++++++++++++++++++
|
||||
3 files changed, 122 insertions(+)
|
||||
create mode 100644 test/cutils/utils_filters/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_filters/utils_filters_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 00753e64..4e67d9ed 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -27,3 +27,4 @@ add_subdirectory(utils_network)
|
||||
add_subdirectory(utils_aes)
|
||||
add_subdirectory(utils_error)
|
||||
add_subdirectory(utils_fs)
|
||||
+add_subdirectory(utils_filters)
|
||||
diff --git a/test/cutils/utils_filters/CMakeLists.txt b/test/cutils/utils_filters/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..31d3ac25
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_filters/CMakeLists.txt
|
||||
@@ -0,0 +1,18 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_filters_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_filters_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
|
||||
+ )
|
||||
+
|
||||
+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_filters/utils_filters_ut.cc b/test/cutils/utils_filters/utils_filters_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..81a928f9
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_filters/utils_filters_ut.cc
|
||||
@@ -0,0 +1,103 @@
|
||||
+/*
|
||||
+ * 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: filters unit test
|
||||
+ * Author: zhongtao
|
||||
+ * Create: 2022-10-17
|
||||
+ */
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "filters.h"
|
||||
+#include "utils.h"
|
||||
+
|
||||
+TEST(utils_filters, test_filters)
|
||||
+{
|
||||
+ struct filters_args *filters = filters_args_new();
|
||||
+ ASSERT_NE(filters, nullptr);
|
||||
+
|
||||
+ const char *key1_outside = "lable";
|
||||
+ const char *key1_inside = "lable1";
|
||||
+ const char *value1_inside = "1";
|
||||
+ const char *value1_outside = "lable1=1";
|
||||
+ const char *exact_value1_outside = "lable2=2";
|
||||
+ const char *key2_outside = "id";
|
||||
+ const char *value2_outside = "id1=123";
|
||||
+ const char *key3_outside = "patten";
|
||||
+ const char *value3_outside = "^/?[a-zA-Z0-9][a-zA-Z0-9_.-]+$";
|
||||
+ const char *match_patten = "c8da28a6cea7443b648ec70a1c947b6cb920ee0ef3c4a691d4252ff6e1888036";
|
||||
+ const char *unmatch_patten = "#c8da28a6cea7443b648ec70a1c947b6cb920ee0ef3c4a691d4252ff6e1888036";
|
||||
+
|
||||
+ //test filters_args_add
|
||||
+ ASSERT_EQ(filters_args_add(filters, key1_outside, value1_outside), true);
|
||||
+ ASSERT_EQ(filters_args_add(filters, key2_outside, value2_outside), true);
|
||||
+ ASSERT_EQ(filters_args_add(filters, key3_outside, value3_outside), true);
|
||||
+
|
||||
+ ASSERT_EQ(filters_args_add(nullptr, key1_outside, value1_outside), false);
|
||||
+
|
||||
+ //test filters_args_get
|
||||
+ char **value = NULL;
|
||||
+ value = filters_args_get(filters, key2_outside);
|
||||
+ ASSERT_NE(value, nullptr);
|
||||
+ ASSERT_STREQ(*value, value2_outside);
|
||||
+
|
||||
+ value = filters_args_get(nullptr, key1_outside);
|
||||
+ ASSERT_EQ(value, nullptr);
|
||||
+
|
||||
+ // test filters_args_len
|
||||
+ ASSERT_EQ(filters_args_len(nullptr), 0);
|
||||
+ ASSERT_EQ(filters_args_len(filters), 3);
|
||||
+
|
||||
+ //test filters_args_del
|
||||
+ ASSERT_EQ(filters_args_del(filters, key2_outside, value2_outside), true);
|
||||
+ value = filters_args_get(filters, key2_outside);
|
||||
+ ASSERT_EQ(value, nullptr);
|
||||
+
|
||||
+ ASSERT_EQ(filters_args_del(nullptr, key1_outside, value1_outside), false);
|
||||
+
|
||||
+ //test filters_args_match_kv_list
|
||||
+ map_t *source = map_new(MAP_STR_STR, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
|
||||
+ ASSERT_EQ(map_replace(source, (void *)key1_inside, (void *)value1_inside), true);
|
||||
+
|
||||
+ ASSERT_EQ(filters_args_match_kv_list(filters, key1_outside, source), true);
|
||||
+ ASSERT_EQ(filters_args_match_kv_list(filters, key1_outside, nullptr), false);
|
||||
+ ASSERT_EQ(filters_args_match_kv_list(nullptr, key1_outside, source), true);
|
||||
+
|
||||
+ //test filters_args_exact_match
|
||||
+ ASSERT_EQ(filters_args_exact_match(filters, key1_outside, value1_outside), true);
|
||||
+ ASSERT_EQ(filters_args_exact_match(filters, key1_outside, exact_value1_outside), false);
|
||||
+ ASSERT_EQ(filters_args_exact_match(nullptr, key1_outside, exact_value1_outside), true);
|
||||
+ ASSERT_EQ(filters_args_exact_match(filters, key1_outside, nullptr), false);
|
||||
+
|
||||
+ //test filters_args_match
|
||||
+ ASSERT_EQ(filters_args_match(filters, key3_outside, match_patten), true);
|
||||
+ ASSERT_EQ(filters_args_match(filters, key3_outside, unmatch_patten), false);
|
||||
+ ASSERT_EQ(filters_args_match(nullptr, key3_outside, match_patten), true);
|
||||
+ ASSERT_EQ(filters_args_match(filters, key3_outside, nullptr), false);
|
||||
+
|
||||
+ //test filters_args_free
|
||||
+ filters_args_free(nullptr);
|
||||
+ filters_args_free(filters);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_filters, test_filters_args_valid_key)
|
||||
+{
|
||||
+ const char *accepted_filters[] = { "id", "label", "name", NULL };
|
||||
+ const char *valid = "name";
|
||||
+ const char *invalid = "description";
|
||||
+
|
||||
+ ASSERT_EQ(filters_args_valid_key(accepted_filters, sizeof(accepted_filters) / sizeof(char *), valid), true);
|
||||
+ ASSERT_EQ(filters_args_valid_key(accepted_filters, sizeof(accepted_filters) / sizeof(char *), invalid), false);
|
||||
+
|
||||
+ ASSERT_EQ(filters_args_valid_key(accepted_filters, sizeof(accepted_filters) / sizeof(char *), nullptr), false);
|
||||
+ ASSERT_EQ(filters_args_valid_key(nullptr, 3, valid), false);
|
||||
+ ASSERT_EQ(filters_args_valid_key(accepted_filters, 1, valid), false);
|
||||
+ ASSERT_EQ(filters_args_valid_key(accepted_filters, 5, valid), true);
|
||||
+
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
91
0017-add-static-for-unexport-function.patch
Normal file
91
0017-add-static-for-unexport-function.patch
Normal file
@ -0,0 +1,91 @@
|
||||
From 5b7c5fd4d856ad222dc51d79f8cf972730e48a54 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Mon, 17 Oct 2022 14:31:39 +0800
|
||||
Subject: [PATCH 17/39] add static for unexport function
|
||||
|
||||
1. add static for inner function;
|
||||
2. add check for aguments;
|
||||
3. remove same code;
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
src/utils/cutils/utils_timestamp.c | 21 ++++++++++++---------
|
||||
1 file changed, 12 insertions(+), 9 deletions(-)
|
||||
|
||||
diff --git a/src/utils/cutils/utils_timestamp.c b/src/utils/cutils/utils_timestamp.c
|
||||
index c490c00e..85551d51 100644
|
||||
--- a/src/utils/cutils/utils_timestamp.c
|
||||
+++ b/src/utils/cutils/utils_timestamp.c
|
||||
@@ -39,7 +39,7 @@ bool unix_nanos_to_timestamp(int64_t nanos, types_timestamp_t *timestamp)
|
||||
return true;
|
||||
}
|
||||
|
||||
-int types_timestamp_cmp_check(const types_timestamp_t *t1, const types_timestamp_t *t2)
|
||||
+static int types_timestamp_cmp_check(const types_timestamp_t *t1, const types_timestamp_t *t2)
|
||||
{
|
||||
if (t1 == NULL && t2 == NULL) {
|
||||
return 0;
|
||||
@@ -54,7 +54,7 @@ int types_timestamp_cmp_check(const types_timestamp_t *t1, const types_timestamp
|
||||
return 2;
|
||||
}
|
||||
|
||||
-int types_timestamp_cmp_nanos(const types_timestamp_t *t1, const types_timestamp_t *t2)
|
||||
+static int types_timestamp_cmp_nanos(const types_timestamp_t *t1, const types_timestamp_t *t2)
|
||||
{
|
||||
if (t1->has_nanos && t2->has_nanos) {
|
||||
if (t1->nanos > t2->nanos) {
|
||||
@@ -147,7 +147,7 @@ bool util_get_timestamp(const char *str_time, types_timestamp_t *timestamp)
|
||||
return true;
|
||||
}
|
||||
|
||||
-bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer, size_t maxsize, bool local_utc)
|
||||
+static bool get_time_buffer_help(const types_timestamp_t *timestamp, char *timebuffer, size_t maxsize, bool local_utc)
|
||||
{
|
||||
int nret = 0;
|
||||
int tm_zone_hour = 0;
|
||||
@@ -222,6 +222,11 @@ bool util_get_now_time_stamp(types_timestamp_t *timestamp)
|
||||
int err = 0;
|
||||
struct timespec ts;
|
||||
|
||||
+ if (timestamp == NULL) {
|
||||
+ ERROR("Invalid arguments");
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
err = clock_gettime(CLOCK_REALTIME, &ts);
|
||||
if (err != 0) {
|
||||
ERROR("failed to get time");
|
||||
@@ -586,10 +591,11 @@ static bool get_tm_zone_from_str(const char *str, struct tm *tm, int32_t *nanos,
|
||||
char *tmstr = NULL;
|
||||
char *zp = NULL;
|
||||
char *zonestr = NULL;
|
||||
+ bool ret = false;
|
||||
|
||||
if (hasnil(str, tm, nanos, tz)) {
|
||||
ERROR("Get tm and timezone from str input error");
|
||||
- goto err_out;
|
||||
+ return false;
|
||||
}
|
||||
|
||||
tmstr = util_strdup_s(str);
|
||||
@@ -610,15 +616,12 @@ static bool get_tm_zone_from_str(const char *str, struct tm *tm, int32_t *nanos,
|
||||
ERROR("init tz failed");
|
||||
goto err_out;
|
||||
}
|
||||
-
|
||||
- free(tmstr);
|
||||
- free(zonestr);
|
||||
- return true;
|
||||
+ ret = true;
|
||||
|
||||
err_out:
|
||||
free(tmstr);
|
||||
free(zonestr);
|
||||
- return false;
|
||||
+ return ret;
|
||||
}
|
||||
|
||||
static int64_t get_minmus_time(struct tm *tm1, struct tm *tm2)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
296
0018-add-ut-for-cutils-timestamp.patch
Normal file
296
0018-add-ut-for-cutils-timestamp.patch
Normal file
@ -0,0 +1,296 @@
|
||||
From 725f5813ee3125ad3c55dfbe3aeb5d8155e93e8f Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Mon, 17 Oct 2022 20:16:58 +0800
|
||||
Subject: [PATCH 18/39] add ut for cutils timestamp
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_timestamp/CMakeLists.txt | 16 ++
|
||||
.../utils_timestamp/utils_timestamp_ut.cc | 241 ++++++++++++++++++
|
||||
3 files changed, 258 insertions(+)
|
||||
create mode 100644 test/cutils/utils_timestamp/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_timestamp/utils_timestamp_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 4e67d9ed..7f454f75 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -28,3 +28,4 @@ add_subdirectory(utils_aes)
|
||||
add_subdirectory(utils_error)
|
||||
add_subdirectory(utils_fs)
|
||||
add_subdirectory(utils_filters)
|
||||
+add_subdirectory(utils_timestamp)
|
||||
diff --git a/test/cutils/utils_timestamp/CMakeLists.txt b/test/cutils/utils_timestamp/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..38aec640
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_timestamp/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_timestamp_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_timestamp_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_timestamp/utils_timestamp_ut.cc b/test/cutils/utils_timestamp/utils_timestamp_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..d6756e3a
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_timestamp/utils_timestamp_ut.cc
|
||||
@@ -0,0 +1,241 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: haozi007
|
||||
+ * Create: 2022-10-13
|
||||
+ * Description: utils timestamp unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils_timestamp.h"
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_types_timestamp_cmp)
|
||||
+{
|
||||
+ types_timestamp_t t1 = { 0 };
|
||||
+ types_timestamp_t t2 = { 0 };
|
||||
+
|
||||
+ // t1 == t2
|
||||
+ ASSERT_EQ(util_types_timestamp_cmp(&t1, &t2), 0);
|
||||
+
|
||||
+ t1.has_seconds = true;
|
||||
+ t1.seconds = 2;
|
||||
+ t1.has_nanos = false;
|
||||
+ t1.nanos = 0;
|
||||
+ t2.has_seconds = false;
|
||||
+ t2.seconds = 0;
|
||||
+ t2.has_nanos = false;
|
||||
+ t2.nanos = 100;
|
||||
+ // t1 > t2
|
||||
+ ASSERT_EQ(util_types_timestamp_cmp(&t1, &t2), 1);
|
||||
+
|
||||
+ t1.has_seconds = false;
|
||||
+ t1.seconds = 2;
|
||||
+ t1.has_nanos = false;
|
||||
+ t1.nanos = 0;
|
||||
+ t2.has_seconds = true;
|
||||
+ t2.seconds = 1;
|
||||
+ t2.has_nanos = true;
|
||||
+ t2.nanos = 100;
|
||||
+ // t1 < t2
|
||||
+ ASSERT_EQ(util_types_timestamp_cmp(&t1, &t2), -1);
|
||||
+
|
||||
+ t1.has_seconds = true;
|
||||
+ t1.seconds = 2;
|
||||
+ t1.has_nanos = false;
|
||||
+ t1.nanos = 0;
|
||||
+ t2.has_seconds = true;
|
||||
+ t2.seconds = 2;
|
||||
+ t2.has_nanos = false;
|
||||
+ t2.nanos = 0;
|
||||
+ // t1 == t2
|
||||
+ ASSERT_EQ(util_types_timestamp_cmp(&t1, &t2), 0);
|
||||
+
|
||||
+ t1.has_nanos = true;
|
||||
+ t1.nanos = 88;
|
||||
+ t2.has_nanos = true;
|
||||
+ t2.nanos = 88;
|
||||
+ // t1 == t2
|
||||
+ ASSERT_EQ(util_types_timestamp_cmp(&t1, &t2), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_get_timestamp)
|
||||
+{
|
||||
+ types_timestamp_t t = { 0 };
|
||||
+ std::string invalid_str = "1970-01-02X:00:xx";
|
||||
+ std::string dstr1 = "1970-01-01T00:00:01.000000800";
|
||||
+ struct tm tm_local = { 0 };
|
||||
+ const time_t now_time = time(NULL);
|
||||
+ long int tm_gmtoff = 0;
|
||||
+
|
||||
+ (void)localtime_r(&now_time, &tm_local);
|
||||
+#ifdef __USE_MISC
|
||||
+ tm_gmtoff = tm_local.tm_gmtoff;
|
||||
+#else
|
||||
+ tm_gmtoff = tm_local.__tm_gmtoff;
|
||||
+#endif
|
||||
+
|
||||
+ ASSERT_EQ(util_get_timestamp(dstr1.c_str(), &t), true);
|
||||
+ t.seconds += tm_gmtoff;
|
||||
+ ASSERT_EQ(t.has_seconds, true);
|
||||
+ ASSERT_EQ(t.seconds, 1);
|
||||
+ ASSERT_EQ(t.has_nanos, true);
|
||||
+ ASSERT_EQ(t.nanos, 800);
|
||||
+
|
||||
+ // invalid agruments check
|
||||
+ ASSERT_EQ(util_get_timestamp(nullptr, &t), false);
|
||||
+ ASSERT_EQ(util_get_timestamp(dstr1.c_str(), nullptr), false);
|
||||
+ ASSERT_EQ(util_get_timestamp(invalid_str.c_str(), nullptr), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_get_now_local_utc_time_buffer)
|
||||
+{
|
||||
+ char local_time[128] = { 0 };
|
||||
+
|
||||
+ ASSERT_EQ(util_get_now_local_utc_time_buffer(local_time, 128), true);
|
||||
+ ASSERT_EQ(util_get_now_local_utc_time_buffer(nullptr, 0), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_get_time_interval)
|
||||
+{
|
||||
+ types_timestamp_t t1 = { 0 };
|
||||
+ types_timestamp_t t2 = { 0 };
|
||||
+ int64_t ret = 0;
|
||||
+
|
||||
+ ASSERT_EQ(util_get_time_interval(t1, t2, &ret), 0);
|
||||
+ ASSERT_EQ(ret, 0);
|
||||
+
|
||||
+ t2.has_seconds = true;
|
||||
+ t2.seconds = 8;
|
||||
+ t2.has_nanos = true;
|
||||
+ t2.nanos = 8;
|
||||
+ ASSERT_EQ(util_get_time_interval(t1, t2, &ret), 0);
|
||||
+ ASSERT_EQ(ret, 8000000008);
|
||||
+
|
||||
+ t2.has_seconds = true;
|
||||
+ t2.seconds = INT64_MAX;
|
||||
+ t2.has_nanos = false;
|
||||
+ t2.nanos = 0;
|
||||
+ ASSERT_NE(util_get_time_interval(t1, t2, &ret), 0);
|
||||
+
|
||||
+ t2.seconds = INT64_MAX - 1;
|
||||
+ t2.has_nanos = true;
|
||||
+ t2.nanos = 100;
|
||||
+ ASSERT_NE(util_get_time_interval(t1, t2, &ret), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_get_tm_from_str)
|
||||
+{
|
||||
+ std::string invalid_str = "2016-01-02T15:04:01:03";
|
||||
+
|
||||
+ std::vector<std::tuple<std::string, int, int, int, int, int, int, int>> cases = {
|
||||
+ std::make_tuple("1970-01-01T01", 0, 0, 0, 1, 1, 0, 70),
|
||||
+ std::make_tuple("1980-02-02T02:02", 0, 0, 2, 2, 2, 1, 80),
|
||||
+ std::make_tuple("1990-03-03T03:03:03", 0, 3, 3, 3, 3, 2, 90),
|
||||
+ };
|
||||
+
|
||||
+ for (const auto &cs : cases) {
|
||||
+ struct tm got = { 0 };
|
||||
+ int32_t nano = 0;
|
||||
+ ASSERT_EQ(util_get_tm_from_str(std::get<0>(elem).c_str(), &got, &nano), true);
|
||||
+ ASSERT_EQ(nano, std::get<1>(elem));
|
||||
+ ASSERT_EQ(got.tm_sec, std::get<2>(elem));
|
||||
+ ASSERT_EQ(got.tm_min, std::get<3>(elem));
|
||||
+ ASSERT_EQ(got.tm_hour, std::get<4>(elem));
|
||||
+ ASSERT_EQ(got.tm_mday, std::get<5>(elem));
|
||||
+ ASSERT_EQ(got.tm_mon, std::get<6>(elem));
|
||||
+ ASSERT_EQ(got.tm_year, std::get<7>(elem));
|
||||
+ }
|
||||
+
|
||||
+ // check invalid cases
|
||||
+ ASSERT_NE(util_get_tm_from_str(invalid_str.c_str(), &got, &nano), true);
|
||||
+ ASSERT_NE(util_get_tm_from_str(nullptr, &got, &nano), true);
|
||||
+ ASSERT_NE(util_get_tm_from_str(invalid_str.c_str(), nullptr, &nano), true);
|
||||
+ ASSERT_NE(util_get_tm_from_str(invalid_str.c_str(), &got, nullptr), true);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_time_seconds_since)
|
||||
+{
|
||||
+ std::string defaultstr = "-";
|
||||
+ std::string invalid_str = "2016-01-02T15:04:01:03";
|
||||
+ std::string dstr1 = "1990-03-03T03:03:03";
|
||||
+ types_timestamp_t currt = { 0 };
|
||||
+ char tbuf[128] = { 0 };
|
||||
+ int64_t ret;
|
||||
+
|
||||
+ ASSERT_EQ(util_get_now_time_stamp(&currt), true);
|
||||
+ currt.seconds -= 10;
|
||||
+ ASSERT_EQ(util_get_time_buffer(&currt, tbuf, 128), true);
|
||||
+ ret = util_time_seconds_since(tbuf);
|
||||
+ ASSERT_GE(ret, 9);
|
||||
+ ASSERT_LE(ret, 11);
|
||||
+
|
||||
+ ASSERT_EQ(util_time_seconds_since(dstr1.c_str()), 0);
|
||||
+
|
||||
+ // invalid cases
|
||||
+ ASSERT_EQ(util_time_seconds_since(invalid_str.c_str()), 0);
|
||||
+ ASSERT_EQ(util_time_seconds_since(nullptr), 0);
|
||||
+ ASSERT_EQ(util_time_seconds_since(defaultContainerTime), 0);
|
||||
+ ASSERT_EQ(util_time_seconds_since(defaultstr.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_time_format_duration)
|
||||
+{
|
||||
+ std::string invalid_str = "2016-01-02T15:04:01:03";
|
||||
+ std::string dstr3 = "1990-03-03T03:03:03.000000000+08:00";
|
||||
+ std::string defaultstr = "-";
|
||||
+ char out[128] = { 0 };
|
||||
+
|
||||
+ ASSERT_EQ(util_time_format_duration(dstr3.c_str(), out, 128), 0);
|
||||
+
|
||||
+ // invalid cases
|
||||
+ ASSERT_EQ(util_time_format_duration(invalid_str.c_str(), out, 128), 1);
|
||||
+ ASSERT_EQ(util_time_format_duration(nullptr, out, 128), 1);
|
||||
+ ASSERT_EQ(util_time_format_duration(defaultContainerTime, out, 128), 1);
|
||||
+ ASSERT_EQ(util_time_format_duration(defaultstr.c_str(), out, 128), 1);
|
||||
+ ASSERT_EQ(util_time_format_duration(invalid_str.c_str(), out, 0), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_to_unix_nanos_from_str)
|
||||
+{
|
||||
+ std::string invalid_str = "2016-01-02T15:04:01:03";
|
||||
+ std::string dstr3 = "1970-01-01T00:00:01.0+00:00";
|
||||
+ int64_t ret = 0;
|
||||
+
|
||||
+ ASSERT_EQ(util_to_unix_nanos_from_str(dstr3.c_str(), &ret), 0);
|
||||
+ ASSERT_EQ(ret, 1000000000);
|
||||
+
|
||||
+ // invalid cases
|
||||
+ ASSERT_NE(util_to_unix_nanos_from_str(invalid_str.c_str(), &ret), 0);
|
||||
+ ASSERT_EQ(util_to_unix_nanos_from_str(nullptr, &ret), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_timestamp, test_util_time_str_to_nanoseconds)
|
||||
+{
|
||||
+ int64_t ret = 0;
|
||||
+ std::string invalid_str = "xxxxxxx";
|
||||
+ std::string dstr2 = "1ms";
|
||||
+ std::string dstr3 = "2s";
|
||||
+ std::string dstr4 = "1m";
|
||||
+ std::string dstr5 = "1h";
|
||||
+
|
||||
+ ASSERT_EQ(util_time_str_to_nanoseconds(dstr2.c_str(), &ret), 0);
|
||||
+ ASSERT_EQ(ret, Time_Milli);
|
||||
+ ASSERT_EQ(util_time_str_to_nanoseconds(dstr3.c_str(), &ret), 0);
|
||||
+ ASSERT_EQ(ret, 2 * Time_Second);
|
||||
+ ASSERT_EQ(util_time_str_to_nanoseconds(dstr4.c_str(), &ret), 0);
|
||||
+ ASSERT_EQ(ret, 60 * Time_Second);
|
||||
+ ASSERT_EQ(util_time_str_to_nanoseconds(dstr5.c_str(), &ret), 0);
|
||||
+ ASSERT_EQ(ret, 3600 * Time_Second);
|
||||
+
|
||||
+ // invalid cases
|
||||
+ ASSERT_NE(util_time_str_to_nanoseconds(invalid_str.c_str(), &ret), 0);
|
||||
+ ASSERT_NE(util_time_str_to_nanoseconds(nullptr, &ret), 0);
|
||||
+ ASSERT_NE(util_time_str_to_nanoseconds(dstr3.c_str(), nullptr), 0);
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
37
0019-fix-timestamp-ut-error.patch
Normal file
37
0019-fix-timestamp-ut-error.patch
Normal file
@ -0,0 +1,37 @@
|
||||
From e437396ff5bc90bfa3736e0ef06be117bca4b174 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Tue, 18 Oct 2022 10:23:34 +0800
|
||||
Subject: [PATCH 19/39] fix timestamp ut error
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
test/cutils/utils_timestamp/utils_timestamp_ut.cc | 6 +++---
|
||||
1 file changed, 3 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/test/cutils/utils_timestamp/utils_timestamp_ut.cc b/test/cutils/utils_timestamp/utils_timestamp_ut.cc
|
||||
index d6756e3a..0f6b80f6 100644
|
||||
--- a/test/cutils/utils_timestamp/utils_timestamp_ut.cc
|
||||
+++ b/test/cutils/utils_timestamp/utils_timestamp_ut.cc
|
||||
@@ -133,6 +133,8 @@ TEST(utils_timestamp, test_util_get_time_interval)
|
||||
TEST(utils_timestamp, test_util_get_tm_from_str)
|
||||
{
|
||||
std::string invalid_str = "2016-01-02T15:04:01:03";
|
||||
+ struct tm got = { 0 };
|
||||
+ int32_t nano = 0;
|
||||
|
||||
std::vector<std::tuple<std::string, int, int, int, int, int, int, int>> cases = {
|
||||
std::make_tuple("1970-01-01T01", 0, 0, 0, 1, 1, 0, 70),
|
||||
@@ -140,9 +142,7 @@ TEST(utils_timestamp, test_util_get_tm_from_str)
|
||||
std::make_tuple("1990-03-03T03:03:03", 0, 3, 3, 3, 3, 2, 90),
|
||||
};
|
||||
|
||||
- for (const auto &cs : cases) {
|
||||
- struct tm got = { 0 };
|
||||
- int32_t nano = 0;
|
||||
+ for (const auto &elem : cases) {
|
||||
ASSERT_EQ(util_get_tm_from_str(std::get<0>(elem).c_str(), &got, &nano), true);
|
||||
ASSERT_EQ(nano, std::get<1>(elem));
|
||||
ASSERT_EQ(got.tm_sec, std::get<2>(elem));
|
||||
--
|
||||
2.25.1
|
||||
|
||||
45
0020-improve-code-in-utils_mount_spec.patch
Normal file
45
0020-improve-code-in-utils_mount_spec.patch
Normal file
@ -0,0 +1,45 @@
|
||||
From 99df201139e1afbc719f78bae047eaf826676b7f Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Mon, 17 Oct 2022 20:20:00 +0800
|
||||
Subject: [PATCH 20/39] improve code in utils_mount_spec
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
src/utils/cutils/utils_mount_spec.c | 16 ++++++++++++----
|
||||
1 file changed, 12 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/utils/cutils/utils_mount_spec.c b/src/utils/cutils/utils_mount_spec.c
|
||||
index d8f64c81..e9b23cf2 100644
|
||||
--- a/src/utils/cutils/utils_mount_spec.c
|
||||
+++ b/src/utils/cutils/utils_mount_spec.c
|
||||
@@ -458,15 +458,23 @@ int util_parse_mount_spec(char *mount_str, mount_spec **spec, char **errmsg_out)
|
||||
|
||||
if (mount_str == NULL) {
|
||||
CACHE_ERRMSG(errmsg, "Invalid mount specification: can't be empty");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
+ return -1;
|
||||
}
|
||||
if (!mount_str[0]) {
|
||||
CACHE_ERRMSG(errmsg, "Invalid mount specification: can't be empty");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
+ if(spec == NULL){
|
||||
+ CACHE_ERRMSG(errmsg, "Invalid spec: can't be NULL");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if(errmsg_out == NULL){
|
||||
+ CACHE_ERRMSG(errmsg, "Invalid errmsg_out: can't be NULL");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
m = util_common_calloc_s(sizeof(mount_spec));
|
||||
if (m == NULL) {
|
||||
CACHE_ERRMSG(errmsg, "out of memory");
|
||||
--
|
||||
2.25.1
|
||||
|
||||
118
0021-Add-ut-for-utils_mount_spec.patch
Normal file
118
0021-Add-ut-for-utils_mount_spec.patch
Normal file
@ -0,0 +1,118 @@
|
||||
From 7e4921d01576f180c3624195a0edff4b4f6807f8 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Tue, 18 Oct 2022 10:46:14 +0800
|
||||
Subject: [PATCH 21/39] Add ut for utils_mount_spec
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_mount_spec/CMakeLists.txt | 16 +++++
|
||||
.../utils_mount_spec/utils_mount_spec_ut.cc | 64 +++++++++++++++++++
|
||||
3 files changed, 81 insertions(+)
|
||||
create mode 100644 test/cutils/utils_mount_spec/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_mount_spec/utils_mount_spec_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 7f454f75..f159aacb 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -29,3 +29,4 @@ add_subdirectory(utils_error)
|
||||
add_subdirectory(utils_fs)
|
||||
add_subdirectory(utils_filters)
|
||||
add_subdirectory(utils_timestamp)
|
||||
+add_subdirectory(utils_mount_spec)
|
||||
diff --git a/test/cutils/utils_mount_spec/CMakeLists.txt b/test/cutils/utils_mount_spec/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..24fb5add
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_mount_spec/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_mount_spec_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_mount_spec_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_mount_spec/utils_mount_spec_ut.cc b/test/cutils/utils_mount_spec/utils_mount_spec_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..0f60d397
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_mount_spec/utils_mount_spec_ut.cc
|
||||
@@ -0,0 +1,64 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: zhongtao
|
||||
+ * Create: 2022-10-18
|
||||
+ * Description: utils mount spec unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils_mount_spec.h"
|
||||
+
|
||||
+TEST(utils_mount_spec, test_util_valid_mount_spec)
|
||||
+{
|
||||
+ char *base_valid = (char *)"type=bind,source=/home,target=/vol3,readonly=true,bind-selinux-opts=z,bind-propagation=rprivate";
|
||||
+ char *oci_valid = (char *)"type=tmpfs,dst=/tmpfs,tmpfs-size=1m,tmpfs-mode=1700";
|
||||
+ char *invalid1 = (char *)"type=volume,src=vol,dst=/vol,ro=true,red=false";
|
||||
+ char *invalid2 = (char *)"type,src,dst";
|
||||
+ char *errmsg = NULL;
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_mount_spec(base_valid, &errmsg), true);
|
||||
+ ASSERT_EQ(util_valid_mount_spec(oci_valid, &errmsg), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_mount_spec(invalid1, &errmsg), false);
|
||||
+ ASSERT_EQ(util_valid_mount_spec(invalid2, &errmsg), false);
|
||||
+ ASSERT_EQ(util_valid_mount_spec(nullptr, &errmsg), false);
|
||||
+ ASSERT_EQ(util_valid_mount_spec(base_valid, nullptr), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_mount_spec, test_util_parse_mount_spec)
|
||||
+{
|
||||
+ char *base_valid = (char *)"type=bind,source=/home,target=/vol3,readonly=true,bind-selinux-opts=z,bind-propagation=rprivate";
|
||||
+ char *oci_valid = (char *)"type=tmpfs,dst=/tmpfs,tmpfs-size=1m,tmpfs-mode=1700";
|
||||
+ char *invalid1 = (char *)"type=volume,src=vol,dst=/vol,ro=true,red=false";
|
||||
+ char *invalid2 = (char *)"type,src,dst";
|
||||
+ mount_spec *m = NULL;
|
||||
+ char *errmsg = NULL;
|
||||
+
|
||||
+ ASSERT_EQ(util_parse_mount_spec(base_valid, &m, &errmsg), 0);
|
||||
+ ASSERT_STREQ(m->type, "bind");
|
||||
+ ASSERT_STREQ(m->source, "/home");
|
||||
+ ASSERT_STREQ(m->target, "/vol3");
|
||||
+ ASSERT_EQ(m->readonly, true);
|
||||
+ ASSERT_STREQ(m->bind_options->propagation, "rprivate");
|
||||
+ ASSERT_STREQ(m->bind_options->selinux_opts, "z");
|
||||
+
|
||||
+ ASSERT_EQ(util_parse_mount_spec(oci_valid, &m, &errmsg), 0);
|
||||
+ ASSERT_STREQ(m->type, "tmpfs");
|
||||
+ ASSERT_STREQ(m->target, "/tmpfs");
|
||||
+ ASSERT_EQ(m->tmpfs_options->size_bytes, 1048576);
|
||||
+ ASSERT_EQ(m->tmpfs_options->mode, 960);
|
||||
+
|
||||
+ ASSERT_NE(util_parse_mount_spec(invalid1, &m, &errmsg), 0);
|
||||
+ ASSERT_NE(util_parse_mount_spec(invalid2, &m, &errmsg), 0);
|
||||
+ ASSERT_NE(util_parse_mount_spec(nullptr, &m, &errmsg), 0);
|
||||
+ ASSERT_NE(util_parse_mount_spec(base_valid, nullptr, &errmsg), 0);
|
||||
+ ASSERT_NE(util_parse_mount_spec(base_valid, &m, nullptr), 0);
|
||||
+}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
100
0022-Add-ut-for-utils_regex.patch
Normal file
100
0022-Add-ut-for-utils_regex.patch
Normal file
@ -0,0 +1,100 @@
|
||||
From e43af2dc017a63a772c7dea2583d7d58506d7608 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Tue, 18 Oct 2022 11:50:37 +0800
|
||||
Subject: [PATCH 22/39] Add ut for utils_regex
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_regex/CMakeLists.txt | 16 ++++++++
|
||||
test/cutils/utils_regex/utils_regex_ut.cc | 46 +++++++++++++++++++++++
|
||||
3 files changed, 63 insertions(+)
|
||||
create mode 100644 test/cutils/utils_regex/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_regex/utils_regex_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index f159aacb..4b235a09 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -30,3 +30,4 @@ add_subdirectory(utils_fs)
|
||||
add_subdirectory(utils_filters)
|
||||
add_subdirectory(utils_timestamp)
|
||||
add_subdirectory(utils_mount_spec)
|
||||
+add_subdirectory(utils_regex)
|
||||
diff --git a/test/cutils/utils_regex/CMakeLists.txt b/test/cutils/utils_regex/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..3f6410b2
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_regex/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_regex_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_regex_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_regex/utils_regex_ut.cc b/test/cutils/utils_regex/utils_regex_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..1b4414de
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_regex/utils_regex_ut.cc
|
||||
@@ -0,0 +1,46 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: zhongtao
|
||||
+ * Create: 2022-10-18
|
||||
+ * Description: utils regex unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils_regex.h"
|
||||
+
|
||||
+TEST(utils_regex, test_util_reg_match)
|
||||
+{
|
||||
+ const char *pattern = "^[a-f0-9]{64}$";
|
||||
+ const char *valid = "c8da28a6cea7443b648ec70a1c947b6cb920ee0ef3c4a691d4252ff6e1888036";
|
||||
+ const char *invalid = "g8da28a6cea7443b648ec70a1c947b6cb920ee0ef3c4a691d4252ff6e1888036";
|
||||
+
|
||||
+ ASSERT_EQ(util_reg_match(pattern, valid), 0);
|
||||
+ ASSERT_EQ(util_reg_match(pattern, invalid), 1);
|
||||
+
|
||||
+ ASSERT_EQ(util_reg_match(pattern, nullptr), -1);
|
||||
+ ASSERT_EQ(util_reg_match(nullptr, pattern), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_regex, test_util_wildcard_to_regex)
|
||||
+{
|
||||
+ std::string wildcard = "*hello?";
|
||||
+ char *value = NULL;
|
||||
+
|
||||
+ ASSERT_EQ(util_wildcard_to_regex(wildcard.c_str(), &value), 0);
|
||||
+ ASSERT_STREQ(value, "^.*hello.$");
|
||||
+
|
||||
+ wildcard = "file{1,2,3}";
|
||||
+ ASSERT_EQ(util_wildcard_to_regex(wildcard.c_str(), &value), 0);
|
||||
+ ASSERT_STREQ(value, "^file\\{1,2,3\\}$");
|
||||
+
|
||||
+ ASSERT_EQ(util_wildcard_to_regex(nullptr, &value), -1);
|
||||
+ ASSERT_EQ(util_wildcard_to_regex(wildcard.c_str(), nullptr), -1);
|
||||
+}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
164
0023-improve-code-in-utils.c.patch
Normal file
164
0023-improve-code-in-utils.c.patch
Normal file
@ -0,0 +1,164 @@
|
||||
From 60ef94806076e728b6f76d5b9b874e375182233c Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Tue, 18 Oct 2022 15:47:36 +0800
|
||||
Subject: [PATCH 23/39] improve code in utils.c
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
src/utils/cutils/utils.c | 60 ++++++++++++++++++++++------------------
|
||||
1 file changed, 33 insertions(+), 27 deletions(-)
|
||||
|
||||
diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c
|
||||
index e362581b..eddfda5c 100644
|
||||
--- a/src/utils/cutils/utils.c
|
||||
+++ b/src/utils/cutils/utils.c
|
||||
@@ -64,13 +64,13 @@ int util_mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize
|
||||
void *tmp = NULL;
|
||||
|
||||
if (newptr == NULL || newsize == 0) {
|
||||
- goto err_out;
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
tmp = util_common_calloc_s(newsize);
|
||||
if (tmp == NULL) {
|
||||
ERROR("Failed to malloc memory");
|
||||
- goto err_out;
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
if (oldptr != NULL) {
|
||||
@@ -82,9 +82,6 @@ int util_mem_realloc(void **newptr, size_t newsize, void *oldptr, size_t oldsize
|
||||
|
||||
*newptr = tmp;
|
||||
return 0;
|
||||
-
|
||||
-err_out:
|
||||
- return -1;
|
||||
}
|
||||
|
||||
static int util_read_pipe(int pipe_fd, char **out_buf, size_t *out_buf_size, size_t *out_real_size)
|
||||
@@ -353,8 +350,6 @@ void util_contain_errmsg(const char *errmsg, int *exit_code)
|
||||
} else if (strcasestr(errmsg, "not a directory")) {
|
||||
*exit_code = 127;
|
||||
}
|
||||
-
|
||||
- return;
|
||||
}
|
||||
|
||||
char *util_short_digest(const char *digest)
|
||||
@@ -818,6 +813,9 @@ bool util_exec_cmd(exec_func_t cb_func, void *args, const char *stdin_msg, char
|
||||
close(in_fd[1]);
|
||||
in_fd[1] = -1;
|
||||
|
||||
+ if (stdout_msg == NULL) {
|
||||
+ stdout_close_flag = 1;
|
||||
+ }
|
||||
for (;;) {
|
||||
if (stdout_close_flag == 0) {
|
||||
stdout_close_flag = util_read_pipe(out_fd[0], &stdout_buffer, &stdout_buf_size, &stdout_real_size);
|
||||
@@ -840,8 +838,14 @@ bool util_exec_cmd(exec_func_t cb_func, void *args, const char *stdin_msg, char
|
||||
close(err_fd[0]);
|
||||
close(out_fd[0]);
|
||||
out:
|
||||
- *stdout_msg = stdout_buffer;
|
||||
- *stderr_msg = stderr_buffer;
|
||||
+ if (stdout_msg != NULL) {
|
||||
+ *stdout_msg = stdout_buffer;
|
||||
+ }
|
||||
+ if (stderr_msg != NULL) {
|
||||
+ *stderr_msg = stderr_buffer;
|
||||
+ } else {
|
||||
+ free(stderr_buffer);
|
||||
+ }
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -947,8 +951,8 @@ int util_env_insert(char ***penv, size_t *penv_len, const char *key, size_t key_
|
||||
env = *penv;
|
||||
env_len = *penv_len;
|
||||
|
||||
- if (env_len > (SIZE_MAX / sizeof(char *)) - 1) {
|
||||
- ERROR("Failed to realloc memory for envionment variables");
|
||||
+ if (env_len > (MAX_MEMORY_SIZE / sizeof(char *)) - 1) {
|
||||
+ ERROR("Too large envionment variables");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -1108,7 +1112,7 @@ static int set_echo_back(bool echo_back)
|
||||
return 0;
|
||||
}
|
||||
|
||||
-int util_input_notty(char *buf, size_t maxlen)
|
||||
+static int util_input_notty(char *buf, size_t maxlen)
|
||||
{
|
||||
size_t i = 0;
|
||||
int ret = 0;
|
||||
@@ -1424,9 +1428,9 @@ int util_read_pid_ppid_info(uint32_t pid, pid_ppid_info_t *pid_info)
|
||||
proc_t *proc = NULL;
|
||||
proc_t *p_proc = NULL;
|
||||
|
||||
- if (pid == 0) {
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
+ if (pid == 0 || pid_info == NULL) {
|
||||
+ ERROR("Invalid arguments");
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
proc = util_get_process_proc_info((pid_t)pid);
|
||||
@@ -1506,8 +1510,8 @@ defs_map_string_object *dup_map_string_empty_object(defs_map_string_object *src)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
- dst->keys = util_common_calloc_s(src->len * sizeof(char *));
|
||||
- dst->values = util_common_calloc_s(src->len * sizeof(defs_map_string_object_element *));
|
||||
+ dst->keys = util_smart_calloc_s(sizeof(char *), src->len);
|
||||
+ dst->values = util_smart_calloc_s(sizeof(defs_map_string_object_element *), src->len);
|
||||
if (dst->keys == NULL || dst->values == NULL) {
|
||||
ERROR("Out of memory");
|
||||
ret = -1;
|
||||
@@ -1538,12 +1542,16 @@ int convert_v2_runtime(const char *runtime, char *binary)
|
||||
size_t parts_len = 0;
|
||||
char buf[PATH_MAX] = {0};
|
||||
int ret = 0;
|
||||
+ int nret;
|
||||
+
|
||||
+ if (binary == NULL) {
|
||||
+ return -1;
|
||||
+ }
|
||||
|
||||
parts = util_string_split_multi(runtime, '.');
|
||||
if (parts == NULL) {
|
||||
ERROR("split failed: %s", runtime);
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
parts_len = util_array_len((const char **)parts);
|
||||
@@ -1553,15 +1561,13 @@ int convert_v2_runtime(const char *runtime, char *binary)
|
||||
goto out;
|
||||
}
|
||||
|
||||
- if (binary != NULL) {
|
||||
- int nret = snprintf(buf, sizeof(buf), "%s-%s-%s-%s", "containerd", "shim", parts[2], parts[3]);
|
||||
- if (nret < 0 || (size_t)nret >= sizeof(buf)) {
|
||||
- ERROR("Failed to snprintf string");
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
- strcpy(binary, buf);
|
||||
+ nret = snprintf(buf, sizeof(buf), "%s-%s-%s-%s", "containerd", "shim", parts[2], parts[3]);
|
||||
+ if (nret < 0 || (size_t)nret >= sizeof(buf)) {
|
||||
+ ERROR("Failed to snprintf string");
|
||||
+ ret = -1;
|
||||
+ goto out;
|
||||
}
|
||||
+ (void)strcpy(binary, buf);
|
||||
|
||||
out:
|
||||
util_free_array(parts);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
327
0024-add-ut-for-cutils-utils.patch
Normal file
327
0024-add-ut-for-cutils-utils.patch
Normal file
@ -0,0 +1,327 @@
|
||||
From fef883b9716bf8b71dd10152d9dea1b4e6952530 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Tue, 18 Oct 2022 17:11:04 +0800
|
||||
Subject: [PATCH 24/39] add ut for cutils utils
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_utils/CMakeLists.txt | 16 ++
|
||||
test/cutils/utils_utils/utils_utils_ut.cc | 272 ++++++++++++++++++++++
|
||||
3 files changed, 289 insertions(+)
|
||||
create mode 100644 test/cutils/utils_utils/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_utils/utils_utils_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 4b235a09..23426015 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -31,3 +31,4 @@ add_subdirectory(utils_filters)
|
||||
add_subdirectory(utils_timestamp)
|
||||
add_subdirectory(utils_mount_spec)
|
||||
add_subdirectory(utils_regex)
|
||||
+add_subdirectory(utils_utils)
|
||||
diff --git a/test/cutils/utils_utils/CMakeLists.txt b/test/cutils/utils_utils/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..7b3bd546
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_utils/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_utils_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_utils_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_utils/utils_utils_ut.cc b/test/cutils/utils_utils/utils_utils_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..531947d2
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_utils/utils_utils_ut.cc
|
||||
@@ -0,0 +1,272 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: haozi007
|
||||
+ * Create: 2022-10-18
|
||||
+ * Description: utils unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils.h"
|
||||
+
|
||||
+TEST(utils_utils, test_util_mem_realloc)
|
||||
+{
|
||||
+ char *old = nullptr;
|
||||
+ ASSERT_EQ(util_mem_realloc(nullptr, 0, old, 0), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_sig_parse)
|
||||
+{
|
||||
+ std::string num_str = "9";
|
||||
+ std::string sig_str = "SIGSEGV";
|
||||
+ std::string sig_only = "SEGV";
|
||||
+
|
||||
+ ASSERT_EQ(util_sig_parse(nullptr), -1);
|
||||
+ ASSERT_EQ(util_sig_parse(num_str.c_str()), 9);
|
||||
+ ASSERT_EQ(util_sig_parse(sig_str.c_str()), 11);
|
||||
+ ASSERT_EQ(util_sig_parse(sig_str.c_str()), 11);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_contain_errmsg)
|
||||
+{
|
||||
+ int exit_code = 0;
|
||||
+ std::string teststr = "hello world";
|
||||
+ std::vector<std::tuple<std::string, int>> cases = {
|
||||
+ std::make_tuple("executable file not found", 127),
|
||||
+ std::make_tuple("no such file or directory", 127),
|
||||
+ std::make_tuple("system cannot find the file specified", 127),
|
||||
+ std::make_tuple("permission denied", 126),
|
||||
+ std::make_tuple("not a directory", 127),
|
||||
+ };
|
||||
+
|
||||
+ for (const auto &elem : cases) {
|
||||
+ util_contain_errmsg(std::get<0>(elem).c_str(), &exit_code);
|
||||
+ ASSERT_EQ(exit_code, std::get<1>(elem));
|
||||
+ }
|
||||
+
|
||||
+ // invalid cases
|
||||
+ util_contain_errmsg(nullptr, &exit_code);
|
||||
+ util_contain_errmsg(teststr.c_str(), &exit_code);
|
||||
+ util_contain_errmsg(teststr.c_str(), nullptr);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_digest)
|
||||
+{
|
||||
+ std::string valid_dg = "sha256:729ce43e2c915c3463b620f3fba201a4a641ca5a282387e233db799208342a08";
|
||||
+ std::string invalid_dg = "xxxx";
|
||||
+
|
||||
+ ASSERT_STREQ(util_short_digest(valid_dg.c_str()), "729ce43e2c91");
|
||||
+ ASSERT_STREQ(util_short_digest(invalid_dg.c_str()), nullptr);
|
||||
+ ASSERT_STREQ(util_short_digest(nullptr), nullptr);
|
||||
+ ASSERT_STREQ(util_full_digest(nullptr), nullptr);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_proc_info)
|
||||
+{
|
||||
+ char buf[1024] = {0};
|
||||
+ pid_t cpid = getpid();
|
||||
+ proc_t *pt = nullptr;
|
||||
+
|
||||
+ ASSERT_EQ(util_stat2proc(nullptr, 10), nullptr);
|
||||
+ ASSERT_EQ(util_stat2proc(buf, 0), nullptr);
|
||||
+
|
||||
+ ASSERT_EQ(util_process_alive(0, 10000), false);
|
||||
+ // maybe return true
|
||||
+ ASSERT_EQ(util_process_alive(10000000, 10000), false);
|
||||
+
|
||||
+ pt = util_get_process_proc_info(cpid);
|
||||
+ ASSERT_NE(pt, nullptr);
|
||||
+ ASSERT_EQ(util_process_alive(cpid, pt->start_time), true);
|
||||
+ ASSERT_EQ(util_process_alive(cpid, 11), false);
|
||||
+
|
||||
+}
|
||||
+
|
||||
+void top_cb(char **args, const char *pid_args, size_t args_len)
|
||||
+{
|
||||
+ printf("this is stdout\n");
|
||||
+ fprintf(stderr, "this is stderr\n");
|
||||
+ exit(0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_exec_top_cmd)
|
||||
+{
|
||||
+ char *out_str = nullptr;
|
||||
+ char *err_str = nullptr;
|
||||
+
|
||||
+ ASSERT_EQ(util_exec_top_cmd(top_cb, nullptr, nullptr, 0, &out_str, &err_str), true);
|
||||
+ ASSERT_NE(out_str, nullptr);
|
||||
+ free(out_str);
|
||||
+ ASSERT_NE(err_str, nullptr);
|
||||
+ free(err_str);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_get_backtrace)
|
||||
+{
|
||||
+ char **ret = util_get_backtrace();
|
||||
+
|
||||
+ ASSERT_NE(ret, nullptr);
|
||||
+ free(ret);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_env_ops)
|
||||
+{
|
||||
+ char **ret = nullptr;
|
||||
+ size_t ret_len = 0;
|
||||
+ std::string first_val = "hello=world";
|
||||
+ std::string second_val = "todo=test";
|
||||
+ std::string new_val = "hello=test";
|
||||
+ std::string key1 = "hello";
|
||||
+ std::string key2 = "todo";
|
||||
+ char *got = nullptr;
|
||||
+
|
||||
+ ASSERT_EQ(util_env_insert(&ret, &ret_len, key1.c_str(), key1.size(), first_val.c_str()), 0);
|
||||
+ ASSERT_EQ(ret_len, 1);
|
||||
+ ASSERT_STREQ(ret[0], first_val.c_str());
|
||||
+
|
||||
+ ASSERT_EQ(util_env_insert(&ret, &ret_len, key2.c_str(), key2.size(), second_val.c_str()), 0);
|
||||
+ ASSERT_EQ(ret_len, 2);
|
||||
+ ASSERT_STREQ(ret[1], second_val.c_str());
|
||||
+
|
||||
+
|
||||
+ got = util_env_get_val(ret, ret_len, key1.c_str(), key1.size());
|
||||
+ ASSERT_STREQ(got, "world");
|
||||
+ free(got);
|
||||
+
|
||||
+ ASSERT_EQ(util_env_insert(&ret, &ret_len, key1.c_str(), key1.size(), new_val.c_str()), 0);
|
||||
+ ASSERT_EQ(ret_len, 2);
|
||||
+ ASSERT_STREQ(ret[0], new_val.c_str());
|
||||
+
|
||||
+ got = util_env_get_val(ret, ret_len, key2.c_str(), key2.size());
|
||||
+ ASSERT_STREQ(got, "test");
|
||||
+ free(got);
|
||||
+
|
||||
+ util_free_array_by_len(ret, ret_len);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_parse_user_remap)
|
||||
+{
|
||||
+ unsigned int uid, gid, offset;
|
||||
+ std::string valid_str = "1000:1000:65535";
|
||||
+ std::string invalid_str = "1000:1000:65536";
|
||||
+
|
||||
+ ASSERT_EQ(util_parse_user_remap(valid_str.c_str(), &uid, &gid, &offset), 0);
|
||||
+ ASSERT_EQ(uid, 1000);
|
||||
+ ASSERT_EQ(gid, 1000);
|
||||
+ ASSERT_EQ(offset, 65535);
|
||||
+
|
||||
+ ASSERT_EQ(util_parse_user_remap(nullptr, &uid, &gid, &offset), -1);
|
||||
+ ASSERT_EQ(util_parse_user_remap(invalid_str.c_str(), &uid, &gid, &offset), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_check_pid_max_kernel_namespaced)
|
||||
+{
|
||||
+ int ret = system("cat /proc/kallsyms | grep proc_dointvec_pidmax");
|
||||
+ ASSERT_EQ(util_check_pid_max_kernel_namespaced(), ret == 0 ? true : false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_memset_sensitive_string)
|
||||
+{
|
||||
+ char buff[32] = "hello";
|
||||
+
|
||||
+ util_memset_sensitive_string(buff);
|
||||
+ ASSERT_EQ(strlen(buff), 0);
|
||||
+ util_memset_sensitive_string(nullptr);
|
||||
+}
|
||||
+
|
||||
+void exec_cb(void *args)
|
||||
+{
|
||||
+ char buff[8] = { 0 };
|
||||
+ int ret;
|
||||
+
|
||||
+ ret = util_input_readall(buff, 7);
|
||||
+
|
||||
+ if (ret < 0) {
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+ exit(0);
|
||||
+}
|
||||
+
|
||||
+void exec_echo_cb(void *args)
|
||||
+{
|
||||
+ char buff[8] = { 0 };
|
||||
+ int ret;
|
||||
+ bool *is_echo = (bool *)args;
|
||||
+
|
||||
+ if (*is_echo) {
|
||||
+ ret = util_input_noecho(buff, 7);
|
||||
+ } else {
|
||||
+ ret = util_input_echo(buff, 7);
|
||||
+ }
|
||||
+
|
||||
+ if (ret < 0) {
|
||||
+ exit(-1);
|
||||
+ }
|
||||
+ exit(0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_input)
|
||||
+{
|
||||
+ std::string test = "hello";
|
||||
+ bool is_echo = true;
|
||||
+
|
||||
+ ASSERT_EQ(util_exec_cmd(exec_cb, nullptr, test.c_str(), nullptr, nullptr), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_exec_cmd(exec_echo_cb, &is_echo, test.c_str(), nullptr, nullptr), false);
|
||||
+ is_echo = false;
|
||||
+ ASSERT_EQ(util_exec_cmd(exec_echo_cb, &is_echo, test.c_str(), nullptr, nullptr), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_normalized_host_os_arch)
|
||||
+{
|
||||
+ ASSERT_EQ(util_normalized_host_os_arch(nullptr, nullptr, nullptr), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_read_pid_ppid_info)
|
||||
+{
|
||||
+ pid_t pid = getpid();
|
||||
+ pid_t ppid = getppid();
|
||||
+ pid_ppid_info_t pid_info = { 0 };
|
||||
+
|
||||
+ ASSERT_EQ(util_read_pid_ppid_info((uint32_t)pid, &pid_info), 0);
|
||||
+ ASSERT_EQ(pid_info.ppid, (int)ppid);
|
||||
+
|
||||
+ ASSERT_EQ(util_read_pid_ppid_info(0, nullptr), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_util_parse_user_group)
|
||||
+{
|
||||
+ std::string uandg = "user:group";
|
||||
+ char *user = nullptr;
|
||||
+ char *group = nullptr;
|
||||
+ char *tmp = nullptr;
|
||||
+
|
||||
+ util_parse_user_group(uandg.c_str(), &user, &group, &tmp);
|
||||
+ ASSERT_STREQ(user, "user");
|
||||
+ ASSERT_STREQ(group, "group");
|
||||
+ free(tmp);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_dup_map_string_empty_object)
|
||||
+{
|
||||
+ ASSERT_EQ(dup_map_string_empty_object(nullptr), nullptr);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_utils, test_convert_v2_runtime)
|
||||
+{
|
||||
+ std::string valid_str = "io.containerd.runc.v1";
|
||||
+ std::string valid_ret = "containerd-shim-runc-v1";
|
||||
+ std::string invalid_str = "xxx.xxx.xxx.xxx";
|
||||
+ char buff[32] = { 0 };
|
||||
+
|
||||
+ ASSERT_EQ(convert_v2_runtime(invalid_str.c_str(), buff), -1);
|
||||
+ ASSERT_EQ(convert_v2_runtime(nullptr, buff), -1);
|
||||
+ ASSERT_EQ(convert_v2_runtime(valid_str.c_str(), nullptr), -1);
|
||||
+ ASSERT_EQ(convert_v2_runtime(valid_str.c_str(), buff), 0);
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
63
0025-make-sure-kill-pid-not-negative.patch
Normal file
63
0025-make-sure-kill-pid-not-negative.patch
Normal file
@ -0,0 +1,63 @@
|
||||
From 979b21ba298edc64c88e2534b013076aa92ec975 Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Wed, 19 Oct 2022 14:38:49 +0800
|
||||
Subject: [PATCH 25/39] make sure kill pid not negative
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
src/cmd/isulad-shim/common.c | 2 +-
|
||||
src/daemon/modules/runtime/isula/isula_rt_ops.c | 4 ++--
|
||||
src/utils/cutils/utils.c | 2 +-
|
||||
3 files changed, 4 insertions(+), 4 deletions(-)
|
||||
|
||||
diff --git a/src/cmd/isulad-shim/common.c b/src/cmd/isulad-shim/common.c
|
||||
index 20e0963c..bb8464bb 100644
|
||||
--- a/src/cmd/isulad-shim/common.c
|
||||
+++ b/src/cmd/isulad-shim/common.c
|
||||
@@ -175,7 +175,7 @@ int cmd_combined_output(const char *binary, const char *params[], void *output,
|
||||
ret = SHIM_OK;
|
||||
|
||||
out:
|
||||
- if (ret != SHIM_OK && pid != 0) {
|
||||
+ if (ret != SHIM_OK) {
|
||||
kill(pid, 9);
|
||||
}
|
||||
|
||||
diff --git a/src/daemon/modules/runtime/isula/isula_rt_ops.c b/src/daemon/modules/runtime/isula/isula_rt_ops.c
|
||||
index 1e4cb5aa..c9667ee5 100644
|
||||
--- a/src/daemon/modules/runtime/isula/isula_rt_ops.c
|
||||
+++ b/src/daemon/modules/runtime/isula/isula_rt_ops.c
|
||||
@@ -361,7 +361,7 @@ static bool shim_alive(const char *workdir)
|
||||
|
||||
file_read_int(fpid, &pid);
|
||||
|
||||
- if (pid == 0) {
|
||||
+ if (pid <= 0) {
|
||||
ERROR("failed read shim-pid file %s", fpid);
|
||||
return false;
|
||||
}
|
||||
@@ -798,7 +798,7 @@ static void shim_kill_force(const char *workdir)
|
||||
|
||||
file_read_int(fpid, &pid);
|
||||
|
||||
- if (pid == 0) {
|
||||
+ if (pid <= 0) {
|
||||
goto out;
|
||||
}
|
||||
|
||||
diff --git a/src/utils/cutils/utils.c b/src/utils/cutils/utils.c
|
||||
index eddfda5c..9f5deaf9 100644
|
||||
--- a/src/utils/cutils/utils.c
|
||||
+++ b/src/utils/cutils/utils.c
|
||||
@@ -461,7 +461,7 @@ bool util_process_alive(pid_t pid, unsigned long long start_time)
|
||||
bool alive = true;
|
||||
proc_t *pid_info = NULL;
|
||||
|
||||
- if (pid == 0) {
|
||||
+ if (pid <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
240
0026-add-UT-for-atomic-and-map.patch
Normal file
240
0026-add-UT-for-atomic-and-map.patch
Normal file
@ -0,0 +1,240 @@
|
||||
From d9eb77bbe430fa74ca1c55c0c6907afaeb559499 Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Tue, 18 Oct 2022 19:19:23 +0800
|
||||
Subject: [PATCH 26/39] add UT for atomic and map
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 2 +
|
||||
test/cutils/map/CMakeLists.txt | 16 ++++++
|
||||
test/cutils/map/map_ut.cc | 39 ++++++++++++++
|
||||
test/cutils/util_atomic/CMakeLists.txt | 18 +++++++
|
||||
test/cutils/util_atomic/util_atomic_ut.cc | 56 +++++++++++++++++++++
|
||||
test/cutils/utils_string/utils_string_ut.cc | 25 +++++++++
|
||||
test/mocks/utils_network_mock.cc | 2 +-
|
||||
7 files changed, 157 insertions(+), 1 deletion(-)
|
||||
create mode 100644 test/cutils/map/CMakeLists.txt
|
||||
create mode 100644 test/cutils/map/map_ut.cc
|
||||
create mode 100644 test/cutils/util_atomic/CMakeLists.txt
|
||||
create mode 100644 test/cutils/util_atomic/util_atomic_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 23426015..28e37b27 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -17,6 +17,8 @@ target_include_directories(libutils_ut
|
||||
|
||||
add_subdirectory(mainloop)
|
||||
add_subdirectory(path)
|
||||
+add_subdirectory(map)
|
||||
+add_subdirectory(util_atomic)
|
||||
add_subdirectory(utils_string)
|
||||
add_subdirectory(utils_convert)
|
||||
add_subdirectory(utils_array)
|
||||
diff --git a/test/cutils/map/CMakeLists.txt b/test/cutils/map/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..4059559f
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/map/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE map_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ map_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
|
||||
+ )
|
||||
+
|
||||
+target_link_libraries(${EXE} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} libutils_ut -lcrypto -lyajl -lz)
|
||||
+add_test(NAME ${EXE} COMMAND ${EXE} --gtest_output=xml:${EXE}-Results.xml)
|
||||
diff --git a/test/cutils/map/map_ut.cc b/test/cutils/map/map_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..fd75da28
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/map/map_ut.cc
|
||||
@@ -0,0 +1,39 @@
|
||||
+/*
|
||||
+ * 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: map unit test
|
||||
+ * Author: zhangxiaoyu
|
||||
+ * Create: 2022-10-19
|
||||
+ */
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+#include <stdio.h>
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "map.h"
|
||||
+
|
||||
+TEST(map_map_ut, test_map)
|
||||
+{
|
||||
+ // map[string][bool]
|
||||
+ map_t *map_test = nullptr;
|
||||
+ bool exist = true;
|
||||
+
|
||||
+ map_test = map_new(MAP_STR_BOOL, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
|
||||
+ ASSERT_NE(map_test, nullptr);
|
||||
+ ASSERT_EQ(map_insert(map_test, (void *)"key", &exist), true);
|
||||
+
|
||||
+ map_itor *itor = map_itor_new(map_test);
|
||||
+ ASSERT_NE(itor, nullptr);
|
||||
+ ASSERT_EQ(map_itor_first(itor), true);
|
||||
+ ASSERT_EQ(map_itor_last(itor), true);
|
||||
+ ASSERT_EQ(map_itor_prev(itor), false);
|
||||
+
|
||||
+ map_itor_free(itor);
|
||||
+ map_clear(map_test);
|
||||
+}
|
||||
diff --git a/test/cutils/util_atomic/CMakeLists.txt b/test/cutils/util_atomic/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..071b2a04
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/util_atomic/CMakeLists.txt
|
||||
@@ -0,0 +1,18 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE util_atomic_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ util_atomic_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
|
||||
+ )
|
||||
+
|
||||
+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/util_atomic/util_atomic_ut.cc b/test/cutils/util_atomic/util_atomic_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..29772a1e
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/util_atomic/util_atomic_ut.cc
|
||||
@@ -0,0 +1,56 @@
|
||||
+/*
|
||||
+ * 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: util_atomic unit test
|
||||
+ * Author: zhangxiaoyu
|
||||
+ * Create: 2022-10-15
|
||||
+ */
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+#include <stdio.h>
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "mock.h"
|
||||
+#include "util_atomic.h"
|
||||
+
|
||||
+TEST(utils_atomic_ut, test_atomic_inc_dec)
|
||||
+{
|
||||
+ uint64_t atomic = 0;
|
||||
+ uint64_t atomic_image = 0;
|
||||
+
|
||||
+ atomic_int_set(&atomic, 10);
|
||||
+ ASSERT_EQ(atomic_int_get(&atomic), 10);
|
||||
+ ASSERT_EQ(atomic_int_inc(&atomic), 11);
|
||||
+ ASSERT_EQ(atomic_int_dec_test(&atomic), false);
|
||||
+
|
||||
+ atomic_int_set_image(&atomic_image, 1);
|
||||
+ ASSERT_EQ(atomic_int_inc_image(&atomic_image), 2);
|
||||
+ ASSERT_EQ(atomic_int_dec_test_image(&atomic_image), false);
|
||||
+ ASSERT_EQ(atomic_int_dec_test_image(&atomic_image), true);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_atomic_ut, test_atomic_calculate)
|
||||
+{
|
||||
+ uint64_t atomic = 0;
|
||||
+
|
||||
+ ASSERT_EQ(atomic_int_compare_exchange(&atomic, 1, 2), false);
|
||||
+
|
||||
+
|
||||
+ ASSERT_EQ(atomic_int_compare_exchange(&atomic, 0, 2), true);
|
||||
+ // atomic = 2
|
||||
+ ASSERT_EQ(atomic_int_add(&atomic, 3), 2);
|
||||
+ // atomic = 5
|
||||
+ ASSERT_EQ(atomic_int_and(&atomic, 4), 5);
|
||||
+ // atomic = 4
|
||||
+ ASSERT_EQ(atomic_int_or(&atomic, 8), 4);
|
||||
+ // atomic = 12
|
||||
+ ASSERT_EQ(atomic_int_xor(&atomic, 3), 12);
|
||||
+ // atomic = 15
|
||||
+ ASSERT_EQ(atomic_int_get(&atomic), 15);
|
||||
+}
|
||||
diff --git a/test/cutils/utils_string/utils_string_ut.cc b/test/cutils/utils_string/utils_string_ut.cc
|
||||
index b488a09f..8b6c61a6 100644
|
||||
--- a/test/cutils/utils_string/utils_string_ut.cc
|
||||
+++ b/test/cutils/utils_string/utils_string_ut.cc
|
||||
@@ -18,6 +18,7 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "mock.h"
|
||||
#include "utils_string.h"
|
||||
+#include "utils_array.h"
|
||||
|
||||
extern "C" {
|
||||
DECLARE_WRAPPER(util_strdup_s, char *, (const char *str));
|
||||
@@ -831,3 +832,27 @@ TEST(utils_string_ut, test_str_token)
|
||||
ASSERT_STREQ(token, "abc");
|
||||
free(token);
|
||||
}
|
||||
+
|
||||
+TEST(utils_string_ut, test_string_split_multi)
|
||||
+{
|
||||
+ char **result = nullptr;
|
||||
+
|
||||
+ ASSERT_EQ(util_string_split_multi(nullptr, ':'), nullptr);
|
||||
+
|
||||
+ result = util_string_split_multi("", ':');
|
||||
+ ASSERT_STREQ(result[0], "");
|
||||
+ ASSERT_EQ(result[1], nullptr);
|
||||
+ util_free_array(result);
|
||||
+
|
||||
+ result = util_string_split_multi("abcd;", ':');
|
||||
+ ASSERT_STREQ(result[0], "abcd;");
|
||||
+ ASSERT_EQ(result[1], nullptr);
|
||||
+ util_free_array(result);
|
||||
+
|
||||
+ result = util_string_split_multi("abc:dd:e", ':');
|
||||
+ ASSERT_STREQ(result[0], "abc");
|
||||
+ ASSERT_STREQ(result[1], "dd");
|
||||
+ ASSERT_STREQ(result[2], "e");
|
||||
+ ASSERT_EQ(result[3], nullptr);
|
||||
+ util_free_array(result);
|
||||
+}
|
||||
diff --git a/test/mocks/utils_network_mock.cc b/test/mocks/utils_network_mock.cc
|
||||
index afa346b5..01027a62 100644
|
||||
--- a/test/mocks/utils_network_mock.cc
|
||||
+++ b/test/mocks/utils_network_mock.cc
|
||||
@@ -57,4 +57,4 @@ int pthread_join(pthread_t thread, void **retval)
|
||||
return g_utils_network_mock->PthreadJoin(thread, retval);
|
||||
}
|
||||
return 0;
|
||||
-}
|
||||
\ No newline at end of file
|
||||
+}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
125
0027-remove-unnecessary-goto-and-add-parameter-check-for-.patch
Normal file
125
0027-remove-unnecessary-goto-and-add-parameter-check-for-.patch
Normal file
@ -0,0 +1,125 @@
|
||||
From d9f2f58a5c8952fe0f03c8f6fbbed7f741a41e68 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Wed, 19 Oct 2022 15:12:27 +0800
|
||||
Subject: [PATCH 27/39] remove unnecessary goto and add parameter check for
|
||||
verify
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
src/utils/cutils/utils_verify.c | 41 ++++++++++++++++++++-------------
|
||||
1 file changed, 25 insertions(+), 16 deletions(-)
|
||||
|
||||
diff --git a/src/utils/cutils/utils_verify.c b/src/utils/cutils/utils_verify.c
|
||||
index 40b153f0..9ed33bf3 100644
|
||||
--- a/src/utils/cutils/utils_verify.c
|
||||
+++ b/src/utils/cutils/utils_verify.c
|
||||
@@ -143,24 +143,21 @@ bool util_validate_unix_socket(const char *socket)
|
||||
}
|
||||
|
||||
if (strncmp("unix://", socket, strlen("unix://"))) {
|
||||
- nret = -1;
|
||||
- goto err_out;
|
||||
+ return false;
|
||||
}
|
||||
|
||||
name = socket + strlen("unix://");
|
||||
|
||||
if (name[0] == '\0') {
|
||||
- nret = -1;
|
||||
- goto err_out;
|
||||
+ return false;
|
||||
}
|
||||
|
||||
nret = util_validate_absolute_path(name);
|
||||
if (nret != 0) {
|
||||
- nret = -1;
|
||||
- goto err_out;
|
||||
+ return false;
|
||||
}
|
||||
-err_out:
|
||||
- return nret == 0;
|
||||
+
|
||||
+ return true;
|
||||
}
|
||||
|
||||
bool util_validate_socket(const char *socket)
|
||||
@@ -219,7 +216,6 @@ size_t util_get_all_caps_len()
|
||||
|
||||
bool util_valid_cap(const char *cap)
|
||||
{
|
||||
- bool cret = true;
|
||||
int nret = 0;
|
||||
char tmpcap[32] = { 0 };
|
||||
size_t all_caps_len = util_get_all_caps_len();
|
||||
@@ -231,16 +227,13 @@ bool util_valid_cap(const char *cap)
|
||||
nret = snprintf(tmpcap, sizeof(tmpcap), "CAP_%s", cap);
|
||||
if (nret < 0 || nret >= sizeof(tmpcap)) {
|
||||
ERROR("Failed to print string");
|
||||
- cret = false;
|
||||
- goto err_out;
|
||||
+ return false;
|
||||
}
|
||||
if (!util_strings_in_slice(g_all_caps, all_caps_len, tmpcap)) {
|
||||
- cret = false;
|
||||
- goto err_out;
|
||||
+ return false;
|
||||
}
|
||||
|
||||
-err_out:
|
||||
- return cret;
|
||||
+ return true;
|
||||
}
|
||||
|
||||
bool util_valid_container_id(const char *id)
|
||||
@@ -570,16 +563,27 @@ bool util_valid_value_false(const char *value)
|
||||
|
||||
bool util_valid_rw_mode(const char *mode)
|
||||
{
|
||||
+ if (mode == NULL){
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
return !strcmp(mode, "rw") || !strcmp(mode, "ro");
|
||||
}
|
||||
|
||||
bool util_valid_label_mode(const char *mode)
|
||||
{
|
||||
+ if (mode == NULL){
|
||||
+ return false;
|
||||
+ }
|
||||
+
|
||||
return !strcmp(mode, "z") || !strcmp(mode, "Z");
|
||||
}
|
||||
|
||||
bool util_valid_copy_mode(const char *mode)
|
||||
{
|
||||
+ if (mode == NULL){
|
||||
+ return false;
|
||||
+ }
|
||||
return !strcmp(mode, "nocopy");
|
||||
}
|
||||
|
||||
@@ -681,7 +685,7 @@ bool util_valid_positive_interger(const char *value)
|
||||
{
|
||||
const char *patten = "^[0-9]*$";
|
||||
|
||||
- if (value == NULL) {
|
||||
+ if (value == NULL || strcmp(value, "") == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -704,6 +708,11 @@ int util_valid_env(const char *env, char **dst)
|
||||
int ret = 0;
|
||||
char *value = NULL;
|
||||
|
||||
+ if (dst == NULL){
|
||||
+ ERROR("NULL dst");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
char **arr = util_string_split_multi(env, '=');
|
||||
if (arr == NULL) {
|
||||
ERROR("Failed to split env string");
|
||||
--
|
||||
2.25.1
|
||||
|
||||
487
0028-Add-ut-for-verify.patch
Normal file
487
0028-Add-ut-for-verify.patch
Normal file
@ -0,0 +1,487 @@
|
||||
From c31c29a9ea4f4818036ee52cb85f82b5a02e43f9 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Wed, 19 Oct 2022 15:09:34 +0800
|
||||
Subject: [PATCH 28/39] Add ut for verify
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_verify/CMakeLists.txt | 16 +
|
||||
test/cutils/utils_verify/utils_verify_ut.cc | 432 ++++++++++++++++++++
|
||||
3 files changed, 449 insertions(+)
|
||||
create mode 100644 test/cutils/utils_verify/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_verify/utils_verify_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 28e37b27..2447b781 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -34,3 +34,4 @@ add_subdirectory(utils_timestamp)
|
||||
add_subdirectory(utils_mount_spec)
|
||||
add_subdirectory(utils_regex)
|
||||
add_subdirectory(utils_utils)
|
||||
+add_subdirectory(utils_verify)
|
||||
diff --git a/test/cutils/utils_verify/CMakeLists.txt b/test/cutils/utils_verify/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..abf9596f
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_verify/CMakeLists.txt
|
||||
@@ -0,0 +1,16 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_verify_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_verify_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_verify/utils_verify_ut.cc b/test/cutils/utils_verify/utils_verify_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..d1a9b6bf
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_verify/utils_verify_ut.cc
|
||||
@@ -0,0 +1,432 @@
|
||||
+/******************************************************************************
|
||||
+ * 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: zhongtao
|
||||
+ * Create: 2022-10-19
|
||||
+ * Description: utils verify unit test
|
||||
+ *******************************************************************************/
|
||||
+
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "utils_verify.h"
|
||||
+#include "utils_file.h"
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_cmd_arg)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_cmd_arg("isula ps"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_cmd_arg(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_cmd_arg("isula ps | grep"), false);
|
||||
+ ASSERT_EQ(util_valid_cmd_arg("isula`"), false);
|
||||
+ ASSERT_EQ(util_valid_cmd_arg("isula ps & grep`"), false);
|
||||
+ ASSERT_EQ(util_valid_cmd_arg("isula ps ; grep`"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_signal)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_signal(2), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_signal(0), false);
|
||||
+ ASSERT_EQ(util_valid_signal(-1), false);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_signal(64), true);
|
||||
+ ASSERT_EQ(util_valid_signal(65), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_validate_absolute_path)
|
||||
+{
|
||||
+ ASSERT_EQ(util_validate_absolute_path("/etc/isulad"), 0);
|
||||
+ ASSERT_EQ(util_validate_absolute_path("/isulad/"), 0);
|
||||
+
|
||||
+ ASSERT_EQ(util_validate_absolute_path(nullptr), -1);
|
||||
+ ASSERT_EQ(util_validate_absolute_path("./isulad"), -1);
|
||||
+ ASSERT_EQ(util_validate_absolute_path("isulad"), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_validate_unix_socket)
|
||||
+{
|
||||
+ ASSERT_EQ(util_validate_unix_socket("unix:///etc/isulad"), true);
|
||||
+ ASSERT_EQ(util_validate_unix_socket("unix:///isulad/"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_validate_unix_socket(nullptr), false);
|
||||
+ ASSERT_EQ(util_validate_unix_socket("unix://"), false);
|
||||
+ ASSERT_EQ(util_validate_unix_socket("unix://./isulad"), false);
|
||||
+ ASSERT_EQ(util_validate_unix_socket("unix://isulad"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_validate_socket)
|
||||
+{
|
||||
+ ASSERT_EQ(util_validate_socket("unix:///etc/isulad"), true);
|
||||
+ ASSERT_EQ(util_validate_socket("unix:///isulad/"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_validate_socket(nullptr), false);
|
||||
+ ASSERT_EQ(util_validate_socket("unix://"), false);
|
||||
+ ASSERT_EQ(util_validate_socket("unix://./isulad"), false);
|
||||
+ ASSERT_EQ(util_validate_socket("unix://isulad"), false);
|
||||
+
|
||||
+ ASSERT_EQ(util_validate_socket("tcp://localhost:2375"), true);
|
||||
+ ASSERT_EQ(util_validate_socket("tcp://127.0.0.1:2375"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_validate_socket("tcp://"), false);
|
||||
+ ASSERT_EQ(util_validate_socket("tcp://127.0.0.1"), false);
|
||||
+ ASSERT_EQ(util_validate_socket("tcp://127.0.0.1,2375"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_device_mode)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_device_mode("rwm"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_device_mode(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_device_mode(""), false);
|
||||
+ ASSERT_EQ(util_valid_device_mode("rrwm"), false);
|
||||
+ ASSERT_EQ(util_valid_device_mode("rwwm"), false);
|
||||
+ ASSERT_EQ(util_valid_device_mode("rwmm"), false);
|
||||
+ ASSERT_EQ(util_valid_device_mode("awm"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_str)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_str("str"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_str(""), false);
|
||||
+ ASSERT_EQ(util_valid_str(nullptr), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_get_all_caps_len)
|
||||
+{
|
||||
+ ASSERT_EQ(util_get_all_caps_len(), 38);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_cap)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_cap("DAC_READ_SEARCH"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_cap(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_cap(""), false);
|
||||
+ ASSERT_EQ(util_valid_cap("DA_READ_SEARCH"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_time_tz)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_time_tz("2022-10-04T18:22:45.289257759Z"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_time_tz(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_time_tz("2016-01-02T15:04:01:03"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_embedded_image_name)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_embedded_image_name("busybox:latest"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_embedded_image_name(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_embedded_image_name("busybox:/latest"), false);
|
||||
+ ASSERT_EQ(util_valid_embedded_image_name("busybox"), false);
|
||||
+ ASSERT_EQ(util_valid_embedded_image_name("busybox:#latest"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_image_name)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_image_name("busybox:latest"), true);
|
||||
+ ASSERT_EQ(util_valid_image_name("busybox"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_image_name(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_image_name("busybox:/latest"), false);
|
||||
+ ASSERT_EQ(util_valid_image_name("busybox:#latest"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_tag_pos)
|
||||
+{
|
||||
+ ASSERT_STREQ(util_tag_pos("busybox:latest"), ":latest");
|
||||
+
|
||||
+ ASSERT_EQ(util_tag_pos("busybox:/latest"), nullptr);
|
||||
+ ASSERT_EQ(util_tag_pos("busybox"), nullptr);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_file)
|
||||
+{
|
||||
+ std::string isulad_dir = "/tmp/test";
|
||||
+ ASSERT_EQ(util_mkdir_p(isulad_dir.c_str(), 0700), 0);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_file(isulad_dir.c_str(), S_IFDIR), true);
|
||||
+ ASSERT_EQ(util_valid_file(isulad_dir.c_str(), S_IFBLK), false);
|
||||
+ ASSERT_EQ(util_valid_file(isulad_dir.c_str(), 0), false);
|
||||
+
|
||||
+ ASSERT_EQ(util_path_remove(isulad_dir.c_str()), 0);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_file(nullptr, S_IFDIR),false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_digest)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_digest("sha256:7bd0c945d7e4cc2ce5c21d449ba07eb89c8e6c28085edbcf6f5fa4bf90e7eedc"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_digest(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_digest("ha256:7bd0c945d7e4cc2ce5c21d449ba07eb89c8e6c28085edbcf6f5fa4bf90e7eedc"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_tag)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_tag("busybox:latest"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_tag(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_tag("sha256:latest"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_type)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_type("type"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_type(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_type("type:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_src)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_src("src"), true);
|
||||
+ ASSERT_EQ(util_valid_key_src("source"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_src(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_src("source:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_dst)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_dst("dst"), true);
|
||||
+ ASSERT_EQ(util_valid_key_dst("destination"), true);
|
||||
+ ASSERT_EQ(util_valid_key_dst("target"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_dst(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_dst("target:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_ro)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_ro("ro"), true);
|
||||
+ ASSERT_EQ(util_valid_key_ro("readonly"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_ro(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_ro("readonly:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_propagation)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_propagation("bind-propagation"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_propagation(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_propagation("bind-propagation:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_selinux)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_selinux("bind-selinux-opts"), true);
|
||||
+ ASSERT_EQ(util_valid_key_selinux("selinux-opts"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_selinux(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_selinux("bind-selinux-opts:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_tmpfs_size)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_tmpfs_size("tmpfs-size"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_tmpfs_size(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_tmpfs_size("tmpfs-size:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_tmpfs_mode)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_tmpfs_mode("tmpfs-mode"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_tmpfs_mode(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_tmpfs_mode("tmpfs-mode:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_key_nocopy)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_key_nocopy("volume-nocopy"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_key_nocopy(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_key_nocopy("volume-nocopy:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_value_true)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_value_true("1"), true);
|
||||
+ ASSERT_EQ(util_valid_value_true("true"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_value_true(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_value_true("0"), false);
|
||||
+ ASSERT_EQ(util_valid_value_true("false"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_value_false)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_value_false("0"), true);
|
||||
+ ASSERT_EQ(util_valid_value_false("false"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_value_false(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_value_false("1"), false);
|
||||
+ ASSERT_EQ(util_valid_value_false("true"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_rw_mode)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_rw_mode("ro"), true);
|
||||
+ ASSERT_EQ(util_valid_rw_mode("rw"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_rw_mode(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_rw_mode("rwro"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_label_mode)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_label_mode("z"), true);
|
||||
+ ASSERT_EQ(util_valid_label_mode("Z"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_label_mode(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_label_mode("zZ"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_copy_mode)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_copy_mode("nocopy"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_copy_mode(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_copy_mode("nocopy:123"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_propagation_mode)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_propagation_mode("private"), true);
|
||||
+ ASSERT_EQ(util_valid_propagation_mode("rprivate"), true);
|
||||
+ ASSERT_EQ(util_valid_propagation_mode("slave"), true);
|
||||
+ ASSERT_EQ(util_valid_propagation_mode("rslave"), true);
|
||||
+ ASSERT_EQ(util_valid_propagation_mode("shared"), true);
|
||||
+ ASSERT_EQ(util_valid_propagation_mode("rshared"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_propagation_mode(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_propagation_mode("rrslave"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_mount_mode)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_mount_mode("ro,private,z,nocopy"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_mount_mode(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_mount_mode("ro,rw,private,z,nocopy"), false);
|
||||
+ ASSERT_EQ(util_valid_mount_mode("ri,private,z,nocopy"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_container_id)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_container_id("451f587884b04ef2a81a6d410f65083c906a865044ef5bef8af833aaab8c63aa"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_container_id(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_container_id("g51f587884b04ef2a81a6d410f65083c906a865044ef5bef8af833aaab8c63aa"), false);
|
||||
+ ASSERT_EQ(util_valid_container_id(""), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_container_name)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_container_name("test"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_container_name(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_container_name(".test"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_container_id_or_name)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_container_id_or_name("test"), true);
|
||||
+ ASSERT_EQ(util_valid_container_id_or_name("451f587884b04ef2a81a6d410f65083c906a865044ef5bef8af833aaab8c63aa"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_container_id_or_name(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_container_id_or_name(".test"), false);
|
||||
+ ASSERT_EQ(util_valid_container_id_or_name(""), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_host_name)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_host_name("LAPTOP-6O44CJ3O"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_host_name(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_host_name(".LAPTOP-6O44CJ3O"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_runtime_name)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_runtime_name("runc"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_runtime_name(nullptr), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_short_sha256_id)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_short_sha256_id("ff4a8eb070e12018233797e865841d877a7835c4c6d5cfc52e5481995da6b2f7"), true);
|
||||
+ ASSERT_EQ(util_valid_short_sha256_id("ff4"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_short_sha256_id(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_short_sha256_id("ff"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_exec_suffix)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_exec_suffix("ff4a8eb070e12018233797e865841d877a7835c4c6d5cfc52e5481995da6b2f7"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_exec_suffix(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_exec_suffix("gf4a8eb070e12018233797e865841d877a7835c4c6d5cfc52e5481995da6b2f7"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_positive_interger)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_positive_interger("123456789"), true);
|
||||
+ ASSERT_EQ(util_valid_positive_interger("0"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_positive_interger(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_positive_interger("-123456789"), false);
|
||||
+ ASSERT_EQ(util_valid_positive_interger(""), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_device_cgroup_rule)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_device_cgroup_rule("b 8:* rmw"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_device_cgroup_rule(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_device_cgroup_rule("d 8:* rmw"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_env)
|
||||
+{
|
||||
+ char *env = (char *)"USER=root";
|
||||
+ char *dst = nullptr;
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_env(env, &dst), 0);
|
||||
+ ASSERT_STREQ(dst, "USER=root");
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_env(nullptr, &dst), -1);
|
||||
+ ASSERT_EQ(util_valid_env(env, nullptr), -1);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_sysctl)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_sysctl("kernel.msgmax"), true);
|
||||
+ ASSERT_EQ(util_valid_sysctl("net.abc"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_sysctl(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_sysctl("kernel.shmal"), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_verify, test_util_valid_volume_name)
|
||||
+{
|
||||
+ ASSERT_EQ(util_valid_volume_name("f6391b735a917ffbaff138970dc45290508574e6ab92e06a1e9dd290f31592ca"), true);
|
||||
+ ASSERT_EQ(util_valid_volume_name("aa"), true);
|
||||
+
|
||||
+ ASSERT_EQ(util_valid_volume_name(nullptr), false);
|
||||
+ ASSERT_EQ(util_valid_volume_name(""), false);
|
||||
+ ASSERT_EQ(util_valid_volume_name("a"), false);
|
||||
+}
|
||||
\ No newline at end of file
|
||||
--
|
||||
2.25.1
|
||||
|
||||
26
0029-fix-error-in-utils_verify_ut.patch
Normal file
26
0029-fix-error-in-utils_verify_ut.patch
Normal file
@ -0,0 +1,26 @@
|
||||
From f342d18d5eb26baabad2749002bac71b412ed8b6 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Thu, 20 Oct 2022 19:03:57 +0800
|
||||
Subject: [PATCH 29/39] fix error in utils_verify_ut
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
test/cutils/utils_verify/utils_verify_ut.cc | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/test/cutils/utils_verify/utils_verify_ut.cc b/test/cutils/utils_verify/utils_verify_ut.cc
|
||||
index d1a9b6bf..9c4bf944 100644
|
||||
--- a/test/cutils/utils_verify/utils_verify_ut.cc
|
||||
+++ b/test/cutils/utils_verify/utils_verify_ut.cc
|
||||
@@ -100,7 +100,7 @@ TEST(utils_verify, test_util_valid_str)
|
||||
|
||||
TEST(utils_verify, test_util_get_all_caps_len)
|
||||
{
|
||||
- ASSERT_EQ(util_get_all_caps_len(), 38);
|
||||
+ ASSERT_NE(util_get_all_caps_len(), 0);
|
||||
}
|
||||
|
||||
TEST(utils_verify, test_util_valid_cap)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
122
0030-add-more-test-for-string-and-map.patch
Normal file
122
0030-add-more-test-for-string-and-map.patch
Normal file
@ -0,0 +1,122 @@
|
||||
From 5e4fc62e36631d8d2e444ac3d60ce99ec7396ca0 Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Fri, 21 Oct 2022 09:58:40 +0800
|
||||
Subject: [PATCH 30/39] add more test for string and map
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
test/cutils/map/map_ut.cc | 50 ++++++++++++++++++++-
|
||||
test/cutils/utils_string/utils_string_ut.cc | 17 ++++---
|
||||
2 files changed, 61 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/test/cutils/map/map_ut.cc b/test/cutils/map/map_ut.cc
|
||||
index fd75da28..7e4c97e4 100644
|
||||
--- a/test/cutils/map/map_ut.cc
|
||||
+++ b/test/cutils/map/map_ut.cc
|
||||
@@ -18,7 +18,12 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include "map.h"
|
||||
|
||||
-TEST(map_map_ut, test_map)
|
||||
+static void ptr_ptr_map_kefree(void *key, void *value)
|
||||
+{
|
||||
+ return;
|
||||
+}
|
||||
+
|
||||
+TEST(map_map_ut, test_map_string)
|
||||
{
|
||||
// map[string][bool]
|
||||
map_t *map_test = nullptr;
|
||||
@@ -37,3 +42,46 @@ TEST(map_map_ut, test_map)
|
||||
map_itor_free(itor);
|
||||
map_clear(map_test);
|
||||
}
|
||||
+
|
||||
+TEST(map_map_ut, test_map_int)
|
||||
+{
|
||||
+ int key = 3;
|
||||
+ int value = 5;
|
||||
+ int *value_ptr = nullptr;
|
||||
+ // map[int][int]
|
||||
+ map_t *map_test = nullptr;
|
||||
+
|
||||
+ map_test = map_new(MAP_INT_INT, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
|
||||
+ ASSERT_NE(map_test, nullptr);
|
||||
+ ASSERT_EQ(map_insert(map_test, &key, &value), true);
|
||||
+
|
||||
+ key = 22;
|
||||
+ value = 33;
|
||||
+ ASSERT_EQ(map_insert(map_test, &key, &value), true);
|
||||
+
|
||||
+ value_ptr = (int *)map_search(map_test, &key);
|
||||
+ ASSERT_EQ(*value_ptr, 33);
|
||||
+
|
||||
+ key = 44;
|
||||
+ ASSERT_EQ(map_search(map_test, &key), nullptr);
|
||||
+
|
||||
+ map_clear(map_test);
|
||||
+}
|
||||
+
|
||||
+TEST(map_map_ut, test_map_ptr)
|
||||
+{
|
||||
+ int *key_ptr = new int(3);
|
||||
+ int *value_ptr = new int(5);
|
||||
+ // map[ptr][ptr]
|
||||
+ map_t *map_test = nullptr;
|
||||
+
|
||||
+ map_test = map_new(MAP_PTR_PTR, MAP_DEFAULT_CMP_FUNC, ptr_ptr_map_kefree);
|
||||
+ ASSERT_NE(map_test, nullptr);
|
||||
+ ASSERT_EQ(map_insert(map_test, key_ptr, value_ptr), true);
|
||||
+ ASSERT_EQ(map_search(map_test, key_ptr), value_ptr);
|
||||
+ ASSERT_EQ(map_search(map_test, nullptr), nullptr);
|
||||
+
|
||||
+ map_clear(map_test);
|
||||
+ delete key_ptr;
|
||||
+ delete value_ptr;
|
||||
+}
|
||||
diff --git a/test/cutils/utils_string/utils_string_ut.cc b/test/cutils/utils_string/utils_string_ut.cc
|
||||
index 8b6c61a6..0f8f0011 100644
|
||||
--- a/test/cutils/utils_string/utils_string_ut.cc
|
||||
+++ b/test/cutils/utils_string/utils_string_ut.cc
|
||||
@@ -833,26 +833,33 @@ TEST(utils_string_ut, test_str_token)
|
||||
free(token);
|
||||
}
|
||||
|
||||
-TEST(utils_string_ut, test_string_split_multi)
|
||||
+TEST(utils_string_ut, test_string_split_n)
|
||||
{
|
||||
char **result = nullptr;
|
||||
|
||||
- ASSERT_EQ(util_string_split_multi(nullptr, ':'), nullptr);
|
||||
+ ASSERT_EQ(util_string_split_n(nullptr, ':', 3), nullptr);
|
||||
+ ASSERT_EQ(util_string_split_n("aa:bb", ':', 0), nullptr);
|
||||
|
||||
- result = util_string_split_multi("", ':');
|
||||
+ result = util_string_split_n("", ':', 3);
|
||||
ASSERT_STREQ(result[0], "");
|
||||
ASSERT_EQ(result[1], nullptr);
|
||||
util_free_array(result);
|
||||
|
||||
- result = util_string_split_multi("abcd;", ':');
|
||||
+ result = util_string_split_n("abcd;", ':', 3);
|
||||
ASSERT_STREQ(result[0], "abcd;");
|
||||
ASSERT_EQ(result[1], nullptr);
|
||||
util_free_array(result);
|
||||
|
||||
- result = util_string_split_multi("abc:dd:e", ':');
|
||||
+ result = util_string_split_n("abc:dd:e", ':', 3);
|
||||
ASSERT_STREQ(result[0], "abc");
|
||||
ASSERT_STREQ(result[1], "dd");
|
||||
ASSERT_STREQ(result[2], "e");
|
||||
ASSERT_EQ(result[3], nullptr);
|
||||
util_free_array(result);
|
||||
+
|
||||
+ result = util_string_split_n("abc:dd:e", ':', 2);
|
||||
+ ASSERT_STREQ(result[0], "abc");
|
||||
+ ASSERT_STREQ(result[1], "dd:e");
|
||||
+ ASSERT_EQ(result[2], nullptr);
|
||||
+ util_free_array(result);
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
@ -0,0 +1,32 @@
|
||||
From 81cf4edd6aa0c4170eb0ec48a6934ef3262a920d Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Sat, 22 Oct 2022 11:48:48 +0800
|
||||
Subject: [PATCH 31/39] remove mnt point if add device mapper device failed
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
.../layer_store/graphdriver/devmapper/driver_devmapper.c | 8 +++++++-
|
||||
1 file changed, 7 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
|
||||
index f4d54963..0a4e5e57 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
|
||||
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
|
||||
@@ -106,7 +106,13 @@ static int do_create(const char *id, const char *parent, const struct graphdrive
|
||||
goto out;
|
||||
}
|
||||
|
||||
- ret = add_device(id, parent, driver->devset, create_opts->storage_opt);
|
||||
+ if (add_device(id, parent, driver->devset, create_opts->storage_opt) != 0) {
|
||||
+ ERROR("Failed to add device");
|
||||
+ ret = -1;
|
||||
+ if (util_path_remove(mnt_point_dir) != 0) {
|
||||
+ ERROR("Remove path:%s failed", mnt_point_dir);
|
||||
+ }
|
||||
+ }
|
||||
|
||||
out:
|
||||
free(mnt_parent_dir);
|
||||
--
|
||||
2.25.1
|
||||
|
||||
59
0032-dec-device-info-ref-in-grow-device-fs.patch
Normal file
59
0032-dec-device-info-ref-in-grow-device-fs.patch
Normal file
@ -0,0 +1,59 @@
|
||||
From 5ded258d2e9a331a1fa5e3f76757fdb1e868cc8f Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Thu, 20 Oct 2022 16:17:26 +0800
|
||||
Subject: [PATCH 32/39] dec device info ref in grow device fs
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
.../graphdriver/devmapper/deviceset.c | 26 +++++++++----------
|
||||
1 file changed, 13 insertions(+), 13 deletions(-)
|
||||
|
||||
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
|
||||
index 78d8737d..4dadc336 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
|
||||
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/deviceset.c
|
||||
@@ -2483,6 +2483,7 @@ static void cleanup_deleted_devices(struct graphdriver *driver)
|
||||
device_info = lookup_device(driver->devset, idsarray[i]);
|
||||
if (device_info == NULL || device_info->info == NULL) {
|
||||
DEBUG("devmapper: no such device with hash(%s), just skip cleanup", idsarray[i]);
|
||||
+ devmapper_device_info_ref_dec(device_info);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -2900,21 +2901,20 @@ static int grow_device_fs(struct device_set *devset, const char *hash, uint64_t
|
||||
|
||||
if (size <= base_size) {
|
||||
return 0;
|
||||
- } else {
|
||||
- DEBUG("devmapper: new fs size is larger than old basesize, start to grow fs");
|
||||
- device_info = lookup_device(devset, hash);
|
||||
- if (device_info == NULL) {
|
||||
- ERROR("devmapper: lookup device %s failed", hash);
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
+ }
|
||||
|
||||
- if (grow_fs(devset, device_info->info) != 0) {
|
||||
- ret = -1;
|
||||
- goto out;
|
||||
- }
|
||||
+ DEBUG("devmapper: new fs size is larger than old basesize, start to grow fs");
|
||||
+ device_info = lookup_device(devset, hash);
|
||||
+ if (device_info == NULL) {
|
||||
+ ERROR("devmapper: lookup device %s failed", hash);
|
||||
+ return -1;
|
||||
}
|
||||
-out:
|
||||
+
|
||||
+ if (grow_fs(devset, device_info->info) != 0) {
|
||||
+ ret = -1;
|
||||
+ }
|
||||
+
|
||||
+ devmapper_device_info_ref_dec(device_info);
|
||||
return ret;
|
||||
}
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
72
0033-device-mapper-bugfix.patch
Normal file
72
0033-device-mapper-bugfix.patch
Normal file
@ -0,0 +1,72 @@
|
||||
From 4b59b86a191a43d88423a1f2659392b8bd9ff849 Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Wed, 26 Oct 2022 16:57:41 +0800
|
||||
Subject: [PATCH 33/39] device mapper bugfix
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
.../layer_store/graphdriver/devmapper/driver_devmapper.c | 9 +++++++--
|
||||
.../graphdriver/devmapper/wrapper_devmapper.c | 8 ++++----
|
||||
2 files changed, 11 insertions(+), 6 deletions(-)
|
||||
|
||||
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
|
||||
index 0a4e5e57..dd231bd6 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
|
||||
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/driver_devmapper.c
|
||||
@@ -231,6 +231,9 @@ char *devmapper_mount_layer(const char *id, const struct graphdriver *driver,
|
||||
if (rootfs == NULL) {
|
||||
ERROR("Failed to join devmapper rootfs %s", mnt_point_dir);
|
||||
ret = -1;
|
||||
+ if (unmount_device(id, mnt_point_dir, driver->devset) != 0) {
|
||||
+ DEBUG("devmapper: unmount %s failed", mnt_point_dir);
|
||||
+ }
|
||||
goto out;
|
||||
}
|
||||
|
||||
@@ -246,6 +249,7 @@ char *devmapper_mount_layer(const char *id, const struct graphdriver *driver,
|
||||
id_file = util_path_join(mnt_point_dir, "id");
|
||||
if (!util_file_exists(id_file)) {
|
||||
if (util_atomic_write_file(id_file, id, strlen(id), SECURE_CONFIG_FILE_MODE, true) != 0) {
|
||||
+ ret = -1;
|
||||
if (unmount_device(id, mnt_point_dir, driver->devset) != 0) {
|
||||
DEBUG("devmapper: unmount %s failed", mnt_point_dir);
|
||||
}
|
||||
@@ -350,13 +354,14 @@ int devmapper_apply_diff(const char *id, const struct graphdriver *driver, const
|
||||
if (archive_unpack(content, layer_fs, &options, &err) != 0) {
|
||||
ERROR("devmapper: failed to unpack to %s: %s", layer_fs, err);
|
||||
ret = -1;
|
||||
- goto out;
|
||||
+ goto umount_out;
|
||||
}
|
||||
|
||||
+umount_out:
|
||||
+ // umount layer if devmapper_mount_layer success
|
||||
if (devmapper_umount_layer(id, driver) != 0) {
|
||||
ERROR("devmapper: failed to umount layer %s", id);
|
||||
ret = -1;
|
||||
- goto out;
|
||||
}
|
||||
|
||||
out:
|
||||
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
|
||||
index 7ae1fd40..c8f3d6d8 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
|
||||
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/wrapper_devmapper.c
|
||||
@@ -28,10 +28,10 @@
|
||||
#include "utils.h"
|
||||
#include "err_msg.h"
|
||||
|
||||
-static bool g_dm_saw_busy = false;
|
||||
-static bool g_dm_saw_exist = false;
|
||||
-static bool g_dm_saw_enxio = false; // no such device or address
|
||||
-static bool g_dm_saw_eno_data = false; // no data available
|
||||
+static __thread bool g_dm_saw_busy = false;
|
||||
+static __thread bool g_dm_saw_exist = false;
|
||||
+static __thread bool g_dm_saw_enxio = false; // no such device or address
|
||||
+static __thread bool g_dm_saw_eno_data = false; // no data available
|
||||
static int64_t dm_udev_wait_timeout = 0;
|
||||
|
||||
char *dev_strerror(int errnum)
|
||||
--
|
||||
2.25.1
|
||||
|
||||
25
0034-delete-syncCloseSem-when-close-all-wssession.patch
Normal file
25
0034-delete-syncCloseSem-when-close-all-wssession.patch
Normal file
@ -0,0 +1,25 @@
|
||||
From 1111a16537bddf5d272f58bd1b67969f105a426d Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Fri, 28 Oct 2022 11:21:19 +0800
|
||||
Subject: [PATCH 34/39] delete syncCloseSem when close all wssession
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
src/daemon/entry/cri/websocket/service/ws_server.cc | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/src/daemon/entry/cri/websocket/service/ws_server.cc b/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
index 6438c4d7..a9b58685 100644
|
||||
--- a/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
+++ b/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
@@ -250,6 +250,7 @@ void WebsocketServer::CloseAllWsSession()
|
||||
close(it->second->pipes.at(0));
|
||||
close(it->second->pipes.at(1));
|
||||
(void)sem_destroy(it->second->syncCloseSem);
|
||||
+ delete it->second->syncCloseSem;
|
||||
delete it->second->sessionMutex;
|
||||
delete it->second;
|
||||
}
|
||||
--
|
||||
2.25.1
|
||||
|
||||
187
0035-improve-debug-information-for-console-io.patch
Normal file
187
0035-improve-debug-information-for-console-io.patch
Normal file
@ -0,0 +1,187 @@
|
||||
From b0022ff6d820d17428aa04e6be148e84dade0855 Mon Sep 17 00:00:00 2001
|
||||
From: haozi007 <liuhao27@huawei.com>
|
||||
Date: Fri, 28 Oct 2022 16:32:03 +0800
|
||||
Subject: [PATCH 35/39] [improve] debug information for console io
|
||||
|
||||
Signed-off-by: haozi007 <liuhao27@huawei.com>
|
||||
---
|
||||
.../entry/cri/websocket/service/ws_server.cc | 22 +++++++++++++------
|
||||
src/daemon/modules/events/collector.c | 12 +++++-----
|
||||
src/utils/console/console.c | 8 ++++++-
|
||||
src/utils/cutils/io_wrapper.h | 11 ++++++++++
|
||||
4 files changed, 39 insertions(+), 14 deletions(-)
|
||||
|
||||
diff --git a/src/daemon/entry/cri/websocket/service/ws_server.cc b/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
index a9b58685..41bb3fe8 100644
|
||||
--- a/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
+++ b/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
@@ -79,17 +79,25 @@ int SessionData::PushMessage(unsigned char *message)
|
||||
|
||||
sessionMutex->lock();
|
||||
|
||||
- // In extreme scenarios, websocket data cannot be processed,
|
||||
- // ignore the data coming in later to prevent iSulad from getting stuck
|
||||
- if (close || buffer.size() >= FIFO_LIST_BUFFER_MAX_LEN) {
|
||||
- free(message);
|
||||
+ if (!close && buffer.size() < FIFO_LIST_BUFFER_MAX_LEN) {
|
||||
+ buffer.push_back(message);
|
||||
sessionMutex->unlock();
|
||||
- return -1;
|
||||
+ return 0;
|
||||
}
|
||||
|
||||
- buffer.push_back(message);
|
||||
+ // In extreme scenarios, websocket data cannot be processed,
|
||||
+ // ignore the data coming in later to prevent iSulad from getting stuck
|
||||
+ free(message);
|
||||
sessionMutex->unlock();
|
||||
- return 0;
|
||||
+
|
||||
+ if (close) {
|
||||
+ DEBUG("Closed session");
|
||||
+ }
|
||||
+ if (buffer.size() >= FIFO_LIST_BUFFER_MAX_LEN) {
|
||||
+ ERROR("Too large: %zu message!", buffer.size());
|
||||
+ }
|
||||
+
|
||||
+ return -1;
|
||||
}
|
||||
|
||||
bool SessionData::IsClosed()
|
||||
diff --git a/src/daemon/modules/events/collector.c b/src/daemon/modules/events/collector.c
|
||||
index 9dc4dbe7..433cb88b 100644
|
||||
--- a/src/daemon/modules/events/collector.c
|
||||
+++ b/src/daemon/modules/events/collector.c
|
||||
@@ -339,28 +339,28 @@ static void supplement_annotations_for_container_msg(const container_t *cont, co
|
||||
struct isulad_events_format *format_msg)
|
||||
{
|
||||
if (supplement_pid_for_container_msg(cont, msg, format_msg) != 0) {
|
||||
- ERROR("Failed to supplement pid info");
|
||||
+ WARN("Failed to supplement pid info");
|
||||
}
|
||||
|
||||
if (supplement_exitcode_for_container_msg(cont, msg, format_msg) != 0) {
|
||||
- ERROR("Failed to supplement exitCode info");
|
||||
+ WARN("Failed to supplement exitCode info");
|
||||
}
|
||||
|
||||
if (supplement_image_for_container_msg(cont, msg, format_msg) != 0) {
|
||||
- ERROR("Failed to supplement image info");
|
||||
+ WARN("Failed to supplement image info");
|
||||
}
|
||||
|
||||
if (supplement_name_for_container_msg(cont, msg, format_msg) != 0) {
|
||||
- ERROR("Failed to supplement name info");
|
||||
+ WARN("Failed to supplement name info");
|
||||
}
|
||||
|
||||
if (supplement_labels_for_container_msg(cont, msg, format_msg) != 0) {
|
||||
- ERROR("Failed to supplement label info");
|
||||
+ WARN("Failed to supplement label info");
|
||||
}
|
||||
|
||||
if (strlen(msg->extra_annations) != 0) {
|
||||
if (util_array_append(&format_msg->annotations, msg->extra_annations) != 0) {
|
||||
- ERROR("Failed to supplement extra annations info");
|
||||
+ WARN("Failed to supplement extra annations info");
|
||||
}
|
||||
}
|
||||
|
||||
diff --git a/src/utils/console/console.c b/src/utils/console/console.c
|
||||
index 3565eef3..d5e5d9af 100644
|
||||
--- a/src/utils/console/console.c
|
||||
+++ b/src/utils/console/console.c
|
||||
@@ -100,7 +100,7 @@ static int console_writer_write_data(const struct io_write_wrapper *writer, cons
|
||||
}
|
||||
ret = writer->write_func(writer->context, buf, (size_t)len);
|
||||
if (ret <= 0 || ret != len) {
|
||||
- ERROR("failed to write, error:%s", strerror(errno));
|
||||
+ ERROR("Failed to write, type: %d, expect: %zd, wrote: %zd, error: %s!", writer->io_type, len, ret, strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
@@ -401,6 +401,7 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin
|
||||
if (fifoinfd >= 0) {
|
||||
ts.stdin_reader = stdinfd;
|
||||
ts.stdin_writer.context = &fifoinfd;
|
||||
+ ts.stdin_writer.io_type = FIFO_IN_IO;
|
||||
ts.stdin_writer.write_func = fd_write_function;
|
||||
if (tty) {
|
||||
ret = epoll_loop_add_handler(&descr, ts.stdin_reader, console_cb_tty_stdin_with_escape, &ts);
|
||||
@@ -418,6 +419,7 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin
|
||||
if (fifooutfd >= 0) {
|
||||
ts.stdout_reader = fifooutfd;
|
||||
ts.stdout_writer.context = &stdoutfd;
|
||||
+ ts.stdin_writer.io_type = FIFO_OUT_IO;
|
||||
ts.stdout_writer.write_func = fd_write_function;
|
||||
ret = epoll_loop_add_handler(&descr, ts.stdout_reader, console_cb_stdio_copy, &ts);
|
||||
if (ret) {
|
||||
@@ -429,6 +431,7 @@ int console_loop_with_std_fd(int stdinfd, int stdoutfd, int stderrfd, int fifoin
|
||||
if (fifoerrfd >= 0) {
|
||||
ts.stderr_reader = fifoerrfd;
|
||||
ts.stderr_writer.context = &stderrfd;
|
||||
+ ts.stdin_writer.io_type = FIFO_ERR_IO;
|
||||
ts.stderr_writer.write_func = fd_write_function;
|
||||
ret = epoll_loop_add_handler(&descr, ts.stderr_reader, console_cb_stdio_copy, &ts);
|
||||
if (ret) {
|
||||
@@ -477,18 +480,21 @@ int console_loop_io_copy(int sync_fd, const int *srcfds, struct io_write_wrapper
|
||||
ts[i].stdin_reader = srcfds[i];
|
||||
ts[i].stdin_writer.context = writers[i].context;
|
||||
ts[i].stdin_writer.write_func = writers[i].write_func;
|
||||
+ ts[i].stdin_writer.io_type = FUNC_IN_IO;
|
||||
ret = epoll_loop_add_handler(&descr, ts[i].stdin_reader, console_cb_stdio_copy, &ts[i]);
|
||||
} else if (channels[i] == STDOUT_CHANNEL) {
|
||||
// Reusing ts.stdout_reader and ts.stdout_writer for coping io
|
||||
ts[i].stdout_reader = srcfds[i];
|
||||
ts[i].stdout_writer.context = writers[i].context;
|
||||
ts[i].stdout_writer.write_func = writers[i].write_func;
|
||||
+ ts[i].stdin_writer.io_type = FUNC_OUT_IO;
|
||||
ret = epoll_loop_add_handler(&descr, ts[i].stdout_reader, console_cb_stdio_copy, &ts[i]);
|
||||
} else {
|
||||
// Reusing ts.stderr_reader and ts.stderr_writer for coping io
|
||||
ts[i].stderr_reader = srcfds[i];
|
||||
ts[i].stderr_writer.context = writers[i].context;
|
||||
ts[i].stderr_writer.write_func = writers[i].write_func;
|
||||
+ ts[i].stdin_writer.io_type = FUNC_ERR_IO;
|
||||
ret = epoll_loop_add_handler(&descr, ts[i].stderr_reader, console_cb_stdio_copy, &ts[i]);
|
||||
}
|
||||
if (ret != 0) {
|
||||
diff --git a/src/utils/cutils/io_wrapper.h b/src/utils/cutils/io_wrapper.h
|
||||
index 0134a822..a9340d01 100644
|
||||
--- a/src/utils/cutils/io_wrapper.h
|
||||
+++ b/src/utils/cutils/io_wrapper.h
|
||||
@@ -21,6 +21,15 @@
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
+enum {
|
||||
+ FIFO_IN_IO = 0,
|
||||
+ FIFO_OUT_IO,
|
||||
+ FIFO_ERR_IO,
|
||||
+ FUNC_IN_IO,
|
||||
+ FUNC_OUT_IO,
|
||||
+ FUNC_ERR_IO,
|
||||
+};
|
||||
+
|
||||
typedef ssize_t (*io_write_func_t)(void *context, const void *data, size_t len);
|
||||
typedef int (*io_close_func_t)(void *context, char **err);
|
||||
|
||||
@@ -28,6 +37,7 @@ struct io_write_wrapper {
|
||||
void *context;
|
||||
io_write_func_t write_func;
|
||||
io_close_func_t close_func;
|
||||
+ int io_type;
|
||||
};
|
||||
|
||||
typedef ssize_t (*io_read_func_t)(void *context, void *buf, size_t len);
|
||||
@@ -36,6 +46,7 @@ struct io_read_wrapper {
|
||||
void *context;
|
||||
io_read_func_t read;
|
||||
io_close_func_t close;
|
||||
+ int io_type;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
--
|
||||
2.25.1
|
||||
|
||||
288
0036-add-ut-for-file.patch
Normal file
288
0036-add-ut-for-file.patch
Normal file
@ -0,0 +1,288 @@
|
||||
From afe09041af292ae529ba8071e0737be778223853 Mon Sep 17 00:00:00 2001
|
||||
From: songbuhuang <544824346@qq.com>
|
||||
Date: Sat, 29 Oct 2022 16:35:21 +0800
|
||||
Subject: [PATCH 36/39] add ut for file
|
||||
|
||||
Signed-off-by: songbuhuang <544824346@qq.com>
|
||||
---
|
||||
test/cutils/CMakeLists.txt | 1 +
|
||||
test/cutils/utils_file/CMakeLists.txt | 18 ++
|
||||
test/cutils/utils_file/utils_file_ut.cc | 229 ++++++++++++++++++++++++
|
||||
3 files changed, 248 insertions(+)
|
||||
create mode 100644 test/cutils/utils_file/CMakeLists.txt
|
||||
create mode 100644 test/cutils/utils_file/utils_file_ut.cc
|
||||
|
||||
diff --git a/test/cutils/CMakeLists.txt b/test/cutils/CMakeLists.txt
|
||||
index 2447b781..11e0ee90 100644
|
||||
--- a/test/cutils/CMakeLists.txt
|
||||
+++ b/test/cutils/CMakeLists.txt
|
||||
@@ -29,6 +29,7 @@ add_subdirectory(utils_network)
|
||||
add_subdirectory(utils_aes)
|
||||
add_subdirectory(utils_error)
|
||||
add_subdirectory(utils_fs)
|
||||
+add_subdirectory(utils_file)
|
||||
add_subdirectory(utils_filters)
|
||||
add_subdirectory(utils_timestamp)
|
||||
add_subdirectory(utils_mount_spec)
|
||||
diff --git a/test/cutils/utils_file/CMakeLists.txt b/test/cutils/utils_file/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..20317e15
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_file/CMakeLists.txt
|
||||
@@ -0,0 +1,18 @@
|
||||
+project(iSulad_UT)
|
||||
+
|
||||
+SET(EXE utils_file_ut)
|
||||
+
|
||||
+add_executable(${EXE}
|
||||
+ utils_file_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
|
||||
+ )
|
||||
+
|
||||
+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_file/utils_file_ut.cc b/test/cutils/utils_file/utils_file_ut.cc
|
||||
new file mode 100644
|
||||
index 00000000..ccd60ba4
|
||||
--- /dev/null
|
||||
+++ b/test/cutils/utils_file/utils_file_ut.cc
|
||||
@@ -0,0 +1,229 @@
|
||||
+/*
|
||||
+ * 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_file unit test
|
||||
+ * Author: huangsong
|
||||
+ * Create: 2022-10-26
|
||||
+ */
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+#include <stdio.h>
|
||||
+#include <unistd.h>
|
||||
+#include <fcntl.h>
|
||||
+#include <gtest/gtest.h>
|
||||
+#include "mock.h"
|
||||
+#include "utils_file.h"
|
||||
+#include "constants.h"
|
||||
+#include "map.h"
|
||||
+
|
||||
+#define FILE_PERMISSION_TEST 0755
|
||||
+
|
||||
+TEST(utils_file, test_util_dir_exists)
|
||||
+{
|
||||
+ ASSERT_EQ(util_dir_exists(nullptr), false);
|
||||
+
|
||||
+ const char *path = "/tmp/test";
|
||||
+ ASSERT_EQ(util_dir_exists(path), false);
|
||||
+ ASSERT_EQ(util_mkdir_p(path, FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_dir_exists(path), true);
|
||||
+ ASSERT_EQ(util_path_remove(path), 0);
|
||||
+
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_fileself_exists)
|
||||
+{
|
||||
+ ASSERT_EQ(util_fileself_exists(nullptr), false);
|
||||
+
|
||||
+ std::string path = "/tmp/test";
|
||||
+ std::string path_link = "/tmp/test/link";
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_fileself_exists(path_link.c_str()), false);
|
||||
+ ASSERT_EQ(symlink(path.c_str(),path_link.c_str()), 0);
|
||||
+ ASSERT_EQ(util_fileself_exists(path_link.c_str()), true);
|
||||
+ ASSERT_EQ(util_path_remove(path_link.c_str()), 0);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_file_exists)
|
||||
+{
|
||||
+ ASSERT_EQ(util_file_exists(nullptr), false);
|
||||
+
|
||||
+ std::string path = "/tmp/test";
|
||||
+ ASSERT_EQ(util_file_exists(path.c_str()), false);
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_file_exists(path.c_str()), true);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+
|
||||
+TEST(utils_file, test_util_recursive_rmdir)
|
||||
+{
|
||||
+ ASSERT_EQ(util_recursive_rmdir(nullptr,0), -1);
|
||||
+
|
||||
+ std::string path = "/tmp/test";
|
||||
+ std::string path_link = "/tmp/test/link";
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_mkdir_p(path_link.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_recursive_rmdir(path.c_str(),1), 0);
|
||||
+ ASSERT_EQ(util_file_exists(path.c_str()), false);
|
||||
+ ASSERT_EQ(util_file_exists(path_link.c_str()), false);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_ensure_path)
|
||||
+{
|
||||
+ char *rpath = NULL;
|
||||
+ std::string path = "/tmp/test";
|
||||
+ ASSERT_EQ(util_ensure_path(nullptr,path.c_str()), -1);
|
||||
+ ASSERT_EQ(util_ensure_path(&rpath,nullptr), -1);
|
||||
+
|
||||
+ ASSERT_EQ(util_file_exists(path.c_str()), false);
|
||||
+ ASSERT_EQ(util_ensure_path(&rpath,path.c_str()), 0);
|
||||
+ ASSERT_EQ(util_file_exists(rpath), true);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_build_dir)
|
||||
+{
|
||||
+ ASSERT_EQ(util_build_dir(nullptr), -1);
|
||||
+
|
||||
+ std::string path = "/tmp/test/file";
|
||||
+ ASSERT_EQ(util_build_dir(path.c_str()), 0);
|
||||
+ ASSERT_EQ(util_file_exists("/tmp"), true);
|
||||
+ ASSERT_EQ(util_file_exists("/tmp/test"), true);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_human_size)
|
||||
+{
|
||||
+ uint64_t b = 1;
|
||||
+ uint64_t kb = 1024;
|
||||
+ uint64_t mb = 1024 * 1024;
|
||||
+ uint64_t gb = 1024 * 1024 * 1024;
|
||||
+ ASSERT_STREQ(util_human_size(b), "1B");
|
||||
+ ASSERT_STREQ(util_human_size(kb), "1KB");
|
||||
+ ASSERT_STREQ(util_human_size(mb), "1MB");
|
||||
+ ASSERT_STREQ(util_human_size(gb), "1GB");
|
||||
+
|
||||
+ ASSERT_STREQ(util_human_size_decimal(b), "1B");
|
||||
+ ASSERT_STREQ(util_human_size_decimal(kb), "1.000KB");
|
||||
+ ASSERT_STREQ(util_human_size_decimal(mb), "1.000MB");
|
||||
+ ASSERT_STREQ(util_human_size_decimal(gb), "1.000GB");
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_open)
|
||||
+{
|
||||
+ std::string path = "/tmp/test";
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_NE(util_open(path.c_str(), O_RDONLY, 0), -1);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_add_path)
|
||||
+{
|
||||
+ std::string path = "/tmp/test/";
|
||||
+ std::string add_path = "add";
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_STREQ(util_add_path(path.c_str(),add_path.c_str()), "/tmp/test/add");
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+
|
||||
+ std::string path1 = "/tmp/test";
|
||||
+ ASSERT_EQ(util_mkdir_p(path1.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_STREQ(util_add_path(path1.c_str(),add_path.c_str()), "/tmp/add");
|
||||
+ ASSERT_EQ(util_path_remove(path1.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_verify_file_and_get_real_path)
|
||||
+{
|
||||
+ std::string path = "/tmp/test";
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_STREQ(verify_file_and_get_real_path(path.c_str()),"/tmp/test");
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_look_path)
|
||||
+{
|
||||
+ std::string path = "/usr/bin/nsenter";
|
||||
+ char *err = NULL;
|
||||
+ ASSERT_STREQ(look_path("nsenter",&err),path.c_str());
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_copy_file)
|
||||
+{
|
||||
+ std::string path = "/tmp/test";
|
||||
+ ASSERT_EQ(util_copy_file("/etc/hosts",path.c_str(),NETWORK_MOUNT_FILE_MODE), 0);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_copy_file("/etc/hosts",path.c_str(),NETWORK_MOUNT_FILE_MODE), -1);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_utils_calculate_dir_size_without_hardlink)
|
||||
+{
|
||||
+ std::string path = "/tmp/test";
|
||||
+ std::string hosts = "/etc/hosts";
|
||||
+ ASSERT_EQ(util_copy_file(hosts.c_str(),path.c_str(),NETWORK_MOUNT_FILE_MODE), 0);
|
||||
+ int64_t total_size = 0;
|
||||
+ int64_t total_inodes = 0;
|
||||
+ utils_calculate_dir_size_without_hardlink("/tmp/", &total_size,&total_inodes);
|
||||
+ ASSERT_NE(total_size, 0);
|
||||
+ ASSERT_NE(total_inodes, 0);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+static bool parse_checked_layer_cb(const char *line, void *context)
|
||||
+{
|
||||
+ printf("this is stdout\n");
|
||||
+ fprintf(stderr, "this is stderr\n");
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_proc_file_line_by_line)
|
||||
+{
|
||||
+ std::string path = "/tmp/test";
|
||||
+ std::string content = "hello world";
|
||||
+ int fd;
|
||||
+ fd = util_open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, DEFAULT_SECURE_FILE_MODE);
|
||||
+ ASSERT_EQ(util_write_nointr_in_total(fd, content.c_str(), strlen(content.c_str())),11);
|
||||
+ FILE *fp = NULL;
|
||||
+ map_t *checked_layers = NULL;
|
||||
+ fp = util_fopen(path.c_str(), "r");
|
||||
+ checked_layers = map_new(MAP_STR_BOOL, MAP_DEFAULT_CMP_FUNC, MAP_DEFAULT_FREE_FUNC);
|
||||
+ ASSERT_EQ(util_proc_file_line_by_line(fp, parse_checked_layer_cb, (void *)checked_layers),0);
|
||||
+ fclose(fp);
|
||||
+ ASSERT_EQ(util_path_remove(path.c_str()), 0);
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_recursive_remove_path)
|
||||
+{
|
||||
+ ASSERT_EQ(util_recursive_remove_path(nullptr), -1);
|
||||
+
|
||||
+ std::string path = "/tmp/test";
|
||||
+ std::string path_link = "/tmp/test/link";
|
||||
+ ASSERT_EQ(util_mkdir_p(path.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_mkdir_p(path_link.c_str(), FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_recursive_remove_path(path.c_str()), 0);
|
||||
+ ASSERT_EQ(util_file_exists(path.c_str()), false);
|
||||
+ ASSERT_EQ(util_file_exists(path_link.c_str()), false);
|
||||
+
|
||||
+}
|
||||
+
|
||||
+TEST(utils_file, test_util_copy_dir_recursive)
|
||||
+{
|
||||
+ char *path = (char*)"/tmp/test1/";
|
||||
+ char *src = (char*)"/tmp/test/";
|
||||
+ ASSERT_EQ(util_mkdir_p(path, FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_mkdir_p(src, FILE_PERMISSION_TEST), 0);
|
||||
+ ASSERT_EQ(util_copy_dir_recursive(path,src), 0);
|
||||
+ ASSERT_EQ(util_recursive_remove_path(path), 0);
|
||||
+ ASSERT_EQ(util_recursive_remove_path(src), 0);
|
||||
+}
|
||||
+
|
||||
+
|
||||
--
|
||||
2.25.1
|
||||
|
||||
688
0037-Add-extend-C-for-header-files.patch
Normal file
688
0037-Add-extend-C-for-header-files.patch
Normal file
@ -0,0 +1,688 @@
|
||||
From d7b324c04b4b353270216887b05e245337942b97 Mon Sep 17 00:00:00 2001
|
||||
From: zhongtao <taozh97@163.com>
|
||||
Date: Mon, 24 Oct 2022 20:46:47 +0800
|
||||
Subject: [PATCH 37/39] Add extend C for header files
|
||||
|
||||
Signed-off-by: zhongtao <taozh97@163.com>
|
||||
---
|
||||
src/cmd/isula/stream/attach.h | 9 +++++++++
|
||||
src/cmd/isula/stream/cp.h | 8 ++++++++
|
||||
src/cmd/isula/stream/exec.h | 8 ++++++++
|
||||
src/daemon/modules/api/log_gather_api.h | 8 ++++++++
|
||||
src/daemon/modules/api/plugin_api.h | 8 ++++++++
|
||||
src/daemon/modules/container/container_events_handler.h | 8 ++++++++
|
||||
.../modules/container/restart_manager/restartmanager.h | 8 ++++++++
|
||||
src/daemon/modules/container/supervisor/supervisor.h | 8 ++++++++
|
||||
src/daemon/modules/events/monitord.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/db/db_all.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/db/db_common.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/db/db_images_common.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/db/sqlite_common.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/embedded_image.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/lim.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/snapshot/embedded.h | 8 ++++++++
|
||||
src/daemon/modules/image/embedded/snapshot/snapshot.h | 8 ++++++++
|
||||
.../modules/image/embedded/snapshot/snapshot_def.h | 7 +++++++
|
||||
src/daemon/modules/image/external/ext_image.h | 8 ++++++++
|
||||
src/daemon/modules/image/oci/registry_type.h | 8 ++++++++
|
||||
.../graphdriver/devmapper/devices_constants.h | 8 ++++++++
|
||||
src/daemon/modules/plugin/pspec.h | 8 ++++++++
|
||||
src/daemon/modules/spec/specs_mount.h | 8 ++++++++
|
||||
src/daemon/modules/spec/specs_security.h | 8 ++++++++
|
||||
src/utils/buffer/buffer.h | 8 ++++++++
|
||||
src/utils/cutils/linked_list.h | 8 ++++++++
|
||||
src/utils/http/parser.h | 8 ++++++++
|
||||
27 files changed, 216 insertions(+)
|
||||
|
||||
diff --git a/src/cmd/isula/stream/attach.h b/src/cmd/isula/stream/attach.h
|
||||
index 2e71852b..9792da9d 100644
|
||||
--- a/src/cmd/isula/stream/attach.h
|
||||
+++ b/src/cmd/isula/stream/attach.h
|
||||
@@ -18,9 +18,18 @@
|
||||
#include "client_arguments.h"
|
||||
#include "isula_libutils/container_inspect.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
extern const char g_cmd_attach_desc[];
|
||||
extern const char g_cmd_attach_usage[];
|
||||
extern struct client_arguments g_cmd_attach_args;
|
||||
int inspect_container(const struct client_arguments *args, container_inspect **inspect_data);
|
||||
int cmd_attach_main(int argc, const char **argv);
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // CMD_ISULA_STREAM_ATTACH_H
|
||||
diff --git a/src/cmd/isula/stream/cp.h b/src/cmd/isula/stream/cp.h
|
||||
index 821a3887..491d5421 100644
|
||||
--- a/src/cmd/isula/stream/cp.h
|
||||
+++ b/src/cmd/isula/stream/cp.h
|
||||
@@ -17,9 +17,17 @@
|
||||
|
||||
#include "client_arguments.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
extern const char g_cmd_cp_desc[];
|
||||
extern const char g_cmd_cp_usage[];
|
||||
extern struct client_arguments g_cmd_cp_args;
|
||||
int cmd_cp_main(int argc, const char **argv);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // CMD_ISULA_STREAM_CP_H
|
||||
diff --git a/src/cmd/isula/stream/exec.h b/src/cmd/isula/stream/exec.h
|
||||
index 6161c62f..d507d71e 100644
|
||||
--- a/src/cmd/isula/stream/exec.h
|
||||
+++ b/src/cmd/isula/stream/exec.h
|
||||
@@ -22,6 +22,10 @@
|
||||
#include "attach.h"
|
||||
#include "command_parser.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
#define EXEC_OPTIONS(cmdargs) \
|
||||
{ \
|
||||
CMD_OPT_TYPE_CALLBACK, false, "env", 'e', &(cmdargs).extra_env, "Set environment variables", \
|
||||
@@ -51,4 +55,8 @@ extern const char g_cmd_exec_usage[];
|
||||
extern struct client_arguments g_cmd_exec_args;
|
||||
int cmd_exec_main(int argc, const char **argv);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // CMD_ISULA_STREAM_EXEC_H
|
||||
diff --git a/src/daemon/modules/api/log_gather_api.h b/src/daemon/modules/api/log_gather_api.h
|
||||
index b72a5800..2c98ff11 100644
|
||||
--- a/src/daemon/modules/api/log_gather_api.h
|
||||
+++ b/src/daemon/modules/api/log_gather_api.h
|
||||
@@ -22,6 +22,10 @@
|
||||
|
||||
#define REV_BUF_SIZE 4096
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct log_gather_conf {
|
||||
const char *fifo_path;
|
||||
int *exitcode;
|
||||
@@ -40,5 +44,9 @@ enum log_gather_driver {
|
||||
|
||||
void *log_gather(void *arg);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/api/plugin_api.h b/src/daemon/modules/api/plugin_api.h
|
||||
index 303ba6bf..bf138ec1 100644
|
||||
--- a/src/daemon/modules/api/plugin_api.h
|
||||
+++ b/src/daemon/modules/api/plugin_api.h
|
||||
@@ -41,6 +41,10 @@
|
||||
#define PLUGIN_EVENT_CONTAINER_POST_STOP (1UL << 2)
|
||||
#define PLUGIN_EVENT_CONTAINER_POST_REMOVE (1UL << 3)
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
typedef struct plugin_manifest {
|
||||
uint64_t init_type;
|
||||
uint64_t watch_event;
|
||||
@@ -109,4 +113,8 @@ int plugin_event_container_post_stop(const container_t *cont);
|
||||
int plugin_event_container_post_remove(const container_t *cont);
|
||||
int plugin_event_container_post_remove2(const char *cid, const oci_runtime_spec *oci);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // DAEMON_MODULES_API_PLUGIN_API_H
|
||||
diff --git a/src/daemon/modules/container/container_events_handler.h b/src/daemon/modules/container/container_events_handler.h
|
||||
index f38f293d..77cf5d06 100644
|
||||
--- a/src/daemon/modules/container/container_events_handler.h
|
||||
+++ b/src/daemon/modules/container/container_events_handler.h
|
||||
@@ -22,10 +22,18 @@
|
||||
#include "container_api.h"
|
||||
#include "events_format.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
container_events_handler_t *container_events_handler_new();
|
||||
|
||||
void container_events_handler_free(container_events_handler_t *handler);
|
||||
|
||||
int container_events_handler_post_events(const struct isulad_events_format *event);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // DAEMON_MODULES_CONTAINER_CONTAINER_EVENTS_HANDLER_H
|
||||
diff --git a/src/daemon/modules/container/restart_manager/restartmanager.h b/src/daemon/modules/container/restart_manager/restartmanager.h
|
||||
index 1f5f13b3..106343b2 100644
|
||||
--- a/src/daemon/modules/container/restart_manager/restartmanager.h
|
||||
+++ b/src/daemon/modules/container/restart_manager/restartmanager.h
|
||||
@@ -22,6 +22,10 @@
|
||||
#include "isula_libutils/host_config.h"
|
||||
#include "container_api.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
void restart_policy_free(host_config_restart_policy *policy);
|
||||
|
||||
restart_manager_t *restart_manager_new(const host_config_restart_policy *policy, int failure_count);
|
||||
@@ -43,4 +47,8 @@ int restart_manager_wait_cancel(restart_manager_t *rm, uint64_t timeout);
|
||||
|
||||
int container_restart_in_thread(const char *id, uint64_t timeout, int exit_code);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // DAEMON_MODULES_CONTAINER_RESTART_MANAGER_RESTARTMANAGER_H
|
||||
diff --git a/src/daemon/modules/container/supervisor/supervisor.h b/src/daemon/modules/container/supervisor/supervisor.h
|
||||
index e5b5a2e7..2b208c5a 100644
|
||||
--- a/src/daemon/modules/container/supervisor/supervisor.h
|
||||
+++ b/src/daemon/modules/container/supervisor/supervisor.h
|
||||
@@ -19,8 +19,16 @@
|
||||
|
||||
#include "container_unix.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
extern char *exit_fifo_name(const char *cont_state_path);
|
||||
|
||||
extern int new_supervisor();
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/src/daemon/modules/events/monitord.h b/src/daemon/modules/events/monitord.h
|
||||
index beace80e..1741983d 100644
|
||||
--- a/src/daemon/modules/events/monitord.h
|
||||
+++ b/src/daemon/modules/events/monitord.h
|
||||
@@ -20,6 +20,10 @@
|
||||
|
||||
#include "utils.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct monitord_sync_data {
|
||||
sem_t *monitord_sem;
|
||||
int *exit_code;
|
||||
@@ -27,4 +31,8 @@ struct monitord_sync_data {
|
||||
|
||||
int new_monitord(struct monitord_sync_data *msync);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/src/daemon/modules/image/embedded/db/db_all.h b/src/daemon/modules/image/embedded/db/db_all.h
|
||||
index 9fbe2729..e72777c2 100644
|
||||
--- a/src/daemon/modules/image/embedded/db/db_all.h
|
||||
+++ b/src/daemon/modules/image/embedded/db/db_all.h
|
||||
@@ -20,6 +20,10 @@
|
||||
#include <stdbool.h>
|
||||
#include "db_common.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct db_sninfo {
|
||||
char *snid;
|
||||
char *parent_snid;
|
||||
@@ -73,5 +77,9 @@ int db_read_all_images_info(struct db_all_images **image_info);
|
||||
|
||||
void db_all_imginfo_free(struct db_all_images *images_info);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/image/embedded/db/db_common.h b/src/daemon/modules/image/embedded/db/db_common.h
|
||||
index ab83599f..8ed1138c 100644
|
||||
--- a/src/daemon/modules/image/embedded/db/db_common.h
|
||||
+++ b/src/daemon/modules/image/embedded/db/db_common.h
|
||||
@@ -25,9 +25,17 @@
|
||||
#define DB_DEREF_ONLY 4
|
||||
#define DB_NOT_EXIST 5
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
int db_common_init(const char *rootpath);
|
||||
|
||||
void db_common_finish(void);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // DAEMON_MODULES_IMAGE_EMBEDDED_DB_DB_COMMON_H
|
||||
|
||||
diff --git a/src/daemon/modules/image/embedded/db/db_images_common.h b/src/daemon/modules/image/embedded/db/db_images_common.h
|
||||
index 1fde16cc..a35ea49f 100644
|
||||
--- a/src/daemon/modules/image/embedded/db/db_images_common.h
|
||||
+++ b/src/daemon/modules/image/embedded/db/db_images_common.h
|
||||
@@ -17,6 +17,10 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/* common interface definition for database */
|
||||
|
||||
struct db_single_image_info {
|
||||
@@ -32,5 +36,9 @@ struct db_all_images_info {
|
||||
struct db_single_image_info **images_info;
|
||||
};
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/image/embedded/db/sqlite_common.h b/src/daemon/modules/image/embedded/db/sqlite_common.h
|
||||
index 7562932c..8c5db83a 100644
|
||||
--- a/src/daemon/modules/image/embedded/db/sqlite_common.h
|
||||
+++ b/src/daemon/modules/image/embedded/db/sqlite_common.h
|
||||
@@ -19,6 +19,10 @@
|
||||
|
||||
#define DBNAME "sqlite.db"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
typedef int(*sqlite_callback_t)(void *, int, char **, char **);
|
||||
|
||||
sqlite3 *get_global_db();
|
||||
@@ -32,5 +36,9 @@ int db_sqlite_request(const char *stmt);
|
||||
int db_sqlite_request_callback(const char *stmt,
|
||||
sqlite_callback_t callback, void *data);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/image/embedded/embedded_image.h b/src/daemon/modules/image/embedded/embedded_image.h
|
||||
index 2177a40b..b1fafacf 100644
|
||||
--- a/src/daemon/modules/image/embedded/embedded_image.h
|
||||
+++ b/src/daemon/modules/image/embedded/embedded_image.h
|
||||
@@ -18,6 +18,10 @@
|
||||
#include <stdint.h>
|
||||
#include "image_api.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
bool embedded_detect(const char *image_name);
|
||||
|
||||
int embedded_prepare_rf(const im_prepare_request *request, char **real_rootfs);
|
||||
@@ -48,4 +52,8 @@ int embedded_init(const isulad_daemon_configs *args);
|
||||
|
||||
void embedded_exit();
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/src/daemon/modules/image/embedded/lim.h b/src/daemon/modules/image/embedded/lim.h
|
||||
index cb21884e..fb5bb414 100644
|
||||
--- a/src/daemon/modules/image/embedded/lim.h
|
||||
+++ b/src/daemon/modules/image/embedded/lim.h
|
||||
@@ -22,6 +22,10 @@
|
||||
#define IMAGE_DATA_TYPE_CONFIG "config"
|
||||
#define IMAGE_DATA_TYPE_CONFIG_PATH "config_path"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct image_creator {
|
||||
char *name;
|
||||
char *type;
|
||||
@@ -56,5 +60,9 @@ int lim_query_image_data(const char *name, const char *type,
|
||||
int lim_create_rw_layer(char *name, const char *id, char **options,
|
||||
char **mount_string);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/image/embedded/snapshot/embedded.h b/src/daemon/modules/image/embedded/snapshot/embedded.h
|
||||
index eaf4b588..e0cf7bab 100644
|
||||
--- a/src/daemon/modules/image/embedded/snapshot/embedded.h
|
||||
+++ b/src/daemon/modules/image/embedded/snapshot/embedded.h
|
||||
@@ -19,6 +19,10 @@
|
||||
#include "linked_list.h"
|
||||
#include "snapshot_def.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct snapshot_plugin ebd_plugin();
|
||||
|
||||
int ebd_create_layer(char *id, char *parent, uint32_t layer_attribute,
|
||||
@@ -31,5 +35,9 @@ int ebd_apply_diff(char *id, char *parent, char *archive, char *metadata);
|
||||
int ebd_generate_mount_string(struct db_image *imginfo,
|
||||
struct db_sninfo **sninfos, char **mount_string);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/image/embedded/snapshot/snapshot.h b/src/daemon/modules/image/embedded/snapshot/snapshot.h
|
||||
index dd2e42e7..fae6c8da 100644
|
||||
--- a/src/daemon/modules/image/embedded/snapshot/snapshot.h
|
||||
+++ b/src/daemon/modules/image/embedded/snapshot/snapshot.h
|
||||
@@ -22,11 +22,19 @@
|
||||
|
||||
#include "db_all.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
int snapshot_init(uint32_t driver_type);
|
||||
|
||||
int snapshot_generate_mount_string(uint32_t driver_type,
|
||||
struct db_image *imginfo,
|
||||
struct db_sninfo **sninfos, char **mount_string);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/image/embedded/snapshot/snapshot_def.h b/src/daemon/modules/image/embedded/snapshot/snapshot_def.h
|
||||
index fbc2c791..eaf397a6 100644
|
||||
--- a/src/daemon/modules/image/embedded/snapshot/snapshot_def.h
|
||||
+++ b/src/daemon/modules/image/embedded/snapshot/snapshot_def.h
|
||||
@@ -26,6 +26,10 @@
|
||||
|
||||
#define LAYER_NUM_MAX 125
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
typedef int(*create_layer_cb)(char *id, char *parent, uint32_t layer_attribute,
|
||||
char **options, char **mount_string);
|
||||
|
||||
@@ -44,6 +48,9 @@ struct snapshot_plugin {
|
||||
generate_mount_string_cb gms;
|
||||
};
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
|
||||
#endif
|
||||
|
||||
diff --git a/src/daemon/modules/image/external/ext_image.h b/src/daemon/modules/image/external/ext_image.h
|
||||
index ded2b8ca..17ef4d98 100644
|
||||
--- a/src/daemon/modules/image/external/ext_image.h
|
||||
+++ b/src/daemon/modules/image/external/ext_image.h
|
||||
@@ -26,6 +26,10 @@
|
||||
|
||||
#include "image_api.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
bool ext_detect(const char *image_name);
|
||||
int ext_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage);
|
||||
|
||||
@@ -46,4 +50,8 @@ int ext_logout(const im_logout_request *request);
|
||||
|
||||
int ext_init(const isulad_daemon_configs *args);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/src/daemon/modules/image/oci/registry_type.h b/src/daemon/modules/image/oci/registry_type.h
|
||||
index 11135250..bfc77f4a 100644
|
||||
--- a/src/daemon/modules/image/oci/registry_type.h
|
||||
+++ b/src/daemon/modules/image/oci/registry_type.h
|
||||
@@ -29,6 +29,10 @@
|
||||
#define MAX_LAYER_NUM 125
|
||||
#define ROOTFS_TYPE "layers"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
typedef struct {
|
||||
char *schema;
|
||||
char *realm;
|
||||
@@ -132,4 +136,8 @@ void free_challenge(challenge *c);
|
||||
void free_layer_blob(layer_blob *layer);
|
||||
void free_pull_desc(pull_descriptor *desc);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // DAEMON_MODULES_IMAGE_OCI_REGISTRY_TYPE_H
|
||||
diff --git a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h
|
||||
index 5b3db2bd..01bbfef7 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h
|
||||
+++ b/src/daemon/modules/image/oci/storage/layer_store/graphdriver/devmapper/devices_constants.h
|
||||
@@ -35,6 +35,10 @@
|
||||
|
||||
#define DEFAULT_DEVICE_SET_MODE 0700
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
typedef struct {
|
||||
map_t *map; // map string image_devmapper_device_info* key string will be strdup value ptr will not
|
||||
} metadata_store_t;
|
||||
@@ -73,4 +77,8 @@ struct device_set {
|
||||
bool user_base_size;
|
||||
};
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/src/daemon/modules/plugin/pspec.h b/src/daemon/modules/plugin/pspec.h
|
||||
index 618159b1..0ad26848 100644
|
||||
--- a/src/daemon/modules/plugin/pspec.h
|
||||
+++ b/src/daemon/modules/plugin/pspec.h
|
||||
@@ -19,6 +19,10 @@
|
||||
#include "isula_libutils/oci_runtime_spec.h"
|
||||
#include "isula_libutils/oci_runtime_pspec.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
/*
|
||||
* extract pspec from oci.
|
||||
* return NULL when failed. oci not modified.
|
||||
@@ -39,5 +43,9 @@ int set_pspec(oci_runtime_spec *oci, const char *data);
|
||||
*/
|
||||
char *merge_pspec(const char *base, const char *data);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif // DAEMON_MODULES_PLUGIN_PSPEC_H
|
||||
|
||||
diff --git a/src/daemon/modules/spec/specs_mount.h b/src/daemon/modules/spec/specs_mount.h
|
||||
index 07c07a37..3283d92b 100644
|
||||
--- a/src/daemon/modules/spec/specs_mount.h
|
||||
+++ b/src/daemon/modules/spec/specs_mount.h
|
||||
@@ -26,6 +26,10 @@
|
||||
#include "isula_libutils/oci_runtime_hooks.h"
|
||||
#include "isula_libutils/oci_runtime_spec.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
int adapt_settings_for_mounts(oci_runtime_spec *oci_spec, container_config *container_spec);
|
||||
|
||||
int merge_conf_mounts(oci_runtime_spec *oci_spec, host_config *host_spec,
|
||||
@@ -43,4 +47,8 @@ int merge_conf_device(oci_runtime_spec *oci_spec, host_config *host_spec);
|
||||
|
||||
int setup_ipc_dirs(host_config *host_spec, container_config_v2_common_config *v2_spec);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/src/daemon/modules/spec/specs_security.h b/src/daemon/modules/spec/specs_security.h
|
||||
index f33814d2..37315a95 100644
|
||||
--- a/src/daemon/modules/spec/specs_security.h
|
||||
+++ b/src/daemon/modules/spec/specs_security.h
|
||||
@@ -25,6 +25,10 @@
|
||||
#include "isula_libutils/container_config_v2.h"
|
||||
#include "isula_libutils/oci_runtime_spec.h"
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
int merge_default_seccomp_spec(oci_runtime_spec *oci_spec, const defs_process_capabilities *capabilities);
|
||||
int merge_caps(oci_runtime_spec *oci_spec, const char **adds, size_t adds_len, const char **drops, size_t drops_len);
|
||||
int refill_oci_process_capabilities(defs_process_capabilities **caps, const char **src_caps, size_t src_caps_len);
|
||||
@@ -36,4 +40,8 @@ int merge_seccomp(oci_runtime_spec *oci_spec, const char *seccomp_profile);
|
||||
int merge_selinux(oci_runtime_spec *oci_spec, container_config_v2_common_config *v2_spec);
|
||||
#endif
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
diff --git a/src/utils/buffer/buffer.h b/src/utils/buffer/buffer.h
|
||||
index 168a61f6..83276100 100644
|
||||
--- a/src/utils/buffer/buffer.h
|
||||
+++ b/src/utils/buffer/buffer.h
|
||||
@@ -19,6 +19,10 @@
|
||||
#include <strings.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct Buffer {
|
||||
char *contents;
|
||||
size_t bytes_used;
|
||||
@@ -32,4 +36,8 @@ size_t buffer_strlen(const Buffer *buf);
|
||||
void buffer_free(Buffer *buf);
|
||||
int buffer_append(Buffer *buf, const char *append, size_t len);
|
||||
void buffer_empty(Buffer *buf);
|
||||
+
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
#endif
|
||||
diff --git a/src/utils/cutils/linked_list.h b/src/utils/cutils/linked_list.h
|
||||
index 59acb2a8..3a87990a 100644
|
||||
--- a/src/utils/cutils/linked_list.h
|
||||
+++ b/src/utils/cutils/linked_list.h
|
||||
@@ -17,6 +17,10 @@
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct linked_list {
|
||||
void *elem;
|
||||
struct linked_list *next;
|
||||
@@ -122,5 +126,9 @@ static inline size_t linked_list_len(struct linked_list *list)
|
||||
return i;
|
||||
}
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
diff --git a/src/utils/http/parser.h b/src/utils/http/parser.h
|
||||
index 9a37bd7f..ce5fe5e7 100644
|
||||
--- a/src/utils/http/parser.h
|
||||
+++ b/src/utils/http/parser.h
|
||||
@@ -55,6 +55,10 @@
|
||||
|
||||
#define MIN(a, b) ((a) < (b) ? (a) : (b))
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
struct parsed_http_message {
|
||||
enum http_method method;
|
||||
int status_code;
|
||||
@@ -88,5 +92,9 @@ int parse_http(const char *buf, size_t len, struct parsed_http_message *m,
|
||||
enum http_parser_type type);
|
||||
char *get_header_value(const struct parsed_http_message *m, const char *header);
|
||||
|
||||
+#ifdef __cplusplus
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
#endif
|
||||
|
||||
--
|
||||
2.25.1
|
||||
|
||||
589
0038-feat-add-container-cleanup-module.patch
Normal file
589
0038-feat-add-container-cleanup-module.patch
Normal file
@ -0,0 +1,589 @@
|
||||
From 587aa25d7f44f79c28c3331b81bbc77efb7e1eb1 Mon Sep 17 00:00:00 2001
|
||||
From: "Neil.wrz" <wangrunze13@huawei.com>
|
||||
Date: Thu, 27 Oct 2022 00:45:53 -0700
|
||||
Subject: [PATCH 38/39] feat add container cleanup module
|
||||
|
||||
Signed-off-by: Neil.wrz <wangrunze13@huawei.com>
|
||||
---
|
||||
src/daemon/modules/api/image_api.h | 6 +
|
||||
src/daemon/modules/container/CMakeLists.txt | 3 +
|
||||
src/daemon/modules/container/container_unix.c | 2 +
|
||||
.../container/leftover_cleanup/CMakeLists.txt | 19 +++
|
||||
.../container/leftover_cleanup/cleanup.c | 135 ++++++++++++++++++
|
||||
.../container/leftover_cleanup/cleanup.h | 49 +++++++
|
||||
.../leftover_cleanup/oci_rootfs_clean.c | 71 +++++++++
|
||||
.../leftover_cleanup/oci_rootfs_clean.h | 30 ++++
|
||||
src/daemon/modules/image/image.c | 26 ++++
|
||||
src/daemon/modules/image/oci/oci_image.c | 5 +
|
||||
src/daemon/modules/image/oci/oci_image.h | 1 +
|
||||
.../oci/storage/rootfs_store/rootfs_store.c | 5 +
|
||||
.../oci/storage/rootfs_store/rootfs_store.h | 3 +
|
||||
.../modules/image/oci/storage/storage.c | 5 +
|
||||
.../modules/image/oci/storage/storage.h | 2 +
|
||||
15 files changed, 362 insertions(+)
|
||||
create mode 100644 src/daemon/modules/container/leftover_cleanup/CMakeLists.txt
|
||||
create mode 100644 src/daemon/modules/container/leftover_cleanup/cleanup.c
|
||||
create mode 100644 src/daemon/modules/container/leftover_cleanup/cleanup.h
|
||||
create mode 100644 src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.c
|
||||
create mode 100644 src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.h
|
||||
|
||||
diff --git a/src/daemon/modules/api/image_api.h b/src/daemon/modules/api/image_api.h
|
||||
index 10fa7b5b..a1c6084a 100644
|
||||
--- a/src/daemon/modules/api/image_api.h
|
||||
+++ b/src/daemon/modules/api/image_api.h
|
||||
@@ -184,6 +184,10 @@ typedef struct {
|
||||
char *name_id;
|
||||
} im_export_request;
|
||||
|
||||
+typedef struct {
|
||||
+ char *type;
|
||||
+} im_get_rf_dir_request;
|
||||
+
|
||||
typedef struct {
|
||||
char *name_id;
|
||||
bool force;
|
||||
@@ -325,6 +329,8 @@ int im_container_export(const im_export_request *request);
|
||||
|
||||
void free_im_export_request(im_export_request *ptr);
|
||||
|
||||
+char *im_get_rootfs_dir(const im_get_rf_dir_request *request);
|
||||
+
|
||||
int im_resolv_image_name(const char *image_type, const char *image_name, char **resolved_name);
|
||||
|
||||
container_inspect_graph_driver *im_graphdriver_get_metadata_by_container_id(const char *id);
|
||||
diff --git a/src/daemon/modules/container/CMakeLists.txt b/src/daemon/modules/container/CMakeLists.txt
|
||||
index fd2a0b10..def602c7 100644
|
||||
--- a/src/daemon/modules/container/CMakeLists.txt
|
||||
+++ b/src/daemon/modules/container/CMakeLists.txt
|
||||
@@ -5,6 +5,7 @@ add_subdirectory(supervisor)
|
||||
add_subdirectory(health_check)
|
||||
add_subdirectory(container_gc)
|
||||
add_subdirectory(restart_manager)
|
||||
+add_subdirectory(leftover_cleanup)
|
||||
|
||||
set(MANAGER_SRCS
|
||||
${local_manager_srcs}
|
||||
@@ -13,6 +14,7 @@ set(MANAGER_SRCS
|
||||
${HEALTH_CHECK_SRCS}
|
||||
${GC_SRCS}
|
||||
${RESTART_MANAGER_SRCS}
|
||||
+ ${LEFTOVER_CLEANUP_SRCS}
|
||||
PARENT_SCOPE
|
||||
)
|
||||
|
||||
@@ -23,5 +25,6 @@ set(MANAGER_INCS
|
||||
${HEALTH_CHECK_INCS}
|
||||
${GC_INCS}
|
||||
${RESTART_MANAGER_INCS}
|
||||
+ ${LEFTOVER_CLEANUP_INCS}
|
||||
PARENT_SCOPE
|
||||
)
|
||||
diff --git a/src/daemon/modules/container/container_unix.c b/src/daemon/modules/container/container_unix.c
|
||||
index 9910b3c8..88c4bf51 100644
|
||||
--- a/src/daemon/modules/container/container_unix.c
|
||||
+++ b/src/daemon/modules/container/container_unix.c
|
||||
@@ -46,6 +46,7 @@
|
||||
#include "utils_string.h"
|
||||
#include "volume_api.h"
|
||||
#include "namespace.h"
|
||||
+#include "cleanup.h"
|
||||
|
||||
static int parse_container_log_configs(container_t *cont);
|
||||
|
||||
@@ -1278,6 +1279,7 @@ int container_module_init(char **msg)
|
||||
}
|
||||
|
||||
containers_restore();
|
||||
+ clean_leftover();
|
||||
|
||||
if (start_gchandler()) {
|
||||
*msg = "Failed to start garbage collecotor handler";
|
||||
diff --git a/src/daemon/modules/container/leftover_cleanup/CMakeLists.txt b/src/daemon/modules/container/leftover_cleanup/CMakeLists.txt
|
||||
new file mode 100644
|
||||
index 00000000..225ac38f
|
||||
--- /dev/null
|
||||
+++ b/src/daemon/modules/container/leftover_cleanup/CMakeLists.txt
|
||||
@@ -0,0 +1,19 @@
|
||||
+# get current directory sources files
|
||||
+aux_source_directory(${CMAKE_CURRENT_SOURCE_DIR} local_leftover_cleanup_srcs)
|
||||
+
|
||||
+set(LEFTOVER_CLEANUP_SRCS
|
||||
+ ${local_leftover_cleanup_srcs}
|
||||
+ PARENT_SCOPE
|
||||
+ )
|
||||
+
|
||||
+set(LEFTOVER_CLEANUP_INCS
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}
|
||||
+ PARENT_SCOPE
|
||||
+ )
|
||||
+
|
||||
+if (DISABLE_OCI)
|
||||
+ list(REMOVE_ITEM
|
||||
+ local_leftover_cleanup_srcs
|
||||
+ ${CMAKE_CURRENT_SOURCE_DIR}/oci_rootfs_clean.c
|
||||
+ )
|
||||
+endif()
|
||||
\ No newline at end of file
|
||||
diff --git a/src/daemon/modules/container/leftover_cleanup/cleanup.c b/src/daemon/modules/container/leftover_cleanup/cleanup.c
|
||||
new file mode 100644
|
||||
index 00000000..29fa4bfa
|
||||
--- /dev/null
|
||||
+++ b/src/daemon/modules/container/leftover_cleanup/cleanup.c
|
||||
@@ -0,0 +1,135 @@
|
||||
+/******************************************************************************
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2018-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: wangrunze
|
||||
+ * Create: 2022-10-31
|
||||
+ * Description: provide cleanup functions
|
||||
+ *********************************************************************************/
|
||||
+#include "utils.h"
|
||||
+#include "cleanup.h"
|
||||
+#include "oci_rootfs_clean.h"
|
||||
+
|
||||
+static struct cleaners *create_cleaners()
|
||||
+{
|
||||
+ struct cleaners *ret = NULL;
|
||||
+
|
||||
+ ret = util_common_calloc_s(sizeof(struct cleaners));
|
||||
+ if (ret == NULL) {
|
||||
+ ERROR("Out of memory");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ linked_list_init(&(ret->cleaner_list));
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+static void destroy_cleaners(struct cleaners *clns)
|
||||
+{
|
||||
+ struct linked_list *it = NULL;
|
||||
+ struct linked_list *next = NULL;
|
||||
+ struct clean_node *c_node = NULL;
|
||||
+
|
||||
+ linked_list_for_each_safe(it, &(clns->cleaner_list), next) {
|
||||
+ c_node = (struct clean_node *)it->elem;
|
||||
+ linked_list_del(it);
|
||||
+ free(c_node);
|
||||
+ free(it);
|
||||
+ it = NULL;
|
||||
+ }
|
||||
+
|
||||
+ free(clns);
|
||||
+}
|
||||
+
|
||||
+static int add_clean_node(struct cleaners * clns, clean_func_t f, char * desc)
|
||||
+{
|
||||
+ struct linked_list *new_node = NULL;
|
||||
+ struct clean_node *c_node = NULL;
|
||||
+
|
||||
+ new_node = util_common_calloc_s(sizeof(struct linked_list));
|
||||
+ if (new_node == NULL) {
|
||||
+ ERROR("Out of memory");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ c_node = util_common_calloc_s(sizeof(struct clean_node));
|
||||
+ if (c_node == NULL) {
|
||||
+ ERROR("Out of memory");
|
||||
+ free(new_node);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ c_node->cleaner = f;
|
||||
+ c_node->desc = desc;
|
||||
+
|
||||
+ linked_list_add_elem(new_node, c_node);
|
||||
+ linked_list_add_tail(&(clns->cleaner_list), new_node);
|
||||
+ clns->count++;
|
||||
+
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static int default_cleaner()
|
||||
+{
|
||||
+ return 0;
|
||||
+}
|
||||
+
|
||||
+static struct cleaners *cleaner_init()
|
||||
+{
|
||||
+ struct cleaners *clns = create_cleaners();
|
||||
+
|
||||
+ if (clns == NULL) {
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ add_clean_node(clns, default_cleaner, "default clean");
|
||||
+#ifdef ENABLE_OCI_IMAGE
|
||||
+ add_clean_node(clns, oci_rootfs_cleaner, "clean rootfs");
|
||||
+#endif
|
||||
+
|
||||
+ return clns;
|
||||
+}
|
||||
+
|
||||
+static void do_clean(struct cleaners * clns)
|
||||
+{
|
||||
+ struct linked_list *it = NULL;
|
||||
+ struct linked_list *next = NULL;
|
||||
+ struct clean_node *c_node = NULL;
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ linked_list_for_each_safe(it, &(clns->cleaner_list), next) {
|
||||
+ c_node = (struct clean_node *)it->elem;
|
||||
+ if ((ret = c_node->cleaner()) != 0) {
|
||||
+ ERROR("failed to clean for: %s", c_node->desc);
|
||||
+ } else {
|
||||
+ DEBUG("do clean success for: %s", c_node->desc);
|
||||
+ clns->done_clean++;
|
||||
+ }
|
||||
+ }
|
||||
+}
|
||||
+
|
||||
+void clean_leftover()
|
||||
+{
|
||||
+ struct cleaners *clns = cleaner_init();
|
||||
+
|
||||
+ if (clns == NULL) {
|
||||
+ ERROR("failed to clean leftovers, because cleaner init error");
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ do_clean(clns);
|
||||
+
|
||||
+ if (clns->count == clns->done_clean) {
|
||||
+ DEBUG("all clean up success");
|
||||
+ } else {
|
||||
+ ERROR("Aim to do %d clean, %d clean sucess\n", clns->count, clns->done_clean);
|
||||
+ }
|
||||
+
|
||||
+ destroy_cleaners(clns);
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/daemon/modules/container/leftover_cleanup/cleanup.h b/src/daemon/modules/container/leftover_cleanup/cleanup.h
|
||||
new file mode 100644
|
||||
index 00000000..26fc1b0b
|
||||
--- /dev/null
|
||||
+++ b/src/daemon/modules/container/leftover_cleanup/cleanup.h
|
||||
@@ -0,0 +1,49 @@
|
||||
+/******************************************************************************
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2018-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: wangrunze
|
||||
+ * Create: 2022-10-31
|
||||
+ * Description: provide cleanup definition
|
||||
+ *********************************************************************************/
|
||||
+#ifndef DAEMON_MODULES_CONTAINER_LEFTOVER_CLEANUP_H
|
||||
+#define DAEMON_MODULES_CONTAINER_LEFTOVER_CLEANUP_H
|
||||
+
|
||||
+#include <stdlib.h>
|
||||
+
|
||||
+#include "linked_list.h"
|
||||
+#include "isula_libutils/log.h"
|
||||
+
|
||||
+#if defined(__cplusplus) || defined(c_plusplus)
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+typedef int clean_func_t(void);
|
||||
+
|
||||
+struct clean_node {
|
||||
+ char *desc;
|
||||
+ clean_func_t *cleaner;
|
||||
+ int error_code;
|
||||
+};
|
||||
+
|
||||
+struct cleaners {
|
||||
+ int count;
|
||||
+ int done_clean;
|
||||
+ struct linked_list cleaner_list;
|
||||
+};
|
||||
+
|
||||
+
|
||||
+void clean_leftover();
|
||||
+
|
||||
+
|
||||
+#if defined(__cplusplus) || defined(c_plusplus)
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif
|
||||
\ No newline at end of file
|
||||
diff --git a/src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.c b/src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.c
|
||||
new file mode 100644
|
||||
index 00000000..db56870b
|
||||
--- /dev/null
|
||||
+++ b/src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.c
|
||||
@@ -0,0 +1,71 @@
|
||||
+/******************************************************************************
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2018-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: wangrunze
|
||||
+ * Create: 2022-10-31
|
||||
+ * Description: provide rootfs cleaner functions
|
||||
+ *********************************************************************************/
|
||||
+#include <sys/stat.h>
|
||||
+#include <string.h>
|
||||
+#include "oci_rootfs_clean.h"
|
||||
+#include "container_api.h"
|
||||
+#include "image_api.h"
|
||||
+#include "utils_file.h"
|
||||
+#include "utils.h"
|
||||
+
|
||||
+struct cb_result {
|
||||
+ int clean_err_cnt;
|
||||
+};
|
||||
+
|
||||
+static bool walk_dir_cb(const char *path_name, const struct dirent *sub_dir, void *context)
|
||||
+{
|
||||
+ struct cb_result *result = (struct cb_result *)context;
|
||||
+ container_t *cont = containers_store_get(sub_dir->d_name);
|
||||
+ int rm_rootfs_ret = 0;
|
||||
+
|
||||
+ if (cont != NULL) {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ INFO("cleaning leftover dir: %s", sub_dir->d_name);
|
||||
+ rm_rootfs_ret = im_remove_container_rootfs(IMAGE_TYPE_OCI, sub_dir->d_name);
|
||||
+ if (rm_rootfs_ret != 0) {
|
||||
+ result->clean_err_cnt++;
|
||||
+ }
|
||||
+
|
||||
+ return true;
|
||||
+}
|
||||
+
|
||||
+
|
||||
+int oci_rootfs_cleaner(void)
|
||||
+{
|
||||
+ struct cb_result res = { 0 };
|
||||
+ im_get_rf_dir_request request = { 0 };
|
||||
+ char *rf_dir = NULL;
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ request.type = IMAGE_TYPE_OCI;
|
||||
+ rf_dir = im_get_rootfs_dir(&request);
|
||||
+ if (rf_dir == NULL) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ ret = util_scan_subdirs(rf_dir, walk_dir_cb, &res);
|
||||
+ if (ret != 0) {
|
||||
+ ERROR("failed to scan subdirs");
|
||||
+ return -1;
|
||||
+ }
|
||||
+
|
||||
+ if (res.clean_err_cnt == 0) {
|
||||
+ return 0;
|
||||
+ }
|
||||
+
|
||||
+ return -1;
|
||||
+}
|
||||
diff --git a/src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.h b/src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.h
|
||||
new file mode 100644
|
||||
index 00000000..8dff351f
|
||||
--- /dev/null
|
||||
+++ b/src/daemon/modules/container/leftover_cleanup/oci_rootfs_clean.h
|
||||
@@ -0,0 +1,30 @@
|
||||
+/******************************************************************************
|
||||
+ * Copyright (c) Huawei Technologies Co., Ltd. 2018-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: wangrunze
|
||||
+ * Create: 2022-10-31
|
||||
+ * Description: provide rootfs cleaner definition
|
||||
+ *********************************************************************************/
|
||||
+#ifndef DAEMON_MODULES_CONTAINER_ROOTFS_CLEAN_H
|
||||
+#define DAEMON_MODULES_CONTAINER_ROOTFS_CLEAN_H
|
||||
+
|
||||
+#include "cleanup.h"
|
||||
+
|
||||
+#if defined(__cplusplus) || defined(c_plusplus)
|
||||
+extern "C" {
|
||||
+#endif
|
||||
+
|
||||
+int oci_rootfs_cleaner(void);
|
||||
+
|
||||
+#if defined(__cplusplus) || defined(c_plusplus)
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
+#endif
|
||||
\ No newline at end of file
|
||||
diff --git a/src/daemon/modules/image/image.c b/src/daemon/modules/image/image.c
|
||||
index f487f831..3c395c1f 100644
|
||||
--- a/src/daemon/modules/image/image.c
|
||||
+++ b/src/daemon/modules/image/image.c
|
||||
@@ -49,6 +49,7 @@ struct bim_ops {
|
||||
int (*delete_rf)(const im_delete_rootfs_request *request);
|
||||
int (*export_rf)(const im_export_request *request);
|
||||
char *(*resolve_image_name)(const char *image_name);
|
||||
+ char *(*get_dir_rf)(void);
|
||||
|
||||
/* merge image config ops */
|
||||
int (*merge_conf)(const char *img_name, container_config *container_spec);
|
||||
@@ -132,6 +133,7 @@ static const struct bim_ops g_embedded_ops = {
|
||||
.umount_rf = embedded_umount_rf,
|
||||
.delete_rf = embedded_delete_rf,
|
||||
.export_rf = NULL,
|
||||
+ .get_dir_rf = NULL,
|
||||
|
||||
.merge_conf = embedded_merge_conf,
|
||||
.get_user_conf = embedded_get_user_conf,
|
||||
@@ -166,6 +168,7 @@ static const struct bim_ops g_oci_ops = {
|
||||
.umount_rf = oci_umount_rf,
|
||||
.delete_rf = oci_delete_rf,
|
||||
.export_rf = oci_export_rf,
|
||||
+ .get_dir_rf = oci_get_dir_rf,
|
||||
|
||||
.merge_conf = oci_merge_conf_rf,
|
||||
.get_user_conf = oci_get_user_conf,
|
||||
@@ -199,6 +202,7 @@ static const struct bim_ops g_ext_ops = {
|
||||
.umount_rf = ext_umount_rf,
|
||||
.delete_rf = ext_delete_rf,
|
||||
.export_rf = NULL,
|
||||
+ .get_dir_rf = NULL,
|
||||
|
||||
.merge_conf = ext_merge_conf,
|
||||
.get_user_conf = ext_get_user_conf,
|
||||
@@ -1768,6 +1772,28 @@ int im_container_export(const im_export_request *request)
|
||||
}
|
||||
#endif
|
||||
|
||||
+#ifdef ENABLE_OCI_IMAGE
|
||||
+char *im_get_rootfs_dir(const im_get_rf_dir_request *request) {
|
||||
+ if (request->type == NULL) {
|
||||
+ ERROR("Missing image type");
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ struct bim *bim = NULL;
|
||||
+ bim = bim_get(request->type, NULL, NULL, NULL);
|
||||
+ if (bim->ops->get_dir_rf == NULL) {
|
||||
+ ERROR("Unimplemnts get rootfs dir in %s", bim->type);
|
||||
+ return NULL;
|
||||
+ }
|
||||
+
|
||||
+ return bim->ops->get_dir_rf();
|
||||
+}
|
||||
+#else
|
||||
+char *im_get_rootfs_dir(const im_get_rf_dir_request *request) {
|
||||
+ return NULL;
|
||||
+}
|
||||
+#endif
|
||||
+
|
||||
void free_im_export_request(im_export_request *ptr)
|
||||
{
|
||||
if (ptr == NULL) {
|
||||
diff --git a/src/daemon/modules/image/oci/oci_image.c b/src/daemon/modules/image/oci/oci_image.c
|
||||
index 86828f50..e951adb4 100644
|
||||
--- a/src/daemon/modules/image/oci/oci_image.c
|
||||
+++ b/src/daemon/modules/image/oci/oci_image.c
|
||||
@@ -686,6 +686,11 @@ int oci_export_rf(const im_export_request *request)
|
||||
return ret;
|
||||
}
|
||||
|
||||
+char *oci_get_dir_rf(void)
|
||||
+{
|
||||
+ return storage_rootfs_get_dir();
|
||||
+}
|
||||
+
|
||||
int oci_login(const im_login_request *request)
|
||||
{
|
||||
int ret = 0;
|
||||
diff --git a/src/daemon/modules/image/oci/oci_image.h b/src/daemon/modules/image/oci/oci_image.h
|
||||
index 64a4d8e8..aeeb3b65 100644
|
||||
--- a/src/daemon/modules/image/oci/oci_image.h
|
||||
+++ b/src/daemon/modules/image/oci/oci_image.h
|
||||
@@ -54,6 +54,7 @@ int oci_mount_rf(const im_mount_request *request);
|
||||
int oci_umount_rf(const im_umount_request *request);
|
||||
int oci_delete_rf(const im_delete_rootfs_request *request);
|
||||
int oci_export_rf(const im_export_request *request);
|
||||
+char *oci_get_dir_rf(void);
|
||||
int oci_container_filesystem_usage(const im_container_fs_usage_request *request, imagetool_fs_info **fs_usage);
|
||||
int oci_login(const im_login_request *request);
|
||||
int oci_logout(const im_logout_request *request);
|
||||
diff --git a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
|
||||
index 378d1a96..0270f6a7 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
|
||||
+++ b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.c
|
||||
@@ -1319,3 +1319,8 @@ out:
|
||||
rootfs_store_unlock();
|
||||
return ret;
|
||||
}
|
||||
+
|
||||
+char *rootfs_store_get_data_dir()
|
||||
+{
|
||||
+ return g_rootfs_store->dir;
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h
|
||||
index e13f97bc..c23af091 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h
|
||||
+++ b/src/daemon/modules/image/oci/storage/rootfs_store/rootfs_store.h
|
||||
@@ -65,6 +65,9 @@ storage_rootfs *rootfs_store_get_rootfs(const char *id);
|
||||
// Return a slice enumerating the known containers.
|
||||
int rootfs_store_get_all_rootfs(struct rootfs_list *all_rootfs);
|
||||
|
||||
+// Return rootfs store data dir
|
||||
+char *rootfs_store_get_data_dir();
|
||||
+
|
||||
// Free memory of container store, but will not delete the persisted files
|
||||
void rootfs_store_free();
|
||||
|
||||
diff --git a/src/daemon/modules/image/oci/storage/storage.c b/src/daemon/modules/image/oci/storage/storage.c
|
||||
index 57b5fb80..6cb4a51b 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/storage.c
|
||||
+++ b/src/daemon/modules/image/oci/storage/storage.c
|
||||
@@ -1868,3 +1868,8 @@ int storage_module_init(struct storage_module_init_options *opts)
|
||||
out:
|
||||
return ret;
|
||||
}
|
||||
+
|
||||
+char *storage_rootfs_get_dir()
|
||||
+{
|
||||
+ return rootfs_store_get_data_dir();
|
||||
+}
|
||||
\ No newline at end of file
|
||||
diff --git a/src/daemon/modules/image/oci/storage/storage.h b/src/daemon/modules/image/oci/storage/storage.h
|
||||
index 1fe29b45..5914adec 100644
|
||||
--- a/src/daemon/modules/image/oci/storage/storage.h
|
||||
+++ b/src/daemon/modules/image/oci/storage/storage.h
|
||||
@@ -181,6 +181,8 @@ char *storage_rootfs_mount(const char *container_id);
|
||||
|
||||
int storage_rootfs_umount(const char *container_id, bool force);
|
||||
|
||||
+char *storage_rootfs_get_dir();
|
||||
+
|
||||
container_inspect_graph_driver *storage_get_metadata_by_container_id(const char *id);
|
||||
|
||||
#ifdef __cplusplus
|
||||
--
|
||||
2.25.1
|
||||
|
||||
154
0039-bugfix-for-websocket-receive-data-too-long.patch
Normal file
154
0039-bugfix-for-websocket-receive-data-too-long.patch
Normal file
@ -0,0 +1,154 @@
|
||||
From 3942fb5667077200017a1a7c72672e482e798df6 Mon Sep 17 00:00:00 2001
|
||||
From: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
Date: Tue, 1 Nov 2022 14:36:02 +0800
|
||||
Subject: [PATCH 39/39] bugfix for websocket receive data too long
|
||||
|
||||
Signed-off-by: zhangxiaoyu <zhangxiaoyu58@huawei.com>
|
||||
---
|
||||
.../entry/cri/websocket/service/ws_server.cc | 65 ++++++++++++++++---
|
||||
.../entry/cri/websocket/service/ws_server.h | 5 +-
|
||||
2 files changed, 59 insertions(+), 11 deletions(-)
|
||||
|
||||
diff --git a/src/daemon/entry/cri/websocket/service/ws_server.cc b/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
index 41bb3fe8..ea320ff4 100644
|
||||
--- a/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
+++ b/src/daemon/entry/cri/websocket/service/ws_server.cc
|
||||
@@ -126,6 +126,32 @@ void SessionData::CloseSession()
|
||||
sessionMutex->unlock();
|
||||
}
|
||||
|
||||
+bool SessionData::IsStdinComplete()
|
||||
+{
|
||||
+ bool c = true;
|
||||
+
|
||||
+ if (sessionMutex == nullptr) {
|
||||
+ return true;
|
||||
+ }
|
||||
+
|
||||
+ sessionMutex->lock();
|
||||
+ c = completeStdin;
|
||||
+ sessionMutex->unlock();
|
||||
+
|
||||
+ return c;
|
||||
+}
|
||||
+
|
||||
+void SessionData::SetStdinComplete(bool complete)
|
||||
+{
|
||||
+ if (sessionMutex == nullptr) {
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ sessionMutex->lock();
|
||||
+ completeStdin = complete;
|
||||
+ sessionMutex->unlock();
|
||||
+}
|
||||
+
|
||||
void SessionData::EraseAllMessage()
|
||||
{
|
||||
if (sessionMutex == nullptr) {
|
||||
@@ -330,6 +356,7 @@ int WebsocketServer::GenerateSessionData(SessionData *session, const std::string
|
||||
session->sessionMutex = bufMutex;
|
||||
session->syncCloseSem = syncCloseSem;
|
||||
session->close = false;
|
||||
+ session->completeStdin = true;
|
||||
session->containerID = containerID;
|
||||
session->suffix = std::string(suffix);
|
||||
|
||||
@@ -524,28 +551,44 @@ int WebsocketServer::ResizeTerminal(int socketID, const char *jsonData, size_t l
|
||||
return ret;
|
||||
}
|
||||
|
||||
-void WebsocketServer::Receive(int socketID, void *in, size_t len)
|
||||
+void WebsocketServer::Receive(int socketID, void *in, size_t len, bool complete)
|
||||
{
|
||||
auto it = m_wsis.find(socketID);
|
||||
if (it == m_wsis.end()) {
|
||||
- ERROR("invailed websocket session!");
|
||||
+ ERROR("Invailed websocket session!");
|
||||
return;
|
||||
}
|
||||
|
||||
+ if (!it->second->IsStdinComplete()) {
|
||||
+ DEBUG("Receive remaning stdin data with length %zu", len);
|
||||
+ // Too much data may cause error 'resource temporarily unavaliable' by using 'write'
|
||||
+ if (util_write_nointr_in_total(m_wsis[socketID]->pipes.at(1), (char *)in, len) < 0) {
|
||||
+ ERROR("Sub write over! err msg: %s", strerror(errno));
|
||||
+ }
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
if (*static_cast<char *>(in) == WebsocketChannel::RESIZECHANNEL) {
|
||||
if (ResizeTerminal(socketID, (char *)in + 1, len, it->second->containerID, it->second->suffix) != 0) {
|
||||
ERROR("Failed to resize terminal tty");
|
||||
- return;
|
||||
}
|
||||
- } else if (*static_cast<char *>(in) == WebsocketChannel::STDINCHANNEL) {
|
||||
- if (write(m_wsis[socketID]->pipes.at(1), (void *)((char *)in + 1), len - 1) < 0) {
|
||||
- ERROR("sub write over!");
|
||||
- return;
|
||||
+ if (!complete) {
|
||||
+ ERROR("Resize data too long");
|
||||
}
|
||||
- } else {
|
||||
- ERROR("invalid data: %s", (char *)in);
|
||||
return;
|
||||
}
|
||||
+
|
||||
+ if (*static_cast<char *>(in) == WebsocketChannel::STDINCHANNEL) {
|
||||
+ if (util_write_nointr_in_total(m_wsis[socketID]->pipes.at(1), (char *)in + 1, len - 1) < 0) {
|
||||
+ ERROR("Sub write over! err msg: %s", strerror(errno));
|
||||
+ }
|
||||
+ goto out;
|
||||
+ }
|
||||
+
|
||||
+ ERROR("Invalid data: %s", (char *)in);
|
||||
+
|
||||
+out:
|
||||
+ it->second->SetStdinComplete(complete);
|
||||
}
|
||||
|
||||
int WebsocketServer::Callback(struct lws *wsi, enum lws_callback_reasons reason, void *user, void *in, size_t len)
|
||||
@@ -605,7 +648,9 @@ int WebsocketServer::Callback(struct lws *wsi, enum lws_callback_reasons reason,
|
||||
break;
|
||||
case LWS_CALLBACK_RECEIVE: {
|
||||
ReadGuard<RWMutex> lock(m_mutex);
|
||||
- WebsocketServer::GetInstance()->Receive(lws_get_socket_fd(wsi), static_cast<char *>(in), len);
|
||||
+ size_t bytesLen = lws_remaining_packet_payload(wsi);
|
||||
+ WebsocketServer::GetInstance()->Receive(lws_get_socket_fd(wsi), static_cast<char *>(in),
|
||||
+ len, bytesLen == 0);
|
||||
}
|
||||
break;
|
||||
case LWS_CALLBACK_CLOSED: {
|
||||
diff --git a/src/daemon/entry/cri/websocket/service/ws_server.h b/src/daemon/entry/cri/websocket/service/ws_server.h
|
||||
index a2a180ec..7da56818 100644
|
||||
--- a/src/daemon/entry/cri/websocket/service/ws_server.h
|
||||
+++ b/src/daemon/entry/cri/websocket/service/ws_server.h
|
||||
@@ -44,6 +44,7 @@ struct SessionData {
|
||||
std::list<unsigned char *> buffer;
|
||||
std::string containerID;
|
||||
std::string suffix;
|
||||
+ volatile bool completeStdin;
|
||||
|
||||
unsigned char *FrontMessage();
|
||||
void PopMessage();
|
||||
@@ -51,6 +52,8 @@ struct SessionData {
|
||||
bool IsClosed();
|
||||
void CloseSession();
|
||||
void EraseAllMessage();
|
||||
+ bool IsStdinComplete();
|
||||
+ void SetStdinComplete(bool complete);
|
||||
};
|
||||
|
||||
class WebsocketServer {
|
||||
@@ -72,7 +75,7 @@ private:
|
||||
std::vector<std::string> split(std::string str, char r);
|
||||
|
||||
int CreateContext();
|
||||
- inline void Receive(int socketID, void *in, size_t len);
|
||||
+ inline void Receive(int socketID, void *in, size_t len, bool complete);
|
||||
int Wswrite(struct lws *wsi, const unsigned char *message);
|
||||
inline void DumpHandshakeInfo(struct lws *wsi) noexcept;
|
||||
int RegisterStreamTask(struct lws *wsi) noexcept;
|
||||
--
|
||||
2.25.1
|
||||
|
||||
41
iSulad.spec
41
iSulad.spec
@ -1,5 +1,5 @@
|
||||
%global _version 2.0.17
|
||||
%global _release 4
|
||||
%global _release 5
|
||||
%global is_systemd 1
|
||||
%global enable_shimv2 1
|
||||
%global is_embedded 1
|
||||
@ -19,6 +19,39 @@ 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
|
||||
Patch0007: 0007-add-check-for-aes-apis.patch
|
||||
Patch0008: 0008-add-ut-for-cutils-aes.patch
|
||||
Patch0009: 0009-add-ut-for-cutils-error.patch
|
||||
Patch0010: 0010-ensure-argument-is-not-null.patch
|
||||
Patch0011: 0011-add-ut-for-utils_fs.patch
|
||||
Patch0012: 0012-Add-adaptation-code-for-filters.patch
|
||||
Patch0013: 0013-Add-parameter-check-to-path.patch
|
||||
Patch0014: 0014-Add-ut-for-utils_convert.patch
|
||||
Patch0015: 0015-Add-ut-for-path.patch
|
||||
Patch0016: 0016-Add-ut-for-filters.patch
|
||||
Patch0017: 0017-add-static-for-unexport-function.patch
|
||||
Patch0018: 0018-add-ut-for-cutils-timestamp.patch
|
||||
Patch0019: 0019-fix-timestamp-ut-error.patch
|
||||
Patch0020: 0020-improve-code-in-utils_mount_spec.patch
|
||||
Patch0021: 0021-Add-ut-for-utils_mount_spec.patch
|
||||
Patch0022: 0022-Add-ut-for-utils_regex.patch
|
||||
Patch0023: 0023-improve-code-in-utils.c.patch
|
||||
Patch0024: 0024-add-ut-for-cutils-utils.patch
|
||||
Patch0025: 0025-make-sure-kill-pid-not-negative.patch
|
||||
Patch0026: 0026-add-UT-for-atomic-and-map.patch
|
||||
Patch0027: 0027-remove-unnecessary-goto-and-add-parameter-check-for-.patch
|
||||
Patch0028: 0028-Add-ut-for-verify.patch
|
||||
Patch0029: 0029-fix-error-in-utils_verify_ut.patch
|
||||
Patch0030: 0030-add-more-test-for-string-and-map.patch
|
||||
Patch0031: 0031-remove-mnt-point-if-add-device-mapper-device-failed.patch
|
||||
Patch0032: 0032-dec-device-info-ref-in-grow-device-fs.patch
|
||||
Patch0033: 0033-device-mapper-bugfix.patch
|
||||
Patch0034: 0034-delete-syncCloseSem-when-close-all-wssession.patch
|
||||
Patch0035: 0035-improve-debug-information-for-console-io.patch
|
||||
Patch0036: 0036-add-ut-for-file.patch
|
||||
Patch0037: 0037-Add-extend-C-for-header-files.patch
|
||||
Patch0038: 0038-feat-add-container-cleanup-module.patch
|
||||
Patch0039: 0039-bugfix-for-websocket-receive-data-too-long.patch
|
||||
|
||||
%ifarch x86_64 aarch64
|
||||
Provides: libhttpclient.so()(64bit)
|
||||
@ -245,6 +278,12 @@ fi
|
||||
%endif
|
||||
|
||||
%changelog
|
||||
* Tue Nov 01 2022 zhangxiaoyu <zhangxiaoyu58@huawei.com> - 2.0.17-5
|
||||
- Type: enhancement
|
||||
- ID: NA
|
||||
- SUG: NA
|
||||
- DESC: add ut and bugfix for device mapper and websocket
|
||||
|
||||
* Mon Oct 31 2022 wujing <wujing50@huawei.com> - 2.0.17-4
|
||||
- Type: enhancement
|
||||
- ID: NA
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user