From d849e9c43ce95cf21884f61a229c227ea82911b0 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 12:39:31 -0600 Subject: [PATCH 01/34] kps/kpv: fix ccache conditional logic Argument to -z is always false due to literal strings. Signed-off-by: Randolph Sapp --- kps | 2 +- kpv | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kps b/kps index dceb54a..6fc91b8 100755 --- a/kps +++ b/kps @@ -22,7 +22,7 @@ if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then docker pull $IMG_NAME fi ccache=`which ccache` -if [ -z "ccache" ]; then +if [ -z "$ccache" ]; then if [ ! -d "/tmp/ccache" ]; then mkdir /tmp/ccache fi diff --git a/kpv b/kpv index 1a5a8a0..caaa397 100755 --- a/kpv +++ b/kpv @@ -24,7 +24,7 @@ if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then docker pull $IMG_NAME fi ccache=`which ccache` -if [ -z "ccache" ]; then +if [ -z "$ccache" ]; then if [ ! -d "/tmp/ccache" ]; then mkdir /tmp/ccache fi From fcf82c14325215677d8f9782b61a6c1e745d17dc Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 16:17:18 -0600 Subject: [PATCH 02/34] all: replace all instances of $* with "$@" Using "$@" will prevent unnecessary splitting of quoted parameters. For instance, if the following parameter was passed previously: "-a 'hello world'" it would be split into "-a" "hello" "world" which could break things later in processing. The kernel_patch_verify script will have to be reworked to deal with this independently as a lot of functions inherently rely on splitting for handling arrays. Signed-off-by: Randolph Sapp --- kpv | 2 +- proxy-configuration/usr/bin/git-tunnel.sh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kpv b/kpv index caaa397..7c9fa71 100755 --- a/kpv +++ b/kpv @@ -59,7 +59,7 @@ IMAGE_ID=`docker commit $CONTAINER_ID | cut -c8-` export PATH=/workdir/scripts/dtc/:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin/:/opt/cross-gcc-linux-12/bin/:/opt/cross-gcc-linux-11/bin/:/opt/cross-gcc-linux-10/bin/:/opt/cross-gcc-linux-9/bin/:/usr/local/cross-gcc-linux-9/bin/:/usr/local/cross-gcc-linux-10/bin/ -docker run --rm -ti --user $USER_ID:$GROUP_ID -e PATH $DOCKER_MOUNT_DIRS "$IMAGE_ID" kernel_patch_verify -S /usr/local/smatch/bin/k_sm_check_script $* +docker run --rm -ti --user $USER_ID:$GROUP_ID -e PATH $DOCKER_MOUNT_DIRS "$IMAGE_ID" kernel_patch_verify -S /usr/local/smatch/bin/k_sm_check_script "$@" # TODO: we can reuse this image for future runs, for now just clean up after ourselves docker rmi $IMAGE_ID diff --git a/proxy-configuration/usr/bin/git-tunnel.sh b/proxy-configuration/usr/bin/git-tunnel.sh index 99a5b62..6ea0c3b 100755 --- a/proxy-configuration/usr/bin/git-tunnel.sh +++ b/proxy-configuration/usr/bin/git-tunnel.sh @@ -67,7 +67,7 @@ else export GIT_PROXY_HOST=`echo "$http_proxy"|cut -d ':' -f1` export GIT_PROXY_PORT=`echo "$http_proxy"|cut -d ':' -f2` fi - exec $CORKSCREW $GIT_PROXY_HOST $GIT_PROXY_PORT $* + exec $CORKSCREW $GIT_PROXY_HOST $GIT_PROXY_PORT "$@" fi From 26c3840a5f31aa9675dec4ecfd977fe3a9f5f485 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 13:24:50 -0600 Subject: [PATCH 03/34] 99-compiler-path: fix path variables Paths mentioned in the `PATH` env variable should not end with `/`. Signed-off-by: Randolph Sapp --- other-configs/etc/profile.d/99-compiler-path.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/other-configs/etc/profile.d/99-compiler-path.sh b/other-configs/etc/profile.d/99-compiler-path.sh index 1aa2e73..cf89e92 100644 --- a/other-configs/etc/profile.d/99-compiler-path.sh +++ b/other-configs/etc/profile.d/99-compiler-path.sh @@ -1,5 +1,5 @@ -export PATH="$PATH:/opt/cross-gcc-linux-13/bin/" -export PATH="$PATH:/opt/cross-gcc-linux-12/bin/" -export PATH="$PATH:/opt/cross-gcc-linux-11/bin/" -export PATH="$PATH:/opt/cross-gcc-linux-10/bin/" -export PATH="$PATH:/opt/cross-gcc-linux-9/bin/" +export PATH="$PATH:/opt/cross-gcc-linux-13/bin" +export PATH="$PATH:/opt/cross-gcc-linux-12/bin" +export PATH="$PATH:/opt/cross-gcc-linux-11/bin" +export PATH="$PATH:/opt/cross-gcc-linux-10/bin" +export PATH="$PATH:/opt/cross-gcc-linux-9/bin" From 7b22825ac203eb689a97a6a416b3ff6df39a799a Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 14:31:15 -0600 Subject: [PATCH 04/34] build-env: fix ARIA_OPTS word splitting Fix shellcheck warning about word splitting by making the split explicit. Signed-off-by: Randolph Sapp --- build-env.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/build-env.sh b/build-env.sh index 274e78a..d3945ff 100755 --- a/build-env.sh +++ b/build-env.sh @@ -18,14 +18,14 @@ export COCCI_TAG=1.1.1 # https://github.com/devicetree-org/dt-schema/tags export DTSCHEMA_REV=v2023.11 -ARIA_OPTS="--timeout=180 --retry-wait=10 -m 0 -x 10 -j 10" +ARIA_OPTS=(--timeout=180 --retry-wait=10 -m 0 -x 10 -j 10) download_build_install_git() { cd /tmp/ FILE=git-"$GIT_TAG".tar.gz URL="https://git.kernel.org/pub/scm/git/git.git/snapshot/${FILE}" - aria2c $ARIA_OPTS -o "$FILE" "$URL" + aria2c "${ARIA_OPTS[@]}" -o "$FILE" "$URL" mkdir /tmp/git tar -C /tmp/git --strip-components=1 -xvf "$FILE" rm $FILE @@ -102,14 +102,14 @@ download_and_install_armgcc() #aarch64 F64='aarch64-gcc.tar.xz' URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz?revision=61c3be5d-5175-4db6-9030-b565aae9f766&la=en&hash=0A37024B42028A9616F56A51C2D20755C5EBBCD7" - aria2c $ARIA_OPTS -o "$F64" "$URL" + aria2c "${ARIA_OPTS[@]}" -o "$F64" "$URL" tar -C /usr/local/cross-gcc-linux-9/ --strip-components=1 -xf "$F64" rm -f "$F64" #arch32 F32='aarch32-gcc.tar.xz' URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=fed31ee5-2ed7-40c8-9e0e-474299a3c4ac&la=en&hash=76DAF56606E7CB66CC5B5B33D8FB90D9F24C9D20" - aria2c $ARIA_OPTS -o "$F32" "$URL" + aria2c "${ARIA_OPTS[@]}" -o "$F32" "$URL" tar -C /usr/local/cross-gcc-linux-9/ --strip-components=1 -xf "$F32" rm -f "$F32" } From 1f74d4c532a52b30175fe8d2d50e2b6bdc95bc5d Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 14:33:11 -0600 Subject: [PATCH 05/34] build-env: quote NPROC to silence shellcheck Signed-off-by: Randolph Sapp --- build-env.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/build-env.sh b/build-env.sh index d3945ff..58a8557 100755 --- a/build-env.sh +++ b/build-env.sh @@ -53,7 +53,7 @@ download_build_install_dtc() URL="https://git.kernel.org/pub/scm/utils/dtc/dtc.git" git clone --depth=1 --branch "$DTC_TAG" "$URL" cd /tmp/dtc - make -j $NPROC PREFIX=/usr/local SETUP_PREFIX=/usr/local install NO_PYTHON=1 + make -j "$NPROC" PREFIX=/usr/local SETUP_PREFIX=/usr/local install NO_PYTHON=1 cd /tmp rm -rf /tmp/dtc } @@ -64,7 +64,7 @@ download_build_install_sparse() URL="https://git.kernel.org/pub/scm/devel/sparse/sparse.git" git clone --depth=1 --branch "$SPARSE_TAG" "$URL" cd /tmp/sparse - make -j $NPROC PREFIX=/usr/local install + make -j "$NPROC" PREFIX=/usr/local install cd /tmp rm -rf /tmp/sparse } @@ -75,7 +75,7 @@ download_build_install_smatch() URL="https://repo.or.cz/smatch.git" git clone --depth=1 --branch "$SMATCH_TAG" "$URL" cd /tmp/smatch - make -j $NPROC PREFIX=/usr/local/smatch install + make -j "$NPROC" PREFIX=/usr/local/smatch install echo -e '#!/bin/bash\n/usr/local/smatch/bin/smatch -p=kernel $@'>/usr/local/smatch/bin/k_sm_check_script chmod +x /usr/local/smatch/bin/k_sm_check_script cd /tmp From 9c2dc402416e719bfd5af83eb507fee878e0c2a4 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 14:34:21 -0600 Subject: [PATCH 06/34] build-env: use $(...) for NPROC Use $(...) notation instead of legacy backticks `...`. Signed-off-by: Randolph Sapp --- build-env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build-env.sh b/build-env.sh index 58a8557..6ffccde 100755 --- a/build-env.sh +++ b/build-env.sh @@ -3,7 +3,7 @@ set -e export HOME=/tmp source /etc/profile shopt -s expand_aliases -NPROC=`nproc` +NPROC=$(nproc) # https://git.kernel.org/pub/scm/git/git.git/ export GIT_TAG=2.43.0 From cbae1045ee11da28cc3cbc54b9a239af7d5bf8cb Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 14:38:34 -0600 Subject: [PATCH 07/34] build-env: use local keyword for function variables Signed-off-by: Randolph Sapp --- build-env.sh | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/build-env.sh b/build-env.sh index 6ffccde..eca0b3a 100755 --- a/build-env.sh +++ b/build-env.sh @@ -22,9 +22,11 @@ ARIA_OPTS=(--timeout=180 --retry-wait=10 -m 0 -x 10 -j 10) download_build_install_git() { - cd /tmp/ + local FILE URL FILE=git-"$GIT_TAG".tar.gz URL="https://git.kernel.org/pub/scm/git/git.git/snapshot/${FILE}" + + cd /tmp/ aria2c "${ARIA_OPTS[@]}" -o "$FILE" "$URL" mkdir /tmp/git tar -C /tmp/git --strip-components=1 -xvf "$FILE" @@ -49,8 +51,10 @@ download_build_install_python_deps() download_build_install_dtc() { - cd /tmp/ + local URL URL="https://git.kernel.org/pub/scm/utils/dtc/dtc.git" + + cd /tmp/ git clone --depth=1 --branch "$DTC_TAG" "$URL" cd /tmp/dtc make -j "$NPROC" PREFIX=/usr/local SETUP_PREFIX=/usr/local install NO_PYTHON=1 @@ -60,8 +64,10 @@ download_build_install_dtc() download_build_install_sparse() { - cd /tmp/ + local URL URL="https://git.kernel.org/pub/scm/devel/sparse/sparse.git" + + cd /tmp/ git clone --depth=1 --branch "$SPARSE_TAG" "$URL" cd /tmp/sparse make -j "$NPROC" PREFIX=/usr/local install @@ -71,8 +77,10 @@ download_build_install_sparse() download_build_install_smatch() { - cd /tmp/ + local URL URL="https://repo.or.cz/smatch.git" + + cd /tmp/ git clone --depth=1 --branch "$SMATCH_TAG" "$URL" cd /tmp/smatch make -j "$NPROC" PREFIX=/usr/local/smatch install @@ -84,8 +92,10 @@ download_build_install_smatch() download_build_install_coccinelle() { - cd /tmp/ + local URL URL="https://github.com/coccinelle/coccinelle.git" + + cd /tmp/ git clone --depth=1 --branch "$COCCI_TAG" "$URL" cd /tmp/coccinelle ./autogen From 04f4b78bd74f0c10b1bdb52f093c20b45525f1f3 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 14:43:41 -0600 Subject: [PATCH 08/34] build-env: split the armgcc install for 32 and 64 bit Split the current `download_and_install_armgcc` function into a `download_and_install_armgcc_64` and `download_and_install_armgcc_32`. Signed-off-by: Randolph Sapp --- build-env.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/build-env.sh b/build-env.sh index eca0b3a..202679e 100755 --- a/build-env.sh +++ b/build-env.sh @@ -105,7 +105,7 @@ download_build_install_coccinelle() rm -rf /tmp/coccinelle } -download_and_install_armgcc() +download_and_install_armgcc_64() { cd /tmp mkdir -p /opt/cross-gcc-linux-9/ @@ -115,7 +115,12 @@ download_and_install_armgcc() aria2c "${ARIA_OPTS[@]}" -o "$F64" "$URL" tar -C /usr/local/cross-gcc-linux-9/ --strip-components=1 -xf "$F64" rm -f "$F64" +} +download_and_install_armgcc_32() +{ + cd /tmp + mkdir -p /opt/cross-gcc-linux-9/ #arch32 F32='aarch32-gcc.tar.xz' URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=fed31ee5-2ed7-40c8-9e0e-474299a3c4ac&la=en&hash=76DAF56606E7CB66CC5B5B33D8FB90D9F24C9D20" @@ -131,7 +136,8 @@ download_build_install_smatch download_build_install_sparse download_build_install_coccinelle if [ "$INSTALL_GCC" == "1" ]; then - download_and_install_armgcc + download_and_install_armgcc_64 + download_and_install_armgcc_32 else echo "Skipping install GCC. INSTALL_GCC!=1. make sure that /opt/cross-gcc-linux-9/bin has aarch64-none-linux-gnu- and arm-none-linux-gnueabihf-" fi From 93d90f7697c69e453387f56da2d0fec095bf4bdb Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 14:59:02 -0600 Subject: [PATCH 09/34] build-env: standardize use of FILE and URL Standardize all functions on the use of FILE and URL variables. Signed-off-by: Randolph Sapp --- build-env.sh | 62 ++++++++++++++++++++++++++++------------------------ 1 file changed, 34 insertions(+), 28 deletions(-) diff --git a/build-env.sh b/build-env.sh index 202679e..3bdaa56 100755 --- a/build-env.sh +++ b/build-env.sh @@ -51,82 +51,88 @@ download_build_install_python_deps() download_build_install_dtc() { - local URL + local FILE URL + FILE='dtc' URL="https://git.kernel.org/pub/scm/utils/dtc/dtc.git" cd /tmp/ - git clone --depth=1 --branch "$DTC_TAG" "$URL" - cd /tmp/dtc + git clone --depth=1 --branch "$DTC_TAG" "$URL" "$FILE" + cd /tmp/"$FILE" make -j "$NPROC" PREFIX=/usr/local SETUP_PREFIX=/usr/local install NO_PYTHON=1 cd /tmp - rm -rf /tmp/dtc + rm -rf /tmp/"$FILE" } download_build_install_sparse() { - local URL + local FILE URL + FILE='sparse' URL="https://git.kernel.org/pub/scm/devel/sparse/sparse.git" cd /tmp/ - git clone --depth=1 --branch "$SPARSE_TAG" "$URL" - cd /tmp/sparse + git clone --depth=1 --branch "$SPARSE_TAG" "$URL" "$FILE" + cd /tmp/"$FILE" make -j "$NPROC" PREFIX=/usr/local install cd /tmp - rm -rf /tmp/sparse + rm -rf /tmp/"$FILE" } download_build_install_smatch() { - local URL + local FILE URL + FILE='smatch' URL="https://repo.or.cz/smatch.git" cd /tmp/ - git clone --depth=1 --branch "$SMATCH_TAG" "$URL" - cd /tmp/smatch + git clone --depth=1 --branch "$SMATCH_TAG" "$URL" "$FILE" + cd /tmp/"$FILE" make -j "$NPROC" PREFIX=/usr/local/smatch install echo -e '#!/bin/bash\n/usr/local/smatch/bin/smatch -p=kernel $@'>/usr/local/smatch/bin/k_sm_check_script chmod +x /usr/local/smatch/bin/k_sm_check_script cd /tmp - rm -rf /tmp/smatch + rm -rf /tmp/"$FILE" } download_build_install_coccinelle() { - local URL + local FILE URL + FILE='coccinelle' URL="https://github.com/coccinelle/coccinelle.git" cd /tmp/ - git clone --depth=1 --branch "$COCCI_TAG" "$URL" - cd /tmp/coccinelle + git clone --depth=1 --branch "$COCCI_TAG" "$URL" "$FILE" + cd /tmp/"$FILE" ./autogen ./configure --prefix=/usr/local make install cd /tmp - rm -rf /tmp/coccinelle + rm -rf /tmp/"$FILE" } download_and_install_armgcc_64() { + local FILE URL + FILE='aarch64-gcc.tar.xz' + URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz?revision=61c3be5d-5175-4db6-9030-b565aae9f766&la=en&hash=0A37024B42028A9616F56A51C2D20755C5EBBCD7" + cd /tmp mkdir -p /opt/cross-gcc-linux-9/ - #aarch64 - F64='aarch64-gcc.tar.xz' - URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz?revision=61c3be5d-5175-4db6-9030-b565aae9f766&la=en&hash=0A37024B42028A9616F56A51C2D20755C5EBBCD7" - aria2c "${ARIA_OPTS[@]}" -o "$F64" "$URL" - tar -C /usr/local/cross-gcc-linux-9/ --strip-components=1 -xf "$F64" - rm -f "$F64" + aria2c "${ARIA_OPTS[@]}" -o "$FILE" "$URL" + tar -C /usr/local/cross-gcc-linux-9/ --strip-components=1 -xf "$FILE" + rm -f /tmp/"$FILE" } download_and_install_armgcc_32() { + local FILE URL + FILE='aarch32-gcc.tar.xz' + URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=fed31ee5-2ed7-40c8-9e0e-474299a3c4ac&la=en&hash=76DAF56606E7CB66CC5B5B33D8FB90D9F24C9D20" + cd /tmp mkdir -p /opt/cross-gcc-linux-9/ - #arch32 - F32='aarch32-gcc.tar.xz' - URL="https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-arm-none-linux-gnueabihf.tar.xz?revision=fed31ee5-2ed7-40c8-9e0e-474299a3c4ac&la=en&hash=76DAF56606E7CB66CC5B5B33D8FB90D9F24C9D20" - aria2c "${ARIA_OPTS[@]}" -o "$F32" "$URL" - tar -C /usr/local/cross-gcc-linux-9/ --strip-components=1 -xf "$F32" - rm -f "$F32" + aria2c "${ARIA_OPTS[@]}" -o "$FILE" "$URL" + tar -C /usr/local/cross-gcc-linux-9/ --strip-components=1 -xf "$FILE" + rm -f /tmp/"$FILE" } download_build_install_git From af725ce0685217c9867931adbf7a90ac5b3aa1a4 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 15:07:17 -0600 Subject: [PATCH 10/34] build-env: factor out common git code Signed-off-by: Randolph Sapp --- build-env.sh | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/build-env.sh b/build-env.sh index 3bdaa56..8c18301 100755 --- a/build-env.sh +++ b/build-env.sh @@ -49,15 +49,21 @@ download_build_install_python_deps() python -m pip install --break-system-packages git+https://github.com/devicetree-org/dt-schema.git@$DTSCHEMA_REV } +clone_and_cd() +{ + cd /tmp && + git clone --depth=1 --branch "$1" "$2" "$3" && + cd /tmp/"$3" + return $? +} + download_build_install_dtc() { local FILE URL FILE='dtc' URL="https://git.kernel.org/pub/scm/utils/dtc/dtc.git" - cd /tmp/ - git clone --depth=1 --branch "$DTC_TAG" "$URL" "$FILE" - cd /tmp/"$FILE" + clone_and_cd "$DTC_TAG" "$URL" "$FILE" make -j "$NPROC" PREFIX=/usr/local SETUP_PREFIX=/usr/local install NO_PYTHON=1 cd /tmp rm -rf /tmp/"$FILE" @@ -69,9 +75,7 @@ download_build_install_sparse() FILE='sparse' URL="https://git.kernel.org/pub/scm/devel/sparse/sparse.git" - cd /tmp/ - git clone --depth=1 --branch "$SPARSE_TAG" "$URL" "$FILE" - cd /tmp/"$FILE" + clone_and_cd "$SPARSE_TAG" "$URL" "$FILE" make -j "$NPROC" PREFIX=/usr/local install cd /tmp rm -rf /tmp/"$FILE" @@ -83,9 +87,7 @@ download_build_install_smatch() FILE='smatch' URL="https://repo.or.cz/smatch.git" - cd /tmp/ - git clone --depth=1 --branch "$SMATCH_TAG" "$URL" "$FILE" - cd /tmp/"$FILE" + clone_and_cd "$SMATCH_TAG" "$URL" "$FILE" make -j "$NPROC" PREFIX=/usr/local/smatch install echo -e '#!/bin/bash\n/usr/local/smatch/bin/smatch -p=kernel $@'>/usr/local/smatch/bin/k_sm_check_script chmod +x /usr/local/smatch/bin/k_sm_check_script @@ -99,9 +101,7 @@ download_build_install_coccinelle() FILE='coccinelle' URL="https://github.com/coccinelle/coccinelle.git" - cd /tmp/ - git clone --depth=1 --branch "$COCCI_TAG" "$URL" "$FILE" - cd /tmp/"$FILE" + clone_and_cd "$COCCI_TAG" "$URL" "$FILE" ./autogen ./configure --prefix=/usr/local make install From 6a854e92c7f22d976520f9bba2ebd9c3043f03ef Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 15:19:10 -0600 Subject: [PATCH 11/34] kpv: fix PATH variable setting Paths mentioned in the `PATH` env variable should not end with `/`. Signed-off-by: Randolph Sapp --- kpv | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kpv b/kpv index 7c9fa71..29f149f 100755 --- a/kpv +++ b/kpv @@ -57,7 +57,7 @@ CONTAINER_ID=`docker ps -lq` # Commit the container state (returns an image_id with sha256: prefix cut off) IMAGE_ID=`docker commit $CONTAINER_ID | cut -c8-` -export PATH=/workdir/scripts/dtc/:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin/:/opt/cross-gcc-linux-12/bin/:/opt/cross-gcc-linux-11/bin/:/opt/cross-gcc-linux-10/bin/:/opt/cross-gcc-linux-9/bin/:/usr/local/cross-gcc-linux-9/bin/:/usr/local/cross-gcc-linux-10/bin/ +export PATH=/workdir/scripts/dtc:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin:/opt/cross-gcc-linux-12/bin:/opt/cross-gcc-linux-11/bin:/opt/cross-gcc-linux-10/bin:/opt/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-10/bin docker run --rm -ti --user $USER_ID:$GROUP_ID -e PATH $DOCKER_MOUNT_DIRS "$IMAGE_ID" kernel_patch_verify -S /usr/local/smatch/bin/k_sm_check_script "$@" From 00c15b6cb423542c54d913d0af9be8db764fe051 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 15:23:48 -0600 Subject: [PATCH 12/34] kpv: use $(...) to appease shellcheck Use $(...) notation instead of legacy backticks `...`. Signed-off-by: Randolph Sapp --- kpv | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kpv b/kpv index 29f149f..8d1b58d 100755 --- a/kpv +++ b/kpv @@ -12,7 +12,7 @@ IMG_NAME="${IMG_NAME:-ghcr.io/nmenon/arm-kernel-dev}" # IMG_NAME=arm-kernel-dev # Check if docker exists -docker=`which docker` +docker=$(which docker) if [ -z "$docker" ]; then echo "Please install Docker to be able to function" exit 1 @@ -23,21 +23,21 @@ fi if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then docker pull $IMG_NAME fi -ccache=`which ccache` +ccache=$(which ccache) if [ -z "$ccache" ]; then if [ ! -d "/tmp/ccache" ]; then mkdir /tmp/ccache fi CCACHEDIR=/tmp/ccache else - CCACHEDIR=`ccache -s|grep "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ' ' -f3` + CCACHEDIR=$(ccache -s|grep "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ' ' -f3) if [ -z "$CCACHEDIR" ]; then - CCACHEDIR=`ccache -v -s|grep -i "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ':' -f2` + CCACHEDIR=$(ccache -v -s|grep -i "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ':' -f2) fi fi -USER_ID=`id -u` -GROUP_ID=`id -g` +USER_ID=$(id -u) +GROUP_ID=$(id -g) DOCKER_MOUNT_DIRS+="-v /tmp:/tmp " DOCKER_MOUNT_DIRS+="-v /opt:/opt " @@ -53,9 +53,9 @@ fi # Run our image to add our swuser docker run "$IMG_NAME" /bin/bash -c "groupadd -r swuser -g $GROUP_ID && useradd -u $USER_ID -r -g swuser -d /workdir -s /sbin/nologin -c \"Docker kernel patch user\" swuser" # Get the container ID of the last run container (above) -CONTAINER_ID=`docker ps -lq` +CONTAINER_ID=$(docker ps -lq) # Commit the container state (returns an image_id with sha256: prefix cut off) -IMAGE_ID=`docker commit $CONTAINER_ID | cut -c8-` +IMAGE_ID=$(docker commit $CONTAINER_ID | cut -c8-) export PATH=/workdir/scripts/dtc:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin:/opt/cross-gcc-linux-12/bin:/opt/cross-gcc-linux-11/bin:/opt/cross-gcc-linux-10/bin:/opt/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-10/bin From 73701434bae2047c0c6d2f33f56a65d116aa46fe Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 15:28:27 -0600 Subject: [PATCH 13/34] kpv: fix word splitting issues Fix word splitting issues that may arrise from docker mount parameters and other variables. Signed-off-by: Randolph Sapp --- kpv | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/kpv b/kpv index 8d1b58d..3a73da9 100755 --- a/kpv +++ b/kpv @@ -21,7 +21,7 @@ fi # If we are working off docker image from github container reg, make sure # we have the latest. if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then - docker pull $IMG_NAME + docker pull "$IMG_NAME" fi ccache=$(which ccache) if [ -z "$ccache" ]; then @@ -39,15 +39,16 @@ fi USER_ID=$(id -u) GROUP_ID=$(id -g) -DOCKER_MOUNT_DIRS+="-v /tmp:/tmp " -DOCKER_MOUNT_DIRS+="-v /opt:/opt " -DOCKER_MOUNT_DIRS+="-v $CCACHEDIR:/ccache " -DOCKER_MOUNT_DIRS+="-v $(pwd):/workdir " +DOCKER_MOUNT_DIRS=() +DOCKER_MOUNT_DIRS+=(-v /tmp:/tmp) +DOCKER_MOUNT_DIRS+=(-v /opt:/opt) +DOCKER_MOUNT_DIRS+=(-v "$CCACHEDIR":/ccache) +DOCKER_MOUNT_DIRS+=(-v "$(pwd)":/workdir) # Mount parent directory if its a worktree GIT_WORKTREE_COMMONDIR=$(git rev-parse --git-common-dir) if [[ $GIT_WORKTREE_COMMONDIR != ".git" ]]; then - DOCKER_MOUNT_DIRS+=" -v $GIT_WORKTREE_COMMONDIR:$GIT_WORKTREE_COMMONDIR " + DOCKER_MOUNT_DIRS+=(-v "$GIT_WORKTREE_COMMONDIR":"$GIT_WORKTREE_COMMONDIR") fi # Run our image to add our swuser @@ -55,11 +56,11 @@ docker run "$IMG_NAME" /bin/bash -c "groupadd -r swuser -g $GROUP_ID && useradd # Get the container ID of the last run container (above) CONTAINER_ID=$(docker ps -lq) # Commit the container state (returns an image_id with sha256: prefix cut off) -IMAGE_ID=$(docker commit $CONTAINER_ID | cut -c8-) +IMAGE_ID=$(docker commit "$CONTAINER_ID" | cut -c8-) export PATH=/workdir/scripts/dtc:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin:/opt/cross-gcc-linux-12/bin:/opt/cross-gcc-linux-11/bin:/opt/cross-gcc-linux-10/bin:/opt/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-10/bin -docker run --rm -ti --user $USER_ID:$GROUP_ID -e PATH $DOCKER_MOUNT_DIRS "$IMAGE_ID" kernel_patch_verify -S /usr/local/smatch/bin/k_sm_check_script "$@" +docker run --rm -ti --user "$USER_ID":"$GROUP_ID" -e PATH "${DOCKER_MOUNT_DIRS[@]}" "$IMAGE_ID" kernel_patch_verify -S /usr/local/smatch/bin/k_sm_check_script "$@" # TODO: we can reuse this image for future runs, for now just clean up after ourselves -docker rmi $IMAGE_ID +docker rmi "$IMAGE_ID" From 15452e3c88bdacbc34ce3699e34b894bced53191 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 15:52:02 -0600 Subject: [PATCH 14/34] kpv/kps: factor out common code Split the common code out into a file both scripts source. Signed-off-by: Randolph Sapp --- kp_common | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++ kps | 66 +++++++--------------------------------------------- kpv | 69 +++++++------------------------------------------------ 3 files changed, 79 insertions(+), 119 deletions(-) create mode 100644 kp_common diff --git a/kp_common b/kp_common new file mode 100644 index 0000000..5c881c3 --- /dev/null +++ b/kp_common @@ -0,0 +1,63 @@ +#!/bin/bash + +export USER_ID GROUP_ID PATH DOCKER_MOUNT_DIRS IMAGE_ID + +# Check if Docker image exists + +# Use Directly from github container registry if not provided: +# dockerhub location is nishanthmenon/arm-kernel-dev +IMG_NAME="${IMG_NAME:-ghcr.io/nmenon/arm-kernel-dev}" + +# TBD: If we are using from github -> I need to figure out how to get that working.. + +# If we are building locally +# IMG_NAME=arm-kernel-dev + +# Check if docker exists +docker=$(which docker) +if [ -z "$docker" ]; then + echo "Please install Docker to be able to function" + exit 1 +fi + +# If we are working off docker image from github container reg, make sure +# we have the latest. +if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then + docker pull "$IMG_NAME" +fi +ccache=$(which ccache 2> /dev/null) +if [ -z "$ccache" ]; then + if [ ! -d "/tmp/ccache" ]; then + mkdir /tmp/ccache + fi + CCACHEDIR=/tmp/ccache +else + CCACHEDIR=$(ccache -s|grep "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ' ' -f3) + if [ -z "$CCACHEDIR" ]; then + CCACHEDIR=$(ccache -v -s|grep -i "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ':' -f2) + fi +fi + +USER_ID=$(id -u) +GROUP_ID=$(id -g) + +DOCKER_MOUNT_DIRS=() +DOCKER_MOUNT_DIRS+=(-v /tmp:/tmp) +DOCKER_MOUNT_DIRS+=(-v /opt:/opt) +DOCKER_MOUNT_DIRS+=(-v "$CCACHEDIR":/ccache) +DOCKER_MOUNT_DIRS+=(-v "$(pwd)":/workdir) + +# Mount parent directory if its a worktree +GIT_WORKTREE_COMMONDIR=$(git rev-parse --git-common-dir) +if [[ $GIT_WORKTREE_COMMONDIR != ".git" ]]; then + DOCKER_MOUNT_DIRS+=(-v "$GIT_WORKTREE_COMMONDIR":"$GIT_WORKTREE_COMMONDIR") +fi + +# Run our image to add our swuser +docker run "$IMG_NAME" /bin/bash -c "groupadd -r swuser -g $GROUP_ID && useradd -u $USER_ID -r -g swuser -d /workdir -s /sbin/nologin -c \"Docker kernel patch user\" swuser" +# Get the container ID of the last run container (above) +CONTAINER_ID=$(docker ps -lq) +# Commit the container state (returns an image_id with sha256: prefix cut off) +IMAGE_ID=$(docker commit "$CONTAINER_ID" | cut -c8-) + +PATH=/workdir/scripts/dtc:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin:/opt/cross-gcc-linux-12/bin:/opt/cross-gcc-linux-11/bin:/opt/cross-gcc-linux-10/bin:/opt/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-10/bin diff --git a/kps b/kps index 6fc91b8..6a7a07b 100755 --- a/kps +++ b/kps @@ -1,64 +1,14 @@ #!/bin/bash -# Use Directly from github container registry if not provided: -# dockerhub location is nishanthmenon/arm-kernel-dev -IMG_NAME="${IMG_NAME:-ghcr.io/nmenon/arm-kernel-dev}" - -# TBD: If we are using from github -> I need to figure out how to get that working.. - -# If we are building locally -# IMG_NAME=arm-kernel-dev - -# Check if docker exists -docker=`which docker` -if [ -z "$docker" ]; then - echo "Please install Docker to be able to function" - exit 1 -fi - -# If we are working off docker image from github container reg, make sure -# we have the latest. -if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then - docker pull $IMG_NAME -fi -ccache=`which ccache` -if [ -z "$ccache" ]; then - if [ ! -d "/tmp/ccache" ]; then - mkdir /tmp/ccache - fi - CCACHEDIR=/tmp/ccache -else - CCACHEDIR=`ccache -s|grep "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ' ' -f3` - if [ -z "$CCACHEDIR" ]; then - CCACHEDIR=`ccache -v -s|grep -i "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ':' -f2` - fi -fi - -USER_ID=`id -u` -GROUP_ID=`id -g` - -DOCKER_MOUNT_DIRS+="-v /tmp:/tmp " -DOCKER_MOUNT_DIRS+="-v /opt:/opt " -DOCKER_MOUNT_DIRS+="-v $CCACHEDIR:/ccache " -DOCKER_MOUNT_DIRS+="-v $(pwd):/workdir " - -# Mount parent directory if its a worktree -GIT_WORKTREE_COMMONDIR=$(git rev-parse --git-common-dir) -if [[ $GIT_WORKTREE_COMMONDIR != ".git" ]]; then - DOCKER_MOUNT_DIRS+=" -v $GIT_WORKTREE_COMMONDIR:$GIT_WORKTREE_COMMONDIR " -fi - -# Run our image to add our swuser -docker run "$IMG_NAME" /bin/bash -c "groupadd -r swuser -g $GROUP_ID && useradd -u $USER_ID -r -g swuser -d /workdir -s /sbin/nologin -c \"Docker kernel patch user\" swuser" -# Get the container ID of the last run container (above) -CONTAINER_ID=`docker ps -lq` -# Commit the container state (returns an image_id with sha256: prefix cut off) -IMAGE_ID=`docker commit $CONTAINER_ID | cut -c8-` - -export PATH=/workdir/scripts/dtc/:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin/:/opt/cross-gcc-linux-12/bin/:/opt/cross-gcc-linux-11/bin/:/opt/cross-gcc-linux-10/bin/:/opt/cross-gcc-linux-9/bin/:/usr/local/cross-gcc-linux-9/bin/:/usr/local/cross-gcc-linux-10/bin/ +source "$(dirname "$(readlink -f "$0")")/kp_common" # If we wanted to get to bash shell: -docker run --rm -ti --user $USER_ID:$GROUP_ID -e PATH $DOCKER_MOUNT_DIRS "$IMAGE_ID" bash --init-file /etc/profile +docker run --rm -ti \ + --user "$USER_ID":"$GROUP_ID" \ + -e PATH \ + "${DOCKER_MOUNT_DIRS[@]}" \ + "$IMAGE_ID" \ + bash --init-file /etc/profile # TODO: we can reuse this image for future runs, for now just clean up after ourselves -docker rmi $IMAGE_ID +docker rmi "$IMAGE_ID" diff --git a/kpv b/kpv index 3a73da9..2de6290 100755 --- a/kpv +++ b/kpv @@ -1,66 +1,13 @@ #!/bin/bash -# Check if Docker image exists - -# Use Directly from github container registry if not provided: -# dockerhub location is nishanthmenon/arm-kernel-dev -IMG_NAME="${IMG_NAME:-ghcr.io/nmenon/arm-kernel-dev}" - -# TBD: If we are using from github -> I need to figure out how to get that working.. - -# If we are building locally -# IMG_NAME=arm-kernel-dev - -# Check if docker exists -docker=$(which docker) -if [ -z "$docker" ]; then - echo "Please install Docker to be able to function" - exit 1 -fi - -# If we are working off docker image from github container reg, make sure -# we have the latest. -if [ "$IMG_NAME" = "ghcr.io/nmenon/arm-kernel-dev" ]; then - docker pull "$IMG_NAME" -fi -ccache=$(which ccache) -if [ -z "$ccache" ]; then - if [ ! -d "/tmp/ccache" ]; then - mkdir /tmp/ccache - fi - CCACHEDIR=/tmp/ccache -else - CCACHEDIR=$(ccache -s|grep "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ' ' -f3) - if [ -z "$CCACHEDIR" ]; then - CCACHEDIR=$(ccache -v -s|grep -i "cache directory"|sed -e "s/\s\s*/ /g"|cut -d ':' -f2) - fi -fi - -USER_ID=$(id -u) -GROUP_ID=$(id -g) - -DOCKER_MOUNT_DIRS=() -DOCKER_MOUNT_DIRS+=(-v /tmp:/tmp) -DOCKER_MOUNT_DIRS+=(-v /opt:/opt) -DOCKER_MOUNT_DIRS+=(-v "$CCACHEDIR":/ccache) -DOCKER_MOUNT_DIRS+=(-v "$(pwd)":/workdir) - -# Mount parent directory if its a worktree -GIT_WORKTREE_COMMONDIR=$(git rev-parse --git-common-dir) -if [[ $GIT_WORKTREE_COMMONDIR != ".git" ]]; then - DOCKER_MOUNT_DIRS+=(-v "$GIT_WORKTREE_COMMONDIR":"$GIT_WORKTREE_COMMONDIR") -fi - -# Run our image to add our swuser -docker run "$IMG_NAME" /bin/bash -c "groupadd -r swuser -g $GROUP_ID && useradd -u $USER_ID -r -g swuser -d /workdir -s /sbin/nologin -c \"Docker kernel patch user\" swuser" -# Get the container ID of the last run container (above) -CONTAINER_ID=$(docker ps -lq) -# Commit the container state (returns an image_id with sha256: prefix cut off) -IMAGE_ID=$(docker commit "$CONTAINER_ID" | cut -c8-) - -export PATH=/workdir/scripts/dtc:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/opt/cross-gcc-linux-13/bin:/opt/cross-gcc-linux-12/bin:/opt/cross-gcc-linux-11/bin:/opt/cross-gcc-linux-10/bin:/opt/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-9/bin:/usr/local/cross-gcc-linux-10/bin - -docker run --rm -ti --user "$USER_ID":"$GROUP_ID" -e PATH "${DOCKER_MOUNT_DIRS[@]}" "$IMAGE_ID" kernel_patch_verify -S /usr/local/smatch/bin/k_sm_check_script "$@" +source "$(dirname "$(readlink -f "$0")")/kp_common" + +docker run --rm -ti \ + --user "$USER_ID":"$GROUP_ID" \ + -e PATH \ + "${DOCKER_MOUNT_DIRS[@]}" \ + "$IMAGE_ID" \ + kernel_patch_verify -S /usr/local/smatch/bin/k_sm_check_script "$@" # TODO: we can reuse this image for future runs, for now just clean up after ourselves docker rmi "$IMAGE_ID" From 4069ec5711b0370baf6f85320d674c15fa77edd9 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 16:30:50 -0600 Subject: [PATCH 15/34] kernel_patch_verify: replace '-a' test calls with '&&' Prefer [ p ] && [ q ] as [ p -a q ] is not well defined. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 7f5ad5e..ba8a015 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -543,7 +543,7 @@ on_exit() { echo "restoring .config" cp $TEST_DIR/.config .config fi - if [ -n "$TEST_DIR" -a -d "$TEST_DIR" ]; then + if [ -n "$TEST_DIR" ] && [ -d "$TEST_DIR" ]; then echo "Removing temp dir" rm -rf $TEST_DIR 2>/dev/null fi @@ -590,7 +590,7 @@ report_tests() { start_log=$TEST_DIR/$test-start end_log=$TEST_DIR/$test-end diff_log=$TEST_DIR/$test-diff - if [ -f $start_log -a -f $end_log ]; then + if [ -f $start_log ] && [ -f $end_log ]; then diff -purN $start_log $end_log > $diff_log fi done @@ -797,24 +797,24 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do ORIDE=1 ;; d) - if [ -z "$LLVM" -a -z "$CROSS_COMPILE" ]; then + if [ -z "$LLVM" ] && [ -z "$CROSS_COMPILE" ]; then export CROSS_COMPILE="$DEF_CROSS_COMPILE" fi if [ -z "$ARCH" ]; then export ARCH="$DEF_ARCH" fi - if [ -z "$KP_TARGETS" -a $ORIDE -eq 0 ]; then + if [ -z "$KP_TARGETS" ] && [ $ORIDE -eq 0 ]; then export KP_TARGETS="$KP_TARGETS $DEF_BUILDTARGETS" fi ;; V) - if [ -z "$LLVM" -a -z "$CROSS_COMPILE" ]; then + if [ -z "$LLVM" ] && [ -z "$CROSS_COMPILE" ]; then export CROSS_COMPILE="$DEF_V8_CROSS_COMPILE" fi if [ -z "$ARCH" ]; then export ARCH="$DEF_V8_ARCH" fi - if [ -z "$KP_TARGETS" -a $ORIDE -eq 0 ]; then + if [ -z "$KP_TARGETS" ] && [ $ORIDE -eq 0 ]; then export KP_TARGETS="$KP_TARGETS $DEF_V8_BUILDTARGETS" fi ;; @@ -828,7 +828,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do ;; U) DEF_BUILDTARGETS="" - if [ -n "$KP_TARGETS" -a $ORIDE -eq 0 ]; then + if [ -n "$KP_TARGETS" ] && [ $ORIDE -eq 0 ]; then export KP_TARGETS="" fi if [ -n "$COMPLETE_TESTS" ]; then @@ -940,7 +940,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do esac done -if [ -z "$TEST_BRANCH" -a -z "$BASE_BRANCH" -a -z "$PATCH_DIR" -a -z "$TEST_TOP" ]; then +if [ -z "${TEST_BRANCH}${BASE_BRANCH}${PATCH_DIR}${TEST_TOP}" ]; then usage "Need at least 1 test type" exit 2 fi @@ -996,19 +996,19 @@ KDIR=`pwd` CURRENT_BRANCH=`git branch | grep '^*' | cut -d " " -f 2` # if we have base or testing branch missing, populate the other as the current branch -if [ -n "$TEST_BRANCH" -a -z "$BASE_BRANCH" ]; then +if [ -n "$TEST_BRANCH" ] && [ -z "$BASE_BRANCH" ]; then BASE_BRANCH=$CURRENT_BRANCH fi -if [ -n "$BASE_BRANCH" -a -z "$TEST_BRANCH" ]; then +if [ -n "$BASE_BRANCH" ] && [ -z "$TEST_BRANCH" ]; then TEST_BRANCH=$CURRENT_BRANCH fi -if [ -n "$TEST_BRANCH" -a "$TEST_BRANCH" = "$BASE_BRANCH" ]; then +if [ -n "$TEST_BRANCH" ] && [ "$TEST_BRANCH" = "$BASE_BRANCH" ]; then usage "Test branch and base branch are the same '$TEST_BRANCH'.. Hmm.. not sleeping lately?" exit 3 fi -if [ ! -e ".config" -a -z "$DEFCONFIG" ]; then +if [ ! -e ".config" ] && [ -z "$DEFCONFIG" ]; then usage "No default .config exists nor is a defconfig specified with -c" exit 3 fi From 24c731485ecd7ef0429e67f32b4c97853181fc9e Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 16:36:18 -0600 Subject: [PATCH 16/34] kernel_patch_verify: use || instead of [ -o ] Prefer [ p ] || [ q ] as [ p -o q ] is not well defined. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index ba8a015..830b2bf 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -869,7 +869,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do ;; [1-9]) TEST_TOP=yes - if [ -n "$PATCH_DIR" -o -n "$BASE_BRANCH" -o -n "$TEST_BRANCH" ]; then + if [ -n "${PATCH_DIR}${BASE_BRANCH}${TEST_BRANCH}" ]; then usage "cannot use -$opt with other options" exit 1; fi @@ -877,7 +877,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do ;; n) TEST_TOP=yes - if [ -n "$PATCH_DIR" -o -n "$BASE_BRANCH" -o -n "$TEST_BRANCH" ]; then + if [ -n "${PATCH_DIR}${BASE_BRANCH}${TEST_BRANCH}" ]; then usage "cannot use -n with other options" exit 1; fi @@ -889,7 +889,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do ;; p) PATCH_DIR=$OPTARG - if [ -n "$TEST_TOP" -o -n "$BASE_BRANCH" -o -n "$TEST_BRANCH" ]; then + if [ -n "${TEST_TOP}${BASE_BRANCH}${TEST_BRANCH}" ]; then usage "cannot use -p with other options" exit 1; fi @@ -906,14 +906,14 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do ;; b) BASE_BRANCH=$OPTARG - if [ -n "$TEST_TOP" -o -n "$PATCH_DIR" ]; then + if [ -n "${TEST_TOP}${PATCH_DIR}" ]; then usage "cannot use -b with other options" exit 1; fi ;; t) TEST_BRANCH=$OPTARG - if [ -n "$TEST_TOP" -o -n "$PATCH_DIR" ]; then + if [ -n "${TEST_TOP}${PATCH_DIR}" ]; then usage "cannot use -t with other options" exit 1; fi @@ -957,7 +957,7 @@ fi GN=`git config --get user.name` GE=`git config --get user.email` -if [ -z "$GE" -o -z "$GN" ]; then +if [ -z "$GE" ] || [ -z "$GN" ]; then echo "We need to know who you are to proceed, please check 'git config -l' and fix via:" echo 'git config --global user.email "you@example.com"' echo 'git config --global user.name "Your Name"' @@ -1027,7 +1027,7 @@ fi GIT_RM_DIR=`git rev-parse --git-path rebase-merge` GIT_RA_DIR=`git rev-parse --git-path rebase-apply` -if [ -e "$GIT_RM_DIR" -o -e "$GIT_RA_DIR" ]; then +if [ -e "$GIT_RM_DIR" ] || [ -e "$GIT_RA_DIR" ]; then usage "$GIT_RA_DIR or $GIT_RM_DIR exists - implying rebase or am in progress. please cleanup to proceed - 'git am --abort;git rebase --abort' perhaps?" exit 3 fi From 20a12aec66c96267ee72c0a34cd2550a1fced7e4 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 16:49:32 -0600 Subject: [PATCH 17/34] kernel_patch_verify: use $(...) to appease shellcheck Use $(...) notation instead of legacy backticks `...`. Also fix the arithmetic sections. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 136 ++++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 830b2bf..3419fbb 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -26,7 +26,7 @@ source /etc/profile shopt -s expand_aliases -ccache=`which ccache` +ccache=$(which ccache) # We would rather that we hit cache more often, than rebuild.. # See https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=87c94bfb8ad354fb43d2caf870d7ca0b3f98dab3 @@ -48,7 +48,7 @@ DEF_V8_BUILDTARGETS="Image dtbs" APPS_NEEDED="perl make dtc sparse patch git realpath basename" # Use all max num CPUs -DEF_CPUS=`grep -c '^processor' /proc/cpuinfo` +DEF_CPUS=$(grep -c '^processor' /proc/cpuinfo) DEFAULT_LOG="./report-kernel-patch-verify.txt" DEFAULT_TMPDIR="/tmp" @@ -83,10 +83,10 @@ run_test() { TEST=$1 shift echo -e "\tRunning test: $TEST ($LOG_EXT)" - SSEC=`date "+%s"` + SSEC=$(date "+%s") eval $TEST $* 2>$LOG_DIR/$TEST-$LOG_EXT - ESEC=`date "+%s"` - DELTA=`expr $ESEC - $SSEC` + ESEC=$(date "+%s") + DELTA=$((ESEC - SSEC)) echo "$DELTA seconds: completed $TEST" } @@ -109,7 +109,7 @@ get_sorted_existing_files() echo return fi - for i in `(ls -d $* 2>/dev/null) | sort` + for i in $((ls -d $* 2>/dev/null) | sort) do if [ -f "$i" ]; then test_files="$test_files $i" @@ -125,13 +125,13 @@ ptest_am() { } ptest_check() { - ($KDIR/scripts/checkpatch.pl --strict $1 --max-line-length=$LINE_LENGTH |grep -v `basename $1`|grep -v "^$"|grep -v "^total"|grep -v "^NOTE:")1>&2 + ($KDIR/scripts/checkpatch.pl --strict $1 --max-line-length=$LINE_LENGTH |grep -v $(basename $1)|grep -v "^$"|grep -v "^total"|grep -v "^NOTE:")1>&2 } ################### # Basic tests to run on the files impacted by the patch ftest_check_kdoc() { - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then ((($KDIR/scripts/kernel-doc $test_files >/dev/null) 2>&1)|cut -d ':' -f1,3-) 1>&2 @@ -139,14 +139,14 @@ ftest_check_kdoc() { } ftest_check_includes() { - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then $KDIR/scripts/checkincludes.pl $test_files 1>&2 fi } ftest_check_headerdeps() { - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then $KDIR/scripts/headerdep.pl $test_files 1>&2 fi @@ -154,13 +154,13 @@ ftest_check_headerdeps() { ytest_dt_binding_check() { if [ $UBOOT_TESTING -eq 0 ]; then - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) for test_file in $test_files do # If adding a new file if [ -f "$test_file" ]; then rm -f Documentation/devicetree/bindings/processed-schema-examples.json - D=`dirname $test_file` + D=$(dirname $test_file) rm -f $D/*.example.* kmake_single dt_binding_check DT_CHECKER_FLAGS=-m DT_SCHEMA_FILES=$test_file>/dev/null fi @@ -178,8 +178,8 @@ ytest_dtbs_check() { # Re-Build all the dtbs to get a list (Ignore log) kmake dtbs 2>&1 >/dev/null - all_dtb_files=`find . -iname *.dtb` - test_files=`get_sorted_existing_files $all_dtb_files` + all_dtb_files=$(find . -iname *.dtb) + test_files=$(get_sorted_existing_files $all_dtb_files) if [ -z "$test_files" ]; then return fi @@ -196,7 +196,7 @@ ytest_dtbs_check() { DTB_FILTER_LIST="property_name_chars_strict" dtest_build_dtb() { if [ $UBOOT_TESTING -eq 0 ]; then - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -z "$test_files" ]; then return fi @@ -205,7 +205,7 @@ dtest_build_dtb() { fi for test_file in $test_files do - D=`dirname $test_file` + D=$(dirname $test_file) rm -f $D/*.dtb done rm -f Documentation/devicetree/bindings/processed-schema-examples.json @@ -216,13 +216,13 @@ dtest_build_dtb() { dtest_build_dtb_to_dts() { if [ $UBOOT_TESTING -eq 0 ]; then - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -z "$test_files" ]; then return fi for test_file in $test_files do - D=`dirname $test_file` + D=$(dirname $test_file) rm -f $D/*.dtb done rm -f Documentation/devicetree/bindings/processed-schema-examples.json @@ -231,9 +231,9 @@ dtest_build_dtb_to_dts() { TEST_DTBS_FULL="" for test_file in $test_files do - D=`dirname $test_file` - TEST_DTBS=`ls $D/*.dtb` - TEST_DTBS_FULL=`echo $TEST_DTBS_FULL $TEST_DTBS| tr ' ' '\n'|sort -u` + D=$(dirname $test_file) + TEST_DTBS=$(ls $D/*.dtb) + TEST_DTBS_FULL=$(echo $TEST_DTBS_FULL $TEST_DTBS| tr ' ' '\n'|sort -u) done for dtb in $TEST_DTBS_FULL do @@ -244,13 +244,13 @@ dtest_build_dtb_to_dts() { dtest_dtbs_check() { if [ $UBOOT_TESTING -eq 0 ]; then - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -z "$test_files" ]; then return fi for test_file in $test_files do - D=`dirname $test_file` + D=$(dirname $test_file) rm -f $D/*.dtb $D/*.yaml done rm -f Documentation/devicetree/bindings/processed-schema-examples.json @@ -266,7 +266,7 @@ btest_mrproper() { } btest_basic() { - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then rm $test_files (((kmake_single $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4- | grep -v "^make$") 1>&2 @@ -274,21 +274,21 @@ btest_basic() { } btest_sparse() { - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then (((kmake_single C=2 $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4-) |grep -v "^mv$" |grep -v "^make$" | grep -v "__ksymtab" 1>&2 fi } btest_smatch() { - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then kmake_single CHECK="$SMATCH" C=2 $test_files | egrep '(warn|error):' 1>&2 fi } btest_cocci() { - test_files=`get_sorted_existing_files $*` + test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then kmake_single C=2 CHECK="scripts/coccicheck" MODE=report $test_files >/dev/null fi @@ -404,10 +404,10 @@ report_tests_end() { test_patch() { patch=$1 - cfiles=`diffstat -lp1 $patch|grep -P "\.c$"|sort` - ofiles=`diffstat -lp1 $patch|grep -P "\.[Sc]$"|sort|sed -e "s/[Sc]$/o/g"` - yfiles=`diffstat -lp1 $patch|grep -P "\.yaml$"|sort` - dfiles=`diffstat -lp1 $patch|grep "boot/dts"|grep -v Makefile|sort` + cfiles=$(diffstat -lp1 $patch|grep -P "\.c$"|sort) + ofiles=$(diffstat -lp1 $patch|grep -P "\.[Sc]$"|sort|sed -e "s/[Sc]$/o/g") + yfiles=$(diffstat -lp1 $patch|grep -P "\.yaml$"|sort) + dfiles=$(diffstat -lp1 $patch|grep "boot/dts"|grep -v Makefile|sort) # Run sequential tests TESTS_P_SET="ptest_am ptest_check" @@ -518,12 +518,12 @@ test_patch() { } report_patch() { - Subject=`grep "^Subject" $1` - log_marker "::test results START " `basename $1` "::" + Subject=$(grep "^Subject" $1) + log_marker "::test results START " $(basename $1) "::" log_me "Subject: $Subject" - echo -en "\n"`basename $1` "Tests: ">>$LOG_SUMMARY_FILE + echo -en "\n"$(basename $1) "Tests: ">>$LOG_SUMMARY_FILE report_tests defconfig btest_kbuild $TESTS_C_SET $TESTS_B_SET $TESTS_P_SET $TESTS_Y_SET $TESTS_D_SET - log_marker "::test results END" `basename $1` "::" + log_marker "::test results END" $(basename $1) "::" } ################### @@ -553,7 +553,7 @@ on_exit() { git checkout $CURRENT_BRANCH 2>/dev/null fi if [ -n "$TEST_BRANCH_NAME" ]; then - bexists=`git branch|grep "$TEST_BRANCH_NAME" 2>/dev/null` + bexists=$(git branch|grep "$TEST_BRANCH_NAME" 2>/dev/null) if [ -n "$bexists" ]; then echo "Cleaning up testing branch" git branch -D $TEST_BRANCH_NAME @@ -600,7 +600,7 @@ report_tests() { do diff_log=$TEST_DIR/$test-diff if [ -f $diff_log ]; then - size=`stat --format "%s" $diff_log` + size=$(stat --format "%s" $diff_log) if [ $size -ne 0 ]; then log_me "$test FAILED?" PASS=0 @@ -617,7 +617,7 @@ report_tests() { do diff_log=$TEST_DIR/$test-diff if [ -f $diff_log ]; then - size=`stat --format "%s" $diff_log` + size=$(stat --format "%s" $diff_log) if [ $size -ne 0 ]; then log_marker "$test results:" cat $diff_log >>$LOG_FILE @@ -654,20 +654,20 @@ report_end() { echo >>$LOG_FILE log_marker - END_DATE=`date` - END_SEC=`date "+%s"` - DELTA=`expr $END_SEC - $START_SEC` + END_DATE=$(date) + END_SEC=$(date "+%s") + DELTA=$((END_SEC - START_SEC)) log_marker "Test duration: $DELTA seconds (Started $START_DATE, ended $END_DATE)" if [ -f "$LOG_SUMMARY_FILE" ]; then echo -e "\e[106m\e[4m\e[1mTest Summary:\e[0m" fail=0 while read ln do - empty=`echo $ln |wc -c` + empty=$(echo $ln |wc -c) # Colored reporting to ensure people dont miss errors # See http://misc.flogisoft.com/bash/tip_colors_and_formatting if [ $empty -gt 2 ]; then - pass=`echo $ln|grep "Passed(ALL)"` + pass=$(echo $ln|grep "Passed(ALL)") if [ -z "$pass" ]; then # Red back, white foreground echo -e "\e[1m\e[97m\e[101m$ln\e[0m" @@ -697,7 +697,7 @@ check_missing_application() { for i in $APPS_NEEDED do if [ "$i" = "smatch" ]; then - i=`cat $SMATCH|grep smatch|cut -d ' ' -f1` + i=$(cat $SMATCH|grep smatch|cut -d ' ' -f1) if [ -z "$i" ]; then i=smatch fi @@ -897,8 +897,8 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do usage "Patch Directory $PATCH_DIR does not exist?" exit 1; fi - PATCHES=`ls $PATCH_DIR/*.patch|grep -v "$COVER_LETTER"|xargs realpath` - PATCHCOUNT=`ls $PATCHES|wc -l` + PATCHES=$(ls $PATCH_DIR/*.patch|grep -v "$COVER_LETTER"|xargs realpath) + PATCHCOUNT=$(ls $PATCHES|wc -l) if [ $PATCHCOUNT -eq 0 ]; then usage "Patch directory $PATCH_DIR has no patches?" exit 1; @@ -917,7 +917,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do usage "cannot use -t with other options" exit 1; fi - CHECK=`git branch|grep $TEST_BRANCH 2>/dev/null` + CHECK=$(git branch|grep $TEST_BRANCH 2>/dev/null) if [ -z "$CHECK" ]; then usage "Test branch $TEST_BRANCH does not exist?" exit 1 @@ -955,8 +955,8 @@ if [ $? -ne 0 ]; then exit 2 fi -GN=`git config --get user.name` -GE=`git config --get user.email` +GN=$(git config --get user.name) +GE=$(git config --get user.email) if [ -z "$GE" ] || [ -z "$GN" ]; then echo "We need to know who you are to proceed, please check 'git config -l' and fix via:" echo 'git config --global user.email "you@example.com"' @@ -992,9 +992,9 @@ fi if [ -z "$TEST_B_DIR" ]; then TEST_B_DIR=$DEFAULT_TMPDIR fi -KDIR=`pwd` +KDIR=$(pwd) -CURRENT_BRANCH=`git branch | grep '^*' | cut -d " " -f 2` +CURRENT_BRANCH=$(git branch | grep '^*' | cut -d " " -f 2) # if we have base or testing branch missing, populate the other as the current branch if [ -n "$TEST_BRANCH" ] && [ -z "$BASE_BRANCH" ]; then BASE_BRANCH=$CURRENT_BRANCH @@ -1014,7 +1014,7 @@ if [ ! -e ".config" ] && [ -z "$DEFCONFIG" ]; then fi # lets do some basic verification -gdiff=`git diff` +gdiff=$(git diff) if [ -n "$gdiff" ]; then usage "git diff returned data.. you may want to do git reset --hard or stash changes" exit 3 @@ -1025,8 +1025,8 @@ if [ "$CURRENT_BRANCH" = "(no" ]; then exit 3 fi -GIT_RM_DIR=`git rev-parse --git-path rebase-merge` -GIT_RA_DIR=`git rev-parse --git-path rebase-apply` +GIT_RM_DIR=$(git rev-parse --git-path rebase-merge) +GIT_RA_DIR=$(git rev-parse --git-path rebase-apply) if [ -e "$GIT_RM_DIR" ] || [ -e "$GIT_RA_DIR" ]; then usage "$GIT_RA_DIR or $GIT_RM_DIR exists - implying rebase or am in progress. please cleanup to proceed - 'git am --abort;git rebase --abort' perhaps?" exit 3 @@ -1067,8 +1067,8 @@ fi if [ -n "$TEST_BRANCH" ]; then git format-patch --no-cover-letter -M -C -o $PATCHD $BASE_BRANCH..$TEST_BRANCH >/dev/null - PATCHES=`realpath $PATCHD/*.patch|grep -v "$COVER_LETTER"` - PATCHCOUNT=`ls $PATCHES|wc -l` + PATCHES=$(realpath $PATCHD/*.patch|grep -v "$COVER_LETTER") + PATCHCOUNT=$(ls $PATCHES|wc -l) if [ $PATCHCOUNT -eq 0 ]; then usage "$BASE_BRANCH..$TEST_BRANCH generated no patches!" exit 4; @@ -1082,30 +1082,30 @@ if [ -e "$LOG_FILE" ]; then mv $LOG_FILE $LOG_FILE.bak fi -START_DATE=`date` -START_SEC=`date "+%s"` +START_DATE=$(date) +START_SEC=$(date "+%s") #=========== MAIN TEST TRIGGER LOOP ========= tests_start -PATCHES=`realpath $PATCHD/*.patch|grep -v "$COVER_LETTER"` -PATCHCOUNT=`ls $PATCHES|wc -l` +PATCHES=$(realpath $PATCHD/*.patch|grep -v "$COVER_LETTER") +PATCHCOUNT=$(ls $PATCHES|wc -l) PATCH_NUM=1 EST_TOTAL="unknown" ETA_REMAIN="unknown" DELTAP="unknown" -STARTP_SEC=`date "+%s"` +STARTP_SEC=$(date "+%s") for patch in $PATCHES do - echo "Testing Patch ($PATCH_NUM/$PATCHCOUNT):" `basename $patch` "$DELTAP seconds elapsed, estimated: remaining $ETA_REMAIN / total $EST_TOTAL seconds" + echo "Testing Patch ($PATCH_NUM/$PATCHCOUNT):" "$(basename "$patch")" "$DELTAP seconds elapsed, estimated: remaining $ETA_REMAIN / total $EST_TOTAL seconds" test_patch $patch report_patch $patch - NOW_SEC=`date "+%s"` - DELTAP=`expr $NOW_SEC - $STARTP_SEC` - AVG=`expr $DELTAP / $PATCH_NUM` - EST_TOTAL=`expr $AVG \* $PATCHCOUNT` - ETA_REMAIN=`expr $EST_TOTAL - $DELTAP` - PATCH_NUM=`expr $PATCH_NUM + 1` + NOW_SEC=$(date "+%s") + DELTAP=$((NOW_SEC - STARTP_SEC)) + AVG=$((DELTAP / PATCH_NUM)) + EST_TOTAL=$((AVG * PATCHCOUNT)) + ETA_REMAIN=$((EST_TOTAL - DELTAP)) + PATCH_NUM=$((PATCH_NUM + 1)) done tests_end From 208ebfe0ba56bc10048afe73ca0e7a833b47fbf0 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 16:52:42 -0600 Subject: [PATCH 18/34] kernel_patch_verify: check command exit code directly Check exit code directly with e.g. 'if ! mycmd;', not indirectly with $?. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 3419fbb..66daf98 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -702,8 +702,8 @@ check_missing_application() { i=smatch fi fi - which "$i" > /dev/null - if [ $? -ne 0 ]; then + + if ! which "$i" > /dev/null; then APPS_MISSING="$APPS_MISSING $i" fi done @@ -776,8 +776,8 @@ usage() { echo -e "\t $APP_NAME -d -1" >&2 echo "Example for usage 8: on a cross_compiled ARM build using defaults,15 patches" >&2 echo -e "\t $APP_NAME -d -n 15" >&2 - check_missing_application - if [ $? -ne 0 ]; then + + if ! check_missing_application; then recommend_missing_application fi } @@ -949,8 +949,7 @@ if [ -n "${CROSS_COMPILE}" ]; then APPS_NEEDED="$APPS_NEEDED ${CROSS_COMPILE}gcc" fi -check_missing_application -if [ $? -ne 0 ]; then +if ! check_missing_application; then usage "Missing apps" exit 2 fi From 1664d2e7c878b79dabdb15fd78e12c2ab8bc992c Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 17:08:52 -0600 Subject: [PATCH 19/34] kernel_patch_verify: rework the usage section Use printf and some short templates to remove some redundant sections. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 101 ++++++++++++++++++++++++-------------------- 1 file changed, 56 insertions(+), 45 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 66daf98..85db2ce 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -733,54 +733,65 @@ APP_NAME=$0 ################### # Help usage() { - echo "$*" >&2 - echo "Usage: $APP_NAME [-d | -V] [-j CPUs] [-B build_target] [-T tmp_dir_base] [-l logfile] [-C] [-c defconfig_name] [-n N][-1..9]|[-p patch_dir]|[-b base_branch [-t head_branch]] [-S smatch_script] -U -Z" >&2 - echo -e "\t-d: if not already defined, use CROSS_COMPILE=$DEF_CROSS_COMPILE, ARCH=$DEF_ARCH, and builds for '$KP_TARGETS $DEF_BUILDTARGETS' build targets" >&2 - echo -e "\t-V: (default armV8 targets) if not already defined, use CROSS_COMPILE=$DEF_V8_CROSS_COMPILE, ARCH=$DEF_V8_ARCH, and builds for '$KP_TARGETS $DEF_V8_BUILDTARGETS' build targets" >&2 - echo -e "\t-j CPUs: override default CPUs count with build (default is $DEF_CPUS)" >&2 - echo -e "\t-B build_target: override default build target and use provided build_target" >&2 - echo -e "\t-T temp_dir_base: temporary directory base (default is $DEFAULT_TMPDIR)" >&2 - echo -e "\t-l logfile: report file (defaults to $DEFAULT_LOG)" >&2 - echo -e "\t-L Use llvm to build 'LLVM=1 CC='$ccache clang''" >&2 - echo -e "\t-C: run Complete tests(WARNING: could take significant time!)" >&2 - echo -e "\t-c defconfig: name (default uses current .config + olddefconfig)" >&2 - echo -e "\t-[1..9]: test the tip of current branch (1 to 9 number of patches)" >&2 - echo -e "\t-n N: test the tip of current branch with 'N' number of patches" >&2 - echo -e "\t-p patch_dir: which directory to take patches from (expects sorted in order)" >&2 - echo -e "\t-b base_branch: test patches from base_branch" >&2 - echo -e "\t-t test_branch: optionally used with -b, till head branch, if not provided, along with -b, default will be tip of current branch" >&2 - echo -e "\t-U : Do u-boot basic sanity tests" >&2 - echo -e "\t-Z : Dont filter dtb warnings ($DTB_FILTER_LIST)" >&2 - echo -e "\t-m : maximum line length number to be passed on to checkpatch.pl" >&2 - echo -e "\t-S smatch_script : Provide a custom smatch_script instead of creating our own" >&2 - echo >&2 - echo "NOTE: only one of -1, -c, -p or (-b,-t) should be used - but at least one of these should be used" >&2 - echo "NOTE: cannot have a diff pending OR be on a dangling branch base_branch should exist as well" >&2 - echo >&2 - echo "Example usage 1: verify last commmitted patch" >&2 - echo -e "\t $APP_NAME -1" >&2 - echo "Example usage 2: verify on top of current branch patches from location ~/tmp/test-patches" >&2 - echo -e "\t $APP_NAME -p ~/tmp/test-patches" >&2 - echo "Example usage 3: verify *from* branch 'base_branch' till current branch" >&2 - echo -e "\t $APP_NAME -b base_branch" >&2 - echo "Example usage 4: verify from current branch, all patches *until* 'test_branch'" >&2 - echo -e "\t $APP_NAME -t test_branch" >&2 - echo "Example usage 5: verify from branch, all patches from 'base_branch' until 'test_branch'" >&2 - echo -e "\t $APP_NAME -b base_branch -t test_branch" >&2 - echo "Example usage 6: verify from branch Complete tests, all patches from 'base_branch' until 'test_branch'" >&2 - echo -e "\t $APP_NAME -b base_branch -t test_branch -C" >&2 - echo >&2 - echo "Example for usage 7: on a native x86 build using make, gcc and bzImage, 1 patch" >&2 - echo -e "\t $APP_NAME -B bzImage -1" >&2 - echo "Example for usage 7: on a cross_compiled ARM build using defaults, 1 patch" >&2 - echo -e "\t $APP_NAME -d -1" >&2 - echo "Example for usage 8: on a cross_compiled ARM build using defaults,15 patches" >&2 - echo -e "\t $APP_NAME -d -n 15" >&2 - + printf '%s\n' "$*" + + printf '%s\n' \ + '' \ + "Usage: $APP_NAME [-d | -V] [-j CPUs] [-B build_target] [-T tmp_dir_base] [-l logfile] [-C] [-c defconfig_name] [-n N][-1..9]|[-p patch_dir]|[-b base_branch [-t head_branch]] [-S smatch_script] -U -Z" \ + '' + + printf '\t%s\n' \ + "-d: if not already defined, use CROSS_COMPILE=$DEF_CROSS_COMPILE, ARCH=$DEF_ARCH, and builds for '$KP_TARGETS $DEF_BUILDTARGETS' build targets" \ + "-V: (default armV8 targets) if not already defined, use CROSS_COMPILE=$DEF_V8_CROSS_COMPILE, ARCH=$DEF_V8_ARCH, and builds for '$KP_TARGETS $DEF_V8_BUILDTARGETS' build targets" \ + "-j CPUs: override default CPUs count with build (default is $DEF_CPUS)" \ + "-B build_target: override default build target and use provided build_target" \ + "-T temp_dir_base: temporary directory base (default is $DEFAULT_TMPDIR)" \ + "-l logfile: report file (defaults to $DEFAULT_LOG)" \ + "-L Use llvm to build 'LLVM=1 CC='$ccache clang''" \ + "-C: run Complete tests(WARNING: could take significant time!)" \ + "-c defconfig: name (default uses current .config + olddefconfig)" \ + "-[1..9]: test the tip of current branch (1 to 9 number of patches)" \ + "-n N: test the tip of current branch with 'N' number of patches" \ + "-p patch_dir: which directory to take patches from (expects sorted in order)" \ + "-b base_branch: test patches from base_branch" \ + "-t test_branch: optionally used with -b, till head branch, if not provided, along with -b, default will be tip of current branch" \ + "-U : Do u-boot basic sanity tests" \ + "-Z : Dont filter dtb warnings ($DTB_FILTER_LIST)" \ + "-m : maximum line length number to be passed on to checkpatch.pl" \ + "-S smatch_script : Provide a custom smatch_script instead of creating our own" + + printf '%s\n' \ + '' \ + "NOTE: only one of -1, -c, -p or (-b,-t) should be used - but at least one of these should be used" \ + "NOTE: cannot have a diff pending OR be on a dangling branch base_branch should exist as well" \ + '' + + printf '%s\n\t%s\n' \ + "Example usage 1: verify last commmitted patch" \ + "$APP_NAME -1" \ + "Example usage 2: verify on top of current branch patches from location ~/tmp/test-patches" \ + "$APP_NAME -p ~/tmp/test-patches" \ + "Example usage 3: verify *from* branch 'base_branch' till current branch" \ + "$APP_NAME -b base_branch" \ + "Example usage 4: verify from current branch, all patches *until* 'test_branch'" \ + "$APP_NAME -t test_branch" \ + "Example usage 5: verify from branch, all patches from 'base_branch' until 'test_branch'" \ + "$APP_NAME -b base_branch -t test_branch" \ + "Example usage 6: verify from branch Complete tests, all patches from 'base_branch' until 'test_branch'" \ + "$APP_NAME -b base_branch -t test_branch -C" \ + "Example usage 7: on a native x86 build using make, gcc and bzImage, 1 patch" \ + "$APP_NAME -B bzImage -1" \ + "Example usage 7: on a cross_compiled ARM build using defaults, 1 patch" \ + "$APP_NAME -d -1" \ + "Example usage 8: on a cross_compiled ARM build using defaults,15 patches" \ + "$APP_NAME -d -n 15" + + printf '%s\n' '' + if ! check_missing_application; then recommend_missing_application fi -} +} >&2 ORIDE=0 DTB_NOSKIP=0 From 1aed026d791c05a917397158fc8c0f66daf5cbcf Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 17:18:07 -0600 Subject: [PATCH 20/34] kernel_patch_verify: tweak grep strings Use static strings for the grep expressions not using variables. Make sure some reserved characters are escaped properly. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 85db2ce..9f1ccdf 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -125,7 +125,7 @@ ptest_am() { } ptest_check() { - ($KDIR/scripts/checkpatch.pl --strict $1 --max-line-length=$LINE_LENGTH |grep -v $(basename $1)|grep -v "^$"|grep -v "^total"|grep -v "^NOTE:")1>&2 + ($KDIR/scripts/checkpatch.pl --strict $1 --max-line-length=$LINE_LENGTH |grep -v $(basename $1)|grep -v '^$'|grep -v '^total'|grep -v '^NOTE:')1>&2 } ################### @@ -186,7 +186,7 @@ ytest_dtbs_check() { rm -f $test_files rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - (((make -j$KM_CPUS dtbs_check > /dev/null) 2>&1)|grep -v "^\s\s*"|sort -u) 1>&2 + (((make -j$KM_CPUS dtbs_check > /dev/null) 2>&1)|grep -v '^\s\s*'|sort -u) 1>&2 fi } @@ -210,7 +210,7 @@ dtest_build_dtb() { done rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - (((kmake_single W=2 dtbs > /dev/null) 2>&1)|cut -d ':' -f1,4- | grep -v "^make$"|grep -v "$DTB_FILTER_LIST") 1>&2 + (((kmake_single W=2 dtbs > /dev/null) 2>&1)|cut -d ':' -f1,4- | grep -v '^make$'|grep -v "$DTB_FILTER_LIST") 1>&2 fi } @@ -255,7 +255,7 @@ dtest_dtbs_check() { done rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - (((make -j$KM_CPUS dtbs_check > /dev/null) 2>&1)|grep -v "^\s\s*"|sort -u) 1>&2 + (((make -j$KM_CPUS dtbs_check > /dev/null) 2>&1)|grep -v '^\s\s*'|sort -u) 1>&2 fi } @@ -269,14 +269,14 @@ btest_basic() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then rm $test_files - (((kmake_single $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4- | grep -v "^make$") 1>&2 + (((kmake_single $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4- | grep -v '^make$') 1>&2 fi } btest_sparse() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - (((kmake_single C=2 $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4-) |grep -v "^mv$" |grep -v "^make$" | grep -v "__ksymtab" 1>&2 + (((kmake_single C=2 $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4-) |grep -v '^mv$' |grep -v '^make$' | grep -v '__ksymtab' 1>&2 fi } @@ -316,7 +316,7 @@ btest_kbuild() { else kmake C=1 $KP_TARGETS $MODULES>/dev/null 2>$TEST_DIR/err_stuff # Get rid of standard sparse mess with u-boot - cat $TEST_DIR/err_stuff|grep -v "efi.h"|grep -v "version.c" |grep -v "_u_boot_list_" 1>&2 + cat $TEST_DIR/err_stuff|grep -v 'efi.h'|grep -v 'version.c' |grep -v '_u_boot_list_' 1>&2 fi } @@ -404,10 +404,10 @@ report_tests_end() { test_patch() { patch=$1 - cfiles=$(diffstat -lp1 $patch|grep -P "\.c$"|sort) - ofiles=$(diffstat -lp1 $patch|grep -P "\.[Sc]$"|sort|sed -e "s/[Sc]$/o/g") - yfiles=$(diffstat -lp1 $patch|grep -P "\.yaml$"|sort) - dfiles=$(diffstat -lp1 $patch|grep "boot/dts"|grep -v Makefile|sort) + cfiles=$(diffstat -lp1 $patch|grep -P '\.c$'|sort) + ofiles=$(diffstat -lp1 $patch|grep -P '\.[Sc]$'|sort|sed -e "s/[Sc]$/o/g") + yfiles=$(diffstat -lp1 $patch|grep -P '\.yaml$'|sort) + dfiles=$(diffstat -lp1 $patch|grep 'boot/dts'|grep -v 'Makefile'|sort) # Run sequential tests TESTS_P_SET="ptest_am ptest_check" @@ -518,7 +518,7 @@ test_patch() { } report_patch() { - Subject=$(grep "^Subject" $1) + Subject=$(grep '^Subject' $1) log_marker "::test results START " $(basename $1) "::" log_me "Subject: $Subject" echo -en "\n"$(basename $1) "Tests: ">>$LOG_SUMMARY_FILE @@ -650,7 +650,7 @@ report_end() { echo >>$LOG_FILE done echo "version of dtschema python3 package:" >>$LOG_FILE - python3 -m pip list|grep dtschema >> $LOG_FILE + python3 -m pip list|grep 'dtschema' >> $LOG_FILE echo >>$LOG_FILE log_marker @@ -667,7 +667,7 @@ report_end() { # Colored reporting to ensure people dont miss errors # See http://misc.flogisoft.com/bash/tip_colors_and_formatting if [ $empty -gt 2 ]; then - pass=$(echo $ln|grep "Passed(ALL)") + pass=$(echo $ln|grep 'Passed(ALL)') if [ -z "$pass" ]; then # Red back, white foreground echo -e "\e[1m\e[97m\e[101m$ln\e[0m" @@ -697,7 +697,7 @@ check_missing_application() { for i in $APPS_NEEDED do if [ "$i" = "smatch" ]; then - i=$(cat $SMATCH|grep smatch|cut -d ' ' -f1) + i=$(cat $SMATCH|grep 'smatch'|cut -d ' ' -f1) if [ -z "$i" ]; then i=smatch fi @@ -928,7 +928,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do usage "cannot use -t with other options" exit 1; fi - CHECK=$(git branch|grep $TEST_BRANCH 2>/dev/null) + CHECK=$(git branch|grep "$TEST_BRANCH" 2>/dev/null) if [ -z "$CHECK" ]; then usage "Test branch $TEST_BRANCH does not exist?" exit 1 @@ -1004,7 +1004,7 @@ if [ -z "$TEST_B_DIR" ]; then fi KDIR=$(pwd) -CURRENT_BRANCH=$(git branch | grep '^*' | cut -d " " -f 2) +CURRENT_BRANCH=$(git branch | grep '^\*' | cut -d " " -f 2) # if we have base or testing branch missing, populate the other as the current branch if [ -n "$TEST_BRANCH" ] && [ -z "$BASE_BRANCH" ]; then BASE_BRANCH=$CURRENT_BRANCH From a602dfad9ca8f8c59bbdbf6470a35381c9e50537 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 17:41:49 -0600 Subject: [PATCH 21/34] kernel_patch_verify: subshell execution needs padding These instances of subshell execution have ((, which is the starting parameter for arithmetic operations. Make sure everything's padded well enough to prevent misinterpretation. Shells disambiguate (( differently or not at all. For subshell, add spaces around ( . For ((, fix parsing errors. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 9f1ccdf..30e940e 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -109,7 +109,7 @@ get_sorted_existing_files() echo return fi - for i in $((ls -d $* 2>/dev/null) | sort) + for i in $( (ls -d $* 2>/dev/null) | sort) do if [ -f "$i" ]; then test_files="$test_files $i" @@ -125,7 +125,7 @@ ptest_am() { } ptest_check() { - ($KDIR/scripts/checkpatch.pl --strict $1 --max-line-length=$LINE_LENGTH |grep -v $(basename $1)|grep -v '^$'|grep -v '^total'|grep -v '^NOTE:')1>&2 + ( $KDIR/scripts/checkpatch.pl --strict $1 --max-line-length=$LINE_LENGTH |grep -v $(basename $1)|grep -v '^$'|grep -v '^total'|grep -v '^NOTE:' )1>&2 } ################### @@ -134,7 +134,7 @@ ftest_check_kdoc() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - ((($KDIR/scripts/kernel-doc $test_files >/dev/null) 2>&1)|cut -d ':' -f1,3-) 1>&2 + ( ( ( $KDIR/scripts/kernel-doc $test_files >/dev/null ) 2>&1 ) | cut -d ':' -f1,3- ) 1>&2 fi } @@ -186,7 +186,7 @@ ytest_dtbs_check() { rm -f $test_files rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - (((make -j$KM_CPUS dtbs_check > /dev/null) 2>&1)|grep -v '^\s\s*'|sort -u) 1>&2 + ( ( ( make -j$KM_CPUS dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 fi } @@ -210,7 +210,7 @@ dtest_build_dtb() { done rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - (((kmake_single W=2 dtbs > /dev/null) 2>&1)|cut -d ':' -f1,4- | grep -v '^make$'|grep -v "$DTB_FILTER_LIST") 1>&2 + ( ( ( kmake_single W=2 dtbs > /dev/null ) 2>&1 )|cut -d ':' -f1,4- | grep -v '^make$'|grep -v "$DTB_FILTER_LIST" ) 1>&2 fi } @@ -255,7 +255,7 @@ dtest_dtbs_check() { done rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - (((make -j$KM_CPUS dtbs_check > /dev/null) 2>&1)|grep -v '^\s\s*'|sort -u) 1>&2 + ( ( ( make -j$KM_CPUS dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 fi } @@ -269,14 +269,14 @@ btest_basic() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then rm $test_files - (((kmake_single $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4- | grep -v '^make$') 1>&2 + ( ( ( kmake_single $test_files > /dev/null ) 2>&1 )|cut -d ':' -f1,4- | grep -v '^make$' ) 1>&2 fi } btest_sparse() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - (((kmake_single C=2 $test_files > /dev/null) 2>&1)|cut -d ':' -f1,4-) |grep -v '^mv$' |grep -v '^make$' | grep -v '__ksymtab' 1>&2 + ( ( ( kmake_single C=2 $test_files > /dev/null ) 2>&1 )|cut -d ':' -f1,4- ) |grep -v '^mv$' |grep -v '^make$' | grep -v '__ksymtab' 1>&2 fi } From e1895b339641f15a10d27112dea7991a1e88a2a8 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sat, 9 Mar 2024 17:58:56 -0600 Subject: [PATCH 22/34] kernel_patch_verify: standardize patches logic Use glob instead of ls and print the files we get from that instead of attempting to reindexing them. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 30e940e..c331ff6 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -908,9 +908,9 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do usage "Patch Directory $PATCH_DIR does not exist?" exit 1; fi - PATCHES=$(ls $PATCH_DIR/*.patch|grep -v "$COVER_LETTER"|xargs realpath) - PATCHCOUNT=$(ls $PATCHES|wc -l) - if [ $PATCHCOUNT -eq 0 ]; then + PATCHES=$(realpath "$PATCH_DIR"/*.patch|grep -v "$COVER_LETTER") + PATCHCOUNT=$(echo "$PATCHES" |wc -l) + if [ "$PATCHCOUNT" -eq 0 ]; then usage "Patch directory $PATCH_DIR has no patches?" exit 1; fi @@ -1061,7 +1061,7 @@ fi # First create a list of patches to test.. if [ -n "$TEST_TOP" ]; then - if ! [[ x$PATCHCOUNT =~ ^x[0-9]+$ ]] ; then + if ! [[ "$PATCHCOUNT" =~ ^[0-9]+$ ]] ; then usage "error: requested number of patches '$PATCHCOUNT' Not a number" exit 4 fi @@ -1077,8 +1077,8 @@ fi if [ -n "$TEST_BRANCH" ]; then git format-patch --no-cover-letter -M -C -o $PATCHD $BASE_BRANCH..$TEST_BRANCH >/dev/null - PATCHES=$(realpath $PATCHD/*.patch|grep -v "$COVER_LETTER") - PATCHCOUNT=$(ls $PATCHES|wc -l) + PATCHES=$(realpath "$PATCHD"/*.patch|grep -v "$COVER_LETTER") + PATCHCOUNT=$(echo "$PATCHES" |wc -l) if [ $PATCHCOUNT -eq 0 ]; then usage "$BASE_BRANCH..$TEST_BRANCH generated no patches!" exit 4; @@ -1098,8 +1098,8 @@ START_SEC=$(date "+%s") #=========== MAIN TEST TRIGGER LOOP ========= tests_start -PATCHES=$(realpath $PATCHD/*.patch|grep -v "$COVER_LETTER") -PATCHCOUNT=$(ls $PATCHES|wc -l) +PATCHES=$(realpath "$PATCHD"/*.patch|grep -v "$COVER_LETTER") +PATCHCOUNT=$(echo "$PATCHES" |wc -l) PATCH_NUM=1 EST_TOTAL="unknown" ETA_REMAIN="unknown" From 7cd042e9f6fc93b2610032e7845758133d62ab95 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sun, 10 Mar 2024 00:07:42 -0600 Subject: [PATCH 23/34] kp_common: fix worktree mount logic I know right now docker ignores "-v : " but I do not want to see what happens if this ever changes. Besides, we can't do anything if we're not working in a git directory anyway. Signed-off-by: Randolph Sapp --- kp_common | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/kp_common b/kp_common index 5c881c3..512c2a4 100644 --- a/kp_common +++ b/kp_common @@ -47,9 +47,13 @@ DOCKER_MOUNT_DIRS+=(-v /opt:/opt) DOCKER_MOUNT_DIRS+=(-v "$CCACHEDIR":/ccache) DOCKER_MOUNT_DIRS+=(-v "$(pwd)":/workdir) +# Check if current directory is a git directory +if ! GIT_WORKTREE_COMMONDIR=$(git rev-parse --git-common-dir); then + exit 1 +fi + # Mount parent directory if its a worktree -GIT_WORKTREE_COMMONDIR=$(git rev-parse --git-common-dir) -if [[ $GIT_WORKTREE_COMMONDIR != ".git" ]]; then +if [ "$GIT_WORKTREE_COMMONDIR" != ".git" ]; then DOCKER_MOUNT_DIRS+=(-v "$GIT_WORKTREE_COMMONDIR":"$GIT_WORKTREE_COMMONDIR") fi From f028394106c54cc203038360cc0ce80541e20018 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Sun, 10 Mar 2024 00:15:46 -0600 Subject: [PATCH 24/34] Makefile: fixup the clean target This just pruned stopped containers and dangling images before removing the built container. Use the official commands for these operations. Signed-off-by: Randolph Sapp --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6efa03e..40b6168 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,8 @@ all: clean: docker container prune; \ - docker image ls|grep none|sed -e "s/\s\s*/ /g"|cut -d ' ' -f3|xargs docker rmi ${IMAGE_TOBUILD} + docker image prune -f; \ + docker rmi ${IMAGE_TOBUILD} deploy: docker push ${REPO}:${IMAGE_TOBUILD} From eeac60bbfd842321cc663d01bedfafc63be68589 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 21:37:31 -0500 Subject: [PATCH 25/34] kernel_patch_verify: quote damn near everything Quote everything currently not relying on word splitting. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 274 ++++++++++++++++++++++---------------------- 1 file changed, 137 insertions(+), 137 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index c331ff6..d297124 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -66,11 +66,11 @@ if [ -z "$KP_TARGETS" ]; then fi kmake_single() { - make "$KM_A" $KP_PARAMS "$KM_C" $KM_L -j1 $* + make "$KM_A" "$KP_PARAMS" "$KM_C" "$KM_L" -j1 "$@" } kmake() { - make "$KM_A" $KP_PARAMS "$KM_C" $KM_L -j$KM_CPUS $* + make "$KM_A" "$KP_PARAMS" "$KM_C" "$KM_L" -j"$KM_CPUS" "$@" } ################### @@ -84,7 +84,7 @@ run_test() { shift echo -e "\tRunning test: $TEST ($LOG_EXT)" SSEC=$(date "+%s") - eval $TEST $* 2>$LOG_DIR/$TEST-$LOG_EXT + "$TEST" "$@" 2> "$LOG_DIR/$TEST-$LOG_EXT" ESEC=$(date "+%s") DELTA=$((ESEC - SSEC)) echo "$DELTA seconds: completed $TEST" @@ -98,7 +98,7 @@ run_test_dummy() { TEST=$1 shift echo -e "\tRunning test: $TEST ($LOG_EXT)" - touch $LOG_DIR/$TEST-$LOG_EXT + touch "$LOG_DIR/$TEST-$LOG_EXT" } get_sorted_existing_files() @@ -109,23 +109,23 @@ get_sorted_existing_files() echo return fi - for i in $( (ls -d $* 2>/dev/null) | sort) + for i in $( (ls -d "$@" 2>/dev/null) | sort) do if [ -f "$i" ]; then test_files="$test_files $i" fi done - echo $test_files + echo "$test_files" } ################### # Basic tests to run on the patch itself ptest_am() { - git am $1 >/dev/null + git am "$1" >/dev/null } ptest_check() { - ( $KDIR/scripts/checkpatch.pl --strict $1 --max-line-length=$LINE_LENGTH |grep -v $(basename $1)|grep -v '^$'|grep -v '^total'|grep -v '^NOTE:' )1>&2 + ( "$KDIR"/scripts/checkpatch.pl --strict "$1" --max-line-length="$LINE_LENGTH" |grep -v "$(basename "$1")" |grep -v '^$'|grep -v '^total'|grep -v '^NOTE:' )1>&2 } ################### @@ -134,42 +134,42 @@ ftest_check_kdoc() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - ( ( ( $KDIR/scripts/kernel-doc $test_files >/dev/null ) 2>&1 ) | cut -d ':' -f1,3- ) 1>&2 + ( ( ( "$KDIR"/scripts/kernel-doc "$test_files" >/dev/null ) 2>&1 ) | cut -d ':' -f1,3- ) 1>&2 fi } ftest_check_includes() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - $KDIR/scripts/checkincludes.pl $test_files 1>&2 + "$KDIR"/scripts/checkincludes.pl "$test_files" 1>&2 fi } ftest_check_headerdeps() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - $KDIR/scripts/headerdep.pl $test_files 1>&2 + "$KDIR"/scripts/headerdep.pl "$test_files" 1>&2 fi } ytest_dt_binding_check() { - if [ $UBOOT_TESTING -eq 0 ]; then + if [ "$UBOOT_TESTING" -eq 0 ]; then test_files=$(get_sorted_existing_files $*) for test_file in $test_files do # If adding a new file if [ -f "$test_file" ]; then rm -f Documentation/devicetree/bindings/processed-schema-examples.json - D=$(dirname $test_file) - rm -f $D/*.example.* - kmake_single dt_binding_check DT_CHECKER_FLAGS=-m DT_SCHEMA_FILES=$test_file>/dev/null + D=$(dirname "$test_file") + rm -f "$D"/*.example.* + kmake_single dt_binding_check DT_CHECKER_FLAGS=-m DT_SCHEMA_FILES="$test_file" >/dev/null fi done fi } ytest_dtbs_check() { - if [ $UBOOT_TESTING -eq 0 ]; then + if [ "$UBOOT_TESTING" -eq 0 ]; then # If we have no yamls to check, nothing to run. if [ -z "$*" ]; then return @@ -178,15 +178,15 @@ ytest_dtbs_check() { # Re-Build all the dtbs to get a list (Ignore log) kmake dtbs 2>&1 >/dev/null - all_dtb_files=$(find . -iname *.dtb) + all_dtb_files=$(find . -iname '*.dtb') test_files=$(get_sorted_existing_files $all_dtb_files) if [ -z "$test_files" ]; then return fi - rm -f $test_files + rm -f "$test_files" rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - ( ( ( make -j$KM_CPUS dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 + ( ( ( make -j"$KM_CPUS" dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 fi } @@ -195,7 +195,7 @@ ytest_dtbs_check() { # by default unless -Z is used. DTB_FILTER_LIST="property_name_chars_strict" dtest_build_dtb() { - if [ $UBOOT_TESTING -eq 0 ]; then + if [ "$UBOOT_TESTING" -eq 0 ]; then test_files=$(get_sorted_existing_files $*) if [ -z "$test_files" ]; then return @@ -205,8 +205,8 @@ dtest_build_dtb() { fi for test_file in $test_files do - D=$(dirname $test_file) - rm -f $D/*.dtb + D=$(dirname "$test_file") + rm -f "$D"/*.dtb done rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null @@ -215,15 +215,15 @@ dtest_build_dtb() { } dtest_build_dtb_to_dts() { - if [ $UBOOT_TESTING -eq 0 ]; then + if [ "$UBOOT_TESTING" -eq 0 ]; then test_files=$(get_sorted_existing_files $*) if [ -z "$test_files" ]; then return fi for test_file in $test_files do - D=$(dirname $test_file) - rm -f $D/*.dtb + D=$(dirname "$test_file") + rm -f "$D"/*.dtb done rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null @@ -231,31 +231,31 @@ dtest_build_dtb_to_dts() { TEST_DTBS_FULL="" for test_file in $test_files do - D=$(dirname $test_file) - TEST_DTBS=$(ls $D/*.dtb) - TEST_DTBS_FULL=$(echo $TEST_DTBS_FULL $TEST_DTBS| tr ' ' '\n'|sort -u) + D=$(dirname "$test_file") + TEST_DTBS=$(ls "$D"/*.dtb) + TEST_DTBS_FULL=$(echo "$TEST_DTBS_FULL" "$TEST_DTBS" | tr ' ' '\n'|sort -u) done for dtb in $TEST_DTBS_FULL do - dtc -I dtb -O dts $dtb >/dev/null + dtc -I dtb -O dts "$dtb" >/dev/null done fi } dtest_dtbs_check() { - if [ $UBOOT_TESTING -eq 0 ]; then + if [ "$UBOOT_TESTING" -eq 0 ]; then test_files=$(get_sorted_existing_files $*) if [ -z "$test_files" ]; then return fi for test_file in $test_files do - D=$(dirname $test_file) - rm -f $D/*.dtb $D/*.yaml + D=$(dirname "$test_file") + rm -f "$D"/*.dtb "$D"/*.yaml done rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null - ( ( ( make -j$KM_CPUS dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 + ( ( ( make -j"$KM_CPUS" dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 fi } @@ -268,29 +268,29 @@ btest_mrproper() { btest_basic() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - rm $test_files - ( ( ( kmake_single $test_files > /dev/null ) 2>&1 )|cut -d ':' -f1,4- | grep -v '^make$' ) 1>&2 + rm "$test_files" + ( ( ( kmake_single "$test_files" > /dev/null ) 2>&1 )|cut -d ':' -f1,4- | grep -v '^make$' ) 1>&2 fi } btest_sparse() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - ( ( ( kmake_single C=2 $test_files > /dev/null ) 2>&1 )|cut -d ':' -f1,4- ) |grep -v '^mv$' |grep -v '^make$' | grep -v '__ksymtab' 1>&2 + ( ( ( kmake_single C=2 "$test_files" > /dev/null ) 2>&1 )|cut -d ':' -f1,4- ) |grep -v '^mv$' |grep -v '^make$' | grep -v '__ksymtab' 1>&2 fi } btest_smatch() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - kmake_single CHECK="$SMATCH" C=2 $test_files | egrep '(warn|error):' 1>&2 + kmake_single CHECK="$SMATCH" C=2 "$test_files" | egrep '(warn|error):' 1>&2 fi } btest_cocci() { test_files=$(get_sorted_existing_files $*) if [ -n "$test_files" ]; then - kmake_single C=2 CHECK="scripts/coccicheck" MODE=report $test_files >/dev/null + kmake_single C=2 CHECK="scripts/coccicheck" MODE=report "$test_files" >/dev/null fi } @@ -311,30 +311,30 @@ btest_headers_check() { } btest_kbuild() { - if [ $UBOOT_TESTING -eq 0 ]; then - kmake C=1 $KP_TARGETS $MODULES>/dev/null + if [ "$UBOOT_TESTING" -eq 0 ]; then + kmake C=1 "$KP_TARGETS" "$MODULES" > /dev/null else - kmake C=1 $KP_TARGETS $MODULES>/dev/null 2>$TEST_DIR/err_stuff + kmake C=1 "$KP_TARGETS" "$MODULES" > /dev/null 2> "$TEST_DIR"/err_stuff # Get rid of standard sparse mess with u-boot - cat $TEST_DIR/err_stuff|grep -v 'efi.h'|grep -v 'version.c' |grep -v '_u_boot_list_' 1>&2 + cat "$TEST_DIR"/err_stuff|grep -v 'efi.h'|grep -v 'version.c' |grep -v '_u_boot_list_' 1>&2 fi } defconfig() { if [ -n "$DEFCONFIG" ]; then - kmake $DEFCONFIG >/dev/null + kmake "$DEFCONFIG" >/dev/null else - cp $TEST_DIR/.config .config + cp "$TEST_DIR"/.config .config kmake olddefconfig >/dev/null fi } build_all_clean() { (kmake clean 2>/dev/null )>/dev/null - kmake_single $KP_TARGETS $MODULES >/dev/null + kmake_single "$KP_TARGETS" "$MODULES" >/dev/null } build_all() { - (kmake $KP_TARGETS $MODULES 2>/dev/null) >/dev/null + (kmake "$KP_TARGETS" "$MODULES" 2>/dev/null) >/dev/null } # executed in sequence @@ -352,19 +352,19 @@ tests_start() { for test_s in $TESTS_ALL_SET do - run_test start $TEST_DIR $test_s + run_test start "$TEST_DIR" "$test_s" done # Run parallel tests PIDS="" for test_s in $TESTS_ALL1_SET do - run_test start $TEST_DIR $test_s & + run_test start "$TEST_DIR" "$test_s" & PIDS="$PIDS $!" done echo "Waiting for PIDs: $PIDS" for pid in $PIDS do - wait $pid + wait "$pid" done PIDS="" @@ -377,37 +377,37 @@ tests_end() { echo "Running END tests.." for test_s in $TESTS_ALL_SET do - run_test end $TEST_DIR $test_s + run_test end "$TEST_DIR" "$test_s" done # Run parallel tests PIDS="" for test_s in $TESTS_ALL1_SET do - run_test start $TEST_DIR $test_s & + run_test start "$TEST_DIR" "$test_s" & PIDS="$PIDS $!" done echo "Waiting for PIDs: $PIDS" for pid in $PIDS do - wait $pid + wait "$pid" done PIDS="" } report_tests_end() { log_marker "::Complete test results START::" - echo -en "\nGeneral Tests: ">>$LOG_SUMMARY_FILE - report_tests $TESTS_ALL_SET $TESTS_ALL1_SET + echo -en "\nGeneral Tests: " >> "$LOG_SUMMARY_FILE" + report_tests "$TESTS_ALL_SET" "$TESTS_ALL1_SET" log_marker "::Complete test results END::" } test_patch() { patch=$1 - cfiles=$(diffstat -lp1 $patch|grep -P '\.c$'|sort) - ofiles=$(diffstat -lp1 $patch|grep -P '\.[Sc]$'|sort|sed -e "s/[Sc]$/o/g") - yfiles=$(diffstat -lp1 $patch|grep -P '\.yaml$'|sort) - dfiles=$(diffstat -lp1 $patch|grep 'boot/dts'|grep -v 'Makefile'|sort) + cfiles=$(diffstat -lp1 "$patch"|grep -P '\.c$'|sort) + ofiles=$(diffstat -lp1 "$patch"|grep -P '\.[Sc]$'|sort|sed -e "s/[Sc]$/o/g") + yfiles=$(diffstat -lp1 "$patch"|grep -P '\.yaml$'|sort) + dfiles=$(diffstat -lp1 "$patch"|grep 'boot/dts'|grep -v 'Makefile'|sort) # Run sequential tests TESTS_P_SET="ptest_am ptest_check" @@ -440,90 +440,90 @@ test_patch() { echo "Tests to run on Patch: $TESTS_P_SET" echo "Tests to run on Build: $TESTS_B_SET" - run_test start $TEST_DIR defconfig + run_test start "$TEST_DIR" defconfig # run twice - we just want end build errors.. - run_test start $TEST_DIR btest_kbuild $ofiles - run_test start $TEST_DIR btest_kbuild $ofiles + run_test start "$TEST_DIR" btest_kbuild "$ofiles" + run_test start "$TEST_DIR" btest_kbuild "$ofiles" for test_s in $TESTS_B_SET do - run_test start $TEST_DIR $test_s $ofiles + run_test start "$TEST_DIR" "$test_s" "$ofiles" done for test_s in $TESTS_D_SET do - run_test start $TEST_DIR $test_s $dfiles + run_test start "$TEST_DIR" "$test_s" "$dfiles" done for test_s in $TESTS_Y_SET do - run_test start $TEST_DIR $test_s $yfiles + run_test start "$TEST_DIR" "$test_s" "$yfiles" done PIDS="" for test_s in $TESTS_C_SET do - run_test start $TEST_DIR $test_s $cfiles & + run_test start "$TEST_DIR" "$test_s" "$cfiles" & PIDS="$PIDS $!" done # wait for all to come back - echo Waiting for test PIDs: $PIDS + echo "Waiting for test PIDs: $PIDS" for pid in $PIDS do - wait $pid + wait "$pid" done PIDS="" for test_s in $TESTS_P_SET do - run_test_dummy start $TEST_DIR $test_s $patch - run_test end $TEST_DIR $test_s $patch + run_test_dummy start "$TEST_DIR" "$test_s" "$patch" + run_test end "$TEST_DIR" "$test_s" "$patch" done - run_test end $TEST_DIR defconfig + run_test end "$TEST_DIR" defconfig # run twice - we just want end build errors.. - run_test end $TEST_DIR btest_kbuild $ofiles - run_test end $TEST_DIR btest_kbuild $ofiles + run_test end "$TEST_DIR" btest_kbuild "$ofiles" + run_test end "$TEST_DIR" btest_kbuild "$ofiles" for test_s in $TESTS_B_SET do - run_test end $TEST_DIR $test_s $ofiles + run_test end "$TEST_DIR" "$test_s" "$ofiles" done for test_s in $TESTS_D_SET do - run_test end $TEST_DIR $test_s $dfiles + run_test end "$TEST_DIR" "$test_s" "$dfiles" done for test_s in $TESTS_Y_SET do - run_test end $TEST_DIR $test_s $yfiles + run_test end "$TEST_DIR" "$test_s" "$yfiles" done PIDS="" for test_s in $TESTS_C_SET do - run_test end $TEST_DIR $test_s $cfiles & + run_test end "$TEST_DIR" "$test_s" "$cfiles" & PIDS="$PIDS $!" done # wait for all to come back - echo Waiting for test PIDs: $PIDS + echo "Waiting for test PIDs: $PIDS" for pid in $PIDS do - wait $pid + wait "$pid" done PIDS="" } report_patch() { - Subject=$(grep '^Subject' $1) - log_marker "::test results START " $(basename $1) "::" + Subject=$(grep '^Subject' "$1") + log_marker "::test results START " "$(basename "$1")" "::" log_me "Subject: $Subject" - echo -en "\n"$(basename $1) "Tests: ">>$LOG_SUMMARY_FILE - report_tests defconfig btest_kbuild $TESTS_C_SET $TESTS_B_SET $TESTS_P_SET $TESTS_Y_SET $TESTS_D_SET - log_marker "::test results END" $(basename $1) "::" + echo -en "\n" "$(basename "$1")" "Tests: " >> "$LOG_SUMMARY_FILE" + report_tests defconfig btest_kbuild "$TESTS_C_SET" "$TESTS_B_SET" "$TESTS_P_SET" "$TESTS_Y_SET" "$TESTS_D_SET" + log_marker "::test results END" "$(basename "$1")" "::" } ################### @@ -533,7 +533,7 @@ on_exit() { if [ x != x"$PIDS" ]; then echo "Killing $PIDS" - killall $PIDS 2>/dev/null + killall "$PIDS" 2>/dev/null fi if [ -n "$DEBUG_MODE" ]; then @@ -541,22 +541,22 @@ on_exit() { fi if [ -f "$TEST_DIR/.config" ]; then echo "restoring .config" - cp $TEST_DIR/.config .config + cp "$TEST_DIR"/.config .config fi if [ -n "$TEST_DIR" ] && [ -d "$TEST_DIR" ]; then echo "Removing temp dir" - rm -rf $TEST_DIR 2>/dev/null + rm -rf "$TEST_DIR" 2>/dev/null fi if [ -n "$CURRENT_BRANCH" ]; then echo "Restoring to $CURRENT_BRANCH branch" git reset --hard 2>/dev/null - git checkout $CURRENT_BRANCH 2>/dev/null + git checkout "$CURRENT_BRANCH" 2>/dev/null fi if [ -n "$TEST_BRANCH_NAME" ]; then bexists=$(git branch|grep "$TEST_BRANCH_NAME" 2>/dev/null) if [ -n "$bexists" ]; then echo "Cleaning up testing branch" - git branch -D $TEST_BRANCH_NAME + git branch -D "$TEST_BRANCH_NAME" fi fi } @@ -566,20 +566,20 @@ on_exit() { log_marker() { MARKER_STRING="================" if [ "$*" ]; then - echo "$MARKER_STRING">>$LOG_FILE - echo "$*">>$LOG_FILE - echo -e "$MARKER_STRING\n">>$LOG_FILE + echo "$MARKER_STRING" >> "$LOG_FILE" + echo "$*" >> "$LOG_FILE" + echo -e "$MARKER_STRING\n" >> "$LOG_FILE" else - echo -e "$MARKER_STRING\n\n">>$LOG_FILE + echo -e "$MARKER_STRING\n\n" >> "$LOG_FILE" fi } log_me() { - echo "$*">>$LOG_FILE + echo "$*" >> "$LOG_FILE" } logs_me() { - echo -e "$*">>$LOG_SUMMARY_FILE + echo -e "$*" >> "$LOG_SUMMARY_FILE" } report_tests() { @@ -590,8 +590,8 @@ report_tests() { start_log=$TEST_DIR/$test-start end_log=$TEST_DIR/$test-end diff_log=$TEST_DIR/$test-diff - if [ -f $start_log ] && [ -f $end_log ]; then - diff -purN $start_log $end_log > $diff_log + if [ -f "$start_log" ] && [ -f "$end_log" ]; then + diff -purN "$start_log" "$end_log" > "$diff_log" fi done FAIL_TEST="" @@ -599,9 +599,9 @@ report_tests() { for test in $TESTS do diff_log=$TEST_DIR/$test-diff - if [ -f $diff_log ]; then - size=$(stat --format "%s" $diff_log) - if [ $size -ne 0 ]; then + if [ -f "$diff_log" ]; then + size=$(stat --format "%s" "$diff_log") + if [ "$size" -ne 0 ]; then log_me "$test FAILED?" PASS=0 FAIL_TEST="$FAIL_TEST $test" @@ -611,16 +611,16 @@ report_tests() { fi done if [ $PASS -eq 1 ]; then - log_me Passed: $TESTS + log_me Passed: "$TESTS" else for test in $TESTS do diff_log=$TEST_DIR/$test-diff - if [ -f $diff_log ]; then - size=$(stat --format "%s" $diff_log) - if [ $size -ne 0 ]; then + if [ -f "$diff_log" ]; then + size=$(stat --format "%s" "$diff_log") + if [ "$size" -ne 0 ]; then log_marker "$test results:" - cat $diff_log >>$LOG_FILE + cat "$diff_log" >> "$LOG_FILE" fi fi done @@ -644,14 +644,14 @@ report_end() { if [ "$app" = "smatch" ]; then app=$SMATCH fi - echo "version of $app:" >>$LOG_FILE - (which $app 2>&1) >> $LOG_FILE - ($app --version 2>&1) >> $LOG_FILE - echo >>$LOG_FILE + echo "version of $app:" >> "$LOG_FILE" + (which "$app" 2>&1) >> "$LOG_FILE" + ("$app" --version 2>&1) >> "$LOG_FILE" + echo >> "$LOG_FILE" done - echo "version of dtschema python3 package:" >>$LOG_FILE - python3 -m pip list|grep 'dtschema' >> $LOG_FILE - echo >>$LOG_FILE + echo "version of dtschema python3 package:" >> "$LOG_FILE" + python3 -m pip list|grep 'dtschema' >> "$LOG_FILE" + echo >> "$LOG_FILE" log_marker END_DATE=$(date) @@ -663,11 +663,11 @@ report_end() { fail=0 while read ln do - empty=$(echo $ln |wc -c) + empty=$(echo "$ln" |wc -c) # Colored reporting to ensure people dont miss errors # See http://misc.flogisoft.com/bash/tip_colors_and_formatting - if [ $empty -gt 2 ]; then - pass=$(echo $ln|grep 'Passed(ALL)') + if [ "$empty" -gt 2 ]; then + pass=$(echo "$ln" | grep 'Passed(ALL)') if [ -z "$pass" ]; then # Red back, white foreground echo -e "\e[1m\e[97m\e[101m$ln\e[0m" @@ -677,12 +677,12 @@ report_end() { echo -e "\e[1m\e[97m\e[102m$ln\e[0m" fi fi - done <$LOG_SUMMARY_FILE - echo "***************** DETAILED RESULTS *********">>$LOG_SUMMARY_FILE - cat "$LOG_FILE">>$LOG_SUMMARY_FILE - mv $LOG_SUMMARY_FILE $LOG_FILE + done < "$LOG_SUMMARY_FILE" + echo "***************** DETAILED RESULTS *********" >> "$LOG_SUMMARY_FILE" + cat "$LOG_FILE" >> "$LOG_SUMMARY_FILE" + mv "$LOG_SUMMARY_FILE" "$LOG_FILE" echo -ne "\e[96m\e[40mComplete report is available here: " - if [ $fail -eq 1 ]; then + if [ "$fail" -eq 1 ]; then echo -e "\e[92m\e[41m\e[5m$LOG_FILE\e[0m" else echo -e "\e[97m\e[42m\e[5m$LOG_FILE\e[0m" @@ -697,7 +697,7 @@ check_missing_application() { for i in $APPS_NEEDED do if [ "$i" = "smatch" ]; then - i=$(cat $SMATCH|grep 'smatch'|cut -d ' ' -f1) + i=$(cat "$SMATCH" | grep 'smatch'|cut -d ' ' -f1) if [ -z "$i" ]; then i=smatch fi @@ -721,7 +721,7 @@ recommend_missing_application() { if [ -x /usr/lib/command-not-found ]; then for i in $APPS_MISSING do - /usr/lib/command-not-found --no-failure-msg $i + /usr/lib/command-not-found --no-failure-msg "$i" done fi return 2 @@ -1051,12 +1051,12 @@ LOG_SUMMARY_FILE=$TEST_DIR/summary # NOW, hook on. cleanup.. we are about to start doing serious stuff. trap on_exit EXIT SIGINT SIGTERM -mkdir -p $TEST_DIR $PATCHD -cp .config $TEST_DIR/.config 2>/dev/null +mkdir -p "$TEST_DIR" "$PATCHD" +cp .config "$TEST_DIR"/.config 2>/dev/null if [ -z "$SMATCH" ]; then SMATCH=$TEST_DIR/smatch - echo -e '#!/bin/bash\nsmatch -p=kernel $@'> $SMATCH - chmod +x $SMATCH + echo -e '#!/bin/bash\nsmatch -p=kernel $@'> "$SMATCH" + chmod +x "$SMATCH" fi # First create a list of patches to test.. @@ -1065,31 +1065,31 @@ if [ -n "$TEST_TOP" ]; then usage "error: requested number of patches '$PATCHCOUNT' Not a number" exit 4 fi - git format-patch --no-cover-letter -M -C -o $PATCHD -$PATCHCOUNT >/dev/null - git checkout -b $TEST_BRANCH_NAME - git reset --hard HEAD~$PATCHCOUNT + git format-patch --no-cover-letter -M -C -o "$PATCHD" -"$PATCHCOUNT" >/dev/null + git checkout -b "$TEST_BRANCH_NAME" + git reset --hard HEAD~"$PATCHCOUNT" fi if [ -n "$PATCHES" ]; then - cp -rf $PATCHES $PATCHD - git checkout -b $TEST_BRANCH_NAME + cp -rf "$PATCHES" "$PATCHD" + git checkout -b "$TEST_BRANCH_NAME" fi if [ -n "$TEST_BRANCH" ]; then - git format-patch --no-cover-letter -M -C -o $PATCHD $BASE_BRANCH..$TEST_BRANCH >/dev/null + git format-patch --no-cover-letter -M -C -o "$PATCHD" "$BASE_BRANCH".."$TEST_BRANCH" >/dev/null PATCHES=$(realpath "$PATCHD"/*.patch|grep -v "$COVER_LETTER") PATCHCOUNT=$(echo "$PATCHES" |wc -l) - if [ $PATCHCOUNT -eq 0 ]; then + if [ "$PATCHCOUNT" -eq 0 ]; then usage "$BASE_BRANCH..$TEST_BRANCH generated no patches!" exit 4; fi - git branch $TEST_BRANCH_NAME $BASE_BRANCH >/dev/null - git checkout $TEST_BRANCH_NAME + git branch "$TEST_BRANCH_NAME" "$BASE_BRANCH" >/dev/null + git checkout "$TEST_BRANCH_NAME" fi if [ -e "$LOG_FILE" ]; then echo "$LOG_FILE exists, taking a backup" - mv $LOG_FILE $LOG_FILE.bak + mv "$LOG_FILE" "$LOG_FILE".bak fi START_DATE=$(date) @@ -1108,8 +1108,8 @@ STARTP_SEC=$(date "+%s") for patch in $PATCHES do echo "Testing Patch ($PATCH_NUM/$PATCHCOUNT):" "$(basename "$patch")" "$DELTAP seconds elapsed, estimated: remaining $ETA_REMAIN / total $EST_TOTAL seconds" - test_patch $patch - report_patch $patch + test_patch "$patch" + report_patch "$patch" NOW_SEC=$(date "+%s") DELTAP=$((NOW_SEC - STARTP_SEC)) AVG=$((DELTAP / PATCH_NUM)) From 70f71cfaf436d9e5c20cd2750d03b27b10d844dd Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 21:40:45 -0500 Subject: [PATCH 26/34] kernel_patch_verify: remove final exit Implied that the script exits 0 by default. With this shellcheck considers some of the code unreachable. Drop it so we can check on things. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 3 --- 1 file changed, 3 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index d297124..9071326 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -1121,6 +1121,3 @@ done tests_end report_tests_end report_end - -#=========== COMPLETE - let the cleanup handler clean things ========= -exit 0 From c9995c7478a3f02dd8d4f3cefe1e31447ed080cb Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 22:40:33 -0500 Subject: [PATCH 27/34] kernel_patch_verify: arrays son Replace all of the loose parameter passing with strict array packing and unpacking. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 77 ++++++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 39 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 9071326..08ee973 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -103,7 +103,7 @@ run_test_dummy() { get_sorted_existing_files() { - test_files="" + test_files=() # If there are no files, then there is nothing to sort.. return empty if [ -z "$*" ]; then echo @@ -112,10 +112,10 @@ get_sorted_existing_files() for i in $( (ls -d "$@" 2>/dev/null) | sort) do if [ -f "$i" ]; then - test_files="$test_files $i" + test_files+=("$i") fi done - echo "$test_files" + printf '%s\n' "${test_files[@]}" } ################### @@ -131,31 +131,30 @@ ptest_check() { ################### # Basic tests to run on the files impacted by the patch ftest_check_kdoc() { - test_files=$(get_sorted_existing_files $*) - - if [ -n "$test_files" ]; then - ( ( ( "$KDIR"/scripts/kernel-doc "$test_files" >/dev/null ) 2>&1 ) | cut -d ':' -f1,3- ) 1>&2 + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -n "${test_files[*]}" ]; then + ( ( ( "$KDIR"/scripts/kernel-doc "${test_files[@]}" >/dev/null ) 2>&1 ) | cut -d ':' -f1,3- ) 1>&2 fi } ftest_check_includes() { - test_files=$(get_sorted_existing_files $*) - if [ -n "$test_files" ]; then - "$KDIR"/scripts/checkincludes.pl "$test_files" 1>&2 + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -n "${test_files[*]}" ]; then + "$KDIR"/scripts/checkincludes.pl "${test_files[@]}" 1>&2 fi } ftest_check_headerdeps() { - test_files=$(get_sorted_existing_files $*) - if [ -n "$test_files" ]; then - "$KDIR"/scripts/headerdep.pl "$test_files" 1>&2 + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -n "${test_files[*]}" ]; then + "$KDIR"/scripts/headerdep.pl "${test_files[@]}" 1>&2 fi } ytest_dt_binding_check() { if [ "$UBOOT_TESTING" -eq 0 ]; then - test_files=$(get_sorted_existing_files $*) - for test_file in $test_files + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + for test_file in "${test_files[@]}" do # If adding a new file if [ -f "$test_file" ]; then @@ -179,11 +178,11 @@ ytest_dtbs_check() { kmake dtbs 2>&1 >/dev/null all_dtb_files=$(find . -iname '*.dtb') - test_files=$(get_sorted_existing_files $all_dtb_files) - if [ -z "$test_files" ]; then + readarray -t test_files <<< "$(get_sorted_existing_files "$all_dtb_files")" + if [ -z "${test_files[*]}" ]; then return fi - rm -f "$test_files" + rm -f "${test_files[@]}" rm -f Documentation/devicetree/bindings/processed-schema-examples.json find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null ( ( ( make -j"$KM_CPUS" dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 @@ -196,8 +195,8 @@ ytest_dtbs_check() { DTB_FILTER_LIST="property_name_chars_strict" dtest_build_dtb() { if [ "$UBOOT_TESTING" -eq 0 ]; then - test_files=$(get_sorted_existing_files $*) - if [ -z "$test_files" ]; then + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -z "${test_files[*]}" ]; then return fi if [ "$DTB_NOSKIP" -eq 1 ]; then @@ -216,11 +215,11 @@ dtest_build_dtb() { dtest_build_dtb_to_dts() { if [ "$UBOOT_TESTING" -eq 0 ]; then - test_files=$(get_sorted_existing_files $*) - if [ -z "$test_files" ]; then + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -z "${test_files[*]}" ]; then return fi - for test_file in $test_files + for test_file in "${test_files[@]}" do D=$(dirname "$test_file") rm -f "$D"/*.dtb @@ -244,11 +243,11 @@ dtest_build_dtb_to_dts() { dtest_dtbs_check() { if [ "$UBOOT_TESTING" -eq 0 ]; then - test_files=$(get_sorted_existing_files $*) - if [ -z "$test_files" ]; then + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -z "${test_files[*]}" ]; then return fi - for test_file in $test_files + for test_file in "${test_files[@]}" do D=$(dirname "$test_file") rm -f "$D"/*.dtb "$D"/*.yaml @@ -266,31 +265,31 @@ btest_mrproper() { } btest_basic() { - test_files=$(get_sorted_existing_files $*) - if [ -n "$test_files" ]; then - rm "$test_files" - ( ( ( kmake_single "$test_files" > /dev/null ) 2>&1 )|cut -d ':' -f1,4- | grep -v '^make$' ) 1>&2 + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -n "${test_files[*]}" ]; then + rm "${test_files[@]}" + ( ( ( kmake_single "${test_files[@]}" > /dev/null ) 2>&1 )|cut -d ':' -f1,4- | grep -v '^make$' ) 1>&2 fi } btest_sparse() { - test_files=$(get_sorted_existing_files $*) - if [ -n "$test_files" ]; then - ( ( ( kmake_single C=2 "$test_files" > /dev/null ) 2>&1 )|cut -d ':' -f1,4- ) |grep -v '^mv$' |grep -v '^make$' | grep -v '__ksymtab' 1>&2 + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -n "${test_files[*]}" ]; then + ( ( ( kmake_single C=2 "${test_files[@]}" > /dev/null ) 2>&1 )|cut -d ':' -f1,4- ) |grep -v '^mv$' |grep -v '^make$' | grep -v '__ksymtab' 1>&2 fi } btest_smatch() { - test_files=$(get_sorted_existing_files $*) - if [ -n "$test_files" ]; then - kmake_single CHECK="$SMATCH" C=2 "$test_files" | egrep '(warn|error):' 1>&2 + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -n "${test_files[*]}" ]; then + kmake_single CHECK="$SMATCH" C=2 "${test_files[@]}" | egrep '(warn|error):' 1>&2 fi } btest_cocci() { - test_files=$(get_sorted_existing_files $*) - if [ -n "$test_files" ]; then - kmake_single C=2 CHECK="scripts/coccicheck" MODE=report "$test_files" >/dev/null + readarray -t test_files <<< "$(get_sorted_existing_files "$@")" + if [ -n "${test_files[*]}" ]; then + kmake_single C=2 CHECK="scripts/coccicheck" MODE=report "${test_files[@]}" >/dev/null fi } From 5e76a84bd65a53aa8a80f61e431a01edafd895fc Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 22:48:10 -0500 Subject: [PATCH 28/34] kernel_patch_verify: move 2>&1 to end of line To redirect stdout+stderr, 2>&1 must be last Signed-off-by: Randolph Sapp --- kernel_patch_verify | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 08ee973..31a69b5 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -175,7 +175,7 @@ ytest_dtbs_check() { fi # Re-Build all the dtbs to get a list (Ignore log) - kmake dtbs 2>&1 >/dev/null + kmake dtbs > /dev/null 2>&1 all_dtb_files=$(find . -iname '*.dtb') readarray -t test_files <<< "$(get_sorted_existing_files "$all_dtb_files")" From a9807b3897a68bb728496707e2c1231021e46c3e Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 22:56:35 -0500 Subject: [PATCH 29/34] kernel_patch_verify: eliminate useless cats Cat is really only good for concatenating files. If we only want to read files we can use bash and printf directly. More keystrokes but faster at runtime than cat. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 31a69b5..c78d4a8 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -315,7 +315,7 @@ btest_kbuild() { else kmake C=1 "$KP_TARGETS" "$MODULES" > /dev/null 2> "$TEST_DIR"/err_stuff # Get rid of standard sparse mess with u-boot - cat "$TEST_DIR"/err_stuff|grep -v 'efi.h'|grep -v 'version.c' |grep -v '_u_boot_list_' 1>&2 + printf '%s\n' "$(< "$TEST_DIR"/err_stuff)"|grep -v 'efi.h'|grep -v 'version.c' |grep -v '_u_boot_list_' 1>&2 fi } @@ -619,7 +619,7 @@ report_tests() { size=$(stat --format "%s" "$diff_log") if [ "$size" -ne 0 ]; then log_marker "$test results:" - cat "$diff_log" >> "$LOG_FILE" + printf '%s\n' "$(< "$diff_log")" >> "$LOG_FILE" fi fi done @@ -678,7 +678,7 @@ report_end() { fi done < "$LOG_SUMMARY_FILE" echo "***************** DETAILED RESULTS *********" >> "$LOG_SUMMARY_FILE" - cat "$LOG_FILE" >> "$LOG_SUMMARY_FILE" + printf '%s\n' "$(< "$LOG_FILE")" >> "$LOG_SUMMARY_FILE" mv "$LOG_SUMMARY_FILE" "$LOG_FILE" echo -ne "\e[96m\e[40mComplete report is available here: " if [ "$fail" -eq 1 ]; then @@ -696,7 +696,7 @@ check_missing_application() { for i in $APPS_NEEDED do if [ "$i" = "smatch" ]; then - i=$(cat "$SMATCH" | grep 'smatch'|cut -d ' ' -f1) + i=$(printf '%s\n' "$(< "$SMATCH")" | grep 'smatch'|cut -d ' ' -f1) if [ -z "$i" ]; then i=smatch fi From 5f6c24183804bfd9e3f19ec86552334525d2edcd Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 22:59:23 -0500 Subject: [PATCH 30/34] kernel_patch_verify: use print0 when piping into xargs Use -print0 and -0 when piping from find into xargs. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index c78d4a8..a361854 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -184,7 +184,7 @@ ytest_dtbs_check() { fi rm -f "${test_files[@]}" rm -f Documentation/devicetree/bindings/processed-schema-examples.json - find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null + find Documentation/devicetree -iname "*.example.*" -print0 | xargs -0 rm -f 2>/dev/null >/dev/null ( ( ( make -j"$KM_CPUS" dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 fi } @@ -208,7 +208,7 @@ dtest_build_dtb() { rm -f "$D"/*.dtb done rm -f Documentation/devicetree/bindings/processed-schema-examples.json - find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null + find Documentation/devicetree -iname "*.example.*" -print0 | xargs -0 rm -f 2>/dev/null >/dev/null ( ( ( kmake_single W=2 dtbs > /dev/null ) 2>&1 )|cut -d ':' -f1,4- | grep -v '^make$'|grep -v "$DTB_FILTER_LIST" ) 1>&2 fi } @@ -225,7 +225,7 @@ dtest_build_dtb_to_dts() { rm -f "$D"/*.dtb done rm -f Documentation/devicetree/bindings/processed-schema-examples.json - find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null + find Documentation/devicetree -iname "*.example.*" -print0 | xargs -0 rm -f 2>/dev/null >/dev/null (kmake_single W=2 dtbs > /dev/null) 2>/dev/null TEST_DTBS_FULL="" for test_file in $test_files @@ -253,7 +253,7 @@ dtest_dtbs_check() { rm -f "$D"/*.dtb "$D"/*.yaml done rm -f Documentation/devicetree/bindings/processed-schema-examples.json - find Documentation/devicetree -iname "*.example.*"|xargs rm -f 2>/dev/null >/dev/null + find Documentation/devicetree -iname "*.example.*" -print0 | xargs -0 rm -f 2>/dev/null >/dev/null ( ( ( make -j"$KM_CPUS" dtbs_check > /dev/null ) 2>&1 )|grep -v '^\s\s*'|sort -u ) 1>&2 fi } From 5f82940c6b1f981e4aa57a4c9f575b9d457e02fe Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 23:03:26 -0500 Subject: [PATCH 31/34] kernel_patch_verify: remove x-prefix in comparison Avoid x-prefix in comparisons as it no longer serves a purpose. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index a361854..2ebfdf3 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -892,7 +892,7 @@ while getopts "S:n:j:c:T:B:l:p:b:t:m:123456789CdDUVZL" opt; do exit 1; fi PATCHCOUNT=$OPTARG - if [ x"$PATCHCOUNT" = x0 ]; then + if [ "$PATCHCOUNT" -eq 0 ]; then usage "Hey! Do your own '0' patch testing!!!" exit 1; fi From 54b032162f21cd88039272130b75d512d2421414 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 23:04:56 -0500 Subject: [PATCH 32/34] kernel_patch_verify: replace egrep with grep -E egrep is non-standard and deprecated. Use grep -E instead. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 2ebfdf3..049b1a6 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -282,7 +282,7 @@ btest_sparse() { btest_smatch() { readarray -t test_files <<< "$(get_sorted_existing_files "$@")" if [ -n "${test_files[*]}" ]; then - kmake_single CHECK="$SMATCH" C=2 "${test_files[@]}" | egrep '(warn|error):' 1>&2 + kmake_single CHECK="$SMATCH" C=2 "${test_files[@]}" | grep -E '(warn|error):' 1>&2 fi } From d91009d36c7294bb99e97e96d8895e95eee3b341 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 23:12:12 -0500 Subject: [PATCH 33/34] kernel_patch_verify: reduce redirects with subshell Reduce the number of redirects with subshell execution. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 46 +++++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 049b1a6..7b9b9ff 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -565,21 +565,21 @@ on_exit() { log_marker() { MARKER_STRING="================" if [ "$*" ]; then - echo "$MARKER_STRING" >> "$LOG_FILE" - echo "$*" >> "$LOG_FILE" - echo -e "$MARKER_STRING\n" >> "$LOG_FILE" + echo "$MARKER_STRING" + echo "$*" + echo -e "$MARKER_STRING\n" else - echo -e "$MARKER_STRING\n\n" >> "$LOG_FILE" + echo -e "$MARKER_STRING\n\n" fi -} +} >> "$LOG_FILE" log_me() { - echo "$*" >> "$LOG_FILE" -} + echo "$*" +} >> "$LOG_FILE" logs_me() { - echo -e "$*" >> "$LOG_SUMMARY_FILE" -} + echo -e "$*" +} >> "$LOG_SUMMARY_FILE" report_tests() { TESTS=$* @@ -638,19 +638,21 @@ report_end() { log_marker "CPUS used: $CPUS" log_marker "Application versions" - for app in $APPS_NEEDED - do - if [ "$app" = "smatch" ]; then - app=$SMATCH - fi - echo "version of $app:" >> "$LOG_FILE" - (which "$app" 2>&1) >> "$LOG_FILE" - ("$app" --version 2>&1) >> "$LOG_FILE" - echo >> "$LOG_FILE" - done - echo "version of dtschema python3 package:" >> "$LOG_FILE" - python3 -m pip list|grep 'dtschema' >> "$LOG_FILE" - echo >> "$LOG_FILE" + { + for app in $APPS_NEEDED + do + if [ "$app" = "smatch" ]; then + app=$SMATCH + fi + echo "version of $app:" + which "$app" 2>&1 + "$app" --version 2>&1 + echo + done + echo "version of dtschema python3 package:" + python3 -m pip list|grep 'dtschema' + echo + } >> "$LOG_FILE" log_marker END_DATE=$(date) From 7c3f06ab9e782da755ce691fc0e34c647f0e25b0 Mon Sep 17 00:00:00 2001 From: Randolph Sapp Date: Thu, 14 Mar 2024 23:19:15 -0500 Subject: [PATCH 34/34] kernel_patch_verify: add -r to read, use var count Read without -r will mangle backslashes. We don't have to let wc count characters in a variable. Signed-off-by: Randolph Sapp --- kernel_patch_verify | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel_patch_verify b/kernel_patch_verify index 7b9b9ff..906c223 100755 --- a/kernel_patch_verify +++ b/kernel_patch_verify @@ -662,9 +662,9 @@ report_end() { if [ -f "$LOG_SUMMARY_FILE" ]; then echo -e "\e[106m\e[4m\e[1mTest Summary:\e[0m" fail=0 - while read ln + while read -r ln do - empty=$(echo "$ln" |wc -c) + empty=${#ln} # Colored reporting to ensure people dont miss errors # See http://misc.flogisoft.com/bash/tip_colors_and_formatting if [ "$empty" -gt 2 ]; then