diff options
author | Theodore Ts'o <tytso@mit.edu> | 2022-11-21 18:38:46 -0500 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2022-11-21 18:38:46 -0500 |
commit | 966edd60181009d68e6a0e29fae72d4715657616 (patch) | |
tree | dc7ec6321bf82b476e742f6ae101830c4aa525d3 | |
parent | 49211b6deddd94b9fca312a91997e0884ead2cf9 (diff) | |
download | xfstests-bld-966edd60181009d68e6a0e29fae72d4715657616.tar.gz |
run-fstests: get/infer the architecture from the kernel file
When uploading a file using "gce-xfstests upload-kernel", infer the
architecture from the kernel to be uploaded, and set it in the Google
Cloud Storage metadata.
When running a test, get the architecture from the kernel file, and if
the architecture is explicitly specified, check to make sure the
kernel architecture matches the architecture specified on the command
line. If the architecture is not explicitly specified, use the
architecture of the kernel as the architecture that should be used for
the test.
The net result of this change is that if an arm64 kernel is uploaded,
for example, using the command "gce-xfstests --arm64 upload-kernel",
the uploaded kernel will be tagged with the appropriate metadata, and
so when a test is launched via "gce-xfstests --kernel
gs://$GS_BUCKET/kernel.deb", the architecture type arm64 will be
automatically inferred, and an ARM64 VM will be used.
Similarly, if kvm-xfstests is passed an explicit kernel --- for
example "kvm-xfstests --kernel /build/ext4-arm64/arch/arm64/boot/Image
shell" qemu-system-aarch64 will be automatically used.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
-rwxr-xr-x | kernel-build/kbuild | 4 | ||||
-rwxr-xr-x | run-fstests/gce-xfstests | 10 | ||||
-rw-r--r-- | run-fstests/util/arch-funcs | 62 | ||||
-rw-r--r-- | run-fstests/util/parse_cli | 14 |
4 files changed, 89 insertions, 1 deletions
diff --git a/kernel-build/kbuild b/kernel-build/kbuild index b325661f..16dfb7cd 100755 --- a/kernel-build/kbuild +++ b/kernel-build/kbuild @@ -183,6 +183,10 @@ else err=$? fi +if test -z "$*" -a "$err" == 0 ; then + git describe > $BLD_DIR/.git_version +fi + if test -z "$*" -a "$err" == 0 && \ grep -q CONFIG_MODULES=y $BLD_DIR/.config ; then TMPMODDIR=$(mktemp --tmpdir -d kbuild-modules.XXXXXXXX) diff --git a/run-fstests/gce-xfstests b/run-fstests/gce-xfstests index b69b0c1c..f4da0910 100755 --- a/run-fstests/gce-xfstests +++ b/run-fstests/gce-xfstests @@ -600,9 +600,17 @@ case "$1" in echo "Can't find kernel at $KERNEL" exit 1 fi + get_kernel_file_info "$KERNEL" + gs_meta= + if test -n "$KERNEL_ARCH" ; then + gs_meta="$gs_meta -h x-goog-meta-arch=$KERNEL_ARCH" + fi + if test -n "$KERNEL_VERSION" ; then + gs_meta="$gs_meta -h x-goog-meta-ver=$KERNEL_VERSION" + fi echo "gsutil cp $KERNEL $GS_KERNEL" if test -z "$NO_ACTION" ; then - gsutil -q cp $KERNEL $GS_KERNEL + gsutil -q $gs_meta cp $KERNEL $GS_KERNEL fi exit $? ;; diff --git a/run-fstests/util/arch-funcs b/run-fstests/util/arch-funcs index 4bdce103..248a2a0e 100644 --- a/run-fstests/util/arch-funcs +++ b/run-fstests/util/arch-funcs @@ -74,3 +74,65 @@ function set_cross_compile () ;; esac } + +function get_kernel_file_info () { + local is_gs= + KERNEL_ARCH= + KERNEL_VERSION= + KERNEL="$1" + + case "$KERNEL" in + gs://*) + is_gs=yes + ;; + esac + + if test -n "$is_gs" ; then + local f=$(mktemp --tmpdir gs_stat_XXXXXX) + if gsutil stat "$KERNEL" > "$f" ; then + cat "$f" | sed -e '1,/^ Metadata:/d' | \ + sed -e '/^ [A-Z]/,$d' > "$f.new" + mv "$f.new" "$f" + else + rm -f "$f" + exit 1 + fi + KERNEL_ARCH=$(cat "$f" | grep arch= | sed -e 's/^ *arch=//' -e 's/: *$//') + KERNEL_VERSION=$(cat "$f" | grep ver= | sed -e 's/^ *ver=//' -e 's/: *$//') + rm -f "$f" + else + if test ! -f "$KERNEL" ; then + echo "get-kernel-arch: file not found: $KERNEL" >&2 + exit 1 + fi + info=$(file "$KERNEL" | sed -e "s;$KERNEL: ;;") + case "$info" in + "Linux kernel"*) + KERNEL_ARCH=$(echo $info | tr A-Z a-z |awk '{print $3}') + d=$(dirname $(dirname $(dirname $(dirname "$KERNEL")))) + if test -f "$d/.git_version" ; then + KERNEL_VERSION=$(cat "$d/.git_version") + fi + if test -f "$d/.config" ; then + if test "$KERNEL_ARCH" = "x86" ; then + KERNEL_ARCH=$(head "$d/.config" | grep "^#.*Kernel Configuration" | \ + awk '{print $2}' | sed -e 's;Linux/;;') + if test "$KERNEL_ARCH" = "x86_64" ; then + KERNEL_ARCH=amd64 + fi + fi + fi + ;; + "Debian binary package"*) + KERNEL_ARCH=$(dpkg -I "$KERNEL" | grep "^ Architecture: " | \ + awk '{print $2}') + KERNEL_VERSION=$(dpkg -I "$KERNEL" | grep "^ Version: " | \ + awk '{print $2}') + ;; + *) + echo "get-kernel-arch $i is not a kernel" >&2 + echo "$info" + exit 1 + esac + fi +} diff --git a/run-fstests/util/parse_cli b/run-fstests/util/parse_cli index 2b50e04f..4436a4d5 100644 --- a/run-fstests/util/parse_cli +++ b/run-fstests/util/parse_cli @@ -399,14 +399,17 @@ while (( $# >= 1 )); do --arch) shift supported_flavors kvm gce ARCH="$1" + EXPLICIT_ARCH=yes ;; --arm64) supported_flavors kvm gce ARCH="arm64" + EXPLICIT_ARCH=yes ;; --i386) supported_flavors kvm gce ARCH="i386" + EXPLICIT_ARCH=yes ;; --blktests) supported_flavors kvm gce @@ -1087,6 +1090,17 @@ set_canonicalized_arch "$ARCH" find_kernel_to_use +get_kernel_file_info "$KERNEL" +if test -n "$EXPLICIT_ARCH" ; then + if test "$ARCH" != "$KERNEL_ARCH" ; then + echo "Kernel $KERNEL is apparently built for $KERNEL_ARCH" + echo "Expected architecture: $ARCH" + exit 1 + fi +else + ARCH="$KERNEL_ARCH" +fi + if test -n "$UPDATE_XFSTESTS_TAR" ; then (cd "$DIR/../fstests-bld" ; ./gen-tarball --fast) fi |