summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorliuyu <[email protected]>2024-07-07 21:20:25 +0800
committerliuyu <[email protected]>2024-07-07 21:20:25 +0800
commitabff8ac70093fe2b29e3a4a7ff5b4f1f2d73edb7 (patch)
treef4f8d27a8f82a1ea4155c8471304101d12c38600
parent4d5c9b6f26237c4b5f61da362e9decb7bf83ddf4 (diff)
调整ut目录结构
-rw-r--r--.vscode/settings.json3
-rw-r--r--bbq/CMakeLists.txt2
-rw-r--r--bbq/tests/CMakeLists.txt18
-rw-r--r--bbq/tests/unittest/CMakeLists.txt11
-rw-r--r--bbq/tests/unittest/ut.h37
-rw-r--r--bbq/unittest/CMakeLists.txt25
-rw-r--r--bbq/unittest/ut_bbq_func.c (renamed from bbq/tests/common/test_queue.c)10
-rw-r--r--bbq/unittest/ut_bbq_func.h (renamed from bbq/tests/common/test_queue.h)0
-rw-r--r--bbq/unittest/ut_example.cc (renamed from bbq/tests/unittest/ut_example.cc)5
-rw-r--r--perf/CMakeLists.txt4
-rw-r--r--perf/benchmark/CMakeLists.txt4
-rw-r--r--perf/benchmark/bcm_benchmark.c4
-rw-r--r--perf/benchmark/bcm_loadconfig.c5
-rw-r--r--perf/benchmark/bcm_queue.h4
14 files changed, 46 insertions, 86 deletions
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 4814c5b..9306e20 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -94,7 +94,8 @@
"prctl.h": "c",
"types.h": "c",
"chrono": "c",
- "fstream": "c"
+ "fstream": "c",
+ "ut_bbq_func.h": "c"
},
"commentTranslate.hover.enabled": true
} \ No newline at end of file
diff --git a/bbq/CMakeLists.txt b/bbq/CMakeLists.txt
index e8f8a9b..bd81b28 100644
--- a/bbq/CMakeLists.txt
+++ b/bbq/CMakeLists.txt
@@ -38,4 +38,4 @@ enable_testing() # 开启测试,否则无法执行make test
# 添加子目录
add_subdirectory(src)
-add_subdirectory(tests) \ No newline at end of file
+add_subdirectory(unittest) \ No newline at end of file
diff --git a/bbq/tests/CMakeLists.txt b/bbq/tests/CMakeLists.txt
deleted file mode 100644
index 2513fbd..0000000
--- a/bbq/tests/CMakeLists.txt
+++ /dev/null
@@ -1,18 +0,0 @@
-cmake_minimum_required(VERSION 3.0)
-project(BBQ_TESTS)
-
-file(GLOB SRC_COMMON_LIST "${CMAKE_CURRENT_SOURCE_DIR}/common/*.c")
-
-# 指定库路径
-link_directories(${LIB_PATH})
-# 指定头文件
-include_directories(
- ${CMAKE_CURRENT_SOURCE_DIR}/common/
-)
-
-# 链接静态库
-link_libraries(bbq)
-# 指定可执行文件输出路径
-set(EXECUTABLE_OUTPUT_PATH ${EXEC_PATH})
-
-add_subdirectory(unittest)
diff --git a/bbq/tests/unittest/CMakeLists.txt b/bbq/tests/unittest/CMakeLists.txt
deleted file mode 100644
index 835058b..0000000
--- a/bbq/tests/unittest/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-cmake_minimum_required(VERSION 3.0)
-project(BBQ_UNITTEST)
-
-# 搜索当前cmake文件所在目录下的c文件
-file(GLOB SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
-list(APPEND SRC_LIST ${SRC_COMMON_LIST})
-
-add_executable(bbq_unittest ${SRC_LIST}) # 添加可执行程序
-target_link_libraries(bbq_unittest gtest gtest_main pthread) # 链接gtest库
-
-add_test(bbq_unittest ${EXEC_PATH}/bbq_unittest) # 添加测试,保证make test可以执行该测试用例 \ No newline at end of file
diff --git a/bbq/tests/unittest/ut.h b/bbq/tests/unittest/ut.h
deleted file mode 100644
index 32e1a2c..0000000
--- a/bbq/tests/unittest/ut.h
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * @Author: liuyu
- * @LastEditTime: 2024-07-07 18:07:51
- * @Email: [email protected]
- * @Describe: TODO
- */
-
-#ifndef _UT_H_
-#define _UT_H_
-#include "bbq.h"
-#include "test_queue.h"
-#include <stdint.h>
-
-typedef struct {
- uint64_t v1;
- uint64_t v2;
-} testdata_s;
-
-typedef struct {
- struct bbq *q;
- uint32_t usleep; // 该线程每次执行间隔睡眠时间
- bool until_end; // 循环读取,直到队列空或满
- uint64_t thread_exec_times; // 每个线程生产/消费次数
-} thread_arg_s;
-
-typedef struct {
- pthread_t thread_id;
- enum ut_thread_type type; // 线程类型
- uint64_t exec_times; // 执行次数
- uint64_t succ_times; // 成功次数
- uint64_t full_times; // 失败,队列满次数
- uint64_t busy_times; // 失败,队列忙次数
- uint64_t empty_times; // 失败,队列空次数
- testdata_s *data; // 线程数据
- thread_arg_s *arg; // 创建线程时传入的参数
-} thread_data_s;
-#endif \ No newline at end of file
diff --git a/bbq/unittest/CMakeLists.txt b/bbq/unittest/CMakeLists.txt
new file mode 100644
index 0000000..fedd026
--- /dev/null
+++ b/bbq/unittest/CMakeLists.txt
@@ -0,0 +1,25 @@
+cmake_minimum_required(VERSION 3.0)
+project(BBQ_TESTS)
+
+
+# 指定库路径
+link_directories(${LIB_PATH})
+# 指定头文件
+include_directories(
+ ${CMAKE_CURRENT_SOURCE_DIR}/common/
+)
+
+# 链接静态库
+link_libraries(bbq)
+# 指定可执行文件输出路径
+set(EXECUTABLE_OUTPUT_PATH ${EXEC_PATH})
+
+# 搜索当前cmake文件所在目录下的c文件
+file(GLOB SRC_C_LIST "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
+file(GLOB SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/*.cc")
+list(APPEND SRC_LIST ${SRC_C_LIST})
+
+add_executable(bbq_unittest ${SRC_LIST}) # 添加可执行程序
+target_link_libraries(bbq_unittest gtest gtest_main pthread) # 链接gtest库
+
+add_test(bbq_unittest ${EXEC_PATH}/bbq_unittest) # 添加测试,保证make test可以执行该测试用例
diff --git a/bbq/tests/common/test_queue.c b/bbq/unittest/ut_bbq_func.c
index 2b10074..7c35484 100644
--- a/bbq/tests/common/test_queue.c
+++ b/bbq/unittest/ut_bbq_func.c
@@ -1,11 +1,11 @@
/*
* @Author: liuyu
- * @LastEditTime: 2024-07-07 20:51:03
+ * @LastEditTime: 2024-07-07 21:20:03
* @Describe: TODO
*/
-#include "test_queue.h"
+#include "ut_bbq_func.h"
#include "bbq.h"
#include <pthread.h>
#include <string.h>
@@ -13,12 +13,12 @@
#include <sys/time.h>
#include <unistd.h>
-typedef struct {
+struct ut_memory {
aotmic_uint64 malloc_cnt;
aotmic_uint64 free_cnt;
-} ut_memory_s;
+};
-ut_memory_s ut_memory_g[UT_MODULE_MAX] = {0};
+struct ut_memory ut_memory_g[UT_MODULE_MAX] = {0};
char *ut_ring_type_map[UT_RING_TYPE_MAX] = {
[UT_RING_TYPE_BBQ] = UT_RING_TYPE_BBQ_STR,
diff --git a/bbq/tests/common/test_queue.h b/bbq/unittest/ut_bbq_func.h
index ba2ea9c..ba2ea9c 100644
--- a/bbq/tests/common/test_queue.h
+++ b/bbq/unittest/ut_bbq_func.h
diff --git a/bbq/tests/unittest/ut_example.cc b/bbq/unittest/ut_example.cc
index 0dc12ce..58491ee 100644
--- a/bbq/tests/unittest/ut_example.cc
+++ b/bbq/unittest/ut_example.cc
@@ -1,14 +1,13 @@
/*
* @Author: liuyu
- * @LastEditTime: 2024-07-07 20:55:43
+ * @LastEditTime: 2024-07-07 21:18:49
* @Describe: 简单的测试用例,测试基本功能
*/
#include "gtest/gtest.h"
extern "C" {
-#include "test_queue.h"
-#include "ut.h"
+#include "ut_bbq_func.h"
#include <math.h>
extern bool bbq_debug_check_array_bounds(struct bbq *q);
extern void bbq_struct_print(struct bbq *q);
diff --git a/perf/CMakeLists.txt b/perf/CMakeLists.txt
index 803ebbe..2b0d1a0 100644
--- a/perf/CMakeLists.txt
+++ b/perf/CMakeLists.txt
@@ -4,7 +4,7 @@ project(BBQ_BENCHMARK)
# 头文件目录
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/../bbq/include
- ${CMAKE_CURRENT_SOURCE_DIR}/../bbq/tests/common
+ ${CMAKE_CURRENT_SOURCE_DIR}/../bbq/unittest
${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/iniparser
${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/rmind_ringbuf
/root/code/c/dpdk-21.11.4/install/include
@@ -12,7 +12,7 @@ include_directories(
)
# 将bbq单元测试里的公共文件,添加到perf里。
-SET(TEST_COMMON_DIR ${PROJECT_SOURCE_DIR}/../bbq/tests/common)
+SET(UT_BBQ_FUNC_DIR ${PROJECT_SOURCE_DIR}/../bbq/unittest)
# 设置输出目录
if(NOT DEFINED OUTPUT_DIR)
diff --git a/perf/benchmark/CMakeLists.txt b/perf/benchmark/CMakeLists.txt
index 1e5a318..ed7de37 100644
--- a/perf/benchmark/CMakeLists.txt
+++ b/perf/benchmark/CMakeLists.txt
@@ -3,8 +3,8 @@ project(BBQ_BENCHMARK)
# 搜索当前cmake文件所在目录下的c文件
file(GLOB SRC_LIST "${CMAKE_CURRENT_SOURCE_DIR}/*.c")
-file(GLOB SRC_COMMON_LIST "${TEST_COMMON_DIR}/*.c")
-list(APPEND SRC_LIST ${SRC_COMMON_LIST})
+file(GLOB SRC_BBQ_UT_FUNC_LIST "${UT_BBQ_FUNC_DIR}/*.c")
+list(APPEND SRC_LIST ${SRC_BBQ_UT_FUNC_LIST})
# 指定可执行文件输出路径
set(EXECUTABLE_OUTPUT_PATH ${EXEC_PATH})
diff --git a/perf/benchmark/bcm_benchmark.c b/perf/benchmark/bcm_benchmark.c
index 99afb3d..5a7db7a 100644
--- a/perf/benchmark/bcm_benchmark.c
+++ b/perf/benchmark/bcm_benchmark.c
@@ -1,13 +1,13 @@
/*
* @Author: liuyu
- * @LastEditTime: 2024-07-07 20:56:02
+ * @LastEditTime: 2024-07-07 21:19:02
* @Describe: TODO
*/
#include "bbq.h"
#include "bcm_queue.h"
#include "iniparser.h"
-#include "test_queue.h"
+#include "ut_bbq_func.h"
#include <pthread.h>
#include <stdatomic.h>
#include <stdlib.h>
diff --git a/perf/benchmark/bcm_loadconfig.c b/perf/benchmark/bcm_loadconfig.c
index b527130..d6c96fb 100644
--- a/perf/benchmark/bcm_loadconfig.c
+++ b/perf/benchmark/bcm_loadconfig.c
@@ -1,12 +1,13 @@
/*
* @Author: liuyu
- * @LastEditTime: 2024-07-07 19:01:27
+ * @LastEditTime: 2024-07-07 21:18:59
* @Describe: TODO
*/
#include "bbq.h"
#include "iniparser.h"
-#include "test_queue.h"
+#include "ut_bbq_func.h"
+
#include <string.h>
int ut_load_config(const char *config, const char *ring_type, uint32_t burst_cnt, struct ut_cfg *cfg) {
diff --git a/perf/benchmark/bcm_queue.h b/perf/benchmark/bcm_queue.h
index b996088..11006e4 100644
--- a/perf/benchmark/bcm_queue.h
+++ b/perf/benchmark/bcm_queue.h
@@ -1,10 +1,10 @@
/*
* @Author: liuyu
- * @LastEditTime: 2024-07-07 20:41:23
+ * @LastEditTime: 2024-07-07 21:18:56
* @Describe: TODO
*/
#include "rte_ring.h"
-#include "test_queue.h"
+#include "ut_bbq_func.h"
extern int bcm_queue_init(struct ut_cfg *cfg, struct ut_queue *q); \ No newline at end of file