unit-test: Support running as non-root
This is nice to have so that all of the generated files in our workspace
are owned by our user so we don't have to deal with ownership issues
after the build has completed.
Tested:
Built all of the openbmc packages locally and found no regressions.
Change-Id: I0811ac4e356a023a1238e291f8184dfe01eb003e
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/build-unit-test-docker.sh b/build-unit-test-docker.sh
index 24745da..859d36a 100755
--- a/build-unit-test-docker.sh
+++ b/build-unit-test-docker.sh
@@ -13,11 +13,6 @@
DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-unit-test"}
DISTRO=${2:-"ubuntu:bionic"}
-# Disable autom4te cache as workaround to permission issue
-AUTOM4TE_CFG="/root/.autom4te.cfg"
-AUTOM4TE="begin-language: \"Autoconf-without-aclocal-m4\"\nargs: --no-cache\n\
-end-language: \"Autoconf-without-aclocal-m4\""
-
# Determine the architecture
ARCH=$(uname -m)
case ${ARCH} in
@@ -329,17 +324,16 @@
FROM openbmc-base
${COPY_CMDS}
-RUN echo '${AUTOM4TE}' > ${AUTOM4TE_CFG}
-
# Some of our infrastructure still relies on the presence of this file
# even though it is no longer needed to rebuild the docker environment
# NOTE: The file is sorted to ensure the ordering is stable.
-RUN echo '$(LC_COLLATE=C sort -s "$DEPCACHE_FILE" | tr '\n' ',')' > /root/.depcache
+RUN echo '$(LC_COLLATE=C sort -s "$DEPCACHE_FILE" | tr '\n' ',')' > /tmp/depcache
# Final configuration for the workspace
RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
RUN mkdir -p $(dirname ${HOME})
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
+RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
RUN /bin/bash
EOF
diff --git a/run-unit-test-docker.sh b/run-unit-test-docker.sh
index 5a4427c..8475556 100755
--- a/run-unit-test-docker.sh
+++ b/run-unit-test-docker.sh
@@ -72,6 +72,7 @@
docker run --cap-add=sys_admin --rm=true \
--network host \
--privileged=true \
+ -u "$USER" \
-w "${DOCKER_WORKDIR}" -v "${WORKSPACE}":"${DOCKER_WORKDIR}" \
-e "MAKEFLAGS=${MAKEFLAGS}" \
-t ${DOCKER_IMG_NAME} \
diff --git a/scripts/unit-test.py b/scripts/unit-test.py
index e6c1661..f086b94 100755
--- a/scripts/unit-test.py
+++ b/scripts/unit-test.py
@@ -309,7 +309,7 @@
check_call_cmd(pkgdir, './bootstrap.sh')
check_call_cmd(pkgdir, './configure', *conf_flags)
check_call_cmd(pkgdir, *make_parallel)
- check_call_cmd(pkgdir, *(make_parallel + [ 'install' ]))
+ check_call_cmd(pkgdir, 'sudo', '-n', '--', *(make_parallel + [ 'install' ]))
def install_deps(dep_list):
"""
@@ -339,7 +339,7 @@
dep_tree = head
os.chdir(pkgdir)
# Open package's configure.ac
- with open("/root/.depcache", "r") as depcache:
+ with open("/tmp/depcache", "r") as depcache:
cached = depcache.readline()
with open("configure.ac", "rt") as configure_ac:
# Retrieve dependency list from package's configure.ac
@@ -560,7 +560,7 @@
top_dir = os.path.join(WORKSPACE, UNIT_TEST_PKG)
os.chdir(top_dir)
# Refresh dynamic linker run time bindings for dependencies
- check_call_cmd(top_dir, 'ldconfig')
+ check_call_cmd(top_dir, 'sudo', '-n', '--', 'ldconfig')
# Run package unit tests
run_unit_tests(top_dir)
maybe_run_valgrind(top_dir)