Install test scripts into chroot.
This also removes support for all scripts that don't really work without a chroot
to only run inside a chroot. This includes:
run_remote_tests
cros_run_vm_tests
parallel_run_vm_tests
Change-Id: I5c89466047047025de6c934b38ef6be8a23ea058
BUG=chromium-os:13498
TEST=Ran full x86-generic-pre-flight-queue with this CL patched in. CBuildbot / CBuild already have their test calls uses enter_chroot.sh -- before their test call.
Committed: http://chrome-svn/viewvc/chromeos?view=rev&revision=98c6a53
Review URL: http://codereview.chromium.org/6736023
diff --git a/Makefile b/Makefile
index f3e5bc2..341d12e 100644
--- a/Makefile
+++ b/Makefile
@@ -13,17 +13,12 @@
mkdir -p "${DESTDIR}/usr/share/crostestutils"
install -m 0644 lib/constants.py "${DESTDIR}/usr/lib/crostestutils"
install -m 0755 cros_run_unit_tests "${DESTDIR}/usr/bin"
- install -m 0755 cros_run_vm_test ${DESTDIR}/usr/bin
install -m 0755 run_remote_tests.sh ${DESTDIR}/usr/bin
install -m 0644 unit_test_black_list.txt \
"${DESTDIR}/usr/share/crostestutils"
- install -m 0755 utils_py/cros_run_parallel_vm_tests.py \
- "${DESTDIR}/usr/lib/crostestutils"
install -m 0755 utils_py/generate_test_report.py \
"${DESTDIR}/usr/lib/crostestutils"
# Make symlinks for those python files in lib.
- ln -s "${DESTDIR}/usr/lib/crostestutils/cros_run_parallel_vm_tests.py" \
- "${DESTDIR}/usr/bin/cros_run_parallel_vm_tests"
ln -s "${DESTDIR}/usr/lib/crostestutils/generate_test_report.py" \
"${DESTDIR}/usr/bin/generate_test_report"
diff --git a/au_test_harness/au_worker.py b/au_test_harness/au_worker.py
index 6dedef1..701a12a 100644
--- a/au_test_harness/au_worker.py
+++ b/au_test_harness/au_worker.py
@@ -41,8 +41,8 @@
self.verify_suite = 'suite_Smoke'
# Set these up as they are used often.
- self.crosutils = cros_lib.CROSUTILS_DIRECTORY
- self.crosutilsbin = os.path.join(self.crosutils, 'bin')
+ self.crosutils = cros_lib.GetCrosUtilsPath()
+ self.crosutilsbin = cros_lib.GetCrosUtilsBinPath()
def CleanUp(self):
"""Called at the end of every test."""
diff --git a/au_test_harness/cros_au_test_harness.py b/au_test_harness/cros_au_test_harness.py
index 7aed0f7..9b7be82 100755
--- a/au_test_harness/cros_au_test_harness.py
+++ b/au_test_harness/cros_au_test_harness.py
@@ -53,9 +53,7 @@
"""
def _GenerateVMUpdate(target, src, private_key_path):
"""Generates an update using the devserver."""
- command = ['./enter_chroot.sh',
- '--',
- 'sudo',
+ command = ['sudo',
'start_devserver',
'--pregenerate_update',
'--exit',
@@ -70,7 +68,9 @@
cros_lib.ReinterpretPathForChroot(private_key_path))
return cros_lib.RunCommandCaptureOutput(command, combine_stdout_stderr=True,
- print_cmd=True)
+ enter_chroot=True,
+ print_cmd=True,
+ cwd=cros_lib.GetCrosUtilsPath())
# Use dummy class to mock out updates that would be run as part of a test.
test_suite = _PrepareTestSuite(options, use_dummy_worker=True)
@@ -168,7 +168,8 @@
# Wipe devserver cache.
cros_lib.RunCommandCaptureOutput(
['sudo', 'start_devserver', '--clear_cache', '--exit', ],
- enter_chroot=True, print_cmd=False, combine_stdout_stderr=True)
+ enter_chroot=True, print_cmd=False, combine_stdout_stderr=True,
+ cwd=cros_lib.GetCrosUtilsPath())
# Clean previous vm images if they exist.
if options.type == 'vm':
diff --git a/au_test_harness/dev_server_wrapper.py b/au_test_harness/dev_server_wrapper.py
index 3ddc1b8..d7d7b05 100644
--- a/au_test_harness/dev_server_wrapper.py
+++ b/au_test_harness/dev_server_wrapper.py
@@ -36,7 +36,8 @@
'--production',
], enter_chroot=True, print_cmd=False,
log_to_file=os.path.join(self.test_root,
- 'dev_server.log'))
+ 'dev_server.log'),
+ cwd=cros_lib.GetCrosUtilsPath())
def Stop(self):
"""Kills the devserver instance."""
diff --git a/au_test_harness/public_key_manager.py b/au_test_harness/public_key_manager.py
index 355e744..0a9fafb 100644
--- a/au_test_harness/public_key_manager.py
+++ b/au_test_harness/public_key_manager.py
@@ -88,4 +88,4 @@
cros_lib.ReinterpretPathForChroot(from_dir),
image], print_cmd=False, redirect_stdout=True,
redirect_stderr=True, enter_chroot=True,
- cwd=cros_lib.CROSUTILS_DIRECTORY)
+ cwd=cros_lib.GetCrosUtilsPath())
diff --git a/au_test_harness/real_au_worker.py b/au_test_harness/real_au_worker.py
index 43b8c2e..ffd9963 100644
--- a/au_test_harness/real_au_worker.py
+++ b/au_test_harness/real_au_worker.py
@@ -53,11 +53,12 @@
"""Verifies an image using run_remote_tests.sh with verification suite."""
test_directory = self.GetNextResultsPath('verify')
output = cros_lib.RunCommand(
- ['%s/run_remote_tests.sh' % self.crosutils,
+ ['run_remote_tests.sh',
'--remote=%s' % self.remote,
'--results_dir_root=%s' % test_directory,
self.verify_suite,
- ], error_ok=True, enter_chroot=False, redirect_stdout=True)
+ ], error_ok=True, enter_chroot=True, redirect_stdout=True,
+ cwd=self.crosutils)
return self.AssertEnoughTestsPassed(unittest, output,
percent_required_to_pass)
diff --git a/au_test_harness/vm_au_worker.py b/au_test_harness/vm_au_worker.py
index 9788fdd..b5925cc 100644
--- a/au_test_harness/vm_au_worker.py
+++ b/au_test_harness/vm_au_worker.py
@@ -103,7 +103,7 @@
(_, _, log_directory_in_chroot) = log_directory.rpartition('chroot')
# image_to_live already verifies lsb-release matching. This is just
# for additional steps.
- commandWithArgs = ['%s/cros_run_vm_test' % self.crosutilsbin,
+ commandWithArgs = ['./cros_run_vm_test',
'--image_path=%s' % self.vm_image_path,
'--snapshot',
'--persist',
@@ -114,7 +114,8 @@
]
if self.graphics_flag: commandWithArgs.append(self.graphics_flag)
output = cros_lib.RunCommand(commandWithArgs, error_ok=True,
- enter_chroot=False, redirect_stdout=True)
+ enter_chroot=False, redirect_stdout=True,
+ cwd=self.crosutilsbin)
return self.AssertEnoughTestsPassed(unittest, output,
percent_required_to_pass)
diff --git a/cros_run_vm_test b/cros_run_vm_test
index 22ec17e..03c529e 100755
--- a/cros_run_vm_test
+++ b/cros_run_vm_test
@@ -6,13 +6,11 @@
#
# Runs a given test case under a VM.
-. $(dirname "$(readlink -f "$0")")/outside_chroot_common.sh 2> /dev/null ||
- SCRIPT_ROOT=/usr/lib/crosutils
-. "${SCRIPT_ROOT}/common.sh" ||
- (echo "Unable to load common.sh" && false) ||
- exit 1
+# This can only run outside the chroot.
+. $(dirname "$(readlink -f "$0")")/outside_chroot_common.sh || exit 1
+. "${SCRIPT_ROOT}/common.sh" || exit 1
. "${SCRIPT_ROOT}/lib/cros_vm_lib.sh" || die "Unable to load cros_vm_lib.sh"
-. "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" || \
+. "${SCRIPT_ROOT}/lib/cros_vm_constants.sh" ||
die "Unable to load cros_vm_constants.sh"
get_default_board
@@ -24,8 +22,6 @@
DEFINE_string test_case "" "Name of the test case to run"
DEFINE_boolean use_emerged ${FLAGS_FALSE} \
"Force use of emerged autotest packages"
-DEFINE_string verify_chrome_version "" \
- "Verify that this chrome version matches that on vm."
set -e
@@ -40,7 +36,7 @@
# Use latest if not specified.
if [ -z "${FLAGS_image_path}" ]; then
- LATEST_IMAGE="$(${SCRIPTS_DIR}/get_latest_image.sh \
+ LATEST_IMAGE="$("${SCRIPT_ROOT}/get_latest_image.sh" \
--board=${FLAGS_board})/${DEFAULT_QEMU_IMAGE}"
info "Using latest vm image ${LATEST_IMAGE}"
FLAGS_image_path=${LATEST_IMAGE}
@@ -72,20 +68,7 @@
start_kvm "${FLAGS_image_path}"
retry_until_ssh
-if [ -n "${FLAGS_verify_chrome_version}" ]; then
- info "Verifying version of Chrome matches what we expect."
- if chrome_version_is_valid "${FLAGS_verify_chrome_version}"; then
- chrome_version_on_vm=$("${SCRIPTS_DIR}/bin/cros_get_chrome_version" \
- --remote=127.0.0.1 \
- --ssh_port=${FLAGS_ssh_port})
- [[ ${chrome_version_on_vm} == ${FLAGS_verify_chrome_version} ]] || \
- warn "CHROME_VERSION is no longer set.This check will be removed"
- else
- warn "${FLAGS_verify_chrome_version} is not a valid Chrome version"
- fi
-fi
-
-"${SCRIPTS_DIR}/run_remote_tests.sh" \
+"${SCRIPT_ROOT}/enter_chroot.sh" -- run_remote_tests.sh \
--board=${FLAGS_board} \
--ssh_port=${FLAGS_ssh_port} \
--remote=127.0.0.1 \
diff --git a/cros_run_vm_update b/cros_run_vm_update
index 6520ada..c1f54c5 100755
--- a/cros_run_vm_update
+++ b/cros_run_vm_update
@@ -6,11 +6,8 @@
#
# Updates an existing vm image with another image.
-. $(dirname "$(readlink -f "$0")")/outside_chroot_common.sh 2> /dev/null ||
- SCRIPT_ROOT=/usr/lib/crosutils
-. "${SCRIPT_ROOT}/common.sh" ||
- (echo "Unable to load common.sh" && false) ||
- exit 1
+. $(dirname "$(readlink -f "$0")")/outside_chroot_common.sh || exit 1
+. "${SCRIPT_ROOT}/common.sh" || exit 1
. "${SCRIPT_ROOT}/lib/cros_vm_lib.sh" || die "Unable to load cros_vm_lib.sh"
DEFINE_string payload "" "Full name of the payload to update with."
@@ -50,7 +47,7 @@
IMAGE_ARGS="${IMAGE_ARGS} --proxy_port=${FLAGS_proxy_port}"
fi
-"${SCRIPTS_DIR}/image_to_live.sh" \
+"${SCRIPT_ROOT}/image_to_live.sh" \
--for_vm \
--remote=127.0.0.1 \
--ssh_port=${FLAGS_ssh_port} \
diff --git a/outside_chroot_common.sh b/outside_chroot_common.sh
index 6947171..3cc4f2e 100644
--- a/outside_chroot_common.sh
+++ b/outside_chroot_common.sh
@@ -7,5 +7,10 @@
# Sets script_root relative to this directory.
# From platform/dev/host.
+if [ -f /etc/debian_chroot ]; then
+ echo "Must be run from outside the chroot." 2> /dev/null
+ exit 1
+fi
+
SCRIPT_ROOT="$(dirname "$(readlink -f "$0")")/../../scripts"
diff --git a/run_remote_tests.sh b/run_remote_tests.sh
index 62f5863..8b881d5 100755
--- a/run_remote_tests.sh
+++ b/run_remote_tests.sh
@@ -4,13 +4,10 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-# Script to run client or server tests on a live remote image.
-. $(dirname "$(readlink -f "$0")")/outside_chroot_common.sh 2> /dev/null ||
- SCRIPT_ROOT=/usr/lib/crosutils
-. "${SCRIPT_ROOT}/common.sh" ||
- (echo "Unable to load common.sh" && false) ||
- exit 1
-. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh"
+# This can only run inside the chroot.
+CROSUTILS=/usr/lib/crosutils
+. "${CROSUTILS}/common.sh" || exit 1
+. "${CROSUTILS}/remote_access.sh" || die "Unable to load remote_access.sh"
DEFINE_string args "" \
"Command line arguments for test. Quoted and space separated if multiple." a
@@ -20,7 +17,6 @@
DEFINE_string board "" \
"The board for which you are building autotest"
DEFINE_boolean build ${FLAGS_FALSE} "Build tests while running" b
-DEFINE_string chroot "${DEFAULT_CHROOT_DIR}" "alternate chroot location" c
DEFINE_boolean cleanup ${FLAGS_FALSE} "Clean up temp directory"
DEFINE_integer iterations 1 "Iterations to run every top level test" i
DEFINE_string results_dir_root "" "alternate root results directory"
@@ -326,10 +322,9 @@
echo ""
info "Test results:"
- ./generate_test_report "${TMP}" --strip="${TMP}/"
+ generate_test_report "${TMP}" --strip="${TMP}/"
print_time_elapsed
}
-restart_in_chroot_if_needed "$@"
main "$@"
diff --git a/ssh_test.sh b/ssh_test.sh
deleted file mode 100755
index 3352cd6..0000000
--- a/ssh_test.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/bash
-
-# Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style license that can be
-# found in the LICENSE file.
-
-# Run remote access test to ensure ssh access to a host is working. Exits with
-# a code of 0 if successful and non-zero otherwise. Used by test infrastructure
-# scripts.
-
-. $(dirname "$(readlink -f "$0")")/outside_chroot_common.sh 2> /dev/null ||
- SCRIPT_ROOT=/usr/lib/crosutils
-. "${SCRIPT_ROOT}/common.sh" ||
- (echo "Unable to load common.sh" && false) ||
- exit 1
-. "${SCRIPT_ROOT}/remote_access.sh" || die "Unable to load remote_access.sh"
-
-function cleanup {
- cleanup_remote_access
- rm -rf "${TMP}"
-}
-
-function main() {
- cd "${SCRIPTS_DIR}"
-
- FLAGS "$@" || exit 1
- eval set -- "${FLAGS_ARGV}"
-
- set -e
-
- trap cleanup EXIT
-
- TMP=$(mktemp -d /tmp/ssh_test.XXXX)
-
- remote_access_init
-}
-
-main $@
diff --git a/utils_py/cros_run_parallel_vm_tests.py b/utils_py/cros_run_parallel_vm_tests.py
index b3bfd6a..0be1c3f 100755
--- a/utils_py/cros_run_parallel_vm_tests.py
+++ b/utils_py/cros_run_parallel_vm_tests.py
@@ -71,9 +71,9 @@
ssh_port = self._base_ssh_port
spawned_tests = []
for test in self._tests:
- # TODO(sosa): Fix when called from /usr/bin inside the chroot.
+ # Must run outside the chroot and use src path.
args = [ os.path.join(os.path.dirname(os.path.realpath(__file__)),
- '../cros_run_vm_test'),
+ '../cros_run_vm_test'),
'--snapshot', # The image is shared so don't modify it.
'--no_graphics',
'--use_emerged',