#!/usr/bin/env bash # # Ceph distributed storage system # # Copyright (C) 2014 Red Hat # # Author: Loic Dachary # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # # To just look at what this script will do, run it like this: # # $ DRY_RUN=echo ./run-make-check.sh # set -e trap clean_up_after_myself EXIT ORIGINAL_CCACHE_CONF="$HOME/.ccache/ccache.conf" SAVED_CCACHE_CONF="$HOME/.run-make-check-saved-ccache-conf" function save_ccache_conf() { test -f $ORIGINAL_CCACHE_CONF && cp $ORIGINAL_CCACHE_CONF $SAVED_CCACHE_CONF || true } function restore_ccache_conf() { test -f $SAVED_CCACHE_CONF && mv $SAVED_CCACHE_CONF $ORIGINAL_CCACHE_CONF || true } function clean_up_after_myself() { rm -fr ${CEPH_BUILD_VIRTUALENV:-/tmp}/*virtualenv* restore_ccache_conf } function get_processors() { if test -n "$NPROC" ; then echo $NPROC else if test $(nproc) -ge 2 ; then expr $(nproc) / 2 else echo 1 fi fi } function detect_ceph_dev_pkgs() { local cmake_opts local boost_root=/opt/ceph if test -f $boost_root/include/boost/config.hpp; then cmake_opts+=" -DWITH_SYSTEM_BOOST=ON -DBOOST_ROOT=$boost_root" else cmake_opts+=" -DBOOST_J=$(get_processors)" fi echo "$cmake_opts" } function run() { local install_cmd local which_pkg="which" source /etc/os-release if test -f /etc/redhat-release ; then if ! type bc > /dev/null 2>&1 ; then echo "Please install bc and re-run." exit 1 fi if test "$(echo "$VERSION_ID >= 22" | bc)" -ne 0; then install_cmd="dnf -y install" else install_cmd="yum install -y" fi elif type zypper > /dev/null 2>&1 ; then install_cmd="zypper --gpg-auto-import-keys --non-interactive install --no-recommends" elif type apt-get > /dev/null 2>&1 ; then install_cmd="apt-get install -y" which_pkg="debianutils" fi if ! type sudo > /dev/null 2>&1 ; then echo "Please install sudo and re-run. This script assumes it is running" echo "as a normal user with the ability to run commands as root via sudo." exit 1 fi if [ -n "$install_cmd" ]; then $DRY_RUN sudo $install_cmd ccache $which_pkg else echo "WARNING: Don't know how to install packages" >&2 echo "This probably means distribution $ID is not supported by run-make-check.sh" >&2 fi if ! type ccache > /dev/null 2>&1 ; then echo "ERROR: ccache could not be installed" exit 1 fi if test -f ./install-deps.sh ; then export WITH_SEASTAR=1 $DRY_RUN source ./install-deps.sh || return 1 trap clean_up_after_myself EXIT fi # Init defaults after deps are installed. get_processors() depends on coreutils nproc. DEFAULT_MAKEOPTS=${DEFAULT_MAKEOPTS:--j$(get_processors)} BUILD_MAKEOPTS=${BUILD_MAKEOPTS:-$DEFAULT_MAKEOPTS} test "$BUILD_MAKEOPTS" && echo "make will run with option(s) $BUILD_MAKEOPTS" CHECK_MAKEOPTS=${CHECK_MAKEOPTS:-$DEFAULT_MAKEOPTS} CMAKE_BUILD_OPTS="-DWITH_GTEST_PARALLEL=ON -DWITH_FIO=ON -DWITH_SEASTAR=ON" if ! type python2 > /dev/null 2>&1 ; then CMAKE_BUILD_OPTS+=" -DWITH_PYTHON2=OFF -DWITH_PYTHON3=ON -DMGR_PYTHON_VERSION=3" fi CMAKE_BUILD_OPTS+=$(detect_ceph_dev_pkgs) cat <= 1024 $DRY_RUN ulimit -n $(ulimit -Hn) if [ $(ulimit -n) -lt 1024 ];then echo "***ulimit -n too small, better bigger than 1024 for test***" return 1 fi # increase the aio-max-nr, which is by default 65536. we could reach this # limit while running seastar tests and bluestore tests. $DRY_RUN sudo sysctl -q -w fs.aio-max-nr=$((65536 * 16)) if ! $DRY_RUN ctest $CHECK_MAKEOPTS --output-on-failure; then rm -fr ${TMPDIR:-/tmp}/ceph-asok.* return 1 fi } function main() { if [[ $EUID -eq 0 ]] ; then echo "For best results, run this script as a normal user configured" echo "with the ability to run commands as root via sudo." fi echo -n "Checking hostname sanity... " if $DRY_RUN hostname --fqdn >/dev/null 2>&1 ; then echo "OK" else echo "NOT OK" echo "Please fix 'hostname --fqdn', otherwise 'make check' will fail" return 1 fi run "$@" && echo "make check: successful run on $(git rev-parse HEAD)" } main "$@"