Merge pull request #19684 from taoCH/wip-librgw-symbolic-link
[ceph.git] / run-make-check.sh
1 #!/usr/bin/env bash
2 #
3 # Ceph distributed storage system
4 #
5 # Copyright (C) 2014 Red Hat <contact@redhat.com>
6 #
7 # Author: Loic Dachary <loic@dachary.org>
8 #
9 #  This library is free software; you can redistribute it and/or
10 #  modify it under the terms of the GNU Lesser General Public
11 #  License as published by the Free Software Foundation; either
12 #  version 2.1 of the License, or (at your option) any later version.
13 #
14
15 #
16 # To just look at what this script will do, run it like this:
17 #
18 # $ DRY_RUN=echo ./run-make-check.sh
19 #
20
21 set -e
22
23 trap clean_up_after_myself EXIT
24
25 ORIGINAL_CCACHE_CONF="$HOME/.ccache/ccache.conf"
26 SAVED_CCACHE_CONF="$HOME/.run-make-check-saved-ccache-conf"
27
28 function save_ccache_conf() {
29     test -f $ORIGINAL_CCACHE_CONF && cp $ORIGINAL_CCACHE_CONF $SAVED_CCACHE_CONF || true
30 }
31
32 function restore_ccache_conf() {
33     test -f $SAVED_CCACHE_CONF && mv $SAVED_CCACHE_CONF $ORIGINAL_CCACHE_CONF || true
34 }
35
36 function clean_up_after_myself() {
37     rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv*
38     restore_ccache_conf
39 }
40
41 function get_processors() {
42     if test -n "$NPROC" ; then
43         echo $NPROC
44     else
45         if test $(nproc) -ge 2 ; then
46             expr $(nproc) / 2
47         else
48             echo 1
49         fi
50     fi
51 }
52
53 function detect_ceph_dev_pkgs() {
54     local cmake_opts
55     local boost_root=/opt/ceph
56     if test -f $boost_root/include/boost/config.hpp; then
57         cmake_opts+=" -DWITH_SYSTEM_BOOST=ON -DBOOST_ROOT=$boost_root"
58     else
59         cmake_opts+=" -DBOOST_J=$(get_processors)"
60     fi
61     echo "$cmake_opts"
62 }
63
64 function run() {
65     local install_cmd
66     local which_pkg="which"
67     source /etc/os-release
68     if test -f /etc/redhat-release ; then
69         if ! type bc > /dev/null 2>&1 ; then
70             echo "Please install bc and re-run." 
71             exit 1
72         fi
73         if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then
74             install_cmd="dnf -y install"
75         else
76             install_cmd="yum install -y"
77         fi
78     elif type zypper > /dev/null 2>&1 ; then
79         install_cmd="zypper --gpg-auto-import-keys --non-interactive install --no-recommends"
80     elif type apt-get > /dev/null 2>&1 ; then
81         install_cmd="apt-get install -y"
82         which_pkg="debianutils"
83     fi
84
85     if ! type sudo > /dev/null 2>&1 ; then
86         echo "Please install sudo and re-run. This script assumes it is running"
87         echo "as a normal user with the ability to run commands as root via sudo." 
88         exit 1
89     fi
90     if [ -n "$install_cmd" ]; then
91         $DRY_RUN sudo $install_cmd ccache $which_pkg
92     else
93         echo "WARNING: Don't know how to install packages" >&2
94         echo "This probably means distribution $ID is not supported by run-make-check.sh" >&2
95     fi
96
97     if ! type ccache > /dev/null 2>&1 ; then
98         echo "ERROR: ccache could not be installed"
99         exit 1
100     fi
101
102     if test -f ./install-deps.sh ; then
103             export WITH_SEASTAR=1
104             $DRY_RUN source ./install-deps.sh || return 1
105         trap clean_up_after_myself EXIT
106     fi
107
108     # Init defaults after deps are installed. get_processors() depends on coreutils nproc.
109     DEFAULT_MAKEOPTS=${DEFAULT_MAKEOPTS:--j$(get_processors)}
110     BUILD_MAKEOPTS=${BUILD_MAKEOPTS:-$DEFAULT_MAKEOPTS}
111     test "$BUILD_MAKEOPTS" && echo "make will run with option(s) $BUILD_MAKEOPTS"
112     CHECK_MAKEOPTS=${CHECK_MAKEOPTS:-$DEFAULT_MAKEOPTS}
113     CMAKE_BUILD_OPTS="-DWITH_GTEST_PARALLEL=ON -DWITH_FIO=ON -DWITH_SEASTAR=ON"
114     if ! type python2 > /dev/null 2>&1 ; then
115         CMAKE_BUILD_OPTS+=" -DWITH_PYTHON2=OFF -DWITH_PYTHON3=ON -DMGR_PYTHON_VERSION=3"
116     fi
117     CMAKE_BUILD_OPTS+=$(detect_ceph_dev_pkgs)
118     cat <<EOM
119 Note that the binaries produced by this script do not contain correct time
120 and git version information, which may make them unsuitable for debugging
121 and production use.
122 EOM
123     save_ccache_conf
124     # remove the entropy generated by the date/time embedded in the build
125     CMAKE_BUILD_OPTS+=" -DENABLE_GIT_VERSION=OFF"
126     $DRY_RUN export SOURCE_DATE_EPOCH="946684800"
127     $DRY_RUN ccache -o sloppiness=time_macros
128     $DRY_RUN ccache -o run_second_cpp=true
129     if [ -n "$JENKINS_HOME" ]; then
130         # Build host has plenty of space available, let's use it to keep
131         # various versions of the built objects. This could increase the cache hit
132         # if the same or similar PRs are running several times
133         $DRY_RUN ccache -o max_size=100G
134     else
135         echo "Current ccache max_size setting:"
136         ccache -p | grep max_size
137     fi
138     $DRY_RUN ccache -sz # Reset the ccache statistics and show the current configuration
139
140     $DRY_RUN ./do_cmake.sh $CMAKE_BUILD_OPTS $@ || return 1
141     $DRY_RUN cd build
142     $DRY_RUN make $BUILD_MAKEOPTS tests || return 1
143
144     $DRY_RUN ccache -s # print the ccache statistics to evaluate the efficiency
145
146     # to prevent OSD EMFILE death on tests, make sure ulimit >= 1024
147     $DRY_RUN ulimit -n $(ulimit -Hn)
148     if [ $(ulimit -n) -lt 1024 ];then
149         echo "***ulimit -n too small, better bigger than 1024 for test***"
150         return 1
151     fi
152
153     # increase the aio-max-nr, which is by default 65536. we could reach this
154     # limit while running seastar tests and bluestore tests.
155     $DRY_RUN sudo sysctl -q -w fs.aio-max-nr=$((65536 * 16))
156
157     if ! $DRY_RUN ctest $CHECK_MAKEOPTS --output-on-failure; then
158         rm -fr ${TMPDIR:-/tmp}/ceph-asok.*
159         return 1
160     fi
161 }
162
163 function main() {
164     if [[ $EUID -eq 0 ]] ; then
165         echo "For best results, run this script as a normal user configured"
166         echo "with the ability to run commands as root via sudo."
167     fi
168     echo -n "Checking hostname sanity... "
169     if $DRY_RUN hostname --fqdn >/dev/null 2>&1 ; then
170         echo "OK"
171     else
172         echo "NOT OK"
173         echo "Please fix 'hostname --fqdn', otherwise 'make check' will fail"
174         return 1
175     fi
176     run "$@" && echo "make check: successful run on $(git rev-parse HEAD)"
177 }
178
179 main "$@"