# $FreeBSD$ # # Copyright 2013 Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # * Neither the name of Google Inc. nor the names of its contributors # may be used to endorse or promote products derived from this software # without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # \file iterate.sh # Creates a FreeBSD release and executes its tests within a VM. shtk_import bool shtk_import cleanup shtk_import cli shtk_import config shtk_import process # List of valid configuration variables. # # Please remember to update sysbuild.conf(5) if you change this list. AUTOTEST_CONFIG_VARS="CHROOTDIR DATADIR IMAGE MKVARS PACKAGES SRCBRANCH \ SVNROOT TARGET TARGET_ARCH TESTS_TIMEOUT" # Paths to installed files. # # Can be overriden for test purposes only. : ${AUTOTEST_ETCDIR="__AUTOTEST_ETCDIR__"} : ${AUTOTEST_ROOT="__AUTOTEST_ROOT__"} # Sets defaults for configuration variables and hooks that need to exist. # # This function should be before the configuration file has been loaded. This # means that the user can undefine a required configuration variable, but we let # him shoot himself in the foot if he so desires. autotest_set_defaults() { # Please remember to update autotest(1) if you change any default values. shtk_config_set CHROOTDIR "${AUTOTEST_ROOT}/head/build" shtk_config_set DATADIR "${AUTOTEST_ROOT}/data" shtk_config_set IMAGE "${AUTOTEST_ROOT}/image.disk" shtk_config_set SRCBRANCH "base/head" shtk_config_set SVNROOT "svn://svn.FreeBSD.org/" shtk_config_set TARGET "amd64" shtk_config_set TARGET_ARCH "amd64" post_mkimage_hook() { true; } } # Dumps the loaded configuration. # # \params ... The options and arguments to the command. autotest_config() { [ ${#} -eq 0 ] || shtk_cli_usage_error "config does not take any arguments" for var in ${AUTOTEST_CONFIG_VARS}; do if shtk_config_has "${var}"; then echo "${var} = $(shtk_config_get "${var}")" else echo "${var} is undefined" fi done } # Prints the contents of the src.conf file. # # The output of this is the collection of variables and their values as defined # in MKVARS. _generate_src_conf() { for varvalue in $(shtk_config_get MKVARS); do echo "${varvalue}" done } # Builds a full release for later testing. autotest_release() { [ ${#} -eq 0 ] || shtk_cli_usage_error "release does not take any arguments" local tmpdir="$(mktemp -d -t autotest)" eval "remove_tmpdir() { rm -rf '${tmpdir}'; }" shtk_cleanup_register remove_tmpdir local src_conf="${tmpdir}/src.conf" _generate_src_conf >"${src_conf}" local release_conf="${tmpdir}/release.conf" cat >"${release_conf}" <"${chrootdir}/etc/src.conf" chroot "${chrootdir}" make -s -C /usr/src \ DESTDIR=/vmimage/mnt \ TARGET="$(shtk_config_get TARGET)" \ TARGET_ARCH="$(shtk_config_get TARGET_ARCH)" \ installworld installkernel distribution 2>&1 >/dev/null shtk_cli_info "Setting up image configuration" echo "-h" >"${chrootdir}/vmimage/mnt/boot.config" sed -i .tmp \ '/^ttyv.*$/s/on/off/;/^ttyu0.*$/s/off/on/;/^ttyu0.*$/s/dialup/xterm/' \ "${chrootdir}/vmimage/mnt/etc/ttys" sed -i .tmp '/^default:/s/:/:al=root:/' \ "${chrootdir}/vmimage/mnt/etc/gettytab" cat >"${chrootdir}/vmimage/mnt/etc/fstab" <>"${chrootdir}/vmimage/mnt/root/.cshrc" <>"${run_datadir}/output.log" 2>&1 ( autotest_release autotest_mkimage autotest_execute autotest_publish "${run_datadir}" ) rm -f "${datadir}/0-LATEST" ln -s "${subdir}" "${datadir}/0-LATEST" exec >&- 2>&- if ! shtk_bool_check "${quiet}"; then kill "${tail_pid}" eval "kill_tail() { true; }" fi } # Loads the configuration file specified in the command line. # # \param config_name Name of the desired configuration. It can be either a # configuration name (no slashes) or a path. autotest_config_load() { local config_name="${1}"; shift local config_file= case "${config_name}" in */*|*.conf) config_file="${config_name}" ;; *) config_file="${AUTOTEST_ETCDIR}/${config_name}.conf" [ ! -e "${config_file}" ] \ || shtk_cli_usage_error "Cannot locate configuration named" \ "'${config_name}'" ;; esac shtk_config_load "${config_file}" } # Entry point to the program. # # \param ... Command-line arguments to be processed. # # \return An exit code to be returned to the user. main() { local config_file="${AUTOTEST_ETCDIR}/head.conf" local expert_mode=false shtk_config_init ${AUTOTEST_CONFIG_VARS} local OPTIND while getopts ':c:o:X' arg "${@}"; do case "${arg}" in c) # Name of the configuration to load. config_file="${OPTARG}" ;; o) # Override for a particular configuration variable. shtk_config_override "${OPTARG}" ;; X) # Enable expert-mode. expert_mode=true ;; \?) shtk_cli_usage_error "Unknown option -${OPTARG}" ;; esac done shift $((${OPTIND} - 1)) [ ${#} -ge 1 ] || shtk_cli_usage_error "No command specified" local exit_code=0 local command="${1}"; shift case "${command}" in all|config) autotest_set_defaults shtk_config_load "${config_file}" "autotest_${command}" "${@}" || exit_code="${?}" ;; execute|mkimage|publish|release) shtk_bool_check "${expert_mode}" \ || shtk_cli_usage_error "Using ${command} requires expert" \ "mode; try passing -X" autotest_set_defaults shtk_config_load "${config_file}" "autotest_${command}" "${@}" || exit_code="${?}" ;; *) shtk_cli_usage_error "Unknown command ${command}" ;; esac return "${exit_code}" }