diff --git a/.github/actions/init-ut-make-config/action.yml b/.github/actions/init-ut-make-config/action.yml index 9df8103652..d81e6b538c 100644 --- a/.github/actions/init-ut-make-config/action.yml +++ b/.github/actions/init-ut-make-config/action.yml @@ -20,15 +20,20 @@ runs: shell: bash - run: | sudo git clone https://github.com/gperftools/gperftools.git - cd gperftools && sudo git checkout tags/gperftools-2.16 && sudo mkdir -p /gperftools - sudo ./autogen.sh && sudo CC=clang-12 CXX=clang++-12 ./configure --prefix=/gperftools --enable-frame-pointers + cd gperftools && sudo git checkout tags/gperftools-2.16 + sudo ./autogen.sh && sudo CC=clang-12 CXX=clang++-12 ./configure --prefix=/usr --enable-frame-pointers sudo make -j ${{env.proc_num}} && sudo make install shell: bash - run: | sudo git clone https://github.com/abseil/abseil-cpp.git cd abseil-cpp && sudo git checkout lts_2022_06_23 && sudo mkdir -p /abseil-cpp - sudo CC=clang-12 CXX=clang++-12 cmake -DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=/abseil-cpp -DCMAKE_POLICY_VERSION_MINIMUM=3.5 . + sudo CC=clang-12 CXX=clang++-12 cmake -DBUILD_TESTING=OFF -DCMAKE_POSITION_INDEPENDENT_CODE=ON -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_POLICY_VERSION_MINIMUM=3.5 . sudo make -j ${{env.proc_num}} && sudo sudo make install shell: bash - - run: sh config_brpc.sh --headers="/libunwind/include /gperftools/include /abseil-cpp/include /usr/include" --libs="/libunwind/lib /gperftools/lib /abseil-cpp/lib /usr/lib /usr/lib64" --cc=clang-12 --cxx=clang++-12 ${{inputs.options}} && cat config.mk + - run: | + wget https://archive.apache.org/dist/thrift/0.11.0/thrift-0.11.0.tar.gz && tar -xf thrift-0.11.0.tar.gz && cd thrift-0.11.0/ + ./configure --prefix=/usr --with-rs=no --with-ruby=no --with-python=no --with-java=no --with-go=no --with-perl=no --with-php=no --with-csharp=no --with-erlang=no --with-lua=no --with-nodejs=no --with-haskell=no --with-dotnetcore=no CXXFLAGS="-Wno-unused-variable" + make -j ${{env.proc_num}} && sudo make install + shell: bash + - run: sh config_brpc.sh --headers="/libunwind/include /usr/include" --libs="/libunwind/lib /usr/lib /usr/lib64" --cc=clang-12 --cxx=clang++-12 ${{inputs.options}} && cat config.mk shell: bash diff --git a/.github/workflows/ci-linux.yml b/.github/workflows/ci-linux.yml index f2d6d69287..ecc0d22426 100644 --- a/.github/workflows/ci-linux.yml +++ b/.github/workflows/ci-linux.yml @@ -15,181 +15,6 @@ env: # https://github.com/actions/runner-images jobs: - compile-with-make: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-all-dependencies - - - name: gcc with default options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=gcc --cxx=g++ --werror - - - name: gcc with all options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=gcc --cxx=g++ --werror --with-thrift --with-glog --with-rdma --with-debug-bthread-sche-safety --with-debug-lock --with-bthread-tracer --with-asan - - - name: clang with default options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=clang --cxx=clang++ --werror - - - name: clang with all options - uses: ./.github/actions/compile-with-make - with: - options: --headers=/usr/include --libs=/usr/lib /usr/lib64 --cc=clang --cxx=clang++ --werror --with-thrift --with-glog --with-rdma --with-debug-bthread-sche-safety --with-debug-lock --with-bthread-tracer --with-asan - - compile-with-cmake: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-all-dependencies - - - name: gcc with default options - run: | - export CC=gcc && export CXX=g++ - mkdir gcc_build && cd gcc_build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - - name: gcc with all options - run: | - export CC=gcc && export CXX=g++ - mkdir gcc_build_all && cd gcc_build_all - cmake -DWITH_MESALINK=OFF -DWITH_GLOG=ON -DWITH_THRIFT=ON -DWITH_RDMA=ON -DWITH_DEBUG_BTHREAD_SCHE_SAFETY=ON -DWITH_DEBUG_LOCK=ON -DWITH_BTHREAD_TRACER=ON -DWITH_ASAN=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - - name: clang with default options - run: | - export CC=clang && export CXX=clang++ - mkdir clang_build && cd clang_build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - - name: clang with all options - run: | - export CC=clang && export CXX=clang++ - mkdir clang_build_all && cd clang_build_all - cmake -DWITH_MESALINK=OFF -DWITH_GLOG=ON -DWITH_THRIFT=ON -DWITH_RDMA=ON -DWITH_DEBUG_BTHREAD_SCHE_SAFETY=ON -DWITH_DEBUG_LOCK=ON -DWITH_BTHREAD_TRACER=ON -DWITH_ASAN=ON -DCMAKE_POLICY_VERSION_MINIMUM=3.5 .. - make -j ${{env.proc_num}} && make clean - - gcc-compile-with-make-protobuf: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-essential-dependencies - - - name: protobuf 3.5.1 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.5.1 - protobuf-cpp-version: 3.5.1 - protobuf-install-dir: /protobuf-3.5.1 - config-brpc-options: --cc=gcc --cxx=g++ --werror - - - name: protobuf 3.12.4 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.12.4 - protobuf-cpp-version: 3.12.4 - protobuf-install-dir: /protobuf-3.12.4 - config-brpc-options: --cc=gcc --cxx=g++ --werror - - - name: protobuf 21.12 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 21.12 - protobuf-cpp-version: 3.21.12 - protobuf-install-dir: /protobuf-3.21.12 - config-brpc-options: --cc=gcc --cxx=g++ --werror - - gcc-compile-with-bazel: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures -- //... -//example/... - - gcc-compile-with-boringssl: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... - - gcc-compile-with-bazel-all-options: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: | - bazel build --verbose_failures \ - --define with_mesalink=false \ - --define with_glog=true \ - --define with_thrift=true \ - --define with_debug_bthread_sche_safety=true \ - --define with_debug_lock=true \ - --define with_asan=true \ - --define with_bthread_tracer=true \ - --define BRPC_WITH_NO_PTHREAD_MUTEX_HOOK=true \ - -- //... -//example/... - - clang-compile-with-make-protobuf: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-essential-dependencies - - - name: protobuf 3.5.1 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.5.1 - protobuf-cpp-version: 3.5.1 - protobuf-install-dir: /protobuf-3.5.1 - config-brpc-options: --cc=clang --cxx=clang++ --werror - - - name: protobuf 3.12.4 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 3.12.4 - protobuf-cpp-version: 3.12.4 - protobuf-install-dir: /protobuf-3.12.4 - config-brpc-options: --cc=clang --cxx=clang++ --werror - - - name: protobuf 21.12 - uses: ./.github/actions/compile-with-make-protobuf - with: - protobuf-version: 21.12 - protobuf-cpp-version: 3.21.12 - protobuf-install-dir: /protobuf-3.21.12 - config-brpc-options: --cc=clang --cxx=clang++ --werror - - clang-compile-with-bazel: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures --action_env=CC=clang -- //... -//example/... - - clang-compile-with-boringssl: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures --action_env=CC=clang --define with_mesalink=false --define with_glog=true --define with_thrift=true --define BRPC_WITH_BORINGSSL=true -- //... -//example/... - - clang-compile-with-bazel-all-options: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: | - bazel build --verbose_failures \ - --action_env=CC=clang \ - --define with_mesalink=false \ - --define with_glog=true \ - --define with_thrift=true \ - --define with_debug_bthread_sche_safety=true \ - --define with_debug_lock=true \ - --define with_asan=true \ - --define with_bthread_tracer=true \ - --define BRPC_WITH_NO_PTHREAD_MUTEX_HOOK=true \ - -- //... -//example/... - clang-unittest: runs-on: ubuntu-22.04 steps: @@ -197,7 +22,24 @@ jobs: - uses: ./.github/actions/install-essential-dependencies - uses: ./.github/actions/init-ut-make-config with: - options: --with-bthread-tracer + options: --with-bthread-tracer --with-thrift + - name: Setup Soft-RoCE + run: | + KERNEL_VERSION=$(uname -r | cut -d '-' -f 1) + KERNEL_NAME="linux-${KERNEL_VERSION%'.0'}" + DOWNLOAD_LINK="https://cdn.kernel.org/pub/linux/kernel/v${KERNEL_VERSION%%.*}.x/${KERNEL_NAME}.tar.xz" + ETHERNET_CARD=$(ip link | awk -F ": " '$0 !~ "lo|vir|wl|^[^0-9]"{print $2;getline}' | head -1) + echo "kernel version is ${KERNEL_VERSION}, download link is ${DOWNLOAD_LINK}, ethernet card is ${ETHERNET_CARD}" + wget -q $DOWNLOAD_LINK -O /tmp/$KERNEL_NAME.tar.xz + tar xf /tmp/$KERNEL_NAME.tar.xz --directory=/tmp + RXE_PATH="/tmp/$KERNEL_NAME/drivers/infiniband/sw/rxe" + sed 's/$(CONFIG_RDMA_RXE)/m/g' $RXE_PATH/Makefile > $RXE_PATH/Kbuild + make -C /lib/modules/$(uname -r)/build M=$RXE_PATH modules -j + sudo modprobe ib_core + sudo modprobe rdma_ucm + sudo insmod $RXE_PATH/rdma_rxe.ko + sudo rdma link add rxe_0 type rxe netdev $ETHERNET_CARD + rdma link - name: compile tests run: | cat config.mk @@ -207,30 +49,3 @@ jobs: run: | cd test sh ./run_tests.sh - - clang-unittest-asan: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - uses: ./.github/actions/install-essential-dependencies - - uses: ./.github/actions/init-ut-make-config - with: - options: --with-bthread-tracer --with-asan - - name: compile tests - run: | - cat config.mk - cd test - make NEED_GPERFTOOLS=0 -j ${{env.proc_num}} - - name: run tests - run: | - cd test - sh ./run_tests.sh - - bazel-bvar-unittest: - runs-on: ubuntu-22.04 - steps: - - uses: actions/checkout@v2 - - run: bazel test --verbose_failures //test:bvar_test - - run: bazel test --verbose_failures --define with_babylon_counter=true //test:bvar_test - - run: bazel test --verbose_failures --action_env=CC=clang //test:bvar_test - - run: bazel test --verbose_failures --action_env=CC=clang --define with_babylon_counter=true //test:bvar_test diff --git a/.github/workflows/ci-macos.yml b/.github/workflows/ci-macos.yml deleted file mode 100644 index 61d45ac821..0000000000 --- a/.github/workflows/ci-macos.yml +++ /dev/null @@ -1,66 +0,0 @@ -name: Build on Macos - -on: - push: - branches: [ master ] - paths-ignore: - - '**.md' - pull_request: - branches: [ master ] - paths-ignore: - - '**.md' - -env: - proc_num: $(sysctl -n hw.logicalcpu) - -jobs: - compile-with-make-cmake-protobuf21: - runs-on: macos-latest # https://github.com/actions/runner-images - - steps: - - uses: actions/checkout@v2 - - - name: install dependences - run: | - brew install openssl gnu-getopt coreutils gflags leveldb protobuf@21 - - - name: compile with make - run: | - GETOPT_PATH=$(brew --prefix gnu-getopt)/bin - export PATH=$GETOPT_PATH:$PATH - ./config_brpc.sh --header="$(brew --prefix)/include" --libs="$(brew --prefix)/lib" - make -j ${{env.proc_num}} && make clean - - - name: compile with cmake - run: | - echo "CMAKE_PREFIX_PATH=$(brew --prefix protobuf@21)" - mkdir build && cd build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_PREFIX_PATH=$(brew --prefix protobuf@21) .. - make -j ${{env.proc_num}} && make clean - - compile-with-make-cmake-protobuf29: - runs-on: macos-latest # https://github.com/actions/runner-images - - steps: - - uses: actions/checkout@v2 - - - name: install dependences - run: | - brew install openssl gnu-getopt coreutils gflags leveldb protobuf@29 - - - name: compile with make - run: | - GETOPT_PATH=$(brew --prefix gnu-getopt)/bin - export PATH=$GETOPT_PATH:$PATH - ./config_brpc.sh --header="$(brew --prefix)/include" --libs="$(brew --prefix)/lib" - make -j ${{env.proc_num}} && make clean - - - name: compile with cmake - run: | - mkdir build && cd build && cmake -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DCMAKE_PREFIX_PATH=$(brew --prefix protobuf@29) .. - make -j ${{env.proc_num}} && make clean - - compile-with-bazel: - runs-on: macos-latest # https://github.com/actions/runner-images - steps: - - uses: actions/checkout@v2 - - run: bazel build --verbose_failures -- //:brpc -//example/... diff --git a/.gitignore b/.gitignore index 44a371abb8..c56b8805f8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,6 +15,7 @@ *.rej /output /test/output +/test/gen-cpp build/ # Ignore hidden files diff --git a/config_brpc.sh b/config_brpc.sh index 75826452b4..81efa98ac2 100755 --- a/config_brpc.sh +++ b/config_brpc.sh @@ -231,6 +231,7 @@ append_linking $GFLAGS_LIB gflags PROTOBUF_LIB=$(find_dir_of_lib_or_die protobuf) append_linking $PROTOBUF_LIB protobuf +PROTOC=$(find_bin_or_die protoc) LEVELDB_LIB=$(find_dir_of_lib_or_die leveldb) # required by leveldb @@ -260,8 +261,6 @@ else DYNAMIC_LINKINGS="$DYNAMIC_LINKINGS -lleveldb" fi -PROTOC=$(find_bin_or_die protoc) - GFLAGS_HDR=$(find_dir_of_header_or_die gflags/gflags.h) PROTOBUF_HDR=$(find_dir_of_header_or_die google/protobuf/message.h) @@ -460,6 +459,7 @@ if [ "$SYSTEM" = "Darwin" ]; then fi if [ $WITH_THRIFT != 0 ]; then + append_to_output "THRIFT=$(find_bin_or_die protoc)" THRIFT_LIB=$(find_dir_of_lib_or_die thriftnb) THRIFT_HDR=$(find_dir_of_header_or_die thrift/Thrift.h) append_to_output_libs "$THRIFT_LIB" diff --git a/src/butil/thread_key.h b/src/butil/thread_key.h index 482e1f2b86..72b177daa3 100644 --- a/src/butil/thread_key.h +++ b/src/butil/thread_key.h @@ -118,7 +118,7 @@ class ThreadLocal { void replace(T* old_ptr, T* new_ptr) { BAIDU_SCOPED_LOCK(mutex); auto it = std::find(ptrs.begin(), ptrs.end(), old_ptr); - CHECK_NE(it, ptrs.end()); + CHECK(it != ptrs.end()); *it = new_ptr; } diff --git a/test/Makefile b/test/Makefile index 30e196bbce..e15ce01d3b 100644 --- a/test/Makefile +++ b/test/Makefile @@ -185,6 +185,9 @@ TEST_BRPC_OBJS = $(addsuffix .o, $(basename $(TEST_BRPC_SOURCES))) TEST_PROTO_SOURCES = $(wildcard *.proto) TEST_PROTO_OBJS = $(TEST_PROTO_SOURCES:.proto=.pb.o) +TEST_THRIFT_SOURCES = "gen-cpp/" +TEST_THRIFT_OBJS = "$(TEST_THRIFT_SOURCES)/echo_types.o" + TEST_BINS = test_butil test_bvar $(TEST_BTHREAD_SOURCES:.cpp=) $(TEST_BRPC_SOURCES:.cpp=) .PHONY:all @@ -193,7 +196,7 @@ all: $(TEST_BINS) .PHONY:clean clean:clean_bins @echo "> Cleaning" - rm -rf $(TEST_BUTIL_OBJS) $(TEST_BVAR_OBJS) $(TEST_BTHREAD_OBJS) $(TEST_BRPC_OBJS) $(TEST_PROTO_OBJS) $(TEST_PROTO_SOURCES:.proto=.pb.h) $(TEST_PROTO_SOURCES:.proto=.pb.cc) + rm -rf $(TEST_BUTIL_OBJS) $(TEST_BVAR_OBJS) $(TEST_BTHREAD_OBJS) $(TEST_BRPC_OBJS) $(TEST_PROTO_OBJS) $(TEST_PROTO_SOURCES:.proto=.pb.h) $(TEST_PROTO_SOURCES:.proto=.pb.cc) $(TEST_THRIFT_SOURCES) $(MAKE) -C.. clean_debug .PHONY:clean_bins @@ -234,7 +237,7 @@ else ifeq ($(SYSTEM),Darwin) $(CXX) -o $@ $(LIBPATHS) $(SOPATHS) $^ $(GTEST_STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS) endif -brpc_%_unittest:$(TEST_PROTO_OBJS) brpc_%_unittest.o | libbrpc.dbg.$(SOEXT) +brpc_%_unittest:$(TEST_PROTO_OBJS) $(TEST_THRIFT_OBJS) brpc_%_unittest.o | libbrpc.dbg.$(SOEXT) @echo "> Linking $@" ifeq ($(SYSTEM),Linux) $(CXX) -o $@ $(LIBPATHS) $(SOPATHS) -Xlinker "-(" $^ -Xlinker "-)" $(STATIC_LINKINGS) $(UT_DYNAMIC_LINKINGS) @@ -246,6 +249,10 @@ endif @echo "> Generating $@" $(PROTOC) --cpp_out=. --proto_path=. --proto_path=../src --proto_path=$(PROTOBUF_HDR) $< +gen-cpp/echo_types.cpp gen-cpp/echo_types.h: echo.thrift + @echo "> Generating $@" + $(THRIFT) --gen cpp $< + baidu_time_unittest.o:baidu_time_unittest.cpp | libbrpc.dbg.$(SOEXT) @echo "> Compiling $@" $(CXX) -c $(HDRPATHS) -O2 $(CXXFLAGS) $< -o $@ @@ -262,3 +269,7 @@ brpc_h2_unsent_message_unittest.o:brpc_h2_unsent_message_unittest.cpp | libbrpc. @echo "> Compiling $@" $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ +echo_types.o:gen-cpp/echo_types.cpp | libbrpc.dbg.$(SOEXT) + @echo "> Compiling $@" + $(CXX) -c $(HDRPATHS) $(CXXFLAGS) $< -o $@ +