From 3242f091d9e0e37fc251d6b10bdfb6a6f722e6d7 Mon Sep 17 00:00:00 2001 From: Wu Tao Date: Thu, 8 Aug 2019 13:05:51 +0800 Subject: [PATCH] scripts: travis supports format (#358) --- .gitignore | 1 + .travis.yml | 4 +++- scripts/format_files.sh | 4 ++-- scripts/travis.sh | 23 +++++++++++++++++++ src/base/test/CMakeLists.txt | 2 +- src/base/test/run.sh | 12 ++++++++++ src/geo/bench/bench.cpp | 2 +- .../proxy_ut/redis_proxy_test.cpp | 6 ++--- .../test/pegasus_compression_options_test.cpp | 3 +-- src/shell/commands/data_operations.cpp | 12 ++++++---- src/test/function_test/test_recovery.cpp | 3 +-- 11 files changed, 55 insertions(+), 17 deletions(-) create mode 100755 scripts/travis.sh create mode 100755 src/base/test/run.sh diff --git a/.gitignore b/.gitignore index d1bec7b..e426ca3 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,4 @@ LOG PACKAGE scripts/py_utils/*.pyc cmake-build-debug +packages diff --git a/.travis.yml b/.travis.yml index 1b70131..60ebd95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,6 +13,7 @@ addons: packages: - libsnappy-dev - liblz4-dev + - clang-format-3.9 cache: - ccache @@ -30,6 +31,7 @@ install: - wget https://github.com/facebook/zstd/archive/v1.3.7.zip; unzip v1.3.7; cd zstd-1.3.7; - mkdir cmake-build; cd cmake-build; cmake -DCMAKE_INSTALL_PREFIX=/usr -DCMAKE_INSTALL_LIBDIR=lib -DZSTD_BUILD_PROGRAMS=OFF ../build/cmake; sudo make install -j8; - cd ../.. + - rm -rf v1.3.7.zip zstd-1.3.7; before_script: - cd rdsn/thirdparty @@ -40,7 +42,7 @@ before_script: - ulimit -c unlimited -S script: - - ./run.sh build --skip_thirdparty --disable_gperf && ./run.sh test + - ./scripts/travis.sh after_script: - ./run.sh stop_zk diff --git a/scripts/format_files.sh b/scripts/format_files.sh index 5571297..d52b03a 100755 --- a/scripts/format_files.sh +++ b/scripts/format_files.sh @@ -10,13 +10,13 @@ sds=./src/shell/sds if [ $# -eq 0 ]; then echo "formating all .h/.cpp files in $root_dir ..." find . -type f -not \( -wholename "$linenoise/*" -o -wholename "$sds/*" -o -wholename "./rocksdb/*" -o -wholename "./rdsn/*" \) \ - -regextype posix-egrep -regex ".*\.(cpp|h)" | xargs clang-format -i -style=file + -regextype posix-egrep -regex ".*\.(cpp|h)" | xargs clang-format-3.9 -i -style=file elif [ $1 = "-h" ]; then echo "USAGE: ./format-files.sh [] -- format .h/.cpp files in $root_dir/relative_path" echo " ./format-files.sh means format all .h/.cpp files in $root_dir" else echo "formating all .h/.cpp files in $root_dir/$1 ..." find ./$1 -type f -not \( -wholename "$linenoise/*" -o -wholename "$sds/*" -o -wholename "./rocksdb/*" -o -wholename "./rdsn/*" \) \ - -regextype posix-egrep -regex ".*\.(cpp|h)" | xargs clang-format -i -style=file + -regextype posix-egrep -regex ".*\.(cpp|h)" | xargs clang-format-3.9 -i -style=file fi diff --git a/scripts/travis.sh b/scripts/travis.sh new file mode 100755 index 0000000..1a0d5f3 --- /dev/null +++ b/scripts/travis.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# to project root directory +script_dir=$(cd "$(dirname "$0")" && pwd) +root=$(dirname "$script_dir") +cd "${root}" || exit 1 + +# ensure source files are well formatted +"${root}"/scripts/format_files.sh + +# ignore updates of submodules +modified=$(git status -s --ignore-submodules) +if [ "$modified" ]; then + echo "$modified" + echo "please format the above files before commit" + exit 1 +fi + +"${root}"/run.sh build -c --skip_thirdparty --disable_gperf && ./run.sh test + +if [ $? ]; then + echo "travis failed with exit code $?" +fi diff --git a/src/base/test/CMakeLists.txt b/src/base/test/CMakeLists.txt index a024768..798569f 100644 --- a/src/base/test/CMakeLists.txt +++ b/src/base/test/CMakeLists.txt @@ -16,6 +16,6 @@ set(MY_PROJ_LIBS set(MY_BOOST_LIBS Boost::system Boost::filesystem) -set(MY_BINPLACES "config.ini") +set(MY_BINPLACES config.ini run.sh) dsn_add_test() diff --git a/src/base/test/run.sh b/src/base/test/run.sh new file mode 100755 index 0000000..5016ad9 --- /dev/null +++ b/src/base/test/run.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +exit_if_fail() { + if [ $1 != 0 ]; then + echo $2 + exit 1 + fi +} + +./base_test + +exit_if_fail $? "run unit test failed" diff --git a/src/geo/bench/bench.cpp b/src/geo/bench/bench.cpp index 349b540..4125f8f 100644 --- a/src/geo/bench/bench.cpp +++ b/src/geo/bench/bench.cpp @@ -89,7 +89,7 @@ int main(int argc, char **argv) uint64_t start = env->NowNanos(); std::atomic count(test_count); dsn::utils::notify_event get_completed; - + // test search_radial by lat & lng for (int i = 0; i < test_count; ++i) { S2LatLng latlng(S2Testing::SamplePoint(rect)); diff --git a/src/redis_protocol/proxy_ut/redis_proxy_test.cpp b/src/redis_protocol/proxy_ut/redis_proxy_test.cpp index 092577c..e475430 100644 --- a/src/redis_protocol/proxy_ut/redis_proxy_test.cpp +++ b/src/redis_protocol/proxy_ut/redis_proxy_test.cpp @@ -115,8 +115,7 @@ public: got_a_message = false; entry_index = 0; rr.length = 6; - rr.buffers = { - {"GEORADIUS"}, {""}, {"123.4"}, {"56.78"}, {"100"}, {"m"}}; + rr.buffers = {{"GEORADIUS"}, {""}, {"123.4"}, {"56.78"}, {"100"}, {"m"}}; const char *request_data = "*6\r\n$9\r\nGEORADIUS\r\n$0\r\n\r\n$5\r\n123.4\r\n$5\r\n56." "78\r\n$3\r\n100\r\n$1\r\nm\r\n"; @@ -130,8 +129,7 @@ public: got_a_message = false; entry_index = 0; rr.length = 5; - rr.buffers = { - {"GEORADIUSBYMEMBER"}, {""}, {"member1"}, {"1000.5"}, {"km"}}; + rr.buffers = {{"GEORADIUSBYMEMBER"}, {""}, {"member1"}, {"1000.5"}, {"km"}}; const char *request_data = "*5\r\n$17\r\nGEORADIUSBYMEMBER\r\n$0\r\n\r\n$" "7\r\nmember1\r\n$6\r\n1000.5\r\n$2\r\nkm\r\n"; diff --git a/src/server/test/pegasus_compression_options_test.cpp b/src/server/test/pegasus_compression_options_test.cpp index ca96fd3..1964df3 100644 --- a/src/server/test/pegasus_compression_options_test.cpp +++ b/src/server/test/pegasus_compression_options_test.cpp @@ -133,8 +133,7 @@ TEST_F(pegasus_compression_options_test, compression_types_convert_fail) TEST_F(pegasus_compression_options_test, check_rocksdb_compression_types_default) { start(); - check_db_compression_types({none, none, lz4, lz4, lz4, lz4}, - "start with default"); + check_db_compression_types({none, none, lz4, lz4, lz4, lz4}, "start with default"); } } // namespace server diff --git a/src/shell/commands/data_operations.cpp b/src/shell/commands/data_operations.cpp index cbcbd78..e7711ec 100644 --- a/src/shell/commands/data_operations.cpp +++ b/src/shell/commands/data_operations.cpp @@ -2548,19 +2548,23 @@ print_current_scan_state(const std::vector> & fprintf(stderr, "\n============================[hash_key_size]============================\n" "%s=======================================================================", - statistics->getHistogramString(static_cast(histogram_type::HASH_KEY_SIZE)).c_str()); + statistics->getHistogramString(static_cast(histogram_type::HASH_KEY_SIZE)) + .c_str()); fprintf(stderr, "\n============================[sort_key_size]============================\n" "%s=======================================================================", - statistics->getHistogramString(static_cast(histogram_type::SORT_KEY_SIZE)).c_str()); + statistics->getHistogramString(static_cast(histogram_type::SORT_KEY_SIZE)) + .c_str()); fprintf(stderr, "\n==============================[value_size]=============================\n" "%s=======================================================================", - statistics->getHistogramString(static_cast(histogram_type::VALUE_SIZE)).c_str()); + statistics->getHistogramString(static_cast(histogram_type::VALUE_SIZE)) + .c_str()); fprintf(stderr, "\n===============================[row_size]==============================\n" "%s=======================================================================\n\n", - statistics->getHistogramString(static_cast(histogram_type::ROW_SIZE)).c_str()); + statistics->getHistogramString(static_cast(histogram_type::ROW_SIZE)) + .c_str()); } } diff --git a/src/test/function_test/test_recovery.cpp b/src/test/function_test/test_recovery.cpp index 482a9ef..e542d39 100644 --- a/src/test/function_test/test_recovery.cpp +++ b/src/test/function_test/test_recovery.cpp @@ -42,8 +42,7 @@ protected: system("sed -i \"/^perf_counter_enable_logging/c perf_counter_enable_logging = false\" " "config-server-test-recovery.ini"); - system( - "./run.sh start_onebox -m 1 -r 3 --config_path config-server-test-recovery.ini"); + system("./run.sh start_onebox -m 1 -r 3 --config_path config-server-test-recovery.ini"); std::cout << "sleep for a while to wait the new onebox start" << std::endl; std::this_thread::sleep_for(std::chrono::seconds(3)); -- GitLab