Skip to content

Commit

Permalink
feat: add github action GTest (#54)
Browse files Browse the repository at this point in the history
* CI add Gtest

* fix gtest out dir

* closs other test

* fix release compile error

* add build.sh read prams,add ci on ubuntu
  • Loading branch information
lqxhub authored Nov 28, 2023
1 parent 705f334 commit 352c5ca
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 10 deletions.
24 changes: 23 additions & 1 deletion .github/workflows/pikiwidb.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,26 @@ jobs:

- name: Build
run: |
sh build.sh
sh build.sh
- name: GTest
working-directory: ${{ github.workspace }}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest

build_on_ubuntu:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Build
run: |
bash build.sh
- name: GTest
working-directory: ${{ github.workspace }}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ELSEIF (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(CMAKE_THREAD_LIBS_INIT "-lpthread")
ELSEIF (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
SET(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl")
SET(CMAKE_CXX_FLAGS "-pthread -Wl,--no-as-needed -ldl -Wno-restrict")
ENDIF ()
ADD_DEFINITIONS(-DOS_LINUX)
ELSE ()
Expand Down
75 changes: 73 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,11 +1,71 @@
#!/bin/bash

#color code
C_RED="\033[31m"
C_GREEN="\033[32m"

C_END="\033[0m"

BUILD_TIME=$(git log -1 --format=%ai)
BUILD_TIME=${BUILD_TIME: 0: 10}

COMMIT_ID=$(git rev-parse HEAD)
SHORT_COMMIT_ID=${COMMIT_ID: 0: 8}

BUILD_TYPE=release
VERBOSE=0
CMAKE_FLAGS=""
MAKE_FLAGS=""
PREFIX="build"

ARGS=`getopt -a -o h -l help,debug,verbose,prefix: -- "$@"`
function show_help() {
echo "
-h --help show help
--debug compile with debug
--verbose compile with verbose
--prefix compile output path
"
exit 0
}

eval set -- "${ARGS}"
while true
do
case "$1" in
-h|--help)
show_help
;;
--debug)
BUILD_TYPE=debug
;;
--verbose)
CMAKE_FLAGS="${CMAKE_FLAGS} -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON"
MAKE_FLAGS="${MAKE_FLAGS} VERBOSE=1"
;;
--prefix)
PREFIX=$2
shift
;;
--)
shift
break
;;
esac
shift
done

if [ ! -f "/proc/cpuinfo" ];then
CPU_CORE=$(sysctl -n hw.ncpu)
else
CPU_CORE=$(cat /proc/cpuinfo| grep "processor"| wc -l)
fi
if [ ${CPU_CORE} -eq 0 ]; then
CPU_CORE=1
fi

echo "cpu core ${CPU_CORE}"

if [ -z "$SHORT_COMMIT_ID" ]; then
echo "no git commit id"
SHORT_COMMIT_ID="pikiwidb"
Expand All @@ -14,5 +74,16 @@ fi
echo "BUILD_TIME:" $BUILD_TIME
echo "COMMIT_ID:" $SHORT_COMMIT_ID

cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID -S . -B build
cmake --build build -- -j 32
echo "BUILD_TYPE:" $BUILD_TYPE
echo "CMAKE_FLAGS:" $CMAKE_FLAGS
echo "MAKE_FLAGS:" $MAKE_FLAGS

cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBUILD_TIME=$BUILD_TIME -DGIT_COMMIT_ID=$SHORT_COMMIT_ID ${CMAKE_FLAGS} -S . -B ${PREFIX}
cmake --build ${PREFIX} -- ${MAKE_FLAGS} -j ${CPU_CORE}

if [ $? -eq 0 ]; then
echo -e "pika compile complete, output file ${C_GREEN} ${BUILD_DIR}/pika ${C_END}"
else
echo -e "${C_RED} pika compile fail ${C_END}"
exit 1
fi
5 changes: 3 additions & 2 deletions cmake/double-conversion.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ FetchContent_DeclareGitHubWithMirror(double-conversion
google/double-conversion v3.3.0
SHA256=4080014235f90854ffade6d1c423940b314bbca273a338235f049da296e47183
)

FetchContent_MakeAvailableWithArgs(double-conversion)
FetchContent_MakeAvailableWithArgs(double-conversion
BUILD_TESTING=OFF
)
1 change: 1 addition & 0 deletions cmake/gflags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ FetchContent_MakeAvailableWithArgs(gflags
BUILD_SHARED_LIBS=OFF
BUILD_gflags_LIB=ON
BUILD_gflags_nothreads_LIB=OFF
BUILD_TESTING=OFF
)

find_package(Threads REQUIRED)
Expand Down
2 changes: 1 addition & 1 deletion cmake/glog.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ FetchContent_Declare(glog
FetchContent_MakeAvailableWithArgs(glog
CMAKE_MODULE_PATH=${PROJECT_SOURCE_DIR}/cmake/modules/glog
WITH_GFLAGS=ON
WITH_GTEST=OFF
BUILD_TESTING=OFF
BUILD_SHARED_LIBS=OFF
WITH_UNWIND=ON
)
5 changes: 2 additions & 3 deletions src/pstd/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ foreach (pstd_test_source ${PSTD_TEST_SOURCE})
get_filename_component(pstd_test_filename ${pstd_test_source} NAME)
string(REPLACE ".cc" "" pstd_test_name ${pstd_test_filename})

set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
add_executable(${pstd_test_name} ${pstd_test_source})
target_include_directories(${pstd_test_name}
PUBLIC ${PROJECT_SOURCE_DIR}/src
Expand All @@ -27,6 +27,5 @@ foreach (pstd_test_source ${PSTD_TEST_SOURCE})
PUBLIC pstd
PUBLIC gtest
)
gtest_discover_tests(${pstd_test_name}
WORKING_DIRECTORY .)
gtest_discover_tests(${pstd_test_name})
endforeach ()

0 comments on commit 352c5ca

Please sign in to comment.