diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000..0e52438 --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,253 @@ +variables: + GIT_STRATEGY: "clone" + BUILD_PADDING_PREFIX: /tmp/padding_for_CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX_PREFIX/ + INSTALL_PREFIX: "/opt/tsg/stellar" + TESTING_VERSION_BUILD: 0 + BUILD_IMAGE_CENTOS7: "git.mesalab.cn:7443/mesa_platform/build-env:master" + BUILD_IMAGE_CENTOS8: "git.mesalab.cn:7443/mesa_platform/build-env:rockylinux" + +stages: + - build + - envelope + - upload + +.build_before_script: + before_script: + - mkdir -p $BUILD_PADDING_PREFIX/$CI_PROJECT_NAMESPACE/ + - ln -s $CI_PROJECT_DIR $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH + - cd $BUILD_PADDING_PREFIX/$CI_PROJECT_PATH + - chmod +x ./ci/travis.sh + - yum makecache + - yum install -y elfutils-libelf-devel + +.build_by_travis_for_centos7: + stage: build + image: $BUILD_IMAGE_CENTOS7 + extends: .build_before_script + script: + - ./ci/travis.sh + tags: + - share + +.build_by_travis_for_centos8: + stage: build + image: $BUILD_IMAGE_CENTOS8 + extends: .build_before_script + script: + - ./ci/travis.sh + tags: + - share + +############################################################################### +# compile use image: build-env:master +############################################################################### + +branch_build_debug_for_centos7: + extends: .build_by_travis_for_centos7 + variables: + BUILD_TYPE: Debug + except: + - /^develop-.*$/i + - /^release-.*$/i + - tags + +branch_build_release_for_centos7: + variables: + BUILD_TYPE: RelWithDebInfo + extends: .build_by_travis_for_centos7 + except: + - /^develop-.*$/i + - /^release-.*$/i + - tags + +develop_build_debug_for_centos7: + extends: .build_by_travis_for_centos7 + variables: + TESTING_VERSION_BUILD: 1 + UPLOAD_SYMBOL_FILES: 1 + BUILD_TYPE: Debug + # ASAN_OPTION: ADDRESS + PACKAGE: 1 + PULP3_REPO_NAME: stellar-testing-x86_64.el7 + PULP3_DIST_NAME: stellar-testing-x86_64.el7 + artifacts: + name: "stellar-develop-$CI_COMMIT_REF_NAME-debug" + paths: + - build/*.rpm + only: + - /^develop-.*$/i + - /^release-.*$/i + +develop_build_release_for_centos7: + extends: .build_by_travis_for_centos7 + variables: + TESTING_VERSION_BUILD: 1 + UPLOAD_SYMBOL_FILES: 1 + # ASAN_OPTION: ADDRESS + BUILD_TYPE: RelWithDebInfo + PACKAGE: 1 + PULP3_REPO_NAME: stellar-testing-x86_64.el7 + PULP3_DIST_NAME: stellar-testing-x86_64.el7 + artifacts: + name: "stellar-develop-$CI_COMMIT_REF_NAME-release" + paths: + - build/*.rpm + only: + - /^develop-.*$/i + - /^release-.*$/i + +release_build_debug_for_centos7: + variables: + UPLOAD_SYMBOL_FILES: 1 + BUILD_TYPE: Debug + PACKAGE: 1 + PULP3_REPO_NAME: stellar-stable-x86_64.el7 + PULP3_DIST_NAME: stellar-stable-x86_64.el7 + extends: .build_by_travis_for_centos7 + artifacts: + name: "stellar-install-$CI_COMMIT_REF_NAME-debug" + paths: + - build/*.rpm + only: + - tags + +release_build_release_for_centos7: + variables: + BUILD_TYPE: RelWithDebInfo + UPLOAD_SYMBOL_FILES: 1 + PACKAGE: 1 + PULP3_REPO_NAME: stellar-stable-x86_64.el7 + PULP3_DIST_NAME: stellar-stable-x86_64.el7 + extends: .build_by_travis_for_centos7 + artifacts: + name: "stellar-install-$CI_COMMIT_REF_NAME-release" + paths: + - build/*.rpm + only: + - tags + +############################################################################### +# compile use image: build-env:rockylinux +############################################################################### + +branch_build_debug_for_centos8: + extends: .build_by_travis_for_centos8 + variables: + BUILD_TYPE: Debug + except: + - /^develop-.*$/i + - /^release-.*$/i + - tags + +branch_build_release_for_centos8: + variables: + BUILD_TYPE: RelWithDebInfo + extends: .build_by_travis_for_centos8 + except: + - /^develop-.*$/i + - /^release-.*$/i + - tags + +develop_build_debug_for_centos8: + extends: .build_by_travis_for_centos8 + variables: + TESTING_VERSION_BUILD: 1 + UPLOAD_SYMBOL_FILES: 1 + BUILD_TYPE: Debug + # ASAN_OPTION: ADDRESS + PACKAGE: 1 + PULP3_REPO_NAME: stellar-testing-x86_64.el8 + PULP3_DIST_NAME: stellar-testing-x86_64.el8 + artifacts: + name: "stellar-develop-$CI_COMMIT_REF_NAME-debug" + paths: + - build/*.rpm + only: + - /^develop-.*$/i + - /^release-.*$/i + +develop_build_release_for_centos8: + extends: .build_by_travis_for_centos8 + variables: + TESTING_VERSION_BUILD: 1 + UPLOAD_SYMBOL_FILES: 1 + # ASAN_OPTION: ADDRESS + BUILD_TYPE: RelWithDebInfo + PACKAGE: 1 + PULP3_REPO_NAME: stellar-testing-x86_64.el8 + PULP3_DIST_NAME: stellar-testing-x86_64.el8 + artifacts: + name: "stellar-develop-$CI_COMMIT_REF_NAME-release" + paths: + - build/*.rpm + only: + - /^develop-.*$/i + - /^release-.*$/i + +release_build_debug_for_centos8: + variables: + UPLOAD_SYMBOL_FILES: 1 + BUILD_TYPE: Debug + PACKAGE: 1 + PULP3_REPO_NAME: stellar-stable-x86_64.el8 + PULP3_DIST_NAME: stellar-stable-x86_64.el8 + extends: .build_by_travis_for_centos8 + artifacts: + name: "stellar-install-$CI_COMMIT_REF_NAME-debug" + paths: + - build/*.rpm + only: + - tags + +release_build_release_for_centos8: + variables: + BUILD_TYPE: RelWithDebInfo + UPLOAD_SYMBOL_FILES: 1 + PACKAGE: 1 + PULP3_REPO_NAME: stellar-stable-x86_64.el8 + PULP3_DIST_NAME: stellar-stable-x86_64.el8 + extends: .build_by_travis_for_centos8 + artifacts: + name: "stellar-install-$CI_COMMIT_REF_NAME-release" + paths: + - build/*.rpm + only: + - tags + +############################################################################### +# envelope and upload +############################################################################### + +envelope_rpm: + stage: envelope + image: $BUILD_IMAGE_CENTOS7 + variables: + FEATURE_ID: 100 + APP_NAME_IN_RPM_SPEC: stellar + script: + - chmod +x ./ci/envelope_rpm.sh + - ./ci/envelope_rpm.sh + artifacts: + name: "stellar-pr-$CI_COMMIT_REF_NAME-release" + paths: + - build/*-pr-*.rpm + tags: + - envelope + only: + - tags + +upload_enveloped_rpm: + stage: upload + image: $BUILD_IMAGE_CENTOS7 + variables: + PULP3_REPO_NAME_EL7: stellar-stable-x86_64.el7 + PULP3_DIST_NAME_EL7: stellar-stable-x86_64.el7 + PULP3_REPO_NAME_EL8: stellar-stable-x86_64.el8 + PULP3_DIST_NAME_EL8: stellar-stable-x86_64.el8 + script: + - chmod +x ./ci/upload_enveloped_rpm.sh + - ./ci/upload_enveloped_rpm.sh + tags: + - share + only: + - tags \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index d1f406e..9bb7320 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,21 +1,35 @@ -cmake_minimum_required(VERSION 3.14) +cmake_minimum_required(VERSION 3.12) project(stellar) -# GoogleTest requires at least C++11 -set(CMAKE_CXX_STANDARD 11) - -#find required package set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake) include(Version) -find_package(PkgConfig REQUIRED) -find_package(Threads REQUIRED) -find_package(PCAP REQUIRED) -pkg_check_modules(SYSTEMD REQUIRED systemd) +include(Package) +add_definitions(-D_GNU_SOURCE) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_C_STANDARD 11) + +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE RelWithDebInfo) +endif() + +if (CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) + set (CMAKE_INSTALL_PREFIX "/opt/tsg/stellar" CACHE PATH "default install path" FORCE) +endif() + +option(ENABLE_PIC "Generate position independent code (necessary for shared libraries)" TRUE) +option(ENABLE_WARNING_ALL "Enable all optional warnings which are desirable for normal code" TRUE) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lelf") + +add_custom_target("install-program" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Program -P cmake_install.cmake) +add_custom_target("install-profile" COMMAND ${CMAKE_COMMAND} ARGS -DCOMPONENT=Profile -P cmake_install.cmake) include_directories(${CMAKE_SOURCE_DIR}/sdk/include) -#add vendor and source directory +add_subdirectory(conf) add_subdirectory(vendor) add_subdirectory(deps/toml) add_subdirectory(deps/sds) @@ -23,11 +37,5 @@ add_subdirectory(deps/timeout) add_subdirectory(src) add_subdirectory(sdk/example) - -#add gtest enable_testing() -add_subdirectory(test) - - - - +add_subdirectory(test) \ No newline at end of file diff --git a/cmake/autorevision.sh b/autorevision.sh similarity index 93% rename from cmake/autorevision.sh rename to autorevision.sh index 3baa179..80d0712 100644 --- a/cmake/autorevision.sh +++ b/autorevision.sh @@ -9,7 +9,7 @@ # Usage message. arUsage() { - cat > "/dev/stderr" << EOF + cat >"/dev/stderr" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" < "${TARGETFILE}" << EOF + cat >"${TARGETFILE}" </dev/null)" ]; then local gitPath="$(git rev-parse --show-toplevel)" local gitDepth="$(pathSegment "${gitPath}")" - REPONUM="$((REPONUM+1))" + REPONUM="$((REPONUM + 1))" else local gitDepth="0" fi if [ ! -z "$(hg root 2>/dev/null)" ]; then local hgPath="$(hg root 2>/dev/null)" local hgDepth="$(pathSegment "${hgPath}")" - REPONUM="$((REPONUM+1))" + REPONUM="$((REPONUM + 1))" else local hgDepth="0" fi if [ ! -z "$(bzr root 2>/dev/null)" ]; then local bzrPath="$(bzr root 2>/dev/null)" local bzrDepth="$(pathSegment "${bzrPath}")" - REPONUM="$((REPONUM+1))" + REPONUM="$((REPONUM + 1))" else local bzrDepth="0" fi @@ -1114,12 +1111,12 @@ repoTest() { local svnPath="$(svn info --xml | sed -n -e "s:${stringz}::" -e "s:${stringx}::p")" # An old enough svn will not be able give us a path; default # to 1 for that case. - if [ -z "${svnPath}" ]; then + if [ -z "${svnPath}" ]; then local svnDepth="1" else local svnDepth="$(pathSegment "${svnPath}")" fi - REPONUM="$((REPONUM+1))" + REPONUM="$((REPONUM + 1))" else local svnDepth="0" fi @@ -1142,8 +1139,6 @@ repoTest() { fi } - - # Detect which repos we are in and gather data. # shellcheck source=/dev/null if [ -f "${CACHEFILE}" ] && [ "${CACHEFORCE}" = "1" ]; then @@ -1165,7 +1160,6 @@ else fi fi - # -s output is handled here. if [ ! -z "${VAROUT}" ]; then if [ "${VAROUT}" = "VCS_TYPE" ]; then @@ -1196,7 +1190,6 @@ if [ ! -z "${VAROUT}" ]; then fi fi - # Detect requested output type and use it. if [ ! -z "${AFILETYPE}" ]; then if [ "${AFILETYPE}" = "c" ]; then @@ -1251,7 +1244,6 @@ if [ ! -z "${AFILETYPE}" ]; then fi fi - # If requested, make a cache file. if [ ! -z "${CACHEFILE}" ] && [ ! "${CACHEFORCE}" = "1" ]; then TARGETFILE="${CACHEFILE}.tmp" diff --git a/ci/envelope_rpm.sh b/ci/envelope_rpm.sh new file mode 100644 index 0000000..4aa2978 --- /dev/null +++ b/ci/envelope_rpm.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env sh + +ls $CI_PROJECT_DIR/build/*.rpm + +BIN_TO_PROTECT_IN_RPM="${INSTALL_PREFIX}/bin/stellar" +RPMS_FULL_PATH=$(ls $CI_PROJECT_DIR/build/*.rpm | grep -v debug | grep -v devel) +echo "RPMS_TO_BE_ENVELOPE: " $RPMS_FULL_PATH + +for RPM in ${RPMS_FULL_PATH[@]}; do + echo "ENVELOPE: " $RPM + /root/rebuildrpm_and_envelope.sh $RPM $BIN_TO_PROTECT_IN_RPM $FEATURE_ID $APP_NAME_IN_RPM_SPEC +done diff --git a/ci/get-nprocessors.sh b/ci/get-nprocessors.sh new file mode 100644 index 0000000..8a754cf --- /dev/null +++ b/ci/get-nprocessors.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash +# Copyright 2017 Google Inc. +# All Rights Reserved. +# +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions are +# met: +# +# * Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# * Redistributions in binary form must reproduce the above +# copyright notice, this list of conditions and the following disclaimer +# in the documentation and/or other materials provided with the +# distribution. +# * Neither the name of Google Inc. nor the names of its +# contributors may be used to endorse or promote products derived from +# this software without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +# This file is typically sourced by another script. +# if possible, ask for the precise number of processors, +# otherwise take 2 processors as reasonable default; see +# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization +if [ -x /usr/bin/getconf ]; then + NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN) +else + NPROCESSORS=2 +fi + +# as of 2017-09-04 Travis CI reports 32 processors, but GCC build +# crashes if parallelized too much (maybe memory consumption problem), +# so limit to 4 processors for the time being. +if [ $NPROCESSORS -gt 4 ]; then + echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4." + NPROCESSORS=4 +fi diff --git a/ci/perpare_pulp3_netrc.sh b/ci/perpare_pulp3_netrc.sh new file mode 100644 index 0000000..0aca8ec --- /dev/null +++ b/ci/perpare_pulp3_netrc.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env sh +set -evx +echo "machine ${PULP3_SERVER_URL}\nlogin ${PULP3_SERVER_LOGIN}\npassword ${PULP3_SERVER_PASSWORD}\n" >~/.netrc diff --git a/ci/travis.sh b/ci/travis.sh new file mode 100644 index 0000000..6f30ffd --- /dev/null +++ b/ci/travis.sh @@ -0,0 +1,66 @@ +#!/usr/bin/env sh +set -evx + +chmod +x ci/get-nprocessors.sh +. ci/get-nprocessors.sh + +# if possible, ask for the precise number of processors, +# otherwise take 2 processors as reasonable default; see +# https://docs.travis-ci.com/user/speeding-up-the-build/#Makefile-optimization +if [ -x /usr/bin/getconf ]; then + NPROCESSORS=$(/usr/bin/getconf _NPROCESSORS_ONLN) +else + NPROCESSORS=2 +fi + +# as of 2017-09-04 Travis CI reports 32 processors, but GCC build +# crashes if parallelized too much (maybe memory consumption problem), +# so limit to 4 processors for the time being. +if [ $NPROCESSORS -gt 4 ]; then + echo "$0:Note: Limiting processors to use by make from $NPROCESSORS to 4." + NPROCESSORS=4 +fi + +# Tell make to use the processors. No preceding '-' required. +MAKEFLAGS="j${NPROCESSORS}" +export MAKEFLAGS + +env | sort + +# Set default values to OFF for these variables if not specified. +: "${NO_EXCEPTION:=OFF}" +: "${NO_RTTI:=OFF}" +: "${COMPILER_IS_GNUCXX:=OFF}" + +# Install dependency from YUM +yum install -y libpcap-devel + +if [ $ASAN_OPTION ]; then + source /opt/rh/devtoolset-7/enable +fi + +mkdir build || true +cd build + +cmake3 -DCMAKE_CXX_FLAGS=$CXX_FLAGS \ + -DCMAKE_BUILD_TYPE=$BUILD_TYPE \ + -DASAN_OPTION=$ASAN_OPTION \ + -DCMAKE_INSTALL_PREFIX=$INSTALL_PREFIX \ + -DTFE_VERSION_DAILY_BUILD=$TESTING_VERSION_BUILD \ + .. + +make +make test + +if [ -n "${PACKAGE}" ]; then + make package + cp ~/rpm_upload_tools.py ./ + python3 rpm_upload_tools.py ${PULP3_REPO_NAME} ${PULP3_DIST_NAME} *.rpm +fi + +if [ -n "${UPLOAD_SYMBOL_FILES}" ]; then + rpm -i stellar*debuginfo*.rpm + ls -ahl /usr/lib/debug/opt/tsg/stellar/bin/ + cp /usr/lib/debug/opt/tsg/stellar/bin/stellar*debug /tmp/stellar.debuginfo.${CI_COMMIT_SHORT_SHA} + sentry-cli upload-dif -t elf /tmp/stellar.debuginfo.${CI_COMMIT_SHORT_SHA} +fi diff --git a/ci/upload_enveloped_rpm.sh b/ci/upload_enveloped_rpm.sh new file mode 100644 index 0000000..0faae1a --- /dev/null +++ b/ci/upload_enveloped_rpm.sh @@ -0,0 +1,21 @@ +#!/usr/bin/env sh + +cd $CI_PROJECT_DIR/build/ +cp ~/rpm_upload_tools.py ./ + +ls -ahl *.rpm + +RPM_IS_EL7=$(ls -ahl *-pr-*.rpm | grep el7 | wc -l) +RPM_IS_EL8=$(ls -ahl *-pr-*.rpm | grep el8 | wc -l) + +if [ $RPM_IS_EL7 -eq 1 ]; then + echo "====== Upload the packed RPM package for CentOS7 ======" + python3 rpm_upload_tools.py ${PULP3_REPO_NAME_EL7} ${PULP3_DIST_NAME_EL7} *-pr-*el7*.rpm +fi + +if [ $RPM_IS_EL8 -eq 1 ]; then + echo "====== Upload the packed RPM package for CentOS8 ======" + python3 rpm_upload_tools.py ${PULP3_REPO_NAME_EL8} ${PULP3_DIST_NAME_EL8} *-pr-*el8*.rpm +fi + +rm -rf *.rpm diff --git a/cmake/FindSYSTEMD.cmake b/cmake/FindSYSTEMD.cmake new file mode 100644 index 0000000..c7decde --- /dev/null +++ b/cmake/FindSYSTEMD.cmake @@ -0,0 +1,39 @@ +# - Find SystemdDaemon +# Find the systemd daemon library +# +# This module defines the following variables: +# SYSTEMD_FOUND - True if library and include directory are found +# If set to TRUE, the following are also defined: +# SYSTEMD_INCLUDE_DIRS - The directory where to find the header file +# SYSTEMD_LIBRARIES - Where to find the library file +# +# For conveniance, these variables are also set. They have the same values +# than the variables above. The user can thus choose his/her prefered way +# to write them. +# SYSTEMD_LIBRARY +# SYSTEMD_INCLUDE_DIR +# +# This file is in the public domain + +include(FindPkgConfig) +pkg_check_modules(SYSTEMD libsystemd) + +if(NOT SYSTEMD_FOUND) + find_path(SYSTEMD_INCLUDE_DIRS NAMES systemd/sd-daemon.h + DOC "The Systemd include directory") + + find_library(SYSTEMD_LIBRARIES NAMES systemd + DOC "The Systemd library") + + # Use some standard module to handle the QUIETLY and REQUIRED arguments, and + # set SYSTEMD_FOUND to TRUE if these two variables are set. + include(FindPackageHandleStandardArgs) + find_package_handle_standard_args(SYSTEMD REQUIRED_VARS SYSTEMD_LIBRARIES SYSTEMD_INCLUDE_DIRS) + + if(SYSTEMD_FOUND) + set(SYSTEMD_LIBRARY ${SYSTEMD_LIBRARIES}) + set(SYSTEMD_INCLUDE_DIR ${SYSTEMD_INCLUDE_DIRS}) + endif() +endif() + +mark_as_advanced(SYSTEMD_INCLUDE_DIRS SYSTEMD_LIBRARIES) \ No newline at end of file diff --git a/cmake/Package.cmake b/cmake/Package.cmake new file mode 100644 index 0000000..3091159 --- /dev/null +++ b/cmake/Package.cmake @@ -0,0 +1,35 @@ +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CPACK_PACKAGE_NAME "stellar-debug") +else() + set(CPACK_PACKAGE_NAME "stellar") +endif() + +message(STATUS "Package: ${CPACK_PACKAGE_NAME}") + +set(CPACK_PACKAGE_VENDOR "TSG") +set(CPACK_PACKAGE_VERSION_MAJOR "${STELLAR_VERSION_MAJOR}") +set(CPACK_PACKAGE_VERSION_MINOR "${STELLAR_VERSION_MINOR}") +set(CPACK_PACKAGE_VERSION_PATCH "${STELLAR_VERSION_PATCH}.${STELLAR_DESCRIBE}") +set(CPACK_PACKAGING_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX}) + +# RPM Build +set(CPACK_GENERATOR "RPM") +set(CPACK_RPM_AUTO_GENERATED_FILE_NAME ON) +set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") +set(CPACK_RPM_PACKAGE_AUTOREQPROV "no") +set(CPACK_RPM_PACKAGE_RELEASE_DIST on) +set(CPACK_RPM_DEBUGINFO_PACKAGE on) +set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostInstall.in) +set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PostUninstall.in) +set(CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE ${CMAKE_SOURCE_DIR}/cmake/PreUninstall.in) + +# Must uninstall the debug package before install release package +if(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CPACK_RPM_PACKAGE_CONFLICTS "stellar") +else() + set(CPACK_RPM_PACKAGE_CONFLICTS "stellar-debug") +endif() + +# Setup %config(noreplace) +set(CPACK_RPM_USER_FILELIST "%config(noreplace) ${CMAKE_INSTALL_PREFIX}/conf/stellar/stellar.conf") +include(CPack) diff --git a/cmake/Version.cmake b/cmake/Version.cmake index f16eb71..4bd226e 100644 --- a/cmake/Version.cmake +++ b/cmake/Version.cmake @@ -1,58 +1,47 @@ - # Using autorevision.sh to generate version information - -set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/cmake/autorevision.sh) +set(__SOURCE_AUTORESIVISION ${CMAKE_SOURCE_DIR}/autorevision.sh) set(__AUTORESIVISION ${CMAKE_BINARY_DIR}/autorevision.sh) -set(__VERSION_CACHE ${CMAKE_BINARY_DIR}/version.txt) +set(__VERSION_CACHE ${CMAKE_SOURCE_DIR}/version.txt) set(__VERSION_CONFIG ${CMAKE_BINARY_DIR}/version.cmake) file(COPY ${__SOURCE_AUTORESIVISION} DESTINATION ${CMAKE_BINARY_DIR} FILE_PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_READ GROUP_EXECUTE WORLD_READ WORLD_EXECUTE) -# execute autorevision.sh to generate version information -execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE} - OUTPUT_FILE ${__VERSION_CONFIG} ERROR_QUIET) +# Execute autorevision.sh to generate version information +execute_process(COMMAND ${__AUTORESIVISION} -t cmake -o ${__VERSION_CACHE} OUTPUT_FILE ${__VERSION_CONFIG}) include(${__VERSION_CONFIG}) -# extract major, minor, patch version from git tag -string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" VERSION_MAJOR "${VCS_TAG}") -string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" VERSION_MINOR "${VCS_TAG}") -string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" VERSION_PATCH "${VCS_TAG}") +# Extract major, minor, patch version from git tag +string(REGEX REPLACE "^v([0-9]+)\\..*" "\\1" STELLAR_VERSION_MAJOR "${VCS_TAG}") +string(REGEX REPLACE "^v[0-9]+\\.([0-9]+).*" "\\1" STELLAR_VERSION_MINOR "${VCS_TAG}") +string(REGEX REPLACE "^v[0-9]+\\.[0-9]+\\.([0-9]+).*" "\\1" STELLAR_VERSION_PATCH "${VCS_TAG}") +string(REGEX REPLACE "[T\\:\\+\\-]" "" STELLAR_VERSION_DATE "${VCS_DATE}") -string(REGEX REPLACE "[T\\:\\+\\-]" "" VERSION_DATE "${VCS_DATE}") - -if(VERSION_DAILY_BUILD) - set(VERSION_PATCH ${VERSION_PATCH}.${VERSION_DATE}) +if(STELLAR_VERSION_DAILY_BUILD) + set(STELLAR_VERSION_PATCH ${STELLAR_VERSION_PATCH}.${STELLAR_VERSION_DATE}) endif() - -if(NOT VERSION_MAJOR) - set(VERSION_MAJOR 1) +if(NOT STELLAR_VERSION_MAJOR) + set(STELLAR_VERSION_MAJOR 3) endif() -if(NOT VERSION_MINOR) - set(VERSION_MINOR 0) +if(NOT STELLAR_VERSION_MINOR) + set(STELLAR_VERSION_MINOR 0) endif() -if(NOT VERSION_PATCH) - set(VERSION_PATCH 0) +if(NOT STELLAR_VERSION_PATCH) + set(STELLAR_VERSION_PATCH 0) endif() -set(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") -set(VERSION_BUILD "${VCS_SHORT_HASH}") +set(STELLAR_DESCRIBE "${VCS_SHORT_HASH}") +set(STELLAR_VERSION "${STELLAR_VERSION_MAJOR}.${STELLAR_VERSION_MINOR}.${STELLAR_VERSION_PATCH}") +set(STELLAR_GIT_VERSION "${STELLAR_VERSION_MAJOR}.${STELLAR_VERSION_MINOR}.${STELLAR_VERSION_PATCH}-${STELLAR_DESCRIBE}") -# print information -message(STATUS "Version: ${VERSION}-${VERSION_BUILD}") +# Replace .- with _ +string(REGEX REPLACE "[\\.\\-]" "_" STELLAR_VAR_VERSION "${STELLAR_GIT_VERSION}") -option(DEFINE_GIT_VERSION "Set DEFINE_GIT_VERSION to TRUE or FALSE" TRUE) - -if(DEFINE_GIT_VERSION) - -set(GIT_VERSION "${VERSION}-${CMAKE_BUILD_TYPE}-${VERSION_BUILD}-${VCS_BRANCH}-${VCS_DATE}") -message(STATUS "GIT_VERSION: ${GIT_VERSION}") -string(REGEX REPLACE "[-:+/\\.]" "_" GIT_VERSION ${GIT_VERSION}) - -add_definitions(-DGIT_VERSION=\"${GIT_VERSION}\") - -endif() +# Print information +message(STATUS "Welcome to stateful network function development platform, Version: ${STELLAR_GIT_VERSION}") +add_definitions(-DSTELLAR_GIT_VERSION=\"${STELLAR_GIT_VERSION}\") +add_definitions(-DSTELLAR_VAR_VERSION=${STELLAR_VAR_VERSION}) \ No newline at end of file diff --git a/conf/CMakeLists.txt b/conf/CMakeLists.txt new file mode 100644 index 0000000..d118a46 --- /dev/null +++ b/conf/CMakeLists.txt @@ -0,0 +1 @@ +install(DIRECTORY stellar DESTINATION conf COMPONENT Profile) \ No newline at end of file diff --git a/conf/stellar/stellar.conf b/conf/stellar/stellar.conf new file mode 100644 index 0000000..e69de29 diff --git a/sdk/example/custom_event_plugin.cpp b/sdk/example/custom_event_plugin.cpp index a1d4d03..dc56c0d 100644 --- a/sdk/example/custom_event_plugin.cpp +++ b/sdk/example/custom_event_plugin.cpp @@ -84,7 +84,7 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess if (*per_tcp_session_pme == NULL) { struct tcp_session_pme *cur_ctx = tcp_session_pme_create(); - snprintf(cur_ctx->data, 6, "tcp******"); + memcpy(cur_ctx->data, "custom_event_plugin_tcp_entry", strlen("custom_event_plugin_tcp_entry")); *per_tcp_session_pme = *&cur_ctx; } } @@ -115,7 +115,7 @@ extern "C" void custom_event_plugin_custom_entry(const struct stellar_session *s if (*per_custom_session_pme == NULL) { struct custom_session_pme *cur_ctx = custom_session_pme_create(); - snprintf(cur_ctx->data, 6, "custom******"); + memcpy(cur_ctx->data, "custom_event_plugin_custom_entry", strlen("custom_event_plugin_custom_entry")); *per_custom_session_pme = *&cur_ctx; } } diff --git a/sdk/example/http_event_plugin.cpp b/sdk/example/http_event_plugin.cpp index 0cf5364..4f795d3 100644 --- a/sdk/example/http_event_plugin.cpp +++ b/sdk/example/http_event_plugin.cpp @@ -50,7 +50,7 @@ extern "C" void http_event_plugin_entry(const struct stellar_session *session, e if (*per_http_session_pme == NULL) { struct http_session_pme *cur_ctx = http_session_pme_create(); - snprintf(cur_ctx->data, 6, "http******"); + memcpy(cur_ctx->data, "http_event_plugin_entry", strlen("http_event_plugin_entry")); *per_http_session_pme = *&cur_ctx; } } diff --git a/src/packet_io/test/CMakeLists.txt b/src/packet_io/test/CMakeLists.txt index 94aca33..3c1503e 100644 --- a/src/packet_io/test/CMakeLists.txt +++ b/src/packet_io/test/CMakeLists.txt @@ -4,7 +4,7 @@ add_executable(gtest_packet_io target_link_libraries( gtest_packet_io - gtest_main + gtest packet_io ) diff --git a/src/plugin_manager/plugin_manager.cpp b/src/plugin_manager/plugin_manager.cpp index 6baaad6..95f63b4 100644 --- a/src/plugin_manager/plugin_manager.cpp +++ b/src/plugin_manager/plugin_manager.cpp @@ -217,7 +217,7 @@ static int plugin_manager_init_plugins(struct plugin_manager *plug_mgr) return -1; } double percentage = ((double)(i + 1)) / ((double)plug_mgr->used_module_num) * ((double)100); - plugin_manager_log(INFO, "Plugin initialization progress: [%.2f%]", percentage); + plugin_manager_log(INFO, "Plugin initialization progress: [%.2f%%]", percentage); } return 0; @@ -419,7 +419,7 @@ void plugin_manager_dispatch(struct plugin_manager *plug_mgr, struct stellar_eve plug_ctx = plugin_manager_create_plugin_ctx(plug_mgr, session_name); if (plug_ctx == NULL) { - plugin_manager_log(ERROR, "can't create runtime plugin ctx for session '%s', Please check whether the callback is registered in the current session"); + plugin_manager_log(ERROR, "can't create runtime plugin ctx for session '%s', Please check whether the callback is registered in the current session", session_name); return; } stellar_event_set_plugin_ctx(event, plug_ctx); diff --git a/src/plugin_manager/plugin_manager_module.cpp b/src/plugin_manager/plugin_manager_module.cpp index def9343..2ff7179 100644 --- a/src/plugin_manager/plugin_manager_module.cpp +++ b/src/plugin_manager/plugin_manager_module.cpp @@ -139,7 +139,7 @@ int plugin_manager_module_init(struct plugin_manager_module *module) return -1; } - long elapsed = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000; + long long elapsed = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000; plugin_manager_log(INFO, "plugin dynamic library '%s' init success, using '%lld' us", module->lib_path, elapsed); return 0; @@ -157,7 +157,7 @@ void plugin_manager_module_exit(struct plugin_manager_module *module) clock_gettime(CLOCK_MONOTONIC, &end); module->exit_cb_ptr = NULL; - long elapsed = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000; + long long elapsed = (end.tv_sec - start.tv_sec) * 1000000 + (end.tv_nsec - start.tv_nsec) / 1000; plugin_manager_log(INFO, "plugin dynamic library '%s' exit success, using '%lld' us", module->lib_path, elapsed); } } diff --git a/src/plugin_manager/test/CMakeLists.txt b/src/plugin_manager/test/CMakeLists.txt index 82bc6d6..e3ce81a 100644 --- a/src/plugin_manager/test/CMakeLists.txt +++ b/src/plugin_manager/test/CMakeLists.txt @@ -4,7 +4,7 @@ add_executable(gtest_plugin_manager target_link_libraries( gtest_plugin_manager - gtest_main + gtest plugin_manager session_manager toml diff --git a/src/plugin_manager/test/gtest_plugin_manager.cpp b/src/plugin_manager/test/gtest_plugin_manager.cpp index efc95b2..dbe267f 100644 --- a/src/plugin_manager/test/gtest_plugin_manager.cpp +++ b/src/plugin_manager/test/gtest_plugin_manager.cpp @@ -184,7 +184,7 @@ TEST(PLUGIN_MANAGER_TEST, plugin_mangager_config_CUSTOM) EXPECT_STREQ(config->session_section[2].session_name, "CUSTOM"); EXPECT_STREQ(config->session_section[2].cb_func_name, "custom_event_plugin_custom_entry"); - EXPECT_TRUE(config->session_section[2].event == (0x01 << 1) | (0x01 << 3) | (0x01 << 5)); + EXPECT_TRUE(config->session_section[2].event == (enum session_event_type)((0x01 << 1) | (0x01 << 3) | (0x01 << 5))); plugin_mangager_config_dump(config); plugin_mangager_config_destory(config); @@ -377,28 +377,28 @@ TEST(PLUGIN_MANAGER_TEST, plugin_manager_dispatch_TCP) plugin_manager_dispatch(plug_mgr, &event); pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session); EXPECT_TRUE(pme->flags == SESSION_EVENT_OPENING); - EXPECT_STREQ(pme->data, "tcp***"); + EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry"); // run evencb event_data.type = SESSION_EVENT_RAWPKT; plugin_manager_dispatch(plug_mgr, &event); pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session); EXPECT_TRUE(pme->flags == SESSION_EVENT_RAWPKT); - EXPECT_STREQ(pme->data, "tcp***"); + EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry"); // run evencb event_data.type = SESSION_EVENT_ORDPKT; plugin_manager_dispatch(plug_mgr, &event); pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session); EXPECT_TRUE(pme->flags == SESSION_EVENT_ORDPKT); - EXPECT_STREQ(pme->data, "tcp***"); + EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry"); // run evencb event_data.type = SESSION_EVENT_META; plugin_manager_dispatch(plug_mgr, &event); pme = (struct tcp_session_pme *)pm_session_get_plugin_pme(&session); EXPECT_TRUE(pme->flags == SESSION_EVENT_META); - EXPECT_STREQ(pme->data, "tcp***"); + EXPECT_STREQ(pme->data, "custom_event_plugin_tcp_entry"); // run evencb event_data.type = SESSION_EVENT_CLOSING; diff --git a/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp b/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp index fbeed57..dc34f1e 100644 --- a/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp +++ b/src/plugin_manager/test/test_plugins/plugins_library/custom_event_plugin.cpp @@ -112,7 +112,7 @@ extern "C" void custom_event_plugin_tcp_entry(const struct stellar_session *sess if (*per_tcp_session_pme == NULL) { struct tcp_session_pme *cur_ctx = tcp_session_pme_create(); - memcpy(cur_ctx->data, "tcp***", 6); + memcpy(cur_ctx->data, "custom_event_plugin_tcp_entry", strlen("custom_event_plugin_tcp_entry")); cur_ctx->flags = SESSION_EVENT_OPENING; *per_tcp_session_pme = *&cur_ctx; } diff --git a/src/protocol_decoder/http/http.cpp b/src/protocol_decoder/http/http.cpp index b24fffd..c7e3e79 100644 --- a/src/protocol_decoder/http/http.cpp +++ b/src/protocol_decoder/http/http.cpp @@ -1,8 +1,10 @@ +#include + #include "sdk/include/session.h" void http_decoder(const struct stellar_session *s, enum session_event_type event, struct stellar_packet *p, const char *payload, uint16_t len, void **pme) { - struct stellar_session_event_extras *info; + struct stellar_session_event_extras *info = NULL; struct stellar_session *new_session = session_manager_session_derive(s, "HTTP"); session_manager_trigger_event(new_session, SESSION_EVENT_OPENING, info); diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7cdc600..56d7b60 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -7,7 +7,7 @@ add_executable(gtest_stellar target_link_libraries( gtest_stellar - gtest_main + gtest ) include(GoogleTest) diff --git a/vendor/CMakeLists.txt b/vendor/CMakeLists.txt index 5653577..6799ed0 100644 --- a/vendor/CMakeLists.txt +++ b/vendor/CMakeLists.txt @@ -1,10 +1,21 @@ -include(FetchContent) -FetchContent_Declare( - googletest - #URL https://github.com/google/googletest/archive/609281088cfefc76f9d0ce82e1ff6c30cc3591e5.zip - URL ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.8.0.tar.gz - URL_MD5 16877098823401d1bf2ed7891d7dce36 -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) -FetchContent_MakeAvailable(googletest) \ No newline at end of file +include(ExternalProject) + +# GoogleTest +ExternalProject_Add(googletest PREFIX googletest + URL ${CMAKE_CURRENT_SOURCE_DIR}/googletest-release-1.8.0.tar.gz + URL_MD5 16877098823401d1bf2ed7891d7dce36 + CMAKE_ARGS -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE}) + +ExternalProject_Get_Property(googletest INSTALL_DIR) +file(MAKE_DIRECTORY ${INSTALL_DIR}/include) + +add_library(gtest STATIC IMPORTED GLOBAL) +add_dependencies(gtest googletest) +set_property(TARGET gtest PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libgtest.a) +set_property(TARGET gtest PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include) +set_property(TARGET gtest PROPERTY INTERFACE_LINK_LIBRARIES pthread) + +add_library(gmock STATIC IMPORTED GLOBAL) +add_dependencies(gmock googletest) +set_property(TARGET gmock PROPERTY IMPORTED_LOCATION ${INSTALL_DIR}/lib/libgmock.a) +set_property(TARGET gmock PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${INSTALL_DIR}/include) \ No newline at end of file