Sync the features and bug fixed in the etmem source repository. Signed-off-by: liubo <liubo254@huawei.com> (cherry picked from commit 07dd6a411bce9ed3d9f617a6f01ae076e24a3adf)
699 lines
22 KiB
Diff
699 lines
22 KiB
Diff
From e36c5a68a748080a473988c7530786f3f7ac90d3 Mon Sep 17 00:00:00 2001
|
|
From: louhongxiang <louhongxiang@huawei.com>
|
|
Date: Mon, 22 Nov 2021 17:51:33 +0800
|
|
Subject: [PATCH 04/33] add code of testcase for etmem common function.
|
|
|
|
---
|
|
etmem/test/CMakeLists.txt | 198 ++++++++++++++++++++++++
|
|
etmem/test/common/test_common.c | 327 ++++++++++++++++++++++++++++++++++++++++
|
|
etmem/test/common/test_common.h | 138 +++++++++++++++++
|
|
3 files changed, 663 insertions(+)
|
|
create mode 100644 etmem/test/CMakeLists.txt
|
|
create mode 100644 etmem/test/common/test_common.c
|
|
create mode 100644 etmem/test/common/test_common.h
|
|
|
|
diff --git a/etmem/test/CMakeLists.txt b/etmem/test/CMakeLists.txt
|
|
new file mode 100644
|
|
index 0000000..5bf3477
|
|
--- /dev/null
|
|
+++ b/etmem/test/CMakeLists.txt
|
|
@@ -0,0 +1,198 @@
|
|
+# /******************************************************************************
|
|
+# * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
|
|
+# * etmem is 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: louhongxiang
|
|
+# * Create: 2021-11-19
|
|
+# * Description: CMakefileList for etmem to compile
|
|
+# ******************************************************************************/
|
|
+
|
|
+cmake_minimum_required (VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
|
|
+project(etmem)
|
|
+
|
|
+EXECUTE_PROCESS( COMMAND uname -m COMMAND tr -d '\n' OUTPUT_VARIABLE ARCHITECTURE )
|
|
+message( STATUS "Architecture: ${ARCHITECTURE}" )
|
|
+
|
|
+set(ETMEMD_SRC_DIR ${PROJECT_SOURCE_DIR}/../src/etmemd_src)
|
|
+set(ETMEM_SRC_DIR ${PROJECT_SOURCE_DIR}/../src/etmem_src)
|
|
+set(TEST_COMMON_DIR ${PROJECT_SOURCE_DIR}/common)
|
|
+set(BUILD_DIR ${PROJECT_SOURCE_DIR}/build)
|
|
+
|
|
+set(ETMEMD_SRC
|
|
+ ${ETMEMD_SRC_DIR}/etmemd.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_file.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_common.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_rpc.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_log.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_project.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_engine.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_memdcd.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_slide.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_cslide.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_thirdparty.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_task.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_scan.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_threadpool.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_threadtimer.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_pool_adapter.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_migrate.c)
|
|
+
|
|
+set(ETMEM_SRC
|
|
+ ${ETMEM_SRC_DIR}/etmem.c
|
|
+ ${ETMEM_SRC_DIR}/etmem_project.c
|
|
+ ${ETMEM_SRC_DIR}/etmem_obj.c
|
|
+ ${ETMEM_SRC_DIR}/etmem_engine.c
|
|
+ ${ETMEM_SRC_DIR}/etmem_rpc.c
|
|
+ ${ETMEM_SRC_DIR}/etmem_common.c)
|
|
+
|
|
+set(ETMEMD_CSLIDE_DEP
|
|
+ ${ETMEMD_SRC_DIR}/etmemd.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_file.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_common.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_rpc.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_log.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_project.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_engine.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_slide.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_thirdparty.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_task.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_scan.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_threadpool.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_threadtimer.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_pool_adapter.c
|
|
+ ${ETMEMD_SRC_DIR}/etmemd_migrate.c)
|
|
+
|
|
+set(TEST_COMMON_SRC
|
|
+ ${TEST_COMMON_DIR}/test_common.c)
|
|
+
|
|
+add_library(
|
|
+etmemd_shared
|
|
+SHARED
|
|
+${ETMEMD_SRC})
|
|
+
|
|
+add_library(
|
|
+etmem_shared
|
|
+SHARED
|
|
+${ETMEM_SRC})
|
|
+
|
|
+add_library(
|
|
+test_common
|
|
+SHARED
|
|
+${TEST_COMMON_SRC})
|
|
+
|
|
+add_library(
|
|
+cslide_dep
|
|
+SHARED
|
|
+${ETMEMD_CSLIDE_DEP})
|
|
+
|
|
+add_executable(etmemd
|
|
+ ${ETMEMD_SRC})
|
|
+
|
|
+add_executable(etmem
|
|
+ ${ETMEM_SRC})
|
|
+
|
|
+set(EXECUTABLE_OUTPUT_PATH ${BUILD_DIR}/bin)
|
|
+
|
|
+set(LIBRARY_OUTPUT_PATH ${BUILD_DIR}/lib)
|
|
+
|
|
+include(FindPkgConfig)
|
|
+pkg_search_module(GLIB2 REQUIRED glib-2.0)
|
|
+
|
|
+target_include_directories(etmemd PRIVATE
|
|
+ ${PROJECT_SOURCE_DIR}/../inc/etmemd_inc
|
|
+ ${GLIB2_INCLUDE_DIRS})
|
|
+
|
|
+target_include_directories(etmemd_shared PRIVATE
|
|
+ ${PROJECT_SOURCE_DIR}/../inc/etmemd_inc
|
|
+ ${GLIB2_INCLUDE_DIRS})
|
|
+
|
|
+target_include_directories(etmem PRIVATE
|
|
+ ${PROJECT_SOURCE_DIR}/../inc/etmem_inc)
|
|
+
|
|
+target_include_directories(etmem_shared PRIVATE
|
|
+ ${PROJECT_SOURCE_DIR}/../inc/etmem_inc)
|
|
+
|
|
+target_include_directories(test_common PRIVATE
|
|
+ ${PROJECT_SOURCE_DIR}/../inc/etmemd_inc
|
|
+ ${PROJECT_SOURCE_DIR}/COMMON
|
|
+ ${GLIB2_INCLUDE_DIRS})
|
|
+
|
|
+target_include_directories(cslide_dep PRIVATE
|
|
+ ${PROJECT_SOURCE_DIR}/../inc/etmemd_inc
|
|
+ ${GLIB2_INCLUDE_DIRS})
|
|
+
|
|
+if(COVERAGE_ENABLE)
|
|
+ message(STATUS "Enable coverage compile option")
|
|
+ SET(COVERAGE_OPTION "${COVERAGE_OPTION} -fprofile-arcs -ftest-coverage")
|
|
+endif(COVERAGE_ENABLE)
|
|
+
|
|
+if(ASAN_ENABLE)
|
|
+ message(STATUS "Enable asan compile option")
|
|
+ SET(ASAN_OPTIONS "${ASAN_OPTION} -fsanitize=address -fsanitize-recover=address")
|
|
+endif(ASAN_ENABLE)
|
|
+
|
|
+IF(CMAKE_BUILD_TYPE STREQUAL Debug)
|
|
+ SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${COVERAGE_OPTION} ${ASAN_OPTIONS}")
|
|
+ SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${COVERAGE_OPTION} ${ASAN_OPTIONS}")
|
|
+ENDIF()
|
|
+
|
|
+# set common compile options
|
|
+set(COMMON_COMPILE_OPT -fsigned-char -fno-omit-frame-pointer -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers -Wmissing-declarations -fno-strict-aliasing -Werror -Wformat -Wformat-security -D_GNU_SOURCE -fPIE -pie -fPIC -fstack-protector-strong -fno-common -DNDEBUG -O2 -D_FORTIFY_SOURCE=2 -Wall -Werror -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines -pthread -Wno-pointer-sign -Wstrict-prototypes -Wold-style-definition -std=gnu99)
|
|
+
|
|
+if (CONFIG_DEBUG STREQUAL "y")
|
|
+ SET(COMMON_COMPILE_OPT ${COMMON_COMPILE_OPT} -g)
|
|
+endif()
|
|
+
|
|
+if( ${ARCHITECTURE} STREQUAL "aarch64")
|
|
+ SET(COMMON_COMPILE_OPT ${COMMON_COMPILE_OPT} -march=armv8-a)
|
|
+else()
|
|
+ SET(COMMON_COMPILE_OPT ${COMMON_COMPILE_OPT} -march=core-avx-i -m64)
|
|
+endif()
|
|
+
|
|
+# set common share library compile options
|
|
+set(SHARE_COMPILE_OPT -ldl -rdynamic)
|
|
+
|
|
+# set common link options
|
|
+set(COMMON_LINK_OPT "-fPIE -pie -fPIC -Wl,-z,relro,-z,now,-z,noexecstack -Wtrampolines")
|
|
+set(COMMON_LINK_LIB pthread dl rt boundscheck)
|
|
+set(SERVER_LINK_LIB numa ${GLIB2_LIBRARIES})
|
|
+
|
|
+# target etmemd
|
|
+target_compile_options(etmemd PRIVATE ${COMMON_COMPILE_OPT})
|
|
+set_target_properties(etmemd PROPERTIES LINK_FLAGS ${COMMON_LINK_OPT})
|
|
+target_link_libraries(etmemd PRIVATE ${COMMON_LINK_LIB} ${SERVER_LINK_LIB})
|
|
+
|
|
+# target etmem
|
|
+target_compile_options(etmem PRIVATE ${COMMON_COMPILE_OPT})
|
|
+set_target_properties(etmem PROPERTIES LINK_FLAGS ${COMMON_LINK_OPT})
|
|
+target_link_libraries(etmem PRIVATE ${COMMON_LINK_LIB} ${SERVER_LINK_LIB})
|
|
+
|
|
+# target etmemd share
|
|
+target_compile_options(etmemd_shared PRIVATE ${COMMON_COMPILE_OPT} ${SHARE_COMPILE_OPT})
|
|
+set_target_properties(etmemd_shared PROPERTIES LINK_FLAGS ${COMMON_LINK_OPT})
|
|
+target_link_libraries(etmemd_shared PRIVATE ${COMMON_LINK_LIB} ${SERVER_LINK_LIB})
|
|
+SET_TARGET_PROPERTIES(etmemd_shared PROPERTIES OUTPUT_NAME "etmemd")
|
|
+
|
|
+# target etmem share
|
|
+target_compile_options(etmem_shared PRIVATE ${COMMON_COMPILE_OPT} ${SHARE_COMPILE_OPT})
|
|
+set_target_properties(etmem_shared PROPERTIES LINK_FLAGS ${COMMON_LINK_OPT})
|
|
+target_link_libraries(etmem_shared PRIVATE ${COMMON_LINK_LIB})
|
|
+SET_TARGET_PROPERTIES(etmem_shared PROPERTIES OUTPUT_NAME "etmem")
|
|
+
|
|
+# target test etmemd share
|
|
+target_compile_options(test_common PRIVATE ${COMMON_COMPILE_OPT} ${SHARE_COMPILE_OPT})
|
|
+set_target_properties(test_common PROPERTIES LINK_FLAGS ${COMMON_LINK_OPT})
|
|
+target_link_libraries(test_common PRIVATE ${COMMON_LINK_LIB} ${SERVER_LINK_LIB})
|
|
+SET_TARGET_PROPERTIES(test_common PROPERTIES OUTPUT_NAME "test")
|
|
+
|
|
+# target etmemd cslide share
|
|
+target_compile_options(cslide_dep PRIVATE ${COMMON_COMPILE_OPT} ${SHARE_COMPILE_OPT})
|
|
+set_target_properties(cslide_dep PROPERTIES LINK_FLAGS ${COMMON_LINK_OPT})
|
|
+target_link_libraries(cslide_dep PRIVATE ${COMMON_LINK_LIB} ${SERVER_LINK_LIB})
|
|
+
|
|
diff --git a/etmem/test/common/test_common.c b/etmem/test/common/test_common.c
|
|
new file mode 100644
|
|
index 0000000..4551177
|
|
--- /dev/null
|
|
+++ b/etmem/test/common/test_common.c
|
|
@@ -0,0 +1,327 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
|
|
+ * etmem is 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: louhongxiang
|
|
+ * Create: 2021-11-19
|
|
+ * Description: This is a header file of the export data structure definition for page.
|
|
+ ******************************************************************************/
|
|
+
|
|
+#include <stdio.h>
|
|
+#include <numa.h>
|
|
+
|
|
+#include <CUnit/Basic.h>
|
|
+#include <CUnit/Automated.h>
|
|
+#include <CUnit/Console.h>
|
|
+
|
|
+#include "etmemd_project.h"
|
|
+
|
|
+#include "test_common.h"
|
|
+
|
|
+#define FIRST_COLD_NODE_INDEX 2
|
|
+#define FIRST_HOT_NODE_INDEX 0
|
|
+#define SECOND_COLD_NODE_INDEX 6
|
|
+#define SECOND_HOT_NODE_INDEX 4
|
|
+
|
|
+GKeyFile *load_config(const char *file_name)
|
|
+{
|
|
+ GKeyFile *config = NULL;
|
|
+
|
|
+ config = g_key_file_new();
|
|
+ CU_ASSERT_PTR_NOT_NULL(config);
|
|
+ CU_ASSERT_NOT_EQUAL(g_key_file_load_from_file(config, file_name, G_KEY_FILE_NONE, NULL), FALSE);
|
|
+ return config;
|
|
+}
|
|
+
|
|
+void unload_config(GKeyFile *config)
|
|
+{
|
|
+ g_key_file_free(config);
|
|
+}
|
|
+
|
|
+void construct_proj_file(struct proj_test_param *param)
|
|
+{
|
|
+ FILE *file = NULL;
|
|
+
|
|
+ file = fopen(param->file_name, "w+");
|
|
+ CU_ASSERT_PTR_NOT_NULL(file);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, "[project]\n"), -1);
|
|
+ if (param->proj_name != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_NAME, param->proj_name), -1);
|
|
+ }
|
|
+ if (param->interval != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_INTERVAL, param->interval), -1);
|
|
+ }
|
|
+ if (param->loop != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_LOOP, param->loop), -1);
|
|
+ }
|
|
+ if (param->sleep != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_SLEEP, param->sleep), -1);
|
|
+ }
|
|
+ fclose(file);
|
|
+}
|
|
+
|
|
+GKeyFile *construct_proj_config(struct proj_test_param *param)
|
|
+{
|
|
+ construct_proj_file(param);
|
|
+
|
|
+ return load_config(param->file_name);
|
|
+}
|
|
+
|
|
+void destroy_proj_config(GKeyFile *config)
|
|
+{
|
|
+ unload_config(config);
|
|
+}
|
|
+
|
|
+void init_proj_param(struct proj_test_param *param)
|
|
+{
|
|
+ param->sleep = "1";
|
|
+ param->interval = "1";
|
|
+ param->loop = "1";
|
|
+ param->file_name = TMP_PROJ_CONFIG;
|
|
+ param->proj_name = DEFAULT_PROJ;
|
|
+ param->expt = OPT_SUCCESS;
|
|
+}
|
|
+
|
|
+void do_add_proj_test(struct proj_test_param * param)
|
|
+{
|
|
+ GKeyFile *config = NULL;
|
|
+
|
|
+ config = construct_proj_config(param);
|
|
+ CU_ASSERT_EQUAL(etmemd_project_add(config), param->expt);
|
|
+ destroy_proj_config(config);
|
|
+}
|
|
+
|
|
+void do_rm_proj_test(struct proj_test_param *param)
|
|
+{
|
|
+ GKeyFile *config = NULL;
|
|
+
|
|
+ config = load_config(param->file_name);
|
|
+ CU_ASSERT_EQUAL(etmemd_project_remove(config), param->expt);
|
|
+ unload_config(config);
|
|
+}
|
|
+
|
|
+void construct_eng_file(struct eng_test_param *param)
|
|
+{
|
|
+ FILE *file = NULL;
|
|
+
|
|
+ file = fopen(param->file_name, "w+");
|
|
+ CU_ASSERT_PTR_NOT_NULL(file);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, "[engine]\n"), -1);
|
|
+ if (param->name != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_NAME, param->name), -1);
|
|
+ }
|
|
+ if (param->proj != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_PROJ, param->proj), -1);
|
|
+ }
|
|
+ fclose(file);
|
|
+}
|
|
+
|
|
+GKeyFile *construct_eng_config(struct eng_test_param *param)
|
|
+{
|
|
+ construct_eng_file(param);
|
|
+
|
|
+ return load_config(param->file_name);
|
|
+}
|
|
+
|
|
+void destroy_eng_config(GKeyFile *config)
|
|
+{
|
|
+ unload_config(config);
|
|
+}
|
|
+
|
|
+void init_task_param(struct task_test_param *param, const char *eng)
|
|
+{
|
|
+ param->name = DEFAULT_TASK;
|
|
+ param->proj = DEFAULT_PROJ;
|
|
+ param->eng = eng;
|
|
+ param->type = "pid";
|
|
+ param->value = "1";
|
|
+ param->file_name = TMP_TASK_CONFIG;
|
|
+}
|
|
+
|
|
+void construct_task_file(struct task_test_param *param)
|
|
+{
|
|
+ FILE *file = NULL;
|
|
+
|
|
+ file = fopen(param->file_name, "w+");
|
|
+ CU_ASSERT_PTR_NOT_NULL(file);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, "[task]\n"), -1);
|
|
+ if (param->name != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_NAME, param->name), -1);
|
|
+ }
|
|
+ if (param->proj != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_PROJ, param->name), -1);
|
|
+ }
|
|
+ if (param->eng != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_ENG, param->name), -1);
|
|
+ }
|
|
+ if (param->type != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_TYPE, param->name), -1);
|
|
+ }
|
|
+ if (param->value != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_VALUE, param->name), -1);
|
|
+ }
|
|
+ fclose(file);
|
|
+}
|
|
+
|
|
+void init_slide_task(struct slide_task_test_param *param)
|
|
+{
|
|
+ init_task_param(¶m->task_param, "slide");
|
|
+ param->max_threads = "1";
|
|
+ param->T = "1";
|
|
+}
|
|
+
|
|
+void add_slide_task(struct slide_task_test_param *param)
|
|
+{
|
|
+ FILE *file = NULL;
|
|
+ const char *file_name = param->task_param.file_name;
|
|
+
|
|
+ file = fopen(file_name, "a+");
|
|
+ CU_ASSERT_PTR_NOT_NULL(file);
|
|
+ if (param->max_threads != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_MAX_THREADS, param->max_threads), -1);
|
|
+ }
|
|
+ if (param->T != NULL) {
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_T, param->T), -1);
|
|
+ }
|
|
+ fclose(file);
|
|
+}
|
|
+
|
|
+GKeyFile *construct_slide_task_config(struct slide_task_test_param *param)
|
|
+{
|
|
+ struct task_test_param *task_param = ¶m->task_param;
|
|
+
|
|
+ construct_task_file(task_param);
|
|
+ add_slide_task(param);
|
|
+
|
|
+ return load_config(task_param->file_name);
|
|
+}
|
|
+
|
|
+void destroy_slide_task_config(GKeyFile *config)
|
|
+{
|
|
+ unload_config(config);
|
|
+}
|
|
+
|
|
+void init_slide_eng(struct eng_test_param *param)
|
|
+{
|
|
+ param->name = "slide";
|
|
+ param->proj = DEFAULT_PROJ;
|
|
+ param->file_name = TMP_ENG_CONFIG;
|
|
+}
|
|
+
|
|
+static char *get_node_pair(void)
|
|
+{
|
|
+ int node_num = numa_num_configured_nodes();
|
|
+
|
|
+ switch (node_num) {
|
|
+ case ONE_NODE_PAIR:
|
|
+ return "0,1";
|
|
+ case TWO_NODE_PAIR:
|
|
+ return "0,2;1,3";
|
|
+ case THREE_NODE_PAIR:
|
|
+ return "0,3;1,4;2,5";
|
|
+ default:
|
|
+ return NULL;
|
|
+ }
|
|
+}
|
|
+
|
|
+int get_first_cold_node(struct cslide_eng_test_param *param)
|
|
+{
|
|
+ return param->node_pair[FIRST_COLD_NODE_INDEX] - '0';
|
|
+}
|
|
+
|
|
+int get_first_hot_node(struct cslide_eng_test_param *param)
|
|
+{
|
|
+ return param->node_pair[FIRST_HOT_NODE_INDEX] - '0';
|
|
+}
|
|
+
|
|
+int get_second_cold_node(struct cslide_eng_test_param *param)
|
|
+{
|
|
+ return param->node_pair[SECOND_COLD_NODE_INDEX] - '0';
|
|
+}
|
|
+
|
|
+int get_second_hot_node(struct cslide_eng_test_param *param)
|
|
+{
|
|
+ return param->node_pair[SECOND_HOT_NODE_INDEX] - '0';
|
|
+}
|
|
+
|
|
+void init_cslide_eng(struct cslide_eng_test_param *param)
|
|
+{
|
|
+ param->eng_param.name = "cslide";
|
|
+ param->eng_param.proj = DEFAULT_PROJ;
|
|
+ param->eng_param.file_name = TMP_ENG_CONFIG;
|
|
+ param->node_pair = get_node_pair();
|
|
+ param->hot_threshold = "2";
|
|
+ param->node_mig_quota = "1024";
|
|
+ param->node_hot_reserve = "1024";
|
|
+}
|
|
+
|
|
+void add_cslide_eng(struct cslide_eng_test_param *param)
|
|
+{
|
|
+ FILE *file = NULL;
|
|
+ const char *file_name = param->eng_param.file_name;
|
|
+
|
|
+ file = fopen(file_name, "a+");
|
|
+ CU_ASSERT_PTR_NOT_NULL(file);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_NODE_PAIR, param->node_pair), -1);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_THRESH, param->hot_threshold), -1);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_QUOTA, param->node_mig_quota), -1);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_RESV, param->node_hot_reserve), -1);
|
|
+ fclose(file);
|
|
+}
|
|
+
|
|
+GKeyFile *construct_cslide_eng_config(struct cslide_eng_test_param *param)
|
|
+{
|
|
+ struct eng_test_param *eng_param = ¶m->eng_param;
|
|
+
|
|
+ construct_eng_file(eng_param);
|
|
+ add_cslide_eng(param);
|
|
+
|
|
+ return load_config(eng_param->file_name);
|
|
+}
|
|
+
|
|
+void destroy_cslide_eng_config(GKeyFile *config)
|
|
+{
|
|
+ unload_config(config);
|
|
+}
|
|
+
|
|
+void init_cslide_task(struct cslide_task_test_param *param)
|
|
+{
|
|
+ init_task_param(¶m->task_param, "cslide");
|
|
+ param->vm_flags = "ht";
|
|
+ param->anon_only = "no";
|
|
+ param->ign_host = "yes";
|
|
+}
|
|
+
|
|
+void add_cslide_task(struct cslide_task_test_param *param)
|
|
+{
|
|
+ FILE *file = NULL;
|
|
+ const char *file_name = param->task_param.file_name;
|
|
+
|
|
+ file = fopen(file_name, "a+");
|
|
+ CU_ASSERT_PTR_NOT_NULL(file);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_VM_FLAGS, param->vm_flags), -1);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_ANON_ONLY, param->anon_only), -1);
|
|
+ CU_ASSERT_NOT_EQUAL(fprintf(file, CONFIG_IGN_HOST, param->ign_host), -1);
|
|
+ fclose(file);
|
|
+}
|
|
+
|
|
+GKeyFile *construct_cslide_task_config(struct cslide_task_test_param *param)
|
|
+{
|
|
+ struct task_test_param *task_param = ¶m->task_param;
|
|
+
|
|
+ construct_task_file(task_param);
|
|
+ add_cslide_task(param);
|
|
+
|
|
+ return load_config(task_param->file_name);
|
|
+}
|
|
+
|
|
+void destroy_cslide_task_config(GKeyFile *config)
|
|
+{
|
|
+ unload_config(config);
|
|
+}
|
|
diff --git a/etmem/test/common/test_common.h b/etmem/test/common/test_common.h
|
|
new file mode 100644
|
|
index 0000000..009c458
|
|
--- /dev/null
|
|
+++ b/etmem/test/common/test_common.h
|
|
@@ -0,0 +1,138 @@
|
|
+/******************************************************************************
|
|
+ * Copyright (c) Huawei Technologies Co., Ltd. 2019-2021. All rights reserved.
|
|
+ * etmem is 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: louhongxiang
|
|
+ * Create: 2021-11-19
|
|
+ * Description: This is a header file of the export data structure definition for page.
|
|
+ ******************************************************************************/
|
|
+
|
|
+#ifndef TEST_COMMON_H
|
|
+#define TEST_COMMON_H
|
|
+
|
|
+#include <glib.h>
|
|
+
|
|
+#include "etmemd_project.h"
|
|
+
|
|
+#define CONFIG_NAME "name=%s\n"
|
|
+#define CONFIG_INTERVAL "interval=%s\n"
|
|
+#define CONFIG_LOOP "loop=%s\n"
|
|
+#define CONFIG_SLEEP "sleep=%s\n"
|
|
+#define TMP_PROJ_CONFIG "proj_tmp.config"
|
|
+#define DEFAULT_PROJ "default_proj"
|
|
+
|
|
+#define CONFIG_PROJ "project=%s\n"
|
|
+#define TMP_ENG_CONFIG "eng_tmp.config"
|
|
+
|
|
+#define CONFIG_ENG "engine=%s\n"
|
|
+#define CONFIG_TYPE "type=%s\n"
|
|
+#define CONFIG_VALUE "value=%s\n"
|
|
+#define TMP_TASK_CONFIG "task_tmp.config"
|
|
+#define DEFAULT_TASK "default_task"
|
|
+
|
|
+#define CONFIG_MAX_THREADS "max_threads=%s\n"
|
|
+#define CONFIG_T "T=%s\n"
|
|
+
|
|
+#define CONFIG_NODE_PAIR "node_pair=%s\n"
|
|
+#define CONFIG_THRESH "hot_threshold=%s\n"
|
|
+#define CONFIG_QUOTA "node_mig_quota=%s\n"
|
|
+#define CONFIG_RESV "node_hot_reserve=%s\n"
|
|
+
|
|
+#define CONFIG_VM_FLAGS "vm_flags=%s\n"
|
|
+#define CONFIG_ANON_ONLY "anon_only=%s\n"
|
|
+#define CONFIG_IGN_HOST "igno_host=%s\n"
|
|
+
|
|
+#define ONE_NODE_PAIR 2
|
|
+#define TWO_NODE_PAIR 4
|
|
+#define THREE_NODE_PAIR 5
|
|
+
|
|
+
|
|
+struct proj_test_param {
|
|
+ const char *sleep;
|
|
+ const char *interval;
|
|
+ const char *loop;
|
|
+ const char *proj_name;
|
|
+ const char *file_name;
|
|
+ enum opt_result expt;
|
|
+};
|
|
+
|
|
+struct eng_test_param {
|
|
+ const char *name;
|
|
+ const char *proj;
|
|
+ const char *file_name;
|
|
+};
|
|
+
|
|
+struct task_test_param {
|
|
+ const char *name;
|
|
+ const char *proj;
|
|
+ const char *eng;
|
|
+ const char *type;
|
|
+ const char *value;
|
|
+ const char *file_name;
|
|
+};
|
|
+
|
|
+struct slide_task_test_param {
|
|
+ struct task_test_param task_param;
|
|
+ const char *max_threads;
|
|
+ const char *T;
|
|
+};
|
|
+
|
|
+struct cslide_eng_test_param {
|
|
+ struct eng_test_param eng_param;
|
|
+ const char *node_pair;
|
|
+ const char *hot_threshold;
|
|
+ const char *node_mig_quota;
|
|
+ const char *node_hot_reserve;
|
|
+};
|
|
+
|
|
+struct cslide_task_test_param {
|
|
+ struct task_test_param task_param;
|
|
+ const char *vm_flags;
|
|
+ const char *anon_only;
|
|
+ const char *ign_host;
|
|
+};
|
|
+
|
|
+GKeyFile *load_config(const char *file_name);
|
|
+void unload_config(GKeyFile *config);
|
|
+
|
|
+void construct_proj_file(struct proj_test_param *param);
|
|
+GKeyFile *construct_proj_config(struct proj_test_param *param);
|
|
+void destroy_proj_config(GKeyFile *config);
|
|
+void init_proj_param(struct proj_test_param *param);
|
|
+void do_add_proj_test(struct proj_test_param *param);
|
|
+void do_rm_proj_test(struct proj_test_param *param);
|
|
+
|
|
+void construct_eng_file(struct eng_test_param *param);
|
|
+GKeyFile *construct_eng_config(struct eng_test_param *param);
|
|
+void destroy_eng_config(GKeyFile *config);
|
|
+
|
|
+void init_task_param(struct task_test_param *param, const char *eng);
|
|
+void construct_task_file(struct task_test_param *param);
|
|
+
|
|
+void init_slide_task(struct slide_task_test_param *param);
|
|
+void add_slide_task(struct slide_task_test_param *param);
|
|
+GKeyFile *construct_slide_task_config(struct slide_task_test_param *param);
|
|
+void destroy_slide_task_config(GKeyFile *config);
|
|
+void init_slide_eng(struct eng_test_param *param);
|
|
+
|
|
+void init_cslide_eng(struct cslide_eng_test_param *param);
|
|
+void add_cslide_eng(struct cslide_eng_test_param *param);
|
|
+GKeyFile *construct_cslide_eng_config(struct cslide_eng_test_param *param);
|
|
+void destroy_cslide_eng_config(GKeyFile *config);
|
|
+
|
|
+int get_first_cold_node(struct cslide_eng_test_param *param);
|
|
+int get_first_hot_node(struct cslide_eng_test_param *param);
|
|
+int get_second_cold_node(struct cslide_eng_test_param *param);
|
|
+int get_second_hot_node(struct cslide_eng_test_param *param);
|
|
+
|
|
+void init_cslide_task(struct cslide_task_test_param *param);
|
|
+void add_cslide_task(struct cslide_task_test_param *param);
|
|
+GKeyFile *construct_cslide_task_config(struct cslide_task_test_param *param);
|
|
+void destroy_cslide_task_config(GKeyFile *config);
|
|
+#endif
|
|
--
|
|
1.8.3.1
|
|
|