diff options
| -rw-r--r-- | .gitlab-ci.yml | 21 | ||||
| -rw-r--r-- | CMakeLists.txt | 5 | ||||
| -rw-r--r-- | demo/test_handle_logger.c | 50 |
3 files changed, 56 insertions, 20 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2f23374..fa80193 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,6 +7,7 @@ variables: stages: - build +- test .build_before_script: before_script: @@ -41,6 +42,26 @@ stages: tags: - share +run_test_for_centos7: + stage: test + image: $BUILD_IMAGE_CENTOS7 + extends: .build_by_travis_for_centos7 + script: + - yum makecache + - ./ci/travis.sh + - cd build + - ctest --verbose + +run_test_for_centos8: + stage: test + image: $BUILD_IMAGE_CENTOS8 + extends: .build_by_travis_for_centos8 + script: + - yum makecache + - ./ci/travis.sh + - cd build + - ctest --verbose + branch_build_debug_for_centos7: stage: build extends: .build_by_travis_for_centos7 diff --git a/CMakeLists.txt b/CMakeLists.txt index 5738e87..ebc3d34 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -69,4 +69,9 @@ install(FILES conf/MESA_handle_logger.conf DESTINATION /usr/lib/tmpfiles.d/ COMP add_executable(${lib_name}_demo demo/test_handle_logger.c) target_link_libraries(${lib_name}_demo pthread ${lib_name}_shared) +enable_testing() + +add_test(NAME test_compatible_mode COMMAND MESA_handle_logger_demo 1 ./demo_zlog.conf 1 100 0) +add_test(NAME test_perf COMMAND MESA_handle_logger_demo 2 ./demo_zlog.conf 1 1000 0) + include(Package) diff --git a/demo/test_handle_logger.c b/demo/test_handle_logger.c index bd36de3..7f28632 100644 --- a/demo/test_handle_logger.c +++ b/demo/test_handle_logger.c @@ -106,6 +106,7 @@ int main(int argc, char ** args) { pthread_t t[MAX_THREAD_NUM]; int i = 0; + int ret =0; if (argc != 6) { @@ -136,26 +137,35 @@ int main(int argc, char ** args) { printf("get log sample_handle error\n"); return -1; - } + } - test_handle = MESA_create_runtime_log_handle("./log/test_log", RLOG_LV_DEBUG); - if(test_handle == NULL) - { - printf("get log test_handle error\n"); - return -1; - } + test_handle = MESA_create_runtime_log_handle("./log/test_log", RLOG_LV_DEBUG); + if (test_handle == NULL) + { + printf("get log test_handle error\n"); + return -1; + } - for(i = 0; i < g_thread_num; i++) - { - pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i)); - } - signal(SIGINT, sig_int_handler); - signal(SIGHUP, sig_hup_handler); - while(1) - ; - //MESA_destroy_runtime_log_handle(sample_handle); - //MESA_destroy_runtime_log_handle(test_handle); - //sample_handle = NULL; - //test_handle = NULL; - return 0; + for (i = 0; i < g_thread_num; i++) + { + pthread_create(&t[i], NULL, thread_logger, (void *)(unsigned long)(i)); + } + signal(SIGINT, sig_int_handler); + signal(SIGHUP, sig_hup_handler); + + // 等待所有线程结束并回收 + for (i = 0; i < g_thread_num; ++i) { + ret = pthread_join(t[i], NULL); + if (ret != 0) { + fprintf(stderr, "Failed to join thread %d\n", i); + return 1; + } + } + + printf("All threads finished\n"); + // MESA_destroy_runtime_log_handle(sample_handle); + // MESA_destroy_runtime_log_handle(test_handle); + // sample_handle = NULL; + // test_handle = NULL; + return 0; } |
